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