From c4d1ffa5c796b3e96077508a1c388c6cec2e8514 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 29 Nov 2005 17:13:44 +0000 Subject: [PATCH] gst/base/gstbasesink.c: Properly handle non GST_FORMAT_TIME segment 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 | 12 ++++++++++ gst/base/gstbasesink.c | 43 ++++++++++++++++++++-------------- gst/elements/gstidentity.c | 12 ++++++---- gst/gstsegment.c | 2 +- libs/gst/base/gstbasesink.c | 43 ++++++++++++++++++++-------------- plugins/elements/gstidentity.c | 12 ++++++---- 6 files changed, 79 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5434196251..a32c3e812a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-11-29 Edward Hervey + + * 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 * docs/gst/gstreamer-sections.txt: diff --git a/gst/base/gstbasesink.c b/gst/base/gstbasesink.c index d1db11c574..2f143dd97b 100644 --- a/gst/base/gstbasesink.c +++ b/gst/base/gstbasesink.c @@ -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 { diff --git a/gst/elements/gstidentity.c b/gst/elements/gstidentity.c index ec16596ee5..a4ede21841 100644 --- a/gst/elements/gstidentity.c +++ b/gst/elements/gstidentity.c @@ -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; diff --git a/gst/gstsegment.c b/gst/gstsegment.c index f1e79bdd18..1161d07043 100644 --- a/gst/gstsegment.c +++ b/gst/gstsegment.c @@ -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) diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index d1db11c574..2f143dd97b 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -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 { diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index ec16596ee5..a4ede21841 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -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;