From patchwork Mon Jul 12 21:56:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12929 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 E6539C3226 for ; Mon, 12 Jul 2021 21:57:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 608A568545; Mon, 12 Jul 2021 23:57:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VzEy/+Mf"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3444168547 for ; Mon, 12 Jul 2021 23:57:41 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C36FE3F1 for ; Mon, 12 Jul 2021 23:57:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626127060; bh=tH6sCl3HLJOlhY89bsKzLByhXJgCVBhv4Mld+StTeDY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VzEy/+MfOy2zYEy1EAfwRMlCgC2t33an6NhqJfX5TZHGEB5VCu+mRVWAOnUyHN/Cm nWJ4VfIFGGJ40MZL75vtNSmxvoa4e4XKOZ2K1BH56JsVHqkhif9nmJawI6hhKOub0g YfNmCKf216mAAQvJVn+0hUXsdU5PU6Aeg8XGN+i8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Jul 2021 00:56:31 +0300 Message-Id: <20210712215645.30478-17-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> References: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 16/30] cam: camera_session: Use std::unique_ptr<> to manage class members 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" Store the BufferWriter and FrameBufferAllocator pointers in std::unique_ptr<> instances to simplify memory management and avoid leaks. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/camera_session.cpp | 16 +++++++--------- src/cam/camera_session.h | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index b1200e60329c..1fb7c1b6ad5d 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -20,9 +20,8 @@ using namespace libcamera; CameraSession::CameraSession(std::shared_ptr camera, CameraConfiguration *config) - : camera_(camera), config_(config), writer_(nullptr), last_(0), - queueCount_(0), captureCount_(0), captureLimit_(0), - printMetadata_(false), allocator_(nullptr) + : camera_(camera), config_(config), last_(0), queueCount_(0), + captureCount_(0), captureLimit_(0), printMetadata_(false) { } @@ -56,12 +55,12 @@ int CameraSession::start(const OptionsParser::Options &options) if (options.isSet(OptFile)) { if (!options[OptFile].toString().empty()) - writer_ = new BufferWriter(options[OptFile]); + writer_ = std::make_unique(options[OptFile]); else - writer_ = new BufferWriter(); + writer_ = std::make_unique(); } - allocator_ = new FrameBufferAllocator(camera_); + allocator_ = std::make_unique(camera_); return startCapture(); } @@ -72,12 +71,11 @@ void CameraSession::stop() if (ret) std::cout << "Failed to stop capture" << std::endl; - delete writer_; - writer_ = nullptr; + writer_.reset(); requests_.clear(); - delete allocator_; + allocator_.reset(); } int CameraSession::startCapture() diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h index 5131cfd48b4e..31e8d6db01d9 100644 --- a/src/cam/camera_session.h +++ b/src/cam/camera_session.h @@ -44,7 +44,7 @@ private: libcamera::CameraConfiguration *config_; std::map streamName_; - BufferWriter *writer_; + std::unique_ptr writer_; uint64_t last_; unsigned int queueCount_; @@ -52,7 +52,7 @@ private: unsigned int captureLimit_; bool printMetadata_; - libcamera::FrameBufferAllocator *allocator_; + std::unique_ptr allocator_; std::vector> requests_; };