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:
Raja Subramanian authored and GitHub committed 2021-12-17 15:45:04 +05:30
1 parent a8fe06e083
commit 502c57d787
2 files changed
+24 -2

No files matched your search

+5 -1
View File
@@ -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
}
+19 -1
View File
@@ -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())
}