[vlc-commits] hw: vaapi: add vlc_vaapi_InitializeInstanceDRM

Thomas Guillem git at videolan.org
Fri Dec 1 17:26:02 CET 2017


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Dec  1 16:07:14 2017 +0100| [499a739be14ccaab4e03570324cff14c48abdc47] | committer: Francois Cartegnie

hw: vaapi: add vlc_vaapi_InitializeInstanceDRM

Common function to open a DRM device, get a VADisplay and initialize it.

Refs #19173

(cherry picked from commit 513fb6e95b5eb418e4f0734380985f2928738db6)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=499a739be14ccaab4e03570324cff14c48abdc47
---

 modules/hw/vaapi/vlc_vaapi.c | 58 ++++++++++++++++++++++++++++++++++++++++++++
 modules/hw/vaapi/vlc_vaapi.h |  8 ++++++
 2 files changed, 66 insertions(+)

diff --git a/modules/hw/vaapi/vlc_vaapi.c b/modules/hw/vaapi/vlc_vaapi.c
index b2d1f16e03..022b706372 100644
--- a/modules/hw/vaapi/vlc_vaapi.c
+++ b/modules/hw/vaapi/vlc_vaapi.c
@@ -31,11 +31,13 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <inttypes.h>
+#include <fcntl.h>
 #include <assert.h>
 
 #include <va/va.h>
 
 #include <vlc_common.h>
+#include <vlc_fs.h>
 #include <vlc_atomic.h>
 #include <vlc_fourcc.h>
 #include <vlc_filter.h>
@@ -108,6 +110,62 @@ error:
     return NULL;
 }
 
+static void native_drm_destroy_cb(VANativeDisplay native)
+{
+    vlc_close((intptr_t) native);
+}
+
+struct vlc_vaapi_instance *
+vlc_vaapi_InitializeInstanceDRM(vlc_object_t *o,
+                                VADisplay (*pf_getDisplayDRM)(int),
+                                VADisplay *pdpy, const char *device)
+{
+    static const char *default_drm_device_paths[] = {
+        "/dev/dri/renderD128",
+        "/dev/dri/card0",
+    };
+
+    const char *user_drm_device_paths[] = { device };
+    const char **drm_device_paths;
+    size_t drm_device_paths_count;
+
+    if (device != NULL)
+    {
+        drm_device_paths = user_drm_device_paths;
+        drm_device_paths_count = 1;
+    }
+    else
+    {
+        drm_device_paths = default_drm_device_paths;
+        drm_device_paths_count = ARRAY_SIZE(default_drm_device_paths);
+    }
+
+    for (size_t i = 0; drm_device_paths_count; i++)
+    {
+        int drm_fd = vlc_open(drm_device_paths[i], O_RDWR);
+        if (drm_fd < 0)
+            continue;
+
+        VADisplay dpy = pf_getDisplayDRM(drm_fd);
+        if (dpy)
+        {
+            struct vlc_vaapi_instance *va_inst =
+                vlc_vaapi_InitializeInstance(o, dpy,
+                                             (VANativeDisplay *)(intptr_t)drm_fd,
+                                             native_drm_destroy_cb);
+            if (va_inst)
+            {
+                *pdpy = dpy;
+                return va_inst;
+            }
+        }
+        else
+            vlc_close(drm_fd);
+    }
+    return NULL;
+}
+
+
 VADisplay
 vlc_vaapi_HoldInstance(struct vlc_vaapi_instance *inst)
 {
diff --git a/modules/hw/vaapi/vlc_vaapi.h b/modules/hw/vaapi/vlc_vaapi.h
index e8ecd1edb1..98737c6929 100644
--- a/modules/hw/vaapi/vlc_vaapi.h
+++ b/modules/hw/vaapi/vlc_vaapi.h
@@ -55,6 +55,14 @@ vlc_vaapi_InitializeInstance(vlc_object_t *o, VADisplay dpy,
                              VANativeDisplay native,
                              vlc_vaapi_native_destroy_cb native_destroy_cb);
 
+/* Get and Initializes a VADisplay from a DRM device. If device is NULL, this
+ * function will try to open default devices. */
+struct vlc_vaapi_instance *
+vlc_vaapi_InitializeInstanceDRM(vlc_object_t *o,
+                                VADisplay (*pf_getDisplayDRM)(int),
+                                VADisplay *pdpy, const char *device);
+
+
 /* Increments the VAAPI instance refcount */
 VADisplay
 vlc_vaapi_HoldInstance(struct vlc_vaapi_instance *inst);



More information about the vlc-commits mailing list