+70
-70
@@ -62,15 +62,15 @@ func TestForwarderLayersVideo(t *testing.T) {
|
||||
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
||||
|
||||
maxLayers := f.MaxLayers()
|
||||
expectedLayers := VideoLayers{spatial: InvalidLayerSpatial, temporal: DefaultMaxLayerTemporal}
|
||||
expectedLayers := VideoLayers{Spatial: InvalidLayerSpatial, Temporal: DefaultMaxLayerTemporal}
|
||||
require.Equal(t, expectedLayers, maxLayers)
|
||||
|
||||
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
||||
require.Equal(t, InvalidLayers, f.TargetLayers())
|
||||
|
||||
expectedLayers = VideoLayers{
|
||||
spatial: DefaultMaxLayerSpatial,
|
||||
temporal: DefaultMaxLayerTemporal,
|
||||
Spatial: DefaultMaxLayerSpatial,
|
||||
Temporal: DefaultMaxLayerTemporal,
|
||||
}
|
||||
changed, maxLayers, currentLayers := f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
||||
require.True(t, changed)
|
||||
@@ -80,34 +80,34 @@ func TestForwarderLayersVideo(t *testing.T) {
|
||||
changed, maxLayers, currentLayers = f.SetMaxSpatialLayer(DefaultMaxLayerSpatial - 1)
|
||||
require.True(t, changed)
|
||||
expectedLayers = VideoLayers{
|
||||
spatial: DefaultMaxLayerSpatial - 1,
|
||||
temporal: DefaultMaxLayerTemporal,
|
||||
Spatial: DefaultMaxLayerSpatial - 1,
|
||||
Temporal: DefaultMaxLayerTemporal,
|
||||
}
|
||||
require.Equal(t, expectedLayers, maxLayers)
|
||||
require.Equal(t, expectedLayers, f.MaxLayers())
|
||||
require.Equal(t, InvalidLayers, currentLayers)
|
||||
|
||||
f.currentLayers = VideoLayers{spatial: 0, temporal: 1}
|
||||
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 1}
|
||||
changed, maxLayers, currentLayers = f.SetMaxSpatialLayer(DefaultMaxLayerSpatial - 1)
|
||||
require.False(t, changed)
|
||||
require.Equal(t, expectedLayers, maxLayers)
|
||||
require.Equal(t, expectedLayers, f.MaxLayers())
|
||||
require.Equal(t, VideoLayers{spatial: 0, temporal: 1}, currentLayers)
|
||||
require.Equal(t, VideoLayers{Spatial: 0, Temporal: 1}, currentLayers)
|
||||
|
||||
changed, maxLayers, currentLayers = f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
||||
require.False(t, changed)
|
||||
require.Equal(t, expectedLayers, maxLayers)
|
||||
require.Equal(t, VideoLayers{spatial: 0, temporal: 1}, currentLayers)
|
||||
require.Equal(t, VideoLayers{Spatial: 0, Temporal: 1}, currentLayers)
|
||||
|
||||
changed, maxLayers, currentLayers = f.SetMaxTemporalLayer(DefaultMaxLayerTemporal - 1)
|
||||
require.True(t, changed)
|
||||
expectedLayers = VideoLayers{
|
||||
spatial: DefaultMaxLayerSpatial - 1,
|
||||
temporal: DefaultMaxLayerTemporal - 1,
|
||||
Spatial: DefaultMaxLayerSpatial - 1,
|
||||
Temporal: DefaultMaxLayerTemporal - 1,
|
||||
}
|
||||
require.Equal(t, expectedLayers, maxLayers)
|
||||
require.Equal(t, expectedLayers, f.MaxLayers())
|
||||
require.Equal(t, VideoLayers{spatial: 0, temporal: 1}, currentLayers)
|
||||
require.Equal(t, VideoLayers{Spatial: 0, Temporal: 1}, currentLayers)
|
||||
}
|
||||
|
||||
func TestForwarderGetForwardingStatus(t *testing.T) {
|
||||
@@ -129,11 +129,11 @@ func TestForwarderGetForwardingStatus(t *testing.T) {
|
||||
|
||||
// when target is the max, should be optimal
|
||||
f.Mute(false)
|
||||
f.targetLayers.spatial = DefaultMaxLayerSpatial
|
||||
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
|
||||
f.targetLayers.Spatial = DefaultMaxLayerSpatial - 1
|
||||
require.Equal(t, ForwardingStatusPartial, f.GetForwardingStatus())
|
||||
|
||||
// when available layers are lower than max subscribed, optimal as long as target is at max available
|
||||
@@ -212,8 +212,8 @@ func TestForwarderAllocate(t *testing.T) {
|
||||
disable(f)
|
||||
f.UpTrackLayersChange([]int32{0})
|
||||
expectedTargetLayers := VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: DefaultMaxLayerTemporal,
|
||||
Spatial: 0,
|
||||
Temporal: DefaultMaxLayerTemporal,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateAwaitingMeasurement,
|
||||
@@ -233,8 +233,8 @@ func TestForwarderAllocate(t *testing.T) {
|
||||
|
||||
// allocate using bitrates, allocation should choose optimal
|
||||
expectedTargetLayers = VideoLayers{
|
||||
spatial: 2,
|
||||
temporal: 1,
|
||||
Spatial: 2,
|
||||
Temporal: 1,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateOptimal,
|
||||
@@ -268,26 +268,26 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
||||
f.availableLayers = availableLayers
|
||||
f.ProvisionalAllocatePrepare(bitrates)
|
||||
|
||||
usedBitrate := f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 0, temporal: 0}, true)
|
||||
usedBitrate := f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true)
|
||||
require.Equal(t, bitrates[0][0], usedBitrate)
|
||||
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 2, temporal: 3}, true)
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 2, Temporal: 3}, true)
|
||||
require.Equal(t, bitrates[2][3]-bitrates[0][0], usedBitrate)
|
||||
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 0, temporal: 3}, true)
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 3}, true)
|
||||
require.Equal(t, bitrates[0][3]-bitrates[2][3], usedBitrate)
|
||||
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 1, temporal: 2}, true)
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 1, Temporal: 2}, true)
|
||||
require.Equal(t, bitrates[1][2]-bitrates[0][3], usedBitrate)
|
||||
|
||||
// available not enough to reach (2, 2), allocating at (2, 2) should not succeed
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][2]-bitrates[1][2]-1, VideoLayers{spatial: 2, temporal: 2}, true)
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][2]-bitrates[1][2]-1, VideoLayers{Spatial: 2, Temporal: 2}, true)
|
||||
require.Equal(t, int64(0), usedBitrate)
|
||||
|
||||
// committing should set target to (1, 2)
|
||||
expectedTargetLayers := VideoLayers{
|
||||
spatial: 1,
|
||||
temporal: 2,
|
||||
Spatial: 1,
|
||||
Temporal: 2,
|
||||
}
|
||||
expectedResult := VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
@@ -307,13 +307,13 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
||||
// when nothing fits and pausing disallowed, should allocate (0, 0)
|
||||
f.targetLayers = InvalidLayers
|
||||
f.ProvisionalAllocatePrepare(bitrates)
|
||||
usedBitrate = f.ProvisionalAllocate(0, VideoLayers{spatial: 0, temporal: 0}, false)
|
||||
usedBitrate = f.ProvisionalAllocate(0, VideoLayers{Spatial: 0, Temporal: 0}, false)
|
||||
require.Equal(t, int64(1), usedBitrate)
|
||||
|
||||
// committing should set target to (0, 0)
|
||||
expectedTargetLayers = VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: 0,
|
||||
Spatial: 0,
|
||||
Temporal: 0,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
@@ -343,10 +343,10 @@ func TestForwarderProvisionalAllocateMute(t *testing.T) {
|
||||
f.Mute(true)
|
||||
f.ProvisionalAllocatePrepare(bitrates)
|
||||
|
||||
usedBitrate := f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 0, temporal: 0}, true)
|
||||
usedBitrate := f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true)
|
||||
require.Equal(t, int64(0), usedBitrate)
|
||||
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 1, temporal: 2}, true)
|
||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 1, Temporal: 2}, true)
|
||||
require.Equal(t, int64(0), usedBitrate)
|
||||
|
||||
// committing should set target to InvalidLayers as track is muted
|
||||
@@ -384,14 +384,14 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
// from scratch (InvalidLayers) should give back layer (0, 0)
|
||||
expectedTransition := VideoTransition{
|
||||
from: InvalidLayers,
|
||||
to: VideoLayers{spatial: 0, temporal: 0},
|
||||
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}
|
||||
expectedLayers := VideoLayers{Spatial: 0, Temporal: 0}
|
||||
expectedResult := VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
change: VideoStreamingChangeResuming,
|
||||
@@ -408,7 +408,7 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
require.Equal(t, expectedLayers, f.TargetLayers())
|
||||
|
||||
// a higher target that is already streaming, just maintain it
|
||||
targetLayers := VideoLayers{spatial: 2, temporal: 1}
|
||||
targetLayers := VideoLayers{Spatial: 2, Temporal: 1}
|
||||
f.targetLayers = targetLayers
|
||||
f.lastAllocation.bandwidthRequested = 10
|
||||
expectedTransition = VideoTransition{
|
||||
@@ -420,7 +420,7 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
|
||||
// committing should set target to (2, 1)
|
||||
expectedLayers = VideoLayers{spatial: 2, temporal: 1}
|
||||
expectedLayers = VideoLayers{Spatial: 2, Temporal: 1}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateOptimal,
|
||||
change: VideoStreamingChangeNone,
|
||||
@@ -437,11 +437,11 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
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}
|
||||
targetLayers = VideoLayers{Spatial: 2, Temporal: 2}
|
||||
f.targetLayers = targetLayers
|
||||
expectedTransition = VideoTransition{
|
||||
from: targetLayers,
|
||||
to: VideoLayers{spatial: 2, temporal: 1},
|
||||
to: VideoLayers{Spatial: 2, Temporal: 1},
|
||||
bandwidthDelta: 0,
|
||||
}
|
||||
transition = f.ProvisionalAllocateGetCooperativeTransition()
|
||||
@@ -455,7 +455,7 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
|
||||
// mute should send target to InvalidLayers
|
||||
expectedTransition = VideoTransition{
|
||||
from: VideoLayers{spatial: 2, temporal: 1},
|
||||
from: VideoLayers{Spatial: 2, Temporal: 1},
|
||||
to: InvalidLayers,
|
||||
bandwidthDelta: -10,
|
||||
}
|
||||
@@ -476,11 +476,11 @@ func TestForwarderProvisionalAllocateGetBestWeightedTransition(t *testing.T) {
|
||||
|
||||
f.ProvisionalAllocatePrepare(bitrates)
|
||||
|
||||
f.targetLayers = VideoLayers{spatial: 2, temporal: 2}
|
||||
f.targetLayers = VideoLayers{Spatial: 2, Temporal: 2}
|
||||
f.lastAllocation.bandwidthRequested = bitrates[2][2]
|
||||
expectedTransition := VideoTransition{
|
||||
from: f.targetLayers,
|
||||
to: VideoLayers{spatial: 2, temporal: 0},
|
||||
to: VideoLayers{Spatial: 2, Temporal: 0},
|
||||
bandwidthDelta: 2,
|
||||
}
|
||||
transition := f.ProvisionalAllocateGetBestWeightedTransition()
|
||||
@@ -515,7 +515,7 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
|
||||
// if layers have not caught up, should not allocate next layer
|
||||
f.lastAllocation.state = VideoAllocationStateDeficient
|
||||
f.targetLayers.spatial = 0
|
||||
f.targetLayers.Spatial = 0
|
||||
expectedResult := VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
change: VideoStreamingChangeNone,
|
||||
@@ -530,14 +530,14 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
require.Equal(t, expectedResult, result)
|
||||
require.Equal(t, expectedResult, f.lastAllocation)
|
||||
require.False(t, boosted)
|
||||
f.currentLayers.spatial = 0
|
||||
f.currentLayers.Spatial = 0
|
||||
|
||||
f.targetLayers.temporal = 0
|
||||
f.targetLayers.Temporal = 0
|
||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates)
|
||||
require.Equal(t, expectedResult, result)
|
||||
require.Equal(t, expectedResult, f.lastAllocation)
|
||||
require.False(t, boosted)
|
||||
f.currentLayers.temporal = 0
|
||||
f.currentLayers.Temporal = 0
|
||||
|
||||
f.lastAllocation.bandwidthRequested = bitrates[0][0]
|
||||
|
||||
@@ -559,8 +559,8 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
|
||||
// move from (0, 0) -> (0, 1), i.e. a higher temporal layer is available in the same spatial layer
|
||||
expectedTargetLayers := VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: 1,
|
||||
Spatial: 0,
|
||||
Temporal: 1,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
@@ -579,10 +579,10 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
require.True(t, boosted)
|
||||
|
||||
// move from (0, 1) -> (1, 0), i.e. a higher spatial layer is available
|
||||
f.currentLayers.temporal = 1
|
||||
f.currentLayers.Temporal = 1
|
||||
expectedTargetLayers = VideoLayers{
|
||||
spatial: 1,
|
||||
temporal: 0,
|
||||
Spatial: 1,
|
||||
Temporal: 0,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
@@ -601,11 +601,11 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
require.True(t, boosted)
|
||||
|
||||
// next higher, move from (1, 0) -> (1, 3), still deficient though
|
||||
f.currentLayers.spatial = 1
|
||||
f.currentLayers.temporal = 0
|
||||
f.currentLayers.Spatial = 1
|
||||
f.currentLayers.Temporal = 0
|
||||
expectedTargetLayers = VideoLayers{
|
||||
spatial: 1,
|
||||
temporal: 3,
|
||||
Spatial: 1,
|
||||
Temporal: 3,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
@@ -624,10 +624,10 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
require.True(t, boosted)
|
||||
|
||||
// next higher, move from (1, 3) -> (2, 1), optimal allocation
|
||||
f.currentLayers.temporal = 3
|
||||
f.currentLayers.Temporal = 3
|
||||
expectedTargetLayers = VideoLayers{
|
||||
spatial: 2,
|
||||
temporal: 1,
|
||||
Spatial: 2,
|
||||
Temporal: 1,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateOptimal,
|
||||
@@ -646,8 +646,8 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
require.True(t, boosted)
|
||||
|
||||
// ask again, should return not boosted as there is no room to go higher
|
||||
f.currentLayers.spatial = 2
|
||||
f.currentLayers.temporal = 1
|
||||
f.currentLayers.Spatial = 2
|
||||
f.currentLayers.Temporal = 1
|
||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates)
|
||||
require.Equal(t, expectedResult, result)
|
||||
require.Equal(t, expectedResult, f.lastAllocation)
|
||||
@@ -660,8 +660,8 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
f.lastAllocation.bandwidthRequested = 0
|
||||
|
||||
expectedTargetLayers = VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: 0,
|
||||
Spatial: 0,
|
||||
Temporal: 0,
|
||||
}
|
||||
expectedResult = VideoAllocation{
|
||||
state: VideoAllocationStateDeficient,
|
||||
@@ -711,7 +711,7 @@ func TestForwarderPause(t *testing.T) {
|
||||
|
||||
f.availableLayers = availableLayers
|
||||
f.ProvisionalAllocatePrepare(bitrates)
|
||||
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 0, temporal: 0}, true)
|
||||
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true)
|
||||
// should have set target at (0, 0)
|
||||
f.ProvisionalAllocateCommit()
|
||||
|
||||
@@ -745,7 +745,7 @@ func TestForwarderPauseMute(t *testing.T) {
|
||||
|
||||
f.availableLayers = availableLayers
|
||||
f.ProvisionalAllocatePrepare(bitrates)
|
||||
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{spatial: 0, temporal: 0}, true)
|
||||
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true)
|
||||
// should have set target at (0, 0)
|
||||
f.ProvisionalAllocateCommit()
|
||||
|
||||
@@ -969,8 +969,8 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
|
||||
|
||||
// although target layer matches, not a key frame, so should drop and ask to send PLI
|
||||
f.targetLayers = VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: 1,
|
||||
Spatial: 0,
|
||||
Temporal: 1,
|
||||
}
|
||||
expectedTP = TranslationParams{
|
||||
shouldDrop: true,
|
||||
@@ -1222,8 +1222,8 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
|
||||
// switching SSRC (happens for new layer or new track source)
|
||||
// should lock onto the new source, but sequence number should be contiguous
|
||||
f.targetLayers = VideoLayers{
|
||||
spatial: 1,
|
||||
temporal: 1,
|
||||
Spatial: 1,
|
||||
Temporal: 1,
|
||||
}
|
||||
|
||||
params = &testutils.TestExtPacketParams{
|
||||
@@ -1306,8 +1306,8 @@ func TestForwardGetSnTsForPadding(t *testing.T) {
|
||||
extPkt, _ := testutils.GetTestExtPacketVP8(params, vp8)
|
||||
|
||||
f.targetLayers = VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: 1,
|
||||
Spatial: 0,
|
||||
Temporal: 1,
|
||||
}
|
||||
f.currentLayers = InvalidLayers
|
||||
|
||||
@@ -1373,8 +1373,8 @@ func TestForwardGetSnTsForBlankFrames(t *testing.T) {
|
||||
extPkt, _ := testutils.GetTestExtPacketVP8(params, vp8)
|
||||
|
||||
f.targetLayers = VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: 1,
|
||||
Spatial: 0,
|
||||
Temporal: 1,
|
||||
}
|
||||
f.currentLayers = InvalidLayers
|
||||
|
||||
@@ -1443,8 +1443,8 @@ func TestForwardGetPaddingVP8(t *testing.T) {
|
||||
extPkt, _ := testutils.GetTestExtPacketVP8(params, vp8)
|
||||
|
||||
f.targetLayers = VideoLayers{
|
||||
spatial: 0,
|
||||
temporal: 1,
|
||||
Spatial: 0,
|
||||
Temporal: 1,
|
||||
}
|
||||
f.currentLayers = InvalidLayers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user