From patchwork Mon Aug 17 20:26:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9333 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 7819EBD87F for ; Mon, 17 Aug 2020 20:26:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6B94A619C0; Mon, 17 Aug 2020 22:26:43 +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="cp50GDrd"; 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 67C0661815 for ; Mon, 17 Aug 2020 22:26:40 +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=FXhILTUfxT0BFUBPIZ20p2fiVt6QYftLfIfgckevdHQ=; b=cp50GDrdPf/uPB/JhjKak/q57OCcTZtsnRSjvBc6C2c1Iz9LOGLa+G9ftWYEdNMT+/em +UvPmZNJIoiu/OR9Us6L5JFHu8IftSXKB3KxrsE+KVPWybLMgf2gSTQYSxRF15ORYxHqYD viEXlVw8buii8rTFiNjm19C+ZzbRkJNAc= Received: by filterdrecv-p3iad2-5c98798b7-zrzkk with SMTP id filterdrecv-p3iad2-5c98798b7-zrzkk-19-5F3AE7FE-53 2020-08-17 20:26:38.938016394 +0000 UTC m=+359824.402835252 Received: from mail.uajain.com (unknown) by ismtpd0002p1maa1.sendgrid.net (SG) with ESMTP id H_tfatOXSeKXc3rObZtlkw for ; Mon, 17 Aug 2020 20:26:38.202 +0000 (UTC) From: Umang Jain Date: Mon, 17 Aug 2020 20:26:39 +0000 (UTC) Message-Id: <20200817202629.4277-4-email@uajain.com> In-Reply-To: <20200817202629.4277-1-email@uajain.com> References: <20200817202629.4277-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcBLpXFhl3+P87RHKL8hWvbIAmAXRqUBwWps8sj3eeReFPzR4KyTXBMlaA8eMkSd1eF+xxDt70e6FDslqNdafPQle2hNeTap9WDXERFDRrTQHe9ZQ3W8ayVcVSPZrRuDnpzjP4zHPlXEeXS96hdv25e1FXEG7TOI0TIUcQjCLmzL+h6menKj1manAhsAj4miaabBfNo0kAvJoHXwVuhOcYZA== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v3 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 | 15 +++++++++++++++ src/android/camera_device.h | 7 +++++-- src/android/camera_hal_manager.cpp | 4 ++-- src/android/camera_hal_manager.h | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index d918350..a79bb69 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -233,6 +233,21 @@ CameraDevice::~CameraDevice() delete it.second; } +std::shared_ptr CameraDevice::create(unsigned int id, + const std::shared_ptr &cam) +{ + struct Deleter : std::default_delete { + void operator()(CameraDevice *camera) + { + delete camera; + } + }; + + CameraDevice *camera = new CameraDevice(id, cam); + + return std::shared_ptr(camera, Deleter()); +} + /* * 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..b149043 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -47,8 +47,8 @@ struct CameraStream { class CameraDevice : protected libcamera::Loggable { public: - CameraDevice(unsigned int id, const std::shared_ptr &camera); - ~CameraDevice(); + static std::shared_ptr create(unsigned int id, + const std::shared_ptr &cam); int initialize(); @@ -72,6 +72,9 @@ protected: std::string logPrefix() const override; private: + CameraDevice(unsigned int id, const std::shared_ptr &camera); + ~CameraDevice(); + 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__ */