From patchwork Tue Jan 12 04:51:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 10849 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 05E90BD80C for ; Tue, 12 Jan 2021 04:51:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C2ABD680C8; Tue, 12 Jan 2021 05:51:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="iLr+3Wl6"; dkim-atps=neutral Received: from mail.uajain.com (static.126.159.217.95.clients.your-server.de [95.217.159.126]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D0C860523 for ; Tue, 12 Jan 2021 05:51:48 +0100 (CET) From: Umang Jain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail; t=1610427107; bh=UWgzg2JrMvee+s7TpRi3IE6dUgfl0XwSoy7hTz45BPM=; h=From:To:Cc:Subject:In-Reply-To:References; b=iLr+3Wl647mP/+AcqFqrkJJkfYvbzgTlwSSH9G5y2Kw7OgkLr1MyHd64RCGTWHU3N ra6daNwjqnNNWZ3M10OAkDpNrD9c+92ByCgV6HU18Yl9MDrat5whgvgFc2fkdSsl54 0OrfzB5XP+HZEVpJ/L1PvobFI2vXwH8kJTe+IkW2p8Et/P5o1Q2YOJkn/G56KrP+jN xqzpZBVarPzWBLOl9ooJrplfuW8mvdRnkMhdow9qIduj2/seCeZVfHpO2XFPJzsQhD V1TkC0+eyftM9K/Qv3Xy3SsAXaZx4ZYJ/vmdxYvzndKLMGjMfdfaRNklXLBPb+pTvy IEtkds2u3tZlw== To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Jan 2021 10:21:39 +0530 Message-Id: <20210112045140.10979-2-email@uajain.com> In-Reply-To: <20210112045140.10979-1-email@uajain.com> References: <20210112045140.10979-1-email@uajain.com> Mime-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Kieran Bingham 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 Signed-off-by: Umang Jain Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 2 ++ src/libcamera/v4l2_videodevice.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 529ca0e3..626dfbcd 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -249,6 +249,8 @@ private: std::map queuedBuffers_; EventNotifier *fdBufferNotifier_; + + bool streaming_; }; class V4L2M2MDevice 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; } From patchwork Tue Jan 12 04:51:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 10850 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 54EFBBD80C for ; Tue, 12 Jan 2021 04:51:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2599D6054E; Tue, 12 Jan 2021 05:51:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="Xf3AvxHh"; dkim-atps=neutral Received: from mail.uajain.com (static.126.159.217.95.clients.your-server.de [95.217.159.126]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 490506054E for ; Tue, 12 Jan 2021 05:51:50 +0100 (CET) From: Umang Jain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail; t=1610427109; bh=yZW2MmJhm1SRNzcqFX+Be/eDcmIZUiLB573/Jnrb3z8=; h=From:To:Cc:Subject:In-Reply-To:References; b=Xf3AvxHhP3OkBAXAb/fwrqWTVko25TirTp6XnN9uBWgNafZn8WK9n3U7bUztg2Xqv SBPj2+CZ8NSiY4JFLl11a+qOjR3qyrbDhtA6VC2YFjO1nwbgGX/+PQiyzu9VRBha4O atD/AImrB8E9jqUo0nVORUmNUfqjYE525u4ZzGcoXJmghLb4/bthDpi5goBYyIWoWY Q6U0oRvx0nXui+OrPcokiddsYa+piaqx9MlCjNUOgA8P6P8GXM1GJOyL4vZ9fG7hJv A1kYugHxvvb+hn/1tzlXhlhe8NaLLBOU8seqmxH6nHvmm9stBD5DqYk4qRMpT1VP7g dcmpwjimYPPaQ== To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Jan 2021 10:21:40 +0530 Message-Id: <20210112045140.10979-3-email@uajain.com> In-Reply-To: <20210112045140.10979-1-email@uajain.com> References: <20210112045140.10979-1-email@uajain.com> Mime-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] libcamera: pipelines: ipu3: Simplify error bail out path on start() 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" On the bail out path, always ensure that ImgU and CIO2 are stopped before freeing the buffers. V4L2VideoDevice class guarantees that calling stop() without having to call start() is harmless, hence use this guarantee to simplify error paths. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index f1151733..73304ea7 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -617,15 +617,14 @@ int PipelineHandlerIPU3::start(Camera *camera, [[maybe_unused]] ControlList *con goto error; ret = imgu->start(); - if (ret) { - imgu->stop(); - cio2->stop(); + if (ret) goto error; - } return 0; error: + imgu->stop(); + cio2->stop(); freeBuffers(camera); LOG(IPU3, Error) << "Failed to start camera " << camera->id();