From patchwork Wed Mar 24 07:07:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11677 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 8827BC32E7 for ; Wed, 24 Mar 2021 07:08:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3D04568D6F; Wed, 24 Mar 2021 08:08:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gATmTxVG"; dkim-atps=neutral Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 59CA668D62 for ; Wed, 24 Mar 2021 08:08:12 +0100 (CET) Received: by mail-pf1-x436.google.com with SMTP id y200so16653789pfb.5 for ; Wed, 24 Mar 2021 00:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FBIId1IlESikLmSIrXc64sNJ/ca/awir3F5edcNGkIU=; b=gATmTxVGog/JFGV2sXXRidCil2jEJP3VP2153GVVnN+Q17ZsbKdi+Kf7yjs9KqNsvX 5PB1vlgtzSfPifuAbFKIoflZDGxjwUl+0Yk99Afrtbb8VXYTJJ+c8MbqeqR0+bq9re1K nwTPYjQp8FvBHLxCs5VS35izCTZX2tJ3koEPA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FBIId1IlESikLmSIrXc64sNJ/ca/awir3F5edcNGkIU=; b=CRvOfHm7c726O/YAO8pa/66cXWSECArY1Hk2X7FKy1tOm4NKPQNYpj9j/kRFmLRq8U 07t/V82TI9kryR8n/yHMLA5PqI9hHSNc/gWcqx0VEx7EX94KgELDYb1h/Tdb1G2RjeQl 5sa0uQSXHpE2Aa6dBGnBXAgD7iPzoYH5L91w5uGx6vx3/kfabfa7EalmVFdp9HRP6W4w Dg8ttmmVyq+OMsAN5uoXHsllAmsl9rOmOeUVwiek59aRZX+bPU08iuwsma8xKQPet4Z7 OYxuQhInDS6fVws+opHJ3uNNGuudUjmznBdnYRFjNrlIA4HZiAQm0KaA7Rp4rYHAGZKY OwLw== X-Gm-Message-State: AOAM533vE7D/zwaI1jr0X6ymrk4XcIBON/lmLMeu1OJly7/rGxG0ZpEN CA7A3dcAL+O8lymdn167RAo4epe9x6zvIQ== X-Google-Smtp-Source: ABdhPJwg8ArejE6C3+lSeOkLDFnZYm0kZBxdJYvrkQP4SWHMDZM0ymwiLtoY4fQBmq5VerBMTXRAVg== X-Received: by 2002:a63:520e:: with SMTP id g14mr1816026pgb.350.1616569686220; Wed, 24 Mar 2021 00:08:06 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:7c07:24cd:c637:7fab]) by smtp.gmail.com with ESMTPSA id e63sm1246860pfe.208.2021.03.24.00.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 00:08:05 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 24 Mar 2021 16:07:50 +0900 Message-Id: <20210324070757.3530377-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210324070757.3530377-1-hiroh@chromium.org> References: <20210324070757.3530377-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/8] android: CameraHalManager: Hold CameraDevice with std::unique_ptr 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 is owned by CameraHalManager. The ownership of the object is not shared with other classes. So CameraHalManager should manage CameraDevice with std::unique_ptr. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 5 ++--- src/android/camera_device.h | 2 +- src/android/camera_hal_manager.cpp | 10 ++++------ src/android/camera_hal_manager.h | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) -- 2.31.0.291.g576ba9dcdaf-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 72a89258..d0955de7 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -350,11 +350,10 @@ CameraDevice::~CameraDevice() delete it.second; } -std::shared_ptr CameraDevice::create(unsigned int id, +std::unique_ptr CameraDevice::create(unsigned int id, const std::shared_ptr &cam) { - CameraDevice *camera = new CameraDevice(id, cam); - return std::shared_ptr(camera); + return std::unique_ptr(new CameraDevice(id, cam)); } /* diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 823d561c..8be7f305 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -32,7 +32,7 @@ class CameraDevice : protected libcamera::Loggable { public: - static std::shared_ptr create(unsigned int id, + static std::unique_ptr create(unsigned int id, const std::shared_ptr &cam); ~CameraDevice(); diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 189eda2b..b3c85406 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -36,8 +36,6 @@ CameraHalManager::CameraHalManager() CameraHalManager::~CameraHalManager() { - cameras_.clear(); - if (cameraManager_) { cameraManager_->stop(); delete cameraManager_; @@ -124,7 +122,7 @@ 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::unique_ptr camera = CameraDevice::create(id, std::move(cam)); int ret = camera->initialize(); if (ret) { LOG(HAL, Error) << "Failed to initialize camera: " << cam->id(); @@ -154,7 +152,7 @@ void CameraHalManager::cameraRemoved(std::shared_ptr cam) MutexLocker locker(mutex_); auto iter = std::find_if(cameras_.begin(), cameras_.end(), - [&cam](std::shared_ptr &camera) { + [&cam](const std::unique_ptr &camera) { return cam == camera->camera(); }); if (iter == cameras_.end()) @@ -191,7 +189,7 @@ int32_t CameraHalManager::cameraLocation(const Camera *cam) CameraDevice *CameraHalManager::cameraDeviceFromHalId(unsigned int id) { auto iter = std::find_if(cameras_.begin(), cameras_.end(), - [id](std::shared_ptr &camera) { + [id](const std::unique_ptr &camera) { return camera->id() == id; }); if (iter == cameras_.end()) @@ -243,7 +241,7 @@ void CameraHalManager::setCallbacks(const camera_module_callbacks_t *callbacks) * Internal cameras are already assumed to be present at module load * time by the Android framework. */ - for (std::shared_ptr &camera : cameras_) { + for (const std::unique_ptr &camera : cameras_) { unsigned int id = camera->id(); if (id >= firstExternalCameraId_) callbacks_->camera_device_status_change(callbacks_, id, diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index a91decc7..65bb3554 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -50,7 +50,7 @@ private: libcamera::CameraManager *cameraManager_; const camera_module_callbacks_t *callbacks_; - std::vector> cameras_; + std::vector> cameras_; std::map cameraIdsMap_; Mutex mutex_;