From patchwork Wed Aug 5 15:14:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9224 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 64DBBBD86F for ; Wed, 5 Aug 2020 15:14:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A0320605C8; Wed, 5 Aug 2020 17:14:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="A3GSacnY"; dkim-atps=neutral Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EA0B060392 for ; Wed, 5 Aug 2020 17:14:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=VhMV+U4GddRuc6p3Gs2zRH6oPbOEximacaN90MzUup0=; b=A3GSacnYuW2LAAGaBry4Cc3fla4txoDoTGayaESj9ZX1UBsjZXu07uej743mO6RRRqmn s+xjAF5k+8iBKuxs8NsjBzTJZvjWyPOohNCmUEIngW8UYdjbbcptAsD9DWSnBnDFVn/0Gs /Tic5vEpy4BNZO14CiAdGBAWWFR0O+M6M= Received: by filterdrecv-p3mdw1-7ff865655c-v2mn4 with SMTP id filterdrecv-p3mdw1-7ff865655c-v2mn4-20-5F2ACCE3-53 2020-08-05 15:14:43.355425338 +0000 UTC m=+593902.314865933 Received: from mail.uajain.com (unknown) by ismtpd0004p1hnd1.sendgrid.net (SG) with ESMTP id HIWX1sRURUuFpQHMgSJtKw for ; Wed, 05 Aug 2020 15:14:43.055 +0000 (UTC) From: Umang Jain Date: Wed, 05 Aug 2020 15:14:43 +0000 (UTC) Message-Id: <20200805151437.157155-2-email@uajain.com> In-Reply-To: <20200805151437.157155-1-email@uajain.com> References: <20200805151437.157155-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcBLpXFhl3+P87RHKL8hWvbDKSmLgbXwLsI2/vRybnYQhtpZ/KUcQqhLGSjdYkhGTZFAAYeIqDmlyA4qRwSulFlKtMrf0POxZpGW6s5Bm2XdszttcJN802lE6RKdRe3svBqeLFh3ro1fLi/wQaSeK7Nax5kB+ZQ1806hVwrCmPAiy/PGrb/9PlkkqHjtLCJxcabapGcXrXLaANkIxVyOke5w== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH 1/2] android: camera_hal_manager: Set camera module callbacks 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" camera_module_callbacks are invoked to inform the framework about the events occuring module-wide. Allow to set these callbacks in camera_hal_manager as this will be used to integration camera hotplug support via camera_module_callbacks::camera_device_status_change in subsequent commit. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/android/camera3_hal.cpp | 2 +- src/android/camera_hal_manager.cpp | 7 +++++++ src/android/camera_hal_manager.h | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/android/camera3_hal.cpp b/src/android/camera3_hal.cpp index 716e36c..47c1aa9 100644 --- a/src/android/camera3_hal.cpp +++ b/src/android/camera3_hal.cpp @@ -34,7 +34,7 @@ static int hal_get_camera_info(int id, struct camera_info *info) static int hal_set_callbacks(const camera_module_callbacks_t *callbacks) { - return 0; + return cameraManager.setCallbacks(callbacks); } static int hal_open_legacy(const struct hw_module_t *module, const char *id, diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 02b6418..3ddcab5 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -120,3 +120,10 @@ int CameraHalManager::getCameraInfo(unsigned int id, struct camera_info *info) return 0; } + +int CameraHalManager::setCallbacks(const camera_module_callbacks_t *callbacks) +{ + callbacks_ = callbacks; + + return 0; +} diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 0619037..4345b1e 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -29,10 +30,12 @@ public: unsigned int numCameras() const; int getCameraInfo(unsigned int id, struct camera_info *info); + int setCallbacks(const camera_module_callbacks_t *callbacks); private: libcamera::CameraManager *cameraManager_; + const camera_module_callbacks_t *callbacks_; std::vector> cameras_; }; From patchwork Wed Aug 5 15:14:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9226 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 C89FCBD86F for ; Wed, 5 Aug 2020 15:14:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9310F605AE; Wed, 5 Aug 2020 17:14:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="IxljR5fS"; dkim-atps=neutral Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7403C60392 for ; Wed, 5 Aug 2020 17:14:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=vsmP+YwBsxogne+hm5MTk+A6/YWvfvAk7Tg9eZacMxg=; b=IxljR5fSm7sgB/yl9fWLNcYr4+2vlGja1H5rj6N/S76JISA473Dl4JFH/Wir2tn0J4O+ LdETvSNLNAI6awAbBtzCE4Koog7rHCY+i/DQhF0zCG7kMCqpWHeohmVWyO9y8d+nhXjMg8 +j5EOqVz6t8reRv2IK8I819DHxz8qo6Uw= Received: by filterdrecv-p3las1-559bd7b968-wk85c with SMTP id filterdrecv-p3las1-559bd7b968-wk85c-19-5F2ACCE4-7F 2020-08-05 15:14:44.744677232 +0000 UTC m=+593915.478323937 Received: from mail.uajain.com (unknown) by ismtpd0003p1maa1.sendgrid.net (SG) with ESMTP id MyAD5_rmSZyzyU9OTWX_2w for ; Wed, 05 Aug 2020 15:14:44.089 +0000 (UTC) From: Umang Jain Date: Wed, 05 Aug 2020 15:14:44 +0000 (UTC) Message-Id: <20200805151437.157155-3-email@uajain.com> In-Reply-To: <20200805151437.157155-1-email@uajain.com> References: <20200805151437.157155-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPc+mYHlj5pFD2lBxsaGLVsOCDqbDvgI+twqiPnkVPbvDJz4I3xKGOwPVaxLzK3xEsQWyiGUgWI/Vw+4+V3/Im8zNYu+tKuuyiFBgrwFs1U5Ooch9vtROwq/JYq9ZMyva4ThsfEBdHzfN8zVUe2XrG9M+//LPMPZm5bnYxfqMkWCnAjp65uHrfc0kYsD9SkyJVZc2pghy8JDwSSqsxN+520mA== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH 2/2] android: camera_hal_manager: Support camera hotplug 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" Extend the support for camera hotplug from libcamera's CameraManager to CameraHalManager. Use camera module callbacks to let the framework know about the hotplug events and change the status of cameras being being hotplugged or unplugged via camera_device_status_change(). Signed-off-by: Umang Jain --- src/android/camera_device.h | 1 + src/android/camera_hal_manager.cpp | 40 ++++++++++++++++++++++++++++-- src/android/camera_hal_manager.h | 3 +++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 4e5fb98..fa9706c 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -47,6 +47,7 @@ public: unsigned int id() const { return id_; } camera3_device_t *camera3Device() { return &camera3Device_; } + const libcamera::Camera *getCamera() { return camera_.get(); }; int facing() const { return facing_; } int orientation() const { return orientation_; } diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 3ddcab5..b498278 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -59,8 +59,6 @@ int CameraHalManager::init() /* * For each Camera registered in the system, a CameraDevice * gets created here to wraps a libcamera Camera instance. - * - * \todo Support camera hotplug. */ unsigned int index = 0; for (auto &cam : cameraManager_->cameras()) { @@ -73,6 +71,10 @@ int CameraHalManager::init() ++index; } + /* Support camera hotplug */ + cameraManager_->cameraAdded.connect(this, &CameraHalManager::cameraAdded); + cameraManager_->cameraRemoved.connect(this, &CameraHalManager::cameraRemoved); + return 0; } @@ -93,6 +95,40 @@ CameraDevice *CameraHalManager::open(unsigned int id, return camera; } +void CameraHalManager::cameraAdded(std::shared_ptr cam) +{ + unsigned int id = cameras_.size(); + CameraDevice *camera = new CameraDevice(id, cam); + int ret = camera->initialize(); + if (ret) { + LOG(HAL, Error) << "Failed to initialize camera: " << cam->name(); + return; + } + + cameras_.emplace_back(camera); + callbacks_->camera_device_status_change(callbacks_, id, + CAMERA_DEVICE_STATUS_PRESENT); + LOG(HAL, Debug) << "Camera " << cam->name() << " ID:" << id + << " added and initialized successfully."; +} + +void CameraHalManager::cameraRemoved(std::shared_ptr cam) +{ + auto iter = std::find_if(cameras_.begin(), cameras_.end(), + [cam](std::unique_ptr &camera) { + return cam.get() == camera->getCamera(); + }); + if (iter == cameras_.end()) + return; + + unsigned int id = (*iter)->id(); + callbacks_->camera_device_status_change(callbacks_, id, + CAMERA_DEVICE_STATUS_NOT_PRESENT); + cameras_.erase(iter); + LOG(HAL, Debug) << "Camera " << cam->name() << " ID:" << id + << " removed successfully."; +} + unsigned int CameraHalManager::numCameras() const { return cameraManager_->cameras().size(); diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 4345b1e..52ab9e2 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -33,6 +33,9 @@ public: int setCallbacks(const camera_module_callbacks_t *callbacks); private: + void cameraAdded(std::shared_ptr cam); + void cameraRemoved(std::shared_ptr cam); + libcamera::CameraManager *cameraManager_; const camera_module_callbacks_t *callbacks_;