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