From patchwork Sat Mar 14 23:57:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3094 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9CEC5628BD for ; Sun, 15 Mar 2020 00:57:40 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E0C0A1163 for ; Sun, 15 Mar 2020 00:57:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584230260; bh=tS/Qhjaj/Mk9qvlplVy+zXORf+c3A/+tFfh6GxIz5C8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hcvnmiKFH//6OqJ2xzOKCAarw1J7wh/LhRynvypsgZ+NitEbfXA/W0ekXeO7KF7M0 UisvsN0POEEXjWZ+sbXjl1OMBYsMuQdpkAZ7YdySQe1kk5PzcAIBi0juNvNPAUW8WL zI9GPmN1Cvyn4NhSMeiGNs3fchO1a9JJYFgVaLtQ= From: Laurent Pinchart 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 Subject: [libcamera-devel] [PATCH 1/9] test: libtest: buffer_source: Close video device right after allocation 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: , X-List-Received-Date: Sat, 14 Mar 2020 23:57:40 -0000 There's no need to keep the video device open after allocating buffers, as V4L2 supports buffer orphaning and the exported buffers will still be usable. Close the device right after allocation to avoid the need for delayed cleanups. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/libtest/buffer_source.cpp | 24 +++++++++--------------- test/libtest/buffer_source.h | 1 - 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/test/libtest/buffer_source.cpp b/test/libtest/buffer_source.cpp index 066049d342a4..0c33200b47ad 100644 --- a/test/libtest/buffer_source.cpp +++ b/test/libtest/buffer_source.cpp @@ -8,26 +8,18 @@ #include "buffer_source.h" #include +#include #include "device_enumerator.h" #include "test.h" BufferSource::BufferSource() - : video_(nullptr) { } BufferSource::~BufferSource() { - if (video_) { - video_->releaseBuffers(); - video_->close(); - } - - delete video_; - video_ = nullptr; - if (media_) media_->release(); } @@ -58,37 +50,39 @@ int BufferSource::allocate(const StreamConfiguration &config) return TestSkip; } - video_ = V4L2VideoDevice::fromEntityName(media_.get(), videoDeviceName); - if (!video_) { + std::unique_ptr video{ V4L2VideoDevice::fromEntityName(media_.get(), videoDeviceName) }; + if (!video) { std::cout << "Failed to get video device from entity " << videoDeviceName << std::endl; return TestFail; } - if (video_->open()) { + if (video->open()) { std::cout << "Unable to open " << videoDeviceName << std::endl; return TestFail; } /* Configure the format. */ V4L2DeviceFormat format; - if (video_->getFormat(&format)) { + if (video->getFormat(&format)) { std::cout << "Failed to get format on output device" << std::endl; return TestFail; } format.size = config.size; format.fourcc = V4L2VideoDevice::toV4L2Fourcc(config.pixelFormat, false); - if (video_->setFormat(&format)) { + if (video->setFormat(&format)) { std::cout << "Failed to set format on output device" << std::endl; return TestFail; } - if (video_->exportBuffers(config.bufferCount, &buffers_) < 0) { + if (video->exportBuffers(config.bufferCount, &buffers_) < 0) { std::cout << "Failed to export buffers" << std::endl; return TestFail; } + video->close(); + return TestPass; } diff --git a/test/libtest/buffer_source.h b/test/libtest/buffer_source.h index 2d8fc5acf6d7..ae0879c99480 100644 --- a/test/libtest/buffer_source.h +++ b/test/libtest/buffer_source.h @@ -25,7 +25,6 @@ public: private: std::shared_ptr media_; - V4L2VideoDevice *video_; std::vector> buffers_; };