OSDN Git Service

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