[vlc-devel] [PATCH 2/3] va_surface: do the setup in 2 parts

Steve Lhomme robux4 at videolabs.io
Wed Jun 28 17:38:19 CEST 2017


1/ allocate the decoder surfaces
2/ allocate the internal va_surface_t

--
replaces https://patches.videolan.org/patch/17140/
- for the call in directx_va
---
 modules/codec/avcodec/directx_va.c          |  6 ++++--
 modules/codec/avcodec/va_surface.c          | 27 ++++++++++++++++++++++-----
 modules/codec/avcodec/va_surface_internal.h |  3 ++-
 3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index b8f7cc51d6..9705ae2f2c 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -315,8 +315,10 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, const AVCodecContext *
     if ( avctx->active_thread_type & FF_THREAD_FRAME )
         surface_count += avctx->thread_count;
 
-    return va_pool_Setup(va, &dx_sys->va_pool, avctx,
-                         surface_count, surface_alignment);
+    int err = va_pool_SetupDecoder(va, &dx_sys->va_pool, avctx, surface_count, surface_alignment);
+    if (err != VLC_SUCCESS)
+        return err;
+    return va_pool_SetupSurfaces(va, &dx_sys->va_pool, surface_count);
 }
 
 void directx_va_Close(vlc_va_t *va, directx_sys_t *dx_sys)
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index 9110d96e57..dcd512527f 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -54,7 +54,7 @@ static void DestroyVideoDecoder(vlc_va_t *va, va_pool_t *va_pool)
 }
 
 /* */
-int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx, unsigned count, int alignment)
+int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx, unsigned count, int alignment)
 {
     int err = VLC_ENOMEM;
     unsigned i = va_pool->surface_count;
@@ -82,7 +82,7 @@ int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx,
     DestroyVideoDecoder(va, va_pool);
 
     /* */
-    msg_Dbg(va, "va_pool_Setup id %d %dx%d count: %d", avctx->codec_id, avctx->coded_width, avctx->coded_height, count);
+    msg_Dbg(va, "va_pool_SetupDecoder id %d %dx%d count: %d", avctx->codec_id, avctx->coded_width, avctx->coded_height, count);
 
     if (count > MAX_SURFACE_COUNT)
         return VLC_EGENERIC;
@@ -98,6 +98,23 @@ int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx,
     if (va_pool->pf_create_decoder_surfaces(va, avctx->codec_id, &fmt, count))
         return VLC_EGENERIC;
 
+    va_pool->surface_width  = surface_width;
+    va_pool->surface_height = surface_height;
+    err = VLC_SUCCESS;
+
+done:
+    va_pool->surface_count = i;
+    if (err == VLC_SUCCESS)
+        va_pool->pf_setup_avcodec_ctx(va);
+
+    return err;
+}
+
+int va_pool_SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool, unsigned count)
+{
+    int err = VLC_ENOMEM;
+    unsigned i = va_pool->surface_count;
+
     for (i = 0; i < count; i++) {
         struct vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface));
         if (unlikely(p_surface==NULL))
@@ -111,9 +128,6 @@ int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx,
         va_pool->surface[i]->va_surface = p_surface;
         atomic_init(&va_pool->surface[i]->va_surface->refcount, 1);
     }
-
-    va_pool->surface_width  = surface_width;
-    va_pool->surface_height = surface_height;
     err = VLC_SUCCESS;
 
 done:
@@ -146,6 +160,9 @@ int va_pool_Get(va_pool_t *va_pool, picture_t *pic)
     unsigned tries = (CLOCK_FREQ + VOUT_OUTMEM_SLEEP) / VOUT_OUTMEM_SLEEP;
     picture_context_t *field;
 
+    if (va_pool->surface_count == 0)
+        return VLC_ENOITEM;
+
     while ((field = GetSurface(va_pool)) == NULL)
     {
         if (--tries == 0)
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index ee83dcc322..7a566dbee8 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -80,7 +80,8 @@ typedef struct
 
 int va_pool_Open(vlc_va_t *, va_pool_t *);
 void va_pool_Close(vlc_va_t *va, va_pool_t *);
-int va_pool_Setup(vlc_va_t *, va_pool_t *, const AVCodecContext *, unsigned count, int alignment);
+int va_pool_SetupDecoder(vlc_va_t *, va_pool_t *, const AVCodecContext *, unsigned count, int alignment);
+int va_pool_SetupSurfaces(vlc_va_t *, va_pool_t *, unsigned count);
 int va_pool_Get(va_pool_t *, picture_t *);
 void va_surface_AddRef(vlc_va_surface_t *surface);
 void va_surface_Release(vlc_va_surface_t *surface);
-- 
2.12.1



More information about the vlc-devel mailing list