refactor
This commit is contained in:
parent
1c8bc7efea
commit
87e1c6f69c
|
@ -26,8 +26,10 @@ set (SRCS
|
|||
include/HCNetSDK.h
|
||||
include/HkStreamer.h
|
||||
include/plaympeg4.h
|
||||
HkStreamer.cpp
|
||||
main.cpp
|
||||
include/cmdlineparser.h
|
||||
src/HkStreamer.cpp
|
||||
src/main.cpp
|
||||
src/cmdlineparser.cpp
|
||||
)
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME} ${SRCS})
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 10.0.0, 2023-03-30T22:49:16. -->
|
||||
<!-- Written by QtCreator 10.0.0, 2023-03-31T18:22:20. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">{e8c938e2-c8fa-4354-a6d6-5cb042d4a566}</value>
|
||||
<value type="QByteArray">{b1d6c31c-e354-4f9b-a89f-0f02a67ed6d1}</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
|
@ -87,14 +87,14 @@
|
|||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">桌面</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">桌面</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{976a26f7-9753-41c3-a002-83e83b921ad8}</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop (x86-darwin-generic-mach_o-32bit)</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop (x86-darwin-generic-mach_o-32bit)</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{ea69aa4c-9f65-4091-af6f-c8dca7313cfe}</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kingecg/code/hkstreamer</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/chengguang/code/hkstreamer</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 10.0.0, 2023-03-30T22:49:16. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">{e8c938e2-c8fa-4354-a6d6-5cb042d4a566}</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
<value type="qlonglong">0</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
|
||||
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||
<value type="QString" key="language">Cpp</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||
<value type="QString" key="language">QmlJS</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
|
||||
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||
<valuemap type="QVariantMap" key="ClangTools">
|
||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">桌面</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">桌面</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{976a26f7-9753-41c3-a002-83e83b921ad8}</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kingecg/code/hkstreamer</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||
<value type="QString">all</value>
|
||||
</valuelist>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||
<value type="QString">clean</value>
|
||||
</valuelist>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">默认</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">部署</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">部署</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||
<value type="qlonglong">1</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>Version</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
</qtcreator>
|
|
@ -4,6 +4,8 @@ include/DataType.h
|
|||
include/DecodeCardSdk.h
|
||||
include/HCNetSDK.h
|
||||
include/HkStreamer.h
|
||||
include/cmdlineparser.h
|
||||
include/convert.h
|
||||
include/plaympeg4.h
|
||||
lib/HCNetSDKCom/libAudioIntercom.so
|
||||
lib/HCNetSDKCom/libHCAlarm.so
|
||||
|
@ -30,4 +32,7 @@ lib/libhpr.so
|
|||
lib/libopenal.so.1
|
||||
lib/libssl.so.1.1
|
||||
lib/libz.so
|
||||
main.cpp
|
||||
src/HkStreamer.cpp
|
||||
src/cmdlineparser.cpp
|
||||
src/convert.cpp
|
||||
src/main.cpp
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
include
|
||||
src
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _HK_STREAMER_
|
||||
#define _HK_STREAMER_
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
// // #ifdef __LINUX__
|
||||
// typedef unsigned char UCHAR;
|
||||
// typedef unsigned char* PBYTE;
|
||||
|
@ -16,25 +17,18 @@ extern "C"
|
|||
#endif
|
||||
typedef struct
|
||||
{
|
||||
char sDeviceAddress[129];
|
||||
char sUserName[64];
|
||||
char sPassword[64];
|
||||
string sDeviceAddress;
|
||||
string sUserName;
|
||||
string sPassword;
|
||||
} LoginInfo, *LPLoginInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long dwYear; // 年
|
||||
unsigned long dwMonth; // 月
|
||||
unsigned long dwDay; // 日
|
||||
unsigned long dwHour; // 时
|
||||
unsigned long dwMinute; // 分
|
||||
unsigned long dwSecond; // 秒
|
||||
} StreamDate, *LStreamDate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long lChannel;
|
||||
StreamDate start;
|
||||
StreamDate end;
|
||||
unsigned long bitrate;
|
||||
string start;
|
||||
string end;
|
||||
} StreamCon, *LPStream;
|
||||
|
||||
#define HPR_OK 0
|
||||
|
|
|
@ -15,14 +15,18 @@ typedef struct {
|
|||
class CmdLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser();
|
||||
CmdLineParser(string name,string desc);
|
||||
void regOpt(OptDefine optdef);
|
||||
void regOpt(string name,int shorName, int needParam, string desc);
|
||||
string getOpt(string key);
|
||||
void parseArgs(int argc, char *argv[]);
|
||||
private:
|
||||
string appName;
|
||||
string appDesc;
|
||||
map<int, OptDefine> optMap;
|
||||
map<string, string> paraMap;
|
||||
bool hasOptSet(string key);
|
||||
void help();
|
||||
};
|
||||
|
||||
#endif // CMDLINEPARSER_H
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef CONVERT_H
|
||||
#define CONVERT_H
|
||||
#include <string>
|
||||
#include <HCNetSDK.h>
|
||||
using namespace std;
|
||||
void convert_str_chararr(string src, char *dst, int dstlen);
|
||||
void convert_isotimestr_time(string timestr, int timezone, LPNET_DVR_TIME time);
|
||||
|
||||
#endif // CONVERT_H
|
|
@ -5,22 +5,37 @@
|
|||
#include <time.h>
|
||||
#include "HCNetSDK.h"
|
||||
#include "HkStreamer.h"
|
||||
|
||||
#include "convert.h"
|
||||
using namespace std;
|
||||
const int outcache_size=1024;
|
||||
void CALLBACK fPlayDataCallBack(LONG lPlayHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, void* dwUser)
|
||||
{
|
||||
if (dwBufSize > 0)
|
||||
{
|
||||
char pb[dwBufSize] = {0};
|
||||
memcpy(pb, pBuffer, dwBufSize);
|
||||
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;
|
||||
}
|
||||
cout.flush();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool checkResult(bool result, string msg){
|
||||
if(result){
|
||||
cerr<<msg<<":"<<NET_DVR_GetLastError()<<endl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int login(LPLoginInfo loginInfo)
|
||||
|
@ -40,7 +55,7 @@ int login(LPLoginInfo loginInfo)
|
|||
lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
|
||||
return lUserID;
|
||||
}
|
||||
void cpTime(NET_DVR_TIME *nvrTime, StreamDate date)
|
||||
|
||||
{
|
||||
nvrTime->dwYear = date.dwYear;
|
||||
nvrTime->dwMonth = date.dwMonth;
|
||||
|
@ -49,74 +64,7 @@ void cpTime(NET_DVR_TIME *nvrTime, StreamDate date)
|
|||
nvrTime->dwMinute = date.dwMinute;
|
||||
nvrTime->dwSecond = date.dwSecond;
|
||||
}
|
||||
int playback(LPLoginInfo loginInfo, LPStream stream)
|
||||
{
|
||||
long lUserID = login(loginInfo);
|
||||
if (lUserID < 0)
|
||||
{
|
||||
std::cerr << "pyd1---Login error" << NET_DVR_GetLastError() << std::endl;
|
||||
return HPR_ERROR;
|
||||
}
|
||||
NET_DVR_VOD_PARA struVodPara = {0};
|
||||
StreamDate start = stream->start;
|
||||
struVodPara.struIDInfo.dwChannel = stream->lChannel;
|
||||
cpTime(&struVodPara.struBeginTime, start);
|
||||
cpTime(&struVodPara.struEndTime, stream->end);
|
||||
int hPlayback = NET_DVR_PlayBackByTime_V40(lUserID, &struVodPara);
|
||||
if (hPlayback < 0)
|
||||
{
|
||||
std::cerr << "pyd1---PlayBack error: " << NET_DVR_GetLastError() << std::endl;
|
||||
return HPR_ERROR;
|
||||
}
|
||||
char usrInfo[200];
|
||||
if (!NET_DVR_SetPlayDataCallBack_V40(hPlayback, fPlayDataCallBack, usrInfo))
|
||||
{
|
||||
std::cerr << "NET_DVR_SetPlayDataCallBack fail!\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
time_t lstart = time(NULL);
|
||||
if (!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART,NULL, 0, NULL, NULL))
|
||||
{
|
||||
std::cerr << "play back control failed : " << NET_DVR_GetLastError() << std::endl;
|
||||
return HPR_ERROR;
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
for (pos = 0; pos < 100 && pos >= 0; pos = NET_DVR_GetDownloadPos(hPlayback))
|
||||
{
|
||||
std::cerr<<"Pos:"<<pos<<std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
std::cerr << "have got: " << pos << std::endl;
|
||||
if (!NET_DVR_StopGetFile(hPlayback))
|
||||
{
|
||||
std::cerr << "failed to stop get file: " << NET_DVR_GetLastError() << std::endl;
|
||||
return HPR_ERROR;
|
||||
}
|
||||
|
||||
time_t lend = time(NULL);
|
||||
std::cerr << "StopGetFile\n"
|
||||
<< "Use:"
|
||||
<< lend - lstart
|
||||
<< std::endl;
|
||||
if (pos < 0 || pos > 100)
|
||||
{
|
||||
std::cerr << "download err:" << NET_DVR_GetLastError() << std::endl;
|
||||
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;
|
||||
}
|
||||
int getCfg(LPLoginInfo loginInfo)
|
||||
{
|
||||
long lUserID = login(loginInfo);
|
||||
|
@ -156,3 +104,70 @@ int getCfg(LPLoginInfo loginInfo)
|
|||
NET_DVR_Cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
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));
|
||||
struVodPara.struIDInfo.dwChannel = stream->lChannel;
|
||||
int hPlayback = NET_DVR_PlayBackByTime_V40(lUserID, &struVodPara);
|
||||
if(checkResult(hPlayback<0,"play back error")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
char usrInfo[200];
|
||||
if(checkResult(!NET_DVR_SetPlayDataCallBack_V40(hPlayback, fPlayDataCallBack, usrInfo), "setup callback error")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
|
||||
if(checkResult(!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART,NULL, 0, NULL, NULL),"start playback error")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
if(checkResult(!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_SETSPEED,&(stream->bitrate), 0, NULL, NULL),"set plackback speed error")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
int pos = 0;
|
||||
for (pos = 0; pos < 100 && pos >= 0; pos = NET_DVR_GetDownloadPos(hPlayback))
|
||||
{
|
||||
// output progress in cerr
|
||||
std::cerr<<"Pos:"<<pos<<std::endl;
|
||||
sleep(10);
|
||||
}
|
||||
if(checkResult(!NET_DVR_StopGetFile(hPlayback),"failed to stop playback")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
return HPR_OK;
|
||||
}
|
||||
|
||||
int _readChannelConfig(long lUserID,LPStream stream){
|
||||
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(checkResult(!resCode, "read channel config fail")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
int startNum = ipcfg.dwStartDChan;
|
||||
if(checkResult(stream->lChannel > ipcfg.dwDChanNum, "channel not correct")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
|
||||
stream->lChannel = ipcfg.dwStartDChan + stream->lChannel -1;
|
||||
stream->bitrate = 2048; // controll speed for download, TODO: get bitrate from device;
|
||||
}
|
||||
|
||||
int playback(LPLoginInfo loginInfo, LPStream stream)
|
||||
{
|
||||
long lUserID = login(loginInfo);
|
||||
if(checkResult(lUserID<1, "device login error")){
|
||||
return HPR_ERROR;
|
||||
}
|
||||
// TODO: find timezone cfg
|
||||
int timezone = 8;
|
||||
// TODO: find actually channel
|
||||
stream->lChannel = stream->lChannel + 33/*channel start*/ - 1;
|
||||
int playbackResult = _playback(lUserID, timezone, stream);
|
||||
NET_DVR_Logout(lUserID);
|
||||
NET_DVR_Cleanup();
|
||||
return playbackResult;
|
||||
}
|
|
@ -1,8 +1,19 @@
|
|||
#include "cmdlineparser.h"
|
||||
|
||||
CmdLineParser::CmdLineParser()
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
template<typename T>
|
||||
bool mapHasKey(map<int, T> *pMap, int key){
|
||||
try {
|
||||
pMap->at(key);
|
||||
return true;
|
||||
}catch(exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
CmdLineParser::CmdLineParser(string name,string desc)
|
||||
{
|
||||
|
||||
appDesc = desc;
|
||||
appName = name;
|
||||
}
|
||||
|
||||
void CmdLineParser::regOpt(OptDefine optdef)
|
||||
|
@ -10,6 +21,12 @@ void CmdLineParser::regOpt(OptDefine optdef)
|
|||
optMap[optdef.shortName] = optdef;
|
||||
}
|
||||
|
||||
void CmdLineParser::regOpt(string name, int shorName, int needParam, string desc)
|
||||
{
|
||||
OptDefine opt = {name,shorName, needParam, desc};
|
||||
regOpt(opt);
|
||||
}
|
||||
|
||||
string CmdLineParser::getOpt(string key)
|
||||
{
|
||||
if(!hasOptSet(key)){
|
||||
|
@ -43,13 +60,21 @@ void CmdLineParser::parseArgs(int argc, char *argv[])
|
|||
int optIndex=0;
|
||||
int opt;
|
||||
while ((opt=getopt_long(argc, argv, shortArgs.c_str(), longOption, &optIndex))!=-1) {
|
||||
if(!mapHasKey(&optMap, opt)){
|
||||
help();
|
||||
exit(0);
|
||||
}
|
||||
OptDefine d = optMap.at(opt);
|
||||
|
||||
if(d.needParam == no_argument){
|
||||
paraMap[d.name] = "true";
|
||||
} else {
|
||||
paraMap[d.name] = optarg;
|
||||
}
|
||||
}
|
||||
//释放动态构造的option数组
|
||||
|
||||
delete[] longOption;
|
||||
}
|
||||
|
||||
bool CmdLineParser::hasOptSet(string key)
|
||||
|
@ -60,3 +85,19 @@ bool CmdLineParser::hasOptSet(string key)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CmdLineParser::help()
|
||||
{
|
||||
cout<< appName <<":" << appDesc << endl;
|
||||
cout<< "Usage:" << appName << "[opt] optvalue" << endl;
|
||||
for(auto i = optMap.begin();i!=optMap.end(); ++i) {
|
||||
OptDefine od = i->second;
|
||||
cout<<"--"<<od.name;
|
||||
if(od.shortName>=65&&od.shortName<=90){
|
||||
cout<<",-"<<char(od.shortName);
|
||||
} else {
|
||||
cout<<" ";
|
||||
}
|
||||
cout<<" "<<od.desc<<endl;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#include "convert.h"
|
||||
#include <string>
|
||||
#include <HCNetSDK.h>
|
||||
#include "time.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void convert_str_chararr(string src, char *dst, int dstlen)
|
||||
{
|
||||
int srcSize = src.size();
|
||||
int cplen = 0;
|
||||
if(dstlen>=srcSize){
|
||||
cplen = srcSize;
|
||||
} else {
|
||||
cplen = dstlen;
|
||||
}
|
||||
strlcpy(dst, src.c_str(), cplen);
|
||||
}
|
||||
|
||||
|
||||
void convert_isotimestr_time(string timestr, int timezone, LPNET_DVR_TIME time)
|
||||
{
|
||||
struct tm t;
|
||||
strptime(timestr.c_str(), "%Y-%m-%dT%H:%M:%SZ", &t);
|
||||
time_t ts = mktime(&t);
|
||||
ts+=timezone*3600;
|
||||
struct tm ltime;
|
||||
localtime_r(&ts, <ime);
|
||||
time->dwYear = ltime.tm_year + 1900;
|
||||
time->dwMonth = ltime.tm_mon + 1;
|
||||
time->dwDay = ltime.tm_mday;
|
||||
time->dwHour = ltime.tm_hour;
|
||||
time->dwMinute = ltime.tm_min;
|
||||
time->dwSecond = ltime.tm_sec;
|
||||
}
|
Loading…
Reference in New Issue