Line data Source code
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 <arpa/inet.h>
22 :
23 : #include <media/stagefright/DataSource.h>
24 : #include <media/stagefright/MediaExtractor.h>
25 : #include <media/stagefright/Utils.h>
26 : #include <utils/List.h>
27 : #include <utils/String8.h>
28 : #include "nsTArray.h"
29 :
30 : namespace stagefright {
31 :
32 : struct AMessage;
33 : class DataSource;
34 : class SampleTable;
35 : class String8;
36 :
37 : struct SidxEntry {
38 : size_t mSize;
39 : uint32_t mDurationUs;
40 : };
41 :
42 : class MPEG4Extractor : public MediaExtractor {
43 : public:
44 : MPEG4Extractor(const sp<DataSource> &source);
45 :
46 : size_t countTracks() override;
47 : sp<MediaSource> getTrack(size_t index) override;
48 : sp<MetaData> getTrackMetaData(size_t index, uint32_t flags) override;
49 :
50 : sp<MetaData> getMetaData() override;
51 : uint32_t flags() const override;
52 :
53 : // for DRM
54 : char* getDrmTrackInfo(size_t trackID, int *len) override;
55 :
56 : protected:
57 : virtual ~MPEG4Extractor();
58 :
59 : private:
60 :
61 : struct PsshInfo {
62 : uint8_t uuid[16];
63 : uint32_t datalen;
64 : uint8_t *data;
65 : };
66 0 : struct Track {
67 : Track *next;
68 : sp<MetaData> meta;
69 : uint32_t timescale;
70 : // Temporary storage for elst until we've
71 : // parsed mdhd and can interpret them.
72 : uint64_t empty_duration;
73 : uint64_t segment_duration;
74 : int64_t media_time;
75 :
76 : sp<SampleTable> sampleTable;
77 : bool includes_expensive_metadata;
78 : bool skipTrack;
79 : };
80 :
81 : nsTArray<SidxEntry> mSidxEntries;
82 : uint64_t mSidxDuration;
83 :
84 : nsTArray<PsshInfo> mPssh;
85 :
86 : sp<DataSource> mDataSource;
87 : status_t mInitCheck;
88 : bool mHasVideo;
89 : uint32_t mHeaderTimescale;
90 :
91 : Track *mFirstTrack, *mLastTrack;
92 :
93 : sp<MetaData> mFileMetaData;
94 :
95 : nsTArray<uint32_t> mPath;
96 : String8 mLastCommentMean;
97 : String8 mLastCommentName;
98 : String8 mLastCommentData;
99 :
100 : status_t readMetaData();
101 : status_t parseChunk(off64_t *offset, int depth);
102 : status_t parseMetaData(off64_t offset, size_t size);
103 :
104 : status_t updateAudioTrackInfoFromESDS_MPEG4Audio(
105 : const void *esds_data, size_t esds_size);
106 :
107 : static status_t verifyTrack(Track *track);
108 :
109 : struct SINF {
110 : SINF *next;
111 : uint16_t trackID;
112 : uint8_t IPMPDescriptorID;
113 : ssize_t len;
114 : char *IPMPData;
115 : };
116 :
117 : SINF *mFirstSINF;
118 :
119 : bool mIsDrm;
120 : uint32_t mDrmScheme;
121 :
122 : status_t parseDrmSINF(off64_t *offset, off64_t data_offset);
123 :
124 : status_t parseTrackHeader(off64_t data_offset, off64_t data_size);
125 :
126 : status_t parseSegmentIndex(off64_t data_offset, size_t data_size);
127 :
128 : void storeEditList();
129 :
130 : MPEG4Extractor(const MPEG4Extractor &);
131 : MPEG4Extractor &operator=(const MPEG4Extractor &);
132 : };
133 :
134 : } // namespace stagefright
135 :
136 : #endif // MPEG4_EXTRACTOR_H_
|