Share watcher that falls over 1 s behind (unbounded packet backlog after a stall, latency stuck at ~2.6 s) drops the backlog and resyncs on the next keyframe
Browse files at this commit03513699990c5eeb7a2d3c81830f3e22ffddeea3Parent: d58406a- fix
- share watcher that falls over 1 s behind (unbounded packet backlog after a stall, latency stuck at ~2.6 s) drops the backlog and resyncs on the next keyframe
1 changed file +9 -0
crates/client/src/share/session.rsmodified+9 -0
| @@ -60,6 +60,7 @@ const INITIAL_DELAY_MS: i64 = 100; | |||
| 60 | const MIN_DELAY_MS: i64 = 20; | 60 | const MIN_DELAY_MS: i64 = 20; |
| 61 | const MAX_DELAY_MS: i64 = 200; | 61 | const MAX_DELAY_MS: i64 = 200; |
| 62 | const RESYNC_MS: i64 = 2000; | 62 | const RESYNC_MS: i64 = 2000; |
| 63 | +const CATCH_UP_MS: i64 = 1000; | ||
| 63 | const DELAY_MARGIN_MS: i64 = 8; | 64 | const DELAY_MARGIN_MS: i64 = 8; |
| 64 | const DELAY_WINDOW_MS: i64 = 3000; | 65 | const DELAY_WINDOW_MS: i64 = 3000; |
| 65 | const DELAY_PERCENTILE: usize = 98; | 66 | const DELAY_PERCENTILE: usize = 98; |
| @@ -1074,6 +1075,14 @@ fn watch_video( | |||
| 1074 | while !stop.load(Ordering::Relaxed) { | 1075 | while !stop.load(Ordering::Relaxed) { |
| 1075 | match rx.recv_timeout(NACK_TICK) { | 1076 | match rx.recv_timeout(NACK_TICK) { |
| 1076 | Ok(bytes) => { | 1077 | Ok(bytes) => { |
| 1078 | + if let Some((_, Packet::Video { ts_ms, .. })) = split(&bytes) | ||
| 1079 | + && clock.now() - clock.origin(ts_ms) > CATCH_UP_MS | ||
| 1080 | + { | ||
| 1081 | + while rx.try_recv().is_ok() {} | ||
| 1082 | + reassembler = Reassembler::new(); | ||
| 1083 | + tracing::warn!("share watch fell behind, skipping to the next keyframe"); | ||
| 1084 | + continue; | ||
| 1085 | + } | ||
| 1077 | if let Some((_, packet)) = split(&bytes) | 1086 | if let Some((_, packet)) = split(&bytes) |
| 1078 | && let Some(last) = reassembler | 1087 | && let Some(last) = reassembler |
| 1079 | .push(&packet, Instant::now()) | 1088 | .push(&packet, Instant::now()) |