等待关闭线程结束再继续下一次拍照

serial
BlueMatthew 1 year ago
parent f4d5882590
commit cbefef91a4

@ -754,6 +754,11 @@ IDevice::timer_uid_t CPhoneDevice::RegisterHeartbeat(unsigned int timerType, uns
bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const std::string& path) bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const std::string& path)
{ {
if (m_threadClose.joinable())
{
m_threadClose.join();
}
if (mCamera != NULL) if (mCamera != NULL)
{ {
delete mCamera; delete mCamera;
@ -1071,7 +1076,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
bool turnOffOtg = (mPhotoInfo.usbCamera != 0); bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg); std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
closeThread.detach(); m_threadClose.swap(closeThread);
return res; return res;
} }
@ -1091,7 +1096,7 @@ bool CPhoneDevice::OnVideoReady(bool result, const char* path, unsigned int phot
bool turnOffOtg = (mPhotoInfo.usbCamera != 0); bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg); std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
closeThread.detach(); m_threadClose.swap(closeThread);
return result; return result;
} }

@ -12,6 +12,7 @@
#include <map> #include <map>
#include <atomic> #include <atomic>
#include <filesystem> #include <filesystem>
#include <thread>
#include <camera/NdkCameraManager.h> #include <camera/NdkCameraManager.h>
#include <camera/NdkCameraError.h> #include <camera/NdkCameraError.h>
@ -289,6 +290,7 @@ protected:
long mCameraPowerCount; long mCameraPowerCount;
long mOtgCount; long mOtgCount;
std::thread m_threadClose;
}; };

Loading…
Cancel
Save