OSDN Git Service

add HEVC(H.265) decoder. plz sync:
[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_HEVC,
95         MODE_TRIAL
96     } mMode;
97
98     enum EOSStatus {
99         INPUT_DATA_AVAILABLE,
100         INPUT_EOS_SEEN,
101         OUTPUT_FRAMES_FLUSHED
102     };
103
104     enum {
105         ERR_NO_FRM              = 2,
106         ERR_FLUSHED             = 1,
107                 ERR_OK                  = 0,  //No errors
108         ERR_OOM                 = -1, //Out of memmory
109                 ERR_CODEC_NOT_FOUND     = -2,
110                 ERR_DECODER_OPEN_FAILED = -2,
111                 ERR_SWS_FAILED          = -3,
112     };
113
114     bool mFFmpegAlreadyInited;
115         bool mCodecAlreadyOpened;
116         bool mPendingFrameAsSettingChanged;
117     AVCodecContext *mCtx;
118     struct SwsContext *mImgConvertCtx;
119         AVFrame *mFrame;
120
121     EOSStatus mEOSStatus;
122
123     bool mExtradataReady;
124     bool mIgnoreExtradata;
125     bool mSignalledError;
126     bool mDoDeinterlace;
127     int32_t mWidth, mHeight, mStride;
128
129     enum {
130         NONE,
131         AWAITING_DISABLED,
132         AWAITING_ENABLED
133     } mOutputPortSettingsChange;
134
135     void setMode(const char *name);
136     void initInputFormat(uint32_t mode, OMX_PARAM_PORTDEFINITIONTYPE &def);
137         void getInputFormat(uint32_t mode, OMX_VIDEO_PARAM_PORTFORMATTYPE *formatParams);
138     void setDefaultCtx(AVCodecContext *avctx, const AVCodec *codec);
139     OMX_ERRORTYPE isRoleSupported(const OMX_PARAM_COMPONENTROLETYPE *roleParams);
140
141     void initPorts();
142     status_t initDecoder();
143     void deInitDecoder();
144
145         bool    handlePortSettingChangeEvent();
146         int32_t handleExtradata();
147         int32_t openDecoder();
148     void    initPacket(AVPacket *pkt, OMX_BUFFERHEADERTYPE *inHeader);
149     int32_t decodeVideo();
150     int32_t preProcessVideoFrame(AVPicture *picture, void **bufp);
151         int32_t drainOneOutputBuffer();
152         void    drainEOSOutputBuffer();
153         void    drainAllOutputBuffers();
154
155     void updatePortDefinitions();
156
157     DISALLOW_EVIL_CONSTRUCTORS(SoftFFmpegVideo);
158 };
159
160 }  // namespace android
161
162 #endif  // SOFT_FFMPEGVIDEO_H_