[vlc-commits] vdpau: factor output surface allocation

Rémi Denis-Courmont git at videolan.org
Mon Dec 24 18:23:15 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 24 16:18:09 2018 +0200| [9ca48ab2e06440fe442756b461f30ad90e46f784] | committer: Rémi Denis-Courmont

vdpau: factor output surface allocation

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9ca48ab2e06440fe442756b461f30ad90e46f784
---

 modules/hw/vdpau/Makefile.am                  |  2 +-
 modules/hw/vdpau/display.c                    | 56 ++-------------------------
 modules/hw/vdpau/picture.c                    | 42 ++++++++++++++++++++
 modules/hw/vdpau/vlc_vdpau.h                  |  3 ++
 modules/video_output/Makefile.am              |  2 +-
 modules/video_output/opengl/converter_vdpau.c | 41 +++-----------------
 6 files changed, 56 insertions(+), 90 deletions(-)

diff --git a/modules/hw/vdpau/Makefile.am b/modules/hw/vdpau/Makefile.am
index 812f068df8..2d3c8c24a0 100644
--- a/modules/hw/vdpau/Makefile.am
+++ b/modules/hw/vdpau/Makefile.am
@@ -30,7 +30,7 @@ libvdpau_chroma_plugin_la_SOURCES = hw/vdpau/chroma.c hw/vdpau/picture.c
 libvdpau_chroma_plugin_la_CFLAGS = $(AM_CFLAGS) $(VDPAU_CFLAGS)
 libvdpau_chroma_plugin_la_LIBADD = libvlc_vdpau.la
 
-libvdpau_display_plugin_la_SOURCES = hw/vdpau/display.c
+libvdpau_display_plugin_la_SOURCES = hw/vdpau/display.c hw/vdpau/picture.c
 libvdpau_display_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/video_output/xcb
 libvdpau_display_plugin_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS) $(VDPAU_CFLAGS)
 libvdpau_display_plugin_la_LIBADD = libvlc_vdpau.la libvlc_xcb_events.la \
diff --git a/modules/hw/vdpau/display.c b/modules/hw/vdpau/display.c
index b01809c548..25db2e28ae 100644
--- a/modules/hw/vdpau/display.c
+++ b/modules/hw/vdpau/display.c
@@ -70,53 +70,6 @@ struct vout_display_sys_t
     unsigned height;
 };
 
