aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Strange <astrange@ithinksw.com>2011-06-12 20:40:00 +0000
committerAnton Khirnov <anton@khirnov.net>2011-06-16 20:51:51 +0200
commit3803af22d8e1092e658110e77db093922ce63e80 (patch)
treeb2e4647ce2477009a13ba649951fa238ed3149d3
parentc98b928fa7dea6418c24a163e7bcd36b0eb922a3 (diff)
downloadffmpeg-3803af22d8e1092e658110e77db093922ce63e80.tar.gz
h264: Complexify frame num gap shortening code
By observation it did not seem to handle prev_frame_num > frame_num. This does not affect any files I have. Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net>
-rw-r--r--libavcodec/h264.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 0aac09754a..ad591269c6 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2681,9 +2681,20 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME;
if(h0->current_slice == 0){
- if(h->frame_num != h->prev_frame_num &&
- (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num) < (h->frame_num - h->sps.ref_frame_count))
- h->prev_frame_num = h->frame_num - h->sps.ref_frame_count - 1;
+ // Shorten frame num gaps so we don't have to allocate reference frames just to throw them away
+ if(h->frame_num != h->prev_frame_num) {
+ int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num;
+
+ if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num;
+
+ if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {
+ unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;
+ if (unwrap_prev_frame_num < 0)
+ unwrap_prev_frame_num += max_frame_num;
+
+ h->prev_frame_num = unwrap_prev_frame_num;
+ }
+ }
while(h->frame_num != h->prev_frame_num &&
h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){