FFmpeg
mpegaudiodec_template.c
Go to the documentation of this file.
1 /*
2  * MPEG Audio decoder
3  * Copyright (c) 2001, 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * MPEG Audio decoder
25  */
26 
27 #include "config_components.h"
28 
29 #include "libavutil/attributes.h"
30 #include "libavutil/avassert.h"
32 #include "libavutil/crc.h"
33 #include "libavutil/float_dsp.h"
34 #include "libavutil/libm.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/mem_internal.h"
37 #include "libavutil/thread.h"
38 
39 #include "avcodec.h"
40 #include "decode.h"
41 #include "get_bits.h"
42 #include "mathops.h"
43 #include "mpegaudiodsp.h"
44 
45 /*
46  * TODO:
47  * - test lsf / mpeg25 extensively.
48  */
49 
50 #include "mpegaudio.h"
51 #include "mpegaudiodecheader.h"
52 
53 #define BACKSTEP_SIZE 512
54 #define EXTRABYTES 24
55 #define LAST_BUF_SIZE 2 * BACKSTEP_SIZE + EXTRABYTES
56 
57 /* layer 3 "granule" */
58 typedef struct GranuleDef {
59  uint8_t scfsi;
64  uint8_t block_type;
65  uint8_t switch_point;
66  int table_select[3];
67  int subblock_gain[3];
68  uint8_t scalefac_scale;
70  int region_size[3]; /* number of huffman codes in each region */
71  int preflag;
72  int short_start, long_end; /* long/short band indexes */
73  uint8_t scale_factors[40];
74  DECLARE_ALIGNED(16, INTFLOAT, sb_hybrid)[SBLIMIT * 18]; /* 576 samples */
75 } GranuleDef;
76 
77 typedef struct MPADecodeContext {
81  int extrasize;
82  /* next header (used in free format parsing) */
89  INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
90  GranuleDef granules[2][2]; /* Used in Layer 3 */
91  int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
96  void (*butterflies_float)(float *restrict v1, float *restrict v2, int len);
98  uint32_t crc;
100 
101 #define HEADER_SIZE 4
102 
103 #include "mpegaudiodata.h"
104 
105 #include "mpegaudio_tablegen.h"
106 /* intensity stereo coef table */
107 static INTFLOAT is_table_lsf[2][2][16];
108 
109 /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
111 /* mult table for layer 2 group quantization */
112 
113 #define SCALE_GEN(v) \
114 { FIXR_OLD(1.0 * (v)), FIXR_OLD(0.7937005259 * (v)), FIXR_OLD(0.6299605249 * (v)) }
115 
116 static const int32_t scale_factor_mult2[3][3] = {
117  SCALE_GEN(4.0 / 3.0), /* 3 steps */
118  SCALE_GEN(4.0 / 5.0), /* 5 steps */
119  SCALE_GEN(4.0 / 9.0), /* 9 steps */
120 };
121 
122 /**
123  * Convert region offsets to region sizes and truncate
124  * size to big_values.
125  */
127 {
128  int i, k, j = 0;
129  g->region_size[2] = 576 / 2;
130  for (i = 0; i < 3; i++) {
131  k = FFMIN(g->region_size[i], g->big_values);
132  g->region_size[i] = k - j;
133  j = k;
134  }
135 }
136 
138 {
139  if (g->block_type == 2) {
140  if (s->sample_rate_index != 8)
141  g->region_size[0] = (36 / 2);
142  else
143  g->region_size[0] = (72 / 2);
144  } else {
145  if (s->sample_rate_index <= 2)
146  g->region_size[0] = (36 / 2);
147  else if (s->sample_rate_index != 8)
148  g->region_size[0] = (54 / 2);
149  else
150  g->region_size[0] = (108 / 2);
151  }
152  g->region_size[1] = (576 / 2);
153 }
154 
156  int ra1, int ra2)
157 {
158  int l;
159  g->region_size[0] = ff_band_index_long[s->sample_rate_index][ra1 + 1];
160  /* should not overflow */
161  l = FFMIN(ra1 + ra2 + 2, 22);
162  g->region_size[1] = ff_band_index_long[s->sample_rate_index][ l];
163 }
164 
166 {
167  if (g->block_type == 2) {
168  if (g->switch_point) {
169  if(s->sample_rate_index == 8)
170  avpriv_request_sample(s->avctx, "switch point in 8khz");
171  /* if switched mode, we handle the 36 first samples as
172  long blocks. For 8000Hz, we handle the 72 first
173  exponents as long blocks */
174  if (s->sample_rate_index <= 2)
175  g->long_end = 8;
176  else
177  g->long_end = 6;
178 
179  g->short_start = 3;
180  } else {
181  g->long_end = 0;
182  g->short_start = 0;
183  }
184  } else {
185  g->short_start = 13;
186  g->long_end = 22;
187  }
188 }
189 
190 /* layer 1 unscaling */
191 /* n = number of bits of the mantissa minus 1 */
192 static inline int l1_unscale(int n, int mant, int scale_factor)
193 {
194  int shift, mod;
195  int64_t val;
196 
197  shift = ff_scale_factor_modshift[scale_factor];
198  mod = shift & 3;
199  shift >>= 2;
200  val = MUL64((int)(mant + (-1U << n) + 1), scale_factor_mult[n-1][mod]);
201  shift += n;
202  /* NOTE: at this point, 1 <= shift >= 21 + 15 */
203  return (int)((val + (1LL << (shift - 1))) >> shift);
204 }
205 
206 static inline int l2_unscale_group(int steps, int mant, int scale_factor)
207 {
208  int shift, mod, val;
209 
210  shift = ff_scale_factor_modshift[scale_factor];
211  mod = shift & 3;
212  shift >>= 2;
213 
214  val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];
215  /* NOTE: at this point, 0 <= shift <= 21 */
216  if (shift > 0)
217  val = (val + (1 << (shift - 1))) >> shift;
218  return val;
219 }
220 
221 /* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */
222 static inline int l3_unscale(int value, int exponent)
223 {
224  unsigned int m;
225  int e;
226 
227  e = ff_table_4_3_exp [4 * value + (exponent & 3)];
228  m = ff_table_4_3_value[4 * value + (exponent & 3)];
229  e -= exponent >> 2;
230 #ifdef DEBUG
231  if(e < 1)
232  av_log(NULL, AV_LOG_WARNING, "l3_unscale: e is %d\n", e);
233 #endif
234  if (e > (SUINT)31)
235  return 0;
236  m = (m + ((1U << e) >> 1)) >> e;
237 
238  return m;
239 }
240 
241 static av_cold void decode_init_static(void)
242 {
243  int i, j;
244 
245  /* scale factor multiply for layer 1 */
246  for (i = 0; i < 15; i++) {
247  int n, norm;
248  n = i + 2;
249  norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
250  scale_factor_mult[i][0] = MULLx(norm, FIXR(1.0 * 2.0), FRAC_BITS);
251  scale_factor_mult[i][1] = MULLx(norm, FIXR(0.7937005259 * 2.0), FRAC_BITS);
252  scale_factor_mult[i][2] = MULLx(norm, FIXR(0.6299605249 * 2.0), FRAC_BITS);
253  ff_dlog(NULL, "%d: norm=%x s=%"PRIx32" %"PRIx32" %"PRIx32"\n", i,
254  (unsigned)norm,
255  scale_factor_mult[i][0],
256  scale_factor_mult[i][1],
257  scale_factor_mult[i][2]);
258  }
259 
260  /* compute n ^ (4/3) and store it in mantissa/exp format */
261 
263 
264  for (i = 0; i < 16; i++) {
265  double f;
266  int e, k;
267 
268  for (j = 0; j < 2; j++) {
269  e = -(j + 1) * ((i + 1) >> 1);
270  f = exp2(e / 4.0);
271  k = i & 1;
272  is_table_lsf[j][k ^ 1][i] = FIXR(f);
273  is_table_lsf[j][k ][i] = FIXR(1.0);
274  ff_dlog(NULL, "is_table_lsf %d %d: %f %f\n",
275  i, j, (float) is_table_lsf[j][0][i],
276  (float) is_table_lsf[j][1][i]);
277  }
278  }
279  RENAME(ff_mpa_synth_init)();
281 }
282 
284 {
285  static AVOnce init_static_once = AV_ONCE_INIT;
286 
287  s->avctx = avctx;
288 
289 #if USE_FLOATS
290  {
291  AVFloatDSPContext *fdsp;
293  if (!fdsp)
294  return AVERROR(ENOMEM);
295  s->butterflies_float = fdsp->butterflies_float;
296  av_free(fdsp);
297  }
298 #endif
299 
300  ff_mpadsp_init(&s->mpadsp);
301 
302  if (avctx->request_sample_fmt == OUT_FMT &&
303  avctx->codec_id != AV_CODEC_ID_MP3ON4)
304  avctx->sample_fmt = OUT_FMT;
305  else
306  avctx->sample_fmt = OUT_FMT_P;
307  s->err_recognition = avctx->err_recognition;
308 
309  if (avctx->codec_id == AV_CODEC_ID_MP3ADU)
310  s->adu_mode = 1;
311 
312  ff_thread_once(&init_static_once, decode_init_static);
313 
314  return 0;
315 }
316 
318 {
319  return decode_ctx_init(avctx, avctx->priv_data);
320 }
321 
322 #define C3 FIXHR(0.86602540378443864676/2)
323 #define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36)
324 #define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36)
325 #define C6 FIXHR(1.93185165257813657349/4) //0.5 / cos(pi*(15)/36)
326 
327 /* 12 points IMDCT. We compute it "by hand" by factorizing obvious
328  cases. */
329 static void imdct12(INTFLOAT *out, SUINTFLOAT *in)
330 {
331  SUINTFLOAT in0, in1, in2, in3, in4, in5, t1, t2;
332 
333  in0 = in[0*3];
334  in1 = in[1*3] + in[0*3];
335  in2 = in[2*3] + in[1*3];
336  in3 = in[3*3] + in[2*3];
337  in4 = in[4*3] + in[3*3];
338  in5 = in[5*3] + in[4*3];
339  in5 += in3;
340  in3 += in1;
341 
342  in2 = MULH3(in2, C3, 2);
343  in3 = MULH3(in3, C3, 4);
344 
345  t1 = in0 - in4;
346  t2 = MULH3(in1 - in5, C4, 2);
347 
348  out[ 7] =
349  out[10] = t1 + t2;
350  out[ 1] =
351  out[ 4] = t1 - t2;
352 
353  in0 += SHR(in4, 1);
354  in4 = in0 + in2;
355  in5 += 2*in1;
356  in1 = MULH3(in5 + in3, C5, 1);
357  out[ 8] =
358  out[ 9] = in4 + in1;
359  out[ 2] =
360  out[ 3] = in4 - in1;
361 
362  in0 -= in2;
363  in5 = MULH3(in5 - in3, C6, 2);
364  out[ 0] =
365  out[ 5] = in0 - in5;
366  out[ 6] =
367  out[11] = in0 + in5;
368 }
369 
370 static int handle_crc(MPADecodeContext *s, int sec_len)
371 {
372  if (s->error_protection && (s->err_recognition & AV_EF_CRCCHECK)) {
373  const uint8_t *buf = s->gb.buffer - HEADER_SIZE;
374  int sec_byte_len = sec_len >> 3;
375  int sec_rem_bits = sec_len & 7;
376  const AVCRC *crc_tab = av_crc_get_table(AV_CRC_16_ANSI);
377  uint8_t tmp_buf[4];
378  uint32_t crc_val = av_crc(crc_tab, UINT16_MAX, &buf[2], 2);
379  crc_val = av_crc(crc_tab, crc_val, &buf[6], sec_byte_len);
380 
381  AV_WB32(tmp_buf,
382  ((buf[6 + sec_byte_len] & (0xFF00U >> sec_rem_bits)) << 24) +
383  ((s->crc << 16) >> sec_rem_bits));
384 
385  crc_val = av_crc(crc_tab, crc_val, tmp_buf, 3);
386 
387  if (crc_val) {
388  av_log(s->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", crc_val);
389  if (s->err_recognition & AV_EF_EXPLODE)
390  return AVERROR_INVALIDDATA;
391  }
392  }
393  return 0;
394 }
395 
396 /* return the number of decoded frames */
398 {
399  int bound, i, v, n, ch, j, mant;
400  uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT];
401  uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
402  int ret;
403 
404  ret = handle_crc(s, (s->nb_channels == 1) ? 8*16 : 8*32);
405  if (ret < 0)
406  return ret;
407 
408  if (s->mode == MPA_JSTEREO)
409  bound = (s->mode_ext + 1) * 4;
410  else
411  bound = SBLIMIT;
412 
413  /* allocation bits */
414  for (i = 0; i < bound; i++) {
415  for (ch = 0; ch < s->nb_channels; ch++) {
416  allocation[ch][i] = get_bits(&s->gb, 4);
417  }
418  }
419  for (i = bound; i < SBLIMIT; i++)
420  allocation[0][i] = get_bits(&s->gb, 4);
421 
422  /* scale factors */
423  for (i = 0; i < bound; i++) {
424  for (ch = 0; ch < s->nb_channels; ch++) {
425  if (allocation[ch][i])
426  scale_factors[ch][i] = get_bits(&s->gb, 6);
427  }
428  }
429  for (i = bound; i < SBLIMIT; i++) {
430  if (allocation[0][i]) {
431  scale_factors[0][i] = get_bits(&s->gb, 6);
432  scale_factors[1][i] = get_bits(&s->gb, 6);
433  }
434  }
435 
436  /* compute samples */
437  for (j = 0; j < 12; j++) {
438  for (i = 0; i < bound; i++) {
439  for (ch = 0; ch < s->nb_channels; ch++) {
440  n = allocation[ch][i];
441  if (n) {
442  mant = get_bits(&s->gb, n + 1);
443  v = l1_unscale(n, mant, scale_factors[ch][i]);
444  } else {
445  v = 0;
446  }
447  s->sb_samples[ch][j][i] = v;
448  }
449  }
450  for (i = bound; i < SBLIMIT; i++) {
451  n = allocation[0][i];
452  if (n) {
453  mant = get_bits(&s->gb, n + 1);
454  v = l1_unscale(n, mant, scale_factors[0][i]);
455  s->sb_samples[0][j][i] = v;
456  v = l1_unscale(n, mant, scale_factors[1][i]);
457  s->sb_samples[1][j][i] = v;
458  } else {
459  s->sb_samples[0][j][i] = 0;
460  s->sb_samples[1][j][i] = 0;
461  }
462  }
463  }
464  return 12;
465 }
466 
468 {
469  int sblimit; /* number of used subbands */
470  const unsigned char *alloc_table;
471  int table, bit_alloc_bits, i, j, ch, bound, v;
472  unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
473  unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
474  unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;
475  int scale, qindex, bits, steps, k, l, m, b;
476  int ret;
477 
478  /* select decoding table */
479  table = ff_mpa_l2_select_table(s->bit_rate / 1000, s->nb_channels,
480  s->sample_rate, s->lsf);
481  sblimit = ff_mpa_sblimit_table[table];
483 
484  if (s->mode == MPA_JSTEREO)
485  bound = (s->mode_ext + 1) * 4;
486  else
487  bound = sblimit;
488 
489  ff_dlog(s->avctx, "bound=%d sblimit=%d\n", bound, sblimit);
490 
491  /* sanity check */
492  if (bound > sblimit)
493  bound = sblimit;
494 
495  /* parse bit allocation */
496  j = 0;
497  for (i = 0; i < bound; i++) {
498  bit_alloc_bits = alloc_table[j];
499  for (ch = 0; ch < s->nb_channels; ch++)
500  bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);
501  j += 1 << bit_alloc_bits;
502  }
503  for (i = bound; i < sblimit; i++) {
504  bit_alloc_bits = alloc_table[j];
505  v = get_bits(&s->gb, bit_alloc_bits);
506  bit_alloc[0][i] = v;
507  bit_alloc[1][i] = v;
508  j += 1 << bit_alloc_bits;
509  }
510 
511  /* scale codes */
512  for (i = 0; i < sblimit; i++) {
513  for (ch = 0; ch < s->nb_channels; ch++) {
514  if (bit_alloc[ch][i])
515  scale_code[ch][i] = get_bits(&s->gb, 2);
516  }
517  }
518 
519  ret = handle_crc(s, get_bits_count(&s->gb) - 16);
520  if (ret < 0)
521  return ret;
522 
523  /* scale factors */
524  for (i = 0; i < sblimit; i++) {
525  for (ch = 0; ch < s->nb_channels; ch++) {
526  if (bit_alloc[ch][i]) {
527  sf = scale_factors[ch][i];
528  switch (scale_code[ch][i]) {
529  default:
530  case 0:
531  sf[0] = get_bits(&s->gb, 6);
532  sf[1] = get_bits(&s->gb, 6);
533  sf[2] = get_bits(&s->gb, 6);
534  break;
535  case 2:
536  sf[0] = get_bits(&s->gb, 6);
537  sf[1] = sf[0];
538  sf[2] = sf[0];
539  break;
540  case 1:
541  sf[0] = get_bits(&s->gb, 6);
542  sf[2] = get_bits(&s->gb, 6);
543  sf[1] = sf[0];
544  break;
545  case 3:
546  sf[0] = get_bits(&s->gb, 6);
547  sf[2] = get_bits(&s->gb, 6);
548  sf[1] = sf[2];
549  break;
550  }
551  }
552  }
553  }
554 
555  /* samples */
556  for (k = 0; k < 3; k++) {
557  for (l = 0; l < 12; l += 3) {
558  j = 0;
559  for (i = 0; i < bound; i++) {
560  bit_alloc_bits = alloc_table[j];
561  for (ch = 0; ch < s->nb_channels; ch++) {
562  b = bit_alloc[ch][i];
563  if (b) {
564  scale = scale_factors[ch][i][k];
565  qindex = alloc_table[j+b];
566  bits = ff_mpa_quant_bits[qindex];
567  if (bits < 0) {
568  int v2;
569  /* 3 values at the same time */
570  v = get_bits(&s->gb, -bits);
571  v2 = ff_division_tabs[qindex][v];
572  steps = ff_mpa_quant_steps[qindex];
573 
574  s->sb_samples[ch][k * 12 + l + 0][i] =
575  l2_unscale_group(steps, v2 & 15, scale);
576  s->sb_samples[ch][k * 12 + l + 1][i] =
577  l2_unscale_group(steps, (v2 >> 4) & 15, scale);
578  s->sb_samples[ch][k * 12 + l + 2][i] =
579  l2_unscale_group(steps, v2 >> 8 , scale);
580  } else {
581  for (m = 0; m < 3; m++) {
582  v = get_bits(&s->gb, bits);
583  v = l1_unscale(bits - 1, v, scale);
584  s->sb_samples[ch][k * 12 + l + m][i] = v;
585  }
586  }
587  } else {
588  s->sb_samples[ch][k * 12 + l + 0][i] = 0;
589  s->sb_samples[ch][k * 12 + l + 1][i] = 0;
590  s->sb_samples[ch][k * 12 + l + 2][i] = 0;
591  }
592  }
593  /* next subband in alloc table */
594  j += 1 << bit_alloc_bits;
595  }
596  /* XXX: find a way to avoid this duplication of code */
597  for (i = bound; i < sblimit; i++) {
598  bit_alloc_bits = alloc_table[j];
599  b = bit_alloc[0][i];
600  if (b) {
601  int mant, scale0, scale1;
602  scale0 = scale_factors[0][i][k];
603  scale1 = scale_factors[1][i][k];
604  qindex = alloc_table[j + b];
605  bits = ff_mpa_quant_bits[qindex];
606  if (bits < 0) {
607  /* 3 values at the same time */
608  v = get_bits(&s->gb, -bits);
609  steps = ff_mpa_quant_steps[qindex];
610  mant = v % steps;
611  v = v / steps;
612  s->sb_samples[0][k * 12 + l + 0][i] =
613  l2_unscale_group(steps, mant, scale0);
614  s->sb_samples[1][k * 12 + l + 0][i] =
615  l2_unscale_group(steps, mant, scale1);
616  mant = v % steps;
617  v = v / steps;
618  s->sb_samples[0][k * 12 + l + 1][i] =
619  l2_unscale_group(steps, mant, scale0);
620  s->sb_samples[1][k * 12 + l + 1][i] =
621  l2_unscale_group(steps, mant, scale1);
622  s->sb_samples[0][k * 12 + l + 2][i] =
623  l2_unscale_group(steps, v, scale0);
624  s->sb_samples[1][k * 12 + l + 2][i] =
625  l2_unscale_group(steps, v, scale1);
626  } else {
627  for (m = 0; m < 3; m++) {
628  mant = get_bits(&s->gb, bits);
629  s->sb_samples[0][k * 12 + l + m][i] =
630  l1_unscale(bits - 1, mant, scale0);
631  s->sb_samples[1][k * 12 + l + m][i] =
632  l1_unscale(bits - 1, mant, scale1);
633  }
634  }
635  } else {
636  s->sb_samples[0][k * 12 + l + 0][i] = 0;
637  s->sb_samples[0][k * 12 + l + 1][i] = 0;
638  s->sb_samples[0][k * 12 + l + 2][i] = 0;
639  s->sb_samples[1][k * 12 + l + 0][i] = 0;
640  s->sb_samples[1][k * 12 + l + 1][i] = 0;
641  s->sb_samples[1][k * 12 + l + 2][i] = 0;
642  }
643  /* next subband in alloc table */
644  j += 1 << bit_alloc_bits;
645  }
646  /* fill remaining samples to zero */
647  for (i = sblimit; i < SBLIMIT; i++) {
648  for (ch = 0; ch < s->nb_channels; ch++) {
649  s->sb_samples[ch][k * 12 + l + 0][i] = 0;
650  s->sb_samples[ch][k * 12 + l + 1][i] = 0;
651  s->sb_samples[ch][k * 12 + l + 2][i] = 0;
652  }
653  }
654  }
655  }
656  return 3 * 12;
657 }
658 
659 #define SPLIT(dst,sf,n) \
660  if (n == 3) { \
661  int m = (sf * 171) >> 9; \
662  dst = sf - 3 * m; \
663  sf = m; \
664  } else if (n == 4) { \
665  dst = sf & 3; \
666  sf >>= 2; \
667  } else if (n == 5) { \
668  int m = (sf * 205) >> 10; \
669  dst = sf - 5 * m; \
670  sf = m; \
671  } else if (n == 6) { \
672  int m = (sf * 171) >> 10; \
673  dst = sf - 6 * m; \
674  sf = m; \
675  } else { \
676  dst = 0; \
677  }
678 
679 static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2,
680  int n3)
681 {
682  SPLIT(slen[3], sf, n3)
683  SPLIT(slen[2], sf, n2)
684  SPLIT(slen[1], sf, n1)
685  slen[0] = sf;
686 }
687 
689  int16_t *exponents)
690 {
691  const uint8_t *bstab, *pretab;
692  int len, i, j, k, l, v0, shift, gain, gains[3];
693  int16_t *exp_ptr;
694 
695  exp_ptr = exponents;
696  gain = g->global_gain - 210;
697  shift = g->scalefac_scale + 1;
698 
699  bstab = ff_band_size_long[s->sample_rate_index];
700  pretab = ff_mpa_pretab[g->preflag];
701  for (i = 0; i < g->long_end; i++) {
702  v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift) + 400;
703  len = bstab[i];
704  for (j = len; j > 0; j--)
705  *exp_ptr++ = v0;
706  }
707 
708  if (g->short_start < 13) {
709  bstab = ff_band_size_short[s->sample_rate_index];
710  gains[0] = gain - (g->subblock_gain[0] << 3);
711  gains[1] = gain - (g->subblock_gain[1] << 3);
712  gains[2] = gain - (g->subblock_gain[2] << 3);
713  k = g->long_end;
714  for (i = g->short_start; i < 13; i++) {
715  len = bstab[i];
716  for (l = 0; l < 3; l++) {
717  v0 = gains[l] - (g->scale_factors[k++] << shift) + 400;
718  for (j = len; j > 0; j--)
719  *exp_ptr++ = v0;
720  }
721  }
722  }
723 }
724 
725 static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos,
726  int *end_pos2)
727 {
728  if (s->in_gb.buffer && *pos >= s->gb.size_in_bits - s->extrasize * 8) {
729  s->gb = s->in_gb;
730  s->in_gb.buffer = NULL;
731  s->extrasize = 0;
732  av_assert2((get_bits_count(&s->gb) & 7) == 0);
733  skip_bits_long(&s->gb, *pos - *end_pos);
734  *end_pos2 =
735  *end_pos = *end_pos2 + get_bits_count(&s->gb) - *pos;
736  *pos = get_bits_count(&s->gb);
737  }
738 }
739 
740 /* Following is an optimized code for
741  INTFLOAT v = *src
742  if(get_bits1(&s->gb))
743  v = -v;
744  *dst = v;
745 */
746 #if USE_FLOATS
747 #define READ_FLIP_SIGN(dst,src) \
748  v = AV_RN32A(src) ^ (get_bits1(&s->gb) << 31); \
749  AV_WN32A(dst, v);
750 #else
751 #define READ_FLIP_SIGN(dst,src) \
752  v = -get_bits1(&s->gb); \
753  *(dst) = (*(src) ^ v) - v;
754 #endif
755 
757  int16_t *exponents, int end_pos2)
758 {
759  int s_index;
760  int i;
761  int last_pos, bits_left;
762  VLC *vlc;
763  int end_pos = FFMIN(end_pos2, s->gb.size_in_bits - s->extrasize * 8);
764 
765  /* low frequencies (called big values) */
766  s_index = 0;
767  for (i = 0; i < 3; i++) {
768  const VLCElem *vlctab;
769  int j, k, l, linbits;
770  j = g->region_size[i];
771  if (j == 0)
772  continue;
773  /* select vlc table */
774  k = g->table_select[i];
775  l = ff_mpa_huff_data[k][0];
776  linbits = ff_mpa_huff_data[k][1];
777 
778  if (!l) {
779  memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * 2 * j);
780  s_index += 2 * j;
781  continue;
782  }
783  vlctab = ff_huff_vlc[l];
784 
785  /* read huffcode and compute each couple */
786  for (; j > 0; j--) {
787  int exponent, x, y;
788  int v;
789  int pos = get_bits_count(&s->gb);
790 
791  if (pos >= end_pos){
792  switch_buffer(s, &pos, &end_pos, &end_pos2);
793  if (pos >= end_pos)
794  break;
795  }
796  y = get_vlc2(&s->gb, vlctab, 7, 3);
797 
798  if (!y) {
799  g->sb_hybrid[s_index ] =
800  g->sb_hybrid[s_index + 1] = 0;
801  s_index += 2;
802  continue;
803  }
804 
805  exponent= exponents[s_index];
806 
807  ff_dlog(s->avctx, "region=%d n=%d y=%d exp=%d\n",
808  i, g->region_size[i] - j, y, exponent);
809  if (y & 16) {
810  x = y >> 5;
811  y = y & 0x0f;
812  if (x < 15) {
813  READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(expval_table)[exponent] + x)
814  } else {
815  x += get_bitsz(&s->gb, linbits);
816  v = l3_unscale(x, exponent);
817  if (get_bits1(&s->gb))
818  v = -v;
819  g->sb_hybrid[s_index] = v;
820  }
821  if (y < 15) {
822  READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(expval_table)[exponent] + y)
823  } else {
824  y += get_bitsz(&s->gb, linbits);
825  v = l3_unscale(y, exponent);
826  if (get_bits1(&s->gb))
827  v = -v;
828  g->sb_hybrid[s_index + 1] = v;
829  }
830  } else {
831  x = y >> 5;
832  y = y & 0x0f;
833  x += y;
834  if (x < 15) {
835  READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(expval_table)[exponent] + x)
836  } else {
837  x += get_bitsz(&s->gb, linbits);
838  v = l3_unscale(x, exponent);
839  if (get_bits1(&s->gb))
840  v = -v;
841  g->sb_hybrid[s_index+!!y] = v;
842  }
843  g->sb_hybrid[s_index + !y] = 0;
844  }
845  s_index += 2;
846  }
847  }
848 
849  /* high frequencies */
850  vlc = &ff_huff_quad_vlc[g->count1table_select];
851  last_pos = 0;
852  while (s_index <= 572) {
853  int pos, code;
854  pos = get_bits_count(&s->gb);
855  if (pos >= end_pos) {
856  if (pos > end_pos2 && last_pos) {
857  /* some encoders generate an incorrect size for this
858  part. We must go back into the data */
859  s_index -= 4;
860  skip_bits_long(&s->gb, last_pos - pos);
861  av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
862  if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
863  s_index=0;
864  break;
865  }
866  switch_buffer(s, &pos, &end_pos, &end_pos2);
867  if (pos >= end_pos)
868  break;
869  }
870  last_pos = pos;
871 
872  code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1);
873  ff_dlog(s->avctx, "t=%d code=%d\n", g->count1table_select, code);
874  g->sb_hybrid[s_index + 0] =
875  g->sb_hybrid[s_index + 1] =
876  g->sb_hybrid[s_index + 2] =
877  g->sb_hybrid[s_index + 3] = 0;
878  while (code) {
879  static const int idxtab[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 };
880  int v;
881  int pos = s_index + idxtab[code];
882  code ^= 8 >> idxtab[code];
883  READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(exp_table)+exponents[pos])
884  }
885  s_index += 4;
886  }
887  /* skip extension bits */
888  bits_left = end_pos2 - get_bits_count(&s->gb);
889  if (bits_left < 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_COMPLIANT))) {
890  av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
891  s_index=0;
892  } else if (bits_left > 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) {
893  av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
894  s_index = 0;
895  }
896  memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * (576 - s_index));
897  skip_bits_long(&s->gb, bits_left);
898 
899  i = get_bits_count(&s->gb);
900  switch_buffer(s, &i, &end_pos, &end_pos2);
901 
902  return 0;
903 }
904 
905 /* Reorder short blocks from bitstream order to interleaved order. It
906  would be faster to do it in parsing, but the code would be far more
907  complicated */
909 {
910  int i, j, len;
911  INTFLOAT *ptr, *dst, *ptr1;
912  INTFLOAT tmp[576];
913 
914  if (g->block_type != 2)
915  return;
916 
917  if (g->switch_point) {
918  if (s->sample_rate_index != 8)
919  ptr = g->sb_hybrid + 36;
920  else
921  ptr = g->sb_hybrid + 72;
922  } else {
923  ptr = g->sb_hybrid;
924  }
925 
926  for (i = g->short_start; i < 13; i++) {
927  len = ff_band_size_short[s->sample_rate_index][i];
928  ptr1 = ptr;
929  dst = tmp;
930  for (j = len; j > 0; j--) {
931  *dst++ = ptr[0*len];
932  *dst++ = ptr[1*len];
933  *dst++ = ptr[2*len];
934  ptr++;
935  }
936  ptr += 2 * len;
937  memcpy(ptr1, tmp, len * 3 * sizeof(*ptr1));
938  }
939 }
940 
941 #define ISQRT2 FIXR(0.70710678118654752440)
942 
944 {
945  int i, j, k, l;
946  int sf_max, sf, len, non_zero_found;
947  INTFLOAT *tab0, *tab1, v1, v2;
948  const INTFLOAT (*is_tab)[16];
949  SUINTFLOAT tmp0, tmp1;
950  int non_zero_found_short[3];
951 
952  /* intensity stereo */
953  if (s->mode_ext & MODE_EXT_I_STEREO) {
954  if (!s->lsf) {
955  is_tab = is_table;
956  sf_max = 7;
957  } else {
958  is_tab = is_table_lsf[g1->scalefac_compress & 1];
959  sf_max = 16;
960  }
961 
962  tab0 = g0->sb_hybrid + 576;
963  tab1 = g1->sb_hybrid + 576;
964 
965  non_zero_found_short[0] = 0;
966  non_zero_found_short[1] = 0;
967  non_zero_found_short[2] = 0;
968  k = (13 - g1->short_start) * 3 + g1->long_end - 3;
969  for (i = 12; i >= g1->short_start; i--) {
970  /* for last band, use previous scale factor */
971  if (i != 11)
972  k -= 3;
973  len = ff_band_size_short[s->sample_rate_index][i];
974  for (l = 2; l >= 0; l--) {
975  tab0 -= len;
976  tab1 -= len;
977  if (!non_zero_found_short[l]) {
978  /* test if non zero band. if so, stop doing i-stereo */
979  for (j = 0; j < len; j++) {
980  if (tab1[j] != 0) {
981  non_zero_found_short[l] = 1;
982  goto found1;
983  }
984  }
985  sf = g1->scale_factors[k + l];
986  if (sf >= sf_max)
987  goto found1;
988 
989  v1 = is_tab[0][sf];
990  v2 = is_tab[1][sf];
991  for (j = 0; j < len; j++) {
992  tmp0 = tab0[j];
993  tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
994  tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
995  }
996  } else {
997 found1:
998  if (s->mode_ext & MODE_EXT_MS_STEREO) {
999  /* lower part of the spectrum : do ms stereo
1000  if enabled */
1001  for (j = 0; j < len; j++) {
1002  tmp0 = tab0[j];
1003  tmp1 = tab1[j];
1004  tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
1005  tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
1006  }
1007  }
1008  }
1009  }
1010  }
1011 
1012  non_zero_found = non_zero_found_short[0] |
1013  non_zero_found_short[1] |
1014  non_zero_found_short[2];
1015 
1016  for (i = g1->long_end - 1;i >= 0;i--) {
1017  len = ff_band_size_long[s->sample_rate_index][i];
1018  tab0 -= len;
1019  tab1 -= len;
1020  /* test if non zero band. if so, stop doing i-stereo */
1021  if (!non_zero_found) {
1022  for (j = 0; j < len; j++) {
1023  if (tab1[j] != 0) {
1024  non_zero_found = 1;
1025  goto found2;
1026  }
1027  }
1028  /* for last band, use previous scale factor */
1029  k = (i == 21) ? 20 : i;
1030  sf = g1->scale_factors[k];
1031  if (sf >= sf_max)
1032  goto found2;
1033  v1 = is_tab[0][sf];
1034  v2 = is_tab[1][sf];
1035  for (j = 0; j < len; j++) {
1036  tmp0 = tab0[j];
1037  tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
1038  tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
1039  }
1040  } else {
1041 found2:
1042  if (s->mode_ext & MODE_EXT_MS_STEREO) {
1043  /* lower part of the spectrum : do ms stereo
1044  if enabled */
1045  for (j = 0; j < len; j++) {
1046  tmp0 = tab0[j];
1047  tmp1 = tab1[j];
1048  tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
1049  tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
1050  }
1051  }
1052  }
1053  }
1054  } else if (s->mode_ext & MODE_EXT_MS_STEREO) {
1055  /* ms stereo ONLY */
1056  /* NOTE: the 1/sqrt(2) normalization factor is included in the
1057  global gain */
1058 #if USE_FLOATS
1059  s->butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
1060 #else
1061  tab0 = g0->sb_hybrid;
1062  tab1 = g1->sb_hybrid;
1063  for (i = 0; i < 576; i++) {
1064  tmp0 = tab0[i];
1065  tmp1 = tab1[i];
1066  tab0[i] = tmp0 + tmp1;
1067  tab1[i] = tmp0 - tmp1;
1068  }
1069 #endif
1070  }
1071 }
1072 
1073 #if USE_FLOATS
1074 #if HAVE_MIPSFPU
1076 #endif /* HAVE_MIPSFPU */
1077 #else
1078 #if HAVE_MIPSDSP
1080 #endif /* HAVE_MIPSDSP */
1081 #endif /* USE_FLOATS */
1082 
1083 #ifndef compute_antialias
1084 #if USE_FLOATS
1085 #define AA(j) do { \
1086  float tmp0 = ptr[-1-j]; \
1087  float tmp1 = ptr[ j]; \
1088  ptr[-1-j] = tmp0 * csa_table[j][0] - tmp1 * csa_table[j][1]; \
1089  ptr[ j] = tmp0 * csa_table[j][1] + tmp1 * csa_table[j][0]; \
1090  } while (0)
1091 #else
1092 #define AA(j) do { \
1093  SUINT tmp0 = ptr[-1-j]; \
1094  SUINT tmp1 = ptr[ j]; \
1095  SUINT tmp2 = MULH(tmp0 + tmp1, csa_table[j][0]); \
1096  ptr[-1-j] = 4 * (tmp2 - MULH(tmp1, csa_table[j][2])); \
1097  ptr[ j] = 4 * (tmp2 + MULH(tmp0, csa_table[j][3])); \
1098  } while (0)
1099 #endif
1100 
1102 {
1103  INTFLOAT *ptr;
1104  int n, i;
1105 
1106  /* we antialias only "long" bands */
1107  if (g->block_type == 2) {
1108  if (!g->switch_point)
1109  return;
1110  /* XXX: check this for 8000Hz case */
1111  n = 1;
1112  } else {
1113  n = SBLIMIT - 1;
1114  }
1115 
1116  ptr = g->sb_hybrid + 18;
1117  for (i = n; i > 0; i--) {
1118  AA(0);
1119  AA(1);
1120  AA(2);
1121  AA(3);
1122  AA(4);
1123  AA(5);
1124  AA(6);
1125  AA(7);
1126 
1127  ptr += 18;
1128  }
1129 }
1130 #endif /* compute_antialias */
1131 
1133  INTFLOAT *sb_samples, INTFLOAT *mdct_buf)
1134 {
1135  INTFLOAT *win, *out_ptr, *ptr, *buf, *ptr1;
1136  INTFLOAT out2[12];
1137  int i, j, mdct_long_end, sblimit;
1138 
1139  /* find last non zero block */
1140  ptr = g->sb_hybrid + 576;
1141  ptr1 = g->sb_hybrid + 2 * 18;
1142  while (ptr >= ptr1) {
1143  int32_t *p;
1144  ptr -= 6;
1145  p = (int32_t*)ptr;
1146  if (p[0] | p[1] | p[2] | p[3] | p[4] | p[5])
1147  break;
1148  }
1149  sblimit = ((ptr - g->sb_hybrid) / 18) + 1;
1150 
1151  if (g->block_type == 2) {
1152  /* XXX: check for 8000 Hz */
1153  if (g->switch_point)
1154  mdct_long_end = 2;
1155  else
1156  mdct_long_end = 0;
1157  } else {
1158  mdct_long_end = sblimit;
1159  }
1160 
1161  s->mpadsp.RENAME(imdct36_blocks)(sb_samples, mdct_buf, g->sb_hybrid,
1162  mdct_long_end, g->switch_point,
1163  g->block_type);
1164 
1165  buf = mdct_buf + 4*18*(mdct_long_end >> 2) + (mdct_long_end & 3);
1166  ptr = g->sb_hybrid + 18 * mdct_long_end;
1167 
1168  for (j = mdct_long_end; j < sblimit; j++) {
1169  /* select frequency inversion */
1170  win = RENAME(ff_mdct_win)[2 + (4 & -(j & 1))];
1171  out_ptr = sb_samples + j;
1172 
1173  for (i = 0; i < 6; i++) {
1174  *out_ptr = buf[4*i];
1175  out_ptr += SBLIMIT;
1176  }
1177  imdct12(out2, ptr + 0);
1178  for (i = 0; i < 6; i++) {
1179  *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*1)];
1180  buf[4*(i + 6*2)] = MULH3(out2[i + 6], win[i + 6], 1);
1181  out_ptr += SBLIMIT;
1182  }
1183  imdct12(out2, ptr + 1);
1184  for (i = 0; i < 6; i++) {
1185  *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*2)];
1186  buf[4*(i + 6*0)] = MULH3(out2[i + 6], win[i + 6], 1);
1187  out_ptr += SBLIMIT;
1188  }
1189  imdct12(out2, ptr + 2);
1190  for (i = 0; i < 6; i++) {
1191  buf[4*(i + 6*0)] = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*0)];
1192  buf[4*(i + 6*1)] = MULH3(out2[i + 6], win[i + 6], 1);
1193  buf[4*(i + 6*2)] = 0;
1194  }
1195  ptr += 18;
1196  buf += (j&3) != 3 ? 1 : (4*18-3);
1197  }
1198  /* zero bands */
1199  for (j = sblimit; j < SBLIMIT; j++) {
1200  /* overlap */
1201  out_ptr = sb_samples + j;
1202  for (i = 0; i < 18; i++) {
1203  *out_ptr = buf[4*i];
1204  buf[4*i] = 0;
1205  out_ptr += SBLIMIT;
1206  }
1207  buf += (j&3) != 3 ? 1 : (4*18-3);
1208  }
1209 }
1210 
1211 /* main layer3 decoding function */
1213 {
1214  int nb_granules, main_data_begin;
1215  int gr, ch, blocksplit_flag, i, j, k, n, bits_pos;
1216  GranuleDef *g;
1217  int16_t exponents[576]; //FIXME try INTFLOAT
1218  int ret;
1219 
1220  /* read side info */
1221  if (s->lsf) {
1222  ret = handle_crc(s, ((s->nb_channels == 1) ? 8*9 : 8*17));
1223  main_data_begin = get_bits(&s->gb, 8);
1224  skip_bits(&s->gb, s->nb_channels);
1225  nb_granules = 1;
1226  } else {
1227  ret = handle_crc(s, ((s->nb_channels == 1) ? 8*17 : 8*32));
1228  main_data_begin = get_bits(&s->gb, 9);
1229  if (s->nb_channels == 2)
1230  skip_bits(&s->gb, 3);
1231  else
1232  skip_bits(&s->gb, 5);
1233  nb_granules = 2;
1234  for (ch = 0; ch < s->nb_channels; ch++) {
1235  s->granules[ch][0].scfsi = 0;/* all scale factors are transmitted */
1236  s->granules[ch][1].scfsi = get_bits(&s->gb, 4);
1237  }
1238  }
1239  if (ret < 0)
1240  return ret;
1241 
1242  for (gr = 0; gr < nb_granules; gr++) {
1243  for (ch = 0; ch < s->nb_channels; ch++) {
1244  ff_dlog(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch);
1245  g = &s->granules[ch][gr];
1246  g->part2_3_length = get_bits(&s->gb, 12);
1247  g->big_values = get_bits(&s->gb, 9);
1248  if (g->big_values > 288) {
1249  av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n");
1250  return AVERROR_INVALIDDATA;
1251  }
1252 
1253  g->global_gain = get_bits(&s->gb, 8);
1254  /* if MS stereo only is selected, we precompute the
1255  1/sqrt(2) renormalization factor */
1256  if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
1258  g->global_gain -= 2;
1259  if (s->lsf)
1260  g->scalefac_compress = get_bits(&s->gb, 9);
1261  else
1262  g->scalefac_compress = get_bits(&s->gb, 4);
1263  blocksplit_flag = get_bits1(&s->gb);
1264  if (blocksplit_flag) {
1265  g->block_type = get_bits(&s->gb, 2);
1266  if (g->block_type == 0) {
1267  av_log(s->avctx, AV_LOG_ERROR, "invalid block type\n");
1268  return AVERROR_INVALIDDATA;
1269  }
1270  g->switch_point = get_bits1(&s->gb);
1271  for (i = 0; i < 2; i++)
1272  g->table_select[i] = get_bits(&s->gb, 5);
1273  for (i = 0; i < 3; i++)
1274  g->subblock_gain[i] = get_bits(&s->gb, 3);
1275  init_short_region(s, g);
1276  } else {
1277  int region_address1, region_address2;
1278  g->block_type = 0;
1279  g->switch_point = 0;
1280  for (i = 0; i < 3; i++)
1281  g->table_select[i] = get_bits(&s->gb, 5);
1282  /* compute huffman coded region sizes */
1283  region_address1 = get_bits(&s->gb, 4);
1284  region_address2 = get_bits(&s->gb, 3);
1285  ff_dlog(s->avctx, "region1=%d region2=%d\n",
1286  region_address1, region_address2);
1287  init_long_region(s, g, region_address1, region_address2);
1288  }
1291 
1292  g->preflag = 0;
1293  if (!s->lsf)
1294  g->preflag = get_bits1(&s->gb);
1295  g->scalefac_scale = get_bits1(&s->gb);
1296  g->count1table_select = get_bits1(&s->gb);
1297  ff_dlog(s->avctx, "block_type=%d switch_point=%d\n",
1298  g->block_type, g->switch_point);
1299  }
1300  }
1301 
1302  if (!s->adu_mode) {
1303  int skip;
1304  const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb) >> 3);
1305  s->extrasize = av_clip((get_bits_left(&s->gb) >> 3) - s->extrasize, 0,
1306  FFMAX(0, LAST_BUF_SIZE - s->last_buf_size));
1307  av_assert1((get_bits_count(&s->gb) & 7) == 0);
1308  /* now we get bits from the main_data_begin offset */
1309  ff_dlog(s->avctx, "seekback:%d, lastbuf:%d\n",
1310  main_data_begin, s->last_buf_size);
1311 
1312  memcpy(s->last_buf + s->last_buf_size, ptr, s->extrasize);
1313  s->in_gb = s->gb;
1314  init_get_bits(&s->gb, s->last_buf, (s->last_buf_size + s->extrasize) * 8);
1315  s->last_buf_size <<= 3;
1316  for (gr = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++) {
1317  for (ch = 0; ch < s->nb_channels; ch++) {
1318  g = &s->granules[ch][gr];
1319  s->last_buf_size += g->part2_3_length;
1320  memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));
1321  compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
1322  }
1323  }
1324  skip = s->last_buf_size - 8 * main_data_begin;
1325  if (skip >= s->gb.size_in_bits - s->extrasize * 8 && s->in_gb.buffer) {
1326  skip_bits_long(&s->in_gb, skip - s->gb.size_in_bits + s->extrasize * 8);
1327  s->gb = s->in_gb;
1328  s->in_gb.buffer = NULL;
1329  s->extrasize = 0;
1330  } else {
1331  skip_bits_long(&s->gb, skip);
1332  }
1333  } else {
1334  gr = 0;
1335  s->extrasize = 0;
1336  }
1337 
1338  for (; gr < nb_granules; gr++) {
1339  for (ch = 0; ch < s->nb_channels; ch++) {
1340  g = &s->granules[ch][gr];
1341  bits_pos = get_bits_count(&s->gb);
1342 
1343  if (!s->lsf) {
1344  uint8_t *sc;
1345  int slen, slen1, slen2;
1346 
1347  /* MPEG-1 scale factors */
1348  slen1 = ff_slen_table[0][g->scalefac_compress];
1349  slen2 = ff_slen_table[1][g->scalefac_compress];
1350  ff_dlog(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);
1351  if (g->block_type == 2) {
1352  n = g->switch_point ? 17 : 18;
1353  j = 0;
1354  if (slen1) {
1355  for (i = 0; i < n; i++)
1356  g->scale_factors[j++] = get_bits(&s->gb, slen1);
1357  } else {
1358  for (i = 0; i < n; i++)
1359  g->scale_factors[j++] = 0;
1360  }
1361  if (slen2) {
1362  for (i = 0; i < 18; i++)
1363  g->scale_factors[j++] = get_bits(&s->gb, slen2);
1364  for (i = 0; i < 3; i++)
1365  g->scale_factors[j++] = 0;
1366  } else {
1367  for (i = 0; i < 21; i++)
1368  g->scale_factors[j++] = 0;
1369  }
1370  } else {
1371  sc = s->granules[ch][0].scale_factors;
1372  j = 0;
1373  for (k = 0; k < 4; k++) {
1374  n = k == 0 ? 6 : 5;
1375  if ((g->scfsi & (0x8 >> k)) == 0) {
1376  slen = (k < 2) ? slen1 : slen2;
1377  if (slen) {
1378  for (i = 0; i < n; i++)
1379  g->scale_factors[j++] = get_bits(&s->gb, slen);
1380  } else {
1381  for (i = 0; i < n; i++)
1382  g->scale_factors[j++] = 0;
1383  }
1384  } else {
1385  /* simply copy from last granule */
1386  for (i = 0; i < n; i++) {
1387  g->scale_factors[j] = sc[j];
1388  j++;
1389  }
1390  }
1391  }
1392  g->scale_factors[j++] = 0;
1393  }
1394  } else {
1395  int tindex, tindex2, slen[4], sl, sf;
1396 
1397  /* LSF scale factors */
1398  if (g->block_type == 2)
1399  tindex = g->switch_point ? 2 : 1;
1400  else
1401  tindex = 0;
1402 
1403  sf = g->scalefac_compress;
1404  if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {
1405  /* intensity stereo case */
1406  sf >>= 1;
1407  if (sf < 180) {
1408  lsf_sf_expand(slen, sf, 6, 6, 0);
1409  tindex2 = 3;
1410  } else if (sf < 244) {
1411  lsf_sf_expand(slen, sf - 180, 4, 4, 0);
1412  tindex2 = 4;
1413  } else {
1414  lsf_sf_expand(slen, sf - 244, 3, 0, 0);
1415  tindex2 = 5;
1416  }
1417  } else {
1418  /* normal case */
1419  if (sf < 400) {
1420  lsf_sf_expand(slen, sf, 5, 4, 4);
1421  tindex2 = 0;
1422  } else if (sf < 500) {
1423  lsf_sf_expand(slen, sf - 400, 5, 4, 0);
1424  tindex2 = 1;
1425  } else {
1426  lsf_sf_expand(slen, sf - 500, 3, 0, 0);
1427  tindex2 = 2;
1428  g->preflag = 1;
1429  }
1430  }
1431 
1432  j = 0;
1433  for (k = 0; k < 4; k++) {
1434  n = ff_lsf_nsf_table[tindex2][tindex][k];
1435  sl = slen[k];
1436  if (sl) {
1437  for (i = 0; i < n; i++)
1438  g->scale_factors[j++] = get_bits(&s->gb, sl);
1439  } else {
1440  for (i = 0; i < n; i++)
1441  g->scale_factors[j++] = 0;
1442  }
1443  }
1444  /* XXX: should compute exact size */
1445  for (; j < 40; j++)
1446  g->scale_factors[j] = 0;
1447  }
1448 
1449  exponents_from_scale_factors(s, g, exponents);
1450 
1451  /* read Huffman coded residue */
1452  huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);
1453  } /* ch */
1454 
1455  if (s->mode == MPA_JSTEREO)
1456  compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]);
1457 
1458  for (ch = 0; ch < s->nb_channels; ch++) {
1459  g = &s->granules[ch][gr];
1460 
1461  reorder_block(s, g);
1462  compute_antialias(s, g);
1463  compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
1464  }
1465  } /* gr */
1466  if (get_bits_count(&s->gb) < 0)
1467  skip_bits_long(&s->gb, -get_bits_count(&s->gb));
1468  return nb_granules * 18;
1469 }
1470 
1472  const uint8_t *buf, int buf_size)
1473 {
1474  int i, nb_frames, ch, ret;
1475  OUT_INT *samples_ptr;
1476 
1477  init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8);
1478  if (s->error_protection)
1479  s->crc = get_bits(&s->gb, 16);
1480 
1481  switch(s->layer) {
1482  case 1:
1483  s->avctx->frame_size = 384;
1484  nb_frames = mp_decode_layer1(s);
1485  break;
1486  case 2:
1487  s->avctx->frame_size = 1152;
1488  nb_frames = mp_decode_layer2(s);
1489  break;
1490  case 3:
1491  s->avctx->frame_size = s->lsf ? 576 : 1152;
1492  default:
1493  nb_frames = mp_decode_layer3(s);
1494 
1495  s->last_buf_size=0;
1496  if (s->in_gb.buffer) {
1497  align_get_bits(&s->gb);
1498  i = (get_bits_left(&s->gb) >> 3) - s->extrasize;
1499  if (i >= 0 && i <= BACKSTEP_SIZE) {
1500  memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb) >> 3), i);
1501  s->last_buf_size=i;
1502  } else
1503  av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);
1504  s->gb = s->in_gb;
1505  s->in_gb.buffer = NULL;
1506  s->extrasize = 0;
1507  }
1508 
1509  align_get_bits(&s->gb);
1510  av_assert1((get_bits_count(&s->gb) & 7) == 0);
1511  i = (get_bits_left(&s->gb) >> 3) - s->extrasize;
1512  if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) {
1513  if (i < 0)
1514  av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i);
1515  i = FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);
1516  }
1517  av_assert1(i <= buf_size - HEADER_SIZE && i >= 0);
1518  memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);
1519  s->last_buf_size += i;
1520  }
1521 
1522  if(nb_frames < 0)
1523  return nb_frames;
1524 
1525  /* get output buffer */
1526  if (!samples) {
1527  av_assert0(s->frame);
1528  s->frame->nb_samples = s->avctx->frame_size;
1529  if ((ret = ff_get_buffer(s->avctx, s->frame, 0)) < 0)
1530  return ret;
1531  samples = (OUT_INT **)s->frame->extended_data;
1532  }
1533 
1534  /* apply the synthesis filter */
1535  for (ch = 0; ch < s->nb_channels; ch++) {
1536  int sample_stride;
1537  if (s->avctx->sample_fmt == OUT_FMT_P) {
1538  samples_ptr = samples[ch];
1539  sample_stride = 1;
1540  } else {
1541  samples_ptr = samples[0] + ch;
1542  sample_stride = s->nb_channels;
1543  }
1544  for (i = 0; i < nb_frames; i++) {
1545  RENAME(ff_mpa_synth_filter)(&s->mpadsp, s->synth_buf[ch],
1546  &(s->synth_buf_offset[ch]),
1547  RENAME(ff_mpa_synth_window),
1548  &s->dither_state, samples_ptr,
1549  sample_stride, s->sb_samples[ch][i]);
1550  samples_ptr += 32 * sample_stride;
1551  }
1552  }
1553 
1554  return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
1555 }
1556 
1558  int *got_frame_ptr, AVPacket *avpkt)
1559 {
1560  const uint8_t *buf = avpkt->data;
1561  int buf_size = avpkt->size;
1562  MPADecodeContext *s = avctx->priv_data;
1563  uint32_t header;
1564  int ret;
1565 
1566  int skipped = 0;
1567  while(buf_size && !*buf){
1568  buf++;
1569  buf_size--;
1570  skipped++;
1571  }
1572 
1573  if (buf_size < HEADER_SIZE)
1574  return AVERROR_INVALIDDATA;
1575 
1576  header = AV_RB32(buf);
1577  if (header >> 8 == AV_RB32("TAG") >> 8) {
1578  av_log(avctx, AV_LOG_DEBUG, "discarding ID3 tag\n");
1579  return buf_size + skipped;
1580  }
1582  if (ret < 0) {
1583  av_log(avctx, AV_LOG_ERROR, "Header missing\n");
1584  return AVERROR_INVALIDDATA;
1585  } else if (ret == 1) {
1586  /* free format: prepare to compute frame size */
1587  s->frame_size = -1;
1588  return AVERROR_INVALIDDATA;
1589  }
1590  /* update codec info */
1592  avctx->ch_layout = s->nb_channels == 1 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
1594  if (!avctx->bit_rate)
1595  avctx->bit_rate = s->bit_rate;
1596 
1597  if (s->frame_size <= 0) {
1598  av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
1599  return AVERROR_INVALIDDATA;
1600  } else if (s->frame_size < buf_size) {
1601  av_log(avctx, AV_LOG_DEBUG, "incorrect frame size - multiple frames in buffer?\n");
1602  buf_size= s->frame_size;
1603  }
1604 
1605  s->frame = frame;
1606 
1607  ret = mp_decode_frame(s, NULL, buf, buf_size);
1608  if (ret >= 0) {
1609  s->frame->nb_samples = avctx->frame_size;
1610  *got_frame_ptr = 1;
1611  avctx->sample_rate = s->sample_rate;
1612  //FIXME maybe move the other codec info stuff from above here too
1613  } else {
1614  av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");
1615  /* Only return an error if the bad frame makes up the whole packet or
1616  * the error is related to buffer management.
1617  * If there is more data in the packet, just consume the bad frame
1618  * instead of returning an error, which would discard the whole
1619  * packet. */
1620  *got_frame_ptr = 0;
1621  if (buf_size == avpkt->size || ret != AVERROR_INVALIDDATA)
1622  return ret;
1623  }
1624  s->frame_size = 0;
1625  return buf_size + skipped;
1626 }
1627 
1629 {
1630  memset(ctx->synth_buf, 0, sizeof(ctx->synth_buf));
1631  memset(ctx->mdct_buf, 0, sizeof(ctx->mdct_buf));
1632  ctx->last_buf_size = 0;
1633  ctx->dither_state = 0;
1634 }
1635 
1636 static av_cold void flush(AVCodecContext *avctx)
1637 {
1638  mp_flush(avctx->priv_data);
1639 }
1640 
1641 #if CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER
1642 static int decode_frame_adu(AVCodecContext *avctx, AVFrame *frame,
1643  int *got_frame_ptr, AVPacket *avpkt)
1644 {
1645  const uint8_t *buf = avpkt->data;
1646  int buf_size = avpkt->size;
1647  MPADecodeContext *s = avctx->priv_data;
1648  uint32_t header;
1649  int len, ret;
1650 
1651  len = buf_size;
1652 
1653  // Discard too short frames
1654  if (buf_size < HEADER_SIZE) {
1655  av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
1656  return AVERROR_INVALIDDATA;
1657  }
1658 
1659 
1662 
1663  // Get header and restore sync word
1664  header = AV_RB32(buf) | 0xffe00000;
1665 
1667  if (ret < 0) {
1668  av_log(avctx, AV_LOG_ERROR, "Invalid frame header\n");
1669  return ret;
1670  }
1671  /* update codec info */
1672  avctx->sample_rate = s->sample_rate;
1674  avctx->ch_layout = s->nb_channels == 1 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
1676  if (!avctx->bit_rate)
1677  avctx->bit_rate = s->bit_rate;
1678 
1679  s->frame_size = len;
1680 
1681  s->frame = frame;
1682 
1683  ret = mp_decode_frame(s, NULL, buf, buf_size);
1684  if (ret < 0) {
1685  av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");
1686  return ret;
1687  }
1688 
1689  *got_frame_ptr = 1;
1690 
1691  return buf_size;
1692 }
1693 #endif /* CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER */
1694 
1695 #if CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER
1696 
1697 /**
1698  * Context for MP3On4 decoder
1699  */
1700 typedef struct MP3On4DecodeContext {
1701  int frames; ///< number of mp3 frames per block (number of mp3 decoder instances)
1702  int syncword; ///< syncword patch
1703  const uint8_t *coff; ///< channel offsets in output buffer
1704  MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance
1705 } MP3On4DecodeContext;
1706 
1707 #include "mpeg4audio.h"
1708 
1709 /* Next 3 arrays are indexed by channel config number (passed via codecdata) */
1710 
1711 /* number of mp3 decoder instances */
1712 static const uint8_t mp3Frames[8] = { 0, 1, 1, 2, 3, 3, 4, 5 };
1713 
1714 /* offsets into output buffer, assume output order is FL FR C LFE BL BR SL SR */
1715 static const uint8_t chan_offset[8][5] = {
1716  { 0 },
1717  { 0 }, // C
1718  { 0 }, // FLR
1719  { 2, 0 }, // C FLR
1720  { 2, 0, 3 }, // C FLR BS
1721  { 2, 0, 3 }, // C FLR BLRS
1722  { 2, 0, 4, 3 }, // C FLR BLRS LFE
1723  { 2, 0, 6, 4, 3 }, // C FLR BLRS BLR LFE
1724 };
1725 
1726 /* mp3on4 channel layouts */
1727 static const int16_t chan_layout[8] = {
1728  0,
1736 };
1737 
1738 static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
1739 {
1740  MP3On4DecodeContext *s = avctx->priv_data;
1741 
1742  av_freep(&s->mp3decctx[0]);
1743 
1744  return 0;
1745 }
1746 
1747 
1748 static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
1749 {
1750  MP3On4DecodeContext *s = avctx->priv_data;
1751  MPEG4AudioConfig cfg;
1752  int i, ret;
1753 
1754  if ((avctx->extradata_size < 2) || !avctx->extradata) {
1755  av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n");
1756  return AVERROR_INVALIDDATA;
1757  }
1758 
1760  avctx->extradata_size, 1, avctx);
1761  if (!cfg.chan_config || cfg.chan_config > 7) {
1762  av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
1763  return AVERROR_INVALIDDATA;
1764  }
1765  s->frames = mp3Frames[cfg.chan_config];
1766  s->coff = chan_offset[cfg.chan_config];
1768  av_channel_layout_from_mask(&avctx->ch_layout, chan_layout[cfg.chan_config]);
1769 
1770  if (cfg.sample_rate < 16000)
1771  s->syncword = 0xffe00000;
1772  else
1773  s->syncword = 0xfff00000;
1774 
1775  /* Init the first mp3 decoder in standard way, so that all tables get built
1776  * Other decoders will be initialized here copying data from the first context
1777  */
1778  // Allocate zeroed memory for the decoder contexts
1779  s->mp3decctx[0] = av_calloc(s->frames, sizeof(*s->mp3decctx[0]));
1780  if (!s->mp3decctx[0])
1781  return AVERROR(ENOMEM);
1782  ret = decode_ctx_init(avctx, s->mp3decctx[0]);
1783  if (ret < 0)
1784  return ret;
1785  s->mp3decctx[0]->adu_mode = 1; // Set adu mode
1786 
1787  /* Create a separate codec/context for each frame (first is already ok).
1788  * Each frame is 1 or 2 channels - up to 5 frames allowed
1789  */
1790  for (i = 1; i < s->frames; i++) {
1791  s->mp3decctx[i] = s->mp3decctx[0] + i;
1792  s->mp3decctx[i]->adu_mode = 1;
1793  s->mp3decctx[i]->avctx = avctx;
1794  s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
1795 #if USE_FLOATS
1796  s->mp3decctx[i]->butterflies_float = s->mp3decctx[0]->butterflies_float;
1797 #endif
1798  }
1799 
1800  return 0;
1801 }
1802 
1803 
1804 static av_cold void flush_mp3on4(AVCodecContext *avctx)
1805 {
1806  int i;
1807  MP3On4DecodeContext *s = avctx->priv_data;
1808 
1809  for (i = 0; i < s->frames; i++)
1810  mp_flush(s->mp3decctx[i]);
1811 }
1812 
1813 
1814 static int decode_frame_mp3on4(AVCodecContext *avctx, AVFrame *frame,
1815  int *got_frame_ptr, AVPacket *avpkt)
1816 {
1817  const uint8_t *buf = avpkt->data;
1818  int buf_size = avpkt->size;
1819  MP3On4DecodeContext *s = avctx->priv_data;
1820  MPADecodeContext *m;
1821  int fsize, len = buf_size, out_size = 0;
1822  uint32_t header;
1823  OUT_INT **out_samples;
1824  OUT_INT *outptr[2];
1825  int fr, ch, ret;
1826 
1827  /* get output buffer */
1828  frame->nb_samples = MPA_FRAME_SIZE;
1829  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1830  return ret;
1831  out_samples = (OUT_INT **)frame->extended_data;
1832 
1833  // Discard too short frames
1834  if (buf_size < HEADER_SIZE)
1835  return AVERROR_INVALIDDATA;
1836 
1837  avctx->bit_rate = 0;
1838 
1839  ch = 0;
1840  for (fr = 0; fr < s->frames; fr++) {
1841  fsize = AV_RB16(buf) >> 4;
1843  m = s->mp3decctx[fr];
1844  av_assert1(m);
1845 
1846  if (fsize < HEADER_SIZE) {
1847  av_log(avctx, AV_LOG_ERROR, "Frame size smaller than header size\n");
1848  return AVERROR_INVALIDDATA;
1849  }
1850  header = (AV_RB32(buf) & 0x000fffff) | s->syncword; // patch header
1851 
1853  if (ret < 0) {
1854  av_log(avctx, AV_LOG_ERROR, "Bad header, discard block\n");
1855  return AVERROR_INVALIDDATA;
1856  }
1857 
1858  if (ch + m->nb_channels > avctx->ch_layout.nb_channels ||
1859  s->coff[fr] + m->nb_channels > avctx->ch_layout.nb_channels) {
1860  av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
1861  "channel count\n");
1862  return AVERROR_INVALIDDATA;
1863  }
1864  ch += m->nb_channels;
1865 
1866  outptr[0] = out_samples[s->coff[fr]];
1867  if (m->nb_channels > 1)
1868  outptr[1] = out_samples[s->coff[fr] + 1];
1869 
1870  if ((ret = mp_decode_frame(m, outptr, buf, fsize)) < 0) {
1871  av_log(avctx, AV_LOG_ERROR, "failed to decode channel %d\n", ch);
1872  memset(outptr[0], 0, MPA_FRAME_SIZE*sizeof(OUT_INT));
1873  if (m->nb_channels > 1)
1874  memset(outptr[1], 0, MPA_FRAME_SIZE*sizeof(OUT_INT));
1875  ret = m->nb_channels * MPA_FRAME_SIZE*sizeof(OUT_INT);
1876  }
1877 
1878  out_size += ret;
1879  buf += fsize;
1880  len -= fsize;
1881 
1882  avctx->bit_rate += m->bit_rate;
1883  }
1884  if (ch != avctx->ch_layout.nb_channels) {
1885  av_log(avctx, AV_LOG_ERROR, "failed to decode all channels\n");
1886  return AVERROR_INVALIDDATA;
1887  }
1888 
1889  /* update codec info */
1890  avctx->sample_rate = s->mp3decctx[0]->sample_rate;
1891 
1892  frame->nb_samples = out_size / (avctx->ch_layout.nb_channels * sizeof(OUT_INT));
1893  *got_frame_ptr = 1;
1894 
1895  return buf_size;
1896 }
1897 #endif /* CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER */
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1051
GranuleDef::scale_factors
uint8_t scale_factors[40]
Definition: mpegaudiodec_template.c:73
MPADecodeContext::last_buf
MPA_DECODE_HEADER uint8_t last_buf[LAST_BUF_SIZE]
Definition: mpegaudiodec_template.c:79
compute_band_indexes
static void compute_band_indexes(MPADecodeContext *s, GranuleDef *g)
Definition: mpegaudiodec_template.c:165
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:276
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
l3_unscale
static int l3_unscale(int value, int exponent)
Definition: mpegaudiodec_template.c:222
INTFLOAT
#define INTFLOAT
Definition: dct32_template.c:44
init_short_region
static void init_short_region(MPADecodeContext *s, GranuleDef *g)
Definition: mpegaudiodec_template.c:137
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
av_clip
#define av_clip
Definition: common.h:100
ff_mpa_l2_select_table
int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf)
Definition: mpegaudio.c:31
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:689
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
SCALE_GEN
#define SCALE_GEN(v)
Definition: mpegaudiodec_template.c:113
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:164
libm.h
mem_internal.h
MPADecodeContext::dither_state
int dither_state
Definition: mpegaudiodec_template.c:92
AV_EF_COMPLIANT
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: defs.h:55
out
FILE * out
Definition: movenc.c:55
MPADecodeContext::last_buf_size
int last_buf_size
Definition: mpegaudiodec_template.c:80
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:395
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1024
MPADecodeContext::granules
GranuleDef granules[2][2]
Definition: mpegaudiodec_template.c:90
AVCRC
uint32_t AVCRC
Definition: crc.h:46
thread.h
l1_unscale
static int l1_unscale(int n, int mant, int scale_factor)
Definition: mpegaudiodec_template.c:192
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:217
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1398
AV_CODEC_ID_MP3ON4
@ AV_CODEC_ID_MP3ON4
Definition: codec_id.h:465
int64_t
long long int64_t
Definition: coverity.c:34
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:250
ff_mpadsp_init
av_cold void ff_mpadsp_init(MPADSPContext *s)
Definition: mpegaudiodsp.c:81
out_size
int out_size
Definition: movenc.c:56
decode_ctx_init
static av_cold int decode_ctx_init(AVCodecContext *avctx, MPADecodeContext *s)
Definition: mpegaudiodec_template.c:283
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
GranuleDef::switch_point
uint8_t switch_point
Definition: mpegaudiodec_template.c:65
MPADecodeContext::adu_mode
int adu_mode
0 for standard mp3, 1 for adu formatted mp3
Definition: mpegaudiodec_template.c:91
mpegaudiodecheader.h
MPADecodeContext::butterflies_float
void(* butterflies_float)(float *restrict v1, float *restrict v2, int len)
Definition: mpegaudiodec_template.c:96
AVPacket::data
uint8_t * data
Definition: packet.h:558
C4
#define C4
Definition: mpegaudiodec_template.c:323
MPADSPContext
Definition: mpegaudiodsp.h:28
b
#define b
Definition: input.c:42
table
static const uint16_t table[]
Definition: prosumer.c:203
MPADecodeHeader
Definition: mpegaudiodecheader.h:47
mp_decode_frame
static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples, const uint8_t *buf, int buf_size)
Definition: mpegaudiodec_template.c:1471
compute_antialias
static void compute_antialias(MPADecodeContext *s, GranuleDef *g)
Definition: mpegaudiodec_template.c:1101
is_table_lsf
static INTFLOAT is_table_lsf[2][2][16]
Definition: mpegaudiodec_template.c:107
GranuleDef::scfsi
uint8_t scfsi
Definition: mpegaudiodec_template.c:59
ff_mpa_quant_bits
const int ff_mpa_quant_bits[17]
Definition: mpegaudiodata.c:42
MPADecodeContext
Definition: mpegaudiodec_template.c:77
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:512
AV_CODEC_ID_MP3ADU
@ AV_CODEC_ID_MP3ADU
Definition: codec_id.h:464
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
mpegaudio_tableinit
static av_cold void mpegaudio_tableinit(void)
Definition: mpegaudio_tablegen.h:48
MPEG4AudioConfig
Definition: mpeg4audio.h:29
crc.h
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:379
ff_table_4_3_exp
int8_t ff_table_4_3_exp[TABLE_4_3_SIZE]
Definition: mpegaudiodec_common_tablegen.h:38
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:333
exponents_from_scale_factors
static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g, int16_t *exponents)
Definition: mpegaudiodec_template.c:688
mpeg4audio.h
reorder_block
static void reorder_block(MPADecodeContext *s, GranuleDef *g)
Definition: mpegaudiodec_template.c:908
MULH3
#define MULH3(x, y, s)
Definition: dct32_template.c:43
mp_decode_layer3
static int mp_decode_layer3(MPADecodeContext *s)
Definition: mpegaudiodec_template.c:1212
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1039
MPADecodeContext::gb
GetBitContext gb
Definition: mpegaudiodec_template.c:84
frames
if it could not because there are no more frames
Definition: filter_design.txt:267
GetBitContext
Definition: get_bits.h:109
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: defs.h:49
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:488
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:218
ff_slen_table
const uint8_t ff_slen_table[2][16]
Definition: mpegaudiodec_common.c:52
tab1
const int16_t * tab1
Definition: mace.c:145
bit_alloc
static int bit_alloc(AC3EncodeContext *s, int snr_offset)
Run the bit allocation with a given SNR offset.
Definition: ac3enc.c:1368
MPA_FRAME_SIZE
#define MPA_FRAME_SIZE
Definition: mpegaudio.h:37
FRAC_ONE
#define FRAC_ONE
Definition: mpegaudio.h:58
avassert.h
MPADecodeContext::in_gb
GetBitContext in_gb
Definition: mpegaudiodec_template.c:85
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
ff_mpa_quant_steps
const int ff_mpa_quant_steps[17]
Definition: mpegaudiodata.c:34
avpriv_mpegaudio_decode_header
int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
Definition: mpegaudiodecheader.c:34
av_cold
#define av_cold
Definition: attributes.h:90
compute_imdct
static void compute_imdct(MPADecodeContext *s, GranuleDef *g, INTFLOAT *sb_samples, INTFLOAT *mdct_buf)
Definition: mpegaudiodec_template.c:1132
imdct12
static void imdct12(INTFLOAT *out, SUINTFLOAT *in)
Definition: mpegaudiodec_template.c:329
MODE_EXT_MS_STEREO
#define MODE_EXT_MS_STEREO
Definition: mpegaudiodata.h:37
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:515
ff_mpa_huff_data
const uint8_t ff_mpa_huff_data[32][2]
Definition: mpegaudiodec_common.c:315
avpriv_mpeg4audio_get_config2
int avpriv_mpeg4audio_get_config2(MPEG4AudioConfig *c, const uint8_t *buf, int size, int sync_extension, void *logctx)
Parse MPEG-4 systems extradata from a raw buffer to retrieve audio configuration.
Definition: mpeg4audio.c:165
s
#define s(width, name)
Definition: cbs_vp9.c:198
GranuleDef::scalefac_compress
int scalefac_compress
Definition: mpegaudiodec_template.c:63
compute_antialias_fixed.h
ff_mpegaudiodec_common_init_static
void ff_mpegaudiodec_common_init_static(void)
Definition: mpegaudiodec_common.c:476
g
const char * g
Definition: vf_curves.c:128
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:252
BACKSTEP_SIZE
#define BACKSTEP_SIZE
Definition: mpegaudiodec_template.c:53
bits
uint8_t bits
Definition: vp3data.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
AVFormatContext * ctx
Definition: movenc.c:49
decode.h
get_bits.h
GranuleDef::subblock_gain
int subblock_gain[3]
Definition: mpegaudiodec_template.c:67
GranuleDef::table_select
int table_select[3]
Definition: mpegaudiodec_template.c:66
MPADecodeContext::crc
uint32_t crc
Definition: mpegaudiodec_template.c:98
OUT_FMT_P
#define OUT_FMT_P
Definition: mpegaudiodec_fixed.c:39
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
ff_mpa_alloc_tables
const unsigned char *const ff_mpa_alloc_tables[5]
Definition: mpegaudiodata.c:132
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
SPLIT
#define SPLIT(dst, sf, n)
Definition: mpegaudiodec_template.c:659
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:441
compute_stereo
static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
Definition: mpegaudiodec_template.c:943
if
if(ret)
Definition: filter_design.txt:179
GranuleDef::big_values
int big_values
Definition: mpegaudiodec_template.c:61
AV_CRC_16_ANSI
@ AV_CRC_16_ANSI
Definition: crc.h:50
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
NULL
#define NULL
Definition: coverity.c:32
bits_left
#define bits_left
Definition: bitstream.h:116
huffman_decode
static int huffman_decode(MPADecodeContext *s, GranuleDef *g, int16_t *exponents, int end_pos2)
Definition: mpegaudiodec_template.c:756
HEADER_SIZE
#define HEADER_SIZE
Definition: mpegaudiodec_template.c:101
MULLx
#define MULLx(x, y, s)
Definition: mpegaudiodec_fixed.c:36
MPADecodeContext::avctx
AVCodecContext * avctx
Definition: mpegaudiodec_template.c:94
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:481
GranuleDef::sb_hybrid
int sb_hybrid[SBLIMIT *18]
Definition: mpegaudiodec_template.c:74
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:386
flush
static av_cold void flush(AVCodecContext *avctx)
Definition: mpegaudiodec_template.c:1636
mp_decode_layer1
static int mp_decode_layer1(MPADecodeContext *s)
Definition: mpegaudiodec_template.c:397
mathops.h
AV_CH_LAYOUT_5POINT1
#define AV_CH_LAYOUT_5POINT1
Definition: channel_layout.h:228
GranuleDef::part2_3_length
int part2_3_length
Definition: mpegaudiodec_template.c:60
AA
#define AA(j)
Definition: mpegaudiodec_template.c:1092
ff_huff_quad_vlc
VLC ff_huff_quad_vlc[2]
Definition: mpegaudiodec_common.c:70
MPADecodeContext::mpadsp
MPADSPContext mpadsp
Definition: mpegaudiodec_template.c:95
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
SBLIMIT
#define SBLIMIT
Definition: mpegaudio.h:44
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:646
GranuleDef::scalefac_scale
uint8_t scalefac_scale
Definition: mpegaudiodec_template.c:68
AVOnce
#define AVOnce
Definition: thread.h:202
float_dsp.h
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:415
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
OUT_FMT
#define OUT_FMT
Definition: mpegaudiodec_fixed.c:38
f
f
Definition: af_crystalizer.c:122
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1720
AVPacket::size
int size
Definition: packet.h:559
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
lsf_sf_expand
static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2, int n3)
Definition: mpegaudiodec_template.c:679
ff_division_tabs
int16_t *const ff_division_tabs[4]
Definition: mpegaudiodec_common.c:44
GranuleDef
Definition: mpegaudiodec_template.c:58
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1031
VLCElem
Definition: vlc.h:32
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
OUT_INT
int16_t OUT_INT
Definition: mpegaudio.h:76
AVFloatDSPContext
Definition: float_dsp.h:24
READ_FLIP_SIGN
#define READ_FLIP_SIGN(dst, src)
Definition: mpegaudiodec_template.c:751
header
static const uint8_t header[24]
Definition: sdr2.c:68
MPADecodeContext::free_format_next_header
uint32_t free_format_next_header
Definition: mpegaudiodec_template.c:83
mp_flush
static av_cold void mp_flush(MPADecodeContext *ctx)
Definition: mpegaudiodec_template.c:1628
GranuleDef::block_type
uint8_t block_type
Definition: mpegaudiodec_template.c:64
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
MPA_DECODE_HEADER
#define MPA_DECODE_HEADER
Definition: mpegaudiodecheader.h:35
AVCodecContext::request_sample_fmt
enum AVSampleFormat request_sample_fmt
desired sample format
Definition: avcodec.h:1079
attributes.h
decode_init_static
static av_cold void decode_init_static(void)
Definition: mpegaudiodec_template.c:241
MPADecodeContext::frame
AVFrame * frame
Definition: mpegaudiodec_template.c:97
handle_crc
static int handle_crc(MPADecodeContext *s, int sec_len)
Definition: mpegaudiodec_template.c:370
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
scale_factor_mult
static int32_t scale_factor_mult[15][3]
Definition: mpegaudiodec_template.c:110
AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_5POINT0
Definition: channel_layout.h:227
switch_buffer
static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, int *end_pos2)
Definition: mpegaudiodec_template.c:725
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:514
ff_mpa_sblimit_table
const int ff_mpa_sblimit_table[5]
Definition: mpegaudiodata.c:32
GranuleDef::region_size
int region_size[3]
Definition: mpegaudiodec_template.c:70
FFMIN3
#define FFMIN3(a, b, c)
Definition: macros.h:50
is_table
static const int32_t is_table[2][16]
Definition: mpegaudiodec_fixed.c:43
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
AV_CH_LAYOUT_7POINT1
#define AV_CH_LAYOUT_7POINT1
Definition: channel_layout.h:240
exp2
#define exp2(x)
Definition: libm.h:290
av_always_inline
#define av_always_inline
Definition: attributes.h:49
value
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 default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
MPADecodeContext::synth_buf
MPA_INT synth_buf[MPA_MAX_CHANNELS][512 *2]
Definition: mpegaudiodec_template.c:86
SUINT
#define SUINT
Definition: dct32_template.c:30
MPEG4AudioConfig::chan_config
int chan_config
Definition: mpeg4audio.h:33
len
int len
Definition: vorbis_enc_data.h:426
ff_band_index_long
uint16_t ff_band_index_long[9][23]
Definition: mpegaudiodec_common.c:395
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
mod
static int mod(int a, int b)
Modulo operation with only positive remainders.
Definition: vf_v360.c:755
mpegaudio.h
mpegaudio_tablegen.h
avcodec.h
VLC::bits
int bits
Definition: vlc.h:51
LAST_BUF_SIZE
#define LAST_BUF_SIZE
Definition: mpegaudiodec_template.c:55
bound
static double bound(const double threshold, const double val)
Definition: af_dynaudnorm.c:413
ret
ret
Definition: filter_design.txt:187
AV_EF_AGGRESSIVE
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
Definition: defs.h:56
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:265
AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_SURROUND
Definition: channel_layout.h:221
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:555
pos
unsigned int pos
Definition: spdifenc.c:414
U
#define U(x)
Definition: vpx_arith.h:37
ff_table_4_3_value
uint32_t ff_table_4_3_value[TABLE_4_3_SIZE]
Definition: mpegaudiodec_common_tablegen.h:39
steps
static const int16_t steps[16]
Definition: misc4.c:30
AVCodecContext
main external API structure.
Definition: avcodec.h:431
GranuleDef::global_gain
int global_gain
Definition: mpegaudiodec_template.c:62
RENAME
#define RENAME(element)
Definition: ac3enc_template.c:44
channel_layout.h
FRAC_BITS
#define FRAC_BITS
Definition: g729postfilter.c:36
MPADecodeContext::synth_buf_offset
int synth_buf_offset[MPA_MAX_CHANNELS]
Definition: mpegaudiodec_template.c:87
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
ff_mpa_pretab
const uint8_t ff_mpa_pretab[2][22]
Definition: mpegaudiodec_common.c:397
C3
#define C3
Definition: mpegaudiodec_template.c:322
VLC
Definition: vlc.h:50
region_offset2size
static void region_offset2size(GranuleDef *g)
Convert region offsets to region sizes and truncate size to big_values.
Definition: mpegaudiodec_template.c:126
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:442
init_long_region
static void init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2)
Definition: mpegaudiodec_template.c:155
MODE_EXT_I_STEREO
#define MODE_EXT_I_STEREO
Definition: mpegaudiodata.h:38
MUL64
#define MUL64(a, b)
Definition: mathops.h:54
MPA_JSTEREO
#define MPA_JSTEREO
Definition: mpegaudio.h:47
alloc_table
static int alloc_table(VLC *vlc, int size, int use_static)
Definition: vlc.c:60
ff_huff_vlc
const VLCElem * ff_huff_vlc[16]
Definition: mpegaudiodec_common.c:67
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
VLC::table
VLCElem * table
Definition: vlc.h:52
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
MPADecodeContext::extrasize
int extrasize
Definition: mpegaudiodec_template.c:81
l2_unscale_group
static int l2_unscale_group(int steps, int mant, int scale_factor)
Definition: mpegaudiodec_template.c:206
GranuleDef::preflag
int preflag
Definition: mpegaudiodec_template.c:71
mpegaudiodata.h
MPADecodeContext::sb_samples
int sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]
Definition: mpegaudiodec_template.c:88
mpegaudiodsp.h
MPA_INT
int32_t MPA_INT
Definition: mpegaudio.h:75
GranuleDef::count1table_select
uint8_t count1table_select
Definition: mpegaudiodec_template.c:69
ff_band_size_long
const uint8_t ff_band_size_long[9][22]
Definition: mpegaudiodec_common.c:362
mem.h
ff_scale_factor_modshift
uint16_t ff_scale_factor_modshift[64]
Definition: mpegaudiodec_common.c:38
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:349
AV_EF_BUFFER
#define AV_EF_BUFFER
detect improper bitstream length
Definition: defs.h:50
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:322
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:37
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:394
MPADecodeContext::err_recognition
int err_recognition
Definition: mpegaudiodec_template.c:93
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:273
AVPacket
This structure stores compressed data.
Definition: packet.h:535
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
ff_lsf_nsf_table
const uint8_t ff_lsf_nsf_table[6][3][4]
Definition: mpegaudiodec_common.c:57
C5
#define C5
Definition: mpegaudiodec_template.c:324
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: mpegaudiodec_template.c:317
AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_4POINT0
Definition: channel_layout.h:223
scale_factor_mult2
static const int32_t scale_factor_mult2[3][3]
Definition: mpegaudiodec_template.c:116
int32_t
int32_t
Definition: audioconvert.c:56
ff_band_size_short
const uint8_t ff_band_size_short[9][13]
Definition: mpegaudiodec_common.c:383
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
C6
#define C6
Definition: mpegaudiodec_template.c:325
ISQRT2
#define ISQRT2
Definition: mpegaudiodec_template.c:941
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MPA_MAX_CHANNELS
#define MPA_MAX_CHANNELS
Definition: mpegaudio.h:42
MPADecodeContext::mdct_buf
INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT *18]
Definition: mpegaudiodec_template.c:89
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: mpegaudiodec_template.c:1557
SUINTFLOAT
#define SUINTFLOAT
Definition: dct32_template.c:45
MPA_MAX_CODED_FRAME_SIZE
#define MPA_MAX_CODED_FRAME_SIZE
Definition: mpegaudio.h:40
GranuleDef::short_start
int short_start
Definition: mpegaudiodec_template.c:72
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:101
SHR
#define SHR(a, b)
Definition: mpegaudiodec_fixed.c:30
compute_antialias_float.h
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:383
FIXR
#define FIXR(x)
Definition: aac_defines.h:107
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98
GranuleDef::long_end
int long_end
Definition: mpegaudiodec_template.c:72
MPEG4AudioConfig::sample_rate
int sample_rate
Definition: mpeg4audio.h:32
mp_decode_layer2
static int mp_decode_layer2(MPADecodeContext *s)
Definition: mpegaudiodec_template.c:467