From f5c5d4e079721451ab0219500ab765135dde2f47 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 3 Jun 2023 14:26:26 +0530 Subject: [PATCH] Wait for a more stable measurement of sample rate. (#1764) --- pkg/sfu/buffer/rtpstats.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/sfu/buffer/rtpstats.go b/pkg/sfu/buffer/rtpstats.go index 62fd5a960..51c18c4d7 100644 --- a/pkg/sfu/buffer/rtpstats.go +++ b/pkg/sfu/buffer/rtpstats.go @@ -17,12 +17,12 @@ import ( ) const ( - GapHistogramNumBins = 101 - NumSequenceNumbers = 65536 - FirstSnapshotId = 1 - SnInfoSize = 8192 - SnInfoMask = SnInfoSize - 1 - TooLargeOWDDelta = 400 * time.Millisecond + GapHistogramNumBins = 101 + NumSequenceNumbers = 65536 + FirstSnapshotId = 1 + SnInfoSize = 8192 + SnInfoMask = SnInfoSize - 1 + MeasurementWindowSecondsMin = float64(5.0) ) // ------------------------------------------------------- @@ -933,13 +933,16 @@ func (r *RTPStats) GetRtcpSenderReport(ssrc uint32, srFirst *RTCPSenderReportDat } } - rtpDiffSinceFirst := nowRTPExt - r.extStartTS - rate := float64(rtpDiffSinceFirst) / timeSinceFirst.Seconds() - pidOutput := r.pidController.Update( - float64(r.params.ClockRate), - rate, - now, - ) + pidOutput := float64(0.0) + if timeSinceFirst.Seconds() > MeasurementWindowSecondsMin { + rtpDiffSinceFirst := nowRTPExt - r.extStartTS + rate := float64(rtpDiffSinceFirst) / timeSinceFirst.Seconds() + pidOutput = r.pidController.Update( + float64(r.params.ClockRate), + rate, + now, + ) + } // monitor and log RTP timestamp anomalies var ntpDiffSinceLast time.Duration