[vlc-devel] [PATCH 10/10] avcodec: vdpau: don't store the vdp in the video context

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


It's already in the decoder device attached to the video context.

Now the video context private is just a table of vlc_vdp_video_field_t*
---
 modules/hw/vdpau/avcodec.c | 52 +++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 32 deletions(-)

diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index 72d75c19a52..7f32d6e0a8e 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -40,12 +40,6 @@
 #include "vlc_vdpau.h"
 #include "../../codec/avcodec/va.h"
 
-struct video_context_private
-{
-    vdp_t *vdp;
-    vlc_vdp_video_field_t *pool[];
-};
-
 struct vlc_va_sys_t
 {
     VdpDevice device;
@@ -56,40 +50,39 @@ struct vlc_va_sys_t
     vlc_video_context *vctx;
 };
 
-static inline struct video_context_private *GetVDPAUContextPrivate(vlc_video_context *vctx)
+static inline vlc_vdp_video_field_t **GetVDPAUContextPrivate(vlc_video_context *vctx)
 {
-    return (struct video_context_private *)
+    return (vlc_vdp_video_field_t **)
         vlc_video_context_GetPrivate( vctx, VLC_VIDEO_CONTEXT_VDPAU );
 }
 
-static vlc_vdp_video_field_t *CreateSurface(vlc_va_t *va)
+static vlc_vdp_video_field_t *CreateSurface(vlc_va_t *va, vdpau_decoder_device_t *vdpau_decoder)
 {
     vlc_va_sys_t *sys = va->sys;
-    struct video_context_private *vctx_priv = GetVDPAUContextPrivate(sys->vctx);
     VdpVideoSurface surface;
     VdpStatus err;
 
-    err = vdp_video_surface_create(vctx_priv->vdp, sys->device, sys->type,
+    err = vdp_video_surface_create(vdpau_decoder->vdp, vdpau_decoder->device, sys->type,
                                    sys->width, sys->height, &surface);
     if (err != VDP_STATUS_OK)
     {
         msg_Err(va, "%s creation failure: %s", "video surface",
-                vdp_get_error_string(vctx_priv->vdp, err));
+                vdp_get_error_string(vdpau_decoder->vdp, err));
         return NULL;
     }
 
-    vlc_vdp_video_field_t *field = vlc_vdp_video_create(vctx_priv->vdp, surface);
+    vlc_vdp_video_field_t *field = vlc_vdp_video_create(vdpau_decoder->vdp, surface);
     if (unlikely(field == NULL))
-        vdp_video_surface_destroy(vctx_priv->vdp, surface);
+        vdp_video_surface_destroy(vdpau_decoder->vdp, surface);
     return field;
 }
 
 static vlc_vdp_video_field_t *GetSurface(vlc_va_sys_t *sys)
 {
     vlc_vdp_video_field_t *f;
-    struct video_context_private *vctx_priv = GetVDPAUContextPrivate(sys->vctx);
+    vlc_vdp_video_field_t **pool = GetVDPAUContextPrivate(sys->vctx);
 
-    for (unsigned i = 0; (f = vctx_priv->pool[i]) != NULL; i++)
+    for (unsigned i = 0; (f = pool[i]) != NULL; i++)
     {
         uintptr_t expected = 1;
 
@@ -146,9 +139,9 @@ static const struct vlc_va_operations ops = { Lock, Close, };
 
 static void DestroyVDPAUVideoContext(void *private)
 {
-    struct video_context_private *vctx_priv = private;
-    for (unsigned i = 0; vctx_priv->pool[i] != NULL; i++)
-        vlc_vdp_video_destroy(vctx_priv->pool[i]);
+    vlc_vdp_video_field_t **pool = private;
+    for (unsigned i = 0; pool[i] != NULL; i++)
+        vlc_vdp_video_destroy(pool[i]);
 }
 
 const struct vlc_video_context_operations vdpau_vctx_ops = {
@@ -212,8 +205,7 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
        return VLC_ENOMEM;
 
     sys->vctx = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_VDPAU,
-                                          sizeof(struct video_context_private) +
-                                           (refs + 1) * sizeof (vlc_vdp_video_field_t),
+                                           (refs + 1) * sizeof (vlc_vdp_video_field_t *),
                                           &vdpau_vctx_ops );
     if (sys->vctx == NULL)
     {
@@ -221,24 +213,22 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
         return VLC_ENOMEM;
     }
 
-    struct video_context_private *vctx_priv = GetVDPAUContextPrivate(sys->vctx);
+    vlc_vdp_video_field_t **pool = GetVDPAUContextPrivate(sys->vctx);
 
     sys->type = type;
     sys->width = width;
     sys->height = height;
     sys->hwaccel_context = NULL;
     vdpau_decoder_device_t *vdpau_decoder = GetVDPAUOpaqueDevice(dec_device);
-    vctx_priv->vdp = vdpau_decoder->vdp;
-    sys->device = vdpau_decoder->device;
 
     unsigned flags = AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH;
 
-    err = vdp_get_proc_address(vctx_priv->vdp, sys->device,
+    err = vdp_get_proc_address(vdpau_decoder->vdp, vdpau_decoder->device,
                                VDP_FUNC_ID_GET_PROC_ADDRESS, &func);
     if (err != VDP_STATUS_OK)
         goto error;
 
-    if (av_vdpau_bind_context(avctx, sys->device, func, flags))
+    if (av_vdpau_bind_context(avctx, vdpau_decoder->device, func, flags))
         goto error;
     sys->hwaccel_context = avctx->hwaccel_context;
     va->sys = sys;
@@ -246,23 +236,21 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
     unsigned i = 0;
     while (i < refs)
     {
-        vctx_priv->pool[i] = CreateSurface(va);
-        if (vctx_priv->pool[i] == NULL)
+        pool[i] = CreateSurface(va, vdpau_decoder);
+        if (pool[i] == NULL)
             break;
         i++;
     }
-    vctx_priv->pool[i] = NULL;
+    pool[i] = NULL;
 
     if (i < refs)
     {
         msg_Err(va, "not enough video RAM");
-        while (i > 0)
-            vlc_vdp_video_destroy(vctx_priv->pool[--i]);
         goto error;
     }
 
     const char *infos;
-    if (vdp_get_information_string(vctx_priv->vdp, &infos) == VDP_STATUS_OK)
+    if (vdp_get_information_string(vdpau_decoder->vdp, &infos) == VDP_STATUS_OK)
         msg_Info(va, "Using %s", infos);
 
     *vtcx_out = sys->vctx;
-- 
2.17.1



More information about the vlc-devel mailing list