• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <utils/Vector.h>
20 #include <utils/KeyedVector.h>
21 #include <utils/String8.h>
22 #include <utils/RefBase.h>
23 #include <system/camera_vendor_tags.h>
24 
25 #include <stdint.h>
26 
27 namespace android {
28 
29 class Parcel;
30 
31 /**
32  * VendorTagDescriptor objects are parcelable containers for the vendor tag
33  * definitions provided, and are typically used to pass the vendor tag
34  * information enumerated by the HAL to clients of the camera service.
35  */
36 class VendorTagDescriptor
37         : public LightRefBase<VendorTagDescriptor> {
38     public:
39         virtual ~VendorTagDescriptor();
40 
41         /**
42          * The following 'get*' methods implement the corresponding
43          * functions defined in
44          * system/media/camera/include/system/camera_vendor_tags.h
45          */
46 
47         // Returns the number of vendor tags defined.
48         int getTagCount() const;
49 
50         // Returns an array containing the id's of vendor tags defined.
51         void getTagArray(uint32_t* tagArray) const;
52 
53         // Returns the section name string for a given vendor tag id.
54         const char* getSectionName(uint32_t tag) const;
55 
56         // Returns the tag name string for a given vendor tag id.
57         const char* getTagName(uint32_t tag) const;
58 
59         // Returns the tag type for a given vendor tag id.
60         int getTagType(uint32_t tag) const;
61 
62         /**
63          * Write the VendorTagDescriptor object into the given parcel.
64          *
65          * Returns OK on success, or a negative error code.
66          */
67         status_t writeToParcel(
68                 /*out*/
69                 Parcel* parcel) const;
70 
71         /**
72          * Convenience method to get a vector containing all vendor tag
73          * sections, or an empty vector if none are defined.
74          */
75         SortedVector<String8> getAllSectionNames() const;
76 
77         /**
78          * Lookup the tag id for a given tag name and section.
79          *
80          * Returns OK on success, or a negative error code.
81          */
82         status_t lookupTag(String8 name, String8 section, /*out*/uint32_t* tag) const;
83 
84         /**
85          * Dump the currently configured vendor tags to a file descriptor.
86          */
87         void dump(int fd, int verbosity, int indentation) const;
88 
89         // Static methods:
90 
91         /**
92          * Create a VendorTagDescriptor object from the given parcel.
93          *
94          * Returns OK on success, or a negative error code.
95          */
96         static status_t createFromParcel(const Parcel* parcel,
97                 /*out*/
98                 sp<VendorTagDescriptor>& descriptor);
99 
100         /**
101          * Create a VendorTagDescriptor object from the given vendor_tag_ops_t
102          * struct.
103          *
104          * Returns OK on success, or a negative error code.
105          */
106         static status_t createDescriptorFromOps(const vendor_tag_ops_t* vOps,
107                 /*out*/
108                 sp<VendorTagDescriptor>& descriptor);
109 
110         /**
111          * Sets the global vendor tag descriptor to use for this process.
112          * Camera metadata operations that access vendor tags will use the
113          * vendor tag definitions set this way.
114          *
115          * Returns OK on success, or a negative error code.
116          */
117         static status_t setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc);
118 
119         /**
120          * Clears the global vendor tag descriptor used by this process.
121          */
122         static void clearGlobalVendorTagDescriptor();
123 
124         /**
125          * Returns the global vendor tag descriptor used by this process.
126          * This will contain NULL if no vendor tags are defined.
127          */
128         static sp<VendorTagDescriptor> getGlobalVendorTagDescriptor();
129     protected:
130         VendorTagDescriptor();
131         KeyedVector<String8, KeyedVector<String8, uint32_t>*> mReverseMapping;
132         KeyedVector<uint32_t, String8> mTagToNameMap;
133         KeyedVector<uint32_t, uint32_t> mTagToSectionMap; // Value is offset in mSections
134         KeyedVector<uint32_t, int32_t> mTagToTypeMap;
135         SortedVector<String8> mSections;
136         // must be int32_t to be compatible with Parcel::writeInt32
137         int32_t mTagCount;
138     private:
139         vendor_tag_ops mVendorOps;
140 };
141 
142 } /* namespace android */
143 
144 #define VENDOR_TAG_DESCRIPTOR_H
145 #endif /* VENDOR_TAG_DESCRIPTOR_H */
146