FFmpeg
aacdec_template.c
Go to the documentation of this file.
1 /*
2  * AAC decoder
3  * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
4  * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
5  * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com>
6  *
7  * AAC LATM decoder
8  * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
9  * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net>
10  *
11  * AAC decoder fixed-point implementation
12  * Copyright (c) 2013
13  * MIPS Technologies, Inc., California.
14  *
15  * This file is part of FFmpeg.
16  *
17  * FFmpeg is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  *
22  * FFmpeg is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  * Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with FFmpeg; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31 
32 /**
33  * @file
34  * AAC decoder
35  * @author Oded Shimon ( ods15 ods15 dyndns org )
36  * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
37  *
38  * AAC decoder fixed-point implementation
39  * @author Stanislav Ocovaj ( stanislav.ocovaj imgtec com )
40  * @author Nedeljko Babic ( nedeljko.babic imgtec com )
41  */
42 
43 /*
44  * supported tools
45  *
46  * Support? Name
47  * N (code in SoC repo) gain control
48  * Y block switching
49  * Y window shapes - standard
50  * N window shapes - Low Delay
51  * Y filterbank - standard
52  * N (code in SoC repo) filterbank - Scalable Sample Rate
53  * Y Temporal Noise Shaping
54  * Y Long Term Prediction
55  * Y intensity stereo
56  * Y channel coupling
57  * Y frequency domain prediction
58  * Y Perceptual Noise Substitution
59  * Y Mid/Side stereo
60  * N Scalable Inverse AAC Quantization
61  * N Frequency Selective Switch
62  * N upsampling filter
63  * Y quantization & coding - AAC
64  * N quantization & coding - TwinVQ
65  * N quantization & coding - BSAC
66  * N AAC Error Resilience tools
67  * N Error Resilience payload syntax
68  * N Error Protection tool
69  * N CELP
70  * N Silence Compression
71  * N HVXC
72  * N HVXC 4kbits/s VR
73  * N Structured Audio tools
74  * N Structured Audio Sample Bank Format
75  * N MIDI
76  * N Harmonic and Individual Lines plus Noise
77  * N Text-To-Speech Interface
78  * Y Spectral Band Replication
79  * Y (not in this code) Layer-1
80  * Y (not in this code) Layer-2
81  * Y (not in this code) Layer-3
82  * N SinuSoidal Coding (Transient, Sinusoid, Noise)
83  * Y Parametric Stereo
84  * N Direct Stream Transfer
85  * Y (not in fixed point code) Enhanced AAC Low Delay (ER AAC ELD)
86  *
87  * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication.
88  * - HE AAC v2 comprises LC AAC with Spectral Band Replication and
89  Parametric Stereo.
90  */
91 
93 #include "libavutil/thread.h"
94 #include "internal.h"
95 
97 static VLC vlc_spectral[11];
98 
99 static int output_configure(AACContext *ac,
100  uint8_t layout_map[MAX_ELEM_ID*4][3], int tags,
101  enum OCStatus oc_type, int get_new_frame);
102 
103 #define overread_err "Input buffer exhausted before END element found\n"
104 
105 static int count_channels(uint8_t (*layout)[3], int tags)
106 {
107  int i, sum = 0;
108  for (i = 0; i < tags; i++) {
109  int syn_ele = layout[i][0];
110  int pos = layout[i][2];
111  sum += (1 + (syn_ele == TYPE_CPE)) *
113  }
114  return sum;
115 }
116 
117 /**
118  * Check for the channel element in the current channel position configuration.
119  * If it exists, make sure the appropriate element is allocated and map the
120  * channel order to match the internal FFmpeg channel layout.
121  *
122  * @param che_pos current channel position configuration
123  * @param type channel element type
124  * @param id channel element id
125  * @param channels count of the number of channels in the configuration
126  *
127  * @return Returns error status. 0 - OK, !0 - error
128  */
130  enum ChannelPosition che_pos,
131  int type, int id, int *channels)
132 {
133  if (*channels >= MAX_CHANNELS)
134  return AVERROR_INVALIDDATA;
135  if (che_pos) {
136  if (!ac->che[type][id]) {
137  if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement))))
138  return AVERROR(ENOMEM);
140  }
141  if (type != TYPE_CCE) {
142  if (*channels >= MAX_CHANNELS - (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))) {
143  av_log(ac->avctx, AV_LOG_ERROR, "Too many channels\n");
144  return AVERROR_INVALIDDATA;
145  }
146  ac->output_element[(*channels)++] = &ac->che[type][id]->ch[0];
147  if (type == TYPE_CPE ||
148  (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1)) {
149  ac->output_element[(*channels)++] = &ac->che[type][id]->ch[1];
150  }
151  }
152  } else {
153  if (ac->che[type][id])
155  av_freep(&ac->che[type][id]);
156  }
157  return 0;
158 }
159 
161 {
162  AACContext *ac = avctx->priv_data;
163  int type, id, ch, ret;
164 
165  /* set channel pointers to internal buffers by default */
166  for (type = 0; type < 4; type++) {
167  for (id = 0; id < MAX_ELEM_ID; id++) {
168  ChannelElement *che = ac->che[type][id];
169  if (che) {
170  che->ch[0].ret = che->ch[0].ret_buf;
171  che->ch[1].ret = che->ch[1].ret_buf;
172  }
173  }
174  }
175 
176  /* get output buffer */
177  av_frame_unref(ac->frame);
178  if (!avctx->ch_layout.nb_channels)
179  return 1;
180 
181  ac->frame->nb_samples = 2048;
182  if ((ret = ff_get_buffer(avctx, ac->frame, 0)) < 0)
183  return ret;
184 
185  /* map output channel pointers to AVFrame data */
186  for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
187  if (ac->output_element[ch])
188  ac->output_element[ch]->ret = (INTFLOAT *)ac->frame->extended_data[ch];
189  }
190 
191  return 0;
192 }
193 
195  uint64_t av_position;
196  uint8_t syn_ele;
197  uint8_t elem_id;
198  uint8_t aac_position;
199 };
200 
201 static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID],
202  uint8_t (*layout_map)[3], int offset, uint64_t left,
203  uint64_t right, int pos, uint64_t *layout)
204 {
205  if (layout_map[offset][0] == TYPE_CPE) {
206  e2c_vec[offset] = (struct elem_to_channel) {
207  .av_position = left | right,
208  .syn_ele = TYPE_CPE,
209  .elem_id = layout_map[offset][1],
210  .aac_position = pos
211  };
212  if (e2c_vec[offset].av_position != UINT64_MAX)
213  *layout |= e2c_vec[offset].av_position;
214 
215  return 1;
216  } else {
217  e2c_vec[offset] = (struct elem_to_channel) {
218  .av_position = left,
219  .syn_ele = TYPE_SCE,
220  .elem_id = layout_map[offset][1],
221  .aac_position = pos
222  };
223  e2c_vec[offset + 1] = (struct elem_to_channel) {
224  .av_position = right,
225  .syn_ele = TYPE_SCE,
226  .elem_id = layout_map[offset + 1][1],
227  .aac_position = pos
228  };
229  if (left != UINT64_MAX)
230  *layout |= left;
231 
232  if (right != UINT64_MAX)
233  *layout |= right;
234 
235  return 2;
236  }
237 }
238 
239 static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos,
240  int *current)
241 {
242  int num_pos_channels = 0;
243  int first_cpe = 0;
244  int sce_parity = 0;
245  int i;
246  for (i = *current; i < tags; i++) {
247  if (layout_map[i][2] != pos)
248  break;
249  if (layout_map[i][0] == TYPE_CPE) {
250  if (sce_parity) {
251  if (pos == AAC_CHANNEL_FRONT && !first_cpe) {
252  sce_parity = 0;
253  } else {
254  return -1;
255  }
256  }
257  num_pos_channels += 2;
258  first_cpe = 1;
259  } else {
260  num_pos_channels++;
261  sce_parity ^= 1;
262  }
263  }
264  if (sce_parity &&
265  ((pos == AAC_CHANNEL_FRONT && first_cpe) || pos == AAC_CHANNEL_SIDE))
266  return -1;
267  *current = i;
268  return num_pos_channels;
269 }
270 
271 #define PREFIX_FOR_22POINT2 (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_LOW_FREQUENCY_2)
272 static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
273 {
274  int i, n, total_non_cc_elements;
275  struct elem_to_channel e2c_vec[4 * MAX_ELEM_ID] = { { 0 } };
276  int num_front_channels, num_side_channels, num_back_channels;
277  uint64_t layout = 0;
278 
279  if (FF_ARRAY_ELEMS(e2c_vec) < tags)
280  return 0;
281 
282  i = 0;
283  num_front_channels =
284  count_paired_channels(layout_map, tags, AAC_CHANNEL_FRONT, &i);
285  if (num_front_channels < 0)
286  return 0;
287  num_side_channels =
288  count_paired_channels(layout_map, tags, AAC_CHANNEL_SIDE, &i);
289  if (num_side_channels < 0)
290  return 0;
291  num_back_channels =
292  count_paired_channels(layout_map, tags, AAC_CHANNEL_BACK, &i);
293  if (num_back_channels < 0)
294  return 0;
295 
296  if (num_side_channels == 0 && num_back_channels >= 4) {
297  num_side_channels = 2;
298  num_back_channels -= 2;
299  }
300 
301  i = 0;
302  if (num_front_channels & 1) {
303  e2c_vec[i] = (struct elem_to_channel) {
305  .syn_ele = TYPE_SCE,
306  .elem_id = layout_map[i][1],
307  .aac_position = AAC_CHANNEL_FRONT
308  };
309  layout |= e2c_vec[i].av_position;
310  i++;
311  num_front_channels--;
312  }
313  if (num_front_channels >= 4) {
314  i += assign_pair(e2c_vec, layout_map, i,
318  num_front_channels -= 2;
319  }
320  if (num_front_channels >= 2) {
321  i += assign_pair(e2c_vec, layout_map, i,
325  num_front_channels -= 2;
326  }
327  while (num_front_channels >= 2) {
328  i += assign_pair(e2c_vec, layout_map, i,
329  UINT64_MAX,
330  UINT64_MAX,
332  num_front_channels -= 2;
333  }
334 
335  if (num_side_channels >= 2) {
336  i += assign_pair(e2c_vec, layout_map, i,
340  num_side_channels -= 2;
341  }
342  while (num_side_channels >= 2) {
343  i += assign_pair(e2c_vec, layout_map, i,
344  UINT64_MAX,
345  UINT64_MAX,
347  num_side_channels -= 2;
348  }
349 
350  while (num_back_channels >= 4) {
351  i += assign_pair(e2c_vec, layout_map, i,
352  UINT64_MAX,
353  UINT64_MAX,
355  num_back_channels -= 2;
356  }
357  if (num_back_channels >= 2) {
358  i += assign_pair(e2c_vec, layout_map, i,
362  num_back_channels -= 2;
363  }
364  if (num_back_channels) {
365  e2c_vec[i] = (struct elem_to_channel) {
367  .syn_ele = TYPE_SCE,
368  .elem_id = layout_map[i][1],
369  .aac_position = AAC_CHANNEL_BACK
370  };
371  layout |= e2c_vec[i].av_position;
372  i++;
373  num_back_channels--;
374  }
375 
376  if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) {
377  e2c_vec[i] = (struct elem_to_channel) {
379  .syn_ele = TYPE_LFE,
380  .elem_id = layout_map[i][1],
381  .aac_position = AAC_CHANNEL_LFE
382  };
383  layout |= e2c_vec[i].av_position;
384  i++;
385  }
386  if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) {
387  e2c_vec[i] = (struct elem_to_channel) {
389  .syn_ele = TYPE_LFE,
390  .elem_id = layout_map[i][1],
391  .aac_position = AAC_CHANNEL_LFE
392  };
393  layout |= e2c_vec[i].av_position;
394  i++;
395  }
396  while (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) {
397  e2c_vec[i] = (struct elem_to_channel) {
398  .av_position = UINT64_MAX,
399  .syn_ele = TYPE_LFE,
400  .elem_id = layout_map[i][1],
401  .aac_position = AAC_CHANNEL_LFE
402  };
403  i++;
404  }
405 
406  // The previous checks would end up at 8 at this point for 22.2
407  if (layout == PREFIX_FOR_22POINT2 && tags == 16 && i == 8) {
408  const uint8_t (*reference_layout_map)[3] = aac_channel_layout_map[12];
409  for (int j = 0; j < tags; j++) {
410  if (layout_map[j][0] != reference_layout_map[j][0] ||
411  layout_map[j][2] != reference_layout_map[j][2])
412  goto end_of_layout_definition;
413  }
414 
415  e2c_vec[i] = (struct elem_to_channel) {
417  .syn_ele = layout_map[i][0],
418  .elem_id = layout_map[i][1],
419  .aac_position = layout_map[i][2]
420  }; layout |= e2c_vec[i].av_position; i++;
421  i += assign_pair(e2c_vec, layout_map, i,
425  &layout);
426  i += assign_pair(e2c_vec, layout_map, i,
430  &layout);
431  e2c_vec[i] = (struct elem_to_channel) {
433  .syn_ele = layout_map[i][0],
434  .elem_id = layout_map[i][1],
435  .aac_position = layout_map[i][2]
436  }; layout |= e2c_vec[i].av_position; i++;
437  i += assign_pair(e2c_vec, layout_map, i,
441  &layout);
442  e2c_vec[i] = (struct elem_to_channel) {
444  .syn_ele = layout_map[i][0],
445  .elem_id = layout_map[i][1],
446  .aac_position = layout_map[i][2]
447  }; layout |= e2c_vec[i].av_position; i++;
448  e2c_vec[i] = (struct elem_to_channel) {
450  .syn_ele = layout_map[i][0],
451  .elem_id = layout_map[i][1],
452  .aac_position = layout_map[i][2]
453  }; layout |= e2c_vec[i].av_position; i++;
454  i += assign_pair(e2c_vec, layout_map, i,
458  &layout);
459  }
460 
461 end_of_layout_definition:
462 
463  total_non_cc_elements = n = i;
464 
465  if (layout == AV_CH_LAYOUT_22POINT2) {
466  // For 22.2 reorder the result as needed
467  FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[0]); // FL & FR first (final), FC third
468  FFSWAP(struct elem_to_channel, e2c_vec[2], e2c_vec[1]); // FC second (final), FLc & FRc third
469  FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[2]); // LFE1 third (final), FLc & FRc seventh
470  FFSWAP(struct elem_to_channel, e2c_vec[4], e2c_vec[3]); // BL & BR fourth (final), SiL & SiR fifth
471  FFSWAP(struct elem_to_channel, e2c_vec[6], e2c_vec[4]); // FLc & FRc fifth (final), SiL & SiR seventh
472  FFSWAP(struct elem_to_channel, e2c_vec[7], e2c_vec[6]); // LFE2 seventh (final), SiL & SiR eight (final)
473  FFSWAP(struct elem_to_channel, e2c_vec[9], e2c_vec[8]); // TpFL & TpFR ninth (final), TFC tenth (final)
474  FFSWAP(struct elem_to_channel, e2c_vec[11], e2c_vec[10]); // TC eleventh (final), TpSiL & TpSiR twelth
475  FFSWAP(struct elem_to_channel, e2c_vec[12], e2c_vec[11]); // TpBL & TpBR twelth (final), TpSiL & TpSiR thirteenth (final)
476  } else {
477  // For everything else, utilize the AV channel position define as a
478  // stable sort.
479  do {
480  int next_n = 0;
481  for (i = 1; i < n; i++)
482  if (e2c_vec[i - 1].av_position > e2c_vec[i].av_position) {
483  FFSWAP(struct elem_to_channel, e2c_vec[i - 1], e2c_vec[i]);
484  next_n = i;
485  }
486  n = next_n;
487  } while (n > 0);
488 
489  }
490 
491  for (i = 0; i < total_non_cc_elements; i++) {
492  layout_map[i][0] = e2c_vec[i].syn_ele;
493  layout_map[i][1] = e2c_vec[i].elem_id;
494  layout_map[i][2] = e2c_vec[i].aac_position;
495  }
496 
497  return layout;
498 }
499 
500 /**
501  * Save current output configuration if and only if it has been locked.
502  */
504  int pushed = 0;
505 
506  if (ac->oc[1].status == OC_LOCKED || ac->oc[0].status == OC_NONE) {
507  ac->oc[0] = ac->oc[1];
508  pushed = 1;
509  }
510  ac->oc[1].status = OC_NONE;
511  return pushed;
512 }
513 
514 /**
515  * Restore the previous output configuration if and only if the current
516  * configuration is unlocked.
517  */
519  if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) {
520  ac->oc[1] = ac->oc[0];
521  ac->avctx->ch_layout = ac->oc[1].ch_layout;
522  output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags,
523  ac->oc[1].status, 0);
524  }
525 }
526 
527 /**
528  * Configure output channel order based on the current program
529  * configuration element.
530  *
531  * @return Returns error status. 0 - OK, !0 - error
532  */
534  uint8_t layout_map[MAX_ELEM_ID * 4][3], int tags,
535  enum OCStatus oc_type, int get_new_frame)
536 {
537  AVCodecContext *avctx = ac->avctx;
538  int i, channels = 0, ret;
539  uint64_t layout = 0;
540  uint8_t id_map[TYPE_END][MAX_ELEM_ID] = {{ 0 }};
541  uint8_t type_counts[TYPE_END] = { 0 };
542 
543  if (ac->oc[1].layout_map != layout_map) {
544  memcpy(ac->oc[1].layout_map, layout_map, tags * sizeof(layout_map[0]));
545  ac->oc[1].layout_map_tags = tags;
546  }
547  for (i = 0; i < tags; i++) {
548  int type = layout_map[i][0];
549  int id = layout_map[i][1];
550  id_map[type][id] = type_counts[type]++;
551  if (id_map[type][id] >= MAX_ELEM_ID) {
552  avpriv_request_sample(ac->avctx, "Too large remapped id");
553  return AVERROR_PATCHWELCOME;
554  }
555  }
556  // Try to sniff a reasonable channel order, otherwise output the
557  // channels in the order the PCE declared them.
558 #if FF_API_OLD_CHANNEL_LAYOUT
560  if (avctx->request_channel_layout == AV_CH_LAYOUT_NATIVE)
563 #endif
564 
566  layout = sniff_channel_order(layout_map, tags);
567  for (i = 0; i < tags; i++) {
568  int type = layout_map[i][0];
569  int id = layout_map[i][1];
570  int iid = id_map[type][id];
571  int position = layout_map[i][2];
572  // Allocate or free elements depending on if they are in the
573  // current program configuration.
574  ret = che_configure(ac, position, type, iid, &channels);
575  if (ret < 0)
576  return ret;
577  ac->tag_che_map[type][id] = ac->che[type][iid];
578  }
579  if (ac->oc[1].m4ac.ps == 1 && channels == 2) {
580  if (layout == AV_CH_FRONT_CENTER) {
582  } else {
583  layout = 0;
584  }
585  }
586 
588  if (layout)
590  else {
592  ac->oc[1].ch_layout.nb_channels = channels;
593  }
594 
595  av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout);
596  ac->oc[1].status = oc_type;
597 
598  if (get_new_frame) {
599  if ((ret = frame_configure_elements(ac->avctx)) < 0)
600  return ret;
601  }
602 
603  return 0;
604 }
605 
606 static void flush(AVCodecContext *avctx)
607 {
608  AACContext *ac= avctx->priv_data;
609  int type, i, j;
610 
611  for (type = 3; type >= 0; type--) {
612  for (i = 0; i < MAX_ELEM_ID; i++) {
613  ChannelElement *che = ac->che[type][i];
614  if (che) {
615  for (j = 0; j <= 1; j++) {
616  memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved));
617  }
618  }
619  }
620  }
621 }
622 
623 /**
624  * Set up channel positions based on a default channel configuration
625  * as specified in table 1.17.
626  *
627  * @return Returns error status. 0 - OK, !0 - error
628  */
630  uint8_t (*layout_map)[3],
631  int *tags,
632  int channel_config)
633 {
634  if (channel_config < 1 || (channel_config > 7 && channel_config < 11) ||
635  channel_config > 13) {
636  av_log(avctx, AV_LOG_ERROR,
637  "invalid default channel configuration (%d)\n",
638  channel_config);
639  return AVERROR_INVALIDDATA;
640  }
641  *tags = tags_per_config[channel_config];
642  memcpy(layout_map, aac_channel_layout_map[channel_config - 1],
643  *tags * sizeof(*layout_map));
644 
645  /*
646  * AAC specification has 7.1(wide) as a default layout for 8-channel streams.
647  * However, at least Nero AAC encoder encodes 7.1 streams using the default
648  * channel config 7, mapping the side channels of the original audio stream
649  * to the second AAC_CHANNEL_FRONT pair in the AAC stream. Similarly, e.g. FAAD
650  * decodes the second AAC_CHANNEL_FRONT pair as side channels, therefore decoding
651  * the incorrect streams as if they were correct (and as the encoder intended).
652  *
653  * As actual intended 7.1(wide) streams are very rare, default to assuming a
654  * 7.1 layout was intended.
655  */
656  if (channel_config == 7 && avctx->strict_std_compliance < FF_COMPLIANCE_STRICT) {
657  layout_map[2][2] = AAC_CHANNEL_SIDE;
658 
659  if (!ac || !ac->warned_71_wide++) {
660  av_log(avctx, AV_LOG_INFO, "Assuming an incorrectly encoded 7.1 channel layout"
661  " instead of a spec-compliant 7.1(wide) layout, use -strict %d to decode"
662  " according to the specification instead.\n", FF_COMPLIANCE_STRICT);
663  }
664  }
665 
666  return 0;
667 }
668 
669 static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
670 {
671  /* For PCE based channel configurations map the channels solely based
672  * on tags. */
673  if (!ac->oc[1].m4ac.chan_config) {
674  return ac->tag_che_map[type][elem_id];
675  }
676  // Allow single CPE stereo files to be signalled with mono configuration.
677  if (!ac->tags_mapped && type == TYPE_CPE &&
678  ac->oc[1].m4ac.chan_config == 1) {
679  uint8_t layout_map[MAX_ELEM_ID*4][3];
680  int layout_map_tags;
682 
683  av_log(ac->avctx, AV_LOG_DEBUG, "mono with CPE\n");
684 
685  if (set_default_channel_config(ac, ac->avctx, layout_map,
686  &layout_map_tags, 2) < 0)
687  return NULL;
688  if (output_configure(ac, layout_map, layout_map_tags,
689  OC_TRIAL_FRAME, 1) < 0)
690  return NULL;
691 
692  ac->oc[1].m4ac.chan_config = 2;
693  ac->oc[1].m4ac.ps = 0;
694  }
695  // And vice-versa
696  if (!ac->tags_mapped && type == TYPE_SCE &&
697  ac->oc[1].m4ac.chan_config == 2) {
698  uint8_t layout_map[MAX_ELEM_ID * 4][3];
699  int layout_map_tags;
701 
702  av_log(ac->avctx, AV_LOG_DEBUG, "stereo with SCE\n");
703 
704  if (set_default_channel_config(ac, ac->avctx, layout_map,
705  &layout_map_tags, 1) < 0)
706  return NULL;
707  if (output_configure(ac, layout_map, layout_map_tags,
708  OC_TRIAL_FRAME, 1) < 0)
709  return NULL;
710 
711  ac->oc[1].m4ac.chan_config = 1;
712  if (ac->oc[1].m4ac.sbr)
713  ac->oc[1].m4ac.ps = -1;
714  }
715  /* For indexed channel configurations map the channels solely based
716  * on position. */
717  switch (ac->oc[1].m4ac.chan_config) {
718  case 13:
719  if (ac->tags_mapped > 3 && ((type == TYPE_CPE && elem_id < 8) ||
720  (type == TYPE_SCE && elem_id < 6) ||
721  (type == TYPE_LFE && elem_id < 2))) {
722  ac->tags_mapped++;
723  return ac->tag_che_map[type][elem_id] = ac->che[type][elem_id];
724  }
725  case 12:
726  case 7:
727  if (ac->tags_mapped == 3 && type == TYPE_CPE) {
728  ac->tags_mapped++;
729  return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
730  }
731  case 11:
732  if (ac->tags_mapped == 2 &&
733  ac->oc[1].m4ac.chan_config == 11 &&
734  type == TYPE_SCE) {
735  ac->tags_mapped++;
736  return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
737  }
738  case 6:
739  /* Some streams incorrectly code 5.1 audio as
740  * SCE[0] CPE[0] CPE[1] SCE[1]
741  * instead of
742  * SCE[0] CPE[0] CPE[1] LFE[0].
743  * If we seem to have encountered such a stream, transfer
744  * the LFE[0] element to the SCE[1]'s mapping */
745  if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
746  if (!ac->warned_remapping_once && (type != TYPE_LFE || elem_id != 0)) {
748  "This stream seems to incorrectly report its last channel as %s[%d], mapping to LFE[0]\n",
749  type == TYPE_SCE ? "SCE" : "LFE", elem_id);
750  ac->warned_remapping_once++;
751  }
752  ac->tags_mapped++;
753  return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
754  }
755  case 5:
756  if (ac->tags_mapped == 2 && type == TYPE_CPE) {
757  ac->tags_mapped++;
758  return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
759  }
760  case 4:
761  /* Some streams incorrectly code 4.0 audio as
762  * SCE[0] CPE[0] LFE[0]
763  * instead of
764  * SCE[0] CPE[0] SCE[1].
765  * If we seem to have encountered such a stream, transfer
766  * the SCE[1] element to the LFE[0]'s mapping */
767  if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
768  if (!ac->warned_remapping_once && (type != TYPE_SCE || elem_id != 1)) {
770  "This stream seems to incorrectly report its last channel as %s[%d], mapping to SCE[1]\n",
771  type == TYPE_SCE ? "SCE" : "LFE", elem_id);
772  ac->warned_remapping_once++;
773  }
774  ac->tags_mapped++;
775  return ac->tag_che_map[type][elem_id] = ac->che[TYPE_SCE][1];
776  }
777  if (ac->tags_mapped == 2 &&
778  ac->oc[1].m4ac.chan_config == 4 &&
779  type == TYPE_SCE) {
780  ac->tags_mapped++;
781  return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
782  }
783  case 3:
784  case 2:
785  if (ac->tags_mapped == (ac->oc[1].m4ac.chan_config != 2) &&
786  type == TYPE_CPE) {
787  ac->tags_mapped++;
788  return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
789  } else if (ac->oc[1].m4ac.chan_config == 2) {
790  return NULL;
791  }
792  case 1:
793  if (!ac->tags_mapped && type == TYPE_SCE) {
794  ac->tags_mapped++;
795  return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
796  }
797  default:
798  return NULL;
799  }
800 }
801 
802 /**
803  * Decode an array of 4 bit element IDs, optionally interleaved with a
804  * stereo/mono switching bit.
805  *
806  * @param type speaker type/position for these channels
807  */
808 static void decode_channel_map(uint8_t layout_map[][3],
809  enum ChannelPosition type,
810  GetBitContext *gb, int n)
811 {
812  while (n--) {
813  enum RawDataBlockType syn_ele;
814  switch (type) {
815  case AAC_CHANNEL_FRONT:
816  case AAC_CHANNEL_BACK:
817  case AAC_CHANNEL_SIDE:
818  syn_ele = get_bits1(gb);
819  break;
820  case AAC_CHANNEL_CC:
821  skip_bits1(gb);
822  syn_ele = TYPE_CCE;
823  break;
824  case AAC_CHANNEL_LFE:
825  syn_ele = TYPE_LFE;
826  break;
827  default:
828  // AAC_CHANNEL_OFF has no channel map
829  av_assert0(0);
830  }
831  layout_map[0][0] = syn_ele;
832  layout_map[0][1] = get_bits(gb, 4);
833  layout_map[0][2] = type;
834  layout_map++;
835  }
836 }
837 
838 static inline void relative_align_get_bits(GetBitContext *gb,
839  int reference_position) {
840  int n = (reference_position - get_bits_count(gb) & 7);
841  if (n)
842  skip_bits(gb, n);
843 }
844 
845 /**
846  * Decode program configuration element; reference: table 4.2.
847  *
848  * @return Returns error status. 0 - OK, !0 - error
849  */
850 static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
851  uint8_t (*layout_map)[3],
852  GetBitContext *gb, int byte_align_ref)
853 {
854  int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
855  int sampling_index;
856  int comment_len;
857  int tags;
858 
859  skip_bits(gb, 2); // object_type
860 
861  sampling_index = get_bits(gb, 4);
862  if (m4ac->sampling_index != sampling_index)
863  av_log(avctx, AV_LOG_WARNING,
864  "Sample rate index in program config element does not "
865  "match the sample rate index configured by the container.\n");
866 
867  num_front = get_bits(gb, 4);
868  num_side = get_bits(gb, 4);
869  num_back = get_bits(gb, 4);
870  num_lfe = get_bits(gb, 2);
871  num_assoc_data = get_bits(gb, 3);
872  num_cc = get_bits(gb, 4);
873 
874  if (get_bits1(gb))
875  skip_bits(gb, 4); // mono_mixdown_tag
876  if (get_bits1(gb))
877  skip_bits(gb, 4); // stereo_mixdown_tag
878 
879  if (get_bits1(gb))
880  skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround
881 
882  if (get_bits_left(gb) < 5 * (num_front + num_side + num_back + num_cc) + 4 *(num_lfe + num_assoc_data + num_cc)) {
883  av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err);
884  return -1;
885  }
886  decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front);
887  tags = num_front;
888  decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side);
889  tags += num_side;
890  decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back);
891  tags += num_back;
892  decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe);
893  tags += num_lfe;
894 
895  skip_bits_long(gb, 4 * num_assoc_data);
896 
897  decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc);
898  tags += num_cc;
899 
900  relative_align_get_bits(gb, byte_align_ref);
901 
902  /* comment field, first byte is length */
903  comment_len = get_bits(gb, 8) * 8;
904  if (get_bits_left(gb) < comment_len) {
905  av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err);
906  return AVERROR_INVALIDDATA;
907  }
908  skip_bits_long(gb, comment_len);
909  return tags;
910 }
911 
912 /**
913  * Decode GA "General Audio" specific configuration; reference: table 4.1.
914  *
915  * @param ac pointer to AACContext, may be null
916  * @param avctx pointer to AVCCodecContext, used for logging
917  *
918  * @return Returns error status. 0 - OK, !0 - error
919  */
921  GetBitContext *gb,
922  int get_bit_alignment,
923  MPEG4AudioConfig *m4ac,
924  int channel_config)
925 {
926  int extension_flag, ret, ep_config, res_flags;
927  uint8_t layout_map[MAX_ELEM_ID*4][3];
928  int tags = 0;
929 
930 #if USE_FIXED
931  if (get_bits1(gb)) { // frameLengthFlag
932  avpriv_report_missing_feature(avctx, "Fixed point 960/120 MDCT window");
933  return AVERROR_PATCHWELCOME;
934  }
935  m4ac->frame_length_short = 0;
936 #else
937  m4ac->frame_length_short = get_bits1(gb);
938  if (m4ac->frame_length_short && m4ac->sbr == 1) {
939  avpriv_report_missing_feature(avctx, "SBR with 960 frame length");
940  if (ac) ac->warned_960_sbr = 1;
941  m4ac->sbr = 0;
942  m4ac->ps = 0;
943  }
944 #endif
945 
946  if (get_bits1(gb)) // dependsOnCoreCoder
947  skip_bits(gb, 14); // coreCoderDelay
948  extension_flag = get_bits1(gb);
949 
950  if (m4ac->object_type == AOT_AAC_SCALABLE ||
952  skip_bits(gb, 3); // layerNr
953 
954  if (channel_config == 0) {
955  skip_bits(gb, 4); // element_instance_tag
956  tags = decode_pce(avctx, m4ac, layout_map, gb, get_bit_alignment);
957  if (tags < 0)
958  return tags;
959  } else {
960  if ((ret = set_default_channel_config(ac, avctx, layout_map,
961  &tags, channel_config)))
962  return ret;
963  }
964 
965  if (count_channels(layout_map, tags) > 1) {
966  m4ac->ps = 0;
967  } else if (m4ac->sbr == 1 && m4ac->ps == -1)
968  m4ac->ps = 1;
969 
970  if (ac && (ret = output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0)))
971  return ret;
972 
973  if (extension_flag) {
974  switch (m4ac->object_type) {
975  case AOT_ER_BSAC:
976  skip_bits(gb, 5); // numOfSubFrame
977  skip_bits(gb, 11); // layer_length
978  break;
979  case AOT_ER_AAC_LC:
980  case AOT_ER_AAC_LTP:
981  case AOT_ER_AAC_SCALABLE:
982  case AOT_ER_AAC_LD:
983  res_flags = get_bits(gb, 3);
984  if (res_flags) {
986  "AAC data resilience (flags %x)",
987  res_flags);
988  return AVERROR_PATCHWELCOME;
989  }
990  break;
991  }
992  skip_bits1(gb); // extensionFlag3 (TBD in version 3)
993  }
994  switch (m4ac->object_type) {
995  case AOT_ER_AAC_LC:
996  case AOT_ER_AAC_LTP:
997  case AOT_ER_AAC_SCALABLE:
998  case AOT_ER_AAC_LD:
999  ep_config = get_bits(gb, 2);
1000  if (ep_config) {
1002  "epConfig %d", ep_config);
1003  return AVERROR_PATCHWELCOME;
1004  }
1005  }
1006  return 0;
1007 }
1008 
1010  GetBitContext *gb,
1011  MPEG4AudioConfig *m4ac,
1012  int channel_config)
1013 {
1014  int ret, ep_config, res_flags;
1015  uint8_t layout_map[MAX_ELEM_ID*4][3];
1016  int tags = 0;
1017  const int ELDEXT_TERM = 0;
1018 
1019  m4ac->ps = 0;
1020  m4ac->sbr = 0;
1021 #if USE_FIXED
1022  if (get_bits1(gb)) { // frameLengthFlag
1023  avpriv_request_sample(avctx, "960/120 MDCT window");
1024  return AVERROR_PATCHWELCOME;
1025  }
1026 #else
1027  m4ac->frame_length_short = get_bits1(gb);
1028 #endif
1029  res_flags = get_bits(gb, 3);
1030  if (res_flags) {
1032  "AAC data resilience (flags %x)",
1033  res_flags);
1034  return AVERROR_PATCHWELCOME;
1035  }
1036 
1037  if (get_bits1(gb)) { // ldSbrPresentFlag
1039  "Low Delay SBR");
1040  return AVERROR_PATCHWELCOME;
1041  }
1042 
1043  while (get_bits(gb, 4) != ELDEXT_TERM) {
1044  int len = get_bits(gb, 4);
1045  if (len == 15)
1046  len += get_bits(gb, 8);
1047  if (len == 15 + 255)
1048  len += get_bits(gb, 16);
1049  if (get_bits_left(gb) < len * 8 + 4) {
1050  av_log(avctx, AV_LOG_ERROR, overread_err);
1051  return AVERROR_INVALIDDATA;
1052  }
1053  skip_bits_long(gb, 8 * len);
1054  }
1055 
1056  if ((ret = set_default_channel_config(ac, avctx, layout_map,
1057  &tags, channel_config)))
1058  return ret;
1059 
1060  if (ac && (ret = output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0)))
1061  return ret;
1062 
1063  ep_config = get_bits(gb, 2);
1064  if (ep_config) {
1066  "epConfig %d", ep_config);
1067  return AVERROR_PATCHWELCOME;
1068  }
1069  return 0;
1070 }
1071 
1072 /**
1073  * Decode audio specific configuration; reference: table 1.13.
1074  *
1075  * @param ac pointer to AACContext, may be null
1076  * @param avctx pointer to AVCCodecContext, used for logging
1077  * @param m4ac pointer to MPEG4AudioConfig, used for parsing
1078  * @param gb buffer holding an audio specific config
1079  * @param get_bit_alignment relative alignment for byte align operations
1080  * @param sync_extension look for an appended sync extension
1081  *
1082  * @return Returns error status or number of consumed bits. <0 - error
1083  */
1085  AVCodecContext *avctx,
1086  MPEG4AudioConfig *m4ac,
1087  GetBitContext *gb,
1088  int get_bit_alignment,
1089  int sync_extension)
1090 {
1091  int i, ret;
1092  GetBitContext gbc = *gb;
1093  MPEG4AudioConfig m4ac_bak = *m4ac;
1094 
1095  if ((i = ff_mpeg4audio_get_config_gb(m4ac, &gbc, sync_extension, avctx)) < 0) {
1096  *m4ac = m4ac_bak;
1097  return AVERROR_INVALIDDATA;
1098  }
1099 
1100  if (m4ac->sampling_index > 12) {
1101  av_log(avctx, AV_LOG_ERROR,
1102  "invalid sampling rate index %d\n",
1103  m4ac->sampling_index);
1104  *m4ac = m4ac_bak;
1105  return AVERROR_INVALIDDATA;
1106  }
1107  if (m4ac->object_type == AOT_ER_AAC_LD &&
1108  (m4ac->sampling_index < 3 || m4ac->sampling_index > 7)) {
1109  av_log(avctx, AV_LOG_ERROR,
1110  "invalid low delay sampling rate index %d\n",
1111  m4ac->sampling_index);
1112  *m4ac = m4ac_bak;
1113  return AVERROR_INVALIDDATA;
1114  }
1115 
1116  skip_bits_long(gb, i);
1117 
1118  switch (m4ac->object_type) {
1119  case AOT_AAC_MAIN:
1120  case AOT_AAC_LC:
1121  case AOT_AAC_SSR:
1122  case AOT_AAC_LTP:
1123  case AOT_ER_AAC_LC:
1124  case AOT_ER_AAC_LD:
1125  if ((ret = decode_ga_specific_config(ac, avctx, gb, get_bit_alignment,
1126  m4ac, m4ac->chan_config)) < 0)
1127  return ret;
1128  break;
1129  case AOT_ER_AAC_ELD:
1130  if ((ret = decode_eld_specific_config(ac, avctx, gb,
1131  m4ac, m4ac->chan_config)) < 0)
1132  return ret;
1133  break;
1134  default:
1136  "Audio object type %s%d",
1137  m4ac->sbr == 1 ? "SBR+" : "",
1138  m4ac->object_type);
1139  return AVERROR(ENOSYS);
1140  }
1141 
1142  ff_dlog(avctx,
1143  "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
1144  m4ac->object_type, m4ac->chan_config, m4ac->sampling_index,
1145  m4ac->sample_rate, m4ac->sbr,
1146  m4ac->ps);
1147 
1148  return get_bits_count(gb);
1149 }
1150 
1152  AVCodecContext *avctx,
1153  MPEG4AudioConfig *m4ac,
1154  const uint8_t *data, int64_t bit_size,
1155  int sync_extension)
1156 {
1157  int i, ret;
1158  GetBitContext gb;
1159 
1160  if (bit_size < 0 || bit_size > INT_MAX) {
1161  av_log(avctx, AV_LOG_ERROR, "Audio specific config size is invalid\n");
1162  return AVERROR_INVALIDDATA;
1163  }
1164 
1165  ff_dlog(avctx, "audio specific config size %d\n", (int)bit_size >> 3);
1166  for (i = 0; i < bit_size >> 3; i++)
1167  ff_dlog(avctx, "%02x ", data[i]);
1168  ff_dlog(avctx, "\n");
1169 
1170  if ((ret = init_get_bits(&gb, data, bit_size)) < 0)
1171  return ret;
1172 
1173  return decode_audio_specific_config_gb(ac, avctx, m4ac, &gb, 0,
1174  sync_extension);
1175 }
1176 
1177 /**
1178  * linear congruential pseudorandom number generator
1179  *
1180  * @param previous_val pointer to the current state of the generator
1181  *
1182  * @return Returns a 32-bit pseudorandom integer
1183  */
1184 static av_always_inline int lcg_random(unsigned previous_val)
1185 {
1186  union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 };
1187  return v.s;
1188 }
1189 
1191 {
1192  int i;
1193  for (i = 0; i < MAX_PREDICTORS; i++)
1194  reset_predict_state(&ps[i]);
1195 }
1196 
1197 static int sample_rate_idx (int rate)
1198 {
1199  if (92017 <= rate) return 0;
1200  else if (75132 <= rate) return 1;
1201  else if (55426 <= rate) return 2;
1202  else if (46009 <= rate) return 3;
1203  else if (37566 <= rate) return 4;
1204  else if (27713 <= rate) return 5;
1205  else if (23004 <= rate) return 6;
1206  else if (18783 <= rate) return 7;
1207  else if (13856 <= rate) return 8;
1208  else if (11502 <= rate) return 9;
1209  else if (9391 <= rate) return 10;
1210  else return 11;
1211 }
1212 
1213 static void reset_predictor_group(PredictorState *ps, int group_num)
1214 {
1215  int i;
1216  for (i = group_num - 1; i < MAX_PREDICTORS; i += 30)
1217  reset_predict_state(&ps[i]);
1218 }
1219 
1220 static void aacdec_init(AACContext *ac);
1221 
1223 {
1224  static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
1225  294 + 306 + 268 + 510 + 366 + 462];
1226  for (unsigned i = 0, offset = 0; i < 11; i++) {
1231  sizeof(ff_aac_spectral_bits[i][0]),
1233  sizeof(ff_aac_spectral_codes[i][0]),
1235  sizeof(ff_aac_codebook_vector_idx[i][0]),
1238  }
1239 
1241 
1242  ff_aac_tableinit();
1243 
1247  sizeof(ff_aac_scalefactor_bits[0]),
1248  sizeof(ff_aac_scalefactor_bits[0]),
1250  sizeof(ff_aac_scalefactor_code[0]),
1251  sizeof(ff_aac_scalefactor_code[0]),
1252  352);
1253 
1254  // window initialization
1255 #if !USE_FIXED
1262 #else
1263  AAC_RENAME(ff_kbd_window_init)(AAC_RENAME2(aac_kbd_long_1024), 4.0, 1024);
1264  AAC_RENAME(ff_kbd_window_init)(AAC_RENAME2(aac_kbd_short_128), 6.0, 128);
1266 #endif
1267 
1269 }
1270 
1272 
1274 {
1275  AACContext *ac = avctx->priv_data;
1276  int ret;
1277 
1278  if (avctx->sample_rate > 96000)
1279  return AVERROR_INVALIDDATA;
1280 
1282  if (ret != 0)
1283  return AVERROR_UNKNOWN;
1284 
1285  ac->avctx = avctx;
1286  ac->oc[1].m4ac.sample_rate = avctx->sample_rate;
1287 
1288  aacdec_init(ac);
1289 #if USE_FIXED
1290  avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
1291 #else
1292  avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
1293 #endif /* USE_FIXED */
1294 
1295  if (avctx->extradata_size > 0) {
1296  if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac,
1297  avctx->extradata,
1298  avctx->extradata_size * 8LL,
1299  1)) < 0)
1300  return ret;
1301  } else {
1302  int sr, i;
1303  uint8_t layout_map[MAX_ELEM_ID*4][3];
1304  int layout_map_tags;
1305 
1306  sr = sample_rate_idx(avctx->sample_rate);
1307  ac->oc[1].m4ac.sampling_index = sr;
1308  ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels;
1309  ac->oc[1].m4ac.sbr = -1;
1310  ac->oc[1].m4ac.ps = -1;
1311 
1312  for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++)
1314  break;
1316  i = 0;
1317  }
1318  ac->oc[1].m4ac.chan_config = i;
1319 
1320  if (ac->oc[1].m4ac.chan_config) {
1321  int ret = set_default_channel_config(ac, avctx, layout_map,
1322  &layout_map_tags, ac->oc[1].m4ac.chan_config);
1323  if (!ret)
1324  output_configure(ac, layout_map, layout_map_tags,
1325  OC_GLOBAL_HDR, 0);
1326  else if (avctx->err_recognition & AV_EF_EXPLODE)
1327  return AVERROR_INVALIDDATA;
1328  }
1329  }
1330 
1331  if (avctx->ch_layout.nb_channels > MAX_CHANNELS) {
1332  av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
1333  return AVERROR_INVALIDDATA;
1334  }
1335 
1336 #if USE_FIXED
1338 #else
1340 #endif /* USE_FIXED */
1341  if (!ac->fdsp) {
1342  return AVERROR(ENOMEM);
1343  }
1344 
1345  ac->random_state = 0x1f2e3d4c;
1346 
1347  AAC_RENAME_32(ff_mdct_init)(&ac->mdct, 11, 1, 1.0 / RANGE15(1024.0));
1348  AAC_RENAME_32(ff_mdct_init)(&ac->mdct_ld, 10, 1, 1.0 / RANGE15(512.0));
1349  AAC_RENAME_32(ff_mdct_init)(&ac->mdct_small, 8, 1, 1.0 / RANGE15(128.0));
1350  AAC_RENAME_32(ff_mdct_init)(&ac->mdct_ltp, 11, 0, RANGE15(-2.0));
1351 #if !USE_FIXED
1352  ret = ff_mdct15_init(&ac->mdct120, 1, 3, 1.0f/(16*1024*120*2));
1353  if (ret < 0)
1354  return ret;
1355  ret = ff_mdct15_init(&ac->mdct480, 1, 5, 1.0f/(16*1024*960));
1356  if (ret < 0)
1357  return ret;
1358  ret = ff_mdct15_init(&ac->mdct960, 1, 6, 1.0f/(16*1024*960*2));
1359  if (ret < 0)
1360  return ret;
1361 #endif
1362 
1363  return 0;
1364 }
1365 
1366 /**
1367  * Skip data_stream_element; reference: table 4.10.
1368  */
1370 {
1371  int byte_align = get_bits1(gb);
1372  int count = get_bits(gb, 8);
1373  if (count == 255)
1374  count += get_bits(gb, 8);
1375  if (byte_align)
1376  align_get_bits(gb);
1377 
1378  if (get_bits_left(gb) < 8 * count) {
1379  av_log(ac->avctx, AV_LOG_ERROR, "skip_data_stream_element: "overread_err);
1380  return AVERROR_INVALIDDATA;
1381  }
1382  skip_bits_long(gb, 8 * count);
1383  return 0;
1384 }
1385 
1387  GetBitContext *gb)
1388 {
1389  int sfb;
1390  if (get_bits1(gb)) {
1391  ics->predictor_reset_group = get_bits(gb, 5);
1392  if (ics->predictor_reset_group == 0 ||
1393  ics->predictor_reset_group > 30) {
1394  av_log(ac->avctx, AV_LOG_ERROR,
1395  "Invalid Predictor Reset Group.\n");
1396  return AVERROR_INVALIDDATA;
1397  }
1398  }
1399  for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]); sfb++) {
1400  ics->prediction_used[sfb] = get_bits1(gb);
1401  }
1402  return 0;
1403 }
1404 
1405 /**
1406  * Decode Long Term Prediction data; reference: table 4.xx.
1407  */
1409  GetBitContext *gb, uint8_t max_sfb)
1410 {
1411  int sfb;
1412 
1413  ltp->lag = get_bits(gb, 11);
1414  ltp->coef = ltp_coef[get_bits(gb, 3)];
1415  for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++)
1416  ltp->used[sfb] = get_bits1(gb);
1417 }
1418 
1419 /**
1420  * Decode Individual Channel Stream info; reference: table 4.6.
1421  */
1423  GetBitContext *gb)
1424 {
1425  const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac;
1426  const int aot = m4ac->object_type;
1427  const int sampling_index = m4ac->sampling_index;
1428  int ret_fail = AVERROR_INVALIDDATA;
1429 
1430  if (aot != AOT_ER_AAC_ELD) {
1431  if (get_bits1(gb)) {
1432  av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n");
1434  return AVERROR_INVALIDDATA;
1435  }
1436  ics->window_sequence[1] = ics->window_sequence[0];
1437  ics->window_sequence[0] = get_bits(gb, 2);
1438  if (aot == AOT_ER_AAC_LD &&
1439  ics->window_sequence[0] != ONLY_LONG_SEQUENCE) {
1440  av_log(ac->avctx, AV_LOG_ERROR,
1441  "AAC LD is only defined for ONLY_LONG_SEQUENCE but "
1442  "window sequence %d found.\n", ics->window_sequence[0]);
1444  return AVERROR_INVALIDDATA;
1445  }
1446  ics->use_kb_window[1] = ics->use_kb_window[0];
1447  ics->use_kb_window[0] = get_bits1(gb);
1448  }
1449  ics->num_window_groups = 1;
1450  ics->group_len[0] = 1;
1451  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1452  int i;
1453  ics->max_sfb = get_bits(gb, 4);
1454  for (i = 0; i < 7; i++) {
1455  if (get_bits1(gb)) {
1456  ics->group_len[ics->num_window_groups - 1]++;
1457  } else {
1458  ics->num_window_groups++;
1459  ics->group_len[ics->num_window_groups - 1] = 1;
1460  }
1461  }
1462  ics->num_windows = 8;
1463  if (m4ac->frame_length_short) {
1464  ics->swb_offset = ff_swb_offset_120[sampling_index];
1465  ics->num_swb = ff_aac_num_swb_120[sampling_index];
1466  } else {
1467  ics->swb_offset = ff_swb_offset_128[sampling_index];
1468  ics->num_swb = ff_aac_num_swb_128[sampling_index];
1469  }
1470  ics->tns_max_bands = ff_tns_max_bands_128[sampling_index];
1471  ics->predictor_present = 0;
1472  } else {
1473  ics->max_sfb = get_bits(gb, 6);
1474  ics->num_windows = 1;
1475  if (aot == AOT_ER_AAC_LD || aot == AOT_ER_AAC_ELD) {
1476  if (m4ac->frame_length_short) {
1477  ics->swb_offset = ff_swb_offset_480[sampling_index];
1478  ics->num_swb = ff_aac_num_swb_480[sampling_index];
1479  ics->tns_max_bands = ff_tns_max_bands_480[sampling_index];
1480  } else {
1481  ics->swb_offset = ff_swb_offset_512[sampling_index];
1482  ics->num_swb = ff_aac_num_swb_512[sampling_index];
1483  ics->tns_max_bands = ff_tns_max_bands_512[sampling_index];
1484  }
1485  if (!ics->num_swb || !ics->swb_offset) {
1486  ret_fail = AVERROR_BUG;
1487  goto fail;
1488  }
1489  } else {
1490  if (m4ac->frame_length_short) {
1491  ics->num_swb = ff_aac_num_swb_960[sampling_index];
1492  ics->swb_offset = ff_swb_offset_960[sampling_index];
1493  } else {
1494  ics->num_swb = ff_aac_num_swb_1024[sampling_index];
1495  ics->swb_offset = ff_swb_offset_1024[sampling_index];
1496  }
1497  ics->tns_max_bands = ff_tns_max_bands_1024[sampling_index];
1498  }
1499  if (aot != AOT_ER_AAC_ELD) {
1500  ics->predictor_present = get_bits1(gb);
1501  ics->predictor_reset_group = 0;
1502  }
1503  if (ics->predictor_present) {
1504  if (aot == AOT_AAC_MAIN) {
1505  if (decode_prediction(ac, ics, gb)) {
1506  goto fail;
1507  }
1508  } else if (aot == AOT_AAC_LC ||
1509  aot == AOT_ER_AAC_LC) {
1510  av_log(ac->avctx, AV_LOG_ERROR,
1511  "Prediction is not allowed in AAC-LC.\n");
1512  goto fail;
1513  } else {
1514  if (aot == AOT_ER_AAC_LD) {
1515  av_log(ac->avctx, AV_LOG_ERROR,
1516  "LTP in ER AAC LD not yet implemented.\n");
1517  ret_fail = AVERROR_PATCHWELCOME;
1518  goto fail;
1519  }
1520  if ((ics->ltp.present = get_bits(gb, 1)))
1521  decode_ltp(&ics->ltp, gb, ics->max_sfb);
1522  }
1523  }
1524  }
1525 
1526  if (ics->max_sfb > ics->num_swb) {
1527  av_log(ac->avctx, AV_LOG_ERROR,
1528  "Number of scalefactor bands in group (%d) "
1529  "exceeds limit (%d).\n",
1530  ics->max_sfb, ics->num_swb);
1531  goto fail;
1532  }
1533 
1534  return 0;
1535 fail:
1536  ics->max_sfb = 0;
1537  return ret_fail;
1538 }
1539 
1540 /**
1541  * Decode band types (section_data payload); reference: table 4.46.
1542  *
1543  * @param band_type array of the used band type
1544  * @param band_type_run_end array of the last scalefactor band of a band type run
1545  *
1546  * @return Returns error status. 0 - OK, !0 - error
1547  */
1548 static int decode_band_types(AACContext *ac, enum BandType band_type[120],
1549  int band_type_run_end[120], GetBitContext *gb,
1551 {
1552  int g, idx = 0;
1553  const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5;
1554  for (g = 0; g < ics->num_window_groups; g++) {
1555  int k = 0;
1556  while (k < ics->max_sfb) {
1557  uint8_t sect_end = k;
1558  int sect_len_incr;
1559  int sect_band_type = get_bits(gb, 4);
1560  if (sect_band_type == 12) {
1561  av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n");
1562  return AVERROR_INVALIDDATA;
1563  }
1564  do {
1565  sect_len_incr = get_bits(gb, bits);
1566  sect_end += sect_len_incr;
1567  if (get_bits_left(gb) < 0) {
1568  av_log(ac->avctx, AV_LOG_ERROR, "decode_band_types: "overread_err);
1569  return AVERROR_INVALIDDATA;
1570  }
1571  if (sect_end > ics->max_sfb) {
1572  av_log(ac->avctx, AV_LOG_ERROR,
1573  "Number of bands (%d) exceeds limit (%d).\n",
1574  sect_end, ics->max_sfb);
1575  return AVERROR_INVALIDDATA;
1576  }
1577  } while (sect_len_incr == (1 << bits) - 1);
1578  for (; k < sect_end; k++) {
1579  band_type [idx] = sect_band_type;
1580  band_type_run_end[idx++] = sect_end;
1581  }
1582  }
1583  }
1584  return 0;
1585 }
1586 
1587 /**
1588  * Decode scalefactors; reference: table 4.47.
1589  *
1590  * @param global_gain first scalefactor value as scalefactors are differentially coded
1591  * @param band_type array of the used band type
1592  * @param band_type_run_end array of the last scalefactor band of a band type run
1593  * @param sf array of scalefactors or intensity stereo positions
1594  *
1595  * @return Returns error status. 0 - OK, !0 - error
1596  */
1598  unsigned int global_gain,
1600  enum BandType band_type[120],
1601  int band_type_run_end[120])
1602 {
1603  int g, i, idx = 0;
1604  int offset[3] = { global_gain, global_gain - NOISE_OFFSET, 0 };
1605  int clipped_offset;
1606  int noise_flag = 1;
1607  for (g = 0; g < ics->num_window_groups; g++) {
1608  for (i = 0; i < ics->max_sfb;) {
1609  int run_end = band_type_run_end[idx];
1610  if (band_type[idx] == ZERO_BT) {
1611  for (; i < run_end; i++, idx++)
1612  sf[idx] = FIXR(0.);
1613  } else if ((band_type[idx] == INTENSITY_BT) ||
1614  (band_type[idx] == INTENSITY_BT2)) {
1615  for (; i < run_end; i++, idx++) {
1617  clipped_offset = av_clip(offset[2], -155, 100);
1618  if (offset[2] != clipped_offset) {
1620  "If you heard an audible artifact, there may be a bug in the decoder. "
1621  "Clipped intensity stereo position (%d -> %d)",
1622  offset[2], clipped_offset);
1623  }
1624 #if USE_FIXED
1625  sf[idx] = 100 - clipped_offset;
1626 #else
1627  sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO];
1628 #endif /* USE_FIXED */
1629  }
1630  } else if (band_type[idx] == NOISE_BT) {
1631  for (; i < run_end; i++, idx++) {
1632  if (noise_flag-- > 0)
1633  offset[1] += get_bits(gb, NOISE_PRE_BITS) - NOISE_PRE;
1634  else
1636  clipped_offset = av_clip(offset[1], -100, 155);
1637  if (offset[1] != clipped_offset) {
1639  "If you heard an audible artifact, there may be a bug in the decoder. "
1640  "Clipped noise gain (%d -> %d)",
1641  offset[1], clipped_offset);
1642  }
1643 #if USE_FIXED
1644  sf[idx] = -(100 + clipped_offset);
1645 #else
1646  sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO];
1647 #endif /* USE_FIXED */
1648  }
1649  } else {
1650  for (; i < run_end; i++, idx++) {
1652  if (offset[0] > 255U) {
1653  av_log(ac->avctx, AV_LOG_ERROR,
1654  "Scalefactor (%d) out of range.\n", offset[0]);
1655  return AVERROR_INVALIDDATA;
1656  }
1657 #if USE_FIXED
1658  sf[idx] = -offset[0];
1659 #else
1660  sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
1661 #endif /* USE_FIXED */
1662  }
1663  }
1664  }
1665  }
1666  return 0;
1667 }
1668 
1669 /**
1670  * Decode pulse data; reference: table 4.7.
1671  */
1672 static int decode_pulses(Pulse *pulse, GetBitContext *gb,
1673  const uint16_t *swb_offset, int num_swb)
1674 {
1675  int i, pulse_swb;
1676  pulse->num_pulse = get_bits(gb, 2) + 1;
1677  pulse_swb = get_bits(gb, 6);
1678  if (pulse_swb >= num_swb)
1679  return -1;
1680  pulse->pos[0] = swb_offset[pulse_swb];
1681  pulse->pos[0] += get_bits(gb, 5);
1682  if (pulse->pos[0] >= swb_offset[num_swb])
1683  return -1;
1684  pulse->amp[0] = get_bits(gb, 4);
1685  for (i = 1; i < pulse->num_pulse; i++) {
1686  pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i - 1];
1687  if (pulse->pos[i] >= swb_offset[num_swb])
1688  return -1;
1689  pulse->amp[i] = get_bits(gb, 4);
1690  }
1691  return 0;
1692 }
1693 
1694 /**
1695  * Decode Temporal Noise Shaping data; reference: table 4.48.
1696  *
1697  * @return Returns error status. 0 - OK, !0 - error
1698  */
1700  GetBitContext *gb, const IndividualChannelStream *ics)
1701 {
1702  int w, filt, i, coef_len, coef_res, coef_compress;
1703  const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE;
1704  const int tns_max_order = is8 ? 7 : ac->oc[1].m4ac.object_type == AOT_AAC_MAIN ? 20 : 12;
1705  for (w = 0; w < ics->num_windows; w++) {
1706  if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) {
1707  coef_res = get_bits1(gb);
1708 
1709  for (filt = 0; filt < tns->n_filt[w]; filt++) {
1710  int tmp2_idx;
1711  tns->length[w][filt] = get_bits(gb, 6 - 2 * is8);
1712 
1713  if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
1714  av_log(ac->avctx, AV_LOG_ERROR,
1715  "TNS filter order %d is greater than maximum %d.\n",
1716  tns->order[w][filt], tns_max_order);
1717  tns->order[w][filt] = 0;
1718  return AVERROR_INVALIDDATA;
1719  }
1720  if (tns->order[w][filt]) {
1721  tns->direction[w][filt] = get_bits1(gb);
1722  coef_compress = get_bits1(gb);
1723  coef_len = coef_res + 3 - coef_compress;
1724  tmp2_idx = 2 * coef_compress + coef_res;
1725 
1726  for (i = 0; i < tns->order[w][filt]; i++)
1727  tns->coef[w][filt][i] = tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)];
1728  }
1729  }
1730  }
1731  }
1732  return 0;
1733 }
1734 
1735 /**
1736  * Decode Mid/Side data; reference: table 4.54.
1737  *
1738  * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
1739  * [1] mask is decoded from bitstream; [2] mask is all 1s;
1740  * [3] reserved for scalable AAC
1741  */
1743  int ms_present)
1744 {
1745  int idx;
1746  int max_idx = cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb;
1747  if (ms_present == 1) {
1748  for (idx = 0; idx < max_idx; idx++)
1749  cpe->ms_mask[idx] = get_bits1(gb);
1750  } else if (ms_present == 2) {
1751  memset(cpe->ms_mask, 1, max_idx * sizeof(cpe->ms_mask[0]));
1752  }
1753 }
1754 
1755 /**
1756  * Decode spectral data; reference: table 4.50.
1757  * Dequantize and scale spectral data; reference: 4.6.3.3.
1758  *
1759  * @param coef array of dequantized, scaled spectral data
1760  * @param sf array of scalefactors or intensity stereo positions
1761  * @param pulse_present set if pulses are present
1762  * @param pulse pointer to pulse data struct
1763  * @param band_type array of the used band type
1764  *
1765  * @return Returns error status. 0 - OK, !0 - error
1766  */
1768  GetBitContext *gb, const INTFLOAT sf[120],
1769  int pulse_present, const Pulse *pulse,
1770  const IndividualChannelStream *ics,
1771  enum BandType band_type[120])
1772 {
1773  int i, k, g, idx = 0;
1774  const int c = 1024 / ics->num_windows;
1775  const uint16_t *offsets = ics->swb_offset;
1776  INTFLOAT *coef_base = coef;
1777 
1778  for (g = 0; g < ics->num_windows; g++)
1779  memset(coef + g * 128 + offsets[ics->max_sfb], 0,
1780  sizeof(INTFLOAT) * (c - offsets[ics->max_sfb]));
1781 
1782  for (g = 0; g < ics->num_window_groups; g++) {
1783  unsigned g_len = ics->group_len[g];
1784 
1785  for (i = 0; i < ics->max_sfb; i++, idx++) {
1786  const unsigned cbt_m1 = band_type[idx] - 1;
1787  INTFLOAT *cfo = coef + offsets[i];
1788  int off_len = offsets[i + 1] - offsets[i];
1789  int group;
1790 
1791  if (cbt_m1 >= INTENSITY_BT2 - 1) {
1792  for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) {
1793  memset(cfo, 0, off_len * sizeof(*cfo));
1794  }
1795  } else if (cbt_m1 == NOISE_BT - 1) {
1796  for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) {
1797  INTFLOAT band_energy;
1798 #if USE_FIXED
1799  for (k = 0; k < off_len; k++) {
1801  cfo[k] = ac->random_state >> 3;
1802  }
1803 
1804  band_energy = ac->fdsp->scalarproduct_fixed(cfo, cfo, off_len);
1805  band_energy = fixed_sqrt(band_energy, 31);
1806  noise_scale(cfo, sf[idx], band_energy, off_len);
1807 #else
1808  float scale;
1809 
1810  for (k = 0; k < off_len; k++) {
1812  cfo[k] = ac->random_state;
1813  }
1814 
1815  band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len);
1816  scale = sf[idx] / sqrtf(band_energy);
1817  ac->fdsp->vector_fmul_scalar(cfo, cfo, scale, off_len);
1818 #endif /* USE_FIXED */
1819  }
1820  } else {
1821 #if !USE_FIXED
1822  const float *vq = ff_aac_codebook_vector_vals[cbt_m1];
1823 #endif /* !USE_FIXED */
1824  const VLCElem *vlc_tab = vlc_spectral[cbt_m1].table;
1825  OPEN_READER(re, gb);
1826 
1827  switch (cbt_m1 >> 1) {
1828  case 0:
1829  for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) {
1830  INTFLOAT *cf = cfo;
1831  int len = off_len;
1832 
1833  do {
1834  int code;
1835  unsigned cb_idx;
1836 
1837  UPDATE_CACHE(re, gb);
1838  GET_VLC(code, re, gb, vlc_tab, 8, 2);
1839  cb_idx = code;
1840 #if USE_FIXED
1841  cf = DEC_SQUAD(cf, cb_idx);
1842 #else
1843  cf = VMUL4(cf, vq, cb_idx, sf + idx);
1844 #endif /* USE_FIXED */
1845  } while (len -= 4);
1846  }
1847  break;
1848 
1849  case 1:
1850  for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) {
1851  INTFLOAT *cf = cfo;
1852  int len = off_len;
1853 
1854  do {
1855  int code;
1856  unsigned nnz;
1857  unsigned cb_idx;
1858  uint32_t bits;
1859 
1860  UPDATE_CACHE(re, gb);
1861  GET_VLC(code, re, gb, vlc_tab, 8, 2);
1862  cb_idx = code;
1863  nnz = cb_idx >> 8 & 15;
1864  bits = nnz ? GET_CACHE(re, gb) : 0;
1865  LAST_SKIP_BITS(re, gb, nnz);
1866 #if USE_FIXED
1867  cf = DEC_UQUAD(cf, cb_idx, bits);
1868 #else
1869  cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx);
1870 #endif /* USE_FIXED */
1871  } while (len -= 4);
1872  }
1873  break;
1874 
1875  case 2:
1876  for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) {
1877  INTFLOAT *cf = cfo;
1878  int len = off_len;
1879 
1880  do {
1881  int code;
1882  unsigned cb_idx;
1883 
1884  UPDATE_CACHE(re, gb);
1885  GET_VLC(code, re, gb, vlc_tab, 8, 2);
1886  cb_idx = code;
1887 #if USE_FIXED
1888  cf = DEC_SPAIR(cf, cb_idx);
1889 #else
1890  cf = VMUL2(cf, vq, cb_idx, sf + idx);
1891 #endif /* USE_FIXED */
1892  } while (len -= 2);
1893  }
1894  break;
1895 
1896  case 3:
1897  case 4:
1898  for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) {
1899  INTFLOAT *cf = cfo;
1900  int len = off_len;
1901 
1902  do {
1903  int code;
1904  unsigned nnz;
1905  unsigned cb_idx;
1906  unsigned sign;
1907 
1908  UPDATE_CACHE(re, gb);
1909  GET_VLC(code, re, gb, vlc_tab, 8, 2);
1910  cb_idx = code;
1911  nnz = cb_idx >> 8 & 15;
1912  sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0;
1913  LAST_SKIP_BITS(re, gb, nnz);
1914 #if USE_FIXED
1915  cf = DEC_UPAIR(cf, cb_idx, sign);
1916 #else
1917  cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx);
1918 #endif /* USE_FIXED */
1919  } while (len -= 2);
1920  }
1921  break;
1922 
1923  default:
1924  for (group = 0; group < (AAC_SIGNE)g_len; group++, cfo+=128) {
1925 #if USE_FIXED
1926  int *icf = cfo;
1927  int v;
1928 #else
1929  float *cf = cfo;
1930  uint32_t *icf = (uint32_t *) cf;
1931 #endif /* USE_FIXED */
1932  int len = off_len;
1933 
1934  do {
1935  int code;
1936  unsigned nzt, nnz;
1937  unsigned cb_idx;
1938  uint32_t bits;
1939  int j;
1940 
1941  UPDATE_CACHE(re, gb);
1942  GET_VLC(code, re, gb, vlc_tab, 8, 2);
1943  cb_idx = code;
1944 
1945  if (cb_idx == 0x0000) {
1946  *icf++ = 0;
1947  *icf++ = 0;
1948  continue;
1949  }
1950 
1951  nnz = cb_idx >> 12;
1952  nzt = cb_idx >> 8;
1953  bits = SHOW_UBITS(re, gb, nnz) << (32-nnz);
1954  LAST_SKIP_BITS(re, gb, nnz);
1955 
1956  for (j = 0; j < 2; j++) {
1957  if (nzt & 1<<j) {
1958  uint32_t b;
1959  int n;
1960  /* The total length of escape_sequence must be < 22 bits according
1961  to the specification (i.e. max is 111111110xxxxxxxxxxxx). */
1962  UPDATE_CACHE(re, gb);
1963  b = GET_CACHE(re, gb);
1964  b = 31 - av_log2(~b);
1965 
1966  if (b > 8) {
1967  av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
1968  return AVERROR_INVALIDDATA;
1969  }
1970 
1971  SKIP_BITS(re, gb, b + 1);
1972  b += 4;
1973  n = (1 << b) + SHOW_UBITS(re, gb, b);
1974  LAST_SKIP_BITS(re, gb, b);
1975 #if USE_FIXED
1976  v = n;
1977  if (bits & 1U<<31)
1978  v = -v;
1979  *icf++ = v;
1980 #else
1981  *icf++ = ff_cbrt_tab[n] | (bits & 1U<<31);
1982 #endif /* USE_FIXED */
1983  bits <<= 1;
1984  } else {
1985 #if USE_FIXED
1986  v = cb_idx & 15;
1987  if (bits & 1U<<31)
1988  v = -v;
1989  *icf++ = v;
1990 #else
1991  unsigned v = ((const uint32_t*)vq)[cb_idx & 15];
1992  *icf++ = (bits & 1U<<31) | v;
1993 #endif /* USE_FIXED */
1994  bits <<= !!v;
1995  }
1996  cb_idx >>= 4;
1997  }
1998  } while (len -= 2);
1999 #if !USE_FIXED
2000  ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len);
2001 #endif /* !USE_FIXED */
2002  }
2003  }
2004 
2005  CLOSE_READER(re, gb);
2006  }
2007  }
2008  coef += g_len << 7;
2009  }
2010 
2011  if (pulse_present) {
2012  idx = 0;
2013  for (i = 0; i < pulse->num_pulse; i++) {
2014  INTFLOAT co = coef_base[ pulse->pos[i] ];
2015  while (offsets[idx + 1] <= pulse->pos[i])
2016  idx++;
2017  if (band_type[idx] != NOISE_BT && sf[idx]) {
2018  INTFLOAT ico = -pulse->amp[i];
2019 #if USE_FIXED
2020  if (co) {
2021  ico = co + (co > 0 ? -ico : ico);
2022  }
2023  coef_base[ pulse->pos[i] ] = ico;
2024 #else
2025  if (co) {
2026  co /= sf[idx];
2027  ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
2028  }
2029  coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx];
2030 #endif /* USE_FIXED */
2031  }
2032  }
2033  }
2034 #if USE_FIXED
2035  coef = coef_base;
2036  idx = 0;
2037  for (g = 0; g < ics->num_window_groups; g++) {
2038  unsigned g_len = ics->group_len[g];
2039 
2040  for (i = 0; i < ics->max_sfb; i++, idx++) {
2041  const unsigned cbt_m1 = band_type[idx] - 1;
2042  int *cfo = coef + offsets[i];
2043  int off_len = offsets[i + 1] - offsets[i];
2044  int group;
2045 
2046  if (cbt_m1 < NOISE_BT - 1) {
2047  for (group = 0; group < (int)g_len; group++, cfo+=128) {
2048  ac->vector_pow43(cfo, off_len);
2049  ac->subband_scale(cfo, cfo, sf[idx], 34, off_len, ac->avctx);
2050  }
2051  }
2052  }
2053  coef += g_len << 7;
2054  }
2055 #endif /* USE_FIXED */
2056  return 0;
2057 }
2058 
2059 /**
2060  * Apply AAC-Main style frequency domain prediction.
2061  */
2063 {
2064  int sfb, k;
2065 
2066  if (!sce->ics.predictor_initialized) {
2068  sce->ics.predictor_initialized = 1;
2069  }
2070 
2071  if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
2072  for (sfb = 0;
2073  sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index];
2074  sfb++) {
2075  for (k = sce->ics.swb_offset[sfb];
2076  k < sce->ics.swb_offset[sfb + 1];
2077  k++) {
2078  predict(&sce->predictor_state[k], &sce->coeffs[k],
2079  sce->ics.predictor_present &&
2080  sce->ics.prediction_used[sfb]);
2081  }
2082  }
2083  if (sce->ics.predictor_reset_group)
2085  sce->ics.predictor_reset_group);
2086  } else
2088 }
2089 
2091 {
2092  // wd_num, wd_test, aloc_size
2093  static const uint8_t gain_mode[4][3] = {
2094  {1, 0, 5}, // ONLY_LONG_SEQUENCE = 0,
2095  {2, 1, 2}, // LONG_START_SEQUENCE,
2096  {8, 0, 2}, // EIGHT_SHORT_SEQUENCE,
2097  {2, 1, 5}, // LONG_STOP_SEQUENCE
2098  };
2099 
2100  const int mode = sce->ics.window_sequence[0];
2101  uint8_t bd, wd, ad;
2102 
2103  // FIXME: Store the gain control data on |sce| and do something with it.
2104  uint8_t max_band = get_bits(gb, 2);
2105  for (bd = 0; bd < max_band; bd++) {
2106  for (wd = 0; wd < gain_mode[mode][0]; wd++) {
2107  uint8_t adjust_num = get_bits(gb, 3);
2108  for (ad = 0; ad < adjust_num; ad++) {
2109  skip_bits(gb, 4 + ((wd == 0 && gain_mode[mode][1])
2110  ? 4
2111  : gain_mode[mode][2]));
2112  }
2113  }
2114  }
2115 }
2116 
2117 /**
2118  * Decode an individual_channel_stream payload; reference: table 4.44.
2119  *
2120  * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information.
2121  * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.)
2122  *
2123  * @return Returns error status. 0 - OK, !0 - error
2124  */
2126  GetBitContext *gb, int common_window, int scale_flag)
2127 {
2128  Pulse pulse;
2129  TemporalNoiseShaping *tns = &sce->tns;
2130  IndividualChannelStream *ics = &sce->ics;
2131  INTFLOAT *out = sce->coeffs;
2132  int global_gain, eld_syntax, er_syntax, pulse_present = 0;
2133  int ret;
2134 
2135  eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
2136  er_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_LC ||
2137  ac->oc[1].m4ac.object_type == AOT_ER_AAC_LTP ||
2138  ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD ||
2139  ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
2140 
2141  /* This assignment is to silence a GCC warning about the variable being used
2142  * uninitialized when in fact it always is.
2143  */
2144  pulse.num_pulse = 0;
2145 
2146  global_gain = get_bits(gb, 8);
2147 
2148  if (!common_window && !scale_flag) {
2149  ret = decode_ics_info(ac, ics, gb);
2150  if (ret < 0)
2151  goto fail;
2152  }
2153 
2154  if ((ret = decode_band_types(ac, sce->band_type,
2155  sce->band_type_run_end, gb, ics)) < 0)
2156  goto fail;
2157  if ((ret = decode_scalefactors(ac, sce->sf, gb, global_gain, ics,
2158  sce->band_type, sce->band_type_run_end)) < 0)
2159  goto fail;
2160 
2161  pulse_present = 0;
2162  if (!scale_flag) {
2163  if (!eld_syntax && (pulse_present = get_bits1(gb))) {
2164  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2165  av_log(ac->avctx, AV_LOG_ERROR,
2166  "Pulse tool not allowed in eight short sequence.\n");
2168  goto fail;
2169  }
2170  if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) {
2171  av_log(ac->avctx, AV_LOG_ERROR,
2172  "Pulse data corrupt or invalid.\n");
2174  goto fail;
2175  }
2176  }
2177  tns->present = get_bits1(gb);
2178  if (tns->present && !er_syntax) {
2179  ret = decode_tns(ac, tns, gb, ics);
2180  if (ret < 0)
2181  goto fail;
2182  }
2183  if (!eld_syntax && get_bits1(gb)) {
2184  decode_gain_control(sce, gb);
2185  if (!ac->warned_gain_control) {
2186  avpriv_report_missing_feature(ac->avctx, "Gain control");
2187  ac->warned_gain_control = 1;
2188  }
2189  }
2190  // I see no textual basis in the spec for this occurring after SSR gain
2191  // control, but this is what both reference and real implmentations do
2192  if (tns->present && er_syntax) {
2193  ret = decode_tns(ac, tns, gb, ics);
2194  if (ret < 0)
2195  goto fail;
2196  }
2197  }
2198 
2199  ret = decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present,
2200  &pulse, ics, sce->band_type);
2201  if (ret < 0)
2202  goto fail;
2203 
2204  if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window)
2205  apply_prediction(ac, sce);
2206 
2207  return 0;
2208 fail:
2209  tns->present = 0;
2210  return ret;
2211 }
2212 
2213 /**
2214  * Mid/Side stereo decoding; reference: 4.6.8.1.3.
2215  */
2217 {
2218  const IndividualChannelStream *ics = &cpe->ch[0].ics;
2219  INTFLOAT *ch0 = cpe->ch[0].coeffs;
2220  INTFLOAT *ch1 = cpe->ch[1].coeffs;
2221  int g, i, group, idx = 0;
2222  const uint16_t *offsets = ics->swb_offset;
2223  for (g = 0; g < ics->num_window_groups; g++) {
2224  for (i = 0; i < ics->max_sfb; i++, idx++) {
2225  if (cpe->ms_mask[idx] &&
2226  cpe->ch[0].band_type[idx] < NOISE_BT &&
2227  cpe->ch[1].band_type[idx] < NOISE_BT) {
2228 #if USE_FIXED
2229  for (group = 0; group < ics->group_len[g]; group++) {
2230  ac->fdsp->butterflies_fixed(ch0 + group * 128 + offsets[i],
2231  ch1 + group * 128 + offsets[i],
2232  offsets[i+1] - offsets[i]);
2233 #else
2234  for (group = 0; group < ics->group_len[g]; group++) {
2235  ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[i],
2236  ch1 + group * 128 + offsets[i],
2237  offsets[i+1] - offsets[i]);
2238 #endif /* USE_FIXED */
2239  }
2240  }
2241  }
2242  ch0 += ics->group_len[g] * 128;
2243  ch1 += ics->group_len[g] * 128;
2244  }
2245 }
2246 
2247 /**
2248  * intensity stereo decoding; reference: 4.6.8.2.3
2249  *
2250  * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
2251  * [1] mask is decoded from bitstream; [2] mask is all 1s;
2252  * [3] reserved for scalable AAC
2253  */
2255  ChannelElement *cpe, int ms_present)
2256 {
2257  const IndividualChannelStream *ics = &cpe->ch[1].ics;
2258  SingleChannelElement *sce1 = &cpe->ch[1];
2259  INTFLOAT *coef0 = cpe->ch[0].coeffs, *coef1 = cpe->ch[1].coeffs;
2260  const uint16_t *offsets = ics->swb_offset;
2261  int g, group, i, idx = 0;
2262  int c;
2263  INTFLOAT scale;
2264  for (g = 0; g < ics->num_window_groups; g++) {
2265  for (i = 0; i < ics->max_sfb;) {
2266  if (sce1->band_type[idx] == INTENSITY_BT ||
2267  sce1->band_type[idx] == INTENSITY_BT2) {
2268  const int bt_run_end = sce1->band_type_run_end[idx];
2269  for (; i < bt_run_end; i++, idx++) {
2270  c = -1 + 2 * (sce1->band_type[idx] - 14);
2271  if (ms_present)
2272  c *= 1 - 2 * cpe->ms_mask[idx];
2273  scale = c * sce1->sf[idx];
2274  for (group = 0; group < ics->group_len[g]; group++)
2275 #if USE_FIXED
2276  ac->subband_scale(coef1 + group * 128 + offsets[i],
2277  coef0 + group * 128 + offsets[i],
2278  scale,
2279  23,
2280  offsets[i + 1] - offsets[i] ,ac->avctx);
2281 #else
2282  ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[i],
2283  coef0 + group * 128 + offsets[i],
2284  scale,
2285  offsets[i + 1] - offsets[i]);
2286 #endif /* USE_FIXED */
2287  }
2288  } else {
2289  int bt_run_end = sce1->band_type_run_end[idx];
2290  idx += bt_run_end - i;
2291  i = bt_run_end;
2292  }
2293  }
2294  coef0 += ics->group_len[g] * 128;
2295  coef1 += ics->group_len[g] * 128;
2296  }
2297 }
2298 
2299 /**
2300  * Decode a channel_pair_element; reference: table 4.4.
2301  *
2302  * @return Returns error status. 0 - OK, !0 - error
2303  */
2305 {
2306  int i, ret, common_window, ms_present = 0;
2307  int eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
2308 
2309  common_window = eld_syntax || get_bits1(gb);
2310  if (common_window) {
2311  if (decode_ics_info(ac, &cpe->ch[0].ics, gb))
2312  return AVERROR_INVALIDDATA;
2313  i = cpe->ch[1].ics.use_kb_window[0];
2314  cpe->ch[1].ics = cpe->ch[0].ics;
2315  cpe->ch[1].ics.use_kb_window[1] = i;
2316  if (cpe->ch[1].ics.predictor_present &&
2317  (ac->oc[1].m4ac.object_type != AOT_AAC_MAIN))
2318  if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1)))
2319  decode_ltp(&cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb);
2320  ms_present = get_bits(gb, 2);
2321  if (ms_present == 3) {
2322  av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
2323  return AVERROR_INVALIDDATA;
2324  } else if (ms_present)
2325  decode_mid_side_stereo(cpe, gb, ms_present);
2326  }
2327  if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0)))
2328  return ret;
2329  if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0)))
2330  return ret;
2331 
2332  if (common_window) {
2333  if (ms_present)
2334  apply_mid_side_stereo(ac, cpe);
2335  if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN) {
2336  apply_prediction(ac, &cpe->ch[0]);
2337  apply_prediction(ac, &cpe->ch[1]);
2338  }
2339  }
2340 
2341  apply_intensity_stereo(ac, cpe, ms_present);
2342  return 0;
2343 }
2344 
2345 static const float cce_scale[] = {
2346  1.09050773266525765921, //2^(1/8)
2347  1.18920711500272106672, //2^(1/4)
2348  M_SQRT2,
2349  2,
2350 };
2351 
2352 /**
2353  * Decode coupling_channel_element; reference: table 4.8.
2354  *
2355  * @return Returns error status. 0 - OK, !0 - error
2356  */
2358 {
2359  int num_gain = 0;
2360  int c, g, sfb, ret;
2361  int sign;
2362  INTFLOAT scale;
2363  SingleChannelElement *sce = &che->ch[0];
2364  ChannelCoupling *coup = &che->coup;
2365 
2366  coup->coupling_point = 2 * get_bits1(gb);
2367  coup->num_coupled = get_bits(gb, 3);
2368  for (c = 0; c <= coup->num_coupled; c++) {
2369  num_gain++;
2370  coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE;
2371  coup->id_select[c] = get_bits(gb, 4);
2372  if (coup->type[c] == TYPE_CPE) {
2373  coup->ch_select[c] = get_bits(gb, 2);
2374  if (coup->ch_select[c] == 3)
2375  num_gain++;
2376  } else
2377  coup->ch_select[c] = 2;
2378  }
2379  coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1);
2380 
2381  sign = get_bits(gb, 1);
2382 #if USE_FIXED
2383  scale = get_bits(gb, 2);
2384 #else
2385  scale = cce_scale[get_bits(gb, 2)];
2386 #endif
2387 
2388  if ((ret = decode_ics(ac, sce, gb, 0, 0)))
2389  return ret;
2390 
2391  for (c = 0; c < num_gain; c++) {
2392  int idx = 0;
2393  int cge = 1;
2394  int gain = 0;
2395  INTFLOAT gain_cache = FIXR10(1.);
2396  if (c) {
2397  cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb);
2398  gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0;
2399  gain_cache = GET_GAIN(scale, gain);
2400 #if USE_FIXED
2401  if ((abs(gain_cache)-1024) >> 3 > 30)
2402  return AVERROR(ERANGE);
2403 #endif
2404  }
2405  if (coup->coupling_point == AFTER_IMDCT) {
2406  coup->gain[c][0] = gain_cache;
2407  } else {
2408  for (g = 0; g < sce->ics.num_window_groups; g++) {
2409  for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) {
2410  if (sce->band_type[idx] != ZERO_BT) {
2411  if (!cge) {
2412  int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
2413  if (t) {
2414  int s = 1;
2415  t = gain += t;
2416  if (sign) {
2417  s -= 2 * (t & 0x1);
2418  t >>= 1;
2419  }
2420  gain_cache = GET_GAIN(scale, t) * s;
2421 #if USE_FIXED
2422  if ((abs(gain_cache)-1024) >> 3 > 30)
2423  return AVERROR(ERANGE);
2424 #endif
2425  }
2426  }
2427  coup->gain[c][idx] = gain_cache;
2428  }
2429  }
2430  }
2431  }
2432  }
2433  return 0;
2434 }
2435 
2436 /**
2437  * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53.
2438  *
2439  * @return Returns number of bytes consumed.
2440  */
2442  GetBitContext *gb)
2443 {
2444  int i;
2445  int num_excl_chan = 0;
2446 
2447  do {
2448  for (i = 0; i < 7; i++)
2449  che_drc->exclude_mask[num_excl_chan++] = get_bits1(gb);
2450  } while (num_excl_chan < MAX_CHANNELS - 7 && get_bits1(gb));
2451 
2452  return num_excl_chan / 7;
2453 }
2454 
2455 /**
2456  * Decode dynamic range information; reference: table 4.52.
2457  *
2458  * @return Returns number of bytes consumed.
2459  */
2461  GetBitContext *gb)
2462 {
2463  int n = 1;
2464  int drc_num_bands = 1;
2465  int i;
2466 
2467  /* pce_tag_present? */
2468  if (get_bits1(gb)) {
2469  che_drc->pce_instance_tag = get_bits(gb, 4);
2470  skip_bits(gb, 4); // tag_reserved_bits
2471  n++;
2472  }
2473 
2474  /* excluded_chns_present? */
2475  if (get_bits1(gb)) {
2476  n += decode_drc_channel_exclusions(che_drc, gb);
2477  }
2478 
2479  /* drc_bands_present? */
2480  if (get_bits1(gb)) {
2481  che_drc->band_incr = get_bits(gb, 4);
2482  che_drc->interpolation_scheme = get_bits(gb, 4);
2483  n++;
2484  drc_num_bands += che_drc->band_incr;
2485  for (i = 0; i < drc_num_bands; i++) {
2486  che_drc->band_top[i] = get_bits(gb, 8);
2487  n++;
2488  }
2489  }
2490 
2491  /* prog_ref_level_present? */
2492  if (get_bits1(gb)) {
2493  che_drc->prog_ref_level = get_bits(gb, 7);
2494  skip_bits1(gb); // prog_ref_level_reserved_bits
2495  n++;
2496  }
2497 
2498  for (i = 0; i < drc_num_bands; i++) {
2499  che_drc->dyn_rng_sgn[i] = get_bits1(gb);
2500  che_drc->dyn_rng_ctl[i] = get_bits(gb, 7);
2501  n++;
2502  }
2503 
2504  return n;
2505 }
2506 
2507 static int decode_fill(AACContext *ac, GetBitContext *gb, int len) {
2508  uint8_t buf[256];
2509  int i, major, minor;
2510 
2511  if (len < 13+7*8)
2512  goto unknown;
2513 
2514  get_bits(gb, 13); len -= 13;
2515 
2516  for(i=0; i+1<sizeof(buf) && len>=8; i++, len-=8)
2517  buf[i] = get_bits(gb, 8);
2518 
2519  buf[i] = 0;
2520  if (ac->avctx->debug & FF_DEBUG_PICT_INFO)
2521  av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf);
2522 
2523  if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){
2524  ac->avctx->internal->skip_samples = 1024;
2525  }
2526 
2527 unknown:
2528  skip_bits_long(gb, len);
2529 
2530  return 0;
2531 }
2532 
2533 /**
2534  * Decode extension data (incomplete); reference: table 4.51.
2535  *
2536  * @param cnt length of TYPE_FIL syntactic element in bytes
2537  *
2538  * @return Returns number of bytes consumed
2539  */
2541  ChannelElement *che, enum RawDataBlockType elem_type)
2542 {
2543  int crc_flag = 0;
2544  int res = cnt;
2545  int type = get_bits(gb, 4);
2546 
2547  if (ac->avctx->debug & FF_DEBUG_STARTCODE)
2548  av_log(ac->avctx, AV_LOG_DEBUG, "extension type: %d len:%d\n", type, cnt);
2549 
2550  switch (type) { // extension type
2551  case EXT_SBR_DATA_CRC:
2552  crc_flag++;
2553  case EXT_SBR_DATA:
2554  if (!che) {
2555  av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n");
2556  return res;
2557  } else if (ac->oc[1].m4ac.frame_length_short) {
2558  if (!ac->warned_960_sbr)
2560  "SBR with 960 frame length");
2561  ac->warned_960_sbr = 1;
2562  skip_bits_long(gb, 8 * cnt - 4);
2563  return res;
2564  } else if (!ac->oc[1].m4ac.sbr) {
2565  av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n");
2566  skip_bits_long(gb, 8 * cnt - 4);
2567  return res;
2568  } else if (ac->oc[1].m4ac.sbr == -1 && ac->oc[1].status == OC_LOCKED) {
2569  av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n");
2570  skip_bits_long(gb, 8 * cnt - 4);
2571  return res;
2572  } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED &&
2573  ac->avctx->ch_layout.nb_channels == 1) {
2574  ac->oc[1].m4ac.sbr = 1;
2575  ac->oc[1].m4ac.ps = 1;
2577  output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags,
2578  ac->oc[1].status, 1);
2579  } else {
2580  ac->oc[1].m4ac.sbr = 1;
2582  }
2583  res = AAC_RENAME(ff_decode_sbr_extension)(ac, &che->sbr, gb, crc_flag, cnt, elem_type);
2584  break;
2585  case EXT_DYNAMIC_RANGE:
2586  res = decode_dynamic_range(&ac->che_drc, gb);
2587  break;
2588  case EXT_FILL:
2589  decode_fill(ac, gb, 8 * cnt - 4);
2590  break;
2591  case EXT_FILL_DATA:
2592  case EXT_DATA_ELEMENT:
2593  default:
2594  skip_bits_long(gb, 8 * cnt - 4);
2595  break;
2596  };
2597  return res;
2598 }
2599 
2600 /**
2601  * Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4.6.9.3.
2602  *
2603  * @param decode 1 if tool is used normally, 0 if tool is used in LTP.
2604  * @param coef spectral coefficients
2605  */
2606 static void apply_tns(INTFLOAT coef_param[1024], TemporalNoiseShaping *tns,
2607  IndividualChannelStream *ics, int decode)
2608 {
2609  const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb);
2610  int w, filt, m, i;
2611  int bottom, top, order, start, end, size, inc;
2612  INTFLOAT lpc[TNS_MAX_ORDER];
2614  UINTFLOAT *coef = coef_param;
2615 
2616  if(!mmm)
2617  return;
2618 
2619  for (w = 0; w < ics->num_windows; w++) {
2620  bottom = ics->num_swb;
2621  for (filt = 0; filt < tns->n_filt[w]; filt++) {
2622  top = bottom;
2623  bottom = FFMAX(0, top - tns->length[w][filt]);
2624  order = tns->order[w][filt];
2625  if (order == 0)
2626  continue;
2627 
2628  // tns_decode_coef
2629  AAC_RENAME(compute_lpc_coefs)(tns->coef[w][filt], order, lpc, 0, 0, 0);
2630 
2631  start = ics->swb_offset[FFMIN(bottom, mmm)];
2632  end = ics->swb_offset[FFMIN( top, mmm)];
2633  if ((size = end - start) <= 0)
2634  continue;
2635  if (tns->direction[w][filt]) {
2636  inc = -1;
2637  start = end - 1;
2638  } else {
2639  inc = 1;
2640  }
2641  start += w * 128;
2642 
2643  if (decode) {
2644  // ar filter
2645  for (m = 0; m < size; m++, start += inc)
2646  for (i = 1; i <= FFMIN(m, order); i++)
2647  coef[start] -= AAC_MUL26((INTFLOAT)coef[start - i * inc], lpc[i - 1]);
2648  } else {
2649  // ma filter
2650  for (m = 0; m < size; m++, start += inc) {
2651  tmp[0] = coef[start];
2652  for (i = 1; i <= FFMIN(m, order); i++)
2653  coef[start] += AAC_MUL26(tmp[i], lpc[i - 1]);
2654  for (i = order; i > 0; i--)
2655  tmp[i] = tmp[i - 1];
2656  }
2657  }
2658  }
2659  }
2660 }
2661 
2662 /**
2663  * Apply windowing and MDCT to obtain the spectral
2664  * coefficient from the predicted sample by LTP.
2665  */
2668 {
2669  const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
2670  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
2671  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
2672  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
2673 
2674  if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
2675  ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024);
2676  } else {
2677  memset(in, 0, 448 * sizeof(*in));
2678  ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128);
2679  }
2680  if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
2681  ac->fdsp->vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
2682  } else {
2683  ac->fdsp->vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
2684  memset(in + 1024 + 576, 0, 448 * sizeof(*in));
2685  }
2686  ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in);
2687 }
2688 
2689 /**
2690  * Apply the long term prediction
2691  */
2693 {
2694  const LongTermPrediction *ltp = &sce->ics.ltp;
2695  const uint16_t *offsets = sce->ics.swb_offset;
2696  int i, sfb;
2697 
2698  if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
2699  INTFLOAT *predTime = sce->ret;
2700  INTFLOAT *predFreq = ac->buf_mdct;
2701  int16_t num_samples = 2048;
2702 
2703  if (ltp->lag < 1024)
2704  num_samples = ltp->lag + 1024;
2705  for (i = 0; i < num_samples; i++)
2706  predTime[i] = AAC_MUL30(sce->ltp_state[i + 2048 - ltp->lag], ltp->coef);
2707  memset(&predTime[i], 0, (2048 - i) * sizeof(*predTime));
2708 
2709  ac->windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics);
2710 
2711  if (sce->tns.present)
2712  ac->apply_tns(predFreq, &sce->tns, &sce->ics, 0);
2713 
2714  for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)
2715  if (ltp->used[sfb])
2716  for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
2717  sce->coeffs[i] += (UINTFLOAT)predFreq[i];
2718  }
2719 }
2720 
2721 /**
2722  * Update the LTP buffer for next frame
2723  */
2725 {
2726  IndividualChannelStream *ics = &sce->ics;
2727  INTFLOAT *saved = sce->saved;
2728  INTFLOAT *saved_ltp = sce->coeffs;
2729  const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
2730  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
2731  int i;
2732 
2733  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2734  memcpy(saved_ltp, saved, 512 * sizeof(*saved_ltp));
2735  memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
2736  ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
2737 
2738  for (i = 0; i < 64; i++)
2739  saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], swindow[63 - i]);
2740  } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
2741  memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(*saved_ltp));
2742  memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
2743  ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
2744 
2745  for (i = 0; i < 64; i++)
2746  saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], swindow[63 - i]);
2747  } else { // LONG_STOP or ONLY_LONG
2748  ac->fdsp->vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512);
2749 
2750  for (i = 0; i < 512; i++)
2751  saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], lwindow[511 - i]);
2752  }
2753 
2754  memcpy(sce->ltp_state, sce->ltp_state+1024, 1024 * sizeof(*sce->ltp_state));
2755  memcpy(sce->ltp_state+1024, sce->ret, 1024 * sizeof(*sce->ltp_state));
2756  memcpy(sce->ltp_state+2048, saved_ltp, 1024 * sizeof(*sce->ltp_state));
2757 }
2758 
2759 /**
2760  * Conduct IMDCT and windowing.
2761  */
2763 {
2764  IndividualChannelStream *ics = &sce->ics;
2765  INTFLOAT *in = sce->coeffs;
2766  INTFLOAT *out = sce->ret;
2767  INTFLOAT *saved = sce->saved;
2768  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
2769  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
2770  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
2771  INTFLOAT *buf = ac->buf_mdct;
2772  INTFLOAT *temp = ac->temp;
2773  int i;
2774 
2775  // imdct
2776  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2777  for (i = 0; i < 1024; i += 128)
2778  ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i);
2779  } else {
2780  ac->mdct.imdct_half(&ac->mdct, buf, in);
2781 #if USE_FIXED
2782  for (i=0; i<1024; i++)
2783  buf[i] = (buf[i] + 4LL) >> 3;
2784 #endif /* USE_FIXED */
2785  }
2786 
2787  /* window overlapping
2788  * NOTE: To simplify the overlapping code, all 'meaningless' short to long
2789  * and long to short transitions are considered to be short to short
2790  * transitions. This leaves just two cases (long to long and short to short)
2791  * with a little special sauce for EIGHT_SHORT_SEQUENCE.
2792  */
2793  if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
2795  ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512);
2796  } else {
2797  memcpy( out, saved, 448 * sizeof(*out));
2798 
2799  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2800  ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64);
2801  ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64);
2802  ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64);
2803  ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64);
2804  ac->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64);
2805  memcpy( out + 448 + 4*128, temp, 64 * sizeof(*out));
2806  } else {
2807  ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
2808  memcpy( out + 576, buf + 64, 448 * sizeof(*out));
2809  }
2810  }
2811 
2812  // buffer update
2813  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2814  memcpy( saved, temp + 64, 64 * sizeof(*saved));
2815  ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
2816  ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
2817  ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
2818  memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
2819  } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
2820  memcpy( saved, buf + 512, 448 * sizeof(*saved));
2821  memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
2822  } else { // LONG_STOP or ONLY_LONG
2823  memcpy( saved, buf + 512, 512 * sizeof(*saved));
2824  }
2825 }
2826 
2827 /**
2828  * Conduct IMDCT and windowing.
2829  */
2831 {
2832 #if !USE_FIXED
2833  IndividualChannelStream *ics = &sce->ics;
2834  INTFLOAT *in = sce->coeffs;
2835  INTFLOAT *out = sce->ret;
2836  INTFLOAT *saved = sce->saved;
2837  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
2838  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_long_960) : AAC_RENAME(sine_960);
2839  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
2840  INTFLOAT *buf = ac->buf_mdct;
2841  INTFLOAT *temp = ac->temp;
2842  int i;
2843 
2844  // imdct
2845  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2846  for (i = 0; i < 8; i++)
2847  ac->mdct120->imdct_half(ac->mdct120, buf + i * 120, in + i * 128, 1);
2848  } else {
2849  ac->mdct960->imdct_half(ac->mdct960, buf, in, 1);
2850  }
2851 
2852  /* window overlapping
2853  * NOTE: To simplify the overlapping code, all 'meaningless' short to long
2854  * and long to short transitions are considered to be short to short
2855  * transitions. This leaves just two cases (long to long and short to short)
2856  * with a little special sauce for EIGHT_SHORT_SEQUENCE.
2857  */
2858 
2859  if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
2861  ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 480);
2862  } else {
2863  memcpy( out, saved, 420 * sizeof(*out));
2864 
2865  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2866  ac->fdsp->vector_fmul_window(out + 420 + 0*120, saved + 420, buf + 0*120, swindow_prev, 60);
2867  ac->fdsp->vector_fmul_window(out + 420 + 1*120, buf + 0*120 + 60, buf + 1*120, swindow, 60);
2868  ac->fdsp->vector_fmul_window(out + 420 + 2*120, buf + 1*120 + 60, buf + 2*120, swindow, 60);
2869  ac->fdsp->vector_fmul_window(out + 420 + 3*120, buf + 2*120 + 60, buf + 3*120, swindow, 60);
2870  ac->fdsp->vector_fmul_window(temp, buf + 3*120 + 60, buf + 4*120, swindow, 60);
2871  memcpy( out + 420 + 4*120, temp, 60 * sizeof(*out));
2872  } else {
2873  ac->fdsp->vector_fmul_window(out + 420, saved + 420, buf, swindow_prev, 60);
2874  memcpy( out + 540, buf + 60, 420 * sizeof(*out));
2875  }
2876  }
2877 
2878  // buffer update
2879  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
2880  memcpy( saved, temp + 60, 60 * sizeof(*saved));
2881  ac->fdsp->vector_fmul_window(saved + 60, buf + 4*120 + 60, buf + 5*120, swindow, 60);
2882  ac->fdsp->vector_fmul_window(saved + 180, buf + 5*120 + 60, buf + 6*120, swindow, 60);
2883  ac->fdsp->vector_fmul_window(saved + 300, buf + 6*120 + 60, buf + 7*120, swindow, 60);
2884  memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
2885  } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
2886  memcpy( saved, buf + 480, 420 * sizeof(*saved));
2887  memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
2888  } else { // LONG_STOP or ONLY_LONG
2889  memcpy( saved, buf + 480, 480 * sizeof(*saved));
2890  }
2891 #endif
2892 }
2894 {
2895  IndividualChannelStream *ics = &sce->ics;
2896  INTFLOAT *in = sce->coeffs;
2897  INTFLOAT *out = sce->ret;
2898  INTFLOAT *saved = sce->saved;
2899  INTFLOAT *buf = ac->buf_mdct;
2900 #if USE_FIXED
2901  int i;
2902 #endif /* USE_FIXED */
2903 
2904  // imdct
2905  ac->mdct.imdct_half(&ac->mdct_ld, buf, in);
2906 
2907 #if USE_FIXED
2908  for (i = 0; i < 1024; i++)
2909  buf[i] = (buf[i] + 2) >> 2;
2910 #endif /* USE_FIXED */
2911 
2912  // window overlapping
2913  if (ics->use_kb_window[1]) {
2914  // AAC LD uses a low overlap sine window instead of a KBD window
2915  memcpy(out, saved, 192 * sizeof(*out));
2916  ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, AAC_RENAME2(sine_128), 64);
2917  memcpy( out + 320, buf + 64, 192 * sizeof(*out));
2918  } else {
2919  ac->fdsp->vector_fmul_window(out, saved, buf, AAC_RENAME2(sine_512), 256);
2920  }
2921 
2922  // buffer update
2923  memcpy(saved, buf + 256, 256 * sizeof(*saved));
2924 }
2925 
2927 {
2928  UINTFLOAT *in = sce->coeffs;
2929  INTFLOAT *out = sce->ret;
2930  INTFLOAT *saved = sce->saved;
2931  INTFLOAT *buf = ac->buf_mdct;
2932  int i;
2933  const int n = ac->oc[1].m4ac.frame_length_short ? 480 : 512;
2934  const int n2 = n >> 1;
2935  const int n4 = n >> 2;
2936  const INTFLOAT *const window = n == 480 ? AAC_RENAME(ff_aac_eld_window_480) :
2938 
2939  // Inverse transform, mapped to the conventional IMDCT by
2940  // Chivukula, R.K.; Reznik, Y.A.; Devarajan, V.,
2941  // "Efficient algorithms for MPEG-4 AAC-ELD, AAC-LD and AAC-LC filterbanks,"
2942  // International Conference on Audio, Language and Image Processing, ICALIP 2008.
2943  // URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4590245&isnumber=4589950
2944  for (i = 0; i < n2; i+=2) {
2945  INTFLOAT temp;
2946  temp = in[i ]; in[i ] = -in[n - 1 - i]; in[n - 1 - i] = temp;
2947  temp = -in[i + 1]; in[i + 1] = in[n - 2 - i]; in[n - 2 - i] = temp;
2948  }
2949 #if !USE_FIXED
2950  if (n == 480)
2951  ac->mdct480->imdct_half(ac->mdct480, buf, in, 1);
2952  else
2953 #endif
2954  ac->mdct.imdct_half(&ac->mdct_ld, buf, in);
2955 
2956 #if USE_FIXED
2957  for (i = 0; i < 1024; i++)
2958  buf[i] = (buf[i] + 1) >> 1;
2959 #endif /* USE_FIXED */
2960 
2961  for (i = 0; i < n; i+=2) {
2962  buf[i] = -buf[i];
2963  }
2964  // Like with the regular IMDCT at this point we still have the middle half
2965  // of a transform but with even symmetry on the left and odd symmetry on
2966  // the right
2967 
2968  // window overlapping
2969  // The spec says to use samples [0..511] but the reference decoder uses
2970  // samples [128..639].
2971  for (i = n4; i < n2; i ++) {
2972  out[i - n4] = AAC_MUL31( buf[ n2 - 1 - i] , window[i - n4]) +
2973  AAC_MUL31( saved[ i + n2] , window[i + n - n4]) +
2974  AAC_MUL31(-saved[n + n2 - 1 - i] , window[i + 2*n - n4]) +
2975  AAC_MUL31(-saved[ 2*n + n2 + i] , window[i + 3*n - n4]);
2976  }
2977  for (i = 0; i < n2; i ++) {
2978  out[n4 + i] = AAC_MUL31( buf[ i] , window[i + n2 - n4]) +
2979  AAC_MUL31(-saved[ n - 1 - i] , window[i + n2 + n - n4]) +
2980  AAC_MUL31(-saved[ n + i] , window[i + n2 + 2*n - n4]) +
2981  AAC_MUL31( saved[2*n + n - 1 - i] , window[i + n2 + 3*n - n4]);
2982  }
2983  for (i = 0; i < n4; i ++) {
2984  out[n2 + n4 + i] = AAC_MUL31( buf[ i + n2] , window[i + n - n4]) +
2985  AAC_MUL31(-saved[n2 - 1 - i] , window[i + 2*n - n4]) +
2986  AAC_MUL31(-saved[n + n2 + i] , window[i + 3*n - n4]);
2987  }
2988 
2989  // buffer update
2990  memmove(saved + n, saved, 2 * n * sizeof(*saved));
2991  memcpy( saved, buf, n * sizeof(*saved));
2992 }
2993 
2994 /**
2995  * channel coupling transformation interface
2996  *
2997  * @param apply_coupling_method pointer to (in)dependent coupling function
2998  */
3000  enum RawDataBlockType type, int elem_id,
3001  enum CouplingPoint coupling_point,
3002  void (*apply_coupling_method)(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index))
3003 {
3004  int i, c;
3005 
3006  for (i = 0; i < MAX_ELEM_ID; i++) {
3007  ChannelElement *cce = ac->che[TYPE_CCE][i];
3008  int index = 0;
3009 
3010  if (cce && cce->coup.coupling_point == coupling_point) {
3011  ChannelCoupling *coup = &cce->coup;
3012 
3013  for (c = 0; c <= coup->num_coupled; c++) {
3014  if (coup->type[c] == type && coup->id_select[c] == elem_id) {
3015  if (coup->ch_select[c] != 1) {
3016  apply_coupling_method(ac, &cc->ch[0], cce, index);
3017  if (coup->ch_select[c] != 0)
3018  index++;
3019  }
3020  if (coup->ch_select[c] != 2)
3021  apply_coupling_method(ac, &cc->ch[1], cce, index++);
3022  } else
3023  index += 1 + (coup->ch_select[c] == 3);
3024  }
3025  }
3026  }
3027 }
3028 
3029 /**
3030  * Convert spectral data to samples, applying all supported tools as appropriate.
3031  */
3033 {
3034  int i, type;
3036  switch (ac->oc[1].m4ac.object_type) {
3037  case AOT_ER_AAC_LD:
3039  break;
3040  case AOT_ER_AAC_ELD:
3042  break;
3043  default:
3044  if (ac->oc[1].m4ac.frame_length_short)
3046  else
3048  }
3049  for (type = 3; type >= 0; type--) {
3050  for (i = 0; i < MAX_ELEM_ID; i++) {
3051  ChannelElement *che = ac->che[type][i];
3052  if (che && che->present) {
3053  if (type <= TYPE_CPE)
3055  if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) {
3056  if (che->ch[0].ics.predictor_present) {
3057  if (che->ch[0].ics.ltp.present)
3058  ac->apply_ltp(ac, &che->ch[0]);
3059  if (che->ch[1].ics.ltp.present && type == TYPE_CPE)
3060  ac->apply_ltp(ac, &che->ch[1]);
3061  }
3062  }
3063  if (che->ch[0].tns.present)
3064  ac->apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1);
3065  if (che->ch[1].tns.present)
3066  ac->apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1);
3067  if (type <= TYPE_CPE)
3069  if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) {
3070  imdct_and_window(ac, &che->ch[0]);
3071  if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
3072  ac->update_ltp(ac, &che->ch[0]);
3073  if (type == TYPE_CPE) {
3074  imdct_and_window(ac, &che->ch[1]);
3075  if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
3076  ac->update_ltp(ac, &che->ch[1]);
3077  }
3078  if (ac->oc[1].m4ac.sbr > 0) {
3079  AAC_RENAME(ff_sbr_apply)(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret);
3080  }
3081  }
3082  if (type <= TYPE_CCE)
3084 
3085 #if USE_FIXED
3086  {
3087  int j;
3088  /* preparation for resampler */
3089  for(j = 0; j<samples; j++){
3090  che->ch[0].ret[j] = (int32_t)av_clip64((int64_t)che->ch[0].ret[j]*128, INT32_MIN, INT32_MAX-0x8000)+0x8000;
3091  if(type == TYPE_CPE)
3092  che->ch[1].ret[j] = (int32_t)av_clip64((int64_t)che->ch[1].ret[j]*128, INT32_MIN, INT32_MAX-0x8000)+0x8000;
3093  }
3094  }
3095 #endif /* USE_FIXED */
3096  che->present = 0;
3097  } else if (che) {
3098  av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i);
3099  }
3100  }
3101  }
3102 }
3103 
3105 {
3106  int size;
3107  AACADTSHeaderInfo hdr_info;
3108  uint8_t layout_map[MAX_ELEM_ID*4][3];
3109  int layout_map_tags, ret;
3110 
3111  size = ff_adts_header_parse(gb, &hdr_info);
3112  if (size > 0) {
3113  if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) {
3114  // This is 2 for "VLB " audio in NSV files.
3115  // See samples/nsv/vlb_audio.
3117  "More than one AAC RDB per ADTS frame");
3118  ac->warned_num_aac_frames = 1;
3119  }
3121  if (hdr_info.chan_config) {
3122  ac->oc[1].m4ac.chan_config = hdr_info.chan_config;
3123  if ((ret = set_default_channel_config(ac, ac->avctx,
3124  layout_map,
3125  &layout_map_tags,
3126  hdr_info.chan_config)) < 0)
3127  return ret;
3128  if ((ret = output_configure(ac, layout_map, layout_map_tags,
3129  FFMAX(ac->oc[1].status,
3130  OC_TRIAL_FRAME), 0)) < 0)
3131  return ret;
3132  } else {
3133  ac->oc[1].m4ac.chan_config = 0;
3134  /**
3135  * dual mono frames in Japanese DTV can have chan_config 0
3136  * WITHOUT specifying PCE.
3137  * thus, set dual mono as default.
3138  */
3139  if (ac->dmono_mode && ac->oc[0].status == OC_NONE) {
3140  layout_map_tags = 2;
3141  layout_map[0][0] = layout_map[1][0] = TYPE_SCE;
3142  layout_map[0][2] = layout_map[1][2] = AAC_CHANNEL_FRONT;
3143  layout_map[0][1] = 0;
3144  layout_map[1][1] = 1;
3145  if (output_configure(ac, layout_map, layout_map_tags,
3146  OC_TRIAL_FRAME, 0))
3147  return -7;
3148  }
3149  }
3150  ac->oc[1].m4ac.sample_rate = hdr_info.sample_rate;
3151  ac->oc[1].m4ac.sampling_index = hdr_info.sampling_index;
3152  ac->oc[1].m4ac.object_type = hdr_info.object_type;
3153  ac->oc[1].m4ac.frame_length_short = 0;
3154  if (ac->oc[0].status != OC_LOCKED ||
3155  ac->oc[0].m4ac.chan_config != hdr_info.chan_config ||
3156  ac->oc[0].m4ac.sample_rate != hdr_info.sample_rate) {
3157  ac->oc[1].m4ac.sbr = -1;
3158  ac->oc[1].m4ac.ps = -1;
3159  }
3160  if (!hdr_info.crc_absent)
3161  skip_bits(gb, 16);
3162  }
3163  return size;
3164 }
3165 
3166 static int aac_decode_er_frame(AVCodecContext *avctx, void *data,
3167  int *got_frame_ptr, GetBitContext *gb)
3168 {
3169  AACContext *ac = avctx->priv_data;
3170  const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac;
3171  ChannelElement *che;
3172  int err, i;
3173  int samples = m4ac->frame_length_short ? 960 : 1024;
3174  int chan_config = m4ac->chan_config;
3175  int aot = m4ac->object_type;
3176 
3177  if (aot == AOT_ER_AAC_LD || aot == AOT_ER_AAC_ELD)
3178  samples >>= 1;
3179 
3180  ac->frame = data;
3181 
3182  if ((err = frame_configure_elements(avctx)) < 0)
3183  return err;
3184 
3185  // The FF_PROFILE_AAC_* defines are all object_type - 1
3186  // This may lead to an undefined profile being signaled
3187  ac->avctx->profile = aot - 1;
3188 
3189  ac->tags_mapped = 0;
3190 
3191  if (chan_config < 0 || (chan_config >= 8 && chan_config < 11) || chan_config >= 13) {
3192  avpriv_request_sample(avctx, "Unknown ER channel configuration %d",
3193  chan_config);
3194  return AVERROR_INVALIDDATA;
3195  }
3196  for (i = 0; i < tags_per_config[chan_config]; i++) {
3197  const int elem_type = aac_channel_layout_map[chan_config-1][i][0];
3198  const int elem_id = aac_channel_layout_map[chan_config-1][i][1];
3199  if (!(che=get_che(ac, elem_type, elem_id))) {
3200  av_log(ac->avctx, AV_LOG_ERROR,
3201  "channel element %d.%d is not allocated\n",
3202  elem_type, elem_id);
3203  return AVERROR_INVALIDDATA;
3204  }
3205  che->present = 1;
3206  if (aot != AOT_ER_AAC_ELD)
3207  skip_bits(gb, 4);
3208  switch (elem_type) {
3209  case TYPE_SCE:
3210  err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3211  break;
3212  case TYPE_CPE:
3213  err = decode_cpe(ac, gb, che);
3214  break;
3215  case TYPE_LFE:
3216  err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3217  break;
3218  }
3219  if (err < 0)
3220  return err;
3221  }
3222 
3224 
3225  if (!ac->frame->data[0] && samples) {
3226  av_log(avctx, AV_LOG_ERROR, "no frame data found\n");
3227  return AVERROR_INVALIDDATA;
3228  }
3229 
3230  ac->frame->nb_samples = samples;
3231  ac->frame->sample_rate = avctx->sample_rate;
3232  *got_frame_ptr = 1;
3233 
3234  skip_bits_long(gb, get_bits_left(gb));
3235  return 0;
3236 }
3237 
3239  int *got_frame_ptr, GetBitContext *gb,
3240  const AVPacket *avpkt)
3241 {
3242  AACContext *ac = avctx->priv_data;
3243  ChannelElement *che = NULL, *che_prev = NULL;
3244  enum RawDataBlockType elem_type, che_prev_type = TYPE_END;
3245  int err, elem_id;
3246  int samples = 0, multiplier, audio_found = 0, pce_found = 0;
3247  int is_dmono, sce_count = 0;
3248  int payload_alignment;
3249  uint8_t che_presence[4][MAX_ELEM_ID] = {{0}};
3250 
3251  ac->frame = frame;
3252 
3253  if (show_bits(gb, 12) == 0xfff) {
3254  if ((err = parse_adts_frame_header(ac, gb)) < 0) {
3255  av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n");
3256  goto fail;
3257  }
3258  if (ac->oc[1].m4ac.sampling_index > 12) {
3259  av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->oc[1].m4ac.sampling_index);
3260  err = AVERROR_INVALIDDATA;
3261  goto fail;
3262  }
3263  }
3264 
3265  if ((err = frame_configure_elements(avctx)) < 0)
3266  goto fail;
3267 
3268  // The FF_PROFILE_AAC_* defines are all object_type - 1
3269  // This may lead to an undefined profile being signaled
3270  ac->avctx->profile = ac->oc[1].m4ac.object_type - 1;
3271 
3272  payload_alignment = get_bits_count(gb);
3273  ac->tags_mapped = 0;
3274  // parse
3275  while ((elem_type = get_bits(gb, 3)) != TYPE_END) {
3276  elem_id = get_bits(gb, 4);
3277 
3278  if (avctx->debug & FF_DEBUG_STARTCODE)
3279  av_log(avctx, AV_LOG_DEBUG, "Elem type:%x id:%x\n", elem_type, elem_id);
3280 
3281  if (!avctx->ch_layout.nb_channels && elem_type != TYPE_PCE) {
3282  err = AVERROR_INVALIDDATA;
3283  goto fail;
3284  }
3285 
3286  if (elem_type < TYPE_DSE) {
3287  if (che_presence[elem_type][elem_id]) {
3288  int error = che_presence[elem_type][elem_id] > 1;
3289  av_log(ac->avctx, error ? AV_LOG_ERROR : AV_LOG_DEBUG, "channel element %d.%d duplicate\n",
3290  elem_type, elem_id);
3291  if (error) {
3292  err = AVERROR_INVALIDDATA;
3293  goto fail;
3294  }
3295  }
3296  che_presence[elem_type][elem_id]++;
3297 
3298  if (!(che=get_che(ac, elem_type, elem_id))) {
3299  av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n",
3300  elem_type, elem_id);
3301  err = AVERROR_INVALIDDATA;
3302  goto fail;
3303  }
3304  samples = ac->oc[1].m4ac.frame_length_short ? 960 : 1024;
3305  che->present = 1;
3306  }
3307 
3308  switch (elem_type) {
3309 
3310  case TYPE_SCE:
3311  err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3312  audio_found = 1;
3313  sce_count++;
3314  break;
3315 
3316  case TYPE_CPE:
3317  err = decode_cpe(ac, gb, che);
3318  audio_found = 1;
3319  break;
3320 
3321  case TYPE_CCE:
3322  err = decode_cce(ac, gb, che);
3323  break;
3324 
3325  case TYPE_LFE:
3326  err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3327  audio_found = 1;
3328  break;
3329 
3330  case TYPE_DSE:
3331  err = skip_data_stream_element(ac, gb);
3332  break;
3333 
3334  case TYPE_PCE: {
3335  uint8_t layout_map[MAX_ELEM_ID*4][3] = {{0}};
3336  int tags;
3337 
3338  int pushed = push_output_configuration(ac);
3339  if (pce_found && !pushed) {
3340  err = AVERROR_INVALIDDATA;
3341  goto fail;
3342  }
3343 
3344  tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb,
3345  payload_alignment);
3346  if (tags < 0) {
3347  err = tags;
3348  break;
3349  }
3350  if (pce_found) {
3351  av_log(avctx, AV_LOG_ERROR,
3352  "Not evaluating a further program_config_element as this construct is dubious at best.\n");
3354  } else {
3355  err = output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1);
3356  if (!err)
3357  ac->oc[1].m4ac.chan_config = 0;
3358  pce_found = 1;
3359  }
3360  break;
3361  }
3362 
3363  case TYPE_FIL:
3364  if (elem_id == 15)
3365  elem_id += get_bits(gb, 8) - 1;
3366  if (get_bits_left(gb) < 8 * elem_id) {
3367  av_log(avctx, AV_LOG_ERROR, "TYPE_FIL: "overread_err);
3368  err = AVERROR_INVALIDDATA;
3369  goto fail;
3370  }
3371  err = 0;
3372  while (elem_id > 0) {
3373  int ret = decode_extension_payload(ac, gb, elem_id, che_prev, che_prev_type);
3374  if (ret < 0) {
3375  err = ret;
3376  break;
3377  }
3378  elem_id -= ret;
3379  }
3380  break;
3381 
3382  default:
3383  err = AVERROR_BUG; /* should not happen, but keeps compiler happy */
3384  break;
3385  }
3386 
3387  if (elem_type < TYPE_DSE) {
3388  che_prev = che;
3389  che_prev_type = elem_type;
3390  }
3391 
3392  if (err)
3393  goto fail;
3394 
3395  if (get_bits_left(gb) < 3) {
3396  av_log(avctx, AV_LOG_ERROR, overread_err);
3397  err = AVERROR_INVALIDDATA;
3398  goto fail;
3399  }
3400  }
3401 
3402  if (!avctx->ch_layout.nb_channels) {
3403  *got_frame_ptr = 0;
3404  return 0;
3405  }
3406 
3407  multiplier = (ac->oc[1].m4ac.sbr == 1) ? ac->oc[1].m4ac.ext_sample_rate > ac->oc[1].m4ac.sample_rate : 0;
3408  samples <<= multiplier;
3409 
3411 
3412  if (ac->oc[1].status && audio_found) {
3413  avctx->sample_rate = ac->oc[1].m4ac.sample_rate << multiplier;
3414  avctx->frame_size = samples;
3415  ac->oc[1].status = OC_LOCKED;
3416  }
3417 
3418  if (multiplier)
3419  avctx->internal->skip_samples_multiplier = 2;
3420 
3421  if (!ac->frame->data[0] && samples) {
3422  av_log(avctx, AV_LOG_ERROR, "no frame data found\n");
3423  err = AVERROR_INVALIDDATA;
3424  goto fail;
3425  }
3426 
3427  if (samples) {
3428  ac->frame->nb_samples = samples;
3429  ac->frame->sample_rate = avctx->sample_rate;
3430  } else
3431  av_frame_unref(ac->frame);
3432  *got_frame_ptr = !!samples;
3433 
3434  /* for dual-mono audio (SCE + SCE) */
3435  is_dmono = ac->dmono_mode && sce_count == 2 &&
3438  if (is_dmono) {
3439  if (ac->dmono_mode == 1)
3440  frame->data[1] = frame->data[0];
3441  else if (ac->dmono_mode == 2)
3442  frame->data[0] = frame->data[1];
3443  }
3444 
3445  return 0;
3446 fail:
3448  return err;
3449 }
3450 
3452  int *got_frame_ptr, AVPacket *avpkt)
3453 {
3454  AACContext *ac = avctx->priv_data;
3455  const uint8_t *buf = avpkt->data;
3456  int buf_size = avpkt->size;
3457  GetBitContext gb;
3458  int buf_consumed;
3459  int buf_offset;
3460  int err;
3461  size_t new_extradata_size;
3462  const uint8_t *new_extradata = av_packet_get_side_data(avpkt,
3464  &new_extradata_size);
3465  size_t jp_dualmono_size;
3466  const uint8_t *jp_dualmono = av_packet_get_side_data(avpkt,
3468  &jp_dualmono_size);
3469 
3470  if (new_extradata) {
3471  /* discard previous configuration */
3472  ac->oc[1].status = OC_NONE;
3473  err = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac,
3474  new_extradata,
3475  new_extradata_size * 8LL, 1);
3476  if (err < 0) {
3477  return err;
3478  }
3479  }
3480 
3481  ac->dmono_mode = 0;
3482  if (jp_dualmono && jp_dualmono_size > 0)
3483  ac->dmono_mode = 1 + *jp_dualmono;
3484  if (ac->force_dmono_mode >= 0)
3485  ac->dmono_mode = ac->force_dmono_mode;
3486 
3487  if (INT_MAX / 8 <= buf_size)
3488  return AVERROR_INVALIDDATA;
3489 
3490  if ((err = init_get_bits8(&gb, buf, buf_size)) < 0)
3491  return err;
3492 
3493  switch (ac->oc[1].m4ac.object_type) {
3494  case AOT_ER_AAC_LC:
3495  case AOT_ER_AAC_LTP:
3496  case AOT_ER_AAC_LD:
3497  case AOT_ER_AAC_ELD:
3498  err = aac_decode_er_frame(avctx, frame, got_frame_ptr, &gb);
3499  break;
3500  default:
3501  err = aac_decode_frame_int(avctx, frame, got_frame_ptr, &gb, avpkt);
3502  }
3503  if (err < 0)
3504  return err;
3505 
3506  buf_consumed = (get_bits_count(&gb) + 7) >> 3;
3507  for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
3508  if (buf[buf_offset])
3509  break;
3510 
3511  return buf_size > buf_offset ? buf_consumed : buf_size;
3512 }
3513 
3515 {
3516  AACContext *ac = avctx->priv_data;
3517  int i, type;
3518 
3519  for (i = 0; i < MAX_ELEM_ID; i++) {
3520  for (type = 0; type < 4; type++) {
3521  if (ac->che[type][i])
3523  av_freep(&ac->che[type][i]);
3524  }
3525  }
3526 
3527  ff_mdct_end(&ac->mdct);
3528  ff_mdct_end(&ac->mdct_small);
3529  ff_mdct_end(&ac->mdct_ld);
3530  ff_mdct_end(&ac->mdct_ltp);
3531 #if !USE_FIXED
3532  ff_mdct15_uninit(&ac->mdct120);
3533  ff_mdct15_uninit(&ac->mdct480);
3534  ff_mdct15_uninit(&ac->mdct960);
3535 #endif
3536  av_freep(&ac->fdsp);
3537  return 0;
3538 }
3539 
3540 static void aacdec_init(AACContext *c)
3541 {
3542  c->imdct_and_windowing = imdct_and_windowing;
3543  c->apply_ltp = apply_ltp;
3544  c->apply_tns = apply_tns;
3545  c->windowing_and_mdct_ltp = windowing_and_mdct_ltp;
3546  c->update_ltp = update_ltp;
3547 #if USE_FIXED
3548  c->vector_pow43 = vector_pow43;
3549  c->subband_scale = subband_scale;
3550 #endif
3551 
3552 #if !USE_FIXED
3553 #if ARCH_MIPS
3555 #endif
3556 #endif /* !USE_FIXED */
3557 }
3558 /**
3559  * AVOptions for Japanese DTV specific extensions (ADTS only)
3560  */
3561 #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
3562 static const AVOption options[] = {
3563  {"dual_mono_mode", "Select the channel to decode for dual mono",
3564  offsetof(AACContext, force_dmono_mode), AV_OPT_TYPE_INT, {.i64=-1}, -1, 2,
3565  AACDEC_FLAGS, "dual_mono_mode"},
3566 
3567  {"auto", "autoselection", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"},
3568  {"main", "Select Main/Left channel", 0, AV_OPT_TYPE_CONST, {.i64= 1}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"},
3569  {"sub" , "Select Sub/Right channel", 0, AV_OPT_TYPE_CONST, {.i64= 2}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"},
3570  {"both", "Select both channels", 0, AV_OPT_TYPE_CONST, {.i64= 0}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"},
3571 
3572  { "channel_order", "Order in which the channels are to be exported",
3573  offsetof(AACContext, output_channel_order), AV_OPT_TYPE_INT,
3574  { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, AACDEC_FLAGS, "channel_order" },
3575  { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST,
3576  { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = AACDEC_FLAGS, "channel_order" },
3577  { "coded", "order in which the channels are coded in the bitstream",
3578  0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = AACDEC_FLAGS, "channel_order" },
3579 
3580  {NULL},
3581 };
3582 
3583 static const AVClass aac_decoder_class = {
3584  .class_name = "AAC decoder",
3585  .item_name = av_default_item_name,
3586  .option = options,
3587  .version = LIBAVUTIL_VERSION_INT,
3588 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
ChannelCoupling::type
enum RawDataBlockType type[8]
Type of channel element to be coupled - SCE or CPE.
Definition: aac.h:238
vector_pow43
static void vector_pow43(int *coefs, int len)
Definition: aacdec_fixed.c:153
MAX_ELEM_ID
#define MAX_ELEM_ID
Definition: aac.h:50
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1026
AAC_CHANNEL_BACK
@ AAC_CHANNEL_BACK
Definition: aac.h:100
CouplingPoint
CouplingPoint
The point during decoding at which channel coupling is applied.
Definition: aac.h:108
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:291
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
lcg_random
static av_always_inline int lcg_random(unsigned previous_val)
linear congruential pseudorandom number generator
Definition: aacdec_template.c:1184
ff_tns_max_bands_128
const uint8_t ff_tns_max_bands_128[]
Definition: aactab.c:1425
apply_mid_side_stereo
static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe)
Mid/Side stereo decoding; reference: 4.6.8.1.3.
Definition: aacdec_template.c:2216
decode_eld_specific_config
static int decode_eld_specific_config(AACContext *ac, AVCodecContext *avctx, GetBitContext *gb, MPEG4AudioConfig *m4ac, int channel_config)
Definition: aacdec_template.c:1009
av_clip
#define av_clip
Definition: common.h:95
update_ltp
static void update_ltp(AACContext *ac, SingleChannelElement *sce)
Update the LTP buffer for next frame.
Definition: aacdec_template.c:2724
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:839
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
GET_GAIN
#define GET_GAIN(x, y)
Definition: aac_defines.h:98
TemporalNoiseShaping::order
int order[8][4]
Definition: aac.h:204
AV_CH_TOP_SIDE_LEFT
#define AV_CH_TOP_SIDE_LEFT
Definition: channel_layout.h:183
TYPE_FIL
@ TYPE_FIL
Definition: aac.h:64
imdct_and_windowing
static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing.
Definition: aacdec_template.c:2762
AV_CH_TOP_FRONT_CENTER
#define AV_CH_TOP_FRONT_CENTER
Definition: channel_layout.h:171
out
FILE * out
Definition: movenc.c:54
EXT_FILL
@ EXT_FILL
Definition: aac.h:69
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:998
AV_CH_LOW_FREQUENCY_2
#define AV_CH_LOW_FREQUENCY_2
Definition: channel_layout.h:182
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
ff_aac_spectral_sizes
const uint16_t ff_aac_spectral_sizes[11]
Definition: aactab.c:446
ff_aac_codebook_vector_vals
const float *const ff_aac_codebook_vector_vals[]
Definition: aactab.c:1093
thread.h
decode_fill
static int decode_fill(AACContext *ac, GetBitContext *gb, int len)
Definition: aacdec_template.c:2507
aac_decode_init
static av_cold int aac_decode_init(AVCodecContext *avctx)
Definition: aacdec_template.c:1273
aac_kbd_short_120
static INTFLOAT aac_kbd_short_120[120]
Definition: aacdec.c:74
INIT_VLC_STATIC
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: vlc.h:125
TemporalNoiseShaping::direction
int direction[8][4]
Definition: aac.h:203
AVCodecInternal::skip_samples
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:115
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1344
GET_VLC
#define GET_VLC(code, name, gb, table, bits, max_depth)
If the vlc code is invalid and max_depth=1, then no bits will be removed.
Definition: get_bits.h:696
Pulse::num_pulse
int num_pulse
Definition: aac.h:226
decode_prediction
static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, GetBitContext *gb)
Definition: aacdec_template.c:1386
ff_cbrt_tableinit
void ff_cbrt_tableinit(void)
Definition: cbrt_tablegen.h:40
AVFloatDSPContext::vector_fmul_reverse
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats, and store the result in a vector of floats...
Definition: float_dsp.h:154
AAC_SIGNE
unsigned AAC_SIGNE
Definition: aac_defines.h:91
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
AACContext::subband_scale
void(* subband_scale)(int *dst, int *src, int scale, int offset, int len, void *log_context)
Definition: aac.h:379
AV_CH_TOP_FRONT_RIGHT
#define AV_CH_TOP_FRONT_RIGHT
Definition: channel_layout.h:172
ff_aac_codebook_vector_idx
const uint16_t *const ff_aac_codebook_vector_idx[]
Definition: aactab.c:1102
FFTContext::mdct_calc
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:96
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
skip_data_stream_element
static int skip_data_stream_element(AACContext *ac, GetBitContext *gb)
Skip data_stream_element; reference: table 4.10.
Definition: aacdec_template.c:1369
apply_dependent_coupling
static void apply_dependent_coupling(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply dependent channel coupling (applied before IMDCT).
Definition: aacdec.c:214
w
uint8_t w
Definition: llviddspenc.c:38
compute_lpc_coefs
static int AAC_RENAME() compute_lpc_coefs(const LPC_TYPE *autoc, int max_order, LPC_TYPE *lpc, int lpc_stride, int fail, int normalize)
Levinson-Durbin recursion.
Definition: lpc.h:166
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:374
ff_aac_num_swb_960
const uint8_t ff_aac_num_swb_960[]
Definition: aactab.c:68
decode_mid_side_stereo
static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, int ms_present)
Decode Mid/Side data; reference: table 4.54.
Definition: aacdec_template.c:1742
AVOption
AVOption.
Definition: opt.h:251
count_paired_channels
static int count_paired_channels(uint8_t(*layout_map)[3], int tags, int pos, int *current)
Definition: aacdec_template.c:239
b
#define b
Definition: input.c:34
AOT_ER_AAC_LTP
@ AOT_ER_AAC_LTP
N Error Resilient Long Term Prediction.
Definition: mpeg4audio.h:91
TYPE_PCE
@ TYPE_PCE
Definition: aac.h:63
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
data
const char data[16]
Definition: mxf.c:143
AACContext::tag_che_map
ChannelElement * tag_che_map[4][MAX_ELEM_ID]
Definition: aac.h:312
MAX_PREDICTORS
#define MAX_PREDICTORS
Definition: aac.h:147
ff_mdct_init
#define ff_mdct_init
Definition: fft.h:153
TemporalNoiseShaping::present
int present
Definition: aac.h:200
ff_aac_num_swb_120
const uint8_t ff_aac_num_swb_120[]
Definition: aactab.c:84
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
ff_mdct15_init
av_cold int ff_mdct15_init(MDCT15Context **ps, int inverse, int N, double scale)
Definition: mdct15.c:248
AV_CH_TOP_FRONT_LEFT
#define AV_CH_TOP_FRONT_LEFT
Definition: channel_layout.h:170
LongTermPrediction::used
int8_t used[MAX_LTP_LONG_SFB]
Definition: aac.h:169
decode_band_types
static int decode_band_types(AACContext *ac, enum BandType band_type[120], int band_type_run_end[120], GetBitContext *gb, IndividualChannelStream *ics)
Decode band types (section_data payload); reference: table 4.46.
Definition: aacdec_template.c:1548
DEC_SQUAD
static int * DEC_SQUAD(int *dst, unsigned idx)
Definition: aacdec_fixed.c:117
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:354
AACContext::random_state
int random_state
Definition: aac.h:341
aac_table_init
static AVOnce aac_table_init
Definition: aacdec_template.c:1271
apply_prediction
static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
Apply AAC-Main style frequency domain prediction.
Definition: aacdec_template.c:2062
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:178
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:295
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_aac_num_swb_480
const uint8_t ff_aac_num_swb_480[]
Definition: aactab.c:76
pop_output_configuration
static void pop_output_configuration(AACContext *ac)
Restore the previous output configuration if and only if the current configuration is unlocked.
Definition: aacdec_template.c:518
SingleChannelElement::ret
INTFLOAT * ret
PCM output.
Definition: aac.h:270
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
decode_spectrum_and_dequant
static int decode_spectrum_and_dequant(AACContext *ac, INTFLOAT coef[1024], GetBitContext *gb, const INTFLOAT sf[120], int pulse_present, const Pulse *pulse, const IndividualChannelStream *ics, enum BandType band_type[120])
Decode spectral data; reference: table 4.50.
Definition: aacdec_template.c:1767
EXT_DYNAMIC_RANGE
@ EXT_DYNAMIC_RANGE
Definition: aac.h:72
ff_swb_offset_128
const uint16_t *const ff_swb_offset_128[]
Definition: aactab.c:1387
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:649
ChannelElement::present
int present
Definition: aac.h:277
decode_pce
static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, uint8_t(*layout_map)[3], GetBitContext *gb, int byte_align_ref)
Decode program configuration element; reference: table 4.2.
Definition: aacdec_template.c:850
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1323
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:346
ff_tns_max_bands_1024
const uint8_t ff_tns_max_bands_1024[]
Definition: aactab.c:1413
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:637
AV_CH_BOTTOM_FRONT_LEFT
#define AV_CH_BOTTOM_FRONT_LEFT
Definition: channel_layout.h:186
AV_CH_TOP_BACK_LEFT
#define AV_CH_TOP_BACK_LEFT
Definition: channel_layout.h:173
AVFloatDSPContext::butterflies_float
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
Definition: float_dsp.h:164
reset_all_predictors
static void reset_all_predictors(PredictorState *ps)
Definition: aacdec_template.c:1190
GET_CACHE
#define GET_CACHE(name, gb)
Definition: get_bits.h:215
set_default_channel_config
static int set_default_channel_config(AACContext *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_template.c:629
MPEG4AudioConfig
Definition: mpeg4audio.h:32
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
DynamicRangeControl
Dynamic Range Control - decoded from the bitstream but not processed further.
Definition: aac.h:212
IndividualChannelStream::num_swb
int num_swb
number of scalefactor window bands
Definition: aac.h:184
AACContext::temp
INTFLOAT temp[128]
Definition: aac.h:362
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
AV_CH_TOP_BACK_CENTER
#define AV_CH_TOP_BACK_CENTER
Definition: channel_layout.h:174
ChannelCoupling::coupling_point
enum CouplingPoint coupling_point
The point during decoding at which coupling is applied.
Definition: aac.h:236
window
static SDL_Window * window
Definition: ffplay.c:365
ff_aac_num_swb_512
const uint8_t ff_aac_num_swb_512[]
Definition: aactab.c:72
OC_LOCKED
@ OC_LOCKED
Output configuration locked in place.
Definition: aac.h:122
overread_err
#define overread_err
Definition: aacdec_template.c:103
AACContext::apply_ltp
void(* apply_ltp)(AACContext *ac, SingleChannelElement *sce)
Definition: aac.h:372
SingleChannelElement::saved
INTFLOAT saved[1536]
overlap
Definition: aac.h:264
LongTermPrediction::coef
INTFLOAT coef
Definition: aac.h:168
ltp_coef
static const INTFLOAT ltp_coef[8]
Definition: aactab.h:50
SingleChannelElement::ret_buf
INTFLOAT ret_buf[2048]
PCM output buffer.
Definition: aac.h:265
U
#define U(x)
Definition: vp56_arith.h:37
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2056
fail
#define fail()
Definition: checkasm.h:131
ChannelElement::coup
ChannelCoupling coup
Definition: aac.h:287
ChannelCoupling::id_select
int id_select[8]
element id
Definition: aac.h:239
BEFORE_TNS
@ BEFORE_TNS
Definition: aac.h:109
ff_adts_header_parse
int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
Parse the ADTS frame header to the end of the variable header, which is the first 54 bits.
Definition: adts_header.c:30
TYPE_CPE
@ TYPE_CPE
Definition: aac.h:59
GetBitContext
Definition: get_bits.h:61
AV_CH_BACK_LEFT
#define AV_CH_BACK_LEFT
Definition: channel_layout.h:162
decode_drc_channel_exclusions
static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, GetBitContext *gb)
Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4....
Definition: aacdec_template.c:2441
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:469
Pulse::amp
int amp[4]
Definition: aac.h:229
Pulse::pos
int pos[4]
Definition: aac.h:228
POW_SF2_ZERO
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
Definition: aac.h:155
decode_gain_control
static void decode_gain_control(SingleChannelElement *sce, GetBitContext *gb)
Definition: aacdec_template.c:2090
OutputConfiguration::status
enum OCStatus status
Definition: aac.h:130
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
TemporalNoiseShaping::length
int length[8][4]
Definition: aac.h:202
VMUL2
static float * VMUL2(float *dst, const float *v, unsigned idx, const float *scale)
Definition: aacdec.c:87
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
decode_ltp
static void decode_ltp(LongTermPrediction *ltp, GetBitContext *gb, uint8_t max_sfb)
Decode Long Term Prediction data; reference: table 4.xx.
Definition: aacdec_template.c:1408
avpriv_alloc_fixed_dsp
AVFixedDSPContext * avpriv_alloc_fixed_dsp(int bit_exact)
Allocate and initialize a fixed DSP context.
Definition: fixed_dsp.c:150
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
IndividualChannelStream::prediction_used
uint8_t prediction_used[41]
Definition: aac.h:191
av_clip64
#define av_clip64
Definition: common.h:98
MAX_LTP_LONG_SFB
#define MAX_LTP_LONG_SFB
Definition: aac.h:53
SingleChannelElement::ics
IndividualChannelStream ics
Definition: aac.h:250
aac_decode_frame
static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: aacdec_template.c:3451
spectral_to_sample
static void spectral_to_sample(AACContext *ac, int samples)
Convert spectral data to samples, applying all supported tools as appropriate.
Definition: aacdec_template.c:3032
AACContext::mdct
FFTContext mdct
Definition: aac.h:329
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: avcodec.h:1353
AOT_ER_AAC_LC
@ AOT_ER_AAC_LC
N Error Resilient Low Complexity.
Definition: mpeg4audio.h:90
AACContext::warned_960_sbr
int warned_960_sbr
Definition: aac.h:366
AFTER_IMDCT
@ AFTER_IMDCT
Definition: aac.h:111
AACADTSHeaderInfo::chan_config
uint8_t chan_config
Definition: adts_header.h:35
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:179
USE_FIXED
#define USE_FIXED
Definition: aac_defines.h:25
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
ZERO_BT
@ ZERO_BT
Scalefactors and spectral data are all zero.
Definition: aac.h:85
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
FF_PROFILE_AAC_HE_V2
#define FF_PROFILE_AAC_HE_V2
Definition: avcodec.h:1556
che_configure
static av_cold int che_configure(AACContext *ac, enum ChannelPosition che_pos, int type, int id, int *channels)
Check for the channel element in the current channel position configuration.
Definition: aacdec_template.c:129
decode_cpe
static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe)
Decode a channel_pair_element; reference: table 4.4.
Definition: aacdec_template.c:2304
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:667
AAC_MUL31
#define AAC_MUL31(x, y)
Definition: aac_defines.h:102
DynamicRangeControl::exclude_mask
int exclude_mask[MAX_CHANNELS]
Channels to be excluded from DRC processing.
Definition: aac.h:216
AACContext::vector_pow43
void(* vector_pow43)(int *coefs, int len)
Definition: aac.h:378
AV_CH_LOW_FREQUENCY
#define AV_CH_LOW_FREQUENCY
Definition: channel_layout.h:161
AV_CH_LAYOUT_22POINT2
#define AV_CH_LAYOUT_22POINT2
Definition: channel_layout.h:232
AACContext::mdct_ld
FFTContext mdct_ld
Definition: aac.h:331
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:149
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:491
NOISE_BT
@ NOISE_BT
Spectral data are scaled white noise not coded in the bitstream.
Definition: aac.h:89
AVFloatDSPContext::scalarproduct_float
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
Calculate the scalar product of two vectors of floats.
Definition: float_dsp.h:175
AOT_ER_AAC_LD
@ AOT_ER_AAC_LD
N Error Resilient Low Delay.
Definition: mpeg4audio.h:95
aac_decoder_class
static const AVClass aac_decoder_class
Definition: aacdec_template.c:3583
OC_TRIAL_FRAME
@ OC_TRIAL_FRAME
Output configuration under trial specified by a frame header.
Definition: aac.h:120
s
#define s(width, name)
Definition: cbs_vp9.c:256
SingleChannelElement::coeffs
INTFLOAT coeffs[1024]
coefficients for IMDCT, maybe processed
Definition: aac.h:263
windowing_and_mdct_ltp
static void windowing_and_mdct_ltp(AACContext *ac, INTFLOAT *out, INTFLOAT *in, IndividualChannelStream *ics)
Apply windowing and MDCT to obtain the spectral coefficient from the predicted sample by LTP.
Definition: aacdec_template.c:2666
ff_swb_offset_960
const uint16_t *const ff_swb_offset_960[]
Definition: aactab.c:1363
sample_rate_idx
static int sample_rate_idx(int rate)
Definition: aacdec_template.c:1197
AAC_MUL30
#define AAC_MUL30(x, y)
Definition: aac_defines.h:101
reset_predict_state
static av_always_inline void reset_predict_state(PredictorState *ps)
Definition: aacdec.c:76
offsets
static const int offsets[]
Definition: hevc_pel.c:34
ChannelCoupling::num_coupled
int num_coupled
number of target elements
Definition: aac.h:237
g
const char * g
Definition: vf_curves.c:117
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:106
decode_dynamic_range
static int decode_dynamic_range(DynamicRangeControl *che_drc, GetBitContext *gb)
Decode dynamic range information; reference: table 4.52.
Definition: aacdec_template.c:2460
EIGHT_SHORT_SEQUENCE
@ EIGHT_SHORT_SEQUENCE
Definition: aac.h:80
OC_NONE
@ OC_NONE
Output unconfigured.
Definition: aac.h:118
INTENSITY_BT2
@ INTENSITY_BT2
Scalefactor data are intensity stereo positions (out of phase).
Definition: aac.h:90
apply_intensity_stereo
static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present)
intensity stereo decoding; reference: 4.6.8.2.3
Definition: aacdec_template.c:2254
vlc_buf
static VLCElem vlc_buf[16716]
Definition: clearvideo.c:87
bits
uint8_t bits
Definition: vp3data.h:141
TYPE_DSE
@ TYPE_DSE
Definition: aac.h:62
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aac.h:180
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
elem_to_channel::av_position
uint64_t av_position
Definition: aacdec_template.c:195
imdct_and_windowing_eld
static void imdct_and_windowing_eld(AACContext *ac, SingleChannelElement *sce)
Definition: aacdec_template.c:2926
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AV_CH_TOP_SIDE_RIGHT
#define AV_CH_TOP_SIDE_RIGHT
Definition: channel_layout.h:184
PredictorState
Predictor State.
Definition: aac.h:136
ChannelPosition
ChannelPosition
Definition: aac.h:96
channels
channels
Definition: aptx.h:32
AACContext::fdsp
AVFloatDSPContext * fdsp
Definition: aac.h:339
LongTermPrediction::present
int8_t present
Definition: aac.h:165
SKIP_BITS
#define SKIP_BITS(name, gb, num)
Definition: get_bits.h:193
aac_decode_er_frame
static int aac_decode_er_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, GetBitContext *gb)
Definition: aacdec_template.c:3166
decode_scalefactors
static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *gb, unsigned int global_gain, IndividualChannelStream *ics, enum BandType band_type[120], int band_type_run_end[120])
Decode scalefactors; reference: table 4.47.
Definition: aacdec_template.c:1597
AACContext::force_dmono_mode
int force_dmono_mode
0->not dmono, 1->use first channel, 2->use second channel
Definition: aac.h:356
parse_adts_frame_header
static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
Definition: aacdec_template.c:3104
IndividualChannelStream
Individual Channel Stream.
Definition: aac.h:175
SCALE_DIFF_ZERO
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
Definition: aac.h:153
TemporalNoiseShaping::coef
INTFLOAT coef[8][4][TNS_MAX_ORDER]
Definition: aac.h:206
NOISE_PRE
#define NOISE_PRE
preamble for NOISE_BT, put in bitstream with the first noise band
Definition: aac.h:157
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: aac.h:182
ff_aac_tableinit
void ff_aac_tableinit(void)
Definition: aactab.c:3347
decode_ga_specific_config
static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, GetBitContext *gb, int get_bit_alignment, MPEG4AudioConfig *m4ac, int channel_config)
Decode GA "General Audio" specific configuration; reference: table 4.1.
Definition: aacdec_template.c:920
AACContext::warned_num_aac_frames
int warned_num_aac_frames
Definition: aac.h:365
AACADTSHeaderInfo::num_aac_frames
uint8_t num_aac_frames
Definition: adts_header.h:36
INTENSITY_BT
@ INTENSITY_BT
Scalefactor data are intensity stereo positions (in phase).
Definition: aac.h:91
elem_to_channel::syn_ele
uint8_t syn_ele
Definition: aacdec_template.c:196
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:177
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AV_CH_TOP_CENTER
#define AV_CH_TOP_CENTER
Definition: channel_layout.h:169
decode_pulses
static int decode_pulses(Pulse *pulse, GetBitContext *gb, const uint16_t *swb_offset, int num_swb)
Decode pulse data; reference: table 4.7.
Definition: aacdec_template.c:1672
NULL
#define NULL
Definition: coverity.c:32
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:606
ff_mpeg4audio_channels
const uint8_t ff_mpeg4audio_channels[14]
Definition: mpeg4audio.c:60
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
FIXR10
#define FIXR10(x)
Definition: aac_defines.h:93
AACContext::output_channel_order
enum AACOutputChannelOrder output_channel_order
Definition: aac.h:360
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
ff_aac_eld_window_480
const float ff_aac_eld_window_480[1800]
Definition: aactab.c:2397
imdct_and_windowing_960
static void imdct_and_windowing_960(AACContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing.
Definition: aacdec_template.c:2830
ff_aac_num_swb_128
const uint8_t ff_aac_num_swb_128[]
Definition: aactab.c:80
decode_channel_map
static void decode_channel_map(uint8_t layout_map[][3], enum ChannelPosition type, GetBitContext *gb, int n)
Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
Definition: aacdec_template.c:808
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:424
IndividualChannelStream::num_window_groups
int num_window_groups
Definition: aac.h:179
AACContext::mdct480
MDCT15Context * mdct480
Definition: aac.h:337
AAC_CHANNEL_SIDE
@ AAC_CHANNEL_SIDE
Definition: aac.h:99
AACContext::frame
AVFrame * frame
Definition: aac.h:302
AACADTSHeaderInfo::sampling_index
uint8_t sampling_index
Definition: adts_header.h:34
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
aac_decode_close
static av_cold int aac_decode_close(AVCodecContext *avctx)
Definition: aacdec_template.c:3514
MPEG4AudioConfig::sampling_index
int sampling_index
Definition: mpeg4audio.h:34
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:934
LAST_SKIP_BITS
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:199
IndividualChannelStream::predictor_present
int predictor_present
Definition: aac.h:187
DynamicRangeControl::band_top
int band_top[17]
Indicates the top of the i-th DRC band in units of 4 spectral lines.
Definition: aac.h:219
abs
#define abs(x)
Definition: cuda_runtime.h:35
AACContext::che
ChannelElement * che[4][MAX_ELEM_ID]
Definition: aac.h:311
apply_ltp
static void apply_ltp(AACContext *ac, SingleChannelElement *sce)
Apply the long term prediction.
Definition: aacdec_template.c:2692
AVCodecInternal::skip_samples_multiplier
int skip_samples_multiplier
Definition: internal.h:136
ff_swb_offset_480
const uint16_t *const ff_swb_offset_480[]
Definition: aactab.c:1379
AAC_CHANNEL_FRONT
@ AAC_CHANNEL_FRONT
Definition: aac.h:98
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:160
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1355
AOT_AAC_MAIN
@ AOT_AAC_MAIN
Y Main.
Definition: mpeg4audio.h:76
SingleChannelElement::predictor_state
PredictorState predictor_state[MAX_PREDICTORS]
Definition: aac.h:269
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:787
TNS_MAX_ORDER
#define TNS_MAX_ORDER
Definition: aac.h:52
AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
Definition: channel_layout.h:164
AAC_CHANNEL_OFF
@ AAC_CHANNEL_OFF
Definition: aac.h:97
convert_header.major
int major
Definition: convert_header.py:23
decode_audio_specific_config
static int decode_audio_specific_config(AACContext *ac, AVCodecContext *avctx, MPEG4AudioConfig *m4ac, const uint8_t *data, int64_t bit_size, int sync_extension)
Definition: aacdec_template.c:1151
AVOnce
#define AVOnce
Definition: thread.h:176
decode_cce
static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
Decode coupling_channel_element; reference: table 4.8.
Definition: aacdec_template.c:2357
apply_channel_coupling
static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, enum RawDataBlockType type, int elem_id, enum CouplingPoint coupling_point, void(*apply_coupling_method)(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index))
channel coupling transformation interface
Definition: aacdec_template.c:2999
index
int index
Definition: gxfenc.c:89
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
SingleChannelElement::band_type_run_end
int band_type_run_end[120]
band type run end points
Definition: aac.h:255
AV_CH_BOTTOM_FRONT_CENTER
#define AV_CH_BOTTOM_FRONT_CENTER
Definition: channel_layout.h:185
ff_tns_max_bands_512
const uint8_t ff_tns_max_bands_512[]
Definition: aactab.c:1417
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:630
OutputConfiguration::layout_map_tags
int layout_map_tags
Definition: aac.h:128
VMUL2S
static float * VMUL2S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale)
Definition: aacdec.c:111
FFTContext::imdct_half
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:95
OutputConfiguration::layout_map
uint8_t layout_map[MAX_ELEM_ID *4][3]
Definition: aac.h:127
CHANNEL_ORDER_CODED
@ CHANNEL_ORDER_CODED
Definition: aac.h:293
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
AACContext::apply_tns
void(* apply_tns)(INTFLOAT coef[1024], TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
Definition: aac.h:373
ff_aac_scalefactor_bits
const uint8_t ff_aac_scalefactor_bits[121]
Definition: aactab.c:111
VLC::table_allocated
int table_allocated
Definition: vlc.h:34
VMUL4
static float * VMUL4(float *dst, const float *v, unsigned idx, const float *scale)
Definition: aacdec.c:98
VMUL4S
static float * VMUL4S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale)
Definition: aacdec.c:128
ff_aac_pred_sfb_max
const uint8_t ff_aac_pred_sfb_max[]
Definition: aactab.c:88
decode_audio_specific_config_gb
static int decode_audio_specific_config_gb(AACContext *ac, AVCodecContext *avctx, MPEG4AudioConfig *m4ac, GetBitContext *gb, int get_bit_alignment, int sync_extension)
Decode audio specific configuration; reference: table 1.13.
Definition: aacdec_template.c:1084
CHANNEL_ORDER_DEFAULT
@ CHANNEL_ORDER_DEFAULT
Definition: aac.h:292
AACContext::tags_mapped
int tags_mapped
Definition: aac.h:313
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1403
AOT_ER_AAC_SCALABLE
@ AOT_ER_AAC_SCALABLE
N Error Resilient Scalable.
Definition: mpeg4audio.h:92
AACContext::avctx
AVCodecContext * avctx
Definition: aac.h:301
ChannelElement::ch
SingleChannelElement ch[2]
Definition: aac.h:285
ff_swb_offset_1024
const uint16_t *const ff_swb_offset_1024[]
Definition: aactab.c:1355
relative_align_get_bits
static void relative_align_get_bits(GetBitContext *gb, int reference_position)
Definition: aacdec_template.c:838
AOT_AAC_SCALABLE
@ AOT_AAC_SCALABLE
N Scalable.
Definition: mpeg4audio.h:81
AVPacket::size
int size
Definition: packet.h:375
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:324
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:290
ONLY_LONG_SEQUENCE
@ ONLY_LONG_SEQUENCE
Definition: aac.h:78
TYPE_END
@ TYPE_END
Definition: aac.h:65
AVFloatDSPContext::vector_fmul
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats and store the result in a vector of floats.
Definition: float_dsp.h:38
ff_aac_float_common_init
void ff_aac_float_common_init(void)
sine_120
static INTFLOAT sine_120[120]
Definition: aacdec.c:71
AACContext::warned_remapping_once
int warned_remapping_once
Definition: aac.h:314
decode_ics
static int decode_ics(AACContext *ac, SingleChannelElement *sce, GetBitContext *gb, int common_window, int scale_flag)
Decode an individual_channel_stream payload; reference: table 4.44.
Definition: aacdec_template.c:2125
TemporalNoiseShaping::n_filt
int n_filt[8]
Definition: aac.h:201
BandType
BandType
Definition: aac.h:84
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:502
tags_per_config
static const int8_t tags_per_config[16]
Definition: aacdectab.h:38
noise_scale
static void noise_scale(int *coefs, int scale, int band_energy, int len)
Definition: aacdec_fixed.c:198
FF_COMPLIANCE_STRICT
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
Definition: avcodec.h:1302
sine_960
static INTFLOAT sine_960[960]
Definition: aacdec.c:72
AACContext::mdct120
MDCT15Context * mdct120
Definition: aac.h:336
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1014
ff_cbrt_tab
uint32_t ff_cbrt_tab[1<< 13]
size
int size
Definition: twinvq_data.h:10344
VLCElem
Definition: vlc.h:27
ff_mdct_end
#define ff_mdct_end
Definition: fft.h:154
DynamicRangeControl::prog_ref_level
int prog_ref_level
A reference level for the long-term program audio level for all channels combined.
Definition: aac.h:220
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.
ff_aac_spectral_codes
const uint16_t *const ff_aac_spectral_codes[11]
Definition: aactab.c:436
OCStatus
OCStatus
Output configuration status.
Definition: aac.h:117
AAC_RENAME2
#define AAC_RENAME2(x)
Definition: aac_defines.h:85
ff_mpeg4audio_get_config_gb
int ff_mpeg4audio_get_config_gb(MPEG4AudioConfig *c, GetBitContext *gb, int sync_extension, void *logctx)
Parse MPEG-4 systems extradata from a potentially unaligned GetBitContext to retrieve audio configura...
Definition: mpeg4audio.c:92
push_output_configuration
static int push_output_configuration(AACContext *ac)
Save current output configuration if and only if it has been locked.
Definition: aacdec_template.c:503
elem_to_channel::elem_id
uint8_t elem_id
Definition: aacdec_template.c:197
ff_tns_max_bands_480
const uint8_t ff_tns_max_bands_480[]
Definition: aactab.c:1421
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:138
elem_to_channel
Definition: aacdec_template.c:194
assign_pair
static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID], uint8_t(*layout_map)[3], int offset, uint64_t left, uint64_t right, int pos, uint64_t *layout)
Definition: aacdec_template.c:201
ff_swb_offset_512
const uint16_t *const ff_swb_offset_512[]
Definition: aactab.c:1371
ff_sbr_apply
void AAC_RENAME() ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, INTFLOAT *L, INTFLOAT *R)
Apply one SBR element to one AAC element.
Definition: aacsbr_template.c:1475
offset
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 offset
Definition: writing_filters.txt:86
AV_CH_TOP_BACK_RIGHT
#define AV_CH_TOP_BACK_RIGHT
Definition: channel_layout.h:175
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:538
AV_CH_FRONT_RIGHT_OF_CENTER
#define AV_CH_FRONT_RIGHT_OF_CENTER
Definition: channel_layout.h:165
AACADTSHeaderInfo::object_type
uint8_t object_type
Definition: adts_header.h:33
MAX_CHANNELS
#define MAX_CHANNELS
Definition: aac.h:49
output_configure
static int output_configure(AACContext *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_template.c:533
ChannelElement::ms_mask
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
Definition: aac.h:282
DynamicRangeControl::dyn_rng_ctl
int dyn_rng_ctl[17]
DRC magnitude information.
Definition: aac.h:215
MPEG4AudioConfig::channels
int channels
Definition: mpeg4audio.h:42
EXT_FILL_DATA
@ EXT_FILL_DATA
Definition: aac.h:70
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
ff_sine_window_init
void ff_sine_window_init(float *window, int n)
Generate a sine window.
Definition: sinewin_tablegen.h:59
OC_GLOBAL_HDR
@ OC_GLOBAL_HDR
Output configuration set in a global header but not yet locked.
Definition: aac.h:121
AOT_AAC_SSR
@ AOT_AAC_SSR
N (code in SoC repo) Scalable Sample Rate.
Definition: mpeg4audio.h:78
RANGE15
#define RANGE15(x)
Definition: aac_defines.h:97
aac_kbd_long_960
static INTFLOAT aac_kbd_long_960[960]
Definition: aacdec.c:73
layout
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 layout
Definition: filter_design.txt:18
convert_header.minor
int minor
Definition: convert_header.py:26
AV_PKT_DATA_JP_DUALMONO
@ AV_PKT_DATA_JP_DUALMONO
An AV_PKT_DATA_JP_DUALMONO side data packet indicates that the packet may contain "dual mono" audio s...
Definition: packet.h:167
AACContext::mdct960
MDCT15Context * mdct960
Definition: aac.h:338
aac_static_table_init
static av_cold void aac_static_table_init(void)
Definition: aacdec_template.c:1222
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:405
AACContext::mdct_ltp
FFTContext mdct_ltp
Definition: aac.h:332
BETWEEN_TNS_AND_IMDCT
@ BETWEEN_TNS_AND_IMDCT
Definition: aac.h:110
RawDataBlockType
RawDataBlockType
Definition: aac.h:57
aacdec_init
static void aacdec_init(AACContext *ac)
Definition: aacdec_template.c:3540
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aac.h:249
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
init_sine_windows_fixed
static av_cold void init_sine_windows_fixed(void)
Definition: sinewin_fixed_tablegen.h:60
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
options
static const AVOption options[]
Definition: aacdec_template.c:3562
IndividualChannelStream::num_windows
int num_windows
Definition: aac.h:185
ChannelElement::sbr
SpectralBandReplication sbr
Definition: aac.h:288
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:490
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:446
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: avpacket.c:251
ff_init_vlc_sparse
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: vlc.c:272
ff_aac_eld_window_512
const float ff_aac_eld_window_512[1920]
Definition: aactab.c:1430
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:386
LONG_STOP_SEQUENCE
@ LONG_STOP_SEQUENCE
Definition: aac.h:81
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aac.h:276
AOT_ER_AAC_ELD
@ AOT_ER_AAC_ELD
N Error Resilient Enhanced Low Delay.
Definition: mpeg4audio.h:111
apply_independent_coupling
static void apply_independent_coupling(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply independent channel coupling (applied after IMDCT).
Definition: aacdec.c:250
predict
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
Definition: aacdec.c:178
AV_CH_LAYOUT_NATIVE
#define AV_CH_LAYOUT_NATIVE
Channel mask value used for AVCodecContext.request_channel_layout to indicate that the user requests ...
Definition: channel_layout.h:196
NOISE_PRE_BITS
#define NOISE_PRE_BITS
length of preamble
Definition: aac.h:158
AV_CH_BACK_CENTER
#define AV_CH_BACK_CENTER
Definition: channel_layout.h:166
AAC_MUL26
#define AAC_MUL26(x, y)
Definition: aac_defines.h:100
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FF_DEBUG_STARTCODE
#define FF_DEBUG_STARTCODE
Definition: avcodec.h:1330
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
vlc_spectral
static VLC vlc_spectral[11]
Definition: aacdec_template.c:97
cbrtf
static av_always_inline float cbrtf(float x)
Definition: libm.h:61
AV_CH_FRONT_LEFT
#define AV_CH_FRONT_LEFT
Definition: channel_layout.h:158
TYPE_LFE
@ TYPE_LFE
Definition: aac.h:61
decode_ics_info
static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, GetBitContext *gb)
Decode Individual Channel Stream info; reference: table 4.6.
Definition: aacdec_template.c:1422
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:477
LongTermPrediction::lag
int16_t lag
Definition: aac.h:166
AAC_RENAME
#define AAC_RENAME(x)
Definition: aac_defines.h:83
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:264
ff_mdct15_uninit
av_cold void ff_mdct15_uninit(MDCT15Context **ps)
Definition: mdct15.c:44
MPEG4AudioConfig::chan_config
int chan_config
Definition: mpeg4audio.h:36
TYPE_SCE
@ TYPE_SCE
Definition: aac.h:58
AV_CH_SIDE_RIGHT
#define AV_CH_SIDE_RIGHT
Definition: channel_layout.h:168
AACContext::oc
OutputConfiguration oc[2]
Definition: aac.h:364
len
int len
Definition: vorbis_enc_data.h:426
filt
static const int8_t filt[NUMTAPS *2]
Definition: af_earwax.c:39
UINTFLOAT
float UINTFLOAT
Definition: aac_defines.h:87
apply_tns
static void apply_tns(INTFLOAT coef_param[1024], TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4....
Definition: aacdec_template.c:2606
MPEG4AudioConfig::ext_sample_rate
int ext_sample_rate
Definition: mpeg4audio.h:40
IndividualChannelStream::tns_max_bands
int tns_max_bands
Definition: aac.h:186
reset_predictor_group
static void reset_predictor_group(PredictorState *ps, int group_num)
Definition: aacdec_template.c:1213
OC_TRIAL_PCE
@ OC_TRIAL_PCE
Output configuration under trial specified by an inband PCE.
Definition: aac.h:119
subband_scale
static void subband_scale(int *dst, int *src, int scale, int offset, int len, void *log_context)
Definition: aacdec_fixed.c:167
AACADTSHeaderInfo::sample_rate
uint32_t sample_rate
Definition: adts_header.h:29
AACContext::che_drc
DynamicRangeControl che_drc
Definition: aac.h:305
ff_swb_offset_120
const uint16_t *const ff_swb_offset_120[]
Definition: aactab.c:1397
AAC_CHANNEL_LFE
@ AAC_CHANNEL_LFE
Definition: aac.h:101
FF_PROFILE_AAC_HE
#define FF_PROFILE_AAC_HE
Definition: avcodec.h:1555
AOT_ER_BSAC
@ AOT_ER_BSAC
N Error Resilient Bit-Sliced Arithmetic Coding.
Definition: mpeg4audio.h:94
av_channel_layout_from_mask
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:389
DynamicRangeControl::pce_instance_tag
int pce_instance_tag
Indicates with which program the DRC info is associated.
Definition: aac.h:213
ret
ret
Definition: filter_design.txt:187
INIT_VLC_STATIC_OVERLONG
#define INIT_VLC_STATIC_OVERLONG
Definition: vlc.h:101
elem_to_channel::aac_position
uint8_t aac_position
Definition: aacdec_template.c:198
ff_aac_num_swb_1024
const uint8_t ff_aac_num_swb_1024[]
Definition: aactab.c:64
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
SingleChannelElement::sf
INTFLOAT sf[120]
scalefactors
Definition: aac.h:256
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
ff_aac_spectral_bits
const uint8_t *const ff_aac_spectral_bits[11]
Definition: aactab.c:441
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1300
AACContext::output_element
SingleChannelElement * output_element[MAX_CHANNELS]
Points to each SingleChannelElement.
Definition: aac.h:348
AACDEC_FLAGS
#define AACDEC_FLAGS
AVOptions for Japanese DTV specific extensions (ADTS only)
Definition: aacdec_template.c:3561
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:683
LONG_START_SEQUENCE
@ LONG_START_SEQUENCE
Definition: aac.h:79
pos
unsigned int pos
Definition: spdifenc.c:412
AACContext::update_ltp
void(* update_ltp)(AACContext *ac, SingleChannelElement *sce)
Definition: aac.h:377
ChannelCoupling::ch_select
int ch_select[8]
[0] shared list of gains; [1] list of gains for right channel; [2] list of gains for left channel; [3...
Definition: aac.h:240
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
MPEG4AudioConfig::object_type
int object_type
Definition: mpeg4audio.h:33
SingleChannelElement::tns
TemporalNoiseShaping tns
Definition: aac.h:251
get_che
static ChannelElement * get_che(AACContext *ac, int type, int elem_id)
Definition: aacdec_template.c:669
imdct_and_window
static void imdct_and_window(TwinVQContext *tctx, enum TwinVQFrameType ftype, int wtype, float *in, float *prev, int ch)
Definition: twinvq.c:328
AACContext::warned_71_wide
unsigned warned_71_wide
Definition: aac.h:367
AACADTSHeaderInfo::crc_absent
uint8_t crc_absent
Definition: adts_header.h:32
MDCT15Context::imdct_half
void(* imdct_half)(struct MDCT15Context *s, float *dst, const float *src, ptrdiff_t stride)
Definition: mdct15.h:54
EXT_SBR_DATA_CRC
@ EXT_SBR_DATA_CRC
Definition: aac.h:74
AVCodecContext
main external API structure.
Definition: avcodec.h:389
ff_decode_sbr_extension
int AAC_RENAME() ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int crc, int cnt, int id_aac)
Decode one SBR element.
Definition: aacsbr_template.c:1111
EXT_SBR_DATA
@ EXT_SBR_DATA
Definition: aac.h:73
LongTermPrediction
Long Term Prediction.
Definition: aac.h:164
channel_layout.h
vlc_scalefactors
static VLC vlc_scalefactors
Definition: aacdec_template.c:96
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:211
MPEG4AudioConfig::ps
int ps
-1 implicit, 1 presence
Definition: mpeg4audio.h:43
ff_aac_pow2sf_tab
float ff_aac_pow2sf_tab[428]
Definition: aactab.c:39
ff_aacdec_init_mips
void ff_aacdec_init_mips(AACContext *c)
Definition: aacdec_mips.c:434
NOISE_OFFSET
#define NOISE_OFFSET
subtracted from global gain, used as offset for the preamble
Definition: aac.h:159
AV_CH_BOTTOM_FRONT_RIGHT
#define AV_CH_BOTTOM_FRONT_RIGHT
Definition: channel_layout.h:187
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
mode
mode
Definition: ebur128.h:83
VLC
Definition: vlc.h:31
decode_tns
static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns, GetBitContext *gb, const IndividualChannelStream *ics)
Decode Temporal Noise Shaping data; reference: table 4.48.
Definition: aacdec_template.c:1699
IndividualChannelStream::window_sequence
enum WindowSequence window_sequence[2]
Definition: aac.h:177
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1547
TemporalNoiseShaping
Temporal Noise Shaping.
Definition: aac.h:199
ff_init_ff_sine_windows
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
Definition: sinewin_tablegen.h:101
ff_kbd_window_init
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
Definition: kbdwin.c:26
ff_aac_sbr_ctx_close
void AAC_RENAME() ff_aac_sbr_ctx_close(SpectralBandReplication *sbr)
Close one SBR context.
Definition: aacsbr_template.c:111
temp
else temp
Definition: vf_mcdeint.c:248
ChannelCoupling::gain
INTFLOAT gain[16][120]
Definition: aac.h:243
MPEG4AudioConfig::sbr
int sbr
-1 implicit, 1 presence
Definition: mpeg4audio.h:37
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
VLC::table
VLCElem * table
Definition: vlc.h:33
DynamicRangeControl::band_incr
int band_incr
Number of DRC bands greater than 1 having DRC info.
Definition: aac.h:217
AACContext::buf_mdct
INTFLOAT buf_mdct[1024]
Definition: aac.h:322
AAC_RENAME_32
#define AAC_RENAME_32(x)
Definition: aac_defines.h:84
AVCodecContext::debug
int debug
debug
Definition: avcodec.h:1322
AV_CH_FRONT_RIGHT
#define AV_CH_FRONT_RIGHT
Definition: channel_layout.h:159
DEC_UQUAD
static int * DEC_UQUAD(int *dst, unsigned idx, unsigned sign)
Definition: aacdec_fixed.c:135
OutputConfiguration::m4ac
MPEG4AudioConfig m4ac
Definition: aac.h:126
VLC::table_size
int table_size
Definition: vlc.h:34
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:82
TYPE_CCE
@ TYPE_CCE
Definition: aac.h:60
OutputConfiguration::ch_layout
AVChannelLayout ch_layout
Definition: aac.h:129
AACContext::windowing_and_mdct_ltp
void(* windowing_and_mdct_ltp)(AACContext *ac, INTFLOAT *out, INTFLOAT *in, IndividualChannelStream *ics)
Definition: aac.h:375
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:278
frame_configure_elements
static int frame_configure_elements(AVCodecContext *avctx)
Definition: aacdec_template.c:160
decode_extension_payload
static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, ChannelElement *che, enum RawDataBlockType elem_type)
Decode extension data (incomplete); reference: table 4.51.
Definition: aacdec_template.c:2540
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVFloatDSPContext::vector_fmul_window
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
Definition: float_dsp.h:119
M_SQRT2
#define M_SQRT2
Definition: mathematics.h:61
MPEG4AudioConfig::frame_length_short
int frame_length_short
Definition: mpeg4audio.h:44
count_channels
static int count_channels(uint8_t(*layout)[3], int tags)
Definition: aacdec_template.c:105
DynamicRangeControl::dyn_rng_sgn
int dyn_rng_sgn[17]
DRC sign information; 0 - positive, 1 - negative.
Definition: aac.h:214
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:416
imdct_and_windowing_ld
static void imdct_and_windowing_ld(AACContext *ac, SingleChannelElement *sce)
Definition: aacdec_template.c:2893
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
AACContext::mdct_small
FFTContext mdct_small
Definition: aac.h:330
ChannelCoupling
coupling parameters
Definition: aac.h:235
EXT_DATA_ELEMENT
@ EXT_DATA_ELEMENT
Definition: aac.h:71
int32_t
int32_t
Definition: audioconvert.c:56
AACContext
main AAC context
Definition: aac.h:299
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
IndividualChannelStream::max_sfb
uint8_t max_sfb
number of scalefactor bands per group
Definition: aac.h:176
Pulse
Definition: aac.h:225
AAC_CHANNEL_CC
@ AAC_CHANNEL_CC
Definition: aac.h:102
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
SingleChannelElement::ltp_state
INTFLOAT ltp_state[3072]
time signal for LTP
Definition: aac.h:266
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_CH_BACK_RIGHT
#define AV_CH_BACK_RIGHT
Definition: channel_layout.h:163
DynamicRangeControl::interpolation_scheme
int interpolation_scheme
Indicates the interpolation scheme used in the SBR QMF domain.
Definition: aac.h:218
AACContext::warned_gain_control
int warned_gain_control
Definition: aac.h:368
fixed_sqrt
static av_always_inline int fixed_sqrt(int x, int bits)
Calculate the square root.
Definition: fixed_dsp.h:176
ff_aac_sbr_in