From patchwork Tue Jun 25 06:23:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20380 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 1C4B1BD87C for ; Tue, 25 Jun 2024 06:23:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 723C1654B1; Tue, 25 Jun 2024 08:23:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eSFv4YBt"; 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 392BA654A4 for ; Tue, 25 Jun 2024 08:23:35 +0200 (CEST) Received: from fedora.local (unknown [IPv6:2405:201:2015:f873:55d7:c02e:b2eb:ee3f]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6C5A9BEB; Tue, 25 Jun 2024 08:23:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1719296593; bh=jGaENnVcS2a8D2v/LbZ9+sCU/smJ9p83j+o0lSBNcbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eSFv4YBtSQWFYRHrpL3ohtGtOXyqYZNufImiz00KOH2VrkCTRZrexSqMi1Qob/E8C 460PEF2kCypESGO+nERMgcLdevcNkmttqYiMSQEgIHro8PmpYJPOPxvhLDROdYNqzy Kw5Y0AjfaCLC8nenuPH/4Qkf5YKQplgS43nOboYk= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Umang Jain Subject: [PATCH v3 2/4] libcamera: converter_v4l2_m2m: Support crop selection Date: Tue, 25 Jun 2024 11:53:25 +0530 Message-ID: <20240625062327.50940-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240625062327.50940-1-umang.jain@ideasonboard.com> References: <20240625062327.50940-1-umang.jain@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" Add a helper to set selection rectangle on the video node to support cropping and scaling capabilites. Signed-off-by: Umang Jain Reviewed-by: Kieran Bingham --- .../internal/converter/converter_v4l2_m2m.h | 5 ++++ .../converter/converter_v4l2_m2m.cpp | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h index b9e59899..846e9f9e 100644 --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -30,6 +30,7 @@ class Size; class SizeRange; class Stream; struct StreamConfiguration; +class Rectangle; class V4L2M2MDevice; class V4L2M2MConverter : public Converter @@ -57,6 +58,8 @@ public: int queueBuffers(FrameBuffer *input, const std::map &outputs); + int setSelection(const Stream *stream, unsigned int target, Rectangle *rect); + private: class V4L2M2MStream : protected Loggable { @@ -75,6 +78,8 @@ private: int queueBuffers(FrameBuffer *input, FrameBuffer *output); + int setSelection(unsigned int target, Rectangle *rect); + protected: std::string logPrefix() const override; diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp index 2e77872e..c323f677 100644 --- a/src/libcamera/converter/converter_v4l2_m2m.cpp +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp @@ -155,6 +155,15 @@ int V4L2M2MConverter::V4L2M2MStream::queueBuffers(FrameBuffer *input, FrameBuffe return 0; } +int V4L2M2MConverter::V4L2M2MStream::setSelection(unsigned int target, Rectangle *rect) +{ + int ret = m2m_->output()->setSelection(target, rect); + if (ret < 0) + return ret; + + return 0; +} + std::string V4L2M2MConverter::V4L2M2MStream::logPrefix() const { return stream_->configuration().toString(); @@ -374,6 +383,24 @@ int V4L2M2MConverter::exportBuffers(const Stream *stream, unsigned int count, return iter->second->exportBuffers(count, buffers); } +/** + * \brief Set a selection rectangle \a rect for \a target + * \param[in] stream Pointer to output stream + * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags + * \param[inout] rect The selection rectangle to be applied + * + * \return 0 on success or a negative error code otherwise + */ +int V4L2M2MConverter::setSelection(const Stream *stream, unsigned int target, + Rectangle *rect) +{ + auto iter = streams_.find(stream); + if (iter == streams_.end()) + return -EINVAL; + + return iter->second->setSelection(target, rect); +} + /** * \copydoc libcamera::Converter::start */