From 88262e596df78fed419a876b444f978262130fad Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 25 Feb 2022 22:50:52 +0900 Subject: [PATCH] fallbacksrc: Disconnect signals on ReadyToNull Otherwise multiple signal handlers will be connected to the source --- .../src/fallbacksrc/custom_source/imp.rs | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/utils/fallbackswitch/src/fallbacksrc/custom_source/imp.rs b/utils/fallbackswitch/src/fallbacksrc/custom_source/imp.rs index c552a1c5..a95cec50 100644 --- a/utils/fallbackswitch/src/fallbacksrc/custom_source/imp.rs +++ b/utils/fallbackswitch/src/fallbacksrc/custom_source/imp.rs @@ -7,6 +7,7 @@ // SPDX-License-Identifier: MPL-2.0 use gst::glib; +use gst::glib::SignalHandlerId; use gst::prelude::*; use gst::subclass::prelude::*; use gst::{gst_debug, gst_error}; @@ -36,6 +37,9 @@ struct State { pads: Vec, num_audio: usize, num_video: usize, + pad_added_sig_id: Option, + pad_removed_sig_id: Option, + no_more_pads_sig_id: Option, } #[derive(Default)] @@ -203,7 +207,7 @@ impl CustomSource { gst_debug!(CAT, obj: element, "Found sometimes pads"); let element_weak = element.downgrade(); - source.connect_pad_added(move |_, pad| { + let pad_added_sig_id = source.connect_pad_added(move |_, pad| { let element = match element_weak.upgrade() { None => return, Some(element) => element, @@ -215,7 +219,7 @@ impl CustomSource { } }); let element_weak = element.downgrade(); - source.connect_pad_removed(move |_, pad| { + let pad_removed_sig_id = source.connect_pad_removed(move |_, pad| { let element = match element_weak.upgrade() { None => return, Some(element) => element, @@ -226,7 +230,7 @@ impl CustomSource { }); let element_weak = element.downgrade(); - source.connect_no_more_pads(move |_| { + let no_more_pads_sig_id = source.connect_no_more_pads(move |_| { let element = match element_weak.upgrade() { None => return, Some(element) => element, @@ -235,6 +239,11 @@ impl CustomSource { src.handle_source_no_more_pads(&element); }); + + let mut state = self.state.lock().unwrap(); + state.pad_added_sig_id = Some(pad_added_sig_id); + state.pad_removed_sig_id = Some(pad_removed_sig_id); + state.no_more_pads_sig_id = Some(no_more_pads_sig_id); } Ok(gst::StateChangeSuccess::Success) @@ -361,6 +370,19 @@ impl CustomSource { gst_debug!(CAT, obj: element, "Stopping"); let mut state = self.state.lock().unwrap(); + let source = self.source.get().unwrap(); + if let Some(id) = state.pad_added_sig_id.take() { + source.disconnect(id) + } + + if let Some(id) = state.pad_removed_sig_id.take() { + source.disconnect(id) + } + + if let Some(id) = state.no_more_pads_sig_id.take() { + source.disconnect(id) + } + let pads = mem::take(&mut state.pads); state.num_audio = 0; state.num_video = 0;