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