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