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

},

相关推荐
任小栗21 小时前
【实战干货】Vue3 + WebRTC + SIP + AI 实现全自动语音接警系统(远程流获取+实时ASR+TTS回播)
人工智能·webrtc
runner365.git1 天前
如何使用RTCPilot--跨平台WebRTC开源服务
webrtc·音视频开发
runner365.git2 天前
RTC实现VoiceAgent(二)
大模型·webrtc·实时音视频·voiceagent
runner365.git3 天前
WebRTC实现VoiceAgent智能体
webrtc
runner365.git3 天前
RTCPilot的信令流程
webrtc·音视频开发
runner365.git3 天前
如何使用RTCPilot配置一个集群RTC服务
webrtc·实时音视频·音视频开发
深念Y4 天前
从WebSocket到WebRTC,豆包级实时语音交互背后的技术演进
websocket·网络协议·实时互动·webrtc·语音识别·实时音视频
AI视觉网奇6 天前
webrtc 硬编码
ffmpeg·webrtc
REDcker6 天前
WebRTC 接收端音频流畅低延迟播放:原理与源码对照(NetEQ / Opus)
音视频·webrtc
SUNNY_SHUN6 天前
LiveKit Agents:基于WebRTC的实时语音视频AI Agent框架(9.9k Star)
人工智能·github·webrtc