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