upgrade to pion/webrtc v4 (#3213)

This commit is contained in:
cnderrauber
2024-11-28 16:05:38 +08:00
committed by GitHub
parent baf47db834
commit 54f9f7de51
52 changed files with 144 additions and 119 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"time"
"github.com/mitchellh/go-homedir"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
+4
View File
@@ -101,6 +101,10 @@ func (c ClientInfo) SupportErrorResponse() bool {
return c.SupportTrackSubscribedEvent()
}
func (c ClientInfo) SupportSctpZeroChecksum() bool {
return !(c.isGo() && c.compareVersion("2.1.3") <= 0)
}
// compareVersion compares a semver against the current client SDK version
// returning 1 if current version is greater than version
// 0 if they are the same, and -1 if it's an earlier version
+3 -1
View File
@@ -16,7 +16,7 @@ package rtc
import (
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
@@ -70,6 +70,8 @@ func NewWebRTCConfig(conf *config.Config) (*WebRTCConfig, error) {
// we don't want to use active TCP on a server, clients should be dialing
webRTCConfig.SettingEngine.DisableActiveTCP(true)
webRTCConfig.SettingEngine.EnableSCTPZeroChecksum(true)
if rtcConf.PacketBufferSize == 0 {
rtcConf.PacketBufferSize = 500
}
+1 -1
View File
@@ -21,7 +21,7 @@ import (
"testing"
"time"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/rtc/types"
+1 -1
View File
@@ -18,7 +18,7 @@ import (
"fmt"
"strings"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/livekit-server/pkg/sfu"
"github.com/livekit/protocol/livekit"
+1 -1
View File
@@ -17,7 +17,7 @@ package rtc
import (
"testing"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"github.com/livekit/protocol/livekit"
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"time"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"github.com/livekit/protocol/livekit"
+1 -1
View File
@@ -23,7 +23,7 @@ import (
"sync"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"google.golang.org/protobuf/proto"
+1 -1
View File
@@ -20,7 +20,7 @@ import (
"sync"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
+9 -1
View File
@@ -27,7 +27,7 @@ import (
lru "github.com/hashicorp/golang-lru/v2"
"github.com/pion/rtcp"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/pkg/errors"
"go.uber.org/atomic"
"google.golang.org/protobuf/proto"
@@ -1458,6 +1458,10 @@ func (h AnyTransportHandler) OnFailed(_isShortLived bool, _ici *types.ICEConnect
h.p.onAnyTransportFailed()
}
func (h AnyTransportHandler) OnClosed() {
h.p.onAnyTransportClosed()
}
func (h AnyTransportHandler) OnNegotiationFailed() {
h.p.onAnyTransportNegotiationFailed()
}
@@ -2023,6 +2027,10 @@ func (p *ParticipantImpl) onAnyTransportFailed() {
p.setupDisconnectTimer()
}
func (p *ParticipantImpl) onAnyTransportClosed() {
_ = p.Close(false, types.ParticipantCloseReasonPeerConnectionDisconnected, false)
}
// subscriberRTCPWorker sends SenderReports periodically when the participant is subscribed to
// other publishedTracks in the room.
func (p *ParticipantImpl) subscriberRTCPWorker() {
+1 -1
View File
@@ -20,7 +20,7 @@ import (
"testing"
"time"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"google.golang.org/protobuf/proto"
+1 -1
View File
@@ -20,7 +20,7 @@ import (
"strings"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/protocol/livekit"
lksdp "github.com/livekit/protocol/sdp"
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"fmt"
"time"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"time"
"github.com/bep/debounce"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"google.golang.org/protobuf/proto"
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"sync"
"time"
"github.com/pion/webrtc/v3/pkg/rtcerr"
"github.com/pion/webrtc/v4/pkg/rtcerr"
"go.uber.org/atomic"
"golang.org/x/exp/maps"
+10 -7
View File
@@ -22,8 +22,8 @@ import (
"sync"
"time"
"github.com/pion/dtls/v2/pkg/crypto/elliptic"
"github.com/pion/ice/v2"
"github.com/pion/dtls/v3/pkg/crypto/elliptic"
"github.com/pion/ice/v4"
"github.com/pion/interceptor"
"github.com/pion/interceptor/pkg/cc"
"github.com/pion/interceptor/pkg/gcc"
@@ -31,7 +31,7 @@ import (
"github.com/pion/rtcp"
"github.com/pion/sctp"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/pkg/errors"
"go.uber.org/atomic"
"go.uber.org/zap/zapcore"
@@ -188,8 +188,6 @@ type PCTransport struct {
firstOfferReceived bool
firstOfferNoDataChannel bool
remoteICEIsLite *bool
localICEIsLite *bool
reliableDC *webrtc.DataChannel
reliableDCOpened bool
lossyDC *webrtc.DataChannel
@@ -650,9 +648,9 @@ func (t *PCTransport) setConnectedAt(at time.Time) bool {
return true
}
func (t *PCTransport) onICEGatheringStateChange(state webrtc.ICEGathererState) {
func (t *PCTransport) onICEGatheringStateChange(state webrtc.ICEGatheringState) {
t.params.Logger.Debugw("ice gathering state change", "state", state.String())
if state != webrtc.ICEGathererStateComplete {
if state != webrtc.ICEGatheringStateComplete {
return
}
@@ -706,6 +704,11 @@ func (t *PCTransport) onPeerConnectionStateChange(state webrtc.PeerConnectionSta
case webrtc.PeerConnectionStateFailed:
t.clearConnTimer()
t.handleConnectionFailed(false)
case webrtc.PeerConnectionStateClosed:
// peerconnection closed by client
if !t.isClosed.Load() {
t.params.Handler.OnClosed()
}
}
}
+2 -1
View File
@@ -17,7 +17,7 @@ package transport
import (
"errors"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
@@ -38,6 +38,7 @@ type Handler interface {
OnInitialConnected()
OnFullyEstablished()
OnFailed(isShortLived bool, iceConnectionInfo *types.ICEConnectionInfo)
OnClosed()
OnTrack(track *webrtc.TrackRemote, rtpReceiver *webrtc.RTPReceiver)
OnDataPacket(kind livekit.DataPacket_Kind, data []byte)
OnDataSendError(err error)
@@ -8,7 +8,7 @@ import (
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
"github.com/livekit/protocol/livekit"
webrtc "github.com/pion/webrtc/v3"
webrtc "github.com/pion/webrtc/v4"
)
type FakeHandler struct {
@@ -23,6 +23,10 @@ type FakeHandler struct {
onAnswerReturnsOnCall map[int]struct {
result1 error
}
OnClosedStub func()
onClosedMutex sync.RWMutex
onClosedArgsForCall []struct {
}
OnDataPacketStub func(livekit.DataPacket_Kind, []byte)
onDataPacketMutex sync.RWMutex
onDataPacketArgsForCall []struct {
@@ -162,6 +166,30 @@ func (fake *FakeHandler) OnAnswerReturnsOnCall(i int, result1 error) {
}{result1}
}
func (fake *FakeHandler) OnClosed() {
fake.onClosedMutex.Lock()
fake.onClosedArgsForCall = append(fake.onClosedArgsForCall, struct {
}{})
stub := fake.OnClosedStub
fake.recordInvocation("OnClosed", []interface{}{})
fake.onClosedMutex.Unlock()
if stub != nil {
fake.OnClosedStub()
}
}
func (fake *FakeHandler) OnClosedCallCount() int {
fake.onClosedMutex.RLock()
defer fake.onClosedMutex.RUnlock()
return len(fake.onClosedArgsForCall)
}
func (fake *FakeHandler) OnClosedCalls(stub func()) {
fake.onClosedMutex.Lock()
defer fake.onClosedMutex.Unlock()
fake.OnClosedStub = stub
}
func (fake *FakeHandler) OnDataPacket(arg1 livekit.DataPacket_Kind, arg2 []byte) {
var arg2Copy []byte
if arg2 != nil {
@@ -591,6 +619,8 @@ func (fake *FakeHandler) Invocations() map[string][][]interface{} {
defer fake.invocationsMutex.RUnlock()
fake.onAnswerMutex.RLock()
defer fake.onAnswerMutex.RUnlock()
fake.onClosedMutex.RLock()
defer fake.onClosedMutex.RUnlock()
fake.onDataPacketMutex.RLock()
defer fake.onDataPacketMutex.RUnlock()
fake.onDataSendErrorMutex.RLock()
+2 -2
View File
@@ -22,7 +22,7 @@ import (
"time"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
@@ -601,7 +601,7 @@ func TestConfigureAudioTransceiver(t *testing.T) {
{true, true},
} {
t.Run(fmt.Sprintf("nack=%v,stereo=%v", testcase.nack, testcase.stereo), func(t *testing.T) {
tr, err := pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, webrtc.RtpTransceiverInit{Direction: webrtc.RTPTransceiverDirectionSendonly})
tr, err := pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionSendonly})
require.NoError(t, err)
configureAudioTransceiver(tr, testcase.stereo, testcase.nack)
+1 -1
View File
@@ -23,7 +23,7 @@ import (
"github.com/pion/rtcp"
"github.com/pion/sctp"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/pkg/errors"
"go.uber.org/atomic"
"google.golang.org/protobuf/proto"
+2 -2
View File
@@ -21,8 +21,8 @@ import (
"strings"
"sync"
"github.com/pion/ice/v2"
"github.com/pion/webrtc/v3"
"github.com/pion/ice/v4"
"github.com/pion/webrtc/v4"
"golang.org/x/exp/slices"
"github.com/livekit/protocol/livekit"
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"time"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
@@ -15,7 +15,7 @@ import (
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils"
"github.com/pion/rtcp"
webrtc "github.com/pion/webrtc/v3"
webrtc "github.com/pion/webrtc/v4"
)
type FakeLocalParticipant struct {
@@ -7,7 +7,7 @@ import (
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/sfu"
"github.com/livekit/protocol/livekit"
webrtc "github.com/pion/webrtc/v3"
webrtc "github.com/pion/webrtc/v4"
)
type FakeSubscribedTrack struct {
+1 -1
View File
@@ -18,7 +18,7 @@ import (
"github.com/pion/interceptor"
"github.com/pion/rtp"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/livekit-server/pkg/sfu/utils"
)
+1 -1
View File
@@ -21,7 +21,7 @@ import (
"net"
"strings"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"strings"
"sync"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
+1 -1
View File
@@ -27,7 +27,7 @@ import (
"strconv"
"time"
"github.com/pion/turn/v2"
"github.com/pion/turn/v4"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/cors"
"github.com/twitchtv/twirp"
+1 -1
View File
@@ -23,7 +23,7 @@ import (
"strings"
"github.com/jxskiss/base62"
"github.com/pion/turn/v2"
"github.com/pion/turn/v4"
"github.com/pkg/errors"
"github.com/livekit/protocol/auth"
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"os"
"github.com/google/wire"
"github.com/pion/turn/v2"
"github.com/pion/turn/v4"
"github.com/pkg/errors"
"github.com/redis/go-redis/v9"
"gopkg.in/yaml.v3"
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"github.com/livekit/protocol/utils"
"github.com/livekit/protocol/webhook"
"github.com/livekit/psrpc"
"github.com/pion/turn/v2"
"github.com/pion/turn/v4"
"github.com/pkg/errors"
"github.com/redis/go-redis/v9"
"gopkg.in/yaml.v3"
+1 -1
View File
@@ -27,7 +27,7 @@ import (
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"github.com/livekit/livekit-server/pkg/sfu/audio"
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"github.com/livekit/mediatransportutil/pkg/nack"
+1 -1
View File
@@ -18,7 +18,7 @@ import (
"io"
"sync"
"github.com/pion/transport/v2/packetio"
"github.com/pion/transport/v3/packetio"
)
type FactoryOfBufferFactory struct {
+1 -1
View File
@@ -20,7 +20,7 @@ import (
"time"
"github.com/frostbyte73/core"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -19,7 +19,7 @@ import (
"testing"
"time"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
+2 -2
View File
@@ -27,8 +27,8 @@ import (
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/sdp/v3"
"github.com/pion/transport/v2/packetio"
"github.com/pion/webrtc/v3"
"github.com/pion/transport/v3/packetio"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"go.uber.org/zap/zapcore"
+1 -1
View File
@@ -24,7 +24,7 @@ import (
"time"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/zap/zapcore"
"github.com/livekit/mediatransportutil"
+1 -1
View File
@@ -17,7 +17,7 @@ package sfu
import (
"testing"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"github.com/livekit/protocol/logger"
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"github.com/pion/interceptor"
"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/livekit-server/pkg/sfu/utils"
"github.com/livekit/protocol/logger"
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"time"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
)
type Packet struct {
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"time"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"github.com/livekit/mediatransportutil/pkg/bucket"
+1 -1
View File
@@ -18,7 +18,7 @@ import (
"testing"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
+1 -1
View File
@@ -22,7 +22,7 @@ import (
"github.com/pion/interceptor/pkg/cc"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"go.uber.org/atomic"
"github.com/livekit/protocol/livekit"
+1 -1
View File
@@ -18,7 +18,7 @@ import (
"time"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
)
+1 -1
View File
@@ -21,7 +21,7 @@ import (
"github.com/pion/interceptor"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v4"
)
// Do a fuzzy find for a codec in the list of codecs
+1 -1
View File
@@ -17,7 +17,7 @@ package telemetry
import (
"net"
"github.com/pion/turn/v2"
"github.com/pion/turn/v4"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
)