summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2021-01-12 10:21:39 +0530
committerKieran Bingham <kieran.bingham@ideasonboard.com>2021-01-12 14:06:56 +0000
commitc0bad607ce16ea66aa9c4de892598793402281c6 (patch)
tree88fa59275f9b9f1478cbcee7a942d00d69ea4bbb /src
parent5988661c9047fc04840603068a94466719319725 (diff)
libcamera: v4l2_videodevice: Track streaming state
Track the state of streamon/streamoff calls to simplify error paths. Ensuring that streamOff() can be called on non-streaming streams facilitates simpler error code paths, where a set of devices can all call streamOff regardless of their initialisation state. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Umang Jain <email@uajain.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/v4l2_videodevice.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index baf683d6..a9509bff 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -481,7 +481,8 @@ const std::string V4L2DeviceFormat::toString() const
* \param[in] deviceNode The file-system path to the video device node
*/
V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)
- : V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr)
+ : V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr),
+ streaming_(false)
{
/*
* We default to an MMAP based CAPTURE video device, however this will
@@ -1554,6 +1555,8 @@ int V4L2VideoDevice::streamOn()
return ret;
}
+ streaming_ = true;
+
return 0;
}
@@ -1565,12 +1568,18 @@ int V4L2VideoDevice::streamOn()
* and the bufferReady signal is emitted for them. The order in which those
* buffers are dequeued is not specified.
*
+ * This will be a no-op if the stream is not started in the first place and
+ * has no queued buffers.
+ *
* \return 0 on success or a negative error code otherwise
*/
int V4L2VideoDevice::streamOff()
{
int ret;
+ if (!streaming_ && queuedBuffers_.empty())
+ return 0;
+
ret = ioctl(VIDIOC_STREAMOFF, &bufferType_);
if (ret < 0) {
LOG(V4L2, Error)
@@ -1588,6 +1597,7 @@ int V4L2VideoDevice::streamOff()
queuedBuffers_.clear();
fdBufferNotifier_->setEnabled(false);
+ streaming_ = false;
return 0;
}