Patch Detail
Show a patch.
GET /api/1.1/patches/13287/?format=api
{ "id": 13287, "url": "https://patchwork.libcamera.org/api/1.1/patches/13287/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13287/", "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": "<20210810151211.56702-4-jacopo@jmondi.org>", "date": "2021-08-10T15:12:09", "name": "[libcamera-devel,v4,3/5] libcamera: controls: Use ControlIdMap in deserialization", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "a80cfe1ae0bacd0a05dfad58ed2bfc3463b0a8e3", "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/13287/mbox/", "series": [ { "id": 2334, "url": "https://patchwork.libcamera.org/api/1.1/series/2334/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2334", "date": "2021-08-10T15:12:06", "name": "libcamera: Initialize controls in the IPA", "version": 4, "mbox": "https://patchwork.libcamera.org/series/2334/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13287/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13287/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 2BB59C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 Aug 2021 15:11:31 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5161468888;\n\tTue, 10 Aug 2021 17:11:30 +0200 (CEST)", "from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 781D6687F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Aug 2021 17:11:28 +0200 (CEST)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id C7FA9200008;\n\tTue, 10 Aug 2021 15:11:27 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 10 Aug 2021 17:12:09 +0200", "Message-Id": "<20210810151211.56702-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20210810151211.56702-1-jacopo@jmondi.org>", "References": "<20210810151211.56702-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 3/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 field is inspected and\n- If the idmap is a globally defined 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 us 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>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/ipa/ipa_controls.h | 9 +++-\n src/libcamera/control_serializer.cpp | 65 +++++++++++++++++++++++-----\n src/libcamera/ipa_controls.cpp | 29 +++++++++++++\n 3 files changed, 90 insertions(+), 13 deletions(-)", "diff": "diff --git a/include/libcamera/ipa/ipa_controls.h b/include/libcamera/ipa/ipa_controls.h\nindex 6d3bf279c22d..eec34d9267af 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 ipa_controls_id_map_type {\n+\tIPA_CONTROL_ID_MAP_CONTROLS,\n+\tIPA_CONTROL_ID_MAP_PROPERTIES,\n+\tIPA_CONTROL_ID_MAP_V4L2,\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+\tenum ipa_controls_id_map_type id_map_type;\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 ed456fd445a0..ba277393d517 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,15 @@ int ControlSerializer::serialize(const ControlInfoMap &infoMap,\n \tfor (const auto &ctrl : infoMap)\n \t\tvaluesSize += binarySize(ctrl.second);\n \n+\tconst ControlIdMap *idmap = &infoMap.idmap();\n+\tenum ipa_controls_id_map_type idMapType;\n+\tif (idmap == &controls::controls)\n+\t\tidMapType = IPA_CONTROL_ID_MAP_CONTROLS;\n+\telse if (idmap == &properties::properties)\n+\t\tidMapType = IPA_CONTROL_ID_MAP_PROPERTIES;\n+\telse\n+\t\tidMapType = IPA_CONTROL_ID_MAP_V4L2;\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 +205,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.id_map_type = idMapType;\n \n \tbuffer.write(&hdr);\n \n@@ -368,6 +379,33 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t\treturn {};\n \t}\n \n+\t/*\n+\t * Use the ControlIdMap corresponding to the id map type. If the type\n+\t * references a globally defined id map (such as controls::controls\n+\t * or properties::properties), use it. Otherwise, create a local id map\n+\t * that will be populated with dynamically created ControlId instances\n+\t * when deserializing individual ControlInfoMap entries.\n+\t */\n+\tconst ControlIdMap *idMap = nullptr;\n+\tControlIdMap *localIdMap = nullptr;\n+\tswitch (hdr->id_map_type) {\n+\tcase IPA_CONTROL_ID_MAP_CONTROLS:\n+\t\tidMap = &controls::controls;\n+\t\tbreak;\n+\tcase IPA_CONTROL_ID_MAP_PROPERTIES:\n+\t\tidMap = &properties::properties;\n+\t\tbreak;\n+\tcase IPA_CONTROL_ID_MAP_V4L2:\n+\t\tcontrolIdMaps_.emplace_back(std::make_unique<ControlIdMap>());\n+\t\tlocalIdMap = controlIdMaps_.back().get();\n+\t\tidMap = localIdMap;\n+\t\tbreak;\n+\tdefault:\n+\t\tLOG(Serializer, Error)\n+\t\t\t<< \"Unknown id map type: \" << hdr->id_map_type;\n+\t\treturn {};\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 +415,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 +423,21 @@ 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-\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+\n+\t\t/* If we're using a local id map, populate it. */\n+\t\tif (localIdMap) {\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\t(*localIdMap)[entry->id] = controlIds_.back().get();\n+\t\t}\n+\n+\t\tconst ControlId *controlId = idMap->at(entry->id);\n+\t\tASSERT(controlId);\n \n \t\tif (entry->offset != values.offset()) {\n \t\t\tLOG(Serializer, Error)\n@@ -413,7 +454,7 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t * Create the ControlInfoMap in the cache, and store the map to handle\n \t * association.\n \t */\n-\tinfoMaps_[hdr->handle] = ControlInfoMap(std::move(ctrls), *localIdMap);\n+\tinfoMaps_[hdr->handle] = ControlInfoMap(std::move(ctrls), *idMap);\n \tControlInfoMap &map = infoMaps_[hdr->handle];\n \tinfoMapHandles_[&map] = hdr->handle;\n \ndiff --git a/src/libcamera/ipa_controls.cpp b/src/libcamera/ipa_controls.cpp\nindex 8fd726513182..fb98cda30ede 100644\n--- a/src/libcamera/ipa_controls.cpp\n+++ b/src/libcamera/ipa_controls.cpp\n@@ -134,6 +134,33 @@\n * \\brief The current control serialization format version\n */\n \n+/**\n+ * \\var ipa_controls_id_map_type\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 ipa_controls_id_map_type::IPA_CONTROL_ID_MAP_CONTROLS\n+ * \\brief The numerical control identifier are resolved to a ControlId * using\n+ * the global controls::controls id map\n+ * \\var ipa_controls_id_map_type::IPA_CONTROL_ID_MAP_PROPERTIES\n+ * \\brief The numerical control identifier are resolved to a ControlId * using\n+ * the global properties::properties id map\n+ * \\var ipa_controls_id_map_type::IPA_CONTROL_ID_MAP_V4L2\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 +176,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::id_map_type\n+ * The id map type as defined by the ipa_controls_id_map_type enumeration\n * \\var ipa_controls_header::reserved\n * Reserved for future extensions\n */\n", "prefixes": [ "libcamera-devel", "v4", "3/5" ] }