MPEG4Extractor.h revision 6f3a0c2dcb8d37d34e29e6a02acf1e3f8596088c
1/*
2 * Copyright (C) 2009 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 MPEG4_EXTRACTOR_H_
18
19#define MPEG4_EXTRACTOR_H_
20
21#include <media/stagefright/MediaExtractor.h>
22#include <utils/Vector.h>
23
24namespace android {
25
26class DataSource;
27class SampleTable;
28class String8;
29
30class MPEG4Extractor : public MediaExtractor {
31public:
32    // Extractor assumes ownership of "source".
33    MPEG4Extractor(const sp<DataSource> &source);
34
35    virtual size_t countTracks();
36    virtual sp<MediaSource> getTrack(size_t index);
37    virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
38
39    virtual sp<MetaData> getMetaData();
40
41protected:
42    virtual ~MPEG4Extractor();
43
44private:
45    struct Track {
46        Track *next;
47        sp<MetaData> meta;
48        uint32_t timescale;
49        sp<SampleTable> sampleTable;
50        bool includes_expensive_metadata;
51        bool skipTrack;
52    };
53
54    sp<DataSource> mDataSource;
55    bool mHaveMetadata;
56    bool mHasVideo;
57
58    Track *mFirstTrack, *mLastTrack;
59
60    sp<MetaData> mFileMetaData;
61
62    uint32_t mHandlerType;
63    Vector<uint32_t> mPath;
64
65    status_t readMetaData();
66    status_t parseChunk(off_t *offset, int depth);
67    status_t parseMetaData(off_t offset, size_t size);
68
69    status_t updateAudioTrackInfoFromESDS_MPEG4Audio(
70            const void *esds_data, size_t esds_size);
71
72    static status_t verifyTrack(Track *track);
73
74    MPEG4Extractor(const MPEG4Extractor &);
75    MPEG4Extractor &operator=(const MPEG4Extractor &);
76};
77
78bool SniffMPEG4(
79        const sp<DataSource> &source, String8 *mimeType, float *confidence);
80
81}  // namespace android
82
83#endif  // MPEG4_EXTRACTOR_H_
84