[vlc-commits] va_surface: release all the resources when the va_pool is finally released

Steve Lhomme git at videolan.org
Fri Oct 18 16:47:42 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Oct 18 16:44:16 2019 +0200| [8a823165b107d194d5002e2ba605677a42dfa65b] | committer: Steve Lhomme

va_surface: release all the resources when the va_pool is finally released

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

 modules/codec/avcodec/d3d11va.c             | 31 ++++++++++-------------------
 modules/codec/avcodec/dxva2.c               | 22 ++++++++++++--------
 modules/codec/avcodec/va_surface.c          | 17 ++++++----------
 modules/codec/avcodec/va_surface_internal.h |  9 ++++-----
 4 files changed, 35 insertions(+), 44 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index be906950e3..bafda9186f 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -121,7 +121,6 @@ struct vlc_va_sys_t
 
 /* */
 static int D3dCreateDevice(vlc_va_t *);
-static void D3dDestroyDevice(vlc_va_t *);
 
 static int DxGetInputList(vlc_va_t *, input_list_t *);
 static int DxSetupOutput(vlc_va_t *, const directx_va_mode_t *, const video_format_t *);
@@ -250,10 +249,6 @@ static void Close(vlc_va_t *va)
 
     if (sys->vctx)
         vlc_video_context_Release(sys->vctx);
-
-    D3D11_Destroy( &sys->hd3d );
-
-    free(sys);
 }
 
 static const struct vlc_va_operations ops = { Get, Close, };
@@ -335,9 +330,8 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
 
     struct va_pool_cfg pool_cfg = {
         D3dCreateDevice,
-        D3dDestroyDevice,
-        DxCreateDecoderSurfaces,
         DxDestroySurfaces,
+        DxCreateDecoderSurfaces,
         SetupAVCodecContext,
         sys,
     };
@@ -442,19 +436,6 @@ static int D3dCreateDevice(vlc_va_t *va)
     return VLC_SUCCESS;
 }
 
-/**
- * It releases a Direct3D device and its resources.
- */
-static void D3dDestroyDevice(vlc_va_t *va)
-{
-    vlc_va_sys_t *sys = va->sys;
-    if (sys->d3ddec)
-        ID3D11VideoDevice_Release(sys->d3ddec);
-    if (sys->hw.video_context)
-        ID3D11VideoContext_Release(sys->hw.video_context);
-    D3D11_ReleaseDevice( &sys->d3d_dev );
-}
-
 static void ReleaseInputList(input_list_t *p_list)
 {
     free(p_list->list);
@@ -796,4 +777,14 @@ static void DxDestroySurfaces(void *opaque)
     }
     if (sys->hw.decoder)
         ID3D11VideoDecoder_Release(sys->hw.decoder);
+
+    if (sys->d3ddec)
+        ID3D11VideoDevice_Release(sys->d3ddec);
+    if (sys->hw.video_context)
+        ID3D11VideoContext_Release(sys->hw.video_context);
+    D3D11_ReleaseDevice( &sys->d3d_dev );
+
+    D3D11_Destroy( &sys->hd3d );
+
+    free(sys);
 }
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 486a9a20c3..5cc97314b0 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -144,7 +144,6 @@ struct vlc_va_sys_t
 
 /* */
 static int D3dCreateDevice(vlc_va_t *);
-static void D3dDestroyDevice(vlc_va_t *);
 
 static int DxGetInputList(vlc_va_t *, input_list_t *);
 static int DxSetupOutput(vlc_va_t *, const directx_va_mode_t *, const video_format_t *);
@@ -243,11 +242,6 @@ static void Close(vlc_va_t *va)
 
     if (sys->vctx)
         vlc_video_context_Release(sys->vctx);
-
-    if (sys->dxva2_dll)
-        FreeLibrary(sys->dxva2_dll);
-
-    free(sys);
 }
 
 static const struct vlc_va_operations ops = { Get, Close, };
