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_; From patchwork Tue Mar 23 01:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11647 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 BB602C32E1 for ; Tue, 23 Mar 2021 01:42:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1852968D68; Tue, 23 Mar 2021 02:42:42 +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="E5j6sWSC"; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B2A9A6084F for ; Tue, 23 Mar 2021 02:42:40 +0100 (CET) Received: by mail-pf1-x42c.google.com with SMTP id y200so12604386pfb.5 for ; Mon, 22 Mar 2021 18:42:40 -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=lS3DA6l2AnNO2wp6Yf+lEL831G/077oi/y8UWQ5WLDU=; b=E5j6sWSCMt1lEdS3TW+gPleXW3K43DyoNuyfVW6Q+R3JaoWROfPKKw53pvIPHpUGqp Xujw8O5fwhc1UbwP4xBEOlFSx9pvS4mirVkwQwQ2PF0CfeMwVrVrtJDQ0wRRUzSzlkgi 8cevysQ8PQ9Ekaojkv7wz6W1SqKCbIUIxc2gM= 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=lS3DA6l2AnNO2wp6Yf+lEL831G/077oi/y8UWQ5WLDU=; b=h5nCerO3HxHmdLHPi0u8l/1PTcx+BfwqStd2AIWP3j3+QPNF9u0mcHKL4jb0ob45Ah TjzMPnv/u1u7XuhcBlVa/9z2+6aLV+/n+CL/hMEVtzkpP/S5g+IX7mgSm7LeUoAfWflT kAsrbTsNkSMP8OqA4lzfCTTN5T6HkQ2MSNUAEB7aJOWM8HD4Buz2Hqxc3fUtIEml63Sc bcB87dEyLuss2qu67tNgSo6rM/xgrpRSaLjLLb7YkXHD3NKjt4kLksIe+G86sQuMJ2DO knmOtbgVWpn+JUbEj4eYYlQnl8X0ZuuwOWXP7+gkFnJKfMhSbz3w7PYpiX7loY0FIvII VrVw== X-Gm-Message-State: AOAM530xwUExdBlWGS9JUV5lFZM+DWua8wGBJ+iRUSOzQ6GtWJnMtS0s NmThBCUatTSlAu0qtlbUWbyF1K2cMycyxQ== X-Google-Smtp-Source: ABdhPJw2FFs36zpi4+yipP1aTF8/0zuj9VpwwpKOmGffJRh/xfNhUVpu8V9oe3dIUZeAvMkhtCUFPQ== X-Received: by 2002:a65:5585:: with SMTP id j5mr1918658pgs.316.1616463759015; Mon, 22 Mar 2021 18:42:39 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:38 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:20 +0900 Message-Id: <20210323014226.3211412-3-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 2/8] android: CameraHalManager: Hold CameraManager 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" CameraManager is owned by CameraHalManager. The ownership of the object is not shared with other classes. So CameraHalManager should manage CameraManager with std::unique_ptr. Signed-off-by: Hirokazu Honda --- src/android/camera_hal_manager.cpp | 14 +++----------- src/android/camera_hal_manager.h | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) -- 2.31.0.rc2.261.g7f71774620-goog diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index b3c85406..fa398fea 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -34,18 +34,11 @@ CameraHalManager::CameraHalManager() { } -CameraHalManager::~CameraHalManager() -{ - if (cameraManager_) { - cameraManager_->stop(); - delete cameraManager_; - cameraManager_ = nullptr; - } -} +CameraHalManager::~CameraHalManager() = default; int CameraHalManager::init() { - cameraManager_ = new CameraManager(); + cameraManager_ = std::make_unique(); /* Support camera hotplug. */ cameraManager_->cameraAdded.connect(this, &CameraHalManager::cameraAdded); @@ -55,8 +48,7 @@ int CameraHalManager::init() if (ret) { LOG(HAL, Error) << "Failed to start camera manager: " << strerror(-ret); - delete cameraManager_; - cameraManager_ = nullptr; + cameraManager_.reset(); return ret; } diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 65bb3554..dc4e37e5 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -47,7 +47,7 @@ private: CameraDevice *cameraDeviceFromHalId(unsigned int id); - libcamera::CameraManager *cameraManager_; + std::unique_ptr cameraManager_; const camera_module_callbacks_t *callbacks_; std::vector> cameras_; From patchwork Tue Mar 23 01:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11648 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 7E58AC32E1 for ; Tue, 23 Mar 2021 01:42:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 32FBA68D71; Tue, 23 Mar 2021 02:42:45 +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="Ej0jtTg5"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F48168D71 for ; Tue, 23 Mar 2021 02:42:42 +0100 (CET) Received: by mail-pj1-x102b.google.com with SMTP id x7-20020a17090a2b07b02900c0ea793940so11495543pjc.2 for ; Mon, 22 Mar 2021 18:42:42 -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=v2/oim4Rfz4IZCVjag7lbWijILii27gCvbe9QBaHfhw=; b=Ej0jtTg5/wMOK6wNJ9Wcs+KAilwsIlo8I3cn2lh3GNVaqMxhSvLg+/c3k0RdaB5F6X pMZVYTzbl+iQ4TMCww/KsO1/iaFTq0zWg70LxAHP4plgwsen0t+KvbRRvg7QdJpRyerp mTu6cyjgSsX36yd2dzEM/TRsgn6J818iciLZU= 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=v2/oim4Rfz4IZCVjag7lbWijILii27gCvbe9QBaHfhw=; b=rWCh1D0qmbMF1PnTUKG2/FkhMk/usIpYrhkCJG3XidZvRIpAC+CoFbUMRZHVuREcve +YOafMtOYpzJP21BTg3dHCcd+PSz68zVhrCd9cRwLAl9RuXLP5WvLlfEqZUNYMtq8tPs DXIEYDCIEijcAIo9NGuNNgN9yh2QSaGo/7DPH0EHGHLsiUoJU+ih47ww2louM1EMr7te f7xY7+FXJyX5dujeaF5szGAfmgM+2GezK6JF4EgKn4U9eBN1eqV1gCnpUC68OCK+aDN7 Igd7vtYc2XxnkqxFQLAklOJjGE8e2r0JKGBkMOFk0QRQR7KXLgsLCEFKpMXr2xx9C0Zf agfQ== X-Gm-Message-State: AOAM531bwTf2qgRwNHZ0llDpABNJQdz2Z9Whv7C/6YhX60MO79uWs/T9 HFrC62Biv8YDZshkrQUB1uEXEoa6Rwh/gw== X-Google-Smtp-Source: ABdhPJw+1UGvln5QxgVjzz88tMc6ZMxMT4quPI4XTQ26tZR98UImVJuyt5eeTo39XTwSovfyg466zQ== X-Received: by 2002:a17:90b:108f:: with SMTP id gj15mr1896055pjb.177.1616463760384; Mon, 22 Mar 2021 18:42:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:40 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:21 +0900 Message-Id: <20210323014226.3211412-4-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 3/8] android: CameraHalManager: Fix a function call of a moved Camera 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" This fixes a bug of calling Camera::id() of a moved Camera. Signed-off-by: Hirokazu Honda --- src/android/camera_hal_manager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.31.0.rc2.261.g7f71774620-goog diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index fa398fea..df3f1cd2 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -95,7 +95,8 @@ void CameraHalManager::cameraAdded(std::shared_ptr cam) * IDs starts from '0' for internal cameras and '1000' for external * cameras. */ - auto iter = cameraIdsMap_.find(cam->id()); + std::string cameraId = cam->id(); + auto iter = cameraIdsMap_.find(cameraId); if (iter != cameraIdsMap_.end()) { id = iter->second; } else { @@ -117,12 +118,12 @@ void CameraHalManager::cameraAdded(std::shared_ptr 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(); + LOG(HAL, Error) << "Failed to initialize camera: " << cameraId; return; } if (isCameraNew) { - cameraIdsMap_.emplace(cam->id(), id); + cameraIdsMap_.emplace(cameraId, id); if (isCameraExternal) nextExternalCameraId_++; From patchwork Tue Mar 23 01:42:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11649 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 17BACC32E1 for ; Tue, 23 Mar 2021 01:42:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BB4BC68D66; Tue, 23 Mar 2021 02:42:45 +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="avg53zh9"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5041A6084F for ; Tue, 23 Mar 2021 02:42:43 +0100 (CET) Received: by mail-pj1-x1031.google.com with SMTP id w8so9372532pjf.4 for ; Mon, 22 Mar 2021 18:42:43 -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=9SsannRWX5zE+DBPjpFdYVxvGcaefXukUFwOVlU+/EA=; b=avg53zh96onRkxS6ny1mMHN0pYgjwImD5tCglZHwDG3Ezg7MZf2VLNbT3NXagg2hcL z0WkLY37p2RMY6BCcFSTGirYxxY4LW6WkM1tE5k6Nf3oYQv/sxz/Gh75VtpHqhneR6Y/ 1ZojvAoTDb3FoO2GTh1pmUPTppmcMYESrtErM= 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=9SsannRWX5zE+DBPjpFdYVxvGcaefXukUFwOVlU+/EA=; b=K2dr7cRUJc3e6RXuLHZ2paasQn7+AQkrNUEtc9+h9hvlIYXWaenuc2uRRzqWaQt6oL EGlmvNypT74YK1XGOObsWKFkLkm3TnHuTv3dTg6oaQ9Dql6EYZ0DH523Db6R9RbLDnx9 j9dbBQD6k81AR1wyirmmkhJc8trnHZ0zcHiDxTirq2Sra4GcgLxvrWowuJuBdCfgPXnX k3LOnWJW5DQKcw1BqsN2xGSh9V1iA2ufG7i1bimzyHXn5iiMHtW5eqGW7wdSnf+dmNNV jbbGZCP7eSyQvjnJ4EWMl4er8D/xkYfz/WDNcx0IngwtbbMYM1yiVDQ1Q7M52ab8H+Zf RxPA== X-Gm-Message-State: AOAM532vdtkPEAuBXdOdNTJFWmClcRt4qv0jCMrEa4YYtl1JbtEsz2bE wpbAuwcMwjiNP7d1Gy5OGJDtzy5bUIi4IQ== X-Google-Smtp-Source: ABdhPJwQ5W1S6LkZh8yagkiGusvLma9LvY7d2p94QwHN/9JzkAkhAZHiaL5kHXEu20PIROJKvap81g== X-Received: by 2002:a17:90a:a414:: with SMTP id y20mr1860919pjp.77.1616463761774; Mon, 22 Mar 2021 18:42:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:41 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:22 +0900 Message-Id: <20210323014226.3211412-5-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 4/8] android: CameraDevice: Take shared_ptr in constructor 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 takes the ownership of Camera. Therefore, shared_ptr would rather be used than const shared_ptr&. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 12 +++++++----- src/android/camera_device.h | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) -- 2.31.0.rc2.261.g7f71774620-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index d0955de7..c0630e53 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -312,9 +312,10 @@ CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() * back to the framework using the designated callbacks. */ -CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr &camera) - : id_(id), running_(false), camera_(camera), staticMetadata_(nullptr), - facing_(CAMERA_FACING_FRONT), orientation_(0) +CameraDevice::CameraDevice(unsigned int id, std::shared_ptr camera) + : id_(id), running_(false), camera_(std::move(camera)), + staticMetadata_(nullptr), facing_(CAMERA_FACING_FRONT), + orientation_(0) { camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); @@ -351,9 +352,10 @@ CameraDevice::~CameraDevice() } std::unique_ptr CameraDevice::create(unsigned int id, - const std::shared_ptr &cam) + std::shared_ptr cam) { - return std::unique_ptr(new CameraDevice(id, cam)); + return std::unique_ptr( + new CameraDevice(id, std::move(cam))); } /* diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 8be7f305..555b33e7 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -33,7 +33,7 @@ class CameraDevice : protected libcamera::Loggable { public: static std::unique_ptr create(unsigned int id, - const std::shared_ptr &cam); + std::shared_ptr cam); ~CameraDevice(); int initialize(); @@ -66,7 +66,7 @@ protected: std::string logPrefix() const override; private: - CameraDevice(unsigned int id, const std::shared_ptr &camera); + CameraDevice(unsigned int id, std::shared_ptr camera); struct Camera3RequestDescriptor { Camera3RequestDescriptor(libcamera::Camera *camera, From patchwork Tue Mar 23 01:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11650 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 16652C32E1 for ; Tue, 23 Mar 2021 01:42:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BC56D68D6D; Tue, 23 Mar 2021 02:42:47 +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="aimzPDmL"; dkim-atps=neutral Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAD5B68D65 for ; Tue, 23 Mar 2021 02:42:44 +0100 (CET) Received: by mail-pg1-x532.google.com with SMTP id u19so10112107pgh.10 for ; Mon, 22 Mar 2021 18:42:44 -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=8V85V8tXNr1xchcUdM20iZoQf/t2GgfTSG7qr1XgV9c=; b=aimzPDmLvZIGX159TOhNYr0p4uOrBjWN4vSgo0Euh8ccdzmmzG6k7jp744LAmr8tG5 4bXClizverSkbCZIUalmApwzwJeEZGoGls3PfB1ekJXax/pR0fpXEErvGJ0ljdALEUFT uR6LUyZFz1ZFs1nhUOMkl/diJ0fcIshEBDD94= 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=8V85V8tXNr1xchcUdM20iZoQf/t2GgfTSG7qr1XgV9c=; b=UpBxdwUx+az4GS8yKWIRBLJ3p17C1axGiRRIEW0VaJIGvXXUyntxOLHnWbYhMzOi13 vVTGq6uV7zGZXHudHY9TV6k8wNmMHHd27XcZIVtqMdGbJOCf8h51pcL3wos7NWrE/l9Y tuasVdhX8/BYoFunfa9lLY//TBUH6G/CORk/QnGt2k1iFNh0SsVngDlzDGvlzMUf+lfL 3gTDDKra7OQruGNtv3YODcgq4MqCTB8rXnRF6g6whAA5ibWo4b7mMFXldkkLBqiOQ3Ig xEUTE1aDAqRMcqrVkCFQwLQmhna6cYUmpSxT76z/fNn9QC2I6rOGESiDNYslrvxLkZDl uXIg== X-Gm-Message-State: AOAM530bncNeqOI3ySW7IkX2MfvMdo0KrLguVJ0J6Z1zgZuPEJN80Px4 DVA5tsYUdNjS8P6BM/kpCQyOC5o9EzHjAQ== X-Google-Smtp-Source: ABdhPJzdBwa565Zpz0ubtj0pj9OisFT0N11AdrafPjlp6r5Dv705bCvsXjLl6C0LIoVZGdzE1vi6ag== X-Received: by 2002:aa7:956d:0:b029:1f1:5ba6:2a58 with SMTP id x13-20020aa7956d0000b02901f15ba62a58mr2500464pfq.63.1616463763173; Mon, 22 Mar 2021 18:42:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:42 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:23 +0900 Message-Id: <20210323014226.3211412-6-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 5/8] android: CameraDevice: Return const shared_ptr& by camera() 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::camera() originally returns shared_ptr. It is mandatory to make a copy by calling camera() in this way. There is no need of copying if a caller needs the reference of the camera like const shared_ptr cam = camera(). That is, it is a caller that copying is required. This changes the return type of camera() to const shared_ptr&, so that we are able to reduce one redundant copy in the above case. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.31.0.rc2.261.g7f71774620-goog diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 555b33e7..14e26b4d 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -43,7 +43,7 @@ public: unsigned int id() const { return id_; } camera3_device_t *camera3Device() { return &camera3Device_; } - std::shared_ptr camera() const { return camera_; } + const std::shared_ptr &camera() const { return camera_; } libcamera::CameraConfiguration *cameraConfiguration() const { return config_.get(); From patchwork Tue Mar 23 01:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11651 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 72783C32E2 for ; Tue, 23 Mar 2021 01:42:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26FCB68D79; Tue, 23 Mar 2021 02:42:48 +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="M2bOfA7D"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 279C968D75 for ; Tue, 23 Mar 2021 02:42:46 +0100 (CET) Received: by mail-pj1-x1034.google.com with SMTP id bt4so9355971pjb.5 for ; Mon, 22 Mar 2021 18:42:46 -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=MRorFuuW+i3Eudcvysm6sAexmlSUngopmtWCo+wVBpo=; b=M2bOfA7D4sd+8LR7GzMsvxHgjTNMgZSTcX7tldWcxGUrrXYOeFnb/TvttaZkII1vTS eVBEKfki40D6Dd96V1kK5ZkNxszbKuU4oSAu+9Qzjw8ggrGPpRi5CVHAjk45T4K1HFao BiFxJ3jNuKJbQEFxfeA///k09BeRAbg2SXNI0= 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=MRorFuuW+i3Eudcvysm6sAexmlSUngopmtWCo+wVBpo=; b=hcQJzfdlBEx4uaWACl3CDTJyzZB9g2C0d0m8FKFqT1kgOf1ITUvrhhELB2zPwfNifS 0O8GdCq8m3gdJl92WNTPymbYUBpV3MD/ZjakqG4af7sehXqPHj5CN49Vyeda4QKuYBP2 FOUMXHAQuBspCzmbagYdYzKbU9ZBLZwf3mXKDQPcqqCLcZNnBA6JLWNylzXH00SQva3G 0veAOqHQXjrkmOVYkJ7mxQb8r/v5YvqD6DakDgIn6PowhD2Mj0pPAjxSL0MI3tCNVxBN QcwUWwHXqSJeFlEkLI73CTp+rrWHXLXnTd+lqFsVySzjP2miPZ8akzggbrrd9JXLQC2+ k6SQ== X-Gm-Message-State: AOAM533uuSIFYXJuxJlq59LKnKlNSCJelhktvOvNGCL83TC5orLqoWVt 6XFYgOZSrV5ioVxvKKoMvTpkNfuBfY/u5w== X-Google-Smtp-Source: ABdhPJxaJfZ1sg4s3TQNYxjedgNtNPMAjpP5Uh0ARaclMNSV+osdgtbLowCjG0MdOrtOoUfqXqJ3EQ== X-Received: by 2002:a17:90a:c588:: with SMTP id l8mr1868881pjt.120.1616463764598; Mon, 22 Mar 2021 18:42:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:44 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:24 +0900 Message-Id: <20210323014226.3211412-7-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 6/8] android: Camera3RequestDescriptor: Manage buffers with std::vector 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" Camera3RequestDescriptor has a length and an allocated buffer for camera_stream_buffer_t array. This replaces the variables with std::vector. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 37 +++++++++++++++-------------------- src/android/camera_device.h | 3 +-- 2 files changed, 17 insertions(+), 23 deletions(-) -- 2.31.0.rc2.261.g7f71774620-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index c0630e53..b000d332 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -271,16 +271,16 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( frameNumber_ = camera3Request->frame_number; /* Copy the camera3 request stream information for later access. */ - numBuffers_ = camera3Request->num_output_buffers; - buffers_ = new camera3_stream_buffer_t[numBuffers_]; - for (unsigned int i = 0; i < numBuffers_; ++i) + const uint32_t numBuffers = camera3Request->num_output_buffers; + buffers_.resize(numBuffers); + for (uint32_t i = 0; i < numBuffers; i++) buffers_[i] = camera3Request->output_buffers[i]; /* * FrameBuffer instances created by wrapping a camera3 provided dmabuf * are emplaced in this vector of unique_ptr<> for lifetime management. */ - frameBuffers_.reserve(numBuffers_); + frameBuffers_.reserve(numBuffers); /* Clone the controls associated with the camera3 request. */ settings_ = CameraMetadata(camera3Request->settings); @@ -294,10 +294,7 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( reinterpret_cast(this)); } -CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() -{ - delete[] buffers_; -} +CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() = default; /* * \class CameraDevice @@ -1840,10 +1837,10 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->settings_ = lastSettings_; LOG(HAL, Debug) << "Queueing request " << descriptor->request_->cookie() - << " with " << descriptor->numBuffers_ << " streams"; - for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { - const camera3_stream_buffer_t *camera3Buffer = &descriptor->buffers_[i]; - camera3_stream *camera3Stream = camera3Buffer->stream; + << " with " << descriptor->buffers_.size() << " streams"; + for (unsigned int i = 0; i < descriptor->buffers_.size(); ++i) { + const camera3_stream_buffer_t &camera3Buffer = descriptor->buffers_[i]; + camera3_stream *camera3Stream = camera3Buffer.stream; CameraStream *cameraStream = static_cast(camera3Stream->priv); std::stringstream ss; @@ -1874,7 +1871,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * associate it with the Camera3RequestDescriptor for * lifetime management only. */ - buffer = createFrameBuffer(*camera3Buffer->buffer); + buffer = createFrameBuffer(*camera3Buffer.buffer); descriptor->frameBuffers_.emplace_back(buffer); LOG(HAL, Debug) << ss.str() << " (direct)"; break; @@ -1899,7 +1896,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques } descriptor->request_->addBuffer(cameraStream->stream(), buffer, - camera3Buffer->acquire_fence); + camera3Buffer.acquire_fence); } /* @@ -1930,7 +1927,7 @@ void CameraDevice::requestComplete(Request *request) } LOG(HAL, Debug) << "Request " << request->cookie() << " completed with " - << descriptor->numBuffers_ << " streams"; + << descriptor->buffers_.size() << " streams"; /* * \todo The timestamp used for the metadata is currently always taken @@ -1942,7 +1939,7 @@ void CameraDevice::requestComplete(Request *request) resultMetadata = getResultMetadata(descriptor, timestamp); /* Handle any JPEG compression. */ - for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { + for (unsigned int i = 0; i < descriptor->buffers_.size(); ++i) { CameraStream *cameraStream = static_cast(descriptor->buffers_[i].stream->priv); @@ -1975,15 +1972,13 @@ void CameraDevice::requestComplete(Request *request) /* Prepare to call back the Android camera stack. */ camera3_capture_result_t captureResult = {}; captureResult.frame_number = descriptor->frameNumber_; - captureResult.num_output_buffers = descriptor->numBuffers_; - for (unsigned int i = 0; i < descriptor->numBuffers_; ++i) { + captureResult.num_output_buffers = descriptor->buffers_.size(); + for (unsigned int i = 0; i < descriptor->buffers_.size(); ++i) { descriptor->buffers_[i].acquire_fence = -1; descriptor->buffers_[i].release_fence = -1; descriptor->buffers_[i].status = status; } - captureResult.output_buffers = - const_cast(descriptor->buffers_); - + captureResult.output_buffers = descriptor->buffers_.data(); if (status == CAMERA3_BUFFER_STATUS_OK) { notifyShutter(descriptor->frameNumber_, timestamp); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 14e26b4d..a11cf243 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -74,8 +74,7 @@ private: ~Camera3RequestDescriptor(); uint32_t frameNumber_; - uint32_t numBuffers_; - camera3_stream_buffer_t *buffers_; + std::vector buffers_; std::vector> frameBuffers_; CameraMetadata settings_; std::unique_ptr request_; From patchwork Tue Mar 23 01:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11652 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 E848AC32E1 for ; Tue, 23 Mar 2021 01:42:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A9F1868D7B; Tue, 23 Mar 2021 02:42:50 +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="EDY3hIMN"; dkim-atps=neutral Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8066C68D65 for ; Tue, 23 Mar 2021 02:42:47 +0100 (CET) Received: by mail-pf1-x435.google.com with SMTP id y5so12615288pfn.1 for ; Mon, 22 Mar 2021 18:42:47 -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=F25CpZfGZLc+v5dCL7KCeC8aHDszpv2/2eWqJl9POf0=; b=EDY3hIMNm9LqByu5VcmalbQeDZyjWPonen58qCk0vwi0HCM7/zc/SCLu4KLgkLxY6E LIgiQsk5mHFNPSowdRqU36WooUkXuP2LEKdVq/U0FuEexBUkEro3SwCKum/I3JFBPdqE ITygNqg5tQtnBlR2bXDHVo3JHJtjVH/rN7C3g= 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=F25CpZfGZLc+v5dCL7KCeC8aHDszpv2/2eWqJl9POf0=; b=OQqk9+lEZ3GYuLuWyEKZRjtIyO/jd+KAg1S9DPzrPDOyEmYns2y3+H9+gMppTXJU0a 0er8ZHytGtRycR0yeTx9oMghTS3Fybj866E2gUn88Z8AZ92Ktw1thGa18UHlJNqWl+rG 5O2Om7Rvmufw9crGdMweoyXbFOzVcoKESXatjBc91wlqwyVxEXDsYSJNF9umWFjNOJ09 SI1FDBxhGYnGO0SlZtQ8F3MQVBtQuy5Ynv7B0RIz1tglF4JMsZLF+3mxCg/tst5JAjwl G/Pxj9ptmWLL7IEw7rVoC51SXZe+eGlGoQvVOXJYh3XolkxwvM7w1bsro4rEczwPq4cf aBYA== X-Gm-Message-State: AOAM530q0qTzEx4zUGow6OfOl4pZ2fU6zqbvJp+NZixAOaWHS/3zVxFk vsj3oaSvQ4aMpaY0eVebXmEHOFxQXqWRHg== X-Google-Smtp-Source: ABdhPJyc9HNEdU/yZx4lg6z1PnUfjsam4O/NK8nY227mldE2nofgn+r5rrrDJATp7x3ur9/tXzT9sg== X-Received: by 2002:a62:7708:0:b029:1ee:f656:51d5 with SMTP id s8-20020a6277080000b02901eef65651d5mr2509873pfc.59.1616463766003; Mon, 22 Mar 2021 18:42:46 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:45 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:25 +0900 Message-Id: <20210323014226.3211412-8-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 7/8] android: CameraDevice: Manage staticMetadata_ 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" Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 14 ++++---------- src/android/camera_device.h | 2 +- 2 files changed, 5 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 b000d332..696f7676 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -311,8 +311,7 @@ CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() = default; CameraDevice::CameraDevice(unsigned int id, std::shared_ptr camera) : id_(id), running_(false), camera_(std::move(camera)), - staticMetadata_(nullptr), facing_(CAMERA_FACING_FRONT), - orientation_(0) + facing_(CAMERA_FACING_FRONT), orientation_(0) { camera_->requestCompleted.connect(this, &CameraDevice::requestComplete); @@ -341,9 +340,6 @@ CameraDevice::CameraDevice(unsigned int id, std::shared_ptr camera) CameraDevice::~CameraDevice() { - if (staticMetadata_) - delete staticMetadata_; - for (auto &it : requestTemplates_) delete it.second; } @@ -732,11 +728,10 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() uint32_t numEntries; uint32_t byteSize; std::tie(numEntries, byteSize) = calculateStaticMetadataSize(); - staticMetadata_ = new CameraMetadata(numEntries, byteSize); + staticMetadata_ = std::make_unique(numEntries, byteSize); if (!staticMetadata_->isValid()) { LOG(HAL, Error) << "Failed to allocate static metadata"; - delete staticMetadata_; - staticMetadata_ = nullptr; + staticMetadata_.reset(); return nullptr; } @@ -1356,8 +1351,7 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() if (!staticMetadata_->isValid()) { LOG(HAL, Error) << "Failed to construct static metadata"; - delete staticMetadata_; - staticMetadata_ = nullptr; + staticMetadata_.reset(); return nullptr; } diff --git a/src/android/camera_device.h b/src/android/camera_device.h index a11cf243..cea82b24 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -113,7 +113,7 @@ private: std::shared_ptr camera_; std::unique_ptr config_; - CameraMetadata *staticMetadata_; + std::unique_ptr staticMetadata_; std::map requestTemplates_; const camera3_callback_ops_t *callbacks_; From patchwork Tue Mar 23 01:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11653 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 78FF0C32E1 for ; Tue, 23 Mar 2021 01:42:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34FD168D6D; Tue, 23 Mar 2021 02:42:51 +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="VVxopW0m"; dkim-atps=neutral Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E240768D68 for ; Tue, 23 Mar 2021 02:42:48 +0100 (CET) Received: by mail-pg1-x531.google.com with SMTP id v3so10123291pgq.2 for ; Mon, 22 Mar 2021 18:42:48 -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=JMGCZzhkfpvJZ+7EN+9n+X1/aLKzRUMcbnPoXHohOp0=; b=VVxopW0mKn9DoLQFDaXEuHzpMwppPwZ/wn1j8qxA8lt1IsYxaNxeMtP43cPOh3aNmK DGQ5uViiGmUIuFWj2Xr96ARqjOX1Ek0amOiG3RCBSjolnaJNNT/7mxqiqu2goUX6Oviy P98FZfMJ/gjPo7gUbszqwQcPWR2zpkgo5uwzA= 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=JMGCZzhkfpvJZ+7EN+9n+X1/aLKzRUMcbnPoXHohOp0=; b=e+o6NR2b1XZDhePhVNyajAApvbAu+dbdrLImCPYLlfO9dTgkpy0YfeUhwcic1WVs/h VNi/35k343aZKcoqDBOmbSmbPRv99dhsuFCQ0ydQXgvQ8/06GlRnS1Jz2RTANYA1jIr0 0MynKOW1G4elRqA7fSzE25GNx8J4aDjhnizTOgjFJbwr+r91uoSiAPmoSiUWzQAmuN20 cd77y4QGSAYB9nxLKjX39eDgzHzybcg3261sbzk1X2lMhKtFb3OiSKaxd90ncoRt1crZ sE79+TqrzRcmB8TupnAJUMO8oErT7mIzkLCU69hE6sfszV2pg/kV2VL0xf4wyqHdGUsr 4dZQ== X-Gm-Message-State: AOAM531ojusIDmEtL+aBX/Dok4UNpDu3KrJYNa7sKw2Zr3hc5b7lKG3Q KINcZqt0snLAz784ia5QWDO3C8rYjcmxww== X-Google-Smtp-Source: ABdhPJwIekaAENFxH/ujNA8CD4WhkJVcIOIFDwpcz6NooUeqi7uhbJwXu6xA79m797lXgI13bBzNvQ== X-Received: by 2002:a63:5444:: with SMTP id e4mr1849108pgm.426.1616463767371; Mon, 22 Mar 2021 18:42:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 18:42:47 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Mar 2021 10:42:26 +0900 Message-Id: <20210323014226.3211412-9-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 8/8] android: CameraDevice: Manage requestTemplates_ 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" Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 22 ++++++++-------------- src/android/camera_device.h | 6 +++--- 2 files changed, 11 insertions(+), 17 deletions(-) -- 2.31.0.rc2.261.g7f71774620-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 696f7676..a9a29c76 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -338,11 +338,7 @@ CameraDevice::CameraDevice(unsigned int id, std::shared_ptr camera) } } -CameraDevice::~CameraDevice() -{ - for (auto &it : requestTemplates_) - delete it.second; -} +CameraDevice::~CameraDevice() = default; std::unique_ptr CameraDevice::create(unsigned int id, std::shared_ptr cam) @@ -1358,15 +1354,14 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() return staticMetadata_->get(); } -CameraMetadata *CameraDevice::requestTemplatePreview() +std::unique_ptr CameraDevice::requestTemplatePreview() { /* * \todo Keep this in sync with the actual number of entries. * Currently: 20 entries, 35 bytes */ - CameraMetadata *requestTemplate = new CameraMetadata(21, 36); + auto requestTemplate = std::make_unique(21, 36); if (!requestTemplate->isValid()) { - delete requestTemplate; return nullptr; } @@ -1454,9 +1449,9 @@ CameraMetadata *CameraDevice::requestTemplatePreview() return requestTemplate; } -CameraMetadata *CameraDevice::requestTemplateVideo() +std::unique_ptr CameraDevice::requestTemplateVideo() { - CameraMetadata *previewTemplate = requestTemplatePreview(); + auto previewTemplate = requestTemplatePreview(); if (!previewTemplate) return nullptr; @@ -1488,7 +1483,7 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) return it->second->get(); /* Use the capture intent matching the requested template type. */ - CameraMetadata *requestTemplate; + std::unique_ptr requestTemplate; uint8_t captureIntent; switch (type) { case CAMERA3_TEMPLATE_PREVIEW: @@ -1521,15 +1516,14 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) if (!requestTemplate || !requestTemplate->isValid()) { LOG(HAL, Error) << "Failed to construct request template"; - delete requestTemplate; return nullptr; } requestTemplate->updateEntry(ANDROID_CONTROL_CAPTURE_INTENT, &captureIntent, 1); - requestTemplates_[type] = requestTemplate; - return requestTemplate->get(); + requestTemplates_[type] = std::move(requestTemplate); + return requestTemplates_[type]->get(); } PixelFormat CameraDevice::toPixelFormat(int format) const diff --git a/src/android/camera_device.h b/src/android/camera_device.h index cea82b24..09c395ff 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -97,8 +97,8 @@ private: libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); - CameraMetadata *requestTemplatePreview(); - CameraMetadata *requestTemplateVideo(); + std::unique_ptr requestTemplatePreview(); + std::unique_ptr requestTemplateVideo(); libcamera::PixelFormat toPixelFormat(int format) const; int processControls(Camera3RequestDescriptor *descriptor); std::unique_ptr getResultMetadata( @@ -114,7 +114,7 @@ private: std::unique_ptr config_; std::unique_ptr staticMetadata_; - std::map requestTemplates_; + std::map> requestTemplates_; const camera3_callback_ops_t *callbacks_; std::vector streamConfigurations_;