gdouble rate, gdouble applied_rate, GstFormat format, gint64 start,
gint64 stop, gint64 time)
{
- gint64 duration;
+ gint64 duration, last_stop;
g_return_if_fail (rate != 0.0);
g_return_if_fail (applied_rate != 0.0);
else
duration = 0;
}
+ /* update last_stop to be a valid value in the updated segment */
+ if (start > segment->last_stop)
+ last_stop = start;
+ else if (stop != -1 && stop < segment->last_stop)
+ last_stop = stop;
+ else
+ last_stop = segment->last_stop;
} else {
/* the new segment has to be aligned with the old segment.
* We first update the accumulated time of the previous
* segment. the accumulated time is used when syncing to the
- * clock.
- */
+ * clock. */
if (segment->stop != -1) {
duration = segment->stop - segment->start;
} else if (segment->last_stop != -1) {
g_warning ("closing segment of unknown duration, assuming duration of 0");
duration = 0;
}
+ /* position the last_stop to the next expected position in the new segment,
+ * which is the start or the stop of the segment */
+ if (rate > 0.0)
+ last_stop = start;
+ else
+ last_stop = stop;
}
/* use previous rate to calculate duration */
if (segment->abs_rate != 1.0)
segment->abs_rate = ABS (rate);
segment->applied_rate = applied_rate;
segment->start = start;
- segment->last_stop = start;
+ segment->last_stop = last_stop;
segment->stop = stop;
segment->time = time;
}
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
+ fail_unless (segment.last_stop == 0);
/* update, nothing changes */
gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
+ fail_unless (segment.last_stop == 0);
/* update */
gst_segment_set_newsegment (&segment, TRUE, 1.0,
fail_unless (segment.stop == -1);
fail_unless (segment.time == 100);
fail_unless (segment.accum == 100);
+ fail_unless (segment.last_stop == 100);
/* last_stop 0, accum does not change */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200);
+ fail_unless (segment.last_stop == 200);
+
/* last_stop 200, accum changes */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 300);
-
+ fail_unless (segment.last_stop == 0);
}
GST_END_TEST;
fail_unless (segment.last_stop == 0);
fail_unless (segment.duration == -1);
- /* do an update */
- gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, 300, 0);
+ /* assume we advanced to position 40 */
+ gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 40);
+ fail_unless (segment.last_stop == 40);
- fail_unless (segment.start == 0);
+ /* do an update to the start, last_stop is unchanged because it's bigger */
+ gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 20, 200,
+ 20);
+
+ fail_unless (segment.start == 20);
+ fail_unless (segment.stop == 200);
+ fail_unless (segment.time == 20);
+ fail_unless (segment.accum == 20);
+ fail_unless (segment.last_stop == 40);
+
+ /* do an update past our last_stop, it should be updated now */
+ gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 50, 300,
+ 50);
+
+ fail_unless (segment.start == 50);
fail_unless (segment.stop == 300);
- fail_unless (segment.time == 0);
- fail_unless (segment.accum == 0);
+ fail_unless (segment.time == 50);
+ fail_unless (segment.accum == 50);
+ fail_unless (segment.last_stop == 50);
/* and a new accumulated one */
gst_segment_set_newsegment (&segment, FALSE, 1.0,
fail_unless (segment.time == 200);
/* accumulated 100 of previous segment to make 200 */
fail_unless (segment.accum == 200);
- fail_unless (segment.last_stop == 0);
+ fail_unless (segment.last_stop == 200);
fail_unless (segment.duration == -1);
/* invalid time gives invalid result */
fail_unless (segment.stop == 200);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 400);
- fail_unless (segment.last_stop == 0);
+ fail_unless (segment.last_stop == 200);
fail_unless (segment.duration == -1);
/* invalid time gives invalid result */
fail_unless (segment.stop == 200);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
- fail_unless (segment.last_stop == 0);
+ fail_unless (segment.last_stop == 200);
fail_unless (segment.duration == -1);
/* invalid time gives invalid result */
fail_unless (segment.stop == 150);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 50);
- fail_unless (segment.last_stop == 0);
+ fail_unless (segment.last_stop == 150);
fail_unless (segment.duration == -1);
result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150);
fail_unless (segment.stop == 200);
fail_unless (segment.time == 100);
fail_unless (segment.accum == 50);
- fail_unless (segment.last_stop == 100);
+ fail_unless (segment.last_stop == 150);
fail_unless (segment.duration == -1);
result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
fail_unless (segment.stop == 200);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
- fail_unless (segment.last_stop == 0);
+ fail_unless (segment.last_stop == 200);
fail_unless (segment.duration == -1);
/* invalid time gives invalid result */
fail_unless (segment.stop == 200);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
- fail_unless (segment.last_stop == 150);
+ fail_unless (segment.last_stop == 200);
fail_unless (segment.duration == -1);
/* new segment, this accumulates 50. */