[vlc-devel] [PATCH] dxva2: fixed incorrect acquiring/releasing of hw surfaces

Steve Lhomme robux4 at gmail.com
Fri Jun 30 08:49:45 CEST 2017


LGTM.

On Fri, Jun 30, 2017 at 8:38 AM, Oliver Collyer <ovcollyer at mac.com> wrote:
> (v2 of patch, following Steve's comments)
>
> 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.
>
> ---
>  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]);
>      }
>  }
>
> --
> 2.11.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list