MetaData.h revision b636abde14f2612ea236257846b9ab15d87d4623
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, image pixel 34 kKeyHeight = 'heig', // int32_t, image pixel 35 kKeyDisplayWidth = 'dWid', // int32_t, display/presentation 36 kKeyDisplayHeight = 'dHgt', // int32_t, display/presentation 37 38 // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1) 39 kKeyCropRect = 'crop', 40 41 kKeyRotation = 'rotA', // int32_t (angle in degrees) 42 kKeyIFramesInterval = 'ifiv', // int32_t 43 kKeyStride = 'strd', // int32_t 44 kKeySliceHeight = 'slht', // int32_t 45 kKeyChannelCount = '#chn', // int32_t 46 kKeyChannelMask = 'chnm', // int32_t 47 kKeySampleRate = 'srte', // int32_t (audio sampling rate Hz) 48 kKeyFrameRate = 'frmR', // int32_t (video frame rate fps) 49 kKeyBitRate = 'brte', // int32_t (bps) 50 kKeyESDS = 'esds', // raw data 51 kKeyAVCC = 'avcc', // raw data 52 kKeyD263 = 'd263', // raw data 53 kKeyVorbisInfo = 'vinf', // raw data 54 kKeyVorbisBooks = 'vboo', // raw data 55 kKeyWantsNALFragments = 'NALf', 56 kKeyIsSyncFrame = 'sync', // int32_t (bool) 57 kKeyIsCodecConfig = 'conf', // int32_t (bool) 58 kKeyTime = 'time', // int64_t (usecs) 59 kKeyDecodingTime = 'decT', // int64_t (decoding timestamp in usecs) 60 kKeyNTPTime = 'ntpT', // uint64_t (ntp-timestamp) 61 kKeyTargetTime = 'tarT', // int64_t (usecs) 62 kKeyDriftTime = 'dftT', // int64_t (usecs) 63 kKeyAnchorTime = 'ancT', // int64_t (usecs) 64 kKeyDuration = 'dura', // int64_t (usecs) 65 kKeyColorFormat = 'colf', 66 kKeyPlatformPrivate = 'priv', // pointer 67 kKeyDecoderComponent = 'decC', // cstring 68 kKeyBufferID = 'bfID', 69 kKeyMaxInputSize = 'inpS', 70 kKeyThumbnailTime = 'thbT', // int64_t (usecs) 71 kKeyTrackID = 'trID', 72 kKeyIsDRM = 'idrm', // int32_t (bool) 73 kKeyEncoderDelay = 'encd', // int32_t (frames) 74 kKeyEncoderPadding = 'encp', // int32_t (frames) 75 76 kKeyAlbum = 'albu', // cstring 77 kKeyArtist = 'arti', // cstring 78 kKeyAlbumArtist = 'aart', // cstring 79 kKeyComposer = 'comp', // cstring 80 kKeyGenre = 'genr', // cstring 81 kKeyTitle = 'titl', // cstring 82 kKeyYear = 'year', // cstring 83 kKeyAlbumArt = 'albA', // compressed image data 84 kKeyAlbumArtMIME = 'alAM', // cstring 85 kKeyAuthor = 'auth', // cstring 86 kKeyCDTrackNumber = 'cdtr', // cstring 87 kKeyDiscNumber = 'dnum', // cstring 88 kKeyDate = 'date', // cstring 89 kKeyWriter = 'writ', // cstring 90 kKeyCompilation = 'cpil', // cstring 91 kKeyLocation = 'loc ', // cstring 92 kKeyTimeScale = 'tmsl', // int32_t 93 94 // video profile and level 95 kKeyVideoProfile = 'vprf', // int32_t 96 kKeyVideoLevel = 'vlev', // int32_t 97 98 // Set this key to enable authoring files in 64-bit offset 99 kKey64BitFileOffset = 'fobt', // int32_t (bool) 100 kKey2ByteNalLength = '2NAL', // int32_t (bool) 101 102 // Identify the file output format for authoring 103 // Please see <media/mediarecorder.h> for the supported 104 // file output formats. 105 kKeyFileType = 'ftyp', // int32_t 106 107 // Track authoring progress status 108 // kKeyTrackTimeStatus is used to track progress in elapsed time 109 kKeyTrackTimeStatus = 'tktm', // int64_t 110 111 kKeyNotRealTime = 'ntrt', // bool (int32_t) 112 113 // Ogg files can be tagged to be automatically looping... 114 kKeyAutoLoop = 'autL', // bool (int32_t) 115 116 kKeyValidSamples = 'valD', // int32_t 117 118 kKeyIsUnreadable = 'unre', // bool (int32_t) 119 120 // An indication that a video buffer has been rendered. 121 kKeyRendered = 'rend', // bool (int32_t) 122 123 // The language code for this media 124 kKeyMediaLanguage = 'lang', // cstring 125 126 // To store the timed text format data 127 kKeyTextFormatData = 'text', // raw data 128 129 kKeyRequiresSecureBuffers = 'secu', // bool (int32_t) 130}; 131 132enum { 133 kTypeESDS = 'esds', 134 kTypeAVCC = 'avcc', 135 kTypeD263 = 'd263', 136}; 137 138class MetaData : public RefBase { 139public: 140 MetaData(); 141 MetaData(const MetaData &from); 142 143 enum Type { 144 TYPE_NONE = 'none', 145 TYPE_C_STRING = 'cstr', 146 TYPE_INT32 = 'in32', 147 TYPE_INT64 = 'in64', 148 TYPE_FLOAT = 'floa', 149 TYPE_POINTER = 'ptr ', 150 TYPE_RECT = 'rect', 151 }; 152 153 void clear(); 154 bool remove(uint32_t key); 155 156 bool setCString(uint32_t key, const char *value); 157 bool setInt32(uint32_t key, int32_t value); 158 bool setInt64(uint32_t key, int64_t value); 159 bool setFloat(uint32_t key, float value); 160 bool setPointer(uint32_t key, void *value); 161 162 bool setRect( 163 uint32_t key, 164 int32_t left, int32_t top, 165 int32_t right, int32_t bottom); 166 167 bool findCString(uint32_t key, const char **value); 168 bool findInt32(uint32_t key, int32_t *value); 169 bool findInt64(uint32_t key, int64_t *value); 170 bool findFloat(uint32_t key, float *value); 171 bool findPointer(uint32_t key, void **value); 172 173 bool findRect( 174 uint32_t key, 175 int32_t *left, int32_t *top, 176 int32_t *right, int32_t *bottom); 177 178 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 179 180 bool findData(uint32_t key, uint32_t *type, 181 const void **data, size_t *size) const; 182 183protected: 184 virtual ~MetaData(); 185 186private: 187 struct typed_data { 188 typed_data(); 189 ~typed_data(); 190 191 typed_data(const MetaData::typed_data &); 192 typed_data &operator=(const MetaData::typed_data &); 193 194 void clear(); 195 void setData(uint32_t type, const void *data, size_t size); 196 void getData(uint32_t *type, const void **data, size_t *size) const; 197 198 private: 199 uint32_t mType; 200 size_t mSize; 201 202 union { 203 void *ext_data; 204 float reservoir; 205 } u; 206 207 bool usesReservoir() const { 208 return mSize <= sizeof(u.reservoir); 209 } 210 211 void allocateStorage(size_t size); 212 void freeStorage(); 213 214 void *storage() { 215 return usesReservoir() ? &u.reservoir : u.ext_data; 216 } 217 218 const void *storage() const { 219 return usesReservoir() ? &u.reservoir : u.ext_data; 220 } 221 }; 222 223 struct Rect { 224 int32_t mLeft, mTop, mRight, mBottom; 225 }; 226 227 KeyedVector<uint32_t, typed_data> mItems; 228 229 // MetaData &operator=(const MetaData &); 230}; 231 232} // namespace android 233 234#endif // META_DATA_H_ 235