diff options
Diffstat (limited to 'contrib/ffmpeg/libavcodec/mpegaudiodec.c')
-rw-r--r-- | contrib/ffmpeg/libavcodec/mpegaudiodec.c | 121 |
1 files changed, 60 insertions, 61 deletions
diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodec.c b/contrib/ffmpeg/libavcodec/mpegaudiodec.c index 54bcee3b0..d64c9f611 100644 --- a/contrib/ffmpeg/libavcodec/mpegaudiodec.c +++ b/contrib/ffmpeg/libavcodec/mpegaudiodec.c @@ -90,6 +90,7 @@ typedef struct MPADecodeContext { int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 int dither_state; int error_resilience; + AVCodecContext* avctx; } MPADecodeContext; /** @@ -143,8 +144,8 @@ static VLC huff_quad_vlc[2]; 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; -static uint32_t *table_4_3_value; +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]; /* intensity stereo coef table */ @@ -301,6 +302,8 @@ static int decode_init(AVCodecContext * avctx) static int init=0; int i, j, k; + s->avctx = avctx; + #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT) avctx->sample_fmt= SAMPLE_FMT_S32; #else @@ -327,11 +330,11 @@ static int decode_init(AVCodecContext * avctx) for(i=0;i<15;i++) { int n, norm; n = i + 2; - norm = ((int64_t_C(1) << n) * FRAC_ONE) / ((1 << n) - 1); + 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); - dprintf("%d: norm=%x s=%x %x %x\n", + dprintf(avctx, "%d: norm=%x s=%x %x %x\n", i, norm, scale_factor_mult[i][0], scale_factor_mult[i][1], @@ -381,12 +384,6 @@ static int decode_init(AVCodecContext * avctx) } /* compute n ^ (4/3) and store it in mantissa/exp format */ - table_4_3_exp= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_exp[0])); - if(!table_4_3_exp) - return -1; - table_4_3_value= av_mallocz_static(TABLE_4_3_SIZE * sizeof(table_4_3_value[0])); - if(!table_4_3_value) - return -1; int_pow_init(); for(i=1;i<TABLE_4_3_SIZE;i++) { @@ -436,7 +433,7 @@ static int decode_init(AVCodecContext * avctx) k = i & 1; is_table_lsf[j][k ^ 1][i] = FIXR(f); is_table_lsf[j][k][i] = FIXR(1.0); - dprintf("is_table_lsf %d %d: %x %x\n", + dprintf(avctx, "is_table_lsf %d %d: %x %x\n", i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]); } } @@ -1172,20 +1169,20 @@ static int decode_header(MPADecodeContext *s, uint32_t header) } #if defined(DEBUG) - dprintf("layer%d, %d Hz, %d kbits/s, ", + dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ", s->layer, s->sample_rate, s->bit_rate); if (s->nb_channels == 2) { if (s->layer == 3) { if (s->mode_ext & MODE_EXT_MS_STEREO) - dprintf("ms-"); + dprintf(s->avctx, "ms-"); if (s->mode_ext & MODE_EXT_I_STEREO) - dprintf("i-"); + dprintf(s->avctx, "i-"); } - dprintf("stereo"); + dprintf(s->avctx, "stereo"); } else { - dprintf("mono"); + dprintf(s->avctx, "mono"); } - dprintf("\n"); + dprintf(s->avctx, "\n"); #endif return 0; } @@ -1195,6 +1192,7 @@ static int decode_header(MPADecodeContext *s, uint32_t header) int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate) { MPADecodeContext s1, *s = &s1; + s1.avctx = avctx; if (ff_mpa_check_header(head) != 0) return -1; @@ -1336,7 +1334,7 @@ static int mp_decode_layer2(MPADecodeContext *s) else bound = sblimit; - dprintf("bound=%d sblimit=%d\n", bound, sblimit); + dprintf(s->avctx, "bound=%d sblimit=%d\n", bound, sblimit); /* sanity check */ if( bound > sblimit ) bound = sblimit; @@ -1362,8 +1360,8 @@ static int mp_decode_layer2(MPADecodeContext *s) { for(ch=0;ch<s->nb_channels;ch++) { for(i=0;i<sblimit;i++) - dprintf(" %d", bit_alloc[ch][i]); - dprintf("\n"); + dprintf(s->avctx, " %d", bit_alloc[ch][i]); + dprintf(s->avctx, "\n"); } } #endif @@ -1413,12 +1411,12 @@ static int mp_decode_layer2(MPADecodeContext *s) for(i=0;i<sblimit;i++) { if (bit_alloc[ch][i]) { sf = scale_factors[ch][i]; - dprintf(" %d %d %d", sf[0], sf[1], sf[2]); + dprintf(s->avctx, " %d %d %d", sf[0], sf[1], sf[2]); } else { - dprintf(" -"); + dprintf(s->avctx, " -"); } } - dprintf("\n"); + dprintf(s->avctx, "\n"); } #endif @@ -1592,6 +1590,19 @@ static inline int get_bitsz(GetBitContext *s, int n) return get_bits(s, n); } + +static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, int *end_pos2){ + if(s->in_gb.buffer && *pos >= s->gb.size_in_bits){ + s->gb= s->in_gb; + s->in_gb.buffer=NULL; + assert((get_bits_count(&s->gb) & 7) == 0); + skip_bits_long(&s->gb, *pos - *end_pos); + *end_pos2= + *end_pos= *end_pos2 + get_bits_count(&s->gb) - *pos; + *pos= get_bits_count(&s->gb); + } +} + static int huffman_decode(MPADecodeContext *s, GranuleDef *g, int16_t *exponents, int end_pos2) { @@ -1627,15 +1638,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, if (pos >= end_pos){ // av_log(NULL, AV_LOG_ERROR, "pos: %d %d %d %d\n", pos, end_pos, end_pos2, s_index); - if(s->in_gb.buffer && pos >= s->gb.size_in_bits){ - s->gb= s->in_gb; - s->in_gb.buffer=NULL; - assert((get_bits_count(&s->gb) & 7) == 0); - skip_bits_long(&s->gb, pos - end_pos); - end_pos2= - end_pos= end_pos2 + get_bits_count(&s->gb) - pos; - pos= get_bits_count(&s->gb); - } + switch_buffer(s, &pos, &end_pos, &end_pos2); // av_log(NULL, AV_LOG_ERROR, "new pos: %d %d\n", pos, end_pos); if(pos >= end_pos) break; @@ -1651,7 +1654,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, exponent= exponents[s_index]; - dprintf("region=%d n=%d x=%d y=%d exp=%d\n", + dprintf(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n", i, g->region_size[i] - j, x, y, exponent); if(y&16){ x = y >> 5; @@ -1712,15 +1715,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, break; } // av_log(NULL, AV_LOG_ERROR, "pos2: %d %d %d %d\n", pos, end_pos, end_pos2, s_index); - if(s->in_gb.buffer && pos >= s->gb.size_in_bits){ - s->gb= s->in_gb; - s->in_gb.buffer=NULL; - assert((get_bits_count(&s->gb) & 7) == 0); - skip_bits_long(&s->gb, pos - end_pos); - end_pos2= - end_pos= end_pos2 + get_bits_count(&s->gb) - pos; - pos= get_bits_count(&s->gb); - } + switch_buffer(s, &pos, &end_pos, &end_pos2); // av_log(NULL, AV_LOG_ERROR, "new pos2: %d %d %d\n", pos, end_pos, s_index); if(pos >= end_pos) break; @@ -1728,7 +1723,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, last_pos= pos; code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1); - dprintf("t=%d code=%d\n", g->count1table_select, code); + dprintf(s->avctx, "t=%d code=%d\n", g->count1table_select, code); g->sb_hybrid[s_index+0]= g->sb_hybrid[s_index+1]= g->sb_hybrid[s_index+2]= @@ -1747,9 +1742,9 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, s_index+=4; } /* skip extension bits */ - bits_left = end_pos - get_bits_count(&s->gb); + 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 > 16) { + if (bits_left < 0/* || bits_left > 500*/) { av_log(NULL, AV_LOG_ERROR, "bits_left=%d\n", bits_left); s_index=0; }else if(bits_left > 0 && s->error_resilience >= FF_ER_AGGRESSIVE){ @@ -1759,6 +1754,9 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*(576 - s_index)); skip_bits_long(&s->gb, bits_left); + i= get_bits_count(&s->gb); + switch_buffer(s, &i, &end_pos, &end_pos2); + return 0; } @@ -2168,12 +2166,12 @@ static int mp_decode_layer3(MPADecodeContext *s) for(gr=0;gr<nb_granules;gr++) { for(ch=0;ch<s->nb_channels;ch++) { - dprintf("gr=%d ch=%d: side_info\n", gr, ch); + dprintf(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch); g = &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){ - av_log(NULL, AV_LOG_ERROR, "big_values too big\n"); + av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n"); return -1; } @@ -2220,7 +2218,7 @@ static int mp_decode_layer3(MPADecodeContext *s) /* compute huffman coded region sizes */ region_address1 = get_bits(&s->gb, 4); region_address2 = get_bits(&s->gb, 3); - dprintf("region1=%d region2=%d\n", + dprintf(s->avctx, "region1=%d region2=%d\n", region_address1, region_address2); g->region_size[0] = band_index_long[s->sample_rate_index][region_address1 + 1] >> 1; @@ -2269,7 +2267,7 @@ static int mp_decode_layer3(MPADecodeContext *s) g->preflag = get_bits(&s->gb, 1); g->scalefac_scale = get_bits(&s->gb, 1); g->count1table_select = get_bits(&s->gb, 1); - dprintf("block_type=%d switch_point=%d\n", + dprintf(s->avctx, "block_type=%d switch_point=%d\n", g->block_type, g->switch_point); } } @@ -2278,7 +2276,7 @@ static int mp_decode_layer3(MPADecodeContext *s) const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3); assert((get_bits_count(&s->gb) & 7) == 0); /* now we get bits from the main_data_begin offset */ - dprintf("seekback: %d\n", main_data_begin); + dprintf(s->avctx, "seekback: %d\n", main_data_begin); //av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size); memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES); @@ -2312,7 +2310,7 @@ static int mp_decode_layer3(MPADecodeContext *s) /* MPEG1 scale factors */ slen1 = slen_table[0][g->scalefac_compress]; slen2 = slen_table[1][g->scalefac_compress]; - dprintf("slen1=%d slen2=%d\n", slen1, slen2); + dprintf(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2); if (g->block_type == 2) { n = g->switch_point ? 17 : 18; j = 0; @@ -2358,11 +2356,11 @@ static int mp_decode_layer3(MPADecodeContext *s) } #if defined(DEBUG) { - dprintf("scfsi=%x gr=%d ch=%d scale_factors:\n", + dprintf(s->avctx, "scfsi=%x gr=%d ch=%d scale_factors:\n", g->scfsi, gr, ch); for(i=0;i<j;i++) - dprintf(" %d", g->scale_factors[i]); - dprintf("\n"); + dprintf(s->avctx, " %d", g->scale_factors[i]); + dprintf(s->avctx, "\n"); } #endif } else { @@ -2420,11 +2418,11 @@ static int mp_decode_layer3(MPADecodeContext *s) g->scale_factors[j] = 0; #if defined(DEBUG) { - dprintf("gr=%d ch=%d scale_factors:\n", + dprintf(s->avctx, "gr=%d ch=%d scale_factors:\n", gr, ch); for(i=0;i<40;i++) - dprintf(" %d", g->scale_factors[i]); - dprintf("\n"); + dprintf(s->avctx, " %d", g->scale_factors[i]); + dprintf(s->avctx, "\n"); } #endif } @@ -2475,7 +2473,7 @@ static int mp_decode_frame(MPADecodeContext *s, if (s->error_protection) get_bits(&s->gb, 16); - dprintf("frame %d:\n", s->frame_count); + dprintf(s->avctx, "frame %d:\n", s->frame_count); switch(s->layer) { case 1: nb_frames = mp_decode_layer1(s); @@ -2518,10 +2516,10 @@ static int mp_decode_frame(MPADecodeContext *s, for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; - dprintf("%d-%d:", i, ch); + dprintf(s->avctx, "%d-%d:", i, ch); for(j=0;j<SBLIMIT;j++) - dprintf(" %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE); - dprintf("\n"); + dprintf(s->avctx, " %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE); + dprintf(s->avctx, "\n"); } } #endif @@ -2717,6 +2715,7 @@ static int decode_init_mp3on4(AVCodecContext * avctx) s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext)); s->mp3decctx[i]->compute_antialias = s->mp3decctx[0]->compute_antialias; s->mp3decctx[i]->adu_mode = 1; + s->mp3decctx[i]->avctx = avctx; } return 0; |