/*
* MPEG Audio decoder
- * Copyright (c) 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2001, 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
*
*/
/**
- * @file mpegaudiodec.c
+ * @file libavcodec/mpegaudiodec.c
* MPEG Audio decoder.
*/
-//#define DEBUG
#include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
#include "dsputil.h"
/*
* - test lsf / mpeg25 extensively.
*/
-/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
- audio decoder */
-#ifdef CONFIG_MPEGAUDIO_HP
-# define USE_HIGHPRECISION
-#endif
-
#include "mpegaudio.h"
#include "mpegaudiodecheader.h"
#define HEADER_SIZE 4
-/* layer 3 "granule" */
-typedef struct GranuleDef {
- uint8_t scfsi;
- int part2_3_length;
- int big_values;
- int global_gain;
- int scalefac_compress;
- uint8_t block_type;
- uint8_t switch_point;
- int table_select[3];
- int subblock_gain[3];
- uint8_t scalefac_scale;
- uint8_t count1table_select;
- int region_size[3]; /* number of huffman codes in each region */
- int preflag;
- int short_start, long_end; /* long/short band indexes */
- uint8_t scale_factors[40];
- int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */
-} GranuleDef;
-
#include "mpegaudiodata.h"
#include "mpegaudiodectab.h"
/* vlc structure for decoding layer 3 huffman tables */
static VLC huff_vlc[16];
+static VLC_TYPE huff_vlc_tables[
+ 0+128+128+128+130+128+154+166+
+ 142+204+190+170+542+460+662+414
+ ][2];
+static const int huff_vlc_tables_sizes[16] = {
+ 0, 128, 128, 128, 130, 128, 154, 166,
+ 142, 204, 190, 170, 542, 460, 662, 414
+};
static VLC huff_quad_vlc[2];
+static VLC_TYPE huff_quad_vlc_tables[128+16][2];
+static const int huff_quad_vlc_tables_sizes[2] = {
+ 128, 16
+};
/* computed from band_size_long */
static uint16_t band_index_long[9][23];
-/* XXX: free when all decoders are closed */
-#define TABLE_4_3_SIZE (8191 + 16)*4
-static int8_t table_4_3_exp[TABLE_4_3_SIZE];
-static uint32_t table_4_3_value[TABLE_4_3_SIZE];
-static uint32_t exp_table[512];
-static uint32_t expval_table[512][16];
+#include "mpegaudio_tablegen.h"
/* intensity stereo coef table */
static int32_t is_table[2][16];
static int32_t is_table_lsf[2][2][16];
SCALE_GEN(4.0 / 9.0), /* 9 steps */
};
-static DECLARE_ALIGNED_16(MPA_INT, window[512]);
+DECLARE_ALIGNED_16(MPA_INT, ff_mpa_synth_window[512]);
/**
* Convert region offsets to region sizes and truncate
};
#endif
-static void int_pow_init(void)
+static av_cold void int_pow_init(void)
{
int i, a;
}
#endif
-static int decode_init(AVCodecContext * avctx)
+static av_cold int decode_init(AVCodecContext * avctx)
{
MPADecodeContext *s = avctx->priv_data;
static int init=0;
s->avctx = avctx;
-#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
- avctx->sample_fmt= SAMPLE_FMT_S32;
-#else
- avctx->sample_fmt= SAMPLE_FMT_S16;
-#endif
- s->error_resilience= avctx->error_resilience;
+ avctx->sample_fmt= OUT_FMT;
+ s->error_recognition= avctx->error_recognition;
if(avctx->antialias_algo != FF_AA_FLOAT)
s->compute_antialias= compute_antialias_integer;
s->compute_antialias= compute_antialias_float;
if (!init && !avctx->parse_only) {
+ int offset;
+
/* scale factors table for layer 1/2 */
for(i=0;i<64;i++) {
int shift, mod;
int n, norm;
n = i + 2;
norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
- scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
- scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
- scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
+ scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm, FRAC_BITS);
+ scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm, FRAC_BITS);
+ scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm, FRAC_BITS);
dprintf(avctx, "%d: norm=%x s=%x %x %x\n",
i, norm,
scale_factor_mult[i][0],
scale_factor_mult[i][2]);
}
- ff_mpa_synth_init(window);
+ ff_mpa_synth_init(ff_mpa_synth_window);
/* huffman decode tables */
+ offset = 0;
for(i=1;i<16;i++) {
const HuffTable *h = &mpa_huff_tables[i];
int xsize, x, y;
- unsigned int n;
uint8_t tmp_bits [512];
uint16_t tmp_codes[512];
memset(tmp_codes, 0, sizeof(tmp_codes));
xsize = h->xsize;
- n = xsize * xsize;
j = 0;
for(x=0;x<xsize;x++) {
}
/* XXX: fail test */
+ huff_vlc[i].table = huff_vlc_tables+offset;
+ huff_vlc[i].table_allocated = huff_vlc_tables_sizes[i];
init_vlc(&huff_vlc[i], 7, 512,
- tmp_bits, 1, 1, tmp_codes, 2, 2, 1);
+ tmp_bits, 1, 1, tmp_codes, 2, 2,
+ INIT_VLC_USE_NEW_STATIC);
+ offset += huff_vlc_tables_sizes[i];
}
+ assert(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
+
+ offset = 0;
for(i=0;i<2;i++) {
+ huff_quad_vlc[i].table = huff_quad_vlc_tables+offset;
+ huff_quad_vlc[i].table_allocated = huff_quad_vlc_tables_sizes[i];
init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
- mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1, 1);
+ mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1,
+ INIT_VLC_USE_NEW_STATIC);
+ offset += huff_quad_vlc_tables_sizes[i];
}
+ assert(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables));
for(i=0;i<9;i++) {
k = 0;
/* compute n ^ (4/3) and store it in mantissa/exp format */
int_pow_init();
- for(i=1;i<TABLE_4_3_SIZE;i++) {
- double f, fm;
- int e, m;
- f = pow((double)(i/4), 4.0 / 3.0) * pow(2, (i&3)*0.25);
- fm = frexp(f, &e);
- m = (uint32_t)(fm*(1LL<<31) + 0.5);
- e+= FRAC_BITS - 31 + 5 - 100;
-
- /* normalized to FRAC_BITS */
- table_4_3_value[i] = m;
-// av_log(NULL, AV_LOG_DEBUG, "%d %d %f\n", i, m, pow((double)i, 4.0 / 3.0));
- table_4_3_exp[i] = -e;
- }
- for(i=0; i<512*16; i++){
- int exponent= (i>>4);
- double f= pow(i&15, 4.0 / 3.0) * pow(2, (exponent-400)*0.25 + FRAC_BITS + 5);
- expval_table[exponent][i&15]= llrint(f);
- if((i&15)==1)
- exp_table[exponent]= llrint(f);
- }
+ mpegaudio_tableinit();
for(i=0;i<7;i++) {
float f;
csa_table_float[i][1] = ca;
csa_table_float[i][2] = ca + cs;
csa_table_float[i][3] = ca - cs;
-// printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca));
-// av_log(NULL, AV_LOG_DEBUG,"%f %f %f %f\n", cs, ca, ca+cs, ca-cs);
}
/* compute mdct windows */
mdct_win[j][i/3] = FIXHR((d / (1<<5)));
else
mdct_win[j][i ] = FIXHR((d / (1<<5)));
-// av_log(NULL, AV_LOG_DEBUG, "%2d %d %f\n", i,j,d / (1<<5));
}
}
}
}
-#if defined(DEBUG)
- for(j=0;j<8;j++) {
- av_log(avctx, AV_LOG_DEBUG, "win%d=\n", j);
- for(i=0;i<36;i++)
- av_log(avctx, AV_LOG_DEBUG, "%f, ", (double)mdct_win[j][i] / FRAC_ONE);
- av_log(avctx, AV_LOG_DEBUG, "\n");
- }
-#endif
init = 1;
}
-#ifdef DEBUG
- s->frame_count = 0;
-#endif
if (avctx->codec_id == CODEC_ID_MP3ADU)
s->adu_mode = 1;
return 0;
int sum1;
sum1 = (*sum) >> OUT_SHIFT;
*sum &= (1<<OUT_SHIFT)-1;
- if (sum1 < OUT_MIN)
- sum1 = OUT_MIN;
- else if (sum1 > OUT_MAX)
- sum1 = OUT_MAX;
- return sum1;
+ return av_clip(sum1, OUT_MIN, OUT_MAX);
}
/* signed 16x16 -> 32 multiply add accumulate */
/* signed 16x16 -> 32 multiply */
#define MULS(ra, rb) MUL16(ra, rb)
+#define MLSS(rt, ra, rb) MLS16(rt, ra, rb)
+
#else
static inline int round_sample(int64_t *sum)
int sum1;
sum1 = (int)((*sum) >> OUT_SHIFT);
*sum &= (1<<OUT_SHIFT)-1;
- if (sum1 < OUT_MIN)
- sum1 = OUT_MIN;
- else if (sum1 > OUT_MAX)
- sum1 = OUT_MAX;
- return sum1;
+ return av_clip(sum1, OUT_MIN, OUT_MAX);
}
# define MULS(ra, rb) MUL64(ra, rb)
+# define MACS(rt, ra, rb) MAC64(rt, ra, rb)
+# define MLSS(rt, ra, rb) MLS64(rt, ra, rb)
#endif
-#define SUM8(sum, op, w, p) \
-{ \
- sum op MULS((w)[0 * 64], p[0 * 64]);\
- sum op MULS((w)[1 * 64], p[1 * 64]);\
- sum op MULS((w)[2 * 64], p[2 * 64]);\
- sum op MULS((w)[3 * 64], p[3 * 64]);\
- sum op MULS((w)[4 * 64], p[4 * 64]);\
- sum op MULS((w)[5 * 64], p[5 * 64]);\
- sum op MULS((w)[6 * 64], p[6 * 64]);\
- sum op MULS((w)[7 * 64], p[7 * 64]);\
+#define SUM8(op, sum, w, p) \
+{ \
+ op(sum, (w)[0 * 64], (p)[0 * 64]); \
+ op(sum, (w)[1 * 64], (p)[1 * 64]); \
+ op(sum, (w)[2 * 64], (p)[2 * 64]); \
+ op(sum, (w)[3 * 64], (p)[3 * 64]); \
+ op(sum, (w)[4 * 64], (p)[4 * 64]); \
+ op(sum, (w)[5 * 64], (p)[5 * 64]); \
+ op(sum, (w)[6 * 64], (p)[6 * 64]); \
+ op(sum, (w)[7 * 64], (p)[7 * 64]); \
}
#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
{ \
int tmp;\
tmp = p[0 * 64];\
- sum1 op1 MULS((w1)[0 * 64], tmp);\
- sum2 op2 MULS((w2)[0 * 64], tmp);\
+ op1(sum1, (w1)[0 * 64], tmp);\
+ op2(sum2, (w2)[0 * 64], tmp);\
tmp = p[1 * 64];\
- sum1 op1 MULS((w1)[1 * 64], tmp);\
- sum2 op2 MULS((w2)[1 * 64], tmp);\
+ op1(sum1, (w1)[1 * 64], tmp);\
+ op2(sum2, (w2)[1 * 64], tmp);\
tmp = p[2 * 64];\
- sum1 op1 MULS((w1)[2 * 64], tmp);\
- sum2 op2 MULS((w2)[2 * 64], tmp);\
+ op1(sum1, (w1)[2 * 64], tmp);\
+ op2(sum2, (w2)[2 * 64], tmp);\
tmp = p[3 * 64];\
- sum1 op1 MULS((w1)[3 * 64], tmp);\
- sum2 op2 MULS((w2)[3 * 64], tmp);\
+ op1(sum1, (w1)[3 * 64], tmp);\
+ op2(sum2, (w2)[3 * 64], tmp);\
tmp = p[4 * 64];\
- sum1 op1 MULS((w1)[4 * 64], tmp);\
- sum2 op2 MULS((w2)[4 * 64], tmp);\
+ op1(sum1, (w1)[4 * 64], tmp);\
+ op2(sum2, (w2)[4 * 64], tmp);\
tmp = p[5 * 64];\
- sum1 op1 MULS((w1)[5 * 64], tmp);\
- sum2 op2 MULS((w2)[5 * 64], tmp);\
+ op1(sum1, (w1)[5 * 64], tmp);\
+ op2(sum2, (w2)[5 * 64], tmp);\
tmp = p[6 * 64];\
- sum1 op1 MULS((w1)[6 * 64], tmp);\
- sum2 op2 MULS((w2)[6 * 64], tmp);\
+ op1(sum1, (w1)[6 * 64], tmp);\
+ op2(sum2, (w2)[6 * 64], tmp);\
tmp = p[7 * 64];\
- sum1 op1 MULS((w1)[7 * 64], tmp);\
- sum2 op2 MULS((w2)[7 * 64], tmp);\
+ op1(sum1, (w1)[7 * 64], tmp);\
+ op2(sum2, (w2)[7 * 64], tmp);\
}
-void ff_mpa_synth_init(MPA_INT *window)
+void av_cold ff_mpa_synth_init(MPA_INT *window)
{
int i;
OUT_INT *samples, int incr,
int32_t sb_samples[SBLIMIT])
{
- int32_t tmp[32];
register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p;
- int j, offset, v;
+ int j, offset;
OUT_INT *samples2;
#if FRAC_BITS <= 15
+ int32_t tmp[32];
int sum, sum2;
#else
int64_t sum, sum2;
#endif
- dct32(tmp, sb_samples);
-
offset = *synth_buf_offset;
synth_buf = synth_buf_ptr + offset;
- for(j=0;j<32;j++) {
- v = tmp[j];
#if FRAC_BITS <= 15
+ dct32(tmp, sb_samples);
+ for(j=0;j<32;j++) {
/* NOTE: can cause a loss in precision if very high amplitude
sound */
- v = av_clip_int16(v);
-#endif
- synth_buf[j] = v;
+ synth_buf[j] = av_clip_int16(tmp[j]);
}
+#else
+ dct32(synth_buf, sb_samples);
+#endif
+
/* copy to avoid wrap */
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
sum = *dither_state;
p = synth_buf + 16;
- SUM8(sum, +=, w, p);
+ SUM8(MACS, sum, w, p);
p = synth_buf + 48;
- SUM8(sum, -=, w + 32, p);
+ SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
- SUM8P2(sum, +=, sum2, -=, w, w2, p);
+ SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
- SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
+ SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
}
p = synth_buf + 32;
- SUM8(sum, -=, w + 32, p);
+ SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
t2 = tmp[i + 1];
t3 = tmp[i + 3];
s1 = MULH(2*(t3 + t2), icos36h[j]);
- s3 = MULL(t3 - t2, icos36[8 - j]);
+ s3 = MULL(t3 - t2, icos36[8 - j], FRAC_BITS);
t0 = s0 + s1;
t1 = s0 - s1;
j += 1 << bit_alloc_bits;
}
-#ifdef DEBUG
- {
- for(ch=0;ch<s->nb_channels;ch++) {
- for(i=0;i<sblimit;i++)
- dprintf(s->avctx, " %d", bit_alloc[ch][i]);
- dprintf(s->avctx, "\n");
- }
- }
-#endif
-
/* scale codes */
for(i=0;i<sblimit;i++) {
for(ch=0;ch<s->nb_channels;ch++) {
}
}
-#ifdef DEBUG
- for(ch=0;ch<s->nb_channels;ch++) {
- for(i=0;i<sblimit;i++) {
- if (bit_alloc[ch][i]) {
- sf = scale_factors[ch][i];
- dprintf(s->avctx, " %d %d %d", sf[0], sf[1], sf[2]);
- } else {
- dprintf(s->avctx, " -");
- }
- }
- dprintf(s->avctx, "\n");
- }
-#endif
-
/* samples */
for(k=0;k<3;k++) {
for(l=0;l<12;l+=3) {
part. We must go back into the data */
s_index -= 4;
skip_bits_long(&s->gb, last_pos - pos);
- av_log(NULL, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
- if(s->error_resilience >= FF_ER_COMPLIANT)
+ av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
+ if(s->error_recognition >= FF_ER_COMPLIANT)
s_index=0;
break;
}
/* skip extension bits */
bits_left = end_pos2 - get_bits_count(&s->gb);
//av_log(NULL, AV_LOG_ERROR, "left:%d buf:%p\n", bits_left, s->in_gb.buffer);
- if (bits_left < 0/* || bits_left > 500*/) {
- av_log(NULL, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
+ if (bits_left < 0 && s->error_recognition >= FF_ER_COMPLIANT) {
+ av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
s_index=0;
- }else if(bits_left > 0 && s->error_resilience >= FF_ER_AGGRESSIVE){
- av_log(NULL, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
+ }else if(bits_left > 0 && s->error_recognition >= FF_ER_AGGRESSIVE){
+ av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
s_index=0;
}
memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*(576 - s_index));
v2 = is_tab[1][sf];
for(j=0;j<len;j++) {
tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
+ tab0[j] = MULL(tmp0, v1, FRAC_BITS);
+ tab1[j] = MULL(tmp0, v2, FRAC_BITS);
}
} else {
found1:
for(j=0;j<len;j++) {
tmp0 = tab0[j];
tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
+ tab0[j] = MULL(tmp0 + tmp1, ISQRT2, FRAC_BITS);
+ tab1[j] = MULL(tmp0 - tmp1, ISQRT2, FRAC_BITS);
}
}
}
v2 = is_tab[1][sf];
for(j=0;j<len;j++) {
tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
+ tab0[j] = MULL(tmp0, v1, FRAC_BITS);
+ tab1[j] = MULL(tmp0, v2, FRAC_BITS);
}
} else {
found2:
for(j=0;j<len;j++) {
tmp0 = tab0[j];
tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
+ tab0[j] = MULL(tmp0 + tmp1, ISQRT2, FRAC_BITS);
+ tab1[j] = MULL(tmp0 - tmp1, ISQRT2, FRAC_BITS);
}
}
}
}
}
-#if defined(DEBUG)
-void sample_dump(int fnum, int32_t *tab, int n)
-{
- static FILE *files[16], *f;
- char buf[512];
- int i;
- int32_t v;
-
- f = files[fnum];
- if (!f) {
- snprintf(buf, sizeof(buf), "/tmp/out%d.%s.pcm",
- fnum,
-#ifdef USE_HIGHPRECISION
- "hp"
-#else
- "lp"
-#endif
- );
- f = fopen(buf, "w");
- if (!f)
- return;
- files[fnum] = f;
- }
-
- if (fnum == 0) {
- static int pos = 0;
- av_log(NULL, AV_LOG_DEBUG, "pos=%d\n", pos);
- for(i=0;i<n;i++) {
- av_log(NULL, AV_LOG_DEBUG, " %0.4f", (double)tab[i] / FRAC_ONE);
- if ((i % 18) == 17)
- av_log(NULL, AV_LOG_DEBUG, "\n");
- }
- pos += n;
- }
- for(i=0;i<n;i++) {
- /* normalize to 23 frac bits */
- v = tab[i] << (23 - FRAC_BITS);
- fwrite(&v, 1, sizeof(int32_t), f);
- }
-}
-#endif
-
-
/* main layer3 decoding function */
static int mp_decode_layer3(MPADecodeContext *s)
{
int nb_granules, main_data_begin, private_bits;
int gr, ch, blocksplit_flag, i, j, k, n, bits_pos;
- GranuleDef granules[2][2], *g;
+ GranuleDef *g;
int16_t exponents[576];
/* read side info */
private_bits = get_bits(&s->gb, 5);
nb_granules = 2;
for(ch=0;ch<s->nb_channels;ch++) {
- granules[ch][0].scfsi = 0; /* all scale factors are transmitted */
- granules[ch][1].scfsi = get_bits(&s->gb, 4);
+ s->granules[ch][0].scfsi = 0;/* all scale factors are transmitted */
+ s->granules[ch][1].scfsi = get_bits(&s->gb, 4);
}
}
for(gr=0;gr<nb_granules;gr++) {
for(ch=0;ch<s->nb_channels;ch++) {
dprintf(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch);
- g = &granules[ch][gr];
+ g = &s->granules[ch][gr];
g->part2_3_length = get_bits(&s->gb, 12);
g->big_values = get_bits(&s->gb, 9);
if(g->big_values > 288){
if (blocksplit_flag) {
g->block_type = get_bits(&s->gb, 2);
if (g->block_type == 0){
- av_log(NULL, AV_LOG_ERROR, "invalid block type\n");
+ av_log(s->avctx, AV_LOG_ERROR, "invalid block type\n");
return -1;
}
g->switch_point = get_bits1(&s->gb);
for(gr=0;gr<nb_granules;gr++) {
for(ch=0;ch<s->nb_channels;ch++) {
- g = &granules[ch][gr];
+ g = &s->granules[ch][gr];
if(get_bits_count(&s->gb)<0){
- av_log(NULL, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skipping granule %d\n",
+ av_log(s->avctx, AV_LOG_DEBUG, "mdb:%d, lastbuf:%d skipping granule %d\n",
main_data_begin, s->last_buf_size, gr);
skip_bits_long(&s->gb, g->part2_3_length);
memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));
g->scale_factors[j++] = 0;
}
} else {
- sc = granules[ch][0].scale_factors;
+ sc = s->granules[ch][0].scale_factors;
j = 0;
for(k=0;k<4;k++) {
n = (k == 0 ? 6 : 5);
}
g->scale_factors[j++] = 0;
}
-#if defined(DEBUG)
- {
- dprintf(s->avctx, "scfsi=%x gr=%d ch=%d scale_factors:\n",
- g->scfsi, gr, ch);
- for(i=0;i<j;i++)
- dprintf(s->avctx, " %d", g->scale_factors[i]);
- dprintf(s->avctx, "\n");
- }
-#endif
} else {
int tindex, tindex2, slen[4], sl, sf;
/* XXX: should compute exact size */
for(;j<40;j++)
g->scale_factors[j] = 0;
-#if defined(DEBUG)
- {
- dprintf(s->avctx, "gr=%d ch=%d scale_factors:\n",
- gr, ch);
- for(i=0;i<40;i++)
- dprintf(s->avctx, " %d", g->scale_factors[i]);
- dprintf(s->avctx, "\n");
- }
-#endif
}
exponents_from_scale_factors(s, g, exponents);
/* read Huffman coded residue */
huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);
-#if defined(DEBUG)
- sample_dump(0, g->sb_hybrid, 576);
-#endif
} /* ch */
if (s->nb_channels == 2)
- compute_stereo(s, &granules[0][gr], &granules[1][gr]);
+ compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]);
for(ch=0;ch<s->nb_channels;ch++) {
- g = &granules[ch][gr];
+ g = &s->granules[ch][gr];
reorder_block(s, g);
-#if defined(DEBUG)
- sample_dump(0, g->sb_hybrid, 576);
-#endif
s->compute_antialias(s, g);
-#if defined(DEBUG)
- sample_dump(1, g->sb_hybrid, 576);
-#endif
compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
-#if defined(DEBUG)
- sample_dump(2, &s->sb_samples[ch][18 * gr][0], 576);
-#endif
}
} /* gr */
if(get_bits_count(&s->gb)<0)
s->last_buf_size=0;
if(s->in_gb.buffer){
align_get_bits(&s->gb);
- i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;
+ i= get_bits_left(&s->gb)>>3;
if(i >= 0 && i <= BACKSTEP_SIZE){
memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);
s->last_buf_size=i;
}else
- av_log(NULL, AV_LOG_ERROR, "invalid old backstep %d\n", i);
+ av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);
s->gb= s->in_gb;
s->in_gb.buffer= NULL;
}
align_get_bits(&s->gb);
assert((get_bits_count(&s->gb) & 7) == 0);
- i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;
+ i= get_bits_left(&s->gb)>>3;
if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){
- av_log(NULL, AV_LOG_ERROR, "invalid new backstep %d\n", i);
+ if(i<0)
+ av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i);
i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);
}
assert(i <= buf_size - HEADER_SIZE && i>= 0);
break;
}
-#if defined(DEBUG)
- for(i=0;i<nb_frames;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- int j;
- dprintf(s->avctx, "%d-%d:", i, ch);
- for(j=0;j<SBLIMIT;j++)
- dprintf(s->avctx, " %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE);
- dprintf(s->avctx, "\n");
- }
- }
-#endif
+
/* apply the synthesis filter */
for(ch=0;ch<s->nb_channels;ch++) {
samples_ptr = samples + ch;
for(i=0;i<nb_frames;i++) {
ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]),
- window, &s->dither_state,
+ ff_mpa_synth_window, &s->dither_state,
samples_ptr, s->nb_channels,
s->sb_samples[ch][i]);
samples_ptr += 32 * s->nb_channels;
}
}
-#ifdef DEBUG
- s->frame_count++;
-#endif
+
return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
}
static int decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
- const uint8_t * buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
MPADecodeContext *s = avctx->priv_data;
uint32_t header;
int out_size;
OUT_INT *out_samples = data;
-retry:
if(buf_size < HEADER_SIZE)
return -1;
header = AV_RB32(buf);
if(ff_mpa_check_header(header) < 0){
- buf++;
-// buf_size--;
- av_log(avctx, AV_LOG_ERROR, "Header missing skipping one byte.\n");
- goto retry;
+ av_log(avctx, AV_LOG_ERROR, "Header missing\n");
+ return -1;
}
- if (ff_mpegaudio_decode_header(s, header) == 1) {
+ if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
/* free format: prepare to compute frame size */
s->frame_size = -1;
return -1;
avctx->bit_rate = s->bit_rate;
avctx->sub_id = s->layer;
+ if(*data_size < 1152*avctx->channels*sizeof(OUT_INT))
+ return -1;
+ *data_size = 0;
+
if(s->frame_size<=0 || s->frame_size > buf_size){
av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
return -1;
s->last_buf_size= 0;
}
-#ifdef CONFIG_MP3ADU_DECODER
+#if CONFIG_MP3ADU_DECODER
static int decode_frame_adu(AVCodecContext * avctx,
void *data, int *data_size,
- const uint8_t * buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
MPADecodeContext *s = avctx->priv_data;
uint32_t header;
int len, out_size;
return buf_size;
}
- ff_mpegaudio_decode_header(s, header);
+ ff_mpegaudio_decode_header((MPADecodeHeader *)s, header);
/* update codec info */
avctx->sample_rate = s->sample_rate;
avctx->channels = s->nb_channels;
}
#endif /* CONFIG_MP3ADU_DECODER */
-#ifdef CONFIG_MP3ON4_DECODER
+#if CONFIG_MP3ON4_DECODER
/**
* Context for MP3On4 decoder
*/
typedef struct MP3On4DecodeContext {
int frames; ///< number of mp3 frames per block (number of mp3 decoder instances)
- int chan_cfg; ///< channel config number
int syncword; ///< syncword patch
+ const uint8_t *coff; ///< channels offsets in output buffer
MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance
} MP3On4DecodeContext;
av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
return -1;
}
- s->chan_cfg = cfg.chan_config;
- s->frames = mp3Frames[s->chan_cfg];
- avctx->channels = ff_mpeg4audio_channels[s->chan_cfg];
+ s->frames = mp3Frames[cfg.chan_config];
+ s->coff = chan_offset[cfg.chan_config];
+ avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
if (cfg.sample_rate < 16000)
s->syncword = 0xffe00000;
}
-static int decode_close_mp3on4(AVCodecContext * avctx)
+static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
{
MP3On4DecodeContext *s = avctx->priv_data;
int i;
static int decode_frame_mp3on4(AVCodecContext * avctx,
void *data, int *data_size,
- const uint8_t * buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
MP3On4DecodeContext *s = avctx->priv_data;
MPADecodeContext *m;
- int len, out_size = 0;
+ int fsize, len = buf_size, out_size = 0;
uint32_t header;
OUT_INT *out_samples = data;
OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];
OUT_INT *outptr, *bp;
- int fsize;
- int fr, i, j, n;
- int off = avctx->channels;
- const uint8_t *coff = chan_offset[s->chan_cfg];
+ int fr, j, n;
- len = buf_size;
+ if(*data_size < MPA_FRAME_SIZE * MPA_MAX_CHANNELS * s->frames * sizeof(OUT_INT))
+ return -1;
*data_size = 0;
// Discard too short frames
// If only one decoder interleave is not needed
outptr = s->frames == 1 ? out_samples : decoded_buf;
+ avctx->bit_rate = 0;
+
for (fr = 0; fr < s->frames; fr++) {
fsize = AV_RB16(buf) >> 4;
fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);
header = (AV_RB32(buf) & 0x000fffff) | s->syncword; // patch header
- if (ff_mpa_check_header(header) < 0) { // Bad header, discard block
- *data_size = 0;
- return buf_size;
- }
+ if (ff_mpa_check_header(header) < 0) // Bad header, discard block
+ break;
- ff_mpegaudio_decode_header(m, header);
+ ff_mpegaudio_decode_header((MPADecodeHeader *)m, header);
out_size += mp_decode_frame(m, outptr, buf, fsize);
buf += fsize;
len -= fsize;
if(s->frames > 1) {
n = m->avctx->frame_size*m->nb_channels;
/* interleave output data */
- bp = out_samples + coff[fr];
+ bp = out_samples + s->coff[fr];
if(m->nb_channels == 1) {
for(j = 0; j < n; j++) {
*bp = decoded_buf[j];
- bp += off;
+ bp += avctx->channels;
}
} else {
for(j = 0; j < n; j++) {
bp[0] = decoded_buf[j++];
bp[1] = decoded_buf[j];
- bp += off;
+ bp += avctx->channels;
}
}
}
+ avctx->bit_rate += m->bit_rate;
}
/* update codec info */
avctx->sample_rate = s->mp3decctx[0]->sample_rate;
- avctx->bit_rate = 0;
- for (i = 0; i < s->frames; i++)
- avctx->bit_rate += s->mp3decctx[i]->bit_rate;
*data_size = out_size;
return buf_size;
}
#endif /* CONFIG_MP3ON4_DECODER */
-#ifdef CONFIG_MP2_DECODER
+#if CONFIG_MP1_DECODER
+AVCodec mp1_decoder =
+{
+ "mp1",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP1,
+ sizeof(MPADecodeContext),
+ decode_init,
+ NULL,
+ NULL,
+ decode_frame,
+ CODEC_CAP_PARSE_ONLY,
+ .flush= flush,
+ .long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
+};
+#endif
+#if CONFIG_MP2_DECODER
AVCodec mp2_decoder =
{
"mp2",
decode_frame,
CODEC_CAP_PARSE_ONLY,
.flush= flush,
+ .long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
};
#endif
-#ifdef CONFIG_MP3_DECODER
+#if CONFIG_MP3_DECODER
AVCodec mp3_decoder =
{
"mp3",
decode_frame,
CODEC_CAP_PARSE_ONLY,
.flush= flush,
+ .long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
};
#endif
-#ifdef CONFIG_MP3ADU_DECODER
+#if CONFIG_MP3ADU_DECODER
AVCodec mp3adu_decoder =
{
"mp3adu",
decode_frame_adu,
CODEC_CAP_PARSE_ONLY,
.flush= flush,
+ .long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
};
#endif
-#ifdef CONFIG_MP3ON4_DECODER
+#if CONFIG_MP3ON4_DECODER
AVCodec mp3on4_decoder =
{
"mp3on4",
decode_close_mp3on4,
decode_frame_mp3on4,
.flush= flush,
+ .long_name= NULL_IF_CONFIG_SMALL("MP3onMP4"),
};
#endif