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