From d0bbea6e91034812a2bd4aeec817a00cbbd79683 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sun, 3 Jul 2022 09:50:14 +0530 Subject: [PATCH] Force send dynacast update on unmute. (#802) As there is a queue to send dynacast update, forcing an update on unmute should be fine. That will send the current state. If the subscribers change it, an update will be sent as necessary. This addresses the case of subscription changes happening when the published track is muted. Dynacast updates are not sent when publisher tarck is muted. If on unmute, if subscribers do not have any changes, an update is missed (i. e. the changes that happen when publisher track is muted is not sent). --- pkg/rtc/mediatracksubscriptions.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/rtc/mediatracksubscriptions.go b/pkg/rtc/mediatracksubscriptions.go index a8f3c92c9..cacf43872 100644 --- a/pkg/rtc/mediatracksubscriptions.go +++ b/pkg/rtc/mediatracksubscriptions.go @@ -128,6 +128,13 @@ func (t *MediaTrackSubscriptions) OnDownTrackCreated(f func(downTrack *sfu.DownT } func (t *MediaTrackSubscriptions) SetMuted(muted bool) { + // update quality based on subscription if unmuting. + // This will queue up the current state, but subscriber + // driven changes could update it. + if !muted { + t.updateQualityChange(true) + } + // update mute of all subscribed tracks for _, st := range t.getAllSubscribedTracks() { st.SetPublisherMuted(muted) @@ -641,7 +648,7 @@ func (t *MediaTrackSubscriptions) notifySubscriberMaxQuality(subscriberID liveki } t.maxQualityLock.Unlock() - t.UpdateQualityChange(false) + t.updateQualityChange(false) } func (t *MediaTrackSubscriptions) NotifySubscriberNodeMaxQuality(nodeID livekit.NodeID, qualities []types.SubscribedCodecQuality) { @@ -687,10 +694,10 @@ func (t *MediaTrackSubscriptions) NotifySubscriberNodeMaxQuality(nodeID livekit. } t.maxQualityLock.Unlock() - t.UpdateQualityChange(false) + t.updateQualityChange(false) } -func (t *MediaTrackSubscriptions) UpdateQualityChange(force bool) { +func (t *MediaTrackSubscriptions) updateQualityChange(force bool) { if t.params.MediaTrack.Kind() != livekit.TrackType_VIDEO { return } @@ -753,11 +760,11 @@ func (t *MediaTrackSubscriptions) UpdateQualityChange(force bool) { noChangeCount++ } } - t.params.Logger.Debugw("updating quality change", + t.params.Logger.Debugw("updated quality change", "changed", changed, "maxSubscribedQuality", maxSubscribedQuality, "t.maxSubscribedQuality", t.maxSubscribedQuality, - "comesDownQuality", qualityDowngrades) + "qualityDowngrades", qualityDowngrades) if !changed && !force { t.maxQualityLock.Unlock() @@ -767,7 +774,7 @@ func (t *MediaTrackSubscriptions) UpdateQualityChange(force bool) { // if quality downgrade (or become OFF), delay notify to publisher if needed if len(qualityDowngrades) > 0 && !force { t.maxSubscribedQualityDebounce(func() { - t.UpdateQualityChange(true) + t.updateQualityChange(true) }) // no quality upgrades @@ -829,7 +836,7 @@ func (t *MediaTrackSubscriptions) startMaxQualityTimer(force bool) { t.maxQualityTimer = time.AfterFunc(initialQualityUpdateWait, func() { t.stopMaxQualityTimer() - t.UpdateQualityChange(force) + t.updateQualityChange(force) }) }