gst/base/gstbasesink.c: Properly handle non GST_FORMAT_TIME segment
authorEdward Hervey <bilboed@bilboed.com>
Tue, 29 Nov 2005 17:13:44 +0000 (17:13 +0000)
committerEdward Hervey <bilboed@bilboed.com>
Tue, 29 Nov 2005 17:13:44 +0000 (17:13 +0000)
Original commit message from CVS:
* gst/base/gstbasesink.c: (gst_base_sink_handle_object),
(gst_base_sink_event), (gst_base_sink_do_sync),
(gst_base_sink_activate_pull), (gst_base_sink_change_state):
Properly handle non GST_FORMAT_TIME segment
* gst/elements/gstidentity.c: (gst_identity_transform_ip):
Properly handle non GST_FORMAT_TIME segment
* gst/gstsegment.c:
This function is valid if the accumulator is 0 and the format
is different from the requested format.

ChangeLog
gst/base/gstbasesink.c
gst/elements/gstidentity.c
gst/gstsegment.c
libs/gst/base/gstbasesink.c
plugins/elements/gstidentity.c

index 5434196..a32c3e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-11-29  Edward Hervey  <edward@fluendo.com>
+
+       * gst/base/gstbasesink.c: (gst_base_sink_handle_object),
+       (gst_base_sink_event), (gst_base_sink_do_sync),
+       (gst_base_sink_activate_pull), (gst_base_sink_change_state):
+       Properly handle non GST_FORMAT_TIME segment
+       * gst/elements/gstidentity.c: (gst_identity_transform_ip):
+       Properly handle non GST_FORMAT_TIME segment
+       * gst/gstsegment.c:
+       This function is valid if the accumulator is 0 and the format
+       is different from the requested format.
+       
 2005-11-29  Jan Schmidt  <thaytan@mad.scientist.com>
 
        * docs/gst/gstreamer-sections.txt:
index d1db11c..2f143dd 100644 (file)
@@ -620,7 +620,8 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
           ", end: %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
           GST_TIME_ARGS (end));
 
-      if (GST_CLOCK_TIME_IS_VALID (start)) {
+      if (GST_CLOCK_TIME_IS_VALID (start) &&
+          (basesink->segment.format == GST_FORMAT_TIME)) {
         if (!gst_segment_clip (&basesink->segment, GST_FORMAT_TIME,
                 (gint64) start, (gint64) end, NULL, NULL))
           goto dropping;
@@ -827,7 +828,7 @@ gst_base_sink_event (GstPad * pad, GstEvent * event)
       basesink->flushing = FALSE;
       GST_OBJECT_UNLOCK (basesink);
       /* we need new segment info after the flush. */
-      gst_segment_init (&basesink->segment, GST_FORMAT_TIME);
+      gst_segment_init (&basesink->segment, GST_FORMAT_UNDEFINED);
 
       GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
       gst_event_unref (event);
@@ -925,18 +926,24 @@ gst_base_sink_do_sync (GstBaseSink * basesink, GstBuffer * buffer)
     goto done;
   }
 
-  /* save last times seen. */
-  if (GST_CLOCK_TIME_IS_VALID (end))
-    gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
-        (gint64) end);
-  else
-    gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
-        (gint64) start);
+  if (basesink->segment.format == GST_FORMAT_TIME) {
+    /* save last times seen. */
+    if (GST_CLOCK_TIME_IS_VALID (end))
+      gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
+          (gint64) end);
+    else
+      gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
+          (gint64) start);
 
-  /* clip */
-  if (!gst_segment_clip (&basesink->segment, GST_FORMAT_TIME,
-          (gint64) start, (gint64) end, &cstart, &cend))
-    goto out_of_segment;
+    /* clip */
+    if (!gst_segment_clip (&basesink->segment, GST_FORMAT_TIME,
+            (gint64) start, (gint64) end, &cstart, &cend))
+      goto out_of_segment;
+  } else {
+    /* no clipping for formats different from GST_FORMAT_TIME */
+    cstart = start;
+    cend = end;
+  }
 
   if (!basesink->sync) {
     GST_DEBUG_OBJECT (basesink, "no need to sync");
@@ -944,7 +951,9 @@ gst_base_sink_do_sync (GstBaseSink * basesink, GstBuffer * buffer)
   }
 
   /* now do clocking */
