More segment updates and more checks.

Original commit message from CVS:
* check/gst/gstsegment.c: (GST_START_TEST), (gstsegments_suite),
(main):
* gst/gstsegment.c: (gst_segment_init), (gst_segment_set_duration),
(gst_segment_set_last_stop), (gst_segment_set_seek),
(gst_segment_set_newsegment), (gst_segment_to_stream_time),
(gst_segment_to_running_time), (gst_segment_clip):
* gst/gstsegment.h:
More segment updates and more checks.
This commit is contained in:
Wim Taymans 2005-11-21 13:26:51 +00:00
parent d1d6357de1
commit 29ea4a0bb0
4 changed files with 296 additions and 15 deletions

View file

@ -359,8 +359,135 @@ GST_START_TEST (segment_seek_size)
}
GST_END_TEST;
/* mess with the segment structure in the bytes format */
GST_START_TEST (segment_newsegment_open)
{
GstSegment segment;
gst_segment_init (&segment, GST_FORMAT_BYTES);
/* time should also work for starting from 0 */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
fail_unless (segment.rate == 1.0);
fail_unless (segment.format == GST_FORMAT_BYTES);
fail_unless (segment.flags == 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
fail_unless (segment.last_stop == -1);
fail_unless (segment.duration == -1);
/* we set stop but in the wrong format, stop stays open. */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, 200, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
/* update, nothing changes */
gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
/* update */
gst_segment_set_newsegment (&segment, TRUE, 1.0,
GST_FORMAT_BYTES, 100, -1, 100);
fail_unless (segment.start == 100);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 100);
fail_unless (segment.accum == 100);
/* last_stop unknown, accum does not change */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 100);
gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200);
/* last_stop 200, accum changes */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 300);
}
GST_END_TEST;
/* mess with the segment structure in the bytes format */
GST_START_TEST (segment_newsegment_closed)
{
GstSegment segment;
gst_segment_init (&segment, GST_FORMAT_BYTES);
gst_segment_set_newsegment (&segment, FALSE, 1.0,
GST_FORMAT_BYTES, 0, 200, 0);
fail_unless (segment.rate == 1.0);
fail_unless (segment.format == GST_FORMAT_BYTES);
fail_unless (segment.flags == 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == 200);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
fail_unless (segment.last_stop == -1);
fail_unless (segment.duration == -1);
/* do an update */
gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, 300, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == 300);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
/* and a new accumulated one */
gst_segment_set_newsegment (&segment, FALSE, 1.0,
GST_FORMAT_BYTES, 100, 400, 300);
fail_unless (segment.start == 100);
fail_unless (segment.stop == 400);
fail_unless (segment.time == 300);
fail_unless (segment.accum == 300);
/* and a new updated one */
gst_segment_set_newsegment (&segment, TRUE, 1.0,
GST_FORMAT_BYTES, 100, 500, 300);
fail_unless (segment.start == 100);
fail_unless (segment.stop == 500);
fail_unless (segment.time == 300);
fail_unless (segment.accum == 300);
/* and a new partially updated one */
gst_segment_set_newsegment (&segment, TRUE, 1.0,
GST_FORMAT_BYTES, 200, 500, 400);
fail_unless (segment.start == 200);
fail_unless (segment.stop == 500);
fail_unless (segment.time == 400);
fail_unless (segment.accum == 400);
}
GST_END_TEST;
Suite *
gstevents_suite (void)
gstsegments_suite (void)
{
Suite *s = suite_create ("GstSegment");
TCase *tc_chain = tcase_create ("segments");
@ -370,6 +497,8 @@ gstevents_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, segment_seek_nosize);
tcase_add_test (tc_chain, segment_seek_size);
tcase_add_test (tc_chain, segment_newsegment_open);
tcase_add_test (tc_chain, segment_newsegment_closed);
return s;
}
@ -378,7 +507,7 @@ main (int argc, char **argv)
{
int nf;
Suite *s = gstevents_suite ();
Suite *s = gstsegments_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);

View file

