cv::cvtColor(cv_src, context->_cvCaptureImage, cv::COLOR_YUV2BGR_I420);
+ context->_isCaptured = true;
context->_capture_event.notify_one();
}
unique_lock<mutex> lock(_capture_mutex);
- _capture_event.wait(lock);
+ _isCaptured = false;
+ auto event_ret = _capture_event.wait_for(lock, chrono::milliseconds(3000), [this] { return _isCaptured; });
+ if (!event_ret)
+ throw InvalidOperation("Camera device not working");
auto &image_data = dynamic_cast<ImageDataType &>(out_data);
// Wait for "Captured" state.
// Ps. captureCompletedCb callback is called by main thread so we cannot use the callback
// to wait for "Captured" state with sync API.
+ const unsigned int max_try_count = 100;
camera_state_e state {};
+ unsigned int try_count = 0;
+
+ while (++try_count < max_try_count) {
+ ret = camera_get_state(_camera, &state);
+ if (ret != CAMERA_ERROR_NONE || state == CAMERA_STATE_CAPTURED)
+ break;
- camera_get_state(_camera, &state);
- while (state != CAMERA_STATE_CAPTURED) {
this_thread::sleep_for(10ms);
- camera_get_state(_camera, &state);
}
+ if (ret != CAMERA_ERROR_NONE || try_count == max_try_count)
+ throw InvalidOperation("Camera device not working");
+
// Change the state to "Previewing".
ret = camera_start_preview(_camera);
if (ret != CAMERA_ERROR_NONE) {