mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-15 13:45:28 +00:00
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:
parent
64f664c859
commit
c399b1f0c6
1 changed files with 33 additions and 0 deletions
|
@ -193,6 +193,7 @@ enum ControllerType {
|
||||||
struct Consumer {
|
struct Consumer {
|
||||||
pipeline: gst::Pipeline,
|
pipeline: gst::Pipeline,
|
||||||
webrtcbin: gst::Element,
|
webrtcbin: gst::Element,
|
||||||
|
rtprtxsend: Option<gst::Element>,
|
||||||
webrtc_pads: HashMap<u32, WebRTCPad>,
|
webrtc_pads: HashMap<u32, WebRTCPad>,
|
||||||
peer_id: String,
|
peer_id: String,
|
||||||
encoders: Vec<VideoEncoder>,
|
encoders: Vec<VideoEncoder>,
|
||||||
|
@ -1139,6 +1140,7 @@ impl Consumer {
|
||||||
webrtcbin,
|
webrtcbin,
|
||||||
peer_id,
|
peer_id,
|
||||||
cc_info,
|
cc_info,
|
||||||
|
rtprtxsend: None,
|
||||||
congestion_controller,
|
congestion_controller,
|
||||||
stats: gst::Structure::new_empty("application/x-webrtc-stats"),
|
stats: gst::Structure::new_empty("application/x-webrtc-stats"),
|
||||||
sdp: None,
|
sdp: None,
|
||||||
|
@ -1789,7 +1791,25 @@ impl WebRTCSink {
|
||||||
Some(cc)
|
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();
|
pipeline.add(&webrtcbin).unwrap();
|
||||||
|
@ -2115,6 +2135,14 @@ impl WebRTCSink {
|
||||||
webrtcbin.emit_by_name::<()>("get-stats", &[&None::<gst::Pad>, &promise]);
|
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) {
|
fn set_bitrate(&self, element: &super::WebRTCSink, peer_id: &str, bitrate: u32) {
|
||||||
let mut state = element.imp().state.lock().unwrap();
|
let mut state = element.imp().state.lock().unwrap();
|
||||||
|
|
||||||
|
@ -2132,6 +2160,11 @@ impl WebRTCSink {
|
||||||
|
|
||||||
let fec_percentage = fec_ratio * 50f64;
|
let fec_percentage = fec_ratio * 50f64;
|
||||||
let encoders_bitrate = ((bitrate as f64) / (1. + (fec_percentage / 100.))) as i32;
|
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() {
|
for encoder in consumer.encoders.iter_mut() {
|
||||||
encoder.set_bitrate(element, encoders_bitrate);
|
encoder.set_bitrate(element, encoders_bitrate);
|
||||||
encoder
|
encoder
|
||||||
|
|
Loading…
Reference in a new issue