From 481a7ff5bd44dc63fcdabe34474a921269c97f99 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sat, 31 Dec 2011 13:36:48 -0500 Subject: mpegaudiodec: fix compilation when testing the unchecked bitstream reader --- libavcodec/mpegaudiodec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavcodec/mpegaudiodec.c') diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 0c8f9c787b..63ae455199 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -1548,7 +1548,7 @@ static int mp_decode_layer3(MPADecodeContext *s) memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES); s->in_gb = s->gb; init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8); -#if CONFIG_SAFE_BITSTREAM_READER +#if !UNCHECKED_BITSTREAM_READER s->gb.size_in_bits_plus8 += EXTRABYTES * 8; #endif skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin)); -- cgit v1.2.3 From 464f26889c99f194d112fcf1197795d341fad38b Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 30 Dec 2011 13:08:21 -0800 Subject: mpegaudiodec: fix seeking. The safe bitstream reader does not allow using skip_bits_long() to seek to a point before the start of the buffer, which was needed by the mp3 decoder. This change instead calculates the start point of the first valid granule and skips to that position. Signed-off-by: Justin Ruggles --- libavcodec/mpegaudiodec.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'libavcodec/mpegaudiodec.c') diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 63ae455199..ad3b199e24 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -1551,25 +1551,27 @@ static int mp_decode_layer3(MPADecodeContext *s) #if !UNCHECKED_BITSTREAM_READER s->gb.size_in_bits_plus8 += EXTRABYTES * 8; #endif - skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin)); - } - - 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); + s->last_buf_size <<= 3; + for (gr = 0, ch = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++, ch = 0) { + for (; ch < s->nb_channels && (s->last_buf_size >> 3) < main_data_begin; ch++) { + g = &s->granules[ch][gr]; + s->last_buf_size += 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; } + } + skip_bits_long(&s->gb, s->last_buf_size - 8 * main_data_begin); + 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; + } + } else { + gr = ch = 0; + } + for (; gr < nb_granules; gr++, ch = 0) { + for (; ch < s->nb_channels; ch++) { + g = &s->granules[ch][gr]; bits_pos = get_bits_count(&s->gb); if (!s->lsf) { -- cgit v1.2.3