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

Steve Lhomme robux4 at videolabs.io
Tue Jun 20 17:45:42 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 bde2deca92..bf1edd7009 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -236,7 +236,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;
@@ -248,7 +248,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,
@@ -261,7 +261,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)
@@ -303,7 +303,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 a07bf1c1ea..b1c3f3ecc2 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 b8b37b4bc9..8794792f44 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 308366bb53..860ef9b7f4 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -38,7 +38,9 @@
 
 #define D3D_DecoderType     void
 #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"
@@ -94,14 +96,14 @@ int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx,
                   avctx->coded_width, avctx->coded_height);
 
     for (int i = 0; i < va_pool->surface_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))
         {
             va_pool->surface_count = i;
             return VLC_ENOMEM;
         }
-        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->pf_setup_avcodec_ctx(va);
@@ -110,18 +112,18 @@ ok:
     return VLC_SUCCESS;
 }
 
-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 (int 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;
@@ -130,12 +132,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 2d4add1306..ded66de0ad 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
@@ -28,13 +28,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 be3ee7ab59..843c71325d 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -33,6 +33,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
 {
@@ -47,8 +54,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 *);
@@ -76,14 +83,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 *, int 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