OMX_ERRORTYPE PortCommTest_EventHandler(OMX_IN OMX_HANDLETYPE hComponent,
                                            OMX_IN OMX_PTR pAppData,
                                            OMX_IN OMX_EVENTTYPE eEvent,
                                            OMX_IN OMX_U32 nData1,
                                            OMX_IN OMX_U32 nData2,
                                            OMX_IN OMX_PTR pEventData)
    {
        PortCommTestCtxt* pContext;

        UNUSED_PARAMETER(hComponent);
        UNUSED_PARAMETER(pEventData);

        if (pAppData == NULL)
            return OMX_ErrorNone;
        pContext = (PortCommTestCtxt*)pAppData;

        if (eEvent == OMX_EventCmdComplete)
        {
            switch ((OMX_COMMANDTYPE)(nData1))
            {
                case OMX_CommandStateSet:
                    OMX_CONF_StateToString((OMX_STATETYPE)(nData2), szDesc);
                    OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Component transitioned to %s\n", szDesc);
                    pContext->eState = (OMX_STATETYPE)(nData2);
                    OMX_OSAL_EventSet(pContext->hStateSetEvent);
                    break;
                case OMX_CommandPortDisable:
                    pContext->nPortsStopped++;
                    if (pContext->nPortsStopped == pContext->nPorts)
                    {
                        OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "All ports completed stopping\n");
                        OMX_OSAL_EventSet(pContext->hPortDisableEvent);
                    }
                    break;
                case OMX_CommandPortEnable:
                    pContext->nPortsRestarted++;
                    if (pContext->nPortsRestarted == pContext->nPorts)
                    {
                        OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "All ports restarted\n");
                        OMX_OSAL_EventSet(pContext->hPortEnableEvent);
                    }
                    break;
                case OMX_EventBufferFlag:
                    break;
                default:
                    break;
            }
        }
        return OMX_ErrorNone;
    }
    /* Handle Events */
    OMX_ERRORTYPE WaitResEventHandler(
        OMX_IN OMX_HANDLETYPE hComponent,
        OMX_IN OMX_PTR pAppData,
        OMX_IN OMX_EVENTTYPE eEvent,
        OMX_IN OMX_U32 nData1,
        OMX_IN OMX_U32 nData2,
        OMX_IN OMX_PTR pEventData)
    {
        OMXWFRTESTDATA* pContext = pAppData;
        OMX_STATETYPE eState;
        char szState[256];

        UNUSED_PARAMETER(hComponent);
        UNUSED_PARAMETER(pEventData);

        if ((eEvent == OMX_EventCmdComplete) && ((OMX_COMMANDTYPE)(nData1) == OMX_CommandStateSet))
        {
            eState = (OMX_STATETYPE)nData2;

            OMX_CONF_StateToString(eState, szState);

            OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO,
                           "Instantiation %i changing to state %s\n", pContext->nInstantiation, szState);

            /* Set event change notification */
            OMX_OSAL_EventSet(pContext->hEventStateChange);

            if (eState == OMX_StateIdle)
            {
                OMX_OSAL_EventSet(hEventStateChangeIdle);
            }
            if (eState == OMX_StateLoaded)
            {
                OMX_OSAL_EventSet(hEventStateChangeLoaded);
            }
        }
        if ((eEvent == OMX_EventError) && ((OMX_ERRORTYPE)(nData1) == OMX_ErrorInsufficientResources))
        {

            OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO,
                           "Instantiation %i sent OMX_ErrorInsufficientResources error\n", pContext->nInstantiation);

            pContext->bErrorInsufficientResources = OMX_TRUE;
            OMX_OSAL_EventSet(pContext->hEventStateChange);
        }
        return OMX_ErrorNone;
    }
    OMX_ERRORTYPE ResourceExhaustionTest_EventHandler(OMX_IN OMX_HANDLETYPE hComponent,
            OMX_IN OMX_PTR pAppData,
            OMX_IN OMX_EVENTTYPE eEvent,
            OMX_IN OMX_U32 nData1,
            OMX_IN OMX_U32 nData2,
            OMX_IN OMX_PTR pEventData)
    {
        ResourceExhaustionTestContext *pCtxt;

        UNUSED_PARAMETER(hComponent);
        UNUSED_PARAMETER(pEventData);

        if (pAppData == NULL)
            return OMX_ErrorNone;
        pCtxt = (ResourceExhaustionTestContext *)pAppData;

        if (eEvent == OMX_EventCmdComplete)
        {
            switch ((OMX_COMMANDTYPE)(nData1))
            {
                case OMX_CommandStateSet:
                    OMX_CONF_StateToString((OMX_STATETYPE)(nData2), szDesc);
                    OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Instance %d transitioned to %s\n",
                                   pCtxt->nInst, szDesc);
                    OMX_OSAL_EventSet(pCtxt->hStateSetEvent);
                    break;
                default:
                    break;
            }
        }
        else if (eEvent == OMX_EventError)
        {
            pCtxt->eLastError = (OMX_ERRORTYPE)(nData1);
            OMX_CONF_ErrorToString(pCtxt->eLastError, szDesc);
            OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Instance %d sent error %0#x %s\n",
                           pCtxt->nInst, nData1, szDesc);
            OMX_OSAL_EventSet(pCtxt->hStateSetEvent);
        }
        return OMX_ErrorNone;
    }
    OMX_ERRORTYPE BufferTest_EventHandler(
        OMX_IN OMX_HANDLETYPE hComponent,
        OMX_IN OMX_PTR pAppData,
        OMX_IN OMX_EVENTTYPE eEvent,
        OMX_IN OMX_U32 nData1,
        OMX_IN OMX_U32 nData2,
        OMX_IN OMX_PTR pEventData)
    {
        TEST_CTXTYPE *pCtx;

        UNUSED_PARAMETER(hComponent);
        UNUSED_PARAMETER(pEventData);

        if (0x0 == pAppData) return(OMX_ErrorNone);
        pCtx = (TEST_CTXTYPE*)pAppData;

        if (OMX_EventCmdComplete == eEvent)
        {
            switch ((OMX_COMMANDTYPE)(nData1))
            {
                case OMX_CommandStateSet:
                    OMX_CONF_StateToString((OMX_STATETYPE)(nData2), szDesc);
                    OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Component transitioned to %s\n", szDesc);
                    pCtx->eState = (OMX_STATETYPE)(nData2);
                    OMX_OSAL_EventSet(pCtx->hStateChangeEvent);
                    break;
                case OMX_CommandPortDisable:
                    OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Port %i completed disable\n", nData2);
                    if (OMX_TRUE == pCtx->bStopAllPorts)
                    {
                        pCtx->nNumPortsStopped++;
                        if (pCtx->nNumPortsStopped == pCtx->nNumPorts)
                        {
                            OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "All ports completed disable\n");
                            OMX_OSAL_EventSet(pCtx->hPortDisableEvent);
                        }

                    }
                    else if (pCtx->nStopPort == nData2)
                    {
                        OMX_OSAL_EventSet(pCtx->hPortDisableEvent);
                    }
                    break;
                case OMX_CommandPortEnable:
                    OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Port %i completed enable\n", nData2);
                    if (OMX_TRUE == pCtx->bRestartAllPorts)
                    {
                        pCtx->nNumPortsRestarted++;
                        if (pCtx->nNumPortsRestarted == pCtx->nNumPorts)
                        {
                            OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "All ports completed enable\n");
                            OMX_OSAL_EventSet(pCtx->hPortEnableEvent);
                        }
                    }
                    else if (pCtx->nRestartPort == nData2)
                    {
                        OMX_OSAL_EventSet(pCtx->hPortEnableEvent);
                    }
                    break;
                case OMX_EventBufferFlag:
                    break;
                default:
                    break;
            }

        }
        else if (OMX_EventError == eEvent)
        {
            OMX_CONF_ErrorToString((OMX_ERRORTYPE)nData1, szDesc);
            OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Component reported error %s (0x%x)\n",
                           szDesc, nData2);
            if (OMX_ErrorPortUnpopulated == nData1)
            {
                OMX_OSAL_EventSet(pCtx->hPortErrorEvent);
            }
        }

        return OMX_ErrorNone;
    }