MPEG4Extractor.h revision b486b52b2b67961073677d583a02269cbdc9a3fc
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/DataSourceBase.h> 24#include <media/MediaExtractor.h> 25#include <media/stagefright/MetaDataBase.h> 26#include <media/stagefright/foundation/AString.h> 27#include <utils/KeyedVector.h> 28#include <utils/List.h> 29#include <utils/String8.h> 30#include <utils/Vector.h> 31 32namespace android { 33struct AMessage; 34class DataSourceBase; 35struct CachedRangedDataSource; 36class SampleTable; 37class String8; 38namespace heif { 39class ItemTable; 40} 41using heif::ItemTable; 42 43struct SidxEntry { 44 size_t mSize; 45 uint32_t mDurationUs; 46}; 47 48struct Trex { 49 uint32_t track_ID; 50 uint32_t default_sample_description_index; 51 uint32_t default_sample_duration; 52 uint32_t default_sample_size; 53 uint32_t default_sample_flags; 54}; 55 56class MPEG4Extractor : public MediaExtractor { 57public: 58 explicit MPEG4Extractor(DataSourceBase *source, const char *mime = NULL); 59 60 virtual size_t countTracks(); 61 virtual MediaTrack *getTrack(size_t index); 62 virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags); 63 64 virtual status_t getMetaData(MetaDataBase& meta); 65 virtual uint32_t flags() const; 66 virtual const char * name() { return "MPEG4Extractor"; } 67 68protected: 69 virtual ~MPEG4Extractor(); 70 71private: 72 73 struct PsshInfo { 74 uint8_t uuid[16]; 75 uint32_t datalen; 76 uint8_t *data; 77 }; 78 struct Track { 79 Track *next; 80 MetaDataBase meta; 81 uint32_t timescale; 82 sp<SampleTable> sampleTable; 83 bool includes_expensive_metadata; 84 bool skipTrack; 85 bool has_elst; 86 int64_t elst_media_time; 87 uint64_t elst_segment_duration; 88 }; 89 90 Vector<SidxEntry> mSidxEntries; 91 off64_t mMoofOffset; 92 bool mMoofFound; 93 bool mMdatFound; 94 95 Vector<PsshInfo> mPssh; 96 97 Vector<Trex> mTrex; 98 99 DataSourceBase *mDataSource; 100 CachedRangedDataSource *mCachedSource; 101 status_t mInitCheck; 102 uint32_t mHeaderTimescale; 103 bool mIsQT; 104 bool mIsHeif; 105 bool mHasMoovBox; 106 bool mPreferHeif; 107 108 Track *mFirstTrack, *mLastTrack; 109 110 MetaDataBase mFileMetaData; 111 112 Vector<uint32_t> mPath; 113 String8 mLastCommentMean; 114 String8 mLastCommentName; 115 String8 mLastCommentData; 116 117 KeyedVector<uint32_t, AString> mMetaKeyMap; 118 119 status_t readMetaData(); 120 status_t parseChunk(off64_t *offset, int depth); 121 status_t parseITunesMetaData(off64_t offset, size_t size); 122 status_t parseColorInfo(off64_t offset, size_t size); 123 status_t parse3GPPMetaData(off64_t offset, size_t size, int depth); 124 void parseID3v2MetaData(off64_t offset); 125 status_t parseQTMetaKey(off64_t data_offset, size_t data_size); 126 status_t parseQTMetaVal(int32_t keyId, off64_t data_offset, size_t data_size); 127 128 status_t updateAudioTrackInfoFromESDS_MPEG4Audio( 129 const void *esds_data, size_t esds_size); 130 131 static status_t verifyTrack(Track *track); 132 133 sp<ItemTable> mItemTable; 134 135 status_t parseTrackHeader(off64_t data_offset, off64_t data_size); 136 137 status_t parseSegmentIndex(off64_t data_offset, size_t data_size); 138 139 Track *findTrackByMimePrefix(const char *mimePrefix); 140 141 status_t parseAC3SampleEntry(off64_t offset); 142 status_t parseAC3SpecificBox(off64_t offset, uint16_t sampleRate); 143 144 MPEG4Extractor(const MPEG4Extractor &); 145 MPEG4Extractor &operator=(const MPEG4Extractor &); 146}; 147 148bool SniffMPEG4( 149 DataSourceBase *source, String8 *mimeType, float *confidence, 150 sp<AMessage> *); 151 152} // namespace android 153 154#endif // MPEG4_EXTRACTOR_H_ 155