From patchwork Thu Oct 23 14:48:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24735 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 CD207C3335 for ; Thu, 23 Oct 2025 14:49:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 157AA607FB; Thu, 23 Oct 2025 16:49:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GCLMIe51"; 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 C2C7B607F3 for ; Thu, 23 Oct 2025 16:49:07 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:7328:357b:4ce1:72b6]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id D55AF195E; Thu, 23 Oct 2025 16:47:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761230842; bh=EsKEi/8heauykb2897O4r4q7gIAaQEdKGvmtRnyf6Rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GCLMIe51rp4716Buj4kFdpcuxuzFIICS3DJMY3m/f9HErcAQTEwFTkRNGmXq0yL1z bAKLdbAgeE4YKYDVnTNg7D4suZZar20AMelRxKRJAcdMgU4JKM/3ezCjWExsA8anji GBQBvTWTFe7a6fAu2MmbHj9H+SPUZxRB1Dz0tCY8= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 07/35] libcamera: converter_v4l2_m2m: Add suport for V4L2 requests Date: Thu, 23 Oct 2025 16:48:08 +0200 Message-ID: <20251023144841.403689-8-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251023144841.403689-1-stefan.klug@ideasonboard.com> References: <20251023144841.403689-1-stefan.klug@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" To actually use requests with the m2m device, requests need to be allocated on the underlying media device. This can only be done if the media device is opened which means acquiring it. Add a function to check if the m2m device supports requests by acquiring the media device, asking it and then releasing it again. Also add a function to allocate requests that acquires the internal media device and releases it after allocating the requests. Signed-off-by: Stefan Klug --- ToDo: - Fix the place where the MediaObject is acquired/released Changes in v2: - Improved commit message - Dropped the change from private to protected as that belongs to a different patch --- .../internal/converter/converter_v4l2_m2m.h | 7 ++++ .../converter/converter_v4l2_m2m.cpp | 34 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h index 1b2a88c4a608..bc85bff7a07b 100644 --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -73,6 +73,11 @@ public: std::pair inputCropBounds() override { return inputCropBounds_; } std::pair inputCropBounds(const Stream *stream) override; + int allocateRequests(unsigned int count, + std::vector> *requests); + + bool supportsRequests(); + private: class V4L2M2MStream : protected Loggable { @@ -122,6 +127,8 @@ private: std::map> streams_; std::map queue_; std::pair inputCropBounds_; + + std::shared_ptr media_; }; } /* namespace libcamera */ diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp index ff11a9735db7..c6153d728c9a 100644 --- a/src/libcamera/converter/converter_v4l2_m2m.cpp +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp @@ -9,6 +9,7 @@ #include "libcamera/internal/converter/converter_v4l2_m2m.h" #include +#include #include #include #include @@ -266,7 +267,7 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer) * \param[in] media The media device implementing the converter */ V4L2M2MConverter::V4L2M2MConverter(std::shared_ptr media) - : Converter(media) + : Converter(media), media_(media) { if (deviceNode().empty()) return; @@ -742,6 +743,37 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input, return 0; } +/** + * \copydoc libcamera::MediaDevice::allocateRequests + */ +int V4L2M2MConverter::allocateRequests(unsigned int count, + std::vector> *requests) +{ + /* \todo The acquire() must be moved to the right place. */ + media_->acquire(); + if (!media_->busy()) + LOG(Converter, Error) + << "MediaDevice must be valid."; + int ret = media_->allocateRequests(count, requests); + media_->release(); + return ret; +} + +/** + * \copydoc libcamera::MediaDevice::supportsRequests + */ +bool V4L2M2MConverter::supportsRequests() +{ + /* \todo The acquire() must be moved to the right place. */ + media_->acquire(); + if (!media_->busy()) + LOG(Converter, Error) + << "MediaDevice must be valid."; + bool ret = media_->supportsRequests(); + media_->release(); + return ret; +} + /* * \todo This should be extended to include Feature::Flag to denote * what each converter supports feature-wise.