github.com/pion/webrtc/v4@v4.0.1/rtptransceiverinit_go_test.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 //go:build !js 5 // +build !js 6 7 package webrtc 8 9 import ( 10 "context" 11 "testing" 12 "time" 13 14 "github.com/pion/transport/v3/test" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func Test_RTPTransceiverInit_SSRC(t *testing.T) { 19 lim := test.TimeOut(time.Second * 30) //nolint 20 defer lim.Stop() 21 22 report := test.CheckRoutines(t) 23 defer report() 24 25 track, err := NewTrackLocalStaticSample(RTPCodecCapability{MimeType: MimeTypeOpus}, "a", "b") 26 assert.NoError(t, err) 27 28 t.Run("SSRC of 0 is ignored", func(t *testing.T) { 29 offerer, answerer, err := newPair() 30 assert.NoError(t, err) 31 32 ctx, cancel := context.WithCancel(context.Background()) 33 answerer.OnTrack(func(track *TrackRemote, _ *RTPReceiver) { 34 assert.NotEqual(t, 0, track.SSRC()) 35 cancel() 36 }) 37 38 _, err = offerer.AddTransceiverFromTrack(track, RTPTransceiverInit{ 39 Direction: RTPTransceiverDirectionSendonly, 40 SendEncodings: []RTPEncodingParameters{ 41 { 42 RTPCodingParameters: RTPCodingParameters{ 43 SSRC: 0, 44 }, 45 }, 46 }, 47 }) 48 assert.NoError(t, err) 49 assert.NoError(t, signalPair(offerer, answerer)) 50 sendVideoUntilDone(ctx.Done(), t, []*TrackLocalStaticSample{track}) 51 closePairNow(t, offerer, answerer) 52 }) 53 54 t.Run("SSRC of 5000", func(t *testing.T) { 55 offerer, answerer, err := newPair() 56 assert.NoError(t, err) 57 58 ctx, cancel := context.WithCancel(context.Background()) 59 answerer.OnTrack(func(track *TrackRemote, _ *RTPReceiver) { 60 assert.NotEqual(t, 5000, track.SSRC()) 61 cancel() 62 }) 63 64 _, err = offerer.AddTransceiverFromTrack(track, RTPTransceiverInit{ 65 Direction: RTPTransceiverDirectionSendonly, 66 SendEncodings: []RTPEncodingParameters{ 67 { 68 RTPCodingParameters: RTPCodingParameters{ 69 SSRC: 5000, 70 }, 71 }, 72 }, 73 }) 74 assert.NoError(t, err) 75 assert.NoError(t, signalPair(offerer, answerer)) 76 sendVideoUntilDone(ctx.Done(), t, []*TrackLocalStaticSample{track}) 77 closePairNow(t, offerer, answerer) 78 }) 79 }