Push track quality to poor on a bandwidth constrained pause. (#1867)

* Push track quality to poor on a bandwidth constrained pause.

* add tests

* scale distance by divisor

* fix test distance to desired

* wait longer for subscription manager to reconcile
This commit is contained in:
Raja Subramanian
2023-07-11 15:29:35 +05:30
committed by GitHub
parent 9abc580e8b
commit 5459bd2931
7 changed files with 118 additions and 40 deletions
+48 -18
View File
@@ -162,6 +162,9 @@ type qualityScorer struct {
layerMutedAt time.Time
layerUnmutedAt time.Time
pausedAt time.Time
resumedAt time.Time
maxPPS float64
aggregateBitrate *utils.TimedAggregator[int64]
@@ -224,17 +227,6 @@ func (q *qualityScorer) UpdateMute(isMuted bool) {
func (q *qualityScorer) addBitrateTransitionAtLocked(bitrate int64, at time.Time) {
q.aggregateBitrate.AddSampleAt(bitrate, at)
if bitrate == 0 {
if !q.isLayerMuted() {
q.layerMutedAt = at
q.score = maxScore
}
} else {
if q.isLayerMuted() {
q.layerUnmutedAt = at
}
}
}
func (q *qualityScorer) AddBitrateTransitionAt(bitrate int64, at time.Time) {
@@ -254,8 +246,9 @@ func (q *qualityScorer) AddBitrateTransition(bitrate int64) {
func (q *qualityScorer) updateLayerMuteAtLocked(isMuted bool, at time.Time) {
if isMuted {
if !q.isLayerMuted() {
q.aggregateBitrate.AddSampleAt(0, at)
q.layerDistance.AddSampleAt(0, at)
q.aggregateBitrate.Reset()
q.layerDistance.Reset()
q.layerMutedAt = at
q.score = maxScore
}
@@ -280,6 +273,36 @@ func (q *qualityScorer) UpdateLayerMute(isMuted bool) {
q.updateLayerMuteAtLocked(isMuted, time.Now())
}
func (q *qualityScorer) updatePauseAtLocked(isPaused bool, at time.Time) {
if isPaused {
if !q.isPaused() {
q.aggregateBitrate.Reset()
q.layerDistance.Reset()
q.pausedAt = at
q.score = poorScore
}
} else {
if q.isPaused() {
q.resumedAt = at
}
}
}
func (q *qualityScorer) UpdatePauseAt(isPaused bool, at time.Time) {
q.lock.Lock()
defer q.lock.Unlock()
q.updatePauseAtLocked(isPaused, at)
}
func (q *qualityScorer) UpdatePause(isPaused bool) {
q.lock.Lock()
defer q.lock.Unlock()
q.updatePauseAtLocked(isPaused, time.Now())
}
func (q *qualityScorer) addLayerTransitionAtLocked(distance float64, at time.Time) {
q.layerDistance.AddSampleAt(distance, at)
}
@@ -311,11 +334,14 @@ func (q *qualityScorer) updateAtLocked(stat *windowStat, at time.Time) {
// nothing to do when muted or not unmuted for long enough
// NOTE: it is possible that unmute -> mute -> unmute transition happens in the
// same analysis window. On a transition to mute, state immediately moves
// to stable and quality EXCELLENT for responsiveness. On an unmute, the
// entire window data is considered (as long as enough time has passed since
// unmute) including the data before mute.
if q.isMuted() || !q.isUnmutedEnough(at) || q.isLayerMuted() {
// same analysis window. On a transition to mute, quality is immediately moved
// EXCELLENT for responsiveness. On an unmute, the entire window data is
// considered (as long as enough time has passed since unmute).
//
// Similarly, when paused (possibly due to congestion), score is immediately
// set to poorScore for responsiveness. The layer transision is reest.
// On a resume, quality climbs back up using normal operation.
if q.isMuted() || !q.isUnmutedEnough(at) || q.isLayerMuted() || q.isPaused() {
q.lastUpdateAt = at
return
}
@@ -430,6 +456,10 @@ func (q *qualityScorer) isLayerMuted() bool {
return !q.layerMutedAt.IsZero() && (q.layerUnmutedAt.IsZero() || q.layerMutedAt.After(q.layerUnmutedAt))
}
func (q *qualityScorer) isPaused() bool {
return !q.pausedAt.IsZero() && (q.resumedAt.IsZero() || q.pausedAt.After(q.resumedAt))
}
func (q *qualityScorer) getPacketLossWeight(stat *windowStat) float64 {
if stat == nil || stat.duration == 0 {
return q.params.PacketLossWeight