[{"id":10924,"web_url":"https://patchwork.libcamera.org/comment/10924/","msgid":"<20200628070442.GA6954@pendragon.ideasonboard.com>","date":"2020-06-28T07:04:42","subject":"Re: [libcamera-devel] [PATCH v2 13/13] libcamera: ipu3: imgu: Use\n\tunique_ptr for video and subdevices","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Sun, Jun 28, 2020 at 02:15:32AM +0200, Niklas Söderlund wrote:\n> Instead of manually deleting the video and subdevices in the destructor\n> use std::unique_ptr.\n> \n> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/pipeline/ipu3/imgu.cpp | 24 ++++++++++++++-------\n>  src/libcamera/pipeline/ipu3/imgu.h   | 32 ++++++++--------------------\n>  2 files changed, 25 insertions(+), 31 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\n> index 6a721d47cdacf3d6..4f11dc0dbb5fe94a 100644\n> --- a/src/libcamera/pipeline/ipu3/imgu.cpp\n> +++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n> @@ -44,28 +44,36 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n>  \t * by the match() function: no need to check for newly created\n>  \t * video devices and subdevice validity here.\n>  \t */\n> -\timgu_ = V4L2Subdevice::fromEntityName(media, name_);\n> +\timgu_ = std::unique_ptr<V4L2Subdevice>(\n> +\t\t\tV4L2Subdevice::fromEntityName(media, name_));\n\nHow about\n\n\timgu_.reset(V4L2Subdevice::fromEntityName(media, name_));\n\nand similarly below ?\n\nI'm considering a patch on top of this to make\nV4L2Subdevice::fromEntityName() return a unique_ptr.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \tret = imgu_->open();\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> -\tinput_ = V4L2VideoDevice::fromEntityName(media, name_ + \" input\");\n> +\tinput_ = std::unique_ptr<V4L2VideoDevice>(\n> +\t\t\tV4L2VideoDevice::fromEntityName(media,\n> +\t\t\t\t\t\t\tname_ + \" input\"));\n>  \tret = input_->open();\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> -\toutput_ = V4L2VideoDevice::fromEntityName(media, name_ + \" output\");\n> +\toutput_ = std::unique_ptr<V4L2VideoDevice>(\n> +\t\t\tV4L2VideoDevice::fromEntityName(media,\n> +\t\t\t\t\t\t\tname_ + \" output\"));\n>  \tret = output_->open();\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> -\tviewfinder_ = V4L2VideoDevice::fromEntityName(media,\n> -\t\t\t\t\t\t      name_ + \" viewfinder\");\n> +\tviewfinder_ = std::unique_ptr<V4L2VideoDevice>(\n> +\t\t\tV4L2VideoDevice::fromEntityName(media,\n> +\t\t\t\t\t\t\tname_ + \" viewfinder\"));\n>  \tret = viewfinder_->open();\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> -\tstat_ = V4L2VideoDevice::fromEntityName(media, name_ + \" 3a stat\");\n> +\tstat_ = std::unique_ptr<V4L2VideoDevice>(\n> +\t\t\tV4L2VideoDevice::fromEntityName(media,\n> +\t\t\t\t\t\t\tname_ + \" 3a stat\"));\n>  \tret = stat_->open();\n>  \tif (ret)\n>  \t\treturn ret;\n> @@ -150,7 +158,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad,\n>  \t\treturn ret;\n>  \n>  \t/* No need to apply format to the stat node. */\n> -\tif (dev == stat_)\n> +\tif (dev == stat_.get())\n>  \t\treturn 0;\n>  \n>  \t*outputFormat = {};\n> @@ -162,7 +170,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad,\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> -\tconst char *name = dev == output_ ? \"output\" : \"viewfinder\";\n> +\tconst char *name = dev == output_.get() ? \"output\" : \"viewfinder\";\n>  \tLOG(IPU3, Debug) << \"ImgU \" << name << \" format = \"\n>  \t\t\t << outputFormat->toString();\n>  \n> diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h\n> index 7be25e40957fcb03..308bf26ee56e4e82 100644\n> --- a/src/libcamera/pipeline/ipu3/imgu.h\n> +++ b/src/libcamera/pipeline/ipu3/imgu.h\n> @@ -24,21 +24,6 @@ struct StreamConfiguration;\n>  class ImgUDevice\n>  {\n>  public:\n> -\tImgUDevice()\n> -\t\t: imgu_(nullptr), input_(nullptr), output_(nullptr),\n> -\t\t  viewfinder_(nullptr), stat_(nullptr)\n> -\t{\n> -\t}\n> -\n> -\t~ImgUDevice()\n> -\t{\n> -\t\tdelete imgu_;\n> -\t\tdelete input_;\n> -\t\tdelete output_;\n> -\t\tdelete viewfinder_;\n> -\t\tdelete stat_;\n> -\t}\n> -\n>  \tint init(MediaDevice *media, unsigned int index);\n>  \n>  \tint configureInput(const Size &size, V4L2DeviceFormat *inputFormat);\n> @@ -46,21 +31,22 @@ public:\n>  \tint configureOutput(const StreamConfiguration &cfg,\n>  \t\t\t    V4L2DeviceFormat *outputFormat)\n>  \t{\n> -\t\treturn configureVideoDevice(output_, PAD_OUTPUT, cfg,\n> +\t\treturn configureVideoDevice(output_.get(), PAD_OUTPUT, cfg,\n>  \t\t\t\t\t    outputFormat);\n>  \t}\n>  \n>  \tint configureViewfinder(const StreamConfiguration &cfg,\n>  \t\t\t\tV4L2DeviceFormat *outputFormat)\n>  \t{\n> -\t\treturn configureVideoDevice(viewfinder_, PAD_VF, cfg,\n> +\t\treturn configureVideoDevice(viewfinder_.get(), PAD_VF, cfg,\n>  \t\t\t\t\t    outputFormat);\n>  \t}\n>  \n>  \tint configureStat(const StreamConfiguration &cfg,\n>  \t\t\t  V4L2DeviceFormat *outputFormat)\n>  \t{\n> -\t\treturn configureVideoDevice(stat_, PAD_STAT, cfg, outputFormat);\n> +\t\treturn configureVideoDevice(stat_.get(), PAD_STAT, cfg,\n> +\t\t\t\t\t    outputFormat);\n>  \t}\n>  \n>  \tint allocateBuffers(unsigned int bufferCount);\n> @@ -71,11 +57,11 @@ public:\n>  \n>  \tint enableLinks(bool enable);\n>  \n> -\tV4L2Subdevice *imgu_;\n> -\tV4L2VideoDevice *input_;\n> -\tV4L2VideoDevice *output_;\n> -\tV4L2VideoDevice *viewfinder_;\n> -\tV4L2VideoDevice *stat_;\n> +\tstd::unique_ptr<V4L2Subdevice> imgu_;\n> +\tstd::unique_ptr<V4L2VideoDevice> input_;\n> +\tstd::unique_ptr<V4L2VideoDevice> output_;\n> +\tstd::unique_ptr<V4L2VideoDevice> viewfinder_;\n> +\tstd::unique_ptr<V4L2VideoDevice> stat_;\n>  \t/* \\todo Add param video device for 3A tuning */\n>  \n>  private:","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5FC6BC2E69\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 28 Jun 2020 07:04:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CB589609D6;\n\tSun, 28 Jun 2020 09:04:46 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 166B1603B4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 28 Jun 2020 09:04:46 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A7E54FB;\n\tSun, 28 Jun 2020 09:04:45 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"LOvUD5G6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593327885;\n\tbh=LOGobqPifEQfADtvmM7ekR04ianhek3JM0kxLsskczo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LOvUD5G6ELqRbU+lfvkCSgqsTbFyZEZD3/5jVPAEMBr/so4P0gJXyW+8A1RmO1FOv\n\t1eqo4HXA7pOObqDv6yD3jVNiRu+2aeYSfSU6hltWlFvssgPbZqT+TRZRWgbAOp2ERK\n\t4iTHzJAqK/G0VjGERLnX3FD1zjhHsZ9UbANRpV7U=","Date":"Sun, 28 Jun 2020 10:04:42 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<20200628070442.GA6954@pendragon.ideasonboard.com>","References":"<20200628001532.2685967-1-niklas.soderlund@ragnatech.se>\n\t<20200628001532.2685967-14-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200628001532.2685967-14-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v2 13/13] libcamera: ipu3: imgu: Use\n\tunique_ptr for video and subdevices","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]