From 8248425905e7ec4ea2d45f9eff0d9c587c54d615 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 24 May 2023 13:33:52 +0200 Subject: [PATCH] webrtcsink: further refactor connection to stats signals - Stop passing webrtcbin around without using it - Stop using glib::closure as clippy complains when using a unit type default-return Part-of: --- net/webrtc/src/webrtcsink/imp.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/net/webrtc/src/webrtcsink/imp.rs b/net/webrtc/src/webrtcsink/imp.rs index b786c78e..0895381e 100644 --- a/net/webrtc/src/webrtcsink/imp.rs +++ b/net/webrtc/src/webrtcsink/imp.rs @@ -1618,7 +1618,7 @@ impl WebRTCSink { } }); - let session = Session::new( + let mut session = Session::new( session_id.clone(), pipeline.clone(), webrtcbin.clone(), @@ -1644,21 +1644,24 @@ impl WebRTCSink { if session.congestion_controller.is_some() { let session_id_str = session_id.to_string(); rtpbin.connect_closure("on-new-ssrc", true, - glib::closure!(@weak-allow-none element, @weak-allow-none webrtcbin + glib::closure!(@weak-allow-none element, => move |rtpbin: gst::Object, session_id: u32, _src: u32| { let rtp_session = rtpbin.emit_by_name::("get-session", &[&session_id]); let element = element.expect("on-new-ssrc emited when webrtcsink has been disposed?"); - let webrtcbin = webrtcbin.unwrap(); let mut state = element.imp().state.lock().unwrap(); if let Some(mut session) = state.sessions.get_mut(&session_id_str) { if session.stats_sigid.is_none() { + let session_id_str = session_id_str.clone(); + let element = element.downgrade(); session.stats_sigid = Some(rtp_session.connect_notify(Some("twcc-stats"), - glib::clone!(@strong session_id_str, @weak webrtcbin, @weak element => @default-return (), move |sess, pspec| { - // Run the Loss-based control algorithm on new peer TWCC feedbacks - element.imp().process_loss_stats(&element, &session_id_str, &sess.property::(pspec.name())); - }) + move |sess, pspec| { + if let Some(element) = element.upgrade() { + // Run the Loss-based control algorithm on new peer TWCC feedbacks + element.imp().process_loss_stats(&element, &session_id_str, &sess.property::(pspec.name())); + } + } )); } }