Do not overshoot when layer is locked. (#1449)
* Do not overshoot when layer is locked. One more challenging case. When current layer is already locked, should not set up for overshoot. * set target to current
This commit is contained in:
+43
-7
@@ -585,9 +585,15 @@ func (f *Forwarder) AllocateOptimal(availableLayers []int32, brs Bitrates, allow
|
|||||||
|
|
||||||
alloc.requestLayerSpatial = alloc.targetLayers.Spatial
|
alloc.requestLayerSpatial = alloc.targetLayers.Spatial
|
||||||
} else {
|
} else {
|
||||||
// opportunistically latch on to anything
|
if f.currentLayers.IsValid() && f.currentLayers.Spatial == f.requestLayerSpatial {
|
||||||
opportunisticAlloc()
|
// current is locked to desired, stay there
|
||||||
alloc.requestLayerSpatial = int32(math.Min(float64(f.maxLayers.Spatial), float64(f.maxPublishedLayer)))
|
alloc.targetLayers = f.currentLayers
|
||||||
|
alloc.requestLayerSpatial = f.requestLayerSpatial
|
||||||
|
} else {
|
||||||
|
// opportunistically latch on to anything
|
||||||
|
opportunisticAlloc()
|
||||||
|
alloc.requestLayerSpatial = int32(math.Min(float64(f.maxLayers.Spatial), float64(f.maxPublishedLayer)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1198,7 +1204,8 @@ func (f *Forwarder) Pause(brs Bitrates) VideoAllocation {
|
|||||||
func (f *Forwarder) updateAllocation(alloc VideoAllocation, reason string) VideoAllocation {
|
func (f *Forwarder) updateAllocation(alloc VideoAllocation, reason string) VideoAllocation {
|
||||||
if alloc.isDeficient != f.lastAllocation.isDeficient ||
|
if alloc.isDeficient != f.lastAllocation.isDeficient ||
|
||||||
alloc.pauseReason != f.lastAllocation.pauseReason ||
|
alloc.pauseReason != f.lastAllocation.pauseReason ||
|
||||||
alloc.targetLayers != f.lastAllocation.targetLayers {
|
alloc.targetLayers != f.lastAllocation.targetLayers ||
|
||||||
|
alloc.requestLayerSpatial != f.lastAllocation.requestLayerSpatial {
|
||||||
f.logger.Infow(fmt.Sprintf("stream allocation: %s", reason), "allocation", alloc)
|
f.logger.Infow(fmt.Sprintf("stream allocation: %s", reason), "allocation", alloc)
|
||||||
}
|
}
|
||||||
f.lastAllocation = alloc
|
f.lastAllocation = alloc
|
||||||
@@ -1437,12 +1444,30 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
|
|||||||
} else {
|
} else {
|
||||||
if extPkt.KeyFrame {
|
if extPkt.KeyFrame {
|
||||||
if layer > f.currentLayers.Spatial && layer <= f.targetLayers.Spatial {
|
if layer > f.currentLayers.Spatial && layer <= f.targetLayers.Spatial {
|
||||||
f.logger.Infow("upgrading layer", "current", f.currentLayers, "target", f.targetLayers, "layer", layer, "feed", extPkt.Packet.SSRC)
|
f.logger.Infow(
|
||||||
|
"upgrading layer",
|
||||||
|
"current", f.currentLayers,
|
||||||
|
"target", f.targetLayers,
|
||||||
|
"max", f.maxLayers,
|
||||||
|
"layer", layer,
|
||||||
|
"req", f.requestLayerSpatial,
|
||||||
|
"maxPublished", f.maxPublishedLayer,
|
||||||
|
"feed", extPkt.Packet.SSRC,
|
||||||
|
)
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if layer < f.currentLayers.Spatial && layer >= f.targetLayers.Spatial {
|
if layer < f.currentLayers.Spatial && layer >= f.targetLayers.Spatial {
|
||||||
f.logger.Infow("downgrading layer", "current", f.currentLayers, "target", f.targetLayers, "layer", layer, "feed", extPkt.Packet.SSRC)
|
f.logger.Infow(
|
||||||
|
"downgrading layer",
|
||||||
|
"current", f.currentLayers,
|
||||||
|
"target", f.targetLayers,
|
||||||
|
"max", f.maxLayers,
|
||||||
|
"layer", layer,
|
||||||
|
"req", f.requestLayerSpatial,
|
||||||
|
"maxPublished", f.maxPublishedLayer,
|
||||||
|
"feed", extPkt.Packet.SSRC,
|
||||||
|
)
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1467,6 +1492,8 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
|
|||||||
"current", f.currentLayers,
|
"current", f.currentLayers,
|
||||||
"target", f.targetLayers,
|
"target", f.targetLayers,
|
||||||
"max", f.maxLayers,
|
"max", f.maxLayers,
|
||||||
|
"layer", layer,
|
||||||
|
"req", f.requestLayerSpatial,
|
||||||
"maxPublished", f.maxPublishedLayer,
|
"maxPublished", f.maxPublishedLayer,
|
||||||
"feed", extPkt.Packet.SSRC,
|
"feed", extPkt.Packet.SSRC,
|
||||||
)
|
)
|
||||||
@@ -1477,7 +1504,16 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
|
|||||||
// if locked to higher than max layer due to overshoot, check if it can be dialed back
|
// if locked to higher than max layer due to overshoot, check if it can be dialed back
|
||||||
if f.targetLayers.Spatial > f.maxLayers.Spatial {
|
if f.targetLayers.Spatial > f.maxLayers.Spatial {
|
||||||
if layer <= f.maxLayers.Spatial && extPkt.KeyFrame {
|
if layer <= f.maxLayers.Spatial && extPkt.KeyFrame {
|
||||||
f.logger.Infow("adjusting overshoot", "current", f.currentLayers, "target", f.targetLayers, "layer", layer, "feed", extPkt.Packet.SSRC)
|
f.logger.Infow(
|
||||||
|
"adjusting overshoot",
|
||||||
|
"current", f.currentLayers,
|
||||||
|
"target", f.targetLayers,
|
||||||
|
"max", f.maxLayers,
|
||||||
|
"layer", layer,
|
||||||
|
"req", f.requestLayerSpatial,
|
||||||
|
"maxPublished", f.maxPublishedLayer,
|
||||||
|
"feed", extPkt.Packet.SSRC,
|
||||||
|
)
|
||||||
f.currentLayers.Spatial = layer
|
f.currentLayers.Spatial = layer
|
||||||
f.targetLayers.Spatial = layer
|
f.targetLayers.Spatial = layer
|
||||||
|
|
||||||
|
|||||||
+31
-35
@@ -215,7 +215,7 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
require.Equal(t, f.parkedLayers, f.TargetLayers())
|
require.Equal(t, f.parkedLayers, f.TargetLayers())
|
||||||
f.parkedLayers = InvalidLayers
|
f.parkedLayers = InvalidLayers
|
||||||
|
|
||||||
// when max layers changes, should switch to that
|
// when max layers changes, target is opportunistic, but requested spatial layer should be at max
|
||||||
f.maxLayers = VideoLayers{Spatial: 1, Temporal: 3}
|
f.maxLayers = VideoLayers{Spatial: 1, Temporal: 3}
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
pauseReason: VideoPauseReasonFeedDry,
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
@@ -280,32 +280,7 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
// max layers changing, feed dry, current invalid, no overshoot, should set target to max layers
|
|
||||||
f.SetMaxSpatialLayer(0)
|
|
||||||
f.SetMaxTemporalLayer(3)
|
|
||||||
f.currentLayers = InvalidLayers
|
f.currentLayers = InvalidLayers
|
||||||
expectedTargetLayers = VideoLayers{
|
|
||||||
Spatial: 0,
|
|
||||||
Temporal: DefaultMaxLayerTemporal,
|
|
||||||
}
|
|
||||||
expectedMaxLayers := VideoLayers{
|
|
||||||
Spatial: 0,
|
|
||||||
Temporal: DefaultMaxLayerTemporal,
|
|
||||||
}
|
|
||||||
expectedResult = VideoAllocation{
|
|
||||||
pauseReason: VideoPauseReasonFeedDry,
|
|
||||||
bandwidthRequested: 0,
|
|
||||||
bandwidthDelta: 0,
|
|
||||||
bitrates: emptyBitrates,
|
|
||||||
targetLayers: expectedTargetLayers,
|
|
||||||
requestLayerSpatial: expectedTargetLayers.Spatial,
|
|
||||||
maxLayers: expectedMaxLayers,
|
|
||||||
distanceToDesired: 0,
|
|
||||||
}
|
|
||||||
result = f.AllocateOptimal(nil, emptyBitrates, false)
|
|
||||||
require.Equal(t, expectedResult, result)
|
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
|
||||||
|
|
||||||
// opportunistic target if feed is not dry and current is not valid, i. e. not forwarding
|
// opportunistic target if feed is not dry and current is not valid, i. e. not forwarding
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
@@ -314,8 +289,8 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
bitrates: emptyBitrates,
|
bitrates: emptyBitrates,
|
||||||
targetLayers: DefaultMaxLayers,
|
targetLayers: DefaultMaxLayers,
|
||||||
requestLayerSpatial: 0,
|
requestLayerSpatial: 2,
|
||||||
maxLayers: expectedMaxLayers,
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true)
|
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true)
|
||||||
@@ -323,16 +298,16 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
require.Equal(t, DefaultMaxLayers, f.TargetLayers())
|
require.Equal(t, DefaultMaxLayers, f.TargetLayers())
|
||||||
|
|
||||||
// if feed is not dry and target is not valid, should be opportunistic (with and without overshoot)
|
// if feed is not dry and current is not locked, should be opportunistic (with and without overshoot)
|
||||||
f.targetLayers = InvalidLayers
|
f.targetLayers = InvalidLayers
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
pauseReason: VideoPauseReasonFeedDry,
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
bitrates: emptyBitrates,
|
bitrates: emptyBitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: DefaultMaxLayers,
|
||||||
requestLayerSpatial: 0,
|
requestLayerSpatial: 2,
|
||||||
maxLayers: expectedMaxLayers,
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, false)
|
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, false)
|
||||||
@@ -350,8 +325,8 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
bitrates: emptyBitrates,
|
bitrates: emptyBitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
requestLayerSpatial: 0,
|
requestLayerSpatial: 2,
|
||||||
maxLayers: expectedMaxLayers,
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true)
|
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true)
|
||||||
@@ -371,12 +346,33 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
bitrates: emptyBitrates,
|
bitrates: emptyBitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
requestLayerSpatial: 1,
|
requestLayerSpatial: 1,
|
||||||
maxLayers: expectedMaxLayers,
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal([]int32{1}, emptyBitrates, true)
|
result = f.AllocateOptimal([]int32{1}, emptyBitrates, true)
|
||||||
require.Equal(t, expectedResult, result)
|
require.Equal(t, expectedResult, result)
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
|
|
||||||
|
// stays the same if feed is not dry and current is valid, available and locked
|
||||||
|
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 1}
|
||||||
|
f.requestLayerSpatial = 0
|
||||||
|
expectedTargetLayers = VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: 1,
|
||||||
|
}
|
||||||
|
expectedResult = VideoAllocation{
|
||||||
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
|
bandwidthRequested: 0,
|
||||||
|
bandwidthDelta: 0,
|
||||||
|
bitrates: emptyBitrates,
|
||||||
|
targetLayers: expectedTargetLayers,
|
||||||
|
requestLayerSpatial: 0,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
|
distanceToDesired: 0,
|
||||||
|
}
|
||||||
|
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true)
|
||||||
|
require.Equal(t, expectedResult, result)
|
||||||
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForwarderProvisionalAllocate(t *testing.T) {
|
func TestForwarderProvisionalAllocate(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user