Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
6dfe5a02 TK |
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 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 | ||
120 | OMX_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; | |
129 | MEMORY_TYPE eMemoryType = NORMAL_MEMORY; | |
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; | |
143 | } | |
144 | ||
145 | for (i = 0; i < nBufferCnt; i++) { | |
146 | ppCodecBuffer[i] = (CODEC_ENC_BUFFER *)Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER)); | |
147 | if (ppCodecBuffer[i] == NULL) { | |
148 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc codec buffer"); | |
149 | ret = OMX_ErrorInsufficientResources; | |
150 | goto EXIT; | |
151 | } | |
152 | Exynos_OSAL_Memset(ppCodecBuffer[i], 0, sizeof(CODEC_ENC_BUFFER)); | |
153 | ||
154 | for (j = 0; j < nPlaneCnt; j++) { | |
155 | ppCodecBuffer[i]->pVirAddr[j] = | |
156 | (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, nPlaneSize[j], eMemoryType); | |
157 | if (ppCodecBuffer[i]->pVirAddr[j] == NULL) { | |
158 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Failed to Alloc plane"); | |
159 | ret = OMX_ErrorInsufficientResources; | |
160 | goto EXIT; | |
161 | } | |
162 | ||
163 | ppCodecBuffer[i]->fd[j] = | |
164 | Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, ppCodecBuffer[i]->pVirAddr[j]); | |
165 | ppCodecBuffer[i]->bufferSize[j] = nPlaneSize[j]; | |
166 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "PORT[%d]: pMFCCodecBuffer[%d]->pVirAddr[%d]: 0x%x", nPortIndex, i, j, ppCodecBuffer[i]->pVirAddr[j]); | |
167 | } | |
168 | ||
169 | ppCodecBuffer[i]->dataSize = 0; | |
170 | } | |
171 | ||
172 | return OMX_ErrorNone; | |
173 | ||
174 | EXIT: | |
175 | Exynos_Free_CodecBuffers(pOMXComponent, nPortIndex); | |
176 | ||
177 | FunctionOut(); | |
178 | ||
179 | return ret; | |
180 | } | |
181 | ||
c6f4bc34 YK |
182 | OMX_BOOL Exynos_Check_BufferProcess_State(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 nPortIndex) |
183 | { | |
184 | OMX_BOOL ret = OMX_FALSE; | |
185 | ||
186 | if ((pExynosComponent->currentState == OMX_StateExecuting) && | |
187 | (pExynosComponent->pExynosPort[nPortIndex].portState == OMX_StateIdle) && | |
188 | (pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) && | |
189 | (pExynosComponent->transientState != EXYNOS_OMX_TransStateIdleToExecuting)) { | |
190 | ret = OMX_TRUE; | |
191 | } else { | |
192 | ret = OMX_FALSE; | |
193 | } | |
194 | ||
195 | return ret; | |
196 | } | |
197 | ||
198 | OMX_ERRORTYPE Exynos_Input_CodecBufferToData(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_PTR codecBuffer, EXYNOS_OMX_DATA *pData) | |
199 | { | |
200 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
201 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
202 | CODEC_ENC_BUFFER *pInputCodecBuffer = (CODEC_ENC_BUFFER*)codecBuffer; | |
203 | ||
204 | pData->buffer.multiPlaneBuffer.dataBuffer[0] = pInputCodecBuffer->pVirAddr[0]; | |
205 | pData->buffer.multiPlaneBuffer.dataBuffer[1] = pInputCodecBuffer->pVirAddr[1]; | |
a56b4516 TK |
206 | pData->buffer.multiPlaneBuffer.fd[0] = pInputCodecBuffer->fd[0]; |
207 | pData->buffer.multiPlaneBuffer.fd[1] = pInputCodecBuffer->fd[1]; | |
c6f4bc34 YK |
208 | pData->allocSize = pInputCodecBuffer->bufferSize[0] + pInputCodecBuffer->bufferSize[1]; |
209 | pData->dataLen = pInputCodecBuffer->dataSize; | |
210 | pData->usedDataLen = 0; | |
211 | pData->remainDataLen = pInputCodecBuffer->dataSize; | |
212 | ||
213 | pData->nFlags = 0; | |
214 | pData->timeStamp = 0; | |
215 | pData->pPrivate = codecBuffer; | |
216 | pData->bufferHeader = NULL; | |
217 | ||
218 | return ret; | |
219 | } | |
220 | ||
e50b9040 TK |
221 | OMX_ERRORTYPE Exynos_Output_CodecBufferToData( |
222 | CODEC_ENC_BUFFER *pCodecBuffer, | |
223 | EXYNOS_OMX_DATA *pData) | |
c6f4bc34 YK |
224 | { |
225 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
c6f4bc34 | 226 | |
e50b9040 | 227 | pData->buffer.singlePlaneBuffer.dataBuffer = pCodecBuffer->pVirAddr[0]; |
a56b4516 | 228 | pData->buffer.singlePlaneBuffer.fd = pCodecBuffer->fd[0]; |
e50b9040 | 229 | pData->allocSize = pCodecBuffer->bufferSize[0]; |
c6f4bc34 YK |
230 | pData->dataLen = 0; |
231 | pData->usedDataLen = 0; | |
232 | pData->remainDataLen = 0; | |
233 | ||
234 | pData->nFlags = 0; | |
235 | pData->timeStamp = 0; | |
e50b9040 | 236 | pData->pPrivate = pCodecBuffer; |
c6f4bc34 YK |
237 | pData->bufferHeader = NULL; |
238 | ||
239 | return ret; | |
240 | } | |
241 | ||
242 | void Exynos_Wait_ProcessPause(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 nPortIndex) | |
243 | { | |
244 | EXYNOS_OMX_BASEPORT *exynosOMXInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
245 | EXYNOS_OMX_BASEPORT *exynosOMXOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
246 | EXYNOS_OMX_BASEPORT *exynosOMXPort = NULL; | |
247 | ||
248 | FunctionIn(); | |
249 | ||
250 | exynosOMXPort = &pExynosComponent->pExynosPort[nPortIndex]; | |
251 | ||
252 | if (((pExynosComponent->currentState == OMX_StatePause) || | |
253 | (pExynosComponent->currentState == OMX_StateIdle) || | |
254 | (pExynosComponent->transientState == EXYNOS_OMX_TransStateLoadedToIdle) || | |
255 | (pExynosComponent->transientState == EXYNOS_OMX_TransStateExecutingToIdle)) && | |
256 | (pExynosComponent->transientState != EXYNOS_OMX_TransStateIdleToLoaded) && | |
257 | (!CHECK_PORT_BEING_FLUSHED(exynosOMXPort))) { | |
258 | Exynos_OSAL_SignalWait(pExynosComponent->pExynosPort[nPortIndex].pauseEvent, DEF_MAX_WAIT_TIME); | |
259 | Exynos_OSAL_SignalReset(pExynosComponent->pExynosPort[nPortIndex].pauseEvent); | |
260 | } | |
261 | ||
262 | FunctionOut(); | |
263 | ||
264 | return; | |
265 | } | |
266 | ||
267 | OMX_BOOL Exynos_CSC_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *srcInputData) | |
268 | { | |
269 | OMX_BOOL ret = OMX_FALSE; | |
270 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
271 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
272 | EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
273 | EXYNOS_OMX_DATABUFFER *inputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer; | |
274 | OMX_U32 nFrameWidth = exynosInputPort->portDefinition.format.video.nFrameWidth; | |
275 | OMX_U32 nFrameHeight = exynosInputPort->portDefinition.format.video.nFrameHeight; | |
276 | OMX_COLOR_FORMATTYPE eColorFormat = exynosInputPort->portDefinition.format.video.eColorFormat; | |
277 | OMX_BYTE checkInputStream = NULL; | |
278 | OMX_BOOL flagEOS = OMX_FALSE; | |
279 | ||
280 | FunctionIn(); | |
281 | ||
282 | checkInputStream = inputUseBuffer->bufferHeader->pBuffer; | |
283 | ||
284 | CODEC_ENC_BUFFER *codecInputBuffer = (CODEC_ENC_BUFFER *)srcInputData->pPrivate; | |
285 | codecInputBuffer->dataSize = ((nFrameWidth * nFrameHeight) * 3) / 2; | |
286 | ||
287 | unsigned int csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar); | |
288 | unsigned int csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar); | |
289 | CSC_METHOD csc_method = CSC_METHOD_SW; | |
290 | unsigned int cacheable = 1; | |
291 | ||
292 | unsigned char *pSrcBuf[3] = {NULL, }; | |
293 | unsigned char *pDstBuf[3] = {NULL, }; | |
294 | ||
295 | CSC_ERRORCODE cscRet = CSC_ErrorNone; | |
296 | ||
297 | pSrcBuf[0] = checkInputStream; | |
298 | pSrcBuf[1] = checkInputStream + (nFrameWidth * nFrameHeight); | |
299 | pSrcBuf[2] = checkInputStream + (((nFrameWidth * nFrameHeight) * 5) / 4); | |
300 | ||
301 | pDstBuf[0] = srcInputData->buffer.multiPlaneBuffer.dataBuffer[0]; | |
302 | pDstBuf[1] = srcInputData->buffer.multiPlaneBuffer.dataBuffer[1]; | |
303 | pDstBuf[2] = srcInputData->buffer.multiPlaneBuffer.dataBuffer[2]; | |
304 | ||
c6f4bc34 YK |
305 | #ifdef USE_METADATABUFFERTYPE |
306 | OMX_PTR ppBuf[MAX_BUFFER_PLANE]; | |
307 | ||
308 | /* kMetadataBufferTypeGrallocSource */ | |
309 | if (exynosInputPort->bStoreMetaData == OMX_TRUE) { | |
310 | /* ARGB8888 converted to YUV420SemiPlanar */ | |
311 | csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_Format32bitARGB8888); | |
312 | csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar); | |
313 | ||
314 | Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf); | |
315 | if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) { | |
316 | ExynosVideoPlane planes[MAX_BUFFER_PLANE]; | |
317 | OMX_U32 stride; | |
318 | int imageSize; | |
319 | ||
5be5cd9c YK |
320 | ret = Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatAndroidOpaque, planes); |
321 | if (ret != OMX_ErrorNone) { | |
322 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: Exynos_OSAL_LockANBHandle() failed", __FUNCTION__); | |
323 | ret = OMX_FALSE; | |
324 | goto EXIT; | |
325 | } | |
326 | ||
c6f4bc34 YK |
327 | imageSize = nFrameWidth * nFrameHeight * 3; /* RGB888 */ |
328 | ||
0ffdc2e6 TK |
329 | #ifdef USE_GSC_RGB_ENCODER |
330 | if (pVideoEnc->csc_set_format == OMX_FALSE) { | |
331 | cscRet = csc_set_method(pVideoEnc->csc_handle, CSC_METHOD_HW); | |
332 | if (cscRet != CSC_ErrorNone) { | |
333 | ret = OMX_FALSE; | |
334 | goto EXIT; | |
335 | } | |
336 | } | |
337 | #endif | |
338 | ||
faa0e22c | 339 | #ifdef USE_DMA_BUF |
0ffdc2e6 | 340 | csc_get_method(pVideoEnc->csc_handle, &csc_method); |
c6f4bc34 YK |
341 | if (csc_method == CSC_METHOD_HW) |
342 | pSrcBuf[0] = (unsigned char *)planes[0].fd; | |
343 | else | |
faa0e22c SKR |
344 | #endif |
345 | pSrcBuf[0] = planes[0].addr; | |
c6f4bc34 YK |
346 | pSrcBuf[1] = NULL; |
347 | pSrcBuf[2] = NULL; | |
348 | } | |
349 | } else | |
350 | #endif | |
351 | { | |
faa0e22c | 352 | #ifdef USE_DMA_BUF |
0ffdc2e6 | 353 | csc_get_method(pVideoEnc->csc_handle, &csc_method); |
c6f4bc34 YK |
354 | if (csc_method == CSC_METHOD_HW) { |
355 | pSrcBuf[0] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, checkInputStream); | |
356 | pSrcBuf[1] = NULL; | |
357 | pSrcBuf[2] = NULL; | |
358 | } | |
faa0e22c | 359 | #endif |
c6f4bc34 YK |
360 | |
361 | switch (eColorFormat) { | |
362 | case OMX_COLOR_FormatYUV420Planar: | |
363 | /* YUV420Planar converted to YUV420Semiplanar (interleaved UV plane) as per MFC spec.*/ | |
364 | csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420Planar); | |
365 | csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar); | |
366 | break; | |
367 | case OMX_COLOR_FormatYUV420SemiPlanar: | |
368 | case OMX_SEC_COLOR_FormatNV12Tiled: | |
369 | case OMX_SEC_COLOR_FormatNV21Linear: | |
370 | /* Just copied to MFC input buffer */ | |
371 | csc_src_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar); | |
372 | csc_dst_color_format = omx_2_hal_pixel_format((unsigned int)OMX_COLOR_FormatYUV420SemiPlanar); | |
373 | break; | |
374 | default: | |
375 | break; | |
376 | } | |
377 | } | |
378 | ||
0ffdc2e6 TK |
379 | #ifdef USE_DMA_BUF |
380 | if (csc_method == CSC_METHOD_HW) { | |
381 | pDstBuf[0] = srcInputData->buffer.multiPlaneBuffer.fd[0]; | |
382 | pDstBuf[1] = srcInputData->buffer.multiPlaneBuffer.fd[1]; | |
383 | pDstBuf[2] = srcInputData->buffer.multiPlaneBuffer.fd[2]; | |
384 | } | |
385 | #endif | |
386 | ||
c6f4bc34 YK |
387 | csc_set_src_format( |
388 | pVideoEnc->csc_handle, /* handle */ | |
389 | nFrameWidth, /* width */ | |
390 | nFrameHeight, /* height */ | |
391 | 0, /* crop_left */ | |
392 | 0, /* crop_right */ | |
393 | nFrameWidth, /* crop_width */ | |
394 | nFrameHeight, /* crop_height */ | |
395 | csc_src_color_format, /* color_format */ | |
396 | cacheable); /* cacheable */ | |
397 | csc_set_dst_format( | |
398 | pVideoEnc->csc_handle, /* handle */ | |
399 | nFrameWidth, /* width */ | |
400 | nFrameHeight, /* height */ | |
401 | 0, /* crop_left */ | |
402 | 0, /* crop_right */ | |
403 | nFrameWidth, /* crop_width */ | |
404 | nFrameHeight, /* crop_height */ | |
405 | csc_dst_color_format, /* color_format */ | |
406 | cacheable); /* cacheable */ | |
407 | csc_set_src_buffer( | |
408 | pVideoEnc->csc_handle, /* handle */ | |
4e27e753 | 409 | pSrcBuf, |
410 | CSC_MEMORY_DMABUF); /* YUV Addr or FD */ | |
c6f4bc34 YK |
411 | csc_set_dst_buffer( |
412 | pVideoEnc->csc_handle, /* handle */ | |
4e27e753 | 413 | pDstBuf, |
414 | CSC_MEMORY_DMABUF); /* YUV Addr or FD */ | |
c6f4bc34 YK |
415 | cscRet = csc_convert(pVideoEnc->csc_handle); |
416 | if (cscRet != CSC_ErrorNone) | |
417 | ret = OMX_FALSE; | |
418 | else | |
419 | ret = OMX_TRUE; | |
420 | ||
421 | #ifdef USE_METADATABUFFERTYPE | |
422 | if (exynosInputPort->bStoreMetaData == OMX_TRUE) { | |
423 | Exynos_OSAL_UnlockANBHandle((OMX_U32)ppBuf[0]); | |
424 | } | |
425 | #endif | |
426 | ||
427 | ret = OMX_TRUE; | |
428 | ||
429 | EXIT: | |
430 | FunctionOut(); | |
431 | ||
432 | return ret; | |
433 | } | |
434 | ||
435 | OMX_BOOL Exynos_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *srcInputData) | |
436 | { | |
437 | OMX_BOOL ret = OMX_FALSE; | |
438 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
439 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
440 | EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
441 | EXYNOS_OMX_DATABUFFER *inputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer; | |
442 | OMX_U32 nFrameWidth = exynosInputPort->portDefinition.format.video.nFrameWidth; | |
443 | OMX_U32 nFrameHeight = exynosInputPort->portDefinition.format.video.nFrameHeight; | |
444 | OMX_COLOR_FORMATTYPE eColorFormat = exynosInputPort->portDefinition.format.video.eColorFormat; | |
445 | OMX_U32 copySize = 0; | |
446 | OMX_BYTE checkInputStream = NULL; | |
447 | OMX_U32 checkInputStreamLen = 0; | |
448 | OMX_BOOL flagEOS = OMX_FALSE; | |
449 | ||
450 | FunctionIn(); | |
451 | ||
24ec2c82 | 452 | if (exynosInputPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
453 | if ((srcInputData->buffer.multiPlaneBuffer.dataBuffer[0] == NULL) || |
454 | (srcInputData->pPrivate == NULL)) { | |
455 | ret = OMX_FALSE; | |
456 | goto EXIT; | |
457 | } | |
458 | } | |
459 | ||
460 | if (inputUseBuffer->dataValid == OMX_TRUE) { | |
24ec2c82 | 461 | if (exynosInputPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
462 | Exynos_Shared_BufferToData(inputUseBuffer, srcInputData, ONE_PLANE); |
463 | #ifdef USE_METADATABUFFERTYPE | |
464 | if (exynosInputPort->bStoreMetaData == OMX_TRUE) { | |
465 | OMX_PTR ppBuf[MAX_BUFFER_PLANE]; | |
466 | OMX_PTR allocSize[MAX_BUFFER_PLANE]; | |
467 | int plane = 0; | |
e4e150b8 | 468 | |
c6f4bc34 YK |
469 | if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) { |
470 | Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf); | |
471 | ExynosVideoPlane planes[MAX_BUFFER_PLANE]; | |
472 | ||
473 | Exynos_OSAL_LockANBHandle((OMX_U32)ppBuf[0], nFrameWidth, nFrameHeight, OMX_COLOR_FormatYUV420SemiPlanar, planes); | |
474 | ||
475 | srcInputData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd; | |
476 | srcInputData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd; | |
477 | allocSize[0] = nFrameWidth * nFrameHeight; | |
478 | allocSize[1] = nFrameWidth * nFrameHeight >> 1; | |
479 | ||
480 | for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { | |
481 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = | |
482 | Exynos_OSAL_SharedMemory_IONToVirt(pVideoEnc->hSharedMemory, srcInputData->buffer.multiPlaneBuffer.fd[plane]); | |
483 | if(srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] == NULL) { | |
484 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = | |
485 | Exynos_OSAL_SharedMemory_Map(pVideoEnc->hSharedMemory, allocSize[plane], srcInputData->buffer.multiPlaneBuffer.fd[plane]); | |
486 | } | |
487 | } | |
488 | /* input buffers are 2 plane. */ | |
489 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL; | |
490 | srcInputData->buffer.multiPlaneBuffer.fd[2] = -1; | |
491 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s:%d YAddr: 0x%x CbCrAddr: 0x%x", __FUNCTION__, __LINE__, (unsigned int)ppBuf[0], (unsigned int)ppBuf[0]); | |
492 | } else { | |
493 | /* kMetadataBufferTypeCameraSource */ | |
494 | Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)inputUseBuffer->bufferHeader->pBuffer, ppBuf); | |
f27148d6 | 495 | #ifndef USE_USERPTR_CAMERA_INPUT |
faa0e22c | 496 | #ifdef USE_DMA_BUF |
c6f4bc34 YK |
497 | srcInputData->buffer.multiPlaneBuffer.fd[0] = ppBuf[0]; |
498 | srcInputData->buffer.multiPlaneBuffer.fd[1] = ppBuf[1]; | |
499 | allocSize[0] = nFrameWidth * nFrameHeight; | |
500 | allocSize[1] = nFrameWidth * nFrameHeight >> 1; | |
501 | ||
502 | for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { | |
503 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = | |
504 | Exynos_OSAL_SharedMemory_IONToVirt(pVideoEnc->hSharedMemory, srcInputData->buffer.multiPlaneBuffer.fd[plane]); | |
505 | if(srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] == NULL) { | |
506 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = | |
507 | Exynos_OSAL_SharedMemory_Map(pVideoEnc->hSharedMemory, allocSize[plane], srcInputData->buffer.multiPlaneBuffer.fd[plane]); | |
508 | } | |
509 | } | |
510 | /* input buffers are 2 plane. */ | |
511 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL; | |
512 | srcInputData->buffer.multiPlaneBuffer.fd[2] = -1; | |
f27148d6 TK |
513 | #else |
514 | for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { | |
515 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = ppBuf[plane]; | |
516 | } | |
517 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL; | |
518 | #endif | |
faa0e22c SKR |
519 | #else |
520 | for (plane = 0; plane < MFC_INPUT_BUFFER_PLANE; plane++) { | |
521 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[plane] = ppBuf[plane]; | |
522 | } | |
523 | srcInputData->buffer.multiPlaneBuffer.dataBuffer[2] = NULL; | |
524 | #endif | |
525 | 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 |
526 | } |
527 | } | |
528 | #endif | |
529 | /* reset dataBuffer */ | |
530 | Exynos_ResetDataBuffer(inputUseBuffer); | |
24ec2c82 | 531 | } else if (exynosInputPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
532 | checkInputStream = inputUseBuffer->bufferHeader->pBuffer + inputUseBuffer->usedDataLen; |
533 | checkInputStreamLen = inputUseBuffer->remainDataLen; | |
534 | ||
535 | pExynosComponent->bUseFlagEOF = OMX_TRUE; | |
536 | ||
537 | if (checkInputStreamLen == 0) { | |
538 | inputUseBuffer->nFlags |= OMX_BUFFERFLAG_EOS; | |
539 | flagEOS = OMX_TRUE; | |
540 | } | |
541 | ||
542 | copySize = checkInputStreamLen; | |
543 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "exynos_checkInputFrame : OMX_TRUE"); | |
544 | ||
545 | if (((srcInputData->allocSize) - (srcInputData->dataLen)) >= copySize) { | |
5be5cd9c YK |
546 | ret = Exynos_CSC_InputData(pOMXComponent, srcInputData); |
547 | if (ret == OMX_FALSE) | |
548 | goto EXIT; | |
c6f4bc34 YK |
549 | |
550 | inputUseBuffer->dataLen -= copySize; | |
551 | inputUseBuffer->remainDataLen -= copySize; | |
552 | inputUseBuffer->usedDataLen += copySize; | |
553 | ||
554 | srcInputData->dataLen += copySize; | |
555 | srcInputData->remainDataLen += copySize; | |
556 | ||
557 | srcInputData->timeStamp = inputUseBuffer->timeStamp; | |
558 | srcInputData->nFlags = inputUseBuffer->nFlags; | |
559 | srcInputData->bufferHeader = inputUseBuffer->bufferHeader; | |
560 | } else { | |
561 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "input codec buffer is smaller than decoded input data size Out Length"); | |
562 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
563 | pExynosComponent->callbackData, | |
564 | OMX_EventError, OMX_ErrorUndefined, 0, NULL); | |
565 | ret = OMX_FALSE; | |
566 | } | |
567 | ||
568 | if (((exynosInputPort->bStoreMetaData == OMX_TRUE) && (eColorFormat == OMX_COLOR_FormatAndroidOpaque)) || | |
569 | (exynosInputPort->bStoreMetaData == OMX_FALSE)) { | |
570 | Exynos_InputBufferReturn(pOMXComponent); | |
571 | } else { | |
572 | inputUseBuffer->dataValid = OMX_TRUE; | |
573 | } | |
574 | } | |
575 | ||
576 | if ((srcInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { | |
577 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "bSaveFlagEOS : OMX_TRUE"); | |
578 | srcInputData->dataLen = 0; | |
579 | srcInputData->remainDataLen = 0; | |
580 | pExynosComponent->bSaveFlagEOS = OMX_TRUE; | |
581 | } | |
582 | ||
583 | if (pExynosComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) { | |
584 | pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_TRUE; | |
585 | pExynosComponent->checkTimeStamp.startTimeStamp = srcInputData->timeStamp; | |
586 | pExynosComponent->checkTimeStamp.nStartFlags = srcInputData->nFlags; | |
587 | pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE; | |
588 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "first frame timestamp after seeking %lld us (%.2f secs)", | |
589 | srcInputData->timeStamp, srcInputData->timeStamp / 1E6); | |
590 | } | |
591 | ||
592 | ret = OMX_TRUE; | |
593 | } | |
594 | ||
595 | EXIT: | |
596 | ||
597 | FunctionOut(); | |
598 | ||
599 | return ret; | |
600 | } | |
601 | ||
602 | OMX_BOOL Exynos_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent, EXYNOS_OMX_DATA *dstOutputData) | |
603 | { | |
604 | OMX_BOOL ret = OMX_FALSE; | |
605 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
606 | EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
607 | EXYNOS_OMX_DATABUFFER *outputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.outputDataBuffer; | |
608 | OMX_U32 copySize = 0; | |
609 | ||
610 | FunctionIn(); | |
611 | ||
24ec2c82 | 612 | if (exynosOutputPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
613 | if (Exynos_Shared_DataToBuffer(dstOutputData, outputUseBuffer) == OMX_ErrorNone) |
614 | outputUseBuffer->dataValid = OMX_TRUE; | |
615 | } | |
616 | ||
617 | if (outputUseBuffer->dataValid == OMX_TRUE) { | |
618 | if (pExynosComponent->checkTimeStamp.needCheckStartTimeStamp == OMX_TRUE) { | |
619 | if (pExynosComponent->checkTimeStamp.startTimeStamp == dstOutputData->timeStamp){ | |
620 | pExynosComponent->checkTimeStamp.startTimeStamp = -19761123; | |
621 | pExynosComponent->checkTimeStamp.nStartFlags = 0x0; | |
622 | pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE; | |
623 | pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE; | |
624 | } else { | |
625 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "garbage frame drop after flush"); | |
626 | ret = OMX_TRUE; | |
627 | goto EXIT; | |
628 | } | |
629 | } else if (pExynosComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) { | |
630 | ret = OMX_TRUE; | |
631 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "input buffer has not come after flush."); | |
632 | goto EXIT; | |
633 | } | |
634 | ||
24ec2c82 | 635 | if (exynosOutputPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
636 | if (dstOutputData->remainDataLen <= (outputUseBuffer->allocSize - outputUseBuffer->dataLen)) { |
637 | copySize = dstOutputData->remainDataLen; | |
638 | if (copySize > 0) | |
639 | Exynos_OSAL_Memcpy((outputUseBuffer->bufferHeader->pBuffer + outputUseBuffer->dataLen), | |
640 | (dstOutputData->buffer.singlePlaneBuffer.dataBuffer + dstOutputData->usedDataLen), | |
641 | copySize); | |
642 | outputUseBuffer->dataLen += copySize; | |
643 | outputUseBuffer->remainDataLen += copySize; | |
644 | outputUseBuffer->nFlags = dstOutputData->nFlags; | |
645 | outputUseBuffer->timeStamp = dstOutputData->timeStamp; | |
646 | ||
647 | ret = OMX_TRUE; | |
648 | ||
649 | if ((outputUseBuffer->remainDataLen > 0) || | |
650 | (outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS)) { | |
651 | Exynos_OutputBufferReturn(pOMXComponent); | |
652 | } | |
653 | } else { | |
654 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "output buffer is smaller than encoded data size Out Length"); | |
655 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
656 | pExynosComponent->callbackData, | |
657 | OMX_EventError, OMX_ErrorUndefined, 0, NULL); | |
658 | ret = OMX_FALSE; | |
659 | } | |
24ec2c82 | 660 | } else if (exynosOutputPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
661 | if ((outputUseBuffer->remainDataLen > 0) || |
662 | ((outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) || | |
663 | (CHECK_PORT_BEING_FLUSHED(exynosOutputPort))) | |
664 | Exynos_OutputBufferReturn(pOMXComponent); | |
665 | } | |
666 | } else { | |
667 | ret = OMX_FALSE; | |
668 | } | |
669 | ||
670 | EXIT: | |
671 | FunctionOut(); | |
672 | ||
673 | return ret; | |
674 | } | |
675 | ||
676 | #ifdef USE_METADATABUFFERTYPE | |
677 | OMX_ERRORTYPE Exynos_OMX_ExtensionSetup(OMX_HANDLETYPE hComponent) | |
678 | { | |
679 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
680 | OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
681 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
682 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
683 | EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
684 | EXYNOS_OMX_DATABUFFER *srcInputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer; | |
685 | EXYNOS_OMX_DATA *pSrcInputData = &exynosInputPort->processData; | |
686 | OMX_COLOR_FORMATTYPE eColorFormat = exynosInputPort->portDefinition.format.video.eColorFormat; | |
687 | ||
688 | int i = 0; | |
689 | OMX_PTR ppBuf[MAX_BUFFER_PLANE]; | |
690 | ||
691 | ||
692 | /* kMetadataBufferTypeGrallocSource */ | |
693 | if (exynosInputPort->bStoreMetaData == OMX_TRUE) { | |
694 | Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)srcInputUseBuffer->bufferHeader->pBuffer, ppBuf); | |
695 | if (eColorFormat == OMX_COLOR_FormatAndroidOpaque) { | |
696 | pVideoEnc->ANBColorFormat = Exynos_OSAL_GetANBColorFormat(ppBuf[0]); | |
697 | if ((pVideoEnc->ANBColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) || | |
698 | (pVideoEnc->ANBColorFormat == OMX_SEC_COLOR_FormatNV12Tiled)) { | |
699 | exynosInputPort->bufferProcessType = BUFFER_SHARE; | |
700 | } else { | |
701 | exynosInputPort->bufferProcessType = BUFFER_COPY; | |
702 | } | |
703 | ||
704 | if ((exynosInputPort->bufferProcessType & BUFFER_COPY) == BUFFER_COPY) { | |
705 | Exynos_OSAL_SemaphoreCreate(&exynosInputPort->codecSemID); | |
706 | Exynos_OSAL_QueueCreate(&exynosInputPort->codecBufferQ, MAX_QUEUE_ELEMENTS); | |
707 | ||
708 | for (i = 0; i < MFC_INPUT_BUFFER_NUM_MAX; i++) { | |
709 | pVideoEnc->pMFCEncInputBuffer[i] = Exynos_OSAL_Malloc(sizeof(CODEC_ENC_BUFFER)); | |
710 | /* Use ION Allocator */ | |
711 | /*Alloc Y-Buffer */ | |
712 | pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_YBUFFER_SIZE, NORMAL_MEMORY); | |
713 | pVideoEnc->pMFCEncInputBuffer[i]->fd[0] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0]); | |
714 | pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[0] = DEFAULT_MFC_INPUT_YBUFFER_SIZE; | |
715 | /*Alloc C-Buffer */ | |
716 | pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1] = (void *)Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, DEFAULT_MFC_INPUT_CBUFFER_SIZE, NORMAL_MEMORY); | |
717 | pVideoEnc->pMFCEncInputBuffer[i]->fd[1] = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1]); | |
718 | pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[1] = DEFAULT_MFC_INPUT_CBUFFER_SIZE; | |
719 | ||
720 | pVideoEnc->pMFCEncInputBuffer[i]->dataSize = 0; | |
721 | ||
722 | if ((pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0] == NULL) || | |
723 | (pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1] == NULL)) { | |
724 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Fail input buffer"); | |
725 | ret = OMX_ErrorInsufficientResources; | |
726 | goto EXIT; | |
727 | } | |
728 | ||
729 | /* MFC input buffers are 1 plane. */ | |
730 | pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[2] = NULL; | |
731 | pVideoEnc->pMFCEncInputBuffer[i]->fd[2] = -1; | |
732 | pVideoEnc->pMFCEncInputBuffer[i]->bufferSize[2] = 0; | |
733 | ||
734 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pVideoEnc->pMFCEncInputBuffer[%d]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]); | |
735 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pVideoEnc->pMFCEncInputBuffer[%d]->pVirAddr[0]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[0]); | |
736 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "pVideoEnc->pMFCEncInputBuffer[%d]->pVirAddr[1]: 0x%x", i, pVideoEnc->pMFCEncInputBuffer[i]->pVirAddr[1]); | |
737 | ||
e4e150b8 | 738 | Exynos_CodecBufferEnqueue(pExynosComponent, INPUT_PORT_INDEX, pVideoEnc->pMFCEncInputBuffer[i]); |
c6f4bc34 YK |
739 | } |
740 | } else if (exynosInputPort->bufferProcessType == BUFFER_SHARE) { | |
741 | /*************/ | |
742 | /* TBD */ | |
743 | /*************/ | |
744 | /* Does not require any actions. */ | |
745 | } | |
746 | } | |
747 | } | |
748 | ||
749 | ||
750 | EXIT: | |
751 | ||
752 | return ret; | |
753 | } | |
754 | #endif | |
755 | ||
756 | OMX_ERRORTYPE Exynos_OMX_SrcInputBufferProcess(OMX_HANDLETYPE hComponent) | |
757 | { | |
758 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
759 | OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
760 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
761 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
762 | EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
763 | EXYNOS_OMX_DATABUFFER *srcInputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.inputDataBuffer; | |
764 | EXYNOS_OMX_DATA *pSrcInputData = &exynosInputPort->processData; | |
765 | OMX_BOOL bCheckInputData = OMX_FALSE; | |
766 | OMX_BOOL bValidCodecData = OMX_FALSE; | |
767 | ||
768 | FunctionIn(); | |
769 | ||
770 | while (!pVideoEnc->bExitBufferProcessThread) { | |
771 | Exynos_OSAL_SleepMillisec(0); | |
772 | Exynos_Wait_ProcessPause(pExynosComponent, INPUT_PORT_INDEX); | |
773 | ||
774 | while ((Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX)) && | |
775 | (!pVideoEnc->bExitBufferProcessThread)) { | |
776 | Exynos_OSAL_SleepMillisec(0); | |
777 | ||
778 | if (CHECK_PORT_BEING_FLUSHED(exynosInputPort)) | |
779 | break; | |
780 | if (exynosInputPort->portState != OMX_StateIdle) | |
781 | break; | |
782 | ||
783 | Exynos_OSAL_MutexLock(srcInputUseBuffer->bufferMutex); | |
784 | if (pVideoEnc->bFirstInput == OMX_FALSE) { | |
24ec2c82 | 785 | if (exynosInputPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
786 | OMX_PTR codecBuffer; |
787 | if ((pSrcInputData->buffer.multiPlaneBuffer.dataBuffer[0] == NULL) || (pSrcInputData->pPrivate == NULL)) { | |
e4e150b8 | 788 | Exynos_CodecBufferDequeue(pExynosComponent, INPUT_PORT_INDEX, &codecBuffer); |
c6f4bc34 YK |
789 | if (codecBuffer != NULL) { |
790 | Exynos_Input_CodecBufferToData(pExynosComponent, codecBuffer, pSrcInputData); | |
791 | } | |
792 | Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex); | |
793 | break; | |
794 | } | |
795 | } | |
796 | ||
797 | if (srcInputUseBuffer->dataValid == OMX_TRUE) { | |
798 | bCheckInputData = Exynos_Preprocessor_InputData(pOMXComponent, pSrcInputData); | |
799 | } else { | |
800 | bCheckInputData = OMX_FALSE; | |
801 | } | |
802 | } | |
803 | if ((bCheckInputData == OMX_FALSE) && | |
804 | (!CHECK_PORT_BEING_FLUSHED(exynosInputPort))) { | |
805 | ret = Exynos_InputBufferGetQueue(pExynosComponent); | |
806 | #ifdef USE_METADATABUFFERTYPE | |
807 | if ((pVideoEnc->bFirstInput == OMX_TRUE) && | |
808 | (!CHECK_PORT_BEING_FLUSHED(exynosInputPort))) { | |
809 | Exynos_OMX_ExtensionSetup(hComponent); | |
810 | pVideoEnc->bFirstInput = OMX_FALSE; | |
811 | } | |
812 | #endif | |
813 | Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex); | |
814 | break; | |
815 | } | |
816 | ||
817 | if (CHECK_PORT_BEING_FLUSHED(exynosInputPort)) { | |
818 | Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex); | |
819 | break; | |
820 | } | |
821 | ||
822 | ret = pVideoEnc->exynos_codec_srcInputProcess(pOMXComponent, pSrcInputData); | |
823 | Exynos_ResetCodecData(pSrcInputData); | |
824 | Exynos_OSAL_MutexUnlock(srcInputUseBuffer->bufferMutex); | |
825 | if (ret == OMX_ErrorCodecInit) | |
826 | pVideoEnc->bExitBufferProcessThread = OMX_TRUE; | |
827 | } | |
828 | } | |
829 | ||
830 | EXIT: | |
831 | ||
832 | FunctionOut(); | |
833 | ||
834 | return ret; | |
835 | } | |
836 | ||
837 | OMX_ERRORTYPE Exynos_OMX_SrcOutputBufferProcess(OMX_HANDLETYPE hComponent) | |
838 | { | |
839 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
840 | OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
841 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
842 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
843 | EXYNOS_OMX_BASEPORT *exynosInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
844 | EXYNOS_OMX_DATABUFFER *srcOutputUseBuffer = &exynosInputPort->way.port2WayDataBuffer.outputDataBuffer; | |
e4e150b8 | 845 | EXYNOS_OMX_DATA srcOutputData; |
c6f4bc34 YK |
846 | |
847 | FunctionIn(); | |
848 | ||
849 | while (!pVideoEnc->bExitBufferProcessThread) { | |
850 | Exynos_OSAL_SleepMillisec(0); | |
851 | ||
852 | while (!pVideoEnc->bExitBufferProcessThread) { | |
24ec2c82 | 853 | if (exynosInputPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
854 | if (Exynos_Check_BufferProcess_State(pExynosComponent, INPUT_PORT_INDEX) == OMX_FALSE) |
855 | break; | |
856 | } | |
857 | Exynos_OSAL_SleepMillisec(0); | |
858 | ||
859 | if (CHECK_PORT_BEING_FLUSHED(exynosInputPort)) | |
860 | break; | |
861 | ||
862 | Exynos_OSAL_MutexLock(srcOutputUseBuffer->bufferMutex); | |
863 | ret = pVideoEnc->exynos_codec_srcOutputProcess(pOMXComponent, &srcOutputData); | |
864 | ||
865 | if (ret == OMX_ErrorNone) { | |
24ec2c82 | 866 | if (exynosInputPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
867 | OMX_PTR codecBuffer; |
868 | codecBuffer = srcOutputData.pPrivate; | |
869 | if (codecBuffer != NULL) | |
e4e150b8 | 870 | Exynos_CodecBufferEnqueue(pExynosComponent, INPUT_PORT_INDEX, codecBuffer); |
c6f4bc34 | 871 | } |
24ec2c82 | 872 | if (exynosInputPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
873 | Exynos_Shared_DataToBuffer(&srcOutputData, srcOutputUseBuffer); |
874 | Exynos_InputBufferReturn(pOMXComponent); | |
875 | } | |
876 | Exynos_ResetCodecData(&srcOutputData); | |
877 | } | |
878 | Exynos_OSAL_MutexUnlock(srcOutputUseBuffer->bufferMutex); | |
879 | } | |
880 | } | |
881 | ||
882 | EXIT: | |
883 | ||
884 | FunctionOut(); | |
885 | ||
886 | return ret; | |
887 | } | |
888 | ||
889 | OMX_ERRORTYPE Exynos_OMX_DstInputBufferProcess(OMX_HANDLETYPE hComponent) | |
890 | { | |
891 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
892 | OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
893 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
894 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; | |
895 | EXYNOS_OMX_BASEPORT *exynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
896 | EXYNOS_OMX_DATABUFFER *dstInputUseBuffer = &exynosOutputPort->way.port2WayDataBuffer.inputDataBuffer; | |
897 | EXYNOS_OMX_DATA dstInputData; | |
e4e150b8 | 898 | |
c6f4bc34 YK |
899 | FunctionIn(); |
900 | ||
901 | while (!pVideoEnc->bExitBufferProcessThread) { | |
902 | Exynos_OSAL_SleepMillisec(0); | |
903 | ||
904 | while ((Exynos_Check_BufferProcess_State(pExynosComponent, OUTPUT_PORT_INDEX)) && | |
905 | (!pVideoEnc->bExitBufferProcessThread)) { | |
906 | Exynos_OSAL_SleepMillisec(0); | |
907 | ||
908 | if ((CHECK_PORT_BEING_FLUSHED(exynosOutputPort)) || | |
909 | (!CHECK_PORT_POPULATED(exynosOutputPort))) | |
910 | break; | |
911 | if (exynosOutputPort->portState != OMX_StateIdle) | |
912 | break; | |
913 | ||
914 | Exynos_OSAL_MutexLock(dstInputUseBuffer->bufferMutex); | |
24ec2c82 | 915 | if (exynosOutputPort->bufferProcessType & BUFFER_COPY) { |
e50b9040 TK |
916 | CODEC_ENC_BUFFER *pCodecBuffer = NULL; |
917 | ret = Exynos_CodecBufferDequeue(pExynosComponent, OUTPUT_PORT_INDEX, (OMX_PTR *)&pCodecBuffer); | |
c6f4bc34 YK |
918 | if (ret != OMX_ErrorNone) { |
919 | Exynos_OSAL_MutexUnlock(dstInputUseBuffer->bufferMutex); | |
920 | break; | |
921 | } | |
e50b9040 | 922 | Exynos_Output_CodecBufferToData(pCodecBuffer, &dstInputData); |
c6f4bc34 YK |
923 | } |
924 | ||
24ec2c82 | 925 | if (exynosOutputPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
926 | if ((dstInputUseBuffer->dataValid != OMX_TRUE) && |
927 | (!CHECK_PORT_BEING_FLUSHED(exynosOutputPort))) { | |
928 | ret = Exynos_OutputBufferGetQueue(pExynosComponent); | |
929 | if (ret != OMX_ErrorNone) { | |
930 | Exynos_OSAL_MutexUnlock(dstInputUseBuffer->bufferMutex); | |
931 | break; | |
932 | } | |
933 | Exynos_Shared_BufferToData(dstInputUseBuffer, &dstInputData, ONE_PLANE); | |
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; | |
e4e150b8 | 965 | |
c6f4bc34 YK |
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); | |
24ec2c82 | 980 | if (exynosOutputPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
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) || | |
24ec2c82 | 992 | (exynosOutputPort->bufferProcessType & BUFFER_SHARE)) |
c6f4bc34 YK |
993 | ret = pVideoEnc->exynos_codec_dstOutputProcess(pOMXComponent, pDstOutputData); |
994 | ||
995 | if (((ret == OMX_ErrorNone) && (dstOutputUseBuffer->dataValid == OMX_TRUE)) || | |
24ec2c82 | 996 | (exynosOutputPort->bufferProcessType & BUFFER_SHARE)) { |
c6f4bc34 YK |
997 | Exynos_Postprocess_OutputData(pOMXComponent, pDstOutputData); |
998 | } | |
999 | ||
24ec2c82 | 1000 | if (exynosOutputPort->bufferProcessType & BUFFER_COPY) { |
e50b9040 TK |
1001 | if (pDstOutputData->pPrivate != NULL) { |
1002 | Exynos_CodecBufferEnqueue(pExynosComponent, OUTPUT_PORT_INDEX, pDstOutputData->pPrivate); | |
c6f4bc34 YK |
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 | } |