1 /* 2 * 3 * Copyright 2013 Rockchip Electronics Co., LTD. 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 /* 19 * @file Rkvpu_OMX_Venc.h 20 * @brief 21 * @author Csy (csy@rock-chips.com) 22 23 * @version 1.0.0 24 * @history 25 * 2013.11.28 : Create 26 */ 27 28 #ifndef Rkvpu_OMX_VIDEO_ENCODER 29 #define Rkvpu_OMX_VIDEO_ENCODER 30 #include <codec_omx_ext.h> 31 #include "OMX_Component.h" 32 #include "OMX_Video.h" 33 #include "OMX_VideoExt.h" 34 #include "Rockchip_OMX_Basecomponent.h" 35 #include "Rockchip_OMX_Baseport.h" 36 #include "Rockchip_OMX_Def.h" 37 #include "Rockchip_OSAL_Queue.h" 38 #include "VideoExt.h" 39 #include "vpu_api.h" 40 41 #define MAX_VIDEOENC_INPUTBUFFER_NUM 2 42 #define MAX_VIDEOENC_OUTPUTBUFFER_NUM 4 43 44 #define DEFAULT_ENC_FRAME_WIDTH 1920 45 #define DEFAULT_ENC_FRAME_HEIGHT 1080 46 #define DEFAULT_ENC_FRAME_FRAMERATE (25 << 16) 47 #define DEFAULT_ENC_FRAME_BITRATE 3000000 48 49 #define DEFAULT_VIDEOENC_INPUT_BUFFER_SIZE ((DEFAULT_ENC_FRAME_WIDTH * DEFAULT_ENC_FRAME_HEIGHT * 3)/2) 50 #define DEFAULT_VIDEOENC_OUTPUT_BUFFER_SIZE (DEFAULT_ENC_FRAME_WIDTH * DEFAULT_ENC_FRAME_HEIGHT) 51 52 #define OUTPUT_PORT_SUPPORTFORMAT_NUM_MAX 4 53 54 typedef struct _RKVPU_OMX_VIDEOENC_COMPONENT { 55 OMX_HANDLETYPE hCodecHandle; 56 57 OMX_BOOL bFirstFrame; 58 59 OMX_VIDEO_PARAM_AVCTYPE AVCComponent[ALL_PORT_NUM]; 60 61 struct CodecVideoParamHevc HEVCComponent[ALL_PORT_NUM]; 62 63 /* Buffer Process */ 64 OMX_BOOL bExitBufferProcessThread; 65 OMX_HANDLETYPE hInputThread; 66 OMX_HANDLETYPE hOutputThread; 67 68 OMX_VIDEO_CODINGTYPE codecId; 69 70 /* Shared Memory Handle */ 71 OMX_HANDLETYPE hSharedMemory; 72 73 OMX_BOOL configChange; 74 75 OMX_BOOL IntraRefreshVOP; 76 77 OMX_VIDEO_CONTROLRATETYPE eControlRate[ALL_PORT_NUM]; 78 79 OMX_VIDEO_PARAM_QUANTIZATIONTYPE quantization; 80 81 OMX_VIDEO_PARAM_INTRAREFRESHTYPE intraRefresh; 82 83 OMX_VIDEO_PARAMS_EXTENDED params_extend; 84 OMX_BOOL bFirstInput; 85 86 OMX_BOOL bFirstOutput; 87 88 OMX_BOOL bStoreMetaData; 89 90 OMX_BOOL bOhosDynamicBuffer; 91 92 OMX_BOOL bPrependSpsPpsToIdr; 93 94 OMX_BOOL bRkWFD; 95 96 VpuCodecContext_t *vpu_ctx; 97 98 void *rga_ctx; 99 100 OMX_U8 *bSpsPpsbuf; 101 102 OMX_U32 bSpsPpsLen; 103 104 OMX_BOOL bSpsPpsHeaderFlag; 105 106 OMX_BOOL bEncSendEos; 107 108 OMX_U32 bFrame_num; 109 OMX_U32 bCurrent_width; 110 111 OMX_U32 bCurrent_height; 112 113 OMX_U32 bLast_config_frame; 114 115 VPUMemLinear_t *enc_vpumem; 116 117 OMX_HANDLETYPE bScale_Mutex; 118 OMX_HANDLETYPE bRecofig_Mutex; 119 OMX_S32 bPixel_format; 120 OMX_BOOL bRgb2yuvFlag; 121 122 void *rkapi_hdl; 123 // for debug 124 FILE *fp_enc_out; 125 FILE *fp_enc_in; 126 127 // add by xlm for use mpp or vpuapi 128 OMX_BOOL bIsUseMpp; 129 OMX_BOOL bIsNewVpu; 130 #ifdef AVS80 131 OMX_CONFIG_DESCRIBECOLORASPECTSPARAMS ConfigColorAspects; 132 OMX_BOOL bIsCfgColorAsp; 133 ISO_COLORASPECTS *colorAspects; 134 #endif 135 OMX_S32 (*rkvpu_open_cxt)(VpuCodecContext_t **ctx); 136 OMX_S32 (*rkvpu_close_cxt)(VpuCodecContext_t **ctx); 137 138 OMX_ERRORTYPE (*Rkvpu_codec_srcInputProcess) (OMX_COMPONENTTYPE *pOMXComponent, ROCKCHIP_OMX_DATA *pInputData); 139 140 OMX_ERRORTYPE (*Rkvpu_codec_srcOutputProcess) (OMX_COMPONENTTYPE *pOMXComponent, ROCKCHIP_OMX_DATA *pInputData); 141 142 OMX_ERRORTYPE (*Rkvpu_codec_dstInputProcess) (OMX_COMPONENTTYPE *pOMXComponent, ROCKCHIP_OMX_DATA *pOutputData); 143 144 OMX_ERRORTYPE (*Rkvpu_codec_dstOutputProcess) (OMX_COMPONENTTYPE *pOMXComponent, ROCKCHIP_OMX_DATA *pOutputData); 145 } RKVPU_OMX_VIDEOENC_COMPONENT; 146 147 #ifdef __cplusplus 148 extern "C" { 149 #endif 150 151 int calc_plane(int width, int height); 152 void UpdateFrameSize(OMX_COMPONENTTYPE *pOMXComponent); 153 OMX_BOOL Rkvpu_Check_BufferProcess_State(ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent, OMX_U32 nPortIndex); 154 155 OMX_ERRORTYPE Rkvpu_OMX_InputBufferProcess(OMX_HANDLETYPE hComponent); 156 OMX_ERRORTYPE Rkvpu_OMX_OutputBufferProcess(OMX_HANDLETYPE hComponent); 157 OMX_ERRORTYPE Rkvpu_Enc_ComponentInit(OMX_COMPONENTTYPE *pOMXComponent); 158 OMX_ERRORTYPE Rkvpu_Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent); 159 OMX_ERRORTYPE Rkvpu_Enc_GetEncParams(OMX_COMPONENTTYPE *pOMXComponent, EncParameter_t **encParams); 160 161 OMX_ERRORTYPE Rockchip_OMX_ComponentConstructor(OMX_HANDLETYPE hComponent, OMX_STRING componentName); 162 OMX_ERRORTYPE Rockchip_OMX_ComponentDeInit(OMX_HANDLETYPE hComponent); 163 164 #ifdef __cplusplus 165 } 166 #endif 167 168 #endif