From patchwork Sun Jun 28 00:15:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8470 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 13785C2E69 for ; Sun, 28 Jun 2020 00:16:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E23C1609C8; Sun, 28 Jun 2020 02:16:04 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C17160AF7 for ; Sun, 28 Jun 2020 02:15:56 +0200 (CEST) X-Halon-ID: 7437b4bc-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 7437b4bc-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:21 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:32 +0200 Message-Id: <20200628001532.2685967-14-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 13/13] libcamera: ipu3: imgu: Use unique_ptr for video and subdevices 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" Instead of manually deleting the video and subdevices in the destructor use std::unique_ptr. Suggested-by: Laurent Pinchart Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/imgu.cpp | 24 ++++++++++++++------- src/libcamera/pipeline/ipu3/imgu.h | 32 ++++++++-------------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 6a721d47cdacf3d6..4f11dc0dbb5fe94a 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -44,28 +44,36 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index) * by the match() function: no need to check for newly created * video devices and subdevice validity here. */ - imgu_ = V4L2Subdevice::fromEntityName(media, name_); + imgu_ = std::unique_ptr( + V4L2Subdevice::fromEntityName(media, name_)); ret = imgu_->open(); if (ret) return ret; - input_ = V4L2VideoDevice::fromEntityName(media, name_ + " input"); + input_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " input")); ret = input_->open(); if (ret) return ret; - output_ = V4L2VideoDevice::fromEntityName(media, name_ + " output"); + output_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " output")); ret = output_->open(); if (ret) return ret; - viewfinder_ = V4L2VideoDevice::fromEntityName(media, - name_ + " viewfinder"); + viewfinder_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " viewfinder")); ret = viewfinder_->open(); if (ret) return ret; - stat_ = V4L2VideoDevice::fromEntityName(media, name_ + " 3a stat"); + stat_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " 3a stat")); ret = stat_->open(); if (ret) return ret; @@ -150,7 +158,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, return ret; /* No need to apply format to the stat node. */ - if (dev == stat_) + if (dev == stat_.get()) return 0; *outputFormat = {}; @@ -162,7 +170,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, if (ret) return ret; - const char *name = dev == output_ ? "output" : "viewfinder"; + const char *name = dev == output_.get() ? "output" : "viewfinder"; LOG(IPU3, Debug) << "ImgU " << name << " format = " << outputFormat->toString(); diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 7be25e40957fcb03..308bf26ee56e4e82 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -24,21 +24,6 @@ struct StreamConfiguration; class ImgUDevice { public: - ImgUDevice() - : imgu_(nullptr), input_(nullptr), output_(nullptr), - viewfinder_(nullptr), stat_(nullptr) - { - } - - ~ImgUDevice() - { - delete imgu_; - delete input_; - delete output_; - delete viewfinder_; - delete stat_; - } - int init(MediaDevice *media, unsigned int index); int configureInput(const Size &size, V4L2DeviceFormat *inputFormat); @@ -46,21 +31,22 @@ public: int configureOutput(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(output_, PAD_OUTPUT, cfg, + return configureVideoDevice(output_.get(), PAD_OUTPUT, cfg, outputFormat); } int configureViewfinder(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(viewfinder_, PAD_VF, cfg, + return configureVideoDevice(viewfinder_.get(), PAD_VF, cfg, outputFormat); } int configureStat(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(stat_, PAD_STAT, cfg, outputFormat); + return configureVideoDevice(stat_.get(), PAD_STAT, cfg, + outputFormat); } int allocateBuffers(unsigned int bufferCount); @@ -71,11 +57,11 @@ public: int enableLinks(bool enable); - V4L2Subdevice *imgu_; - V4L2VideoDevice *input_; - V4L2VideoDevice *output_; - V4L2VideoDevice *viewfinder_; - V4L2VideoDevice *stat_; + std::unique_ptr imgu_; + std::unique_ptr input_; + std::unique_ptr output_; + std::unique_ptr viewfinder_; + std::unique_ptr stat_; /* \todo Add param video device for 3A tuning */ private: