”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > WebRTC SFU:完整指南。

WebRTC SFU:完整指南。

发布于2024-08-17
浏览:885

What is WebRTC SFU (Selective Forwarding Unit)?

Selective Forwarding Unit or SFU

SFU is an server based architecture that is used in webrtc to conduct multi party video calling, audio calling and data transfer.

The SFU acts an intermediary between devices that recives media streams from multiple devices and then decides which streams must be send to which devices.

What is WebRTC?

WebRTC is an open source project, using which you can enable real time audio, video and data transfer between devices

WebRTC runs in web browsers as well as in apps, WebRTC is supported by almost all modern browsers and is an standard for video, audio communication

Image description

How does SFU or Selective Forwarding Unit work

here is a step by step guide on how does an SFU work

Step 1 Client connections and media capture

  1. Participant connection

Each participant first establishes a connection with the SFU. This process involves a signalling server where session descriptions are exchanged.

the session description contains important information, which is used to establish a session.

2. Media stream capture

On the client side the media streams are captured from the participant devices, like audio from microphone, video from camera etc. In the next step these streams are sent to the SFU

Step 2: Stream Transmission to SFU

  1. Encoding and sending the stream: The client device encodes the media stream using codecs for video and audio and sends it to the SFU

This is done using the RTP protocol or the SRTP protocol if you need encryption

2. Receipt by SFU

The SFU or the Selective forwarding unit recieves the individual streams from each connected device and maintains a seprate inbound stream for each device.

Step 3 Stream Processing at SFU

  1. No Mixing

In SFU as compated to MCU all the streams are seprate from each other and there is no mixing

2. Selective Forwarding

The SFU recieves a seprate stream from each device that is connected to the SFU and then the SFU maintains a seprate stream for each participant

Step 4: Stream Distribution by SFU

  1. Adapting:

Before forwarding the stream to uesrs the SFU performs certain adaptations to the stream, such as chossing different quality video codecs and selecting between different simulcast streams.

These are based on the receiving client CPU and Bandwidth capabilities

2*. Forwarding Streams*

The SFU forwards the stream which each client is asking for.

The client devices could receive multiple  of streams from the SFU or even a single stream of video and audio data

  1. RTP or SRTP Packets

The media is sent in RTP or SRTP packets, and because different client devices might have different cpu and bandwidth limitations.

The SFU optimizes the streams packets to flow such that the stream flows smoothly and the video quality is smooth on the devices

Step 5 Client Reception and Display

  1. Decoding: Each client recieves a RTP streams from the SFU, the client then decodes the stream and renders it on the screen

  2. Synchronization: Audio and video synchronization is important and it is handled at the client level.The client uses the timestamps and the sequence numbers from the RTP stream to sync video and audio playback smoothly

SFU Vs p2p vs MCU

In this section let us consider the distinctions between SFU that is Selective forwarding unit, Peer to Peer or P2p and MCU that is Multipoint Control Unit

1.  Selective Forwarding Unit SFU

selective forwarding: The SFU recieves multiple streams and selectively forwards the stream to devices without altering stream content

Server Based: The SFU relies on a server but the server is used for routing the steams and not for anything else.

Advantages:

Scalability: the SFU is highly scalable and it reduces the load on single client devices by managing which stream is sent to any client device

Low processing requirement: Because the SFU just forwards the stream and does not do any processing on the stream, thus reducing the latency and the cpu processing requirement

Stream flexibility:

The client devices can recive multiple streams or just one stream or no stream at all, it all depends on which stream the client device is asking for and needs to display it on the screen

Disadvantages:

Bandwidth Intensive: The SFU are bandwidth intensive on the server side because each stream is recieved by the server and the SFU should have the CPU and the bandwidth to handle all the streams

2. Peer-to-Peer P2P

In P2p architecture each participant connects to another participant directly without the need for an intermediate server

but often a STUN server or a TURN server is required for NAT traversal and to relay the streams around NAT

if you are looking for a turn server you can consider the Metered TURN server service provider

