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;
}
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" );
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 );
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;
}