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