Patch Detail
Show a patch.
GET /api/1.1/patches/13141/?format=api
{ "id": 13141, "url": "https://patchwork.libcamera.org/api/1.1/patches/13141/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13141/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210728161116.64489-3-jacopo@jmondi.org>", "date": "2021-07-28T16:11:13", "name": "[libcamera-devel,v2,2/5] libcamera: controls: Use ControlIdMap in deserialization", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "1b9b16a11969164539662fbf40274698f6d21e61", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13141/mbox/", "series": [ { "id": 2288, "url": "https://patchwork.libcamera.org/api/1.1/series/2288/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2288", "date": "2021-07-28T16:11:11", "name": "libcamera: Initialize controls in the IPA", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2288/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13141/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13141/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 960C3C322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jul 2021 16:10:36 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5C556687DD;\n\tWed, 28 Jul 2021 18:10:35 +0200 (CEST)", "from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2AA23687C8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jul 2021 18:10:33 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id B1BC16000E;\n\tWed, 28 Jul 2021 16:10:32 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 28 Jul 2021 18:11:13 +0200", "Message-Id": "<20210728161116.64489-3-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20210728161116.64489-1-jacopo@jmondi.org>", "References": "<20210728161116.64489-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 2/5] libcamera: controls: Use\n\tControlIdMap in deserialization", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Introduce a new field in the controls serialization protocol to\nallow discerning which ControlIdMap a ControlInfoMap refers to.\n\nThe newly introduced IdMapType enumeration describes the possible\ninfo maps:\n- Either the globally available controls::controls and\n properties::properties maps, which are valid across IPC boundaries\n- A ControlIdMap created locally by the V4L2 device, which is not valid\n across the IPC boundaries\n\nAt de-serialization time the idMapType filed is inspected and\n- If the idmap is a globally available one, there's no need to create\n new ControlId instances when populating the de-serialized\n ControlInfoMap. Use the globally available map to retrieve the\n ControlId reference and use it\n- If the idmap is a map only available locally, create a new ControlId\n as it used to happen before this patch.\n\nAs a direct consequence, this change allows to perform lookup by\nControlId reference on de-serialized ControlIdMap that refers to the\nlibcamera defined controls::controls and properties::properties.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/ipa/ipa_controls.h | 9 +++-\n src/libcamera/control_serializer.cpp | 73 +++++++++++++++++++++++-----\n src/libcamera/ipa_controls.cpp | 31 ++++++++++++\n 3 files changed, 101 insertions(+), 12 deletions(-)", "diff": "diff --git a/include/libcamera/ipa/ipa_controls.h b/include/libcamera/ipa/ipa_controls.h\nindex 6d3bf279c22d..5b1690066314 100644\n--- a/include/libcamera/ipa/ipa_controls.h\n+++ b/include/libcamera/ipa/ipa_controls.h\n@@ -15,13 +15,20 @@ extern \"C\" {\n \n #define IPA_CONTROLS_FORMAT_VERSION\t1\n \n+enum class IdMapType {\n+\tLIBCAMERA_CONTROLS,\n+\tLIBCAMERA_PROPERTIES,\n+\tV4L2_CONTROLS,\n+};\n+\n struct ipa_controls_header {\n \tuint32_t version;\n \tuint32_t handle;\n \tuint32_t entries;\n \tuint32_t size;\n \tuint32_t data_offset;\n-\tuint32_t reserved[3];\n+\tIdMapType idMapType;\n+\tuint32_t reserved[2];\n };\n \n struct ipa_control_value_entry {\ndiff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp\nindex df6ed93f477e..255f9d30fb85 100644\n--- a/src/libcamera/control_serializer.cpp\n+++ b/src/libcamera/control_serializer.cpp\n@@ -17,6 +17,7 @@\n #include <libcamera/control_ids.h>\n #include <libcamera/controls.h>\n #include <libcamera/ipa/ipa_controls.h>\n+#include <libcamera/property_ids.h>\n \n #include \"libcamera/internal/byte_stream_buffer.h\"\n \n@@ -188,6 +189,16 @@ int ControlSerializer::serialize(const ControlInfoMap &infoMap,\n \tfor (const auto &ctrl : infoMap)\n \t\tvaluesSize += binarySize(ctrl.second);\n \n+\t/* Serialize the id map type to be used when de-serializing. */\n+\tconst ControlIdMap *idmap = &infoMap.idmap();\n+\tenum IdMapType idMapType;\n+\tif (idmap == &controls::controls)\n+\t\tidMapType = IdMapType::LIBCAMERA_CONTROLS;\n+\telse if (idmap == &properties::properties)\n+\t\tidMapType = IdMapType::LIBCAMERA_PROPERTIES;\n+\telse\n+\t\tidMapType = IdMapType::V4L2_CONTROLS;\n+\n \t/* Prepare the packet header, assign a handle to the ControlInfoMap. */\n \tstruct ipa_controls_header hdr;\n \thdr.version = IPA_CONTROLS_FORMAT_VERSION;\n@@ -195,6 +206,7 @@ int ControlSerializer::serialize(const ControlInfoMap &infoMap,\n \thdr.entries = infoMap.size();\n \thdr.size = sizeof(hdr) + entriesSize + valuesSize;\n \thdr.data_offset = sizeof(hdr) + entriesSize;\n+\thdr.idMapType = idMapType;\n \n \tbuffer.write(&hdr);\n \n@@ -368,6 +380,34 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t\treturn {};\n \t}\n \n+\t/*\n+\t * Use the id map type to retrieve the ControlId instances associated\n+\t * to the serialized numerical identifier.\n+\t *\n+\t * If a globally available id map such as controls::controls or\n+\t * properties::properties is used, the ControlId instances can be\n+\t * retrieved from there.\n+\t *\n+\t * If, otherwise, the idmap is valid only on one side of the IPC\n+\t * boundary (as in case it has been created by the V4L2 devices)\n+\t * the deserializer shall create new ControlId and store them in an\n+\t * locally created id map.\n+\t */\n+\tconst ControlIdMap *idMap = nullptr;\n+\tControlIdMap *localIdMap;\n+\tswitch (hdr->idMapType) {\n+\tcase IdMapType::LIBCAMERA_CONTROLS:\n+\t\tidMap = &controls::controls;\n+\t\tbreak;\n+\tcase IdMapType::LIBCAMERA_PROPERTIES:\n+\t\tidMap = &properties::properties;\n+\t\tbreak;\n+\tcase IdMapType::V4L2_CONTROLS:\n+\t\tcontrolIdMaps_.emplace_back(std::make_unique<ControlIdMap>());\n+\t\tlocalIdMap = controlIdMaps_.back().get();\n+\t\tbreak;\n+\t}\n+\n \tByteStreamBuffer entries = buffer.carveOut(hdr->data_offset - sizeof(*hdr));\n \tByteStreamBuffer values = buffer.carveOut(hdr->size - hdr->data_offset);\n \n@@ -377,9 +417,6 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t}\n \n \tControlInfoMap::Map ctrls;\n-\tcontrolIdMaps_.emplace_back(std::make_unique<ControlIdMap>());\n-\tControlIdMap *localIdMap = controlIdMaps_.back().get();\n-\n \tfor (unsigned int i = 0; i < hdr->entries; ++i) {\n \t\tconst struct ipa_control_info_entry *entry =\n \t\t\tentries.read<decltype(*entry)>();\n@@ -388,15 +425,27 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t\t\treturn {};\n \t\t}\n \n-\t\t/* Create and cache the individual ControlId. */\n \t\tControlType type = static_cast<ControlType>(entry->type);\n-\t\t/**\n-\t\t * \\todo Find a way to preserve the control name for debugging\n-\t\t * purpose.\n+\n+\t\t/*\n+\t\t * If we have a valid id map, reuse the control id there stored,\n+\t\t * Otherwise populate the local idmap with a new ControlId\n+\t\t * reference.\n \t\t */\n-\t\tcontrolIds_.emplace_back(std::make_unique<ControlId>(entry->id, \"\", type));\n-\t\tControlId *controlId = controlIds_.back().get();\n-\t\t(*localIdMap)[entry->id] = controlId;\n+\t\tconst ControlId *controlId;\n+\t\tif (idMap) {\n+\t\t\tcontrolId = idMap->at(entry->id);\n+\t\t\tASSERT(controlId);\n+\t\t} else {\n+\t\t\t/**\n+\t\t\t * \\todo Find a way to preserve the control name for\n+\t\t\t * debugging purpose.\n+\t\t\t */\n+\t\t\tcontrolIds_.emplace_back(std::make_unique<ControlId>(entry->id,\n+\t\t\t\t\t\t\t\t\t \"\", type));\n+\t\t\tcontrolId = controlIds_.back().get();\n+\t\t\t(*localIdMap)[entry->id] = controlId;\n+\t\t}\n \n \t\tif (entry->offset != values.offset()) {\n \t\t\tLOG(Serializer, Error)\n@@ -405,10 +454,12 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t\t\treturn {};\n \t\t}\n \n-\t\t/* Create and store the ControlInfo. */\n \t\tctrls.emplace(controlId, loadControlInfo(type, values));\n \t}\n \n+\tif (!idMap)\n+\t\tidMap = localIdMap;\n+\n \t/*\n \t * Create the ControlInfoMap in the cache, and store the map to handle\n \t * association.\ndiff --git a/src/libcamera/ipa_controls.cpp b/src/libcamera/ipa_controls.cpp\nindex 8fd726513182..1323fa31a28f 100644\n--- a/src/libcamera/ipa_controls.cpp\n+++ b/src/libcamera/ipa_controls.cpp\n@@ -134,6 +134,35 @@\n * \\brief The current control serialization format version\n */\n \n+/**\n+ * \\enum IdMapType\n+ * \\brief Enumerates the different control id map types\n+ *\n+ * Each ControlInfoMap and ControlList refers to a control id map that\n+ * associates the ControlId references to a numerical identifier.\n+ * During the serialization procedure the raw pointers to the ControlId\n+ * instances cannot be transported on the wire, hence their numerical id is\n+ * used to identify them in the serialized data buffer. At deserialization time\n+ * it is required to associate back to the numerical id the ControlId instance\n+ * it represents. This enumeration describes which ControlIdMap should be\n+ * used to perform such operation.\n+ *\n+ * \\var IdMapType::LIBCAMERA_CONTROLS\n+ * \\brief The numerical control identifier are resolved to a ControlId * using\n+ * the global controls::controls id map\n+ *\n+ * \\var IdMapType::LIBCAMERA_PROPERTIES\n+ * \\brief The numerical control identifier are resolved to a ControlId * using\n+ * the global properties::properties id map\n+ *\n+ * \\var IdMapType::V4L2_CONTROLS\n+ * \\brief ControlId for V4L2 defined controls are created by the video device\n+ * that enumerates them, and are not available across the IPC boundaries. The\n+ * deserializer shall create new ControlId instances for them as well as store\n+ * them in a dedicated ControlIdMap. Only lookup by numerical id can be\n+ * performed on de-serialized ControlInfoMap that represents V4L2 controls.\n+ */\n+\n /**\n * \\struct ipa_controls_header\n * \\brief Serialized control packet header\n@@ -149,6 +178,8 @@\n * The total packet size in bytes\n * \\var ipa_controls_header::data_offset\n * Offset in bytes from the beginning of the packet of the data section start\n+ * \\var ipa_controls_header::idMapType\n+ * The id map type as defined by the IdMapType enumeration\n * \\var ipa_controls_header::reserved\n * Reserved for future extensions\n */\n", "prefixes": [ "libcamera-devel", "v2", "2/5" ] }