[vlc-commits] directx_va: let the va deal with the vlc_va_surface_t storage

Steve Lhomme git at videolan.org
Tue Jun 13 14:59:38 CEST 2017


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Wed May 17 17:28:06 2017 +0200| [79d7926ae5b02918fa269c22136144339beddf20] | committer: Jean-Baptiste Kempf

directx_va: let the va deal with the vlc_va_surface_t storage

To move away from the picture context

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

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

 modules/codec/avcodec/d3d11va.c    | 20 ++++++++++++++++----
 modules/codec/avcodec/directx_va.c | 15 ++++-----------
 modules/codec/avcodec/directx_va.h |  4 ++--
 modules/codec/avcodec/dxva2.c      | 15 +++++++++++++--
 4 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index b9f8d051f5..89500f1868 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -299,7 +299,9 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
     if (p_sys == NULL)
     {
         assert(!va->sys->b_extern_pool);
-        return directx_va_Get(va, &va->sys->dx_sys, pic, data);
+        vlc_va_surface_t *va_surface = directx_va_Get(va, &va->sys->dx_sys, data);
+        pic->context = va_surface;
+        return va_surface ? VLC_SUCCESS : VLC_EGENERIC;
     }
 
     if (p_sys->decoder == NULL)
@@ -331,7 +333,9 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
     *data = p_sys->decoder;
     return VLC_SUCCESS;
 #else
-    return directx_va_Get(va, &va->sys->dx_sys, pic, data);
+    vlc_va_surface_t *va_surface = directx_va_Get(va, &va->sys->dx_sys, data);
+    pic->context = va_surface;
+    return va_surface ? VLC_SUCCESS : VLC_EGENERIC;
 #endif
 }
 
@@ -363,6 +367,14 @@ static vlc_fourcc_t d3d11va_fourcc(enum PixelFormat swfmt)
     }
 }
 
+static void ReleasePic(void *opaque, uint8_t *data)
+{
+    (void)data;
+    picture_t *pic = opaque;
+    directx_va_Release(pic->context);
+    pic->context = NULL;
+    picture_Release(pic);
+}
 
 static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
                 const es_format_t *fmt, picture_sys_t *p_sys)
@@ -448,9 +460,9 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     va->setup   = Setup;
     va->get     = Get;
 #if D3D11_DIRECT_DECODE
-    va->release = sys->b_extern_pool ? NULL : directx_va_Release;
+    va->release = sys->b_extern_pool ? NULL : ReleasePic;
 #else
-    va->release = directx_va_Release;
+    va->release = ReleasePic;
 #endif
     va->extract = Extract;
 
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 63307a6ae5..664e686d39 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -382,11 +382,11 @@ void DestroyVideoDecoder(vlc_va_t *va, directx_sys_t *dx_sys)
 }
 
 /* FIXME it is nearly common with VAAPI */
-int directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys, picture_t *pic, uint8_t **data)
+vlc_va_surface_t *directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys, uint8_t **data)
 {
     /* Check the device */
     if (dx_sys->pf_check_device(va)!=VLC_SUCCESS)
-        return VLC_EGENERIC;
+        return NULL;
 
     vlc_mutex_lock( &dx_sys->surface_lock );
 
@@ -414,23 +414,16 @@ int directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys, picture_t *pic, uint8_t
     surface->refcount = 1;
     surface->order = ++dx_sys->surface_order;
     *data = (void *)dx_sys->hw_surface[i];
-    pic->context = surface;
 
     vlc_mutex_unlock( &dx_sys->surface_lock );
 
-    return VLC_SUCCESS;
+    return surface;
 }
 
-void directx_va_Release(void *opaque, uint8_t *data)
+void directx_va_Release(vlc_va_surface_t *surface)
 {
-    picture_t *pic = opaque;
-    vlc_va_surface_t *surface = pic->context;
     vlc_mutex_lock( surface->p_lock );
-
     surface->refcount--;
-    pic->context = NULL;
-    picture_Release(pic);
-
     vlc_mutex_unlock( surface->p_lock );
 }
 
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 0561dcdae1..a7e20d39ea 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -137,8 +137,8 @@ typedef struct
 int directx_va_Open(vlc_va_t *, directx_sys_t *, AVCodecContext *ctx, const es_format_t *fmt, bool b_dll);
 void directx_va_Close(vlc_va_t *, directx_sys_t *);
 int directx_va_Setup(vlc_va_t *, directx_sys_t *, AVCodecContext *avctx);
-int directx_va_Get(vlc_va_t *, directx_sys_t *, picture_t *pic, uint8_t **data);
-void directx_va_Release(void *opaque, uint8_t *data);
+vlc_va_surface_t *directx_va_Get(vlc_va_t *, directx_sys_t *, uint8_t **data);
+void directx_va_Release(vlc_va_surface_t *surface);
 char *directx_va_GetDecoderName(const GUID *guid);
 
 #endif /* AVCODEC_DIRECTX_VA_H */
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index b289c194f4..f510704971 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -220,7 +220,9 @@ static int CheckDevice(vlc_va_t *va)
 
 static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
 {
-    return directx_va_Get(va, &va->sys->dx_sys, pic, data);
+    vlc_va_surface_t *va_surface = directx_va_Get(va, &va->sys->dx_sys, data);
+    pic->context = va_surface;
+    return va_surface ? VLC_SUCCESS : VLC_EGENERIC;
 }
 
 static void Close(vlc_va_t *va, AVCodecContext *ctx)
@@ -252,6 +254,15 @@ static vlc_fourcc_t d3d9va_fourcc(enum PixelFormat swfmt)
     }
 }
 
+static void ReleasePic(void *opaque, uint8_t *data)
+{
+    (void)data;
+    picture_t *pic = opaque;
+    directx_va_Release(pic->context);
+    pic->context = NULL;
+    picture_Release(pic);
+}
+
 static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
                 const es_format_t *fmt, picture_sys_t *p_sys)
 {
@@ -316,7 +327,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     va->description = DxDescribe(sys);
     va->setup   = Setup;
     va->get     = Get;
-    va->release = directx_va_Release;
+    va->release = ReleasePic;
     va->extract = Extract;
     return VLC_SUCCESS;
 



More information about the vlc-commits mailing list