From patchwork Mon May 10 10:52:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12244 X-Patchwork-Delegate: jacopo@jmondi.org 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 AB0E4BF835 for ; Mon, 10 May 2021 10:52:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 31BB168926; Mon, 10 May 2021 12:52:01 +0200 (CEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E74C6891C for ; Mon, 10 May 2021 12:51:59 +0200 (CEST) X-Originating-IP: 82.59.136.116 Received: from uno.homenet.telecomitalia.it (host-82-59-136-116.retail.telecomitalia.it [82.59.136.116]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 878A8E01E6; Mon, 10 May 2021 10:51:58 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 10 May 2021 12:52:31 +0200 Message-Id: <20210510105235.28319-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510105235.28319-1-jacopo@jmondi.org> References: <20210510105235.28319-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/8] android: camera_device: Replace running_ with CameraState 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" The CameraDevice class maintains the camera state in the 'running_' boolean flag to check if the camera has to be started at the first received process_capture_request() call which happens after the camera had been stopped. So far this was correct, as the operations that change the camera could only start or stop the camera, so a simple boolean flag was enough. To prepare to handle the flush() operation that will introduce a new 'flushing' state, replace the simple plain boolean flag with an enumeration of values that define the CameraState. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/android/camera_device.cpp | 10 +++++----- src/android/camera_device.h | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index d8b7e62ef896..bdb5c8ed52aa 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -401,7 +401,7 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( */ CameraDevice::CameraDevice(unsigned int id, std::shared_ptr camera) - : id_(id), running_(false), camera_(std::move(camera)), + : id_(id), state_(CameraStopped), camera_(std::move(camera)), facing_(CAMERA_FACING_FRONT), orientation_(0) { camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); @@ -757,14 +757,14 @@ void CameraDevice::close() void CameraDevice::stop() { - if (!running_) + if (state_ == CameraStopped) return; worker_.stop(); camera_->stop(); descriptors_.clear(); - running_ = false; + state_ = CameraStopped; } void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) @@ -1913,7 +1913,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques return -EINVAL; /* Start the camera if that's the first request we handle. */ - if (!running_) { + if (state_ == CameraStopped) { worker_.start(); int ret = camera_->start(); @@ -1922,7 +1922,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques return ret; } - running_ = true; + state_ = CameraRunning; } /* diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 8d5da8bc59e1..30b364decaab 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -88,6 +88,11 @@ private: int androidFormat; }; + enum State { + CameraStopped, + CameraRunning, + }; + void stop(); int initializeStreamConfigurations(); @@ -115,7 +120,8 @@ private: CameraWorker worker_; - bool running_; + State state_; + std::shared_ptr camera_; std::unique_ptr config_;