From patchwork Tue Mar 23 01:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11646 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 EB15BC32E2 for ; Tue, 23 Mar 2021 01:42:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A561F68D6C; Tue, 23 Mar 2021 02:42:41 +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="kEw3izpg"; dkim-atps=neutral Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 397746084F for ; Tue, 23 Mar 2021 02:42:39 +0100 (CET) Received: by mail-pg1-x534.google.com with SMTP id n11so10111804pgm.12 for ; Mon, 22 Mar 2021 18:42:39 -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=6dstDRcU6yUHRjDFdU0T2rMm1tuKswyN+1GX25YXinw=; b=kEw3izpgac5eCJSl6XAKkr/OcbKcmmm4rWzJMMcnuFwB5Iga47mII/EIbxPaOn65LD uj/pmQVjAQymo7XI5DXm8S7zbXvb8c6xbBGtKbZpccv6jZHb6/TOf62FJ0s35zvt+FXH gu45wFGUZrCxRIolhFAh+ZYx5MFm1NlZ1cGQE= 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=6dstDRcU6yUHRjDFdU0T2rMm1tuKswyN+1GX25YXinw=; b=Kb0rDiDvoqpZ2mvS2DeOCBjcZgoZz3tPUEDF061hNaXASyoQugLph2mtjfXH8AAvtB v1voLBNI1s4cIUV1pxLDr2wXSNXlJVuwDm6fzLv4cLsZeN8ctTUyYhJNZjxrCA7mkBQL quBt3B1tnxl5J+8YhITRNfcCRp/HtJbF0Vl3TejJFcgWssPtbPKLqD2QEpGmExea3sId FBK5TQcs13qwdX+OhHLW/fvqyorKPCZJR0Vkx8tKn7iK/E6lsCXCoAZsOZJdq4JkF1mg A5HAfKtKq1TWdaraTZoYzUjdjkvhxFdpca0s65098yMIQ76/P46/mAAE7JbSYtAsCTSh RVRg== X-Gm-Message-State: AOAM5318vjl+7B951fCJOO4TZQOJGM+nPW68J2OLOQ3lRFZNJrqzhT+s yk9j6pvjs/VLV9gc2SzUtHjRqNq+9RyeUQ== X-Google-Smtp-Source: ABdhPJzOqr0OP+2HbcK/Ignl+UBG3XXnQmbnrLEQt7zCKI1bY0dipBvzIx+nR/P2VezVYgQaVAhQyQ== X-Received: by 2002:a62:804f:0:b029:1f6:6159:a6d0 with SMTP id j76-20020a62804f0000b02901f66159a6d0mr2083937pfd.50.1616463757610; Mon, 22 Mar 2021 18:42:37 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8115:e5cc:747b:64de]) by smtp.gmail.com with ESMTPSA id h13sm590527pjv.52.2021.03.22.18.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:37 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:19 +0900 Message-Id: <20210323014226.3211412-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog In-Reply-To: <20210323014226.3211412-1-hiroh@chromium.org> References: <20210323014226.3211412-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 --- 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.rc2.261.g7f71774620-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_;