github.com/pion/webrtc/v3@v3.2.24/rtpreceiver_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/webrtc/v3/pkg/media" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func TestSetRTPParameters(t *testing.T) { 19 sender, receiver, wan := createVNetPair(t) 20 21 outgoingTrack, err := NewTrackLocalStaticSample(RTPCodecCapability{MimeType: MimeTypeVP8}, "video", "pion") 22 assert.NoError(t, err) 23 24 _, err = sender.AddTrack(outgoingTrack) 25 assert.NoError(t, err) 26 27 // Those parameters wouldn't make sense in a real application, 28 // but for the sake of the test we just need different values. 29 p := RTPParameters{ 30 Codecs: []RTPCodecParameters{ 31 { 32 RTPCodecCapability: RTPCodecCapability{MimeTypeOpus, 48000, 2, "minptime=10;useinbandfec=1", []RTCPFeedback{{"nack", ""}}}, 33 PayloadType: 111, 34 }, 35 }, 36 HeaderExtensions: []RTPHeaderExtensionParameter{ 37 {URI: "urn:ietf:params:rtp-hdrext:sdes:mid"}, 38 {URI: "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"}, 39 {URI: "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"}, 40 }, 41 } 42 43 seenPacket, seenPacketCancel := context.WithCancel(context.Background()) 44 receiver.OnTrack(func(trackRemote *TrackRemote, r *RTPReceiver) { 45 r.SetRTPParameters(p) 46 47 incomingTrackCodecs := r.Track().Codec() 48 49 assert.EqualValues(t, p.HeaderExtensions, r.Track().params.HeaderExtensions) 50 51 assert.EqualValues(t, p.Codecs[0].MimeType, incomingTrackCodecs.MimeType) 52 assert.EqualValues(t, p.Codecs[0].ClockRate, incomingTrackCodecs.ClockRate) 53 assert.EqualValues(t, p.Codecs[0].Channels, incomingTrackCodecs.Channels) 54 assert.EqualValues(t, p.Codecs[0].SDPFmtpLine, incomingTrackCodecs.SDPFmtpLine) 55 assert.EqualValues(t, p.Codecs[0].RTCPFeedback, incomingTrackCodecs.RTCPFeedback) 56 assert.EqualValues(t, p.Codecs[0].PayloadType, incomingTrackCodecs.PayloadType) 57 58 seenPacketCancel() 59 }) 60 61 peerConnectionsConnected := untilConnectionState(PeerConnectionStateConnected, sender, receiver) 62 63 assert.NoError(t, signalPair(sender, receiver)) 64 65 peerConnectionsConnected.Wait() 66 assert.NoError(t, outgoingTrack.WriteSample(media.Sample{Data: []byte{0xAA}, Duration: time.Second})) 67 68 <-seenPacket.Done() 69 assert.NoError(t, wan.Stop()) 70 closePairNow(t, sender, receiver) 71 }