[vlc-commits] va_surface: do the setup in 2 parts

Steve Lhomme git at videolan.org
Sat Jul 1 18:34:29 CEST 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Wed Jun 28 17:38:19 2017 +0200| [2a7e19a1b5e7badb749893834ec1d079305fa1ea] | committer: Jean-Baptiste Kempf

va_surface: do the setup in 2 parts

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

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

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

 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 a4b384c5e0..8e5ae64658 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -50,7 +50,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;
@@ -78,7 +78,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;
@@ -94,6 +94,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))
@@ -107,9 +124,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:
@@ -142,6 +156,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 da2dc4b745..c7a649b167 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -82,7 +82,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);



More information about the vlc-commits mailing list