[vlc-devel] [PATCH 07/10] vdpau: store the xcb_connection_t in the vdpau_decoder_device_t

Steve Lhomme robux4 at ycbcr.xyz
Fri Nov 22 14:12:35 CET 2019


We select the screen the same way it's done in the display module.
---
 modules/hw/vdpau/vlc_vdpau.h                  |  3 +++
 modules/video_output/Makefile.am              |  6 +++--
 modules/video_output/opengl/converter_vdpau.c | 26 ++++++++++++++++++-
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/modules/hw/vdpau/vlc_vdpau.h b/modules/hw/vdpau/vlc_vdpau.h
index abdee8d77d9..07253537462 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -22,6 +22,7 @@
 # include <stdint.h>
 # include <vdpau/vdpau.h>
 #include <vlc_codec.h>
+#include <xcb/xcb.h>
 
 typedef struct vdp_s vdp_t;
 
@@ -278,6 +279,8 @@ typedef struct vlc_vdp_video_field
 typedef struct {
     vdp_t              *vdp;
     VdpDevice          device;
+    xcb_connection_t   *conn;
+    const xcb_screen_t *screen;
 } vdpau_decoder_device_t;
 
 static inline vdpau_decoder_device_t *GetVDPAUOpaqueDevice(vlc_decoder_device *device)
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 23a2bee5cbe..4b43ebe55dc 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -93,8 +93,10 @@ libglconv_vaapi_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_EGL_LIBS)
 
 libglconv_vdpau_plugin_la_SOURCES = video_output/opengl/converter_vdpau.c \
 	video_output/opengl/converter.h hw/vdpau/picture.c hw/vdpau/vlc_vdpau.h
-libglconv_vdpau_plugin_la_CFLAGS = $(AM_CFLAGS) $(VDPAU_CFLAGS)
-libglconv_vdpau_plugin_la_LIBADD = $(LIBDL) libvlc_vdpau.la $(X_LIBS) $(X_PRE_LIBS) -lX11
+libglconv_vdpau_plugin_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS) $(VDPAU_CFLAGS)
+libglconv_vdpau_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/video_output/xcb
+libglconv_vdpau_plugin_la_LIBADD = $(LIBDL) libvlc_vdpau.la libvlc_xcb_events.la \
+	$(X_LIBS) $(X_PRE_LIBS) -lX11
 
 if HAVE_GL
 vout_LTLIBRARIES += libgl_plugin.la
diff --git a/modules/video_output/opengl/converter_vdpau.c b/modules/video_output/opengl/converter_vdpau.c
index 1218cdf820a..951b505cc65 100644
--- a/modules/video_output/opengl/converter_vdpau.c
+++ b/modules/video_output/opengl/converter_vdpau.c
@@ -35,6 +35,7 @@
 #include <vlc_codec.h>
 
 #include "../../hw/vdpau/vlc_vdpau.h"
+#include "../xcb/events.h"
 #include "internal.h"
 
 #define INTEROP_CALL(fct, ...) \
@@ -205,6 +206,7 @@ static void
 DecoderDeviceClose(vlc_decoder_device *device)
 {
     vdpau_decoder_device_t *vdpau_dev = GetVDPAUOpaqueDevice(device);
+    xcb_disconnect(vdpau_dev->conn);
     vdp_release_x11(vdpau_dev->vdp);
 }
 
@@ -212,6 +214,21 @@ static const struct vlc_decoder_device_operations dev_ops = {
     .close = DecoderDeviceClose,
 };
 
+static int xcb_screen_num(xcb_connection_t *conn, const xcb_screen_t *screen)
+{
+    const xcb_setup_t *setup = xcb_get_setup(conn);
+    unsigned snum = 0;
+
+    for (xcb_screen_iterator_t i = xcb_setup_roots_iterator(setup);
+         i.rem > 0; xcb_screen_next(&i))
+    {
+        if (i.data->root == screen->root)
+            return snum;
+        snum++;
+    }
+    return -1;
+}
+
 static int
 DecoderDeviceOpen(vlc_decoder_device *device, vout_window_t *window)
 {
@@ -222,7 +239,14 @@ DecoderDeviceOpen(vlc_decoder_device *device, vout_window_t *window)
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
-    if (vdp_get_x11(window->display.x11, -1,
+    if (vlc_xcb_parent_Create(VLC_OBJECT(device), window,
+                              &sys->conn, &sys->screen) != VLC_SUCCESS)
+    {
+        vlc_obj_free(VLC_OBJECT(device), sys);
+        return VLC_EGENERIC;
+    }
+
+    if (vdp_get_x11(window->display.x11, xcb_screen_num(sys->conn, sys->screen),
                     &sys->vdp, &sys->device) != VDP_STATUS_OK)
     {
         vlc_obj_free(VLC_OBJECT(device), sys);
-- 
2.17.1



More information about the vlc-devel mailing list