diff --git a/pkg/sfu/forwarder.go b/pkg/sfu/forwarder.go index b64824ca9..0b7320991 100644 --- a/pkg/sfu/forwarder.go +++ b/pkg/sfu/forwarder.go @@ -811,7 +811,7 @@ func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition(allowOvershoot b if f.provisional.muted || f.provisional.pubMuted { f.provisional.allocatedLayer = buffer.InvalidLayer return VideoTransition{ - From: f.vls.GetTarget(), + From: existingTargetLayer, To: f.provisional.allocatedLayer, BandwidthDelta: -getBandwidthNeeded(f.provisional.Bitrates, existingTargetLayer, f.lastAllocation.BandwidthRequested), } @@ -1300,12 +1300,18 @@ func (f *Forwarder) Pause(availableLayers []int32, brs Bitrates) VideoAllocation f.lock.Lock() defer f.lock.Unlock() + existingTargetLayer := f.vls.GetTarget() + if !existingTargetLayer.IsValid() { + // already paused + return f.lastAllocation + } + maxLayer := f.vls.GetMax() maxSeenLayer := f.vls.GetMaxSeen() optimalBandwidthNeeded := getOptimalBandwidthNeeded(f.muted, f.pubMuted, maxSeenLayer.Spatial, brs, maxLayer) alloc := VideoAllocation{ BandwidthRequested: 0, - BandwidthDelta: 0 - getBandwidthNeeded(brs, f.vls.GetTarget(), f.lastAllocation.BandwidthRequested), + BandwidthDelta: 0 - getBandwidthNeeded(brs, existingTargetLayer, f.lastAllocation.BandwidthRequested), Bitrates: brs, BandwidthNeeded: optimalBandwidthNeeded, TargetLayer: buffer.InvalidLayer, diff --git a/pkg/sfu/streamallocator/streamallocator.go b/pkg/sfu/streamallocator/streamallocator.go index f9baf7e5c..91ad018cc 100644 --- a/pkg/sfu/streamallocator/streamallocator.go +++ b/pkg/sfu/streamallocator/streamallocator.go @@ -883,8 +883,8 @@ func (s *StreamAllocator) allocateTrack(track *Track) { return } - // already streaming at some layer and transition is not requesting any change, i. e. BandwidthDelta == 0 - if transition.From.IsValid() && transition.BandwidthDelta == 0 { + // a no-op transition + if transition.From == transition.To { return }