2023-03-24 19:34:36 +08:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <bitset>
|
|
|
|
|
#include <unistd.h>
|
2023-03-29 19:03:49 +08:00
|
|
|
|
#include <time.h>
|
2023-03-24 19:34:36 +08:00
|
|
|
|
#include "HCNetSDK.h"
|
|
|
|
|
#include "HkStreamer.h"
|
|
|
|
|
|
2023-03-29 19:03:49 +08:00
|
|
|
|
void CALLBACK fPlayDataCallBack(LONG lPlayHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, void* dwUser)
|
2023-03-24 19:34:36 +08:00
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
if (dwBufSize > 0)
|
|
|
|
|
{
|
|
|
|
|
char pb[dwBufSize] = {0};
|
|
|
|
|
memcpy(pb, pBuffer, dwBufSize);
|
|
|
|
|
|
|
|
|
|
std::cout.write(pb, dwBufSize);
|
|
|
|
|
std::cout.flush();
|
|
|
|
|
}
|
|
|
|
|
int pos = NET_DVR_GetDownloadPos(lPlayHandle);
|
|
|
|
|
if (pos > 98)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "pyd---Current Time:%d, data size:%d\n", time(NULL), dwBufSize);
|
|
|
|
|
}
|
2023-03-24 19:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int login(LPLoginInfo loginInfo)
|
|
|
|
|
{
|
|
|
|
|
NET_DVR_Init();
|
|
|
|
|
long lUserID;
|
|
|
|
|
// login
|
|
|
|
|
NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
|
2023-03-29 19:03:49 +08:00
|
|
|
|
NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
|
2023-03-24 19:34:36 +08:00
|
|
|
|
struLoginInfo.bUseAsynLogin = false;
|
|
|
|
|
|
|
|
|
|
struLoginInfo.wPort = 8000;
|
|
|
|
|
memcpy(struLoginInfo.sDeviceAddress, loginInfo->sDeviceAddress, NET_DVR_DEV_ADDRESS_MAX_LEN);
|
|
|
|
|
memcpy(struLoginInfo.sUserName, loginInfo->sUserName, NAME_LEN);
|
|
|
|
|
memcpy(struLoginInfo.sPassword, loginInfo->sPassword, NAME_LEN);
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << struLoginInfo.sDeviceAddress << " " << struLoginInfo.sUserName << " " << struLoginInfo.sPassword << std::endl;
|
|
|
|
|
lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
|
2023-03-24 19:34:36 +08:00
|
|
|
|
return lUserID;
|
|
|
|
|
}
|
2023-03-29 19:03:49 +08:00
|
|
|
|
void cpTime(NET_DVR_TIME *nvrTime, StreamDate date)
|
|
|
|
|
{
|
2023-03-24 19:34:36 +08:00
|
|
|
|
nvrTime->dwYear = date.dwYear;
|
|
|
|
|
nvrTime->dwMonth = date.dwMonth;
|
|
|
|
|
nvrTime->dwDay = date.dwDay;
|
|
|
|
|
nvrTime->dwHour = date.dwHour;
|
|
|
|
|
nvrTime->dwMinute = date.dwMinute;
|
|
|
|
|
nvrTime->dwSecond = date.dwSecond;
|
|
|
|
|
}
|
|
|
|
|
int playback(LPLoginInfo loginInfo, LPStream stream)
|
|
|
|
|
{
|
|
|
|
|
long lUserID = login(loginInfo);
|
|
|
|
|
if (lUserID < 0)
|
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << "pyd1---Login error" << NET_DVR_GetLastError() << std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
return HPR_ERROR;
|
|
|
|
|
}
|
|
|
|
|
NET_DVR_VOD_PARA struVodPara = {0};
|
|
|
|
|
StreamDate start = stream->start;
|
2023-03-29 19:03:49 +08:00
|
|
|
|
struVodPara.struIDInfo.dwChannel = stream->lChannel;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
cpTime(&struVodPara.struBeginTime, start);
|
|
|
|
|
cpTime(&struVodPara.struEndTime, stream->end);
|
|
|
|
|
int hPlayback = NET_DVR_PlayBackByTime_V40(lUserID, &struVodPara);
|
|
|
|
|
if (hPlayback < 0)
|
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << "pyd1---PlayBack error: " << NET_DVR_GetLastError() << std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
return HPR_ERROR;
|
|
|
|
|
}
|
2023-03-29 19:03:49 +08:00
|
|
|
|
char usrInfo[200];
|
|
|
|
|
if (!NET_DVR_SetPlayDataCallBack_V40(hPlayback, fPlayDataCallBack, usrInfo))
|
2023-03-24 19:34:36 +08:00
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << "NET_DVR_SetPlayDataCallBack fail!\n"
|
|
|
|
|
<< std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 19:03:49 +08:00
|
|
|
|
time_t lstart = time(NULL);
|
|
|
|
|
if (!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART,NULL, 0, NULL, NULL))
|
2023-03-24 19:34:36 +08:00
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << "play back control failed : " << NET_DVR_GetLastError() << std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
return HPR_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
|
for (pos = 0; pos < 100 && pos >= 0; pos = NET_DVR_GetDownloadPos(hPlayback))
|
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr<<"Pos:"<<pos<<std::endl;
|
|
|
|
|
sleep(1);
|
2023-03-24 19:34:36 +08:00
|
|
|
|
}
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << "have got: " << pos << std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
if (!NET_DVR_StopGetFile(hPlayback))
|
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << "failed to stop get file: " << NET_DVR_GetLastError() << std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
return HPR_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 19:03:49 +08:00
|
|
|
|
time_t lend = time(NULL);
|
|
|
|
|
std::cerr << "StopGetFile\n"
|
|
|
|
|
<< "Use:"
|
|
|
|
|
<< lend - lstart
|
|
|
|
|
<< std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
if (pos < 0 || pos > 100)
|
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
std::cerr << "download err:" << NET_DVR_GetLastError() << std::endl;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
return HPR_ERROR;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sleep(180); //˯3<CBAF><33><EFBFBD><EFBFBD>
|
|
|
|
|
NET_DVR_Logout_V30(lUserID);
|
|
|
|
|
// cleanup
|
|
|
|
|
NET_DVR_Cleanup();
|
|
|
|
|
|
|
|
|
|
return HPR_OK;
|
|
|
|
|
}
|
2023-03-29 19:03:49 +08:00
|
|
|
|
int getCfg(LPLoginInfo loginInfo)
|
2023-03-24 19:34:36 +08:00
|
|
|
|
{
|
2023-03-29 19:03:49 +08:00
|
|
|
|
long lUserID = login(loginInfo);
|
|
|
|
|
if (lUserID < 0)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "pyd1---Login error" << NET_DVR_GetLastError() << std::endl;
|
|
|
|
|
return HPR_ERROR;
|
|
|
|
|
}
|
|
|
|
|
NET_DVR_IPPARACFG_V40 ipcfg;
|
|
|
|
|
DWORD bytesReturned = 0;
|
|
|
|
|
ipcfg.dwSize = sizeof(NET_DVR_IPPARACFG_V40);
|
|
|
|
|
int iGroupNO = 0;
|
|
|
|
|
bool resCode = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_IPPARACFG_V40, iGroupNO, &ipcfg, sizeof(NET_DVR_IPPARACFG_V40), &bytesReturned);
|
|
|
|
|
if (!resCode)
|
|
|
|
|
{
|
|
|
|
|
DWORD code = NET_DVR_GetLastError();
|
|
|
|
|
std::cout << "NET_DVR_GetDVRConfig failed " << NET_DVR_GetErrorMsg((LONG *)(&code)) << std::endl;
|
|
|
|
|
NET_DVR_Logout(lUserID);
|
|
|
|
|
NET_DVR_Cleanup();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
std::cout << "设备组 " << ipcfg.dwGroupNum << " 数字通道个数 " << ipcfg.dwDChanNum << " 起始通道 " << ipcfg.dwStartDChan << std::endl
|
|
|
|
|
<< std::endl;
|
|
|
|
|
for (int i = 0; i < ipcfg.dwDChanNum; i++)
|
|
|
|
|
{
|
|
|
|
|
NET_DVR_PICCFG_V30 channelInfo;
|
|
|
|
|
bytesReturned = 0;
|
|
|
|
|
channelInfo.dwSize = sizeof(NET_DVR_PICCFG_V30);
|
|
|
|
|
int channelNum = i + ipcfg.dwStartDChan;
|
|
|
|
|
NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_PICCFG_V30, channelNum, &channelInfo, sizeof(NET_DVR_PICCFG_V30), &bytesReturned);
|
|
|
|
|
std::cout << "通道号 " << channelNum << "\t通道名称 " << channelInfo.sChanName;
|
|
|
|
|
std::cout << "\t用户名 " << ipcfg.struIPDevInfo[i].sUserName << "\t密码 " << ipcfg.struIPDevInfo[i].sPassword;
|
|
|
|
|
std::cout << "\t设备ID " << (long)ipcfg.struIPDevInfo[i].szDeviceID;
|
|
|
|
|
std::cout << "\tip地址 " << ipcfg.struIPDevInfo[i].struIP.sIpV4 << "\t端口 " << ipcfg.struIPDevInfo[i].wDVRPort << std::endl;
|
|
|
|
|
}
|
|
|
|
|
NET_DVR_Logout(lUserID);
|
|
|
|
|
NET_DVR_Cleanup();
|
|
|
|
|
return 0;
|
2023-03-24 19:34:36 +08:00
|
|
|
|
}
|