diff --git a/pkg/sfu/forwarder.go b/pkg/sfu/forwarder.go index 3059439a..6fe51513 100644 --- a/pkg/sfu/forwarder.go +++ b/pkg/sfu/forwarder.go @@ -556,7 +556,12 @@ func (f *Forwarder) SetMaxSpatialLayer(spatialLayer int32) (bool, buffer.VideoLa f.logger.Debugw("setting max spatial layer", "layer", spatialLayer) f.vls.SetMaxSpatial(spatialLayer) - return true, f.vls.GetMax() + newMax := f.vls.GetMax() + if f.vls.GetTarget().Spatial == buffer.InvalidLayerSpatial && !f.isDeficientLocked() { + f.logger.Debugw("opportunistically setting target spatial layer", "layer", newMax.Spatial) + f.vls.SetTarget(newMax) + } + return true, newMax } func (f *Forwarder) SetMaxTemporalLayer(temporalLayer int32) (bool, buffer.VideoLayer) { diff --git a/pkg/sfu/forwarder_test.go b/pkg/sfu/forwarder_test.go index ee2743b9..ad24469a 100644 --- a/pkg/sfu/forwarder_test.go +++ b/pkg/sfu/forwarder_test.go @@ -464,6 +464,9 @@ func TestForwarderProvisionalAllocate(t *testing.T) { f.SetMaxPublishedLayer(buffer.DefaultMaxLayerSpatial) f.SetMaxTemporalLayerSeen(buffer.DefaultMaxLayerTemporal) + // Reset to invalid layers for testing allocation from scratch + disable(f) + bitrates := Bitrates{ {1, 2, 3, 4}, {5, 6, 7, 8}, @@ -682,6 +685,9 @@ func TestForwarderProvisionalAllocateMute(t *testing.T) { f.SetMaxSpatialLayer(buffer.DefaultMaxLayerSpatial) f.SetMaxTemporalLayer(buffer.DefaultMaxLayerTemporal) + // Reset to invalid layers for testing muted state + disable(f) + bitrates := Bitrates{ {1, 2, 3, 4}, {5, 6, 7, 8}, @@ -723,6 +729,9 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) { f.SetMaxPublishedLayer(buffer.DefaultMaxLayerSpatial) f.SetMaxTemporalLayerSeen(buffer.DefaultMaxLayerTemporal) + // Reset to invalid layers for testing cooperative transition from scratch + disable(f) + availableLayers := []int32{0, 1, 2} bitrates := Bitrates{ {1, 2, 3, 4},