From d1298663f3979d9bcf5476e96b69db905b369698 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 12 Mar 2025 20:57:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BD=91=E7=BB=9C=E7=9F=AD?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/CMakeLists.txt | 5 +- app/src/main/cpp/PhoneDevice.cpp | 90 +++++++++++------------ app/src/main/cpp/PhoneDevice.h | 3 + app/src/main/cpp/netcamera/HangYuCtrl.cpp | 87 ++++++++++++++++++++++ app/src/main/cpp/netcamera/HangYuCtrl.h | 28 +++++++ app/src/main/cpp/netcamera/VendorCtrl.cpp | 2 +- app/src/main/cpp/netcamera/VendorCtrl.h | 5 +- app/src/main/cpp/netcamera/YuShiCtrl.h | 1 + app/src/main/cpp/netcamera/httpclient.cpp | 7 +- app/src/main/cpp/netcamera/httpclient.h | 2 +- 10 files changed, 174 insertions(+), 56 deletions(-) create mode 100644 app/src/main/cpp/netcamera/HangYuCtrl.cpp create mode 100644 app/src/main/cpp/netcamera/HangYuCtrl.h diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 9d18a0af..36093aca 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -21,7 +21,7 @@ if(ANDROID_ABI STREQUAL "armeabi-v7a") add_definitions(-DUSING_N938) elseif(ANDROID_ABI STREQUAL "arm64-v8a") # add_definitions(-DUSING_N938) - add_definitions(-DUSING_PLZ) + # add_definitions(-DUSING_PLZ) endif() # OUTPUT_DBG_INFO: 输出调试相关信息 @@ -396,6 +396,9 @@ add_library( # Sets the name of the library. ncnn/yolov5ncnn.cpp netcamera/httpclient.cpp + netcamera/VendorCtrl.cpp + netcamera/YuShiCtrl.cpp + netcamera/HangYuCtrl.cpp ${STREAMING_SRCS} diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index f4021b17..8eabf34b 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -10,6 +10,10 @@ #include "PositionHelper.h" #include "DngCreator.h" +#include "netcamera/VendorCtrl.h" +#include "netcamera/YuShiCtrl.h" +#include "netcamera/HangYuCtrl.h" + #include "media/RTSPRecorder.h" #include @@ -1711,8 +1715,8 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c } XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power ON"); - // std::shared_ptr ethernetPowerCtrl = std::make_shared(1); - std::shared_ptr ethernetPowerCtrl; + std::shared_ptr ethernetPowerCtrl = std::make_shared(1); + // std::shared_ptr ethernetPowerCtrl; net_handle_t netHandle = GetEthnetHandle(); if (netHandle == 0) @@ -1747,64 +1751,31 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c // SetStaticIp(); std::this_thread::sleep_for(std::chrono::milliseconds(256)); - NET_PHOTO_INFO netPhotoInfo = { netHandle, 0 }; - if (localPhotoInfo.vendor == 1) - { - // Hai Kang - netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; - snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/ISAPI/Streaming/channels/1/picture?"); - } - else if (localPhotoInfo.vendor == 2) - { - // Hang Yu - strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi"); - } - else if (localPhotoInfo.vendor == 3) - { - // Yu Shi - netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; - int streamSid = 0; // should put into config - // rtsp://192.168.0.13:554/media/video1 - snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/media/video%u", (uint32_t)localPhotoInfo.cameraId); - // strcpy(netPhotoInfo.url, "rtsp://192.168.50.224/live/0"); - } - else if (localPhotoInfo.vendor == 5) - { - // Hang Yu - New - netPhotoInfo.authType = HTTP_AUTH_TYPE_BASIC; - // http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080 - // http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg - // http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg - snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", (uint32_t)localPhotoInfo.cameraId); - } - else + struct in_addr addr; + char ip[32] = { 0 }; + addr.s_addr = localPhotoInfo.ip; + strcpy(ip, inet_ntoa(addr)); + // strcpy(netPhotoInfo.outputPath, path.c_str()); + + VendorCtrl* vendorCtrl = MakeVendorCtrl(localPhotoInfo.vendor, localPhotoInfo.channel, ip, localPhotoInfo.userName, localPhotoInfo.password, netHandle); + if (vendorCtrl == NULL) { XYLOG(XYLOG_SEVERITY_ERROR, "Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.vendor, (uint32_t)localPhotoInfo.channel, (unsigned int)localPhotoInfo.preset, localPhotoInfo.photoId); TakePhotoCb(0, localPhotoInfo, "", 0); return false; } - struct in_addr addr; - addr.s_addr = localPhotoInfo.ip; - strcpy(netPhotoInfo.ip, inet_ntoa(addr)); - strcpy(netPhotoInfo.outputPath, path.c_str()); - if (!localPhotoInfo.userName.empty()) - { - size_t len = std::min(sizeof(netPhotoInfo.userName) - 1, localPhotoInfo.userName.size()); - strncpy(netPhotoInfo.userName, localPhotoInfo.userName.c_str(), len); - } - if (!localPhotoInfo.password.empty()) - { - size_t len = std::min(sizeof(netPhotoInfo.password) - 1, localPhotoInfo.password.size()); - strncpy(netPhotoInfo.password, localPhotoInfo.password.c_str(), len); - } + std::string streamingUrl = vendorCtrl->GetStreamingUrl(localPhotoInfo.channel); + + // strcpy(netPhotoInfo.outputPath, path.c_str()); + // strcpy(netPhotoInfo.interface, "eth0"); localPhotoInfo.photoTime = time(NULL); std::string tmpFile = m_appPath + (APP_PATH_TMP DIR_SEP_STR) + std::to_string(localPhotoInfo.photoId) + ".mp4"; // RTSPToMP4 dumper(netPhotoInfo.url, tmpFile.c_str(), localPhotoInfo.duration * 1000); // dumper.start(); - dumpRtspToMp4(netPhotoInfo.url, tmpFile.c_str(), localPhotoInfo.duration * 1000); + dumpRtspToMp4(streamingUrl.c_str(), tmpFile.c_str(), localPhotoInfo.duration * 1000); ethernetPowerCtrl.reset(); XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power OFF"); @@ -1820,7 +1791,7 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c { TakePhotoCb(0, localPhotoInfo, "", 0); XYLOG(XYLOG_SEVERITY_ERROR, "Failed to TP on NET Camera CH=%u PR=%X PHOTOID=%u URL=http://%s%s", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, - localPhotoInfo.photoId, netPhotoInfo.ip, netPhotoInfo.url); + localPhotoInfo.photoId, ip, streamingUrl.c_str()); } // Notify to take next photo // TakePhotoCb(1, localPhotoInfo, "", takingTime); @@ -4957,4 +4928,25 @@ void CPhoneDevice::SetStaticIp() #endif XYLOG(XYLOG_SEVERITY_WARNING, "No Static IP Confg"); } +} + +VendorCtrl* CPhoneDevice::MakeVendorCtrl(int vendor, uint8_t channel, const std::string& ip, const std::string& userName, const std::string& password, net_handle_t netHandle) +{ + VendorCtrl* vendorCtrl = NULL; + switch (vendor) + { + case 1: + // Hai Kang + break; + case 2: + break; + case 3: + // Yu Shi + vendorCtrl = new YuShiCtrl(ip, userName, password, channel, netHandle); + break; + case 5: + // Hang Yu - New + vendorCtrl = new HangYuCtrl(ip, userName, password, channel, netHandle); + } + return vendorCtrl; } \ No newline at end of file diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 50c1be77..49033047 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -154,6 +154,7 @@ void MatToBitmap(JNIEnv *env, cv::Mat& mat, jobject& bitmap) { #endif class PowerControl; +class VendorCtrl; class CPhoneDevice : public IDevice { @@ -266,6 +267,8 @@ public: net_handle_t GetEthnetHandle() const; + VendorCtrl* MakeVendorCtrl(int vendor, uint8_t channel, const std::string& ip, const std::string& userName, const std::string& password, net_handle_t netHandle); + protected: std::string GetFileName() const; diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.cpp b/app/src/main/cpp/netcamera/HangYuCtrl.cpp new file mode 100644 index 00000000..b40e6450 --- /dev/null +++ b/app/src/main/cpp/netcamera/HangYuCtrl.cpp @@ -0,0 +1,87 @@ +// +// Created by Matthew on 2025/3/4. +// + +#include "YuShiCtrl.h" +#include "httpclient.h" + +HangYuCtrl::~HangYuCtrl() +{ + +} + +bool HangYuCtrl::SetOsd() +{ + // /LAPI/V1.0/Channels//Media/OSDs/Contents +} + +void HangYuCtrl::EnableOsd(bool enable) +{ + return false; +} + +std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) +{ + // /LAPI/V1.0/Channels//Media/Video/Streams//LiveStreamURL?TransType=&TransProtocol= + char url[128] = { 0 }; + snprintf(url, sizeof(url), "/Streams/%u/1/Transport", (uint32_t)channel); + + std::vector resData; + int res = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, "", resData); + if (res != 0 || resData.empty()) + { + return ""; + } + + resData.push_back(0); + const char* start = strstr(&resData[0], ""); + if (start == NULL) + { + return ""; + } + start += 9; + const char* end = strstr(start, ""); + if (end == NULL) + { + return ""; + } + strncpy(url, start, end - start); + + return std::string(url); +} + +bool HangYuCtrl::UpdateTime(time_t ts) +{ + // /LAPI/V1.0/System/Time + + // + // + + std::string reqData = ""; + + std::string url = "http://" + m_ip + " /System/Time"; + std::vector resData; + int res = DoPutRequest(url.c_str(), HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, reqData.c_str(), resData); + + if (res != 0) + { + return false; + } + + return true; +} + +bool HangYuCtrl::TakePhoto(std::vector& img) +{ + 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 new file mode 100644 index 00000000..3cb86ede --- /dev/null +++ b/app/src/main/cpp/netcamera/HangYuCtrl.h @@ -0,0 +1,28 @@ +// +// Created by Matthew on 2025/3/4. +// + +#ifndef __MICROPHOTO_HANGYUCTRL_H__ +#define __MICROPHOTO_HANGYUCTRL_H__ + +#include "VendorCtrl.h" + +class HangYuCtrl : public VendorCtrl +{ +public: + using VendorCtrl::VendorCtrl; + virtual ~HangYuCtrl(); + + virtual bool SetOsd(); + virtual void EnableOsd(bool enable); + 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: + +}; + + +#endif //__MICROPHOTO_HANGYUCTRL_H__ diff --git a/app/src/main/cpp/netcamera/VendorCtrl.cpp b/app/src/main/cpp/netcamera/VendorCtrl.cpp index 81f5d1c8..e89fa58e 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.cpp +++ b/app/src/main/cpp/netcamera/VendorCtrl.cpp @@ -4,7 +4,7 @@ #include "VendorCtrl.h" VendorCtrl::VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password) : - m_ip(ip), m_userName(userName), m_password(password), m_channel(channel) + m_ip(ip), m_userName(userName), m_password(password), m_channel(channel), m_netHandle(netHandle) { } std::string VendorCtrl::CvtJSONToString(const Json::Value& data) diff --git a/app/src/main/cpp/netcamera/VendorCtrl.h b/app/src/main/cpp/netcamera/VendorCtrl.h index 66a18e4a..d12e80f8 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.h +++ b/app/src/main/cpp/netcamera/VendorCtrl.h @@ -7,10 +7,11 @@ #include #include +#include class VendorCtrl { public: - VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password, uint8_t channel); + VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password, uint8_t channel, net_handle_t netHandle); virtual ~VendorCtrl() = 0; virtual bool SetOsd() = 0; @@ -18,6 +19,7 @@ public: 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; protected: @@ -28,6 +30,7 @@ protected: std::string m_userName; std::string m_password; uint8_t m_channel; + net_handle_t m_netHandle; }; diff --git a/app/src/main/cpp/netcamera/YuShiCtrl.h b/app/src/main/cpp/netcamera/YuShiCtrl.h index d5da62ad..d0103ad1 100644 --- a/app/src/main/cpp/netcamera/YuShiCtrl.h +++ b/app/src/main/cpp/netcamera/YuShiCtrl.h @@ -18,6 +18,7 @@ public: 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: diff --git a/app/src/main/cpp/netcamera/httpclient.cpp b/app/src/main/cpp/netcamera/httpclient.cpp index 532b5353..6f4e4ac4 100644 --- a/app/src/main/cpp/netcamera/httpclient.cpp +++ b/app/src/main/cpp/netcamera/httpclient.cpp @@ -119,7 +119,7 @@ int DoGetRequest(const char* url, int authType, const char* userName, const char return ((0 == nRet) && (responseCode == 200)) ? 0 : 1; } -int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, char* data) +int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data) { std::string auth; @@ -239,10 +239,11 @@ int UniviewResolutionSet(const NET_PHOTO_INFO& photoInfo, int channel, unsigned Json::StreamWriterBuilder writer; std::string sendbuf = Json::writeString(writer, outdata); - char respContent[1024]; + std::vector respContent; DoPutRequest(path.c_str(), photoInfo.authType, photoInfo.userName, photoInfo.password, photoInfo.netHandle, sendbuf.c_str(), respContent); - XYLOG(XYLOG_SEVERITY_DEBUG, "Sendlen= %zu, respContent=%s", sendbuf.size(), respContent); + // respContent.push_back(0); + // XYLOG(XYLOG_SEVERITY_DEBUG, "Sendlen= %zu, respContent=%s", sendbuf.size(), (const char*)&respContent[0]); return 0; } diff --git a/app/src/main/cpp/netcamera/httpclient.h b/app/src/main/cpp/netcamera/httpclient.h index 496c8515..fe57564c 100644 --- a/app/src/main/cpp/netcamera/httpclient.h +++ b/app/src/main/cpp/netcamera/httpclient.h @@ -19,6 +19,6 @@ bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr); int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector& data); -int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, char* data); +int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data); #endif // __HTTP_CLIENT__ \ No newline at end of file