Connection quality (#1490)

* Make connection quality not too optimistic.

With score normalization, the quality indicator showed good
under conditions which should have normally showed some badness.

So, a few things in this PR
- Do not normalize scores
- Pick the weakest link as the representative score (moving away from
  averaging)
- For down track direction, when reporting delta stats, take the number
  of packets sent actually. If there are holes in the feed (upstream
  packet loss), down tracks should not be penalised for that loss.

State of things in connection quality feature
- Audio uses rtcscore-go (with a change to accommodate RED codec). This
  follows the E-model.
- Camera uses rtcscore-go. No change here. NOTE: THe rtscore here is
  purely based on bits per pixel per frame (bpf). This has the following
  existing issues (no change, these were already there)
  o Does not take packet loss, jitter, rtt into account
  o Expected frame rate is not available. So, measured frame rate is
    used as expected frame rate also. If expected frame rate were available,
    the score could be reduced for lower frame rates.
- Screen share tracks: No change. This uses the very old simple loss
  based thresholding for scoring. As the bit rate varies a lot based on
  content and rtcscore video algorithm used for camera relies on
  bits per pixel per frame, this could produce a very low value
  (large width/height encoded in a small number of bits because of static content)
  and hence a low score. So, the old loss based thresholding is used.

* clean up

* update rtcscore pointer

* fix tests

* log lines reformat

* WIP commit

* WIP commit

* update mute of receiver

* WIP commit

* WIP commit

* start adding tests

* take min score if quality matches

* start adding bytes based scoring

* clean up

* more clean up

* Use Fuse

* log quality drop

* clean up debug log

* - Use number of windows for wait to make things simpler
- track no layer expected case
- always update transition
- always call updateScore
This commit is contained in:
Raja Subramanian
2023-03-05 12:55:04 +05:30
committed by GitHub
parent e22de045ba
commit 9e327b1f3c
19 changed files with 1216 additions and 940 deletions
+2 -3
View File
@@ -140,9 +140,8 @@ func (d *DynacastManager) getOrCreateDynacastQuality(mime string) *DynacastQuali
}
dq := NewDynacastQuality(DynacastQualityParams{
MimeType: mime,
DynacastPauseDelay: d.params.DynacastPauseDelay,
Logger: d.params.Logger,
MimeType: mime,
Logger: d.params.Logger,
})
dq.OnSubscribedMaxQualityChange(func(maxQuality livekit.VideoQuality) {
d.updateMaxQualityForMime(mime, maxQuality)
+2 -3
View File
@@ -13,9 +13,8 @@ const (
)
type DynacastQualityParams struct {
MimeType string
DynacastPauseDelay time.Duration
Logger logger.Logger
MimeType string
Logger logger.Logger
}
// DynacastQuality manages max subscribed quality of a single receiver of a media track
+5 -3
View File
@@ -18,6 +18,7 @@ import (
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/sfu"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
"github.com/livekit/livekit-server/pkg/telemetry"
)
@@ -312,12 +313,13 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
return newCodec
}
func (t *MediaTrack) GetConnectionScore() float32 {
func (t *MediaTrack) GetConnectionScoreAndQuality() (float32, livekit.ConnectionQuality) {
receiver := t.PrimaryReceiver()
if rtcReceiver, ok := receiver.(*sfu.WebRTCReceiver); ok {
return rtcReceiver.GetConnectionScore()
return rtcReceiver.GetConnectionScoreAndQuality()
}
return 0.0
return connectionquality.MaxMOS, livekit.ConnectionQuality_EXCELLENT
}
func (t *MediaTrack) SetRTT(rtt uint32) {
+27 -31
View File
@@ -23,7 +23,6 @@ import (
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/sfu"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
"github.com/livekit/livekit-server/pkg/telemetry"
"github.com/livekit/mediatransportutil/pkg/twcc"
"github.com/livekit/protocol/auth"
@@ -818,35 +817,45 @@ func (p *ParticipantImpl) GetAudioLevel() (level float64, active bool) {
}
func (p *ParticipantImpl) GetConnectionQuality() *livekit.ConnectionQualityInfo {
publisherScores := p.getPublisherConnectionQuality()
numTracks := 0
minQuality := livekit.ConnectionQuality_EXCELLENT
minScore := float32(0.0)
numTracks := len(publisherScores)
totalScore := float32(0.0)
for _, score := range publisherScores {
totalScore += score
for _, pt := range p.GetPublishedTracks() {
numTracks++
score, quality := pt.(types.LocalMediaTrack).GetConnectionScoreAndQuality()
if quality < minQuality {
// WARNING NOTE: comparing protobuf enums directly
minQuality = quality
minScore = score
} else if quality == minQuality && score < minScore {
minScore = score
}
}
subscribedTracks := p.SubscriptionManager.GetSubscribedTracks()
subscriberScores := make(map[livekit.TrackID]float32, len(subscribedTracks))
for _, subTrack := range subscribedTracks {
if subTrack.IsMuted() || subTrack.MediaTrack().IsMuted() {
continue
}
score := subTrack.DownTrack().GetConnectionScore()
subscriberScores[subTrack.ID()] = score
totalScore += score
numTracks++
score, quality := subTrack.DownTrack().GetConnectionScoreAndQuality()
if quality < minQuality {
// WARNING NOTE: comparing protobuf enums directly
minQuality = quality
minScore = score
} else if quality == minQuality && score < minScore {
minScore = score
}
}
avgScore := float32(5.0)
if numTracks > 0 {
avgScore = totalScore / float32(numTracks)
if numTracks == 0 {
return nil
}
return &livekit.ConnectionQualityInfo{
ParticipantSid: string(p.ID()),
Quality: connectionquality.Score2Rating(avgScore),
Score: avgScore,
Quality: minQuality,
Score: minScore,
}
}
@@ -1526,19 +1535,6 @@ func (p *ParticipantImpl) setTrackMuted(trackID livekit.TrackID, muted bool) {
}
}
func (p *ParticipantImpl) getPublisherConnectionQuality() map[livekit.TrackID]float32 {
publishedTracks := p.GetPublishedTracks()
scores := make(map[livekit.TrackID]float32, len(publishedTracks))
for _, pt := range publishedTracks {
if pt.IsMuted() {
continue
}
scores[pt.ID()] = pt.(types.LocalMediaTrack).GetConnectionScore()
}
return scores
}
func (p *ParticipantImpl) mediaTrackReceived(track *webrtc.TrackRemote, rtpReceiver *webrtc.RTPReceiver) (*MediaTrack, bool) {
p.pendingTracksLock.Lock()
newTrack := false
+5 -3
View File
@@ -308,9 +308,11 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
}, false)
}
update := &livekit.ConnectionQualityUpdate{}
update.Updates = append(update.Updates, pub.GetConnectionQuality())
_ = participant.SendConnectionQualityUpdate(update)
if cq := pub.GetConnectionQuality(); cq != nil {
update := &livekit.ConnectionQualityUpdate{}
update.Updates = append(update.Updates, cq)
_ = participant.SendConnectionQualityUpdate(update)
}
}
} else {
// no longer subscribed to the publisher, clear speaker status
+1 -1
View File
@@ -405,7 +405,7 @@ type LocalMediaTrack interface {
HasSdpCid(cid string) bool
GetAudioLevel() (level float64, active bool)
GetConnectionScore() float32
GetConnectionScoreAndQuality() (float32, livekit.ConnectionQuality)
SetRTT(rtt uint32)
@@ -60,15 +60,17 @@ type FakeLocalMediaTrack struct {
result1 float64
result2 bool
}
GetConnectionScoreStub func() float32
getConnectionScoreMutex sync.RWMutex
getConnectionScoreArgsForCall []struct {
GetConnectionScoreAndQualityStub func() (float32, livekit.ConnectionQuality)
getConnectionScoreAndQualityMutex sync.RWMutex
getConnectionScoreAndQualityArgsForCall []struct {
}
getConnectionScoreReturns struct {
getConnectionScoreAndQualityReturns struct {
result1 float32
result2 livekit.ConnectionQuality
}
getConnectionScoreReturnsOnCall map[int]struct {
getConnectionScoreAndQualityReturnsOnCall map[int]struct {
result1 float32
result2 livekit.ConnectionQuality
}
GetNumSubscribersStub func() int
getNumSubscribersMutex sync.RWMutex
@@ -578,57 +580,60 @@ func (fake *FakeLocalMediaTrack) GetAudioLevelReturnsOnCall(i int, result1 float
}{result1, result2}
}
func (fake *FakeLocalMediaTrack) GetConnectionScore() float32 {
fake.getConnectionScoreMutex.Lock()
ret, specificReturn := fake.getConnectionScoreReturnsOnCall[len(fake.getConnectionScoreArgsForCall)]
fake.getConnectionScoreArgsForCall = append(fake.getConnectionScoreArgsForCall, struct {
func (fake *FakeLocalMediaTrack) GetConnectionScoreAndQuality() (float32, livekit.ConnectionQuality) {
fake.getConnectionScoreAndQualityMutex.Lock()
ret, specificReturn := fake.getConnectionScoreAndQualityReturnsOnCall[len(fake.getConnectionScoreAndQualityArgsForCall)]
fake.getConnectionScoreAndQualityArgsForCall = append(fake.getConnectionScoreAndQualityArgsForCall, struct {
}{})
stub := fake.GetConnectionScoreStub
fakeReturns := fake.getConnectionScoreReturns
fake.recordInvocation("GetConnectionScore", []interface{}{})
fake.getConnectionScoreMutex.Unlock()
stub := fake.GetConnectionScoreAndQualityStub
fakeReturns := fake.getConnectionScoreAndQualityReturns
fake.recordInvocation("GetConnectionScoreAndQuality", []interface{}{})
fake.getConnectionScoreAndQualityMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
return ret.result1, ret.result2
}
return fakeReturns.result1
return fakeReturns.result1, fakeReturns.result2
}
func (fake *FakeLocalMediaTrack) GetConnectionScoreCallCount() int {
fake.getConnectionScoreMutex.RLock()
defer fake.getConnectionScoreMutex.RUnlock()
return len(fake.getConnectionScoreArgsForCall)
func (fake *FakeLocalMediaTrack) GetConnectionScoreAndQualityCallCount() int {
fake.getConnectionScoreAndQualityMutex.RLock()
defer fake.getConnectionScoreAndQualityMutex.RUnlock()
return len(fake.getConnectionScoreAndQualityArgsForCall)
}
func (fake *FakeLocalMediaTrack) GetConnectionScoreCalls(stub func() float32) {
fake.getConnectionScoreMutex.Lock()
defer fake.getConnectionScoreMutex.Unlock()
fake.GetConnectionScoreStub = stub
func (fake *FakeLocalMediaTrack) GetConnectionScoreAndQualityCalls(stub func() (float32, livekit.ConnectionQuality)) {
fake.getConnectionScoreAndQualityMutex.Lock()
defer fake.getConnectionScoreAndQualityMutex.Unlock()
fake.GetConnectionScoreAndQualityStub = stub
}
func (fake *FakeLocalMediaTrack) GetConnectionScoreReturns(result1 float32) {
fake.getConnectionScoreMutex.Lock()
defer fake.getConnectionScoreMutex.Unlock()
fake.GetConnectionScoreStub = nil
fake.getConnectionScoreReturns = struct {
func (fake *FakeLocalMediaTrack) GetConnectionScoreAndQualityReturns(result1 float32, result2 livekit.ConnectionQuality) {
fake.getConnectionScoreAndQualityMutex.Lock()
defer fake.getConnectionScoreAndQualityMutex.Unlock()
fake.GetConnectionScoreAndQualityStub = nil
fake.getConnectionScoreAndQualityReturns = struct {
result1 float32
}{result1}
result2 livekit.ConnectionQuality
}{result1, result2}
}
func (fake *FakeLocalMediaTrack) GetConnectionScoreReturnsOnCall(i int, result1 float32) {
fake.getConnectionScoreMutex.Lock()
defer fake.getConnectionScoreMutex.Unlock()
fake.GetConnectionScoreStub = nil
if fake.getConnectionScoreReturnsOnCall == nil {
fake.getConnectionScoreReturnsOnCall = make(map[int]struct {
func (fake *FakeLocalMediaTrack) GetConnectionScoreAndQualityReturnsOnCall(i int, result1 float32, result2 livekit.ConnectionQuality) {
fake.getConnectionScoreAndQualityMutex.Lock()
defer fake.getConnectionScoreAndQualityMutex.Unlock()
fake.GetConnectionScoreAndQualityStub = nil
if fake.getConnectionScoreAndQualityReturnsOnCall == nil {
fake.getConnectionScoreAndQualityReturnsOnCall = make(map[int]struct {
result1 float32
result2 livekit.ConnectionQuality
})
}
fake.getConnectionScoreReturnsOnCall[i] = struct {
fake.getConnectionScoreAndQualityReturnsOnCall[i] = struct {
result1 float32
}{result1}
result2 livekit.ConnectionQuality
}{result1, result2}
}
func (fake *FakeLocalMediaTrack) GetNumSubscribers() int {
@@ -1930,8 +1935,8 @@ func (fake *FakeLocalMediaTrack) Invocations() map[string][][]interface{} {
defer fake.getAllSubscribersMutex.RUnlock()
fake.getAudioLevelMutex.RLock()
defer fake.getAudioLevelMutex.RUnlock()
fake.getConnectionScoreMutex.RLock()
defer fake.getConnectionScoreMutex.RUnlock()
fake.getConnectionScoreAndQualityMutex.RLock()
defer fake.getConnectionScoreAndQualityMutex.RUnlock()
fake.getNumSubscribersMutex.RLock()
defer fake.getNumSubscribersMutex.RUnlock()
fake.getQualityForDimensionMutex.RLock()
-7
View File
@@ -259,13 +259,6 @@ func (d *DummyReceiver) DebugInfo() map[string]interface{} {
return nil
}
func (d *DummyReceiver) GetLayerDimension(quality int32) (uint32, uint32) {
if r, ok := d.receiver.Load().(sfu.TrackReceiver); ok {
return r.GetLayerDimension(quality)
}
return 0, 0
}
func (d *DummyReceiver) GetTemporalLayerFpsForSpatial(spatial int32) []float32 {
if r, ok := d.receiver.Load().(sfu.TrackReceiver); ok {
return r.GetTemporalLayerFpsForSpatial(spatial)