VendorTagDescriptor.cpp revision faef8f92c95a1e0868c1ec8fd220b9d957831022
1faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh/* 2faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * Copyright (C) 2016 The Android Open Source Project 3faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * 4faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * Licensed under the Apache License, Version 2.0 (the "License"); 5faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * you may not use this file except in compliance with the License. 6faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * You may obtain a copy of the License at 7faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * 8faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * http://www.apache.org/licenses/LICENSE-2.0 9faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * 10faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * Unless required by applicable law or agreed to in writing, software 11faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * distributed under the License is distributed on an "AS IS" BASIS, 12faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * See the License for the specific language governing permissions and 14faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh * limitations under the License. 15faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh */ 16faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 17faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#define LOG_TAG "CamComm1.0-VTDesc" 18faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 19faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <utils/Errors.h> 20faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <utils/Log.h> 21faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <utils/Mutex.h> 22faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <utils/Vector.h> 23faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <utils/SortedVector.h> 24faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <system/camera_metadata.h> 25faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <camera_metadata_hidden.h> 26faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 27faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include "VendorTagDescriptor.h" 28faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 29faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <stdio.h> 30faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh#include <string.h> 31faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 32faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace android { 33faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace hardware { 34faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace camera2 { 35faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace params { 36faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 37faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia YehVendorTagDescriptor::~VendorTagDescriptor() { 38faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh size_t len = mReverseMapping.size(); 39faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh for (size_t i = 0; i < len; ++i) { 40faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh delete mReverseMapping[i]; 41faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 42faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 43faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 44faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia YehVendorTagDescriptor::VendorTagDescriptor() : 45faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mTagCount(0), 46faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mVendorOps() { 47faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 48faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 49faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia YehVendorTagDescriptor::VendorTagDescriptor(const VendorTagDescriptor& src) { 50faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh copyFrom(src); 51faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 52faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 53faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia YehVendorTagDescriptor& VendorTagDescriptor::operator=(const VendorTagDescriptor& rhs) { 54faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh copyFrom(rhs); 55faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return *this; 56faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 57faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 58faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehvoid VendorTagDescriptor::copyFrom(const VendorTagDescriptor& src) { 59faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (this == &src) return; 60faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 61faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh size_t len = mReverseMapping.size(); 62faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh for (size_t i = 0; i < len; ++i) { 63faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh delete mReverseMapping[i]; 64faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 65faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mReverseMapping.clear(); 66faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 67faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh len = src.mReverseMapping.size(); 68faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh // Have to copy KeyedVectors inside mReverseMapping 69faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh for (size_t i = 0; i < len; ++i) { 70faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>(); 71faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh *nameMapper = *(src.mReverseMapping.valueAt(i)); 72faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mReverseMapping.add(src.mReverseMapping.keyAt(i), nameMapper); 73faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 74faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh // Everything else is simple 75faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mTagToNameMap = src.mTagToNameMap; 76faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mTagToSectionMap = src.mTagToSectionMap; 77faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mTagToTypeMap = src.mTagToTypeMap; 78faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mSections = src.mSections; 79faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mTagCount = src.mTagCount; 80faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh mVendorOps = src.mVendorOps; 81faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 82faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 83faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehint VendorTagDescriptor::getTagCount() const { 84faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh size_t size = mTagToNameMap.size(); 85faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (size == 0) { 86faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_TAG_COUNT_ERR; 87faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 88faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return size; 89faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 90faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 91faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehvoid VendorTagDescriptor::getTagArray(uint32_t* tagArray) const { 92faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh size_t size = mTagToNameMap.size(); 93faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh for (size_t i = 0; i < size; ++i) { 94faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh tagArray[i] = mTagToNameMap.keyAt(i); 95faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 96faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 97faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 98faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehconst char* VendorTagDescriptor::getSectionName(uint32_t tag) const { 99faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ssize_t index = mTagToSectionMap.indexOfKey(tag); 100faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (index < 0) { 101faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_SECTION_NAME_ERR; 102faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 103faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return mSections[mTagToSectionMap.valueAt(index)].string(); 104faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 105faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 106faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehssize_t VendorTagDescriptor::getSectionIndex(uint32_t tag) const { 107faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return mTagToSectionMap.valueFor(tag); 108faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 109faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 110faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehconst char* VendorTagDescriptor::getTagName(uint32_t tag) const { 111faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ssize_t index = mTagToNameMap.indexOfKey(tag); 112faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (index < 0) { 113faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_TAG_NAME_ERR; 114faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 115faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return mTagToNameMap.valueAt(index).string(); 116faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 117faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 118faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehint VendorTagDescriptor::getTagType(uint32_t tag) const { 119faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ssize_t index = mTagToNameMap.indexOfKey(tag); 120faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (index < 0) { 121faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_TAG_TYPE_ERR; 122faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 123faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return mTagToTypeMap.valueFor(tag); 124faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 125faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 126faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehconst SortedVector<String8>* VendorTagDescriptor::getAllSectionNames() const { 127faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return &mSections; 128faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 129faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 130faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatus_t VendorTagDescriptor::lookupTag(const String8& name, const String8& section, /*out*/uint32_t* tag) const { 131faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ssize_t index = mReverseMapping.indexOfKey(section); 132faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (index < 0) { 133faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Section '%s' does not exist.", __FUNCTION__, section.string()); 134faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 135faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 136faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 137faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ssize_t nameIndex = mReverseMapping[index]->indexOfKey(name); 138faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (nameIndex < 0) { 139faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Tag name '%s' does not exist.", __FUNCTION__, name.string()); 140faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 141faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 142faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 143faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (tag != NULL) { 144faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh *tag = mReverseMapping[index]->valueAt(nameIndex); 145faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 146faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return OK; 147faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 148faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 149faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehvoid VendorTagDescriptor::dump(int fd, int verbosity, int indentation) const { 150faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 151faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh size_t size = mTagToNameMap.size(); 152faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (size == 0) { 153faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh dprintf(fd, "%*sDumping configured vendor tag descriptors: None set\n", 154faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh indentation, ""); 155faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return; 156faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 157faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 158faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh dprintf(fd, "%*sDumping configured vendor tag descriptors: %zu entries\n", 159faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh indentation, "", size); 160faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh for (size_t i = 0; i < size; ++i) { 161faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh uint32_t tag = mTagToNameMap.keyAt(i); 162faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 163faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (verbosity < 1) { 164faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh dprintf(fd, "%*s0x%x\n", indentation + 2, "", tag); 165faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh continue; 166faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 167faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh String8 name = mTagToNameMap.valueAt(i); 168faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh uint32_t sectionId = mTagToSectionMap.valueFor(tag); 169faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh String8 sectionName = mSections[sectionId]; 170faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh int type = mTagToTypeMap.valueFor(tag); 171faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh const char* typeName = (type >= 0 && type < NUM_TYPES) ? 172faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh camera_metadata_type_names[type] : "UNKNOWN"; 173faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh dprintf(fd, "%*s0x%x (%s) with type %d (%s) defined in section %s\n", indentation + 2, 174faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh "", tag, name.string(), type, typeName, sectionName.string()); 175faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 176faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 177faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 178faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 179faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace params 180faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace camera2 181faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 182faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace camera { 183faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace common { 184faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace V1_0 { 185faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehnamespace helper { 186faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 187faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehextern "C" { 188faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 189faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatic int vendor_tag_descriptor_get_tag_count(const vendor_tag_ops_t* v); 190faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatic void vendor_tag_descriptor_get_all_tags(const vendor_tag_ops_t* v, uint32_t* tagArray); 191faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatic const char* vendor_tag_descriptor_get_section_name(const vendor_tag_ops_t* v, uint32_t tag); 192faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatic const char* vendor_tag_descriptor_get_tag_name(const vendor_tag_ops_t* v, uint32_t tag); 193faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatic int vendor_tag_descriptor_get_tag_type(const vendor_tag_ops_t* v, uint32_t tag); 194faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 195faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} /* extern "C" */ 196faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 197faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatic Mutex sLock; 198faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatic sp<VendorTagDescriptor> sGlobalVendorTagDescriptor; 199faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 200faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatus_t VendorTagDescriptor::createDescriptorFromOps(const vendor_tag_ops_t* vOps, 201faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh /*out*/ 202faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh sp<VendorTagDescriptor>& descriptor) { 203faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (vOps == NULL) { 204faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: vendor_tag_ops argument was NULL.", __FUNCTION__); 205faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 206faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 207faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 208faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh int tagCount = vOps->get_tag_count(vOps); 209faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (tagCount < 0 || tagCount > INT32_MAX) { 210faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: tag count %d from vendor ops is invalid.", __FUNCTION__, tagCount); 211faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 212faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 213faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 214faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Vector<uint32_t> tagArray; 215faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount, 216faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh "%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount); 217faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 218faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh vOps->get_all_tags(vOps, /*out*/tagArray.editArray()); 219faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 220faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh sp<VendorTagDescriptor> desc = new VendorTagDescriptor(); 221faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh desc->mTagCount = tagCount; 222faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 223faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh SortedVector<String8> sections; 224faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh KeyedVector<uint32_t, String8> tagToSectionMap; 225faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 226faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) { 227faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh uint32_t tag = tagArray[i]; 228faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) { 229faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag); 230faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 231faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 232faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh const char *tagName = vOps->get_tag_name(vOps, tag); 233faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (tagName == NULL) { 234faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag); 235faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 236faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 237faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh desc->mTagToNameMap.add(tag, String8(tagName)); 238faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh const char *sectionName = vOps->get_section_name(vOps, tag); 239faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (sectionName == NULL) { 240faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: no section name defined for vendor tag %d.", __FUNCTION__, tag); 241faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 242faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 243faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 244faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh String8 sectionString(sectionName); 245faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 246faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh sections.add(sectionString); 247faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh tagToSectionMap.add(tag, sectionString); 248faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 249faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh int tagType = vOps->get_tag_type(vOps, tag); 250faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (tagType < 0 || tagType >= NUM_TYPES) { 251faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType); 252faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return BAD_VALUE; 253faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 254faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh desc->mTagToTypeMap.add(tag, tagType); 255faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 256faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 257faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh desc->mSections = sections; 258faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 259faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) { 260faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh uint32_t tag = tagArray[i]; 261faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh String8 sectionString = tagToSectionMap.valueFor(tag); 262faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 263faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh // Set up tag to section index map 264faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ssize_t index = sections.indexOf(sectionString); 265faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index); 266faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index)); 267faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 268faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh // Set up reverse mapping 269faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ssize_t reverseIndex = -1; 270faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) { 271faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>(); 272faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper); 273faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 274faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag); 275faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 276faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 277faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh descriptor = desc; 278faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return OK; 279faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 280faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 281faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehstatus_t VendorTagDescriptor::setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc) { 282faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh status_t res = OK; 283faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 284faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh sGlobalVendorTagDescriptor = desc; 285faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 286faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh vendor_tag_ops_t* opsPtr = NULL; 287faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (desc != NULL) { 288faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh opsPtr = &(desc->mVendorOps); 289faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh opsPtr->get_tag_count = vendor_tag_descriptor_get_tag_count; 290faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh opsPtr->get_all_tags = vendor_tag_descriptor_get_all_tags; 291faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh opsPtr->get_section_name = vendor_tag_descriptor_get_section_name; 292faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh opsPtr->get_tag_name = vendor_tag_descriptor_get_tag_name; 293faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh opsPtr->get_tag_type = vendor_tag_descriptor_get_tag_type; 294faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 295faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if((res = set_camera_metadata_vendor_ops(opsPtr)) != OK) { 296faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Could not set vendor tag descriptor, received error %s (%d)." 297faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh , __FUNCTION__, strerror(-res), res); 298faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 299faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return res; 300faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 301faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 302faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehvoid VendorTagDescriptor::clearGlobalVendorTagDescriptor() { 303faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 304faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh set_camera_metadata_vendor_ops(NULL); 305faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh sGlobalVendorTagDescriptor.clear(); 306faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 307faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 308faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehsp<VendorTagDescriptor> VendorTagDescriptor::getGlobalVendorTagDescriptor() { 309faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 310faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return sGlobalVendorTagDescriptor; 311faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 312faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 313faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehextern "C" { 314faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 315faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehint vendor_tag_descriptor_get_tag_count(const vendor_tag_ops_t* /*v*/) { 316faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 317faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (sGlobalVendorTagDescriptor == NULL) { 318faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Vendor tag descriptor not initialized.", __FUNCTION__); 319faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_TAG_COUNT_ERR; 320faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 321faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return sGlobalVendorTagDescriptor->getTagCount(); 322faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 323faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 324faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehvoid vendor_tag_descriptor_get_all_tags(const vendor_tag_ops_t* /*v*/, uint32_t* tagArray) { 325faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 326faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (sGlobalVendorTagDescriptor == NULL) { 327faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Vendor tag descriptor not initialized.", __FUNCTION__); 328faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return; 329faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 330faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh sGlobalVendorTagDescriptor->getTagArray(tagArray); 331faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 332faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 333faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehconst char* vendor_tag_descriptor_get_section_name(const vendor_tag_ops_t* /*v*/, uint32_t tag) { 334faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 335faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (sGlobalVendorTagDescriptor == NULL) { 336faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Vendor tag descriptor not initialized.", __FUNCTION__); 337faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_SECTION_NAME_ERR; 338faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 339faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return sGlobalVendorTagDescriptor->getSectionName(tag); 340faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 341faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 342faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehconst char* vendor_tag_descriptor_get_tag_name(const vendor_tag_ops_t* /*v*/, uint32_t tag) { 343faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 344faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (sGlobalVendorTagDescriptor == NULL) { 345faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Vendor tag descriptor not initialized.", __FUNCTION__); 346faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_TAG_NAME_ERR; 347faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 348faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return sGlobalVendorTagDescriptor->getTagName(tag); 349faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 350faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 351faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yehint vendor_tag_descriptor_get_tag_type(const vendor_tag_ops_t* /*v*/, uint32_t tag) { 352faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh Mutex::Autolock al(sLock); 353faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh if (sGlobalVendorTagDescriptor == NULL) { 354faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh ALOGE("%s: Vendor tag descriptor not initialized.", __FUNCTION__); 355faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return VENDOR_TAG_TYPE_ERR; 356faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh } 357faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh return sGlobalVendorTagDescriptor->getTagType(tag); 358faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} 359faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 360faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} /* extern "C" */ 361faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh 362faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace helper 363faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace V1_0 364faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace common 365faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace camera 366faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace hardware 367faef8f92c95a1e0868c1ec8fd220b9d957831022Yin-Chia Yeh} // namespace android 368