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