Metered is a Global TURN server provider with TURN server all around the world, that connects to the user nearest to the TURN server for minimum latency and best performance

Disadvantages:

Each participant device must handle multiple streams if there are multiple devices in a meeting.

Which is CPU and bandwidth intensive on all the client devices. For this you can consider the Metered SFU

Multipoint Control Unit

The MCU mixes all incoming streams and creates a single stream or few streams out of a many streams and then sends it to all the clients

The MCU requires a lot of CPU computation and resources on the server, it also creates latency when transmitting streams but it has one advantage, it can greatly reduce the computation and bandwidth requirement on client devices

When in the past the mobile devies were pretty slow and the network infrastructe was also bad, in those days MCU made a lot of sence

But these days with the advance in technology it perhaps provides a bad experience with increased latency and slow video delivery.

Advantages of SFU in WebRTC

Here are some of the advantages of SFU in WebRTC

1. Scalability

the most important advantage of SFU in WebRTC is scalability. You can also scale P2P video calling but it is difficult to create a mesh and scale it

  • Reduced Client Bandwidth

When you are video calling with multiple client devices in peer 2 peer format, each client must send their stream to all the other clients and vice versa.

Because of these there is exponentially greater requirement of bandwidth as well as CPU for each client

Some client that do not have capacity for very high bandwidth and cpu compute struggle with the video calling

2. Improved Quality Management

The SFU can make intelligent decisions regarding which streams to send to which clients thus saving imporving quality of video

  • Stream Adaptation

The SFU can adapt the stream according to the bandwidth and CPU capacity of the recieving devices.

If the client device has lower bandwidth then the SFU can send low quality streams to that perticular device so that the video runs smoothly without buffering

3. Reduced Processing Load on Clients

The SFU handles the majority of the data processsing that is required for stream management, the client devices themsevles are freed from all the heavy lifting

This is helpful for mobilde devices and devices with low processing power that is CPU power

  • Less CPU intensive

Client devices do not face a need for encoding and decoding the multiples streams that are comming to the SFU for processing instead the SFU does this for them

Thus these devices drink less battery run cooler and require less cpu time

  • User Experience

The reduction in CPU processing leads to smoother interface, cooler devices and overall better user experience

4. Flexibility in Media handling

SFU offer greater flexibility in how you want to handle the media steams and how you want the video to be displayed on the participants client devices

  • Individual Stream Control

The client deives or the meeting participants can choose which streams they want to download and also how they want to display the stream on their screens

They also have the ability to download different quality of strems or make it automatic such that the SFU chooses the best stream based on the client device bandwidth capacity and CPU capability

  • Support for advanced featuers

SFU or the Selective Forwarding Unit supports a variety of advanced features like

simulcasting ( ability to send multiple qualites of a single video stream), scalable video codec  and many more  

5. Enhanced Flexibility and Security

All the streams passing through the SFU are end to end encrypted meaning no one not even the SFU know what streams are passing through it

The encryption protocols such as DTLS and SRTP are used for end to end encryption

the SFU can log the interactions but cannot intercept the streams for compliance purposes as well.

Image description

Metered TURN servers

  1. API: TURN server management with powerful API. You can do things like Add/ Remove credentials via the API, Retrieve Per User / Credentials and User metrics via the API, Enable/ Disable credentials via the API, Retrive Usage data by date via the API.

  2. Global Geo-Location targeting: Automatically directs traffic to the nearest servers, for lowest possible latency and highest quality performance. less than 50 ms latency anywhere around the world

  3. Servers in all the Regions of the world: Toronto, Miami, San Francisco, Amsterdam, London, Frankfurt, Bangalore, Singapore,Sydney, Seoul, Dallas, New York

  4. Low Latency: less than 50 ms latency, anywhere across the world.

  5. Cost-Effective: pay-as-you-go pricing with bandwidth and volume discounts available.

  6. Easy Administration: Get usage logs, emails when accounts reach threshold limits, billing records and email and phone support.

  7. Standards Compliant: Conforms to RFCs 5389, 5769, 5780, 5766, 6062, 6156, 5245, 5768, 6336, 6544, 5928 over UDP, TCP, TLS, and DTLS.

  8. Multi‑Tenancy: Create multiple credentials and separate the usage by customer, or different apps. Get Usage logs, billing records and threshold alerts.

  9. Enterprise Reliability: 99.999% Uptime with SLA.

  10. Enterprise Scale: With no limit on concurrent traffic or total traffic. Metered TURN Servers provide Enterprise Scalability

  11. 5 GB/mo Free: Get 5 GB every month free TURN server usage with the Free Plan

  12. Runs on port 80 and 443

  13. Support TURNS SSL to allow connections through deep packet inspection firewalls.

  14. Supports both TCP and UDP

  15. Free Unlimited STUN

