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