From patchwork Tue Jul 21 11:26:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 8903 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 16D70C0109 for ; Tue, 21 Jul 2020 11:23:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9883360832; Tue, 21 Jul 2020 13:23:00 +0200 (CEST) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED1CF60496 for ; Tue, 21 Jul 2020 13:22:59 +0200 (CEST) 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 relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 70F8020005; Tue, 21 Jul 2020 11:22:59 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Jul 2020 13:26:33 +0200 Message-Id: <20200721112633.103016-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: camera_hal_manager: Fail on no cameras 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 CameraHalManager initialization tries to start the libcamera::CameraManager which enumerate the registered cameras. When initialization is called too early during system boot, it might happen that the media graphs are still being registered to user-space preventing any pipeline handler to match and register cameras. If that happens, the CameraHalManager silently accepts that no cameras are available in the system, reporting that information to the camera stack: cros_camera_service[2054]: (5) StartOnThread(): Camera module "libcamera camera HALv3 module" has 0 built-in camera(s) cros_camera_service[2054]: (5) StartOnThread(): SuperHAL started with 1 modules and 0 built-in cameras CameraProviderManager: Camera provider legacy/0 ready with 0 camera devices Fix this by returning an error code if no camera is registered in the system at the time CameraHalManager::init() is called. The camera framework then tries to re-load the HAL module later in time, hopefully after the media device dependencies have been registered: 2020-07-21T12:26:37.903456+02:00 INFO cros_camera_service[2054]: (5) StartOnThread(): Camera module "libcamera camera HALv3 module" has 0 built-in camera(s) 2020-07-21T12:26:37.903521+02:00 INFO cros_camera_service[2054]: (5) StartOnThread(): SuperHAL started with 1 modules and 0 built-in cameras .... 2020-07-21T12:30:36.662877+02:00 INFO cros_camera_service[5908]: (5910) StartOnThread(): Camera module "libcamera camera HALv3 module" has 2 built-in camera(s) 2020-07-21T12:30:36.663196+02:00 INFO cros_camera_service[5908]: (5910) StartOnThread(): SuperHAL started with 1 modules and 2 built-in cameras Return -ENODEV as according to camera_common.h specification is the only supported error code. The CrOS HAL adapter does not distinguish between that and other negative values, so it does not really make a difference. Signed-off-by: Jacopo Mondi --- src/android/camera_hal_manager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 02b6418fb36d..e967d210e547 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -73,6 +73,17 @@ int CameraHalManager::init() ++index; } + /* + * If no pipeline has registered cameras, defer initialization to give + * time to media devices to register to user-space. + */ + if (index == 0) { + LOG(HAL, Debug) << "Defer CameraHALManager initialization"; + delete cameraManager_; + cameraManager_ = nullptr; + return -ENODEV; + } + return 0; }