[{"id":4022,"web_url":"https://patchwork.libcamera.org/comment/4022/","msgid":"<20200316132517.GA2260535@oden.dyn.berto.se>","date":"2020-03-16T13:25:17","subject":"Re: [libcamera-devel] [PATCH 1/9] test: libtest: buffer_source:\n\tClose video device right after allocation","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-03-15 01:57:20 +0200, Laurent Pinchart wrote:\n> There's no need to keep the video device open after allocating buffers,\n> as V4L2 supports buffer orphaning and the exported buffers will still be\n> usable. Close the device right after allocation to avoid the need for\n> delayed cleanups.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  test/libtest/buffer_source.cpp | 24 +++++++++---------------\n>  test/libtest/buffer_source.h   |  1 -\n>  2 files changed, 9 insertions(+), 16 deletions(-)\n> \n> diff --git a/test/libtest/buffer_source.cpp b/test/libtest/buffer_source.cpp\n> index 066049d342a4..0c33200b47ad 100644\n> --- a/test/libtest/buffer_source.cpp\n> +++ b/test/libtest/buffer_source.cpp\n> @@ -8,26 +8,18 @@\n>  #include \"buffer_source.h\"\n>  \n>  #include <iostream>\n> +#include <memory>\n>  \n>  #include \"device_enumerator.h\"\n>  \n>  #include \"test.h\"\n>  \n>  BufferSource::BufferSource()\n> -\t: video_(nullptr)\n>  {\n>  }\n>  \n>  BufferSource::~BufferSource()\n>  {\n> -\tif (video_) {\n> -\t\tvideo_->releaseBuffers();\n> -\t\tvideo_->close();\n> -\t}\n> -\n> -\tdelete video_;\n> -\tvideo_ = nullptr;\n> -\n>  \tif (media_)\n>  \t\tmedia_->release();\n>  }\n> @@ -58,37 +50,39 @@ int BufferSource::allocate(const StreamConfiguration &config)\n>  \t\treturn TestSkip;\n>  \t}\n>  \n> -\tvideo_ = V4L2VideoDevice::fromEntityName(media_.get(), videoDeviceName);\n> -\tif (!video_) {\n> +\tstd::unique_ptr<V4L2VideoDevice> video{ V4L2VideoDevice::fromEntityName(media_.get(), videoDeviceName) };\n> +\tif (!video) {\n>  \t\tstd::cout << \"Failed to get video device from entity \"\n>  \t\t\t  << videoDeviceName << std::endl;\n>  \t\treturn TestFail;\n>  \t}\n>  \n> -\tif (video_->open()) {\n> +\tif (video->open()) {\n>  \t\tstd::cout << \"Unable to open \" << videoDeviceName << std::endl;\n>  \t\treturn TestFail;\n>  \t}\n>  \n>  \t/* Configure the format. */\n>  \tV4L2DeviceFormat format;\n> -\tif (video_->getFormat(&format)) {\n> +\tif (video->getFormat(&format)) {\n>  \t\tstd::cout << \"Failed to get format on output device\" << std::endl;\n>  \t\treturn TestFail;\n>  \t}\n>  \n>  \tformat.size = config.size;\n>  \tformat.fourcc = V4L2VideoDevice::toV4L2Fourcc(config.pixelFormat, false);\n> -\tif (video_->setFormat(&format)) {\n> +\tif (video->setFormat(&format)) {\n>  \t\tstd::cout << \"Failed to set format on output device\" << std::endl;\n>  \t\treturn TestFail;\n>  \t}\n>  \n> -\tif (video_->exportBuffers(config.bufferCount, &buffers_) < 0) {\n> +\tif (video->exportBuffers(config.bufferCount, &buffers_) < 0) {\n>  \t\tstd::cout << \"Failed to export buffers\" << std::endl;\n>  \t\treturn TestFail;\n>  \t}\n>  \n> +\tvideo->close();\n> +\n>  \treturn TestPass;\n>  }\n>  \n> diff --git a/test/libtest/buffer_source.h b/test/libtest/buffer_source.h\n> index 2d8fc5acf6d7..ae0879c99480 100644\n> --- a/test/libtest/buffer_source.h\n> +++ b/test/libtest/buffer_source.h\n> @@ -25,7 +25,6 @@ public:\n>  \n>  private:\n>  \tstd::shared_ptr<MediaDevice> media_;\n> -\tV4L2VideoDevice *video_;\n>  \tstd::vector<std::unique_ptr<FrameBuffer>> buffers_;\n>  };\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D13426041A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Mar 2020 14:25:19 +0100 (CET)","by mail-lj1-x243.google.com with SMTP id o10so18610100ljc.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Mar 2020 06:25:19 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\tz18sm30833767ljm.15.2020.03.16.06.25.18\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 16 Mar 2020 06:25:18 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=Kc0vyHidpCz4uv8gc1AJgVmp31IyDGYOtbdf5bKqvbM=;\n\tb=zyxiL9NrnHjNomkWhu1ur3MBIDwn4kiLVtoKTMZakPChN+cq1InLT2jsfgqfa6SV3U\n\t9M1u9hn1GUcd9/PKzsSW+RpuSa3Q8vVYBrK8oghCt0zZhiOKGYCA4M2UKckhv38BAxNK\n\tzIfqB54bupvCEheIsUqjcSQy/gSRrJzWogQ90LT1bXLCgR28fdDXYwtKojKTwSzlqM01\n\tz8IATaYqgQGdSAmWwcfYJuCnszSiOHyOZSQ8uy8AIas0aZRV9SHTATJXVNaOE3iNoVeV\n\tKI38kyzs5Mmj/0jR3zqN5uUZD0plEfs4wrCumbYn03AaebHbsQoKVbOfuyb2KTOJdU9/\n\tS3PQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=Kc0vyHidpCz4uv8gc1AJgVmp31IyDGYOtbdf5bKqvbM=;\n\tb=leBBzNhMA1FptGJd62SetDGlvDSYtewzTq3LHsdF2lP+3iY10sCm+nCiKUbpvZuDW4\n\tZrVjLPiqBTrxg0CltXm6ALZncrIa6NigslHpUCFfKZa9duESh8JcBEqlTm8YPBL5QRC/\n\t8aiwRDh7PZJkB+Vr93z35sf29rYAn2XK1YgwP6gI/zHNm50B0KciYatL7XljlJezjFxD\n\tfPFax0TKQo09+vsTDmH7yUZBhEe8RgN2EmbHhWFfRe82hXLTi35g0W/GQAFX1u9L39MM\n\tnnkZr9D4d/VkuLTkkbMGNTo6DYLLfY9UbwojBDluFJuoKJgXTOFJQZZGdxSXTzW07kTl\n\tyTsQ==","X-Gm-Message-State":"ANhLgQ0mE/qwFMat2Mi5R6RnhIJi/2iq2Ocumtfg3AyUSS9l0tfe8R5L\n\tUtyHNFp5m7GsMkPefNJsQGwPlc3iAQc=","X-Google-Smtp-Source":"ADFU+vuZXceUSbF0w2y7oCBOqXugFDwkyHxHchyQIfJ9hv0WqzzwZY5eXXOqtAw1TkgM9NPhlpvAwQ==","X-Received":"by 2002:a05:651c:2006:: with SMTP id\n\ts6mr16374084ljo.251.1584365118942; \n\tMon, 16 Mar 2020 06:25:18 -0700 (PDT)","Date":"Mon, 16 Mar 2020 14:25:17 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200316132517.GA2260535@oden.dyn.berto.se>","References":"<20200314235728.15495-1-laurent.pinchart@ideasonboard.com>\n\t<20200314235728.15495-2-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200314235728.15495-2-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 1/9] test: libtest: buffer_source:\n\tClose video device right after allocation","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>","X-List-Received-Date":"Mon, 16 Mar 2020 13:25:20 -0000"}}]