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