Fix a case of changing video quality not succeeding. (#1483)

In the following order, got the wrong layer
- Max layer is 0, max published is 0, request layer is 0
- Current locks to 0.
- Max changes to 1. Nothing changes as 1 is not published yet.
- Max published changes to 1.
- As curernt layer is valid, available and locked to request layer, it
  was kept. But, it should have checked if the request layer changed
  and updated accordingly.
This commit is contained in:
Raja Subramanian
2023-03-01 11:12:54 +05:30
committed by GitHub
parent ab098d951e
commit a35eecd03d
2 changed files with 27 additions and 7 deletions
+3 -6
View File
@@ -544,10 +544,6 @@ func (f *Forwarder) AllocateOptimal(availableLayers []int32, brs Bitrates, allow
alloc.targetLayers = f.parkedLayers alloc.targetLayers = f.parkedLayers
alloc.requestLayerSpatial = alloc.targetLayers.Spatial alloc.requestLayerSpatial = alloc.targetLayers.Spatial
case f.maxLayers != f.lastAllocation.maxLayers:
opportunisticAlloc()
alloc.requestLayerSpatial = int32(math.Min(float64(f.maxLayers.Spatial), float64(f.maxPublishedLayer)))
case len(availableLayers) == 0: case len(availableLayers) == 0:
// feed may be dry // feed may be dry
if f.currentLayers.IsValid() { if f.currentLayers.IsValid() {
@@ -585,14 +581,15 @@ func (f *Forwarder) AllocateOptimal(availableLayers []int32, brs Bitrates, allow
alloc.requestLayerSpatial = alloc.targetLayers.Spatial alloc.requestLayerSpatial = alloc.targetLayers.Spatial
} else { } else {
if f.currentLayers.IsValid() && f.currentLayers.Spatial == f.requestLayerSpatial { requestLayerSpatial := int32(math.Min(float64(f.maxLayers.Spatial), float64(f.maxPublishedLayer)))
if f.currentLayers.IsValid() && requestLayerSpatial == f.requestLayerSpatial && f.currentLayers.Spatial == f.requestLayerSpatial {
// current is locked to desired, stay there // current is locked to desired, stay there
alloc.targetLayers = f.currentLayers alloc.targetLayers = f.currentLayers
alloc.requestLayerSpatial = f.requestLayerSpatial alloc.requestLayerSpatial = f.requestLayerSpatial
} else { } else {
// opportunistically latch on to anything // opportunistically latch on to anything
opportunisticAlloc() opportunisticAlloc()
alloc.requestLayerSpatial = int32(math.Min(float64(f.maxLayers.Spatial), float64(f.maxPublishedLayer))) alloc.requestLayerSpatial = requestLayerSpatial
} }
} }
} }
+24 -1
View File
@@ -354,6 +354,7 @@ func TestForwarderAllocateOptimal(t *testing.T) {
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 // stays the same if feed is not dry and current is valid, available and locked
f.maxLayers = VideoLayers{Spatial: 0, Temporal: 1}
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 1} f.currentLayers = VideoLayers{Spatial: 0, Temporal: 1}
f.requestLayerSpatial = 0 f.requestLayerSpatial = 0
expectedTargetLayers = VideoLayers{ expectedTargetLayers = VideoLayers{
@@ -367,7 +368,29 @@ func TestForwarderAllocateOptimal(t *testing.T) {
bitrates: emptyBitrates, bitrates: emptyBitrates,
targetLayers: expectedTargetLayers, targetLayers: expectedTargetLayers,
requestLayerSpatial: 0, requestLayerSpatial: 0,
maxLayers: DefaultMaxLayers, maxLayers: f.maxLayers,
distanceToDesired: 0,
}
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true)
require.Equal(t, expectedResult, result)
require.Equal(t, expectedResult, f.lastAllocation)
// opportunistic if feed is not dry and current is valid, but request layer has changed
f.maxLayers = VideoLayers{Spatial: 2, Temporal: 1}
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 1}
f.requestLayerSpatial = 0
expectedTargetLayers = VideoLayers{
Spatial: 2,
Temporal: 3,
}
expectedResult = VideoAllocation{
pauseReason: VideoPauseReasonFeedDry,
bandwidthRequested: 0,
bandwidthDelta: 0,
bitrates: emptyBitrates,
targetLayers: expectedTargetLayers,
requestLayerSpatial: 2,
maxLayers: f.maxLayers,
distanceToDesired: 0, distanceToDesired: 0,
} }
result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true) result = f.AllocateOptimal([]int32{0, 1}, emptyBitrates, true)