Plug in metadata refactor.
Replaces metadata usage in Camera/V4L2Camera with the
new Metadata class.
Switches Camera from camera_metadata_t to android::CameraMetadata
where appropriate for ease of use/clarity of ownership.
Also cleaned up some "error" logs that were potentially expected,
leaving it to the caller to log if something goes wrong, since
they were numerous and cluttering the log feed.
BUG: https://b/30140438, https://b/29335262
TEST: unit tests pass, test picture program still works,
tested setting a V4L2 control to a non-default value.
Change-Id: I24e50c9b71736dfc576debf8d09dbe36b9bbf23a
diff --git a/modules/camera/3_4/metadata/enum_converter.cpp b/modules/camera/3_4/metadata/enum_converter.cpp
index 3165804..f4c9819 100644
--- a/modules/camera/3_4/metadata/enum_converter.cpp
+++ b/modules/camera/3_4/metadata/enum_converter.cpp
@@ -49,7 +49,7 @@
}
if (count == 0) {
- HAL_LOGE("Couldn't find V4L2 conversion of metadata value %d.", value);
+ HAL_LOGV("Couldn't find V4L2 conversion of metadata value %d.", value);
return -EINVAL;
} else if (count > 1) {
HAL_LOGV(
@@ -64,7 +64,7 @@
auto element_range = v4l2_to_metadata_.equal_range(value);
if (element_range.first == element_range.second) {
- HAL_LOGE("Couldn't find metadata conversion of V4L2 value %d.", value);
+ HAL_LOGV("Couldn't find metadata conversion of V4L2 value %d.", value);
return -EINVAL;
}
diff --git a/modules/camera/3_4/metadata/metadata.cpp b/modules/camera/3_4/metadata/metadata.cpp
index ddd73c1..efc9959 100644
--- a/modules/camera/3_4/metadata/metadata.cpp
+++ b/modules/camera/3_4/metadata/metadata.cpp
@@ -35,6 +35,10 @@
int Metadata::FillStaticMetadata(android::CameraMetadata* metadata) {
HAL_LOG_ENTER();
+ if (!metadata) {
+ HAL_LOGE("Can't fill null metadata.");
+ return -EINVAL;
+ }
std::vector<int32_t> static_tags;
std::vector<int32_t> control_tags;
@@ -123,6 +127,10 @@
int Metadata::GetRequestTemplate(int template_type,
android::CameraMetadata* template_metadata) {
HAL_LOG_ENTER();
+ if (!template_metadata) {
+ HAL_LOGE("Can't fill null template.");
+ return -EINVAL;
+ }
// Templates are numbered 1 through COUNT-1 for some reason.
if (template_type < 1 || template_type >= CAMERA3_TEMPLATE_COUNT) {
@@ -172,6 +180,12 @@
}
int Metadata::FillResultMetadata(android::CameraMetadata* metadata) {
+ HAL_LOG_ENTER();
+ if (!metadata) {
+ HAL_LOGE("Can't fill null metadata.");
+ return -EINVAL;
+ }
+
for (auto& component : components_) {
// Prevent components from potentially overriding others.
android::CameraMetadata additional_metadata;
diff --git a/modules/camera/3_4/metadata/metadata_test.cpp b/modules/camera/3_4/metadata/metadata_test.cpp
index e97e60b..508884c 100644
--- a/modules/camera/3_4/metadata/metadata_test.cpp
+++ b/modules/camera/3_4/metadata/metadata_test.cpp
@@ -162,6 +162,11 @@
EXPECT_EQ(dut_->FillStaticMetadata(metadata_.get()), err);
}
+TEST_F(MetadataTest, FillStaticNull) {
+ AddComponents();
+ EXPECT_EQ(dut_->FillStaticMetadata(nullptr), -EINVAL);
+}
+
TEST_F(MetadataTest, IsValidSuccess) {
// Should check if all the component request values are valid.
EXPECT_CALL(*component1_, SupportsRequestValues(_)).WillOnce(Return(true));
@@ -231,6 +236,11 @@
EXPECT_EQ(dut_->GetRequestTemplate(template_type, metadata_.get()), err);
}
+TEST_F(MetadataTest, GetTemplateNull) {
+ AddComponents();
+ EXPECT_EQ(dut_->GetRequestTemplate(1, nullptr), -EINVAL);
+}
+
TEST_F(MetadataTest, GetTemplateInvalid) {
int template_type = 99; // Invalid template type.
@@ -304,4 +314,9 @@
EXPECT_EQ(dut_->FillResultMetadata(metadata_.get()), err);
}
+TEST_F(MetadataTest, FillResultNull) {
+ AddComponents();
+ EXPECT_EQ(dut_->FillResultMetadata(nullptr), -EINVAL);
+}
+
} // namespace v4l2_camera_hal
diff --git a/modules/camera/3_4/metadata/partial_metadata_factory.h b/modules/camera/3_4/metadata/partial_metadata_factory.h
index a554ee7..27ea6e8 100644
--- a/modules/camera/3_4/metadata/partial_metadata_factory.h
+++ b/modules/camera/3_4/metadata/partial_metadata_factory.h
@@ -223,6 +223,9 @@
HAL_LOGE("Error converting value %d for control %d.", i, control_id);
return nullptr;
}
+ if (control_id == V4L2_CID_COLORFX) {
+ HAL_LOGE("Adding color effect %d (%d)", i, metadata_val);
+ }
options.push_back(metadata_val);
}
// Check to make sure there's at least one option.
@@ -269,8 +272,9 @@
new SliderControlOptions<T>(metadata_min, metadata_max));
break;
default:
- HAL_LOGE("Control %d is of unsupported type %d",
+ HAL_LOGE("Control %d (%s) is of unsupported type %d",
control_id,
+ control_query.name,
control_query.type);
return nullptr;
}