From 750d5904f0e4de0d3e16b1006b86e620ebeb6d19 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Mon, 16 Mar 2026 15:20:13 +0530 Subject: [PATCH] Add API to restart lite stats. (#4366) --- pkg/sfu/buffer/buffer_base.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pkg/sfu/buffer/buffer_base.go b/pkg/sfu/buffer/buffer_base.go index cb3818270..3251ab853 100644 --- a/pkg/sfu/buffer/buffer_base.go +++ b/pkg/sfu/buffer/buffer_base.go @@ -460,6 +460,10 @@ func (b *BufferBase) setupRTPStats(clockRate uint32) { b.deltaStatsSnapshotId = b.rtpStats.NewSnapshotId() } + b.setupRTPStatsLite(clockRate) +} + +func (b *BufferBase) setupRTPStatsLite(clockRate uint32) { if b.params.IsOOBSequenceNumber { b.rtpStatsLite = rtpstats.NewRTPStatsReceiverLite(rtpstats.RTPStatsParams{}) b.rtpStatsLite.SetLogger(b.logger) @@ -474,21 +478,40 @@ func (b *BufferBase) stopRTPStats(reason string) (stats *livekit.RTPStats, stats b.rtpStats.Stop() stats = b.rtpStats.ToProto() } + b.logger.Debugw( + "rtp stats", + "direction", "upstream", + "stats", b.rtpStats, + "reason", reason, + ) + + statsLite = b.stopRTPStatsLite(reason) + return +} + +func (b *BufferBase) stopRTPStatsLite(reason string) (statsLite *livekit.RTPStats) { if b.rtpStatsLite != nil { b.rtpStatsLite.Stop() statsLite = b.rtpStatsLite.ToProto() } b.logger.Debugw( - "rtp stats", + "rtp stats lite", "direction", "upstream", - "stats", b.rtpStats, "statsLite", b.rtpStatsLite, "reason", reason, ) return } +func (b *BufferBase) RestartStatsLite(reason string) { + b.Lock() + defer b.Unlock() + + b.stopRTPStatsLite(reason) + b.setupRTPStatsLite(b.clockRate) +} + func (b *BufferBase) MarkForRestartStream(reason string) { b.logger.Debugw("marking for stream restart", "reason", reason)