- Documentation
- Video Call
- Upgrade using advanced features
- Advanced features
- Improve video quality
- Configure bandwidth management
Configure bandwidth management
Introduction
This document describes how to enable and configure the traffic control feature for ZEGOCLOUD’s SDKs.
Network conditions can change at any time during a call or a live streaming session. To maintain smooth stream publishing even when network conditions degrade, you can enable the traffic control feature of the SDK to dynamically adjust the uplink bitrate to adapt to the current network conditions. At the same time, you can also specify which of the following encoding parameters should be changed to adjust the uplink bitrate:
- Video bitrate
- Video frame rate
- Video resolution
- Audio bitrate
If the estimated uplink bandwidth is lower than the configured stream publishing bitrate, the SDK gradually lowers the specified parameters to reduce the uplink bitrate. When the network conditions improve, the SDK then adjusts those parameters to bring the uplink bitrate back to the configured value.
In one-on-one real-time interactions, the SDK automatically enables downlink traffic control. In such cases, the SDK on the stream subscriber side sends the information of the downlink network conditions to the stream publisher. The SDK on the stream publisher side then adjusts its uplink bitrate to fit the lower one of the estimated uplink bandwidth of its own and the estimated downlink bandwidth of the stream subscriber.
The difference between traffic control and scalable video coding:
Traffic control: The control is performed for stream publishing. When the network condition is not ideal, the stream publisher adaptively adjusts its uplink bitrate accordingly to maintain smooth streaming.
Scalable video coding: The control is performed for stream playback. With scalable video coding, the stream publisher encodes the video content into a bitstream with multiple quality layers. So each stream subscriber can choose to receive and decode the layers that best fit its downlink bandwidth. For more information, see Scalable video coding.
Prerequisites
Before you begin, make sure you complete the following:
Create a project in ZEGOCLOUD Admin Console and get the AppID and AppSign of your project.
Refer to the Quick Start doc to complete the SDK integration and basic function implementation.
Enable traffic control
To enable traffic control, call the enableTrafficControl
method before publishing any stream.
Here are some notes about how to set up the parameters of the method:
- The first parameter
enable
is a boolean. Set it totrue
to enable traffic control. - The second parameter
property
is an enum value ofZegoTrafficControlProperty
. The default value isADAPTIVE_FPS
, which means the SDK adjusts the uplink bitrate by adjusting the video frame rate. You can decide how to set up the traffic control property based on the needs of your use case. For example:- For social live streaming use cases, video smoothness takes priority over video quality. You can set
property
toADAPTIVE_RESOLUTION
, which means the SDK adjusts the uplink bitrate by adjusting the video resolution. - For online classroom use cases, video quality is usually more important. You can set
property
toADAPTIVE_FPS
, which means the SDK lowers the video frame rate but maintains the video quality when it needs to lower the uplink bitrate. - You can specify more than one value to the
property
parameter as needed.
- For social live streaming use cases, video smoothness takes priority over video quality. You can set
The traffic control feature is enabled by default. Generally, you don't have to pay special attention to its method.
Once you disable the traffic control feature, the value of the
property
parameter no longer takes effect. You need to set it up again next time you enable traffic control.The
property
valueZegoTrafficControlPropertyAdaptiveResolution
only works for videos with a 16:9 or 4:3 aspect ratio. For videos with other aspect ratios, the SDK can't adjust the resolution but will directly adjust the encoding bitrate.If you need to record the live stream as local files while traffic control is enabled, adjusting the video resolution will affect the recording in MP4 format, and you need to change the recording format to FLV. For more information about local recording, see Recording live streams as local files.
// Enable traffic control, and adjust the uplink bitrate by adjusting both the video resolution and frame rate.
ZegoExpressEngine.getEngine().enableTrafficControl(true, ADAPTIVE_RESOLUTION.value() | ADAPTIVE_FPS.value());
Advanced settings
You can call the setMinVideoBitrateForTrafficControl
method to set up a minimum video bitrate and specify what the SDK should do when the uplink bandwidth is not sufficient for this minimal video bitrate.
Similarly, you can call the setMinVideoFpsForTrafficControl
and setMinVideoResolutionForTrafficControl
methods to set up a minimum video frame rate and minimum resolution.
You can call these methods at any time after you initiate the SDK, but they only take effect after you enable the traffic control feature.
// After traffic control is enabled, when the uplink bandwidth is lower than 200kbps, continue to send video data at a very low frame rate.
ZegoExpressEngine.getEngine().setMinVideoBitrateForTrafficControl(200, ZegoTrafficControlMinVideoBitrateMode.ULTRA_LOW_FPS);