MetaData.h revision 2b82e9652ba049e754c2cc74e381282f231d5fbf
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 kKeyNTPTime = 'ntpT', // uint64_t (ntp-timestamp) 50 kKeyTargetTime = 'tarT', // int64_t (usecs) 51 kKeyDriftTime = 'dftT', // int64_t (usecs) 52 kKeyAnchorTime = 'ancT', // int64_t (usecs) 53 kKeyDuration = 'dura', // int64_t (usecs) 54 kKeyColorFormat = 'colf', 55 kKeyPlatformPrivate = 'priv', // pointer 56 kKeyDecoderComponent = 'decC', // cstring 57 kKeyBufferID = 'bfID', 58 kKeyMaxInputSize = 'inpS', 59 kKeyThumbnailTime = 'thbT', // int64_t (usecs) 60 61 kKeyAlbum = 'albu', // cstring 62 kKeyArtist = 'arti', // cstring 63 kKeyAlbumArtist = 'aart', // cstring 64 kKeyComposer = 'comp', // cstring 65 kKeyGenre = 'genr', // cstring 66 kKeyTitle = 'titl', // cstring 67 kKeyYear = 'year', // cstring 68 kKeyAlbumArt = 'albA', // compressed image data 69 kKeyAlbumArtMIME = 'alAM', // cstring 70 kKeyAuthor = 'auth', // cstring 71 kKeyCDTrackNumber = 'cdtr', // cstring 72 kKeyDiscNumber = 'dnum', // cstring 73 kKeyDate = 'date', // cstring 74 kKeyWriter = 'writ', // cstring 75 kKeyTimeScale = 'tmsl', // int32_t 76 77 // video profile and level 78 kKeyVideoProfile = 'vprf', // int32_t 79 kKeyVideoLevel = 'vlev', // int32_t 80 81 // Set this key to enable authoring files in 64-bit offset 82 kKey64BitFileOffset = 'fobt', // int32_t (bool) 83 kKey2ByteNalLength = '2NAL', // int32_t (bool) 84 85 // Identify the file output format for authoring 86 // Please see <media/mediarecorder.h> for the supported 87 // file output formats. 88 kKeyFileType = 'ftyp', // int32_t 89 90 // Track authoring progress status 91 // kKeyTrackTimeStatus is used to track progress in elapsed time 92 kKeyTrackTimeStatus = 'tktm', // int64_t 93 94 kKeyNotRealTime = 'ntrt', // bool (int32_t) 95 96 // Ogg files can be tagged to be automatically looping... 97 kKeyAutoLoop = 'autL', // bool (int32_t) 98 99 kKeyValidSamples = 'valD', // int32_t 100 101 kKeyIsUnreadable = 'unre', // bool (int32_t) 102}; 103 104enum { 105 kTypeESDS = 'esds', 106 kTypeAVCC = 'avcc', 107}; 108 109class MetaData : public RefBase { 110public: 111 MetaData(); 112 MetaData(const MetaData &from); 113 114 enum Type { 115 TYPE_NONE = 'none', 116 TYPE_C_STRING = 'cstr', 117 TYPE_INT32 = 'in32', 118 TYPE_INT64 = 'in64', 119 TYPE_FLOAT = 'floa', 120 TYPE_POINTER = 'ptr ', 121 }; 122 123 void clear(); 124 bool remove(uint32_t key); 125 126 bool setCString(uint32_t key, const char *value); 127 bool setInt32(uint32_t key, int32_t value); 128 bool setInt64(uint32_t key, int64_t value); 129 bool setFloat(uint32_t key, float value); 130 bool setPointer(uint32_t key, void *value); 131 132 bool findCString(uint32_t key, const char **value); 133 bool findInt32(uint32_t key, int32_t *value); 134 bool findInt64(uint32_t key, int64_t *value); 135 bool findFloat(uint32_t key, float *value); 136 bool findPointer(uint32_t key, void **value); 137 138 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 139 140 bool findData(uint32_t key, uint32_t *type, 141 const void **data, size_t *size) const; 142 143protected: 144 virtual ~MetaData(); 145 146private: 147 struct typed_data { 148 typed_data(); 149 ~typed_data(); 150 151 typed_data(const MetaData::typed_data &); 152 typed_data &operator=(const MetaData::typed_data &); 153 154 void clear(); 155 void setData(uint32_t type, const void *data, size_t size); 156 void getData(uint32_t *type, const void **data, size_t *size) const; 157 158 private: 159 uint32_t mType; 160 size_t mSize; 161 162 union { 163 void *ext_data; 164 float reservoir; 165 } u; 166 167 bool usesReservoir() const { 168 return mSize <= sizeof(u.reservoir); 169 } 170 171 void allocateStorage(size_t size); 172 void freeStorage(); 173 174 void *storage() { 175 return usesReservoir() ? &u.reservoir : u.ext_data; 176 } 177 178 const void *storage() const { 179 return usesReservoir() ? &u.reservoir : u.ext_data; 180 } 181 }; 182 183 KeyedVector<uint32_t, typed_data> mItems; 184 185 // MetaData &operator=(const MetaData &); 186}; 187 188} // namespace android 189 190#endif // META_DATA_H_ 191