[FFmpeg-devel] [PATCH v2] avutils/hwcontext: When deriving a hwdevice, search for existing device in both directions

Soft Works softworkz at hotmail.com
Thu Aug 19 10:51:44 EEST 2021



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Xiang,
> Haihao
> Sent: Thursday, 19 August 2021 09:37
> To: ffmpeg-devel at ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v2] avutils/hwcontext: When deriving a
> hwdevice, search for existing device in both directions
> 
> On Fri, 2021-08-13 at 06:29 +0000, Xiang, Haihao wrote:
> > On Tue, 2021-08-10 at 09:52 +0000, Soft Works wrote:
> > > The test /libavutil/tests/hwdevice checks that when deriving a device
> > > from a source device and then deriving back to the type of the source
> > > device, the result is matching the original source device, i.e. the
> > > derivation mechanism doesn't create a new device in this case.
> > >

[..]

> >
> > video:143kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
> muxing
> > overhead: unknown
> > corrupted size vs. prev_size in fastbins
> > Aborted
> >
> 
> Hi Softworks,
> 
> +        child_device->internal->derived_devices[ctx->type] =
> av_buffer_create((uint8_t*)ctx, sizeof(*ctx), 0, ctx, 0);
> 
> The above change introduces a new AVBufferRef for ctx. The first AVBufferRef
> for
> ctx is created when function av_hwdevice_ctx_alloc is called. So there are
> two
> different AVBufferRefs referring to the same ctx, then ctx will be double-
> freed
> 
> The change below is a bit ugly, but it may fix this double-free issue.
> 
> +static void qsv_ctx_free(void *opaque, uint8_t *ctx)
> +{
> +    // Do nothing here
> +    // ctx is freed in hwdevice_ctx_free
> +}
> +
>  static int qsv_device_create(AVHWDeviceContext *ctx, const char *device,
>                               AVDictionary *opts, int flags)
>  {
> @@ -1271,7 +1277,7 @@ static int qsv_device_create(AVHWDeviceContext *ctx,
> const
> char *device,
>      ret = qsv_device_derive_from_child(ctx, impl, child_device, 0);
>      if (ret >= 0) {
>          ctx->internal->source_device = av_buffer_ref(priv-
> >child_device_ctx);
> -        child_device->internal->derived_devices[ctx->type] =
> av_buffer_create((uint8_t*)ctx, sizeof(*ctx), 0, ctx, 0);
> +        child_device->internal->derived_devices[ctx->type] =
> av_buffer_create((uint8_t*)ctx, sizeof(*ctx), qsv_ctx_free, ctx, 0);
>          if (!child_device->internal->derived_devices[ctx->type]) {
>              return AVERROR(ENOMEM);
>          }

Hi Haihao,

sorry for getting back late and thanks for your suggested fix.
I'll apply it and submit a new patch version.

Best regards,
softworkz







More information about the ffmpeg-devel mailing list