
# 事件回调（IHRTCEngine）
本章节介绍了全平台C++ SDK的回调接口IHRTCEngineEventHandler的详情。
表1事件回调说明 
| 接口                                                                                                                                                        | 描述                   |
|:---|:---|
| [onError]                                                                                     | 错误回调。                |
| [onJoinRoomSuccess]                                                                            | 成功加入房间回调。            |
| [onJoinRoomFailure]                                                                            | 加入房间失败回调。            |
| [onLeaveRoom]                                                                                 | 离开房间回调。              |
| [onRemoteUserOnline](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section422052222412)             | 远端用户加入当前房间回调。        |
| [onRemoteUserOffline](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section166775422416)            | 远端用户离开当前房间回调。        |
| [onRemoteUserNameChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section8386124822410) | 远端用户昵称变化回调。          |
| [onUserNameChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section81445822511)         | 本地用户昵称变化回调。          |
| [onFirstRemoteVideoDecoded]                                                                    | 引擎收到第一帧远端视频流并解码成功回调。 |
| [onFirstRemoteAuxiliaryStreamDecoded]                                                            | 引擎收到第一帧远端辅流并解码成功回调。  |
| [onConnectionChangedNotify]                                                                    | 网络连接状态发生变化回调。        |
| [onDeviceStateChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section2858888385)             | 设备状态发生变化回调。          |
| [onDeviceVolumeChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section539533215480)          | 音频设备音量发生变化回调。        |
| [onLogUploadResult]                                                                            | 日志上传结果回调。            |
| [onLogUploadProgress]                                                                           | 日志上传进度回调。            |
| [onUserRoleChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section9263123615018)             | 用户角色切换成功回调。          |
| [onScreenShareStarted]                                                                         | 辅流开启回调。              |
| [onScreenShareStopped]                                                                        | 辅流关闭回调。              |
| [onUserAuxiliaryStreamAvailable](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section104831644105410)    | 远端开启/停止辅流回调。         |
| [onVideoStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section11701824125713)                 | 视频流详情，2s触发一次回调。      |
| [onAudioStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section1183315549572)                                         | 音频流详情，2s触发一次回调。      |
| [onAuxiliaryStreamStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section2352324125817)                               | 辅流详情，2s触发一次回调。       |
| [onAuthorizationExpired](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section9566994582)           | 鉴权签名过期回调。            |
| [onRemoteAudioStateChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section9856611239)  | 远端音频流状态变化回调。         |
| [onRemoteVideoStateChangedNotify]                                                             | 远端视频流状态变化回调。         |
| [onRenderAuxiliaryExternalVideoFrame]                                                           | 辅流自渲染回调。             |
| [onRenderExternalVideoFrame]                                                                                            | 视频自渲染回调              |
| [onPlaybackExternalAudioFrame]                                                                                         | 音频渲染回调               |
| [onRejoinRoomSuccess]                                                                           | 重新加入房间回调。            |
| [onNetworkTestQuality]                                                                       | 网络探测信号质量回调。          |
| [onNetworkTestResult]                                                                           | 网络探测详细结果回调。          |
| [onUserVolumeStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section924462264812)              | 音频音量回调。              |
| [onLocalAudioStateChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section1929423810318)      | 本地音频状态改变回调。          |
| [onLocalVideoStateChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section1655812393313)      | 本地视频状态改变回调。          |
| [onNetworkQualityNotify]                                                                        | 网络质量上报。              |
| [onRenderSuccessNotify]                                                                          | 媒体渲染成功上报。            |
| [onLocalVolumeChangedNotify]                                                                   | 本地采集音量实时回调。          |
| [onFirstLocalAudioFrameNotify]                                                                     | 本地音频首帧发送回调。          |
| [onFirstLocalVideoFrameNotify]                                                                | 本地视频首帧渲染回调。          |
| [onMediaConnectStateChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0277015530_section1841519155264)    | 媒体服务器连接状态变化回调。       |
| [onStartAllRemoteViewResult]                                                                                          | 批量选看结果回调。            |
| [onStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section1831181831)                                                 | 当前会话统计回调。            |
| [onLocalVideoStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section18159124522018)                                   | 本地视频流详情，2s触发一次回调。    |
| [onRemoteVideoStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section1565124602018)                                   | 远端视频流详情，2s触发一次回调。    |
| [onLocalAudioStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section159054461209)                                     | 本地音频流详情，2s触发一次回调。    |
| [onRemoteAudioStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section6833247142013)                                   | 远端音频流详情，2s触发一次回调。    |
| [onVideoResolutionChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section13763184812017)                            | 视频分辨率大小改变回调。         |
| [onAudioClipFinished]                                                                                                  | 音效文件播放结束回调。          |
| [onAudioFileFinished]                                                                                                  | 音频文件播放结束回调。          |
| [onAudioMixStateChangedNotify]                                                                                          | 混音音频文件播放状态改变回调。      |
| [onSeiSendMsgSuccess]                                                                                                 | 音频SEI信息发送成功回调        |
| [onSeiRecvMsg]                                                                                                      | 接收音频SEI信息回调          |
| [onStartPublishStream]                                                                                               | 开始旁路（RTMP）推流回调       |
| [onUpdateTransCoding]                                                                                               | 更新旁路（RTMP）推流消息       |
| [onStopPublishStream]                                                                                                 | 停止旁路（RTMP）推流消息       |
| [onStreamPublishStateChange]                                                                                          | RTMP推流状态回调           |
| [onAudioDeviceTestVolumeNotify]                                                                                      | 音频设备测试回调             |
| [onShareSourceInfoChangedNotify]                                                                                       | 共享源目标发生变化通知          |
| [onShareWindowLocationChangedNotify]                                                                                    | 共享源目标坐标发生改变通知        |
| [onLocalAudioMutedStatusDetected]                                                                                    | 本端禁音状态检测回调           |
| [onMultiRoomMediaRelayStateChanged]                                                                                   | 跨房状态改变回调             |
| [onRemoteMicrophoneStateChanged]                                                                                      | 麦克风设备状态变更通知          |
| [onUserNetworkQualityNotify]                                                                                             | 加入房间后的网络质量状态回调       |
| [onRoomStreamStatusNotify]                                                                                               | 房间流状态回调              |
   
 #### onError
