From 892c0f4c19f2d423560a1ab4d7498130816852c3 Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Wed, 23 Dec 2020 12:34:42 +0900 Subject: libcamera: control_serializer: Save serialized ControlInfoMap in a cache 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 Reviewed-by: Laurent Pinchart --- src/libcamera/control_serializer.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/libcamera/control_serializer.cpp') 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(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(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 */ -- cgit v1.2.1