From 2f2d0a5735c53aa43631a300a1f8aaf988871804 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Wed, 17 Dec 2025 00:02:51 -0800 Subject: [PATCH] skip lost sequence number ranges in getIntervalStats (#4166) --- pkg/sfu/rtpstats/rtpstats_sender.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/sfu/rtpstats/rtpstats_sender.go b/pkg/sfu/rtpstats/rtpstats_sender.go index 19d5b5c4a..98fb8312d 100644 --- a/pkg/sfu/rtpstats/rtpstats_sender.go +++ b/pkg/sfu/rtpstats/rtpstats_sender.go @@ -1268,13 +1268,18 @@ func (r *RTPStatsSender) getIntervalStats( extEndExclusive uint64, ehsn uint64, ) (intervalStats intervalStats) { - processESN := func(esn uint64, ehsn uint64) { - slot := r.getSnInfoOutOfOrderSlot(esn, ehsn) - if slot < 0 { - intervalStats.packetsNotFoundMetadata++ - return - } + upperBound := ehsn + 1 + lowerBound := uint64(0) + if n := uint64(len(r.snInfos)); n != 0 && ehsn >= n-1 { + lowerBound = ehsn - n + 1 + } + extStartInclusiveClamped := max(min(extStartInclusive, upperBound), lowerBound) + extEndExclusiveClamped := max(min(extEndExclusive, upperBound), extStartInclusive) + intervalStats.packetsNotFoundMetadata += (extEndExclusive - extStartInclusive) - (extEndExclusiveClamped - extStartInclusiveClamped) + + for esn := extStartInclusiveClamped; esn != extEndExclusiveClamped; esn++ { + slot := r.getSnInfoOutOfOrderSlot(esn, ehsn) snInfo := &r.snInfos[slot] switch { case snInfo.pktSize == 0: @@ -1298,10 +1303,6 @@ func (r *RTPStatsSender) getIntervalStats( intervalStats.frames++ } } - - for esn := extStartInclusive; esn != extEndExclusive; esn++ { - processESN(esn, ehsn) - } return }