1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CAMERA_COMMON_1_0_VENDORTAGDESCRIPTOR_H 18 #define CAMERA_COMMON_1_0_VENDORTAGDESCRIPTOR_H 19 20 #include <utils/Vector.h> 21 #include <utils/KeyedVector.h> 22 #include <utils/String8.h> 23 #include <utils/RefBase.h> 24 #include <system/camera_vendor_tags.h> 25 26 #include <stdint.h> 27 #include <unordered_map> 28 29 namespace android { 30 namespace hardware { 31 namespace camera2 { 32 namespace params { 33 34 /** 35 * VendorTagDescriptor objects are containers for the vendor tag 36 * definitions provided, and are typically used to pass the vendor tag 37 * information enumerated by the HAL to clients of the camera service. 38 */ 39 class VendorTagDescriptor { 40 public: 41 virtual ~VendorTagDescriptor(); 42 43 VendorTagDescriptor(); 44 VendorTagDescriptor(const VendorTagDescriptor& src); 45 VendorTagDescriptor& operator=(const VendorTagDescriptor& rhs); 46 47 void copyFrom(const VendorTagDescriptor& src); 48 49 /** 50 * The following 'get*' methods implement the corresponding 51 * functions defined in 52 * system/media/camera/include/system/camera_vendor_tags.h 53 */ 54 55 // Returns the number of vendor tags defined. 56 int getTagCount() const; 57 58 // Returns an array containing the id's of vendor tags defined. 59 void getTagArray(uint32_t* tagArray) const; 60 61 // Returns the section name string for a given vendor tag id. 62 const char* getSectionName(uint32_t tag) const; 63 64 // Returns the index in section vectors returned in getAllSectionNames() 65 // for a given vendor tag id. -1 if input tag does not exist. 66 ssize_t getSectionIndex(uint32_t tag) const; 67 68 // Returns the tag name string for a given vendor tag id. 69 const char* getTagName(uint32_t tag) const; 70 71 // Returns the tag type for a given vendor tag id. 72 int getTagType(uint32_t tag) const; 73 74 /** 75 * Convenience method to get a vector containing all vendor tag 76 * sections, or an empty vector if none are defined. 77 * The pointer is valid for the lifetime of the VendorTagDescriptor, 78 * or until copyFrom is invoked. 79 */ 80 const SortedVector<String8>* getAllSectionNames() const; 81 82 /** 83 * Lookup the tag id for a given tag name and section. 84 * 85 * Returns OK on success, or a negative error code. 86 */ 87 status_t lookupTag(const String8& name, const String8& section, /*out*/uint32_t* tag) const; 88 89 /** 90 * Dump the currently configured vendor tags to a file descriptor. 91 */ 92 void dump(int fd, int verbosity, int indentation) const; 93 94 protected: 95 KeyedVector<String8, KeyedVector<String8, uint32_t>*> mReverseMapping; 96 KeyedVector<uint32_t, String8> mTagToNameMap; 97 KeyedVector<uint32_t, uint32_t> mTagToSectionMap; // Value is offset in mSections 98 99 std::unordered_map<uint32_t, int32_t> mTagToTypeMap; 100 SortedVector<String8> mSections; 101 // must be int32_t to be compatible with Parcel::writeInt32 102 int32_t mTagCount; 103 104 vendor_tag_ops mVendorOps; 105 }; 106 } /* namespace params */ 107 } /* namespace camera2 */ 108 109 namespace camera { 110 namespace common { 111 namespace V1_0 { 112 namespace helper { 113 114 /** 115 * This version of VendorTagDescriptor must be stored in Android sp<>, and adds support for using it 116 * as a global tag descriptor. 117 * 118 * It's a child class of the basic hardware::camera2::params::VendorTagDescriptor since basic 119 * Parcelable objects cannot require being kept in an sp<> and still work with auto-generated AIDL 120 * interface implementations. 121 */ 122 class VendorTagDescriptor : 123 public ::android::hardware::camera2::params::VendorTagDescriptor, 124 public LightRefBase<VendorTagDescriptor> { 125 126 public: 127 128 /** 129 * Create a VendorTagDescriptor object from the given vendor_tag_ops_t 130 * struct. 131 * 132 * Returns OK on success, or a negative error code. 133 */ 134 static status_t createDescriptorFromOps(const vendor_tag_ops_t* vOps, 135 /*out*/ 136 sp<VendorTagDescriptor>& descriptor); 137 138 /** 139 * Sets the global vendor tag descriptor to use for this process. 140 * Camera metadata operations that access vendor tags will use the 141 * vendor tag definitions set this way. 142 * 143 * Returns OK on success, or a negative error code. 144 */ 145 static status_t setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc); 146 147 /** 148 * Returns the global vendor tag descriptor used by this process. 149 * This will contain NULL if no vendor tags are defined. 150 */ 151 static sp<VendorTagDescriptor> getGlobalVendorTagDescriptor(); 152 153 /** 154 * Clears the global vendor tag descriptor used by this process. 155 */ 156 static void clearGlobalVendorTagDescriptor(); 157 158 }; 159 160 } /* namespace helper */ 161 } /* namespace V1_0 */ 162 } /* namespace common */ 163 } /* namespace camera */ 164 165 namespace camera2 { 166 namespace params { 167 168 class VendorTagDescriptorCache { 169 public: 170 typedef android::hardware::camera::common::V1_0::helper::VendorTagDescriptor 171 VendorTagDescriptor; VendorTagDescriptorCache()172 VendorTagDescriptorCache(){}; 173 int32_t addVendorDescriptor(metadata_vendor_id_t id, sp<VendorTagDescriptor> desc); 174 175 int32_t getVendorTagDescriptor(metadata_vendor_id_t id, sp<VendorTagDescriptor>* desc /*out*/); 176 177 // Returns the number of vendor tags defined. 178 int getTagCount(metadata_vendor_id_t id) const; 179 180 // Returns an array containing the id's of vendor tags defined. 181 void getTagArray(uint32_t* tagArray, metadata_vendor_id_t id) const; 182 183 // Returns the section name string for a given vendor tag id. 184 const char* getSectionName(uint32_t tag, metadata_vendor_id_t id) const; 185 186 // Returns the tag name string for a given vendor tag id. 187 const char* getTagName(uint32_t tag, metadata_vendor_id_t id) const; 188 189 // Returns the tag type for a given vendor tag id. 190 int getTagType(uint32_t tag, metadata_vendor_id_t id) const; 191 192 /** 193 * Dump the currently configured vendor tags to a file descriptor. 194 */ 195 void dump(int fd, int verbosity, int indentation) const; 196 197 protected: 198 std::unordered_map<metadata_vendor_id_t, sp<VendorTagDescriptor>> mVendorMap; 199 struct vendor_tag_cache_ops mVendorCacheOps; 200 }; 201 202 } /* namespace params */ 203 } /* namespace camera2 */ 204 205 namespace camera { 206 namespace common { 207 namespace V1_0 { 208 namespace helper { 209 210 class VendorTagDescriptorCache 211 : public ::android::hardware::camera2::params::VendorTagDescriptorCache, 212 public LightRefBase<VendorTagDescriptorCache> { 213 public: 214 /** 215 * Sets the global vendor tag descriptor cache to use for this process. 216 * Camera metadata operations that access vendor tags will use the 217 * vendor tag definitions set this way. 218 * 219 * Returns OK on success, or a negative error code. 220 */ 221 static status_t setAsGlobalVendorTagCache(const sp<VendorTagDescriptorCache>& cache); 222 223 /** 224 * Returns the global vendor tag cache used by this process. 225 * This will contain NULL if no vendor tags are defined. 226 */ 227 static sp<VendorTagDescriptorCache> getGlobalVendorTagCache(); 228 229 /** 230 * Clears the global vendor tag cache used by this process. 231 */ 232 static void clearGlobalVendorTagCache(); 233 }; 234 235 } // namespace helper 236 } // namespace V1_0 237 } // namespace common 238 } // namespace camera 239 } // namespace hardware 240 } // namespace android 241 242 #endif /* CAMERA_COMMON_1_0_VENDORTAGDESCRIPTOR_H */ 243