[FFmpeg-devel] [PATCH 6/7] avfilter/formats: Always keep longer references list when merging lists

Nicolas George george at nsup.org
Thu Aug 20 18:12:21 EEST 2020


Andreas Rheinhardt (12020-08-20):
> The MERGE_REF() macro is asymmetric by design: The refs of the second
> argument are added to the refs of the first argument and the second
> argument is freed. The list of the first argument meanwhile is/ought to
> be preserved. When swapping, one therefore has to swap the
> non-ref-fields, too. But the MERGE_REF at the end of
> ff_merge_channel_layouts() is special. The list will be freed and
> replaced by a different list after the macro anyway, so one doesn't need
> to preserve the list at all. preserve_fmts exists so that the compiler
> can optimize this part of MERGE_REF() away for that invocation of the macro.

Thanks for the explanation. I had not realized that these are precisely
the functions that make the lists the same.

> It is certainly interesting (e.g. if I am not mistaken, it would mean
> that ff_merge_formats/samplerates() can't fail at all any more). I see

This is one of the benefits I expect, yes.

> two obvious downsides: Traversing the list for freeing is slower (but it
> should only be a constant factor) and it increases the size of the
> AVFilterLink even after merging. But I don't consider these obstacles to
> have much weight.

If we become worried about the size of the fields AVFilterLink used only
at initialization, we can move them all together in a separate structure
that gets freed once the filter is configured.

> Speaking of AVFilterLink: All ff_merge_*() as well as ff_can_merge_*()
> always use the in- and out-fields of one and the same AVFilterLink. I
> wonder whether these function should not just take the AVFilterLink * as
> parameter. It would also mean that ff_merge_formats() would have the
> same signature as the other functions, which simplifies macros.

Now that you mention it, it is probably something that can be done,
indeed.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200820/1df98b8d/attachment.sig>


More information about the ffmpeg-devel mailing list