Repository navigation
Description
LiveKit treats VP9 as an SVC-only codec (the simulcast field is ignored for VP9). For screen-share we needed VP9 simulcast (ONE_SPATIAL_LAYER_PER_STREAM, a separate RTP stream per resolution) — per-viewer resolution adaptation at constant fps, plus Android HW-decode of single-spatial rids. We got it working on a v1.11.0 fork and want to share the root causes in case they're useful upstream.
Symptom (v1.11.0): a single VP9-simulcast subscriber works for ~60 s (stable on its initial layer), then freezes the instant the allocator first switches layers (e.g. a BWE-driven upgrade). The forwarder enters a constant processSourceSwitch loop (~60/s), output timestamps freeze (extNextTS = extLastTS + 1), and a NACK/PLI storm follows. H.264/VP8 simulcast is unaffected.
Root causes & fixes (full write-up + diff, 5 files / ~35 lines on v1.11.0, running in production: https://github.com/SpeakNow06/livekit-server):
-
pkg/sfu/receiver_base.go— all rids collapse to spatial layer 0.if extPkt.Spatial >= 0 { spatialLayer = extPkt.Spatial }overrides the rid/uptrack index with the in-packet spatial id. Each VP9 simulcast rid is single-spatial → DDSpatialId == 0for every rid → all map tospatialLayer 0; the forwarder can't tell them apart and alternates SSRCs on every packet. (H.264/VP8 are unaffected becauseextPkt.Spatial == -1, so the override never fires.) Fix: apply the override only for SVC (single uptrack,layer == 0). -
pkg/sfu/forwarder.gogetRefLayerRTPTimestamp— the cross-layer SR timestamp offset never establishes (tsOffsetstays 0) → every switch errorsswitch point too far behind. Treating VP9 simulcast asONE_SPATIAL_LAYER_PER_STREAM_INCOMPLETE_RTCP_SR(setskipReferenceTS, fall back toextExpectedTS) makes switches work. -
pkg/sfu/forwarder.go— theDependencyDescriptorselector is wrong for separate-stream VP9 simulcast (it reports a switch on nearly every frame); theSimulcastselector (keyframe-based, used for VP8/H.264) is correct. -
pkg/sfu/buffer/dependencydescriptorparser.go— frame drops with frequent keyframes.structureExtFrameNumadvances on every structure-bearing keyframe (even whenStructureIdis unchanged), so reordered/retransmitted frames are dropped as "earlier than current structure" (severe withcontentHint=text/ screen content). Fix: advance the drop threshold only on an actualStructureIdchange.
Note: the client SDK also needs enabling — upstream livekit-client forces VP9 into SVC; VP9 simulcast requires signaling SimulcastCodec.videoLayerMode = ONE_SPATIAL_LAYER_PER_STREAM plus per-encoding scalabilityMode.
Happy to open a PR if there's interest in supporting VP9 simulcast.
Activity
cnderrauber commentedon Jun 15, 2026
Thank you for looking at this. Have you forked both the client and server repo? We'd be happy to accept the VP9 simulcast PR.
SpeakNow06 commentedon Jun 15, 2026
Yes, we forked both the client and the server. VP9 and AV1 can now be published as real simulcast, and
contentHint='text'works for both VP9 and AV1.Both forks plus a full write-up (with file:line references) are in one repo, on two branches:
https://github.com/SpeakNow06/livekit-server —
vp9-av1-simulcast-server(SFU fork) andvp9-av1-simulcast-client(client SDK fork). Write-up:VP9_AV1_SIMULCAST_PR_REPORT.md.Happy to open formal PRs against
livekit/livekitandlivekit/client-sdk-js— they need to land together since the SFU path only triggers when the client signals the mode.Fix VP9 simulcast freezing on first layer switch
cnderrauber commentedon Nov 10, 2026
Fix by #4830