Deficient state handling when a track needs a change (#261)

* WIP commit

* deficient handling

* Add missing ProvisionalAllocatePrepare

* adjust state on track removal

* Increase test timeout

* - Add comments about cooperative routines
- Take down transition if available in cooperative scheme
- Use layer comparison when taking down transition. Because of when the
  bitrate is measured, it is not always guaranteed bandwidthDelta is -ve
  when moving down.
- Do not add track to stream allocator till bind.

* make comment better

* a bit more clear comments

* Use OnBind on subscribed track
This commit is contained in:
Raja Subramanian
2021-12-16 10:58:34 +05:30
committed by GitHub
parent c08d1e9d72
commit e504b6678c
10 changed files with 509 additions and 26 deletions
+115
View File
@@ -340,6 +340,121 @@ func TestForwarderProvisionalAllocateMute(t *testing.T) {
require.Equal(t, InvalidLayers, f.TargetLayers())
}
func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
f := NewForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
bitrates := Bitrates{
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 0, 0},
}
f.ProvisionalAllocatePrepare(bitrates)
// from scratch (InvalidLayers) should give back layer (0, 0)
expectedTransition := VideoTransition{
from: InvalidLayers,
to: VideoLayers{spatial: 0, temporal: 0},
bandwidthDelta: 1,
}
transition := f.ProvisionalAllocateGetCooperativeTransition()
require.Equal(t, expectedTransition, transition)
// committing should set target to (0, 0)
expectedLayers := VideoLayers{spatial: 0, temporal: 0}
expectedResult := VideoAllocation{
state: VideoAllocationStateDeficient,
change: VideoStreamingChangeResuming,
bandwidthRequested: 1,
bandwidthDelta: 1,
availableLayers: nil,
bitrates: bitrates,
targetLayers: expectedLayers,
distanceToDesired: 9,
}
result := f.ProvisionalAllocateCommit()
require.Equal(t, expectedResult, result)
require.Equal(t, expectedResult, f.lastAllocation)
require.Equal(t, expectedLayers, f.TargetLayers())
// a higher target that is already streaming, just maintain it
targetLayers := VideoLayers{spatial: 2, temporal: 1}
f.targetLayers = targetLayers
f.lastAllocation.bandwidthRequested = 10
expectedTransition = VideoTransition{
from: targetLayers,
to: targetLayers,
bandwidthDelta: 0,
}
transition = f.ProvisionalAllocateGetCooperativeTransition()
require.Equal(t, expectedTransition, transition)
// committing should set target to (2, 1)
expectedLayers = VideoLayers{spatial: 2, temporal: 1}
expectedResult = VideoAllocation{
state: VideoAllocationStateOptimal,
change: VideoStreamingChangeNone,
bandwidthRequested: 10,
bandwidthDelta: 0,
availableLayers: nil,
bitrates: bitrates,
targetLayers: expectedLayers,
distanceToDesired: 0,
}
result = f.ProvisionalAllocateCommit()
require.Equal(t, expectedResult, result)
require.Equal(t, expectedResult, f.lastAllocation)
require.Equal(t, expectedLayers, f.TargetLayers())
// from a target that has become unavailable, should switch to lower available layer
targetLayers = VideoLayers{spatial: 2, temporal: 2}
f.targetLayers = targetLayers
expectedTransition = VideoTransition{
from: targetLayers,
to: VideoLayers{spatial: 2, temporal: 1},
bandwidthDelta: 0,
}
transition = f.ProvisionalAllocateGetCooperativeTransition()
require.Equal(t, expectedTransition, transition)
f.ProvisionalAllocateCommit()
// mute
f.Mute(true)
f.ProvisionalAllocatePrepare(bitrates)
// mute should send target to InvalidLayers
expectedTransition = VideoTransition{
from: VideoLayers{spatial: 2, temporal: 1},
to: InvalidLayers,
bandwidthDelta: -10,
}
transition = f.ProvisionalAllocateGetCooperativeTransition()
require.Equal(t, expectedTransition, transition)
}
func TestForwarderProvisionalAllocateGetBestWeightedTransition(t *testing.T) {
f := NewForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
bitrates := Bitrates{
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
}
f.ProvisionalAllocatePrepare(bitrates)
f.targetLayers = VideoLayers{spatial: 2, temporal: 2}
f.lastAllocation.bandwidthRequested = bitrates[2][2]
expectedTransition := VideoTransition{
from: f.targetLayers,
to: VideoLayers{spatial: 2, temporal: 0},
bandwidthDelta: 2,
}
transition := f.ProvisionalAllocateGetBestWeightedTransition()
require.Equal(t, expectedTransition, transition)
}
func TestForwarderFinalizeAllocate(t *testing.T) {
f := NewForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)