Connection quality clean up (#766)
* WIP commit * WIP commit * Remove debug * Revert to reduce diff * Fix tests * Determine spatial layer from track info quality if non-simulcast * Adjust for invalid layer on no rid, previously that function was returning 0 for no rid case * Fall back to top level width/height if there are no layers * Use duration from RTPDeltaInfo
This commit is contained in:
@@ -203,6 +203,10 @@ func (t *MediaTrackReceiver) SetLayerSsrc(mime string, rid string, ssrc uint32)
|
|||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
layer := sfu.RidToLayer(rid)
|
layer := sfu.RidToLayer(rid)
|
||||||
|
if layer == sfu.InvalidLayerSpatial {
|
||||||
|
// non-simulcast case will not have `rid`
|
||||||
|
layer = 0
|
||||||
|
}
|
||||||
for _, receiver := range t.receiversShadow {
|
for _, receiver := range t.receiversShadow {
|
||||||
if strings.EqualFold(receiver.Codec().MimeType, mime) && int(layer) < len(receiver.layerSSRCs) {
|
if strings.EqualFold(receiver.Codec().MimeType, mime) && int(layer) < len(receiver.layerSSRCs) {
|
||||||
receiver.layerSSRCs[layer] = ssrc
|
receiver.layerSSRCs[layer] = ssrc
|
||||||
@@ -671,29 +675,3 @@ func (t *MediaTrackReceiver) OnSubscribedMaxQualityChange(f func(trackID livekit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
func QualityForSpatialLayer(layer int32) livekit.VideoQuality {
|
|
||||||
switch layer {
|
|
||||||
case 0:
|
|
||||||
return livekit.VideoQuality_LOW
|
|
||||||
case 1:
|
|
||||||
return livekit.VideoQuality_MEDIUM
|
|
||||||
case 2:
|
|
||||||
return livekit.VideoQuality_HIGH
|
|
||||||
case sfu.InvalidLayerSpatial:
|
|
||||||
return livekit.VideoQuality_OFF
|
|
||||||
default:
|
|
||||||
return livekit.VideoQuality_OFF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func VideoQualityToRID(q livekit.VideoQuality) string {
|
|
||||||
switch q {
|
|
||||||
case livekit.VideoQuality_HIGH:
|
|
||||||
return sfu.FullResolution
|
|
||||||
case livekit.VideoQuality_MEDIUM:
|
|
||||||
return sfu.HalfResolution
|
|
||||||
default:
|
|
||||||
return sfu.QuarterResolution
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/sfu"
|
"github.com/livekit/livekit-server/pkg/sfu"
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||||
|
"github.com/livekit/livekit-server/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -224,7 +225,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
|||||||
})
|
})
|
||||||
|
|
||||||
downTrack.OnMaxLayerChanged(func(dt *sfu.DownTrack, layer int32) {
|
downTrack.OnMaxLayerChanged(func(dt *sfu.DownTrack, layer int32) {
|
||||||
go t.notifySubscriberMaxQuality(subscriberID, dt.Codec(), QualityForSpatialLayer(layer))
|
go t.notifySubscriberMaxQuality(subscriberID, dt.Codec(), utils.QualityForSpatialLayer(layer))
|
||||||
})
|
})
|
||||||
|
|
||||||
downTrack.OnRttUpdate(func(_ *sfu.DownTrack, rtt uint32) {
|
downTrack.OnRttUpdate(func(_ *sfu.DownTrack, rtt uint32) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/utils"
|
"github.com/livekit/protocol/utils"
|
||||||
@@ -224,27 +223,17 @@ func TestMuteSetting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConnectionQuality(t *testing.T) {
|
func TestConnectionQuality(t *testing.T) {
|
||||||
videoScore := func(totalBytes int64, totalFrames int64, qualityParam *buffer.ConnectionQualityParams,
|
testPublishedVideoTrack := func(params connectionquality.TrackScoreParams) *typesfakes.FakeLocalMediaTrack {
|
||||||
codec string, expectedHeight int32, expectedWidth int32, actualHeight int32, actualWidth int32) float32 {
|
|
||||||
return connectionquality.VideoConnectionScore(1*time.Second, totalBytes, totalFrames, qualityParam, codec,
|
|
||||||
expectedHeight, expectedWidth, actualHeight, actualWidth)
|
|
||||||
}
|
|
||||||
|
|
||||||
testPublishedVideoTrack := func(totalBytes int64, totalFrames int64, qualityParam *buffer.ConnectionQualityParams,
|
|
||||||
codec string, expectedHeight int32, expectedWidth int32, actualHeight int32, actualWidth int32) *typesfakes.FakeLocalMediaTrack {
|
|
||||||
tr := &typesfakes.FakeLocalMediaTrack{}
|
tr := &typesfakes.FakeLocalMediaTrack{}
|
||||||
score := videoScore(totalBytes, totalFrames, qualityParam, codec, expectedHeight, expectedWidth,
|
score := connectionquality.VideoTrackScore(params)
|
||||||
actualHeight, actualWidth)
|
|
||||||
t.Log("video score: ", score)
|
t.Log("video score: ", score)
|
||||||
tr.GetConnectionScoreReturns(score)
|
tr.GetConnectionScoreReturns(score)
|
||||||
return tr
|
return tr
|
||||||
}
|
}
|
||||||
|
|
||||||
testPublishedAudioTrack := func(totalBytes int64, qualityParam *buffer.ConnectionQualityParams,
|
testPublishedAudioTrack := func(params connectionquality.TrackScoreParams) *typesfakes.FakeLocalMediaTrack {
|
||||||
dtxDisabled bool) *typesfakes.FakeLocalMediaTrack {
|
|
||||||
tr := &typesfakes.FakeLocalMediaTrack{}
|
tr := &typesfakes.FakeLocalMediaTrack{}
|
||||||
|
score := connectionquality.AudioTrackScore(params)
|
||||||
score := connectionquality.AudioConnectionScore(1*time.Second, totalBytes, qualityParam, dtxDisabled)
|
|
||||||
t.Log("audio score: ", score)
|
t.Log("audio score: ", score)
|
||||||
tr.GetConnectionScoreReturns(score)
|
tr.GetConnectionScoreReturns(score)
|
||||||
return tr
|
return tr
|
||||||
@@ -257,11 +246,33 @@ func TestConnectionQuality(t *testing.T) {
|
|||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
|
|
||||||
// >2Mbps, 30fps, expected/actual video size = 1280x720
|
// >2Mbps, 30fps, expected/actual video size = 1280x720
|
||||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(290000, 30, &buffer.ConnectionQualityParams{},
|
params := connectionquality.TrackScoreParams{
|
||||||
"", 720, 1280, 720, 1280)
|
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
|
// no packet loss
|
||||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, &buffer.ConnectionQualityParams{}, false)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
@@ -270,11 +281,33 @@ func TestConnectionQuality(t *testing.T) {
|
|||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
|
|
||||||
// 1Mbps, 15fps, expected = 1280x720, actual = 640 x 480
|
// 1Mbps, 15fps, expected = 1280x720, actual = 640 x 480
|
||||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(25000, 15, &buffer.ConnectionQualityParams{},
|
params := connectionquality.TrackScoreParams{
|
||||||
"", 720, 1280, 480, 640)
|
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 10%
|
// packet loss of 5%
|
||||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, &buffer.ConnectionQualityParams{LossPercentage: 5}, false)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
@@ -282,20 +315,51 @@ func TestConnectionQuality(t *testing.T) {
|
|||||||
t.Run("audio smooth publishing", func(t *testing.T) {
|
t.Run("audio smooth publishing", func(t *testing.T) {
|
||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
// no packet loss
|
// no packet loss
|
||||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, &buffer.ConnectionQualityParams{}, false)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("audio reduced publishing", func(t *testing.T) {
|
t.Run("audio reduced publishing", func(t *testing.T) {
|
||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, &buffer.ConnectionQualityParams{LossPercentage: 5}, false)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("audio bad publishing", func(t *testing.T) {
|
t.Run("audio bad publishing", func(t *testing.T) {
|
||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
p.UpTrackManager.publishedTracks["audio"] = testPublishedAudioTrack(1000, &buffer.ConnectionQualityParams{LossPercentage: 20}, false)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_POOR, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
@@ -304,26 +368,64 @@ func TestConnectionQuality(t *testing.T) {
|
|||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
|
|
||||||
// >2Mbps, 30fps, expected/actual video size = 1280x720
|
// >2Mbps, 30fps, expected/actual video size = 1280x720
|
||||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(290000, 30, &buffer.ConnectionQualityParams{},
|
params := connectionquality.TrackScoreParams{
|
||||||
"", 720, 1280, 720, 1280)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_EXCELLENT, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("video reduced publishing", func(t *testing.T) {
|
t.Run("video reduced publishing", func(t *testing.T) {
|
||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
|
|
||||||
// 1Mbps, 15fps, expected = 1280x720, actual = 640 x 480
|
// 1Mbps, 15fps, expected = 1280x720, actual = 640 x 480
|
||||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(100000, 15, &buffer.ConnectionQualityParams{},
|
params := connectionquality.TrackScoreParams{
|
||||||
"", 720, 1280, 480, 640)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_GOOD, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("video poor publishing", func(t *testing.T) {
|
t.Run("video poor publishing", func(t *testing.T) {
|
||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
|
|
||||||
// 20kbps, 8fps, expected = 1280x720, actual = 640 x 480
|
// 20kbps, 8fps, expected = 1280x720, actual = 240x426
|
||||||
p.UpTrackManager.publishedTracks["video"] = testPublishedVideoTrack(2500, 8, &buffer.ConnectionQualityParams{},
|
params := connectionquality.TrackScoreParams{
|
||||||
"", 720, 1280, 426, 240)
|
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())
|
require.Equal(t, livekit.ConnectionQuality_POOR, p.GetConnectionQuality().GetQuality())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -73,10 +73,9 @@ type Buffer struct {
|
|||||||
|
|
||||||
pliThrottle int64
|
pliThrottle int64
|
||||||
|
|
||||||
rtpStats *RTPStats
|
rtpStats *RTPStats
|
||||||
rrSnapshotId uint32
|
rrSnapshotId uint32
|
||||||
connectionQualitySnapshotId uint32
|
deltaStatsSnapshotId uint32
|
||||||
deltaStatsSnapshotId uint32
|
|
||||||
|
|
||||||
lastFractionLostToReport uint8 // Last fraction lost from subscribers, should report to publisher; Audio only
|
lastFractionLostToReport uint8 // Last fraction lost from subscribers, should report to publisher; Audio only
|
||||||
|
|
||||||
@@ -148,7 +147,6 @@ func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapabili
|
|||||||
Logger: b.logger,
|
Logger: b.logger,
|
||||||
})
|
})
|
||||||
b.rrSnapshotId = b.rtpStats.NewSnapshotId()
|
b.rrSnapshotId = b.rtpStats.NewSnapshotId()
|
||||||
b.connectionQualitySnapshotId = b.rtpStats.NewSnapshotId()
|
|
||||||
b.deltaStatsSnapshotId = b.rtpStats.NewSnapshotId()
|
b.deltaStatsSnapshotId = b.rtpStats.NewSnapshotId()
|
||||||
|
|
||||||
b.clockRate = codec.ClockRate
|
b.clockRate = codec.ClockRate
|
||||||
@@ -613,17 +611,6 @@ func (b *Buffer) GetStats() *livekit.RTPStats {
|
|||||||
return b.rtpStats.ToProto()
|
return b.rtpStats.ToProto()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) GetQualityInfo() *RTPSnapshotInfo {
|
|
||||||
b.RLock()
|
|
||||||
defer b.RUnlock()
|
|
||||||
|
|
||||||
if b.rtpStats == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return b.rtpStats.SnapshotInfo(b.connectionQualitySnapshotId)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Buffer) GetDeltaStats() *StreamStatsWithLayers {
|
func (b *Buffer) GetDeltaStats() *StreamStatsWithLayers {
|
||||||
b.RLock()
|
b.RLock()
|
||||||
defer b.RUnlock()
|
defer b.RUnlock()
|
||||||
@@ -637,16 +624,11 @@ func (b *Buffer) GetDeltaStats() *StreamStatsWithLayers {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
layers := make(map[int]LayerStats)
|
|
||||||
layers[0] = LayerStats{
|
|
||||||
Packets: deltaStats.Packets + deltaStats.PacketsDuplicate + deltaStats.PacketsPadding,
|
|
||||||
Bytes: deltaStats.Bytes + deltaStats.BytesDuplicate + deltaStats.BytesPadding,
|
|
||||||
Frames: deltaStats.Frames,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &StreamStatsWithLayers{
|
return &StreamStatsWithLayers{
|
||||||
RTPStats: deltaStats,
|
RTPStats: deltaStats,
|
||||||
Layers: layers,
|
Layers: map[int32]*RTPDeltaInfo{
|
||||||
|
0: deltaStats,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
GapHistogramNumBins = 101
|
GapHistogramNumBins = 101
|
||||||
SequenceNumberMin = uint16(0)
|
|
||||||
SequenceNumberMax = uint16(65535)
|
|
||||||
NumSequenceNumbers = 65536
|
NumSequenceNumbers = 65536
|
||||||
FirstSnapshotId = 1
|
FirstSnapshotId = 1
|
||||||
SnInfoSize = 2048
|
SnInfoSize = 2048
|
||||||
@@ -29,14 +27,8 @@ type RTPFlowState struct {
|
|||||||
LossEndExclusive uint16
|
LossEndExclusive uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
type RTPSnapshotInfo struct {
|
|
||||||
PacketsExpected uint32
|
|
||||||
PacketsLost uint32
|
|
||||||
JitterMax float64
|
|
||||||
RttMax uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type RTPDeltaInfo struct {
|
type RTPDeltaInfo struct {
|
||||||
|
Duration time.Duration
|
||||||
Packets uint32
|
Packets uint32
|
||||||
Bytes uint64
|
Bytes uint64
|
||||||
PacketsDuplicate uint32
|
PacketsDuplicate uint32
|
||||||
@@ -53,6 +45,7 @@ type RTPDeltaInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Snapshot struct {
|
type Snapshot struct {
|
||||||
|
startTime time.Time
|
||||||
extStartSN uint32
|
extStartSN uint32
|
||||||
packetsDuplicate uint32
|
packetsDuplicate uint32
|
||||||
bytesDuplicate uint64
|
bytesDuplicate uint64
|
||||||
@@ -177,7 +170,7 @@ func (r *RTPStats) NewSnapshotId() uint32 {
|
|||||||
|
|
||||||
id := r.nextSnapshotId
|
id := r.nextSnapshotId
|
||||||
if r.initialized {
|
if r.initialized {
|
||||||
r.snapshots[id] = &Snapshot{extStartSN: r.extStartSN}
|
r.snapshots[id] = &Snapshot{startTime: time.Now(), extStartSN: r.extStartSN}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.nextSnapshotId++
|
r.nextSnapshotId++
|
||||||
@@ -613,54 +606,6 @@ func (r *RTPStats) SnapshotRtcpReceptionReport(ssrc uint32, proxyFracLost uint8,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RTPStats) SnapshotInfo(snapshotId uint32) *RTPSnapshotInfo {
|
|
||||||
r.lock.Lock()
|
|
||||||
then, now := r.getAndResetSnapshot(snapshotId)
|
|
||||||
r.lock.Unlock()
|
|
||||||
|
|
||||||
if now == nil || then == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r.lock.RLock()
|
|
||||||
defer r.lock.RUnlock()
|
|
||||||
|
|
||||||
packetsExpected := now.extStartSN - then.extStartSN
|
|
||||||
if packetsExpected > NumSequenceNumbers {
|
|
||||||
r.logger.Warnw(
|
|
||||||
"too many packets expected in snapshot",
|
|
||||||
fmt.Errorf("start: %d, end: %d, expected: %d", then.extStartSN, now.extStartSN, packetsExpected),
|
|
||||||
)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if packetsExpected == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
packetsLost := uint32(0)
|
|
||||||
if r.params.IsReceiverReportDriven {
|
|
||||||
packetsLost = now.packetsLostOverridden - then.packetsLostOverridden
|
|
||||||
if int32(packetsLost) < 0 {
|
|
||||||
packetsLost = 0
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_, _, _, _, packetsLost, _ = r.getIntervalStats(uint16(then.extStartSN), uint16(now.extStartSN))
|
|
||||||
}
|
|
||||||
|
|
||||||
maxJitter := then.maxJitter
|
|
||||||
if r.params.IsReceiverReportDriven {
|
|
||||||
maxJitter = then.maxJitterOverridden
|
|
||||||
}
|
|
||||||
maxJitterTime := maxJitter / float64(r.params.ClockRate) * 1e6
|
|
||||||
|
|
||||||
return &RTPSnapshotInfo{
|
|
||||||
PacketsExpected: packetsExpected,
|
|
||||||
PacketsLost: packetsLost,
|
|
||||||
JitterMax: maxJitterTime,
|
|
||||||
RttMax: then.maxRtt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RTPStats) DeltaInfo(snapshotId uint32) *RTPDeltaInfo {
|
func (r *RTPStats) DeltaInfo(snapshotId uint32) *RTPDeltaInfo {
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
then, now := r.getAndResetSnapshot(snapshotId)
|
then, now := r.getAndResetSnapshot(snapshotId)
|
||||||
@@ -700,6 +645,7 @@ func (r *RTPStats) DeltaInfo(snapshotId uint32) *RTPDeltaInfo {
|
|||||||
maxJitterTime := maxJitter / float64(r.params.ClockRate) * 1e6
|
maxJitterTime := maxJitter / float64(r.params.ClockRate) * 1e6
|
||||||
|
|
||||||
return &RTPDeltaInfo{
|
return &RTPDeltaInfo{
|
||||||
|
Duration: now.startTime.Sub(then.startTime),
|
||||||
Packets: packetsExpected - packetsPadding,
|
Packets: packetsExpected - packetsPadding,
|
||||||
Bytes: bytes,
|
Bytes: bytes,
|
||||||
PacketsDuplicate: now.packetsDuplicate - then.packetsDuplicate,
|
PacketsDuplicate: now.packetsDuplicate - then.packetsDuplicate,
|
||||||
@@ -1068,6 +1014,7 @@ func (r *RTPStats) getAndResetSnapshot(snapshotId uint32) (*Snapshot, *Snapshot)
|
|||||||
|
|
||||||
// snapshot now
|
// snapshot now
|
||||||
r.snapshots[snapshotId] = &Snapshot{
|
r.snapshots[snapshotId] = &Snapshot{
|
||||||
|
startTime: time.Now(),
|
||||||
extStartSN: r.getExtHighestSNAdjusted() + 1,
|
extStartSN: r.getExtHighestSNAdjusted() + 1,
|
||||||
packetsDuplicate: r.packetsDuplicate,
|
packetsDuplicate: r.packetsDuplicate,
|
||||||
bytesDuplicate: r.bytesDuplicate,
|
bytesDuplicate: r.bytesDuplicate,
|
||||||
|
|||||||
@@ -1,18 +1,6 @@
|
|||||||
package buffer
|
package buffer
|
||||||
|
|
||||||
type LayerStats struct {
|
|
||||||
Packets uint32
|
|
||||||
Bytes uint64
|
|
||||||
Frames uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamStatsWithLayers struct {
|
type StreamStatsWithLayers struct {
|
||||||
RTPStats *RTPDeltaInfo
|
RTPStats *RTPDeltaInfo
|
||||||
Layers map[int]LayerStats
|
Layers map[int32]*RTPDeltaInfo
|
||||||
}
|
|
||||||
|
|
||||||
type ConnectionQualityParams struct {
|
|
||||||
LossPercentage float32
|
|
||||||
Jitter float32
|
|
||||||
Rtt uint32
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package connectionquality
|
package connectionquality
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"sort"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,11 +22,9 @@ type ConnectionStatsParams struct {
|
|||||||
UpdateInterval time.Duration
|
UpdateInterval time.Duration
|
||||||
CodecType webrtc.RTPCodecType
|
CodecType webrtc.RTPCodecType
|
||||||
CodecName string
|
CodecName string
|
||||||
DtxDisabled bool
|
DtxDisabled bool // RAJA-TODO - fix this
|
||||||
MimeType string
|
MimeType string
|
||||||
GetDeltaStats func() map[uint32]*buffer.StreamStatsWithLayers
|
GetDeltaStats func() map[uint32]*buffer.StreamStatsWithLayers
|
||||||
GetQualityParams func() *buffer.ConnectionQualityParams
|
|
||||||
GetIsReducedQuality func() bool
|
|
||||||
GetLayerDimension func(int32) (uint32, uint32)
|
GetLayerDimension func(int32) (uint32, uint32)
|
||||||
GetMaxExpectedLayer func() *livekit.VideoLayer
|
GetMaxExpectedLayer func() *livekit.VideoLayer
|
||||||
Logger logger.Logger
|
Logger logger.Logger
|
||||||
@@ -39,8 +35,9 @@ type ConnectionStats struct {
|
|||||||
|
|
||||||
onStatsUpdate func(cs *ConnectionStats, stat *livekit.AnalyticsStat)
|
onStatsUpdate func(cs *ConnectionStats, stat *livekit.AnalyticsStat)
|
||||||
|
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
score float32
|
score float32
|
||||||
|
lastUpdate time.Time
|
||||||
|
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
isClosed atomic.Bool
|
isClosed atomic.Bool
|
||||||
@@ -77,64 +74,65 @@ func (cs *ConnectionStats) GetScore() float32 {
|
|||||||
return cs.score
|
return cs.score
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ConnectionStats) updateScore(streams []*livekit.AnalyticsStream, iteration uint64) float32 {
|
func (cs *ConnectionStats) updateScore(streams map[uint32]*buffer.StreamStatsWithLayers) float32 {
|
||||||
cs.lock.Lock()
|
cs.lock.Lock()
|
||||||
defer cs.lock.Unlock()
|
defer cs.lock.Unlock()
|
||||||
|
|
||||||
// Initial interval will have partial data
|
// Initial interval will have partial data
|
||||||
if iteration < 2 {
|
if cs.lastUpdate.IsZero() {
|
||||||
|
cs.lastUpdate = time.Now()
|
||||||
cs.score = 5
|
cs.score = 5
|
||||||
return cs.score
|
return cs.score
|
||||||
}
|
}
|
||||||
|
|
||||||
s := cs.params.GetQualityParams()
|
cs.lastUpdate = time.Now()
|
||||||
var qualityParam buffer.ConnectionQualityParams
|
// RAJA-TODO - take mute into account
|
||||||
if s == nil {
|
// 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
|
||||||
return cs.score
|
return cs.score
|
||||||
} else {
|
|
||||||
qualityParam = *s
|
|
||||||
if math.IsInf(float64(qualityParam.Jitter), 0) {
|
|
||||||
qualityParam.Jitter = 0
|
|
||||||
}
|
|
||||||
if math.IsInf(float64(qualityParam.LossPercentage), 0) {
|
|
||||||
qualityParam.LossPercentage = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interval := cs.params.UpdateInterval
|
params := TrackScoreParams{
|
||||||
if interval == 0 {
|
Duration: maxAvailableLayerStats.Duration,
|
||||||
interval = UpdateInterval
|
Codec: cs.params.CodecName,
|
||||||
|
PacketsExpected: maxAvailableLayerStats.Packets + maxAvailableLayerStats.PacketsPadding,
|
||||||
|
PacketsLost: maxAvailableLayerStats.PacketsLost,
|
||||||
|
Bytes: maxAvailableLayerStats.Bytes,
|
||||||
|
Frames: maxAvailableLayerStats.Frames,
|
||||||
|
Jitter: maxAvailableLayerStats.JitterMax,
|
||||||
|
Rtt: maxAvailableLayerStats.RttMax,
|
||||||
}
|
}
|
||||||
if cs.params.CodecType == webrtc.RTPCodecTypeAudio {
|
|
||||||
totalBytes, _, _ := cs.getBytesFramesFromStreams(streams)
|
switch cs.params.CodecType {
|
||||||
cs.score = AudioConnectionScore(interval, int64(totalBytes), s, cs.params.DtxDisabled)
|
case webrtc.RTPCodecTypeAudio:
|
||||||
} else {
|
// RAJA-TODO - need to set DTX in params
|
||||||
|
cs.score = AudioTrackScore(params)
|
||||||
|
|
||||||
|
case webrtc.RTPCodecTypeVideo:
|
||||||
// get tracks expected max layer and dimensions
|
// get tracks expected max layer and dimensions
|
||||||
expectedLayer := cs.params.GetMaxExpectedLayer()
|
maxExpectedLayer := cs.params.GetMaxExpectedLayer()
|
||||||
if expectedLayer == nil || utils.SpatialLayerForQuality(expectedLayer.Quality) == buffer.InvalidLayerSpatial {
|
if maxExpectedLayer == nil || utils.SpatialLayerForQuality(maxExpectedLayer.Quality) == buffer.InvalidLayerSpatial {
|
||||||
return cs.score
|
return cs.score
|
||||||
}
|
}
|
||||||
|
|
||||||
// get bytes/frames and max later from actual stream stats
|
if maxAvailableLayerStats != nil {
|
||||||
totalBytes, totalFrames, maxLayer := cs.getBytesFramesFromStreams(streams)
|
params.ActualWidth, params.ActualHeight = cs.params.GetLayerDimension(maxAvailableLayer)
|
||||||
var actualHeight uint32
|
|
||||||
var actualWidth uint32
|
|
||||||
// if data present, but maxLayer == -1 no layer info available, set actual to expected, else fetch
|
|
||||||
if maxLayer == buffer.InvalidLayerSpatial && totalBytes > 0 {
|
|
||||||
actualHeight = expectedLayer.Height
|
|
||||||
actualWidth = expectedLayer.Width
|
|
||||||
} else {
|
|
||||||
actualWidth, actualHeight = cs.params.GetLayerDimension(maxLayer)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.score = VideoConnectionScore(interval, int64(totalBytes), int64(totalFrames), &qualityParam, cs.params.CodecName,
|
params.ExpectedWidth = maxExpectedLayer.Width
|
||||||
int32(expectedLayer.Height), int32(expectedLayer.Width), int32(actualHeight), int32(actualWidth))
|
params.ExpectedHeight = maxExpectedLayer.Height
|
||||||
|
cs.score = VideoTrackScore(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cs.score
|
return cs.score
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ConnectionStats) getStat(iteration uint64) *livekit.AnalyticsStat {
|
func (cs *ConnectionStats) getStat() *livekit.AnalyticsStat {
|
||||||
if cs.params.GetDeltaStats == nil {
|
if cs.params.GetDeltaStats == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -155,14 +153,14 @@ func (cs *ConnectionStats) getStat(iteration uint64) *livekit.AnalyticsStat {
|
|||||||
//
|
//
|
||||||
if cs.params.CodecType == webrtc.RTPCodecTypeVideo && (len(streams) > 1 || len(stream.Layers) > 1) {
|
if cs.params.CodecType == webrtc.RTPCodecTypeVideo && (len(streams) > 1 || len(stream.Layers) > 1) {
|
||||||
for layer, layerStats := range stream.Layers {
|
for layer, layerStats := range stream.Layers {
|
||||||
as.VideoLayers = append(as.VideoLayers, ToAnalyticsVideoLayer(layer, &layerStats))
|
as.VideoLayers = append(as.VideoLayers, ToAnalyticsVideoLayer(layer, layerStats))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
analyticsStreams = append(analyticsStreams, as)
|
analyticsStreams = append(analyticsStreams, as)
|
||||||
}
|
}
|
||||||
|
|
||||||
score := cs.updateScore(analyticsStreams, iteration)
|
score := cs.updateScore(streams)
|
||||||
|
|
||||||
return &livekit.AnalyticsStat{
|
return &livekit.AnalyticsStat{
|
||||||
Score: score,
|
Score: score,
|
||||||
@@ -180,16 +178,13 @@ func (cs *ConnectionStats) updateStatsWorker() {
|
|||||||
tk := time.NewTicker(interval)
|
tk := time.NewTicker(interval)
|
||||||
defer tk.Stop()
|
defer tk.Stop()
|
||||||
|
|
||||||
// Delay sending scores until 2nd cycle, as 1st will be partial.
|
|
||||||
counter := uint64(0)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-cs.done:
|
case <-cs.done:
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-tk.C:
|
case <-tk.C:
|
||||||
stat := cs.getStat(counter)
|
stat := cs.getStat()
|
||||||
if stat == nil {
|
if stat == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -197,9 +192,6 @@ func (cs *ConnectionStats) updateStatsWorker() {
|
|||||||
if cs.onStatsUpdate != nil {
|
if cs.onStatsUpdate != nil {
|
||||||
cs.onStatsUpdate(cs, stat)
|
cs.onStatsUpdate(cs, stat)
|
||||||
}
|
}
|
||||||
|
|
||||||
counter++
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,49 +215,26 @@ func ToAnalyticsStream(ssrc uint32, deltaStats *buffer.RTPDeltaInfo) *livekit.An
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToAnalyticsVideoLayer(layer int, layerStats *buffer.LayerStats) *livekit.AnalyticsVideoLayer {
|
func ToAnalyticsVideoLayer(layer int32, layerStats *buffer.RTPDeltaInfo) *livekit.AnalyticsVideoLayer {
|
||||||
return &livekit.AnalyticsVideoLayer{
|
return &livekit.AnalyticsVideoLayer{
|
||||||
Layer: int32(layer),
|
Layer: layer,
|
||||||
Packets: layerStats.Packets,
|
Packets: layerStats.Packets + layerStats.PacketsDuplicate + layerStats.PacketsPadding,
|
||||||
Bytes: layerStats.Bytes,
|
Bytes: layerStats.Bytes + layerStats.BytesDuplicate + layerStats.BytesPadding,
|
||||||
Frames: layerStats.Frames,
|
Frames: layerStats.Frames,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ConnectionStats) getBytesFramesFromStreams(streams []*livekit.AnalyticsStream) (totalBytes uint64, totalFrames uint32, maxLayer int32) {
|
func (cs *ConnectionStats) getMaxAvailableLayerStats(streams map[uint32]*buffer.StreamStatsWithLayers) (int32, *buffer.RTPDeltaInfo) {
|
||||||
layerStats := make(map[int32]buffer.LayerStats)
|
maxAvailableLayer := buffer.InvalidLayerSpatial
|
||||||
hasLayers := false
|
var maxAvailableLayerStats *buffer.RTPDeltaInfo
|
||||||
maxLayer = buffer.InvalidLayerSpatial
|
|
||||||
for _, stream := range streams {
|
for _, stream := range streams {
|
||||||
// get frames/bytes/packets from video layers if available. Store per layer in layerStats map
|
for layer, layerStats := range stream.Layers {
|
||||||
if len(stream.VideoLayers) > 0 {
|
if int32(layer) > maxAvailableLayer {
|
||||||
hasLayers = true
|
maxAvailableLayer = int32(layer)
|
||||||
|
maxAvailableLayerStats = layerStats
|
||||||
layers := stream.VideoLayers
|
|
||||||
// find max quality 0(LOW), 1(MED), 2(HIGH) . sort on layer.Layer desc
|
|
||||||
sort.Slice(layers, func(i, j int) bool {
|
|
||||||
return layers[i].Layer > layers[j].Layer
|
|
||||||
})
|
|
||||||
|
|
||||||
layerStats[layers[0].Layer] = buffer.LayerStats{
|
|
||||||
Bytes: layers[0].GetBytes(),
|
|
||||||
Frames: layers[0].GetFrames(),
|
|
||||||
}
|
}
|
||||||
if layers[0].Layer > maxLayer {
|
|
||||||
maxLayer = layers[0].Layer
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
totalFrames += stream.GetFrames()
|
|
||||||
totalBytes += stream.GetPrimaryBytes()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hasLayers {
|
|
||||||
if stats, ok := layerStats[maxLayer]; ok {
|
|
||||||
return stats.Bytes, stats.Frames, maxLayer
|
|
||||||
} else {
|
|
||||||
return 0, 0, buffer.InvalidLayerSpatial
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return totalBytes, totalFrames, maxLayer
|
|
||||||
|
|
||||||
|
return maxAvailableLayer, maxAvailableLayerStats
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package connectionquality
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/rtcscore-go/pkg/rtcmos"
|
"github.com/livekit/rtcscore-go/pkg/rtcmos"
|
||||||
)
|
)
|
||||||
@@ -19,30 +18,55 @@ func Score2Rating(score float32) livekit.ConnectionQuality {
|
|||||||
return livekit.ConnectionQuality_POOR
|
return livekit.ConnectionQuality_POOR
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBitRate(interval float64, totalBytes int64) int32 {
|
func getBitRate(interval float64, bytes uint64) int32 {
|
||||||
return int32(float64(totalBytes*8) / interval)
|
return int32(float64(bytes*8) / interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFrameRate(interval float64, totalFrames int64) int32 {
|
func getFrameRate(interval float64, frames uint32) int32 {
|
||||||
return int32(float64(totalFrames) / interval)
|
return int32(float64(frames) / interval)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLossPercentage(expected uint32, lost uint32) float32 {
|
||||||
|
if expected == 0 {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
return float32(lost) * 100.0 / float32(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func int32Ptr(x int32) *int32 {
|
func int32Ptr(x int32) *int32 {
|
||||||
return &x
|
return &x
|
||||||
}
|
}
|
||||||
|
|
||||||
func AudioConnectionScore(interval time.Duration, totalBytes int64,
|
type TrackScoreParams struct {
|
||||||
qualityParam *buffer.ConnectionQualityParams, dtxDisabled bool) float32 {
|
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
|
||||||
|
}
|
||||||
|
|
||||||
stat := rtcmos.Stat{
|
func getRtcMosStat(params TrackScoreParams) rtcmos.Stat {
|
||||||
Bitrate: getBitRate(interval.Seconds(), totalBytes),
|
return rtcmos.Stat{
|
||||||
PacketLoss: qualityParam.LossPercentage,
|
Bitrate: getBitRate(params.Duration.Seconds(), params.Bytes),
|
||||||
RoundTripTime: int32Ptr(int32(qualityParam.Rtt)),
|
PacketLoss: getLossPercentage(params.PacketsExpected, params.PacketsLost),
|
||||||
BufferDelay: int32Ptr(int32(qualityParam.Jitter)),
|
RoundTripTime: int32Ptr(int32(params.Rtt)),
|
||||||
AudioConfig: &rtcmos.AudioConfig{},
|
BufferDelay: int32Ptr(int32(params.Jitter / 1000.0)),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if dtxDisabled {
|
func AudioTrackScore(params TrackScoreParams) float32 {
|
||||||
|
stat := getRtcMosStat(params)
|
||||||
|
stat.AudioConfig = &rtcmos.AudioConfig{}
|
||||||
|
if params.DtxDisabled {
|
||||||
flag := false
|
flag := false
|
||||||
stat.AudioConfig.Dtx = &flag
|
stat.AudioConfig.Dtx = &flag
|
||||||
}
|
}
|
||||||
@@ -54,22 +78,17 @@ func AudioConnectionScore(interval time.Duration, totalBytes int64,
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func VideoConnectionScore(interval time.Duration, totalBytes int64, totalFrames int64, qualityParam *buffer.ConnectionQualityParams,
|
func VideoTrackScore(params TrackScoreParams) float32 {
|
||||||
codec string, expectedHeight int32, expectedWidth int32, actualHeight int32, actualWidth int32) float32 {
|
stat := getRtcMosStat(params)
|
||||||
stat := rtcmos.Stat{
|
stat.VideoConfig = &rtcmos.VideoConfig{
|
||||||
Bitrate: getBitRate(interval.Seconds(), totalBytes),
|
FrameRate: int32Ptr(getFrameRate(params.Duration.Seconds(), params.Frames)),
|
||||||
PacketLoss: qualityParam.LossPercentage,
|
Codec: params.Codec,
|
||||||
RoundTripTime: int32Ptr(int32(qualityParam.Rtt)),
|
ExpectedWidth: int32Ptr(int32(params.ExpectedWidth)),
|
||||||
BufferDelay: int32Ptr(int32(qualityParam.Jitter)),
|
ExpectedHeight: int32Ptr(int32(params.ExpectedHeight)),
|
||||||
VideoConfig: &rtcmos.VideoConfig{
|
Width: int32Ptr(int32(params.ActualWidth)),
|
||||||
FrameRate: int32Ptr(getFrameRate(interval.Seconds(), totalFrames)),
|
Height: int32Ptr(int32(params.ActualHeight)),
|
||||||
Codec: codec,
|
|
||||||
ExpectedHeight: &expectedHeight,
|
|
||||||
ExpectedWidth: &expectedWidth,
|
|
||||||
Height: &actualHeight,
|
|
||||||
Width: &actualWidth,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scores := rtcmos.Score([]rtcmos.Stat{stat})
|
scores := rtcmos.Score([]rtcmos.Stat{stat})
|
||||||
if len(scores) == 1 {
|
if len(scores) == 1 {
|
||||||
return float32(scores[0].VideoScore)
|
return float32(scores[0].VideoScore)
|
||||||
|
|||||||
+15
-41
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||||
dd "github.com/livekit/livekit-server/pkg/sfu/dependencydescriptor"
|
dd "github.com/livekit/livekit-server/pkg/sfu/dependencydescriptor"
|
||||||
|
"github.com/livekit/livekit-server/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackSender defines an interface send media to remote peer
|
// TrackSender defines an interface send media to remote peer
|
||||||
@@ -147,9 +148,8 @@ type DownTrack struct {
|
|||||||
|
|
||||||
blankFramesGeneration atomic.Uint32
|
blankFramesGeneration atomic.Uint32
|
||||||
|
|
||||||
connectionStats *connectionquality.ConnectionStats
|
connectionStats *connectionquality.ConnectionStats
|
||||||
connectionQualitySnapshotId uint32
|
deltaStatsSnapshotId uint32
|
||||||
deltaStatsSnapshotId uint32
|
|
||||||
|
|
||||||
// Debug info
|
// Debug info
|
||||||
pktsDropped atomic.Uint32
|
pktsDropped atomic.Uint32
|
||||||
@@ -222,22 +222,20 @@ func NewDownTrack(
|
|||||||
d.forwarder = NewForwarder(d.kind, d.logger)
|
d.forwarder = NewForwarder(d.kind, d.logger)
|
||||||
|
|
||||||
d.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
d.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
||||||
CodecType: kind,
|
CodecType: kind,
|
||||||
GetDeltaStats: d.getDeltaStats,
|
GetDeltaStats: d.getDeltaStats,
|
||||||
GetQualityParams: d.getQualityParams,
|
GetLayerDimension: func(layer int32) (uint32, uint32) {
|
||||||
GetIsReducedQuality: func() bool {
|
|
||||||
return d.GetForwardingStatus() != ForwardingStatusOptimal
|
|
||||||
},
|
|
||||||
GetLayerDimension: func(quality int32) (uint32, uint32) {
|
|
||||||
if d.receiver != nil {
|
if d.receiver != nil {
|
||||||
return d.receiver.GetLayerDimension(quality)
|
return d.receiver.GetLayerDimension(layer)
|
||||||
}
|
}
|
||||||
return 0, 0
|
return 0, 0
|
||||||
},
|
},
|
||||||
|
// 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 {
|
GetMaxExpectedLayer: func() *livekit.VideoLayer {
|
||||||
quality := d.forwarder.MaxLayers().Spatial
|
maxLayer := d.forwarder.MaxLayers().Spatial
|
||||||
width, height := d.receiver.GetLayerDimension(quality)
|
width, height := d.receiver.GetLayerDimension(maxLayer)
|
||||||
return &livekit.VideoLayer{Quality: livekit.VideoQuality(quality), Width: width, Height: height}
|
return &livekit.VideoLayer{Quality: utils.QualityForSpatialLayer(maxLayer), Width: width, Height: height}
|
||||||
},
|
},
|
||||||
Logger: d.logger,
|
Logger: d.logger,
|
||||||
CodecName: getCodecNameFromMime(codecs[0].MimeType),
|
CodecName: getCodecNameFromMime(codecs[0].MimeType),
|
||||||
@@ -253,7 +251,6 @@ func NewDownTrack(
|
|||||||
IsReceiverReportDriven: true,
|
IsReceiverReportDriven: true,
|
||||||
Logger: d.logger,
|
Logger: d.logger,
|
||||||
})
|
})
|
||||||
d.connectionQualitySnapshotId = d.rtpStats.NewSnapshotId()
|
|
||||||
d.deltaStatsSnapshotId = d.rtpStats.NewSnapshotId()
|
d.deltaStatsSnapshotId = d.rtpStats.NewSnapshotId()
|
||||||
|
|
||||||
return d, nil
|
return d, nil
|
||||||
@@ -1383,24 +1380,6 @@ func (d *DownTrack) GetTrackStats() *livekit.RTPStats {
|
|||||||
return d.rtpStats.ToProto()
|
return d.rtpStats.ToProto()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) getQualityParams() *buffer.ConnectionQualityParams {
|
|
||||||
s := d.rtpStats.SnapshotInfo(d.connectionQualitySnapshotId)
|
|
||||||
if s == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
lossPercentage := float32(0.0)
|
|
||||||
if s.PacketsExpected != 0 {
|
|
||||||
lossPercentage = float32(s.PacketsLost) * 100.0 / float32(s.PacketsExpected)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &buffer.ConnectionQualityParams{
|
|
||||||
LossPercentage: lossPercentage,
|
|
||||||
Jitter: float32(s.JitterMax / 1000.0),
|
|
||||||
Rtt: s.RttMax,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DownTrack) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayers {
|
func (d *DownTrack) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayers {
|
||||||
streamStats := make(map[uint32]*buffer.StreamStatsWithLayers, 1)
|
streamStats := make(map[uint32]*buffer.StreamStatsWithLayers, 1)
|
||||||
|
|
||||||
@@ -1409,16 +1388,11 @@ func (d *DownTrack) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayers {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
layers := make(map[int]buffer.LayerStats)
|
|
||||||
layers[0] = buffer.LayerStats{
|
|
||||||
Packets: deltaStats.Packets + deltaStats.PacketsDuplicate + deltaStats.PacketsPadding,
|
|
||||||
Bytes: deltaStats.Bytes + deltaStats.BytesDuplicate + deltaStats.BytesPadding,
|
|
||||||
Frames: deltaStats.Frames,
|
|
||||||
}
|
|
||||||
|
|
||||||
streamStats[d.ssrc] = &buffer.StreamStatsWithLayers{
|
streamStats[d.ssrc] = &buffer.StreamStatsWithLayers{
|
||||||
RTPStats: deltaStats,
|
RTPStats: deltaStats,
|
||||||
Layers: layers,
|
Layers: map[int32]*buffer.RTPDeltaInfo{
|
||||||
|
0: deltaStats,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return streamStats
|
return streamStats
|
||||||
|
|||||||
+64
-95
@@ -54,7 +54,7 @@ type TrackReceiver interface {
|
|||||||
|
|
||||||
DebugInfo() map[string]interface{}
|
DebugInfo() map[string]interface{}
|
||||||
|
|
||||||
GetLayerDimension(quality int32) (uint32, uint32)
|
GetLayerDimension(layer int32) (uint32, uint32)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebRTCReceiver receives a media track
|
// WebRTCReceiver receives a media track
|
||||||
@@ -64,18 +64,19 @@ type WebRTCReceiver struct {
|
|||||||
pliThrottleConfig config.PLIThrottleConfig
|
pliThrottleConfig config.PLIThrottleConfig
|
||||||
audioConfig config.AudioConfig
|
audioConfig config.AudioConfig
|
||||||
|
|
||||||
trackID livekit.TrackID
|
trackID livekit.TrackID
|
||||||
streamID string
|
streamID string
|
||||||
kind webrtc.RTPCodecType
|
kind webrtc.RTPCodecType
|
||||||
receiver *webrtc.RTPReceiver
|
receiver *webrtc.RTPReceiver
|
||||||
codec webrtc.RTPCodecParameters
|
codec webrtc.RTPCodecParameters
|
||||||
isSimulcast bool
|
isSimulcast bool
|
||||||
isSVC bool
|
isSVC bool
|
||||||
onCloseHandler func()
|
onCloseHandler func()
|
||||||
closeOnce sync.Once
|
closeOnce sync.Once
|
||||||
closed atomic.Bool
|
closed atomic.Bool
|
||||||
useTrackers bool
|
useTrackers bool
|
||||||
TrackInfo *livekit.TrackInfo
|
trackInfo *livekit.TrackInfo
|
||||||
|
maxPublishedLayer int32
|
||||||
|
|
||||||
rtcpCh chan []rtcp.Packet
|
rtcpCh chan []rtcp.Packet
|
||||||
|
|
||||||
@@ -109,8 +110,10 @@ func RidToLayer(rid string) int32 {
|
|||||||
return 2
|
return 2
|
||||||
case HalfResolution:
|
case HalfResolution:
|
||||||
return 1
|
return 1
|
||||||
default:
|
case QuarterResolution:
|
||||||
return 0
|
return 0
|
||||||
|
default:
|
||||||
|
return InvalidLayerSpatial
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,10 +185,19 @@ func NewWebRTCReceiver(
|
|||||||
isSimulcast: len(track.RID()) > 0,
|
isSimulcast: len(track.RID()) > 0,
|
||||||
twcc: twcc,
|
twcc: twcc,
|
||||||
streamTrackerManager: NewStreamTrackerManager(logger, trackInfo.Source),
|
streamTrackerManager: NewStreamTrackerManager(logger, trackInfo.Source),
|
||||||
TrackInfo: trackInfo,
|
trackInfo: trackInfo,
|
||||||
|
maxPublishedLayer: 0,
|
||||||
isSVC: IsSvcCodec(track.Codec().MimeType),
|
isSVC: IsSvcCodec(track.Codec().MimeType),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, layer := range w.trackInfo.Layers {
|
||||||
|
spatialLayer := utils.SpatialLayerForQuality(layer.Quality)
|
||||||
|
if spatialLayer > w.maxPublishedLayer {
|
||||||
|
w.maxPublishedLayer = spatialLayer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.streamTrackerManager.SetMaxExpectedSpatialLayer(w.maxPublishedLayer)
|
||||||
w.streamTrackerManager.OnMaxLayerChanged(w.onMaxLayerChange)
|
w.streamTrackerManager.OnMaxLayerChanged(w.onMaxLayerChange)
|
||||||
w.streamTrackerManager.OnAvailableLayersChanged(w.downTrackLayerChange)
|
w.streamTrackerManager.OnAvailableLayersChanged(w.downTrackLayerChange)
|
||||||
w.streamTrackerManager.OnBitrateAvailabilityChanged(w.downTrackBitrateAvailabilityChange)
|
w.streamTrackerManager.OnBitrateAvailabilityChanged(w.downTrackBitrateAvailabilityChange)
|
||||||
@@ -200,39 +212,24 @@ func NewWebRTCReceiver(
|
|||||||
})
|
})
|
||||||
|
|
||||||
w.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
w.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
||||||
CodecType: w.kind,
|
CodecType: w.kind,
|
||||||
GetDeltaStats: w.getDeltaStats,
|
GetDeltaStats: w.getDeltaStats,
|
||||||
GetQualityParams: w.getQualityParams,
|
GetLayerDimension: func(layer int32) (uint32, uint32) {
|
||||||
GetIsReducedQuality: func() bool {
|
return w.GetLayerDimension(layer)
|
||||||
return w.streamTrackerManager.IsReducedQuality()
|
|
||||||
},
|
|
||||||
GetLayerDimension: func(quality int32) (uint32, uint32) {
|
|
||||||
return w.GetLayerDimension(quality)
|
|
||||||
},
|
},
|
||||||
GetMaxExpectedLayer: func() *livekit.VideoLayer {
|
GetMaxExpectedLayer: func() *livekit.VideoLayer {
|
||||||
var expectedLayer *livekit.VideoLayer
|
|
||||||
var maxPublishedLayer *livekit.VideoLayer
|
|
||||||
// find min of <expected, published> layer
|
// find min of <expected, published> layer
|
||||||
expectedQuality := w.streamTrackerManager.GetMaxExpectedLayer()
|
maxExpectedSpatialLayer := w.streamTrackerManager.GetMaxExpectedSpatialLayer()
|
||||||
maxPublishedQuality := InvalidLayerSpatial
|
if maxExpectedSpatialLayer > w.maxPublishedLayer {
|
||||||
if w.TrackInfo != nil {
|
maxExpectedSpatialLayer = w.maxPublishedLayer
|
||||||
for _, layer := range w.TrackInfo.Layers {
|
}
|
||||||
if layer.Quality == livekit.VideoQuality_OFF {
|
for _, layer := range w.trackInfo.Layers {
|
||||||
continue
|
if maxExpectedSpatialLayer == utils.SpatialLayerForQuality(layer.Quality) {
|
||||||
}
|
return proto.Clone(layer).(*livekit.VideoLayer)
|
||||||
if expectedQuality == utils.SpatialLayerForQuality(layer.Quality) {
|
|
||||||
expectedLayer = proto.Clone(layer).(*livekit.VideoLayer)
|
|
||||||
}
|
|
||||||
if utils.SpatialLayerForQuality(layer.Quality) > maxPublishedQuality {
|
|
||||||
maxPublishedQuality = int32(layer.Quality)
|
|
||||||
maxPublishedLayer = proto.Clone(layer).(*livekit.VideoLayer)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if expectedQuality < maxPublishedQuality {
|
|
||||||
return expectedLayer
|
return nil
|
||||||
}
|
|
||||||
return maxPublishedLayer
|
|
||||||
},
|
},
|
||||||
Logger: w.logger,
|
Logger: w.logger,
|
||||||
CodecName: getCodecNameFromMime(w.codec.MimeType),
|
CodecName: getCodecNameFromMime(w.codec.MimeType),
|
||||||
@@ -247,15 +244,21 @@ func NewWebRTCReceiver(
|
|||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebRTCReceiver) GetLayerDimension(quality int32) (uint32, uint32) {
|
func (w *WebRTCReceiver) GetLayerDimension(layer int32) (uint32, uint32) {
|
||||||
height := uint32(0)
|
height := uint32(0)
|
||||||
width := uint32(0)
|
width := uint32(0)
|
||||||
for _, layer := range w.TrackInfo.Layers {
|
if len(w.trackInfo.Layers) > 0 {
|
||||||
if layer.Quality == livekit.VideoQuality(quality) {
|
quality := utils.QualityForSpatialLayer(layer)
|
||||||
height = layer.Height
|
for _, layer := range w.trackInfo.Layers {
|
||||||
width = layer.Width
|
if layer.Quality == quality {
|
||||||
break
|
height = layer.Height
|
||||||
|
width = layer.Width
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
width = w.trackInfo.Width
|
||||||
|
height = w.trackInfo.Height
|
||||||
}
|
}
|
||||||
return width, height
|
return width, height
|
||||||
}
|
}
|
||||||
@@ -333,6 +336,14 @@ func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buff
|
|||||||
}
|
}
|
||||||
|
|
||||||
layer := RidToLayer(track.RID())
|
layer := RidToLayer(track.RID())
|
||||||
|
if layer == InvalidLayerSpatial {
|
||||||
|
// check if there is only one layer and if so, assign it to that
|
||||||
|
if len(w.trackInfo.Layers) == 1 {
|
||||||
|
layer = utils.SpatialLayerForQuality(w.trackInfo.Layers[0].Quality)
|
||||||
|
} else {
|
||||||
|
layer = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
buff.SetLogger(logger.Logger(logr.Logger(w.logger).WithValues("layer", layer)))
|
buff.SetLogger(logger.Logger(logr.Logger(w.logger).WithValues("layer", layer)))
|
||||||
buff.SetTWCC(w.twcc)
|
buff.SetTWCC(w.twcc)
|
||||||
buff.SetAudioLevelParams(audio.AudioLevelParams{
|
buff.SetAudioLevelParams(audio.AudioLevelParams{
|
||||||
@@ -522,46 +533,6 @@ func (w *WebRTCReceiver) GetAudioLevel() (float64, bool) {
|
|||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebRTCReceiver) getQualityParams() *buffer.ConnectionQualityParams {
|
|
||||||
w.bufferMu.RLock()
|
|
||||||
defer w.bufferMu.RUnlock()
|
|
||||||
|
|
||||||
packetsExpected := uint32(0)
|
|
||||||
packetsLost := uint32(0)
|
|
||||||
maxJitter := 0.0
|
|
||||||
maxRtt := uint32(0)
|
|
||||||
for _, buff := range w.buffers {
|
|
||||||
if buff == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
q := buff.GetQualityInfo()
|
|
||||||
if q == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
packetsExpected += q.PacketsExpected
|
|
||||||
packetsLost += q.PacketsLost
|
|
||||||
if q.JitterMax > maxJitter {
|
|
||||||
maxJitter = q.JitterMax
|
|
||||||
}
|
|
||||||
if q.RttMax > maxRtt {
|
|
||||||
maxRtt = q.RttMax
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lossPercentage := float32(0.0)
|
|
||||||
if packetsExpected != 0 {
|
|
||||||
lossPercentage = float32(packetsLost) * 100.0 / float32(packetsExpected)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &buffer.ConnectionQualityParams{
|
|
||||||
LossPercentage: lossPercentage,
|
|
||||||
Jitter: float32(maxJitter / 1000.0),
|
|
||||||
Rtt: maxRtt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebRTCReceiver) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayers {
|
func (w *WebRTCReceiver) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayers {
|
||||||
w.bufferMu.RLock()
|
w.bufferMu.RLock()
|
||||||
defer w.bufferMu.RUnlock()
|
defer w.bufferMu.RUnlock()
|
||||||
@@ -578,12 +549,10 @@ func (w *WebRTCReceiver) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayer
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// if simulcast, patch buffer stats with correct layer
|
// patch buffer stats with correct layer
|
||||||
if w.isSimulcast {
|
patched := make(map[int32]*buffer.RTPDeltaInfo, 1)
|
||||||
patched := make(map[int]buffer.LayerStats, 1)
|
patched[int32(layer)] = sswl.Layers[0]
|
||||||
patched[layer] = sswl.Layers[0]
|
sswl.Layers = patched
|
||||||
sswl.Layers = patched
|
|
||||||
}
|
|
||||||
|
|
||||||
deltaStats[w.SSRC(layer)] = sswl
|
deltaStats[w.SSRC(layer)] = sswl
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ func (s *StreamTrackerManager) IsReducedQuality() bool {
|
|||||||
return int32(len(s.availableLayers)) < (s.maxExpectedLayer + 1)
|
return int32(len(s.availableLayers)) < (s.maxExpectedLayer + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StreamTrackerManager) GetMaxExpectedLayer() int32 {
|
func (s *StreamTrackerManager) GetMaxExpectedSpatialLayer() int32 {
|
||||||
s.lock.RLock()
|
s.lock.RLock()
|
||||||
defer s.lock.RUnlock()
|
defer s.lock.RUnlock()
|
||||||
return s.maxExpectedLayer
|
return s.maxExpectedLayer
|
||||||
|
|||||||
+16
-1
@@ -1,6 +1,8 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "github.com/livekit/protocol/livekit"
|
import (
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
|
)
|
||||||
|
|
||||||
func SpatialLayerForQuality(quality livekit.VideoQuality) int32 {
|
func SpatialLayerForQuality(quality livekit.VideoQuality) int32 {
|
||||||
switch quality {
|
switch quality {
|
||||||
@@ -16,3 +18,16 @@ func SpatialLayerForQuality(quality livekit.VideoQuality) int32 {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func QualityForSpatialLayer(layer int32) livekit.VideoQuality {
|
||||||
|
switch layer {
|
||||||
|
case 0:
|
||||||
|
return livekit.VideoQuality_LOW
|
||||||
|
case 1:
|
||||||
|
return livekit.VideoQuality_MEDIUM
|
||||||
|
case 2:
|
||||||
|
return livekit.VideoQuality_HIGH
|
||||||
|
default:
|
||||||
|
return livekit.VideoQuality_OFF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user