@@ -799,6 +799,7 @@ void CameraDevice::close()
void CameraDevice::stop()
{
+ MutexLocker stateLock(stateMutex_);
if (state_ == State::Stopped)
return;
@@ -1898,17 +1899,21 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
if (!isValidRequest(camera3Request))
return -EINVAL;
- /* Start the camera if that's the first request we handle. */
- if (state_ == State::Stopped) {
- worker_.start();
+ {
+ MutexLocker stateLock(stateMutex_);
- int ret = camera_->start();
- if (ret) {
- LOG(HAL, Error) << "Failed to start camera";
- return ret;
- }
+ /* Start the camera if that's the first request we handle. */
+ if (state_ == State::Stopped) {
+ worker_.start();
- state_ = State::Running;
+ int ret = camera_->start();
+ if (ret) {
+ LOG(HAL, Error) << "Failed to start camera";
+ return ret;
+ }
+
+ state_ = State::Running;
+ }
}
/*
@@ -120,6 +120,7 @@ private:
CameraWorker worker_;
+ libcamera::Mutex stateMutex_; /* Protects access to the camera state. */
State state_;
std::shared_ptr<libcamera::Camera> camera_;