diff options
Diffstat (limited to 'libavcodec/mpegaudiodec.c')
-rw-r--r-- | libavcodec/mpegaudiodec.c | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 03094f6..8507976 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,7 @@ */ #include "libavutil/audioconvert.h" +#include "libavutil/avassert.h" #include "avcodec.h" #include "get_bits.h" #include "mathops.h" @@ -262,7 +263,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 +330,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 +341,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; @@ -826,7 +830,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; @@ -957,7 +961,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; } @@ -987,10 +991,10 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, /* 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 && (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; } @@ -1170,6 +1174,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]; \ @@ -1215,6 +1230,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) @@ -1384,9 +1400,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\n", main_data_begin); //av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size); @@ -1395,7 +1410,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++) { @@ -1590,7 +1605,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) { @@ -1598,7 +1613,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; } @@ -1639,10 +1654,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; @@ -1663,6 +1687,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; } @@ -1701,7 +1726,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; @@ -1902,7 +1928,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; @@ -1923,7 +1949,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"); |