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 
     86     Track *mFirstTrack, *mLastTrack;
     87 
     88     sp<MetaData> mFileMetaData;
     89 
     90     Vector<uint32_t> mPath;
     91     String8 mLastCommentMean;
     92     String8 mLastCommentName;
     93     String8 mLastCommentData;
     94 
     95     status_t readMetaData();
     96     status_t parseChunk(off64_t *offset, int depth);
     97     status_t parseMetaData(off64_t offset, size_t size);
     98 
     99     status_t updateAudioTrackInfoFromESDS_MPEG4Audio(
    100             const void *esds_data, size_t esds_size);
    101 
    102     static status_t verifyTrack(Track *track);
    103 
    104     struct SINF {
    105         SINF *next;
    106         uint16_t trackID;
    107         uint8_t IPMPDescriptorID;
    108         ssize_t len;
    109         char *IPMPData;
    110     };
    111 
    112     SINF *mFirstSINF;
    113 
    114     bool mIsDrm;
    115     status_t parseDrmSINF(off64_t *offset, off64_t data_offset);
    116 
    117     status_t parseTrackHeader(off64_t data_offset, off64_t data_size);
    118 
    119     status_t parseSegmentIndex(off64_t data_offset, size_t data_size);
    120 
    121     Track *findTrackByMimePrefix(const char *mimePrefix);
    122 
    123     MPEG4Extractor(const MPEG4Extractor &);
    124     MPEG4Extractor &operator=(const MPEG4Extractor &);
    125 };
    126 
    127 bool SniffMPEG4(
    128         const sp<DataSource> &source, String8 *mimeType, float *confidence,
    129         sp<AMessage> *);
    130 
    131 }  // namespace android
    132 
    133 #endif  // MPEG4_EXTRACTOR_H_
    134