[FFmpeg-devel] [PATCH] avcodec/avcodec: don't uninitialize ch_layout in avcodec_close()
James Almer
jamrial at gmail.com
Sun Mar 20 21:06:00 EET 2022
On 3/20/2022 2:03 PM, James Almer wrote:
> On 3/19/2022 10:47 AM, Anton Khirnov wrote:
>> Quoting James Almer (2022-03-19 04:04:07)
>>> The function is not meant to clear codec parameters, and the lavf
>>> demux code
>>> relies on this behavior.
>>
>> Maybe it shouldn't?
>>
>> Which code is it exactly?
>
> The parser included by demux.c. That file calls avcodec_close() in
> certain situations, but the avctx is still used when calling
> av_parser_parse2() as it's expected that all the parameters are left
> intact, and all were until 327efa6633, where avctx->ch_layout started
> being uninitialized, and it shouldn't.
An alternative is
> diff --git a/libavformat/demux.c b/libavformat/demux.c
> index c1c9422ac0..c14e44cb07 100644
> --- a/libavformat/demux.c
> +++ b/libavformat/demux.c
> @@ -2957,6 +2957,7 @@ find_stream_info_err:
> av_freep(&sti->info);
> }
> avcodec_close(sti->avctx);
> + avcodec_parameters_to_context(sti->avctx, st->codecpar);
> av_bsf_free(&sti->extract_extradata.bsf);
> }
> if (ic->pb) {
Which works around this specific issue, but either way,
avcodec_close(avctx) should not nuke avctx->ch_layout.
More information about the ffmpeg-devel
mailing list