[vlc-commits] d3d_fmt: add a function to acquire the resources used in the picture_sys_t

Steve Lhomme git at videolan.org
Tue Jun 13 15:01:49 CEST 2017


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Wed Jun  7 11:53:26 2017 +0200| [d895ea983063683e477ef5d7dd4f9e8905fd51f1] | committer: Jean-Baptiste Kempf

d3d_fmt: add a function to acquire the resources used in the picture_sys_t

This is the reverse of ReleasePictureSys

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

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

 modules/codec/avcodec/d3d11va.c  | 11 +----------
 modules/codec/avcodec/dxva2.c    |  2 +-
 modules/video_chroma/d3d11_fmt.h | 16 ++++++++++++++++
 modules/video_chroma/d3d9_fmt.h  |  5 +++++
 4 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index c1d060ad88..85c6969c46 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -231,6 +231,7 @@ static struct va_pic_context *CreatePicContext(vlc_va_surface_t *va_surface,
         pic_ctx->picsys.resource[i] = p_resource;
         pic_ctx->picsys.resourceView[i] = resourceView[i];
     }
+    AcquirePictureSys(&pic_ctx->picsys);
     pic_ctx->picsys.context = context;
 done:
     return pic_ctx;
@@ -302,16 +303,6 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
             directx_va_Release(va_surface);
             return VLC_ENOMEM;
         }
-        ID3D11VideoDecoderOutputView_AddRef(pic_ctx->picsys.decoder);
-        ID3D11DeviceContext_AddRef(pic_ctx->picsys.context);
-        for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++)
-        {
-            if (pic_ctx->picsys.resource[i])
-                ID3D11Resource_AddRef(pic_ctx->picsys.resource[i]);
-            if (pic_ctx->picsys.resourceView[i])
-                ID3D11ShaderResourceView_AddRef(pic_ctx->picsys.resourceView[i]);
-        }
-
         pic->context = &pic_ctx->s;
     }
     *data = (uint8_t*)((struct va_pic_context *)pic->context)->picsys.decoder;
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index e549743110..90b2919b70 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -229,7 +229,7 @@ static struct picture_context_t *CreatePicContext(vlc_va_surface_t *va_surface)
     pic_ctx->s.destroy = d3d9_pic_context_destroy;
     pic_ctx->s.copy    = d3d9_pic_context_copy;
     pic_ctx->picsys.surface = va_surface->decoderSurface;
-    IDirect3DSurface9_AddRef(pic_ctx->picsys.surface);
+    AcquirePictureSys(&pic_ctx->picsys);
     return &pic_ctx->s;
 }
 
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 6b4de23cd0..6c3f6e06ba 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -62,6 +62,22 @@ struct va_pic_context
  * (ie not DXGI_FORMAT_UNKNWON) */
 #define KNOWN_DXGI_INDEX   0
 
+static inline void AcquirePictureSys(picture_sys_t *p_sys)
+{
+    for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
+        if (p_sys->resourceView[i])
+            ID3D11ShaderResourceView_AddRef(p_sys->resourceView[i]);
+        if (p_sys->texture[i])
+            ID3D11Texture2D_AddRef(p_sys->texture[i]);
+    }
+    if (p_sys->context)
+        ID3D11DeviceContext_AddRef(p_sys->context);
+    if (p_sys->decoder)
+        ID3D11VideoDecoderOutputView_AddRef(p_sys->decoder);
+    if (p_sys->processorInput)
+        ID3D11VideoProcessorInputView_AddRef(p_sys->processorInput);
+}
+
 static inline void ReleasePictureSys(picture_sys_t *p_sys)
 {
     for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
diff --git a/modules/video_chroma/d3d9_fmt.h b/modules/video_chroma/d3d9_fmt.h
index fe960992a0..2571ecf77b 100644
--- a/modules/video_chroma/d3d9_fmt.h
+++ b/modules/video_chroma/d3d9_fmt.h
@@ -41,6 +41,11 @@ struct va_pic_context
     vlc_va_surface_t           *va_surface;
 };
 
+static inline void AcquirePictureSys(picture_sys_t *p_sys)
+{
+    IDirect3DSurface9_AddRef(p_sys->surface);
+}
+
 static inline void ReleasePictureSys(picture_sys_t *p_sys)
 {
     IDirect3DSurface9_Release(p_sys->surface);



More information about the vlc-commits mailing list