[DO NOT MERGE] camera: add vendor tag interface
This interface allows HWL implementation to query vendor tags info,
which is especially needed when vendor tags are defined outside the HWL.
Test: GCA
Bug: 150496578
Change-Id: Ibc11a683bd590c256b836b215184bca24aa11671
diff --git a/common/hal/utils/vendor_tag_interface.h b/common/hal/utils/vendor_tag_interface.h
new file mode 100644
index 0000000..3eacee1
--- /dev/null
+++ b/common/hal/utils/vendor_tag_interface.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HARDWARE_GOOGLE_CAMERA_HAL_UTILS_HAL_VENDOR_TAG_INTERFACE_H
+#define HARDWARE_GOOGLE_CAMERA_HAL_UTILS_HAL_VENDOR_TAG_INTERFACE_H
+
+#include "hal_types.h"
+
+#include <utils/Errors.h>
+#include <vector>
+
+namespace android {
+namespace google_camera_hal {
+
+struct VendorTagInfo {
+ uint32_t tag_id = 0;
+ int tag_type = TYPE_BYTE;
+ std::string section_name;
+ std::string tag_name;
+};
+
+// This is an interface for accessing vendor tags in HAL
+class VendorTagInterface {
+ public:
+ // Get Tag info for the give tag id
+ virtual status_t GetTagInfo(uint32_t tag_id, VendorTagInfo* tag_info) = 0;
+
+ // Get the tag id for the given section/name
+ virtual status_t GetTag(const std::string section_name,
+ const std::string tag_name, uint32_t* tag_id);
+
+ protected:
+ virtual ~VendorTagInterface(){};
+};
+
+} // namespace google_camera_hal
+} // namespace android
+
+#endif // HARDWARE_GOOGLE_CAMERA_HAL_UTILS_HAL_VENDOR_TAG_INTERFACE_H
diff --git a/common/hal/utils/vendor_tag_utils.cc b/common/hal/utils/vendor_tag_utils.cc
index 937fcdf..84cf4ea 100644
--- a/common/hal/utils/vendor_tag_utils.cc
+++ b/common/hal/utils/vendor_tag_utils.cc
@@ -16,10 +16,12 @@
#include <system/camera_metadata.h>
#include <camera_metadata_hidden.h>
+
#define LOG_TAG "GCH_VendorTagUtils"
#include <log/log.h>
#include <map>
+#include <string>
#include <unordered_set>
#include "vendor_tag_utils.h"
@@ -135,9 +137,13 @@
for (auto& section : tag_sections) {
for (auto& tag : section.tags) {
vendor_tag_map_[tag.tag_id] =
- VendorTagInfo{.section_name = section.section_name,
- .tag_name = tag.tag_name,
- .tag_type = static_cast<int>(tag.tag_type)};
+ VendorTagInfo{.tag_id = tag.tag_id,
+ .tag_type = static_cast<int>(tag.tag_type),
+ .section_name = section.section_name,
+ .tag_name = tag.tag_name};
+
+ vendor_tag_inverse_map_[TagString(section.section_name, tag.tag_name)] =
+ tag.tag_id;
}
}
@@ -220,5 +226,42 @@
return it->second.tag_type;
}
+
+status_t VendorTagManager::GetTagInfo(uint32_t tag_id, VendorTagInfo* tag_info) {
+ if (tag_info == nullptr) {
+ ALOGE("%s tag_info is nullptr", __FUNCTION__);
+ return BAD_VALUE;
+ }
+ std::lock_guard<std::mutex> lock(api_mutex_);
+ auto itr = vendor_tag_map_.find(tag_id);
+ if (itr == vendor_tag_map_.end()) {
+ ALOGE("%s Given tag_id not found", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ *tag_info = itr->second;
+ return OK;
+}
+
+status_t VendorTagManager::GetTag(const std::string section_name,
+ const std::string tag_name, uint32_t* tag_id) {
+ if (tag_id == nullptr) {
+ ALOGE("%s tag_id is nullptr", __FUNCTION__);
+ return BAD_VALUE;
+ }
+ std::lock_guard<std::mutex> lock(api_mutex_);
+
+ const TagString section_tag{section_name, tag_name};
+
+ auto itr = vendor_tag_inverse_map_.find(section_tag);
+ if (itr == vendor_tag_inverse_map_.end()) {
+ ALOGE("%s Given section/tag names not found", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ *tag_id = itr->second;
+ return OK;
+}
+
} // namespace google_camera_hal
} // namespace android
diff --git a/common/hal/utils/vendor_tag_utils.h b/common/hal/utils/vendor_tag_utils.h
index 88900c7..abcb3bd 100644
--- a/common/hal/utils/vendor_tag_utils.h
+++ b/common/hal/utils/vendor_tag_utils.h
@@ -23,6 +23,7 @@
#include <vector>
#include "hal_types.h"
+#include "vendor_tag_interface.h"
namespace android {
namespace google_camera_hal {
@@ -44,7 +45,7 @@
// could be only one set of callbacks set per camera provider. The HWL or HAL
// layers should use this wrapper instead of directly invoking
// set_camera_metadata_vendor_ops()
-class VendorTagManager {
+class VendorTagManager : public VendorTagInterface {
public:
static VendorTagManager& GetInstance();
@@ -74,21 +75,33 @@
VendorTagManager(VendorTagManager const&) = delete;
VendorTagManager& operator=(VendorTagManager const&) = delete;
- private:
- // Vendor tag descriptor containing all the information expected by camera
- // metadata framework operations in vendor_tag_ops_t.
- struct VendorTagInfo {
- std::string section_name;
- std::string tag_name;
- int tag_type = TYPE_BYTE;
- };
+ // Get Tag info for the give tag id
+ status_t GetTagInfo(uint32_t tag_id, VendorTagInfo* tag_info) override;
+ // Get the tag id for the given section/name
+ status_t GetTag(const std::string section_name, const std::string tag_name,
+ uint32_t* tag_id) override;
+
+ private:
VendorTagManager() = default;
// Map from vendor tag ID to VendorTagInfo. Used for camera framework
// vendor tag callbacks, protected by api_mutex_.
std::unordered_map<uint32_t, VendorTagInfo> vendor_tag_map_;
+ using TagString = std::pair<std::string, std::string>;
+
+ struct TagStringHash {
+ size_t operator()(const TagString& pair) const {
+ std::hash<TagString::first_type> h1;
+ std::hash<TagString::second_type> h2;
+ return h1(pair.first) ^ h2(pair.second);
+ }
+ };
+
+ std::unordered_map<const TagString, uint32_t, TagStringHash>
+ vendor_tag_inverse_map_;
+
// Protects the public entry points into this class.
mutable std::mutex api_mutex_;