[Bug]: Missing WebRTC playoutDelayHint introduces 50-100ms artificial latency and redundant MediaStream recreation triggers video pipeline reload

Open
#523 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@MPoojaSiyag is already working on this.

Since Nov 26, 2026.

  • #524 by @MPoojaSiyag — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript, web-dev

Research direction

Read src/hooks/useWebRtcStream.ts around the pc.ontrack handler and ScreenMirror.tsx around the effect that assigns video.srcObject. Check how track additions update the stream reference and what receiver controls are supported. The linked pull request #524 is already open; compare its changes and tests with the reported startup flicker and playout delay.

Written by the indexing model from the issue text.

Description

bug enhancement
Bug Description
Summary

Rein is designed as a low-latency remote desktop and screen mirror aiming for sub-8ms response times. However, two issues in src/hooks/useWebRtcStream.ts introduce significant visual lag and a video pipeline reset on initial connection:

  1. Artificial Browser Jitter Buffer Delay (50ms–100ms):
    When WebRTC media tracks arrive in pc.ontrack (src/hooks/useWebRtcStream.ts, lines 255–275), low-latency playout hints (event.receiver.playoutDelayHint = 0 / jitterBufferTarget = 0) are not configured on the RTCRtpReceiver. By default, Chromium and other browsers treat incoming WebRTC tracks as conversational video calls, automatically buffering frames in an internal jitter buffer for 50ms to 100ms before rendering them to the <video> element. For real-time remote desktop interaction, this causes perceptible input-to-display lag.

  2. Redundant MediaStream Instantiation & Video Reload:
    The server streams both video and audio tracks. When the audio track arrives shortly after the video track (lines 264–268):

    if (!activeStream.getTracks().some((t) => t.id === event.track.id)) {
        activeStream.addTrack(event.track);
        setVideoStream(new MediaStream(activeStream.getTracks())); // Creates a brand new instance
    }
    

    This creates a brand new MediaStream instance and updates state. In ScreenMirror.tsx (lines 66–70), the effect detects video.srcObject !== videoStream and re-assigns video.srcObject = videoStream. Re-assigning srcObject on an actively playing HTML5 video element forces the browser to abort playback, re-run the media element load algorithm, and re-negotiate codecs. This results in a brief black frame flash and stalls stream startup.

Performance & Latency Impact
  • Latency: Adds an unnecessary 50ms–100ms playout delay to remote desktop mirroring.
  • Speed & Stability: Forces a redundant video decoder reload right after initial connection.
Steps to Reproduce
  1. Start the Rein host server (npm run dev).
  2. Open a client browser (e.g. Chrome 130+) and navigate to /trackpad.
  3. Observe the mirror startup: a brief black frame flash occurs when the audio track arrives and re-assigns video.srcObject.
  4. Open chrome://webrtc-internals in another tab, locate the Inbound RTP video stream, and inspect jitterBufferDelay / playoutDelay: observe ~50ms–100ms buffer delay instead of near-zero playout latency.
  5. Move the cursor on the trackpad and notice the visual lag on the mirrored screen.
Expected Behavior
  1. The video receiver should set receiver.playoutDelayHint = 0 (and jitterBufferTarget = 0 where supported) to instruct the browser decoder to render frames immediately without artificial buffering.
  2. The client should retain a stable MediaStream reference across track additions so video.srcObject is assigned once, eliminating the video reload and black frame flicker.
Desktop Operating System

Windows 11

Client OS and browser

Chrome 130+ on Windows

Rein Version

1.0.0

Console Logs / Error Messages (Optional)
[WebRTC] Received track: video
[WebRTC] Received track: audio
[ScreenMirror] User interaction detected

Screenshots / Recordings (Optional)
Checklist
  • I have searched for existing issues to avoid duplicates
Dominant language
TypeScript
Stars
55
Forks
120
Avg merge
4d 5h
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AOSSIE-Org/Rein

All issues in AOSSIE-Org/Rein

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.