From patchwork Tue Jun 24 12:28:29 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: 23642 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 2E35CC3237 for ; Tue, 24 Jun 2025 12:28:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DFF8668DF0; Tue, 24 Jun 2025 14:28:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LMt7W5r0"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FC7768DC6 for ; Tue, 24 Jun 2025 14:28:34 +0200 (CEST) Received: from pb-laptop.local (185.221.143.107.nat.pool.zt.hu [185.221.143.107]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8ED3C16A for ; Tue, 24 Jun 2025 14:28:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1750768096; bh=jHPfh/qyjuoteRmpv19I9+YMo1YX7HcOGVGwbW3nV98=; h=From:To:Subject:Date:From; b=LMt7W5r0iM/JXOo2omiikkWljzqAGlnwH5dtFrWsjyO5mZR/aTPXSGOiPx+eDzB+D ogNUFdF+JKb90j1TNFChpRqYPH5VY3OVPgpEv7Cx/QUd2h0Gc8e5+9GVkUQoBvbMLx sAQUmc6qcJbaPyv6XgQL69QujbN5ALUKKE5GHxuU= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1 1/2] apps: lc-compliance: Commit camera configuration last Date: Tue, 24 Jun 2025 14:28:29 +0200 Message-ID: <20250624122830.726987-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.50.0 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" Save the result of `Camera::generateConfiguration()` in a local variable, and only commit it to the member variable `config_` if it passes all checks. This removes the need for explicit `config_.reset()` calls in error paths, hence making things simpler. Signed-off-by: Barnabás Pőcze --- src/apps/lc-compliance/helpers/capture.cpp | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 2a3fa3b68..d076e964a 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -27,35 +27,30 @@ void Capture::configure(libcamera::Span roles) { assert(!roles.empty()); - config_ = camera_->generateConfiguration(roles); - if (!config_) + auto config = camera_->generateConfiguration(roles); + if (!config) GTEST_SKIP() << "Roles not supported by camera"; - ASSERT_EQ(config_->size(), roles.size()) << "Unexpected number of streams in configuration"; + 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(), + std::max_element(config->begin(), config->end(), [](const StreamConfiguration &l, const StreamConfiguration &r) { return l.bufferCount < r.bufferCount; }); - assert(largest != config_->end()); + assert(largest != config->end()); - for (auto &cfg : *config_) + for (auto &cfg : *config) cfg.bufferCount = largest->bufferCount; - if (config_->validate() != CameraConfiguration::Valid) { - config_.reset(); - FAIL() << "Configuration not valid"; - } + ASSERT_EQ(config->validate(), CameraConfiguration::Valid); + ASSERT_EQ(camera_->configure(config.get()), 0); - if (camera_->configure(config_.get())) { - config_.reset(); - FAIL() << "Failed to configure camera"; - } + config_ = std::move(config); } void Capture::run(unsigned int captureLimit, std::optional queueLimit) From patchwork Tue Jun 24 12:28:30 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: 23643 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 CC591C3237 for ; Tue, 24 Jun 2025 12:28:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5BB8E68DF3; Tue, 24 Jun 2025 14:28:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UVTZks48"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6333668DE2 for ; Tue, 24 Jun 2025 14:28:34 +0200 (CEST) Received: from pb-laptop.local (185.221.143.107.nat.pool.zt.hu [185.221.143.107]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D21C2C72 for ; Tue, 24 Jun 2025 14:28:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1750768096; bh=S3dau1QvY+vK+dVFmDxpZjqW9StgVIdJ+docSzXpvb0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UVTZks48V7zhWEt3J30ql1EphYAzitQIxsLAabu9rmluFpKRGNtcGpT41S8xYYAoU ywTt5LWzcaj2viFYegk/b7WmqLBNzU+GLuIMfgIp2Fy8WslwIqmsKd28XFrN1OB7oM 0oPDSyfD7pjdTUggymamo4+5BwHxqTW0uM7CkwXQ= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1 2/2] apps: lc-compliance: Allocate buffers when configuring Date: Tue, 24 Jun 2025 14:28:30 +0200 Message-ID: <20250624122830.726987-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250624122830.726987-1-barnabas.pocze@ideasonboard.com> References: <20250624122830.726987-1-barnabas.pocze@ideasonboard.com> 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" Most pipeline handlers release buffers when a camera is stopped. However, the raspberry pi pipelines do not do that. Hence they are incompatible with the current model and all "CaptureStartStop" tests fail because lc-compliance allocates buffers before starting and releases them after stopping. Fix this by allocating buffers after the camera is configured, and do not release them after stopping. Signed-off-by: Barnabás Pőcze --- src/apps/lc-compliance/helpers/capture.cpp | 28 +++++++++++++++++----- src/apps/lc-compliance/helpers/capture.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index d076e964a..df0ad00ac 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -21,6 +21,7 @@ Capture::Capture(std::shared_ptr camera) Capture::~Capture() { stop(); + unconfigure(); } void Capture::configure(libcamera::Span roles) @@ -50,6 +51,20 @@ void Capture::configure(libcamera::Span roles) ASSERT_EQ(config->validate(), CameraConfiguration::Valid); ASSERT_EQ(camera_->configure(config.get()), 0); + const auto bufferCount = config->at(0).bufferCount; + + for (const auto &cfg : *config) { + Stream *stream = cfg.stream(); + + ASSERT_GE(allocator_.allocate(stream), 0) + << "Failed to allocate buffers"; + + ASSERT_EQ(allocator_.buffers(stream).size(), bufferCount) + << "Mismatching buffer count"; + } + + ASSERT_TRUE(allocator_.allocated()); + config_ = std::move(config); } @@ -112,7 +127,7 @@ void Capture::start() { assert(config_); assert(!config_->empty()); - assert(!allocator_.allocated()); + assert(allocator_.allocated()); assert(requests_.empty()); const auto bufferCount = config_->at(0).bufferCount; @@ -132,9 +147,6 @@ void Capture::start() for (const auto &cfg : *config_) { Stream *stream = cfg.stream(); - int count = allocator_.allocate(stream); - ASSERT_GE(count, 0) << "Failed to allocate buffers"; - const auto &buffers = allocator_.buffers(stream); ASSERT_EQ(buffers.size(), bufferCount) << "Mismatching buffer count"; @@ -144,8 +156,6 @@ void Capture::start() } } - ASSERT_TRUE(allocator_.allocated()); - camera_->requestCompleted.connect(this, &Capture::requestComplete); ASSERT_EQ(camera_->start(), 0) << "Failed to start camera"; @@ -161,6 +171,12 @@ void Capture::stop() camera_->requestCompleted.disconnect(this); requests_.clear(); +} + +void Capture::unconfigure() +{ + if (!config_ || !allocator_.allocated()) + return; for (const auto &cfg : *config_) { EXPECT_EQ(allocator_.free(cfg.stream()), 0) diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index ea01c11c1..41ce4e5a6 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -28,6 +28,7 @@ private: void start(); void stop(); + void unconfigure(); int queueRequest(libcamera::Request *request); void requestComplete(libcamera::Request *request);