[FFmpeg-devel] [PATCH 01/54] avformat: Add internal flags for AV(In|Out)putFormat

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Jun 16 02:16:37 EEST 2021


James Almer:
> On 6/15/2021 8:01 PM, Andreas Rheinhardt wrote:
>> Both AVInputFormat and AVOutputFormat currently lack an equivalent to
>> AVCodec's caps_internal. E.g. if reading a header fails, each demuxer
>> is currently required to clean up manually, which often means to just
>> call the demuxer's read_close function. This could (and will) be done
>> generically via an equivalent of FF_CODEC_CAP_INIT_CLEANUP.
>>
>> Because of the unholy ABI-relationship between libavdevice and
>> libavformat adding such a flag is only possible when the ABI is open
>> (despite the flag not being part of the public API), such as now.
>> Therefore such a flag is also added to AVOutputFormat, despite there
>> being no immediate use for it.
> 
> Since new "non public" fields can if needed be added at the very end of
> the struct, is this still an issue?

Yes, because one is allowed to use an old libavdevice together with a
new libavformat. The AV(In|Out)putFormats defined in libavdevice don't
have these new fields; so using these fields in libavformat is
problematic even when they are at the end. While this is not an
unsurmountable problem (if a commit adding new fields bumps libavdevice
version, one can check via via AV_IS_(IN|OUT)PUT_DEVICE whether the
in/outformat is a device and then use a version check whether the given
libavdevice version has the desired field), it is easier to just add
flags_internal to AVOutputFormat, too.

> It's adding new public ones which generate issues because they will
> invariably push the offset of all the non public ones down by a few
> bytes, and thus break lavd devices.
> 
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
>> ---
>>   libavformat/avformat.h | 10 ++++++++++
>>   1 file changed, 10 insertions(+)
>>
>> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
>> index cd7b0d941c..81d2ac38d0 100644
>> --- a/libavformat/avformat.h
>> +++ b/libavformat/avformat.h
>> @@ -535,6 +535,11 @@ typedef struct AVOutputFormat {
>>        */
>>       int priv_data_size;
>>   +    /**
>> +     * Internal flags. See FF_FMT_FLAG_* in internal.h.
>> +     */
>> +    int flags_internal;
>> +
>>       int (*write_header)(struct AVFormatContext *);
>>       /**
>>        * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,
>> @@ -674,6 +679,11 @@ typedef struct AVInputFormat {
>>        */
>>       int priv_data_size;
>>   +    /**
>> +     * Internal flags. See FF_FMT_FLAG_* in internal.h.
>> +     */
>> +    int flags_internal;
>> +
>>       /**
>>        * Tell if a given file has a chance of being parsed as this
>> format.
>>        * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE
>> bytes
>>
> 


More information about the ffmpeg-devel mailing list