Show a patch.

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

{
    "id": 22437,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/22437/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22437/",
    "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": "<20241220150759.709756-12-pobrn@protonmail.com>",
    "date": "2024-12-20T15:08:51",
    "name": "[RFC,v1,11/12] apps: lc-compliance: Support multiple streams in helpers",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "0741ce108b976298352f0a4680ff2ff39677e069",
    "submitter": {
        "id": 133,
        "url": "https://patchwork.libcamera.org/api/1.1/people/133/?format=api",
        "name": "Pőcze Barnabás",
        "email": "pobrn@protonmail.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22437/mbox/",
    "series": [
        {
            "id": 4923,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4923/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4923",
            "date": "2024-12-20T15:08:03",
            "name": "apps: lc-compliance: Multi-stream tests",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4923/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22437/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22437/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 21A3BC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Dec 2024 15:09:01 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7B856684B6;\n\tFri, 20 Dec 2024 16:09:00 +0100 (CET)",
            "from mail-40131.protonmail.ch (mail-40131.protonmail.ch\n\t[185.70.40.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 140FD684AE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Dec 2024 16:08:58 +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=\"pZ2QhNyS\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1734707336; x=1734966536;\n\tbh=C7RsNeSb066QbfUOWol90VEasHYTTm4kBKkdKoQGcKY=;\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=pZ2QhNySdCDVEPJ6vafbz1Gqr8Vp+gk8yrByfwV7ADxCjn0o2JVuYCMJasobOa1vJ\n\tT3IwY3wp63VYAwmomQPCcsdkeFbtBM0awhwrB7mGuZBxAud8ZCbD0d5TaeNRmjhOLu\n\tSRRwkua3gqB9UzbisnoR3sGOU+OCJSbjLsBjg4SWd+YE6pRdHYajxj+DxiQ6Mp5+o6\n\to5k+bSORiWrPWmssrQ2iVe/45VSOehlCuBDBsn2yRkqph46ocsnnq6fCIPzHV4N4oG\n\tiNyccoljpZeFUi6LvATwiBLy9Pltvfe2FK9A0ih8lSr9AFnNfBfilVeFyCMMhoPYiP\n\tgRr/aDmTEWvYA==",
        "Date": "Fri, 20 Dec 2024 15:08:51 +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>",
        "Subject": "[RFC PATCH v1 11/12] apps: lc-compliance: Support multiple streams\n\tin helpers",
        "Message-ID": "<20241220150759.709756-12-pobrn@protonmail.com>",
        "In-Reply-To": "<20241220150759.709756-1-pobrn@protonmail.com>",
        "References": "<20241220150759.709756-1-pobrn@protonmail.com>",
        "Feedback-ID": "20568564:user:proton",
        "X-Pm-Message-ID": "24cc50e67843f5a4cf4c8658dab53a16b8dc8fca",
        "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>\n---\n src/apps/lc-compliance/helpers/capture.cpp    | 83 ++++++++++++++-----\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(+), 25 deletions(-)",
    "diff": "diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp\nindex 7a05be9a3..38edb6f28 100644\n--- a/src/apps/lc-compliance/helpers/capture.cpp\n+++ b/src/apps/lc-compliance/helpers/capture.cpp\n@@ -24,15 +24,29 @@ 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\tstd::cout << \"Role 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 [](const StreamConfiguration &l, const StreamConfiguration &r)\n+\t\t\t\t { return l.bufferCount < r.bufferCount; });\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@@ -46,12 +60,20 @@ 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+\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\tASSERT_EQ(count, allocator_.buffers(stream).size()) << \"Unexpected number of buffers in allocator\";\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_EQ(count, allocator_.buffers(stream).size()) << \"Unexpected number of buffers in allocator\";\n+\tASSERT_TRUE(allocator_.allocated());\n \n \tcamera_->requestCompleted.connect(this, &Capture::requestComplete);\n \n@@ -71,9 +93,14 @@ 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 res = allocator_.free(cfg.stream());\n+\t\tASSERT_EQ(res, 0) << \"Failed to free buffers associated with stream\";\n+\t}\n+\n+\tASSERT_FALSE(allocator_.allocated());\n }\n \n void Capture::prepareRequests(unsigned int plannedRequests)\n@@ -81,22 +108,36 @@ void Capture::prepareRequests(unsigned int plannedRequests)\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-\t/* No point in testing less requests then the camera depth. */\n-\tif (plannedRequests < buffers.size()) {\n-\t\tstd::cout << \"Camera needs \" << buffers.size()\n-\t\t\t  << \" requests, can't test only \"\n-\t\t\t  << plannedRequests << std::endl;\n-\t\tGTEST_SKIP();\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\t/* No point in testing less requests then the camera depth. */\n+\t\tif (plannedRequests < buffers.size()) {\n+\t\t\tstd::cout << \"Camera needs \" << buffers.size()\n+\t\t\t\t  << \" requests, can't test only \"\n+\t\t\t\t  << plannedRequests << std::endl;\n+\t\t\tGTEST_SKIP();\n+\t\t}\n+\n+\t\tmaxBuffers = std::max(maxBuffers, buffers.size());\n \t}\n \n-\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n-\t\tstd::unique_ptr<Request> request = camera_->createRequest();\n-\t\tASSERT_TRUE(request) << \"Can't create request\";\n+\tfor (std::size_t i = 0; i < maxBuffers; i++) {\n+\t\tstd::unique_ptr<Request> request = camera_->createRequest(i);\n+\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\tASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << \"Can't set buffer for request\";\n+\t\t\tif (i < buffers.size()) {\n+\t\t\t\tASSERT_EQ(request->addBuffer(stream, buffers[i].get()), 0)\n+\t\t\t\t\t<< \"Can't add buffer to request\";\n+\t\t\t}\n+\t\t}\n \n \t\trequests_.push_back(std::move(request));\n \t}\ndiff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h\nindex 67c29021b..b3a390941 100644\n--- a/src/apps/lc-compliance/helpers/capture.h\n+++ b/src/apps/lc-compliance/helpers/capture.h\n@@ -17,7 +17,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 97465a612..c382fcf47 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 \tCaptureBalanced capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(std::array{ role });\n \n \tcapture.capture(numRequests);\n }\n@@ -108,7 +108,7 @@ TEST_P(SingleStream, CaptureStartStop)\n \n \tCaptureBalanced 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.capture(numRequests);\n@@ -127,7 +127,7 @@ TEST_P(SingleStream, UnbalancedStop)\n \n \tCaptureUnbalanced capture(camera_);\n \n-\tcapture.configure(role);\n+\tcapture.configure(std::array{ role });\n \n \tcapture.capture(numRequests);\n }\n",
    "prefixes": [
        "RFC",
        "v1",
        "11/12"
    ]
}