From patchwork Wed Dec 28 22:29:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 18066 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 2F0AFC3220 for ; Wed, 28 Dec 2022 22:30:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CBB86625FE; Wed, 28 Dec 2022 23:30:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1672266637; bh=CgTVHMsudzEX7Z7J8lk8mQNzHP/BX6KslEspC+7juCw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=U4vN2VmZEujhPe+1gjbY7R8Z0bd0vojns9l9j8BOCqLbw4fHgJmeHcxNB1iYvknjV 4bxNcKg95cjIlEof1b/GgyN/azuQ7qsHyL3q0axjQRNes3Zj9kIwAH4+4F276LUo4/ HxvrryQZl6c1tx6wJNjCCJMVZYEN7eEW7fxCwJGf/PMzvNR6IQV6nu6DJ32swRbStY Ee2Doany/rh5yPbd+ioK46RoDNHOvZmBaSeSD589YDj4pqC2ft8UortMfD9pq1jklw s9Y+Fb8ItnObI3SqZyUnl5sgeGYPMm6E3oxQ8Bktc9Yn6sUM1zFPDz3u692ytmnA1v I/g0tyJJqzS/Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E789625EB for ; Wed, 28 Dec 2022 23:30:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eXj6PT2q"; dkim-atps=neutral Received: from pyrite.mediacom.info (unknown [IPv6:2604:2d80:ad8a:9000:1bf9:855b:22de:3645]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E121109; Wed, 28 Dec 2022 23:30:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1672266629; bh=CgTVHMsudzEX7Z7J8lk8mQNzHP/BX6KslEspC+7juCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXj6PT2qpMZr2WApM98NrqEvlZ3TxEcFd1n2rcth8yuMPfxE7Vm1VNhWqY63Bynf+ 2jE3Dtrh6ClXGSxhD0vl3L2/7b8PUGCRVg8ig8BavJZoxeFvsKgBlo1+X6ukafVePe keEKMhvp2MxPnruWy/TnoDHe7AdFaxxKOiKeodx4= To: libcamera-devel@lists.libcamera.org Date: Wed, 28 Dec 2022 16:29:54 -0600 Message-Id: <20221228223003.2265712-11-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221228223003.2265712-1-paul.elder@ideasonboard.com> References: <20221228223003.2265712-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 10/19] v4l2: Allocate buffers based on requested count and MinimumRequests 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: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: NĂ­colas F. R. A. Prado Currently the number of buffers allocated is based on bufferCount, which is hardcoded to 1. Instead allocate buffers based on the requested count and on the MinimumRequests property for the camera, which is accessed through a newly added getter. This allows the removal of bufferCount. While at it, fix a typo: s/interval/internal/. Signed-off-by: NĂ­colas F. R. A. Prado Reviewed-by: Paul Elder Signed-off-by: Paul Elder --- Changes in v9: - rebased Changes in v8: - New - Fixed typo: s/interval/internal/ --- src/v4l2/v4l2_camera.cpp | 20 +++++++++++++------- src/v4l2/v4l2_camera.h | 5 +++-- src/v4l2/v4l2_camera_proxy.cpp | 10 +++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp index 1c5fab64..eb0fd239 100644 --- a/src/v4l2/v4l2_camera.cpp +++ b/src/v4l2/v4l2_camera.cpp @@ -12,6 +12,8 @@ #include +#include + using namespace libcamera; LOG_DECLARE_CATEGORY(V4L2Compat) @@ -106,15 +108,13 @@ void V4L2Camera::requestComplete(Request *request) } int V4L2Camera::configure(StreamConfiguration *streamConfigOut, - const Size &size, const PixelFormat &pixelformat, - unsigned int bufferCount) + const Size &size, const PixelFormat &pixelformat) { StreamConfiguration &streamConfig = config_->at(0); streamConfig.size.width = size.width; streamConfig.size.height = size.height; streamConfig.pixelFormat = pixelformat; - streamConfig.bufferCount = bufferCount; - /* \todo memoryType (interval vs external) */ + /* \todo memoryType (internal vs external) */ CameraConfiguration::Status validation = config_->validate(); if (validation == CameraConfiguration::Invalid) { @@ -145,7 +145,6 @@ int V4L2Camera::validateConfiguration(const PixelFormat &pixelFormat, StreamConfiguration &cfg = config->at(0); cfg.size = size; cfg.pixelFormat = pixelFormat; - cfg.bufferCount = 1; CameraConfiguration::Status validation = config->validate(); if (validation == CameraConfiguration::Invalid) @@ -164,7 +163,9 @@ int V4L2Camera::allocBuffers(unsigned int count) if (ret < 0) return ret; - for (unsigned int i = 0; i < count; i++) { + unsigned int allocatedCount = ret; + + for (unsigned int i = 0; i < allocatedCount; i++) { std::unique_ptr request = camera_->createRequest(i); if (!request) { requestPool_.clear(); @@ -173,7 +174,7 @@ int V4L2Camera::allocBuffers(unsigned int count) requestPool_.push_back(std::move(request)); } - return ret; + return allocatedCount; } void V4L2Camera::freeBuffers() @@ -298,3 +299,8 @@ bool V4L2Camera::isRunning() { return isRunning_; } + +unsigned int V4L2Camera::minimumRequests() +{ + return camera_->properties().get(properties::MinimumRequests).value(); +} diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index d3483444..ada66421 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -43,8 +43,7 @@ public: int configure(libcamera::StreamConfiguration *streamConfigOut, const libcamera::Size &size, - const libcamera::PixelFormat &pixelformat, - unsigned int bufferCount); + const libcamera::PixelFormat &pixelformat); int validateConfiguration(const libcamera::PixelFormat &pixelformat, const libcamera::Size &size, libcamera::StreamConfiguration *streamConfigOut); @@ -63,6 +62,8 @@ public: bool isRunning(); + unsigned int minimumRequests(); + private: void requestComplete(libcamera::Request *request) LIBCAMERA_TSA_EXCLUDES(bufferLock_); diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 55ff62cd..bcf9c2ab 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -367,8 +367,7 @@ int V4L2CameraProxy::vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg) Size size(arg->fmt.pix.width, arg->fmt.pix.height); V4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->fmt.pix.pixelformat); - ret = vcam_->configure(&streamConfig_, size, v4l2Format.toPixelFormat(), - bufferCount_); + ret = vcam_->configure(&streamConfig_, size, v4l2Format.toPixelFormat()); if (ret < 0) return -EINVAL; @@ -514,14 +513,13 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf Size size(v4l2PixFormat_.width, v4l2PixFormat_.height); V4L2PixelFormat v4l2Format = V4L2PixelFormat(v4l2PixFormat_.pixelformat); int ret = vcam_->configure(&streamConfig_, size, - v4l2Format.toPixelFormat(), arg->count); + v4l2Format.toPixelFormat()); if (ret < 0) return -EINVAL; setFmtFromConfig(streamConfig_); - arg->count = streamConfig_.bufferCount; - bufferCount_ = arg->count; + arg->count = std::max(arg->count, vcam_->minimumRequests()); ret = vcam_->allocBuffers(arg->count); if (ret < 0) { @@ -529,6 +527,8 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf return ret; } + bufferCount_ = arg->count = ret; + buffers_.resize(arg->count); for (unsigned int i = 0; i < arg->count; i++) { struct v4l2_buffer buf = {};