{"id":19357,"url":"https://patchwork.libcamera.org/api/patches/19357/?format=json","web_url":"https://patchwork.libcamera.org/patch/19357/","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":"<20231230162912.827669-7-jacopo.mondi@ideasonboard.com>","date":"2023-12-30T16:29:11","name":"[libcamera-devel,v3,6/7] apps: lc-compliance: Support multiple streams in helpers","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"d64ddc0bc93c3b753e4b23127aa4d76c37c37f54","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19357/mbox/","series":[{"id":4129,"url":"https://patchwork.libcamera.org/api/series/4129/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4129","date":"2023-12-30T16:29:05","name":"apps: lc-compliance: Properties and multi-stream tests","version":3,"mbox":"https://patchwork.libcamera.org/series/4129/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19357/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19357/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 13E4FC3295\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 30 Dec 2023 16:29:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A297462B6B;\n\tSat, 30 Dec 2023 17:29:39 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 33BBE61D89\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 30 Dec 2023 17:29:34 +0100 (CET)","from localhost.localdomain (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C719C842;\n\tSat, 30 Dec 2023 17:28:36 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1703953779;\n\tbh=EhdxCrVxDYg8lvNpqpoeOFt5YT2l7CeYtsR80UGqVN0=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=iSu1DZ9+vJHb4KrbGzxWzMbRZack/jdZ/rcsXuKhOHzC+oCTrtgMigxU/73jVPTXP\n\tKQ071YvG/we5ZZjIaiBhE30UygrcPLSniNs8KYPGlO2LySmhCej06HhLQWlT2fRp9N\n\tOCH4RsaHhDGAtJOQzLRB56n23C0PmMRSjgUOOZo8+tP+wR3zV/Pl5a3giG6AG6NNOb\n\tjbM8Od7y1YhwjCN/sN+sTzm8O+c0p119WNIAI0Ka1fOi2fa8dTMu4xSolq1TQKU7pr\n\tB/vH4OeljF4uf7YpsVHD+4g3VocqYR8XEt7TE6rZGasfPhf0WAhwsyIjHp2YMytthH\n\t1l290O5C1wp+Q==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1703953717;\n\tbh=EhdxCrVxDYg8lvNpqpoeOFt5YT2l7CeYtsR80UGqVN0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=IffVZ7QYyL3Y4Bbxw0SK+xKtqYzF1tzNruxgL7+jbnaMZ3bE8YwhREplP0TC7z92E\n\tnUkXPBt8bkdBH4FzfgEd/2Xo4KMRASvAIZJkPXBK6rHo7azBzOd+TpAxfzme74s4+V\n\tuQrZEQZolpiPXjP50cr6Ztqjbcx2adGvDolQypiQ="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"IffVZ7QY\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 30 Dec 2023 17:29:11 +0100","Message-ID":"<20231230162912.827669-7-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.41.0","In-Reply-To":"<20231230162912.827669-1-jacopo.mondi@ideasonboard.com>","References":"<20231230162912.827669-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 6/7] apps: lc-compliance: Support\n\tmultiple streams in helpers","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","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\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/apps/lc-compliance/helpers/capture.cpp    | 85 ++++++++++++++-----\n src/apps/lc-compliance/helpers/capture.h      |  2 +-\n src/apps/lc-compliance/tests/capture_test.cpp | 26 +++---\n 3 files changed, 76 insertions(+), 37 deletions(-)","diff":"diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp\nindex 5aab973f0392..bb95af3d758c 100644\n--- a/src/apps/lc-compliance/helpers/capture.cpp\n+++ b/src/apps/lc-compliance/helpers/capture.cpp\n@@ -7,6 +7,8 @@\n \n #include \"capture.h\"\n \n+#include <algorithm>\n+\n #include <gtest/gtest.h>\n \n using namespace libcamera;\n@@ -22,15 +24,27 @@ Capture::~Capture()\n \tstop();\n }\n \n-void Capture::configure(StreamRole role)\n+void Capture::configure(Span<const StreamRole> roles)\n {\n-\tconfig_ = camera_->generateConfiguration({ role });\n+\tconfig_ = camera_->generateConfiguration(roles);\n \n \tif (!config_) {\n-\t\tstd::cout << \"Role not supported by camera\" << std::endl;\n+\t\tstd::cout << \"Roles not supported by camera\" << std::endl;\n \t\tGTEST_SKIP();\n \t}\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 [](StreamConfiguration &l, StreamConfiguration &r)\n+\t\t\t\t { return l.bufferCount < r.bufferCount; });\n+\n+\tfor (auto &stream : *config_)\n+\t\tstream.bufferCount = largest->bufferCount;\n+\n \tif (config_->validate() != CameraConfiguration::Valid) {\n \t\tconfig_.reset();\n \t\tFAIL() << \"Configuration not valid\";\n@@ -44,11 +58,17 @@ void Capture::configure(StreamRole role)\n \n void Capture::start()\n {\n-\tStream *stream = config_->at(0).stream();\n-\tint count = allocator_->allocate(stream);\n+\tunsigned int i = 0;\n+\tfor (auto const &config : *config_) {\n+\t\tStream *stream = config.stream();\n+\t\tint count = allocator_->allocate(stream);\n \n-\tASSERT_GE(count, 0) << \"Failed to allocate buffers\";\n-\tEXPECT_EQ(count, config_->at(0).bufferCount) << \"Allocated less buffers than expected\";\n+\t\tASSERT_GE(count, 0) << \"Failed to allocate buffers for stream \" << i;\n+\t\tEXPECT_EQ(count, config.bufferCount)\n+\t\t\t<< \"Allocated less buffers than expected for stream \" << i;\n+\n+\t\t++i;\n+\t}\n \n \tcamera_->requestCompleted.connect(this, &Capture::requestComplete);\n \n@@ -64,9 +84,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 (auto const &config : *config_) {\n+\t\tStream *stream = config.stream();\n+\t\tallocator_->free(stream);\n+\t}\n }\n \n /* CaptureBalanced */\n@@ -80,14 +103,12 @@ void CaptureBalanced::capture(unsigned int numRequests)\n {\n \tstart();\n \n-\tStream *stream = config_->at(0).stream();\n-\tconst std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator_->buffers(stream);\n-\n \t/* No point in testing less requests then the camera depth. */\n-\tif (buffers.size() > numRequests) {\n-\t\tstd::cout << \"Camera needs \" + std::to_string(buffers.size())\n-\t\t\t+ \" requests, can't test only \"\n-\t\t\t+ std::to_string(numRequests) << std::endl;\n+\tconst unsigned int bufferCount = config_->at(0).bufferCount;\n+\tif (bufferCount > numRequests) {\n+\t\tstd::cout << \"Camera needs \" << bufferCount\n+\t\t\t  << \" requests, can't test only \" << numRequests\n+\t\t\t  << std::endl;\n \t\tGTEST_SKIP();\n \t}\n \n@@ -96,11 +117,21 @@ void CaptureBalanced::capture(unsigned int numRequests)\n \tcaptureLimit_ = numRequests;\n \n \t/* Queue the recommended number of requests. */\n-\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\tfor (unsigned int bufferIdx = 0; bufferIdx < bufferCount; ++bufferIdx) {\n \t\tstd::unique_ptr<Request> request = camera_->createRequest();\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\t/* Add buffers for each stream. */\n+\t\tunsigned int i = 0;\n+\t\tfor (const auto &config : *config_) {\n+\t\t\tStream *stream = config.stream();\n+\t\t\tconst auto &buffers = allocator_->buffers(stream);\n+\n+\t\t\tASSERT_EQ(request->addBuffer(stream, buffers[bufferIdx].get()), 0)\n+\t\t\t\t<< \"Can't add buffers for stream \" << i;\n+\n+\t\t\t++i;\n+\t\t}\n \n \t\tASSERT_EQ(queueRequest(request.get()), 0) << \"Failed to queue request\";\n \n@@ -152,18 +183,26 @@ void CaptureUnbalanced::capture(unsigned int numRequests)\n {\n \tstart();\n \n-\tStream *stream = config_->at(0).stream();\n-\tconst std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator_->buffers(stream);\n-\n \tcaptureCount_ = 0;\n \tcaptureLimit_ = numRequests;\n \n \t/* Queue the recommended number of requests. */\n-\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\tconst unsigned int bufferCount = config_->at(0).bufferCount;\n+\tfor (unsigned int bufferIdx = 0; bufferIdx < bufferCount; ++bufferIdx) {\n \t\tstd::unique_ptr<Request> request = camera_->createRequest();\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\t/* Add buffers for each stream. */\n+\t\tunsigned int i = 0;\n+\t\tfor (const auto &config : *config_) {\n+\t\t\tStream *stream = config.stream();\n+\t\t\tconst auto &buffers = allocator_->buffers(stream);\n+\n+\t\t\tASSERT_EQ(request->addBuffer(stream, buffers[bufferIdx].get()), 0)\n+\t\t\t\t<< \"Can't add buffers for stream \" << i;\n+\n+\t\t\t++i;\n+\t\t}\n \n \t\tASSERT_EQ(camera_->queueRequest(request.get()), 0) << \"Failed to queue request\";\n \ndiff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h\nindex 0574ab1c7ac7..3e2b2889244d 100644\n--- a/src/apps/lc-compliance/helpers/capture.h\n+++ b/src/apps/lc-compliance/helpers/capture.h\n@@ -16,7 +16,7 @@\n class Capture\n {\n public:\n-\tvoid configure(libcamera::StreamRole role);\n+\tvoid configure(libcamera::Span<const libcamera::StreamRole> roles);\n \n protected:\n \tCapture(std::shared_ptr<libcamera::Camera> camera);\ndiff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp\nindex 284d36307619..3d3cc97791d9 100644\n--- a/src/apps/lc-compliance/tests/capture_test.cpp\n+++ b/src/apps/lc-compliance/tests/capture_test.cpp\n@@ -17,14 +17,14 @@\n using namespace libcamera;\n \n const std::vector<int> NUMREQUESTS = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };\n-const std::vector<StreamRole> ROLES = {\n-\tStreamRole::Raw,\n-\tStreamRole::StillCapture,\n-\tStreamRole::VideoRecording,\n-\tStreamRole::Viewfinder\n+const std::vector<std::vector<StreamRole>> ROLES = {\n+\t{ StreamRole::Raw },\n+\t{ StreamRole::StillCapture },\n+\t{ StreamRole::VideoRecording },\n+\t{ StreamRole::Viewfinder },\n };\n \n-class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>\n+class SingleStream : public testing::TestWithParam<std::tuple<std::vector<StreamRole>, int>>\n {\n public:\n \tstatic std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info);\n@@ -67,7 +67,7 @@ std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStre\n \t\t{ StreamRole::Viewfinder, \"Viewfinder\" }\n \t};\n \n-\tstd::string roleName = rolesMap[std::get<0>(info.param)];\n+\tstd::string roleName = rolesMap[std::get<0>(info.param)[0]];\n \tstd::string numRequestsName = std::to_string(std::get<1>(info.param));\n \n \treturn roleName + \"_\" + numRequestsName;\n@@ -82,11 +82,11 @@ std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStre\n  */\n TEST_P(SingleStream, Capture)\n {\n-\tauto [role, numRequests] = GetParam();\n+\tconst auto [role, numRequests] = GetParam();\n \n \tCaptureBalanced capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(Span<const StreamRole>{ role });\n \n \tcapture.capture(numRequests);\n }\n@@ -100,12 +100,12 @@ TEST_P(SingleStream, Capture)\n  */\n TEST_P(SingleStream, CaptureStartStop)\n {\n-\tauto [role, numRequests] = GetParam();\n+\tconst auto [role, numRequests] = GetParam();\n \tunsigned int numRepeats = 3;\n \n \tCaptureBalanced capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(Span<const StreamRole>{ role });\n \n \tfor (unsigned int starts = 0; starts < numRepeats; starts++)\n \t\tcapture.capture(numRequests);\n@@ -120,11 +120,11 @@ TEST_P(SingleStream, CaptureStartStop)\n  */\n TEST_P(SingleStream, UnbalancedStop)\n {\n-\tauto [role, numRequests] = GetParam();\n+\tconst auto [role, numRequests] = GetParam();\n \n \tCaptureUnbalanced capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(Span<const StreamRole>{ role });\n \n \tcapture.capture(numRequests);\n }\n","prefixes":["libcamera-devel","v3","6/7"]}