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