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