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