From patchwork Sat Sep 27 20:39:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Mader X-Patchwork-Id: 24485 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 F15D7C328C for ; Sat, 27 Sep 2025 20:40:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D76316B5F3; Sat, 27 Sep 2025 22:40:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=collabora.com header.i=robert.mader@collabora.com header.b="PiOsmKEB"; dkim-atps=neutral Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 940916B5A2 for ; Sat, 27 Sep 2025 22:40:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; t=1759005640; cv=none; d=zohomail.com; s=zohoarc; b=K44NtfGzJc/cZ5PQCVsV+7kiYTdkG4IMSIae0mTVKhdVqD9yfVz9n6mP2UHXUT++J9u+nszVBCUl63WgSYftJcP6VDufc9DWNwSZyPx5gOtl9COmUOZPeDIUKeXH9h07WmJHeyHeJUDUbhAglsr43YQxXfyqHmMk4M3agXQ1eGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759005640; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=Xd+5SdlrLyJIUZ2ddfMseF7JvcudweLFTJIaFhy96AM=; b=Vi72wiG2VaTYGI7kABTS4hBkYJ5dptHNYqRTF9NZEFb1yoW2gV8d6TgeFKp8v2rd2qkHAhD2uf19Fy7mxbizLeHVH9XLZp/ECQJUYzKAz6FfI3MEqWgurMUL6ou4JKzcnwkngpbG6kVAlJT8QoY1blPE1cYRxINAiI0T2RznKnE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=robert.mader@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1759005640; s=zohomail; d=collabora.com; i=robert.mader@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=Xd+5SdlrLyJIUZ2ddfMseF7JvcudweLFTJIaFhy96AM=; b=PiOsmKEB3kxJ8+orHqxNSLLik5xCUwgNAdGfkxnez/Di2Huuiv764zxUzk2D5ygB qVUjWjTuv3h4ciz52gGPIMdppEPtrOh2qz2iF3Mze2d5p4hM3ReYtcqpFKsEwoEk9WF dXP0FvJheGjWO91R6tV64Z+cDj12BnTo8mzNRvzY= Received: by mx.zohomail.com with SMTPS id 1759005637285361.7375955440649; Sat, 27 Sep 2025 13:40:37 -0700 (PDT) From: Robert Mader To: libcamera-devel@lists.libcamera.org Cc: Robert Mader Subject: [PATCH v2] pipeline: simple: Allow buffer counts from 1 to 32 Date: Sat, 27 Sep 2025 22:39:47 +0200 Message-ID: <20250927203947.126092-1-robert.mader@collabora.com> X-Mailer: git-send-email 2.51.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" While a default value of 4 buffers appears to be a good default that is used by other pipelines as well, allowing both higher and lower values can be desirable, notably for: 1. Video encoding, e.g. encoding multiple buffers in parallel. 2. Clients requesting a single buffer - e.g. in multi-stream scenarios. Thus allow up to 32 buffers - following the default from vb2 core - while keeping the default to the previous 4. While on it: 1. mark the config as adjusted when appropriate. 2. increase the number of internal buffer used by the swISP to 4 as well. This has been shipped downstream in postmarketOS for a while and, in some cases, seems to improve stability on no-so-great drivers. Signed-off-by: Robert Mader --- Changes since v1 with title "pipeline: simple: Allow buffer counts from 1 to 16 for swISP" 1: Cover all cases, not just the swISP one. 2: Increase maximum to 32 to match vb2 core. 3: Change constant naming to better match similar ones. 4: Bump kNumInternalBuffers to 4. --- src/libcamera/pipeline/simple/simple.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index c816cffc9..23585692c 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -378,6 +378,9 @@ public: const Transform &combinedTransform() const { return combinedTransform_; } private: + static constexpr unsigned int kNumBuffersDefault = 4; + static constexpr unsigned int kNumBuffersMax = 32; + /* * The SimpleCameraData instance is guaranteed to be valid as long as * the corresponding Camera instance is valid. In order to borrow a @@ -417,7 +420,7 @@ protected: int queueRequestDevice(Camera *camera, Request *request) override; private: - static constexpr unsigned int kNumInternalBuffers = 3; + static constexpr unsigned int kNumInternalBuffers = 4; struct EntityData { std::unique_ptr video; @@ -1239,7 +1242,7 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate() cfg.size != pipeConfig_->captureSize) needConversion_ = true; - /* Set the stride, frameSize and bufferCount. */ + /* Set the stride and frameSize. */ if (needConversion_) { std::tie(cfg.stride, cfg.frameSize) = data_->converter_ @@ -1262,7 +1265,19 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate() cfg.frameSize = format.planes[0].size; } - cfg.bufferCount = 4; + if (cfg.bufferCount == 0) { + LOG(SimplePipeline, Debug) + << "Adjusting bufferCount from " << cfg.bufferCount + << " to " << kNumBuffersDefault; + cfg.bufferCount = kNumBuffersDefault; + status = Adjusted; + } else if (cfg.bufferCount > kNumBuffersMax) { + LOG(SimplePipeline, Debug) + << "Adjusting bufferCount from " << cfg.bufferCount + << " to " << kNumBuffersMax; + cfg.bufferCount = kNumBuffersMax; + status = Adjusted; + } } return status;