@@ -165,7 +165,8 @@ use crate::rtp_transceiver::direction::RTCRtpTransceiverDirection;
165165use crate :: rtp_transceiver:: rtp_sender:: rtp_codec:: { RTCRtpCodec , RtpCodecKind } ;
166166use crate :: rtp_transceiver:: rtp_sender:: rtp_codec_parameters:: RTCRtpCodecParameters ;
167167use crate :: rtp_transceiver:: {
168- PayloadType , RTCRtpTransceiver , RtpStreamId , SSRC , rtp_sender:: rtcp_parameters:: RTCPFeedback ,
168+ PayloadType , RtpStreamId , SSRC , internal:: RTCRtpTransceiverInternal ,
169+ rtp_sender:: rtcp_parameters:: RTCPFeedback ,
169170} ;
170171use ice:: candidate:: { Candidate , unmarshal_candidate} ;
171172use interceptor:: Interceptor ;
@@ -616,7 +617,7 @@ where
616617 mut d : SessionDescription ,
617618 dtls_fingerprints : & [ RTCDtlsFingerprint ] ,
618619 media_engine : & MediaEngine ,
619- transceivers : & mut [ RTCRtpTransceiver < I > ] ,
620+ transceivers : & mut [ RTCRtpTransceiverInternal < I > ] ,
620621 ice_params : & RTCIceParameters ,
621622 candidates : & [ RTCIceCandidate ] ,
622623 media_section : & MediaSection ,
@@ -820,7 +821,7 @@ where
820821 fn add_sender_sdp (
821822 mut media : MediaDescription ,
822823 media_engine : & MediaEngine ,
823- transceiver : & mut RTCRtpTransceiver < I > ,
824+ transceiver : & mut RTCRtpTransceiverInternal < I > ,
824825 write_ssrc_attributes_for_simulcast : bool ,
825826 ) -> ( MediaDescription , Vec < RtpStreamId > ) {
826827 let mut send_rids = vec ! [ ] ;
@@ -986,13 +987,59 @@ impl<I> RTCPeerConnection<I>
986987where
987988 I : Interceptor ,
988989{
990+ pub ( crate ) fn find_by_mid (
991+ mid : & String ,
992+ local_transceivers : & [ RTCRtpTransceiverInternal < I > ] ,
993+ ) -> Option < usize > {
994+ local_transceivers
995+ . iter ( )
996+ . enumerate ( )
997+ . find ( |( _i, t) | t. mid ( ) . as_ref ( ) == Some ( mid) )
998+ . map ( |( i, _v) | i)
999+ }
1000+
1001+ /// Given a direction+type pluck a transceiver from the passed list
1002+ /// if no entry satisfies the requested type+direction return a inactive Transceiver
1003+ pub ( crate ) fn satisfy_type_and_direction (
1004+ remote_kind : RtpCodecKind ,
1005+ remote_direction : RTCRtpTransceiverDirection ,
1006+ local_transceivers : & mut [ RTCRtpTransceiverInternal < I > ] ,
1007+ ) -> Option < & mut RTCRtpTransceiverInternal < I > > {
1008+ // Get direction order from most preferred to least
1009+ let get_preferred_directions = || -> Vec < RTCRtpTransceiverDirection > {
1010+ match remote_direction {
1011+ RTCRtpTransceiverDirection :: Sendrecv => vec ! [
1012+ RTCRtpTransceiverDirection :: Recvonly ,
1013+ RTCRtpTransceiverDirection :: Sendrecv ,
1014+ ] ,
1015+ RTCRtpTransceiverDirection :: Sendonly => vec ! [ RTCRtpTransceiverDirection :: Recvonly ] ,
1016+ RTCRtpTransceiverDirection :: Recvonly => vec ! [
1017+ RTCRtpTransceiverDirection :: Sendonly ,
1018+ RTCRtpTransceiverDirection :: Sendrecv ,
1019+ ] ,
1020+ _ => vec ! [ ] ,
1021+ }
1022+ } ;
1023+
1024+ for possible_direction in get_preferred_directions ( ) {
1025+ // Find the index first to avoid multiple mutable borrows
1026+ if let Some ( index) = local_transceivers. iter ( ) . position ( |t| {
1027+ t. mid ( ) . is_none ( ) && t. kind ( ) == remote_kind && possible_direction == t. direction ( )
1028+ } ) {
1029+ return Some ( & mut local_transceivers[ index] ) ;
1030+ }
1031+ }
1032+
1033+ None
1034+ }
1035+
9891036 /// populate_sdp serializes a PeerConnections state into an SDP
9901037 #[ allow( clippy:: too_many_arguments) ]
9911038 pub ( crate ) fn populate_sdp (
9921039 mut d : SessionDescription ,
9931040 dtls_fingerprints : & [ RTCDtlsFingerprint ] ,
9941041 media_engine : & MediaEngine ,
995- transceivers : & mut [ RTCRtpTransceiver < I > ] ,
1042+ transceivers : & mut [ RTCRtpTransceiverInternal < I > ] ,
9961043 candidates : & [ RTCIceCandidate ] ,
9971044 ice_params : & RTCIceParameters ,
9981045 media_sections : & [ MediaSection ] ,
0 commit comments