From d6dc5729fefe7fa8c81896f2f812215618a60390 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 22 Feb 2025 17:40:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=85=A7=E7=89=87=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 51 +++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index cd1e9457..e08d4873 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -450,6 +450,7 @@ void CPhoneDevice::CJpegCamera::onImageAvailable(AImageReader* reader) if (!(status == AMEDIA_OK && planeCount == 1)) { // LOGE("Error: getNumberOfPlanes() planeCount = %d", planeCount); + AImage_delete(image); return; } @@ -1740,6 +1741,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< } else if (photoInfo.cameraType == CAM_TYPE_PLZ) { + XYLOG(XYLOG_SEVERITY_DEBUG, "PTZ PWR turned ON"); if(mPhotoInfo.scheduleTime == 0) powerCtrlPtr = std::shared_ptr(new PlzCameraPowerCtrl(mPhotoInfo.closeDelayTime)); else @@ -2246,7 +2248,7 @@ bool CPhoneDevice::onOneCapture(std::shared_ptr characteristics } CPhoneDevice* pThis = this; - std::thread th([pThis, characteristics, result, photoInfo, osds, path, rgb, facing, sensorOrientation, ldr, duration, takingTime]()mutable + std::thread th([pThis, characteristics, result, photoInfo, osds, path, rgb, facing, sensorOrientation, ldr, duration, takingTime]() { std::string cameraInfo; if (photoInfo.outputDbgInfo != 0) @@ -3332,6 +3334,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat mat) #endif // OUTPUT_CAMERA_DBG_INFO + if (!std::filesystem::exists(std::filesystem::path(fullPath)) || getFileSize(fullPath) == 0) { bool res = cv::imwrite(fullPath.c_str(), mat, params); if (!res) @@ -3590,27 +3593,61 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector 0) { - int aa = 0; + res = (rename(tmpPath.c_str(), fullPath.c_str()) == 0); + } + else + { + remove(tmpPath.c_str()); + res = false; } +#else + bool res = cv::imwrite(fullPath.c_str(), mat, params); + size_t imgFileSize = getFileSize(fullPath); +#endif +#if 0 + std::string bakPath = fullPath; + replaceAll(bakPath, "/photos/", "/backup/"); + // cv::imwrite(bakPath.c_str(), mat, params); + + vector inImage; + imencode(".jpg", mat, inImage); + + size_t bytesWrtten = 0; + if (!inImage.empty()) + writeFile((bakPath + ".dat"), (const unsigned char*)&inImage[0], inImage.size()); + + bytesWrtten = getFileSize(bakPath + ".dat"); + +// #ifdef _DEBUG + size_t photoFileSize = getFileSize(fullPath); + XYLOG(XYLOG_SEVERITY_ERROR, "Photo File %s Size=%u BufSize=%u DataFileSize=%u", fullPath.c_str() + m_appPath.size(), (uint32_t)photoFileSize, + (uint32_t)inImage.size(), (uint32_t)bytesWrtten); +// #endif #endif + if (!res) { XYLOG(XYLOG_SEVERITY_ERROR, "Failed to Write File: %s", fullPath.c_str() + m_appPath.size()); } else { - XYLOG(XYLOG_SEVERITY_INFO, "Succeeded to Write File: %s", fullPath.c_str() + m_appPath.size()); + XYLOG(XYLOG_SEVERITY_INFO, "Succeeded to Write File: %s, FileSize=%u", fullPath.c_str() + m_appPath.size(), (uint32_t)imgFileSize); } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); TakePhotoCb(res ? 2 : 0, photoInfo, fullPath, photoInfo.photoTime, objs); } else