mirror of
https://github.com/livekit/livekit.git
synced 2026-05-25 14:15:15 +00:00
Fix forwarding status deduction (#267)
* Fix forwarding status deduction - When muted OR when there are no available layers, declare optimal - When target layer is the maximum it can achieve taking available layers into account even if they are not the maximum subscribed layer, it is still optimal as there is nothing better available. * Fix and add more tests for forwarding status
This commit is contained in:
@@ -287,11 +287,15 @@ func (f *Forwarder) GetForwardingStatus() ForwardingStatus {
|
||||
f.lock.RLock()
|
||||
defer f.lock.RUnlock()
|
||||
|
||||
if f.muted || len(f.availableLayers) == 0 {
|
||||
return ForwardingStatusOptimal
|
||||
}
|
||||
|
||||
if f.targetLayers == InvalidLayers {
|
||||
return ForwardingStatusOff
|
||||
}
|
||||
|
||||
if f.targetLayers.spatial < f.maxLayers.spatial {
|
||||
if f.targetLayers.spatial < f.maxLayers.spatial && f.targetLayers.spatial < int32(f.availableLayers[len(f.availableLayers)-1]) {
|
||||
return ForwardingStatusPartial
|
||||
}
|
||||
|
||||
|
||||
@@ -90,12 +90,30 @@ func TestForwarderLayersVideo(t *testing.T) {
|
||||
func TestForwarderGetForwardingStatus(t *testing.T) {
|
||||
f := NewForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
||||
|
||||
// no available layers, should be optimal
|
||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
||||
|
||||
// with available layers, should be off
|
||||
availableLayers := []uint16{0, 1, 2}
|
||||
f.UptrackLayersChange(availableLayers)
|
||||
require.Equal(t, ForwardingStatusOff, f.GetForwardingStatus())
|
||||
|
||||
// when muted, should be optimal
|
||||
f.Mute(true)
|
||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
||||
|
||||
// when target is the max, should be optimal
|
||||
f.Mute(false)
|
||||
f.targetLayers.spatial = DefaultMaxLayerSpatial
|
||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
||||
|
||||
// when target is less than max subscribed and max available, should be partial
|
||||
f.targetLayers.spatial = DefaultMaxLayerSpatial - 1
|
||||
require.Equal(t, ForwardingStatusPartial, f.GetForwardingStatus())
|
||||
|
||||
f.targetLayers.spatial = DefaultMaxLayerSpatial
|
||||
// when available layers are lower than max subscribed, optimal as long as target is at max available
|
||||
availableLayers = []uint16{0, 1}
|
||||
f.UptrackLayersChange(availableLayers)
|
||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user