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_Basecomponent.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 32 #include "SEC_OSAL_Event.h" 33 #include "SEC_OSAL_Thread.h" 34 #include "SEC_OMX_Baseport.h" 35 #include "SEC_OMX_Basecomponent.h" 36 #include "SEC_OMX_Macros.h" 37 38 #undef SEC_LOG_TAG 39 #define SEC_LOG_TAG "SEC_BASE_COMP" 40 #define SEC_LOG_OFF 41 #include "SEC_OSAL_Log.h" 42 43 44 /* Change CHECK_SIZE_VERSION Macro */ 45 OMX_ERRORTYPE SEC_OMX_Check_SizeVersion(OMX_PTR header, OMX_U32 size) 46 { 47 OMX_ERRORTYPE ret = OMX_ErrorNone; 48 49 OMX_VERSIONTYPE* version = NULL; 50 if (header == NULL) { 51 ret = OMX_ErrorBadParameter; 52 goto EXIT; 53 } 54 version = (OMX_VERSIONTYPE*)((char*)header + sizeof(OMX_U32)); 55 if (*((OMX_U32*)header) != size) { 56 ret = OMX_ErrorBadParameter; 57 goto EXIT; 58 } 59 if (version->s.nVersionMajor != VERSIONMAJOR_NUMBER || 60 version->s.nVersionMinor != VERSIONMINOR_NUMBER) { 61 ret = OMX_ErrorVersionMismatch; 62 goto EXIT; 63 } 64 ret = OMX_ErrorNone; 65 EXIT: 66 return ret; 67 } 68 69 OMX_ERRORTYPE SEC_OMX_GetComponentVersion( 70 OMX_IN OMX_HANDLETYPE hComponent, 71 OMX_OUT OMX_STRING pComponentName, 72 OMX_OUT OMX_VERSIONTYPE *pComponentVersion, 73 OMX_OUT OMX_VERSIONTYPE *pSpecVersion, 74 OMX_OUT OMX_UUIDTYPE *pComponentUUID) 75 { 76 OMX_ERRORTYPE ret = OMX_ErrorNone; 77 OMX_COMPONENTTYPE *pOMXComponent = NULL; 78 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 79 OMX_U32 compUUID[3]; 80 81 FunctionIn(); 82 83 /* check parameters */ 84 if (hComponent == NULL || 85 pComponentName == NULL || pComponentVersion == NULL || 86 pSpecVersion == NULL || pComponentUUID == NULL) { 87 ret = OMX_ErrorBadParameter; 88 goto EXIT; 89 } 90 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 91 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 92 if (ret != OMX_ErrorNone) { 93 goto EXIT; 94 } 95 96 if (pOMXComponent->pComponentPrivate == NULL) { 97 ret = OMX_ErrorBadParameter; 98 goto EXIT; 99 } 100 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 101 102 if (pSECComponent->currentState == OMX_StateInvalid) { 103 ret = OMX_ErrorInvalidState; 104 goto EXIT; 105 } 106 107 SEC_OSAL_Strcpy(pComponentName, pSECComponent->componentName); 108 SEC_OSAL_Memcpy(pComponentVersion, &(pSECComponent->componentVersion), sizeof(OMX_VERSIONTYPE)); 109 SEC_OSAL_Memcpy(pSpecVersion, &(pSECComponent->specVersion), sizeof(OMX_VERSIONTYPE)); 110 111 /* Fill UUID with handle address, PID and UID. 112 * This should guarantee uiniqness */ 113 compUUID[0] = (OMX_U32)pOMXComponent; 114 compUUID[1] = getpid(); 115 compUUID[2] = getuid(); 116 SEC_OSAL_Memcpy(*pComponentUUID, compUUID, 3 * sizeof(*compUUID)); 117 118 ret = OMX_ErrorNone; 119 120 EXIT: 121 FunctionOut(); 122 123 return ret; 124 } 125 126 OMX_ERRORTYPE SEC_OMX_GetState ( 127 OMX_IN OMX_HANDLETYPE hComponent, 128 OMX_OUT OMX_STATETYPE *pState) 129 { 130 OMX_ERRORTYPE ret = OMX_ErrorNone; 131 OMX_COMPONENTTYPE *pOMXComponent = NULL; 132 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 133 134 FunctionIn(); 135 136 if (hComponent == NULL || pState == NULL) { 137 ret = OMX_ErrorBadParameter; 138 goto EXIT; 139 } 140 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 141 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 142 if (ret != OMX_ErrorNone) { 143 goto EXIT; 144 } 145 146 if (pOMXComponent->pComponentPrivate == NULL) { 147 ret = OMX_ErrorBadParameter; 148 goto EXIT; 149 } 150 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 151 152 *pState = pSECComponent->currentState; 153 ret = OMX_ErrorNone; 154 155 EXIT: 156 FunctionOut(); 157 158 return ret; 159 } 160 161 static OMX_ERRORTYPE SEC_OMX_BufferProcessThread(OMX_PTR threadData) 162 { 163 OMX_ERRORTYPE ret = OMX_ErrorNone; 164 OMX_COMPONENTTYPE *pOMXComponent = NULL; 165 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 166 SEC_OMX_MESSAGE *message = NULL; 167 168 FunctionIn(); 169 170 if (threadData == NULL) { 171 ret = OMX_ErrorBadParameter; 172 goto EXIT; 173 } 174 pOMXComponent = (OMX_COMPONENTTYPE *)threadData; 175 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 176 if (ret != OMX_ErrorNone) { 177 goto EXIT; 178 } 179 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 180 pSECComponent->sec_BufferProcess(pOMXComponent); 181 182 SEC_OSAL_ThreadExit(NULL); 183 184 EXIT: 185 FunctionOut(); 186 187 return ret; 188 } 189 190 OMX_ERRORTYPE SEC_OMX_ComponentStateSet(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 messageParam) 191 { 192 OMX_ERRORTYPE ret = OMX_ErrorNone; 193 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 194 SEC_OMX_MESSAGE *message; 195 OMX_STATETYPE destState = messageParam; 196 OMX_STATETYPE currentState = pSECComponent->currentState; 197 SEC_OMX_BASEPORT *pSECPort = NULL; 198 OMX_S32 countValue = 0; 199 int i = 0, j = 0; 200 201 FunctionIn(); 202 203 /* check parameters */ 204 if (currentState == destState) { 205 ret = OMX_ErrorSameState; 206 goto EXIT; 207 } 208 if (currentState == OMX_StateInvalid) { 209 ret = OMX_ErrorInvalidState; 210 goto EXIT; 211 } 212 213 if ((currentState == OMX_StateLoaded) && (destState == OMX_StateIdle)) { 214 ret = SEC_OMX_Get_Resource(pOMXComponent); 215 if (ret != OMX_ErrorNone) { 216 goto EXIT; 217 } 218 } 219 if (((currentState == OMX_StateIdle) && (destState == OMX_StateLoaded)) || 220 ((currentState == OMX_StateIdle) && (destState == OMX_StateInvalid)) || 221 ((currentState == OMX_StateExecuting) && (destState == OMX_StateInvalid)) || 222 ((currentState == OMX_StatePause) && (destState == OMX_StateInvalid))) { 223 SEC_OMX_Release_Resource(pOMXComponent); 224 } 225 226 SEC_OSAL_Log(SEC_LOG_TRACE, "destState: %d", destState); 227 228 switch (destState) { 229 case OMX_StateInvalid: 230 switch (currentState) { 231 case OMX_StateIdle: 232 case OMX_StateExecuting: 233 case OMX_StatePause: 234 case OMX_StateLoaded: 235 case OMX_StateWaitForResources: 236 pSECComponent->currentState = OMX_StateInvalid; 237 if (pSECComponent->hBufferProcess) { 238 pSECComponent->bExitBufferProcessThread = OMX_TRUE; 239 240 for (i = 0; i < ALL_PORT_NUM; i++) { 241 SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[i].bufferSemID, &countValue); 242 if (countValue == 0) 243 SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID); 244 } 245 246 SEC_OSAL_SignalSet(pSECComponent->pauseEvent); 247 SEC_OSAL_ThreadTerminate(pSECComponent->hBufferProcess); 248 pSECComponent->hBufferProcess = NULL; 249 250 for (i = 0; i < ALL_PORT_NUM; i++) { 251 SEC_OSAL_MutexTerminate(pSECComponent->secDataBuffer[i].bufferMutex); 252 pSECComponent->secDataBuffer[i].bufferMutex = NULL; 253 } 254 255 SEC_OSAL_SignalTerminate(pSECComponent->pauseEvent); 256 for (i = 0; i < ALL_PORT_NUM; i++) { 257 SEC_OSAL_SemaphoreTerminate(pSECComponent->pSECPort[i].bufferSemID); 258 pSECComponent->pSECPort[i].bufferSemID = NULL; 259 } 260 } 261 if (pSECComponent->sec_mfc_componentTerminate != NULL) 262 pSECComponent->sec_mfc_componentTerminate(pOMXComponent); 263 break; 264 } 265 ret = OMX_ErrorInvalidState; 266 break; 267 case OMX_StateLoaded: 268 switch (currentState) { 269 case OMX_StateIdle: 270 pSECComponent->bExitBufferProcessThread = OMX_TRUE; 271 272 for (i = 0; i < ALL_PORT_NUM; i++) { 273 SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[i].bufferSemID, &countValue); 274 if (countValue == 0) 275 SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID); 276 } 277 278 SEC_OSAL_SignalSet(pSECComponent->pauseEvent); 279 SEC_OSAL_ThreadTerminate(pSECComponent->hBufferProcess); 280 pSECComponent->hBufferProcess = NULL; 281 282 for (i = 0; i < ALL_PORT_NUM; i++) { 283 SEC_OSAL_MutexTerminate(pSECComponent->secDataBuffer[i].bufferMutex); 284 pSECComponent->secDataBuffer[i].bufferMutex = NULL; 285 } 286 287 SEC_OSAL_SignalTerminate(pSECComponent->pauseEvent); 288 for (i = 0; i < ALL_PORT_NUM; i++) { 289 SEC_OSAL_SemaphoreTerminate(pSECComponent->pSECPort[i].bufferSemID); 290 pSECComponent->pSECPort[i].bufferSemID = NULL; 291 } 292 293 pSECComponent->sec_mfc_componentTerminate(pOMXComponent); 294 295 for (i = 0; i < (pSECComponent->portParam.nPorts); i++) { 296 pSECPort = (pSECComponent->pSECPort + i); 297 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 298 while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) > 0) { 299 message = (SEC_OMX_MESSAGE*)SEC_OSAL_Dequeue(&pSECPort->bufferQ); 300 if (message != NULL) 301 SEC_OSAL_Free(message); 302 } 303 ret = pSECComponent->sec_FreeTunnelBuffer(pSECComponent, i); 304 if (OMX_ErrorNone != ret) { 305 goto EXIT; 306 } 307 } else { 308 if (CHECK_PORT_ENABLED(pSECPort)) { 309 SEC_OSAL_SemaphoreWait(pSECPort->unloadedResource); 310 pSECPort->portDefinition.bPopulated = OMX_FALSE; 311 } 312 } 313 } 314 pSECComponent->currentState = OMX_StateLoaded; 315 break; 316 case OMX_StateWaitForResources: 317 ret = SEC_OMX_Out_WaitForResource(pOMXComponent); 318 pSECComponent->currentState = OMX_StateLoaded; 319 break; 320 case OMX_StateExecuting: 321 case OMX_StatePause: 322 default: 323 ret = OMX_ErrorIncorrectStateTransition; 324 break; 325 } 326 break; 327 case OMX_StateIdle: 328 switch (currentState) { 329 case OMX_StateLoaded: 330 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 331 pSECPort = (pSECComponent->pSECPort + i); 332 if (pSECPort == NULL) { 333 ret = OMX_ErrorBadParameter; 334 goto EXIT; 335 } 336 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 337 if (CHECK_PORT_ENABLED(pSECPort)) { 338 ret = pSECComponent->sec_AllocateTunnelBuffer(pSECPort, i); 339 if (ret!=OMX_ErrorNone) 340 goto EXIT; 341 } 342 } else { 343 if (CHECK_PORT_ENABLED(pSECPort)) { 344 SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[i].loadedResource); 345 pSECPort->portDefinition.bPopulated = OMX_TRUE; 346 } 347 } 348 } 349 ret = pSECComponent->sec_mfc_componentInit(pOMXComponent); 350 if (ret != OMX_ErrorNone) { 351 /* 352 * if (CHECK_PORT_TUNNELED == OMX_TRUE) thenTunnel Buffer Free 353 */ 354 goto EXIT; 355 } 356 pSECComponent->bExitBufferProcessThread = OMX_FALSE; 357 SEC_OSAL_SignalCreate(&pSECComponent->pauseEvent); 358 for (i = 0; i < ALL_PORT_NUM; i++) { 359 SEC_OSAL_SemaphoreCreate(&pSECComponent->pSECPort[i].bufferSemID); 360 } 361 for (i = 0; i < ALL_PORT_NUM; i++) { 362 SEC_OSAL_MutexCreate(&pSECComponent->secDataBuffer[i].bufferMutex); 363 } 364 ret = SEC_OSAL_ThreadCreate(&pSECComponent->hBufferProcess, 365 SEC_OMX_BufferProcessThread, 366 pOMXComponent); 367 if (ret != OMX_ErrorNone) { 368 /* 369 * if (CHECK_PORT_TUNNELED == OMX_TRUE) thenTunnel Buffer Free 370 */ 371 372 SEC_OSAL_SignalTerminate(pSECComponent->pauseEvent); 373 for (i = 0; i < ALL_PORT_NUM; i++) { 374 SEC_OSAL_MutexTerminate(pSECComponent->secDataBuffer[i].bufferMutex); 375 pSECComponent->secDataBuffer[i].bufferMutex = NULL; 376 } 377 for (i = 0; i < ALL_PORT_NUM; i++) { 378 SEC_OSAL_SemaphoreTerminate(pSECComponent->pSECPort[i].bufferSemID); 379 pSECComponent->pSECPort[i].bufferSemID = NULL; 380 } 381 382 ret = OMX_ErrorInsufficientResources; 383 goto EXIT; 384 } 385 pSECComponent->currentState = OMX_StateIdle; 386 break; 387 case OMX_StateExecuting: 388 case OMX_StatePause: 389 SEC_OMX_BufferFlushProcessNoEvent(pOMXComponent, ALL_PORT_INDEX); 390 pSECComponent->currentState = OMX_StateIdle; 391 break; 392 case OMX_StateWaitForResources: 393 pSECComponent->currentState = OMX_StateIdle; 394 break; 395 } 396 break; 397 case OMX_StateExecuting: 398 switch (currentState) { 399 case OMX_StateLoaded: 400 ret = OMX_ErrorIncorrectStateTransition; 401 break; 402 case OMX_StateIdle: 403 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 404 pSECPort = &pSECComponent->pSECPort[i]; 405 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort) && CHECK_PORT_ENABLED(pSECPort)) { 406 for (j = 0; j < pSECPort->tunnelBufferNum; j++) { 407 SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID); 408 } 409 } 410 } 411 412 pSECComponent->transientState = SEC_OMX_TransStateMax; 413 pSECComponent->currentState = OMX_StateExecuting; 414 SEC_OSAL_SignalSet(pSECComponent->pauseEvent); 415 break; 416 case OMX_StatePause: 417 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 418 pSECPort = &pSECComponent->pSECPort[i]; 419 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort) && CHECK_PORT_ENABLED(pSECPort)) { 420 OMX_U32 semaValue = 0, cnt = 0; 421 SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[i].bufferSemID, &semaValue); 422 if (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) > semaValue) { 423 cnt = SEC_OSAL_GetElemNum(&pSECPort->bufferQ) - semaValue; 424 for (j = 0; j < cnt; j++) { 425 SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID); 426 } 427 } 428 } 429 } 430 431 pSECComponent->currentState = OMX_StateExecuting; 432 SEC_OSAL_SignalSet(pSECComponent->pauseEvent); 433 break; 434 case OMX_StateWaitForResources: 435 ret = OMX_ErrorIncorrectStateTransition; 436 break; 437 } 438 break; 439 case OMX_StatePause: 440 switch (currentState) { 441 case OMX_StateLoaded: 442 ret = OMX_ErrorIncorrectStateTransition; 443 break; 444 case OMX_StateIdle: 445 pSECComponent->currentState = OMX_StatePause; 446 break; 447 case OMX_StateExecuting: 448 pSECComponent->currentState = OMX_StatePause; 449 break; 450 case OMX_StateWaitForResources: 451 ret = OMX_ErrorIncorrectStateTransition; 452 break; 453 } 454 break; 455 case OMX_StateWaitForResources: 456 switch (currentState) { 457 case OMX_StateLoaded: 458 ret = SEC_OMX_In_WaitForResource(pOMXComponent); 459 pSECComponent->currentState = OMX_StateWaitForResources; 460 break; 461 case OMX_StateIdle: 462 case OMX_StateExecuting: 463 case OMX_StatePause: 464 ret = OMX_ErrorIncorrectStateTransition; 465 break; 466 } 467 break; 468 } 469 470 EXIT: 471 if (ret == OMX_ErrorNone) { 472 if (pSECComponent->pCallbacks != NULL) { 473 pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, 474 pSECComponent->callbackData, 475 OMX_EventCmdComplete, OMX_CommandStateSet, 476 destState, NULL); 477 } 478 } else { 479 if (pSECComponent->pCallbacks != NULL) { 480 pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, 481 pSECComponent->callbackData, 482 OMX_EventError, ret, 0, NULL); 483 } 484 } 485 FunctionOut(); 486 487 return ret; 488 } 489 490 static OMX_ERRORTYPE SEC_OMX_MessageHandlerThread(OMX_PTR threadData) 491 { 492 OMX_ERRORTYPE ret = OMX_ErrorNone; 493 OMX_COMPONENTTYPE *pOMXComponent = NULL; 494 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 495 SEC_OMX_MESSAGE *message = NULL; 496 OMX_U32 messageType = 0, portIndex = 0; 497 498 FunctionIn(); 499 500 if (threadData == NULL) { 501 ret = OMX_ErrorBadParameter; 502 goto EXIT; 503 } 504 505 pOMXComponent = (OMX_COMPONENTTYPE *)threadData; 506 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 507 if (ret != OMX_ErrorNone) { 508 goto EXIT; 509 } 510 511 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 512 513 while (pSECComponent->bExitMessageHandlerThread != OMX_TRUE) { 514 SEC_OSAL_SemaphoreWait(pSECComponent->msgSemaphoreHandle); 515 message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECComponent->messageQ); 516 if (message != NULL) { 517 messageType = message->messageType; 518 switch (messageType) { 519 case OMX_CommandStateSet: 520 ret = SEC_OMX_ComponentStateSet(pOMXComponent, message->messageParam); 521 break; 522 case OMX_CommandFlush: 523 ret = SEC_OMX_BufferFlushProcess(pOMXComponent, message->messageParam); 524 break; 525 case OMX_CommandPortDisable: 526 ret = SEC_OMX_PortDisableProcess(pOMXComponent, message->messageParam); 527 break; 528 case OMX_CommandPortEnable: 529 ret = SEC_OMX_PortEnableProcess(pOMXComponent, message->messageParam); 530 break; 531 case OMX_CommandMarkBuffer: 532 portIndex = message->messageParam; 533 pSECComponent->pSECPort[portIndex].markType.hMarkTargetComponent = ((OMX_MARKTYPE *)message->pCmdData)->hMarkTargetComponent; 534 pSECComponent->pSECPort[portIndex].markType.pMarkData = ((OMX_MARKTYPE *)message->pCmdData)->pMarkData; 535 break; 536 case (OMX_COMMANDTYPE)SEC_OMX_CommandComponentDeInit: 537 pSECComponent->bExitMessageHandlerThread = OMX_TRUE; 538 break; 539 default: 540 break; 541 } 542 SEC_OSAL_Free(message); 543 message = NULL; 544 } 545 } 546 547 SEC_OSAL_ThreadExit(NULL); 548 549 EXIT: 550 FunctionOut(); 551 552 return ret; 553 } 554 555 static OMX_ERRORTYPE SEC_StateSet(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 556 { 557 OMX_U32 destState = nParam; 558 OMX_U32 i = 0; 559 560 if ((destState == OMX_StateIdle) && (pSECComponent->currentState == OMX_StateLoaded)) { 561 pSECComponent->transientState = SEC_OMX_TransStateLoadedToIdle; 562 for(i = 0; i < pSECComponent->portParam.nPorts; i++) { 563 pSECComponent->pSECPort[i].portState = OMX_StateIdle; 564 } 565 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateIdle"); 566 } else if ((destState == OMX_StateLoaded) && (pSECComponent->currentState == OMX_StateIdle)) { 567 pSECComponent->transientState = SEC_OMX_TransStateIdleToLoaded; 568 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 569 pSECComponent->pSECPort[i].portState = OMX_StateLoaded; 570 } 571 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateLoaded"); 572 } else if ((destState == OMX_StateIdle) && (pSECComponent->currentState == OMX_StateExecuting)) { 573 pSECComponent->transientState = SEC_OMX_TransStateExecutingToIdle; 574 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateIdle"); 575 } else if ((destState == OMX_StateExecuting) && (pSECComponent->currentState == OMX_StateIdle)) { 576 pSECComponent->transientState = SEC_OMX_TransStateIdleToExecuting; 577 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateExecuting"); 578 } else if (destState == OMX_StateInvalid) { 579 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 580 pSECComponent->pSECPort[i].portState = OMX_StateInvalid; 581 } 582 } 583 584 return OMX_ErrorNone; 585 } 586 587 static OMX_ERRORTYPE SEC_SetPortFlush(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 588 { 589 OMX_ERRORTYPE ret = OMX_ErrorNone; 590 SEC_OMX_BASEPORT *pSECPort = NULL; 591 OMX_U32 portIndex = nParam; 592 OMX_U16 i = 0, cnt = 0, index = 0; 593 594 595 if ((pSECComponent->currentState == OMX_StateExecuting) || 596 (pSECComponent->currentState == OMX_StatePause)) { 597 if ((portIndex != ALL_PORT_INDEX) && 598 ((OMX_S32)portIndex >= (OMX_S32)pSECComponent->portParam.nPorts)) { 599 ret = OMX_ErrorBadPortIndex; 600 goto EXIT; 601 } 602 603 /********************* 604 * need flush event set ????? 605 **********************/ 606 cnt = (portIndex == ALL_PORT_INDEX ) ? ALL_PORT_NUM : 1; 607 for (i = 0; i < cnt; i++) { 608 if (portIndex == ALL_PORT_INDEX) 609 index = i; 610 else 611 index = portIndex; 612 pSECComponent->pSECPort[index].bIsPortFlushed = OMX_TRUE; 613 } 614 } else { 615 ret = OMX_ErrorIncorrectStateOperation; 616 goto EXIT; 617 } 618 ret = OMX_ErrorNone; 619 620 EXIT: 621 return ret; 622 } 623 624 static OMX_ERRORTYPE SEC_SetPortEnable(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 625 { 626 OMX_ERRORTYPE ret = OMX_ErrorNone; 627 SEC_OMX_BASEPORT *pSECPort = NULL; 628 OMX_U32 portIndex = nParam; 629 OMX_U16 i = 0, cnt = 0; 630 631 FunctionIn(); 632 633 if ((portIndex != ALL_PORT_INDEX) && 634 ((OMX_S32)portIndex >= (OMX_S32)pSECComponent->portParam.nPorts)) { 635 ret = OMX_ErrorBadPortIndex; 636 goto EXIT; 637 } 638 639 if (portIndex == ALL_PORT_INDEX) { 640 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 641 pSECPort = &pSECComponent->pSECPort[i]; 642 if (CHECK_PORT_ENABLED(pSECPort)) { 643 ret = OMX_ErrorIncorrectStateOperation; 644 goto EXIT; 645 } else { 646 pSECPort->portState = OMX_StateIdle; 647 } 648 } 649 } else { 650 pSECPort = &pSECComponent->pSECPort[portIndex]; 651 if (CHECK_PORT_ENABLED(pSECPort)) { 652 ret = OMX_ErrorIncorrectStateOperation; 653 goto EXIT; 654 } else { 655 pSECPort->portState = OMX_StateIdle; 656 } 657 } 658 ret = OMX_ErrorNone; 659 660 EXIT: 661 FunctionOut(); 662 663 return ret; 664 665 } 666 667 static OMX_ERRORTYPE SEC_SetPortDisable(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 668 { 669 OMX_ERRORTYPE ret = OMX_ErrorNone; 670 SEC_OMX_BASEPORT *pSECPort = NULL; 671 OMX_U32 portIndex = nParam; 672 OMX_U16 i = 0, cnt = 0; 673 674 FunctionIn(); 675 676 if ((portIndex != ALL_PORT_INDEX) && 677 ((OMX_S32)portIndex >= (OMX_S32)pSECComponent->portParam.nPorts)) { 678 ret = OMX_ErrorBadPortIndex; 679 goto EXIT; 680 } 681 682 if (portIndex == ALL_PORT_INDEX) { 683 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 684 pSECPort = &pSECComponent->pSECPort[i]; 685 if (!CHECK_PORT_ENABLED(pSECPort)) { 686 ret = OMX_ErrorIncorrectStateOperation; 687 goto EXIT; 688 } 689 pSECPort->portState = OMX_StateLoaded; 690 pSECPort->bIsPortDisabled = OMX_TRUE; 691 } 692 } else { 693 pSECPort = &pSECComponent->pSECPort[portIndex]; 694 pSECPort->portState = OMX_StateLoaded; 695 pSECPort->bIsPortDisabled = OMX_TRUE; 696 } 697 ret = OMX_ErrorNone; 698 699 EXIT: 700 FunctionOut(); 701 702 return ret; 703 } 704 705 static OMX_ERRORTYPE SEC_SetMarkBuffer(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 706 { 707 OMX_ERRORTYPE ret = OMX_ErrorNone; 708 SEC_OMX_BASEPORT *pSECPort = NULL; 709 OMX_U32 portIndex = nParam; 710 OMX_U16 i = 0, cnt = 0; 711 712 713 if (nParam >= pSECComponent->portParam.nPorts) { 714 ret = OMX_ErrorBadPortIndex; 715 goto EXIT; 716 } 717 718 if ((pSECComponent->currentState == OMX_StateExecuting) || 719 (pSECComponent->currentState == OMX_StatePause)) { 720 ret = OMX_ErrorNone; 721 } else { 722 ret = OMX_ErrorIncorrectStateOperation; 723 } 724 725 EXIT: 726 return ret; 727 } 728 729 static OMX_ERRORTYPE SEC_OMX_CommandQueue( 730 SEC_OMX_BASECOMPONENT *pSECComponent, 731 OMX_COMMANDTYPE Cmd, 732 OMX_U32 nParam, 733 OMX_PTR pCmdData) 734 { 735 OMX_ERRORTYPE ret = OMX_ErrorNone; 736 SEC_OMX_MESSAGE *command = (SEC_OMX_MESSAGE *)SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE)); 737 738 if (command == NULL) { 739 ret = OMX_ErrorInsufficientResources; 740 goto EXIT; 741 } 742 command->messageType = (OMX_U32)Cmd; 743 command->messageParam = nParam; 744 command->pCmdData = pCmdData; 745 746 ret = SEC_OSAL_Queue(&pSECComponent->messageQ, (void *)command); 747 if (ret != 0) { 748 ret = OMX_ErrorUndefined; 749 goto EXIT; 750 } 751 ret = SEC_OSAL_SemaphorePost(pSECComponent->msgSemaphoreHandle); 752 753 EXIT: 754 return ret; 755 } 756 757 OMX_ERRORTYPE SEC_OMX_SendCommand( 758 OMX_IN OMX_HANDLETYPE hComponent, 759 OMX_IN OMX_COMMANDTYPE Cmd, 760 OMX_IN OMX_U32 nParam, 761 OMX_IN OMX_PTR pCmdData) 762 { 763 OMX_ERRORTYPE ret = OMX_ErrorNone; 764 OMX_COMPONENTTYPE *pOMXComponent = NULL; 765 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 766 SEC_OMX_MESSAGE *message = NULL; 767 768 FunctionIn(); 769 770 if (hComponent == NULL) { 771 ret = OMX_ErrorBadParameter; 772 goto EXIT; 773 } 774 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 775 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 776 if (ret != OMX_ErrorNone) { 777 goto EXIT; 778 } 779 780 if (pOMXComponent->pComponentPrivate == NULL) { 781 ret = OMX_ErrorBadParameter; 782 goto EXIT; 783 } 784 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 785 786 if (pSECComponent->currentState == OMX_StateInvalid) { 787 ret = OMX_ErrorInvalidState; 788 goto EXIT; 789 } 790 791 switch (Cmd) { 792 case OMX_CommandStateSet : 793 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandStateSet"); 794 SEC_StateSet(pSECComponent, nParam); 795 break; 796 case OMX_CommandFlush : 797 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandFlush"); 798 ret = SEC_SetPortFlush(pSECComponent, nParam); 799 if (ret != OMX_ErrorNone) 800 goto EXIT; 801 break; 802 case OMX_CommandPortDisable : 803 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandPortDisable"); 804 ret = SEC_SetPortDisable(pSECComponent, nParam); 805 if (ret != OMX_ErrorNone) 806 goto EXIT; 807 break; 808 case OMX_CommandPortEnable : 809 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandPortEnable"); 810 ret = SEC_SetPortEnable(pSECComponent, nParam); 811 if (ret != OMX_ErrorNone) 812 goto EXIT; 813 break; 814 case OMX_CommandMarkBuffer : 815 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandMarkBuffer"); 816 ret = SEC_SetMarkBuffer(pSECComponent, nParam); 817 if (ret != OMX_ErrorNone) 818 goto EXIT; 819 break; 820 /* 821 case SEC_CommandFillBuffer : 822 case SEC_CommandEmptyBuffer : 823 case SEC_CommandDeInit : 824 */ 825 default: 826 break; 827 } 828 829 ret = SEC_OMX_CommandQueue(pSECComponent, Cmd, nParam, pCmdData); 830 831 EXIT: 832 FunctionOut(); 833 834 return ret; 835 } 836 837 OMX_ERRORTYPE SEC_OMX_GetParameter( 838 OMX_IN OMX_HANDLETYPE hComponent, 839 OMX_IN OMX_INDEXTYPE nParamIndex, 840 OMX_INOUT OMX_PTR ComponentParameterStructure) 841 { 842 OMX_ERRORTYPE ret = OMX_ErrorNone; 843 OMX_COMPONENTTYPE *pOMXComponent = NULL; 844 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 845 846 FunctionIn(); 847 848 if (hComponent == NULL) { 849 ret = OMX_ErrorBadParameter; 850 goto EXIT; 851 } 852 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 853 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 854 if (ret != OMX_ErrorNone) { 855 goto EXIT; 856 } 857 858 if (pOMXComponent->pComponentPrivate == NULL) { 859 ret = OMX_ErrorBadParameter; 860 goto EXIT; 861 } 862 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 863 864 if (ComponentParameterStructure == NULL) { 865 ret = OMX_ErrorBadParameter; 866 goto EXIT; 867 } 868 if (pSECComponent->currentState == OMX_StateInvalid) { 869 ret = OMX_ErrorInvalidState; 870 goto EXIT; 871 } 872 873 switch (nParamIndex) { 874 case (OMX_INDEXTYPE)OMX_COMPONENT_CAPABILITY_TYPE_INDEX: 875 { 876 /* For Android PV OpenCORE */ 877 OMXComponentCapabilityFlagsType *capabilityFlags = (OMXComponentCapabilityFlagsType *)ComponentParameterStructure; 878 SEC_OSAL_Memcpy(capabilityFlags, &pSECComponent->capabilityFlags, sizeof(OMXComponentCapabilityFlagsType)); 879 } 880 break; 881 case OMX_IndexParamAudioInit: 882 case OMX_IndexParamVideoInit: 883 case OMX_IndexParamImageInit: 884 case OMX_IndexParamOtherInit: 885 { 886 OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure; 887 ret = SEC_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE)); 888 if (ret != OMX_ErrorNone) { 889 goto EXIT; 890 } 891 portParam->nPorts = 0; 892 portParam->nStartPortNumber = 0; 893 } 894 break; 895 case OMX_IndexParamPortDefinition: 896 { 897 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; 898 OMX_U32 portIndex = portDefinition->nPortIndex; 899 SEC_OMX_BASEPORT *pSECPort; 900 901 if (portIndex >= pSECComponent->portParam.nPorts) { 902 ret = OMX_ErrorBadPortIndex; 903 goto EXIT; 904 } 905 ret = SEC_OMX_Check_SizeVersion(portDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 906 if (ret != OMX_ErrorNone) { 907 goto EXIT; 908 } 909 910 pSECPort = &pSECComponent->pSECPort[portIndex]; 911 SEC_OSAL_Memcpy(portDefinition, &pSECPort->portDefinition, portDefinition->nSize); 912 } 913 break; 914 case OMX_IndexParamPriorityMgmt: 915 { 916 OMX_PRIORITYMGMTTYPE *compPriority = (OMX_PRIORITYMGMTTYPE *)ComponentParameterStructure; 917 918 ret = SEC_OMX_Check_SizeVersion(compPriority, sizeof(OMX_PRIORITYMGMTTYPE)); 919 if (ret != OMX_ErrorNone) { 920 goto EXIT; 921 } 922 923 compPriority->nGroupID = pSECComponent->compPriority.nGroupID; 924 compPriority->nGroupPriority = pSECComponent->compPriority.nGroupPriority; 925 } 926 break; 927 928 case OMX_IndexParamCompBufferSupplier: 929 { 930 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure; 931 OMX_U32 portIndex = bufferSupplier->nPortIndex; 932 SEC_OMX_BASEPORT *pSECPort; 933 934 if ((pSECComponent->currentState == OMX_StateLoaded) || 935 (pSECComponent->currentState == OMX_StateWaitForResources)) { 936 if (portIndex >= pSECComponent->portParam.nPorts) { 937 ret = OMX_ErrorBadPortIndex; 938 goto EXIT; 939 } 940 ret = SEC_OMX_Check_SizeVersion(bufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 941 if (ret != OMX_ErrorNone) { 942 goto EXIT; 943 } 944 945 pSECPort = &pSECComponent->pSECPort[portIndex]; 946 947 948 if (pSECPort->portDefinition.eDir == OMX_DirInput) { 949 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 950 bufferSupplier->eBufferSupplier = OMX_BufferSupplyInput; 951 } else if (CHECK_PORT_TUNNELED(pSECPort)) { 952 bufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput; 953 } else { 954 bufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified; 955 } 956 } else { 957 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 958 bufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput; 959 } else if (CHECK_PORT_TUNNELED(pSECPort)) { 960 bufferSupplier->eBufferSupplier = OMX_BufferSupplyInput; 961 } else { 962 bufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified; 963 } 964 } 965 } 966 else 967 { 968 ret = OMX_ErrorIncorrectStateOperation; 969 goto EXIT; 970 } 971 } 972 break; 973 default: 974 { 975 ret = OMX_ErrorUnsupportedIndex; 976 goto EXIT; 977 } 978 break; 979 } 980 981 ret = OMX_ErrorNone; 982 983 EXIT: 984 985 FunctionOut(); 986 987 return ret; 988 } 989 990 OMX_ERRORTYPE SEC_OMX_SetParameter( 991 OMX_IN OMX_HANDLETYPE hComponent, 992 OMX_IN OMX_INDEXTYPE nIndex, 993 OMX_IN OMX_PTR ComponentParameterStructure) 994 { 995 OMX_ERRORTYPE ret = OMX_ErrorNone; 996 OMX_COMPONENTTYPE *pOMXComponent = NULL; 997 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 998 999 FunctionIn(); 1000 1001 if (hComponent == NULL) { 1002 ret = OMX_ErrorBadParameter; 1003 goto EXIT; 1004 } 1005 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1006 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1007 if (ret != OMX_ErrorNone) { 1008 goto EXIT; 1009 } 1010 1011 if (pOMXComponent->pComponentPrivate == NULL) { 1012 ret = OMX_ErrorBadParameter; 1013 goto EXIT; 1014 } 1015 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1016 1017 if (ComponentParameterStructure == NULL) { 1018 ret = OMX_ErrorBadParameter; 1019 goto EXIT; 1020 } 1021 if (pSECComponent->currentState == OMX_StateInvalid) { 1022 ret = OMX_ErrorInvalidState; 1023 goto EXIT; 1024 } 1025 1026 switch (nIndex) { 1027 case OMX_IndexParamAudioInit: 1028 case OMX_IndexParamVideoInit: 1029 case OMX_IndexParamImageInit: 1030 case OMX_IndexParamOtherInit: 1031 { 1032 OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure; 1033 ret = SEC_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE)); 1034 if (ret != OMX_ErrorNone) { 1035 goto EXIT; 1036 } 1037 1038 if ((pSECComponent->currentState != OMX_StateLoaded) && 1039 (pSECComponent->currentState != OMX_StateWaitForResources)) { 1040 ret = OMX_ErrorIncorrectStateOperation; 1041 goto EXIT; 1042 } 1043 ret = OMX_ErrorUndefined; 1044 /* SEC_OSAL_Memcpy(&pSECComponent->portParam, portParam, sizeof(OMX_PORT_PARAM_TYPE)); */ 1045 } 1046 break; 1047 case OMX_IndexParamPortDefinition: 1048 { 1049 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; 1050 OMX_U32 portIndex = portDefinition->nPortIndex; 1051 SEC_OMX_BASEPORT *pSECPort; 1052 1053 if (portIndex >= pSECComponent->portParam.nPorts) { 1054 ret = OMX_ErrorBadPortIndex; 1055 goto EXIT; 1056 } 1057 ret = SEC_OMX_Check_SizeVersion(portDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 1058 if (ret != OMX_ErrorNone) { 1059 goto EXIT; 1060 } 1061 1062 pSECPort = &pSECComponent->pSECPort[portIndex]; 1063 1064 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 1065 if (pSECPort->portDefinition.bEnabled == OMX_TRUE) { 1066 ret = OMX_ErrorIncorrectStateOperation; 1067 goto EXIT; 1068 } 1069 } 1070 if (portDefinition->nBufferCountActual < pSECPort->portDefinition.nBufferCountMin) { 1071 ret = OMX_ErrorBadParameter; 1072 goto EXIT; 1073 } 1074 1075 SEC_OSAL_Memcpy(&pSECPort->portDefinition, portDefinition, portDefinition->nSize); 1076 } 1077 break; 1078 case OMX_IndexParamPriorityMgmt: 1079 { 1080 OMX_PRIORITYMGMTTYPE *compPriority = (OMX_PRIORITYMGMTTYPE *)ComponentParameterStructure; 1081 1082 if ((pSECComponent->currentState != OMX_StateLoaded) && 1083 (pSECComponent->currentState != OMX_StateWaitForResources)) { 1084 ret = OMX_ErrorIncorrectStateOperation; 1085 goto EXIT; 1086 } 1087 1088 ret = SEC_OMX_Check_SizeVersion(compPriority, sizeof(OMX_PRIORITYMGMTTYPE)); 1089 if (ret != OMX_ErrorNone) { 1090 goto EXIT; 1091 } 1092 1093 pSECComponent->compPriority.nGroupID = compPriority->nGroupID; 1094 pSECComponent->compPriority.nGroupPriority = compPriority->nGroupPriority; 1095 } 1096 break; 1097 case OMX_IndexParamCompBufferSupplier: 1098 { 1099 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure; 1100 OMX_U32 portIndex = bufferSupplier->nPortIndex; 1101 SEC_OMX_BASEPORT *pSECPort = &pSECComponent->pSECPort[portIndex]; 1102 1103 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 1104 if (pSECPort->portDefinition.bEnabled == OMX_TRUE) { 1105 ret = OMX_ErrorIncorrectStateOperation; 1106 goto EXIT; 1107 } 1108 } 1109 1110 if (portIndex >= pSECComponent->portParam.nPorts) { 1111 ret = OMX_ErrorBadPortIndex; 1112 goto EXIT; 1113 } 1114 ret = SEC_OMX_Check_SizeVersion(bufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 1115 if (ret != OMX_ErrorNone) { 1116 goto EXIT; 1117 } 1118 1119 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyUnspecified) { 1120 ret = OMX_ErrorNone; 1121 goto EXIT; 1122 } 1123 if (CHECK_PORT_TUNNELED(pSECPort) == 0) { 1124 ret = OMX_ErrorNone; /*OMX_ErrorNone ?????*/ 1125 goto EXIT; 1126 } 1127 1128 if (pSECPort->portDefinition.eDir == OMX_DirInput) { 1129 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyInput) { 1130 /* 1131 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1132 ret = OMX_ErrorNone; 1133 } 1134 */ 1135 pSECPort->tunnelFlags |= SEC_TUNNEL_IS_SUPPLIER; 1136 bufferSupplier->nPortIndex = pSECPort->tunneledPort; 1137 ret = OMX_SetParameter(pSECPort->tunneledComponent, OMX_IndexParamCompBufferSupplier, bufferSupplier); 1138 goto EXIT; 1139 } else if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) { 1140 ret = OMX_ErrorNone; 1141 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1142 pSECPort->tunnelFlags &= ~SEC_TUNNEL_IS_SUPPLIER; 1143 bufferSupplier->nPortIndex = pSECPort->tunneledPort; 1144 ret = OMX_SetParameter(pSECPort->tunneledComponent, OMX_IndexParamCompBufferSupplier, bufferSupplier); 1145 } 1146 goto EXIT; 1147 } 1148 } else if (pSECPort->portDefinition.eDir == OMX_DirOutput) { 1149 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyInput) { 1150 ret = OMX_ErrorNone; 1151 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1152 pSECPort->tunnelFlags &= ~SEC_TUNNEL_IS_SUPPLIER; 1153 ret = OMX_ErrorNone; 1154 } 1155 goto EXIT; 1156 } else if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) { 1157 /* 1158 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1159 ret = OMX_ErrorNone; 1160 } 1161 */ 1162 pSECPort->tunnelFlags |= SEC_TUNNEL_IS_SUPPLIER; 1163 ret = OMX_ErrorNone; 1164 goto EXIT; 1165 } 1166 } 1167 } 1168 break; 1169 default: 1170 { 1171 ret = OMX_ErrorUnsupportedIndex; 1172 goto EXIT; 1173 } 1174 break; 1175 } 1176 1177 ret = OMX_ErrorNone; 1178 1179 EXIT: 1180 1181 FunctionOut(); 1182 1183 return ret; 1184 } 1185 1186 OMX_ERRORTYPE SEC_OMX_GetConfig( 1187 OMX_IN OMX_HANDLETYPE hComponent, 1188 OMX_IN OMX_INDEXTYPE nIndex, 1189 OMX_INOUT OMX_PTR pComponentConfigStructure) 1190 { 1191 OMX_ERRORTYPE ret = OMX_ErrorNone; 1192 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1193 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1194 1195 FunctionIn(); 1196 1197 if (hComponent == NULL) { 1198 ret = OMX_ErrorBadParameter; 1199 goto EXIT; 1200 } 1201 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1202 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1203 if (ret != OMX_ErrorNone) { 1204 goto EXIT; 1205 } 1206 1207 if (pOMXComponent->pComponentPrivate == NULL) { 1208 ret = OMX_ErrorBadParameter; 1209 goto EXIT; 1210 } 1211 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1212 1213 if (pComponentConfigStructure == NULL) { 1214 ret = OMX_ErrorBadParameter; 1215 goto EXIT; 1216 } 1217 if (pSECComponent->currentState == OMX_StateInvalid) { 1218 ret = OMX_ErrorInvalidState; 1219 goto EXIT; 1220 } 1221 ret = OMX_ErrorUnsupportedIndex; 1222 1223 EXIT: 1224 FunctionOut(); 1225 1226 return ret; 1227 } 1228 1229 OMX_ERRORTYPE SEC_OMX_SetConfig( 1230 OMX_IN OMX_HANDLETYPE hComponent, 1231 OMX_IN OMX_INDEXTYPE nIndex, 1232 OMX_IN OMX_PTR pComponentConfigStructure) 1233 { 1234 OMX_ERRORTYPE ret = OMX_ErrorNone; 1235 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1236 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1237 1238 FunctionIn(); 1239 1240 if (hComponent == NULL) { 1241 ret = OMX_ErrorBadParameter; 1242 goto EXIT; 1243 } 1244 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1245 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1246 if (ret != OMX_ErrorNone) { 1247 goto EXIT; 1248 } 1249 1250 if (pOMXComponent->pComponentPrivate == NULL) { 1251 ret = OMX_ErrorBadParameter; 1252 goto EXIT; 1253 } 1254 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1255 1256 if (pComponentConfigStructure == NULL) { 1257 ret = OMX_ErrorBadParameter; 1258 goto EXIT; 1259 } 1260 if (pSECComponent->currentState == OMX_StateInvalid) { 1261 ret = OMX_ErrorInvalidState; 1262 goto EXIT; 1263 } 1264 ret = OMX_ErrorUnsupportedIndex; 1265 1266 EXIT: 1267 FunctionOut(); 1268 1269 return ret; 1270 } 1271 1272 OMX_ERRORTYPE SEC_OMX_GetExtensionIndex( 1273 OMX_IN OMX_HANDLETYPE hComponent, 1274 OMX_IN OMX_STRING cParameterName, 1275 OMX_OUT OMX_INDEXTYPE *pIndexType) 1276 { 1277 OMX_ERRORTYPE ret = OMX_ErrorNone; 1278 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1279 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1280 1281 FunctionIn(); 1282 1283 if (hComponent == NULL) { 1284 ret = OMX_ErrorBadParameter; 1285 goto EXIT; 1286 } 1287 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1288 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1289 if (ret != OMX_ErrorNone) { 1290 goto EXIT; 1291 } 1292 1293 if (pOMXComponent->pComponentPrivate == NULL) { 1294 ret = OMX_ErrorBadParameter; 1295 goto EXIT; 1296 } 1297 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1298 1299 if ((cParameterName == NULL) || (pIndexType == NULL)) { 1300 ret = OMX_ErrorBadParameter; 1301 goto EXIT; 1302 } 1303 if (pSECComponent->currentState == OMX_StateInvalid) { 1304 ret = OMX_ErrorInvalidState; 1305 goto EXIT; 1306 } 1307 1308 ret = OMX_ErrorBadParameter; 1309 1310 EXIT: 1311 FunctionOut(); 1312 1313 return ret; 1314 } 1315 1316 OMX_ERRORTYPE SEC_OMX_SetCallbacks ( 1317 OMX_IN OMX_HANDLETYPE hComponent, 1318 OMX_IN OMX_CALLBACKTYPE* pCallbacks, 1319 OMX_IN OMX_PTR pAppData) 1320 { 1321 OMX_ERRORTYPE ret = OMX_ErrorNone; 1322 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1323 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1324 1325 FunctionIn(); 1326 1327 if (hComponent == NULL) { 1328 ret = OMX_ErrorBadParameter; 1329 goto EXIT; 1330 } 1331 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1332 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1333 if (ret != OMX_ErrorNone) { 1334 goto EXIT; 1335 } 1336 1337 if (pOMXComponent->pComponentPrivate == NULL) { 1338 ret = OMX_ErrorBadParameter; 1339 goto EXIT; 1340 } 1341 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1342 1343 if (pCallbacks == NULL) { 1344 ret = OMX_ErrorBadParameter; 1345 goto EXIT; 1346 } 1347 if (pSECComponent->currentState == OMX_StateInvalid) { 1348 ret = OMX_ErrorInvalidState; 1349 goto EXIT; 1350 } 1351 if (pSECComponent->currentState != OMX_StateLoaded) { 1352 ret = OMX_ErrorIncorrectStateOperation; 1353 goto EXIT; 1354 } 1355 1356 pSECComponent->pCallbacks = pCallbacks; 1357 pSECComponent->callbackData = pAppData; 1358 1359 ret = OMX_ErrorNone; 1360 1361 EXIT: 1362 FunctionOut(); 1363 1364 return ret; 1365 } 1366 1367 OMX_ERRORTYPE SEC_OMX_UseEGLImage( 1368 OMX_IN OMX_HANDLETYPE hComponent, 1369 OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr, 1370 OMX_IN OMX_U32 nPortIndex, 1371 OMX_IN OMX_PTR pAppPrivate, 1372 OMX_IN void *eglImage) 1373 { 1374 return OMX_ErrorNotImplemented; 1375 } 1376 1377 OMX_ERRORTYPE SEC_OMX_BaseComponent_Constructor( 1378 OMX_IN OMX_HANDLETYPE hComponent) 1379 { 1380 OMX_ERRORTYPE ret = OMX_ErrorNone; 1381 OMX_COMPONENTTYPE *pOMXComponent; 1382 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1383 1384 FunctionIn(); 1385 1386 if (hComponent == NULL) { 1387 ret = OMX_ErrorBadParameter; 1388 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); 1389 goto EXIT; 1390 } 1391 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1392 pSECComponent = SEC_OSAL_Malloc(sizeof(SEC_OMX_BASECOMPONENT)); 1393 if (pSECComponent == NULL) { 1394 ret = OMX_ErrorInsufficientResources; 1395 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1396 goto EXIT; 1397 } 1398 SEC_OSAL_Memset(pSECComponent, 0, sizeof(SEC_OMX_BASECOMPONENT)); 1399 pOMXComponent->pComponentPrivate = (OMX_PTR)pSECComponent; 1400 1401 ret = SEC_OSAL_SemaphoreCreate(&pSECComponent->msgSemaphoreHandle); 1402 if (ret != OMX_ErrorNone) { 1403 ret = OMX_ErrorInsufficientResources; 1404 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1405 goto EXIT; 1406 } 1407 ret = SEC_OSAL_MutexCreate(&pSECComponent->compMutex); 1408 if (ret != OMX_ErrorNone) { 1409 ret = OMX_ErrorInsufficientResources; 1410 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1411 goto EXIT; 1412 } 1413 1414 pSECComponent->bExitMessageHandlerThread = OMX_FALSE; 1415 SEC_OSAL_QueueCreate(&pSECComponent->messageQ); 1416 ret = SEC_OSAL_ThreadCreate(&pSECComponent->hMessageHandler, SEC_OMX_MessageHandlerThread, pOMXComponent); 1417 if (ret != OMX_ErrorNone) { 1418 ret = OMX_ErrorInsufficientResources; 1419 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1420 goto EXIT; 1421 } 1422 1423 pOMXComponent->GetComponentVersion = &SEC_OMX_GetComponentVersion; 1424 pOMXComponent->SendCommand = &SEC_OMX_SendCommand; 1425 pOMXComponent->GetExtensionIndex = &SEC_OMX_GetExtensionIndex; 1426 pOMXComponent->GetState = &SEC_OMX_GetState; 1427 pOMXComponent->SetCallbacks = &SEC_OMX_SetCallbacks; 1428 pOMXComponent->UseEGLImage = &SEC_OMX_UseEGLImage; 1429 1430 EXIT: 1431 FunctionOut(); 1432 1433 return ret; 1434 } 1435 1436 OMX_ERRORTYPE SEC_OMX_BaseComponent_Destructor( 1437 OMX_IN OMX_HANDLETYPE hComponent) 1438 { 1439 OMX_ERRORTYPE ret = OMX_ErrorNone; 1440 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1441 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1442 OMX_U32 semaValue = 0; 1443 1444 FunctionIn(); 1445 1446 if (hComponent == NULL) { 1447 ret = OMX_ErrorBadParameter; 1448 goto EXIT; 1449 } 1450 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1451 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1452 if (ret != OMX_ErrorNone) { 1453 goto EXIT; 1454 } 1455 1456 if (pOMXComponent->pComponentPrivate == NULL) { 1457 ret = OMX_ErrorBadParameter; 1458 goto EXIT; 1459 } 1460 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1461 1462 SEC_OMX_CommandQueue(pSECComponent, SEC_OMX_CommandComponentDeInit, 0, NULL); 1463 SEC_OSAL_SleepMillisec(0); 1464 SEC_OSAL_Get_SemaphoreCount(pSECComponent->msgSemaphoreHandle, &semaValue); 1465 if (semaValue == 0) 1466 SEC_OSAL_SemaphorePost(pSECComponent->msgSemaphoreHandle); 1467 SEC_OSAL_SemaphorePost(pSECComponent->msgSemaphoreHandle); 1468 1469 SEC_OSAL_ThreadTerminate(pSECComponent->hMessageHandler); 1470 pSECComponent->hMessageHandler = NULL; 1471 1472 SEC_OSAL_MutexTerminate(pSECComponent->compMutex); 1473 pSECComponent->compMutex = NULL; 1474 SEC_OSAL_SemaphoreTerminate(pSECComponent->msgSemaphoreHandle); 1475 pSECComponent->msgSemaphoreHandle = NULL; 1476 SEC_OSAL_QueueTerminate(&pSECComponent->messageQ); 1477 1478 SEC_OSAL_Free(pSECComponent); 1479 pSECComponent = NULL; 1480 1481 ret = OMX_ErrorNone; 1482 EXIT: 1483 FunctionOut(); 1484 1485 return ret; 1486 } 1487