Show a patch.

GET /api/1.1/patches/19783/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 19783,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/19783/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19783/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240320101652.12873-4-jacopo.mondi@ideasonboard.com>",
    "date": "2024-03-20T10:16:50",
    "name": "[3/4] apps: lc-compliance: Support multiple streams in helpers",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "117815703b694867011cb97b313840e6b544cce3",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19783/mbox/",
    "series": [
        {
            "id": 4234,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4234/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4234",
            "date": "2024-03-20T10:16:47",
            "name": "apps: lc-compliance: Properties and multi-stream tests",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4234/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19783/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19783/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 ACE8CC32C3\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Mar 2024 10:17:12 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5547A62D3C;\n\tWed, 20 Mar 2024 11:17:09 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B21C61C5B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Mar 2024 11:17:05 +0100 (CET)",
            "from localhost.localdomain (unknown\n\t[IPv6:2001:b07:5d2e:52c9:cc1e:e404:491f:e6ea])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C886EB1;\n\tWed, 20 Mar 2024 11:16:37 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"fby09bR7\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710929798;\n\tbh=reHW3rV8XT6OttbOYl32USLYdnzSHXomL4YtHDSBGwY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=fby09bR7TcBANPh3tqkbcSMzxCH6VPHfNbY6tVviEBQv//uf0lWFOk+0QQb0GRgL+\n\thg1e7lnJAQom+YvkYtOIWhL9IcZhYnsiWMG4698jVo3qPF2RSzDZ9CC0dj6cpvwI/r\n\tjuAkouq6ZAIwqmB+1m1olJQftGOqGrZYtW+H4a9M=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>",
        "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",
        "Content-Transfer-Encoding": "8bit",
        "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\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Stefan Klug <stefan.klug@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..2fcaf7285eec 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": [
        "3/4"
    ]
}