{"id":3094,"url":"https://patchwork.libcamera.org/api/patches/3094/?format=json","web_url":"https://patchwork.libcamera.org/patch/3094/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200314235728.15495-2-laurent.pinchart@ideasonboard.com>","date":"2020-03-14T23:57:20","name":"[libcamera-devel,1/9] test: libtest: buffer_source: Close video device right after allocation","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"3668f75dc514cf1e0061555f3d3b5c53a053b26a","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3094/mbox/","series":[{"id":719,"url":"https://patchwork.libcamera.org/api/series/719/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=719","date":"2020-03-14T23:57:19","name":"Simplify buffer management with V4L2 buffer orphaning","version":1,"mbox":"https://patchwork.libcamera.org/series/719/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3094/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3094/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9CEC5628BD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 15 Mar 2020 00:57:40 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E0C0A1163\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 15 Mar 2020 00:57:39 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584230260;\n\tbh=tS/Qhjaj/Mk9qvlplVy+zXORf+c3A/+tFfh6GxIz5C8=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=hcvnmiKFH//6OqJ2xzOKCAarw1J7wh/LhRynvypsgZ+NitEbfXA/W0ekXeO7KF7M0\n\tUisvsN0POEEXjWZ+sbXjl1OMBYsMuQdpkAZ7YdySQe1kk5PzcAIBi0juNvNPAUW8WL\n\tzI9GPmN1Cvyn4NhSMeiGNs3fchO1a9JJYFgVaLtQ=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 15 Mar 2020 01:57:20 +0200","Message-Id":"<20200314235728.15495-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200314235728.15495-1-laurent.pinchart@ideasonboard.com>","References":"<20200314235728.15495-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/9] test: libtest: buffer_source: Close\n\tvideo 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":"Sat, 14 Mar 2020 23:57:40 -0000"},"content":"There's no need to keep the video device open after allocating buffers,\nas V4L2 supports buffer orphaning and the exported buffers will still be\nusable. Close the device right after allocation to avoid the need for\ndelayed cleanups.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/libtest/buffer_source.cpp | 24 +++++++++---------------\n test/libtest/buffer_source.h   |  1 -\n 2 files changed, 9 insertions(+), 16 deletions(-)","diff":"diff --git a/test/libtest/buffer_source.cpp b/test/libtest/buffer_source.cpp\nindex 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 \ndiff --git a/test/libtest/buffer_source.h b/test/libtest/buffer_source.h\nindex 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","prefixes":["libcamera-devel","1/9"]}