OSDN Git Service

stagefright-plugins: Fix timestamp calculation
[android-x86/external-stagefright-plugins.git] / omx / SoftFFmpegVideo.h
1 /*
2  * Copyright 2012 Michael Chen <omxcodec@gmail.com>
3  * Copyright 2015 The CyanogenMod Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef SOFT_FFMPEGVIDEO_H_
19
20 #define SOFT_FFMPEGVIDEO_H_
21
22 #include "SoftVideoDecoderOMXComponent.h"
23
24 #include "utils/ffmpeg_utils.h"
25
26 namespace android {
27
28 struct SoftFFmpegVideo : public SoftVideoDecoderOMXComponent {
29     SoftFFmpegVideo(const char *name,
30             const char *componentRole,
31             OMX_VIDEO_CODINGTYPE codingType,
32             const CodecProfileLevel *profileLevels,
33             size_t numProfileLevels,
34             const OMX_CALLBACKTYPE *callbacks,
35             OMX_PTR appData,
36             OMX_COMPONENTTYPE **component,
37             enum AVCodecID codecID);
38
39 public:
40     static SoftOMXComponent* createSoftOMXComponent(
41             const char *name, const OMX_CALLBACKTYPE *callbacks,
42             OMX_PTR appData, OMX_COMPONENTTYPE **component);
43
44 protected:
45     virtual ~SoftFFmpegVideo();
46
47     virtual OMX_ERRORTYPE internalGetParameter(
48             OMX_INDEXTYPE index, OMX_PTR params);
49
50     virtual OMX_ERRORTYPE internalSetParameter(
51             OMX_INDEXTYPE index, const OMX_PTR params);
52
53     virtual void onQueueFilled(OMX_U32 portIndex);
54     virtual void onPortFlushCompleted(OMX_U32 portIndex);
55     virtual void onReset();
56
57 private:
58     enum {
59         kInputPortIndex   = 0,
60         kOutputPortIndex  = 1,
61         kNumInputBuffers  = 8,
62         kNumOutputBuffers = 2,
63     };
64
65     enum EOSStatus {
66         INPUT_DATA_AVAILABLE,
67         INPUT_EOS_SEEN,
68         OUTPUT_FRAMES_FLUSHED
69     };
70
71     enum {
72         ERR_NO_FRM              = 2,
73         ERR_FLUSHED             = 1,
74         ERR_OK                  = 0,  //No errors
75         ERR_OOM                 = -1, //Out of memmory
76         ERR_CODEC_NOT_FOUND     = -2,
77         ERR_DECODER_OPEN_FAILED = -2,
78         ERR_SWS_FAILED          = -3,
79     };
80
81     OMX_VIDEO_CODINGTYPE mCodingType;
82     bool mFFmpegAlreadyInited;
83     bool mCodecAlreadyOpened;
84     AVCodecContext *mCtx;
85     struct SwsContext *mImgConvertCtx;
86     AVFrame *mFrame;
87
88     EOSStatus mEOSStatus;
89
90     bool mExtradataReady;
91     bool mIgnoreExtradata;
92     int32_t mStride;
93     int32_t mOutputWidth;
94     int32_t mOutputHeight;
95
96     bool mSignalledError;
97
98     void     initInputFormat(uint32_t mode, OMX_PARAM_PORTDEFINITIONTYPE *def);
99     void     getInputFormat(uint32_t mode, OMX_VIDEO_PARAM_PORTFORMATTYPE *formatParams);
100     void     setDefaultCtx(AVCodecContext *avctx, const AVCodec *codec);
101     OMX_ERRORTYPE isRoleSupported(const OMX_PARAM_COMPONENTROLETYPE *roleParams);
102
103     status_t initDecoder(enum AVCodecID codecID);
104     void     deInitDecoder();
105
106     bool     isPortSettingChanged();
107
108     int32_t  handleExtradata();
109     int32_t  openDecoder();
110     void     initPacket(AVPacket *pkt, OMX_BUFFERHEADERTYPE *inHeader);
111     int32_t  decodeVideo();
112     int32_t  preProcessVideoFrame(AVPicture *picture, void **bufp);
113     int32_t  drainOneOutputBuffer();
114     void     drainEOSOutputBuffer();
115     void     drainAllOutputBuffers();
116     bool     handlePortSettingsChange();
117
118     DISALLOW_EVIL_CONSTRUCTORS(SoftFFmpegVideo);
119 };
120
121 }  // namespace android
122
123 #endif  // SOFT_FFMPEGVIDEO_H_