1/*
2* Copyright (c) 2009-2011 Intel Corporation.  All rights reserved.
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
18
19#ifndef OMX_VIDEO_ENCODER_BASE_H_
20#define OMX_VIDEO_ENCODER_BASE_H_
21
22#include "OMXComponentCodecBase.h"
23#include <va/va_tpi.h>
24#include <va/va_android.h>
25#include <VideoEncoderHost.h>
26
27#include <OMX_VideoExt.h>
28#include <OMX_IndexExt.h>
29
30#define LOGV(...) ALOGI_IF(mOmxLogLevel, __VA_ARGS__)
31#define LOGI(...) ALOGI_IF(mOmxLogLevel, __VA_ARGS__)
32#define LOGW(...) ALOGI_IF(mOmxLogLevel, __VA_ARGS__)
33#define LOGD(...) ALOGI_IF(mOmxLogLevel, __VA_ARGS__)
34#define LOGE ALOGE
35#define LOGV_IF ALOGV_IF
36
37
38using android::sp;
39
40class OMXVideoEncoderBase : public OMXComponentCodecBase {
41public:
42    OMXVideoEncoderBase();
43    virtual ~OMXVideoEncoderBase();
44
45protected:
46    virtual OMX_ERRORTYPE InitInputPort(void);
47    virtual OMX_ERRORTYPE InitOutputPort(void);
48    virtual OMX_ERRORTYPE InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionInput);
49    virtual OMX_ERRORTYPE InitOutputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionOutput) = 0;
50
51    virtual OMX_ERRORTYPE ProcessorInit(void);
52    virtual OMX_ERRORTYPE ProcessorDeinit(void);
53    //virtual OMX_ERRORTYPE ProcessorStart(void);
54    virtual OMX_ERRORTYPE ProcessorStop(void);
55    //virtual OMX_ERRORTYPE ProcessorPause(void);
56    //virtual OMX_ERRORTYPE ProcessorResume(void);
57    virtual OMX_ERRORTYPE ProcessorFlush(OMX_U32 portIndex);
58    virtual OMX_ERRORTYPE ProcessorProcess(
59            OMX_BUFFERHEADERTYPE **buffers,
60            buffer_retain_t *retains,
61            OMX_U32 numberBuffers);
62
63    virtual OMX_ERRORTYPE BuildHandlerList(void);
64
65    DECLARE_HANDLER(OMXVideoEncoderBase, ParamVideoPortFormat);
66    DECLARE_HANDLER(OMXVideoEncoderBase, ParamVideoBitrate);
67    DECLARE_HANDLER(OMXVideoEncoderBase, IntelPrivateInfo);
68    DECLARE_HANDLER(OMXVideoEncoderBase, ConfigIntelBitrate);
69    DECLARE_HANDLER(OMXVideoEncoderBase, ConfigIntelAIR);
70    DECLARE_HANDLER(OMXVideoEncoderBase, ParamVideoIntraRefresh);
71    DECLARE_HANDLER(OMXVideoEncoderBase, ConfigVideoFramerate);
72    DECLARE_HANDLER(OMXVideoEncoderBase, ConfigVideoIntraVOPRefresh);
73    DECLARE_HANDLER(OMXVideoEncoderBase, ParamIntelAdaptiveSliceControl);
74    //DECLARE_HANDLER(OMXVideoEncoderBase, ParamVideoProfileLevelQuerySupported);
75    DECLARE_HANDLER(OMXVideoEncoderBase, StoreMetaDataInBuffers);
76    DECLARE_HANDLER(OMXVideoEncoderBase, SyncEncoding);
77    DECLARE_HANDLER(OMXVideoEncoderBase, PrependSPSPPS);
78    DECLARE_HANDLER(OMXVideoEncoderBase, TemporalLayer);
79    DECLARE_HANDLER(OMXVideoEncoderBase, ConfigVideoBitrate);
80    DECLARE_HANDLER(OMXVideoEncoderBase, BlackFramePointer);
81    DECLARE_HANDLER(OMXVideoEncoderBase, ConfigAndroidIntraRefresh);
82
83protected:
84    virtual OMX_ERRORTYPE SetVideoEncoderParam();
85protected:
86    OMX_VIDEO_PARAM_BITRATETYPE mParamBitrate;
87    OMX_VIDEO_CONFIG_PRI_INFOTYPE mConfigPriInfo;
88    OMX_VIDEO_CONFIG_INTEL_BITRATETYPE mConfigIntelBitrate;
89    OMX_VIDEO_CONFIG_INTEL_AIR mConfigIntelAir;
90    OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE mConfigAndroidIntraRefresh;
91    OMX_VIDEO_PARAM_INTRAREFRESHTYPE mParamVideoRefresh;
92    OMX_CONFIG_FRAMERATETYPE  mConfigFramerate;
93    OMX_VIDEO_PARAM_INTEL_ADAPTIVE_SLICE_CONTROL mParamIntelAdaptiveSliceControl;
94    OMX_VIDEO_PARAM_PROFILELEVELTYPE mParamProfileLevel;
95    OMX_VIDEO_PARAM_INTEL_TEMPORAL_LAYER mTemporalLayer;
96    OMX_VIDEO_CONFIG_BITRATETYPE mConfigBitrate;
97
98    IVideoEncoder *mVideoEncoder;
99    VideoParamsCommon *mEncoderParams;
100    OMX_U32 mFrameInputCount;
101    OMX_U32 mFrameOutputCount;
102    OMX_BOOL mFirstFrame;
103    OMX_BOOL mFrameRetrieved;
104    OMX_BOOL mStoreMetaDataInBuffers;
105    OMX_BOOL mSyncEncoding;
106    int32_t mOmxLogLevel;
107    OMX_PTR mBlackFramePointer;
108
109private:
110
111    enum {
112        // OMX_PARAM_PORTDEFINITIONTYPE
113        INPORT_MIN_BUFFER_COUNT = 1,
114        // FIXME: increate input buffer count to 5
115#ifdef USE_VIDEO_EFFECT
116        INPORT_ACTUAL_BUFFER_COUNT = 5,
117#else
118        INPORT_ACTUAL_BUFFER_COUNT = 2,
119#endif
120        INPORT_BUFFER_SIZE = 1382400,
121
122        // OMX_PARAM_PORTDEFINITIONTYPE
123        OUTPORT_MIN_BUFFER_COUNT = 1,
124        OUTPORT_ACTUAL_BUFFER_COUNT = 2,
125        OUTPORT_BUFFER_SIZE = 1382400,
126    };
127
128};
129
130#endif /* OMX_VIDEO_ENCODER_BASE_H_ */
131