Traffic control refers to the SDK dynamically adjusting the bitrate, frame rate, resolution, and audio bitrate of video streaming based on the local and remote network conditions. It automatically adapts to the current network environment and fluctuations to ensure smooth audio and video streaming.
The principle of traffic control is based on modeling and estimating the user's network environment based on the current network situation. If the current upload bandwidth is lower than the set streaming bitrate, the SDK will progressively reduce the video bitrate, resolution, frame rate, and audio bitrate in order to reduce the upload bitrate and ensure smooth live broadcasting. Once the network environment returns to normal, the upload bitrate will be restored to the initial setting.
When there is only one RTC publishing stream, one RTC playing stream or one L3 playing stream(1v1), the SDK will automatically enable downstream traffic control. The stream playing end informs the stream publishing end about its network conditions, and the stream publishing end estimates its own upload bandwidth and the downstream bandwidth of the playing end. It adjusts its upload bitrate based on the minimum value of the estimated upload and download bandwidths to ensure smooth communication.
Before publishing the stream, call the enableTrafficControl
interface to enable traffic control by setting the enable
parameter to true. You can also set adjustable traffic control properties (bitrate, frame rate, resolution) through the property
parameter. Multiple options can be selected, with the default value being ADAPTIVE_FPS
, which means adaptive (reduced) video frame rate. When the upstream bandwidth is insufficient, the SDK will reduce the upstream bitrate of the publishing stream based on the current network environment and the property
parameter settings to adapt to the upstream bandwidth.
property
will also be invalidated.ADAPTIVE_RESOLUTION
, only "16:9" or "4:3" aspect ratios are supported as the initial resolution. If the initial resolution is set to other values, the adaptive (reduced) video resolution will not take effect, and the SDK will directly reduce the encoding bitrate.// Enable traffic control and enable adaptive (reduced) video frame rate and adaptive (reduced) video resolution at the same time
ZegoExpressEngine.getEngine().enableTrafficControl(true, ADAPTIVE_RESOLUTION.value() | ADAPTIVE_FPS.value());
The SDK will automatically set traffic control properties suitable for the selected scene scenario
based on the scene selected by the developer when creating the engine. For example, in the Live Broadcasting scene, smooth video streaming is required, so it is recommended to choose adaptive (reduced) video resolution; in the Education scene, clarity is required, so it is recommended to choose adaptive (reduced) video frame rate.
The SDK determines the current traffic control properties based on the order of interface calls, and the properties set by the later call take effect. That is, if the traffic control properties are set through enableTrafficControl
first, and then setRoomScenario
is called to set scenario
, the traffic control properties will change according to scenario
.
After enabling traffic control, call the setMinVideoBitrateForTrafficControl method to set the minimum video bitrate (default value is "0") and the 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 video bitrate for sending.
You can call setMinVideoBitrateForTrafficControl at any time after initializing the SDK and before starting to publish the stream startPublishingStream, but this setting will only take effect after traffic control is enabled.
// After enabling traffic control, when the upstream and downstream bandwidth is lower than 200 kbps, continue to send video data at an extremely low frame rate
ZegoExpressEngine.getEngine().setMinVideoBitrateForTrafficControl(200, ZegoTrafficControlMinVideoBitrateMode.ULTRA_LOW_FPS);