From patchwork Fri Aug 21 14:46:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9345 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 C8201BE174 for ; Fri, 21 Aug 2020 14:46:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0F6276211C; Fri, 21 Aug 2020 16:46:13 +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="QgGzkQ6/"; 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 651AA61B4F for ; Fri, 21 Aug 2020 16:46:09 +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-type: content-transfer-encoding; s=s1; bh=7JPVmRK/eFw1gTrH2wmgD2gmPY/CFv59plWVYemxWxo=; b=QgGzkQ6/+cjdsgAP4hkc/qcj0SWKWF8dFqeKtJHt+PGZ0Dnu4/ICIpjlRV35s7FVqqBi RGDZog9/h+mRMUrTvsTKanmu91FYoXUUB28AD90ZnSUyopqeICe9ODwj6WQ+CxPR2yVZhZ 9JqzJwSwF5vJ18sAGCnLYJWLl+g8WW5aY= Received: by filterdrecv-p3iad2-86945d9569-tl4zj with SMTP id filterdrecv-p3iad2-86945d9569-tl4zj-17-5F3FDE2F-12C 2020-08-21 14:46:08.193268624 +0000 UTC m=+74588.801882622 Received: from mail.uajain.com (unknown) by ismtpd0002p1maa1.sendgrid.net (SG) with ESMTP id ujNN064dTr63HV9cIcE2cw Fri, 21 Aug 2020 14:46:07.760 +0000 (UTC) From: Umang Jain Date: Fri, 21 Aug 2020 14:46:08 +0000 (UTC) Message-Id: <20200821144601.67860-4-email@uajain.com> In-Reply-To: <20200821144601.67860-1-email@uajain.com> References: <20200821144601.67860-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcbjgBrPKwU6zsq5Nc1XDaVjFR/iFc4shZU4fvBEIs/r9zO4E6PsoypsFPhvx2SHHx4luUBFEua31z1hd3ImscIXsgjy9614Du3ef7lVPFJnLLiTE+xmnGJ5clYeUBkplB36W9sR4B1HrSr6odbCKKf3Fz1IHZWRK2AbchAGpSgdDLqyz5dHyKt/3uCj3xlVTCb4i/DYeMJhgeLb7YcBmD5w== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v4 3/5] android: camera_device: Make CameraDevice a shared object 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" CameraDevice needs to be wrapper into the std::shared_ptr instead of std::unique_ptr to enable refcounting. The refcounting will help us to support hotplug and hot-unplug CameraHalManager operations in the subsequent commit. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/android/camera_device.cpp | 7 +++++++ src/android/camera_device.h | 5 ++++- src/android/camera_hal_manager.cpp | 4 ++-- src/android/camera_hal_manager.h | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 3419236..550fcfa 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -233,6 +233,13 @@ CameraDevice::~CameraDevice() delete it.second; } +std::shared_ptr CameraDevice::create(unsigned int id, + const std::shared_ptr &cam) +{ + CameraDevice *camera = new CameraDevice(id, cam); + return std::shared_ptr(camera); +} + /* * Initialize the camera static information. * This method is called before the camera device is opened. diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 7be9e11..3e472c7 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -47,7 +47,8 @@ struct CameraStream { class CameraDevice : protected libcamera::Loggable { public: - CameraDevice(unsigned int id, const std::shared_ptr &camera); + static std::shared_ptr create(unsigned int id, + const std::shared_ptr &cam); ~CameraDevice(); int initialize(); @@ -72,6 +73,8 @@ protected: std::string logPrefix() const override; private: + CameraDevice(unsigned int id, const std::shared_ptr &camera); + struct Camera3RequestDescriptor { Camera3RequestDescriptor(unsigned int frameNumber, unsigned int numBuffers); diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 3d6d2b4..3a744af 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -64,12 +64,12 @@ int CameraHalManager::init() */ unsigned int index = 0; for (auto &cam : cameraManager_->cameras()) { - CameraDevice *camera = new CameraDevice(index, cam); + std::shared_ptr camera = CameraDevice::create(index, cam); ret = camera->initialize(); if (ret) continue; - cameras_.emplace_back(camera); + cameras_.emplace_back(std::move(camera)); ++index; } diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index a582f04..3e34d63 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -36,7 +36,7 @@ private: libcamera::CameraManager *cameraManager_; const camera_module_callbacks_t *callbacks_; - std::vector> cameras_; + std::vector> cameras_; }; #endif /* __ANDROID_CAMERA_MANAGER_H__ */