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