In real-time scenarios requiring high quality, conducting tests before joining a channel helps troubleshoot in advance and improve the overall user experience. You can perform the following pre-call tests:
This article describes how to implement these tests.
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.
As of v2.4.0, the Agora RTC Native SDK provides the startLastmileProbeTest
method that 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.
Before proceeding, ensure that you have implemented the basic real-time communication functions in your project. For details, see Start a Call or Start Live Interactive Streaming.
Refer to the following steps to implement the network probe test:
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.The API call sequence is as follows:
Refer to the following code to implement the last-mile test in your project.
// Register the callback events.
// Triggered 2 seconds after starting the last-mile test.
void onLastmileQuality(int quality) {
}
// Triggered 30 seconds after starting the last-mile test.
void onLastmileProbeResult(LastmileProbeResult) {
// (1) Stop the test. Agora recommends not calling any other API method before the test ends.
lpAgoraEngine->stopLastmileProbeTest();
}
// Configure a LastmileProbeConfig instance.
LastmileProbeConfig config;
// 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.
lpAgoraEngine->startLastmileProbeTest(config);
// (2) Stop the test in an alternate place. Agora recommends not calling any other API method before the test ends.
lpAgoraEngine->stopLastmileProbeTest();
To ensure smooth communications, we recommend conducting a media device test before joining a channel to check whether the microphone or camera works properly. This function applies to scenarios that have high-quality requirements, such as online education.
Before proceeding, ensure that you have implemented basic real-time functions in your project. See Start a Call or Start Live Interactive Streaming for details.
startEchoTest
method to test if the audio devices and network connection are working properly.startRecordingDeviceTest
method to test the audio recording devices, and call the startPlaybackDeviceTest
method to test the audio playback devices.startAudioDeviceLoopbackTest
method to test the audio device loopback (including the recording and playback devices).startCaptureDeviceTest
method to test the video capture devices.Call the startEchoTest
method to test if the audio devices, such as the microphone and the speaker, are working properly.
To conduct the test, call startEchoTest
and set the interval parameter in this method to notify the SDK when to report the result of this test. The user speaks, and if the recording plays back within the set time interval, the audio devices and the network connection are working properly.
// Start an echo test.
rtcEngine.startEchoTest(10);
// Wait and check if the user can hear the recorded audio.
// Stop the echo test.
rtcEngine.stopEchoTest;
Call the startRecordingDeviceTest
method to test whether the local audio recording device, such as the microphone, is working properly.
To conduct the test, call startRecordingDeviceTest
and set the indicationInterval
parameter in this method to notify the SDK when to report the result of this test. The user speaks, and the SDK reports the audio volume information in the onAudioVolumeIndication
callback. A UID of 0
indicates the local user.
When the test finishes, call the stopRecordingDeviceTest
method to stop the current test.
indicationInterval
greater than 200 ms. Do not set the interval smaller than 10 ms, or the onAudioVolumeIndication
callback will not be triggered.// Select an audio capture device.
lpDeviceManager->setRecordingDevice(strDeviceID); // device ID chosen
// Implement the audio volume callback.
virtual void onAudioVolumeIndication(const AudioVolumeInfo* speakers, unsigned int speakerNumber, int totalVolume) {
(void)speakers;
(void)speakerNumber;
(void)totalVolume;
}
// Start the audio capture device test.
(*lpDeviceManager)->startRecordingDeviceTest(1000);
// Stop the audio capture device test.
(*lpDeviceManager)->stopRecordingDeviceTest();
Call the startPlaybackDeviceTest
method to test whether the local audio playback device, such as the speaker, is working properly.
To conduct the test, specify an audio file for playback and call startPlaybackDeviceTest
. If you can hear the audio file, the audio playback device works properly. The SDK triggers a onAudioVolumeIndication
callback to report the audio volume information of the audio playback device with a UID of 1
.
When the test finishes, call the stopPlaybackDeviceTest
method to stop the current test.
// Select an audio playback device.
lpDeviceManager->setPlaybackDevice(strDeviceID); // device ID chosen
// Specify the absolute path of an audio file and start the audio playback device test.
(*lpDeviceManager)->startPlaybackDeviceTest(filePath);
// Stop the audio capture device test.
(*lpDeviceManager)->stopPlaybackDeviceTest();
Call the startAudioDeviceLoopbackTest
method to test whether the local audio devices, including the microphones and speakers, are working properly.
To conduct the test, call startAudioDeviceLoopbackTest
and set the indicationInterval
parameter in this method to notify the SDK when to report the result of this test. The user speaks, then the microphone captures the local audio and plays it through the speaker. The SDK triggers two onAudioVolumeIndication
callbacks. One callback reports the audio volume information of the microphone with a UID of 0; the other callback reports the audio volume information of the speaker with a UID of 1.
When the test finishes, call the stopAudioDeviceLoopbackTest
method to stop the current test.
indicationInterval
greater than 200 ms. Do not set the interval smaller than 10 ms, or the onAudioVolumeIndication
callback will not be triggered.The video device tests check the video capture device and the video rendering device.
After calling the enableVideo
method, call the startDeviceTest
method to test whether the local video devices, such as the camera and renderer, are working properly.
To conduct the test, specify a window handle that displays the image. If you can see the local video view, the video devices work properly.
When the test finishes, call the stopDeviceTest
method to stop the current test.
// Select a video capture device.
lpDeviceManager->setDevice(strDeviceID); // device ID chosen
// Start the video capture device test. If it succeeds, you will see a preview of the screen.
(*lpDeviceManager)->startDeviceTest(view); // Pass a window handler to it.
// Stop the video capture device test.
(*lpDeviceManager)->stopDeviceTest();
startEchoTest
stopEchoTest
enableAudioVolumeIndication
enumerateRecordingDevices
setRecordingDevice
enumeratePlaybackDevices
setPlaybackDevice
startRecordingDeviceTest
stopRecordingDeviceTest
startAudioDeviceLoopbackTest
stopAudioDeviceLoopbackTest
enumerateVideoDevices
startDeviceTest
stopDeviceTest
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 lastmileProbeTest
callback.lastmileQuality
callback may return UNKNOWN
the first time it is triggered. Subsequent callbacks will return the test results.startEchoTest
.joinChannel
.