From e13124a426c71d30dbec5d5345007894756badd6 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Fri, 19 May 2023 14:56:49 +0200 Subject: [PATCH] webrtcsink: fix stats_sigid logic First off, we just created the session, we know stats_sigid is None at this point. Second, don't first assign the result of connecting on-new-ssrc to the field, then the result of connection twcc-stats, that simply doesn't make sense. Finally, actually check that stats_sigid *is* None before connecting twcc-stats, as I understand it this must have been the original intention / behavior. Part-of: --- net/webrtc/src/webrtcsink/imp.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/net/webrtc/src/webrtcsink/imp.rs b/net/webrtc/src/webrtcsink/imp.rs index ba2cbd2b..3e9d70c7 100644 --- a/net/webrtc/src/webrtcsink/imp.rs +++ b/net/webrtc/src/webrtcsink/imp.rs @@ -2166,7 +2166,7 @@ impl BaseWebRTCSink { } }); - let mut session = Session::new( + let session = Session::new( session_id.clone(), pipeline.clone(), webrtcbin.clone(), @@ -2191,8 +2191,7 @@ impl BaseWebRTCSink { if session.congestion_controller.is_some() { let session_id_str = session_id.to_string(); - if session.stats_sigid.is_none() { - session.stats_sigid = Some(rtpbin.connect_closure("on-new-ssrc", true, + rtpbin.connect_closure("on-new-ssrc", true, glib::closure!(@weak-allow-none element, @weak-allow-none webrtcbin => move |rtpbin: gst::Object, session_id: u32, _src: u32| { let rtp_session = rtpbin.emit_by_name::("get-session", &[&session_id]); @@ -2202,16 +2201,17 @@ impl BaseWebRTCSink { let mut state = element.imp().state.lock().unwrap(); if let Some(session) = state.sessions.get_mut(&session_id_str) { - 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())); - }) - )); + if session.stats_sigid.is_none() { + 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())); + }) + )); + } } }) - )); - } + ); } let clock = element.clock();