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:
@@ -239,6 +239,14 @@ func TestConnectionQuality(t *testing.T) {
|
||||
return tr
|
||||
}
|
||||
|
||||
testPublishedScreenshareTrack := func(params connectionquality.TrackScoreParams) *typesfakes.FakeLocalMediaTrack {
|
||||
tr := &typesfakes.FakeLocalMediaTrack{}
|
||||
score := connectionquality.ScreenshareTrackScore(params)
|
||||
t.Log("screen share score: ", score)
|
||||
tr.GetConnectionScoreReturns(score)
|
||||
return tr
|
||||
}
|
||||
|
||||
// TODO: this test is rather limited since we cannot mock DownTrack's Target & Max spatial layers
|
||||
// to improve this after split
|
||||
|
||||
@@ -429,6 +437,71 @@ func TestConnectionQuality(t *testing.T) {
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_POOR, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("screen share no loss, not reduced quality, should be excellent", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// 20kbps, 2fps
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 2500,
|
||||
Frames: 2,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["ss"] = testPublishedScreenshareTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("screen share low loss, not reduced quality, should be excellent", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// 20kbps, 2fps
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 1,
|
||||
Bytes: 2500,
|
||||
Frames: 2,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["ss"] = testPublishedScreenshareTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("screen share high loss, not reduced quality, should be poor", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// 20kbps, 2fps
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 5,
|
||||
Bytes: 2500,
|
||||
Frames: 2,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["ss"] = testPublishedScreenshareTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_POOR, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("screen share no loss, but reduced quality, should be good", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// 20kbps, 2fps
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 2500,
|
||||
Frames: 2,
|
||||
IsReducedQuality: true,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["ss"] = testPublishedScreenshareTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
}
|
||||
|
||||
func TestSubscriberAsPrimary(t *testing.T) {
|
||||
|
||||
@@ -198,3 +198,11 @@ func (d *DumbReceiver) IsDtxDisabled() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *DumbReceiver) TrackSource() livekit.TrackSource {
|
||||
if r, ok := d.receiver.Load().(sfu.TrackReceiver); ok {
|
||||
return r.TrackSource()
|
||||
}
|
||||
|
||||
return livekit.TrackSource_UNKNOWN
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -223,18 +223,20 @@ func NewDownTrack(
|
||||
|
||||
d.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
||||
CodecType: kind,
|
||||
CodecName: getCodecNameFromMime(codecs[0].MimeType), // LK-TODO: have to notify on codec change
|
||||
MimeType: codecs[0].MimeType, // LK-TODO have to notify on codec change
|
||||
GetDeltaStats: d.getDeltaStats,
|
||||
IsDtxDisabled: d.receiver.IsDtxDisabled,
|
||||
GetLayerDimension: d.receiver.GetLayerDimension,
|
||||
// RAJA-TODO: Check muted, test quality when muted
|
||||
// RAJA-TODO: this one needs more work as layers are muxed into one layer, maybe need to maitain RTP stats separately for each layer
|
||||
GetMaxExpectedLayer: func() *livekit.VideoLayer {
|
||||
maxLayer := d.forwarder.MaxLayers().Spatial
|
||||
width, height := d.receiver.GetLayerDimension(maxLayer)
|
||||
return &livekit.VideoLayer{Quality: utils.QualityForSpatialLayer(maxLayer), Width: width, Height: height}
|
||||
},
|
||||
Logger: d.logger,
|
||||
CodecName: getCodecNameFromMime(codecs[0].MimeType),
|
||||
GetIsReducedQuality: func() bool {
|
||||
return d.GetForwardingStatus() != ForwardingStatusOptimal
|
||||
},
|
||||
Logger: d.logger,
|
||||
})
|
||||
d.connectionStats.OnStatsUpdate(func(_cs *connectionquality.ConnectionStats, stat *livekit.AnalyticsStat) {
|
||||
if d.onStatsUpdate != nil {
|
||||
@@ -295,6 +297,7 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
|
||||
}
|
||||
d.bound.Store(true)
|
||||
|
||||
d.connectionStats.SetTrackSource(d.receiver.TrackSource())
|
||||
d.connectionStats.Start()
|
||||
d.logger.Debugw("bound")
|
||||
|
||||
|
||||
+10
-6
@@ -53,6 +53,7 @@ type TrackReceiver interface {
|
||||
|
||||
DebugInfo() map[string]interface{}
|
||||
|
||||
TrackSource() livekit.TrackSource
|
||||
GetLayerDimension(layer int32) (uint32, uint32)
|
||||
IsDtxDisabled() bool
|
||||
}
|
||||
@@ -203,13 +204,16 @@ func NewWebRTCReceiver(
|
||||
|
||||
w.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
||||
CodecType: w.kind,
|
||||
CodecName: getCodecNameFromMime(w.codec.MimeType),
|
||||
MimeType: w.codec.MimeType,
|
||||
GetDeltaStats: w.getDeltaStats,
|
||||
IsDtxDisabled: w.IsDtxDisabled,
|
||||
GetLayerDimension: w.GetLayerDimension,
|
||||
GetMaxExpectedLayer: w.getMaxExpectedLayer,
|
||||
GetMaxExpectedLayer: w.streamTrackerManager.GetMaxExpectedLayer,
|
||||
GetIsReducedQuality: w.streamTrackerManager.IsReducedQuality,
|
||||
Logger: w.logger,
|
||||
CodecName: getCodecNameFromMime(w.codec.MimeType),
|
||||
})
|
||||
w.connectionStats.SetTrackSource(w.trackInfo.Source)
|
||||
w.connectionStats.OnStatsUpdate(func(_cs *connectionquality.ConnectionStats, stat *livekit.AnalyticsStat) {
|
||||
if w.onStatsUpdate != nil {
|
||||
w.onStatsUpdate(w, stat)
|
||||
@@ -220,6 +224,10 @@ func NewWebRTCReceiver(
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) TrackSource() livekit.TrackSource {
|
||||
return w.trackInfo.Source
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) IsDtxDisabled() bool {
|
||||
return w.trackInfo.DisableDtx
|
||||
}
|
||||
@@ -228,10 +236,6 @@ func (w *WebRTCReceiver) GetLayerDimension(layer int32) (uint32, uint32) {
|
||||
return w.streamTrackerManager.GetLayerDimension(layer)
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) getMaxExpectedLayer() *livekit.VideoLayer {
|
||||
return w.streamTrackerManager.GetMaxExpectedLayer()
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) OnStatsUpdate(fn func(w *WebRTCReceiver, stat *livekit.AnalyticsStat)) {
|
||||
w.onStatsUpdate = fn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user