[FFmpeg-devel] [PATCH 04/21] avformat: Redo cleanup of demuxer upon read_header() failure

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sun Mar 22 06:51:00 EET 2020


James Almer:
> On 3/22/2020 12:47 AM, Andreas Rheinhardt wrote:
>> If reading the header fails, the demuxer's read_close() function (if
>> existing) is not called automatically; instead several demuxers call it
>> via "goto fail" in read_header().
>>
>> This commit intends to change this by adding a flag to AVInputFormat
>> that can be used to set on a per-AVInputFormat basis whether read_close()
>> should be called generically after an error during read_header().
>>
>> The flag controlling this behaviour has been added because it might be
>> unsafe to call read_close() generally (e.g. this might lead to
>> read_close() being called twice and this might e.g. lead to double-frees
>> if av_free() instead of av_freep() is used; or a size field has not
>> been reset after freeing the elements (see the mov demuxer for an
>> example of this)). Yet the intention is to check and fix all demuxers
>> and make the flag redundant in the medium run.
>>
>> The flag has been added to a new internal field of AVInputFormat,
>> flags_internal. When it has become redundant, it can be removed again
>> at the next major version bump.
> 
> Fields considered not public (And thus added below the relevant notice
> in the struct) can be added and removed at any time. So this sentence is
> not needed.
> 
This field is not public, but I thought that the fact that libavdevice
also defines AVInputFormats makes this de-facto avpriv. Isn't it allowed
to use a newer libavdevice together with an older libavformat? Imagine
your libavdevice to be so new that the field has already been removed,
yet the libavformat being so old that it still checks for the field.
That would not go well.
(If I am right then this gives the task of checking and adapting all the
demuxers a certain urgency to be finished before the next major bump.)

>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
>> ---
>>  libavformat/avformat.h |  7 +++++++
>>  libavformat/utils.c    | 11 +++++++++--
>>  2 files changed, 16 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
>> index 9b9b634ec3..50b90788b1 100644
>> --- a/libavformat/avformat.h
>> +++ b/libavformat/avformat.h
>> @@ -780,6 +780,13 @@ typedef struct AVInputFormat {
>>       * @see avdevice_capabilities_free() for more details.
>>       */
>>      int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);
>> +
>> +#define FF_INPUTFORMAT_HEADER_CLEANUP 0x0001 /**< read_close() should be called
>> +                                                  on read_header() failure */
> 
> If this is internal, then it should be defined in internal.h, same as
> the caps_internal flags for AVCodecContext.
> 
I thought about this and given that avformat.h already defines
FF_DEBUG_TS I put it in there. But sure, I can move it.

- Andreas


More information about the ffmpeg-devel mailing list