From patchwork Wed Mar 20 10:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19783 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 ACE8CC32C3 for ; Wed, 20 Mar 2024 10:17:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5547A62D3C; Wed, 20 Mar 2024 11:17:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fby09bR7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B21C61C5B for ; Wed, 20 Mar 2024 11:17:05 +0100 (CET) Received: from localhost.localdomain (unknown [IPv6:2001:b07:5d2e:52c9:cc1e:e404:491f:e6ea]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C886EB1; Wed, 20 Mar 2024 11:16:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1710929798; bh=reHW3rV8XT6OttbOYl32USLYdnzSHXomL4YtHDSBGwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fby09bR7TcBANPh3tqkbcSMzxCH6VPHfNbY6tVviEBQv//uf0lWFOk+0QQb0GRgL+ hg1e7lnJAQom+YvkYtOIWhL9IcZhYnsiWMG4698jVo3qPF2RSzDZ9CC0dj6cpvwI/r juAkouq6ZAIwqmB+1m1olJQftGOqGrZYtW+H4a9M= From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Stefan Klug Subject: [PATCH 3/4] apps: lc-compliance: Support multiple streams in helpers Date: Wed, 20 Mar 2024 11:16:50 +0100 Message-ID: <20240320101652.12873-4-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320101652.12873-1-jacopo.mondi@ideasonboard.com> References: <20240320101652.12873-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 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" Prepare to add a test suite for capture operations with multiple streams. Modify the Capture helper class to support multiple roles and streams in the configure() and capture() operations. Multi-stream support will be added in next patches. Signed-off-by: Jacopo Mondi Reviewed-by: Stefan Klug --- src/apps/lc-compliance/helpers/capture.cpp | 85 ++++++++++++++----- src/apps/lc-compliance/helpers/capture.h | 2 +- src/apps/lc-compliance/tests/capture_test.cpp | 26 +++--- 3 files changed, 76 insertions(+), 37 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 5aab973f0392..2fcaf7285eec 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -7,6 +7,8 @@ #include "capture.h" +#include + #include using namespace libcamera; @@ -22,15 +24,27 @@ Capture::~Capture() stop(); } -void Capture::configure(StreamRole role) +void Capture::configure(Span roles) { - config_ = camera_->generateConfiguration({ role }); + config_ = camera_->generateConfiguration(roles); if (!config_) { - std::cout << "Role not supported by camera" << std::endl; + std::cout << "Roles not supported by camera" << std::endl; GTEST_SKIP(); } + /* + * Set the buffers count to the largest value across all streams. + * \todo: Should all streams from a Camera have the same buffer count ? + */ + auto largest = + std::max_element(config_->begin(), config_->end(), + [](StreamConfiguration &l, StreamConfiguration &r) + { return l.bufferCount < r.bufferCount; }); + + for (auto &stream : *config_) + stream.bufferCount = largest->bufferCount; + if (config_->validate() != CameraConfiguration::Valid) { config_.reset(); FAIL() << "Configuration not valid"; @@ -44,11 +58,17 @@ void Capture::configure(StreamRole role) void Capture::start() { - Stream *stream = config_->at(0).stream(); - int count = allocator_->allocate(stream); + unsigned int i = 0; + for (auto const &config : *config_) { + Stream *stream = config.stream(); + int count = allocator_->allocate(stream); - ASSERT_GE(count, 0) << "Failed to allocate buffers"; - EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected"; + ASSERT_GE(count, 0) << "Failed to allocate buffers for stream " << i; + EXPECT_EQ(count, config.bufferCount) + << "Allocated less buffers than expected for stream " << i; + + ++i; + } camera_->requestCompleted.connect(this, &Capture::requestComplete); @@ -64,9 +84,12 @@ void Capture::stop() camera_->requestCompleted.disconnect(this); - Stream *stream = config_->at(0).stream(); requests_.clear(); - allocator_->free(stream); + + for (auto const &config : *config_) { + Stream *stream = config.stream(); + allocator_->free(stream); + } } /* CaptureBalanced */ @@ -80,14 +103,12 @@ void CaptureBalanced::capture(unsigned int numRequests) { start(); - Stream *stream = config_->at(0).stream(); - const std::vector> &buffers = allocator_->buffers(stream); - /* No point in testing less requests then the camera depth. */ - if (buffers.size() > numRequests) { - std::cout << "Camera needs " + std::to_string(buffers.size()) - + " requests, can't test only " - + std::to_string(numRequests) << std::endl; + const unsigned int bufferCount = config_->at(0).bufferCount; + if (bufferCount > numRequests) { + std::cout << "Camera needs " << bufferCount + << " requests, can't test only " << numRequests + << std::endl; GTEST_SKIP(); } @@ -96,11 +117,21 @@ void CaptureBalanced::capture(unsigned int numRequests) captureLimit_ = numRequests; /* Queue the recommended number of requests. */ - for (const std::unique_ptr &buffer : buffers) { + for (unsigned int bufferIdx = 0; bufferIdx < bufferCount; ++bufferIdx) { std::unique_ptr request = camera_->createRequest(); ASSERT_TRUE(request) << "Can't create request"; - ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; + /* Add buffers for each stream. */ + unsigned int i = 0; + for (const auto &config : *config_) { + Stream *stream = config.stream(); + const auto &buffers = allocator_->buffers(stream); + + ASSERT_EQ(request->addBuffer(stream, buffers[bufferIdx].get()), 0) + << "Can't add buffers for stream " << i; + + ++i; + } ASSERT_EQ(queueRequest(request.get()), 0) << "Failed to queue request"; @@ -152,18 +183,26 @@ void CaptureUnbalanced::capture(unsigned int numRequests) { start(); - Stream *stream = config_->at(0).stream(); - const std::vector> &buffers = allocator_->buffers(stream); - captureCount_ = 0; captureLimit_ = numRequests; /* Queue the recommended number of requests. */ - for (const std::unique_ptr &buffer : buffers) { + const unsigned int bufferCount = config_->at(0).bufferCount; + for (unsigned int bufferIdx = 0; bufferIdx < bufferCount; ++bufferIdx) { std::unique_ptr request = camera_->createRequest(); ASSERT_TRUE(request) << "Can't create request"; - ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; + /* Add buffers for each stream. */ + unsigned int i = 0; + for (const auto &config : *config_) { + Stream *stream = config.stream(); + const auto &buffers = allocator_->buffers(stream); + + ASSERT_EQ(request->addBuffer(stream, buffers[bufferIdx].get()), 0) + << "Can't add buffers for stream " << i; + + ++i; + } ASSERT_EQ(camera_->queueRequest(request.get()), 0) << "Failed to queue request"; diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index 0574ab1c7ac7..3e2b2889244d 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -16,7 +16,7 @@ class Capture { public: - void configure(libcamera::StreamRole role); + void configure(libcamera::Span roles); protected: Capture(std::shared_ptr camera); diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index 284d36307619..3d3cc97791d9 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -17,14 +17,14 @@ using namespace libcamera; const std::vector NUMREQUESTS = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; -const std::vector ROLES = { - StreamRole::Raw, - StreamRole::StillCapture, - StreamRole::VideoRecording, - StreamRole::Viewfinder +const std::vector> ROLES = { + { StreamRole::Raw }, + { StreamRole::StillCapture }, + { StreamRole::VideoRecording }, + { StreamRole::Viewfinder }, }; -class SingleStream : public testing::TestWithParam> +class SingleStream : public testing::TestWithParam, int>> { public: static std::string nameParameters(const testing::TestParamInfo &info); @@ -67,7 +67,7 @@ std::string SingleStream::nameParameters(const testing::TestParamInfo(info.param)]; + std::string roleName = rolesMap[std::get<0>(info.param)[0]]; std::string numRequestsName = std::to_string(std::get<1>(info.param)); return roleName + "_" + numRequestsName; @@ -82,11 +82,11 @@ std::string SingleStream::nameParameters(const testing::TestParamInfo{ role }); capture.capture(numRequests); } @@ -100,12 +100,12 @@ TEST_P(SingleStream, Capture) */ TEST_P(SingleStream, CaptureStartStop) { - auto [role, numRequests] = GetParam(); + const auto [role, numRequests] = GetParam(); unsigned int numRepeats = 3; CaptureBalanced capture(camera_); - capture.configure(role); + capture.configure(Span{ role }); for (unsigned int starts = 0; starts < numRepeats; starts++) capture.capture(numRequests); @@ -120,11 +120,11 @@ TEST_P(SingleStream, CaptureStartStop) */ TEST_P(SingleStream, UnbalancedStop) { - auto [role, numRequests] = GetParam(); + const auto [role, numRequests] = GetParam(); CaptureUnbalanced capture(camera_); - capture.configure(role); + capture.configure(Span{ role }); capture.capture(numRequests); }