Files
livekit/pkg/sfu/export_test.go
T
Raja SubramanianandClaude Opus 5.5 c2de273198 DownTrack: arm key frame requester timer only while a layer lock is pending (#4980)
The key frame requester re-armed its timer on every loop, so every video down
track woke up every 200 ms to 1 s for its whole life, even when the layer was
locked and there was nothing to do.

Re-arm the timer only while the requested layer is not locked, or while the
lock can change without an event: an acquisition grace is armed, or layers are
selected with the dependency descriptor, which can lose the lock on the packet
path. Post the event on resync, mute, max published layer change and packet
path layer switch, since those can change the lock without an allocation.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 11:25:37 +05:30

84 lines
2.8 KiB
Go

// 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 sfu
import (
"time"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
)
// Test-only seams that expose DownTrack internals to the external sfu_test package.
// This file is only compiled into the test binary (its name ends in _test.go), so it
// does not affect the production API. The external test package is required because the
// integration tests import the streamallocator package, which itself imports sfu (an
// import cycle that an in-package test cannot resolve).
func (d *DownTrack) IsWritableForTest() bool { return d.writable.Load() }
func (d *DownTrack) PayloadTypeRTXForTest() uint32 { return d.payloadTypeRTX.Load() }
func (d *DownTrack) RTPStatsActiveForTest() bool { return d.rtpStats.IsActive() }
func (d *DownTrack) LastReceiverReportTimeForTest() int64 {
return d.rtpStats.LastReceiverReportTime()
}
func (d *DownTrack) ExtIDsForTest() (absSendTime int, transportWide int) {
return d.absSendTimeExtID, d.transportWideExtID
}
func (d *DownTrack) HandleRTCPForTest(pkt []byte) { d.handleRTCP(pkt) }
func (d *DownTrack) SetRTPHeaderExtensionsForTest() { d.setRTPHeaderExtensions() }
// ForceForwardLayerForTest forces the forwarder onto a valid current/target layer so a
// (non-simulcast) video packet will be forwarded without driving full allocation.
func (d *DownTrack) ForceForwardLayerForTest(layer buffer.VideoLayer) {
d.forwarder.ForceLayerForTest(layer)
}
// RetransmitForTest drives the (unexported) retransmitPacket path with an in-package
// extPacketMeta built from exported values, so the external test can exercise the
// retransmit path.
func (d *DownTrack) RetransmitForTest(
sourceSeqNo uint64,
targetSeqNo uint16,
timestamp uint32,
extTimestamp uint64,
layer int8,
sourcePkt []byte,
trailerStripped uint8,
) (int, error) {
epm := extPacketMeta{
packetMeta: packetMeta{
sourceSeqNo: sourceSeqNo,
targetSeqNo: targetSeqNo,
timestamp: timestamp,
layer: layer,
trailerStripped: trailerStripped,
},
extSequenceNumber: uint64(targetSeqNo),
extTimestamp: extTimestamp,
}
return d.retransmitPacket(&epm, sourcePkt, false)
}
const KeyFrameIntervalMaxForTest = keyFrameIntervalMax * time.Millisecond
func (d *DownTrack) KeyFrameRequesterWakeupsForTest() uint32 {
return d.keyFrameRequesterWakeups.Load()
}