MetaData.h revision 93d6b102a13afa23bfa80d74c399d93d542e6ad6
1/* 2 * Copyright (C) 2009 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 META_DATA_H_ 18 19#define META_DATA_H_ 20 21#include <sys/types.h> 22 23#include <stdint.h> 24 25#include <utils/RefBase.h> 26#include <utils/KeyedVector.h> 27 28namespace android { 29 30// The following keys map to int32_t data unless indicated otherwise. 31enum { 32 kKeyMIMEType = 'mime', // cstring 33 kKeyWidth = 'widt', // int32_t 34 kKeyHeight = 'heig', // int32_t 35 kKeyIFramesInterval = 'ifiv', // int32_t 36 kKeyStride = 'strd', // int32_t 37 kKeySliceHeight = 'slht', // int32_t 38 kKeyChannelCount = '#chn', // int32_t 39 kKeySampleRate = 'srte', // int32_t (also video frame rate) 40 kKeyBitRate = 'brte', // int32_t (bps) 41 kKeyESDS = 'esds', // raw data 42 kKeyAVCC = 'avcc', // raw data 43 kKeyVorbisInfo = 'vinf', // raw data 44 kKeyVorbisBooks = 'vboo', // raw data 45 kKeyWantsNALFragments = 'NALf', 46 kKeyIsSyncFrame = 'sync', // int32_t (bool) 47 kKeyIsCodecConfig = 'conf', // int32_t (bool) 48 kKeyTime = 'time', // int64_t (usecs) 49 kKeyDuration = 'dura', // int64_t (usecs) 50 kKeyColorFormat = 'colf', 51 kKeyPlatformPrivate = 'priv', // pointer 52 kKeyDecoderComponent = 'decC', // cstring 53 kKeyBufferID = 'bfID', 54 kKeyMaxInputSize = 'inpS', 55 kKeyThumbnailTime = 'thbT', // int64_t (usecs) 56 57 kKeyAlbum = 'albu', // cstring 58 kKeyArtist = 'arti', // cstring 59 kKeyAlbumArtist = 'aart', // cstring 60 kKeyComposer = 'comp', // cstring 61 kKeyGenre = 'genr', // cstring 62 kKeyTitle = 'titl', // cstring 63 kKeyYear = 'year', // cstring 64 kKeyAlbumArt = 'albA', // compressed image data 65 kKeyAlbumArtMIME = 'alAM', // cstring 66 kKeyAuthor = 'auth', // cstring 67 kKeyCDTrackNumber = 'cdtr', // cstring 68 kKeyDiscNumber = 'dnum', // cstring 69 kKeyDate = 'date', // cstring 70 kKeyWriter = 'writ', // cstring 71 72 // Set this key to enable authoring files in 64-bit offset 73 kKey64BitFileOffset = 'fobt', // int32_t (bool) 74 75 // Identify the file output format for authoring 76 // Please see <media/mediarecorder.h> for the supported 77 // file output formats. 78 kKeyFileType = 'ftyp', // int32_t 79 80 // Track authoring progress status 81 // kKeyTrackTimeStatus is used to track progress in elapsed time 82 // kKeyTrackFrameStatus is used to track progress in authored frames 83 kKeyTrackFrameStatus = 'tkfm', // int32_t 84 kKeyTrackTimeStatus = 'tktm', // int64_t 85 86}; 87 88enum { 89 kTypeESDS = 'esds', 90 kTypeAVCC = 'avcc', 91}; 92 93class MetaData : public RefBase { 94public: 95 MetaData(); 96 MetaData(const MetaData &from); 97 98 enum Type { 99 TYPE_NONE = 'none', 100 TYPE_C_STRING = 'cstr', 101 TYPE_INT32 = 'in32', 102 TYPE_INT64 = 'in64', 103 TYPE_FLOAT = 'floa', 104 TYPE_POINTER = 'ptr ', 105 }; 106 107 void clear(); 108 bool remove(uint32_t key); 109 110 bool setCString(uint32_t key, const char *value); 111 bool setInt32(uint32_t key, int32_t value); 112 bool setInt64(uint32_t key, int64_t value); 113 bool setFloat(uint32_t key, float value); 114 bool setPointer(uint32_t key, void *value); 115 116 bool findCString(uint32_t key, const char **value); 117 bool findInt32(uint32_t key, int32_t *value); 118 bool findInt64(uint32_t key, int64_t *value); 119 bool findFloat(uint32_t key, float *value); 120 bool findPointer(uint32_t key, void **value); 121 122 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 123 124 bool findData(uint32_t key, uint32_t *type, 125 const void **data, size_t *size) const; 126 127protected: 128 virtual ~MetaData(); 129 130private: 131 struct typed_data { 132 typed_data(); 133 ~typed_data(); 134 135 typed_data(const MetaData::typed_data &); 136 typed_data &operator=(const MetaData::typed_data &); 137 138 void clear(); 139 void setData(uint32_t type, const void *data, size_t size); 140 void getData(uint32_t *type, const void **data, size_t *size) const; 141 142 private: 143 uint32_t mType; 144 size_t mSize; 145 146 union { 147 void *ext_data; 148 float reservoir; 149 } u; 150 151 bool usesReservoir() const { 152 return mSize <= sizeof(u.reservoir); 153 } 154 155 void allocateStorage(size_t size); 156 void freeStorage(); 157 158 void *storage() { 159 return usesReservoir() ? &u.reservoir : u.ext_data; 160 } 161 162 const void *storage() const { 163 return usesReservoir() ? &u.reservoir : u.ext_data; 164 } 165 }; 166 167 KeyedVector<uint32_t, typed_data> mItems; 168 169 // MetaData &operator=(const MetaData &); 170}; 171 172} // namespace android 173 174#endif // META_DATA_H_ 175