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 <utils/RefBase.h>
     26 #include <utils/KeyedVector.h>
     27 #include <utils/String8.h>
     28 
     29 namespace android {
     30 
     31 // The following keys map to int32_t data unless indicated otherwise.
     32 enum {
     33     kKeyMIMEType          = 'mime',  // cstring
     34     kKeyWidth             = 'widt',  // int32_t, image pixel
     35     kKeyHeight            = 'heig',  // int32_t, image pixel
     36     kKeyDisplayWidth      = 'dWid',  // int32_t, display/presentation
     37     kKeyDisplayHeight     = 'dHgt',  // int32_t, display/presentation
     38     kKeySARWidth          = 'sarW',  // int32_t, sampleAspectRatio width
     39     kKeySARHeight         = 'sarH',  // int32_t, sampleAspectRatio height
     40 
     41     // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1)
     42     kKeyCropRect          = 'crop',
     43 
     44     kKeyRotation          = 'rotA',  // int32_t (angle in degrees)
     45     kKeyIFramesInterval   = 'ifiv',  // int32_t
     46     kKeyStride            = 'strd',  // int32_t
     47     kKeySliceHeight       = 'slht',  // int32_t
     48     kKeyChannelCount      = '#chn',  // int32_t
     49     kKeyChannelMask       = 'chnm',  // int32_t
     50     kKeySampleRate        = 'srte',  // int32_t (audio sampling rate Hz)
     51     kKeyFrameRate         = 'frmR',  // int32_t (video frame rate fps)
     52     kKeyBitRate           = 'brte',  // int32_t (bps)
     53     kKeyESDS              = 'esds',  // raw data
     54     kKeyAACProfile        = 'aacp',  // int32_t
     55     kKeyAVCC              = 'avcc',  // raw data
     56     kKeyHVCC              = 'hvcc',  // raw data
     57     kKeyD263              = 'd263',  // raw data
     58     kKeyVorbisInfo        = 'vinf',  // raw data
     59     kKeyVorbisBooks       = 'vboo',  // raw data
     60     kKeyOpusHeader        = 'ohdr',  // raw data
     61     kKeyOpusCodecDelay    = 'ocod',  // uint64_t (codec delay in ns)
     62     kKeyOpusSeekPreRoll   = 'ospr',  // uint64_t (seek preroll in ns)
     63     kKeyWantsNALFragments = 'NALf',
     64     kKeyIsSyncFrame       = 'sync',  // int32_t (bool)
     65     kKeyIsCodecConfig     = 'conf',  // int32_t (bool)
     66     kKeyTime              = 'time',  // int64_t (usecs)
     67     kKeyDecodingTime      = 'decT',  // int64_t (decoding timestamp in usecs)
     68     kKeyNTPTime           = 'ntpT',  // uint64_t (ntp-timestamp)
     69     kKeyTargetTime        = 'tarT',  // int64_t (usecs)
     70     kKeyDriftTime         = 'dftT',  // int64_t (usecs)
     71     kKeyAnchorTime        = 'ancT',  // int64_t (usecs)
     72     kKeyDuration          = 'dura',  // int64_t (usecs)
     73     kKeyColorFormat       = 'colf',
     74     kKeyPlatformPrivate   = 'priv',  // pointer
     75     kKeyDecoderComponent  = 'decC',  // cstring
     76     kKeyBufferID          = 'bfID',
     77     kKeyMaxInputSize      = 'inpS',
     78     kKeyThumbnailTime     = 'thbT',  // int64_t (usecs)
     79     kKeyTrackID           = 'trID',
     80     kKeyIsDRM             = 'idrm',  // int32_t (bool)
     81     kKeyEncoderDelay      = 'encd',  // int32_t (frames)
     82     kKeyEncoderPadding    = 'encp',  // int32_t (frames)
     83 
     84     kKeyAlbum             = 'albu',  // cstring
     85     kKeyArtist            = 'arti',  // cstring
     86     kKeyAlbumArtist       = 'aart',  // cstring
     87     kKeyComposer          = 'comp',  // cstring
     88     kKeyGenre             = 'genr',  // cstring
     89     kKeyTitle             = 'titl',  // cstring
     90     kKeyYear              = 'year',  // cstring
     91     kKeyAlbumArt          = 'albA',  // compressed image data
     92     kKeyAlbumArtMIME      = 'alAM',  // cstring
     93     kKeyAuthor            = 'auth',  // cstring
     94     kKeyCDTrackNumber     = 'cdtr',  // cstring
     95     kKeyDiscNumber        = 'dnum',  // cstring
     96     kKeyDate              = 'date',  // cstring
     97     kKeyWriter            = 'writ',  // cstring
     98     kKeyCompilation       = 'cpil',  // cstring
     99     kKeyLocation          = 'loc ',  // cstring
    100     kKeyTimeScale         = 'tmsl',  // int32_t
    101 
    102     // video profile and level
    103     kKeyVideoProfile      = 'vprf',  // int32_t
    104     kKeyVideoLevel        = 'vlev',  // int32_t
    105 
    106     // Set this key to enable authoring files in 64-bit offset
    107     kKey64BitFileOffset   = 'fobt',  // int32_t (bool)
    108     kKey2ByteNalLength    = '2NAL',  // int32_t (bool)
    109 
    110     // Identify the file output format for authoring
    111     // Please see <media/mediarecorder.h> for the supported
    112     // file output formats.
    113     kKeyFileType          = 'ftyp',  // int32_t
    114 
    115     // Track authoring progress status
    116     // kKeyTrackTimeStatus is used to track progress in elapsed time
    117     kKeyTrackTimeStatus   = 'tktm',  // int64_t
    118 
    119     kKeyRealTimeRecording = 'rtrc',  // bool (int32_t)
    120     kKeyNumBuffers        = 'nbbf',  // int32_t
    121 
    122     // Ogg files can be tagged to be automatically looping...
    123     kKeyAutoLoop          = 'autL',  // bool (int32_t)
    124 
    125     kKeyValidSamples      = 'valD',  // int32_t
    126 
    127     kKeyIsUnreadable      = 'unre',  // bool (int32_t)
    128 
    129     // An indication that a video buffer has been rendered.
    130     kKeyRendered          = 'rend',  // bool (int32_t)
    131 
    132     // The language code for this media
    133     kKeyMediaLanguage     = 'lang',  // cstring
    134 
    135     // To store the timed text format data
    136     kKeyTextFormatData    = 'text',  // raw data
    137 
    138     kKeyRequiresSecureBuffers = 'secu',  // bool (int32_t)
    139 
    140     kKeyIsADTS            = 'adts',  // bool (int32_t)
    141     kKeyAACAOT            = 'aaot',  // int32_t
    142 
    143     // If a MediaBuffer's data represents (at least partially) encrypted
    144     // data, the following fields aid in decryption.
    145     // The data can be thought of as pairs of plain and encrypted data
    146     // fragments, i.e. plain and encrypted data alternate.
    147     // The first fragment is by convention plain data (if that's not the
    148     // case, simply specify plain fragment size of 0).
    149     // kKeyEncryptedSizes and kKeyPlainSizes each map to an array of
    150     // size_t values. The sum total of all size_t values of both arrays
    151     // must equal the amount of data (i.e. MediaBuffer's range_length()).
    152     // If both arrays are present, they must be of the same size.
    153     // If only encrypted sizes are present it is assumed that all
    154     // plain sizes are 0, i.e. all fragments are encrypted.
    155     // To programmatically set these array, use the MetaData::setData API, i.e.
    156     // const size_t encSizes[];
    157     // meta->setData(
    158     //  kKeyEncryptedSizes, 0 /* type */, encSizes, sizeof(encSizes));
    159     // A plain sizes array by itself makes no sense.
    160     kKeyEncryptedSizes    = 'encr',  // size_t[]
    161     kKeyPlainSizes        = 'plai',  // size_t[]
    162     kKeyCryptoKey         = 'cryK',  // uint8_t[16]
    163     kKeyCryptoIV          = 'cryI',  // uint8_t[16]
    164     kKeyCryptoMode        = 'cryM',  // int32_t
    165 
    166     kKeyCryptoDefaultIVSize = 'cryS',  // int32_t
    167 
    168     kKeyPssh              = 'pssh',  // raw data
    169 
    170     // Please see MediaFormat.KEY_IS_AUTOSELECT.
    171     kKeyTrackIsAutoselect = 'auto', // bool (int32_t)
    172     // Please see MediaFormat.KEY_IS_DEFAULT.
    173     kKeyTrackIsDefault    = 'dflt', // bool (int32_t)
    174     // Similar to MediaFormat.KEY_IS_FORCED_SUBTITLE but pertains to av tracks as well.
    175     kKeyTrackIsForced     = 'frcd', // bool (int32_t)
    176 };
    177 
    178 enum {
    179     kTypeESDS        = 'esds',
    180     kTypeAVCC        = 'avcc',
    181     kTypeHVCC        = 'hvcc',
    182     kTypeD263        = 'd263',
    183 };
    184 
    185 class MetaData : public RefBase {
    186 public:
    187     MetaData();
    188     MetaData(const MetaData &from);
    189 
    190     enum Type {
    191         TYPE_NONE     = 'none',
    192         TYPE_C_STRING = 'cstr',
    193         TYPE_INT32    = 'in32',
    194         TYPE_INT64    = 'in64',
    195         TYPE_FLOAT    = 'floa',
    196         TYPE_POINTER  = 'ptr ',
    197         TYPE_RECT     = 'rect',
    198     };
    199 
    200     void clear();
    201     bool remove(uint32_t key);
    202 
    203     bool setCString(uint32_t key, const char *value);
    204     bool setInt32(uint32_t key, int32_t value);
    205     bool setInt64(uint32_t key, int64_t value);
    206     bool setFloat(uint32_t key, float value);
    207     bool setPointer(uint32_t key, void *value);
    208 
    209     bool setRect(
    210             uint32_t key,
    211             int32_t left, int32_t top,
    212             int32_t right, int32_t bottom);
    213 
    214     bool findCString(uint32_t key, const char **value);
    215     bool findInt32(uint32_t key, int32_t *value);
    216     bool findInt64(uint32_t key, int64_t *value);
    217     bool findFloat(uint32_t key, float *value);
    218     bool findPointer(uint32_t key, void **value);
    219 
    220     bool findRect(
    221             uint32_t key,
    222             int32_t *left, int32_t *top,
    223             int32_t *right, int32_t *bottom);
    224 
    225     bool setData(uint32_t key, uint32_t type, const void *data, size_t size);
    226 
    227     bool findData(uint32_t key, uint32_t *type,
    228                   const void **data, size_t *size) const;
    229 
    230     bool hasData(uint32_t key) const;
    231 
    232     void dumpToLog() const;
    233 
    234 protected:
    235     virtual ~MetaData();
    236 
    237 private:
    238     struct typed_data {
    239         typed_data();
    240         ~typed_data();
    241 
    242         typed_data(const MetaData::typed_data &);
    243         typed_data &operator=(const MetaData::typed_data &);
    244 
    245         void clear();
    246         void setData(uint32_t type, const void *data, size_t size);
    247         void getData(uint32_t *type, const void **data, size_t *size) const;
    248         String8 asString() const;
    249 
    250     private:
    251         uint32_t mType;
    252         size_t mSize;
    253 
    254         union {
    255             void *ext_data;
    256             float reservoir;
    257         } u;
    258 
    259         bool usesReservoir() const {
    260             return mSize <= sizeof(u.reservoir);
    261         }
    262 
    263         void allocateStorage(size_t size);
    264         void freeStorage();
    265 
    266         void *storage() {
    267             return usesReservoir() ? &u.reservoir : u.ext_data;
    268         }
    269 
    270         const void *storage() const {
    271             return usesReservoir() ? &u.reservoir : u.ext_data;
    272         }
    273     };
    274 
    275     struct Rect {
    276         int32_t mLeft, mTop, mRight, mBottom;
    277     };
    278 
    279     KeyedVector<uint32_t, typed_data> mItems;
    280 
    281     // MetaData &operator=(const MetaData &);
    282 };
    283 
    284 }  // namespace android
    285 
    286 #endif  // META_DATA_H_
    287