For network protocols, there are usually two things to do: 1) establish a connection and 2) transfer data, and WebRTC is no exception.

Assuming that the two ends of the WebRTC application are already connected, it is only a matter of transferring the data.

WebRTC supports the transmission of audio and video data and custom application data. Multiple protocols are involved, including UDP, RTP/SRTP, RTCP/SRTCP, DTLS, and SCTP.

These protocols have similar names, which can be confusing. To summarize:

  1. Protocols for transmission of audio and video data: UDP, DTLS, RTP/SRTCP;
  2. Protocols for transmitting user-defined application data: UDP, DTLS, and SCTP.

Here’s a quick overview of what these protocols do, how they differ, and how they relate.

Encryption channel establishment: UDP, DTLS

For WebRTC applications, both audio and video data and custom application data must be transmitted over encrypted channels. DTLS is similar to TLS. It encrypts channels on the basis of UDP.

The main purpose of DTLS is to enable communication parties to negotiate keys for data encryption and decryption.

  1. Communication parties: use DTLS handshake to negotiate and generate a pair of keys.
  2. Sender: encrypts data;
  3. Sender: Transmits encrypted data through UDP.
  4. Receiver: decrypts encrypted data;

Audio and video data transmission: RTP/SRTP, RTCP/SRTCP

RTP, RTCP, RTP, RTCP

  1. Realtime Transport Protocol (RTP) : used to transmit real-time data, such as audio and video data.
  2. RTP Trasport Control Protocol (RTCP) : RTP transmission Control Protocol defined in the same RFC. It monitors the quality of data transmission and provides feedback to the data sender.

In other words:

  1. RTP is used to transmit audio and video data.
  2. RTCP is used to transmit (quality) control data; For example, the WebRTC monitors the transmission quality and synchronizes the session between the two parties. In this way, WebRTC can dynamically adjust the transmission quality, such as the transmission rate and video bit rate.

For SRTP and SRTCP, add S(Secure) on the basis of RTP and RTCP respectively to indicate security. This is what DTLS does.

Combined with the previous content, summarize the sending process of audio and video data:

  1. Communication parties: use DTLS handshake to negotiate and generate a pair of keys.
  2. Data sender: encapsulate audio and video data into RTP packets and control data into RTCP packets;
  3. Data sender: Encrypts RTP packets and RTCP packets using encryption keys to generate SRTP packets and SRTCP packets.
  4. Data sender: Transmits SRTP packets and SRTCP packets through UDP.

Note: SRTP/SRTCP packets contain other information besides encrypted data. Details are not displayed here.

Custom application data transmission: SCTP

Stream Control Transmission Protocol (SCTP) : Stream Control Transmission Protocol.

As mentioned earlier, RTP/RTCP is primarily used for audio and video transmission and is designed for streaming media. The SCTP protocol is used in WebRTC for data transmission of custom applications.

Similarly, SCTP relies on the encrypted channel established by DTLS. For sending custom application data, the flow is as follows:

  1. Communication parties: use DTLS handshake to negotiate and generate a pair of keys.
  2. Data sender: encrypts user-defined application data with a key to generate SCTP packets.
  3. Data sender: Transmits SCTP packets through UDP.

Write in the back

For the sake of explanation, many details of the agreement have been skipped. Some details may not be precise enough. Interested students can conduct further research, such as the following questions:

  1. UDP is used in the transport layer, and UDP itself is not reliable. Then, how to ensure the timing and quality of audio and video data, custom user data?
  2. RTP is used to transmit audio and video data. Why RTCP?
  3. Why is RTP not suitable for transferring custom user data?
  4. How does SCTP balance transmission efficiency and quality at the protocol level? How to achieve efficient delivery of custom data?
  5. other

A link to the

RTP: A Transport Protocol for Real – Time Applications tools.ietf.org/html/rfc355…

The Stream Control Transmission Protocol tools.ietf.org/html/rfc496…

Datagram Transport Layer Security tools.ietf.org/html/rfc434…

Github blog: github.com/chyingp/blo… Sina weibo: weibo.com/chyingp standing cool home page: www.zcool.com.cn/u/346408/