summaryrefslogtreecommitdiff
path: root/src/android/camera_metadata.h
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2021-04-30 17:10:05 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2021-05-14 17:55:58 +0900
commit1ff6887d6b2311e582978342b398d6bf557c1acd (patch)
tree070315b339fb7cb2095b3a8308060d22af8e2391 /src/android/camera_metadata.h
parent0445a2dc02e8d686566553c50e89a7e873a964aa (diff)
android: camera_metadata: Auto-resize CameraMetadata
Previously we had to manually declare the size of CameraMetadata on allocation, and its count could not be changed after construction. Change CameraMetadata's behavior so that the user can simply add or update entries, and the CameraMetadata will auto-resize (double the size) as necessary. Also remove everything involved with calculating the initial size for any CameraMetadata instances. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/android/camera_metadata.h')
-rw-r--r--src/android/camera_metadata.h52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h
index d653e2f0..07afd4b2 100644
--- a/src/android/camera_metadata.h
+++ b/src/android/camera_metadata.h
@@ -8,6 +8,7 @@
#define __ANDROID_CAMERA_METADATA_H__
#include <stdint.h>
+#include <vector>
#include <system/camera_metadata.h>
@@ -23,9 +24,56 @@ public:
CameraMetadata &operator=(const CameraMetadata &other);
bool isValid() const { return valid_; }
+ bool resize(size_t count, size_t size);
bool getEntry(uint32_t tag, camera_metadata_ro_entry_t *entry) const;
- bool addEntry(uint32_t tag, const void *data, size_t data_count);
- bool updateEntry(uint32_t tag, const void *data, size_t data_count);
+
+ template<typename T,
+ std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
+ bool addEntry(uint32_t tag, const T &data)
+ {
+ return addEntry(tag, &data, 1, sizeof(T));
+ }
+
+ template<typename T, size_t size>
+ bool addEntry(uint32_t tag, const T (&data)[size])
+ {
+ return addEntry(tag, data, size, sizeof(T));
+ }
+
+ template<typename S,
+ typename T = typename S::value_type>
+ bool addEntry(uint32_t tag, S &data)
+ {
+ return addEntry(tag, data.data(), data.size(), sizeof(T));
+ }
+
+ template<typename T>
+ bool addEntry(uint32_t tag, const T *data, size_t count)
+ {
+ return addEntry(tag, data, count, sizeof(T));
+ }
+
+ template<typename T>
+ bool updateEntry(uint32_t tag, const T &data)
+ {
+ return updateEntry(tag, &data, 1);
+ }
+
+ template<typename T, size_t size>
+ bool updateEntry(uint32_t tag, const T (&data)[size])
+ {
+ return updateEntry(tag, data, size, sizeof(T));
+ }
+
+ template<typename S,
+ typename T = typename S::value_type>
+ bool updateEntry(uint32_t tag, S &data)
+ {
+ return updateEntry(tag, data.data(), data.size());
+ }
+
+ bool addEntry(uint32_t tag, const void *data, size_t count, size_t sizeofT);
+ bool updateEntry(uint32_t tag, const void *data, size_t count);
camera_metadata_t *get();
const camera_metadata_t *get() const;