00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #define UNCHECKED_BITSTREAM_READER 1
00028
00029 #include "libavutil/audioconvert.h"
00030 #include "avcodec.h"
00031 #include "get_bits.h"
00032 #include "mathops.h"
00033 #include "mpegaudiodsp.h"
00034
00035
00036
00037
00038
00039
00040 #include "mpegaudio.h"
00041 #include "mpegaudiodecheader.h"
00042
00043 #define BACKSTEP_SIZE 512
00044 #define EXTRABYTES 24
00045 #define LAST_BUF_SIZE 2 * BACKSTEP_SIZE + EXTRABYTES
00046
00047
00048 typedef struct GranuleDef {
00049 uint8_t scfsi;
00050 int part2_3_length;
00051 int big_values;
00052 int global_gain;
00053 int scalefac_compress;
00054 uint8_t block_type;
00055 uint8_t switch_point;
00056 int table_select[3];
00057 int subblock_gain[3];
00058 uint8_t scalefac_scale;
00059 uint8_t count1table_select;
00060 int region_size[3];
00061 int preflag;
00062 int short_start, long_end;
00063 uint8_t scale_factors[40];
00064 DECLARE_ALIGNED(16, INTFLOAT, sb_hybrid)[SBLIMIT * 18];
00065 } GranuleDef;
00066
00067 typedef struct MPADecodeContext {
00068 MPA_DECODE_HEADER
00069 uint8_t last_buf[LAST_BUF_SIZE];
00070 int last_buf_size;
00071
00072 uint32_t free_format_next_header;
00073 GetBitContext gb;
00074 GetBitContext in_gb;
00075 DECLARE_ALIGNED(32, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2];
00076 int synth_buf_offset[MPA_MAX_CHANNELS];
00077 DECLARE_ALIGNED(32, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
00078 INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18];
00079 GranuleDef granules[2][2];
00080 int adu_mode;
00081 int dither_state;
00082 int err_recognition;
00083 AVCodecContext* avctx;
00084 MPADSPContext mpadsp;
00085 AVFrame frame;
00086 } MPADecodeContext;
00087
00088 #if CONFIG_FLOAT
00089 # define SHR(a,b) ((a)*(1.0f/(1<<(b))))
00090 # define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
00091 # define FIXR(x) ((float)(x))
00092 # define FIXHR(x) ((float)(x))
00093 # define MULH3(x, y, s) ((s)*(y)*(x))
00094 # define MULLx(x, y, s) ((y)*(x))
00095 # define RENAME(a) a ## _float
00096 # define OUT_FMT AV_SAMPLE_FMT_FLT
00097 #else
00098 # define SHR(a,b) ((a)>>(b))
00099
00100 # define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
00101 # define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
00102 # define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
00103 # define MULH3(x, y, s) MULH((s)*(x), y)
00104 # define MULLx(x, y, s) MULL(x,y,s)
00105 # define RENAME(a) a ## _fixed
00106 # define OUT_FMT AV_SAMPLE_FMT_S16
00107 #endif
00108
00109
00110
00111 #define HEADER_SIZE 4
00112
00113 #include "mpegaudiodata.h"
00114 #include "mpegaudiodectab.h"
00115
00116
00117 static VLC huff_vlc[16];
00118 static VLC_TYPE huff_vlc_tables[
00119 0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 +
00120 142 + 204 + 190 + 170 + 542 + 460 + 662 + 414
00121 ][2];
00122 static const int huff_vlc_tables_sizes[16] = {
00123 0, 128, 128, 128, 130, 128, 154, 166,
00124 142, 204, 190, 170, 542, 460, 662, 414
00125 };
00126 static VLC huff_quad_vlc[2];
00127 static VLC_TYPE huff_quad_vlc_tables[128+16][2];
00128 static const int huff_quad_vlc_tables_sizes[2] = { 128, 16 };
00129
00130 static uint16_t band_index_long[9][23];
00131 #include "mpegaudio_tablegen.h"
00132
00133 static INTFLOAT is_table[2][16];
00134 static INTFLOAT is_table_lsf[2][2][16];
00135 static INTFLOAT csa_table[8][4];
00136
00137 static int16_t division_tab3[1<<6 ];
00138 static int16_t division_tab5[1<<8 ];
00139 static int16_t division_tab9[1<<11];
00140
00141 static int16_t * const division_tabs[4] = {
00142 division_tab3, division_tab5, NULL, division_tab9
00143 };
00144
00145
00146 static uint16_t scale_factor_modshift[64];
00147
00148 static int32_t scale_factor_mult[15][3];
00149
00150
00151 #define SCALE_GEN(v) \
00152 { FIXR_OLD(1.0 * (v)), FIXR_OLD(0.7937005259 * (v)), FIXR_OLD(0.6299605249 * (v)) }
00153
00154 static const int32_t scale_factor_mult2[3][3] = {
00155 SCALE_GEN(4.0 / 3.0),
00156 SCALE_GEN(4.0 / 5.0),
00157 SCALE_GEN(4.0 / 9.0),
00158 };
00159
00164 static void ff_region_offset2size(GranuleDef *g)
00165 {
00166 int i, k, j = 0;
00167 g->region_size[2] = 576 / 2;
00168 for (i = 0; i < 3; i++) {
00169 k = FFMIN(g->region_size[i], g->big_values);
00170 g->region_size[i] = k - j;
00171 j = k;
00172 }
00173 }
00174
00175 static void ff_init_short_region(MPADecodeContext *s, GranuleDef *g)
00176 {
00177 if (g->block_type == 2)
00178 g->region_size[0] = (36 / 2);
00179 else {
00180 if (s->sample_rate_index <= 2)
00181 g->region_size[0] = (36 / 2);
00182 else if (s->sample_rate_index != 8)
00183 g->region_size[0] = (54 / 2);
00184 else
00185 g->region_size[0] = (108 / 2);
00186 }
00187 g->region_size[1] = (576 / 2);
00188 }
00189
00190 static void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2)
00191 {
00192 int l;
00193 g->region_size[0] = band_index_long[s->sample_rate_index][ra1 + 1] >> 1;
00194
00195 l = FFMIN(ra1 + ra2 + 2, 22);
00196 g->region_size[1] = band_index_long[s->sample_rate_index][ l] >> 1;
00197 }
00198
00199 static void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g)
00200 {
00201 if (g->block_type == 2) {
00202 if (g->switch_point) {
00203
00204
00205
00206 if (s->sample_rate_index <= 2)
00207 g->long_end = 8;
00208 else if (s->sample_rate_index != 8)
00209 g->long_end = 6;
00210 else
00211 g->long_end = 4;
00212
00213 g->short_start = 3;
00214 } else {
00215 g->long_end = 0;
00216 g->short_start = 0;
00217 }
00218 } else {
00219 g->short_start = 13;
00220 g->long_end = 22;
00221 }
00222 }
00223
00224
00225
00226 static inline int l1_unscale(int n, int mant, int scale_factor)
00227 {
00228 int shift, mod;
00229 int64_t val;
00230
00231 shift = scale_factor_modshift[scale_factor];
00232 mod = shift & 3;
00233 shift >>= 2;
00234 val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]);
00235 shift += n;
00236
00237 return (int)((val + (1LL << (shift - 1))) >> shift);
00238 }
00239
00240 static inline int l2_unscale_group(int steps, int mant, int scale_factor)
00241 {
00242 int shift, mod, val;
00243
00244 shift = scale_factor_modshift[scale_factor];
00245 mod = shift & 3;
00246 shift >>= 2;
00247
00248 val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];
00249
00250 if (shift > 0)
00251 val = (val + (1 << (shift - 1))) >> shift;
00252 return val;
00253 }
00254
00255
00256 static inline int l3_unscale(int value, int exponent)
00257 {
00258 unsigned int m;
00259 int e;
00260
00261 e = table_4_3_exp [4 * value + (exponent & 3)];
00262 m = table_4_3_value[4 * value + (exponent & 3)];
00263 e -= exponent >> 2;
00264 assert(e >= 1);
00265 if (e > 31)
00266 return 0;
00267 m = (m + (1 << (e - 1))) >> e;
00268
00269 return m;
00270 }
00271
00272 static av_cold void decode_init_static(void)
00273 {
00274 int i, j, k;
00275 int offset;
00276
00277
00278 for (i = 0; i < 64; i++) {
00279 int shift, mod;
00280
00281 shift = i / 3;
00282 mod = i % 3;
00283 scale_factor_modshift[i] = mod | (shift << 2);
00284 }
00285
00286
00287 for (i = 0; i < 15; i++) {
00288 int n, norm;
00289 n = i + 2;
00290 norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
00291 scale_factor_mult[i][0] = MULLx(norm, FIXR(1.0 * 2.0), FRAC_BITS);
00292 scale_factor_mult[i][1] = MULLx(norm, FIXR(0.7937005259 * 2.0), FRAC_BITS);
00293 scale_factor_mult[i][2] = MULLx(norm, FIXR(0.6299605249 * 2.0), FRAC_BITS);
00294 av_dlog(NULL, "%d: norm=%x s=%x %x %x\n", i, norm,
00295 scale_factor_mult[i][0],
00296 scale_factor_mult[i][1],
00297 scale_factor_mult[i][2]);
00298 }
00299
00300 RENAME(ff_mpa_synth_init)(RENAME(ff_mpa_synth_window));
00301
00302
00303 offset = 0;
00304 for (i = 1; i < 16; i++) {
00305 const HuffTable *h = &mpa_huff_tables[i];
00306 int xsize, x, y;
00307 uint8_t tmp_bits [512];
00308 uint16_t tmp_codes[512];
00309
00310 memset(tmp_bits , 0, sizeof(tmp_bits ));
00311 memset(tmp_codes, 0, sizeof(tmp_codes));
00312
00313 xsize = h->xsize;
00314
00315 j = 0;
00316 for (x = 0; x < xsize; x++) {
00317 for (y = 0; y < xsize; y++) {
00318 tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->bits [j ];
00319 tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++];
00320 }
00321 }
00322
00323
00324 huff_vlc[i].table = huff_vlc_tables+offset;
00325 huff_vlc[i].table_allocated = huff_vlc_tables_sizes[i];
00326 init_vlc(&huff_vlc[i], 7, 512,
00327 tmp_bits, 1, 1, tmp_codes, 2, 2,
00328 INIT_VLC_USE_NEW_STATIC);
00329 offset += huff_vlc_tables_sizes[i];
00330 }
00331 assert(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
00332
00333 offset = 0;
00334 for (i = 0; i < 2; i++) {
00335 huff_quad_vlc[i].table = huff_quad_vlc_tables+offset;
00336 huff_quad_vlc[i].table_allocated = huff_quad_vlc_tables_sizes[i];
00337 init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
00338 mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1,
00339 INIT_VLC_USE_NEW_STATIC);
00340 offset += huff_quad_vlc_tables_sizes[i];
00341 }
00342 assert(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables));
00343
00344 for (i = 0; i < 9; i++) {
00345 k = 0;
00346 for (j = 0; j < 22; j++) {
00347 band_index_long[i][j] = k;
00348 k += band_size_long[i][j];
00349 }
00350 band_index_long[i][22] = k;
00351 }
00352
00353
00354
00355 mpegaudio_tableinit();
00356
00357 for (i = 0; i < 4; i++) {
00358 if (ff_mpa_quant_bits[i] < 0) {
00359 for (j = 0; j < (1 << (-ff_mpa_quant_bits[i]+1)); j++) {
00360 int val1, val2, val3, steps;
00361 int val = j;
00362 steps = ff_mpa_quant_steps[i];
00363 val1 = val % steps;
00364 val /= steps;
00365 val2 = val % steps;
00366 val3 = val / steps;
00367 division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
00368 }
00369 }
00370 }
00371
00372
00373 for (i = 0; i < 7; i++) {
00374 float f;
00375 INTFLOAT v;
00376 if (i != 6) {
00377 f = tan((double)i * M_PI / 12.0);
00378 v = FIXR(f / (1.0 + f));
00379 } else {
00380 v = FIXR(1.0);
00381 }
00382 is_table[0][ i] = v;
00383 is_table[1][6 - i] = v;
00384 }
00385
00386 for (i = 7; i < 16; i++)
00387 is_table[0][i] = is_table[1][i] = 0.0;
00388
00389 for (i = 0; i < 16; i++) {
00390 double f;
00391 int e, k;
00392
00393 for (j = 0; j < 2; j++) {
00394 e = -(j + 1) * ((i + 1) >> 1);
00395 f = pow(2.0, e / 4.0);
00396 k = i & 1;
00397 is_table_lsf[j][k ^ 1][i] = FIXR(f);
00398 is_table_lsf[j][k ][i] = FIXR(1.0);
00399 av_dlog(NULL, "is_table_lsf %d %d: %f %f\n",
00400 i, j, (float) is_table_lsf[j][0][i],
00401 (float) is_table_lsf[j][1][i]);
00402 }
00403 }
00404
00405 for (i = 0; i < 8; i++) {
00406 float ci, cs, ca;
00407 ci = ci_table[i];
00408 cs = 1.0 / sqrt(1.0 + ci * ci);
00409 ca = cs * ci;
00410 #if !CONFIG_FLOAT
00411 csa_table[i][0] = FIXHR(cs/4);
00412 csa_table[i][1] = FIXHR(ca/4);
00413 csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4);
00414 csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4);
00415 #else
00416 csa_table[i][0] = cs;
00417 csa_table[i][1] = ca;
00418 csa_table[i][2] = ca + cs;
00419 csa_table[i][3] = ca - cs;
00420 #endif
00421 }
00422 }
00423
00424 static av_cold int decode_init(AVCodecContext * avctx)
00425 {
00426 static int initialized_tables = 0;
00427 MPADecodeContext *s = avctx->priv_data;
00428
00429 if (!initialized_tables) {
00430 decode_init_static();
00431 initialized_tables = 1;
00432 }
00433
00434 s->avctx = avctx;
00435
00436 ff_mpadsp_init(&s->mpadsp);
00437
00438 avctx->sample_fmt= OUT_FMT;
00439 s->err_recognition = avctx->err_recognition;
00440
00441 if (avctx->codec_id == CODEC_ID_MP3ADU)
00442 s->adu_mode = 1;
00443
00444 avcodec_get_frame_defaults(&s->frame);
00445 avctx->coded_frame = &s->frame;
00446
00447 return 0;
00448 }
00449
00450 #define C3 FIXHR(0.86602540378443864676/2)
00451 #define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36)
00452 #define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36)
00453 #define C6 FIXHR(1.93185165257813657349/4) //0.5 / cos(pi*(15)/36)
00454
00455
00456
00457 static void imdct12(INTFLOAT *out, INTFLOAT *in)
00458 {
00459 INTFLOAT in0, in1, in2, in3, in4, in5, t1, t2;
00460
00461 in0 = in[0*3];
00462 in1 = in[1*3] + in[0*3];
00463 in2 = in[2*3] + in[1*3];
00464 in3 = in[3*3] + in[2*3];
00465 in4 = in[4*3] + in[3*3];
00466 in5 = in[5*3] + in[4*3];
00467 in5 += in3;
00468 in3 += in1;
00469
00470 in2 = MULH3(in2, C3, 2);
00471 in3 = MULH3(in3, C3, 4);
00472
00473 t1 = in0 - in4;
00474 t2 = MULH3(in1 - in5, C4, 2);
00475
00476 out[ 7] =
00477 out[10] = t1 + t2;
00478 out[ 1] =
00479 out[ 4] = t1 - t2;
00480
00481 in0 += SHR(in4, 1);
00482 in4 = in0 + in2;
00483 in5 += 2*in1;
00484 in1 = MULH3(in5 + in3, C5, 1);
00485 out[ 8] =
00486 out[ 9] = in4 + in1;
00487 out[ 2] =
00488 out[ 3] = in4 - in1;
00489
00490 in0 -= in2;
00491 in5 = MULH3(in5 - in3, C6, 2);
00492 out[ 0] =
00493 out[ 5] = in0 - in5;
00494 out[ 6] =
00495 out[11] = in0 + in5;
00496 }
00497
00498
00499 static int mp_decode_layer1(MPADecodeContext *s)
00500 {
00501 int bound, i, v, n, ch, j, mant;
00502 uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT];
00503 uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
00504
00505 if (s->mode == MPA_JSTEREO)
00506 bound = (s->mode_ext + 1) * 4;
00507 else
00508 bound = SBLIMIT;
00509
00510
00511 for (i = 0; i < bound; i++) {
00512 for (ch = 0; ch < s->nb_channels; ch++) {
00513 allocation[ch][i] = get_bits(&s->gb, 4);
00514 }
00515 }
00516 for (i = bound; i < SBLIMIT; i++)
00517 allocation[0][i] = get_bits(&s->gb, 4);
00518
00519
00520 for (i = 0; i < bound; i++) {
00521 for (ch = 0; ch < s->nb_channels; ch++) {
00522 if (allocation[ch][i])
00523 scale_factors[ch][i] = get_bits(&s->gb, 6);
00524 }
00525 }
00526 for (i = bound; i < SBLIMIT; i++) {
00527 if (allocation[0][i]) {
00528 scale_factors[0][i] = get_bits(&s->gb, 6);
00529 scale_factors[1][i] = get_bits(&s->gb, 6);
00530 }
00531 }
00532
00533
00534 for (j = 0; j < 12; j++) {
00535 for (i = 0; i < bound; i++) {
00536 for (ch = 0; ch < s->nb_channels; ch++) {
00537 n = allocation[ch][i];
00538 if (n) {
00539 mant = get_bits(&s->gb, n + 1);
00540 v = l1_unscale(n, mant, scale_factors[ch][i]);
00541 } else {
00542 v = 0;
00543 }
00544 s->sb_samples[ch][j][i] = v;
00545 }
00546 }
00547 for (i = bound; i < SBLIMIT; i++) {
00548 n = allocation[0][i];
00549 if (n) {
00550 mant = get_bits(&s->gb, n + 1);
00551 v = l1_unscale(n, mant, scale_factors[0][i]);
00552 s->sb_samples[0][j][i] = v;
00553 v = l1_unscale(n, mant, scale_factors[1][i]);
00554 s->sb_samples[1][j][i] = v;
00555 } else {
00556 s->sb_samples[0][j][i] = 0;
00557 s->sb_samples[1][j][i] = 0;
00558 }
00559 }
00560 }
00561 return 12;
00562 }
00563
00564 static int mp_decode_layer2(MPADecodeContext *s)
00565 {
00566 int sblimit;
00567 const unsigned char *alloc_table;
00568 int table, bit_alloc_bits, i, j, ch, bound, v;
00569 unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
00570 unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
00571 unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;
00572 int scale, qindex, bits, steps, k, l, m, b;
00573
00574
00575 table = ff_mpa_l2_select_table(s->bit_rate / 1000, s->nb_channels,
00576 s->sample_rate, s->lsf);
00577 sblimit = ff_mpa_sblimit_table[table];
00578 alloc_table = ff_mpa_alloc_tables[table];
00579
00580 if (s->mode == MPA_JSTEREO)
00581 bound = (s->mode_ext + 1) * 4;
00582 else
00583 bound = sblimit;
00584
00585 av_dlog(s->avctx, "bound=%d sblimit=%d\n", bound, sblimit);
00586
00587
00588 if (bound > sblimit)
00589 bound = sblimit;
00590
00591
00592 j = 0;
00593 for (i = 0; i < bound; i++) {
00594 bit_alloc_bits = alloc_table[j];
00595 for (ch = 0; ch < s->nb_channels; ch++)
00596 bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);
00597 j += 1 << bit_alloc_bits;
00598 }
00599 for (i = bound; i < sblimit; i++) {
00600 bit_alloc_bits = alloc_table[j];
00601 v = get_bits(&s->gb, bit_alloc_bits);
00602 bit_alloc[0][i] = v;
00603 bit_alloc[1][i] = v;
00604 j += 1 << bit_alloc_bits;
00605 }
00606
00607
00608 for (i = 0; i < sblimit; i++) {
00609 for (ch = 0; ch < s->nb_channels; ch++) {
00610 if (bit_alloc[ch][i])
00611 scale_code[ch][i] = get_bits(&s->gb, 2);
00612 }
00613 }
00614
00615
00616 for (i = 0; i < sblimit; i++) {
00617 for (ch = 0; ch < s->nb_channels; ch++) {
00618 if (bit_alloc[ch][i]) {
00619 sf = scale_factors[ch][i];
00620 switch (scale_code[ch][i]) {
00621 default:
00622 case 0:
00623 sf[0] = get_bits(&s->gb, 6);
00624 sf[1] = get_bits(&s->gb, 6);
00625 sf[2] = get_bits(&s->gb, 6);
00626 break;
00627 case 2:
00628 sf[0] = get_bits(&s->gb, 6);
00629 sf[1] = sf[0];
00630 sf[2] = sf[0];
00631 break;
00632 case 1:
00633 sf[0] = get_bits(&s->gb, 6);
00634 sf[2] = get_bits(&s->gb, 6);
00635 sf[1] = sf[0];
00636 break;
00637 case 3:
00638 sf[0] = get_bits(&s->gb, 6);
00639 sf[2] = get_bits(&s->gb, 6);
00640 sf[1] = sf[2];
00641 break;
00642 }
00643 }
00644 }
00645 }
00646
00647
00648 for (k = 0; k < 3; k++) {
00649 for (l = 0; l < 12; l += 3) {
00650 j = 0;
00651 for (i = 0; i < bound; i++) {
00652 bit_alloc_bits = alloc_table[j];
00653 for (ch = 0; ch < s->nb_channels; ch++) {
00654 b = bit_alloc[ch][i];
00655 if (b) {
00656 scale = scale_factors[ch][i][k];
00657 qindex = alloc_table[j+b];
00658 bits = ff_mpa_quant_bits[qindex];
00659 if (bits < 0) {
00660 int v2;
00661
00662 v = get_bits(&s->gb, -bits);
00663 v2 = division_tabs[qindex][v];
00664 steps = ff_mpa_quant_steps[qindex];
00665
00666 s->sb_samples[ch][k * 12 + l + 0][i] =
00667 l2_unscale_group(steps, v2 & 15, scale);
00668 s->sb_samples[ch][k * 12 + l + 1][i] =
00669 l2_unscale_group(steps, (v2 >> 4) & 15, scale);
00670 s->sb_samples[ch][k * 12 + l + 2][i] =
00671 l2_unscale_group(steps, v2 >> 8 , scale);
00672 } else {
00673 for (m = 0; m < 3; m++) {
00674 v = get_bits(&s->gb, bits);
00675 v = l1_unscale(bits - 1, v, scale);
00676 s->sb_samples[ch][k * 12 + l + m][i] = v;
00677 }
00678 }
00679 } else {
00680 s->sb_samples[ch][k * 12 + l + 0][i] = 0;
00681 s->sb_samples[ch][k * 12 + l + 1][i] = 0;
00682 s->sb_samples[ch][k * 12 + l + 2][i] = 0;
00683 }
00684 }
00685
00686 j += 1 << bit_alloc_bits;
00687 }
00688
00689 for (i = bound; i < sblimit; i++) {
00690 bit_alloc_bits = alloc_table[j];
00691 b = bit_alloc[0][i];
00692 if (b) {
00693 int mant, scale0, scale1;
00694 scale0 = scale_factors[0][i][k];
00695 scale1 = scale_factors[1][i][k];
00696 qindex = alloc_table[j+b];
00697 bits = ff_mpa_quant_bits[qindex];
00698 if (bits < 0) {
00699
00700 v = get_bits(&s->gb, -bits);
00701 steps = ff_mpa_quant_steps[qindex];
00702 mant = v % steps;
00703 v = v / steps;
00704 s->sb_samples[0][k * 12 + l + 0][i] =
00705 l2_unscale_group(steps, mant, scale0);
00706 s->sb_samples[1][k * 12 + l + 0][i] =
00707 l2_unscale_group(steps, mant, scale1);
00708 mant = v % steps;
00709 v = v / steps;
00710 s->sb_samples[0][k * 12 + l + 1][i] =
00711 l2_unscale_group(steps, mant, scale0);
00712 s->sb_samples[1][k * 12 + l + 1][i] =
00713 l2_unscale_group(steps, mant, scale1);
00714 s->sb_samples[0][k * 12 + l + 2][i] =
00715 l2_unscale_group(steps, v, scale0);
00716 s->sb_samples[1][k * 12 + l + 2][i] =
00717 l2_unscale_group(steps, v, scale1);
00718 } else {
00719 for (m = 0; m < 3; m++) {
00720 mant = get_bits(&s->gb, bits);
00721 s->sb_samples[0][k * 12 + l + m][i] =
00722 l1_unscale(bits - 1, mant, scale0);
00723 s->sb_samples[1][k * 12 + l + m][i] =
00724 l1_unscale(bits - 1, mant, scale1);
00725 }
00726 }
00727 } else {
00728 s->sb_samples[0][k * 12 + l + 0][i] = 0;
00729 s->sb_samples[0][k * 12 + l + 1][i] = 0;
00730 s->sb_samples[0][k * 12 + l + 2][i] = 0;
00731 s->sb_samples[1][k * 12 + l + 0][i] = 0;
00732 s->sb_samples[1][k * 12 + l + 1][i] = 0;
00733 s->sb_samples[1][k * 12 + l + 2][i] = 0;
00734 }
00735
00736 j += 1 << bit_alloc_bits;
00737 }
00738
00739 for (i = sblimit; i < SBLIMIT; i++) {
00740 for (ch = 0; ch < s->nb_channels; ch++) {
00741 s->sb_samples[ch][k * 12 + l + 0][i] = 0;
00742 s->sb_samples[ch][k * 12 + l + 1][i] = 0;
00743 s->sb_samples[ch][k * 12 + l + 2][i] = 0;
00744 }
00745 }
00746 }
00747 }
00748 return 3 * 12;
00749 }
00750
00751 #define SPLIT(dst,sf,n) \
00752 if (n == 3) { \
00753 int m = (sf * 171) >> 9; \
00754 dst = sf - 3 * m; \
00755 sf = m; \
00756 } else if (n == 4) { \
00757 dst = sf & 3; \
00758 sf >>= 2; \
00759 } else if (n == 5) { \
00760 int m = (sf * 205) >> 10; \
00761 dst = sf - 5 * m; \
00762 sf = m; \
00763 } else if (n == 6) { \
00764 int m = (sf * 171) >> 10; \
00765 dst = sf - 6 * m; \
00766 sf = m; \
00767 } else { \
00768 dst = 0; \
00769 }
00770
00771 static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2,
00772 int n3)
00773 {
00774 SPLIT(slen[3], sf, n3)
00775 SPLIT(slen[2], sf, n2)
00776 SPLIT(slen[1], sf, n1)
00777 slen[0] = sf;
00778 }
00779
00780 static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g,
00781 int16_t *exponents)
00782 {
00783 const uint8_t *bstab, *pretab;
00784 int len, i, j, k, l, v0, shift, gain, gains[3];
00785 int16_t *exp_ptr;
00786
00787 exp_ptr = exponents;
00788 gain = g->global_gain - 210;
00789 shift = g->scalefac_scale + 1;
00790
00791 bstab = band_size_long[s->sample_rate_index];
00792 pretab = mpa_pretab[g->preflag];
00793 for (i = 0; i < g->long_end; i++) {
00794 v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift) + 400;
00795 len = bstab[i];
00796 for (j = len; j > 0; j--)
00797 *exp_ptr++ = v0;
00798 }
00799
00800 if (g->short_start < 13) {
00801 bstab = band_size_short[s->sample_rate_index];
00802 gains[0] = gain - (g->subblock_gain[0] << 3);
00803 gains[1] = gain - (g->subblock_gain[1] << 3);
00804 gains[2] = gain - (g->subblock_gain[2] << 3);
00805 k = g->long_end;
00806 for (i = g->short_start; i < 13; i++) {
00807 len = bstab[i];
00808 for (l = 0; l < 3; l++) {
00809 v0 = gains[l] - (g->scale_factors[k++] << shift) + 400;
00810 for (j = len; j > 0; j--)
00811 *exp_ptr++ = v0;
00812 }
00813 }
00814 }
00815 }
00816
00817
00818 static inline int get_bitsz(GetBitContext *s, int n)
00819 {
00820 return n ? get_bits(s, n) : 0;
00821 }
00822
00823
00824 static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos,
00825 int *end_pos2)
00826 {
00827 if (s->in_gb.buffer && *pos >= s->gb.size_in_bits) {
00828 s->gb = s->in_gb;
00829 s->in_gb.buffer = NULL;
00830 assert((get_bits_count(&s->gb) & 7) == 0);
00831 skip_bits_long(&s->gb, *pos - *end_pos);
00832 *end_pos2 =
00833 *end_pos = *end_pos2 + get_bits_count(&s->gb) - *pos;
00834 *pos = get_bits_count(&s->gb);
00835 }
00836 }
00837
00838
00839
00840
00841
00842
00843
00844 #if CONFIG_FLOAT
00845 #define READ_FLIP_SIGN(dst,src) \
00846 v = AV_RN32A(src) ^ (get_bits1(&s->gb) << 31); \
00847 AV_WN32A(dst, v);
00848 #else
00849 #define READ_FLIP_SIGN(dst,src) \
00850 v = -get_bits1(&s->gb); \
00851 *(dst) = (*(src) ^ v) - v;
00852 #endif
00853
00854 static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
00855 int16_t *exponents, int end_pos2)
00856 {
00857 int s_index;
00858 int i;
00859 int last_pos, bits_left;
00860 VLC *vlc;
00861 int end_pos = FFMIN(end_pos2, s->gb.size_in_bits);
00862
00863
00864 s_index = 0;
00865 for (i = 0; i < 3; i++) {
00866 int j, k, l, linbits;
00867 j = g->region_size[i];
00868 if (j == 0)
00869 continue;
00870
00871 k = g->table_select[i];
00872 l = mpa_huff_data[k][0];
00873 linbits = mpa_huff_data[k][1];
00874 vlc = &huff_vlc[l];
00875
00876 if (!l) {
00877 memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * 2 * j);
00878 s_index += 2 * j;
00879 continue;
00880 }
00881
00882
00883 for (; j > 0; j--) {
00884 int exponent, x, y;
00885 int v;
00886 int pos = get_bits_count(&s->gb);
00887
00888 if (pos >= end_pos){
00889
00890 switch_buffer(s, &pos, &end_pos, &end_pos2);
00891
00892 if (pos >= end_pos)
00893 break;
00894 }
00895 y = get_vlc2(&s->gb, vlc->table, 7, 3);
00896
00897 if (!y) {
00898 g->sb_hybrid[s_index ] =
00899 g->sb_hybrid[s_index+1] = 0;
00900 s_index += 2;
00901 continue;
00902 }
00903
00904 exponent= exponents[s_index];
00905
00906 av_dlog(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n",
00907 i, g->region_size[i] - j, x, y, exponent);
00908 if (y & 16) {
00909 x = y >> 5;
00910 y = y & 0x0f;
00911 if (x < 15) {
00912 READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(expval_table)[exponent] + x)
00913 } else {
00914 x += get_bitsz(&s->gb, linbits);
00915 v = l3_unscale(x, exponent);
00916 if (get_bits1(&s->gb))
00917 v = -v;
00918 g->sb_hybrid[s_index] = v;
00919 }
00920 if (y < 15) {
00921 READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(expval_table)[exponent] + y)
00922 } else {
00923 y += get_bitsz(&s->gb, linbits);
00924 v = l3_unscale(y, exponent);
00925 if (get_bits1(&s->gb))
00926 v = -v;
00927 g->sb_hybrid[s_index+1] = v;
00928 }
00929 } else {
00930 x = y >> 5;
00931 y = y & 0x0f;
00932 x += y;
00933 if (x < 15) {
00934 READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(expval_table)[exponent] + x)
00935 } else {
00936 x += get_bitsz(&s->gb, linbits);
00937 v = l3_unscale(x, exponent);
00938 if (get_bits1(&s->gb))
00939 v = -v;
00940 g->sb_hybrid[s_index+!!y] = v;
00941 }
00942 g->sb_hybrid[s_index + !y] = 0;
00943 }
00944 s_index += 2;
00945 }
00946 }
00947
00948
00949 vlc = &huff_quad_vlc[g->count1table_select];
00950 last_pos = 0;
00951 while (s_index <= 572) {
00952 int pos, code;
00953 pos = get_bits_count(&s->gb);
00954 if (pos >= end_pos) {
00955 if (pos > end_pos2 && last_pos) {
00956
00957
00958 s_index -= 4;
00959 skip_bits_long(&s->gb, last_pos - pos);
00960 av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
00961 if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
00962 s_index=0;
00963 break;
00964 }
00965
00966 switch_buffer(s, &pos, &end_pos, &end_pos2);
00967
00968 if (pos >= end_pos)
00969 break;
00970 }
00971 last_pos = pos;
00972
00973 code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1);
00974 av_dlog(s->avctx, "t=%d code=%d\n", g->count1table_select, code);
00975 g->sb_hybrid[s_index+0] =
00976 g->sb_hybrid[s_index+1] =
00977 g->sb_hybrid[s_index+2] =
00978 g->sb_hybrid[s_index+3] = 0;
00979 while (code) {
00980 static const int idxtab[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 };
00981 int v;
00982 int pos = s_index + idxtab[code];
00983 code ^= 8 >> idxtab[code];
00984 READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(exp_table)+exponents[pos])
00985 }
00986 s_index += 4;
00987 }
00988
00989 bits_left = end_pos2 - get_bits_count(&s->gb);
00990
00991 if (bits_left < 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_COMPLIANT))) {
00992 av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
00993 s_index=0;
00994 } else if (bits_left > 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) {
00995 av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
00996 s_index = 0;
00997 }
00998 memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * (576 - s_index));
00999 skip_bits_long(&s->gb, bits_left);
01000
01001 i = get_bits_count(&s->gb);
01002 switch_buffer(s, &i, &end_pos, &end_pos2);
01003
01004 return 0;
01005 }
01006
01007
01008
01009
01010 static void reorder_block(MPADecodeContext *s, GranuleDef *g)
01011 {
01012 int i, j, len;
01013 INTFLOAT *ptr, *dst, *ptr1;
01014 INTFLOAT tmp[576];
01015
01016 if (g->block_type != 2)
01017 return;
01018
01019 if (g->switch_point) {
01020 if (s->sample_rate_index != 8)
01021 ptr = g->sb_hybrid + 36;
01022 else
01023 ptr = g->sb_hybrid + 48;
01024 } else {
01025 ptr = g->sb_hybrid;
01026 }
01027
01028 for (i = g->short_start; i < 13; i++) {
01029 len = band_size_short[s->sample_rate_index][i];
01030 ptr1 = ptr;
01031 dst = tmp;
01032 for (j = len; j > 0; j--) {
01033 *dst++ = ptr[0*len];
01034 *dst++ = ptr[1*len];
01035 *dst++ = ptr[2*len];
01036 ptr++;
01037 }
01038 ptr += 2 * len;
01039 memcpy(ptr1, tmp, len * 3 * sizeof(*ptr1));
01040 }
01041 }
01042
01043 #define ISQRT2 FIXR(0.70710678118654752440)
01044
01045 static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
01046 {
01047 int i, j, k, l;
01048 int sf_max, sf, len, non_zero_found;
01049 INTFLOAT (*is_tab)[16], *tab0, *tab1, tmp0, tmp1, v1, v2;
01050 int non_zero_found_short[3];
01051
01052
01053 if (s->mode_ext & MODE_EXT_I_STEREO) {
01054 if (!s->lsf) {
01055 is_tab = is_table;
01056 sf_max = 7;
01057 } else {
01058 is_tab = is_table_lsf[g1->scalefac_compress & 1];
01059 sf_max = 16;
01060 }
01061
01062 tab0 = g0->sb_hybrid + 576;
01063 tab1 = g1->sb_hybrid + 576;
01064
01065 non_zero_found_short[0] = 0;
01066 non_zero_found_short[1] = 0;
01067 non_zero_found_short[2] = 0;
01068 k = (13 - g1->short_start) * 3 + g1->long_end - 3;
01069 for (i = 12; i >= g1->short_start; i--) {
01070
01071 if (i != 11)
01072 k -= 3;
01073 len = band_size_short[s->sample_rate_index][i];
01074 for (l = 2; l >= 0; l--) {
01075 tab0 -= len;
01076 tab1 -= len;
01077 if (!non_zero_found_short[l]) {
01078
01079 for (j = 0; j < len; j++) {
01080 if (tab1[j] != 0) {
01081 non_zero_found_short[l] = 1;
01082 goto found1;
01083 }
01084 }
01085 sf = g1->scale_factors[k + l];
01086 if (sf >= sf_max)
01087 goto found1;
01088
01089 v1 = is_tab[0][sf];
01090 v2 = is_tab[1][sf];
01091 for (j = 0; j < len; j++) {
01092 tmp0 = tab0[j];
01093 tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
01094 tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
01095 }
01096 } else {
01097 found1:
01098 if (s->mode_ext & MODE_EXT_MS_STEREO) {
01099
01100
01101 for (j = 0; j < len; j++) {
01102 tmp0 = tab0[j];
01103 tmp1 = tab1[j];
01104 tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
01105 tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
01106 }
01107 }
01108 }
01109 }
01110 }
01111
01112 non_zero_found = non_zero_found_short[0] |
01113 non_zero_found_short[1] |
01114 non_zero_found_short[2];
01115
01116 for (i = g1->long_end - 1;i >= 0;i--) {
01117 len = band_size_long[s->sample_rate_index][i];
01118 tab0 -= len;
01119 tab1 -= len;
01120
01121 if (!non_zero_found) {
01122 for (j = 0; j < len; j++) {
01123 if (tab1[j] != 0) {
01124 non_zero_found = 1;
01125 goto found2;
01126 }
01127 }
01128
01129 k = (i == 21) ? 20 : i;
01130 sf = g1->scale_factors[k];
01131 if (sf >= sf_max)
01132 goto found2;
01133 v1 = is_tab[0][sf];
01134 v2 = is_tab[1][sf];
01135 for (j = 0; j < len; j++) {
01136 tmp0 = tab0[j];
01137 tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
01138 tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
01139 }
01140 } else {
01141 found2:
01142 if (s->mode_ext & MODE_EXT_MS_STEREO) {
01143
01144
01145 for (j = 0; j < len; j++) {
01146 tmp0 = tab0[j];
01147 tmp1 = tab1[j];
01148 tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
01149 tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
01150 }
01151 }
01152 }
01153 }
01154 } else if (s->mode_ext & MODE_EXT_MS_STEREO) {
01155
01156
01157
01158 tab0 = g0->sb_hybrid;
01159 tab1 = g1->sb_hybrid;
01160 for (i = 0; i < 576; i++) {
01161 tmp0 = tab0[i];
01162 tmp1 = tab1[i];
01163 tab0[i] = tmp0 + tmp1;
01164 tab1[i] = tmp0 - tmp1;
01165 }
01166 }
01167 }
01168
01169 #if CONFIG_FLOAT
01170 #define AA(j) do { \
01171 float tmp0 = ptr[-1-j]; \
01172 float tmp1 = ptr[ j]; \
01173 ptr[-1-j] = tmp0 * csa_table[j][0] - tmp1 * csa_table[j][1]; \
01174 ptr[ j] = tmp0 * csa_table[j][1] + tmp1 * csa_table[j][0]; \
01175 } while (0)
01176 #else
01177 #define AA(j) do { \
01178 int tmp0 = ptr[-1-j]; \
01179 int tmp1 = ptr[ j]; \
01180 int tmp2 = MULH(tmp0 + tmp1, csa_table[j][0]); \
01181 ptr[-1-j] = 4 * (tmp2 - MULH(tmp1, csa_table[j][2])); \
01182 ptr[ j] = 4 * (tmp2 + MULH(tmp0, csa_table[j][3])); \
01183 } while (0)
01184 #endif
01185
01186 static void compute_antialias(MPADecodeContext *s, GranuleDef *g)
01187 {
01188 INTFLOAT *ptr;
01189 int n, i;
01190
01191
01192 if (g->block_type == 2) {
01193 if (!g->switch_point)
01194 return;
01195
01196 n = 1;
01197 } else {
01198 n = SBLIMIT - 1;
01199 }
01200
01201 ptr = g->sb_hybrid + 18;
01202 for (i = n; i > 0; i--) {
01203 AA(0);
01204 AA(1);
01205 AA(2);
01206 AA(3);
01207 AA(4);
01208 AA(5);
01209 AA(6);
01210 AA(7);
01211
01212 ptr += 18;
01213 }
01214 }
01215
01216 static void compute_imdct(MPADecodeContext *s, GranuleDef *g,
01217 INTFLOAT *sb_samples, INTFLOAT *mdct_buf)
01218 {
01219 INTFLOAT *win, *out_ptr, *ptr, *buf, *ptr1;
01220 INTFLOAT out2[12];
01221 int i, j, mdct_long_end, sblimit;
01222
01223
01224 ptr = g->sb_hybrid + 576;
01225 ptr1 = g->sb_hybrid + 2 * 18;
01226 while (ptr >= ptr1) {
01227 int32_t *p;
01228 ptr -= 6;
01229 p = (int32_t*)ptr;
01230 if (p[0] | p[1] | p[2] | p[3] | p[4] | p[5])
01231 break;
01232 }
01233 sblimit = ((ptr - g->sb_hybrid) / 18) + 1;
01234
01235 if (g->block_type == 2) {
01236
01237 if (g->switch_point)
01238 mdct_long_end = 2;
01239 else
01240 mdct_long_end = 0;
01241 } else {
01242 mdct_long_end = sblimit;
01243 }
01244
01245 s->mpadsp.RENAME(imdct36_blocks)(sb_samples, mdct_buf, g->sb_hybrid,
01246 mdct_long_end, g->switch_point,
01247 g->block_type);
01248
01249 buf = mdct_buf + 4*18*(mdct_long_end >> 2) + (mdct_long_end & 3);
01250 ptr = g->sb_hybrid + 18 * mdct_long_end;
01251
01252 for (j = mdct_long_end; j < sblimit; j++) {
01253
01254 win = RENAME(ff_mdct_win)[2 + (4 & -(j & 1))];
01255 out_ptr = sb_samples + j;
01256
01257 for (i = 0; i < 6; i++) {
01258 *out_ptr = buf[4*i];
01259 out_ptr += SBLIMIT;
01260 }
01261 imdct12(out2, ptr + 0);
01262 for (i = 0; i < 6; i++) {
01263 *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*1)];
01264 buf[4*(i + 6*2)] = MULH3(out2[i + 6], win[i + 6], 1);
01265 out_ptr += SBLIMIT;
01266 }
01267 imdct12(out2, ptr + 1);
01268 for (i = 0; i < 6; i++) {
01269 *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*2)];
01270 buf[4*(i + 6*0)] = MULH3(out2[i + 6], win[i + 6], 1);
01271 out_ptr += SBLIMIT;
01272 }
01273 imdct12(out2, ptr + 2);
01274 for (i = 0; i < 6; i++) {
01275 buf[4*(i + 6*0)] = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*0)];
01276 buf[4*(i + 6*1)] = MULH3(out2[i + 6], win[i + 6], 1);
01277 buf[4*(i + 6*2)] = 0;
01278 }
01279 ptr += 18;
01280 buf += (j&3) != 3 ? 1 : (4*18-3);
01281 }
01282
01283 for (j = sblimit; j < SBLIMIT; j++) {
01284
01285 out_ptr = sb_samples + j;
01286 for (i = 0; i < 18; i++) {
01287 *out_ptr = buf[4*i];
01288 buf[4*i] = 0;
01289 out_ptr += SBLIMIT;
01290 }
01291 buf += (j&3) != 3 ? 1 : (4*18-3);
01292 }
01293 }
01294
01295
01296 static int mp_decode_layer3(MPADecodeContext *s)
01297 {
01298 int nb_granules, main_data_begin;
01299 int gr, ch, blocksplit_flag, i, j, k, n, bits_pos;
01300 GranuleDef *g;
01301 int16_t exponents[576];
01302
01303
01304 if (s->lsf) {
01305 main_data_begin = get_bits(&s->gb, 8);
01306 skip_bits(&s->gb, s->nb_channels);
01307 nb_granules = 1;
01308 } else {
01309 main_data_begin = get_bits(&s->gb, 9);
01310 if (s->nb_channels == 2)
01311 skip_bits(&s->gb, 3);
01312 else
01313 skip_bits(&s->gb, 5);
01314 nb_granules = 2;
01315 for (ch = 0; ch < s->nb_channels; ch++) {
01316 s->granules[ch][0].scfsi = 0;
01317 s->granules[ch][1].scfsi = get_bits(&s->gb, 4);
01318 }
01319 }
01320
01321 for (gr = 0; gr < nb_granules; gr++) {
01322 for (ch = 0; ch < s->nb_channels; ch++) {
01323 av_dlog(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch);
01324 g = &s->granules[ch][gr];
01325 g->part2_3_length = get_bits(&s->gb, 12);
01326 g->big_values = get_bits(&s->gb, 9);
01327 if (g->big_values > 288) {
01328 av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n");
01329 return AVERROR_INVALIDDATA;
01330 }
01331
01332 g->global_gain = get_bits(&s->gb, 8);
01333
01334
01335 if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
01336 MODE_EXT_MS_STEREO)
01337 g->global_gain -= 2;
01338 if (s->lsf)
01339 g->scalefac_compress = get_bits(&s->gb, 9);
01340 else
01341 g->scalefac_compress = get_bits(&s->gb, 4);
01342 blocksplit_flag = get_bits1(&s->gb);
01343 if (blocksplit_flag) {
01344 g->block_type = get_bits(&s->gb, 2);
01345 if (g->block_type == 0) {
01346 av_log(s->avctx, AV_LOG_ERROR, "invalid block type\n");
01347 return AVERROR_INVALIDDATA;
01348 }
01349 g->switch_point = get_bits1(&s->gb);
01350 for (i = 0; i < 2; i++)
01351 g->table_select[i] = get_bits(&s->gb, 5);
01352 for (i = 0; i < 3; i++)
01353 g->subblock_gain[i] = get_bits(&s->gb, 3);
01354 ff_init_short_region(s, g);
01355 } else {
01356 int region_address1, region_address2;
01357 g->block_type = 0;
01358 g->switch_point = 0;
01359 for (i = 0; i < 3; i++)
01360 g->table_select[i] = get_bits(&s->gb, 5);
01361
01362 region_address1 = get_bits(&s->gb, 4);
01363 region_address2 = get_bits(&s->gb, 3);
01364 av_dlog(s->avctx, "region1=%d region2=%d\n",
01365 region_address1, region_address2);
01366 ff_init_long_region(s, g, region_address1, region_address2);
01367 }
01368 ff_region_offset2size(g);
01369 ff_compute_band_indexes(s, g);
01370
01371 g->preflag = 0;
01372 if (!s->lsf)
01373 g->preflag = get_bits1(&s->gb);
01374 g->scalefac_scale = get_bits1(&s->gb);
01375 g->count1table_select = get_bits1(&s->gb);
01376 av_dlog(s->avctx, "block_type=%d switch_point=%d\n",
01377 g->block_type, g->switch_point);
01378 }
01379 }
01380
01381 if (!s->adu_mode) {
01382 int skip;
01383 const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
01384 int extrasize = av_clip(get_bits_left(&s->gb) >> 3, 0,
01385 FFMAX(0, LAST_BUF_SIZE - s->last_buf_size));
01386 assert((get_bits_count(&s->gb) & 7) == 0);
01387
01388 av_dlog(s->avctx, "seekback: %d\n", main_data_begin);
01389
01390
01391 memcpy(s->last_buf + s->last_buf_size, ptr, extrasize);
01392 s->in_gb = s->gb;
01393 init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8);
01394 #if !UNCHECKED_BITSTREAM_READER
01395 s->gb.size_in_bits_plus8 += extrasize * 8;
01396 #endif
01397 skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin));
01398 }
01399
01400 for (gr = 0; gr < nb_granules; gr++) {
01401 for (ch = 0; ch < s->nb_channels; ch++) {
01402 g = &s->granules[ch][gr];
01403 if (get_bits_count(&s->gb) < 0) {
01404 av_log(s->avctx, AV_LOG_DEBUG, "mdb:%d, lastbuf:%d skipping granule %d\n",
01405 main_data_begin, s->last_buf_size, gr);
01406 skip_bits_long(&s->gb, g->part2_3_length);
01407 memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));
01408 if (get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer) {
01409 skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits);
01410 s->gb = s->in_gb;
01411 s->in_gb.buffer = NULL;
01412 }
01413 continue;
01414 }
01415
01416 bits_pos = get_bits_count(&s->gb);
01417
01418 if (!s->lsf) {
01419 uint8_t *sc;
01420 int slen, slen1, slen2;
01421
01422
01423 slen1 = slen_table[0][g->scalefac_compress];
01424 slen2 = slen_table[1][g->scalefac_compress];
01425 av_dlog(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);
01426 if (g->block_type == 2) {
01427 n = g->switch_point ? 17 : 18;
01428 j = 0;
01429 if (slen1) {
01430 for (i = 0; i < n; i++)
01431 g->scale_factors[j++] = get_bits(&s->gb, slen1);
01432 } else {
01433 for (i = 0; i < n; i++)
01434 g->scale_factors[j++] = 0;
01435 }
01436 if (slen2) {
01437 for (i = 0; i < 18; i++)
01438 g->scale_factors[j++] = get_bits(&s->gb, slen2);
01439 for (i = 0; i < 3; i++)
01440 g->scale_factors[j++] = 0;
01441 } else {
01442 for (i = 0; i < 21; i++)
01443 g->scale_factors[j++] = 0;
01444 }
01445 } else {
01446 sc = s->granules[ch][0].scale_factors;
01447 j = 0;
01448 for (k = 0; k < 4; k++) {
01449 n = k == 0 ? 6 : 5;
01450 if ((g->scfsi & (0x8 >> k)) == 0) {
01451 slen = (k < 2) ? slen1 : slen2;
01452 if (slen) {
01453 for (i = 0; i < n; i++)
01454 g->scale_factors[j++] = get_bits(&s->gb, slen);
01455 } else {
01456 for (i = 0; i < n; i++)
01457 g->scale_factors[j++] = 0;
01458 }
01459 } else {
01460
01461 for (i = 0; i < n; i++) {
01462 g->scale_factors[j] = sc[j];
01463 j++;
01464 }
01465 }
01466 }
01467 g->scale_factors[j++] = 0;
01468 }
01469 } else {
01470 int tindex, tindex2, slen[4], sl, sf;
01471
01472
01473 if (g->block_type == 2)
01474 tindex = g->switch_point ? 2 : 1;
01475 else
01476 tindex = 0;
01477
01478 sf = g->scalefac_compress;
01479 if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {
01480
01481 sf >>= 1;
01482 if (sf < 180) {
01483 lsf_sf_expand(slen, sf, 6, 6, 0);
01484 tindex2 = 3;
01485 } else if (sf < 244) {
01486 lsf_sf_expand(slen, sf - 180, 4, 4, 0);
01487 tindex2 = 4;
01488 } else {
01489 lsf_sf_expand(slen, sf - 244, 3, 0, 0);
01490 tindex2 = 5;
01491 }
01492 } else {
01493
01494 if (sf < 400) {
01495 lsf_sf_expand(slen, sf, 5, 4, 4);
01496 tindex2 = 0;
01497 } else if (sf < 500) {
01498 lsf_sf_expand(slen, sf - 400, 5, 4, 0);
01499 tindex2 = 1;
01500 } else {
01501 lsf_sf_expand(slen, sf - 500, 3, 0, 0);
01502 tindex2 = 2;
01503 g->preflag = 1;
01504 }
01505 }
01506
01507 j = 0;
01508 for (k = 0; k < 4; k++) {
01509 n = lsf_nsf_table[tindex2][tindex][k];
01510 sl = slen[k];
01511 if (sl) {
01512 for (i = 0; i < n; i++)
01513 g->scale_factors[j++] = get_bits(&s->gb, sl);
01514 } else {
01515 for (i = 0; i < n; i++)
01516 g->scale_factors[j++] = 0;
01517 }
01518 }
01519
01520 for (; j < 40; j++)
01521 g->scale_factors[j] = 0;
01522 }
01523
01524 exponents_from_scale_factors(s, g, exponents);
01525
01526
01527 huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);
01528 }
01529
01530 if (s->nb_channels == 2)
01531 compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]);
01532
01533 for (ch = 0; ch < s->nb_channels; ch++) {
01534 g = &s->granules[ch][gr];
01535
01536 reorder_block(s, g);
01537 compute_antialias(s, g);
01538 compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
01539 }
01540 }
01541 if (get_bits_count(&s->gb) < 0)
01542 skip_bits_long(&s->gb, -get_bits_count(&s->gb));
01543 return nb_granules * 18;
01544 }
01545
01546 static int mp_decode_frame(MPADecodeContext *s, OUT_INT *samples,
01547 const uint8_t *buf, int buf_size)
01548 {
01549 int i, nb_frames, ch, ret;
01550 OUT_INT *samples_ptr;
01551
01552 init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8);
01553
01554
01555 if (s->error_protection)
01556 skip_bits(&s->gb, 16);
01557
01558 switch(s->layer) {
01559 case 1:
01560 s->avctx->frame_size = 384;
01561 nb_frames = mp_decode_layer1(s);
01562 break;
01563 case 2:
01564 s->avctx->frame_size = 1152;
01565 nb_frames = mp_decode_layer2(s);
01566 break;
01567 case 3:
01568 s->avctx->frame_size = s->lsf ? 576 : 1152;
01569 default:
01570 nb_frames = mp_decode_layer3(s);
01571
01572 s->last_buf_size=0;
01573 if (s->in_gb.buffer) {
01574 align_get_bits(&s->gb);
01575 i = get_bits_left(&s->gb)>>3;
01576 if (i >= 0 && i <= BACKSTEP_SIZE) {
01577 memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);
01578 s->last_buf_size=i;
01579 } else
01580 av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);
01581 s->gb = s->in_gb;
01582 s->in_gb.buffer = NULL;
01583 }
01584
01585 align_get_bits(&s->gb);
01586 assert((get_bits_count(&s->gb) & 7) == 0);
01587 i = get_bits_left(&s->gb) >> 3;
01588
01589 if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) {
01590 if (i < 0)
01591 av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i);
01592 i = FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);
01593 }
01594 assert(i <= buf_size - HEADER_SIZE && i >= 0);
01595 memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);
01596 s->last_buf_size += i;
01597 }
01598
01599
01600 if (!samples) {
01601 s->frame.nb_samples = s->avctx->frame_size;
01602 if ((ret = s->avctx->get_buffer(s->avctx, &s->frame)) < 0) {
01603 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
01604 return ret;
01605 }
01606 samples = (OUT_INT *)s->frame.data[0];
01607 }
01608
01609
01610 for (ch = 0; ch < s->nb_channels; ch++) {
01611 samples_ptr = samples + ch;
01612 for (i = 0; i < nb_frames; i++) {
01613 RENAME(ff_mpa_synth_filter)(
01614 &s->mpadsp,
01615 s->synth_buf[ch], &(s->synth_buf_offset[ch]),
01616 RENAME(ff_mpa_synth_window), &s->dither_state,
01617 samples_ptr, s->nb_channels,
01618 s->sb_samples[ch][i]);
01619 samples_ptr += 32 * s->nb_channels;
01620 }
01621 }
01622
01623 return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
01624 }
01625
01626 static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
01627 AVPacket *avpkt)
01628 {
01629 const uint8_t *buf = avpkt->data;
01630 int buf_size = avpkt->size;
01631 MPADecodeContext *s = avctx->priv_data;
01632 uint32_t header;
01633 int out_size;
01634
01635 if (buf_size < HEADER_SIZE)
01636 return AVERROR_INVALIDDATA;
01637
01638 header = AV_RB32(buf);
01639 if (ff_mpa_check_header(header) < 0) {
01640 av_log(avctx, AV_LOG_ERROR, "Header missing\n");
01641 return AVERROR_INVALIDDATA;
01642 }
01643
01644 if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
01645
01646 s->frame_size = -1;
01647 return AVERROR_INVALIDDATA;
01648 }
01649
01650 avctx->channels = s->nb_channels;
01651 avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
01652 if (!avctx->bit_rate)
01653 avctx->bit_rate = s->bit_rate;
01654 avctx->sub_id = s->layer;
01655
01656 if (s->frame_size <= 0 || s->frame_size > buf_size) {
01657 av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
01658 return AVERROR_INVALIDDATA;
01659 }else if(s->frame_size < buf_size){
01660 av_log(avctx, AV_LOG_DEBUG, "incorrect frame size - multiple frames in buffer?\n");
01661 buf_size= s->frame_size;
01662 }
01663
01664 out_size = mp_decode_frame(s, NULL, buf, buf_size);
01665 if (out_size >= 0) {
01666 *got_frame_ptr = 1;
01667 *(AVFrame *)data = s->frame;
01668 avctx->sample_rate = s->sample_rate;
01669
01670 } else {
01671 av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");
01672
01673
01674
01675
01676 *got_frame_ptr = 0;
01677 if (buf_size == avpkt->size)
01678 return out_size;
01679 }
01680 s->frame_size = 0;
01681 return buf_size;
01682 }
01683
01684 static void flush(AVCodecContext *avctx)
01685 {
01686 MPADecodeContext *s = avctx->priv_data;
01687 memset(s->synth_buf, 0, sizeof(s->synth_buf));
01688 s->last_buf_size = 0;
01689 }
01690
01691 #if CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER
01692 static int decode_frame_adu(AVCodecContext *avctx, void *data,
01693 int *got_frame_ptr, AVPacket *avpkt)
01694 {
01695 const uint8_t *buf = avpkt->data;
01696 int buf_size = avpkt->size;
01697 MPADecodeContext *s = avctx->priv_data;
01698 uint32_t header;
01699 int len, out_size;
01700
01701 len = buf_size;
01702
01703
01704 if (buf_size < HEADER_SIZE) {
01705 av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
01706 return AVERROR_INVALIDDATA;
01707 }
01708
01709
01710 if (len > MPA_MAX_CODED_FRAME_SIZE)
01711 len = MPA_MAX_CODED_FRAME_SIZE;
01712
01713
01714 header = AV_RB32(buf) | 0xffe00000;
01715
01716 if (ff_mpa_check_header(header) < 0) {
01717 av_log(avctx, AV_LOG_ERROR, "Invalid frame header\n");
01718 return AVERROR_INVALIDDATA;
01719 }
01720
01721 avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header);
01722
01723 avctx->sample_rate = s->sample_rate;
01724 avctx->channels = s->nb_channels;
01725 if (!avctx->bit_rate)
01726 avctx->bit_rate = s->bit_rate;
01727 avctx->sub_id = s->layer;
01728
01729 s->frame_size = len;
01730
01731 #if FF_API_PARSE_FRAME
01732 if (avctx->parse_only)
01733 out_size = buf_size;
01734 else
01735 #endif
01736 out_size = mp_decode_frame(s, NULL, buf, buf_size);
01737
01738 *got_frame_ptr = 1;
01739 *(AVFrame *)data = s->frame;
01740
01741 return buf_size;
01742 }
01743 #endif
01744
01745 #if CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER
01746
01750 typedef struct MP3On4DecodeContext {
01751 AVFrame *frame;
01752 int frames;
01753 int syncword;
01754 const uint8_t *coff;
01755 MPADecodeContext *mp3decctx[5];
01756 OUT_INT *decoded_buf;
01757 } MP3On4DecodeContext;
01758
01759 #include "mpeg4audio.h"
01760
01761
01762
01763
01764 static const uint8_t mp3Frames[8] = { 0, 1, 1, 2, 3, 3, 4, 5 };
01765
01766
01767 static const uint8_t chan_offset[8][5] = {
01768 { 0 },
01769 { 0 },
01770 { 0 },
01771 { 2, 0 },
01772 { 2, 0, 3 },
01773 { 2, 0, 3 },
01774 { 2, 0, 4, 3 },
01775 { 2, 0, 6, 4, 3 },
01776 };
01777
01778
01779 static const int16_t chan_layout[8] = {
01780 0,
01781 AV_CH_LAYOUT_MONO,
01782 AV_CH_LAYOUT_STEREO,
01783 AV_CH_LAYOUT_SURROUND,
01784 AV_CH_LAYOUT_4POINT0,
01785 AV_CH_LAYOUT_5POINT0,
01786 AV_CH_LAYOUT_5POINT1,
01787 AV_CH_LAYOUT_7POINT1
01788 };
01789
01790 static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
01791 {
01792 MP3On4DecodeContext *s = avctx->priv_data;
01793 int i;
01794
01795 for (i = 0; i < s->frames; i++)
01796 av_free(s->mp3decctx[i]);
01797
01798 av_freep(&s->decoded_buf);
01799
01800 return 0;
01801 }
01802
01803
01804 static int decode_init_mp3on4(AVCodecContext * avctx)
01805 {
01806 MP3On4DecodeContext *s = avctx->priv_data;
01807 MPEG4AudioConfig cfg;
01808 int i;
01809
01810 if ((avctx->extradata_size < 2) || (avctx->extradata == NULL)) {
01811 av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n");
01812 return AVERROR_INVALIDDATA;
01813 }
01814
01815 avpriv_mpeg4audio_get_config(&cfg, avctx->extradata,
01816 avctx->extradata_size * 8, 1);
01817 if (!cfg.chan_config || cfg.chan_config > 7) {
01818 av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
01819 return AVERROR_INVALIDDATA;
01820 }
01821 s->frames = mp3Frames[cfg.chan_config];
01822 s->coff = chan_offset[cfg.chan_config];
01823 avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
01824 avctx->channel_layout = chan_layout[cfg.chan_config];
01825
01826 if (cfg.sample_rate < 16000)
01827 s->syncword = 0xffe00000;
01828 else
01829 s->syncword = 0xfff00000;
01830
01831
01832
01833
01834
01835
01836
01837 s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
01838 if (!s->mp3decctx[0])
01839 goto alloc_fail;
01840
01841 avctx->priv_data = s->mp3decctx[0];
01842 decode_init(avctx);
01843 s->frame = avctx->coded_frame;
01844
01845 avctx->priv_data = s;
01846 s->mp3decctx[0]->adu_mode = 1;
01847
01848
01849
01850
01851 for (i = 1; i < s->frames; i++) {
01852 s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
01853 if (!s->mp3decctx[i])
01854 goto alloc_fail;
01855 s->mp3decctx[i]->adu_mode = 1;
01856 s->mp3decctx[i]->avctx = avctx;
01857 s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
01858 }
01859
01860
01861 if (s->frames > 1) {
01862 s->decoded_buf = av_malloc(MPA_FRAME_SIZE * MPA_MAX_CHANNELS *
01863 sizeof(*s->decoded_buf));
01864 if (!s->decoded_buf)
01865 goto alloc_fail;
01866 }
01867
01868 return 0;
01869 alloc_fail:
01870 decode_close_mp3on4(avctx);
01871 return AVERROR(ENOMEM);
01872 }
01873
01874
01875 static void flush_mp3on4(AVCodecContext *avctx)
01876 {
01877 int i;
01878 MP3On4DecodeContext *s = avctx->priv_data;
01879
01880 for (i = 0; i < s->frames; i++) {
01881 MPADecodeContext *m = s->mp3decctx[i];
01882 memset(m->synth_buf, 0, sizeof(m->synth_buf));
01883 m->last_buf_size = 0;
01884 }
01885 }
01886
01887
01888 static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
01889 int *got_frame_ptr, AVPacket *avpkt)
01890 {
01891 const uint8_t *buf = avpkt->data;
01892 int buf_size = avpkt->size;
01893 MP3On4DecodeContext *s = avctx->priv_data;
01894 MPADecodeContext *m;
01895 int fsize, len = buf_size, out_size = 0;
01896 uint32_t header;
01897 OUT_INT *out_samples;
01898 OUT_INT *outptr, *bp;
01899 int fr, j, n, ch, ret;
01900
01901
01902 s->frame->nb_samples = MPA_FRAME_SIZE;
01903 if ((ret = avctx->get_buffer(avctx, s->frame)) < 0) {
01904 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
01905 return ret;
01906 }
01907 out_samples = (OUT_INT *)s->frame->data[0];
01908
01909
01910 if (buf_size < HEADER_SIZE)
01911 return AVERROR_INVALIDDATA;
01912
01913
01914 outptr = s->frames == 1 ? out_samples : s->decoded_buf;
01915
01916 avctx->bit_rate = 0;
01917
01918 ch = 0;
01919 for (fr = 0; fr < s->frames; fr++) {
01920 fsize = AV_RB16(buf) >> 4;
01921 fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);
01922 m = s->mp3decctx[fr];
01923 assert(m != NULL);
01924
01925 if (fsize < HEADER_SIZE) {
01926 av_log(avctx, AV_LOG_ERROR, "Frame size smaller than header size\n");
01927 return AVERROR_INVALIDDATA;
01928 }
01929 header = (AV_RB32(buf) & 0x000fffff) | s->syncword;
01930
01931 if (ff_mpa_check_header(header) < 0)
01932 break;
01933
01934 avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header);
01935
01936 if (ch + m->nb_channels > avctx->channels) {
01937 av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
01938 "channel count\n");
01939 return AVERROR_INVALIDDATA;
01940 }
01941 ch += m->nb_channels;
01942
01943 out_size += mp_decode_frame(m, outptr, buf, fsize);
01944 buf += fsize;
01945 len -= fsize;
01946
01947 if (s->frames > 1) {
01948 n = m->avctx->frame_size*m->nb_channels;
01949
01950 bp = out_samples + s->coff[fr];
01951 if (m->nb_channels == 1) {
01952 for (j = 0; j < n; j++) {
01953 *bp = s->decoded_buf[j];
01954 bp += avctx->channels;
01955 }
01956 } else {
01957 for (j = 0; j < n; j++) {
01958 bp[0] = s->decoded_buf[j++];
01959 bp[1] = s->decoded_buf[j];
01960 bp += avctx->channels;
01961 }
01962 }
01963 }
01964 avctx->bit_rate += m->bit_rate;
01965 }
01966
01967
01968 avctx->sample_rate = s->mp3decctx[0]->sample_rate;
01969
01970 s->frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT));
01971 *got_frame_ptr = 1;
01972 *(AVFrame *)data = *s->frame;
01973
01974 return buf_size;
01975 }
01976 #endif
01977
01978 #if !CONFIG_FLOAT
01979 #if CONFIG_MP1_DECODER
01980 AVCodec ff_mp1_decoder = {
01981 .name = "mp1",
01982 .type = AVMEDIA_TYPE_AUDIO,
01983 .id = CODEC_ID_MP1,
01984 .priv_data_size = sizeof(MPADecodeContext),
01985 .init = decode_init,
01986 .decode = decode_frame,
01987 #if FF_API_PARSE_FRAME
01988 .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
01989 #else
01990 .capabilities = CODEC_CAP_DR1,
01991 #endif
01992 .flush = flush,
01993 .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
01994 };
01995 #endif
01996 #if CONFIG_MP2_DECODER
01997 AVCodec ff_mp2_decoder = {
01998 .name = "mp2",
01999 .type = AVMEDIA_TYPE_AUDIO,
02000 .id = CODEC_ID_MP2,
02001 .priv_data_size = sizeof(MPADecodeContext),
02002 .init = decode_init,
02003 .decode = decode_frame,
02004 #if FF_API_PARSE_FRAME
02005 .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
02006 #else
02007 .capabilities = CODEC_CAP_DR1,
02008 #endif
02009 .flush = flush,
02010 .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
02011 };
02012 #endif
02013 #if CONFIG_MP3_DECODER
02014 AVCodec ff_mp3_decoder = {
02015 .name = "mp3",
02016 .type = AVMEDIA_TYPE_AUDIO,
02017 .id = CODEC_ID_MP3,
02018 .priv_data_size = sizeof(MPADecodeContext),
02019 .init = decode_init,
02020 .decode = decode_frame,
02021 #if FF_API_PARSE_FRAME
02022 .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
02023 #else
02024 .capabilities = CODEC_CAP_DR1,
02025 #endif
02026 .flush = flush,
02027 .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
02028 };
02029 #endif
02030 #if CONFIG_MP3ADU_DECODER
02031 AVCodec ff_mp3adu_decoder = {
02032 .name = "mp3adu",
02033 .type = AVMEDIA_TYPE_AUDIO,
02034 .id = CODEC_ID_MP3ADU,
02035 .priv_data_size = sizeof(MPADecodeContext),
02036 .init = decode_init,
02037 .decode = decode_frame_adu,
02038 #if FF_API_PARSE_FRAME
02039 .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
02040 #else
02041 .capabilities = CODEC_CAP_DR1,
02042 #endif
02043 .flush = flush,
02044 .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
02045 };
02046 #endif
02047 #if CONFIG_MP3ON4_DECODER
02048 AVCodec ff_mp3on4_decoder = {
02049 .name = "mp3on4",
02050 .type = AVMEDIA_TYPE_AUDIO,
02051 .id = CODEC_ID_MP3ON4,
02052 .priv_data_size = sizeof(MP3On4DecodeContext),
02053 .init = decode_init_mp3on4,
02054 .close = decode_close_mp3on4,
02055 .decode = decode_frame_mp3on4,
02056 .capabilities = CODEC_CAP_DR1,
02057 .flush = flush_mp3on4,
02058 .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
02059 };
02060 #endif
02061 #endif