The Agora RTC SDK triggers callbacks related to the quality of the call and live streaming in real-time, from which you can learn about users' interaction experience, and conduct corresponding troubleshooting and experience optimization.
This page describes how to understand the information returned by the callbacks and how to use these callbacks.
After a user successfully joins the channel, the SDK triggers a series of callbacks with a two-second callback period, including the following: network quality report, interaction statistics report, local and remote audio and video streams statistic report.
When the user's audio or video state changes, the SDK triggers a callback to report the latest audio or video state and the reason for the state change.
The onNetworkQuality
callback reports the uplink and downlink last-mile network quality of each user in the COMMUNICATION
profile or each host in the LIVE_BROADCASTING
profile in the current call, see quality rating table for details.
The onRtcStats
callback reports call statistics. You can learn about the duration, the number of users in the channel, the system CPU usage, the application CPU usage, and so on.
This section describes the user's audio quality report, including local audio stream statistics, local audio stream state change, remote audio stream statistics, and remote audio stream state change.
The onLocalAudioStats
callback, which is triggered once every two seconds, reports the statistics of the audio streams sent. You can learn about the following important statistics:
When the state of local audio changes, such as the state of audio recording or audio encoding changes, the SDK triggers the onLocalAudioStateChanged
callback to report the current state. You can troubleshoot with the error code when exceptions occur.
The following figure shows the transmission process between app clients.
The onRemoteAudioStats
callback reports the audio statistics of each remote user in the COMMUNICATION
profile or remote host in the LIVE_BROADCASTING
profile in the current call, including the quality of the remote audio streams (see quality rating table), the number of audio channels, and so on.
To analyse statistics more closely linked to the user's experience and audio transmission quality, use onRemoteAudioStats
. Even if network packet loss occurs, users might find the overall audio quality acceptable because the audio frame loss rate of the received audio streams might not be high due to the anti-packet-loss and congestion control methods, such as forward error correction (FEC), retransmissions and bandwidth estimation.
When the audio state of a remote user in the COMMUNICATION
profile or remote host in the LIVE_BROADCASTING
profile changes, the SDK triggers the onRemoteAudioStateChanged
callback to report the current state and the reason for the state change.
This section describes the user's video quality report, including local video stream statistics, local video stream state change, remote video stream statistics, and remote video stream state change.
The onLocalVideoStats
callback reports the statistics of the video streams sent. You can learn about the dimensions of the encoding frame, the target bitrate of the encoder, the bitrate of the video sent in the reported interval, and so on.
enableDualStreamMode
method to enable dual-stream mode, this callback reports the statistics of the high-video streams sent.When the state of the local video changes, the SDK triggers the onLocalVideoStateChanged
callback to report the current state. You can troubleshoot with the error code when exceptions occur.
The following figure shows the transmission process between app clients.
The onRemoteVideoStats
callback reports the video statistics of each remote user in the COMMUNICATION
profile or remote host in the LIVE_BROADCASTING
profile in the current call. You can learn about their video dimensions, the type of video streams, the bitrate of the video received in the reported interval, and so on.
When the video state of a remote user in the COMMUNICATION
profile or remote host in the LIVE_BROADCASTING
profile changes, the SDK triggers the onRemoteVideoStateChanged
callback to report the current state and the reason for the state change.
Ensure that you have a project that has implemented the basic real-time engagement functionality. For details, see Start a Call or Start Interactive Live Streaming.
Implement the following real-time interaction quality statistic callbacks and audio or video state callbacks in IRtcEngineEventHandler
to monitor user interaction experience.
onNetworkQuality
: Reports the quality of uplink and downlink last-mile network.onRtcStats
: Reports real-time interaction statistics.onLocalAudioStats
: Reports statistics of the audio stream sent.onLocalAudioStateChanged
: Reports the local audio stream state changes.onRemoteAudioStats
: Reports statistics of a remote audio stream received.onRemoteAudioStateChanged
: Reports the remote audio stream state changes.onLocalVideoStats
: Reports statistics of the video stream sent.onLocalVideoStateChanged
: Reports the local video stream state changes.onRemoteVideoStats
: Reports statistics of a remote video stream received.onRemoteVideoStateChanged
: Reports the remote video stream state changes.private final IRtcEngineEventHandler iRtcEngineEventHandler = new IRtcEngineEventHandler()
{
public void onRemoteAudioStateChanged(int uid, IRtcEngineEventHandler.REMOTE_AUDIO_STATE state, IRtcEngineEventHandler.REMOTE_AUDIO_STATE_REASON reason, int elapsed)
{
super.onRemoteAudioStateChanged(uid, state, reason, elapsed);
Log.i(TAG, "onRemoteAudioStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
}
@Override
public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed)
{
super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
Log.i(TAG, "onRemoteVideoStateChanged->" + uid + ", state->" + state + ", reason->" + reason);
}
@Override
public void onRemoteAudioStats(RemoteAudioStats remoteAudioStats) {
statisticsInfo.setRemoteAudioStats(remoteAudioStats);
updateRemoteStats();
}
@Override
public void onLocalAudioStats(LocalAudioStats localAudioStats) {
statisticsInfo.setLocalAudioStats(localAudioStats);
updateLocalStats();
}
@Override
public void onRemoteVideoStats(RemoteVideoStats remoteVideoStats) {
statisticsInfo.setRemoteVideoStats(remoteVideoStats);
updateRemoteStats();
}
@Override
public void onLocalVideoStats(LocalVideoStats localVideoStats) {
statisticsInfo.setLocalVideoStats(localVideoStats);
updateLocalStats();
}
@Override
public void onRtcStats(RtcStats rtcStats) {
statisticsInfo.setRtcStats(rtcStats);
}
};
onNetworkQuality
onRtcStats
onLocalAudioStats
onLocalAudioStateChanged
onRemoteAudioStats
onRemoteAudioStateChanged
onLocalVideoStats
onLocalVideoStateChanged
onRemoteVideoStats
onRemoteVideoStateChanged
Code | Description |
---|---|
QUALITY_UNKNOWN (0) |
The network quality is unknown. |
QUALITY_EXCELLENT (1) |
The network quality is excellent. |
QUALITY_GOOD(2) |
The user subjectively feels that the network quality is similar to QUALITY_EXCELLENT (1) , but the bitrate might be slightly lower than QUALITY_EXCELLENT (1) . |
QUALITY_POOR (3) |
The user subjectively feels that the network quality is flawed but does not affect communication. |
QUALITY_BAD (4) |
The user can barely communicate, but the communication is not smooth. |
QUALITY_VBAD (5) |
The network quality is so poor and the communication is basically impossible. |
QUALITY_DOWN (6) |
Users cannot communicate with each other at all. |