diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.cpp b/app/src/main/cpp/netcamera/HangYuCtrl.cpp index d6fca518..a9e6d1c9 100644 --- a/app/src/main/cpp/netcamera/HangYuCtrl.cpp +++ b/app/src/main/cpp/netcamera/HangYuCtrl.cpp @@ -13,14 +13,97 @@ HangYuCtrl::~HangYuCtrl() } -bool HangYuCtrl::SetOsd() +bool HangYuCtrl::SetResolution(uint8_t channel, uint8_t streamID, uint32_t resX, uint32_t resY) +{ + //流类型范围1-4,1为主流 + char url[128] = { 0 }; + snprintf(url, sizeof(url), "http://%s/Streams/%u/%u", m_ip.c_str(), (uint32_t)channel, (uint32_t)streamID); + + std::vector resData; + + int res = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, resData); + if (res != 0 || resData.empty()) + { + return 0; + } + + std::string xmlString(resData.begin(), resData.end()); + + size_t widthStart = xmlString.find(""); + size_t widthEnd = xmlString.find(""); + if (widthStart != std::string::npos && widthEnd != std::string::npos) { + widthStart += std::string("").length(); + xmlString.replace(widthStart, widthEnd - widthStart, std::to_string(resX)); + } + + size_t heightStart = xmlString.find(""); + size_t heightEnd = xmlString.find(""); + if (heightStart != std::string::npos && heightEnd != std::string::npos) { + heightStart += std::string("").length(); + xmlString.replace(heightStart, heightEnd - heightStart, std::to_string(resY)); + } + + res = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, xmlString.c_str(), resData); + + if (res != 0) + { + return 0; + } + return true; +} + +bool HangYuCtrl::SetOsd(uint8_t channel, std::string osdstring) { // /LAPI/V1.0/Channels//Media/OSDs/Contents + //左上OSD + char url[128] = { 0 }; + snprintf(url, sizeof(url), "http://%s/Pictures/%u/MultiOSDV2", m_ip.c_str(), (uint32_t)channel); + std::vector resData; + std::replace(osdstring.begin(), osdstring.end(), '\n', '^'); + string xmlString = "true801true"+ osdstring+ "824"; + int res = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, xmlString.c_str(), resData); + return res; } -void HangYuCtrl::EnableOsd(bool enable) +void HangYuCtrl::EnableOsd(bool enable, uint8_t channel) { - // return false; + //航煜 只能显示时间和一个OSD + char url[128] = { 0 }; + snprintf(url, sizeof(url), "http://%s/Pictures/%u/MultiOSDV2", m_ip.c_str(), (uint32_t)channel); + + std::vector resData; + + int res = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, resData); + if (res != 0 || resData.empty()) + { + return; + } + + std::string xmlString(resData.begin(), resData.end()); + + std::string enableStartTag = ""; + std::string enableEndTag = ""; + + size_t pos = 0; + while ((pos = xmlString.find(enableStartTag, pos)) != std::string::npos) { + size_t startPos = pos + enableStartTag.length(); + size_t endPos = xmlString.find(enableEndTag, startPos); + if (endPos == std::string::npos) { + break; + } + std::string newValue = enable ? "true" : "false"; + xmlString.replace(startPos, endPos - startPos, newValue); + pos = endPos + enableEndTag.length(); + } + + res = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, xmlString.c_str(), resData); + + if (res != 0) + { +// return; + } + + } std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.h b/app/src/main/cpp/netcamera/HangYuCtrl.h index 4096fb45..a370ec81 100644 --- a/app/src/main/cpp/netcamera/HangYuCtrl.h +++ b/app/src/main/cpp/netcamera/HangYuCtrl.h @@ -13,8 +13,8 @@ public: using VendorCtrl::VendorCtrl; virtual ~HangYuCtrl(); - virtual bool SetOsd(); - virtual void EnableOsd(bool enable); + virtual bool SetOsd(uint8_t channel, std::string osd); + 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); @@ -22,6 +22,7 @@ public: virtual bool HasAuthOnStreaming() const { return true; } private: + bool SetResolution(uint8_t channel, uint8_t streamID, uint32_t resX, uint32_t resY); }; diff --git a/app/src/main/cpp/netcamera/VendorCtrl.h b/app/src/main/cpp/netcamera/VendorCtrl.h index 84676581..7018a21c 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.h +++ b/app/src/main/cpp/netcamera/VendorCtrl.h @@ -9,13 +9,18 @@ #include #include +#define LEFT_TOP 0 +#define RIGHT_TOP 1 +#define LEFT_BOTTOM 2 +#define RIGHT_BOTTOM 3 + class VendorCtrl { public: VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password, uint8_t channel, net_handle_t netHandle, bool syncTime = true); virtual ~VendorCtrl() {} - virtual bool SetOsd() = 0; - virtual void EnableOsd(bool enable) = 0; + virtual bool SetOsd(uint8_t channel, std::string osd, uint8_t pos) = 0; + 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; diff --git a/app/src/main/cpp/netcamera/YuShiCtrl.cpp b/app/src/main/cpp/netcamera/YuShiCtrl.cpp index 93ca9d22..43fc0cf9 100644 --- a/app/src/main/cpp/netcamera/YuShiCtrl.cpp +++ b/app/src/main/cpp/netcamera/YuShiCtrl.cpp @@ -13,14 +13,75 @@ YuShiCtrl::~YuShiCtrl() } -bool YuShiCtrl::SetOsd() +bool YuShiCtrl::SetOsd(uint8_t channel, std::string osd, uint8_t pos) { // /LAPI/V1.0/Channels//Media/OSDs/Contents + char url[128] = { 0 }; + snprintf(url, sizeof(url), "http://%s/LAPI/V1.0/Channels/%u/Media/OSDs/Contents", m_ip.c_str(), (uint32_t)channel); + std::vector resData; + + string jsonstring; + switch (pos) { + case LEFT_TOP: + { + OSDJson(0, 1, osd, 0, 0, true, jsonstring); + break; + } + case RIGHT_TOP: + { + OSDJson(1, 1, osd, 9900, 0, false, jsonstring); + break; + } + case LEFT_BOTTOM: + { + OSDJson(2, 1, osd, 0, 9900, false, jsonstring); + break; + } + case RIGHT_BOTTOM: + { + OSDJson(3, 1, osd, 9900, 9900, false, jsonstring); + break; + } + + } + int res = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, jsonstring.c_str(), resData); + return res; } -void YuShiCtrl::EnableOsd(bool enable) +void YuShiCtrl::EnableOsd(bool enable, uint8_t channel) { - // return false; + char url[128] = { 0 }; + snprintf(url, sizeof(url), "http://%s/LAPI/V1.0/Channels/%u/Media/OSDs/Contents", m_ip.c_str(), (uint32_t)channel); + std::vector resData; + int res =DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, resData); + std::string jsonString(resData.begin(), resData.end()); + + Json::CharReaderBuilder reader; + Json::Value root; + std::string errors; + std::istringstream s(jsonString); + + if (!Json::parseFromStream(reader, s, &root, &errors)) { + XYLOG(XYLOG_SEVERITY_ERROR,"Failed to parse JSON:%s", errors); + return; + } + + Json::Value& data = root["Response"]["Data"]; + if (data.isNull()) { + XYLOG(XYLOG_SEVERITY_ERROR,"Data not found in JSON"); + return; + } + + Json::Value& contentList = data["ContentList"]; + for (auto& content : contentList) { + content["Enabled"] = enable ? 1 : 0; + } + + Json::StreamWriterBuilder writer; + std::string putJsonString = Json::writeString(writer, data); + DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, putJsonString.c_str(), resData); + + } std::string YuShiCtrl::GetStreamingUrl(uint8_t channel) @@ -94,7 +155,73 @@ bool YuShiCtrl::TakePhoto(std::vector& img) return false; } -bool YuShiCtrl::TakeVideo(uint32_t duration, std::string path) + +bool YuShiCtrl::TakeVideo(uint32_t duration, std::string path) { + +} + + +void YuShiCtrl::OSDJson(int id, bool enabled, std::string osdString, int x, int y, bool timeOn, std::string& jsonString) { + Json::Value root; + root["Num"] = 1; + + Json::Value contentList(Json::arrayValue); + + Json::Value content; + content["ID"] = id; + content["Enabled"] = enabled; + + int row = 1; + for (char ch : osdString) { + if (ch == '\n') { + row++; + } + } + + content["Num"] = row; + Json::Value contentInfo(Json::arrayValue); + size_t start = 0; + size_t end = osdString.find('\n'); + + if(timeOn) + { + //如果在此位置显示时间 + Json::Value info; + info["ContentType"] = 2; + info["Value"] = ""; + contentInfo.append(info); + } + + for (int i = 0; i < row; i++) + { + std::string line; + if (end == std::string::npos) { + line = osdString.substr(start); + } else { + line = osdString.substr(start, end - start); + start = end + 1; + end = osdString.find('\n', start); + } + + Json::Value info; + info["ContentType"] = 1; + info["Value"] = line; + contentInfo.append(info); + } + content["ContentInfo"] = contentInfo; + + Json::Value area; + Json::Value topLeft; + topLeft["X"] = x; //9900 + topLeft["Y"] = y; + area["TopLeft"] = topLeft; + content["Area"] = area; + + contentList.append(content); + + root["ContentList"] = contentList; + Json::StreamWriterBuilder writer; + jsonString = Json::writeString(writer, root); } \ No newline at end of file diff --git a/app/src/main/cpp/netcamera/YuShiCtrl.h b/app/src/main/cpp/netcamera/YuShiCtrl.h index d0103ad1..0f2d1b26 100644 --- a/app/src/main/cpp/netcamera/YuShiCtrl.h +++ b/app/src/main/cpp/netcamera/YuShiCtrl.h @@ -13,14 +13,15 @@ public: using VendorCtrl::VendorCtrl; virtual ~YuShiCtrl(); - virtual bool SetOsd(); - virtual void EnableOsd(bool enable); + 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 bool UpdateTime(time_t ts); virtual bool TakePhoto(std::vector& img); virtual bool TakeVideo(uint32_t duration, std::string path); private: + void OSDJson(int id, bool enabled, std::string osdString, int x, int y, bool timeOn, std::string& jsonString); };