summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2018-12-21 10:59:25 +0000
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-02-06 06:49:38 +0200
commit374673f84ac71425d840db5521de14cc7ad139fe (patch)
treec8f30e08f65419a234785bab411acea59e972368
parentdffbde33b8a7a26e5bd0a840837af647b6317534 (diff)
libcamera: v4l2_device: Implement stream{On,Off}
Support starting and stopping a stream on a V4L2 device. Buffers must be queued before the stream is started. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
-rw-r--r--src/libcamera/include/v4l2_device.h3
-rw-r--r--src/libcamera/v4l2_device.cpp45
2 files changed, 48 insertions, 0 deletions
diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index 30a8f77d..988e646c 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -103,6 +103,9 @@ public:
int queueBuffer(Buffer *buffer);
Signal<Buffer *> bufferReady;
+ int streamOn();
+ int streamOff();
+
private:
int getFormatSingleplane(V4L2DeviceFormat *format);
int setFormatSingleplane(V4L2DeviceFormat *format);
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 134a468c..f9839fc7 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -756,4 +756,49 @@ void V4L2Device::bufferAvailable(EventNotifier *notifier)
* \brief A Signal emitted when a buffer completes
*/
+/**
+ * \brief Start the video stream
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2Device::streamOn()
+{
+ int ret;
+
+ ret = ioctl(fd_, VIDIOC_STREAMON, &bufferType_);
+ if (ret < 0) {
+ ret = -errno;
+ LOG(V4L2, Error)
+ << "Failed to start streaming: " << strerror(-ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/**
+ * \brief Stop the video stream
+ *
+ * \todo Ensure completion notifications are sent for all queued buffers
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2Device::streamOff()
+{
+ int ret;
+
+ ret = ioctl(fd_, VIDIOC_STREAMOFF, &bufferType_);
+ if (ret < 0) {
+ ret = -errno;
+ LOG(V4L2, Error)
+ << "Failed to stop streaming: " << strerror(-ret);
+ return ret;
+ }
+
+ queuedBuffersCount_ = 0;
+ fdEvent_->setEnabled(false);
+
+ return 0;
+}
+
} /* namespace libcamera */