From patchwork Wed Feb 6 06:07:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 521 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C1BAE61022 for ; Wed, 6 Feb 2019 07:08:24 +0100 (CET) Received: from pendragon.ideasonboard.com (d51A4137F.access.telenet.be [81.164.19.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6B0CD2D7 for ; Wed, 6 Feb 2019 07:08:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549433304; bh=vdNnO7uzLhJIZcdswDjBiG1uwUAte5M9V//IYPhHTIE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pZP3cOFBe/t/yCDmCbVnDHKaiGPYq7ZKay43xqeCy821XYuomxXLIx4Z+FanZXhHy wdPiesJStn5OL3fABgZfP+z366OR39aQEOV8BY58ICvZHbgD2dzvzv5t/qYDHhWrVs HqgZdQSGLrZSK8V4+FDyP8dV+E7hHx7j9NbVXrfg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Feb 2019 08:07:57 +0200 Message-Id: <20190206060818.13907-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> References: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/27] libcamera: v4l2_device: Implement stream{On, Off} X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Feb 2019 06:08:25 -0000 From: Kieran Bingham Support starting and stopping a stream on a V4L2 device. Buffers must be queued before the stream is started. Signed-off-by: Kieran Bingham Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Signed-off-by: Niklas Söderlund --- src/libcamera/include/v4l2_device.h | 3 ++ src/libcamera/v4l2_device.cpp | 45 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 30a8f77d9772..988e646c5de1 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 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 134a468c4236..f9839fc715f4 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 */