From 5ad1f006057e292243dd11c59a37db4869b99a0e Mon Sep 17 00:00:00 2001 From: Alexander Slobodeniuk Date: Mon, 4 Sep 2023 14:02:25 +0200 Subject: [PATCH] aggregator: fix start-time-selection=first on negative rate When the property "start-time-selection" is set to "first", it calculates the start time of the output from the buffer pts (converting it to running time of the segment), but if the rate is negative, the real start is not the pts, but the pts + duration, because it plays from the end of the buffer to it's start. As a result of this bug, in the negative rate, when the start-time-selection=first, the first frame is dropped by the videoaggregator (reproduced on d3d11compositor). Part-of: --- subprojects/gstreamer/libs/gst/base/gstaggregator.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/gstreamer/libs/gst/base/gstaggregator.c b/subprojects/gstreamer/libs/gst/base/gstaggregator.c index 819f7ef71c..64b59469c0 100644 --- a/subprojects/gstreamer/libs/gst/base/gstaggregator.c +++ b/subprojects/gstreamer/libs/gst/base/gstaggregator.c @@ -3244,6 +3244,7 @@ gst_aggregator_pad_chain_internal (GstAggregator * self, { GstFlowReturn flow_return; GstClockTime buf_pts; + GstClockTime buf_duration; GST_TRACE_OBJECT (aggpad, "entering chain internal with %" GST_PTR_FORMAT, buffer); @@ -3256,6 +3257,7 @@ gst_aggregator_pad_chain_internal (GstAggregator * self, PAD_UNLOCK (aggpad); buf_pts = GST_BUFFER_PTS (buffer); + buf_duration = GST_BUFFER_DURATION (buffer); for (;;) { SRC_LOCK (self); @@ -3312,6 +3314,9 @@ gst_aggregator_pad_chain_internal (GstAggregator * self, if (aggpad->priv->head_segment.format == GST_FORMAT_TIME) { start_time = buf_pts; if (start_time != -1) { + if (aggpad->priv->head_segment.rate < 0.0 && buf_duration != -1) { + start_time += buf_duration; + } start_time = MAX (start_time, aggpad->priv->head_segment.start); start_time = gst_segment_to_running_time (&aggpad->priv->head_segment,