@@ -45,6 +45,8 @@ public:
const CameraControlValidator *validator() const { return validator_.get(); }
+ bool isRunningOrStopping() const;
+
private:
enum State {
CameraAvailable,
@@ -55,7 +57,6 @@ private:
};
bool isAcquired() const;
- bool isRunning() const;
int isAccessAllowed(State state, bool allowDisconnected = false,
const char *from = __builtin_FUNCTION()) const;
int isAccessAllowed(State low, State high,
@@ -64,6 +65,7 @@ private:
void disconnect();
void setState(State state);
+ State state() const { return state_.load(std::memory_order_acquire); }
std::shared_ptr<PipelineHandler> pipe_;
std::string id_;
@@ -682,9 +682,21 @@ bool Camera::Private::isAcquired() const
return state_.load(std::memory_order_acquire) != CameraAvailable;
}
-bool Camera::Private::isRunning() const
+/**
+ * \brief Check if the camera running or stopping
+ *
+ * This functions checks if the camera's current state is either
+ * CameraRunning or CameraStopping.
+ *
+ * \return True if the camera is running or stopping
+ */
+bool Camera::Private::isRunningOrStopping() const
{
- return state_.load(std::memory_order_acquire) == CameraRunning;
+ State currentState = state_.load(std::memory_order_acquire);
+ if (currentState == CameraRunning || currentState == CameraStopping)
+ return true;
+
+ return false;
}
int Camera::Private::isAccessAllowed(State state, bool allowDisconnected,
@@ -1450,7 +1462,7 @@ int Camera::stop()
* \todo Make calling stop() when not in 'Running' part of the state
* machine rather than take this shortcut
*/
- if (!d->isRunning())
+ if (d->state() != Private::CameraRunning)
return 0;
int ret = d->isAccessAllowed(Private::CameraRunning);
@@ -474,6 +474,17 @@ void PipelineHandler::queueRequest(Request *request)
Camera::Private *data = camera->_d();
data->waitingRequests_.push(request);
+ /*
+ * If we are running into this assert, the calling application didn't
+ * synchronize calls to Camera::queueRequest() and Camera::stop() and a
+ * PipelineHandler::queueRequest() invocation was queued after
+ * PipelineHandler::stop(). We can't guard against that in the Camera
+ * class as it is lock free. Synchronization happens when the Camera
+ * class invokes PipelineHandler::stop() in blocking mode. As such a
+ * race leads to difficult to debug issues, assert here.
+ */
+ ASSERT(data->isRunningOrStopping());
+
request->_d()->prepare(300ms);
}