Refactoring connection stats (#384)

This commit is contained in:
Raja Subramanian
2022-01-29 00:55:00 +05:30
committed by GitHub
parent 9747243ce2
commit 5b57522c05
9 changed files with 299 additions and 374 deletions
+9 -17
View File
@@ -22,16 +22,8 @@ func Score2Rating(score float64) livekit.ConnectionQuality {
return livekit.ConnectionQuality_POOR
}
func mosAudioEmodel(delta ConnectionStat, jitter uint32) float64 {
// find percentage of lost packets in this window
if delta.TotalPackets == 0 {
return 0.0
}
percentageLost := (float64(delta.PacketsLost) / float64(delta.TotalPackets)) * 100
rx := 93.2 - percentageLost
func mosAudioEmodel(pctLoss float64, jitter uint32) float64 {
rx := 93.2 - pctLoss
ry := 0.18*rx*rx - 27.9*rx + 1126.62
// Jitter is in MicroSecs (1/1e6) units. Convert it to MilliSecs
@@ -55,27 +47,27 @@ func mosAudioEmodel(delta ConnectionStat, jitter uint32) float64 {
return score
}
func loss2Score(loss uint32, reducedQuality bool) float64 {
func loss2Score(pctLoss float64, reducedQuality bool) float64 {
// No Loss, excellent
if loss == 0 && !reducedQuality {
if pctLoss == 0.0 && !reducedQuality {
return 5
}
// default when loss is minimal, but reducedQuality
score := 3.5
// loss is bad
if loss >= 4 {
if pctLoss >= 4.0 {
score = 2.0
} else if loss <= 2 && !reducedQuality {
} else if pctLoss <= 2.0 && !reducedQuality {
// loss is acceptable and at reduced quality
score = 4.5
}
return score
}
func AudioConnectionScore(delta ConnectionStat, jitter uint32) float64 {
return mosAudioEmodel(delta, jitter)
func AudioConnectionScore(pctLoss float64, jitter uint32) float64 {
return mosAudioEmodel(pctLoss, jitter)
}
func VideoConnectionScore(pctLoss uint32, reducedQuality bool) float64 {
func VideoConnectionScore(pctLoss float64, reducedQuality bool) float64 {
return loss2Score(pctLoss, reducedQuality)
}