连接视频流程
- (1)说明:连接视频支持 tcp 、 udp 、 muc 网络传输模式,以下程序为控制台程序,VC环境下编译运行,可连接播放视频。
- (2)注意:收到登陆成功的消息后进行连接视频的操作,收到视频头的消息后进行播放视频的操作。
示例代码
#include "NetSDK.h"
#include <stdio.h>
int g_iLogonID = -1;
unsigned int g_uConnID = -1;
unsigned int StartRecv(int _iLogonID)
{
unsigned int uConnID = -1;
CLIENTINFO clientinfo = {0};
clientinfo.m_iNetMode = NETMODE_TCP;
clientinfo.m_iServerID = _iLogonID;
clientinfo.m_iChannelNo = 0;//预览通道号
clientinfo.m_iStreamNO = MAIN_STREAM;
int iRet = NetClient_StartRecv(&uConnID,&clientinfo,NULL);//建立视频连接
if (iRet == 0)
{
printf("StartRecv success!\n");
}
else
{
printf("StartRecv failed!\n");
}
return uConnID;
}
void StartPlay(unsigned int _uConnID)
{
RECT rc = {0};
HWND hWnd = GetConsoleWindow();//获得窗口句柄
NetClient_StopPlay(_uConnID);//停止播放视频
int iRet = NetClient_StartPlay(_uConnID, hWnd, rc, H264DEC_DECTWO);//开始播放视频
if(iRet >= 0)
{
printf("StartPlay success!\n");
}
else
{
printf("StartPlay failed!\n");
}
}
void Notify_Main(int _iLogonID, int _iWparam, int _iLParam,int _iUserData)
{
int iMsgType = LOWORD(_iWparam);
switch (iMsgType)
{
case WCM_LOGON_NOTIFY:
{
printf("WCM_LOGON_NOTIFY\n");
if(_iLParam == LOGON_SUCCESS)
{
printf("Logon success!\n");
g_uConnID = StartRecv(_iLogonID);//连接视频
}
else
{
printf("Logon failed!\n");
}
}
break;
case WCM_VIDEO_HEAD:
{
printf("WCM_VIDEO_HEAD\n");
StartPlay(g_uConnID);//播放视频
}
break;
default:
break;
}
}
int main(int argc,char *argv[])
{
LoadNVSSDK();//初始化接口库
NetClient_Startup_V4(3000, 6000, 0);//初始化SDK
NetClient_SetNotifyFunction_V4(Notify_Main, NULL, NULL, NULL, NULL);//设置回调函数
//登录设备
g_iLogonID = NetClient_Logon("", "10.30.11.250", "Admin", "1111", "", 3000);
if(g_iLogonID < 0)
{
printf("Logon failed!\n");
}
getchar();//等待用户输入
NetClient_Logoff(g_iLogonID);//注销用户
NetClient_Cleanup();//释放SDK资源
FreeNVSSDK();//释放接口库
return 0;
}