From 870190624e1689594263ca38ee35b446b5470f9f Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 23 Feb 2022 00:04:18 +0530 Subject: [PATCH] Fix no-video with adaptive streaming (#456) * Fix no-video with adaptive streaming With a recent change to initialize max quality for subscriber synchronously, a subsequent update at the same quality was getting ignored. So, there was no message back to publisher to start up video layers. Reproducible every time the subscriber joined after all the layers of publishers was turned off. While not pretty, for now, disable the check for quality match on subscriber update. That disabling itself is fine as there is another check for consolidated quality match before sending a message to the publisher, but in general this area has shown some shakiness and needs some work. * Use notify function to set initial quality also --- pkg/rtc/mediatrackreceiver.go | 4 ++-- pkg/rtc/mediatracksubscriptions.go | 6 +++--- pkg/sfu/downtrack.go | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pkg/rtc/mediatrackreceiver.go b/pkg/rtc/mediatrackreceiver.go index f3e7cd1eb..badd0fc6b 100644 --- a/pkg/rtc/mediatrackreceiver.go +++ b/pkg/rtc/mediatrackreceiver.go @@ -179,8 +179,8 @@ func (t *MediaTrackReceiver) AddOnClose(f func()) { // AddSubscriber subscribes sub to current mediaTrack func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error { - t.lock.Lock() - defer t.lock.Unlock() + t.lock.RLock() + defer t.lock.RUnlock() if t.receiver == nil { // cannot add, no receiver diff --git a/pkg/rtc/mediatracksubscriptions.go b/pkg/rtc/mediatracksubscriptions.go index 9f74c18e9..34237aaf9 100644 --- a/pkg/rtc/mediatracksubscriptions.go +++ b/pkg/rtc/mediatracksubscriptions.go @@ -58,6 +58,7 @@ func NewMediaTrackSubscriptions(params MediaTrackSubscriptionsParams) *MediaTrac subscribedTracks: make(map[livekit.ParticipantID]types.SubscribedTrack), maxSubscriberQuality: make(map[livekit.ParticipantID]livekit.VideoQuality), maxSubscriberNodeQuality: make(map[livekit.NodeID]livekit.VideoQuality), + maxSubscribedQuality: livekit.VideoQuality_LOW, } return t @@ -256,10 +257,9 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, code sub.Negotiate() }() - t.maxQualityLock.Lock() // initialize to default layer - t.maxSubscriberQuality[sub.ID()] = livekit.VideoQuality_HIGH - t.maxQualityLock.Unlock() + t.notifySubscriberMaxQuality(subscriberID, livekit.VideoQuality_HIGH) + t.params.Telemetry.TrackSubscribed(context.Background(), subscriberID, t.params.MediaTrack.ToProto()) return downTrack, nil } diff --git a/pkg/sfu/downtrack.go b/pkg/sfu/downtrack.go index 9b0d7fc4d..53c759b57 100644 --- a/pkg/sfu/downtrack.go +++ b/pkg/sfu/downtrack.go @@ -633,11 +633,6 @@ func (d *DownTrack) OnRttUpdate(fn func(dt *DownTrack, rtt uint32)) { func (d *DownTrack) OnMaxLayerChanged(fn func(dt *DownTrack, layer int32)) { d.onMaxLayerChanged = fn - - // have to send this immediately to set initial values - if fn != nil && d.kind == webrtc.RTPCodecTypeVideo { - go fn(d, d.forwarder.MaxLayers().spatial) - } } func (d *DownTrack) IsDeficient() bool {