Code inspection (#581)

* Code inspection

* fix [4]int64 conversiong
This commit is contained in:
David Colburn
2022-03-30 13:49:53 -07:00
committed by GitHub
parent 26f7bb498a
commit 0b8a180554
77 changed files with 228 additions and 151 deletions
+1 -1
View File
@@ -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
+2 -1
View File
@@ -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"
+2 -1
View File
@@ -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) {
@@ -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 {
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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
+3 -2
View File
@@ -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
+2 -1
View File
@@ -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 (
+4 -3
View File
@@ -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"
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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"
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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"
)
+3 -2
View File
@@ -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 {
+2 -1
View File
@@ -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 {
+2 -1
View File
@@ -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) {
+4 -4
View File
@@ -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
+4 -2
View File
@@ -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) {
+6 -4
View File
@@ -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
}
+3 -2
View File
@@ -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"
+11 -7
View File
@@ -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()))
+2 -1
View File
@@ -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"
+5 -3
View File
@@ -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 {
+4 -3
View File
@@ -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())
}
}
}
+3 -2
View File
@@ -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"
)
+2 -1
View File
@@ -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"
)
+4 -3
View File
@@ -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{}
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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"
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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) {
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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
+3 -2
View File
@@ -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"
)
+3 -2
View File
@@ -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 (
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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"
+3 -2
View File
@@ -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"
+3 -4
View File
@@ -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)
+4 -3
View File
@@ -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"
+3 -2
View File
@@ -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"
)
+1 -1
View File
@@ -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)
}
+4 -2
View File
@@ -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 (
+3 -2
View File
@@ -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(),
}
}
+2 -1
View File
@@ -5,8 +5,9 @@ import (
"errors"
"time"
"github.com/livekit/protocol/logger"
"github.com/pion/rtp/codecs"
"github.com/livekit/protocol/logger"
)
var (
+1 -1
View File
@@ -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
+12 -11
View File
@@ -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,
}
}
+5 -3
View File
@@ -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 (
+2 -2
View File
@@ -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 {
+6 -5
View File
@@ -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()
}
+3 -2
View File
@@ -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
}
+3 -2
View File
@@ -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)
+2 -1
View File
@@ -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 (
+2 -1
View File
@@ -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 {
+7 -6
View File
@@ -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 {
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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"
)
+5 -4
View File
@@ -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 {
+4 -3
View File
@@ -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]
}
+1 -1
View File
@@ -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()
}
+1
View File
@@ -2,6 +2,7 @@ package sfu
import (
"github.com/elliotchance/orderedmap"
"github.com/livekit/protocol/logger"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
+2 -1
View File
@@ -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"
)
+2 -2
View File
@@ -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 {
+5 -3
View File
@@ -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)
@@ -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"
)
@@ -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) {
+4 -3
View File
@@ -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)
}
+3 -2
View File
@@ -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"
)
+2 -1
View File
@@ -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"
+2 -1
View File
@@ -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"
)
+2 -1
View File
@@ -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"
+3 -2
View File
@@ -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"
)
+4 -3
View File
@@ -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"
+3 -2
View File
@@ -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"