Use loss based scoring for screen share tracks. (#771)
* Use loss based scoring for screen share tracks. * Remove named TODO markers and file issues
This commit is contained in:
@@ -27,11 +27,13 @@ type ConnectionStatsParams struct {
|
||||
IsDtxDisabled func() bool
|
||||
GetLayerDimension func(int32) (uint32, uint32)
|
||||
GetMaxExpectedLayer func() *livekit.VideoLayer
|
||||
GetIsReducedQuality func() bool
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type ConnectionStats struct {
|
||||
params ConnectionStatsParams
|
||||
params ConnectionStatsParams
|
||||
trackSource livekit.TrackSource
|
||||
|
||||
onStatsUpdate func(cs *ConnectionStats, stat *livekit.AnalyticsStat)
|
||||
|
||||
@@ -45,9 +47,10 @@ type ConnectionStats struct {
|
||||
|
||||
func NewConnectionStats(params ConnectionStatsParams) *ConnectionStats {
|
||||
return &ConnectionStats{
|
||||
params: params,
|
||||
score: 5.0,
|
||||
done: make(chan struct{}),
|
||||
params: params,
|
||||
trackSource: livekit.TrackSource_UNKNOWN,
|
||||
score: 5.0,
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +66,10 @@ func (cs *ConnectionStats) Close() {
|
||||
close(cs.done)
|
||||
}
|
||||
|
||||
func (cs *ConnectionStats) SetTrackSource(trackSource livekit.TrackSource) {
|
||||
cs.trackSource = trackSource
|
||||
}
|
||||
|
||||
func (cs *ConnectionStats) OnStatsUpdate(fn func(cs *ConnectionStats, stat *livekit.AnalyticsStat)) {
|
||||
cs.onStatsUpdate = fn
|
||||
}
|
||||
@@ -86,11 +93,6 @@ func (cs *ConnectionStats) updateScore(streams map[uint32]*buffer.StreamStatsWit
|
||||
}
|
||||
|
||||
cs.lastUpdate = time.Now()
|
||||
// RAJA-TODO - take mute into account
|
||||
// RAJA-TODO - maybe a probation period at the start, coming out of mute?
|
||||
// RAJA-TODO - maybe a probation period when a layer starts/stops?
|
||||
// RAJA-TODO - maybe layer changes should be notified here directly rather than pulling
|
||||
// RAJA-TODO - maybe track info should be set here and this can know max published without having to pull every time
|
||||
maxAvailableLayer, maxAvailableLayerStats := cs.getMaxAvailableLayerStats(streams)
|
||||
if maxAvailableLayerStats == nil {
|
||||
// retain old score as stats will not be available when muted
|
||||
@@ -108,14 +110,19 @@ func (cs *ConnectionStats) updateScore(streams map[uint32]*buffer.StreamStatsWit
|
||||
Rtt: maxAvailableLayerStats.RttMax,
|
||||
}
|
||||
|
||||
switch cs.params.CodecType {
|
||||
case webrtc.RTPCodecTypeAudio:
|
||||
switch {
|
||||
case cs.trackSource == livekit.TrackSource_SCREEN_SHARE:
|
||||
if cs.params.GetIsReducedQuality != nil {
|
||||
params.IsReducedQuality = cs.params.GetIsReducedQuality()
|
||||
}
|
||||
cs.score = ScreenshareTrackScore(params)
|
||||
case cs.params.CodecType == webrtc.RTPCodecTypeAudio:
|
||||
if cs.params.IsDtxDisabled != nil {
|
||||
params.DtxDisabled = cs.params.IsDtxDisabled()
|
||||
}
|
||||
cs.score = AudioTrackScore(params)
|
||||
|
||||
case webrtc.RTPCodecTypeVideo:
|
||||
case cs.params.CodecType == webrtc.RTPCodecTypeVideo:
|
||||
// get tracks expected max layer and dimensions
|
||||
maxExpectedLayer := cs.params.GetMaxExpectedLayer()
|
||||
if maxExpectedLayer == nil || utils.SpatialLayerForQuality(maxExpectedLayer.Quality) == buffer.InvalidLayerSpatial {
|
||||
|
||||
@@ -39,19 +39,20 @@ func int32Ptr(x int32) *int32 {
|
||||
}
|
||||
|
||||
type TrackScoreParams struct {
|
||||
Duration time.Duration
|
||||
Codec string
|
||||
PacketsExpected uint32
|
||||
PacketsLost uint32
|
||||
Bytes uint64
|
||||
Frames uint32
|
||||
Jitter float64
|
||||
Rtt uint32
|
||||
DtxDisabled bool
|
||||
ActualWidth uint32
|
||||
ActualHeight uint32
|
||||
ExpectedWidth uint32
|
||||
ExpectedHeight uint32
|
||||
Duration time.Duration
|
||||
Codec string
|
||||
PacketsExpected uint32
|
||||
PacketsLost uint32
|
||||
Bytes uint64
|
||||
Frames uint32
|
||||
Jitter float64
|
||||
Rtt uint32
|
||||
DtxDisabled bool
|
||||
ActualWidth uint32
|
||||
ActualHeight uint32
|
||||
ExpectedWidth uint32
|
||||
ExpectedHeight uint32
|
||||
IsReducedQuality bool
|
||||
}
|
||||
|
||||
func getRtcMosStat(params TrackScoreParams) rtcmos.Stat {
|
||||
@@ -95,3 +96,27 @@ func VideoTrackScore(params TrackScoreParams) float32 {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
//
|
||||
// rtcmos gives lower score when screen share content is static.
|
||||
// Even though the frame rate is low, the bit rate is also low and
|
||||
// the resolution is high. Till rtcmos model can be adapted to that
|
||||
// scenario, use loss based scoring.
|
||||
//
|
||||
func ScreenshareTrackScore(params TrackScoreParams) float32 {
|
||||
pctLoss := getLossPercentage(params.PacketsExpected, params.PacketsLost)
|
||||
// No Loss, excellent
|
||||
if pctLoss == 0.0 && !params.IsReducedQuality {
|
||||
return 5.0
|
||||
}
|
||||
// default when loss is minimal, but reducedQuality
|
||||
score := float32(3.5)
|
||||
// loss is bad
|
||||
if pctLoss >= 4.0 {
|
||||
score = 2.0
|
||||
} else if pctLoss <= 2.0 && !params.IsReducedQuality {
|
||||
// loss is acceptable and at reduced quality
|
||||
score = 4.5
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user