From 50ee0c1a1d9dc8e717c0adaa3ef71b641ad687bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 18 Sep 2019 14:29:55 +0300 Subject: [PATCH] fallbackswitch: Correctly handle incoming non-default segments We need to convert buffer timestamps to the outgoing [0, -1] segment of aggregator. This won't work correctly for negative DTS as is. --- .../src/fallbackswitch.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gst-plugin-fallbackswitch/src/fallbackswitch.rs b/gst-plugin-fallbackswitch/src/fallbackswitch.rs index b7ea55f2..b7d5077b 100644 --- a/gst-plugin-fallbackswitch/src/fallbackswitch.rs +++ b/gst-plugin-fallbackswitch/src/fallbackswitch.rs @@ -112,7 +112,7 @@ impl FallbackSwitch { &self, agg: &gst_base::Aggregator, state: &mut OutputState, - buffer: gst::Buffer, + mut buffer: gst::Buffer, fallback_sinkpad: Option<&gst_base::AggregatorPad>, ) -> Result, gst::FlowError> { // If we got a buffer on the sinkpad just handle it @@ -132,6 +132,13 @@ impl FallbackSwitch { gst::FlowError::Error })?; + { + // FIXME: This will not work correctly for negative DTS + let buffer = buffer.make_mut(); + buffer.set_pts(segment.to_running_time(buffer.get_pts())); + buffer.set_dts(segment.to_running_time(buffer.get_dts())); + } + let mut active_sinkpad = self.active_sinkpad.lock().unwrap(); let pad_change = &*active_sinkpad != self.sinkpad.upcast_ref::(); if pad_change { @@ -202,7 +209,7 @@ impl FallbackSwitch { // If we have a fallback sinkpad and timeout, try to get a fallback buffer from here // and drop all too old buffers in the process loop { - let buffer = fallback_sinkpad + let mut buffer = fallback_sinkpad .pop_buffer() .ok_or(gst_base::AGGREGATOR_FLOW_NEED_DATA)?; @@ -227,6 +234,13 @@ impl FallbackSwitch { })?; let running_time = fallback_segment.to_running_time(buffer.get_pts()); + { + // FIXME: This will not work correctly for negative DTS + let buffer = buffer.make_mut(); + buffer.set_pts(fallback_segment.to_running_time(buffer.get_pts())); + buffer.set_dts(fallback_segment.to_running_time(buffer.get_dts())); + } + // If we never had a real buffer, initialize with the running time of the fallback // sinkpad so that we still output fallback buffers after the timeout if state.last_sinkpad_time.is_none() {