[vlc-devel] [PATCH 1/2] vdpau: add vdp_get_gpa

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Thu Jul 20 14:33:43 CEST 2017


Save the VdpGetProcAddress within the instance.
---
 modules/hw/vdpau/instance.c  | 28 +++++++++++++++++++++++++++-
 modules/hw/vdpau/vlc_vdpau.c |  7 +++----
 modules/hw/vdpau/vlc_vdpau.h | 14 +++++++++++++-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/modules/hw/vdpau/instance.c b/modules/hw/vdpau/instance.c
index 6194d88fbc..49b24c7e37 100644
--- a/modules/hw/vdpau/instance.c
+++ b/modules/hw/vdpau/instance.c
@@ -37,6 +37,7 @@ typedef struct vdp_instance
     Display *display;
     vdp_t *vdp;
     VdpDevice device;
+    VdpGetProcAddress *gpa;
 
     int num; /**< X11 screen number */
     char *name; /**< X11 display name */
@@ -76,7 +77,7 @@ static VdpStatus vdp_instance_create(const char *name, int num,
     vi->refs = 1;
 
     VdpStatus err = vdp_create_x11(vi->display, vi->num,
-                                   &vi->vdp, &vi->device);
+                                   &vi->vdp, &vi->device, &vi->gpa);
     if (err != VDP_STATUS_OK)
     {
         XCloseDisplay(vi->display);
@@ -185,6 +186,31 @@ found:
     return VDP_STATUS_OK;
 }
 
+VdpStatus vdp_get_gpa(char const *display_name, int snum,
+                      VdpGetProcAddress **p_gpa)
+{
+    vdp_instance_t *vi;
+
+    if (!display_name)
+    {
+        display_name = getenv("DISPLAY");
+        if (!display_name)
+            return VDP_STATUS_ERROR;
+    }
+
+    pthread_mutex_lock(&lock);
+    vi = vdp_instance_lookup(display_name, snum);
+    pthread_mutex_unlock(&lock);
+    if (!vi)
+        return VDP_STATUS_ERROR;
+
+    assert(vi->gpa);
+    *p_gpa = vi->gpa;
+
+    vdp_release_x11(vi->vdp);
+    return VDP_STATUS_OK;
+}
+
 vdp_t *vdp_hold_x11(vdp_t *vdp, VdpDevice *restrict devp)
 {
     vdp_instance_t *vi, **pp = &list;
diff --git a/modules/hw/vdpau/vlc_vdpau.c b/modules/hw/vdpau/vlc_vdpau.c
index 3cc62f18df..69b2e252e3 100644
--- a/modules/hw/vdpau/vlc_vdpau.c
+++ b/modules/hw/vdpau/vlc_vdpau.c
@@ -616,7 +616,7 @@ VdpStatus vdp_presentation_queue_target_create_x11(const vdp_t *vdp,
 }
 
 VdpStatus vdp_create_x11(void *dpy, int snum,
-                         vdp_t **restrict vdpp, VdpDevice *restrict devp)
+                         vdp_t **restrict vdpp, VdpDevice *restrict devp, VdpGetProcAddress **p_gpa)
 {
     vdp_t *vdp = malloc(sizeof (*vdp));
     if (unlikely(vdp == NULL))
@@ -636,13 +636,12 @@ VdpStatus vdp_create_x11(void *dpy, int snum,
     if (create == NULL)
         goto error;
 
-    VdpGetProcAddress *gpa;
-    err = create(dpy, snum, devp, &gpa);
+    err = create(dpy, snum, devp, p_gpa);
     if (err != VDP_STATUS_OK)
         goto error;
 
     for (VdpFuncId i = 0; i < sizeof (vdp->vt) / sizeof (void *); i++)
-        if (gpa(*devp, i, vdp->funcs + i) != VDP_STATUS_OK)
+        if ((*p_gpa)(*devp, i, vdp->funcs + i) != VDP_STATUS_OK)
             vdp->funcs[i] = NULL;
 
     return VDP_STATUS_OK;
diff --git a/modules/hw/vdpau/vlc_vdpau.h b/modules/hw/vdpau/vlc_vdpau.h
index af62bddcc1..0bf72eb322 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -159,7 +159,7 @@ VdpStatus vdp_presentation_queue_target_create_x11(const vdp_t *,
  * device has been destroyed with vdp_device_destroy().
  * @return VDP_STATUS_OK on success, otherwise a VDPAU error code.
  */
-VdpStatus vdp_create_x11(void *dpy, int snum, vdp_t **vdpp, VdpDevice *devp);
+VdpStatus vdp_create_x11(void *dpy, int snum, vdp_t **vdpp, VdpDevice *devp, VdpGetProcAddress **p_gpa);
 
 
 /**
@@ -188,6 +188,18 @@ void vdp_destroy_x11(vdp_t *);
 VdpStatus vdp_get_x11(const char *name, int num, vdp_t **vdp, VdpDevice *dev);
 
 /**
+ * Finds an existing VdpGetProcAddress matching the
+ * specified X11 display and screen number from within the process-wide list.
+ * If no existing instance corresponds, returns VDP_STATUS_ERROR.
+ * @param name X11 display name
+ * @param snum X11 screen number
+ * @param p_gpa location to hold the VDPAU GPA function pointer [OUT]
+ * @return VDP_STATUS_OK on success, otherwise VDP_STATUS_ERROR.
+ */
+VdpStatus vdp_get_gpa(char const *display_name, int snum,
+                      VdpGetProcAddress **p_gpa);
+
+/**
  * Increases the reference count of a VDPAU instance created by vdp_get_x11().
  * @param vdp VDPAU instance (as returned by vdp_get_x11())
  * @param device location to store the VDPAU device corresponding to the
-- 
2.13.1



More information about the vlc-devel mailing list