```
virtual void onError(int error, const char* msg)
```
【**功能说明**】
发生错误，触发此回调。返回[客户端错误码](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)或者[服务端错误码](https://support.huaweicloud.com/csdk-rtc/rtc_05_0126.html)。
【**回调参数**】
- error：错误码，具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
- msg：错误描述。
 
 #### onJoinRoomSuccess
```
virtual void onJoinRoomSuccess(const char* roomId, const char* userId)
```
【**功能说明**】
成功加入房间，触发此回调。
【**回调参数**】
- roomId：新加入的房间ID。
- userId：新加入房间的用户ID。
 
 #### onJoinRoomFailure
```
virtual void onJoinRoomFailure(int error, const char* msg)
```
【**功能说明**】
加入房间失败，触发此回调。
【**回调参数**】
- error：错误码，具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
- msg：错误描述。
 
 #### onLeaveRoom
```
virtual void onLeaveRoom(HRTCLeaveReason reason, const HRTCStatsInfo &statsInfo)
```
【**功能说明**】
离开房间，触发此回调。
【**回调参数**】
- reason：离开的房间原因，具体请参见[HRTCLeaveReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section414213447916)。
- statsInfo：卡顿统计信息，具体请参见[HRTCStatsInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section75431844173718)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
APP调用[leaveRoom](https://support.huaweicloud.com/csdk-rtc/rtc_05_0099.html#rtc_05_0099__zh-cn_topic_0000001113849700_section72039355375)接口时，会返回[HRTC_LEAVE_REASON_USER_LEAVE_ROOM](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section414213447916)，可以通过以下任一方式回退到登录界面。
- APP在调用[leaveRoom](https://support.huaweicloud.com/csdk-rtc/rtc_05_0099.html#rtc_05_0099__zh-cn_topic_0000001113849700_section72039355375)接口时退到登录界面，或者在收到onLeaveRoom回调，且回调消息不等于[HRTC_LEAVE_REASON_USER_LEAVE_ROOM](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section414213447916)时（防止重复操作）退到登录界面。
- APP只在收到onLeaveRoom消息时退到登录界面。
 
 #### onRemoteUserOnline
```
virtual void onRemoteUserOnline(const char* roomId, const char* userId, const char* userName)
```
【**功能说明**】
远端joiner用户加入当前房间，触发此回调。该回调提示有远端joiner用户加入了房间，并返回新加入用户的ID。
【**回调参数**】
- roomId：房间ID。
- userId：远端用户ID。
- userName：远端用户昵称。
 
 #### onRemoteUserOffline
```
virtual void onRemoteUserOffline(const char* roomId, const char* userId, int reason)
```
【**功能说明**】
远端joiner用户离开当前房间，触发此回调。
本端用户离开当前房间，会回调当前房间所有用户offline。
【**回调参数** 】
- roomId：当前房间的房间ID。
- userId：离开房间的远端用户ID。
- reason：远端用户离线原因，预留参数。
 
#### onRemoteUserNameChangedNotify
```
virtual void onRemoteUserNameChangedNotify(const char* roomId, const char* userId, const char* userName)
```
【**功能说明**】
远端用户昵称变化，触发此回调。
【**回调参数**】
- roomId：房间ID。
- userId：用户ID。
- userName：变更后的昵称。
 
 #### onUserNameChangedNotify
```
virtual void onUserNameChangedNotify(const char* oldUserName, const char* newUserName)
```
【**功能说明**】
本端用户昵称变化，触发此回调。
【**回调参数**】
- oldUserName：变更前的昵称。
- newUserName：变更后的昵称。
 
 #### onFirstRemoteAuxiliaryStreamDecoded
```
virtual void onFirstRemoteAuxiliaryStreamDecoded(const char* roomId, const char* userId, int width, int height)
```
【**功能说明**】
接收到第一帧远端辅流并解码成功，触发此回调。
【**回调参数**】
- roomId：视频流对应的房间ID。
- userId：视频流对应的用户ID。
- width：视频流宽。
- height：视频流高。
 
 #### onFirstRemoteVideoDecoded
```
virtual void onFirstRemoteVideoDecoded(const char* roomId, const char* userId, int width, int height)
```
【**功能说明**】
接收到第一帧远端视频流并解码成功，触发此回调。
【**回调参数**】
- roomId：视频流对应的房间ID。
- userId：视频流对应的用户ID。
- width：视频流宽。
- height：视频流高。
 
 #### onConnectionChangedNotify
```
virtual void onConnectionChangedNotify(HRTCConnStateTypes connType, HRTCConnChangeReason reason, const char* description)
```
【**功能说明**】
网络连接状态发生变化，触发此回调。
【**回调参数**】
- connType：网络连接状态。具体请参见[HRTCConnStateTypes](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section726832651815)。
- reason：网络连接状态发生变化原因。具体请参见[HRTCConnChangeReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section12711426101819)。
- description：错误原因描述。
 
#### onDeviceStateChangedNotify
```
virtual void onDeviceStateChangedNotify(const char* deviceId, HRTCDeviceType deviceType, HRTCDeviceState deviceState)
```
【**功能说明**】
设备状态发生变化，触发此回调。
【**回调参数**】
- deviceId：系统设备标识，如系统音频播放设备标识可通过[getPlaybackDevices](https://support.huaweicloud.com/csdk-rtc/rtc_05_0116.html#rtc_05_0116__zh-cn_topic_0277015531_section1159715261797)获取。
- deviceType：系统设备类型，具体请参见[HRTCDeviceType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1828214264182)。
- deviceState：系统设备状态，具体请参见[HRTCDeviceState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1728432617187)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
通话前插拔设备会上报变化。
#### onDeviceVolumeChangedNotify
```
virtual void onDeviceVolumeChangedNotify(HRTCDeviceType deviceType, unsigned int volume, unsigned int muted)
```
【**功能说明**】
音频设备音量发生变化，触发此回调。
【**回调参数**】
- deviceType：系统设备类型，具体请参见[HRTCDeviceType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1828214264182)。
- volume：音量
- muted：true表示设备静音，false表示设备未静音。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
通话前调整音频设备音量和静音会上报变化。
 #### onLogUploadResult
```
virtual void onLogUploadResult(int result)
```
【**功能说明**】
日志上传结果回调。
【**回调参数**】
result：日志上传结果。
- 0：上传成功
- \>0：上传失败
 
 #### onLogUploadProgress
```
virtual void onLogUploadProgress(int progress)
```
【**功能说明**】
日志上传进度回调。
【**回调参数**】
progress：日志上传进度。取值范围为\[0,100\]。
 #### onUserRoleChangedNotify
```
virtual void onUserRoleChangedNotify(const char* roomId, HRTCRoleType oldRole, HRTCRoleType newRole)
```
【**功能说明**】
用户角色切换成功，触发此回调。
【**回调参数**】
- roomId：发生角色切换的房间号。
- oldRole：切换前的角色。具体请参见[HRTCRoleType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section426214263183)。
- newRole：切换成功后的角色。具体请参见[HRTCRoleType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section426214263183)。
 
 #### onScreenShareStarted
```
virtual void onScreenShareStarted()
```
【**功能说明**】
屏幕流共享开启，触发此回调。
 #### onScreenShareStopped
```
virtual void onScreenShareStopped(int reason)
```
【**功能说明**】
屏幕流共享关闭，触发此回调。
【**回调参数**】
reason：屏幕共享关闭原因。
 #### onUserAuxiliaryStreamAvailable
```
virtual void onUserAuxiliaryStreamAvailable(const char* roomId, const char* userId, bool available)
```
【**功能说明**】
远端开启，停止辅流后，触发此回调。
【**回调参数**】
- roomId：房间ID。
- userId：远端用户ID。
- available：true表示远端开启辅流，false表示远端停止辅流。
 
#### onVideoStatsNotify
```
virtual void onVideoStatsNotify(HRTCLocalVideoStats *localStats, unsigned int localStatsCount, HRTCRemoteVideoStats *remoteStats, unsigned int remoteStatsCount)
```
【**功能说明**】
视频流详情，2s触发一次回调。
【**回调参数** 】
- localStats：本地视频发流统计，具体请参见[HRTCLocalVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section133091918111612)。
- localStatsCount：localStats数组长度。
- remoteStats：远端视频收流统计，具体请参见[HRTCRemoteVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1519645813161)。
- remoteStatsCount：remoteStats数组长度。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 当无本地视频时，localStatsCount为0，localStats为空指针，需要先判断不为空再使用，否则可能引发空指针错误。
- 当无远端视频时，remoteStatsCount为0，remoteStats为空指针，需要先判断不为空再使用，否则可能引发空指针错误。
 
#### onAudioStatsNotify
```
virtual void onAudioStatsNotify(HRTCLocalAudioStats *localStats, unsigned int localStatsCount, HRTCRemoteAudioStats *remoteStats, unsigned int remoteStatsCount)
```
【**功能说明**】
音频流详情，2s触发一次回调。
【**回调参数**】
- localStats：本地音频发流统计，具体请参见[HRTCLocalAudioStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1483619515499)。
- localStatsCount：localStats数组长度。
- remoteStats：远端音频收流统计，具体请参见[HRTCRemoteAudioStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section6738131145018)。
- remoteStatsCount：remoteStats数组长度。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 当无本地音频时，localStatsCount为0，localStats为空指针，需要先判断不为空再使用，否则可能引发空指针错误。
- 当无远端音频时，remoteStatsCount为0，remoteStats为空指针，需要先判断不为空再使用，否则可能引发空指针错误。
 
#### onAuxiliaryStreamStatsNotify
```
virtual void onAuxiliaryStreamStatsNotify(HRTCLocalVideoStats *localStats, unsigned int localStatsCount, HRTCRemoteVideoStats *remoteStats, unsigned int remoteStatsCount)
```
【**功能说明**】
辅流详情，2s触发一次回调。
【**回调参数**】
- localStats：本地辅流发流统计，具体请参见[HRTCLocalVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section133091918111612)。
- localStatsCount：localStats数组长度。
- remoteStats：远端辅流收流统计，具体请参见[HRTCRemoteVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1519645813161)。
- remoteStatsCount：remoteStats数组长度。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 当无本地辅流时，localStatsCount为0，localStats为空指针，需要先判断不为空再使用，否则可能引发空指针错误。
- 当无远端辅流时，remoteStatsCount为0，remoteStats为空指针，需要先判断不为空再使用，否则可能引发空指针错误。
 
 #### onAuthorizationExpired
```
virtual void onAuthorizationExpired();
```
【**功能说明**】
鉴权签名过期回调，需要app调用更新签名。
 #### onRemoteAudioStateChangedNotify
```
virtual void onRemoteAudioStateChangedNotify(const char* userId, HRTCRemoteAudioStreamState state, HRTCRemoteAudioStreamStateReason reason)
```
【**功能说明**】
远端音频流状态变化回调。
【**回调参数**】
- userId：远端用户ID。
- state：远端音频流状态，具体请参见[HRTCRemoteAudioStreamState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1231316191106)。
- reason：远端音频流状态变化原因，具体请参见[HRTCRemoteAudioStreamStateReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section131711120131020)。
 
 #### onRemoteVideoStateChangedNotify
```
virtual void onRemoteVideoStateChangedNotify(const char* userId, HRTCRemoteVideoStreamState state, HRTCRemoteVideoStreamStateReason reason)
```
【**功能说明**】
远端视频流状态变化回调。
【**回调参数**】
- userId：远端用户ID。
- state：远端视频流状态，具体请参见[HRTCRemoteVideoStreamState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section105601959163512)。
- reason：远端视频流状态变化原因，具体请参见[HRTCRemoteVideoStreamStateReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section65623596353)。
 
 #### onRenderAuxiliaryExternalVideoFrame
```
virtual void onRenderAuxiliaryExternalVideoFrame(const char* roomId, HRTCMediaDirection direction, const char* userId, HRTCVideoFrame& videoFrame)
```
【**功能说明**】
辅流自渲染回调。需要调用setAuxiliaryExternalVideoFrameOutput接口开启辅流自渲染，从而触发该回调。
【**回调参数**】
- roomId：房间ID。
- direction：数据源，本地数据，远端数据，具体请参见[HRTCMediaDirection](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section41882561268)。
- userId：用户ID。
- videoFrame：辅流详情，具体请参见[HRTCVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section252640124317)。
 
 #### onRenderExternalVideoFrame
```
virtual void onRenderExternalVideoFrame(const char* roomId, HRTCMediaDirection direction, const char* userId, HRTCVideoFrame& videoFrame)
```
【**功能说明**】
视频自渲染回调。需要调用[setExternalVideoFrameOutput](https://support.huaweicloud.com/csdk-rtc/rtc_05_0105.html#rtc_05_0105__section1654151193217)接口开启视频自渲染，从而触发该回调。
【**回调参数**】
- roomId：房间ID。
- direction：数据源，本地数据，远端数据，具体请参见[HRTCMediaDirection](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section41882561268)。
- userId：视频数据对应的远端用户ID。
- videoFrame：视频帧详情，具体请参见[HRTCVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section252640124317)。
 
 #### onPlaybackExternalAudioFrame
```
virtual void onPlaybackExternalAudioFrame(const char* roomId, HRTCMediaDirection direction, HRTCAudioFrame& audioFrame)
```
【**功能说明**】
音频自渲染回调。需要调用[setExternalAudioFrameOutput](https://support.huaweicloud.com/csdk-rtc/rtc_05_0105.html#rtc_05_0105__section1275317485323)接口开启音频自渲染，从而触发该回调。
【**回调参数**】
- roomId：房间ID。
- direction：数据源，本地数据，远端数据，具体请参见[HRTCMediaDirection](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section41882561268)。
- audioFrame：音频帧详情，具体请参见[HRTCAudioFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1015722617613)。
 
 #### onRejoinRoomSuccess
```
virtual void onRejoinRoomSuccess(const char* roomId, const char* userId)
```
【**功能说明**】
重新加入房间回调。例如网络异常后重连成功加入房间触发。
【**回调参数**】
- roomId：房间ID。
- userId：用户ID。
 
 #### onNetworkTestQuality
```
virtual void onNetworkTestQuality(HRTCNetworkQualityLevel level)
```
【**功能说明**】
加房间前网络探测回调。
【**回调参数**】
level：网络质量，具体请参见[HRTCNetworkQualityLevel](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section195341126192013)。
 #### onNetworkTestResult
```
virtual void onNetworkTestResult(HRTCNetworkTestResult& networkTestResult)
```
【**功能说明**】
加房间前网络探测结果回调。
【**回调参数**】
networkTestResult：主要包括测试成功与否、上行和下行的网络带宽、丢包、延时和抖动，具体请参见[HRTCNetworkTestResult](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section8291202014203)。
 #### onUserVolumeStatsNotify
```
virtual void onUserVolumeStatsNotify(const HRTCVolumeInfo* userVolumes, unsigned int userVolumesCount, unsigned int totalVolume)
```
【**功能说明**】
用户音量状态回调。通过[enableUserVolumeNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0100.html#rtc_05_0100__zh-cn_topic_0000001160409613_section16217114063820)开启并设置回调周期，定时上报。
【**回调参数**】
- userVolumes：用户信息，具体请参见[HRTCVolumeInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section729719918275)。
- userVolumesCount：上报的用户人数，包含本地用户。
- totalVolume：总音量。
 
#### onTopActiveSpeaker
```
virtual void onTopActiveSpeaker(const char* userId, bool noStream)
```
【**功能说明**】
声控画面的用户ID变化时，触发此回调。该回调主要用于0号会场场景（订阅用户id为0的音频）。
【**回调参数**】
userId：返回当前声控画面的用户ID。
noStream：该用户是否有视频流。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
0号会场模式下，SDK会持续监测（根据一定时间内用户音量大小）当前最活跃的用户，如果最活跃用户发生变化，则触发此回调并上报当前最活跃的用户userId。
#### onLocalAudioStateChangedNotify
```
virtual void onLocalAudioStateChangedNotify(HRTCLocalAudioStreamState state, HRTCLocalAudioStreamStateReason reason)
```
【**功能说明**】
本地音频状态改变，触发此回调。
【**回调参数**】
- state：本地音频状态，具体请参见[HRTCLocalAudioStreamState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1907681286)。
- reason：本地音频状态改变的原因，具体请参见[HRTCLocalAudioStreamStateReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1737961311817)。
 
#### onLocalVideoStateChangedNotify
```
virtual void onLocalVideoStateChangedNotify(HRTCLocalVideoStreamState state, HRTCLocalVideoStreamStateReason reason)
```
【**功能说明**】
本地视频状态改变，触发此回调。
【**回调参数**】
- state：本地视频状态，具体请参见[HRTCLocalVideoStreamState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1631414204610)。
- reason：本地视频状态改变原因，具体请参见[HRTCLocalVideoStreamStateReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section530116162462)。
 
 #### onNetworkQualityNotify
```
virtual void onNetworkQualityNotify(HRTCQualityInfo* localQuality, unsigned int localQualityCount, HRTCQualityInfo* remoteQuality, unsigned int remoteQualityCount)
```
【**功能说明**】
房间内客户端基于流级别的网络质量实时上报，默认开启，每2s上报一次，有数据流时才会回调，音频流、视频流分开回调。
【**回调参数**】
- localQuality：本地上行网络质量，该参数暂时不使用。
- localQualityCount：正在上报的网络质量数量，该参数暂时不使用。
- remoteQuality：（本地下行）远端各路流的网络质量，具体请参见[HRTCQualityInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section16340181819464)。
- remoteQualityCount：正在上报的流的数量，集合的大小。
 
 #### onRenderSuccessNotify
```
virtual void onRenderSuccessNotify(const char* userId, unsigned int isAux)
```
【**功能说明**】
媒体恢复渲染成功回调。
回调包括以下场景：
- 视频流第一次渲染；
- 分辨率有变化；
- 一段时间没有渲染后恢复渲染（2s）。
【**回调参数**】
- userId：用户ID。
- isAux：是否是辅流。
 
 #### onLocalVolumeChangedNotify
```
virtual void onLocalVolumeChangedNotify(unsigned int volume, unsigned int muted)
```
【**功能说明**】
本地采集音量回调。
【**回调参数**】
- volume：麦克风采集音量。
- muted：是否静音，用于区分是没有声音还是muted。
 
 #### onFirstLocalAudioFrameNotify
```
virtual void onFirstLocalAudioFrameNotify(unsigned int elapsed)
```
【**功能说明**】
本地音频首帧发送回调。
【**回调参数**】
elapsed：从入会到本地音频首帧发送所用的时间，单位ms。
 #### onFirstLocalVideoFrameNotify
```
virtual void onFirstLocalVideoFrameNotify(unsigned int elapsed)
```
【**功能说明**】
本地视频首帧渲染回调。
【**回调参数**】
elapsed：从开始采集到本地视频首帧渲染所用的时间，单位ms。
#### onMediaConnectStateChangedNotify
```
virtual void onMediaConnectStateChangedNotify(HRTCMediaConnStateTypes state, HRTCMediaConnChangeReason reason, const char* description)
```
【**功能说明**】
媒体服务器连接状态变更通知。
【**回调参数**】
- state：与媒体服务器连接状态，具体请参见[HRTCMediaConnStateTypes](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1784814239711)。
- reason：连接状态变化的原因，具体请参见[HRTCMediaConnChangeReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section13292263715)。
- description：连接状态变化原因描述。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
加入房间过后，收到媒体服务的数据包时，返回Connected消息，超过6s没有收到包，则返回Failed消息。
 #### onStartAllRemoteViewResult
```
virtual void onStartAllRemoteViewResult(int errCode, const char* errMsg, unsigned int counts, const HRTCSetupRemoteViewResult* results)
```
【**功能说明**】
批量选看结果回调。
【**回调参数**】
- errCode：错误码。
- errMsg：错误信息。
- counts：results数组大小。
- results：批量选看结果，具体请参见[HRTCSetupRemoteViewResult](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section895105225712)。
 
#### onStatsNotify
```
virtual void onStatsNotify(HRTCOnStats *rtcStats)
```
【**功能说明**】
当前会话统计回调。
【**回调参数**】
rtcStats：当前会话统计，具体请参见[HRTCOnStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section14832161915511)。
#### onLocalVideoStatsNotify
```
virtual void onLocalVideoStatsNotify(const HRTCLocalVideoStats *localStats, unsigned int localStatsCount)
```
【**功能说明**】
本地视频流详情，2s触发一次回调。
【**回调参数**】
- localStats：本地视频收流统计，具体请参见[HRTCLocalVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section133091918111612)。
- localStatsCount：localStats数组长度。
 
#### onRemoteVideoStatsNotify
```
virtual void onRemoteVideoStatsNotify(const HRTCRemoteVideoStats *remoteStats, unsigned int remoteStatsCount)
```
【**功能说明**】
远端视频流详情，2s触发一次回调。
【**回调参数**】
- remoteStats：远端视频收流统计，具体请参见[HRTCRemoteVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1519645813161)。
- remoteStatsCount：remoteStats数组长度。
 
#### onLocalAudioStatsNotify
```
virtual void onLocalAudioStatsNotify(const HRTCLocalAudioStats *localStats, unsigned int localStatsCount)
```
【**功能说明**】
本地音频流详情，2s触发一次回调。
【**回调参数**】
- localStats：本地音频收流统计，具体请参见[HRTCLocalAudioStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section1483619515499)。
- localStatsCount：localStats数组长度。
#### onRemoteAudioStatsNotify
```
virtual void onRemoteAudioStatsNotify(const HRTCRemoteAudioStats *remoteStats, unsigned int remoteStatsCount)
```
【**功能说明**】
远端音频流详情，2s触发一次回调。
【**回调参数**】
- remoteStats：远端音频收流统计，具体请参见[HRTCRemoteAudioStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section6738131145018)。
- remoteStatsCount：remoteStats数组长度。
#### onVideoResolutionChangedNotify
```
virtual void onVideoResolutionChangedNotify(const char* userId, int width, int height)
```
【**功能说明**】
远端视频分辨率大小改变，触发此回调。
【**回调参数**】
- userId：用户ID。
- width：视频分辨率改变后的宽。
- height：视频分辨率改变后的高。
 #### onAudioClipFinished
```
virtual void onAudioClipFinished(int soundId)
```
【**功能说明**】
音效文件播放结束，触发此回调。
【**回调参数**】
soundId：音效ID，取值\>=0。
 #### onAudioFileFinished
```
virtual void onAudioFileFinished()
```
【**功能说明**】
音频文件播放结束，触发此回调。
【**回调参数**】
无
 #### onAudioMixStateChangedNotify
```
virtual void onAudioMixStateChangedNotify(HRTCAudioFileState state, HRTCAudioFileReason reason, unsigned long long value)
```
【**功能说明**】
音频文件播放状态改变，触发此回调。
【**回调参数**】
- state：音频播放状态，具体请参见[HRTCAudioFileState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section49629118111)。
- reason：音频播放状态改变原因，具体请参见[HRTCAudioFileReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section18807173319112)。
- value：state为HWRtcAudioFileOpenCompleted表示音频文件的时长，单位为ms；state为HWRtcAudioFilePositionUpdate表示当前播放的位置，单位为ms。其他情况下，value值无意义。
 #### onSeiSendMsgSuccess
```
void onSeiSendMsgSuccess(const char* message);
```
【**功能说明**】
音频SEI信息发送成功回调。
【**回调参数**】
message：发送SEI信息的内容。
 #### onSeiRecvMsg
```
void onSeiRecvMsg(const char* userId, const char* message);
```
【**功能说明**】
接收音频SEI信息回调。
【**回调参数**】
- userId：用户ID。
- message：接收SEI信息的内容。
 
 #### onStartPublishStream
```
void onStartPublishStream(int code, const char* taskId);
```
【**功能说明**】
开始旁路（RTMP）推流回调。
【**回调参数**】
- code：错误码，成功为0，失败请参考错误码[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
- taskId：任务Id。
 
 #### onUpdateTransCoding
```
void onUpdateTransCoding(int code, const char* taskId);
```
【**功能说明**】
更新旁路（RTMP）推流消息。
【**回调参数**】
- code：错误码，成功为0，失败请参考错误码[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
- taskId：任务Id。
 
 #### onStopPublishStream
```
void onStopPublishStream(int code, const char* taskId);
```
【**功能说明**】
停止旁路（RTMP）推流消息。
【**回调参数**】
- code：错误码，成功为0，失败请参考错误码[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
- taskId：任务Id。
 
 #### onStreamPublishStateChange
```
void onStreamPublishStateChange(int code, const char* taskId, const HRTCUrlStatusList * urlStatu);
```
【**功能说明**】
RTMP推流状态回调。
【**回调参数**】
- code：错误码，成功为0，失败请参考错误码[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
- taskId：任务Id。
- urlStatu：推流的url状态，具体请参见[HRTCUrlStatusList](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section159071888515)。
 
 #### onAudioDeviceTestVolumeNotify
```
void onAudioDeviceTestVolumeNotify(HRTCAudioDeviceTestVolumeNotify *data);
```
【**功能说明**】
音频设备测试回调。
【**回调参数**】
data：回调数据，具体请参见[HRTCAudioDeviceTestVolumeNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section1113845862319)。
 #### onShareSourceInfoChangedNotify
```
void onShareSourceInfoChangedNotify(HRTCShareSourceInfoChangedType type);
```
【**功能说明**】
共享源目标发生变化通知。
【**回调参数**】
type：具体请参见[HRTCShareSourceInfoChangedType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section953113296475)
 #### onShareWindowLocationChangedNotify
```
void onShareWindowLocationChangedNotify(const char* info);
```
【**功能说明**】
共享源目标坐标或者DPI发生变化通知。
【**回调参数**】
info：json类型，如{dpi:100, x:0, y:0, width:1920, height:1080}
- dpi：当前窗口的缩放
- x：左上角x轴坐标
- y：左上角y轴坐标
- width：宽
- height：高
 
 #### onLocalAudioMutedStatusDetected
```
void onLocalAudioMutedStatusDetected();
```
【**功能说明**】
本端禁音状态被检测到。
**回调参数**
无
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
通过[enableUserVolumeNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0100.html#rtc_05_0100__zh-cn_topic_0000001160409613_section16217114063820)开启并设置回调周期，本端禁音后检测到麦克风有输入后定时上报。上报频率和[enableUserVolumeNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0100.html#rtc_05_0100__zh-cn_topic_0000001160409613_section16217114063820)的参数大小相关，参考值建议设置成200。
 #### onMultiRoomMediaRelayStateChanged
```
void onMultiRoomMediaRelayStateChanged(const char *roomId, HRTCMultiRoomMediaRelayState state, HRTCMultiRoomMediaRelayStateCode code);
```
【**功能说明**】
跨房状态回调。
**【回调参数**】
roomId：跨房房间号。
state：状态类型，具体请参见[HRTCMultiRoomMediaRelayState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section817464593514)。
code：状态的具体原因，具体请参见[HRTCMultiRoomMediaRelayStateCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section12745550193512)。
 #### onRemoteMicrophoneStateChanged
```
void onRemoteMicrophoneStateChanged(const char* userId, HRTCRemoteMicState state);
```
【**功能说明**】
远端麦克风设备状态变更通知。
**【回调参数**】
userId：远端用户userId。
state：麦克风设备状态，具体请参见[HRTCRemoteMicState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section5682143519474)。
 #### onUserNetworkQualityNotify
```
void onUserNetworkQualityNotify(const char *roomId, const char* userId, HRTCNetworkQualityLevel txQuality,  HRTCNetworkQualityLevel rxQuality);
```
【**功能说明**】
支持用户上报各自与近端SFU间的上下行网络质量，基于用户级，使本地用户能获取同房间内远端用户与其近端SFU间的网络质量。CMD广播时为房间级，将广播给订阅了此主播流的用户或者此主播被选为TOPN用户且观众订阅了该TOPN用户。
【**回调参数**】
- roomId：用户所在房间号。
- userId: 上报的用户id，0为本地，非0为远端。
- txQuality：该用户的上行网络质量，具体请参见[HRTCNetworkQualityLevel](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section195341126192013)。
- rxQuality：该用户的下行网络质量，具体请参见[HRTCNetworkQualityLevel](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section195341126192013)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 此接口不支持跨房场景、WebRTC场景。
- 不支持RTSA。
 
 #### onRoomStreamStatusNotify
```
void onRoomStreamStatusNotify(int audienceState)
```
【**功能说明**】
房间流状态通知，业务调用云侧暂停/恢复接口后，端侧收到该通知。
【**回调参数**】
audienceState：0表示暂停 ，1表示恢复。
