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