[libcamera-devel] [PATCH v7 01/10] libcamera: control_serializer: Save serialized ControlInfoMap in a cache

Paul Elder paul.elder at ideasonboard.com
Thu Feb 11 08:17:56 CET 2021


The ControlSerializer saves all ControlInfoMaps that it has already
(de)serialized, in order to (de)serialize ControlLists that contain the
ControlInfoMaps. Leverage this to cache ControlInfoMaps, such that the
ControlSerializer will not re-(de)serialize a ControlInfoMap that it has
previously (de)serialized.

Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

---
Changes in v7:
- log cache status to Debug instead of Info
- fix doc wording
- pass const reference to isCached instead of const pointer
- simplify isCached implementation

New in v6
---
 .../libcamera/internal/control_serializer.h   |  2 ++
 src/libcamera/control_serializer.cpp          | 26 +++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/include/libcamera/internal/control_serializer.h b/include/libcamera/internal/control_serializer.h
index 0ab29d9a..7d4426c9 100644
--- a/include/libcamera/internal/control_serializer.h
+++ b/include/libcamera/internal/control_serializer.h
@@ -33,6 +33,8 @@ public:
 	template<typename T>
 	T deserialize(ByteStreamBuffer &buffer);
 
+	bool isCached(const ControlInfoMap &infoMap);
+
 private:
 	static size_t binarySize(const ControlValue &value);
 	static size_t binarySize(const ControlInfo &info);
diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
index 258db6df..09744413 100644
--- a/src/libcamera/control_serializer.cpp
+++ b/src/libcamera/control_serializer.cpp
@@ -173,6 +173,12 @@ void ControlSerializer::store(const ControlInfo &info, ByteStreamBuffer &buffer)
 int ControlSerializer::serialize(const ControlInfoMap &infoMap,
 				 ByteStreamBuffer &buffer)
 {
+	if (isCached(infoMap)) {
+		LOG(Serializer, Debug)
+			<< "Skipping already serialized ControlInfoMap";
+		return 0;
+	}
+
 	/* Compute entries and data required sizes. */
 	size_t entriesSize = infoMap.size()
 			   * sizeof(struct ipa_control_info_entry);
@@ -347,6 +353,12 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &
 		return {};
 	}
 
+	auto iter = infoMaps_.find(hdr->handle);
+	if (iter != infoMaps_.end()) {
+		LOG(Serializer, Debug) << "Use cached ControlInfoMap";
+		return iter->second;
+	}
+
 	if (hdr->version != IPA_CONTROLS_FORMAT_VERSION) {
 		LOG(Serializer, Error)
 			<< "Unsupported controls format version "
@@ -485,4 +497,18 @@ ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer
 	return ctrls;
 }
 
+/**
+ * \brief Check if a ControlInfoMap is cached
+ * \param[in] infoMap The ControlInfoMap to check
+ *
+ * The ControlSerializer caches all ControlInfoMaps that it has (de)serialized.
+ * This function checks if \a infoMap is in the cache.
+ *
+ * \return True if \a infoMap is in the cache or false otherwise
+ */
+bool ControlSerializer::isCached(const ControlInfoMap &infoMap)
+{
+	return infoMapHandles_.count(&infoMap);
+}
+
 } /* namespace libcamera */
-- 
2.27.0



More information about the libcamera-devel mailing list