From patchwork Fri Dec 20 15:08:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22436 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0FE02C3272 for ; Fri, 20 Dec 2024 15:08:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65E22684B6; Fri, 20 Dec 2024 16:08:53 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="knAmMQ21"; dkim-atps=neutral Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 900BC684A2 for ; Fri, 20 Dec 2024 16:08:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734707330; x=1734966530; bh=/3WlX5EfLCj0pHQugTvk5SHZZO0FyUNvfLhnXbm/j7c=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=knAmMQ21eIQhRYrGjDVGv9Pc+JTN/AgA5qfJikfDNEs0+AkdlUavXy6HY2h8aY5V2 8dZqQDflJHVfa6Af1X+zYkaErCJdHB8+1UdEa3tsB/KRwPQ9La1/iy5S9ZWl9F1qAl dQKwEZdmpIKlyoVLdfJEQnfyCOXT5TUFmWUmx4Jn3NUlbUBXWQJYcQLsqi15ry2l1e iF/+YLT2VSqOkIJQCtIsgF2+zAmmi584oQV2OlmtzWOnGnj3fPE+Sy9Kg3XAmL8XOJ NcGkuJiQeMqqaYh/6NO0718oIUQl94LEPb1LDWd7OzzmcQTBhAkSr0QaNaCe515VBq sqxqa+k8v6BPw== Date: Fri, 20 Dec 2024 15:08:46 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 10/12] apps: lc-compliance: Move request creation into common function Message-ID: <20241220150759.709756-11-pobrn@protonmail.com> In-Reply-To: <20241220150759.709756-1-pobrn@protonmail.com> References: <20241220150759.709756-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 02a0c80a5695a2c671cfa52c49a68478a557a176 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" `CaptureBalanced` and `CaptureUnbalanced` share the same logic for creating requests and assigning buffers, only the queueing of requests is slightly different. Move this common part into a separate function in the base class. Signed-off-by: Barnabás Pőcze --- src/apps/lc-compliance/helpers/capture.cpp | 66 +++++++++++----------- src/apps/lc-compliance/helpers/capture.h | 2 + 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 5cc7635f7..7a05be9a3 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -7,6 +7,8 @@ #include "capture.h" +#include + #include using namespace libcamera; @@ -74,43 +76,51 @@ void Capture::stop() allocator_.free(stream); } -/* CaptureBalanced */ - -CaptureBalanced::CaptureBalanced(std::shared_ptr camera) - : Capture(std::move(camera)) +void Capture::prepareRequests(unsigned int plannedRequests) { -} - -void CaptureBalanced::capture(unsigned int numRequests) -{ - start(); + assert(config_); + assert(requests_.empty()); Stream *stream = config_->at(0).stream(); const std::vector> &buffers = allocator_.buffers(stream); /* No point in testing less requests then the camera depth. */ - if (buffers.size() > numRequests) { - std::cout << "Camera needs " + std::to_string(buffers.size()) - + " requests, can't test only " - + std::to_string(numRequests) << std::endl; + if (plannedRequests < buffers.size()) { + std::cout << "Camera needs " << buffers.size() + << " requests, can't test only " + << plannedRequests << std::endl; GTEST_SKIP(); } - queueCount_ = 0; - captureCount_ = 0; - captureLimit_ = numRequests; - - /* Queue the recommended number of requests. */ for (const std::unique_ptr &buffer : buffers) { std::unique_ptr request = camera_->createRequest(); ASSERT_TRUE(request) << "Can't create request"; ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; - ASSERT_EQ(queueRequest(request.get()), 0) << "Failed to queue request"; - requests_.push_back(std::move(request)); } +} + +/* CaptureBalanced */ + +CaptureBalanced::CaptureBalanced(std::shared_ptr camera) + : Capture(std::move(camera)) +{ +} + +void CaptureBalanced::capture(unsigned int numRequests) +{ + start(); + + queueCount_ = 0; + captureCount_ = 0; + captureLimit_ = numRequests; + + prepareRequests(numRequests); + + for (const auto &request : requests_) + queueRequest(request.get()); /* Run capture session. */ int status = result_.wait(); @@ -156,23 +166,13 @@ void CaptureUnbalanced::capture(unsigned int numRequests) { start(); - Stream *stream = config_->at(0).stream(); - const std::vector> &buffers = allocator_.buffers(stream); - captureCount_ = 0; captureLimit_ = numRequests; - /* Queue the recommended number of requests. */ - for (const std::unique_ptr &buffer : buffers) { - std::unique_ptr request = camera_->createRequest(); - ASSERT_TRUE(request) << "Can't create request"; + prepareRequests(numRequests); - ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request"; - - ASSERT_EQ(camera_->queueRequest(request.get()), 0) << "Failed to queue request"; - - requests_.push_back(std::move(request)); - } + for (const auto &request : requests_) + camera_->queueRequest(request.get()); /* Run capture session. */ int status = result_.wait(); diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index 8582ade8e..67c29021b 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -26,6 +26,8 @@ protected: void start(); void stop(); + void prepareRequests(unsigned int plannedRequests); + virtual void requestComplete(libcamera::Request *request) = 0; std::shared_ptr camera_;