From patchwork Wed Mar 24 07:07:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11682 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 63F8EC32E7 for ; Wed, 24 Mar 2021 07:08:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2273368D62; Wed, 24 Mar 2021 08:08:22 +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="Yt/eJjvy"; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0536E68D47 for ; Wed, 24 Mar 2021 08:08:21 +0100 (CET) Received: by mail-pj1-x102a.google.com with SMTP id lr1-20020a17090b4b81b02900ea0a3f38c1so2180560pjb.0 for ; Wed, 24 Mar 2021 00:08:20 -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=C5yhi2t31vH+/xv/5DHYTUWdfzioA1Oz+dXxUKn6obs=; b=Yt/eJjvyATeGzvBibfGlaL1OFIU7TafCWiUk0aSkG+1JU1lGFckxM4ERvM+GSJtxmB cwvn81B32tkD+/0m4t1xU7pD353fvQZAM5zfGZ+FpfPcC7+XDmj8MZYUguIg2TewYQP4 7B9GQ3dANuB6FDc1eGZXhHePyCeUPHBI6YGXA= 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=C5yhi2t31vH+/xv/5DHYTUWdfzioA1Oz+dXxUKn6obs=; b=LIg/afvUWyqMAy7aaw21PwdKKBtn/UKK0ASnB2Yq4E5WIbxrKbo4FoqT9puUVKQ9ZA X+j+WflF8X0U8BC9O+YaIJIxBRrDY0s4S+Kc49IDfB/Q/2DTqfkVaMMLwTRsdSquJFQH C0xGcL+h5VJOTxMPCgZu64ru7CS8dAcem2Ju8+PTYvo1q/bgt2tSuHHsS2KGaE336H9G EtBqIhQAqJQONG3gRmRm1P9hWrHDCfNb86WU5V01ybTvTQCY2nccVy3fuJfM08IP0QkZ /hU4pT0Tq6G76KVQKQ/uZYfC9HxF4TRKXUYQPB4EASkY6yBYI7tfDBW7G4Jyjju+suZY uP1A== X-Gm-Message-State: AOAM531ra/Nan/YqAgm0y7pObMnO8XLdCZFKBP/aoFLQetjy4GcZRp58 YyQq3kxMDdGFdLmzrX0tLd2pqaJ2KQCUwQ== X-Google-Smtp-Source: ABdhPJwlr3L9m0D54YJP+5yfk6wvTo9Z6xhsugLFuzT0/f1jIRgdeYS046t83M6CBtNN1wRPAZeOXQ== X-Received: by 2002:a17:902:ce88:b029:e6:3a3c:2f65 with SMTP id f8-20020a170902ce88b02900e63a3c2f65mr2402956plg.66.1616569695822; Wed, 24 Mar 2021 00:08:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 00:08:15 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 24 Mar 2021 16:07:56 +0900 Message-Id: <20210324070757.3530377-8-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 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" staticMetadata_ in CameraDevice is not necessary to be a raw pointer. This reduces the manual new/delete code by changing the type to std::unique_ptr. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 14 ++++---------- src/android/camera_device.h | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) -- 2.31.0.291.g576ba9dcdaf-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index e75fd25f..8fdcb85a 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_;