webrtc基于DTLS的端口复用技术

DTLS协议:

DTLS(Datagram Transport Layer Security)数据包安全传输协议,用于在不可靠的数据包传输协议上(如UDP)提供数据的安全传输。

UDP多路复用:

一个UDP多路复用,被用来处理共享同一个UDP端口的多个并发的UDT连接。类似同一个tcp port上创建多个socket connection.

UDP多路复用,根据包头的目标Socket ID,将接收到的不同的UDT包分发给相应 的UDT Socket。

换言之,多个UDT Socket绑定到不同的UDP端口时,必然被各自的UDP多路复用 分发处理。

一个UDP多路复用维护两个队列:发送队列和接收队列。

发送队列包含Socket信息的链表。链表节点的Socket必须包含至少一个计划发送的 信息包。Sockets按照下一个信息包发送的时间进行排序。

发送队列维护一个高性能的计时器。当队列的Socket包发送时间到时,队列头部的 Socket的包被发送,并且头部的Socket从队列中删除。如果头部Socket包含多个计划信 息包时,该头部Socket将被重新插入到发送队列里。

接收队列读取输入的信息包,并分发信息包到相应的UDT Socket。如果目标Socket ID 是0,信息包将被分发给当前正在监听的Socket,或者被分发给会合的连接 (Rendezvous connection)。

和发送队列相似,接收队列也包含等待接收信息包的Socket信息链表。如果队列的任 意一个Socket的SYN间隔时间到时,接收队列会检测该Socket的"任意一个定时器"(参 见定时器)是否期满。

ICE其实不算一个传输协议,它更像是标识协议,一般指Binding Request和Response,会在里面带有IP和优先级信息,来标识地址和信道的信息,用于多条信道的选择,比如4G和WiFi都很好时优先选谁。

还会用作会话的心跳,客户端会一直发送这个消息。因此ICE对于负载均衡没有作用,但是它可以用来标识会话,和QUIC的ConnectionID作用类似,因此在经过Load Balance时可以起到识别会话的作用,特别是客户端的网络切换时。

而TURN协议其实是对Cloud Native非常不友好的协议,因为它是需要分配一系列的端口,用端口来区分用户,这种是在私有网络中的做法,假设端口无限,而公有云上端口往往是受限的,比如需要经过Load Balance这个系统时,端口就是有限的。

mediasoup支持:

* Multi-stream: multiple audio/video streams over a single ICE + DTLS transport.

* ICE / DTLS / RTP / RTCP over UDP and TCP.

从srs的配置文件可以更为清晰地看到udp端口复用规则。

#############################################################################################

WebRTC server section

#############################################################################################

rtc_server {

The udp listen port, we will reuse it for connections.

Overwrite by env SRS_RTC_SERVER_LISTEN

default: 8000

listen 8000;

For WebRTC over TCP directly, not TURN, see https://github.com/ossrs/srs/issues/2852

Some network does not support UDP, or not very well, so we use TCP like HTTP/80 port for firewall traversing.

tcp {

Whether enable WebRTC over TCP.

Overwrite by env SRS_RTC_SERVER_TCP_ENABLED

Default: off

enabled off;

The TCP listen port for WebRTC. Highly recommend is some normally used ports, such as TCP/80, TCP/443,

TCP/8000, TCP/8080 etc. However SRS default to TCP/8000 corresponding to UDP/8000.

Overwrite by env SRS_RTC_SERVER_TCP_LISTEN

Default: 8000

listen 8000;

}

The protocol for candidate to use, it can be:

udp Generate UDP candidates. Note that UDP server is always enabled for WebRTC.

tcp Generate TCP candidates. Fail if rtc_server.tcp(WebRTC over TCP) is disabled.

all Generate UDP+TCP candidates. Ignore if rtc_server.tcp(WebRTC over TCP) is disabled.

Note that if both are connected, we will use the first connected(DTLS done) one.

Overwrite by env SRS_RTC_SERVER_PROTOCOL

Default: udp

protocol udp; //缺省用udp作为webrtc transport

We listen multiple times at the same port, by REUSEPORT, to increase the UDP queue.

Note that you can set to 1 and increase the system UDP buffer size by net.core.rmem_max

and net.core.rmem_default or just increase this to get larger UDP recv and send buffer.

Overwrite by env SRS_RTC_SERVER_REUSEPORT

default: 1

reuseport 1; //启用udp端口复用。

}

mediasoup对udp端口复用配置如下:

webRtcTransport: {

// listenIps: LISTEN_IP,

enableUdp: true, //配置为all(tcp+udp)

enableTcp: true,

preferUdp: true, //default用udp

preferTcp: false

},

相关推荐
中屹指纹浏览器svip2 天前
WebRTC泄露是什么,怎么关闭?
webrtc
海边捡石子3 天前
从零设计一个通用智能电话平台:FreeSWITCH + ESL + AI 实战架构
人工智能·架构·webrtc
音视频牛哥3 天前
不换摄像机,也能接入 WebRTC?SmartMediaKit RTSP/RTMP 转 WHIP 技术实践
音视频·webrtc·smartmediakit·rtsp转whip·rtmp转whip·whip推流·rtsp转webrtc播放
直播技术开发交流5 天前
Android 端 WHIP 协议推流技术实践:相机/录屏/多路转发WHIP实现测试
webrtc·android whip·rtsp转whip·毫秒级实时媒体流·whip低延时推送·whip推送实现·rtsp转webrtc
程序员阿明7 天前
docker搭建视频流服务go2rtc,webRTC
docker·容器·webrtc
O。O蛋黄酥啊10 天前
实时语音 Agent 开发完全指南:从 ASR/TTS 到 WebRTC/VAD 的链路拆解
大模型·webrtc·语音识别·tts·asr
海水冷却11 天前
WebRTC 视频通话:从裸写信令到 30 分钟上线
音视频·webrtc
PiaoKe___11 天前
云手机底层架构与工程实践:从 KVM/容器到 WebRTC 串流
智能手机·架构·webrtc
znnnk11 天前
【网络优化】减少B站直播卡顿的上行占用:AdGuard nowebrtc规则 / WebRTC Control 实测
服务器·网络·webrtc·直播·bilibili·adguard
平行云PVT11 天前
国产信创实时云渲染解决方案:如何实现数字孪生与三维应用云化部署?
unity·webrtc·unreal engine·实时云渲染·国产信创·摩尔线程·砺算科技