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_;