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