venc: removed FlushXXBufferReturn function
[GitHub/LineageOS/android_hardware_samsung_slsi_openmax.git] / component / video / enc / Exynos_OMX_Venc.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_Venc.c
20 * @brief
21 * @author SeungBeom Kim (sbcrux.kim@samsung.com)
22 * Yunji Kim (yunji.kim@samsung.com)
23 * @version 2.0.0
24 * @history
25 * 2012.02.20 : Create
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include "Exynos_OMX_Macros.h"
32 #include "Exynos_OSAL_Event.h"
33 #include "Exynos_OMX_Venc.h"
34 #include "Exynos_OMX_VencControl.h"
35 #include "Exynos_OMX_Basecomponent.h"
36 #include "Exynos_OSAL_Thread.h"
37 #include "Exynos_OSAL_Semaphore.h"
38 #include "Exynos_OSAL_SharedMemory.h"
39 #include "Exynos_OSAL_Mutex.h"
40 #include "Exynos_OSAL_ETC.h"
41 #include "ExynosVideoApi.h"
42 #include "csc.h"
43
44 #ifdef USE_STOREMETADATA
45 #include "Exynos_OSAL_Android.h"
46 #endif
47
48 #undef EXYNOS_LOG_TAG
49 #define EXYNOS_LOG_TAG "EXYNOS_VIDEO_ENC"
50 #define EXYNOS_LOG_OFF
51 //#define EXYNOS_TRACE_ON
52 #include "Exynos_OSAL_Log.h"
53
54
55 inline void Exynos_UpdateFrameSize(OMX_COMPONENTTYPE *pOMXComponent)
56 {
57 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
58 EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
59 EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
60
61 if ((exynosOutputPort->portDefinition.format.video.nFrameWidth !=
62 exynosInputPort->portDefinition.format.video.nFrameWidth) ||
63 (exynosOutputPort->portDefinition.format.video.nFrameHeight !=
64 exynosInputPort->portDefinition.format.video.nFrameHeight)) {
65 OMX_U32 width = 0, height = 0;
66
67 exynosOutputPort->portDefinition.format.video.nFrameWidth =
68 exynosInputPort->portDefinition.format.video.nFrameWidth;
69 exynosOutputPort->portDefinition.format.video.nFrameHeight =
70 exynosInputPort->portDefinition.format.video.nFrameHeight;
71 width = exynosOutputPort->portDefinition.format.video.nStride =
72 exynosInputPort->portDefinition.format.video.nStride;
73 height = exynosOutputPort->portDefinition.format.video.nSliceHeight =
74 exynosInputPort->portDefinition.format.video.nSliceHeight;
75
76 if (width && height)
77 exynosOutputPort->portDefinition.nBufferSize = (width * height * 3) / 2;
78 }
79
80 return;
81 }
82
83 void Exynos_Free_CodecBuffers(
84 OMX_COMPONENTTYPE *pOMXComponent,
85 OMX_U32 nPortIndex)
86 {
87 OMX_ERRORTYPE ret = OMX_ErrorNone;
88 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
89 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
90 CODEC_ENC_BUFFER **ppCodecBuffer = NULL;
91
92 OMX_U32 nBufferCnt = 0, nPlaneCnt = 0;
93 int i, j;
94
95 FunctionIn();
96
97 if (nPortIndex == INPUT_PORT_INDEX) {
98 ppCodecBuffer = &(pVideoEnc->pMFCEncInputBuffer[0]);
99 nBufferCnt = MFC_INPUT_BUFFER_NUM_MAX;
100 nPlaneCnt = MFC_INPUT_BUFFER_PLANE;
101 } else {
102 ppCodecBuffer = &(pVideoEnc->pMFCEncOutputBuffer[0]);
103 nBufferCnt = MFC_OUTPUT_BUFFER_NUM_MAX;
104 nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE;
105 }
106
107 for (i = 0; i < nBufferCnt; i++) {
108 if (ppCodecBuffer[i] != NULL) {
109 for (j = 0; j < nPlaneCnt; j++) {
110 if (ppCodecBuffer[i]->pVirAddr[j] != NULL)
111 Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, ppCodecBuffer[i]->pVirAddr[j]);
112 }
113
114 Exynos_OSAL_Free(ppCodecBuffer[i]);
115 ppCodecBuffer[i] = NULL;
116 }
117 }
118
119 FunctionOut();
120 }
121
122 OMX_ERRORTYPE Exynos_Allocate_CodecBuffers(
123 OMX_COMPONENTTYPE *pOMXComponent,
124 OMX_U32 nPortIndex,
125 OMX_U32 nBufferCnt,
126 OMX_U32 nPlaneSize[MFC_OUTPUT_BUFFER_PLANE])
127 {
128 OMX_ERRORTYPE ret = OMX_ErrorNone;
129 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
130 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
131 MEMORY_TYPE eMemoryType = SYSTEM_MEMORY;
132 CODEC_ENC_BUFFER **ppCodecBuffer = NULL;
133
134 OMX_U32 nPlaneCnt = 0;
135 int i, j;
136
137 FunctionIn();
138
139 if (nPortIndex == INPUT_PORT_INDEX) {
140 ppCodecBuffer = &(pVideoEnc->pMFCEncInputBuffer[0]);
141 nPlaneCnt = MFC_INPUT_BUFFER_PLANE;
142 } else {
143 ppCodecBuffer = &(pVideoEnc->pMFCEncOutputBuffer[0]);
144 nPlaneCnt = MFC_OUTPUT_BUFFER_PLANE;
145 #ifdef USE_CSC_HW
146 eMemoryType = NORMAL_MEMORY;
147 #endif
148 }
149
150 if (pVideoEnc->bDRMPlayerMode == OMX_TRUE)
151 eMemoryType = SECURE_MEMORY;
152
153 for (i = 0; i < nBufferCnt; i++) {
154 ppCodecBuffer[i] = (CODEC_ENC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER));
155 if (ppCodecBuffer[i] == NULL) {
156 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc codec buffer");
157 ret = OMX_ErrorInsufficientResources;
158 goto EXIT;
159 }
160 Exynos_OSAL_Memset(ppCodecBuffer[i], 0, sizeof(CODEC_ENC_BUFFER));
161
162 for (j = 0; j < nPlaneCnt; j++) {
163 ppCodecBuffer[i]->pVirAddr[j] =
164 (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, nPlaneSize[j], eMemoryType);
165 if (ppCodecBuffer[i]->pVirAddr[j] == NULL) {
166 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc plane");
167 ret = OMX_ErrorInsufficientResources;
168 goto EXIT;
169 }
170
171 ppCodecBuffer[i]->fd[j] =
172 Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, ppCodecBuffer[i]->pVirAddr[j]);
173 ppCodecBuffer[i]->bufferSize[j] = nPlaneSize[j];
174 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "PORT[%d]: pMFCCodecBuffer[%d]->pVirAddr[%d]: 0x%x", nPortIndex, i, j, ppCodecBuffer[i]->pVirAddr[j]);
175 }
176
177 ppCodecBuffer[i]->dataSize = 0;
178 }
179
180 return OMX_ErrorNone;
181
182 EXIT:
183 Exynos_Free_CodecBuffers(pOMXComponent, nPortIndex);
184
185 FunctionOut();
186
187 return ret;
188 }
189
190 OMX_BOOL Exynos_Check_BufferProcess_State(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 nPortIndex)
191 {
192 OMX_BOOL ret = OMX_FALSE;
193
194 if ((pExynosComponent->currentState == OMX_StateExecuting) &&
195 (pExynosComponent->pExynosPort[nPortIndex].portState == OMX_StateIdle) &&
196 (pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) &&
197 (pExynosComponent->transientState != EXYNOS_OMX_TransStateIdleToExecuting)) {
198 ret = OMX_TRUE;
199 } else {
200 ret = OMX_FALSE;
201 }
202
203 return ret;
204 }
205
206 OMX_ERRORTYPE Exynos_Input_CodecBufferToData(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_PTR codecBuffer, EXYNOS_OMX_DATA *pData)
207 {
208 OMX_ERRORTYPE ret = OMX_ErrorNone;
209 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
210 CODEC_ENC_BUFFER *pInputCodecBuffer = (CODEC_ENC_BUFFER*)codecBuffer;
211
212 pData->buffer.multiPlaneBuffer.dataBuffer[0] = pInputCodecBuffer->pVirAddr[0];
213 pData->buffer.multiPlaneBuffer.dataBuffer[1] = pInputCodecBuffer->pVirAddr[1];
214 pData->buffer.multiPlaneBuffer.fd[0] = pInputCodecBuffer->fd[0];
215 pData->buffer.multiPlaneBuffer.fd[1] = pInputCodecBuffer->fd[1];
216 pData->allocSize = pInputCodecBuffer->bufferSize[0] + pInputCodecBuffer->bufferSize[1];
217 pData->dataLen = pInputCodecBuffer->dataSize;
218 pData->usedDataLen = 0;
219 pData->remainDataLen = pInputCodecBuffer->dataSize;
220
221 pData->nFlags = 0;
222 pData->timeStamp = 0;
223 pData->pPrivate = codecBuffer;
224 pData->bufferHeader = NULL;
225
226 return ret;
227 }
228
229 OMX_ERRORTYPE Exynos_Output_CodecBufferToData(
230 CODEC_ENC_BUFFER *pCodecBuffer,
231 EXYNOS_OMX_DATA *pData)
232 {
233 OMX_ERRORTYPE ret = OMX_ErrorNone;
234
235 pData->buffer.singlePlaneBuffer.dataBuffer = pCodecBuffer->pVirAddr[0];
236 pData->buffer.singlePlaneBuffer.fd = pCodecBuffer->fd[0];
237 pData->allocSize = pCodecBuffer->bufferSize[0];
238 pData->dataLen = 0;
239 pData->usedDataLen = 0;
240 pData->remainDataLen = 0;
241
242 pData->nFlags = 0;
243 pData->timeStamp = 0;
244 pData->pPrivate = pCodecBuffer;
245 pData->bufferHeader = NULL;
246
247 return ret;
248 }
249
250 void Exynos_Wait_ProcessPause(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 nPortIndex)
251 {
252 EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
253 EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
254 EXYNOS_OMX_BASEPORT *exynosOMXPort = NULL;
255
256 FunctionIn();
257
258 exynosOMXPort = &pExynosComponent->pExynosPort[nPortIndex];
259
260 if (((pExynosComponent->currentState == OMX_StatePause) ||
261 (pExynosComponent->currentState == OMX_StateIdle) ||
262 (pExynosComponent->transientState == EXYNOS_OMX_TransStateLoadedToIdle) ||
263 (pExynosComponent->transientState == EXYNOS_OMX_TransStateExecutingToIdle)) &&
264 (pExynosComponent->transientState != EXYNOS_OMX_TransStateIdleToLoaded) &&
265 (!CHECK_PORT_BEING_FLUSHED(exynosOMXPort))) {
266 Exynos_OSAL_SignalWait(pExynosComponent->pExynosPort[nPortIndex].pauseEvent, DEF_MAX_WAIT_TIME);
267 Exynos_OSAL_SignalReset(pExynosComponent->pExynosPort[nPortIndex].pauseEvent);
268 }
269
270 FunctionOut();
271
272 return;
273 }
274
275 OMX_BOOL Exynos_CSC_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *srcInputData)
276 {
277 OMX_BOOL ret = OMX_FALSE;
278 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
279 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
280 EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
281 EXYNOS_OMX_DATABUFFER *inputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer;
282 OMX_U32 nFrameWidth = exynosInputPort->portDefinition.format.video.nFrameWidth;
283 OMX_U32 nFrameHeight = exynosInputPort->portDefinition.format.video.nFrameHeight;
284 OMX_COLOR_FORMATTYPE eColorFormat = exynosInputPort->portDefinition.format.video.eColorFormat;
285 OMX_BYTE checkInputStream = NULL;
286 OMX_BOOL flagEOS = OMX_FALSE;
287
288 FunctionIn();
289
290 checkInputStream = inputUseBuffer->bufferHeader->pBuffer;
291
292 CODEC_ENC_BUFFER *codecInputBuffer = (CODEC_ENC_BUFFER *)srcInputData->pPrivate;
293 codecInputBuffer->dataSize = ((nFrameWidth * nFrameHeight) * 3) / 2;
294
295 unsigned int csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar);
296 unsigned int csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar);
297
298 CSC_ERRORCODE cscRet = CSC_ErrorNone;
299 CSC_METHOD csc_method = CSC_METHOD_SW;
300 CSC_MEMTYPE csc_memType = CSC_MEMORY_USERPTR;
301
302 unsigned int srcCacheable = 1, dstCacheable = 1;
303
304 unsigned char *pSrcBuf[3] = {NULL, };
305 unsigned char *pDstBuf[3] = {NULL, };
306
307 pSrcBuf[0] = checkInputStream;
308 pSrcBuf[1] = checkInputStream + (nFrameWidth * nFrameHeight);
309 pSrcBuf[2] = checkInputStream + (((nFrameWidth * nFrameHeight) * 5) / 4);
310
311 pDstBuf[0] = srcInputData->buffer.multiPlaneBuffer.dataBuffer[0];
312 pDstBuf[1] = srcInputData->buffer.multiPlaneBuffer.dataBuffer[1];
313 pDstBuf[2] = srcInputData->buffer.multiPlaneBuffer.dataBuffer[2];
314
315 csc_get_method(pVideoEnc->csc_handle, &csc_method);
316 if (csc_method == CSC_METHOD_HW)
317 dstCacheable = 0;
318
319 #ifdef USE_METADATABUFFERTYPE
320 OMX_PTR ppBuf[MAX_BUFFER_PLANE];
321
322 /* kMetadataBufferTypeGrallocSource */
323 if (exynosInputPort->bStoreMetaData == OMX_TRUE) {
324 /* ARGB8888 converted to YUV420SemiPlanar */
325 csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_Format32bitARGB8888);
326 csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar);
327
328 Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf);
329 if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) {
330 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
331 OMX_U32 stride;
332 int imageSize;
333
334 ret = Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatAndroidOpaque, planes);
335 if (ret != OMX_ErrorNone) {
336 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OSAL_LockANBHandle() failed", __FUNCTION__);
337 ret = OMX_FALSE;
338 goto EXIT;
339 }
340
341 imageSize = nFrameWidth * nFrameHeight * 3; /* RGB888 */
342
343 #ifdef USE_GSC_RGB_ENCODER
344 if (pVideoEnc->csc_set_format == OMX_FALSE) {
345 cscRet = csc_set_method(pVideoEnc->csc_handle, CSC_METHOD_HW);
346 if (cscRet != CSC_ErrorNone) {
347 ret = OMX_FALSE;
348 goto EXIT;
349 }
350 }
351 #endif
352
353 #ifdef USE_DMA_BUF
354 if (csc_method == CSC_METHOD_HW) {
355 csc_memType = CSC_MEMORY_DMABUF;
356 pSrcBuf[0] = (unsigned char *)planes[0].fd;
357 } else
358 #endif
359 pSrcBuf[0] = planes[0].addr;
360 pSrcBuf[1] = NULL;
361 pSrcBuf[2] = NULL;
362 }
363 } else
364 #endif
365 {
366 #ifdef USE_DMA_BUF
367 if (csc_method == CSC_METHOD_HW) {
368 csc_memType = CSC_MEMORY_DMABUF;
369 pSrcBuf[0] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, checkInputStream);
370 pSrcBuf[1] = NULL;
371 pSrcBuf[2] = NULL;
372 }
373 #endif
374
375 switch (eColorFormat) {
376 case OMX_COLOR_FormatYUV420Planar:
377 /* YUV420Planar converted to YUV420Semiplanar (interleaved UV plane) as per MFC spec.*/
378 csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420Planar);
379 csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar);
380 break;
381 case OMX_COLOR_FormatYUV420SemiPlanar:
382 case OMX_SEC_COLOR_FormatNV12Tiled:
383 case OMX_SEC_COLOR_FormatNV21Linear:
384 /* Just copied to MFC input buffer */
385 csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar);
386 csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar);
387 break;
388 default:
389 break;
390 }
391 }
392
393 #ifdef USE_DMA_BUF
394 if (csc_method == CSC_METHOD_HW) {
395 pDstBuf[0] = srcInputData->buffer.multiPlaneBuffer.fd[0];
396 pDstBuf[1] = srcInputData->buffer.multiPlaneBuffer.fd[1];
397 pDstBuf[2] = srcInputData->buffer.multiPlaneBuffer.fd[2];
398 }
399 #endif
400
401 csc_set_src_format(
402 pVideoEnc->csc_handle, /* handle */
403 nFrameWidth, /* width */
404 nFrameHeight, /* height */
405 0, /* crop_left */
406 0, /* crop_right */
407 nFrameWidth, /* crop_width */
408 nFrameHeight, /* crop_height */
409 csc_src_color_format, /* color_format */
410 srcCacheable); /* cacheable */
411 csc_set_dst_format(
412 pVideoEnc->csc_handle, /* handle */
413 nFrameWidth, /* width */
414 nFrameHeight, /* height */
415 0, /* crop_left */
416 0, /* crop_right */
417 nFrameWidth, /* crop_width */
418 nFrameHeight, /* crop_height */
419 csc_dst_color_format, /* color_format */
420 dstCacheable); /* cacheable */
421 csc_set_src_buffer(
422 pVideoEnc->csc_handle, /* handle */
423 pSrcBuf,
424 csc_memType); /* YUV Addr or FD */
425 csc_set_dst_buffer(
426 pVideoEnc->csc_handle, /* handle */
427 pDstBuf,
428 csc_memType); /* YUV Addr or FD */
429 cscRet = csc_convert(pVideoEnc->csc_handle);
430 if (cscRet != CSC_ErrorNone)
431 ret = OMX_FALSE;
432 else
433 ret = OMX_TRUE;
434
435 #ifdef USE_METADATABUFFERTYPE
436 if (exynosInputPort->bStoreMetaData == OMX_TRUE) {
437 Exynos_OSAL_UnlockANBHandle((OMX_U32)ppBuf[0]);
438 }
439 #endif
440
441 ret = OMX_TRUE;
442
443 EXIT:
444 FunctionOut();
445
446 return ret;
447 }
448
449 OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *srcInputData)
450 {
451 OMX_BOOL ret = OMX_FALSE;
452 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
453 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
454 EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
455 EXYNOS_OMX_DATABUFFER *inputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer;
456 OMX_U32 nFrameWidth = exynosInputPort->portDefinition.format.video.nFrameWidth;
457 OMX_U32 nFrameHeight = exynosInputPort->portDefinition.format.video.nFrameHeight;
458 OMX_COLOR_FORMATTYPE eColorFormat = exynosInputPort->portDefinition.format.video.eColorFormat;
459 OMX_U32 copySize = 0;
460 OMX_BYTE checkInputStream = NULL;
461 OMX_U32 checkInputStreamLen = 0;
462 OMX_BOOL flagEOS = OMX_FALSE;
463
464 FunctionIn();
465
466 if (exynosInputPort->bufferProcessType & BUFFER_COPY) {
467 if ((srcInputData->buffer.multiPlaneBuffer.dataBuffer[0] == NULL) ||
468 (srcInputData->pPrivate == NULL)) {
469 ret = OMX_FALSE;
470 goto EXIT;
471 }
472 }
473
474 if (inputUseBuffer->dataValid == OMX_TRUE) {
475 if (exynosInputPort->bufferProcessType & BUFFER_SHARE) {
476 Exynos_Shared_BufferToData(inputUseBuffer, srcInputData, ONE_PLANE);
477 #ifdef USE_METADATABUFFERTYPE
478 if (exynosInputPort->bStoreMetaData == OMX_TRUE) {
479 OMX_PTR ppBuf[MAX_BUFFER_PLANE];
480 OMX_PTR allocSize[MAX_BUFFER_PLANE];
481 int plane = 0;
482
483 if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) {
484 Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf);
485 ExynosVideoPlane planes[MAX_BUFFER_PLANE];
486
487 Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatYUV420SemiPlanar, planes);
488
489 srcInputData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd;
490 srcInputData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd;
491 allocSize[0] = nFrameWidth * nFrameHeight;
492 allocSize[1] = nFrameWidth * nFrameHeight >> 1;
493
494 for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) {
495 srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] =
496 Exynos_OSAL_SharedMemory_IONToVirt(pVideoEnc->hSharedMemory, srcInputData->buffer.multiPlaneBuffer.fd[plane]);
497 if(srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] == NULL) {
498 srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] =
499 Exynos_OSAL_SharedMemory_Map(pVideoEnc->hSharedMemory, allocSize[plane], srcInputData->buffer.multiPlaneBuffer.fd[plane]);
500 }
501 }
502 /* input buffers are 2 plane. */
503 srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL;
504 srcInputData->buffer.multiPlaneBuffer.fd[2] = -1;
505 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s:%d YAddr: 0x%x CbCrAddr: 0x%x", __FUNCTION__, __LINE__, (unsigned int)ppBuf[0], (unsigned int)ppBuf[0]);
506 } else {
507 /* kMetadataBufferTypeCameraSource */
508 Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf);
509 #ifdef USE_DMA_BUF
510 srcInputData->buffer.multiPlaneBuffer.fd[0] = ppBuf[0];
511 srcInputData->buffer.multiPlaneBuffer.fd[1] = ppBuf[1];
512 allocSize[0] = nFrameWidth * nFrameHeight;
513 allocSize[1] = nFrameWidth * nFrameHeight >> 1;
514
515 for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) {
516 srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] =
517 Exynos_OSAL_SharedMemory_IONToVirt(pVideoEnc->hSharedMemory, srcInputData->buffer.multiPlaneBuffer.fd[plane]);
518 if(srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] == NULL) {
519 srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] =
520 Exynos_OSAL_SharedMemory_Map(pVideoEnc->hSharedMemory, allocSize[plane], srcInputData->buffer.multiPlaneBuffer.fd[plane]);
521 }
522 }
523 /* input buffers are 2 plane. */
524 srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL;
525 srcInputData->buffer.multiPlaneBuffer.fd[2] = -1;
526 #else
527 for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) {
528 srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = ppBuf[plane];
529 }
530 srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL;
531 #endif
532 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s:%d YAddr: 0x%x CbCrAddr: 0x%x", __FUNCTION__, __LINE__, (unsigned int)ppBuf[0], (unsigned int)ppBuf[1]);
533 }
534 }
535 #endif
536 /* reset dataBuffer */
537 Exynos_ResetDataBuffer(inputUseBuffer);
538 } else if (exynosInputPort->bufferProcessType & BUFFER_COPY) {
539 checkInputStream = inputUseBuffer->bufferHeader->pBuffer + inputUseBuffer->usedDataLen;
540 checkInputStreamLen = inputUseBuffer->remainDataLen;
541
542 pExynosComponent->bUseFlagEOF = OMX_TRUE;
543
544 if (checkInputStreamLen == 0) {
545 inputUseBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
546 flagEOS = OMX_TRUE;
547 }
548
549 copySize = checkInputStreamLen;
550 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "exynos_checkInputFrame : OMX_TRUE");
551
552 if (((srcInputData->allocSize) - (srcInputData->dataLen)) >= copySize) {
553 ret = Exynos_CSC_InputData(pOMXComponent, srcInputData);
554 if (ret == OMX_FALSE)
555 goto EXIT;
556
557 inputUseBuffer->dataLen -= copySize;
558 inputUseBuffer->remainDataLen -= copySize;
559 inputUseBuffer->usedDataLen += copySize;
560
561 srcInputData->dataLen += copySize;
562 srcInputData->remainDataLen += copySize;
563
564 srcInputData->timeStamp = inputUseBuffer->timeStamp;
565 srcInputData->nFlags = inputUseBuffer->nFlags;
566 srcInputData->bufferHeader = inputUseBuffer->bufferHeader;
567 } else {
568 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "input codec buffer is smaller than decoded input data size Out Length");
569 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
570 pExynosComponent->callbackData,
571 OMX_EventError, OMX_ErrorUndefined, 0, NULL);
572 ret = OMX_FALSE;
573 }
574
575 if (((exynosInputPort->bStoreMetaData == OMX_TRUE) && (eColorFormat == OMX_COLOR_FormatAndroidOpaque)) ||
576 (exynosInputPort->bStoreMetaData == OMX_FALSE)) {
577 Exynos_InputBufferReturn(pOMXComponent, inputUseBuffer);
578 } else {
579 inputUseBuffer->dataValid = OMX_TRUE;
580 }
581 }
582
583 if ((srcInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) {
584 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "bSaveFlagEOS : OMX_TRUE");
585 srcInputData->dataLen = 0;
586 srcInputData->remainDataLen = 0;
587 pExynosComponent->bSaveFlagEOS = OMX_TRUE;
588 }
589
590 if (pExynosComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) {
591 pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_TRUE;
592 pExynosComponent->checkTimeStamp.startTimeStamp = srcInputData->timeStamp;
593 pExynosComponent->checkTimeStamp.nStartFlags = srcInputData->nFlags;
594 pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE;
595 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "first frame timestamp after seeking %lld us (%.2f secs)",
596 srcInputData->timeStamp, srcInputData->timeStamp / 1E6);
597 }
598
599 ret = OMX_TRUE;
600 }
601
602 EXIT:
603
604 FunctionOut();
605
606 return ret;
607 }
608
609 OMX_BOOL Exynos_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *dstOutputData)
610 {
611 OMX_BOOL ret = OMX_FALSE;
612 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
613 EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
614 EXYNOS_OMX_DATABUFFER *outputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.outputDataBuffer;
615 OMX_U32 copySize = 0;
616
617 FunctionIn();
618
619 if (exynosOutputPort->bufferProcessType & BUFFER_SHARE) {
620 if (Exynos_Shared_DataToBuffer(dstOutputData, outputUseBuffer, OMX_FALSE) == OMX_ErrorNone)
621 outputUseBuffer->dataValid = OMX_TRUE;
622 }
623
624 if (outputUseBuffer->dataValid == OMX_TRUE) {
625 if (pExynosComponent->checkTimeStamp.needCheckStartTimeStamp == OMX_TRUE) {
626 if (pExynosComponent->checkTimeStamp.startTimeStamp == dstOutputData->timeStamp){
627 pExynosComponent->checkTimeStamp.startTimeStamp = -19761123;
628 pExynosComponent->checkTimeStamp.nStartFlags = 0x0;
629 pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE;
630 pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
631 } else {
632 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "garbage frame drop after flush");
633 ret = OMX_TRUE;
634 goto EXIT;
635 }
636 } else if (pExynosComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) {
637 ret = OMX_TRUE;
638 Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "input buffer has not come after flush.");
639 goto EXIT;
640 }
641
642 if (exynosOutputPort->bufferProcessType & BUFFER_COPY) {
643 if (dstOutputData->remainDataLen <= (outputUseBuffer->allocSize - outputUseBuffer->dataLen)) {
644 copySize = dstOutputData->remainDataLen;
645 if (copySize > 0)
646 Exynos_OSAL_Memcpy((outputUseBuffer->bufferHeader->pBuffer + outputUseBuffer->dataLen),
647 (dstOutputData->buffer.singlePlaneBuffer.dataBuffer + dstOutputData->usedDataLen),
648 copySize);
649 outputUseBuffer->dataLen += copySize;
650 outputUseBuffer->remainDataLen += copySize;
651 outputUseBuffer->nFlags = dstOutputData->nFlags;
652 outputUseBuffer->timeStamp = dstOutputData->timeStamp;
653
654 ret = OMX_TRUE;
655
656 if ((outputUseBuffer->remainDataLen > 0) ||
657 (outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS)) {
658 Exynos_OutputBufferReturn(pOMXComponent, outputUseBuffer);
659 }
660 } else {
661 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "output buffer is smaller than encoded data size Out Length");
662 pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
663 pExynosComponent->callbackData,
664 OMX_EventError, OMX_ErrorUndefined, 0, NULL);
665 ret = OMX_FALSE;
666 }
667 } else if (exynosOutputPort->bufferProcessType & BUFFER_SHARE) {
668 if ((outputUseBuffer->remainDataLen > 0) ||
669 ((outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) ||
670 (CHECK_PORT_BEING_FLUSHED(exynosOutputPort)))
671 Exynos_OutputBufferReturn(pOMXComponent, outputUseBuffer);
672 }
673 } else {
674 ret = OMX_FALSE;
675 }
676
677 EXIT:
678 FunctionOut();
679
680 return ret;
681 }
682
683 #ifdef USE_METADATABUFFERTYPE
684 OMX_ERRORTYPE Exynos_OMX_ExtensionSetup(OMX_HANDLETYPE hComponent)
685 {
686 OMX_ERRORTYPE ret = OMX_ErrorNone;
687 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
688 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
689 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
690 EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
691 EXYNOS_OMX_DATABUFFER *srcInputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer;
692 EXYNOS_OMX_DATA *pSrcInputData = &exynosInputPort->processData;
693 OMX_COLOR_FORMATTYPE eColorFormat = exynosInputPort->portDefinition.format.video.eColorFormat;
694
695 int i = 0;
696 OMX_PTR ppBuf[MAX_BUFFER_PLANE];
697
698
699 /* kMetadataBufferTypeGrallocSource */
700 if (exynosInputPort->bStoreMetaData == OMX_TRUE) {
701 Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)srcInputUseBuffer->bufferHeader->pBuffer, ppBuf);
702 if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) {
703 pVideoEnc->ANBColorFormat = Exynos_OSAL_GetANBColorFormat(ppBuf[0]);
704 if ((pVideoEnc->ANBColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) ||
705 (pVideoEnc->ANBColorFormat == OMX_SEC_COLOR_FormatNV12Tiled)) {
706 exynosInputPort->bufferProcessType = BUFFER_SHARE;
707 } else {
708 exynosInputPort->bufferProcessType = BUFFER_COPY;
709 }
710
711 if ((exynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) {
712 OMX_U32 nPlaneSize[MFC_INPUT_BUFFER_PLANE] = {0, };
713 nPlaneSize[0] = DEFAULT_MFC_INPUT_YBUFFER_SIZE;
714 nPlaneSize[1] = DEFAULT_MFC_INPUT_CBUFFER_SIZE;
715
716 Exynos_OSAL_SemaphoreCreate(&exynosInputPort->codecSemID);
717 Exynos_OSAL_QueueCreate(&exynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS);
718
719 ret = Exynos_Allocate_CodecBuffers(pOMXComponent, INPUT_PORT_INDEX, MFC_INPUT_BUFFER_NUM_MAX, nPlaneSize);
720 if (ret != OMX_ErrorNone)
721 goto EXIT;
722
723 for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++)
724 Exynos_CodecBufferEnqueue(pExynosComponent, INPUT_PORT_INDEX, pVideoEnc->pMFCEncInputBuffer[i]);
725 } else if (exynosInputPort->bufferProcessType == BUFFER_SHARE) {
726 /*************/
727 /* TBD */
728 /*************/
729 /* Does not require any actions. */
730 }
731 }
732 }
733
734 EXIT:
735
736 return ret;
737 }
738 #endif
739
740 OMX_ERRORTYPE Exynos_OMX_SrcInputBufferProcess(OMX_HANDLETYPE hComponent)
741 {
742 OMX_ERRORTYPE ret = OMX_ErrorNone;
743 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
744 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
745 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
746 EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
747 EXYNOS_OMX_DATABUFFER *srcInputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer;
748 EXYNOS_OMX_DATA *pSrcInputData = &exynosInputPort->processData;
749 OMX_BOOL bCheckInputData = OMX_FALSE;
750 OMX_BOOL bValidCodecData = OMX_FALSE;
751
752 FunctionIn();
753
754 while (!pVideoEnc->bExitBufferProcessThread) {
755 Exynos_OSAL_SleepMillisec(0);
756 Exynos_Wait_ProcessPause(pExynosComponent, INPUT_PORT_INDEX);
757
758 while ((Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) &&
759 (!pVideoEnc->bExitBufferProcessThread)) {
760 Exynos_OSAL_SleepMillisec(0);
761
762 if (CHECK_PORT_BEING_FLUSHED(exynosInputPort))
763 break;
764 if (exynosInputPort->portState != OMX_StateIdle)
765 break;
766
767 Exynos_OSAL_MutexLock(srcInputUseBuffer->bufferMutex);
768 if (pVideoEnc->bFirstInput == OMX_FALSE) {
769 if (exynosInputPort->bufferProcessType & BUFFER_COPY) {
770 OMX_PTR codecBuffer;
771 if ((pSrcInputData->buffer.multiPlaneBuffer.dataBuffer[0] == NULL) || (pSrcInputData->pPrivate == NULL)) {
772 Exynos_CodecBufferDequeue(pExynosComponent, INPUT_PORT_INDEX, &codecBuffer);
773 if (codecBuffer != NULL) {
774 Exynos_Input_CodecBufferToData(pExynosComponent, codecBuffer, pSrcInputData);
775 }
776 Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex);
777 break;
778 }
779 }
780
781 if (srcInputUseBuffer->dataValid == OMX_TRUE) {
782 bCheckInputData = Exynos_Preprocessor_InputData(pOMXComponent, pSrcInputData);
783 } else {
784 bCheckInputData = OMX_FALSE;
785 }
786 }
787 if ((bCheckInputData == OMX_FALSE) &&
788 (!CHECK_PORT_BEING_FLUSHED(exynosInputPort))) {
789 ret = Exynos_InputBufferGetQueue(pExynosComponent);
790 #ifdef USE_METADATABUFFERTYPE
791 if ((pVideoEnc->bFirstInput == OMX_TRUE) &&
792 (!CHECK_PORT_BEING_FLUSHED(exynosInputPort))) {
793 Exynos_OMX_ExtensionSetup(hComponent);
794 pVideoEnc->bFirstInput = OMX_FALSE;
795 }
796 #endif
797 Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex);
798 break;
799 }
800
801 if (CHECK_PORT_BEING_FLUSHED(exynosInputPort)) {
802 Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex);
803 break;
804 }
805
806 ret = pVideoEnc->exynos_codec_srcInputProcess(pOMXComponent, pSrcInputData);
807 Exynos_ResetCodecData(pSrcInputData);
808 Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex);
809 if (ret == OMX_ErrorCodecInit)
810 pVideoEnc->bExitBufferProcessThread = OMX_TRUE;
811 }
812 }
813
814 EXIT:
815
816 FunctionOut();
817
818 return ret;
819 }
820
821 OMX_ERRORTYPE Exynos_OMX_SrcOutputBufferProcess(OMX_HANDLETYPE hComponent)
822 {
823 OMX_ERRORTYPE ret = OMX_ErrorNone;
824 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
825 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
826 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
827 EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
828 EXYNOS_OMX_DATABUFFER *srcOutputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.outputDataBuffer;
829 EXYNOS_OMX_DATA srcOutputData;
830
831 FunctionIn();
832
833 while (!pVideoEnc->bExitBufferProcessThread) {
834 Exynos_OSAL_SleepMillisec(0);
835
836 while (!pVideoEnc->bExitBufferProcessThread) {
837 if (exynosInputPort->bufferProcessType & BUFFER_COPY) {
838 if (Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX) == OMX_FALSE)
839 break;
840 }
841 Exynos_OSAL_SleepMillisec(0);
842
843 if (CHECK_PORT_BEING_FLUSHED(exynosInputPort))
844 break;
845
846 Exynos_OSAL_MutexLock(srcOutputUseBuffer->bufferMutex);
847 ret = pVideoEnc->exynos_codec_srcOutputProcess(pOMXComponent, &srcOutputData);
848
849 if (ret == OMX_ErrorNone) {
850 if (exynosInputPort->bufferProcessType & BUFFER_COPY) {
851 OMX_PTR codecBuffer;
852 codecBuffer = srcOutputData.pPrivate;
853 if (codecBuffer != NULL)
854 Exynos_CodecBufferEnqueue(pExynosComponent, INPUT_PORT_INDEX, codecBuffer);
855 }
856 if (exynosInputPort->bufferProcessType & BUFFER_SHARE) {
857 OMX_BOOL bNeedUnlock = OMX_FALSE;
858 OMX_COLOR_FORMATTYPE eColorFormat = exynosInputPort->portDefinition.format.video.eColorFormat;
859 if (eColorFormat == OMX_COLOR_FormatAndroidOpaque)
860 bNeedUnlock = OMX_TRUE;
861 Exynos_Shared_DataToBuffer(&srcOutputData, srcOutputUseBuffer, bNeedUnlock);
862 Exynos_InputBufferReturn(pOMXComponent, srcOutputUseBuffer);
863 }
864 Exynos_ResetCodecData(&srcOutputData);
865 }
866 Exynos_OSAL_MutexUnlock(srcOutputUseBuffer->bufferMutex);
867 }
868 }
869
870 EXIT:
871
872 FunctionOut();
873
874 return ret;
875 }
876
877 OMX_ERRORTYPE Exynos_OMX_DstInputBufferProcess(OMX_HANDLETYPE hComponent)
878 {
879 OMX_ERRORTYPE ret = OMX_ErrorNone;
880 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
881 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
882 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
883 EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
884 EXYNOS_OMX_DATABUFFER *dstInputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.inputDataBuffer;
885 EXYNOS_OMX_DATA dstInputData;
886
887 FunctionIn();
888
889 while (!pVideoEnc->bExitBufferProcessThread) {
890 Exynos_OSAL_SleepMillisec(0);
891
892 while ((Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) &&
893 (!pVideoEnc->bExitBufferProcessThread)) {
894 Exynos_OSAL_SleepMillisec(0);
895
896 if ((CHECK_PORT_BEING_FLUSHED(exynosOutputPort)) ||
897 (!CHECK_PORT_POPULATED(exynosOutputPort)))
898 break;
899 if (exynosOutputPort->portState != OMX_StateIdle)
900 break;
901
902 Exynos_OSAL_MutexLock(dstInputUseBuffer->bufferMutex);
903 if (exynosOutputPort->bufferProcessType & BUFFER_COPY) {
904 CODEC_ENC_BUFFER *pCodecBuffer = NULL;
905 ret = Exynos_CodecBufferDequeue(pExynosComponent, OUTPUT_PORT_INDEX, (OMX_PTR *)&pCodecBuffer);
906 if (ret != OMX_ErrorNone) {
907 Exynos_OSAL_MutexUnlock(dstInputUseBuffer->bufferMutex);
908 break;
909 }
910 Exynos_Output_CodecBufferToData(pCodecBuffer, &dstInputData);
911 }
912
913 if (exynosOutputPort->bufferProcessType & BUFFER_SHARE) {
914 if ((dstInputUseBuffer->dataValid != OMX_TRUE) &&
915 (!CHECK_PORT_BEING_FLUSHED(exynosOutputPort))) {
916 ret = Exynos_OutputBufferGetQueue(pExynosComponent);
917 if (ret != OMX_ErrorNone) {
918 Exynos_OSAL_MutexUnlock(dstInputUseBuffer->bufferMutex);
919 break;
920 }
921 Exynos_Shared_BufferToData(dstInputUseBuffer, &dstInputData, ONE_PLANE);
922 if (pVideoEnc->bDRMPlayerMode == OMX_TRUE) {
923 OMX_PTR dataBuffer = NULL;
924 dataBuffer = Exynos_OSAL_SharedMemory_IONToVirt(pVideoEnc->hSharedMemory,
925 dstInputData.buffer.singlePlaneBuffer.dataBuffer);
926 if (dataBuffer == NULL) {
927 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Wrong dst-input Secure buffer", __LINE__);
928 ret = OMX_ErrorUndefined;
929 break;
930 }
931
932 dstInputData.buffer.singlePlaneBuffer.dataBuffer = dataBuffer;
933 }
934 Exynos_ResetDataBuffer(dstInputUseBuffer);
935 }
936 }
937
938 if (CHECK_PORT_BEING_FLUSHED(exynosOutputPort)) {
939 Exynos_OSAL_MutexUnlock(dstInputUseBuffer->bufferMutex);
940 break;
941 }
942 ret = pVideoEnc->exynos_codec_dstInputProcess(pOMXComponent, &dstInputData);
943
944 Exynos_ResetCodecData(&dstInputData);
945 Exynos_OSAL_MutexUnlock(dstInputUseBuffer->bufferMutex);
946 }
947 }
948
949 EXIT:
950
951 FunctionOut();
952
953 return ret;
954 }
955
956 OMX_ERRORTYPE Exynos_OMX_DstOutputBufferProcess(OMX_HANDLETYPE hComponent)
957 {
958 OMX_ERRORTYPE ret = OMX_ErrorNone;
959 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
960 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
961 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
962 EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
963 EXYNOS_OMX_DATABUFFER *dstOutputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.outputDataBuffer;
964 EXYNOS_OMX_DATA *pDstOutputData = &exynosOutputPort->processData;
965
966 FunctionIn();
967
968 while (!pVideoEnc->bExitBufferProcessThread) {
969 Exynos_OSAL_SleepMillisec(0);
970 Exynos_Wait_ProcessPause(pExynosComponent, OUTPUT_PORT_INDEX);
971
972 while ((Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) &&
973 (!pVideoEnc->bExitBufferProcessThread)) {
974 Exynos_OSAL_SleepMillisec(0);
975
976 if (CHECK_PORT_BEING_FLUSHED(exynosOutputPort))
977 break;
978
979 Exynos_OSAL_MutexLock(dstOutputUseBuffer->bufferMutex);
980 if (exynosOutputPort->bufferProcessType & BUFFER_COPY) {
981 if ((dstOutputUseBuffer->dataValid != OMX_TRUE) &&
982 (!CHECK_PORT_BEING_FLUSHED(exynosOutputPort))) {
983 ret = Exynos_OutputBufferGetQueue(pExynosComponent);
984 if (ret != OMX_ErrorNone) {
985 Exynos_OSAL_MutexUnlock(dstOutputUseBuffer->bufferMutex);
986 break;
987 }
988 }
989 }
990
991 if ((dstOutputUseBuffer->dataValid == OMX_TRUE) ||
992 (exynosOutputPort->bufferProcessType & BUFFER_SHARE))
993 ret = pVideoEnc->exynos_codec_dstOutputProcess(pOMXComponent, pDstOutputData);
994
995 if (((ret == OMX_ErrorNone) && (dstOutputUseBuffer->dataValid == OMX_TRUE)) ||
996 (exynosOutputPort->bufferProcessType & BUFFER_SHARE)) {
997 Exynos_Postprocess_OutputData(pOMXComponent, pDstOutputData);
998 }
999
1000 if (exynosOutputPort->bufferProcessType & BUFFER_COPY) {
1001 if (pDstOutputData->pPrivate != NULL) {
1002 Exynos_CodecBufferEnqueue(pExynosComponent, OUTPUT_PORT_INDEX, pDstOutputData->pPrivate);
1003 pDstOutputData->pPrivate = NULL;
1004 }
1005 }
1006
1007 /* reset outputData */
1008 Exynos_ResetCodecData(pDstOutputData);
1009 Exynos_OSAL_MutexUnlock(dstOutputUseBuffer->bufferMutex);
1010 }
1011 }
1012
1013 EXIT:
1014
1015 FunctionOut();
1016
1017 return ret;
1018 }
1019
1020 static OMX_ERRORTYPE Exynos_OMX_SrcInputProcessThread(OMX_PTR threadData)
1021 {
1022 OMX_ERRORTYPE ret = OMX_ErrorNone;
1023 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1024 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1025 EXYNOS_OMX_MESSAGE *message = NULL;
1026
1027 FunctionIn();
1028
1029 if (threadData == NULL) {
1030 ret = OMX_ErrorBadParameter;
1031 goto EXIT;
1032 }
1033 pOMXComponent = (OMX_COMPONENTTYPE *)threadData;
1034 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1035 if (ret != OMX_ErrorNone) {
1036 goto EXIT;
1037 }
1038 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1039 Exynos_OMX_SrcInputBufferProcess(pOMXComponent);
1040
1041 Exynos_OSAL_ThreadExit(NULL);
1042
1043 EXIT:
1044 FunctionOut();
1045
1046 return ret;
1047 }
1048
1049 static OMX_ERRORTYPE Exynos_OMX_SrcOutputProcessThread(OMX_PTR threadData)
1050 {
1051 OMX_ERRORTYPE ret = OMX_ErrorNone;
1052 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1053 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1054 EXYNOS_OMX_MESSAGE *message = NULL;
1055
1056 FunctionIn();
1057
1058 if (threadData == NULL) {
1059 ret = OMX_ErrorBadParameter;
1060 goto EXIT;
1061 }
1062 pOMXComponent = (OMX_COMPONENTTYPE *)threadData;
1063 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1064 if (ret != OMX_ErrorNone) {
1065 goto EXIT;
1066 }
1067 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1068 Exynos_OMX_SrcOutputBufferProcess(pOMXComponent);
1069
1070 Exynos_OSAL_ThreadExit(NULL);
1071
1072 EXIT:
1073 FunctionOut();
1074
1075 return ret;
1076 }
1077
1078 static OMX_ERRORTYPE Exynos_OMX_DstInputProcessThread(OMX_PTR threadData)
1079 {
1080 OMX_ERRORTYPE ret = OMX_ErrorNone;
1081 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1082 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1083 EXYNOS_OMX_MESSAGE *message = NULL;
1084
1085 FunctionIn();
1086
1087 if (threadData == NULL) {
1088 ret = OMX_ErrorBadParameter;
1089 goto EXIT;
1090 }
1091 pOMXComponent = (OMX_COMPONENTTYPE *)threadData;
1092 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1093 if (ret != OMX_ErrorNone) {
1094 goto EXIT;
1095 }
1096 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1097 Exynos_OMX_DstInputBufferProcess(pOMXComponent);
1098
1099 Exynos_OSAL_ThreadExit(NULL);
1100
1101 EXIT:
1102 FunctionOut();
1103
1104 return ret;
1105 }
1106
1107 static OMX_ERRORTYPE Exynos_OMX_DstOutputProcessThread(OMX_PTR threadData)
1108 {
1109 OMX_ERRORTYPE ret = OMX_ErrorNone;
1110 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1111 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1112 EXYNOS_OMX_MESSAGE *message = NULL;
1113
1114 FunctionIn();
1115
1116 if (threadData == NULL) {
1117 ret = OMX_ErrorBadParameter;
1118 goto EXIT;
1119 }
1120 pOMXComponent = (OMX_COMPONENTTYPE *)threadData;
1121 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1122 if (ret != OMX_ErrorNone) {
1123 goto EXIT;
1124 }
1125 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1126 Exynos_OMX_DstOutputBufferProcess(pOMXComponent);
1127
1128 Exynos_OSAL_ThreadExit(NULL);
1129
1130 EXIT:
1131 FunctionOut();
1132
1133 return ret;
1134 }
1135
1136 OMX_ERRORTYPE Exynos_OMX_BufferProcess_Create(OMX_HANDLETYPE hComponent)
1137 {
1138 OMX_ERRORTYPE ret = OMX_ErrorNone;
1139 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1140 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1141 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
1142
1143 FunctionIn();
1144
1145 pVideoEnc->bExitBufferProcessThread = OMX_FALSE;
1146
1147 ret = Exynos_OSAL_ThreadCreate(&pVideoEnc->hDstOutputThread,
1148 Exynos_OMX_DstOutputProcessThread,
1149 pOMXComponent);
1150 if (ret == OMX_ErrorNone)
1151 ret = Exynos_OSAL_ThreadCreate(&pVideoEnc->hSrcOutputThread,
1152 Exynos_OMX_SrcOutputProcessThread,
1153 pOMXComponent);
1154 if (ret == OMX_ErrorNone)
1155 ret = Exynos_OSAL_ThreadCreate(&pVideoEnc->hDstInputThread,
1156 Exynos_OMX_DstInputProcessThread,
1157 pOMXComponent);
1158 if (ret == OMX_ErrorNone)
1159 ret = Exynos_OSAL_ThreadCreate(&pVideoEnc->hSrcInputThread,
1160 Exynos_OMX_SrcInputProcessThread,
1161 pOMXComponent);
1162
1163 EXIT:
1164 FunctionOut();
1165
1166 return ret;
1167 }
1168
1169 OMX_ERRORTYPE Exynos_OMX_BufferProcess_Terminate(OMX_HANDLETYPE hComponent)
1170 {
1171 OMX_ERRORTYPE ret = OMX_ErrorNone;
1172 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1173 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1174 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
1175 OMX_S32 countValue = 0;
1176 unsigned int i = 0;
1177
1178 FunctionIn();
1179
1180 pVideoEnc->bExitBufferProcessThread = OMX_TRUE;
1181
1182 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[INPUT_PORT_INDEX].bufferSemID, &countValue);
1183 if (countValue == 0)
1184 Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[INPUT_PORT_INDEX].bufferSemID);
1185 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[INPUT_PORT_INDEX].codecSemID, &countValue);
1186 if (countValue == 0)
1187 Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[INPUT_PORT_INDEX].codecSemID);
1188 Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[INPUT_PORT_INDEX].pauseEvent);
1189 Exynos_OSAL_ThreadTerminate(pVideoEnc->hSrcInputThread);
1190 pVideoEnc->hSrcInputThread = NULL;
1191
1192 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].bufferSemID, &countValue);
1193 if (countValue == 0)
1194 Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].bufferSemID);
1195 Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].codecSemID, &countValue);
1196 if (countValue == 0)
1197 Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].codecSemID);
1198 Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].pauseEvent);
1199 Exynos_OSAL_ThreadTerminate(pVideoEnc->hDstInputThread);
1200 pVideoEnc->hDstInputThread = NULL;
1201
1202 pVideoEnc->exynos_codec_stop(pOMXComponent, INPUT_PORT_INDEX);
1203 pVideoEnc->exynos_codec_bufferProcessRun(pOMXComponent, INPUT_PORT_INDEX);
1204 Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[INPUT_PORT_INDEX].pauseEvent);
1205 Exynos_OSAL_ThreadTerminate(pVideoEnc->hSrcOutputThread);
1206 pVideoEnc->hSrcOutputThread = NULL;
1207
1208 pVideoEnc->exynos_codec_stop(pOMXComponent, OUTPUT_PORT_INDEX);
1209 pVideoEnc->exynos_codec_bufferProcessRun(pOMXComponent, INPUT_PORT_INDEX);
1210 Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX].pauseEvent);
1211 Exynos_OSAL_ThreadTerminate(pVideoEnc->hDstOutputThread);
1212 pVideoEnc->hDstOutputThread = NULL;
1213
1214 EXIT:
1215 FunctionOut();
1216
1217 return ret;
1218 }
1219
1220 OMX_ERRORTYPE Exynos_OMX_VideoEncodeComponentInit(OMX_IN OMX_HANDLETYPE hComponent)
1221 {
1222 OMX_ERRORTYPE ret = OMX_ErrorNone;
1223 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1224 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1225 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1226 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL;
1227
1228 FunctionIn();
1229
1230 if (hComponent == NULL) {
1231 ret = OMX_ErrorBadParameter;
1232 goto EXIT;
1233 }
1234 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1235 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1236 if (ret != OMX_ErrorNone) {
1237 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
1238 goto EXIT;
1239 }
1240
1241 ret = Exynos_OMX_BaseComponent_Constructor(pOMXComponent);
1242 if (ret != OMX_ErrorNone) {
1243 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
1244 goto EXIT;
1245 }
1246
1247 ret = Exynos_OMX_Port_Constructor(pOMXComponent);
1248 if (ret != OMX_ErrorNone) {
1249 Exynos_OMX_BaseComponent_Destructor(pOMXComponent);
1250 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_Error, Line:%d", __LINE__);
1251 goto EXIT;
1252 }
1253
1254 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1255
1256 pVideoEnc = Exynos_OSAL_Malloc(sizeof(EXYNOS_OMX_VIDEOENC_COMPONENT));
1257 if (pVideoEnc == NULL) {
1258 Exynos_OMX_BaseComponent_Destructor(pOMXComponent);
1259 ret = OMX_ErrorInsufficientResources;
1260 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
1261 goto EXIT;
1262 }
1263
1264 Exynos_OSAL_Memset(pVideoEnc, 0, sizeof(EXYNOS_OMX_VIDEOENC_COMPONENT));
1265 pExynosComponent->hComponentHandle = (OMX_HANDLETYPE)pVideoEnc;
1266
1267 pExynosComponent->bSaveFlagEOS = OMX_FALSE;
1268
1269 pVideoEnc->bFirstInput = OMX_FALSE;
1270 pVideoEnc->bFirstOutput = OMX_FALSE;
1271 pVideoEnc->configChange = OMX_FALSE;
1272 pVideoEnc->quantization.nQpI = 4; // I frame quantization parameter
1273 pVideoEnc->quantization.nQpP = 5; // P frame quantization parameter
1274 pVideoEnc->quantization.nQpB = 5; // B frame quantization parameter
1275
1276 pExynosComponent->bMultiThreadProcess = OMX_TRUE;
1277
1278 /* Input port */
1279 pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
1280 pExynosPort->portDefinition.nBufferCountActual = MAX_VIDEO_INPUTBUFFER_NUM;
1281 pExynosPort->portDefinition.nBufferCountMin = MAX_VIDEO_INPUTBUFFER_NUM;
1282 pExynosPort->portDefinition.nBufferSize = 0;
1283 pExynosPort->portDefinition.eDomain = OMX_PortDomainVideo;
1284
1285 pExynosPort->portDefinition.format.video.cMIMEType = Exynos_OSAL_Malloc(MAX_OMX_MIMETYPE_SIZE);
1286 Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "raw/video");
1287 pExynosPort->portDefinition.format.video.pNativeRender = 0;
1288 pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
1289 pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
1290
1291 pExynosPort->portDefinition.format.video.nFrameWidth = 0;
1292 pExynosPort->portDefinition.format.video.nFrameHeight= 0;
1293 pExynosPort->portDefinition.format.video.nStride = 0;
1294 pExynosPort->portDefinition.format.video.nSliceHeight = 0;
1295 pExynosPort->portDefinition.format.video.nBitrate = 64000;
1296 pExynosPort->portDefinition.format.video.xFramerate = (15 << 16);
1297 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused;
1298 pExynosPort->portDefinition.format.video.pNativeWindow = NULL;
1299 pVideoEnc->eControlRate[INPUT_PORT_INDEX] = OMX_Video_ControlRateDisable;
1300
1301 pExynosPort->bStoreMetaData = OMX_FALSE;
1302
1303 /* Output port */
1304 pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
1305 pExynosPort->portDefinition.nBufferCountActual = MAX_VIDEO_OUTPUTBUFFER_NUM;
1306 pExynosPort->portDefinition.nBufferCountMin = MAX_VIDEO_OUTPUTBUFFER_NUM;
1307 pExynosPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE;
1308 pExynosPort->portDefinition.eDomain = OMX_PortDomainVideo;
1309
1310 pExynosPort->portDefinition.format.video.cMIMEType = Exynos_OSAL_Malloc(MAX_OMX_MIMETYPE_SIZE);
1311 Exynos_OSAL_Strcpy(pExynosPort->portDefinition.format.video.cMIMEType, "raw/video");
1312 pExynosPort->portDefinition.format.video.pNativeRender = 0;
1313 pExynosPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE;
1314 pExynosPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
1315
1316 pExynosPort->portDefinition.format.video.nFrameWidth = 0;
1317 pExynosPort->portDefinition.format.video.nFrameHeight= 0;
1318 pExynosPort->portDefinition.format.video.nStride = 0;
1319 pExynosPort->portDefinition.format.video.nSliceHeight = 0;
1320 pExynosPort->portDefinition.format.video.nBitrate = 64000;
1321 pExynosPort->portDefinition.format.video.xFramerate = (15 << 16);
1322 pExynosPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused;
1323 pExynosPort->portDefinition.format.video.pNativeWindow = NULL;
1324 pVideoEnc->eControlRate[OUTPUT_PORT_INDEX] = OMX_Video_ControlRateDisable;
1325
1326 pOMXComponent->UseBuffer = &Exynos_OMX_UseBuffer;
1327 pOMXComponent->AllocateBuffer = &Exynos_OMX_AllocateBuffer;
1328 pOMXComponent->FreeBuffer = &Exynos_OMX_FreeBuffer;
1329 pOMXComponent->ComponentTunnelRequest = &Exynos_OMX_ComponentTunnelRequest;
1330
1331 pExynosComponent->exynos_AllocateTunnelBuffer = &Exynos_OMX_AllocateTunnelBuffer;
1332 pExynosComponent->exynos_FreeTunnelBuffer = &Exynos_OMX_FreeTunnelBuffer;
1333 pExynosComponent->exynos_BufferProcessCreate = &Exynos_OMX_BufferProcess_Create;
1334 pExynosComponent->exynos_BufferProcessTerminate = &Exynos_OMX_BufferProcess_Terminate;
1335 pExynosComponent->exynos_BufferFlush = &Exynos_OMX_BufferFlush;
1336
1337 EXIT:
1338 FunctionOut();
1339
1340 return ret;
1341 }
1342
1343 OMX_ERRORTYPE Exynos_OMX_VideoEncodeComponentDeinit(OMX_IN OMX_HANDLETYPE hComponent)
1344 {
1345 OMX_ERRORTYPE ret = OMX_ErrorNone;
1346 OMX_COMPONENTTYPE *pOMXComponent = NULL;
1347 EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL;
1348 EXYNOS_OMX_BASEPORT *pExynosPort = NULL;
1349 EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL;
1350 int i = 0;
1351
1352 FunctionIn();
1353
1354 if (hComponent == NULL) {
1355 ret = OMX_ErrorBadParameter;
1356 goto EXIT;
1357 }
1358 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
1359 ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
1360 if (ret != OMX_ErrorNone) {
1361 goto EXIT;
1362 }
1363
1364 if (pOMXComponent->pComponentPrivate == NULL) {
1365 ret = OMX_ErrorBadParameter;
1366 goto EXIT;
1367 }
1368 pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
1369
1370 pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle;
1371
1372 Exynos_OSAL_Free(pVideoEnc);
1373 pExynosComponent->hComponentHandle = pVideoEnc = NULL;
1374
1375 for(i = 0; i < ALL_PORT_NUM; i++) {
1376 pExynosPort = &pExynosComponent->pExynosPort[i];
1377 Exynos_OSAL_Free(pExynosPort->portDefinition.format.video.cMIMEType);
1378 pExynosPort->portDefinition.format.video.cMIMEType = NULL;
1379 }
1380
1381 ret = Exynos_OMX_Port_Destructor(pOMXComponent);
1382
1383 ret = Exynos_OMX_BaseComponent_Destructor(hComponent);
1384
1385 EXIT:
1386 FunctionOut();
1387
1388 return ret;
1389 }