X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Favcodec%2Faudio.c;h=7ea107bd4b42cc1859ee3fdc204775831d7430b0;hb=497b59e4fc525cca1fd422c0b5ece0672d4d8036;hp=ca48b90b36061353f59ee72fc7fc10e5c2000fd0;hpb=f7d5f3e7cab176a0d68b736e05dece392d611161;p=vlc diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c index ca48b90b36..7ea107bd4b 100644 --- a/modules/codec/avcodec/audio.c +++ b/modules/codec/avcodec/audio.c @@ -100,7 +100,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context, if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) { - msg_Err( p_dec, "out of memory" ); return VLC_ENOMEM; } @@ -128,26 +127,56 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context, p_sys->p_context->bit_rate = p_dec->fmt_in.i_bitrate; p_sys->p_context->bits_per_sample = p_dec->fmt_in.audio.i_bitspersample; - if( ( p_sys->p_context->extradata_size = p_dec->fmt_in.i_extra ) > 0 ) + if( p_dec->fmt_in.i_extra > 0 ) { - int i_offset = 0; + const uint8_t * const p_src = p_dec->fmt_in.p_extra; + int i_offset; + int i_size; if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'f', 'l', 'a', 'c' ) ) + { i_offset = 8; - - p_sys->p_context->extradata_size -= i_offset; - p_sys->p_context->extradata = - malloc( p_sys->p_context->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE ); - memcpy( p_sys->p_context->extradata, - (char*)p_dec->fmt_in.p_extra + i_offset, - p_sys->p_context->extradata_size ); - memset( (char*)p_sys->p_context->extradata + - p_sys->p_context->extradata_size, 0, - FF_INPUT_BUFFER_PADDING_SIZE ); + i_size = p_dec->fmt_in.i_extra - 8; + } + else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'l', 'a', 'c' ) ) + { + static const uint8_t p_pattern[] = { 0, 0, 0, 36, 'a', 'l', 'a', 'c' }; + /* Find alac atom XXX it is a bit ugly */ + for( i_offset = 0; i_offset < p_dec->fmt_in.i_extra - 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; + } + else + { + i_offset = 0; + i_size = p_dec->fmt_in.i_extra; + } + + if( i_size > 0 ) + { + p_sys->p_context->extradata = + malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE ); + if( p_sys->p_context->extradata ) + { + uint8_t *p_dst = p_sys->p_context->extradata; + + p_sys->p_context->extradata_size = i_size; + + memcpy( &p_dst[0], &p_src[i_offset], i_size ); + memset( &p_dst[i_size], 0, FF_INPUT_BUFFER_PADDING_SIZE ); + } + } } else + { + p_sys->p_context->extradata_size = 0; p_sys->p_context->extradata = NULL; + } /* ***** Open the codec ***** */ vlc_mutex_t *lock = var_AcquireMutex( "avcodec" ); @@ -291,7 +320,7 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block ) if( i_used < 0 || i_output < 0 ) { if( i_used < 0 ) - msg_Warn( p_dec, "cannot decode one frame (%d bytes)", + msg_Warn( p_dec, "cannot decode one frame (%zu bytes)", p_block->i_buffer ); block_Release( p_block ); @@ -305,10 +334,11 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block ) p_block->i_buffer -= i_used; p_block->p_buffer += i_used; - if( p_sys->p_context->channels <= 0 || p_sys->p_context->channels > 6 ) + if( p_sys->p_context->channels <= 0 || p_sys->p_context->channels > 6 || + p_sys->p_context->sample_rate <= 0 ) { - msg_Warn( p_dec, "invalid channels count %d", - p_sys->p_context->channels ); + msg_Warn( p_dec, "invalid audio properties channels count %d, sample rate %d", + p_sys->p_context->channels, p_sys->p_context->sample_rate ); block_Release( p_block ); return NULL; }