Use rtprtxsend stuffing when available and congestion control is enabled

Depends on https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2273/
This commit is contained in:
Thibault Saunier 2022-06-30 19:04:17 +00:00 committed by Mathieu Duponchelle
parent 64f664c859
commit c399b1f0c6

View file

@ -193,6 +193,7 @@ enum ControllerType {
struct Consumer {
pipeline: gst::Pipeline,
webrtcbin: gst::Element,
rtprtxsend: Option<gst::Element>,
webrtc_pads: HashMap<u32, WebRTCPad>,
peer_id: String,
encoders: Vec<VideoEncoder>,
@ -1139,6 +1140,7 @@ impl Consumer {
webrtcbin,
peer_id,
cc_info,
rtprtxsend: None,
congestion_controller,
stats: gst::Structure::new_empty("application/x-webrtc-stats"),
sdp: None,
@ -1789,7 +1791,25 @@ impl WebRTCSink {
Some(cc)
}),
);
webrtcbin.connect_closure(
"deep-element-added",
false,
glib::closure!(@watch element, @strong peer_id
=> move |_webrtcbin: gst::Element, _bin: gst::Bin, e: gst::Element| {
if e.factory().map_or(false, |f| f.name() == "rtprtxsend") {
if e.has_property("stuffing-kbps", Some(i32::static_type())) {
element.imp().set_rtptrxsend(&element, &peer_id, e);
} else {
gst::warning!(CAT, "rtprtxsend doesn't have a `stuffing-kbps` \
property, stuffing disabled");
}
}
}),
);
}
_ => (),
}
pipeline.add(&webrtcbin).unwrap();
@ -2115,6 +2135,14 @@ impl WebRTCSink {
webrtcbin.emit_by_name::<()>("get-stats", &[&None::<gst::Pad>, &promise]);
}
fn set_rtptrxsend(&self, element: &super::WebRTCSink, peer_id: &str, rtprtxsend: gst::Element) {
let mut state = element.imp().state.lock().unwrap();
if let Some(consumer) = state.consumers.get_mut(peer_id) {
consumer.rtprtxsend = Some(rtprtxsend);
}
}
fn set_bitrate(&self, element: &super::WebRTCSink, peer_id: &str, bitrate: u32) {
let mut state = element.imp().state.lock().unwrap();
@ -2132,6 +2160,11 @@ impl WebRTCSink {
let fec_percentage = fec_ratio * 50f64;
let encoders_bitrate = ((bitrate as f64) / (1. + (fec_percentage / 100.))) as i32;
if let Some(ref rtpxsend) = consumer.rtprtxsend.as_ref() {
rtpxsend.set_property("stuffing-kbps", (bitrate as f64 / 1000.) as i32);
}
for encoder in consumer.encoders.iter_mut() {
encoder.set_bitrate(element, encoders_bitrate);
encoder