From 6e67ad7675c3bd00dae00c5aa20647f7e241802a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 18 Mar 2015 10:53:30 +0100 Subject: [PATCH] segment: fix offset handling with non 0 start The position in the segment is relative to the start but the offset isn't, so subtract the start from the position when setting the offset. Add unit test for this as well. --- gst/gstsegment.c | 2 +- tests/check/gst/gstsegment.c | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/gst/gstsegment.c b/gst/gstsegment.c index fc52363f81..2f1b037ad2 100644 --- a/gst/gstsegment.c +++ b/gst/gstsegment.c @@ -757,7 +757,7 @@ gst_segment_offset_running_time (GstSegment * segment, GstFormat format, if (position == -1) return FALSE; - segment->offset = position; + segment->offset = position - segment->start; } } return TRUE; diff --git a/tests/check/gst/gstsegment.c b/tests/check/gst/gstsegment.c index 94eb2b2f08..3e5f16b8fe 100644 --- a/tests/check/gst/gstsegment.c +++ b/tests/check/gst/gstsegment.c @@ -689,6 +689,57 @@ GST_START_TEST (segment_offset) fail_unless (segment.base == 0); fail_unless (segment.offset == 200); check_times (&segment, 200, 200, 0); + + gst_segment_init (&segment, GST_FORMAT_TIME); + + segment.start = 20; + segment.position = 50; + segment.stop = 220; + segment.time = 0; + + check_times (&segment, 40, 20, 20); + check_times (&segment, 240, -1, -1); + + fail_unless (gst_segment_offset_running_time (&segment, GST_FORMAT_TIME, + 0) == TRUE); + fail_unless (segment.start == 20); + fail_unless (segment.stop == 220); + fail_unless (segment.time == 0); + fail_unless (segment.position == 50); + fail_unless (segment.base == 0); + fail_unless (segment.offset == 0); + check_times (&segment, 40, 20, 20); + + fail_unless (gst_segment_offset_running_time (&segment, GST_FORMAT_TIME, + 100) == TRUE); + fail_unless (segment.start == 20); + fail_unless (segment.stop == 220); + fail_unless (segment.time == 0); + fail_unless (segment.position == 50); + fail_unless (segment.base == 100); + fail_unless (segment.offset == 0); + check_times (&segment, 40, 20, 120); + + fail_unless (gst_segment_offset_running_time (&segment, GST_FORMAT_TIME, + -50) == TRUE); + fail_unless (segment.start == 20); + fail_unless (segment.stop == 220); + fail_unless (segment.time == 0); + fail_unless (segment.position == 50); + fail_unless (segment.base == 50); + fail_unless (segment.offset == 0); + check_times (&segment, 40, 20, 70); + + fail_unless (gst_segment_offset_running_time (&segment, GST_FORMAT_TIME, + -100) == TRUE); + fail_unless (segment.start == 20); + fail_unless (segment.stop == 220); + fail_unless (segment.time == 0); + fail_unless (segment.position == 50); + fail_unless (segment.base == 0); + fail_unless (segment.offset == 50); + check_times (&segment, 40, 20, -1); + check_times (&segment, 220, 200, 150); } GST_END_TEST;