From patchwork Fri Dec 4 14:39:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10558 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 C56D8BE176 for ; Fri, 4 Dec 2020 14:39:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F48F635DE; Fri, 4 Dec 2020 15:39:54 +0100 (CET) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 318CF635D0 for ; Fri, 4 Dec 2020 15:39:53 +0100 (CET) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id D7111C0006 for ; Fri, 4 Dec 2020 14:39:52 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 4 Dec 2020 15:39:55 +0100 Message-Id: <20201204143955.294320-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: camera_device: Stop camera when re-configuring it 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 Android camera device HAL3 specification does not require a camera to go through any explicit close() call between configurations. It is legit for a camera to be configured, a number of requests processed and the re-configured again without any explicit stop. The libcamera Android camera HAL starts the Camera at the first handled request, and only stops it at camera close time. This mean, that two camera configuration attempts part of the same streaming session are only interleaved by capture requests handling. The libcamera::Camera state machine requires the Camera to be stopped, before any configuration take place, and this currently doesn't happen in the camera HAL CameraDevice class. Fix this by stopping the camera and the associated worker thread if a configuration attempt is performed while the Camera is in running state. This patch fixes cros_camera_test: Camera3PreviewTest/Camera3SinglePreviewTest.Camera3BasicPreviewTest/0 Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- Alternatively, the camera can be stopped at the very beginning of the configureStream() function. But in that case the camera gets stopped even if the configuration attempt fails (ie at validation time). As both behaviour seems to be compliant with what Android expects, I decided to stop the camera only if the configuration is valid. --- src/android/camera_device.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.29.1 diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 675af5705055..2500994e2f6a 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1341,8 +1341,15 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) /* * Once the CameraConfiguration has been adjusted/validated - * it can be applied to the camera. + * it can be applied to the camera, which has to be stopped if + * in running state. */ + if (running_) { + worker_.stop(); + camera_->stop(); + running_ = false; + } + int ret = camera_->configure(config_.get()); if (ret) { LOG(HAL, Error) << "Failed to configure camera '"