[vlc-commits] directx_va: make each vlc_va_surface_t more independent

Steve Lhomme git at videolan.org
Tue Jun 13 15:00:52 CEST 2017


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Mon May 29 14:28:17 2017 +0200| [1ff9f287813b559cf46f3798e017919d1563cdb6] | committer: Jean-Baptiste Kempf

directx_va: make each vlc_va_surface_t more independent

Can be free'd independently

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/codec/avcodec/directx_va.c | 29 ++++++++++++++++++-----------
 modules/codec/avcodec/directx_va.h |  2 +-
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 3d2703611b..a5a7783d28 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -348,18 +348,22 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, AVCodecContext *avctx)
                   dx_sys->surface_width, dx_sys->surface_height,
                   avctx->coded_width, avctx->coded_height);
 
-    dx_sys->pf_setup_avcodec_ctx(va);
-
     for (int i = 0; i < dx_sys->surface_count; i++) {
-        vlc_va_surface_t *surface = &dx_sys->surface[i];
+        vlc_va_surface_t *surface = malloc(sizeof(*surface));
+        if (unlikely(surface==NULL))
+        {
+            dx_sys->surface_count = i;
+            return VLC_ENOMEM;
+        }
         surface->refcount = 0;
         surface->order = 0;
         surface->p_lock = &dx_sys->surface_lock;
         surface->p_pic = dx_sys->pf_alloc_surface_pic(va, &fmt, i);
-        if (unlikely(surface->p_pic == NULL))
-            return VLC_EGENERIC;
+        dx_sys->surface[i] = surface;
     }
 
+    dx_sys->pf_setup_avcodec_ctx(va);
+
 ok:
     return VLC_SUCCESS;
 }
@@ -372,8 +376,11 @@ void DestroyVideoDecoder(vlc_va_t *va, directx_sys_t *dx_sys)
         IUnknown_Release( dx_sys->hw_surface[i] );
 
     for (int i = 0; i < dx_sys->surface_count; i++)
-        if (dx_sys->surface[i].p_pic)
-            picture_Release(dx_sys->surface[i].p_pic);
+    {
+        if (dx_sys->surface[i]->p_pic)
+            picture_Release(dx_sys->surface[i]->p_pic);
+        free(dx_sys->surface[i]);
+    }
 
     if (dx_sys->decoder)
         IUnknown_Release( dx_sys->decoder );
@@ -396,10 +403,10 @@ vlc_va_surface_t *directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys, uint8_t **
     int i, old = -1, old_used = -1;
 
     for (i = 0; i < dx_sys->surface_count; i++) {
-        vlc_va_surface_t *surface = &dx_sys->surface[i];
-        if (((old == -1 || surface->order < dx_sys->surface[old].order)) && !surface->refcount)
+        vlc_va_surface_t *surface = dx_sys->surface[i];
+        if (((old == -1 || surface->order < dx_sys->surface[old]->order)) && !surface->refcount)
             old = i;
-        if (old_used == -1 || surface->order < dx_sys->surface[old_used].order)
+        if (old_used == -1 || surface->order < dx_sys->surface[old_used]->order)
             old_used = i;
     }
     if (old >= 0)
@@ -410,7 +417,7 @@ vlc_va_surface_t *directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys, uint8_t **
         i = old_used;
     }
 
-    vlc_va_surface_t *surface = &dx_sys->surface[i];
+    vlc_va_surface_t *surface = dx_sys->surface[i];
 
     surface->refcount = 1;
     surface->order = ++dx_sys->surface_order;
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 46b83366df..1a6640470c 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -83,7 +83,7 @@ typedef struct
     int          surface_height;
 
     vlc_mutex_t      surface_lock;
-    vlc_va_surface_t surface[MAX_SURFACE_COUNT];
+    vlc_va_surface_t     *surface[MAX_SURFACE_COUNT];
     D3D_DecoderSurface  *hw_surface[MAX_SURFACE_COUNT];
 
     /**



More information about the vlc-commits mailing list