Skip to content

Commit ec670b4

Browse files
committed
Re-instate changes from webrtc-rs#217
1 parent 9fdf70b commit ec670b4

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

webrtc/src/peer_connection/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,12 @@ impl RTCPeerConnection {
466466
if let Some(m) = m {
467467
// Step 5.3.1
468468
if t.direction().has_send() {
469-
let _dmsid = match m.attribute(ATTR_KEY_MSID).and_then(|o| o) {
469+
let dmsid = match m.attribute(ATTR_KEY_MSID).and_then(|o| o) {
470470
Some(m) => m,
471471
None => return true, // doesn't contain a single a=msid line
472472
};
473473

474-
let _sender = match t.sender().await {
474+
let sender = match t.sender().await {
475475
Some(s) => s,
476476
None => {
477477
log::warn!(
@@ -490,17 +490,15 @@ impl RTCPeerConnection {
490490
// local description so we can compare all of them. For no we only
491491
// consider the first one.
492492

493-
// TODO: Go and see what Pion does these days here
494-
// let stream_ids = sender.associated_media_stream_ids();
495-
// // Different number of lines, 1 vs 0
496-
// if stream_ids.is_empty() {
497-
return true;
498-
// }
499-
493+
let stream_ids = sender.associated_media_stream_ids();
494+
// Different number of lines, 1 vs 0
495+
if stream_ids.is_empty() {
496+
return true;
497+
}
500498
// different stream id
501-
// if dmsid.split_whitespace().next() != Some(&stream_ids[0]) {
502-
// return true;
503-
// }
499+
if dmsid.split_whitespace().next() != Some(&stream_ids[0]) {
500+
return true;
501+
}
504502
}
505503
match local_desc.sdp_type {
506504
RTCSdpType::Offer => {

webrtc/src/peer_connection/sdp/mod.rs

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -545,33 +545,17 @@ pub(crate) async fn add_transceiver_sdp(
545545
if let Some(sender) = mt.sender().await {
546546
let send_parameters = sender.get_parameters().await;
547547
if let Some(track) = sender.track().await {
548+
// Get the different encodings expressed first
548549
for encoding in send_parameters.encodings.iter() {
549550
media = media.with_media_source(
550551
encoding.ssrc,
551552
track.stream_id().to_owned(), /* cname */
552553
track.stream_id().to_owned(), /* streamLabel */
553554
track.id().to_owned(),
554555
);
555-
556-
// Send msid based on the configured track if we haven't already
557-
// sent on this sender. If we have sent we must keep the msid line consistent, this
558-
// is handled below.
559-
if !is_plan_b {
560-
// We need this?
561-
// related streams don't exist any more in pion (and nor should they?)
562-
563-
// I this should become obsolete
564-
if sender.initial_track_id().is_none() {
565-
media = media.with_property_attribute(format!(
566-
"msid:{} {}",
567-
track.stream_id(),
568-
track.id()
569-
));
570-
sender.set_initial_track_id(track.id().to_string())?;
571-
}
572-
}
573556
}
574557

558+
// Then tell the world about simulcast
575559
if send_parameters.encodings.len() > 1 {
576560
let mut send_rids: Vec<String> = vec![];
577561

@@ -586,10 +570,43 @@ pub(crate) async fn add_transceiver_sdp(
586570
s.push_str(send_rids.join(";").as_ref());
587571
media = media.with_value_attribute("simulcast".into(), s);
588572
}
573+
// Send msid based on the configured track if we haven't already
574+
// sent on this sender. If we have sent we must keep the msid line consistent, this
575+
// is handled below.
576+
// And now when we 'break', the above will have been printed properly still?
577+
if !is_plan_b && sender.initial_track_id().is_none() {
578+
for stream_id in sender.associated_media_stream_ids() {
579+
media = media.with_property_attribute(format!(
580+
"msid:{} {}",
581+
stream_id,
582+
track.id()
583+
));
584+
}
585+
sender.set_initial_track_id(track.id().to_string())?;
586+
break;
587+
}
588+
}
589+
if !is_plan_b {
590+
if let Some(track_id) = sender.initial_track_id() {
591+
// After we have include an msid attribute in an offer it must stay the same for
592+
// all subsequent offer even if the track or transceiver direction changes.
593+
//
594+
// [RFC 8829 Section 5.2.2](https://datatracker.ietf.org/doc/html/rfc8829#section-5.2.2)
595+
//
596+
// For RtpTransceivers that are not stopped, the "a=msid" line or
597+
// lines MUST stay the same if they are present in the current
598+
// description, regardless of changes to the transceiver's direction
599+
// or track. If no "a=msid" line is present in the current
600+
// description, "a=msid" line(s) MUST be generated according to the
601+
// same rules as for an initial offer.
602+
for stream_id in sender.associated_media_stream_ids() {
603+
media = media
604+
.with_property_attribute(format!("msid:{} {}", stream_id, track_id));
605+
}
606+
607+
break;
608+
}
589609
}
590-
}
591-
if !is_plan_b {
592-
break;
593610
}
594611
}
595612

webrtc/src/rtp_transceiver/rtp_sender/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ pub struct RTCRtpSender {
108108
/// track id should be use when negotiating.
109109
pub(crate) initial_track_id: std::sync::Mutex<Option<String>>,
110110

111+
/// AssociatedMediaStreamIds from the WebRTC specifcations
112+
pub(crate) associated_media_stream_ids: std::sync::Mutex<Vec<String>>,
113+
111114
rtp_transceiver: Mutex<Option<Weak<RTCRtpTransceiver>>>,
112115

113116
send_called_tx: Mutex<Option<mpsc::Sender<()>>>,
@@ -144,6 +147,7 @@ impl RTCRtpSender {
144147
let stop_called_tx = Arc::new(Notify::new());
145148
let stop_called_rx = stop_called_tx.clone();
146149
let stop_called_signal = Arc::new(AtomicBool::new(false));
150+
let stream_ids = vec![track.stream_id().to_string()];
147151

148152
let internal = Arc::new(RTPSenderInternal {
149153
send_called_rx: Mutex::new(send_called_rx),
@@ -165,6 +169,7 @@ impl RTCRtpSender {
165169

166170
id,
167171
initial_track_id: std::sync::Mutex::new(None),
172+
associated_media_stream_ids: std::sync::Mutex::new(stream_ids),
168173
kind: track.kind(),
169174

170175
rtp_transceiver: Mutex::new(None),
@@ -627,6 +632,12 @@ impl RTCRtpSender {
627632
lock.clone()
628633
}
629634

635+
pub(crate) fn associated_media_stream_ids(&self) -> Vec<String> {
636+
let lock = self.associated_media_stream_ids.lock().unwrap();
637+
638+
lock.clone()
639+
}
640+
630641
pub(crate) fn set_initial_track_id(&self, id: String) -> Result<()> {
631642
let mut lock = self.initial_track_id.lock().unwrap();
632643

0 commit comments

Comments
 (0)