Skip to content

Commit 26b86e4

Browse files
committed
Support gaps in the frame num.
Fixes at least: MR3_TANDBERG_B.264 MR4_TANDBERG_C.264 MR5_TANDBERG_C.264 Originally committed as revision 14339 to svn://svn.ffmpeg.org/ffmpeg/trunk
1 parent e44e483 commit 26b86e4

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

libavcodec/h264.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,12 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
35393539
pic= remove_long(h, j);
35403540
if(pic) unreference_pic(h, pic, 0);
35413541
}
3542+
s->current_picture_ptr->poc=
3543+
s->current_picture_ptr->field_poc[0]=
3544+
s->current_picture_ptr->field_poc[1]=
3545+
h->poc_lsb=
3546+
h->poc_msb=
3547+
h->frame_num=
35423548
s->current_picture_ptr->frame_num= 0;
35433549
break;
35443550
default: assert(0);
@@ -3599,7 +3605,7 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
35993605
"number of reference frames exceeds max (probably "
36003606
"corrupt input), discarding one\n");
36013607

3602-
if (h->long_ref_count) {
3608+
if (h->long_ref_count && !h->short_ref_count) {
36033609
for (i = 0; i < 16; ++i)
36043610
if (h->long_ref[i])
36053611
break;
@@ -4018,6 +4024,16 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
40184024
}
40194025

40204026
if(h0->current_slice == 0){
4027+
while(h->frame_num != h->prev_frame_num &&
4028+
h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){
4029+
av_log(NULL, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num);
4030+
frame_start(h);
4031+
h->prev_frame_num++;
4032+
h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;
4033+
s->current_picture_ptr->frame_num= h->prev_frame_num;
4034+
execute_ref_pic_marking(h, NULL, 0);
4035+
}
4036+
40214037
/* See if we have a decoded first field looking for a pair... */
40224038
if (s0->first_field) {
40234039
assert(s0->current_picture_ptr);
@@ -7738,7 +7754,7 @@ static int decode_frame(AVCodecContext *avctx,
77387754
//FIXME factorize this with the output code below
77397755
out = h->delayed_pic[0];
77407756
out_idx = 0;
7741-
for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++)
7757+
for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && h->delayed_pic[i]->poc; i++)
77427758
if(h->delayed_pic[i]->poc < out->poc){
77437759
out = h->delayed_pic[i];
77447760
out_idx = i;
@@ -7821,13 +7837,13 @@ static int decode_frame(AVCodecContext *avctx,
78217837
s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
78227838
s->current_picture_ptr->pict_type= s->pict_type;
78237839

7824-
h->prev_frame_num_offset= h->frame_num_offset;
7825-
h->prev_frame_num= h->frame_num;
78267840
if(!s->dropable) {
7841+
execute_ref_pic_marking(h, h->mmco, h->mmco_index);
78277842
h->prev_poc_msb= h->poc_msb;
78287843
h->prev_poc_lsb= h->poc_lsb;
7829-
execute_ref_pic_marking(h, h->mmco, h->mmco_index);
78307844
}
7845+
h->prev_frame_num_offset= h->frame_num_offset;
7846+
h->prev_frame_num= h->frame_num;
78317847

78327848
/*
78337849
* FIXME: Error handling code does not seem to support interlaced
@@ -7887,7 +7903,7 @@ static int decode_frame(AVCodecContext *avctx,
78877903

78887904
out = h->delayed_pic[0];
78897905
out_idx = 0;
7890-
for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++)
7906+
for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && h->delayed_pic[i]->poc; i++)
78917907
if(h->delayed_pic[i]->poc < out->poc){
78927908
out = h->delayed_pic[i];
78937909
out_idx = i;

0 commit comments

Comments
 (0)