libs: display: drm: allow user specify a drm device via an env variable

Currently the default drm device is always used on a system with
multiple drm devices. This patch allows user to specify the required
drm device via GST_VAAPI_DRM_DEVICE env variable

Example:
GST_VAAPI_DRM_DEVICE=/dev/dri/renderD129 gst-launch-1.0 videotestsrc !
vaapih264enc ! fakesink

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/409>
This commit is contained in:
Haihao Xiang 2021-01-13 14:43:20 +08:00 committed by GStreamer Merge Bot
parent 23967fc02b
commit 85284f4aac
2 changed files with 22 additions and 5 deletions

View file

@ -27,3 +27,8 @@ example, intel's driver is `i915`, meanwhile mesa is `gallium`.
This environment variable can be set to a colon-separated list of paths
(or a semicolon-separated list on Windows). libva will scan these paths
for va drivers.
**GST_VAAPI_DRM_DEVICE.**
This environment variable can be set to a specified DRM device when DRM
display is used, it is ignored when other types of displays are used.
By default /dev/dri/renderD128 is used for DRM display.

View file

@ -337,15 +337,27 @@ GstVaapiDisplay *
gst_vaapi_display_drm_new (const gchar * device_path)
{
GstVaapiDisplay *display;
guint types[2], i, num_types = 0;
guint types[3], i, num_types = 0;
gpointer device_paths[3];
g_mutex_lock (&g_drm_device_type_lock);
if (device_path)
if (device_path) {
device_paths[num_types] = (gpointer) device_path;
types[num_types++] = 0;
else if (g_drm_device_type)
} else if (g_drm_device_type) {
device_paths[num_types] = (gpointer) device_path;
types[num_types++] = g_drm_device_type;
else {
} else {
const gchar *user_choice = g_getenv ("GST_VAAPI_DRM_DEVICE");
if (user_choice && g_str_has_prefix (user_choice, "/dev/dri/")) {
device_paths[num_types] = (gpointer) user_choice;
types[num_types++] = 0;
}
device_paths[num_types] = (gpointer) device_path;
types[num_types++] = DRM_DEVICE_RENDERNODES;
device_paths[num_types] = (gpointer) device_path;
types[num_types++] = DRM_DEVICE_LEGACY;
}
@ -353,7 +365,7 @@ gst_vaapi_display_drm_new (const gchar * device_path)
g_drm_device_type = types[i];
display = g_object_new (GST_TYPE_VAAPI_DISPLAY_DRM, NULL);
display = gst_vaapi_display_config (display,
GST_VAAPI_DISPLAY_INIT_FROM_DISPLAY_NAME, (gpointer) device_path);
GST_VAAPI_DISPLAY_INIT_FROM_DISPLAY_NAME, device_paths[i]);
if (display || device_path)
break;
}