From b517b59171790fd160f14f6ef85eb055e24873b2 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 28 Apr 2020 13:28:32 -0400 Subject: [PATCH] identity,clocksync: Fix timestamping inside single segment in reverse playback In reverse playback, buffers are played back from buffer.stop (buffer.pts + buffer.duration) to buffer.pts running times which mean that we need to use the buffer end running time as a buffer timestsamp, not the buffer pts when using a single segment in reverse playback. This is now being tested in `validate.test.identity.reverse_single_segment` Part-of: --- plugins/elements/gstclocksync.c | 19 +++++++++++++++---- plugins/elements/gstidentity.c | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/plugins/elements/gstclocksync.c b/plugins/elements/gstclocksync.c index 7ca1a923fd..ede3277f44 100644 --- a/plugins/elements/gstclocksync.c +++ b/plugins/elements/gstclocksync.c @@ -338,10 +338,21 @@ gst_clock_sync_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) GstClockTime runtimestamp = 0; GstClockTime rundts, runpts; - rundts = gst_segment_to_running_time (&clocksync->segment, - GST_FORMAT_TIME, GST_BUFFER_DTS (buf)); - runpts = gst_segment_to_running_time (&clocksync->segment, - GST_FORMAT_TIME, GST_BUFFER_PTS (buf)); + if (clocksync->segment.rate > 0.0) { + rundts = gst_segment_to_running_time (&clocksync->segment, + GST_FORMAT_TIME, GST_BUFFER_DTS (buf)); + runpts = gst_segment_to_running_time (&clocksync->segment, + GST_FORMAT_TIME, GST_BUFFER_PTS (buf)); + } else { + runpts = gst_segment_to_running_time (&clocksync->segment, + GST_FORMAT_TIME, GST_CLOCK_TIME_IS_VALID (buf->duration) + && GST_CLOCK_TIME_IS_VALID (buf->pts) ? buf->pts + + buf->duration : buf->pts); + rundts = gst_segment_to_running_time (&clocksync->segment, + GST_FORMAT_TIME, GST_CLOCK_TIME_IS_VALID (buf->duration) + && GST_CLOCK_TIME_IS_VALID (buf->dts) ? buf->dts + + buf->duration : buf->dts); + } if (GST_CLOCK_TIME_IS_VALID (rundts)) runtimestamp = rundts; diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index a653428c9a..ffa0756a0e 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -687,10 +687,21 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf); if (trans->segment.format == GST_FORMAT_TIME) { - rundts = gst_segment_to_running_time (&trans->segment, - GST_FORMAT_TIME, GST_BUFFER_DTS (buf)); - runpts = gst_segment_to_running_time (&trans->segment, - GST_FORMAT_TIME, GST_BUFFER_PTS (buf)); + if (trans->segment.rate > 0) { + runpts = gst_segment_to_running_time (&trans->segment, + GST_FORMAT_TIME, GST_BUFFER_PTS (buf)); + rundts = gst_segment_to_running_time (&trans->segment, + GST_FORMAT_TIME, GST_BUFFER_DTS (buf)); + } else { + runpts = gst_segment_to_running_time (&trans->segment, + GST_FORMAT_TIME, GST_CLOCK_TIME_IS_VALID (buf->duration) + && GST_CLOCK_TIME_IS_VALID (buf->pts) ? buf->pts + + buf->duration : buf->pts); + rundts = gst_segment_to_running_time (&trans->segment, + GST_FORMAT_TIME, GST_CLOCK_TIME_IS_VALID (buf->duration) + && GST_CLOCK_TIME_IS_VALID (buf->dts) ? buf->dts + + buf->duration : buf->dts); + } } if (GST_CLOCK_TIME_IS_VALID (rundts))