diff options
Diffstat (limited to 'libavcodec/mpegaudiodec.c')
-rw-r--r-- | libavcodec/mpegaudiodec.c | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 80acdadc48..6ef1f6b427 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -2,20 +2,20 @@ * MPEG Audio decoder * Copyright (c) 2001, 2002 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -25,6 +25,8 @@ */ #include "libavutil/audioconvert.h" +#include "libavutil/avassert.h" +#include "libavutil/libm.h" #include "avcodec.h" #include "get_bits.h" #include "mathops.h" @@ -203,6 +205,8 @@ static void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g) { if (g->block_type == 2) { if (g->switch_point) { + if(s->sample_rate_index == 8) + av_log_ask_for_sample(s->avctx, "switch point in 8khz\n"); /* if switched mode, we handle the 36 first samples as long blocks. For 8000Hz, we handle the 72 first exponents as long blocks */ @@ -262,7 +266,10 @@ static inline int l3_unscale(int value, int exponent) e = table_4_3_exp [4 * value + (exponent & 3)]; m = table_4_3_value[4 * value + (exponent & 3)]; e -= exponent >> 2; - assert(e >= 1); +#ifdef DEBUG + if(e < 1) + av_log(0, AV_LOG_WARNING, "l3_unscale: e is %d\n", e); +#endif if (e > 31) return 0; m = (m + (1 << (e - 1))) >> e; @@ -326,7 +333,7 @@ static av_cold void decode_init_static(void) INIT_VLC_USE_NEW_STATIC); offset += huff_vlc_tables_sizes[i]; } - assert(offset == FF_ARRAY_ELEMS(huff_vlc_tables)); + av_assert0(offset == FF_ARRAY_ELEMS(huff_vlc_tables)); offset = 0; for (i = 0; i < 2; i++) { @@ -337,7 +344,7 @@ static av_cold void decode_init_static(void) INIT_VLC_USE_NEW_STATIC); offset += huff_quad_vlc_tables_sizes[i]; } - assert(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables)); + av_assert0(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables)); for (i = 0; i < 9; i++) { k = 0; @@ -390,7 +397,7 @@ static av_cold void decode_init_static(void) for (j = 0; j < 2; j++) { e = -(j + 1) * ((i + 1) >> 1); - f = pow(2.0, e / 4.0); + f = exp2(e / 4.0); k = i & 1; is_table_lsf[j][k ^ 1][i] = FIXR(f); is_table_lsf[j][k ][i] = FIXR(1.0); @@ -826,7 +833,7 @@ static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, 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); + av_assert2((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; @@ -955,7 +962,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, s_index -= 4; skip_bits_long(&s->gb, last_pos - pos); 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->err_recognition & AV_EF_BITSTREAM) + if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) s_index=0; break; } @@ -982,10 +989,10 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, } /* skip extension bits */ bits_left = end_pos2 - get_bits_count(&s->gb); - if (bits_left < 0 && (s->err_recognition & AV_EF_BUFFER)) { + if (bits_left < 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_COMPLIANT))) { av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left); s_index=0; - } else if (bits_left > 0 && (s->err_recognition & AV_EF_BUFFER)) { + } else if (bits_left > 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) { av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left); s_index = 0; } @@ -1165,6 +1172,17 @@ found2: } #if CONFIG_FLOAT +#if HAVE_MIPSFPU +# include "mips/compute_antialias_float.h" +#endif /* HAVE_MIPSFPU */ +#else +#if HAVE_MIPSDSPR1 +# include "mips/compute_antialias_fixed.h" +#endif /* HAVE_MIPSDSPR1 */ +#endif /* CONFIG_FLOAT */ + +#ifndef compute_antialias +#if CONFIG_FLOAT #define AA(j) do { \ float tmp0 = ptr[-1-j]; \ float tmp1 = ptr[ j]; \ @@ -1210,6 +1228,7 @@ static void compute_antialias(MPADecodeContext *s, GranuleDef *g) ptr += 18; } } +#endif /* compute_antialias */ static void compute_imdct(MPADecodeContext *s, GranuleDef *g, INTFLOAT *sb_samples, INTFLOAT *mdct_buf) @@ -1379,9 +1398,8 @@ static int mp_decode_layer3(MPADecodeContext *s) if (!s->adu_mode) { int skip; const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3); - int extrasize = av_clip(get_bits_left(&s->gb) >> 3, 0, - FFMAX(0, LAST_BUF_SIZE - s->last_buf_size)); - assert((get_bits_count(&s->gb) & 7) == 0); + int extrasize = av_clip(get_bits_left(&s->gb) >> 3, 0, EXTRABYTES); + av_assert1((get_bits_count(&s->gb) & 7) == 0); /* now we get bits from the main_data_begin offset */ av_dlog(s->avctx, "seekback:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size); @@ -1390,7 +1408,7 @@ static int mp_decode_layer3(MPADecodeContext *s) s->in_gb = s->gb; init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8); #if !UNCHECKED_BITSTREAM_READER - s->gb.size_in_bits_plus8 += extrasize * 8; + s->gb.size_in_bits_plus8 += FFMAX(extrasize, LAST_BUF_SIZE - s->last_buf_size) * 8; #endif s->last_buf_size <<= 3; for (gr = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++) { @@ -1585,7 +1603,7 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT *samples, } align_get_bits(&s->gb); - assert((get_bits_count(&s->gb) & 7) == 0); + av_assert1((get_bits_count(&s->gb) & 7) == 0); i = get_bits_left(&s->gb) >> 3; if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) { @@ -1593,7 +1611,7 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT *samples, 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); + av_assert1(i <= buf_size - HEADER_SIZE && i >= 0); memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); s->last_buf_size += i; } @@ -1634,10 +1652,19 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, uint32_t header; int out_size; + while(buf_size && !*buf){ + buf++; + buf_size--; + } + if (buf_size < HEADER_SIZE) return AVERROR_INVALIDDATA; header = AV_RB32(buf); + if (header>>8 == AV_RB32("TAG")>>8) { + av_log(avctx, AV_LOG_DEBUG, "discarding ID3 tag\n"); + return buf_size; + } if (ff_mpa_check_header(header) < 0) { av_log(avctx, AV_LOG_ERROR, "Header missing\n"); return AVERROR_INVALIDDATA; @@ -1658,6 +1685,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); return AVERROR_INVALIDDATA; } else if (s->frame_size < buf_size) { + av_log(avctx, AV_LOG_DEBUG, "incorrect frame size - multiple frames in buffer?\n"); buf_size= s->frame_size; } @@ -1696,7 +1724,8 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data, int buf_size = avpkt->size; MPADecodeContext *s = avctx->priv_data; uint32_t header; - int len, out_size; + int len; + int av_unused out_size; len = buf_size; @@ -1897,7 +1926,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, int fr, j, n, ch, ret; /* get output buffer */ - s->frame->nb_samples = MPA_FRAME_SIZE; + s->frame->nb_samples = s->frames * MPA_FRAME_SIZE; if ((ret = avctx->get_buffer(avctx, s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; @@ -1918,7 +1947,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, fsize = AV_RB16(buf) >> 4; fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE); m = s->mp3decctx[fr]; - assert(m != NULL); + av_assert1(m); if (fsize < HEADER_SIZE) { av_log(avctx, AV_LOG_ERROR, "Frame size smaller than header size\n"); |