Home | History | Annotate | Download | only in camera
      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 #include <unordered_map>
     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                 android::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          * The pointer is valid for the lifetime of the VendorTagDescriptor,
     85          * or until readParcel or copyFrom is invoked.
     86          */
     87         const SortedVector<String8>* getAllSectionNames() const;
     88 
     89         /**
     90          * Lookup the tag id for a given tag name and section.
     91          *
     92          * Returns OK on success, or a negative error code.
     93          */
     94         status_t lookupTag(const String8& name, const String8& section, /*out*/uint32_t* tag) const;
     95 
     96         /**
     97          * Dump the currently configured vendor tags to a file descriptor.
     98          */
     99         void dump(int fd, int verbosity, int indentation) const;
    100 
    101         /**
    102          * Read values VendorTagDescriptor object from the given parcel.
    103          *
    104          * Returns OK on success, or a negative error code.
    105          */
    106         virtual status_t readFromParcel(const android::Parcel* parcel) override;
    107 
    108     protected:
    109         KeyedVector<String8, KeyedVector<String8, uint32_t>*> mReverseMapping;
    110         KeyedVector<uint32_t, String8> mTagToNameMap;
    111         KeyedVector<uint32_t, uint32_t> mTagToSectionMap; // Value is offset in mSections
    112         KeyedVector<uint32_t, int32_t> mTagToTypeMap;
    113         SortedVector<String8> mSections;
    114         // must be int32_t to be compatible with Parcel::writeInt32
    115         int32_t mTagCount;
    116 
    117         vendor_tag_ops mVendorOps;
    118 };
    119 } /* namespace params */
    120 } /* namespace camera2 */
    121 } /* namespace hardware */
    122 
    123 /**
    124  * This version of VendorTagDescriptor must be stored in Android sp<>, and adds support for using it
    125  * as a global tag descriptor.
    126  *
    127  * It's a child class of the basic hardware::camera2::params::VendorTagDescriptor since basic
    128  * Parcelable objects cannot require being kept in an sp<> and still work with auto-generated AIDL
    129  * interface implementations.
    130  */
    131 class VendorTagDescriptor :
    132             public ::android::hardware::camera2::params::VendorTagDescriptor,
    133             public LightRefBase<VendorTagDescriptor> {
    134 
    135   public:
    136 
    137     /**
    138      * Create a VendorTagDescriptor object from the given vendor_tag_ops_t
    139      * struct.
    140      *
    141      * Returns OK on success, or a negative error code.
    142      */
    143     static status_t createDescriptorFromOps(const vendor_tag_ops_t* vOps,
    144             /*out*/
    145             sp<VendorTagDescriptor>& descriptor);
    146 
    147     /**
    148      * Sets the global vendor tag descriptor to use for this process.
    149      * Camera metadata operations that access vendor tags will use the
    150      * vendor tag definitions set this way.
    151      *
    152      * Returns OK on success, or a negative error code.
    153      */
    154     static status_t setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc);
    155 
    156     /**
    157      * Returns the global vendor tag descriptor used by this process.
    158      * This will contain NULL if no vendor tags are defined.
    159      */
    160     static sp<VendorTagDescriptor> getGlobalVendorTagDescriptor();
    161 
    162     /**
    163      * Clears the global vendor tag descriptor used by this process.
    164      */
    165     static void clearGlobalVendorTagDescriptor();
    166 
    167 };
    168 
    169 namespace hardware {
    170 namespace camera2 {
    171 namespace params {
    172 
    173 class VendorTagDescriptorCache : public Parcelable {
    174   public:
    175 
    176     VendorTagDescriptorCache() {};
    177 
    178     int32_t addVendorDescriptor(metadata_vendor_id_t id,
    179             sp<android::VendorTagDescriptor> desc);
    180 
    181     int32_t getVendorTagDescriptor(
    182             metadata_vendor_id_t id,
    183             sp<android::VendorTagDescriptor> *desc /*out*/);
    184 
    185     // Parcelable interface
    186     status_t writeToParcel(Parcel* parcel) const override;
    187     status_t readFromParcel(const Parcel* parcel) override;
    188 
    189     // Returns the number of vendor tags defined.
    190     int getTagCount(metadata_vendor_id_t id) const;
    191 
    192     // Returns an array containing the id's of vendor tags defined.
    193     void getTagArray(uint32_t* tagArray, metadata_vendor_id_t id) const;
    194 
    195     // Returns the section name string for a given vendor tag id.
    196     const char* getSectionName(uint32_t tag, metadata_vendor_id_t id) const;
    197 
    198     // Returns the tag name string for a given vendor tag id.
    199     const char* getTagName(uint32_t tag, metadata_vendor_id_t id) const;
    200 
    201     // Returns the tag type for a given vendor tag id.
    202     int getTagType(uint32_t tag, metadata_vendor_id_t id) const;
    203 
    204     /**
    205      * Dump the currently configured vendor tags to a file descriptor.
    206      */
    207     void dump(int fd, int verbosity, int indentation) const;
    208 
    209   protected:
    210     std::unordered_map<metadata_vendor_id_t, sp<android::VendorTagDescriptor>> mVendorMap;
    211     struct vendor_tag_cache_ops mVendorCacheOps;
    212 };
    213 
    214 } /* namespace params */
    215 } /* namespace camera2 */
    216 } /* namespace hardware */
    217 
    218 class VendorTagDescriptorCache :
    219         public ::android::hardware::camera2::params::VendorTagDescriptorCache,
    220         public LightRefBase<VendorTagDescriptorCache> {
    221   public:
    222 
    223     /**
    224      * Sets the global vendor tag descriptor cache to use for this process.
    225      * Camera metadata operations that access vendor tags will use the
    226      * vendor tag definitions set this way.
    227      *
    228      * Returns OK on success, or a negative error code.
    229      */
    230     static status_t setAsGlobalVendorTagCache(
    231             const sp<VendorTagDescriptorCache>& cache);
    232 
    233     /**
    234      * Returns the global vendor tag cache used by this process.
    235      * This will contain NULL if no vendor tags are defined.
    236      */
    237     static sp<VendorTagDescriptorCache> getGlobalVendorTagCache();
    238 
    239     /**
    240      * Clears the global vendor tag cache used by this process.
    241      */
    242     static void clearGlobalVendorTagCache();
    243 
    244 };
    245 
    246 } /* namespace android */
    247 
    248 #define VENDOR_TAG_DESCRIPTOR_H
    249 #endif /* VENDOR_TAG_DESCRIPTOR_H */
    250