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