Use variables for score -> quality mapping (#2268)
* Use variables for score -> quality mapping * spelling
This commit is contained in:
@@ -29,10 +29,9 @@ const (
|
|||||||
MaxMOS = float32(4.5)
|
MaxMOS = float32(4.5)
|
||||||
MinMOS = float32(1.0)
|
MinMOS = float32(1.0)
|
||||||
|
|
||||||
cMaxScore = float64(100.0)
|
cMaxScore = float64(100.0)
|
||||||
cPoorScore = float64(30.0)
|
cMinScore = float64(20.0)
|
||||||
cMinScore = float64(20.0)
|
cPausedPoorScore = float64(30.0)
|
||||||
cDisconnectedScore = cMinScore
|
|
||||||
|
|
||||||
increaseFactor = float64(0.4) // slower increase, i. e. when score is recovering move up slower -> conservative
|
increaseFactor = float64(0.4) // slower increase, i. e. when score is recovering move up slower -> conservative
|
||||||
decreaseFactor = float64(0.7) // faster decrease, i. e. when score is dropping move down faster -> aggressive to be responsive to quality drops
|
decreaseFactor = float64(0.7) // faster decrease, i. e. when score is dropping move down faster -> aggressive to be responsive to quality drops
|
||||||
@@ -42,6 +41,14 @@ const (
|
|||||||
unmuteTimeThreshold = float64(0.5)
|
unmuteTimeThreshold = float64(0.5)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
qualityTransitionScore = map[livekit.ConnectionQuality]float64{
|
||||||
|
livekit.ConnectionQuality_GOOD: 80,
|
||||||
|
livekit.ConnectionQuality_POOR: 40,
|
||||||
|
livekit.ConnectionQuality_DISCONNECTED: 20,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
|
|
||||||
type windowStat struct {
|
type windowStat struct {
|
||||||
@@ -221,7 +228,7 @@ func (q *qualityScorer) updateMuteAtLocked(isMuted bool, at time.Time) {
|
|||||||
if isMuted {
|
if isMuted {
|
||||||
q.mutedAt = at
|
q.mutedAt = at
|
||||||
// muting when DISCONNECTED should not push quality to EXCELLENT
|
// muting when DISCONNECTED should not push quality to EXCELLENT
|
||||||
if q.score != cDisconnectedScore {
|
if q.score != qualityTransitionScore[livekit.ConnectionQuality_DISCONNECTED] {
|
||||||
q.score = cMaxScore
|
q.score = cMaxScore
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -298,7 +305,7 @@ func (q *qualityScorer) updatePauseAtLocked(isPaused bool, at time.Time) {
|
|||||||
q.layerDistance.Reset()
|
q.layerDistance.Reset()
|
||||||
|
|
||||||
q.pausedAt = at
|
q.pausedAt = at
|
||||||
q.score = cPoorScore
|
q.score = cPausedPoorScore
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if q.isPaused() {
|
if q.isPaused() {
|
||||||
@@ -357,7 +364,7 @@ func (q *qualityScorer) updateAtLocked(stat *windowStat, at time.Time) {
|
|||||||
// considered (as long as enough time has passed since unmute).
|
// considered (as long as enough time has passed since unmute).
|
||||||
//
|
//
|
||||||
// Similarly, when paused (possibly due to congestion), score is immediately
|
// Similarly, when paused (possibly due to congestion), score is immediately
|
||||||
// set to cPoorScore for responsiveness. The layer transision is reest.
|
// set to cPausedPoorScore for responsiveness. The layer transision is reest.
|
||||||
// On a resume, quality climbs back up using normal operation.
|
// On a resume, quality climbs back up using normal operation.
|
||||||
if q.isMuted() || !q.isUnmutedEnough(at) || q.isLayerMuted() || q.isPaused() {
|
if q.isMuted() || !q.isUnmutedEnough(at) || q.isLayerMuted() || q.isPaused() {
|
||||||
q.lastUpdateAt = at
|
q.lastUpdateAt = at
|
||||||
@@ -369,7 +376,7 @@ func (q *qualityScorer) updateAtLocked(stat *windowStat, at time.Time) {
|
|||||||
var score float64
|
var score float64
|
||||||
if stat.packetsExpected == 0 {
|
if stat.packetsExpected == 0 {
|
||||||
reason = "dry"
|
reason = "dry"
|
||||||
score = cDisconnectedScore
|
score = qualityTransitionScore[livekit.ConnectionQuality_DISCONNECTED]
|
||||||
} else {
|
} else {
|
||||||
packetScore := stat.calculatePacketScore(plw, q.params.IncludeRTT, q.params.IncludeJitter)
|
packetScore := stat.calculatePacketScore(plw, q.params.IncludeRTT, q.params.IncludeJitter)
|
||||||
bitrateScore := stat.calculateBitrateScore(expectedBitrate)
|
bitrateScore := stat.calculateBitrateScore(expectedBitrate)
|
||||||
@@ -528,15 +535,15 @@ func scoreToConnectionQuality(score float64) livekit.ConnectionQuality {
|
|||||||
// that a score of 60 does not correspond to `POOR` quality. Repair
|
// that a score of 60 does not correspond to `POOR` quality. Repair
|
||||||
// mechanisms and use of algorithms like de-jittering makes the experience
|
// mechanisms and use of algorithms like de-jittering makes the experience
|
||||||
// better even under harsh conditions.
|
// better even under harsh conditions.
|
||||||
if score > 80.0 {
|
if score > qualityTransitionScore[livekit.ConnectionQuality_GOOD] {
|
||||||
return livekit.ConnectionQuality_EXCELLENT
|
return livekit.ConnectionQuality_EXCELLENT
|
||||||
}
|
}
|
||||||
|
|
||||||
if score > 40.0 {
|
if score > qualityTransitionScore[livekit.ConnectionQuality_POOR] {
|
||||||
return livekit.ConnectionQuality_GOOD
|
return livekit.ConnectionQuality_GOOD
|
||||||
}
|
}
|
||||||
|
|
||||||
if score > 20.0 {
|
if score > qualityTransitionScore[livekit.ConnectionQuality_DISCONNECTED] {
|
||||||
return livekit.ConnectionQuality_POOR
|
return livekit.ConnectionQuality_POOR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user