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.
This commit is contained in:
Wim Taymans 2014-01-08 14:54:47 +01:00
parent 05eaa6bc1b
commit f8582e27da
3 changed files with 51 additions and 1 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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