Files
piik/docs/research/realtime-quality-adaptation.md
T

11 KiB

Realtime Screen-Share Quality Adaptation

  • Research date: 2026-08-19
  • Scope: realtime game screen sharing in the browser
  • Status: implementation input; real-device quality remains unverified

Finding

Screener should not optimize one quality dimension at the expense of the others. maintain-framerate may preserve motion by reducing resolution until game UI, maps, subtitles, and text become unreadable; maintain-resolution may instead lower frame rate. Neither preference overrides congestion control.

The current bounded implementation retains the game-oriented motion hint, defaults to maintain-resolution, and offers explicit balanced and fluid choices. This is a readability-first default, not a quality guarantee: the WebRTC API describes a user-agent preference rather than its algorithm, so Chromium, Firefox, and Safari behavior still needs measured comparison.

The inspected Chromium/libwebrtc source chain makes a screen-only shortcut especially unsafe to assume for Screener. The JavaScript motion hint reaches VideoRtpSender as kFluid, which explicitly clears options.is_screencast. WebRtcVideoSendStream then configures the encoder as kRealtimeVideo, while VideoStreamEncoder only reinterprets BALANCED as MAINTAIN_RESOLUTION when its encoder is marked as screen share. The explicit balanced preference still wins the earlier preference-selection branch, but the later screen-only remap does not follow from this project path. Treat the effective tradeoff as an implementation detail to verify, not a product guarantee.

An older libwebrtc experiment could detect animated screen content under balanced and cap it to 1280x720. Commit 1d7d0e6e2c50 deleted that experiment on 2024-05-22; the commit says it had already been disabled for several years and was not maintained. Current Chromium behavior must therefore not be described as automatically detecting game motion and forcing a 720p cap.

Production Degradation Report

On 2026-08-19 the deployed build was reported to deliver very low resolution, bitrate, and frame rate across all three profiles. This is a user observation, not yet an instrumented result. The highest-confidence explanation is the combination of one independent peer connection, sender, encoder pipeline, and upload copy per viewer with balanced adaptation: host CPU or uplink pressure can grow per edge, and the browser may then reduce both dimensions. The current peer-assisted and SFU drafts are not deployed, so relay re-encoding and LiveKit cannot explain that production observation.

One controlled capture should classify the problem before changing constants:

  1. Run the same high-motion scene for 60 to 90 seconds with one, two, then three viewers, plus one TURN/UDP case.
  2. Compare capture settings/media-source, outbound and inbound resolution/FPS, actual and target bitrate, codec and encoder implementation, interval encode cost, selected path, and qualityLimitationReason.
  3. Treat source-low as capture, outbound-low with cpu as encoder pressure, outbound-low with bandwidth as uplink/path pressure, and inbound-only loss or dropped/frozen frames as network or receiver pressure.
  4. Export chrome://webrtc-internals only as sensitive local evidence; remove SDP, candidate addresses, and other identifiers before sharing or retaining.

Missing scaleResolutionDownBy is not itself a root cause for a single encoding because its effective default is 1.0. Likewise, the current 3/5/8 Mbps values are ceilings rather than targets. Raising them cannot repair CPU or bandwidth limitation and should only follow evidence that the encoder is already pinned to the ceiling while spare transport capacity remains.

Why Offline Encoding Presets Do Not Transfer

Maruko Toolbox is an Apache-2.0 GUI around offline video-processing tools. Its x264-style CRF, slow presets, lookahead, and multi-pass workflows trade encoding time and buffering for file size and quality. Interactive WebRTC cannot buffer or revisit future frames in that way. The transferable principle is to treat bitrate, image detail, frame rate, and encode cost as a joint tradeoff; its concrete offline presets are not a WebRTC configuration baseline. The GUI repository is Apache-2.0, while x264 itself uses GPL-2.0 or commercial licensing; no implementation or preset is copied into Screener.

Discord's published Go Live design reaches the same broad conclusion for realtime game streaming: bandwidth estimates, frame delivery, image quality, latency, CPU, and memory conflict and must be balanced. Its native encoder tuning and hardware integration are not available to a browser-only sender and must not be presented as settings this project already has.

