mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-22 19:41:00 +00:00
webrtcsink: fix calculation of fec_ratio with multiple encoders
In this context, the bitrate variable is for all encoders, but the max_bitrate field is per encoder. To calculate a proper FEC ratio, we need to scale max_bitrate to the number of encoders. + Also clamp the fec-percentage that we set on the transceiver for extra safety Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1151>
This commit is contained in:
parent
23c165dee1
commit
15e1844956
1 changed files with 7 additions and 5 deletions
|
@ -2376,19 +2376,21 @@ impl WebRTCSink {
|
|||
let mut state = element.imp().state.lock().unwrap();
|
||||
|
||||
if let Some(session) = state.sessions.get_mut(peer_id) {
|
||||
let n_encoders = session.encoders.len();
|
||||
|
||||
let fec_ratio = {
|
||||
if settings.do_fec && bitrate > DO_FEC_THRESHOLD {
|
||||
(bitrate as f64 - DO_FEC_THRESHOLD as f64)
|
||||
/ (session.cc_info.max_bitrate as f64 - DO_FEC_THRESHOLD as f64)
|
||||
/ ((session.cc_info.max_bitrate as usize * n_encoders) as f64
|
||||
- DO_FEC_THRESHOLD as f64)
|
||||
} else {
|
||||
0f64
|
||||
}
|
||||
};
|
||||
|
||||
let fec_percentage = fec_ratio * 50f64;
|
||||
let encoders_bitrate = ((bitrate as f64)
|
||||
/ (1. + (fec_percentage / 100.))
|
||||
/ (session.encoders.len() as f64)) as i32;
|
||||
let encoders_bitrate =
|
||||
((bitrate as f64) / (1. + (fec_percentage / 100.)) / (n_encoders as f64)) as i32;
|
||||
|
||||
if let Some(rtpxsend) = session.rtprtxsend.as_ref() {
|
||||
rtpxsend.set_property("stuffing-kbps", (bitrate as f64 / 1000.) as i32);
|
||||
|
@ -2398,7 +2400,7 @@ impl WebRTCSink {
|
|||
encoder.set_bitrate(element, encoders_bitrate);
|
||||
encoder
|
||||
.transceiver
|
||||
.set_property("fec-percentage", fec_percentage as u32);
|
||||
.set_property("fec-percentage", (fec_percentage as u32).min(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue