asfdemux: fix playback regression in push mode
authorMatej Knopp <matej.knopp@gmail.com>
Mon, 16 Sep 2013 17:38:36 +0000 (19:38 +0200)
committerSebastian Dröge <slomo@circular-chaos.org>
Wed, 18 Sep 2013 16:20:00 +0000 (18:20 +0200)
gst/asfdemux/asfpacket.c
gst/asfdemux/gstasfdemux.c

index 8f6dc23..ecf1e05 100644 (file)
@@ -190,19 +190,6 @@ gst_asf_payload_queue_for_stream (GstASFDemux * demux, AsfPayload * payload,
     GST_BUFFER_FLAG_SET (payload->buf, GST_BUFFER_FLAG_DISCONT);
   }
 
-  /* remember the first queued timestamp for the segment */
-  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (demux->segment_ts) &&
-          GST_CLOCK_TIME_IS_VALID (demux->first_ts))) {
-    GST_DEBUG_OBJECT (demux, "segment ts: %" GST_TIME_FORMAT,
-        GST_TIME_ARGS (demux->first_ts));
-    demux->segment_ts = demux->first_ts;
-    /* always note, but only determines segment when streaming */
-    if (demux->streaming)
-      gst_segment_do_seek (&demux->segment, demux->in_segment.rate,
-          GST_FORMAT_TIME, (GstSeekFlags) demux->segment.flags,
-          GST_SEEK_TYPE_SET, demux->segment_ts, GST_SEEK_TYPE_NONE, 0, NULL);
-  }
-
   g_array_append_vals (stream->payloads, payload, 1);
 }
 
index b64ee40..ec44035 100644 (file)
@@ -1314,6 +1314,23 @@ gst_asf_demux_have_mutually_exclusive_active_stream (GstASFDemux * demux,
 }
 #endif
 
+static void
+gst_asf_demux_check_segment_ts (GstASFDemux * demux, GstClockTime payload_ts)
+{
+  /* remember the first queued timestamp for the segment */
+  if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (demux->segment_ts) &&
+          GST_CLOCK_TIME_IS_VALID (demux->first_ts))) {
+    GST_DEBUG_OBJECT (demux, "segment ts: %" GST_TIME_FORMAT,
+        GST_TIME_ARGS (demux->first_ts));
+    demux->segment_ts = payload_ts;
+    /* always note, but only determines segment when streaming */
+    if (demux->streaming)
+      gst_segment_do_seek (&demux->segment, demux->in_segment.rate,
+          GST_FORMAT_TIME, (GstSeekFlags) demux->segment.flags,
+          GST_SEEK_TYPE_SET, demux->segment_ts, GST_SEEK_TYPE_NONE, 0, NULL);
+  }
+}
+
 static gboolean
 gst_asf_demux_check_first_ts (GstASFDemux * demux, gboolean force)
 {
@@ -1368,6 +1385,8 @@ gst_asf_demux_check_first_ts (GstASFDemux * demux, gboolean force)
     }
   }
 
+  gst_asf_demux_check_segment_ts (demux, 0);
+
   return TRUE;
 }
 
@@ -1505,6 +1524,11 @@ gst_asf_demux_find_stream_with_complete_payload (GstASFDemux * demux)
               || !GST_CLOCK_TIME_IS_VALID (payload->ts)); --last_idx) {
         payload = &g_array_index (stream->payloads, AsfPayload, last_idx);
       }
+
+      /* if this is first payload after seek we might need to update the segment */
+      if (GST_CLOCK_TIME_IS_VALID (payload->ts))
+        gst_asf_demux_check_segment_ts (demux, payload->ts);
+
       if (G_UNLIKELY (GST_CLOCK_TIME_IS_VALID (payload->ts) &&
               (payload->ts < demux->segment.start))) {
         if (G_UNLIKELY ((!demux->accurate) && payload->keyframe)) {
@@ -1558,14 +1582,14 @@ gst_asf_demux_push_complete_payloads (GstASFDemux * demux, gboolean force)
     /* streams are now activated */
   }
 
-  /* wait until we had a chance to "lock on" some payload's timestamp */
-  if (G_UNLIKELY (demux->need_newsegment
-          && !GST_CLOCK_TIME_IS_VALID (demux->segment_ts)))
-    return GST_FLOW_OK;
-
   while ((stream = gst_asf_demux_find_stream_with_complete_payload (demux))) {
     AsfPayload *payload;
 
+    /* wait until we had a chance to "lock on" some payload's timestamp */
+    if (G_UNLIKELY (demux->need_newsegment
+            && !GST_CLOCK_TIME_IS_VALID (demux->segment_ts)))
+      return GST_FLOW_OK;
+
     payload = &g_array_index (stream->payloads, AsfPayload, 0);
 
     /* do we need to send a newsegment event */