Commit d2e5ffde authored by Wim Taymans's avatar Wim Taymans
Browse files

gst/gstsegment.c: Set the last_stop to a more meaningful position when...

gst/gstsegment.c: Set the last_stop to a more meaningful position when configuring the segment. ie. the start/stop of...

Original commit message from CVS:
* gst/gstsegment.c: (gst_segment_set_newsegment_full):
Set the last_stop to a more meaningful position when configuring the
segment. ie. the start/stop of the segment or clipped against the
updated segment boundaries.
* tests/check/gst/gstsegment.c: (GST_START_TEST):
Add some unit tests for the last_stop.
parent d3cb47b9
2008-10-23 Wim Taymans <wim.taymans@collabora.co.uk>
* gst/gstsegment.c: (gst_segment_set_newsegment_full):
Set the last_stop to a more meaningful position when configuring the
segment. ie. the start/stop of the segment or clipped against the
updated segment boundaries.
* tests/check/gst/gstsegment.c: (GST_START_TEST):
Add some unit tests for the last_stop.
2008-10-23 Sebastian Dröge <sebastian.droege@collabora.co.uk>
 
* libs/gst/base/gstbytereader.c:
......@@ -440,7 +440,7 @@ gst_segment_set_newsegment_full (GstSegment * segment, gboolean update,
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);
......@@ -483,12 +483,18 @@ gst_segment_set_newsegment_full (GstSegment * segment, gboolean update,
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) {
......@@ -500,6 +506,12 @@ gst_segment_set_newsegment_full (GstSegment * segment, gboolean update,
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)
......@@ -513,7 +525,7 @@ gst_segment_set_newsegment_full (GstSegment * segment, gboolean update,
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;
}
......
......@@ -593,6 +593,7 @@ GST_START_TEST (segment_newsegment_open)
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);
......@@ -601,6 +602,7 @@ GST_START_TEST (segment_newsegment_open)
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,
......@@ -610,6 +612,7 @@ GST_START_TEST (segment_newsegment_open)
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);
......@@ -621,6 +624,8 @@ GST_START_TEST (segment_newsegment_open)
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);
......@@ -628,7 +633,7 @@ GST_START_TEST (segment_newsegment_open)
fail_unless (segment.stop == -1);
fail_unless (segment.time == 0);
fail_unless (segment.accum == 300);
fail_unless (segment.last_stop == 0);
}
GST_END_TEST;
......@@ -654,13 +659,29 @@ GST_START_TEST (segment_newsegment_closed)
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,
......@@ -1222,7 +1243,7 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate)
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 */
......@@ -1262,7 +1283,7 @@ GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate)
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 */
......@@ -1487,7 +1508,7 @@ GST_START_TEST (segment_newsegment_accum)
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 */
......@@ -1512,7 +1533,7 @@ GST_START_TEST (segment_newsegment_accum)
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);
......@@ -1534,7 +1555,7 @@ GST_START_TEST (segment_newsegment_accum)
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);
......@@ -1568,7 +1589,7 @@ GST_START_TEST (segment_newsegment_accum2)
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 */
......@@ -1593,7 +1614,7 @@ GST_START_TEST (segment_newsegment_accum2)
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. */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment