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/stagefright/MediaExtractor.h>
24 #include <utils/Vector.h>
25 #include <utils/threads.h>
26 
27 namespace android {
28 
29 struct AMessage;
30 class String8;
31 
32 class MetaData;
33 struct DataSourceReader;
34 struct MatroskaSource;
35 
36 struct MatroskaExtractor : public MediaExtractor {
37     MatroskaExtractor(const sp<DataSource> &source);
38 
39     virtual size_t countTracks();
40 
41     virtual sp<IMediaSource> getTrack(size_t index);
42 
43     virtual sp<MetaData> getTrackMetaData(
44             size_t index, uint32_t flags);
45 
46     virtual sp<MetaData> getMetaData();
47 
48     virtual uint32_t flags() const;
49 
nameMatroskaExtractor50     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         sp<MetaData> mMeta;
63         const MatroskaExtractor *mExtractor;
64         Vector<const mkvparser::CuePoint*> mCuePoints;
65 
66         const mkvparser::Track* getTrack() const;
67         const mkvparser::CuePoint::TrackPosition *find(long long timeNs) const;
68     };
69 
70     Mutex mLock;
71     Vector<TrackInfo> mTracks;
72 
73     sp<DataSource> mDataSource;
74     DataSourceReader *mReader;
75     mkvparser::Segment *mSegment;
76     bool mExtractedThumbnails;
77     bool mIsLiveStreaming;
78     bool mIsWebm;
79     int64_t mSeekPreRollNs;
80 
81     status_t synthesizeAVCC(TrackInfo *trackInfo, size_t index);
82     void addTracks();
83     void findThumbnails();
84     void getColorInformation(const mkvparser::VideoTrack *vtrack, sp<MetaData> &meta);
85     bool isLiveStreaming() const;
86 
87     MatroskaExtractor(const MatroskaExtractor &);
88     MatroskaExtractor &operator=(const MatroskaExtractor &);
89 };
90 
91 bool SniffMatroska(
92         const sp<DataSource> &source, String8 *mimeType, float *confidence,
93         sp<AMessage> *);
94 
95 }  // namespace android
96 
97 #endif  // MATROSKA_EXTRACTOR_H_
98