宇视IMOS 平台 SDK 开发记录探测视频数据demo

没接触过宇视平台,刚开始百度了下宇视SDK后来发现网上搜到的都是NetDevSDK 这个

那IMOS又是啥,领导安排就说宇视平台 我以为是NetDevSDK这个,后来咨询了另一位同事才知道

IMOS是IMP8500 的一个类似于视频NVR管理平台,而NetDEvSDK 是针对IPC之类的终端设备的

和IMOS一点关系也没有

也没有文档 花了一天时间,参考原来的例子写了个探测是否有码流的小程序

执行方式:TestIMOS.exe 服务器IP 端口 用户名 密码 摄像机编号 码流编号

有视频的话会打印出视频的数据

宇视IMOS 平台 SDK 开发记录探测视频数据demo

 宇视IMOS 平台 SDK 开发记录探测视频数据demo

代码如下:

// TestIMOS.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>


#include "GeneralDef.h"

#include "imos_public.h"
#include "imos_errcode.h"
#include "imos_def.h"

#include "sdk_def.h"
#include "sdk_struct.h"
#include "sdk_func.h"

#include<windows.h>

LOGIN_INFO_S login_info;

VOID STDCALL GetPacketCB(IN const USER_LOGIN_ID_INFO_S *pstUserLoginIDInfo,
	IN const CHAR *pcChannelCode,
	IN const XP_PARSE_VIDEO_DATA_S *pstParseVideoData,
	IN LONG lUserParam,
	IN LONG lReserved)
{
	static int total = 0;

	//ulVideoCodeFormat 0:MPEG2,1:MPEG4,2:H264,MJPEG :3
	//ulVideoFrameType I:0,P:1,B:2
	total++;
	printf("size:%d WXH[%dX%d] frame[%d] format[%d],content[%02X %02X %02X %02X %02X %02X %02X %02X]\n", pstParseVideoData->ulDataLen, pstParseVideoData->ulWidth, pstParseVideoData->ulHeight, 
		pstParseVideoData->ulVideoFrameType,pstParseVideoData->ulVideoCodeFormat,
		pstParseVideoData->pucData[0], pstParseVideoData->pucData[1], pstParseVideoData->pucData[2], pstParseVideoData->pucData[3], 
		pstParseVideoData->pucData[4], pstParseVideoData->pucData[5], pstParseVideoData->pucData[6], pstParseVideoData->pucData[7]);

	if (total == 100)
	{
		printf("exit program\n");
		IMOS_LogoutEx(&login_info.stUserLoginIDInfo);
		IMOS_CleanUp(NULL);
		exit(1);
	}
	return;
}



