* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* Clean up

* Clean up

* Store RTT in stats

* spelling mistake

* Make tests compile

* Fix test compilation error

* fix tests

* clone

* latest protocol
This commit is contained in:
Raja Subramanian
2022-02-08 12:53:14 +05:30
committed by GitHub
parent a6eb4290d3
commit 36289bbca7
23 changed files with 913 additions and 639 deletions
+9 -57
View File
@@ -6,8 +6,6 @@ import (
"sync/atomic"
"time"
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/pion/rtcp"
@@ -36,8 +34,6 @@ type MediaTrack struct {
audioLevelMu sync.RWMutex
audioLevel *AudioLevel
connectionStats *connectionquality.ConnectionStats
done chan struct{}
*MediaTrackReceiver
@@ -97,30 +93,6 @@ func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTra
}
})
t.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
UpdateInterval: connectionQualityUpdateInterval,
CodecType: track.Kind(),
GetTotalBytes: func() uint64 {
receiver := t.Receiver()
if receiver != nil {
return receiver.(*sfu.WebRTCReceiver).GetTotalBytes()
}
return 0
},
GetIsReducedQuality: func() bool {
publishing, expected := t.getNumUpTracks()
return publishing < expected
},
Logger: t.params.Logger,
})
t.connectionStats.OnStatsUpdate(func(_cs *connectionquality.ConnectionStats, stat *livekit.AnalyticsStat) {
t.params.Telemetry.TrackStats(livekit.StreamType_UPSTREAM, t.PublisherID(), t.ID(), stat)
})
t.AddOnClose(func() {
t.connectionStats.Close()
})
return t
}
@@ -147,23 +119,6 @@ func (t *MediaTrack) ToProto() *livekit.TrackInfo {
return info
}
func (t *MediaTrack) getNumUpTracks() (uint32, uint32) {
numExpected := atomic.LoadUint32(&t.numUpTracks)
numSubscribedLayers := t.numSubscribedLayers()
if numSubscribedLayers < numExpected {
numExpected = numSubscribedLayers
}
numPublishing := uint32(0)
receiver := t.Receiver()
if receiver != nil {
numPublishing = uint32(receiver.(*sfu.WebRTCReceiver).NumAvailableSpatialLayers())
}
return numPublishing, numExpected
}
// AddReceiver adds a new RTP receiver to the track
func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote, twcc *twcc.Responder) {
buff, rtcpReader := t.params.BufferFactory.GetBufferPair(uint32(track.SSRC()))
@@ -171,7 +126,6 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
t.params.Logger.Errorw("could not retrieve buffer pair", nil)
return
}
buff.OnFeedback(t.handlePublisherFeedback)
if t.Kind() == livekit.TrackType_AUDIO {
t.audioLevelMu.Lock()
@@ -225,13 +179,14 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
t.MediaTrackReceiver.Close()
t.params.Telemetry.TrackUnpublished(context.Background(), t.PublisherID(), t.ToProto(), uint32(track.SSRC()))
})
wr.OnStatsUpdate(func(_ *sfu.WebRTCReceiver, stat *livekit.AnalyticsStat) {
t.params.Telemetry.TrackStats(livekit.StreamType_UPSTREAM, t.PublisherID(), t.ID(), stat)
})
t.params.Telemetry.TrackPublished(context.Background(), t.PublisherID(), t.ToProto())
t.buffer = buff
t.MediaTrackReceiver.SetupReceiver(wr)
t.connectionStats.Start()
}
t.lock.Unlock()
@@ -272,14 +227,11 @@ func (t *MediaTrack) GetAudioLevel() (level uint8, active bool) {
return t.audioLevel.GetLevel()
}
func (t *MediaTrack) handlePublisherFeedback(packets []rtcp.Packet) {
t.connectionStats.RTCPFeedback(packets, 0)
func (t *MediaTrack) GetConnectionScore() float32 {
receiver := t.Receiver()
if receiver == nil {
return 0.0
}
// also look for sender reports
// feedback for the source RTCP
t.params.RTCPChan <- packets
}
func (t *MediaTrack) GetConnectionScore() float64 {
return t.connectionStats.GetScore()
return receiver.(*sfu.WebRTCReceiver).GetConnectionScore()
}
+1 -1
View File
@@ -291,7 +291,7 @@ func (t *MediaTrackReceiver) GetQualityForDimension(width, height uint32) liveki
return quality
}
// handles max loss for audio packets
// handles max loss for audio streams
func (t *MediaTrackReceiver) handleMaxLossFeedback(_ *sfu.DownTrack, report *rtcp.ReceiverReport) {
t.downFracLostLock.Lock()
for _, rr := range report.Reports {
+3 -3
View File
@@ -762,9 +762,9 @@ func (p *ParticipantImpl) GetConnectionQuality() *livekit.ConnectionQualityInfo
}
p.lock.RUnlock()
avgScore := 5.0
avgScore := float32(5.0)
if numTracks > 0 {
avgScore = totalScore / float64(numTracks)
avgScore = totalScore / float32(numTracks)
}
rating := connectionquality.Score2Rating(avgScore)
@@ -1348,7 +1348,7 @@ func (p *ParticipantImpl) setTrackMuted(trackID livekit.TrackID, muted bool) {
}
}
func (p *ParticipantImpl) getPublisherConnectionQuality() (totalScore float64, numTracks int) {
func (p *ParticipantImpl) getPublisherConnectionQuality() (totalScore float32, numTracks int) {
for _, pt := range p.GetPublishedTracks() {
if pt.IsMuted() {
continue
+5 -5
View File
@@ -244,7 +244,7 @@ func TestMuteSetting(t *testing.T) {
func TestConnectionQuality(t *testing.T) {
// loss based score is currently a publisher method.
videoScore := func(loss float64, numPublishing, numRegistered uint32) float64 {
videoScore := func(loss float32, numPublishing, numRegistered uint32) float32 {
var reducedQuality bool
if numRegistered > 0 && numPublishing != numRegistered {
reducedQuality = true
@@ -252,7 +252,7 @@ func TestConnectionQuality(t *testing.T) {
return connectionquality.VideoConnectionScore(loss, reducedQuality)
}
testPublishedVideoTrack := func(loss float64, numPublishing, numRegistered uint32) *typesfakes.FakeLocalMediaTrack {
testPublishedVideoTrack := func(loss float32, numPublishing, numRegistered uint32) *typesfakes.FakeLocalMediaTrack {
tr := &typesfakes.FakeLocalMediaTrack{}
score := videoScore(loss, numPublishing, numRegistered)
t.Log("video score: ", score)
@@ -263,11 +263,11 @@ func TestConnectionQuality(t *testing.T) {
testPublishedAudioTrack := func(totalPackets, packetsLost uint32) *typesfakes.FakeLocalMediaTrack {
tr := &typesfakes.FakeLocalMediaTrack{}
pctLoss := float64(0.0)
pctLoss := float32(0.0)
if totalPackets > 0 {
pctLoss = (float64(packetsLost) / float64(totalPackets)) * 100.0
pctLoss = (float32(packetsLost) / float32(totalPackets)) * 100.0
}
score := connectionquality.AudioConnectionScore(pctLoss, 0)
score := connectionquality.AudioConnectionScore(pctLoss, 0, 0.0)
t.Log("audio score: ", score)
tr.GetConnectionScoreReturns(score)
return tr
+1 -1
View File
@@ -211,7 +211,7 @@ type LocalMediaTrack interface {
SdpCid() string
GetAudioLevel() (level uint8, active bool)
GetConnectionScore() float64
GetConnectionScore() float32
}
// MediaTrack is the main interface representing a track published to the room
@@ -38,15 +38,15 @@ type FakeLocalMediaTrack struct {
result1 uint8
result2 bool
}
GetConnectionScoreStub func() float64
GetConnectionScoreStub func() float32
getConnectionScoreMutex sync.RWMutex
getConnectionScoreArgsForCall []struct {
}
getConnectionScoreReturns struct {
result1 float64
result1 float32
}
getConnectionScoreReturnsOnCall map[int]struct {
result1 float64
result1 float32
}
GetQualityForDimensionStub func(uint32, uint32) livekit.VideoQuality
getQualityForDimensionMutex sync.RWMutex
@@ -387,7 +387,7 @@ func (fake *FakeLocalMediaTrack) GetAudioLevelReturnsOnCall(i int, result1 uint8
}{result1, result2}
}
func (fake *FakeLocalMediaTrack) GetConnectionScore() float64 {
func (fake *FakeLocalMediaTrack) GetConnectionScore() float32 {
fake.getConnectionScoreMutex.Lock()
ret, specificReturn := fake.getConnectionScoreReturnsOnCall[len(fake.getConnectionScoreArgsForCall)]
fake.getConnectionScoreArgsForCall = append(fake.getConnectionScoreArgsForCall, struct {
@@ -411,32 +411,32 @@ func (fake *FakeLocalMediaTrack) GetConnectionScoreCallCount() int {
return len(fake.getConnectionScoreArgsForCall)
}
func (fake *FakeLocalMediaTrack) GetConnectionScoreCalls(stub func() float64) {
func (fake *FakeLocalMediaTrack) GetConnectionScoreCalls(stub func() float32) {
fake.getConnectionScoreMutex.Lock()
defer fake.getConnectionScoreMutex.Unlock()
fake.GetConnectionScoreStub = stub
}
func (fake *FakeLocalMediaTrack) GetConnectionScoreReturns(result1 float64) {
func (fake *FakeLocalMediaTrack) GetConnectionScoreReturns(result1 float32) {
fake.getConnectionScoreMutex.Lock()
defer fake.getConnectionScoreMutex.Unlock()
fake.GetConnectionScoreStub = nil
fake.getConnectionScoreReturns = struct {
result1 float64
result1 float32
}{result1}
}
func (fake *FakeLocalMediaTrack) GetConnectionScoreReturnsOnCall(i int, result1 float64) {
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 {
result1 float64
result1 float32
})
}
fake.getConnectionScoreReturnsOnCall[i] = struct {
result1 float64
result1 float32
}{result1}
}