pipeline: use reset_time message to reset the start time
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 13 Jun 2012 08:51:04 +0000 (10:51 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 14 Jun 2012 07:04:33 +0000 (09:04 +0200)
Use the new RESET_TIME message to reset the start-time of the pipeline to the
requested time.
Make basesink request a new running-time when the flush-stop message tells it to
insteasd of waiting for preroll.

gst/gstpipeline.c
libs/gst/base/gstbasesink.c

index 38eb09d..34daca3 100644 (file)
@@ -279,12 +279,12 @@ gst_pipeline_get_property (GObject * object, guint prop_id,
 /* set the start_time to 0, this will cause us to select a new base_time and
  * make the running_time start from 0 again. */
 static void
-reset_start_time (GstPipeline * pipeline)
+reset_start_time (GstPipeline * pipeline, GstClockTime start_time)
 {
   GST_OBJECT_LOCK (pipeline);
   if (GST_ELEMENT_START_TIME (pipeline) != GST_CLOCK_TIME_NONE) {
     GST_DEBUG_OBJECT (pipeline, "reset start_time to 0");
-    GST_ELEMENT_START_TIME (pipeline) = 0;
+    GST_ELEMENT_START_TIME (pipeline) = start_time;
     pipeline->priv->last_start_time = -1;
   } else {
     GST_DEBUG_OBJECT (pipeline, "application asked to not reset stream_time");
@@ -476,7 +476,8 @@ gst_pipeline_change_state (GstElement * element, GstStateChange transition)
       break;
     case GST_STATE_CHANGE_READY_TO_PAUSED:
     {
-      reset_start_time (pipeline);
+      /* READY to PAUSED starts running_time from 0 */
+      reset_start_time (pipeline, 0);
       break;
     }
     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
@@ -544,17 +545,15 @@ gst_pipeline_handle_message (GstBin * bin, GstMessage * message)
   GstPipeline *pipeline = GST_PIPELINE_CAST (bin);
 
   switch (GST_MESSAGE_TYPE (message)) {
-    case GST_MESSAGE_ASYNC_DONE:
+    case GST_MESSAGE_RESET_TIME:
     {
-      gboolean reset_time;
+      GstClockTime running_time;
 
-      gst_message_parse_async_done (message, &reset_time);
+      gst_message_parse_reset_time (message, &running_time);
 
       /* reset our running time if we need to distribute a new base_time to the
        * children. */
-      if (reset_time)
-        reset_start_time (pipeline);
-
+      reset_start_time (pipeline, running_time);
       break;
     }
     case GST_MESSAGE_CLOCK_LOST:
index f242f98..7ddadb9 100644 (file)
@@ -261,8 +261,6 @@ struct _GstBaseSinkPrivate
   /* for throttling and QoS */
   GstClockTime earliest_in_time;
   GstClockTime throttle_time;
-
-  gboolean reset_time;
 };
 
 #define DO_RUNNING_AVG(avg,val,size) (((val) + ((size)-1) * (avg)) / (size))
@@ -1408,7 +1406,6 @@ gst_base_sink_commit_state (GstBaseSink * basesink)
   gboolean post_paused = FALSE;
   gboolean post_async_done = FALSE;
   gboolean post_playing = FALSE;
-  gboolean reset_time;
 
   /* we are certainly not playing async anymore now */
   basesink->playing_async = FALSE;
@@ -1418,8 +1415,6 @@ gst_base_sink_commit_state (GstBaseSink * basesink)
   next = GST_STATE_NEXT (basesink);
   pending = GST_STATE_PENDING (basesink);
   post_pending = pending;
-  reset_time = basesink->priv->reset_time;
-  basesink->priv->reset_time = FALSE;
 
   switch (pending) {
     case GST_STATE_PLAYING:
@@ -1470,7 +1465,7 @@ gst_base_sink_commit_state (GstBaseSink * basesink)
   if (post_async_done) {
     GST_DEBUG_OBJECT (basesink, "posting async-done message");
     gst_element_post_message (GST_ELEMENT_CAST (basesink),
-        gst_message_new_async_done (GST_OBJECT_CAST (basesink), reset_time));
+        gst_message_new_async_done (GST_OBJECT_CAST (basesink), FALSE));
   }
   if (post_playing) {
     GST_DEBUG_OBJECT (basesink, "posting PLAYING state change message");
@@ -2003,8 +1998,8 @@ gst_base_sink_wait_clock (GstBaseSink * sink, GstClockTime time,
   /* FIXME: Casting to GstClockEntry only works because the types
    * are the same */
   if (G_LIKELY (sink->priv->cached_clock_id != NULL
-          && GST_CLOCK_ENTRY_CLOCK ((GstClockEntry *) sink->
-              priv->cached_clock_id) == clock)) {
+          && GST_CLOCK_ENTRY_CLOCK ((GstClockEntry *) sink->priv->
+              cached_clock_id) == clock)) {
     if (!gst_clock_single_shot_id_reinit (clock, sink->priv->cached_clock_id,
             time)) {
       gst_clock_id_unref (sink->priv->cached_clock_id);
@@ -2824,8 +2819,13 @@ gst_base_sink_flush_stop (GstBaseSink * basesink, GstPad * pad,
       gst_segment_init (&basesink->segment, GST_FORMAT_UNDEFINED);
     }
   }
-  basesink->priv->reset_time = reset_time;
   GST_OBJECT_UNLOCK (basesink);
+
+  if (reset_time) {
+    GST_DEBUG_OBJECT (basesink, "posting reset-time message");
+    gst_element_post_message (GST_ELEMENT_CAST (basesink),
+        gst_message_new_reset_time (GST_OBJECT_CAST (basesink), 0));
+  }
 }
 
 static GstFlowReturn
@@ -4643,7 +4643,6 @@ gst_base_sink_change_state (GstElement * element, GstStateChange transition)
       priv->step_unlock = FALSE;
       basesink->need_preroll = TRUE;
       basesink->playing_async = TRUE;
-      basesink->priv->reset_time = FALSE;
       priv->current_sstart = GST_CLOCK_TIME_NONE;
       priv->current_sstop = GST_CLOCK_TIME_NONE;
       priv->eos_rtime = GST_CLOCK_TIME_NONE;