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 <media/stagefright/MediaExtractor.h>
     22 #include <utils/Vector.h>
     23 
     24 namespace android {
     25 
     26 struct AMessage;
     27 class DataSource;
     28 class SampleTable;
     29 class String8;
     30 
     31 class MPEG4Extractor : public MediaExtractor {
     32 public:
     33     // Extractor assumes ownership of "source".
     34     MPEG4Extractor(const sp<DataSource> &source);
     35 
     36     virtual size_t countTracks();
     37     virtual sp<MediaSource> getTrack(size_t index);
     38     virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
     39 
     40     virtual sp<MetaData> getMetaData();
     41 
     42     // for DRM
     43     virtual char* getDrmTrackInfo(size_t trackID, int *len);
     44 
     45 protected:
     46     virtual ~MPEG4Extractor();
     47 
     48 private:
     49     struct Track {
     50         Track *next;
     51         sp<MetaData> meta;
     52         uint32_t timescale;
     53         sp<SampleTable> sampleTable;
     54         bool includes_expensive_metadata;
     55         bool skipTrack;
     56     };
     57 
     58     sp<DataSource> mDataSource;
     59     status_t mInitCheck;
     60     bool mHasVideo;
     61 
     62     Track *mFirstTrack, *mLastTrack;
     63 
     64     sp<MetaData> mFileMetaData;
     65 
     66     Vector<uint32_t> mPath;
     67 
     68     status_t readMetaData();
     69     status_t parseChunk(off64_t *offset, int depth);
     70     status_t parseMetaData(off64_t offset, size_t size);
     71 
     72     status_t updateAudioTrackInfoFromESDS_MPEG4Audio(
     73             const void *esds_data, size_t esds_size);
     74 
     75     static status_t verifyTrack(Track *track);
     76 
     77     struct SINF {
     78         SINF *next;
     79         uint16_t trackID;
     80         uint8_t IPMPDescriptorID;
     81         ssize_t len;
     82         char *IPMPData;
     83     };
     84 
     85     SINF *mFirstSINF;
     86 
     87     bool mIsDrm;
     88     status_t parseDrmSINF(off64_t *offset, off64_t data_offset);
     89 
     90     status_t parseTrackHeader(off64_t data_offset, off64_t data_size);
     91 
     92     Track *findTrackByMimePrefix(const char *mimePrefix);
     93 
     94     MPEG4Extractor(const MPEG4Extractor &);
     95     MPEG4Extractor &operator=(const MPEG4Extractor &);
     96 };
     97 
     98 bool SniffMPEG4(
     99         const sp<DataSource> &source, String8 *mimeType, float *confidence,
    100         sp<AMessage> *);
    101 
    102 }  // namespace android
    103 
    104 #endif  // MPEG4_EXTRACTOR_H_
    105