summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/android/camera_device.cpp23
-rw-r--r--src/android/camera_device.h1
2 files changed, 15 insertions, 9 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 3346811b..d3581c70 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -800,6 +800,7 @@ void CameraDevice::close()
void CameraDevice::stop()
{
+ MutexLocker stateLock(stateMutex_);
if (state_ == State::Stopped)
return;
@@ -1900,17 +1901,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;
+ }
}
/*
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 70c29755..117d829e 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -120,6 +120,7 @@ private:
CameraWorker worker_;
+ libcamera::Mutex stateMutex_; /* Protects access to the camera state. */
State state_;
std::shared_ptr<libcamera::Camera> camera_;