android: Guard access to the camera state
Guard access to the camera state and the start/stop sequences with a mutex. Currently only stop() and the first call to processCaptureRequest() start and stop the camera, and they're not meant to race with each other. With the introduction of flush() the camera can be stopped concurrently to a processCaptureRequest() call, hence access to the camera state will need to be protected. Prepare for that by guarding the existing paths with a mutex. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
int ret = camera_->start();
|
||||
if (ret) {
|
||||
LOG(HAL, Error) << "Failed to start camera";
|
||||
return ret;
|
||||
}
|
||||
|
||||
state_ = State::Running;
|
||||
}
|
||||
|
||||
state_ = State::Running;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user