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 kKeyBitsPerSample = 'bits', // int32_t (bits per sample) 57 kKeyStreamHeader = 'stHd', // raw data 58 kKeyESDS = 'esds', // raw data 59 kKeyAACProfile = 'aacp', // int32_t 60 kKeyAVCC = 'avcc', // raw data 61 kKeyHVCC = 'hvcc', // raw data 62 kKeyDVCC = 'dvcc', // raw data 63 kKeyDVVC = 'dvvc', // raw data 64 kKeyDVWC = 'dvwc', // raw data 65 kKeyAV1C = 'av1c', // raw data 66 kKeyAPVC = 'apvc', // raw data 67 kKeyThumbnailHVCC = 'thvc', // raw data 68 kKeyThumbnailAV1C = 'tav1', // raw data 69 kKeyD263 = 'd263', // raw data 70 kKeyOpusHeader = 'ohdr', // raw data 71 kKeyOpusCodecDelay = 'ocod', // uint64_t (codec delay in ns) 72 kKeyOpusSeekPreRoll = 'ospr', // uint64_t (seek preroll in ns) 73 kKeyVp9CodecPrivate = 'vp9p', // raw data (vp9 csd information) 74 kKeyIsSyncFrame = 'sync', // int32_t (bool) 75 kKeyIsCodecConfig = 'conf', // int32_t (bool) 76 kKeyIsMuxerData = 'muxd', // int32_t (bool) 77 kKeyIsEndOfStream = 'feos', // int32_t (bool) 78 kKeyTime = 'time', // int64_t (usecs) 79 kKeyDecodingTime = 'decT', // int64_t (decoding timestamp in usecs) 80 kKeyNTPTime = 'ntpT', // uint64_t (ntp-timestamp) 81 kKeyTargetTime = 'tarT', // int64_t (usecs) 82 kKeyDriftTime = 'dftT', // int64_t (usecs) 83 kKeyAnchorTime = 'ancT', // int64_t (usecs) 84 kKeyDuration = 'dura', // int64_t (usecs) 85 kKeyPixelFormat = 'pixf', // int32_t 86 kKeyColorFormat = 'colf', // int32_t 87 kKeyColorSpace = 'cols', // int32_t 88 kKeyGainmap = 'gmap', // int32_t 89 kKeyPlatformPrivate = 'priv', // pointer 90 kKeyDecoderComponent = 'decC', // cstring 91 kKeyBufferID = 'bfID', 92 kKeyMaxInputSize = 'inpS', 93 kKeyMaxWidth = 'maxW', 94 kKeyMaxHeight = 'maxH', 95 kKeyThumbnailTime = 'thbT', // int64_t (usecs) 96 kKeyTrackID = 'trID', 97 kKeyEncoderDelay = 'encd', // int32_t (frames) 98 kKeyEncoderPadding = 'encp', // int32_t (frames) 99 100 kKeyAlbum = 'albu', // cstring 101 kKeyArtist = 'arti', // cstring 102 kKeyAlbumArtist = 'aart', // cstring 103 kKeyComposer = 'comp', // cstring 104 kKeyGenre = 'genr', // cstring 105 kKeyTitle = 'titl', // cstring 106 kKeyYear = 'year', // cstring 107 kKeyAlbumArt = 'albA', // compressed image data 108 kKeyAuthor = 'auth', // cstring 109 kKeyCDTrackNumber = 'cdtr', // cstring 110 kKeyDiscNumber = 'dnum', // cstring 111 kKeyDate = 'date', // cstring 112 kKeyWriter = 'writ', // cstring 113 kKeyCompilation = 'cpil', // cstring 114 kKeyLocation = 'loc ', // cstring 115 kKeyTimeScale = 'tmsl', // int32_t 116 kKeyCaptureFramerate = 'capF', // float (capture fps) 117 118 // video profile and level 119 kKeyVideoProfile = 'vprf', // int32_t 120 kKeyVideoLevel = 'vlev', // int32_t 121 122 // audio profile and level 123 // The codec framework doesn't distinguish between video and audio profiles, 124 // so there is no need to define a separate key 125 kKeyAudioProfile = 'vprf', // int32_t 126 kKeyAudioLevel = 'vlev', // int32_t 127 128 kKey2ByteNalLength = '2NAL', // int32_t (bool) 129 130 // Identify the file output format for authoring 131 // Please see <media/mediarecorder.h> for the supported 132 // file output formats. 133 kKeyFileType = 'ftyp', // int32_t 134 135 // Track authoring progress status 136 // kKeyTrackTimeStatus is used to track progress in elapsed time 137 kKeyTrackTimeStatus = 'tktm', // int64_t 138 139 kKeyRealTimeRecording = 'rtrc', // bool (int32_t) 140 kKeyBackgroundMode = 'bkmd', // bool (int32_t) 141 142 kKeyNumBuffers = 'nbbf', // int32_t 143 144 // Ogg files can be tagged to be automatically looping... 145 kKeyAutoLoop = 'autL', // bool (int32_t) 146 147 kKeyValidSamples = 'valD', // int32_t 148 149 kKeyIsUnreadable = 'unre', // bool (int32_t) 150 151 // An indication that a video buffer has been rendered. 152 kKeyRendered = 'rend', // bool (int32_t) 153 154 // The language code for this media 155 kKeyMediaLanguage = 'lang', // cstring 156 157 // The manufacturer code for this media 158 kKeyManufacturer = 'manu', // cstring 159 160 // To store the timed text format data 161 kKeyTextFormatData = 'text', // raw data 162 163 kKeyRequiresSecureBuffers = 'secu', // bool (int32_t) 164 165 kKeyIsADTS = 'adts', // bool (int32_t) 166 kKeyAACAOT = 'aaot', // int32_t 167 168 kKeyMpeghProfileLevelIndication = 'hpli', // int32_t 169 kKeyMpeghReferenceChannelLayout = 'hrcl', // int32_t 170 kKeyMpeghCompatibleSets = 'hcos', // raw data 171 172 // If a MediaBuffer's data represents (at least partially) encrypted 173 // data, the following fields aid in decryption. 174 // The data can be thought of as pairs of plain and encrypted data 175 // fragments, i.e. plain and encrypted data alternate. 176 // The first fragment is by convention plain data (if that's not the 177 // case, simply specify plain fragment size of 0). 178 // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of 179 // size_t values. The sum total of all size_t values of both arrays 180 // must equal the amount of data (i.e. MediaBuffer's range_length()). 181 // If both arrays are present, they must be of the same size. 182 // If only encrypted sizes are present it is assumed that all 183 // plain sizes are 0, i.e. all fragments are encrypted. 184 // To programmatically set these array, use the MetaDataBase::setData API, i.e. 185 // const size_t encSizes[]; 186 // meta->setData( 187 // kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes)); 188 // A plain sizes array by itself makes no sense. 189 kKeyEncryptedSizes = 'encr', // size_t[] 190 kKeyPlainSizes = 'plai', // size_t[] 191 kKeyCryptoKey = 'cryK', // uint8_t[16] 192 kKeyCryptoIV = 'cryI', // uint8_t[16] 193 kKeyCryptoMode = 'cryM', // int32_t 194 195 kKeyCryptoDefaultIVSize = 'cryS', // int32_t 196 197 kKeyPssh = 'pssh', // raw data 198 kKeyCASystemID = 'caid', // int32_t 199 kKeyCASessionID = 'seid', // raw data 200 kKeyCAPrivateData = 'cadc', // raw data 201 202 kKeyEncryptedByteBlock = 'cblk', // uint8_t 203 kKeySkipByteBlock = 'sblk', // uint8_t 204 205 // Please see MediaFormat.KEY_IS_AUTOSELECT. 206 kKeyTrackIsAutoselect = 'auto', // bool (int32_t) 207 // Please see MediaFormat.KEY_IS_DEFAULT. 208 kKeyTrackIsDefault = 'dflt', // bool (int32_t) 209 // Similar to MediaFormat.KEY_IS_FORCED_SUBTITLE but pertains to av tracks as well. 210 kKeyTrackIsForced = 'frcd', // bool (int32_t) 211 212 // H264 supplemental enhancement information offsets/sizes 213 kKeySEI = 'sei ', // raw data 214 215 // MPEG user data offsets 216 kKeyMpegUserData = 'mpud', // size_t[] 217 218 // HDR related 219 kKeyHdrStaticInfo = 'hdrS', // HDRStaticInfo 220 kKeyHdr10PlusInfo = 'hdrD', // raw data 221 222 // color aspects 223 kKeyColorRange = 'cRng', // int32_t, color range, value defined by ColorAspects.Range 224 kKeyColorPrimaries = 'cPrm', // int32_t, 225 // color Primaries, value defined by ColorAspects.Primaries 226 kKeyTransferFunction = 'tFun', // int32_t, 227 // transfer Function, value defined by ColorAspects.Transfer. 228 kKeyColorMatrix = 'cMtx', // int32_t, 229 // color Matrix, value defined by ColorAspects.MatrixCoeffs. 230 kKeyTemporalLayerId = 'iLyr', // int32_t, temporal layer-id. 0-based (0 => base layer) 231 kKeyTemporalLayerCount = 'cLyr', // int32_t, number of temporal layers encoded 232 233 kKeyTileWidth = 'tilW', // int32_t, HEIF tile width 234 kKeyTileHeight = 'tilH', // int32_t, HEIF tile height 235 kKeyGridRows = 'grdR', // int32_t, HEIF grid rows 236 kKeyGridCols = 'grdC', // int32_t, HEIF grid columns 237 kKeyIccProfile = 'prof', // raw data, ICC profile data 238 kKeyIsPrimaryImage = 'prim', // bool (int32_t), image track is the primary image 239 kKeyFrameCount = 'nfrm', // int32_t, total number of frame in video track 240 kKeyExifOffset = 'exof', // int64_t, Exif data offset 241 kKeyExifSize = 'exsz', // int64_t, Exif data size 242 kKeyExifTiffOffset = 'thdr', // int32_t, if > 0, buffer contains exif data block with 243 // tiff hdr at specified offset 244 kKeyXmpOffset = 'xmof', // int64_t, XMP data offset 245 kKeyXmpSize = 'xmsz', // int64_t, XMP data size 246 kKeyPcmBigEndian = 'pcmb', // bool (int32_t) 247 248 // Key for ALAC Magic Cookie 249 kKeyAlacMagicCookie = 'almc', // raw data 250 251 // AC-4 AudioPresentationInfo 252 kKeyAudioPresentationInfo = 'audP', // raw data 253 254 // opaque codec specific data being passed from extractor to codec 255 kKeyOpaqueCSD0 = 'csd0', 256 kKeyOpaqueCSD1 = 'csd1', 257 kKeyOpaqueCSD2 = 'csd2', 258 259 kKeyHapticChannelCount = 'hapC', 260 261 /* MediaRecorder.h, error notifications can represent track ids with 4 bits only. 262 * | track id | reserved | error or info type | 263 * 31 28 16 0 264 */ 265 kKey4BitTrackIds = '4bid', 266 267 // Treat empty track as malformed for MediaRecorder. 268 kKeyEmptyTrackMalFormed = 'nemt', // bool (int32_t) 269 270 kKeyVps = 'sVps', // int32_t, indicates that a buffer has vps. 271 kKeySps = 'sSps', // int32_t, indicates that a buffer has sps. 272 kKeyPps = 'sPps', // int32_t, indicates that a buffer has pps. 273 kKeySelfID = 'sfid', // int32_t, source ID to identify itself on RTP protocol. 274 kKeyPayloadType = 'pTyp', // int32_t, SDP negotiated payload type. 275 kKeyRtpExtMap = 'extm', // int32_t, rtp extension ID for cvo on RTP protocol. 276 kKeyRtpCvoDegrees = 'cvod', // int32_t, rtp cvo degrees as per 3GPP 26.114. 277 kKeyRtpDscp = 'dscp', // int32_t, DSCP(Differentiated services codepoint) of RFC 2474. 278 kKeyRtpEcn = 'sEcn', // int32_t, ECN (Explicit Congestion Notification) of RFC 3168 279 kKeySocketNetwork = 'sNet', // int64_t, socket will be bound to network handle. 280 281 // Slow-motion markers 282 kKeySlowMotionMarkers = 'slmo', // raw data, byte array following spec for 283 // MediaFormat#KEY_SLOW_MOTION_MARKERS 284 285 kKeySampleFileOffset = 'sfof', // int64_t, sample's offset in a media file. 286 kKeyLastSampleIndexInChunk = 'lsic', //int64_t, index of last sample in a chunk. 287 kKeySampleTimeBeforeAppend = 'lsba', // int64_t, timestamp of last sample of a track. 288 289 // DVB component tag 290 kKeyDvbComponentTag = 'copt', // int32_t, component tag for DVB video/audio/subtitle 291 292 // DVB audio description 293 kKeyDvbAudioDescription = 'addt', // bool (int32_t), DVB audio description only defined for 294 // audio component 295 296 // DVB teletext magazine number 297 kKeyDvbTeletextMagazineNumber = 'ttxm', // int32_t, DVB teletext magazine number 298 299 // DVB teletext page number 300 kKeyDvbTeletextPageNumber = 'ttxp', // int32_t, DVB teletext page number 301 }; 302 303 enum { 304 kTypeESDS = 'esds', 305 kTypeAVCC = 'avcc', 306 kTypeHVCC = 'hvcc', 307 kTypeAV1C = 'av1c', 308 kTypeDVCC = 'dvcc', 309 kTypeDVVC = 'dvvc', 310 kTypeDVWC = 'dvwc', 311 kTypeD263 = 'd263', 312 kTypeHCOS = 'hcos', 313 }; 314 315 enum { 316 kCryptoModeUnencrypted = 0, 317 kCryptoModeAesCtr = 1, 318 kCryptoModeAesCbc = 2, 319 }; 320 321 class Parcel; 322 323 class MetaDataBase { 324 public: 325 MetaDataBase(); 326 MetaDataBase(const MetaDataBase &from); 327 MetaDataBase& operator = (const MetaDataBase &); 328 329 virtual ~MetaDataBase(); 330 331 enum Type { 332 TYPE_NONE = 'none', 333 TYPE_C_STRING = 'cstr', 334 TYPE_INT32 = 'in32', 335 TYPE_INT64 = 'in64', 336 TYPE_FLOAT = 'floa', 337 TYPE_POINTER = 'ptr ', 338 TYPE_RECT = 'rect', 339 }; 340 341 void clear(); 342 bool remove(uint32_t key); 343 344 bool setCString(uint32_t key, const char *value); 345 bool setInt32(uint32_t key, int32_t value); 346 bool setInt64(uint32_t key, int64_t value); 347 bool setFloat(uint32_t key, float value); 348 bool setPointer(uint32_t key, void *value); 349 350 bool setRect( 351 uint32_t key, 352 int32_t left, int32_t top, 353 int32_t right, int32_t bottom); 354 355 bool findCString(uint32_t key, const char **value) const; 356 bool findInt32(uint32_t key, int32_t *value) const; 357 bool findInt64(uint32_t key, int64_t *value) const; 358 bool findFloat(uint32_t key, float *value) const; 359 bool findPointer(uint32_t key, void **value) const; 360 361 bool findRect( 362 uint32_t key, 363 int32_t *left, int32_t *top, 364 int32_t *right, int32_t *bottom) const; 365 366 bool setData(uint32_t key, uint32_t type, const void *data, size_t size); 367 368 bool findData(uint32_t key, uint32_t *type, 369 const void **data, size_t *size) const; 370 371 bool hasData(uint32_t key) const; 372 373 String8 toString() const; 374 void dumpToLog() const; 375 376 private: 377 friend class BpMediaSource; 378 friend class BnMediaSource; 379 friend class BnMediaExtractor; 380 friend class MetaData; 381 382 struct typed_data; 383 struct Rect; 384 struct MetaDataInternal; 385 MetaDataInternal *mInternalData; 386 #ifndef __ANDROID_VNDK__ 387 status_t writeToParcel(Parcel &parcel); 388 status_t updateFromParcel(const Parcel &parcel); 389 #endif 390 }; 391 392 } // namespace android 393 394 #endif // META_DATA_H_ 395