Current Policy

The three user-visible profiles remain ceilings rather than promised rates:

Profile Capture ceiling Sender bitrate ceiling
1080p60 1920x1080 at 60 fps 8 Mbps
1080p30 1920x1080 at 30 fps 5 Mbps
720p30 1280x720 at 30 fps 3 Mbps

The middle profile is an explicit manual 1080p30 ceiling: choosing it trades a 60 fps ceiling for a 1080p capture bound. LiveKit currently uses the same 1080p30 at 5 Mbps screen-share preset, but neither preset guarantees the emitted resolution, frame rate, or bitrate.

  • Initial capture supplies ideal and max bounds for resolution and frame rate; the actual result is read back from MediaStreamTrack.getSettings().
  • A live profile change uses track.applyConstraints() and updates every current sender with RTCRtpSender.setParameters(). It does not reopen the source picker or renegotiate healthy peer connections.
  • The video track keeps contentHint = "motion"; recommended profiles default to maintain-resolution, with explicit balanced and maintain-framerate choices. None promises an emitted resolution or rate.
  • maxBitrate and maxFramerate are ceilings. They are neither minimums nor target guarantees, and the project does not use SDP bitrate hacks.
  • The folded advanced panel accepts only 720p/1080p/1440p, integer 15-60 fps, 2-12 Mbps, and the three preferences. Audio stereo/bitrate is not exposed because standard sender controls cannot reliably guarantee the negotiated browser audio mode.
  • Every sender update derives from getParameters(), calls setParameters(), then reads requested/applied bitrate, frame rate, scale, and preference. Rejection or browser rewriting is visible rather than console-only.
  • One strict room setting is last-wins for current/future peer relays and the optional SFU publisher. Ordinary P2P keeps that state local and does not add it to the authenticated wire.
  • Pausing the picture disables the existing video track, producing black video without closing the room or media connection. Audio remains enabled.

The implementation deliberately stops at manual bounded controls. It adds no composite score, periodic adjustment, codec forcing, SDP bitrate manipulation, or scene detector. Three consecutive samples of one non-none native qualityLimitationReason produce one explanatory warning; a reason change or recovery resets it and never triggers a media action.

A Chromium 151 loopback smoke with one host, three viewers, and synthetic 720p30 video propagated balanced then clarity settings to every participant, displayed both sender preference readbacks, and preserved all peer-connection fingerprints. Host media edges peaked at two, relay edges at one, and all three viewers kept decoding. This verifies controls and connection preservation, not visual quality, full-resolution performance, CPU/GPU cost, public networks, or sustained behavior.

Deliberate Non-Goals

  • No canvas pixel-difference detector, machine-learned rate controller, or periodic profile switching.
  • No copied x264 CRF/preset recipe in the browser path.
  • No forced codec order until target hardware measurements identify the actual power-efficient encoder.
  • No promise that all browsers honor applyConstraints or degradation preference identically.
  • No automatic composite quality score or periodic profile controller before the controlled production capture identifies a reproducible bottleneck.

Verification Gate

Use the same static UI scene and deterministic high-motion game scene at 720p30, 1080p30, and 1080p60. Record actual capture and outbound dimensions/fps, bitrate, qualityLimitationReason, codec, encoder implementation, encode time, dropped frames, RTT, packet loss, and host CPU/GPU utilization. A live profile change must preserve peer connection IDs, avoid a second source prompt, and visibly converge to the requested bounds.

Compute per-frame encode and decode cost from adjacent samples of cumulative totalEncodeTime/totalDecodeTime and frame counters. The first sample, a zero-frame interval, changed stats object, or a counter reset is unknown and establishes a new baseline. Skip overlapping sampling ticks on the same peer so reports cannot complete out of order. Do not use a connection-lifetime average to judge a later overload. Use browser WebRTC diagnostics plus a small run manifest for time series and percentiles rather than adding a server telemetry pipeline.

Compare image readability and motion continuity instead of declaring success from FPS alone. If reproducible evidence later shows that balanced still oscillates or makes the wrong tradeoff on supported machines, revise the fixed profiles before adding an application-level adaptation controller.

Primary Sources