| Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2012 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 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame^] | 17 | #ifndef ANDROID_SERVERS_CAMERA_CAMERA2METADATA_CPP | 
|  | 18 | #define ANDROID_SERVERS_CAMERA_CAMERA2METADATA_CPP | 
| Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 19 |  | 
|  | 20 | #include "system/camera_metadata.h" | 
|  | 21 | #include <utils/String8.h> | 
|  | 22 | #include <utils/Vector.h> | 
|  | 23 |  | 
|  | 24 | namespace android { | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame^] | 25 | namespace camera2 { | 
| Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | /** | 
|  | 28 | * A convenience wrapper around the C-based camera_metadata_t library. | 
|  | 29 | */ | 
|  | 30 | class CameraMetadata { | 
|  | 31 | public: | 
|  | 32 | /** Creates an empty object; best used when expecting to acquire contents | 
|  | 33 | * from elsewhere */ | 
|  | 34 | CameraMetadata(); | 
|  | 35 | /** Creates an object with space for entryCapacity entries, with | 
|  | 36 | * dataCapacity extra storage */ | 
|  | 37 | CameraMetadata(size_t entryCapacity, size_t dataCapacity = 10); | 
|  | 38 |  | 
|  | 39 | ~CameraMetadata(); | 
|  | 40 |  | 
|  | 41 | /** Takes ownership of passed-in buffer */ | 
|  | 42 | CameraMetadata(camera_metadata_t *buffer); | 
|  | 43 | /** Clones the metadata */ | 
|  | 44 | CameraMetadata(const CameraMetadata &other); | 
|  | 45 |  | 
|  | 46 | /** | 
|  | 47 | * Assignment clones metadata buffer. | 
|  | 48 | */ | 
|  | 49 | CameraMetadata &operator=(const CameraMetadata &other); | 
|  | 50 | CameraMetadata &operator=(const camera_metadata_t *buffer); | 
|  | 51 |  | 
|  | 52 | /** | 
|  | 53 | * Release a raw metadata buffer to the caller. After this call, | 
|  | 54 | * CameraMetadata no longer references the buffer, and the caller takes | 
|  | 55 | * responsibility for freeing the raw metadata buffer (using | 
|  | 56 | * free_camera_metadata()), or for handing it to another CameraMetadata | 
|  | 57 | * instance. | 
|  | 58 | */ | 
|  | 59 | camera_metadata_t* release(); | 
|  | 60 |  | 
|  | 61 | /** | 
|  | 62 | * Clear the metadata buffer and free all storage used by it | 
|  | 63 | */ | 
|  | 64 | void clear(); | 
|  | 65 |  | 
|  | 66 | /** | 
|  | 67 | * Acquire a raw metadata buffer from the caller. After this call, | 
|  | 68 | * the caller no longer owns the raw buffer, and must not free or manipulate it. | 
|  | 69 | * If CameraMetadata already contains metadata, it is freed. | 
|  | 70 | */ | 
|  | 71 | void acquire(camera_metadata_t* buffer); | 
|  | 72 |  | 
|  | 73 | /** | 
|  | 74 | * Acquires raw buffer from other CameraMetadata object. After the call, the argument | 
|  | 75 | * object no longer has any metadata. | 
|  | 76 | */ | 
|  | 77 | void acquire(CameraMetadata &other); | 
|  | 78 |  | 
|  | 79 | /** | 
|  | 80 | * Append metadata from another CameraMetadata object. | 
|  | 81 | */ | 
|  | 82 | status_t append(const CameraMetadata &other); | 
|  | 83 |  | 
|  | 84 | /** | 
|  | 85 | * Number of metadata entries. | 
|  | 86 | */ | 
|  | 87 | size_t entryCount() const; | 
|  | 88 |  | 
|  | 89 | /** | 
|  | 90 | * Sort metadata buffer for faster find | 
|  | 91 | */ | 
|  | 92 | status_t sort(); | 
|  | 93 |  | 
|  | 94 | /** | 
|  | 95 | * Update metadata entry. Will create entry if it doesn't exist already, and | 
|  | 96 | * will reallocate the buffer if insufficient space exists. Overloaded for | 
|  | 97 | * the various types of valid data. | 
|  | 98 | */ | 
|  | 99 | status_t update(uint32_t tag, | 
|  | 100 | const uint8_t *data, size_t data_count); | 
|  | 101 | status_t update(uint32_t tag, | 
|  | 102 | const int32_t *data, size_t data_count); | 
|  | 103 | status_t update(uint32_t tag, | 
|  | 104 | const float *data, size_t data_count); | 
|  | 105 | status_t update(uint32_t tag, | 
|  | 106 | const int64_t *data, size_t data_count); | 
|  | 107 | status_t update(uint32_t tag, | 
|  | 108 | const double *data, size_t data_count); | 
|  | 109 | status_t update(uint32_t tag, | 
|  | 110 | const camera_metadata_rational_t *data, size_t data_count); | 
|  | 111 | status_t update(uint32_t tag, | 
|  | 112 | const String8 &string); | 
|  | 113 |  | 
|  | 114 | template<typename T> | 
|  | 115 | status_t update(uint32_t tag, Vector<T> data) { | 
|  | 116 | return update(tag, data.array(), data.size()); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | /** | 
|  | 120 | * Get metadata entry by tag id | 
|  | 121 | */ | 
|  | 122 | camera_metadata_entry find(uint32_t tag); | 
|  | 123 |  | 
|  | 124 | /** | 
|  | 125 | * Get metadata entry by tag id, with no editing | 
|  | 126 | */ | 
|  | 127 | camera_metadata_ro_entry find(uint32_t tag) const; | 
|  | 128 |  | 
|  | 129 | /** | 
|  | 130 | * Delete metadata entry by tag | 
|  | 131 | */ | 
|  | 132 | status_t erase(uint32_t tag); | 
|  | 133 |  | 
|  | 134 | /** | 
|  | 135 | * Dump contents into FD for debugging. The verbosity levels are | 
|  | 136 | * 0: Tag entry information only, no data values | 
|  | 137 | * 1: Level 0 plus at most 16 data values per entry | 
|  | 138 | * 2: All information | 
|  | 139 | * | 
|  | 140 | * The indentation parameter sets the number of spaces to add to the start | 
|  | 141 | * each line of output. | 
|  | 142 | */ | 
|  | 143 | void dump(int fd, int verbosity = 1, int indentation = 0) const; | 
|  | 144 |  | 
|  | 145 | private: | 
|  | 146 | camera_metadata_t *mBuffer; | 
|  | 147 |  | 
|  | 148 | /** | 
|  | 149 | * Check if tag has a given type | 
|  | 150 | */ | 
|  | 151 | status_t checkType(uint32_t tag, uint8_t expectedType); | 
|  | 152 |  | 
|  | 153 | /** | 
|  | 154 | * Base update entry method | 
|  | 155 | */ | 
|  | 156 | status_t update(uint32_t tag, const void *data, size_t data_count); | 
|  | 157 |  | 
|  | 158 | /** | 
|  | 159 | * Resize metadata buffer if needed by reallocating it and copying it over. | 
|  | 160 | */ | 
|  | 161 | status_t resizeIfNeeded(size_t extraEntries, size_t extraData); | 
|  | 162 |  | 
|  | 163 | }; | 
|  | 164 |  | 
| Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame^] | 165 | }; // namespace camera2 | 
| Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 166 | }; // namespace android | 
|  | 167 |  | 
|  | 168 | #endif |