First on the conclusion, when using the browser and the interaction of Janus, RTCPeerConnection. BundlePolicy final video and audio transmission is the use of a port, the influence of different values note is ICE negotiation phase, it is recommended to use"max-bundle"Improved ICE negotiation speed.

The official definition of

RTCPeerConnection. BundlePolicy specifies the remote peer is not compatible with the standard SDP BUNDLE when how to deal with the candidate for negotiation, the default value is “balanced”.

const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });
Copy the code

If the remote endpoint is perceived by the BUNDLE, all media tracks and data channels are tied to a single transmission at negotiation completion, regardless of the policy used, and any redundant transmissions originally created are closed at this point.

All browser implementations are bundle-aware.

Enumeration Value Description

Balanced (default) : The ICE agent collects ICE options for each used media type (video, audio, and data). If the remote endpoint does not support bundling, only one audio and video track is negotiated on a separate transmission.

“Max-compat” : The ICE agent collects ICE options for each track. If the remote endpoint does not support bundling, all media tracks are negotiated on a separate transmission.

“Max-bundle” : The ICE agent collects only one track candidate. If the remote endpoint does not support bundling, only one media track is negotiated.

SDP BUNDLE

When studying the RFC documentation for RTP, section 2.2 explains that if audio and video media are used in a meeting, they use separate RTP sessions to transmit RTCP packets, with each media using two different UDP port pairs or multicast addresses.

Datatracker.ietf.org/doc/html/rf…

In this way, if five people are in a meeting at the same time, each browser needs to negotiate two ports for releasing streams and 4×2 ports for receiving streams. A total of 10 ports need to be negotiated. When communicating with the back end, the feedback is that the same port is used for video and audio transmission. Go to section 5.2 of the RFC documentation, which describes how to reuse RTP sessions.

Datatracker.ietf.org/doc/html/rf…

In the scenario where RTP sessions are reused and five meetings are held, each browser needs to negotiate five ports. In the Janus implementation, you can notify Janus not to send videos or audio to the client through signaling, or you can only subscribe to videos or audio.

Understanding of the values

When “max-bundle” is used, only one track is negotiated to collect candidates, which is the fastest and least compatible. If the remote end does not support SDP bundling, only one video or audio track can be transmitted.

Using “max-compat” to collect candidates for each track is the slowest, the least compatible, and can transmit all media data when the remote end does not support it.

In use, both Janus and the browser support SDP bundling, so the final transport will use the same port. The difference in value affects the ICE negotiation phase, and the use of “max-bundle” during use.

Verify in the actual environment

Use a Janus server and a computer for verification, looking at the candidate information reported by the browser in the signaling data

Backup location of signaling and captured packet files

  • Link: pan.baidu.com/s/15ypf3al6…
  • Extract code: GTHC
  • Copy this section of content after opening Baidu web disk mobile App, operation more convenient oh

max-bundle

Candidate :360945858 1 UDP 2122260223 172.25.64.1 49885 TYp host generation 0 ufrag LzwC networker id 1 Candidate :6840418 1 Udp 2122194687 192.168.0.23 49886 typ host generation 0 ufrag LzwC network-id 2Copy the code

max-compat

Candidate :360945858 1 UDP 2122260223 172.25.64.1 53782 TYp host generation 0 ufrag HtWM networker - ID 1 Candidate :6840418 1 Udp 2122194687 192.168.0.23 53783 TYp host generation 0 ufrag HtWM networker 2 Candidate :360945858 1 UDP 2122260223 172.25.64.1 53784 typ host generation 0 ufrag HtWM networker-id 1 Candidate :6840418 1 UDP 2122194687 192.168.0.23 53785 Typ host generation 0 ufrag HtWM network-id 2 Candidate :1526752306 1 TCP 1518280447 172.25.64.1 9 Typ host tcptype Active Generation 0 ufrag HtWM network-id 1 Candidate :1324063890 1 TCP 1518214911 192.168.0.23 9 typ host tcpType active  generation 0 ufrag HtWM network-id 2Copy the code

Caught analysis

According to the candidate information reported by the browser, when max-bundle is used, only one port is negotiated for each IP address. When max-compat is used, multiple ports are negotiated for each IP address (3 for the first time and 2 for the second time).

Max-compat was used for interaction and Wireshark was used for packet capture analysis. In the candidate information reported by the browser, 192.168.0.23 negotiated port 53707 and port 53709, but only 53707 was used for interaction. Description Failed to capture the packet from port 53709.

conclusion

When using the browser and the interaction of Janus, RTCPeerConnection bundlePolicy final video and audio transmission is the use of a port, the influence of different values note is ICE negotiation phase, it is recommended to use “Max – bundle” raising the speed of the ICE to negotiate.

Reference documentation

  • RTCBundlePolicy enumeration value: w3C. github. IO /webrtc-pc/#…
  • MDN RTCBundlePolicy Enumeration value: developer.mozilla.org/zh-CN/docs/…
  • SDP binding: webrtcstandards.info/sdp-bundle/