OSDN Git Service

compile fixes, include bug "error: 'INT64_MIN' was not declared in this scope"
[android-x86/external-stagefright-plugins.git] / libstagefright / FFmpegExtractor / 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/stagefright/foundation/ABase.h>
22 #include <media/stagefright/MediaExtractor.h>
23 #include <utils/threads.h>
24 #include <utils/KeyedVector.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <inttypes.h>
31 #include <math.h>
32 #include <limits.h> /* INT_MAX */
33 #include <signal.h>
34 #include <limits.h> /* INT_MAX */
35
36 #include "config.h"
37 #include "libavutil/avstring.h"
38 #include "libavutil/colorspace.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/pixdesc.h"
41 #include "libavutil/imgutils.h"
42 #include "libavutil/dict.h"
43 #include "libavutil/parseutils.h"
44 #include "libavutil/samplefmt.h"
45 #include "libavutil/avassert.h"
46 #include "libavutil/intreadwrite.h"
47 #include "libavformat/avformat.h"
48 #include "libavdevice/avdevice.h"
49 #include "libswscale/swscale.h"
50 #include "libavcodec/audioconvert.h"
51 #include "libavutil/opt.h"
52 #include "libavutil/internal.h"
53 #include "libavcodec/avfft.h"
54 #include "libswresample/swresample.h"
55
56 #include "cmdutils.h"
57
58 #include <SDL.h>
59 #include <SDL_thread.h>
60
61 #ifdef __cplusplus
62 }
63 #endif
64
65 typedef struct PacketQueue {
66     AVPacketList *first_pkt, *last_pkt;
67     int nb_packets;
68     int size;
69     int abort_request;
70     SDL_mutex *mutex;
71     SDL_cond *cond;
72 } PacketQueue;
73
74 namespace android {
75
76 struct ABuffer;
77 struct AMessage;
78 struct Track;
79 struct String8;
80
81 struct FFmpegExtractor : public MediaExtractor {
82     FFmpegExtractor(const sp<DataSource> &source);
83
84     virtual size_t countTracks();
85     virtual sp<MediaSource> getTrack(size_t index);
86     virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
87
88     virtual sp<MetaData> getMetaData();
89
90     virtual uint32_t flags() const;
91
92 protected:
93     virtual ~FFmpegExtractor();
94
95 private:
96     struct Track;
97
98     mutable Mutex mLock;
99     sp<DataSource> mDataSource;
100     status_t mInitCheck;
101
102     KeyedVector<unsigned, sp<Track> > mTracks;
103
104     char mFilename[1024];
105     int mGenPTS;
106     int mVideoDisable;
107     int mAudioDisable;
108     int mShowStatus;
109     int mSeekByBytes;
110     int64_t mStartTime;
111     int mAutoExit;
112     int64_t mDuration;
113     int mLoop;
114     bool mEOF;
115     size_t mProbePkts;
116
117     int mAbortRequest;
118     int mPaused;
119     int mLastPaused;
120     int mSeekReq;
121     int mSeekFlags;
122     int64_t mSeekPos;
123     int mReadPauseReturn;
124     PacketQueue mAudioQ;
125     PacketQueue mVideoQ;
126     bool mVideoEOSReceived;
127     bool mAudioEOSReceived;
128
129     AVFormatContext *mFormatCtx;
130     int mVideoStreamIdx;
131     int mAudioStreamIdx;
132     AVStream *mVideoStream;
133     AVStream *mAudioStream;
134     bool mVideoQInited;
135     bool mAudioQInited;
136     bool mDefersToCreateVideoTrack;
137     bool mDefersToCreateAudioTrack;
138     AVBitStreamFilterContext *mVideoBsfc;
139     AVBitStreamFilterContext *mAudioBsfc;
140     static int decode_interrupt_cb(void *ctx);
141     void print_error_ex(const char *filename, int err);
142     int initFFmpeg();
143     void deInitFFmpeg();
144     void setFFmpegDefaultOpts();
145     int stream_component_open(int stream_index);
146     void stream_component_close(int stream_index);
147     void packet_queue_init(PacketQueue *q);
148     void packet_queue_flush(PacketQueue *q);
149     void packet_queue_end(PacketQueue *q);
150     void packet_queue_abort(PacketQueue *q);
151     int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block);
152     int packet_queue_put(PacketQueue *q, AVPacket *pkt);
153     void reachedEOS(enum AVMediaType media_type);
154     int stream_seek(int64_t pos, enum AVMediaType media_type);
155     int check_extradata(AVCodecContext *avctx);
156
157     bool mReaderThreadStarted;
158     pthread_t mReaderThread;
159     status_t startReaderThread();
160     void stopReaderThread();
161     static void *ReaderWrapper(void *me);
162     void readerEntry();
163
164     DISALLOW_EVIL_CONSTRUCTORS(FFmpegExtractor);
165 };
166
167 bool SniffFFMPEG(
168         const sp<DataSource> &source, String8 *mimeType, float *confidence,
169         sp<AMessage> *);
170
171 }  // namespace android
172
173 #endif  // SUPER_EXTRACTOR_H_
174