* Consolidating PLI throttle

Use the throttler in `sfu.WebRTCReceiver`.

Does change shape of config object.

* Move PLIThrottleConfig to sfu.WebRTCReceiver

* fix test compile

* Cleaning up unused stuff

* improve readability

* RTT

- Calculate down track RTT using RTCP Receiver report
- Surface it back to the participant
- Participant updates all its published trackes
  (throttled to limit update to once in 5 seconds)
- That propagates to all the upstream sfu.Buffer and the nacker.
  So, we will have RTT throttled NACKs.

* rtt callback
This commit is contained in:
Raja Subramanian
2022-02-09 09:34:40 +05:30
committed by GitHub
parent 562546829b
commit 222b02aa73
10 changed files with 156 additions and 108 deletions
+9
View File
@@ -236,3 +236,12 @@ func (t *MediaTrack) GetConnectionScore() float32 {
return receiver.(*sfu.WebRTCReceiver).GetConnectionScore()
}
func (t *MediaTrack) SetRTT(rtt uint32) {
receiver := t.Receiver()
if receiver == nil {
return
}
receiver.(*sfu.WebRTCReceiver).SetRTT(rtt)
}
+4
View File
@@ -199,6 +199,10 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, code
t.notifySubscriberMaxQuality(subscriberID, QualityForSpatialLayer(layer))
})
downTrack.OnRttUpdate(func(_ *sfu.DownTrack, rtt uint32) {
go sub.UpdateRTT(rtt)
})
downTrack.OnCloseHandler(func() {
t.subscribedTracksMu.Lock()
delete(t.subscribedTracks, subscriberID)
+21
View File
@@ -33,6 +33,7 @@ const (
lossyDataChannel = "_lossy"
reliableDataChannel = "_reliable"
sdBatchSize = 20
rttUpdateInterval = 5 * time.Second
)
type pendingTrackInfo struct {
@@ -102,6 +103,9 @@ type ParticipantImpl struct {
// keep track of other publishers identities that we are subscribed to
subscribedTo sync.Map // livekit.ParticipantID => struct{}
rttUpdatedAt time.Time
lastRTT uint32
lock sync.RWMutex
once sync.Once
updateLock sync.Mutex
@@ -131,6 +135,7 @@ func NewParticipant(params ParticipantParams, perms *livekit.ParticipantPermissi
subscribedTracksSettings: make(map[livekit.TrackID]*livekit.UpdateTrackSettings),
disallowedSubscriptions: make(map[livekit.TrackID]livekit.ParticipantID),
connectedAt: time.Now(),
rttUpdatedAt: time.Now(),
version: params.InitialVersion,
}
p.migrateState.Store(types.MigrateStateInit)
@@ -932,6 +937,22 @@ func (p *ParticipantImpl) SubscriptionPermissionUpdate(publisherID livekit.Parti
}
}
func (p *ParticipantImpl) UpdateRTT(rtt uint32) {
now := time.Now()
p.lock.Lock()
if now.Sub(p.rttUpdatedAt) < rttUpdateInterval || p.lastRTT == rtt {
p.lock.Unlock()
return
}
p.rttUpdatedAt = now
p.lastRTT = rtt
p.lock.Unlock()
for _, pt := range p.GetPublishedTracks() {
pt.(types.LocalMediaTrack).SetRTT(rtt)
}
}
func (p *ParticipantImpl) setupUpTrackManager() {
p.UpTrackManager = NewUpTrackManager(UpTrackManagerParams{
SID: p.params.SID,
+4
View File
@@ -153,6 +153,8 @@ type LocalParticipant interface {
MigrateState() MigrateState
AddMigratedTrack(cid string, ti *livekit.TrackInfo)
SetPreviousAnswer(previous *webrtc.SessionDescription)
UpdateRTT(rtt uint32)
}
// Room is a container of participants, and can provide room-level actions
@@ -215,6 +217,8 @@ type LocalMediaTrack interface {
GetAudioLevel() (level uint8, active bool)
GetConnectionScore() float32
SetRTT(rtt uint32)
}
// MediaTrack is the main interface representing a track published to the room
@@ -199,6 +199,11 @@ type FakeLocalMediaTrack struct {
setMutedArgsForCall []struct {
arg1 bool
}
SetRTTStub func(uint32)
setRTTMutex sync.RWMutex
setRTTArgsForCall []struct {
arg1 uint32
}
SignalCidStub func() string
signalCidMutex sync.RWMutex
signalCidArgsForCall []struct {
@@ -1261,6 +1266,38 @@ func (fake *FakeLocalMediaTrack) SetMutedArgsForCall(i int) bool {
return argsForCall.arg1
}
func (fake *FakeLocalMediaTrack) SetRTT(arg1 uint32) {
fake.setRTTMutex.Lock()
fake.setRTTArgsForCall = append(fake.setRTTArgsForCall, struct {
arg1 uint32
}{arg1})
stub := fake.SetRTTStub
fake.recordInvocation("SetRTT", []interface{}{arg1})
fake.setRTTMutex.Unlock()
if stub != nil {
fake.SetRTTStub(arg1)
}
}
func (fake *FakeLocalMediaTrack) SetRTTCallCount() int {
fake.setRTTMutex.RLock()
defer fake.setRTTMutex.RUnlock()
return len(fake.setRTTArgsForCall)
}
func (fake *FakeLocalMediaTrack) SetRTTCalls(stub func(uint32)) {
fake.setRTTMutex.Lock()
defer fake.setRTTMutex.Unlock()
fake.SetRTTStub = stub
}
func (fake *FakeLocalMediaTrack) SetRTTArgsForCall(i int) uint32 {
fake.setRTTMutex.RLock()
defer fake.setRTTMutex.RUnlock()
argsForCall := fake.setRTTArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalMediaTrack) SignalCid() string {
fake.signalCidMutex.Lock()
ret, specificReturn := fake.signalCidReturnsOnCall[len(fake.signalCidArgsForCall)]
@@ -1502,6 +1539,8 @@ func (fake *FakeLocalMediaTrack) Invocations() map[string][][]interface{} {
defer fake.sdpCidMutex.RUnlock()
fake.setMutedMutex.RLock()
defer fake.setMutedMutex.RUnlock()
fake.setRTTMutex.RLock()
defer fake.setRTTMutex.RUnlock()
fake.signalCidMutex.RLock()
defer fake.signalCidMutex.RUnlock()
fake.sourceMutex.RLock()
@@ -550,6 +550,11 @@ type FakeLocalParticipant struct {
updateMediaLossReturnsOnCall map[int]struct {
result1 error
}
UpdateRTTStub func(uint32)
updateRTTMutex sync.RWMutex
updateRTTArgsForCall []struct {
arg1 uint32
}
UpdateSubscribedQualityStub func(string, livekit.TrackID, livekit.VideoQuality) error
updateSubscribedQualityMutex sync.RWMutex
updateSubscribedQualityArgsForCall []struct {
@@ -3532,6 +3537,38 @@ func (fake *FakeLocalParticipant) UpdateMediaLossReturnsOnCall(i int, result1 er
}{result1}
}
func (fake *FakeLocalParticipant) UpdateRTT(arg1 uint32) {
fake.updateRTTMutex.Lock()
fake.updateRTTArgsForCall = append(fake.updateRTTArgsForCall, struct {
arg1 uint32
}{arg1})
stub := fake.UpdateRTTStub
fake.recordInvocation("UpdateRTT", []interface{}{arg1})
fake.updateRTTMutex.Unlock()
if stub != nil {
fake.UpdateRTTStub(arg1)
}
}
func (fake *FakeLocalParticipant) UpdateRTTCallCount() int {
fake.updateRTTMutex.RLock()
defer fake.updateRTTMutex.RUnlock()
return len(fake.updateRTTArgsForCall)
}
func (fake *FakeLocalParticipant) UpdateRTTCalls(stub func(uint32)) {
fake.updateRTTMutex.Lock()
defer fake.updateRTTMutex.Unlock()
fake.UpdateRTTStub = stub
}
func (fake *FakeLocalParticipant) UpdateRTTArgsForCall(i int) uint32 {
fake.updateRTTMutex.RLock()
defer fake.updateRTTMutex.RUnlock()
argsForCall := fake.updateRTTArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) UpdateSubscribedQuality(arg1 string, arg2 livekit.TrackID, arg3 livekit.VideoQuality) error {
fake.updateSubscribedQualityMutex.Lock()
ret, specificReturn := fake.updateSubscribedQualityReturnsOnCall[len(fake.updateSubscribedQualityArgsForCall)]
@@ -3905,6 +3942,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
defer fake.toProtoMutex.RUnlock()
fake.updateMediaLossMutex.RLock()
defer fake.updateMediaLossMutex.RUnlock()
fake.updateRTTMutex.RLock()
defer fake.updateRTTMutex.RUnlock()
fake.updateSubscribedQualityMutex.RLock()
defer fake.updateSubscribedQualityMutex.RUnlock()
fake.updateSubscribedTrackSettingsMutex.RLock()