From fc2810badaa0f3e8dcd1ede91bde4a21be28c531 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Mon, 27 Apr 2020 09:57:30 -0400 Subject: [PATCH] videorate: Fix buffer timestamp underflow in reverse playback And fix reverse playback buffer duration computation as in reverse playback, buffer duration is prev_buffer.pts - buffer.pts not pts - next_pts (buffers are displayed from buffer.pts + buffer.duration for a duration of buffers.duration). This is now tested with the `validate.test.clock_sync.videorate.*` tests in the default integration testsuite where we check the exact data flow and the synchronization on the clock behaviour with a TestClock. Part-of: --- gst/videorate/gstvideorate.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gst/videorate/gstvideorate.c b/gst/videorate/gstvideorate.c index 3a1945ef1c..b2510e6062 100644 --- a/gst/videorate/gstvideorate.c +++ b/gst/videorate/gstvideorate.c @@ -673,14 +673,22 @@ gst_video_rate_push_buffer (GstVideoRate * videorate, GstBuffer * outbuf, if (videorate->segment.rate < 0.0) { if (videorate->to_rate_numerator) { /* interpolate next expected timestamp in the segment */ - videorate->next_ts = + GstClockTimeDiff next_ts = videorate->segment.base + videorate->segment.stop - videorate->base_ts - gst_util_uint64_scale (videorate->out_frame_count + 1, videorate->to_rate_denominator * GST_SECOND, videorate->to_rate_numerator); - GST_BUFFER_DURATION (outbuf) = push_ts - videorate->next_ts; + videorate->next_ts = next_ts < 0 ? GST_CLOCK_TIME_NONE : next_ts; + + GST_BUFFER_DURATION (outbuf) = + gst_util_uint64_scale (videorate->out_frame_count, + videorate->to_rate_denominator * GST_SECOND, + videorate->to_rate_numerator) - + gst_util_uint64_scale (videorate->out_frame_count - 1, + videorate->to_rate_denominator * GST_SECOND, + videorate->to_rate_numerator); } else if (next_intime != GST_CLOCK_TIME_NONE) { videorate->next_ts = next_intime; } else {