int main(int argc, char*argv[])
{
	CHAR * dummy = (CHAR*)"N/A";

	char  m_userName[32] = {0};		//用户名
	char  m_passWord[64] = {0};		//密码
	char  m_proxyIp[64] = {0};
	char  m_deviceId[128] = {0};		//设备ID
	LONG  m_proxyPort = 8800;
	const char* name = "spsy";
	const char* pass = "gdkjspsy";
	const char* ip = "10.118.6.254";
	int port = 8800;

	CHAR szPasswd[IMOS_PASSWD_ENCRYPT_LEN] = { 0 };
	
	char stream_index = 0;//0:Main stream 1:substream,2:thrid stream

	char m_szXpCode[IMOS_RES_CODE_LEN];



	if (argc == 2)//cmd deviceid
	{
		memcpy(m_deviceId, argv[1], strlen(argv[1]));
	}
	else if (argc == 7) //cmd streamindex deviceid
	{
	
		memcpy(m_proxyIp, argv[1], strlen(argv[1]));
		port = atoi(argv[2]);
		memcpy(m_userName, argv[3], strlen(argv[3]));
		memcpy(m_passWord, argv[4], strlen(argv[4]));
		memcpy(m_deviceId, argv[5], strlen(argv[5]));
		stream_index = atoi(argv[6]);
	}
	else
	{
		printf("Execute like this imos:ip port username password deviceid streamindex\n");
		//return -1;
	}


	
	int   ret = IMOS_Initiate(m_proxyIp, port, BOOL_TRUE, BOOL_TRUE);
	if (ERR_COMMON_SUCCEED != ret)
	{
		std::cout << "Init failed" << std::endl;
		return -1;
	}
	else
	{
		std::cout << "Init Success :\n" << ret << std::endl;
	}


	ret = IMOS_Encrypt(m_passWord, strlen(m_passWord), szPasswd);
	if (ERR_COMMON_SUCCEED != ret)
	{
		printf("Encrypt failed\n");
		return -1;
	}
	else
	{
		printf("Encrypt success:[%s]\n",szPasswd);
	}
	ret  = IMOS_LoginEx(m_userName, szPasswd, m_proxyIp, dummy, &login_info);//IMOS_Login(szUserLoginName, szPasswd, szServerAdd, &g_stLoginInfo);

	if (ERR_COMMON_SUCCEED != ret)
	{
		printf("IMOS_LoginEx failed ret is %d ip[%s] port[%d] username[%s] pass[%s] deviceid[%s] streamindex[%d]\n", ret,m_proxyIp, port, m_userName, m_passWord,m_deviceId,stream_index);
		return -1;
	}

	
	PLAY_WND_INFO_S *pstPlayWndInfoList = (PLAY_WND_INFO_S*)malloc(DEMO_MAX_PLAYS * sizeof(PLAY_WND_INFO_S));
	if (NULL == pstPlayWndInfoList)
	{
		printf("No memory \n");
		return -1;
	}

	memset(pstPlayWndInfoList, 0, DEMO_MAX_PLAYS * sizeof(PLAY_WND_INFO_S));

	ret = IMOS_StartPlayer(&login_info.stUserLoginIDInfo, DEMO_MAX_PLAYS, pstPlayWndInfoList);
	if (ERR_COMMON_SUCCEED != ret)
	{
		free(pstPlayWndInfoList);
		printf("IMOS_StartPlayer failed \n");
		return -1;
	}
	free(pstPlayWndInfoList);
	IMOS_AutoKeepAlive(&login_info.stUserLoginIDInfo);

	ret = IMOS_GetChannelCode(&login_info.stUserLoginIDInfo, m_szXpCode);
	if (ERR_COMMON_SUCCEED != ret)
	{
		printf("IMOS_GetChannelCode failed ret is %d\n", ret);
		return -1;
	}

	printf("m_szXpCode = %s \n", m_szXpCode);



	ret = IMOS_SetParseVideoDataCB(&login_info.stUserLoginIDInfo, m_szXpCode,GetPacketCB,0,0);
	if (ERR_COMMON_SUCCEED != ret)
	{
		printf("IMOS_SetParseVideoDataCB failed ret is %d\n", ret);
		return -1;
	}


	DEV_STATUS_INFO_S status = {0};
	
	ret = IMOS_QueryDevStatus(&login_info.stUserLoginIDInfo,40,&status);


	printf("IMOS_QueryDevStatus ret is %d status[%d] code[%s],name[%s]\n", ret, status.ulDevType,status.szDevCode,status.szDevName);

	CAMERA_INFO_S cam_info = { 0 };
	//IMOS_QueryCameraAndChannelList(&login_info.stUserLoginIDInfo,);
	ret = IMOS_QueryCamera(&login_info.stUserLoginIDInfo, m_deviceId, &cam_info);
	printf("IMOS_QueryCamera ret is %d status[%d] code[%s],name[%s]\n", ret, cam_info.ulChannelIndex, cam_info.szCameraCode, cam_info.szCameraName);
	  
	ret = IMOS_StartMonitor(&login_info.stUserLoginIDInfo,m_deviceId,m_szXpCode, stream_index,USER_OPERATE_SERVICE);
	if (ERR_COMMON_SUCCEED != ret)
	{
		printf("IMOS_StartMonitor failed ret is %d\n", ret);

		IMOS_LogoutEx(&login_info.stUserLoginIDInfo);
		IMOS_CleanUp(NULL);

		return -1;

	}


	while (1)
	{
		//printf("Sleep index \n");
		Sleep(5);
	}

	return 0;
}




// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

上一篇:#systemverilog# 关键字之 program


下一篇:Ubuntu20.04安装pip过程遇到依赖问题