OSDN Git Service

653c94822d3a4acc98a0a538dfacd54ab106b710
[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 "libavformat/avformat.h"
42 #include "libavdevice/avdevice.h"
43 #include "libswscale/swscale.h"
44 #include "libavutil/opt.h"
45 #include "libavutil/internal.h"
46 #include "libavcodec/avfft.h"
47 #include "libswresample/swresample.h"
48
49 #ifdef __cplusplus
50 }
51 #endif
52
53 namespace android {
54
55 struct SoftFFmpegVideo : public SimpleSoftOMXComponent {
56     SoftFFmpegVideo(const char *name,
57             const OMX_CALLBACKTYPE *callbacks,
58             OMX_PTR appData,
59             OMX_COMPONENTTYPE **component);
60
61 protected:
62     virtual ~SoftFFmpegVideo();
63
64     virtual OMX_ERRORTYPE internalGetParameter(
65             OMX_INDEXTYPE index, OMX_PTR params);
66
67     virtual OMX_ERRORTYPE internalSetParameter(
68             OMX_INDEXTYPE index, const OMX_PTR params);
69
70     virtual void onQueueFilled(OMX_U32 portIndex);
71     virtual void onPortFlushCompleted(OMX_U32 portIndex);
72     virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
73
74 private:
75     enum {
76         kInputPortIndex   = 0,
77         kOutputPortIndex  = 1,
78         kNumInputBuffers  = 5,
79         kNumOutputBuffers = 2,
80     };
81
82     enum {
83         MODE_NONE,
84         MODE_MPEG2,
85         MODE_H263,
86         MODE_MPEG4,
87         MODE_WMV,
88         MODE_RV,
89         MODE_H264,
90         MODE_VPX,
91         MODE_VC1,
92         MODE_FLV1,
93         MODE_DIVX,
94         MODE_TRIAL
95     } mMode;
96
97     enum EOSStatus {
98         INPUT_DATA_AVAILABLE,
99         INPUT_EOS_SEEN,
100         OUTPUT_FRAMES_FLUSHED
101     };
102
103     enum {
104         ERR_NO_FRM              = 2,
105         ERR_FLUSHED             = 1,
106                 ERR_OK                  = 0,  //No errors
107         ERR_OOM                 = -1, //Out of memmory
108                 ERR_CODEC_NOT_FOUND     = -2,
109                 ERR_DECODER_OPEN_FAILED = -2,
110                 ERR_SWS_FAILED          = -3,
111     };
112
113     bool mFFmpegAlreadyInited;
114         bool mCodecAlreadyOpened;
115         bool mPendingFrameAsSettingChanged;
116     AVCodecContext *mCtx;
117     struct SwsContext *mImgConvertCtx;
118         AVFrame *mFrame;
119
120     EOSStatus mEOSStatus;
121
122     bool mExtradataReady;
123     bool mIgnoreExtradata;
124     bool mSignalledError;
125     bool mDoDeinterlace;
126     int32_t mWidth, mHeight, mStride;
127
128     enum {
129         NONE,
130         AWAITING_DISABLED,
131         AWAITING_ENABLED
132     } mOutputPortSettingsChange;
133
134     void setMode(const char *name);
135     void initInputFormat(uint32_t mode, OMX_PARAM_PORTDEFINITIONTYPE &def);
136         void getInputFormat(uint32_t mode, OMX_VIDEO_PARAM_PORTFORMATTYPE *formatParams);
137     void setDefaultCtx(AVCodecContext *avctx, const AVCodec *codec);
138     OMX_ERRORTYPE isRoleSupported(const OMX_PARAM_COMPONENTROLETYPE *roleParams);
139
140     void initPorts();
141     status_t initDecoder();
142     void deInitDecoder();
143
144         bool    handlePortSettingChangeEvent();
145         int32_t handleExtradata();
146         int32_t openDecoder();
147     void    initPacket(AVPacket *pkt, OMX_BUFFERHEADERTYPE *inHeader);
148     int32_t decodeVideo();
149     int32_t preProcessVideoFrame(AVPicture *picture, void **bufp);
150         int32_t drainOneOutputBuffer();
151         void    drainEOSOutputBuffer();
152         void    drainAllOutputBuffers();
153
154     void updatePortDefinitions();
155
156     DISALLOW_EVIL_CONSTRUCTORS(SoftFFmpegVideo);
157 };
158
159 }  // namespace android
160
161 #endif  // SOFT_FFMPEGVIDEO_H_