logo
On this page

Traffic Control

2024-11-13

Feature Overview

Traffic control enables the SDK to dynamically adjust the bitrate, frame rate, and resolution of video publishing, as well as audio bitrate, based on its own and the remote's current network environment status, automatically adapting to the current network environment and network fluctuations, thereby ensuring smooth video publishing.

The principle of traffic control is based on the current network situation to model the user's network environment and estimate their uplink bandwidth. If the current uplink bandwidth is less than the set publishing bitrate, the configured options will be used to gradually reduce from video bitrate, resolution, frame rate, and audio bitrate respectively to reduce the final uplink bitrate of publishing, ensuring the fluency of live streaming. After the network environment returns to normal, the uplink bitrate will also recover to the initial set value.

Only in 1-to-1 call scenarios, the SDK will automatically enable downlink traffic control. The playing side notifies the publishing side of its network situation. The publishing side estimates its own uplink bandwidth and the playing side's downlink bandwidth, and takes the minimum value from the uplink and downlink bandwidth estimates to adjust its own uplink bitrate, ensuring the fluency of the call.

Difference Between Traffic Control and Layered Video Coding

  • Traffic control: Oriented to the publishing side. When the publishing side's network environment is poor, in order to ensure normal publishing, it actively reduces the uplink bitrate of publishing.
  • Layered video coding: Oriented to the playing side. When the publishing side publishes a stream with multiple layers of different quality, the playing side can autonomously choose the video quality of playing based on its own network environment to adapt to downlink bandwidth.

Prerequisites

Before setting network adaptation, please ensure that basic audio/video publishing and playing functions have been implemented in your project. For details, please refer to Quick Start - Integration.

Usage Steps

1 Enable Traffic Control

Before publishing, call the enableTrafficControl interface to enable traffic control through the enable parameter, and set adjustable traffic control properties (bitrate, frame rate, resolution) through the property parameter, supporting multiple selections. The default value is ADAPTIVE_FPS, i.e., dynamically adjusting frame rate. When uplink bandwidth is insufficient, the SDK will automatically adjust the set properties to adapt to uplink bandwidth based on the current network environment.

In different scenarios, traffic control property settings are different. For example, show live streaming scenarios need to ensure video fluency, so resolution adaptation is recommended; education scenarios need to ensure clarity, so frame rate adaptation is recommended.

Warning
  • After closing the traffic control switch, the set traffic control property property will also become invalid.
  • When the traffic control property contains adaptive resolution ADAPTIVE_RESOLUTION, only initial resolutions with 16:9 or 4:3 ratios are supported. If the initial resolution is other values, adaptive resolution cannot take effect, and the SDK will downgrade to directly reducing encoding bitrate. If local media recording is needed during using traffic control function, adaptive resolution will affect MP4 format file recording. At this time, the format needs to be changed to FLV.
// Enable traffic control, and simultaneously enable resolution and frame rate adaptation
ZegoExpressSDK::getEngine()->enableTrafficControl(true, ZEGO_TRAFFIC_CONTROL_PROPERTY_ADAPTIVE_FPS | ZEGO_TRAFFIC_CONTROL_PROPERTY_ADAPTIVE_RESOLUTION);

In different scenarios, traffic control property settings are different. For example, show live streaming scenarios need to ensure video fluency, so resolution adaptation is recommended; education scenarios need to ensure clarity, so frame rate adaptation is recommended.

  • After closing the traffic control switch, the set traffic control property property will also become invalid.
  • When the traffic control property contains adaptive resolution ADAPTIVE_RESOLUTION, only initial resolutions with 16:9 or 4:3 ratios are supported. If the initial resolution is other values, adaptive resolution cannot take effect, and the SDK will downgrade to directly reducing encoding bitrate. If local media recording is needed during using traffic control function, adaptive resolution will affect MP4 format file recording. At this time, the format needs to be changed to FLV.
// Enable traffic control, and simultaneously enable resolution and frame rate adaptation
ZegoExpressSDK::getEngine()->enableTrafficControl(true, ZEGO_TRAFFIC_CONTROL_PROPERTY_ADAPTIVE_FPS | ZEGO_TRAFFIC_CONTROL_PROPERTY_ADAPTIVE_RESOLUTION);

2 Set Minimum Video Bitrate for Traffic Control

After enabling traffic control, call the setMinVideoBitrateForTrafficControl method to set the minimum video bitrate (default value is 0). This enables the SDK to use the method set here to determine the video sending mode (not sending video or sending at extremely low frame rate) when the network does not reach the minimum bitrate for sending video.

Note: Can be called at any time after initializing the SDK, but needs traffic control to be enabled for this setting to take effect.

// After enabling flow control, when uplink and downlink bandwidth is lower than 200kbps, continue sending video data at extremely low frame rate
ZegoExpressSDK::getEngine()->setMinVideoBitrateForTrafficControl(200, ZEGO_TRAFFIC_CONTROL_MIN_VIDEO_BITRATE_MODE_ULTRA_LOW_FPS);

API Reference List

MethodDescription
enableTrafficControlStart or stop traffic control
setMinVideoBitrateForTrafficControlSet minimum video bitrate for traffic control

Previous

Supplemental Enhancement Information (SEI)

Next

Cloud Proxy

On this page

Back to top