[vlc-devel] [PATCH 16/23] directx_va: make va_pic_context public via va_surface.h

Steve Lhomme robux4 at videolabs.io
Wed Jun 21 14:15:01 CEST 2017


---
 modules/codec/avcodec/d3d11va.c             |  8 ++++----
 modules/codec/avcodec/directx_va.c          |  4 +++-
 modules/codec/avcodec/dxva2.c               | 14 ++++----------
 modules/codec/avcodec/va_surface.c          | 26 ++++++++++++++------------
 modules/codec/avcodec/va_surface.h          | 14 +++++++-------
 modules/codec/avcodec/va_surface_internal.h | 15 +++++++++++----
 modules/video_chroma/d3d11_fmt.h            | 10 +---------
 modules/video_chroma/d3d9_fmt.h             | 10 +---------
 8 files changed, 45 insertions(+), 56 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 38bfb9bb86..73c45955d1 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -237,7 +237,7 @@ done:
     return pic_ctx;
 }
 
-static picture_context_t* NewSurfacePicContext(vlc_va_t *va, vlc_va_surface_t *va_surface, ID3D11VideoDecoderOutputView *surface)
+static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, ID3D11VideoDecoderOutputView *surface)
 {
     ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW];
     ID3D11Resource *p_resource;
@@ -249,7 +249,7 @@ static picture_context_t* NewSurfacePicContext(vlc_va_t *va, vlc_va_surface_t *v
     for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++)
         resourceView[i] = va->sys->resourceView[viewDesc.Texture2D.ArraySlice*D3D11_MAX_SHADER_VIEW + i];
 
-    struct va_pic_context *pic_ctx = CreatePicContext(va_surface,
+    struct va_pic_context *pic_ctx = CreatePicContext(NULL,
                                                   surface,
                                                   p_resource,
                                                   va->sys->d3dctx,
@@ -262,7 +262,7 @@ static picture_context_t* NewSurfacePicContext(vlc_va_t *va, vlc_va_surface_t *v
      * CreatePicContext(), undo one of them otherwise we need an extra release
      * when the pool is emptied */
     ReleasePictureSys(&pic_ctx->picsys);
-    return &pic_ctx->s;
+    return pic_ctx;
 }
 
 static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
@@ -304,7 +304,7 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
     else
 #endif
     {
-        int res = va_pool_Get(va, pic, &va->sys->dx_sys.va_pool);
+        int res = va_pool_Get(&va->sys->dx_sys.va_pool, pic);
         if (unlikely(res != VLC_SUCCESS))
             return res;
     }
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index d68368e6fc..b8f7cc51d6 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -40,7 +40,9 @@
 #define D3D_DecoderType     IUnknown
 #define D3D_DecoderDevice   IUnknown
 #define D3D_DecoderSurface  IUnknown
-typedef struct vlc_va_surface_t vlc_va_surface_t;
+struct picture_sys_t {
+    void *dummy;
+};
 #include "directx_va.h"
 
 #include "avcodec.h"
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index b793cb6c42..6efd1a788a 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -198,10 +198,7 @@ static struct va_pic_context *CreatePicContext(vlc_va_surface_t *, IDirect3DSurf
 static struct picture_context_t *d3d9_pic_context_copy(struct picture_context_t *ctx)
 {
     struct va_pic_context *src_ctx = (struct va_pic_context*)ctx;
-    struct va_pic_context *pic_ctx = CreatePicContext(src_ctx->va_surface, src_ctx->picsys.surface);
-    if (unlikely(pic_ctx==NULL))
-        return NULL;
-    return &pic_ctx->s;
+    return (picture_context_t*)CreatePicContext(src_ctx->va_surface, src_ctx->picsys.surface);
 }
 
 static struct va_pic_context *CreatePicContext(vlc_va_surface_t *va_surface, IDirect3DSurface9 *surface)
@@ -218,13 +215,10 @@ static struct va_pic_context *CreatePicContext(vlc_va_surface_t *va_surface, IDi
     return pic_ctx;
 }
 
-static picture_context_t* NewSurfacePicContext(vlc_va_t *va, vlc_va_surface_t *va_surface, IDirect3DSurface9 *surface)
+static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, IDirect3DSurface9 *surface)
 {
     VLC_UNUSED(va);
-    struct va_pic_context *pic_ctx = CreatePicContext(va_surface, surface);
-    if (unlikely(pic_ctx==NULL))
-        return NULL;
-    return &pic_ctx->s;
+    return CreatePicContext(NULL, surface);
 }
 
 static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
@@ -241,7 +235,7 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
         return VLC_EGENERIC;
     }
 
-    int res = va_pool_Get(va, pic, &sys->dx_sys.va_pool);
+    int res = va_pool_Get(&sys->dx_sys.va_pool, pic);
     if (likely(res==VLC_SUCCESS))
         *data = (uint8_t*)((struct va_pic_context*)pic->context)->picsys.surface;
     return res;
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index 324a823d5d..9d2bd9175e 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -36,7 +36,9 @@
 
 
 #define D3D_DecoderSurface  void
-typedef struct vlc_va_surface_t vlc_va_surface_t;
+struct picture_sys_t {
+    void *dummy;
+};
 #include "va_surface_internal.h"
 
 #include "avcodec.h"
@@ -93,11 +95,11 @@ int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx,
         return VLC_EGENERIC;
 
     for (i = 0; i < count; i++) {
-        vlc_va_surface_t *surface = malloc(sizeof(*surface));
-        if (unlikely(surface==NULL))
+        struct va_pic_context *p_ctx = va_pool->pf_new_surface_context(va, va_pool->hw_surface[i]);
+        if (unlikely(p_ctx==NULL))
             goto done;
-        atomic_init(&surface->refcount, 1);
-        va_pool->surface[i] = surface;
+        atomic_init(&p_ctx->va_surface->refcount, 1);
+        va_pool->surface[i] = p_ctx;
     }
 
     va_pool->surface_width  = surface_width;
@@ -111,18 +113,18 @@ done:
     return err;
 }
 
