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