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

Don't reuse transceiver in one round negotiation #2899

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

cnderrauber
Copy link
Member

Should not reuse transceiver (remove & add track) in one round negotiation, it causes the transceiver change ssrc/msid without transit to inactive and the remote peer connection can't fire track close and OnTrack event.

Description

Failure case:

  1. pcOffer,pcAnswer negotiate a track A with direction SendRecv, RecvOny
  2. offer = pcOffer.CreateOffer, send to pcAnswer,
  3. pcAnswer.SetRemoteDescription(offer), CreateAnwser, SetLocalDescription
  4. pcOffer.RemoveTrack(A), SetRemoteDescription(answer)
  5. pcOffer.AddTrack(B), offer2 = CreateOffer
    In step 5, B should not reuse track A's transceiver, otherwise the transceiver in offer and offer2 will not change direction but has different ssrc, cause pcAnwser can't fire OnTrack correctly.

Reference issue

Fixes #...

func() {
for _, t := range tracks {
for _, track := range tracks {
func(t *TrackRemote) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Narrow down the scope of the lock

}
case direction == RTPTransceiverDirectionSendrecv:
if t.Direction() == RTPTransceiverDirectionSendonly {
t.setDirection(RTPTransceiverDirectionSendrecv)
} else if t.Direction() == RTPTransceiverDirectionInactive {
Copy link
Member Author

Choose a reason for hiding this comment

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

Transit Inactive transceiver to RecvOnly if the remote peer reuse the inactive transceiver to send track

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 78.99%. Comparing base (9a71f69) to head (bc4bdaf).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
peerconnection.go 75.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2899      +/-   ##
==========================================
+ Coverage   78.95%   78.99%   +0.04%     
==========================================
  Files          89       89              
  Lines        8481     8488       +7     
==========================================
+ Hits         6696     6705       +9     
+ Misses       1298     1296       -2     
  Partials      487      487              
Flag Coverage Δ
go 80.55% <75.00%> (+0.04%) ⬆️
wasm 65.11% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1118,10 +1118,18 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
case direction == RTPTransceiverDirectionRecvonly:
if t.Direction() == RTPTransceiverDirectionSendrecv {
t.setDirection(RTPTransceiverDirectionSendonly)
} else if t.Direction() == RTPTransceiverDirectionRecvonly {
Copy link
Member Author

Choose a reason for hiding this comment

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

Set RecvOnly transceiver to Inactive if the remote peer stop sending

Should not reuse transceiver (remove & add track)
in one round negotiation, it cause the transceiver
changes ssrc/id without transit to inactive and the
remote peer connection can't fire track close and
OnTrack event.
@cnderrauber cnderrauber merged commit e6a86e7 into master Sep 6, 2024
18 checks passed
@cnderrauber cnderrauber deleted the reuse_transceiver branch September 6, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants