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