Skip to content

Commit ecf1e78

Browse files
authored
Align BWE ArrivalGroup calculation with libwebrtc implementation
1 parent b690540 commit ecf1e78

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Ensure lexical ordering of SDP-formatted candidates follows priority #557
2424
* Limit TWCC iteration with packet status count #606
2525
* Dedupe acked packets from `TwccSendRegister::apply_report()` #601, #605
26+
* Align BWE ArrivalGroup calculation with libwebrtc implementation #608
2627

2728
# 0.6.2
2829

src/packet/bwe/arrival_group.rs

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::cmp::Ordering;
12
use std::mem;
23
use std::time::{Duration, Instant};
34

@@ -6,6 +7,8 @@ use crate::rtp_::SeqNo;
67
use super::AckedPacket;
78

89
const BURST_TIME_INTERVAL: Duration = Duration::from_millis(5);
10+
const SEND_TIME_GROUP_LENGTH: Duration = Duration::from_millis(5);
11+
const MAX_BURST_DURATION: Duration = Duration::from_millis(100);
912

1013
#[derive(Debug, Default)]
1114
pub struct ArrivalGroup {
@@ -51,38 +54,47 @@ impl ArrivalGroup {
5154
return Belongs::Yes;
5255
};
5356

54-
let Some(send_diff) = packet
57+
let Some(first_send_delta) = packet
5558
.local_send_time
5659
.checked_duration_since(first_local_send_time)
5760
else {
5861
// Out of order
5962
return Belongs::Skipped;
6063
};
6164

62-
if send_diff < BURST_TIME_INTERVAL {
63-
// Sent within the same burst interval
64-
return Belongs::Yes;
65-
}
65+
let inter_arrival_time = {
66+
let last_remote_recv_time = self.remote_recv_time();
6667

67-
let inter_arrival_time = packet
68-
.remote_recv_time
69-
.checked_duration_since(self.remote_recv_time());
68+
if packet.remote_recv_time >= last_remote_recv_time {
69+
(packet.remote_recv_time - last_remote_recv_time).as_secs_f64()
70+
} else {
71+
(last_remote_recv_time - packet.remote_recv_time).as_secs_f64() * -1.0
72+
}
73+
};
7074

71-
let Some(inter_arrival_time) = inter_arrival_time else {
72-
info!("TWCC: Out of order arrival");
73-
return Belongs::Skipped;
75+
let last_send_delta = {
76+
let last_send_time = self.local_send_time();
77+
78+
match packet.local_send_time.cmp(&last_send_time) {
79+
Ordering::Equal => {
80+
return Belongs::Yes;
81+
}
82+
Ordering::Greater => (packet.local_send_time - last_send_time).as_secs_f64(),
83+
Ordering::Less => (last_send_time - packet.local_send_time).as_secs_f64() * -1.0,
84+
}
7485
};
7586

76-
let inter_group_delay_delta = inter_arrival_time.as_secs_f64()
77-
- (packet.local_send_time - self.local_send_time()).as_secs_f64();
87+
let inter_group_delay_delta = inter_arrival_time - last_send_delta;
7888

7989
if inter_group_delay_delta < 0.0
80-
&& inter_arrival_time < BURST_TIME_INTERVAL
81-
&& packet.remote_recv_time - first_remote_recv_time < Duration::from_millis(100)
90+
&& inter_arrival_time <= BURST_TIME_INTERVAL.as_secs_f64()
91+
&& packet.remote_recv_time - first_remote_recv_time < MAX_BURST_DURATION
8292
{
8393
Belongs::Yes
84-
} else {
94+
} else if first_send_delta > SEND_TIME_GROUP_LENGTH {
8595
Belongs::NewGroup
96+
} else {
97+
Belongs::Yes
8698
}
8799
}
88100

@@ -344,7 +356,7 @@ mod test {
344356
packets.push(AckedPacket {
345357
seq_no: 4.into(),
346358
size: DataSize::ZERO,
347-
local_send_time: now + duration_us(5001),
359+
local_send_time: now - duration_us(100),
348360
remote_recv_time: now + duration_us(5000),
349361
local_recv_time: now + duration_us(5050),
350362
});

0 commit comments

Comments
 (0)