mirror of
https://github.com/pion/webrtc.git
synced 2025-12-24 11:51:03 +08:00
@@ -9,7 +9,6 @@ linters:
|
||||
disable:
|
||||
- maligned
|
||||
- lll
|
||||
- gochecknoglobals
|
||||
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
|
||||
@@ -42,6 +42,8 @@ type DTLSTransport struct {
|
||||
srtpEndpoint *mux.Endpoint
|
||||
srtcpEndpoint *mux.Endpoint
|
||||
|
||||
dtlsMatcher mux.MatchFunc
|
||||
|
||||
api *API
|
||||
}
|
||||
|
||||
@@ -53,6 +55,7 @@ func (api *API) NewDTLSTransport(transport *ICETransport, certificates []Certifi
|
||||
iceTransport: transport,
|
||||
api: api,
|
||||
state: DTLSTransportStateNew,
|
||||
dtlsMatcher: mux.MatchDTLS,
|
||||
}
|
||||
|
||||
if len(certificates) > 0 {
|
||||
|
||||
@@ -11,14 +11,6 @@ import (
|
||||
"github.com/pion/webrtc/v2/examples/internal/signal"
|
||||
)
|
||||
|
||||
var peerConnectionConfig = webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const (
|
||||
rtcpPLIInterval = time.Second * 3
|
||||
)
|
||||
@@ -41,6 +33,14 @@ func main() {
|
||||
signal.Decode(<-sdpChan, &offer)
|
||||
fmt.Println("")
|
||||
|
||||
peerConnectionConfig := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := api.NewPeerConnection(peerConnectionConfig)
|
||||
if err != nil {
|
||||
|
||||
@@ -119,7 +119,7 @@ func (g *ICEGatherer) createAgent() error {
|
||||
|
||||
requestedNetworkTypes := g.networkTypes
|
||||
if len(requestedNetworkTypes) == 0 {
|
||||
requestedNetworkTypes = supportedNetworkTypes
|
||||
requestedNetworkTypes = supportedNetworkTypes()
|
||||
}
|
||||
|
||||
for _, typ := range requestedNetworkTypes {
|
||||
|
||||
@@ -57,7 +57,9 @@ func MatchZRTP(b []byte) bool {
|
||||
|
||||
// MatchDTLS is a MatchFunc that accepts packets with the first byte in [20..63]
|
||||
// as defied in RFC7983
|
||||
var MatchDTLS = MatchRange(20, 63)
|
||||
func MatchDTLS(b []byte) bool {
|
||||
return MatchRange(20, 63)(b)
|
||||
}
|
||||
|
||||
// MatchTURN is a MatchFunc that accepts packets with the first byte in [64..79]
|
||||
// as defied in RFC7983
|
||||
|
||||
@@ -6,11 +6,13 @@ import (
|
||||
"github.com/pion/ice"
|
||||
)
|
||||
|
||||
var supportedNetworkTypes = []NetworkType{
|
||||
NetworkTypeUDP4,
|
||||
NetworkTypeUDP6,
|
||||
// NetworkTypeTCP4, // Not supported yet
|
||||
// NetworkTypeTCP6, // Not supported yet
|
||||
func supportedNetworkTypes() []NetworkType {
|
||||
return []NetworkType{
|
||||
NetworkTypeUDP4,
|
||||
NetworkTypeUDP6,
|
||||
// NetworkTypeTCP4, // Not supported yet
|
||||
// NetworkTypeTCP6, // Not supported yet
|
||||
}
|
||||
}
|
||||
|
||||
// NetworkType represents the type of network
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
|
||||
"github.com/pion/ice"
|
||||
"github.com/pion/transport/test"
|
||||
"github.com/pion/webrtc/v2/internal/mux"
|
||||
"github.com/pion/webrtc/v2/pkg/rtcerr"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -300,15 +299,6 @@ func TestPeerConnection_EventHandlers_Go(t *testing.T) {
|
||||
// This test asserts that nothing deadlocks we try to shutdown when DTLS is in flight
|
||||
// We ensure that DTLS is in flight by removing the mux func for it, so all inbound DTLS is lost
|
||||
func TestPeerConnection_ShutdownNoDTLS(t *testing.T) {
|
||||
dtlsMatchFunc := mux.MatchDTLS
|
||||
defer func() {
|
||||
mux.MatchDTLS = dtlsMatchFunc
|
||||
}()
|
||||
|
||||
// Drop all incoming DTLS traffic
|
||||
mux.MatchDTLS = func([]byte) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
lim := test.TimeOut(time.Second * 10)
|
||||
defer lim.Stop()
|
||||
@@ -319,6 +309,13 @@ func TestPeerConnection_ShutdownNoDTLS(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Drop all incoming DTLS traffic
|
||||
dropAllDTLS := func([]byte) bool {
|
||||
return false
|
||||
}
|
||||
offerPC.dtlsTransport.dtlsMatcher = dropAllDTLS
|
||||
answerPC.dtlsTransport.dtlsMatcher = dropAllDTLS
|
||||
|
||||
if err = signalPair(offerPC, answerPC); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// The file starts with #!rtpplay1.0 address/port\n
|
||||
var preambleRegexp = regexp.MustCompile(`#\!rtpplay1\.0 \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,5}\n`)
|
||||
|
||||
// Reader reads the RTPDump file format
|
||||
type Reader struct {
|
||||
readerMu sync.Mutex
|
||||
@@ -31,6 +28,9 @@ func NewReader(r io.Reader) (*Reader, Header, error) {
|
||||
if err != nil {
|
||||
return nil, hdr, err
|
||||
}
|
||||
|
||||
// The file starts with #!rtpplay1.0 address/port\n
|
||||
var preambleRegexp = regexp.MustCompile(`#\!rtpplay1\.0 \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,5}\n`)
|
||||
if !preambleRegexp.Match(peek) {
|
||||
return nil, hdr, errMalformed
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var validPreamble = []byte("#!rtpplay1.0 224.2.0.1/3456\n")
|
||||
|
||||
func TestReader(t *testing.T) {
|
||||
validPreamble := []byte("#!rtpplay1.0 224.2.0.1/3456\n")
|
||||
|
||||
for _, test := range []struct {
|
||||
Name string
|
||||
Data []byte
|
||||
|
||||
@@ -22,74 +22,72 @@ func (f *fakeDepacketizer) Unmarshal(r []byte) ([]byte, error) {
|
||||
return r, nil
|
||||
}
|
||||
|
||||
var testCases = []sampleBuilderTest{
|
||||
{
|
||||
message: "SampleBuilder shouldn't emit anything if only one RTP packet has been pushed",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
},
|
||||
samples: []*media.Sample{},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder should emit one packet, we had three packets with unique timestamps",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 7}, Payload: []byte{0x03}},
|
||||
},
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder should emit one packet, we had two packets but two with duplicate timestamps",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 6}, Payload: []byte{0x03}},
|
||||
{Header: rtp.Header{SequenceNumber: 5003, Timestamp: 7}, Payload: []byte{0x04}},
|
||||
},
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02, 0x03}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder shouldn't emit a packet because we have a gap before a valid one",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5007, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5008, Timestamp: 7}, Payload: []byte{0x03}},
|
||||
},
|
||||
samples: []*media.Sample{},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder should emit multiple valid packets",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 1}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 2}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 3}, Payload: []byte{0x03}},
|
||||
{Header: rtp.Header{SequenceNumber: 5003, Timestamp: 4}, Payload: []byte{0x04}},
|
||||
{Header: rtp.Header{SequenceNumber: 5004, Timestamp: 5}, Payload: []byte{0x05}},
|
||||
{Header: rtp.Header{SequenceNumber: 5005, Timestamp: 6}, Payload: []byte{0x06}},
|
||||
},
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02}, Samples: 1},
|
||||
{Data: []byte{0x03}, Samples: 1},
|
||||
{Data: []byte{0x04}, Samples: 1},
|
||||
{Data: []byte{0x05}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
},
|
||||
}
|
||||
|
||||
func TestSampleBuilder(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
for _, t := range testCases {
|
||||
for _, t := range []sampleBuilderTest{
|
||||
{
|
||||
message: "SampleBuilder shouldn't emit anything if only one RTP packet has been pushed",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
},
|
||||
samples: []*media.Sample{},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder should emit one packet, we had three packets with unique timestamps",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 7}, Payload: []byte{0x03}},
|
||||
},
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder should emit one packet, we had two packets but two with duplicate timestamps",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 6}, Payload: []byte{0x03}},
|
||||
{Header: rtp.Header{SequenceNumber: 5003, Timestamp: 7}, Payload: []byte{0x04}},
|
||||
},
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02, 0x03}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder shouldn't emit a packet because we have a gap before a valid one",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5007, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5008, Timestamp: 7}, Payload: []byte{0x03}},
|
||||
},
|
||||
samples: []*media.Sample{},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
message: "SampleBuilder should emit multiple valid packets",
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 1}, Payload: []byte{0x01}},
|
||||
{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 2}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 3}, Payload: []byte{0x03}},
|
||||
{Header: rtp.Header{SequenceNumber: 5003, Timestamp: 4}, Payload: []byte{0x04}},
|
||||
{Header: rtp.Header{SequenceNumber: 5004, Timestamp: 5}, Payload: []byte{0x05}},
|
||||
{Header: rtp.Header{SequenceNumber: 5005, Timestamp: 6}, Payload: []byte{0x06}},
|
||||
},
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02}, Samples: 1},
|
||||
{Data: []byte{0x03}, Samples: 1},
|
||||
{Data: []byte{0x04}, Samples: 1},
|
||||
{Data: []byte{0x05}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
},
|
||||
} {
|
||||
s := New(t.maxLate, &fakeDepacketizer{})
|
||||
samples := []*media.Sample{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user