Connection quality v1 (#260)
* audio connection quality mos for publisher stats Signed-off-by: shishir gowda <shishir@livekit.io> * Update tests Signed-off-by: shishir gowda <shishir@livekit.io> * Change ratings range, increase default rtt to 80 Signed-off-by: shishir gowda <shishir@livekit.io> * Use stats worker to get total packets to find %lost in window Signed-off-by: shishir gowda <shishir@livekit.io> * Update go dep Signed-off-by: shishir gowda <shishir@livekit.io> * Increase interval of score cal to 5 seconds Signed-off-by: shishir gowda <shishir@livekit.io> * use lastSequenceNumber in reports to find total packets Signed-off-by: shishir gowda <shishir@livekit.io> * Account for delay while calculating scores Signed-off-by: shishir gowda <shishir@livekit.io> * Fix minor typo Signed-off-by: shishir gowda <shishir@livekit.io> * Add connection stats/score to subscribed audio tracks Signed-off-by: shishir gowda <shishir@livekit.io> * Cleanup Signed-off-by: shishir gowda <shishir@livekit.io> * Ignore duplicate LastSequenceNumbers in rtcp reports Ignore if sequence number is less than what was recieved Signed-off-by: shishir gowda <shishir@livekit.io> * Move video track score calc to media/downtracks Signed-off-by: shishir gowda <shishir@livekit.io> * Deprecate SubscribeLossPercentage() as score calc is now handled downstream Signed-off-by: shishir gowda <shishir@livekit.io> * Initialize connection score to excellent score is calc at 5sec interval. Client fetches score before first score is computed * Update test cases for connection quality Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
+17
-26
@@ -2,6 +2,7 @@ package rtc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||
"io"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -665,50 +666,40 @@ func (p *ParticipantImpl) GetAudioLevel() (level uint8, active bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) GetConnectionQuality() livekit.ConnectionQuality {
|
||||
func (p *ParticipantImpl) GetConnectionQuality() *livekit.ConnectionQualityInfo {
|
||||
// avg loss across all tracks, weigh published the same as subscribed
|
||||
var pubLoss, subLoss uint32
|
||||
var reducedQualityPub bool
|
||||
var reducedQualitySub bool
|
||||
var scores float64
|
||||
var numTracks int
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
for _, pubTrack := range p.publishedTracks {
|
||||
if pubTrack.IsMuted() {
|
||||
continue
|
||||
}
|
||||
pubLoss += pubTrack.PublishLossPercentage()
|
||||
publishing, registered := pubTrack.NumUpTracks()
|
||||
if registered > 0 && publishing != registered {
|
||||
reducedQualityPub = true
|
||||
}
|
||||
}
|
||||
numTracks := uint32(len(p.publishedTracks))
|
||||
if numTracks > 0 {
|
||||
pubLoss /= numTracks
|
||||
scores += pubTrack.GetConnectionScore()
|
||||
numTracks++
|
||||
}
|
||||
|
||||
for _, subTrack := range p.subscribedTracks {
|
||||
if subTrack.IsMuted() {
|
||||
continue
|
||||
}
|
||||
if subTrack.DownTrack().GetForwardingStatus() != sfu.ForwardingStatusOptimal {
|
||||
reducedQualitySub = true
|
||||
}
|
||||
subLoss += subTrack.SubscribeLossPercentage()
|
||||
scores += subTrack.DownTrack().GetConnectionScore()
|
||||
numTracks++
|
||||
}
|
||||
numTracks = uint32(len(p.subscribedTracks))
|
||||
|
||||
var avgScore float64
|
||||
if numTracks > 0 {
|
||||
subLoss /= numTracks
|
||||
avgScore = scores / float64(numTracks)
|
||||
}
|
||||
|
||||
avgLoss := (pubLoss + subLoss) / 2
|
||||
if avgLoss >= 4 {
|
||||
return livekit.ConnectionQuality_POOR
|
||||
} else if avgLoss <= 2 && !reducedQualityPub && !reducedQualitySub {
|
||||
return livekit.ConnectionQuality_EXCELLENT
|
||||
}
|
||||
rating := connectionquality.Score2Rating(avgScore)
|
||||
|
||||
return livekit.ConnectionQuality_GOOD
|
||||
return &livekit.ConnectionQualityInfo{
|
||||
ParticipantSid: p.ID(),
|
||||
Quality: rating,
|
||||
Score: float32(avgScore),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) IsSubscribedTo(identity string) bool {
|
||||
|
||||
Reference in New Issue
Block a user