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_TheadExit(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 (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 333 if (CHECK_PORT_ENABLED(pSECPort)) { 334 ret = pSECComponent->sec_AllocateTunnelBuffer(pSECPort, i); 335 if (ret!=OMX_ErrorNone) 336 goto EXIT; 337 } 338 } else { 339 if (CHECK_PORT_ENABLED(pSECPort)) { 340 SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[i].loadedResource); 341 pSECPort->portDefinition.bPopulated = OMX_TRUE; 342 } 343 } 344 } 345 ret = pSECComponent->sec_mfc_componentInit(pOMXComponent); 346 if (ret != OMX_ErrorNone) { 347 /* 348 * if (CHECK_PORT_TUNNELED == OMX_TRUE) thenTunnel Buffer Free 349 */ 350 goto EXIT; 351 } 352 pSECComponent->bExitBufferProcessThread = OMX_FALSE; 353 SEC_OSAL_SignalCreate(&pSECComponent->pauseEvent); 354 for (i = 0; i < ALL_PORT_NUM; i++) { 355 SEC_OSAL_SemaphoreCreate(&pSECComponent->pSECPort[i].bufferSemID); 356 } 357 for (i = 0; i < ALL_PORT_NUM; i++) { 358 SEC_OSAL_MutexCreate(&pSECComponent->secDataBuffer[i].bufferMutex); 359 } 360 ret = SEC_OSAL_ThreadCreate(&pSECComponent->hBufferProcess, 361 SEC_OMX_BufferProcessThread, 362 pOMXComponent); 363 if (ret != OMX_ErrorNone) { 364 /* 365 * if (CHECK_PORT_TUNNELED == OMX_TRUE) thenTunnel Buffer Free 366 */ 367 368 SEC_OSAL_SignalTerminate(pSECComponent->pauseEvent); 369 for (i = 0; i < ALL_PORT_NUM; i++) { 370 SEC_OSAL_MutexTerminate(pSECComponent->secDataBuffer[i].bufferMutex); 371 pSECComponent->secDataBuffer[i].bufferMutex = NULL; 372 } 373 for (i = 0; i < ALL_PORT_NUM; i++) { 374 SEC_OSAL_SemaphoreTerminate(pSECComponent->pSECPort[i].bufferSemID); 375 pSECComponent->pSECPort[i].bufferSemID = NULL; 376 } 377 378 ret = OMX_ErrorInsufficientResources; 379 goto EXIT; 380 } 381 pSECComponent->currentState = OMX_StateIdle; 382 break; 383 case OMX_StateExecuting: 384 case OMX_StatePause: 385 SEC_OMX_BufferFlushProcessNoEvent(pOMXComponent, ALL_PORT_INDEX); 386 pSECComponent->currentState = OMX_StateIdle; 387 break; 388 case OMX_StateWaitForResources: 389 pSECComponent->currentState = OMX_StateIdle; 390 break; 391 } 392 break; 393 case OMX_StateExecuting: 394 switch (currentState) { 395 case OMX_StateLoaded: 396 ret = OMX_ErrorIncorrectStateTransition; 397 break; 398 case OMX_StateIdle: 399 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 400 pSECPort = &pSECComponent->pSECPort[i]; 401 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort) && CHECK_PORT_ENABLED(pSECPort)) { 402 for (j = 0; j < pSECPort->tunnelBufferNum; j++) { 403 SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID); 404 } 405 } 406 } 407 408 pSECComponent->transientState = SEC_OMX_TransStateMax; 409 pSECComponent->currentState = OMX_StateExecuting; 410 SEC_OSAL_SignalSet(pSECComponent->pauseEvent); 411 break; 412 case OMX_StatePause: 413 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 414 pSECPort = &pSECComponent->pSECPort[i]; 415 if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort) && CHECK_PORT_ENABLED(pSECPort)) { 416 OMX_U32 semaValue = 0, cnt = 0; 417 SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[i].bufferSemID, &semaValue); 418 if (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) > semaValue) { 419 cnt = SEC_OSAL_GetElemNum(&pSECPort->bufferQ) - semaValue; 420 for (j = 0; j < cnt; j++) { 421 SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID); 422 } 423 } 424 } 425 } 426 427 pSECComponent->currentState = OMX_StateExecuting; 428 SEC_OSAL_SignalSet(pSECComponent->pauseEvent); 429 break; 430 case OMX_StateWaitForResources: 431 ret = OMX_ErrorIncorrectStateTransition; 432 break; 433 } 434 break; 435 case OMX_StatePause: 436 switch (currentState) { 437 case OMX_StateLoaded: 438 ret = OMX_ErrorIncorrectStateTransition; 439 break; 440 case OMX_StateIdle: 441 pSECComponent->currentState = OMX_StatePause; 442 break; 443 case OMX_StateExecuting: 444 pSECComponent->currentState = OMX_StatePause; 445 break; 446 case OMX_StateWaitForResources: 447 ret = OMX_ErrorIncorrectStateTransition; 448 break; 449 } 450 break; 451 case OMX_StateWaitForResources: 452 switch (currentState) { 453 case OMX_StateLoaded: 454 ret = SEC_OMX_In_WaitForResource(pOMXComponent); 455 pSECComponent->currentState = OMX_StateWaitForResources; 456 break; 457 case OMX_StateIdle: 458 case OMX_StateExecuting: 459 case OMX_StatePause: 460 ret = OMX_ErrorIncorrectStateTransition; 461 break; 462 } 463 break; 464 } 465 466 EXIT: 467 if (ret == OMX_ErrorNone) { 468 if (pSECComponent->pCallbacks != NULL) { 469 pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, 470 pSECComponent->callbackData, 471 OMX_EventCmdComplete, OMX_CommandStateSet, 472 destState, NULL); 473 } 474 } else { 475 if (pSECComponent->pCallbacks != NULL) { 476 pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, 477 pSECComponent->callbackData, 478 OMX_EventError, ret, 0, NULL); 479 } 480 } 481 FunctionOut(); 482 483 return ret; 484 } 485 486 static OMX_ERRORTYPE SEC_OMX_MessageHandlerThread(OMX_PTR threadData) 487 { 488 OMX_ERRORTYPE ret = OMX_ErrorNone; 489 OMX_COMPONENTTYPE *pOMXComponent = NULL; 490 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 491 SEC_OMX_MESSAGE *message = NULL; 492 OMX_U32 messageType = 0, portIndex = 0; 493 494 FunctionIn(); 495 496 if (threadData == NULL) { 497 ret = OMX_ErrorBadParameter; 498 goto EXIT; 499 } 500 501 pOMXComponent = (OMX_COMPONENTTYPE *)threadData; 502 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 503 if (ret != OMX_ErrorNone) { 504 goto EXIT; 505 } 506 507 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 508 509 while (pSECComponent->bExitMessageHandlerThread != OMX_TRUE) { 510 SEC_OSAL_SemaphoreWait(pSECComponent->msgSemaphoreHandle); 511 message = (SEC_OMX_MESSAGE *)SEC_OSAL_Dequeue(&pSECComponent->messageQ); 512 if (message != NULL) { 513 messageType = message->messageType; 514 switch (messageType) { 515 case OMX_CommandStateSet: 516 ret = SEC_OMX_ComponentStateSet(pOMXComponent, message->messageParam); 517 break; 518 case OMX_CommandFlush: 519 ret = SEC_OMX_BufferFlushProcess(pOMXComponent, message->messageParam); 520 break; 521 case OMX_CommandPortDisable: 522 ret = SEC_OMX_PortDisableProcess(pOMXComponent, message->messageParam); 523 break; 524 case OMX_CommandPortEnable: 525 ret = SEC_OMX_PortEnableProcess(pOMXComponent, message->messageParam); 526 break; 527 case OMX_CommandMarkBuffer: 528 portIndex = message->messageParam; 529 pSECComponent->pSECPort[portIndex].markType.hMarkTargetComponent = ((OMX_MARKTYPE *)message->pCmdData)->hMarkTargetComponent; 530 pSECComponent->pSECPort[portIndex].markType.pMarkData = ((OMX_MARKTYPE *)message->pCmdData)->pMarkData; 531 break; 532 case (OMX_COMMANDTYPE)SEC_OMX_CommandComponentDeInit: 533 pSECComponent->bExitMessageHandlerThread = OMX_TRUE; 534 break; 535 default: 536 break; 537 } 538 SEC_OSAL_Free(message); 539 message = NULL; 540 } 541 } 542 543 SEC_OSAL_TheadExit(NULL); 544 545 EXIT: 546 FunctionOut(); 547 548 return ret; 549 } 550 551 static OMX_ERRORTYPE SEC_StateSet(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 552 { 553 OMX_U32 destState = nParam; 554 OMX_U32 i = 0; 555 556 if ((destState == OMX_StateIdle) && (pSECComponent->currentState == OMX_StateLoaded)) { 557 pSECComponent->transientState = SEC_OMX_TransStateLoadedToIdle; 558 for(i = 0; i < pSECComponent->portParam.nPorts; i++) { 559 pSECComponent->pSECPort[i].portState = OMX_StateIdle; 560 } 561 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateIdle"); 562 } else if ((destState == OMX_StateLoaded) && (pSECComponent->currentState == OMX_StateIdle)) { 563 pSECComponent->transientState = SEC_OMX_TransStateIdleToLoaded; 564 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 565 pSECComponent->pSECPort[i].portState = OMX_StateLoaded; 566 } 567 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateLoaded"); 568 } else if ((destState == OMX_StateIdle) && (pSECComponent->currentState == OMX_StateExecuting)) { 569 pSECComponent->transientState = SEC_OMX_TransStateExecutingToIdle; 570 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateIdle"); 571 } else if ((destState == OMX_StateExecuting) && (pSECComponent->currentState == OMX_StateIdle)) { 572 pSECComponent->transientState = SEC_OMX_TransStateIdleToExecuting; 573 SEC_OSAL_Log(SEC_LOG_TRACE, "to OMX_StateExecuting"); 574 } else if (destState == OMX_StateInvalid) { 575 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 576 pSECComponent->pSECPort[i].portState = OMX_StateInvalid; 577 } 578 } 579 580 return OMX_ErrorNone; 581 } 582 583 static OMX_ERRORTYPE SEC_SetPortFlush(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 584 { 585 OMX_ERRORTYPE ret = OMX_ErrorNone; 586 SEC_OMX_BASEPORT *pSECPort = NULL; 587 OMX_U32 portIndex = nParam; 588 OMX_U16 i = 0, cnt = 0, index = 0; 589 590 591 if ((pSECComponent->currentState == OMX_StateExecuting) || 592 (pSECComponent->currentState == OMX_StatePause)) { 593 if ((portIndex != ALL_PORT_INDEX) && 594 ((OMX_S32)portIndex >= (OMX_S32)pSECComponent->portParam.nPorts)) { 595 ret = OMX_ErrorBadPortIndex; 596 goto EXIT; 597 } 598 599 /********************* 600 * need flush event set ????? 601 **********************/ 602 cnt = (portIndex == ALL_PORT_INDEX ) ? ALL_PORT_NUM : 1; 603 for (i = 0; i < cnt; i++) { 604 if (portIndex == ALL_PORT_INDEX) 605 index = i; 606 else 607 index = portIndex; 608 pSECComponent->pSECPort[index].bIsPortFlushed = OMX_TRUE; 609 } 610 } else { 611 ret = OMX_ErrorIncorrectStateOperation; 612 goto EXIT; 613 } 614 ret = OMX_ErrorNone; 615 616 EXIT: 617 return ret; 618 } 619 620 static OMX_ERRORTYPE SEC_SetPortEnable(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 621 { 622 OMX_ERRORTYPE ret = OMX_ErrorNone; 623 SEC_OMX_BASEPORT *pSECPort = NULL; 624 OMX_U32 portIndex = nParam; 625 OMX_U16 i = 0, cnt = 0; 626 627 FunctionIn(); 628 629 if ((portIndex != ALL_PORT_INDEX) && 630 ((OMX_S32)portIndex >= (OMX_S32)pSECComponent->portParam.nPorts)) { 631 ret = OMX_ErrorBadPortIndex; 632 goto EXIT; 633 } 634 635 if (portIndex == ALL_PORT_INDEX) { 636 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 637 pSECPort = &pSECComponent->pSECPort[i]; 638 if (CHECK_PORT_ENABLED(pSECPort)) { 639 ret = OMX_ErrorIncorrectStateOperation; 640 goto EXIT; 641 } else { 642 pSECPort->portState = OMX_StateIdle; 643 } 644 } 645 } else { 646 pSECPort = &pSECComponent->pSECPort[portIndex]; 647 if (CHECK_PORT_ENABLED(pSECPort)) { 648 ret = OMX_ErrorIncorrectStateOperation; 649 goto EXIT; 650 } else { 651 pSECPort->portState = OMX_StateIdle; 652 } 653 } 654 ret = OMX_ErrorNone; 655 656 EXIT: 657 FunctionOut(); 658 659 return ret; 660 661 } 662 663 static OMX_ERRORTYPE SEC_SetPortDisable(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 664 { 665 OMX_ERRORTYPE ret = OMX_ErrorNone; 666 SEC_OMX_BASEPORT *pSECPort = NULL; 667 OMX_U32 portIndex = nParam; 668 OMX_U16 i = 0, cnt = 0; 669 670 FunctionIn(); 671 672 if ((portIndex != ALL_PORT_INDEX) && 673 ((OMX_S32)portIndex >= (OMX_S32)pSECComponent->portParam.nPorts)) { 674 ret = OMX_ErrorBadPortIndex; 675 goto EXIT; 676 } 677 678 if (portIndex == ALL_PORT_INDEX) { 679 for (i = 0; i < pSECComponent->portParam.nPorts; i++) { 680 pSECPort = &pSECComponent->pSECPort[i]; 681 if (!CHECK_PORT_ENABLED(pSECPort)) { 682 ret = OMX_ErrorIncorrectStateOperation; 683 goto EXIT; 684 } 685 pSECPort->portState = OMX_StateLoaded; 686 pSECPort->bIsPortDisabled = OMX_TRUE; 687 } 688 } else { 689 pSECPort = &pSECComponent->pSECPort[portIndex]; 690 pSECPort->portState = OMX_StateLoaded; 691 pSECPort->bIsPortDisabled = OMX_TRUE; 692 } 693 ret = OMX_ErrorNone; 694 695 EXIT: 696 FunctionOut(); 697 698 return ret; 699 } 700 701 static OMX_ERRORTYPE SEC_SetMarkBuffer(SEC_OMX_BASECOMPONENT *pSECComponent, OMX_U32 nParam) 702 { 703 OMX_ERRORTYPE ret = OMX_ErrorNone; 704 SEC_OMX_BASEPORT *pSECPort = NULL; 705 OMX_U32 portIndex = nParam; 706 OMX_U16 i = 0, cnt = 0; 707 708 709 if (nParam >= pSECComponent->portParam.nPorts) { 710 ret = OMX_ErrorBadPortIndex; 711 goto EXIT; 712 } 713 714 if ((pSECComponent->currentState == OMX_StateExecuting) || 715 (pSECComponent->currentState == OMX_StatePause)) { 716 ret = OMX_ErrorNone; 717 } else { 718 ret = OMX_ErrorIncorrectStateOperation; 719 } 720 721 EXIT: 722 return ret; 723 } 724 725 static OMX_ERRORTYPE SEC_OMX_CommandQueue( 726 SEC_OMX_BASECOMPONENT *pSECComponent, 727 OMX_COMMANDTYPE Cmd, 728 OMX_U32 nParam, 729 OMX_PTR pCmdData) 730 { 731 OMX_ERRORTYPE ret = OMX_ErrorNone; 732 SEC_OMX_MESSAGE *command = (SEC_OMX_MESSAGE *)SEC_OSAL_Malloc(sizeof(SEC_OMX_MESSAGE)); 733 734 if (command == NULL) { 735 ret = OMX_ErrorInsufficientResources; 736 goto EXIT; 737 } 738 command->messageType = (OMX_U32)Cmd; 739 command->messageParam = nParam; 740 command->pCmdData = pCmdData; 741 742 ret = SEC_OSAL_Queue(&pSECComponent->messageQ, (void *)command); 743 if (ret != 0) { 744 ret = OMX_ErrorUndefined; 745 goto EXIT; 746 } 747 ret = SEC_OSAL_SemaphorePost(pSECComponent->msgSemaphoreHandle); 748 749 EXIT: 750 return ret; 751 } 752 753 OMX_ERRORTYPE SEC_OMX_SendCommand( 754 OMX_IN OMX_HANDLETYPE hComponent, 755 OMX_IN OMX_COMMANDTYPE Cmd, 756 OMX_IN OMX_U32 nParam, 757 OMX_IN OMX_PTR pCmdData) 758 { 759 OMX_ERRORTYPE ret = OMX_ErrorNone; 760 OMX_COMPONENTTYPE *pOMXComponent = NULL; 761 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 762 SEC_OMX_MESSAGE *message = NULL; 763 764 FunctionIn(); 765 766 if (hComponent == NULL) { 767 ret = OMX_ErrorBadParameter; 768 goto EXIT; 769 } 770 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 771 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 772 if (ret != OMX_ErrorNone) { 773 goto EXIT; 774 } 775 776 if (pOMXComponent->pComponentPrivate == NULL) { 777 ret = OMX_ErrorBadParameter; 778 goto EXIT; 779 } 780 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 781 782 if (pSECComponent->currentState == OMX_StateInvalid) { 783 ret = OMX_ErrorInvalidState; 784 goto EXIT; 785 } 786 787 switch (Cmd) { 788 case OMX_CommandStateSet : 789 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandStateSet"); 790 SEC_StateSet(pSECComponent, nParam); 791 break; 792 case OMX_CommandFlush : 793 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandFlush"); 794 ret = SEC_SetPortFlush(pSECComponent, nParam); 795 if (ret != OMX_ErrorNone) 796 goto EXIT; 797 break; 798 case OMX_CommandPortDisable : 799 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandPortDisable"); 800 ret = SEC_SetPortDisable(pSECComponent, nParam); 801 if (ret != OMX_ErrorNone) 802 goto EXIT; 803 break; 804 case OMX_CommandPortEnable : 805 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandPortEnable"); 806 ret = SEC_SetPortEnable(pSECComponent, nParam); 807 if (ret != OMX_ErrorNone) 808 goto EXIT; 809 break; 810 case OMX_CommandMarkBuffer : 811 SEC_OSAL_Log(SEC_LOG_TRACE, "Command: OMX_CommandMarkBuffer"); 812 ret = SEC_SetMarkBuffer(pSECComponent, nParam); 813 if (ret != OMX_ErrorNone) 814 goto EXIT; 815 break; 816 /* 817 case SEC_CommandFillBuffer : 818 case SEC_CommandEmptyBuffer : 819 case SEC_CommandDeInit : 820 */ 821 default: 822 break; 823 } 824 825 ret = SEC_OMX_CommandQueue(pSECComponent, Cmd, nParam, pCmdData); 826 827 EXIT: 828 FunctionOut(); 829 830 return ret; 831 } 832 833 OMX_ERRORTYPE SEC_OMX_GetParameter( 834 OMX_IN OMX_HANDLETYPE hComponent, 835 OMX_IN OMX_INDEXTYPE nParamIndex, 836 OMX_INOUT OMX_PTR ComponentParameterStructure) 837 { 838 OMX_ERRORTYPE ret = OMX_ErrorNone; 839 OMX_COMPONENTTYPE *pOMXComponent = NULL; 840 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 841 842 FunctionIn(); 843 844 if (hComponent == NULL) { 845 ret = OMX_ErrorBadParameter; 846 goto EXIT; 847 } 848 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 849 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 850 if (ret != OMX_ErrorNone) { 851 goto EXIT; 852 } 853 854 if (pOMXComponent->pComponentPrivate == NULL) { 855 ret = OMX_ErrorBadParameter; 856 goto EXIT; 857 } 858 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 859 860 if (ComponentParameterStructure == NULL) { 861 ret = OMX_ErrorBadParameter; 862 goto EXIT; 863 } 864 if (pSECComponent->currentState == OMX_StateInvalid) { 865 ret = OMX_ErrorInvalidState; 866 goto EXIT; 867 } 868 869 switch (nParamIndex) { 870 case (OMX_INDEXTYPE)OMX_COMPONENT_CAPABILITY_TYPE_INDEX: 871 { 872 /* For Android PV OpenCORE */ 873 OMXComponentCapabilityFlagsType *capabilityFlags = (OMXComponentCapabilityFlagsType *)ComponentParameterStructure; 874 SEC_OSAL_Memcpy(capabilityFlags, &pSECComponent->capabilityFlags, sizeof(OMXComponentCapabilityFlagsType)); 875 } 876 break; 877 case OMX_IndexParamAudioInit: 878 case OMX_IndexParamVideoInit: 879 case OMX_IndexParamImageInit: 880 case OMX_IndexParamOtherInit: 881 { 882 OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure; 883 ret = SEC_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE)); 884 if (ret != OMX_ErrorNone) { 885 goto EXIT; 886 } 887 portParam->nPorts = 0; 888 portParam->nStartPortNumber = 0; 889 } 890 break; 891 case OMX_IndexParamPortDefinition: 892 { 893 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; 894 OMX_U32 portIndex = portDefinition->nPortIndex; 895 SEC_OMX_BASEPORT *pSECPort; 896 897 if (portIndex >= pSECComponent->portParam.nPorts) { 898 ret = OMX_ErrorBadPortIndex; 899 goto EXIT; 900 } 901 ret = SEC_OMX_Check_SizeVersion(portDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 902 if (ret != OMX_ErrorNone) { 903 goto EXIT; 904 } 905 906 pSECPort = &pSECComponent->pSECPort[portIndex]; 907 SEC_OSAL_Memcpy(portDefinition, &pSECPort->portDefinition, portDefinition->nSize); 908 } 909 break; 910 case OMX_IndexParamPriorityMgmt: 911 { 912 OMX_PRIORITYMGMTTYPE *compPriority = (OMX_PRIORITYMGMTTYPE *)ComponentParameterStructure; 913 914 ret = SEC_OMX_Check_SizeVersion(compPriority, sizeof(OMX_PRIORITYMGMTTYPE)); 915 if (ret != OMX_ErrorNone) { 916 goto EXIT; 917 } 918 919 compPriority->nGroupID = pSECComponent->compPriority.nGroupID; 920 compPriority->nGroupPriority = pSECComponent->compPriority.nGroupPriority; 921 } 922 break; 923 924 case OMX_IndexParamCompBufferSupplier: 925 { 926 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure; 927 OMX_U32 portIndex = bufferSupplier->nPortIndex; 928 SEC_OMX_BASEPORT *pSECPort; 929 930 if ((pSECComponent->currentState == OMX_StateLoaded) || 931 (pSECComponent->currentState == OMX_StateWaitForResources)) { 932 if (portIndex >= pSECComponent->portParam.nPorts) { 933 ret = OMX_ErrorBadPortIndex; 934 goto EXIT; 935 } 936 ret = SEC_OMX_Check_SizeVersion(bufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 937 if (ret != OMX_ErrorNone) { 938 goto EXIT; 939 } 940 941 pSECPort = &pSECComponent->pSECPort[portIndex]; 942 943 944 if (pSECPort->portDefinition.eDir == OMX_DirInput) { 945 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 946 bufferSupplier->eBufferSupplier = OMX_BufferSupplyInput; 947 } else if (CHECK_PORT_TUNNELED(pSECPort)) { 948 bufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput; 949 } else { 950 bufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified; 951 } 952 } else { 953 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 954 bufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput; 955 } else if (CHECK_PORT_TUNNELED(pSECPort)) { 956 bufferSupplier->eBufferSupplier = OMX_BufferSupplyInput; 957 } else { 958 bufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified; 959 } 960 } 961 } 962 else 963 { 964 ret = OMX_ErrorIncorrectStateOperation; 965 goto EXIT; 966 } 967 } 968 break; 969 default: 970 { 971 ret = OMX_ErrorUnsupportedIndex; 972 goto EXIT; 973 } 974 break; 975 } 976 977 ret = OMX_ErrorNone; 978 979 EXIT: 980 981 FunctionOut(); 982 983 return ret; 984 } 985 986 OMX_ERRORTYPE SEC_OMX_SetParameter( 987 OMX_IN OMX_HANDLETYPE hComponent, 988 OMX_IN OMX_INDEXTYPE nIndex, 989 OMX_IN OMX_PTR ComponentParameterStructure) 990 { 991 OMX_ERRORTYPE ret = OMX_ErrorNone; 992 OMX_COMPONENTTYPE *pOMXComponent = NULL; 993 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 994 995 FunctionIn(); 996 997 if (hComponent == NULL) { 998 ret = OMX_ErrorBadParameter; 999 goto EXIT; 1000 } 1001 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1002 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1003 if (ret != OMX_ErrorNone) { 1004 goto EXIT; 1005 } 1006 1007 if (pOMXComponent->pComponentPrivate == NULL) { 1008 ret = OMX_ErrorBadParameter; 1009 goto EXIT; 1010 } 1011 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1012 1013 if (ComponentParameterStructure == NULL) { 1014 ret = OMX_ErrorBadParameter; 1015 goto EXIT; 1016 } 1017 if (pSECComponent->currentState == OMX_StateInvalid) { 1018 ret = OMX_ErrorInvalidState; 1019 goto EXIT; 1020 } 1021 1022 switch (nIndex) { 1023 case OMX_IndexParamAudioInit: 1024 case OMX_IndexParamVideoInit: 1025 case OMX_IndexParamImageInit: 1026 case OMX_IndexParamOtherInit: 1027 { 1028 OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure; 1029 ret = SEC_OMX_Check_SizeVersion(portParam, sizeof(OMX_PORT_PARAM_TYPE)); 1030 if (ret != OMX_ErrorNone) { 1031 goto EXIT; 1032 } 1033 1034 if ((pSECComponent->currentState != OMX_StateLoaded) && 1035 (pSECComponent->currentState != OMX_StateWaitForResources)) { 1036 ret = OMX_ErrorIncorrectStateOperation; 1037 goto EXIT; 1038 } 1039 ret = OMX_ErrorUndefined; 1040 /* SEC_OSAL_Memcpy(&pSECComponent->portParam, portParam, sizeof(OMX_PORT_PARAM_TYPE)); */ 1041 } 1042 break; 1043 case OMX_IndexParamPortDefinition: 1044 { 1045 OMX_PARAM_PORTDEFINITIONTYPE *portDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure; 1046 OMX_U32 portIndex = portDefinition->nPortIndex; 1047 SEC_OMX_BASEPORT *pSECPort; 1048 1049 if (portIndex >= pSECComponent->portParam.nPorts) { 1050 ret = OMX_ErrorBadPortIndex; 1051 goto EXIT; 1052 } 1053 ret = SEC_OMX_Check_SizeVersion(portDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 1054 if (ret != OMX_ErrorNone) { 1055 goto EXIT; 1056 } 1057 1058 pSECPort = &pSECComponent->pSECPort[portIndex]; 1059 1060 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 1061 if (pSECPort->portDefinition.bEnabled == OMX_TRUE) { 1062 ret = OMX_ErrorIncorrectStateOperation; 1063 goto EXIT; 1064 } 1065 } 1066 if (portDefinition->nBufferCountActual < pSECPort->portDefinition.nBufferCountMin) { 1067 ret = OMX_ErrorBadParameter; 1068 goto EXIT; 1069 } 1070 1071 SEC_OSAL_Memcpy(&pSECPort->portDefinition, portDefinition, portDefinition->nSize); 1072 } 1073 break; 1074 case OMX_IndexParamPriorityMgmt: 1075 { 1076 OMX_PRIORITYMGMTTYPE *compPriority = (OMX_PRIORITYMGMTTYPE *)ComponentParameterStructure; 1077 1078 if ((pSECComponent->currentState != OMX_StateLoaded) && 1079 (pSECComponent->currentState != OMX_StateWaitForResources)) { 1080 ret = OMX_ErrorIncorrectStateOperation; 1081 goto EXIT; 1082 } 1083 1084 ret = SEC_OMX_Check_SizeVersion(compPriority, sizeof(OMX_PRIORITYMGMTTYPE)); 1085 if (ret != OMX_ErrorNone) { 1086 goto EXIT; 1087 } 1088 1089 pSECComponent->compPriority.nGroupID = compPriority->nGroupID; 1090 pSECComponent->compPriority.nGroupPriority = compPriority->nGroupPriority; 1091 } 1092 break; 1093 case OMX_IndexParamCompBufferSupplier: 1094 { 1095 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure; 1096 OMX_U32 portIndex = bufferSupplier->nPortIndex; 1097 SEC_OMX_BASEPORT *pSECPort; 1098 1099 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 1100 if (pSECPort->portDefinition.bEnabled == OMX_TRUE) { 1101 ret = OMX_ErrorIncorrectStateOperation; 1102 goto EXIT; 1103 } 1104 } 1105 1106 if (portIndex >= pSECComponent->portParam.nPorts) { 1107 ret = OMX_ErrorBadPortIndex; 1108 goto EXIT; 1109 } 1110 ret = SEC_OMX_Check_SizeVersion(bufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 1111 if (ret != OMX_ErrorNone) { 1112 goto EXIT; 1113 } 1114 1115 pSECPort = &pSECComponent->pSECPort[portIndex]; 1116 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyUnspecified) { 1117 ret = OMX_ErrorNone; 1118 goto EXIT; 1119 } 1120 if (CHECK_PORT_TUNNELED(pSECPort) == 0) { 1121 ret = OMX_ErrorNone; /*OMX_ErrorNone ?????*/ 1122 goto EXIT; 1123 } 1124 1125 if (pSECPort->portDefinition.eDir == OMX_DirInput) { 1126 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyInput) { 1127 /* 1128 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1129 ret = OMX_ErrorNone; 1130 } 1131 */ 1132 pSECPort->tunnelFlags |= SEC_TUNNEL_IS_SUPPLIER; 1133 bufferSupplier->nPortIndex = pSECPort->tunneledPort; 1134 ret = OMX_SetParameter(pSECPort->tunneledComponent, OMX_IndexParamCompBufferSupplier, bufferSupplier); 1135 goto EXIT; 1136 } else if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) { 1137 ret = OMX_ErrorNone; 1138 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1139 pSECPort->tunnelFlags &= ~SEC_TUNNEL_IS_SUPPLIER; 1140 bufferSupplier->nPortIndex = pSECPort->tunneledPort; 1141 ret = OMX_SetParameter(pSECPort->tunneledComponent, OMX_IndexParamCompBufferSupplier, bufferSupplier); 1142 } 1143 goto EXIT; 1144 } 1145 } else if (pSECPort->portDefinition.eDir == OMX_DirOutput) { 1146 if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyInput) { 1147 ret = OMX_ErrorNone; 1148 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1149 pSECPort->tunnelFlags &= ~SEC_TUNNEL_IS_SUPPLIER; 1150 ret = OMX_ErrorNone; 1151 } 1152 goto EXIT; 1153 } else if (bufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) { 1154 /* 1155 if (CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) { 1156 ret = OMX_ErrorNone; 1157 } 1158 */ 1159 pSECPort->tunnelFlags |= SEC_TUNNEL_IS_SUPPLIER; 1160 ret = OMX_ErrorNone; 1161 goto EXIT; 1162 } 1163 } 1164 } 1165 break; 1166 default: 1167 { 1168 ret = OMX_ErrorUnsupportedIndex; 1169 goto EXIT; 1170 } 1171 break; 1172 } 1173 1174 ret = OMX_ErrorNone; 1175 1176 EXIT: 1177 1178 FunctionOut(); 1179 1180 return ret; 1181 } 1182 1183 OMX_ERRORTYPE SEC_OMX_GetConfig( 1184 OMX_IN OMX_HANDLETYPE hComponent, 1185 OMX_IN OMX_INDEXTYPE nIndex, 1186 OMX_INOUT OMX_PTR pComponentConfigStructure) 1187 { 1188 OMX_ERRORTYPE ret = OMX_ErrorNone; 1189 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1190 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1191 1192 FunctionIn(); 1193 1194 if (hComponent == NULL) { 1195 ret = OMX_ErrorBadParameter; 1196 goto EXIT; 1197 } 1198 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1199 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1200 if (ret != OMX_ErrorNone) { 1201 goto EXIT; 1202 } 1203 1204 if (pOMXComponent->pComponentPrivate == NULL) { 1205 ret = OMX_ErrorBadParameter; 1206 goto EXIT; 1207 } 1208 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1209 1210 if (pComponentConfigStructure == NULL) { 1211 ret = OMX_ErrorBadParameter; 1212 goto EXIT; 1213 } 1214 if (pSECComponent->currentState == OMX_StateInvalid) { 1215 ret = OMX_ErrorInvalidState; 1216 goto EXIT; 1217 } 1218 ret = OMX_ErrorNone; 1219 1220 EXIT: 1221 FunctionOut(); 1222 1223 return ret; 1224 } 1225 1226 OMX_ERRORTYPE SEC_OMX_SetConfig( 1227 OMX_IN OMX_HANDLETYPE hComponent, 1228 OMX_IN OMX_INDEXTYPE nIndex, 1229 OMX_IN OMX_PTR pComponentConfigStructure) 1230 { 1231 OMX_ERRORTYPE ret = OMX_ErrorNone; 1232 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1233 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1234 1235 FunctionIn(); 1236 1237 if (hComponent == NULL) { 1238 ret = OMX_ErrorBadParameter; 1239 goto EXIT; 1240 } 1241 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1242 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1243 if (ret != OMX_ErrorNone) { 1244 goto EXIT; 1245 } 1246 1247 if (pOMXComponent->pComponentPrivate == NULL) { 1248 ret = OMX_ErrorBadParameter; 1249 goto EXIT; 1250 } 1251 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1252 1253 if (pComponentConfigStructure == NULL) { 1254 ret = OMX_ErrorBadParameter; 1255 goto EXIT; 1256 } 1257 if (pSECComponent->currentState == OMX_StateInvalid) { 1258 ret = OMX_ErrorInvalidState; 1259 goto EXIT; 1260 } 1261 ret = OMX_ErrorNone; 1262 1263 EXIT: 1264 FunctionOut(); 1265 1266 return ret; 1267 } 1268 1269 OMX_ERRORTYPE SEC_OMX_GetExtensionIndex( 1270 OMX_IN OMX_HANDLETYPE hComponent, 1271 OMX_IN OMX_STRING cParameterName, 1272 OMX_OUT OMX_INDEXTYPE *pIndexType) 1273 { 1274 OMX_ERRORTYPE ret = OMX_ErrorNone; 1275 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1276 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1277 1278 FunctionIn(); 1279 1280 if (hComponent == NULL) { 1281 ret = OMX_ErrorBadParameter; 1282 goto EXIT; 1283 } 1284 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1285 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1286 if (ret != OMX_ErrorNone) { 1287 goto EXIT; 1288 } 1289 1290 if (pOMXComponent->pComponentPrivate == NULL) { 1291 ret = OMX_ErrorBadParameter; 1292 goto EXIT; 1293 } 1294 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1295 1296 if ((cParameterName == NULL) || (pIndexType == NULL)) { 1297 ret = OMX_ErrorBadParameter; 1298 goto EXIT; 1299 } 1300 if (pSECComponent->currentState == OMX_StateInvalid) { 1301 ret = OMX_ErrorInvalidState; 1302 goto EXIT; 1303 } 1304 1305 ret = OMX_ErrorBadParameter; 1306 1307 EXIT: 1308 FunctionOut(); 1309 1310 return ret; 1311 } 1312 1313 OMX_ERRORTYPE SEC_OMX_SetCallbacks ( 1314 OMX_IN OMX_HANDLETYPE hComponent, 1315 OMX_IN OMX_CALLBACKTYPE* pCallbacks, 1316 OMX_IN OMX_PTR pAppData) 1317 { 1318 OMX_ERRORTYPE ret = OMX_ErrorNone; 1319 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1320 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1321 1322 FunctionIn(); 1323 1324 if (hComponent == NULL) { 1325 ret = OMX_ErrorBadParameter; 1326 goto EXIT; 1327 } 1328 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1329 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1330 if (ret != OMX_ErrorNone) { 1331 goto EXIT; 1332 } 1333 1334 if (pOMXComponent->pComponentPrivate == NULL) { 1335 ret = OMX_ErrorBadParameter; 1336 goto EXIT; 1337 } 1338 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1339 1340 if (pCallbacks == NULL) { 1341 ret = OMX_ErrorBadParameter; 1342 goto EXIT; 1343 } 1344 if (pSECComponent->currentState == OMX_StateInvalid) { 1345 ret = OMX_ErrorInvalidState; 1346 goto EXIT; 1347 } 1348 if (pSECComponent->currentState != OMX_StateLoaded) { 1349 ret = OMX_ErrorIncorrectStateOperation; 1350 goto EXIT; 1351 } 1352 1353 pSECComponent->pCallbacks = pCallbacks; 1354 pSECComponent->callbackData = pAppData; 1355 1356 ret = OMX_ErrorNone; 1357 1358 EXIT: 1359 FunctionOut(); 1360 1361 return ret; 1362 } 1363 1364 OMX_ERRORTYPE SEC_OMX_UseEGLImage( 1365 OMX_IN OMX_HANDLETYPE hComponent, 1366 OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr, 1367 OMX_IN OMX_U32 nPortIndex, 1368 OMX_IN OMX_PTR pAppPrivate, 1369 OMX_IN void *eglImage) 1370 { 1371 return OMX_ErrorNotImplemented; 1372 } 1373 1374 OMX_ERRORTYPE SEC_OMX_BaseComponent_Constructor( 1375 OMX_IN OMX_HANDLETYPE hComponent) 1376 { 1377 OMX_ERRORTYPE ret = OMX_ErrorNone; 1378 OMX_COMPONENTTYPE *pOMXComponent; 1379 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1380 1381 FunctionIn(); 1382 1383 if (hComponent == NULL) { 1384 ret = OMX_ErrorBadParameter; 1385 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__); 1386 goto EXIT; 1387 } 1388 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1389 pSECComponent = SEC_OSAL_Malloc(sizeof(SEC_OMX_BASECOMPONENT)); 1390 if (pSECComponent == NULL) { 1391 ret = OMX_ErrorInsufficientResources; 1392 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1393 goto EXIT; 1394 } 1395 SEC_OSAL_Memset(pSECComponent, 0, sizeof(SEC_OMX_BASECOMPONENT)); 1396 pOMXComponent->pComponentPrivate = (OMX_PTR)pSECComponent; 1397 1398 ret = SEC_OSAL_SemaphoreCreate(&pSECComponent->msgSemaphoreHandle); 1399 if (ret != OMX_ErrorNone) { 1400 ret = OMX_ErrorInsufficientResources; 1401 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1402 goto EXIT; 1403 } 1404 ret = SEC_OSAL_MutexCreate(&pSECComponent->compMutex); 1405 if (ret != OMX_ErrorNone) { 1406 ret = OMX_ErrorInsufficientResources; 1407 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1408 goto EXIT; 1409 } 1410 1411 pSECComponent->bExitMessageHandlerThread = OMX_FALSE; 1412 SEC_OSAL_QueueCreate(&pSECComponent->messageQ); 1413 ret = SEC_OSAL_ThreadCreate(&pSECComponent->hMessageHandler, SEC_OMX_MessageHandlerThread, pOMXComponent); 1414 if (ret != OMX_ErrorNone) { 1415 ret = OMX_ErrorInsufficientResources; 1416 SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__); 1417 goto EXIT; 1418 } 1419 1420 pOMXComponent->GetComponentVersion = &SEC_OMX_GetComponentVersion; 1421 pOMXComponent->SendCommand = &SEC_OMX_SendCommand; 1422 pOMXComponent->GetConfig = &SEC_OMX_GetConfig; 1423 pOMXComponent->GetExtensionIndex = &SEC_OMX_GetExtensionIndex; 1424 pOMXComponent->GetState = &SEC_OMX_GetState; 1425 pOMXComponent->SetCallbacks = &SEC_OMX_SetCallbacks; 1426 pOMXComponent->UseEGLImage = &SEC_OMX_UseEGLImage; 1427 1428 EXIT: 1429 FunctionOut(); 1430 1431 return ret; 1432 } 1433 1434 OMX_ERRORTYPE SEC_OMX_BaseComponent_Destructor( 1435 OMX_IN OMX_HANDLETYPE hComponent) 1436 { 1437 OMX_ERRORTYPE ret = OMX_ErrorNone; 1438 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1439 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1440 OMX_U32 semaValue = 0; 1441 1442 FunctionIn(); 1443 1444 if (hComponent == NULL) { 1445 ret = OMX_ErrorBadParameter; 1446 goto EXIT; 1447 } 1448 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1449 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 1450 if (ret != OMX_ErrorNone) { 1451 goto EXIT; 1452 } 1453 1454 if (pOMXComponent->pComponentPrivate == NULL) { 1455 ret = OMX_ErrorBadParameter; 1456 goto EXIT; 1457 } 1458 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1459 1460 SEC_OMX_CommandQueue(pSECComponent, SEC_OMX_CommandComponentDeInit, 0, NULL); 1461 SEC_OSAL_SleepMillisec(0); 1462 SEC_OSAL_Get_SemaphoreCount(pSECComponent->msgSemaphoreHandle, &semaValue); 1463 if (semaValue == 0) 1464 SEC_OSAL_SemaphorePost(pSECComponent->msgSemaphoreHandle); 1465 SEC_OSAL_SemaphorePost(pSECComponent->msgSemaphoreHandle); 1466 1467 SEC_OSAL_ThreadTerminate(pSECComponent->hMessageHandler); 1468 pSECComponent->hMessageHandler = NULL; 1469 1470 SEC_OSAL_MutexTerminate(pSECComponent->compMutex); 1471 pSECComponent->compMutex = NULL; 1472 SEC_OSAL_SemaphoreTerminate(pSECComponent->msgSemaphoreHandle); 1473 pSECComponent->msgSemaphoreHandle = NULL; 1474 SEC_OSAL_QueueTerminate(&pSECComponent->messageQ); 1475 1476 SEC_OSAL_Free(pSECComponent); 1477 pSECComponent = NULL; 1478 1479 ret = OMX_ErrorNone; 1480 EXIT: 1481 FunctionOut(); 1482 1483 return ret; 1484 } 1485 1486 1487