OMX_ERRORTYPE SEC_OMX_BaseComponent_Constructor(
    OMX_IN OMX_HANDLETYPE hComponent)
{
    OMX_ERRORTYPE          ret = OMX_ErrorNone;
    OMX_COMPONENTTYPE     *pOMXComponent;
    SEC_OMX_BASECOMPONENT *pSECComponent = NULL;

    FunctionIn();

    if (hComponent == NULL) {
        ret = OMX_ErrorBadParameter;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
        goto EXIT;
    }
    pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    pSECComponent = SEC_OSAL_Malloc(sizeof(SEC_OMX_BASECOMPONENT));
    if (pSECComponent == NULL) {
        ret = OMX_ErrorInsufficientResources;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
        goto EXIT;
    }
    SEC_OSAL_Memset(pSECComponent, 0, sizeof(SEC_OMX_BASECOMPONENT));
    pOMXComponent->pComponentPrivate = (OMX_PTR)pSECComponent;

    ret = SEC_OSAL_SemaphoreCreate(&pSECComponent->msgSemaphoreHandle);
    if (ret != OMX_ErrorNone) {
        ret = OMX_ErrorInsufficientResources;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
        goto EXIT;
    }
    ret = SEC_OSAL_MutexCreate(&pSECComponent->compMutex);
    if (ret != OMX_ErrorNone) {
        ret = OMX_ErrorInsufficientResources;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
        goto EXIT;
    }

    pSECComponent->bExitMessageHandlerThread = OMX_FALSE;
    SEC_OSAL_QueueCreate(&pSECComponent->messageQ);
    ret = SEC_OSAL_ThreadCreate(&pSECComponent->hMessageHandler, SEC_OMX_MessageHandlerThread, pOMXComponent);
    if (ret != OMX_ErrorNone) {
        ret = OMX_ErrorInsufficientResources;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
        goto EXIT;
    }

    pOMXComponent->GetComponentVersion = &SEC_OMX_GetComponentVersion;
    pOMXComponent->SendCommand         = &SEC_OMX_SendCommand;
    pOMXComponent->GetConfig           = &SEC_OMX_GetConfig;
    pOMXComponent->GetExtensionIndex   = &SEC_OMX_GetExtensionIndex;
    pOMXComponent->GetState            = &SEC_OMX_GetState;
    pOMXComponent->SetCallbacks        = &SEC_OMX_SetCallbacks;
    pOMXComponent->UseEGLImage         = &SEC_OMX_UseEGLImage;

EXIT:
    FunctionOut();

    return ret;
}
OMX_ERRORTYPE SEC_OMX_ComponentStateSet(OMX_COMPONENTTYPE *pOMXComponent, OMX_U32 messageParam)
{
    OMX_ERRORTYPE          ret = OMX_ErrorNone;
    SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    SEC_OMX_MESSAGE       *message;
    OMX_STATETYPE          destState = messageParam;
    OMX_STATETYPE          currentState = pSECComponent->currentState;
    SEC_OMX_BASEPORT      *pSECPort = NULL;
    OMX_S32                countValue = 0;
    int                   i = 0, j = 0;

    FunctionIn();

    /* check parameters */
    if (currentState == destState) {
         ret = OMX_ErrorSameState;
            goto EXIT;
    }
    if (currentState == OMX_StateInvalid) {
        ret = OMX_ErrorInvalidState;
        goto EXIT;
    }

    if ((currentState == OMX_StateLoaded) && (destState == OMX_StateIdle)) {
        ret = SEC_OMX_Get_Resource(pOMXComponent);
        if (ret != OMX_ErrorNone) {
            goto EXIT;
        }
    }
    if (((currentState == OMX_StateIdle) && (destState == OMX_StateLoaded))       ||
        ((currentState == OMX_StateIdle) && (destState == OMX_StateInvalid))      ||
        ((currentState == OMX_StateExecuting) && (destState == OMX_StateInvalid)) ||
        ((currentState == OMX_StatePause) && (destState == OMX_StateInvalid))) {
        SEC_OMX_Release_Resource(pOMXComponent);
    }

    SEC_OSAL_Log(SEC_LOG_TRACE, "destState: %d", destState);

    switch (destState) {
    case OMX_StateInvalid:
        switch (currentState) {
        case OMX_StateIdle:
        case OMX_StateExecuting:
        case OMX_StatePause:
        case OMX_StateLoaded:
        case OMX_StateWaitForResources:
            pSECComponent->currentState = OMX_StateInvalid;
            if (pSECComponent->hBufferProcess) {
                pSECComponent->bExitBufferProcessThread = OMX_TRUE;

                for (i = 0; i < ALL_PORT_NUM; i++) {
                    SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[i].bufferSemID, &countValue);
                    if (countValue == 0)
                        SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID);
                }

                SEC_OSAL_SignalSet(pSECComponent->pauseEvent);
                SEC_OSAL_ThreadTerminate(pSECComponent->hBufferProcess);
                pSECComponent->hBufferProcess = NULL;

                for (i = 0; i < ALL_PORT_NUM; i++) {
                    SEC_OSAL_MutexTerminate(pSECComponent->secDataBuffer[i].bufferMutex);
                    pSECComponent->secDataBuffer[i].bufferMutex = NULL;
                }

                SEC_OSAL_SignalTerminate(pSECComponent->pauseEvent);
                for (i = 0; i < ALL_PORT_NUM; i++) {
                    SEC_OSAL_SemaphoreTerminate(pSECComponent->pSECPort[i].bufferSemID);
                    pSECComponent->pSECPort[i].bufferSemID = NULL;
                }
            }
            if (pSECComponent->sec_mfc_componentTerminate != NULL)
                pSECComponent->sec_mfc_componentTerminate(pOMXComponent);
            break;
        }
        ret = OMX_ErrorInvalidState;
        break;
    case OMX_StateLoaded:
        switch (currentState) {
        case OMX_StateIdle:
            pSECComponent->bExitBufferProcessThread = OMX_TRUE;

            for (i = 0; i < ALL_PORT_NUM; i++) {
                SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[i].bufferSemID, &countValue);
                if (countValue == 0)
                    SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID);
            }

            SEC_OSAL_SignalSet(pSECComponent->pauseEvent);
            SEC_OSAL_ThreadTerminate(pSECComponent->hBufferProcess);
            pSECComponent->hBufferProcess = NULL;

            for (i = 0; i < ALL_PORT_NUM; i++) {
                SEC_OSAL_MutexTerminate(pSECComponent->secDataBuffer[i].bufferMutex);
                pSECComponent->secDataBuffer[i].bufferMutex = NULL;
            }

            SEC_OSAL_SignalTerminate(pSECComponent->pauseEvent);
            for (i = 0; i < ALL_PORT_NUM; i++) {
                SEC_OSAL_SemaphoreTerminate(pSECComponent->pSECPort[i].bufferSemID);
                pSECComponent->pSECPort[i].bufferSemID = NULL;
            }

            pSECComponent->sec_mfc_componentTerminate(pOMXComponent);

            for (i = 0; i < (pSECComponent->portParam.nPorts); i++) {
                pSECPort = (pSECComponent->pSECPort + i);
                if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
                    while (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) > 0) {
                        message = (SEC_OMX_MESSAGE*)SEC_OSAL_Dequeue(&pSECPort->bufferQ);
                        if (message != NULL)
                            SEC_OSAL_Free(message);
                    }
                    ret = pSECComponent->sec_FreeTunnelBuffer(pSECComponent, i);
                    if (OMX_ErrorNone != ret) {
                        goto EXIT;
                    }
                } else {
                    if (CHECK_PORT_ENABLED(pSECPort)) {
                        SEC_OSAL_SemaphoreWait(pSECPort->unloadedResource);
                        pSECPort->portDefinition.bPopulated = OMX_FALSE;
                    }
                }
            }
            pSECComponent->currentState = OMX_StateLoaded;
            break;
        case OMX_StateWaitForResources:
            ret = SEC_OMX_Out_WaitForResource(pOMXComponent);
            pSECComponent->currentState = OMX_StateLoaded;
            break;
        case OMX_StateExecuting:
        case OMX_StatePause:
        default:
            ret = OMX_ErrorIncorrectStateTransition;
            break;
        }
        break;
    case OMX_StateIdle:
        switch (currentState) {
        case OMX_StateLoaded:
            for (i = 0; i < pSECComponent->portParam.nPorts; i++) {
                pSECPort = (pSECComponent->pSECPort + i);
                if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort)) {
                    if (CHECK_PORT_ENABLED(pSECPort)) {
                        ret = pSECComponent->sec_AllocateTunnelBuffer(pSECPort, i);
                        if (ret!=OMX_ErrorNone)
                            goto EXIT;
                    }
                } else {
                    if (CHECK_PORT_ENABLED(pSECPort)) {
                        SEC_OSAL_SemaphoreWait(pSECComponent->pSECPort[i].loadedResource);
                        pSECPort->portDefinition.bPopulated = OMX_TRUE;
                    }
                }
            }
            ret = pSECComponent->sec_mfc_componentInit(pOMXComponent);
            if (ret != OMX_ErrorNone) {
                /*
                 * if (CHECK_PORT_TUNNELED == OMX_TRUE) thenTunnel Buffer Free
                 */
                goto EXIT;
            }
            pSECComponent->bExitBufferProcessThread = OMX_FALSE;
            SEC_OSAL_SignalCreate(&pSECComponent->pauseEvent);
            for (i = 0; i < ALL_PORT_NUM; i++) {
                SEC_OSAL_SemaphoreCreate(&pSECComponent->pSECPort[i].bufferSemID);
            }
            for (i = 0; i < ALL_PORT_NUM; i++) {
                SEC_OSAL_MutexCreate(&pSECComponent->secDataBuffer[i].bufferMutex);
            }
            ret = SEC_OSAL_ThreadCreate(&pSECComponent->hBufferProcess,
                             SEC_OMX_BufferProcessThread,
                             pOMXComponent);
            if (ret != OMX_ErrorNone) {
                /*
                 * if (CHECK_PORT_TUNNELED == OMX_TRUE) thenTunnel Buffer Free
                 */

                SEC_OSAL_SignalTerminate(pSECComponent->pauseEvent);
                for (i = 0; i < ALL_PORT_NUM; i++) {
                    SEC_OSAL_MutexTerminate(pSECComponent->secDataBuffer[i].bufferMutex);
                    pSECComponent->secDataBuffer[i].bufferMutex = NULL;
                }
                for (i = 0; i < ALL_PORT_NUM; i++) {
                    SEC_OSAL_SemaphoreTerminate(pSECComponent->pSECPort[i].bufferSemID);
                    pSECComponent->pSECPort[i].bufferSemID = NULL;
                }

                ret = OMX_ErrorInsufficientResources;
                goto EXIT;
            }
            pSECComponent->currentState = OMX_StateIdle;
            break;
        case OMX_StateExecuting:
        case OMX_StatePause:
            SEC_OMX_BufferFlushProcessNoEvent(pOMXComponent, ALL_PORT_INDEX);
            pSECComponent->currentState = OMX_StateIdle;
            break;
        case OMX_StateWaitForResources:
            pSECComponent->currentState = OMX_StateIdle;
            break;
        }
        break;
    case OMX_StateExecuting:
        switch (currentState) {
        case OMX_StateLoaded:
            ret = OMX_ErrorIncorrectStateTransition;
            break;
        case OMX_StateIdle:
            for (i = 0; i < pSECComponent->portParam.nPorts; i++) {
                pSECPort = &pSECComponent->pSECPort[i];
                if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort) && CHECK_PORT_ENABLED(pSECPort)) {
                    for (j = 0; j < pSECPort->tunnelBufferNum; j++) {
                        SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID);
                    }
                }
            }

            pSECComponent->transientState = SEC_OMX_TransStateMax;
            pSECComponent->currentState = OMX_StateExecuting;
            SEC_OSAL_SignalSet(pSECComponent->pauseEvent);
            break;
        case OMX_StatePause:
            for (i = 0; i < pSECComponent->portParam.nPorts; i++) {
                pSECPort = &pSECComponent->pSECPort[i];
                if (CHECK_PORT_TUNNELED(pSECPort) && CHECK_PORT_BUFFER_SUPPLIER(pSECPort) && CHECK_PORT_ENABLED(pSECPort)) {
                    OMX_U32 semaValue = 0, cnt = 0;
                    SEC_OSAL_Get_SemaphoreCount(pSECComponent->pSECPort[i].bufferSemID, &semaValue);
                    if (SEC_OSAL_GetElemNum(&pSECPort->bufferQ) > semaValue) {
                        cnt = SEC_OSAL_GetElemNum(&pSECPort->bufferQ) - semaValue;
                        for (j = 0; j < cnt; j++) {
                            SEC_OSAL_SemaphorePost(pSECComponent->pSECPort[i].bufferSemID);
                        }
                    }
                }
            }

            pSECComponent->currentState = OMX_StateExecuting;
            SEC_OSAL_SignalSet(pSECComponent->pauseEvent);
            break;
        case OMX_StateWaitForResources:
            ret = OMX_ErrorIncorrectStateTransition;
            break;
        }
        break;
    case OMX_StatePause:
        switch (currentState) {
        case OMX_StateLoaded:
            ret = OMX_ErrorIncorrectStateTransition;
            break;
        case OMX_StateIdle:
            pSECComponent->currentState = OMX_StatePause;
            break;
        case OMX_StateExecuting:
            pSECComponent->currentState = OMX_StatePause;
            break;
        case OMX_StateWaitForResources:
            ret = OMX_ErrorIncorrectStateTransition;
            break;
        }
        break;
    case OMX_StateWaitForResources:
        switch (currentState) {
        case OMX_StateLoaded:
            ret = SEC_OMX_In_WaitForResource(pOMXComponent);
            pSECComponent->currentState = OMX_StateWaitForResources;
            break;
        case OMX_StateIdle:
        case OMX_StateExecuting:
        case OMX_StatePause:
            ret = OMX_ErrorIncorrectStateTransition;
            break;
        }
        break;
    }

