segment: Correct stream_time calc for negative applied rate
authorVivia Nikolaidou <vivia@ahiru.eu>
Mon, 19 Oct 2015 13:50:51 +0000 (16:50 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 20 Oct 2015 07:43:07 +0000 (10:43 +0300)
commit45f0f354ac34618d6f6adf20b0bffcf14a3f0a29
treef1238ccef6e1990483d4ceee5191d7e1314d8ae2
parent70d2a676af2bc51ed7b828dfd762b506bb82083b
segment: Correct stream_time calc for negative applied rate

Updated gst_segment_position_from_stream_time and gst_segment_to_stream_time to reflect correct calculations for the case when the applied rate is negative.

Pasting from design docs:

===============================
Stream time is calculated using the buffer times and the preceding SEGMENT
event as follows:

    stream_time = (B.timestamp - S.start) * ABS (S.applied_rate) + S.time

For negative rates, B.timestamp will go backwards from S.stop to S.start,
making the stream time go backwards.
===============================

Therefore, the calculation for applied_rate < 0 should be:

    stream_time = (S.stop - B.timestamp) * ABS (S.applied_rate) + S.time

and the reverse:

    B.timestamp = S.stop - (stream_time - S.time) / ABS (S.applied_rate)

https://bugzilla.gnome.org/show_bug.cgi?id=756810
gst/gstsegment.c
tests/check/gst/gstsegment.c