From: Wim Taymans Date: Wed, 8 Jan 2014 13:54:47 +0000 (+0100) Subject: segment: add method to offset the segment running-time X-Git-Tag: 1.3.1~235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc0176e4a072888aec029f008e6ab4357ad09e96;p=platform%2Fupstream%2Fgstreamer.git segment: add method to offset the segment running-time Add a method that can apply an offset to the calculated running-time of a segment. --- diff --git a/gst/gstsegment.c b/gst/gstsegment.c index 3e6677f..86447f3 100644 --- a/gst/gstsegment.c +++ b/gst/gstsegment.c @@ -668,7 +668,6 @@ gst_segment_to_position (const GstSegment * segment, GstFormat format, return result; } - /** * gst_segment_set_running_time: * @segment: a #GstSegment structure. @@ -713,3 +712,51 @@ gst_segment_set_running_time (GstSegment * segment, GstFormat format, return TRUE; } + +/** + * gst_segment_offset_running_time: + * @segment: a #GstSegment structure. + * @format: the format of the segment. + * @offset: the offset to apply in the segment + * + * Adjust the values in @segment so that @offset is applied to all + * future running-time calculations. + * + * Since: 1.4 + * + * Returns: %TRUE if the segment could be updated successfully. If %FALSE is + * returned, @offset is not in @segment. + */ +gboolean +gst_segment_offset_running_time (GstSegment * segment, GstFormat format, + gint64 offset) +{ + g_return_val_if_fail (segment != NULL, FALSE); + g_return_val_if_fail (segment->format == format, FALSE); + + if (offset == 0) + return TRUE; + + if (offset > 0) { + /* positive offset, we can simply apply to the base time */ + segment->base += offset; + } else { + offset = -offset; + /* negative offset, first try to subtract from base */ + if (segment->base > offset) { + segment->base -= offset; + } else { + guint64 position; + + /* subtract all from segment.base, remainder in offset */ + offset -= segment->base; + segment->base = 0; + position = gst_segment_to_position (segment, format, offset); + if (position == -1) + return FALSE; + + segment->offset = position; + } + } + return TRUE; +} diff --git a/gst/gstsegment.h b/gst/gstsegment.h index 0a36f45..c9ec1e4 100644 --- a/gst/gstsegment.h +++ b/gst/gstsegment.h @@ -191,6 +191,8 @@ guint64 gst_segment_to_position (const GstSegment *segment, GstForm gboolean gst_segment_set_running_time (GstSegment *segment, GstFormat format, guint64 running_time); +gboolean gst_segment_offset_running_time (GstSegment *segment, GstFormat format, gint64 offset); + gboolean gst_segment_clip (const GstSegment *segment, GstFormat format, guint64 start, guint64 stop, guint64 *clip_start, guint64 *clip_stop); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index ce8893e..f9f3254 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -1041,6 +1041,7 @@ EXPORTS gst_segment_get_type gst_segment_init gst_segment_new + gst_segment_offset_running_time gst_segment_set_running_time gst_segment_to_position gst_segment_to_running_time