1 /* 2 * 3 * Copyright 2010 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 SEC_OMX_Venc.c 20 * @brief 21 * @author SeungBeom Kim (sbcrux.kim (at) samsung.com) 22 * Yunji Kim (yunji.kim (at) samsung.com) 23 * @version 1.0 24 * @history 25 * 2010.7.15 : Create 26 */ 27 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <string.h> 31 #include "SEC_OMX_Macros.h" 32 #include "SEC_OSAL_Event.h" 33 #include "SEC_OMX_Venc.h" 34 #include "SEC_OMX_Basecomponent.h" 35 #include "SEC_OSAL_Thread.h" 36 #include "color_space_convertor.h" 37 38 #undef SEC_LOG_TAG 39 #define SEC_LOG_TAG "SEC_VIDEO_ENC" 40 #define SEC_LOG_OFF 41 #include "SEC_OSAL_Log.h" 42 43 44 inline void SEC_UpdateFrameSize(OMX_COMPONENTTYPE *pOMXComponent) 45 { 46 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 47 SEC_OMX_BASEPORT *secInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 48 SEC_OMX_BASEPORT *secOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 49 50 if ((secOutputPort->portDefinition.format.video.nFrameWidth != 51 secInputPort->portDefinition.format.video.nFrameWidth) || 52 (secOutputPort->portDefinition.format.video.nFrameHeight != 53 secInputPort->portDefinition.format.video.nFrameHeight)) { 54 OMX_U32 width = 0, height = 0; 55 56 secOutputPort->portDefinition.format.video.nFrameWidth = 57 secInputPort->portDefinition.format.video.nFrameWidth; 58 secOutputPort->portDefinition.format.video.nFrameHeight = 59 secInputPort->portDefinition.format.video.nFrameHeight; 60 width = secOutputPort->portDefinition.format.video.nStride = 61 secInputPort->portDefinition.format.video.nStride; 62 height = secOutputPort->portDefinition.format.video.nSliceHeight = 63 secInputPort->portDefinition.format.video.nSliceHeight; 64 65 switch(secOutputPort->portDefinition.format.video.eColorFormat) { 66 case OMX_COLOR_FormatYUV420Planar: 67 case OMX_COLOR_FormatYUV420SemiPlanar: 68 if (width && height) 69 secOutputPort->portDefinition.nBufferSize = (width * height * 3) / 2; 70 break; 71 default: 72 if (width && height) 73 secOutputPort->portDefinition.nBufferSize = width * height * 2; 74 break; 75 } 76 } 77 78 return ; 79 } 80 81 OMX_ERRORTYPE SEC_OMX_UseBuffer( 82 OMX_IN OMX_HANDLETYPE hComponent, 83 OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr, 84 OMX_IN OMX_U32 nPortIndex, 85 OMX_IN OMX_PTR pAppPrivate, 86 OMX_IN OMX_U32 nSizeBytes, 87 OMX_IN OMX_U8 *pBuffer) 88 { 89 OMX_ERRORTYPE ret = OMX_ErrorNone; 90 OMX_COMPONENTTYPE *pOMXComponent = NULL; 91 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 92 SEC_OMX_BASEPORT *pSECPort = NULL; 93 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; 94 int i = 0; 95 96 FunctionIn(); 97 98 if (hComponent == NULL) { 99 ret = OMX_ErrorBadParameter; 100 goto EXIT; 101 } 102 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 103 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 104 if (ret != OMX_ErrorNone) { 105 goto EXIT; 106 } 107 108 if (pOMXComponent->pComponentPrivate == NULL) { 109 ret = OMX_ErrorBadParameter; 110 goto EXIT; 111 } 112 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 113 114 pSECPort = &pSECComponent->pSECPort[nPortIndex]; 115 if (nPortIndex >= pSECComponent->portParam.nPorts) { 116 ret = OMX_ErrorBadPortIndex; 117 goto EXIT; 118 } 119 if (pSECPort->portState != OMX_StateIdle) { 120 ret = OMX_ErrorIncorrectStateOperation; 121 goto EXIT; 122 } 123 124 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 125 ret = OMX_ErrorBadPortIndex; 126 goto EXIT; 127 } 128 129 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE)); 130 if (temp_bufferHeader == NULL) { 131 ret = OMX_ErrorInsufficientResources; 132 goto EXIT; 133 } 134 SEC_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE)); 135 136 for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) { 137 if (pSECPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) { 138 pSECPort->bufferHeader[i] = temp_bufferHeader; 139 pSECPort->bufferStateAllocate[i] = (BUFFER_STATE_ASSIGNED | HEADER_STATE_ALLOCATED); 140 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE); 141 temp_bufferHeader->pBuffer = pBuffer; 142 temp_bufferHeader->nAllocLen = nSizeBytes; 143 temp_bufferHeader->pAppPrivate = pAppPrivate; 144 if (nPortIndex == INPUT_PORT_INDEX) 145 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX; 146 else 147 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX; 148 149 pSECPort->assignedBufferNum++; 150 if (pSECPort->assignedBufferNum == pSECPort->portDefinition.nBufferCountActual) { 151 pSECPort->portDefinition.bPopulated = OMX_TRUE; 152 /* SEC_OSAL_MutexLock(pSECComponent->compMutex); */ 153 SEC_OSAL_SemaphorePost(pSECPort->loadedResource); 154 /* SEC_OSAL_MutexUnlock(pSECComponent->compMutex); */ 155 } 156 *ppBufferHdr = temp_bufferHeader; 157 ret = OMX_ErrorNone; 158 goto EXIT; 159 } 160 } 161 162 SEC_OSAL_Free(temp_bufferHeader); 163 ret = OMX_ErrorInsufficientResources; 164 165 EXIT: 166 FunctionOut(); 167 168 return ret; 169 } 170 171 OMX_ERRORTYPE SEC_OMX_AllocateBuffer( 172 OMX_IN OMX_HANDLETYPE hComponent, 173 OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer, 174 OMX_IN OMX_U32 nPortIndex, 175 OMX_IN OMX_PTR pAppPrivate, 176 OMX_IN OMX_U32 nSizeBytes) 177 { 178 OMX_ERRORTYPE ret = OMX_ErrorNone; 179 OMX_COMPONENTTYPE *pOMXComponent = NULL; 180 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 181 SEC_OMX_BASEPORT *pSECPort = NULL; 182 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; 183 OMX_U8 *temp_buffer = NULL; 184 int i = 0; 185 186 FunctionIn(); 187 188 if (hComponent == NULL) { 189 ret = OMX_ErrorBadParameter; 190 goto EXIT; 191 } 192 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 193 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 194 if (ret != OMX_ErrorNone) { 195 goto EXIT; 196 } 197 198 if (pOMXComponent->pComponentPrivate == NULL) { 199 ret = OMX_ErrorBadParameter; 200 goto EXIT; 201 } 202 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 203 204 pSECPort = &pSECComponent->pSECPort[nPortIndex]; 205 if (nPortIndex >= pSECComponent->portParam.nPorts) { 206 ret = OMX_ErrorBadPortIndex; 207 goto EXIT; 208 } 209 /* 210 if (pSECPort->portState != OMX_StateIdle ) { 211 ret = OMX_ErrorIncorrectStateOperation; 212 goto EXIT; 213 } 214 */ 215 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 216 ret = OMX_ErrorBadPortIndex; 217 goto EXIT; 218 } 219 220 temp_buffer = SEC_OSAL_Malloc(sizeof(OMX_U8) * nSizeBytes); 221 if (temp_buffer == NULL) { 222 ret = OMX_ErrorInsufficientResources; 223 goto EXIT; 224 } 225 226 temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE)); 227 if (temp_bufferHeader == NULL) { 228 SEC_OSAL_Free(temp_buffer); 229 temp_buffer = NULL; 230 ret = OMX_ErrorInsufficientResources; 231 goto EXIT; 232 } 233 SEC_OSAL_Memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE)); 234 235 for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) { 236 if (pSECPort->bufferStateAllocate[i] == BUFFER_STATE_FREE) { 237 pSECPort->bufferHeader[i] = temp_bufferHeader; 238 pSECPort->bufferStateAllocate[i] = (BUFFER_STATE_ALLOCATED | HEADER_STATE_ALLOCATED); 239 INIT_SET_SIZE_VERSION(temp_bufferHeader, OMX_BUFFERHEADERTYPE); 240 temp_bufferHeader->pBuffer = temp_buffer; 241 temp_bufferHeader->nAllocLen = nSizeBytes; 242 temp_bufferHeader->pAppPrivate = pAppPrivate; 243 if (nPortIndex == INPUT_PORT_INDEX) 244 temp_bufferHeader->nInputPortIndex = INPUT_PORT_INDEX; 245 else 246 temp_bufferHeader->nOutputPortIndex = OUTPUT_PORT_INDEX; 247 pSECPort->assignedBufferNum++; 248 if (pSECPort->assignedBufferNum == pSECPort->portDefinition.nBufferCountActual) { 249 pSECPort->portDefinition.bPopulated = OMX_TRUE; 250 /* SEC_OSAL_MutexLock(pSECComponent->compMutex); */ 251 SEC_OSAL_SemaphorePost(pSECPort->loadedResource); 252 /* SEC_OSAL_MutexUnlock(pSECComponent->compMutex); */ 253 } 254 *ppBuffer = temp_bufferHeader; 255 ret = OMX_ErrorNone; 256 goto EXIT; 257 } 258 } 259 260 SEC_OSAL_Free(temp_bufferHeader); 261 SEC_OSAL_Free(temp_buffer); 262 ret = OMX_ErrorInsufficientResources; 263 264 EXIT: 265 FunctionOut(); 266 267 return ret; 268 } 269 270 OMX_ERRORTYPE SEC_OMX_FreeBuffer( 271 OMX_IN OMX_HANDLETYPE hComponent, 272 OMX_IN OMX_U32 nPortIndex, 273 OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr) 274 { 275 OMX_ERRORTYPE ret = OMX_ErrorNone; 276 OMX_COMPONENTTYPE *pOMXComponent = NULL; 277 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 278 SEC_OMX_BASEPORT *pSECPort = NULL; 279 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; 280 OMX_U8 *temp_buffer = NULL; 281 int i = 0; 282 283 FunctionIn(); 284 285 if (hComponent == NULL) { 286 ret = OMX_ErrorBadParameter; 287 goto EXIT; 288 } 289 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 290 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 291 if (ret != OMX_ErrorNone) { 292 goto EXIT; 293 } 294 295 if (pOMXComponent->pComponentPrivate == NULL) { 296 ret = OMX_ErrorBadParameter; 297 goto EXIT; 298 } 299 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 300 pSECPort = &pSECComponent->pSECPort[nPortIndex]; 301 302 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 303 ret = OMX_ErrorBadPortIndex; 304 goto EXIT; 305 } 306 307 if ((pSECPort->portState != OMX_StateLoaded) && (pSECPort->portState != OMX_StateInvalid)) { 308 (*(pSECComponent->pCallbacks->EventHandler)) (pOMXComponent, 309 pSECComponent->callbackData, 310 (OMX_U32)OMX_EventError, 311 (OMX_U32)OMX_ErrorPortUnpopulated, 312 nPortIndex, NULL); 313 } 314 315 for (i = 0; i < pSECPort->portDefinition.nBufferCountActual; i++) { 316 if (((pSECPort->bufferStateAllocate[i] | BUFFER_STATE_FREE) != 0) && (pSECPort->bufferHeader[i] != NULL)) { 317 if (pSECPort->bufferHeader[i]->pBuffer == pBufferHdr->pBuffer) { 318 if (pSECPort->bufferStateAllocate[i] & BUFFER_STATE_ALLOCATED) { 319 SEC_OSAL_Free(pSECPort->bufferHeader[i]->pBuffer); 320 pSECPort->bufferHeader[i]->pBuffer = NULL; 321 pBufferHdr->pBuffer = NULL; 322 } else if (pSECPort->bufferStateAllocate[i] & BUFFER_STATE_ASSIGNED) { 323 ; /* None*/ 324 } 325 pSECPort->assignedBufferNum--; 326 if (pSECPort->bufferStateAllocate[i] & HEADER_STATE_ALLOCATED) { 327 SEC_OSAL_Free(pSECPort->bufferHeader[i]); 328 pSECPort->bufferHeader[i] = NULL; 329 pBufferHdr = NULL; 330 } 331 pSECPort->bufferStateAllocate[i] = BUFFER_STATE_FREE; 332 ret = OMX_ErrorNone; 333 goto EXIT; 334 } 335 } 336 } 337 338 EXIT: 339 if (ret == OMX_ErrorNone) { 340 if (pSECPort->assignedBufferNum == 0 ) { 341 SEC_OSAL_Log(SEC_LOG_TRACE, "pSECPort->unloadedResource signal set"); 342 /* SEC_OSAL_MutexLock(pSECComponent->compMutex); */ 343 SEC_OSAL_SemaphorePost(pSECPort->unloadedResource); 344 /* SEC_OSAL_MutexUnlock(pSECComponent->compMutex); */ 345 pSECPort->portDefinition.bPopulated = OMX_FALSE; 346 } 347 } 348 349 FunctionOut(); 350 351 return ret; 352 } 353 354 OMX_ERRORTYPE SEC_OMX_AllocateTunnelBuffer(SEC_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex) 355 { 356 OMX_ERRORTYPE ret = OMX_ErrorNone; 357 SEC_OMX_BASEPORT *pSECPort = NULL; 358 OMX_BUFFERHEADERTYPE *temp_bufferHeader = NULL; 359 OMX_U8 *temp_buffer = NULL; 360 OMX_U32 bufferSize = 0; 361 OMX_PARAM_PORTDEFINITIONTYPE portDefinition; 362 363 ret = OMX_ErrorTunnelingUnsupported; 364 EXIT: 365 return ret; 366 } 367 368 OMX_ERRORTYPE SEC_OMX_FreeTunnelBuffer(SEC_OMX_BASEPORT *pOMXBasePort, OMX_U32 nPortIndex) 369 { 370 OMX_ERRORTYPE ret = OMX_ErrorNone; 371 SEC_OMX_BASEPORT* pSECPort = NULL; 372 OMX_BUFFERHEADERTYPE* temp_bufferHeader = NULL; 373 OMX_U8 *temp_buffer = NULL; 374 OMX_U32 bufferSize = 0; 375 OMX_PARAM_PORTDEFINITIONTYPE portDefinition; 376 377 ret = OMX_ErrorTunnelingUnsupported; 378 EXIT: 379 return ret; 380 } 381 382 OMX_ERRORTYPE SEC_OMX_ComponentTunnelRequest( 383 OMX_IN OMX_HANDLETYPE hComp, 384 OMX_IN OMX_U32 nPort, 385 OMX_IN OMX_HANDLETYPE hTunneledComp, 386 OMX_IN OMX_U32 nTunneledPort, 387 OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup) 388 { 389 OMX_ERRORTYPE ret = OMX_ErrorNone; 390 391 ret = OMX_ErrorTunnelingUnsupported; 392 EXIT: 393 return ret; 394 } 395 396 OMX_BOOL SEC_Check_BufferProcess_State(SEC_OMX_BASECOMPONENT *pSECComponent) 397 { 398 if ((pSECComponent->currentState == OMX_StateExecuting) && 399 (pSECComponent->pSECPort[INPUT_PORT_INDEX].portState == OMX_StateIdle) && 400 (pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portState == OMX_StateIdle) && 401 (pSECComponent->transientState != SEC_OMX_TransStateExecutingToIdle) && 402 (pSECComponent->transientState != SEC_OMX_TransStateIdleToExecuting)) 403 return OMX_TRUE; 404 else 405 return OMX_FALSE; 406 } 407 408 static OMX_ERRORTYPE SEC_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent) 409 { 410 OMX_ERRORTYPE ret = OMX_ErrorNone; 411 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 412 SEC_OMX_BASEPORT *secOMXInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 413 SEC_OMX_BASEPORT *secOMXOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 414 SEC_OMX_DATABUFFER *dataBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX]; 415 OMX_BUFFERHEADERTYPE *bufferHeader = dataBuffer->bufferHeader; 416 417 FunctionIn(); 418 419 if (bufferHeader != NULL) { 420 if (secOMXInputPort->markType.hMarkTargetComponent != NULL ) { 421 bufferHeader->hMarkTargetComponent = secOMXInputPort->markType.hMarkTargetComponent; 422 bufferHeader->pMarkData = secOMXInputPort->markType.pMarkData; 423 secOMXInputPort->markType.hMarkTargetComponent = NULL; 424 secOMXInputPort->markType.pMarkData = NULL; 425 } 426 427 if (bufferHeader->hMarkTargetComponent != NULL) { 428 if (bufferHeader->hMarkTargetComponent == pOMXComponent) { 429 pSECComponent->pCallbacks->EventHandler(pOMXComponent, 430 pSECComponent->callbackData, 431 OMX_EventMark, 432 0, 0, bufferHeader->pMarkData); 433 } else { 434 pSECComponent->propagateMarkType.hMarkTargetComponent = bufferHeader->hMarkTargetComponent; 435 pSECComponent->propagateMarkType.pMarkData = bufferHeader->pMarkData; 436 } 437 } 438 439 if (CHECK_PORT_TUNNELED(secOMXInputPort)) { 440 OMX_FillThisBuffer(secOMXInputPort->tunneledComponent, bufferHeader); 441 } else { 442 bufferHeader->nFilledLen = 0; 443 pSECComponent->pCallbacks->EmptyBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader); 444 } 445 } 446 447 if ((pSECComponent->currentState == OMX_StatePause) && 448 ((!CHECK_PORT_BEING_FLUSHED(secOMXInputPort) && !CHECK_PORT_BEING_FLUSHED(secOMXOutputPort)))) { 449 SEC_OSAL_SignalReset(pSECComponent->pauseEvent); 450 SEC_OSAL_SignalWait(pSECComponent->pauseEvent, DEF_MAX_WAIT_TIME); 451 } 452 453 dataBuffer->dataValid = OMX_FALSE; 454 dataBuffer->dataLen = 0; 455 dataBuffer->remainDataLen = 0; 456 dataBuffer->usedDataLen = 0; 457 dataBuffer->bufferHeader = NULL; 458 dataBuffer->nFlags = 0; 459 dataBuffer->timeStamp = 0; 460 461 EXIT: 462 FunctionOut(); 463 464 return ret; 465 } 466 467 OMX_ERRORTYPE SEC_InputBufferGetQueue(SEC_OMX_BASECOMPONENT *pSECComponent) 468 { 469 OMX_ERRORTYPE ret = OMX_ErrorNone; 470 SEC_OMX_BASEPORT *pSECPort = NULL; 471 SEC_OMX_DATABUFFER *dataBuffer = NULL; 472 SEC_OMX_MESSAGE* message = NULL; 473 SEC_OMX_DATABUFFER *inputUseBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX]; 474 475 FunctionIn(); 476 477 pSECPort= &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 478 dataBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX]; 479 480 if (pSECComponent->currentState != OMX_StateExecuting) { 481 ret = OMX_ErrorUndefined; 482 goto EXIT; 483 } else { 484 SEC_OSAL_SemaphoreWait(pSECPort->bufferSemID); 485 SEC_OSAL_MutexLock(inputUseBuffer->bufferMutex); 486 if (dataBuffer->dataValid != OMX_TRUE) { 487 message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECPort->bufferQ); 488 if (message == NULL) { 489 ret = OMX_ErrorUndefined; 490 SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex); 491 goto EXIT; 492 } 493 494 dataBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData); 495 dataBuffer->allocSize = dataBuffer->bufferHeader->nAllocLen; 496 dataBuffer->dataLen = dataBuffer->bufferHeader->nFilledLen; 497 dataBuffer->remainDataLen = dataBuffer->dataLen; 498 dataBuffer->usedDataLen = 0; //dataBuffer->bufferHeader->nOffset; 499 dataBuffer->dataValid = OMX_TRUE; 500 dataBuffer->nFlags = dataBuffer->bufferHeader->nFlags; 501 dataBuffer->timeStamp = dataBuffer->bufferHeader->nTimeStamp; 502 pSECComponent->processData[INPUT_PORT_INDEX].dataBuffer = dataBuffer->bufferHeader->pBuffer; 503 pSECComponent->processData[INPUT_PORT_INDEX].allocSize = dataBuffer->bufferHeader->nAllocLen; 504 505 SEC_OSAL_Free(message); 506 } 507 SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex); 508 ret = OMX_ErrorNone; 509 } 510 EXIT: 511 FunctionOut(); 512 513 return ret; 514 } 515 516 static OMX_ERRORTYPE SEC_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent) 517 { 518 OMX_ERRORTYPE ret = OMX_ErrorNone; 519 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 520 SEC_OMX_BASEPORT *secOMXInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 521 SEC_OMX_BASEPORT *secOMXOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 522 SEC_OMX_DATABUFFER *dataBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX]; 523 OMX_BUFFERHEADERTYPE *bufferHeader = dataBuffer->bufferHeader; 524 525 FunctionIn(); 526 527 if (bufferHeader != NULL) { 528 bufferHeader->nFilledLen = dataBuffer->remainDataLen; 529 bufferHeader->nOffset = 0; 530 bufferHeader->nFlags = dataBuffer->nFlags; 531 bufferHeader->nTimeStamp = dataBuffer->timeStamp; 532 533 if (pSECComponent->propagateMarkType.hMarkTargetComponent != NULL) { 534 bufferHeader->hMarkTargetComponent = pSECComponent->propagateMarkType.hMarkTargetComponent; 535 bufferHeader->pMarkData = pSECComponent->propagateMarkType.pMarkData; 536 pSECComponent->propagateMarkType.hMarkTargetComponent = NULL; 537 pSECComponent->propagateMarkType.pMarkData = NULL; 538 } 539 540 if (bufferHeader->nFlags & OMX_BUFFERFLAG_EOS) { 541 pSECComponent->pCallbacks->EventHandler(pOMXComponent, 542 pSECComponent->callbackData, 543 OMX_EventBufferFlag, 544 OUTPUT_PORT_INDEX, 545 bufferHeader->nFlags, NULL); 546 } 547 548 if (CHECK_PORT_TUNNELED(secOMXOutputPort)) { 549 OMX_EmptyThisBuffer(secOMXOutputPort->tunneledComponent, bufferHeader); 550 } else { 551 pSECComponent->pCallbacks->FillBufferDone(pOMXComponent, pSECComponent->callbackData, bufferHeader); 552 } 553 } 554 555 if ((pSECComponent->currentState == OMX_StatePause) && 556 ((!CHECK_PORT_BEING_FLUSHED(secOMXInputPort) && !CHECK_PORT_BEING_FLUSHED(secOMXOutputPort)))) { 557 SEC_OSAL_SignalReset(pSECComponent->pauseEvent); 558 SEC_OSAL_SignalWait(pSECComponent->pauseEvent, DEF_MAX_WAIT_TIME); 559 } 560 561 /* reset dataBuffer */ 562 dataBuffer->dataValid = OMX_FALSE; 563 dataBuffer->dataLen = 0; 564 dataBuffer->remainDataLen = 0; 565 dataBuffer->usedDataLen = 0; 566 dataBuffer->bufferHeader = NULL; 567 dataBuffer->nFlags = 0; 568 dataBuffer->timeStamp = 0; 569 570 EXIT: 571 FunctionOut(); 572 573 return ret; 574 } 575 576 OMX_ERRORTYPE SEC_OutputBufferGetQueue(SEC_OMX_BASECOMPONENT *pSECComponent) 577 { 578 OMX_ERRORTYPE ret = OMX_ErrorNone; 579 SEC_OMX_BASEPORT *pSECPort = NULL; 580 SEC_OMX_DATABUFFER *dataBuffer = NULL; 581 SEC_OMX_MESSAGE *message = NULL; 582 SEC_OMX_DATABUFFER *outputUseBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX]; 583 584 FunctionIn(); 585 586 pSECPort= &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 587 dataBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX]; 588 589 if (pSECComponent->currentState != OMX_StateExecuting) { 590 ret = OMX_ErrorUndefined; 591 goto EXIT; 592 } else { 593 SEC_OSAL_SemaphoreWait(pSECPort->bufferSemID); 594 SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex); 595 if (dataBuffer->dataValid != OMX_TRUE) { 596 message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECPort->bufferQ); 597 if (message == NULL) { 598 ret = OMX_ErrorUndefined; 599 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex); 600 goto EXIT; 601 } 602 603 dataBuffer->bufferHeader = (OMX_BUFFERHEADERTYPE *)(message->pCmdData); 604 dataBuffer->allocSize = dataBuffer->bufferHeader->nAllocLen; 605 dataBuffer->dataLen = 0; //dataBuffer->bufferHeader->nFilledLen; 606 dataBuffer->remainDataLen = dataBuffer->dataLen; 607 dataBuffer->usedDataLen = 0; //dataBuffer->bufferHeader->nOffset; 608 dataBuffer->dataValid =OMX_TRUE; 609 /* dataBuffer->nFlags = dataBuffer->bufferHeader->nFlags; */ 610 /* dataBuffer->nTimeStamp = dataBuffer->bufferHeader->nTimeStamp; */ 611 SEC_OSAL_Free(message); 612 } 613 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex); 614 ret = OMX_ErrorNone; 615 } 616 EXIT: 617 FunctionOut(); 618 619 return ret; 620 621 } 622 623 static OMX_ERRORTYPE SEC_BufferReset(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 portIndex) 624 { 625 OMX_ERRORTYPE ret = OMX_ErrorNone; 626 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 627 /* SEC_OMX_BASEPORT *pSECPort = &pSECComponent->pSECPort[portIndex]; */ 628 SEC_OMX_DATABUFFER *dataBuffer = &pSECComponent->secDataBuffer[portIndex]; 629 /* OMX_BUFFERHEADERTYPE *bufferHeader = dataBuffer->bufferHeader; */ 630 631 dataBuffer->dataValid = OMX_FALSE; 632 dataBuffer->dataLen = 0; 633 dataBuffer->remainDataLen = 0; 634 dataBuffer->usedDataLen = 0; 635 dataBuffer->bufferHeader = NULL; 636 dataBuffer->nFlags = 0; 637 dataBuffer->timeStamp = 0; 638 639 return ret; 640 } 641 642 static OMX_ERRORTYPE SEC_DataReset(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 portIndex) 643 { 644 OMX_ERRORTYPE ret = OMX_ErrorNone; 645 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 646 /* SEC_OMX_BASEPORT *pSECPort = &pSECComponent->pSECPort[portIndex]; */ 647 /* SEC_OMX_DATABUFFER *dataBuffer = &pSECComponent->secDataBuffer[portIndex]; */ 648 /* OMX_BUFFERHEADERTYPE *bufferHeader = dataBuffer->bufferHeader; */ 649 SEC_OMX_DATA *processData = &pSECComponent->processData[portIndex]; 650 651 processData->dataLen = 0; 652 processData->remainDataLen = 0; 653 processData->usedDataLen = 0; 654 processData->nFlags = 0; 655 processData->timeStamp = 0; 656 657 return ret; 658 } 659 660 OMX_BOOL SEC_Preprocessor_InputData(OMX_COMPONENTTYPE *pOMXComponent) 661 { 662 OMX_BOOL ret = OMX_FALSE; 663 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 664 SEC_OMX_DATABUFFER *inputUseBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX]; 665 SEC_OMX_DATA *inputData = &pSECComponent->processData[INPUT_PORT_INDEX]; 666 OMX_U32 copySize = 0; 667 OMX_BYTE checkInputStream = NULL; 668 OMX_U32 checkInputStreamLen = 0; 669 OMX_U32 checkedSize = 0; 670 OMX_BOOL flagEOS = OMX_FALSE; 671 OMX_BOOL flagEOF = OMX_FALSE; 672 OMX_BOOL previousFrameEOF = OMX_FALSE; 673 674 if (inputUseBuffer->dataValid == OMX_TRUE) { 675 checkInputStream = inputUseBuffer->bufferHeader->pBuffer + inputUseBuffer->usedDataLen; 676 checkInputStreamLen = inputUseBuffer->remainDataLen; 677 678 if ((inputUseBuffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) && 679 (pSECComponent->bUseFlagEOF == OMX_FALSE)) { 680 pSECComponent->bUseFlagEOF = OMX_TRUE; 681 } 682 683 if (inputData->dataLen == 0) { 684 previousFrameEOF = OMX_TRUE; 685 } else { 686 previousFrameEOF = OMX_FALSE; 687 } 688 if (pSECComponent->bUseFlagEOF == OMX_TRUE) { 689 flagEOF = OMX_TRUE; 690 checkedSize = checkInputStreamLen; 691 if (checkedSize == 0) { 692 SEC_OMX_BASEPORT *pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 693 int width = pSECPort->portDefinition.format.video.nFrameWidth; 694 int height = pSECPort->portDefinition.format.video.nFrameHeight; 695 inputUseBuffer->remainDataLen = inputUseBuffer->dataLen = (width * height * 3) / 2; 696 checkedSize = checkInputStreamLen = inputUseBuffer->remainDataLen; 697 inputUseBuffer->nFlags |= OMX_BUFFERFLAG_EOS; 698 } 699 if (inputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) { 700 flagEOS = OMX_TRUE; 701 } 702 } else { 703 SEC_OMX_BASEPORT *pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 704 int width = pSECPort->portDefinition.format.video.nFrameWidth; 705 int height = pSECPort->portDefinition.format.video.nFrameHeight; 706 int oneFrameSize = 0; 707 708 if (pSECPort->portDefinition.format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) 709 oneFrameSize = (width * height * 3) / 2; 710 else if (pSECPort->portDefinition.format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) 711 oneFrameSize = (width * height * 3) / 2; 712 else if (pSECPort->portDefinition.format.video.eColorFormat == OMX_COLOR_FormatYUV422Planar) 713 oneFrameSize = width * height * 2; 714 715 if (previousFrameEOF == OMX_TRUE) { 716 if (checkInputStreamLen >= oneFrameSize) { 717 checkedSize = oneFrameSize; 718 flagEOF = OMX_TRUE; 719 } else { 720 flagEOF = OMX_FALSE; 721 } 722 } else { 723 if (checkInputStreamLen >= (oneFrameSize - inputData->dataLen)) { 724 checkedSize = oneFrameSize - inputData->dataLen; 725 flagEOF = OMX_TRUE; 726 } else { 727 flagEOF = OMX_FALSE; 728 } 729 } 730 731 if ((flagEOF == OMX_FALSE) && (inputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS)) { 732 flagEOF = OMX_TRUE; 733 flagEOS = OMX_TRUE; 734 } 735 } 736 737 if (flagEOF == OMX_TRUE) { 738 copySize = checkedSize; 739 SEC_OSAL_Log(SEC_LOG_TRACE, "sec_checkInputFrame : OMX_TRUE"); 740 } else { 741 copySize = checkInputStreamLen; 742 SEC_OSAL_Log(SEC_LOG_TRACE, "sec_checkInputFrame : OMX_FALSE"); 743 } 744 745 if (inputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS) 746 pSECComponent->bSaveFlagEOS = OMX_TRUE; 747 748 if (((inputData->allocSize) - (inputData->dataLen)) >= copySize) { 749 SEC_OMX_BASEPORT *pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 750 751 if ((pSECPort->portDefinition.format.video.eColorFormat != OMX_SEC_COLOR_FormatNV12TPhysicalAddress) && 752 (pSECPort->bStoreMetaDataInBuffer == OMX_FALSE)) { 753 if (flagEOF == OMX_TRUE) { 754 OMX_U32 width, height; 755 756 width = pSECPort->portDefinition.format.video.nFrameWidth; 757 height = pSECPort->portDefinition.format.video.nFrameHeight; 758 759 SEC_OSAL_Log(SEC_LOG_TRACE, "inputData->specificBufferHeader.YVirAddr : 0x%x", inputData->specificBufferHeader.YVirAddr); 760 SEC_OSAL_Log(SEC_LOG_TRACE, "inputData->specificBufferHeader.CVirAddr : 0x%x", inputData->specificBufferHeader.CVirAddr); 761 762 SEC_OSAL_Log(SEC_LOG_TRACE, "width:%d, height:%d, Ysize:%d", width, height, ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height))); 763 SEC_OSAL_Log(SEC_LOG_TRACE, "width:%d, height:%d, Csize:%d", width, height, ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height / 2))); 764 765 switch (pSECPort->portDefinition.format.video.eColorFormat) { 766 case OMX_COLOR_FormatYUV420Planar: 767 /* Real YUV420P Data */ 768 csc_linear_to_tiled(inputData->specificBufferHeader.YVirAddr, 769 checkInputStream, width, height); 770 csc_linear_to_tiled_interleave(inputData->specificBufferHeader.CVirAddr, 771 checkInputStream + (width * height), 772 checkInputStream + (((width * height) * 5) / 4), 773 width, height >> 1); 774 break; 775 case OMX_COLOR_FormatYUV420SemiPlanar: 776 default: 777 SEC_OSAL_Memcpy(inputData->specificBufferHeader.YVirAddr, checkInputStream, (width * height)); 778 SEC_OSAL_Memcpy(inputData->specificBufferHeader.CVirAddr, checkInputStream + (width * height), (width * height / 2)); 779 break; 780 } 781 } 782 } 783 784 inputUseBuffer->dataLen -= copySize; 785 inputUseBuffer->remainDataLen -= copySize; 786 inputUseBuffer->usedDataLen += copySize; 787 788 inputData->dataLen += copySize; 789 inputData->remainDataLen += copySize; 790 791 if (previousFrameEOF == OMX_TRUE) { 792 inputData->timeStamp = inputUseBuffer->timeStamp; 793 inputData->nFlags = inputUseBuffer->nFlags; 794 } 795 796 if (pSECComponent->bUseFlagEOF == OMX_TRUE) { 797 if (pSECComponent->bSaveFlagEOS == OMX_TRUE) { 798 inputData->nFlags |= OMX_BUFFERFLAG_EOS; 799 flagEOF = OMX_TRUE; 800 pSECComponent->bSaveFlagEOS = OMX_FALSE; 801 } 802 } else { 803 if ((checkedSize == checkInputStreamLen) && (pSECComponent->bSaveFlagEOS == OMX_TRUE)) { 804 inputData->nFlags |= OMX_BUFFERFLAG_EOS; 805 flagEOF = OMX_TRUE; 806 pSECComponent->bSaveFlagEOS = OMX_FALSE; 807 } else { 808 inputData->nFlags = (inputUseBuffer->nFlags & (~OMX_BUFFERFLAG_EOS)); 809 } 810 } 811 } else { 812 /*????????????????????????????????? Error ?????????????????????????????????*/ 813 SEC_DataReset(pOMXComponent, INPUT_PORT_INDEX); 814 flagEOF = OMX_FALSE; 815 } 816 817 if (inputUseBuffer->remainDataLen == 0) { 818 if(flagEOF == OMX_FALSE) 819 SEC_InputBufferReturn(pOMXComponent); 820 } else { 821 inputUseBuffer->dataValid = OMX_TRUE; 822 } 823 } 824 825 if (flagEOF == OMX_TRUE) { 826 if (pSECComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) { 827 pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_TRUE; 828 pSECComponent->checkTimeStamp.startTimeStamp = inputData->timeStamp; 829 pSECComponent->checkTimeStamp.nStartFlags = inputData->nFlags; 830 pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE; 831 } 832 833 ret = OMX_TRUE; 834 } else { 835 ret = OMX_FALSE; 836 } 837 return ret; 838 } 839 840 OMX_BOOL SEC_Postprocess_OutputData(OMX_COMPONENTTYPE *pOMXComponent) 841 { 842 OMX_BOOL ret = OMX_FALSE; 843 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 844 SEC_OMX_DATABUFFER *outputUseBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX]; 845 SEC_OMX_DATA *outputData = &pSECComponent->processData[OUTPUT_PORT_INDEX]; 846 OMX_U32 copySize = 0; 847 848 if (outputUseBuffer->dataValid == OMX_TRUE) { 849 if (pSECComponent->checkTimeStamp.needCheckStartTimeStamp == OMX_TRUE) { 850 if (pSECComponent->checkTimeStamp.startTimeStamp == outputData->timeStamp){ 851 pSECComponent->checkTimeStamp.startTimeStamp = -19761123; 852 pSECComponent->checkTimeStamp.nStartFlags = 0x0; 853 pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_FALSE; 854 pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE; 855 } else { 856 SEC_DataReset(pOMXComponent, OUTPUT_PORT_INDEX); 857 858 ret = OMX_TRUE; 859 goto EXIT; 860 } 861 } else if (pSECComponent->checkTimeStamp.needSetStartTimeStamp == OMX_TRUE) { 862 SEC_DataReset(pOMXComponent, OUTPUT_PORT_INDEX); 863 864 ret = OMX_TRUE; 865 goto EXIT; 866 } 867 868 if (outputData->remainDataLen <= (outputUseBuffer->allocSize - outputUseBuffer->dataLen)) { 869 copySize = outputData->remainDataLen; 870 if (copySize > 0) 871 SEC_OSAL_Memcpy((outputUseBuffer->bufferHeader->pBuffer + outputUseBuffer->dataLen), 872 (outputData->dataBuffer + outputData->usedDataLen), 873 copySize); 874 875 outputUseBuffer->dataLen += copySize; 876 outputUseBuffer->remainDataLen += copySize; 877 outputUseBuffer->nFlags = outputData->nFlags; 878 outputUseBuffer->timeStamp = outputData->timeStamp; 879 880 ret = OMX_TRUE; 881 882 /* reset outputData */ 883 SEC_DataReset(pOMXComponent, OUTPUT_PORT_INDEX); 884 885 if ((outputUseBuffer->remainDataLen > 0) || 886 (outputUseBuffer->nFlags & OMX_BUFFERFLAG_EOS)) 887 SEC_OutputBufferReturn(pOMXComponent); 888 } else { 889 SEC_OSAL_Log(SEC_LOG_ERROR, "output buffer is smaller than encoded data size Out Length"); 890 891 copySize = outputUseBuffer->allocSize - outputUseBuffer->dataLen; 892 893 SEC_OSAL_Memcpy((outputUseBuffer->bufferHeader->pBuffer + outputUseBuffer->dataLen), 894 (outputData->dataBuffer + outputData->usedDataLen), 895 copySize); 896 897 outputUseBuffer->dataLen += copySize; 898 outputUseBuffer->remainDataLen += copySize; 899 outputUseBuffer->nFlags = 0; 900 outputUseBuffer->timeStamp = outputData->timeStamp; 901 902 ret = OMX_FALSE; 903 904 outputData->remainDataLen -= copySize; 905 outputData->usedDataLen += copySize; 906 907 SEC_OutputBufferReturn(pOMXComponent); 908 } 909 } else { 910 ret = OMX_FALSE; 911 } 912 913 EXIT: 914 return ret; 915 } 916 917 OMX_ERRORTYPE SEC_OMX_BufferProcess(OMX_HANDLETYPE hComponent) 918 { 919 OMX_ERRORTYPE ret = OMX_ErrorNone; 920 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 921 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 922 SEC_OMX_BASEPORT *secInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 923 SEC_OMX_BASEPORT *secOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 924 SEC_OMX_DATABUFFER *inputUseBuffer = &pSECComponent->secDataBuffer[INPUT_PORT_INDEX]; 925 SEC_OMX_DATABUFFER *outputUseBuffer = &pSECComponent->secDataBuffer[OUTPUT_PORT_INDEX]; 926 SEC_OMX_DATA *inputData = &pSECComponent->processData[INPUT_PORT_INDEX]; 927 SEC_OMX_DATA *outputData = &pSECComponent->processData[OUTPUT_PORT_INDEX]; 928 OMX_U32 copySize = 0; 929 930 pSECComponent->remainOutputData = OMX_FALSE; 931 pSECComponent->reInputData = OMX_FALSE; 932 933 FunctionIn(); 934 935 while (!pSECComponent->bExitBufferProcessThread) { 936 SEC_OSAL_SleepMillisec(0); 937 938 if (((pSECComponent->currentState == OMX_StatePause) || 939 (pSECComponent->currentState == OMX_StateIdle) || 940 (pSECComponent->transientState == SEC_OMX_TransStateLoadedToIdle) || 941 (pSECComponent->transientState == SEC_OMX_TransStateExecutingToIdle)) && 942 (pSECComponent->transientState != SEC_OMX_TransStateIdleToLoaded)&& 943 ((!CHECK_PORT_BEING_FLUSHED(secInputPort) && !CHECK_PORT_BEING_FLUSHED(secOutputPort)))) { 944 SEC_OSAL_SignalReset(pSECComponent->pauseEvent); 945 SEC_OSAL_SignalWait(pSECComponent->pauseEvent, DEF_MAX_WAIT_TIME); 946 } 947 948 while (SEC_Check_BufferProcess_State(pSECComponent) && !pSECComponent->bExitBufferProcessThread) { 949 SEC_OSAL_SleepMillisec(0); 950 951 SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex); 952 if ((outputUseBuffer->dataValid != OMX_TRUE) && 953 (!CHECK_PORT_BEING_FLUSHED(secOutputPort))) { 954 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex); 955 ret = SEC_OutputBufferGetQueue(pSECComponent); 956 if ((ret == OMX_ErrorUndefined) || 957 (secInputPort->portState != OMX_StateIdle) || 958 (secOutputPort->portState != OMX_StateIdle)) { 959 break; 960 } 961 } else { 962 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex); 963 } 964 965 if (pSECComponent->remainOutputData == OMX_FALSE) { 966 if (pSECComponent->reInputData == OMX_FALSE) { 967 SEC_OSAL_MutexLock(inputUseBuffer->bufferMutex); 968 if ((SEC_Preprocessor_InputData(pOMXComponent) == OMX_FALSE) && 969 (!CHECK_PORT_BEING_FLUSHED(secInputPort))) { 970 SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex); 971 ret = SEC_InputBufferGetQueue(pSECComponent); 972 break; 973 } 974 975 SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex); 976 } 977 978 SEC_OSAL_MutexLock(inputUseBuffer->bufferMutex); 979 SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex); 980 ret = pSECComponent->sec_mfc_bufferProcess(pOMXComponent, inputData, outputData); 981 982 if (inputUseBuffer->remainDataLen == 0) 983 SEC_InputBufferReturn(pOMXComponent); 984 else 985 inputUseBuffer->dataValid = OMX_TRUE; 986 987 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex); 988 SEC_OSAL_MutexUnlock(inputUseBuffer->bufferMutex); 989 990 if (ret == OMX_ErrorInputDataEncodeYet) 991 pSECComponent->reInputData = OMX_TRUE; 992 else 993 pSECComponent->reInputData = OMX_FALSE; 994 } 995 996 SEC_OSAL_MutexLock(outputUseBuffer->bufferMutex); 997 998 if (SEC_Postprocess_OutputData(pOMXComponent) == OMX_FALSE) 999 pSECComponent->remainOutputData = OMX_TRUE; 1000 else 1001 pSECComponent->remainOutputData = OMX_FALSE; 1002 1003 SEC_OSAL_MutexUnlock(outputUseBuffer->bufferMutex); 1004 } 1005 } 1006 1007 EXIT: 1008 FunctionOut(); 1009 1010 return ret; 1011 } 1012 1013 OMX_ERRORTYPE SEC_OMX_VideoEncodeGetParameter( 1014 OMX_IN OMX_HANDLETYPE hComponent, 1015 OMX_IN OMX_INDEXTYPE nParamIndex, 1016 OMX_INOUT OMX_PTR ComponentParameterStructure) 1017 { 1018 OMX_ERRORTYPE ret = OMX_ErrorNone; 1019 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1020 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1021 SEC_OMX_BASEPORT *pSECPort = NULL; 1022 1023 FunctionIn(); 1024 1025 if (hComponent == NULL) { 1026 ret = OMX_ErrorBadParameter; 1027 goto EXIT; 1028 } 1029 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1030 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1031 if (ret != OMX_ErrorNone) { 1032 goto EXIT; 1033 } 1034 1035 if (pOMXComponent->pComponentPrivate == NULL) { 1036 ret = OMX_ErrorBadParameter; 1037 goto EXIT; 1038 } 1039 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1040 1041 if (pSECComponent->currentState == OMX_StateInvalid ) { 1042 ret = OMX_StateInvalid; 1043 goto EXIT; 1044 } 1045 1046 if (ComponentParameterStructure == NULL) { 1047 ret = OMX_ErrorBadParameter; 1048 goto EXIT; 1049 } 1050 1051 switch (nParamIndex) { 1052 case OMX_IndexParamVideoInit: 1053 { 1054 OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure; 1055 ret = SEC_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE)); 1056 if (ret != OMX_ErrorNone) { 1057 goto EXIT; 1058 } 1059 1060 portParam->nPorts = pSECComponent->portParam.nPorts; 1061 portParam->nStartPortNumber = pSECComponent->portParam.nStartPortNumber; 1062 ret = OMX_ErrorNone; 1063 } 1064 break; 1065 case OMX_IndexParamVideoPortFormat: 1066 { 1067 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure; 1068 OMX_U32 portIndex = portFormat->nPortIndex; 1069 OMX_U32 index = portFormat->nIndex; 1070 SEC_OMX_BASEPORT *pSECPort = NULL; 1071 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL; 1072 OMX_U32 supportFormatNum = 0; 1073 1074 ret = SEC_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); 1075 if (ret != OMX_ErrorNone) { 1076 goto EXIT; 1077 } 1078 1079 if ((portIndex >= pSECComponent->portParam.nPorts)) { 1080 ret = OMX_ErrorBadPortIndex; 1081 goto EXIT; 1082 } 1083 1084 1085 if (portIndex == INPUT_PORT_INDEX) { 1086 supportFormatNum = INPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1; 1087 if (index > supportFormatNum) { 1088 ret = OMX_ErrorNoMore; 1089 goto EXIT; 1090 } 1091 1092 pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1093 portDefinition = &pSECPort->portDefinition; 1094 1095 switch (index) { 1096 case supportFormat_0: 1097 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 1098 portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; 1099 portFormat->xFramerate = portDefinition->format.video.xFramerate; 1100 break; 1101 case supportFormat_1: 1102 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 1103 portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar; 1104 portFormat->xFramerate = portDefinition->format.video.xFramerate; 1105 break; 1106 case supportFormat_2: 1107 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 1108 portFormat->eColorFormat = OMX_SEC_COLOR_FormatNV12TPhysicalAddress; 1109 portFormat->xFramerate = portDefinition->format.video.xFramerate; 1110 break; 1111 #ifdef USE_ANDROID_EXTENSION 1112 case supportFormat_3: 1113 portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 1114 portFormat->eColorFormat = OMX_COLOR_FormatAndroidOpaque; 1115 portFormat->xFramerate = portDefinition->format.video.xFramerate; 1116 break; 1117 #endif 1118 } 1119 } else if (portIndex == OUTPUT_PORT_INDEX) { 1120 supportFormatNum = OUTPUT_PORT_SUPPORTFORMAT_NUM_MAX - 1; 1121 if (index > supportFormatNum) { 1122 ret = OMX_ErrorNoMore; 1123 goto EXIT; 1124 } 1125 1126 pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1127 portDefinition = &pSECPort->portDefinition; 1128 1129 portFormat->eCompressionFormat = portDefinition->format.video.eCompressionFormat; 1130 portFormat->eColorFormat = portDefinition->format.video.eColorFormat; 1131 portFormat->xFramerate = portDefinition->format.video.xFramerate; 1132 } 1133 ret = OMX_ErrorNone; 1134 } 1135 break; 1136 case OMX_IndexParamVideoBitrate: 1137 { 1138 OMX_VIDEO_PARAM_BITRATETYPE *videoRateControl = (OMX_VIDEO_PARAM_BITRATETYPE *)ComponentParameterStructure; 1139 OMX_U32 portIndex = videoRateControl->nPortIndex; 1140 SEC_OMX_BASEPORT *pSECPort = NULL; 1141 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL; 1142 1143 if ((portIndex != OUTPUT_PORT_INDEX)) { 1144 ret = OMX_ErrorBadPortIndex; 1145 goto EXIT; 1146 } else { 1147 pSECPort = &pSECComponent->pSECPort[portIndex]; 1148 portDefinition = &pSECPort->portDefinition; 1149 1150 videoRateControl->eControlRate = pSECPort->eControlRate; 1151 videoRateControl->nTargetBitrate = portDefinition->format.video.nBitrate; 1152 } 1153 ret = OMX_ErrorNone; 1154 } 1155 break; 1156 case OMX_IndexParamPortDefinition: 1157 { 1158 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; 1159 OMX_U32 portIndex = portDefinition->nPortIndex; 1160 SEC_OMX_BASEPORT *pSECPort; 1161 1162 if (portIndex >= pSECComponent->portParam.nPorts) { 1163 ret = OMX_ErrorBadPortIndex; 1164 goto EXIT; 1165 } 1166 ret = SEC_OMX_Check_SizeVersion(portDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 1167 if (ret != OMX_ErrorNone) { 1168 goto EXIT; 1169 } 1170 1171 pSECPort = &pSECComponent->pSECPort[portIndex]; 1172 SEC_OSAL_Memcpy(portDefinition, &pSECPort->portDefinition, portDefinition->nSize); 1173 1174 #ifdef USE_ANDROID_EXTENSION 1175 if (portIndex == 0 && pSECPort->bStoreMetaDataInBuffer == OMX_TRUE) { 1176 portDefinition->nBufferSize = MAX_INPUT_METADATA_BUFFER_SIZE; 1177 } 1178 #endif 1179 } 1180 break; 1181 default: 1182 { 1183 ret = SEC_OMX_GetParameter(hComponent, nParamIndex, ComponentParameterStructure); 1184 } 1185 break; 1186 } 1187 1188 EXIT: 1189 FunctionOut(); 1190 1191 return ret; 1192 } 1193 OMX_ERRORTYPE SEC_OMX_VideoEncodeSetParameter( 1194 OMX_IN OMX_HANDLETYPE hComponent, 1195 OMX_IN OMX_INDEXTYPE nIndex, 1196 OMX_IN OMX_PTR ComponentParameterStructure) 1197 { 1198 OMX_ERRORTYPE ret = OMX_ErrorNone; 1199 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1200 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1201 SEC_OMX_BASEPORT *pSECPort = NULL; 1202 1203 FunctionIn(); 1204 1205 if (hComponent == NULL) { 1206 ret = OMX_ErrorBadParameter; 1207 goto EXIT; 1208 } 1209 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1210 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1211 if (ret != OMX_ErrorNone) { 1212 goto EXIT; 1213 } 1214 1215 if (pOMXComponent->pComponentPrivate == NULL) { 1216 ret = OMX_ErrorBadParameter; 1217 goto EXIT; 1218 } 1219 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1220 1221 if (pSECComponent->currentState == OMX_StateInvalid ) { 1222 ret = OMX_StateInvalid; 1223 goto EXIT; 1224 } 1225 1226 if (ComponentParameterStructure == NULL) { 1227 ret = OMX_ErrorBadParameter; 1228 goto EXIT; 1229 } 1230 1231 switch (nIndex) { 1232 case OMX_IndexParamVideoPortFormat: 1233 { 1234 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure; 1235 OMX_U32 portIndex = portFormat->nPortIndex; 1236 OMX_U32 index = portFormat->nIndex; 1237 SEC_OMX_BASEPORT *pSECPort = NULL; 1238 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL; 1239 OMX_U32 supportFormatNum = 0; 1240 1241 ret = SEC_OMX_Check_SizeVersion(portFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); 1242 if (ret != OMX_ErrorNone) { 1243 goto EXIT; 1244 } 1245 1246 if ((portIndex >= pSECComponent->portParam.nPorts)) { 1247 ret = OMX_ErrorBadPortIndex; 1248 goto EXIT; 1249 } else { 1250 pSECPort = &pSECComponent->pSECPort[portIndex]; 1251 portDefinition = &pSECPort->portDefinition; 1252 1253 portDefinition->format.video.eColorFormat = portFormat->eColorFormat; 1254 portDefinition->format.video.eCompressionFormat = portFormat->eCompressionFormat; 1255 portDefinition->format.video.xFramerate = portFormat->xFramerate; 1256 } 1257 } 1258 break; 1259 case OMX_IndexParamVideoBitrate: 1260 { 1261 OMX_VIDEO_PARAM_BITRATETYPE *videoRateControl = (OMX_VIDEO_PARAM_BITRATETYPE *)ComponentParameterStructure; 1262 OMX_U32 portIndex = videoRateControl->nPortIndex; 1263 SEC_OMX_BASEPORT *pSECPort = NULL; 1264 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = NULL; 1265 1266 if ((portIndex != OUTPUT_PORT_INDEX)) { 1267 ret = OMX_ErrorBadPortIndex; 1268 goto EXIT; 1269 } else { 1270 pSECPort = &pSECComponent->pSECPort[portIndex]; 1271 portDefinition = &pSECPort->portDefinition; 1272 1273 pSECPort->eControlRate = videoRateControl->eControlRate; 1274 portDefinition->format.video.nBitrate = videoRateControl->nTargetBitrate; 1275 } 1276 ret = OMX_ErrorNone; 1277 } 1278 break; 1279 case OMX_IndexParamPortDefinition: 1280 { 1281 OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = 1282 (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; 1283 ret = SEC_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure); 1284 if (ret != OMX_ErrorNone) { 1285 goto EXIT; 1286 } 1287 1288 if (pPortDefinition->nPortIndex == INPUT_PORT_INDEX) { 1289 SEC_OMX_BASEPORT *pSECInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1290 OMX_U32 width = pSECInputPort->portDefinition.format.video.nFrameWidth; 1291 OMX_U32 height = pSECInputPort->portDefinition.format.video.nFrameHeight; 1292 SEC_OMX_BASEPORT *pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1293 pSECOutputPort->portDefinition.format.video.nFrameWidth = width; 1294 pSECOutputPort->portDefinition.format.video.nFrameHeight = height; 1295 pSECOutputPort->portDefinition.nBufferSize = (width * height * 3) / 2; 1296 SEC_OSAL_Log(SEC_LOG_TRACE, "pSECOutputPort->portDefinition.nBufferSize: %d", 1297 pSECOutputPort->portDefinition.nBufferSize); 1298 } 1299 } 1300 break; 1301 #ifdef USE_ANDROID_EXTENSION 1302 case OMX_IndexParamStoreMetaDataBuffer: 1303 { 1304 if (OMX_ErrorNone != checkVersionANB(ComponentParameterStructure)) 1305 goto EXIT; 1306 1307 if (INPUT_PORT_INDEX != checkPortIndexANB(ComponentParameterStructure)) { 1308 ret = OMX_ErrorBadPortIndex; 1309 goto EXIT; 1310 } 1311 1312 ret = enableStoreMetaDataInBuffers(hComponent, ComponentParameterStructure); 1313 } 1314 break; 1315 #endif 1316 default: 1317 { 1318 ret = SEC_OMX_SetParameter(hComponent, nIndex, ComponentParameterStructure); 1319 } 1320 break; 1321 } 1322 1323 EXIT: 1324 FunctionOut(); 1325 1326 return ret; 1327 } 1328 1329 OMX_ERRORTYPE SEC_OMX_VideoEncodeComponentInit(OMX_IN OMX_HANDLETYPE hComponent) 1330 { 1331 OMX_ERRORTYPE ret = OMX_ErrorNone; 1332 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1333 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1334 SEC_OMX_BASEPORT *pSECPort = NULL; 1335 1336 FunctionIn(); 1337 1338 if (hComponent == NULL) { 1339 ret = OMX_ErrorBadParameter; 1340 goto EXIT; 1341 } 1342 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1343 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1344 if (ret != OMX_ErrorNone) { 1345 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_Error, Line:%d", __LINE__); 1346 goto EXIT; 1347 } 1348 1349 ret = SEC_OMX_BaseComponent_Constructor(pOMXComponent); 1350 if (ret != OMX_ErrorNone) { 1351 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_Error, Line:%d", __LINE__); 1352 goto EXIT; 1353 } 1354 1355 ret = SEC_OMX_Port_Constructor(pOMXComponent); 1356 if (ret != OMX_ErrorNone) { 1357 SEC_OMX_BaseComponent_Destructor(pOMXComponent); 1358 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_Error, Line:%d", __LINE__); 1359 goto EXIT; 1360 } 1361 1362 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1363 pSECComponent->bSaveFlagEOS = OMX_FALSE; 1364 1365 /* Input port */ 1366 pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1367 pSECPort->portDefinition.nBufferCountActual = MAX_VIDEO_INPUTBUFFER_NUM; 1368 pSECPort->portDefinition.nBufferCountMin = MAX_VIDEO_INPUTBUFFER_NUM; 1369 pSECPort->portDefinition.nBufferSize = 0; 1370 pSECPort->portDefinition.eDomain = OMX_PortDomainVideo; 1371 1372 pSECPort->portDefinition.format.video.cMIMEType = SEC_OSAL_Malloc(MAX_OMX_MIMETYPE_SIZE); 1373 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video"); 1374 pSECPort->portDefinition.format.video.pNativeRender = 0; 1375 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1376 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; 1377 1378 pSECPort->portDefinition.format.video.nFrameWidth = 0; 1379 pSECPort->portDefinition.format.video.nFrameHeight= 0; 1380 pSECPort->portDefinition.format.video.nStride = 0; 1381 pSECPort->portDefinition.format.video.nSliceHeight = 0; 1382 pSECPort->portDefinition.format.video.nBitrate = 64000; 1383 pSECPort->portDefinition.format.video.xFramerate = (15 << 16); 1384 pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; 1385 pSECPort->portDefinition.format.video.pNativeWindow = NULL; 1386 1387 /* Output port */ 1388 pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1389 pSECPort->portDefinition.nBufferCountActual = MAX_VIDEO_OUTPUTBUFFER_NUM; 1390 pSECPort->portDefinition.nBufferCountMin = MAX_VIDEO_OUTPUTBUFFER_NUM; 1391 pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; 1392 pSECPort->portDefinition.eDomain = OMX_PortDomainVideo; 1393 1394 pSECPort->portDefinition.format.video.cMIMEType = SEC_OSAL_Malloc(MAX_OMX_MIMETYPE_SIZE); 1395 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video"); 1396 pSECPort->portDefinition.format.video.pNativeRender = 0; 1397 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1398 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; 1399 1400 pSECPort->portDefinition.format.video.nFrameWidth = 0; 1401 pSECPort->portDefinition.format.video.nFrameHeight= 0; 1402 pSECPort->portDefinition.format.video.nStride = 0; 1403 pSECPort->portDefinition.format.video.nSliceHeight = 0; 1404 pSECPort->portDefinition.format.video.nBitrate = 64000; 1405 pSECPort->portDefinition.format.video.xFramerate = (15 << 16); 1406 pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; 1407 pSECPort->portDefinition.format.video.pNativeWindow = NULL; 1408 1409 pOMXComponent->UseBuffer = &SEC_OMX_UseBuffer; 1410 pOMXComponent->AllocateBuffer = &SEC_OMX_AllocateBuffer; 1411 pOMXComponent->FreeBuffer = &SEC_OMX_FreeBuffer; 1412 pOMXComponent->ComponentTunnelRequest = &SEC_OMX_ComponentTunnelRequest; 1413 1414 pSECComponent->sec_AllocateTunnelBuffer = &SEC_OMX_AllocateTunnelBuffer; 1415 pSECComponent->sec_FreeTunnelBuffer = &SEC_OMX_FreeTunnelBuffer; 1416 pSECComponent->sec_BufferProcess = &SEC_OMX_BufferProcess; 1417 pSECComponent->sec_BufferReset = &SEC_BufferReset; 1418 pSECComponent->sec_InputBufferReturn = &SEC_InputBufferReturn; 1419 pSECComponent->sec_OutputBufferReturn = &SEC_OutputBufferReturn; 1420 1421 EXIT: 1422 FunctionOut(); 1423 1424 return ret; 1425 } 1426 1427 OMX_ERRORTYPE SEC_OMX_VideoEncodeComponentDeinit(OMX_IN OMX_HANDLETYPE hComponent) 1428 { 1429 OMX_ERRORTYPE ret = OMX_ErrorNone; 1430 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1431 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1432 SEC_OMX_BASEPORT *pSECPort = NULL; 1433 int i = 0; 1434 1435 FunctionIn(); 1436 1437 if (hComponent == NULL) { 1438 ret = OMX_ErrorBadParameter; 1439 goto EXIT; 1440 } 1441 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1442 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1443 if (ret != OMX_ErrorNone) { 1444 goto EXIT; 1445 } 1446 1447 if (pOMXComponent->pComponentPrivate == NULL) { 1448 ret = OMX_ErrorBadParameter; 1449 goto EXIT; 1450 } 1451 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1452 1453 for(i = 0; i < ALL_PORT_NUM; i++) { 1454 pSECPort = &pSECComponent->pSECPort[i]; 1455 SEC_OSAL_Free(pSECPort->portDefinition.format.video.cMIMEType); 1456 pSECPort->portDefinition.format.video.cMIMEType = NULL; 1457 } 1458 1459 ret = SEC_OMX_Port_Destructor(pOMXComponent); 1460 1461 ret = SEC_OMX_BaseComponent_Destructor(hComponent); 1462 1463 EXIT: 1464 FunctionOut(); 1465 1466 return ret; 1467 } 1468