]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegaudiodec.c
Add missing release_buffer on close
[ffmpeg] / libavcodec / mpegaudiodec.c
index 4c0d34a1165447bf2bae2b4900d8702a0cfaebf5..dd986bd85909a7459e2541942597cf25fe5f9917 100644 (file)
@@ -780,14 +780,14 @@ static inline int round_sample(int64_t *sum)
 
 #define SUM8(op, sum, w, p)               \
 {                                         \
-    op(sum, (w)[0 * 64], p[0 * 64]);      \
-    op(sum, (w)[1 * 64], p[1 * 64]);      \
-    op(sum, (w)[2 * 64], p[2 * 64]);      \
-    op(sum, (w)[3 * 64], p[3 * 64]);      \
-    op(sum, (w)[4 * 64], p[4 * 64]);      \
-    op(sum, (w)[5 * 64], p[5 * 64]);      \
-    op(sum, (w)[6 * 64], p[6 * 64]);      \
-    op(sum, (w)[7 * 64], p[7 * 64]);      \
+    op(sum, (w)[0 * 64], (p)[0 * 64]);    \
+    op(sum, (w)[1 * 64], (p)[1 * 64]);    \
+    op(sum, (w)[2 * 64], (p)[2 * 64]);    \
+    op(sum, (w)[3 * 64], (p)[3 * 64]);    \
+    op(sum, (w)[4 * 64], (p)[4 * 64]);    \
+    op(sum, (w)[5 * 64], (p)[5 * 64]);    \
+    op(sum, (w)[6 * 64], (p)[6 * 64]);    \
+    op(sum, (w)[7 * 64], (p)[7 * 64]);    \
 }
 
 #define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
@@ -2033,7 +2033,7 @@ static int mp_decode_layer3(MPADecodeContext *s)
         for(ch=0;ch<s->nb_channels;ch++) {
             g = &granules[ch][gr];
             if(get_bits_count(&s->gb)<0){
-                av_log(s->avctx, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skipping granule %d\n",
+                av_log(s->avctx, AV_LOG_DEBUG, "mdb:%d, lastbuf:%d skipping granule %d\n",
                                             main_data_begin, s->last_buf_size, gr);
                 skip_bits_long(&s->gb, g->part2_3_length);
                 memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));
@@ -2255,20 +2255,15 @@ static int decode_frame(AVCodecContext * avctx,
     MPADecodeContext *s = avctx->priv_data;
     uint32_t header;
     int out_size;
-    int skipped = 0;
     OUT_INT *out_samples = data;
 
-retry:
     if(buf_size < HEADER_SIZE)
         return -1;
 
     header = AV_RB32(buf);
     if(ff_mpa_check_header(header) < 0){
-        buf++;
-        buf_size--;
-        skipped++;
-        av_log(avctx, AV_LOG_ERROR, "Header missing skipping one byte.\n");
-        goto retry;
+        av_log(avctx, AV_LOG_ERROR, "Header missing\n");
+        return -1;
     }
 
     if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
@@ -2281,6 +2276,10 @@ retry:
     avctx->bit_rate = s->bit_rate;
     avctx->sub_id = s->layer;
 
+    if(*data_size < 1152*avctx->channels*sizeof(OUT_INT))
+        return -1;
+    *data_size = 0;
+
     if(s->frame_size<=0 || s->frame_size > buf_size){
         av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
         return -1;
@@ -2297,7 +2296,7 @@ retry:
     }else
         av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed
     s->frame_size = 0;
-    return buf_size + skipped;
+    return buf_size;
 }
 
 static void flush(AVCodecContext *avctx){
@@ -2468,6 +2467,9 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
     OUT_INT *outptr, *bp;
     int fr, j, n;
 
+    if(*data_size < MPA_FRAME_SIZE * MPA_MAX_CHANNELS * s->frames * sizeof(OUT_INT))
+        return -1;
+
     *data_size = 0;
     // Discard too short frames
     if (buf_size < HEADER_SIZE)