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:
CloudWebRTC
2026-06-19 20:12:54 +08:00
committed by GitHub
co-authored by Claude Opus 4.8 Copilot Autofix powered by AI
parent a011d995da
commit cfedcc71d0
12 changed files with 314 additions and 19 deletions
+10 -9
View File
@@ -104,15 +104,16 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
t.subscribedTracksMu.Unlock()
subTrack, err := NewSubscribedTrack(SubscribedTrackParams{
ReceiverConfig: t.params.ReceiverConfig,
SubscriberConfig: t.params.SubscriberConfig,
Subscriber: sub,
MediaTrack: t.params.MediaTrack,
AdaptiveStream: sub.GetAdaptiveStream(),
TelemetryListener: sub.GetTelemetryListener(),
WrappedReceiver: wr,
IsRelayed: t.params.IsRelayed,
OnDownTrackCreated: t.onDownTrackCreated,
ReceiverConfig: t.params.ReceiverConfig,
SubscriberConfig: t.params.SubscriberConfig,
Subscriber: sub,
MediaTrack: t.params.MediaTrack,
AdaptiveStream: sub.GetAdaptiveStream(),
EnableStartAtDesiredQuality: sub.GetEnableStartAtDesiredQuality(),
TelemetryListener: sub.GetTelemetryListener(),
WrappedReceiver: wr,
IsRelayed: t.params.IsRelayed,
OnDownTrackCreated: t.onDownTrackCreated,
OnDownTrackClosed: func(subscriberID livekit.ParticipantID) {
t.subscribedTracksMu.Lock()
delete(t.subscribedTracks, subscriberID)
+5
View File
@@ -225,6 +225,7 @@ type ParticipantParams struct {
EnableRTPStreamRestartDetection bool
ForceBackupCodecPolicySimulcast bool
DisableTransceiverReuseForE2EE bool
EnableStartAtDesiredQuality bool
}
type ParticipantImpl struct {
@@ -505,6 +506,10 @@ func (p *ParticipantImpl) GetAdaptiveStream() bool {
return p.params.AdaptiveStream
}
func (p *ParticipantImpl) GetEnableStartAtDesiredQuality() bool {
return p.params.EnableStartAtDesiredQuality
}
func (p *ParticipantImpl) GetPacer() pacer.Pacer {
return p.TransportManager.GetSubscriberPacer()
}
+8 -1
View File
@@ -48,6 +48,7 @@ type SubscribedTrackParams struct {
Subscriber types.LocalParticipant
MediaTrack types.MediaTrack
AdaptiveStream bool
EnableStartAtDesiredQuality bool
TelemetryListener types.ParticipantTelemetryListener
WrappedReceiver *WrappedReceiver
IsRelayed bool
@@ -154,6 +155,7 @@ func NewSubscribedTrack(params SubscribedTrackParams) (*SubscribedTrack, error)
RTCPWriter: params.Subscriber.WriteSubscriberRTCP,
DisableSenderReportPassThrough: params.Subscriber.GetDisableSenderReportPassThrough(),
SupportsCodecChange: params.Subscriber.SupportsCodecChange(),
EnableStartAtDesiredQuality: params.EnableStartAtDesiredQuality,
Listener: s,
})
if err != nil {
@@ -212,7 +214,12 @@ func (t *SubscribedTrack) Bound(err error) {
t.logger.Debugw("enabling subscriber track settings on bind", "settings", logger.Proto(t.settings))
}
} else {
if t.params.AdaptiveStream {
if t.params.EnableStartAtDesiredQuality {
// default to HIGH quality so the subscriber acquires the top layer directly instead of
// ramping up from a lower layer. adaptive stream clients can still scale down afterwards
// based on viewport.
t.settings = &livekit.UpdateTrackSettings{Quality: livekit.VideoQuality_HIGH}
} else if t.params.AdaptiveStream {
t.settings = &livekit.UpdateTrackSettings{Quality: livekit.VideoQuality_LOW}
} else {
t.settings = &livekit.UpdateTrackSettings{Quality: livekit.VideoQuality_HIGH}
+1
View File
@@ -403,6 +403,7 @@ type LocalParticipant interface {
GetReporter() roomobs.ParticipantSessionReporter
GetReporterResolver() roomobs.ParticipantReporterResolver
GetAdaptiveStream() bool
GetEnableStartAtDesiredQuality() bool
ProtocolVersion() ProtocolVersion
SupportsSyncStreamID() bool
SupportsTransceiverReuse(mt MediaTrack) bool
@@ -325,6 +325,16 @@ type FakeLocalParticipant struct {
getDisableSenderReportPassThroughReturnsOnCall map[int]struct {
result1 bool
}
GetEnableStartAtDesiredQualityStub func() bool
getEnableStartAtDesiredQualityMutex sync.RWMutex
getEnableStartAtDesiredQualityArgsForCall []struct {
}
getEnableStartAtDesiredQualityReturns struct {
result1 bool
}
getEnableStartAtDesiredQualityReturnsOnCall map[int]struct {
result1 bool
}
GetEnabledPublishCodecsStub func() []*livekit.Codec
getEnabledPublishCodecsMutex sync.RWMutex
getEnabledPublishCodecsArgsForCall []struct {
@@ -3079,6 +3089,59 @@ func (fake *FakeLocalParticipant) GetDisableSenderReportPassThroughReturnsOnCall
}{result1}
}
func (fake *FakeLocalParticipant) GetEnableStartAtDesiredQuality() bool {
fake.getEnableStartAtDesiredQualityMutex.Lock()
ret, specificReturn := fake.getEnableStartAtDesiredQualityReturnsOnCall[len(fake.getEnableStartAtDesiredQualityArgsForCall)]
fake.getEnableStartAtDesiredQualityArgsForCall = append(fake.getEnableStartAtDesiredQualityArgsForCall, struct {
}{})
stub := fake.GetEnableStartAtDesiredQualityStub
fakeReturns := fake.getEnableStartAtDesiredQualityReturns
fake.recordInvocation("GetEnableStartAtDesiredQuality", []interface{}{})
fake.getEnableStartAtDesiredQualityMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *FakeLocalParticipant) GetEnableStartAtDesiredQualityCallCount() int {
fake.getEnableStartAtDesiredQualityMutex.RLock()
defer fake.getEnableStartAtDesiredQualityMutex.RUnlock()
return len(fake.getEnableStartAtDesiredQualityArgsForCall)
}
func (fake *FakeLocalParticipant) GetEnableStartAtDesiredQualityCalls(stub func() bool) {
fake.getEnableStartAtDesiredQualityMutex.Lock()
defer fake.getEnableStartAtDesiredQualityMutex.Unlock()
fake.GetEnableStartAtDesiredQualityStub = stub
}
func (fake *FakeLocalParticipant) GetEnableStartAtDesiredQualityReturns(result1 bool) {
fake.getEnableStartAtDesiredQualityMutex.Lock()
defer fake.getEnableStartAtDesiredQualityMutex.Unlock()
fake.GetEnableStartAtDesiredQualityStub = nil
fake.getEnableStartAtDesiredQualityReturns = struct {
result1 bool
}{result1}
}
func (fake *FakeLocalParticipant) GetEnableStartAtDesiredQualityReturnsOnCall(i int, result1 bool) {
fake.getEnableStartAtDesiredQualityMutex.Lock()
defer fake.getEnableStartAtDesiredQualityMutex.Unlock()
fake.GetEnableStartAtDesiredQualityStub = nil
if fake.getEnableStartAtDesiredQualityReturnsOnCall == nil {
fake.getEnableStartAtDesiredQualityReturnsOnCall = make(map[int]struct {
result1 bool
})
}
fake.getEnableStartAtDesiredQualityReturnsOnCall[i] = struct {
result1 bool
}{result1}
}
func (fake *FakeLocalParticipant) GetEnabledPublishCodecs() []*livekit.Codec {
fake.getEnabledPublishCodecsMutex.Lock()
ret, specificReturn := fake.getEnabledPublishCodecsReturnsOnCall[len(fake.getEnabledPublishCodecsArgsForCall)]