Skip to content

Commit 38eddfe

Browse files
Don't follow the specification
Match libWebrtc's behaviour which doesn't update `transcevier.[[Direction]]` instead of following the specification. See: https://webrtc.googlesource.com/src/+/c501f30333ce8b46a92b75a6bf75733ddb0e9741/pc/sdp_offer_answer.cc#2018
1 parent 1ff16fd commit 38eddfe

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/peer_connection/mod.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ impl RTCPeerConnection {
14371437

14381438
if we_offer {
14391439
// WebRTC Spec 1.0 https://www.w3.org/TR/webrtc/
1440-
// Section 4.4.1.5
1440+
// 4.5.9.2
14411441
// This is an answer from the remote.
14421442
if let Some(parsed) = remote_description.as_ref().and_then(|r| r.parsed.as_ref()) {
14431443
for media in &parsed.media_descriptions {
@@ -1466,17 +1466,19 @@ impl RTCPeerConnection {
14661466
if let Some(t) = find_by_mid(mid_value, &mut local_transceivers).await {
14671467
let previous_direction = t.direction();
14681468

1469-
// 4.9.2.9
1469+
// 4.5.9.2.9
14701470
// Let direction be an RTCRtpTransceiverDirection value representing the direction
14711471
// from the media description, but with the send and receive directions reversed to
14721472
// represent this peer's point of view. If the media description is rejected,
14731473
// set direction to "inactive".
14741474
let reversed_direction = direction.reverse();
14751475

1476-
// 4.9.2.13.2
1476+
// 4.5.9.2.13.2
14771477
// Set transceiver.[[CurrentDirection]] and transceiver.[[Direction]]s to direction.
1478-
t.set_direction_internal(reversed_direction);
14791478
t.set_current_direction(reversed_direction);
1479+
// TODO: According to the specification we should set
1480+
// transceiver.[[Direction]] here, however libWebrtc doesn't do this.
1481+
// t.set_direction_internal(reversed_direction);
14801482
t.process_new_current_direction(previous_direction).await?;
14811483
}
14821484
}
@@ -1766,18 +1768,24 @@ impl RTCPeerConnection {
17661768
}
17671769
}
17681770

1769-
if let Some(t) = transceiver {
1770-
let sender_result = sender.stop().await;
1771-
// This also updates direction
1772-
let sending_track_result = t.set_sending_track(None).await;
1771+
let t = transceiver.ok_or(Error::ErrSenderNotCreatedByConnection)?;
17731772

1774-
if sender_result.is_ok() && sending_track_result.is_ok() {
1775-
self.internal.trigger_negotiation_needed().await;
1776-
}
1777-
Ok(())
1778-
} else {
1779-
Err(Error::ErrSenderNotCreatedByConnection)
1773+
// This also happens in `set_sending_track` but we need to make sure we do this
1774+
// before we call sender.stop to avoid a race condition when removing tracks and
1775+
// generating offers.
1776+
t.set_direction_internal(RTCRtpTransceiverDirection::from_send_recv(
1777+
false,
1778+
t.direction().has_recv(),
1779+
));
1780+
// Stop the sender
1781+
let sender_result = sender.stop().await;
1782+
// This also updates direction
1783+
let sending_track_result = t.set_sending_track(None).await;
1784+
1785+
if sender_result.is_ok() && sending_track_result.is_ok() {
1786+
self.internal.trigger_negotiation_needed().await;
17801787
}
1788+
Ok(())
17811789
}
17821790

17831791
/// add_transceiver_from_kind Create a new RtpTransceiver and adds it to the set of transceivers.

src/rtp_transceiver/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,10 @@ impl RTCRtpTransceiver {
394394

395395
let current_direction = self.current_direction();
396396
if previous_direction != current_direction {
397+
let mid = self.mid().await;
397398
trace!(
398-
"Processing transceiver direction change from {} to {}",
399+
"Processing transceiver({}) direction change from {} to {}",
400+
mid,
399401
previous_direction,
400402
current_direction
401403
);

0 commit comments

Comments
 (0)