From a1338b149cf14e3496669528f42faba9a28b81ef Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 8 Feb 2023 11:28:32 +0530 Subject: [PATCH] Limit layer to num advertised. (#1395) * Limit layer to num advertised. Otherwise, this leads to invalid layer for non-simulcast tracks. * need to subtrack 1 * fix test --- pkg/sfu/forwarder.go | 2 +- pkg/sfu/forwarder_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/sfu/forwarder.go b/pkg/sfu/forwarder.go index 55b43a1f2..0cd185f65 100644 --- a/pkg/sfu/forwarder.go +++ b/pkg/sfu/forwarder.go @@ -746,7 +746,7 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates, allowOvershoot bool) VideoAllo } else { // opportunisitically latch on to anything alloc.targetLayers = VideoLayers{ - Spatial: DefaultMaxLayerSpatial, + Spatial: int32(math.Max(0, float64(f.numAdvertisedLayers-1))), Temporal: DefaultMaxLayerTemporal, } } diff --git a/pkg/sfu/forwarder_test.go b/pkg/sfu/forwarder_test.go index 5248bd587..d86371f51 100644 --- a/pkg/sfu/forwarder_test.go +++ b/pkg/sfu/forwarder_test.go @@ -197,10 +197,11 @@ func TestForwarderAllocateOptimal(t *testing.T) { f.Mute(false) // feed dry state, target set to maximum for opportunistic start + f.SetNumAdvertisedLayers(3) f.lastAllocation.state = VideoAllocationStateNone disable(f) expectedTargetLayers := VideoLayers{ - Spatial: DefaultMaxLayerSpatial, + Spatial: 2, Temporal: DefaultMaxLayerTemporal, } expectedResult = VideoAllocation{