版本声明 本文转载于:https://dev.to/alakkadshaw/webrtc-sfu-the-complete-guide-4eh5?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • 网页抓取 - 有趣!
    网页抓取 - 有趣!
    一个很酷的术语: CRON = 按指定时间间隔自动安排任务的编程技术 网络什么? 在研究项目等时,我们通常会从各个网站编写信息 - 无论是日记/Excel/文档等。 我们正在抓取网络并手动提取数据。 网络抓取正在自动化这一过程。 例子 当在网上搜索运动鞋时,它会显示包...
    编程 发布于2024-11-06
  • 感言网格部分
    感言网格部分
    ?在学习 CSS 网格时刚刚完成了这个推荐网格部分的构建! ?网格非常适合创建结构化布局。 ?现场演示:https://courageous-chebakia-b55f43.netlify.app/ ? GitHub:https://github.com/khanimran17/Testimonia...
    编程 发布于2024-11-06
  • 为什么 REGISTER_GLOBALS 被认为是 PHP 中的主要安全风险?
    为什么 REGISTER_GLOBALS 被认为是 PHP 中的主要安全风险?
    REGISTER_GLOBALS 的危险REGISTER_GLOBALS 是一个 PHP 设置,它允许所有 GET 和 POST 变量在 PHP 脚本中用作全局变量。此功能可能看起来很方便,但由于潜在的安全漏洞和编码实践,强烈建议不要使用它。为什么 REGISTER_GLOBALS 不好?REGIS...
    编程 发布于2024-11-06
  • Nodemailer 概述:在 Node.js 中轻松发送电子邮件
    Nodemailer 概述:在 Node.js 中轻松发送电子邮件
    Nodemailer 是一个用于发送电子邮件的 Node.js 模块。以下是快速概述: Transporter:定义电子邮件的发送方式(通过 Gmail、自定义 SMTP 等)。 const transporter = nodemailer.createTransport({ ... }); ...
    编程 发布于2024-11-06
  • JavaScript 中的轻松错误处理:安全赋值运算符如何简化您的代码
    JavaScript 中的轻松错误处理:安全赋值运算符如何简化您的代码
    JavaScript 中的错误处理可能很混乱。将大块代码包装在 try/catch 语句中是可行的,但随着项目的增长,调试就变成了一场噩梦。幸运的是,有更好的方法。输入 安全赋值运算符 (?=) - 一种更干净、更有效的错误处理方法,使代码保持可读性并简化调试。 什么是安全赋值运算符...
    编程 发布于2024-11-06
  • Javascript 很难(有悲伤)
    Javascript 很难(有悲伤)
    这将是一个很长的阅读,但让我再说一遍。 JAVASCRIPT很难。上次我们见面时,我正在踏入 Javascript 的世界,一个眼睛明亮、充满希望的程序员踏入野生丛林,说“这能有多难?”。我错得有多离谱??事情变得更难了,我(勉强)活了下来,这是关于我的旅程的一个小混乱的故事。 变量:疯狂的开始 ...
    编程 发布于2024-11-06
  • ## 您可以在不使用 JavaScript 的情况下使用 CSS 创建饼图分段吗?
    ## 您可以在不使用 JavaScript 的情况下使用 CSS 创建饼图分段吗?
    使用 CSS 在圆中分段使用 border-radius 在 CSS 中创建圆是一种常见的做法。但是,我们可以通过分段(类似于饼图)实现类似的效果吗?本文深入研究了仅通过 HTML 和 CSS 实现此目的的方法,不包括使用 JavaScript。生成相等大小的段相等大小段的一种方法涉及生成以下内容的...
    编程 发布于2024-11-06
  • 从头开始构建一个小型矢量存储
    从头开始构建一个小型矢量存储
    With the evolving landscape of generative AI, vector databases are playing crucial role in powering generative AI applications. There are so many vect...
    编程 发布于2024-11-06
  • 如何在Chrome中使用AI实验API
    如何在Chrome中使用AI实验API
    要在 Chrome 中使用实验性 AI API,请按照以下步骤操作: 硬件要求 4GB 内存 GPU可用 至少 22GB 空间 Windows 10.11 或 macOS Ventura 或更新版本(无 Linux 规范) 尚不支持: Chrome操作系统 Chrome iOS Ch...
    编程 发布于2024-11-06
  • 评论:Adam Johnson 的《Boost Your Django DX》
    评论:Adam Johnson 的《Boost Your Django DX》
    书评很微妙。您不想破坏它,但您也想让潜在读者体验一下所期待的内容。这是提供背景和保持兴趣之间的巧妙平衡。我试图在这篇评论中达到这种平衡,为您提供足够的内容来吸引您,而不透露太多。 一个小背景故事:我第一次从 Djangonaut Space 的好朋友 Tim 那里听说这本书,并将其添加到我的阅读列表...
    编程 发布于2024-11-06
  • 如何对数组元素进行分组并组合多维数组中另一列的值?
    如何对数组元素进行分组并组合多维数组中另一列的值?
    按列对数组元素进行分组并组合另一列中的值给定一个包含两列嵌套数组的数组,任务是将基于特定列的子数组,并将每个组中另一列的值连接起来,生成一个以逗号分隔的列表。考虑以下示例数组:$array = [ ["444", "0081"], ["...
    编程 发布于2024-11-06
  • 三个新添加的例外功能
    三个新添加的例外功能
    从 JDK 7 开始,异常处理已扩展为三个新功能:自动资源管理、多重捕获和更准确的重新抛出。 多重catch允许您使用同一个catch子句捕获多个异常,避免代码重复。 要使用多重捕获,请指定由 | 分隔的异常列表。在 catch 子句中。每个参数都是隐式最终参数。 用法示例:catch(final...
    编程 发布于2024-11-06
  • 如何修复运行 ES6 代码时出现“意外的令牌导出”错误?
    如何修复运行 ES6 代码时出现“意外的令牌导出”错误?
    “排除意外的令牌导出错误”尝试在项目中执行 ES6 代码时,可能会出现“意外的令牌导出”错误。此错误表明所使用的环境不支持 ES6 模块中使用的导出关键字语法。错误详细信息以下代码片段举例说明了错误的来源: export class MyClass { constructor() { c...
    编程 发布于2024-11-06
  • 即使卸载后,VSCode 扩展也不会从文件系统中删除,我创建了一个解决方案!
    即使卸载后,VSCode 扩展也不会从文件系统中删除,我创建了一个解决方案!
    所以这是基于 vscode 的编辑器的问题。即使您卸载了扩展程序,它也会保留在文件系统中,并随着时间的推移堵塞您的系统。我创建了一个简单的解决方案。运行此 python 脚本将删除 vscode 上未安装的扩展。 它适用于 VS Code、VS Code Insiders,也适用于 VSCodiu...
    编程 发布于2024-11-06
  • 通过 GitHub Actions 按计划更新网站内容
    通过 GitHub Actions 按计划更新网站内容
    我想分享我构建一个自我可持续的内容管理系统的旅程,该系统不需要传统意义上的内容数据库。 问题 该网站的内容(博客文章和书签)存储在 Notion 数据库中: 带书签的数据库 –  Notion UI 我试图解决的问题是不必在添加每个书签后手动部署网站。最重要的是 - 保持托管尽可能便...
    编程 发布于2024-11-06

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3