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 
28 #include "libavcodec/aactab.h"
29 #include "libavutil/mem.h"
30 #include "libavcodec/mpeg4audio.h"
31 #include "libavcodec/unary.h"
32 
33 /* Number of scalefactor bands per complex prediction band, equal to 2. */
34 #define SFB_PER_PRED_BAND 2
35 
36 static inline uint32_t get_escaped_value(GetBitContext *gb, int nb1, int nb2, int nb3)
37 {
38  uint32_t val = get_bits(gb, nb1), val2;
39  if (val < ((1 << nb1) - 1))
40  return val;
41 
42  val += val2 = get_bits(gb, nb2);
43  if (nb3 && (val2 == ((1 << nb2) - 1)))
44  val += get_bits(gb, nb3);
45 
46  return val;
47 }
48 
49 /* ISO/IEC 23003-3, Table 74 — bsOutputChannelPos */
50 static const enum AVChannel usac_ch_pos_to_av[64] = {
51  [0] = AV_CHAN_FRONT_LEFT,
52  [1] = AV_CHAN_FRONT_RIGHT,
55  [4] = AV_CHAN_SIDE_LEFT, // +110 degrees, Ls|LS|kAudioChannelLabel_LeftSurround
56  [5] = AV_CHAN_SIDE_RIGHT, // -110 degrees, Rs|RS|kAudioChannelLabel_RightSurround
59  [8] = AV_CHAN_BACK_LEFT, // +135 degrees, Lsr|BL|kAudioChannelLabel_RearSurroundLeft
60  [9] = AV_CHAN_BACK_RIGHT, // -135 degrees, Rsr|BR|kAudioChannelLabel_RearSurroundRight
61  [10] = AV_CHAN_BACK_CENTER,
64  [13] = AV_CHAN_SIDE_SURROUND_LEFT, // +90 degrees, Lss|SL|kAudioChannelLabel_LeftSideSurround
65  [14] = AV_CHAN_SIDE_SURROUND_RIGHT, // -90 degrees, Rss|SR|kAudioChannelLabel_RightSideSurround
66  [15] = AV_CHAN_WIDE_LEFT, // +60 degrees, Lw|FLw|kAudioChannelLabel_LeftWide
67  [16] = AV_CHAN_WIDE_RIGHT, // -60 degrees, Rw|FRw|kAudioChannelLabel_RightWide
71  [20] = AV_CHAN_TOP_BACK_LEFT,
74  [23] = AV_CHAN_TOP_SIDE_LEFT,
76  [25] = AV_CHAN_TOP_CENTER,
81  [30] = AV_CHAN_TOP_SURROUND_LEFT, ///< +110 degrees, Lvs, TpLS
82  [31] = AV_CHAN_TOP_SURROUND_RIGHT, ///< -110 degrees, Rvs, TpRS
83 };
84 
86  GetBitContext *gb)
87 {
88  info->drc_set_id = get_bits(gb, 6);
89  info->downmix_id = get_bits(gb, 7);
90 
91  if ((info->sample_peak.present = get_bits1(gb))) /* samplePeakLevelPresent */
92  info->sample_peak.lvl = get_bits(gb, 12);
93 
94  if ((info->true_peak.present = get_bits1(gb))) { /* truePeakLevelPresent */
95  info->true_peak.lvl = get_bits(gb, 12);
96  info->true_peak.measurement = get_bits(gb, 4);
97  info->true_peak.reliability = get_bits(gb, 2);
98  }
99 
100  info->nb_measurements = get_bits(gb, 4);
101  for (int i = 0; i < info->nb_measurements; i++) {
102  info->measurements[i].method_def = get_bits(gb, 4);
103  info->measurements[i].method_val = get_unary(gb, 0, 8);
104  info->measurements[i].measurement = get_bits(gb, 4);
105  info->measurements[i].reliability = get_bits(gb, 2);
106  }
107 
108  return 0;
109 }
110 
112  GetBitContext *gb)
113 {
114  int ret;
115 
116  usac->loudness.nb_album = get_bits(gb, 6); /* loudnessInfoAlbumCount */
117  usac->loudness.nb_info = get_bits(gb, 6); /* loudnessInfoCount */
118 
119  for (int i = 0; i < usac->loudness.nb_album; i++) {
120  ret = decode_loudness_info(ac, &usac->loudness.album_info[i], gb);
121  if (ret < 0)
122  return ret;
123  }
124 
125  for (int i = 0; i < usac->loudness.nb_info; i++) {
126  ret = decode_loudness_info(ac, &usac->loudness.info[i], gb);
127  if (ret < 0)
128  return ret;
129  }
130 
131  if (get_bits1(gb)) { /* loudnessInfoSetExtPresent */
133  while ((type = get_bits(gb, 4)) != UNIDRCLOUDEXT_TERM) {
134  uint8_t size_bits = get_bits(gb, 4) + 4;
135  uint8_t bit_size = get_bits(gb, size_bits) + 1;
136  switch (type) {
137  case UNIDRCLOUDEXT_EQ:
138  avpriv_report_missing_feature(ac->avctx, "loudnessInfoV1");
139  return AVERROR_PATCHWELCOME;
140  default:
141  for (int i = 0; i < bit_size; i++)
142  skip_bits1(gb);
143  }
144  }
145  }
146 
147  return 0;
148 }
149 
152 {
153  uint8_t header_extra1;
154  uint8_t header_extra2;
155 
156  e->sbr.harmonic_sbr = get_bits1(gb); /* harmonicSBR */
157  e->sbr.bs_intertes = get_bits1(gb); /* bs_interTes */
158  e->sbr.bs_pvc = get_bits1(gb); /* bs_pvc */
159  if (e->sbr.harmonic_sbr || e->sbr.bs_intertes || e->sbr.bs_pvc) {
160  avpriv_report_missing_feature(ac->avctx, "AAC USAC eSBR");
161  return AVERROR_PATCHWELCOME;
162  }
163 
164  e->sbr.dflt.start_freq = get_bits(gb, 4); /* dflt_start_freq */
165  e->sbr.dflt.stop_freq = get_bits(gb, 4); /* dflt_stop_freq */
166 
167  header_extra1 = get_bits1(gb); /* dflt_header_extra1 */
168  header_extra2 = get_bits1(gb); /* dflt_header_extra2 */
169 
170  e->sbr.dflt.freq_scale = 2;
171  e->sbr.dflt.alter_scale = 1;
172  e->sbr.dflt.noise_bands = 2;
173  if (header_extra1) {
174  e->sbr.dflt.freq_scale = get_bits(gb, 2); /* dflt_freq_scale */
175  e->sbr.dflt.alter_scale = get_bits1(gb); /* dflt_alter_scale */
176  e->sbr.dflt.noise_bands = get_bits(gb, 2); /* dflt_noise_bands */
177  }
178 
179  e->sbr.dflt.limiter_bands = 2;
180  e->sbr.dflt.limiter_gains = 2;
181  e->sbr.dflt.interpol_freq = 1;
182  e->sbr.dflt.smoothing_mode = 1;
183  if (header_extra2) {
184  e->sbr.dflt.limiter_bands = get_bits(gb, 2); /* dflt_limiter_bands */
185  e->sbr.dflt.limiter_gains = get_bits(gb, 2); /* dflt_limiter_gains */
186  e->sbr.dflt.interpol_freq = get_bits1(gb); /* dflt_interpol_freq */
187  e->sbr.dflt.smoothing_mode = get_bits1(gb); /* dflt_smoothing_mode */
188  }
189 
190  return 0;
191 }
192 
194  GetBitContext *gb,
195  int sbr_ratio)
196 {
197  e->tw_mdct = get_bits1(gb); /* tw_mdct */
198  e->noise_fill = get_bits1(gb);
199  e->sbr.ratio = sbr_ratio;
200 }
201 
204 {
205  e->stereo_config_index = 0;
206  if (e->sbr.ratio) {
207  int ret = decode_usac_sbr_data(ac, e, gb);
208  if (ret < 0)
209  return ret;
210  e->stereo_config_index = get_bits(gb, 2);
211  }
212 
213  if (e->stereo_config_index) {
214  e->mps.freq_res = get_bits(gb, 3); /* bsFreqRes */
215  e->mps.fixed_gain = get_bits(gb, 3); /* bsFixedGainDMX */
216  e->mps.temp_shape_config = get_bits(gb, 2); /* bsTempShapeConfig */
217  e->mps.decorr_config = get_bits(gb, 2); /* bsDecorrConfig */
218  e->mps.high_rate_mode = get_bits1(gb); /* bsHighRateMode */
219  e->mps.phase_coding = get_bits1(gb); /* bsPhaseCoding */
220 
221  if (get_bits1(gb)) /* bsOttBandsPhasePresent */
222  e->mps.otts_bands_phase = get_bits(gb, 5); /* bsOttBandsPhase */
223 
224  e->mps.residual_coding = e->stereo_config_index >= 2; /* bsResidualCoding */
225  if (e->mps.residual_coding) {
226  e->mps.residual_bands = get_bits(gb, 5); /* bsResidualBands */
227  e->mps.pseudo_lr = get_bits1(gb); /* bsPseudoLr */
228  }
229  if (e->mps.temp_shape_config == 2)
230  e->mps.env_quant_mode = get_bits1(gb); /* bsEnvQuantMode */
231  }
232 
233  return 0;
234 }
235 
237  GetBitContext *gb)
238 {
239  int len = 0, ext_config_len;
240 
241  e->ext.type = get_escaped_value(gb, 4, 8, 16); /* usacExtElementType */
242  ext_config_len = get_escaped_value(gb, 4, 8, 16); /* usacExtElementConfigLength */
243 
244  if (get_bits1(gb)) /* usacExtElementDefaultLengthPresent */
245  len = get_escaped_value(gb, 8, 16, 0) + 1;
246 
247  e->ext.default_len = len;
248  e->ext.payload_frag = get_bits1(gb); /* usacExtElementPayloadFrag */
249 
250  av_log(ac->avctx, AV_LOG_DEBUG, "Extension present: type %i, len %i\n",
251  e->ext.type, ext_config_len);
252 
253  switch (e->ext.type) {
254 #if 0 /* Skip unsupported values */
255  case ID_EXT_ELE_MPEGS:
256  break;
257  case ID_EXT_ELE_SAOC:
258  break;
259  case ID_EXT_ELE_UNI_DRC:
260  break;
261 #endif
262  case ID_EXT_ELE_FILL:
263  break; /* This is what the spec does */
265  /* No configuration needed - fallthrough (len should be 0) */
266  default:
267  skip_bits(gb, 8*ext_config_len);
268  e->ext.type = ID_EXT_ELE_FILL;
269  break;
270  };
271 
272  return 0;
273 }
274 
276 {
277  AACUSACConfig *usac = &oc->usac;
278  int elem_id[3 /* SCE, CPE, LFE */] = { 0, 0, 0 };
279 
280  ChannelElement *che;
281  enum RawDataBlockType type;
282  int id, ch;
283 
284  /* Initialize state */
285  for (int i = 0; i < usac->nb_elems; i++) {
286  AACUsacElemConfig *e = &usac->elems[i];
287  if (e->type == ID_USAC_EXT)
288  continue;
289 
290  switch (e->type) {
291  case ID_USAC_SCE:
292  ch = 1;
293  type = TYPE_SCE;
294  id = elem_id[0]++;
295  break;
296  case ID_USAC_CPE:
297  ch = 2;
298  type = TYPE_CPE;
299  id = elem_id[1]++;
300  break;
301  case ID_USAC_LFE:
302  ch = 1;
303  type = TYPE_LFE;
304  id = elem_id[2]++;
305  break;
306  }
307 
308  che = ff_aac_get_che(ac, type, id);
309  if (che) {
310  AACUsacStereo *us = &che->us;
311  memset(us, 0, sizeof(*us));
312 
313  if (e->sbr.ratio)
314  ff_aac_sbr_config_usac(ac, che, e);
315 
316  for (int j = 0; j < ch; j++) {
317  SingleChannelElement *sce = &che->ch[ch];
318  AACUsacElemData *ue = &sce->ue;
319 
320  memset(ue, 0, sizeof(*ue));
321 
322  if (!ch)
323  ue->noise.seed = 0x3039;
324  else
325  che->ch[1].ue.noise.seed = 0x10932;
326  }
327  }
328  }
329 
330  return 0;
331 }
332 
333 /* UsacConfig */
336  int channel_config)
337 {
338  int ret;
339  uint8_t freq_idx;
340  uint8_t channel_config_idx;
341  int nb_channels = 0;
342  int ratio_mult, ratio_dec;
343  int samplerate;
344  int sbr_ratio;
345  MPEG4AudioConfig *m4ac = &oc->m4ac;
346  AACUSACConfig *usac = &oc->usac;
347  int elem_id[3 /* SCE, CPE, LFE */];
348 
349  int map_pos_set = 0;
350  uint8_t layout_map[MAX_ELEM_ID*4][3] = { 0 };
351 
352  if (!ac)
353  return AVERROR_PATCHWELCOME;
354 
355  memset(usac, 0, sizeof(*usac));
356 
357  freq_idx = get_bits(gb, 5); /* usacSamplingFrequencyIndex */
358  if (freq_idx == 0x1f) {
359  samplerate = get_bits(gb, 24); /* usacSamplingFrequency */
360  } else {
361  samplerate = ff_aac_usac_samplerate[freq_idx];
362  if (samplerate < 0)
363  return AVERROR(EINVAL);
364  }
365 
366  usac->core_sbr_frame_len_idx = get_bits(gb, 3); /* coreSbrFrameLengthIndex */
367  m4ac->frame_length_short = usac->core_sbr_frame_len_idx == 0 ||
368  usac->core_sbr_frame_len_idx == 2;
369 
370  usac->core_frame_len = (usac->core_sbr_frame_len_idx == 0 ||
371  usac->core_sbr_frame_len_idx == 2) ? 768 : 1024;
372 
373  sbr_ratio = usac->core_sbr_frame_len_idx == 2 ? 2 :
374  usac->core_sbr_frame_len_idx == 3 ? 3 :
375  usac->core_sbr_frame_len_idx == 4 ? 1 :
376  0;
377 
378  if (sbr_ratio == 2) {
379  ratio_mult = 8;
380  ratio_dec = 3;
381  } else if (sbr_ratio == 3) {
382  ratio_mult = 2;
383  ratio_dec = 1;
384  } else if (sbr_ratio == 4) {
385  ratio_mult = 4;
386  ratio_dec = 1;
387  } else {
388  ratio_mult = 1;
389  ratio_dec = 1;
390  }
391 
392  avctx->sample_rate = samplerate;
393  m4ac->ext_sample_rate = samplerate;
394  m4ac->sample_rate = (samplerate * ratio_dec) / ratio_mult;
395 
397  m4ac->sbr = sbr_ratio > 0;
398 
399  channel_config_idx = get_bits(gb, 5); /* channelConfigurationIndex */
400  if (!channel_config_idx) {
401  /* UsacChannelConfig() */
402  nb_channels = get_escaped_value(gb, 5, 8, 16); /* numOutChannels */
403  if (nb_channels > 64)
404  return AVERROR(EINVAL);
405 
407 
408  ret = av_channel_layout_custom_init(&ac->oc[1].ch_layout, nb_channels);
409  if (ret < 0)
410  return ret;
411 
412  for (int i = 0; i < nb_channels; i++) {
413  AVChannelCustom *cm = &ac->oc[1].ch_layout.u.map[i];
414  cm->id = usac_ch_pos_to_av[get_bits(gb, 5)]; /* bsOutputChannelPos */
415  }
416 
420  if (ret < 0)
421  return ret;
422 
423  ret = av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout);
424  if (ret < 0)
425  return ret;
426  } else {
427  int nb_elements;
428  if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map,
429  &nb_elements, channel_config_idx)))
430  return ret;
431 
432  /* Fill in the number of expected channels */
433  for (int i = 0; i < nb_elements; i++)
434  nb_channels += layout_map[i][0] == TYPE_CPE ? 2 : 1;
435 
436  map_pos_set = 1;
437  }
438 
439  /* UsacDecoderConfig */
440  elem_id[0] = elem_id[1] = elem_id[2] = 0;
441  usac->nb_elems = get_escaped_value(gb, 4, 8, 16) + 1;
442  if (usac->nb_elems > 64) {
443  av_log(ac->avctx, AV_LOG_ERROR, "Too many elements: %i\n",
444  usac->nb_elems);
445  usac->nb_elems = 0;
446  return AVERROR(EINVAL);
447  }
448 
449  for (int i = 0; i < usac->nb_elems; i++) {
450  int map_count = elem_id[0] + elem_id[1] + elem_id[2];
451  AACUsacElemConfig *e = &usac->elems[i];
452  memset(e, 0, sizeof(*e));
453 
454  e->type = get_bits(gb, 2); /* usacElementType */
455  if (e->type != ID_USAC_EXT && (map_count + 1) > nb_channels) {
456  av_log(ac->avctx, AV_LOG_ERROR, "Too many channels for the channel "
457  "configuration\n");
458  usac->nb_elems = 0;
459  return AVERROR(EINVAL);
460  }
461 
462  av_log(ac->avctx, AV_LOG_DEBUG, "Element present: idx %i, type %i\n",
463  i, e->type);
464 
465  switch (e->type) {
466  case ID_USAC_SCE: /* SCE */
467  /* UsacCoreConfig */
468  decode_usac_element_core(e, gb, sbr_ratio);
469  if (e->sbr.ratio > 0) {
470  ret = decode_usac_sbr_data(ac, e, gb);
471  if (ret < 0)
472  return ret;
473  }
474  layout_map[map_count][0] = TYPE_SCE;
475  layout_map[map_count][1] = elem_id[0]++;
476  if (!map_pos_set)
477  layout_map[map_count][2] = AAC_CHANNEL_FRONT;
478 
479  break;
480  case ID_USAC_CPE: /* UsacChannelPairElementConf */
481  /* UsacCoreConfig */
482  decode_usac_element_core(e, gb, sbr_ratio);
483  ret = decode_usac_element_pair(ac, e, gb);
484  if (ret < 0)
485  return ret;
486  layout_map[map_count][0] = TYPE_CPE;
487  layout_map[map_count][1] = elem_id[1]++;
488  if (!map_pos_set)
489  layout_map[map_count][2] = AAC_CHANNEL_FRONT;
490 
491  break;
492  case ID_USAC_LFE: /* LFE */
493  /* LFE has no need for any configuration */
494  e->tw_mdct = 0;
495  e->noise_fill = 0;
496  layout_map[map_count][0] = TYPE_LFE;
497  layout_map[map_count][1] = elem_id[2]++;
498  if (!map_pos_set)
499  layout_map[map_count][2] = AAC_CHANNEL_LFE;
500 
501  break;
502  case ID_USAC_EXT: /* EXT */
503  ret = decode_usac_extension(ac, e, gb);
504  if (ret < 0)
505  return ret;
506  break;
507  };
508  }
509 
510  ret = ff_aac_output_configure(ac, layout_map, elem_id[0] + elem_id[1] + elem_id[2],
511  OC_GLOBAL_HDR, 0);
512  if (ret < 0) {
513  av_log(avctx, AV_LOG_ERROR, "Unable to parse channel config!\n");
514  usac->nb_elems = 0;
515  return ret;
516  }
517 
518  if (get_bits1(gb)) { /* usacConfigExtensionPresent */
519  int invalid;
520  int nb_extensions = get_escaped_value(gb, 2, 4, 8) + 1; /* numConfigExtensions */
521  for (int i = 0; i < nb_extensions; i++) {
522  int type = get_escaped_value(gb, 4, 8, 16);
523  int len = get_escaped_value(gb, 4, 8, 16);
524  switch (type) {
526  ret = decode_loudness_set(ac, usac, gb);
527  if (ret < 0)
528  return ret;
529  break;
531  usac->stream_identifier = get_bits(gb, 16);
532  break;
533  case ID_CONFIG_EXT_FILL: /* fallthrough */
534  invalid = 0;
535  while (len--) {
536  if (get_bits(gb, 8) != 0xA5)
537  invalid++;
538  }
539  if (invalid)
540  av_log(avctx, AV_LOG_WARNING, "Invalid fill bytes: %i\n",
541  invalid);
542  break;
543  default:
544  while (len--)
545  skip_bits(gb, 8);
546  break;
547  }
548  }
549  }
550 
552 
553  ret = ff_aac_usac_reset_state(ac, oc);
554  if (ret < 0)
555  return ret;
556 
557  return 0;
558 }
559 
562  GetBitContext *gb, uint8_t global_gain)
563 {
564  IndividualChannelStream *ics = &sce->ics;
565 
566  /* Decode all scalefactors. */
567  int offset_sf = global_gain;
568  for (int g = 0; g < ics->num_window_groups; g++) {
569  for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
570  if (g || sfb)
571  offset_sf += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
572  if (offset_sf > 255U) {
574  "Scalefactor (%d) out of range.\n", offset_sf);
575  return AVERROR_INVALIDDATA;
576  }
577 
578  sce->sfo[g*ics->max_sfb + sfb] = offset_sf - 100;
579  }
580  }
581 
582  return 0;
583 }
584 
585 /**
586  * Decode and dequantize arithmetically coded, uniformly quantized value
587  *
588  * @param coef array of dequantized, scaled spectral data
589  * @param sf array of scalefactors or intensity stereo positions
590  *
591  * @return Returns error status. 0 - OK, !0 - error
592  */
593 static int decode_spectrum_ac(AACDecContext *s, float coef[1024],
595  int reset, uint16_t len, uint16_t N)
596 {
597  AACArith ac;
598  int i, a, b;
599  uint32_t c;
600 
601  int gb_count;
602  GetBitContext gb2;
603 
604  c = ff_aac_ac_map_process(state, reset, N);
605 
606  if (!len) {
607  ff_aac_ac_finish(state, 0, N);
608  return 0;
609  }
610 
611  ff_aac_ac_init(&ac, gb);
612 
613  /* Backup reader for rolling back by 14 bits at the end */
614  gb2 = *gb;
615  gb_count = get_bits_count(&gb2);
616 
617  for (i = 0; i < len/2; i++) {
618  /* MSB */
619  int lvl, esc_nb, m;
621  for (lvl=esc_nb=0;;) {
622  uint32_t pki = ff_aac_ac_get_pk(c + (esc_nb << 17));
623  m = ff_aac_ac_decode(&ac, &gb2, ff_aac_ac_msb_cdfs[pki],
625  if (m < FF_AAC_AC_ESCAPE)
626  break;
627  lvl++;
628 
629  /* Cargo-culted value. */
630  if (lvl > 23)
631  return AVERROR(EINVAL);
632 
633  if ((esc_nb = lvl) > 7)
634  esc_nb = 7;
635  }
636 
637  b = m >> 2;
638  a = m - (b << 2);
639 
640  /* ARITH_STOP detection */
641  if (!m) {
642  if (esc_nb)
643  break;
644  a = b = 0;
645  }
646 
647  /* LSB */
648  for (int l = lvl; l > 0; l--) {
649  int lsbidx = !a ? 1 : (!b ? 0 : 2);
650  uint8_t r = ff_aac_ac_decode(&ac, &gb2, ff_aac_ac_lsb_cdfs[lsbidx],
652  a = (a << 1) | (r & 1);
653  b = (b << 1) | ((r >> 1) & 1);
654  }
655 
656  /* Dequantize coeffs here */
657  coef[2*i + 0] = a * cbrt(a);
658  coef[2*i + 1] = b * cbrt(b);
660  }
661 
662  if (len > 1) {
663  /* "Rewind" bitstream back by 14 bits */
664  int gb_count2 = get_bits_count(&gb2);
665  skip_bits(gb, gb_count2 - gb_count - 14);
666  } else {
667  *gb = gb2;
668  }
669 
671 
672  for (; i < N/2; i++) {
673  coef[2*i + 0] = 0;
674  coef[2*i + 1] = 0;
675  }
676 
677  /* Signs */
678  for (i = 0; i < len; i++) {
679  if (coef[i]) {
680  if (!get_bits1(gb)) /* s */
681  coef[i] *= -1;
682  }
683  }
684 
685  return 0;
686 }
687 
689  ChannelElement *cpe, GetBitContext *gb,
690  int num_window_groups,
691  int prev_num_window_groups,
692  int indep_flag)
693 {
694  int delta_code_time;
695  IndividualChannelStream *ics = &cpe->ch[0].ics;
696 
697  if (!get_bits1(gb)) { /* cplx_pred_all */
698  for (int g = 0; g < num_window_groups; g++) {
699  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb += SFB_PER_PRED_BAND) {
700  const uint8_t val = get_bits1(gb);
701  us->pred_used[g*cpe->max_sfb_ste + sfb] = val;
702  if ((sfb + 1) < cpe->max_sfb_ste)
703  us->pred_used[g*cpe->max_sfb_ste + sfb + 1] = val;
704  }
705  }
706  } else {
707  for (int g = 0; g < num_window_groups; g++)
708  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++)
709  us->pred_used[g*cpe->max_sfb_ste + sfb] = 1;
710  }
711 
712  us->pred_dir = get_bits1(gb);
713  us->complex_coef = get_bits1(gb);
714 
715  us->use_prev_frame = 0;
716  if (us->complex_coef && !indep_flag)
717  us->use_prev_frame = get_bits1(gb);
718 
719  delta_code_time = 0;
720  if (!indep_flag)
721  delta_code_time = get_bits1(gb);
722 
723  /* TODO: shouldn't be needed */
724  for (int g = 0; g < num_window_groups; g++) {
725  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb += SFB_PER_PRED_BAND) {
726  float last_alpha_q_re = 0;
727  float last_alpha_q_im = 0;
728  if (delta_code_time) {
729  if (g) {
730  /* Transient, after the first group - use the current frame,
731  * previous window, alpha values. */
732  last_alpha_q_re = us->alpha_q_re[(g - 1)*cpe->max_sfb_ste + sfb];
733  last_alpha_q_im = us->alpha_q_im[(g - 1)*cpe->max_sfb_ste + sfb];
734  } else if (!g &&
735  (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) &&
736  (ics->window_sequence[1] == EIGHT_SHORT_SEQUENCE)) {
737  /* The spec doesn't explicitly mention this, but it doesn't make
738  * any other sense otherwise! */
739  const int wg = prev_num_window_groups - 1;
740  last_alpha_q_re = us->prev_alpha_q_re[wg*cpe->max_sfb_ste + sfb];
741  last_alpha_q_im = us->prev_alpha_q_im[wg*cpe->max_sfb_ste + sfb];
742  } else {
743  last_alpha_q_re = us->prev_alpha_q_re[g*cpe->max_sfb_ste + sfb];
744  last_alpha_q_im = us->prev_alpha_q_im[g*cpe->max_sfb_ste + sfb];
745  }
746  } else {
747  if (sfb) {
748  last_alpha_q_re = us->alpha_q_re[g*cpe->max_sfb_ste + sfb - 1];
749  last_alpha_q_im = us->alpha_q_im[g*cpe->max_sfb_ste + sfb - 1];
750  }
751  }
752 
753  if (us->pred_used[g*cpe->max_sfb_ste + sfb]) {
754  int val = -get_vlc2(gb, ff_vlc_scalefactors, 7, 3) + 60;
755  last_alpha_q_re += val * 0.1f;
756  if (us->complex_coef) {
757  val = -get_vlc2(gb, ff_vlc_scalefactors, 7, 3) + 60;
758  last_alpha_q_im += val * 0.1f;
759  }
760  us->alpha_q_re[g*cpe->max_sfb_ste + sfb] = last_alpha_q_re;
761  us->alpha_q_im[g*cpe->max_sfb_ste + sfb] = last_alpha_q_im;
762  } else {
763  us->alpha_q_re[g*cpe->max_sfb_ste + sfb] = 0;
764  us->alpha_q_im[g*cpe->max_sfb_ste + sfb] = 0;
765  }
766 
767  if ((sfb + 1) < cpe->max_sfb_ste) {
768  us->alpha_q_re[g*cpe->max_sfb_ste + sfb + 1] =
769  us->alpha_q_re[g*cpe->max_sfb_ste + sfb];
770  us->alpha_q_im[g*cpe->max_sfb_ste + sfb + 1] =
771  us->alpha_q_im[g*cpe->max_sfb_ste + sfb];
772  }
773  }
774  }
775 
776  return 0;
777 }
778 
780  AACUSACConfig *usac)
781 {
782  AACUsacElemData *ue = &sce->ue;
783  IndividualChannelStream *ics = &sce->ics;
784  const int sampling_index = ac->oc[1].m4ac.sampling_index;
785 
786  /* Setup window parameters */
788  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
789  if (usac->core_frame_len == 768) {
790  ics->swb_offset = ff_swb_offset_96[sampling_index];
791  ics->num_swb = ff_aac_num_swb_96[sampling_index];
792  } else {
793  ics->swb_offset = ff_swb_offset_128[sampling_index];
794  ics->num_swb = ff_aac_num_swb_128[sampling_index];
795  }
796  ics->tns_max_bands = ff_tns_max_bands_usac_128[sampling_index];
797 
798  /* Setup scalefactor grouping. 7 bit mask. */
799  ics->num_window_groups = 0;
800  for (int j = 0; j < 7; j++) {
801  ics->group_len[j] = 1;
802  if (ue->scale_factor_grouping & (1 << (6 - j)))
803  ics->group_len[ics->num_window_groups] += 1;
804  else
805  ics->num_window_groups++;
806  }
807 
808  ics->group_len[7] = 1;
809  ics->num_window_groups++;
810  ics->num_windows = 8;
811  } else {
812  if (usac->core_frame_len == 768) {
813  ics->swb_offset = ff_swb_offset_768[sampling_index];
814  ics->num_swb = ff_aac_num_swb_768[sampling_index];
815  } else {
816  ics->swb_offset = ff_swb_offset_1024[sampling_index];
817  ics->num_swb = ff_aac_num_swb_1024[sampling_index];
818  }
819  ics->tns_max_bands = ff_tns_max_bands_usac_1024[sampling_index];
820 
821  ics->group_len[0] = 1;
822  ics->num_window_groups = 1;
823  ics->num_windows = 1;
824  }
825 
826  if (ics->max_sfb > ics->num_swb) {
828  "Number of scalefactor bands in group (%d) "
829  "exceeds limit (%d).\n",
830  ics->max_sfb, ics->num_swb);
831  ics->max_sfb = 0;
832  return AVERROR(EINVAL);
833  }
834 
835  /* Just some defaults for the band types */
836  for (int i = 0; i < FF_ARRAY_ELEMS(sce->band_type); i++)
837  sce->band_type[i] = ESC_BT;
838 
839  return 0;
840 }
841 
844  GetBitContext *gb, int indep_flag)
845 {
846  int ret, tns_active;
847 
848  AACUsacStereo *us = &cpe->us;
849  SingleChannelElement *sce1 = &cpe->ch[0];
850  SingleChannelElement *sce2 = &cpe->ch[1];
851  IndividualChannelStream *ics1 = &sce1->ics;
852  IndividualChannelStream *ics2 = &sce2->ics;
853  AACUsacElemData *ue1 = &sce1->ue;
854  AACUsacElemData *ue2 = &sce2->ue;
855 
856  us->common_window = 0;
857  us->common_tw = 0;
858 
859  /* Alpha values must always be zeroed out for the current frame,
860  * as they are propagated to the next frame and may be used. */
861  memset(us->alpha_q_re, 0, sizeof(us->alpha_q_re));
862  memset(us->alpha_q_im, 0, sizeof(us->alpha_q_im));
863 
864  if (!(!ue1->core_mode && !ue2->core_mode))
865  return 0;
866 
867  tns_active = get_bits1(gb);
868  us->common_window = get_bits1(gb);
869 
870  if (!us->common_window || indep_flag) {
871  memset(us->prev_alpha_q_re, 0, sizeof(us->prev_alpha_q_re));
872  memset(us->prev_alpha_q_im, 0, sizeof(us->prev_alpha_q_im));
873  }
874 
875  if (us->common_window) {
876  /* ics_info() */
877  ics1->window_sequence[1] = ics1->window_sequence[0];
878  ics2->window_sequence[1] = ics2->window_sequence[0];
879  ics1->window_sequence[0] = ics2->window_sequence[0] = get_bits(gb, 2);
880 
881  ics1->use_kb_window[1] = ics1->use_kb_window[0];
882  ics2->use_kb_window[1] = ics2->use_kb_window[0];
883  ics1->use_kb_window[0] = ics2->use_kb_window[0] = get_bits1(gb);
884 
885  /* If there's a change in the transform sequence, zero out last frame's
886  * stereo prediction coefficients */
887  if ((ics1->window_sequence[0] == EIGHT_SHORT_SEQUENCE &&
888  ics1->window_sequence[1] != EIGHT_SHORT_SEQUENCE) ||
889  (ics1->window_sequence[1] == EIGHT_SHORT_SEQUENCE &&
890  ics1->window_sequence[0] != EIGHT_SHORT_SEQUENCE) ||
891  (ics2->window_sequence[0] == EIGHT_SHORT_SEQUENCE &&
892  ics2->window_sequence[1] != EIGHT_SHORT_SEQUENCE) ||
893  (ics2->window_sequence[1] == EIGHT_SHORT_SEQUENCE &&
894  ics2->window_sequence[0] != EIGHT_SHORT_SEQUENCE)) {
895  memset(us->prev_alpha_q_re, 0, sizeof(us->prev_alpha_q_re));
896  memset(us->prev_alpha_q_im, 0, sizeof(us->prev_alpha_q_im));
897  }
898 
899  if (ics1->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
900  ics1->max_sfb = ics2->max_sfb = get_bits(gb, 4);
902  } else {
903  ics1->max_sfb = ics2->max_sfb = get_bits(gb, 6);
904  }
905 
906  if (!get_bits1(gb)) { /* common_max_sfb */
907  if (ics2->window_sequence[0] == EIGHT_SHORT_SEQUENCE)
908  ics2->max_sfb = get_bits(gb, 4);
909  else
910  ics2->max_sfb = get_bits(gb, 6);
911  }
912 
913  ret = setup_sce(ac, sce1, usac);
914  if (ret < 0) {
915  ics2->max_sfb = 0;
916  return ret;
917  }
918 
919  ret = setup_sce(ac, sce2, usac);
920  if (ret < 0)
921  return ret;
922 
923  cpe->max_sfb_ste = FFMAX(ics1->max_sfb, ics2->max_sfb);
924 
925  us->ms_mask_mode = get_bits(gb, 2); /* ms_mask_present */
926  memset(cpe->ms_mask, 0, sizeof(cpe->ms_mask));
927  if (us->ms_mask_mode == 1) {
928  for (int g = 0; g < ics1->num_window_groups; g++)
929  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++)
930  cpe->ms_mask[g*cpe->max_sfb_ste + sfb] = get_bits1(gb);
931  } else if (us->ms_mask_mode == 2) {
932  memset(cpe->ms_mask, 0xFF, sizeof(cpe->ms_mask));
933  } else if ((us->ms_mask_mode == 3) && !ec->stereo_config_index) {
934  ret = decode_usac_stereo_cplx(ac, us, cpe, gb,
935  ics1->num_window_groups,
937  indep_flag);
938  if (ret < 0)
939  return ret;
940  }
941  }
942 
943  if (ec->tw_mdct) {
944  us->common_tw = get_bits1(gb);
946  "AAC USAC timewarping");
947  return AVERROR_PATCHWELCOME;
948  }
949 
950  us->tns_on_lr = 0;
951  ue1->tns_data_present = ue2->tns_data_present = 0;
952  if (tns_active) {
953  int common_tns = 0;
954  if (us->common_window)
955  common_tns = get_bits1(gb);
956 
957  us->tns_on_lr = get_bits1(gb);
958  if (common_tns) {
959  ret = ff_aac_decode_tns(ac, &sce1->tns, gb, ics1);
960  if (ret < 0)
961  return ret;
962  memcpy(&sce2->tns, &sce1->tns, sizeof(sce1->tns));
963  sce2->tns.present = 1;
964  sce1->tns.present = 1;
965  ue1->tns_data_present = 0;
966  ue2->tns_data_present = 0;
967  } else {
968  if (get_bits1(gb)) {
969  ue1->tns_data_present = 1;
970  ue2->tns_data_present = 1;
971  } else {
972  ue2->tns_data_present = get_bits1(gb);
973  ue1->tns_data_present = !ue2->tns_data_present;
974  }
975  }
976  }
977 
978  return 0;
979 }
980 
981 /* 7.2.4 Generation of random signs for spectral noise filling
982  * This function is exactly defined, though we've helped the definition
983  * along with being slightly faster. */
984 static inline float noise_random_sign(unsigned int *seed)
985 {
986  unsigned int new_seed = *seed = ((*seed) * 69069) + 5;
987  if (((new_seed) & 0x10000) > 0)
988  return -1.f;
989  return +1.f;
990 }
991 
994 {
995  float *coef;
996  IndividualChannelStream *ics = &sce->ics;
997 
998  float noise_val = powf(2, ((float)ue->noise.level - 14.0f)/3.0f);
999  int noise_offset = ue->noise.offset - 16;
1000  int band_off;
1001 
1004 
1005  coef = sce->coeffs;
1006  for (int g = 0; g < ics->num_window_groups; g++) {
1007  unsigned g_len = ics->group_len[g];
1008 
1009  for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
1010  float *cb = coef + ics->swb_offset[sfb];
1011  int cb_len = ics->swb_offset[sfb + 1] - ics->swb_offset[sfb];
1012  int band_quantized_to_zero = 1;
1013 
1014  if (ics->swb_offset[sfb] < band_off)
1015  continue;
1016 
1017  for (int group = 0; group < (unsigned)g_len; group++, cb += 128) {
1018  for (int z = 0; z < cb_len; z++) {
1019  if (cb[z] == 0)
1020  cb[z] = noise_random_sign(&sce->ue.noise.seed) * noise_val;
1021  else
1022  band_quantized_to_zero = 0;
1023  }
1024  }
1025 
1026  if (band_quantized_to_zero)
1027  sce->sfo[g*ics->max_sfb + sfb] += noise_offset;
1028  }
1029  coef += g_len << 7;
1030  }
1031 }
1032 
1035 {
1036  IndividualChannelStream *ics = &sce->ics;
1037  float *coef;
1038 
1039  /* Synthesise noise */
1040  if (ue->noise.level)
1041  apply_noise_fill(ac, sce, ue);
1042 
1043  /* Noise filling may apply an offset to the scalefactor offset */
1044  ac->dsp.dequant_scalefactors(sce);
1045 
1046  /* Apply scalefactors */
1047  coef = sce->coeffs;
1048  for (int g = 0; g < ics->num_window_groups; g++) {
1049  unsigned g_len = ics->group_len[g];
1050 
1051  for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
1052  float *cb = coef + ics->swb_offset[sfb];
1053  int cb_len = ics->swb_offset[sfb + 1] - ics->swb_offset[sfb];
1054  float sf = sce->sf[g*ics->max_sfb + sfb];
1055 
1056  for (int group = 0; group < (unsigned)g_len; group++, cb += 128)
1057  ac->fdsp->vector_fmul_scalar(cb, cb, sf, cb_len);
1058  }
1059  coef += g_len << 7;
1060  }
1061 }
1062 
1064  float *dmix_re)
1065 {
1066  IndividualChannelStream *ics = &cpe->ch[0].ics;
1067  int sign = !cpe->us.pred_dir ? +1 : -1;
1068  float *coef1 = cpe->ch[0].coeffs;
1069  float *coef2 = cpe->ch[1].coeffs;
1070 
1071  for (int g = 0; g < ics->num_window_groups; g++) {
1072  unsigned g_len = ics->group_len[g];
1073  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
1074  int off = ics->swb_offset[sfb];
1075  int cb_len = ics->swb_offset[sfb + 1] - off;
1076 
1077  float *c1 = coef1 + off;
1078  float *c2 = coef2 + off;
1079  float *dm = dmix_re + off;
1080 
1081  for (int group = 0; group < (unsigned)g_len;
1082  group++, c1 += 128, c2 += 128, dm += 128) {
1083  for (int z = 0; z < cb_len; z++)
1084  dm[z] = 0.5*(c1[z] + sign*c2[z]);
1085  }
1086  }
1087 
1088  coef1 += g_len << 7;
1089  coef2 += g_len << 7;
1090  dmix_re += g_len << 7;
1091  }
1092 }
1093 
1095  float *dmix_re)
1096 {
1097  AACUsacStereo *us = &cpe->us;
1098  IndividualChannelStream *ics = &cpe->ch[0].ics;
1099  int sign = !cpe->us.pred_dir ? +1 : -1;
1100  float *coef1 = cpe->ch[0].coeffs;
1101  float *coef2 = cpe->ch[1].coeffs;
1102 
1103  for (int g = 0; g < ics->num_window_groups; g++) {
1104  unsigned g_len = ics->group_len[g];
1105  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
1106  int off = ics->swb_offset[sfb];
1107  int cb_len = ics->swb_offset[sfb + 1] - off;
1108 
1109  float *c1 = coef1 + off;
1110  float *c2 = coef2 + off;
1111  float *dm = dmix_re + off;
1112 
1113  if (us->pred_used[g*cpe->max_sfb_ste + sfb]) {
1114  for (int group = 0; group < (unsigned)g_len;
1115  group++, c1 += 128, c2 += 128, dm += 128) {
1116  for (int z = 0; z < cb_len; z++)
1117  dm[z] = 0.5*(c1[z] + sign*c2[z]);
1118  }
1119  } else {
1120  for (int group = 0; group < (unsigned)g_len;
1121  group++, c1 += 128, c2 += 128, dm += 128) {
1122  for (int z = 0; z < cb_len; z++)
1123  dm[z] = c1[z];
1124  }
1125  }
1126  }
1127 
1128  coef1 += g_len << 7;
1129  coef2 += g_len << 7;
1130  dmix_re += g_len << 7;
1131  }
1132 }
1133 
1134 static void complex_stereo_interpolate_imag(float *im, float *re, const float f[7],
1135  int len, int factor_even, int factor_odd)
1136 {
1137  int i = 0;
1138  float s;
1139 
1140  s = f[6]*re[2] + f[5]*re[1] + f[4]*re[0] +
1141  f[3]*re[0] +
1142  f[2]*re[1] + f[1]*re[2] + f[0]*re[3];
1143  im[i] += s*factor_even;
1144 
1145  i = 1;
1146  s = f[6]*re[1] + f[5]*re[0] + f[4]*re[0] +
1147  f[3]*re[1] +
1148  f[2]*re[2] + f[1]*re[3] + f[0]*re[4];
1149  im[i] += s*factor_odd;
1150 
1151  i = 2;
1152  s = f[6]*re[0] + f[5]*re[0] + f[4]*re[1] +
1153  f[3]*re[2] +
1154  f[2]*re[3] + f[1]*re[4] + f[0]*re[5];
1155 
1156  im[i] += s*factor_even;
1157  for (i = 3; i < len - 4; i += 2) {
1158  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1159  f[3]*re[i] +
1160  f[2]*re[i+1] + f[1]*re[i+2] + f[0]*re[i+3];
1161  im[i+0] += s*factor_odd;
1162 
1163  s = f[6]*re[i-2] + f[5]*re[i-1] + f[4]*re[i] +
1164  f[3]*re[i+1] +
1165  f[2]*re[i+2] + f[1]*re[i+3] + f[0]*re[i+4];
1166  im[i+1] += s*factor_even;
1167  }
1168 
1169  i = len - 3;
1170  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1171  f[3]*re[i] +
1172  f[2]*re[i+1] + f[1]*re[i+2] + f[0]*re[i+2];
1173  im[i] += s*factor_odd;
1174 
1175  i = len - 2;
1176  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1177  f[3]*re[i] +
1178  f[2]*re[i+1] + f[1]*re[i+1] + f[0]*re[i];
1179  im[i] += s*factor_even;
1180 
1181  i = len - 1;
1182  s = f[6]*re[i-3] + f[5]*re[i-2] + f[4]*re[i-1] +
1183  f[3]*re[i] +
1184  f[2]*re[i] + f[1]*re[i-1] + f[0]*re[i-2];
1185  im[i] += s*factor_odd;
1186 }
1187 
1189 {
1190  AACUsacStereo *us = &cpe->us;
1191  IndividualChannelStream *ics = &cpe->ch[0].ics;
1192  float *coef1 = cpe->ch[0].coeffs;
1193  float *coef2 = cpe->ch[1].coeffs;
1194  float *dmix_im = us->dmix_im;
1195 
1196  for (int g = 0; g < ics->num_window_groups; g++) {
1197  unsigned g_len = ics->group_len[g];
1198  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
1199  int off = ics->swb_offset[sfb];
1200  int cb_len = ics->swb_offset[sfb + 1] - off;
1201 
1202  float *c1 = coef1 + off;
1203  float *c2 = coef2 + off;
1204  float *dm_im = dmix_im + off;
1205  float alpha_re = us->alpha_q_re[g*cpe->max_sfb_ste + sfb];
1206  float alpha_im = us->alpha_q_im[g*cpe->max_sfb_ste + sfb];
1207 
1208  if (!us->pred_used[g*cpe->max_sfb_ste + sfb])
1209  continue;
1210 
1211  if (!cpe->us.pred_dir) {
1212  for (int group = 0; group < (unsigned)g_len;
1213  group++, c1 += 128, c2 += 128, dm_im += 128) {
1214  for (int z = 0; z < cb_len; z++) {
1215  float side;
1216  side = c2[z] - alpha_re*c1[z] - alpha_im*dm_im[z];
1217  c2[z] = c1[z] - side;
1218  c1[z] = c1[z] + side;
1219  }
1220  }
1221  } else {
1222  for (int group = 0; group < (unsigned)g_len;
1223  group++, c1 += 128, c2 += 128, dm_im += 128) {
1224  for (int z = 0; z < cb_len; z++) {
1225  float mid;
1226  mid = c2[z] - alpha_re*c1[z] - alpha_im*dm_im[z];
1227  c2[z] = mid - c1[z];
1228  c1[z] = mid + c1[z];
1229  }
1230  }
1231  }
1232  }
1233 
1234  coef1 += g_len << 7;
1235  coef2 += g_len << 7;
1236  dmix_im += g_len << 7;
1237  }
1238 }
1239 
1240 static const float *complex_stereo_get_filter(ChannelElement *cpe, int is_prev)
1241 {
1242  int win, shape;
1243  if (!is_prev) {
1244  switch (cpe->ch[0].ics.window_sequence[0]) {
1245  default:
1246  case ONLY_LONG_SEQUENCE:
1247  case EIGHT_SHORT_SEQUENCE:
1248  win = 0;
1249  break;
1250  case LONG_START_SEQUENCE:
1251  win = 1;
1252  break;
1253  case LONG_STOP_SEQUENCE:
1254  win = 2;
1255  break;
1256  }
1257 
1258  if (cpe->ch[0].ics.use_kb_window[0] == 0 &&
1259  cpe->ch[0].ics.use_kb_window[1] == 0)
1260  shape = 0;
1261  else if (cpe->ch[0].ics.use_kb_window[0] == 1 &&
1262  cpe->ch[0].ics.use_kb_window[1] == 1)
1263  shape = 1;
1264  else if (cpe->ch[0].ics.use_kb_window[0] == 0 &&
1265  cpe->ch[0].ics.use_kb_window[1] == 1)
1266  shape = 2;
1267  else if (cpe->ch[0].ics.use_kb_window[0] == 1 &&
1268  cpe->ch[0].ics.use_kb_window[1] == 0)
1269  shape = 3;
1270  else
1271  shape = 3;
1272  } else {
1273  win = cpe->ch[0].ics.window_sequence[0] == LONG_STOP_SEQUENCE;
1274  shape = cpe->ch[0].ics.use_kb_window[1];
1275  }
1276 
1277  return ff_aac_usac_mdst_filt_cur[win][shape];
1278 }
1279 
1281  ChannelElement *cpe, int nb_channels)
1282 {
1283  AACUsacStereo *us = &cpe->us;
1284 
1285  for (int ch = 0; ch < nb_channels; ch++) {
1286  SingleChannelElement *sce = &cpe->ch[ch];
1287  AACUsacElemData *ue = &sce->ue;
1288 
1289  spectrum_scale(ac, sce, ue);
1290  }
1291 
1292  if (nb_channels > 1 && us->common_window) {
1293  for (int ch = 0; ch < nb_channels; ch++) {
1294  SingleChannelElement *sce = &cpe->ch[ch];
1295 
1296  /* Apply TNS, if the tns_on_lr bit is not set. */
1297  if (sce->tns.present && !us->tns_on_lr)
1298  ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1);
1299  }
1300 
1301  if (us->ms_mask_mode == 3) {
1302  const float *filt;
1303  complex_stereo_downmix_cur(ac, cpe, us->dmix_re);
1304  complex_stereo_downmix_prev(ac, cpe, us->prev_dmix_re);
1305 
1306  filt = complex_stereo_get_filter(cpe, 0);
1307  complex_stereo_interpolate_imag(us->dmix_im, us->dmix_re, filt,
1308  usac->core_frame_len, 1, 1);
1309  if (us->use_prev_frame) {
1310  filt = complex_stereo_get_filter(cpe, 1);
1311  complex_stereo_interpolate_imag(us->dmix_im, us->prev_dmix_re, filt,
1312  usac->core_frame_len, -1, 1);
1313  }
1314 
1315  apply_complex_stereo(ac, cpe);
1316  } else if (us->ms_mask_mode > 0) {
1317  ac->dsp.apply_mid_side_stereo(ac, cpe);
1318  }
1319  }
1320 
1321  /* Save coefficients and alpha values for prediction reasons */
1322  if (nb_channels > 1) {
1323  AACUsacStereo *us = &cpe->us;
1324  for (int ch = 0; ch < nb_channels; ch++) {
1325  SingleChannelElement *sce = &cpe->ch[ch];
1326  memcpy(sce->prev_coeffs, sce->coeffs, sizeof(sce->coeffs));
1327  }
1328  memcpy(us->prev_alpha_q_re, us->alpha_q_re, sizeof(us->alpha_q_re));
1329  memcpy(us->prev_alpha_q_im, us->alpha_q_im, sizeof(us->alpha_q_im));
1330  }
1331 
1332  for (int ch = 0; ch < nb_channels; ch++) {
1333  SingleChannelElement *sce = &cpe->ch[ch];
1334 
1335  /* Apply TNS, if it hasn't been applied yet. */
1336  if (sce->tns.present && ((nb_channels == 1) || (us->tns_on_lr)))
1337  ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1);
1338 
1339  ac->oc[1].m4ac.frame_length_short ? ac->dsp.imdct_and_windowing_768(ac, sce) :
1340  ac->dsp.imdct_and_windowing(ac, sce);
1341  }
1342 }
1343 
1346  GetBitContext *gb, int indep_flag, int nb_channels)
1347 {
1348  int ret;
1349  int arith_reset_flag;
1350  AACUsacStereo *us = &che->us;
1351  int core_nb_channels = nb_channels;
1352 
1353  /* Local symbols */
1354  uint8_t global_gain;
1355 
1356  us->common_window = 0;
1357 
1358  for (int ch = 0; ch < core_nb_channels; ch++) {
1359  SingleChannelElement *sce = &che->ch[ch];
1360  AACUsacElemData *ue = &sce->ue;
1361 
1362  sce->tns.present = 0;
1363  ue->tns_data_present = 0;
1364 
1365  ue->core_mode = get_bits1(gb);
1366  }
1367 
1368  if (nb_channels > 1 && ec->stereo_config_index == 1)
1369  core_nb_channels = 1;
1370 
1371  if (core_nb_channels == 2) {
1372  ret = decode_usac_stereo_info(ac, usac, ec, che, gb, indep_flag);
1373  if (ret)
1374  return ret;
1375  }
1376 
1377  for (int ch = 0; ch < core_nb_channels; ch++) {
1378  SingleChannelElement *sce = &che->ch[ch];
1379  IndividualChannelStream *ics = &sce->ics;
1380  AACUsacElemData *ue = &sce->ue;
1381 
1382  if (ue->core_mode) { /* lpd_channel_stream */
1383  ret = ff_aac_ldp_parse_channel_stream(ac, usac, ue, gb);
1384  if (ret < 0)
1385  return ret;
1386  continue;
1387  }
1388 
1389  if ((core_nb_channels == 1) ||
1390  (che->ch[0].ue.core_mode != che->ch[1].ue.core_mode))
1391  ue->tns_data_present = get_bits1(gb);
1392 
1393  /* fd_channel_stream */
1394  global_gain = get_bits(gb, 8);
1395 
1396  ue->noise.level = 0;
1397  if (ec->noise_fill) {
1398  ue->noise.level = get_bits(gb, 3);
1399  ue->noise.offset = get_bits(gb, 5);
1400  }
1401 
1402  if (!us->common_window) {
1403  /* ics_info() */
1404  ics->window_sequence[1] = ics->window_sequence[0];
1405  ics->window_sequence[0] = get_bits(gb, 2);
1406  ics->use_kb_window[1] = ics->use_kb_window[0];
1407  ics->use_kb_window[0] = get_bits1(gb);
1408  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1409  ics->max_sfb = get_bits(gb, 4);
1410  ue->scale_factor_grouping = get_bits(gb, 7);
1411  } else {
1412  ics->max_sfb = get_bits(gb, 6);
1413  }
1414 
1415  ret = setup_sce(ac, sce, usac);
1416  if (ret < 0)
1417  return ret;
1418  }
1419 
1420  if (ec->tw_mdct && !us->common_tw) {
1421  /* tw_data() */
1422  if (get_bits1(gb)) { /* tw_data_present */
1423  /* Time warping is not supported in baseline profile streams. */
1425  "AAC USAC timewarping");
1426  return AVERROR_PATCHWELCOME;
1427  }
1428  }
1429 
1430  ret = decode_usac_scale_factors(ac, sce, gb, global_gain);
1431  if (ret < 0)
1432  return ret;
1433 
1434  if (ue->tns_data_present) {
1435  sce->tns.present = 1;
1436  ret = ff_aac_decode_tns(ac, &sce->tns, gb, ics);
1437  if (ret < 0)
1438  return ret;
1439  }
1440 
1441  /* ac_spectral_data */
1442  arith_reset_flag = indep_flag;
1443  if (!arith_reset_flag)
1444  arith_reset_flag = get_bits1(gb);
1445 
1446  /* Decode coeffs */
1447  memset(&sce->coeffs[0], 0, 1024*sizeof(float));
1448  for (int win = 0; win < ics->num_windows; win++) {
1449  int lg = ics->swb_offset[ics->max_sfb];
1450  int N;
1451  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE)
1452  N = usac->core_frame_len / 8;
1453  else
1454  N = usac->core_frame_len;
1455 
1456  ret = decode_spectrum_ac(ac, sce->coeffs + win*128, gb, &ue->ac,
1457  arith_reset_flag && (win == 0), lg, N);
1458  if (ret < 0)
1459  return ret;
1460  }
1461 
1462  if (get_bits1(gb)) { /* fac_data_present */
1463  const uint16_t len_8 = usac->core_frame_len / 8;
1464  const uint16_t len_16 = usac->core_frame_len / 16;
1465  const uint16_t fac_len = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? len_16 : len_8;
1466  ret = ff_aac_parse_fac_data(ue, gb, 1, fac_len);
1467  if (ret < 0)
1468  return ret;
1469  }
1470  }
1471 
1472  if (ec->sbr.ratio) {
1473  int sbr_ch = nb_channels;
1474  if (nb_channels == 2 &&
1475  !(ec->stereo_config_index == 0 || ec->stereo_config_index == 3))
1476  sbr_ch = 1;
1477 
1478  ret = ff_aac_sbr_decode_usac_data(ac, che, ec, gb, sbr_ch, indep_flag);
1479  if (ret < 0)
1480  return ret;
1481 
1482  if (ec->stereo_config_index) {
1483  avpriv_report_missing_feature(ac->avctx, "AAC USAC Mps212");
1484  return AVERROR_PATCHWELCOME;
1485  }
1486  }
1487 
1488  spectrum_decode(ac, usac, che, core_nb_channels);
1489 
1490  if (ac->oc[1].m4ac.sbr > 0) {
1491  ac->proc.sbr_apply(ac, che, nb_channels == 2 ? TYPE_CPE : TYPE_SCE,
1492  che->ch[0].output,
1493  che->ch[1].output);
1494  }
1495 
1496  return 0;
1497 }
1498 
1500 {
1501  int ret = 0;
1502  GetBitContext gbc;
1503  OutputConfiguration *oc = &ac->oc[1];
1504  MPEG4AudioConfig *m4ac = &oc->m4ac;
1505  MPEG4AudioConfig m4ac_bak = oc->m4ac;
1506  uint8_t temp_data[512];
1507  uint8_t *tmp_buf = temp_data;
1508  size_t tmp_buf_size = sizeof(temp_data);
1509 
1510  av_unused int crossfade;
1511  int num_preroll_frames;
1512 
1513  int config_len = get_escaped_value(gb, 4, 4, 8);
1514 
1515  /* Implementations are free to pad the config to any length, so use a
1516  * different reader for this. */
1517  gbc = *gb;
1518  ret = ff_aac_usac_config_decode(ac, ac->avctx, &gbc, oc, m4ac->chan_config);
1519  if (ret < 0) {
1520  *m4ac = m4ac_bak;
1521  return ret;
1522  } else {
1523  ac->oc[1].m4ac.chan_config = 0;
1524  }
1525 
1526  /* 7.18.3.3 Bitrate adaption
1527  * If configuration didn't change after applying preroll, continue
1528  * without decoding it. */
1529  if (!memcmp(m4ac, &m4ac_bak, sizeof(m4ac_bak)))
1530  return 0;
1531 
1532  skip_bits_long(gb, config_len*8);
1533 
1534  crossfade = get_bits1(gb); /* applyCrossfade */
1535  skip_bits1(gb); /* reserved */
1536  num_preroll_frames = get_escaped_value(gb, 2, 4, 0); /* numPreRollFrames */
1537 
1538  for (int i = 0; i < num_preroll_frames; i++) {
1539  int got_frame_ptr = 0;
1540  int au_len = get_escaped_value(gb, 16, 16, 0);
1541 
1542  if (au_len*8 > tmp_buf_size) {
1543  uint8_t *tmp2;
1544  tmp_buf = tmp_buf == temp_data ? NULL : tmp_buf;
1545  tmp2 = av_realloc_array(tmp_buf, au_len, 8);
1546  if (!tmp2) {
1547  if (tmp_buf != temp_data)
1548  av_free(tmp_buf);
1549  return AVERROR(ENOMEM);
1550  }
1551  tmp_buf = tmp2;
1552  }
1553 
1554  /* Byte alignment is not guaranteed. */
1555  for (int i = 0; i < au_len; i++)
1556  tmp_buf[i] = get_bits(gb, 8);
1557 
1558  ret = init_get_bits8(&gbc, tmp_buf, au_len);
1559  if (ret < 0)
1560  break;
1561 
1562  ret = ff_aac_usac_decode_frame(ac->avctx, ac, &gbc, &got_frame_ptr);
1563  if (ret < 0)
1564  break;
1565  }
1566 
1567  if (tmp_buf != temp_data)
1568  av_free(tmp_buf);
1569 
1570  return 0;
1571 }
1572 
1574  GetBitContext *gb)
1575 {
1576  uint8_t *tmp;
1577  uint8_t pl_frag_start = 1;
1578  uint8_t pl_frag_end = 1;
1579  uint32_t len;
1580 
1581  if (!get_bits1(gb)) /* usacExtElementPresent */
1582  return 0;
1583 
1584  if (get_bits1(gb)) { /* usacExtElementUseDefaultLength */
1585  len = e->ext.default_len;
1586  } else {
1587  len = get_bits(gb, 8); /* usacExtElementPayloadLength */
1588  if (len == 255)
1589  len += get_bits(gb, 16) - 2;
1590  }
1591 
1592  if (!len)
1593  return 0;
1594 
1595  if (e->ext.payload_frag) {
1596  pl_frag_start = get_bits1(gb); /* usacExtElementStart */
1597  pl_frag_end = get_bits1(gb); /* usacExtElementStop */
1598  }
1599 
1600  if (pl_frag_start)
1601  e->ext.pl_data_offset = 0;
1602 
1603  /* If an extension starts and ends this packet, we can directly use it */
1604  if (!(pl_frag_start && pl_frag_end)) {
1606  if (!tmp) {
1607  av_free(e->ext.pl_data);
1608  return AVERROR(ENOMEM);
1609  }
1610  e->ext.pl_data = tmp;
1611 
1612  /* Readout data to a buffer */
1613  for (int i = 0; i < len; i++)
1614  e->ext.pl_data[e->ext.pl_data_offset + i] = get_bits(gb, 8);
1615  }
1616 
1617  e->ext.pl_data_offset += len;
1618 
1619  if (pl_frag_end) {
1620  int ret = 0;
1621  int start_bits = get_bits_count(gb);
1622  const int pl_len = e->ext.pl_data_offset;
1623  GetBitContext *gb2 = gb;
1624  GetBitContext gbc;
1625  if (!(pl_frag_start && pl_frag_end)) {
1626  ret = init_get_bits8(&gbc, e->ext.pl_data, pl_len);
1627  if (ret < 0)
1628  return ret;
1629 
1630  gb2 = &gbc;
1631  }
1632 
1633  switch (e->ext.type) {
1634  case ID_EXT_ELE_FILL:
1635  /* Filler elements have no usable payload */
1636  break;
1638  ret = parse_audio_preroll(ac, gb2);
1639  break;
1640  default:
1641  /* This should never happen */
1642  av_assert0(0);
1643  }
1644  av_freep(&e->ext.pl_data);
1645  if (ret < 0)
1646  return ret;
1647 
1648  skip_bits_long(gb, pl_len*8 - (get_bits_count(gb) - start_bits));
1649  }
1650 
1651  return 0;
1652 }
1653 
1655  GetBitContext *gb, int *got_frame_ptr)
1656 {
1657  int ret, is_dmono = 0;
1658  int indep_flag, samples = 0;
1659  int audio_found = 0;
1660  int elem_id[3 /* SCE, CPE, LFE */] = { 0, 0, 0 };
1661  AVFrame *frame = ac->frame;
1662 
1663  int ratio_mult, ratio_dec;
1664  AACUSACConfig *usac = &ac->oc[1].usac;
1665  int sbr_ratio = usac->core_sbr_frame_len_idx == 2 ? 2 :
1666  usac->core_sbr_frame_len_idx == 3 ? 3 :
1667  usac->core_sbr_frame_len_idx == 4 ? 1 :
1668  0;
1669 
1670  if (sbr_ratio == 2) {
1671  ratio_mult = 8;
1672  ratio_dec = 3;
1673  } else if (sbr_ratio == 3) {
1674  ratio_mult = 2;
1675  ratio_dec = 1;
1676  } else if (sbr_ratio == 4) {
1677  ratio_mult = 4;
1678  ratio_dec = 1;
1679  } else {
1680  ratio_mult = 1;
1681  ratio_dec = 1;
1682  }
1683 
1685  ac->oc[1].status, 0);
1686 
1688 
1689  indep_flag = get_bits1(gb);
1690 
1691  for (int i = 0; i < ac->oc[1].usac.nb_elems; i++) {
1692  int layout_id;
1693  int layout_type;
1694  AACUsacElemConfig *e = &ac->oc[1].usac.elems[i];
1695  ChannelElement *che;
1696 
1697  if (e->type == ID_USAC_SCE) {
1698  layout_id = elem_id[0]++;
1699  layout_type = TYPE_SCE;
1700  che = ff_aac_get_che(ac, TYPE_SCE, layout_id);
1701  } else if (e->type == ID_USAC_CPE) {
1702  layout_id = elem_id[1]++;
1703  layout_type = TYPE_CPE;
1704  che = ff_aac_get_che(ac, TYPE_CPE, layout_id);
1705  } else if (e->type == ID_USAC_LFE) {
1706  layout_id = elem_id[2]++;
1707  layout_type = TYPE_LFE;
1708  che = ff_aac_get_che(ac, TYPE_LFE, layout_id);
1709  }
1710 
1711  if (e->type != ID_USAC_EXT && !che) {
1712  av_log(ac->avctx, AV_LOG_ERROR,
1713  "channel element %d.%d is not allocated\n",
1714  layout_type, layout_id);
1715  return AVERROR_INVALIDDATA;
1716  }
1717 
1718  switch (e->type) {
1719  case ID_USAC_LFE:
1720  /* Fallthrough */
1721  case ID_USAC_SCE:
1722  ret = decode_usac_core_coder(ac, &ac->oc[1].usac, e, che, gb,
1723  indep_flag, 1);
1724  if (ret < 0)
1725  return ret;
1726 
1727  audio_found = 1;
1728  che->present = 1;
1729  break;
1730  case ID_USAC_CPE:
1731  ret = decode_usac_core_coder(ac, &ac->oc[1].usac, e, che, gb,
1732  indep_flag, 2);
1733  if (ret < 0)
1734  return ret;
1735 
1736  audio_found = 1;
1737  che->present = 1;
1738  break;
1739  case ID_USAC_EXT:
1740  ret = parse_ext_ele(ac, e, gb);
1741  if (ret < 0)
1742  return ret;
1743  break;
1744  }
1745  }
1746 
1747  if (audio_found)
1748  samples = ac->oc[1].m4ac.frame_length_short ? 768 : 1024;
1749 
1750  samples = (samples * ratio_mult) / ratio_dec;
1751 
1752  if (ac->oc[1].status && audio_found) {
1753  avctx->sample_rate = ac->oc[1].m4ac.ext_sample_rate;
1754  avctx->frame_size = samples;
1755  ac->oc[1].status = OC_LOCKED;
1756  }
1757 
1758  if (!frame->data[0] && samples) {
1759  av_log(avctx, AV_LOG_ERROR, "no frame data found\n");
1760  return AVERROR_INVALIDDATA;
1761  }
1762 
1763  if (samples) {
1764  frame->nb_samples = samples;
1765  frame->sample_rate = avctx->sample_rate;
1766  frame->flags = indep_flag ? AV_FRAME_FLAG_KEY : 0x0;
1767  *got_frame_ptr = 1;
1768  } else {
1769  av_frame_unref(ac->frame);
1770  frame->flags = indep_flag ? AV_FRAME_FLAG_KEY : 0x0;
1771  *got_frame_ptr = 0;
1772  }
1773 
1774  /* for dual-mono audio (SCE + SCE) */
1775  is_dmono = ac->dmono_mode && elem_id[0] == 2 &&
1778  if (is_dmono) {
1779  if (ac->dmono_mode == 1)
1780  frame->data[1] = frame->data[0];
1781  else if (ac->dmono_mode == 2)
1782  frame->data[0] = frame->data[1];
1783  }
1784 
1785  return 0;
1786 }
MAX_ELEM_ID
#define MAX_ELEM_ID
Definition: aac.h:34
AACUsacElemConfig::stereo_config_index
uint8_t stereo_config_index
Definition: aacdec.h:303
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1091
ff_usac_noise_fill_start_offset
const uint8_t ff_usac_noise_fill_start_offset[2][2]
Definition: aactab.c:2009
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:261
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
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:842
aacdec_ac.h
AACUSACConfig
Definition: aacdec.h:351
ID_EXT_ELE_SAOC
@ ID_EXT_ELE_SAOC
Definition: aacdec.h:90
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:1064
AACUSACConfig::stream_identifier
uint16_t stream_identifier
Definition: aacdec.h:354
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:360
spectrum_decode
static void spectrum_decode(AACDecContext *ac, AACUSACConfig *usac, ChannelElement *cpe, int nb_channels)
Definition: aacdec_usac.c:1280
AACUsacElemConfig::payload_frag
uint8_t payload_frag
Definition: aacdec.h:344
AACUsacElemConfig::sbr
struct AACUsacElemConfig::@24 sbr
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:334
AV_CHAN_WIDE_LEFT
@ AV_CHAN_WIDE_LEFT
Definition: channel_layout.h:72
ID_USAC_LFE
@ ID_USAC_LFE
Definition: aacdec.h:77
ff_aac_ac_lsb_cdfs
const uint16_t ff_aac_ac_lsb_cdfs[3][4]
Definition: aactab.c:1335
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:249
AVChannelLayout::map
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
Definition: channel_layout.h:370
av_unused
#define av_unused
Definition: attributes.h:131
AACUsacElemConfig::tw_mdct
uint8_t tw_mdct
Definition: aacdec.h:300
aacsbr.h
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AV_CHAN_TOP_SURROUND_LEFT
@ AV_CHAN_TOP_SURROUND_LEFT
+110 degrees, Lvs, TpLS
Definition: channel_layout.h:84
complex_stereo_downmix_cur
static void complex_stereo_downmix_cur(AACDecContext *ac, ChannelElement *cpe, float *dmix_re)
Definition: aacdec_usac.c:1094
b
#define b
Definition: input.c:41
aacdec_usac.h
TemporalNoiseShaping::present
int present
Definition: aacdec.h:185
AACUsacElemData::scale_factor_grouping
uint8_t scale_factor_grouping
Definition: aacdec.h:127
AACUSACConfig::nb_info
uint8_t nb_info
Definition: aacdec.h:362
AACDecDSP::apply_tns
void(* apply_tns)(void *_coef_param, TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
Definition: aacdec.h:421
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AACDecContext::proc
AACDecProc proc
Definition: aacdec.h:453
AACUsacElemConfig::bs_pvc
uint8_t bs_pvc
Definition: aacdec.h:310
c1
static const uint64_t c1
Definition: murmur3.c:52
AACUsacStereo::pred_dir
uint8_t pred_dir
Definition: aacdec.h:242
AACUsacElemData::tns_data_present
uint8_t tns_data_present
Definition: aacdec.h:128
ChannelElement::ch
SingleChannelElement ch[2]
Definition: aacdec.h:266
ff_aac_sample_rate_idx
static int ff_aac_sample_rate_idx(int rate)
Definition: aac.h:106
ff_swb_offset_128
const uint16_t *const ff_swb_offset_128[]
Definition: aactab.c:1950
ChannelElement::present
int present
Definition: aacdec.h:261
ID_CONFIG_EXT_STREAM_ID
@ ID_CONFIG_EXT_STREAM_ID
Definition: aacdec.h:84
ID_USAC_EXT
@ ID_USAC_EXT
Definition: aacdec.h:78
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:522
MPEG4AudioConfig
Definition: mpeg4audio.h:29
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:364
AACUsacElemConfig::pseudo_lr
uint8_t pseudo_lr
Definition: aacdec.h:338
IndividualChannelStream::num_swb
int num_swb
number of scalefactor window bands
Definition: aacdec.h:171
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:318
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:119
AACUsacElemData::core_mode
uint8_t core_mode
Definition: aacdec.h:126
mpeg4audio.h
AACArith
Definition: aacdec_ac.h:34
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1079
AV_CHAN_TOP_BACK_RIGHT
@ AV_CHAN_TOP_BACK_RIGHT
Definition: channel_layout.h:67
AACUsacElemConfig::dflt
struct AACUsacElemConfig::@24::@27 dflt
parse_ext_ele
static int parse_ext_ele(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:1573
ID_EXT_ELE_AUDIOPREROLL
@ ID_EXT_ELE_AUDIOPREROLL
Definition: aacdec.h:91
TYPE_CPE
@ TYPE_CPE
Definition: aac.h:41
SFB_PER_PRED_BAND
#define SFB_PER_PRED_BAND
Definition: aacdec_usac.c:34
GetBitContext
Definition: get_bits.h:108
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:593
ue
#define ue(name, range_min, range_max)
Definition: cbs_h2645.c:254
AACUsacElemConfig::high_rate_mode
uint8_t high_rate_mode
Definition: aacdec.h:332
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AACDecProc::sbr_apply
void(* sbr_apply)(AACDecContext *ac, ChannelElement *che, int id_aac, void *L, void *R)
Definition: aacdec.h:406
OutputConfiguration::status
enum OCStatus status
Definition: aacdec.h:372
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
us
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:263
AACUsacElemConfig::freq_res
uint8_t freq_res
Definition: aacdec.h:328
SingleChannelElement::ics
IndividualChannelStream ics
Definition: aacdec.h:211
AACUSACConfig::elems
AACUsacElemConfig elems[64]
Definition: aacdec.h:356
cbrt
#define cbrt
Definition: tablegen.h:35
AACUsacElemConfig::pl_data_offset
uint32_t pl_data_offset
Definition: aacdec.h:346
ID_CONFIG_EXT_FILL
@ ID_CONFIG_EXT_FILL
Definition: aacdec.h:82
AACUsacElemConfig
Definition: aacdec.h:297
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:1134
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:209
AACUsacElemConfig::ext
struct AACUsacElemConfig::@26 ext
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AACDecDSP::dequant_scalefactors
void(* dequant_scalefactors)(SingleChannelElement *sce)
Definition: aacdec.h:415
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:528
AACUsacElemConfig::residual_bands
uint8_t residual_bands
Definition: aacdec.h:337
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:661
OC_GLOBAL_HDR
@ OC_GLOBAL_HDR
Output configuration set in a global header but not yet locked.
Definition: aacdec.h:56
s
#define s(width, name)
Definition: cbs_vp9.c:198
AACUsacElemConfig::harmonic_sbr
uint8_t harmonic_sbr
Definition: aacdec.h:308
AACDecDSP::apply_mid_side_stereo
void(* apply_mid_side_stereo)(AACDecContext *ac, ChannelElement *cpe)
Definition: aacdec.h:417
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:199
g
const char * g
Definition: vf_curves.c:128
EIGHT_SHORT_SEQUENCE
@ EIGHT_SHORT_SEQUENCE
Definition: aac.h:62
info
MIPS optimizations info
Definition: mips.txt:2
AACUsacElemConfig::pl_data
uint8_t * pl_data
Definition: aacdec.h:347
decode_usac_scale_factors
static int decode_usac_scale_factors(AACDecContext *ac, SingleChannelElement *sce, GetBitContext *gb, uint8_t global_gain)
Definition: aacdec_usac.c:560
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:40
ff_aac_get_che
ChannelElement * ff_aac_get_che(AACDecContext *ac, int type, int elem_id)
Definition: aacdec.c:592
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
AACUsacElemData
Definition: aacdec.h:125
AACUSACConfig::core_sbr_frame_len_idx
uint8_t core_sbr_frame_len_idx
Definition: aacdec.h:352
IndividualChannelStream
Individual Channel Stream.
Definition: aacdec.h:162
UNIDRCLOUDEXT_TERM
@ UNIDRCLOUDEXT_TERM
Definition: aacdec.h:96
ID_USAC_CPE
@ ID_USAC_CPE
Definition: aacdec.h:76
SCALE_DIFF_ZERO
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
Definition: aac.h:91
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:1988
AACDecContext::fdsp
AVFloatDSPContext * fdsp
Definition: aacdec.h:504
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:1654
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:106
decode_loudness_info
static int decode_loudness_info(AACDecContext *ac, AACUSACLoudnessInfo *info, GetBitContext *gb)
Definition: aacdec_usac.c:85
AV_CHAN_SIDE_SURROUND_LEFT
@ AV_CHAN_SIDE_SURROUND_LEFT
+90 degrees, Lss, SiL
Definition: channel_layout.h:82
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:148
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AACUsacElemData::seed
unsigned int seed
Definition: aacdec.h:146
AACUSACConfig::core_frame_len
uint16_t core_frame_len
Definition: aacdec.h:353
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:165
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:166
ff_tns_max_bands_usac_128
const uint8_t ff_tns_max_bands_usac_128[]
Definition: aactab.c:2004
AACUSACConfig::loudness
struct AACUSACConfig::@28 loudness
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
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:371
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:264
parse_audio_preroll
static int parse_audio_preroll(AACDecContext *ac, GetBitContext *gb)
Definition: aacdec_usac.c:1499
get_escaped_value
static uint32_t get_escaped_value(GetBitContext *gb, int nb1, int nb2, int nb3)
Definition: aacdec_usac.c:36
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:301
AV_CHAN_TOP_CENTER
@ AV_CHAN_TOP_CENTER
Definition: channel_layout.h:61
AAC_CHANNEL_FRONT
@ AAC_CHANNEL_FRONT
Definition: aac.h:78
AACUsacElemConfig::temp_shape_config
uint8_t temp_shape_config
Definition: aacdec.h:330
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:635
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:688
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:113
spectrum_scale
static void spectrum_scale(AACDecContext *ac, SingleChannelElement *sce, AACUsacElemData *ue)
Definition: aacdec_usac.c:1033
AACUsacStereo
Definition: aacdec.h:232
OC_LOCKED
@ OC_LOCKED
Output configuration locked in place.
Definition: aacdec.h:57
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:167
get_unary
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
AACUsacElemConfig::default_len
uint32_t default_len
Definition: aacdec.h:345
OutputConfiguration::layout_map_tags
int layout_map_tags
Definition: aacdec.h:370
SingleChannelElement::ue
AACUsacElemData ue
USAC element data.
Definition: aacdec.h:212
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:369
AACUsacElemConfig::bs_intertes
uint8_t bs_intertes
Definition: aacdec.h:309
IndividualChannelStream::window_sequence
enum WindowSequence window_sequence[2]
Definition: aacdec.h:164
AACDecContext::dsp
AACDecDSP dsp
Definition: aacdec.h:452
f
f
Definition: af_crystalizer.c:122
ff_swb_offset_1024
const uint16_t *const ff_swb_offset_1024[]
Definition: aactab.c:1910
powf
#define powf(x, y)
Definition: libm.h:50
state
static struct @474 state
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:60
AACDecDSP::imdct_and_windowing
void(* imdct_and_windowing)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:436
ChannelElement::max_sfb_ste
uint8_t max_sfb_ste
(USAC) Maximum of both max_sfb values
Definition: aacdec.h:263
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:69
SingleChannelElement::sfo
int sfo[128]
scalefactor offsets
Definition: aacdec.h:215
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:270
OutputConfiguration
Definition: aacdec.h:367
ff_aac_usac_mdst_filt_cur
const float ff_aac_usac_mdst_filt_cur[4][4][7]
Definition: aactab.c:3920
AACUsacElemConfig::mps
struct AACUsacElemConfig::@25 mps
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:885
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:396
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
SingleChannelElement::band_type
enum BandType band_type[128]
band types
Definition: aacdec.h:214
AACUsacElemConfig::fixed_gain
uint8_t fixed_gain
Definition: aacdec.h:329
ID_CONFIG_EXT_LOUDNESS_INFO
@ ID_CONFIG_EXT_LOUDNESS_INFO
Definition: aacdec.h:83
unary.h
SingleChannelElement::output
float * output
PCM output.
Definition: aacdec.h:227
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:809
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:232
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:992
AV_CHAN_TOP_SURROUND_RIGHT
@ AV_CHAN_TOP_SURROUND_RIGHT
-110 degrees, Rvs, TpRS
Definition: channel_layout.h:85
RawDataBlockType
RawDataBlockType
Definition: aac.h:39
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:210
ff_swb_offset_768
const uint16_t *const ff_swb_offset_768[]
Definition: aactab.c:1926
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
decode_usac_element_pair
static int decode_usac_element_pair(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:202
IndividualChannelStream::num_windows
int num_windows
Definition: aacdec.h:172
OutputConfiguration::usac
AACUSACConfig usac
Definition: aacdec.h:373
LONG_STOP_SEQUENCE
@ LONG_STOP_SEQUENCE
Definition: aac.h:63
usac_ch_pos_to_av
static enum AVChannel usac_ch_pos_to_av[64]
Definition: aacdec_usac.c:50
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aacdec.h:260
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:170
ff_aac_parse_fac_data
int ff_aac_parse_fac_data(AACUsacElemData *ce, GetBitContext *gb, int use_gain, int len)
Definition: aacdec_lpd.c:129
ff_aac_usac_samplerate
const int ff_aac_usac_samplerate[32]
Definition: aactab.c:3912
AACUsacElemConfig::type
enum AACUsacElem type
Definition: aacdec.h:298
TYPE_LFE
@ TYPE_LFE
Definition: aac.h:43
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:623
complex_stereo_get_filter
static const float * complex_stereo_get_filter(ChannelElement *cpe, int is_prev)
Definition: aacdec_usac.c:1240
MPEG4AudioConfig::chan_config
int chan_config
Definition: mpeg4audio.h:33
AACUsacElemConfig::decorr_config
uint8_t decorr_config
Definition: aacdec.h:331
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:40
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:1063
AACDecContext::oc
OutputConfiguration oc[2]
Definition: aacdec.h:527
MPEG4AudioConfig::ext_sample_rate
int ext_sample_rate
Definition: mpeg4audio.h:37
IndividualChannelStream::tns_max_bands
int tns_max_bands
Definition: aacdec.h:173
ff_aac_num_swb_96
const uint8_t ff_aac_num_swb_96[]
Definition: aactab.c:177
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:357
ID_EXT_ELE_UNI_DRC
@ ID_EXT_ELE_UNI_DRC
Definition: aacdec.h:92
AAC_CHANNEL_LFE
@ AAC_CHANNEL_LFE
Definition: aac.h:81
decode_usac_sbr_data
static int decode_usac_sbr_data(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:150
ret
ret
Definition: filter_design.txt:187
ff_aac_num_swb_1024
const uint8_t ff_aac_num_swb_1024[]
Definition: aactab.c:149
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:264
AACDecContext::frame
struct AVFrame * frame
Definition: aacdec.h:455
decode_usac_element_core
static void decode_usac_element_core(AACUsacElemConfig *e, GetBitContext *gb, int sbr_ratio)
Definition: aacdec_usac.c:193
LONG_START_SEQUENCE
@ LONG_START_SEQUENCE
Definition: aac.h:61
UNIDRCLOUDEXT_EQ
@ UNIDRCLOUDEXT_EQ
Definition: aacdec.h:97
id
enum AVCodecID id
Definition: dts2pts.c:367
aacdec_lpd.h
AV_CHAN_BACK_CENTER
@ AV_CHAN_BACK_CENTER
Definition: channel_layout.h:58
SingleChannelElement::tns
TemporalNoiseShaping tns
Definition: aacdec.h:213
U
#define U(x)
Definition: vpx_arith.h:37
AACDecContext
main AAC decoding context
Definition: aacdec.h:448
AACUSACConfig::info
AACUSACLoudnessInfo info[64]
Definition: aacdec.h:363
AVCodecContext
main external API structure.
Definition: avcodec.h:451
c2
static const uint64_t c2
Definition: murmur3.c:53
AV_CHAN_LOW_FREQUENCY_2
@ AV_CHAN_LOW_FREQUENCY_2
Definition: channel_layout.h:76
AACDecContext::avctx
struct AVCodecContext * avctx
Definition: aacdec.h:450
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:984
apply_complex_stereo
static void apply_complex_stereo(AACDecContext *ac, ChannelElement *cpe)
Definition: aacdec_usac.c:1188
aacdec_tab.h
setup_sce
static int setup_sce(AACDecContext *ac, SingleChannelElement *sce, AACUSACConfig *usac)
Definition: aacdec_usac.c:779
AACUSACLoudnessInfo
Definition: aacdec.h:273
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1658
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:442
cm
#define cm
Definition: dvbsubdec.c:40
AACUsacElemConfig::env_quant_mode
uint8_t env_quant_mode
Definition: aacdec.h:339
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:1559
ff_aac_usac_reset_state
int ff_aac_usac_reset_state(AACDecContext *ac, OutputConfiguration *oc)
Definition: aacdec_usac.c:275
AV_CHAN_BOTTOM_FRONT_CENTER
@ AV_CHAN_BOTTOM_FRONT_CENTER
Definition: channel_layout.h:79
AACUsacElemConfig::ratio
int ratio
Definition: aacdec.h:306
decode_loudness_set
static int decode_loudness_set(AACDecContext *ac, AACUSACConfig *usac, GetBitContext *gb)
Definition: aacdec_usac.c:111
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:449
OutputConfiguration::m4ac
MPEG4AudioConfig m4ac
Definition: aacdec.h:368
AV_CHAN_TOP_FRONT_CENTER
@ AV_CHAN_TOP_FRONT_CENTER
Definition: channel_layout.h:63
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:371
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:1344
AACDecDSP::imdct_and_windowing_768
void(* imdct_and_windowing_768)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:437
MPEG4AudioConfig::frame_length_short
int frame_length_short
Definition: mpeg4audio.h:41
ID_EXT_ELE_MPEGS
@ ID_EXT_ELE_MPEGS
Definition: aacdec.h:89
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
ff_aac_ac_msb_cdfs
const uint16_t ff_aac_ac_msb_cdfs[64][17]
Definition: aactab.c:1204
ff_vlc_scalefactors
VLCElem ff_vlc_scalefactors[352]
Definition: aacdec_tab.c:111
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_CHAN_TOP_FRONT_LEFT
@ AV_CHAN_TOP_FRONT_LEFT
Definition: channel_layout.h:62
AVChannelLayout::u
union AVChannelLayout::@434 u
Details about which channels are present in this layout.
AACUsacElemData::noise
struct AACUsacElemData::@15 noise
IndividualChannelStream::max_sfb
uint8_t max_sfb
number of scalefactor bands per group
Definition: aacdec.h:163
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
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:552
AACArithState
Definition: aacdec_ac.h:27
AACUsacElemConfig::residual_coding
uint8_t residual_coding
Definition: aacdec.h:336
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:335
AACUSACLoudnessExt
AACUSACLoudnessExt
Definition: aacdec.h:95
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aacdec.h:168
ff_aac_num_swb_768
const uint8_t ff_aac_num_swb_768[]
Definition: aactab.c:157
AV_PROFILE_AAC_USAC
#define AV_PROFILE_AAC_USAC
Definition: defs.h:76
AACUsacElemConfig::phase_coding
uint8_t phase_coding
Definition: aacdec.h:333
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:459
ID_EXT_ELE_FILL
@ ID_EXT_ELE_FILL
Definition: aacdec.h:88
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:155
AACUSACConfig::album_info
AACUSACLoudnessInfo album_info[64]
Definition: aacdec.h:361
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:1968
decode_usac_extension
static int decode_usac_extension(AACDecContext *ac, AACUsacElemConfig *e, GetBitContext *gb)
Definition: aacdec_usac.c:236
ID_USAC_SCE
@ ID_USAC_SCE
Definition: aacdec.h:75