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 {