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_VdecControl.c | |
20 | * @brief | |
21 | * @author SeungBeom Kim (sbcrux.kim@samsung.com) | |
22 | * @version 2.0.0 | |
23 | * @history | |
24 | * 2012.02.20 : Create | |
25 | */ | |
26 | ||
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | #include "Exynos_OMX_Macros.h" | |
31 | #include "Exynos_OSAL_Event.h" | |
32 | #include "Exynos_OMX_Vdec.h" | |
33 | #include "Exynos_OMX_VdecControl.h" | |
34 | #include "Exynos_OMX_Basecomponent.h" | |
35 | #include "Exynos_OSAL_Thread.h" | |
36 | #include "Exynos_OSAL_Semaphore.h" | |
37 | #include "Exynos_OSAL_Mutex.h" | |
38 | #include "Exynos_OSAL_ETC.h" | |
39 | #include "Exynos_OSAL_SharedMemory.h" | |
c6f4bc34 YK |
40 | |
41 | #ifdef USE_ANB | |
42 | #include "Exynos_OSAL_Android.h" | |
43 | #endif | |
44 | ||
e4e150b8 HK |
45 | #include "ExynosVideoApi.h" |
46 | ||
c6f4bc34 YK |
47 | #undef EXYNOS_LOG_TAG |
48 | #define EXYNOS_LOG_TAG "EXYNOS_VIDEO_DECCONTROL" | |
49 | #define EXYNOS_LOG_OFF | |
50 | //#define EXYNOS_TRACE_ON | |
51 | #include "Exynos_OSAL_Log.h" | |
52 | ||
53 | ||
54 | OMX_ERRORTYPE Exynos_OMX_UseBuffer( | |
55 | OMX_IN OMX_HANDLETYPE hComponent, | |
56 | OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr, | |
57 | OMX_IN OMX_U32 nPortIndex, | |
58 | OMX_IN OMX_PTR pAppPrivate, | |
59 | OMX_IN OMX_U32 nSizeBytes, | |
60 | OMX_IN OMX_U8 *pBuffer) | |
61 | { | |
62 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
63 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
64 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
65 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
66 | OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; | |
67 | OMX_U32 i = 0; | |
68 | ||
69 | FunctionIn(); | |
70 | ||
71 | if (hComponent == NULL) { | |
72 | ret = OMX_ErrorBadParameter; | |
73 | goto EXIT; | |
74 | } | |
75 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
76 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
77 | if (ret != OMX_ErrorNone) { | |
78 | goto EXIT; | |
79 | } | |
80 | ||
81 | if (pOMXComponent->pComponentPrivate == NULL) { | |
82 | ret = OMX_ErrorBadParameter; | |
83 | goto EXIT; | |
84 | } | |
85 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
86 | ||
87 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; | |
88 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { | |
89 | ret = OMX_ErrorBadPortIndex; | |
90 | goto EXIT; | |
91 | } | |
92 | if (pExynosPort->portState != OMX_StateIdle) { | |
93 | ret = OMX_ErrorIncorrectStateOperation; | |
94 | goto EXIT; | |
95 | } | |
96 | ||
97 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { | |
98 | ret = OMX_ErrorBadPortIndex; | |
99 | goto EXIT; | |
100 | } | |
101 | ||
102 | temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE)); | |
103 | if (temp_bufferHeader == NULL) { | |
104 | ret = OMX_ErrorInsufficientResources; | |
105 | goto EXIT; | |
106 | } | |
107 | Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE)); | |
108 | ||
109 | for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) { | |
110 | if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) { | |
111 | pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader; | |
112 | pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED); | |
113 | INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE); | |
114 | temp_bufferHeader->pBuffer = pBuffer; | |
115 | temp_bufferHeader->nAllocLen = nSizeBytes; | |
116 | temp_bufferHeader->pAppPrivate = pAppPrivate; | |
117 | if (nPortIndex == INPUT_PORT_INDEX) | |
118 | temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX; | |
119 | else | |
120 | temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX; | |
121 | ||
122 | pExynosPort->assignedBufferNum++; | |
123 | if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) { | |
124 | pExynosPort->portDefinition.bPopulated = OMX_TRUE; | |
125 | /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */ | |
126 | Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource); | |
127 | /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */ | |
128 | } | |
129 | *ppBufferHdr = temp_bufferHeader; | |
130 | ret = OMX_ErrorNone; | |
131 | goto EXIT; | |
132 | } | |
133 | } | |
134 | ||
135 | Exynos_OSAL_Free(temp_bufferHeader); | |
136 | ret = OMX_ErrorInsufficientResources; | |
137 | ||
138 | EXIT: | |
139 | FunctionOut(); | |
140 | ||
141 | return ret; | |
142 | } | |
143 | ||
144 | OMX_ERRORTYPE Exynos_OMX_AllocateBuffer( | |
145 | OMX_IN OMX_HANDLETYPE hComponent, | |
146 | OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer, | |
147 | OMX_IN OMX_U32 nPortIndex, | |
148 | OMX_IN OMX_PTR pAppPrivate, | |
149 | OMX_IN OMX_U32 nSizeBytes) | |
150 | { | |
151 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
152 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
153 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
154 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
155 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
156 | OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; | |
157 | OMX_U8 *temp_buffer = NULL; | |
158 | int temp_buffer_fd = -1; | |
159 | OMX_U32 i = 0; | |
026e5b24 | 160 | MEMORY_TYPE mem_type = SYSTEM_MEMORY; |
c6f4bc34 YK |
161 | |
162 | FunctionIn(); | |
163 | ||
164 | if (hComponent == NULL) { | |
165 | ret = OMX_ErrorBadParameter; | |
166 | goto EXIT; | |
167 | } | |
168 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
169 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
170 | if (ret != OMX_ErrorNone) { | |
171 | goto EXIT; | |
172 | } | |
173 | ||
174 | if (pOMXComponent->pComponentPrivate == NULL) { | |
175 | ret = OMX_ErrorBadParameter; | |
176 | goto EXIT; | |
177 | } | |
178 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
179 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
180 | ||
181 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; | |
182 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { | |
183 | ret = OMX_ErrorBadPortIndex; | |
184 | goto EXIT; | |
185 | } | |
186 | /* | |
187 | if (pExynosPort->portState != OMX_StateIdle ) { | |
188 | ret = OMX_ErrorIncorrectStateOperation; | |
189 | goto EXIT; | |
190 | } | |
191 | */ | |
192 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { | |
193 | ret = OMX_ErrorBadPortIndex; | |
194 | goto EXIT; | |
195 | } | |
196 | ||
026e5b24 TK |
197 | if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && |
198 | (nPortIndex == INPUT_PORT_INDEX)) { | |
c6f4bc34 | 199 | mem_type = SECURE_MEMORY; |
c31a957e TK |
200 | } else if (pExynosPort->bNeedContigMem == OMX_TRUE) { |
201 | mem_type = CONTIG_MEMORY; | |
026e5b24 TK |
202 | } else if ((nPortIndex == OUTPUT_PORT_INDEX) && |
203 | (pExynosPort->bufferProcessType & BUFFER_SHARE)) { | |
c6f4bc34 | 204 | mem_type = NORMAL_MEMORY; |
c6f4bc34 | 205 | } |
026e5b24 | 206 | |
c6f4bc34 YK |
207 | temp_buffer = Exynos_OSAL_SharedMemory_Alloc(pVideoDec->hSharedMemory, nSizeBytes, mem_type); |
208 | if (temp_buffer == NULL) { | |
209 | ret = OMX_ErrorInsufficientResources; | |
210 | goto EXIT; | |
211 | } | |
212 | temp_buffer_fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, temp_buffer); | |
213 | ||
214 | temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE)); | |
215 | if (temp_bufferHeader == NULL) { | |
216 | Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer); | |
217 | ret = OMX_ErrorInsufficientResources; | |
218 | goto EXIT; | |
219 | } | |
220 | Exynos_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE)); | |
221 | ||
222 | for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) { | |
223 | if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) { | |
224 | pExynosPort->extendBufferHeader[i].OMXBufferHeader = temp_bufferHeader; | |
225 | pExynosPort->extendBufferHeader[i].buf_fd[0] = temp_buffer_fd; | |
226 | pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ALLOCATED | HEADER_STATE_ALLOCATED); | |
227 | INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE); | |
228 | if (mem_type == SECURE_MEMORY) | |
229 | temp_bufferHeader->pBuffer = temp_buffer_fd; | |
230 | else | |
231 | temp_bufferHeader->pBuffer = temp_buffer; | |
232 | temp_bufferHeader->nAllocLen = nSizeBytes; | |
233 | temp_bufferHeader->pAppPrivate = pAppPrivate; | |
234 | if (nPortIndex == INPUT_PORT_INDEX) | |
235 | temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX; | |
236 | else | |
237 | temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX; | |
238 | pExynosPort->assignedBufferNum++; | |
239 | if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) { | |
240 | pExynosPort->portDefinition.bPopulated = OMX_TRUE; | |
241 | /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */ | |
242 | Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource); | |
243 | /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */ | |
244 | } | |
245 | *ppBuffer = temp_bufferHeader; | |
246 | ret = OMX_ErrorNone; | |
247 | goto EXIT; | |
248 | } | |
249 | } | |
250 | ||
251 | Exynos_OSAL_Free(temp_bufferHeader); | |
252 | Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, temp_buffer); | |
253 | ||
254 | ret = OMX_ErrorInsufficientResources; | |
255 | ||
256 | EXIT: | |
257 | FunctionOut(); | |
258 | ||
259 | return ret; | |
260 | } | |
261 | ||
262 | OMX_ERRORTYPE Exynos_OMX_FreeBuffer( | |
263 | OMX_IN OMX_HANDLETYPE hComponent, | |
264 | OMX_IN OMX_U32 nPortIndex, | |
265 | OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr) | |
266 | { | |
267 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
268 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
269 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
270 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
271 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
272 | OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; | |
273 | OMX_U8 *temp_buffer = NULL; | |
274 | OMX_U32 i = 0; | |
275 | ||
276 | FunctionIn(); | |
277 | ||
278 | if (hComponent == NULL) { | |
279 | ret = OMX_ErrorBadParameter; | |
280 | goto EXIT; | |
281 | } | |
282 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
283 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
284 | if (ret != OMX_ErrorNone) { | |
285 | goto EXIT; | |
286 | } | |
287 | ||
288 | if (pOMXComponent->pComponentPrivate == NULL) { | |
289 | ret = OMX_ErrorBadParameter; | |
290 | goto EXIT; | |
291 | } | |
292 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
293 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
294 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; | |
295 | ||
296 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { | |
297 | ret = OMX_ErrorBadPortIndex; | |
298 | goto EXIT; | |
299 | } | |
300 | ||
301 | if ((pExynosPort->portState != OMX_StateLoaded) && (pExynosPort->portState != OMX_StateInvalid)) { | |
302 | (*(pExynosComponent->pCallbacks->EventHandler)) (pOMXComponent, | |
303 | pExynosComponent->callbackData, | |
304 | (OMX_U32)OMX_EventError, | |
305 | (OMX_U32)OMX_ErrorPortUnpopulated, | |
306 | nPortIndex, NULL); | |
307 | } | |
308 | ||
309 | for (i = 0; i < /*pExynosPort->portDefinition.nBufferCountActual*/MAX_BUFFER_NUM; i++) { | |
310 | if (((pExynosPort->bufferStateAllocate[i] | BUFFER_STATE_FREE) != 0) && (pExynosPort->extendBufferHeader[i].OMXBufferHeader != NULL)) { | |
311 | if (pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer == pBufferHdr->pBuffer) { | |
312 | if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ALLOCATED) { | |
313 | if ((pVideoDec->bDRMPlayerMode == OMX_TRUE) && (nPortIndex == INPUT_PORT_INDEX)) { | |
314 | OMX_PTR mapBuffer = Exynos_OSAL_SharedMemory_IONToVirt(pVideoDec->hSharedMemory, (int)pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer); | |
315 | Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, mapBuffer); | |
316 | } else { | |
317 | Exynos_OSAL_SharedMemory_Free(pVideoDec->hSharedMemory, pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer); | |
318 | } | |
319 | pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer = NULL; | |
320 | pBufferHdr->pBuffer = NULL; | |
321 | } else if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) { | |
322 | ; /* None*/ | |
323 | } | |
324 | pExynosPort->assignedBufferNum--; | |
325 | if (pExynosPort->bufferStateAllocate[i] & HEADER_STATE_ALLOCATED) { | |
326 | Exynos_OSAL_Free(pExynosPort->extendBufferHeader[i].OMXBufferHeader); | |
327 | pExynosPort->extendBufferHeader[i].OMXBufferHeader = NULL; | |
328 | pBufferHdr = NULL; | |
329 | } | |
330 | pExynosPort->bufferStateAllocate[i] = BUFFER_STATE_FREE; | |
331 | ret = OMX_ErrorNone; | |
332 | goto EXIT; | |
333 | } | |
334 | } | |
335 | } | |
336 | ||
337 | EXIT: | |
338 | if (ret == OMX_ErrorNone) { | |
339 | if (pExynosPort->assignedBufferNum == 0) { | |
340 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pExynosPort->unloadedResource signal set"); | |
341 | /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */ | |
342 | Exynos_OSAL_SemaphorePost(pExynosPort->unloadedResource); | |
343 | /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */ | |
344 | pExynosPort->portDefinition.bPopulated = OMX_FALSE; | |
345 | } | |
346 | } | |
347 | ||
348 | FunctionOut(); | |
349 | ||
350 | return ret; | |
351 | } | |
352 | ||
353 | OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex) | |
354 | { | |
355 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
356 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
357 | OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; | |
358 | OMX_U8 *temp_buffer = NULL; | |
359 | OMX_U32 bufferSize = 0; | |
360 | OMX_PARAM_PORTDEFINITIONTYPE portDefinition; | |
361 | ||
362 | ret = OMX_ErrorTunnelingUnsupported; | |
363 | EXIT: | |
364 | return ret; | |
365 | } | |
366 | ||
367 | OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer(EXYNOS_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex) | |
368 | { | |
369 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
370 | EXYNOS_OMX_BASEPORT* pExynosPort = NULL; | |
371 | OMX_BUFFERHEADERTYPE* temp_bufferHeader = NULL; | |
372 | OMX_U8 *temp_buffer = NULL; | |
373 | OMX_U32 bufferSize = 0; | |
374 | ||
375 | ret = OMX_ErrorTunnelingUnsupported; | |
376 | EXIT: | |
377 | return ret; | |
378 | } | |
379 | ||
380 | OMX_ERRORTYPE Exynos_OMX_ComponentTunnelRequest( | |
381 | OMX_IN OMX_HANDLETYPE hComp, | |
382 | OMX_IN OMX_U32 nPort, | |
383 | OMX_IN OMX_HANDLETYPE hTunneledComp, | |
384 | OMX_IN OMX_U32 nTunneledPort, | |
385 | OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup) | |
386 | { | |
387 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
388 | ||
389 | ret = OMX_ErrorTunnelingUnsupported; | |
390 | EXIT: | |
391 | return ret; | |
392 | } | |
393 | ||
394 | OMX_ERRORTYPE Exynos_OMX_GetFlushBuffer(EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_DATABUFFER *pDataBuffer[]) | |
395 | { | |
396 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
397 | ||
398 | FunctionIn(); | |
399 | ||
400 | *pDataBuffer = NULL; | |
401 | ||
402 | if (pExynosPort->portWayType == WAY1_PORT) { | |
403 | *pDataBuffer = &pExynosPort->way.port1WayDataBuffer.dataBuffer; | |
404 | } else if (pExynosPort->portWayType == WAY2_PORT) { | |
405 | pDataBuffer[0] = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer); | |
406 | pDataBuffer[1] = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer); | |
407 | } | |
408 | ||
409 | EXIT: | |
410 | FunctionOut(); | |
411 | ||
412 | return ret; | |
413 | } | |
414 | ||
415 | OMX_ERRORTYPE Exynos_OMX_FlushPort(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 portIndex) | |
416 | { | |
417 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
418 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
405399e5 | 419 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; |
c6f4bc34 YK |
420 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
421 | OMX_BUFFERHEADERTYPE *bufferHeader = NULL; | |
422 | EXYNOS_OMX_DATABUFFER *pDataPortBuffer[2] = {NULL, NULL}; | |
423 | EXYNOS_OMX_MESSAGE *message = NULL; | |
424 | OMX_U32 flushNum = 0; | |
425 | OMX_S32 semValue = 0; | |
426 | int i = 0, maxBufferNum = 0; | |
427 | FunctionIn(); | |
428 | ||
429 | pExynosPort = &pExynosComponent->pExynosPort[portIndex]; | |
430 | ||
431 | while (Exynos_OSAL_GetElemNum(&pExynosPort->bufferQ) > 0) { | |
432 | Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &semValue); | |
433 | if (semValue == 0) | |
434 | Exynos_OSAL_SemaphorePost(pExynosComponent->pExynosPort[portIndex].bufferSemID); | |
435 | ||
436 | Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID); | |
437 | message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); | |
438 | if ((message != NULL) && (message->messageType != EXYNOS_OMX_CommandFakeBuffer)) { | |
439 | bufferHeader = (OMX_BUFFERHEADERTYPE *)message->pCmdData; | |
440 | bufferHeader->nFilledLen = 0; | |
441 | ||
442 | if (portIndex == OUTPUT_PORT_INDEX) { | |
443 | Exynos_OMX_OutputBufferReturn(pOMXComponent, bufferHeader); | |
444 | } else if (portIndex == INPUT_PORT_INDEX) { | |
445 | Exynos_OMX_InputBufferReturn(pOMXComponent, bufferHeader); | |
446 | } | |
447 | } | |
448 | Exynos_OSAL_Free(message); | |
449 | message = NULL; | |
450 | } | |
451 | ||
452 | Exynos_OMX_GetFlushBuffer(pExynosPort, pDataPortBuffer); | |
453 | if (portIndex == INPUT_PORT_INDEX) { | |
454 | if (pDataPortBuffer[0]->dataValid == OMX_TRUE) | |
7ccbc6ff | 455 | Exynos_InputBufferReturn(pOMXComponent, pDataPortBuffer[0]); |
c6f4bc34 | 456 | if (pDataPortBuffer[1]->dataValid == OMX_TRUE) |
7ccbc6ff | 457 | Exynos_InputBufferReturn(pOMXComponent, pDataPortBuffer[1]); |
c6f4bc34 YK |
458 | } else if (portIndex == OUTPUT_PORT_INDEX) { |
459 | if (pDataPortBuffer[0]->dataValid == OMX_TRUE) | |
7ccbc6ff | 460 | Exynos_OutputBufferReturn(pOMXComponent, pDataPortBuffer[0]); |
c6f4bc34 | 461 | if (pDataPortBuffer[1]->dataValid == OMX_TRUE) |
7ccbc6ff | 462 | Exynos_OutputBufferReturn(pOMXComponent, pDataPortBuffer[1]); |
c6f4bc34 YK |
463 | } |
464 | ||
465 | if (pExynosComponent->bMultiThreadProcess == OMX_TRUE) { | |
24ec2c82 | 466 | if (pExynosPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
467 | if (pExynosPort->processData.bufferHeader != NULL) { |
468 | if (portIndex == INPUT_PORT_INDEX) { | |
469 | Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader); | |
470 | } else if (portIndex == OUTPUT_PORT_INDEX) { | |
71180190 TK |
471 | #ifdef USE_ANB |
472 | if (pExynosPort->bIsANBEnabled == OMX_TRUE) | |
473 | Exynos_OSAL_UnlockANB(pExynosPort->processData.bufferHeader->pBuffer); | |
474 | #endif | |
c6f4bc34 YK |
475 | Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader); |
476 | } | |
477 | } | |
478 | Exynos_ResetCodecData(&pExynosPort->processData); | |
479 | ||
405399e5 TK |
480 | if (pVideoDec->bReconfigDPB == OMX_TRUE) |
481 | maxBufferNum = pVideoDec->nSavedDPBCnt; | |
482 | else | |
483 | maxBufferNum = pExynosPort->portDefinition.nBufferCountActual; | |
c6f4bc34 YK |
484 | for (i = 0; i < maxBufferNum; i++) { |
485 | if (pExynosPort->extendBufferHeader[i].bBufferInOMX == OMX_TRUE) { | |
486 | if (portIndex == OUTPUT_PORT_INDEX) { | |
71180190 TK |
487 | #ifdef USE_ANB |
488 | if (pExynosPort->bIsANBEnabled == OMX_TRUE) | |
489 | Exynos_OSAL_UnlockANB(pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer); | |
490 | #endif | |
c6f4bc34 YK |
491 | Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader); |
492 | } else if (portIndex == INPUT_PORT_INDEX) { | |
493 | Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->extendBufferHeader[i].OMXBufferHeader); | |
494 | } | |
495 | } | |
496 | } | |
497 | } | |
498 | } else { | |
499 | Exynos_ResetCodecData(&pExynosPort->processData); | |
500 | } | |
501 | ||
502 | while(1) { | |
503 | OMX_S32 cnt = 0; | |
504 | Exynos_OSAL_Get_SemaphoreCount(pExynosComponent->pExynosPort[portIndex].bufferSemID, &cnt); | |
505 | if (cnt <= 0) | |
506 | break; | |
507 | Exynos_OSAL_SemaphoreWait(pExynosComponent->pExynosPort[portIndex].bufferSemID); | |
508 | } | |
509 | Exynos_OSAL_ResetQueue(&pExynosPort->bufferQ); | |
510 | ||
511 | EXIT: | |
512 | FunctionOut(); | |
513 | ||
514 | return ret; | |
515 | } | |
516 | ||
517 | OMX_ERRORTYPE Exynos_OMX_BufferFlush(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent) | |
518 | { | |
519 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
520 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
521 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = NULL; | |
522 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
523 | EXYNOS_OMX_DATABUFFER *flushPortBuffer[2] = {NULL, NULL}; | |
524 | OMX_U32 i = 0, cnt = 0; | |
525 | ||
526 | FunctionIn(); | |
527 | ||
528 | if (pOMXComponent == NULL) { | |
529 | ret = OMX_ErrorBadParameter; | |
530 | goto EXIT; | |
531 | } | |
532 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
533 | if (ret != OMX_ErrorNone) { | |
534 | goto EXIT; | |
535 | } | |
536 | ||
537 | if (pOMXComponent->pComponentPrivate == NULL) { | |
538 | ret = OMX_ErrorBadParameter; | |
539 | goto EXIT; | |
540 | } | |
541 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
542 | pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
543 | ||
544 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush start, port:%d", nPortIndex); | |
545 | ||
546 | pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_TRUE; | |
547 | ||
548 | if (pExynosComponent->bMultiThreadProcess == OMX_FALSE) { | |
549 | Exynos_OSAL_SignalSet(pExynosComponent->pauseEvent); | |
550 | } else { | |
551 | Exynos_OSAL_SignalSet(pExynosComponent->pExynosPort[nPortIndex].pauseEvent); | |
552 | } | |
553 | ||
554 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; | |
555 | Exynos_OMX_GetFlushBuffer(pExynosPort, flushPortBuffer); | |
556 | ||
24ec2c82 | 557 | if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY) |
c6f4bc34 YK |
558 | Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID); |
559 | Exynos_OSAL_SemaphorePost(pExynosPort->bufferSemID); | |
560 | ||
561 | pVideoDec->exynos_codec_bufferProcessRun(pOMXComponent, nPortIndex); | |
562 | Exynos_OSAL_MutexLock(flushPortBuffer[0]->bufferMutex); | |
563 | pVideoDec->exynos_codec_stop(pOMXComponent, nPortIndex); | |
564 | Exynos_OSAL_MutexLock(flushPortBuffer[1]->bufferMutex); | |
565 | ret = Exynos_OMX_FlushPort(pOMXComponent, nPortIndex); | |
405399e5 TK |
566 | if (pVideoDec->bReconfigDPB == OMX_TRUE) |
567 | pVideoDec->exynos_codec_reconfigAllBuffers(pOMXComponent, nPortIndex); | |
568 | else if (pExynosComponent->pExynosPort[nPortIndex].bufferProcessType & BUFFER_COPY) | |
c6f4bc34 YK |
569 | pVideoDec->exynos_codec_enqueueAllBuffer(pOMXComponent, nPortIndex); |
570 | Exynos_ResetCodecData(&pExynosPort->processData); | |
571 | ||
572 | if (ret == OMX_ErrorNone) { | |
573 | if (nPortIndex == INPUT_PORT_INDEX) { | |
574 | pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE; | |
575 | pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE; | |
576 | Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); | |
577 | Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); | |
578 | pExynosComponent->getAllDelayBuffer = OMX_FALSE; | |
579 | pExynosComponent->bSaveFlagEOS = OMX_FALSE; | |
580 | pExynosComponent->reInputData = OMX_FALSE; | |
581 | } | |
582 | ||
583 | pExynosComponent->pExynosPort[nPortIndex].bIsPortFlushed = OMX_FALSE; | |
584 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush EventCmdComplete, port:%d", nPortIndex); | |
585 | if (bEvent == OMX_TRUE) | |
586 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, | |
587 | pExynosComponent->callbackData, | |
588 | OMX_EventCmdComplete, | |
589 | OMX_CommandFlush, nPortIndex, NULL); | |
590 | } | |
591 | Exynos_OSAL_MutexUnlock(flushPortBuffer[1]->bufferMutex); | |
592 | Exynos_OSAL_MutexUnlock(flushPortBuffer[0]->bufferMutex); | |
593 | ||
594 | EXIT: | |
595 | if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pExynosComponent != NULL)) { | |
596 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR,"%s : %d", __FUNCTION__, __LINE__); | |
597 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, | |
598 | pExynosComponent->callbackData, | |
599 | OMX_EventError, | |
600 | ret, 0, NULL); | |
601 | } | |
602 | ||
603 | FunctionOut(); | |
604 | ||
605 | return ret; | |
606 | } | |
607 | ||
7ccbc6ff TK |
608 | OMX_ERRORTYPE Exynos_InputBufferReturn( |
609 | OMX_COMPONENTTYPE *pOMXComponent, | |
610 | EXYNOS_OMX_DATABUFFER *pDataBuffer) | |
c6f4bc34 | 611 | { |
7ccbc6ff TK |
612 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
613 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
614 | EXYNOS_OMX_BASEPORT *pInputPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
615 | OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; | |
c6f4bc34 YK |
616 | |
617 | FunctionIn(); | |
618 | ||
7ccbc6ff | 619 | pBufferHdr = pDataBuffer->bufferHeader; |
c6f4bc34 | 620 | |
7ccbc6ff TK |
621 | if (pBufferHdr != NULL) { |
622 | if (pInputPort->markType.hMarkTargetComponent != NULL) { | |
623 | pBufferHdr->hMarkTargetComponent = pInputPort->markType.hMarkTargetComponent; | |
624 | pBufferHdr->pMarkData = pInputPort->markType.pMarkData; | |
625 | pInputPort->markType.hMarkTargetComponent = NULL; | |
626 | pInputPort->markType.pMarkData = NULL; | |
c6f4bc34 YK |
627 | } |
628 | ||
7ccbc6ff TK |
629 | if (pBufferHdr->hMarkTargetComponent != NULL) { |
630 | if (pBufferHdr->hMarkTargetComponent == pOMXComponent) { | |
c6f4bc34 YK |
631 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, |
632 | pExynosComponent->callbackData, | |
633 | OMX_EventMark, | |
7ccbc6ff | 634 | 0, 0, pBufferHdr->pMarkData); |
c6f4bc34 | 635 | } else { |
7ccbc6ff TK |
636 | pExynosComponent->propagateMarkType.hMarkTargetComponent = pBufferHdr->hMarkTargetComponent; |
637 | pExynosComponent->propagateMarkType.pMarkData = pBufferHdr->pMarkData; | |
c6f4bc34 YK |
638 | } |
639 | } | |
640 | ||
7ccbc6ff TK |
641 | pBufferHdr->nFilledLen = 0; |
642 | pBufferHdr->nOffset = 0; | |
643 | Exynos_OMX_InputBufferReturn(pOMXComponent, pBufferHdr); | |
c6f4bc34 YK |
644 | } |
645 | ||
646 | /* reset dataBuffer */ | |
7ccbc6ff | 647 | Exynos_ResetDataBuffer(pDataBuffer); |
c6f4bc34 YK |
648 | |
649 | EXIT: | |
650 | FunctionOut(); | |
651 | ||
652 | return ret; | |
653 | } | |
654 | ||
655 | OMX_ERRORTYPE Exynos_InputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent) | |
656 | { | |
657 | OMX_ERRORTYPE ret = OMX_ErrorUndefined; | |
658 | EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
659 | EXYNOS_OMX_MESSAGE *message = NULL; | |
660 | EXYNOS_OMX_DATABUFFER *inputUseBuffer = NULL; | |
661 | ||
662 | FunctionIn(); | |
663 | ||
664 | inputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer); | |
665 | ||
666 | if (pExynosComponent->currentState != OMX_StateExecuting) { | |
667 | ret = OMX_ErrorUndefined; | |
668 | goto EXIT; | |
669 | } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) && | |
670 | (!CHECK_PORT_BEING_FLUSHED(pExynosPort))) { | |
671 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); | |
672 | if (inputUseBuffer->dataValid != OMX_TRUE) { | |
673 | message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); | |
674 | if (message == NULL) { | |
675 | ret = OMX_ErrorUndefined; | |
676 | goto EXIT; | |
677 | } | |
678 | if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) { | |
679 | Exynos_OSAL_Free(message); | |
680 | ret = OMX_ErrorCodecFlush; | |
681 | goto EXIT; | |
682 | } | |
683 | ||
684 | inputUseBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData); | |
685 | inputUseBuffer->allocSize = inputUseBuffer->bufferHeader->nAllocLen; | |
686 | inputUseBuffer->dataLen = inputUseBuffer->bufferHeader->nFilledLen; | |
687 | inputUseBuffer->remainDataLen = inputUseBuffer->dataLen; | |
688 | inputUseBuffer->usedDataLen = 0; | |
689 | inputUseBuffer->dataValid = OMX_TRUE; | |
690 | inputUseBuffer->nFlags = inputUseBuffer->bufferHeader->nFlags; | |
691 | inputUseBuffer->timeStamp = inputUseBuffer->bufferHeader->nTimeStamp; | |
692 | ||
693 | Exynos_OSAL_Free(message); | |
694 | ||
695 | if (inputUseBuffer->allocSize <= inputUseBuffer->dataLen) | |
696 | Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "Input Buffer Full, Check input buffer size! allocSize:%d, dataLen:%d", inputUseBuffer->allocSize, inputUseBuffer->dataLen); | |
697 | } | |
698 | ret = OMX_ErrorNone; | |
699 | } | |
700 | EXIT: | |
701 | FunctionOut(); | |
702 | ||
703 | return ret; | |
704 | } | |
705 | ||
7ccbc6ff TK |
706 | OMX_ERRORTYPE Exynos_OutputBufferReturn( |
707 | OMX_COMPONENTTYPE *pOMXComponent, | |
708 | EXYNOS_OMX_DATABUFFER *pDataBuffer) | |
c6f4bc34 | 709 | { |
7ccbc6ff TK |
710 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
711 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
712 | OMX_BUFFERHEADERTYPE *pBufferHdr = pDataBuffer->bufferHeader; | |
c6f4bc34 YK |
713 | |
714 | FunctionIn(); | |
715 | ||
7ccbc6ff TK |
716 | if (pBufferHdr != NULL) { |
717 | pBufferHdr->nFilledLen = pDataBuffer->remainDataLen; | |
718 | pBufferHdr->nOffset = 0; | |
719 | pBufferHdr->nFlags = pDataBuffer->nFlags; | |
720 | pBufferHdr->nTimeStamp = pDataBuffer->timeStamp; | |
c6f4bc34 YK |
721 | |
722 | if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) { | |
7ccbc6ff TK |
723 | pBufferHdr->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent; |
724 | pBufferHdr->pMarkData = pExynosComponent->propagateMarkType.pMarkData; | |
c6f4bc34 | 725 | |
7ccbc6ff TK |
726 | pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL; |
727 | pExynosComponent->propagateMarkType.pMarkData = NULL; | |
c6f4bc34 YK |
728 | } |
729 | ||
7ccbc6ff TK |
730 | if ((pBufferHdr->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { |
731 | pBufferHdr->nFilledLen = 0; | |
c6f4bc34 YK |
732 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"event OMX_BUFFERFLAG_EOS!!!"); |
733 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, | |
734 | pExynosComponent->callbackData, | |
735 | OMX_EventBufferFlag, | |
736 | OUTPUT_PORT_INDEX, | |
7ccbc6ff | 737 | pBufferHdr->nFlags, NULL); |
c6f4bc34 | 738 | } |
7ccbc6ff | 739 | Exynos_OMX_OutputBufferReturn(pOMXComponent, pBufferHdr); |
c6f4bc34 YK |
740 | } |
741 | ||
742 | /* reset dataBuffer */ | |
7ccbc6ff | 743 | Exynos_ResetDataBuffer(pDataBuffer); |
c6f4bc34 YK |
744 | |
745 | EXIT: | |
746 | FunctionOut(); | |
747 | ||
748 | return ret; | |
749 | } | |
750 | ||
751 | OMX_ERRORTYPE Exynos_OutputBufferGetQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent) | |
752 | { | |
753 | OMX_ERRORTYPE ret = OMX_ErrorUndefined; | |
754 | EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
755 | EXYNOS_OMX_MESSAGE *message = NULL; | |
756 | EXYNOS_OMX_DATABUFFER *outputUseBuffer = NULL; | |
757 | ||
758 | FunctionIn(); | |
759 | ||
24ec2c82 | 760 | if (pExynosPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 | 761 | outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer); |
24ec2c82 | 762 | } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
763 | outputUseBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer); |
764 | } | |
765 | ||
766 | if (pExynosComponent->currentState != OMX_StateExecuting) { | |
767 | ret = OMX_ErrorUndefined; | |
768 | goto EXIT; | |
769 | } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) && | |
770 | (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){ | |
771 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); | |
772 | if (outputUseBuffer->dataValid != OMX_TRUE) { | |
773 | message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); | |
774 | if (message == NULL) { | |
775 | ret = OMX_ErrorUndefined; | |
776 | goto EXIT; | |
777 | } | |
778 | if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) { | |
779 | Exynos_OSAL_Free(message); | |
780 | ret = OMX_ErrorCodecFlush; | |
781 | goto EXIT; | |
782 | } | |
783 | ||
784 | outputUseBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData); | |
785 | outputUseBuffer->allocSize = outputUseBuffer->bufferHeader->nAllocLen; | |
786 | outputUseBuffer->dataLen = 0; //dataBuffer->bufferHeader->nFilledLen; | |
787 | outputUseBuffer->remainDataLen = outputUseBuffer->dataLen; | |
788 | outputUseBuffer->usedDataLen = 0; //dataBuffer->bufferHeader->nOffset; | |
789 | outputUseBuffer->dataValid = OMX_TRUE; | |
790 | /* dataBuffer->nFlags = dataBuffer->bufferHeader->nFlags; */ | |
791 | /* dataBuffer->nTimeStamp = dataBuffer->bufferHeader->nTimeStamp; */ | |
792 | /* | |
24ec2c82 | 793 | if (pExynosPort->bufferProcessType & BUFFER_SHARE) |
c6f4bc34 | 794 | outputUseBuffer->pPrivate = outputUseBuffer->bufferHeader->pOutputPortPrivate; |
24ec2c82 | 795 | else if (pExynosPort->bufferProcessType & BUFFER_COPY) { |
c6f4bc34 YK |
796 | pExynosPort->processData.dataBuffer = outputUseBuffer->bufferHeader->pBuffer; |
797 | pExynosPort->processData.allocSize = outputUseBuffer->bufferHeader->nAllocLen; | |
798 | } | |
799 | */ | |
800 | ||
801 | Exynos_OSAL_Free(message); | |
802 | } | |
803 | ret = OMX_ErrorNone; | |
804 | } | |
805 | EXIT: | |
806 | FunctionOut(); | |
807 | ||
808 | return ret; | |
809 | ||
810 | } | |
811 | ||
812 | OMX_BUFFERHEADERTYPE *Exynos_OutputBufferGetQueue_Direct(EXYNOS_OMX_BASECOMPONENT *pExynosComponent) | |
813 | { | |
814 | OMX_BUFFERHEADERTYPE *retBuffer = NULL; | |
815 | EXYNOS_OMX_BASEPORT *pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
816 | EXYNOS_OMX_MESSAGE *message = NULL; | |
817 | ||
818 | FunctionIn(); | |
819 | ||
820 | if (pExynosComponent->currentState != OMX_StateExecuting) { | |
821 | retBuffer = NULL; | |
822 | goto EXIT; | |
823 | } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) && | |
824 | (!CHECK_PORT_BEING_FLUSHED(pExynosPort))){ | |
825 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); | |
826 | ||
827 | message = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); | |
828 | if (message == NULL) { | |
829 | retBuffer = NULL; | |
830 | goto EXIT; | |
831 | } | |
832 | if (message->messageType == EXYNOS_OMX_CommandFakeBuffer) { | |
833 | Exynos_OSAL_Free(message); | |
834 | retBuffer = NULL; | |
835 | goto EXIT; | |
836 | } | |
837 | ||
838 | retBuffer = (OMX_BUFFERHEADERTYPE *)(message->pCmdData); | |
839 | Exynos_OSAL_Free(message); | |
840 | } | |
841 | ||
842 | EXIT: | |
843 | FunctionOut(); | |
844 | ||
845 | return retBuffer; | |
846 | } | |
847 | ||
848 | OMX_ERRORTYPE Exynos_CodecBufferEnQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR data) | |
849 | { | |
850 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
851 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
852 | ||
853 | FunctionIn(); | |
854 | ||
855 | pExynosPort= &pExynosComponent->pExynosPort[PortIndex]; | |
856 | ||
857 | if (data == NULL) { | |
858 | ret = OMX_ErrorInsufficientResources; | |
859 | goto EXIT; | |
860 | } | |
861 | ||
862 | ret = Exynos_OSAL_Queue(&pExynosPort->codecBufferQ, (void *)data); | |
863 | if (ret != 0) { | |
864 | ret = OMX_ErrorUndefined; | |
865 | goto EXIT; | |
866 | } | |
867 | Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID); | |
868 | ||
869 | ret = OMX_ErrorNone; | |
870 | ||
871 | EXIT: | |
872 | FunctionOut(); | |
873 | ||
874 | return ret; | |
875 | } | |
876 | ||
877 | OMX_ERRORTYPE Exynos_CodecBufferDeQueue(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex, OMX_PTR *data) | |
878 | { | |
879 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
880 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
881 | OMX_U32 tempData; | |
882 | ||
883 | FunctionIn(); | |
884 | ||
885 | pExynosPort = &pExynosComponent->pExynosPort[PortIndex]; | |
886 | Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID); | |
887 | tempData = (OMX_U32)Exynos_OSAL_Dequeue(&pExynosPort->codecBufferQ); | |
888 | if (tempData == NULL) { | |
889 | *data = NULL; | |
890 | ret = OMX_ErrorUndefined; | |
891 | goto EXIT; | |
892 | } | |
893 | *data = (OMX_PTR)tempData; | |
894 | ||
895 | ret = OMX_ErrorNone; | |
896 | ||
897 | EXIT: | |
898 | FunctionOut(); | |
899 | ||
900 | return ret; | |
901 | } | |
902 | ||
903 | OMX_ERRORTYPE Exynos_CodecBufferReset(EXYNOS_OMX_BASECOMPONENT *pExynosComponent, OMX_U32 PortIndex) | |
904 | { | |
905 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
906 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
907 | ||
908 | FunctionIn(); | |
909 | ||
910 | pExynosPort= &pExynosComponent->pExynosPort[PortIndex]; | |
911 | ||
912 | ret = Exynos_OSAL_ResetQueue(&pExynosPort->codecBufferQ); | |
913 | if (ret != 0) { | |
914 | ret = OMX_ErrorUndefined; | |
915 | goto EXIT; | |
916 | } | |
917 | while (1) { | |
918 | int cnt = 0; | |
919 | Exynos_OSAL_Get_SemaphoreCount(pExynosPort->codecSemID, &cnt); | |
920 | if (cnt > 0) | |
921 | Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID); | |
922 | else | |
923 | break; | |
924 | } | |
925 | ret = OMX_ErrorNone; | |
926 | ||
927 | EXIT: | |
928 | FunctionOut(); | |
929 | ||
930 | return ret; | |
931 | } | |
932 | ||
933 | OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetParameter( | |
934 | OMX_IN OMX_HANDLETYPE hComponent, | |
935 | OMX_IN OMX_INDEXTYPE nParamIndex, | |
936 | OMX_INOUT OMX_PTR ComponentParameterStructure) | |
937 | { | |
938 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
939 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
940 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
941 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
942 | ||
943 | FunctionIn(); | |
944 | ||
945 | if (hComponent == NULL) { | |
946 | ret = OMX_ErrorBadParameter; | |
947 | goto EXIT; | |
948 | } | |
949 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
950 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
951 | if (ret != OMX_ErrorNone) { | |
952 | goto EXIT; | |
953 | } | |
954 | ||
955 | if (pOMXComponent->pComponentPrivate == NULL) { | |
956 | ret = OMX_ErrorBadParameter; | |
957 | goto EXIT; | |
958 | } | |
959 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
960 | ||
961 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
962 | ret = OMX_ErrorInvalidState; | |
963 | goto EXIT; | |
964 | } | |
965 | ||
966 | if (ComponentParameterStructure == NULL) { | |
967 | ret = OMX_ErrorBadParameter; | |
968 | goto EXIT; | |
969 | } | |
970 | ||
971 | switch (nParamIndex) { | |
972 | case OMX_IndexParamVideoInit: | |
973 | { | |
974 | OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure; | |
975 | ret = Exynos_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE)); | |
976 | if (ret != OMX_ErrorNone) { | |
977 | goto EXIT; | |
978 | } | |
979 | ||
980 | portParam->nPorts = pExynosComponent->portParam.nPorts; | |
981 | portParam->nStartPortNumber = pExynosComponent->portParam.nStartPortNumber; | |
982 | ret = OMX_ErrorNone; | |
983 | } | |
984 | break; | |
985 | case OMX_IndexParamVideoPortFormat: | |
986 | { | |
987 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure; | |
988 | OMX_U32 portIndex = portFormat->nPortIndex; | |
989 | OMX_U32 index = portFormat->nIndex; | |
990 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
991 | OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL; | |
992 | OMX_U32 supportFormatNum = 0; /* supportFormatNum = N-1 */ | |
993 | ||
994 | ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); | |
995 | if (ret != OMX_ErrorNone) { | |
996 | goto EXIT; | |
997 | } | |
998 | ||
999 | if ((portIndex >= pExynosComponent->portParam.nPorts)) { | |
1000 | ret = OMX_ErrorBadPortIndex; | |
1001 | goto EXIT; | |
1002 | } | |
1003 | ||
1004 | ||
1005 | if (portIndex == INPUT_PORT_INDEX) { | |
1006 | supportFormatNum = INPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1; | |
1007 | if (index > supportFormatNum) { | |
1008 | ret = OMX_ErrorNoMore; | |
1009 | goto EXIT; | |
1010 | } | |
1011 | ||
1012 | pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; | |
1013 | portDefinition = &pExynosPort->portDefinition; | |
1014 | ||
1015 | portFormat->eCompressionFormat = portDefinition->format.video.eCompressionFormat; | |
1016 | portFormat->eColorFormat = portDefinition->format.video.eColorFormat; | |
1017 | portFormat->xFramerate = portDefinition->format.video.xFramerate; | |
1018 | } else if (portIndex == OUTPUT_PORT_INDEX) { | |
1019 | pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
1020 | portDefinition = &pExynosPort->portDefinition; | |
1021 | ||
1022 | switch (index) { | |
1023 | case supportFormat_0: | |
1024 | portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; | |
1025 | portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar; | |
1026 | portFormat->xFramerate = portDefinition->format.video.xFramerate; | |
1027 | break; | |
1028 | case supportFormat_1: | |
1029 | portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; | |
1030 | portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; | |
1031 | portFormat->xFramerate = portDefinition->format.video.xFramerate; | |
1032 | break; | |
1033 | case supportFormat_2: | |
c6f4bc34 YK |
1034 | portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; |
1035 | portFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12Tiled; | |
1036 | portFormat->xFramerate = portDefinition->format.video.xFramerate; | |
1037 | break; | |
1038 | default: | |
1039 | if (index > supportFormat_0) { | |
1040 | ret = OMX_ErrorNoMore; | |
1041 | goto EXIT; | |
1042 | } | |
1043 | break; | |
1044 | } | |
1045 | } | |
1046 | ret = OMX_ErrorNone; | |
1047 | } | |
1048 | break; | |
1049 | #ifdef USE_ANB | |
1050 | case OMX_IndexParamGetAndroidNativeBuffer: | |
1051 | { | |
1052 | ret = Exynos_OSAL_GetANBParameter(hComponent, nParamIndex, ComponentParameterStructure); | |
1053 | } | |
1054 | break; | |
1055 | case OMX_IndexParamPortDefinition: | |
1056 | { | |
1057 | OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; | |
e4e150b8 HK |
1058 | OMX_U32 portIndex = portDefinition->nPortIndex; |
1059 | EXYNOS_OMX_BASEPORT *pExynosPort; | |
c6f4bc34 YK |
1060 | |
1061 | ret = Exynos_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure); | |
1062 | if (ret != OMX_ErrorNone) { | |
1063 | goto EXIT; | |
1064 | } | |
1065 | ||
1066 | /* at this point, GetParameter has done all the verification, we | |
1067 | * just dereference things directly here | |
1068 | */ | |
1069 | pExynosPort = &pExynosComponent->pExynosPort[portIndex]; | |
1070 | if (pExynosPort->bIsANBEnabled == OMX_TRUE) { | |
1071 | portDefinition->format.video.eColorFormat = | |
1072 | (OMX_COLOR_FORMATTYPE)Exynos_OSAL_OMX2HalPixelFormat(portDefinition->format.video.eColorFormat); | |
1073 | } | |
1074 | } | |
1075 | break; | |
1076 | #endif | |
c31a957e TK |
1077 | case OMX_IndexVendorNeedContigMemory: |
1078 | { | |
1079 | EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *pPortMemType = (EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *)ComponentParameterStructure; | |
1080 | OMX_U32 nPortIndex = pPortMemType->nPortIndex; | |
1081 | EXYNOS_OMX_BASEPORT *pExynosPort; | |
1082 | ||
1083 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { | |
1084 | ret = OMX_ErrorBadPortIndex; | |
1085 | goto EXIT; | |
1086 | } | |
1087 | ||
1088 | ret = Exynos_OMX_Check_SizeVersion(pPortMemType, sizeof(EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE)); | |
1089 | if (ret != OMX_ErrorNone) | |
1090 | goto EXIT; | |
1091 | ||
1092 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; | |
1093 | ||
1094 | pPortMemType->bNeedContigMem = pExynosPort->bNeedContigMem; | |
1095 | } | |
1096 | break; | |
c6f4bc34 YK |
1097 | default: |
1098 | { | |
1099 | ret = Exynos_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure); | |
1100 | } | |
1101 | break; | |
1102 | } | |
1103 | ||
1104 | EXIT: | |
1105 | FunctionOut(); | |
1106 | ||
1107 | return ret; | |
1108 | } | |
1109 | OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetParameter( | |
1110 | OMX_IN OMX_HANDLETYPE hComponent, | |
1111 | OMX_IN OMX_INDEXTYPE nIndex, | |
1112 | OMX_IN OMX_PTR ComponentParameterStructure) | |
1113 | { | |
1114 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1115 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1116 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1117 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
1118 | ||
1119 | FunctionIn(); | |
1120 | ||
1121 | if (hComponent == NULL) { | |
1122 | ret = OMX_ErrorBadParameter; | |
1123 | goto EXIT; | |
1124 | } | |
1125 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1126 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1127 | if (ret != OMX_ErrorNone) { | |
1128 | goto EXIT; | |
1129 | } | |
1130 | ||
1131 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1132 | ret = OMX_ErrorBadParameter; | |
1133 | goto EXIT; | |
1134 | } | |
1135 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1136 | ||
1137 | if (pExynosComponent->currentState == OMX_StateInvalid ) { | |
1138 | ret = OMX_ErrorInvalidState; | |
1139 | goto EXIT; | |
1140 | } | |
1141 | ||
1142 | if (ComponentParameterStructure == NULL) { | |
1143 | ret = OMX_ErrorBadParameter; | |
1144 | goto EXIT; | |
1145 | } | |
1146 | ||
1147 | switch (nIndex) { | |
1148 | case OMX_IndexParamVideoPortFormat: | |
1149 | { | |
1150 | OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure; | |
1151 | OMX_U32 portIndex = portFormat->nPortIndex; | |
1152 | OMX_U32 index = portFormat->nIndex; | |
1153 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; | |
1154 | OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL; | |
1155 | OMX_U32 supportFormatNum = 0; | |
1156 | ||
1157 | ret = Exynos_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); | |
1158 | if (ret != OMX_ErrorNone) { | |
1159 | goto EXIT; | |
1160 | } | |
1161 | ||
1162 | if ((portIndex >= pExynosComponent->portParam.nPorts)) { | |
1163 | ret = OMX_ErrorBadPortIndex; | |
1164 | goto EXIT; | |
1165 | } else { | |
1166 | pExynosPort = &pExynosComponent->pExynosPort[portIndex]; | |
1167 | portDefinition = &pExynosPort->portDefinition; | |
1168 | ||
1169 | portDefinition->format.video.eColorFormat = portFormat->eColorFormat; | |
1170 | portDefinition->format.video.eCompressionFormat = portFormat->eCompressionFormat; | |
1171 | portDefinition->format.video.xFramerate = portFormat->xFramerate; | |
1172 | } | |
1173 | } | |
1174 | break; | |
1175 | case OMX_IndexParamPortDefinition: | |
1176 | { | |
1177 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; | |
e4e150b8 HK |
1178 | OMX_U32 portIndex = pPortDefinition->nPortIndex; |
1179 | EXYNOS_OMX_BASEPORT *pExynosPort; | |
c6f4bc34 YK |
1180 | OMX_U32 width, height, size; |
1181 | OMX_U32 realWidth, realHeight; | |
1182 | ||
1183 | if (portIndex >= pExynosComponent->portParam.nPorts) { | |
1184 | ret = OMX_ErrorBadPortIndex; | |
1185 | goto EXIT; | |
1186 | } | |
1187 | ret = Exynos_OMX_Check_SizeVersion(pPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); | |
1188 | if (ret != OMX_ErrorNone) { | |
1189 | goto EXIT; | |
1190 | } | |
1191 | ||
1192 | pExynosPort = &pExynosComponent->pExynosPort[portIndex]; | |
1193 | ||
1194 | if ((pExynosComponent->currentState != OMX_StateLoaded) && (pExynosComponent->currentState != OMX_StateWaitForResources)) { | |
1195 | if (pExynosPort->portDefinition.bEnabled == OMX_TRUE) { | |
1196 | ret = OMX_ErrorIncorrectStateOperation; | |
1197 | goto EXIT; | |
1198 | } | |
1199 | } | |
1200 | if (pPortDefinition->nBufferCountActual < pExynosPort->portDefinition.nBufferCountMin) { | |
1201 | ret = OMX_ErrorBadParameter; | |
1202 | goto EXIT; | |
1203 | } | |
1204 | ||
1205 | Exynos_OSAL_Memcpy(&pExynosPort->portDefinition, pPortDefinition, pPortDefinition->nSize); | |
1206 | ||
1207 | #ifdef USE_ANB // Modified by Google engineer | |
1208 | /* should not affect the format since in ANB case, the caller | |
1209 | * is providing us a HAL format */ | |
1210 | if (pExynosPort->bIsANBEnabled == OMX_TRUE) { | |
1211 | pExynosPort->portDefinition.format.video.eColorFormat = | |
1212 | Exynos_OSAL_Hal2OMXPixelFormat(pExynosPort->portDefinition.format.video.eColorFormat); | |
1213 | } | |
1214 | #endif | |
1215 | ||
1216 | realWidth = pExynosPort->portDefinition.format.video.nFrameWidth; | |
1217 | realHeight = pExynosPort->portDefinition.format.video.nFrameHeight; | |
1218 | width = ((realWidth + 15) & (~15)); | |
1219 | height = ((realHeight + 15) & (~15)); | |
1220 | size = (width * height * 3) / 2; | |
1221 | pExynosPort->portDefinition.format.video.nStride = width; | |
1222 | pExynosPort->portDefinition.format.video.nSliceHeight = height; | |
1223 | pExynosPort->portDefinition.nBufferSize = (size > pExynosPort->portDefinition.nBufferSize) ? size : pExynosPort->portDefinition.nBufferSize; | |
1224 | ||
1225 | if (portIndex == INPUT_PORT_INDEX) { | |
1226 | EXYNOS_OMX_BASEPORT *pExynosOutputPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; | |
1227 | pExynosOutputPort->portDefinition.format.video.nFrameWidth = pExynosPort->portDefinition.format.video.nFrameWidth; | |
1228 | pExynosOutputPort->portDefinition.format.video.nFrameHeight = pExynosPort->portDefinition.format.video.nFrameHeight; | |
1229 | pExynosOutputPort->portDefinition.format.video.nStride = width; | |
1230 | pExynosOutputPort->portDefinition.format.video.nSliceHeight = height; | |
1231 | ||
1232 | switch (pExynosOutputPort->portDefinition.format.video.eColorFormat) { | |
1233 | case OMX_COLOR_FormatYUV420Planar: | |
1234 | case OMX_COLOR_FormatYUV420SemiPlanar: | |
c6f4bc34 YK |
1235 | pExynosOutputPort->portDefinition.nBufferSize = (width * height * 3) / 2; |
1236 | break; | |
1237 | case OMX_SEC_COLOR_FormatNV12Tiled: | |
1238 | pExynosOutputPort->portDefinition.nBufferSize = | |
1239 | calc_plane(pExynosPort->portDefinition.format.video.nFrameWidth, pExynosOutputPort->portDefinition.format.video.nFrameHeight) + | |
1240 | calc_plane(pExynosPort->portDefinition.format.video.nFrameWidth, pExynosOutputPort->portDefinition.format.video.nFrameHeight >> 1); | |
1241 | break; | |
1242 | default: | |
1243 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Color format is not support!! use default YUV size!!"); | |
1244 | ret = OMX_ErrorUnsupportedSetting; | |
1245 | break; | |
1246 | } | |
1247 | ||
24ec2c82 | 1248 | if (pExynosOutputPort->bufferProcessType & BUFFER_SHARE) { |
c6f4bc34 YK |
1249 | pExynosOutputPort->portDefinition.nBufferSize = |
1250 | calc_plane(pExynosPort->portDefinition.format.video.nFrameWidth, pExynosOutputPort->portDefinition.format.video.nFrameHeight) + | |
1251 | calc_plane(pExynosPort->portDefinition.format.video.nFrameWidth, pExynosOutputPort->portDefinition.format.video.nFrameHeight >> 1); | |
1252 | } | |
1253 | } | |
1254 | } | |
1255 | break; | |
1256 | #ifdef USE_ANB | |
1257 | case OMX_IndexParamEnableAndroidBuffers: | |
1258 | case OMX_IndexParamUseAndroidNativeBuffer: | |
1259 | { | |
1260 | ret = Exynos_OSAL_SetANBParameter(hComponent, nIndex, ComponentParameterStructure); | |
1261 | } | |
1262 | break; | |
1263 | #endif | |
c31a957e TK |
1264 | case OMX_IndexVendorNeedContigMemory: |
1265 | { | |
1266 | EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *pPortMemType = (EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *)ComponentParameterStructure; | |
1267 | OMX_U32 nPortIndex = pPortMemType->nPortIndex; | |
1268 | EXYNOS_OMX_BASEPORT *pExynosPort; | |
1269 | ||
1270 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { | |
1271 | ret = OMX_ErrorBadPortIndex; | |
1272 | goto EXIT; | |
1273 | } | |
1274 | ||
1275 | ret = Exynos_OMX_Check_SizeVersion(pPortMemType, sizeof(EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE)); | |
1276 | if (ret != OMX_ErrorNone) | |
1277 | goto EXIT; | |
1278 | ||
1279 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; | |
1280 | ||
1281 | if ((pExynosComponent->currentState != OMX_StateLoaded) && (pExynosComponent->currentState != OMX_StateWaitForResources)) { | |
1282 | if (pExynosPort->portDefinition.bEnabled == OMX_TRUE) { | |
1283 | ret = OMX_ErrorIncorrectStateOperation; | |
1284 | goto EXIT; | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | pExynosPort->bNeedContigMem = pPortMemType->bNeedContigMem; | |
1289 | } | |
1290 | break; | |
c6f4bc34 YK |
1291 | default: |
1292 | { | |
1293 | ret = Exynos_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure); | |
1294 | } | |
1295 | break; | |
1296 | } | |
1297 | ||
1298 | EXIT: | |
1299 | FunctionOut(); | |
1300 | ||
1301 | return ret; | |
1302 | } | |
1303 | ||
1304 | OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetConfig( | |
1305 | OMX_HANDLETYPE hComponent, | |
1306 | OMX_INDEXTYPE nIndex, | |
1307 | OMX_PTR pComponentConfigStructure) | |
1308 | { | |
1309 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1310 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1311 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1312 | ||
1313 | FunctionIn(); | |
1314 | ||
1315 | if (hComponent == NULL) { | |
1316 | ret = OMX_ErrorBadParameter; | |
1317 | goto EXIT; | |
1318 | } | |
1319 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1320 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1321 | if (ret != OMX_ErrorNone) { | |
1322 | goto EXIT; | |
1323 | } | |
1324 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1325 | ret = OMX_ErrorBadParameter; | |
1326 | goto EXIT; | |
1327 | } | |
1328 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1329 | if (pComponentConfigStructure == NULL) { | |
1330 | ret = OMX_ErrorBadParameter; | |
1331 | goto EXIT; | |
1332 | } | |
1333 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1334 | ret = OMX_ErrorInvalidState; | |
1335 | goto EXIT; | |
1336 | } | |
1337 | ||
1338 | switch (nIndex) { | |
ea1234c8 TK |
1339 | case OMX_IndexVendorGetBufferFD: |
1340 | { | |
1341 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1342 | EXYNOS_OMX_VIDEO_CONFIG_BUFFERINFO *pBufferInfo = (EXYNOS_OMX_VIDEO_CONFIG_BUFFERINFO *)pComponentConfigStructure; | |
1343 | ||
1344 | ret = Exynos_OMX_Check_SizeVersion(pBufferInfo, sizeof(EXYNOS_OMX_VIDEO_CONFIG_BUFFERINFO)); | |
1345 | if (ret != OMX_ErrorNone) | |
1346 | goto EXIT; | |
1347 | ||
1348 | pBufferInfo->fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoDec->hSharedMemory, pBufferInfo->pVirAddr); | |
1349 | } | |
1350 | break; | |
c6f4bc34 YK |
1351 | default: |
1352 | ret = Exynos_OMX_GetConfig(hComponent, nIndex, pComponentConfigStructure); | |
1353 | break; | |
1354 | } | |
1355 | ||
1356 | EXIT: | |
1357 | FunctionOut(); | |
1358 | ||
1359 | return ret; | |
1360 | } | |
1361 | ||
1362 | OMX_ERRORTYPE Exynos_OMX_VideoDecodeSetConfig( | |
1363 | OMX_HANDLETYPE hComponent, | |
1364 | OMX_INDEXTYPE nIndex, | |
1365 | OMX_PTR pComponentConfigStructure) | |
1366 | { | |
1367 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1368 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1369 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1370 | ||
1371 | FunctionIn(); | |
1372 | ||
1373 | if (hComponent == NULL) { | |
1374 | ret = OMX_ErrorBadParameter; | |
1375 | goto EXIT; | |
1376 | } | |
1377 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1378 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1379 | if (ret != OMX_ErrorNone) { | |
1380 | goto EXIT; | |
1381 | } | |
1382 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1383 | ret = OMX_ErrorBadParameter; | |
1384 | goto EXIT; | |
1385 | } | |
1386 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1387 | if (pComponentConfigStructure == NULL) { | |
1388 | ret = OMX_ErrorBadParameter; | |
1389 | goto EXIT; | |
1390 | } | |
1391 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1392 | ret = OMX_ErrorInvalidState; | |
1393 | goto EXIT; | |
1394 | } | |
1395 | ||
1396 | switch (nIndex) { | |
1397 | case OMX_IndexVendorThumbnailMode: | |
1398 | { | |
1399 | EXYNOS_OMX_VIDEODEC_COMPONENT *pVideoDec = (EXYNOS_OMX_VIDEODEC_COMPONENT *)pExynosComponent->hComponentHandle; | |
1400 | pVideoDec->bThumbnailMode = *((OMX_BOOL *)pComponentConfigStructure); | |
1401 | ||
1402 | ret = OMX_ErrorNone; | |
1403 | } | |
1404 | break; | |
1405 | default: | |
1406 | ret = Exynos_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure); | |
1407 | break; | |
1408 | } | |
1409 | ||
1410 | EXIT: | |
1411 | FunctionOut(); | |
1412 | ||
1413 | return ret; | |
1414 | } | |
1415 | ||
1416 | OMX_ERRORTYPE Exynos_OMX_VideoDecodeGetExtensionIndex( | |
1417 | OMX_IN OMX_HANDLETYPE hComponent, | |
1418 | OMX_IN OMX_STRING cParameterName, | |
1419 | OMX_OUT OMX_INDEXTYPE *pIndexType) | |
1420 | { | |
1421 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1422 | OMX_COMPONENTTYPE *pOMXComponent = NULL; | |
1423 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; | |
1424 | ||
1425 | FunctionIn(); | |
1426 | ||
1427 | if (hComponent == NULL) { | |
1428 | ret = OMX_ErrorBadParameter; | |
1429 | goto EXIT; | |
1430 | } | |
1431 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; | |
1432 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); | |
1433 | if (ret != OMX_ErrorNone) { | |
1434 | goto EXIT; | |
1435 | } | |
1436 | ||
1437 | if (pOMXComponent->pComponentPrivate == NULL) { | |
1438 | ret = OMX_ErrorBadParameter; | |
1439 | goto EXIT; | |
1440 | } | |
1441 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; | |
1442 | ||
1443 | if ((cParameterName == NULL) || (pIndexType == NULL)) { | |
1444 | ret = OMX_ErrorBadParameter; | |
1445 | goto EXIT; | |
1446 | } | |
1447 | if (pExynosComponent->currentState == OMX_StateInvalid) { | |
1448 | ret = OMX_ErrorInvalidState; | |
1449 | goto EXIT; | |
1450 | } | |
1451 | ||
c31a957e TK |
1452 | if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_NEED_CONTIG_MEMORY) == 0) { |
1453 | *pIndexType = (OMX_INDEXTYPE) OMX_IndexVendorNeedContigMemory; | |
1454 | ret = OMX_ErrorNone; | |
1455 | goto EXIT; | |
ea1234c8 TK |
1456 | } else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_CONFIG_GET_BUFFER_FD) == 0) { |
1457 | *pIndexType = (OMX_INDEXTYPE) OMX_IndexVendorGetBufferFD; | |
1458 | ret = OMX_ErrorNone; | |
1459 | goto EXIT; | |
c31a957e TK |
1460 | } |
1461 | ||
c6f4bc34 YK |
1462 | #ifdef USE_ANB |
1463 | if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_ENABLE_ANB) == 0) | |
1464 | *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamEnableAndroidBuffers; | |
1465 | else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_GET_ANB) == 0) | |
1466 | *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamGetAndroidNativeBuffer; | |
1467 | else if (Exynos_OSAL_Strcmp(cParameterName, EXYNOS_INDEX_PARAM_USE_ANB) == 0) | |
1468 | *pIndexType = (OMX_INDEXTYPE) OMX_IndexParamUseAndroidNativeBuffer; | |
1469 | else | |
1470 | ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType); | |
1471 | #else | |
1472 | ret = Exynos_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType); | |
1473 | #endif | |
1474 | ||
1475 | EXIT: | |
1476 | FunctionOut(); | |
1477 | ||
1478 | return ret; | |
1479 | } | |
1480 | ||
1481 | #ifdef USE_ANB | |
1482 | OMX_ERRORTYPE Exynos_Shared_ANBBufferToData(EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_DATA *pData, EXYNOS_OMX_BASEPORT *pExynosPort, EXYNOS_OMX_PLANE nPlane) | |
1483 | { | |
1484 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1485 | OMX_U32 width, height; | |
1486 | // void *pPhys[MAX_BUFFER_PLANE]; | |
1487 | ExynosVideoPlane planes[MAX_BUFFER_PLANE]; | |
1488 | ||
1489 | memset(planes, 0, sizeof(planes)); | |
1490 | ||
1491 | if (pExynosPort->bIsANBEnabled == OMX_TRUE) { | |
1492 | OMX_U32 stride; | |
1493 | ||
1494 | width = pExynosPort->portDefinition.format.video.nFrameWidth; | |
1495 | height = pExynosPort->portDefinition.format.video.nFrameHeight; | |
1496 | if ((pUseBuffer->bufferHeader != NULL) && (pUseBuffer->bufferHeader->pBuffer != NULL)) { | |
1497 | Exynos_OSAL_LockANB(pUseBuffer->bufferHeader->pBuffer, width, height, pExynosPort->portDefinition.format.video.eColorFormat, &stride, planes); | |
1498 | pUseBuffer->dataLen = sizeof(void *); | |
1499 | } else { | |
1500 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__); | |
1501 | ret = OMX_ErrorBadParameter; | |
1502 | goto EXIT; | |
1503 | } | |
1504 | } else { | |
1505 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__); | |
1506 | ret = OMX_ErrorBadParameter; | |
1507 | goto EXIT; | |
1508 | } | |
1509 | ||
1510 | if (nPlane == TWO_PLANE) { | |
1511 | /* Case of Shared Buffer, Only support two PlaneBuffer */ | |
1512 | pData->buffer.multiPlaneBuffer.dataBuffer[0] = planes[0].addr; | |
c6f4bc34 | 1513 | pData->buffer.multiPlaneBuffer.dataBuffer[1] = planes[1].addr; |
faa0e22c SKR |
1514 | #ifdef USE_DMA_BUF |
1515 | pData->buffer.multiPlaneBuffer.fd[0] = planes[0].fd; | |
c6f4bc34 | 1516 | pData->buffer.multiPlaneBuffer.fd[1] = planes[1].fd; |
faa0e22c | 1517 | #endif |
c6f4bc34 YK |
1518 | } else { |
1519 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Can not support plane"); | |
1520 | ret = OMX_ErrorNotImplemented; | |
1521 | goto EXIT; | |
1522 | } | |
1523 | ||
1524 | pData->allocSize = pUseBuffer->allocSize; | |
1525 | pData->dataLen = pUseBuffer->dataLen; | |
1526 | pData->usedDataLen = pUseBuffer->usedDataLen; | |
1527 | pData->remainDataLen = pUseBuffer->remainDataLen; | |
1528 | pData->timeStamp = pUseBuffer->timeStamp; | |
1529 | pData->nFlags = pUseBuffer->nFlags; | |
1530 | pData->pPrivate = pUseBuffer->pPrivate; | |
1531 | pData->bufferHeader = pUseBuffer->bufferHeader; | |
1532 | ||
1533 | EXIT: | |
1534 | return ret; | |
1535 | } | |
1536 | ||
1537 | OMX_ERRORTYPE Exynos_Shared_DataToANBBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, EXYNOS_OMX_BASEPORT *pExynosPort) | |
1538 | { | |
1539 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1540 | ||
1541 | pUseBuffer->bufferHeader = pData->bufferHeader; | |
1542 | pUseBuffer->allocSize = pData->allocSize; | |
1543 | pUseBuffer->dataLen = pData->dataLen; | |
1544 | pUseBuffer->usedDataLen = pData->usedDataLen; | |
1545 | pUseBuffer->remainDataLen = pData->remainDataLen; | |
1546 | pUseBuffer->timeStamp = pData->timeStamp; | |
1547 | pUseBuffer->nFlags = pData->nFlags; | |
1548 | pUseBuffer->pPrivate = pData->pPrivate; | |
1549 | ||
1550 | if ((pUseBuffer->bufferHeader == NULL) || | |
1551 | (pUseBuffer->bufferHeader->pBuffer == NULL)) { | |
1552 | ret = OMX_ErrorUndefined; | |
1553 | goto EXIT; | |
1554 | } | |
1555 | ||
1556 | if (pExynosPort->bIsANBEnabled == OMX_TRUE) { | |
1557 | Exynos_OSAL_UnlockANB(pUseBuffer->bufferHeader->pBuffer); | |
1558 | } else { | |
1559 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s : %d", __FUNCTION__, __LINE__); | |
1560 | ret = OMX_ErrorBadParameter; | |
1561 | goto EXIT; | |
1562 | } | |
1563 | ||
1564 | EXIT: | |
1565 | return ret; | |
1566 | } | |
1567 | #endif | |
323488ff SK |
1568 | |
1569 | OMX_ERRORTYPE Exynos_Shared_DataToBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer) | |
1570 | { | |
1571 | OMX_ERRORTYPE ret = OMX_ErrorNone; | |
1572 | ||
1573 | pUseBuffer->bufferHeader = pData->bufferHeader; | |
1574 | pUseBuffer->allocSize = pData->allocSize; | |
1575 | pUseBuffer->dataLen = pData->dataLen; | |
1576 | pUseBuffer->usedDataLen = pData->usedDataLen; | |
1577 | pUseBuffer->remainDataLen = pData->remainDataLen; | |
1578 | pUseBuffer->timeStamp = pData->timeStamp; | |
1579 | pUseBuffer->nFlags = pData->nFlags; | |
1580 | pUseBuffer->pPrivate = pData->pPrivate; | |
1581 | ||
1582 | return ret; | |
1583 | } |