EXIT:
    if (ret == OMX_ErrorNone) {
        if (pSECComponent->pCallbacks != NULL) {
            pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
            pSECComponent->callbackData,
            OMX_EventCmdComplete, OMX_CommandStateSet,
            destState, NULL);
        }
    } else {
        if (pSECComponent->pCallbacks != NULL) {
            pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent,
            pSECComponent->callbackData,
            OMX_EventError, ret, 0, NULL);
        }
    }
    FunctionOut();

    return ret;
}
OMX_ERRORTYPE SEC_OMX_Port_Constructor(OMX_HANDLETYPE hComponent)
{
    OMX_ERRORTYPE          ret = OMX_ErrorNone;
    OMX_COMPONENTTYPE     *pOMXComponent = NULL;
    SEC_OMX_BASECOMPONENT *pSECComponent = NULL;
    SEC_OMX_BASEPORT      *pSECPort = NULL;
    SEC_OMX_BASEPORT      *pSECInputPort = NULL;
    SEC_OMX_BASEPORT      *pSECOutputPort = NULL;
    int i = 0;

    FunctionIn();

    if (hComponent == NULL) {
        ret = OMX_ErrorBadParameter;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
        goto EXIT;
    }
    pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
    ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE));
    if (ret != OMX_ErrorNone) {
        goto EXIT;
    }

    if (pOMXComponent->pComponentPrivate == NULL) {
        ret = OMX_ErrorBadParameter;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorBadParameter, Line:%d", __LINE__);
        goto EXIT;
    }
    pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;

    INIT_SET_SIZE_VERSION(&pSECComponent->portParam, OMX_PORT_PARAM_TYPE);
    pSECComponent->portParam.nPorts = ALL_PORT_NUM;
    pSECComponent->portParam.nStartPortNumber = INPUT_PORT_INDEX;

    pSECPort = SEC_OSAL_Malloc(sizeof(SEC_OMX_BASEPORT) * ALL_PORT_NUM);
    if (pSECPort == NULL) {
        ret = OMX_ErrorInsufficientResources;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
        goto EXIT;
    }
    SEC_OSAL_Memset(pSECPort, 0, sizeof(SEC_OMX_BASEPORT) * ALL_PORT_NUM);
    pSECComponent->pSECPort = pSECPort;

    /* Input Port */
    pSECInputPort = &pSECPort[INPUT_PORT_INDEX];

    SEC_OSAL_QueueCreate(&pSECInputPort->bufferQ);

    pSECInputPort->bufferHeader = SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);
    if (pSECInputPort->bufferHeader == NULL) {
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        ret = OMX_ErrorInsufficientResources;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
        goto EXIT;
    }
    SEC_OSAL_Memset(pSECInputPort->bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);

    pSECInputPort->bufferStateAllocate = SEC_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
    if (pSECInputPort->bufferStateAllocate == NULL) {
        SEC_OSAL_Free(pSECInputPort->bufferHeader);
        pSECInputPort->bufferHeader = NULL;
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        ret = OMX_ErrorInsufficientResources;
        SEC_OSAL_Log(SEC_LOG_ERROR, "OMX_ErrorInsufficientResources, Line:%d", __LINE__);
        goto EXIT;
    }
    SEC_OSAL_Memset(pSECInputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);

    pSECInputPort->bufferSemID = NULL;
    pSECInputPort->assignedBufferNum = 0;
    pSECInputPort->portState = OMX_StateMax;
    pSECInputPort->bIsPortFlushed = OMX_FALSE;
    pSECInputPort->bIsPortDisabled = OMX_FALSE;
    pSECInputPort->tunneledComponent = NULL;
    pSECInputPort->tunneledPort = 0;
    pSECInputPort->tunnelBufferNum = 0;
    pSECInputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
    pSECInputPort->tunnelFlags = 0;
    pSECInputPort->eControlRate = OMX_Video_ControlRateDisable;
    ret = SEC_OSAL_SemaphoreCreate(&pSECInputPort->loadedResource);
    if (ret != OMX_ErrorNone) {
        SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
        pSECInputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferHeader);
        pSECInputPort->bufferHeader = NULL;
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        goto EXIT;
    }
    ret = SEC_OSAL_SemaphoreCreate(&pSECInputPort->unloadedResource);
    if (ret != OMX_ErrorNone) {
        SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
        pSECInputPort->loadedResource = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
        pSECInputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferHeader);
        pSECInputPort->bufferHeader = NULL;
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        goto EXIT;
    }

    INIT_SET_SIZE_VERSION(&pSECInputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
    pSECInputPort->portDefinition.nPortIndex = INPUT_PORT_INDEX;
    pSECInputPort->portDefinition.eDir = OMX_DirInput;
    pSECInputPort->portDefinition.nBufferCountActual = 0;
    pSECInputPort->portDefinition.nBufferCountMin = 0;
    pSECInputPort->portDefinition.nBufferSize = 0;
    pSECInputPort->portDefinition.bEnabled = OMX_FALSE;
    pSECInputPort->portDefinition.bPopulated = OMX_FALSE;
    pSECInputPort->portDefinition.eDomain = OMX_PortDomainMax;
    pSECInputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
    pSECInputPort->portDefinition.nBufferAlignment = 0;
    pSECInputPort->markType.hMarkTargetComponent = NULL;
    pSECInputPort->markType.pMarkData = NULL;

    /* Output Port */
    pSECOutputPort = &pSECPort[OUTPUT_PORT_INDEX];

    SEC_OSAL_QueueCreate(&pSECOutputPort->bufferQ);

    pSECOutputPort->bufferHeader = SEC_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);
    if (pSECOutputPort->bufferHeader == NULL) {
        SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
        pSECInputPort->unloadedResource = NULL;
        SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
        pSECInputPort->loadedResource = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
        pSECInputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferHeader);
        pSECInputPort->bufferHeader = NULL;
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        ret = OMX_ErrorInsufficientResources;
        goto EXIT;
    }
    SEC_OSAL_Memset(pSECOutputPort->bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE*) * MAX_BUFFER_NUM);

    pSECOutputPort->bufferStateAllocate = SEC_OSAL_Malloc(sizeof(OMX_U32) * MAX_BUFFER_NUM);
    if (pSECOutputPort->bufferStateAllocate == NULL) {
        SEC_OSAL_Free(pSECOutputPort->bufferHeader);
        pSECOutputPort->bufferHeader = NULL;

        SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
        pSECInputPort->unloadedResource = NULL;
        SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
        pSECInputPort->loadedResource = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
        pSECInputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferHeader);
        pSECInputPort->bufferHeader = NULL;
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        ret = OMX_ErrorInsufficientResources;
        goto EXIT;
    }
    SEC_OSAL_Memset(pSECOutputPort->bufferStateAllocate, 0, sizeof(OMX_U32) * MAX_BUFFER_NUM);

    pSECOutputPort->bufferSemID = NULL;
    pSECOutputPort->assignedBufferNum = 0;
    pSECOutputPort->portState = OMX_StateMax;
    pSECOutputPort->bIsPortFlushed = OMX_FALSE;
    pSECOutputPort->bIsPortDisabled = OMX_FALSE;
    pSECOutputPort->tunneledComponent = NULL;
    pSECOutputPort->tunneledPort = 0;
    pSECOutputPort->tunnelBufferNum = 0;
    pSECOutputPort->bufferSupplier = OMX_BufferSupplyUnspecified;
    pSECOutputPort->tunnelFlags = 0;
    pSECOutputPort->eControlRate = OMX_Video_ControlRateDisable;
    ret = SEC_OSAL_SemaphoreCreate(&pSECOutputPort->loadedResource);
    if (ret != OMX_ErrorNone) {
        SEC_OSAL_Free(pSECOutputPort->bufferStateAllocate);
        pSECOutputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECOutputPort->bufferHeader);
        pSECOutputPort->bufferHeader = NULL;

        SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
        pSECInputPort->unloadedResource = NULL;
        SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
        pSECInputPort->loadedResource = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
        pSECInputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferHeader);
        pSECInputPort->bufferHeader = NULL;
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        goto EXIT;
    }
    ret = SEC_OSAL_SemaphoreCreate(&pSECOutputPort->unloadedResource);
    if (ret != OMX_ErrorNone) {
        SEC_OSAL_SemaphoreTerminate(pSECOutputPort->loadedResource);
        pSECOutputPort->loadedResource = NULL;
        SEC_OSAL_Free(pSECOutputPort->bufferStateAllocate);
        pSECOutputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECOutputPort->bufferHeader);
        pSECOutputPort->bufferHeader = NULL;

        SEC_OSAL_SemaphoreTerminate(pSECInputPort->unloadedResource);
        pSECInputPort->unloadedResource = NULL;
        SEC_OSAL_SemaphoreTerminate(pSECInputPort->loadedResource);
        pSECInputPort->loadedResource = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferStateAllocate);
        pSECInputPort->bufferStateAllocate = NULL;
        SEC_OSAL_Free(pSECInputPort->bufferHeader);
        pSECInputPort->bufferHeader = NULL;
        SEC_OSAL_Free(pSECPort);
        pSECPort = NULL;
        goto EXIT;
    }

    INIT_SET_SIZE_VERSION(&pSECOutputPort->portDefinition, OMX_PARAM_PORTDEFINITIONTYPE);
    pSECOutputPort->portDefinition.nPortIndex = OUTPUT_PORT_INDEX;
    pSECOutputPort->portDefinition.eDir = OMX_DirOutput;
    pSECOutputPort->portDefinition.nBufferCountActual = 0;
    pSECOutputPort->portDefinition.nBufferCountMin = 0;
    pSECOutputPort->portDefinition.nBufferSize = 0;
    pSECOutputPort->portDefinition.bEnabled = OMX_FALSE;
    pSECOutputPort->portDefinition.bPopulated = OMX_FALSE;
    pSECOutputPort->portDefinition.eDomain = OMX_PortDomainMax;
    pSECOutputPort->portDefinition.bBuffersContiguous = OMX_FALSE;
    pSECOutputPort->portDefinition.nBufferAlignment = 0;
    pSECOutputPort->markType.hMarkTargetComponent = NULL;
    pSECOutputPort->markType.pMarkData = NULL;

    pSECComponent->checkTimeStamp.needSetStartTimeStamp = OMX_TRUE;
    pSECComponent->checkTimeStamp.needCheckStartTimeStamp = OMX_FALSE;
    pSECComponent->checkTimeStamp.startTimeStamp  = 0;
    pSECComponent->checkTimeStamp.nStartFlags = 0x0;

    pOMXComponent->EmptyThisBuffer = &SEC_OMX_EmptyThisBuffer;
    pOMXComponent->FillThisBuffer  = &SEC_OMX_FillThisBuffer;

    ret = OMX_ErrorNone;
EXIT:
    FunctionOut();

    return ret;
}