Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct msid handling for RtpSender #217

Merged
merged 3 commits into from
Jul 12, 2022
Merged

Correct msid handling for RtpSender #217

merged 3 commits into from
Jul 12, 2022

Conversation

k0nserv
Copy link
Member

@k0nserv k0nserv commented Jul 7, 2022

The previous logic would put negotiation into an endless loop after
running remove_track due to incorrectly implementing the negotiation
check and handling of stream ids.

Upon calling remove_track the following steps were carried out:

  1. Find the transceiver the sender passed to remove_track is associated with
  2. Stop the sender and set its track to None.

There were three problems with this:

  1. The remove_track implementation is mostly correct, but it didn't always update the transceivers direction.
  2. When checking if negotiation is needed the logic wasn't quite correct.
  3. When offering the offered msid attribute didn't comply with the specification, in particular the msid line(s) should stay the same regardless of changes to the track or the transceivers direction.

In total this meant that when removing a track, at least some times, we'd end up in an endless negotiation loop where the check if negotiation was needed was always returning true, even after negotiating with the peer.

The previous logic would put negotiation into an endless loop after
running `remove_track` due to incorrectly implementing the negotiation
check and handling of stream ids.
@k0nserv k0nserv marked this pull request as ready for review July 7, 2022 16:02
@@ -447,27 +447,48 @@ impl RTCPeerConnection {
// if t.stopping && !t.stopped {
// return true
// }
let m = get_by_mid(t.mid().await.as_str(), local_desc);
let mid = t.mid().await;
let m = get_by_mid(&mid, local_desc);
// Step 5.2
if !t.stopped.load(Ordering::SeqCst) && m.is_none() {
return true;
}
if !t.stopped.load(Ordering::SeqCst) {
if let Some(m) = m {
// Step 5.3.1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://www.w3.org/TR/webrtc/#ref-for-dfn-check-if-negotiation-is-needed-1 for the steps outlined by the specification

@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #217 (38eddfe) into master (414a55c) will decrease coverage by 0.21%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##           master     #217      +/-   ##
==========================================
- Coverage   44.01%   43.79%   -0.22%     
==========================================
  Files          68       68              
  Lines        9658     9667       +9     
  Branches     2794     2820      +26     
==========================================
- Hits         4251     4234      -17     
- Misses       3350     3374      +24     
- Partials     2057     2059       +2     
Impacted Files Coverage Δ
src/error.rs 4.70% <60.00%> (+0.18%) ⬆️
src/rtp_transceiver/rtp_transceiver_direction.rs 92.59% <100.00%> (ø)
src/ice_transport/ice_parameters.rs 33.33% <0.00%> (-33.34%) ⬇️
src/rtp_transceiver/rtp_transceiver_test.rs 47.03% <0.00%> (-6.34%) ⬇️
src/rtp_transceiver/rtp_codec.rs 55.71% <0.00%> (-4.29%) ⬇️
src/ice_transport/ice_connection_state.rs 72.22% <0.00%> (-2.78%) ⬇️
src/peer_connection/operation/operation_test.rs 53.33% <0.00%> (-1.51%) ⬇️
src/ice_transport/ice_candidate.rs 32.71% <0.00%> (-0.94%) ⬇️
.../rtp_transceiver/rtp_receiver/rtp_receiver_test.rs 49.13% <0.00%> (-0.44%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 414a55c...38eddfe. Read the comment docs.

The way this code was written the `set_sending_track` call could
sometimes not run if `sender.stop()` failed. With this change we make
sure to attempt both operations always, even if one fails.
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
Copy link
Contributor

@lolgesten lolgesten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I don't know about the logic, because I don't know the spec.

@k0nserv k0nserv merged commit 4895d64 into master Jul 12, 2022
@k0nserv k0nserv deleted the fix/rtp-sender-msid branch July 12, 2022 13:55
robashton added a commit to robashton/webrtc that referenced this pull request Oct 10, 2022
robashton added a commit to robashton/webrtc that referenced this pull request Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants