logo
Video Call
On this page

Traffic Control

2024-11-13

Feature Overview

Traffic control refers to the SDK dynamically adjusting the video publishing bitrate, frame rate, and resolution, as well as the audio bitrate, based on the local and peer network conditions, to automatically adapt to the current network environment and fluctuations, thereby ensuring smooth audio and video publishing.

The principle of traffic control is to model the user's network environment and estimate the uplink bandwidth based on current network conditions. If the current uplink bandwidth is less than the set publishing bitrate, the SDK will progressively reduce the video bitrate, resolution, frame rate, and audio bitrate according to the configured options to reduce the final uplink publishing bitrate and ensure the smoothness of the live stream. After the network environment returns to normal, the uplink bitrate will also recover to the initial set value.

When there is only one RTC publishing stream, only one RTC playing stream or only one L3 playing stream, the SDK will automatically enable downlink traffic control. The playing stream endpoint notifies its network conditions to the publishing stream endpoint, which estimates its own uplink bandwidth and the downlink bandwidth of the playing stream endpoint, and takes the minimum value from the uplink and downlink bandwidth estimates to adjust its own uplink bitrate to ensure the smoothness of the co-hosting.

Prerequisites

Before implementing traffic control, please ensure:

Usage Steps

1 Enable traffic control

Before publishing stream, call the enableTrafficControl interface to enable traffic control through the enable parameter, and set the adjustable traffic control properties (bitrate, frame rate, resolution) through the property parameter. Multiple options are supported, and the default value is ADAPTIVE_FPS, which means adaptive (reducing) video frame rate. When uplink bandwidth is insufficient, the SDK will reduce the final uplink publishing bitrate according to the current network environment and the set property parameter to adapt to the uplink bandwidth.

Warning
  • Usage restriction: Only supports RTC publishing streams.
  • When traffic control is disabled, the previously set traffic control properties property will also become invalid.
  • When the traffic control properties include adaptive (reducing) video resolution ADAPTIVE_RESOLUTION, only initial resolutions with "16:9" or "4:3" aspect ratios are supported. If the initial resolution is other values, adaptive (reducing) video resolution will not take effect, and the SDK will directly reduce the encoding bitrate. If you need to record local media while using the traffic control feature, adaptive (reducing) video resolution will affect "MP4" format file recording. In this case, you need to change the format to "FLV". For details, please refer to Audio and Video Recording.
// Enable traffic control, and simultaneously enable adaptive (reducing) video resolution and adaptive (reducing) video frame rate
ZegoExpressEngine.getEngine().enableTrafficControl(true, ADAPTIVE_RESOLUTION.value() | ADAPTIVE_FPS.value());

2 (Optional) Automatically adjust traffic control properties

The SDK will automatically set traffic control properties suitable for the scenario based on the scenario selected by the developer when creating the engine. For example, the show live streaming scenario needs to ensure video smoothness, so adaptive (reducing) video resolution is recommended; the education scenario needs to ensure clarity, so adaptive (reducing) video frame rate is recommended.

Warning

The SDK will determine the current traffic control properties based on the order of interface calls, and the later call takes effect. That is, if traffic control properties are first set through enableTrafficControl, and then setRoomScenario is called to set scenario, the traffic control properties will change according to scenario.

3 Set the minimum value for traffic control video bitrate (can be skipped for audio-only scenarios)

After enabling traffic control, call the setMinVideoBitrateForTrafficControl method to set the minimum video bitrate (default value is "0") and video sending mode, which allows the SDK to use the video sending mode set by this method (not sending video or sending at a very low frame rate) when the network does not meet the minimum bitrate for sending video.

Warning

You can call setMinVideoBitrateForTrafficControl at any time after initializing the SDK and before publishing stream startPublishingStream, but this setting takes effect only after traffic control is enabled.

// After enabling traffic control, when the uplink and downlink bandwidth is lower than 200 kbps, continue sending video data at a very low frame rate
ZegoExpressEngine.getEngine().setMinVideoBitrateForTrafficControl(200, ZegoTrafficControlMinVideoBitrateMode.ULTRA_LOW_FPS);

Previous

Supplemental Enhancement Information (SEI)

Next

Cloud Proxy

On this page

Back to top