TSINGSEE青犀视频研发的部分视频平台已经支持了语音喊话对讲的功能,在室内的安防视频监控中,语音对讲的实用性不可小觑,因此我们在使用EasyCVR视频监控系统上云平台集成海康EHome协议时,也实现了语音对讲功能。
本文档就讲一下基于海康EHome协议实现语音对讲功能步骤。
开始语音对讲操作前,务必进行NET_ECMS_Init初始化CMS,NET_ECMS_StartListen开启CMS监听服务以接收设备注册信息。
开启语音对讲接口调用流程
设备必须支持语音对讲功能,程序中可以调用NET_ECMS_StartListen开启CMS监听和注册回调函数,将回调函数DEVICE_REGISTER_CB中的dwDataType设为ENUM_DEV_ON,设备支持的版本信息会通过结构体NET_EHOME_DEV_REG_INFO的成员byDevProtocolVersion进行回调。
具体的操作步骤
1、调用NET_ECMS_StartVoiceTalk并将NET_EHOME_VOICETALK_PARA中的byVoiceTalk设置为“0”,从而开启语音对讲
2、调用NET_ECMS_StopVoiceTalk停止语音转发和对讲。
3、调用NET_ECMS_ForceLogout强制注销设备
代码示例
#include
#include "HCISUPCMS.h"
LONG lLoginID = -1;
LONG m_lVoiceTalkHandle = -1;
//
//注册回调函数
BOOL CALLBACK RegisterCallBack(LONG lUserID, DWORD dwDataType, void *pOutBuffer, DWORD dwOutLen, void *pInBuffer, DWORD dwInLen, void *pUser)
{
if (ENUM_DEV_ON == dwDataType)
{
NET_EHOME_DEV_REG_INFO *pDevInfo = (NET_EHOME_DEV_REG_INFO *)pOutBuffer;
if (pDevInfo != NULL)
{
lLoginID = lUserID;
printf("On-line, lUserID: %d, Device ID: %s\n", lLoginID, pDevInfo->byDeviceID);
}
//输入参数
NET_EHOME_SERVER_INFO *pServerInfo = (NET_EHOME_SERVER_INFO *)pInBuffer;
pServerInfo->dwTimeOutCount = 6; //心跳超时次数
pServerInfo->dwKeepAliveSec = 15; //心跳间隔
}
else if (ENUM_DEV_OFF == dwDataType)
{
printf("Off-line, lUserID: %d\n", lUserID);
NET_ECMS_ForceLogout(lUserID);
}
else
{
}
return TRUE;
}
//
//语音数据回调函数
void CALLBACK g_fVoiceDataCallBack(LONG iVoiceComHandle, char *pRecvDataBuffer, DWORD dwBufSize, DWORD dwEncodeType, BYTE byAudioFlag, void *pUser)
{
//获取到语音数据自行处理
}
void main(){
//CMS注册和预览请求
//CMS注册模块初始化
NET_ECMS_Init();
//注册监听参数
NET_EHOME_CMS_LISTEN_PARAM struCMSListenPara = {0};
memcpy(struCMSListenPara.struAddress.szIP, "0.0.0.0", sizeof("0.0.0.0"));
struCMSListenPara.struAddress.wPort = 7660;
struCMSListenPara.fnCB = RegisterCallBack;
//启动监听服务,接收设备注册信息
LONG lListen = NET_ECMS_StartListen(&struCMSListenPara);
if(lListen < -1)
{
printf("NET_ECMS_StartListen failed, error code: %d\n", NET_ECMS_GetLastError());
NET_ECMS_Fini();
return;
}
printf("NET_ECMS_StartListen!\n");
while(1)
{
Sleep(1000); //注册成功之后再做后续操作
if(lLoginID >= 0)
{
break;
}
}
//语音对讲参数
NET_EHOME_VOICETALK_PARA struVoiceTalkPara = {0};
struVoiceTalkPara.bNeedCBNoEncData = 0; //需要回调的语音类型:0- 编码后语音,1- 编码前语音(语音转发时不支持)
struVoiceTalkPara.cbVoiceDataCallBack = g_fVoiceDataCallBack;
struVoiceTalkPara.dwEncodeType = 0; //设备的语音编码类型:0- G722,1- G711U,2- G711A,3- G726,4- AAC,5- MP2L2,6- PCM
struVoiceTalkPara.byVoiceTalk = 0; //语音对讲模式:0- 语音对讲,1- 语音转发
DWORD dwVoiceChan = 1; //语音对讲通道号
//开始语音对讲
m_lVoiceTalkHandle = NET_ECMS_StartVoiceTalk(lLoginID, dwVoiceChan, &struVoiceTalkPara);
if (m_lVoiceTalkHandle < 0)
{
printf("NET_ECMS_StartVoiceTalk failed, error code: %d\n", NET_ECMS_GetLastError());
NET_ECMS_Fini();
return;
}
Sleep(30000);
//停止语音对讲
if(!NET_ECMS_StopVoiceTalk(m_lVoiceTalkHandle))
{
printf("NET_ECMS_StopVoiceTalk failed, error code: %d\n", NET_ECMS_GetLastError());
NET_ECMS_Fini();
return;
}
//退出
//CMS停止监听服务
if(!NET_ECMS_StopListen(lListen))
{
printf("NET_ECMS_StopListen failed, error code: %d\n", NET_ECMS_GetLastError());
}
//CMS反初始化,释放资源
NET_ECMS_Fini();
printf("Exit!\n");
}
视频相关解决方案均可访问TSINGSEE青犀视频官网,详细了解系统效果,且可随意进行下载及测试:www.tsingsee.com。