h264parse: Don't push NALs before we have HEADERS
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 13 Jun 2019 02:19:04 +0000 (22:19 -0400)
committerNicolas Dufresne <nicolas@ndufresne.ca>
Wed, 15 Apr 2020 14:10:16 +0000 (14:10 +0000)
Otherwise we may endup pushing incomplete caps, which cause a renegotiation.
Note that this has the effect that caps are no longer pushed twice in presence
of valid framerate in the headers.

gst/videoparsers/gsth264parse.c

index a8c48ac..7ccdba5 100644 (file)
@@ -231,7 +231,6 @@ gst_h264_parse_reset_frame (GstH264Parse * h264parse)
   h264parse->bidirectional = FALSE;
   h264parse->header = FALSE;
   h264parse->frame_start = FALSE;
-  h264parse->aud_insert = FALSE;
   h264parse->have_sps_in_frame = FALSE;
   h264parse->have_pps_in_frame = FALSE;
   gst_adapter_clear (h264parse->frame_out);
@@ -323,6 +322,8 @@ gst_h264_parse_start (GstBaseParse * parse)
   h264parse->sei_pic_struct_pres_flag = FALSE;
   h264parse->sei_pic_struct = 0;
   h264parse->field_pic_flag = 0;
+  h264parse->aud_needed = TRUE;
+  h264parse->aud_insert = FALSE;
 
   gst_base_parse_set_min_frame_size (parse, 4);
 
@@ -1512,6 +1513,13 @@ gst_h264_parse_handle_frame (GstBaseParse * parse,
       h264parse->aud_needed = FALSE;
     }
 
+    /* Do not push immediatly if we don't have all headers. This ensure that
+     * our caps are complete, avoiding a renegotiation */
+    if (h264parse->align == GST_H264_PARSE_ALIGN_NAL &&
+        !GST_H264_PARSE_STATE_VALID (h264parse,
+            GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS))
+      frame->flags |= GST_BASE_PARSE_FRAME_FLAG_QUEUE;
+
     /* if no next nal, we reached the end of this buffer */
     if (nonext) {
       /* If there is a marker flag, or input is AU, we know this is complete */
@@ -3050,6 +3058,7 @@ gst_h264_parse_pre_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
   } else {
     buffer = frame->buffer;
   }
+  h264parse->aud_insert = FALSE;
 
   if ((event = check_pending_key_unit_event (h264parse->force_key_unit_event,
               &parse->segment, GST_BUFFER_TIMESTAMP (buffer),