
# 通话质量监测
#### 功能描述
加入频道后，SDK会每隔2秒自动触发通话质量相关的回调，上报当前通话的网络质量、本地和远端的音视频统计信息。
#### 上报接口
![](https://support.huaweicloud.com/bestpractice-rtc/zh-cn_image_0000001227090933.png)
#### 通话质量上报
onNetworkQualityNotify回调上报当前通话中每个入会者的上下行网络质量。默认开启，每2s上报一次。
```
void HWEngineEventHandler::onNetworkQualityNotify(HRTCQualityInfo * localQuality, unsigned int localQualityCount, HRTCQualityInfo * remoteQuality, unsigned int remoteQualityCount) {
    for (unsigned int i = 0; i < remoteQualityCount; i++) {
        HRTCQualityInfo stats;
        memcpy_s(&stats, sizeof(stats), &remoteQuality[i], sizeof(HRTCQualityInfo));
        //把远端网络质量刷新到统计界面上
    }
}
```
#### 本地音频流统计信息报告
onLocalAudioStatsNotify回调上报本地设备发送音频流的统计信息。您可以了解到当前通话声道数（单声道或双声道）、发送音频的采样率、码率、比特率、丢包率、延时和抖动等。
```
void HWEngineEventHandler::onLocalAudioStatsNotify(const HRTCLocalAudioStats * localStats, unsigned int localStatsCount) {
}
```
#### 远端音频流统计信息报告
onRemoteAudioStatsNotify回调上报当前通话中每个远端用户音频流的统计信息。您可以了解到每个远端用户发送的音频流的采样率、声道数、码率、丢包率、延时、抖动和卡顿时长等一些信息。
```
void HWEngineEventHandler::onRemoteAudioStatsNotify(const HRTCRemoteAudioStats * remoteStats, unsigned int remoteStatsCount) {
}
```
#### 本地视频流统计信息上报
onLocalVideoStatsNotify回调向您报告当前本地视频流统计信息，包括帧率、码率、延时、抖动等信息。
```
void HWEngineEventHandler::onLocalVideoStatsNotify(const HRTCLocalVideoStats * localStats, unsigned int localStatsCount) {
}
```
#### 远端视频流状态监控
onRemoteVideoStatsNotify回调向您报告当前远端视频流统计信息，包括帧率、码率、延时、抖动和卡顿时长等信息。
```
void HWEngineEventHandler::onRemoteVideoStatsNotify(const HRTCRemoteVideoStats * remoteStats, unsigned int remoteStatsCount) {
}
```
#### 视频流状态监控
onVideoStatsNotify回调上报视频流的状态，包括本地上行视频流和远端用户的下行视频流状态。
```
void HWEngineEventHandler::onVideoStatsNotify(HRTCLocalVideoStats *localStats, unsigned int localStatsCount, HRTCRemoteVideoStats *remoteStats, unsigned int remoteStatsCount) {
    for (unsigned int i = 0; i < localStatsCount; i++) {
        HRTCLocalVideoStats stats;
        memcpy_s(&stats, sizeof(stats), &localStats[i], sizeof(HRTCLocalVideoStats));
        //本地视频流信息刷新到统计界面上
    }
    for (unsigned int i = 0; i < remoteStatsCount; i++) {
        HRTCRemoteVideoStats stats;
        memcpy_s(&stats, sizeof(stats), &remoteStats[i], sizeof(HRTCRemoteVideoStats));
        //远端视频流信息刷新到统计界面上
    }
}
```
#### 音频流状态监控
onAudioStatsNotify回调上报音频流的状态，包括本地上行音频流和远端用户的下行音频流状态。
```
void HWEngineEventHandler::onAudioStatsNotify(HRTCLocalAudioStats *localStats, unsigned int localStatsCount, HRTCRemoteAudioStats *remoteStats, unsigned int remoteStatsCount) {
    for (unsigned int i = 0; i < localStatsCount; i++) {
        HRTCLocalAudioStats stats;
        memcpy_s(&stats, sizeof(stats), &localStats[i], sizeof(HRTCLocalAudioStats));
        //本地音频流信息刷新到统计界面上
    }
    for (unsigned int i = 0; i < remoteStatsCount; i++) {
        HRTCRemoteAudioStats stats;
        memcpy_s(&stats, sizeof(stats), &remoteStats[i], sizeof(HRTCRemoteAudioStats));
        //远端音频流信息刷新到统计界面上
    }
}
```
#### API参考
[onNetworkQualityNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#section52)
[onLocalVideoStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#section23)
[onLocalAudioStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#section93)
[onRemoteVideoStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#section92)
[onRemoteAudioStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#section94)
[onVideoStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#section21)
[onAudioStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#section20)
