get the number of blocks from the ac3 parser and use in the ac3 decoder.
authorJustin Ruggles <justin.ruggles@gmail.com>
Sat, 7 Jun 2008 22:29:03 +0000 (22:29 +0000)
committerJustin Ruggles <justin.ruggles@gmail.com>
Sat, 7 Jun 2008 22:29:03 +0000 (22:29 +0000)
Originally committed as revision 13688 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/ac3.h
libavcodec/ac3_parser.c
libavcodec/ac3dec.c

index 9e9495ab39941d32f1a21acce5e6b2fcace093e0..a7c48ebc23eba9fda2e8452186bc4fb47bcda37a 100644 (file)
@@ -88,6 +88,7 @@ typedef struct {
     int center_mix_level;                   ///< Center mix level index
     int surround_mix_level;                 ///< Surround mix level index
     uint16_t channel_map;
+    int num_blocks;                         ///< number of audio blocks
     /** @} */
 
     /** @defgroup derived Derived values
index a6b9b740e05e6d376d9ae27e8ffb6ae3f1db3370..667c6d3821a7c8889ede8d17cd5e5fe4f16616f7 100644 (file)
@@ -49,7 +49,6 @@ static const uint8_t surround_levels[4] = { 2, 4, 0, 4 };
 int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
 {
     int frame_size_code;
-    int num_blocks;
 
     memset(hdr, 0, sizeof(*hdr));
 
@@ -62,6 +61,8 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
     if(hdr->bitstream_id > 16)
         return AC3_PARSE_ERROR_BSID;
 
+    hdr->num_blocks = 6;
+
     if(hdr->bitstream_id <= 10) {
         /* Normal AC-3 */
         hdr->crc1 = get_bits(gbc, 16);
@@ -118,9 +119,8 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
                 return AC3_PARSE_ERROR_SAMPLE_RATE;
             hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;
             hdr->sr_shift = 1;
-            num_blocks = 6;
         } else {
-            num_blocks = eac3_blocks[get_bits(gbc, 2)];
+            hdr->num_blocks = eac3_blocks[get_bits(gbc, 2)];
             hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code];
             hdr->sr_shift = 0;
         }
@@ -129,7 +129,7 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
         hdr->lfe_on = get_bits1(gbc);
 
         hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate /
-                        (num_blocks * 256.0));
+                        (hdr->num_blocks * 256.0));
         hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;
     }
 
index 29955cc6467cca6f15b44a9f9eeabd822f0efcec..ad5e0831f0e6e501b0ffb7cdf619494136aa3432 100644 (file)
@@ -111,6 +111,7 @@ static const uint8_t ac3_default_coeffs[8][5][2] = {
 #define AC3_OUTPUT_LFEON  8
 
 typedef struct {
+    int num_blocks;                         ///< number of audio blocks
     int channel_mode;                       ///< channel mode (acmod)
     int block_switch[AC3_MAX_CHANNELS];     ///< block switch flags
     int dither_flag[AC3_MAX_CHANNELS];      ///< dither flags
@@ -324,6 +325,7 @@ static int ac3_parse_header(AC3DecodeContext *s)
     s->frame_size                   = hdr.frame_size;
     s->center_mix_level             = hdr.center_mix_level;
     s->surround_mix_level           = hdr.surround_mix_level;
+    s->num_blocks                   = hdr.num_blocks;
 
     if(s->lfe_on) {
         s->start_freq[s->lfe_ch] = 0;
@@ -1206,7 +1208,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
     }
 
     /* parse the audio blocks */
-    for (blk = 0; blk < NB_BLOCKS; blk++) {
+    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");
         }
@@ -1216,7 +1218,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
             for (ch = 0; ch < s->out_channels; ch++)
                 *(out_samples++) = s->int_output[ch][i];
     }
-    *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t);
+    *data_size = s->num_blocks * 256 * avctx->channels * sizeof (int16_t);
     return s->frame_size;
 }