camera_h _camera;
InputServiceCallbackType _userCb;
void *_userData;
- std::unique_ptr<std::thread> _thread_handle;
- bool _exit_thread { false };
- std::mutex _preview_mutex;
std::mutex _capture_mutex;
- std::condition_variable _preview_event;
std::condition_variable _capture_event;
cv::Mat _cvCaptureImage;
camera_pixel_format_e _defaultPreviewPixelFormat { CAMERA_PIXEL_FORMAT_I420 };
data_type.ptr = cv_dst.data;
context->_userCb(data_type, context->_userData);
- context->_preview_event.notify_one();
}
bool CameraApiBackend::previewFormatCb(camera_pixel_format_e format, void *user_data)
}
}
-void CameraApiBackend::threadLoop()
-{
- int ret = camera_start_preview(_camera);
- if (ret != CAMERA_ERROR_NONE) {
- SINGLEO_LOGE("CameraApiBackend: camera_start_preview failed. ret: %d", ret);
- throw InvalidOperation("CameraApiBackend: camera_start_preview failed.");
- }
-
- unique_lock<mutex> lock(_preview_mutex);
- _preview_event.wait(lock, [this] { return _exit_thread; });
-}
-
void CameraApiBackend::streamOn()
{
SINGLEO_LOGD("CameraApiBackend: stream on.");
throw InvalidOperation("CameraApiBackend: camera_set_preview_cb failed.");
}
- if (!_thread_handle)
- _thread_handle = std::make_unique<std::thread>(&CameraApiBackend::threadLoop, this);
+ ret = camera_start_preview(_camera);
+ if (ret != CAMERA_ERROR_NONE) {
+ SINGLEO_LOGE("CameraApiBackend: camera_start_preview failed. ret: %d", ret);
+ throw InvalidOperation("CameraApiBackend: camera_start_preview failed.");
+ }
}
void CameraApiBackend::streamOff()
SINGLEO_LOGE("CameraApiBackend: camera_unset_preview_cb failed. ret: %d", ret);
throw InvalidOperation("camera_start_preview: camera_unset_preview_cb failed.");
}
-
- _exit_thread = true;
- _preview_event.notify_one();
- _thread_handle->join();
}
}