summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2014-01-08 14:54:47 +0100
committerWim Taymans <wtaymans@redhat.com>2014-01-15 11:12:28 +0100
commitf8582e27daac69d95073b5fe43f17a6acccfca25 (patch)
tree329db87dafc4e086dc4c8140a9ba93cae4caa98c
parent05eaa6bc1be17d966a9e012b4a916be099bcfeb6 (diff)
downloadgstreamer-f8582e27daac69d95073b5fe43f17a6acccfca25.tar.gz
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.
-rw-r--r--gst/gstsegment.c49
-rw-r--r--gst/gstsegment.h2
-rw-r--r--win32/common/libgstreamer.def1
3 files changed, 51 insertions, 1 deletions
diff --git a/gst/gstsegment.c b/gst/gstsegment.c
index 4a40807a4e..f51af9b00c 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 65f8a62e26..0f08eb5a7e 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 6f8da1a40e..a53d2b5a2a 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