[vlc-devel] [PATCH 1/2] vdpau: free the hwaccel_context allocated locally ourself

Steve Lhomme robux4 at ycbcr.xyz
Tue Jul 23 08:52:15 CEST 2019


On 2019-07-23 8:31, Steve Lhomme wrote:
> On 2019-07-23 8:06, Rémi Denis-Courmont wrote:
>> IIRC that does not work because FFmpeg could reallocate it.
> 
> I see no such thing in libavcodec/vdpau.c
> 
> The only reallocate there is on the hwaccel_context is the one done in 
> av_vdpau_bind_context() which is not called internally, we're the ones 
> calling it.

In fact hwaccel_context is the sole responsibility of the host app. It's 
never modified by lavc for any of the variants. The bind function is 
just a helper to set it properly (rings a bell ?).

We should set hwaccel_context to NULL after we free it in patch 2/2 to 
have a clean context if we switch to software or another hardware decoder.

>> Le 23 juillet 2019 08:57:44 GMT+03:00, Steve Lhomme <robux4 at ycbcr.xyz> 
>> a écrit :
>>> ---
>>> modules/hw/vdpau/avcodec.c | 8 +++++++-
>>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
>>> index 913e391562..49536e6d60 100644
>>> --- a/modules/hw/vdpau/avcodec.c
>>> +++ b/modules/hw/vdpau/avcodec.c
>>> @@ -44,6 +44,7 @@ struct vlc_va_sys_t
>>>      vdp_t *vdp;
>>>      VdpDevice device;
>>>      VdpChromaType type;
>>> +    void *hwaccel_context;
>>>      uint32_t width;
>>>      uint32_t height;
>>>      vlc_vdp_video_field_t *pool[];
>>> @@ -124,7 +125,8 @@ static void Close(vlc_va_t *va, void **hwctx)
>>>      for (unsigned i = 0; sys->pool[i] != NULL; i++)
>>>          vlc_vdp_video_destroy(sys->pool[i]);
>>>      vdp_release_x11(sys->vdp);
>>> -    av_freep(hwctx);
>>> +    if (sys->hwaccel_context)
>>> +        av_free(sys->hwaccel_context);
>>>      free(sys);
>>> }
>>>
>>> @@ -172,6 +174,7 @@ static int Open(vlc_va_t *va, AVCodecContext
>>> *avctx, enum PixelFormat pix_fmt,
>>>      sys->type = type;
>>>      sys->width = width;
>>>      sys->height = height;
>>> +    sys->hwaccel_context = NULL;
>>>
>>>      err = vdp_get_x11(NULL, -1, &sys->vdp, &sys->device);
>>>      if (err != VDP_STATUS_OK)
>>> @@ -189,6 +192,7 @@ static int Open(vlc_va_t *va, AVCodecContext
>>> *avctx, enum PixelFormat pix_fmt,
>>>
>>>      if (av_vdpau_bind_context(avctx, sys->device, func, flags))
>>>          goto error;
>>> +    sys->hwaccel_context = avctx->hwaccel_context;
>>>      va->sys = sys;
>>>
>>>      unsigned i = 0;
>>> @@ -221,6 +225,8 @@ static int Open(vlc_va_t *va, AVCodecContext
>>> *avctx, enum PixelFormat pix_fmt,
>>>      return VLC_SUCCESS;
>>>
>>> error:
>>> +    if (sys->hwaccel_context)
>>> +        av_free(sys->hwaccel_context);
>>>      vdp_release_x11(sys->vdp);
>>>      free(sys);
>>>      return VLC_EGENERIC;
>>> -- 
>>> 2.17.1
>>>
>>> _______________________________________________
>>> vlc-devel mailing list
>>> To unsubscribe or modify your subscription options:
>>> https://mailman.videolan.org/listinfo/vlc-devel
>>
>> -- 
>> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez 
>> excuser ma brièveté.
>>
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>>
> _______________________________________________
> 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