优化照片写入文件的实现,增加日志

streaming
Matthew 4 months ago
parent c64cc8ef44
commit a205ee22f9

@ -3645,16 +3645,44 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector<ID
#if 1
// Save photo to temporary file and then rename to right path
bool res = cv::imwrite(tmpPath.c_str(), mat, params);
size_t imgFileSize = getFileSize(tmpPath);
if (res && imgFileSize > 0)
std::vector<uint8_t> imgContents;
size_t imgFileSize = 0;
bool res = cv::imencode(".jpg", mat, imgContents, params);
if (res)
{
res = (rename(tmpPath.c_str(), fullPath.c_str()) == 0);
int errcode = 0;
res = writeFile(tmpPath.c_str(), &imgContents[0], imgContents.size(), errcode);
if (res)
{
if (existsFile(tmpPath))
{
imgFileSize = getFileSize(tmpPath);
if (imgFileSize == 0)
{
XYLOG(XYLOG_SEVERITY_ERROR, "Empty File Written: %s errno=%d", tmpPath.c_str() + m_appPath.size(), errcode);
remove(tmpPath.c_str());
res = false;
}
}
}
else
{
XYLOG(XYLOG_SEVERITY_ERROR, "Failed to Write File: %s errno=%d", tmpPath.c_str() + m_appPath.size(), errcode);
if (existsFile(tmpPath))
{
remove(tmpPath.c_str());
res = false;
}
}
}
else
{
int errcode = errno;
XYLOG(XYLOG_SEVERITY_ERROR, "Failed to Encode Image CH=%u PR=%u IMGID=%u, errno=%d", (uint32_t)photoInfo.channel, (uint32_t)photoInfo.preset, (uint32_t)photoInfo.photoId, errcode);
}
// bool res = cv::imwrite(tmpPath.c_str(), mat, params);
if (res/* && imgFileSize > 0*/)
{
res = (rename(tmpPath.c_str(), fullPath.c_str()) == 0);
}
#else
bool res = cv::imwrite(fullPath.c_str(), mat, params);

Loading…
Cancel
Save