Commit df7648f0 authored by Laurent Aimar's avatar Laurent Aimar

Fixed ALAC. (close #633)

parent 4d763911
......@@ -127,29 +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;
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;
}
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 );
if( p_sys->p_context->extradata )
if( i_size > 0 )
{
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 );
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" );
......
......@@ -1133,18 +1133,16 @@ static int MP4_ReadBox_sample_soun( stream_t *p_stream, MP4_Box_t *p_box )
/*
* XXX hack -> produce a copy of the nearly complete chunk
*/
p_box->data.p_sample_soun->i_qt_description = 0;
p_box->data.p_sample_soun->p_qt_description = NULL;
if( i_read > 0 )
{
p_box->data.p_sample_soun->p_qt_description = malloc( i_read );
if( p_box->data.p_sample_soun->p_qt_description == NULL )
MP4_READBOX_EXIT( 0 );
p_box->data.p_sample_soun->i_qt_description = i_read;
memcpy( p_box->data.p_sample_soun->p_qt_description, p_peek, i_read );
}
else
{
p_box->data.p_sample_soun->i_qt_description = 0;
p_box->data.p_sample_soun->p_qt_description = NULL;
if( p_box->data.p_sample_soun->p_qt_description )
{
p_box->data.p_sample_soun->i_qt_description = i_read;
memcpy( p_box->data.p_sample_soun->p_qt_description, p_peek, i_read );
}
}
MP4_GET2BYTES( p_box->data.p_sample_soun->i_qt_version );
......@@ -1182,12 +1180,12 @@ static int MP4_ReadBox_sample_soun( stream_t *p_stream, MP4_Box_t *p_box )
{
/* SoundDescriptionV2 */
double f_sample_rate;
int64_t dummy;
int64_t dummy;
uint32_t i_channel;
MP4_GET4BYTES( p_box->data.p_sample_soun->i_sample_per_packet );
MP4_GET8BYTES( dummy );
memcpy( &f_sample_rate, &dummy, 8 );
memcpy( &f_sample_rate, &dummy, 8 );
msg_Dbg( p_stream, "read box: %f Hz", f_sample_rate );
p_box->data.p_sample_soun->i_sampleratehi = (int)f_sample_rate % 65536;
......@@ -1232,20 +1230,7 @@ static int MP4_ReadBox_sample_soun( stream_t *p_stream, MP4_Box_t *p_box )
p_box->data.p_sample_soun->i_channelcount = 1;
}
if( p_box->i_type == FOURCC_alac )
{
free( p_box->data.p_sample_soun->p_qt_description );
p_box->data.p_sample_soun->p_qt_description = malloc( i_read );
if( p_box->data.p_sample_soun->p_qt_description == NULL )
MP4_READBOX_EXIT( 0 );
p_box->data.p_sample_soun->i_qt_description = i_read;
memcpy( p_box->data.p_sample_soun->p_qt_description, p_peek, i_read );
}
else
{
MP4_ReadBoxContainerRaw( p_stream, p_box ); /* esds */
}
MP4_ReadBoxContainerRaw( p_stream, p_box ); /* esds/wave/... */
#ifdef MP4_VERBOSE
msg_Dbg( p_stream, "read box: \"soun\" in stsd channel %d "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment