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: 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 reportRtcStats
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 localAudioStats
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 localAudioStateChange
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 remoteAudioStats
callback reports the audio statistics of each remote user in the Communication
profile or remote host in the LiveBroadcasting
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 remoteAudioStats
. 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 LiveBroadcasting
profile changes, the SDK triggers the remoteAudioStateChangedOfUid
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 localVideoStats
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 localVideoStateChangedOfState
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 remoteVideoStats
callback reports the video statistics of each remote user in the Communication
profile or remote host in the LiveBroadcasting
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 LiveBroadcasting
profile changes, the SDK triggers the remoteVideoStateChangedOfUid
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 the following quickstart guides:
Implement the following real-time interaction quality statistic callbacks and audio or video state callbacks in AgoraRtcEngineDelegate
to monitor user interaction experience.
reportRtcStats
: Reports real-time interaction statistics.localAudioStats
: Reports statistics of the audio stream sent.localAudioStateChange
: Reports the local audio stream state changes.remoteAudioStats
: Reports statistics of a remote audio stream received.remoteAudioStateChangedOfUid
: Reports the remote audio stream state changes.localVideoStats
: Reports statistics of the video stream sent.localVideoStateChangedOfState
: Reports the local video stream state changes.remoteVideoStats
: Reports statistics of a remote video stream received.remoteVideoStateChangedOfUid
: Reports the remote video stream state changes.extension JoinChannelVideoMain: AgoraRtcEngineDelegate {
func rtcEngine(_ engine: AgoraRtcEngineKit, reportRtcStats stats: AgoraChannelStats) {
localVideo.statsInfo?.updateChannelStats(stats)
}
func rtcEngine(_ engine: AgoraRtcEngineKit, localVideoStats stats: AgoraRtcLocalVideoStats) {
localVideo.statsInfo?.updateLocalVideoStats(stats)
}
func rtcEngine(_ engine: AgoraRtcEngineKit, localAudioStats stats: AgoraRtcLocalAudioStats) {
localVideo.statsInfo?.updateLocalAudioStats(stats)
}
func rtcEngine(_ engine: AgoraRtcEngineKit, remoteVideoStats stats: AgoraRtcRemoteVideoStats) {
remoteVideo.statsInfo?.updateVideoStats(stats)
}
func rtcEngine(_ engine: AgoraRtcEngineKit, remoteAudioStats stats: AgoraRtcRemoteAudioStats) {
remoteVideo.statsInfo?.updateAudioStats(stats)
}
}
networkQuality
reportRtcStats
localAudioStats
localAudioStateChange
remoteAudioStats
remoteAudioStateChangedOfUid
localVideoStats
localVideoStateChangedOfState
remoteVideoStats
remoteVideoStateChangedOfUid
Code | Description |
---|---|
AgoraNetworkQualityUnknown (0) |
The network quality is unknown. |
AgoraNetworkQualityExcellent (1) |
The network quality is excellent. |
AgoraNetworkQualityGood(2) |
The user subjectively feels that the network quality is similar to AgoraNetworkQualityExcellent (1) , but the bitrate might be slightly lower than AgoraNetworkQualityExcellent (1) . |
AgoraNetworkQualityPoor (3) |
The user subjectively feels that the network quality is flawed but does not affect communication. |
AgoraNetworkQualityBad (4) |
The user can barely communicate, but the communication is not smooth. |
AgoraNetworkQualityVBad (5) |
The network quality is so poor and the communication is basically impossible. |
AgoraNetworkQualityDown (6) |
Users cannot communicate with each other at all. |