Skip to content

Commit

Permalink
Limit TWCC iterator with packet status count
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlapa authored Jan 7, 2025
1 parent 2135586 commit 621c91e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Make start of talkspurt information available for sample api #559
* Do not disconnect whilst we still check new candidates #489
* Ensure lexical ordering of SDP-formatted candidates follows priority #557
* Limit TWCC iteration with packet status count #606

# 0.6.2

Expand Down
32 changes: 31 additions & 1 deletion src/rtp/rtcp/twcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ impl Twcc {
let millis = self.reference_time as u64 * 64;
let time_base = time_zero + Duration::from_millis(millis);
let base_seq = extend_u16(Some(*extend_from), self.base_seq);
let last_seq = base_seq + self.status_count as u64;

TwccIter {
base_seq,
last_seq,
time_base,
index: 0,
twcc: self,
Expand All @@ -55,6 +58,7 @@ impl Twcc {

pub struct TwccIter {
base_seq: u64,
last_seq: u64,
time_base: Instant,
index: usize,
twcc: Twcc,
Expand All @@ -64,6 +68,12 @@ impl Iterator for TwccIter {
type Item = (SeqNo, PacketStatus, Option<Instant>);

fn next(&mut self) -> Option<Self::Item> {
let seq: SeqNo = (self.base_seq + self.index as u64).into();

if *seq == self.last_seq {
return None;
}

let head = self.twcc.chunks.front()?;

let (status, amount) = match head {
Expand Down Expand Up @@ -114,7 +124,6 @@ impl Iterator for TwccIter {
if let Some(new_timebase) = instant {
self.time_base = new_timebase;
}
let seq: SeqNo = (self.base_seq + self.index as u64).into();

self.index += 1;
if self.index == amount as usize {
Expand Down Expand Up @@ -1923,6 +1932,27 @@ mod test {
assert_eq!(result, expected);
}

#[test]
fn test_twcc_iter_limited_with_status_count() {
let status_count = 3;

// [(1, NotReceived), (2, ReceivedSmallDelta), (3, ReceivedSmallDelta)]
let twcc_iter_count = Twcc {
sender_ssrc: 1.into(),
ssrc: 2.into(),
base_seq: 1,
status_count,
reference_time: 406753,
feedback_count: 1,
chunks: VecDeque::from(vec![VectorDouble(0b00_00_01_01_00_00_00_00, 7)]),
delta: VecDeque::from(vec![Small(236), Small(1)]),
}
.into_iter(Instant::now(), 1.into())
.count();

assert_eq!(twcc_iter_count, status_count as usize);
}

#[test]
fn test_twcc_register_send_records() {
let mut reg = TwccSendRegister::new(25);
Expand Down

0 comments on commit 621c91e

Please sign in to comment.