Connection quality changes (#913)
* WIP commit
* Connection quality changes
- Fix Firefox showing poor quality
o The issue was that we were using max available layer and
calculating quality. The rationale being that even if
server sends dynacast messages, client may not implement
dynacast and still stream all layers. But, with Firefox
(maybe a Firefox bug), it sends some small amount of
data on layer 2 even when that layer is disabled.
Guessing it is probing (or actually we might be using
some small value for high layers as Firefox cannot turn off
layers). That higher layer gets used in quality calculation.
As the bit rate on that layer is extremely low, it yields low
score.
Fixed by considering the max expected layer. That is of most
interest. Yes, clients may ignore dynacast and stream all layers,
but, max expected is the one of interest. So, look for
quality in the max expected layer and not max available layer.
- Lots of clean up around connection quality stuff
o Use a dynamic scaling thing to ensure that we do not get bitten
by absolute values. Calculate best possible scenario score and
map that to maximum MOS score. This will ensure that different
codecs, different settings do not mess up the scoring. For example,
a client might use 1 Mbps for 720p, but a different client could
use 2 Mbps for 720p. As an SFU/infrastructure middlebox, we do
not have control over quality at those rates. We can only ensure
that streaming happens smoothly at those rates. So, in that
example, for client 1, 1 Mbps will map to MOS 5.0 and for client 2,
2 Mbps will map to MOS 5.0. Any impairments after that will
reflect in the score.
o Penalise for missing target layer by one level for one layer missed.
o Move tests to connection quality directory. The participant test
was not super useful.
* Add missed file
* Remove debug code
* use more constants and initialise normalisation factor
* rtcscore pointer
This commit is contained in:
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/routing/routingfakes"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||
"github.com/livekit/livekit-server/pkg/testutils"
|
||||
)
|
||||
|
||||
@@ -253,288 +252,6 @@ func TestMuteSetting(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectionQuality(t *testing.T) {
|
||||
testPublishedVideoTrack := func(params connectionquality.TrackScoreParams) *typesfakes.FakeLocalMediaTrack {
|
||||
tr := &typesfakes.FakeLocalMediaTrack{}
|
||||
score := connectionquality.VideoTrackScore(params)
|
||||
t.Log("video score: ", score)
|
||||
tr.GetConnectionScoreReturns(score)
|
||||
return tr
|
||||
}
|
||||
|
||||
testPublishedAudioTrack := func(params connectionquality.TrackScoreParams) *typesfakes.FakeLocalMediaTrack {
|
||||
tr := &typesfakes.FakeLocalMediaTrack{}
|
||||
score := connectionquality.AudioTrackScore(params)
|
||||
t.Log("audio score: ", score)
|
||||
tr.GetConnectionScoreReturns(score)
|
||||
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
|
||||
|
||||
t.Run("smooth sailing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// >2Mbps, 30fps, expected/actual video size = 1280x720
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 290000,
|
||||
Frames: 30,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
ExpectedWidth: 1280,
|
||||
ExpectedHeight: 720,
|
||||
ActualWidth: 1280,
|
||||
ActualHeight: 720,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(params)
|
||||
|
||||
// no packet loss
|
||||
params = connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
Codec: "opus",
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 1000,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
DtxDisabled: false,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("reduced publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// 1Mbps, 15fps, expected = 1280x720, actual = 640 x 480
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 125000,
|
||||
Frames: 15,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
ExpectedWidth: 1280,
|
||||
ExpectedHeight: 720,
|
||||
ActualWidth: 640,
|
||||
ActualHeight: 480,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(params)
|
||||
|
||||
// packet loss of 5%
|
||||
params = connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
Codec: "opus",
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 5,
|
||||
Bytes: 1000,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
DtxDisabled: false,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("audio smooth publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
// no packet loss
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
Codec: "opus",
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 1000,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
DtxDisabled: false,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("audio reduced publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
Codec: "opus",
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 5,
|
||||
Bytes: 1000,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
DtxDisabled: false,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("audio bad publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
Codec: "opus",
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 20,
|
||||
Bytes: 1000,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
DtxDisabled: false,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_POOR, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("video smooth publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// >2Mbps, 30fps, expected/actual video size = 1280x720
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 290000,
|
||||
Frames: 30,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
ExpectedWidth: 1280,
|
||||
ExpectedHeight: 720,
|
||||
ActualWidth: 1280,
|
||||
ActualHeight: 720,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("video reduced publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// 1Mbps, 15fps, expected = 1280x720, actual = 640 x 480
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 125000,
|
||||
Frames: 15,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
ExpectedWidth: 1280,
|
||||
ExpectedHeight: 720,
|
||||
ActualWidth: 640,
|
||||
ActualHeight: 480,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(params)
|
||||
|
||||
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||
})
|
||||
|
||||
t.Run("video poor publishing", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
|
||||
// 20kbps, 8fps, expected = 1280x720, actual = 240x426
|
||||
params := connectionquality.TrackScoreParams{
|
||||
Duration: 1 * time.Second,
|
||||
PacketsExpected: 100,
|
||||
PacketsLost: 0,
|
||||
Bytes: 2500,
|
||||
Frames: 8,
|
||||
Jitter: 0.0,
|
||||
Rtt: 0,
|
||||
ExpectedWidth: 1280,
|
||||
ExpectedHeight: 720,
|
||||
ActualWidth: 240,
|
||||
ActualHeight: 426,
|
||||
}
|
||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(params)
|
||||
|
||||
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) {
|
||||
t.Run("protocol 4 uses subs as primary", func(t *testing.T) {
|
||||
p := newParticipantForTestWithOpts("test", &participantOpts{
|
||||
|
||||
@@ -221,17 +221,9 @@ func (d *DummyReceiver) GetLayerDimension(quality int32) (uint32, uint32) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
func (d *DummyReceiver) IsDtxDisabled() bool {
|
||||
func (d *DummyReceiver) TrackInfo() *livekit.TrackInfo {
|
||||
if r, ok := d.receiver.Load().(sfu.TrackReceiver); ok {
|
||||
return r.IsDtxDisabled()
|
||||
return r.TrackInfo()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *DummyReceiver) TrackSource() livekit.TrackSource {
|
||||
if r, ok := d.receiver.Load().(sfu.TrackReceiver); ok {
|
||||
return r.TrackSource()
|
||||
}
|
||||
|
||||
return livekit.TrackSource_UNKNOWN
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user