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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1234>
This commit is contained in:
Mathieu Duponchelle 2023-05-19 14:56:49 +02:00 committed by Sebastian Dröge
parent 8ff2c6609c
commit e9d32fb221

View file

@ -1618,7 +1618,7 @@ impl WebRTCSink {
} }
}); });
let mut session = Session::new( let session = Session::new(
session_id.clone(), session_id.clone(),
pipeline.clone(), pipeline.clone(),
webrtcbin.clone(), webrtcbin.clone(),
@ -1643,8 +1643,7 @@ impl WebRTCSink {
if session.congestion_controller.is_some() { if session.congestion_controller.is_some() {
let session_id_str = session_id.to_string(); let session_id_str = session_id.to_string();
if session.stats_sigid.is_none() { rtpbin.connect_closure("on-new-ssrc", true,
session.stats_sigid = Some(rtpbin.connect_closure("on-new-ssrc", true,
glib::closure!(@weak-allow-none element, @weak-allow-none webrtcbin glib::closure!(@weak-allow-none element, @weak-allow-none webrtcbin
=> move |rtpbin: gst::Object, session_id: u32, _src: u32| { => move |rtpbin: gst::Object, session_id: u32, _src: u32| {
let rtp_session = rtpbin.emit_by_name::<gst::Element>("get-session", &[&session_id]); let rtp_session = rtpbin.emit_by_name::<gst::Element>("get-session", &[&session_id]);
@ -1654,16 +1653,17 @@ impl WebRTCSink {
let mut state = element.imp().state.lock().unwrap(); let mut state = element.imp().state.lock().unwrap();
if let Some(mut session) = state.sessions.get_mut(&session_id_str) { if let Some(mut session) = state.sessions.get_mut(&session_id_str) {
session.stats_sigid = Some(rtp_session.connect_notify(Some("twcc-stats"), if session.stats_sigid.is_none() {
glib::clone!(@strong session_id_str, @weak webrtcbin, @weak element => @default-return (), move |sess, pspec| { session.stats_sigid = Some(rtp_session.connect_notify(Some("twcc-stats"),
// Run the Loss-based control algorithm on new peer TWCC feedbacks glib::clone!(@strong session_id_str, @weak webrtcbin, @weak element => @default-return (), move |sess, pspec| {
element.imp().process_loss_stats(&element, &session_id_str, &sess.property::<gst::Structure>(pspec.name())); // Run the Loss-based control algorithm on new peer TWCC feedbacks
}) element.imp().process_loss_stats(&element, &session_id_str, &sess.property::<gst::Structure>(pspec.name()));
)); })
));
}
} }
}) })
)); );
}
} }
state state