[{"id":22472,"web_url":"https://patchwork.libcamera.org/comment/22472/","msgid":"<YkDu/9ThNj4aHPWR@pendragon.ideasonboard.com>","date":"2022-03-27T23:10:55","subject":"Re: [libcamera-devel] [PATCH v5 5/8] libcamera: v4l2_videodevice:\n\tBetter tracking of the device state","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Naush,\n\nThank you for the patch.\n\nOn Fri, Mar 25, 2022 at 09:09:00AM +0000, Naushir Patuck via libcamera-devel wrote:\n> Replace the existing streaming_ state variable with an enum to track the\n> following three state: Streaming, Stopping, and Stopped. The alternate states\n> will be used in a subsequent commit.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  3 ++-\n>  src/libcamera/v4l2_videodevice.cpp            | 10 ++++++----\n>  2 files changed, 8 insertions(+), 5 deletions(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 2d2ccc477c91..32e022543385 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -258,7 +258,8 @@ private:\n>  \n>  \tEventNotifier *fdBufferNotifier_;\n>  \n> -\tbool streaming_;\n> +\tenum class State { Streaming, Stopping, Stopped };\n\n\tenum class State {\n\t\tStreaming,\n\t\tStopping,\n\t\tStopped,\n\t};\n\nand this should go right after LIBCAMERA_DISABLE_COPY() as we declare\ntypes before functions and variables.\n\nWith this,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tState state_;\n>  };\n>  \n>  class V4L2M2MDevice\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 5f36ee20710d..9cea6a608660 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -507,7 +507,7 @@ const std::string V4L2DeviceFormat::toString() const\n>   */\n>  V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n>  \t: V4L2Device(deviceNode), formatInfo_(nullptr), cache_(nullptr),\n> -\t  fdBufferNotifier_(nullptr), streaming_(false)\n> +\t  fdBufferNotifier_(nullptr), state_(State::Stopped)\n>  {\n>  \t/*\n>  \t * We default to an MMAP based CAPTURE video device, however this will\n> @@ -1796,7 +1796,7 @@ int V4L2VideoDevice::streamOn()\n>  \t\treturn ret;\n>  \t}\n>  \n> -\tstreaming_ = true;\n> +\tstate_ = State::Streaming;\n>  \n>  \treturn 0;\n>  }\n> @@ -1818,7 +1818,7 @@ int V4L2VideoDevice::streamOff()\n>  {\n>  \tint ret;\n>  \n> -\tif (!streaming_ && queuedBuffers_.empty())\n> +\tif (state_ != State::Streaming && queuedBuffers_.empty())\n>  \t\treturn 0;\n>  \n>  \tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n> @@ -1828,6 +1828,8 @@ int V4L2VideoDevice::streamOff()\n>  \t\treturn ret;\n>  \t}\n>  \n> +\tstate_ = State::Stopping;\n> +\n>  \t/* Send back all queued buffers. */\n>  \tfor (auto it : queuedBuffers_) {\n>  \t\tFrameBuffer *buffer = it.second;\n> @@ -1838,7 +1840,7 @@ int V4L2VideoDevice::streamOff()\n>  \n>  \tqueuedBuffers_.clear();\n>  \tfdBufferNotifier_->setEnabled(false);\n> -\tstreaming_ = false;\n> +\tstate_ = State::Stopped;\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 A7C07C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 27 Mar 2022 23:10:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65ED665631;\n\tMon, 28 Mar 2022 01:10:58 +0200 (CEST)","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 399CF600B0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Mar 2022 01:10:57 +0200 (CEST)","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 C6F792F7;\n\tMon, 28 Mar 2022 01:10:56 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648422658;\n\tbh=TP27VQeL9sib/jqSEGF7vQSDte50n3ZKB6VXN8t0Fpk=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=DXVQ2vJTZkgioiETevImHWt6M/t53xPe2GpbplatjiONl/RBT+QQ/QgLUdOccg1pM\n\tPpT4sIg8OmwVJS6tt9NR0V6eFInLI7f+eP9SJooEQMTXMjzA9oRmwSKugB8PyGCqEE\n\tMGm3lbcr4B0ftRKgj2O/c5AItPdSoo0CAkdDkESgFrM0QG72xZ5kKPYhGQ2Qg9QOxu\n\tJm4Kkoy+Cj8+NGTMJR6ZdJ3AZHmZjMRrZ6IaJ4kX/ga2vb8Gm4WLxdXqVvG5hflWeS\n\tRdtyrZH3Xb8dIMmw0aKnUq8HQvKgIGF2Xa3Z1KFZAy3RhS+ojdQ/ysORaQg77Mezj6\n\tWK9s9tZSyJgrQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648422657;\n\tbh=TP27VQeL9sib/jqSEGF7vQSDte50n3ZKB6VXN8t0Fpk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=CF9UpCd0JVCl1fYW2p9OX5LlQAjWBYXNR9Gt6cgY/A8bizJOTHS4ukXFnCfgafSkD\n\tsJK4M7aiBnRrRz6ZsFc6NPgmE0K5qkPxl+d5NGHn0hlT/OJ3CgyjFGGgtfSypd3e52\n\tI6b4uW18vm8PUa4ZRUg94t/9BC/9CBi5xME+QF8I="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"CF9UpCd0\"; dkim-atps=neutral","Date":"Mon, 28 Mar 2022 02:10:55 +0300","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<YkDu/9ThNj4aHPWR@pendragon.ideasonboard.com>","References":"<20220325090903.880311-1-naush@raspberrypi.com>\n\t<20220325090903.880311-6-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220325090903.880311-6-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v5 5/8] libcamera: v4l2_videodevice:\n\tBetter tracking of the device 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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]