legacyh264parse: Delay pushing buffers until we have width/height
authorEdward Hervey <edward.hervey@collabora.co.uk>
Thu, 19 May 2011 10:55:30 +0000 (12:55 +0200)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Tue, 31 May 2011 10:58:10 +0000 (12:58 +0200)
gst/h264parse/gsth264parse.c

index 9c751a1..514a739 100644 (file)
@@ -1602,6 +1602,8 @@ gst_h264_parse_push_codec_buffer (GstH264Parse * h264parse, GstBuffer * nal,
 static GstFlowReturn
 gst_h264_parse_push_buffer (GstH264Parse * h264parse, GstBuffer * buf)
 {
+  GstFlowReturn res = GST_FLOW_OK;
+
   /* We can send pending events if this is the first call, since we now have
    * caps for the srcpad */
   if (G_UNLIKELY (h264parse->pending_segment != NULL)) {
@@ -1619,6 +1621,33 @@ gst_h264_parse_push_buffer (GstH264Parse * h264parse, GstBuffer * buf)
     }
   }
 
+  if (G_UNLIKELY (h264parse->width == 0 || h264parse->height == 0)) {
+    GST_DEBUG ("Delaying actual push until we are configured");
+    h264parse->gather = g_list_append (h264parse->gather, buf);
+    goto beach;
+  }
+
+  if (G_UNLIKELY (h264parse->gather)) {
+    GList *pendingbuffers = h264parse->gather;
+    GList *tmp;
+
+    GST_DEBUG ("Pushing out pending buffers");
+
+    /* Yes, we're recursively calling in... */
+    h264parse->gather = NULL;
+    for (tmp = pendingbuffers; tmp; tmp = tmp->next) {
+      res = gst_h264_parse_push_buffer (h264parse, (GstBuffer *) tmp->data);
+      if (res != GST_FLOW_OK && res != GST_FLOW_NOT_LINKED)
+        break;
+    }
+    g_list_free (pendingbuffers);
+
+    if (res != GST_FLOW_OK && res != GST_FLOW_NOT_LINKED) {
+      gst_buffer_unref (buf);
+      goto beach;
+    }
+  }
+
   /* start of picture is good time to slip in codec_data NALUs
    * (when outputting NALS and transforming to bytestream) */
   if (G_UNLIKELY (h264parse->codec_nals && h264parse->picture_start)) {
@@ -1740,7 +1769,10 @@ gst_h264_parse_push_buffer (GstH264Parse * h264parse, GstBuffer * buf)
   }
 
   gst_buffer_set_caps (buf, h264parse->src_caps);
-  return gst_pad_push (h264parse->srcpad, buf);
+  res = gst_pad_push (h264parse->srcpad, buf);
+
+beach:
+  return res;
 }
 
 /* takes over ownership of nal and returns fresh buffer */