libs: display: drm: allow user specify a drm device via an env variable
authorHaihao Xiang <haihao.xiang@intel.com>
Wed, 13 Jan 2021 06:43:20 +0000 (14:43 +0800)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 29 Jan 2021 14:08:42 +0000 (14:08 +0000)
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>

docs/index.md
gst-libs/gst/vaapi/gstvaapidisplay_drm.c

index b95c2a7..dcdf204 100644 (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.
index d575ffd..7f4d399 100644 (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;
   }