OSDN Git Service

add ffmpeg heuristic decoder.
[android-x86/external-stagefright-plugins.git] / libstagefright / codecs / ffmpegdec / vdec / SoftFFmpegVideo.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 SOFT_FFMPEGVIDEO_H_
18
19 #define SOFT_FFMPEGVIDEO_H_
20
21 #include "SimpleSoftOMXComponent.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include <inttypes.h>
28 #include <math.h>
29 #include <limits.h> /* INT_MAX */
30
31 #include "config.h"
32 #include "libavutil/avstring.h"
33 #include "libavutil/colorspace.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/pixdesc.h"
36 #include "libavutil/imgutils.h"
37 #include "libavutil/dict.h"
38 #include "libavutil/parseutils.h"
39 #include "libavutil/samplefmt.h"
40 #include "libavutil/avassert.h"
41 #include "libavutil/intreadwrite.h"
42 #include "libavformat/avformat.h"
43 #include "libavdevice/avdevice.h"
44 #include "libswscale/swscale.h"
45 #include "libavutil/opt.h"
46 #include "libavutil/internal.h"
47 #include "libavcodec/avfft.h"
48 #include "libswresample/swresample.h"
49
50 #ifdef __cplusplus
51 }
52 #endif
53
54 namespace android {
55
56 struct SoftFFmpegVideo : public SimpleSoftOMXComponent {
57     SoftFFmpegVideo(const char *name,
58             const OMX_CALLBACKTYPE *callbacks,
59             OMX_PTR appData,
60             OMX_COMPONENTTYPE **component);
61
62 protected:
63     virtual ~SoftFFmpegVideo();
64
65     virtual OMX_ERRORTYPE internalGetParameter(
66             OMX_INDEXTYPE index, OMX_PTR params);
67
68     virtual OMX_ERRORTYPE internalSetParameter(
69             OMX_INDEXTYPE index, const OMX_PTR params);
70
71     virtual void onQueueFilled(OMX_U32 portIndex);
72     virtual void onPortFlushCompleted(OMX_U32 portIndex);
73     virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
74
75 private:
76     enum {
77         kNumInputBuffers  = 5,
78         kNumOutputBuffers = 2,
79     };
80
81     enum {
82         MODE_H264,
83         MODE_MPEG4,
84         MODE_MPEG2,
85         MODE_H263,
86         MODE_VPX,
87         MODE_VC1,
88         MODE_DIVX,
89         MODE_WMV,
90         MODE_FLV,
91         MODE_RV,
92         MODE_HEURISTIC
93     } mMode;
94
95     enum {
96         kPortIndexInput  = 0,
97         kPortIndexOutput = 1,
98     };
99
100     bool mFFmpegInited;
101     AVCodecContext *mCtx;
102     struct SwsContext *mImgConvertCtx;
103
104     bool mExtradataReady;
105     bool mIgnoreExtradata;
106     bool mSignalledError;
107     bool mDoDeinterlace;
108     int32_t mWidth, mHeight, mStride;
109
110     enum {
111         NONE,
112         AWAITING_DISABLED,
113         AWAITING_ENABLED
114     } mOutputPortSettingsChange;
115
116     void setAVCtxToDefault(AVCodecContext *avctx, const AVCodec *codec);
117     void preProcessVideoFrame(AVPicture *picture, void **bufp);
118
119     void initPorts();
120     status_t initDecoder();
121     void deInitDecoder();
122
123     void updatePortDefinitions();
124
125     DISALLOW_EVIL_CONSTRUCTORS(SoftFFmpegVideo);
126 };
127
128 }  // namespace android
129
130 #endif  // SOFT_FFMPEGVIDEO_H_