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#include <utils/String8.h>
24
25namespace android {
26
27struct AMessage;
28class DataSource;
29class SampleTable;
30class String8;
31
32class MPEG4Extractor : public MediaExtractor {
33public:
34    // Extractor assumes ownership of "source".
35    MPEG4Extractor(const sp<DataSource> &source);
36
37    virtual size_t countTracks();
38    virtual sp<MediaSource> getTrack(size_t index);
39    virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
40
41    virtual sp<MetaData> getMetaData();
42
43    // for DRM
44    virtual char* getDrmTrackInfo(size_t trackID, int *len);
45
46protected:
47    virtual ~MPEG4Extractor();
48
49private:
50    struct Track {
51        Track *next;
52        sp<MetaData> meta;
53        uint32_t timescale;
54        sp<SampleTable> sampleTable;
55        bool includes_expensive_metadata;
56        bool skipTrack;
57    };
58
59    sp<DataSource> mDataSource;
60    status_t mInitCheck;
61    bool mHasVideo;
62
63    Track *mFirstTrack, *mLastTrack;
64
65    sp<MetaData> mFileMetaData;
66
67    Vector<uint32_t> mPath;
68    String8 mLastCommentMean;
69    String8 mLastCommentName;
70    String8 mLastCommentData;
71
72    status_t readMetaData();
73    status_t parseChunk(off64_t *offset, int depth);
74    status_t parseMetaData(off64_t offset, size_t size);
75
76    status_t updateAudioTrackInfoFromESDS_MPEG4Audio(
77            const void *esds_data, size_t esds_size);
78
79    static status_t verifyTrack(Track *track);
80
81    struct SINF {
82        SINF *next;
83        uint16_t trackID;
84        uint8_t IPMPDescriptorID;
85        ssize_t len;
86        char *IPMPData;
87    };
88
89    SINF *mFirstSINF;
90
91    bool mIsDrm;
92    status_t parseDrmSINF(off64_t *offset, off64_t data_offset);
93
94    status_t parseTrackHeader(off64_t data_offset, off64_t data_size);
95
96    Track *findTrackByMimePrefix(const char *mimePrefix);
97
98    MPEG4Extractor(const MPEG4Extractor &);
99    MPEG4Extractor &operator=(const MPEG4Extractor &);
100};
101
102bool SniffMPEG4(
103        const sp<DataSource> &source, String8 *mimeType, float *confidence,
104        sp<AMessage> *);
105
106}  // namespace android
107
108#endif  // MPEG4_EXTRACTOR_H_
109