[{"id":17137,"web_url":"https://patchwork.libcamera.org/comment/17137/","msgid":"<YKqY0VBCgqhbph0D@pendragon.ideasonboard.com>","date":"2021-05-23T18:02:57","subject":"Re: [libcamera-devel] [PATCH v3 4/8] android: camera_device:\n\tReplace running_ with CameraState","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Fri, May 21, 2021 at 05:42:23PM +0200, Jacopo Mondi wrote:\n> The CameraDevice class maintains the camera state in the 'running_'\n> boolean flag to check if the camera has to be started at the first\n> received process_capture_request() call which happens after the camera\n> had been stopped.\n> \n> So far this was correct, as the operations that change the camera\n> could only start or stop the camera, so a simple boolean flag\n> was enough.\n> \n> To prepare to handle the flush() operation that will introduce a new\n> 'flushing' state, replace the simple plain boolean flag with an\n> enumeration of values that define the CameraState.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>\n> ---\n>  src/android/camera_device.cpp | 10 +++++-----\n>  src/android/camera_device.h   |  8 +++++++-\n>  2 files changed, 12 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index bd96b355ea92..cf0e5e459213 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -402,7 +402,7 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor(\n>   */\n>  \n>  CameraDevice::CameraDevice(unsigned int id, std::shared_ptr<Camera> camera)\n> -\t: id_(id), running_(false), camera_(std::move(camera)),\n> +\t: id_(id), state_(CameraStopped), camera_(std::move(camera)),\n>  \t  facing_(CAMERA_FACING_FRONT), orientation_(0)\n>  {\n>  \tcamera_->requestCompleted.connect(this, &CameraDevice::requestComplete);\n> @@ -758,14 +758,14 @@ void CameraDevice::close()\n>  \n>  void CameraDevice::stop()\n>  {\n> -\tif (!running_)\n> +\tif (state_ == CameraStopped)\n>  \t\treturn;\n>  \n>  \tworker_.stop();\n>  \tcamera_->stop();\n>  \n>  \tdescriptors_.clear();\n> -\trunning_ = false;\n> +\tstate_ = CameraStopped;\n>  }\n>  \n>  void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks)\n> @@ -1844,7 +1844,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n>  \t\treturn -EINVAL;\n>  \n>  \t/* Start the camera if that's the first request we handle. */\n> -\tif (!running_) {\n> +\tif (state_ == CameraStopped) {\n>  \t\tworker_.start();\n>  \n>  \t\tint ret = camera_->start();\n> @@ -1853,7 +1853,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n>  \t\t\treturn ret;\n>  \t\t}\n>  \n> -\t\trunning_ = true;\n> +\t\tstate_ = CameraRunning;\n>  \t}\n>  \n>  \t/*\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index a34e8a2cd900..995b423c6deb 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -88,6 +88,11 @@ private:\n>  \t\tint androidFormat;\n>  \t};\n>  \n> +\tenum State {\n> +\t\tCameraStopped,\n> +\t\tCameraRunning,\n> +\t};\n\nThis is a topic that will require revisiting enums globally, but I think\nthe code would be clearer with\n\n\tenum class State {\n\t\tStopped,\n\t\tRunning,\n\t};\n\nYou would then need to use State::Stopped and State::Running explicitly\nabove. It states explicitly the value is a camera state (compared to\nCameraRunning and CameraStopped that do so implicitly only), and avoids\nusing incorrect values for state_ by mistake as the compiler would catch\nthat with enum class. What do you think ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n>  \tvoid stop();\n>  \n>  \tint initializeStreamConfigurations();\n> @@ -114,7 +119,8 @@ private:\n>  \n>  \tCameraWorker worker_;\n>  \n> -\tbool running_;\n> +\tState state_;\n> +\n>  \tstd::shared_ptr<libcamera::Camera> camera_;\n>  \tstd::unique_ptr<libcamera::CameraConfiguration> config_;\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 1B606C3201\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 23 May 2021 18:03:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9CE976891B;\n\tSun, 23 May 2021 20:03:02 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E7D29601A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 May 2021 20:03:01 +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 4A2D42A8;\n\tSun, 23 May 2021 20:03:01 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"arg7mhW8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1621792981;\n\tbh=n5bzRsdMpswg0BduWbEsKeTd0nLLlFfMs/S8QW/IbGg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=arg7mhW8W3Z3zUDK8XjeDr/FtdRWkZqx8DpxXOctrKbEDhXLtNGLoxmHMx+zi5+xP\n\tvDZMHW/YTkf5guluJzcOEXuWaLZHRGZ31ImtXcQbUOPxAxpxqTm69C/ksF1MHVghog\n\tSkSP3RnxFoXIvenQMWQE9btk5NWYg/7Jm6MDR8zw=","Date":"Sun, 23 May 2021 21:02:57 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YKqY0VBCgqhbph0D@pendragon.ideasonboard.com>","References":"<20210521154227.60186-1-jacopo@jmondi.org>\n\t<20210521154227.60186-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20210521154227.60186-5-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v3 4/8] android: camera_device:\n\tReplace running_ with CameraState","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","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]