From 6f3cae9d025badfa078801cc571d0d7ebd9d20e1 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 10 Jun 2025 16:16:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=96=B0=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E6=95=B4=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/PhoneDevice.cpp | 69 +++++++++++++++----------------- app/src/main/cpp/PhoneDevice.h | 8 ++-- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 7960cbfa..63b2bb67 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1595,7 +1595,7 @@ IDevice::timer_uid_t CPhoneDevice::RegisterHeartbeat(unsigned int timerType, uns return uid; } -bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector& osds, std::shared_ptr powerCtrlPtr) +bool CPhoneDevice::TakePhotoWithNetCamera(const IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, const std::vector& osds, std::shared_ptr powerCtrlPtr) { // AutoEnv autoEnv(pThis->m_vm); time_t ts = time(NULL); @@ -1721,15 +1721,13 @@ bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c } } - localPhotoInfo.photoTime = takingTime; - // Notify to take next photo TakePhotoCb(1, localPhotoInfo, "", takingTime); #ifdef _DEBUG // cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb); #endif - netCaptureResult = PostProcessPhoto(localPhotoInfo, osds, path, "", rgb); + netCaptureResult = PostProcessPhoto(localPhotoInfo, osds, path, "", rgb, takingTime); } else { @@ -1742,7 +1740,7 @@ bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c } -bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector& osds, std::shared_ptr powerCtrlPtr) +bool CPhoneDevice::TakeVideoWithNetCamera(const IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, const std::vector& osds, std::shared_ptr powerCtrlPtr) { // AutoEnv autoEnv(pThis->m_vm); time_t ts = time(NULL); @@ -1794,7 +1792,7 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c // strcpy(netPhotoInfo.interface, "eth0"); - localPhotoInfo.photoTime = time(NULL); + time_t 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(); @@ -1814,12 +1812,12 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c ethernetPowerCtrl.reset(); XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power OFF"); - std::string fullPath = endsWith(mPath, ".mp4") ? mPath : (mPath + CTerminal::BuildPhotoFileName(mPhotoInfo)); + std::string fullPath = endsWith(mPath, ".mp4") ? mPath : (mPath + CTerminal::BuildPhotoFileName(mPhotoInfo, photoTime)); if (existsFile(tmpFile)) { std::rename(tmpFile.c_str(), fullPath.c_str()); - TakePhotoCb(3, localPhotoInfo, fullPath, localPhotoInfo.photoTime); + TakePhotoCb(3, localPhotoInfo, fullPath, photoTime); } else { @@ -1837,7 +1835,7 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c return true; } -bool CPhoneDevice::StartPushStreaming(IDevice::PHOTO_INFO& photoInfo, const std::string& url, std::vector& osds, std::shared_ptr powerCtrlPtr) +bool CPhoneDevice::StartPushStreaming(const IDevice::PHOTO_INFO& photoInfo, const std::string& url, const std::vector& osds, std::shared_ptr powerCtrlPtr) { if (photoInfo.mediaType == XY_MEDIA_TYPE_STREAM) { @@ -2122,7 +2120,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< osds.swap(mOsds); IDevice::PHOTO_INFO localPhotoInfo = mPhotoInfo; - std::thread t([localPhotoInfo, path, pThis, osds, powerCtrlPtr]() mutable + std::thread t([localPhotoInfo, path, pThis, osds, powerCtrlPtr]() { uint32_t waitTime = localPhotoInfo.selfTestingTime; XYLOG(XYLOG_SEVERITY_INFO, "Camera is SelfTesting Time=%u s", waitTime); @@ -2148,7 +2146,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< vector osds; osds.swap(mOsds); - std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial]() mutable + std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial]() { time_t ts = time(NULL); if(localPhotoInfo.scheduleTime != 0) @@ -2192,13 +2190,12 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< if(photo.state == 5) { XYLOG(XYLOG_SEVERITY_INFO,"Get Serials Photo, PhotoID = %s", photo.photoname); - localPhotoInfo.photoTime = takingTime; cv::Mat img = cv::imread(photo.photoname, cv::IMREAD_COLOR); if (!img.empty()) { int result = std::remove(photo.photoname); pThis->TakePhotoCb(1, localPhotoInfo, "", takingTime, objects); - pThis->PostProcessPhoto(localPhotoInfo, osds, path, "", img); + pThis->PostProcessPhoto(localPhotoInfo, osds, path, "", img, takingTime); } }else @@ -2224,7 +2221,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< vector osds; osds.swap(mOsds); - std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial, powerCtrlPtr]() mutable + std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial, powerCtrlPtr]() { uint32_t waitTime = localPhotoInfo.selfTestingTime; if(!GpioControl::GetSelftestStatus(waitTime)) @@ -2269,7 +2266,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< m_ptzController->AddPhotoCommand(localPhotoInfo, path, osds); }else { - std::thread t([localPhotoInfo, path, pThis, osds, powerCtrlPtr]() mutable + std::thread t([localPhotoInfo, path, pThis, osds, powerCtrlPtr]() { pThis->TakePhotoCb(1, localPhotoInfo, "", 0); pThis->StartPushStreaming(localPhotoInfo, path, osds, powerCtrlPtr); @@ -2289,7 +2286,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< GetPhotoSerialsParamCb(param); vector osds; osds.swap(mOsds); - std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial, powerCtrlPtr]() mutable + std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial, powerCtrlPtr]() { uint32_t waitTime = localPhotoInfo.selfTestingTime; if(!GpioControl::GetSelftestStatus(waitTime)) @@ -2325,7 +2322,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< vector osds; osds.swap(mOsds); - std::thread t([localPhotoInfo, pThis, path, osds, wid_serial, powerCtrlPtr]() mutable + std::thread t([localPhotoInfo, pThis, path, osds, wid_serial, powerCtrlPtr]() { uint32_t waitTime = localPhotoInfo.selfTestingTime; if(!GpioControl::GetSelftestStatus(waitTime)) @@ -2573,7 +2570,6 @@ bool CPhoneDevice::onOneCapture(std::shared_ptr characteristics takingTime = scheduleTime + mPhotoInfo.channel * 2; } } - mPhotoInfo.photoTime = takingTime; vector osds; osds.swap(mOsds); @@ -2675,11 +2671,14 @@ bool CPhoneDevice::onOneCapture(std::shared_ptr characteristics XYLOG(XYLOG_SEVERITY_INFO, "TP: Notofy to Take Next CUR Info: CH=%u PR=%u IMGID=%u", (uint32_t)photoInfo.channel, (uint32_t)photoInfo.preset, (uint32_t)photoInfo.photoId); pThis->TakePhotoCb(1, photoInfo, "", takingTime); - bool res = pThis->PostProcessPhoto(photoInfo, osds, path, cameraInfo, rgb); + bool res = pThis->PostProcessPhoto(photoInfo, osds, path, cameraInfo, rgb, takingTime); if (res) { // TakePhotoCb(2, photoInfo, path, takingTime); + ALOGW("Current allocated matrices %u", (uint32_t)rgb.total()); } + + }); th.detach(); @@ -2729,7 +2728,7 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr characteristi } CPhoneDevice* pThis = this; - std::thread th([pThis, characteristics, results, photoInfo, osds, path, pByteArrays, ldr, duration, takingTime]()mutable + std::thread th([pThis, characteristics, results, photoInfo, osds, path, pByteArrays, ldr, duration, takingTime]() { cv::Mat rgb; std::string cameraInfo; @@ -3047,7 +3046,7 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr characteristi } else { - bool res = pThis->PostProcessPhoto(photoInfo, osds, path, cameraInfo, rgb); + bool res = pThis->PostProcessPhoto(photoInfo, osds, path, cameraInfo, rgb, takingTime); if (res) { // TakePhotoCb(2, photoInfo, path, takingTime); @@ -3098,7 +3097,6 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr characteristi takingTime = scheduleTime + mPhotoInfo.channel * 2; } } - mPhotoInfo.photoTime = takingTime; vector osds; osds.swap(mOsds); @@ -3376,7 +3374,7 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr characteristi } else { - bool res = pThis->PostProcessPhoto(photoInfo, osds, path, cameraInfo, rgb); + bool res = pThis->PostProcessPhoto(photoInfo, osds, path, cameraInfo, rgb, takingTime); if (res) { // TakePhotoCb(2, photoInfo, path, takingTime); @@ -3437,7 +3435,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat mat) takingTime = scheduleTime + mPhotoInfo.channel * 2; } } - mPhotoInfo.photoTime = takingTime; + // mPhotoInfo.photoTime = takingTime; int baseline = 0; cv::Size textSize; double height = mat.size().height; @@ -3664,7 +3662,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat mat) params.push_back((int)((uint32_t)mPhotoInfo.quality)); bool res = false; - std::string fullPath = endsWith(mPath, ".jpg") ? mPath : (mPath + CTerminal::BuildPhotoFileName(mPhotoInfo)); + std::string fullPath = endsWith(mPath, ".jpg") ? mPath : (mPath + CTerminal::BuildPhotoFileName(mPhotoInfo, takingTime)); #ifdef OUTPUT_DBG_INFO @@ -3749,7 +3747,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat mat) return res; } -bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector& osds, const std::string& path, const std::string& cameraInfo, cv::Mat mat) +bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector& osds, const std::string& path, const std::string& cameraInfo, cv::Mat mat, time_t takingTime) { int baseline = 0; cv::Size textSize; @@ -3894,7 +3892,6 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector (int)width - 1) { rb.x = (int)width - 1; @@ -3974,7 +3971,7 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector objs; - std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo); + std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo, photoTime); if (result) { std::rename(path, fullPath.c_str()); } - TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, time(NULL), objs); + TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, photoTime, objs); bool turnOffOtg = (mPhotoInfo.usbCamera != 0); std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, mPhotoInfo.cameraType); @@ -4119,16 +4116,16 @@ bool CPhoneDevice::OnVideoReady(bool photoOrVideo, bool result, const char* path } else { - mPhotoInfo.photoTime = time(NULL); + time_t photoTime = time(NULL); CPhoneCamera* pCamera = NULL; std::vector objs; - std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo); + std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo, photoTime); if (result) { std::rename(path, fullPath.c_str()); } - TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, time(NULL), objs); + TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, photoTime, objs); bool turnOffOtg = (mPhotoInfo.usbCamera != 0); std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, mPhotoInfo.cameraType); @@ -4373,7 +4370,7 @@ void CPhoneDevice::CameraCtrl(unsigned short waitTime, unsigned short delayTime, CPhoneDevice *pThis = this; string serfileStr(serfile); std::thread ctrlThread([pThis, waitTime, delayTime, cmdidx, channel, preset, serfileStr, baud, - addr]() mutable { + addr]() { uint64_t wid = pThis->RequestWakelock(0); XYLOG(XYLOG_SEVERITY_INFO,"CameraCtrl Command= %d, preset = %u", cmdidx, preset); pThis->OpenPTZSensors(waitTime); diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index a7f3254c..263aca66 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -289,10 +289,10 @@ protected: bool SendBroadcastMessage(std::string action, int value); // bool MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_, - bool TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector& osds, std::shared_ptr powerCtrlPtr); - bool TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector& osds, std::shared_ptr powerCtrlPtr); - bool StartPushStreaming(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& url, std::vector& osds, std::shared_ptr powerCtrlPtr); - bool PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector& osds, const std::string& path, const std::string& cameraInfo, cv::Mat mat); + bool TakePhotoWithNetCamera(const IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, const std::vector& osds, std::shared_ptr powerCtrlPtr); + bool TakeVideoWithNetCamera(const IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, const std::vector& osds, std::shared_ptr powerCtrlPtr); + bool StartPushStreaming(const IDevice::PHOTO_INFO& localPhotoInfo, const std::string& url, const std::vector& osds, std::shared_ptr powerCtrlPtr); + bool PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector& osds, const std::string& path, const std::string& cameraInfo, cv::Mat mat, time_t takingTime); inline bool TakePhotoCb(int res, const IDevice::PHOTO_INFO& photoInfo, const string& path, time_t photoTime, const std::vector& objects) const { if (m_listener != NULL)