From 2cf751d2615d7816f626fed660549c272194ecfd Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 13 Sep 2023 01:38:34 +0530 Subject: [PATCH] Use timer in scorer lock scope. (#2066) Using time from outside make anachronous samples in expected distance/bit rate measurement. So, have to let the time be snap shotted in scorer lock scope. --- pkg/sfu/connectionquality/connectionstats.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/sfu/connectionquality/connectionstats.go b/pkg/sfu/connectionquality/connectionstats.go index 05daf5f25..1a977c650 100644 --- a/pkg/sfu/connectionquality/connectionstats.go +++ b/pkg/sfu/connectionquality/connectionstats.go @@ -299,7 +299,11 @@ func (cs *ConnectionStats) updateStreamingStart(at time.Time) time.Time { if packetsSent > cs.packetsSent { if cs.streamingStartedAt.IsZero() { // the start could be anywhere after last update, but using `at` as this is not required to be accurate - cs.streamingStartedAt = at + if at.IsZero() { + cs.streamingStartedAt = time.Now() + } else { + cs.streamingStartedAt = at + } } } else { cs.streamingStartedAt = time.Time{} @@ -310,7 +314,7 @@ func (cs *ConnectionStats) updateStreamingStart(at time.Time) time.Time { } func (cs *ConnectionStats) getStat() { - score, streams := cs.updateScoreAt(time.Now()) + score, streams := cs.updateScoreAt(time.Time{}) if cs.onStatsUpdate != nil && len(streams) != 0 { analyticsStreams := make([]*livekit.AnalyticsStream, 0, len(streams))