summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNĂ­colas F. R. A. Prado <nfraprado@collabora.com>2021-07-02 09:21:10 -0300
committerJacopo Mondi <jacopo@jmondi.org>2021-07-06 12:40:41 +0200
commitb0bf6b0aa90e2ce94ec77e389eea0e5849f2eaec (patch)
tree64973d1d420cd5db0442f5f595f292fddc26b6c1 /src
parentd7415bc4e46fe8aa25a495c79516d9882a35a5aa (diff)
libcamera: camera: Make stop() idempotent
Make Camera::stop() idempotent so that it can be called in any state and consecutive times. When called in any state other than CameraRunning, it is a no-op. This simplifies the cleanup path for applications. Signed-off-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/camera.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index de0123ae..29f2d91d 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -348,6 +348,7 @@ public:
const std::set<Stream *> &streams);
~Private();
+ bool isRunning() const;
int isAccessAllowed(State state, bool allowDisconnected = false,
const char *from = __builtin_FUNCTION()) const;
int isAccessAllowed(State low, State high,
@@ -389,6 +390,11 @@ static const char *const camera_state_names[] = {
"Running",
};
+bool Camera::Private::isRunning() const
+{
+ return state_.load(std::memory_order_acquire) == CameraRunning;
+}
+
int Camera::Private::isAccessAllowed(State state, bool allowDisconnected,
const char *from) const
{
@@ -1062,9 +1068,10 @@ int Camera::start(const ControlList *controls)
* This method stops capturing and processing requests immediately. All pending
* requests are cancelled and complete synchronously in an error state.
*
- * \context This function may only be called when the camera is in the Running
- * state as defined in \ref camera_operation, and shall be synchronized by the
- * caller with other functions that affect the camera state.
+ * \context This function may be called in any camera state as defined in \ref
+ * camera_operation, and shall be synchronized by the caller with other
+ * functions that affect the camera state. If called when the camera isn't
+ * running, it is a no-op.
*
* \return 0 on success or a negative error code otherwise
* \retval -ENODEV The camera has been disconnected from the system
@@ -1074,6 +1081,13 @@ int Camera::stop()
{
Private *const d = LIBCAMERA_D_PTR();
+ /*
+ * \todo Make calling stop() when not in 'Running' part of the state
+ * machine rather than take this shortcut
+ */
+ if (!d->isRunning())
+ return 0;
+
int ret = d->isAccessAllowed(Private::CameraRunning);
if (ret < 0)
return ret;