From patchwork Fri Dec 20 15:08:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22427 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 A8F5EC32A3 for ; Fri, 20 Dec 2024 15:08:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67F64684A0; Fri, 20 Dec 2024 16:08:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="MLoo/+/B"; dkim-atps=neutral Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 14A3A6849E for ; Fri, 20 Dec 2024 16:08:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707291; x=1734966491; bh=jZy8XuWNRqLwwW3t3QvEKlj3uyBz5Bvo2lxFkZ+OqRA=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=MLoo/+/BGheQsn4ebnDC5kHX6ZveSmWZbprF42D8oxeaWge+4goug/ffg9lZW0U+V bHS3f04U2Lrs19aPkQ6kUbLLZt5LVxlpJrjGEE+osXUNG3sZ3ePjOMaxHoCC1WtliB OX/esV++xG1ceO8zvWbHgh8v4YtVSOcBMdfJVEoa693UJMlqoBg1aFQU2VDMsSmWrP X5yvbKaqb44GYFkzHDUV4eH07dVCrR9Iw8uvLQ/ORmj1D6ms0jg9Ln5vJOEuWLcVak 5JMMeSYVQ9cqtCI6gH7k6/Kt8C9pJqpzoU493toy6oXjJwuBMJn6maC1bYsvABzXWQ 9NuvJn2enmksg== Date: Fri, 20 Dec 2024 15:08:08 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 01/12] apps: lc-compliance: Initialize `CameraManager` pointer in `Environment` Message-ID: <20241220150759.709756-2-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: d35015acd4474a8ed00a445135960d9c883d29c7 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" Do not leave it unitialized. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/lc-compliance/environment.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/lc-compliance/environment.h b/src/apps/lc-compliance/environment.h index 543e5372f..834c722ef 100644 --- a/src/apps/lc-compliance/environment.h +++ b/src/apps/lc-compliance/environment.h @@ -23,5 +23,5 @@ private: Environment() = default; std::string cameraId_; - libcamera::CameraManager *cm_; + libcamera::CameraManager *cm_ = nullptr; }; From patchwork Fri Dec 20 15:08:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22428 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 9972FC32A3 for ; Fri, 20 Dec 2024 15:08:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7E796849F; Fri, 20 Dec 2024 16:08:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="OtkMhzlC"; dkim-atps=neutral Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 486E36848B for ; Fri, 20 Dec 2024 16:08:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707296; x=1734966496; bh=TEMqMhwBjwgv1GXGoLDXfpOM5BvQk1Ljn2pIyE6G96c=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=OtkMhzlCgJwTmd8jRxVrlI+CWTkwa2m0vKYGdhcQ1BNQ210u4hasa5E3Efg6b27E4 rShCytd0AW0K+xvx6YVVFpSllM+du8aci/PdE4WfV73pDqAaVjxfcQ5r982Fd2RmZE UzTDan/2UV3EA7ZtscKLif+tvz4mi0cyBrHlvTb4YskxRuUcgRMUV2Zhjoo458TrCX iLqftJXHeP+xkdtaFZyV48SG7AzyoVUuqosuPDxjDPjzdBxkknxGPUj9PvsbD1sxj9 3ApnyNQ4Iz4wkUzfk3GxLNxFwEXY+UxGmxRmkLT+cCx1BG2NcfbgAbNGCKP/aE54Kp 7YDwXxam2Z0DQ== Date: Fri, 20 Dec 2024 15:08:12 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 02/12] apps: lc-compliance: Put tests into anonymous namespace Message-ID: <20241220150759.709756-3-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: 706dd424fabac6076807cf2bf3c39129d3faab2e 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" There is no reason for these symbols to be global. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/lc-compliance/tests/capture_test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index ad3a1da2f..db196a949 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -14,6 +14,8 @@ #include "environment.h" +namespace { + using namespace libcamera; const std::vector NUMREQUESTS = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; @@ -134,3 +136,5 @@ INSTANTIATE_TEST_SUITE_P(CaptureTests, testing::Combine(testing::ValuesIn(ROLES), testing::ValuesIn(NUMREQUESTS)), SingleStream::nameParameters); + +} /* namespace */ From patchwork Fri Dec 20 15:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22429 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 A85BAC32A3 for ; Fri, 20 Dec 2024 15:08:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 53E0B684A0; Fri, 20 Dec 2024 16:08:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="TVPEvluZ"; dkim-atps=neutral Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 38C376849E for ; Fri, 20 Dec 2024 16:08:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707299; x=1734966499; bh=pwaQhfWHfVNVY1zJGMttEXuyS9NybpqmvbpovBtNc3U=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=TVPEvluZiObBLb0HGAMyEUqg6797Vj5eLzm85gt8rrN4KQ+WZjMK/b22sDnMkHrKX zkLAN5eNJvVyaC7Sy42TV5gbTi2Jk9FnwIK3rrJjXaS9HoWWq5bt97Q/Nj/BfUuFa+ NjcbZ8vZDcM/k4+aDyqe4NcMCnvtXUz++P6CCYoPTn4mKZ7rIRLilVulO6va/a/oZe 1EEEdgG2XjS6agfFFLHlyBH6/KCvbZ0H0JyxH4F6L1gSxnYchp3ep8by5sY00dYFgB bssjbii7WIMNMS3Naos/VrAFL8dlt2HnPRrTJyaizb9FZdKIUA++r5cgm88eIvwOAy ajqSeVF0GcEaQ== Date: Fri, 20 Dec 2024 15:08:16 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 03/12] apps: lc-compliance: Optimize `std::shared_ptr` usage Message-ID: <20241220150759.709756-4-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: 57757501e3233cb17a3146087151df1c29e161fb 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" Avoid unnecessary copies and try to move construct `std::shared_ptr` whenever possible. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- src/apps/lc-compliance/helpers/capture.cpp | 8 ++++---- src/apps/lc-compliance/main.cpp | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 90c1530ba..d1dafb6cf 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -12,8 +12,8 @@ using namespace libcamera; Capture::Capture(std::shared_ptr camera) - : loop_(nullptr), camera_(camera), - allocator_(std::make_unique(camera)) + : loop_(nullptr), camera_(std::move(camera)), + allocator_(std::make_unique(camera_)) { } @@ -72,7 +72,7 @@ void Capture::stop() /* CaptureBalanced */ CaptureBalanced::CaptureBalanced(std::shared_ptr camera) - : Capture(camera) + : Capture(std::move(camera)) { } @@ -144,7 +144,7 @@ void CaptureBalanced::requestComplete(Request *request) /* CaptureUnbalanced */ CaptureUnbalanced::CaptureUnbalanced(std::shared_ptr camera) - : Capture(camera) + : Capture(std::move(camera)) { } diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp index 3f1d2a61b..98f2573d0 100644 --- a/src/apps/lc-compliance/main.cpp +++ b/src/apps/lc-compliance/main.cpp @@ -50,8 +50,6 @@ static void listCameras(CameraManager *cm) static int initCamera(CameraManager *cm, OptionsParser::Options options) { - std::shared_ptr camera; - int ret = cm->start(); if (ret) { std::cout << "Failed to start camera manager: " @@ -66,7 +64,7 @@ static int initCamera(CameraManager *cm, OptionsParser::Options options) } const std::string &cameraId = options[OptCamera]; - camera = cm->get(cameraId); + std::shared_ptr camera = cm->get(cameraId); if (!camera) { std::cout << "Camera " << cameraId << " not found, available cameras:" << std::endl; listCameras(cm); From patchwork Fri Dec 20 15:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22430 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 30B3EC32A3 for ; Fri, 20 Dec 2024 15:08:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE0B6684A5; Fri, 20 Dec 2024 16:08:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="AbjgySR7"; dkim-atps=neutral Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9828F684A0 for ; Fri, 20 Dec 2024 16:08:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707306; x=1734966506; bh=4Ls1Y+ok2GkRlfGiJV2vOVf1kzeSpg/Ib4icv9FXoCM=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=AbjgySR7Xtxpnt+kTXDN+msrJvcSS022PZsOfRq1wEfOosCA9mW7szEdN3hmgD+GV Q9H/aqDfRtcZH23Q+QReMvmNbhuYVEvUmvAYb7prIxVasneGc+GEbWmpjuMAmX0Eju Izkupyvx691mw/oNVzX5W58XqoDr9aKtR4qU+tN9CNEK4EFw84oKjEqvokS00zE2Hy oKNHd0a+8WYhegKqdb9p9AM9E5gmNqnIlSNoIeaSZ3+vqVsozzSeucxLOEW27dwqvt kyYNVIoHT34aqVhXrLaP1hYTCXYZT0FPlB4IlLhrMtfToaPKgkNxXJDa1doGV+s4bh ft1IjGW3XK8Zw== Date: Fri, 20 Dec 2024 15:08:20 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 04/12] apps: lc-compliance: Remove redundant getter call Message-ID: <20241220150759.709756-5-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: 9c2ac4c9c0578734c45848ec54a5120beb0ba56d 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" Smart pointers overload `operator->()`, no reason to use `get()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/lc-compliance/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp index 98f2573d0..cdd0bd515 100644 --- a/src/apps/lc-compliance/main.cpp +++ b/src/apps/lc-compliance/main.cpp @@ -45,7 +45,7 @@ class ThrowListener : public testing::EmptyTestEventListener static void listCameras(CameraManager *cm) { for (const std::shared_ptr &cam : cm->cameras()) - std::cout << "- " << cam.get()->id() << std::endl; + std::cout << "- " << cam->id() << std::endl; } static int initCamera(CameraManager *cm, OptionsParser::Options options) From patchwork Fri Dec 20 15:08:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22431 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 774B6C3272 for ; Fri, 20 Dec 2024 15:08:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34C38684AB; Fri, 20 Dec 2024 16:08:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="dT7RtF+E"; dkim-atps=neutral Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DAB8A6849B for ; Fri, 20 Dec 2024 16:08:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707310; x=1734966510; bh=czeInqymJn87RyMONeijTyPwqNtDX9fQTMA0VzZy9ec=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=dT7RtF+EkUutxBYYWG05ILLPVAYG1mQeA3A1TlnExl1XRcO/Y/O5/jOIPLHdHvTgS NOKnU6X3HvN4mg0REPQHQwGUBc3861swI5WFaJToHinkR5aRvpxAyHCFWvDgx2VXOr s6hwCd7T6j8rsKWdmO3PPN64KzLkavVMrmcB6RcwtURl9+5bmR/A4YjOLaNqjBffUh /BNp6wbxljFk7xPApOPchHkBhnojMicAUkHqnVDQS6BY11ag5it0Bq9CWHhz1b/gTz pCDESPPKW+cbo5PpPlua/n7rfceXc4n9vSRjfwGScxaAtewq++9xJLhPrJJnqLEAK0 lQyGRv52oIL1w== Date: Fri, 20 Dec 2024 15:08:25 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 05/12] apps: lc-compliance: Don't allocate `FrameBufferAllocator` dynamically Message-ID: <20241220150759.709756-6-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: 88254bb79732204b8edf1020dda697d23bb7cc5d 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" There is no reason to do so. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/lc-compliance/helpers/capture.cpp | 12 ++++++------ src/apps/lc-compliance/helpers/capture.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index d1dafb6cf..91c4d4400 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -13,7 +13,7 @@ using namespace libcamera; Capture::Capture(std::shared_ptr camera) : loop_(nullptr), camera_(std::move(camera)), - allocator_(std::make_unique(camera_)) + allocator_(camera_) { } @@ -45,7 +45,7 @@ void Capture::configure(StreamRole role) void Capture::start() { Stream *stream = config_->at(0).stream(); - int count = allocator_->allocate(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"; @@ -57,7 +57,7 @@ void Capture::start() void Capture::stop() { - if (!config_ || !allocator_->allocated()) + if (!config_ || !allocator_.allocated()) return; camera_->stop(); @@ -66,7 +66,7 @@ void Capture::stop() Stream *stream = config_->at(0).stream(); requests_.clear(); - allocator_->free(stream); + allocator_.free(stream); } /* CaptureBalanced */ @@ -81,7 +81,7 @@ void CaptureBalanced::capture(unsigned int numRequests) start(); Stream *stream = config_->at(0).stream(); - const std::vector> &buffers = allocator_->buffers(stream); + const std::vector> &buffers = allocator_.buffers(stream); /* No point in testing less requests then the camera depth. */ if (buffers.size() > numRequests) { @@ -153,7 +153,7 @@ void CaptureUnbalanced::capture(unsigned int numRequests) start(); Stream *stream = config_->at(0).stream(); - const std::vector> &buffers = allocator_->buffers(stream); + const std::vector> &buffers = allocator_.buffers(stream); captureCount_ = 0; captureLimit_ = numRequests; diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index 19b6927c6..a4cc3a99e 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -30,7 +30,7 @@ protected: EventLoop *loop_; std::shared_ptr camera_; - std::unique_ptr allocator_; + libcamera::FrameBufferAllocator allocator_; std::unique_ptr config_; std::vector> requests_; }; From patchwork Fri Dec 20 15:08:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22432 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 33192C3272 for ; Fri, 20 Dec 2024 15:08:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C438B684A8; Fri, 20 Dec 2024 16:08:36 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="dr8pYaGV"; dkim-atps=neutral Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 82010684AE for ; Fri, 20 Dec 2024 16:08:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707312; x=1734966512; bh=/eFqrououbZfXmJl7a+duwFZTp8wp2GU8TqinR48qD4=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=dr8pYaGVwGcYQ3y1IvaEM8OCGRg/EoCzJb1EN4ulTnXpZlfceLURZYJRNSb/YJHR1 cwyH02AXH0CJWxKd7xjyGGDmkAt7IoZ8qrFLa2JoF9rCVeiUW3eReBd6intvNVS2Bi 3uv23UTCyjCThZG4sXe103XWIbfMMT50GqnrK6MOawA9LVPN5gQuQDE9wys+fYV+gk pH1E54GV3HMYw+AIO7cfvg+iDO2PS/Kxf9xsNjlUAHG+qNmNs2ZTIygJrcj2IrUoSi sqTCkJu7jY/e6NPG4RxTD/7x4VwOC2h48xK/pVElYfSt3c3k4OremM8LCp99vnOWXs jY4hhEvk1LcLA== Date: Fri, 20 Dec 2024 15:08:29 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 06/12] apps: lc-compliance: Use `std::vector` for argument array Message-ID: <20241220150759.709756-7-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: b386c62b3e6ab82a481382a3987c76ac62242204 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" Just use an `std::vector` to store the arguments passed to `InitGoogleTest()`. This removes the need for the map and the separate `argc` variable used for size-keeping. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart --- src/apps/lc-compliance/main.cpp | 36 +++++++++------------------------ 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp index cdd0bd515..3d9c51fc3 100644 --- a/src/apps/lc-compliance/main.cpp +++ b/src/apps/lc-compliance/main.cpp @@ -80,45 +80,27 @@ static int initCamera(CameraManager *cm, OptionsParser::Options options) static int initGtestParameters(char *arg0, OptionsParser::Options options) { - const std::map gtestFlags = { { "list", "--gtest_list_tests" }, - { "filter", "--gtest_filter" } }; - - int argc = 0; + std::vector argv; std::string filterParam; - /* - * +2 to have space for both the 0th argument that is needed but not - * used and the null at the end. - */ - char **argv = new char *[(gtestFlags.size() + 2)]; - if (!argv) - return -ENOMEM; - - argv[0] = arg0; - argc++; + argv.push_back(arg0); - if (options.isSet(OptList)) { - argv[argc] = const_cast(gtestFlags.at("list").c_str()); - argc++; - } + if (options.isSet(OptList)) + argv.push_back(const_cast("--gtest_list_tests")); if (options.isSet(OptFilter)) { /* * The filter flag needs to be passed as a single parameter, in * the format --gtest_filter=filterStr */ - filterParam = gtestFlags.at("filter") + "=" + - static_cast(options[OptFilter]); - - argv[argc] = const_cast(filterParam.c_str()); - argc++; + filterParam = "--gtest_filter=" + options[OptFilter].toString(); + argv.push_back(const_cast(filterParam.c_str())); } - argv[argc] = nullptr; - - ::testing::InitGoogleTest(&argc, argv); + argv.push_back(nullptr); - delete[] argv; + int argc = argv.size(); + ::testing::InitGoogleTest(&argc, argv.data()); return 0; } From patchwork Fri Dec 20 15:08:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22433 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 C588BC3272 for ; Fri, 20 Dec 2024 15:08:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 44E16684B0; Fri, 20 Dec 2024 16:08:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="HgSvzZg9"; dkim-atps=neutral Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 25088684A5 for ; Fri, 20 Dec 2024 16:08:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707318; x=1734966518; bh=WKoFjmRvW/VLNW9jHasQCeXJOze+IkFyTDPoeZgW8/U=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=HgSvzZg9ZH4sKuSzstzQ4K7twh54ouE8+iIdMbJfARuV5QGshSb7SnMNI0xRcR3Ny 0QeNNhZTv3a2nn9qUH5Moa2k7yqOaR5i0gGGXBtYxJzktay2AnJpCVhiCEVyxujLHv Px1jUKiaxyu+/q9sq0wp+Jm/K+QAshLcCe8+hQxLgh6pcbrf8+nP2gVuK6iV3y0toU jYqNtU5wvNbfZZhxSkNBh5vNsS7RrslvvKPGuLOhdlR/Y4Ae7GpwZbAwIXIXIkk4Yc 4EvWD9duIwOv/EUf56/N1DEVvXhaQE8mbUT99bKnS1o+lXQTOnEJrc8+3OMUjuUaep pKbsdiXSP8Btw== Date: Fri, 20 Dec 2024 15:08:33 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 07/12] apps: lc-compliance: Use array instead of `std::vector` Message-ID: <20241220150759.709756-8-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: 527a818331aa2e1a317dff3b1b0f48ca59ab86d2 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" There is no reason to use `std::vector` for this static data, a simple array will do fine. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/lc-compliance/tests/capture_test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index db196a949..97465a612 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -18,8 +18,9 @@ namespace { using namespace libcamera; -const std::vector NUMREQUESTS = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; -const std::vector ROLES = { +const int NUMREQUESTS[] = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; + +const StreamRole ROLES[] = { StreamRole::Raw, StreamRole::StillCapture, StreamRole::VideoRecording, From patchwork Fri Dec 20 15:08:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22434 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 C8E8CC3272 for ; Fri, 20 Dec 2024 15:08:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 64145684B2; Fri, 20 Dec 2024 16:08:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="ZoDjLvxh"; dkim-atps=neutral Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0294C684AE for ; Fri, 20 Dec 2024 16:08:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707320; x=1734966520; bh=T1ArgVyr9LxnraRalmGQSwNWbt3n6iSqk9UDRW1FMM8=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=ZoDjLvxhG56N2fBRxXgeuDse3QR+gblciFP71dreMHmswTzgR7ECSZcf6kQSJAn2f gGbodGVXWRjl19QRtBsRVrhzWE2VGAXnhV/3D7aW8KdiTwjSFkj7vmKISN3coC2ekH DoJNrcHb/uQVECErp6rIMz04oGMEFKHxS5PJVrVXi4X6GnFcE/1AE3uupkaNENVHP5 n4Fa8j5iz3FK0kCeAoYaWMiDfbHvy7cJKqKJ8MBhnIteFpXYCLK/KbvZoSgOihhjOC 6aqfo8Gd4lRA8QhSUzldmYR7GDyNp5SSmVjk3hIOUCfBhXkft9MQC3HCcfx6xGrdpH R5btGgGe7dCmA== Date: Fri, 20 Dec 2024 15:08:37 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 08/12] apps: lc-compliance: Remove libevent dependency Message-ID: <20241220150759.709756-9-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: 5e7dddb2a7e18cb9935e602b516beae085bcff46 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" libevent is only used as a way to notify the main thread from the CameraManager thread when the capture should be terminated. Not only is libevent not really necessary and instead can be replaced with a simple combination of C++ STL parts, the current usage is prone to race conditions. Specifically, the camera's `queueRequest()` might complete the request before the main thread could set the `loop_` member variable and synchronize with the thread. This is a data race, practically resulting in a nullptr or dangling pointer dereference. This can easily be triggered by inserting a sufficiently large timeout before `loop_ = new EventLoop;`: [46:43:40.529620351] [671833] DEBUG Request request.cpp:129 Request(4:C:0/1:0) ../src/apps/lc-compliance/helpers/capture.cpp:140:14: runtime error: member call on null pointer of type 'struct EventLoop' 0 0x632c3e82f81a in CaptureBalanced::requestComplete(libcamera::Request*) ../src/apps/lc-compliance/helpers/capture.cpp:140 Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- README.rst | 2 +- src/apps/lc-compliance/helpers/capture.cpp | 23 ++++++------ src/apps/lc-compliance/helpers/capture.h | 42 +++++++++++++++++++--- src/apps/lc-compliance/meson.build | 7 ++-- src/apps/meson.build | 5 --- 5 files changed, 53 insertions(+), 26 deletions(-) diff --git a/README.rst b/README.rst index 4068c6cc8..f1749be97 100644 --- a/README.rst +++ b/README.rst @@ -97,7 +97,7 @@ for Python bindings: [optional] pybind11-dev for lc-compliance: [optional] - libevent-dev libgtest-dev + libgtest-dev for abi-compat.sh: [optional] abi-compliance-checker diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 91c4d4400..b473e0773 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -12,7 +12,7 @@ using namespace libcamera; Capture::Capture(std::shared_ptr camera) - : loop_(nullptr), camera_(std::move(camera)), + : camera_(std::move(camera)), allocator_(camera_) { } @@ -52,6 +52,8 @@ void Capture::start() camera_->requestCompleted.connect(this, &Capture::requestComplete); + result_.reset(); + ASSERT_EQ(camera_->start(), 0) << "Failed to start camera"; } @@ -62,6 +64,8 @@ void Capture::stop() camera_->stop(); + result_.reset(); + camera_->requestCompleted.disconnect(this); Stream *stream = config_->at(0).stream(); @@ -108,11 +112,10 @@ void CaptureBalanced::capture(unsigned int numRequests) } /* Run capture session. */ - loop_ = new EventLoop(); - loop_->exec(); + int status = result_.wait(); stop(); - delete loop_; + ASSERT_EQ(status, 0); ASSERT_EQ(captureCount_, captureLimit_); } @@ -132,13 +135,13 @@ void CaptureBalanced::requestComplete(Request *request) captureCount_++; if (captureCount_ >= captureLimit_) { - loop_->exit(0); + result_.set(0); return; } request->reuse(Request::ReuseBuffers); if (queueRequest(request)) - loop_->exit(-EINVAL); + result_.set(-EINVAL); } /* CaptureUnbalanced */ @@ -171,10 +174,8 @@ void CaptureUnbalanced::capture(unsigned int numRequests) } /* Run capture session. */ - loop_ = new EventLoop(); - int status = loop_->exec(); + int status = result_.wait(); stop(); - delete loop_; ASSERT_EQ(status, 0); } @@ -183,7 +184,7 @@ void CaptureUnbalanced::requestComplete(Request *request) { captureCount_++; if (captureCount_ >= captureLimit_) { - loop_->exit(0); + result_.set(0); return; } @@ -192,5 +193,5 @@ void CaptureUnbalanced::requestComplete(Request *request) request->reuse(Request::ReuseBuffers); if (camera_->queueRequest(request)) - loop_->exit(-EINVAL); + result_.set(-EINVAL); } diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index a4cc3a99e..8582ade8e 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -7,12 +7,13 @@ #pragma once +#include #include +#include +#include #include -#include "../common/event_loop.h" - class Capture { public: @@ -27,12 +28,45 @@ protected: virtual void requestComplete(libcamera::Request *request) = 0; - EventLoop *loop_; - std::shared_ptr camera_; libcamera::FrameBufferAllocator allocator_; std::unique_ptr config_; std::vector> requests_; + + struct + { + private: + std::mutex mutex_; + std::condition_variable cv_; + std::optional value_; + + public: + int wait() + { + std::unique_lock guard(mutex_); + + cv_.wait(guard, [&] { + return value_.has_value(); + }); + + return *value_; + } + + void set(int value) + { + std::unique_lock guard(mutex_); + + if (!value_) + value_ = value; + + cv_.notify_all(); + } + + void reset() + { + value_.reset(); + } + } result_; }; class CaptureBalanced : public Capture diff --git a/src/apps/lc-compliance/meson.build b/src/apps/lc-compliance/meson.build index b1f605f33..0884bc6ca 100644 --- a/src/apps/lc-compliance/meson.build +++ b/src/apps/lc-compliance/meson.build @@ -4,13 +4,11 @@ libgtest = dependency('gtest', version : '>=1.10.0', required : get_option('lc-compliance'), fallback : ['gtest', 'gtest_dep']) -if opt_lc_compliance.disabled() or not libevent.found() or not libgtest.found() - lc_compliance_enabled = false +lc_compliance_enabled = opt_lc_compliance.allowed() and libgtest.found() +if not lc_compliance_enabled subdir_done() endif -lc_compliance_enabled = true - lc_compliance_sources = files([ 'environment.cpp', 'helpers/capture.cpp', @@ -29,7 +27,6 @@ lc_compliance = executable('lc-compliance', lc_compliance_sources, dependencies : [ libatomic, libcamera_public, - libevent, libgtest, ], include_directories : lc_compliance_includes, diff --git a/src/apps/meson.build b/src/apps/meson.build index af632b9a7..252491441 100644 --- a/src/apps/meson.build +++ b/src/apps/meson.build @@ -3,12 +3,7 @@ opt_cam = get_option('cam') opt_lc_compliance = get_option('lc-compliance') -# libevent is needed by cam and lc-compliance. As they are both feature options, -# they can't be combined with simple boolean logic. libevent = dependency('libevent_pthreads', required : opt_cam) -if not libevent.found() - libevent = dependency('libevent_pthreads', required : opt_lc_compliance) -endif libtiff = dependency('libtiff-4', required : false) From patchwork Fri Dec 20 15:08:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22435 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 D3E10C3272 for ; Fri, 20 Dec 2024 15:08:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 90A31684AF; Fri, 20 Dec 2024 16:08:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="QWUDwiFw"; dkim-atps=neutral Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7FF79684AC for ; Fri, 20 Dec 2024 16:08:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707326; x=1734966526; bh=+iiPDfrcCv9OFJskYucvmMVv7O2CT3WTy/jBR5SZ7DE=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=QWUDwiFwr9d9tgR/pAlVMm+FTPYdKadMTILavWYgXqC/ZxcQ4pVn9HrBjxHGuzOYe n8llUSv4yGr50bW1PIZyfXpedroe0DXNyWE13QjZs2zWuqvH/m24zhZY5v6yhVt0nn MOgEYc9RRnC7zRnWaNyozPOHq5BlmJm7NyzxpczbbQvd2w3qXYP0SM754h3/EpmqSY MmNF38RZKp732jdzNr0U+bMYfCdYAbpopBbyb7k83jSJxdJkvg/S4QyP9lfQXWfByI ypqpZx0Tvsp52XIIy1cnHXT5GxwAvzpoF289gxZ2PV88z8RZAPRMIyeK8ePczeJJE/ hg29YArhi8kOw== Date: Fri, 20 Dec 2024 15:08:41 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 09/12] apps: lc-compliance: Check number of buffers in allocator Message-ID: <20241220150759.709756-10-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: 7d51ce620a41cac21baa4869851f4faf520fd0e6 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" Do a consistency check to ensure that the return value matches the number of buffers actually created. Signed-off-by: Barnabás Pőcze --- src/apps/lc-compliance/helpers/capture.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index b473e0773..5cc7635f7 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -49,6 +49,7 @@ void Capture::start() ASSERT_GE(count, 0) << "Failed to allocate buffers"; EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected"; + ASSERT_EQ(count, allocator_.buffers(stream).size()) << "Unexpected number of buffers in allocator"; camera_->requestCompleted.connect(this, &Capture::requestComplete); From patchwork Fri Dec 20 15:08:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22436 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 0FE02C3272 for ; Fri, 20 Dec 2024 15:08:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65E22684B6; Fri, 20 Dec 2024 16:08:53 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="knAmMQ21"; dkim-atps=neutral Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 900BC684A2 for ; Fri, 20 Dec 2024 16:08:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707330; x=1734966530; bh=/3WlX5EfLCj0pHQugTvk5SHZZO0FyUNvfLhnXbm/j7c=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=knAmMQ21eIQhRYrGjDVGv9Pc+JTN/AgA5qfJikfDNEs0+AkdlUavXy6HY2h8aY5V2 8dZqQDflJHVfa6Af1X+zYkaErCJdHB8+1UdEa3tsB/KRwPQ9La1/iy5S9ZWl9F1qAl dQKwEZdmpIKlyoVLdfJEQnfyCOXT5TUFmWUmx4Jn3NUlbUBXWQJYcQLsqi15ry2l1e iF/+YLT2VSqOkIJQCtIsgF2+zAmmi584oQV2OlmtzWOnGnj3fPE+Sy9Kg3XAmL8XOJ NcGkuJiQeMqqaYh/6NO0718oIUQl94LEPb1LDWd7OzzmcQTBhAkSr0QaNaCe515VBq sqxqa+k8v6BPw== Date: Fri, 20 Dec 2024 15:08:46 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 10/12] apps: lc-compliance: Move request creation into common function Message-ID: <20241220150759.709756-11-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: 02a0c80a5695a2c671cfa52c49a68478a557a176 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" `CaptureBalanced` and `CaptureUnbalanced` share the same logic for creating requests and assigning buffers, only the queueing of requests is slightly different. Move this common part into a separate function in the base class. Signed-off-by: Barnabás Pőcze --- src/apps/lc-compliance/helpers/capture.cpp | 66 +++++++++++----------- src/apps/lc-compliance/helpers/capture.h | 2 + 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 5cc7635f7..7a05be9a3 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; @@ -74,43 +76,51 @@ void Capture::stop() allocator_.free(stream); } -/* CaptureBalanced */ - -CaptureBalanced::CaptureBalanced(std::shared_ptr camera) - : Capture(std::move(camera)) +void Capture::prepareRequests(unsigned int plannedRequests) { -} - -void CaptureBalanced::capture(unsigned int numRequests) -{ - start(); + assert(config_); + assert(requests_.empty()); 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; + if (plannedRequests < buffers.size()) { + std::cout << "Camera needs " << buffers.size() + << " requests, can't test only " + << plannedRequests << std::endl; GTEST_SKIP(); } - queueCount_ = 0; - captureCount_ = 0; - captureLimit_ = numRequests; - - /* Queue the recommended number of requests. */ for (const std::unique_ptr &buffer : buffers) { 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"; - ASSERT_EQ(queueRequest(request.get()), 0) << "Failed to queue request"; - requests_.push_back(std::move(request)); } +} + +/* CaptureBalanced */ + +CaptureBalanced::CaptureBalanced(std::shared_ptr camera) + : Capture(std::move(camera)) +{ +} + +void CaptureBalanced::capture(unsigned int numRequests) +{ + start(); + + queueCount_ = 0; + captureCount_ = 0; + captureLimit_ = numRequests; + + prepareRequests(numRequests); + + for (const auto &request : requests_) + queueRequest(request.get()); /* Run capture session. */ int status = result_.wait(); @@ -156,23 +166,13 @@ 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) { - std::unique_ptr request = camera_->createRequest(); - ASSERT_TRUE(request) << "Can't create request"; + prepareRequests(numRequests); - ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; - - ASSERT_EQ(camera_->queueRequest(request.get()), 0) << "Failed to queue request"; - - requests_.push_back(std::move(request)); - } + for (const auto &request : requests_) + camera_->queueRequest(request.get()); /* Run capture session. */ int status = result_.wait(); diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index 8582ade8e..67c29021b 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -26,6 +26,8 @@ protected: void start(); void stop(); + void prepareRequests(unsigned int plannedRequests); + virtual void requestComplete(libcamera::Request *request) = 0; std::shared_ptr camera_; From patchwork Fri Dec 20 15:08:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22437 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 21A3BC3272 for ; Fri, 20 Dec 2024 15:09:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7B856684B6; Fri, 20 Dec 2024 16:09:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="pZ2QhNyS"; dkim-atps=neutral Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 140FD684AE for ; Fri, 20 Dec 2024 16:08:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707336; x=1734966536; bh=C7RsNeSb066QbfUOWol90VEasHYTTm4kBKkdKoQGcKY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=pZ2QhNySdCDVEPJ6vafbz1Gqr8Vp+gk8yrByfwV7ADxCjn0o2JVuYCMJasobOa1vJ T3IwY3wp63VYAwmomQPCcsdkeFbtBM0awhwrB7mGuZBxAud8ZCbD0d5TaeNRmjhOLu SRRwkua3gqB9UzbisnoR3sGOU+OCJSbjLsBjg4SWd+YE6pRdHYajxj+DxiQ6Mp5+o6 o5k+bSORiWrPWmssrQ2iVe/45VSOehlCuBDBsn2yRkqph46ocsnnq6fCIPzHV4N4oG iNyccoljpZeFUi6LvATwiBLy9Pltvfe2FK9A0ih8lSr9AFnNfBfilVeFyCMMhoPYiP gRr/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?= Cc: Jacopo Mondi Subject: [RFC PATCH v1 11/12] apps: lc-compliance: Support multiple streams in 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 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. Co-developed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- src/apps/lc-compliance/helpers/capture.cpp | 83 ++++++++++++++----- src/apps/lc-compliance/helpers/capture.h | 2 +- src/apps/lc-compliance/tests/capture_test.cpp | 6 +- 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 7a05be9a3..38edb6f28 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -24,15 +24,29 @@ Capture::~Capture() stop(); } -void Capture::configure(StreamRole role) +void Capture::configure(libcamera::Span roles) { - config_ = camera_->generateConfiguration({ role }); + assert(!roles.empty()); + + config_ = camera_->generateConfiguration(roles); if (!config_) { std::cout << "Role 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(), + [](const StreamConfiguration &l, const StreamConfiguration &r) + { return l.bufferCount < r.bufferCount; }); + + for (auto &cfg : *config_) + cfg.bufferCount = largest->bufferCount; + if (config_->validate() != CameraConfiguration::Valid) { config_.reset(); FAIL() << "Configuration not valid"; @@ -46,12 +60,20 @@ void Capture::configure(StreamRole role) void Capture::start() { - Stream *stream = config_->at(0).stream(); - int count = allocator_.allocate(stream); + assert(config_); + assert(!config_->empty()); + assert(!allocator_.allocated()); + + for (const auto &cfg : *config_) { + Stream *stream = cfg.stream(); + int count = allocator_.allocate(stream); + + ASSERT_GE(count, 0) << "Failed to allocate buffers"; + EXPECT_EQ(count, cfg.bufferCount) << "Allocated less buffers than expected"; + ASSERT_EQ(count, allocator_.buffers(stream).size()) << "Unexpected number of buffers in allocator"; + } - ASSERT_GE(count, 0) << "Failed to allocate buffers"; - EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected"; - ASSERT_EQ(count, allocator_.buffers(stream).size()) << "Unexpected number of buffers in allocator"; + ASSERT_TRUE(allocator_.allocated()); camera_->requestCompleted.connect(this, &Capture::requestComplete); @@ -71,9 +93,14 @@ void Capture::stop() camera_->requestCompleted.disconnect(this); - Stream *stream = config_->at(0).stream(); requests_.clear(); - allocator_.free(stream); + + for (const auto &cfg : *config_) { + int res = allocator_.free(cfg.stream()); + ASSERT_EQ(res, 0) << "Failed to free buffers associated with stream"; + } + + ASSERT_FALSE(allocator_.allocated()); } void Capture::prepareRequests(unsigned int plannedRequests) @@ -81,22 +108,36 @@ void Capture::prepareRequests(unsigned int plannedRequests) assert(config_); assert(requests_.empty()); - Stream *stream = config_->at(0).stream(); - const std::vector> &buffers = allocator_.buffers(stream); + std::size_t maxBuffers = 0; - /* No point in testing less requests then the camera depth. */ - if (plannedRequests < buffers.size()) { - std::cout << "Camera needs " << buffers.size() - << " requests, can't test only " - << plannedRequests << std::endl; - GTEST_SKIP(); + for (const auto &cfg : *config_) { + const auto &buffers = allocator_.buffers(cfg.stream()); + ASSERT_FALSE(buffers.empty()) << "Zero buffers allocated for stream"; + + /* No point in testing less requests then the camera depth. */ + if (plannedRequests < buffers.size()) { + std::cout << "Camera needs " << buffers.size() + << " requests, can't test only " + << plannedRequests << std::endl; + GTEST_SKIP(); + } + + maxBuffers = std::max(maxBuffers, buffers.size()); } - for (const std::unique_ptr &buffer : buffers) { - std::unique_ptr request = camera_->createRequest(); - ASSERT_TRUE(request) << "Can't create request"; + for (std::size_t i = 0; i < maxBuffers; i++) { + std::unique_ptr request = camera_->createRequest(i); + + for (const auto &cfg : *config_) { + Stream *stream = cfg.stream(); + const auto &buffers = allocator_.buffers(stream); + assert(!buffers.empty()); - ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; + if (i < buffers.size()) { + ASSERT_EQ(request->addBuffer(stream, buffers[i].get()), 0) + << "Can't add buffer to request"; + } + } requests_.push_back(std::move(request)); } diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index 67c29021b..b3a390941 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -17,7 +17,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 97465a612..c382fcf47 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -89,7 +89,7 @@ TEST_P(SingleStream, Capture) CaptureBalanced capture(camera_); - capture.configure(role); + capture.configure(std::array{ role }); capture.capture(numRequests); } @@ -108,7 +108,7 @@ TEST_P(SingleStream, CaptureStartStop) CaptureBalanced capture(camera_); - capture.configure(role); + capture.configure(std::array{ role }); for (unsigned int starts = 0; starts < numRepeats; starts++) capture.capture(numRequests); @@ -127,7 +127,7 @@ TEST_P(SingleStream, UnbalancedStop) CaptureUnbalanced capture(camera_); - capture.configure(role); + capture.configure(std::array{ role }); capture.capture(numRequests); } From patchwork Fri Dec 20 15:08:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22438 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 29500C3272 for ; Fri, 20 Dec 2024 15:09:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B0B22684B2; Fri, 20 Dec 2024 16:09:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="hbsiWWvE"; dkim-atps=neutral Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B5A6684AE for ; Fri, 20 Dec 2024 16:09:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707342; x=1734966542; bh=jvEfDcpVLMS3dZmFCxIdo0hoK5ndJ3c1uZ7U7Bgzg5I=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=hbsiWWvEMRzWnKIbyqQ7oqcrLo7jMdKqYzmgctJlbbXZSNr5TbM88GOSO1Ktubp2P UMusOVM2lsUymCyfjvz2PPbitZUrux5nEk6kam/GRzV2PUid9QxFyvO7VtNLuYfHhT ChTLEYARxYz2wSiIteZjQrYPS2J6HPlzptfhwXNoIWP94U0JvxUgmRMpwlEZEJrSjf iHYHVHF/MDt+T55NCGrN8Xn6MHptTkSqwmUz6Lkzz0fA9X4DfgWjQrYO7nzLn4KVEl YSBkzOA3YaQK5gNFgSLjoS8eqwjTcKRSXjessNVWG1DOptm1IKaETmByindbKUwkOy t7dQ8a+1BpoTA== Date: Fri, 20 Dec 2024 15:08:58 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi Subject: [RFC PATCH v1 12/12] apps: lc-compliance: Add multi-stream tests Message-ID: <20241220150759.709756-13-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: da41cd29e5586f7d8ffef82a1be3c6857f4815e1 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" Rename the `SingleStream` test to `SimpleCapture`, and extend it to support using multiple roles. And instantiate another test suite from the `SimpleCapture` test that tests multiple streams in one capture session. Co-developed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/apps/lc-compliance/tests/capture_test.cpp | 85 +++++++++++-------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index c382fcf47..8ea422f0d 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -8,7 +8,7 @@ #include "capture.h" -#include +#include #include @@ -18,19 +18,10 @@ namespace { using namespace libcamera; -const int NUMREQUESTS[] = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; - -const StreamRole ROLES[] = { - StreamRole::Raw, - StreamRole::StillCapture, - StreamRole::VideoRecording, - StreamRole::Viewfinder -}; - -class SingleStream : public testing::TestWithParam> +class SimpleCapture : public testing::TestWithParam, int>> { public: - static std::string nameParameters(const testing::TestParamInfo &info); + static std::string nameParameters(const testing::TestParamInfo &info); protected: void SetUp() override; @@ -43,7 +34,7 @@ protected: * We use gtest's SetUp() and TearDown() instead of constructor and destructor * in order to be able to assert on them. */ -void SingleStream::SetUp() +void SimpleCapture::SetUp() { Environment *env = Environment::get(); @@ -52,7 +43,7 @@ void SingleStream::SetUp() ASSERT_EQ(camera_->acquire(), 0); } -void SingleStream::TearDown() +void SimpleCapture::TearDown() { if (!camera_) return; @@ -61,19 +52,17 @@ void SingleStream::TearDown() camera_.reset(); } -std::string SingleStream::nameParameters(const testing::TestParamInfo &info) +std::string SimpleCapture::nameParameters(const testing::TestParamInfo &info) { - std::map rolesMap = { - { StreamRole::Raw, "Raw" }, - { StreamRole::StillCapture, "StillCapture" }, - { StreamRole::VideoRecording, "VideoRecording" }, - { StreamRole::Viewfinder, "Viewfinder" } - }; + const auto &[roles, numRequests] = info.param; + std::ostringstream ss; - std::string roleName = rolesMap[std::get<0>(info.param)]; - std::string numRequestsName = std::to_string(std::get<1>(info.param)); + for (StreamRole r : roles) + ss << r << '_'; - return roleName + "_" + numRequestsName; + ss << '_' << numRequests; + + return std::move(ss).str(); } /* @@ -83,13 +72,13 @@ std::string SingleStream::nameParameters(const testing::TestParamInfo SINGLEROLES[] = { + { StreamRole::Raw, }, + { StreamRole::StillCapture, }, + { StreamRole::VideoRecording, }, + { StreamRole::Viewfinder, }, +}; + +const std::vector MULTIROLES[] = { + { StreamRole::Raw, StreamRole::StillCapture }, + { StreamRole::Raw, StreamRole::VideoRecording }, + { StreamRole::StillCapture, StreamRole::VideoRecording }, + { StreamRole::VideoRecording, StreamRole::VideoRecording }, +}; + +INSTANTIATE_TEST_SUITE_P(SingleStream, + SimpleCapture, + testing::Combine(testing::ValuesIn(SINGLEROLES), + testing::ValuesIn(NUMREQUESTS)), + SimpleCapture::nameParameters); + +INSTANTIATE_TEST_SUITE_P(MultiStream, + SimpleCapture, + testing::Combine(testing::ValuesIn(MULTIROLES), testing::ValuesIn(NUMREQUESTS)), - SingleStream::nameParameters); + SimpleCapture::nameParameters); } /* namespace */