diff options
Diffstat (limited to 'libavcodec/mpegaudiodec.c')
-rw-r--r-- | libavcodec/mpegaudiodec.c | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 6c08862..f474161 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 */ @@ -24,6 +24,8 @@ * MPEG Audio decoder */ +#define UNCHECKED_BITSTREAM_READER 1 + #include "libavutil/audioconvert.h" #include "avcodec.h" #include "get_bits.h" @@ -955,7 +957,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; } @@ -985,10 +987,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; } @@ -1376,7 +1378,6 @@ 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, EXTRABYTES); assert((get_bits_count(&s->gb) & 7) == 0); @@ -1390,29 +1391,25 @@ static int mp_decode_layer3(MPADecodeContext *s) #if !UNCHECKED_BITSTREAM_READER s->gb.size_in_bits_plus8 += extrasize * 8; #endif - s->last_buf_size <<= 3; - for (gr = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++) { - for (ch = 0; ch < s->nb_channels; ch++) { - g = &s->granules[ch][gr]; - s->last_buf_size += g->part2_3_length; - memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid)); - } - } - skip = s->last_buf_size - 8 * main_data_begin; - if (skip >= s->gb.size_in_bits && s->in_gb.buffer) { - skip_bits_long(&s->in_gb, skip - s->gb.size_in_bits); - s->gb = s->in_gb; - s->in_gb.buffer = NULL; - } else { - skip_bits_long(&s->gb, skip); - } - } else { - gr = 0; + skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin)); } - for (; gr < nb_granules; gr++) { + for (gr = 0; gr < nb_granules; gr++) { for (ch = 0; ch < s->nb_channels; ch++) { g = &s->granules[ch][gr]; + if (get_bits_count(&s->gb) < 0) { + 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)); + if (get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer) { + skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits); + s->gb = s->in_gb; + s->in_gb.buffer = NULL; + } + continue; + } + bits_pos = get_bits_count(&s->gb); if (!s->lsf) { @@ -1656,8 +1653,8 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, if (s->frame_size <= 0 || s->frame_size > buf_size) { av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); return AVERROR_INVALIDDATA; - } else if (s->frame_size < buf_size) { - av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n"); + }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; } |