From patchwork Wed Mar 24 07:07:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11683 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 D70A0C32E7 for ; Wed, 24 Mar 2021 07:08:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 964D968D63; Wed, 24 Mar 2021 08:08:26 +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="Mrq5NQWB"; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A36BC68D58 for ; Wed, 24 Mar 2021 08:08:24 +0100 (CET) Received: by mail-pj1-x102f.google.com with SMTP id bt4so11231228pjb.5 for ; Wed, 24 Mar 2021 00:08:24 -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=CZ/yhheXZdNsy75ODPaUnOnvm2NuTPUwsZaJGHiRGDI=; b=Mrq5NQWB6cRA321dPaeC2TWVu/2qNuait/NR8RPExpyPZfYxqoc9MbB+GgSwg8UwN9 RYpYVdwQCyvSDxQhwNJCc0FZsHqNDvTbVlCwx45yBxXCAbwcFXVm+obnf15RZ4flLyFL GqW++G5XU9l4Hus/GTdT1Ky+pMh+6RXVr3peU= 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=CZ/yhheXZdNsy75ODPaUnOnvm2NuTPUwsZaJGHiRGDI=; b=OqnL6gy4yyh7benvsfCkOHz/SLYHZbdLyCJyK2EP9ebQF1R0WJRCNvxEM16Bei1+3e 6HDfef2i3/utolQX0g7T7OtAduvSdoR+/IRQoHwEpqa0OZdAY7P65zdRgxmeAHuB97Ur ErKlHNdM0OF/Lf8Iu45HlocMWo4AG21AgZPJ1WmwnTZlfdgUACV0xVAo4MheZg7KcnS9 IjpTklHxePw8Oefuok7M56/OSc8X89kYylvRC08wCC2bjgmr5WlA/2iCzaQ/3xKStvWg /Mz41qOdaAd9hAoaXM1mQ9xX/f8tfQZ/pZG5B+7J5LQdBrgnIze2JYWvY6cSr80tsLaq zc+A== X-Gm-Message-State: AOAM533dPIEP6QwuNRbaGWHYVHKLGzuNC7fOfb6IW6uzNRdaWamAsX0V usKeU1pjMESaHaDSQPIVGb5nSd0cWC/WIg== X-Google-Smtp-Source: ABdhPJxXhsnwIqFiYbkBBll/L/NkjiVDhWNJelEJbttuc0sdzekGB26t52JtmXFgPLuhpWPPxQLZdg== X-Received: by 2002:a17:90b:1296:: with SMTP id fw22mr1975418pjb.93.1616569697466; Wed, 24 Mar 2021 00:08:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 00:08:17 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 24 Mar 2021 16:07:57 +0900 Message-Id: <20210324070757.3530377-9-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 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" CameraMetadata stored in requestTemplates_ 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 | 22 ++++++++-------------- src/android/camera_device.h | 6 +++--- 2 files changed, 11 insertions(+), 17 deletions(-) -- 2.31.0.291.g576ba9dcdaf-goog diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 8fdcb85a..5fbf6f82 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(); + std::unique_ptr 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_;