Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

WebRTC development practice: why you need a SFU server

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

When you get started with WebRTC, you will soon come across a term called SFU. You may easily find many open source implementations of SFU online and enthusiastically start compiling, deploying and testing these servers, but have you ever wondered why our WebRTC applications need SFU servers?

Network Model of 1 WebRTC P2P call

For example, the picture shows the network topology under WebRTC P2P mode. If ClientA and ClientB can successfully establish a P2P connection, they can exchange data with each other directly through P2P. If the P2P connection cannot be successfully connected due to some network environment, the data can be transferred to the other party through a TURN Server.

This TURN Server refers to a server that supports the TURN protocol, which acts as a network relay, supporting transparent forwarding of packets from one Client to multiple other Client clients.

In this simple P2P call scenario, in fact, this model is basically sufficient, there is no need to set up any SFU server.

Let's take a closer look at the scene of a multi-person call:

As shown in the figure, the only difference between a multi-person call and a single-person call is that each client needs to establish a P2P connection with the other two. I also introduced this scenario in "WebRTC Development practice: from an one-to-one call to a multi-person meeting." Like one-to-one calls, if the two sides can successfully establish a P2P connection, they will exchange data directly through P2P; if they can not get through, then use Turn Server to transfer the data.

We call this completely P2P network topology Mesh structure, and let's talk about its advantages and disadvantages.

2 the advantages and disadvantages of WebRTC Mesh network topology

Advantages:

The logic is simple and easy to implement

The server is "lightweight", the TURN server is relatively simple, and a certain proportion of P2P success rate can greatly reduce the pressure on the server.

Disadvantages:

For each new client, all clients need to add one more data upstream, and the upstream bandwidth of the client is too large. Therefore, the greater the number of calls, the worse the effect.

It is impossible to perform additional processing on the server, such as recording, storage and playback, real-time transcoding, intelligent analysis, multi-channel confluence, push live broadcasting, etc.

From this, we can see that the shortcomings of mesh structure still have a great impact, and the real commercial applications need to have good call quality, service stability and expansibility. Therefore, there is an urgent need for a new network topology structure, which can avoid these shortcomings of mesh structure.

3 what is SFU?

The full name of SFU is: Selective Forwarding Unit, which is a method of routing and forwarding WebRTC client audio and video data streams through the server.

As shown in the figure, the core feature of the SFU server is that it "disguises" itself as a Peer client of WebRTC. In fact, other clients of WebRTC do not know whether they are connecting to a real client or a server through P2P. We usually call this connection P2S, namely: Peer to Server. In addition to the Peer client that "disguises" as a WebRTC, one of the most important capabilities of the SFU server is the ability to one-to-many, that is, it can forward data from one Client side to multiple Client clients.

In this network topology, no matter how many people make video calls at the same time, the client of each WebRTC only needs to connect to one SFU server for upstream data, which greatly reduces the upstream bandwidth pressure on the client caused by the Mesh model in the multi-person video call scenario.

The biggest difference between SFU server and TURN server is that TURN server is only an auxiliary data forwarding channel for WebRTC clients, which transparently forwards data when P2P is not available. On the other hand, SFU is "business-savvy", it has an equal relationship with WebRTC clients, and even "takes over" the application and control of data forwarding from WebRTC clients.

4 what is MCU?

As can be seen from the above definition of SFU, the network topology model SFU, in which one-to-many is implemented by SFU Server, reduces the upstream bandwidth pressure on each client in a multi-person video call scenario, but the downlink is still multi-stream. With the increase of the number of calls, the downlink bandwidth pressure will still increase proportionally, so can only one stream be left in the downstream? -- Yes, it can be solved by merging on the server and then sending it, as shown in the following figure:

This network topology, known as MCU, is characterized by the fact that MCU Server combines the uplink video streams of various clients into one, and then forwards them to other clients. Compared with SFU, this model reduces the downlink bandwidth pressure of the client in the multi-person video call scenario, but because the merging requires transcoding operation, the pressure on the server is relatively high, and the flow sent to the client is a fixed confluence picture, so the flexibility is not very good.

5 Why is SFU recommended?

To sum up, the pure mesh scheme can not adapt to multi-person video calls, nor can it achieve a variety of video processing requirements on the server side, so it is excluded from commercial applications first.

SFU compared with MCU, the server pressure is less (pure forwarding, no transcoding confluence), more flexible (can selectively switch any data uplink and downlink, etc.), is more widely welcomed and applied, common open source SFU servers are: Licode,Janus,Jitsi,mediasoup,Medooze, etc., each has its own characteristics, you can go to the project home page for more details.

Of course, the hybrid scheme of SFU + MCU can also be combined to flexibly respond to the application needs of different scenarios.

5 Summary

So much for sharing the relevant knowledge about WebRTC SFU. If you have any questions, you are welcome to write to lujun.hust@gmail.com to communicate. In addition, you are welcome to follow my Sina Weibo @ Lu _ Jun or Wechat official account @ Jhuster for the latest articles and information.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report