Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(receive): Handle sleds of identical RTP timestamps #249

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ simd-json = { features = ["serde_impl"], optional = true, version = "0.13" }
socket2 = { optional = true, version = "0.5" }
streamcatcher = { optional = true, version = "1" }
stream_lib = { default-features = false, optional = true, version = "0.4.2" }
symphonia = { default_features = false, optional = true, version = "0.5.2" }
symphonia = { default-features = false, optional = true, version = "0.5.2" }
symphonia-core = { optional = true, version = "0.5.2" }
tokio = { default-features = false, optional = true, version = "1.0" }
tokio-tungstenite = { optional = true, version = "0.21" }
Expand Down
13 changes: 9 additions & 4 deletions src/driver/tasks/udp_rx/playout_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl PlayoutBuffer {
if desired_index < 0 {
trace!("Missed packet arrived late, discarding from playout.");
} else if desired_index >= 64 {
trace!("Packet arrived beyond playout max length.");
trace!("Packet arrived beyond playout max length: wanted slot {desired_index}.");
} else {
let index = desired_index as usize;
while self.buffer.len() <= index {
Expand All @@ -101,10 +101,15 @@ impl PlayoutBuffer {
let rtp = RtpPacket::new(&pkt.packet)
.expect("FATAL: earlier valid packet now invalid (fetch)");

// The curr_ts captures the current playout point; we want to
// be able to emit *all* packets with a smaller timestamp.
// However, we need to handle this in a wrap-safe way.
// ts_diff shows where the current time lies if we treat packet_ts
// as 0, s.t. ts_diff >= 0 (equiv) packet_time <= curr_time.
let curr_ts = self.current_timestamp.unwrap();
let ts_diff = curr_ts - rtp.get_timestamp().0;
let ts_diff = (curr_ts - rtp.get_timestamp().0).0 as i32;

if (ts_diff.0 as i32) <= 0 {
if ts_diff >= 0 {
self.next_seq = (rtp.get_sequence() + 1).0;

PacketLookup::Packet(pkt)
Expand Down Expand Up @@ -142,5 +147,5 @@ impl PlayoutBuffer {
#[inline]
fn reset_timeout(packet: &RtpPacket<'_>, config: &Config) -> RtpTimestamp {
let t_shift = MONO_FRAME_SIZE * config.playout_buffer_length.get();
(packet.get_timestamp() - (t_shift as u32)).0
(packet.get_timestamp() + (t_shift as u32)).0
}
Loading