Commit | Line | Data |
---|---|---|
20d3e6e3 JC |
1 | /* |
2 | * | |
38ef2572 | 3 | * Copyright 2012 Samsung Electronics S.LSI Co. LTD |
20d3e6e3 JC |
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 Exynos_OMX_H264enc.c | |
20 | * @brief | |
21 | * @author SeungBeom Kim (sbcrux.kim@samsung.com) | |
38ef2572 | 22 | * @version 2.0.0 |
20d3e6e3 | 23 | * @history |
38ef2572 | 24 | * 2012.02.20 : Create |
20d3e6e3 JC |
25 | */ |
26 | ||
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | ||
31 | #include "Exynos_OMX_Macros.h" | |
32 | #include "Exynos_OMX_Basecomponent.h" | |
33 | #include "Exynos_OMX_Baseport.h" | |
34 | #include "Exynos_OMX_Venc.h" | |
35 | #include "Exynos_OSAL_ETC.h" | |
36 | #include "Exynos_OSAL_Semaphore.h" | |
37 | #include "Exynos_OSAL_Thread.h" | |
38 | #include "Exynos_OSAL_Android.h" | |
39 | #include "library_register.h" | |
40 | #include "Exynos_OMX_H264enc.h" | |
41 | #include "ExynosVideoApi.h" | |
38ef2572 JC |
42 | #include "Exynos_OSAL_SharedMemory.h" |
43 | #include "Exynos_OSAL_Event.h" | |
44 | ||
45 | /* To use CSC_METHOD_HW in EXYNOS OMX, gralloc should allocate physical memory using FIMC */ | |
46 | /* It means GRALLOC_USAGE_HW_FIMC1 should be set on Native Window usage */ | |
20d3e6e3 JC |
47 | #include "csc.h" |
48 | ||
49 | #undef EXYNOS_LOG_TAG | |
50 | #define EXYNOS_LOG_TAG "EXYNOS_H264_ENC" | |
51 | #define EXYNOS_LOG_OFF | |
38ef2572 | 52 | //#define EXYNOS_TRACE_ON |
20d3e6e3 JC |
53 | #include "Exynos_OSAL_Log.h" |
54 | ||
55 | /* H.264 Encoder Supported Levels & profiles */ | |
56 | EXYNOS_OMX_VIDEO_PROFILELEVEL supportedAVCProfileLevels[] ={ | |
57 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1}, | |
58 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel1b}, | |
59 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel11}, | |
60 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel12}, | |
61 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel13}, | |
62 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel2}, | |
63 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel21}, | |
64 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel22}, | |
65 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel3}, | |
66 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel31}, | |
67 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel32}, | |
68 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel4}, | |
800a8d75 JC |
69 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel41}, |
70 | {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel42}, | |
20d3e6e3 JC |
71 | |
72 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel1}, | |
73 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel1b}, | |
74 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel11}, | |
75 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel12}, | |
76 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel13}, | |
77 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel2}, | |
78 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel21}, | |
79 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel22}, | |
80 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel3}, | |
81 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel31}, | |
82 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel32}, | |
83 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel4}, | |
800a8d75 JC |
84 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel41}, |
85 | {OMX_VIDEO_AVCProfileMain, OMX_VIDEO_AVCLevel42}, | |
20d3e6e3 JC |
86 | |
87 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel1}, | |
88 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel1b}, | |
89 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel11}, | |
90 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel12}, | |
91 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel13}, | |
92 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel2}, | |
93 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel21}, | |
94 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel22}, | |
95 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel3}, | |
96 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel31}, | |
97 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel32}, | |
800a8d75 JC |
98 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel4}, |
99 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel41}, | |
100 | {OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_AVCLevel42}}; | |
20d3e6e3 | 101 | |
800a8d75 | 102 | static OMX_U32 OMXAVCProfileToProfileIDC(OMX_VIDEO_AVCPROFILETYPE profile) |
20d3e6e3 | 103 | { |
800a8d75 | 104 | OMX_U32 ret = 0; |
20d3e6e3 | 105 | |
800a8d75 | 106 | if (profile == OMX_VIDEO_AVCProfileBaseline) |
20d3e6e3 | 107 | ret = 0; |
800a8d75 | 108 | else if (profile == OMX_VIDEO_AVCProfileMain) |
20d3e6e3 | 109 | ret = 2; |
800a8d75 JC |
110 | else if (profile == OMX_VIDEO_AVCProfileHigh) |
111 | ret = 4; | |
20d3e6e3 JC |
112 | |
113 | return ret; | |
114 | } | |
115 | ||
800a8d75 | 116 | static OMX_U32 OMXAVCLevelToLevelIDC(OMX_VIDEO_AVCLEVELTYPE level) |
20d3e6e3 | 117 | { |
800a8d75 | 118 | OMX_U32 ret = 11; //default OMX_VIDEO_AVCLevel4 |
20d3e6e3 JC |
119 | |
120 | if (level == OMX_VIDEO_AVCLevel1) | |
800a8d75 | 121 | ret = 0; |
20d3e6e3 | 122 | else if (level == OMX_VIDEO_AVCLevel1b) |
800a8d75 | 123 | ret = 1; |
20d3e6e3 | 124 | else if (level == OMX_VIDEO_AVCLevel11) |
800a8d75 | 125 | ret = 2; |
20d3e6e3 | 126 | else if (level == OMX_VIDEO_AVCLevel12) |
800a8d75 | 127 | ret = 3; |
20d3e6e3 | 128 | else if (level == OMX_VIDEO_AVCLevel13) |
800a8d75 | 129 | ret = 4; |
20d3e6e3 | 130 | else if (level == OMX_VIDEO_AVCLevel2) |
800a8d75 | 131 | ret = 5; |
20d3e6e3 | 132 | else if (level == OMX_VIDEO_AVCLevel21) |
800a8d75 | 133 | ret = 6; |
20d3e6e3 | 134 | else if (level == OMX_VIDEO_AVCLevel22) |
800a8d75 | 135 | ret = 7; |
20d3e6e3 | 136 | else if (level == OMX_VIDEO_AVCLevel3) |
800a8d75 | 137 | ret = 8; |
20d3e6e3 | 138 | else if (level == OMX_VIDEO_AVCLevel31) |
800a8d75 | 139 | ret = 9; |
20d3e6e3 | 140 | else if (level == OMX_VIDEO_AVCLevel32) |
800a8d75 | 141 | ret = 10; |
20d3e6e3 | 142 | else if (level == OMX_VIDEO_AVCLevel4) |
800a8d75 JC |
143 | ret = 11; |
144 | else if (level == OMX_VIDEO_AVCLevel41) | |
145 | ret = 12; | |
146 | else if (level == OMX_VIDEO_AVCLevel42) | |
147 | ret = 13; | |
20d3e6e3 JC |
148 | |
149 | return ret; | |
150 | } | |
151 | ||
800a8d75 | 152 | static OMX_U8 *FindDelimiter(OMX_U8 *pBuffer, OMX_U32 size) |
20d3e6e3 JC |
153 | { |
154 | OMX_U32 i; | |
155 | ||
156 | for (i = 0; i < size - 3; i++) { | |
157 | if ((pBuffer[i] == 0x00) && | |
158 | (pBuffer[i + 1] == 0x00) && | |
159 | (pBuffer[i + 2] == 0x00) && | |
160 | (pBuffer[i + 3] == 0x01)) | |
161 | return (pBuffer + i); | |
162 | } | |
163 | ||
164 | return NULL; | |
165 | } | |
166 | ||
800a8d75 | 167 | static void Print_H264Enc_Param(ExynosVideoEncParam *pEncParam) |
20d3e6e3 JC |
168 | { |
169 | ExynosVideoEncCommonParam *pCommonParam = &pEncParam->commonParam; | |
170 | ExynosVideoEncH264Param *pH264Param = &pEncParam->codecParam.h264; | |
171 | ||
172 | /* common parameters */ | |
173 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "SourceWidth : %d", pCommonParam->SourceWidth); | |
174 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "SourceHeight : %d", pCommonParam->SourceHeight); | |
175 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "IDRPeriod : %d", pCommonParam->IDRPeriod); | |
176 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "SliceMode : %d", pCommonParam->SliceMode); | |
177 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "RandomIntraMBRefresh : %d", pCommonParam->RandomIntraMBRefresh); | |
178 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Bitrate : %d", pCommonParam->Bitrate); | |
179 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "FrameQp : %d", pCommonParam->FrameQp); | |
180 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "FrameQp_P : %d", pCommonParam->FrameQp_P); | |
181 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "QSCodeMax : %d", pCommonParam->QSCodeMax); | |
182 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "QSCodeMin : %d", pCommonParam->QSCodeMin); | |
183 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "PadControlOn : %d", pCommonParam->PadControlOn); | |
184 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "LumaPadVal : %d", pCommonParam->LumaPadVal); | |
185 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "CbPadVal : %d", pCommonParam->CbPadVal); | |
186 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "CrPadVal : %d", pCommonParam->CrPadVal); | |
187 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "FrameMap : %d", pCommonParam->FrameMap); | |
188 | ||
189 | /* H.264 specific parameters */ | |
190 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "ProfileIDC : %d", pH264Param->ProfileIDC); | |
191 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "LevelIDC : %d", pH264Param->LevelIDC); | |
192 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "FrameQp_B : %d", pH264Param->FrameQp_B); | |
193 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "FrameRate : %d", pH264Param->FrameRate); | |
194 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "SliceArgument : %d", pH264Param->SliceArgument); | |
195 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NumberBFrames : %d", pH264Param->NumberBFrames); | |
196 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NumberReferenceFrames : %d", pH264Param->NumberReferenceFrames); | |
197 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "NumberRefForPframes : %d", pH264Param->NumberRefForPframes); | |
198 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "LoopFilterDisable : %d", pH264Param->LoopFilterDisable); | |
199 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "LoopFilterAlphaC0Offset : %d", pH264Param->LoopFilterAlphaC0Offset); | |
200 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "LoopFilterBetaOffset : %d", pH264Param->LoopFilterBetaOffset); | |
201 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "SymbolMode : %d", pH264Param->SymbolMode); | |
202 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "PictureInterlace : %d", pH264Param->PictureInterlace); | |
203 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Transform8x8Mode : %d", pH264Param->Transform8x8Mode); | |
204 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "DarkDisable : %d", pH264Param->DarkDisable); | |
205 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "SmoothDisable : %d", pH264Param->SmoothDisable); | |
206 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "StaticDisable : %d", pH264Param->StaticDisable); | |
207 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "ActivityDisable : %d", pH264Param->ActivityDisable); | |
208 | ||
209 | /* rate control related parameters */ | |
210 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "EnableFRMRateControl : %d", pCommonParam->EnableFRMRateControl); | |
800a8d75 | 211 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "EnableMBRateControl : %d", pCommonParam->EnableMBRateControl); |
20d3e6e3 JC |
212 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "CBRPeriodRf : %d", pCommonParam->CBRPeriodRf); |
213 | } | |
214 | ||
800a8d75 | 215 | static void Set_H264Enc_Param(EXYNOS_OMX_BASECOMPONENT *pExynosComponent) |
20d3e6e3 JC |
216 | { |
217 | EXYNOS_OMX_BASEPORT *pExynosInputPort = NULL; | |
218 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = NULL; | |
219 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; | |
220 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
38ef2572 | 221 | EXYNOS_MFC_H264ENC_HANDLE *pMFCH264Handle = NULL; |
20d3e6e3 JC |
222 | |
223 | ExynosVideoEncParam *pEncParam = NULL; | |
224 | ExynosVideoEncCommonParam *pCommonParam = NULL; | |
225 | ExynosVideoEncH264Param *pH264Param = NULL; | |
226 | ||
227 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
228 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
38ef2572 | 229 | pMFCH264Handle = &pH264Enc->hMFCH264Handle; |
20d3e6e3 JC |
230 | pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; |
231 | pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
232 | ||
38ef2572 | 233 | pEncParam = &pMFCH264Handle->encParam; |
20d3e6e3 JC |
234 | pCommonParam = &pEncParam->commonParam; |
235 | pH264Param = &pEncParam->codecParam.h264; | |
236 | pEncParam->eCompressionFormat = VIDEO_CODING_AVC; | |
237 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "eCompressionFormat: %d", pEncParam->eCompressionFormat); | |
238 | ||
239 | /* common parameters */ | |
240 | pCommonParam->SourceWidth = pExynosOutputPort->portDefinition.format.video.nFrameWidth; | |
241 | pCommonParam->SourceHeight = pExynosOutputPort->portDefinition.format.video.nFrameHeight; | |
242 | pCommonParam->IDRPeriod = pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].nPFrames + 1; | |
243 | pCommonParam->SliceMode = 0; | |
244 | pCommonParam->RandomIntraMBRefresh = 0; | |
245 | pCommonParam->Bitrate = pExynosOutputPort->portDefinition.format.video.nBitrate; | |
246 | pCommonParam->FrameQp = pVideoEnc->quantization.nQpI; | |
247 | pCommonParam->FrameQp_P = pVideoEnc->quantization.nQpP; | |
248 | pCommonParam->QSCodeMax = 51; | |
249 | pCommonParam->QSCodeMin = 10; | |
250 | pCommonParam->PadControlOn = 0; /* 0: disable, 1: enable */ | |
251 | pCommonParam->LumaPadVal = 0; | |
252 | pCommonParam->CbPadVal = 0; | |
253 | pCommonParam->CrPadVal = 0; | |
254 | ||
255 | switch ((EXYNOS_OMX_COLOR_FORMATTYPE)pExynosInputPort->portDefinition.format.video.eColorFormat) { | |
20d3e6e3 | 256 | case OMX_COLOR_FormatYUV420SemiPlanar: |
38ef2572 | 257 | case OMX_COLOR_FormatYUV420Planar: /* Converted to NV12 in Exynos_Preprocessor_InputData */ |
20d3e6e3 JC |
258 | #ifdef USE_METADATABUFFERTYPE |
259 | case OMX_COLOR_FormatAndroidOpaque: | |
260 | #endif | |
261 | pCommonParam->FrameMap = VIDEO_COLORFORMAT_NV12; | |
262 | break; | |
20d3e6e3 JC |
263 | case OMX_SEC_COLOR_FormatNV12Tiled: |
264 | pCommonParam->FrameMap = VIDEO_COLORFORMAT_NV12_TILED; | |
265 | break; | |
20d3e6e3 JC |
266 | case OMX_SEC_COLOR_FormatNV21Linear: |
267 | pCommonParam->FrameMap = VIDEO_COLORFORMAT_NV21; | |
268 | break; | |
269 | default: | |
270 | pCommonParam->FrameMap = VIDEO_COLORFORMAT_NV12_TILED; | |
271 | break; | |
272 | } | |
273 | ||
274 | /* H.264 specific parameters */ | |
275 | pH264Param->ProfileIDC = OMXAVCProfileToProfileIDC(pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].eProfile); /*0: OMX_VIDEO_AVCProfileMain */ | |
276 | pH264Param->LevelIDC = OMXAVCLevelToLevelIDC(pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].eLevel); /*40: OMX_VIDEO_AVCLevel4 */ | |
277 | pH264Param->FrameQp_B = pVideoEnc->quantization.nQpB; | |
278 | pH264Param->FrameRate = (pExynosInputPort->portDefinition.format.video.xFramerate) >> 16; | |
279 | pH264Param->SliceArgument = 0; /* Slice mb/byte size number */ | |
280 | pH264Param->NumberBFrames = 0; /* 0 ~ 2 */ | |
281 | pH264Param->NumberReferenceFrames = 1; | |
282 | pH264Param->NumberRefForPframes = 1; | |
283 | pH264Param->LoopFilterDisable = 1; /* 1: Loop Filter Disable, 0: Filter Enable */ | |
284 | pH264Param->LoopFilterAlphaC0Offset = 0; | |
285 | pH264Param->LoopFilterBetaOffset = 0; | |
286 | pH264Param->SymbolMode = 0; /* 0: CAVLC, 1: CABAC */ | |
287 | pH264Param->PictureInterlace = 0; | |
288 | pH264Param->Transform8x8Mode = 0; /* 0: 4x4, 1: allow 8x8 */ | |
289 | pH264Param->DarkDisable = 1; | |
290 | pH264Param->SmoothDisable = 1; | |
291 | pH264Param->StaticDisable = 1; | |
292 | pH264Param->ActivityDisable = 1; | |
293 | ||
294 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->eControlRate[OUTPUT_PORT_INDEX]: 0x%x", pVideoEnc->eControlRate[OUTPUT_PORT_INDEX]); | |
295 | /* rate control related parameters */ | |
296 | switch (pVideoEnc->eControlRate[OUTPUT_PORT_INDEX]) { | |
297 | case OMX_Video_ControlRateVariable: | |
298 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Video Encode VBR"); | |
299 | pCommonParam->EnableFRMRateControl = 0; /* 0: Disable, 1: Frame level RC */ | |
800a8d75 | 300 | pCommonParam->EnableMBRateControl = 0; /* 0: Disable, 1:MB level RC */ |
20d3e6e3 JC |
301 | pCommonParam->CBRPeriodRf = 100; |
302 | break; | |
303 | case OMX_Video_ControlRateConstant: | |
304 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Video Encode CBR"); | |
305 | pCommonParam->EnableFRMRateControl = 1; /* 0: Disable, 1: Frame level RC */ | |
800a8d75 | 306 | pCommonParam->EnableMBRateControl = 1; /* 0: Disable, 1:MB level RC */ |
20d3e6e3 JC |
307 | pCommonParam->CBRPeriodRf = 10; |
308 | break; | |
309 | case OMX_Video_ControlRateDisable: | |
310 | default: /*Android default */ | |
311 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Video Encode VBR"); | |
312 | pCommonParam->EnableFRMRateControl = 0; | |
800a8d75 | 313 | pCommonParam->EnableMBRateControl = 0; |
20d3e6e3 JC |
314 | pCommonParam->CBRPeriodRf = 100; |
315 | break; | |
316 | } | |
317 | ||
318 | Print_H264Enc_Param(pEncParam); | |
20d3e6e3 JC |
319 | } |
320 | ||
800a8d75 | 321 | static void Change_H264Enc_Param(EXYNOS_OMX_BASECOMPONENT *pExynosComponent) |
20d3e6e3 JC |
322 | { |
323 | EXYNOS_OMX_BASEPORT *pExynosInputPort = NULL; | |
324 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = NULL; | |
325 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; | |
326 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
38ef2572 | 327 | EXYNOS_MFC_H264ENC_HANDLE *pMFCH264Handle = NULL; |
20d3e6e3 JC |
328 | |
329 | ExynosVideoEncOps *pEncOps = NULL; | |
330 | ExynosVideoEncParam *pEncParam = NULL; | |
331 | ExynosVideoEncCommonParam *pCommonParam = NULL; | |
332 | ExynosVideoEncH264Param *pH264Param = NULL; | |
333 | ||
334 | int setParam = 0; | |
335 | ||
336 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
337 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
38ef2572 | 338 | pMFCH264Handle = &pH264Enc->hMFCH264Handle; |
20d3e6e3 JC |
339 | pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; |
340 | pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
38ef2572 | 341 | pEncOps = pMFCH264Handle->pEncOps; |
20d3e6e3 | 342 | |
38ef2572 | 343 | pEncParam = &pMFCH264Handle->encParam; |
20d3e6e3 JC |
344 | pCommonParam = &pEncParam->commonParam; |
345 | pH264Param = &pEncParam->codecParam.h264; | |
346 | ||
347 | if (pVideoEnc->IntraRefreshVOP == OMX_TRUE) { | |
348 | setParam = VIDEO_FRAME_I; | |
349 | pEncOps->Set_FrameType(pH264Enc->hMFCH264Handle.hMFCHandle, setParam); | |
350 | pVideoEnc->IntraRefreshVOP = OMX_FALSE; | |
351 | } | |
352 | if (pCommonParam->IDRPeriod != (int)pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].nPFrames + 1) { | |
353 | setParam = pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].nPFrames + 1; | |
354 | pEncOps->Set_IDRPeriod(pH264Enc->hMFCH264Handle.hMFCHandle, setParam); | |
355 | } | |
356 | if (pCommonParam->Bitrate != (int)pExynosOutputPort->portDefinition.format.video.nBitrate) { | |
357 | setParam = pExynosOutputPort->portDefinition.format.video.nBitrate; | |
358 | pEncOps->Set_BitRate(pH264Enc->hMFCH264Handle.hMFCHandle, setParam); | |
359 | } | |
360 | if (pH264Param->FrameRate != (int)((pExynosOutputPort->portDefinition.format.video.xFramerate) >> 16)) { | |
361 | setParam = (pExynosInputPort->portDefinition.format.video.xFramerate) >> 16; | |
362 | pEncOps->Set_FrameRate(pH264Enc->hMFCH264Handle.hMFCHandle, setParam); | |
363 | } | |
364 | ||
365 | Set_H264Enc_Param(pExynosComponent); | |
366 | } | |
367 | ||
38ef2572 | 368 | OMX_ERRORTYPE GetCodecInputPrivateData(OMX_PTR codecBuffer, OMX_PTR addr[], OMX_U32 size[]) |
20d3e6e3 | 369 | { |
38ef2572 | 370 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
20d3e6e3 | 371 | |
38ef2572 JC |
372 | EXIT: |
373 | return ret; | |
374 | } | |
20d3e6e3 | 375 | |
38ef2572 JC |
376 | OMX_ERRORTYPE GetCodecOutputPrivateData(OMX_PTR codecBuffer, OMX_PTR *pVirtAddr, OMX_U32 *dataSize) |
377 | { | |
378 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
379 | ExynosVideoBuffer *pCodecBuffer; | |
380 | ||
381 | if (codecBuffer == NULL) { | |
20d3e6e3 JC |
382 | ret = OMX_ErrorBadParameter; |
383 | goto EXIT; | |
384 | } | |
38ef2572 JC |
385 | |
386 | pCodecBuffer = (ExynosVideoBuffer *)codecBuffer; | |
387 | ||
388 | if (pVirtAddr != NULL) | |
389 | *pVirtAddr = pCodecBuffer->planes[0].addr; | |
390 | ||
391 | if (dataSize != NULL) | |
392 | *dataSize = pCodecBuffer->planes[0].allocSize; | |
393 | ||
394 | pCodecBuffer = (ExynosVideoBuffer *)codecBuffer; | |
395 | ||
396 | EXIT: | |
397 | return ret; | |
398 | } | |
399 | ||
400 | OMX_ERRORTYPE H264CodecOpen(EXYNOS_H264ENC_HANDLE *pH264Enc) | |
401 | { | |
402 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
403 | ||
404 | ExynosVideoEncOps *pEncOps = NULL; | |
405 | ExynosVideoEncBufferOps *pInbufOps = NULL; | |
406 | ExynosVideoEncBufferOps *pOutbufOps = NULL; | |
407 | ||
408 | FunctionIn(); | |
409 | ||
410 | if (pH264Enc == NULL) { | |
20d3e6e3 | 411 | ret = OMX_ErrorBadParameter; |
38ef2572 | 412 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); |
20d3e6e3 JC |
413 | goto EXIT; |
414 | } | |
415 | ||
38ef2572 JC |
416 | /* alloc ops structure */ |
417 | pEncOps = (ExynosVideoEncOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoEncOps)); | |
418 | pInbufOps = (ExynosVideoEncBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoEncBufferOps)); | |
419 | pOutbufOps = (ExynosVideoEncBufferOps *)Exynos_OSAL_Malloc(sizeof(ExynosVideoEncBufferOps)); | |
420 | ||
421 | if ((pEncOps == NULL) || (pInbufOps == NULL) || (pOutbufOps == NULL)) { | |
422 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate encoder ops buffer"); | |
423 | ret = OMX_ErrorInsufficientResources; | |
20d3e6e3 JC |
424 | goto EXIT; |
425 | } | |
426 | ||
38ef2572 JC |
427 | pH264Enc->hMFCH264Handle.pEncOps = pEncOps; |
428 | pH264Enc->hMFCH264Handle.pInbufOps = pInbufOps; | |
429 | pH264Enc->hMFCH264Handle.pOutbufOps = pOutbufOps; | |
20d3e6e3 | 430 | |
38ef2572 JC |
431 | /* function pointer mapping */ |
432 | pEncOps->nSize = sizeof(ExynosVideoEncOps); | |
433 | pInbufOps->nSize = sizeof(ExynosVideoEncBufferOps); | |
434 | pOutbufOps->nSize = sizeof(ExynosVideoEncBufferOps); | |
20d3e6e3 | 435 | |
38ef2572 | 436 | Exynos_Video_Register_Encoder(pEncOps, pInbufOps, pOutbufOps); |
20d3e6e3 | 437 | |
38ef2572 JC |
438 | /* check mandatory functions for encoder ops */ |
439 | if ((pEncOps->Init == NULL) || (pEncOps->Finalize == NULL) || | |
440 | (pEncOps->Set_FrameTag == NULL) || (pEncOps->Get_FrameTag == NULL)) { | |
441 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied"); | |
442 | ret = OMX_ErrorInsufficientResources; | |
443 | goto EXIT; | |
444 | } | |
20d3e6e3 | 445 | |
38ef2572 JC |
446 | /* check mandatory functions for buffer ops */ |
447 | if ((pInbufOps->Setup == NULL) || (pOutbufOps->Setup == NULL) || | |
448 | (pInbufOps->Run == NULL) || (pOutbufOps->Run == NULL) || | |
449 | (pInbufOps->Stop == NULL) || (pOutbufOps->Stop == NULL) || | |
450 | (pInbufOps->Enqueue == NULL) || (pOutbufOps->Enqueue == NULL) || | |
451 | (pInbufOps->Dequeue == NULL) || (pOutbufOps->Dequeue == NULL)) { | |
452 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Mandatory functions must be supplied"); | |
453 | ret = OMX_ErrorInsufficientResources; | |
454 | goto EXIT; | |
20d3e6e3 | 455 | } |
20d3e6e3 | 456 | |
38ef2572 | 457 | /* alloc context, open, querycap */ |
c94beaeb | 458 | pH264Enc->hMFCH264Handle.hMFCHandle = pH264Enc->hMFCH264Handle.pEncOps->Init(V4L2_MEMORY_DMABUF); |
38ef2572 JC |
459 | if (pH264Enc->hMFCH264Handle.hMFCHandle == NULL) { |
460 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to allocate context buffer"); | |
461 | ret = OMX_ErrorInsufficientResources; | |
462 | goto EXIT; | |
20d3e6e3 | 463 | } |
20d3e6e3 | 464 | |
38ef2572 | 465 | ret = OMX_ErrorNone; |
20d3e6e3 | 466 | |
38ef2572 JC |
467 | EXIT: |
468 | FunctionOut(); | |
20d3e6e3 | 469 | |
38ef2572 JC |
470 | return ret; |
471 | } | |
20d3e6e3 | 472 | |
38ef2572 JC |
473 | OMX_ERRORTYPE H264CodecClose(EXYNOS_H264ENC_HANDLE *pH264Enc) |
474 | { | |
475 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
476 | void *hMFCHandle = NULL; | |
477 | ExynosVideoEncOps *pEncOps = NULL; | |
478 | ExynosVideoEncBufferOps *pInbufOps = NULL; | |
479 | ExynosVideoEncBufferOps *pOutbufOps = NULL; | |
20d3e6e3 | 480 | |
3e79a27e SK |
481 | FunctionIn(); |
482 | ||
38ef2572 JC |
483 | if (pH264Enc == NULL) { |
484 | ret = OMX_ErrorBadParameter; | |
485 | goto EXIT; | |
20d3e6e3 | 486 | } |
20d3e6e3 | 487 | |
38ef2572 JC |
488 | hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; |
489 | pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
490 | pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
491 | pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
20d3e6e3 | 492 | |
38ef2572 JC |
493 | if (hMFCHandle != NULL) { |
494 | pEncOps->Finalize(hMFCHandle); | |
495 | hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle = NULL; | |
496 | } | |
497 | if (pOutbufOps != NULL) { | |
498 | Exynos_OSAL_Free(pOutbufOps); | |
499 | pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps = NULL; | |
500 | } | |
501 | if (pInbufOps != NULL) { | |
502 | Exynos_OSAL_Free(pInbufOps); | |
503 | pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps = NULL; | |
504 | } | |
505 | if (pEncOps != NULL) { | |
506 | Exynos_OSAL_Free(pEncOps); | |
507 | pEncOps = pH264Enc->hMFCH264Handle.pEncOps = NULL; | |
508 | } | |
20d3e6e3 | 509 | |
38ef2572 | 510 | ret = OMX_ErrorNone; |
20d3e6e3 | 511 | |
38ef2572 JC |
512 | EXIT: |
513 | FunctionOut(); | |
20d3e6e3 | 514 | |
38ef2572 JC |
515 | return ret; |
516 | } | |
20d3e6e3 | 517 | |
38ef2572 JC |
518 | OMX_ERRORTYPE H264CodecStart(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) |
519 | { | |
520 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
521 | void *hMFCHandle = NULL; | |
522 | ExynosVideoEncOps *pEncOps = NULL; | |
523 | ExynosVideoEncBufferOps *pInbufOps = NULL; | |
524 | ExynosVideoEncBufferOps *pOutbufOps = NULL; | |
525 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; | |
526 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
20d3e6e3 | 527 | |
38ef2572 | 528 | FunctionIn(); |
20d3e6e3 | 529 | |
38ef2572 JC |
530 | if (pOMXComponent == NULL) { |
531 | ret = OMX_ErrorBadParameter; | |
532 | goto EXIT; | |
20d3e6e3 | 533 | } |
38ef2572 JC |
534 | |
535 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle; | |
536 | if (pVideoEnc == NULL) { | |
537 | ret = OMX_ErrorBadParameter; | |
538 | goto EXIT; | |
539 | } | |
540 | ||
541 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)pVideoEnc->hCodecHandle; | |
542 | if (pH264Enc == NULL) { | |
543 | ret = OMX_ErrorBadParameter; | |
544 | goto EXIT; | |
20d3e6e3 | 545 | } |
38ef2572 JC |
546 | |
547 | hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
548 | pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
549 | pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
550 | pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
551 | ||
552 | if (nPortIndex == INPUT_PORT_INDEX) | |
553 | pInbufOps->Run(hMFCHandle); | |
554 | else if (nPortIndex == OUTPUT_PORT_INDEX) | |
555 | pOutbufOps->Run(hMFCHandle); | |
556 | ||
557 | ret = OMX_ErrorNone; | |
558 | ||
20d3e6e3 JC |
559 | EXIT: |
560 | FunctionOut(); | |
561 | ||
562 | return ret; | |
563 | } | |
564 | ||
38ef2572 | 565 | OMX_ERRORTYPE H264CodecStop(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) |
20d3e6e3 | 566 | { |
38ef2572 JC |
567 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
568 | void *hMFCHandle = NULL; | |
569 | ExynosVideoEncOps *pEncOps = NULL; | |
570 | ExynosVideoEncBufferOps *pInbufOps = NULL; | |
571 | ExynosVideoEncBufferOps *pOutbufOps = NULL; | |
572 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; | |
573 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
20d3e6e3 JC |
574 | |
575 | FunctionIn(); | |
576 | ||
38ef2572 | 577 | if (pOMXComponent == NULL) { |
20d3e6e3 JC |
578 | ret = OMX_ErrorBadParameter; |
579 | goto EXIT; | |
580 | } | |
38ef2572 JC |
581 | |
582 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle; | |
583 | if (pVideoEnc == NULL) { | |
584 | ret = OMX_ErrorBadParameter; | |
20d3e6e3 JC |
585 | goto EXIT; |
586 | } | |
38ef2572 JC |
587 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)pVideoEnc->hCodecHandle; |
588 | if (pH264Enc == NULL) { | |
20d3e6e3 JC |
589 | ret = OMX_ErrorBadParameter; |
590 | goto EXIT; | |
591 | } | |
592 | ||
38ef2572 JC |
593 | hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; |
594 | pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
595 | pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
596 | pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
20d3e6e3 | 597 | |
38ef2572 JC |
598 | if ((nPortIndex == INPUT_PORT_INDEX) && (pInbufOps != NULL)) |
599 | pInbufOps->Stop(hMFCHandle); | |
600 | else if ((nPortIndex == OUTPUT_PORT_INDEX) && (pOutbufOps != NULL)) | |
601 | pOutbufOps->Stop(hMFCHandle); | |
20d3e6e3 | 602 | |
38ef2572 | 603 | ret = OMX_ErrorNone; |
20d3e6e3 | 604 | |
38ef2572 JC |
605 | EXIT: |
606 | FunctionOut(); | |
20d3e6e3 | 607 | |
38ef2572 JC |
608 | return ret; |
609 | } | |
20d3e6e3 | 610 | |
38ef2572 JC |
611 | OMX_ERRORTYPE H264CodecOutputBufferProcessRun(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) |
612 | { | |
613 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
614 | void *hMFCHandle = NULL; | |
615 | ExynosVideoEncOps *pEncOps = NULL; | |
616 | ExynosVideoEncBufferOps *pInbufOps = NULL; | |
617 | ExynosVideoEncBufferOps *pOutbufOps = NULL; | |
618 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; | |
619 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
620 | ||
621 | FunctionIn(); | |
622 | ||
623 | if (pOMXComponent == NULL) { | |
624 | ret = OMX_ErrorBadParameter; | |
625 | goto EXIT; | |
626 | } | |
627 | ||
628 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)((EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate)->hComponentHandle; | |
629 | if (pVideoEnc == NULL) { | |
630 | ret = OMX_ErrorBadParameter; | |
631 | goto EXIT; | |
632 | } | |
633 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)pVideoEnc->hCodecHandle; | |
634 | if (pH264Enc == NULL) { | |
635 | ret = OMX_ErrorBadParameter; | |
636 | goto EXIT; | |
637 | } | |
638 | ||
639 | hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
640 | pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
641 | pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
642 | pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
643 | ||
644 | if (nPortIndex == INPUT_PORT_INDEX) { | |
645 | if (pH264Enc->bSourceStart == OMX_FALSE) { | |
646 | Exynos_OSAL_SignalSet(pH264Enc->hSourceStartEvent); | |
647 | Exynos_OSAL_SleepMillisec(0); | |
648 | } | |
649 | } | |
650 | ||
651 | if (nPortIndex == OUTPUT_PORT_INDEX) { | |
652 | if (pH264Enc->bDestinationStart == OMX_FALSE) { | |
653 | Exynos_OSAL_SignalSet(pH264Enc->hDestinationStartEvent); | |
654 | Exynos_OSAL_SleepMillisec(0); | |
655 | } | |
656 | } | |
657 | ||
658 | ret = OMX_ErrorNone; | |
659 | ||
660 | EXIT: | |
661 | FunctionOut(); | |
662 | ||
663 | return ret; | |
664 | } | |
665 | ||
666 | OMX_ERRORTYPE H264CodecEnQueueAllBuffer(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 nPortIndex) | |
667 | { | |
668 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
669 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
670 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
671 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
672 | void *hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
673 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
674 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
675 | int i, nOutbufs; | |
38ef2572 JC |
676 | |
677 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
678 | ExynosVideoEncBufferOps *pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
679 | ExynosVideoEncBufferOps *pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
680 | ||
681 | FunctionIn(); | |
682 | ||
683 | if ((nPortIndex == INPUT_PORT_INDEX) && | |
684 | (pH264Enc->bSourceStart == OMX_TRUE)) { | |
38ef2572 | 685 | Exynos_CodecBufferReset(pExynosComponent, INPUT_PORT_INDEX); |
38ef2572 JC |
686 | |
687 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { | |
688 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]); | |
689 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->YVirAddr: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr); | |
690 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->CVirAddr: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->CVirAddr); | |
691 | ||
692 | Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoEnc->pMFCEncInputBuffer[i]); | |
693 | } | |
694 | ||
695 | pInbufOps->Clear_Queue(hMFCHandle); | |
696 | } else if ((nPortIndex == OUTPUT_PORT_INDEX) && | |
697 | (pH264Enc->bDestinationStart == OMX_TRUE)) { | |
698 | OMX_U32 dataLen[2] = {0, 0}; | |
699 | ExynosVideoBuffer *pBuffer = NULL; | |
38ef2572 | 700 | |
3e79a27e | 701 | Exynos_CodecBufferReset(pExynosComponent, OUTPUT_PORT_INDEX); |
38ef2572 JC |
702 | |
703 | for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { | |
704 | pOutbufOps->Get_Buffer(hMFCHandle, i, &pBuffer); | |
705 | Exynos_CodecBufferEnQueue(pExynosComponent, OUTPUT_PORT_INDEX, (OMX_PTR)pBuffer); | |
706 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncOutputBuffer[%d]: 0x%x", i, pVideoEnc->pMFCEncOutputBuffer[i]); | |
707 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncOutputBuffer[%d]->YVirAddr: 0x%x", i, pVideoEnc->pMFCEncOutputBuffer[i]->VirAddr); | |
708 | } | |
709 | pOutbufOps->Clear_Queue(hMFCHandle); | |
710 | } else { | |
711 | ret = OMX_ErrorBadParameter; | |
712 | goto EXIT; | |
713 | } | |
714 | ||
715 | EXIT: | |
716 | FunctionOut(); | |
717 | ||
718 | return ret; | |
719 | } | |
720 | ||
721 | OMX_ERRORTYPE H264CodecSrcSetup(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData) | |
722 | { | |
723 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
724 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
725 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
726 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
727 | EXYNOS_MFC_H264ENC_HANDLE *pMFCH264Handle = &pH264Enc->hMFCH264Handle; | |
728 | void *hMFCHandle = pMFCH264Handle->hMFCHandle; | |
729 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
730 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
731 | OMX_U32 oneFrameSize = pSrcInputData->dataLen; | |
732 | ||
733 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
734 | ExynosVideoEncBufferOps *pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
735 | ExynosVideoEncBufferOps *pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
736 | ||
737 | FunctionIn(); | |
738 | ||
739 | if ((oneFrameSize <= 0) && (pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS)) { | |
740 | EXYNOS_OMX_DATA *pDstOutputData = &pExynosOutputPort->processData; | |
741 | ||
742 | ret = Exynos_OutputBufferGetQueue(pExynosComponent); | |
743 | if (ret != OMX_ErrorNone) { | |
744 | ret = OMX_ErrorUndefined; | |
745 | goto EXIT; | |
746 | } | |
747 | pDstOutputData->timeStamp = pSrcInputData->timeStamp; | |
748 | pDstOutputData->nFlags = pSrcInputData->nFlags; | |
749 | ||
750 | Exynos_Postprocess_OutputData(pOMXComponent, pDstOutputData); | |
751 | ||
752 | ret = OMX_ErrorNone; | |
753 | goto EXIT; | |
754 | } | |
755 | ||
756 | OMX_PTR pMFCYUVVirBuffer[2] = {NULL, NULL}; | |
757 | OMX_U32 pMFCYUVDataSize[2] = {0, 0}; | |
758 | ||
759 | pExynosComponent->timeStamp[pH264Enc->hMFCH264Handle.indexTimestamp] = pSrcInputData->timeStamp; | |
760 | pExynosComponent->nFlags[pH264Enc->hMFCH264Handle.indexTimestamp] = pSrcInputData->nFlags; | |
761 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "input timestamp %lld us (%.2f secs), Tag: %d, nFlags: 0x%x", pSrcInputData->timeStamp, pSrcInputData->timeStamp / 1E6, pH264Enc->hMFCH264Handle.indexTimestamp, pSrcInputData->nFlags); | |
762 | pEncOps->Set_FrameTag(pH264Enc->hMFCH264Handle.hMFCHandle, pH264Enc->hMFCH264Handle.indexTimestamp); | |
763 | pH264Enc->hMFCH264Handle.indexTimestamp++; | |
764 | pH264Enc->hMFCH264Handle.indexTimestamp %= MAX_TIMESTAMP; | |
765 | ||
766 | /* queue work for input buffer */ | |
767 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s:%d H264CodecSetup(): oneFrameSize: %d, bufferHeader: 0x%x", __FUNCTION__, __LINE__, oneFrameSize, pSrcInputData->bufferHeader); | |
768 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
769 | CODEC_ENC_INPUT_BUFFER *codecInputBuffer = (CODEC_ENC_INPUT_BUFFER *)pSrcInputData->pPrivate; | |
770 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s:%d codecInputBuffer:0x%x", __FUNCTION__, __LINE__, codecInputBuffer); | |
771 | pMFCYUVDataSize[0] = codecInputBuffer->YDataSize; | |
772 | pMFCYUVDataSize[1] = codecInputBuffer->CDataSize; | |
773 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
774 | pMFCYUVDataSize[0] = pExynosInputPort->portDefinition.format.video.nFrameWidth * pExynosInputPort->portDefinition.format.video.nFrameHeight; //codecInputBuffer->YDataSize; | |
775 | pMFCYUVDataSize[1] = pMFCYUVDataSize[0]/2; | |
776 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s:%d Ysize:%d CSize %d", __FUNCTION__, __LINE__, pMFCYUVDataSize[0], pMFCYUVDataSize[1]); | |
777 | } | |
778 | ||
779 | pMFCYUVVirBuffer[0] = pSrcInputData->buffer.multiPlaneBuffer.dataBuffer[0]; | |
780 | pMFCYUVVirBuffer[1] = pSrcInputData->buffer.multiPlaneBuffer.dataBuffer[1]; | |
781 | ||
782 | if (pInbufOps->Enqueue(pH264Enc->hMFCH264Handle.hMFCHandle, (unsigned char **)pMFCYUVVirBuffer, | |
783 | (unsigned int *)pMFCYUVDataSize, 2, pSrcInputData->bufferHeader) != VIDEO_ERROR_NONE) { | |
784 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to enqueue input buffer"); | |
785 | ret = OMX_ErrorUndefined; | |
786 | goto EXIT; | |
787 | } | |
788 | /* input start */ | |
789 | if (pInbufOps->Run(pH264Enc->hMFCH264Handle.hMFCHandle) != VIDEO_ERROR_NONE) { | |
790 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run input buffer for header parsing"); | |
791 | ret = OMX_ErrorCodecInit; | |
792 | goto EXIT; | |
793 | } | |
794 | ||
795 | pH264Enc->bSourceStart = OMX_TRUE; | |
796 | Exynos_OSAL_SignalSet(pH264Enc->hSourceStartEvent); | |
797 | Exynos_OSAL_SleepMillisec(0); | |
798 | ||
799 | pH264Enc->hMFCH264Handle.bConfiguredMFCSrc = OMX_TRUE; | |
800 | ret = OMX_ErrorNone; | |
801 | ||
802 | EXIT: | |
803 | FunctionOut(); | |
804 | ||
805 | return ret; | |
806 | } | |
807 | ||
808 | OMX_ERRORTYPE H264CodecDstSetup(OMX_COMPONENTTYPE *pOMXComponent) | |
809 | { | |
810 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
811 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
812 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
813 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
814 | EXYNOS_MFC_H264ENC_HANDLE *pMFCH264Handle = &pH264Enc->hMFCH264Handle; | |
815 | void *hMFCHandle = pMFCH264Handle->hMFCHandle; | |
816 | ||
817 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
818 | ExynosVideoEncBufferOps *pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
819 | ExynosVideoEncBufferOps *pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
820 | ||
821 | FunctionIn(); | |
822 | ||
823 | /* start header encoding */ | |
824 | if (pOutbufOps->Run) { | |
825 | if (pOutbufOps->Run(pH264Enc->hMFCH264Handle.hMFCHandle) != VIDEO_ERROR_NONE) { | |
826 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to run output buffer for header parsing"); | |
827 | ret = OMX_ErrorInsufficientResources; | |
828 | goto EXIT; | |
829 | } | |
830 | } | |
831 | ||
832 | pH264Enc->bDestinationStart = OMX_TRUE; | |
833 | Exynos_OSAL_SignalSet(pH264Enc->hDestinationStartEvent); | |
834 | Exynos_OSAL_SleepMillisec(0); | |
835 | ||
836 | /* bConfiguredMFCDst should be set true before waiting headerGeneratedEvent event. | |
837 | * To make sure that the first dequeued destination buffer is enqueued before H264CodecDstSetup returns. | |
838 | * If bConfiguredMFCDst is not set to be true, | |
839 | * Exynos_H264Enc_dstInputBufferProcess returns without enqueuing the first dequeued destination buffer. | |
840 | */ | |
841 | pH264Enc->hMFCH264Handle.bConfiguredMFCDst = OMX_TRUE; | |
842 | ||
843 | Exynos_OSAL_SignalWait(pVideoEnc->headerGeneratedEvent, DEF_MAX_WAIT_TIME); | |
844 | Exynos_OSAL_SignalReset(pVideoEnc->headerGeneratedEvent); | |
845 | ||
846 | ret = OMX_ErrorNone; | |
847 | ||
848 | EXIT: | |
849 | FunctionOut(); | |
850 | ||
851 | return ret; | |
852 | } | |
853 | ||
854 | OMX_ERRORTYPE Exynos_H264Enc_GetParameter( | |
855 | OMX_IN OMX_HANDLETYPE hComponent, | |
856 | OMX_IN OMX_INDEXTYPE nParamIndex, | |
857 | OMX_INOUT OMX_PTR pComponentParameterStructure) | |
858 | { | |
859 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
860 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
861 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
862 | ||
863 | FunctionIn(); | |
864 | ||
865 | if (hComponent == NULL || pComponentParameterStructure == NULL) { | |
866 | ret = OMX_ErrorBadParameter; | |
867 | goto EXIT; | |
868 | } | |
869 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
870 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
871 | if (ret != OMX_ErrorNone) { | |
872 | goto EXIT; | |
873 | } | |
874 | if (pOMXComponent->pComponentPrivate == NULL) { | |
875 | ret = OMX_ErrorBadParameter; | |
876 | goto EXIT; | |
877 | } | |
878 | ||
879 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
880 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
881 | ret = OMX_ErrorInvalidState; | |
882 | goto EXIT; | |
883 | } | |
884 | ||
885 | switch (nParamIndex) { | |
886 | case OMX_IndexParamVideoAvc: | |
887 | { | |
888 | OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = (OMX_VIDEO_PARAM_AVCTYPE *)pComponentParameterStructure; | |
889 | OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = NULL; | |
890 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
891 | ||
892 | ret = Exynos_OMX_Check_SizeVersion(pDstAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
893 | if (ret != OMX_ErrorNone) { | |
894 | goto EXIT; | |
895 | } | |
896 | ||
897 | if (pDstAVCComponent->nPortIndex >= ALL_PORT_NUM) { | |
898 | ret = OMX_ErrorBadPortIndex; | |
899 | goto EXIT; | |
900 | } | |
901 | ||
902 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
903 | pSrcAVCComponent = &pH264Enc->AVCComponent[pDstAVCComponent->nPortIndex]; | |
904 | ||
905 | Exynos_OSAL_Memcpy(pDstAVCComponent, pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
906 | } | |
907 | break; | |
908 | case OMX_IndexParamStandardComponentRole: | |
909 | { | |
910 | OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)pComponentParameterStructure; | |
911 | ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); | |
912 | if (ret != OMX_ErrorNone) { | |
913 | goto EXIT; | |
914 | } | |
915 | ||
916 | Exynos_OSAL_Strcpy((char *)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H264_ENC_ROLE); | |
917 | } | |
918 | break; | |
919 | case OMX_IndexParamVideoProfileLevelQuerySupported: | |
920 | { | |
921 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)pComponentParameterStructure; | |
922 | EXYNOS_OMX_VIDEO_PROFILELEVEL *pProfileLevel = NULL; | |
923 | OMX_U32 maxProfileLevelNum = 0; | |
924 | ||
925 | ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); | |
926 | if (ret != OMX_ErrorNone) { | |
927 | goto EXIT; | |
928 | } | |
929 | ||
930 | if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { | |
931 | ret = OMX_ErrorBadPortIndex; | |
932 | goto EXIT; | |
933 | } | |
934 | ||
935 | pProfileLevel = supportedAVCProfileLevels; | |
936 | maxProfileLevelNum = sizeof(supportedAVCProfileLevels) / sizeof(EXYNOS_OMX_VIDEO_PROFILELEVEL); | |
937 | ||
938 | if (pDstProfileLevel->nProfileIndex >= maxProfileLevelNum) { | |
939 | ret = OMX_ErrorNoMore; | |
940 | goto EXIT; | |
941 | } | |
942 | ||
943 | pProfileLevel += pDstProfileLevel->nProfileIndex; | |
944 | pDstProfileLevel->eProfile = pProfileLevel->profile; | |
945 | pDstProfileLevel->eLevel = pProfileLevel->level; | |
946 | } | |
947 | break; | |
948 | case OMX_IndexParamVideoProfileLevelCurrent: | |
949 | { | |
950 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)pComponentParameterStructure; | |
951 | OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = NULL; | |
952 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
953 | ||
954 | ret = Exynos_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); | |
955 | if (ret != OMX_ErrorNone) { | |
956 | goto EXIT; | |
957 | } | |
958 | ||
959 | if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { | |
960 | ret = OMX_ErrorBadPortIndex; | |
961 | goto EXIT; | |
962 | } | |
963 | ||
964 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
965 | pSrcAVCComponent = &pH264Enc->AVCComponent[pDstProfileLevel->nPortIndex]; | |
966 | ||
967 | pDstProfileLevel->eProfile = pSrcAVCComponent->eProfile; | |
968 | pDstProfileLevel->eLevel = pSrcAVCComponent->eLevel; | |
969 | } | |
970 | break; | |
971 | case OMX_IndexParamVideoErrorCorrection: | |
972 | { | |
973 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; | |
974 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = NULL; | |
975 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
976 | ||
977 | ret = Exynos_OMX_Check_SizeVersion(pDstErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); | |
978 | if (ret != OMX_ErrorNone) { | |
979 | goto EXIT; | |
980 | } | |
981 | ||
982 | if (pDstErrorCorrectionType->nPortIndex != OUTPUT_PORT_INDEX) { | |
983 | ret = OMX_ErrorBadPortIndex; | |
984 | goto EXIT; | |
985 | } | |
986 | ||
987 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
988 | pSrcErrorCorrectionType = &pH264Enc->errorCorrectionType[OUTPUT_PORT_INDEX]; | |
989 | ||
990 | pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; | |
991 | pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; | |
992 | pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; | |
993 | pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; | |
994 | pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; | |
995 | } | |
996 | break; | |
997 | default: | |
998 | ret = Exynos_OMX_VideoEncodeGetParameter(hComponent, nParamIndex, pComponentParameterStructure); | |
999 | break; | |
1000 | } | |
1001 | EXIT: | |
1002 | FunctionOut(); | |
1003 | ||
1004 | return ret; | |
1005 | } | |
1006 | ||
1007 | OMX_ERRORTYPE Exynos_H264Enc_SetParameter( | |
1008 | OMX_IN OMX_HANDLETYPE hComponent, | |
1009 | OMX_IN OMX_INDEXTYPE nIndex, | |
1010 | OMX_IN OMX_PTR pComponentParameterStructure) | |
1011 | { | |
1012 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1013 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1014 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1015 | ||
1016 | FunctionIn(); | |
1017 | ||
1018 | if (hComponent == NULL || pComponentParameterStructure == NULL) { | |
1019 | ret = OMX_ErrorBadParameter; | |
1020 | goto EXIT; | |
1021 | } | |
1022 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1023 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1024 | if (ret != OMX_ErrorNone) { | |
1025 | goto EXIT; | |
1026 | } | |
1027 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1028 | ret = OMX_ErrorBadParameter; | |
1029 | goto EXIT; | |
1030 | } | |
1031 | ||
1032 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1033 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
1034 | ret = OMX_ErrorInvalidState; | |
1035 | goto EXIT; | |
1036 | } | |
1037 | ||
1038 | switch (nIndex) { | |
1039 | case OMX_IndexParamVideoAvc: | |
1040 | { | |
1041 | OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = NULL; | |
1042 | OMX_VIDEO_PARAM_AVCTYPE *pSrcAVCComponent = (OMX_VIDEO_PARAM_AVCTYPE *)pComponentParameterStructure; | |
1043 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
1044 | ||
1045 | ret = Exynos_OMX_Check_SizeVersion(pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
1046 | if (ret != OMX_ErrorNone) { | |
1047 | goto EXIT; | |
1048 | } | |
1049 | ||
1050 | if (pSrcAVCComponent->nPortIndex >= ALL_PORT_NUM) { | |
1051 | ret = OMX_ErrorBadPortIndex; | |
1052 | goto EXIT; | |
1053 | } | |
1054 | ||
1055 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1056 | pDstAVCComponent = &pH264Enc->AVCComponent[pSrcAVCComponent->nPortIndex]; | |
1057 | ||
1058 | Exynos_OSAL_Memcpy(pDstAVCComponent, pSrcAVCComponent, sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | |
1059 | } | |
1060 | break; | |
1061 | case OMX_IndexParamStandardComponentRole: | |
1062 | { | |
1063 | OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)pComponentParameterStructure; | |
20d3e6e3 JC |
1064 | |
1065 | ret = Exynos_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); | |
1066 | if (ret != OMX_ErrorNone) { | |
1067 | goto EXIT; | |
1068 | } | |
1069 | ||
1070 | if ((pExynosComponent->currentState != OMX_StateLoaded) && (pExynosComponent->currentState != OMX_StateWaitForResources)) { | |
1071 | ret = OMX_ErrorIncorrectStateOperation; | |
1072 | goto EXIT; | |
1073 | } | |
1074 | ||
1075 | if (!Exynos_OSAL_Strcmp((char*)pComponentRole->cRole, EXYNOS_OMX_COMPONENT_H264_ENC_ROLE)) { | |
1076 | pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; | |
1077 | } else { | |
1078 | ret = OMX_ErrorBadParameter; | |
1079 | goto EXIT; | |
1080 | } | |
1081 | } | |
1082 | break; | |
1083 | case OMX_IndexParamVideoProfileLevelCurrent: | |
1084 | { | |
1085 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; | |
1086 | OMX_VIDEO_PARAM_AVCTYPE *pDstAVCComponent = NULL; | |
1087 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
1088 | ||
1089 | ret = Exynos_OMX_Check_SizeVersion(pSrcProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); | |
3e79a27e | 1090 | if (ret != OMX_ErrorNone) |
20d3e6e3 | 1091 | goto EXIT; |
20d3e6e3 JC |
1092 | |
1093 | if (pSrcProfileLevel->nPortIndex >= ALL_PORT_NUM) { | |
1094 | ret = OMX_ErrorBadPortIndex; | |
1095 | goto EXIT; | |
1096 | } | |
1097 | ||
1098 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1099 | ||
1100 | pDstAVCComponent = &pH264Enc->AVCComponent[pSrcProfileLevel->nPortIndex]; | |
1101 | pDstAVCComponent->eProfile = pSrcProfileLevel->eProfile; | |
1102 | pDstAVCComponent->eLevel = pSrcProfileLevel->eLevel; | |
1103 | } | |
1104 | break; | |
1105 | case OMX_IndexParamVideoErrorCorrection: | |
1106 | { | |
1107 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; | |
1108 | OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = NULL; | |
1109 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
1110 | ||
1111 | ret = Exynos_OMX_Check_SizeVersion(pSrcErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); | |
1112 | if (ret != OMX_ErrorNone) { | |
1113 | goto EXIT; | |
1114 | } | |
1115 | ||
1116 | if (pSrcErrorCorrectionType->nPortIndex != OUTPUT_PORT_INDEX) { | |
1117 | ret = OMX_ErrorBadPortIndex; | |
1118 | goto EXIT; | |
1119 | } | |
1120 | ||
1121 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1122 | pDstErrorCorrectionType = &pH264Enc->errorCorrectionType[OUTPUT_PORT_INDEX]; | |
1123 | ||
1124 | pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; | |
1125 | pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; | |
1126 | pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; | |
1127 | pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; | |
1128 | pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; | |
1129 | } | |
1130 | break; | |
1131 | default: | |
1132 | ret = Exynos_OMX_VideoEncodeSetParameter(hComponent, nIndex, pComponentParameterStructure); | |
1133 | break; | |
1134 | } | |
1135 | EXIT: | |
1136 | FunctionOut(); | |
1137 | ||
1138 | return ret; | |
1139 | } | |
1140 | ||
800a8d75 | 1141 | OMX_ERRORTYPE Exynos_H264Enc_GetConfig( |
20d3e6e3 JC |
1142 | OMX_HANDLETYPE hComponent, |
1143 | OMX_INDEXTYPE nIndex, | |
1144 | OMX_PTR pComponentConfigStructure) | |
1145 | { | |
1146 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1147 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1148 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1149 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
1150 | ||
1151 | FunctionIn(); | |
1152 | ||
1153 | if (hComponent == NULL || pComponentConfigStructure == NULL) { | |
1154 | ret = OMX_ErrorBadParameter; | |
1155 | goto EXIT; | |
1156 | } | |
1157 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1158 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1159 | if (ret != OMX_ErrorNone) { | |
1160 | goto EXIT; | |
1161 | } | |
1162 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1163 | ret = OMX_ErrorBadParameter; | |
1164 | goto EXIT; | |
1165 | } | |
20d3e6e3 JC |
1166 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
1167 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1168 | ret = OMX_ErrorInvalidState; | |
1169 | goto EXIT; | |
1170 | } | |
1171 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1172 | ||
1173 | switch (nIndex) { | |
1174 | case OMX_IndexConfigVideoAVCIntraPeriod: | |
1175 | { | |
1176 | OMX_VIDEO_CONFIG_AVCINTRAPERIOD *pAVCIntraPeriod = (OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pComponentConfigStructure; | |
1177 | OMX_U32 portIndex = pAVCIntraPeriod->nPortIndex; | |
1178 | ||
1179 | if ((portIndex != OUTPUT_PORT_INDEX)) { | |
1180 | ret = OMX_ErrorBadPortIndex; | |
1181 | goto EXIT; | |
1182 | } else { | |
1183 | pAVCIntraPeriod->nIDRPeriod = pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].nPFrames + 1; | |
1184 | pAVCIntraPeriod->nPFrames = pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].nPFrames; | |
1185 | } | |
1186 | } | |
1187 | break; | |
1188 | default: | |
1189 | ret = Exynos_OMX_VideoEncodeGetConfig(hComponent, nIndex, pComponentConfigStructure); | |
1190 | break; | |
1191 | } | |
1192 | ||
1193 | EXIT: | |
1194 | FunctionOut(); | |
1195 | ||
1196 | return ret; | |
1197 | } | |
1198 | ||
800a8d75 | 1199 | OMX_ERRORTYPE Exynos_H264Enc_SetConfig( |
20d3e6e3 JC |
1200 | OMX_HANDLETYPE hComponent, |
1201 | OMX_INDEXTYPE nIndex, | |
1202 | OMX_PTR pComponentConfigStructure) | |
1203 | { | |
1204 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1205 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1206 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1207 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; | |
1208 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
1209 | ||
1210 | FunctionIn(); | |
1211 | ||
1212 | if (hComponent == NULL || pComponentConfigStructure == NULL) { | |
1213 | ret = OMX_ErrorBadParameter; | |
1214 | goto EXIT; | |
1215 | } | |
1216 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1217 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1218 | if (ret != OMX_ErrorNone) { | |
1219 | goto EXIT; | |
1220 | } | |
1221 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1222 | ret = OMX_ErrorBadParameter; | |
1223 | goto EXIT; | |
1224 | } | |
20d3e6e3 JC |
1225 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
1226 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1227 | ret = OMX_ErrorInvalidState; | |
1228 | goto EXIT; | |
1229 | } | |
1230 | ||
3e79a27e | 1231 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
20d3e6e3 JC |
1232 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; |
1233 | ||
1234 | switch (nIndex) { | |
1235 | case OMX_IndexConfigVideoIntraPeriod: | |
1236 | { | |
1237 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVEncBase = ((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle); | |
1238 | OMX_U32 nPFrames = (*((OMX_U32 *)pComponentConfigStructure)) - 1; | |
1239 | ||
1240 | pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].nPFrames = nPFrames; | |
1241 | ||
1242 | ret = OMX_ErrorNone; | |
1243 | } | |
1244 | break; | |
1245 | case OMX_IndexConfigVideoAVCIntraPeriod: | |
1246 | { | |
1247 | OMX_VIDEO_CONFIG_AVCINTRAPERIOD *pAVCIntraPeriod = (OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pComponentConfigStructure; | |
1248 | OMX_U32 portIndex = pAVCIntraPeriod->nPortIndex; | |
1249 | ||
1250 | if ((portIndex != OUTPUT_PORT_INDEX)) { | |
1251 | ret = OMX_ErrorBadPortIndex; | |
1252 | goto EXIT; | |
1253 | } else { | |
1254 | if (pAVCIntraPeriod->nIDRPeriod == (pAVCIntraPeriod->nPFrames + 1)) | |
1255 | pH264Enc->AVCComponent[OUTPUT_PORT_INDEX].nPFrames = pAVCIntraPeriod->nPFrames; | |
1256 | else { | |
1257 | ret = OMX_ErrorBadParameter; | |
1258 | goto EXIT; | |
1259 | } | |
1260 | } | |
1261 | } | |
1262 | break; | |
1263 | default: | |
1264 | ret = Exynos_OMX_VideoEncodeSetConfig(hComponent, nIndex, pComponentConfigStructure); | |
1265 | break; | |
1266 | } | |
1267 | ||
1268 | EXIT: | |
1269 | if (ret == OMX_ErrorNone) | |
1270 | pVideoEnc->configChange = OMX_TRUE; | |
1271 | ||
1272 | FunctionOut(); | |
1273 | ||
1274 | return ret; | |
1275 | } | |
1276 | ||
800a8d75 | 1277 | OMX_ERRORTYPE Exynos_H264Enc_GetExtensionIndex( |
20d3e6e3 JC |
1278 | OMX_IN OMX_HANDLETYPE hComponent, |
1279 | OMX_IN OMX_STRING cParameterName, | |
1280 | OMX_OUT OMX_INDEXTYPE *pIndexType) | |
1281 | { | |
1282 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1283 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1284 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1285 | ||
1286 | FunctionIn(); | |
1287 | ||
1288 | if (hComponent == NULL) { | |
1289 | ret = OMX_ErrorBadParameter; | |
1290 | goto EXIT; | |
1291 | } | |
1292 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1293 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1294 | if (ret != OMX_ErrorNone) { | |
1295 | goto EXIT; | |
1296 | } | |
20d3e6e3 JC |
1297 | if (pOMXComponent->pComponentPrivate == NULL) { |
1298 | ret = OMX_ErrorBadParameter; | |
1299 | goto EXIT; | |
1300 | } | |
1301 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
20d3e6e3 JC |
1302 | if ((cParameterName == NULL) || (pIndexType == NULL)) { |
1303 | ret = OMX_ErrorBadParameter; | |
1304 | goto EXIT; | |
1305 | } | |
1306 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1307 | ret = OMX_ErrorInvalidState; | |
1308 | goto EXIT; | |
1309 | } | |
1310 | if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_CONFIG_VIDEO_INTRAPERIOD) == 0) { | |
1311 | *pIndexType = OMX_IndexConfigVideoIntraPeriod; | |
1312 | ret = OMX_ErrorNone; | |
1313 | } else { | |
1314 | ret = Exynos_OMX_VideoEncodeGetExtensionIndex(hComponent, cParameterName, pIndexType); | |
1315 | } | |
1316 | ||
1317 | EXIT: | |
1318 | FunctionOut(); | |
1319 | ||
1320 | return ret; | |
1321 | } | |
1322 | ||
800a8d75 | 1323 | OMX_ERRORTYPE Exynos_H264Enc_ComponentRoleEnum(OMX_HANDLETYPE hComponent, OMX_U8 *cRole, OMX_U32 nIndex) |
20d3e6e3 JC |
1324 | { |
1325 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1326 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1327 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1328 | ||
1329 | FunctionIn(); | |
1330 | ||
1331 | if ((hComponent == NULL) || (cRole == NULL)) { | |
1332 | ret = OMX_ErrorBadParameter; | |
1333 | goto EXIT; | |
1334 | } | |
1335 | if (nIndex == (MAX_COMPONENT_ROLE_NUM-1)) { | |
1336 | Exynos_OSAL_Strcpy((char *)cRole, EXYNOS_OMX_COMPONENT_H264_ENC_ROLE); | |
1337 | ret = OMX_ErrorNone; | |
1338 | } else { | |
1339 | ret = OMX_ErrorNoMore; | |
1340 | } | |
1341 | ||
1342 | EXIT: | |
1343 | FunctionOut(); | |
1344 | ||
1345 | return ret; | |
1346 | } | |
1347 | ||
20d3e6e3 | 1348 | /* MFC Init */ |
800a8d75 | 1349 | OMX_ERRORTYPE Exynos_H264Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) |
20d3e6e3 | 1350 | { |
38ef2572 | 1351 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
20d3e6e3 | 1352 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
38ef2572 JC |
1353 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
1354 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1355 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
1356 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle;; | |
1357 | EXYNOS_MFC_H264ENC_HANDLE *pMFCH264Handle = &pH264Enc->hMFCH264Handle; | |
1358 | OMX_PTR hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
1359 | OMX_COLOR_FORMATTYPE eColorFormat; | |
1360 | ||
1361 | ExynosVideoEncOps *pEncOps = NULL; | |
1362 | ExynosVideoEncBufferOps *pInbufOps = NULL; | |
1363 | ExynosVideoEncBufferOps *pOutbufOps = NULL; | |
20d3e6e3 | 1364 | |
38ef2572 | 1365 | CSC_METHOD csc_method = CSC_METHOD_SW; |
20d3e6e3 | 1366 | |
38ef2572 JC |
1367 | ExynosVideoEncParam *pEncParam = NULL; |
1368 | ExynosVideoGeometry bufferConf; | |
1369 | OMX_U32 inputBufferNumber = 0; | |
20d3e6e3 | 1370 | ExynosVideoBuffer bufferInfo; |
20d3e6e3 | 1371 | |
38ef2572 | 1372 | int i = 0; |
20d3e6e3 JC |
1373 | |
1374 | FunctionIn(); | |
1375 | ||
38ef2572 JC |
1376 | pH264Enc->hMFCH264Handle.bConfiguredMFCSrc = OMX_FALSE; |
1377 | pH264Enc->hMFCH264Handle.bConfiguredMFCDst = OMX_FALSE; | |
1378 | pVideoEnc->bFirstOutput = OMX_FALSE; | |
1379 | pExynosComponent->bUseFlagEOF = OMX_TRUE; | |
20d3e6e3 JC |
1380 | pExynosComponent->bSaveFlagEOS = OMX_FALSE; |
1381 | ||
38ef2572 | 1382 | eColorFormat = pExynosInputPort->portDefinition.format.video.eColorFormat; |
38ef2572 JC |
1383 | if (pExynosInputPort->bStoreMetaData == OMX_TRUE) { |
1384 | if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) { | |
1385 | pExynosInputPort->bufferProcessType = BUFFER_COPY; | |
3e79a27e | 1386 | } else { |
38ef2572 JC |
1387 | pExynosInputPort->bufferProcessType = BUFFER_SHARE; |
1388 | } | |
1389 | } | |
800a8d75 | 1390 | |
38ef2572 JC |
1391 | /* H.264 Codec Open */ |
1392 | ret = H264CodecOpen(pH264Enc); | |
1393 | if (ret != OMX_ErrorNone) { | |
1394 | goto EXIT; | |
1395 | } | |
800a8d75 | 1396 | |
38ef2572 JC |
1397 | pEncOps = pH264Enc->hMFCH264Handle.pEncOps; |
1398 | pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
1399 | pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
800a8d75 | 1400 | |
38ef2572 JC |
1401 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
1402 | Exynos_OSAL_SemaphoreCreate(&pExynosInputPort->codecSemID); | |
1403 | Exynos_OSAL_QueueCreate(&pExynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); | |
1404 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
1405 | /*************/ | |
1406 | /* TBD */ | |
1407 | /*************/ | |
1408 | /* Does not require any actions? */ | |
1409 | } | |
1410 | ||
1411 | Set_H264Enc_Param(pExynosComponent); | |
1412 | pEncParam = &pMFCH264Handle->encParam; | |
1413 | if (pEncOps->Set_EncParam) { | |
1414 | if(pEncOps->Set_EncParam(pH264Enc->hMFCH264Handle.hMFCHandle, pEncParam) != VIDEO_ERROR_NONE) { | |
1415 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for input buffer"); | |
1416 | ret = OMX_ErrorInsufficientResources; | |
1417 | goto EXIT; | |
1418 | } | |
20d3e6e3 JC |
1419 | } |
1420 | ||
38ef2572 JC |
1421 | if (pInbufOps->Set_Shareable) { |
1422 | pInbufOps->Set_Shareable(pH264Enc->hMFCH264Handle.hMFCHandle); | |
1423 | } | |
20d3e6e3 | 1424 | |
38ef2572 JC |
1425 | if ((pExynosInputPort->bufferProcessType & BUFFER_SHARE) == BUFFER_SHARE) { |
1426 | inputBufferNumber = MAX_VIDEO_INPUTBUFFER_NUM; | |
1427 | } else if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
1428 | inputBufferNumber = MFC_INPUT_BUFFER_NUM_MAX; | |
1429 | } | |
20d3e6e3 | 1430 | |
38ef2572 | 1431 | Exynos_OSAL_Memset(&bufferConf, 0, sizeof(bufferConf)); |
20d3e6e3 | 1432 | |
38ef2572 JC |
1433 | /* input buffer info: only 3 config values needed */ |
1434 | bufferConf.eColorFormat = pEncParam->commonParam.FrameMap; | |
1435 | bufferConf.nFrameWidth = pExynosInputPort->portDefinition.format.video.nFrameWidth; | |
1436 | bufferConf.nFrameHeight = pExynosInputPort->portDefinition.format.video.nFrameHeight; | |
1437 | ||
1438 | /* set input buffer geometry */ | |
1439 | if (pInbufOps->Set_Geometry) { | |
1440 | if (pInbufOps->Set_Geometry(pH264Enc->hMFCH264Handle.hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) { | |
1441 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for input buffer"); | |
1442 | ret = OMX_ErrorInsufficientResources; | |
1443 | goto EXIT; | |
1444 | } | |
20d3e6e3 JC |
1445 | } |
1446 | ||
38ef2572 JC |
1447 | /* should be done before prepare input buffer */ |
1448 | if (pInbufOps->Enable_Cacheable) { | |
1449 | if (pInbufOps->Enable_Cacheable(pH264Enc->hMFCH264Handle.hMFCHandle) != VIDEO_ERROR_NONE) { | |
1450 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup cacheable input buffer"); | |
1451 | ret = OMX_ErrorInsufficientResources; | |
1452 | goto EXIT; | |
1453 | } | |
20d3e6e3 JC |
1454 | } |
1455 | ||
38ef2572 JC |
1456 | /* setup input buffer */ |
1457 | if (pInbufOps->Setup(pH264Enc->hMFCH264Handle.hMFCHandle, inputBufferNumber) != VIDEO_ERROR_NONE) { | |
1458 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup input buffer"); | |
20d3e6e3 JC |
1459 | ret = OMX_ErrorInsufficientResources; |
1460 | goto EXIT; | |
1461 | } | |
1462 | ||
38ef2572 JC |
1463 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
1464 | /* Register input buffer */ | |
1465 | OMX_PTR pTempAddress[2] = {NULL, NULL}; | |
1466 | OMX_U32 TempAllocSize[2] = {0, 0}; | |
1467 | ||
1468 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { | |
1469 | pVideoEnc->pMFCEncInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_ENC_INPUT_BUFFER)); | |
1470 | /* Use ION Allocator */ | |
1471 | /*Alloc Y-Buffer */ | |
1472 | pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_YBUFFER_SIZE, NORMAL_MEMORY); | |
1473 | pVideoEnc->pMFCEncInputBuffer[i]->YBufferSize = DEFAULT_MFC_INPUT_YBUFFER_SIZE; | |
1474 | pVideoEnc->pMFCEncInputBuffer[i]->YDataSize = 0; | |
1475 | /*Alloc C-Buffer */ | |
1476 | pVideoEnc->pMFCEncInputBuffer[i]->CVirAddr = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_CBUFFER_SIZE, NORMAL_MEMORY); | |
1477 | pVideoEnc->pMFCEncInputBuffer[i]->CBufferSize = DEFAULT_MFC_INPUT_CBUFFER_SIZE; | |
1478 | pVideoEnc->pMFCEncInputBuffer[i]->CDataSize = 0; | |
1479 | ||
1480 | pTempAddress[0] = pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr; | |
1481 | pTempAddress[1] = pVideoEnc->pMFCEncInputBuffer[i]->CVirAddr; | |
1482 | TempAllocSize[0] = pVideoEnc->pMFCEncInputBuffer[i]->YBufferSize; | |
1483 | TempAllocSize[1] = pVideoEnc->pMFCEncInputBuffer[i]->CBufferSize; | |
1484 | ||
1485 | if ((pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr == NULL) || | |
1486 | (pVideoEnc->pMFCEncInputBuffer[i]->CVirAddr == NULL)) { | |
1487 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); | |
1488 | ret = OMX_ErrorInsufficientResources; | |
1489 | goto EXIT; | |
1490 | } | |
1491 | ||
1492 | if (pInbufOps->Register(pH264Enc->hMFCH264Handle.hMFCHandle, | |
1493 | (unsigned char **)pTempAddress, | |
1494 | (unsigned int *)TempAllocSize) != VIDEO_ERROR_NONE) { | |
1495 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); | |
1496 | ret = OMX_ErrorInsufficientResources; | |
1497 | goto EXIT; | |
1498 | } | |
1499 | ||
1500 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]); | |
1501 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->YVirAddr: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr); | |
1502 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pVideoEnc->pMFCEncInputBuffer[%d]->CVirAddr: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->CVirAddr); | |
1503 | ||
1504 | Exynos_CodecBufferEnQueue(pExynosComponent, INPUT_PORT_INDEX, pVideoEnc->pMFCEncInputBuffer[i]); | |
1505 | } | |
1506 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
1507 | OMX_U32 TempAllocSize[2] = {0, 0}; | |
1508 | if (pExynosInputPort->bStoreMetaData == OMX_TRUE) { | |
1509 | TempAllocSize[0] = ALIGN_TO_16B(pExynosInputPort->portDefinition.format.video.nFrameWidth) * ALIGN_TO_16B(pExynosInputPort->portDefinition.format.video.nFrameHeight); | |
1510 | TempAllocSize[1] = ALIGN(TempAllocSize[0]/2,256); | |
20d3e6e3 | 1511 | } |
20d3e6e3 | 1512 | |
38ef2572 JC |
1513 | /* Register input buffer */ |
1514 | for (i = 0; i < pExynosInputPort->portDefinition.nBufferCountActual; i++) { | |
1515 | if (pInbufOps->Register(pH264Enc->hMFCH264Handle.hMFCHandle, | |
1516 | (unsigned char **)&pExynosInputPort->extendBufferHeader[i].OMXBufferHeader->pBuffer, | |
1517 | (pExynosInputPort->bStoreMetaData ? (unsigned int *)TempAllocSize : | |
1518 | (unsigned int *)&pExynosInputPort->extendBufferHeader[i].OMXBufferHeader->nAllocLen)) != VIDEO_ERROR_NONE) { | |
1519 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register input buffer"); | |
20d3e6e3 JC |
1520 | ret = OMX_ErrorInsufficientResources; |
1521 | goto EXIT; | |
1522 | } | |
1523 | } | |
1524 | } | |
1525 | ||
38ef2572 JC |
1526 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
1527 | Exynos_OSAL_SemaphoreCreate(&pExynosOutputPort->codecSemID); | |
1528 | Exynos_OSAL_QueueCreate(&pExynosOutputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); | |
1529 | } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
1530 | /*************/ | |
1531 | /* TBD */ | |
1532 | /*************/ | |
1533 | /* Does not require any actions. */ | |
1534 | } | |
20d3e6e3 | 1535 | |
38ef2572 JC |
1536 | /* set geometry for output (dst) */ |
1537 | if (pOutbufOps->Set_Geometry) { | |
1538 | /* only 2 config values needed */ | |
1539 | bufferConf.eCompressionFormat = VIDEO_CODING_AVC; | |
1540 | bufferConf.nSizeImage = pExynosInputPort->portDefinition.format.video.nFrameWidth * pExynosInputPort->portDefinition.format.video.nFrameHeight * 3 / 2; | |
20d3e6e3 | 1541 | |
38ef2572 JC |
1542 | if (pOutbufOps->Set_Geometry(pH264Enc->hMFCH264Handle.hMFCHandle, &bufferConf) != VIDEO_ERROR_NONE) { |
1543 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to set geometry for output buffer"); | |
20d3e6e3 JC |
1544 | ret = OMX_ErrorInsufficientResources; |
1545 | goto EXIT; | |
1546 | } | |
1547 | } | |
38ef2572 | 1548 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s:%d", __FUNCTION__, __LINE__); |
20d3e6e3 | 1549 | |
38ef2572 JC |
1550 | /* should be done before prepare output buffer */ |
1551 | if (pOutbufOps->Enable_Cacheable) { | |
1552 | if (pOutbufOps->Enable_Cacheable(pH264Enc->hMFCH264Handle.hMFCHandle) != VIDEO_ERROR_NONE) { | |
1553 | ret = OMX_ErrorInsufficientResources; | |
1554 | goto EXIT; | |
1555 | } | |
800a8d75 JC |
1556 | } |
1557 | ||
38ef2572 JC |
1558 | if (pOutbufOps->Set_Shareable) { |
1559 | pOutbufOps->Set_Shareable(pH264Enc->hMFCH264Handle.hMFCHandle); | |
1560 | } | |
1561 | ||
1562 | if (pOutbufOps->Setup(pH264Enc->hMFCH264Handle.hMFCHandle, MFC_OUTPUT_BUFFER_NUM_MAX) != VIDEO_ERROR_NONE) { | |
1563 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to setup output buffer"); | |
20d3e6e3 JC |
1564 | ret = OMX_ErrorInsufficientResources; |
1565 | goto EXIT; | |
1566 | } | |
1567 | ||
38ef2572 JC |
1568 | OMX_U32 dataLen[2] = {0, 0}; |
1569 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
1570 | int OutBufferSize = pExynosInputPort->portDefinition.format.video.nFrameWidth * pExynosInputPort->portDefinition.format.video.nFrameHeight * 3 / 2; | |
1571 | /* Register input buffer */ | |
1572 | for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { | |
1573 | pVideoEnc->pMFCEncOutputBuffer[i] = (CODEC_ENC_OUTPUT_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_ENC_OUTPUT_BUFFER)); | |
1574 | pVideoEnc->pMFCEncOutputBuffer[i]->VirAddr = | |
1575 | (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, OutBufferSize, NORMAL_MEMORY); | |
1576 | pVideoEnc->pMFCEncOutputBuffer[i]->bufferSize = OutBufferSize; | |
1577 | pVideoEnc->pMFCEncOutputBuffer[i]->dataSize = 0; | |
20d3e6e3 | 1578 | |
38ef2572 JC |
1579 | if (pVideoEnc->pMFCEncOutputBuffer[i]->VirAddr == NULL) { |
1580 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc output buffer"); | |
1581 | ret = OMX_ErrorInsufficientResources; | |
1582 | goto EXIT; | |
1583 | } | |
20d3e6e3 | 1584 | |
38ef2572 JC |
1585 | if (pOutbufOps->Register(pH264Enc->hMFCH264Handle.hMFCHandle, |
1586 | (unsigned char **)(&pVideoEnc->pMFCEncOutputBuffer[i]->VirAddr), | |
1587 | (unsigned int *)&pVideoEnc->pMFCEncOutputBuffer[i]->bufferSize) != VIDEO_ERROR_NONE) { | |
1588 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer"); | |
1589 | ret = OMX_ErrorInsufficientResources; | |
1590 | goto EXIT; | |
1591 | } | |
1592 | pOutbufOps->Enqueue(pH264Enc->hMFCH264Handle.hMFCHandle, | |
1593 | (unsigned char **)&pVideoEnc->pMFCEncOutputBuffer[i]->VirAddr, | |
1594 | (unsigned int *)dataLen, 1, NULL); | |
1595 | } | |
1596 | } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
1597 | /* Register input buffer */ | |
1598 | /*************/ | |
1599 | /* TBD */ | |
1600 | /*************/ | |
1601 | for (i = 0; i < pExynosOutputPort->portDefinition.nBufferCountActual; i++) { | |
1602 | if (pOutbufOps->Register(hMFCHandle, | |
1603 | (unsigned char **)&pExynosOutputPort->extendBufferHeader[i].OMXBufferHeader->pBuffer, | |
1604 | (unsigned int *)&pExynosOutputPort->extendBufferHeader[i].OMXBufferHeader->nAllocLen) != VIDEO_ERROR_NONE) { | |
1605 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Register output buffer"); | |
1606 | ret = OMX_ErrorInsufficientResources; | |
1607 | goto EXIT; | |
1608 | } | |
1609 | pOutbufOps->Enqueue(pH264Enc->hMFCH264Handle.hMFCHandle, | |
1610 | (unsigned char **)&pExynosOutputPort->extendBufferHeader[i].OMXBufferHeader->pBuffer, | |
1611 | (unsigned int *)dataLen, 1, NULL); | |
1612 | } | |
1613 | } | |
20d3e6e3 | 1614 | |
38ef2572 JC |
1615 | pH264Enc->bSourceStart = OMX_FALSE; |
1616 | Exynos_OSAL_SignalCreate(&pH264Enc->hSourceStartEvent); | |
38ef2572 JC |
1617 | pH264Enc->bDestinationStart = OMX_FALSE; |
1618 | Exynos_OSAL_SignalCreate(&pH264Enc->hDestinationStartEvent); | |
20d3e6e3 JC |
1619 | |
1620 | Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); | |
1621 | Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); | |
1622 | pH264Enc->hMFCH264Handle.indexTimestamp = 0; | |
38ef2572 | 1623 | pH264Enc->hMFCH264Handle.outputIndexTimestamp = 0; |
20d3e6e3 | 1624 | |
38ef2572 JC |
1625 | pExynosComponent->getAllDelayBuffer = OMX_FALSE; |
1626 | ||
1627 | #if 0//defined(USE_CSC_GSCALER) | |
3e79a27e | 1628 | csc_method = CSC_METHOD_HW; //in case of Use ION buffer. |
38ef2572 | 1629 | #endif |
800a8d75 | 1630 | pVideoEnc->csc_handle = csc_init(csc_method); |
38ef2572 JC |
1631 | if (pVideoEnc->csc_handle == NULL) { |
1632 | ret = OMX_ErrorInsufficientResources; | |
1633 | goto EXIT; | |
1634 | } | |
1635 | pVideoEnc->csc_set_format = OMX_FALSE; | |
20d3e6e3 JC |
1636 | |
1637 | EXIT: | |
1638 | FunctionOut(); | |
1639 | ||
1640 | return ret; | |
1641 | } | |
1642 | ||
1643 | /* MFC Terminate */ | |
800a8d75 | 1644 | OMX_ERRORTYPE Exynos_H264Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) |
20d3e6e3 JC |
1645 | { |
1646 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1647 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1648 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = ((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle); | |
38ef2572 JC |
1649 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; |
1650 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
1651 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1652 | OMX_PTR hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
20d3e6e3 | 1653 | |
38ef2572 JC |
1654 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; |
1655 | ExynosVideoEncBufferOps *pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
1656 | ExynosVideoEncBufferOps *pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
20d3e6e3 | 1657 | |
38ef2572 | 1658 | int i = 0; |
20d3e6e3 | 1659 | |
38ef2572 | 1660 | FunctionIn(); |
20d3e6e3 | 1661 | |
38ef2572 JC |
1662 | if (pVideoEnc->csc_handle != NULL) { |
1663 | csc_deinit(pVideoEnc->csc_handle); | |
1664 | pVideoEnc->csc_handle = NULL; | |
20d3e6e3 JC |
1665 | } |
1666 | ||
38ef2572 JC |
1667 | Exynos_OSAL_SignalTerminate(pH264Enc->hDestinationStartEvent); |
1668 | pH264Enc->hDestinationStartEvent = NULL; | |
1669 | pH264Enc->bDestinationStart = OMX_FALSE; | |
1670 | Exynos_OSAL_SignalTerminate(pH264Enc->hSourceStartEvent); | |
1671 | pH264Enc->hSourceStartEvent = NULL; | |
1672 | pH264Enc->bSourceStart = OMX_FALSE; | |
1673 | ||
1674 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
1675 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { | |
1676 | if (pVideoEnc->pMFCEncInputBuffer[i] != NULL) { | |
1677 | if (pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr != NULL) | |
1678 | Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr); | |
1679 | if (pVideoEnc->pMFCEncInputBuffer[i]->CVirAddr != NULL) | |
1680 | Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->CVirAddr); | |
1681 | Exynos_OSAL_Free(pVideoEnc->pMFCEncInputBuffer[i]); | |
1682 | pVideoEnc->pMFCEncInputBuffer[i] = NULL; | |
1683 | } | |
1684 | } | |
20d3e6e3 | 1685 | |
3e79a27e | 1686 | Exynos_OSAL_QueueTerminate(&pExynosInputPort->codecBufferQ); |
38ef2572 JC |
1687 | Exynos_OSAL_SemaphoreTerminate(pExynosInputPort->codecSemID); |
1688 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
1689 | /*************/ | |
1690 | /* TBD */ | |
1691 | /*************/ | |
1692 | /* Does not require any actions. */ | |
1693 | } | |
1694 | ||
1695 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
3e79a27e | 1696 | for (i = 0; i < MFC_OUTPUT_BUFFER_NUM_MAX; i++) { |
38ef2572 JC |
1697 | if (pVideoEnc->pMFCEncOutputBuffer[i] != NULL) { |
1698 | if (pVideoEnc->pMFCEncOutputBuffer[i]->VirAddr != NULL) | |
1699 | Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncOutputBuffer[i]->VirAddr); | |
1700 | Exynos_OSAL_Free(pVideoEnc->pMFCEncOutputBuffer[i]); | |
1701 | pVideoEnc->pMFCEncOutputBuffer[i] = NULL; | |
1702 | } | |
1703 | } | |
20d3e6e3 | 1704 | |
38ef2572 JC |
1705 | Exynos_OSAL_QueueTerminate(&pExynosOutputPort->codecBufferQ); |
1706 | Exynos_OSAL_SemaphoreTerminate(pExynosOutputPort->codecSemID); | |
1707 | } else if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { | |
1708 | /*************/ | |
1709 | /* TBD */ | |
1710 | /*************/ | |
1711 | /* Does not require any actions. */ | |
20d3e6e3 | 1712 | } |
38ef2572 | 1713 | H264CodecClose(pH264Enc); |
20d3e6e3 JC |
1714 | |
1715 | EXIT: | |
1716 | FunctionOut(); | |
1717 | ||
1718 | return ret; | |
1719 | } | |
1720 | ||
38ef2572 | 1721 | OMX_ERRORTYPE Exynos_H264Enc_SrcIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData) |
20d3e6e3 | 1722 | { |
38ef2572 JC |
1723 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
1724 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1725 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1726 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1727 | void *hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
1728 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1729 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
1730 | OMX_U32 oneFrameSize = pSrcInputData->dataLen; | |
38ef2572 JC |
1731 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; |
1732 | ExynosVideoEncBufferOps *pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
1733 | ExynosVideoEncBufferOps *pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
1734 | ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE; | |
20d3e6e3 JC |
1735 | int i; |
1736 | ||
38ef2572 | 1737 | FunctionIn(); |
20d3e6e3 | 1738 | |
38ef2572 JC |
1739 | if (pH264Enc->hMFCH264Handle.bConfiguredMFCDst == OMX_FALSE) { |
1740 | ret = H264CodecDstSetup(pOMXComponent); | |
800a8d75 JC |
1741 | } |
1742 | ||
38ef2572 JC |
1743 | if (pH264Enc->hMFCH264Handle.bConfiguredMFCSrc == OMX_FALSE) { |
1744 | ret = H264CodecSrcSetup(pOMXComponent, pSrcInputData); | |
20d3e6e3 JC |
1745 | goto EXIT; |
1746 | } | |
1747 | ||
38ef2572 JC |
1748 | if ((pSrcInputData->dataLen >= 0) || |
1749 | ((pSrcInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) { | |
1750 | OMX_PTR pMFCYUVVirBuffer[2] = {NULL, NULL}; | |
1751 | OMX_U32 pMFCYUVDataSize[2] = {NULL, NULL}; | |
1752 | ||
1753 | pExynosComponent->timeStamp[pH264Enc->hMFCH264Handle.indexTimestamp] = pSrcInputData->timeStamp; | |
1754 | pExynosComponent->nFlags[pH264Enc->hMFCH264Handle.indexTimestamp] = pSrcInputData->nFlags; | |
1755 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "input timestamp %lld us (%.2f secs), Tag: %d, nFlags: 0x%x", pSrcInputData->timeStamp, pSrcInputData->timeStamp / 1E6, pH264Enc->hMFCH264Handle.indexTimestamp, pSrcInputData->nFlags); | |
1756 | pEncOps->Set_FrameTag(hMFCHandle, pH264Enc->hMFCH264Handle.indexTimestamp); | |
1757 | pH264Enc->hMFCH264Handle.indexTimestamp++; | |
1758 | pH264Enc->hMFCH264Handle.indexTimestamp %= MAX_TIMESTAMP; | |
1759 | ||
1760 | /* queue work for input buffer */ | |
1761 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
1762 | CODEC_ENC_INPUT_BUFFER *codecInputBuffer = (CODEC_ENC_INPUT_BUFFER *)pSrcInputData->pPrivate; | |
1763 | pMFCYUVDataSize[0] = codecInputBuffer->YDataSize; | |
1764 | pMFCYUVDataSize[1] = codecInputBuffer->CDataSize; | |
1765 | } else if (pExynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
1766 | pMFCYUVDataSize[0] = pExynosInputPort->portDefinition.format.video.nFrameWidth * pExynosInputPort->portDefinition.format.video.nFrameHeight; //codecInputBuffer->YDataSize; | |
1767 | pMFCYUVDataSize[1] = pMFCYUVDataSize[0]/2; | |
20d3e6e3 | 1768 | } |
20d3e6e3 | 1769 | |
38ef2572 | 1770 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "Exynos_H264Enc_SrcIn(): oneFrameSize: %d, bufferHeader: 0x%x", oneFrameSize, pSrcInputData->bufferHeader); |
20d3e6e3 | 1771 | |
38ef2572 JC |
1772 | pMFCYUVVirBuffer[0] = pSrcInputData->buffer.multiPlaneBuffer.dataBuffer[0]; |
1773 | pMFCYUVVirBuffer[1] = pSrcInputData->buffer.multiPlaneBuffer.dataBuffer[1]; | |
1774 | ||
1775 | codecReturn = pInbufOps->Enqueue(hMFCHandle, (unsigned char **)pMFCYUVVirBuffer, | |
1776 | (unsigned int *)pMFCYUVDataSize, 2, pSrcInputData->bufferHeader); | |
1777 | if (codecReturn != VIDEO_ERROR_NONE) { | |
1778 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: %d: Failed - pInbufOps->Enqueue", __FUNCTION__, __LINE__); | |
1779 | ret = (OMX_ERRORTYPE)OMX_ErrorCodecEncode; | |
1780 | goto EXIT; | |
1781 | } | |
20d3e6e3 | 1782 | |
38ef2572 JC |
1783 | // if (pH264Enc->bSourceStart ==OMX_TRUE) |
1784 | // H264CodecStart(pOMXComponent, INPUT_PORT_INDEX); | |
1785 | } | |
20d3e6e3 JC |
1786 | |
1787 | ret = OMX_ErrorNone; | |
1788 | ||
20d3e6e3 | 1789 | EXIT: |
38ef2572 JC |
1790 | FunctionOut(); |
1791 | ||
20d3e6e3 JC |
1792 | return ret; |
1793 | } | |
1794 | ||
38ef2572 | 1795 | OMX_ERRORTYPE Exynos_H264Enc_SrcOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData) |
20d3e6e3 | 1796 | { |
38ef2572 JC |
1797 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
1798 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1799 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1800 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1801 | void *hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
1802 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1803 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
1804 | ExynosVideoEncBufferOps *pInbufOps = pH264Enc->hMFCH264Handle.pInbufOps; | |
1805 | ExynosVideoBuffer *pVideoBuffer; | |
20d3e6e3 JC |
1806 | |
1807 | FunctionIn(); | |
1808 | ||
38ef2572 JC |
1809 | pVideoBuffer = pInbufOps->Dequeue(hMFCHandle); |
1810 | ||
1811 | pSrcOutputData->dataLen = 0; | |
1812 | pSrcOutputData->usedDataLen = 0; | |
1813 | pSrcOutputData->remainDataLen = 0; | |
1814 | pSrcOutputData->nFlags = 0; | |
1815 | pSrcOutputData->timeStamp = 0; | |
1816 | ||
1817 | if (pVideoBuffer == NULL) { | |
1818 | pSrcOutputData->buffer.singlePlaneBuffer.dataBuffer = NULL; | |
1819 | pSrcOutputData->allocSize = 0; | |
1820 | pSrcOutputData->pPrivate = NULL; | |
1821 | pSrcOutputData->bufferHeader = NULL; | |
1822 | } else { | |
1823 | pSrcOutputData->buffer.multiPlaneBuffer.dataBuffer[0] = pVideoBuffer->planes[0].addr; | |
1824 | pSrcOutputData->buffer.multiPlaneBuffer.dataBuffer[1] = pVideoBuffer->planes[1].addr; | |
1825 | pSrcOutputData->buffer.multiPlaneBuffer.dataBuffer[2] = pVideoBuffer->planes[2].addr; | |
1826 | pSrcOutputData->allocSize = pVideoBuffer->planes[0].allocSize + | |
1827 | pVideoBuffer->planes[1].allocSize + | |
1828 | pVideoBuffer->planes[2].allocSize; | |
1829 | ||
1830 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
1831 | int i = 0; | |
1832 | while (pSrcOutputData->buffer.multiPlaneBuffer.dataBuffer[0] != pVideoEnc->pMFCEncInputBuffer[i]->YVirAddr) { | |
1833 | if (i >= MFC_INPUT_BUFFER_NUM_MAX) { | |
1834 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: %d: Failed - Lost buffer", __FUNCTION__, __LINE__); | |
1835 | ret = (OMX_ERRORTYPE)OMX_ErrorCodecEncode; | |
1836 | goto EXIT; | |
1837 | } | |
1838 | i++; | |
1839 | } | |
1840 | pVideoEnc->pMFCEncInputBuffer[i]->YDataSize = 0; | |
1841 | pVideoEnc->pMFCEncInputBuffer[i]->CDataSize = 0; | |
1842 | pSrcOutputData->pPrivate = pVideoEnc->pMFCEncInputBuffer[i]; | |
1843 | } | |
1844 | ||
1845 | /* For Share Buffer */ | |
1846 | pSrcOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE*)pVideoBuffer->pPrivate; | |
1847 | } | |
20d3e6e3 | 1848 | |
38ef2572 | 1849 | ret = OMX_ErrorNone; |
20d3e6e3 | 1850 | |
38ef2572 JC |
1851 | EXIT: |
1852 | FunctionOut(); | |
20d3e6e3 | 1853 | |
38ef2572 JC |
1854 | return ret; |
1855 | } | |
20d3e6e3 | 1856 | |
38ef2572 JC |
1857 | OMX_ERRORTYPE Exynos_H264Enc_DstIn(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData) |
1858 | { | |
1859 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1860 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1861 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1862 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1863 | void *hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
1864 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
1865 | ExynosVideoEncBufferOps *pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
1866 | OMX_U32 dataLen = 0; | |
1867 | ExynosVideoErrorType codecReturn = VIDEO_ERROR_NONE; | |
20d3e6e3 | 1868 | |
38ef2572 | 1869 | FunctionIn(); |
20d3e6e3 | 1870 | |
38ef2572 JC |
1871 | if (pDstInputData->buffer.singlePlaneBuffer.dataBuffer == NULL) { |
1872 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to find input buffer"); | |
1873 | ret = OMX_ErrorBadParameter; | |
1874 | goto EXIT; | |
20d3e6e3 JC |
1875 | } |
1876 | ||
38ef2572 JC |
1877 | codecReturn = pOutbufOps->Enqueue(hMFCHandle, |
1878 | (unsigned char **)&pDstInputData->buffer.singlePlaneBuffer.dataBuffer, | |
1879 | (unsigned int *)&dataLen, 1, pDstInputData->bufferHeader); | |
20d3e6e3 | 1880 | |
38ef2572 JC |
1881 | if (codecReturn != VIDEO_ERROR_NONE) { |
1882 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: %d: Failed - pOutbufOps->Enqueue", __FUNCTION__, __LINE__); | |
1883 | ret = (OMX_ERRORTYPE)OMX_ErrorCodecEncode; | |
20d3e6e3 JC |
1884 | goto EXIT; |
1885 | } | |
1886 | ||
38ef2572 JC |
1887 | // if (pH264Enc->bDestinationStart ==OMX_TRUE) |
1888 | // H264CodecStart(pOMXComponent, OUTPUT_PORT_INDEX); | |
20d3e6e3 | 1889 | |
38ef2572 | 1890 | ret = OMX_ErrorNone; |
20d3e6e3 | 1891 | |
38ef2572 JC |
1892 | EXIT: |
1893 | FunctionOut(); | |
20d3e6e3 | 1894 | |
38ef2572 JC |
1895 | return ret; |
1896 | } | |
20d3e6e3 | 1897 | |
38ef2572 JC |
1898 | OMX_ERRORTYPE Exynos_H264Enc_DstOut(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData) |
1899 | { | |
1900 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1901 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1902 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1903 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1904 | void *hMFCHandle = pH264Enc->hMFCH264Handle.hMFCHandle; | |
1905 | ExynosVideoEncOps *pEncOps = pH264Enc->hMFCH264Handle.pEncOps; | |
1906 | ExynosVideoEncBufferOps *pOutbufOps = pH264Enc->hMFCH264Handle.pOutbufOps; | |
1907 | ExynosVideoBuffer *pVideoBuffer; | |
1908 | ExynosVideoFrameStatusType displayStatus = VIDEO_FRAME_STATUS_UNKNOWN; | |
1909 | ExynosVideoGeometry bufferGeometry; | |
1910 | OMX_S32 indexTimestamp = 0; | |
20d3e6e3 | 1911 | |
38ef2572 | 1912 | FunctionIn(); |
20d3e6e3 | 1913 | |
38ef2572 JC |
1914 | if (pH264Enc->bDestinationStart == OMX_FALSE) { |
1915 | ret = OMX_ErrorNone; | |
1916 | goto EXIT; | |
1917 | } | |
20d3e6e3 | 1918 | |
38ef2572 JC |
1919 | if ((pVideoBuffer = pOutbufOps->Dequeue(hMFCHandle)) == NULL) { |
1920 | ret = OMX_ErrorNone; | |
1921 | goto EXIT; | |
1922 | } | |
20d3e6e3 | 1923 | |
38ef2572 JC |
1924 | pH264Enc->hMFCH264Handle.outputIndexTimestamp++; |
1925 | pH264Enc->hMFCH264Handle.outputIndexTimestamp %= MAX_TIMESTAMP; | |
1926 | ||
1927 | pDstOutputData->buffer.singlePlaneBuffer.dataBuffer = pVideoBuffer->planes[0].addr; | |
1928 | pDstOutputData->allocSize = pVideoBuffer->planes[0].allocSize; | |
1929 | pDstOutputData->dataLen = pVideoBuffer->planes[0].dataSize; | |
1930 | pDstOutputData->remainDataLen = pVideoBuffer->planes[0].dataSize; | |
1931 | pDstOutputData->usedDataLen = 0; | |
1932 | pDstOutputData->pPrivate = pVideoBuffer; | |
1933 | /* For Share Buffer */ | |
1934 | pDstOutputData->bufferHeader = (OMX_BUFFERHEADERTYPE *)pVideoBuffer->pPrivate; | |
1935 | ||
1936 | if (pVideoEnc->bFirstOutput == OMX_FALSE) { | |
1937 | OMX_U8 *p = NULL; | |
1938 | int iSpsSize = 0; | |
1939 | int iPpsSize = 0; | |
1940 | ||
1941 | /* Calculate sps/pps size if needed */ | |
1942 | p = FindDelimiter((OMX_U8 *)(pDstOutputData->buffer.singlePlaneBuffer.dataBuffer + 4), | |
1943 | pDstOutputData->dataLen - 4); | |
1944 | ||
1945 | iSpsSize = (unsigned int)p - (unsigned int)pDstOutputData->buffer.singlePlaneBuffer.dataBuffer; | |
1946 | pH264Enc->hMFCH264Handle.headerData.pHeaderSPS = | |
1947 | (OMX_PTR)pDstOutputData->buffer.singlePlaneBuffer.dataBuffer; | |
1948 | pH264Enc->hMFCH264Handle.headerData.SPSLen = iSpsSize; | |
3e79a27e | 1949 | |
38ef2572 JC |
1950 | iPpsSize = pDstOutputData->dataLen - iSpsSize; |
1951 | pH264Enc->hMFCH264Handle.headerData.pHeaderPPS = | |
1952 | (OMX_U8 *)pDstOutputData->buffer.singlePlaneBuffer.dataBuffer + iSpsSize; | |
1953 | pH264Enc->hMFCH264Handle.headerData.PPSLen = iPpsSize; | |
3e79a27e | 1954 | |
38ef2572 JC |
1955 | pDstOutputData->timeStamp = 0; |
1956 | pDstOutputData->nFlags |= OMX_BUFFERFLAG_CODECCONFIG; | |
1957 | pDstOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; | |
1958 | } else { | |
20d3e6e3 JC |
1959 | indexTimestamp = pEncOps->Get_FrameTag(pH264Enc->hMFCH264Handle.hMFCHandle); |
1960 | if ((indexTimestamp < 0) || (indexTimestamp >= MAX_TIMESTAMP)) { | |
38ef2572 JC |
1961 | pDstOutputData->timeStamp = pExynosComponent->timeStamp[pH264Enc->hMFCH264Handle.outputIndexTimestamp]; |
1962 | pDstOutputData->nFlags = pExynosComponent->nFlags[pH264Enc->hMFCH264Handle.outputIndexTimestamp]; | |
20d3e6e3 | 1963 | } else { |
38ef2572 JC |
1964 | pDstOutputData->timeStamp = pExynosComponent->timeStamp[indexTimestamp]; |
1965 | pDstOutputData->nFlags = pExynosComponent->nFlags[indexTimestamp]; | |
20d3e6e3 JC |
1966 | } |
1967 | ||
38ef2572 JC |
1968 | pDstOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; |
1969 | if (pVideoBuffer->frameType == VIDEO_FRAME_I) | |
1970 | pDstOutputData->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; | |
1971 | } | |
20d3e6e3 | 1972 | |
38ef2572 JC |
1973 | if ((displayStatus == VIDEO_FRAME_STATUS_CHANGE_RESOL) || |
1974 | ((pDstOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS)) { | |
1975 | pDstOutputData->remainDataLen = 0; | |
1976 | } | |
20d3e6e3 | 1977 | |
38ef2572 | 1978 | ret = OMX_ErrorNone; |
20d3e6e3 | 1979 | |
38ef2572 JC |
1980 | EXIT: |
1981 | FunctionOut(); | |
20d3e6e3 | 1982 | |
38ef2572 JC |
1983 | return ret; |
1984 | } | |
20d3e6e3 | 1985 | |
38ef2572 JC |
1986 | OMX_ERRORTYPE Exynos_H264Enc_srcInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcInputData) |
1987 | { | |
1988 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1989 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1990 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
1991 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1992 | ||
1993 | FunctionIn(); | |
1994 | ||
1995 | if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) { | |
1996 | ret = OMX_ErrorNone; | |
1997 | goto EXIT; | |
1998 | } | |
1999 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) { | |
2000 | ret = OMX_ErrorNone; | |
2001 | goto EXIT; | |
2002 | } | |
2003 | ||
2004 | ret = Exynos_H264Enc_SrcIn(pOMXComponent, pSrcInputData); | |
2005 | if (ret != OMX_ErrorNone) { | |
2006 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: %d: Failed - SrcIn -> event is thrown to client", __FUNCTION__, __LINE__); | |
2007 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
2008 | pExynosComponent->callbackData, | |
2009 | OMX_EventError, ret, 0, NULL); | |
2010 | } | |
2011 | ||
2012 | EXIT: | |
2013 | FunctionOut(); | |
2014 | ||
2015 | return ret; | |
2016 | } | |
2017 | ||
2018 | OMX_ERRORTYPE Exynos_H264Enc_srcOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pSrcOutputData) | |
2019 | { | |
2020 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
2021 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
2022 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
2023 | EXYNOS_OMX_BASEPORT *pExynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
2024 | ||
2025 | FunctionIn(); | |
2026 | ||
2027 | if ((!CHECK_PORT_ENABLED(pExynosInputPort)) || (!CHECK_PORT_POPULATED(pExynosInputPort))) { | |
2028 | ret = OMX_ErrorNone; | |
2029 | goto EXIT; | |
2030 | } | |
20d3e6e3 | 2031 | |
38ef2572 JC |
2032 | if ((pExynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
2033 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) { | |
20d3e6e3 | 2034 | ret = OMX_ErrorNone; |
38ef2572 | 2035 | goto EXIT; |
20d3e6e3 JC |
2036 | } |
2037 | } | |
38ef2572 JC |
2038 | if ((pH264Enc->bSourceStart == OMX_FALSE) && |
2039 | (!CHECK_PORT_BEING_FLUSHED(pExynosInputPort))) { | |
2040 | Exynos_OSAL_SignalWait(pH264Enc->hSourceStartEvent, DEF_MAX_WAIT_TIME); | |
2041 | Exynos_OSAL_SignalReset(pH264Enc->hSourceStartEvent); | |
20d3e6e3 JC |
2042 | } |
2043 | ||
38ef2572 JC |
2044 | ret = Exynos_H264Enc_SrcOut(pOMXComponent, pSrcOutputData); |
2045 | if ((ret != OMX_ErrorNone) && (pExynosComponent->currentState == OMX_StateExecuting)) { | |
2046 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: %d: Failed - SrcOut -> event is thrown to client", __FUNCTION__, __LINE__); | |
2047 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
2048 | pExynosComponent->callbackData, | |
2049 | OMX_EventError, ret, 0, NULL); | |
20d3e6e3 JC |
2050 | } |
2051 | ||
38ef2572 JC |
2052 | EXIT: |
2053 | FunctionOut(); | |
2054 | ||
2055 | return ret; | |
2056 | } | |
2057 | ||
2058 | OMX_ERRORTYPE Exynos_H264Enc_dstInputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstInputData) | |
2059 | { | |
2060 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
2061 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
2062 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
2063 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
2064 | ||
2065 | FunctionIn(); | |
2066 | ||
2067 | if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) { | |
2068 | ret = OMX_ErrorNone; | |
800a8d75 JC |
2069 | goto EXIT; |
2070 | } | |
38ef2572 JC |
2071 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) { |
2072 | ret = OMX_ErrorNone; | |
800a8d75 | 2073 | goto EXIT; |
800a8d75 | 2074 | } |
38ef2572 JC |
2075 | if (pExynosOutputPort->bufferProcessType == BUFFER_SHARE) { |
2076 | if ((pH264Enc->bDestinationStart == OMX_FALSE) && | |
2077 | (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) { | |
2078 | Exynos_OSAL_SignalWait(pH264Enc->hDestinationStartEvent, DEF_MAX_WAIT_TIME); | |
2079 | Exynos_OSAL_SignalReset(pH264Enc->hDestinationStartEvent); | |
2080 | } | |
2081 | } | |
38ef2572 JC |
2082 | if (pH264Enc->hMFCH264Handle.bConfiguredMFCDst == OMX_TRUE) { |
2083 | ret = Exynos_H264Enc_DstIn(pOMXComponent, pDstInputData); | |
2084 | if (ret != OMX_ErrorNone) { | |
2085 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: %d: Failed - DstIn -> event is thrown to client", __FUNCTION__, __LINE__); | |
2086 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
2087 | pExynosComponent->callbackData, | |
2088 | OMX_EventError, ret, 0, NULL); | |
2089 | } | |
2090 | } | |
20d3e6e3 JC |
2091 | |
2092 | EXIT: | |
2093 | FunctionOut(); | |
2094 | ||
2095 | return ret; | |
2096 | } | |
2097 | ||
38ef2572 | 2098 | OMX_ERRORTYPE Exynos_H264Enc_dstOutputBufferProcess(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *pDstOutputData) |
20d3e6e3 | 2099 | { |
38ef2572 JC |
2100 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
2101 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
2102 | EXYNOS_H264ENC_HANDLE *pH264Enc = (EXYNOS_H264ENC_HANDLE *)((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle; | |
2103 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
20d3e6e3 JC |
2104 | |
2105 | FunctionIn(); | |
2106 | ||
38ef2572 | 2107 | if ((!CHECK_PORT_ENABLED(pExynosOutputPort)) || (!CHECK_PORT_POPULATED(pExynosOutputPort))) { |
20d3e6e3 JC |
2108 | ret = OMX_ErrorNone; |
2109 | goto EXIT; | |
2110 | } | |
38ef2572 | 2111 | if (OMX_FALSE == Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) { |
20d3e6e3 JC |
2112 | ret = OMX_ErrorNone; |
2113 | goto EXIT; | |
2114 | } | |
2115 | ||
38ef2572 JC |
2116 | if ((pExynosOutputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { |
2117 | if ((pH264Enc->bDestinationStart == OMX_FALSE) && | |
2118 | (!CHECK_PORT_BEING_FLUSHED(pExynosOutputPort))) { | |
2119 | Exynos_OSAL_SignalWait(pH264Enc->hDestinationStartEvent, DEF_MAX_WAIT_TIME); | |
2120 | Exynos_OSAL_SignalReset(pH264Enc->hDestinationStartEvent); | |
20d3e6e3 | 2121 | } |
38ef2572 | 2122 | } |
38ef2572 JC |
2123 | ret = Exynos_H264Enc_DstOut(pOMXComponent, pDstOutputData); |
2124 | if ((ret != OMX_ErrorNone) && (pExynosComponent->currentState == OMX_StateExecuting)) { | |
2125 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: %d: Failed - DstOut -> event is thrown to client", __FUNCTION__, __LINE__); | |
2126 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
2127 | pExynosComponent->callbackData, | |
2128 | OMX_EventError, ret, 0, NULL); | |
20d3e6e3 JC |
2129 | } |
2130 | ||
2131 | EXIT: | |
2132 | FunctionOut(); | |
2133 | ||
2134 | return ret; | |
2135 | } | |
2136 | ||
2137 | OSCL_EXPORT_REF OMX_ERRORTYPE Exynos_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName) | |
2138 | { | |
2139 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
2140 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
2141 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
2142 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
2143 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; | |
2144 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; | |
2145 | int i = 0; | |
2146 | ||
2147 | FunctionIn(); | |
2148 | ||
2149 | if ((hComponent == NULL) || (componentName == NULL)) { | |
2150 | ret = OMX_ErrorBadParameter; | |
2151 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); | |
2152 | goto EXIT; | |
2153 | } | |
2154 | if (Exynos_OSAL_Strcmp(EXYNOS_OMX_COMPONENT_H264_ENC, componentName) != 0) { | |
2155 | ret = OMX_ErrorBadParameter; | |
2156 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorBadParameter, componentName:%s, Line:%d", componentName, __LINE__); | |
2157 | goto EXIT; | |
2158 | } | |
2159 | ||
2160 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
2161 | ret = Exynos_OMX_VideoEncodeComponentInit(pOMXComponent); | |
2162 | if (ret != OMX_ErrorNone) { | |
2163 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_Error, Line:%d", __LINE__); | |
2164 | goto EXIT; | |
2165 | } | |
2166 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
2167 | pExynosComponent->codecType = HW_VIDEO_ENC_CODEC; | |
2168 | ||
2169 | pExynosComponent->componentName = (OMX_STRING)Exynos_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE); | |
2170 | if (pExynosComponent->componentName == NULL) { | |
2171 | Exynos_OMX_VideoEncodeComponentDeinit(pOMXComponent); | |
2172 | ret = OMX_ErrorInsufficientResources; | |
2173 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); | |
2174 | goto EXIT; | |
2175 | } | |
2176 | Exynos_OSAL_Memset(pExynosComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE); | |
2177 | ||
2178 | pH264Enc = Exynos_OSAL_Malloc(sizeof(EXYNOS_H264ENC_HANDLE)); | |
2179 | if (pH264Enc == NULL) { | |
2180 | Exynos_OMX_VideoEncodeComponentDeinit(pOMXComponent); | |
2181 | ret = OMX_ErrorInsufficientResources; | |
2182 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); | |
2183 | goto EXIT; | |
2184 | } | |
2185 | Exynos_OSAL_Memset(pH264Enc, 0, sizeof(EXYNOS_H264ENC_HANDLE)); | |
2186 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
2187 | pVideoEnc->hCodecHandle = (OMX_HANDLETYPE)pH264Enc; | |
38ef2572 JC |
2188 | pVideoEnc->quantization.nQpI = 20; |
2189 | pVideoEnc->quantization.nQpP = 20; | |
2190 | pVideoEnc->quantization.nQpB = 20; | |
20d3e6e3 JC |
2191 | |
2192 | Exynos_OSAL_Strcpy(pExynosComponent->componentName, EXYNOS_OMX_COMPONENT_H264_ENC); | |
2193 | /* Set componentVersion */ | |
2194 | pExynosComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; | |
2195 | pExynosComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; | |
2196 | pExynosComponent->componentVersion.s.nRevision = REVISION_NUMBER; | |
2197 | pExynosComponent->componentVersion.s.nStep = STEP_NUMBER; | |
2198 | /* Set specVersion */ | |
2199 | pExynosComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; | |
2200 | pExynosComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; | |
2201 | pExynosComponent->specVersion.s.nRevision = REVISION_NUMBER; | |
2202 | pExynosComponent->specVersion.s.nStep = STEP_NUMBER; | |
2203 | ||
20d3e6e3 JC |
2204 | /* Input port */ |
2205 | pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
2206 | pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; | |
2207 | pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; | |
2208 | pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/ | |
2209 | pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE; | |
2210 | pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; | |
2211 | Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); | |
2212 | Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "raw/video"); | |
2213 | pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; | |
2214 | pExynosPort->portDefinition.bEnabled = OMX_TRUE; | |
38ef2572 JC |
2215 | pExynosPort->bufferProcessType = BUFFER_COPY; |
2216 | pExynosPort->portWayType = WAY2_PORT; | |
20d3e6e3 JC |
2217 | |
2218 | /* Output port */ | |
2219 | pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
2220 | pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; | |
2221 | pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; | |
2222 | pExynosPort->portDefinition.format.video.nStride = 0; /*DEFAULT_FRAME_WIDTH;*/ | |
2223 | pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; | |
2224 | pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; | |
2225 | Exynos_OSAL_Memset(pExynosPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); | |
2226 | Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "video/avc"); | |
2227 | pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; | |
2228 | pExynosPort->portDefinition.bEnabled = OMX_TRUE; | |
38ef2572 JC |
2229 | pExynosPort->bufferProcessType = BUFFER_COPY; |
2230 | pExynosPort->portWayType = WAY2_PORT; | |
20d3e6e3 JC |
2231 | |
2232 | for(i = 0; i < ALL_PORT_NUM; i++) { | |
2233 | INIT_SET_SIZE_VERSION(&pH264Enc->AVCComponent[i], OMX_VIDEO_PARAM_AVCTYPE); | |
2234 | pH264Enc->AVCComponent[i].nPortIndex = i; | |
2235 | pH264Enc->AVCComponent[i].eProfile = OMX_VIDEO_AVCProfileBaseline; | |
2236 | pH264Enc->AVCComponent[i].eLevel = OMX_VIDEO_AVCLevel31; | |
2237 | ||
2238 | pH264Enc->AVCComponent[i].nPFrames = 20; | |
2239 | } | |
2240 | ||
800a8d75 JC |
2241 | pOMXComponent->GetParameter = &Exynos_H264Enc_GetParameter; |
2242 | pOMXComponent->SetParameter = &Exynos_H264Enc_SetParameter; | |
2243 | pOMXComponent->GetConfig = &Exynos_H264Enc_GetConfig; | |
2244 | pOMXComponent->SetConfig = &Exynos_H264Enc_SetConfig; | |
2245 | pOMXComponent->GetExtensionIndex = &Exynos_H264Enc_GetExtensionIndex; | |
2246 | pOMXComponent->ComponentRoleEnum = &Exynos_H264Enc_ComponentRoleEnum; | |
20d3e6e3 JC |
2247 | pOMXComponent->ComponentDeInit = &Exynos_OMX_ComponentDeinit; |
2248 | ||
38ef2572 JC |
2249 | pExynosComponent->exynos_codec_componentInit = &Exynos_H264Enc_Init; |
2250 | pExynosComponent->exynos_codec_componentTerminate = &Exynos_H264Enc_Terminate; | |
2251 | ||
2252 | pVideoEnc->exynos_codec_srcInputProcess = &Exynos_H264Enc_srcInputBufferProcess; | |
2253 | pVideoEnc->exynos_codec_srcOutputProcess = &Exynos_H264Enc_srcOutputBufferProcess; | |
2254 | pVideoEnc->exynos_codec_dstInputProcess = &Exynos_H264Enc_dstInputBufferProcess; | |
2255 | pVideoEnc->exynos_codec_dstOutputProcess = &Exynos_H264Enc_dstOutputBufferProcess; | |
2256 | ||
2257 | pVideoEnc->exynos_codec_start = &H264CodecStart; | |
2258 | pVideoEnc->exynos_codec_stop = &H264CodecStop; | |
2259 | pVideoEnc->exynos_codec_bufferProcessRun = &H264CodecOutputBufferProcessRun; | |
2260 | pVideoEnc->exynos_codec_enqueueAllBuffer = &H264CodecEnQueueAllBuffer; | |
2261 | ||
2262 | pVideoEnc->exynos_checkInputFrame = NULL; | |
2263 | pVideoEnc->exynos_codec_getCodecInputPrivateData = &GetCodecInputPrivateData; | |
2264 | pVideoEnc->exynos_codec_getCodecOutputPrivateData = &GetCodecOutputPrivateData; | |
38ef2572 JC |
2265 | |
2266 | pVideoEnc->hSharedMemory = Exynos_OSAL_SharedMemory_Open(); | |
2267 | if (pVideoEnc->hSharedMemory == NULL) { | |
2268 | Exynos_OSAL_Free(pH264Enc); | |
2269 | pH264Enc = ((EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle)->hCodecHandle = NULL; | |
2270 | Exynos_OMX_VideoEncodeComponentDeinit(pOMXComponent); | |
2271 | ret = OMX_ErrorInsufficientResources; | |
2272 | goto EXIT; | |
2273 | } | |
20d3e6e3 JC |
2274 | |
2275 | pExynosComponent->currentState = OMX_StateLoaded; | |
2276 | ||
2277 | ret = OMX_ErrorNone; | |
2278 | ||
2279 | EXIT: | |
2280 | FunctionOut(); | |
2281 | ||
2282 | return ret; | |
2283 | } | |
2284 | ||
2285 | OMX_ERRORTYPE Exynos_OMX_ComponentDeinit(OMX_HANDLETYPE hComponent) | |
2286 | { | |
38ef2572 JC |
2287 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
2288 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
20d3e6e3 | 2289 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
38ef2572 | 2290 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
20d3e6e3 JC |
2291 | EXYNOS_H264ENC_HANDLE *pH264Enc = NULL; |
2292 | ||
2293 | FunctionIn(); | |
2294 | ||
2295 | if (hComponent == NULL) { | |
2296 | ret = OMX_ErrorBadParameter; | |
2297 | goto EXIT; | |
2298 | } | |
2299 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
2300 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
38ef2572 JC |
2301 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
2302 | ||
2303 | Exynos_OSAL_SharedMemory_Close(pVideoEnc->hSharedMemory); | |
20d3e6e3 JC |
2304 | |
2305 | Exynos_OSAL_Free(pExynosComponent->componentName); | |
2306 | pExynosComponent->componentName = NULL; | |
2307 | ||
38ef2572 | 2308 | pH264Enc = (EXYNOS_H264ENC_HANDLE *)pVideoEnc->hCodecHandle; |
20d3e6e3 JC |
2309 | if (pH264Enc != NULL) { |
2310 | Exynos_OSAL_Free(pH264Enc); | |
38ef2572 | 2311 | pH264Enc = pVideoEnc->hCodecHandle = NULL; |
20d3e6e3 JC |
2312 | } |
2313 | ||
2314 | ret = Exynos_OMX_VideoEncodeComponentDeinit(pOMXComponent); | |
2315 | if (ret != OMX_ErrorNone) { | |
2316 | goto EXIT; | |
2317 | } | |
2318 | ||
2319 | ret = OMX_ErrorNone; | |
2320 | ||
2321 | EXIT: | |
2322 | FunctionOut(); | |
2323 | ||
2324 | return ret; | |
2325 | } |