feat: acquire requested video layer directly at HIGH quality by default (#4595)
* feat: acquire requested video layer directly at HIGH quality by default Two changes that together remove the visible low->high quality ramp for a new subscriber (both publisher-first and subscriber-first join orders): 1. Default a subscriber's initial video quality to HIGH on bind instead of LOW for adaptive stream, so the subscribed max layer is the top layer. Adaptive stream clients can still scale down afterwards based on viewport. 2. On initial layer acquisition the forwarder/selector latch directly onto the allocator's target (the requested top layer) instead of opportunistically latching onto the first lower key frame that arrives. A short initial-acquisition grace aims the target at the requested layer; if it does not show up in time, the target falls back to the highest layer seen so acquisition never stalls. Always on - no configuration flag. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat: gate start-at-desired-quality behind EnableStartAtDesiredQuality flag Put the "acquire requested video layer directly at HIGH quality" behavior behind a per-subscriber EnableStartAtDesiredQuality flag (default off, so the original low->high ramp-up is restored unless enabled). Plumbed from config.RTC.EnableStartAtDesiredQuality through ParticipantParams -> SubscribedTrack/DownTrack -> Forwarder -> simulcast selector, gating all three behavior changes: the HIGH default on bind, the forwarder's initial-acquisition grace, and the selector's direct-latch-onto-target. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * remove config. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
Copilot Autofix powered by AI
parent
a011d995da
commit
cfedcc71d0
@@ -39,6 +39,7 @@ func newForwarder(codec webrtc.RTPCodecCapability, kind webrtc.RTPCodecType) *Fo
|
||||
logger.GetLogger(),
|
||||
true, // skipReferenceTS
|
||||
true, // disableOpportunisticAllocation
|
||||
true, // enableStartAtDesiredQuality
|
||||
nil,
|
||||
)
|
||||
f.DetermineCodec(codec, nil, livekit.VideoLayer_MODE_UNUSED)
|
||||
@@ -2145,3 +2146,44 @@ func TestForwarderGetPaddingVP8(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, marshalledVP8, buf)
|
||||
}
|
||||
|
||||
func TestForwarderInitialAcquisitionGrace(t *testing.T) {
|
||||
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
||||
|
||||
// subscriber requested the top spatial layer
|
||||
f.SetMaxSpatialLayer(buffer.DefaultMaxLayerSpatial)
|
||||
f.SetMaxTemporalLayer(buffer.DefaultMaxLayerTemporal)
|
||||
f.SetMaxTemporalLayerSeen(buffer.DefaultMaxLayerTemporal)
|
||||
|
||||
bitrates := Bitrates{
|
||||
{2, 3, 0, 0},
|
||||
{4, 0, 0, 5},
|
||||
{0, 7, 0, 0},
|
||||
}
|
||||
|
||||
// subscriber-first: only layer 1 has been seen so far and nothing is being forwarded yet
|
||||
// (current invalid). this arms the initial-acquisition grace.
|
||||
require.True(t, f.SetMaxPublishedLayer(1))
|
||||
f.lock.RLock()
|
||||
require.True(t, f.withinAcquireGraceLocked())
|
||||
f.lock.RUnlock()
|
||||
|
||||
// during the grace, the target aims straight at the requested layer (2) and requests a key
|
||||
// frame for it, even though only layer 1 has been seen - so acquisition does not ramp up
|
||||
// gradually as higher layers are detected
|
||||
alloc := f.AllocateOptimal([]int32{0, 1}, bitrates, false, false)
|
||||
require.Equal(t, int32(2), alloc.TargetLayer.Spatial)
|
||||
require.Equal(t, int32(2), alloc.RequestLayerSpatial)
|
||||
|
||||
// force the grace to expire while still not streaming: must signal that a re-allocation is
|
||||
// needed so the target can fall back
|
||||
f.acquireDeadline = 1 // a deadline far in the past
|
||||
require.True(t, f.MaybeExpireAcquireGrace())
|
||||
require.False(t, f.MaybeExpireAcquireGrace()) // only fires once
|
||||
|
||||
// after the grace, the target falls back to the highest layer actually seen (1) instead of
|
||||
// stalling while waiting for a requested layer that never showed up
|
||||
alloc = f.AllocateOptimal([]int32{0, 1}, bitrates, false, false)
|
||||
require.Equal(t, int32(1), alloc.TargetLayer.Spatial)
|
||||
require.Equal(t, int32(1), alloc.RequestLayerSpatial)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user