#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "HCNetSDK.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
iUserID =-1;
iRealHandle = -1;
iUserID_2 =-1;
iRealHandle_2 = -1;
bool bInit = NET_DVR_Init();
if ( bInit == false )
{
qDebug("Init failed!");
}
else
{
qDebug("Init succeeded!");
}
NET_DVR_SetLogToFile(3, "./sdkLog", false);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btnPlay_clicked()
{
if(iRealHandle >= 0)
{
if(NET_DVR_StopRealPlay(iRealHandle))
{
qDebug("NET_DVR_RealPlay_V40 successfully!");
iRealHandle = -1;
}
else
{
qDebug("NET_DVR_RealPlay_V40 failed!");
}
}
// NET_DVR_CLIENTINFO tmpclientinfo = {0};
// tmpclientinfo.lChannel = 1;
// struPreview.dwStreamType = 0;
// tmpclientinfo.lLinkMode = 0x80000000;
// tmpclientinfo.hPlayWnd = (HWND)ui->frameWin1->winId();
// struPreview.bBlocked = 1;
NET_DVR_PREVIEWINFO struPreview = {0};
struPreview.lChannel = 33;
struPreview.dwStreamType = 0;
struPreview.dwLinkMode = 0;
struPreview.hPlayWnd = (HWND)ui->frameWin1->winId();
struPreview.bBlocked = 1;
iRealHandle = NET_DVR_RealPlay_V40(iUserID, &struPreview, NULL, NULL);
if (iRealHandle < 0)
{
//int iErr = NET_DVR_GetLastError();
qDebug("NET_DVR_RealPlay_V40 failed");
NET_DVR_Logout(iUserID);
NET_DVR_Cleanup();
return;
}
}
void MainWindow::on_btnStop_clicked()
{
if(iRealHandle >= 0)
{
if(NET_DVR_StopRealPlay(iRealHandle))
{
qDebug("NET_DVR_RealPlay_V40 successfully!");
iRealHandle = -1;
}
else
{
qDebug("NET_DVR_RealPlay_V40 failed!");
}
}
}
void MainWindow::on_btnLogin_clicked()
{
// 注册设备
NET_DVR_DEVICEINFO_V30 struDeviceInfo;
// QString ip = "192.168.0.221";
// QString UserName = "admin";
// QString passwd="cd123456";
// iUserID = NET_DVR_Login_V30(const_cast<char *>( qPrintable(ip) ), 8000,
// const_cast<char *>( qPrintable(UserName) ), const_cast<char *>( qPrintable(passwd) ) ,
// &struDeviceInfo);
iUserID = NET_DVR_Login_V30("192.168.0.221", 8000, "admin", "cd123456", &struDeviceInfo);
if (iUserID < 0)
{
qDebug("Login failed ");
NET_DVR_Cleanup();
return;
}
else
{
qDebug("Login succeeded, iUserID=%d ", iUserID);
}
}
void MainWindow::on_btnLogout_clicked()
{
if(iRealHandle >= 0)
{
if(NET_DVR_StopRealPlay(iRealHandle))
{
qDebug("NET_DVR_RealPlay_V40 successfully!");
iRealHandle = -1;
}
else
{
qDebug("NET_DVR_RealPlay_V40 failed!");
}
}
if(iUserID >= 0)
{
if(NET_DVR_Logout(iUserID))
{
qDebug("NET_DVR_Logout successfully!");
iUserID = -1;
}
else
{
qDebug("NET_DVR_Logout failed!");
}
}
}
void MainWindow::on_btnPlay_2_clicked()
{
if(iRealHandle_2 >= 0)
{
if(NET_DVR_StopRealPlay(iRealHandle_2))
{
qDebug("NET_DVR_RealPlay_V40 successfully!");
iRealHandle_2 = -1;
}
else
{
qDebug("NET_DVR_RealPlay_V40 failed!");
}
}
// NET_DVR_CLIENTINFO tmpclientinfo = {0};
// tmpclientinfo.lChannel = 1;
// struPreview.dwStreamType = 0;
// tmpclientinfo.lLinkMode = 0x80000000;
// tmpclientinfo.hPlayWnd = (HWND)ui->frameWin1->winId();
// struPreview.bBlocked = 1;
NET_DVR_PREVIEWINFO struPreview = {1};
struPreview.lChannel = 1;
struPreview.dwStreamType = 0;
struPreview.dwLinkMode = 0;
struPreview.hPlayWnd = (HWND)ui->frameWin2->winId();
struPreview.bBlocked = 1;
iRealHandle_2 = NET_DVR_RealPlay_V40(iUserID_2, &struPreview, NULL, NULL);
if (iRealHandle_2 < 0)
{
//int iErr = NET_DVR_GetLastError();
qDebug("NET_DVR_RealPlay_V40 failed");
NET_DVR_Logout(iUserID_2);
NET_DVR_Cleanup();
return;
}
}
void MainWindow::on_btnLogin_2_clicked()
{
// 注册设备
NET_DVR_DEVICEINFO_V30 struDeviceInfo;
QString ip = "192.168.1.222";
QString UserName = "admin";
QString passwd="cd123456";
iUserID_2 = NET_DVR_Login_V30(const_cast<char *>( qPrintable(ip) ), 8000,
const_cast<char *>( qPrintable(UserName) ), const_cast<char *>( qPrintable(passwd) ) ,
&struDeviceInfo);
if (iUserID_2 < 0)
{
qDebug("Login failed ");
NET_DVR_Cleanup();
return;
}
else
{
qDebug("Login succeeded, iUserID=%d ", iUserID_2);
}
}
void MainWindow::on_btnLogout_2_clicked()
{
if(iRealHandle_2 >= 0)
{
if(NET_DVR_StopRealPlay(iRealHandle_2))
{
qDebug("NET_DVR_RealPlay_V40 successfully!");
iRealHandle_2 = -1;
}
else
{
qDebug("NET_DVR_RealPlay_V40 failed!");
}
}
if(iUserID_2 >= 0)
{
if(NET_DVR_Logout(iUserID_2))
{
qDebug("NET_DVR_Logout successfully!");
iUserID_2 = -1;
}
else
{
qDebug("NET_DVR_Logout failed!");
}
}
}
评论0