]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ac3dec.c
Check *data_size in decode_frame()
[ffmpeg] / libavcodec / ac3dec.c
index 1f7ca8f71cec38f2ccae41526efdee9901bc70a4..d04209df2e507b501c46c5e36b379d480e0a3028 100644 (file)
@@ -276,16 +276,12 @@ static int ac3_parse_header(AC3DecodeContext *s)
 static int parse_frame_header(AC3DecodeContext *s)
 {
     AC3HeaderInfo hdr;
-    GetBitContext *gbc = &s->gbc;
     int err;
 
-    err = ff_ac3_parse_header(gbc, &hdr);
+    err = ff_ac3_parse_header(&s->gbc, &hdr);
     if(err)
         return err;
 
-    if(hdr.bitstream_id > 10)
-        return AC3_PARSE_ERROR_BSID;
-
     /* get decoding parameters from header info */
     s->bit_alloc_params.sr_code     = hdr.sr_code;
     s->channel_mode                 = hdr.channel_mode;
@@ -310,6 +306,9 @@ static int parse_frame_header(AC3DecodeContext *s)
         s->channel_in_cpl[s->lfe_ch] = 0;
     }
 
+    if(hdr.bitstream_id > 10)
+        return AC3_PARSE_ERROR_BSID;
+
     return ac3_parse_header(s);
 }
 
@@ -384,7 +383,7 @@ static void decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps,
  * range using the coupling coefficients and coupling coordinates.
  * reference: Section 7.4.3 Coupling Coordinate Format
  */
-static void uncouple_channels(AC3DecodeContext *s)
+static void calc_transform_coeffs_cpl(AC3DecodeContext *s)
 {
     int i, j, ch, bnd, subbnd;
 
@@ -547,7 +546,7 @@ static void get_transform_coeffs(AC3DecodeContext *s)
         if (s->channel_in_cpl[ch])  {
             if (!got_cplchan) {
                 get_transform_coeffs_ch(s, CPL_CH, &m);
-                uncouple_channels(s);
+                calc_transform_coeffs_cpl(s);
                 got_cplchan = 1;
             }
             end = s->end_freq[CPL_CH];
@@ -712,9 +711,9 @@ static void ac3_upmix_delay(AC3DecodeContext *s)
 }
 
 /**
- * Parse an audio block from AC-3 bitstream.
+ * Decode a single audio block from the AC-3 bitstream.
  */
-static int ac3_parse_audio_block(AC3DecodeContext *s, int blk)
+static int decode_audio_block(AC3DecodeContext *s, int blk)
 {
     int fbw_channels = s->fbw_channels;
     int channel_mode = s->channel_mode;
@@ -1165,10 +1164,10 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
             s->output_mode  = s->out_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO;
     }
 
-    /* parse the audio blocks */
+    /* decode the audio blocks */
     for (blk = 0; blk < s->num_blocks; blk++) {
-        if (!err && ac3_parse_audio_block(s, blk)) {
-            av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n");
+        if (!err && decode_audio_block(s, blk)) {
+            av_log(avctx, AV_LOG_ERROR, "error decoding the audio block\n");
         }
 
         /* interleave output samples */