From 9d7af671c5ee1fb744ca27913fd21e474f8c95b4 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 ee6fea71..9b66cc15 100644 --- a/utils/togglerecord/src/togglerecord/imp.rs +++ b/utils/togglerecord/src/togglerecord/imp.rs @@ -415,6 +415,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, @@ -426,14 +434,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); @@ -444,17 +444,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)