[vlc-devel] [PATCH] avcodec: reconstruct the ALAC atom if we have enough data
Steve Lhomme
robux4 at videolabs.io
Mon Feb 15 12:04:10 CET 2016
fixes #16620
--
Write the matching ATOM size, the 3rd dword is supposed to be 0.
This way remuxing produces data that Quicktime should be able to use.
replaces https://patches.videolan.org/patch/12235/
replaces https://patches.videolan.org/patch/12243/
---
modules/codec/avcodec/audio.c | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 159dbf1..e766763 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -85,15 +85,39 @@ 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' };
- /* 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 < GetDWBE( p_pattern ))
{
- 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 )
+ {
+ uint8_t *p_dst = p_context->extradata;
+
+ i_size = 0;
+ SetDWBE( &p_dst[i_size], p_dec->fmt_in.i_extra + 12 );
+ memcpy( &p_dst[i_size], &p_pattern[4], 4 );
+ i_size += 8;
+ SetDWBE( &p_dst[i_size], 0 );
+ 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
More information about the vlc-devel
mailing list