[FFmpeg-devel] [PATCH 6/7] avfilter/formats: Always keep longer references list when merging lists
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Thu Aug 20 01:22:30 EEST 2020
Nicolas George:
> Andreas Rheinhardt (12020-08-15):
>> This means that one only needs to update the shorter list of references.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
>> ---
>> I doubt that this optimizations is worth the additional complexity. I
>> have just added it for you to decide.
>
> I must say, I do not understand the logic, especially the preserve_fmts
> bit.
>
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.
> I think we can leave it for later.
>
Or it can be dropped altogether. Which I would actually prefer.
> Have you given thought to the linked list option I suggested?
>
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
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.
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.
- Andreas
More information about the ffmpeg-devel
mailing list