logo
Video Call
On this page

Traffic Control

2024-11-13

Feature Introduction

Traffic control refers to the SDK dynamically adjusting the bitrate, frame rate, and resolution of video publishing, as well as audio bitrate, based on the current network status of the local and remote ends, automatically adapting to the current network environment and network fluctuations, thereby ensuring smooth audio and video publishing.

The principle of traffic control is to model the user's network environment and estimate their uplink bandwidth based on the current network situation. If the current uplink bandwidth is less than the set publishing bitrate, the SDK will progressively reduce it from video bitrate, resolution, frame rate, and audio bitrate through the configured options to reduce the final uplink bitrate of publishing and ensure the smoothness of live streaming. 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 end notifies the publishing end of its network situation, and the publishing end estimates its own uplink bandwidth and the downlink bandwidth of the playing end, and takes the minimum value from the uplink and downlink bandwidth estimates to adjust its own uplink bitrate to ensure the smoothness of co-hosting.

Usage Steps

1 Enable traffic control

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

Warning
  • Usage restrictions: Only supports RTC publishing.
  • When traffic control is disabled, the set traffic control property property will also become invalid.
  • When the traffic control property contains adaptive (reducing) video resolution AdaptiveResolution, only initial resolutions with "16:9" or "4:3" ratios are supported. If the initial resolution is other values, the 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, the adaptive (reducing) video resolution will affect "MP4" format file recording. In this case, you need to change the format to "FLV". For detailed operations, please refer to Audio and Video Recording.
// Enable traffic control, and simultaneously enable adaptive (reducing) video frame rate and adaptive (reducing) video resolution
[ZegoExpressEngine sharedEngine] enableTrafficControl:YES property:ZegoTrafficControlPropertyAdaptiveFPS | ZegoTrafficControlPropertyAdaptiveResolution];

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 video bitrate for traffic control (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. This allows the SDK to not send video or send video at an extremely low frame rate when the network does not reach 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 only takes effect 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 an extremely low frame rate
[[ZegoExpressEngine sharedEngine] setMinVideoBitrateForTrafficControl:200 mode:ZegoTrafficControlMinVideoBitrateModeUltraLowFPS];
2024-11-13

Previous

Supplemental Enhancement Information (SEI)

Next

Cloud Proxy

On this page

Back to top