FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
eac3dec.c
Go to the documentation of this file.
1 /*
2  * E-AC-3 decoder
3  * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
4  * Copyright (c) 2008 Justin Ruggles
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /*
24  * There are several features of E-AC-3 that this decoder does not yet support.
25  *
26  * Enhanced Coupling
27  * No known samples exist. If any ever surface, this feature should not be
28  * too difficult to implement.
29  *
30  * Reduced Sample Rates
31  * No known samples exist. The spec also does not give clear information
32  * on how this is to be implemented.
33  *
34  * Dependent Streams
35  * Only the independent stream is currently decoded. Any dependent
36  * streams are skipped. We have only come across two examples of this, and
37  * they are both just test streams, one for HD-DVD and the other for
38  * Blu-ray.
39  *
40  * Transient Pre-noise Processing
41  * This is side information which a decoder should use to reduce artifacts
42  * caused by transients. There are samples which are known to have this
43  * information, but this decoder currently ignores it.
44  */
45 
46 
47 #include "avcodec.h"
48 #include "internal.h"
49 #include "aac_ac3_parser.h"
50 #include "ac3.h"
51 #include "ac3dec.h"
52 #include "ac3dec_data.h"
53 #include "eac3_data.h"
54 
55 /** gain adaptive quantization mode */
56 typedef enum {
61 } EAC3GaqMode;
62 
63 #define EAC3_SR_CODE_REDUCED 3
64 
66 {
67  int bin, bnd, ch, i;
68  uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
69  float rms_energy[SPX_MAX_BANDS];
70 
71  /* Set copy index mapping table. Set wrap flags to apply a notch filter at
72  wrap points later on. */
73  bin = s->spx_dst_start_freq;
74  num_copy_sections = 0;
75  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
76  int copysize;
77  int bandsize = s->spx_band_sizes[bnd];
78  if (bin + bandsize > s->spx_src_start_freq) {
79  copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
80  bin = s->spx_dst_start_freq;
81  wrapflag[bnd] = 1;
82  }
83  for (i = 0; i < bandsize; i += copysize) {
84  if (bin == s->spx_src_start_freq) {
85  copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
86  bin = s->spx_dst_start_freq;
87  }
88  copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
89  bin += copysize;
90  }
91  }
92  copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
93 
94  for (ch = 1; ch <= s->fbw_channels; ch++) {
95  if (!s->channel_uses_spx[ch])
96  continue;
97 
98  /* Copy coeffs from normal bands to extension bands */
99  bin = s->spx_src_start_freq;
100  for (i = 0; i < num_copy_sections; i++) {
101  memcpy(&s->transform_coeffs[ch][bin],
103  copy_sizes[i]*sizeof(INTFLOAT));
104  bin += copy_sizes[i];
105  }
106 
107  /* Calculate RMS energy for each SPX band. */
108  bin = s->spx_src_start_freq;
109  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
110  int bandsize = s->spx_band_sizes[bnd];
111  float accum = 0.0f;
112  for (i = 0; i < bandsize; i++) {
113  float coeff = s->transform_coeffs[ch][bin++];
114  accum += coeff * coeff;
115  }
116  rms_energy[bnd] = sqrtf(accum / bandsize);
117  }
118 
119  /* Apply a notch filter at transitions between normal and extension
120  bands and at all wrap points. */
121  if (s->spx_atten_code[ch] >= 0) {
122  const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
123  bin = s->spx_src_start_freq - 2;
124  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
125  if (wrapflag[bnd]) {
126  INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
127  coeffs[0] *= atten_tab[0];
128  coeffs[1] *= atten_tab[1];
129  coeffs[2] *= atten_tab[2];
130  coeffs[3] *= atten_tab[1];
131  coeffs[4] *= atten_tab[0];
132  }
133  bin += s->spx_band_sizes[bnd];
134  }
135  }
136 
137  /* Apply noise-blended coefficient scaling based on previously
138  calculated RMS energy, blending factors, and SPX coordinates for
139  each band. */
140  bin = s->spx_src_start_freq;
141  for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
142  float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
143  float sscale = s->spx_signal_blend[ch][bnd];
144 #if USE_FIXED
145  // spx_noise_blend and spx_signal_blend are both FP.23
146  nscale *= 1.0 / (1<<23);
147  sscale *= 1.0 / (1<<23);
148 #endif
149  for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
150  float noise = nscale * (int32_t)av_lfg_get(&s->dith_state);
151  s->transform_coeffs[ch][bin] *= sscale;
152  s->transform_coeffs[ch][bin++] += noise;
153  }
154  }
155  }
156 }
157 
158 
159 /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
160 #define COEFF_0 10273905LL
161 
162 /** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
163 #define COEFF_1 11863283LL
164 
165 /** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
166 #define COEFF_2 3070444LL
167 
168 /**
169  * Calculate 6-point IDCT of the pre-mantissas.
170  * All calculations are 24-bit fixed-point.
171  */
172 static void idct6(int pre_mant[6])
173 {
174  int tmp;
175  int even0, even1, even2, odd0, odd1, odd2;
176 
177  odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
178 
179  even2 = ( pre_mant[2] * COEFF_0) >> 23;
180  tmp = ( pre_mant[4] * COEFF_1) >> 23;
181  odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
182 
183  even0 = pre_mant[0] + (tmp >> 1);
184  even1 = pre_mant[0] - tmp;
185 
186  tmp = even0;
187  even0 = tmp + even2;
188  even2 = tmp - even2;
189 
190  tmp = odd0;
191  odd0 = tmp + pre_mant[1] + pre_mant[3];
192  odd2 = tmp + pre_mant[5] - pre_mant[3];
193 
194  pre_mant[0] = even0 + odd0;
195  pre_mant[1] = even1 + odd1;
196  pre_mant[2] = even2 + odd2;
197  pre_mant[3] = even2 - odd2;
198  pre_mant[4] = even1 - odd1;
199  pre_mant[5] = even0 - odd0;
200 }
201 
203 {
204  int bin, blk, gs;
205  int end_bap, gaq_mode;
206  GetBitContext *gbc = &s->gbc;
207  int gaq_gain[AC3_MAX_COEFS];
208 
209  gaq_mode = get_bits(gbc, 2);
210  end_bap = (gaq_mode < 2) ? 12 : 17;
211 
212  /* if GAQ gain is used, decode gain codes for bins with hebap between
213  8 and end_bap */
214  gs = 0;
215  if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
216  /* read 1-bit GAQ gain codes */
217  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218  if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
219  gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
220  }
221  } else if (gaq_mode == EAC3_GAQ_124) {
222  /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
223  int gc = 2;
224  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
225  if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
226  if (gc++ == 2) {
227  int group_code = get_bits(gbc, 5);
228  if (group_code > 26) {
229  av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
230  group_code = 26;
231  }
232  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
233  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
234  gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
235  gc = 0;
236  }
237  }
238  }
239  }
240 
241  gs=0;
242  for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
243  int hebap = s->bap[ch][bin];
244  int bits = ff_eac3_bits_vs_hebap[hebap];
245  if (!hebap) {
246  /* zero-mantissa dithering */
247  for (blk = 0; blk < 6; blk++) {
248  s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
249  }
250  } else if (hebap < 8) {
251  /* Vector Quantization */
252  int v = get_bits(gbc, bits);
253  for (blk = 0; blk < 6; blk++) {
254  s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
255  }
256  } else {
257  /* Gain Adaptive Quantization */
258  int gbits, log_gain;
259  if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
260  log_gain = gaq_gain[gs++];
261  } else {
262  log_gain = 0;
263  }
264  gbits = bits - log_gain;
265 
266  for (blk = 0; blk < 6; blk++) {
267  int mant = get_sbits(gbc, gbits);
268  if (log_gain && mant == -(1 << (gbits-1))) {
269  /* large mantissa */
270  int b;
271  int mbits = bits - (2 - log_gain);
272  mant = get_sbits(gbc, mbits);
273  mant = ((unsigned)mant) << (23 - (mbits - 1));
274  /* remap mantissa value to correct for asymmetric quantization */
275  if (mant >= 0)
276  b = 1 << (23 - log_gain);
277  else
278  b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
279  mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
280  } else {
281  /* small mantissa, no GAQ, or Gk=1 */
282  mant *= (1 << 24 - bits);
283  if (!log_gain) {
284  /* remap mantissa value for no GAQ or Gk=1 */
285  mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
286  }
287  }
288  s->pre_mantissa[ch][bin][blk] = mant;
289  }
290  }
291  idct6(s->pre_mantissa[ch][bin]);
292  }
293 }
294 
296 {
297  int i, blk, ch;
298  int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
299  int parse_transient_proc_info;
300  int num_cpl_blocks;
301  GetBitContext *gbc = &s->gbc;
302 
303  /* An E-AC-3 stream can have multiple independent streams which the
304  application can select from. each independent stream can also contain
305  dependent streams which are used to add or replace channels. */
307  av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
309  }
310 
311  /* The substream id indicates which substream this frame belongs to. each
312  independent stream has its own substream id, and the dependent streams
313  associated to an independent stream have matching substream id's. */
314  if (s->substreamid) {
315  /* only decode substream with id=0. skip any additional substreams. */
316  if (!s->eac3_subsbtreamid_found) {
318  avpriv_request_sample(s->avctx, "Additional substreams");
319  }
321  }
322 
324  /* The E-AC-3 specification does not tell how to handle reduced sample
325  rates in bit allocation. The best assumption would be that it is
326  handled like AC-3 DolbyNet, but we cannot be sure until we have a
327  sample which utilizes this feature. */
328  avpriv_request_sample(s->avctx, "Reduced sampling rate");
329  return AVERROR_PATCHWELCOME;
330  }
331  skip_bits(gbc, 5); // skip bitstream id
332 
333  /* volume control params */
334  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
335  s->dialog_normalization[i] = -get_bits(gbc, 5);
336  if (s->dialog_normalization[i] == 0) {
337  s->dialog_normalization[i] = -31;
338  }
339  if (s->target_level != 0) {
340  s->level_gain[i] = powf(2.0f,
341  (float)(s->target_level - s->dialog_normalization[i])/6.0f);
342  }
343  s->compression_exists[i] = get_bits1(gbc);
344  if (s->compression_exists[i]) {
346  }
347  }
348 
349  /* dependent stream channel map */
351  if (get_bits1(gbc)) {
352  s->channel_map = get_bits(gbc, 16);
353  av_log(s->avctx, AV_LOG_DEBUG, "channel_map: %0X\n", s->channel_map);
354  }
355  }
356 
357  /* mixing metadata */
358  if (get_bits1(gbc)) {
359  /* center and surround mix levels */
360  if (s->channel_mode > AC3_CHMODE_STEREO) {
361  s->preferred_downmix = get_bits(gbc, 2);
362  if (s->channel_mode & 1) {
363  /* if three front channels exist */
364  s->center_mix_level_ltrt = get_bits(gbc, 3);
365  s->center_mix_level = get_bits(gbc, 3);
366  }
367  if (s->channel_mode & 4) {
368  /* if a surround channel exists */
369  s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
370  s->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
371  }
372  }
373 
374  /* lfe mix level */
375  if (s->lfe_on && (s->lfe_mix_level_exists = get_bits1(gbc))) {
376  s->lfe_mix_level = get_bits(gbc, 5);
377  }
378 
379  /* info for mixing with other streams and substreams */
381  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
382  // TODO: apply program scale factor
383  if (get_bits1(gbc)) {
384  skip_bits(gbc, 6); // skip program scale factor
385  }
386  }
387  if (get_bits1(gbc)) {
388  skip_bits(gbc, 6); // skip external program scale factor
389  }
390  /* skip mixing parameter data */
391  switch(get_bits(gbc, 2)) {
392  case 1: skip_bits(gbc, 5); break;
393  case 2: skip_bits(gbc, 12); break;
394  case 3: {
395  int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
396  skip_bits_long(gbc, mix_data_size);
397  break;
398  }
399  }
400  /* skip pan information for mono or dual mono source */
401  if (s->channel_mode < AC3_CHMODE_STEREO) {
402  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
403  if (get_bits1(gbc)) {
404  /* note: this is not in the ATSC A/52B specification
405  reference: ETSI TS 102 366 V1.1.1
406  section: E.1.3.1.25 */
407  skip_bits(gbc, 8); // skip pan mean direction index
408  skip_bits(gbc, 6); // skip reserved paninfo bits
409  }
410  }
411  }
412  /* skip mixing configuration information */
413  if (get_bits1(gbc)) {
414  for (blk = 0; blk < s->num_blocks; blk++) {
415  if (s->num_blocks == 1 || get_bits1(gbc)) {
416  skip_bits(gbc, 5);
417  }
418  }
419  }
420  }
421  }
422 
423  /* informational metadata */
424  if (get_bits1(gbc)) {
425  s->bitstream_mode = get_bits(gbc, 3);
426  skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
427  if (s->channel_mode == AC3_CHMODE_STEREO) {
428  s->dolby_surround_mode = get_bits(gbc, 2);
429  s->dolby_headphone_mode = get_bits(gbc, 2);
430  }
431  if (s->channel_mode >= AC3_CHMODE_2F2R) {
432  s->dolby_surround_ex_mode = get_bits(gbc, 2);
433  }
434  for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
435  if (get_bits1(gbc)) {
436  skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
437  }
438  }
440  skip_bits1(gbc); // skip source sample rate code
441  }
442  }
443 
444  /* converter synchronization flag
445  If frames are less than six blocks, this bit should be turned on
446  once every 6 blocks to indicate the start of a frame set.
447  reference: RFC 4598, Section 2.1.3 Frame Sets */
448  if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
449  skip_bits1(gbc); // skip converter synchronization flag
450  }
451 
452  /* original frame size code if this stream was converted from AC-3 */
454  (s->num_blocks == 6 || get_bits1(gbc))) {
455  skip_bits(gbc, 6); // skip frame size code
456  }
457 
458  /* additional bitstream info */
459  if (get_bits1(gbc)) {
460  int addbsil = get_bits(gbc, 6);
461  for (i = 0; i < addbsil + 1; i++) {
462  skip_bits(gbc, 8); // skip additional bit stream info
463  }
464  }
465 
466  /* audio frame syntax flags, strategy data, and per-frame data */
467 
468  if (s->num_blocks == 6) {
469  ac3_exponent_strategy = get_bits1(gbc);
470  parse_aht_info = get_bits1(gbc);
471  } else {
472  /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
473  do not use AHT */
474  ac3_exponent_strategy = 1;
475  parse_aht_info = 0;
476  }
477 
478  s->snr_offset_strategy = get_bits(gbc, 2);
479  parse_transient_proc_info = get_bits1(gbc);
480 
481  s->block_switch_syntax = get_bits1(gbc);
482  if (!s->block_switch_syntax)
483  memset(s->block_switch, 0, sizeof(s->block_switch));
484 
485  s->dither_flag_syntax = get_bits1(gbc);
486  if (!s->dither_flag_syntax) {
487  for (ch = 1; ch <= s->fbw_channels; ch++)
488  s->dither_flag[ch] = 1;
489  }
490  s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
491 
493  if (!s->bit_allocation_syntax) {
494  /* set default bit allocation parameters */
500  }
501 
502  s->fast_gain_syntax = get_bits1(gbc);
503  s->dba_syntax = get_bits1(gbc);
504  s->skip_syntax = get_bits1(gbc);
505  parse_spx_atten_data = get_bits1(gbc);
506 
507  /* coupling strategy occurrence and coupling use per block */
508  num_cpl_blocks = 0;
509  if (s->channel_mode > 1) {
510  for (blk = 0; blk < s->num_blocks; blk++) {
511  s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
512  if (s->cpl_strategy_exists[blk]) {
513  s->cpl_in_use[blk] = get_bits1(gbc);
514  } else {
515  s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
516  }
517  num_cpl_blocks += s->cpl_in_use[blk];
518  }
519  } else {
520  memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
521  }
522 
523  /* exponent strategy data */
524  if (ac3_exponent_strategy) {
525  /* AC-3-style exponent strategy syntax */
526  for (blk = 0; blk < s->num_blocks; blk++) {
527  for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
528  s->exp_strategy[blk][ch] = get_bits(gbc, 2);
529  }
530  }
531  } else {
532  /* LUT-based exponent strategy syntax */
533  for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
534  int frmchexpstr = get_bits(gbc, 5);
535  for (blk = 0; blk < 6; blk++) {
536  s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
537  }
538  }
539  }
540  /* LFE exponent strategy */
541  if (s->lfe_on) {
542  for (blk = 0; blk < s->num_blocks; blk++) {
543  s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
544  }
545  }
546  /* original exponent strategies if this stream was converted from AC-3 */
548  (s->num_blocks == 6 || get_bits1(gbc))) {
549  skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
550  }
551 
552  /* determine which channels use AHT */
553  if (parse_aht_info) {
554  /* For AHT to be used, all non-zero blocks must reuse exponents from
555  the first block. Furthermore, for AHT to be used in the coupling
556  channel, all blocks must use coupling and use the same coupling
557  strategy. */
558  s->channel_uses_aht[CPL_CH]=0;
559  for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
560  int use_aht = 1;
561  for (blk = 1; blk < 6; blk++) {
562  if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
563  (!ch && s->cpl_strategy_exists[blk])) {
564  use_aht = 0;
565  break;
566  }
567  }
568  s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
569  }
570  } else {
571  memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
572  }
573 
574  /* per-frame SNR offset */
575  if (!s->snr_offset_strategy) {
576  int csnroffst = (get_bits(gbc, 6) - 15) << 4;
577  int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
578  for (ch = 0; ch <= s->channels; ch++)
579  s->snr_offset[ch] = snroffst;
580  }
581 
582  /* transient pre-noise processing data */
583  if (parse_transient_proc_info) {
584  for (ch = 1; ch <= s->fbw_channels; ch++) {
585  if (get_bits1(gbc)) { // channel in transient processing
586  skip_bits(gbc, 10); // skip transient processing location
587  skip_bits(gbc, 8); // skip transient processing length
588  }
589  }
590  }
591 
592  /* spectral extension attenuation data */
593  for (ch = 1; ch <= s->fbw_channels; ch++) {
594  if (parse_spx_atten_data && get_bits1(gbc)) {
595  s->spx_atten_code[ch] = get_bits(gbc, 5);
596  } else {
597  s->spx_atten_code[ch] = -1;
598  }
599  }
600 
601  /* block start information */
602  if (s->num_blocks > 1 && get_bits1(gbc)) {
603  /* reference: Section E2.3.2.27
604  nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
605  The spec does not say what this data is or what it's used for.
606  It is likely the offset of each block within the frame. */
607  int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
608  skip_bits_long(gbc, block_start_bits);
609  avpriv_request_sample(s->avctx, "Block start info");
610  }
611 
612  /* syntax state initialization */
613  for (ch = 1; ch <= s->fbw_channels; ch++) {
614  s->first_spx_coords[ch] = 1;
615  s->first_cpl_coords[ch] = 1;
616  }
617  s->first_cpl_leak = 1;
618 
619  return 0;
620 }
EAC3GaqMode
gain adaptive quantization mode
Definition: eac3dec.c:56
const uint8_t ff_ac3_slow_decay_tab[4]
Definition: ac3tab.c:280
int dither_flag[AC3_MAX_CHANNELS]
dither flags (dithflg)
Definition: ac3dec.h:217
const float ff_eac3_spx_atten_tab[32][3]
Table E.25: Spectral Extension Attenuation Table ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0);.
Definition: eac3_data.c:1101
int preferred_downmix
Preferred 2-channel downmix mode (dmixmod)
Definition: ac3dec.h:92
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:269
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]
Table used to ungroup 3 values stored in 5 bits.
Definition: ac3dec_data.c:35
static int ff_eac3_parse_header(AC3DecodeContext *s)
Definition: eac3dec.c:295
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:212
#define AC3_MAX_COEFS
Definition: ac3.h:35
const char * b
Definition: vf_curves.c:113
int channels
number of total channels
Definition: ac3dec.h:163
int av_log2(unsigned v)
Definition: intmath.c:26
#define EXP_REUSE
Definition: ac3.h:48
int exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]
exponent strategies (expstr)
Definition: ac3dec.h:197
int lfe_on
lfe channel in use
Definition: ac3dec.h:87
const uint16_t ff_ac3_slow_gain_tab[4]
Definition: ac3tab.c:288
int block_switch[AC3_MAX_CHANNELS]
block switch flags (blksw)
Definition: ac3dec.h:222
#define blk(i)
Definition: sha.c:185
int dba_syntax
delta bit allocation syntax enabled (dbaflde)
Definition: ac3dec.h:121
int dialog_normalization[2]
dialog level in dBFS (dialnorm)
Definition: ac3dec.h:88
int spx_src_start_freq
spx start frequency bin
Definition: ac3dec.h:144
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:254
int lfe_mix_level_exists
indicates if lfemixlevcod is specified (lfemixlevcode)
Definition: ac3dec.h:97
float INTFLOAT
Definition: aac_defines.h:86
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define COEFF_0
lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23))
Definition: eac3dec.c:160
uint8_t
int first_cpl_coords[AC3_MAX_CHANNELS]
first coupling coordinates states (firstcplcos)
Definition: ac3dec.h:135
#define f(width, name)
Definition: cbs_vp9.c:255
INTFLOAT spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]
spx noise blending factor (nblendfact)
Definition: ac3dec.h:152
int bit_allocation_syntax
bit allocation model syntax enabled (bamode)
Definition: ac3dec.h:119
#define av_log(a,...)
Common code between the AC-3 and E-AC-3 decoders.
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
Definition: eac3dec.c:202
int channel_map
custom channel map (chanmap)
Definition: ac3dec.h:91
int substreamid
substream identification
Definition: ac3dec.h:78
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
const uint8_t ff_ac3_fast_decay_tab[4]
Definition: ac3tab.c:284
int lfe_ch
index of LFE channel
Definition: ac3dec.h:164
uint8_t first_spx_coords[AC3_MAX_CHANNELS]
first spx coordinates states (firstspxcos)
Definition: ac3dec.h:151
AC3BitAllocParameters bit_alloc_params
bit allocation parameters
Definition: ac3dec.h:201
int dolby_surround_mode
dolby surround mode (dsurmod)
Definition: ac3dec.h:102
GetBitContext gbc
bitstream reader
Definition: ac3dec.h:73
int eac3_subsbtreamid_found
bitstream has E-AC-3 additional substream(s)
Definition: ac3dec.h:101
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
int dolby_headphone_mode
dolby headphone mode (dheadphonmod)
Definition: ac3dec.h:104
#define COEFF_2
lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23))
Definition: eac3dec.c:166
int compression_exists[2]
compression field is valid for frame (compre)
Definition: ac3dec.h:89
INTFLOAT transform_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]
transform coefficients
Definition: ac3dec.h:244
#define EAC3_SR_CODE_REDUCED
Definition: eac3dec.c:63
int block_switch_syntax
block switch syntax enabled (blkswe)
Definition: ac3dec.h:117
float level_gain[2]
Definition: ac3dec.h:113
int fast_gain_syntax
fast gain codes enabled (frmfgaincode)
Definition: ac3dec.h:120
uint8_t channel_uses_spx[AC3_MAX_CHANNELS]
channel uses spectral extension (chinspx)
Definition: ac3dec.h:142
#define powf(x, y)
Definition: libm.h:50
static void idct6(int pre_mant[6])
Calculate 6-point IDCT of the pre-mantissas.
Definition: eac3dec.c:172
#define AC3_HEAVY_RANGE(x)
Definition: ac3.h:91
int surround_mix_level_ltrt
Surround mix level index for Lt/Rt (ltrtsurmixlev)
Definition: ac3dec.h:96
#define FFMIN(a, b)
Definition: common.h:96
int dither_flag_syntax
dither flag syntax enabled (dithflage)
Definition: ac3dec.h:118
INTFLOAT heavy_dynamic_range[2]
heavy dynamic range compression
Definition: ac3dec.h:177
int32_t
const int16_t ff_eac3_gaq_remap_1[12]
Table E3.6, Gk=1 No gain (Gk=1) inverse quantization, remapping scale factors ff_eac3_gaq_remap[hebap...
Definition: eac3_data.c:40
#define s(width, name)
Definition: cbs_vp9.c:257
const int16_t ff_eac3_gaq_remap_2_4_a[9][2]
Table E3.6, Gk=2 & Gk=4, A Large mantissa inverse quantization, remapping scale factors ff_eac3_gaq_r...
Definition: eac3_data.c:49
#define COEFF_1
lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23))
Definition: eac3dec.c:163
AVCodecContext * avctx
parent context
Definition: ac3dec.h:72
const uint8_t ff_eac3_bits_vs_hebap[20]
Definition: eac3_data.c:30
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int fbw_channels
number of full-bandwidth channels
Definition: ac3dec.h:162
int8_t spx_atten_code[AC3_MAX_CHANNELS]
spx attenuation code (spxattencod)
Definition: ac3dec.h:143
uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]
bit allocation pointers
Definition: ac3dec.h:205
#define CPL_CH
coupling channel index
Definition: ac3.h:33
Libavcodec external API header.
const int16_t ff_eac3_gaq_remap_2_4_b[9][2]
Table E3.6, Gk=2 & Gk=4, B Large mantissa inverse quantization, negative mantissa remapping offsets f...
Definition: eac3_data.c:66
static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
Definition: eac3dec.c:65
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:47
int num_spx_bands
number of spx bands (nspxbnds)
Definition: ac3dec.h:148
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:321
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:346
INTFLOAT spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]
spx signal blending factor (sblendfact)
Definition: ac3dec.h:153
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:314
int bitstream_mode
bitstream mode (bsmod)
Definition: ac3dec.h:85
int center_mix_level_ltrt
Center mix level index for Lt/Rt (ltrtcmixlev)
Definition: ac3dec.h:94
int frame_type
frame type (strmtyp)
Definition: ac3dec.h:77
int channel_uses_aht[AC3_MAX_CHANNELS]
channel AHT in use (chahtinu)
Definition: ac3dec.h:157
const int16_t ff_ac3_floor_tab[8]
Definition: ac3tab.c:296
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise_bsf.c:38
int cpl_in_use[AC3_MAX_BLOCKS]
coupling in use (cplinu)
Definition: ac3dec.h:126
int first_cpl_leak
first coupling leak state (firstcplleak)
Definition: ac3dec.h:202
int surround_mix_level
Surround mix level index.
Definition: ac3dec.h:95
int snr_offset[AC3_MAX_CHANNELS]
signal-to-noise ratio offsets (snroffst)
Definition: ac3dec.h:203
common internal api header.
const uint8_t ff_eac3_frm_expstr[32][6]
Table E2.14 Frame Exponent Strategy Combinations.
Definition: eac3_data.c:1062
int num_blocks
number of audio blocks
Definition: ac3dec.h:83
#define SPX_MAX_BANDS
Definition: ac3dec.h:65
int target_level
target level in dBFS
Definition: ac3dec.h:112
int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][AC3_MAX_BLOCKS]
pre-IDCT mantissas
Definition: ac3dec.h:158
uint8_t spx_band_sizes[SPX_MAX_BANDS]
number of bins in each spx band
Definition: ac3dec.h:150
int lfe_mix_level
LFE mix level index (lfemixlevcod)
Definition: ac3dec.h:98
int snr_offset_strategy
SNR offset strategy (snroffststr)
Definition: ac3dec.h:116
static const int16_t coeffs[]
int start_freq[AC3_MAX_CHANNELS]
start frequency bin (strtmant)
Definition: ac3dec.h:181
int center_mix_level
Center mix level index.
Definition: ac3dec.h:93
static const double coeff[2][5]
Definition: vf_owdenoise.c:72
int frame_size
current frame size, in bytes
Definition: ac3dec.h:80
const int16_t(*const [8] ff_eac3_mantissa_vq)[6]
Definition: eac3_data.c:1048
int dolby_surround_ex_mode
dolby surround ex mode (dsurexmod)
Definition: ac3dec.h:103
AVLFG dith_state
for dither generation
Definition: ac3dec.h:218
int cpl_strategy_exists[AC3_MAX_BLOCKS]
coupling strategy exists (cplstre)
Definition: ac3dec.h:127
const uint16_t ff_ac3_db_per_bit_tab[4]
Definition: ac3tab.c:292
Common code between the AC-3 encoder and decoder.
int channel_mode
channel mode (acmod)
Definition: ac3dec.h:86
int spx_dst_start_freq
spx starting frequency bin for copying (copystartmant) the copy region ends at the start of the spx r...
Definition: ac3dec.h:146
int skip_syntax
skip field syntax enabled (skipflde)
Definition: ac3dec.h:122
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
static uint8_t tmp[11]
Definition: aes_ctr.c:26