diff --git a/pkg/sfu/receiver_base.go b/pkg/sfu/receiver_base.go index ae0111b2..31cc25aa 100644 --- a/pkg/sfu/receiver_base.go +++ b/pkg/sfu/receiver_base.go @@ -157,6 +157,7 @@ type TrackReceiver interface { type REDTransformer interface { TrackReceiver + SetLBThreshold(lbThreshold int) ForwardRTP(pkt *buffer.ExtPacket, spatialLayer int32) int32 ForwardRTCPSenderReport( payloadType webrtc.PayloadType, @@ -312,6 +313,9 @@ func (r *ReceiverBase) SetEnableRTPStreamRestartDetection(enableRTPStremRestartD func (r *ReceiverBase) SetLBThreshold(lbThreshold int) { r.lbThreshold = lbThreshold r.downTrackSpreader.SetThreshold(lbThreshold) + if rt := r.loadREDTransformer(); rt != nil { + rt.SetLBThreshold(lbThreshold) + } } func (r *ReceiverBase) SetForwardStats(forwardStats *ForwardStats) { diff --git a/pkg/sfu/redprimaryreceiver.go b/pkg/sfu/redprimaryreceiver.go index 4963a14b..ca81ce89 100644 --- a/pkg/sfu/redprimaryreceiver.go +++ b/pkg/sfu/redprimaryreceiver.go @@ -61,6 +61,10 @@ func NewRedPrimaryReceiver(receiver TrackReceiver, dsp utils.DownTrackSpreaderPa } } +func (r *RedPrimaryReceiver) SetLBThreshold(lbThreshold int) { + r.downTrackSpreader.SetThreshold(lbThreshold) +} + func (r *RedPrimaryReceiver) ForwardRTP(pkt *buffer.ExtPacket, spatialLayer int32) int32 { // extract primary payload from RED and forward to downtracks if r.downTrackSpreader.DownTrackCount() == 0 { diff --git a/pkg/sfu/redreceiver.go b/pkg/sfu/redreceiver.go index b93f3431..959a54e9 100644 --- a/pkg/sfu/redreceiver.go +++ b/pkg/sfu/redreceiver.go @@ -61,6 +61,10 @@ func NewRedReceiver(receiver TrackReceiver, dsp utils.DownTrackSpreaderParams) R } } +func (r *RedReceiver) SetLBThreshold(lbThreshold int) { + r.downTrackSpreader.SetThreshold(lbThreshold) +} + func (r *RedReceiver) ForwardRTP(pkt *buffer.ExtPacket, spatialLayer int32) int32 { // encode RED payload from primary payload and forward to downtracks if r.downTrackSpreader.DownTrackCount() == 0 { diff --git a/pkg/sfu/utils/downtrackspreader_test.go b/pkg/sfu/utils/downtrackspreader_test.go deleted file mode 100644 index adb0f3c3..00000000 --- a/pkg/sfu/utils/downtrackspreader_test.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2026 LiveKit, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import ( - "testing" - - "github.com/livekit/protocol/livekit" - "github.com/stretchr/testify/require" -) - -type testSender struct { - subscriberID livekit.ParticipantID -} - -func (t testSender) SubscriberID() livekit.ParticipantID { - return t.subscriberID -} - -func TestDownTrackSpreaderSetThreshold(t *testing.T) { - spreader := NewDownTrackSpreader[testSender](DownTrackSpreaderParams{}) - - spreader.SetThreshold(20) - - spreader.downTrackMu.RLock() - threshold := spreader.params.Threshold - spreader.downTrackMu.RUnlock() - - require.Equal(t, 20, threshold) -}