a research team of INFOCOM CORPORATION • Writing a series of WebRTC on HTML5Experts.jp (HTML5 tech site) – https://html5experts.jp/series/webrtc2016/ • English Presentation for WebRTC (2013-2017) – https://speakerdeck.com/mganeko • Japanese Presentation for WebRTC (2013-2017) – http://www.slideshare.net/mganeko 2
SFU : Selective forwarding Unit – mediasoup : Open Source WebRTC SFU module for Node.js • New Topics for #15 – Updates of mediasoup v0.3 → v1.2 – New sample codes for v1.2 • https://github.com/mganeko/mediasoup_sample 3
B Browser D Browser C P2P • No media server • Browser side: • CPU load: Very High • Network load: Very High 5 Browser A Browser B Browser D Browser C SFU Dispatch audio/video SFU • User SFU server, CPU load: Low • Browser side: low CPU load • Browser side: network load: middle Able to choose display layout on member side ◎
Browser C SFU Dispatch audio/video SFU • User SFU server, CPU load: Low • Browser side: low CPU load • Browser side: network load: middle Able to choose display layout on member side ◎ Browser A Browser B Browser D Browser C MCU Mix video / audio MCU • Use MCU server, CPU load: Super High • Browser side: very low CPU/Network load
Web Site https://mediasoup.org/ – GitHub https://github.com/ibc/mediasoup/ → https://github.com/versatica/mediasoup • Not a Server App, but components for a Server – Instead of creating yet another opinionated server, mediasoup is a Node.js module which can be integrated into a larger application or made standalone with just a few lines of JavaScript. • Provided as Node.js module – You have to prepare Web Server and Signaling method 8
(No DataChannel), No Codecs • Powerful … Main part is build with C++, on libuv – Node.js invokes child worker process – Node.js and worker communicate via interprocess communication • JavaScript API for Node.js – WebRTC 1.0 … RTCPeerConnection, using promise – ORTC … Transport, RtpSender, RtpReceiver 9
sample – Video and Audio – Looks same as P2P, but … • if you stop SFU Sever process, then Remote video/audio will stop • Source codes on GitHub – https://github.com/mganeko/mediasoup_sample • multi participants, 1 way streaming, SSL support
higher – Linux / Mac OS X (Windows not supported yet) – Python 2.x (NOT Python 3.x !!) • Explicit local python version is needed, when using pyenv / virtualenv • $ pyenv local 2.7.12 – make – gcc with g++ , or clang with C++11 • Installation – $ npm install mediasoup • C++ compile may take a few minutes 11
Peer Peer Transport Transport RtpSender RtpSender RtpSender RtpReceiver RtpReceiver RtpReceiver ・1 Server has Many Rooms ・1 Room has Many Peers ・1 Peer has multiple RtpSender ・1 Peer has multiple RtpReceiver ・1 Peer has multiple のTransport Correspond to MediaTrack (video/audio) Correspond to MediaTrack Correspond to UDP/TCP port 1 Transport is used by - multiple RtpSender - multiple RtpReceiver BUNDLE, rtcp-mux multi-stream
Browser Peer RtpReceiver RtpSender Peer Browser RtpReceiver RtpSender RtpSender RtpSender RtpSender Streams are connected automatically in the room Transport Transport Transport
let receiver1; return server.createRoom(roomOptions) .then( (room) => { peer1 = room.Peer('alice'); return peer.setCapabilities(peerCapabilities); }) .then(() => { return peer.createTransport({ tcp: false }); }) .then((transport) => { rtpReceiver1 = peer1.RtpReceiver('audio', transport); }) 15 • Compose objects step by step • Use Promise • Do not create RtpSender expressly • Will be created automatically, passed by event (I do not understand well ..) Quite complex
CODECs – Available RTCP controls • Getting Capabilities of browser – ORTC, WebRTC 1.0 Spec has getCapabilities(), but not implemented yet • RTCRtpSender.getCapabilities(kind), • RTCRtpReceiver.getCapabilities(kind) – BUT, there are in SDP • Steps in Browser side – Get SDP with pc.createOffer({ offerToReceiveAudio: false, offerToReceiveVideo: false}) – DO NOT CALL pc.setLocalDescription() … P2P initiation will not start – Send SDP to mediasoup as “Capabilities” 21
(Browser) – Currently, the mediasoup implementation of RTCPeerConnection requires that the initial offer comes from the remote endpoint, • After onnegotiationneeded() event, create Offer in mediasoup • Not allowed to re-creating Offer in Remote (Browser) – Add/Remove of Remote stream/track is not supported • It seems like Plan B support is tentative. (maybe my sample was wrong ..) 24 Limitation of RTCPeerConnection, NOT limitation of mediasoup itself. It must be possible if you compose Transport, RtpReceiver, SDP manually.
first • Offer is always from mediasoup side / mediasoup do not accept Offer • When Add/Remove of Remote stream/track after connecting – Request re-negotiation to mediasoup somehow – Re-create Offer in mediasoup, and send to browser – Create Answer in browser , and send back to meidasoup • Plan B support for Chrome – Specify “usePlanB” option while creating PeerConnection object – Support Mix of Chrome / Firefox in the same room 25
my sample code – DO NOT send SDP right after createAnswer() from browser – Send Answer SDP after collecting all ICE candidates • When re-create Answer in browser – Send Answer SDP right away – onicecandidate() WILL NOT be fired on Chrome • all ICE candidates are collected, already • No events will be fired, after re- createAnswer() – onicecandidate() with empty candiate will be fired on Firefox 26
- N Subscriber) – Use option for creating Offer for Subscriber at mediasoup side • pc.createOffer({ offerToReceiveAudio:0, offerToReceiveVideo:0}) • Strick control for “1” to N – MUST exclude 2nd Publisher with application code – If you allow 2nd Publisher, the become “2 to N” • Bi-directional between publishers • ontrack()/onaddtream() will be fired in publishers 28 * It is possible to stop stream between publishers, if use RtpSender directly
room Browser Subscriber A Browser Subscriber B Browser Subscriber C PeerConnection PeerConnection PeerConnection PeerConnection Browser Publisher 2 PeerConnection * It is possible to stop stream between publishers, if use RtpSender directly
NAT/Firewall. Need global IP address. – mediasoup does not look for STUN/TURN server • Browser inside of NAT/Firewall is OK – When Browoser looks for STUN/TURN server, it is possible to connect. 32 mediasoup Browser STUN Browser TURN NAT Firewall
MCU → SFU • mediasoup v1.2 is stable enough to use – First choice if you want to built in SFU in your application. • If you want high functional Server, there are commercial products (such as Siguredo Sora, tokbox, twillio) • This slides on speakerdeck – https://speakerdeck.com/mganeko/playing-with-oss-webrtc-sfu-meidasoup-update-for-v1-dot-2 • Sample source on GitHub – https://github.com/mganeko/mediasoup_sample 33