diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.cpp b/app/src/main/cpp/netcamera/HangYuCtrl.cpp index 44effbc2..d8c29226 100644 --- a/app/src/main/cpp/netcamera/HangYuCtrl.cpp +++ b/app/src/main/cpp/netcamera/HangYuCtrl.cpp @@ -5,8 +5,12 @@ #include "HangYuCtrl.h" #include "netcamera.h" #include "httpclient.h" +#include + +#include #include +#include HangYuCtrl::~HangYuCtrl() { @@ -186,12 +190,143 @@ bool HangYuCtrl::UpdateTime(time_t ts) return true; } -bool HangYuCtrl::TakePhoto(std::vector& img) +bool HangYuCtrl::TakePhoto(uint8_t streamID, std::vector& img) +{ + bool res = false; + + std::vector 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 header = {0xFF, 0xD8, 0xFF, 0xE0}; // JPEG + std::vector::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 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, "middle", "low") == 0) + { + res = (replaceAll(str, "high", "middle") != 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::TakeVideo(uint32_t duration, std::string path) +bool HangYuCtrl::UpdateQuality(const std::string& originalConfig) +{ + std::vector 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 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, "low", "middle") == 0) + { + res = (replaceAll(str, "middle", "high") != 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 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; } \ No newline at end of file diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.h b/app/src/main/cpp/netcamera/HangYuCtrl.h index 1188400c..be5b2a84 100644 --- a/app/src/main/cpp/netcamera/HangYuCtrl.h +++ b/app/src/main/cpp/netcamera/HangYuCtrl.h @@ -17,11 +17,16 @@ public: virtual void EnableOsd(bool enable, uint8_t channel); virtual std::string GetStreamingUrl(uint8_t channel); virtual bool UpdateTime(time_t ts); - virtual bool TakePhoto(std::vector& img); - virtual bool TakeVideo(uint32_t duration, std::string path); + virtual bool TakePhoto(uint8_t streamID, std::vector& img); + virtual bool TakeVideo(uint8_t streamID, uint32_t duration, std::string path); virtual bool HasAuthOnStreaming() const { return true; } virtual bool SetResolution(uint8_t channel, uint8_t streamID, uint32_t resX, uint32_t resY); +private: + bool QueryQuality(std::string& qualityContents); + bool DowngradeQuality(std::string& originalConfig); + bool UpdateQuality(const std::string& originalConfig); + bool UpgradeQuality(); }; diff --git a/app/src/main/cpp/netcamera/VendorCtrl.h b/app/src/main/cpp/netcamera/VendorCtrl.h index bb9b28f9..29056e6b 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.h +++ b/app/src/main/cpp/netcamera/VendorCtrl.h @@ -23,8 +23,8 @@ public: virtual void EnableOsd(bool enable, uint8_t channel) = 0; virtual std::string GetStreamingUrl(uint8_t channel) = 0; virtual bool UpdateTime(time_t ts) = 0; - virtual bool TakePhoto(std::vector& img) = 0; - virtual bool TakeVideo(uint32_t duration, std::string path) = 0; + virtual bool TakePhoto(uint8_t streamID, std::vector& img) = 0; + virtual bool TakeVideo(uint8_t streamID, uint32_t duration, std::string path) = 0; virtual bool HasAuthOnStreaming() const { return false; } virtual bool SetResolution(uint8_t channel, uint8_t streamID, uint32_t resX, uint32_t resY) = 0; diff --git a/app/src/main/cpp/netcamera/YuShiCtrl.cpp b/app/src/main/cpp/netcamera/YuShiCtrl.cpp index 1599ee04..3e336e2a 100644 --- a/app/src/main/cpp/netcamera/YuShiCtrl.cpp +++ b/app/src/main/cpp/netcamera/YuShiCtrl.cpp @@ -155,13 +155,13 @@ bool YuShiCtrl::UpdateTime(time_t ts) return true; } -bool YuShiCtrl::TakePhoto(std::vector& img) +bool YuShiCtrl::TakePhoto(uint8_t streamID, std::vector& img) { return false; } -bool YuShiCtrl::TakeVideo(uint32_t duration, std::string path) { +bool YuShiCtrl::TakeVideo(uint8_t streamID, uint32_t duration, std::string path) { return false; } diff --git a/app/src/main/cpp/netcamera/YuShiCtrl.h b/app/src/main/cpp/netcamera/YuShiCtrl.h index d8d17bdf..dbc4c07a 100644 --- a/app/src/main/cpp/netcamera/YuShiCtrl.h +++ b/app/src/main/cpp/netcamera/YuShiCtrl.h @@ -15,10 +15,10 @@ public: virtual bool SetOsd(uint8_t channel, std::string osd, uint8_t pos); virtual void EnableOsd(bool enable, uint8_t channel); - virtual std::string GetStreamingUrl(uint8_t channel); + virtual std::string GetStreamingUrl(uint8_t streamID); virtual bool UpdateTime(time_t ts); - virtual bool TakePhoto(std::vector& img); - virtual bool TakeVideo(uint32_t duration, std::string path); + virtual bool TakePhoto(uint8_t streamID, std::vector& img); + virtual bool TakeVideo(uint8_t streamID, uint32_t duration, std::string path); virtual bool SetResolution(uint8_t channel, uint8_t streamID, uint32_t resX, uint32_t resY); private: