当前通话信息
本章节主要介绍在通话过程中,您可能要用到的各种通话信息。
获取通话状态
API介绍
获取当前的通话状态,允许客户在业务需要的时机主动发起查询,确认当前用户 与音视频服务器的连接状态。适用于对房间中用户状态较敏感的客户,比如需要较高互动性的多人语聊室。
API原型
C++
static NIMVChatConnectStatus GetConnectStatus()
File: nim_cpp_vchat.h
Namespace: nim
Class: VChat
C
typedef int (*nim_vchat_get_connect_status)()
File: nim_vchat.h
参数说明
返回结果指向枚举NIMVChatConnectStatus
示例
C++
void foo() { NIMVChatConnectStatus status = nim::VChat::GetConnectStatus(); }
C
typedef bool(*nim_vchat_get_connect_status)(); void foo() { nim_vchat_get_connect_status func = (nim_vchat_get_connect_status) GetProcAddress(hInst, "nim_vchat_get_connect_status"); NIMVChatConnectStatus status = (NIMVChatConnectStatus)func(); }
实时音视频数据状态
API介绍
在连接建立后,会定时2秒返回一次通话的状态信息。如视频码流信息,音频流信息,系统资源等。通过音视频全局回调接口返回。
API原型
C#
NIMVChatSessionStatus.onSessionRealtimeStateNotify
public delegate void onSessionRealtimeInfoNotifyHandler(long channel_id, int code, NIMVChatRealtimeState state)
Namespace:NIM
Class:VChatAPI
C++/C
typedef void (*nim_vchat_cb_func)(enum NIMVideoChatSessionType type, int64 channel_id, int code, const char *json_extension, const void *user_data)
NIMVideoChatSessionType::kNIMVideoChatSessionTypeInfoNotify
File:nim_vchat_def.h
参数说明
- C#
参数 | 类型 | 说明 |
---|---|---|
channel_id | long | 频道id |
code | int | 无效状态码 |
status | object | 状态信息 NIMVChatRealtimeState |
- C++/C
参数 | 类型 | 说明 |
---|---|---|
type | enum | 回调类型kNIMVideoChatSessionTypeInfoNotify |
channel_id | int64 | 频道id |
code | int | 无效状态码 |
json_extension | string | Json string 扩展,返回kNIMVChatStaticInfo,见音视频事件通知扩展参数,示例:{"static_info":{"rtt":20, "video": {"fps":20, "KBps":200, "lost_rate":5, "width":1280,"height":720}, "audio": {"fps":17, "KBps":3", lost_rate":3 }}} |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
示例
C#
private static void onSessionRealtimeInfo(long channel_id, int code, NIMVChatRealtimeState state) { state.Info.VideoState;//视频信息,包括帧率,编码码率,丢包,宽高 state.Info.AudioState;//音频信息,包括音频每秒分包数,编码码率,丢包 state.Info.Rtt;//延迟 }
C++/C
void VChatCb(nim::NIMVideoChatSessionType type, __int64 channel_id, int code, const char *json, const void*) { switch (type) { case nim::kNIMVideoChatSessionTypeInfoNotify:{ Json::Value valus; Json::Reader reader; if (reader.parse(json, valus) && valus[kNIMVChatStaticInfo].isObject()) { std::string v_info; for (int i = 0; i < valus[kNIMVChatStaticInfo][kNIMVChatVideo].size(); i++) { auto &v = valus[kNIMVChatStaticInfo][kNIMVChatVideo][i]; int ssm = v["v_type"].asUInt(); int video_width = v[kNRTCDeviceWidth].asInt(); int video_height = v[kNRTCDeviceHeight].asInt(); int video_fps = v[kNIMVChatFPS].asInt(); int video_KBps = v[kNIMVChatKBPS].asInt(); int video_loss_rate = v[kNIMVChatLostRate].asInt(); std::string info = StringPrintf("v_type:%d \tvideo:%d*%d \tfps:%d \tKBps: %d \tloss:%d%% \n", \ ssm, video_width, video_height, video_fps, video_KBps, video_loss_rate); v_info += info; } int audio_fps = valus[kNIMVChatStaticInfo][kNIMVChatAudio][kNIMVChatFPS].asInt(); int audio_KBps = valus[kNIMVChatStaticInfo][kNIMVChatAudio][kNIMVChatKBPS].asInt(); int audio_loss_rate = valus[kNIMVChatStaticInfo][kNIMVChatAudio][kNIMVChatLostRate].asInt(); int cpu_t = valus[kNIMVChatStaticInfo][kNIMVChatCpu][kNIMVChatTotalPercent].asInt(); int cpu_s = valus[kNIMVChatStaticInfo][kNIMVChatCpu][kNIMVChatSelfPercent].asInt(); int memory_size = valus[kNIMVChatStaticInfo][kNIMVChatMemInfo][kNIMVChatMemorySize].asInt(); std::string info = StringPrintf("video:\t\t%s audio: \t\tfps:%d \tKBps: %d \tloss:%d%% \ncpu: total:%d%% \tself:%d%% \nmemory:%dKB", \ v_info.c_str(), audio_fps, audio_KBps, audio_loss_rate, cpu_t, cpu_s, memory_size); } }break; //··· } }
当前音量回调
在连接建立后,会定时200毫秒返回一次通话的音量信息。带有本人的音量和当前说话的成员音量信息,未说话成员不上报。
API原型
C#
NIMVChatSessionStatus.onSessionVolumeStateChanged
public delegate void onSessionVolumeNotifyHandler(long channel_id, int code, NIMVchatAudioVolumeState state)
Namespace:NIM
Class:VChatAPI
C++/C
typedef void (*nim_vchat_cb_func)(enum NIMVideoChatSessionType type, int64 channel_id, int code, const char *json_extension, const void *user_data)
NIMVideoChatSessionType::kNIMVideoChatSessionTypeVolumeNotify
File:nim_vchat_def.h
参数说明
- C#
参数 | 类型 | 说明 |
---|---|---|
channel_id | long | 频道id |
code | int | 无效状态码 |
status | object | 状态信息 NIMVchatAudioVolumeState |
- C++/C
参数 | 类型 | 说明 |
---|---|---|
type | enum | 回调类型kNIMVideoChatSessionTypeVolumeNotify |
channel_id | int64 | 频道id |
code | int | 无效状态码 |
json_extension | string | Json string 扩展,返回kNIMVChatAudioVolume,见音视频事件通知扩展参数,示例:{"audio_volume":{ "self": {"status":600}, "receiver": [{"uid":"id123","status":1000},{"uid":"id456","status":222}] }} |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
音量值说明
返回的音量值是一个整型,是音量pcm数据数字域的平均值。如果需要转成近似的分贝值,将得到的音量rms如下转换:
int ret = (int)(20.0*log10(rms * 1.0 / 65535.0)) + 96;
示例
C#
private static void onSessionVolume(long channel_id, int code, NIMVchatAudioVolumeState state) { state.Self;//本人音量信息 state.Receivers;//其他成员音量 }
C++/C
void VChatCb(nim::NIMVideoChatSessionType type, __int64 channel_id, int code, const char *json, const void*) { switch (type) { case nim::kNIMVideoChatSessionTypeInfoNotify:{ Json::Value valus; Json::Reader reader; if (reader.parse(json, valus) && valus[kNIMVChatAudioVolume].isObject()) { Json::Value valus_vol = valus[kNIMVChatAudioVolume]; int self_volume = valus_info[kNIMVChatSelf][kNIMVChatStatus].asInt(); std::map<std::string, int32_t> other_volume; if (valus_info[nim::kNIMVChatReceiver].isArray()) { int count = valus_info[nim::kNIMVChatReceiver].size(); for (int i = 0; i < count; ++i) { Json::Value item; item = valus_info[nim::kNIMVChatReceiver].get(i, item); std::string uid = item[nim::kNIMVChatUid].asString(); int32_t status = item[nim::kNIMVChatStatus].asInt(); other_volume[uid] = status; } } } }break; //··· } }