From d4f31d36283745d9fa95925f6fc7f2c6b4282df6 Mon Sep 17 00:00:00 2001 From: boks1971 Date: Wed, 19 Jul 2023 18:10:13 +0530 Subject: [PATCH] min PPS --- pkg/sfu/streamallocator/channelobserver.go | 4 ++-- pkg/sfu/streamallocator/nacktracker.go | 15 +++++++++++++-- pkg/sfu/streamallocator/streamallocator.go | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/sfu/streamallocator/channelobserver.go b/pkg/sfu/streamallocator/channelobserver.go index 818562722..65a425481 100644 --- a/pkg/sfu/streamallocator/channelobserver.go +++ b/pkg/sfu/streamallocator/channelobserver.go @@ -61,7 +61,7 @@ type ChannelObserverParams struct { EstimateDownwardTrendThreshold float64 EstimateCollapseThreshold time.Duration EstimateValidityWindow time.Duration - NackMinPackets uint32 + NackMinPPS uint32 NackWindowMinDuration time.Duration NackWindowMaxDuration time.Duration NackRatioThreshold float64 @@ -90,7 +90,7 @@ func NewChannelObserver(params ChannelObserverParams, logger logger.Logger) *Cha nackTracker: NewNackTracker(NackTrackerParams{ Name: params.Name + "-nack", Logger: logger, - MinPackets: params.NackMinPackets, + MinPPS: params.NackMinPPS, WindowMinDuration: params.NackWindowMinDuration, WindowMaxDuration: params.NackWindowMaxDuration, RatioThreshold: params.NackRatioThreshold, diff --git a/pkg/sfu/streamallocator/nacktracker.go b/pkg/sfu/streamallocator/nacktracker.go index 46182fa05..8e3f27db6 100644 --- a/pkg/sfu/streamallocator/nacktracker.go +++ b/pkg/sfu/streamallocator/nacktracker.go @@ -12,7 +12,7 @@ import ( type NackTrackerParams struct { Name string Logger logger.Logger - MinPackets uint32 + MinPPS uint32 WindowMinDuration time.Duration WindowMaxDuration time.Duration RatioThreshold float64 @@ -63,7 +63,18 @@ func (n *NackTracker) Add(packets uint32, repeatedNacks uint32) { func (n *NackTracker) GetRatio() float64 { ratio := 0.0 - if n.packets != 0 && n.packets >= n.params.MinPackets { + + var elapsed time.Duration + if !n.windowStartTime.IsZero() { + elapsed = time.Since(n.windowStartTime) + } + + pps := uint32(0) + if elapsed.Seconds() != 0 { + pps = uint32(float64(n.packets) / elapsed.Seconds()) + } + + if n.packets != 0 && pps > n.params.MinPPS { ratio = float64(n.repeatedNacks) / float64(n.packets) if ratio > 1.0 { ratio = 1.0 diff --git a/pkg/sfu/streamallocator/streamallocator.go b/pkg/sfu/streamallocator/streamallocator.go index b98f20d66..26682ef30 100644 --- a/pkg/sfu/streamallocator/streamallocator.go +++ b/pkg/sfu/streamallocator/streamallocator.go @@ -46,7 +46,7 @@ var ( EstimateDownwardTrendThreshold: 0.0, EstimateCollapseThreshold: 0, EstimateValidityWindow: 10 * time.Second, - NackMinPackets: 0, + NackMinPPS: 0, NackWindowMinDuration: 500 * time.Millisecond, NackWindowMaxDuration: 1 * time.Second, NackRatioThreshold: 0.04, @@ -58,7 +58,7 @@ var ( EstimateDownwardTrendThreshold: -0.5, EstimateCollapseThreshold: 500 * time.Millisecond, EstimateValidityWindow: 10 * time.Second, - NackMinPackets: 50, + NackMinPPS: 50, NackWindowMinDuration: 1 * time.Second, NackWindowMaxDuration: 2 * time.Second, NackRatioThreshold: 0.08,