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 28 namespace android { 29 namespace hardware { 30 namespace camera2 { 31 namespace params { 32 33 /** 34 * VendorTagDescriptor objects are containers for the vendor tag 35 * definitions provided, and are typically used to pass the vendor tag 36 * information enumerated by the HAL to clients of the camera service. 37 */ 38 class VendorTagDescriptor { 39 public: 40 virtual ~VendorTagDescriptor(); 41 42 VendorTagDescriptor(); 43 VendorTagDescriptor(const VendorTagDescriptor& src); 44 VendorTagDescriptor& operator=(const VendorTagDescriptor& rhs); 45 46 void copyFrom(const VendorTagDescriptor& src); 47 48 /** 49 * The following 'get*' methods implement the corresponding 50 * functions defined in 51 * system/media/camera/include/system/camera_vendor_tags.h 52 */ 53 54 // Returns the number of vendor tags defined. 55 int getTagCount() const; 56 57 // Returns an array containing the id's of vendor tags defined. 58 void getTagArray(uint32_t* tagArray) const; 59 60 // Returns the section name string for a given vendor tag id. 61 const char* getSectionName(uint32_t tag) const; 62 63 // Returns the index in section vectors returned in getAllSectionNames() 64 // for a given vendor tag id. -1 if input tag does not exist. 65 ssize_t getSectionIndex(uint32_t tag) const; 66 67 // Returns the tag name string for a given vendor tag id. 68 const char* getTagName(uint32_t tag) const; 69 70 // Returns the tag type for a given vendor tag id. 71 int getTagType(uint32_t tag) const; 72 73 /** 74 * Convenience method to get a vector containing all vendor tag 75 * sections, or an empty vector if none are defined. 76 * The pointer is valid for the lifetime of the VendorTagDescriptor, 77 * or until copyFrom is invoked. 78 */ 79 const SortedVector<String8>* getAllSectionNames() const; 80 81 /** 82 * Lookup the tag id for a given tag name and section. 83 * 84 * Returns OK on success, or a negative error code. 85 */ 86 status_t lookupTag(const String8& name, const String8& section, /*out*/uint32_t* tag) const; 87 88 /** 89 * Dump the currently configured vendor tags to a file descriptor. 90 */ 91 void dump(int fd, int verbosity, int indentation) const; 92 93 protected: 94 KeyedVector<String8, KeyedVector<String8, uint32_t>*> mReverseMapping; 95 KeyedVector<uint32_t, String8> mTagToNameMap; 96 KeyedVector<uint32_t, uint32_t> mTagToSectionMap; // Value is offset in mSections 97 KeyedVector<uint32_t, int32_t> mTagToTypeMap; 98 SortedVector<String8> mSections; 99 // must be int32_t to be compatible with Parcel::writeInt32 100 int32_t mTagCount; 101 102 vendor_tag_ops mVendorOps; 103 }; 104 } /* namespace params */ 105 } /* namespace camera2 */ 106 107 namespace camera { 108 namespace common { 109 namespace V1_0 { 110 namespace helper { 111 112 /** 113 * This version of VendorTagDescriptor must be stored in Android sp<>, and adds support for using it 114 * as a global tag descriptor. 115 * 116 * It's a child class of the basic hardware::camera2::params::VendorTagDescriptor since basic 117 * Parcelable objects cannot require being kept in an sp<> and still work with auto-generated AIDL 118 * interface implementations. 119 */ 120 class VendorTagDescriptor : 121 public ::android::hardware::camera2::params::VendorTagDescriptor, 122 public LightRefBase<VendorTagDescriptor> { 123 124 public: 125 126 /** 127 * Create a VendorTagDescriptor object from the given vendor_tag_ops_t 128 * struct. 129 * 130 * Returns OK on success, or a negative error code. 131 */ 132 static status_t createDescriptorFromOps(const vendor_tag_ops_t* vOps, 133 /*out*/ 134 sp<VendorTagDescriptor>& descriptor); 135 136 /** 137 * Sets the global vendor tag descriptor to use for this process. 138 * Camera metadata operations that access vendor tags will use the 139 * vendor tag definitions set this way. 140 * 141 * Returns OK on success, or a negative error code. 142 */ 143 static status_t setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc); 144 145 /** 146 * Returns the global vendor tag descriptor used by this process. 147 * This will contain NULL if no vendor tags are defined. 148 */ 149 static sp<VendorTagDescriptor> getGlobalVendorTagDescriptor(); 150 151 /** 152 * Clears the global vendor tag descriptor used by this process. 153 */ 154 static void clearGlobalVendorTagDescriptor(); 155 156 }; 157 158 } // namespace helper 159 } // namespace V1_0 160 } // namespace common 161 } // namespace camera 162 } // namespace hardware 163 } // namespace android 164 165 #endif /* CAMERA_COMMON_1_0_VENDORTAGDESCRIPTOR_H */ 166