github.com/pion/webrtc/v3@v3.2.24/rtpreceiver_go.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 "github.com/pion/interceptor"
    10  
    11  // SetRTPParameters applies provided RTPParameters the RTPReceiver's tracks.
    12  //
    13  // This method is part of the ORTC API. It is not
    14  // meant to be used together with the basic WebRTC API.
    15  //
    16  // The amount of provided codecs must match the number of tracks on the receiver.
    17  func (r *RTPReceiver) SetRTPParameters(params RTPParameters) {
    18  	headerExtensions := make([]interceptor.RTPHeaderExtension, 0, len(params.HeaderExtensions))
    19  	for _, h := range params.HeaderExtensions {
    20  		headerExtensions = append(headerExtensions, interceptor.RTPHeaderExtension{ID: h.ID, URI: h.URI})
    21  	}
    22  
    23  	r.mu.Lock()
    24  	defer r.mu.Unlock()
    25  
    26  	for ndx, codec := range params.Codecs {
    27  		currentTrack := r.tracks[ndx].track
    28  
    29  		r.tracks[ndx].streamInfo.RTPHeaderExtensions = headerExtensions
    30  
    31  		currentTrack.mu.Lock()
    32  		currentTrack.codec = codec
    33  		currentTrack.params = params
    34  		currentTrack.mu.Unlock()
    35  	}
    36  }