For calls and events that require high quality audio and video, best practice is to ensure that both 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 network and device 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 exists.
The following measures are important:
A device test checks if the audio captured from a device can be played back after it has passed through a network. The test captures audio from the microphone of the device and sends it to Agora Platform with a defined wait time, such as 5 seconds. After the wait time, Agora Platform sends the audio back to the device, and it is played through the speaker of the device. You can then judge if the audio is of adequate quality.
Agora recommends that you perform a device test before starting a network probe test.
The SDK provides the following methods for device test:
startEchoTestWithInterval
method, which tests whether the network connection and the audio devices, such as the microphone and the speaker, are working properly.startRecordingDeviceTest
method, which tests whether the local audio recording devices, such as the microphone, are working properly.startPlaybackDeviceTest
method, which tests whether the local audio playing devices, such as the external audio player, are working properly.startAudioDeviceLoopbackTest
method, which tests whether the local audio device loopback is working properly.The startLastmileProbeTest
method probes the last-mile network before you join 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:
When you conduct the last-mile network test, the Video SDK adjusts the actual bitrate according to the configuration file of the video.
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:
startEchoTestWithInterval
before joining a channel. You need to set the interval
parameter in this method to notify the SDK when to report the result of this test. The value range (in seconds) is [2,10], and the default value is 10.stopEchoTest
to stop the current test, and call joinChannelByToken
to join a channel.Refer to the following code to implement the test in your project.
// swift
// Start the echo test
// Only a broadcaster can call startEchoTestWithInterval.
agoraKit.startEchoTestWithInterval(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 joinChannelByToken.
agoraKit.stopEchoTest
To test the local recording devices, such as the microphone, refer to the following steps:
startRecordingDeviceTest
, and set the indicationInterval
parameter as the interval of triggering the callbacks.reportAudioVolumeIndicationOfSpeakers
callback, the SDK reports uid
= 0 and the volume information of the devices.stopRecordingDeviceTest
method to stop the current test.indicationInterval
parameter setting be greater than 200 ms and no less than 10 ms; otherwise the reportAudioVolumeIndicationOfSpeakers
callback fails. // swift
agoraKit.startRecordingDeviceTest(1000)
agoraKit.stopRecordingDeviceTest()
To test the local audio playback devices, such as the speaker, refer to the following steps:
startPlaybackDeviceTest
, and set the audioFileName
parameter as the absolute path of the to-be-played audio file.reportAudioVolumeIndicationOfSpeakers
callback, and reports uid
= 1 and the volume information of the devices.stopPlaybackDeviceTest
method tostop
the current test.// swift
agoraKit.startPlaybackDeviceTest("audio file path")
agoraKit.stopPlaybackDeviceTest()
To start a local audio device loopback test, refer to the following steps:
startAudioDeviceLoopbackTest
, and set the indicationInterval
parameter as the interval of triggering the callbacks.reportAudioVolumeIndicationOfSpeakers
callbacks and reports the volume information of the audio capture device (uid
= 0) and the audio playback device (uid
= 1).stopAudioDeviceLoopbackTest
method to stop the current test.indicationInterval
parameter setting be greater than 200 ms and no less than 10 ms; otherwise the reportAudioVolumeIndicationOfSpeakers
callback fails. // swift
agoraKit.startAudioDeviceLoopbackTest(1000)
agoraKit.stopAudioDeviceLoopbackTest()
To implement the network probe test, refer to the following steps:
Call the startLastmileProbeTest
method to start the network probe test before joining a channel or switching the user role. You need to specify the expected uplink and downlink bitrate in this method.
// swift
let config = AgoraLastmileProbeConfig()
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;
// Call startLastmileProbeTest to start the network probe test
// 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 lastmileProbeTest callback.
agoraKit.startLastmileProbeTest(config)
After this method is called, the SDK returns the following callbacks:
lastmileQuality
: Returned 2 seconds after calling startLastmileProbeTest
. This callback rates the network quality with a score, so it is more closely linked to the user experience.lastmileProbeResult
: Returned 30 seconds after calling startLastmileProbeTest
. This callback returns the real-time statistics of the network quality, so it is more objective.// swift
// Return the lastmileQuality callback about 2 seconds after calling startLastmileProbeTest. This callback reports once every two seconds.
// lastmileQuality might return Unknown the first time it is triggered. Subsequent callbacks return the test results.
func rtcEngine(_ engine: AgoraRtcEngineKit, lastmileQuality quality: AgoraNetworkQuality) {
lastmileResultLabel.stringValue = "Quality: \(quality.description())"
}
// Return the lastmileProbeResult callback about 30 seconds after calling startLastmileProbeTest. This callback offers more detailed statistics of the network quality.
func rtcEngine(_ engine: AgoraRtcEngineKit, lastmileProbeTest result: AgoraLastmileProbeResult) {
// The round-trip latency
let rtt = "Rtt: \(result.rtt)ms"
// The downlink network bandwidth
let downlinkBandWidth = "DownlinkAvailableBandwidth: \(result.downlinkReport.availableBandwidth)Kbps"
// The downlink jitter buffer
let downlinkJitter = "DownlinkJitter: \(result.downlinkReport.jitter)ms"
// The downlink packet loss rate
let downlinkLoss = "DownlinkLoss: \(result.downlinkReport.packetLossRate)%"
// The uplink network bandwidth
let uplinkBandwidth = "UplinkAvailableBandwidth: \(result.uplinkReport.availableBandwidth)Kbps"
// The uplink jitter buffer
let uplinkJitter = "UplinkJitter: \(result.uplinkReport.jitter)ms"
// The uplink packet loss rate
let uplinkLoss = "UplinkLoss: \(result.uplinkReport.packetLossRate)%"
lastmileProbResultLabel.stringValue = [rtt, downlinkBandwidth, downlinkJitter, downlinkLoss,uplinkBandwidth,uplinkJitter,uplinkLoss].joined(separator: "\n")
}
After getting the network quality statistics, call the stopLastmileProbeTest
method to stop the last-mile network probe test.
// swift
// Stop the last-mile network probe test.
// You can call stopLastmileProbeTest to stop the test in the lastmileProbeResult method, or before you join the channel.
agoraKit.stopLastmileProbeTest()
This section includes in-depth information about the methods used in this page and links to related pages.
Agora provides an open-source sample project that implements PrecallTest.swift on GitHub. You can download the sample project to try it out or refer to the source code.