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 <media/stagefright/MediaExtractor.h>
22#include <utils/Vector.h>
23#include <utils/threads.h>
24
25namespace mkvparser {
26struct Segment;
27};
28
29namespace android {
30
31struct AMessage;
32class String8;
33
34struct DataSourceReader;
35struct MatroskaSource;
36
37struct MatroskaExtractor : public MediaExtractor {
38    MatroskaExtractor(const sp<DataSource> &source);
39
40    virtual size_t countTracks();
41
42    virtual sp<MediaSource> getTrack(size_t index);
43
44    virtual sp<MetaData> getTrackMetaData(
45            size_t index, uint32_t flags);
46
47    virtual sp<MetaData> getMetaData();
48
49    virtual uint32_t flags() const;
50
51protected:
52    virtual ~MatroskaExtractor();
53
54private:
55    friend struct MatroskaSource;
56    friend struct BlockIterator;
57
58    struct TrackInfo {
59        unsigned long mTrackNum;
60        sp<MetaData> mMeta;
61    };
62
63    Mutex mLock;
64    Vector<TrackInfo> mTracks;
65
66    sp<DataSource> mDataSource;
67    DataSourceReader *mReader;
68    mkvparser::Segment *mSegment;
69    bool mExtractedThumbnails;
70    bool mIsLiveStreaming;
71    bool mIsWebm;
72
73    void addTracks();
74    void findThumbnails();
75
76    bool isLiveStreaming() const;
77
78    MatroskaExtractor(const MatroskaExtractor &);
79    MatroskaExtractor &operator=(const MatroskaExtractor &);
80};
81
82bool SniffMatroska(
83        const sp<DataSource> &source, String8 *mimeType, float *confidence,
84        sp<AMessage> *);
85
86}  // namespace android
87
88#endif  // MATROSKA_EXTRACTOR_H_
89