update core to 0.0.5 (#1540)
* update core * sort imports * fix typos * redundant types
This commit is contained in:
@@ -6,13 +6,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/frostbyte73/core"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -227,13 +226,14 @@ func (cs *ConnectionStats) updateStatsWorker() {
|
||||
tk := time.NewTicker(interval)
|
||||
defer tk.Stop()
|
||||
|
||||
done := cs.done.Watch()
|
||||
for {
|
||||
select {
|
||||
case <-cs.done.Watch():
|
||||
case <-done:
|
||||
return
|
||||
|
||||
case <-tk.C:
|
||||
if cs.done.IsClosed() {
|
||||
if cs.done.IsBroken() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -247,13 +247,15 @@ func (cs *ConnectionStats) updateStatsWorker() {
|
||||
// how much weight to give to packet loss rate when calculating score.
|
||||
// It is codec dependent.
|
||||
// For audio:
|
||||
// o Opus without FEC or RED suffers the most through packet loss, hence has the highest weight
|
||||
// o RED with two packet redundancy can absorb two out of every three packets lost, so packet loss is not as detrimental and therefore lower weight
|
||||
//
|
||||
// o Opus without FEC or RED suffers the most through packet loss, hence has the highest weight
|
||||
// o RED with two packet redundancy can absorb two out of every three packets lost, so packet loss is not as detrimental and therefore lower weight
|
||||
//
|
||||
// For video:
|
||||
// o No in-built codec repair available, hence same for all codecs
|
||||
//
|
||||
// o No in-built codec repair available, hence same for all codecs
|
||||
func getPacketLossWeight(mimeType string, isFecEnabled bool) float64 {
|
||||
plw := float64(0.0)
|
||||
var plw float64
|
||||
switch {
|
||||
case strings.EqualFold(mimeType, webrtc.MimeTypeOpus):
|
||||
// 2.5%: fall to GOOD, 7.5%: fall to POOR
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newConnectionStats(mimeType string, isFECEnabled bool, isDependentRTT bool, isDependentJitter bool) *ConnectionStats {
|
||||
@@ -38,7 +39,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
|
||||
// best conditions (no loss, jitter/rtt = 0) - quality should stay EXCELLENT
|
||||
streams := map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -54,7 +55,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// introduce loss and the score should drop - 12% loss for Opus -> POOR
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -73,7 +74,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// bound so that climbing back does not take too long even under excellent conditions.
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -89,7 +90,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// should stay at GOOD if conditions continue to be good
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -105,7 +106,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// should climb up to EXCELLENT if conditions continue to be good
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -121,7 +122,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// introduce loss and the score should drop - 5% loss for Opus -> GOOD
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -138,7 +139,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// should stay at GOOD quality for another iteration even if the conditions improve
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -154,7 +155,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// should climb up to EXCELLENT if conditions continue to be good
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -170,7 +171,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// mute when quality is POOR should return quality to EXCELLENT
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -195,7 +196,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
cs.UpdateMute(false, now.Add(3*time.Second))
|
||||
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -211,7 +212,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// next update with no packets should knock quality down
|
||||
now = now.Add(duration)
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -232,7 +233,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// with lesser number of packet (simulating DTX).
|
||||
// even higher loss (like 10%) should only knock down quality to GOOD, typically would be POOR at that loss rate
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -254,7 +255,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
// RTT and jitter can knock quality down.
|
||||
// at 2% loss, quality should stay at EXCELLENT purely based on loss, but with added RTT/jitter, should drop to GOOD
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -280,7 +281,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
cs.AddBitrateTransition(2_000_000, now.Add(2*time.Second))
|
||||
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -306,7 +307,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
cs.AddBitrateTransition(2_000_000, now.Add(2*time.Second))
|
||||
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -331,7 +332,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
cs.AddBitrateTransition(2_000_000, now.Add(2*time.Second))
|
||||
|
||||
streams = map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -356,9 +357,9 @@ func TestConnectionQuality(t *testing.T) {
|
||||
|
||||
// RTT does not knock quality down because it is dependent and hence not taken into account
|
||||
// at 2% loss, quality should stay at EXCELLENT purely based on loss. With high RTT (700 ms)
|
||||
// quality should drop to GOOD if RTT were taken into consieration
|
||||
// quality should drop to GOOD if RTT were taken into consideration
|
||||
streams := map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -384,9 +385,9 @@ func TestConnectionQuality(t *testing.T) {
|
||||
|
||||
// Jitter does not knock quality down because it is dependent and hence not taken into account
|
||||
// at 2% loss, quality should stay at EXCELLENT purely based on loss. With high jitter (200 ms)
|
||||
// quality should drop to GOOD if jitter were taken into consieration
|
||||
// quality should drop to GOOD if jitter were taken into consideration
|
||||
streams := map[uint32]*buffer.StreamStatsWithLayers{
|
||||
1: &buffer.StreamStatsWithLayers{
|
||||
1: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -548,7 +549,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
|
||||
for _, eq := range tc.expectedQualities {
|
||||
streams := map[uint32]*buffer.StreamStatsWithLayers{
|
||||
123: &buffer.StreamStatsWithLayers{
|
||||
123: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -644,7 +645,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
}
|
||||
|
||||
streams := map[uint32]*buffer.StreamStatsWithLayers{
|
||||
123: &buffer.StreamStatsWithLayers{
|
||||
123: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
@@ -731,7 +732,7 @@ func TestConnectionQuality(t *testing.T) {
|
||||
}
|
||||
|
||||
streams := map[uint32]*buffer.StreamStatsWithLayers{
|
||||
123: &buffer.StreamStatsWithLayers{
|
||||
123: {
|
||||
RTPStats: &buffer.RTPDeltaInfo{
|
||||
StartTime: now,
|
||||
Duration: duration,
|
||||
|
||||
@@ -63,7 +63,7 @@ func (w *windowStat) calculatePacketScore(plw float64, isDependentRTT bool, isDe
|
||||
actualLost = 0
|
||||
}
|
||||
|
||||
lossEffect := float64(0.0)
|
||||
var lossEffect float64
|
||||
if w.packetsExpected > 0 {
|
||||
lossEffect = float64(actualLost) * 100.0 / float64(w.packetsExpected)
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func (w *windowStat) calculateBitrateScore(expectedBitrate int64) float64 {
|
||||
return maxScore
|
||||
}
|
||||
|
||||
score := float64(0.0)
|
||||
var score float64
|
||||
if w.bytes != 0 {
|
||||
// using the ratio of expectedBitrate / actualBitrate
|
||||
// the quality inflection points are approximately
|
||||
@@ -369,7 +369,7 @@ func (q *qualityScorer) getExpectedBitsAndUpdateTransitions(at time.Time) int64
|
||||
}
|
||||
|
||||
var startedAt time.Time
|
||||
totalBits := float64(0.0)
|
||||
var totalBits float64
|
||||
for idx := 0; idx < len(q.bitrateTransitions)-1; idx++ {
|
||||
bt := &q.bitrateTransitions[idx]
|
||||
btNext := &q.bitrateTransitions[idx+1]
|
||||
@@ -391,8 +391,8 @@ func (q *qualityScorer) getExpectedBitsAndUpdateTransitions(at time.Time) int64
|
||||
}
|
||||
totalBits += at.Sub(startedAt).Seconds() * float64(bt.bitrate)
|
||||
|
||||
// set up last bit rate as the startig bit rate for next analysis window
|
||||
q.bitrateTransitions = []bitrateTransition{bitrateTransition{
|
||||
// set up last bit rate as the starting bit rate for next analysis window
|
||||
q.bitrateTransitions = []bitrateTransition{{
|
||||
startedAt: at,
|
||||
bitrate: bt.bitrate,
|
||||
}}
|
||||
@@ -406,7 +406,7 @@ func (q *qualityScorer) getExpectedDistanceAndUpdateTransitions(at time.Time) fl
|
||||
}
|
||||
|
||||
var startedAt time.Time
|
||||
totalDistance := float64(0.0)
|
||||
var totalDistance float64
|
||||
totalDuration := time.Duration(0)
|
||||
for idx := 0; idx < len(q.layerTransitions)-1; idx++ {
|
||||
lt := &q.layerTransitions[idx]
|
||||
@@ -425,7 +425,7 @@ func (q *qualityScorer) getExpectedDistanceAndUpdateTransitions(at time.Time) fl
|
||||
// negative distances are overshoot, that does not compensate for shortfalls, so use optimal, i. e. 0 distance when overshooting
|
||||
dist = 0.0
|
||||
}
|
||||
totalDistance += dur.Seconds() * float64(dist)
|
||||
totalDistance += dur.Seconds() * dist
|
||||
}
|
||||
|
||||
// last transition
|
||||
@@ -442,10 +442,10 @@ func (q *qualityScorer) getExpectedDistanceAndUpdateTransitions(at time.Time) fl
|
||||
if dist < 0.0 {
|
||||
dist = 0.0
|
||||
}
|
||||
totalDistance += dur.Seconds() * float64(dist)
|
||||
totalDistance += dur.Seconds() * dist
|
||||
|
||||
// set up last distance as the startig distance for next analysis window
|
||||
q.layerTransitions = []layerTransition{layerTransition{
|
||||
// set up last distance as the starting distance for next analysis window
|
||||
q.layerTransitions = []layerTransition{{
|
||||
startedAt: at,
|
||||
distance: lt.distance,
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user