multipartdemux: timestamp output buffers based on first input buffer that provided...
authorTim-Philipp Müller <tim@centricular.net>
Fri, 23 Aug 2013 14:29:28 +0000 (15:29 +0100)
committerTim-Philipp Müller <tim@centricular.net>
Fri, 23 Aug 2013 14:57:46 +0000 (15:57 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=637754

gst/multipart/multipartdemux.c
gst/multipart/multipartdemux.h

index 4889e45..895a8f3 100644 (file)
@@ -301,6 +301,7 @@ gst_multipart_find_pad_by_mime (GstMultipartDemux * demux, gchar * mime,
     mppad->pad = pad;
     mppad->mime = g_strdup (mime);
     mppad->last_ret = GST_FLOW_OK;
+    mppad->last_ts = GST_CLOCK_TIME_NONE;
 
     demux->srcpads = g_slist_prepend (demux->srcpads, mppad);
     demux->numpads++;
@@ -536,7 +537,6 @@ gst_multipart_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
 {
   GstMultipartDemux *multipart;
   GstAdapter *adapter;
-  GstClockTime timestamp;
   gint size = 1;
   GstFlowReturn res;
 
@@ -545,8 +545,6 @@ gst_multipart_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
 
   res = GST_FLOW_OK;
 
-  timestamp = GST_BUFFER_TIMESTAMP (buf);
-
   if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT)) {
     gst_adapter_clear (adapter);
   }
@@ -578,9 +576,13 @@ gst_multipart_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
       GST_DEBUG_OBJECT (multipart, "skipping empty content.");
       gst_adapter_flush (adapter, size - datalen);
     } else {
+      GstClockTime ts;
+
       srcpad =
           gst_multipart_find_pad_by_mime (multipart,
           multipart->mime_type, &created);
+
+      ts = gst_adapter_prev_pts (adapter, NULL);
       outbuf = gst_adapter_take_buffer (adapter, datalen);
       gst_adapter_flush (adapter, size - datalen);
 
@@ -596,11 +598,21 @@ gst_multipart_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
         tags = gst_tag_list_new (GST_TAG_CONTAINER_FORMAT, "Multipart", NULL);
         gst_tag_list_set_scope (tags, GST_TAG_SCOPE_GLOBAL);
         gst_pad_push_event (srcpad->pad, gst_event_new_tag (tags));
+      }
 
-        GST_BUFFER_TIMESTAMP (outbuf) = 0;
+      outbuf = gst_buffer_make_writable (outbuf);
+      if (srcpad->last_ts == GST_CLOCK_TIME_NONE || srcpad->last_ts != ts) {
+        GST_BUFFER_TIMESTAMP (outbuf) = ts;
+        srcpad->last_ts = ts;
       } else {
-        GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
+        GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
       }
+
+      if (created)
+        GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
+      else
+        GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DISCONT);
+
       GST_DEBUG_OBJECT (multipart,
           "pushing buffer with timestamp %" GST_TIME_FORMAT,
           GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
index f4ac4e2..a37d3e5 100644 (file)
@@ -51,6 +51,8 @@ typedef struct
 
   gchar *mime;
 
+  GstClockTime  last_ts;        /* last timestamp to make sure we don't send
+                                 * two buffers with the same timestamp */
   GstFlowReturn last_ret;
 }
 GstMultipartPad;