From 0b8a18055445527c99ec06f4fd25d6ede8d2e7b9 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Wed, 30 Mar 2022 15:49:53 -0500 Subject: [PATCH] Code inspection (#581) * Code inspection * fix [4]int64 conversiong --- README.md | 2 +- cmd/server/main.go | 3 ++- pkg/clientconfiguration/conf_test.go | 3 ++- .../staticconfiguration.go | 3 ++- pkg/logger/logger.go | 3 ++- pkg/routing/interfaces.go | 3 ++- pkg/routing/localrouter.go | 5 ++-- pkg/routing/redis.go | 3 ++- pkg/routing/redisrouter.go | 7 +++--- pkg/routing/selector/random.go | 3 ++- pkg/routing/selector/regionaware.go | 3 ++- pkg/routing/selector/regionaware_test.go | 3 ++- pkg/routing/selector/sysload.go | 3 ++- pkg/routing/selector/utils.go | 3 ++- pkg/routing/selector/utils_test.go | 3 ++- pkg/rtc/config.go | 5 ++-- pkg/rtc/mediaengine.go | 3 ++- pkg/rtc/mediaengine_test.go | 3 ++- pkg/rtc/mediatrack.go | 8 +++---- pkg/rtc/mediatrack_test.go | 6 +++-- pkg/rtc/mediatrackreceiver.go | 10 ++++---- pkg/rtc/mediatracksubscriptions.go | 5 ++-- pkg/rtc/participant.go | 18 +++++++++------ pkg/rtc/participant_internal_test.go | 3 ++- pkg/rtc/participant_signal.go | 8 ++++--- pkg/rtc/room.go | 7 +++--- pkg/rtc/room_test.go | 5 ++-- pkg/rtc/subscribedtrack.go | 3 ++- pkg/rtc/transport.go | 7 +++--- pkg/rtc/transport_test.go | 3 ++- pkg/rtc/types/interfaces.go | 3 ++- pkg/rtc/uptrackmanager_test.go | 3 ++- pkg/rtc/utils.go | 3 ++- pkg/rtc/utils_test.go | 3 ++- pkg/service/auth_test.go | 3 ++- pkg/service/localstore.go | 3 ++- pkg/service/recordingservice.go | 5 ++-- pkg/service/redisstore.go | 5 ++-- pkg/service/redisstore_test.go | 3 ++- pkg/service/roomallocator_test.go | 3 ++- pkg/service/roomservice_test.go | 5 ++-- pkg/service/rtcservice.go | 7 +++--- pkg/service/server.go | 7 +++--- pkg/service/wsprotocol.go | 5 ++-- pkg/sfu/buffer/bucket_test.go | 2 +- pkg/sfu/buffer/buffer.go | 6 +++-- pkg/sfu/buffer/datastats.go | 5 ++-- pkg/sfu/buffer/helpers.go | 3 ++- pkg/sfu/buffer/nack.go | 2 +- pkg/sfu/buffer/rtpstats.go | 23 ++++++++++--------- pkg/sfu/connectionquality/connectionstats.go | 8 ++++--- pkg/sfu/connectionquality/mos.go | 4 ++-- pkg/sfu/downtrack.go | 11 +++++---- pkg/sfu/forwarder.go | 5 ++-- pkg/sfu/forwarder_test.go | 5 ++-- pkg/sfu/helpers.go | 3 ++- pkg/sfu/prober.go | 3 ++- pkg/sfu/receiver.go | 13 ++++++----- pkg/sfu/rtpmunger_test.go | 3 ++- pkg/sfu/sequencer_test.go | 3 ++- pkg/sfu/streamallocator.go | 9 ++++---- pkg/sfu/streamtracker.go | 7 +++--- pkg/sfu/streamtrackermanager.go | 2 +- pkg/sfu/vp8munger.go | 1 + pkg/sfu/vp8munger_test.go | 3 ++- pkg/telemetry/statsworker.go | 4 ++-- pkg/telemetry/telemetryserviceinternal.go | 8 ++++--- .../telemetryserviceinternalevents.go | 3 ++- .../test/telemetry_service_events_test.go | 3 ++- pkg/telemetry/test/telemetry_service_test.go | 7 +++--- test/client/client.go | 5 ++-- test/integration_helpers.go | 3 ++- test/multinode_roomservice_test.go | 3 ++- test/multinode_test.go | 3 ++- test/scenarios.go | 5 ++-- test/singlenode_test.go | 7 +++--- test/webhook_test.go | 5 ++-- 77 files changed, 228 insertions(+), 151 deletions(-) diff --git a/README.md b/README.md index c7cb51f4b..523eab86e 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ availability. For detailed instructions, see [Kubernetes guide](https://docs.liv ### Testing your deployment -Use the [connection tester](https://livekit.io/connection-test) to ensure your installation is set-up properly for user +Use the [connection tester](https://livekit.io/connection-test) to ensure your installation is set up properly for user traffic. ## Building from source diff --git a/cmd/server/main.go b/cmd/server/main.go index 2aeee7da1..c7304026e 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -11,9 +11,10 @@ import ( "syscall" "time" - "github.com/livekit/protocol/logger" "github.com/urfave/cli/v2" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" serverlogger "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/routing" diff --git a/pkg/clientconfiguration/conf_test.go b/pkg/clientconfiguration/conf_test.go index aac624764..46f271735 100644 --- a/pkg/clientconfiguration/conf_test.go +++ b/pkg/clientconfiguration/conf_test.go @@ -3,8 +3,9 @@ package clientconfiguration import ( "testing" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + + "github.com/livekit/protocol/livekit" ) func TestScriptMatchConfiguration(t *testing.T) { diff --git a/pkg/clientconfiguration/staticconfiguration.go b/pkg/clientconfiguration/staticconfiguration.go index e417bcbd6..83f9c2dfb 100644 --- a/pkg/clientconfiguration/staticconfiguration.go +++ b/pkg/clientconfiguration/staticconfiguration.go @@ -3,9 +3,10 @@ package clientconfiguration import ( "fmt" + "google.golang.org/protobuf/proto" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" - "google.golang.org/protobuf/proto" ) type ConfigurationItem struct { diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 71d847e0e..a42d59ec9 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -3,11 +3,12 @@ package serverlogger import ( "github.com/go-logr/logr" "github.com/go-logr/zapr" - "github.com/livekit/protocol/logger" "github.com/pion/logging" "go.uber.org/zap" "go.uber.org/zap/zapcore" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" ) diff --git a/pkg/routing/interfaces.go b/pkg/routing/interfaces.go index 6e9e3e37c..303990c48 100644 --- a/pkg/routing/interfaces.go +++ b/pkg/routing/interfaces.go @@ -4,10 +4,11 @@ import ( "context" "github.com/go-redis/redis/v8" + "google.golang.org/protobuf/proto" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" - "google.golang.org/protobuf/proto" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate diff --git a/pkg/routing/localrouter.go b/pkg/routing/localrouter.go index 7e9b0fb17..958ce4030 100644 --- a/pkg/routing/localrouter.go +++ b/pkg/routing/localrouter.go @@ -5,10 +5,11 @@ import ( "sync" "time" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "go.uber.org/atomic" "google.golang.org/protobuf/proto" + + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" ) // a router of messages on the same node, basic implementation for local testing diff --git a/pkg/routing/redis.go b/pkg/routing/redis.go index 1091fb4da..c1f091737 100644 --- a/pkg/routing/redis.go +++ b/pkg/routing/redis.go @@ -4,9 +4,10 @@ import ( "context" "github.com/go-redis/redis/v8" - "github.com/livekit/protocol/livekit" "go.uber.org/atomic" "google.golang.org/protobuf/proto" + + "github.com/livekit/protocol/livekit" ) const ( diff --git a/pkg/routing/redisrouter.go b/pkg/routing/redisrouter.go index 566a10a86..7c8038bd0 100644 --- a/pkg/routing/redisrouter.go +++ b/pkg/routing/redisrouter.go @@ -9,13 +9,14 @@ import ( "time" "github.com/go-redis/redis/v8" + "github.com/pkg/errors" + "go.uber.org/atomic" + "google.golang.org/protobuf/proto" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/utils" - "github.com/pkg/errors" - "go.uber.org/atomic" - "google.golang.org/protobuf/proto" "github.com/livekit/livekit-server/pkg/routing/selector" "github.com/livekit/livekit-server/pkg/telemetry/prometheus" diff --git a/pkg/routing/selector/random.go b/pkg/routing/selector/random.go index 5f5b02826..757aae6d7 100644 --- a/pkg/routing/selector/random.go +++ b/pkg/routing/selector/random.go @@ -1,8 +1,9 @@ package selector import ( - "github.com/livekit/protocol/livekit" "github.com/thoas/go-funk" + + "github.com/livekit/protocol/livekit" ) // RandomSelector selects an available node at random diff --git a/pkg/routing/selector/regionaware.go b/pkg/routing/selector/regionaware.go index 5e6cade08..9930f6af3 100644 --- a/pkg/routing/selector/regionaware.go +++ b/pkg/routing/selector/regionaware.go @@ -3,9 +3,10 @@ package selector import ( "math" - "github.com/livekit/protocol/livekit" "github.com/thoas/go-funk" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/config" ) diff --git a/pkg/routing/selector/regionaware_test.go b/pkg/routing/selector/regionaware_test.go index ea6055a2a..1596f9f79 100644 --- a/pkg/routing/selector/regionaware_test.go +++ b/pkg/routing/selector/regionaware_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/utils" - "github.com/stretchr/testify/require" "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing/selector" diff --git a/pkg/routing/selector/sysload.go b/pkg/routing/selector/sysload.go index 5edc25df3..34dbea5a9 100644 --- a/pkg/routing/selector/sysload.go +++ b/pkg/routing/selector/sysload.go @@ -1,8 +1,9 @@ package selector import ( - "github.com/livekit/protocol/livekit" "github.com/thoas/go-funk" + + "github.com/livekit/protocol/livekit" ) // SystemLoadSelector eliminates nodes that surpass has a per-cpu node higher than SysloadLimit diff --git a/pkg/routing/selector/utils.go b/pkg/routing/selector/utils.go index cd0f4476c..667f8049e 100644 --- a/pkg/routing/selector/utils.go +++ b/pkg/routing/selector/utils.go @@ -3,9 +3,10 @@ package selector import ( "time" - "github.com/livekit/protocol/livekit" "github.com/thoas/go-funk" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/config" ) diff --git a/pkg/routing/selector/utils_test.go b/pkg/routing/selector/utils_test.go index 305ab22fa..46038be7f 100644 --- a/pkg/routing/selector/utils_test.go +++ b/pkg/routing/selector/utils_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/routing/selector" ) diff --git a/pkg/rtc/config.go b/pkg/rtc/config.go index a192c6677..c1046e474 100644 --- a/pkg/rtc/config.go +++ b/pkg/rtc/config.go @@ -4,11 +4,12 @@ import ( "errors" "net" - "github.com/livekit/protocol/logger" "github.com/pion/ice/v2" "github.com/pion/sdp/v3" "github.com/pion/webrtc/v3" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" logging "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/sfu/buffer" @@ -184,7 +185,7 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err includes := rtcConf.Interfaces.Includes excludes := rtcConf.Interfaces.Excludes s.SetInterfaceFilter(func(s string) bool { - //filter by include interfaces + // filter by include interfaces if len(includes) > 0 { for _, iface := range includes { if iface == s { diff --git a/pkg/rtc/mediaengine.go b/pkg/rtc/mediaengine.go index 19e1f6e51..8c8b12d4b 100644 --- a/pkg/rtc/mediaengine.go +++ b/pkg/rtc/mediaengine.go @@ -3,8 +3,9 @@ package rtc import ( "strings" - "github.com/livekit/protocol/livekit" "github.com/pion/webrtc/v3" + + "github.com/livekit/protocol/livekit" ) func registerCodecs(me *webrtc.MediaEngine, codecs []*livekit.Codec, rtcpFeedback RTCPFeedbackConfig) error { diff --git a/pkg/rtc/mediaengine_test.go b/pkg/rtc/mediaengine_test.go index 183f6f799..b774f49fa 100644 --- a/pkg/rtc/mediaengine_test.go +++ b/pkg/rtc/mediaengine_test.go @@ -3,9 +3,10 @@ package rtc import ( "testing" - "github.com/livekit/protocol/livekit" "github.com/pion/webrtc/v3" "github.com/stretchr/testify/require" + + "github.com/livekit/protocol/livekit" ) func TestIsCodecEnabled(t *testing.T) { diff --git a/pkg/rtc/mediatrack.go b/pkg/rtc/mediatrack.go index 59857ec5c..3dda1909e 100644 --- a/pkg/rtc/mediatrack.go +++ b/pkg/rtc/mediatrack.go @@ -4,18 +4,18 @@ import ( "context" "sync" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/rtcp" "github.com/pion/webrtc/v3" + "go.uber.org/atomic" + + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/sfu" "github.com/livekit/livekit-server/pkg/sfu/buffer" "github.com/livekit/livekit-server/pkg/sfu/twcc" "github.com/livekit/livekit-server/pkg/telemetry" - - "go.uber.org/atomic" ) // MediaTrack represents a WebRTC track that needs to be forwarded diff --git a/pkg/rtc/mediatrack_test.go b/pkg/rtc/mediatrack_test.go index b8b2fe733..b3fbd2b6c 100644 --- a/pkg/rtc/mediatrack_test.go +++ b/pkg/rtc/mediatrack_test.go @@ -4,9 +4,11 @@ import ( "testing" "time" - "github.com/livekit/livekit-server/pkg/config" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + + "github.com/livekit/protocol/livekit" + + "github.com/livekit/livekit-server/pkg/config" ) func TestTrackInfo(t *testing.T) { diff --git a/pkg/rtc/mediatrackreceiver.go b/pkg/rtc/mediatrackreceiver.go index 1f4b38964..0b58ef26e 100644 --- a/pkg/rtc/mediatrackreceiver.go +++ b/pkg/rtc/mediatrackreceiver.go @@ -6,14 +6,14 @@ import ( "sync" "time" - "github.com/livekit/livekit-server/pkg/config" - "github.com/livekit/livekit-server/pkg/rtc/types" + "github.com/pion/rtcp" "go.uber.org/atomic" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" - "github.com/pion/rtcp" + "github.com/livekit/livekit-server/pkg/config" + "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/telemetry" @@ -205,7 +205,9 @@ func (t *MediaTrackReceiver) AddSubscriber(sub types.LocalParticipant) error { downTrack.AddReceiverReportListener(t.handleMaxLossFeedback) } - receiver.AddDownTrack(downTrack) + if err = receiver.AddDownTrack(downTrack); err != nil { + logger.Errorw("could not add down track", err, "participant", sub.Identity(), "pID", sub.ID()) + } } return nil } diff --git a/pkg/rtc/mediatracksubscriptions.go b/pkg/rtc/mediatracksubscriptions.go index 67a009aca..f5393f99f 100644 --- a/pkg/rtc/mediatracksubscriptions.go +++ b/pkg/rtc/mediatracksubscriptions.go @@ -7,12 +7,13 @@ import ( "time" "github.com/bep/debounce" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/rtcp" "github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3/pkg/rtcerr" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/rtc/types" "github.com/livekit/livekit-server/pkg/sfu" diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 7fc77fae0..d1804e79f 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -8,16 +8,17 @@ import ( "time" lru "github.com/hashicorp/golang-lru" - "github.com/livekit/protocol/auth" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" - "github.com/livekit/protocol/utils" "github.com/pion/rtcp" "github.com/pion/webrtc/v3" "github.com/pkg/errors" "go.uber.org/atomic" "google.golang.org/protobuf/proto" + "github.com/livekit/protocol/auth" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/protocol/utils" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/rtc/types" @@ -607,7 +608,10 @@ func (p *ParticipantImpl) SetMigrateState(s types.MigrateState) { p.handlePendingDataChannels() } if pendingOffer != nil { - p.HandleOffer(*pendingOffer) + _, err := p.HandleOffer(*pendingOffer) + if err != nil { + p.GetLogger().Errorw("could not handle offer", err) + } } } @@ -671,7 +675,7 @@ func (p *ParticipantImpl) GetConnectionQuality() *livekit.ConnectionQualityInfo return &livekit.ConnectionQualityInfo{ ParticipantSid: string(p.ID()), Quality: rating, - Score: float32(avgScore), + Score: avgScore, } } @@ -1321,7 +1325,7 @@ func (p *ParticipantImpl) mediaTrackReceived(track *webrtc.TrackRemote, rtpRecei p.pendingTracksLock.Lock() newTrack := false - // use existing mediatrack to handle simulcast + // use existing media track to handle simulcast mt, ok := p.getPublishedTrackBySdpCid(track.ID()).(*MediaTrack) if !ok { signalCid, ti := p.getPendingTrack(track.ID(), ToProtoTrackKind(track.Kind())) diff --git a/pkg/rtc/participant_internal_test.go b/pkg/rtc/participant_internal_test.go index 0837baa87..b5345a00c 100644 --- a/pkg/rtc/participant_internal_test.go +++ b/pkg/rtc/participant_internal_test.go @@ -4,10 +4,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/utils" - "github.com/stretchr/testify/require" "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing" diff --git a/pkg/rtc/participant_signal.go b/pkg/rtc/participant_signal.go index 5197758c3..a15227067 100644 --- a/pkg/rtc/participant_signal.go +++ b/pkg/rtc/participant_signal.go @@ -3,11 +3,13 @@ package rtc import ( "fmt" - "github.com/livekit/livekit-server/pkg/routing" - "github.com/livekit/livekit-server/version" - "github.com/livekit/protocol/livekit" "github.com/pion/webrtc/v3" "google.golang.org/protobuf/proto" + + "github.com/livekit/protocol/livekit" + + "github.com/livekit/livekit-server/pkg/routing" + "github.com/livekit/livekit-server/version" ) func (p *ParticipantImpl) GetResponseSink() routing.MessageSink { diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index 4c2b19a68..9118383a6 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -7,11 +7,12 @@ import ( "sync" "time" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "go.uber.org/atomic" "google.golang.org/protobuf/proto" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/rtc/types" @@ -664,7 +665,7 @@ func (r *Room) onDataPacket(source types.LocalParticipant, dp *livekit.DataPacke } err := op.SendDataPacket(dp) if err != nil { - r.Logger.Infow("send datapacket error", "error", err, "participant", op.Identity()) + r.Logger.Infow("send data packet error", "error", err, "participant", op.Identity()) } } } diff --git a/pkg/rtc/room_test.go b/pkg/rtc/room_test.go index 3c7d6b799..ad04c175e 100644 --- a/pkg/rtc/room_test.go +++ b/pkg/rtc/room_test.go @@ -5,10 +5,10 @@ import ( "testing" "time" - "github.com/livekit/livekit-server/pkg/telemetry/telemetryfakes" + "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/webhook" - "github.com/stretchr/testify/require" "github.com/livekit/livekit-server/pkg/config" serverlogger "github.com/livekit/livekit-server/pkg/logger" @@ -16,6 +16,7 @@ import ( "github.com/livekit/livekit-server/pkg/rtc/types" "github.com/livekit/livekit-server/pkg/rtc/types/typesfakes" "github.com/livekit/livekit-server/pkg/telemetry" + "github.com/livekit/livekit-server/pkg/telemetry/telemetryfakes" "github.com/livekit/livekit-server/pkg/testutils" ) diff --git a/pkg/rtc/subscribedtrack.go b/pkg/rtc/subscribedtrack.go index 2dbebbc13..b03579366 100644 --- a/pkg/rtc/subscribedtrack.go +++ b/pkg/rtc/subscribedtrack.go @@ -4,10 +4,11 @@ import ( "time" "github.com/bep/debounce" - "github.com/livekit/protocol/livekit" "github.com/pion/webrtc/v3" "go.uber.org/atomic" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/rtc/types" "github.com/livekit/livekit-server/pkg/sfu" ) diff --git a/pkg/rtc/transport.go b/pkg/rtc/transport.go index bb2468b62..0d2de281e 100644 --- a/pkg/rtc/transport.go +++ b/pkg/rtc/transport.go @@ -8,8 +8,6 @@ import ( "github.com/bep/debounce" "github.com/go-logr/logr" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/interceptor" "github.com/pion/interceptor/pkg/cc" "github.com/pion/interceptor/pkg/gcc" @@ -17,6 +15,9 @@ import ( "github.com/pion/sdp/v3" "github.com/pion/webrtc/v3" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" serverlogger "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/rtc/types" @@ -391,7 +392,7 @@ func (t *PCTransport) preparePC(previousAnswer webrtc.SessionDescription) error // // Simulate client side peer connection and set DTLS role from previous answer. // Role needs to be set properly (one side needs to be server and the other side - // eeds to be the client) for DTLS connection to form properly. As this is + // needs to be the client) for DTLS connection to form properly. As this is // trying to replicate previous setup, read from previous answer and use that role. // se := webrtc.SettingEngine{} diff --git a/pkg/rtc/transport_test.go b/pkg/rtc/transport_test.go index f7cafc17d..2ad3ecbb6 100644 --- a/pkg/rtc/transport_test.go +++ b/pkg/rtc/transport_test.go @@ -4,11 +4,12 @@ import ( "testing" "time" - "github.com/livekit/protocol/livekit" "github.com/pion/webrtc/v3" "github.com/stretchr/testify/require" "go.uber.org/atomic" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/testutils" ) diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index 8c7dd6a70..f8917316e 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -4,10 +4,11 @@ import ( "fmt" "time" + "github.com/pion/webrtc/v3" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" - "github.com/pion/webrtc/v3" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/sfu" diff --git a/pkg/rtc/uptrackmanager_test.go b/pkg/rtc/uptrackmanager_test.go index 7b71b9961..31d49d211 100644 --- a/pkg/rtc/uptrackmanager_test.go +++ b/pkg/rtc/uptrackmanager_test.go @@ -3,9 +3,10 @@ package rtc import ( "testing" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/rtc/types/typesfakes" ) diff --git a/pkg/rtc/utils.go b/pkg/rtc/utils.go index bfffc84d5..47c527996 100644 --- a/pkg/rtc/utils.go +++ b/pkg/rtc/utils.go @@ -7,9 +7,10 @@ import ( "strings" "github.com/go-logr/logr" + "github.com/pion/webrtc/v3" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" - "github.com/pion/webrtc/v3" "github.com/livekit/livekit-server/pkg/rtc/types" ) diff --git a/pkg/rtc/utils_test.go b/pkg/rtc/utils_test.go index b93637b50..9e13e8fe2 100644 --- a/pkg/rtc/utils_test.go +++ b/pkg/rtc/utils_test.go @@ -3,8 +3,9 @@ package rtc import ( "testing" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + + "github.com/livekit/protocol/livekit" ) func TestPackStreamId(t *testing.T) { diff --git a/pkg/service/auth_test.go b/pkg/service/auth_test.go index 67f8d0686..f61d9fbc0 100644 --- a/pkg/service/auth_test.go +++ b/pkg/service/auth_test.go @@ -5,9 +5,10 @@ import ( "net/http/httptest" "testing" + "github.com/stretchr/testify/require" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/auth/authfakes" - "github.com/stretchr/testify/require" "github.com/livekit/livekit-server/pkg/service" ) diff --git a/pkg/service/localstore.go b/pkg/service/localstore.go index c5b5396ac..9f9e86e21 100644 --- a/pkg/service/localstore.go +++ b/pkg/service/localstore.go @@ -5,8 +5,9 @@ import ( "sync" "time" - "github.com/livekit/protocol/livekit" "github.com/thoas/go-funk" + + "github.com/livekit/protocol/livekit" ) // encapsulates CRUD operations for room settings diff --git a/pkg/service/recordingservice.go b/pkg/service/recordingservice.go index eeaf8bc0c..dbd3759c0 100644 --- a/pkg/service/recordingservice.go +++ b/pkg/service/recordingservice.go @@ -4,12 +4,13 @@ import ( "context" "errors" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/emptypb" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/recording" "github.com/livekit/protocol/utils" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/emptypb" "github.com/livekit/livekit-server/pkg/telemetry" ) diff --git a/pkg/service/redisstore.go b/pkg/service/redisstore.go index 5002cef77..eab293abe 100644 --- a/pkg/service/redisstore.go +++ b/pkg/service/redisstore.go @@ -5,10 +5,11 @@ import ( "time" "github.com/go-redis/redis/v8" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/utils" "github.com/pkg/errors" "google.golang.org/protobuf/proto" + + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/utils" ) const ( diff --git a/pkg/service/redisstore_test.go b/pkg/service/redisstore_test.go index c135a07be..1f6eb6868 100644 --- a/pkg/service/redisstore_test.go +++ b/pkg/service/redisstore_test.go @@ -6,10 +6,11 @@ import ( "testing" "time" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" "go.uber.org/atomic" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/service" ) diff --git a/pkg/service/roomallocator_test.go b/pkg/service/roomallocator_test.go index 8c75b9de0..952f41972 100644 --- a/pkg/service/roomallocator_test.go +++ b/pkg/service/roomallocator_test.go @@ -4,9 +4,10 @@ import ( "context" "testing" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/routing/routingfakes" diff --git a/pkg/service/roomservice_test.go b/pkg/service/roomservice_test.go index 3f3086755..74ec8fb31 100644 --- a/pkg/service/roomservice_test.go +++ b/pkg/service/roomservice_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/livekit/protocol/auth" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" "github.com/twitchtv/twirp" + "github.com/livekit/protocol/auth" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing/routingfakes" "github.com/livekit/livekit-server/pkg/service" diff --git a/pkg/service/rtcservice.go b/pkg/service/rtcservice.go index 79b59960c..cfdbb2eb7 100644 --- a/pkg/service/rtcservice.go +++ b/pkg/service/rtcservice.go @@ -8,9 +8,8 @@ import ( "strconv" "strings" - "github.com/sebest/xff" - "github.com/gorilla/websocket" + "github.com/sebest/xff" "github.com/ua-parser/uap-go/uaparser" "github.com/livekit/protocol/livekit" @@ -147,7 +146,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - // when autocreate is disabled, we'll check to ensure it's already created + // when auto create is disabled, we'll check to ensure it's already created if !s.config.Room.AutoCreate { _, err := s.store.LoadRoom(context.Background(), roomName) if err == ErrRoomNotFound { @@ -288,7 +287,7 @@ func (s *RTCService) ParseClientInfo(r *http.Request) *livekit.ClientInfo { ci.Browser = values.Get("browser") ci.BrowserVersion = values.Get("browser_version") ci.DeviceModel = values.Get("device_model") - // get real address (forwarded http header) - check Cloudfare headers first, fall back to X-Forwaded-For + // get real address (forwarded http header) - check Cloudflare headers first, fall back to X-Forwarded-For ci.Address = r.Header.Get("CF-Connecting-IP") if len(ci.Address) == 0 { ci.Address = xff.GetRemoteAddr(r) diff --git a/pkg/service/server.go b/pkg/service/server.go index 7d05f148e..1c5ac902f 100644 --- a/pkg/service/server.go +++ b/pkg/service/server.go @@ -10,15 +10,16 @@ import ( "runtime/pprof" "time" - "github.com/livekit/protocol/auth" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/turn/v2" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rs/cors" "github.com/urfave/negroni" "go.uber.org/atomic" + "github.com/livekit/protocol/auth" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/version" diff --git a/pkg/service/wsprotocol.go b/pkg/service/wsprotocol.go index d67d775c8..3bd450c14 100644 --- a/pkg/service/wsprotocol.go +++ b/pkg/service/wsprotocol.go @@ -5,11 +5,12 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/rtc/types" ) diff --git a/pkg/sfu/buffer/bucket_test.go b/pkg/sfu/buffer/bucket_test.go index b9d522b7b..c6c4c723c 100644 --- a/pkg/sfu/buffer/bucket_test.go +++ b/pkg/sfu/buffer/bucket_test.go @@ -85,7 +85,7 @@ func Test_queue(t *testing.T) { _, err = q.GetPacket(buff, 0) require.ErrorIs(t, err, ErrPacketNotFound) - // ask for soemething ahead of headSN + // ask for something ahead of headSN _, err = q.GetPacket(buff, 11) require.ErrorIs(t, err, ErrPacketNotFound) } diff --git a/pkg/sfu/buffer/buffer.go b/pkg/sfu/buffer/buffer.go index 9f95141a7..e3dce2c60 100644 --- a/pkg/sfu/buffer/buffer.go +++ b/pkg/sfu/buffer/buffer.go @@ -9,13 +9,15 @@ import ( "time" "github.com/gammazero/deque" - "github.com/livekit/livekit-server/pkg/utils" - "github.com/livekit/protocol/logger" "github.com/pion/rtcp" "github.com/pion/rtp" "github.com/pion/sdp/v3" "github.com/pion/webrtc/v3" "go.uber.org/atomic" + + "github.com/livekit/protocol/logger" + + "github.com/livekit/livekit-server/pkg/utils" ) const ( diff --git a/pkg/sfu/buffer/datastats.go b/pkg/sfu/buffer/datastats.go index 1160fa91f..face072e6 100644 --- a/pkg/sfu/buffer/datastats.go +++ b/pkg/sfu/buffer/datastats.go @@ -4,8 +4,9 @@ import ( "sync" "time" - "github.com/livekit/protocol/livekit" "google.golang.org/protobuf/types/known/timestamppb" + + "github.com/livekit/protocol/livekit" ) type DataStatsParam struct { @@ -83,6 +84,6 @@ func (s *DataStats) ToProtoAggregateOnly() *livekit.RTPStats { EndTime: timestamppb.New(end), Duration: end.Sub(s.startTime).Seconds(), Bytes: uint64(s.windowBytes), - Bitrate: float64(s.windowBytes) * 8 / float64(end.Sub(s.startTime).Seconds()), + Bitrate: float64(s.windowBytes) * 8 / end.Sub(s.startTime).Seconds(), } } diff --git a/pkg/sfu/buffer/helpers.go b/pkg/sfu/buffer/helpers.go index c9f7a5309..398edbf9e 100644 --- a/pkg/sfu/buffer/helpers.go +++ b/pkg/sfu/buffer/helpers.go @@ -5,8 +5,9 @@ import ( "errors" "time" - "github.com/livekit/protocol/logger" "github.com/pion/rtp/codecs" + + "github.com/livekit/protocol/logger" ) var ( diff --git a/pkg/sfu/buffer/nack.go b/pkg/sfu/buffer/nack.go index a7c7a5387..81bb80407 100644 --- a/pkg/sfu/buffer/nack.go +++ b/pkg/sfu/buffer/nack.go @@ -63,7 +63,7 @@ func (n *NackQueue) Pairs() ([]rtcp.NackPair, int) { // set it far back to get the first pair baseSN := n.nacks[0].seqNum - 17 - snsToPurge := []uint16{} + snsToPurge := make([]uint16, 0) numSeqNumsNacked := 0 isPairActive := false diff --git a/pkg/sfu/buffer/rtpstats.go b/pkg/sfu/buffer/rtpstats.go index 43f6a1a77..16bd6e6c1 100644 --- a/pkg/sfu/buffer/rtpstats.go +++ b/pkg/sfu/buffer/rtpstats.go @@ -6,11 +6,12 @@ import ( "sync" "time" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/rtcp" "github.com/pion/rtp" "google.golang.org/protobuf/types/known/timestamppb" + + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" ) const ( @@ -224,7 +225,7 @@ func (r *RTPStats) Update(rtph *rtp.Header, payloadSize int, paddingSize int, pa "tsDiff", rtph.Timestamp-r.highestTS, "highestTime", r.highestTime, "now", packetTime, - "timeDiff(ms)", float64(packetTime-r.highestTime)/float64(1e6), + "timeDiff(ms)", float64(packetTime-r.highestTime)/1e6, ) } // LK-DEBUG-REMOVE END @@ -290,7 +291,7 @@ func (r *RTPStats) maybeAdjustStartSN(rtph *rtp.Header, packetTime int64) { "tsDiff", rtph.Timestamp-r.highestTS, "highestTime", r.highestTime, "now", packetTime, - "timeDiff(ms)", float64(packetTime-r.highestTime)/float64(1e6), + "timeDiff(ms)", float64(packetTime-r.highestTime)/1e6, ) // LK-DEBUG-REMOVE END // NOTE: current sequence number is counted as loss as it will be deducted in the duplicate check @@ -839,12 +840,12 @@ func (r *RTPStats) getNumPacketsSeen() uint32 { func (r *RTPStats) setSeenSN(sn uint16) { idx, rem := getPos(sn) - r.seenSNs[idx] |= (1 << rem) + r.seenSNs[idx] |= 1 << rem } func (r *RTPStats) clearSeenSN(sn uint16) { idx, rem := getPos(sn) - r.seenSNs[idx] &^= (1 << rem) + r.seenSNs[idx] &^= 1 << rem } func (r *RTPStats) isSeenSN(sn uint16) bool { @@ -943,7 +944,7 @@ func (r *RTPStats) getAndResetSnapshot(snapshotId uint32) *Snapshot { // ---------------------------------- -func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats { +func AggregateRTPStats(statsList []*livekit.RTPStats) *livekit.RTPStats { startTime := time.Time{} endTime := time.Time{} @@ -958,7 +959,7 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats { frames := uint32(0) keyFrames := uint32(0) lastKeyFrame := time.Time{} - jitter := float64(0.0) + jitter := 0.0 maxJitter := float64(0) gapHistogram := make(map[int32]uint32, GapHistogramNumBins) nacks := uint32(0) @@ -972,7 +973,7 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats { rtt := uint32(0) maxRtt := uint32(0) - for _, stats := range statses { + for _, stats := range statsList { if startTime.IsZero() || startTime.After(stats.StartTime.AsTime()) { startTime = stats.StartTime.AsTime() } @@ -1076,7 +1077,7 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats { FrameRate: frameRate, KeyFrames: keyFrames, LastKeyFrame: timestamppb.New(lastKeyFrame), - JitterCurrent: jitter / float64(len(statses)), + JitterCurrent: jitter / float64(len(statsList)), JitterMax: maxJitter, GapHistogram: gapHistogram, Nacks: nacks, @@ -1087,7 +1088,7 @@ func AggregateRTPStats(statses []*livekit.RTPStats) *livekit.RTPStats { LastLayerLockPli: timestamppb.New(lastLayerLockPli), Firs: firs, LastFir: timestamppb.New(lastFir), - RttCurrent: rtt / uint32(len(statses)), + RttCurrent: rtt / uint32(len(statsList)), RttMax: maxRtt, } } diff --git a/pkg/sfu/connectionquality/connectionstats.go b/pkg/sfu/connectionquality/connectionstats.go index 0f1b53f53..1736e0319 100644 --- a/pkg/sfu/connectionquality/connectionstats.go +++ b/pkg/sfu/connectionquality/connectionstats.go @@ -4,11 +4,13 @@ import ( "sync" "time" - "github.com/livekit/livekit-server/pkg/sfu/buffer" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/webrtc/v3" "go.uber.org/atomic" + + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + + "github.com/livekit/livekit-server/pkg/sfu/buffer" ) const ( diff --git a/pkg/sfu/connectionquality/mos.go b/pkg/sfu/connectionquality/mos.go index ef73a91d4..c2b02ea3f 100644 --- a/pkg/sfu/connectionquality/mos.go +++ b/pkg/sfu/connectionquality/mos.go @@ -22,7 +22,7 @@ func Score2Rating(score float32) livekit.ConnectionQuality { return livekit.ConnectionQuality_POOR } -func mosAudioEmodel(pctLoss float32, rtt uint32, jitter float32) float32 { +func mosAudioEModel(pctLoss float32, rtt uint32, jitter float32) float32 { rx := 93.2 - pctLoss ry := 0.18*rx*rx - 27.9*rx + 1126.62 @@ -68,7 +68,7 @@ func loss2Score(pctLoss float32, reducedQuality bool) float32 { } func AudioConnectionScore(pctLoss float32, rtt uint32, jitter float32) float32 { - return mosAudioEmodel(pctLoss, rtt, jitter) + return mosAudioEModel(pctLoss, rtt, jitter) } func VideoConnectionScore(pctLoss float32, reducedQuality bool) float32 { diff --git a/pkg/sfu/downtrack.go b/pkg/sfu/downtrack.go index 304c96c1f..c11df369f 100644 --- a/pkg/sfu/downtrack.go +++ b/pkg/sfu/downtrack.go @@ -9,8 +9,6 @@ import ( "sync" "time" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/rtcp" "github.com/pion/rtp" "github.com/pion/sdp/v3" @@ -18,6 +16,9 @@ import ( "github.com/pion/webrtc/v3" "go.uber.org/atomic" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/sfu/buffer" "github.com/livekit/livekit-server/pkg/sfu/connectionquality" "github.com/livekit/livekit-server/pkg/utils" @@ -241,7 +242,7 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters, d.bound.Store(true) d.connectionStats.Start() - d.logger.Debugw("binded") + d.logger.Debugw("bound") return codec, nil } @@ -555,7 +556,7 @@ func (d *DownTrack) Close() { // 1. When transceiver is reused by other participant's video track, // set flush=true to avoid previous video shows before previous stream is displayed. // 2. in case of session migration, participant migrate from other node, video track should -// be resumed with same participant, set flush=false since we don't need flush decoder. +// be resumed with same participant, set flush=false since we don't need to flush decoder. func (d *DownTrack) CloseWithFlush(flush bool) { d.forwarder.Mute(true) @@ -563,7 +564,7 @@ func (d *DownTrack) CloseWithFlush(flush bool) { // Idea here is to send blank 1x1 key frames to flush the decoder buffer at the remote end. // Otherwise, with transceiver re-use last frame from previous stream is held in the // display buffer and there could be a brief moment where the previous stream is displayed. - d.logger.Infow("close downtrack", "peerID", d.peerID, "trackID", d.id, "flushBlankFrame", flush) + d.logger.Infow("close down track", "peerID", d.peerID, "trackID", d.id, "flushBlankFrame", flush) if flush { _ = d.writeBlankFrameRTP() } diff --git a/pkg/sfu/forwarder.go b/pkg/sfu/forwarder.go index dc41946e0..b0d0e1194 100644 --- a/pkg/sfu/forwarder.go +++ b/pkg/sfu/forwarder.go @@ -6,9 +6,10 @@ import ( "strings" "sync" - "github.com/livekit/protocol/logger" "github.com/pion/webrtc/v3" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/sfu/buffer" ) @@ -298,7 +299,7 @@ func (f *Forwarder) GetForwardingStatus() ForwardingStatus { return ForwardingStatusOff } - if f.targetLayers.spatial < f.maxLayers.spatial && f.targetLayers.spatial < int32(f.availableLayers[len(f.availableLayers)-1]) { + if f.targetLayers.spatial < f.maxLayers.spatial && f.targetLayers.spatial < f.availableLayers[len(f.availableLayers)-1] { return ForwardingStatusPartial } diff --git a/pkg/sfu/forwarder_test.go b/pkg/sfu/forwarder_test.go index 15c94ee63..918d7544b 100644 --- a/pkg/sfu/forwarder_test.go +++ b/pkg/sfu/forwarder_test.go @@ -4,10 +4,11 @@ import ( "reflect" "testing" - "github.com/livekit/protocol/logger" "github.com/pion/webrtc/v3" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/sfu/buffer" "github.com/livekit/livekit-server/pkg/sfu/testutils" ) @@ -1400,7 +1401,7 @@ func TestForwardGetSnTsForBlankFrames(t *testing.T) { require.Equal(t, sntsExpected, snts) // now that there is a marker, timestamp should jump on first padding when asked again - // also number of padding should be RTPBlnkFramesMax + // also number of padding should be RTPBlankFramesMax snts, frameEndNeeded, err = f.GetSnTsForBlankFrames() require.NoError(t, err) require.False(t, frameEndNeeded) diff --git a/pkg/sfu/helpers.go b/pkg/sfu/helpers.go index 78cc3fe90..cc54c824e 100644 --- a/pkg/sfu/helpers.go +++ b/pkg/sfu/helpers.go @@ -5,9 +5,10 @@ import ( "strings" "time" - "github.com/livekit/livekit-server/pkg/sfu/buffer" "github.com/pion/rtcp" "github.com/pion/webrtc/v3" + + "github.com/livekit/livekit-server/pkg/sfu/buffer" ) const ( diff --git a/pkg/sfu/prober.go b/pkg/sfu/prober.go index 6627991ce..6b26fa0d5 100644 --- a/pkg/sfu/prober.go +++ b/pkg/sfu/prober.go @@ -112,8 +112,9 @@ import ( "time" "github.com/gammazero/deque" - "github.com/livekit/protocol/logger" "go.uber.org/atomic" + + "github.com/livekit/protocol/logger" ) type ProberParams struct { diff --git a/pkg/sfu/receiver.go b/pkg/sfu/receiver.go index 572707858..806fd3fa2 100644 --- a/pkg/sfu/receiver.go +++ b/pkg/sfu/receiver.go @@ -8,13 +8,14 @@ import ( "time" "github.com/go-logr/logr" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/rtcp" "github.com/pion/webrtc/v3" "github.com/rs/zerolog/log" "go.uber.org/atomic" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/sfu/buffer" "github.com/livekit/livekit-server/pkg/sfu/connectionquality" @@ -205,12 +206,12 @@ func (w *WebRTCReceiver) SetRTT(rtt uint32) { buffers := w.buffers w.bufferMu.Unlock() - for _, buffer := range buffers { - if buffer == nil { + for _, buff := range buffers { + if buff == nil { continue } - buffer.SetRTT(rtt) + buff.SetRTT(rtt) } } @@ -440,7 +441,7 @@ func (w *WebRTCReceiver) getQualityParams() *buffer.ConnectionQualityParams { packetsExpected := uint32(0) packetsLost := uint32(0) - maxJitter := float64(0.0) + maxJitter := 0.0 maxRtt := uint32(0) for _, buff := range w.buffers { if buff == nil { diff --git a/pkg/sfu/rtpmunger_test.go b/pkg/sfu/rtpmunger_test.go index 203729da4..e5ed51dc9 100644 --- a/pkg/sfu/rtpmunger_test.go +++ b/pkg/sfu/rtpmunger_test.go @@ -4,9 +4,10 @@ import ( "reflect" "testing" - "github.com/livekit/protocol/logger" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/sfu/testutils" ) diff --git a/pkg/sfu/sequencer_test.go b/pkg/sfu/sequencer_test.go index 7566029c3..394b2153a 100644 --- a/pkg/sfu/sequencer_test.go +++ b/pkg/sfu/sequencer_test.go @@ -5,9 +5,10 @@ import ( "testing" "time" - "github.com/livekit/protocol/logger" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/sfu/buffer" ) diff --git a/pkg/sfu/streamallocator.go b/pkg/sfu/streamallocator.go index 29ca3a0db..5d579abc8 100644 --- a/pkg/sfu/streamallocator.go +++ b/pkg/sfu/streamallocator.go @@ -7,13 +7,14 @@ import ( "sync" "time" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/interceptor/pkg/cc" "github.com/pion/rtcp" "github.com/pion/webrtc/v3" "go.uber.org/atomic" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" ) @@ -864,7 +865,7 @@ func (s *StreamAllocator) finalizeProbe() { // reset probe interval on a successful probe s.resetProbeInterval() - // probe estimate is same or higher, commit it and try allocate deficient tracks + // probe estimate is same or higher, commit it and try to allocate deficient tracks s.params.Logger.Infow( "successful probe, updating channel capacity", "old(bps)", s.committedChannelCapacity, @@ -1597,7 +1598,7 @@ func (c *ChannelObserver) GetHighestEstimate() int64 { } func (c *ChannelObserver) GetNackRatio() float64 { - ratio := float64(0.0) + ratio := 0.0 if c.packets != 0 { ratio = float64(c.repeatedNacks) / float64(c.packets) if ratio > 1.0 { diff --git a/pkg/sfu/streamtracker.go b/pkg/sfu/streamtracker.go index 9990ae63b..035927103 100644 --- a/pkg/sfu/streamtracker.go +++ b/pkg/sfu/streamtracker.go @@ -4,9 +4,10 @@ import ( "sync" "time" + "go.uber.org/atomic" + "github.com/livekit/livekit-server/pkg/utils" "github.com/livekit/protocol/logger" - "go.uber.org/atomic" ) type StreamStatus int32 @@ -228,12 +229,12 @@ func (s *StreamTracker) Observe(sn uint16, temporalLayer int32, pktSize int) { } // BitrateTemporalCumulative returns the current stream bitrate temporal layer accumulated with lower temporal layers. -func (s *StreamTracker) BitrateTemporalCumulative() [4]int64 { +func (s *StreamTracker) BitrateTemporalCumulative() []int64 { s.lock.RLock() defer s.lock.RUnlock() // copy and process - var brs [4]int64 + brs := make([]int64, len(s.bitrate)) for i := 0; i < len(s.bitrate); i++ { brs[i] = s.bitrate[i] } diff --git a/pkg/sfu/streamtrackermanager.go b/pkg/sfu/streamtrackermanager.go index 05f2c7c77..f325d9454 100644 --- a/pkg/sfu/streamtrackermanager.go +++ b/pkg/sfu/streamtrackermanager.go @@ -232,7 +232,7 @@ func (s *StreamTrackerManager) GetBitrateTemporalCumulative() Bitrates { for i, tracker := range s.trackers { if tracker != nil { - var tls [DefaultMaxLayerTemporal + 1]int64 + tls := make([]int64, DefaultMaxLayerTemporal+1) if s.hasSpatialLayerLocked(int32(i)) { tls = tracker.BitrateTemporalCumulative() } diff --git a/pkg/sfu/vp8munger.go b/pkg/sfu/vp8munger.go index 7250eb355..655484a7d 100644 --- a/pkg/sfu/vp8munger.go +++ b/pkg/sfu/vp8munger.go @@ -2,6 +2,7 @@ package sfu import ( "github.com/elliotchance/orderedmap" + "github.com/livekit/protocol/logger" "github.com/livekit/livekit-server/pkg/sfu/buffer" diff --git a/pkg/sfu/vp8munger_test.go b/pkg/sfu/vp8munger_test.go index 1f356ff4f..b3519d568 100644 --- a/pkg/sfu/vp8munger_test.go +++ b/pkg/sfu/vp8munger_test.go @@ -4,9 +4,10 @@ import ( "reflect" "testing" - "github.com/livekit/protocol/logger" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/sfu/buffer" "github.com/livekit/livekit-server/pkg/sfu/testutils" ) diff --git a/pkg/telemetry/statsworker.go b/pkg/telemetry/statsworker.go index 2a2a834f7..42a6b8158 100644 --- a/pkg/telemetry/statsworker.go +++ b/pkg/telemetry/statsworker.go @@ -6,9 +6,9 @@ import ( "github.com/livekit/protocol/logger" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/livekit/protocol/livekit" - "google.golang.org/protobuf/types/known/timestamppb" ) type Stat struct { @@ -307,7 +307,7 @@ func (stats *Stats) computeDeltaStats() *livekit.AnalyticsStat { maxLayer := int32(-1) var maxDeltaBytes uint64 - //create a map of VideoLayers - to pick max/best layer wrt current and prev + // create a map of VideoLayers - to pick max/best layer wrt current and prev curLayers := make(map[int32]*livekit.AnalyticsVideoLayer) // if we have prev, find max delta total bytes for each layer if prev != nil { diff --git a/pkg/telemetry/telemetryserviceinternal.go b/pkg/telemetry/telemetryserviceinternal.go index 663ba4459..ee68fcf17 100644 --- a/pkg/telemetry/telemetryserviceinternal.go +++ b/pkg/telemetry/telemetryserviceinternal.go @@ -4,9 +4,11 @@ import ( "context" "github.com/gammazero/workerpool" - "github.com/livekit/livekit-server/pkg/telemetry/prometheus" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/webhook" + + "github.com/livekit/livekit-server/pkg/telemetry/prometheus" ) const maxWebhookWorkers = 50 @@ -75,8 +77,8 @@ func (t *telemetryServiceInternal) Report(ctx context.Context, stats []*livekit. totalPackets := uint32(0) totalBytes := uint64(0) for _, stream := range stat.Streams { - totalPackets += (stream.TotalPrimaryPackets + stream.TotalRetransmitPackets + stream.TotalPaddingPackets) - totalBytes += (stream.TotalPrimaryBytes + stream.TotalRetransmitBytes + stream.TotalPaddingBytes) + totalPackets += stream.TotalPrimaryPackets + stream.TotalRetransmitPackets + stream.TotalPaddingPackets + totalBytes += stream.TotalPrimaryBytes + stream.TotalRetransmitBytes + stream.TotalPaddingBytes } prometheus.IncrementPackets(direction, uint64(totalPackets)) prometheus.IncrementBytes(direction, totalBytes) diff --git a/pkg/telemetry/telemetryserviceinternalevents.go b/pkg/telemetry/telemetryserviceinternalevents.go index aa44bf250..5cebd6fa5 100644 --- a/pkg/telemetry/telemetryserviceinternalevents.go +++ b/pkg/telemetry/telemetryserviceinternalevents.go @@ -4,11 +4,12 @@ import ( "context" "time" + "google.golang.org/protobuf/types/known/timestamppb" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/utils" "github.com/livekit/protocol/webhook" - "google.golang.org/protobuf/types/known/timestamppb" "github.com/livekit/livekit-server/pkg/telemetry/prometheus" ) diff --git a/pkg/telemetry/test/telemetry_service_events_test.go b/pkg/telemetry/test/telemetry_service_events_test.go index e8d0fed48..0fafce5d8 100644 --- a/pkg/telemetry/test/telemetry_service_events_test.go +++ b/pkg/telemetry/test/telemetry_service_events_test.go @@ -4,8 +4,9 @@ import ( "context" "testing" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + + "github.com/livekit/protocol/livekit" ) func Test_OnParticipantJoin_EventIsSent(t *testing.T) { diff --git a/pkg/telemetry/test/telemetry_service_test.go b/pkg/telemetry/test/telemetry_service_test.go index 130c7d1f2..2254030aa 100644 --- a/pkg/telemetry/test/telemetry_service_test.go +++ b/pkg/telemetry/test/telemetry_service_test.go @@ -4,9 +4,10 @@ import ( "context" "testing" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/telemetry" "github.com/livekit/livekit-server/pkg/telemetry/telemetryfakes" ) @@ -447,7 +448,7 @@ func Test_AnalyticsSentWhenParticipantLeaves(t *testing.T) { // do fixture.sut.ParticipantLeft(context.Background(), room, participantInfo) - // should not be called if there are not track stats + // should not be called if there are no track stats require.Equal(t, 0, fixture.analytics.SendStatsCallCount()) } @@ -482,7 +483,7 @@ func Test_AddUpTrack(t *testing.T) { require.Equal(t, 1, len(stats)) require.Equal(t, livekit.StreamType_UPSTREAM, stats[0].Kind) require.Equal(t, totalBytes, stats[0].Streams[0].TotalPrimaryBytes) - require.Equal(t, totalPackets, uint32(stats[0].Streams[0].TotalPrimaryPackets)) + require.Equal(t, totalPackets, stats[0].Streams[0].TotalPrimaryPackets) require.Equal(t, string(trackID), stats[0].TrackId) } diff --git a/test/client/client.go b/test/client/client.go index c8b294b3d..88421ff25 100644 --- a/test/client/client.go +++ b/test/client/client.go @@ -12,8 +12,6 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/rtcp" "github.com/pion/rtp" "github.com/pion/webrtc/v3" @@ -21,6 +19,9 @@ import ( "go.uber.org/atomic" "google.golang.org/protobuf/proto" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/rtc" ) diff --git a/test/integration_helpers.go b/test/integration_helpers.go index d1f5194ae..57490c3c2 100644 --- a/test/integration_helpers.go +++ b/test/integration_helpers.go @@ -9,11 +9,12 @@ import ( "time" "github.com/go-redis/redis/v8" + "github.com/twitchtv/twirp" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/utils" - "github.com/twitchtv/twirp" "github.com/livekit/livekit-server/pkg/config" serverlogger "github.com/livekit/livekit-server/pkg/logger" diff --git a/test/multinode_roomservice_test.go b/test/multinode_roomservice_test.go index a631a1f9e..dded4cb25 100644 --- a/test/multinode_roomservice_test.go +++ b/test/multinode_roomservice_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" - "github.com/livekit/protocol/livekit" "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" + "github.com/livekit/livekit-server/pkg/testutils" ) diff --git a/test/multinode_test.go b/test/multinode_test.go index 5250a83f7..2c2ba2ef6 100644 --- a/test/multinode_test.go +++ b/test/multinode_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" - "github.com/stretchr/testify/require" "github.com/livekit/livekit-server/pkg/rtc" "github.com/livekit/livekit-server/pkg/testutils" diff --git a/test/scenarios.go b/test/scenarios.go index e322fd34d..d02de1198 100644 --- a/test/scenarios.go +++ b/test/scenarios.go @@ -5,11 +5,12 @@ import ( "testing" "time" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/stretchr/testify/require" "go.uber.org/atomic" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/testutils" testclient "github.com/livekit/livekit-server/test/client" ) diff --git a/test/singlenode_test.go b/test/singlenode_test.go index 17dae069d..dea40dace 100644 --- a/test/singlenode_test.go +++ b/test/singlenode_test.go @@ -8,13 +8,14 @@ import ( "testing" "time" - "github.com/livekit/protocol/auth" - "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/logger" "github.com/pion/webrtc/v3" "github.com/stretchr/testify/require" "github.com/thoas/go-funk" + "github.com/livekit/protocol/auth" + "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/rtc" "github.com/livekit/livekit-server/pkg/testutils" diff --git a/test/webhook_test.go b/test/webhook_test.go index e0a69c020..fdd40b307 100644 --- a/test/webhook_test.go +++ b/test/webhook_test.go @@ -10,13 +10,14 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protojson" + "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/utils" "github.com/livekit/protocol/webhook" - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/encoding/protojson" "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing"