Improve:take picture from chip.
This commit is contained in:
		
							parent
							
								
									fefc76b1cd
								
							
						
					
					
						commit
						573ce84da7
					
				|  | @ -20,7 +20,7 @@ | |||
| #include <stdio.h> | ||||
| CameraHal::CameraHal() | ||||
|     : mTaskRuning(false), mAudioStreamCallback(nullptr), mVideoStreamCallback(nullptr), mVideoFile(nullptr), | ||||
|       mAudioFile(nullptr), mTaskType(CameraTaskType::END) | ||||
|       mAudioFile(nullptr), mTaskType(CameraTaskType::END), mFastBootSaveFile(false) | ||||
| { | ||||
| } | ||||
| void CameraHal::Init(void) | ||||
|  | @ -29,6 +29,14 @@ void CameraHal::Init(void) | |||
| void CameraHal::UnInit(void) | ||||
| { | ||||
| } | ||||
| void CameraHal::SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor) | ||||
| { | ||||
|     std::lock_guard<std::mutex> locker(mMutex); | ||||
|     mCameraMonitor = monitor; | ||||
|     if (nullptr != mFastBootEvent) { | ||||
|         monitor->ReportEvent(*(mFastBootEvent.get())); | ||||
|     } | ||||
| } | ||||
| StatusCode CameraHal::StartSingleTask(const CameraTaskParam ¶m) | ||||
| { | ||||
|     LogInfo("StartSingleTask.\n"); | ||||
|  | @ -89,6 +97,9 @@ void CameraHal::GetJpegData(const void *stream, const unsigned int &length, cons | |||
|     if (mTaskRuning && nullptr != mJpegEncodeCallback) { | ||||
|         mJpegEncodeCallback(stream, length, timeStamp); | ||||
|     } | ||||
|     else { | ||||
|         FastStartGetJpegData(stream, length, timeStamp); | ||||
|     } | ||||
| } | ||||
| void CameraHal::SaveChipStream(const ChipStreamType &streamType, const void *stream, const unsigned int &length) | ||||
| { | ||||
|  | @ -98,4 +109,43 @@ void CameraHal::SaveChipStream(const ChipStreamType &streamType, const void *str | |||
|         fwrite(stream, 1, length, file); | ||||
|         fflush(file); | ||||
|     } | ||||
| } | ||||
| void CameraHal::FastStartGetJpegData(const void *stream, const unsigned int &length, | ||||
|                                      const unsigned long long &timeStamp) | ||||
| { | ||||
|     std::lock_guard<std::mutex> locker(mMutex); | ||||
|     if (mFastBootSaveFile) { | ||||
|         return; | ||||
|     } | ||||
|     std::string savedFile = SaveJpeg(stream, length); | ||||
|     if (savedFile.empty()) { | ||||
|         LogError("save jpeg failed.\n"); | ||||
|         return; | ||||
|     } | ||||
|     mFastBootSaveFile = true; | ||||
|     auto monitor = mCameraMonitor.lock(); | ||||
|     if (mCameraMonitor.expired()) { | ||||
|         LogWarning("SdCardHal: monitor is expired.\n"); | ||||
|         mFastBootEvent = std::make_shared<CameraReportEvent>(savedFile, CameraType::MAIN_CAMERA); | ||||
|         return; | ||||
|     } | ||||
|     CameraReportEvent report(savedFile, CameraType::MAIN_CAMERA); | ||||
|     monitor->ReportEvent(report); | ||||
| } | ||||
| std::string CameraHal::SaveJpeg(const void *data, unsigned int dataLength) | ||||
| { | ||||
|     const std::string SAVE_JPEG_FAILED = ""; | ||||
|     const std::string SaveJpegPath = "/tmp/fastboot.jpg"; | ||||
|     FILE *fp = nullptr; | ||||
|     fp = fopen(SaveJpegPath.c_str(), "wb"); | ||||
|     if (fp) { | ||||
|         fwrite(data, 1, dataLength, fp); | ||||
|         fflush(fp); | ||||
|         fclose(fp); | ||||
|         return SaveJpegPath; | ||||
|     } | ||||
|     else { | ||||
|         LogInfo("open file error\n"); | ||||
|         return SAVE_JPEG_FAILED; | ||||
|     } | ||||
| } | ||||
|  | @ -31,6 +31,7 @@ public: | |||
|     virtual ~CameraHal() = default; | ||||
|     virtual void Init(void); | ||||
|     virtual void UnInit(void); | ||||
|     void SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor) override; | ||||
| 
 | ||||
| protected: | ||||
|     StatusCode StartSingleTask(const CameraTaskParam ¶m) override; | ||||
|  | @ -45,8 +46,13 @@ protected: | |||
|     void GetJpegData(const void *stream, const unsigned int &length, const unsigned long long &timeStamp); | ||||
|     void SaveChipStream(const ChipStreamType &streamType, const void *stream, const unsigned int &length); | ||||
| 
 | ||||
| private: | ||||
|     void FastStartGetJpegData(const void *stream, const unsigned int &length, const unsigned long long &timeStamp); | ||||
|     std::string SaveJpeg(const void *data, unsigned int dataLength); | ||||
| 
 | ||||
| private: | ||||
|     // std::mutex mMutex;
 | ||||
|     std::mutex mMutex; | ||||
|     bool mTaskRuning; | ||||
|     AudioStreamCallback mAudioStreamCallback; | ||||
|     VideoStreamCallback mVideoStreamCallback; | ||||
|  | @ -57,5 +63,8 @@ private: | |||
|     FILE *mVideoFile; ///< The original video stream data is saved.
 | ||||
|     FILE *mAudioFile; ///< The original audio stream data is saved.
 | ||||
|     CameraTaskType mTaskType; | ||||
|     std::weak_ptr<VCameraHalMonitor> mCameraMonitor; | ||||
|     std::shared_ptr<CameraReportEvent> mFastBootEvent; | ||||
|     bool mFastBootSaveFile; | ||||
| }; | ||||
| #endif | ||||
|  | @ -202,7 +202,6 @@ void McuManagerImpl::WatchDogThread(void) | |||
|         mCv.wait_for(lock, std::chrono::milliseconds(WATCH_DOG_CYCLE_MS), [&] { | ||||
|             return !mWatchDogRuning; | ||||
|         }); | ||||
|         LogInfo("WatchDogThread is running.\n"); | ||||
|     } | ||||
| } | ||||
| std::shared_ptr<VMcuMonitor> McuManagerImpl::GetMcuMonitor(void) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Fancy code
						Fancy code