[vlc-devel] [PATCH 25/39] directx_va: make each vlc_va_surface_t more independent

Steve Lhomme robux4 at videolabs.io
Fri Jun 2 16:46:28 CEST 2017


Can be free'd independently
---
 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 feadf2b935..d164661848 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -342,18 +342,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;
 }
@@ -366,8 +370,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 );
@@ -390,10 +397,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)
@@ -404,7 +411,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 7bdec0052d..146f408338 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];
     AVVA_DecoderSurface  *hw_surface[MAX_SURFACE_COUNT];
 
     /**
-- 
2.12.1



More information about the vlc-devel mailing list