• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 
3  * Copyright (C) 2010 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef MPEG2_TS_EXTRACTOR_H_
19 
20 #define MPEG2_TS_EXTRACTOR_H_
21 
22 #include <media/stagefright/foundation/ABase.h>
23 #include <media/MediaExtractorPluginApi.h>
24 #include <media/MediaExtractorPluginHelper.h>
25 #include <media/stagefright/MetaDataBase.h>
26 #include <utils/threads.h>
27 #include <utils/KeyedVector.h>
28 #include <utils/Vector.h>
29 
30 #include <ATSParser.h>
31 
32 namespace android {
33 
34 struct AMessage;
35 struct AnotherPacketSource;
36 struct ATSParser;
37 struct CDataSource;
38 struct MPEG2TSSource;
39 class String8;
40 
41 struct MPEG2TSExtractor : public MediaExtractorPluginHelper {
42     explicit MPEG2TSExtractor(DataSourceHelper *source);
43 
44     virtual size_t countTracks();
45     virtual MediaTrackHelper *getTrack(size_t index);
46     virtual media_status_t getTrackMetaData(AMediaFormat *meta, size_t index, uint32_t flags);
47 
48     virtual media_status_t getMetaData(AMediaFormat *meta);
49 
50     virtual media_status_t setMediaCas(const uint8_t* /*casToken*/, size_t /*size*/) override;
51 
52     virtual uint32_t flags() const;
nameMPEG2TSExtractor53     virtual const char * name() { return "MPEG2TSExtractor"; }
54 
55 protected:
56     virtual ~MPEG2TSExtractor();
57 
58 private:
59     friend struct MPEG2TSSource;
60 
61     mutable Mutex mLock;
62 
63     DataSourceHelper *mDataSource;
64 
65     sp<ATSParser> mParser;
66 
67     // Used to remember SyncEvent occurred in feedMore() when called from init(),
68     // because init() needs to update |mSourceImpls| before adding SyncPoint.
69     ATSParser::SyncEvent mLastSyncEvent;
70 
71     Vector<sp<AnotherPacketSource> > mSourceImpls;
72 
73     Vector<KeyedVector<int64_t, off64_t> > mSyncPoints;
74     // Sync points used for seeking --- normally one for video track is used.
75     // If no video track is present, audio track will be used instead.
76     KeyedVector<int64_t, off64_t> *mSeekSyncPoints;
77 
78     off64_t mOffset;
79 
80     static bool isScrambledFormat(MetaDataBase &format);
81 
82     void init();
83     void addSource(const sp<AnotherPacketSource> &impl);
84     // Try to feed more data from source to parser.
85     // |isInit| means this function is called inside init(). This is a signal to
86     // save SyncEvent so that init() can add SyncPoint after it updates |mSourceImpls|.
87     // This function returns OK if expected amount of data is fed from DataSourceHelper to
88     // parser and is successfully parsed. Otherwise, various error codes could be
89     // returned, e.g., ERROR_END_OF_STREAM, or no data availalbe from DataSourceHelper, or
90     // the data has syntax error during parsing, etc.
91     status_t feedMore(bool isInit = false);
92     status_t seek(int64_t seekTimeUs,
93             const MediaTrackHelper::ReadOptions::SeekMode& seekMode);
94     status_t queueDiscontinuityForSeek(int64_t actualSeekTimeUs);
95     status_t seekBeyond(int64_t seekTimeUs);
96 
97     status_t feedUntilBufferAvailable(const sp<AnotherPacketSource> &impl);
98     status_t findIndexOfSource(const sp<AnotherPacketSource> &impl, size_t *index);
99 
100     // Add a SynPoint derived from |event|.
101     void addSyncPoint_l(const ATSParser::SyncEvent &event);
102 
103     status_t  estimateDurationsFromTimesUsAtEnd();
104 
105     size_t mHeaderSkip;
106     DISALLOW_EVIL_CONSTRUCTORS(MPEG2TSExtractor);
107 };
108 
109 bool SniffMPEG2TS(DataSourceHelper *source, float *confidence);
110 
111 }  // namespace android
112 
113 #endif  // MPEG2_TS_EXTRACTOR_H_
114