[libcamera-devel] [PATCH 3/7] android: camera_metadata: Add appendEntry helper

Paul Elder paul.elder at ideasonboard.com
Tue Nov 23 11:40:38 CET 2021


Add appendEntry() helper, that automatically detects if updateEntry() or
addEntry() should be used.

For now only implement it for enums and arithmetic values, as they will
mainly be used in populating templates, where the preview template
generator may or may not have (based on capabilities) already added a
key.

Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
 src/android/camera_metadata.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h
index 8555c7c3..cca14d6c 100644
--- a/src/android/camera_metadata.h
+++ b/src/android/camera_metadata.h
@@ -33,6 +33,17 @@ public:
 
 	bool hasEntry(uint32_t tag) const;
 
+	template<typename T,
+		 std::enable_if_t<std::is_arithmetic_v<T> ||
+				  std::is_enum_v<T>> * = nullptr>
+	bool appendEntry(uint32_t tag, const T &data)
+	{
+		if (hasEntry(tag))
+			return updateEntry(tag, &data, 1, sizeof(T));
+		else
+			return addEntry(tag, &data, 1, sizeof(T));
+	}
+
 	template<typename T,
 		 std::enable_if_t<std::is_arithmetic_v<T> ||
 				  std::is_enum_v<T>> * = nullptr>
-- 
2.27.0



More information about the libcamera-devel mailing list