Check for valid layers and also log unexpected target (#1438)

This commit is contained in:
Raja Subramanian
2023-02-17 23:39:06 +05:30
committed by GitHub
parent 9f33ce0ecd
commit 9bf80511a9
+15 -5
View File
@@ -554,7 +554,17 @@ func (f *Forwarder) BandwidthRequested(brs Bitrates) int64 {
f.lock.RLock()
defer f.lock.RUnlock()
if f.targetLayers == InvalidLayers {
if !f.targetLayers.IsValid() {
if f.targetLayers != InvalidLayers {
f.logger.Warnw(
"unexpected target layers", nil,
"target", f.targetLayers,
"current", f.currentLayers,
"parked", f.parkedLayers,
"max", f.maxLayers,
"lastAllocation", f.lastAllocation,
)
}
return 0
}
@@ -762,7 +772,7 @@ func (f *Forwarder) ProvisionalAllocate(availableChannelCapacity int64, layers V
// 2. a layer above maximum which may or may not fit.
// In any of those cases, take the lowest possible layer if pause is not allowed
//
if !allowPause && (f.provisional.allocatedLayers == InvalidLayers || !layers.GreaterThan(f.provisional.allocatedLayers)) {
if !allowPause && (!f.provisional.allocatedLayers.IsValid() || !layers.GreaterThan(f.provisional.allocatedLayers)) {
f.provisional.allocatedLayers = layers
return requiredBitrate - alreadyAllocatedBitrate
}
@@ -874,7 +884,7 @@ func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition(allowOvershoot b
targetLayers := f.targetLayers
bandwidthRequired := int64(0)
if targetLayers == InvalidLayers {
if !targetLayers.IsValid() {
// currently not streaming, find minimal
// NOTE: a layer in feed could have paused and there could be other options than going back to minimal,
// but the cooperative scheme knocks things back to minimal
@@ -893,7 +903,7 @@ func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition(allowOvershoot b
}
// if nothing available, just leave target at current to enable opportunistic forwarding in case current resumes
if targetLayers == InvalidLayers {
if !targetLayers.IsValid() {
if f.provisional.parkedLayers.IsValid() {
targetLayers = f.provisional.parkedLayers
} else {
@@ -1292,7 +1302,7 @@ func (f *Forwarder) updateAllocation(alloc VideoAllocation, reason string) Video
f.lastAllocation = alloc
f.setTargetLayers(f.lastAllocation.targetLayers)
if f.targetLayers == InvalidLayers {
if !f.targetLayers.IsValid() {
f.resyncLocked()
}