Protect against looking up dimensions for invalid spatial layer (#977)

Also use loss based scoring when track dimensions are not available.
This commit is contained in:
Raja Subramanian
2022-09-03 00:59:47 +05:30
committed by GitHub
parent f2aee4160e
commit c75f38bce6
2 changed files with 7 additions and 8 deletions
+6 -7
View File
@@ -215,19 +215,18 @@ func (cs *ConnectionStats) updateScore(streams map[uint32]*buffer.StreamStatsWit
// using the current and maximum is a reasonable approximation.
if cs.params.GetCurrentLayerSpatial != nil {
maxAvailableLayer = cs.params.GetCurrentLayerSpatial()
if maxAvailableLayer == buffer.InvalidLayerSpatial {
// retain old score as stats will not be available if not forwarding
return cs.score
}
}
params.Width, params.Height = cs.getLayerDimensions(maxAvailableLayer)
if params.Width == 0 || params.Height == 0 {
cs.params.Logger.Warnw("could not get dimensions", nil, "maxAvailableLayer", maxAvailableLayer)
return cs.score
}
if cs.trackInfo.Source == livekit.TrackSource_SCREEN_SHARE {
if cs.trackInfo.Source == livekit.TrackSource_SCREEN_SHARE || params.Width == 0 || params.Height == 0 {
if cs.params.GetIsReducedQuality != nil {
_, params.IsReducedQuality = cs.params.GetIsReducedQuality()
}
cs.score = ScreenshareTrackScore(params)
cs.score = LossBasedTrackScore(params)
} else {
normFactor := float32(1)
if int(maxAvailableLayer) < len(cs.normFactors) {
+1 -1
View File
@@ -115,7 +115,7 @@ func VideoTrackScore(params TrackScoreParams, normFactor float32) float32 {
// the resolution is high. Till rtcmos model can be adapted to that
// scenario, use loss based scoring.
//
func ScreenshareTrackScore(params TrackScoreParams) float32 {
func LossBasedTrackScore(params TrackScoreParams) float32 {
pctLoss := getLossPercentage(params.PacketsExpected, params.PacketsLost)
// No Loss, excellent
if pctLoss == 0.0 && !params.IsReducedQuality {