-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Renegotiation support #1099
Renegotiation support #1099
Conversation
Started playing with adding a new media stream in an existing PeerConnection: of course this means adding one if it wasn't present already, you're still bound to the "max 1 audio, 1 video, 1 data per PC" constraint. Modified the EchoTest demo to start audio only:
and then tried this snippet:
which is basically the same as the snippet presented before, but which also updates the local stream (which unlike the remote stream, is not automatically updated by Edit: the desync was caused by a typo (damn copy/paste), works great now! Of course, this is something that plugins will need to provide support for: while for the EchoTest this is transparent, other plugins involving multiple users will need to be smarter than that. In the VideoRoom, for instance, a change in the available media for a publisher means sending a new offer to all its subscribers as well, or they won't be aware of the new media stream. I'll take note of this for the next patches. |
… when ordering of m-lines is different, SRTP setup when audio and video only appears later on
Played some more with a different scenario, today: starting from a datachannel only PeerConnection, and then adding audio and video in a new renegotiation later on. This brought up a ton of errors and assumptions we had in the code, mostly related to the ordering we assumed for m-lines (audio, video, data) that were of course invalidated with this renegotiation: as a result, nothing worked. I had to modify many parts of the core to get this working as expected, but I believe this now makes it much more flexible and resilient. If you want to test this, start from datachannels only in the EchoTest demo:
and then try this snippet to renegotiate with audio and video too:
I'll have to work on the other way around, that is starting from audio and/or video, and only add datachannels in a later moment, since at the moment that won't work: in fact, the only place where we set up the SCTP association is in the "DTLS handshake done" code, which would not happen again after a renegotiation. This means we'll have to expose that as a separate function, to allow us to do that when needed, whether it's right after the DTLS handshake or later on. Again, all these experiments have been only tested with the EchoTest so far, as I'm only interested in getting this to work from a functional perspective in the core. Any plugin-specific management of those scenarios will have to wait. |
Since the bulk of the changes has been added to both core and plugins (it's a matter of testing now), I've added some controls to the JavaScript API in The important bits here are some additional flags you can set when doing a The new properties you can pass are the following:
Notice that these properties are only processed when you're trying a renegotiation, and will be ignored when creating a new PeerConnection. These properties don't replace the existing Here are a few examples of how this works with the EchoTest demo (which I already updated to handle the additional Remove video:
Add video:
Replace video with a specific devideId:
Hopefully this syntax is clean and simple enough as it is. If you start playing with it, please let me know if it's not working as expected and/or if it needs fine tuning. |
I updated all the relevant demos (some like screensharing and VP9 demos haven't been updated yet, but they're basically clones of the videoroom so I'll update them shortly) to support updates to local and remote streams resulting from renegotiations, so you should be able to test most if not all plugins for that. For instance, if you wanted to check how switching a camera in the videoroom demo works, you can use a command like this:
Feedback welcome. |
Tested other demos/plugins as well, played with going from camera to screensharing and viceversa, etc., and everything seems to be working. That said, I'll wait for more comprehensive tests from other Janus users to merge, as I'm only doing some specific tests and cannot possibly cover all the common scenarios people play with. |
Hi @lminiero, looks there is an issues with make command in this branch - I can't build Janus if disabled data channels support. For example, I do the following:
then I do the following:
and receive this:
now I try to 'make' and receive 3 errors:
As I understand, the janus_dtls_sctp_setup_thread function is not defined if HAVE_SCTP is not defined Line 104 in 9d4c95d
which actually will not be defined If I disabled the data-channels: Line 298 in 9d4c95d
|
Thanks for the heads up! I'll have a look and fix shortly. |
@soulfly it should be fixed now, please let me know if that's not the case. |
Just tagged the latest version before renegotiations here. Merging this branch which becomes the new master 0.3.0. Hopefully this will encourage more people to experiment with its new features, and allows me to keep on working on what's coming next. |
@lminiero thanks, the issue is fixed now now I receive 2 other errors:
and
from my understanding, this is related to your latest commit in this PR |
Yep, probably one more |
Fixed: 2fb2335 |
Thanks, works now! |
@lminiero I'm a bit confused with VideoRoom plugin here What is the final format of "configure" message to Janus server after create offer:
or
or
? |
|
Thanks @lminiero |
For viewers it's needed, as it's the only way to have the plugin send them a new offer. Publishers send a new offer themselves instead, so it's them who originate the renegotiation. You can find some more info on the rationale in #753 (which referred to ICE restarts but the principle is the same). |
I mean what is the difference between |
Yes, |
This patch tries to add renegotiation support to Janus and its plugins for existing media streams. It does also supports ICE restarts, which means that it obsoletes #753, which I'll close as soon as this is published.
For what concerns generic renegotiations and how to force a restart, you can check the examples in the above mentioned PR. Most importantly, though, this PR now allows you to renegotiate a session, e.g., as a consequence of a changed media device (think about changing a camera on the fly on the same peerconnection). The SSRC change is handled automatically, and the RTP headers are also updated on the fly, which means media-wise these changes should be completely transparent to plugins (and as such recorders).
Here's an example of how you can test this with the EchoTest demo:
This snippet basically removes the video track from both MediaStream and PeerConnection sender, does a new getUserMedia just for video, and then adds the new resulting video track to the two objects above. This requires a renegotiation to work, which is why we have a new
createOffer
call there. ThiscreateOffer
will generate a new SDP with new SSRCs for video: as soon as the new answer from Janus comes back, the new camera will be used for video. Notice that, if you were usingsimulcast: true
, you can use it for the newcreateOffer
as well and it should work.This is a snippet to test the same for a VideoRoom publisher:
which does basically the same thing but in a VideoRoom. If you have subscribers, you should see viewers display the new camera (or the same one, if you replaced the video track with the same source) even after the renegotiation. A freeze there means something's not working.
As a further note, you can use these renegotiations to update media directions too, even though I don't think any of the plugins honor this at the moment, and neither does the core. We'll have to implement and fix this along the way: please provide feedback while using the features, and let us know about what's not working as expected when using this new feature.
Finally, you cannot currently use this to add new media tracks: let's say you started audio only, and want to renegotiate to add a video track, you currently can't do it. Again, this will need to be implemented later on, as soon as we know what we have now works reasonably well.
Feedback welcome!