Skip to content

RTMP/WHIP Stream "Tape Recorder Effect" During Packet Loss #350

@mpisat

Description

@mpisat

Description

When experiencing packet loss during WHIP streaming, the ingress pipeline exhibits a "tape recorder effect" where:

  1. Latency gradually increases
  2. 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.
  3. 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

  1. Set up a LiveKit ingress with WHIP input and transcoding enabled
  2. Stream with H.264 encoding
  3. Introduce network packet loss (can be simulated with network traffic shapers)
  4. Observe growing latency between source and output
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions