d3d_fmt: add a function to acquire the resources used in the picture_sys_t
authorSteve Lhomme <robux4@videolabs.io>
Wed, 7 Jun 2017 09:53:26 +0000 (11:53 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 13 Jun 2017 12:44:05 +0000 (14:44 +0200)
This is the reverse of ReleasePictureSys

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/codec/avcodec/d3d11va.c
modules/codec/avcodec/dxva2.c
modules/video_chroma/d3d11_fmt.h
modules/video_chroma/d3d9_fmt.h

index c1d060a..85c6969 100644 (file)
@@ -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;
index e549743..90b2919 100644 (file)
@@ -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;
 }
 
index 6b4de23..6c3f6e0 100644 (file)
@@ -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++) {
index fe96099..2571ecf 100644 (file)
@@ -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);