[FFmpeg-cvslog] Merge commit '74b1bf632f125a795e66e5fd0a060b9c7c55b7a3'
Hendrik Leppkes
git at videolan.org
Sun Jun 26 20:23:50 CEST 2016
ffmpeg | branch: release/3.1 | Hendrik Leppkes <h.leppkes at gmail.com> | Sun Jun 26 14:31:53 2016 +0200| [314e6086315dafc2008839238b0d7b053ce009c4] | committer: Hendrik Leppkes
Merge commit '74b1bf632f125a795e66e5fd0a060b9c7c55b7a3'
* commit '74b1bf632f125a795e66e5fd0a060b9c7c55b7a3':
mp3: Make the extrasize explicit
Merged-by: Hendrik Leppkes <h.leppkes at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=314e6086315dafc2008839238b0d7b053ce009c4
---
libavcodec/mpegaudiodec_template.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 91c4051..1114428 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -71,6 +71,7 @@ typedef struct MPADecodeContext {
MPA_DECODE_HEADER
uint8_t last_buf[LAST_BUF_SIZE];
int last_buf_size;
+ int extrasize;
/* next header (used in free format parsing) */
uint32_t free_format_next_header;
GetBitContext gb;
@@ -819,9 +820,10 @@ static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g,
static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos,
int *end_pos2)
{
- if (s->in_gb.buffer && *pos >= s->gb.size_in_bits) {
+ if (s->in_gb.buffer && *pos >= s->gb.size_in_bits - s->extrasize * 8) {
s->gb = s->in_gb;
s->in_gb.buffer = NULL;
+ s->extrasize = 0;
av_assert2((get_bits_count(&s->gb) & 7) == 0);
skip_bits_long(&s->gb, *pos - *end_pos);
*end_pos2 =
@@ -853,7 +855,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
int i;
int last_pos, bits_left;
VLC *vlc;
- int end_pos = FFMIN(end_pos2, s->gb.size_in_bits);
+ int end_pos = FFMIN(end_pos2, s->gb.size_in_bits - s->extrasize * 8);
/* low frequencies (called big values) */
s_index = 0;
@@ -1387,18 +1389,16 @@ 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);
+ s->extrasize = av_clip((get_bits_left(&s->gb) >> 3) - s->extrasize, 0,
+ FFMAX(0, LAST_BUF_SIZE - s->last_buf_size));
av_assert1((get_bits_count(&s->gb) & 7) == 0);
/* now we get bits from the main_data_begin offset */
ff_dlog(s->avctx, "seekback:%d, lastbuf:%d\n",
main_data_begin, s->last_buf_size);
- memcpy(s->last_buf + s->last_buf_size, ptr, extrasize);
+ memcpy(s->last_buf + s->last_buf_size, ptr, s->extrasize);
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 += FFMAX(extrasize, LAST_BUF_SIZE - s->last_buf_size) * 8;
-#endif
+ init_get_bits(&s->gb, s->last_buf, (s->last_buf_size + s->extrasize) * 8);
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++) {
@@ -1409,15 +1409,17 @@ static int mp_decode_layer3(MPADecodeContext *s)
}
}
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);
+ if (skip >= s->gb.size_in_bits - s->extrasize * 8 && s->in_gb.buffer) {
+ skip_bits_long(&s->in_gb, skip - s->gb.size_in_bits + s->extrasize * 8);
s->gb = s->in_gb;
s->in_gb.buffer = NULL;
+ s->extrasize = 0;
} else {
skip_bits_long(&s->gb, skip);
}
} else {
gr = 0;
+ s->extrasize = 0;
}
for (; gr < nb_granules; gr++) {
@@ -1582,7 +1584,7 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples,
s->last_buf_size=0;
if (s->in_gb.buffer) {
align_get_bits(&s->gb);
- i = get_bits_left(&s->gb)>>3;
+ i = (get_bits_left(&s->gb) >> 3) - s->extrasize;
if (i >= 0 && i <= BACKSTEP_SIZE) {
memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);
s->last_buf_size=i;
@@ -1590,12 +1592,12 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples,
av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);
s->gb = s->in_gb;
s->in_gb.buffer = NULL;
+ s->extrasize = 0;
}
align_get_bits(&s->gb);
av_assert1((get_bits_count(&s->gb) & 7) == 0);
- i = get_bits_left(&s->gb) >> 3;
-
+ i = (get_bits_left(&s->gb) >> 3) - s->extrasize;
if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) {
if (i < 0)
av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i);
======================================================================
diff --cc libavcodec/mpegaudiodec_template.c
index 91c4051,9bfba6f..1114428
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@@ -819,10 -799,11 +820,11 @@@ static void exponents_from_scale_factor
static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos,
int *end_pos2)
{
- if (s->in_gb.buffer && *pos >= s->gb.size_in_bits) {
+ if (s->in_gb.buffer && *pos >= s->gb.size_in_bits - s->extrasize * 8) {
s->gb = s->in_gb;
s->in_gb.buffer = NULL;
+ s->extrasize = 0;
- 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;
@@@ -1387,8 -1356,9 +1389,9 @@@ static int mp_decode_layer3(MPADecodeCo
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);
+ s->extrasize = av_clip((get_bits_left(&s->gb) >> 3) - s->extrasize, 0,
+ FFMAX(0, LAST_BUF_SIZE - s->last_buf_size));
- assert((get_bits_count(&s->gb) & 7) == 0);
+ av_assert1((get_bits_count(&s->gb) & 7) == 0);
/* now we get bits from the main_data_begin offset */
ff_dlog(s->avctx, "seekback:%d, lastbuf:%d\n",
main_data_begin, s->last_buf_size);
@@@ -1593,9 -1566,8 +1596,8 @@@ static int mp_decode_frame(MPADecodeCon
}
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;
-
+ i = (get_bits_left(&s->gb) >> 3) - s->extrasize;
if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) {
if (i < 0)
av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i);
More information about the ffmpeg-cvslog
mailing list