Limit REMB target bitrate to 2x maximum actually seen value

This commit is contained in:
Marvin W 2021-11-11 22:35:45 +01:00
parent e205743f0c
commit 9e5a3895ae
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A

View file

@ -167,8 +167,10 @@ public class Dino.Plugins.Rtp.Stream : Xmpp.Xep.JingleRtp.Stream {
}
private int last_packets_lost = -1;
private uint64 last_packets_received;
private uint64 last_octets_received;
private uint64 last_packets_received = 0;
private uint64 last_octets_received = 0;
private uint max_target_receive_bitrate = 0;
private int64 last_remb_time = 0;
private bool remb_adjust() {
unowned Gst.Structure? stats;
if (session == null) {
@ -210,13 +212,26 @@ public class Dino.Plugins.Rtp.Stream : Xmpp.Xep.JingleRtp.Stream {
last_octets_received = octets_received;
if (new_received == 0) continue;
double loss_rate = (double)new_lost / (double)(new_lost + new_received);
uint new_target_receive_bitrate = 256;
if (new_lost <= 0 || loss_rate < 0.02) {
target_receive_bitrate = (uint)(1.08 * (double)target_receive_bitrate);
new_target_receive_bitrate = (uint)(1.08 * (double)target_receive_bitrate);
} else if (loss_rate > 0.1) {
target_receive_bitrate = (uint)((1.0 - 0.5 * loss_rate) * (double)target_receive_bitrate);
new_target_receive_bitrate = (uint)((1.0 - 0.5 * loss_rate) * (double)target_receive_bitrate);
}
target_receive_bitrate = uint.max(target_receive_bitrate, (uint)((new_octets * 8) / 1000));
target_receive_bitrate = uint.max(16, target_receive_bitrate); // Never go below 16
if (last_remb_time == 0) {
last_remb_time = get_monotonic_time();
} else {
int64 time_now = get_monotonic_time();
int64 time_diff = time_now - last_remb_time;
last_remb_time = time_now;
uint actual_bitrate = (uint)(((double)new_octets * 8.0) * (double)time_diff / 1000.0 / 1000000.0);
new_target_receive_bitrate = uint.max(new_target_receive_bitrate, (uint)(0.9 * (double)actual_bitrate));
max_target_receive_bitrate = uint.max(actual_bitrate * 2, max_target_receive_bitrate);
new_target_receive_bitrate = uint.min(new_target_receive_bitrate, max_target_receive_bitrate);
}
new_target_receive_bitrate = uint.max(16, new_target_receive_bitrate); // Never go below 16
if (new_target_receive_bitrate != target_receive_bitrate) {
target_receive_bitrate = new_target_receive_bitrate;
uint8[] data = new uint8[] {
143, 206, 0, 5,
0, 0, 0, 0,
@ -246,6 +261,7 @@ public class Dino.Plugins.Rtp.Stream : Xmpp.Xep.JingleRtp.Stream {
encrypt_and_send_rtcp(data);
}
}
}
return Source.CONTINUE;
}