Code cleanup (#353)

This commit is contained in:
David Colburn
2022-01-19 02:13:06 -08:00
committed by GitHub
parent 6400de1c10
commit 5bea9debb7
35 changed files with 223 additions and 218 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ type Buffer struct {
latestTimestamp uint32 // latest received RTP timestamp on packet
latestTimestampTime int64 // Time of the latest timestamp (in nanos since unix epoch)
lastFractionLostToReport uint8 // Last fractionlost from subscribers, should report to publisher; Audio only
lastFractionLostToReport uint8 // Last fraction lost from subscribers, should report to publisher; Audio only
// callbacks
onClose func()
+1 -1
View File
@@ -40,7 +40,7 @@ func mosAudioEmodel(cur, prev *ConnectionStat) float64 {
rx := 93.2 - percentageLost
ry := 0.18*rx*rx - 27.9*rx + 1126.62
//Jitter is in MicroSecs (1/1e6) units. Convert it to MilliSecs
// Jitter is in MicroSecs (1/1e6) units. Convert it to MilliSecs
d := float64(rtt + (cur.Jitter / 1000))
h := d - 177.3
if h < 0 {
+4 -5
View File
@@ -10,9 +10,7 @@ import (
"sync/atomic"
"time"
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
"github.com/livekit/protocol/livekit"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/sdp/v3"
@@ -20,6 +18,7 @@ import (
"github.com/pion/webrtc/v3"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
)
const (
@@ -28,7 +27,7 @@ const (
// TrackSender defines an interface send media to remote peer
type TrackSender interface {
UptrackLayersChange(availableLayers []uint16)
UpTrackLayersChange(availableLayers []uint16)
WriteRTP(p *buffer.ExtPacket, layer int32) error
Close()
// ID is the globally unique identifier for this Track.
@@ -480,8 +479,8 @@ func (d *DownTrack) GetForwardingStatus() ForwardingStatus {
return d.forwarder.GetForwardingStatus()
}
func (d *DownTrack) UptrackLayersChange(availableLayers []uint16) {
d.forwarder.UptrackLayersChange(availableLayers)
func (d *DownTrack) UpTrackLayersChange(availableLayers []uint16) {
d.forwarder.UpTrackLayersChange(availableLayers)
if d.onAvailableLayersChanged != nil {
d.onAvailableLayersChanged(d)
+2 -2
View File
@@ -293,7 +293,7 @@ func (f *Forwarder) GetForwardingStatus() ForwardingStatus {
return ForwardingStatusOptimal
}
func (f *Forwarder) UptrackLayersChange(availableLayers []uint16) {
func (f *Forwarder) UpTrackLayersChange(availableLayers []uint16) {
f.lock.Lock()
defer f.lock.Unlock()
@@ -711,7 +711,7 @@ func (f *Forwarder) ProvisionalAllocateGetBestWeightedTransition() VideoTransiti
}
}
// starting from mimimum to target, find transition which gives the best
// starting from minimum to target, find transition which gives the best
// transition taking into account bits saved vs cost of such a transition
bestLayers := InvalidLayers
bestBandwidthDelta := int64(0)
+8 -8
View File
@@ -94,7 +94,7 @@ func TestForwarderGetForwardingStatus(t *testing.T) {
// with available layers, should be off
availableLayers := []uint16{0, 1, 2}
f.UptrackLayersChange(availableLayers)
f.UpTrackLayersChange(availableLayers)
require.Equal(t, ForwardingStatusOff, f.GetForwardingStatus())
// when muted, should be optimal
@@ -112,25 +112,25 @@ func TestForwarderGetForwardingStatus(t *testing.T) {
// when available layers are lower than max subscribed, optimal as long as target is at max available
availableLayers = []uint16{0, 1}
f.UptrackLayersChange(availableLayers)
f.UpTrackLayersChange(availableLayers)
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
}
func TestForwarderUptrackLayersChange(t *testing.T) {
func TestForwarderUpTrackLayersChange(t *testing.T) {
f := NewForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
require.Nil(t, f.availableLayers)
availableLayers := []uint16{0, 1, 2}
f.UptrackLayersChange(availableLayers)
f.UpTrackLayersChange(availableLayers)
require.Equal(t, availableLayers, f.availableLayers)
availableLayers = []uint16{0, 2}
f.UptrackLayersChange(availableLayers)
f.UpTrackLayersChange(availableLayers)
require.Equal(t, availableLayers, f.availableLayers)
availableLayers = []uint16{}
f.UptrackLayersChange(availableLayers)
f.UpTrackLayersChange(availableLayers)
require.Equal(t, availableLayers, f.availableLayers)
}
@@ -182,7 +182,7 @@ func TestForwarderAllocate(t *testing.T) {
// awaiting measurement, i.e. bitrates are not available, but layers available
f.lastAllocation.state = VideoAllocationStateNone
disable(f)
f.UptrackLayersChange([]uint16{0})
f.UpTrackLayersChange([]uint16{0})
expectedTargetLayers := VideoLayers{
spatial: 0,
temporal: DefaultMaxLayerTemporal,
@@ -611,7 +611,7 @@ func TestForwarderFinalizeAllocate(t *testing.T) {
// layers available, but still awaiting measurement
f.lastAllocation.state = VideoAllocationStateAwaitingMeasurement
disable(f)
f.UptrackLayersChange([]uint16{0, 1})
f.UpTrackLayersChange([]uint16{0, 1})
expectedResult = VideoAllocation{
state: VideoAllocationStateAwaitingMeasurement,
change: VideoStreamingChangeNone,
+5 -5
View File
@@ -91,12 +91,12 @@
//
// A few things to note
// 1. When a probe cluster is added, the expected media rate is provided.
// So, the wake up interval takes that into account. For example,
// So, the wake-up interval takes that into account. For example,
// if probing at 5 Mbps for 1/2 second and if 4 Mbps of it is expected
// to be provided by media traffic, the wake up interval becomes 8 ms.
// to be provided by media traffic, the wake-up interval becomes 8 ms.
// 2. The amount of probing should actually be capped at some value to
// avoid too much self-induced congestion. It maybe something like 500 kbps.
// That will increase the wake up interval to 16 ms in the above example.
// That will increase the wake-up interval to 16 ms in the above example.
// 3. In practice, the probing interval may also be shorter. Typically,
// it can be run for 2 - 3 RTTs to get a good measurement. For
// the longest hauls, RTT could be 250 ms or so leading to the probing
@@ -356,9 +356,9 @@ func (c *Cluster) Process(p *Prober) {
// Calculate number of probe bytes that should have been sent since start.
// Overall goal is to send desired number of probe bytes in minDuration.
// However it is possible that timeElapsed is more than minDuration due
// However, it is possible that timeElapsed is more than minDuration due
// to scheduling variance. When overshooting time budget, use a capped
// short fall if there a grace period given.
// short fall if there is a grace period given.
windowDone := float64(timeElapsed) / float64(c.minDuration)
if windowDone > 1.0 {
// cluster has been running for longer than minDuration
+10 -10
View File
@@ -9,12 +9,12 @@ import (
"sync/atomic"
"time"
"github.com/livekit/protocol/livekit"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/rs/zerolog/log"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/protocol/livekit"
)
type AudioLevelHandle func(level uint8, duration uint32)
@@ -243,12 +243,12 @@ func (w *WebRTCReceiver) AddDownTrack(track TrackSender) {
}
if w.Kind() == webrtc.RTPCodecTypeVideo {
// notify added downtrack of available layers
// notify added down track of available layers
w.upTrackMu.RLock()
layers, ok := w.availableLayers.Load().([]uint16)
w.upTrackMu.RUnlock()
if ok && len(layers) != 0 {
track.UptrackLayersChange(layers)
track.UpTrackLayersChange(layers)
}
}
@@ -308,12 +308,12 @@ func (w *WebRTCReceiver) SetMaxExpectedSpatialLayer(layer int32) {
//
// Some higher layer is expected to start.
// If the layer was not stopped (i. e. it will still be in available layers),
// If the layer was not stopped (i.e. it will still be in available layers),
// don't need to do anything. If not, reset the stream tracker so that
// the layer is declared available on the first packet
//
// NOTE: There may be a race between checking if a layer is available and
// resetting the tracker, i. e. the track may stop just after checking.
// resetting the tracker, i.e. the track may stop just after checking.
// But, those conditions should be rare. In those cases, the restart will
// take longer.
//
@@ -339,14 +339,14 @@ func (w *WebRTCReceiver) NumAvailableSpatialLayers() int {
return len(layers)
}
func (w *WebRTCReceiver) downtrackLayerChange(layers []uint16) {
func (w *WebRTCReceiver) downTrackLayerChange(layers []uint16) {
w.downTrackMu.RLock()
downTracks := w.downTracks
w.downTrackMu.RUnlock()
for _, dt := range downTracks {
if dt != nil {
dt.UptrackLayersChange(layers)
dt.UpTrackLayersChange(layers)
}
}
}
@@ -371,7 +371,7 @@ func (w *WebRTCReceiver) addAvailableLayer(layer uint16) {
w.availableLayers.Store(layers)
w.upTrackMu.Unlock()
w.downtrackLayerChange(layers)
w.downTrackLayerChange(layers)
}
func (w *WebRTCReceiver) removeAvailableLayer(layer uint16) {
@@ -392,7 +392,7 @@ func (w *WebRTCReceiver) removeAvailableLayer(layer uint16) {
w.upTrackMu.Unlock()
// need to immediately switch off unavailable layers
w.downtrackLayerChange(newLayers)
w.downTrackLayerChange(newLayers)
}
func (w *WebRTCReceiver) GetBitrateTemporalCumulative() Bitrates {
@@ -558,7 +558,7 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
func (w *WebRTCReceiver) writeRTP(layer int32, dt TrackSender, pkt *buffer.ExtPacket) {
if err := dt.WriteRTP(pkt, layer); err != nil {
log.Error().Err(err).Str("id", string(dt.ID())).Msg("Error writing to down track")
log.Error().Err(err).Str("id", dt.ID()).Msg("Error writing to down track")
}
}
+1 -1
View File
@@ -44,7 +44,7 @@ type packetMeta struct {
lastNack uint32
// Spatial layer of packet
layer uint8
// Information that differs depending the codec
// Information that differs depending on the codec
misc uint64
}
+1 -1
View File
@@ -114,7 +114,7 @@ func Test_packetMeta_VP8(t *testing.T) {
p.packVP8(vp8)
// booleans are not packed, so they will be `false` in unpacked.
// Also TID is only two bits, so it should be modulo 3.
// Also, TID is only two bits, so it should be modulo 3.
expectedVP8 := &buffer.VP8{
FirstByte: 25,
PictureIDPresent: 1,
+4 -3
View File
@@ -7,11 +7,12 @@ import (
"sync"
"time"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/livekit/livekit-server/pkg/config"
)
const (
@@ -817,7 +818,7 @@ func (s *StreamAllocator) allocateAllTracks() {
availableChannelCapacity := s.committedChannelCapacity
//
// This pass is just to find out if there is any left over channel capacity.
// This pass is just to find out if there is any leftover channel capacity.
// Infinite channel capacity is given so that exempt tracks do not stall
//
for _, track := range s.exemptVideoTracksSorted {
@@ -974,7 +975,7 @@ func (s *StreamAllocator) maybeBoostLayer() {
}
func (s *StreamAllocator) isTimeToBoost() bool {
// if enough time has passed since last esitmate drop or last estimate boost,
// if enough time has passed since last estimate drop or last estimate boost,
// artificially boost estimate before allocating.
// Checking against last estimate boost prevents multiple artificial boosts
// in situations where multiple tracks become available in a short span.
+2 -2
View File
@@ -24,7 +24,7 @@ const (
StreamStatusActive StreamStatus = 1
)
// StreamTracker keeps track of packet flow and ensures a particular uptrack is consistently producing
// StreamTracker keeps track of packet flow and ensures a particular up track is consistently producing
// It runs its own goroutine for detection, and fires OnStatusChanged callback
type StreamTracker struct {
// number of samples needed per cycle
@@ -169,7 +169,7 @@ func (s *StreamTracker) Observe(sn uint16) {
s.lastSN = sn
atomic.AddUint32(&s.countSinceLast, 1)
// declare stream active and start the detect worker
// declare stream active and start the detection worker
go s.init()
return
+1 -1
View File
@@ -100,7 +100,7 @@ func TestStreamTracker(t *testing.T) {
require.Equal(t, StreamStatusActive, tracker.Status())
require.Equal(t, uint32(1), callbackCalled.get())
// obaerver a few more
// observe a few more
tracker.Observe(2)
tracker.Observe(3)
tracker.Observe(4)