diff options
author | Janne Grunau <janne-libav@jannau.net> | 2011-10-21 19:25:30 +0400 |
---|---|---|
committer | Janne Grunau <janne-libav@jannau.net> | 2011-12-03 03:42:48 +0400 |
commit | fd095539d10bb440042e671f95306b16b0fec674 (patch) | |
tree | c28e329a98879823371f7b3e3f388f83f3805fab /libavcodec | |
parent | 0eea212943544d40f99b05571aa7159d78667154 (diff) |
latmdec: fix audio specific config parsing
Pass the correct size in bits to mpeg4audio_get_config and add a flag
to disable parsing of the sync extension when the size is not known.
Latm with AudioMuxVersion 0 does not specify the size of the audio
specific config. Data after the audio specific config can be
misinterpreted as sync extension resulting in random and wrong configs.
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/aacdec.c | 35 | ||||
-rw-r--r-- | libavcodec/alsdec.c | 2 | ||||
-rw-r--r-- | libavcodec/mpeg4audio.c | 7 | ||||
-rw-r--r-- | libavcodec/mpeg4audio.h | 7 | ||||
-rw-r--r-- | libavcodec/mpegaudiodec.c | 3 |
5 files changed, 34 insertions, 20 deletions
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 672ba1c648..a4fe2ee2cc 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -452,15 +452,17 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, * @param ac pointer to AACContext, may be null * @param avctx pointer to AVCCodecContext, used for logging * @param m4ac pointer to MPEG4AudioConfig, used for parsing - * @param data pointer to AVCodecContext extradata - * @param data_size size of AVCCodecContext extradata + * @param data pointer to buffer holding an audio specific config + * @param bit_size size of audio specific config or data in bits + * @param sync_extension look for an appended sync extension * * @return Returns error status or number of consumed bits. <0 - error */ static int decode_audio_specific_config(AACContext *ac, AVCodecContext *avctx, MPEG4AudioConfig *m4ac, - const uint8_t *data, int data_size) + const uint8_t *data, int bit_size, + int sync_extension) { GetBitContext gb; int i; @@ -470,9 +472,9 @@ static int decode_audio_specific_config(AACContext *ac, av_dlog(avctx, "%02x ", avctx->extradata[i]); av_dlog(avctx, "\n"); - init_get_bits(&gb, data, data_size * 8); + init_get_bits(&gb, data, bit_size); - if ((i = avpriv_mpeg4audio_get_config(m4ac, data, data_size)) < 0) + if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, sync_extension)) < 0) return -1; if (m4ac->sampling_index > 12) { av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index); @@ -572,7 +574,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) if (avctx->extradata_size > 0) { if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac, avctx->extradata, - avctx->extradata_size) < 0) + avctx->extradata_size*8, 1) < 0) return -1; } else { int sr, i; @@ -2315,12 +2317,19 @@ static inline uint32_t latm_get_value(GetBitContext *b) } static int latm_decode_audio_specific_config(struct LATMContext *latmctx, - GetBitContext *gb) + GetBitContext *gb, int asclen) { AVCodecContext *avctx = latmctx->aac_ctx.avctx; MPEG4AudioConfig m4ac; - int config_start_bit = get_bits_count(gb); - int bits_consumed, esize; + int config_start_bit = get_bits_count(gb); + int sync_extension = 0; + int bits_consumed, esize; + + if (asclen) { + sync_extension = 1; + asclen = FFMIN(asclen, get_bits_left(gb)); + } else + asclen = get_bits_left(gb); if (config_start_bit % 8) { av_log_missing_feature(latmctx->aac_ctx.avctx, "audio specific " @@ -2330,7 +2339,7 @@ static int latm_decode_audio_specific_config(struct LATMContext *latmctx, bits_consumed = decode_audio_specific_config(NULL, avctx, &m4ac, gb->buffer + (config_start_bit / 8), - get_bits_left(gb) / 8); + asclen, sync_extension); if (bits_consumed < 0) return AVERROR_INVALIDDATA; @@ -2388,11 +2397,11 @@ static int read_stream_mux_config(struct LATMContext *latmctx, // for all but first stream: use_same_config = get_bits(gb, 1); if (!audio_mux_version) { - if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0) + if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0) return ret; } else { int ascLen = latm_get_value(gb); - if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0) + if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0) return ret; ascLen -= ret; skip_bits_long(gb, ascLen); @@ -2514,7 +2523,7 @@ static int latm_decode_frame(AVCodecContext *avctx, void *out, } else { if ((err = decode_audio_specific_config( &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.m4ac, - avctx->extradata, avctx->extradata_size)) < 0) + avctx->extradata, avctx->extradata_size*8, 1)) < 0) return err; latmctx->initialized = 1; } diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index 71495803a3..dc4961c9ba 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -291,7 +291,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx) init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); config_offset = avpriv_mpeg4audio_get_config(&m4ac, avctx->extradata, - avctx->extradata_size); + avctx->extradata_size * 8, 1); if (config_offset < 0) return -1; diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c index f9e866f405..0fb9b96c80 100644 --- a/libavcodec/mpeg4audio.c +++ b/libavcodec/mpeg4audio.c @@ -76,12 +76,13 @@ static inline int get_sample_rate(GetBitContext *gb, int *index) avpriv_mpeg4audio_sample_rates[*index]; } -int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size) +int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, + int bit_size, int sync_extension) { GetBitContext gb; int specific_config_bitindex; - init_get_bits(&gb, buf, buf_size*8); + init_get_bits(&gb, buf, bit_size); c->object_type = get_object_type(&gb); c->sample_rate = get_sample_rate(&gb, &c->sampling_index); c->chan_config = get_bits(&gb, 4); @@ -117,7 +118,7 @@ int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int bu return -1; } - if (c->ext_object_type != AOT_SBR) { + if (c->ext_object_type != AOT_SBR && sync_extension) { while (get_bits_left(&gb) > 15) { if (show_bits(&gb, 11) == 0x2b7) { // sync extension get_bits(&gb, 11); diff --git a/libavcodec/mpeg4audio.h b/libavcodec/mpeg4audio.h index d6730b97b3..7560f3f4e4 100644 --- a/libavcodec/mpeg4audio.h +++ b/libavcodec/mpeg4audio.h @@ -42,14 +42,17 @@ typedef struct { extern const int avpriv_mpeg4audio_sample_rates[16]; extern const uint8_t ff_mpeg4audio_channels[8]; + /** * Parse MPEG-4 systems extradata to retrieve audio configuration. * @param[in] c MPEG4AudioConfig structure to fill. * @param[in] buf Extradata from container. - * @param[in] buf_size Extradata size. + * @param[in] bit_size Extradata size in bits. + * @param[in] sync_extension look for a sync extension after config if true. * @return On error -1 is returned, on success AudioSpecificConfig bit index in extradata. */ -int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size); +int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, + int bit_size, int sync_extension); enum AudioObjectType { AOT_NULL, diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index c819bc546f..eeef470a57 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -1966,7 +1966,8 @@ static int decode_init_mp3on4(AVCodecContext * avctx) return AVERROR_INVALIDDATA; } - avpriv_mpeg4audio_get_config(&cfg, avctx->extradata, avctx->extradata_size); + avpriv_mpeg4audio_get_config(&cfg, avctx->extradata, + avctx->extradata_size * 8, 1); if (!cfg.chan_config || cfg.chan_config > 7) { av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n"); return AVERROR_INVALIDDATA; |