1 /*
2  * Copyright (C) 2011 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 MPEG2_PS_EXTRACTOR_H_
18 
19 #define MPEG2_PS_EXTRACTOR_H_
20 
21 #include <media/stagefright/foundation/ABase.h>
22 #include <media/stagefright/MediaExtractor.h>
23 #include <utils/threads.h>
24 #include <utils/KeyedVector.h>
25 
26 namespace android {
27 
28 struct ABuffer;
29 struct AMessage;
30 struct Track;
31 class String8;
32 
33 struct MPEG2PSExtractor : public MediaExtractor {
34     MPEG2PSExtractor(const sp<DataSource> &source);
35 
36     virtual size_t countTracks();
37     virtual sp<IMediaSource> getTrack(size_t index);
38     virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
39 
40     virtual sp<MetaData> getMetaData();
41 
42     virtual uint32_t flags() const;
nameMPEG2PSExtractor43     virtual const char * name() { return "MPEG2PSExtractor"; }
44 
45 protected:
46     virtual ~MPEG2PSExtractor();
47 
48 private:
49     struct Track;
50     struct WrappedTrack;
51 
52     mutable Mutex mLock;
53     sp<DataSource> mDataSource;
54 
55     off64_t mOffset;
56     status_t mFinalResult;
57     sp<ABuffer> mBuffer;
58     KeyedVector<unsigned, sp<Track> > mTracks;
59     bool mScanning;
60 
61     bool mProgramStreamMapValid;
62     KeyedVector<unsigned, unsigned> mStreamTypeByESID;
63 
64     status_t feedMore();
65 
66     status_t dequeueChunk();
67     ssize_t dequeuePack();
68     ssize_t dequeueSystemHeader();
69     ssize_t dequeuePES();
70 
71     DISALLOW_EVIL_CONSTRUCTORS(MPEG2PSExtractor);
72 };
73 
74 bool SniffMPEG2PS(
75         const sp<DataSource> &source, String8 *mimeType, float *confidence,
76         sp<AMessage> *);
77 
78 }  // namespace android
79 
80 #endif  // MPEG2_PS_EXTRACTOR_H_
81 
82