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