From 254a35543d9caf5d5dcea773e4f185e40e01282a Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Tue, 12 Sep 2023 08:34:28 +0530 Subject: [PATCH] Fix down stream stats. (#2063) Need to pass in the correct time. Previously streaming start was determined by another delta snap shot which as removed for efficiency. Did not realise that we were passing in zero time for stats. Also, revert of the change (the part which did not re-pause) from this PR (https://github.com/livekit/livekit/pull/2037). That change affects other paths. The edge it was trying to fix is more rare. Need to think about a way which covers all cases. --- pkg/sfu/connectionquality/connectionstats.go | 2 +- pkg/sfu/forwarder.go | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/sfu/connectionquality/connectionstats.go b/pkg/sfu/connectionquality/connectionstats.go index 5b03cfe2..05daf5f2 100644 --- a/pkg/sfu/connectionquality/connectionstats.go +++ b/pkg/sfu/connectionquality/connectionstats.go @@ -310,7 +310,7 @@ func (cs *ConnectionStats) updateStreamingStart(at time.Time) time.Time { } func (cs *ConnectionStats) getStat() { - score, streams := cs.updateScoreAt(time.Time{}) + score, streams := cs.updateScoreAt(time.Now()) if cs.onStatsUpdate != nil && len(streams) != 0 { analyticsStreams := make([]*livekit.AnalyticsStream, 0, len(streams)) diff --git a/pkg/sfu/forwarder.go b/pkg/sfu/forwarder.go index 8fc170ab..68fa1f0f 100644 --- a/pkg/sfu/forwarder.go +++ b/pkg/sfu/forwarder.go @@ -1307,18 +1307,12 @@ func (f *Forwarder) Pause(availableLayers []int32, brs Bitrates) VideoAllocation f.lock.Lock() defer f.lock.Unlock() - existingTargetLayer := f.vls.GetTarget() - if !existingTargetLayer.IsValid() { - // already paused - return f.lastAllocation - } - maxLayer := f.vls.GetMax() maxSeenLayer := f.vls.GetMaxSeen() optimalBandwidthNeeded := getOptimalBandwidthNeeded(f.muted, f.pubMuted, maxSeenLayer.Spatial, brs, maxLayer) alloc := VideoAllocation{ BandwidthRequested: 0, - BandwidthDelta: 0 - getBandwidthNeeded(brs, existingTargetLayer, f.lastAllocation.BandwidthRequested), + BandwidthDelta: 0 - getBandwidthNeeded(brs, f.vls.GetTarget(), f.lastAllocation.BandwidthRequested), Bitrates: brs, BandwidthNeeded: optimalBandwidthNeeded, TargetLayer: buffer.InvalidLayer,