Skip to content

VP9 simulcast (ONE_SPATIAL_LAYER_PER_STREAM) freezes on first layer switch — root causes + working fork #4594

Closed

Description

@SpeakNow06

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):

  1. 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 → DD SpatialId == 0 for every rid → all map to spatialLayer 0; the forwarder can't tell them apart and alternates SSRCs on every packet. (H.264/VP8 are unaffected because extPkt.Spatial == -1, so the override never fires.) Fix: apply the override only for SVC (single uptrack, layer == 0).

  2. pkg/sfu/forwarder.go getRefLayerRTPTimestamp — the cross-layer SR timestamp offset never establishes (tsOffset stays 0) → every switch errors switch point too far behind. Treating VP9 simulcast as ONE_SPATIAL_LAYER_PER_STREAM_INCOMPLETE_RTCP_SR (set skipReferenceTS, fall back to extExpectedTS) makes switches work.

  3. pkg/sfu/forwarder.go — the DependencyDescriptor selector is wrong for separate-stream VP9 simulcast (it reports a switch on nearly every frame); the Simulcast selector (keyframe-based, used for VP8/H.264) is correct.

  4. pkg/sfu/buffer/dependencydescriptorparser.go — frame drops with frequent keyframes. structureExtFrameNum advances on every structure-bearing keyframe (even when StructureId is unchanged), so reordered/retransmitted frames are dropped as "earlier than current structure" (severe with contentHint=text / screen content). Fix: advance the drop threshold only on an actual StructureId change.

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

  1. cnderrauber commented on Jun 15, 2026

    @cnderrauber
    Contributor

    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.

  2. SpeakNow06 commented on Jun 15, 2026

    @SpeakNow06
    Author

    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) and vp9-av1-simulcast-client (client SDK fork). Write-up: VP9_AV1_SIMULCAST_PR_REPORT.md.

    Happy to open formal PRs against livekit/livekit and livekit/client-sdk-js — they need to land together since the SFU path only triggers when the client signals the mode.

  3. added a commit that references this issue on Aug 2, 2026
    bb14091
  4. cnderrauber commented on Nov 10, 2026

    @cnderrauber
    Contributor

    Fix by #4830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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