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.
This commit is contained in:
parent
78bdbadc4e
commit
6e67ad7675
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user