Skip to content

Commit

Permalink
Merge pull request #20 from jaymell/wrapping-add-timestamp
Browse files Browse the repository at this point in the history
use wrapping_add to prevent overflow panic -- fixes webrtc-rs/rtp#19
  • Loading branch information
rainliu committed Dec 6, 2021
2 parents 7e5107a + 3bce313 commit 5ccc16d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/rtp/src/packetizer/mod.rs
Expand Up @@ -135,7 +135,7 @@ impl Packetizer for PacketizerImpl {
i += 1;
}

self.timestamp += samples;
self.timestamp.wrapping_add(samples);

if l != 0 && self.abs_send_time != 0 {
let st = if let Some(fn_time_gen) = &self.time_gen {
Expand Down
13 changes: 13 additions & 0 deletions crates/rtp/src/packetizer/packetizer_test.rs
Expand Up @@ -93,3 +93,16 @@ async fn test_packetizer_abs_send_time() -> Result<()> {

Ok(())
}

#[tokio::test]
async fn test_packetizer_timestamp_rollover_does_not_panic() -> Result<()> {
let g722 = Box::new(g7xx::G722Payloader {});
let seq = Box::new(new_random_sequencer());

let payload = Bytes::from_static(&[0; 128]);
let mut packetizer = new_packetizer(100, 98, 0x1234ABCD, g722, seq, 90000);

packetizer.packetize(&payload, u64::MAX as _).await?;

Ok(())
}

0 comments on commit 5ccc16d

Please sign in to comment.