From patchwork Mon Dec 7 09:34:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10589 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 58FEDBDB1F for ; Mon, 7 Dec 2020 10:32:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C826F67E16; Mon, 7 Dec 2020 11:32:54 +0100 (CET) Received: from mslow2.mail.gandi.net (mslow2.mail.gandi.net [217.70.178.242]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6AD5467E12 for ; Mon, 7 Dec 2020 11:32:53 +0100 (CET) Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow2.mail.gandi.net (Postfix) with ESMTP id 6A9723B276E for ; Mon, 7 Dec 2020 09:34:32 +0000 (UTC) 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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 195C6FF808 for ; Mon, 7 Dec 2020 09:34:11 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 10:34:13 +0100 Message-Id: <20201207093413.5479-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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. 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 Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- v1 -> v2: - Stop the camera at the very beginning of the configureStreams() function --- src/android/camera_device.cpp | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.29.1 diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 675af5705055..dc711550546c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1210,6 +1210,13 @@ PixelFormat CameraDevice::toPixelFormat(int format) const */ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) { + /* Before any configuration attempt, stop the camera if it's running. */ + if (running_) { + worker_.stop(); + camera_->stop(); + running_ = false; + } + /* * Generate an empty configuration, and construct a StreamConfiguration * for each camera3_stream to add to it.