diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2018-06-22 21:45:59 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2018-07-08 19:45:47 +0200 |
commit | 2a30376e5095feafced45964b0cc8fb507fdff61 (patch) | |
tree | 13fb66847d7c8c4a8beef83d2aa0624722723cf1 /libavcodec/h264_parser.c | |
parent | be9424966fff829e04d6f6f9c9cc5ca298993ece (diff) | |
download | ffmpeg-2a30376e5095feafced45964b0cc8fb507fdff61.tar.gz |
avcodec/h264_parser: Reduce needed history for parsing mb index
This fixes a bug/regression with very small packets
Fixes: output_file
Regression since: 0782fb6bcb32fe3ab956a99af4cc472ff81da0c2
Reported-by: Thierry Foucu <tfoucu@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit d25c945247979a88fac6bb3b7a26370262b96ef1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/h264_parser.c')
-rw-r--r-- | libavcodec/h264_parser.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 7ac6a5f0be..c3ca86ef2e 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -121,20 +121,23 @@ static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf, } state = 7; } else { + unsigned int mb, last_mb = p->parse_last_mb; + GetBitContext gb; p->parse_history[p->parse_history_count++] = buf[i]; - if (p->parse_history_count > 5) { - unsigned int mb, last_mb = p->parse_last_mb; - GetBitContext gb; - init_get_bits(&gb, p->parse_history, 8*p->parse_history_count); - p->parse_history_count = 0; - mb= get_ue_golomb_long(&gb); + init_get_bits(&gb, p->parse_history, 8*p->parse_history_count); + mb= get_ue_golomb_long(&gb); + if (get_bits_left(&gb) > 0 || p->parse_history_count > 5) { p->parse_last_mb = mb; if (pc->frame_start_found) { - if (mb <= last_mb) + if (mb <= last_mb) { + i -= p->parse_history_count - 1; + p->parse_history_count = 0; goto found; + } } else pc->frame_start_found = 1; + p->parse_history_count = 0; state = 7; } } @@ -149,7 +152,7 @@ found: pc->frame_start_found = 0; if (p->is_avc) return next_avc; - return i - (state & 5) - 5 * (state > 7); + return i - (state & 5); } static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb, |