fix video output callback

This commit is contained in:
程广 2023-04-07 19:30:08 +08:00
parent a042e23587
commit cbdd3b9e92
3 changed files with 46 additions and 22 deletions

5
build_test.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
./build.sh
export LD_LIBRARY_PATH=`pwd`/lib
cd build
./hkstreamer --cmd playback --device 192.168.12.100 --channel 3 -U admin -P Admin123 -S 2023-04-06T00:00:00Z -E 2023-04-06T00:10:00Z >t.ts

View File

@ -13,7 +13,7 @@ using namespace std;
long playHandle = -1;
bool is_playback = false;
long lUserID;
const int outcache_size=1024;
const int outcache_size=10240;
void signalexit(int signal){
if(playHandle!= -1){
@ -35,22 +35,12 @@ void exitHandler(){
template<typename T>
void CALLBACK fPlayDataCallBack(LONG lPlayHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, T dwUser){
DWORD remained = dwBufSize;
char cache[outcache_size]={0};
BYTE *cp; // cp head point
cp = pBuffer;
while(remained>0){
int cplen = outcache_size;
if(remained<cplen){
cplen=remained;
}
memcpy(cache, cp, cplen);
cout.write(cache, outcache_size);
if(cplen<remained){
cp+=cplen;
}
remained-=cplen;
if(dwDataType == NET_DVR_SYSHEAD){
return;
}
char* p= (char*)pBuffer;
cout.write(p, dwBufSize);
cerr<<"recv:"<<dwBufSize<<endl;
cout.flush();
}
@ -78,6 +68,7 @@ int login(LPLoginInfo loginInfo)
memcpy(struLoginInfo.sPassword, loginInfo->sPassword.c_str(), NAME_LEN);
std::cerr << struLoginInfo.sDeviceAddress << " " << struLoginInfo.sUserName << " " << struLoginInfo.sPassword << std::endl;
lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
cerr<<"UserID:"<<lUserID<<endl;
return lUserID;
}
@ -126,7 +117,8 @@ int getCfg(LPLoginInfo loginInfo)
int _playback(long lUserID, int timezone,LPStream stream) {
NET_DVR_VOD_PARA struVodPara = {0};
convert_isotimestr_time(stream->start,timezone, &(struVodPara.struBeginTime));
convert_isotimestr_time(stream->start,timezone, &(struVodPara.struEndTime));
convert_isotimestr_time(stream->end,timezone, &(struVodPara.struEndTime));
struVodPara.struIDInfo.dwChannel = stream->lChannel;
playHandle = NET_DVR_PlayBackByTime_V40(lUserID, &struVodPara);
if(checkResult(playHandle<0,"play back error")){
@ -186,7 +178,7 @@ void _installExitHandler(){
int playback(LPLoginInfo loginInfo, LPStream stream)
{
lUserID = login(loginInfo);
if(checkResult(lUserID<1, "device login error")){
if(checkResult(lUserID<0, "device login error")){
return HPR_ERROR;
}
// TODO: find timezone cfg
@ -207,7 +199,8 @@ int _getStream(long lUserID,LPStream stream){
NET_DVR_PREVIEWINFO struPlayInfo = {0};
struPlayInfo.hPlayWnd = 0;
struPlayInfo.lChannel = stream->lChannel; //channel NO
struPlayInfo.dwLinkMode = 1; // 采用子码流
struPlayInfo.dwStreamType = 1;// 采用子码流
struPlayInfo.dwLinkMode = 0;
struPlayInfo.bBlocked = 1;
struPlayInfo.dwDisplayBufNum = 1;
playHandle = NET_DVR_RealPlay_V40(lUserID, &struPlayInfo, NULL, NULL);
@ -215,7 +208,7 @@ int _getStream(long lUserID,LPStream stream){
return HPR_ERROR;
}
int scRet;
scRet = NET_DVR_SetStandardDataCallBack(playHandle,fPlayDataCallBack<DWORD>,0);
scRet = NET_DVR_SetRealDataCallBack(playHandle,fPlayDataCallBack<DWORD>,0);
if(checkResult(scRet<0,"set play callback error")){
return HPR_ERROR;
}
@ -226,7 +219,7 @@ int _getStream(long lUserID,LPStream stream){
int play(LPLoginInfo loginInfo, LPStream stream)
{
lUserID = login(loginInfo);
if(checkResult(lUserID<1, "device login error")){
if(checkResult(lUserID<0, "device login error")){
return HPR_ERROR;
}
int fChannelInfo = _readChannelConfig(lUserID, stream);
@ -234,5 +227,13 @@ int play(LPLoginInfo loginInfo, LPStream stream)
return fChannelInfo;
}
return _getStream(lUserID, stream);
int ret = _getStream(lUserID, stream);
if(ret != 0){
cerr<<"Get stream error"<<endl;
return HPR_ERROR;
}
while(true){
sleep(10);
}
return HPR_OK;
}

View File

@ -3,6 +3,7 @@
#include <cstring>
#include "../include/HCNetSDK.h"
#include "time.h"
#include <iostream>
using namespace std;
void convert_str_chararr(string src, char *dst, int dstlen)
@ -17,6 +18,17 @@ void convert_str_chararr(string src, char *dst, int dstlen)
strncpy(dst, src.c_str(), cplen);
}
void outtm(string msg, struct tm t){
cerr<<msg<<":";
cerr<<t.tm_year <<endl;
cerr<<t.tm_mon <<endl;
cerr<<t.tm_mday <<endl;
cerr<<t.tm_hour <<endl;
cerr<<t.tm_min <<endl;
cerr<<t.tm_sec <<endl;
cerr<<t.tm_gmtoff <<endl;
cerr<<t.tm_zone<<endl;
}
void convert_isotimestr_time(string timestr, int timezone, LPNET_DVR_TIME time)
{
@ -32,4 +44,10 @@ void convert_isotimestr_time(string timestr, int timezone, LPNET_DVR_TIME time)
time->dwHour = ltime.tm_hour;
time->dwMinute = ltime.tm_min;
time->dwSecond = ltime.tm_sec;
if(ts<1680768000){
outtm("iso", t);
cerr<<"Ts:"<<ts<<endl;
outtm("local", ltime);
}
}