From 774dda249e3bbc0203a5fc201c86cedc49e8c412 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Fri, 30 Jun 2023 14:21:29 +0300 Subject: [PATCH] togglerecord: Clip segment before calculating timestamp/duration Clipping happens in buffer time space and data.clip can modify the buffer timestamp and duration. Move it before we calculate them in order to make it actually have some effect. Part-of: --- utils/togglerecord/src/togglerecord/imp.rs | 27 +++++++--------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/utils/togglerecord/src/togglerecord/imp.rs b/utils/togglerecord/src/togglerecord/imp.rs index 379e27ee..57a54cba 100644 --- a/utils/togglerecord/src/togglerecord/imp.rs +++ b/utils/togglerecord/src/togglerecord/imp.rs @@ -337,6 +337,14 @@ impl ToggleRecord { ) -> Result, gst::FlowError> { let mut state = stream.state.lock(); + let data = match data.clip(&state, &state.in_segment) { + Some(data) => data, + None => { + gst::log!(CAT, obj: pad, "Dropping raw data outside segment"); + return Ok(HandleResult::Drop); + } + }; + let mut dts_or_pts = data.dts_or_pts().ok_or_else(|| { gst::element_imp_error!( self, @@ -348,14 +356,6 @@ impl ToggleRecord { let mut dts_or_pts_end = dts_or_pts + data.duration(&state).unwrap_or(gst::ClockTime::ZERO); - let data = match data.clip(&state, &state.in_segment) { - Some(data) => data, - None => { - gst::log!(CAT, obj: pad, "Dropping raw data outside segment"); - return Ok(HandleResult::Drop); - } - }; - // This will only do anything for non-raw data dts_or_pts = state.in_segment.start().unwrap().max(dts_or_pts); dts_or_pts_end = state.in_segment.start().unwrap().max(dts_or_pts_end); @@ -366,17 +366,6 @@ impl ToggleRecord { let current_running_time = state.in_segment.to_running_time(dts_or_pts); let current_running_time_end = state.in_segment.to_running_time(dts_or_pts_end); - let (current_running_time, current_running_time_end) = state - .in_segment - .clip(current_running_time, current_running_time_end) - .ok_or_else(|| { - gst::element_imp_error!( - self, - gst::StreamError::Format, - ["Received a buffer in the main stream without a valid running time"] - ); - gst::FlowError::Error - })?; state.current_running_time = current_running_time .opt_max(state.current_running_time)