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