From patchwork Tue Jan 14 18:23:05 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: 22577 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 BFAEAC3304 for ; Tue, 14 Jan 2025 18:23:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7868368562; Tue, 14 Jan 2025 19:23: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="owY7BZKR"; 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 2E18468560 for ; Tue, 14 Jan 2025 19:23:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1736878989; x=1737138189; bh=5pID2MA8VOFbZIuXw2qYio4RxdA4dJ8xJoviCGtAhlM=; 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=owY7BZKRPsbc8lKZzdINCT7687upzmtZAJiWyUdcBhWHew/KIPGJTVHsXHxEDyYXj gGl3oEvp404JYv/eSZWYvrqZtm0AH67oPyPFuYByoVtZf9LQOAY7EJJIzT6/45Woyo gh2XRnkksVkhYfhDEN3448XVyljCy01QpeoKm4kL46GLkKDFnc6YRG8F2Ot0bbxeee IfSuPghsIxM5nXcp1nQvu7ODchWnLb5xr+9qvk3k3ccFOvCIWarDuoPYKI5pWSv0dc 9lnubmqU0GZ2ttzxnXFWXxJ+eQF18osHKNHQpYXLu2IRJw9RuEI9nk1kchie5VeMZX Txl4B0bxalltg== Date: Tue, 14 Jan 2025 18:23:05 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v2 16/16] apps: lc-compliance: Run request completion handler in "main" thread Message-ID: <20250114182143.1773762-17-pobrn@protonmail.com> In-Reply-To: <20250114182143.1773762-1-pobrn@protonmail.com> References: <20250114182143.1773762-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 6272a51921d450ec30a7bf583bae3c870de9ce89 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 --- src/apps/lc-compliance/helpers/capture.cpp | 21 ++++++++++++--------- src/apps/lc-compliance/helpers/capture.h | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index dbaff4138..528a3a13a 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -129,16 +129,13 @@ void Capture::prepareRequests(std::optional queueLimit) } } -int Capture::queueRequest(libcamera::Request *request) +void Capture::queueRequest(libcamera::Request *request) { if (queueLimit_ && queueCount_ >= *queueLimit_) - return 0; - - if (int ret = camera_->queueRequest(request); ret < 0) - return ret; + return; + ASSERT_EQ(camera_->queueRequest(request), 0); queueCount_ += 1; - return 0; } void Capture::requestComplete(Request *request) @@ -153,8 +150,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() @@ -173,7 +169,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); + }); + }); ASSERT_EQ(camera_->start(), 0) << "Failed to start camera"; } diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index 391184ad6..9003a0934 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(std::optional queueLimit = {}); - int queueRequest(libcamera::Request *request); + void queueRequest(libcamera::Request *request); void requestComplete(libcamera::Request *request); std::shared_ptr camera_;