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)