h264_sei: Check actual presence of picture timing SEI message
authorMichael Niedermayer <michael@niedermayer.cc>
Wed, 15 Feb 2017 16:34:52 +0000 (11:34 -0500)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Tue, 28 Feb 2017 15:32:50 +0000 (10:32 -0500)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
libavcodec/h264_parser.c
libavcodec/h264_sei.c
libavcodec/h264_sei.h
libavcodec/h264_slice.c

index 6de37c0..22153bd 100644 (file)
@@ -402,7 +402,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
                 }
             }
 
-            if (sps->pic_struct_present_flag) {
+            if (sps->pic_struct_present_flag && p->sei.picture_timing.present) {
                 switch (p->sei.picture_timing.pic_struct) {
                 case SEI_PIC_STRUCT_TOP_FIELD:
                 case SEI_PIC_STRUCT_BOTTOM_FIELD:
@@ -433,7 +433,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
 
             if (p->picture_structure == PICT_FRAME) {
                 s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
-                if (sps->pic_struct_present_flag) {
+                if (sps->pic_struct_present_flag && p->sei.picture_timing.present) {
                     switch (p->sei.picture_timing.pic_struct) {
                     case SEI_PIC_STRUCT_TOP_BOTTOM:
                     case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
index 4bf001a..17f89ce 100644 (file)
@@ -44,6 +44,7 @@ void ff_h264_sei_uninit(H264SEIContext *h)
     h->picture_timing.dpb_output_delay  = 0;
     h->picture_timing.cpb_removal_delay = -1;
 
+    h->picture_timing.present      = 0;
     h->buffering_period.present    = 0;
     h->frame_packing.present       = 0;
     h->display_orientation.present = 0;
@@ -109,6 +110,8 @@ static int decode_picture_timing(H264SEIPictureTiming *h, GetBitContext *gb,
         av_log(logctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n",
                h->ct_type, h->pic_struct);
     }
+
+    h->present = 1;
     return 0;
 }
 
index 58f5ecc..8815aa3 100644 (file)
@@ -50,6 +50,7 @@ typedef enum {
 } SEI_PicStructType;
 
 typedef struct H264SEIPictureTiming {
+    int present;
     SEI_PicStructType pic_struct;
 
     /**
index f1f5fc0..427cbe6 100644 (file)
@@ -1004,7 +1004,7 @@ static int h264_export_frame_props(H264Context *h)
     /* Prioritize picture timing SEI information over used
      * decoding process if it exists. */
 
-    if (sps->pic_struct_present_flag) {
+    if (sps->pic_struct_present_flag && h->sei.picture_timing.present) {
         H264SEIPictureTiming *pt = &h->sei.picture_timing;
         switch (pt->pic_struct) {
         case SEI_PIC_STRUCT_FRAME:
@@ -1049,7 +1049,8 @@ static int h264_export_frame_props(H264Context *h)
         /* Derive top_field_first from field pocs. */
         cur->f->top_field_first = cur->field_poc[0] < cur->field_poc[1];
     } else {
-        if (cur->f->interlaced_frame || sps->pic_struct_present_flag) {
+        if (cur->f->interlaced_frame ||
+            (sps->pic_struct_present_flag && h->sei.picture_timing.present)) {
             /* Use picture timing SEI information. Even if it is a
              * information of a past frame, better than nothing. */
             if (h->sei.picture_timing.pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM ||