Skip to content

Commit 106c5e7

Browse files
committed
rename RTCRtpTransceiver to RTCRtpTransceiverInternal
1 parent f85aed8 commit 106c5e7

File tree

8 files changed

+451
-440
lines changed

8 files changed

+451
-440
lines changed

rtc/src/peer_connection/handler/endpoint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::peer_connection::configuration::media_engine::MediaEngine;
1212
use crate::peer_connection::event::track_event::{RTCTrackEvent, RTCTrackEventInit};
1313
use crate::rtp_transceiver::rtp_receiver::internal::RTCRtpReceiverInternal;
1414
use crate::rtp_transceiver::rtp_sender::{RTCRtpCodingParameters, RTCRtpHeaderExtensionCapability};
15-
use crate::rtp_transceiver::{RTCRtpReceiverId, RTCRtpTransceiver, SSRC};
15+
use crate::rtp_transceiver::{RTCRtpReceiverId, SSRC, internal::RTCRtpTransceiverInternal};
1616
use crate::statistics::accumulator::RTCStatsAccumulator;
1717
use interceptor::{Interceptor, Packet};
1818
use log::{debug, trace, warn};
@@ -36,7 +36,7 @@ where
3636
I: Interceptor,
3737
{
3838
ctx: &'a mut EndpointHandlerContext,
39-
rtp_transceivers: &'a mut Vec<RTCRtpTransceiver<I>>,
39+
rtp_transceivers: &'a mut Vec<RTCRtpTransceiverInternal<I>>,
4040
media_engine: &'a MediaEngine,
4141
interceptor: &'a mut I,
4242
stats: &'a mut RTCStatsAccumulator,
@@ -48,7 +48,7 @@ where
4848
{
4949
pub(crate) fn new(
5050
ctx: &'a mut EndpointHandlerContext,
51-
rtp_transceivers: &'a mut Vec<RTCRtpTransceiver<I>>,
51+
rtp_transceivers: &'a mut Vec<RTCRtpTransceiverInternal<I>>,
5252
media_engine: &'a MediaEngine,
5353
interceptor: &'a mut I,
5454
stats: &'a mut RTCStatsAccumulator,

rtc/src/peer_connection/internal.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ where
582582
/// add_rtp_transceiver appends t into rtp_transceivers
583583
/// and fires onNegotiationNeeded;
584584
/// caller of this method should hold `self.mu` lock
585-
pub(super) fn add_rtp_transceiver(&mut self, t: RTCRtpTransceiver<I>) -> RTCRtpTransceiverId {
585+
pub(super) fn add_rtp_transceiver(
586+
&mut self,
587+
t: RTCRtpTransceiverInternal<I>,
588+
) -> RTCRtpTransceiverId {
586589
self.rtp_transceivers.push(t);
587590
self.trigger_negotiation_needed();
588591
self.rtp_transceivers.len() - 1
@@ -1001,14 +1004,18 @@ where
10011004
&self,
10021005
track: MediaStreamTrack,
10031006
mut init: RTCRtpTransceiverInit,
1004-
) -> Result<RTCRtpTransceiver<I>> {
1007+
) -> Result<RTCRtpTransceiverInternal<I>> {
10051008
if init.direction == RTCRtpTransceiverDirection::Unspecified {
10061009
Err(Error::ErrPeerConnAddTransceiverFromTrackSupport)
10071010
} else {
10081011
if init.send_encodings.is_empty() {
10091012
init.send_encodings = self.send_encodings_from_track(&track);
10101013
}
1011-
Ok(RTCRtpTransceiver::new(track.kind(), Some(track), init))
1014+
Ok(RTCRtpTransceiverInternal::new(
1015+
track.kind(),
1016+
Some(track),
1017+
init,
1018+
))
10121019
}
10131020
}
10141021

rtc/src/peer_connection/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ use crate::rtp_transceiver::rtp_sender::{
295295
RTCRtpCodingParameters, RTCRtpEncodingParameters, RTCRtpSender,
296296
};
297297
use crate::rtp_transceiver::{
298-
RTCRtpReceiverId, RTCRtpSenderId, RTCRtpTransceiver, RTCRtpTransceiverId, RTCRtpTransceiverInit,
298+
RTCRtpReceiverId, RTCRtpSenderId, RTCRtpTransceiverId, RTCRtpTransceiverInit,
299+
internal::RTCRtpTransceiverInternal,
299300
};
300301
use crate::statistics::StatsSelector;
301302
use crate::statistics::accumulator::RTCStatsAccumulator;
@@ -656,7 +657,7 @@ where
656657
//////////////////////////////////////////////////
657658
pub(crate) pipeline_context: PipelineContext,
658659
pub(crate) data_channels: HashMap<RTCDataChannelId, RTCDataChannelInternal>,
659-
pub(super) rtp_transceivers: Vec<RTCRtpTransceiver<I>>,
660+
pub(super) rtp_transceivers: Vec<RTCRtpTransceiverInternal<I>>,
660661

661662
greater_mid: isize,
662663
sdp_origin: Origin,
@@ -1382,7 +1383,7 @@ where
13821383
RTCRtpTransceiverDirection::Recvonly
13831384
};
13841385

1385-
let mut transceiver = RTCRtpTransceiver::new(
1386+
let mut transceiver = RTCRtpTransceiverInternal::new(
13861387
kind,
13871388
None,
13881389
RTCRtpTransceiverInit {
@@ -2094,7 +2095,7 @@ where
20942095
return Err(Error::ErrRTPSenderNoBaseEncoding);
20952096
}
20962097
}
2097-
RTCRtpTransceiverDirection::Recvonly => RTCRtpTransceiver::new(
2098+
RTCRtpTransceiverDirection::Recvonly => RTCRtpTransceiverInternal::new(
20982099
kind,
20992100
None,
21002101
RTCRtpTransceiverInit {

rtc/src/peer_connection/sdp/mod.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ use crate::rtp_transceiver::direction::RTCRtpTransceiverDirection;
165165
use crate::rtp_transceiver::rtp_sender::rtp_codec::{RTCRtpCodec, RtpCodecKind};
166166
use crate::rtp_transceiver::rtp_sender::rtp_codec_parameters::RTCRtpCodecParameters;
167167
use 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
};
170171
use ice::candidate::{Candidate, unmarshal_candidate};
171172
use 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>
986987
where
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

Comments
 (0)