From patchwork Fri Jul 12 05:29:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20649 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 AAA9FBDB1C for ; Fri, 12 Jul 2024 05:29:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C643463374; Fri, 12 Jul 2024 07:29:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uy5FYBQy"; 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 94B8E619A9 for ; Fri, 12 Jul 2024 07:29:33 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2405:201:2015:f873:55f8:639e:8e9f:12ec]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 81BB5D50; Fri, 12 Jul 2024 07:28:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720762139; bh=d9nWrdKic1P+XVgN81WRUQs94uSk0gkUXefH13F5mfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uy5FYBQyYcXlofQPfjGA6ee+GVlD1LvIkNu/dYn5VlO0OEyGyOS1t0SaPeX0/nhz0 ZJZgzzRuEJz7RIaEfRMqBI9Iw8zGQnNYUYpZpQLTMY+RmD/jBu7Lvmi10Nu/ehI2Lc 6NhHdZ5DL1nmUYpSsgMhrWpWHV7QctDZS8adm9+o= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Xavier Roumegue , Umang Jain Subject: [RFC PATCH 1/6] libcamera: v4l2_device: Add support for V4L2_CTRL_TYPE_U32 Date: Fri, 12 Jul 2024 10:59:15 +0530 Message-ID: <20240712052920.33396-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240712052920.33396-1-umang.jain@ideasonboard.com> References: <20240712052920.33396-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" Support for the U16 and U32 compound control types is missing. U16 will require a new libcamera control type, but U32 maps to the existing ControlTypeInteger32 and can be added easily. Signed-off-by: Umang Jain --- include/libcamera/controls.h | 5 +++++ src/libcamera/v4l2_device.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 7c2bb287..c6db4ebb 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -57,6 +57,11 @@ struct control_type { static constexpr ControlType value = ControlTypeByte; }; +template<> +struct control_type { + static constexpr ControlType value = ControlTypeInteger32; +}; + template<> struct control_type { static constexpr ControlType value = ControlTypeInteger32; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 4a2048cf..db20f31c 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -212,6 +212,10 @@ ControlList V4L2Device::getControls(const std::vector &ids) type = ControlTypeByte; break; + case V4L2_CTRL_TYPE_U32: + type = ControlTypeInteger32; + break; + default: LOG(V4L2, Error) << "Unsupported payload control type " @@ -491,6 +495,7 @@ ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType) return ControlTypeBool; case V4L2_CTRL_TYPE_INTEGER: + case V4L2_CTRL_TYPE_U32: return ControlTypeInteger32; case V4L2_CTRL_TYPE_INTEGER64: @@ -543,6 +548,11 @@ std::optional V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl static_cast(ctrl.maximum), static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_U32: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_INTEGER64: return ControlInfo(static_cast(ctrl.minimum), static_cast(ctrl.maximum), @@ -624,6 +634,7 @@ void V4L2Device::listControls() case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_U8: + case V4L2_CTRL_TYPE_U32: break; /* \todo Support other control types. */ default: From patchwork Fri Jul 12 05:29:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20650 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 8AA06BDB1C for ; Fri, 12 Jul 2024 05:29:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3468563378; Fri, 12 Jul 2024 07:29:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LfCDGdx1"; 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 4E84163371 for ; Fri, 12 Jul 2024 07:29:35 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2405:201:2015:f873:55f8:639e:8e9f:12ec]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F2159CC8; Fri, 12 Jul 2024 07:28:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720762140; bh=pS8ZNhEAjZ3R9W6fOfdb5YHkNlSnq0N3U4oT2PMaaP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LfCDGdx1OtR/eNL1DC8JXbLU5mmC7VYItYvKxr0eVqH1quMOFV4k8jnvTjhCzPq4d J7BDTHDK45nXnf7isdy81qAwssMBnZRnjNsD9Cpz2Bq6QYb8kjhFZpOtrkfUK3oVLB uVMefrBwnBxJM7YhWZcy2JfPGkM07oX1YyWixBLo= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Xavier Roumegue , Umang Jain Subject: [RFC PATCH 2/6] include: linux: Update headers for Dw100 dewarper engine Date: Fri, 12 Jul 2024 10:59:16 +0530 Message-ID: <20240712052920.33396-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240712052920.33396-1-umang.jain@ideasonboard.com> References: <20240712052920.33396-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" From: Xavier Roumegue Include the DW100 dewarper header as part of linux headers. It will be used to set the V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP control by ConverterDW100 Signed-off-by: Xavier Roumegue Signed-off-by: Umang Jain Acked-by: Jacopo Mondi --- include/linux/dw100.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 include/linux/dw100.h diff --git a/include/linux/dw100.h b/include/linux/dw100.h new file mode 100644 index 00000000..3356496e --- /dev/null +++ b/include/linux/dw100.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* Copyright 2022 NXP */ + +#ifndef __UAPI_DW100_H__ +#define __UAPI_DW100_H__ + +#include + +/* + * Check Documentation/userspace-api/media/drivers/dw100.rst for control details. + */ +#define V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP (V4L2_CID_USER_DW100_BASE + 1) + +#endif From patchwork Fri Jul 12 05:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20651 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 5EF16BDB1C for ; Fri, 12 Jul 2024 05:29:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E3F046337A; Fri, 12 Jul 2024 07:29:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="J2sYmYg/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 81B3C6336E for ; Fri, 12 Jul 2024 07:29:36 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2405:201:2015:f873:55f8:639e:8e9f:12ec]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6C3BAD50; Fri, 12 Jul 2024 07:29:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720762142; bh=qMn3R1HdkGQNP0A9FbcXQQtgNYGG5yOo3ZcJfdSZ0jw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J2sYmYg/qIT9NetQ1hMTFoGT/BHopoH881jCO/++O1r7yk6ccae0kxV1pkIWthM/W pDLkXP60M8A3f2doSDaxBpqPDOiA4Y7IDi612iiGZ205tdWolxN3WYYXlMy0ICsVgY MwNDuw7EzMCcbymWr+e7SxVVcQTKJTHnMdhlIUTk= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Xavier Roumegue , Umang Jain Subject: [RFC PATCH 3/6] libcamera: yaml_parser: Increase sentinel to 100k Date: Fri, 12 Jul 2024 10:59:17 +0530 Message-ID: <20240712052920.33396-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240712052920.33396-1-umang.jain@ideasonboard.com> References: <20240712052920.33396-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" From: Xavier Roumegue Instead of manually increasing the limit, prepare a constexpr for maximum sentinel and use that instead. Signed-off-by: Xavier Roumegue Signed-off-by: Umang Jain --- src/libcamera/yaml_parser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 025006bc..09ed75f1 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -690,6 +690,8 @@ void YamlParserContext::readValue(std::string &value, EventPtr event) int YamlParserContext::parseDictionaryOrList(YamlObject::Type type, const std::function &parseItem) { + constexpr unsigned int maxSentinel = 100000; + yaml_event_type_t endEventType = YAML_SEQUENCE_END_EVENT; if (type == YamlObject::Type::Dictionary) endEventType = YAML_MAPPING_END_EVENT; @@ -698,7 +700,7 @@ int YamlParserContext::parseDictionaryOrList(YamlObject::Type type, * Add a safety counter to make sure we don't loop indefinitely in case * the YAML file is malformed. */ - for (unsigned int sentinel = 2000; sentinel; sentinel--) { + for (unsigned int sentinel = maxSentinel; sentinel; sentinel--) { auto evt = nextEvent(); if (!evt) return -EINVAL; @@ -711,8 +713,9 @@ int YamlParserContext::parseDictionaryOrList(YamlObject::Type type, return ret; } - LOG(YamlParser, Error) << "The YAML file contains a List or Dictionary" - " whose size exceeds the parser's limit (1000)"; + LOG(YamlParser, Error) + << "The YAML file contains a List or Dictionary whose size exceeds" + << " the parser's limit (" << maxSentinel << ")"; return -EINVAL; } From patchwork Fri Jul 12 05:29:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20652 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 73305BDB1C for ; Fri, 12 Jul 2024 05:29:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1542163380; Fri, 12 Jul 2024 07:29:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="vJzcLdMr"; 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 03EF063375 for ; Fri, 12 Jul 2024 07:29:38 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2405:201:2015:f873:55f8:639e:8e9f:12ec]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DAE1CCC8; Fri, 12 Jul 2024 07:29:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720762143; bh=5tqWoobuZgvPGY3SNqsGS28koWPuZHeYd+jVzUHZLds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vJzcLdMrPJ8FlT4vR7+r25ypRfYj8SCVrN47h0PXLgvY+Q7MUL391GpxSzQVz7Z3S fQlhJS0Bs9QML3VPg/r/RO1P5JDeKhc4vRiUtorTRWL+JNux0No3oDucQ4he5iSNgO Qr/DDRHAeT1VrSQ0KOEJumH0xSOHSW1mDWwn1orE= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Xavier Roumegue , Umang Jain Subject: [RFC PATCH 4/6] libcamera: converter_v4l2_m2m: Add vertex mapping class Date: Fri, 12 Jul 2024 10:59:18 +0530 Message-ID: <20240712052920.33396-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240712052920.33396-1-umang.jain@ideasonboard.com> References: <20240712052920.33396-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 vertex mapping protected class to V4L2M2M converter class. Instances of this class will store a dewarp vertex mappings along with their input/output configuration. Add a vector of Mapping class and applyMapping() helper as well, to apply relevant mappings to V4L2Stream. ConverterDW100 will use this helper to set vertex maps, in subsequent patch. Signed-off-by: Umang Jain --- .../internal/converter/converter_v4l2_m2m.h | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h index 2697eed9..f61beef8 100644 --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -61,6 +61,26 @@ public: int setCrop(const Stream *stream, Rectangle *rect); std::pair getCropBounds(const Stream *stream); +protected: + class Mapping + { + public: + Mapping(const Size &input, const Size &output, const std::vector &map) + : input_(input), output_(output), map_(map) {} + Size inputSize() const { return input_; } + Size outputSize() const { return output_; } + std::size_t size() const { return map_.size(); } + const uint32_t *mapping() const { return map_.data(); } + + private: + Size input_; + Size output_; + std::vector map_; + }; + + int applyMapping(const Stream *stream, Mapping &mapping); + std::vector mappings_; + private: class V4L2M2MStream : protected Loggable { From patchwork Fri Jul 12 05:29:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20653 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 A0BEAC328C for ; Fri, 12 Jul 2024 05:29:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AC16963377; Fri, 12 Jul 2024 07:29:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qrAH9KDx"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F52963377 for ; Fri, 12 Jul 2024 07:29:39 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2405:201:2015:f873:55f8:639e:8e9f:12ec]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 54146191B; Fri, 12 Jul 2024 07:29:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720762145; bh=JorrjuSnTDdfn96gkyLW8ukdpSDHC33JP/GOpH6t8rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qrAH9KDxfPbiRm+bv5EAqxhdQHAzheyQvmMOvz56TmOUeMibTgXVM0Y+7gjP5gJFE HZTJieVpPRVU2Rp8i6Wxkx5L8lh2a6sLBYuLbdUkMErtsiV/UFYOl/PPTOy/sccdDX QbUIOpMaL0Mp/uvQaq3tNME8twmh9Oe8RRcvt+jY= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Xavier Roumegue , Umang Jain Subject: [RFC PATCH 5/6] libcamera: converter_v4l2_m2m: Add helper to apply controls Date: Fri, 12 Jul 2024 10:59:19 +0530 Message-ID: <20240712052920.33396-6-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240712052920.33396-1-umang.jain@ideasonboard.com> References: <20240712052920.33396-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 applyControls() helper to apply controls for a stream. Signed-off-by: Umang Jain --- .../internal/converter/converter_v4l2_m2m.h | 5 +++++ src/libcamera/converter/converter_v4l2_m2m.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h index f61beef8..9d3d62d6 100644 --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -24,6 +24,7 @@ namespace libcamera { +class ControlList; class FrameBuffer; class MediaDevice; class Size; @@ -61,6 +62,8 @@ public: int setCrop(const Stream *stream, Rectangle *rect); std::pair getCropBounds(const Stream *stream); + int applyControls(const Stream *stream, ControlList &ctrls); + protected: class Mapping { @@ -97,6 +100,8 @@ private: int start(); void stop(); + int applyControls(ControlList &ctrls); + int queueBuffers(FrameBuffer *input, FrameBuffer *output); int setSelection(unsigned int target, Rectangle *rect); diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp index 9752a23e..9ff5102a 100644 --- a/src/libcamera/converter/converter_v4l2_m2m.cpp +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -186,6 +187,11 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer) converter_->outputBufferReady.emit(buffer); } +int V4L2M2MConverter::V4L2M2MStream::applyControls(ControlList &ctrls) +{ + return m2m_->capture()->setControls(&ctrls); +}; + /* ----------------------------------------------------------------------------- * V4L2M2MConverter */ @@ -532,6 +538,18 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input, return 0; } +/** + * libcamera::Converter::applyControls + */ +int V4L2M2MConverter::applyControls(const Stream *stream, ControlList &ctrls) +{ + auto iter = streams_.find(stream); + if (iter == streams_.end()) + return -EINVAL; + + return iter->second->applyControls(ctrls); +} + /* * \todo: This should be extended to include Feature::Flag to denote * what each converter supports feature-wise. From patchwork Fri Jul 12 05:29:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20654 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 F2512BDB1C for ; Fri, 12 Jul 2024 05:29:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7050D63374; Fri, 12 Jul 2024 07:29:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PMl6w/gV"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D921263373 for ; Fri, 12 Jul 2024 07:29:40 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2405:201:2015:f873:55f8:639e:8e9f:12ec]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C120DCC8; Fri, 12 Jul 2024 07:29:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1720762146; bh=ie7HwfJuw/xdXZQNuu2T2/iCexCnVjC/rUn72ssmos8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PMl6w/gVyS5en74MjT8ZaNLfIPybK5e+KF9MiDuXfVHwGVW51JaoqdMi3LBvzhoWf 2uTWNWh1NjGxEUyDBdLLhnWLpGP8y5VwT1TxbvKVAfXY+LaIWx+4PzvqjGqIYdaaam puxgY33cHD43WbyfZ5/77TvdXn6Nl4lXSopHgz6Q= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Xavier Roumegue , Umang Jain Subject: [RFC PATCH 6/6] libcamera: converter_dw100: Load and apply dewarp vertex maps Date: Fri, 12 Jul 2024 10:59:20 +0530 Message-ID: <20240712052920.33396-7-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240712052920.33396-1-umang.jain@ideasonboard.com> References: <20240712052920.33396-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" Load the dewarp vertex maps for different configurations using the LIBCAMERA_DEWARP_CONFIG_FILE environment variable. In addition, provide a applyMappings(stream) API for converter_dw100, in order to apply mappings for the given stream. Plumb it into rkisp1 pipeline handler, if the dewarper is being used. \todo The parsing of dewarp configuration file is yet to be determined. I've used the same parsing logic as made in previous attempts: https://patchwork.libcamera.org/patch/17348/ Signed-off-by: Umang Jain --- .../internal/converter/converter_dw100.h | 5 + src/libcamera/converter/converter_dw100.cpp | 127 ++++++++++++++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 4 + 3 files changed, 136 insertions(+) diff --git a/include/libcamera/internal/converter/converter_dw100.h b/include/libcamera/internal/converter/converter_dw100.h index dc41f365..a3062e84 100644 --- a/include/libcamera/internal/converter/converter_dw100.h +++ b/include/libcamera/internal/converter/converter_dw100.h @@ -19,6 +19,11 @@ class ConverterDW100 : public V4L2M2MConverter { public: ConverterDW100(std::shared_ptr media); + + int applyMappings(const Stream *stream); + +private: + int loadDewarpMaps(); }; } /* namespace libcamera */ diff --git a/src/libcamera/converter/converter_dw100.cpp b/src/libcamera/converter/converter_dw100.cpp index 3061fc71..1a641779 100644 --- a/src/libcamera/converter/converter_dw100.cpp +++ b/src/libcamera/converter/converter_dw100.cpp @@ -7,12 +7,17 @@ #include "libcamera/internal/converter/converter_dw100.h" +#include + +#include #include +#include #include #include "libcamera/internal/media_device.h" #include "libcamera/internal/v4l2_videodevice.h" +#include "libcamera/internal/yaml_parser.h" namespace libcamera { @@ -32,6 +37,128 @@ LOG_DECLARE_CATEGORY(Converter) ConverterDW100::ConverterDW100(std::shared_ptr media) : V4L2M2MConverter(media.get(), Feature::Crop) { + loadDewarpMaps(); +} + +int ConverterDW100::loadDewarpMaps() +{ + int ret; + + char const *configFromEnv = utils::secure_getenv("LIBCAMERA_DEWARP_CONFIG_FILE"); + if (!configFromEnv || *configFromEnv == '\0') + return 0; + + LOG(Converter, Info) << "Parsing dewarp configuration file " << configFromEnv; + + std::string filename = std::string(configFromEnv); + File file(filename); + + if (!file.open(File::OpenModeFlag::ReadOnly)) { + ret = file.error(); + LOG(Converter, Error) << "Failed to open configuration file " + << filename << ": " << strerror(-ret); + return ret; + } + + std::unique_ptr data = YamlParser::parse(file); + if (!data) + return -EINVAL; + + if (!data->contains("mappings")) { + LOG(Converter, Error) << "Vertex mapping key missing"; + return -EINVAL; + } + + const YamlObject &mappings = (*data)["mappings"]; + if (!mappings.isList() || mappings.size() == 0) { + LOG(Converter, Error) << "Invalid mappings entry"; + return -EINVAL; + } + + LOG(Converter, Debug) << "Parsing " << mappings.size() << " mappings"; + mappings_.clear(); + mappings_.reserve(mappings.size()); + + for (std::size_t i = 0; i < mappings.size(); i++) { + const YamlObject &mapping = mappings[i]; + if (!mapping.isDictionary()) { + LOG(Converter, Error) << "Mapping is not a dictionary"; + return -EINVAL; + } + + if (!mapping.contains("input-resolution")) { + LOG(Converter, Error) << "Input resolution missing"; + return -EINVAL; + } + + if (!mapping.contains("output-resolution")) { + LOG(Converter, Error) << "Output resolution missing"; + return -EINVAL; + } + + if (!mapping.contains("mapping")) { + LOG(Converter, Error) << "Mapping table missing"; + return -EINVAL; + } + + const YamlObject &input_res = mapping["input-resolution"]; + if (!input_res.isList() || input_res.size() != 2) { + LOG(Converter, Error) << "Incorrect input resolution"; + return -EINVAL; + } + + const YamlObject &output_res = mapping["output-resolution"]; + if (!output_res.isList() || output_res.size() != 2) { + LOG(Converter, Error) << "Incorrect output resolution"; + return -EINVAL; + } + + const YamlObject &map = mapping["mapping"]; + if (!map.isList() || map.size() == 0) { + LOG(Converter, Error) << "Incorrect mapping entries"; + return -EINVAL; + } + + Size input(input_res[0].get(0), input_res[1].get(0)); + Size output(output_res[0].get(0), output_res[1].get(0)); + const auto &mapVector = map.getList().value_or(std::vector{}); + + LOG(Converter, Debug) + << "Input/Output mapping resolution " << input << " -> " << output; + + mappings_.emplace_back(Mapping(input, output, mapVector)); + } + + return mappings.size(); +} + +/* + * \brief Apply + * \todo this is just a wrapper, trying to test waters + * \param[in] media The media device implementing the converter + */ +int ConverterDW100::applyMappings(const Stream *stream) +{ + const StreamConfiguration &config = stream->configuration(); + ControlList ctrls; + int ret = 0; + + for (const auto &map : mappings_) { + /* Currently DW100's input and output configuration are same. */ + if (map.inputSize() == config.size && + map.outputSize() == config.size) { + auto value = Span(reinterpret_cast(map.mapping()), map.size()); + + ControlValue c(value); + ctrls.set(V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP, c); + ret = applyControls(stream, ctrls); + + LOG(Converter, Debug) << "Dewarp mapping applied for " << config.toString(); + break; + } + } + + return ret; } } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 881e10e1..f102b364 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -1019,6 +1019,10 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlL LOG(RkISP1, Error) << "Failed to start dewarper"; return ret; } + + ret = dewarper_->applyMappings(&data->mainPathStream_); + if (ret) + LOG(RkISP1, Warning) << "Dewarper mapping couldn't be applied"; } }