From patchwork Wed Mar 3 09:37:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 11473 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 3ABF9BD1F1 for ; Wed, 3 Mar 2021 09:38:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B572568A91; Wed, 3 Mar 2021 10:38:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CocsMYZU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 77D3068A69 for ; Wed, 3 Mar 2021 10:38:07 +0100 (CET) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ECE68ED; Wed, 3 Mar 2021 10:38:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614764287; bh=gwo4pu+gFpcnNYcGpmC47IFkhiavolL6ZAdeVVRF5Q0=; h=From:To:Cc:Subject:Date:From; b=CocsMYZUEk2E1/tczBnVXpskh9B1d7jy2nAPjPm6xNNHFeJvWYIvmwhrNrtLw1nZr htvTarWh58F+BSQAlhaJY/c8SwML0hgugE9fo/Xm9fvroy+YwAss6Hqxc5pCwky9/F nHml7roijl1Pn0Gc+JElR0/1/viufZfnietTvfVo= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Mar 2021 18:37:56 +0900 Message-Id: <20210303093756.490065-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: Add flag for external camera support 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" In the static metadata, we claim that we don't support external cameras, yet libcamera core defaults the camera location to external. In the HAL CameraDevice we defaulted external to front, but we hadn't handled CameraHalManager when counting the internal vs external cameras for hal_get_number_of_cameras(). To solve this, add a flag to hold if we have external camera support (hardcoded to false until we do), and add that to the condition in CameraHalManager when deciding whether a camera should be counted as internal or external. CameraDevice also uses this flag to decide on the default location. Signed-off-by: Paul Elder --- src/android/camera_device.cpp | 24 ++++++++++++++---------- src/android/camera_device.h | 8 ++++++-- src/android/camera_hal_manager.cpp | 11 +++++++---- src/android/camera_hal_manager.h | 2 ++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index ae01c362..bb33c922 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -311,9 +311,11 @@ CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() * back to the framework using the designated callbacks. */ -CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr &camera) +CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr &camera, + bool externalCameraSupport) : id_(id), running_(false), camera_(camera), staticMetadata_(nullptr), - facing_(CAMERA_FACING_FRONT), orientation_(0) + facing_(CAMERA_FACING_FRONT), orientation_(0), + externalCameraSupport_(externalCameraSupport) { camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); @@ -350,9 +352,10 @@ CameraDevice::~CameraDevice() } std::shared_ptr CameraDevice::create(unsigned int id, - const std::shared_ptr &cam) + const std::shared_ptr &cam, + bool externalCameraSupport) { - CameraDevice *camera = new CameraDevice(id, cam); + CameraDevice *camera = new CameraDevice(id, cam, externalCameraSupport); return std::shared_ptr(camera); } @@ -375,11 +378,10 @@ int CameraDevice::initialize() facing_ = CAMERA_FACING_BACK; break; case properties::CameraLocationExternal: - /* - * \todo Set this to EXTERNAL once we support - * HARDWARE_LEVEL_EXTERNAL - */ - facing_ = CAMERA_FACING_FRONT; + if (externalCameraSupport_) + facing_ = CAMERA_FACING_EXTERNAL; + else + facing_ = CAMERA_FACING_FRONT; break; } } @@ -1121,7 +1123,9 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, &croppingType, 1); /* Info static metadata. */ - uint8_t supportedHWLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; + uint8_t supportedHWLevel = externalCameraSupport_ ? + ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL : + ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, &supportedHWLevel, 1); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 4905958e..f96934db 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -33,7 +33,8 @@ class CameraDevice : protected libcamera::Loggable { public: static std::shared_ptr create(unsigned int id, - const std::shared_ptr &cam); + const std::shared_ptr &cam, + bool externalCameraSupport); ~CameraDevice(); int initialize(); @@ -66,7 +67,8 @@ protected: std::string logPrefix() const override; private: - CameraDevice(unsigned int id, const std::shared_ptr &camera); + CameraDevice(unsigned int id, const std::shared_ptr &camera, + bool externalCameraSupport); struct Camera3RequestDescriptor { Camera3RequestDescriptor(libcamera::Camera *camera, @@ -130,6 +132,8 @@ private: unsigned int maxJpegBufferSize_; CameraMetadata lastSettings_; + + const bool externalCameraSupport_; }; #endif /* __ANDROID_CAMERA_DEVICE_H__ */ diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 189eda2b..e4ca4c82 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -29,7 +29,8 @@ LOG_DECLARE_CATEGORY(HAL) */ CameraHalManager::CameraHalManager() - : cameraManager_(nullptr), callbacks_(nullptr), numInternalCameras_(0), + : cameraManager_(nullptr), callbacks_(nullptr), + externalCameraSupport_(false), numInternalCameras_(0), nextExternalCameraId_(firstExternalCameraId_) { } @@ -115,7 +116,8 @@ void CameraHalManager::cameraAdded(std::shared_ptr cam) * Now check if this is an external camera and assign * its id accordingly. */ - if (cameraLocation(cam.get()) == properties::CameraLocationExternal) { + if (cameraLocation(cam.get()) == properties::CameraLocationExternal && + externalCameraSupport_) { isCameraExternal = true; id = nextExternalCameraId_; } else { @@ -124,7 +126,8 @@ void CameraHalManager::cameraAdded(std::shared_ptr cam) } /* Create a CameraDevice instance to wrap the libcamera Camera. */ - std::shared_ptr camera = CameraDevice::create(id, std::move(cam)); + std::shared_ptr camera = + CameraDevice::create(id, std::move(cam), externalCameraSupport_); int ret = camera->initialize(); if (ret) { LOG(HAL, Error) << "Failed to initialize camera: " << cam->id(); @@ -134,7 +137,7 @@ void CameraHalManager::cameraAdded(std::shared_ptr cam) if (isCameraNew) { cameraIdsMap_.emplace(cam->id(), id); - if (isCameraExternal) + if (isCameraExternal && externalCameraSupport_) nextExternalCameraId_++; else numInternalCameras_++; diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index a91decc7..74dc6b3e 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -54,6 +54,8 @@ private: std::map cameraIdsMap_; Mutex mutex_; + const bool externalCameraSupport_; + unsigned int numInternalCameras_; unsigned int nextExternalCameraId_; };