Home | History | Annotate | Download | only in stagefright
      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     kKeyAV1C              = 'av1c',  // raw data
     63     kKeyThumbnailHVCC     = 'thvc',  // raw data
     64     kKeyD263              = 'd263',  // 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     kKeyVp9CodecPrivate   = 'vp9p',  // raw data (vp9 csd information)
     69     kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
     70     kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
     71     kKeyIsMuxerData       = 'muxd',  // int32_t (bool)
     72     kKeyTime              = 'time',  // int64_t (usecs)
     73     kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
     74     kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
     75     kKeyTargetTime        = 'tarT',  // int64_t (usecs)
     76     kKeyDriftTime         = 'dftT',  // int64_t (usecs)
     77     kKeyAnchorTime        = 'ancT',  // int64_t (usecs)
     78     kKeyDuration          = 'dura',  // int64_t (usecs)
     79     kKeyPixelFormat       = 'pixf',  // int32_t
     80     kKeyColorFormat       = 'colf',  // int32_t
     81     kKeyColorSpace        = 'cols',  // int32_t
     82     kKeyPlatformPrivate   = 'priv',  // pointer
     83     kKeyDecoderComponent  = 'decC',  // cstring
     84     kKeyBufferID          = 'bfID',
     85     kKeyMaxInputSize      = 'inpS',
     86     kKeyMaxWidth          = 'maxW',
     87     kKeyMaxHeight         = 'maxH',
     88     kKeyThumbnailTime     = 'thbT',  // int64_t (usecs)
     89     kKeyTrackID           = 'trID',
     90     kKeyEncoderDelay      = 'encd',  // int32_t (frames)
     91     kKeyEncoderPadding    = 'encp',  // int32_t (frames)
     92 
     93     kKeyAlbum             = 'albu',  // cstring
     94     kKeyArtist            = 'arti',  // cstring
     95     kKeyAlbumArtist       = 'aart',  // cstring
     96     kKeyComposer          = 'comp',  // cstring
     97     kKeyGenre             = 'genr',  // cstring
     98     kKeyTitle             = 'titl',  // cstring
     99     kKeyYear              = 'year',  // cstring
    100     kKeyAlbumArt          = 'albA',  // compressed image data
    101     kKeyAuthor            = 'auth',  // cstring
    102     kKeyCDTrackNumber     = 'cdtr',  // cstring
    103     kKeyDiscNumber        = 'dnum',  // cstring
    104     kKeyDate              = 'date',  // cstring
    105     kKeyWriter            = 'writ',  // cstring
    106     kKeyCompilation       = 'cpil',  // cstring
    107     kKeyLocation          = 'loc ',  // cstring
    108     kKeyTimeScale         = 'tmsl',  // int32_t
    109     kKeyCaptureFramerate  = 'capF',  // float (capture fps)
    110 
    111     // video profile and level
    112     kKeyVideoProfile      = 'vprf',  // int32_t
    113     kKeyVideoLevel        = 'vlev',  // int32_t
    114 
    115     // Set this key to enable authoring files in 64-bit offset
    116     kKey64BitFileOffset   = 'fobt',  // int32_t (bool)
    117     kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
    118 
    119     // Identify the file output format for authoring
    120     // Please see <media/mediarecorder.h> for the supported
    121     // file output formats.
    122     kKeyFileType          = 'ftyp',  // int32_t
    123 
    124     // Track authoring progress status
    125     // kKeyTrackTimeStatus is used to track progress in elapsed time
    126     kKeyTrackTimeStatus   = 'tktm',  // int64_t
    127 
    128     kKeyRealTimeRecording = 'rtrc',  // bool (int32_t)
    129     kKeyNumBuffers        = 'nbbf',  // int32_t
    130 
    131     // Ogg files can be tagged to be automatically looping...
    132     kKeyAutoLoop          = 'autL',  // bool (int32_t)
    133 
    134     kKeyValidSamples      = 'valD',  // int32_t
    135 
    136     kKeyIsUnreadable      = 'unre',  // bool (int32_t)
    137 
    138     // An indication that a video buffer has been rendered.
    139     kKeyRendered          = 'rend',  // bool (int32_t)
    140 
    141     // The language code for this media
    142     kKeyMediaLanguage     = 'lang',  // cstring
    143 
    144     // The manufacturer code for this media
    145     kKeyManufacturer  = 'manu',  // cstring
    146 
    147     // To store the timed text format data
    148     kKeyTextFormatData    = 'text',  // raw data
    149 
    150     kKeyRequiresSecureBuffers = 'secu',  // bool (int32_t)
    151 
    152     kKeyIsADTS            = 'adts',  // bool (int32_t)
    153     kKeyAACAOT            = 'aaot',  // int32_t
    154 
    155     // If a MediaBuffer's data represents (at least partially) encrypted
    156     // data, the following fields aid in decryption.
    157     // The data can be thought of as pairs of plain and encrypted data
    158     // fragments, i.e. plain and encrypted data alternate.
    159     // The first fragment is by convention plain data (if that's not the
    160     // case, simply specify plain fragment size of 0).
    161     // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of
    162     // size_t values. The sum total of all size_t values of both arrays
    163     // must equal the amount of data (i.e. MediaBuffer's range_length()).
    164     // If both arrays are present, they must be of the same size.
    165     // If only encrypted sizes are present it is assumed that all
    166     // plain sizes are 0, i.e. all fragments are encrypted.
    167     // To programmatically set these array, use the MetaDataBase::setData API, i.e.
    168     // const size_t encSizes[];
    169     // meta->setData(
    170     //  kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes));
    171     // A plain sizes array by itself makes no sense.
    172     kKeyEncryptedSizes    = 'encr',  // size_t[]
    173     kKeyPlainSizes        = 'plai',  // size_t[]
    174     kKeyCryptoKey         = 'cryK',  // uint8_t[16]
    175     kKeyCryptoIV          = 'cryI',  // uint8_t[16]
    176     kKeyCryptoMode        = 'cryM',  // int32_t
    177 
    178     kKeyCryptoDefaultIVSize = 'cryS',  // int32_t
    179 
    180     kKeyPssh              = 'pssh',  // raw data
    181     kKeyCASystemID        = 'caid',  // int32_t
    182     kKeyCASessionID       = 'seid',  // raw data
    183     kKeyCAPrivateData     = 'cadc',  // 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     // HDR related
    202     kKeyHdrStaticInfo    = 'hdrS', // HDRStaticInfo
    203     kKeyHdr10PlusInfo    = 'hdrD', // raw data
    204 
    205     // color aspects
    206     kKeyColorRange       = 'cRng', // int32_t, color range, value defined by ColorAspects.Range
    207     kKeyColorPrimaries   = 'cPrm', // int32_t,
    208                                    // color Primaries, value defined by ColorAspects.Primaries
    209     kKeyTransferFunction = 'tFun', // int32_t,
    210                                    // transfer Function, value defined by ColorAspects.Transfer.
    211     kKeyColorMatrix      = 'cMtx', // int32_t,
    212                                    // color Matrix, value defined by ColorAspects.MatrixCoeffs.
    213     kKeyTemporalLayerId  = 'iLyr', // int32_t, temporal layer-id. 0-based (0 => base layer)
    214     kKeyTemporalLayerCount = 'cLyr', // int32_t, number of temporal layers encoded
    215 
    216     kKeyTileWidth        = 'tilW', // int32_t, HEIF tile width
    217     kKeyTileHeight       = 'tilH', // int32_t, HEIF tile height
    218     kKeyGridRows         = 'grdR', // int32_t, HEIF grid rows
    219     kKeyGridCols         = 'grdC', // int32_t, HEIF grid columns
    220     kKeyIccProfile       = 'prof', // raw data, ICC profile data
    221     kKeyIsPrimaryImage   = 'prim', // bool (int32_t), image track is the primary image
    222     kKeyFrameCount       = 'nfrm', // int32_t, total number of frame in video track
    223     kKeyExifOffset       = 'exof', // int64_t, Exif data offset
    224     kKeyExifSize         = 'exsz', // int64_t, Exif data size
    225     kKeyExifTiffOffset   = 'thdr', // int32_t, if > 0, buffer contains exif data block with
    226                                    // tiff hdr at specified offset
    227     kKeyPcmBigEndian     = 'pcmb', // bool (int32_t)
    228 
    229     // Key for ALAC Magic Cookie
    230     kKeyAlacMagicCookie  = 'almc', // raw data
    231 
    232     // AC-4 AudioPresentationInfo
    233     kKeyAudioPresentationInfo = 'audP',  // raw data
    234 
    235     // opaque codec specific data being passed from extractor to codec
    236     kKeyOpaqueCSD0       = 'csd0',
    237     kKeyOpaqueCSD1       = 'csd1',
    238     kKeyOpaqueCSD2       = 'csd2',
    239 
    240     kKeyHapticChannelCount = 'hapC',
    241 };
    242 
    243 enum {
    244     kTypeESDS        = 'esds',
    245     kTypeAVCC        = 'avcc',
    246     kTypeHVCC        = 'hvcc',
    247     kTypeAV1C        = 'av1c',
    248     kTypeD263        = 'd263',
    249 };
    250 
    251 enum {
    252     kCryptoModeUnencrypted = 0,
    253     kCryptoModeAesCtr      = 1,
    254     kCryptoModeAesCbc      = 2,
    255 };
    256 
    257 class Parcel;
    258 
    259 class MetaDataBase {
    260 public:
    261     MetaDataBase();
    262     MetaDataBase(const MetaDataBase &from);
    263     MetaDataBase& operator = (const MetaDataBase &);
    264 
    265     virtual ~MetaDataBase();
    266 
    267     enum Type {
    268         TYPE_NONE     = 'none',
    269         TYPE_C_STRING = 'cstr',
    270         TYPE_INT32    = 'in32',
    271         TYPE_INT64    = 'in64',
    272         TYPE_FLOAT    = 'floa',
    273         TYPE_POINTER  = 'ptr ',
    274         TYPE_RECT     = 'rect',
    275     };
    276 
    277     void clear();
    278     bool remove(uint32_t key);
    279 
    280     bool setCString(uint32_t key, const char *value);
    281     bool setInt32(uint32_t key, int32_t value);
    282     bool setInt64(uint32_t key, int64_t value);
    283     bool setFloat(uint32_t key, float value);
    284     bool setPointer(uint32_t key, void *value);
    285 
    286     bool setRect(
    287             uint32_t key,
    288             int32_t left, int32_t top,
    289             int32_t right, int32_t bottom);
    290 
    291     bool findCString(uint32_t key, const char **value) const;
    292     bool findInt32(uint32_t key, int32_t *value) const;
    293     bool findInt64(uint32_t key, int64_t *value) const;
    294     bool findFloat(uint32_t key, float *value) const;
    295     bool findPointer(uint32_t key, void **value) const;
    296 
    297     bool findRect(
    298             uint32_t key,
    299             int32_t *left, int32_t *top,
    300             int32_t *right, int32_t *bottom) const;
    301 
    302     bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
    303 
    304     bool findData(uint32_t key, uint32_t *type,
    305                   const void **data, size_t *size) const;
    306 
    307     bool hasData(uint32_t key) const;
    308 
    309     String8 toString() const;
    310     void dumpToLog() const;
    311 
    312 private:
    313     friend class BpMediaSource;
    314     friend class BnMediaSource;
    315     friend class BnMediaExtractor;
    316     friend class MetaData;
    317 
    318     struct typed_data;
    319     struct Rect;
    320     struct MetaDataInternal;
    321     MetaDataInternal *mInternalData;
    322     status_t writeToParcel(Parcel &parcel);
    323     status_t updateFromParcel(const Parcel &parcel);
    324 };
    325 
    326 }  // namespace android
    327 
    328 #endif  // META_DATA_H_
    329