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