logo
Video Call
On this page

Network Speed Test

2024-01-02

Feature Overview

ZEGO provides network speed test functionality, which can detect uplink and downlink network speeds before users publish/play streams, to determine the bitrate of audio and video streams suitable for publishing/playing under current network conditions.

When the uplink speed test results show a high packet loss rate, it is recommended to use methods such as lowering resolution or lowering frame rate to reduce the publish stream bitrate to ensure normal publishing; when the downlink speed test results show a high packet loss rate, it is recommended to use the Layered Video Encoding feature provided by the SDK to play low-bitrate streams to ensure normal playing.

When the following situations occur in developers' business, ZEGO recommends using the SDK's network speed test feature:

  • In call scenarios, network quality assessment needs to be performed.

  • In education scenarios, pre-class network detection needs to be performed.

  • In live streaming scenarios, network connection speed testing needs to be performed.

The basic principle of network speed test is shown in the following figure:

Example Source Code Download

Please refer to Download Example Source Code to get the source code.

For related source code, please check the files in the "/ZegoExpressExample/Others/src/main/java/im/zego/others/networkandperformance" directory.

Prerequisites

Before implementing the network speed test feature, please ensure:

Usage Steps

1 Listen for speed test callbacks

Before starting the speed test, you can first set speed test related callbacks.

// Set speed test related callbacks
ZegoExpressEngine.getEngine().setEventHandler(new IZegoEventHandler() {
    @Override
    // Network speed test quality callback
    public void onNetworkSpeedTestQualityUpdate(ZegoNetworkSpeedTestQuality quality, ZegoNetworkSpeedTestType type) {

    }

    @Override
    // Network speed test exception callback
    public void onNetworkSpeedTestError(int errorCode, ZegoNetworkSpeedTestType type) {

    }
});

2 Start speed test

Create an instance of ZegoNetworkSpeedTestConfig network speed test configuration, set whether to perform uplink and downlink speed tests and expected bitrate according to the actual situation, and call the startNetworkSpeedTest interface to enable network speed test.

Note

After calling the startNetworkSpeedTest interface to enable speed test, it supports speed test for 30 seconds by default (if you need to adjust the duration, please contact ZEGO Technical Support to modify the dynamic configuration). After timeout, the speed test will be forcibly ended. If you need to continue the speed test, please call this interface again.

ZegoNetworkSpeedTestConfig config =new ZegoNetworkSpeedTestConfig();

// Perform uplink speed test, specify expected publish stream bitrate
config.testUplink = true;
config.expectedUplinkBitrate = ZegoExpressEngine.getEngine().getVideoConfig().bitrate;

// Perform downlink speed test, specify expected play stream bitrate
config.testDownlink = true;
config.expectedDownlinkBitrate = ZegoExpressEngine.getEngine().getVideoConfig().bitrate;

// Start speed test, default callback interval is 3 seconds
engine.startNetworkSpeedTest(config);

// If you need to set callback interval, you can refer to the following call (take 1.5 seconds as an example)
engine.startNetworkSpeedTest(config, 1500);

The speed test results will be returned in the network speed test quality ZegoNetworkSpeedTestQuality in onNetworkSpeedTestQualityUpdate. By analyzing each parameter value, you can know whether the current network quality is good.

The parameters in ZegoNetworkSpeedTestQuality are as follows:

ParameterDescriptionExplanation
connectCostTime to connect to server, in milliseconds.If the network connection is disconnected during the speed test process, it will automatically reconnect. This variable will be updated accordingly. The smaller the value, the better.
rttNetwork latency, in milliseconds.Represents the time consumed between the SDK and the server round trip. The smaller the value, the better.
packetLostRatePacket loss rate, in percentage.The value range is 0.0 - 1.0. For example, 0.5 means that out of every 10 packets sent to the server, 5 may be lost on the way.

quality

Network quality

Represents the current network quality level. For details, please refer to ZegoStreamQualityLevel.

  • ZegoStreamQualityLevel.EXCELLENT: Excellent quality.

  • ZegoStreamQualityLevel.GOOD: Good quality.

  • ZegoStreamQualityLevel.MEDIUM: Normal quality.

  • ZegoStreamQualityLevel.BAD: Poor quality.

  • ZegoStreamQualityLevel.DIE: Abnormal quality.

  • ZegoStreamQualityLevel.UNKNOWN: Unknown quality.

3 Stop speed test

Call the stopNetworkSpeedTest interface to stop network speed test.

After stopping the speed test, you will no longer receive onNetworkSpeedTestQualityUpdate or onNetworkSpeedTestError callbacks.

engine.stopNetworkSpeedTest();

Previous

Call Quality Monitoring

Next

Multi-Source Capture

On this page

Back to top