---
 libavcodec/aacdec.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 374616e..4fa3976 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -2313,8 +2313,9 @@ static inline uint32_t latm_get_value(GetBitContext *b)
 static int latm_decode_audio_specific_config(struct LATMContext *latmctx,
                                              GetBitContext *gb, int asclen)
 {
-    AVCodecContext *avctx = latmctx->aac_ctx.avctx;
-    MPEG4AudioConfig m4ac;
+    AACContext *ac        = &latmctx->aac_ctx;
+    AVCodecContext *avctx = ac->avctx;
+    MPEG4AudioConfig m4ac = {0};
     int  config_start_bit = get_bits_count(gb);
     int     bits_consumed, esize;
     int ebc_ps = 1;
@@ -2337,18 +2338,23 @@ static int latm_decode_audio_specific_config(struct 
LATMContext *latmctx,
         if (bits_consumed < 0)
             return AVERROR_INVALIDDATA;
 
-        esize = (bits_consumed+7) / 8;
+        if (ac->m4ac.sample_rate != m4ac.sample_rate ||
+            ac->m4ac.chan_config != m4ac.chan_config) {
+            latmctx->initialized = 0;
 
-        if (avctx->extradata_size <= esize) {
-            av_free(avctx->extradata);
-            avctx->extradata = av_malloc(esize + FF_INPUT_BUFFER_PADDING_SIZE);
-            if (!avctx->extradata)
-                return AVERROR(ENOMEM);
-        }
+            esize = (bits_consumed+7) / 8;
 
-        avctx->extradata_size = esize;
-        memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize);
-        memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+            if (avctx->extradata_size < esize) {
+                av_free(avctx->extradata);
+                avctx->extradata = av_malloc(esize + 
FF_INPUT_BUFFER_PADDING_SIZE);
+                if (!avctx->extradata)
+                    return AVERROR(ENOMEM);
+            }
+
+            avctx->extradata_size = esize;
+            memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize);
+            memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+        }
 
         skip_bits_long(gb, bits_consumed);
     }
-- 
1.7.7

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to