From: Sreerenj Balachandran Date: Tue, 13 Feb 2018 23:40:22 +0000 (-0900) Subject: msdk : Add RenderNode support X-Git-Tag: 1.19.3~507^2~4459 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b622d21d6a309e3fdf698d9edb60d2f7423fd47f;p=platform%2Fupstream%2Fgstreamer.git msdk : Add RenderNode support Use drm render node as the first choice of device node file. Fall backs to use drm primary (/dev/dri/card[0-9]) if there is no render node available Basic logic is inherited from gstreamer-vaapi, but using gudev API rather than libudev directly. Added gudev library as dependency for msdk. https://bugzilla.gnome.org/show_bug.cgi?id=791599 --- diff --git a/sys/msdk/Makefile.am b/sys/msdk/Makefile.am index bdfae2b..08175ee 100644 --- a/sys/msdk/Makefile.am +++ b/sys/msdk/Makefile.am @@ -49,7 +49,8 @@ libgstmsdk_la_CFLAGS = \ $(GST_PBUTILS_CFLAGS) \ $(GST_VIDEO_CFLAGS) \ $(MSDK_CFLAGS) \ - $(LIBMFX_CFLAGS) + $(LIBMFX_CFLAGS)\ + $(G_UDEV_CFLAGS) libgstmsdk_la_LIBADD = \ $(GST_LIBS) \ @@ -57,7 +58,8 @@ libgstmsdk_la_LIBADD = \ $(GST_PBUTILS_LIBS) \ $(GST_VIDEO_LIBS) \ $(MSDK_LIBS) \ - $(LIBMFX_LIBS) + $(LIBMFX_LIBS) \ + $(G_UDEV_LIBS) if USE_MSDK_LIBVA libgstmsdk_la_SOURCES += \ diff --git a/sys/msdk/gstmsdkcontext.c b/sys/msdk/gstmsdkcontext.c index 90950e2..696998e 100644 --- a/sys/msdk/gstmsdkcontext.c +++ b/sys/msdk/gstmsdkcontext.c @@ -35,6 +35,7 @@ #include #include #include +#include #endif GST_DEBUG_CATEGORY_STATIC (gst_debug_msdkcontext); @@ -64,6 +65,65 @@ struct _GstMsdkContextPrivate }; #ifndef _WIN32 + +static gint +get_device_id (void) +{ + GUdevClient *client = NULL; + GUdevEnumerator *e = NULL; + GList *devices, *l; + GUdevDevice *dev, *parent; + const gchar *devnode_path; + const gchar *devnode_files[2] = { "renderD[0-9]*", "card[0-9]*" }; + int fd = -1, i; + + client = g_udev_client_new (NULL); + if (!client) + goto done; + + e = g_udev_enumerator_new (client); + if (!e) + goto done; + + g_udev_enumerator_add_match_subsystem (e, "drm"); + for (i = 0; i < 2; i++) { + g_udev_enumerator_add_match_name (e, devnode_files[i]); + devices = g_udev_enumerator_execute (e); + + for (l = devices; l != NULL; l = l->next) { + dev = (GUdevDevice *) l->data; + + parent = g_udev_device_get_parent (dev); + if (strcmp (g_udev_device_get_subsystem (parent), "pci") != 0) { + g_object_unref (parent); + continue; + } + g_object_unref (parent); + + devnode_path = g_udev_device_get_device_file (dev); + fd = open (devnode_path, O_RDWR | O_CLOEXEC); + if (fd < 0) + continue; + GST_DEBUG ("Opened the drm device node %s", devnode_path); + break; + } + + g_list_foreach (devices, (GFunc) gst_object_unref, NULL); + g_list_free (devices); + if (fd >= 0) + goto done; + } + +done: + if (e) + g_object_unref (e); + if (client) + g_object_unref (client); + + return fd; +} + + static gboolean gst_msdk_context_use_vaapi (GstMsdkContext * context) { @@ -74,12 +134,9 @@ gst_msdk_context_use_vaapi (GstMsdkContext * context) mfxStatus status; GstMsdkContextPrivate *priv = context->priv; - /* maybe /dev/dri/renderD128 */ - static const gchar *dri_path = "/dev/dri/card0"; - - fd = open (dri_path, O_RDWR); + fd = get_device_id (); if (fd < 0) { - GST_ERROR ("Couldn't open %s", dri_path); + GST_ERROR ("Couldn't find a drm device node to open"); return FALSE; } diff --git a/sys/msdk/meson.build b/sys/msdk/meson.build index ece91aa..fd34acb 100644 --- a/sys/msdk/meson.build +++ b/sys/msdk/meson.build @@ -40,8 +40,9 @@ if msdk_root != '' else libva_dep = dependency('libva-drm', required: false) libdl_dep = cc.find_library('dl', required: false) - msdk_dep = declare_dependency(include_directories: msdk_incdir, dependencies: [msdk_lib, libva_dep, libdl_dep]) - msdk_dep_found = msdk_lib.found() and libva_dep.found() and libdl_dep.found() + libgudev_dep = dependency('gudev-1.0', required : false) + msdk_dep = declare_dependency(include_directories: msdk_incdir, dependencies: [msdk_lib, libva_dep, libdl_dep, libgudev_dep]) + msdk_dep_found = msdk_lib.found() and libva_dep.found() and libdl_dep.found() and libgudev_dep.found() endif if msdk_dep_found