-
Notifications
You must be signed in to change notification settings - Fork 52
Description
Description
When experiencing packet loss during WHIP streaming, the ingress pipeline exhibits a "tape recorder effect" where:
- Latency gradually increases
- When RTMP publishing is stopped, the pipeline continues playing back buffered content for several seconds. We don't have this issue with WHIP because of WHIP delete session kicking in.
- The system never catches up to real-time after packet loss occurs
This creates a continuously growing delay between source and output, particularly noticeable in interactive streaming scenarios.
Root Cause
The targetMinQueueLength
constant in webrtc_sink.go
is set to 2
, which isn't aggressive enough for detecting when the pipeline should drop frames to catch up after packet loss. This results in the system preserving timing relationships rather than prioritizing real-time delivery.
Reproduction Steps
- Set up a LiveKit ingress with WHIP input and transcoding enabled
- Stream with H.264 encoding
- Introduce network packet loss (can be simulated with network traffic shapers)
- Observe growing latency between source and output
- Stop RTMP publishing and note that pipeline continues playing old content, if WHIP used, it can terminate with Delete request.
Solution
Setting targetMinQueueLength = 0
in webrtc_sink.go
resolves the issue by making the system more aggressive in detecting when it needs to drop frames to maintain real-time playback. This only works in packet loss scenario (tested with 2% upload packet loss, using H264 codec)
Proposed Fix
// In webrtc_sink.go
const (
targetMinQueueLength = 0 // Changed from 2
)
This simple change makes the system immediately respond to any queue buildup during packet loss by triggering the "playing too slow" condition and dropping frames to catch up.
Additional Context
This issue becomes particularly problematic in interactive streaming scenarios where maintaining low latency is critical. The current behavior prioritizes preserving all frames over maintaining real-time delivery.
Note: This fix resolves the issue for WHIP input specifically. RTMP input requires additional changes to address similar behavior.