diff options
author | Alexander Strange <astrange@ithinksw.com> | 2011-06-02 01:39:56 -0700 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-06-12 18:02:24 +0200 |
commit | 33eac92a3c1aa0f3d0b5bbc6893ed5f646ee527c (patch) | |
tree | 4d72e677ca28f203d16b194d77a905c2435e0032 /libavcodec | |
parent | 53781bf13e47d15f4d9964001af3894a72c513ee (diff) | |
download | ffmpeg-33eac92a3c1aa0f3d0b5bbc6893ed5f646ee527c.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.
(cherry picked from commit 43c0092a80f8212cbb783260bafa157f7b85126e)
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/h264.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c index dfe9d4a6a5..7d54e1c6c1 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -2133,9 +2133,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)){ |