FFmpeg
aacdec_usac.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 Lynne <dev@lynne.ee>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "aacdec_usac.h"
22 #include "aacdec_tab.h"
23 #include "aacdec_lpd.h"
24 #include "aacdec_ac.h"
25 
26 #include "libavcodec/aacsbr.h"
27 #include "libavcodec/aactab.h"
28 #include "libavcodec/mpeg4audio.h"
29 #include "libavcodec/unary.h"
30 
31 #include "libavutil/mem.h"
32 #include "libavutil/refstruct.h"
33 
34 #include "aacdec_usac_mps212.h"
35 
36 /* Number of scalefactor bands per complex prediction band, equal to 2. */
37 #define SFB_PER_PRED_BAND 2
38 
39 static inline uint32_t get_escaped_value(GetBitContext *gb, int nb1, int nb2, int nb3)
40 {
41  uint32_t val = get_bits(gb, nb1), val2;
42  if (val < ((1 << nb1) - 1))
43  return val;
44 
45  val += val2 = get_bits(gb, nb2);
46  if (nb3 && (val2 == ((1 << nb2) - 1)))
47  val += get_bits(gb, nb3);
48 
49  return val;
50 }
51 
52 /* ISO/IEC 23003-3, Table 74: bsOutputChannelPos */
53 static const enum AVChannel usac_ch_pos_to_av[64] = {
54  [0] = AV_CHAN_FRONT_LEFT,
55  [1] = AV_CHAN_FRONT_RIGHT,
58  [4] = AV_CHAN_SIDE_LEFT, // +110 degrees, Ls|LS|kAudioChannelLabel_LeftSurround
59  [5] = AV_CHAN_SIDE_RIGHT, // -110 degrees, Rs|RS|kAudioChannelLabel_RightSurround
62  [8] = AV_CHAN_BACK_LEFT, // +135 degrees, Lsr|BL|kAudioChannelLabel_RearSurroundLeft
63  [9] = AV_CHAN_BACK_RIGHT, // -135 degrees, Rsr|BR|kAudioChannelLabel_RearSurroundRight
64  [10] = AV_CHAN_BACK_CENTER,
67  [13] = AV_CHAN_SIDE_SURROUND_LEFT, // +90 degrees, Lss|SL|kAudioChannelLabel_LeftSideSurround
68  [14] = AV_CHAN_SIDE_SURROUND_RIGHT, // -90 degrees, Rss|SR|kAudioChannelLabel_RightSideSurround
69  [15] = AV_CHAN_WIDE_LEFT, // +60 degrees, Lw|FLw|kAudioChannelLabel_LeftWide
70  [16] = AV_CHAN_WIDE_RIGHT, // -60 degrees, Rw|FRw|kAudioChannelLabel_RightWide
74  [20] = AV_CHAN_TOP_BACK_LEFT,
77  [23] = AV_CHAN_TOP_SIDE_LEFT,
79  [25] = AV_CHAN_TOP_CENTER,
84  [30] = AV_CHAN_TOP_SURROUND_LEFT, ///< +110 degrees, Lvs, TpLS
85  [31] = AV_CHAN_TOP_SURROUND_RIGHT, ///< -110 degrees, Rvs, TpRS
86 };
87 
88 /* ISO/IEC 23003-4, Table A.48: bit width of bsMethodValue depends on methodDef. */
89 static int methodvalue_width(int method_def)
90 {
91  switch (method_def) {
92  case 7: return 5; /* mixing level */
93  case 8: return 2; /* room type */
94  default: return 8; /* loudness (0..6, 9) + reserved */
95  }
96 }
97 
98 /* ISO/IEC 23003-4, Table 58/60: loudnessInfo(), loudnessInfoV1().
99  * The only difference in V1 is the added eqSetId field. */
101  GetBitContext *gb, int v1)
102 {
103  info->drc_set_id = get_bits(gb, 6);
104  info->eq_set_id = v1 ? get_bits(gb, 6) : 0;
105  info->downmix_id = get_bits(gb, 7);
106 
107  if ((info->sample_peak.present = get_bits1(gb))) /* samplePeakLevelPresent */
108  info->sample_peak.lvl = get_bits(gb, 12);
109 
110  if ((info->true_peak.present = get_bits1(gb))) { /* truePeakLevelPresent */
111  info->true_peak.lvl = get_bits(gb, 12);
112  info->true_peak.measurement = get_bits(gb, 4);
113  info->true_peak.reliability = get_bits(gb, 2);
114  }
115 
116  info->nb_measurements = get_bits(gb, 4);
117  for (int i = 0; i < info->nb_measurements; i++) {
118  info->measurements[i].method_def = get_bits(gb, 4);
119  info->measurements[i].method_val =
120  get_bits(gb, methodvalue_width(info->measurements[i].method_def));
121  info->measurements[i].measurement = get_bits(gb, 4);
122  info->measurements[i].reliability = get_bits(gb, 2);
123  }
124 
125  return 0;
126 }
127 
128 /* ISO/IEC 23003-4, Table 61: loudnessInfoSetExtension(), UNIDRCLOUDEXT_EQ */
130  GetBitContext *gb)
131 {
132  int ret;
133  int nb_album = get_bits(gb, 6); /* loudnessInfoV1AlbumCount */
134  int nb_info = get_bits(gb, 6); /* loudnessInfoV1Count */
135 
136  for (int i = 0; i < nb_album; i++) {
138  ret = decode_loudness_info(ac, &tmp, gb, 1);
139  if (ret < 0)
140  return ret;
142  usac->loudness.album_info[usac->loudness.nb_album++] = tmp;
143  }
144 
145  for (int i = 0; i < nb_info; i++) {
147  ret = decode_loudness_info(ac, &tmp, gb, 1);
148  if (ret < 0)
149  return ret;
150  if (usac->loudness.nb_info < FF_ARRAY_ELEMS(usac->loudness.info))
151  usac->loudness.info[usac->loudness.nb_info++] = tmp;
152  }
153 
154  return 0;
155 }
156 
157 /* Pick the bsMethodValue of a program- or anchor-loudness measurement.
158  * Per ISO/IEC 23003-4 6.1.2.5, downmixId, drcSetId and eqSetId identify the
159  * signal a loudnessInfo() applies to; only downmixId == 0 (base layout)
160  * together with drcSetId == 0 and eqSetId == 0 (no DRC/EQ) describes the
161  * unprocessed signal we output, so measurements for any other
162  * downmix/DRC/EQ set must not be used. */
164 {
165  for (int i = 0; i < usac->loudness.nb_info; i++) {
166  const AACUSACLoudnessInfo *info = &usac->loudness.info[i];
167  if (info->downmix_id != 0 || info->drc_set_id != 0 || info->eq_set_id != 0)
168  continue;
169  for (int j = 0; j < info->nb_measurements; j++) {
170  int method = info->measurements[j].method_def;
171  if (method == 1 || method == 2)
172  return info->measurements[j].method_val;
173  }
174  }
175  return -1;
176 }
177 
179  GetBitContext *gb)
180 {
181  int ret;
182 
183  usac->loudness.nb_album = get_bits(gb, 6); /* loudnessInfoAlbumCount */
184  usac->loudness.nb_info = get_bits(gb, 6); /* loudnessInfoCount */
185 
186  for (int i = 0; i < usac->loudness.nb_album; i++) {
187  ret = decode_loudness_info(ac, &usac->loudness.album_info[i], gb, 0);
188  if (ret < 0)
189  return ret;
190  }
191 
192  for (int i = 0; i < usac->loudness.nb_info; i++) {
193  ret = decode_loudness_info(ac, &usac->loudness.info[i], gb, 0);
194  if (ret < 0)
195  return ret;
196  }
197 
198  if (get_bits1(gb)) { /* loudnessInfoSetExtPresent */
200  while ((type = get_bits(gb, 4)) != UNIDRCLOUDEXT_TERM) {
201  uint8_t size_bits = get_bits(gb, 4) + 4; /* bitSizeLen */
202  uint32_t bit_size = get_bits_long(gb, size_bits) + 1; /* bitSize */
203  int start = get_bits_count(gb);
204  int skip;
205  switch (type) {
206  case UNIDRCLOUDEXT_EQ:
207  ret = decode_loudness_set_v1(ac, usac, gb);
208  if (ret < 0)
209  return ret;
210  break;
211  default:
212  break;
213  }
214  /* The extension size is explicit, so unparsed (or unknown)
215  * data can be skipped without desynchronizing. */
216  skip = bit_size - (get_bits_count(gb) - start);
217  if (skip < 0)
218  return AVERROR_INVALIDDATA;
219  skip_bits_long(gb, skip);
220  }
221  }
222 
223  return 0;
224 }
225 
228 {
229  uint8_t header_extra1;
230  uint8_t header_extra2;
231 
232  e->sbr.harmonic_sbr = get_bits1(gb); /* harmonicSBR */
233  e->sbr.bs_intertes = get_bits1(gb); /* bs_interTes */
234  e->sbr.bs_pvc = get_bits1(gb); /* bs_pvc */
235  if (e->sbr.harmonic_sbr || e->sbr.bs_intertes || e->sbr.bs_pvc) {
236  avpriv_report_missing_feature(ac->avctx, "AAC USAC eSBR");
237  return AVERROR_PATCHWELCOME;
238  }
239 
240  e->sbr.dflt.start_freq = get_bits(gb, 4); /* dflt_start_freq */
241  e->sbr.dflt.stop_freq = get_bits(gb, 4); /* dflt_stop_freq */
242 
243  header_extra1 = get_bits1(gb); /* dflt_header_extra1 */
244  header_extra2 = get_bits1(gb); /* dflt_header_extra2 */
245 
246  e->sbr.dflt.freq_scale = 2;
247  e->sbr.dflt.alter_scale = 1;
248  e->sbr.dflt.noise_bands = 2;
249  if (header_extra1) {
250  e->sbr.dflt.freq_scale = get_bits(gb, 2); /* dflt_freq_scale */
251  e->sbr.dflt.alter_scale = get_bits1(gb); /* dflt_alter_scale */
252  e->sbr.dflt.noise_bands = get_bits(gb, 2); /* dflt_noise_bands */
253  }
254 
255  e->sbr.dflt.limiter_bands = 2;
256  e->sbr.dflt.limiter_gains = 2;
257  e->sbr.dflt.interpol_freq = 1;
258  e->sbr.dflt.smoothing_mode = 1;
259  if (header_extra2) {
260  e->sbr.dflt.limiter_bands = get_bits(gb, 2); /* dflt_limiter_bands */
261  e->sbr.dflt.limiter_gains = get_bits(gb, 2); /* dflt_limiter_gains */
262  e->sbr.dflt.interpol_freq = get_bits1(gb); /* dflt_interpol_freq */
263  e->sbr.dflt.smoothing_mode = get_bits1(gb); /* dflt_smoothing_mode */
264  }
265 
266  return 0;
267 }
268 
270  GetBitContext *gb,
271  int sbr_ratio)
272 {
273  e->tw_mdct = get_bits1(gb); /* tw_mdct */
274  e->noise_fill = get_bits1(gb);
275  e->sbr.ratio = sbr_ratio;
276 }
277 
280 {
281  e->stereo_config_index = 0;
282  if (e->sbr.ratio) {
283  int ret = decode_usac_sbr_data(ac, e, gb);
284  if (ret < 0)
285  return ret;
286  e->stereo_config_index = get_bits(gb, 2);
287  }
288 
289  if (e->stereo_config_index) {
290  e->mps.freq_res = get_bits(gb, 3); /* bsFreqRes */
291  if (!e->mps.freq_res)
292  return AVERROR_INVALIDDATA; /* value 0 is reserved */
293 
294  int numBands = ((int[]){0,28,20,14,10,7,5,4})[e->mps.freq_res]; // ISO/IEC 23003-1:2007, 5.2, Table 39
295 
296  e->mps.fixed_gain = get_bits(gb, 3); /* bsFixedGainDMX */
297  e->mps.temp_shape_config = get_bits(gb, 2); /* bsTempShapeConfig */
298  e->mps.decorr_config = get_bits(gb, 2); /* bsDecorrConfig */
299  e->mps.high_rate_mode = get_bits1(gb); /* bsHighRateMode */
300  e->mps.phase_coding = get_bits1(gb); /* bsPhaseCoding */
301 
303  int otts_bands_phase = ((int[]){0,10,10,7,5,3,2,2})[e->mps.freq_res]; // Table 109: Default value of bsOttBandsPhase
304  if (e->mps.otts_bands_phase_present) { /* bsOttBandsPhasePresent */
305  otts_bands_phase = get_bits(gb, 5); /* bsOttBandsPhase */
306  if (otts_bands_phase > numBands)
307  return AVERROR_INVALIDDATA;
308  }
309  e->mps.otts_bands_phase = otts_bands_phase;
310 
311  e->mps.residual_coding = e->stereo_config_index >= 2; /* bsResidualCoding */
312  if (e->mps.residual_coding) {
313  int residual_bands = get_bits(gb, 5); /* bsResidualBands */
314  if (residual_bands > numBands)
315  return AVERROR_INVALIDDATA;
316  e->mps.residual_bands = residual_bands;
317 
319  e->mps.residual_bands);
320  e->mps.pseudo_lr = get_bits1(gb); /* bsPseudoLr */
321  }
322  if (e->mps.temp_shape_config == 2)
323  e->mps.env_quant_mode = get_bits1(gb); /* bsEnvQuantMode */
324  }
325 
326  return 0;
327 }
328 
329 /* ISO/IEC 23003-4, Table 62: channelLayout() */
331 {
332  int base_channel_count = get_bits(gb, 7); /* baseChannelCount */
333  if (get_bits1(gb)) { /* layoutSignallingPresent */
334  if (get_bits(gb, 8) == 0) /* definedLayout == 0 */
335  for (int i = 0; i < base_channel_count; i++)
336  skip_bits(gb, 7); /* speakerPosition */
337  }
338  return base_channel_count;
339 }
340 
341 /* ISO/IEC 23003-4, Table 63: downmixInstructions() */
342 static void skip_drc_downmix_instructions(GetBitContext *gb, int base_channel_count)
343 {
344  int target_channel_count;
345  skip_bits(gb, 7); /* downmixId */
346  target_channel_count = get_bits(gb, 7); /* targetChannelCount */
347  skip_bits(gb, 8); /* targetLayout */
348  if (get_bits1(gb)) /* downmixCoefficientsPresent */
349  skip_bits_long(gb, 4 * target_channel_count * base_channel_count);
350 }
351 
352 /* ISO/IEC 23003-4, Table 70: drcInstructionsBasic(), common with the
353  * uniDrc variant up to the loudness-target fields. */
355 {
356  int set_effects;
357 
358  skip_bits(gb, 6); /* drcSetId */
359  skip_bits(gb, 4); /* drcLocation */
360  skip_bits(gb, 7); /* downmixId */
361  if (get_bits1(gb)) { /* additionalDownmixIdPresent */
362  int add_downmix_cnt = get_bits(gb, 3); /* additionalDownmixIdCount */
363  for (int j = 0; j < add_downmix_cnt; j++)
364  skip_bits(gb, 7); /* additionalDownmixId */
365  }
366 
367  set_effects = get_bits(gb, 16); /* drcSetEffect */
368  if ((set_effects & (3 << 10)) == 0) {
369  if (get_bits1(gb)) /* limiterPeakTargetPresent */
370  skip_bits(gb, 8); /* bsLimiterPeakTarget */
371  }
372 
373  if (get_bits1(gb)) { /* drcSetTargetLoudnessPresent */
374  e->drc.loudness.upper = get_bits(gb, 6); /* bsDrcSetTargetLoudnessValueUpper */
375  if (get_bits1(gb)) /* drcSetTargetLoudnessValueLowerPresent */
376  e->drc.loudness.lower = get_bits(gb, 6); /* bsDrcSetTargetLoudnessValueLower */
377  }
378 }
379 
380 /* ISO/IEC 23003-4, Table 57: uniDrcConfig() */
382  GetBitContext *gb)
383 {
384  int nb_downmix_instr, nb_coeff_basic = 0, nb_instr_basic = 0;
385  int nb_coeff_uni, nb_instr_uni;
386  int base_channel_count;
387 
388  e->drc.loudness.lower = -1;
389  e->drc.loudness.upper = -1;
390 
391  if (get_bits1(gb)) /* sampleRatePresent */
392  skip_bits(gb, 18); /* bsSampleRate */
393 
394  nb_downmix_instr = get_bits(gb, 7); /* downmixInstructionsCount */
395 
396  if (get_bits1(gb)) { /* drcDescriptionBasicPresent */
397  nb_coeff_basic = get_bits(gb, 3); /* drcCoefficientsBasicCount */
398  nb_instr_basic = get_bits(gb, 4); /* drcInstructionsBasicCount */
399  }
400 
401  nb_coeff_uni = get_bits(gb, 3); /* drcCoefficientsUniDrcCount */
402  nb_instr_uni = get_bits(gb, 6); /* drcInstructionsUniDrcCount */
403 
404  if (nb_coeff_uni || nb_instr_uni) {
406  "AAC USAC uniDrc DRC processing");
407  return AVERROR_PATCHWELCOME;
408  }
409 
410  base_channel_count = decode_drc_channel_layout(gb);
411 
412  for (int i = 0; i < nb_downmix_instr; i++)
413  skip_drc_downmix_instructions(gb, base_channel_count);
414 
415  for (int i = 0; i < nb_coeff_basic; i++)
416  skip_bits(gb, 4 + 7); /* drcLocation, drcCharacteristic */
417 
418  for (int i = 0; i < nb_instr_basic; i++)
420 
421  if (get_bits1(gb)) { /* uniDrcConfigExtPresent */
422  enum AACUSACDRCExt type;
423  while ((type = get_bits(gb, 4)) != UNIDRCCONFEXT_TERM) {
424  uint8_t size_bits = get_bits(gb, 4) + 4; /* bitSizeLen */
425  uint32_t bit_size = get_bits_long(gb, size_bits) + 1; /* extBitSize */
426  switch (type) {
427  default:
428  skip_bits_long(gb, bit_size);
429  break;
430  }
431  }
432  }
433 
434  return 0;
435 }
436 
438  GetBitContext *gb)
439 {
440  int len = 0, ext_config_len;
441 
442  e->ext.type = get_escaped_value(gb, 4, 8, 16); /* usacExtElementType */
443  ext_config_len = get_escaped_value(gb, 4, 8, 16); /* usacExtElementConfigLength */
444 
445  if (get_bits1(gb)) /* usacExtElementDefaultLengthPresent */
446  len = get_escaped_value(gb, 8, 16, 0) + 1;
447 
448  e->ext.default_len = len;
449  e->ext.payload_frag = get_bits1(gb); /* usacExtElementPayloadFrag */
450 
451  av_log(ac->avctx, AV_LOG_DEBUG, "Extension present: type %i, len %i\n",
452  e->ext.type, ext_config_len);
453 
454  switch (e->ext.type) {
455 #if 0 /* Skip unsupported values */
456  case ID_EXT_ELE_MPEGS:
457  break;
458  case ID_EXT_ELE_SAOC:
459  break;
460 #endif
461  case ID_EXT_ELE_UNI_DRC: {
462  int start = get_bits_count(gb);
463  int ret = decode_drc_config(ac, e, gb);
464  int skip = 8*ext_config_len - (get_bits_count(gb) - start);
465  if (ret == AVERROR_PATCHWELCOME) {
466  /* Unsupported uniDrcConfig(): ignore the DRC metadata and treat
467  * the element as fill so the stream stays decodable. */
468  e->ext.type = ID_EXT_ELE_FILL;
469  ret = 0;
470  }
471  if (ret < 0)
472  return ret;
473  if (skip < 0)
474  return AVERROR_INVALIDDATA;
475  /* The config is byte-padded to usacExtElementConfigLength */
476  skip_bits_long(gb, skip);
477  break;
478  }
479  case ID_EXT_ELE_FILL:
480  break; /* This is what the spec does */
482  /* No configuration needed - fallthrough (len should be 0) */
483  default:
484  skip_bits(gb, 8*ext_config_len);
485  e->ext.type = ID_EXT_ELE_FILL;
486  break;
487  };
488 
489  return 0;
490 }
491 
493 {
494  AACUSACConfig *usac = &oc->usac;
495  int elem_id[3 /* SCE, CPE, LFE */] = { 0, 0, 0 };
496 
497  ChannelElement *che;
498  enum RawDataBlockType type;
499  int id, ch;
500 
501  /* Initialize state */
502  for (int i = 0; i < usac->nb_elems; i++) {
503  AACUsacElemConfig *e = &usac->elems[i];
504  if (e->type == ID_USAC_EXT)
505  continue;
506 
507  switch (e->type) {
508  case ID_USAC_SCE:
509  ch = 1;
510  type = TYPE_SCE;
511  id = elem_id[0]++;
512  break;
513  case ID_USAC_CPE:
514  ch = 2;
515  type = TYPE_CPE;
516  id = elem_id[1]++;
517  break;
518  case ID_USAC_LFE:
519  ch = 1;
520  type = TYPE_LFE;
521  id = elem_id[2]++;
522  break;
523  }
524 
525  che = ff_aac_get_che(ac, type, id);
526  if (che) {
527  AACUsacStereo *us = &che->us;
528  memset(us, 0, sizeof(*us));
529 
530  if (e->sbr.ratio)
531  ff_aac_sbr_config_usac(ac, che, e);
532 
533  for (int j = 0; j < ch; j++) {
534  SingleChannelElement *sce = &che->ch[j];
535  AACUsacElemData *ue = &sce->ue;
536 
537  memset(ue, 0, sizeof(*ue));
538 
539  if (!ch)
540  ue->noise.seed = 0x3039;
541  else
542  che->ch[1].ue.noise.seed = 0x10932;
543  }
544  }
545  }
546 
547  return 0;
548 }
549 
550 /* UsacConfig */
553  int channel_config)
554 {
555  int ret;
556  uint8_t freq_idx;
557  uint8_t channel_config_idx;
558  int nb_channels = 0;
559  int ratio_mult, ratio_dec;
560  int samplerate;
561  int sbr_ratio;
562  MPEG4AudioConfig *m4ac = &oc->m4ac;
563  AACUSACConfig *usac = &oc->usac;
564  int elem_id[3 /* SCE, CPE, LFE */];
565 
566  int map_pos_set = 0;
567  uint8_t layout_map[MAX_ELEM_ID*4][3] = { 0 };
568 
569  if (!ac)
570  return AVERROR_PATCHWELCOME;
571 
572  memset(usac, 0, sizeof(*usac));
573  usac->loudness.input_method_val = -1;
574 
575  freq_idx = get_bits(gb, 5); /* usacSamplingFrequencyIndex */
576  if (freq_idx == 0x1f) {
577  samplerate = get_bits(gb, 24); /* usacSamplingFrequency */
578  if (samplerate == 0)
579  return AVERROR(EINVAL);
580  } else {
581  samplerate = ff_aac_usac_samplerate[freq_idx];
582  if (samplerate < 0)
583  return AVERROR(EINVAL);
584  }
585 
586  usac->core_sbr_frame_len_idx = get_bits(gb, 3); /* coreSbrFrameLengthIndex */
587  m4ac->frame_length_short = usac->core_sbr_frame_len_idx == 0 ||
588  usac->core_sbr_frame_len_idx == 2;
589 
590  usac->core_frame_len = (usac->core_sbr_frame_len_idx == 0 ||
591  usac->core_sbr_frame_len_idx == 2) ? 768 : 1024;
592 
593  sbr_ratio = usac->core_sbr_frame_len_idx == 2 ? 2 :
594  usac->core_sbr_frame_len_idx == 3 ? 3 :
595  usac->core_sbr_frame_len_idx == 4 ? 1 :
596  0;
597 
598  if (sbr_ratio == 2) {
599  ratio_mult = 8;
600  ratio_dec = 3;
601  } else if (sbr_ratio == 3) {
602  ratio_mult = 2;
603  ratio_dec = 1;
604  } else if (sbr_ratio == 4) {
605  ratio_mult = 4;
606  ratio_dec = 1;
607  } else {
608  ratio_mult = 1;
609  ratio_dec = 1;
610  }
611 
612  avctx->sample_rate = samplerate;
613  m4ac->ext_sample_rate = samplerate;
614  m4ac->sample_rate = (samplerate * ratio_dec) / ratio_mult;
615 
617  m4ac->sbr = sbr_ratio > 0;
618 
619  channel_config_idx = get_bits(gb, 5); /* channelConfigurationIndex */
620  if (!channel_config_idx) {
621  /* UsacChannelConfig() */
622  nb_channels = get_escaped_value(gb, 5, 8, 16); /* numOutChannels */
623  if (nb_channels > 64)
624  return AVERROR(EINVAL);
625 
627 
628  ret = av_channel_layout_custom_init(&ac->oc[1].ch_layout, nb_channels);
629  if (ret < 0)
630  return ret;
631 
632  for (int i = 0; i < nb_channels; i++) {
633  AVChannelCustom *cm = &ac->oc[1].ch_layout.u.map[i];
634  cm->id = usac_ch_pos_to_av[get_bits(gb, 5)]; /* bsOutputChannelPos */
635  }
636 
640  if (ret < 0)
641  return ret;
642 
643  ret = av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout);
644  if (ret < 0)
645  return ret;
646  } else {
647  int nb_elements;
648  if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map,
649  &nb_elements, channel_config_idx)))
650  return ret;
651 
652  /* Fill in the number of expected channels */
653  for (int i = 0; i < nb_elements; i++)
654  nb_channels += layout_map[i][0] == TYPE_CPE ? 2 : 1;
655 
656  map_pos_set = 1;
657  }
658 
659  /* UsacDecoderConfig */
660  elem_id[0] = elem_id[1] = elem_id[2] = 0;
661  usac->nb_elems = get_escaped_value(gb, 4, 8, 16) + 1;
662  if (usac->nb_elems > 64) {
663  av_log(ac->avctx, AV_LOG_ERROR, "Too many elements: %i\n",
664  usac->nb_elems);
665  usac->nb_elems = 0;
666  return AVERROR(EINVAL);
667  }
668 
669  for (int i = 0; i < usac->nb_elems; i++) {
670  int map_count = elem_id[0] + elem_id[1] + elem_id[2];
671  AACUsacElemConfig *e = &usac->elems[i];
672  memset(e, 0, sizeof(*e));
673 
674  e->type = get_bits(gb, 2); /* usacElementType */
675  if (e->type != ID_USAC_EXT && (map_count + 1) > nb_channels) {
676  av_log(ac->avctx, AV_LOG_ERROR, "Too many channels for the channel "
677  "configuration\n");
678  usac->nb_elems = 0;
679  return AVERROR(EINVAL);
680  }
681 
682  av_log(ac->avctx, AV_LOG_DEBUG, "Element present: idx %i, type %i\n",
683  i, e->type);
684 
685  switch (e->type) {
686  case ID_USAC_SCE: /* SCE */
687  /* UsacCoreConfig */
688  decode_usac_element_core(e, gb, sbr_ratio);
689  if (e->sbr.ratio > 0) {
690  ret = decode_usac_sbr_data(ac, e, gb);
691  if (ret < 0)
692  return ret;
693  }
694  layout_map[map_count][0] = TYPE_SCE;
695  layout_map[map_count][1] = elem_id[0]++;
696  if (!map_pos_set)
697  layout_map[map_count][2] = AAC_CHANNEL_FRONT;
698 
699  break;
700  case ID_USAC_CPE: /* UsacChannelPairElementConf */
701  /* UsacCoreConfig */
702  decode_usac_element_core(e, gb, sbr_ratio);
703  ret = decode_usac_element_pair(ac, e, gb);
704  if (ret < 0)
705  return ret;
706  layout_map[map_count][0] = TYPE_CPE;
707  layout_map[map_count][1] = elem_id[1]++;
708  if (!map_pos_set)
709  layout_map[map_count][2] = AAC_CHANNEL_FRONT;
710 
711  break;
712  case ID_USAC_LFE: /* LFE */
713  /* LFE has no need for any configuration */
714  e->tw_mdct = 0;
715  e->noise_fill = 0;
716  layout_map[map_count][0] = TYPE_LFE;
717  layout_map[map_count][1] = elem_id[2]++;
718  if (!map_pos_set)
719  layout_map[map_count][2] = AAC_CHANNEL_LFE;
720 
721  break;
722  case ID_USAC_EXT: /* EXT */
723  ret = decode_usac_extension(ac, e, gb);
724  if (ret < 0)
725  return ret;
726  break;
727  };
728  }
729 
730  ret = ff_aac_output_configure(ac, layout_map, elem_id[0] + elem_id[1] + elem_id[2],
731  OC_GLOBAL_HDR, 0);
732  if (ret < 0) {
733  av_log(avctx, AV_LOG_ERROR, "Unable to parse channel config!\n");
734  usac->nb_elems = 0;
735  return ret;
736  }
737 
738  if (get_bits1(gb)) { /* usacConfigExtensionPresent */
739  int invalid;
740  int nb_extensions = get_escaped_value(gb, 2, 4, 8) + 1; /* numConfigExtensions */
741  for (int i = 0; i < nb_extensions; i++) {
742  int type = get_escaped_value(gb, 4, 8, 16);
743  int len = get_escaped_value(gb, 4, 8, 16);
744  switch (type) {
746  ret = decode_loudness_set(ac, usac, gb);
747  if (ret < 0)
748  return ret;
749  break;
751  usac->stream_identifier = get_bits(gb, 16);
752  break;
753  case ID_CONFIG_EXT_FILL: /* fallthrough */
754  invalid = 0;
755  while (len--) {
756  if (get_bits(gb, 8) != 0xA5)
757  invalid++;
758  }
759  if (invalid)
760  av_log(avctx, AV_LOG_WARNING, "Invalid fill bytes: %i\n",
761  invalid);
762  break;
763  default:
764  while (len--)
765  skip_bits(gb, 8);
766  break;
767  }
768  }
769  }
770 
772 
774  if (usac->loudness.input_method_val >= 0)
775  av_log(avctx, AV_LOG_VERBOSE,
776  "USAC input loudness: %.2f LKFS (bsMethodValue=%d)\n",
777  -57.75f + 0.25f * usac->loudness.input_method_val,
778  usac->loudness.input_method_val);
779 
780  ret = ff_aac_usac_reset_state(ac, oc);
781  if (ret < 0)
782  return ret;
783 
784  return 0;
785 }
786 
789  GetBitContext *gb, uint8_t global_gain)
790 {
791  IndividualChannelStream *ics = &sce->ics;
792 
793  /* Decode all scalefactors. */
794  int offset_sf = global_gain;
795  for (int g = 0; g < ics->num_window_groups; g++) {
796  for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
797  if (g || sfb)
798  offset_sf += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
799  if (offset_sf > 255U) {
801  "Scalefactor (%d) out of range.\n", offset_sf);
802  return AVERROR_INVALIDDATA;
803  }
804 
805  sce->sfo[g*ics->max_sfb + sfb] = offset_sf - 100;
806  }
807  }
808 
809  return 0;
810 }
811 
812 /**
813  * Decode and dequantize arithmetically coded, uniformly quantized value
814  *
815  * @param coef array of dequantized, scaled spectral data
816  * @param sf array of scalefactors or intensity stereo positions
817  *
818  * @return Returns error status. 0 - OK, !0 - error
819  */
820 static int decode_spectrum_ac(AACDecContext *s, float coef[1024],
822  int reset, uint16_t len, uint16_t N)
823 {
824  AACArith ac;
825  int i, a, b;
826  uint32_t c;
827 
828  int gb_count;
829  GetBitContext gb2;
830 
831  c = ff_aac_ac_map_process(state, reset, N);
832 
833  if (!len) {
834  ff_aac_ac_finish(state, 0, N);
835  return 0;
836  }
837 
838  ff_aac_ac_init(&ac, gb);
839 
840  /* Backup reader for rolling back by 14 bits at the end */
841  gb2 = *gb;
842  gb_count = get_bits_count(&gb2);
843 
844  for (i = 0; i < len/2; i++) {
845  /* MSB */
846  int lvl, esc_nb, m;
848  for (lvl=esc_nb=0;;) {
849  uint32_t pki = ff_aac_ac_get_pk(c + (esc_nb << 17));
850  m = ff_aac_ac_decode(&ac, &gb2, ff_aac_ac_msb_cdfs[pki],
852  if (m < FF_AAC_AC_ESCAPE)
853  break;
854  lvl++;
855 
856  /* Cargo-culted value. */
857  if (lvl > 23)
858  return AVERROR(EINVAL);
859 
860  if ((esc_nb = lvl) > 7)
861  esc_nb = 7;
862  }
863 
864  b = m >> 2;
865  a = m - (b << 2);
866 
867  /* ARITH_STOP detection */
868  if (!m) {
869  if (esc_nb)
870  break;
871  a = b = 0;
872  }
873 
874  /* LSB */
875  for (int l = lvl; l > 0; l--) {
876  int lsbidx = !a ? 1 : (!b ? 0 : 2);
877  uint8_t r = ff_aac_ac_decode(&ac, &gb2, ff_aac_ac_lsb_cdfs[lsbidx],
879  a = (a << 1) | (r & 1);
880  b = (b << 1) | ((r >> 1) & 1);
881  }
882 
883  /* Dequantize coeffs here */
884  coef[2*i + 0] = a * cbrt(a);
885  coef[2*i + 1] = b * cbrt(b);
887  }
888 
889  if (len > 1) {
890  /* "Rewind" bitstream back by 14 bits */
891  int gb_count2 = get_bits_count(&gb2);
892  skip_bits(gb, gb_count2 - gb_count - 14);
893  } else {
894  *gb = gb2;
895  }
896 
898 
899  for (; i < N/2; i++) {
900  coef[2*i + 0] = 0;
901  coef[2*i + 1] = 0;
902  }
903 
904  /* Signs */
905  for (i = 0; i < len; i++) {
906  if (coef[i]) {
907  if (!get_bits1(gb)) /* s */
908  coef[i] *= -1;
909  }
910  }
911 
912  return 0;
913 }
914 
916  ChannelElement *cpe, GetBitContext *gb,
917  int num_window_groups,
918  int prev_num_window_groups,
919  int indep_flag)
920 {
921  int delta_code_time;
922  IndividualChannelStream *ics = &cpe->ch[0].ics;
923 
924  if (!get_bits1(gb)) { /* cplx_pred_all */
925  for (int g = 0; g < num_window_groups; g++) {
926  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb += SFB_PER_PRED_BAND) {
927  const uint8_t val = get_bits1(gb);
928  us->pred_used[g*cpe->max_sfb_ste + sfb] = val;
929  if ((sfb + 1) < cpe->max_sfb_ste)
930  us->pred_used[g*cpe->max_sfb_ste + sfb + 1] = val;
931  }
932  }
933  } else {
934  for (int g = 0; g < num_window_groups; g++)
935  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++)
936  us->pred_used[g*cpe->max_sfb_ste + sfb] = 1;
937  }
938 
939  us->pred_dir = get_bits1(gb);
940  us->complex_coef = get_bits1(gb);
941 
942  us->use_prev_frame = 0;
943  if (us->complex_coef && !indep_flag)
944  us->use_prev_frame = get_bits1(gb);
945 
946  delta_code_time = 0;
947  if (!indep_flag)
948  delta_code_time = get_bits1(gb);
949 
950  /* TODO: shouldn't be needed */
951  for (int g = 0; g < num_window_groups; g++) {
952  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb += SFB_PER_PRED_BAND) {
953  float last_alpha_q_re = 0;
954  float last_alpha_q_im = 0;
955  if (delta_code_time) {
956  if (g) {
957  /* Transient, after the first group - use the current frame,
958  * previous window, alpha values. */
959  last_alpha_q_re = us->alpha_q_re[(g - 1)*cpe->max_sfb_ste + sfb];
960  last_alpha_q_im = us->alpha_q_im[(g - 1)*cpe->max_sfb_ste + sfb];
961  } else if (!g &&
962  (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) &&
963  (ics->window_sequence[1] == EIGHT_SHORT_SEQUENCE)) {
964  /* The spec doesn't explicitly mention this, but it doesn't make
965  * any other sense otherwise! */
966  const int wg = prev_num_window_groups - 1;
967  last_alpha_q_re = us->prev_alpha_q_re[wg*cpe->max_sfb_ste + sfb];
968  last_alpha_q_im = us->prev_alpha_q_im[wg*cpe->max_sfb_ste + sfb];
969  } else {
970  last_alpha_q_re = us->prev_alpha_q_re[g*cpe->max_sfb_ste + sfb];
971  last_alpha_q_im = us->prev_alpha_q_im[g*cpe->max_sfb_ste + sfb];
972  }
973  } else {
974  if (sfb) {
975  last_alpha_q_re = us->alpha_q_re[g*cpe->max_sfb_ste + sfb - 1];
976  last_alpha_q_im = us->alpha_q_im[g*cpe->max_sfb_ste + sfb - 1];
977  }
978  }
979 
980  if (us->pred_used[g*cpe->max_sfb_ste + sfb]) {
981  int val = -get_vlc2(gb, ff_vlc_scalefactors, 7, 3) + 60;
982  last_alpha_q_re += val * 0.1f;
983  if (us->complex_coef) {
984  val = -get_vlc2(gb, ff_vlc_scalefactors, 7, 3) + 60;
985  last_alpha_q_im += val * 0.1f;
986  }
987  us->alpha_q_re[g*cpe->max_sfb_ste + sfb] = last_alpha_q_re;
988  us->alpha_q_im[g*cpe->max_sfb_ste + sfb] = last_alpha_q_im;
989  } else {
990  us->alpha_q_re[g*cpe->max_sfb_ste + sfb] = 0;
991  us->alpha_q_im[g*cpe->max_sfb_ste + sfb] = 0;
992  }
993 
994  if ((sfb + 1) < cpe->max_sfb_ste) {
995  us->alpha_q_re[g*cpe->max_sfb_ste + sfb + 1] =
996  us->alpha_q_re[g*cpe->max_sfb_ste + sfb];
997  us->alpha_q_im[g*cpe->max_sfb_ste + sfb + 1] =
998  us->alpha_q_im[g*cpe->max_sfb_ste + sfb];
999  }
1000  }
1001  }
1002 
1003  return 0;
1004 }
1005 
1007  AACUSACConfig *usac)
1008 {
1009  AACUsacElemData *ue = &sce->ue;
1010  IndividualChannelStream *ics = &sce->ics;
1011  const int sampling_index = ac->oc[1].m4ac.sampling_index;
1012 
1013  /* Setup window parameters */
1015  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1016  if (usac->core_frame_len == 768) {
1017  ics->swb_offset = ff_swb_offset_96[sampling_index];
1018  ics->num_swb = ff_aac_num_swb_96[sampling_index];
1019  } else {
1020  ics->swb_offset = ff_swb_offset_128[sampling_index];
1021  ics->num_swb = ff_aac_num_swb_128[sampling_index];
1022  }
1023  ics->tns_max_bands = ff_tns_max_bands_usac_128[sampling_index];
1024 
1025  /* Setup scalefactor grouping. 7 bit mask. */
1026  ics->num_window_groups = 0;
1027  for (int j = 0; j < 7; j++) {
1028  ics->group_len[j] = 1;
1029  if (ue->scale_factor_grouping & (1 << (6 - j)))
1030  ics->group_len[ics->num_window_groups] += 1;
1031  else
1032  ics->num_window_groups++;
1033  }
1034 
1035  ics->group_len[7] = 1;
1036  ics->num_window_groups++;
1037  ics->num_windows = 8;
1038  } else {
1039  if (usac->core_frame_len == 768) {
1040  ics->swb_offset = ff_swb_offset_768[sampling_index];
1041  ics->num_swb = ff_aac_num_swb_768[sampling_index];
1042  } else {
1043  ics->swb_offset = ff_swb_offset_1024[sampling_index];
1044  ics->num_swb = ff_aac_num_swb_1024[sampling_index];
1045  }
1046  ics->tns_max_bands = ff_tns_max_bands_usac_1024[sampling_index];
1047 
1048  ics->group_len[0] = 1;
1049  ics->num_window_groups = 1;
1050  ics->num_windows = 1;
1051  }
1052 
1053  if (ics->max_sfb > ics->num_swb) {
1054  av_log(ac->avctx, AV_LOG_ERROR,
1055  "Number of scalefactor bands in group (%d) "
1056  "exceeds limit (%d).\n",
1057  ics->max_sfb, ics->num_swb);
1058  ics->max_sfb = 0;
1059  return AVERROR(EINVAL);
1060  }
1061 
1062  /* Just some defaults for the band types */
1063  for (int i = 0; i < FF_ARRAY_ELEMS(sce->band_type); i++)
1064  sce->band_type[i] = ESC_BT;
1065 
1066  return 0;
1067 }
1068 
1071  GetBitContext *gb, int indep_flag)
1072 {
1073  int ret, tns_active;
1074 
1075  AACUsacStereo *us = &cpe->us;
1076  SingleChannelElement *sce1 = &cpe->ch[0];
1077  SingleChannelElement *sce2 = &cpe->ch[1];
1078  IndividualChannelStream *ics1 = &sce1->ics;
1079  IndividualChannelStream *ics2 = &sce2->ics;
1080  AACUsacElemData *ue1 = &sce1->ue;
1081  AACUsacElemData *ue2 = &sce2->ue;
1082 
1083  us->common_window = 0;
1084  us->common_tw = 0;
1085 
1086  /* Alpha values must always be zeroed out for the current frame,
1087  * as they are propagated to the next frame and may be used. */
1088  memset(us->alpha_q_re, 0, sizeof(us->alpha_q_re));
1089  memset(us->alpha_q_im, 0, sizeof(us->alpha_q_im));
1090 
1091  if (!(!ue1->core_mode && !ue2->core_mode))
1092  return 0;
1093 
1094  tns_active = get_bits1(gb);
1095  us->common_window = get_bits1(gb);
1096 
1097  if (!us->common_window || indep_flag) {
1098  memset(us->prev_alpha_q_re, 0, sizeof(us->prev_alpha_q_re));
1099  memset(us->prev_alpha_q_im, 0, sizeof(us->prev_alpha_q_im));
1100  }
1101 
1102  if (us->common_window) {
1103  /* ics_info() */
1104  ics1->window_sequence[1] = ics1->window_sequence[0];
1105  ics2->window_sequence[1] = ics2->window_sequence[0];
1106  ics1->window_sequence[0] = ics2->window_sequence[0] = get_bits(gb, 2);
1107 
1108  ics1->use_kb_window[1] = ics1->use_kb_window[0];
1109  ics2->use_kb_window[1] = ics2->use_kb_window[0];
1110  ics1->use_kb_window[0] = ics2->use_kb_window[0] = get_bits1(gb);
1111 
1112  /* If there's a change in the transform sequence, zero out last frame's
1113  * stereo prediction coefficients */
1114  if ((ics1->window_sequence[0] == EIGHT_SHORT_SEQUENCE &&
1115  ics1->window_sequence[1] != EIGHT_SHORT_SEQUENCE) ||
1116  (ics1->window_sequence[1] == EIGHT_SHORT_SEQUENCE &&
1117  ics1->window_sequence[0] != EIGHT_SHORT_SEQUENCE) ||
1118  (ics2->window_sequence[0] == EIGHT_SHORT_SEQUENCE &&
1119  ics2->window_sequence[1] != EIGHT_SHORT_SEQUENCE) ||
1120  (ics2->window_sequence[1] == EIGHT_SHORT_SEQUENCE &&
1121  ics2->window_sequence[0] != EIGHT_SHORT_SEQUENCE)) {
1122  memset(us->prev_alpha_q_re, 0, sizeof(us->prev_alpha_q_re));
1123  memset(us->prev_alpha_q_im, 0, sizeof(us->prev_alpha_q_im));
1124  }
1125 
1126  if (ics1->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1127  ics1->max_sfb = ics2->max_sfb = get_bits(gb, 4);
1129  } else {
1130  ics1->max_sfb = ics2->max_sfb = get_bits(gb, 6);
1131  }
1132 
1133  if (!get_bits1(gb)) { /* common_max_sfb */
1134  if (ics2->window_sequence[0] == EIGHT_SHORT_SEQUENCE)
1135  ics2->max_sfb = get_bits(gb, 4);
1136  else
1137  ics2->max_sfb = get_bits(gb, 6);
1138  }
1139 
1140  ret = setup_sce(ac, sce1, usac);
1141  if (ret < 0) {
1142  ics2->max_sfb = 0;
1143  return ret;
1144  }
1145 
1146  ret = setup_sce(ac, sce2, usac);
1147  if (ret < 0)
1148  return ret;
1149 
1150  cpe->max_sfb_ste = FFMAX(ics1->max_sfb, ics2->max_sfb);
1151 
1152  us->ms_mask_mode = get_bits(gb, 2); /* ms_mask_present */
1153  memset(cpe->ms_mask, 0, sizeof(cpe->ms_mask));
1154  if (us->ms_mask_mode == 1) {
1155  for (int g = 0; g < ics1->num_window_groups; g++)
1156  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++)
1157  cpe->ms_mask[g*cpe->max_sfb_ste + sfb] = get_bits1(gb);
1158  } else if (us->ms_mask_mode == 2) {
1159  memset(cpe->ms_mask, 0xFF, sizeof(cpe->ms_mask));
1160  } else if ((us->ms_mask_mode == 3) && !ec->stereo_config_index) {
1161  ret = decode_usac_stereo_cplx(ac, us, cpe, gb,
1162  ics1->num_window_groups,
1163  ics1->prev_num_window_groups,
1164  indep_flag);
1165  if (ret < 0)
1166  return ret;
1167  }
1168  }
1169 
1170  if (ec->tw_mdct) {
1171  us->common_tw = get_bits1(gb);
1173  "AAC USAC timewarping");
1174  return AVERROR_PATCHWELCOME;
1175  }
1176 
1177  us->tns_on_lr = 0;
1178  ue1->tns_data_present = ue2->tns_data_present = 0;
1179  if (tns_active) {
1180  int common_tns = 0;
1181  if (us->common_window)
1182  common_tns = get_bits1(gb);
1183 
1184  us->tns_on_lr = get_bits1(gb);
1185  if (common_tns) {
1186  ret = ff_aac_decode_tns(ac, &sce1->tns, gb, ics1);
1187  if (ret < 0)
1188  return ret;
1189  memcpy(&sce2->tns, &sce1->tns, sizeof(sce1->tns));
1190  sce2->tns.present = 1;
1191  sce1->tns.present = 1;
1192  ue1->tns_data_present = 0;
1193  ue2->tns_data_present = 0;
1194  } else {
1195  if (get_bits1(gb)) {
1196  ue1->tns_data_present = 1;
1197  ue2->tns_data_present = 1;
1198  } else {
1199  ue2->tns_data_present = get_bits1(gb);
1200  ue1->tns_data_present = !ue2->tns_data_present;
1201  }
1202  }
1203  }
1204 
1205  return 0;
1206 }
1207 
1208 /* 7.2.4 Generation of random signs for spectral noise filling
1209  * This function is exactly defined, though we've helped the definition
1210  * along with being slightly faster. */
1211 static inline float noise_random_sign(unsigned int *seed)
1212 {
1213  unsigned int new_seed = *seed = ((*seed) * 69069) + 5;
1214  if (((new_seed) & 0x10000) > 0)
1215  return -1.f;
1216  return +1.f;
1217 }
1218 
1221 {
1222  float *coef;
1223  IndividualChannelStream *ics = &sce->ics;
1224 
1225  float noise_val = powf(2, ((float)ue->noise.level - 14.0f)/3.0f);
1226  int noise_offset = ue->noise.offset - 16;
1227  int band_off;
1228 
1231 
1232  coef = sce->coeffs;
1233  for (int g = 0; g < ics->num_window_groups; g++) {
1234  unsigned g_len = ics->group_len[g];
1235 
1236  for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
1237  float *cb = coef + ics->swb_offset[sfb];
1238  int cb_len = ics->swb_offset[sfb + 1] - ics->swb_offset[sfb];
1239  int band_quantized_to_zero = 1;
1240 
1241  if (ics->swb_offset[sfb] < band_off)
1242  continue;
1243 
1244  for (int group = 0; group < (unsigned)g_len; group++, cb += 128) {
1245  for (int z = 0; z < cb_len; z++) {
1246  if (cb[z] == 0)
1247  cb[z] = noise_random_sign(&sce->ue.noise.seed) * noise_val;
1248  else
1249  band_quantized_to_zero = 0;
1250  }
1251  }
1252 
1253  if (band_quantized_to_zero) {
1254  sce->sfo[g*ics->max_sfb + sfb] = FFMAX(sce->sfo[g*ics->max_sfb + sfb] + noise_offset, -200);
1255  }
1256  }
1257  coef += g_len << 7;
1258  }
1259 }
1260 
1263 {
1264  IndividualChannelStream *ics = &sce->ics;
1265  float *coef;
1266 
1267  /* Synthesise noise */
1268  if (ue->noise.level)
1269  apply_noise_fill(ac, sce, ue);
1270 
1271  /* Noise filling may apply an offset to the scalefactor offset */
1272  ac->dsp.dequant_scalefactors(sce);
1273 
1274  /* Apply scalefactors */
1275  coef = sce->coeffs;
1276  for (int g = 0; g < ics->num_window_groups; g++) {
1277  unsigned g_len = ics->group_len[g];
1278 
1279  for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
1280  float *cb = coef + ics->swb_offset[sfb];
1281  int cb_len = ics->swb_offset[sfb + 1] - ics->swb_offset[sfb];
1282  float sf = sce->sf[g*ics->max_sfb + sfb];
1283 
1284  for (int group = 0; group < (unsigned)g_len; group++, cb += 128)
1285  ac->fdsp->vector_fmul_scalar(cb, cb, sf, cb_len);
1286  }
1287  coef += g_len << 7;
1288  }
1289 }
1290 
1292  float *dmix_re)
1293 {
1294  IndividualChannelStream *ics = &cpe->ch[0].ics;
1295  int sign = !cpe->us.pred_dir ? +1 : -1;
1296  float *coef1 = cpe->ch[0].coeffs;
1297  float *coef2 = cpe->ch[1].coeffs;
1298 
1299  for (int g = 0; g < ics->num_window_groups; g++) {
1300  unsigned g_len = ics->group_len[g];
1301  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
1302  int off = ics->swb_offset[sfb];
1303  int cb_len = ics->swb_offset[sfb + 1] - off;
1304 
1305  float *c1 = coef1 + off;
1306  float *c2 = coef2 + off;
1307  float *dm = dmix_re + off;
1308 
1309  for (int group = 0; group < (unsigned)g_len;
1310  group++, c1 += 128, c2 += 128, dm += 128) {
1311  for (int z = 0; z < cb_len; z++)
1312  dm[z] = 0.5*(c1[z] + sign*c2[z]);
1313  }
1314  }
1315 
1316  coef1 += g_len << 7;
1317  coef2 += g_len << 7;
1318  dmix_re += g_len << 7;
1319  }
1320 }
1321 
1323  float *dmix_re)
1324 {
1325  AACUsacStereo *us = &cpe->us;
1326  IndividualChannelStream *ics = &cpe->ch[0].ics;
1327  int sign = !cpe->us.pred_dir ? +1 : -1;
1328  float *coef1 = cpe->ch[0].coeffs;
1329  float *coef2 = cpe->ch[1].coeffs;
1330 
1331  for (int g = 0; g < ics->num_window_groups; g++) {
1332  unsigned g_len = ics->group_len[g];
1333  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
1334  int off = ics->swb_offset[sfb];
1335  int cb_len = ics->swb_offset[sfb + 1] - off;
1336 
1337  float *c1 = coef1 + off;
1338  float *c2 = coef2 + off;
1339  float *dm = dmix_re + off;
1340 
1341  if (us->pred_used[g*cpe->max_sfb_ste + sfb]) {
1342  for (int group = 0; group < (unsigned)g_len;
1343  group++, c1 += 128, c2 += 128, dm += 128) {
1344  for (int z = 0; z < cb_len; z++)
1345  dm[z] = 0.5*(c1[z] + sign*c2[z]);
1346  }
1347  } else {
1348  for (int group = 0; group < (unsigned)g_len;
1349  group++, c1 += 128, c2 += 128, dm += 128) {
1350  for (int z = 0; z < cb_len; z++)
1351  dm[z] = c1[z];
1352  }
1353  }
1354  }
1355 
1356  coef1 += g_len << 7;
1357  coef2 += g_len << 7;
1358  dmix_re += g_len << 7;
1359  }
1360 }
1361 
1362 static void complex_stereo_interpolate_imag(float *im, float *re, const float f[7],
1363  int len, int factor_even, int factor_odd)
1364 {
1365  int i = 0;
1366  float s;
1367 
1368  s = f[6]*re[2] + f[5]*re[1] + f[4]*re[0] +
1369  f[3]*re[0] +
1370  f[2]*re[1] + f[1]*re[2] + f[0]*re[3];
1371  im[i] += s*factor_even;
1372 
1373  i = 1;
1374  s = f[6]*re[1] + f[5]*re[0] + f[4]*re[0] +
1375  f[3]*re[1] +
1376  f[2]*re[2] + f[1]*re[3] + f[0]*re[4];
1377  im[i] += s*factor_odd;
1378 
1379  i = 2;
1380  s = f[6]*re[0] + f[5]*re[0] + f[4]*re[1] +
1381  f[3]*re[2] +
1382  f[2]*re[3] + f[1]*re[4] + f[0]*re[5];
1383 
1384  im[i] += s*factor_even;
1385  for (i = 3; i < len - 4; i += 2) {
1386  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1387  f[3]*re[i] +
1388  f[2]*re[i+1] + f[1]*re[i+2] + f[0]*re[i+3];
1389  im[i+0] += s*factor_odd;
1390 
1391  s = f[6]*re[i-2] + f[5]*re[i-1] + f[4]*re[i] +
1392  f[3]*re[i+1] +
1393  f[2]*re[i+2] + f[1]*re[i+3] + f[0]*re[i+4];
1394  im[i+1] += s*factor_even;
1395  }
1396 
1397  i = len - 3;
1398  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1399  f[3]*re[i] +
1400  f[2]*re[i+1] + f[1]*re[i+2] + f[0]*re[i+2];
1401  im[i] += s*factor_odd;
1402 
1403  i = len - 2;
1404  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1405  f[3]*re[i] +
1406  f[2]*re[i+1] + f[1]*re[i+1] + f[0]*re[i];
1407  im[i] += s*factor_even;
1408 
1409  i = len - 1;
1410  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1411  f[3]*re[i] +
1412  f[2]*re[i] + f[1]*re[i-1] + f[0]*re[i-2];
1413  im[i] += s*factor_odd;
1414 }
1415 
1417 {
1418  AACUsacStereo *us = &cpe->us;
1419  IndividualChannelStream *ics = &cpe->ch[0].ics;
1420  float *coef1 = cpe->ch[0].coeffs;
1421  float *coef2 = cpe->ch[1].coeffs;
1422  float *dmix_im = us->dmix_im;
1423 
1424  for (int g = 0; g < ics->num_window_groups; g++) {
1425  unsigned g_len = ics->group_len[g];
1426  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
1427  int off = ics->swb_offset[sfb];
1428  int cb_len = ics->swb_offset[sfb + 1] - off;
1429 
1430  float *c1 = coef1 + off;
1431  float *c2 = coef2 + off;
1432  float *dm_im = dmix_im + off;
1433  float alpha_re = us->alpha_q_re[g*cpe->max_sfb_ste + sfb];
1434  float alpha_im = us->alpha_q_im[g*cpe->max_sfb_ste + sfb];
1435 
1436  if (!us->pred_used[g*cpe->max_sfb_ste + sfb])
1437  continue;
1438 
1439  if (!cpe->us.pred_dir) {
1440  for (int group = 0; group < (unsigned)g_len;
1441  group++, c1 += 128, c2 += 128, dm_im += 128) {
1442  for (int z = 0; z < cb_len; z++) {
1443  float side;
1444  side = c2[z] - alpha_re*c1[z] - alpha_im*dm_im[z];
1445  c2[z] = c1[z] - side;
1446  c1[z] = c1[z] + side;
1447  }
1448  }
1449  } else {
1450  for (int group = 0; group < (unsigned)g_len;
1451  group++, c1 += 128, c2 += 128, dm_im += 128) {
1452  for (int z = 0; z < cb_len; z++) {
1453  float mid;
1454  mid = c2[z] - alpha_re*c1[z] - alpha_im*dm_im[z];
1455  c2[z] = mid - c1[z];
1456  c1[z] = mid + c1[z];
1457  }
1458  }
1459  }
1460  }
1461 
1462  coef1 += g_len << 7;
1463  coef2 += g_len << 7;
1464  dmix_im += g_len << 7;
1465  }
1466 }
1467 
1468 static const float *complex_stereo_get_filter(ChannelElement *cpe, int is_prev)
1469 {
1470  int win, shape;
1471  if (!is_prev) {
1472  switch (cpe->ch[0].ics.window_sequence[0]) {
1473  default:
1474  case ONLY_LONG_SEQUENCE:
1475  case EIGHT_SHORT_SEQUENCE:
1476  win = 0;
1477  break;
1478  case LONG_START_SEQUENCE:
1479  win = 1;
1480  break;
1481  case LONG_STOP_SEQUENCE:
1482  win = 2;
1483  break;
1484  }
1485 
1486  if (cpe->ch[0].ics.use_kb_window[0] == 0 &&
1487  cpe->ch[0].ics.use_kb_window[1] == 0)
1488  shape = 0;
1489  else if (cpe->ch[0].ics.use_kb_window[0] == 1 &&
1490  cpe->ch[0].ics.use_kb_window[1] == 1)
1491  shape = 1;
1492  else if (cpe->ch[0].ics.use_kb_window[0] == 0 &&
1493  cpe->ch[0].ics.use_kb_window[1] == 1)
1494  shape = 2;
1495  else if (cpe->ch[0].ics.use_kb_window[0] == 1 &&
1496  cpe->ch[0].ics.use_kb_window[1] == 0)
1497  shape = 3;
1498  else
1499  shape = 3;
1500  } else {
1501  win = cpe->ch[0].ics.window_sequence[0] == LONG_STOP_SEQUENCE;
1502  shape = cpe->ch[0].ics.use_kb_window[1];
1503  }
1504 
1505  return ff_aac_usac_mdst_filt_cur[win][shape];
1506 }
1507 
1509  ChannelElement *cpe, int nb_channels)
1510 {
1511  AACUsacStereo *us = &cpe->us;
1512 
1513  for (int ch = 0; ch < nb_channels; ch++) {
1514  SingleChannelElement *sce = &cpe->ch[ch];
1515  AACUsacElemData *ue = &sce->ue;
1516 
1517  if (!ue->core_mode)
1518  spectrum_scale(ac, sce, ue);
1519  }
1520 
1521  if (nb_channels > 1 && us->common_window) {
1522  for (int ch = 0; ch < nb_channels; ch++) {
1523  SingleChannelElement *sce = &cpe->ch[ch];
1524 
1525  /* Apply TNS, if the tns_on_lr bit is not set. */
1526  if (sce->tns.present && !us->tns_on_lr)
1527  ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1);
1528  }
1529 
1530  if (us->ms_mask_mode == 3) {
1531  const float *filt;
1532  complex_stereo_downmix_cur(ac, cpe, us->dmix_re);
1533  complex_stereo_downmix_prev(ac, cpe, us->prev_dmix_re);
1534 
1535  filt = complex_stereo_get_filter(cpe, 0);
1536  complex_stereo_interpolate_imag(us->dmix_im, us->dmix_re, filt,
1537  usac->core_frame_len, 1, 1);
1538  if (us->use_prev_frame) {
1539  filt = complex_stereo_get_filter(cpe, 1);
1540  complex_stereo_interpolate_imag(us->dmix_im, us->prev_dmix_re, filt,
1541  usac->core_frame_len, -1, 1);
1542  }
1543 
1544  apply_complex_stereo(ac, cpe);
1545  } else if (us->ms_mask_mode > 0) {
1546  ac->dsp.apply_mid_side_stereo(ac, cpe);
1547  }
1548  }
1549 
1550  /* Save coefficients and alpha values for prediction reasons */
1551  if (nb_channels > 1) {
1552  AACUsacStereo *us2 = &cpe->us;
1553  for (int ch = 0; ch < nb_channels; ch++) {
1554  SingleChannelElement *sce = &cpe->ch[ch];
1555  memcpy(sce->prev_coeffs, sce->coeffs, sizeof(sce->coeffs));
1556  }
1557  memcpy(us2->prev_alpha_q_re, us2->alpha_q_re, sizeof(us2->alpha_q_re));
1558  memcpy(us2->prev_alpha_q_im, us2->alpha_q_im, sizeof(us2->alpha_q_im));
1559  }
1560 
1561  for (int ch = 0; ch < nb_channels; ch++) {
1562  SingleChannelElement *sce = &cpe->ch[ch];
1563 
1564  /* Apply TNS, if it hasn't been applied yet. */
1565  if (sce->tns.present && ((nb_channels == 1) || (us->tns_on_lr)))
1566  ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1);
1567 
1568  if (!sce->ue.core_mode)
1569  ac->oc[1].m4ac.frame_length_short ? ac->dsp.imdct_and_windowing_768(ac, sce) :
1570  ac->dsp.imdct_and_windowing(ac, sce);
1571  }
1572 }
1573 
1574 static const uint8_t mps_fr_nb_bands[8] = {
1575  255 /* Reserved */, 28, 20, 14, 10, 7, 5, 4,
1576 };
1577 
1578 static const uint8_t mps_fr_stride_smg[4] = {
1579  1, 2, 5, 28,
1580 };
1581 
1582 static void decode_tsd(GetBitContext *gb, int *data,
1583  int nb_tr_slots, int nb_slots)
1584 {
1585  int nb_bits = av_log2(nb_slots / (nb_tr_slots + 1));
1586  int s = get_bits(gb, nb_bits);
1587  for (int k = 0; k < nb_slots; k++)
1588  data[k]=0;
1589 
1590  int p = nb_tr_slots + 1;
1591  for (int k = nb_slots - 1; k >= 0; k--) {
1592  if (p > k) {
1593  for (; k >= 0; k--)
1594  data[k] = 1;
1595  break;
1596  }
1597  int64_t c = k - p + 1;
1598  for (int h = 2; h <= p && c <= s; h++) {
1599  c += c*(k-p)/h;
1600  }
1601  if (s >= c) {
1602  s -= c;
1603  data[k] = 1;
1604  p--;
1605  if (!p)
1606  break;
1607  }
1608  }
1609 }
1610 
1613  GetBitContext *gb, int frame_indep_flag)
1614 {
1615  int err;
1616  int nb_bands = mps_fr_nb_bands[ec->mps.freq_res];
1617 
1618  /* Framing info */
1619  mps->framing_type = 0;
1620  mps->nb_param_sets = 2;
1621  if (ec->mps.high_rate_mode) {
1622  mps->framing_type = get_bits1(gb);
1623  mps->nb_param_sets = get_bits(gb, 3) + 1;
1624  }
1625  int param_slot_bits = usac->core_sbr_frame_len_idx == 4 ? 6 : 5;
1626  int nb_time_slots = usac->core_sbr_frame_len_idx == 4 ? 64 : 32;
1627 
1628  if (mps->framing_type)
1629  for (int i = 0; i < mps->nb_param_sets; i++)
1630  mps->param_sets[i] = get_bits(gb, param_slot_bits);
1631 
1632  int indep = frame_indep_flag;
1633  if (!frame_indep_flag)
1634  indep = get_bits1(gb);
1635 
1636  int extend_frame = mps->param_sets[mps->nb_param_sets - 1] !=
1637  (nb_time_slots - 1);
1638 
1639  /* CLD */
1640  err = ff_aac_ec_data_dec(gb, &mps->ott[MPS_CLD], MPS_CLD,
1641  0, 0, nb_bands,
1642  indep, indep, mps->nb_param_sets);
1643  if (err < 0) {
1644  av_log(ac->avctx, AV_LOG_ERROR, "Error parsing OTT CLD data!\n");
1645  return err;
1646  }
1648  0, 0, nb_bands, mps->nb_param_sets,
1649  mps->param_sets, extend_frame);
1650 
1651  /* ICC */
1652  err = ff_aac_ec_data_dec(gb, &mps->ott[MPS_ICC], MPS_ICC, 0, 0, nb_bands,
1653  indep, indep, mps->nb_param_sets);
1654  if (err < 0) {
1655  av_log(ac->avctx, AV_LOG_ERROR, "Error parsing OTT ICC data!\n");
1656  return err;
1657  }
1659  0, 0, nb_bands, mps->nb_param_sets,
1660  mps->param_sets, extend_frame);
1661 
1662  /* IPD */
1663  if (ec->mps.phase_coding) {
1664  if (get_bits1(gb)) {
1665  mps->opd_smoothing_mode = get_bits1(gb);
1666  err = ff_aac_ec_data_dec(gb, &mps->ott[MPS_IPD], MPS_IPD, 0, 0,
1667  ec->mps.otts_bands_phase,
1668  indep, indep, mps->nb_param_sets);
1670  0, 0, nb_bands, mps->nb_param_sets,
1671  mps->param_sets, extend_frame);
1672  if (err < 0) {
1673  av_log(ac->avctx, AV_LOG_ERROR, "Error parsing OTT IPD data!\n");
1674  return err;
1675  }
1676  }
1677  }
1678 
1679  /* SMG data */
1680  memset(mps->smooth_mode, 0, sizeof(mps->smooth_mode));
1681  if (ec->mps.high_rate_mode) {
1682  for (int i = 0; i < mps->nb_param_sets; i++) {
1683  mps->smooth_mode[i] = get_bits(gb, 2);
1684  if (mps->smooth_mode[i] >= 2)
1685  mps->smooth_time[i] = get_bits(gb, 2);
1686  if (mps->smooth_mode[i] >= 3) {
1687  mps->freq_res_stride_smg[i] = get_bits(gb, 2);
1688  int nb_data_bands = (nb_bands - 1);
1689  nb_data_bands /= (mps_fr_stride_smg[mps->freq_res_stride_smg[i]] + 1);
1690  for (int j = 0; j < nb_data_bands; j++)
1691  mps->smg_data[i][j] = get_bits1(gb);
1692  }
1693  }
1694  }
1695 
1696  /* Temp shape data */
1697  mps->tsd_enable = 0;
1698  if (ec->mps.temp_shape_config == 3) {
1699  mps->tsd_enable = get_bits1(gb);
1700  } else if (ec->mps.temp_shape_config) {
1701  mps->temp_shape_enable = get_bits1(gb);
1702  if (mps->temp_shape_enable) {
1703  for (int i = 0; i < 2; i++)
1704  mps->temp_shape_enable_ch[i] = get_bits1(gb);
1705  if (ec->mps.temp_shape_config == 2) {
1706  err = ff_aac_huff_dec_reshape(gb, mps->temp_shape_data, 16);
1707  if (err < 0) {
1708  av_log(ac->avctx, AV_LOG_ERROR,
1709  "Error parsing TSD reshape data!\n");
1710  return err;
1711  }
1712  }
1713  }
1714  }
1715 
1716  /* TSD data */
1717  if (mps->tsd_enable) {
1718  mps->tsd_num_tr_slots = get_bits(gb, param_slot_bits - 1);
1719  int tsd_pos[64];
1720  decode_tsd(gb, tsd_pos, mps->tsd_num_tr_slots, nb_time_slots);
1721  for (int i = 0; i < nb_time_slots; i++) {
1722  mps->tsd_phase_data[i] = 0;
1723  if (tsd_pos[i])
1724  mps->tsd_phase_data[i] = get_bits(gb, 3);
1725  }
1726  }
1727 
1728  return 0;
1729 }
1730 
1733  GetBitContext *gb, int indep_flag, int nb_channels)
1734 {
1735  int ret;
1736  int arith_reset_flag;
1737  AACUsacStereo *us = &che->us;
1738  int core_nb_channels = nb_channels;
1739 
1740  /* Local symbols */
1741  uint8_t global_gain;
1742 
1743  us->common_window = 0;
1744 
1745  for (int ch = 0; ch < core_nb_channels; ch++) {
1746  SingleChannelElement *sce = &che->ch[ch];
1747  AACUsacElemData *ue = &sce->ue;
1748 
1749  sce->tns.present = 0;
1750  ue->tns_data_present = 0;
1751 
1752  ue->core_mode = get_bits1(gb);
1753  }
1754 
1755  if (nb_channels > 1 && ec->stereo_config_index == 1)
1756  core_nb_channels = 1;
1757 
1758  if (core_nb_channels == 2) {
1759  ret = decode_usac_stereo_info(ac, usac, ec, che, gb, indep_flag);
1760  if (ret)
1761  return ret;
1762  }
1763 
1764  for (int ch = 0; ch < core_nb_channels; ch++) {
1765  SingleChannelElement *sce = &che->ch[ch];
1766  IndividualChannelStream *ics = &sce->ics;
1767  AACUsacElemData *ue = &sce->ue;
1768 
1769  if (ue->core_mode) { /* lpd_channel_stream */
1770  ret = ff_aac_ldp_parse_channel_stream(ac, usac, ue, gb);
1771  if (ret < 0)
1772  return ret;
1773  continue;
1774  }
1775 
1776  if ((core_nb_channels == 1) ||
1777  (che->ch[0].ue.core_mode != che->ch[1].ue.core_mode))
1778  ue->tns_data_present = get_bits1(gb);
1779 
1780  /* fd_channel_stream */
1781  global_gain = get_bits(gb, 8);
1782 
1783  ue->noise.level = 0;
1784  if (ec->noise_fill) {
1785  ue->noise.level = get_bits(gb, 3);
1786  ue->noise.offset = get_bits(gb, 5);
1787  }
1788 
1789  if (!us->common_window) {
1790  /* ics_info() */
1791  ics->window_sequence[1] = ics->window_sequence[0];
1792  ics->window_sequence[0] = get_bits(gb, 2);
1793  ics->use_kb_window[1] = ics->use_kb_window[0];
1794  ics->use_kb_window[0] = get_bits1(gb);
1795  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1796  ics->max_sfb = get_bits(gb, 4);
1797  ue->scale_factor_grouping = get_bits(gb, 7);
1798  } else {
1799  ics->max_sfb = get_bits(gb, 6);
1800  }
1801 
1802  ret = setup_sce(ac, sce, usac);
1803  if (ret < 0)
1804  return ret;
1805  }
1806 
1807  if (ec->tw_mdct && !us->common_tw) {
1808  /* tw_data() */
1809  if (get_bits1(gb)) { /* tw_data_present */
1810  /* Time warping is not supported in baseline profile streams. */
1812  "AAC USAC timewarping");
1813  return AVERROR_PATCHWELCOME;
1814  }
1815  }
1816 
1817  ret = decode_usac_scale_factors(ac, sce, gb, global_gain);
1818  if (ret < 0)
1819  return ret;
1820 
1821  if (ue->tns_data_present) {
1822  sce->tns.present = 1;
1823  ret = ff_aac_decode_tns(ac, &sce->tns, gb, ics);
1824  if (ret < 0)
1825  return ret;
1826  }
1827 
1828  /* ac_spectral_data */
1829  arith_reset_flag = indep_flag;
1830  if (!arith_reset_flag)
1831  arith_reset_flag = get_bits1(gb);
1832 
1833  /* Decode coeffs */
1834  memset(&sce->coeffs[0], 0, 1024*sizeof(float));
1835  for (int win = 0; win < ics->num_windows; win++) {
1836  int lg = ics->swb_offset[ics->max_sfb];
1837  int N;
1838  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE)
1839  N = usac->core_frame_len / 8;
1840  else
1841  N = usac->core_frame_len;
1842 
1843  ret = decode_spectrum_ac(ac, sce->coeffs + win*128, gb, &ue->ac,
1844  arith_reset_flag && (win == 0), lg, N);
1845  if (ret < 0)
1846  return ret;
1847  }
1848 
1849  if (get_bits1(gb)) { /* fac_data_present */
1850  const uint16_t len_8 = usac->core_frame_len / 8;
1851  const uint16_t len_16 = usac->core_frame_len / 16;
1852  const uint16_t fac_len = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ?
1853  len_16 : len_8;
1854  ret = ff_aac_parse_fac_data(ue, gb, 1, fac_len);
1855  if (ret < 0)
1856  return ret;
1857  }
1858  }
1859 
1860  if (ec->sbr.ratio) {
1861  int sbr_ch = nb_channels;
1862  if (nb_channels == 2 &&
1863  !(ec->stereo_config_index == 0 || ec->stereo_config_index == 3))
1864  sbr_ch = 1;
1865 
1866  ret = ff_aac_sbr_decode_usac_data(ac, che, ec, gb, sbr_ch, indep_flag);
1867  if (ret < 0)
1868  return ret;
1869  }
1870 
1871  if (ec->stereo_config_index) {
1872  ret = parse_mps212(ac, usac, &us->mps, ec, gb, indep_flag);
1873  if (ret < 0)
1874  return ret;
1875  }
1876 
1877  spectrum_decode(ac, usac, che, core_nb_channels);
1878 
1879  if (ac->oc[1].m4ac.sbr > 0) {
1880  ac->proc.sbr_apply(ac, che, nb_channels == 2 ? TYPE_CPE : TYPE_SCE, 0,
1881  che->ch[0].output,
1882  che->ch[1].output);
1883  }
1884 
1885  return 0;
1886 }
1887 
1889 {
1890  int ret = 0;
1891  GetBitContext gbc;
1892  OutputConfiguration *oc = &ac->oc[1];
1893  MPEG4AudioConfig *m4ac = &oc->m4ac;
1894  MPEG4AudioConfig m4ac_bak = oc->m4ac;
1895  uint8_t temp_data[512];
1896  uint8_t *tmp_buf = temp_data;
1897  size_t tmp_buf_size = sizeof(temp_data);
1898 
1899  av_unused int crossfade;
1900  int num_preroll_frames;
1901 
1902  int config_len = get_escaped_value(gb, 4, 4, 8);
1903 
1904  /* Implementations are free to pad the config to any length, so use a
1905  * different reader for this. */
1906  gbc = *gb;
1907  ret = ff_aac_usac_config_decode(ac, ac->avctx, &gbc, oc, m4ac->chan_config);
1908  if (ret < 0) {
1909  *m4ac = m4ac_bak;
1910  return ret;
1911  } else {
1912  ac->oc[1].m4ac.chan_config = 0;
1913  }
1914 
1915  /* 7.18.3.3 Bitrate adaption
1916  * If configuration didn't change after applying preroll, continue
1917  * without decoding it. */
1918  if (!memcmp(m4ac, &m4ac_bak, sizeof(m4ac_bak)))
1919  return 0;
1920 
1921  skip_bits_long(gb, config_len*8);
1922 
1923  crossfade = get_bits1(gb); /* applyCrossfade */
1924  skip_bits1(gb); /* reserved */
1925  num_preroll_frames = get_escaped_value(gb, 2, 4, 0); /* numPreRollFrames */
1926 
1927  for (int i = 0; i < num_preroll_frames; i++) {
1928  int got_frame_ptr = 0;
1929  int au_len = get_escaped_value(gb, 16, 16, 0);
1930 
1931  if (au_len*8 > tmp_buf_size) {
1932  uint8_t *tmp2;
1933  tmp_buf = tmp_buf == temp_data ? NULL : tmp_buf;
1934  tmp2 = av_realloc_array(tmp_buf, au_len, 8);
1935  if (!tmp2) {
1936  if (tmp_buf != temp_data)
1937  av_free(tmp_buf);
1938  return AVERROR(ENOMEM);
1939  }
1940  tmp_buf = tmp2;
1941  }
1942 
1943  /* Byte alignment is not guaranteed. */
1944  for (int j = 0; j < au_len; j++)
1945  tmp_buf[j] = get_bits(gb, 8);
1946 
1947  ret = init_get_bits8(&gbc, tmp_buf, au_len);
1948  if (ret < 0)
1949  break;
1950 
1951  ret = ff_aac_usac_decode_frame(ac->avctx, ac, &gbc, &got_frame_ptr);
1952  if (ret < 0)
1953  break;
1954  }
1955 
1956  if (tmp_buf != temp_data)
1957  av_free(tmp_buf);
1958 
1959  return 0;
1960 }
1961 
1963  GetBitContext *gb)
1964 {
1965  uint8_t pl_frag_start = 1;
1966  uint8_t pl_frag_end = 1;
1967  uint32_t len;
1968 
1969  if (!get_bits1(gb)) /* usacExtElementPresent */
1970  return 0;
1971 
1972  if (get_bits1(gb)) { /* usacExtElementUseDefaultLength */
1973  len = e->ext.default_len;
1974  } else {
1975  len = get_bits(gb, 8); /* usacExtElementPayloadLength */
1976  if (len == 255)
1977  len += get_bits(gb, 16) - 2;
1978  }
1979 
1980  if (!len)
1981  return 0;
1982 
1983  if (e->ext.payload_frag) {
1984  pl_frag_start = get_bits1(gb); /* usacExtElementStart */
1985  pl_frag_end = get_bits1(gb); /* usacExtElementStop */
1986  }
1987 
1988  if (pl_frag_start)
1989  e->ext.pl_data_offset = 0;
1990 
1991  /* If an extension starts and ends this packet, we can directly use it below.
1992  * Otherwise, we have to copy it to a buffer and accumulate it. */
1993  if (!(pl_frag_start && pl_frag_end)) {
1994  /* Reallocate the data */
1995  uint8_t *tmp_buf = av_refstruct_alloc_ext(e->ext.pl_data_offset + len,
1997  NULL, NULL);
1998  if (!tmp_buf)
1999  return AVERROR(ENOMEM);
2000 
2001  /* Copy the data over only if we had saved data to begin with */
2002  if (e->ext.pl_buf)
2003  memcpy(tmp_buf, e->ext.pl_buf, e->ext.pl_data_offset);
2004 
2006  e->ext.pl_buf = tmp_buf;
2007 
2008  /* Readout data to a buffer */
2009  for (int i = 0; i < len; i++)
2010  e->ext.pl_buf[e->ext.pl_data_offset + i] = get_bits(gb, 8);
2011  }
2012 
2013  e->ext.pl_data_offset += len;
2014 
2015  if (pl_frag_end) {
2016  int ret = 0;
2017  int start_bits = get_bits_count(gb);
2018  const int pl_len = e->ext.pl_data_offset;
2019  GetBitContext *gb2 = gb;
2020  GetBitContext gbc;
2021  if (!(pl_frag_start && pl_frag_end)) {
2022  ret = init_get_bits8(&gbc, e->ext.pl_buf, pl_len);
2023  if (ret < 0)
2024  return ret;
2025 
2026  gb2 = &gbc;
2027  }
2028 
2029  switch (e->ext.type) {
2030  case ID_EXT_ELE_FILL:
2031  /* Filler elements have no usable payload */
2032  break;
2034  ret = parse_audio_preroll(ac, gb2);
2035  break;
2036  case ID_EXT_ELE_UNI_DRC:
2037  /* uniDrcGain() payload: DRC is not applied, just consume the
2038  * bits via skip_bits_long below. */
2039  break;
2040  default:
2041  /* This should never happen */
2042  av_assert0(0);
2043  }
2045  if (ret < 0)
2046  return ret;
2047 
2048  skip_bits_long(gb, pl_len*8 - (get_bits_count(gb) - start_bits));
2049  }
2050 
2051  return 0;
2052 }
2053 
2055  GetBitContext *gb, int *got_frame_ptr)
2056 {
2057  int ret, is_dmono = 0;
2058  int indep_flag, samples = 0;
2059  int audio_found = 0;
2060  int elem_id[3 /* SCE, CPE, LFE */] = { 0, 0, 0 };
2061  AVFrame *frame = ac->frame;
2062 
2063  int ratio_mult, ratio_dec;
2064  AACUSACConfig *usac = &ac->oc[1].usac;
2065  int sbr_ratio = usac->core_sbr_frame_len_idx == 2 ? 2 :
2066  usac->core_sbr_frame_len_idx == 3 ? 3 :
2067  usac->core_sbr_frame_len_idx == 4 ? 1 :
2068  0;
2069 
2070  if (sbr_ratio == 2) {
2071  ratio_mult = 8;
2072  ratio_dec = 3;
2073  } else if (sbr_ratio == 3) {
2074  ratio_mult = 2;
2075  ratio_dec = 1;
2076  } else if (sbr_ratio == 4) {
2077  ratio_mult = 4;
2078  ratio_dec = 1;
2079  } else {
2080  ratio_mult = 1;
2081  ratio_dec = 1;
2082  }
2083 
2085  ac->oc[1].status, 0);
2086 
2088 
2089  indep_flag = get_bits1(gb);
2090 
2091  for (int i = 0; i < ac->oc[1].usac.nb_elems; i++) {
2092  int layout_id;
2093  int layout_type;
2094  AACUsacElemConfig *e = &ac->oc[1].usac.elems[i];
2095  ChannelElement *che;
2096 
2097  if (e->type == ID_USAC_SCE) {
2098  layout_id = elem_id[0]++;
2099  layout_type = TYPE_SCE;
2100  che = ff_aac_get_che(ac, TYPE_SCE, layout_id);
2101  } else if (e->type == ID_USAC_CPE) {
2102  layout_id = elem_id[1]++;
2103  layout_type = TYPE_CPE;
2104  che = ff_aac_get_che(ac, TYPE_CPE, layout_id);
2105  } else if (e->type == ID_USAC_LFE) {
2106  layout_id = elem_id[2]++;
2107  layout_type = TYPE_LFE;
2108  che = ff_aac_get_che(ac, TYPE_LFE, layout_id);
2109  }
2110 
2111  if (e->type != ID_USAC_EXT && !che) {
2112  av_log(ac->avctx, AV_LOG_ERROR,
2113  "channel element %d.%d is not allocated\n",
2114  layout_type, layout_id);
2115  return AVERROR_INVALIDDATA;
2116  }
2117 
2118  switch (e->type) {
2119  case ID_USAC_LFE:
2120  /* Fallthrough */
2121  case ID_USAC_SCE:
2122  ret = decode_usac_core_coder(ac, &ac->oc[1].usac, e, che, gb,
2123  indep_flag, 1);
2124  if (ret < 0)
2125  return ret;
2126 
2127  audio_found = 1;
2128  che->present = 1;
2129  break;
2130  case ID_USAC_CPE:
2131  ret = decode_usac_core_coder(ac, &ac->oc[1].usac, e, che, gb,
2132  indep_flag, 2);
2133  if (ret < 0)
2134  return ret;
2135 
2136  audio_found = 1;
2137  che->present = 1;
2138  break;
2139  case ID_USAC_EXT:
2140  ret = parse_ext_ele(ac, e, gb);
2141  if (ret < 0)
2142  return ret;
2143  break;
2144  }
2145  }
2146 
2147  if (audio_found)
2148  samples = ac->oc[1].m4ac.frame_length_short ? 768 : 1024;
2149 
2150  samples = (samples * ratio_mult) / ratio_dec;
2151 
2152  if (ac->oc[1].status && audio_found) {
2153  avctx->sample_rate = ac->oc[1].m4ac.ext_sample_rate;
2154  avctx->frame_size = samples;
2155  ac->oc[1].status = OC_LOCKED;
2156  }
2157 
2158  if (!frame->data[0] && samples) {
2159  av_log(avctx, AV_LOG_ERROR, "no frame data found\n");
2160  return AVERROR_INVALIDDATA;
2161  }
2162 
2163  if (samples) {
2164  frame->nb_samples = samples;
2165  frame->sample_rate = avctx->sample_rate;
2166  frame->flags = indep_flag ? AV_FRAME_FLAG_KEY : 0x0;
2167  *got_frame_ptr = 1;
2168  } else {
2169  av_frame_unref(ac->frame);
2170  frame->flags = indep_flag ? AV_FRAME_FLAG_KEY : 0x0;
2171  *got_frame_ptr = 0;
2172  }
2173 
2174  if (samples && ac->target_level) {
2175  int method_val = usac->loudness.input_method_val;
2176  if (method_val < 0) {
2177  if (!ac->warned_loudness_missing) {
2178  av_log(avctx, AV_LOG_WARNING,
2179  "target_level set but no program/anchor loudness "
2180  "measurement available; normalization skipped\n");
2181  ac->warned_loudness_missing = 1;
2182  }
2183  } else {
2184  /* Per ISO/IEC 23003-4 Table A.48: L = -57.75 + 0.25 * μ */
2185  float input_loudness = -57.75f + 0.25f * method_val;
2186  float gain_dB = (float)ac->target_level - input_loudness;
2187  float gain = powf(10.0f, gain_dB / 20.0f);
2188 
2189  for (int ch = 0; ch < frame->ch_layout.nb_channels; ch++)
2190  ac->fdsp->vector_fmul_scalar((float *)frame->extended_data[ch],
2191  (float *)frame->extended_data[ch],
2192  gain, frame->nb_samples);
2193  }
2194  }
2195 
2196  /* for dual-mono audio (SCE + SCE) */
2197  is_dmono = ac->dmono_mode && elem_id[0] == 2 &&
2200  if (is_dmono) {
2201  if (ac->dmono_mode == 1)
2202  frame->data[1] = frame->data[0];
2203  else if (ac->dmono_mode == 2)
2204  frame->data[0] = frame->data[1];
2205  }
2206 
2207  return 0;
2208 }
AACUsacMPSData::nb_param_sets
int nb_param_sets
Definition: aacdec.h:242
MAX_ELEM_ID
#define MAX_ELEM_ID
Definition: aac.h:34
AACUsacElemConfig::stereo_config_index
uint8_t stereo_config_index
Definition: aacdec.h:340
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1068
ff_usac_noise_fill_start_offset
const uint8_t ff_usac_noise_fill_start_offset[2][2]
Definition: aactab.c:1999
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:280
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AACUSACConfig::input_method_val
int input_method_val
Raw bsMethodValue (μ) of the program/anchor-loudness measurement selected for normalization at config...
Definition: aacdec.h:415
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
decode_usac_stereo_info
static int decode_usac_stereo_info(AACDecContext *ac, AACUSACConfig *usac, AACUsacElemConfig *ec, ChannelElement *cpe, GetBitContext *gb, int indep_flag)
Definition: aacdec_usac.c:1069
aacdec_ac.h
AACUSACConfig
Definition: aacdec.h:396
ID_EXT_ELE_SAOC
@ ID_EXT_ELE_SAOC
Definition: aacdec.h:91
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:395
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1040
AACUSACConfig::stream_identifier
uint16_t stream_identifier
Definition: aacdec.h:399
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:247
AACUSACConfig::nb_album
uint8_t nb_album
Definition: aacdec.h:405
spectrum_decode
static void spectrum_decode(AACDecContext *ac, AACUSACConfig *usac, ChannelElement *cpe, int nb_channels)
Definition: aacdec_usac.c:1508
AACUsacElemConfig::payload_frag
uint8_t payload_frag
Definition: aacdec.h:382
AACUsacMPSData::temp_shape_data
int16_t temp_shape_data[MPS_MAX_TIME_SLOTS]
Definition: aacdec.h:260
ff_aac_usac_config_decode
int ff_aac_usac_config_decode(AACDecContext *ac, AVCodecContext *avctx, GetBitContext *gb, OutputConfiguration *oc, int channel_config)
Definition: aacdec_usac.c:551
AV_CHAN_WIDE_LEFT
@ AV_CHAN_WIDE_LEFT
Definition: channel_layout.h:72
ID_USAC_LFE
@ ID_USAC_LFE
Definition: aacdec.h:78
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:424
ff_aac_ac_lsb_cdfs
const uint16_t ff_aac_ac_lsb_cdfs[3][4]
Definition: aactab.c:1331
int64_t
long long int64_t
Definition: coverity.c:34
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:254
AVChannelLayout::map
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
Definition: channel_layout.h:370
AACUsacElemConfig::tw_mdct
uint8_t tw_mdct
Definition: aacdec.h:337
aacsbr.h
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
AV_CHAN_TOP_SURROUND_LEFT
@ AV_CHAN_TOP_SURROUND_LEFT
+110 degrees, Lvs, TpLS
Definition: channel_layout.h:84
aacdec_usac_mps212.h
mps_fr_stride_smg
static const uint8_t mps_fr_stride_smg[4]
Definition: aacdec_usac.c:1578
complex_stereo_downmix_cur
static void complex_stereo_downmix_cur(AACDecContext *ac, ChannelElement *cpe, float *dmix_re)
Definition: aacdec_usac.c:1322
MPS_ICC
@ MPS_ICC
Definition: aacdec_usac_mps212.h:31
b
#define b
Definition: input.c:43
AACUsacMPSData
Definition: aacdec.h:239
data
const char data[16]
Definition: mxf.c:149
aacdec_usac.h
TemporalNoiseShaping::present
int present
Definition: aacdec.h:192
ue
#define ue(name, range_min, range_max)
Definition: cbs_h264.c:61
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AACUsacElemData::scale_factor_grouping
uint8_t scale_factor_grouping
Definition: aacdec.h:134
AACUSACConfig::nb_info
uint8_t nb_info
Definition: aacdec.h:407
AACDecDSP::apply_tns
void(* apply_tns)(void *_coef_param, TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
Definition: aacdec.h:473
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AACDecContext::proc
AACDecProc proc
Definition: aacdec.h:505
AACUsacElemConfig::bs_pvc
uint8_t bs_pvc
Definition: aacdec.h:347
c1
static const uint64_t c1
Definition: murmur3.c:52
AACUsacStereo::pred_dir
uint8_t pred_dir
Definition: aacdec.h:276
AACUsacElemData::tns_data_present
uint8_t tns_data_present
Definition: aacdec.h:135
ChannelElement::ch
SingleChannelElement ch[2]
Definition: aacdec.h:302
ff_aac_sample_rate_idx
static int ff_aac_sample_rate_idx(int rate)
Definition: aac.h:110
AACUsacElemConfig::dflt
struct AACUsacElemConfig::@29::@33 dflt
ff_swb_offset_128
const uint16_t *const ff_swb_offset_128[]
Definition: aactab.c:1940
ChannelElement::present
int present
Definition: aacdec.h:297
ID_CONFIG_EXT_STREAM_ID
@ ID_CONFIG_EXT_STREAM_ID
Definition: aacdec.h:85
ID_USAC_EXT
@ ID_USAC_EXT
Definition: aacdec.h:79
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
AACDecContext::dmono_mode
int dmono_mode
0->not dmono, 1->use first channel, 2->use second channel
Definition: aacdec.h:574
MPEG4AudioConfig
Definition: mpeg4audio.h:29
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:383
AACUsacElemConfig::pseudo_lr
uint8_t pseudo_lr
Definition: aacdec.h:376
IndividualChannelStream::num_swb
int num_swb
number of scalefactor window bands
Definition: aacdec.h:178
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:337
AV_CHAN_SURROUND_DIRECT_LEFT
@ AV_CHAN_SURROUND_DIRECT_LEFT
Definition: channel_layout.h:74
SingleChannelElement::coeffs
float coeffs[1024]
coefficients for IMDCT, maybe processed
Definition: aacenc.h:121
AACUsacElemData::core_mode
uint8_t core_mode
Definition: aacdec.h:133
mpeg4audio.h
AACUsacElemConfig::ext
struct AACUsacElemConfig::@31 ext
AACArith
Definition: aacdec_ac.h:34
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1055
AV_CHAN_TOP_BACK_RIGHT
@ AV_CHAN_TOP_BACK_RIGHT
Definition: channel_layout.h:67
parse_ext_ele
static int parse_ext_ele(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:1962
ID_EXT_ELE_AUDIOPREROLL
@ ID_EXT_ELE_AUDIOPREROLL
Definition: aacdec.h:92
AACUSACConfig::loudness
struct AACUSACConfig::@35 loudness
TYPE_CPE
@ TYPE_CPE
Definition: aac.h:45
SFB_PER_PRED_BAND
#define SFB_PER_PRED_BAND
Definition: aacdec_usac.c:37
GetBitContext
Definition: get_bits.h:109
decode_spectrum_ac
static int decode_spectrum_ac(AACDecContext *s, float coef[1024], GetBitContext *gb, AACArithState *state, int reset, uint16_t len, uint16_t N)
Decode and dequantize arithmetically coded, uniformly quantized value.
Definition: aacdec_usac.c:820
AACUsacElemConfig::high_rate_mode
uint8_t high_rate_mode
Definition: aacdec.h:369
val
static double val(void *priv, double ch)
Definition: aeval.c:77
OutputConfiguration::status
enum OCStatus status
Definition: aacdec.h:424
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
decode_loudness_info
static int decode_loudness_info(AACDecContext *ac, AACUSACLoudnessInfo *info, GetBitContext *gb, int v1)
Definition: aacdec_usac.c:100
AACUsacElemConfig::freq_res
uint8_t freq_res
Definition: aacdec.h:365
av_unused
#define av_unused
Definition: attributes.h:164
refstruct.h
SingleChannelElement::ics
IndividualChannelStream ics
Definition: aacdec.h:218
AACUsacMPSData::smooth_time
int smooth_time[MPS_MAX_PARAM_SETS]
Definition: aacdec.h:252
state
static struct @599 state
cbrt
#define cbrt
Definition: tablegen.h:35
AACUsacElemConfig::pl_data_offset
uint32_t pl_data_offset
Definition: aacdec.h:384
ID_CONFIG_EXT_FILL
@ ID_CONFIG_EXT_FILL
Definition: aacdec.h:83
AACUsacElemConfig
Definition: aacdec.h:334
AVChannelLayout::u
union AVChannelLayout::@527 u
Details about which channels are present in this layout.
ff_aac_ec_data_dec
int ff_aac_ec_data_dec(GetBitContext *gb, AACMPSLosslessData *ld, enum AACMPSDataType data_type, int default_val, int start_band, int end_band, int frame_indep_flag, int indep_flag, int nb_param_sets)
Definition: aacdec_usac_mps212.c:599
AACUsacMPSData::param_sets
int param_sets[MPS_MAX_PARAM_SETS]
Definition: aacdec.h:243
complex_stereo_interpolate_imag
static void complex_stereo_interpolate_imag(float *im, float *re, const float f[7], int len, int factor_even, int factor_odd)
Definition: aacdec_usac.c:1362
AV_CHAN_BOTTOM_FRONT_LEFT
@ AV_CHAN_BOTTOM_FRONT_LEFT
Definition: channel_layout.h:80
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AACDecDSP::dequant_scalefactors
void(* dequant_scalefactors)(SingleChannelElement *sce)
Definition: aacdec.h:467
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:544
AACUsacElemConfig::residual_bands
uint8_t residual_bands
Definition: aacdec.h:375
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:681
OC_GLOBAL_HDR
@ OC_GLOBAL_HDR
Output configuration set in a global header but not yet locked.
Definition: aacdec.h:57
float
float
Definition: af_crystalizer.c:122
parse_mps212
static int parse_mps212(AACDecContext *ac, AACUSACConfig *usac, AACUsacMPSData *mps, AACUsacElemConfig *ec, GetBitContext *gb, int frame_indep_flag)
Definition: aacdec_usac.c:1611
AACUsacElemConfig::harmonic_sbr
uint8_t harmonic_sbr
Definition: aacdec.h:345
AACDecDSP::apply_mid_side_stereo
void(* apply_mid_side_stereo)(AACDecContext *ac, ChannelElement *cpe)
Definition: aacdec.h:469
AACUSACDRCExt
AACUSACDRCExt
Definition: aacdec.h:101
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
AVChannelCustom
An AVChannelCustom defines a single channel within a custom order layout.
Definition: channel_layout.h:283
ff_aac_ac_finish
void ff_aac_ac_finish(AACArithState *state, int offset, int N)
Definition: aacdec_ac.c:196
g
const char * g
Definition: vf_curves.c:128
AACUsacMPSData::tsd_phase_data
int tsd_phase_data[64]
Definition: aacdec.h:263
AACUsacMPSData::tsd_num_tr_slots
int tsd_num_tr_slots
Definition: aacdec.h:262
EIGHT_SHORT_SEQUENCE
@ EIGHT_SHORT_SEQUENCE
Definition: aac.h:66
info
MIPS optimizations info
Definition: mips.txt:2
AACUsacElemConfig::mps
struct AACUsacElemConfig::@30 mps
decode_usac_scale_factors
static int decode_usac_scale_factors(AACDecContext *ac, SingleChannelElement *sce, GetBitContext *gb, uint8_t global_gain)
Definition: aacdec_usac.c:787
AV_CHAN_SIDE_RIGHT
@ AV_CHAN_SIDE_RIGHT
Definition: channel_layout.h:60
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
decode_tsd
static void decode_tsd(GetBitContext *gb, int *data, int nb_tr_slots, int nb_slots)
Definition: aacdec_usac.c:1582
av_refstruct_alloc_ext
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition: refstruct.h:94
ff_aac_get_che
ChannelElement * ff_aac_get_che(AACDecContext *ac, int type, int elem_id)
Definition: aacdec.c:623
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AACUsacMPSData::tsd_enable
bool tsd_enable
Definition: aacdec.h:257
decode_drc_instructions_basic
static void decode_drc_instructions_basic(AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:354
AACUsacElemData
Definition: aacdec.h:132
AACUSACConfig::core_sbr_frame_len_idx
uint8_t core_sbr_frame_len_idx
Definition: aacdec.h:397
IndividualChannelStream
Individual Channel Stream.
Definition: aacdec.h:169
UNIDRCLOUDEXT_TERM
@ UNIDRCLOUDEXT_TERM
Definition: aacdec.h:97
ID_USAC_CPE
@ ID_USAC_CPE
Definition: aacdec.h:77
SCALE_DIFF_ZERO
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
Definition: aac.h:95
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
AV_CHAN_TOP_SIDE_LEFT
@ AV_CHAN_TOP_SIDE_LEFT
Definition: channel_layout.h:77
ff_tns_max_bands_usac_1024
const uint8_t ff_tns_max_bands_usac_1024[]
Definition: aactab.c:1978
AACDecContext::fdsp
AVFloatDSPContext * fdsp
Definition: aacdec.h:556
ff_aac_usac_decode_frame
int ff_aac_usac_decode_frame(AVCodecContext *avctx, AACDecContext *ac, GetBitContext *gb, int *got_frame_ptr)
Definition: aacdec_usac.c:2054
AV_CHAN_TOP_SIDE_RIGHT
@ AV_CHAN_TOP_SIDE_RIGHT
Definition: channel_layout.h:78
ff_aac_ac_init
void ff_aac_ac_init(AACArith *ac, GetBitContext *gb)
Definition: aacdec_ac.c:103
if
if(ret)
Definition: filter_design.txt:179
AV_CHAN_SIDE_SURROUND_LEFT
@ AV_CHAN_SIDE_SURROUND_LEFT
+90 degrees, Lss, SiL
Definition: channel_layout.h:82
AACDecProc::sbr_apply
void(* sbr_apply)(AACDecContext *ac, ChannelElement *che, int id_aac, int fl960, void *L, void *R)
Definition: aacdec.h:458
decode_drc_channel_layout
static int decode_drc_channel_layout(GetBitContext *gb)
Definition: aacdec_usac.c:330
ff_aac_ldp_parse_channel_stream
int ff_aac_ldp_parse_channel_stream(AACDecContext *ac, AACUSACConfig *usac, AACUsacElemData *ce, GetBitContext *gb)
Definition: aacdec_lpd.c:112
NULL
#define NULL
Definition: coverity.c:32
AACDecContext::target_level
int target_level
Target output loudness in dBFS, used for xHE-AAC loudness normalization based on the parsed loudnessI...
Definition: aacdec.h:583
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AACUsacMPSData::ott
AACMPSLosslessData ott[MPS_ELE_NB]
Definition: aacdec.h:246
AACUsacElemData::seed
unsigned int seed
Definition: aacdec.h:153
AACUSACConfig::core_frame_len
uint16_t core_frame_len
Definition: aacdec.h:398
AVFloatDSPContext::vector_fmul_scalar
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
Definition: float_dsp.h:85
IndividualChannelStream::use_kb_window
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sine window.
Definition: aacdec.h:172
ff_aac_num_swb_128
const uint8_t ff_aac_num_swb_128[]
Definition: aactab.c:169
IndividualChannelStream::num_window_groups
int num_window_groups
Definition: aacdec.h:173
ff_tns_max_bands_usac_128
const uint8_t ff_tns_max_bands_usac_128[]
Definition: aactab.c:1994
AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL
#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL
The specified retype target order is ignored and the simplest possible (canonical) order is used for ...
Definition: channel_layout.h:721
AV_CHAN_TOP_BACK_CENTER
@ AV_CHAN_TOP_BACK_CENTER
Definition: channel_layout.h:66
AV_REFSTRUCT_FLAG_NO_ZEROING
#define AV_REFSTRUCT_FLAG_NO_ZEROING
If this flag is set in av_refstruct_alloc_ext_c(), the object will not be initially zeroed.
Definition: refstruct.h:67
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:391
MPEG4AudioConfig::sampling_index
int sampling_index
Definition: mpeg4audio.h:31
ChannelElement::ms_mask
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
Definition: aacdec.h:300
mps_fr_nb_bands
static const uint8_t mps_fr_nb_bands[8]
Definition: aacdec_usac.c:1574
parse_audio_preroll
static int parse_audio_preroll(AACDecContext *ac, GetBitContext *gb)
Definition: aacdec_usac.c:1888
get_escaped_value
static uint32_t get_escaped_value(GetBitContext *gb, int nb1, int nb2, int nb3)
Definition: aacdec_usac.c:39
aactab.h
AV_CHAN_BOTTOM_FRONT_RIGHT
@ AV_CHAN_BOTTOM_FRONT_RIGHT
Definition: channel_layout.h:81
AACUsacElemConfig::noise_fill
uint8_t noise_fill
Definition: aacdec.h:338
AV_CHAN_TOP_CENTER
@ AV_CHAN_TOP_CENTER
Definition: channel_layout.h:61
AAC_CHANNEL_FRONT
@ AAC_CHANNEL_FRONT
Definition: aac.h:82
AACUsacElemConfig::temp_shape_config
uint8_t temp_shape_config
Definition: aacdec.h:367
seed
static unsigned int seed
Definition: videogen.c:78
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:645
decode_usac_stereo_cplx
static int decode_usac_stereo_cplx(AACDecContext *ac, AACUsacStereo *us, ChannelElement *cpe, GetBitContext *gb, int num_window_groups, int prev_num_window_groups, int indep_flag)
Definition: aacdec_usac.c:915
ff_aac_ac_decode
uint16_t ff_aac_ac_decode(AACArith *ac, GetBitContext *gb, const uint16_t *cdf, uint16_t cdf_len)
Definition: aacdec_ac.c:110
spectrum_scale
static void spectrum_scale(AACDecContext *ac, SingleChannelElement *sce, AACUsacElemData *ue)
Definition: aacdec_usac.c:1261
AACUsacStereo
Definition: aacdec.h:266
OC_LOCKED
@ OC_LOCKED
Output configuration locked in place.
Definition: aacdec.h:58
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AV_CHAN_FRONT_RIGHT_OF_CENTER
@ AV_CHAN_FRONT_RIGHT_OF_CENTER
Definition: channel_layout.h:57
IndividualChannelStream::prev_num_window_groups
int prev_num_window_groups
Previous frame's number of window groups.
Definition: aacdec.h:174
AACUsacElemConfig::default_len
uint32_t default_len
Definition: aacdec.h:383
OutputConfiguration::layout_map_tags
int layout_map_tags
Definition: aacdec.h:422
SingleChannelElement::ue
AACUsacElemData ue
USAC element data.
Definition: aacdec.h:219
AV_CHAN_FRONT_RIGHT
@ AV_CHAN_FRONT_RIGHT
Definition: channel_layout.h:51
AV_CHAN_FRONT_CENTER
@ AV_CHAN_FRONT_CENTER
Definition: channel_layout.h:52
OutputConfiguration::layout_map
uint8_t layout_map[MAX_ELEM_ID *4][3]
Definition: aacdec.h:421
AACUsacMPSData::smg_data
bool smg_data[MPS_MAX_PARAM_SETS][MPS_MAX_PARAM_BANDS]
Definition: aacdec.h:254
AACUsacElemConfig::sbr
struct AACUsacElemConfig::@29 sbr
AACUsacElemConfig::bs_intertes
uint8_t bs_intertes
Definition: aacdec.h:346
IndividualChannelStream::window_sequence
enum WindowSequence window_sequence[2]
Definition: aacdec.h:171
AACUsacMPSData::ott_idx
int ott_idx[MPS_ELE_NB][MPS_MAX_PARAM_SETS][MPS_MAX_PARAM_BANDS]
Definition: aacdec.h:247
AACDecContext::dsp
AACDecDSP dsp
Definition: aacdec.h:504
f
f
Definition: af_crystalizer.c:122
ff_swb_offset_1024
const uint16_t *const ff_swb_offset_1024[]
Definition: aactab.c:1900
AACUsacElemConfig::otts_bands_phase_present
uint8_t otts_bands_phase_present
Definition: aacdec.h:372
AACUsacMPSData::framing_type
int framing_type
Definition: aacdec.h:241
powf
#define powf(x, y)
Definition: libm.h:52
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
ONLY_LONG_SEQUENCE
@ ONLY_LONG_SEQUENCE
Definition: aac.h:64
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AACDecDSP::imdct_and_windowing
void(* imdct_and_windowing)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:488
ChannelElement::max_sfb_ste
uint8_t max_sfb_ste
(USAC) Maximum of both max_sfb values
Definition: aacdec.h:299
AV_CHAN_LOW_FREQUENCY
@ AV_CHAN_LOW_FREQUENCY
Definition: channel_layout.h:53
ESC_BT
@ ESC_BT
Spectral data are coded with an escape sequence.
Definition: aac.h:73
SingleChannelElement::sfo
int sfo[128]
scalefactor offsets
Definition: aacdec.h:222
AACDecContext::warned_loudness_missing
int warned_loudness_missing
Definition: aacdec.h:584
MPS_CLD
@ MPS_CLD
Definition: aacdec_usac_mps212.h:30
AV_CHAN_BACK_RIGHT
@ AV_CHAN_BACK_RIGHT
Definition: channel_layout.h:55
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
AV_CHAN_SIDE_LEFT
@ AV_CHAN_SIDE_LEFT
Definition: channel_layout.h:59
ChannelElement::us
AACUsacStereo us
Definition: aacdec.h:306
OutputConfiguration
Definition: aacdec.h:419
ff_aac_usac_mdst_filt_cur
const float ff_aac_usac_mdst_filt_cur[4][4][7]
Definition: aactab.c:3885
AACUsacMPSData::freq_res_stride_smg
int freq_res_stride_smg[MPS_MAX_PARAM_SETS]
Definition: aacdec.h:253
MPS_IPD
@ MPS_IPD
Definition: aacdec_usac_mps212.h:32
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
av_channel_layout_retype
int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags)
Change the AVChannelOrder of a channel layout.
Definition: channel_layout.c:887
AV_CHAN_TOP_FRONT_RIGHT
@ AV_CHAN_TOP_FRONT_RIGHT
Definition: channel_layout.h:64
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:125
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:416
ff_aac_ac_get_context
uint32_t ff_aac_ac_get_context(AACArithState *state, uint32_t c, int i, int N)
Definition: aacdec_ac.c:57
AV_CHAN_FRONT_LEFT_OF_CENTER
@ AV_CHAN_FRONT_LEFT_OF_CENTER
Definition: channel_layout.h:56
N
#define N
Definition: af_mcompand.c:54
AACUsacElemData::noise
struct AACUsacElemData::@20 noise
SingleChannelElement::band_type
enum BandType band_type[128]
band types
Definition: aacdec.h:221
AACUsacElemConfig::fixed_gain
uint8_t fixed_gain
Definition: aacdec.h:366
ID_CONFIG_EXT_LOUDNESS_INFO
@ ID_CONFIG_EXT_LOUDNESS_INFO
Definition: aacdec.h:84
unary.h
SingleChannelElement::output
float * output
PCM output.
Definition: aacdec.h:234
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:811
ff_aac_ac_get_pk
uint32_t ff_aac_ac_get_pk(uint32_t c)
Definition: aacdec_ac.c:73
av_channel_layout_custom_init
int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels)
Initialize a custom channel layout with the specified number of channels.
Definition: channel_layout.c:233
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
AVChannel
AVChannel
Definition: channel_layout.h:47
apply_noise_fill
static void apply_noise_fill(AACDecContext *ac, SingleChannelElement *sce, AACUsacElemData *ue)
Definition: aacdec_usac.c:1219
AV_CHAN_TOP_SURROUND_RIGHT
@ AV_CHAN_TOP_SURROUND_RIGHT
-110 degrees, Rvs, TpRS
Definition: channel_layout.h:85
RawDataBlockType
RawDataBlockType
Definition: aac.h:43
AV_CHAN_SURROUND_DIRECT_RIGHT
@ AV_CHAN_SURROUND_DIRECT_RIGHT
Definition: channel_layout.h:75
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aacdec.h:217
ff_swb_offset_768
const uint16_t *const ff_swb_offset_768[]
Definition: aactab.c:1916
decode_usac_element_pair
static int decode_usac_element_pair(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:278
IndividualChannelStream::num_windows
int num_windows
Definition: aacdec.h:179
OutputConfiguration::usac
AACUSACConfig usac
Definition: aacdec.h:425
AACUsacElemConfig::drc
struct AACUsacElemConfig::@32 drc
LONG_STOP_SEQUENCE
@ LONG_STOP_SEQUENCE
Definition: aac.h:67
usac_ch_pos_to_av
static enum AVChannel usac_ch_pos_to_av[64]
Definition: aacdec_usac.c:53
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aacdec.h:296
IndividualChannelStream::swb_offset
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
Definition: aacdec.h:177
decode_drc_config
static int decode_drc_config(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:381
s
uint8_t s
Definition: llvidencdsp.c:39
ff_aac_parse_fac_data
int ff_aac_parse_fac_data(AACUsacElemData *ce, GetBitContext *gb, int use_gain, int len)
Definition: aacdec_lpd.c:93
ff_aac_usac_samplerate
const int ff_aac_usac_samplerate[32]
Definition: aactab.c:3877
AACUsacElemConfig::type
enum AACUsacElem type
Definition: aacdec.h:335
TYPE_LFE
@ TYPE_LFE
Definition: aac.h:47
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
complex_stereo_get_filter
static const float * complex_stereo_get_filter(ChannelElement *cpe, int is_prev)
Definition: aacdec_usac.c:1468
MPEG4AudioConfig::chan_config
int chan_config
Definition: mpeg4audio.h:33
AACUsacElemConfig::decorr_config
uint8_t decorr_config
Definition: aacdec.h:368
ff_aac_ac_update_context
void ff_aac_ac_update_context(AACArithState *state, int idx, uint16_t a, uint16_t b)
Definition: aacdec_ac.c:91
TYPE_SCE
@ TYPE_SCE
Definition: aac.h:44
len
int len
Definition: vorbis_enc_data.h:426
filt
static const int8_t filt[NUMTAPS *2]
Definition: af_earwax.c:40
complex_stereo_downmix_prev
static void complex_stereo_downmix_prev(AACDecContext *ac, ChannelElement *cpe, float *dmix_re)
Definition: aacdec_usac.c:1291
AACDecContext::oc
OutputConfiguration oc[2]
Definition: aacdec.h:586
MPEG4AudioConfig::ext_sample_rate
int ext_sample_rate
Definition: mpeg4audio.h:37
IndividualChannelStream::tns_max_bands
int tns_max_bands
Definition: aacdec.h:180
ff_aac_num_swb_96
const uint8_t ff_aac_num_swb_96[]
Definition: aactab.c:173
ff_aac_ac_map_process
uint32_t ff_aac_ac_map_process(AACArithState *state, int reset, int N)
Definition: aacdec_ac.c:25
AACUSACConfig::nb_elems
int nb_elems
Definition: aacdec.h:402
ID_EXT_ELE_UNI_DRC
@ ID_EXT_ELE_UNI_DRC
Definition: aacdec.h:93
AAC_CHANNEL_LFE
@ AAC_CHANNEL_LFE
Definition: aac.h:85
decode_usac_sbr_data
static int decode_usac_sbr_data(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:226
decode_loudness_set_v1
static int decode_loudness_set_v1(AACDecContext *ac, AACUSACConfig *usac, GetBitContext *gb)
Definition: aacdec_usac.c:129
ret
ret
Definition: filter_design.txt:187
ff_aac_num_swb_1024
const uint8_t ff_aac_num_swb_1024[]
Definition: aactab.c:149
AACUsacMPSData::temp_shape_enable
bool temp_shape_enable
Definition: aacdec.h:258
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AACDecContext::frame
struct AVFrame * frame
Definition: aacdec.h:507
decode_usac_element_core
static void decode_usac_element_core(AACUsacElemConfig *e, GetBitContext *gb, int sbr_ratio)
Definition: aacdec_usac.c:269
LONG_START_SEQUENCE
@ LONG_START_SEQUENCE
Definition: aac.h:65
UNIDRCLOUDEXT_EQ
@ UNIDRCLOUDEXT_EQ
Definition: aacdec.h:98
id
enum AVCodecID id
Definition: dts2pts.c:578
AACUsacMPSData::smooth_mode
int smooth_mode[MPS_MAX_PARAM_SETS]
Definition: aacdec.h:251
aacdec_lpd.h
AV_CHAN_BACK_CENTER
@ AV_CHAN_BACK_CENTER
Definition: channel_layout.h:58
SingleChannelElement::tns
TemporalNoiseShaping tns
Definition: aacdec.h:220
U
#define U(x)
Definition: vpx_arith.h:37
AACDecContext
main AAC decoding context
Definition: aacdec.h:500
AACUSACConfig::info
AACUSACLoudnessInfo info[64]
Definition: aacdec.h:408
AVCodecContext
main external API structure.
Definition: avcodec.h:443
c2
static const uint64_t c2
Definition: murmur3.c:53
AACUsacMPSData::temp_shape_enable_ch
bool temp_shape_enable_ch[2]
Definition: aacdec.h:259
AACUsacElemConfig::loudness
struct AACUsacElemConfig::@32::@34 loudness
AV_CHAN_LOW_FREQUENCY_2
@ AV_CHAN_LOW_FREQUENCY_2
Definition: channel_layout.h:76
AACDecContext::avctx
struct AVCodecContext * avctx
Definition: aacdec.h:502
AV_CHAN_TOP_BACK_LEFT
@ AV_CHAN_TOP_BACK_LEFT
Definition: channel_layout.h:65
noise_random_sign
static float noise_random_sign(unsigned int *seed)
Definition: aacdec_usac.c:1211
apply_complex_stereo
static void apply_complex_stereo(AACDecContext *ac, ChannelElement *cpe)
Definition: aacdec_usac.c:1416
aacdec_tab.h
setup_sce
static int setup_sce(AACDecContext *ac, SingleChannelElement *sce, AACUSACConfig *usac)
Definition: aacdec_usac.c:1006
AACUSACLoudnessInfo
Definition: aacdec.h:309
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1636
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:443
cm
#define cm
Definition: dvbsubdec.c:40
AACUsacElemConfig::env_quant_mode
uint8_t env_quant_mode
Definition: aacdec.h:377
AV_CHAN_BACK_LEFT
@ AV_CHAN_BACK_LEFT
Definition: channel_layout.h:54
MPEG4AudioConfig::sbr
int sbr
-1 implicit, 1 presence
Definition: mpeg4audio.h:34
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
ff_aac_decode_tns
int ff_aac_decode_tns(AACDecContext *ac, TemporalNoiseShaping *tns, GetBitContext *gb, const IndividualChannelStream *ics)
Decode Temporal Noise Shaping data; reference: table 4.48.
Definition: aacdec.c:1678
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
ff_aac_usac_reset_state
int ff_aac_usac_reset_state(AACDecContext *ac, OutputConfiguration *oc)
Definition: aacdec_usac.c:492
AV_CHAN_BOTTOM_FRONT_CENTER
@ AV_CHAN_BOTTOM_FRONT_CENTER
Definition: channel_layout.h:79
AACUsacElemConfig::ratio
int ratio
Definition: aacdec.h:343
decode_loudness_set
static int decode_loudness_set(AACDecContext *ac, AACUSACConfig *usac, GetBitContext *gb)
Definition: aacdec_usac.c:178
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:450
OutputConfiguration::m4ac
MPEG4AudioConfig m4ac
Definition: aacdec.h:420
ff_aac_map_index_data
int ff_aac_map_index_data(AACMPSLosslessData *ld, enum AACMPSDataType data_type, int dst_idx[MPS_MAX_PARAM_SETS][MPS_MAX_PARAM_BANDS], int default_value, int start_band, int stop_band, int nb_param_sets, const int *param_set_idx, int extend_frame)
Definition: aacdec_usac_mps212.c:786
AV_CHAN_TOP_FRONT_CENTER
@ AV_CHAN_TOP_FRONT_CENTER
Definition: channel_layout.h:63
AACUSACConfig::elems
AACUsacElemConfig elems[MAX_ELEM_ID]
Definition: aacdec.h:401
us
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_apv.c:70
skip_drc_downmix_instructions
static void skip_drc_downmix_instructions(GetBitContext *gb, int base_channel_count)
Definition: aacdec_usac.c:342
AV_CHAN_SIDE_SURROUND_RIGHT
@ AV_CHAN_SIDE_SURROUND_RIGHT
-90 degrees, Rss, SiR
Definition: channel_layout.h:83
mem.h
FF_AAC_AC_ESCAPE
#define FF_AAC_AC_ESCAPE
Definition: aacdec_ac.h:40
OutputConfiguration::ch_layout
AVChannelLayout ch_layout
Definition: aacdec.h:423
AV_CHAN_WIDE_RIGHT
@ AV_CHAN_WIDE_RIGHT
Definition: channel_layout.h:73
ff_aac_sbr_decode_usac_data
int ff_aac_sbr_decode_usac_data(AACDecContext *ac, ChannelElement *che, AACUsacElemConfig *ue, GetBitContext *gb, int sbr_ch, int indep_flag)
Decode frame SBR data, USAC.
Definition: aacsbr_template.c:1209
decode_usac_core_coder
static int decode_usac_core_coder(AACDecContext *ac, AACUSACConfig *usac, AACUsacElemConfig *ec, ChannelElement *che, GetBitContext *gb, int indep_flag, int nb_channels)
Definition: aacdec_usac.c:1731
AACDecDSP::imdct_and_windowing_768
void(* imdct_and_windowing_768)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:489
MPEG4AudioConfig::frame_length_short
int frame_length_short
Definition: mpeg4audio.h:41
ID_EXT_ELE_MPEGS
@ ID_EXT_ELE_MPEGS
Definition: aacdec.h:90
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AACUsacMPSData::opd_smoothing_mode
bool opd_smoothing_mode
Definition: aacdec.h:248
ff_aac_ac_msb_cdfs
const uint16_t ff_aac_ac_msb_cdfs[64][17]
Definition: aactab.c:1200
ff_vlc_scalefactors
VLCElem ff_vlc_scalefactors[352]
Definition: aacdec_tab.c:111
AV_CHAN_TOP_FRONT_LEFT
@ AV_CHAN_TOP_FRONT_LEFT
Definition: channel_layout.h:62
IndividualChannelStream::max_sfb
uint8_t max_sfb
number of scalefactor bands per group
Definition: aacdec.h:170
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2070
AV_CHAN_FRONT_LEFT
@ AV_CHAN_FRONT_LEFT
Definition: channel_layout.h:50
ff_aac_set_default_channel_config
int ff_aac_set_default_channel_config(AACDecContext *ac, AVCodecContext *avctx, uint8_t(*layout_map)[3], int *tags, int channel_config)
Set up channel positions based on a default channel configuration as specified in table 1....
Definition: aacdec.c:583
ff_aac_huff_dec_reshape
int ff_aac_huff_dec_reshape(GetBitContext *gb, int16_t *out_data, int nb_val)
Definition: aacdec_usac_mps212.c:686
AACArithState
Definition: aacdec_ac.h:27
AACUsacElemConfig::residual_coding
uint8_t residual_coding
Definition: aacdec.h:374
ff_aac_sbr_config_usac
int ff_aac_sbr_config_usac(AACDecContext *ac, ChannelElement *che, AACUsacElemConfig *ue)
Due to channel allocation not being known upon SBR parameter transmission, supply the parameters sepa...
Definition: aacsbr_template.c:1201
AACUsacElemConfig::otts_bands_phase
uint8_t otts_bands_phase
Definition: aacdec.h:373
AACUSACLoudnessExt
AACUSACLoudnessExt
Definition: aacdec.h:96
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aacdec.h:175
UNIDRCCONFEXT_TERM
@ UNIDRCCONFEXT_TERM
Definition: aacdec.h:102
ff_aac_num_swb_768
const uint8_t ff_aac_num_swb_768[]
Definition: aactab.c:157
AACUsacElemConfig::pl_buf
uint8_t * pl_buf
Definition: aacdec.h:385
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AV_PROFILE_AAC_USAC
#define AV_PROFILE_AAC_USAC
Definition: defs.h:76
select_loudness_measurement
static int select_loudness_measurement(const AACUSACConfig *usac)
Definition: aacdec_usac.c:163
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:383
methodvalue_width
static int methodvalue_width(int method_def)
Definition: aacdec_usac.c:89
AACUsacElemConfig::phase_coding
uint8_t phase_coding
Definition: aacdec.h:370
ff_aac_output_configure
int ff_aac_output_configure(AACDecContext *ac, uint8_t layout_map[MAX_ELEM_ID *4][3], int tags, enum OCStatus oc_type, int get_new_frame)
Configure output channel order based on the current program configuration element.
Definition: aacdec.c:487
ID_EXT_ELE_FILL
@ ID_EXT_ELE_FILL
Definition: aacdec.h:89
AACUSACConfig::album_info
AACUSACLoudnessInfo album_info[64]
Definition: aacdec.h:406
MPEG4AudioConfig::sample_rate
int sample_rate
Definition: mpeg4audio.h:32
ff_swb_offset_96
const uint16_t *const ff_swb_offset_96[]
Definition: aactab.c:1958
decode_usac_extension
static int decode_usac_extension(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:437
ID_USAC_SCE
@ ID_USAC_SCE
Definition: aacdec.h:76