MetaData.h revision 78bd91b15ee8ea5aa2ab5a8cad7e892cb2d01c1b
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 <binder/Parcel.h> 26#include <utils/RefBase.h> 27#include <utils/KeyedVector.h> 28#include <utils/String8.h> 29 30namespace android { 31 32// The following keys map to int32_t data unless indicated otherwise. 33enum { 34 kKeyMIMEType = 'mime', // cstring 35 kKeyWidth = 'widt', // int32_t, image pixel 36 kKeyHeight = 'heig', // int32_t, image pixel 37 kKeyDisplayWidth = 'dWid', // int32_t, display/presentation 38 kKeyDisplayHeight = 'dHgt', // int32_t, display/presentation 39 kKeySARWidth = 'sarW', // int32_t, sampleAspectRatio width 40 kKeySARHeight = 'sarH', // int32_t, sampleAspectRatio height 41 42 // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1) 43 kKeyCropRect = 'crop', 44 45 kKeyRotation = 'rotA', // int32_t (angle in degrees) 46 kKeyIFramesInterval = 'ifiv', // int32_t 47 kKeyStride = 'strd', // int32_t 48 kKeySliceHeight = 'slht', // int32_t 49 kKeyChannelCount = '#chn', // int32_t 50 kKeyChannelMask = 'chnm', // int32_t 51 kKeySampleRate = 'srte', // int32_t (audio sampling rate Hz) 52 kKeyPcmEncoding = 'PCMe', // int32_t (audio encoding enum) 53 kKeyFrameRate = 'frmR', // int32_t (video frame rate fps) 54 kKeyBitRate = 'brte', // int32_t (bps) 55 kKeyESDS = 'esds', // raw data 56 kKeyAACProfile = 'aacp', // int32_t 57 kKeyAVCC = 'avcc', // raw data 58 kKeyHVCC = 'hvcc', // raw data 59 kKeyD263 = 'd263', // raw data 60 kKeyVorbisInfo = 'vinf', // raw data 61 kKeyVorbisBooks = 'vboo', // raw data 62 kKeyOpusHeader = 'ohdr', // raw data 63 kKeyOpusCodecDelay = 'ocod', // uint64_t (codec delay in ns) 64 kKeyOpusSeekPreRoll = 'ospr', // uint64_t (seek preroll in ns) 65 kKeyWantsNALFragments = 'NALf', 66 kKeyIsSyncFrame = 'sync', // int32_t (bool) 67 kKeyIsCodecConfig = 'conf', // int32_t (bool) 68 kKeyTime = 'time', // int64_t (usecs) 69 kKeyDecodingTime = 'decT', // int64_t (decoding timestamp in usecs) 70 kKeyNTPTime = 'ntpT', // uint64_t (ntp-timestamp) 71 kKeyTargetTime = 'tarT', // int64_t (usecs) 72 kKeyDriftTime = 'dftT', // int64_t (usecs) 73 kKeyAnchorTime = 'ancT', // int64_t (usecs) 74 kKeyDuration = 'dura', // int64_t (usecs) 75 kKeyPixelFormat = 'pixf', // int32_t 76 kKeyColorFormat = 'colf', // int32_t 77 kKeyColorSpace = 'cols', // int32_t 78 kKeyPlatformPrivate = 'priv', // pointer 79 kKeyDecoderComponent = 'decC', // cstring 80 kKeyBufferID = 'bfID', 81 kKeyMaxInputSize = 'inpS', 82 kKeyMaxWidth = 'maxW', 83 kKeyMaxHeight = 'maxH', 84 kKeyThumbnailTime = 'thbT', // int64_t (usecs) 85 kKeyTrackID = 'trID', 86 kKeyIsDRM = 'idrm', // int32_t (bool) 87 kKeyEncoderDelay = 'encd', // int32_t (frames) 88 kKeyEncoderPadding = 'encp', // int32_t (frames) 89 90 kKeyAlbum = 'albu', // cstring 91 kKeyArtist = 'arti', // cstring 92 kKeyAlbumArtist = 'aart', // cstring 93 kKeyComposer = 'comp', // cstring 94 kKeyGenre = 'genr', // cstring 95 kKeyTitle = 'titl', // cstring 96 kKeyYear = 'year', // cstring 97 kKeyAlbumArt = 'albA', // compressed image data 98 kKeyAlbumArtMIME = 'alAM', // cstring 99 kKeyAuthor = 'auth', // cstring 100 kKeyCDTrackNumber = 'cdtr', // cstring 101 kKeyDiscNumber = 'dnum', // cstring 102 kKeyDate = 'date', // cstring 103 kKeyWriter = 'writ', // cstring 104 kKeyCompilation = 'cpil', // cstring 105 kKeyLocation = 'loc ', // cstring 106 kKeyTimeScale = 'tmsl', // int32_t 107 kKeyCaptureFramerate = 'capF', // float (capture fps) 108 109 // video profile and level 110 kKeyVideoProfile = 'vprf', // int32_t 111 kKeyVideoLevel = 'vlev', // int32_t 112 113 // Set this key to enable authoring files in 64-bit offset 114 kKey64BitFileOffset = 'fobt', // int32_t (bool) 115 kKey2ByteNalLength = '2NAL', // int32_t (bool) 116 117 // Identify the file output format for authoring 118 // Please see <media/mediarecorder.h> for the supported 119 // file output formats. 120 kKeyFileType = 'ftyp', // int32_t 121 122 // Track authoring progress status 123 // kKeyTrackTimeStatus is used to track progress in elapsed time 124 kKeyTrackTimeStatus = 'tktm', // int64_t 125 126 kKeyRealTimeRecording = 'rtrc', // bool (int32_t) 127 kKeyNumBuffers = 'nbbf', // int32_t 128 129 // Ogg files can be tagged to be automatically looping... 130 kKeyAutoLoop = 'autL', // bool (int32_t) 131 132 kKeyValidSamples = 'valD', // int32_t 133 134 kKeyIsUnreadable = 'unre', // bool (int32_t) 135 136 // An indication that a video buffer has been rendered. 137 kKeyRendered = 'rend', // bool (int32_t) 138 139 // The language code for this media 140 kKeyMediaLanguage = 'lang', // cstring 141 142 // To store the timed text format data 143 kKeyTextFormatData = 'text', // raw data 144 145 kKeyRequiresSecureBuffers = 'secu', // bool (int32_t) 146 147 kKeyIsADTS = 'adts', // bool (int32_t) 148 kKeyAACAOT = 'aaot', // int32_t 149 150 // If a MediaBuffer's data represents (at least partially) encrypted 151 // data, the following fields aid in decryption. 152 // The data can be thought of as pairs of plain and encrypted data 153 // fragments, i.e. plain and encrypted data alternate. 154 // The first fragment is by convention plain data (if that's not the 155 // case, simply specify plain fragment size of 0). 156 // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of 157 // size_t values. The sum total of all size_t values of both arrays 158 // must equal the amount of data (i.e. MediaBuffer's range_length()). 159 // If both arrays are present, they must be of the same size. 160 // If only encrypted sizes are present it is assumed that all 161 // plain sizes are 0, i.e. all fragments are encrypted. 162 // To programmatically set these array, use the MetaData::setData API, i.e. 163 // const size_t encSizes[]; 164 // meta->setData( 165 // kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes)); 166 // A plain sizes array by itself makes no sense. 167 kKeyEncryptedSizes = 'encr', // size_t[] 168 kKeyPlainSizes = 'plai', // size_t[] 169 kKeyCryptoKey = 'cryK', // uint8_t[16] 170 kKeyCryptoIV = 'cryI', // uint8_t[16] 171 kKeyCryptoMode = 'cryM', // int32_t 172 173 kKeyCryptoDefaultIVSize = 'cryS', // int32_t 174 175 kKeyPssh = 'pssh', // raw data 176 177 // Please see MediaFormat.KEY_IS_AUTOSELECT. 178 kKeyTrackIsAutoselect = 'auto', // bool (int32_t) 179 // Please see MediaFormat.KEY_IS_DEFAULT. 180 kKeyTrackIsDefault = 'dflt', // bool (int32_t) 181 // Similar to MediaFormat.KEY_IS_FORCED_SUBTITLE but pertains to av tracks as well. 182 kKeyTrackIsForced = 'frcd', // bool (int32_t) 183 184 // H264 supplemental enhancement information offsets/sizes 185 kKeySEI = 'sei ', // raw data 186 187 // MPEG user data offsets 188 kKeyMpegUserData = 'mpud', // size_t[] 189 190 // Size of NALU length in mkv/mp4 191 kKeyNalLengthSize = 'nals', // int32_t 192 193 // HDR related 194 kKeyMinLuminance = 'minL', // int32_t, min luminance of the content in cd/m2. 195 kKeyMaxLuminance = 'maxL', // int32_t, max luminance of the content in cd/m2. 196 197 // color aspects 198 kKeyColorRange = 'cRng', // int32_t, color range, value defined by ColorAspects.Range 199 kKeyColorPrimaries = 'cPrm', // int32_t, 200 // color Primaries, value defined by ColorAspects.Primaries 201 kKeyTransferFunction = 'tFun', // int32_t, 202 // transfer Function, value defined by ColorAspects.Transfer. 203 kKeyColorMatrix = 'cMtx', // int32_t, 204 // color Matrix, value defined by ColorAspects.MatrixCoeffs. 205}; 206 207enum { 208 kTypeESDS = 'esds', 209 kTypeAVCC = 'avcc', 210 kTypeHVCC = 'hvcc', 211 kTypeD263 = 'd263', 212}; 213 214class MetaData : public RefBase { 215public: 216 MetaData(); 217 MetaData(const MetaData &from); 218 219 enum Type { 220 TYPE_NONE = 'none', 221 TYPE_C_STRING = 'cstr', 222 TYPE_INT32 = 'in32', 223 TYPE_INT64 = 'in64', 224 TYPE_FLOAT = 'floa', 225 TYPE_POINTER = 'ptr ', 226 TYPE_RECT = 'rect', 227 }; 228 229 void clear(); 230 bool remove(uint32_t key); 231 232 bool setCString(uint32_t key, const char *value); 233 bool setInt32(uint32_t key, int32_t value); 234 bool setInt64(uint32_t key, int64_t value); 235 bool setFloat(uint32_t key, float value); 236 bool setPointer(uint32_t key, void *value); 237 238 bool setRect( 239 uint32_t key, 240 int32_t left, int32_t top, 241 int32_t right, int32_t bottom); 242 243 bool findCString(uint32_t key, const char **value); 244 bool findInt32(uint32_t key, int32_t *value); 245 bool findInt64(uint32_t key, int64_t *value); 246 bool findFloat(uint32_t key, float *value); 247 bool findPointer(uint32_t key, void **value); 248 249 bool findRect( 250 uint32_t key, 251 int32_t *left, int32_t *top, 252 int32_t *right, int32_t *bottom); 253 254 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 255 256 bool findData(uint32_t key, uint32_t *type, 257 const void **data, size_t *size) const; 258 259 bool hasData(uint32_t key) const; 260 261 void dumpToLog() const; 262 263 status_t writeToParcel(Parcel &parcel); 264 status_t updateFromParcel(const Parcel &parcel); 265 static sp<MetaData> createFromParcel(const Parcel &parcel); 266 267protected: 268 virtual ~MetaData(); 269 270private: 271 struct typed_data { 272 typed_data(); 273 ~typed_data(); 274 275 typed_data(const MetaData::typed_data &); 276 typed_data &operator=(const MetaData::typed_data &); 277 278 void clear(); 279 void setData(uint32_t type, const void *data, size_t size); 280 void getData(uint32_t *type, const void **data, size_t *size) const; 281 String8 asString() const; 282 283 private: 284 uint32_t mType; 285 size_t mSize; 286 287 union { 288 void *ext_data; 289 float reservoir; 290 } u; 291 292 bool usesReservoir() const { 293 return mSize <= sizeof(u.reservoir); 294 } 295 296 void *allocateStorage(size_t size); 297 void freeStorage(); 298 299 void *storage() { 300 return usesReservoir() ? &u.reservoir : u.ext_data; 301 } 302 303 const void *storage() const { 304 return usesReservoir() ? &u.reservoir : u.ext_data; 305 } 306 }; 307 308 struct Rect { 309 int32_t mLeft, mTop, mRight, mBottom; 310 }; 311 312 KeyedVector<uint32_t, typed_data> mItems; 313 314 // MetaData &operator=(const MetaData &); 315}; 316 317} // namespace android 318 319#endif // META_DATA_H_ 320