-static picture_context_t *GetSurface(vlc_va_t *va, va_pool_t *va_pool)
+static picture_context_t *GetSurface(va_pool_t *va_pool)
 {
     for (unsigned i = 0; i < va_pool->surface_count; i++) {
-        vlc_va_surface_t *surface = va_pool->surface[i];
+        struct va_pic_context *surface = va_pool->surface[i];
         uintptr_t expected = 1;
 
-        if (atomic_compare_exchange_strong(&surface->refcount, &expected, 2))
+        if (atomic_compare_exchange_strong(&surface->va_surface->refcount, &expected, 2))
         {
-            picture_context_t *field = va_pool->pf_new_surface_context(va, surface, va_pool->hw_surface[i]);
+            picture_context_t *field = surface->s.copy(&surface->s);
             if (!field)
             {
-                atomic_fetch_sub(&surface->refcount, 1);
+                atomic_fetch_sub(&surface->va_surface->refcount, 1);
                 continue;
             }
             return field;
@@ -131,12 +133,12 @@ static picture_context_t *GetSurface(vlc_va_t *va, va_pool_t *va_pool)
     return NULL;
 }
 
-int va_pool_Get(vlc_va_t *va, picture_t *pic, va_pool_t *va_pool)
+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;
 
-    while ((field = GetSurface(va, va_pool)) == NULL)
+    while ((field = GetSurface(va_pool)) == NULL)
     {
         if (--tries == 0)
             return VLC_ENOITEM;
diff --git a/modules/codec/avcodec/va_surface.h b/modules/codec/avcodec/va_surface.h
index 2f10311a1c..0ce48cb026 100644
--- a/modules/codec/avcodec/va_surface.h
+++ b/modules/codec/avcodec/va_surface.h
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * directx_va.h: DirectX Generic Video Acceleration helpers
+ * va_surface.h: libavcodec Generic Video Acceleration helpers
  *****************************************************************************
  * Copyright (C) 2009 Geoffroy Couprie
  * Copyright (C) 2009 Laurent Aimar
@@ -27,13 +27,13 @@
 #ifndef AVCODEC_VA_SURFACE_H
 #define AVCODEC_VA_SURFACE_H
 
-#include <vlc_common.h>
+#include <vlc_picture.h>
 
-#include <stdatomic.h>
-
-/* */
-struct vlc_va_surface_t {
-    atomic_uintptr_t     refcount;
+struct va_pic_context
+{
+    picture_context_t         s;
+    struct vlc_va_surface_t *va_surface;
+    struct picture_sys_t      picsys;
 };
 
 #endif /* AVCODEC_VA_SURFACE_H */
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index caa3679590..8bfd96f8a4 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -32,6 +32,13 @@
 #include <libavcodec/avcodec.h>
 #include "va.h"
 
+#include <stdatomic.h>
+
+/* */
+typedef struct vlc_va_surface_t {
+    atomic_uintptr_t     refcount;
+} vlc_va_surface_t;
+
 #define MAX_SURFACE_COUNT (64)
 typedef struct
 {
@@ -40,8 +47,8 @@ typedef struct
     int          surface_width;
     int          surface_height;
 
-    vlc_va_surface_t    *surface[MAX_SURFACE_COUNT];
-    D3D_DecoderSurface  *hw_surface[MAX_SURFACE_COUNT];
+    struct va_pic_context  *surface[MAX_SURFACE_COUNT];
+    D3D_DecoderSurface     *hw_surface[MAX_SURFACE_COUNT];
 
     int (*pf_create_device)(vlc_va_t *);
     void (*pf_destroy_device)(vlc_va_t *);
@@ -70,14 +77,14 @@ typedef struct
     /**
      * Create a new context for the surface being acquired
      */
-    picture_context_t* (*pf_new_surface_context)(vlc_va_t *, vlc_va_surface_t *, D3D_DecoderSurface *);
+    struct va_pic_context* (*pf_new_surface_context)(vlc_va_t *, D3D_DecoderSurface *);
 
 } va_pool_t;
 
 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_Get(vlc_va_t *, picture_t *, va_pool_t *);
+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);
 
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 25130f147b..13e109e5ed 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -32,8 +32,6 @@
 
 DEFINE_GUID(GUID_CONTEXT_MUTEX, 0x472e8835, 0x3f8e, 0x4f93, 0xa0, 0xcb, 0x25, 0x79, 0x77, 0x6c, 0xed, 0x86);
 
-typedef struct vlc_va_surface_t vlc_va_surface_t;
-
 /* owned by the vout for VLC_CODEC_D3D11_OPAQUE */
 struct picture_sys_t
 {
@@ -50,13 +48,7 @@ struct picture_sys_t
     DXGI_FORMAT                   formatTexture;
 };
 
-/* owned by the hardware decoder */
-struct va_pic_context
-{
-    picture_context_t         s;
-    vlc_va_surface_t          *va_surface;
-    struct picture_sys_t      picsys;
-};
+#include "../codec/avcodec/va_surface.h"
 
 /* index to use for texture/resource that use a known DXGI format
  * (ie not DXGI_FORMAT_UNKNWON) */
diff --git a/modules/video_chroma/d3d9_fmt.h b/modules/video_chroma/d3d9_fmt.h
index 2571ecf77b..eb9a1ac9b5 100644
--- a/modules/video_chroma/d3d9_fmt.h
+++ b/modules/video_chroma/d3d9_fmt.h
@@ -25,21 +25,13 @@
 
 #include <vlc_picture.h>
 
-typedef struct vlc_va_surface_t vlc_va_surface_t;
-
 /* owned by the vout for VLC_CODEC_D3D9_OPAQUE */
 struct picture_sys_t
 {
     LPDIRECT3DSURFACE9 surface;
 };
 
-/* owned by the hardware decoder */
-struct va_pic_context
-{
-    picture_context_t          s;
-    struct picture_sys_t       picsys;
-    vlc_va_surface_t           *va_surface;
-};
+#include "../codec/avcodec/va_surface.h"
 
 static inline void AcquirePictureSys(picture_sys_t *p_sys)
 {
-- 
2.12.1



More information about the vlc-devel mailing list