aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDale Curtis <dalecurtis@chromium.org>2012-02-24 13:17:39 -0500
committerAlex Converse <alex.converse@gmail.com>2012-03-06 15:28:00 -0800
commitfeed0c6b6ae31cb3d5af144c74dd2040051780b7 (patch)
treee769923cb71c1b6a2161c76ac07a18a56c15417f
parentd0e53ecff736fd23c985c184051a7ae44529e448 (diff)
downloadffmpeg-feed0c6b6ae31cb3d5af144c74dd2040051780b7.tar.gz
mpegaudiodec: Prevent premature clipping of mp3 input buffer.
Instead of clipping extrasize based on EXTRABYTES, clip based on the amount of buffer actually left. Without this fix, there are warbles and other distortions in the test case below. http://kevincennis.com/mix/assets/sounds/1901_voxfx.mp3 (cherry picked from commit b7165426917f91ebcad84bdff366824f03b32bfe) Signed-off-by: Alex Converse <alex.converse@gmail.com>
-rw-r--r--libavcodec/mpegaudiodec.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index 04c1d9842c..d90257303c 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -40,6 +40,7 @@
#define BACKSTEP_SIZE 512
#define EXTRABYTES 24
+#define LAST_BUF_SIZE 2 * BACKSTEP_SIZE + EXTRABYTES
/* layer 3 "granule" */
typedef struct GranuleDef {
@@ -63,7 +64,7 @@ typedef struct GranuleDef {
typedef struct MPADecodeContext {
MPA_DECODE_HEADER
- uint8_t last_buf[2 * BACKSTEP_SIZE + EXTRABYTES];
+ uint8_t last_buf[LAST_BUF_SIZE];
int last_buf_size;
/* next header (used in free format parsing) */
uint32_t free_format_next_header;
@@ -1378,7 +1379,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, EXTRABYTES);
+ 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);
/* now we get bits from the main_data_begin offset */
av_dlog(s->avctx, "seekback: %d\n", main_data_begin);