[FFmpeg-devel] [PATCH] libavcodec/mpegaudio_parser.c: differentiate MPEG audio dual mono

Scott Theisen scott.the.elm at gmail.com
Thu Dec 12 23:00:02 EET 2024


On 12/12/24 01:41, Anton Khirnov wrote:
> Quoting Scott Theisen (2024-12-10 21:42:06)
>> On 12/9/24 02:31, Anton Khirnov wrote:
>>> Quoting Scott Theisen (2024-11-30 08:38:54)
>>>> On 11/25/24 00:42, Anton Khirnov wrote:
>>>>> Quoting Scott Theisen (2024-11-14 05:37:49)
>>>>>> @@ -85,7 +85,13 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
>>>>>>                         if (s->header_count > header_threshold) {
>>>>>>                             avctx->sample_rate= sr;
>>>>>>                             av_channel_layout_uninit(&avctx->ch_layout);
>>>>>> -                        av_channel_layout_default(&avctx->ch_layout, channels);
>>>>>> +                        if (dual_mono) {
>>>>>> +                            av_channel_layout_custom_init(&avctx->ch_layout, 2);
>>>>> This can fail - the return code should be checked.
>>>>>
>>>> It can only fail if av_calloc() fails to allocate 48 bytes.  Should it
>>>> return buf_size or just use the default order?
>>> Memory allocation failure should always propagate back to the caller.
>>>
>> The parsers can't return error codes, though.  See line 105 in
>> libavcodec/mpegaudio_parser.c
> Huh, disregard my comment then.
>
> And we really should do something about parsers.
>

You did make a valid comment, since if the allocation fails 
`avctx->ch_layout.u.map` will be NULL and the subsequent lines would 
crash from dereferencing the null pointer.

The question remains, however, on how to respond to that since the 
parser can't return an error code.  Should it ignore the memory 
allocation failure and use the default stereo layout or return buf_size 
to skip that part of the input?

Regards,

Scott Theisen


More information about the ffmpeg-devel mailing list