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,
100 OUTPUT_FRAMES_FLUSHED
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,
113 bool mFFmpegAlreadyInited;
114 bool mCodecAlreadyOpened;
115 bool mPendingFrameAsSettingChanged;
116 AVCodecContext *mCtx;
117 struct SwsContext *mImgConvertCtx;
120 EOSStatus mEOSStatus;
122 bool mExtradataReady;
123 bool mIgnoreExtradata;
124 bool mSignalledError;
126 int32_t mWidth, mHeight, mStride;
132 } mOutputPortSettingsChange;
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);
141 status_t initDecoder();
142 void deInitDecoder();
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();
154 void updatePortDefinitions();
156 DISALLOW_EVIL_CONSTRUCTORS(SoftFFmpegVideo);
159 } // namespace android
161 #endif // SOFT_FFMPEGVIDEO_H_