-  if (GST_ELEMENT_CLOCK (basesink)) {
+  if (GST_ELEMENT_CLOCK (basesink)
+      && ((basesink->segment.format == GST_FORMAT_TIME)
+          || (basesink->segment.accum == 0))) {
     GstClockTime base_time;
     GstClockTimeDiff stream_start, stream_end;
 
@@ -1261,7 +1270,7 @@ gst_base_sink_activate_pull (GstPad * pad, gboolean active)
       } else {
         if (gst_pad_activate_pull (peer, TRUE)) {
           basesink->have_newsegment = TRUE;
-          gst_segment_init (&basesink->segment, GST_FORMAT_TIME);
+          gst_segment_init (&basesink->segment, GST_FORMAT_UNDEFINED);
 
           /* set the pad mode before starting the task so that it's in the
              correct state for the new thread... */
@@ -1460,7 +1469,7 @@ gst_base_sink_change_state (GstElement * element, GstStateChange transition)
       GST_DEBUG_OBJECT (basesink, "READY to PAUSED, need preroll to FALSE");
       basesink->need_preroll = TRUE;
       GST_PAD_PREROLL_UNLOCK (basesink->sinkpad);
-      gst_segment_init (&basesink->segment, GST_FORMAT_TIME);
+      gst_segment_init (&basesink->segment, GST_FORMAT_UNDEFINED);
       basesink->have_newsegment = FALSE;
       ret = GST_STATE_CHANGE_ASYNC;
       break;
@@ -1490,7 +1499,7 @@ gst_base_sink_change_state (GstElement * element, GstStateChange transition)
         /* queue a commit_state */
         basesink->need_preroll = TRUE;
         GST_DEBUG_OBJECT (basesink,
-            "PAUSED to PLAYING, !eos, !have_preroll, need preroll to FALSE");
+            "PAUSED to PLAYING, !eos, !have_preroll, need preroll to TRUE");
         ret = GST_STATE_CHANGE_ASYNC;
         /* we know it's not waiting, no need to signal */
       } else {
index ec16596..a4ede21 100644 (file)
@@ -339,7 +339,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
 {
   GstFlowReturn ret = GST_FLOW_OK;
   GstIdentity *identity = GST_IDENTITY (trans);
-  GstClockTime runtimestamp;
+  GstClockTime runtimestamp = 0LL;
 
   if (identity->check_perfect)
     gst_identity_check_perfect (identity, buf);
@@ -403,10 +403,11 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
   g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
       buf);
 
-  runtimestamp = gst_segment_to_running_time (&trans->segment,
-      GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
+  if (trans->segment.format == GST_FORMAT_TIME)
+    runtimestamp = gst_segment_to_running_time (&trans->segment,
+        GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
 
-  if (identity->sync) {
+  if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
     GstClock *clock;
 
     GST_OBJECT_LOCK (identity);
@@ -439,7 +440,8 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
   if (identity->sleep_time && ret == GST_FLOW_OK)
     g_usleep (identity->sleep_time);
 
-  if (identity->single_segment && ret == GST_FLOW_OK)
+  if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
+      && (ret == GST_FLOW_OK))
     GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
 
   return ret;
index f1e79bd..1161d07 100644 (file)
@@ -404,7 +404,7 @@ gst_segment_to_running_time (GstSegment * segment, GstFormat format,
 
   if (segment->format == GST_FORMAT_UNDEFINED)
     segment->format = format;
-  else
+  else if (segment->accum)
     g_return_val_if_fail (segment->format == format, -1);
 
   if (position != -1)
index d1db11c..2f143dd 100644 (file)
@@ -620,7 +620,8 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
           ", end: %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
           GST_TIME_ARGS (end));
 
-      if (GST_CLOCK_TIME_IS_VALID (start)) {
+      if (GST_CLOCK_TIME_IS_VALID (start) &&
+          (basesink->segment.format == GST_FORMAT_TIME)) {
         if (!gst_segment_clip (&basesink->segment, GST_FORMAT_TIME,
                 (gint64) start, (gint64) end, NULL, NULL))
           goto dropping;
@@ -827,7 +828,7 @@ gst_base_sink_event (GstPad * pad, GstEvent * event)
       basesink->flushing = FALSE;
       GST_OBJECT_UNLOCK (basesink);
       /* we need new segment info after the flush. */
-      gst_segment_init (&basesink->segment, GST_FORMAT_TIME);
+      gst_segment_init (&basesink->segment, GST_FORMAT_UNDEFINED);
 
       GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
       gst_event_unref (event);
@@ -925,18 +926,24 @@ gst_base_sink_do_sync (GstBaseSink * basesink, GstBuffer * buffer)
     goto done;
   }
 
-  /* save last times seen. */
-  if (GST_CLOCK_TIME_IS_VALID (end))
-    gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
-        (gint64) end);
-  else
-    gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
-        (gint64) start);
+  if (basesink->segment.format == GST_FORMAT_TIME) {
+    /* save last times seen. */
+    if (GST_CLOCK_TIME_IS_VALID (end))
+      gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
+          (gint64) end);
+    else
+      gst_segment_set_last_stop (&basesink->segment, GST_FORMAT_TIME,
+          (gint64) start);
 
-  /* clip */
-  if (!gst_segment_clip (&basesink->segment, GST_FORMAT_TIME,
-          (gint64) start, (gint64) end, &cstart, &cend))
-    goto out_of_segment;
+    /* clip */
+    if (!gst_segment_clip (&basesink->segment, GST_FORMAT_TIME,
+            (gint64) start, (gint64) end, &cstart, &cend))
+      goto out_of_segment;
+  } else {
+    /* no clipping for formats different from GST_FORMAT_TIME */
+    cstart = start;
+    cend = end;
+  }
 
   if (!basesink->sync) {
     GST_DEBUG_OBJECT (basesink, "no need to sync");
@@ -944,7 +951,9 @@ gst_base_sink_do_sync (GstBaseSink * basesink, GstBuffer * buffer)
   }
 
   /* now do clocking */
-  if (GST_ELEMENT_CLOCK (basesink)) {
+  if (GST_ELEMENT_CLOCK (basesink)
+      && ((basesink->segment.format == GST_FORMAT_TIME)
+          || (basesink->segment.accum == 0))) {
     GstClockTime base_time;
     GstClockTimeDiff stream_start, stream_end;
 
@@ -1261,7 +1270,7 @@ gst_base_sink_activate_pull (GstPad * pad, gboolean active)
       } else {
         if (gst_pad_activate_pull (peer, TRUE)) {
           basesink->have_newsegment = TRUE;
-          gst_segment_init (&basesink->segment, GST_FORMAT_TIME);
+          gst_segment_init (&basesink->segment, GST_FORMAT_UNDEFINED);
 
           /* set the pad mode before starting the task so that it's in the
              correct state for the new thread... */
@@ -1460,7 +1469,7 @@ gst_base_sink_change_state (GstElement * element, GstStateChange transition)
       GST_DEBUG_OBJECT (basesink, "READY to PAUSED, need preroll to FALSE");
       basesink->need_preroll = TRUE;
       GST_PAD_PREROLL_UNLOCK (basesink->sinkpad);
-      gst_segment_init (&basesink->segment, GST_FORMAT_TIME);
+      gst_segment_init (&basesink->segment, GST_FORMAT_UNDEFINED);
       basesink->have_newsegment = FALSE;
       ret = GST_STATE_CHANGE_ASYNC;
       break;
@@ -1490,7 +1499,7 @@ gst_base_sink_change_state (GstElement * element, GstStateChange transition)
         /* queue a commit_state */
         basesink->need_preroll = TRUE;
         GST_DEBUG_OBJECT (basesink,
-            "PAUSED to PLAYING, !eos, !have_preroll, need preroll to FALSE");
+            "PAUSED to PLAYING, !eos, !have_preroll, need preroll to TRUE");
         ret = GST_STATE_CHANGE_ASYNC;
         /* we know it's not waiting, no need to signal */
       } else {
index ec16596..a4ede21 100644 (file)
@@ -339,7 +339,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
 {
   GstFlowReturn ret = GST_FLOW_OK;
   GstIdentity *identity = GST_IDENTITY (trans);
-  GstClockTime runtimestamp;
+  GstClockTime runtimestamp = 0LL;
 
   if (identity->check_perfect)
     gst_identity_check_perfect (identity, buf);
@@ -403,10 +403,11 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
   g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
       buf);
 
-  runtimestamp = gst_segment_to_running_time (&trans->segment,
-      GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
+  if (trans->segment.format == GST_FORMAT_TIME)
+    runtimestamp = gst_segment_to_running_time (&trans->segment,
+        GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
 
-  if (identity->sync) {
+  if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
     GstClock *clock;
 
     GST_OBJECT_LOCK (identity);
@@ -439,7 +440,8 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
   if (identity->sleep_time && ret == GST_FLOW_OK)
     g_usleep (identity->sleep_time);
 
-  if (identity->single_segment && ret == GST_FLOW_OK)
+  if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
+      && (ret == GST_FLOW_OK))
     GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
 
   return ret;