vlc | branch: master | Oliver Collyer <[email protected]> | Fri Jun 30 09:38:52 
2017 +0300| [d5467ede3e794b84a12275476def0e1f800977f3] | committer: 
Jean-Baptiste Kempf

dxva2: fixed incorrect acquiring/releasing of hw surfaces

I found that after using DXVA2 in a custom libVLC application I could no longer 
reset my D3D9 device, because some surfaces hadn't been released.

This was caused by two issues:

1) failure to release the surfaces in DxDestroyVideoDecoder that were created 
by DxCreateVideoDecoder
2) incorrectly calling AcquirePictureSys on the newly created (as opposed to 
copied) surfaces

The result was that all the surfaces allocated had 2 references that were never 
released.

Signed-off-by: Jean-Baptiste Kempf <[email protected]>

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

 modules/codec/avcodec/dxva2.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 31c8f67afb..0977990671 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -206,7 +206,14 @@ static struct va_pic_context 
*CreatePicContext(IDirect3DSurface9 *surface)
 static struct va_pic_context* NewSurfacePicContext(vlc_va_t *va, int 
surface_index)
 {
     directx_sys_t *dx_sys = &va->sys->dx_sys;
-    return CreatePicContext(dx_sys->hw_surface[surface_index]);
+    struct va_pic_context *pic_ctx = 
CreatePicContext(dx_sys->hw_surface[surface_index]);
+    if (unlikely(pic_ctx==NULL))
+        return NULL;
+    /* all the resources are acquired during surfaces init, and a second time 
in
+     * CreatePicContext(), undo one of them otherwise we need an extra release
+     * when the pool is emptied */
+    ReleasePictureSys(&pic_ctx->picsys);
+    return pic_ctx;
 }
 
 static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
@@ -749,6 +756,8 @@ static void DxDestroyVideoDecoder(vlc_va_t *va)
     {
         IDirectXVideoDecoder_Release(dx_sys->decoder);
         dx_sys->decoder = NULL;
+        for (unsigned i = 0; i < dx_sys->va_pool.surface_count; i++)
+            IDirect3DSurface9_Release(dx_sys->hw_surface[i]);
     }
 }
 

_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to