• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     explicit 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         // 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     sp<DataSource> mDataSource;
80     DataSourceReader *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(const mkvparser::Track *track, const sp<MetaData> &meta, TrackInfo *trackInfo);
89     void addTracks();
90     void findThumbnails();
91     void getColorInformation(const mkvparser::VideoTrack *vtrack, sp<MetaData> &meta);
92     bool isLiveStreaming() const;
93 
94     MatroskaExtractor(const MatroskaExtractor &);
95     MatroskaExtractor &operator=(const MatroskaExtractor &);
96 };
97 
98 bool SniffMatroska(
99         const sp<DataSource> &source, String8 *mimeType, float *confidence,
100         sp<AMessage> *);
101 
102 }  // namespace android
103 
104 #endif  // MATROSKA_EXTRACTOR_H_
105