Skip to content
Browse files

Make has_b_frames calculation resiliant to broken files where poc

can decrease by a large increment
  • Loading branch information...
1 parent a1b9b1f commit f9579b5982cfc7a18c189ed62ddf23eb73d95825 Paul Gardiner committed
View
20 mythtv/external/FFmpeg/libavcodec/h264.c
@@ -1238,7 +1238,7 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx)
h->thread_context[0] = h;
h->outputed_poc = h->next_outputed_poc = INT_MIN;
- for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+ for (i = 0; i < MAX_LAST_POCS; i++)
h->last_pocs[i] = INT_MIN;
h->prev_poc_msb = 1 << 16;
h->prev_frame_num = -1;
@@ -1602,7 +1602,7 @@ static void decode_postinit(H264Context *h, int setup_finished)
}
for (i = 0; 1; i++) {
- if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){
+ if(i == MAX_LAST_POCS || cur->poc < h->last_pocs[i]){
if(i)
h->last_pocs[i-1] = cur->poc;
break;
@@ -1610,9 +1610,19 @@ static void decode_postinit(H264Context *h, int setup_finished)
h->last_pocs[i-1]= h->last_pocs[i];
}
}
- out_of_order = MAX_DELAYED_PIC_COUNT - i;
+
+ if (i < 2 || (i < MAX_LAST_POCS && h->last_pocs[i-2] == INT_MIN)) {
+ // poc is less than any value we have recently seen
+ // Broken file. Reset last_pocs
+ for (i = 0; i < MAX_LAST_POCS; i++)
+ h->last_pocs[i] = INT_MIN;
+ h->last_pocs[MAX_LAST_POCS-1] = cur->poc;
+ i = MAX_LAST_POCS;
+ }
+
+ out_of_order = MAX_LAST_POCS - i;
if( cur->f.pict_type == AV_PICTURE_TYPE_B
- || (h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > INT_MIN && h->last_pocs[MAX_DELAYED_PIC_COUNT-1] - h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > 2))
+ || (h->last_pocs[MAX_LAST_POCS-2] > INT_MIN && h->last_pocs[MAX_LAST_POCS-1] - h->last_pocs[MAX_LAST_POCS-2] > 2))
out_of_order = FFMAX(out_of_order, 1);
if(s->avctx->has_b_frames < out_of_order && !h->sps.bitstream_restriction_flag){
av_log(s->avctx, AV_LOG_WARNING, "Increasing reorder buffer to %d\n", out_of_order);
@@ -2592,7 +2602,7 @@ static void idr(H264Context *h)
h->prev_frame_num_offset = 0;
h->prev_poc_msb = 1<<16;
h->prev_poc_lsb = 0;
- for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+ for (i = 0; i < MAX_LAST_POCS; i++)
h->last_pocs[i] = INT_MIN;
}
View
3 mythtv/external/FFmpeg/libavcodec/h264.h
@@ -45,6 +45,7 @@
#define MAX_MMCO_COUNT 66
#define MAX_DELAYED_PIC_COUNT 16
+#define MAX_LAST_POCS (MAX_DELAYED_PIC_COUNT+2)
#define MAX_MBPAIR_SIZE (256*1024) // a tighter bound could be calculated if someone cares about a few bytes
@@ -489,7 +490,7 @@ typedef struct H264Context {
Picture *long_ref[32];
Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture
Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size?
- int last_pocs[MAX_DELAYED_PIC_COUNT];
+ int last_pocs[MAX_LAST_POCS];
Picture *next_output_pic;
int outputed_poc;
int next_outputed_poc;
View
2 mythtv/external/FFmpeg/libavcodec/h264_refs.c
@@ -586,7 +586,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
s->current_picture_ptr->frame_num= 0;
h->mmco_reset = 1;
s->current_picture_ptr->mmco_reset=1;
- for (j = 0; j < MAX_DELAYED_PIC_COUNT; j++)
+ for (j = 0; j < MAX_LAST_POCS; j++)
h->last_pocs[j] = INT_MIN;
break;
default: assert(0);

0 comments on commit f9579b5

Please sign in to comment.
Something went wrong with that request. Please try again.