1 /* 2 * Copyright (C) 2010 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 MATROSKA_EXTRACTOR_H_ 18 19 #define MATROSKA_EXTRACTOR_H_ 20 21 #include "mkvparser/mkvparser.h" 22 23 #include <media/MediaExtractorPluginApi.h> 24 #include <media/MediaExtractorPluginHelper.h> 25 #include <media/NdkMediaFormat.h> 26 #include <utils/Vector.h> 27 #include <utils/threads.h> 28 29 namespace android { 30 31 struct AMessage; 32 class String8; 33 34 class MetaData; 35 struct DataSourceBaseReader; 36 struct MatroskaSource; 37 38 struct MatroskaExtractor : public MediaExtractorPluginHelper { 39 explicit MatroskaExtractor(DataSourceHelper *source); 40 41 virtual size_t countTracks(); 42 43 virtual MediaTrackHelper *getTrack(size_t index); 44 45 virtual media_status_t getTrackMetaData(AMediaFormat *meta, size_t index, uint32_t flags); 46 47 virtual media_status_t getMetaData(AMediaFormat *meta); 48 49 virtual uint32_t flags() const; 50 nameMatroskaExtractor51 virtual const char * name() { return "MatroskaExtractor"; } 52 53 protected: 54 virtual ~MatroskaExtractor(); 55 56 private: 57 friend struct MatroskaSource; 58 friend struct BlockIterator; 59 60 struct TrackInfo { TrackInfoMatroskaExtractor::TrackInfo61 TrackInfo() { 62 mMeta = NULL; 63 } 64 ~TrackInfoMatroskaExtractor::TrackInfo65 ~TrackInfo() { 66 } 67 unsigned long mTrackNum; 68 bool mEncrypted; 69 AMediaFormat *mMeta; 70 const MatroskaExtractor *mExtractor; 71 Vector<const mkvparser::CuePoint*> mCuePoints; 72 73 // mHeader points to memory managed by mkvparser; 74 // mHeader would be deleted when mSegment is deleted 75 // in ~MatroskaExtractor. 76 unsigned char *mHeader; 77 size_t mHeaderLen; 78 int32_t mNalLengthSize; 79 80 const mkvparser::Track* getTrack() const; 81 const mkvparser::CuePoint::TrackPosition *find(long long timeNs) const; 82 }; 83 84 Mutex mLock; 85 Vector<TrackInfo> mTracks; 86 87 DataSourceHelper *mDataSource; 88 DataSourceBaseReader *mReader; 89 mkvparser::Segment *mSegment; 90 bool mExtractedThumbnails; 91 bool mIsLiveStreaming; 92 bool mIsWebm; 93 int64_t mSeekPreRollNs; 94 95 status_t synthesizeAVCC(TrackInfo *trackInfo, size_t index); 96 status_t synthesizeMPEG2(TrackInfo *trackInfo, size_t index); 97 status_t synthesizeMPEG4(TrackInfo *trackInfo, size_t index); 98 status_t initTrackInfo( 99 const mkvparser::Track *track, 100 AMediaFormat *meta, 101 TrackInfo *trackInfo); 102 void addTracks(); 103 void findThumbnails(); 104 void getColorInformation( 105 const mkvparser::VideoTrack *vtrack, 106 AMediaFormat *meta); 107 bool isLiveStreaming() const; 108 109 MatroskaExtractor(const MatroskaExtractor &); 110 MatroskaExtractor &operator=(const MatroskaExtractor &); 111 }; 112 113 } // namespace android 114 115 #endif // MATROSKA_EXTRACTOR_H_ 116