For calls and events that require high quality audio and video, best practice is to ensure that the hardware your app is running on and the last mile between the device and Agora Platform are good enough to assure the quality you require. This improves the user experience and helps you troubleshoot.
This page shows you how to implement device and network tests in your app.
In telecommunications, a probe is an action taken or an object used for the purpose of learning something about the state of the network. For example, an empty message can be sent simply to see whether the destination actually exists.
The following measures are important:
A device test checks if audio captured from a device can be played back after the it has passed through a network. The Agora tests captures audio from the device microphone, sends it to Agora Platform with a defined wait time. For example, five seconds. After the wait time Agora Platform sends the audio back to the device and it is played to the device loudspeaker. You can then judge if the audio is of adequate quality.
Agora recommends that you start device test before starting network probe test.
The SDK provides the startEchoTest
method that tests whether the network connection and the audio devices, such as the microphone and the speakers, are working properly.
The startLastmileProbeTest
method probes the last-mile network before joining a channel and returns statistics about the network quality, including round-trip latency, packet loss rate, and network bandwidth.
The API call sequence is as follows:
Before proceeding, ensure that you have implemented basic real-time functions in your project. See Start a Call or Start Interactive Live Streaming.
To implement pre-call testing in your project, refer to the following steps.
To start an echo test, refer to the following steps.
startEchoTest
before joining a channel. You need to set the intervalInSeconds
parameter in this method to notify the SDK when to report the result of this test. The value range is [2,10], and the default value is 10 (in seconds).stopEchoTest
to stop the current test before joining a channel using joinChannel
.Refer to the following code to implement the device test in your project.
// Start the echo test.
// Set the time interval between when you speak and when the recording plays back as 10 seconds.
// Only a broadcaster can call `startEchoTest`.
rtcEngine.startEchoTest(10);
// Wait and check if the user can hear the recorded audio.
// Stop the echo test.
// Once the echo test ends, you must call `stopEchoTest` to stop it. Otherwise, you cannot conduct another echo test or join a channel using `joinChannel`.
rtcEngine.stopEchoTest();
To implement the network probe test, refer to the following steps.
startLastmileProbeTest
to start the network probe test before joining a channel or switching the user role. You need to specify the expected upstream and downstream bitrate in this method.onLastmileQuality
: Triggered two seconds after the startLastmileProbeTest
method is called. This callback rates the network conditions with a score and is more closely linked to the user experience.onLastmileProbeResult
: Triggered 30 seconds after the startLastmileProbeTest
method is called. This callback returns the real-time statistics of the network conditions and is more objective.stopLastmileProbeTest
method to stop the last-mile network probe test.Refer to the following code to implement the last-mile test in your project.
// Configure a LastmileProbeConfig instance.
LastmileProbeConfig config = new LastmileProbeConfig(){};
// Probe the uplink network quality.
config.probeUplink = true;
// Probe the downlink network quality.
config.probeDownlink = true;
// The expected uplink bitrate (bps). The value range is [100000,5000000].
config.expectedUplinkBitrate = 100000;
// The expected downlink bitrate (bps). The value range is [100000,5000000].
config.expectedDownlinkBitrate = 100000;
// Start the last-mile network test before joining the channel.
// Calling `startLastmileProbeTest` for pre-call network quality detection consumes network traffic. Therefore, after calling this method, Agora recommends not calling any other method until you receive the `onLastmileProbeResult` callback.
rtcEngine.startLastmileProbeTest(config);
// Implemented in the global IRtcEngineEventHandler class.
// Triggered 2 seconds after starting the last-mile test.
// The `onLastmileQuality` callback may return `UNKNOWN` the first time it is triggered. Subsequent callbacks will return the test results.
public void onLastmileQuality(int quality){
statisticsInfo.setLastMileQuality(quality);
updateLastMileResult();
}
// Implemented in the global IRtcEngineEventHandler class.
// Triggered 30 seconds after starting the last-mile test.
public void onLastmileProbeResult(LastmileProbeResult) {
// (1) Stop the test. Agora recommends not calling any other API method before the test ends.
rtcEngine.stopLastmileProbeTest();
statisticsInfo.setLastMileProbeResult(lastmileProbeResult);
updateLastMileResult();
}
// (2) Stop the test in an alternate place. Agora recommends not calling any other API method before the test ends.
rtcEngine.stopLastmileProbeTest();
This section includes in depth information about the methods you used in this page, and links to related pages.
Agora provides an open-source sample project that implements pre-call tests on GitHub. You can download the sample project to try it out or refer to the source code.