-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
pion/webrtc v2.2.26 wrong transceivers reuse, cannot re-add removed tracks on receiver side. #1843
Comments
After investigating we saw that there is a difference between the behavior of the browser and that of the pion webrtc library in handling transceivers and related m-sections in the SDP. Browser Aswerer side: transceivers are reused whenever possible. PION WebRTC package Aswerer side (browser): same as previous. Following the W3C specification on adding tracks (and related modification of senders and transceivers), a transceiver cannot be reused if it previously had the Commenting out the code that iterates over the transceivers in the You can see the p2p behavior on this fiddle https://jsfiddle.net/yt7m5xvj/ by following these steps:
Currently we cannot switch to the new release of the library and we have seen that even in the latest release Can you give us some advice on how to modify the code to get the behavior from W3C specs instead of always avoiding reusing transceivers? |
According to W3C specifications, the transceiver can be reused if "The sender has never been used to send. More precisely, the [[CurrentDirection]] slot of the RTCRtpTransceiver associated with the sender has never had a value of "sendrecv" or "sendonly"". Current implementation does not have CurrentDirection slot, so the flag usedToSend is set on setDirection change. This fixes pion#1843 and maybe other issues.
I am so sorry @marco-sacchi @EdoaLive that I dropped the ball on this. I really appreciate your deep investigation on this and we are going to fix this :) I am trying to get a I am curious how |
I am not able to reproduce this. Would you mind cloning this repro and tell me what is wrong/different about my reproduce. I will continue to investigate this! https://github.com/Sean-Der/pion-webrtc-issue-1843 |
Also I used @Antonito if you have the bandwidth would you mind trying my repro/checking if it matches the summary in #1843 (comment) if you don't totally understand I can find someone else :) you are just great at detail/debugging stuff! I am going to get an old version of Chromium to try also. |
Hi, @Sean-Der from what I understood, your example matches the scenario described – the only difference I spot is the audio stuff, but it should not impact the results. I ran the example a few times on (MacOS):
I didn’t detect any issue – the video played / stopped / continued as expected 🤔 Would you be able to test with a more recent Chrome version or a different browser @marco-sacchi ? My best guess right now would be an issue with libwebrtc: might be a bug in an old version, or maybe Pion doesn't do something correctly and newer libwebrtc is less strict about it, or may be arch related (Linux vs MacOS, as I guess @Sean-Der also ran the example on a Mac?) |
Just tried with I really appreciate this bug report @marco-sacchi and @EdoaLive I just am not able to reproduce. I don't want to disable Transceiver reuse unless we have to. It will really bloat signaling. Those costs really start to add up for some users. I will leave this open for a few more days, then will resolve. thanks! |
Sorry @Sean-Der and @Antonito, I will be watching carefully during the next week. Using your repro I have no problems: I have now tested with Chrome But the difference I noticed right away, apart from the different version of the webrtc module ( We had problems using a stream coming from the webcam (or from the screen sharing) so the negotiation started in the browser both for the start of the broadcast and for the stop (and subsequent reactivation). This means that in your repro the SDP with the offer is always generated by the Pion webrtc module, while in our case it is always generated by the browser. These problems were present in my system, but also in the MacBook Pro with macOS Mojave Version 10.14.6 (where I tested Safari and Chrome) and in @EdoaLive's Windows 10 system with Chrome (whose version I don't remember). I will try to integrate your test using the video track coming from the webcam. |
Ah ok nice catch @marco-sacchi, sorry about the behavior differences. How should I modify the example to reproduce the behavior?
If that is right I can update my repo today! |
Also no worry about the delay. You reported this and I was really slow, I moved into a new house June 20th so my life was a blur for a good month :) |
You have to loop like this:
Note that you must create the I wrote it from memory, so I hope I haven't been wrong somewhere. |
Hi @Sean-Der , I created a pull-request following the steps I indicated above and I was able to reproduce the behavior indicated in the first post of the issue.. |
@marco-sacchi That example is perfect! I am also surprised on the behavior (and don't know the right answer). If Pion gets an offer that disables a currently disabled track, I wouldn't expect it to be re-enabled automatically. I need to make a JS Fiddle to see what happens Chrome<->Chrome. If your transceiver is disabled by the remote, can it be re-enabled by the remote? |
@Sean-Der, you don't need to create a fiddle, I had already attached one in this post (#1843 (comment)) of this issue. |
Hey @marco-sacchi Can you pull + try the repro repo. It looks like signaling does work in this case. I just had to do the following
|
@Sean-Der, you can't avoid to unset the video element, this way the track continues to exist on the javascript side. Your changes work because, from the browser's point of view, instead of sending a new track you are just stopping and resuming sending packets to a track that already exists in the As you can see, on the javascript side,
Note: I opened this issue, not because Pion doesn't reuse transceivers, but because it reuses them even when it shouldn't, causing a different behavior than the p2p connection between two browsers. Following the W3C specification on adding tracks (and related modification of senders and transceivers): "a transceiver cannot be reused if it previously had the currentDirection state set to sendonly or sendrecv. (https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-addtrack)". Could you please check this behavior? |
Your environment.
What did you do?
First of all, thank you for your product and support!
We are using pion to implement our own SFU.
We are trying to figure out why, although Chrome's webrtc-internal stats display packet reception, negotiation, and transceiver status change are correct, the audio/video stream doesn't show when tracks are removed and then re-added.
Steps
The panelist initiates the call with only the webcam video track (to simplify debugging) and publishes it, attendees joins the call with only the microphone audio track.
The panelist's audio/video stream is then added to the attendees subscriptions and correctly displayed.
The broadcast of the panelist's audio/video stream is stopped and the attendees subscriptions are stopped.
Then the panelist's audio/video stream is added again and the subscriptions restored.
I am attaching the log of the negotiations on both the panelist and the attendant side and the stats.
We don't think this is your issue, but it would be great if we could get support to try and understand why the stream isn't being received again.
EDIT 2021-06-24
Note that:
track.stop()
method is not called for any remote track.Obviously any information and suggestions will be welcome.
We regret not being able to share more information, we are still investigating, and will keep you updated in case we manage to isolate or solve the problem on our side or on your side.
What did you expect?
The audio/video stream should be visible again.
What happened?
The audio/video stream is not restored.
panelist-negotiations.txt
attendee-negotiations.txt
The text was updated successfully, but these errors were encountered: