Skip to content

fix: let VP9/AV1 simulcast subscribers reach the target temporal layer - #4961

Closed
obcached wants to merge 2 commits into
livekit:masterfrom
obcached:fix/vp9-simulcast-temporal-layer
Closed

obcached wants to merge 2 commits into
livekit:masterfrom
obcached:fix/vp9-simulcast-temporal-layer

Conversation

@obcached

@obcached obcached commented Oct 7, 2026

Copy link
Copy Markdown

Title

fix: let VP9/AV1 simulcast subscribers reach the target temporal layer

Problem

With VP9/AV1 published as rid simulcast with temporal layers (L1T2/L1T3), a subscriber moved to a lower rid
for congestion never comes back up after the link recovers: the allocator stays DEFICIENT and never probes.
VP9 k-SVC, VP8/H.264 simulcast and VP9 simulcast with L1T1 recover fine.

Root cause

VP9/AV1 simulcast use the Simulcast selector without a temporal layer selector
(forwarder.go#L423-L430),
so all temporal layers are forwarded, but on a spatial switch the current temporal layer is set to the key
frame's TID (0) and never moves again
(simulcast.go#L125-L128).
The target temporal layer is 2 for L1T3, so GetNextHigherTransition sees a pending target forever
(forwarder.go#L1557-L1561)
and maybeProbeWithPadding never probes
(streamallocator.go#L1356-L1361).

Fix

In Simulcast.Select, when no temporal layer selector is set, the current temporal layer follows the target.
VP8 (has a temporal layer selector), H.264 (target already clamped to 0) and the SVC selectors are unaffected.

Not addressed here: after a codec change from VP8 to VP9/AV1/H.265 simulcast, the down track keeps the VP8
temporal layer selector, so this fix doesn't apply to it. Clearing the selector in the non-VP8 branches of
DetermineCodec would fix that; happy to send it separately.

Tests

  • TestForwarderSimulcastTemporalLayerAfterSwitch: transition unavailable before the switch key frame, available
    after. VP9/AV1 L1T3 fail on master; VP9 L1T1, H.264 and VP8 pass on both.
  • TestSimulcastSelectCurrentTemporalFollowsTargetWithoutTemporalLayerSelector (fails on master) and
    TestSimulcastSelectTemporalLayerSelectorOwnsCurrentTemporal.
  • go test -race ./pkg/sfu/... and golangci-lint pass.

Observed

v1.13.8 (same code as master), JS SDK, VP9 rid simulcast 720p/1080p, subscriber download capped at 600 kbit/s
for 60 s then restored:

encodings probes after recovery subscriber after restore
VP9 simulcast L1T3 (7 runs) 0 stuck on the lower rid (120 s; 300 s with the cap removed)
VP9 simulcast L1T1 8-13 back on the top rid in 3-6 s
VP9 k-SVC L3T3_KEY 15-17 top layer in 8-10 s

VP9, AV1 and H.265 simulcast use the Simulcast video layer selector
without a temporal layer selector, so every temporal layer of the
selected spatial layer is forwarded. On a spatial switch the selector set
the current temporal layer to that of the switch key frame (always 0) and
nothing moved it afterwards. With L1T2/L1T3 encodings the allocator target
temporal layer is higher, so the target stayed pending forever:
GetNextHigherTransition refused every transition and the stream allocator
never probed, leaving a subscriber that was down-switched for congestion
on the lower layer for the rest of the session.

When no temporal layer selector is set, report the current temporal layer
as the target, both at a spatial switch and when only the target temporal
layer changes. H.264 is unaffected in practice (its target temporal layer
is already clamped to 0). VP8 (which has a temporal layer selector) and
the SVC selectors are unchanged.
@obcached
obcached requested a review from a team as a code owner October 7, 2026 21:16
@CLAassistant

CLAassistant commented Oct 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

devin-ai-integration[bot]

This comment was marked as resolved.

A VP8 down track installs a VP8 temporal layer selector. On a codec change
to VP9/AV1 simulcast (or H.264/H.265), the new selector is built from the
previous one and keeps its Base, including that VP8 temporal layer
selector. It cannot parse the new codec's payloads, so the current
temporal layer never moves and the temporal layer recovery for selectors
without a temporal layer selector never runs.

Clear the temporal layer selector before configuring the new codec; the
VP8 branch sets its own as before.
@obcached
obcached marked this pull request as draft October 9, 2026 06:02
@obcached

obcached commented Oct 9, 2026

Copy link
Copy Markdown
Author

Measurements show that unblocking temporal probing without TID filtering lets the forwarder send all temporal layers while the allocator budgets a lower one (~1.6× overshoot), causing probe/overshoot cycles under constrained downlinks. Adding a VP9/AV1 simulcast temporal-layer selector before re-requesting review...

@boks1971

Copy link
Copy Markdown
Contributor

Addressed this in #4991 and some subsequent PRs. Can you please try the latest and open an issue if that does not work?

@boks1971 boks1971 closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants