From patchwork Thu Jan 30 11:50:08 2025 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: 22660 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 22E7EBDB1C for ; Thu, 30 Jan 2025 11:50:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F5DE68563; Thu, 30 Jan 2025 12:50:15 +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="WeJxizlH"; 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 871876034C for ; Thu, 30 Jan 2025 12:50:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237812; x=1738497012; bh=nx5skBNCz7i+955ZPFMrLg8EFjHcpon5EJqDadeZ0uw=; 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=WeJxizlHbUecy2jTRitY6EEz57fEE/ZP2a1Tg7+8zgdTNvpyxfi7y3A4Qpmed0/dE xdoldLgtvYosC0FBqrB3Ek70eDx4qtTU0VyFV8M1th6O8uPNbbvAmtrSYxrr5tPecK SexuefZ5uEBmfayuWo3tgd9ihyDTss9joCG0iHr+hdb/y9M3v8y8pny4V249D80LRV qIC4w9sP4Z6rB1k1KuUb5ij7Ya3sLMztMpc0v/Gl7KEcKhSKrVos6C4/89/8kig27S ME+4NwDCV5OVa2BOefNvAGzuFtd18Xw9VRS2TuYmQ0EhdBXHghbHkKQ5VOPRrdQZlN 63B5qn7SyxzRQ== Date: Thu, 30 Jan 2025 11:50:08 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 01/21] apps: common: event_loop: Take callbacks by rvalue ref Message-ID: <20250130115001.1129305-2-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 20fb6a77ee7f601afe43b05fb225494ea8a04396 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" Using a const lvalue reference to `std::function<>` is not ideal because it forces a copy to happen. Use an rvalue reference and `std::move()` to avoid that. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/common/event_loop.cpp | 16 ++++++++-------- src/apps/common/event_loop.h | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/apps/common/event_loop.cpp b/src/apps/common/event_loop.cpp index f7f9afa0c..bc8cf17ab 100644 --- a/src/apps/common/event_loop.cpp +++ b/src/apps/common/event_loop.cpp @@ -50,20 +50,20 @@ void EventLoop::exit(int code) event_base_loopbreak(base_); } -void EventLoop::callLater(const std::function &func) +void EventLoop::callLater(std::function &&func) { { std::unique_lock locker(lock_); - calls_.push_back(func); + calls_.push_back(std::move(func)); } event_base_once(base_, -1, EV_TIMEOUT, dispatchCallback, this, nullptr); } void EventLoop::addFdEvent(int fd, EventType type, - const std::function &callback) + std::function &&callback) { - std::unique_ptr event = std::make_unique(callback); + std::unique_ptr event = std::make_unique(std::move(callback)); short events = (type & Read ? EV_READ : 0) | (type & Write ? EV_WRITE : 0) | EV_PERSIST; @@ -85,9 +85,9 @@ void EventLoop::addFdEvent(int fd, EventType type, } void EventLoop::addTimerEvent(const std::chrono::microseconds period, - const std::function &callback) + std::function &&callback) { - std::unique_ptr event = std::make_unique(callback); + std::unique_ptr event = std::make_unique(std::move(callback)); event->event_ = event_new(base_, -1, EV_PERSIST, &EventLoop::Event::dispatch, event.get()); if (!event->event_) { @@ -131,8 +131,8 @@ void EventLoop::dispatchCall() call(); } -EventLoop::Event::Event(const std::function &callback) - : callback_(callback), event_(nullptr) +EventLoop::Event::Event(std::function &&callback) + : callback_(std::move(callback)), event_(nullptr) { } diff --git a/src/apps/common/event_loop.h b/src/apps/common/event_loop.h index ef129b9aa..d7d012c76 100644 --- a/src/apps/common/event_loop.h +++ b/src/apps/common/event_loop.h @@ -33,18 +33,18 @@ public: int exec(); void exit(int code = 0); - void callLater(const std::function &func); + void callLater(std::function &&func); void addFdEvent(int fd, EventType type, - const std::function &handler); + std::function &&handler); using duration = std::chrono::steady_clock::duration; void addTimerEvent(const std::chrono::microseconds period, - const std::function &handler); + std::function &&handler); private: struct Event { - Event(const std::function &callback); + Event(std::function &&callback); ~Event(); static void dispatch(int fd, short events, void *arg); From patchwork Thu Jan 30 11:50:13 2025 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: 22661 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 92F4DBDB1C for ; Thu, 30 Jan 2025 11:50:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 490496856A; Thu, 30 Jan 2025 12:50:21 +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="KWtOvRPx"; 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 45F076851B for ; Thu, 30 Jan 2025 12:50:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237818; x=1738497018; bh=QWjz6/M4YbBh8sUNp10+V/Pp31LxoiqvTTEfCQGMAR4=; 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=KWtOvRPx14paoEq62XHhAyzlZ2jmodxMjwqPTlvfCmSQjlKJiDE1Le2Q9JxO1xmYi DCvYFNbZ4kREdJ/7AlMizoG814go/0Fnf57zVTZCoejgSbqCJ0jm3m7ciGMZhdMPTj ULZEzUomVcE4VGBrbBqoW/wUDZsGofKbdbzpC5PH5ceVLwA+7kOBDVpuxZ0r4c+ENa bCtEu5i5MG8oucx2lN0CxvOt24H6aKcwrcMKrKzz3VdgzwvOnYpt2aZOMZlNTSO+31 Aq9vNaxwrqtPxc6pHnYawOK9ZX5sneLospFysc/7lWuplw8P5TuKxCQmRbUtUhPbM8 +cXgrHQy0Q90g== Date: Thu, 30 Jan 2025 11:50:13 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 02/21] apps: common: event_loop: Disable copy/move Message-ID: <20250130115001.1129305-3-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 1cff335e5849fb761b04346b83305d872fc30d22 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" The compiler generated functions are not appropriate, so delete the copy/move constructor/assignment to avoid potential issues. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/apps/common/event_loop.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/apps/common/event_loop.h b/src/apps/common/event_loop.h index d7d012c76..4e8dd0a46 100644 --- a/src/apps/common/event_loop.h +++ b/src/apps/common/event_loop.h @@ -13,6 +13,8 @@ #include #include +#include + #include struct event_base; @@ -43,8 +45,11 @@ public: std::function &&handler); private: + LIBCAMERA_DISABLE_COPY_AND_MOVE(EventLoop) + struct Event { Event(std::function &&callback); + LIBCAMERA_DISABLE_COPY_AND_MOVE(Event) ~Event(); static void dispatch(int fd, short events, void *arg); From patchwork Thu Jan 30 11:50:18 2025 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: 22673 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 E3499BDB1C for ; Thu, 30 Jan 2025 11:51:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 94B7B6856B; Thu, 30 Jan 2025 12:51:31 +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="SIGfMAhp"; 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 DEC8268564 for ; Thu, 30 Jan 2025 12:51:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237889; x=1738497089; bh=RlWobZ/H0WWwvgbFlZzkTlSBuNxPsg2LYAMadRltoag=; 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=SIGfMAhp+WbrDvAQusk6S7RG9HajOChuQd73AgG5Aj8nLgocCD9mxmhpDsbLsfvk9 XFheDnIHESzbpbLcIz0YgaX6kmqMGa2os+sOs2zmBjBeEPrRi00dspD5eU3P4UTWEj qDjGHbS/TlcMdEF6ifsigEfIWIICQlXDkz4k4lTZVLPplTRfRy6ikXXXtmum92JIz3 NOElYuAPYnNVYjShYecEWNuB9pT3Ti90JrCQFDnmd8TudjB/M3J38rrUCHuRr5gZDu J/RHZIGRlUitiOziqyE/0zEZDaFqYMnK7hDc7cQ/8k+Mn0oqbdWkMF2ttq52oyw0rn Nt3pde3TXQ9VA== Date: Thu, 30 Jan 2025 11:50:18 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 03/21] apps: common: event_loop: Use `std::deque` instead of `std::list` Message-ID: <20250130115001.1129305-4-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: a05cc21231e9c2e1e1f3639077a6c5610ed9f755 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" Deque has fast pop_front and push_back operations while making fewer allocations for the same number of elements as an `std::list`. So use an `std::deque` for storing the deferred calls of the loop. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/common/event_loop.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/apps/common/event_loop.h b/src/apps/common/event_loop.h index 4e8dd0a46..760075885 100644 --- a/src/apps/common/event_loop.h +++ b/src/apps/common/event_loop.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -63,7 +64,8 @@ private: struct event_base *base_; int exitCode_; - std::list> calls_; + std::deque> calls_; + std::list> events_; std::mutex lock_; From patchwork Thu Jan 30 11:50:23 2025 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: 22662 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 41E43BDB1C for ; Thu, 30 Jan 2025 11:50:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0CBE468567; Thu, 30 Jan 2025 12:50:29 +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="xpmgCBr7"; 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 61AFD68567 for ; Thu, 30 Jan 2025 12:50:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237826; x=1738497026; bh=zTJlVF9VecSivZdM7mHggxshRZizFlrVHInQxMvM9Xw=; 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=xpmgCBr7n5o/28Up94qw5sPHZXS0lCHPh4WpU2JWq/D4v+LVEw8sAs5EyknA3fvLW MIgNkp+3O4+6BWUKl/+aNZ2nPRJi6pOE2Jdh4iqcf0Ecz972zNQ2pu0q78aIWLrVrL zQlOnasuCyBBFY3zAEXJdS8F7CHROGh1EjqqV+Kfd/aiYL8iov593GMNpydt5rdVuO 2STanDNmgKw8MGqijhfY8ucKwvWnOfe0e2XYmxL56wDGS0RuBPNEs6sS1tQAiqWpb1 zgJM61wX5xmNoNx/4hYViy2fGM6zTpGDXuFGOwm1b23raoD5OPX8Ff/YWoa3WqI6gh FGPlQKPeFltWw== Date: Thu, 30 Jan 2025 11:50:23 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 04/21] apps: common: event_loop: Use single event source for deferred calls Message-ID: <20250130115001.1129305-5-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: ae2c0c9f34f3fac4d10449178f413ab0823d239e 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" Instead of calling `event_base_once()` every time a deferred call is added to the loop, create an event source at construction, and simply trigger that when a new deferred call is scheduled. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/apps/common/event_loop.cpp | 48 +++++++++++++++++----------------- src/apps/common/event_loop.h | 5 +--- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/apps/common/event_loop.cpp b/src/apps/common/event_loop.cpp index bc8cf17ab..b6230f4ba 100644 --- a/src/apps/common/event_loop.cpp +++ b/src/apps/common/event_loop.cpp @@ -21,12 +21,35 @@ EventLoop::EventLoop() evthread_use_pthreads(); base_ = event_base_new(); instance_ = this; + + callsTrigger_ = event_new(base_, -1, EV_PERSIST, [](evutil_socket_t, short, void *closure) { + auto *self = static_cast(closure); + + for (;;) { + std::function call; + + { + std::lock_guard locker(self->lock_); + if (self->calls_.empty()) + break; + + call = std::move(self->calls_.front()); + self->calls_.pop_front(); + } + + call(); + } + }, this); + assert(callsTrigger_); + event_add(callsTrigger_, nullptr); } EventLoop::~EventLoop() { instance_ = nullptr; + event_free(callsTrigger_); + events_.clear(); event_base_free(base_); libevent_global_shutdown(); @@ -57,7 +80,7 @@ void EventLoop::callLater(std::function &&func) calls_.push_back(std::move(func)); } - event_base_once(base_, -1, EV_TIMEOUT, dispatchCallback, this, nullptr); + event_active(callsTrigger_, 0, 0); } void EventLoop::addFdEvent(int fd, EventType type, @@ -108,29 +131,6 @@ void EventLoop::addTimerEvent(const std::chrono::microseconds period, events_.push_back(std::move(event)); } -void EventLoop::dispatchCallback([[maybe_unused]] evutil_socket_t fd, - [[maybe_unused]] short flags, void *param) -{ - EventLoop *loop = static_cast(param); - loop->dispatchCall(); -} - -void EventLoop::dispatchCall() -{ - std::function call; - - { - std::unique_lock locker(lock_); - if (calls_.empty()) - return; - - call = calls_.front(); - calls_.pop_front(); - } - - call(); -} - EventLoop::Event::Event(std::function &&callback) : callback_(std::move(callback)), event_(nullptr) { diff --git a/src/apps/common/event_loop.h b/src/apps/common/event_loop.h index 760075885..aac5ed3cc 100644 --- a/src/apps/common/event_loop.h +++ b/src/apps/common/event_loop.h @@ -65,11 +65,8 @@ private: int exitCode_; std::deque> calls_; + ::event *callsTrigger_ = nullptr; std::list> events_; std::mutex lock_; - - static void dispatchCallback(evutil_socket_t fd, short flags, - void *param); - void dispatchCall(); }; From patchwork Thu Jan 30 11:50:28 2025 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: 22663 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 F0D41BDB1C for ; Thu, 30 Jan 2025 11:50:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD99768570; Thu, 30 Jan 2025 12:50:33 +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="V5MYjQHR"; 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 B987A6856D for ; Thu, 30 Jan 2025 12:50:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237831; x=1738497031; bh=maK1hZrqUgg7HkQWchJiiXUl2r0RU0EoV8tYO26r9j4=; 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=V5MYjQHRMWTayqLkZURJF0Ejc2kX9hPQ+7uHnD6QqhawvW1WSLNfzZKnoRP2HppEv WDhfQ3hugnv9IOkt+JLujLdZ+JztqO0W4rok2s+W5/0teemXKYtIv8VkXNeHDLFdB3 zOPopADauH2A83saGVOGrJgrcGfJg935Rx6qdBotbzKQYVBkklfe1RxmGhZMp8vASA 1wwvetjDGUy2PJr8D0s2TxJJKawy2ia/DS/Jsi07pPbDa97gUBVJ/p+jduVAulfXaV qvkaAJFiCurXXPcGqTJ54QpnYOomktloH/Z5d8HKAADNrjcpyaCCOqrGFUIFtzS8E9 2fn5KhwBMzKTg== Date: Thu, 30 Jan 2025 11:50:28 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 05/21] apps: common: event_loop: Remove unused type alias Message-ID: <20250130115001.1129305-6-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 14d368c52a271ab729d3a5ed442bd6a9d0deaa43 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" Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/apps/common/event_loop.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/common/event_loop.h b/src/apps/common/event_loop.h index aac5ed3cc..507023996 100644 --- a/src/apps/common/event_loop.h +++ b/src/apps/common/event_loop.h @@ -41,7 +41,6 @@ public: void addFdEvent(int fd, EventType type, std::function &&handler); - using duration = std::chrono::steady_clock::duration; void addTimerEvent(const std::chrono::microseconds period, std::function &&handler); From patchwork Thu Jan 30 11:50:32 2025 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: 22665 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 C3362BDB1C for ; Thu, 30 Jan 2025 11:50:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 824E868574; Thu, 30 Jan 2025 12:50:39 +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="q9LjDeYR"; 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 D11D76856D for ; Thu, 30 Jan 2025 12:50:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237837; x=1738497037; bh=++fnX87jtPIaFW6i7xSF2EgMVTu3VhdXA6LIpPZRbU0=; 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=q9LjDeYRW3OWdr8kYRQoS+mvLFnu8KKsQUP9N8xM+ALXieMBIx1zS0NxtbC48lgDw cjMQQpaOKhAWTNsVwewfnOWo2jA0YQvnmzYyiHGlLcSAYmGh3QZG3qjjdzpURkaycO udT0OmXgvFFDi4V1qnfjPgbcoyRO2THv9UsK3Oy8a9lRkLgYKVVBf2n0pE9/PGMj7D tg9oim/NfRlg26vDThvZaa9BwVhD4i1B9CZ+y/bzbunBDeVk/PrhxrSuYJ/aJLsvpr uCshRfFNpI2F4uMTXHepevfQvhM0LW3zWy5zz89PyOD9O2oZLG7+4lnUx93moeflyM yx5PbKowaDnOg== Date: Thu, 30 Jan 2025 11:50:32 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 06/21] apps: common: event_loop: Add way to cancel deferred calls Message-ID: <20250130115001.1129305-7-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 54d386a6db609a346f81fd4305c4182dabe8b716 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" Store a cookie value of `std::uintptr_t` with the callback to make later cancellation of the callback possible. Signed-off-by: Barnabás Pőcze --- src/apps/common/event_loop.cpp | 18 ++++++++++++++---- src/apps/common/event_loop.h | 6 ++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/apps/common/event_loop.cpp b/src/apps/common/event_loop.cpp index b6230f4ba..0d7a4a024 100644 --- a/src/apps/common/event_loop.cpp +++ b/src/apps/common/event_loop.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include EventLoop *EventLoop::instance_ = nullptr; @@ -33,7 +34,7 @@ EventLoop::EventLoop() if (self->calls_.empty()) break; - call = std::move(self->calls_.front()); + call = std::move(self->calls_.front().first); self->calls_.pop_front(); } @@ -73,16 +74,25 @@ void EventLoop::exit(int code) event_base_loopbreak(base_); } -void EventLoop::callLater(std::function &&func) +void EventLoop::callLater(std::function &&func, std::optional cookie) { { - std::unique_lock locker(lock_); - calls_.push_back(std::move(func)); + std::lock_guard locker(lock_); + calls_.emplace_back(std::move(func), cookie); } event_active(callsTrigger_, 0, 0); } +void EventLoop::cancelLater(std::optional cookie) +{ + std::lock_guard locker(lock_); + + calls_.erase(std::remove_if(calls_.begin(), calls_.end(), + [&](const auto &x) { return !cookie || x.second == *cookie; }), + calls_.end()); +} + void EventLoop::addFdEvent(int fd, EventType type, std::function &&callback) { diff --git a/src/apps/common/event_loop.h b/src/apps/common/event_loop.h index 507023996..6d7d0497a 100644 --- a/src/apps/common/event_loop.h +++ b/src/apps/common/event_loop.h @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -36,7 +37,8 @@ public: int exec(); void exit(int code = 0); - void callLater(std::function &&func); + void callLater(std::function &&func, std::optional cookie = {}); + void cancelLater(std::optional cookie = {}); void addFdEvent(int fd, EventType type, std::function &&handler); @@ -63,7 +65,7 @@ private: struct event_base *base_; int exitCode_; - std::deque> calls_; + std::deque, std::optional>> calls_; ::event *callsTrigger_ = nullptr; std::list> events_; From patchwork Thu Jan 30 11:50:36 2025 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: 22674 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 B549ABDB1C for ; Thu, 30 Jan 2025 11:51:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2B4446857F; Thu, 30 Jan 2025 12:51:35 +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="GVWVCYaN"; dkim-atps=neutral Received: from mail-10631.protonmail.ch (mail-10631.protonmail.ch [79.135.106.31]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE3476857E for ; Thu, 30 Jan 2025 12:51:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237891; x=1738497091; bh=NUhrDH+R6HSzEFO8Hof78/dy7krBWAL7vNTi4zrPXrY=; 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=GVWVCYaN5/iPLofg/GD/TfzViRuAgtpgZfts7Vg+5W0vDg1GwkZ20lHg55hRxa/68 DqkkvixdkJNtnTIuCZFdXfAtAzcGOp26sX++NxlG5tPMw1PTxnAaZMRQe+BF1+s6Cp C4AGE47TO4qP098cFBYqogV4KX3bNSUYFClulo/g33+ZS+QVJdaZjSIIdZs2hHk/Dq 2Mn/qtc9cGMSabLjF7dINOnT0/rLJS8hQpLUbTAY9XsxolBe9t01ClcJlpEYpjAZ9B lKRx6DjAjiqZZ7kxoBR/MhGNkhR33r76ppYcljrcr1zGWAQbQztKkroXl/9chOM+mU OwoXu0vkxbHTA== Date: Thu, 30 Jan 2025 11:50:36 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 07/21] apps: common: event_loop: Make it possible to exit with exception Message-ID: <20250130115001.1129305-8-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 1d14dc4b50c39baa5b13ef346ff4914946cd24f8 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" Instead of taking a single integer in `EventLoop:exit()`, change it so that an `std::exception_ptr` can also be passed. And in `EventLoop::exec()` rethrow the stored exception (if any). Furthermore, catch exceptions from deferred calls, and stop the event loop with the caught exception. Signed-off-by: Barnabás Pőcze --- src/apps/common/event_loop.cpp | 35 +++++++++++++++++++++++++++++----- src/apps/common/event_loop.h | 6 ++++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/apps/common/event_loop.cpp b/src/apps/common/event_loop.cpp index 0d7a4a024..13c2d6057 100644 --- a/src/apps/common/event_loop.cpp +++ b/src/apps/common/event_loop.cpp @@ -12,6 +12,7 @@ #include #include #include +#include EventLoop *EventLoop::instance_ = nullptr; @@ -38,7 +39,14 @@ EventLoop::EventLoop() self->calls_.pop_front(); } - call(); + try { + call(); + } + catch (...) { + ::event_active(self->callsTrigger_, 0, 0); + self->exit(std::current_exception()); + break; + } } }, this); assert(callsTrigger_); @@ -63,14 +71,31 @@ EventLoop *EventLoop::instance() int EventLoop::exec() { - exitCode_ = -1; + { + std::lock_guard locker(lock_); + result_ = 0; + } + event_base_loop(base_, EVLOOP_NO_EXIT_ON_EMPTY); - return exitCode_; + + auto result = [&] { + std::lock_guard locker(lock_); + return std::exchange(result_, 0); + }(); + + if (auto *exc = std::get_if(&result)) + std::rethrow_exception(std::move(*exc)); + + return std::get(result); } -void EventLoop::exit(int code) +void EventLoop::exit(std::variant result) { - exitCode_ = code; + { + std::lock_guard locker(lock_); + result_ = std::move(result); + } + event_base_loopbreak(base_); } diff --git a/src/apps/common/event_loop.h b/src/apps/common/event_loop.h index 6d7d0497a..380c3483a 100644 --- a/src/apps/common/event_loop.h +++ b/src/apps/common/event_loop.h @@ -9,11 +9,13 @@ #include #include +#include #include #include #include #include #include +#include #include @@ -35,7 +37,7 @@ public: static EventLoop *instance(); int exec(); - void exit(int code = 0); + void exit(std::variant result = 0); void callLater(std::function &&func, std::optional cookie = {}); void cancelLater(std::optional cookie = {}); @@ -63,7 +65,7 @@ private: static EventLoop *instance_; struct event_base *base_; - int exitCode_; + std::variant result_ = 0; std::deque, std::optional>> calls_; ::event *callsTrigger_ = nullptr; From patchwork Thu Jan 30 11:50:41 2025 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: 22666 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 8A4DCBDB1C for ; Thu, 30 Jan 2025 11:50:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4399468572; Thu, 30 Jan 2025 12:50:47 +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="dYOzcUev"; 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 949E668567 for ; Thu, 30 Jan 2025 12:50:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237845; x=1738497045; bh=R7Tvb3Pgt2ZSiGu7mNV++YGEpaunk8MMtii+BXPKm94=; 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=dYOzcUevClddQj49UxePzDCAjdkeyGR6CVBN64NBt2TcMvOJsxt6e7NO21fTvNf3f AGfM3AYyW2pmRhKhcvTmwhJ5mTLUDxpsNWszWoZmrxGKRLOkCjWtWC96uSXxpdrTky MLC+tmVUA6UuShldZxJJL9tb5xbtElqSuLsRgAzJoipN992l2IPQcq2qKr0msC5zOl rUvUP4x1225hmQ/yvvk5rfhqJ2blVxoktd8sGXU7MB87bAPMcOK+oSy99CwUJhfOSk IFU56z2fyWUsp20HrnLyKA6wEabqtjSxxsmzMtGW70CutGur2Ww1fSVz4dzaVdgs0m mfIiJ2zORszeg== Date: Thu, 30 Jan 2025 11:50:41 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 08/21] apps: lc-compliance: Initialize `CameraManager` pointer in `Environment` Message-ID: <20250130115001.1129305-9-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: b2cc7084a97c5f4ce227fb0d930023f468afcd33 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 Thu Jan 30 11:50:45 2025 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: 22667 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 A2A82BDB1C for ; Thu, 30 Jan 2025 11:50:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5BE0C68577; Thu, 30 Jan 2025 12:50:51 +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="I9KlM9SK"; 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 7D37868567 for ; Thu, 30 Jan 2025 12:50:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237848; x=1738497048; bh=lsg7THwC1Sxs3MJW1yLsvHg6gnUUKyaAWT1fLdPFGbE=; 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=I9KlM9SKrm9zGhhMNspN0ooKkSYiz3jl6nhwTqcKL4CZXZqXle4XyyjWmfkACb+Cw To5ACyCig3I83rH8cbIRtWTRMV7vLkzjWYVSGWubMZim5xrMBOE9oIDAFxzH7EQm/n uL2MPrLJv4rqUwAof4yu8ZugzoY5B44TV2HNQZ8076pxBnBko212WIPiRONFYg5A5k 5QeOQO4SfY1ybz/ypVP8ivpbXfRZn308uw9TYZ9XUslLSG6V8RuimXgwNT55/2nz2S klpE1px37PuCYV95t+n+5xzW6fo+U8T9Hctp7jL634nsg7wdiPhHVHGEJnMMgXT+U9 k95oBy5Jfygsw== Date: Thu, 30 Jan 2025 11:50:45 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 09/21] apps: lc-compliance: Put tests into anonymous namespace Message-ID: <20250130115001.1129305-10-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 7d69735555ab37ac48f52fd61accfac49209c178 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 Thu Jan 30 11:50:49 2025 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: 22668 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 A0DF3BDB1C for ; Thu, 30 Jan 2025 11:50:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C00168574; Thu, 30 Jan 2025 12:50:56 +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="YxYFhTKv"; 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 A319068567 for ; Thu, 30 Jan 2025 12:50:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237854; x=1738497054; bh=EmlKr/K5pA9A3sAhwLBPYk63SFj8WerfxfMelmGXeaI=; 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=YxYFhTKv1KW7xGSNZ91BCL/8pUFsHtfuJC/ZrKjbk+muR6K0hM0/O84vcEzD6GNdx Fc7lwaWvanwG1IE4l14/gqA0+S8AYUM6OjULySW4XdXGnVrdySfy1wqMLAjlL+OJU6 VbZZe+Gobuay4BtLUUrL/WinuN4jb27NyNydpOKkGmGKfIWOyZ570RVwRaC0a79lZU iqtD8Ec1BfHMbBCFgmuG1qG2HEF0X6hMNg4NBWv4t+gAIlM9yoo87SryvvTjaEhDa9 Aiz3AWeSlaYasQYBZDoHPbec7f1TVJ8wrXnyfl4pLhz5T+9dwycNzi6c+gD67IftoT suetaBXUNkWSg== Date: Thu, 30 Jan 2025 11:50:49 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Laurent Pinchart , Paul Elder Subject: [RFC PATCH v3 10/21] apps: lc-compliance: Optimize `std::shared_ptr` usage Message-ID: <20250130115001.1129305-11-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 583ed973c0106fb0230165f604a8bf3504032a01 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 Reviewed-by: Paul Elder --- 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 Thu Jan 30 11:50:55 2025 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: 22676 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 99FF6BDB1C for ; Thu, 30 Jan 2025 11:51:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2B93468580; Thu, 30 Jan 2025 12:51: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="mRcu+YI3"; 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 4FE366856A for ; Thu, 30 Jan 2025 12:51:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237901; x=1738497101; bh=6LZdqGHRubU4bkTEAjaYF73miEfHhdYWLPMaF/agJSE=; 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=mRcu+YI3XD9eLmJ+qUYGvUObuDJ7AYThWK4AGH8r5WumCNjSUXHqnZG3Zgn4fZd2D kPvCCkqI76x3AA/d+n7d3GRcThjCM5t88uMx1JVNXGHOJffFyZMYr7WuCFRXu+O5wZ 3Xdz7zV9SmJ5A10e/lhbSSYUuDkZSnWniLyDQj2PfCOfC6XX+h8XMoubgDT9uDJ393 uVqAlnn5JnL2+5guuaZrkdw9Y/5TKFZTs9Z4I0n39y+L1dBpC/WYj/thZABnNzc6zt 97X/yDXCqp8y02+KORsupDnUtvj6vxpzsTiXiulvBoaju0bgMnkR26xDv36ESLhmET gnD+yPZfid75Q== Date: Thu, 30 Jan 2025 11:50:55 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 11/21] apps: lc-compliance: Remove redundant getter call Message-ID: <20250130115001.1129305-12-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: ce11d9b09d9fa4ef351a0ed915bcc1cda73b571d 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 Thu Jan 30 11:51:00 2025 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: 22669 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 820A3BDB1C for ; Thu, 30 Jan 2025 11:51:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3F6A268570; Thu, 30 Jan 2025 12:51:08 +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="NMa3+OXk"; 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 B74D468564 for ; Thu, 30 Jan 2025 12:51:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237866; x=1738497066; bh=eTzvA6QdrvQ08lkMvjYmvyl55ZnFctQsHD25rsc9d9Q=; 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=NMa3+OXkJ1ckPT2CxxkHYi3G3L04mRmwJRakxzIfA38vCnJRbSOaT78I9QxkHU98D QKKGD0KYHSpz3niyhAB7rTxoAd0Fo8CIHH6g/msqJ7VBEPqhnpbUHnPEu7k/AJuyfQ jzHQqLqpKGKwfsCZce1aSBrVW6g4+GrJ6Tsg2R+jazSLaiC4O4kh8f88PJ3zzcmCU/ J1U/IZ/SH2QigGop5HnaFdCyXBCCrEnY7UDg307HhneI6Bw+habRsMOnk7L2/HULdL m/ItjibqGD1GWJOdvB/AiR5kgDp9m+ylQWroDBXa5KHeXB1m0slua+yrDrNfRnJw7A LEe9D0OwaRF/A== Date: Thu, 30 Jan 2025 11:51:00 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 12/21] apps: lc-compliance: Don't allocate `FrameBufferAllocator` dynamically Message-ID: <20250130115001.1129305-13-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: c35f6f3e271be92d064a82957fcffec90216fc3b 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 Thu Jan 30 11:51:07 2025 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: 22670 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 23E65BDB1C for ; Thu, 30 Jan 2025 11:51:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D189068564; Thu, 30 Jan 2025 12:51:12 +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="A+9f+le5"; 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 66FD568564 for ; Thu, 30 Jan 2025 12:51:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237870; x=1738497070; bh=nqlMBelF5v+69lyYjHnBUjEtD5UiIUZk4Cd8MSMneas=; 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=A+9f+le5nukJiYjiLvBv3j7q3qc1YXt2UQfxepjyJ2k0Yk9I3EB/j0hreXB64iEeM CDDMAb65dQ0XVfPr2OXIW0UeILwCzZXcHjxfz1q4nDmh3TK1XbYPw1eV2SBivudu7L fQStB0WZDk65/1Z4s7/2GMW3WVWEpXKr4qb+v4v+AJ9HI/b/SNzZDTrAcvPqMZxndE CJhREgee9S8Jp1gexnuT/0XPpuXuzwi7vnmAgT9O8/NyaAz0fT+uUvQ329Ajlva+eJ WVGlCCM8TDP4n+UomMD4jCo0To4yo+lc29UDCZnyZ5onXsqnCv8x2GIBXNzprqd4Ro cW2tgyvOmrL1w== Date: Thu, 30 Jan 2025 11:51:07 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder , Laurent Pinchart Subject: [RFC PATCH v3 13/21] apps: lc-compliance: Use `std::vector` for argument array Message-ID: <20250130115001.1129305-14-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: eb2869fc7f07dd516daa6622556c658af371c25c 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..e9f0ffbb5 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("--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(filterParam.c_str()); } - argv[argc] = nullptr; - - ::testing::InitGoogleTest(&argc, argv); + argv.push_back(nullptr); - delete[] argv; + int argc = argv.size(); + ::testing::InitGoogleTest(&argc, const_cast(argv.data())); return 0; } From patchwork Thu Jan 30 11:51:11 2025 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: 22671 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 B978ABDB1C for ; Thu, 30 Jan 2025 11:51:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 71ADF6856B; Thu, 30 Jan 2025 12:51:19 +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="QKKFiseY"; dkim-atps=neutral Received: from mail-10631.protonmail.ch (mail-10631.protonmail.ch [79.135.106.31]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AF61C68564 for ; Thu, 30 Jan 2025 12:51:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237877; x=1738497077; bh=Ks/jrvruHnGDH5S7fiRidPqZKOiy3H1qrm/Mj2zPtpo=; 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=QKKFiseYqdB0zI93HYmfkhLKp2OI7TMq11STQKNrxLt+bN4yknzDT7TKf2E+zwMNn VrYQzcGFAUwONNPAlOzq6hokC7cfLKzjHEkPRXz3KGNoBRM+s40aPt6fWbDfyvxRfk BtsKMTJ31JfOp+aOhsYjCjuv15N/eK4YiY0KU4+RIdjccANdE7MNnDKeONWELCYMZM /vJDhXlBli7NQTqupp+mMbSDWo8DYQSBY0OQ9eI+/5dtqn3vV2v6xuTx0YQ/lRVClX wqrlzmrykLfWv+6UBJ5OkDzrCae7fupO+yhN6cAxRgKcTZoY5iZGOKDdApHux2FQjV sgQ0RN+aByOaw== Date: Thu, 30 Jan 2025 11:51:11 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 14/21] apps: lc-compliance: Use array instead of `std::vector` Message-ID: <20250130115001.1129305-15-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 98f34ba44523224312d70e8e7867d9a04654486c 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 Thu Jan 30 11:51:16 2025 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: 22672 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 AF96ABDB1C for ; Thu, 30 Jan 2025 11:51:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67B4B6856B; Thu, 30 Jan 2025 12:51: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="CfDHkSCP"; dkim-atps=neutral Received: from mail-10631.protonmail.ch (mail-10631.protonmail.ch [79.135.106.31]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CC9F68567 for ; Thu, 30 Jan 2025 12:51:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237881; x=1738497081; bh=DEbUidfSCnUI+HkVH6T6+a3fD4zi5Dum9YJRCtNXAks=; 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=CfDHkSCPLBVfiXgZISlu8egxBSblV9gDSv0OhVZnt1J1RQo+Sy8H9QWPOAuX15bLh flHOL2qx4MsjZyVvlwgXbqo6BEntH/zcJJeiQKbWw7psB9u9PhQZ7m3Rx53ibx5W/l eQWLc+t539PX8FVmG1M2qf6n78pac+eqZDd7IKZMqbuuHx368qQXtEDsMneaRs++Io TSZFkFVdDa0YZkyAuV0OklLNwiIlXE0fap3dIg7+8jfWLBU6g0hehLLW5bRRcJFw7V xSsaI8TafhYD30aKD8BWJQOIMNWiNHw6YuiS0sFl6clDyuhepdj9qPSOQA22vbqNL2 n9zyfDge3ZiQw== Date: Thu, 30 Jan 2025 11:51:16 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 15/21] apps: lc-compliance: Add message to `GTEST_SKIP()` Message-ID: <20250130115001.1129305-16-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 238472c94445cd4844c5afd5464d7f1f0ec9bb7c 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 like other gtest macros, `GTEST_SKIP()` returns an object to which a formatted message can be added using the usual `<<` stream operator. So use it instead of printing to `std::cout`. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/apps/lc-compliance/helpers/capture.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 91c4d4400..43db15d2d 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -26,10 +26,8 @@ void Capture::configure(StreamRole role) { config_ = camera_->generateConfiguration({ role }); - if (!config_) { - std::cout << "Role not supported by camera" << std::endl; - GTEST_SKIP(); - } + if (!config_) + GTEST_SKIP() << "Role not supported by camera"; if (config_->validate() != CameraConfiguration::Valid) { config_.reset(); @@ -85,10 +83,8 @@ void CaptureBalanced::capture(unsigned int numRequests) /* 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; - GTEST_SKIP(); + GTEST_SKIP() << "Camera needs " << buffers.size() + << " requests, can't test only " << numRequests; } queueCount_ = 0; From patchwork Thu Jan 30 11:51:22 2025 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: 22677 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 61A66BD808 for ; Thu, 30 Jan 2025 11:51:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 16C8168584; Thu, 30 Jan 2025 12:51:47 +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="Rm+E1JGB"; dkim-atps=neutral Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 07B126856B for ; Thu, 30 Jan 2025 12:51:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237903; x=1738497103; bh=CfpOwcxNQ4PgpJJcgE7e19c1DM78S0upTgtixZ04Wvo=; 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=Rm+E1JGBwaDFdVcHQnOXeP4GdowyPfgO0QKl7YIQAjLC+uLZl2UiJuOw+uWqB55Yw KGpeDhoSSqbbTpIAo29onR//jj5F+4RLdWbfBmA18wbZYs76cdzb2sjW56LuF5Wznr IBw1vKuuFCDWjXE2wXHrpKm9nUuB+wXKgPDBzemYB7XSrh7yfi0TVa4vyAq98v85e8 xlbPROaHAW/N+GjdnelsviZjxOKJXV+VfoPjXKUISeISpE/WAxmpBanvvR0QmJVxvY Yrf61wPQ4rWH8/KZ8LI//GvAKfR6zc33BpkyzuPzvKOK0b3iujBBntW7NH0Zr+tcIb qmuPKHjx6qQCw== Date: Thu, 30 Jan 2025 11:51:22 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 16/21] apps: lc-compliance: Merge `CaptureBalanced` and `CaptureUnbalanced` Message-ID: <20250130115001.1129305-17-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 2b914d415b2f656034ef799a88158ce03b3303b0 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" The above two classes have very similar implementations, in fact, the only essential difference is how many requests are queued. `CaptureBalanced` queues a predetermined number of requests, while `CaptureUnbalanced` queues requests without limit. This can be addressed by introducing a "capture" and a "queue" limit into the `Capture` class, which determine at most how many requests can be queued, and how many request completions are expected before stopping. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/apps/lc-compliance/helpers/capture.cpp | 142 ++++++------------ src/apps/lc-compliance/helpers/capture.h | 50 ++---- src/apps/lc-compliance/tests/capture_test.cpp | 12 +- 3 files changed, 71 insertions(+), 133 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 43db15d2d..940646f6c 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -7,12 +7,14 @@ #include "capture.h" +#include + #include using namespace libcamera; Capture::Capture(std::shared_ptr camera) - : loop_(nullptr), camera_(std::move(camera)), + : camera_(std::move(camera)), allocator_(camera_) { } @@ -40,153 +42,109 @@ void Capture::configure(StreamRole role) } } -void Capture::start() +void Capture::run(unsigned int captureLimit, std::optional queueLimit) { - Stream *stream = config_->at(0).stream(); - int count = allocator_.allocate(stream); + assert(!queueLimit || captureLimit <= *queueLimit); - ASSERT_GE(count, 0) << "Failed to allocate buffers"; - EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected"; + captureLimit_ = captureLimit; + queueLimit_ = queueLimit; - camera_->requestCompleted.connect(this, &Capture::requestComplete); + captureCount_ = queueCount_ = 0; - ASSERT_EQ(camera_->start(), 0) << "Failed to start camera"; -} + EventLoop loop; + loop_ = &loop; -void Capture::stop() -{ - if (!config_ || !allocator_.allocated()) - return; - - camera_->stop(); + start(); + prepareRequests(); - camera_->requestCompleted.disconnect(this); + for (const auto &request : requests_) + queueRequest(request.get()); - Stream *stream = config_->at(0).stream(); - requests_.clear(); - allocator_.free(stream); -} + EXPECT_EQ(loop_->exec(), 0); -/* CaptureBalanced */ + stop(); -CaptureBalanced::CaptureBalanced(std::shared_ptr camera) - : Capture(std::move(camera)) -{ + EXPECT_LE(captureLimit_, captureCount_); + EXPECT_LE(captureCount_, queueCount_); + EXPECT_TRUE(!queueLimit_ || queueCount_ <= *queueLimit_); } -void CaptureBalanced::capture(unsigned int numRequests) +void Capture::prepareRequests() { - 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) { + if (queueLimit_ && *queueLimit_ < buffers.size()) { GTEST_SKIP() << "Camera needs " << buffers.size() - << " requests, can't test only " << numRequests; + << " requests, can't test only " << *queueLimit_; } - 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)); } - - /* Run capture session. */ - loop_ = new EventLoop(); - loop_->exec(); - stop(); - delete loop_; - - ASSERT_EQ(captureCount_, captureLimit_); } -int CaptureBalanced::queueRequest(Request *request) +int Capture::queueRequest(libcamera::Request *request) { - queueCount_++; - if (queueCount_ > captureLimit_) + if (queueLimit_ && queueCount_ >= *queueLimit_) return 0; - return camera_->queueRequest(request); + int ret = camera_->queueRequest(request); + if (ret < 0) + return ret; + + queueCount_ += 1; + return 0; } -void CaptureBalanced::requestComplete(Request *request) +void Capture::requestComplete(Request *request) { - EXPECT_EQ(request->status(), Request::Status::RequestComplete) - << "Request didn't complete successfully"; - captureCount_++; if (captureCount_ >= captureLimit_) { loop_->exit(0); return; } + EXPECT_EQ(request->status(), Request::Status::RequestComplete) + << "Request didn't complete successfully"; + request->reuse(Request::ReuseBuffers); if (queueRequest(request)) loop_->exit(-EINVAL); } -/* CaptureUnbalanced */ - -CaptureUnbalanced::CaptureUnbalanced(std::shared_ptr camera) - : Capture(std::move(camera)) -{ -} - -void CaptureUnbalanced::capture(unsigned int numRequests) +void Capture::start() { - 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"; - - 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"; + int count = allocator_.allocate(stream); - requests_.push_back(std::move(request)); - } + ASSERT_GE(count, 0) << "Failed to allocate buffers"; + EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected"; - /* Run capture session. */ - loop_ = new EventLoop(); - int status = loop_->exec(); - stop(); - delete loop_; + camera_->requestCompleted.connect(this, &Capture::requestComplete); - ASSERT_EQ(status, 0); + ASSERT_EQ(camera_->start(), 0) << "Failed to start camera"; } -void CaptureUnbalanced::requestComplete(Request *request) +void Capture::stop() { - captureCount_++; - if (captureCount_ >= captureLimit_) { - loop_->exit(0); + if (!config_ || !allocator_.allocated()) return; - } - EXPECT_EQ(request->status(), Request::Status::RequestComplete) - << "Request didn't complete successfully"; + camera_->stop(); - request->reuse(Request::ReuseBuffers); - if (camera_->queueRequest(request)) - loop_->exit(-EINVAL); + camera_->requestCompleted.disconnect(this); + + Stream *stream = config_->at(0).stream(); + requests_.clear(); + allocator_.free(stream); } diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index a4cc3a99e..ede395e2a 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include @@ -16,51 +17,30 @@ class Capture { public: + Capture(std::shared_ptr camera); + ~Capture(); + void configure(libcamera::StreamRole role); + void run(unsigned int captureLimit, std::optional queueLimit = {}); -protected: - Capture(std::shared_ptr camera); - virtual ~Capture(); +private: + LIBCAMERA_DISABLE_COPY_AND_MOVE(Capture) void start(); void stop(); - virtual void requestComplete(libcamera::Request *request) = 0; - - EventLoop *loop_; + void prepareRequests(); + int queueRequest(libcamera::Request *request); + void requestComplete(libcamera::Request *request); std::shared_ptr camera_; libcamera::FrameBufferAllocator allocator_; std::unique_ptr config_; std::vector> requests_; -}; - -class CaptureBalanced : public Capture -{ -public: - CaptureBalanced(std::shared_ptr camera); - - void capture(unsigned int numRequests); - -private: - int queueRequest(libcamera::Request *request); - void requestComplete(libcamera::Request *request) override; - - unsigned int queueCount_; - unsigned int captureCount_; - unsigned int captureLimit_; -}; - -class CaptureUnbalanced : public Capture -{ -public: - CaptureUnbalanced(std::shared_ptr camera); - - void capture(unsigned int numRequests); - -private: - void requestComplete(libcamera::Request *request) override; - unsigned int captureCount_; - unsigned int captureLimit_; + EventLoop *loop_ = nullptr; + unsigned int captureLimit_ = 0; + std::optional queueLimit_; + unsigned int captureCount_ = 0; + unsigned int queueCount_ = 0; }; diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index 97465a612..93bed48f0 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -87,11 +87,11 @@ TEST_P(SingleStream, Capture) { auto [role, numRequests] = GetParam(); - CaptureBalanced capture(camera_); + Capture capture(camera_); capture.configure(role); - capture.capture(numRequests); + capture.run(numRequests, numRequests); } /* @@ -106,12 +106,12 @@ TEST_P(SingleStream, CaptureStartStop) auto [role, numRequests] = GetParam(); unsigned int numRepeats = 3; - CaptureBalanced capture(camera_); + Capture capture(camera_); capture.configure(role); for (unsigned int starts = 0; starts < numRepeats; starts++) - capture.capture(numRequests); + capture.run(numRequests, numRequests); } /* @@ -125,11 +125,11 @@ TEST_P(SingleStream, UnbalancedStop) { auto [role, numRequests] = GetParam(); - CaptureUnbalanced capture(camera_); + Capture capture(camera_); capture.configure(role); - capture.capture(numRequests); + capture.run(numRequests); } INSTANTIATE_TEST_SUITE_P(CaptureTests, From patchwork Thu Jan 30 11:51:28 2025 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: 22683 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 6847DBD808 for ; Thu, 30 Jan 2025 11:52:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 30C3068590; Thu, 30 Jan 2025 12:52:22 +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="P23UArn6"; 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 B56706857B for ; Thu, 30 Jan 2025 12:52:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237940; x=1738497140; bh=eujMRioviBy1qABpNpdEduEvC9g1+hm76ZmEmG9g2ow=; 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=P23UArn6MnDV0wVPyo5nR2o+TiqM2PSpFwZq/ID6smmcj+0lfO6SxdseYDj+Cukqm Vic/nu7E+wnwmcHU+SYH4BCBQmTw4JHJ8HIltwkyrbdZzDvQvlP8cRAjfPhTY676Ne 5iaWDb3NtXr+QzLjaLdJUH0o7yz5REk+AZK8eQjSfk3JoBr4osOlmhFutrlpXqjnJC Ns8Afb3++26AQpokFaLdFp0oFC4HCJX12R5ncPsvshyDI9dmeqR2MUp2Gi608RzTbH 4qkyyt2tiTXeiaZu7veGe2FFecfZJ7dwyf6wfpc3OHaDT6JSh5o2YBGn4Qkie78gfe syej0l7EI1uiA== Date: Thu, 30 Jan 2025 11:51:28 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 17/21] apps: lc-compliance: Support multiple streams in helpers Message-ID: <20250130115001.1129305-18-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 1188264907a062b340aa2fcee355670b4b6615e5 MIME-Version: 1.0 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: Paul Elder --- src/apps/lc-compliance/helpers/capture.cpp | 77 +++++++++++++++---- src/apps/lc-compliance/helpers/capture.h | 2 +- src/apps/lc-compliance/tests/capture_test.cpp | 6 +- 3 files changed, 66 insertions(+), 19 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 940646f6c..4a8627662 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -24,13 +24,31 @@ 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_) GTEST_SKIP() << "Role not supported by camera"; + ASSERT_EQ(config_->size(), roles.size()) << "Unexpected number of streams in configuration"; + + /* + * 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; }); + + assert(largest != config_->end()); + + for (auto &cfg : *config_) + cfg.bufferCount = largest->bufferCount; + if (config_->validate() != CameraConfiguration::Valid) { config_.reset(); FAIL() << "Configuration not valid"; @@ -74,20 +92,36 @@ void Capture::prepareRequests() assert(config_); assert(requests_.empty()); - Stream *stream = config_->at(0).stream(); - const std::vector> &buffers = allocator_.buffers(stream); + std::size_t maxBuffers = 0; + + for (const auto &cfg : *config_) { + const auto &buffers = allocator_.buffers(cfg.stream()); + ASSERT_FALSE(buffers.empty()) << "Zero buffers allocated for stream"; + + maxBuffers = std::max(maxBuffers, buffers.size()); + } /* No point in testing less requests then the camera depth. */ - if (queueLimit_ && *queueLimit_ < buffers.size()) { - GTEST_SKIP() << "Camera needs " << buffers.size() + if (queueLimit_ && *queueLimit_ < maxBuffers) { + GTEST_SKIP() << "Camera needs " << maxBuffers << " requests, can't test only " << *queueLimit_; } - for (const std::unique_ptr &buffer : buffers) { - std::unique_ptr request = camera_->createRequest(); + for (std::size_t i = 0; i < maxBuffers; i++) { + std::unique_ptr request = camera_->createRequest(i); ASSERT_TRUE(request) << "Can't create request"; - ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; + for (const auto &cfg : *config_) { + Stream *stream = cfg.stream(); + const auto &buffers = allocator_.buffers(stream); + assert(!buffers.empty()); + + if (i >= buffers.size()) + continue; + + ASSERT_EQ(request->addBuffer(stream, buffers[i].get()), 0) + << "Can't add buffer to request"; + } requests_.push_back(std::move(request)); } @@ -124,11 +158,19 @@ void Capture::requestComplete(Request *request) 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_GE(count, 0) << "Failed to allocate buffers"; - EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected"; + ASSERT_TRUE(allocator_.allocated()); camera_->requestCompleted.connect(this, &Capture::requestComplete); @@ -144,7 +186,12 @@ void Capture::stop() camera_->requestCompleted.disconnect(this); - Stream *stream = config_->at(0).stream(); requests_.clear(); - allocator_.free(stream); + + for (const auto &cfg : *config_) { + int ret = allocator_.free(cfg.stream()); + EXPECT_EQ(ret, 0) << "Failed to free buffers associated with stream"; + } + + EXPECT_FALSE(allocator_.allocated()); } diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index ede395e2a..48a8dadcb 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -20,7 +20,7 @@ public: Capture(std::shared_ptr camera); ~Capture(); - void configure(libcamera::StreamRole role); + void configure(libcamera::Span roles); void run(unsigned int captureLimit, std::optional queueLimit = {}); private: diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index 93bed48f0..147e17019 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) Capture capture(camera_); - capture.configure(role); + capture.configure(std::array{ role }); capture.run(numRequests, numRequests); } @@ -108,7 +108,7 @@ TEST_P(SingleStream, CaptureStartStop) Capture capture(camera_); - capture.configure(role); + capture.configure(std::array{ role }); for (unsigned int starts = 0; starts < numRepeats; starts++) capture.run(numRequests, numRequests); @@ -127,7 +127,7 @@ TEST_P(SingleStream, UnbalancedStop) Capture capture(camera_); - capture.configure(role); + capture.configure(std::array{ role }); capture.run(numRequests); } From patchwork Thu Jan 30 11:51:35 2025 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: 22686 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 4FB00BD808 for ; Thu, 30 Jan 2025 11:52:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 149A768592; Thu, 30 Jan 2025 12:52:39 +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="f4MnjeW9"; 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 B15086857B for ; Thu, 30 Jan 2025 12:52:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237957; x=1738497157; bh=Gt9wdryDMdfPe5D3YNPS7ZhG0hGhkm2yY/M/1f+qTvw=; 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=f4MnjeW9gEXqG1ISMzFM8UuP9EqDsHkEC07+p1WHCjxY6IRt1WhHPvg01AzHVrbTk E5zy5Bji84uMSV/EUzvfcw9ni1a6zu2W5CFHLNi5yq+kjIRvSFuJaZxf80Ne87v3pK 8C8Ebf+B8+XSM1pkVg+eo5+1i+nZAEZW5KfLG83ziTkeg6V2oPu2pI7qQtA1e16FzE y7ZPJbo0vx2JJB/6AjXImFyyWTsthb0g5Ub6XmlF5fZFcYCVrnHtSJf7ViOYXxg4HY Fl2MWeU2EHvT6yI7Z6tJH/B2NzShZqBixvIod9MG/ECCbekLf3EKN/5+zVsPmz3snj 6hfdr1NJ0N/5w== Date: Thu, 30 Jan 2025 11:51:35 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 18/21] apps: lc-compliance: Add multi-stream tests Message-ID: <20250130115001.1129305-19-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 88615a448ee853cc71a58efd3818eefeb11d39cf 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: Paul Elder Reviewed-by: Jacopo Mondi --- 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 147e17019..db1d52fc9 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 */ From patchwork Thu Jan 30 11:51:41 2025 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: 22678 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 0AE91BD808 for ; Thu, 30 Jan 2025 11:51:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C070F68586; Thu, 30 Jan 2025 12:51:49 +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="iTVx9enu"; dkim-atps=neutral Received: from mail-10631.protonmail.ch (mail-10631.protonmail.ch [79.135.106.31]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 99E8C68585 for ; Thu, 30 Jan 2025 12:51:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237907; x=1738497107; bh=WA9XW3ePOxUFoUm4S12Lvq92T+nfxRnepdlU4S8fWwg=; 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=iTVx9enuH0bykoK+WF5Klr1yYR0D9PtOZDMgaip3jn5U+bPA+MN7j9IPmVcv/4W/r Fa0cFGSiqJksgIKputaQm4TLtetbuju0k7DPPG20ymMhFJ+XrbVmfIY6VVYWIRASPj WqtIRNkT1JR3+CKPSz8ORMQdZYFLlDiQqCGrGx+0CILMO1xqCPtQhTrUU1Fj3KwLeg vETwHlYcmbUYU4J6drs0gGrdbJiKHYr2cEI7yxUWvXRGBJKHmz6/+lD8e6acmviemq Tkz4CaLCr8g/g3dSkhP8JbiPjD0yJs4YtZV5ub5kugUaOdCUbPgYcSwTZ6O+WS1Yho oHRjkxi6q4mYA== Date: Thu, 30 Jan 2025 11:51:41 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 19/21] apps: lc-compliance: Run request completion handler in "main" thread Message-ID: <20250130115001.1129305-20-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 8d23c9458e26aa7527bad0cb73628c6c8a0e7d6f 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" Currently, `Capture::requestCompleted()` runs in the `CameraManager`'s thread. This makes it a bit more complicated to use googletest and report errors in those callbacks since lc-compliance sets up googletest to throw exceptions on fatal errors / test skip, but those exceptions are only caught on the "main" thread, the one running the test suite. To minimize the burden of dealing with synchronization in tests, execute `Capture::requestCompleted()` in the event loop's thread by utilizing `EventLoop::callLater()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/apps/lc-compliance/helpers/capture.cpp | 24 +++++++++++++--------- src/apps/lc-compliance/helpers/capture.h | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 4a8627662..5032470d9 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -127,17 +127,13 @@ void Capture::prepareRequests() } } -int Capture::queueRequest(libcamera::Request *request) +void Capture::queueRequest(libcamera::Request *request) { if (queueLimit_ && queueCount_ >= *queueLimit_) - return 0; - - int ret = camera_->queueRequest(request); - if (ret < 0) - return ret; + return; + ASSERT_EQ(camera_->queueRequest(request), 0); queueCount_ += 1; - return 0; } void Capture::requestComplete(Request *request) @@ -152,8 +148,7 @@ void Capture::requestComplete(Request *request) << "Request didn't complete successfully"; request->reuse(Request::ReuseBuffers); - if (queueRequest(request)) - loop_->exit(-EINVAL); + queueRequest(request); } void Capture::start() @@ -172,7 +167,14 @@ void Capture::start() ASSERT_TRUE(allocator_.allocated()); - camera_->requestCompleted.connect(this, &Capture::requestComplete); + camera_->requestCompleted.connect(this, [this](libcamera::Request *request) { + /* Runs in the CameraManager thread. */ + + loop_->callLater([this, request] { + /* Run handler in the context of the event loop. */ + requestComplete(request); + }, reinterpret_cast(this)); + }); ASSERT_EQ(camera_->start(), 0) << "Failed to start camera"; } @@ -188,6 +190,8 @@ void Capture::stop() requests_.clear(); + loop_->cancelLater(reinterpret_cast(this)); + for (const auto &cfg : *config_) { int ret = allocator_.free(cfg.stream()); EXPECT_EQ(ret, 0) << "Failed to free buffers associated with stream"; diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index 48a8dadcb..dacce1fe2 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -30,7 +30,7 @@ private: void stop(); void prepareRequests(); - int queueRequest(libcamera::Request *request); + void queueRequest(libcamera::Request *request); void requestComplete(libcamera::Request *request); std::shared_ptr camera_; From patchwork Thu Jan 30 11:51:46 2025 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: 22679 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 316E8BD808 for ; Thu, 30 Jan 2025 11:51:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE3BF6858A; Thu, 30 Jan 2025 12:51:51 +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="WbYefwHS"; 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 F216968588 for ; Thu, 30 Jan 2025 12:51:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237909; x=1738497109; bh=44uTnHhpmqWaFRo7925aVDpsEg8M002arxNUFiLyCvI=; 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=WbYefwHS1iN85kUeUVfNxGINy+z12gEOu1xUCTli5/CDeDYotrmB20TZK6TYi6M5V 32D34FvxO98qOr9yxyZGaTD+kCTXKGhvkhALQA/iYYHpgtwEUjY097C1M6MXoAcu1e wP+bOhlh0k7envL8QyIHOx+bRUzHa+DbV6JaONike4ONr67Pz9oDAKKvXy+tkZBy3n Sio9HTMhgYztJiJQH+eloAY5UaAMMmqyikaaZbW0R/Y5EFsSrQgx9UahTOyyRaDx6f R/wINsyvmDHkfe4uNM/YyLFIdyD9FWpzWzgkxraE4ObeM5W7uXhU+O64q9Qe00XBR/ kLsqCY7M5M9AA== Date: Thu, 30 Jan 2025 11:51:46 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v3 20/21] apps: lc-compliance: Make `EventLoop` a member Message-ID: <20250130115001.1129305-21-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: c75102745a46ba28d74340cc42d24cd31efd7f87 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" Instead of creating an `EventLoop` in each `run()` invocation and setting a member pointer to the on-stack object, simply make it a member variable. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/apps/lc-compliance/helpers/capture.cpp | 11 ++++------- src/apps/lc-compliance/helpers/capture.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 5032470d9..13a5e3f33 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -69,16 +69,13 @@ void Capture::run(unsigned int captureLimit, std::optional queueLi captureCount_ = queueCount_ = 0; - EventLoop loop; - loop_ = &loop; - start(); prepareRequests(); for (const auto &request : requests_) queueRequest(request.get()); - EXPECT_EQ(loop_->exec(), 0); + EXPECT_EQ(loop_.exec(), 0); stop(); @@ -140,7 +137,7 @@ void Capture::requestComplete(Request *request) { captureCount_++; if (captureCount_ >= captureLimit_) { - loop_->exit(0); + loop_.exit(0); return; } @@ -170,7 +167,7 @@ void Capture::start() camera_->requestCompleted.connect(this, [this](libcamera::Request *request) { /* Runs in the CameraManager thread. */ - loop_->callLater([this, request] { + loop_.callLater([this, request] { /* Run handler in the context of the event loop. */ requestComplete(request); }, reinterpret_cast(this)); @@ -190,7 +187,7 @@ void Capture::stop() requests_.clear(); - loop_->cancelLater(reinterpret_cast(this)); + loop_.cancelLater(reinterpret_cast(this)); for (const auto &cfg : *config_) { int ret = allocator_.free(cfg.stream()); diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index dacce1fe2..50dc37c28 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -38,7 +38,7 @@ private: std::unique_ptr config_; std::vector> requests_; - EventLoop *loop_ = nullptr; + EventLoop loop_; unsigned int captureLimit_ = 0; std::optional queueLimit_; unsigned int captureCount_ = 0; From patchwork Thu Jan 30 11:51:50 2025 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: 22680 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 23D34BD808 for ; Thu, 30 Jan 2025 11:51:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE42A6858D; Thu, 30 Jan 2025 12:51:56 +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="JG9cQ2Im"; 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 2CC3B68582 for ; Thu, 30 Jan 2025 12:51:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738237914; x=1738497114; bh=PBAfXnfvaxNZUPPyp2LO2SCJu/pHTiGnY0b3zSUInxU=; 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=JG9cQ2ImMahu2y+6Peev3HyQK2Ymny9HqEeasomnWSObcPFB626HP1dWBh4BZIgwk HZuF9Ahd4Hc3G9pmCuS6zAQLxXYlvjlEcGqzYWtOnCNFktHNGv8CKiyfGg84CZ8JWJ akH6XIHkqzD7fk4Tt2qAZHQMa2WnhuiFkKtOIzm8hpCmAe68rHpnXK9SYklHbCxziT nizasf1YA0QeBHRogmIv4b5HBHQpRyEpe6CwkTb18zh7TnO1bMHylYblFtt/lrDWgv c3XmKoKOKIT31hyXpr91e1KxqfTwP2u4KTC/ASiari6Iu47zq54RleGr24guLoYs3w nSWkvEl+iNIdg== Date: Thu, 30 Jan 2025 11:51:50 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Jacopo Mondi Subject: [RFC PATCH v3 21/21] apps: lc-compliance: Rename `CaptureUnbalanced` Message-ID: <20250130115001.1129305-22-pobrn@protonmail.com> In-Reply-To: <20250130115001.1129305-1-pobrn@protonmail.com> References: <20250130115001.1129305-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: e6a39df64e762c940c273474d298c8d31c1de44a 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 test to `StopWithRequestsQueued` for more clarity. Suggested-by: Jacopo Mondi Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/apps/lc-compliance/tests/capture_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index db1d52fc9..39761f9b1 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -104,13 +104,13 @@ TEST_P(SimpleCapture, CaptureStartStop) } /* - * Test unbalanced stop + * Test stop with queued requests * * Makes sure the camera supports a stop with requests queued. Example failure * is a camera that does not handle cancelation of buffers coming back from the * video device while stopping. */ -TEST_P(SimpleCapture, UnbalancedStop) +TEST_P(SimpleCapture, StopWithRequestsQueued) { const auto &[roles, numRequests] = GetParam();