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:
parent
ebf8b5e7e0
commit
10b31904d8
2 changed files with 15 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue