Support simulating subscriber bandwidth. (#1609)

* Support simualting subscriber bandwidth.

When non-zero, a full allocation is triggered.
Also, probes are stopped.

When set to zero, normal probing mechanism should catch up.

Adding `allowPause` override which can be a connection option.

* fix log

* allowPause in participant params
This commit is contained in:
Raja Subramanian
2023-04-13 13:59:24 +05:30
committed by GitHub
parent f8a94c2125
commit d2bf8f0ba1
8 changed files with 187 additions and 10 deletions
+3
View File
@@ -88,6 +88,7 @@ type ParticipantParams struct {
VersionGenerator utils.TimedVersionGenerator
TrackResolver types.MediaTrackResolver
DisableDynacast bool
SubscriberAllowPause bool
}
type ParticipantImpl struct {
@@ -1035,6 +1036,8 @@ func (p *ParticipantImpl) setupTransportManager() error {
tm.OnAnyTransportNegotiationFailed(p.onAnyTransportNegotiationFailed)
tm.OnDataMessage(p.onDataMessage)
tm.SetSubscriberAllowPause(p.params.SubscriberAllowPause)
p.TransportManager = tm
return nil
}
+8 -2
View File
@@ -692,7 +692,7 @@ func (r *Room) OnMetadataUpdate(f func(metadata string)) {
func (r *Room) SimulateScenario(participant types.LocalParticipant, simulateScenario *livekit.SimulateScenario) error {
switch scenario := simulateScenario.Scenario.(type) {
case *livekit.SimulateScenario_SpeakerUpdate:
r.Logger.Infow("simulating speaker update", "participant", participant.Identity())
r.Logger.Infow("simulating speaker update", "participant", participant.Identity(), "duration", scenario.SpeakerUpdate)
go func() {
<-time.After(time.Duration(scenario.SpeakerUpdate) * time.Second)
r.sendSpeakerChanges([]*livekit.SpeakerInfo{{
@@ -723,13 +723,19 @@ func (r *Room) SimulateScenario(participant types.LocalParticipant, simulateScen
if err := participant.Close(true, types.ParticipantCloseReasonSimulateServerLeave); err != nil {
return err
}
case *livekit.SimulateScenario_SwitchCandidateProtocol:
r.Logger.Infow("simulating switch candidate protocol", "participant", participant.Identity())
participant.ICERestart(&livekit.ICEConfig{
PreferenceSubscriber: livekit.ICECandidateType(scenario.SwitchCandidateProtocol),
PreferencePublisher: livekit.ICECandidateType(scenario.SwitchCandidateProtocol),
})
case *livekit.SimulateScenario_SubscriberBandwidth:
if scenario.SubscriberBandwidth > 0 {
r.Logger.Infow("simulating subscriber bandwidth start", "participant", participant.Identity(), "bandwidth", scenario.SubscriberBandwidth)
} else {
r.Logger.Infow("simulating subscriber bandwidth end", "participant", participant.Identity())
}
participant.SetSubscriberChannelCapacity(scenario.SubscriberBandwidth)
}
return nil
}
+16
View File
@@ -1118,6 +1118,22 @@ func (t *PCTransport) RemoveTrackFromStreamAllocator(subTrack types.SubscribedTr
t.streamAllocator.RemoveTrack(subTrack.DownTrack())
}
func (t *PCTransport) SetAllowPauseOfStreamAllocator(allowPause bool) {
if t.streamAllocator == nil {
return
}
t.streamAllocator.SetAllowPause(allowPause)
}
func (t *PCTransport) SetChannelCapacityOfStreamAllocator(channelCapacity int64) {
if t.streamAllocator == nil {
return
}
t.streamAllocator.SetChannelCapacity(channelCapacity)
}
func (t *PCTransport) GetICEConnectionType() types.ICEConnectionType {
unknown := types.ICEConnectionTypeUnknown
if t.pc == nil {
+8
View File
@@ -782,3 +782,11 @@ func (t *TransportManager) SetSignalSourceValid(valid bool) {
t.signalSourceValid.Store(valid)
t.params.Logger.Debugw("signal source valid", "valid", valid)
}
func (t *TransportManager) SetSubscriberAllowPause(allowPause bool) {
t.subscriber.SetAllowPauseOfStreamAllocator(allowPause)
}
func (t *TransportManager) SetSubscriberChannelCapacity(channelCapacity int64) {
t.subscriber.SetChannelCapacityOfStreamAllocator(channelCapacity)
}
+4
View File
@@ -333,6 +333,10 @@ type LocalParticipant interface {
UpdateSubscribedQuality(nodeID livekit.NodeID, trackID livekit.TrackID, maxQualities []SubscribedCodecQuality) error
UpdateMediaLoss(nodeID livekit.NodeID, trackID livekit.TrackID, fractionalLoss uint32) error
// down stream bandwidth management
SetSubscriberAllowPause(allowPause bool)
SetSubscriberChannelCapacity(channelCapacity int64)
}
// Room is a container of participants, and can provide room-level actions
@@ -659,6 +659,16 @@ type FakeLocalParticipant struct {
setSignalSourceValidArgsForCall []struct {
arg1 bool
}
SetSubscriberAllowPauseStub func(bool)
setSubscriberAllowPauseMutex sync.RWMutex
setSubscriberAllowPauseArgsForCall []struct {
arg1 bool
}
SetSubscriberChannelCapacityStub func(int64)
setSubscriberChannelCapacityMutex sync.RWMutex
setSubscriberChannelCapacityArgsForCall []struct {
arg1 int64
}
SetTrackMutedStub func(livekit.TrackID, bool, bool)
setTrackMutedMutex sync.RWMutex
setTrackMutedArgsForCall []struct {
@@ -4343,6 +4353,70 @@ func (fake *FakeLocalParticipant) SetSignalSourceValidArgsForCall(i int) bool {
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) SetSubscriberAllowPause(arg1 bool) {
fake.setSubscriberAllowPauseMutex.Lock()
fake.setSubscriberAllowPauseArgsForCall = append(fake.setSubscriberAllowPauseArgsForCall, struct {
arg1 bool
}{arg1})
stub := fake.SetSubscriberAllowPauseStub
fake.recordInvocation("SetSubscriberAllowPause", []interface{}{arg1})
fake.setSubscriberAllowPauseMutex.Unlock()
if stub != nil {
fake.SetSubscriberAllowPauseStub(arg1)
}
}
func (fake *FakeLocalParticipant) SetSubscriberAllowPauseCallCount() int {
fake.setSubscriberAllowPauseMutex.RLock()
defer fake.setSubscriberAllowPauseMutex.RUnlock()
return len(fake.setSubscriberAllowPauseArgsForCall)
}
func (fake *FakeLocalParticipant) SetSubscriberAllowPauseCalls(stub func(bool)) {
fake.setSubscriberAllowPauseMutex.Lock()
defer fake.setSubscriberAllowPauseMutex.Unlock()
fake.SetSubscriberAllowPauseStub = stub
}
func (fake *FakeLocalParticipant) SetSubscriberAllowPauseArgsForCall(i int) bool {
fake.setSubscriberAllowPauseMutex.RLock()
defer fake.setSubscriberAllowPauseMutex.RUnlock()
argsForCall := fake.setSubscriberAllowPauseArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) SetSubscriberChannelCapacity(arg1 int64) {
fake.setSubscriberChannelCapacityMutex.Lock()
fake.setSubscriberChannelCapacityArgsForCall = append(fake.setSubscriberChannelCapacityArgsForCall, struct {
arg1 int64
}{arg1})
stub := fake.SetSubscriberChannelCapacityStub
fake.recordInvocation("SetSubscriberChannelCapacity", []interface{}{arg1})
fake.setSubscriberChannelCapacityMutex.Unlock()
if stub != nil {
fake.SetSubscriberChannelCapacityStub(arg1)
}
}
func (fake *FakeLocalParticipant) SetSubscriberChannelCapacityCallCount() int {
fake.setSubscriberChannelCapacityMutex.RLock()
defer fake.setSubscriberChannelCapacityMutex.RUnlock()
return len(fake.setSubscriberChannelCapacityArgsForCall)
}
func (fake *FakeLocalParticipant) SetSubscriberChannelCapacityCalls(stub func(int64)) {
fake.setSubscriberChannelCapacityMutex.Lock()
defer fake.setSubscriberChannelCapacityMutex.Unlock()
fake.SetSubscriberChannelCapacityStub = stub
}
func (fake *FakeLocalParticipant) SetSubscriberChannelCapacityArgsForCall(i int) int64 {
fake.setSubscriberChannelCapacityMutex.RLock()
defer fake.setSubscriberChannelCapacityMutex.RUnlock()
argsForCall := fake.setSubscriberChannelCapacityArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) SetTrackMuted(arg1 livekit.TrackID, arg2 bool, arg3 bool) {
fake.setTrackMutedMutex.Lock()
fake.setTrackMutedArgsForCall = append(fake.setTrackMutedArgsForCall, struct {
@@ -5368,6 +5442,10 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
defer fake.setResponseSinkMutex.RUnlock()
fake.setSignalSourceValidMutex.RLock()
defer fake.setSignalSourceValidMutex.RUnlock()
fake.setSubscriberAllowPauseMutex.RLock()
defer fake.setSubscriberAllowPauseMutex.RUnlock()
fake.setSubscriberChannelCapacityMutex.RLock()
defer fake.setSubscriberChannelCapacityMutex.RUnlock()
fake.setTrackMutedMutex.RLock()
defer fake.setTrackMutedMutex.RUnlock()
fake.startMutex.RLock()