Add V4L2 Format Metadata Factory.
This factory queries the device for the properties detailing
what formats it supports. Since this may fail, Metadata/V4L2Metadata
was moved from the weird inheritance/constructor stuff it was doing
to Metadata having a better constructor and V4L2Metadata being a
factory.
BUG: 30140438
TEST: unit tests pass
Change-Id: Id4bcb27fbd8b517e3a9a8e9fb8a984af139254b3
diff --git a/modules/camera/3_4/metadata/metadata.cpp b/modules/camera/3_4/metadata/metadata.cpp
index e18a454..976a77d 100644
--- a/modules/camera/3_4/metadata/metadata.cpp
+++ b/modules/camera/3_4/metadata/metadata.cpp
@@ -23,7 +23,8 @@
namespace v4l2_camera_hal {
-Metadata::Metadata() {
+Metadata::Metadata(PartialMetadataSet components)
+ : components_(std::move(components)) {
HAL_LOG_ENTER();
}
@@ -31,13 +32,6 @@
HAL_LOG_ENTER();
}
-void Metadata::AddComponent(
- std::unique_ptr<PartialMetadataInterface> component) {
- HAL_LOG_ENTER();
-
- components_.push_back(std::move(component));
-}
-
int Metadata::FillStaticMetadata(android::CameraMetadata* metadata) {
HAL_LOG_ENTER();
diff --git a/modules/camera/3_4/metadata/metadata.h b/modules/camera/3_4/metadata/metadata.h
index 36e238b..0683df2 100644
--- a/modules/camera/3_4/metadata/metadata.h
+++ b/modules/camera/3_4/metadata/metadata.h
@@ -17,16 +17,18 @@
#ifndef V4L2_CAMERA_HAL_METADATA_H_
#define V4L2_CAMERA_HAL_METADATA_H_
+#include <set>
+
#include <camera/CameraMetadata.h>
#include <hardware/camera3.h>
#include "../common.h"
-#include "partial_metadata_interface.h"
+#include "metadata_common.h"
namespace v4l2_camera_hal {
class Metadata {
public:
- Metadata();
+ Metadata(PartialMetadataSet components);
virtual ~Metadata();
int FillStaticMetadata(android::CameraMetadata* metadata);
@@ -34,16 +36,10 @@
int SetRequestSettings(const android::CameraMetadata& metadata);
int FillResultMetadata(android::CameraMetadata* metadata);
- protected:
- // Helper for the child constructors to fill in metadata components.
- void AddComponent(std::unique_ptr<PartialMetadataInterface> component);
-
private:
// The overall metadata is broken down into several distinct pieces.
// Note: it is undefined behavior if multiple components share tags.
- std::vector<std::unique_ptr<PartialMetadataInterface>> components_;
-
- friend class MetadataTest;
+ PartialMetadataSet components_;
DISALLOW_COPY_AND_ASSIGN(Metadata);
};
diff --git a/modules/camera/3_4/metadata/metadata_common.h b/modules/camera/3_4/metadata/metadata_common.h
index efea152..15f8084 100644
--- a/modules/camera/3_4/metadata/metadata_common.h
+++ b/modules/camera/3_4/metadata/metadata_common.h
@@ -18,14 +18,19 @@
#define V4L2_CAMERA_HAL_METADATA_METADATA_COMMON_H_
#include <array>
+#include <memory>
+#include <set>
#include <vector>
#include <camera/CameraMetadata.h>
#include "array_vector.h"
+#include "partial_metadata_interface.h"
namespace v4l2_camera_hal {
+typedef std::set<std::unique_ptr<PartialMetadataInterface>> PartialMetadataSet;
+
// Templated helper functions effectively extending android::CameraMetadata.
// Will cause a compile-time errors if CameraMetadata doesn't support
// using the templated type. Templates are provided to extend this support
diff --git a/modules/camera/3_4/metadata/metadata_test.cpp b/modules/camera/3_4/metadata/metadata_test.cpp
index 3ea94ba..e6fb70f 100644
--- a/modules/camera/3_4/metadata/metadata_test.cpp
+++ b/modules/camera/3_4/metadata/metadata_test.cpp
@@ -24,7 +24,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include "metadata/partial_metadata_interface_mock.h"
+#include "metadata_common.h"
+#include "partial_metadata_interface_mock.h"
using testing::AtMost;
using testing::Return;
@@ -36,7 +37,8 @@
class MetadataTest : public Test {
protected:
virtual void SetUp() {
- dut_.reset(new Metadata());
+ // Clear the DUT. AddComponents must be called before using it.
+ dut_.reset();
component1_.reset(new PartialMetadataInterfaceMock());
component2_.reset(new PartialMetadataInterfaceMock());
@@ -51,8 +53,10 @@
virtual void AddComponents() {
// Don't mind moving; Gmock/Gtest fails on leaked mocks unless disabled by
// runtime flags.
- dut_->AddComponent(std::move(component1_));
- dut_->AddComponent(std::move(component2_));
+ PartialMetadataSet components;
+ components.insert(std::move(component1_));
+ components.insert(std::move(component2_));
+ dut_.reset(new Metadata(std::move(components)));
}
virtual void CompareTags(const std::set<int32_t>& expected,
diff --git a/modules/camera/3_4/metadata/property.h b/modules/camera/3_4/metadata/property.h
index 1ddd20f..3ded4c4 100644
--- a/modules/camera/3_4/metadata/property.h
+++ b/modules/camera/3_4/metadata/property.h
@@ -27,7 +27,7 @@
template <typename T>
class Property : public PartialMetadataInterface {
public:
- Property(int32_t tag, T value) : tag_(tag), value_(value){};
+ Property(int32_t tag, T value) : tag_(tag), value_(std::move(value)){};
virtual std::vector<int32_t> StaticTags() const override { return {tag_}; };