@@ -320,9 +314,8 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
 
     struct va_pool_cfg pool_cfg = {
         D3dCreateDevice,
-        D3dDestroyDevice,
-        DxCreateVideoDecoder,
         DxDestroyVideoDecoder,
+        DxCreateVideoDecoder,
         SetupAVCodecContext,
         sys,
     };
@@ -445,6 +438,10 @@ static void D3dDestroyDevice(vlc_va_t *va)
     IDirect3DDeviceManager9_Release(sys->devmng);
     D3D9_ReleaseDevice(&sys->d3d_dev);
     D3D9_Destroy( &sys->hd3d );
+    if (sys->dxva2_dll)
+        FreeLibrary(sys->dxva2_dll);
+
+    free(sys);
 }
 
 static void ReleaseInputList(input_list_t *p_list)
@@ -689,4 +686,13 @@ static void DxDestroyVideoDecoder(void *opaque)
         for (unsigned i = 0; i < sys->hw.surface_count; i++)
             IDirect3DSurface9_Release(sys->hw_surface[i]);
     }
+    IDirect3DDeviceManager9_CloseDeviceHandle(sys->devmng, sys->device);
+    IDirectXVideoDecoderService_Release(sys->d3ddec);
+    IDirect3DDeviceManager9_Release(sys->devmng);
+    D3D9_ReleaseDevice(&sys->d3d_dev);
+    D3D9_Destroy( &sys->hd3d );
+    if (sys->dxva2_dll)
+        FreeLibrary(sys->dxva2_dll);
+
+    free(sys);
 }
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index 9ace60fcc8..9bc67981ac 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -70,15 +70,9 @@ static void va_pool_Release(va_pool_t *va_pool)
     if (atomic_fetch_sub(&va_pool->poolrefs, 1) != 1)
         return;
 
-    free(va_pool);
-}
+    va_pool->callbacks.pf_destroy_device(va_pool->callbacks.opaque);
 
-static void ReleasePoolSurfaces(va_pool_t *va_pool)
-{
-    for (unsigned i = 0; i < va_pool->surface_count; i++)
-        va_surface_Release(&va_pool->surface[i]);
-    va_pool->callbacks.pf_destroy_surfaces(va_pool->callbacks.opaque);
-    va_pool->surface_count = 0;
+    free(va_pool);
 }
 
 /* */
@@ -176,10 +170,11 @@ unsigned va_surface_GetIndex(vlc_va_surface_t *surface)
 
 void va_pool_Close(vlc_va_t *va, va_pool_t *va_pool)
 {
-    ReleasePoolSurfaces(va_pool);
-    void (*pf_destroy_device)(vlc_va_t *) = va_pool->callbacks.pf_destroy_device;
+    for (unsigned i = 0; i < va_pool->surface_count; i++)
+        va_surface_Release(&va_pool->surface[i]);
+    va_pool->surface_count = 0;
+
     va_pool_Release(va_pool);
-    pf_destroy_device(va);
 }
 
 va_pool_t * va_pool_Create(vlc_va_t *va, const struct va_pool_cfg *cbs)
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index 9968e3483a..c2c39bf9ca 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -38,7 +38,10 @@ typedef struct va_pool_t va_pool_t;
 
 struct va_pool_cfg {
     int (*pf_create_device)(vlc_va_t *);
-    void (*pf_destroy_device)(vlc_va_t *);
+    /**
+     * Destroy resources allocated with the surfaces and the associated decoder
+     */
+    void (*pf_destroy_device)(void *opaque);
 
     /**
      * Create the DirectX surfaces in hw_surface and the decoder in decoder
@@ -46,10 +49,6 @@ struct va_pool_cfg {
     int (*pf_create_decoder_surfaces)(vlc_va_t *, int codec_id,
                                       const video_format_t *fmt,
                                       unsigned surface_count);
-    /**
-     * Destroy resources allocated with the surfaces and the associated decoder
-     */
-    void (*pf_destroy_surfaces)(void *opaque);
     /**
      * Set the avcodec hw context after the decoder is created
      */



More information about the vlc-commits mailing list