[{"id":14533,"web_url":"https://patchwork.libcamera.org/comment/14533/","msgid":"<X/00ECN6xQCDRqah@pendragon.ideasonboard.com>","date":"2021-01-12T05:30:56","subject":"Re: [libcamera-devel] [PATCH v2 1/2] libcamera: v4l2_videodevice:\n\tTrack streaming state","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang and Kieran,\n\nThank you for the patch.\n\nOn Tue, Jan 12, 2021 at 10:21:39AM +0530, Umang Jain wrote:\n> From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> Track the state of streamon/streamoff calls to simplify error paths.\n> \n> Ensuring that streamOff() can be called on non-streaming streams\n> facilitates simpler error code paths, where a set of devices can all\n> call streamOff regardless of their initialisation state.\n>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Signed-off-by: Umang Jain <email@uajain.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  2 ++\n>  src/libcamera/v4l2_videodevice.cpp            | 12 +++++++++++-\n>  2 files changed, 13 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 529ca0e3..626dfbcd 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -249,6 +249,8 @@ private:\n>  \tstd::map<unsigned int, FrameBuffer *> queuedBuffers_;\n>  \n>  \tEventNotifier *fdBufferNotifier_;\n> +\n> +\tbool streaming_;\n>  };\n>  \n>  class V4L2M2MDevice\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index baf683d6..a9509bff 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -481,7 +481,8 @@ const std::string V4L2DeviceFormat::toString() const\n>   * \\param[in] deviceNode The file-system path to the video device node\n>   */\n>  V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n> -\t: V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr)\n> +\t: V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr),\n> +\t  streaming_(false)\n>  {\n>  \t/*\n>  \t * We default to an MMAP based CAPTURE video device, however this will\n> @@ -1554,6 +1555,8 @@ int V4L2VideoDevice::streamOn()\n>  \t\treturn ret;\n>  \t}\n>  \n> +\tstreaming_ = true;\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -1565,12 +1568,18 @@ int V4L2VideoDevice::streamOn()\n>   * and the bufferReady signal is emitted for them. The order in which those\n>   * buffers are dequeued is not specified.\n>   *\n> + * This will be a no-op if the stream is not started in the first place and\n> + * has no queued buffers.\n> + *\n>   * \\return 0 on success or a negative error code otherwise\n>   */\n>  int V4L2VideoDevice::streamOff()\n>  {\n>  \tint ret;\n>  \n> +\tif (!streaming_ && queuedBuffers_.empty())\n> +\t\treturn 0;\n> +\n>  \tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n>  \tif (ret < 0) {\n>  \t\tLOG(V4L2, Error)\n> @@ -1588,6 +1597,7 @@ int V4L2VideoDevice::streamOff()\n>  \n>  \tqueuedBuffers_.clear();\n>  \tfdBufferNotifier_->setEnabled(false);\n> +\tstreaming_ = false;\n>  \n>  \treturn 0;\n>  }","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5D6FDBD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Jan 2021 05:31:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CFB20680CA;\n\tTue, 12 Jan 2021 06:31:11 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8965B60523\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Jan 2021 06:31:10 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0AE0B3E;\n\tTue, 12 Jan 2021 06:31:09 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tPbofFaa\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1610429470;\n\tbh=YY42dR9BUjUuJTXphChdzpwXbC5zWwzcMSgi+s3jGbM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tPbofFaaK5vXjZGXTm3VYGOckigtlrzUZZrXbPCEAPsm6Sld70ODgu5mWuFSNm84l\n\tlt2V8X2P50g144K/qG1okErWNv0thjlc9RnGUCxe5K+m19TzEAIdcOkqbMau3Y9sNJ\n\t+z3tzyNS/J8hQCTOdb899NHwJBqYZC3wszdTPg1A=","Date":"Tue, 12 Jan 2021 07:30:56 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <email@uajain.com>","Message-ID":"<X/00ECN6xQCDRqah@pendragon.ideasonboard.com>","References":"<20210112045140.10979-1-email@uajain.com>\n\t<20210112045140.10979-2-email@uajain.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210112045140.10979-2-email@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/2] libcamera: v4l2_videodevice:\n\tTrack streaming state","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]