|
|
@ -5,8 +5,12 @@
|
|
|
|
#include "HangYuCtrl.h"
|
|
|
|
#include "HangYuCtrl.h"
|
|
|
|
#include "netcamera.h"
|
|
|
|
#include "netcamera.h"
|
|
|
|
#include "httpclient.h"
|
|
|
|
#include "httpclient.h"
|
|
|
|
|
|
|
|
#include <LogThread.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <SpecData_JSON.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
|
HangYuCtrl::~HangYuCtrl()
|
|
|
|
HangYuCtrl::~HangYuCtrl()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -186,12 +190,143 @@ bool HangYuCtrl::UpdateTime(time_t ts)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HangYuCtrl::TakePhoto(std::vector<uint8_t>& img)
|
|
|
|
bool HangYuCtrl::TakePhoto(uint8_t streamID, std::vector<uint8_t>& img)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg
|
|
|
|
|
|
|
|
char url[128] = { 0 };
|
|
|
|
|
|
|
|
snprintf(url, sizeof(url), "http://%s/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", m_ip.c_str(), (uint32_t)streamID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, img);
|
|
|
|
|
|
|
|
if (0 == nRet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool qualityDowngraded = false;
|
|
|
|
|
|
|
|
std::string originalConfig;
|
|
|
|
|
|
|
|
if (img.size() < 1000)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
qualityDowngraded = DowngradeQuality(originalConfig);
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO,"Reduce Img Quality");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nRet = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, img);
|
|
|
|
|
|
|
|
if (!originalConfig.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UpdateQuality(originalConfig);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> header = {0xFF, 0xD8, 0xFF, 0xE0}; // JPEG
|
|
|
|
|
|
|
|
std::vector<uint8_t>::iterator it = std::search(img.begin(), img.end(), header.begin(), header.end());
|
|
|
|
|
|
|
|
if (it != img.end() && it != img.begin())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
img.erase(img.begin(), it);
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
|
|
|
int aa = 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nRet == 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool HangYuCtrl::DowngradeQuality(std::string& originalConfig)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
char url[64] = { 0 };
|
|
|
|
|
|
|
|
snprintf(url, sizeof(url), "http://%s/Snapshot/Config", m_ip.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, data);
|
|
|
|
|
|
|
|
if (0 == nRet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string str = ByteArrayToString(&data[0], data.size());
|
|
|
|
|
|
|
|
originalConfig = str;
|
|
|
|
|
|
|
|
if (replaceAll(str, "<Quality>middle</Quality>", "<Quality>low</Quality>") == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = (replaceAll(str, "<Quality>high</Quality>", "<Quality>middle</Quality>") != 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.clear();
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nRet = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, str.c_str(), data);
|
|
|
|
|
|
|
|
return 0 == nRet;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HangYuCtrl::TakeVideo(uint32_t duration, std::string path)
|
|
|
|
bool HangYuCtrl::UpdateQuality(const std::string& originalConfig)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
|
|
|
|
char url[64] = { 0 };
|
|
|
|
|
|
|
|
snprintf(url, sizeof(url), "http://%s/Snapshot/Config", m_ip.c_str());
|
|
|
|
|
|
|
|
int nRet = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, originalConfig.c_str(), data);
|
|
|
|
|
|
|
|
return 0 == nRet;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool HangYuCtrl::UpgradeQuality()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
char url[64] = { 0 };
|
|
|
|
|
|
|
|
snprintf(url, sizeof(url), "http://%s/Snapshot/Config", m_ip.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, data);
|
|
|
|
|
|
|
|
if (0 == nRet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string str = ByteArrayToString(&data[0], data.size());
|
|
|
|
|
|
|
|
if (replaceAll(str, "<Quality>low</Quality>", "<Quality>middle</Quality>") == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = (replaceAll(str, "<Quality>middle</Quality>", "<Quality>high</Quality>") != 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.clear();
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nRet = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, str.c_str(), data);
|
|
|
|
|
|
|
|
return 0 == nRet;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool HangYuCtrl::QueryQuality(std::string& qualityContents)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char url[64] = { 0 };
|
|
|
|
|
|
|
|
snprintf(url, sizeof(url), "http://%s/Snapshot/Config", m_ip.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
|
|
|
|
int nRet = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, data);
|
|
|
|
|
|
|
|
if (0 == nRet && !data.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
qualityContents = ByteArrayToString(&data[0], data.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0 == nRet);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool HangYuCtrl::TakeVideo(uint8_t streamID, uint32_t duration, std::string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|