@ -57,7 +57,7 @@ gst_segment_init (GstSegment * segment, GstFormat format)
segment->stop = -1;
segment->time = 0;
segment->accum = 0;
segment->last_stop = 0;
segment->last_stop = -1;
segment->duration = -1;
}
@ -81,6 +81,24 @@ gst_segment_set_duration (GstSegment * segment, GstFormat format,
segment->duration = duration;
}
/**
* gst_segment_set_last_stop:
* @segment: a #GstSegment structure.
* @format: the format of the segment.
* @position: the position
*
* Set the last observed stop position in the segment to @position.
*/
void
gst_segment_set_last_stop (GstSegment * segment, GstFormat format,
gint64 position)
{
g_return_if_fail (segment != NULL);
g_return_if_fail (segment->format == format);
segment->last_stop = position;
}
/**
* gst_segment_set_seek:
* @segment: a #GstSegment structure.
@ -202,6 +220,17 @@ gst_segment_set_newsegment (GstSegment * segment, gboolean update, gdouble rate,
g_return_if_fail (rate != 0.0);
g_return_if_fail (segment != NULL);
/* any other format with 0 also gives time 0, the other values are
* invalid in the format though. */
if (format != segment->format && start == 0) {
format = segment->format;
if (stop != 0)
stop = -1;
if (time != 0)
time = -1;
}
g_return_if_fail (segment->format == format);
if (update) {
@ -212,13 +241,13 @@ gst_segment_set_newsegment (GstSegment * segment, gboolean update, gdouble rate,
/* 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. A flush event sets the accumulated time back to 0
* clock.
*/
if (GST_CLOCK_TIME_IS_VALID (segment->stop)) {
duration = segment->stop - segment->start;
} else if (GST_CLOCK_TIME_IS_VALID (segment->duration)) {
} else if (GST_CLOCK_TIME_IS_VALID (segment->last_stop)) {
/* else use last seen timestamp as segment stop */
duration = segment->duration - segment->start;
duration = segment->last_stop - segment->start;
} else {
/* else we don't know */
duration = 0;
@ -233,13 +262,6 @@ gst_segment_set_newsegment (GstSegment * segment, gboolean update, gdouble rate,
segment->start = start;
segment->stop = stop;
segment->time = time;
GST_DEBUG ("received NEWSEGMENT %" GST_TIME_FORMAT " -- %"
GST_TIME_FORMAT ", time %" GST_TIME_FORMAT ", accum %"
GST_TIME_FORMAT,
GST_TIME_ARGS (segment->start),
GST_TIME_ARGS (segment->stop),
GST_TIME_ARGS (segment->time), GST_TIME_ARGS (segment->accum));
}
/**

View file

@ -67,6 +67,7 @@ struct _GstSegment {
void gst_segment_init (GstSegment *segment, GstFormat format);
void gst_segment_set_duration (GstSegment *segment, GstFormat format, gint64 duration);
void gst_segment_set_last_stop (GstSegment *segment, GstFormat format, gint64 position);
void gst_segment_set_seek (GstSegment *segment, gdouble rate,
GstFormat format, GstSeekFlags flags,

View file

@ -359,8 +359,135 @@ GST_START_TEST (segment_seek_size)
}
GST_END_TEST;
/* mess with the segment structure in the bytes format */
GST_START_TEST (segment_newsegment_open)
{
GstSegment segment;
gst_segment_init (&segment, GST_FORMAT_BYTES);
/* time should also work for starting from 0 */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
fail_unless (segment.rate == 1.0);
fail_unless (segment.format == GST_FORMAT_BYTES);
fail_unless (segment.flags == 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
fail_unless (segment.last_stop == -1);
fail_unless (segment.duration == -1);
/* we set stop but in the wrong format, stop stays open. */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, 200, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
/* update, nothing changes */
gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
/* update */
gst_segment_set_newsegment (&segment, TRUE, 1.0,
GST_FORMAT_BYTES, 100, -1, 100);
fail_unless (segment.start == 100);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 100);
fail_unless (segment.accum == 100);
/* last_stop unknown, accum does not change */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 100);
gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200);
/* last_stop 200, accum changes */
gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 300);
}
GST_END_TEST;
/* mess with the segment structure in the bytes format */
GST_START_TEST (segment_newsegment_closed)
{
GstSegment segment;
gst_segment_init (&segment, GST_FORMAT_BYTES);
gst_segment_set_newsegment (&segment, FALSE, 1.0,
GST_FORMAT_BYTES, 0, 200, 0);
fail_unless (segment.rate == 1.0);
fail_unless (segment.format == GST_FORMAT_BYTES);
fail_unless (segment.flags == 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == 200);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
fail_unless (segment.last_stop == -1);
fail_unless (segment.duration == -1);
/* do an update */
gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, 300, 0);
fail_unless (segment.start == 0);
fail_unless (segment.stop == 300);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 0);
/* and a new accumulated one */
gst_segment_set_newsegment (&segment, FALSE, 1.0,
GST_FORMAT_BYTES, 100, 400, 300);
fail_unless (segment.start == 100);
fail_unless (segment.stop == 400);
fail_unless (segment.time == 300);
fail_unless (segment.accum == 300);
/* and a new updated one */
gst_segment_set_newsegment (&segment, TRUE, 1.0,
GST_FORMAT_BYTES, 100, 500, 300);
fail_unless (segment.start == 100);
fail_unless (segment.stop == 500);
fail_unless (segment.time == 300);
fail_unless (segment.accum == 300);
/* and a new partially updated one */
gst_segment_set_newsegment (&segment, TRUE, 1.0,
GST_FORMAT_BYTES, 200, 500, 400);
fail_unless (segment.start == 200);
fail_unless (segment.stop == 500);
fail_unless (segment.time == 400);
fail_unless (segment.accum == 400);
}
GST_END_TEST;
Suite *
gstevents_suite (void)
gstsegments_suite (void)
{
Suite *s = suite_create ("GstSegment");
TCase *tc_chain = tcase_create ("segments");
@ -370,6 +497,8 @@ gstevents_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, segment_seek_nosize);
tcase_add_test (tc_chain, segment_seek_size);
tcase_add_test (tc_chain, segment_newsegment_open);
tcase_add_test (tc_chain, segment_newsegment_closed);
return s;
}
@ -378,7 +507,7 @@ main (int argc, char **argv)
{
int nf;
Suite *s = gstevents_suite ();
Suite *s = gstsegments_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);