From 2acb83da8f22b128a0cf7f0bac8242b8859b7f82 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Tue, 14 Dec 2021 13:24:49 +0200 Subject: [PATCH] togglerecord: Handle stream-start event after EOS It should restart any pending streams instead of keeping everything EOS'd Part-of: --- utils/togglerecord/src/togglerecord/imp.rs | 76 ++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/utils/togglerecord/src/togglerecord/imp.rs b/utils/togglerecord/src/togglerecord/imp.rs index 38a9d871..2583a7ff 100644 --- a/utils/togglerecord/src/togglerecord/imp.rs +++ b/utils/togglerecord/src/togglerecord/imp.rs @@ -1086,7 +1086,7 @@ impl ToggleRecord { // Check whether all secondary streams are in eos. If so, update recording // state to Stopped if rec_state.recording_state != RecordingState::Stopped { - let mut others_eos = true; + let mut all_others_eos = true; // Check eos state of all secondary streams self.other_streams.lock().0.iter().all(|s| { @@ -1096,12 +1096,12 @@ impl ToggleRecord { let s = s.state.lock(); if !s.eos { - others_eos = false; + all_others_eos = false; } - others_eos + all_others_eos }); - if others_eos { + if all_others_eos { gst_debug!( CAT, obj: pad, @@ -1116,6 +1116,46 @@ impl ToggleRecord { false } + // should be called only if main stream stops being in eos state + fn check_and_update_stream_start( + &self, + pad: &gst::Pad, + stream: &Stream, + stream_state: &mut StreamState, + rec_state: &mut State, + ) -> bool { + stream_state.eos = false; + + // Check whether no secondary streams are in eos. If so, update recording + // state according to the record property + if rec_state.recording_state == RecordingState::Stopped { + let mut all_others_not_eos = false; + + // Check eos state of all secondary streams + self.other_streams.lock().0.iter().any(|s| { + if s == stream { + return false; + } + + let s = s.state.lock(); + if !s.eos { + all_others_not_eos = true; + } + all_others_not_eos + }); + + if !all_others_not_eos { + let settings = self.settings.lock(); + if settings.record { + gst_debug!(CAT, obj: pad, "Restarting recording after EOS"); + rec_state.recording_state = RecordingState::Starting; + } + } + } + + false + } + fn sink_chain( &self, pad: &gst::Pad, @@ -1361,6 +1401,34 @@ impl ToggleRecord { _ => false, }; } + EventView::StreamStart(..) => { + let main_state = if stream != self.main_stream { + Some(self.main_stream.state.lock()) + } else { + None + }; + let mut state = stream.state.lock(); + state.eos = false; + + let main_is_eos = if let Some(main_state) = main_state { + main_state.eos + } else { + false + }; + + if !main_is_eos { + let mut rec_state = self.state.lock(); + recording_state_changed = self.check_and_update_stream_start( + pad, + &stream, + &mut state, + &mut rec_state, + ); + } + + self.main_stream_cond.notify_all(); + gst_debug!(CAT, obj: pad, "Stream is not EOS now"); + } EventView::Eos(..) => { let main_state = if stream != self.main_stream { Some(self.main_stream.state.lock())