#include <gst/check/gstcheck.h>
+static void
+check_times (GstSegment * segment, guint64 position, guint64 stream_time,
+ guint64 running_time)
+{
+ guint64 st, rt;
+
+ st = gst_segment_to_stream_time (segment, segment->format, position);
+ rt = gst_segment_to_running_time (segment, segment->format, position);
+
+ fail_unless (st == stream_time);
+ fail_unless (rt == running_time);
+}
+
/* mess with the segment structure in the bytes format */
GST_START_TEST (segment_seek_nosize)
{
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
fail_unless (segment.start == 100);
+ fail_unless (segment.position == 100);
fail_unless (segment.stop == -1);
fail_unless (update == TRUE);
+ /* appended after current position 0 */
+ check_times (&segment, 100, 100, 0);
/* do some clipping on the open range */
/* completely outside */
fail_unless (cstart == 150);
fail_unless (cstop == -1);
+ /* move to 150, this is a running_time of 50 */
+ segment.position = 150;
+ check_times (&segment, 150, 150, 50);
+
/* add 100 to start, set stop to 300 */
gst_segment_do_seek (&segment, 1.0,
GST_FORMAT_BYTES,
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_SET, 100 + 100, GST_SEEK_TYPE_SET, 300, &update);
fail_unless (segment.start == 200);
+ fail_unless (segment.position == 200);
fail_unless (segment.stop == 300);
fail_unless (update == TRUE);
+ check_times (&segment, 200, 200, 50);
update = FALSE;
/* add 100 to start (to 300), set stop to 200, this is not allowed.
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_SET, 200 + 100, GST_SEEK_TYPE_SET, 200, &update));
fail_unless (segment.start == 200);
+ fail_unless (segment.position == 200);
fail_unless (segment.stop == 300);
/* update didn't change */
fail_unless (update == FALSE);
+ check_times (&segment, 250, 250, 100);
update = TRUE;
/* seek relative to end, should not do anything since size is
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_END, -300, GST_SEEK_TYPE_END, -100, &update);
fail_unless (segment.start == 200);
+ fail_unless (segment.position == 200);
fail_unless (segment.stop == 300);
fail_unless (update == FALSE);
+ check_times (&segment, 250, 250, 100);
/* completely outside */
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
fail_unless (segment.start == 100);
+ fail_unless (segment.position == 100);
fail_unless (segment.stop == -1);
fail_unless (update == TRUE);
+ check_times (&segment, 100, 100, 0);
/* do some clipping on the open range */
/* completely outside */
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_SET, 100 + 100, GST_SEEK_TYPE_SET, 300, &update);
fail_unless (segment.start == 200);
+ fail_unless (segment.position == 200);
fail_unless (segment.stop == 200);
+ check_times (&segment, 200, 200, 0);
/* add 100 to start (to 300), set stop to 200, this clips start
* to duration */
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_SET, 200 + 100, GST_SEEK_TYPE_SET, 200, &update);
fail_unless (segment.start == 200);
+ fail_unless (segment.position == 200);
fail_unless (segment.stop == 200);
fail_unless (update == FALSE);
+ check_times (&segment, 200, 200, 0);
/* seek relative to end */
gst_segment_do_seek (&segment, 1.0,
GST_SEEK_FLAG_NONE,
GST_SEEK_TYPE_END, -100, GST_SEEK_TYPE_END, -20, &update);
fail_unless (segment.start == 100);
+ fail_unless (segment.position == 100);
fail_unless (segment.stop == 180);
fail_unless (update == TRUE);
+ check_times (&segment, 150, 150, 50);
/* completely outside */
res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
fail_unless (segment.time == 0);
fail_unless (segment.position == 100);
fail_unless (update == TRUE);
+ check_times (&segment, 100, 100, 0);
+ check_times (&segment, 50, 50, 50);
+ check_times (&segment, 0, 0, 100);
/* update */
gst_segment_do_seek (&segment, -1.0,
fail_unless (segment.time == 10);
fail_unless (segment.position == 80);
fail_unless (update == TRUE);
+ check_times (&segment, 80, 80, 0);
+ check_times (&segment, 40, 40, 40);
+ check_times (&segment, 10, 10, 70);
gst_segment_do_seek (&segment, -1.0,
GST_FORMAT_BYTES,
fail_unless (segment.time == 20);
fail_unless (segment.position == 80);
fail_unless (update == FALSE);
+ check_times (&segment, 80, 80, 0);
+ check_times (&segment, 20, 20, 60);
}
GST_END_TEST;