Limit REMB target bitrate to 2x maximum actually seen value
This commit is contained in:
parent
e205743f0c
commit
9e5a3895ae
|
@ -167,8 +167,10 @@ public class Dino.Plugins.Rtp.Stream : Xmpp.Xep.JingleRtp.Stream {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int last_packets_lost = -1;
|
private int last_packets_lost = -1;
|
||||||
private uint64 last_packets_received;
|
private uint64 last_packets_received = 0;
|
||||||
private uint64 last_octets_received;
|
private uint64 last_octets_received = 0;
|
||||||
|
private uint max_target_receive_bitrate = 0;
|
||||||
|
private int64 last_remb_time = 0;
|
||||||
private bool remb_adjust() {
|
private bool remb_adjust() {
|
||||||
unowned Gst.Structure? stats;
|
unowned Gst.Structure? stats;
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
|
@ -210,13 +212,26 @@ public class Dino.Plugins.Rtp.Stream : Xmpp.Xep.JingleRtp.Stream {
|
||||||
last_octets_received = octets_received;
|
last_octets_received = octets_received;
|
||||||
if (new_received == 0) continue;
|
if (new_received == 0) continue;
|
||||||
double loss_rate = (double)new_lost / (double)(new_lost + new_received);
|
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) {
|
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) {
|
} 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));
|
if (last_remb_time == 0) {
|
||||||
target_receive_bitrate = uint.max(16, target_receive_bitrate); // Never go below 16
|
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[] {
|
uint8[] data = new uint8[] {
|
||||||
143, 206, 0, 5,
|
143, 206, 0, 5,
|
||||||
0, 0, 0, 0,
|
0, 0, 0, 0,
|
||||||
|
@ -246,6 +261,7 @@ public class Dino.Plugins.Rtp.Stream : Xmpp.Xep.JingleRtp.Stream {
|
||||||
encrypt_and_send_rtcp(data);
|
encrypt_and_send_rtcp(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Source.CONTINUE;
|
return Source.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue