[vlc-devel] [PATCH] avcodec: reconstruct the ALAC atom if we have enough data
Steve Lhomme
robux4 at gmail.com
Mon Feb 15 09:05:33 CET 2016
On Fri, Feb 12, 2016 at 5:53 PM, Tristan Matthews <tmatth at videolan.org> wrote:
> Hi,
>
> On Fri, Feb 12, 2016 at 10:28 AM, Steve Lhomme <robux4 at videolabs.io> wrote:
>> fixes #16620
>> ---
>> modules/codec/avcodec/audio.c | 37 ++++++++++++++++++++++++++++++-------
>> 1 file changed, 30 insertions(+), 7 deletions(-)
>>
>> diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
>> index 159dbf1..9ce190f 100644
>> --- a/modules/codec/avcodec/audio.c
>> +++ b/modules/codec/avcodec/audio.c
>> @@ -85,15 +85,38 @@ static void InitDecoderConfig( decoder_t *p_dec, AVCodecContext *p_context )
>> if( p_dec->fmt_in.i_codec == VLC_CODEC_ALAC )
>> {
>> static const uint8_t p_pattern[] = { 0, 0, 0, 36, 'a', 'l', 'a', 'c' };
>
> Maybe define 36 somewhere, or use p_pattern[3].
I'll use GetDWBE(), it's even cleaner.
>> - /* Find alac atom XXX it is a bit ugly */
>> - for( i_offset = 0; i_offset < i_size - (int)sizeof(p_pattern); i_offset++ )
>> + if( i_size >= 24 && i_size < 36)
>> {
>> - if( !memcmp( &p_src[i_offset], p_pattern, sizeof(p_pattern) ) )
>> - break;
>> - }
>> - i_size = __MIN( p_dec->fmt_in.i_extra - i_offset, 36 );
>> - if( i_size < 36 )
>> + p_context->extradata =
>> + av_malloc( 12 + i_size + FF_INPUT_BUFFER_PADDING_SIZE );
>> + if( p_context->extradata )
>
> What if av_malloc fails?
The same as before the extra data is empty and decoding will be
refused by avcodec.
>> + {
>> + uint8_t *p_dst = p_context->extradata;
>> +
>> + i_size = 0;
>> + memcpy( &p_dst[i_size], &p_pattern[0], 8 );
>> + i_size += 8;
>> + memset( &p_dst[i_size], 0, 4 );
>> + i_size += 4;
>> + memcpy( &p_dst[i_size], &p_src[0], p_dec->fmt_in.i_extra );
>> + i_size += p_dec->fmt_in.i_extra;
>> + p_context->extradata_size = i_size;
>> + memset( &p_dst[i_size], 0, FF_INPUT_BUFFER_PADDING_SIZE );
>> + }
>> i_size = 0;
>> + }
>> + else
>> + {
>> + /* Find alac atom XXX it is a bit ugly */
>> + for( i_offset = 0; i_offset < i_size - (int)sizeof(p_pattern); i_offset++ )
>> + {
>> + if( !memcmp( &p_src[i_offset], p_pattern, sizeof(p_pattern) ) )
>> + break;
>> + }
>> + i_size = __MIN( p_dec->fmt_in.i_extra - i_offset, 36 );
>> + if( i_size < 36 )
>> + i_size = 0;
>> + }
>> }
>>
>> if( i_size > 0 )
>> --
>> 2.7.0
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list