2 * Copyright 2012 Michael Chen <omxcodec@gmail.com>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SOFT_FFMPEGVIDEO_H_
19 #define SOFT_FFMPEGVIDEO_H_
21 #include "SimpleSoftOMXComponent.h"
29 #include <limits.h> /* INT_MAX */
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"
55 struct SoftFFmpegVideo : public SimpleSoftOMXComponent {
56 SoftFFmpegVideo(const char *name,
57 const OMX_CALLBACKTYPE *callbacks,
59 OMX_COMPONENTTYPE **component);
62 virtual ~SoftFFmpegVideo();
64 virtual OMX_ERRORTYPE internalGetParameter(
65 OMX_INDEXTYPE index, OMX_PTR params);
67 virtual OMX_ERRORTYPE internalSetParameter(
68 OMX_INDEXTYPE index, const OMX_PTR params);
70 virtual void onQueueFilled(OMX_U32 portIndex);
71 virtual void onPortFlushCompleted(OMX_U32 portIndex);
72 virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
79 kNumOutputBuffers = 2,
101 OUTPUT_FRAMES_FLUSHED
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,
114 bool mFFmpegAlreadyInited;
115 bool mCodecAlreadyOpened;
116 bool mPendingFrameAsSettingChanged;
117 AVCodecContext *mCtx;
118 struct SwsContext *mImgConvertCtx;
121 EOSStatus mEOSStatus;
123 bool mExtradataReady;
124 bool mIgnoreExtradata;
125 bool mSignalledError;
127 int32_t mWidth, mHeight, mStride;
133 } mOutputPortSettingsChange;
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);
142 status_t initDecoder();
143 void deInitDecoder();
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();
155 void updatePortDefinitions();
157 DISALLOW_EVIL_CONSTRUCTORS(SoftFFmpegVideo);
160 } // namespace android
162 #endif // SOFT_FFMPEGVIDEO_H_