From patchwork Fri Oct 25 14:13:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 2221 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3294F61378 for ; Fri, 25 Oct 2019 16:13:32 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8421E33A; Fri, 25 Oct 2019 16:13:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572012811; bh=8aRG3VqWJyMocYHHYjy5Yk5xUgFS8XOIcNnu6whvxy4=; h=From:To:Cc:Subject:Date:From; b=FKoo6zQfB1zOIzzh9VXy8GqxL57E/p/fiWVqRGLXkysbmU0g+fsesSCXGcA14fYOy 7bvgetiQgDVg579e9K5YlrFSMnaR3xiZdqVadH5AE3cE87AwT6VT20ynlA+UjS1AW3 XJnD6piIA//Ow0saxvuVxBNSemWCFE13x+FSyibs= From: Kieran Bingham To: LibCamera Devel Date: Fri, 25 Oct 2019 15:13:27 +0100 Message-Id: <20191025141327.2803-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Track streaming state X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Oct 2019 14:13:32 -0000 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. Acked-by: Laurent Pinchart Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Since RFC: - Rebased to master. src/libcamera/include/v4l2_videodevice.h | 2 ++ src/libcamera/v4l2_videodevice.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 4b8cf9394eb9..caf36bf9c1aa 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -187,6 +187,8 @@ private: std::map queuedBuffers_; EventNotifier *fdEvent_; + + bool streaming_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 208ab54199b1..c0b3a79f76da 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -272,7 +272,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), bufferPool_(nullptr), fdEvent_(nullptr) + : V4L2Device(deviceNode), bufferPool_(nullptr), fdEvent_(nullptr), + streaming_(false) { /* * We default to an MMAP based CAPTURE video device, however this will @@ -1173,6 +1174,8 @@ int V4L2VideoDevice::streamOn() return ret; } + streaming_ = true; + return 0; } @@ -1190,6 +1193,9 @@ int V4L2VideoDevice::streamOff() { int ret; + if (!streaming_) + return 0; + ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); if (ret < 0) { LOG(V4L2, Error) @@ -1210,6 +1216,8 @@ int V4L2VideoDevice::streamOff() queuedBuffers_.clear(); fdEvent_->setEnabled(false); + streaming_ = false; + return 0; }