{"id":22683,"url":"https://patchwork.libcamera.org/api/patches/22683/?format=json","web_url":"https://patchwork.libcamera.org/patch/22683/","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":"<20250130115001.1129305-18-pobrn@protonmail.com>","date":"2025-01-30T11:51:28","name":"[RFC,v3,17/21] apps: lc-compliance: Support multiple streams in helpers","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"cae3de92ba125b7754950ce2dbea5cdb31cde967","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/?format=json","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22683/mbox/","series":[{"id":4978,"url":"https://patchwork.libcamera.org/api/series/4978/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4978","date":"2025-01-30T11:50:08","name":"apps: lc-compliance: Multi-stream tests","version":3,"mbox":"https://patchwork.libcamera.org/series/4978/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22683/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22683/checks/","tags":{},"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 6847DBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Jan 2025 11:52:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 30C3068590;\n\tThu, 30 Jan 2025 12:52:22 +0100 (CET)","from mail-4322.protonmail.ch (mail-4322.protonmail.ch\n\t[185.70.43.22])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B56706857B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jan 2025 12:52:20 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"P23UArn6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1738237940; x=1738497140;\n\tbh=eujMRioviBy1qABpNpdEduEvC9g1+hm76ZmEmG9g2ow=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=P23UArn6MnDV0wVPyo5nR2o+TiqM2PSpFwZq/ID6smmcj+0lfO6SxdseYDj+Cukqm\n\tVic/nu7E+wnwmcHU+SYH4BCBQmTw4JHJ8HIltwkyrbdZzDvQvlP8cRAjfPhTY676Ne\n\t5iaWDb3NtXr+QzLjaLdJUH0o7yz5REk+AZK8eQjSfk3JoBr4osOlmhFutrlpXqjnJC\n\tNs8Afb3++26AQpokFaLdFp0oFC4HCJX12R5ncPsvshyDI9dmeqR2MUp2Gi608RzTbH\n\t4qkyyt2tiTXeiaZu7veGe2FFecfZJ7dwyf6wfpc3OHaDT6JSh5o2YBGn4Qkie78gfe\n\tsyej0l7EI1uiA==","Date":"Thu, 30 Jan 2025 11:51:28 +0000","To":"libcamera-devel@lists.libcamera.org","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"[RFC PATCH v3 17/21] apps: lc-compliance: Support multiple streams\n\tin helpers","Message-ID":"<20250130115001.1129305-18-pobrn@protonmail.com>","In-Reply-To":"<20250130115001.1129305-1-pobrn@protonmail.com>","References":"<20250130115001.1129305-1-pobrn@protonmail.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"1188264907a062b340aa2fcee355670b4b6615e5","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Prepare to add a test suite for capture operations with multiple\nstreams.\n\nModify the Capture helper class to support multiple roles and streams\nin the configure() and capture() operations.\n\nMulti-stream support will be added in next patches.\n\nCo-developed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/apps/lc-compliance/helpers/capture.cpp    | 77 +++++++++++++++----\n src/apps/lc-compliance/helpers/capture.h      |  2 +-\n src/apps/lc-compliance/tests/capture_test.cpp |  6 +-\n 3 files changed, 66 insertions(+), 19 deletions(-)","diff":"diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp\nindex 940646f6c..4a8627662 100644\n--- a/src/apps/lc-compliance/helpers/capture.cpp\n+++ b/src/apps/lc-compliance/helpers/capture.cpp\n@@ -24,13 +24,31 @@ Capture::~Capture()\n \tstop();\n }\n \n-void Capture::configure(StreamRole role)\n+void Capture::configure(libcamera::Span<const libcamera::StreamRole> roles)\n {\n-\tconfig_ = camera_->generateConfiguration({ role });\n+\tassert(!roles.empty());\n+\n+\tconfig_ = camera_->generateConfiguration(roles);\n \n \tif (!config_)\n \t\tGTEST_SKIP() << \"Role not supported by camera\";\n \n+\tASSERT_EQ(config_->size(), roles.size()) << \"Unexpected number of streams in configuration\";\n+\n+\t/*\n+\t * Set the buffers count to the largest value across all streams.\n+\t * \\todo: Should all streams from a Camera have the same buffer count ?\n+\t */\n+\tauto largest =\n+\t\tstd::max_element(config_->begin(), config_->end(),\n+\t\t\t\t [](const StreamConfiguration &l, const StreamConfiguration &r)\n+\t\t\t\t { return l.bufferCount < r.bufferCount; });\n+\n+\tassert(largest != config_->end());\n+\n+\tfor (auto &cfg : *config_)\n+\t\tcfg.bufferCount = largest->bufferCount;\n+\n \tif (config_->validate() != CameraConfiguration::Valid) {\n \t\tconfig_.reset();\n \t\tFAIL() << \"Configuration not valid\";\n@@ -74,20 +92,36 @@ void Capture::prepareRequests()\n \tassert(config_);\n \tassert(requests_.empty());\n \n-\tStream *stream = config_->at(0).stream();\n-\tconst std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator_.buffers(stream);\n+\tstd::size_t maxBuffers = 0;\n+\n+\tfor (const auto &cfg : *config_) {\n+\t\tconst auto &buffers = allocator_.buffers(cfg.stream());\n+\t\tASSERT_FALSE(buffers.empty()) << \"Zero buffers allocated for stream\";\n+\n+\t\tmaxBuffers = std::max(maxBuffers, buffers.size());\n+\t}\n \n \t/* No point in testing less requests then the camera depth. */\n-\tif (queueLimit_ && *queueLimit_ < buffers.size()) {\n-\t\tGTEST_SKIP() << \"Camera needs \" << buffers.size()\n+\tif (queueLimit_ && *queueLimit_ < maxBuffers) {\n+\t\tGTEST_SKIP() << \"Camera needs \" << maxBuffers\n \t\t\t     << \" requests, can't test only \" << *queueLimit_;\n \t}\n \n-\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n-\t\tstd::unique_ptr<Request> request = camera_->createRequest();\n+\tfor (std::size_t i = 0; i < maxBuffers; i++) {\n+\t\tstd::unique_ptr<Request> request = camera_->createRequest(i);\n \t\tASSERT_TRUE(request) << \"Can't create request\";\n \n-\t\tASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << \"Can't set buffer for request\";\n+\t\tfor (const auto &cfg : *config_) {\n+\t\t\tStream *stream = cfg.stream();\n+\t\t\tconst auto &buffers = allocator_.buffers(stream);\n+\t\t\tassert(!buffers.empty());\n+\n+\t\t\tif (i >= buffers.size())\n+\t\t\t\tcontinue;\n+\n+\t\t\tASSERT_EQ(request->addBuffer(stream, buffers[i].get()), 0)\n+\t\t\t\t<< \"Can't add buffer to request\";\n+\t\t}\n \n \t\trequests_.push_back(std::move(request));\n \t}\n@@ -124,11 +158,19 @@ void Capture::requestComplete(Request *request)\n \n void Capture::start()\n {\n-\tStream *stream = config_->at(0).stream();\n-\tint count = allocator_.allocate(stream);\n+\tassert(config_);\n+\tassert(!config_->empty());\n+\tassert(!allocator_.allocated());\n+\n+\tfor (const auto &cfg : *config_) {\n+\t\tStream *stream = cfg.stream();\n+\t\tint count = allocator_.allocate(stream);\n+\n+\t\tASSERT_GE(count, 0) << \"Failed to allocate buffers\";\n+\t\tEXPECT_EQ(count, cfg.bufferCount) << \"Allocated less buffers than expected\";\n+\t}\n \n-\tASSERT_GE(count, 0) << \"Failed to allocate buffers\";\n-\tEXPECT_EQ(count, config_->at(0).bufferCount) << \"Allocated less buffers than expected\";\n+\tASSERT_TRUE(allocator_.allocated());\n \n \tcamera_->requestCompleted.connect(this, &Capture::requestComplete);\n \n@@ -144,7 +186,12 @@ void Capture::stop()\n \n \tcamera_->requestCompleted.disconnect(this);\n \n-\tStream *stream = config_->at(0).stream();\n \trequests_.clear();\n-\tallocator_.free(stream);\n+\n+\tfor (const auto &cfg : *config_) {\n+\t\tint ret = allocator_.free(cfg.stream());\n+\t\tEXPECT_EQ(ret, 0) << \"Failed to free buffers associated with stream\";\n+\t}\n+\n+\tEXPECT_FALSE(allocator_.allocated());\n }\ndiff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h\nindex ede395e2a..48a8dadcb 100644\n--- a/src/apps/lc-compliance/helpers/capture.h\n+++ b/src/apps/lc-compliance/helpers/capture.h\n@@ -20,7 +20,7 @@ public:\n \tCapture(std::shared_ptr<libcamera::Camera> camera);\n \t~Capture();\n \n-\tvoid configure(libcamera::StreamRole role);\n+\tvoid configure(libcamera::Span<const libcamera::StreamRole> roles);\n \tvoid run(unsigned int captureLimit, std::optional<unsigned int> queueLimit = {});\n \n private:\ndiff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp\nindex 93bed48f0..147e17019 100644\n--- a/src/apps/lc-compliance/tests/capture_test.cpp\n+++ b/src/apps/lc-compliance/tests/capture_test.cpp\n@@ -89,7 +89,7 @@ TEST_P(SingleStream, Capture)\n \n \tCapture capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(std::array{ role });\n \n \tcapture.run(numRequests, numRequests);\n }\n@@ -108,7 +108,7 @@ TEST_P(SingleStream, CaptureStartStop)\n \n \tCapture capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(std::array{ role });\n \n \tfor (unsigned int starts = 0; starts < numRepeats; starts++)\n \t\tcapture.run(numRequests, numRequests);\n@@ -127,7 +127,7 @@ TEST_P(SingleStream, UnbalancedStop)\n \n \tCapture capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(std::array{ role });\n \n \tcapture.run(numRequests);\n }\n","prefixes":["RFC","v3","17/21"]}