00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <stdio.h>
00033 #include <stddef.h>
00034 #include <math.h>
00035 #include <string.h>
00036
00037 #include "libavutil/crc.h"
00038 #include "internal.h"
00039 #include "aac_ac3_parser.h"
00040 #include "ac3_parser.h"
00041 #include "ac3dec.h"
00042 #include "ac3dec_data.h"
00043
00045 #define AC3_FRAME_BUFFER_SIZE 32768
00046
00051 static uint8_t ungroup_3_in_7_bits_tab[128][3];
00052
00053
00055 static int b1_mantissas[32][3];
00056 static int b2_mantissas[128][3];
00057 static int b3_mantissas[8];
00058 static int b4_mantissas[128][2];
00059 static int b5_mantissas[16];
00060
00065 static const uint8_t quantization_tab[16] = {
00066 0, 3, 5, 7, 11, 15,
00067 5, 6, 7, 8, 9, 10, 11, 12, 14, 16
00068 };
00069
00071 static float dynamic_range_tab[256];
00072
00074 #define LEVEL_PLUS_3DB 1.4142135623730950
00075 #define LEVEL_PLUS_1POINT5DB 1.1892071150027209
00076 #define LEVEL_MINUS_1POINT5DB 0.8408964152537145
00077 #define LEVEL_MINUS_3DB 0.7071067811865476
00078 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605
00079 #define LEVEL_MINUS_6DB 0.5000000000000000
00080 #define LEVEL_MINUS_9DB 0.3535533905932738
00081 #define LEVEL_ZERO 0.0000000000000000
00082 #define LEVEL_ONE 1.0000000000000000
00083
00084 static const float gain_levels[9] = {
00085 LEVEL_PLUS_3DB,
00086 LEVEL_PLUS_1POINT5DB,
00087 LEVEL_ONE,
00088 LEVEL_MINUS_1POINT5DB,
00089 LEVEL_MINUS_3DB,
00090 LEVEL_MINUS_4POINT5DB,
00091 LEVEL_MINUS_6DB,
00092 LEVEL_ZERO,
00093 LEVEL_MINUS_9DB
00094 };
00095
00100 static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
00101
00106 static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
00107
00112 static const uint8_t ac3_default_coeffs[8][5][2] = {
00113 { { 2, 7 }, { 7, 2 }, },
00114 { { 4, 4 }, },
00115 { { 2, 7 }, { 7, 2 }, },
00116 { { 2, 7 }, { 5, 5 }, { 7, 2 }, },
00117 { { 2, 7 }, { 7, 2 }, { 6, 6 }, },
00118 { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 }, },
00119 { { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
00120 { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
00121 };
00122
00128 static inline int
00129 symmetric_dequant(int code, int levels)
00130 {
00131 return ((code - (levels >> 1)) << 24) / levels;
00132 }
00133
00134
00135
00136
00137 static av_cold void ac3_tables_init(void)
00138 {
00139 int i;
00140
00141
00142
00143 for(i=0; i<128; i++) {
00144 ungroup_3_in_7_bits_tab[i][0] = i / 25;
00145 ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5;
00146 ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5;
00147 }
00148
00149
00150
00151 for(i=0; i<32; i++) {
00152
00153 b1_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][0], 3);
00154 b1_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][1], 3);
00155 b1_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][2], 3);
00156 }
00157 for(i=0; i<128; i++) {
00158
00159 b2_mantissas[i][0] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][0], 5);
00160 b2_mantissas[i][1] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][1], 5);
00161 b2_mantissas[i][2] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][2], 5);
00162
00163
00164 b4_mantissas[i][0] = symmetric_dequant(i / 11, 11);
00165 b4_mantissas[i][1] = symmetric_dequant(i % 11, 11);
00166 }
00167
00168
00169 for(i=0; i<7; i++) {
00170
00171 b3_mantissas[i] = symmetric_dequant(i, 7);
00172 }
00173 for(i=0; i<15; i++) {
00174
00175 b5_mantissas[i] = symmetric_dequant(i, 15);
00176 }
00177
00178
00179
00180 for(i=0; i<256; i++) {
00181 int v = (i >> 5) - ((i >> 7) << 3) - 5;
00182 dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20);
00183 }
00184 }
00185
00186
00190 static av_cold int ac3_decode_init(AVCodecContext *avctx)
00191 {
00192 AC3DecodeContext *s = avctx->priv_data;
00193 s->avctx = avctx;
00194
00195 ac3_common_init();
00196 ac3_tables_init();
00197 ff_mdct_init(&s->imdct_256, 8, 1);
00198 ff_mdct_init(&s->imdct_512, 9, 1);
00199 ff_kbd_window_init(s->window, 5.0, 256);
00200 dsputil_init(&s->dsp, avctx);
00201 av_lfg_init(&s->dith_state, 0);
00202
00203
00204 if(s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {
00205 s->add_bias = 385.0f;
00206 s->mul_bias = 1.0f;
00207 } else {
00208 s->add_bias = 0.0f;
00209 s->mul_bias = 32767.0f;
00210 }
00211
00212
00213 if (avctx->channels > 0 && avctx->request_channels > 0 &&
00214 avctx->request_channels < avctx->channels &&
00215 avctx->request_channels <= 2) {
00216 avctx->channels = avctx->request_channels;
00217 }
00218 s->downmixed = 1;
00219
00220
00221 if (avctx->error_recognition >= FF_ER_CAREFUL) {
00222 s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
00223 if (!s->input_buffer)
00224 return AVERROR_NOMEM;
00225 }
00226
00227 avctx->sample_fmt = SAMPLE_FMT_S16;
00228 return 0;
00229 }
00230
00236 static int ac3_parse_header(AC3DecodeContext *s)
00237 {
00238 GetBitContext *gbc = &s->gbc;
00239 int i;
00240
00241
00242 i = !(s->channel_mode);
00243 do {
00244 skip_bits(gbc, 5);
00245 if (get_bits1(gbc))
00246 skip_bits(gbc, 8);
00247 if (get_bits1(gbc))
00248 skip_bits(gbc, 8);
00249 if (get_bits1(gbc))
00250 skip_bits(gbc, 7);
00251 } while (i--);
00252
00253 skip_bits(gbc, 2);
00254
00255
00256
00257 if (get_bits1(gbc))
00258 skip_bits(gbc, 14);
00259 if (get_bits1(gbc))
00260 skip_bits(gbc, 14);
00261
00262
00263 if (get_bits1(gbc)) {
00264 i = get_bits(gbc, 6);
00265 do {
00266 skip_bits(gbc, 8);
00267 } while(i--);
00268 }
00269
00270 return 0;
00271 }
00272
00276 static int parse_frame_header(AC3DecodeContext *s)
00277 {
00278 AC3HeaderInfo hdr;
00279 int err;
00280
00281 err = ff_ac3_parse_header(&s->gbc, &hdr);
00282 if(err)
00283 return err;
00284
00285
00286 s->bit_alloc_params.sr_code = hdr.sr_code;
00287 s->channel_mode = hdr.channel_mode;
00288 s->lfe_on = hdr.lfe_on;
00289 s->bit_alloc_params.sr_shift = hdr.sr_shift;
00290 s->sample_rate = hdr.sample_rate;
00291 s->bit_rate = hdr.bit_rate;
00292 s->channels = hdr.channels;
00293 s->fbw_channels = s->channels - s->lfe_on;
00294 s->lfe_ch = s->fbw_channels + 1;
00295 s->frame_size = hdr.frame_size;
00296 s->center_mix_level = hdr.center_mix_level;
00297 s->surround_mix_level = hdr.surround_mix_level;
00298 s->num_blocks = hdr.num_blocks;
00299 s->frame_type = hdr.frame_type;
00300 s->substreamid = hdr.substreamid;
00301
00302 if(s->lfe_on) {
00303 s->start_freq[s->lfe_ch] = 0;
00304 s->end_freq[s->lfe_ch] = 7;
00305 s->num_exp_groups[s->lfe_ch] = 2;
00306 s->channel_in_cpl[s->lfe_ch] = 0;
00307 }
00308
00309 if (hdr.bitstream_id <= 10) {
00310 s->eac3 = 0;
00311 s->snr_offset_strategy = 2;
00312 s->block_switch_syntax = 1;
00313 s->dither_flag_syntax = 1;
00314 s->bit_allocation_syntax = 1;
00315 s->fast_gain_syntax = 0;
00316 s->first_cpl_leak = 0;
00317 s->dba_syntax = 1;
00318 s->skip_syntax = 1;
00319 memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
00320 return ac3_parse_header(s);
00321 } else {
00322 s->eac3 = 1;
00323 return ff_eac3_parse_header(s);
00324 }
00325 }
00326
00331 static void set_downmix_coeffs(AC3DecodeContext *s)
00332 {
00333 int i;
00334 float cmix = gain_levels[center_levels[s->center_mix_level]];
00335 float smix = gain_levels[surround_levels[s->surround_mix_level]];
00336 float norm0, norm1;
00337
00338 for(i=0; i<s->fbw_channels; i++) {
00339 s->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]];
00340 s->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]];
00341 }
00342 if(s->channel_mode > 1 && s->channel_mode & 1) {
00343 s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix;
00344 }
00345 if(s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) {
00346 int nf = s->channel_mode - 2;
00347 s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB;
00348 }
00349 if(s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) {
00350 int nf = s->channel_mode - 4;
00351 s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix;
00352 }
00353
00354
00355 norm0 = norm1 = 0.0;
00356 for(i=0; i<s->fbw_channels; i++) {
00357 norm0 += s->downmix_coeffs[i][0];
00358 norm1 += s->downmix_coeffs[i][1];
00359 }
00360 norm0 = 1.0f / norm0;
00361 norm1 = 1.0f / norm1;
00362 for(i=0; i<s->fbw_channels; i++) {
00363 s->downmix_coeffs[i][0] *= norm0;
00364 s->downmix_coeffs[i][1] *= norm1;
00365 }
00366
00367 if(s->output_mode == AC3_CHMODE_MONO) {
00368 for(i=0; i<s->fbw_channels; i++)
00369 s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB;
00370 }
00371 }
00372
00377 static int decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps,
00378 uint8_t absexp, int8_t *dexps)
00379 {
00380 int i, j, grp, group_size;
00381 int dexp[256];
00382 int expacc, prevexp;
00383
00384
00385 group_size = exp_strategy + (exp_strategy == EXP_D45);
00386 for(grp=0,i=0; grp<ngrps; grp++) {
00387 expacc = get_bits(gbc, 7);
00388 dexp[i++] = ungroup_3_in_7_bits_tab[expacc][0];
00389 dexp[i++] = ungroup_3_in_7_bits_tab[expacc][1];
00390 dexp[i++] = ungroup_3_in_7_bits_tab[expacc][2];
00391 }
00392
00393
00394 prevexp = absexp;
00395 for(i=0,j=0; i<ngrps*3; i++) {
00396 prevexp += dexp[i] - 2;
00397 if (prevexp > 24U)
00398 return -1;
00399 switch (group_size) {
00400 case 4: dexps[j++] = prevexp;
00401 dexps[j++] = prevexp;
00402 case 2: dexps[j++] = prevexp;
00403 case 1: dexps[j++] = prevexp;
00404 }
00405 }
00406 return 0;
00407 }
00408
00414 static void calc_transform_coeffs_cpl(AC3DecodeContext *s)
00415 {
00416 int i, j, ch, bnd, subbnd;
00417
00418 subbnd = -1;
00419 i = s->start_freq[CPL_CH];
00420 for(bnd=0; bnd<s->num_cpl_bands; bnd++) {
00421 do {
00422 subbnd++;
00423 for(j=0; j<12; j++) {
00424 for(ch=1; ch<=s->fbw_channels; ch++) {
00425 if(s->channel_in_cpl[ch]) {
00426 s->fixed_coeffs[ch][i] = ((int64_t)s->fixed_coeffs[CPL_CH][i] * (int64_t)s->cpl_coords[ch][bnd]) >> 23;
00427 if (ch == 2 && s->phase_flags[bnd])
00428 s->fixed_coeffs[ch][i] = -s->fixed_coeffs[ch][i];
00429 }
00430 }
00431 i++;
00432 }
00433 } while(s->cpl_band_struct[subbnd]);
00434 }
00435 }
00436
00440 typedef struct {
00441 int b1_mant[3];
00442 int b2_mant[3];
00443 int b4_mant[2];
00444 int b1ptr;
00445 int b2ptr;
00446 int b4ptr;
00447 } mant_groups;
00448
00453 static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m)
00454 {
00455 GetBitContext *gbc = &s->gbc;
00456 int i, gcode, tbap, start, end;
00457 uint8_t *exps;
00458 uint8_t *bap;
00459 int *coeffs;
00460
00461 exps = s->dexps[ch_index];
00462 bap = s->bap[ch_index];
00463 coeffs = s->fixed_coeffs[ch_index];
00464 start = s->start_freq[ch_index];
00465 end = s->end_freq[ch_index];
00466
00467 for (i = start; i < end; i++) {
00468 tbap = bap[i];
00469 switch (tbap) {
00470 case 0:
00471 coeffs[i] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
00472 break;
00473
00474 case 1:
00475 if(m->b1ptr > 2) {
00476 gcode = get_bits(gbc, 5);
00477 m->b1_mant[0] = b1_mantissas[gcode][0];
00478 m->b1_mant[1] = b1_mantissas[gcode][1];
00479 m->b1_mant[2] = b1_mantissas[gcode][2];
00480 m->b1ptr = 0;
00481 }
00482 coeffs[i] = m->b1_mant[m->b1ptr++];
00483 break;
00484
00485 case 2:
00486 if(m->b2ptr > 2) {
00487 gcode = get_bits(gbc, 7);
00488 m->b2_mant[0] = b2_mantissas[gcode][0];
00489 m->b2_mant[1] = b2_mantissas[gcode][1];
00490 m->b2_mant[2] = b2_mantissas[gcode][2];
00491 m->b2ptr = 0;
00492 }
00493 coeffs[i] = m->b2_mant[m->b2ptr++];
00494 break;
00495
00496 case 3:
00497 coeffs[i] = b3_mantissas[get_bits(gbc, 3)];
00498 break;
00499
00500 case 4:
00501 if(m->b4ptr > 1) {
00502 gcode = get_bits(gbc, 7);
00503 m->b4_mant[0] = b4_mantissas[gcode][0];
00504 m->b4_mant[1] = b4_mantissas[gcode][1];
00505 m->b4ptr = 0;
00506 }
00507 coeffs[i] = m->b4_mant[m->b4ptr++];
00508 break;
00509
00510 case 5:
00511 coeffs[i] = b5_mantissas[get_bits(gbc, 4)];
00512 break;
00513
00514 default: {
00515
00516 int qlevel = quantization_tab[tbap];
00517 coeffs[i] = get_sbits(gbc, qlevel) << (24 - qlevel);
00518 break;
00519 }
00520 }
00521 coeffs[i] >>= exps[i];
00522 }
00523 }
00524
00529 static void remove_dithering(AC3DecodeContext *s) {
00530 int ch, i;
00531 int end=0;
00532 int *coeffs;
00533 uint8_t *bap;
00534
00535 for(ch=1; ch<=s->fbw_channels; ch++) {
00536 if(!s->dither_flag[ch]) {
00537 coeffs = s->fixed_coeffs[ch];
00538 bap = s->bap[ch];
00539 if(s->channel_in_cpl[ch])
00540 end = s->start_freq[CPL_CH];
00541 else
00542 end = s->end_freq[ch];
00543 for(i=0; i<end; i++) {
00544 if(!bap[i])
00545 coeffs[i] = 0;
00546 }
00547 if(s->channel_in_cpl[ch]) {
00548 bap = s->bap[CPL_CH];
00549 for(; i<s->end_freq[CPL_CH]; i++) {
00550 if(!bap[i])
00551 coeffs[i] = 0;
00552 }
00553 }
00554 }
00555 }
00556 }
00557
00558 static void decode_transform_coeffs_ch(AC3DecodeContext *s, int blk, int ch,
00559 mant_groups *m)
00560 {
00561 if (!s->channel_uses_aht[ch]) {
00562 ac3_decode_transform_coeffs_ch(s, ch, m);
00563 } else {
00564
00565
00566 int bin;
00567 if (!blk)
00568 ff_eac3_decode_transform_coeffs_aht_ch(s, ch);
00569 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
00570 s->fixed_coeffs[ch][bin] = s->pre_mantissa[ch][bin][blk] >> s->dexps[ch][bin];
00571 }
00572 }
00573 }
00574
00578 static void decode_transform_coeffs(AC3DecodeContext *s, int blk)
00579 {
00580 int ch, end;
00581 int got_cplchan = 0;
00582 mant_groups m;
00583
00584 m.b1ptr = m.b2ptr = m.b4ptr = 3;
00585
00586 for (ch = 1; ch <= s->channels; ch++) {
00587
00588 decode_transform_coeffs_ch(s, blk, ch, &m);
00589
00590
00591 if (s->channel_in_cpl[ch]) {
00592 if (!got_cplchan) {
00593 decode_transform_coeffs_ch(s, blk, CPL_CH, &m);
00594 calc_transform_coeffs_cpl(s);
00595 got_cplchan = 1;
00596 }
00597 end = s->end_freq[CPL_CH];
00598 } else {
00599 end = s->end_freq[ch];
00600 }
00601 do
00602 s->fixed_coeffs[ch][end] = 0;
00603 while(++end < 256);
00604 }
00605
00606
00607 remove_dithering(s);
00608 }
00609
00614 static void do_rematrixing(AC3DecodeContext *s)
00615 {
00616 int bnd, i;
00617 int end, bndend;
00618 int tmp0, tmp1;
00619
00620 end = FFMIN(s->end_freq[1], s->end_freq[2]);
00621
00622 for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) {
00623 if(s->rematrixing_flags[bnd]) {
00624 bndend = FFMIN(end, ff_ac3_rematrix_band_tab[bnd+1]);
00625 for(i=ff_ac3_rematrix_band_tab[bnd]; i<bndend; i++) {
00626 tmp0 = s->fixed_coeffs[1][i];
00627 tmp1 = s->fixed_coeffs[2][i];
00628 s->fixed_coeffs[1][i] = tmp0 + tmp1;
00629 s->fixed_coeffs[2][i] = tmp0 - tmp1;
00630 }
00631 }
00632 }
00633 }
00634
00640 static inline void do_imdct(AC3DecodeContext *s, int channels)
00641 {
00642 int ch;
00643 float add_bias = s->add_bias;
00644 if(s->out_channels==1 && channels>1)
00645 add_bias *= LEVEL_MINUS_3DB;
00646
00647 for (ch=1; ch<=channels; ch++) {
00648 if (s->block_switch[ch]) {
00649 int i;
00650 float *x = s->tmp_output+128;
00651 for(i=0; i<128; i++)
00652 x[i] = s->transform_coeffs[ch][2*i];
00653 ff_imdct_half(&s->imdct_256, s->tmp_output, x);
00654 s->dsp.vector_fmul_window(s->output[ch-1], s->delay[ch-1], s->tmp_output, s->window, add_bias, 128);
00655 for(i=0; i<128; i++)
00656 x[i] = s->transform_coeffs[ch][2*i+1];
00657 ff_imdct_half(&s->imdct_256, s->delay[ch-1], x);
00658 } else {
00659 ff_imdct_half(&s->imdct_512, s->tmp_output, s->transform_coeffs[ch]);
00660 s->dsp.vector_fmul_window(s->output[ch-1], s->delay[ch-1], s->tmp_output, s->window, add_bias, 128);
00661 memcpy(s->delay[ch-1], s->tmp_output+128, 128*sizeof(float));
00662 }
00663 }
00664 }
00665
00669 void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len)
00670 {
00671 int i, j;
00672 float v0, v1;
00673 if(out_ch == 2) {
00674 for(i=0; i<len; i++) {
00675 v0 = v1 = 0.0f;
00676 for(j=0; j<in_ch; j++) {
00677 v0 += samples[j][i] * matrix[j][0];
00678 v1 += samples[j][i] * matrix[j][1];
00679 }
00680 samples[0][i] = v0;
00681 samples[1][i] = v1;
00682 }
00683 } else if(out_ch == 1) {
00684 for(i=0; i<len; i++) {
00685 v0 = 0.0f;
00686 for(j=0; j<in_ch; j++)
00687 v0 += samples[j][i] * matrix[j][0];
00688 samples[0][i] = v0;
00689 }
00690 }
00691 }
00692
00696 static void ac3_upmix_delay(AC3DecodeContext *s)
00697 {
00698 int channel_data_size = sizeof(s->delay[0]);
00699 switch(s->channel_mode) {
00700 case AC3_CHMODE_DUALMONO:
00701 case AC3_CHMODE_STEREO:
00702
00703 memcpy(s->delay[1], s->delay[0], channel_data_size);
00704 break;
00705 case AC3_CHMODE_2F2R:
00706 memset(s->delay[3], 0, channel_data_size);
00707 case AC3_CHMODE_2F1R:
00708 memset(s->delay[2], 0, channel_data_size);
00709 break;
00710 case AC3_CHMODE_3F2R:
00711 memset(s->delay[4], 0, channel_data_size);
00712 case AC3_CHMODE_3F1R:
00713 memset(s->delay[3], 0, channel_data_size);
00714 case AC3_CHMODE_3F:
00715 memcpy(s->delay[2], s->delay[1], channel_data_size);
00716 memset(s->delay[1], 0, channel_data_size);
00717 break;
00718 }
00719 }
00720
00735 static void decode_band_structure(GetBitContext *gbc, int blk, int eac3,
00736 int ecpl, int start_subband, int end_subband,
00737 const uint8_t *default_band_struct,
00738 uint8_t *band_struct, int *num_subbands,
00739 int *num_bands, uint8_t *band_sizes)
00740 {
00741 int subbnd, bnd, n_subbands, n_bands=0;
00742 uint8_t bnd_sz[22];
00743
00744 n_subbands = end_subband - start_subband;
00745
00746
00747 if (!eac3 || get_bits1(gbc)) {
00748 for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
00749 band_struct[subbnd] = get_bits1(gbc);
00750 }
00751 } else if (!blk) {
00752 memcpy(band_struct,
00753 &default_band_struct[start_subband+1],
00754 n_subbands-1);
00755 }
00756 band_struct[n_subbands-1] = 0;
00757
00758
00759
00760
00761 if (num_bands || band_sizes ) {
00762 n_bands = n_subbands;
00763 bnd_sz[0] = ecpl ? 6 : 12;
00764 for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) {
00765 int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12;
00766 if (band_struct[subbnd-1]) {
00767 n_bands--;
00768 bnd_sz[bnd] += subbnd_size;
00769 } else {
00770 bnd_sz[++bnd] = subbnd_size;
00771 }
00772 }
00773 }
00774
00775
00776 if (num_subbands)
00777 *num_subbands = n_subbands;
00778 if (num_bands)
00779 *num_bands = n_bands;
00780 if (band_sizes)
00781 memcpy(band_sizes, bnd_sz, n_bands);
00782 }
00783
00787 static int decode_audio_block(AC3DecodeContext *s, int blk)
00788 {
00789 int fbw_channels = s->fbw_channels;
00790 int channel_mode = s->channel_mode;
00791 int i, bnd, seg, ch;
00792 int different_transforms;
00793 int downmix_output;
00794 int cpl_in_use;
00795 GetBitContext *gbc = &s->gbc;
00796 uint8_t bit_alloc_stages[AC3_MAX_CHANNELS];
00797
00798 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS);
00799
00800
00801 different_transforms = 0;
00802 if (s->block_switch_syntax) {
00803 for (ch = 1; ch <= fbw_channels; ch++) {
00804 s->block_switch[ch] = get_bits1(gbc);
00805 if(ch > 1 && s->block_switch[ch] != s->block_switch[1])
00806 different_transforms = 1;
00807 }
00808 }
00809
00810
00811 if (s->dither_flag_syntax) {
00812 for (ch = 1; ch <= fbw_channels; ch++) {
00813 s->dither_flag[ch] = get_bits1(gbc);
00814 }
00815 }
00816
00817
00818 i = !(s->channel_mode);
00819 do {
00820 if(get_bits1(gbc)) {
00821 s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) *
00822 s->avctx->drc_scale)+1.0;
00823 } else if(blk == 0) {
00824 s->dynamic_range[i] = 1.0f;
00825 }
00826 } while(i--);
00827
00828
00829 if (s->eac3 && (!blk || get_bits1(gbc))) {
00830 if (get_bits1(gbc)) {
00831 ff_log_missing_feature(s->avctx, "Spectral extension", 1);
00832 return -1;
00833 }
00834
00835 }
00836
00837
00838
00839
00840 if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) {
00841 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);
00842 if (!s->eac3)
00843 s->cpl_in_use[blk] = get_bits1(gbc);
00844 if (s->cpl_in_use[blk]) {
00845
00846 int cpl_start_subband, cpl_end_subband;
00847
00848 if (channel_mode < AC3_CHMODE_STEREO) {
00849 av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");
00850 return -1;
00851 }
00852
00853
00854 if (s->eac3 && get_bits1(gbc)) {
00855
00856 ff_log_missing_feature(s->avctx, "Enhanced coupling", 1);
00857 return -1;
00858 }
00859
00860
00861 if (s->eac3 && s->channel_mode == AC3_CHMODE_STEREO) {
00862 s->channel_in_cpl[1] = 1;
00863 s->channel_in_cpl[2] = 1;
00864 } else {
00865 for (ch = 1; ch <= fbw_channels; ch++)
00866 s->channel_in_cpl[ch] = get_bits1(gbc);
00867 }
00868
00869
00870 if (channel_mode == AC3_CHMODE_STEREO)
00871 s->phase_flags_in_use = get_bits1(gbc);
00872
00873
00874
00875 cpl_start_subband = get_bits(gbc, 4);
00876 cpl_end_subband = get_bits(gbc, 4) + 3;
00877 s->num_cpl_subbands = cpl_end_subband - cpl_start_subband;
00878 if (s->num_cpl_subbands < 0) {
00879 av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d > %d)\n",
00880 cpl_start_subband, cpl_end_subband);
00881 return -1;
00882 }
00883 s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;
00884 s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37;
00885
00886 decode_band_structure(gbc, blk, s->eac3, 0,
00887 cpl_start_subband, cpl_end_subband,
00888 ff_eac3_default_cpl_band_struct,
00889 s->cpl_band_struct, &s->num_cpl_subbands,
00890 &s->num_cpl_bands, NULL);
00891 } else {
00892
00893 for (ch = 1; ch <= fbw_channels; ch++) {
00894 s->channel_in_cpl[ch] = 0;
00895 s->first_cpl_coords[ch] = 1;
00896 }
00897 s->first_cpl_leak = s->eac3;
00898 s->phase_flags_in_use = 0;
00899 }
00900 } else if (!s->eac3) {
00901 if(!blk) {
00902 av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n");
00903 return -1;
00904 } else {
00905 s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
00906 }
00907 }
00908 cpl_in_use = s->cpl_in_use[blk];
00909
00910
00911 if (cpl_in_use) {
00912 int cpl_coords_exist = 0;
00913
00914 for (ch = 1; ch <= fbw_channels; ch++) {
00915 if (s->channel_in_cpl[ch]) {
00916 if ((s->eac3 && s->first_cpl_coords[ch]) || get_bits1(gbc)) {
00917 int master_cpl_coord, cpl_coord_exp, cpl_coord_mant;
00918 s->first_cpl_coords[ch] = 0;
00919 cpl_coords_exist = 1;
00920 master_cpl_coord = 3 * get_bits(gbc, 2);
00921 for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
00922 cpl_coord_exp = get_bits(gbc, 4);
00923 cpl_coord_mant = get_bits(gbc, 4);
00924 if (cpl_coord_exp == 15)
00925 s->cpl_coords[ch][bnd] = cpl_coord_mant << 22;
00926 else
00927 s->cpl_coords[ch][bnd] = (cpl_coord_mant + 16) << 21;
00928 s->cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord);
00929 }
00930 } else if (!blk) {
00931 av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must be present in block 0\n");
00932 return -1;
00933 }
00934 } else {
00935
00936 s->first_cpl_coords[ch] = 1;
00937 }
00938 }
00939
00940 if (channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) {
00941 for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
00942 s->phase_flags[bnd] = s->phase_flags_in_use? get_bits1(gbc) : 0;
00943 }
00944 }
00945 }
00946
00947
00948 if (channel_mode == AC3_CHMODE_STEREO) {
00949 if ((s->eac3 && !blk) || get_bits1(gbc)) {
00950 s->num_rematrixing_bands = 4;
00951 if(cpl_in_use && s->start_freq[CPL_CH] <= 61)
00952 s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37);
00953 for(bnd=0; bnd<s->num_rematrixing_bands; bnd++)
00954 s->rematrixing_flags[bnd] = get_bits1(gbc);
00955 } else if (!blk) {
00956 av_log(s->avctx, AV_LOG_ERROR, "new rematrixing strategy must be present in block 0\n");
00957 return -1;
00958 }
00959 }
00960
00961
00962 for (ch = !cpl_in_use; ch <= s->channels; ch++) {
00963 if (!s->eac3)
00964 s->exp_strategy[blk][ch] = get_bits(gbc, 2 - (ch == s->lfe_ch));
00965 if(s->exp_strategy[blk][ch] != EXP_REUSE)
00966 bit_alloc_stages[ch] = 3;
00967 }
00968
00969
00970 for (ch = 1; ch <= fbw_channels; ch++) {
00971 s->start_freq[ch] = 0;
00972 if (s->exp_strategy[blk][ch] != EXP_REUSE) {
00973 int group_size;
00974 int prev = s->end_freq[ch];
00975 if (s->channel_in_cpl[ch])
00976 s->end_freq[ch] = s->start_freq[CPL_CH];
00977 else {
00978 int bandwidth_code = get_bits(gbc, 6);
00979 if (bandwidth_code > 60) {
00980 av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60\n", bandwidth_code);
00981 return -1;
00982 }
00983 s->end_freq[ch] = bandwidth_code * 3 + 73;
00984 }
00985 group_size = 3 << (s->exp_strategy[blk][ch] - 1);
00986 s->num_exp_groups[ch] = (s->end_freq[ch]+group_size-4) / group_size;
00987 if(blk > 0 && s->end_freq[ch] != prev)
00988 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);
00989 }
00990 }
00991 if (cpl_in_use && s->exp_strategy[blk][CPL_CH] != EXP_REUSE) {
00992 s->num_exp_groups[CPL_CH] = (s->end_freq[CPL_CH] - s->start_freq[CPL_CH]) /
00993 (3 << (s->exp_strategy[blk][CPL_CH] - 1));
00994 }
00995
00996
00997 for (ch = !cpl_in_use; ch <= s->channels; ch++) {
00998 if (s->exp_strategy[blk][ch] != EXP_REUSE) {
00999 s->dexps[ch][0] = get_bits(gbc, 4) << !ch;
01000 if (decode_exponents(gbc, s->exp_strategy[blk][ch],
01001 s->num_exp_groups[ch], s->dexps[ch][0],
01002 &s->dexps[ch][s->start_freq[ch]+!!ch])) {
01003 av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n");
01004 return -1;
01005 }
01006 if(ch != CPL_CH && ch != s->lfe_ch)
01007 skip_bits(gbc, 2);
01008 }
01009 }
01010
01011
01012 if (s->bit_allocation_syntax) {
01013 if (get_bits1(gbc)) {
01014 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift;
01015 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift;
01016 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)];
01017 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)];
01018 s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)];
01019 for(ch=!cpl_in_use; ch<=s->channels; ch++)
01020 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
01021 } else if (!blk) {
01022 av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n");
01023 return -1;
01024 }
01025 }
01026
01027
01028 if(!s->eac3 || !blk){
01029 if(s->snr_offset_strategy && get_bits1(gbc)) {
01030 int snr = 0;
01031 int csnr;
01032 csnr = (get_bits(gbc, 6) - 15) << 4;
01033 for (i = ch = !cpl_in_use; ch <= s->channels; ch++) {
01034
01035 if (ch == i || s->snr_offset_strategy == 2)
01036 snr = (csnr + get_bits(gbc, 4)) << 2;
01037
01038 if(blk && s->snr_offset[ch] != snr) {
01039 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 1);
01040 }
01041 s->snr_offset[ch] = snr;
01042
01043
01044 if (!s->eac3) {
01045 int prev = s->fast_gain[ch];
01046 s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)];
01047
01048 if(blk && prev != s->fast_gain[ch])
01049 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
01050 }
01051 }
01052 } else if (!s->eac3 && !blk) {
01053 av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n");
01054 return -1;
01055 }
01056 }
01057
01058
01059 if (s->fast_gain_syntax && get_bits1(gbc)) {
01060 for (ch = !cpl_in_use; ch <= s->channels; ch++) {
01061 int prev = s->fast_gain[ch];
01062 s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)];
01063
01064 if(blk && prev != s->fast_gain[ch])
01065 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
01066 }
01067 } else if (s->eac3 && !blk) {
01068 for (ch = !cpl_in_use; ch <= s->channels; ch++)
01069 s->fast_gain[ch] = ff_ac3_fast_gain_tab[4];
01070 }
01071
01072
01073 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && get_bits1(gbc)) {
01074 skip_bits(gbc, 10);
01075 }
01076
01077
01078 if (cpl_in_use) {
01079 if (s->first_cpl_leak || get_bits1(gbc)) {
01080 int fl = get_bits(gbc, 3);
01081 int sl = get_bits(gbc, 3);
01082
01083
01084 if(blk && (fl != s->bit_alloc_params.cpl_fast_leak ||
01085 sl != s->bit_alloc_params.cpl_slow_leak)) {
01086 bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2);
01087 }
01088 s->bit_alloc_params.cpl_fast_leak = fl;
01089 s->bit_alloc_params.cpl_slow_leak = sl;
01090 } else if (!s->eac3 && !blk) {
01091 av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must be present in block 0\n");
01092 return -1;
01093 }
01094 s->first_cpl_leak = 0;
01095 }
01096
01097
01098 if (s->dba_syntax && get_bits1(gbc)) {
01099
01100 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
01101 s->dba_mode[ch] = get_bits(gbc, 2);
01102 if (s->dba_mode[ch] == DBA_RESERVED) {
01103 av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
01104 return -1;
01105 }
01106 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
01107 }
01108
01109 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
01110 if (s->dba_mode[ch] == DBA_NEW) {
01111 s->dba_nsegs[ch] = get_bits(gbc, 3);
01112 for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) {
01113 s->dba_offsets[ch][seg] = get_bits(gbc, 5);
01114 s->dba_lengths[ch][seg] = get_bits(gbc, 4);
01115 s->dba_values[ch][seg] = get_bits(gbc, 3);
01116 }
01117
01118 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
01119 }
01120 }
01121 } else if(blk == 0) {
01122 for(ch=0; ch<=s->channels; ch++) {
01123 s->dba_mode[ch] = DBA_NONE;
01124 }
01125 }
01126
01127
01128 for(ch=!cpl_in_use; ch<=s->channels; ch++) {
01129 if(bit_alloc_stages[ch] > 2) {
01130
01131 ff_ac3_bit_alloc_calc_psd(s->dexps[ch],
01132 s->start_freq[ch], s->end_freq[ch],
01133 s->psd[ch], s->band_psd[ch]);
01134 }
01135 if(bit_alloc_stages[ch] > 1) {
01136
01137
01138 if (ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params, s->band_psd[ch],
01139 s->start_freq[ch], s->end_freq[ch],
01140 s->fast_gain[ch], (ch == s->lfe_ch),
01141 s->dba_mode[ch], s->dba_nsegs[ch],
01142 s->dba_offsets[ch], s->dba_lengths[ch],
01143 s->dba_values[ch], s->mask[ch])) {
01144 av_log(s->avctx, AV_LOG_ERROR, "error in bit allocation\n");
01145 return -1;
01146 }
01147 }
01148 if(bit_alloc_stages[ch] > 0) {
01149
01150 const uint8_t *bap_tab = s->channel_uses_aht[ch] ?
01151 ff_eac3_hebap_tab : ff_ac3_bap_tab;
01152 ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch],
01153 s->start_freq[ch], s->end_freq[ch],
01154 s->snr_offset[ch],
01155 s->bit_alloc_params.floor,
01156 bap_tab, s->bap[ch]);
01157 }
01158 }
01159
01160
01161 if (s->skip_syntax && get_bits1(gbc)) {
01162 int skipl = get_bits(gbc, 9);
01163 while(skipl--)
01164 skip_bits(gbc, 8);
01165 }
01166
01167
01168
01169 decode_transform_coeffs(s, blk);
01170
01171
01172
01173
01174
01175
01176 if(s->channel_mode == AC3_CHMODE_STEREO)
01177 do_rematrixing(s);
01178
01179
01180 for(ch=1; ch<=s->channels; ch++) {
01181 float gain = s->mul_bias / 4194304.0f;
01182 if(s->channel_mode == AC3_CHMODE_DUALMONO) {
01183 gain *= s->dynamic_range[ch-1];
01184 } else {
01185 gain *= s->dynamic_range[0];
01186 }
01187 s->dsp.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256);
01188 }
01189
01190
01191
01192
01193 downmix_output = s->channels != s->out_channels &&
01194 !((s->output_mode & AC3_OUTPUT_LFEON) &&
01195 s->fbw_channels == s->out_channels);
01196 if(different_transforms) {
01197
01198
01199 if(s->downmixed) {
01200 s->downmixed = 0;
01201 ac3_upmix_delay(s);
01202 }
01203
01204 do_imdct(s, s->channels);
01205
01206 if(downmix_output) {
01207 s->dsp.ac3_downmix(s->output, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256);
01208 }
01209 } else {
01210 if(downmix_output) {
01211 s->dsp.ac3_downmix(s->transform_coeffs+1, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256);
01212 }
01213
01214 if(downmix_output && !s->downmixed) {
01215 s->downmixed = 1;
01216 s->dsp.ac3_downmix(s->delay, s->downmix_coeffs, s->out_channels, s->fbw_channels, 128);
01217 }
01218
01219 do_imdct(s, s->out_channels);
01220 }
01221
01222 return 0;
01223 }
01224
01228 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
01229 const uint8_t *buf, int buf_size)
01230 {
01231 AC3DecodeContext *s = avctx->priv_data;
01232 int16_t *out_samples = (int16_t *)data;
01233 int blk, ch, err;
01234
01235
01236 if (s->input_buffer) {
01237
01238
01239 memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE));
01240 init_get_bits(&s->gbc, s->input_buffer, buf_size * 8);
01241 } else {
01242 init_get_bits(&s->gbc, buf, buf_size * 8);
01243 }
01244
01245
01246 *data_size = 0;
01247 err = parse_frame_header(s);
01248
01249
01250 if(s->frame_size > buf_size) {
01251 av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
01252 err = AAC_AC3_PARSE_ERROR_FRAME_SIZE;
01253 }
01254
01255
01256 if(err != AAC_AC3_PARSE_ERROR_FRAME_SIZE && avctx->error_recognition >= FF_ER_CAREFUL) {
01257 if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) {
01258 av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n");
01259 err = AAC_AC3_PARSE_ERROR_CRC;
01260 }
01261 }
01262
01263 if(err && err != AAC_AC3_PARSE_ERROR_CRC) {
01264 switch(err) {
01265 case AAC_AC3_PARSE_ERROR_SYNC:
01266 av_log(avctx, AV_LOG_ERROR, "frame sync error\n");
01267 return -1;
01268 case AAC_AC3_PARSE_ERROR_BSID:
01269 av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n");
01270 break;
01271 case AAC_AC3_PARSE_ERROR_SAMPLE_RATE:
01272 av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
01273 break;
01274 case AAC_AC3_PARSE_ERROR_FRAME_SIZE:
01275 av_log(avctx, AV_LOG_ERROR, "invalid frame size\n");
01276 break;
01277 case AAC_AC3_PARSE_ERROR_FRAME_TYPE:
01278
01279
01280 if(s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) {
01281 av_log(avctx, AV_LOG_ERROR, "unsupported frame type : skipping frame\n");
01282 return s->frame_size;
01283 } else {
01284 av_log(avctx, AV_LOG_ERROR, "invalid frame type\n");
01285 }
01286 break;
01287 default:
01288 av_log(avctx, AV_LOG_ERROR, "invalid header\n");
01289 break;
01290 }
01291 }
01292
01293
01294 if (!err) {
01295 avctx->sample_rate = s->sample_rate;
01296 avctx->bit_rate = s->bit_rate;
01297
01298
01299 s->out_channels = s->channels;
01300 s->output_mode = s->channel_mode;
01301 if(s->lfe_on)
01302 s->output_mode |= AC3_OUTPUT_LFEON;
01303 if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
01304 avctx->request_channels < s->channels) {
01305 s->out_channels = avctx->request_channels;
01306 s->output_mode = avctx->request_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO;
01307 }
01308 avctx->channels = s->out_channels;
01309
01310
01311 if(s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) &&
01312 s->fbw_channels == s->out_channels)) {
01313 set_downmix_coeffs(s);
01314 }
01315 } else if (!s->out_channels) {
01316 s->out_channels = avctx->channels;
01317 if(s->out_channels < s->channels)
01318 s->output_mode = s->out_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO;
01319 }
01320
01321
01322 for (blk = 0; blk < s->num_blocks; blk++) {
01323 const float *output[s->out_channels];
01324 if (!err && decode_audio_block(s, blk)) {
01325 av_log(avctx, AV_LOG_ERROR, "error decoding the audio block\n");
01326 err = 1;
01327 }
01328 for (ch = 0; ch < s->out_channels; ch++)
01329 output[ch] = s->output[ch];
01330 s->dsp.float_to_int16_interleave(out_samples, output, 256, s->out_channels);
01331 out_samples += 256 * s->out_channels;
01332 }
01333 *data_size = s->num_blocks * 256 * avctx->channels * sizeof (int16_t);
01334 return s->frame_size;
01335 }
01336
01340 static av_cold int ac3_decode_end(AVCodecContext *avctx)
01341 {
01342 AC3DecodeContext *s = avctx->priv_data;
01343 ff_mdct_end(&s->imdct_512);
01344 ff_mdct_end(&s->imdct_256);
01345
01346 av_freep(&s->input_buffer);
01347
01348 return 0;
01349 }
01350
01351 AVCodec ac3_decoder = {
01352 .name = "ac3",
01353 .type = CODEC_TYPE_AUDIO,
01354 .id = CODEC_ID_AC3,
01355 .priv_data_size = sizeof (AC3DecodeContext),
01356 .init = ac3_decode_init,
01357 .close = ac3_decode_end,
01358 .decode = ac3_decode_frame,
01359 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
01360 };
01361
01362 AVCodec eac3_decoder = {
01363 .name = "eac3",
01364 .type = CODEC_TYPE_AUDIO,
01365 .id = CODEC_ID_EAC3,
01366 .priv_data_size = sizeof (AC3DecodeContext),
01367 .init = ac3_decode_init,
01368 .close = ac3_decode_end,
01369 .decode = ac3_decode_frame,
01370 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"),
01371 };