From 7757e06e36dfc07256d80b1e5e244deafb05a1e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 5 Apr 2024 10:19:58 +0300 Subject: [PATCH] onvifmetadataparse: Reset state in PAUSED->READY after pad deactivation Otherwise the clock id will simply be overridden instead of unscheduling it, and if the streaming thread of the source pad currently waits on it then it will wait potentially for a very long time and deactivating the pad would wait for that to happen. Also unschedule the clock id on `Drop` of the state to be one the safe side and not simply forget about it. Part-of: --- net/onvif/src/onvifmetadataparse/imp.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/net/onvif/src/onvifmetadataparse/imp.rs b/net/onvif/src/onvifmetadataparse/imp.rs index fea2faf8..875e26dd 100644 --- a/net/onvif/src/onvifmetadataparse/imp.rs +++ b/net/onvif/src/onvifmetadataparse/imp.rs @@ -153,6 +153,14 @@ impl Default for State { } } +impl Drop for State { + fn drop(&mut self) { + if let Some(clock_wait) = self.clock_wait.take() { + clock_wait.unschedule(); + } + } +} + pub struct OnvifMetadataParse { srcpad: gst::Pad, sinkpad: gst::Pad, @@ -1595,14 +1603,18 @@ impl ElementImpl for OnvifMetadataParse { ) -> Result { gst::trace!(CAT, imp: self, "Changing state {:?}", transition); - if matches!( - transition, - gst::StateChange::PausedToReady | gst::StateChange::ReadyToPaused - ) { + if matches!(transition, gst::StateChange::ReadyToPaused) { let mut state = self.state.lock().unwrap(); *state = State::default(); } - self.parent_change_state(transition) + let res = self.parent_change_state(transition)?; + + if matches!(transition, gst::StateChange::PausedToReady) { + let mut state = self.state.lock().unwrap(); + *state = State::default(); + } + + Ok(res) } }