| 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_VencControl.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_Venc.h" |
| 33 | #include "Exynos_OMX_VencControl.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" |
| 40 | |
| 41 | #ifdef USE_ANB |
| 42 | #include "Exynos_OSAL_Android.h" |
| 43 | #endif |
| 44 | |
| 45 | #undef EXYNOS_LOG_TAG |
| 46 | #define EXYNOS_LOG_TAG "EXYNOS_VIDEO_ENCCONTROL" |
| 47 | #define EXYNOS_LOG_OFF |
| 48 | //#define EXYNOS_TRACE_ON |
| 49 | #include "Exynos_OSAL_Log.h" |
| 50 | |
| 51 | |
| 52 | OMX_ERRORTYPE Exynos_OMX_UseBuffer( |
| 53 | OMX_IN OMX_HANDLETYPE hComponent, |
| 54 | OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr, |
| 55 | OMX_IN OMX_U32 nPortIndex, |
| 56 | OMX_IN OMX_PTR pAppPrivate, |
| 57 | OMX_IN OMX_U32 nSizeBytes, |
| 58 | OMX_IN OMX_U8 *pBuffer) |
| 59 | { |
| 60 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 61 | OMX_COMPONENTTYPE *pOMXComponent = NULL; |
| 62 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 63 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 64 | OMX_BUFFERHEADERTYPE *pTempBufferHdr = NULL; |
| 65 | OMX_U32 i = 0; |
| 66 | |
| 67 | FunctionIn(); |
| 68 | |
| 69 | if (hComponent == NULL) { |
| 70 | ret = OMX_ErrorBadParameter; |
| 71 | goto EXIT; |
| 72 | } |
| 73 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 74 | |
| 75 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 76 | if (ret != OMX_ErrorNone) { |
| 77 | goto EXIT; |
| 78 | } |
| 79 | |
| 80 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 81 | ret = OMX_ErrorBadParameter; |
| 82 | goto EXIT; |
| 83 | } |
| 84 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 85 | |
| 86 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 87 | ret = OMX_ErrorBadPortIndex; |
| 88 | goto EXIT; |
| 89 | } |
| 90 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 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 | pTempBufferHdr = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE)); |
| 103 | if (pTempBufferHdr == NULL) { |
| 104 | ret = OMX_ErrorInsufficientResources; |
| 105 | goto EXIT; |
| 106 | } |
| 107 | Exynos_OSAL_Memset(pTempBufferHdr, 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 = pTempBufferHdr; |
| 112 | pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED); |
| 113 | INIT_SET_SIZE_VERSION(pTempBufferHdr, OMX_BUFFERHEADERTYPE); |
| 114 | pTempBufferHdr->pBuffer = pBuffer; |
| 115 | pTempBufferHdr->nAllocLen = nSizeBytes; |
| 116 | pTempBufferHdr->pAppPrivate = pAppPrivate; |
| 117 | if (nPortIndex == INPUT_PORT_INDEX) |
| 118 | pTempBufferHdr->nInputPortIndex = INPUT_PORT_INDEX; |
| 119 | else |
| 120 | pTempBufferHdr->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 = pTempBufferHdr; |
| 130 | ret = OMX_ErrorNone; |
| 131 | goto EXIT; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | Exynos_OSAL_Free(pTempBufferHdr); |
| 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 **ppBufferHdr, |
| 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_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 155 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 156 | OMX_BUFFERHEADERTYPE *pTempBufferHdr = NULL; |
| 157 | OMX_U8 *pTempBuffer = NULL; |
| 158 | int fdTempBuffer = -1; |
| 159 | MEMORY_TYPE eMemType = SYSTEM_MEMORY; |
| 160 | OMX_U32 i = 0; |
| 161 | |
| 162 | FunctionIn(); |
| 163 | |
| 164 | if (hComponent == NULL) { |
| 165 | ret = OMX_ErrorBadParameter; |
| 166 | goto EXIT; |
| 167 | } |
| 168 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 169 | |
| 170 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 171 | if (ret != OMX_ErrorNone) { |
| 172 | goto EXIT; |
| 173 | } |
| 174 | |
| 175 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 176 | ret = OMX_ErrorBadParameter; |
| 177 | goto EXIT; |
| 178 | } |
| 179 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 180 | |
| 181 | if (pExynosComponent->hComponentHandle == NULL) { |
| 182 | ret = OMX_ErrorBadParameter; |
| 183 | goto EXIT; |
| 184 | } |
| 185 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 186 | |
| 187 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 188 | ret = OMX_ErrorBadPortIndex; |
| 189 | goto EXIT; |
| 190 | } |
| 191 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 192 | /* |
| 193 | if (pExynosPort->portState != OMX_StateIdle ) { |
| 194 | ret = OMX_ErrorIncorrectStateOperation; |
| 195 | goto EXIT; |
| 196 | } |
| 197 | */ |
| 198 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { |
| 199 | ret = OMX_ErrorBadPortIndex; |
| 200 | goto EXIT; |
| 201 | } |
| 202 | |
| 203 | if ((pVideoEnc->bDRMPlayerMode == OMX_TRUE) && |
| 204 | (nPortIndex == OUTPUT_PORT_INDEX)) { |
| 205 | eMemType = SECURE_MEMORY; |
| 206 | } else if (pExynosPort->bNeedContigMem == OMX_TRUE) { |
| 207 | eMemType = CONTIG_MEMORY; |
| 208 | } else if ((nPortIndex == INPUT_PORT_INDEX) && |
| 209 | (pExynosPort->bufferProcessType & BUFFER_SHARE)) { |
| 210 | eMemType = NORMAL_MEMORY; |
| 211 | } |
| 212 | |
| 213 | pTempBuffer = Exynos_OSAL_SharedMemory_Alloc(pVideoEnc->hSharedMemory, nSizeBytes, eMemType); |
| 214 | if (pTempBuffer == NULL) { |
| 215 | ret = OMX_ErrorInsufficientResources; |
| 216 | goto EXIT; |
| 217 | } |
| 218 | fdTempBuffer = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pTempBuffer); |
| 219 | |
| 220 | pTempBufferHdr = (OMX_BUFFERHEADERTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE)); |
| 221 | if (pTempBufferHdr == NULL) { |
| 222 | Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pTempBuffer); |
| 223 | ret = OMX_ErrorInsufficientResources; |
| 224 | goto EXIT; |
| 225 | } |
| 226 | Exynos_OSAL_Memset(pTempBufferHdr, 0, sizeof(OMX_BUFFERHEADERTYPE)); |
| 227 | |
| 228 | for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) { |
| 229 | if (pExynosPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) { |
| 230 | pExynosPort->extendBufferHeader[i].OMXBufferHeader = pTempBufferHdr; |
| 231 | pExynosPort->extendBufferHeader[i].buf_fd[0] = fdTempBuffer; |
| 232 | pExynosPort->bufferStateAllocate[i] = (BUFFER_STATE_ALLOCATED | HEADER_STATE_ALLOCATED); |
| 233 | INIT_SET_SIZE_VERSION(pTempBufferHdr, OMX_BUFFERHEADERTYPE); |
| 234 | if (eMemType == SECURE_MEMORY) |
| 235 | pTempBufferHdr->pBuffer = fdTempBuffer; |
| 236 | else |
| 237 | pTempBufferHdr->pBuffer = pTempBuffer; |
| 238 | pTempBufferHdr->nAllocLen = nSizeBytes; |
| 239 | pTempBufferHdr->pAppPrivate = pAppPrivate; |
| 240 | if (nPortIndex == INPUT_PORT_INDEX) |
| 241 | pTempBufferHdr->nInputPortIndex = INPUT_PORT_INDEX; |
| 242 | else |
| 243 | pTempBufferHdr->nOutputPortIndex = OUTPUT_PORT_INDEX; |
| 244 | pExynosPort->assignedBufferNum++; |
| 245 | if (pExynosPort->assignedBufferNum == pExynosPort->portDefinition.nBufferCountActual) { |
| 246 | pExynosPort->portDefinition.bPopulated = OMX_TRUE; |
| 247 | /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */ |
| 248 | Exynos_OSAL_SemaphorePost(pExynosPort->loadedResource); |
| 249 | /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */ |
| 250 | } |
| 251 | *ppBufferHdr = pTempBufferHdr; |
| 252 | ret = OMX_ErrorNone; |
| 253 | goto EXIT; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | Exynos_OSAL_Free(pTempBufferHdr); |
| 258 | Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pTempBuffer); |
| 259 | |
| 260 | ret = OMX_ErrorInsufficientResources; |
| 261 | |
| 262 | EXIT: |
| 263 | FunctionOut(); |
| 264 | |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | OMX_ERRORTYPE Exynos_OMX_FreeBuffer( |
| 269 | OMX_IN OMX_HANDLETYPE hComponent, |
| 270 | OMX_IN OMX_U32 nPortIndex, |
| 271 | OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr) |
| 272 | { |
| 273 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 274 | OMX_COMPONENTTYPE *pOMXComponent = NULL; |
| 275 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 276 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 277 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 278 | OMX_BUFFERHEADERTYPE *pOMXBufferHdr = NULL; |
| 279 | OMX_U32 i = 0; |
| 280 | |
| 281 | FunctionIn(); |
| 282 | |
| 283 | if (hComponent == NULL) { |
| 284 | ret = OMX_ErrorBadParameter; |
| 285 | goto EXIT; |
| 286 | } |
| 287 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 288 | |
| 289 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 290 | if (ret != OMX_ErrorNone) { |
| 291 | goto EXIT; |
| 292 | } |
| 293 | |
| 294 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 295 | ret = OMX_ErrorBadParameter; |
| 296 | goto EXIT; |
| 297 | } |
| 298 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 299 | |
| 300 | if (pExynosComponent->hComponentHandle == NULL) { |
| 301 | ret = OMX_ErrorBadParameter; |
| 302 | goto EXIT; |
| 303 | } |
| 304 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 305 | |
| 306 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 307 | ret = OMX_ErrorBadPortIndex; |
| 308 | goto EXIT; |
| 309 | } |
| 310 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 311 | |
| 312 | if (CHECK_PORT_TUNNELED(pExynosPort) && CHECK_PORT_BUFFER_SUPPLIER(pExynosPort)) { |
| 313 | ret = OMX_ErrorBadPortIndex; |
| 314 | goto EXIT; |
| 315 | } |
| 316 | |
| 317 | if ((pExynosPort->portState != OMX_StateLoaded) && |
| 318 | (pExynosPort->portState != OMX_StateInvalid)) { |
| 319 | (*(pExynosComponent->pCallbacks->EventHandler)) (pOMXComponent, |
| 320 | pExynosComponent->callbackData, |
| 321 | (OMX_U32)OMX_EventError, |
| 322 | (OMX_U32)OMX_ErrorPortUnpopulated, |
| 323 | nPortIndex, NULL); |
| 324 | } |
| 325 | |
| 326 | for (i = 0; i < /*pExynosPort->portDefinition.nBufferCountActual*/MAX_BUFFER_NUM; i++) { |
| 327 | if ((pExynosPort->bufferStateAllocate[i] != BUFFER_STATE_FREE) && |
| 328 | (pExynosPort->extendBufferHeader[i].OMXBufferHeader != NULL)) { |
| 329 | pOMXBufferHdr = pExynosPort->extendBufferHeader[i].OMXBufferHeader; |
| 330 | |
| 331 | if (pOMXBufferHdr->pBuffer == pBufferHdr->pBuffer) { |
| 332 | if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ALLOCATED) { |
| 333 | if ((pVideoEnc->bDRMPlayerMode == OMX_TRUE) && |
| 334 | (nPortIndex == OUTPUT_PORT_INDEX)) { |
| 335 | OMX_PTR mapBuffer = Exynos_OSAL_SharedMemory_IONToVirt(pVideoEnc->hSharedMemory, (int)pOMXBufferHdr->pBuffer); |
| 336 | Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, mapBuffer); |
| 337 | } else { |
| 338 | Exynos_OSAL_SharedMemory_Free(pVideoEnc->hSharedMemory, pOMXBufferHdr->pBuffer); |
| 339 | } |
| 340 | pOMXBufferHdr->pBuffer = NULL; |
| 341 | pBufferHdr->pBuffer = NULL; |
| 342 | } else if (pExynosPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) { |
| 343 | ; /* None*/ |
| 344 | } |
| 345 | pExynosPort->assignedBufferNum--; |
| 346 | |
| 347 | if (pExynosPort->bufferStateAllocate[i] & HEADER_STATE_ALLOCATED) { |
| 348 | Exynos_OSAL_Free(pOMXBufferHdr); |
| 349 | pExynosPort->extendBufferHeader[i].OMXBufferHeader = NULL; |
| 350 | pBufferHdr = NULL; |
| 351 | } |
| 352 | |
| 353 | pExynosPort->bufferStateAllocate[i] = BUFFER_STATE_FREE; |
| 354 | ret = OMX_ErrorNone; |
| 355 | goto EXIT; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | EXIT: |
| 361 | if ((ret == OMX_ErrorNone) && |
| 362 | (pExynosPort->assignedBufferNum == 0)) { |
| 363 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pExynosPort->unloadedResource signal set"); |
| 364 | /* Exynos_OSAL_MutexLock(pExynosComponent->compMutex); */ |
| 365 | Exynos_OSAL_SemaphorePost(pExynosPort->unloadedResource); |
| 366 | /* Exynos_OSAL_MutexUnlock(pExynosComponent->compMutex); */ |
| 367 | pExynosPort->portDefinition.bPopulated = OMX_FALSE; |
| 368 | } |
| 369 | |
| 370 | FunctionOut(); |
| 371 | |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | OMX_ERRORTYPE Exynos_OMX_AllocateTunnelBuffer( |
| 376 | EXYNOS_OMX_BASEPORT *pOMXBasePort, |
| 377 | OMX_U32 nPortIndex) |
| 378 | { |
| 379 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 380 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 381 | OMX_BUFFERHEADERTYPE *pTempBufferHdr = NULL; |
| 382 | OMX_U8 *pTempBuffer = NULL; |
| 383 | OMX_U32 nBufferSize = 0; |
| 384 | OMX_PARAM_PORTDEFINITIONTYPE portDefinition; |
| 385 | |
| 386 | ret = OMX_ErrorTunnelingUnsupported; |
| 387 | EXIT: |
| 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | OMX_ERRORTYPE Exynos_OMX_FreeTunnelBuffer( |
| 392 | EXYNOS_OMX_BASEPORT *pOMXBasePort, |
| 393 | OMX_U32 nPortIndex) |
| 394 | { |
| 395 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 396 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 397 | OMX_BUFFERHEADERTYPE *pTempBufferHdr = NULL; |
| 398 | OMX_U8 *pTempBuffer = NULL; |
| 399 | OMX_U32 nBufferSize = 0; |
| 400 | |
| 401 | ret = OMX_ErrorTunnelingUnsupported; |
| 402 | EXIT: |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | OMX_ERRORTYPE Exynos_OMX_ComponentTunnelRequest( |
| 407 | OMX_IN OMX_HANDLETYPE hComp, |
| 408 | OMX_IN OMX_U32 nPort, |
| 409 | OMX_IN OMX_HANDLETYPE hTunneledComp, |
| 410 | OMX_IN OMX_U32 nTunneledPort, |
| 411 | OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup) |
| 412 | { |
| 413 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 414 | |
| 415 | ret = OMX_ErrorTunnelingUnsupported; |
| 416 | EXIT: |
| 417 | return ret; |
| 418 | } |
| 419 | |
| 420 | OMX_ERRORTYPE Exynos_OMX_GetFlushBuffer( |
| 421 | EXYNOS_OMX_BASEPORT *pExynosPort, |
| 422 | EXYNOS_OMX_DATABUFFER *pDataBuffer[]) |
| 423 | { |
| 424 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 425 | |
| 426 | FunctionIn(); |
| 427 | |
| 428 | *pDataBuffer = NULL; |
| 429 | |
| 430 | if (pExynosPort->portWayType == WAY1_PORT) { |
| 431 | *pDataBuffer = &pExynosPort->way.port1WayDataBuffer.dataBuffer; |
| 432 | } else if (pExynosPort->portWayType == WAY2_PORT) { |
| 433 | pDataBuffer[0] = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer); |
| 434 | pDataBuffer[1] = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer); |
| 435 | } |
| 436 | |
| 437 | EXIT: |
| 438 | FunctionOut(); |
| 439 | |
| 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | OMX_ERRORTYPE Exynos_OMX_FlushPort( |
| 444 | OMX_COMPONENTTYPE *pOMXComponent, |
| 445 | OMX_S32 nPortIndex) |
| 446 | { |
| 447 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 448 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 449 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 450 | OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; |
| 451 | EXYNOS_OMX_DATABUFFER *pDataBuffer[2] = {NULL, NULL}; |
| 452 | EXYNOS_OMX_MESSAGE *pMessage = NULL; |
| 453 | OMX_S32 nSemaCnt = 0; |
| 454 | int i = 0; |
| 455 | |
| 456 | FunctionIn(); |
| 457 | |
| 458 | if (pOMXComponent == NULL) { |
| 459 | ret = OMX_ErrorBadParameter; |
| 460 | goto EXIT; |
| 461 | } |
| 462 | |
| 463 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 464 | ret = OMX_ErrorBadParameter; |
| 465 | goto EXIT; |
| 466 | } |
| 467 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 468 | |
| 469 | if ((nPortIndex < 0) || |
| 470 | (nPortIndex >= pExynosComponent->portParam.nPorts)) { |
| 471 | ret = OMX_ErrorBadPortIndex; |
| 472 | goto EXIT; |
| 473 | } |
| 474 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 475 | |
| 476 | while (Exynos_OSAL_GetElemNum(&pExynosPort->bufferQ) > 0) { |
| 477 | Exynos_OSAL_Get_SemaphoreCount(pExynosPort->bufferSemID, &nSemaCnt); |
| 478 | if (nSemaCnt == 0) |
| 479 | Exynos_OSAL_SemaphorePost(pExynosPort->bufferSemID); |
| 480 | |
| 481 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); |
| 482 | pMessage = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); |
| 483 | if ((pMessage != NULL) && |
| 484 | (pMessage->messageType != EXYNOS_OMX_CommandFakeBuffer)) { |
| 485 | pBufferHdr = (OMX_BUFFERHEADERTYPE *)pMessage->pCmdData; |
| 486 | pBufferHdr->nFilledLen = 0; |
| 487 | |
| 488 | if (nPortIndex == OUTPUT_PORT_INDEX) { |
| 489 | Exynos_OMX_OutputBufferReturn(pOMXComponent, pBufferHdr); |
| 490 | } else if (nPortIndex == INPUT_PORT_INDEX) { |
| 491 | Exynos_OMX_InputBufferReturn(pOMXComponent, pBufferHdr); |
| 492 | } |
| 493 | } |
| 494 | Exynos_OSAL_Free(pMessage); |
| 495 | pMessage = NULL; |
| 496 | } |
| 497 | |
| 498 | Exynos_OMX_GetFlushBuffer(pExynosPort, pDataBuffer); |
| 499 | if ((pDataBuffer[0] != NULL) && |
| 500 | (pDataBuffer[0]->dataValid == OMX_TRUE)) { |
| 501 | if (nPortIndex == INPUT_PORT_INDEX) |
| 502 | Exynos_FlushInputBufferReturn(pOMXComponent, pDataBuffer[0]); |
| 503 | else if (nPortIndex == OUTPUT_PORT_INDEX) |
| 504 | Exynos_FlushOutputBufferReturn(pOMXComponent, pDataBuffer[0]); |
| 505 | } |
| 506 | if ((pDataBuffer[1] != NULL) && |
| 507 | (pDataBuffer[1]->dataValid == OMX_TRUE)) { |
| 508 | if (nPortIndex == INPUT_PORT_INDEX) |
| 509 | Exynos_FlushInputBufferReturn(pOMXComponent, pDataBuffer[1]); |
| 510 | else if (nPortIndex == OUTPUT_PORT_INDEX) |
| 511 | Exynos_FlushOutputBufferReturn(pOMXComponent, pDataBuffer[1]); |
| 512 | } |
| 513 | |
| 514 | if (pExynosComponent->bMultiThreadProcess == OMX_TRUE) { |
| 515 | if (pExynosPort->bufferProcessType & BUFFER_SHARE) { |
| 516 | if (pExynosPort->processData.bufferHeader != NULL) { |
| 517 | if (nPortIndex == INPUT_PORT_INDEX) { |
| 518 | #ifdef USE_METADATABUFFERTYPE |
| 519 | if ((pExynosPort->bStoreMetaData == OMX_TRUE) && |
| 520 | (pExynosPort->portDefinition.format.video.eColorFormat == OMX_COLOR_FormatAndroidOpaque)) { |
| 521 | OMX_PTR ppBuf[MAX_BUFFER_PLANE]; |
| 522 | Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)pExynosPort->processData.bufferHeader->pBuffer, ppBuf); |
| 523 | Exynos_OSAL_UnlockANBHandle(ppBuf[0]); |
| 524 | } |
| 525 | #endif |
| 526 | Exynos_OMX_InputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader); |
| 527 | } else if (nPortIndex == OUTPUT_PORT_INDEX) { |
| 528 | Exynos_OMX_OutputBufferReturn(pOMXComponent, pExynosPort->processData.bufferHeader); |
| 529 | } |
| 530 | } |
| 531 | Exynos_ResetCodecData(&pExynosPort->processData); |
| 532 | |
| 533 | for (i = 0; i < pExynosPort->portDefinition.nBufferCountActual; i++) { |
| 534 | if (pExynosPort->extendBufferHeader[i].bBufferInOMX == OMX_TRUE) { |
| 535 | if (nPortIndex == OUTPUT_PORT_INDEX) { |
| 536 | Exynos_OMX_OutputBufferReturn(pOMXComponent, |
| 537 | pExynosPort->extendBufferHeader[i].OMXBufferHeader); |
| 538 | } else if (nPortIndex == INPUT_PORT_INDEX) { |
| 539 | #ifdef USE_METADATABUFFERTYPE |
| 540 | if ((pExynosPort->bStoreMetaData == OMX_TRUE) && |
| 541 | (pExynosPort->portDefinition.format.video.eColorFormat == OMX_COLOR_FormatAndroidOpaque)) { |
| 542 | OMX_PTR ppBuf[MAX_BUFFER_PLANE]; |
| 543 | Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)pExynosPort->extendBufferHeader[i].OMXBufferHeader->pBuffer, ppBuf); |
| 544 | Exynos_OSAL_UnlockANBHandle(ppBuf[0]); |
| 545 | } |
| 546 | #endif |
| 547 | Exynos_OMX_InputBufferReturn(pOMXComponent, |
| 548 | pExynosPort->extendBufferHeader[i].OMXBufferHeader); |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | } else { |
| 554 | Exynos_ResetCodecData(&pExynosPort->processData); |
| 555 | } |
| 556 | |
| 557 | while (1) { |
| 558 | OMX_S32 cnt = 0; |
| 559 | Exynos_OSAL_Get_SemaphoreCount(pExynosPort->bufferSemID, &cnt); |
| 560 | if (cnt <= 0) |
| 561 | break; |
| 562 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); |
| 563 | } |
| 564 | Exynos_OSAL_ResetQueue(&pExynosPort->bufferQ); |
| 565 | |
| 566 | EXIT: |
| 567 | FunctionOut(); |
| 568 | |
| 569 | return ret; |
| 570 | } |
| 571 | |
| 572 | OMX_ERRORTYPE Exynos_OMX_BufferFlush( |
| 573 | OMX_COMPONENTTYPE *pOMXComponent, |
| 574 | OMX_S32 nPortIndex, |
| 575 | OMX_BOOL bEvent) |
| 576 | { |
| 577 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 578 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 579 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 580 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 581 | EXYNOS_OMX_DATABUFFER *pDataBuffer[2] = {NULL, NULL}; |
| 582 | OMX_U32 i = 0; |
| 583 | |
| 584 | FunctionIn(); |
| 585 | |
| 586 | if (pOMXComponent == NULL) { |
| 587 | ret = OMX_ErrorBadParameter; |
| 588 | goto EXIT; |
| 589 | } |
| 590 | |
| 591 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 592 | if (ret != OMX_ErrorNone) { |
| 593 | goto EXIT; |
| 594 | } |
| 595 | |
| 596 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 597 | ret = OMX_ErrorBadParameter; |
| 598 | goto EXIT; |
| 599 | } |
| 600 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 601 | |
| 602 | if (pExynosComponent->hComponentHandle == NULL) { |
| 603 | ret = OMX_ErrorBadParameter; |
| 604 | goto EXIT; |
| 605 | } |
| 606 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 607 | |
| 608 | if ((nPortIndex < 0) || |
| 609 | (nPortIndex >= pExynosComponent->portParam.nPorts)) { |
| 610 | ret = OMX_ErrorBadPortIndex; |
| 611 | goto EXIT; |
| 612 | } |
| 613 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 614 | |
| 615 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush start, port:%d", nPortIndex); |
| 616 | |
| 617 | pExynosPort->bIsPortFlushed = OMX_TRUE; |
| 618 | |
| 619 | if (pExynosComponent->bMultiThreadProcess == OMX_FALSE) { |
| 620 | Exynos_OSAL_SignalSet(pExynosComponent->pauseEvent); |
| 621 | } else { |
| 622 | Exynos_OSAL_SignalSet(pExynosPort->pauseEvent); |
| 623 | } |
| 624 | |
| 625 | Exynos_OMX_GetFlushBuffer(pExynosPort, pDataBuffer); |
| 626 | if (pDataBuffer[0] == NULL) { |
| 627 | ret = OMX_ErrorBadParameter; |
| 628 | goto EXIT; |
| 629 | } |
| 630 | |
| 631 | if (pExynosPort->bufferProcessType & BUFFER_COPY) |
| 632 | Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID); |
| 633 | Exynos_OSAL_SemaphorePost(pExynosPort->bufferSemID); |
| 634 | |
| 635 | pVideoEnc->exynos_codec_bufferProcessRun(pOMXComponent, nPortIndex); |
| 636 | |
| 637 | Exynos_OSAL_MutexLock(pDataBuffer[0]->bufferMutex); |
| 638 | pVideoEnc->exynos_codec_stop(pOMXComponent, nPortIndex); |
| 639 | |
| 640 | if (pDataBuffer[1] != NULL) |
| 641 | Exynos_OSAL_MutexLock(pDataBuffer[1]->bufferMutex); |
| 642 | |
| 643 | ret = Exynos_OMX_FlushPort(pOMXComponent, nPortIndex); |
| 644 | if (ret != OMX_ErrorNone) |
| 645 | goto EXIT; |
| 646 | |
| 647 | if (pExynosPort->bufferProcessType & BUFFER_COPY) |
| 648 | pVideoEnc->exynos_codec_enqueueAllBuffer(pOMXComponent, nPortIndex); |
| 649 | Exynos_ResetCodecData(&pExynosPort->processData); |
| 650 | |
| 651 | if (ret == OMX_ErrorNone) { |
| 652 | if (nPortIndex == INPUT_PORT_INDEX) { |
| 653 | pExynosComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE; |
| 654 | pExynosComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE; |
| 655 | Exynos_OSAL_Memset(pExynosComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); |
| 656 | Exynos_OSAL_Memset(pExynosComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); |
| 657 | pExynosComponent->getAllDelayBuffer = OMX_FALSE; |
| 658 | pExynosComponent->bSaveFlagEOS = OMX_FALSE; |
| 659 | pExynosComponent->reInputData = OMX_FALSE; |
| 660 | } |
| 661 | |
| 662 | pExynosPort->bIsPortFlushed = OMX_FALSE; |
| 663 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE,"OMX_CommandFlush EventCmdComplete, port:%d", nPortIndex); |
| 664 | if (bEvent == OMX_TRUE) |
| 665 | pExynosComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, |
| 666 | pExynosComponent->callbackData, |
| 667 | OMX_EventCmdComplete, |
| 668 | OMX_CommandFlush, nPortIndex, NULL); |
| 669 | } |
| 670 | |
| 671 | if (pDataBuffer[1] != NULL) |
| 672 | Exynos_OSAL_MutexUnlock(pDataBuffer[1]->bufferMutex); |
| 673 | |
| 674 | Exynos_OSAL_MutexUnlock(pDataBuffer[0]->bufferMutex); |
| 675 | |
| 676 | EXIT: |
| 677 | if ((ret != OMX_ErrorNone) && (pOMXComponent != NULL) && (pExynosComponent != NULL)) { |
| 678 | Exynos_OSAL_Log(EXYNOS_LOG_ERROR,"%s : %d", __FUNCTION__, __LINE__); |
| 679 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, |
| 680 | pExynosComponent->callbackData, |
| 681 | OMX_EventError, |
| 682 | ret, 0, NULL); |
| 683 | } |
| 684 | |
| 685 | FunctionOut(); |
| 686 | |
| 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | OMX_ERRORTYPE Exynos_InputBufferReturn( |
| 691 | OMX_COMPONENTTYPE *pOMXComponent) |
| 692 | { |
| 693 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 694 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 695 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 696 | EXYNOS_OMX_DATABUFFER *pDataBuffer = NULL; |
| 697 | OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; |
| 698 | |
| 699 | FunctionIn(); |
| 700 | |
| 701 | if (pOMXComponent == NULL) { |
| 702 | ret = OMX_ErrorBadParameter; |
| 703 | goto EXIT; |
| 704 | } |
| 705 | |
| 706 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 707 | ret = OMX_ErrorBadParameter; |
| 708 | goto EXIT; |
| 709 | } |
| 710 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 711 | pExynosPort = &(pExynosComponent->pExynosPort[INPUT_PORT_INDEX]); |
| 712 | |
| 713 | if (pExynosPort->bufferProcessType & BUFFER_COPY) { |
| 714 | pDataBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer); |
| 715 | } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) { |
| 716 | pDataBuffer = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer); |
| 717 | } |
| 718 | |
| 719 | if (pDataBuffer != NULL) |
| 720 | pBufferHdr = pDataBuffer->bufferHeader; |
| 721 | |
| 722 | if (pBufferHdr != NULL) { |
| 723 | if (pExynosPort->markType.hMarkTargetComponent != NULL) { |
| 724 | pBufferHdr->hMarkTargetComponent = pExynosPort->markType.hMarkTargetComponent; |
| 725 | pBufferHdr->pMarkData = pExynosPort->markType.pMarkData; |
| 726 | pExynosPort->markType.hMarkTargetComponent = NULL; |
| 727 | pExynosPort->markType.pMarkData = NULL; |
| 728 | } |
| 729 | |
| 730 | if (pBufferHdr->hMarkTargetComponent != NULL) { |
| 731 | if (pBufferHdr->hMarkTargetComponent == pOMXComponent) { |
| 732 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, |
| 733 | pExynosComponent->callbackData, |
| 734 | OMX_EventMark, |
| 735 | 0, 0, pBufferHdr->pMarkData); |
| 736 | } else { |
| 737 | pExynosComponent->propagateMarkType.hMarkTargetComponent = pBufferHdr->hMarkTargetComponent; |
| 738 | pExynosComponent->propagateMarkType.pMarkData = pBufferHdr->pMarkData; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | pBufferHdr->nFilledLen = 0; |
| 743 | pBufferHdr->nOffset = 0; |
| 744 | Exynos_OMX_InputBufferReturn(pOMXComponent, pBufferHdr); |
| 745 | } |
| 746 | |
| 747 | /* reset dataBuffer */ |
| 748 | Exynos_ResetDataBuffer(pDataBuffer); |
| 749 | |
| 750 | EXIT: |
| 751 | FunctionOut(); |
| 752 | |
| 753 | return ret; |
| 754 | } |
| 755 | |
| 756 | OMX_ERRORTYPE Exynos_FlushInputBufferReturn( |
| 757 | OMX_COMPONENTTYPE *pOMXComponent, |
| 758 | EXYNOS_OMX_DATABUFFER *pDataBuffer) |
| 759 | { |
| 760 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 761 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 762 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 763 | OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; |
| 764 | |
| 765 | FunctionIn(); |
| 766 | |
| 767 | if (pOMXComponent == NULL) { |
| 768 | ret = OMX_ErrorBadParameter; |
| 769 | goto EXIT; |
| 770 | } |
| 771 | |
| 772 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 773 | ret = OMX_ErrorBadParameter; |
| 774 | goto EXIT; |
| 775 | } |
| 776 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 777 | pExynosPort = &(pExynosComponent->pExynosPort[INPUT_PORT_INDEX]); |
| 778 | |
| 779 | pBufferHdr = pDataBuffer->bufferHeader; |
| 780 | |
| 781 | if (pBufferHdr != NULL) { |
| 782 | if (pExynosPort->markType.hMarkTargetComponent != NULL) { |
| 783 | pBufferHdr->hMarkTargetComponent = pExynosPort->markType.hMarkTargetComponent; |
| 784 | pBufferHdr->pMarkData = pExynosPort->markType.pMarkData; |
| 785 | pExynosPort->markType.hMarkTargetComponent = NULL; |
| 786 | pExynosPort->markType.pMarkData = NULL; |
| 787 | } |
| 788 | |
| 789 | if (pBufferHdr->hMarkTargetComponent != NULL) { |
| 790 | if (pBufferHdr->hMarkTargetComponent == pOMXComponent) { |
| 791 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, |
| 792 | pExynosComponent->callbackData, |
| 793 | OMX_EventMark, |
| 794 | 0, 0, pBufferHdr->pMarkData); |
| 795 | } else { |
| 796 | pExynosComponent->propagateMarkType.hMarkTargetComponent = pBufferHdr->hMarkTargetComponent; |
| 797 | pExynosComponent->propagateMarkType.pMarkData = pBufferHdr->pMarkData; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | pBufferHdr->nFilledLen = 0; |
| 802 | pBufferHdr->nOffset = 0; |
| 803 | Exynos_OMX_InputBufferReturn(pOMXComponent, pBufferHdr); |
| 804 | } |
| 805 | |
| 806 | /* reset dataBuffer */ |
| 807 | Exynos_ResetDataBuffer(pDataBuffer); |
| 808 | |
| 809 | EXIT: |
| 810 | FunctionOut(); |
| 811 | |
| 812 | return ret; |
| 813 | } |
| 814 | |
| 815 | OMX_ERRORTYPE Exynos_InputBufferGetQueue( |
| 816 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent) |
| 817 | { |
| 818 | OMX_ERRORTYPE ret = OMX_ErrorUndefined; |
| 819 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 820 | EXYNOS_OMX_MESSAGE *pMessage = NULL; |
| 821 | EXYNOS_OMX_DATABUFFER *pDataBuffer = NULL; |
| 822 | |
| 823 | FunctionIn(); |
| 824 | |
| 825 | if (pExynosComponent == NULL) { |
| 826 | ret = OMX_ErrorBadParameter; |
| 827 | goto EXIT; |
| 828 | } |
| 829 | pExynosPort = &(pExynosComponent->pExynosPort[INPUT_PORT_INDEX]); |
| 830 | pDataBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer); |
| 831 | |
| 832 | if (pExynosComponent->currentState != OMX_StateExecuting) { |
| 833 | ret = OMX_ErrorUndefined; |
| 834 | goto EXIT; |
| 835 | } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) && |
| 836 | (!CHECK_PORT_BEING_FLUSHED(pExynosPort))) { |
| 837 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); |
| 838 | if (pDataBuffer->dataValid != OMX_TRUE) { |
| 839 | pMessage = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); |
| 840 | if (pMessage == NULL) { |
| 841 | ret = OMX_ErrorUndefined; |
| 842 | goto EXIT; |
| 843 | } |
| 844 | if (pMessage->messageType == EXYNOS_OMX_CommandFakeBuffer) { |
| 845 | Exynos_OSAL_Free(pMessage); |
| 846 | ret = OMX_ErrorCodecFlush; |
| 847 | goto EXIT; |
| 848 | } |
| 849 | |
| 850 | pDataBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(pMessage->pCmdData); |
| 851 | pDataBuffer->allocSize = pDataBuffer->bufferHeader->nAllocLen; |
| 852 | pDataBuffer->dataLen = pDataBuffer->bufferHeader->nFilledLen; |
| 853 | pDataBuffer->remainDataLen = pDataBuffer->dataLen; |
| 854 | pDataBuffer->usedDataLen = 0; |
| 855 | pDataBuffer->dataValid = OMX_TRUE; |
| 856 | pDataBuffer->nFlags = pDataBuffer->bufferHeader->nFlags; |
| 857 | pDataBuffer->timeStamp = pDataBuffer->bufferHeader->nTimeStamp; |
| 858 | |
| 859 | Exynos_OSAL_Free(pMessage); |
| 860 | |
| 861 | if (pDataBuffer->allocSize <= pDataBuffer->dataLen) |
| 862 | Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "Input Buffer Full, Check input buffer size! allocSize:%d, dataLen:%d", pDataBuffer->allocSize, pDataBuffer->dataLen); |
| 863 | } |
| 864 | ret = OMX_ErrorNone; |
| 865 | } |
| 866 | EXIT: |
| 867 | FunctionOut(); |
| 868 | |
| 869 | return ret; |
| 870 | } |
| 871 | |
| 872 | OMX_ERRORTYPE Exynos_OutputBufferReturn( |
| 873 | OMX_COMPONENTTYPE *pOMXComponent) |
| 874 | { |
| 875 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 876 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 877 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 878 | EXYNOS_OMX_DATABUFFER *pDataBuffer = NULL; |
| 879 | OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; |
| 880 | |
| 881 | FunctionIn(); |
| 882 | |
| 883 | if (pOMXComponent == NULL) { |
| 884 | ret = OMX_ErrorBadParameter; |
| 885 | goto EXIT; |
| 886 | } |
| 887 | |
| 888 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 889 | ret = OMX_ErrorBadParameter; |
| 890 | goto EXIT; |
| 891 | } |
| 892 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 893 | pExynosPort = &(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]); |
| 894 | |
| 895 | pDataBuffer = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer); |
| 896 | pBufferHdr = pDataBuffer->bufferHeader; |
| 897 | |
| 898 | if (pBufferHdr != NULL) { |
| 899 | pBufferHdr->nFilledLen = pDataBuffer->remainDataLen; |
| 900 | pBufferHdr->nOffset = 0; |
| 901 | pBufferHdr->nFlags = pDataBuffer->nFlags; |
| 902 | pBufferHdr->nTimeStamp = pDataBuffer->timeStamp; |
| 903 | |
| 904 | if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) { |
| 905 | pBufferHdr->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent; |
| 906 | pBufferHdr->pMarkData = pExynosComponent->propagateMarkType.pMarkData; |
| 907 | pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL; |
| 908 | pExynosComponent->propagateMarkType.pMarkData = NULL; |
| 909 | } |
| 910 | |
| 911 | if ((pBufferHdr->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { |
| 912 | pBufferHdr->nFilledLen = 0; |
| 913 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "event OMX_BUFFERFLAG_EOS!!!"); |
| 914 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, |
| 915 | pExynosComponent->callbackData, |
| 916 | OMX_EventBufferFlag, |
| 917 | OUTPUT_PORT_INDEX, |
| 918 | pBufferHdr->nFlags, NULL); |
| 919 | } |
| 920 | |
| 921 | Exynos_OMX_OutputBufferReturn(pOMXComponent, pBufferHdr); |
| 922 | } |
| 923 | |
| 924 | /* reset dataBuffer */ |
| 925 | Exynos_ResetDataBuffer(pDataBuffer); |
| 926 | |
| 927 | EXIT: |
| 928 | FunctionOut(); |
| 929 | |
| 930 | return ret; |
| 931 | } |
| 932 | |
| 933 | OMX_ERRORTYPE Exynos_FlushOutputBufferReturn( |
| 934 | OMX_COMPONENTTYPE *pOMXComponent, |
| 935 | EXYNOS_OMX_DATABUFFER *pDataBuffer) |
| 936 | { |
| 937 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 938 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 939 | OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; |
| 940 | |
| 941 | FunctionIn(); |
| 942 | |
| 943 | if (pOMXComponent == NULL) { |
| 944 | ret = OMX_ErrorBadParameter; |
| 945 | goto EXIT; |
| 946 | } |
| 947 | |
| 948 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 949 | ret = OMX_ErrorBadParameter; |
| 950 | goto EXIT; |
| 951 | } |
| 952 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 953 | pBufferHdr = pDataBuffer->bufferHeader; |
| 954 | |
| 955 | if (pBufferHdr != NULL) { |
| 956 | pBufferHdr->nFilledLen = pDataBuffer->remainDataLen; |
| 957 | pBufferHdr->nOffset = 0; |
| 958 | pBufferHdr->nFlags = pDataBuffer->nFlags; |
| 959 | pBufferHdr->nTimeStamp = pDataBuffer->timeStamp; |
| 960 | |
| 961 | if (pExynosComponent->propagateMarkType.hMarkTargetComponent != NULL) { |
| 962 | pBufferHdr->hMarkTargetComponent = pExynosComponent->propagateMarkType.hMarkTargetComponent; |
| 963 | pBufferHdr->pMarkData = pExynosComponent->propagateMarkType.pMarkData; |
| 964 | pExynosComponent->propagateMarkType.hMarkTargetComponent = NULL; |
| 965 | pExynosComponent->propagateMarkType.pMarkData = NULL; |
| 966 | } |
| 967 | |
| 968 | if ((pBufferHdr->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { |
| 969 | pBufferHdr->nFilledLen = 0; |
| 970 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "event OMX_BUFFERFLAG_EOS!!!"); |
| 971 | pExynosComponent->pCallbacks->EventHandler(pOMXComponent, |
| 972 | pExynosComponent->callbackData, |
| 973 | OMX_EventBufferFlag, |
| 974 | OUTPUT_PORT_INDEX, |
| 975 | pBufferHdr->nFlags, NULL); |
| 976 | } |
| 977 | Exynos_OMX_OutputBufferReturn(pOMXComponent, pBufferHdr); |
| 978 | } |
| 979 | |
| 980 | /* reset dataBuffer */ |
| 981 | Exynos_ResetDataBuffer(pDataBuffer); |
| 982 | |
| 983 | EXIT: |
| 984 | FunctionOut(); |
| 985 | |
| 986 | return ret; |
| 987 | } |
| 988 | |
| 989 | OMX_ERRORTYPE Exynos_OutputBufferGetQueue( |
| 990 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent) |
| 991 | { |
| 992 | OMX_ERRORTYPE ret = OMX_ErrorUndefined; |
| 993 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 994 | EXYNOS_OMX_MESSAGE *pMessage = NULL; |
| 995 | EXYNOS_OMX_DATABUFFER *pDataBuffer = NULL; |
| 996 | |
| 997 | FunctionIn(); |
| 998 | |
| 999 | if (pExynosComponent == NULL) { |
| 1000 | ret = OMX_ErrorBadParameter; |
| 1001 | goto EXIT; |
| 1002 | } |
| 1003 | pExynosPort = &(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]); |
| 1004 | |
| 1005 | if (pExynosPort->bufferProcessType & BUFFER_COPY) { |
| 1006 | pDataBuffer = &(pExynosPort->way.port2WayDataBuffer.outputDataBuffer); |
| 1007 | } else if (pExynosPort->bufferProcessType & BUFFER_SHARE) { |
| 1008 | pDataBuffer = &(pExynosPort->way.port2WayDataBuffer.inputDataBuffer); |
| 1009 | } else { |
| 1010 | ret = OMX_ErrorUndefined; |
| 1011 | goto EXIT; |
| 1012 | } |
| 1013 | |
| 1014 | if (pExynosComponent->currentState != OMX_StateExecuting) { |
| 1015 | ret = OMX_ErrorUndefined; |
| 1016 | goto EXIT; |
| 1017 | } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) && |
| 1018 | (!CHECK_PORT_BEING_FLUSHED(pExynosPort))) { |
| 1019 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); |
| 1020 | if (pDataBuffer->dataValid != OMX_TRUE) { |
| 1021 | pMessage = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); |
| 1022 | if (pMessage == NULL) { |
| 1023 | ret = OMX_ErrorUndefined; |
| 1024 | goto EXIT; |
| 1025 | } |
| 1026 | if (pMessage->messageType == EXYNOS_OMX_CommandFakeBuffer) { |
| 1027 | Exynos_OSAL_Free(pMessage); |
| 1028 | ret = OMX_ErrorCodecFlush; |
| 1029 | goto EXIT; |
| 1030 | } |
| 1031 | |
| 1032 | pDataBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(pMessage->pCmdData); |
| 1033 | pDataBuffer->allocSize = pDataBuffer->bufferHeader->nAllocLen; |
| 1034 | pDataBuffer->dataLen = 0; //dataBuffer->bufferHeader->nFilledLen; |
| 1035 | pDataBuffer->remainDataLen = pDataBuffer->dataLen; |
| 1036 | pDataBuffer->usedDataLen = 0; //dataBuffer->bufferHeader->nOffset; |
| 1037 | pDataBuffer->dataValid = OMX_TRUE; |
| 1038 | /* pDataBuffer->nFlags = pDataBuffer->bufferHeader->nFlags; */ |
| 1039 | /* pDtaBuffer->nTimeStamp = pDataBuffer->bufferHeader->nTimeStamp; */ |
| 1040 | /* |
| 1041 | if (pExynosPort->bufferProcessType & BUFFER_SHARE) |
| 1042 | pDataBuffer->pPrivate = pDataBuffer->bufferHeader->pOutputPortPrivate; |
| 1043 | else if (pExynosPort->bufferProcessType & BUFFER_COPY) { |
| 1044 | pExynosPort->processData.dataBuffer = pDataBuffer->bufferHeader->pBuffer; |
| 1045 | pExynosPort->processData.allocSize = pDataBuffer->bufferHeader->nAllocLen; |
| 1046 | } |
| 1047 | */ |
| 1048 | Exynos_OSAL_Free(pMessage); |
| 1049 | } |
| 1050 | ret = OMX_ErrorNone; |
| 1051 | } |
| 1052 | EXIT: |
| 1053 | FunctionOut(); |
| 1054 | |
| 1055 | return ret; |
| 1056 | } |
| 1057 | |
| 1058 | OMX_BUFFERHEADERTYPE *Exynos_OutputBufferGetQueue_Direct( |
| 1059 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent) |
| 1060 | { |
| 1061 | OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; |
| 1062 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1063 | EXYNOS_OMX_MESSAGE *pMessage = NULL; |
| 1064 | |
| 1065 | FunctionIn(); |
| 1066 | |
| 1067 | if (pExynosComponent == NULL) { |
| 1068 | pBufferHdr = NULL; |
| 1069 | goto EXIT; |
| 1070 | } |
| 1071 | pExynosPort = &(pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]); |
| 1072 | |
| 1073 | if (pExynosComponent->currentState != OMX_StateExecuting) { |
| 1074 | pBufferHdr = NULL; |
| 1075 | goto EXIT; |
| 1076 | } else if ((pExynosComponent->transientState != EXYNOS_OMX_TransStateExecutingToIdle) && |
| 1077 | (!CHECK_PORT_BEING_FLUSHED(pExynosPort))) { |
| 1078 | Exynos_OSAL_SemaphoreWait(pExynosPort->bufferSemID); |
| 1079 | |
| 1080 | pMessage = (EXYNOS_OMX_MESSAGE *)Exynos_OSAL_Dequeue(&pExynosPort->bufferQ); |
| 1081 | if (pMessage == NULL) { |
| 1082 | pBufferHdr = NULL; |
| 1083 | goto EXIT; |
| 1084 | } |
| 1085 | if (pMessage->messageType == EXYNOS_OMX_CommandFakeBuffer) { |
| 1086 | Exynos_OSAL_Free(pMessage); |
| 1087 | pBufferHdr = NULL; |
| 1088 | goto EXIT; |
| 1089 | } |
| 1090 | |
| 1091 | pBufferHdr = (OMX_BUFFERHEADERTYPE *)(pMessage->pCmdData); |
| 1092 | Exynos_OSAL_Free(pMessage); |
| 1093 | } |
| 1094 | |
| 1095 | EXIT: |
| 1096 | FunctionOut(); |
| 1097 | |
| 1098 | return pBufferHdr; |
| 1099 | } |
| 1100 | |
| 1101 | OMX_ERRORTYPE Exynos_CodecBufferEnqueue( |
| 1102 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent, |
| 1103 | OMX_U32 nPortIndex, |
| 1104 | OMX_PTR pData) |
| 1105 | { |
| 1106 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1107 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1108 | |
| 1109 | FunctionIn(); |
| 1110 | |
| 1111 | if (pExynosComponent == NULL) { |
| 1112 | ret = OMX_ErrorBadParameter; |
| 1113 | goto EXIT; |
| 1114 | } |
| 1115 | |
| 1116 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1117 | ret = OMX_ErrorBadPortIndex; |
| 1118 | goto EXIT; |
| 1119 | } |
| 1120 | pExynosPort = &(pExynosComponent->pExynosPort[nPortIndex]); |
| 1121 | |
| 1122 | if (pData == NULL) { |
| 1123 | ret = OMX_ErrorInsufficientResources; |
| 1124 | goto EXIT; |
| 1125 | } |
| 1126 | |
| 1127 | ret = Exynos_OSAL_Queue(&pExynosPort->codecBufferQ, (void *)pData); |
| 1128 | if (ret != 0) { |
| 1129 | ret = OMX_ErrorUndefined; |
| 1130 | goto EXIT; |
| 1131 | } |
| 1132 | Exynos_OSAL_SemaphorePost(pExynosPort->codecSemID); |
| 1133 | |
| 1134 | ret = OMX_ErrorNone; |
| 1135 | |
| 1136 | EXIT: |
| 1137 | FunctionOut(); |
| 1138 | |
| 1139 | return ret; |
| 1140 | } |
| 1141 | |
| 1142 | OMX_ERRORTYPE Exynos_CodecBufferDequeue( |
| 1143 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent, |
| 1144 | OMX_U32 nPortIndex, |
| 1145 | OMX_PTR *pData) |
| 1146 | { |
| 1147 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1148 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1149 | OMX_PTR pTempData = NULL; |
| 1150 | |
| 1151 | FunctionIn(); |
| 1152 | |
| 1153 | if (pExynosComponent == NULL) { |
| 1154 | ret = OMX_ErrorBadParameter; |
| 1155 | goto EXIT; |
| 1156 | } |
| 1157 | |
| 1158 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1159 | ret = OMX_ErrorBadPortIndex; |
| 1160 | goto EXIT; |
| 1161 | } |
| 1162 | pExynosPort = &(pExynosComponent->pExynosPort[nPortIndex]); |
| 1163 | |
| 1164 | Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID); |
| 1165 | pTempData = (OMX_PTR)Exynos_OSAL_Dequeue(&pExynosPort->codecBufferQ); |
| 1166 | if (pTempData != NULL) { |
| 1167 | *pData = (OMX_PTR)pTempData; |
| 1168 | ret = OMX_ErrorNone; |
| 1169 | } else { |
| 1170 | *pData = NULL; |
| 1171 | ret = OMX_ErrorUndefined; |
| 1172 | } |
| 1173 | |
| 1174 | EXIT: |
| 1175 | FunctionOut(); |
| 1176 | |
| 1177 | return ret; |
| 1178 | } |
| 1179 | |
| 1180 | OMX_ERRORTYPE Exynos_CodecBufferReset( |
| 1181 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent, |
| 1182 | OMX_U32 nPortIndex) |
| 1183 | { |
| 1184 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1185 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1186 | |
| 1187 | FunctionIn(); |
| 1188 | |
| 1189 | if (pExynosComponent == NULL) { |
| 1190 | ret = OMX_ErrorBadParameter; |
| 1191 | goto EXIT; |
| 1192 | } |
| 1193 | |
| 1194 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1195 | ret = OMX_ErrorBadPortIndex; |
| 1196 | goto EXIT; |
| 1197 | } |
| 1198 | pExynosPort = &(pExynosComponent->pExynosPort[nPortIndex]); |
| 1199 | |
| 1200 | ret = Exynos_OSAL_ResetQueue(&pExynosPort->codecBufferQ); |
| 1201 | if (ret != 0) { |
| 1202 | ret = OMX_ErrorUndefined; |
| 1203 | goto EXIT; |
| 1204 | } |
| 1205 | |
| 1206 | while (1) { |
| 1207 | int cnt = 0; |
| 1208 | Exynos_OSAL_Get_SemaphoreCount(pExynosPort->codecSemID, &cnt); |
| 1209 | if (cnt > 0) |
| 1210 | Exynos_OSAL_SemaphoreWait(pExynosPort->codecSemID); |
| 1211 | else |
| 1212 | break; |
| 1213 | } |
| 1214 | ret = OMX_ErrorNone; |
| 1215 | |
| 1216 | EXIT: |
| 1217 | FunctionOut(); |
| 1218 | |
| 1219 | return ret; |
| 1220 | } |
| 1221 | |
| 1222 | OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetParameter( |
| 1223 | OMX_IN OMX_HANDLETYPE hComponent, |
| 1224 | OMX_IN OMX_INDEXTYPE nParamIndex, |
| 1225 | OMX_INOUT OMX_PTR pComponentParameterStructure) |
| 1226 | { |
| 1227 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1228 | OMX_COMPONENTTYPE *pOMXComponent = NULL; |
| 1229 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 1230 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1231 | |
| 1232 | FunctionIn(); |
| 1233 | |
| 1234 | if (hComponent == NULL) { |
| 1235 | ret = OMX_ErrorBadParameter; |
| 1236 | goto EXIT; |
| 1237 | } |
| 1238 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 1239 | |
| 1240 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 1241 | if (ret != OMX_ErrorNone) { |
| 1242 | goto EXIT; |
| 1243 | } |
| 1244 | |
| 1245 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 1246 | ret = OMX_ErrorBadParameter; |
| 1247 | goto EXIT; |
| 1248 | } |
| 1249 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 1250 | |
| 1251 | if (pExynosComponent->currentState == OMX_StateInvalid) { |
| 1252 | ret = OMX_ErrorInvalidState; |
| 1253 | goto EXIT; |
| 1254 | } |
| 1255 | |
| 1256 | if (pComponentParameterStructure == NULL) { |
| 1257 | ret = OMX_ErrorBadParameter; |
| 1258 | goto EXIT; |
| 1259 | } |
| 1260 | |
| 1261 | switch (nParamIndex) { |
| 1262 | case OMX_IndexParamVideoInit: |
| 1263 | { |
| 1264 | OMX_PORT_PARAM_TYPE *pPortParam = (OMX_PORT_PARAM_TYPE *)pComponentParameterStructure; |
| 1265 | ret = Exynos_OMX_Check_SizeVersion(pPortParam, sizeof(OMX_PORT_PARAM_TYPE)); |
| 1266 | if (ret != OMX_ErrorNone) { |
| 1267 | goto EXIT; |
| 1268 | } |
| 1269 | |
| 1270 | pPortParam->nPorts = pExynosComponent->portParam.nPorts; |
| 1271 | pPortParam->nStartPortNumber = pExynosComponent->portParam.nStartPortNumber; |
| 1272 | ret = OMX_ErrorNone; |
| 1273 | } |
| 1274 | break; |
| 1275 | case OMX_IndexParamVideoPortFormat: |
| 1276 | { |
| 1277 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; |
| 1278 | OMX_U32 nPortIndex = pPortFormat->nPortIndex; |
| 1279 | OMX_U32 nIndex = pPortFormat->nIndex; |
| 1280 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1281 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; |
| 1282 | OMX_U32 nSupportFormat = 0; |
| 1283 | |
| 1284 | ret = Exynos_OMX_Check_SizeVersion(pPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); |
| 1285 | if (ret != OMX_ErrorNone) { |
| 1286 | goto EXIT; |
| 1287 | } |
| 1288 | |
| 1289 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1290 | ret = OMX_ErrorBadPortIndex; |
| 1291 | goto EXIT; |
| 1292 | } |
| 1293 | |
| 1294 | if (nPortIndex == INPUT_PORT_INDEX) { |
| 1295 | pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX]; |
| 1296 | pPortDef = &pExynosPort->portDefinition; |
| 1297 | |
| 1298 | switch (nIndex) { |
| 1299 | case supportFormat_0: |
| 1300 | pPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 1301 | pPortFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar; |
| 1302 | pPortFormat->xFramerate = pPortDef->format.video.xFramerate; |
| 1303 | break; |
| 1304 | case supportFormat_1: |
| 1305 | pPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 1306 | pPortFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; |
| 1307 | pPortFormat->xFramerate = pPortDef->format.video.xFramerate; |
| 1308 | break; |
| 1309 | case supportFormat_2: |
| 1310 | pPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 1311 | pPortFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12Tiled; |
| 1312 | pPortFormat->xFramerate = pPortDef->format.video.xFramerate; |
| 1313 | break; |
| 1314 | case supportFormat_3: |
| 1315 | pPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 1316 | pPortFormat->eColorFormat = OMX_SEC_COLOR_FormatNV21Linear; |
| 1317 | pPortFormat->xFramerate = pPortDef->format.video.xFramerate; |
| 1318 | break; |
| 1319 | case supportFormat_4: |
| 1320 | pPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; |
| 1321 | pPortFormat->eColorFormat = OMX_COLOR_FormatAndroidOpaque; |
| 1322 | pPortFormat->xFramerate = pPortDef->format.video.xFramerate; |
| 1323 | break; |
| 1324 | default: |
| 1325 | if (nIndex > supportFormat_0) { |
| 1326 | ret = OMX_ErrorNoMore; |
| 1327 | goto EXIT; |
| 1328 | } |
| 1329 | break; |
| 1330 | } |
| 1331 | } else if (nPortIndex == OUTPUT_PORT_INDEX) { |
| 1332 | nSupportFormat = OUTPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1; |
| 1333 | if (nIndex > nSupportFormat) { |
| 1334 | ret = OMX_ErrorNoMore; |
| 1335 | goto EXIT; |
| 1336 | } |
| 1337 | |
| 1338 | pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; |
| 1339 | pPortDef = &pExynosPort->portDefinition; |
| 1340 | |
| 1341 | pPortFormat->eCompressionFormat = pPortDef->format.video.eCompressionFormat; |
| 1342 | pPortFormat->eColorFormat = pPortDef->format.video.eColorFormat; |
| 1343 | pPortFormat->xFramerate = pPortDef->format.video.xFramerate; |
| 1344 | } |
| 1345 | ret = OMX_ErrorNone; |
| 1346 | } |
| 1347 | break; |
| 1348 | case OMX_IndexParamVideoBitrate: |
| 1349 | { |
| 1350 | OMX_VIDEO_PARAM_BITRATETYPE *pVideoBitrate = (OMX_VIDEO_PARAM_BITRATETYPE *)pComponentParameterStructure; |
| 1351 | OMX_U32 nPortIndex = pVideoBitrate->nPortIndex; |
| 1352 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1353 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 1354 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; |
| 1355 | |
| 1356 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1357 | ret = OMX_ErrorBadPortIndex; |
| 1358 | goto EXIT; |
| 1359 | } else { |
| 1360 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1361 | if (pVideoEnc == NULL) { |
| 1362 | ret = OMX_ErrorBadParameter; |
| 1363 | goto EXIT; |
| 1364 | } |
| 1365 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1366 | pPortDef = &pExynosPort->portDefinition; |
| 1367 | |
| 1368 | pVideoBitrate->eControlRate = pVideoEnc->eControlRate[nPortIndex]; |
| 1369 | pVideoBitrate->nTargetBitrate = pPortDef->format.video.nBitrate; |
| 1370 | } |
| 1371 | ret = OMX_ErrorNone; |
| 1372 | } |
| 1373 | break; |
| 1374 | case OMX_IndexParamVideoQuantization: |
| 1375 | { |
| 1376 | OMX_VIDEO_PARAM_QUANTIZATIONTYPE *pVideoQuantization = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pComponentParameterStructure; |
| 1377 | OMX_U32 nPortIndex = pVideoQuantization->nPortIndex; |
| 1378 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1379 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 1380 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; |
| 1381 | |
| 1382 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1383 | ret = OMX_ErrorBadPortIndex; |
| 1384 | goto EXIT; |
| 1385 | } else { |
| 1386 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1387 | if (pVideoEnc == NULL) { |
| 1388 | ret = OMX_ErrorBadParameter; |
| 1389 | goto EXIT; |
| 1390 | } |
| 1391 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1392 | pPortDef = &pExynosPort->portDefinition; |
| 1393 | |
| 1394 | pVideoQuantization->nQpI = pVideoEnc->quantization.nQpI; |
| 1395 | pVideoQuantization->nQpP = pVideoEnc->quantization.nQpP; |
| 1396 | pVideoQuantization->nQpB = pVideoEnc->quantization.nQpB; |
| 1397 | } |
| 1398 | ret = OMX_ErrorNone; |
| 1399 | } |
| 1400 | break; |
| 1401 | case OMX_IndexParamPortDefinition: |
| 1402 | { |
| 1403 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParameterStructure; |
| 1404 | OMX_U32 nPortIndex = pPortDef->nPortIndex; |
| 1405 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1406 | |
| 1407 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1408 | ret = OMX_ErrorBadPortIndex; |
| 1409 | goto EXIT; |
| 1410 | } |
| 1411 | |
| 1412 | ret = Exynos_OMX_Check_SizeVersion(pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); |
| 1413 | if (ret != OMX_ErrorNone) { |
| 1414 | goto EXIT; |
| 1415 | } |
| 1416 | |
| 1417 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1418 | Exynos_OSAL_Memcpy(pPortDef, &pExynosPort->portDefinition, pPortDef->nSize); |
| 1419 | |
| 1420 | #ifdef USE_STOREMETADATA |
| 1421 | if ((nPortIndex == 0) && |
| 1422 | (pExynosPort->bStoreMetaData == OMX_TRUE)) { |
| 1423 | pPortDef->nBufferSize = MAX_INPUT_METADATA_BUFFER_SIZE; |
| 1424 | } |
| 1425 | #endif |
| 1426 | } |
| 1427 | break; |
| 1428 | case OMX_IndexVendorNeedContigMemory: |
| 1429 | { |
| 1430 | EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *pPortMemType = (EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *)pComponentParameterStructure; |
| 1431 | OMX_U32 nPortIndex = pPortMemType->nPortIndex; |
| 1432 | EXYNOS_OMX_BASEPORT *pExynosPort; |
| 1433 | |
| 1434 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1435 | ret = OMX_ErrorBadPortIndex; |
| 1436 | goto EXIT; |
| 1437 | } |
| 1438 | |
| 1439 | ret = Exynos_OMX_Check_SizeVersion(pPortMemType, sizeof(EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE)); |
| 1440 | if (ret != OMX_ErrorNone) |
| 1441 | goto EXIT; |
| 1442 | |
| 1443 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1444 | |
| 1445 | pPortMemType->bNeedContigMem = pExynosPort->bNeedContigMem; |
| 1446 | } |
| 1447 | break; |
| 1448 | case OMX_IndexParamVideoIntraRefresh: |
| 1449 | { |
| 1450 | OMX_VIDEO_PARAM_INTRAREFRESHTYPE *pIntraRefresh = (OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)pComponentParameterStructure; |
| 1451 | OMX_U32 nPortIndex = pIntraRefresh->nPortIndex; |
| 1452 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 1453 | |
| 1454 | ret = Exynos_OMX_Check_SizeVersion(pIntraRefresh, sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE)); |
| 1455 | if (ret != OMX_ErrorNone) |
| 1456 | goto EXIT; |
| 1457 | |
| 1458 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1459 | ret = OMX_ErrorBadPortIndex; |
| 1460 | goto EXIT; |
| 1461 | } |
| 1462 | |
| 1463 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1464 | pIntraRefresh->eRefreshMode = pVideoEnc->intraRefresh.eRefreshMode; |
| 1465 | pIntraRefresh->nAirMBs = pVideoEnc->intraRefresh.nAirMBs; |
| 1466 | pIntraRefresh->nAirRef = pVideoEnc->intraRefresh.nAirRef; |
| 1467 | pIntraRefresh->nCirMBs = pVideoEnc->intraRefresh.nCirMBs; |
| 1468 | |
| 1469 | ret = OMX_ErrorNone; |
| 1470 | } |
| 1471 | break; |
| 1472 | default: |
| 1473 | { |
| 1474 | ret = Exynos_OMX_GetParameter(hComponent, nParamIndex, pComponentParameterStructure); |
| 1475 | } |
| 1476 | break; |
| 1477 | } |
| 1478 | EXIT: |
| 1479 | FunctionOut(); |
| 1480 | |
| 1481 | return ret; |
| 1482 | } |
| 1483 | |
| 1484 | OMX_ERRORTYPE Exynos_OMX_VideoEncodeSetParameter( |
| 1485 | OMX_IN OMX_HANDLETYPE hComponent, |
| 1486 | OMX_IN OMX_INDEXTYPE nParamIndex, |
| 1487 | OMX_IN OMX_PTR pComponentParameterStructure) |
| 1488 | { |
| 1489 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1490 | OMX_COMPONENTTYPE *pOMXComponent = NULL; |
| 1491 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 1492 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1493 | |
| 1494 | FunctionIn(); |
| 1495 | |
| 1496 | if (hComponent == NULL) { |
| 1497 | ret = OMX_ErrorBadParameter; |
| 1498 | goto EXIT; |
| 1499 | } |
| 1500 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 1501 | |
| 1502 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 1503 | if (ret != OMX_ErrorNone) { |
| 1504 | goto EXIT; |
| 1505 | } |
| 1506 | |
| 1507 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 1508 | ret = OMX_ErrorBadParameter; |
| 1509 | goto EXIT; |
| 1510 | } |
| 1511 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 1512 | |
| 1513 | if (pExynosComponent->currentState == OMX_StateInvalid) { |
| 1514 | ret = OMX_ErrorInvalidState; |
| 1515 | goto EXIT; |
| 1516 | } |
| 1517 | |
| 1518 | if (pComponentParameterStructure == NULL) { |
| 1519 | ret = OMX_ErrorBadParameter; |
| 1520 | goto EXIT; |
| 1521 | } |
| 1522 | |
| 1523 | switch (nParamIndex) { |
| 1524 | case OMX_IndexParamVideoPortFormat: |
| 1525 | { |
| 1526 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; |
| 1527 | OMX_U32 nPortIndex = pPortFormat->nPortIndex; |
| 1528 | OMX_U32 nIndex = pPortFormat->nIndex; |
| 1529 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; |
| 1530 | OMX_U32 nSupportFormat = 0; |
| 1531 | |
| 1532 | ret = Exynos_OMX_Check_SizeVersion(pPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); |
| 1533 | if (ret != OMX_ErrorNone) { |
| 1534 | goto EXIT; |
| 1535 | } |
| 1536 | |
| 1537 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1538 | ret = OMX_ErrorBadPortIndex; |
| 1539 | goto EXIT; |
| 1540 | } |
| 1541 | pPortDef = &(pExynosComponent->pExynosPort[nPortIndex].portDefinition); |
| 1542 | |
| 1543 | pPortDef->format.video.eColorFormat = pPortFormat->eColorFormat; |
| 1544 | pPortDef->format.video.eCompressionFormat = pPortFormat->eCompressionFormat; |
| 1545 | pPortDef->format.video.xFramerate = pPortFormat->xFramerate; |
| 1546 | } |
| 1547 | break; |
| 1548 | case OMX_IndexParamVideoBitrate: |
| 1549 | { |
| 1550 | OMX_VIDEO_PARAM_BITRATETYPE *pVideoBitrate = (OMX_VIDEO_PARAM_BITRATETYPE *)pComponentParameterStructure; |
| 1551 | OMX_U32 nPortIndex = pVideoBitrate->nPortIndex; |
| 1552 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1553 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 1554 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; |
| 1555 | |
| 1556 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1557 | ret = OMX_ErrorBadPortIndex; |
| 1558 | goto EXIT; |
| 1559 | } else { |
| 1560 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1561 | if (pVideoEnc == NULL) { |
| 1562 | ret = OMX_ErrorBadParameter; |
| 1563 | goto EXIT; |
| 1564 | } |
| 1565 | pPortDef = &(pExynosComponent->pExynosPort[nPortIndex].portDefinition); |
| 1566 | |
| 1567 | pVideoEnc->eControlRate[nPortIndex] = pVideoBitrate->eControlRate; |
| 1568 | pPortDef->format.video.nBitrate = pVideoBitrate->nTargetBitrate; |
| 1569 | } |
| 1570 | ret = OMX_ErrorNone; |
| 1571 | } |
| 1572 | break; |
| 1573 | case OMX_IndexParamVideoQuantization: |
| 1574 | { |
| 1575 | OMX_VIDEO_PARAM_QUANTIZATIONTYPE *pVideoQuantization = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pComponentParameterStructure; |
| 1576 | OMX_U32 nPortIndex = pVideoQuantization->nPortIndex; |
| 1577 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1578 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 1579 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; |
| 1580 | |
| 1581 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1582 | ret = OMX_ErrorBadPortIndex; |
| 1583 | goto EXIT; |
| 1584 | } else { |
| 1585 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1586 | if (pVideoEnc == NULL) { |
| 1587 | ret = OMX_ErrorBadParameter; |
| 1588 | goto EXIT; |
| 1589 | } |
| 1590 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1591 | pPortDef = &pExynosPort->portDefinition; |
| 1592 | |
| 1593 | pVideoEnc->quantization.nQpI = pVideoQuantization->nQpI; |
| 1594 | pVideoEnc->quantization.nQpP = pVideoQuantization->nQpP; |
| 1595 | pVideoEnc->quantization.nQpB = pVideoQuantization->nQpB; |
| 1596 | } |
| 1597 | ret = OMX_ErrorNone; |
| 1598 | } |
| 1599 | break; |
| 1600 | case OMX_IndexParamPortDefinition: |
| 1601 | { |
| 1602 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParameterStructure; |
| 1603 | OMX_U32 nPortIndex = pPortDef->nPortIndex; |
| 1604 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1605 | OMX_U32 width, height, size; |
| 1606 | |
| 1607 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1608 | ret = OMX_ErrorBadPortIndex; |
| 1609 | goto EXIT; |
| 1610 | } |
| 1611 | |
| 1612 | ret = Exynos_OMX_Check_SizeVersion(pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); |
| 1613 | if (ret != OMX_ErrorNone) { |
| 1614 | goto EXIT; |
| 1615 | } |
| 1616 | |
| 1617 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1618 | |
| 1619 | if ((pExynosComponent->currentState != OMX_StateLoaded) && |
| 1620 | (pExynosComponent->currentState != OMX_StateWaitForResources)) { |
| 1621 | if (pExynosPort->portDefinition.bEnabled == OMX_TRUE) { |
| 1622 | ret = OMX_ErrorIncorrectStateOperation; |
| 1623 | goto EXIT; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | if (pPortDef->nBufferCountActual < pExynosPort->portDefinition.nBufferCountMin) { |
| 1628 | ret = OMX_ErrorBadParameter; |
| 1629 | goto EXIT; |
| 1630 | } |
| 1631 | |
| 1632 | Exynos_OSAL_Memcpy(&pExynosPort->portDefinition, pPortDef, pPortDef->nSize); |
| 1633 | if (nPortIndex == INPUT_PORT_INDEX) { |
| 1634 | pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX]; |
| 1635 | Exynos_UpdateFrameSize(pOMXComponent); |
| 1636 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "pExynosOutputPort->portDefinition.nBufferSize: %d", |
| 1637 | pExynosPort->portDefinition.nBufferSize); |
| 1638 | } |
| 1639 | ret = OMX_ErrorNone; |
| 1640 | } |
| 1641 | break; |
| 1642 | #ifdef USE_STOREMETADATA |
| 1643 | case OMX_IndexParamStoreMetaDataBuffer: |
| 1644 | { |
| 1645 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1646 | if (pVideoEnc == NULL) { |
| 1647 | ret = OMX_ErrorBadParameter; |
| 1648 | goto EXIT; |
| 1649 | } |
| 1650 | |
| 1651 | ret = Exynos_OSAL_SetANBParameter(hComponent, nParamIndex, pComponentParameterStructure); |
| 1652 | if (ret == OMX_ErrorNone) |
| 1653 | pVideoEnc->bFirstInput = OMX_TRUE; |
| 1654 | } |
| 1655 | break; |
| 1656 | #endif |
| 1657 | case OMX_IndexVendorNeedContigMemory: |
| 1658 | { |
| 1659 | EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *pPortMemType = (EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE *)pComponentParameterStructure; |
| 1660 | OMX_U32 nPortIndex = pPortMemType->nPortIndex; |
| 1661 | EXYNOS_OMX_BASEPORT *pExynosPort; |
| 1662 | |
| 1663 | if (nPortIndex >= pExynosComponent->portParam.nPorts) { |
| 1664 | ret = OMX_ErrorBadPortIndex; |
| 1665 | goto EXIT; |
| 1666 | } |
| 1667 | |
| 1668 | ret = Exynos_OMX_Check_SizeVersion(pPortMemType, sizeof(EXYNOS_OMX_VIDEO_PARAM_PORTMEMTYPE)); |
| 1669 | if (ret != OMX_ErrorNone) |
| 1670 | goto EXIT; |
| 1671 | |
| 1672 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1673 | |
| 1674 | if ((pExynosComponent->currentState != OMX_StateLoaded) && (pExynosComponent->currentState != OMX_StateWaitForResources)) { |
| 1675 | if (pExynosPort->portDefinition.bEnabled == OMX_TRUE) { |
| 1676 | ret = OMX_ErrorIncorrectStateOperation; |
| 1677 | goto EXIT; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | pExynosPort->bNeedContigMem = pPortMemType->bNeedContigMem; |
| 1682 | } |
| 1683 | break; |
| 1684 | case OMX_IndexParamVideoIntraRefresh: |
| 1685 | { |
| 1686 | OMX_VIDEO_PARAM_INTRAREFRESHTYPE *pIntraRefresh = (OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)pComponentParameterStructure; |
| 1687 | OMX_U32 nPortIndex = pIntraRefresh->nPortIndex; |
| 1688 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 1689 | |
| 1690 | ret = Exynos_OMX_Check_SizeVersion(pIntraRefresh, sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE)); |
| 1691 | if (ret != OMX_ErrorNone) |
| 1692 | goto EXIT; |
| 1693 | |
| 1694 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1695 | ret = OMX_ErrorBadPortIndex; |
| 1696 | goto EXIT; |
| 1697 | } |
| 1698 | |
| 1699 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1700 | if (pIntraRefresh->eRefreshMode == OMX_VIDEO_IntraRefreshCyclic) { |
| 1701 | pVideoEnc->intraRefresh.eRefreshMode = pIntraRefresh->eRefreshMode; |
| 1702 | pVideoEnc->intraRefresh.nCirMBs = pIntraRefresh->nCirMBs; |
| 1703 | Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "OMX_VIDEO_IntraRefreshCyclic Enable, nCirMBs: %d", |
| 1704 | pVideoEnc->intraRefresh.nCirMBs); |
| 1705 | } else { |
| 1706 | ret = OMX_ErrorUnsupportedSetting; |
| 1707 | goto EXIT; |
| 1708 | } |
| 1709 | |
| 1710 | ret = OMX_ErrorNone; |
| 1711 | } |
| 1712 | break; |
| 1713 | default: |
| 1714 | { |
| 1715 | ret = Exynos_OMX_SetParameter(hComponent, nParamIndex, pComponentParameterStructure); |
| 1716 | } |
| 1717 | break; |
| 1718 | } |
| 1719 | EXIT: |
| 1720 | FunctionOut(); |
| 1721 | |
| 1722 | return ret; |
| 1723 | } |
| 1724 | |
| 1725 | OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetConfig( |
| 1726 | OMX_HANDLETYPE hComponent, |
| 1727 | OMX_INDEXTYPE nParamIndex, |
| 1728 | OMX_PTR pComponentConfigStructure) |
| 1729 | { |
| 1730 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1731 | OMX_COMPONENTTYPE *pOMXComponent = NULL; |
| 1732 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 1733 | |
| 1734 | FunctionIn(); |
| 1735 | |
| 1736 | if ((hComponent == NULL) || |
| 1737 | (pComponentConfigStructure == NULL)) { |
| 1738 | ret = OMX_ErrorBadParameter; |
| 1739 | goto EXIT; |
| 1740 | } |
| 1741 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 1742 | |
| 1743 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 1744 | if (ret != OMX_ErrorNone) { |
| 1745 | goto EXIT; |
| 1746 | } |
| 1747 | |
| 1748 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 1749 | ret = OMX_ErrorBadParameter; |
| 1750 | goto EXIT; |
| 1751 | } |
| 1752 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 1753 | |
| 1754 | if (pExynosComponent->currentState == OMX_StateInvalid) { |
| 1755 | ret = OMX_ErrorInvalidState; |
| 1756 | goto EXIT; |
| 1757 | } |
| 1758 | |
| 1759 | switch (nParamIndex) { |
| 1760 | case OMX_IndexConfigVideoBitrate: |
| 1761 | { |
| 1762 | OMX_VIDEO_CONFIG_BITRATETYPE *pConfigBitrate = (OMX_VIDEO_CONFIG_BITRATETYPE *)pComponentConfigStructure; |
| 1763 | OMX_U32 nPortIndex = pConfigBitrate->nPortIndex; |
| 1764 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1765 | |
| 1766 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1767 | ret = OMX_ErrorBadPortIndex; |
| 1768 | goto EXIT; |
| 1769 | } else { |
| 1770 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1771 | pConfigBitrate->nEncodeBitrate = pExynosPort->portDefinition.format.video.nBitrate; |
| 1772 | } |
| 1773 | } |
| 1774 | break; |
| 1775 | case OMX_IndexConfigVideoFramerate: |
| 1776 | { |
| 1777 | OMX_CONFIG_FRAMERATETYPE *pConfigFramerate = (OMX_CONFIG_FRAMERATETYPE *)pComponentConfigStructure; |
| 1778 | OMX_U32 nPortIndex = pConfigFramerate->nPortIndex; |
| 1779 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1780 | |
| 1781 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1782 | ret = OMX_ErrorBadPortIndex; |
| 1783 | goto EXIT; |
| 1784 | } else { |
| 1785 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1786 | pConfigFramerate->xEncodeFramerate = pExynosPort->portDefinition.format.video.xFramerate; |
| 1787 | } |
| 1788 | } |
| 1789 | break; |
| 1790 | case OMX_IndexVendorGetBufferFD: |
| 1791 | { |
| 1792 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1793 | EXYNOS_OMX_VIDEO_CONFIG_BUFFERINFO *pBufferInfo = (EXYNOS_OMX_VIDEO_CONFIG_BUFFERINFO *)pComponentConfigStructure; |
| 1794 | |
| 1795 | ret = Exynos_OMX_Check_SizeVersion(pBufferInfo, sizeof(EXYNOS_OMX_VIDEO_CONFIG_BUFFERINFO)); |
| 1796 | if (ret != OMX_ErrorNone) |
| 1797 | goto EXIT; |
| 1798 | |
| 1799 | pBufferInfo->fd = Exynos_OSAL_SharedMemory_VirtToION(pVideoEnc->hSharedMemory, pBufferInfo->pVirAddr); |
| 1800 | } |
| 1801 | break; |
| 1802 | default: |
| 1803 | { |
| 1804 | ret = Exynos_OMX_GetConfig(hComponent, nParamIndex, pComponentConfigStructure); |
| 1805 | } |
| 1806 | break; |
| 1807 | } |
| 1808 | EXIT: |
| 1809 | FunctionOut(); |
| 1810 | |
| 1811 | return ret; |
| 1812 | } |
| 1813 | |
| 1814 | OMX_ERRORTYPE Exynos_OMX_VideoEncodeSetConfig( |
| 1815 | OMX_HANDLETYPE hComponent, |
| 1816 | OMX_INDEXTYPE nParamIndex, |
| 1817 | OMX_PTR pComponentConfigStructure) |
| 1818 | { |
| 1819 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1820 | OMX_COMPONENTTYPE *pOMXComponent = NULL; |
| 1821 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 1822 | |
| 1823 | FunctionIn(); |
| 1824 | |
| 1825 | if ((hComponent == NULL) || |
| 1826 | (pComponentConfigStructure == NULL)) { |
| 1827 | ret = OMX_ErrorBadParameter; |
| 1828 | goto EXIT; |
| 1829 | } |
| 1830 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 1831 | |
| 1832 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 1833 | if (ret != OMX_ErrorNone) { |
| 1834 | goto EXIT; |
| 1835 | } |
| 1836 | |
| 1837 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 1838 | ret = OMX_ErrorBadParameter; |
| 1839 | goto EXIT; |
| 1840 | } |
| 1841 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 1842 | |
| 1843 | if (pExynosComponent->currentState == OMX_StateInvalid) { |
| 1844 | ret = OMX_ErrorInvalidState; |
| 1845 | goto EXIT; |
| 1846 | } |
| 1847 | |
| 1848 | switch (nParamIndex) { |
| 1849 | case OMX_IndexConfigVideoBitrate: |
| 1850 | { |
| 1851 | OMX_VIDEO_CONFIG_BITRATETYPE *pConfigBitrate = (OMX_VIDEO_CONFIG_BITRATETYPE *)pComponentConfigStructure; |
| 1852 | OMX_U32 nPortIndex = pConfigBitrate->nPortIndex; |
| 1853 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1854 | |
| 1855 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1856 | ret = OMX_ErrorBadPortIndex; |
| 1857 | goto EXIT; |
| 1858 | } else { |
| 1859 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1860 | pExynosPort->portDefinition.format.video.nBitrate = pConfigBitrate->nEncodeBitrate; |
| 1861 | } |
| 1862 | } |
| 1863 | break; |
| 1864 | case OMX_IndexConfigVideoFramerate: |
| 1865 | { |
| 1866 | OMX_CONFIG_FRAMERATETYPE *pConfigFramerate = (OMX_CONFIG_FRAMERATETYPE *)pComponentConfigStructure; |
| 1867 | OMX_U32 nPortIndex = pConfigFramerate->nPortIndex; |
| 1868 | EXYNOS_OMX_BASEPORT *pExynosPort = NULL; |
| 1869 | |
| 1870 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1871 | ret = OMX_ErrorBadPortIndex; |
| 1872 | goto EXIT; |
| 1873 | } else { |
| 1874 | pExynosPort = &pExynosComponent->pExynosPort[nPortIndex]; |
| 1875 | pExynosPort->portDefinition.format.video.xFramerate = pConfigFramerate->xEncodeFramerate; |
| 1876 | } |
| 1877 | } |
| 1878 | break; |
| 1879 | case OMX_IndexConfigVideoIntraVOPRefresh: |
| 1880 | { |
| 1881 | OMX_CONFIG_INTRAREFRESHVOPTYPE *pIntraRefreshVOP = (OMX_CONFIG_INTRAREFRESHVOPTYPE *)pComponentConfigStructure; |
| 1882 | EXYNOS_OMX_VIDEOENC_COMPONENT *pVideoEnc = NULL; |
| 1883 | OMX_U32 nPortIndex = pIntraRefreshVOP->nPortIndex; |
| 1884 | |
| 1885 | if (pExynosComponent->hComponentHandle == NULL) { |
| 1886 | ret = OMX_ErrorBadParameter; |
| 1887 | goto EXIT; |
| 1888 | } |
| 1889 | pVideoEnc = (EXYNOS_OMX_VIDEOENC_COMPONENT *)pExynosComponent->hComponentHandle; |
| 1890 | |
| 1891 | if (nPortIndex != OUTPUT_PORT_INDEX) { |
| 1892 | ret = OMX_ErrorBadPortIndex; |
| 1893 | goto EXIT; |
| 1894 | } else { |
| 1895 | pVideoEnc->IntraRefreshVOP = pIntraRefreshVOP->IntraRefreshVOP; |
| 1896 | } |
| 1897 | } |
| 1898 | break; |
| 1899 | default: |
| 1900 | { |
| 1901 | ret = Exynos_OMX_SetConfig(hComponent, nParamIndex, pComponentConfigStructure); |
| 1902 | } |
| 1903 | break; |
| 1904 | } |
| 1905 | EXIT: |
| 1906 | FunctionOut(); |
| 1907 | |
| 1908 | return ret; |
| 1909 | } |
| 1910 | |
| 1911 | OMX_ERRORTYPE Exynos_OMX_VideoEncodeGetExtensionIndex( |
| 1912 | OMX_IN OMX_HANDLETYPE hComponent, |
| 1913 | OMX_IN OMX_STRING szParamName, |
| 1914 | OMX_OUT OMX_INDEXTYPE *pIndexType) |
| 1915 | { |
| 1916 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1917 | OMX_COMPONENTTYPE *pOMXComponent = NULL; |
| 1918 | EXYNOS_OMX_BASECOMPONENT *pExynosComponent = NULL; |
| 1919 | |
| 1920 | FunctionIn(); |
| 1921 | |
| 1922 | if (hComponent == NULL) { |
| 1923 | ret = OMX_ErrorBadParameter; |
| 1924 | goto EXIT; |
| 1925 | } |
| 1926 | pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; |
| 1927 | |
| 1928 | ret = Exynos_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); |
| 1929 | if (ret != OMX_ErrorNone) { |
| 1930 | goto EXIT; |
| 1931 | } |
| 1932 | |
| 1933 | if (pOMXComponent->pComponentPrivate == NULL) { |
| 1934 | ret = OMX_ErrorBadParameter; |
| 1935 | goto EXIT; |
| 1936 | } |
| 1937 | pExynosComponent = (EXYNOS_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; |
| 1938 | |
| 1939 | if ((szParamName == NULL) || (pIndexType == NULL)) { |
| 1940 | ret = OMX_ErrorBadParameter; |
| 1941 | goto EXIT; |
| 1942 | } |
| 1943 | |
| 1944 | if (pExynosComponent->currentState == OMX_StateInvalid) { |
| 1945 | ret = OMX_ErrorInvalidState; |
| 1946 | goto EXIT; |
| 1947 | } |
| 1948 | |
| 1949 | if (Exynos_OSAL_Strcmp(szParamName, EXYNOS_INDEX_PARAM_NEED_CONTIG_MEMORY) == 0) { |
| 1950 | *pIndexType = (OMX_INDEXTYPE) OMX_IndexVendorNeedContigMemory; |
| 1951 | ret = OMX_ErrorNone; |
| 1952 | goto EXIT; |
| 1953 | } else if (Exynos_OSAL_Strcmp(szParamName, EXYNOS_INDEX_CONFIG_GET_BUFFER_FD) == 0) { |
| 1954 | *pIndexType = (OMX_INDEXTYPE) OMX_IndexVendorGetBufferFD; |
| 1955 | ret = OMX_ErrorNone; |
| 1956 | goto EXIT; |
| 1957 | } |
| 1958 | |
| 1959 | #ifdef USE_STOREMETADATA |
| 1960 | if (Exynos_OSAL_Strcmp(szParamName, EXYNOS_INDEX_PARAM_STORE_METADATA_BUFFER) == 0) { |
| 1961 | *pIndexType = (OMX_INDEXTYPE)OMX_IndexParamStoreMetaDataBuffer; |
| 1962 | } else { |
| 1963 | ret = Exynos_OMX_GetExtensionIndex(hComponent, szParamName, pIndexType); |
| 1964 | } |
| 1965 | #else |
| 1966 | ret = Exynos_OMX_GetExtensionIndex(hComponent, szParamName, pIndexType); |
| 1967 | #endif |
| 1968 | EXIT: |
| 1969 | FunctionOut(); |
| 1970 | |
| 1971 | return ret; |
| 1972 | } |
| 1973 | |
| 1974 | OMX_ERRORTYPE Exynos_Shared_DataToBuffer(EXYNOS_OMX_DATA *pData, EXYNOS_OMX_DATABUFFER *pUseBuffer, OMX_BOOL bNeedUnlock) |
| 1975 | { |
| 1976 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 1977 | |
| 1978 | pUseBuffer->bufferHeader = pData->bufferHeader; |
| 1979 | pUseBuffer->allocSize = pData->allocSize; |
| 1980 | pUseBuffer->dataLen = pData->dataLen; |
| 1981 | pUseBuffer->usedDataLen = pData->usedDataLen; |
| 1982 | pUseBuffer->remainDataLen = pData->remainDataLen; |
| 1983 | pUseBuffer->timeStamp = pData->timeStamp; |
| 1984 | pUseBuffer->nFlags = pData->nFlags; |
| 1985 | pUseBuffer->pPrivate = pData->pPrivate; |
| 1986 | |
| 1987 | if ((bNeedUnlock == OMX_TRUE) && (pUseBuffer->bufferHeader != NULL)) { |
| 1988 | OMX_PTR ppBuf[MAX_BUFFER_PLANE]; |
| 1989 | Exynos_OSAL_GetInfoFromMetaData((OMX_BYTE)pUseBuffer->bufferHeader->pBuffer, ppBuf); |
| 1990 | Exynos_OSAL_UnlockANBHandle(ppBuf[0]); |
| 1991 | } |
| 1992 | |
| 1993 | return ret; |
| 1994 | } |