-static void pictureSys_DestroyVDPAU(vlc_vdp_output_surface_t *psys)
-{
-    vdp_output_surface_destroy(psys->vdp, psys->surface);
-    vdp_release_x11(psys->vdp);
-    free(psys);
-}
-
-static void PictureDestroyVDPAU(picture_t *pic)
-{
-    pictureSys_DestroyVDPAU(pic->p_sys);
-}
-
-static VdpStatus picture_NewVDPAU(vdp_t *vdp, VdpRGBAFormat rgb_fmt,
-                                  const video_format_t *restrict fmt,
-                                  picture_t **restrict picp)
-{
-    vlc_vdp_output_surface_t *psys = malloc(sizeof (*psys));
-    if (unlikely(psys == NULL))
-        return VDP_STATUS_RESOURCES;
-
-    psys->vdp = vdp_hold_x11(vdp, &psys->device);
-
-    VdpStatus err = vdp_output_surface_create(psys->vdp, psys->device,
-                          rgb_fmt, fmt->i_visible_width, fmt->i_visible_height,
-                                              &psys->surface);
-    if (err != VDP_STATUS_OK)
-    {
-        vdp_release_x11(psys->vdp);
-        free(psys);
-        return err;
-    }
-
-    picture_resource_t res = {
-        .p_sys = psys,
-        .pf_destroy = PictureDestroyVDPAU,
-    };
-
-    picture_t *pic = picture_NewFromResource(fmt, &res);
-    if (unlikely(pic == NULL))
-    {
-        pictureSys_DestroyVDPAU(psys);
-        return VDP_STATUS_RESOURCES;
-    }
-    *picp = pic;
-    return VDP_STATUS_OK;
-}
-
 static picture_pool_t *PoolAlloc(vout_display_t *vd, unsigned requested_count)
 {
     vout_display_sys_t *sys = vd->sys;
@@ -125,12 +78,11 @@ static picture_pool_t *PoolAlloc(vout_display_t *vd, unsigned requested_count)
     unsigned count = 0;
     while (count < requested_count)
     {
-        VdpStatus err = picture_NewVDPAU(sys->vdp, sys->rgb_fmt, &vd->fmt,
-                                         pics + count);
-        if (err != VDP_STATUS_OK)
+        pics[count] = vlc_vdp_output_surface_create(sys->vdp, sys->rgb_fmt,
+                                                    &vd->fmt);
+        if (pics[count] == NULL)
         {
-            msg_Err(vd, "%s creation failure: %s", "output surface",
-                    vdp_get_error_string(sys->vdp, err));
+            msg_Err(vd, "%s creation failure", "output surface");
             break;
         }
         count++;
diff --git a/modules/hw/vdpau/picture.c b/modules/hw/vdpau/picture.c
index d48d937505..be1940ab22 100644
--- a/modules/hw/vdpau/picture.c
+++ b/modules/hw/vdpau/picture.c
@@ -126,3 +126,45 @@ VdpStatus vlc_vdp_video_attach(vdp_t *vdp, VdpVideoSurface surface,
     pic->context = &field->context;
     return VDP_STATUS_OK;
 }
+
+static void vlc_vdp_output_surface_destroy(picture_t *pic)
+{
+    vlc_vdp_output_surface_t *sys = pic->p_sys;
+
+    vdp_output_surface_destroy(sys->vdp, sys->surface);
+    vdp_release_x11(sys->vdp);
+    free(sys);
+}
+
+picture_t *vlc_vdp_output_surface_create(vdp_t *vdp, VdpRGBAFormat rgb_fmt,
+                                         const video_format_t *restrict fmt)
+{
+    vlc_vdp_output_surface_t *sys = malloc(sizeof (*sys));
+    if (unlikely(sys == NULL))
+        return NULL;
+
+    sys->vdp = vdp_hold_x11(vdp, &sys->device);
+
+    VdpStatus err = vdp_output_surface_create(vdp, sys->device, rgb_fmt,
+        fmt->i_visible_width, fmt->i_visible_height, &sys->surface);
+    if (err != VDP_STATUS_OK)
+    {
+error:
+        vdp_release_x11(vdp);
+        free(sys);
+        return NULL;
+    }
+
+    picture_resource_t res = {
+        .p_sys = sys,
+        .pf_destroy = vlc_vdp_output_surface_destroy,
+    };
+
+    picture_t *pic = picture_NewFromResource(fmt, &res);
+    if (unlikely(pic == NULL))
+    {
+        vdp_output_surface_destroy(vdp, sys->surface);
+        goto error;
+    }
+    return pic;
+}
diff --git a/modules/hw/vdpau/vlc_vdpau.h b/modules/hw/vdpau/vlc_vdpau.h
index 11070d2228..e29013620a 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -306,4 +306,7 @@ typedef struct vlc_vdp_output_surface
     void *gl_nv_surface;
 } vlc_vdp_output_surface_t;
 
+picture_t *vlc_vdp_output_surface_create(vdp_t *vdp, VdpRGBAFormat rgb_fmt,
+                                         const video_format_t *restrict fmt);
+
 #endif
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 8051b5e554..bd3363954e 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -95,7 +95,7 @@ libglconv_vaapi_drm_plugin_la_LIBADD = $(LIBVA_LIBS) $(LIBVA_EGL_LIBS) \
 	$(LIBVA_DRM_LIBS)
 
 libglconv_vdpau_plugin_la_SOURCES = video_output/opengl/converter_vdpau.c \
-	video_output/opengl/converter.h hw/vdpau/vlc_vdpau.h
+	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
 
diff --git a/modules/video_output/opengl/converter_vdpau.c b/modules/video_output/opengl/converter_vdpau.c
index 5671ea30b4..00275771b3 100644
--- a/modules/video_output/opengl/converter_vdpau.c
+++ b/modules/video_output/opengl/converter_vdpau.c
@@ -63,16 +63,6 @@ static PFNGLVDPAUSURFACEACCESSNVPROC            _glVDPAUSurfaceAccessNV;
 static PFNGLVDPAUMAPSURFACESNVPROC              _glVDPAUMapSurfacesNV;
 static PFNGLVDPAUUNMAPSURFACESNVPROC            _glVDPAUUnmapSurfacesNV;
 
-static void
-pool_pic_destroy_cb(picture_t *pic)
-{
-    vlc_vdp_output_surface_t *p_sys = pic->p_sys;
-
-    vdp_output_surface_destroy(p_sys->vdp, p_sys->surface);
-    vdp_release_x11(p_sys->vdp);
-    free(p_sys);
-}
-
 static picture_pool_t *
 tc_vdpau_gl_get_pool(opengl_tex_converter_t const *tc,
                      unsigned int requested_count)
@@ -83,36 +73,15 @@ tc_vdpau_gl_get_pool(opengl_tex_converter_t const *tc,
     unsigned int i;
     for (i = 0; i < requested_count; ++i)
     {
-        VdpOutputSurface surface;
-
-        VdpStatus st;
-        if ((st = vdp_output_surface_create(priv->vdp, priv->vdp_device,
-                                            VDP_RGBA_FORMAT_B8G8R8A8,
-                                            tc->fmt.i_visible_width,
-                                            tc->fmt.i_visible_height,
-                                            &surface)) != VDP_STATUS_OK)
+        pics[i] = vlc_vdp_output_surface_create(priv->vdp,
+                                                VDP_RGBA_FORMAT_B8G8R8A8,
+                                                &tc->fmt);
+        if (pics[i] == NULL)
             goto error;
 
-        vlc_vdp_output_surface_t *picsys = malloc(sizeof (*picsys));
-        if (!picsys) {
-            vdp_output_surface_destroy(priv->vdp, surface);
-            goto error;
-        }
+        vlc_vdp_output_surface_t *picsys = pics[i]->p_sys;
 
-        picsys->vdp = vdp_hold_x11(priv->vdp, NULL);
-        picsys->device = priv->vdp_device;
-        picsys->surface = surface;
         *(GLvdpauSurfaceNV *)&picsys->gl_nv_surface = 0;
-
-        picture_resource_t rsc = { .p_sys = picsys,
-                                   .pf_destroy = pool_pic_destroy_cb };
-
-        pics[i] = picture_NewFromResource(&tc->fmt, &rsc);
-        if (!pics[i]) {
-            free(picsys);
-            vdp_output_surface_destroy(priv->vdp, surface);
-            goto error;
-        }
     }
 
     picture_pool_t *pool = picture_pool_New(requested_count, pics);



More information about the vlc-commits mailing list