Home | History | Annotate | Download | only in include
      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 MPEG4_EXTRACTOR_H_
     18 
     19 #define MPEG4_EXTRACTOR_H_
     20 
     21 #include <arpa/inet.h>
     22 
     23 #include <media/stagefright/DataSource.h>
     24 #include <media/stagefright/MediaExtractor.h>
     25 #include <media/stagefright/Utils.h>
     26 #include <utils/List.h>
     27 #include <utils/Vector.h>
     28 #include <utils/String8.h>
     29 
     30 namespace android {
     31 
     32 struct AMessage;
     33 class DataSource;
     34 class SampleTable;
     35 class String8;
     36 
     37 struct SidxEntry {
     38     size_t mSize;
     39     uint32_t mDurationUs;
     40 };
     41 
     42 class MPEG4Extractor : public MediaExtractor {
     43 public:
     44     // Extractor assumes ownership of "source".
     45     MPEG4Extractor(const sp<DataSource> &source);
     46 
     47     virtual size_t countTracks();
     48     virtual sp<MediaSource> getTrack(size_t index);
     49     virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
     50 
     51     virtual sp<MetaData> getMetaData();
     52     virtual uint32_t flags() const;
     53 
     54     // for DRM
     55     virtual char* getDrmTrackInfo(size_t trackID, int *len);
     56 
     57 protected:
     58     virtual ~MPEG4Extractor();
     59 
     60 private:
     61 
     62     struct PsshInfo {
     63         uint8_t uuid[16];
     64         uint32_t datalen;
     65         uint8_t *data;
     66     };
     67     struct Track {
     68         Track *next;
     69         sp<MetaData> meta;
     70         uint32_t timescale;
     71         sp<SampleTable> sampleTable;
     72         bool includes_expensive_metadata;
     73         bool skipTrack;
     74     };
     75 
     76     Vector<SidxEntry> mSidxEntries;
     77     uint64_t mSidxDuration;
     78     off64_t mMoofOffset;
     79 
     80     Vector<PsshInfo> mPssh;
     81 
     82     sp<DataSource> mDataSource;
     83     status_t mInitCheck;
     84     bool mHasVideo;
     85     uint32_t mHeaderTimescale;
     86 
     87     Track *mFirstTrack, *mLastTrack;
     88 
     89     sp<MetaData> mFileMetaData;
     90 
     91     Vector<uint32_t> mPath;
     92     String8 mLastCommentMean;
     93     String8 mLastCommentName;
     94     String8 mLastCommentData;
     95 
     96     status_t readMetaData();
     97     status_t parseChunk(off64_t *offset, int depth);
     98     status_t parseMetaData(off64_t offset, size_t size);
     99 
    100     status_t updateAudioTrackInfoFromESDS_MPEG4Audio(
    101             const void *esds_data, size_t esds_size);
    102 
    103     static status_t verifyTrack(Track *track);
    104 
    105     struct SINF {
    106         SINF *next;
    107         uint16_t trackID;
    108         uint8_t IPMPDescriptorID;
    109         ssize_t len;
    110         char *IPMPData;
    111     };
    112 
    113     SINF *mFirstSINF;
    114 
    115     bool mIsDrm;
    116     status_t parseDrmSINF(off64_t *offset, off64_t data_offset);
    117 
    118     status_t parseTrackHeader(off64_t data_offset, off64_t data_size);
    119 
    120     status_t parseSegmentIndex(off64_t data_offset, size_t data_size);
    121 
    122     Track *findTrackByMimePrefix(const char *mimePrefix);
    123 
    124     MPEG4Extractor(const MPEG4Extractor &);
    125     MPEG4Extractor &operator=(const MPEG4Extractor &);
    126 };
    127 
    128 bool SniffMPEG4(
    129         const sp<DataSource> &source, String8 *mimeType, float *confidence,
    130         sp<AMessage> *);
    131 
    132 }  // namespace android
    133 
    134 #endif  // MPEG4_EXTRACTOR_H_
    135