OSDN Git Service

Port to pie-x86
[android-x86/external-stagefright-plugins.git] / extractor / FFmpegExtractor.h
1 /*
2  * Copyright 2012 Michael Chen <omxcodec@gmail.com>
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 SUPER_EXTRACTOR_H_
18
19 #define SUPER_EXTRACTOR_H_
20
21 #include <media/MediaExtractor.h>
22 #include <media/MediaSource.h>
23 #include <media/stagefright/foundation/ABase.h>
24 #include <utils/threads.h>
25 #include <utils/KeyedVector.h>
26
27 #include "utils/ffmpeg_utils.h"
28
29 namespace android {
30
31 struct ABuffer;
32 struct AMessage;
33 class String8;
34 struct FFmpegSource;
35
36 struct FFmpegExtractor : public MediaExtractor {
37     FFmpegExtractor(DataSourceBase *source, const sp<AMessage> &meta);
38
39     virtual size_t countTracks();
40     virtual MediaTrack* getTrack(size_t index);
41     virtual status_t getTrackMetaData(MetaDataBase &meta, size_t index, uint32_t flags);
42
43     virtual status_t getMetaData(MetaDataBase &meta);
44
45     virtual uint32_t flags() const;
46
47 protected:
48     virtual ~FFmpegExtractor();
49
50 private:
51     friend struct FFmpegSource;
52
53     struct TrackInfo {
54         int mIndex; //stream index
55         MetaDataBase mMeta;
56         AVStream *mStream;
57         PacketQueue *mQueue;
58     };
59
60     Vector<TrackInfo> mTracks;
61
62     mutable Mutex mLock;
63     mutable Mutex mExtractorMutex;
64     Condition mCondition;
65
66     DataSourceBase *mDataSource;
67     MetaDataBase mMeta;
68     status_t mInitCheck;
69
70     char mFilename[PATH_MAX];
71     int mGenPTS;
72     int mVideoDisable;
73     int mAudioDisable;
74     int mShowStatus;
75     int mSeekByBytes;
76     int mAutoExit;
77     int64_t mStartTime;
78     int64_t mDuration;
79     int mLoop;
80     bool mEOF;
81     size_t mProbePkts;
82
83     int mAbortRequest;
84     int mPaused;
85     int mLastPaused;
86     int mSeekIdx;
87     MediaSource::ReadOptions::SeekMode mSeekMode;
88     int64_t mSeekPos;
89     int64_t mSeekMin;
90     int64_t mSeekMax;
91
92     int mReadPauseReturn;
93     PacketQueue mAudioQ;
94     PacketQueue mVideoQ;
95     bool mVideoEOSReceived;
96     bool mAudioEOSReceived;
97
98     AVFormatContext *mFormatCtx;
99     int mVideoStreamIdx;
100     int mAudioStreamIdx;
101     AVStream *mVideoStream;
102     AVStream *mAudioStream;
103     bool mDefersToCreateVideoTrack;
104     bool mDefersToCreateAudioTrack;
105     AVBitStreamFilterContext *mVideoBsfc;
106     AVBitStreamFilterContext *mAudioBsfc;
107
108     static int decode_interrupt_cb(void *ctx);
109     int initStreams();
110     void deInitStreams();
111     void fetchStuffsFromSniffedMeta(const sp<AMessage> &meta);
112     void setFFmpegDefaultOpts();
113     void printTime(int64_t time);
114     bool is_codec_supported(enum AVCodecID codec_id);
115     status_t setVideoFormat(AVStream *stream, MetaDataBase &meta);
116     status_t setAudioFormat(AVStream *stream, MetaDataBase &meta);
117     void setDurationMetaData(AVStream *stream, MetaDataBase &meta);
118     int stream_component_open(int stream_index);
119     void stream_component_close(int stream_index);
120     void reachedEOS(enum AVMediaType media_type);
121     int stream_seek(int64_t pos, enum AVMediaType media_type,
122             MediaSource::ReadOptions::SeekMode mode);
123     int check_extradata(AVCodecContext *avctx);
124
125     bool mReaderThreadStarted;
126     pthread_t mReaderThread;
127     status_t startReaderThread();
128     void stopReaderThread();
129     static void *ReaderWrapper(void *me);
130     void readerEntry();
131
132     bool mParsedMetadata;
133
134     DISALLOW_EVIL_CONSTRUCTORS(FFmpegExtractor);
135 };
136
137 /*
138 extern "C" {
139
140 static const char *findMatchingContainer(const char *name);
141
142 bool SniffFFMPEG(
143         const sp<DataSource> &source, String8 *mimeType, float *confidence,
144         sp<AMessage> *);
145
146 MediaExtractor* CreateFFMPEGExtractor(const sp<DataSource> &source,
147         const char *mime, const sp<AMessage> &meta);
148
149 }
150 */
151
152 }  // namespace android
153
154 #endif  // SUPER_EXTRACTOR_H_
155