Do not mute when stream is paused. (#2069)
This commit is contained in:
+44
-21
@@ -40,13 +40,19 @@ func newForwarder(codec webrtc.RTPCodecCapability, kind webrtc.RTPCodecType) *Fo
|
||||
func TestForwarderMute(t *testing.T) {
|
||||
f := newForwarder(testutils.TestOpusCodec, webrtc.RTPCodecTypeAudio)
|
||||
require.False(t, f.IsMuted())
|
||||
muted := f.Mute(false)
|
||||
muted := f.Mute(false, true)
|
||||
require.False(t, muted) // no change in mute state
|
||||
require.False(t, f.IsMuted())
|
||||
muted = f.Mute(true)
|
||||
|
||||
muted = f.Mute(true, false)
|
||||
require.False(t, muted)
|
||||
require.False(t, f.IsMuted())
|
||||
|
||||
muted = f.Mute(true, true)
|
||||
require.True(t, muted)
|
||||
require.True(t, f.IsMuted())
|
||||
muted = f.Mute(false)
|
||||
|
||||
muted = f.Mute(false, true)
|
||||
require.True(t, muted)
|
||||
require.False(t, f.IsMuted())
|
||||
}
|
||||
@@ -164,7 +170,7 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
||||
f.SetMaxPublishedLayer(buffer.DefaultMaxLayerSpatial)
|
||||
|
||||
// muted should not consume any bandwidth
|
||||
f.Mute(true)
|
||||
f.Mute(true, true)
|
||||
disable(f)
|
||||
expectedResult = VideoAllocation{
|
||||
PauseReason: VideoPauseReasonMuted,
|
||||
@@ -180,7 +186,7 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
||||
require.Equal(t, expectedResult, result)
|
||||
require.Equal(t, expectedResult, f.lastAllocation)
|
||||
|
||||
f.Mute(false)
|
||||
f.Mute(false, true)
|
||||
|
||||
// pub muted should not consume any bandwidth
|
||||
f.PubMute(true)
|
||||
@@ -616,7 +622,7 @@ func TestForwarderProvisionalAllocateMute(t *testing.T) {
|
||||
{9, 10, 11, 12},
|
||||
}
|
||||
|
||||
f.Mute(true)
|
||||
f.Mute(true, true)
|
||||
f.ProvisionalAllocatePrepare(nil, bitrates)
|
||||
|
||||
isCandidate, usedBitrate := f.ProvisionalAllocate(bitrates[2][3], buffer.VideoLayer{Spatial: 0, Temporal: 0}, true, false)
|
||||
@@ -651,13 +657,14 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
f.SetMaxPublishedLayer(buffer.DefaultMaxLayerSpatial)
|
||||
f.SetMaxTemporalLayerSeen(buffer.DefaultMaxLayerTemporal)
|
||||
|
||||
availableLayers := []int32{0, 1, 2}
|
||||
bitrates := Bitrates{
|
||||
{1, 2, 3, 4},
|
||||
{5, 6, 7, 8},
|
||||
{9, 10, 0, 0},
|
||||
}
|
||||
|
||||
f.ProvisionalAllocatePrepare(nil, bitrates)
|
||||
f.ProvisionalAllocatePrepare(availableLayers, bitrates)
|
||||
|
||||
// from scratch (buffer.InvalidLayer) should give back layer (0, 0)
|
||||
expectedTransition := VideoTransition{
|
||||
@@ -665,8 +672,10 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
To: buffer.VideoLayer{Spatial: 0, Temporal: 0},
|
||||
BandwidthDelta: 1,
|
||||
}
|
||||
transition := f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
transition, al, brs := f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
require.Equal(t, availableLayers, al)
|
||||
require.Equal(t, bitrates, brs)
|
||||
|
||||
// committing should set target to (0, 0)
|
||||
expectedLayers := buffer.VideoLayer{Spatial: 0, Temporal: 0}
|
||||
@@ -695,8 +704,10 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
To: targetLayer,
|
||||
BandwidthDelta: 0,
|
||||
}
|
||||
transition = f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
transition, al, brs = f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
require.Equal(t, availableLayers, al)
|
||||
require.Equal(t, bitrates, brs)
|
||||
|
||||
// committing should set target to (2, 1)
|
||||
expectedLayers = buffer.VideoLayer{Spatial: 2, Temporal: 1}
|
||||
@@ -723,14 +734,16 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
To: buffer.VideoLayer{Spatial: 2, Temporal: 1},
|
||||
BandwidthDelta: 0,
|
||||
}
|
||||
transition = f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
transition, al, brs = f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
require.Equal(t, availableLayers, al)
|
||||
require.Equal(t, bitrates, brs)
|
||||
|
||||
f.ProvisionalAllocateCommit()
|
||||
|
||||
// mute
|
||||
f.Mute(true)
|
||||
f.ProvisionalAllocatePrepare(nil, bitrates)
|
||||
f.Mute(true, true)
|
||||
f.ProvisionalAllocatePrepare(availableLayers, bitrates)
|
||||
|
||||
// mute should send target to buffer.InvalidLayer
|
||||
expectedTransition = VideoTransition{
|
||||
@@ -738,17 +751,20 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
To: buffer.InvalidLayer,
|
||||
BandwidthDelta: -10,
|
||||
}
|
||||
transition = f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
transition, al, brs = f.ProvisionalAllocateGetCooperativeTransition(false)
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
require.Equal(t, availableLayers, al)
|
||||
require.Equal(t, bitrates, brs)
|
||||
|
||||
f.ProvisionalAllocateCommit()
|
||||
|
||||
//
|
||||
// Test allowOvershoot
|
||||
//
|
||||
f.Mute(false)
|
||||
f.Mute(false, true)
|
||||
f.SetMaxSpatialLayer(0)
|
||||
|
||||
availableLayers = []int32{1, 2}
|
||||
bitrates = Bitrates{
|
||||
{0, 0, 0, 0},
|
||||
{5, 6, 7, 8},
|
||||
@@ -756,7 +772,7 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
}
|
||||
|
||||
f.vls.SetTarget(buffer.InvalidLayer)
|
||||
f.ProvisionalAllocatePrepare(nil, bitrates)
|
||||
f.ProvisionalAllocatePrepare(availableLayers, bitrates)
|
||||
|
||||
// from scratch (buffer.InvalidLayer) should go to a layer past maximum as overshoot is allowed
|
||||
expectedTransition = VideoTransition{
|
||||
@@ -764,8 +780,10 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
To: buffer.VideoLayer{Spatial: 1, Temporal: 0},
|
||||
BandwidthDelta: 5,
|
||||
}
|
||||
transition = f.ProvisionalAllocateGetCooperativeTransition(true)
|
||||
transition, al, brs = f.ProvisionalAllocateGetCooperativeTransition(true)
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
require.Equal(t, availableLayers, al)
|
||||
require.Equal(t, bitrates, brs)
|
||||
|
||||
// committing should set target to (1, 0)
|
||||
expectedLayers = buffer.VideoLayer{Spatial: 1, Temporal: 0}
|
||||
@@ -804,8 +822,10 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
||||
To: buffer.VideoLayer{Spatial: 0, Temporal: 2},
|
||||
BandwidthDelta: -5, // 5 was the bandwidth needed for the last allocation
|
||||
}
|
||||
transition = f.ProvisionalAllocateGetCooperativeTransition(true)
|
||||
transition, al, brs = f.ProvisionalAllocateGetCooperativeTransition(true)
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
require.Equal(t, []int32{}, al)
|
||||
require.Equal(t, bitrates, brs)
|
||||
|
||||
// committing should set target to (0, 2)
|
||||
expectedLayers = buffer.VideoLayer{Spatial: 0, Temporal: 2}
|
||||
@@ -844,13 +864,14 @@ func TestForwarderProvisionalAllocateGetBestWeightedTransition(t *testing.T) {
|
||||
f.SetMaxSpatialLayer(buffer.DefaultMaxLayerSpatial)
|
||||
f.SetMaxTemporalLayer(buffer.DefaultMaxLayerTemporal)
|
||||
|
||||
availableLayers := []int32{0, 1, 2}
|
||||
bitrates := Bitrates{
|
||||
{1, 2, 3, 4},
|
||||
{5, 6, 7, 8},
|
||||
{9, 10, 11, 12},
|
||||
}
|
||||
|
||||
f.ProvisionalAllocatePrepare(nil, bitrates)
|
||||
f.ProvisionalAllocatePrepare(availableLayers, bitrates)
|
||||
|
||||
f.vls.SetTarget(buffer.VideoLayer{Spatial: 2, Temporal: 2})
|
||||
f.lastAllocation.BandwidthRequested = bitrates[2][2]
|
||||
@@ -859,8 +880,10 @@ func TestForwarderProvisionalAllocateGetBestWeightedTransition(t *testing.T) {
|
||||
To: buffer.VideoLayer{Spatial: 2, Temporal: 0},
|
||||
BandwidthDelta: -2,
|
||||
}
|
||||
transition := f.ProvisionalAllocateGetBestWeightedTransition()
|
||||
transition, al, brs := f.ProvisionalAllocateGetBestWeightedTransition()
|
||||
require.Equal(t, expectedTransition, transition)
|
||||
require.Equal(t, availableLayers, al)
|
||||
require.Equal(t, bitrates, brs)
|
||||
}
|
||||
|
||||
func TestForwarderAllocateNextHigher(t *testing.T) {
|
||||
@@ -1142,7 +1165,7 @@ func TestForwarderPauseMute(t *testing.T) {
|
||||
// should have set target at (0, 0)
|
||||
f.ProvisionalAllocateCommit()
|
||||
|
||||
f.Mute(true)
|
||||
f.Mute(true, true)
|
||||
expectedResult := VideoAllocation{
|
||||
PauseReason: VideoPauseReasonMuted,
|
||||
BandwidthRequested: 0,
|
||||
@@ -1161,7 +1184,7 @@ func TestForwarderPauseMute(t *testing.T) {
|
||||
|
||||
func TestForwarderGetTranslationParamsMuted(t *testing.T) {
|
||||
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
||||
f.Mute(true)
|
||||
f.Mute(true, true)
|
||||
|
||||
params := &testutils.TestExtPacketParams{
|
||||
SequenceNumber: 23333,
|
||||
|
||||
Reference in New Issue
Block a user