[FFmpeg-devel] [PATCH v2 1/3] avutil/dict: add av_dict_pop

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Oct 20 18:42:46 EEST 2023


Anton Khirnov:
> Quoting Andreas Rheinhardt (2023-10-20 16:00:45)
>> Anton Khirnov:
>>> Quoting Andreas Rheinhardt (2023-07-03 20:02:25)
>>>> Marvin Scholz:
>>>>> I honestly can't think of a sensible API design for this,
>>>>> if you have any idea feel free to share.
>>>>>
>>>>
>>>> The only way I can think of that allows this is for the user to pass a
>>>> pointer to a (const) AVDictionaryEntry, namely the entry that the user
>>>> wishes to pop. This is of course cumbersome, because it would be two
>>>> function calls.
>>>
>>> We could start guaranteeing that entries with the same key are always
>>> returned in insertion order. Now that I think of it there's some code in
>>> ffmpeg CLI that relies on that.
>>>
>>
>> IIRC this is not true correctly, because removing an entry changes the
>> order of the remaining entries (we don't memmove the remaining entries
>> into the new position; instead we move the last entry to the now vacant
>> slot).
> 
> I am aware - that code is strictly speaking incorrect. It happens to
> work because nothing ever gets removed from the option dicts. We could
> consider changing the internal representation somehow, so that all
> values for a key are grouped together.
> 

We could also just memmove the remaining entries.

- Andreas



More information about the ffmpeg-devel mailing list