The WebRTC SFU server can:
- Forward: Only need to send 1 stream to SFU, which forwards to other peers in the room.
- Simulcast: If the stream is simulcast stream, SFU can forward streams with different bitrate like MCU, but with less CPU cost without transcoding.
- Protocol Converter: SFU can also convert WebRTC to other protocols, like publish to YouTube by RTMP.
- DVR: Record the WebRTC stream as VoD file such as MP4 file.
- Network Quality: SFU provides better network quality, especially when P2P is not able to enabled.
- Firewall Traverse: For peers behind enterprise firewall, the UDP might not avaialbe, SFU can use HTTP(TCP/80) or HTTPS(TCP/443) port.
Forward
The default model of WebRTC is P2P like this:
PeerA(WebRTC/Chrome) --------> PeerB(WebRTC/Chrome)
PeerB(WebRTC/Chrome) --------> PeerA(WebRTC/Chrome)
If you got three participants in a room:
PeerA(WebRTC/Chrome) --------> PeerB(WebRTC/Chrome)
PeerA(WebRTC/Chrome) --------> PeerC(WebRTC/Chrome)
PeerB(WebRTC/Chrome) --------> PeerA(WebRTC/Chrome)
PeerB(WebRTC/Chrome) --------> PeerC(WebRTC/Chrome)
PeerC(WebRTC/Chrome) --------> PeerA(WebRTC/Chrome)
PeerC(WebRTC/Chrome) --------> PeerB(WebRTC/Chrome)
For P2P model, each peer need to send N-1 streams and receive N-1 streams from other peers, which requires lots of upload bandwidth.
SFU can forward the stream to other peers, like this:
PeerA(WebRTC/Chrome) ---> SFU --+--> PeerB(WebRTC/Chrome)
+--> PeerC(WebRTC/Chrome)
PeerB(WebRTC/Chrome) ---> SFU --+--> PeerA(WebRTC/Chrome)
+--> PeerC(WebRTC/Chrome)
PeerC(WebRTC/Chrome) ---> SFU --+--> PeerA(WebRTC/Chrome)
+--> PeerB(WebRTC/Chrome)
For SFU model, each peer only need to send 1 stream and receive N-1 streams, so this model is better than P2P, especially when there are more peers in a room.
Simulcast
Because the network of peers is different, so SFU can use simulcast to send diffent bitrate to peers, it works like this:
PeerA(WebRTC/Chrome) --1Mbps-> SFU --+--1Mbps----> PeerB(WebRTC/Chrome)
+--500Kbps--> PeerC(WebRTC/Chrome)
Because the network of PeerC is worse, so SFU send stream in bitrate 500Kbps.
Please note that this requires PeerA to use AV1 codec, the H.264 is not supported by default, so it's not a perfect solution.
And it's also complex and PeerC might doesn't want low bitrate stream, but it accepts larger latency, so this solution does not always work.
Note: Simulcast is not the same to MCU, which requires a lots of CPU cost for transcoding. MCU convert the streams in a room to 1 stream for a peer to recieve, so it's been used in some scenario such as for SIP embeded device, which only recieve 1 stream with video and audio.
There are lots of SFU servers can do this, for example, SRS, Mediasoup, Janus and Licode.
Note: Right not at 2023.02, SRS simulcast feature has not been merged to develop, it's in a feature branch.
Protocol Converter
Sometimes you want to covert WebRTC to live streaming, for example, to open a web page and publish camera stream to YouTube.
How to do that by SFU? It works like this:
Chrome --WebRTC------> SFU ---RTMP------> YouTube/Twitch/TikTok
(H.264+OPUS) (H.264+AAC)
In this model, SFU only need to covert audio stream from OPUS to AAC, and video stream is by-pass for both WebRTC and RTMP is H.264.
Because of the audio transcoding, there are few of SFU servers can do this, for example, SRS and Janus.
Note: Janus need ffmpeg to covert RTP packets, while SRS do this natively so it's easy to use.
DVR
SFU can also DVR WebRTC streams to MP4 file, for example:
Chrome ---WebRTC---> SFU ---DVR--> MP4
This enable you to use a web page to upload MP4 file. For example, to allow user to record a clip of camera to feedback for your product.
Similar to live streaming, MP4 file support AAC better, so SFU need to convert OPUS to AAC.
Because of the audio transcoding, there are few of SFU servers can do this, for example, SRS.
Note: I'm not sure which SFU servers supports this, please let me know if I miss something.
Network Quality
On internet, the SFU model is better than P2P model. Consider about the bellow flow:
PeerA <----Internet--> PeerB
P2P seems simple and high efficiency, but there are actually lots of routers and network devices, generally they are servers, so the flow of P2P model should be:
PeerA <--------Internet----------> PeerB
Routers, Servers, etc.
From the perspective of network transport, the SFU model is similar:
PeerA <--------SFU-Server----------> PeerB
Routers, Servers, etc.
SFU network quality is better than P2P, not about the server but you are able to control the transport network by use dedicated server and even dedicated network.
But for P2P, you can't control the routers and servers, all peers are clients.
Note: TURN server model also improve network quality, but SFU is still better because you could use some QoS algorithms such as GCC on SFU, because SFU server is actually a client, but TURN is just a proxy.
Note: SFU cluster, which is built of a set of SFU servers, can also iprove the quality when peers crossing countries.
Firewall Traverse
For some users behind enterprise firewall, UDP is not available:
Firewall
|
Chrome -----X---WebRTC--- Chrome(PeerB)
PeerA | (UDP)
Even worse, only HTTP(TCP/80) or HTTPS(TCP/443) is allowed by some firewall. So we can use SFU which listen at HTTP(TCP/80) or HTTPS(TCP/443), it works like this:
Firewall
|
Chrome -----+---WebRTC-------> SFU ---> Chrome(PeerB)
PeerA | (TCP 80/443)
Note: Yep, TURN server can also solve this problem, coturn as such, but note that TURN server usually allocate a set of port, not fixed ports, so TURN server is not easy to use as SFU server.
There are few of SFU servers can do this, for example, SRS and Mediasoup.
Note: I'm not sure which SFU servers supports this, please let me know if I miss something.