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

Steve Lhomme robux4 at videolabs.io
Wed Jun 28 17:33:49 CEST 2017


1/ allocate the decoder surfaces
2/ allocate the internal va_surface_t
---
 modules/codec/avcodec/va_surface.c          | 27 ++++++++++++++++++++++-----
 modules/codec/avcodec/va_surface_internal.h |  3 ++-
 2 files changed, 24 insertions(+), 6 deletions(-)

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