[libcamera-devel] [PATCH 1/2] android: camera_metadata: Track storage usage
Kieran Bingham
kieran.bingham at ideasonboard.com
Tue Aug 4 13:31:06 CEST 2020
Track the quantity and size of metadata tags as they are added, to
facilitate reporting of the consumed space.
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
src/android/camera_metadata.cpp | 17 ++++++++++++++++-
src/android/camera_metadata.h | 12 ++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/android/camera_metadata.cpp b/src/android/camera_metadata.cpp
index 47b2e4ef117a..4acb802026c7 100644
--- a/src/android/camera_metadata.cpp
+++ b/src/android/camera_metadata.cpp
@@ -14,6 +14,8 @@ using namespace libcamera;
LOG_DEFINE_CATEGORY(CameraMetadata);
CameraMetadata::CameraMetadata(size_t entryCapacity, size_t dataCapacity)
+ : entryCapacity_(entryCapacity), dataCapacity_(dataCapacity),
+ entries_(0), size_(0)
{
metadata_ = allocate_camera_metadata(entryCapacity, dataCapacity);
valid_ = metadata_ != nullptr;
@@ -30,8 +32,11 @@ bool CameraMetadata::addEntry(uint32_t tag, const void *data, size_t count)
if (!valid_)
return false;
- if (!add_camera_metadata_entry(metadata_, tag, data, count))
+ if (!add_camera_metadata_entry(metadata_, tag, data, count)) {
+ entries_++;
+ size_ += count;
return true;
+ }
const char *name = get_camera_metadata_tag_name(tag);
if (name)
@@ -50,3 +55,13 @@ camera_metadata_t *CameraMetadata::get()
{
return valid_ ? metadata_ : nullptr;
}
+
+std::string CameraMetadata::usage() const
+{
+ std::ostringstream os;
+
+ os << "Entries: " << entries_ << "/" << entryCapacity_
+ << " Size: " << size_ << "/" << dataCapacity_;
+
+ return os.str();
+}
diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h
index 75a9d7066f31..8612eb57974d 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 <string>
#include <system/camera_metadata.h>
@@ -22,9 +23,20 @@ public:
camera_metadata_t *get();
+ size_t entries() const { return entries_; }
+ size_t size() const { return size_; };
+
+ std::string usage() const;
+
private:
camera_metadata_t *metadata_;
bool valid_;
+
+ size_t entryCapacity_;
+ size_t dataCapacity_;
+
+ size_t entries_;
+ size_t size_;
};
#endif /* __ANDROID_CAMERA_METADATA_H__ */
--
2.25.1
More information about the libcamera-devel
mailing list