OMX_ERRORTYPE ResourceExhaustionTest_AllocateAllBuffers(ResourceExhaustionTestContext *pCtxt) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_PARAM_PORTDEFINITIONTYPE sPortDef; OMX_U32 i, j, k; OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; BufferList *pBufferListObj; BufferList *pTemp; /* for all ports */ for (j = 0; j < NUM_DOMAINS; j++) { for (i = pCtxt->sPortParam[j].nStartPortNumber; i < pCtxt->sPortParam[j].nStartPortNumber + pCtxt->sPortParam[j].nPorts; i++) { OMX_CONF_INIT_STRUCT(sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); sPortDef.nPortIndex = i; OMX_CONF_BAIL_IF_ERROR(OMX_GetParameter(pCtxt->hWComp[pCtxt->nInst], OMX_IndexParamPortDefinition, (OMX_PTR)&sPortDef)); if (sPortDef.nBufferCountActual == 0x0 || sPortDef.nBufferCountActual < sPortDef.nBufferCountMin) OMX_CONF_SET_ERROR_BAIL("Incorrect nBufferCountActual\n", OMX_ErrorUndefined); for (k = 0x0; k < sPortDef.nBufferCountActual; k++) { pBufferListObj = (BufferList *)OMX_OSAL_Malloc(sizeof(BufferList)); if (!pBufferListObj) { OMX_CONF_SET_ERROR_BAIL("Malloc internal list failed\n", OMX_ErrorInsufficientResources); } OMX_CONF_BAIL_IF_ERROR(OMX_AllocateBuffer(pCtxt->hWComp[pCtxt->nInst], &pBufferHdr, sPortDef.nPortIndex, 0, sPortDef.nBufferSize)); pBufferListObj->pNextBuf = NULL; pBufferListObj->pBufHdr = pBufferHdr; if (sPortDef.eDir == OMX_DirInput) pBufferListObj->pBufHdr->nOutputPortIndex = OMX_NOPORT; else pBufferListObj->pBufHdr->nInputPortIndex = OMX_NOPORT; if (pCtxt->pBufferList[pCtxt->nInst] == NULL) pCtxt->pBufferList[pCtxt->nInst] = pBufferListObj; else { pTemp = pCtxt->pBufferList[pCtxt->nInst]; while (pTemp->pNextBuf) { pTemp = pTemp->pNextBuf; } pTemp->pNextBuf = pBufferListObj; } } } } OMX_CONF_TEST_BAIL: return eError; }
OMX_ERRORTYPE PortCommTest_TransitionWait(OMX_STATETYPE eToState, PortCommTestCtxt* pContext) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_BOOL bTimeout = OMX_FALSE; OMX_OSAL_EventReset(pContext->hStateSetEvent); eError = OMX_SendCommand(pContext->hWComp, OMX_CommandStateSet, eToState, 0); OMX_CONF_BAIL_IF_ERROR(eError); if (eToState == OMX_StateIdle && (pContext->eState == OMX_StateLoaded)) { OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pContext, AllocBuf)); } else if (eToState == OMX_StateLoaded && pContext->eState == OMX_StateIdle) { OMX_CONF_BAIL_IF_ERROR(PortCommTest_DeInitBuffer(pContext)); } OMX_OSAL_EventWait(pContext->hStateSetEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (bTimeout == OMX_TRUE) OMX_CONF_SET_ERROR_BAIL("Transition timed out\n", OMX_ErrorUndefined); if (pContext->eState != eToState) OMX_CONF_SET_ERROR_BAIL("Incorrect transition\n", OMX_ErrorUndefined); OMX_CONF_TEST_BAIL: return eError; }
OMX_ERRORTYPE PortCommTest_TransmitTest(PortCommTestCtxt* pContext, OMX_BOOL bInit, OMX_BOOL bClose) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_BOOL bTimeout; if (bInit) { OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pContext, OpenFile)); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateIdle, pContext)); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateExecuting, pContext)); } /* process buffers */ while (pContext->nBufDoneCalls < OMX_CONF_BUFFERS_OF_TRAFFIC) { if (pContext->nOutBuf) OMX_CONF_BAIL_IF_ERROR(PortCommTest_ReadOutBuffers(pContext)); if (pContext->nInBuf) OMX_CONF_BAIL_IF_ERROR(PortCommTest_WriteInBuffers(pContext)); /* if no empty input or output buffer, wait for bufferdone call */ if (pContext->nOutBuf == pContext->nOutBufBusy && pContext->nInBuf == pContext->nInBufBusy) { OMX_OSAL_EventReset(pContext->hBufDoneEvent); OMX_OSAL_EventWait(pContext->hBufDoneEvent, OMX_CONF_TIMEOUT_BUFFER_TRAFFIC, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("Component is not processing any buffers\n", OMX_ErrorUndefined); } } } OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Processed %d buffers\n", pContext->nBufDoneCalls); if (bClose) { OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pContext, CloseFile)); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateIdle, pContext)); while (pContext->nOutBufBusy || pContext->nInBufBusy) { OMX_OSAL_EventReset(pContext->hBufDoneEvent); OMX_OSAL_EventWait(pContext->hBufDoneEvent, OMX_CONF_TIMEOUT_BUFFER_TRAFFIC, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("All buffers not returned\n", OMX_ErrorUndefined); } } OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateLoaded, pContext)); } pContext->nBufDoneCalls = 0; OMX_CONF_TEST_BAIL: return eError; }
OMX_ERRORTYPE ResourceExhaustionTest_TransitionWait(ResourceExhaustionTestContext* pCtxt, OMX_STATETYPE eToState) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_BOOL bTimeout = OMX_FALSE; OMX_STATETYPE eState; OMX_OSAL_EventReset(pCtxt->hStateSetEvent); pCtxt->eLastError = OMX_ErrorNone; OMX_CONF_BAIL_IF_ERROR(OMX_GetState(pCtxt->hWComp[pCtxt->nInst], &eState)); eError = OMX_SendCommand(pCtxt->hWComp[pCtxt->nInst], OMX_CommandStateSet, eToState, 0); OMX_CONF_BAIL_IF_ERROR(eError); if (eToState == OMX_StateIdle && (eState == OMX_StateLoaded)) { OMX_CONF_BAIL_IF_ERROR(ResourceExhaustionTest_AllocateAllBuffers(pCtxt)); } else if (eToState == OMX_StateLoaded && eState == OMX_StateIdle) { OMX_CONF_BAIL_IF_ERROR(ResourceExhaustionTest_DeInitBuffer(pCtxt)); } OMX_OSAL_EventWait(pCtxt->hStateSetEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); OMX_CONF_BAIL_IF_ERROR(pCtxt->eLastError); if (bTimeout == OMX_TRUE) OMX_CONF_SET_ERROR_BAIL("Timeout on state transition\n", OMX_ErrorUndefined); OMX_CONF_BAIL_IF_ERROR(OMX_GetState(pCtxt->hWComp[pCtxt->nInst], &eState)); if (eState != eToState) OMX_CONF_SET_ERROR_BAIL("Incorrect transition\n", OMX_ErrorUndefined); OMX_CONF_TEST_BAIL: if (OMX_ErrorNone != eError && eToState == OMX_StateIdle && (eState == OMX_StateLoaded)) { /* Add some delay before cleaning up */ OMX_OSAL_EventWait(pCtxt->hStateSetEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); /* Disable all ports to free buffers*/ OMX_SendCommand(pCtxt->hWComp[pCtxt->nInst], OMX_CommandPortDisable, OMX_ALL, 0x0); /* Cleanup last instance */ ResourceExhaustionTest_DeInitBuffer(pCtxt); } return eError; }
OMX_ERRORTYPE PortCommTest_RepackTest(PortCommTestCtxt* pContext) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_BOOL bTimeout; OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pContext, OpenFile)); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateIdle, pContext)); if (pContext->nInBuf == 0) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Source component, Repack Test not applicable\n"); OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pContext, CloseFile)); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateLoaded, pContext)); goto OMX_CONF_TEST_BAIL; } OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateExecuting, pContext)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Sending single byte payloads\n"); pContext->nBufFactor = 0; OMX_OSAL_EventReset(pContext->hEmptyBufDoneEvent); if (pContext->nOutBuf) OMX_CONF_BAIL_IF_ERROR(PortCommTest_ReadOutBuffers(pContext)); if (pContext->nInBuf) OMX_CONF_BAIL_IF_ERROR(PortCommTest_WriteInBuffers(pContext)); OMX_OSAL_EventWait(pContext->hEmptyBufDoneEvent, OMX_CONF_TIMEOUT_BUFFER_TRAFFIC, &bTimeout); if (pContext->nOutBuf && OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("Component is not repacking\n", OMX_ErrorUndefined); } if (pContext->nInBuf && !pContext->pInBufferList->pBufHdr) { OMX_CONF_SET_ERROR_BAIL("first buffer has to be returned\n", OMX_ErrorUndefined); } OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Sending full payloads\n"); pContext->nBufFactor = 1; OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pContext, OMX_FALSE, OMX_TRUE)); OMX_CONF_TEST_BAIL: return eError; }
OMX_ERRORTYPE PortCommTest_PauseResume(PortCommTestCtxt* pContext) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_BOOL bTimeout; OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pContext, OMX_TRUE, OMX_FALSE)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Pause the component\n"); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StatePause, pContext)); OMX_OSAL_EventReset(pContext->hBufDoneEvent); OMX_OSAL_EventWait(pContext->hBufDoneEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("bufferdone callbacks made after pause cmdcomplete\n", OMX_ErrorUndefined); } pContext->nBufDoneCalls = 0; OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Attempting to process buffers while paused\n"); OMX_OSAL_EventReset(pContext->hBufDoneEvent); if (pContext->nOutBuf) OMX_CONF_BAIL_IF_ERROR(PortCommTest_ReadOutBuffers(pContext)); if (pContext->nInBuf) OMX_CONF_BAIL_IF_ERROR(PortCommTest_WriteInBuffers(pContext)); OMX_OSAL_EventWait(pContext->hBufDoneEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("bufferdone callbacks made during paused state\n", OMX_ErrorUndefined); } OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Processed %d buffers\n", pContext->nBufDoneCalls); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Return to executing\n"); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransitionWait(OMX_StateExecuting, pContext)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Process buffers after resuming\n"); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pContext, OMX_FALSE, OMX_TRUE)); OMX_CONF_TEST_BAIL: return eError; }
OMX_ERRORTYPE ResourceExhaustionTest_LOAD(ResourceExhaustionTestContext *pCtxt, OMX_STRING cComponentName, OMX_PTR pWAppData, OMX_PTR pWCallbacks) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_STATETYPE eState; eError = OMX_GetHandle(&pCtxt->hComp[pCtxt->nInst], cComponentName, pWAppData, pWCallbacks); OMX_CONF_BAIL_IF_ERROR(eError); eError = OMX_CONF_ComponentTracerCreate(pCtxt->hComp[pCtxt->nInst], cComponentName, &pCtxt->hWComp[pCtxt->nInst]); OMX_CONF_BAIL_IF_ERROR(eError); eError = OMX_GetState(pCtxt->hWComp[pCtxt->nInst], &eState); OMX_CONF_BAIL_IF_ERROR(eError); if (eState != OMX_StateLoaded) OMX_CONF_SET_ERROR_BAIL("Not in loaded state\n", OMX_ErrorUndefined); OMX_CONF_TEST_BAIL: return eError; }
/*----------------------------------------------------------------------------*/ void* OMX_VIDENC_Thread (void* pThreadData) { int status = -1; int fdmax = -1; fd_set rfds; OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_COMMANDTYPE eCmd = -1; OMX_U32 nParam1; int nRet = -1; OMX_PTR pCmdData = NULL; VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL; LCML_DSP_INTERFACE* pLcmlHandle = NULL; sigset_t set; if (!pThreadData) { eError = OMX_ErrorBadParameter; goto OMX_CONF_CMD_BAIL; } pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pThreadData; pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; #ifdef __PERF_INSTRUMENTATION__ pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('V', 'E', ' ', 'T'), PERF_ModuleComponent | PERF_ModuleVideoEncode); #endif /** Looking for highest number of file descriptor for pipes inorder to put in select loop */ fdmax = pComponentPrivate->nCmdPipe[0]; if (pComponentPrivate->nFree_oPipe[0] > fdmax) { fdmax = pComponentPrivate->nFree_oPipe[0]; } if (pComponentPrivate->nFilled_iPipe[0] > fdmax) { fdmax = pComponentPrivate->nFilled_iPipe[0]; } while (1) { FD_ZERO (&rfds); FD_SET (pComponentPrivate->nCmdPipe[0], &rfds); FD_SET (pComponentPrivate->nFree_oPipe[0], &rfds); FD_SET (pComponentPrivate->nFilled_iPipe[0], &rfds); sigemptyset(&set); sigaddset(&set,SIGALRM); status = pselect(fdmax+1, &rfds, NULL, NULL, NULL,&set); if (0 == status) { OMX_TRACE2(pComponentPrivate->dbg, "pselect() = 0\n"); #ifndef UNDER_CE sched_yield(); #else sched_yield(); #endif } else if (-1 == status) { if (pComponentPrivate->eState != OMX_StateLoaded) { OMX_TRACE3(pComponentPrivate->dbg, "select() error.\n"); OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, OMX_EventError, OMX_ErrorHardware, 0, NULL); } /*OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorHardware, pComponentPrivate);*/ eError = OMX_ErrorHardware; OMX_ERROR5(pComponentPrivate->dbg, "*Fatal Error : %x\n", eError); OMX_VIDENC_HandleError(pComponentPrivate, eError); } else { if (FD_ISSET(pComponentPrivate->nCmdPipe[0], &rfds)) { nRet = read(pComponentPrivate->nCmdPipe[0], &eCmd, sizeof(eCmd)); if (nRet == -1) { OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from cmdPipe\n"); OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorHardware, pComponentPrivate); } #ifdef __PERF_INSTRUMENTATION__ PERF_ReceivedCommand(pComponentPrivate->pPERFcomp, eCmd, 0, PERF_ModuleLLMM); #endif if (eCmd == (OMX_COMMANDTYPE)-1) { OMX_PRCOMM2(pComponentPrivate->dbg, "Received thread close command.\n"); OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorNone); } if (eCmd == OMX_CommandMarkBuffer) { nRet = read(pComponentPrivate->nCmdDataPipe[0], &pCmdData, sizeof(pCmdData)); if (nRet == -1) { OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from cmdDataPipe\n"); OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorHardware, pComponentPrivate); } } else { nRet = read(pComponentPrivate->nCmdDataPipe[0], &nParam1, sizeof(nParam1)); if (nRet == -1) { OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from cmdDataPipe\n"); OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorHardware, pComponentPrivate); } } #ifdef __PERF_INSTRUMENTATION__ PERF_ReceivedCommand(pComponentPrivate->pPERFcomp, eCmd, (eCmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam1, PERF_ModuleLLMM); #endif switch (eCmd) { case OMX_CommandStateSet : OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandStateSet\n"); eError = OMX_VIDENC_HandleCommandStateSet(pComponentPrivate, nParam1); OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate); OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandStateSet\n"); break; case OMX_CommandFlush : OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandFlush\n"); eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate, nParam1, OMX_FALSE); OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate); OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandFlush\n"); break; case OMX_CommandPortDisable : OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandDisablePort\n"); eError = OMX_VIDENC_HandleCommandDisablePort(pComponentPrivate, nParam1); OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate); OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandDisablePort\n"); break; case OMX_CommandPortEnable : OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandDisablePort\n"); eError = OMX_VIDENC_HandleCommandEnablePort(pComponentPrivate, nParam1); OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate); OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandDisablePort\n"); break; case OMX_CommandMarkBuffer : if (!pComponentPrivate->pMarkBuf) { pComponentPrivate->pMarkBuf = (OMX_MARKTYPE*)(pCmdData); } break; default: OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, OMX_EventError, OMX_ErrorUndefined, 0, NULL); } } if ((FD_ISSET(pComponentPrivate->nFilled_iPipe[0], &rfds)) && (pComponentPrivate->eState != OMX_StatePause && pComponentPrivate->eState != OMX_StateIdle && pComponentPrivate->eState != OMX_StateLoaded)) { OMX_PRBUFFER1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FilledInBuf\n"); eError = OMX_VIDENC_Process_FilledInBuf(pComponentPrivate); if (eError != OMX_ErrorNone) { OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, OMX_EventError, OMX_ErrorUndefined, 0, NULL); OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate); } OMX_PRBUFFER1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FilledInBuf\n"); } if (FD_ISSET(pComponentPrivate->nFree_oPipe[0], &rfds) && (pComponentPrivate->eState!= OMX_StatePause && pComponentPrivate->eState != OMX_StateIdle && pComponentPrivate->eState != OMX_StateLoaded)) { OMX_PRBUFFER1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FreeOutBuf\n"); eError = OMX_VIDENC_Process_FreeOutBuf(pComponentPrivate); if (eError != OMX_ErrorNone) { OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, OMX_EventError, OMX_ErrorUndefined, 0, NULL); OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate); } OMX_PRBUFFER1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FreeOutBuf\n"); } } } OMX_CONF_CMD_BAIL: #ifdef __PERF_INSTRUMENTATION__ if (pComponentPrivate) PERF_Done(pComponentPrivate->pPERFcomp); #endif if (pComponentPrivate) OMX_PRINT2(pComponentPrivate->dbg, "Component Thread Exits\n"); return (void*)eError; }
OMX_ERRORTYPE OMX_CONF_BufferTest(OMX_IN OMX_STRING cComponentName) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_ERRORTYPE eCleanupError = OMX_ErrorNone; TEST_CTXTYPE ctx; TEST_CTXTYPE *pCtx; OMX_HANDLETYPE hComp = 0x0; OMX_CALLBACKTYPE oCallbacks; OMX_HANDLETYPE hWrappedComp = 0x0; OMX_CALLBACKTYPE *pWrappedCallbacks; OMX_PTR pWrappedAppData; OMX_BOOL bTimeout; TEST_PORTTYPE *pPort; OMX_U32 i; OMX_U32 nPortIndex; OMX_PARAM_PORTDEFINITIONTYPE sPortDefinition; oCallbacks.EventHandler = BufferTest_EventHandler; oCallbacks.EmptyBufferDone = StubbedEmptyBufferDone; oCallbacks.FillBufferDone = StubbedFillBufferDone; pCtx = &ctx; pCtx->hStateChangeEvent = 0x0; pCtx->hPortDisableEvent = 0x0; pCtx->hPortEnableEvent = 0x0; pCtx->hPortErrorEvent = 0x0; pCtx->aPorts = 0x0; pCtx->bRestartAllPorts = OMX_FALSE; pCtx->bStopAllPorts = OMX_FALSE; /* initialize events to track callbacks */ OMX_OSAL_EventCreate(&pCtx->hStateChangeEvent); OMX_OSAL_EventReset(pCtx->hStateChangeEvent); OMX_OSAL_EventCreate(&pCtx->hPortDisableEvent); OMX_OSAL_EventReset(pCtx->hPortDisableEvent); OMX_OSAL_EventCreate(&pCtx->hPortEnableEvent); OMX_OSAL_EventReset(pCtx->hPortEnableEvent); OMX_OSAL_EventCreate(&pCtx->hPortErrorEvent); OMX_OSAL_EventReset(pCtx->hPortErrorEvent); eError = OMX_CONF_CallbackTracerCreate(&oCallbacks, (OMX_PTR)pCtx, cComponentName, &pWrappedCallbacks, &pWrappedAppData); OMX_CONF_BAIL_ON_ERROR(eError); /* Initialize OpenMax */ eError = OMX_Init(); OMX_CONF_BAIL_ON_ERROR(eError); eError = OMX_GetHandle(&hComp, cComponentName, pWrappedAppData, pWrappedCallbacks); OMX_CONF_BAIL_ON_ERROR(eError); eError = OMX_CONF_ComponentTracerCreate(hComp, cComponentName, &hWrappedComp); OMX_CONF_BAIL_ON_ERROR(eError); pCtx->hWrappedComp = hWrappedComp; OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected all port on component %s\n", cComponentName); /* inspect component's ports */ OMX_CONF_INIT_STRUCT(pCtx->sPortParam[0], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(hWrappedComp, OMX_IndexParamAudioInit, (OMX_PTR) & pCtx->sPortParam[0]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i audio ports starting at %i \n", pCtx->sPortParam[0].nPorts, pCtx->sPortParam[0].nStartPortNumber); /* detect all video ports on the component */ OMX_CONF_INIT_STRUCT(pCtx->sPortParam[1], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(hWrappedComp, OMX_IndexParamVideoInit, (OMX_PTR) & pCtx->sPortParam[1]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i video ports starting at %i \n", pCtx->sPortParam[1].nPorts, pCtx->sPortParam[1].nStartPortNumber); /* detect all image ports on the component */ OMX_CONF_INIT_STRUCT(pCtx->sPortParam[2], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(hWrappedComp, OMX_IndexParamImageInit, (OMX_PTR) & pCtx->sPortParam[2]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i image ports starting at %i \n", pCtx->sPortParam[2].nPorts, pCtx->sPortParam[2].nStartPortNumber); /* detect all other ports on the component */ OMX_CONF_INIT_STRUCT(pCtx->sPortParam[3], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(hWrappedComp, OMX_IndexParamOtherInit, (OMX_PTR) & pCtx->sPortParam[3]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i other ports starting at %i \n", pCtx->sPortParam[3].nPorts, pCtx->sPortParam[3].nStartPortNumber); /* record total number of ports and allocate port structures */ pCtx->nNumPorts = pCtx->sPortParam[0].nPorts + pCtx->sPortParam[1].nPorts + pCtx->sPortParam[2].nPorts + pCtx->sPortParam[3].nPorts; if (0x0 == pCtx->nNumPorts) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Component has no ports\n"); } /* allocate port structures */ eError = BufferTest_AllocatePortStructures(pCtx); OMX_CONF_BAIL_ON_ERROR(eError); /* transition component to idle, verifying that the component does not go to IDLE within a certain timeout */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command component to OMX_StateIdle\n"); OMX_OSAL_EventReset(pCtx->hStateChangeEvent); eError = OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateIdle, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); /* allocate some buffers on the ports, vertifying the component does not transition to idle */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Allocate some buffers on all ports\n"); eError = BufferTest_AllocateAllButOne(pCtx); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hStateChangeEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Unexpected state transition to OMX_StateIdle\n"); } /* allocate all buffers on the ports, vertifying the component does transition to idle */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Allocate remaining buffers on all ports\n"); eError = BufferTest_AllocateAllPlusOne(pCtx); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hStateChangeEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "State transition to OMX_StateIdle never occured\n"); } /* transition the component to from idle to loaded, verifying the component does not transition */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command component to OMX_StateLoaded\n"); OMX_OSAL_EventReset(pCtx->hStateChangeEvent); eError = OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateLoaded, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); /* free some buffers */ eError = BufferTest_FreeAllButOne(pCtx); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hStateChangeEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Unexpected state transition to OMX_StateLoaded\n"); } /* free all buffers and confirm component transitions to loaded */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Free buffers on all ports\n"); eError = BufferTest_FreeAll(pCtx); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hStateChangeEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Expected state transition to OMX_StateLoaded\n"); } /* stop all ports */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command all ports to disabled\n"); pCtx->bStopAllPorts = OMX_TRUE; pCtx->nNumPortsStopped = 0x0; OMX_OSAL_EventReset(pCtx->hPortDisableEvent); eError = OMX_SendCommand(hWrappedComp, OMX_CommandPortDisable, OMX_ALL, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hPortDisableEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "All ports not disabled\n"); } pCtx->bStopAllPorts = OMX_FALSE; /* set the component to idle */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command component to OMX_StateIdle\n"); OMX_OSAL_EventReset(pCtx->hStateChangeEvent); eError = OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateIdle, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hStateChangeEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Expected state transition to OMX_StateIdle\n"); } pPort = pCtx->aPorts; for (i = 0; i < pCtx->nNumPorts; i++) { /* verify port enable and populated status */ nPortIndex = pPort->sPortDef.nPortIndex; OMX_CONF_INIT_STRUCT(sPortDefinition, OMX_PARAM_PORTDEFINITIONTYPE); sPortDefinition.nPortIndex = nPortIndex; eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & sPortDefinition); OMX_CONF_BAIL_ON_ERROR(eError); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bEnabled), "Incorrect value in PortDefinition bEnabled field\n"); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bPopulated), "Incorrect value in PortDefinition bPopulated field\n"); /* enable port, and verify it does not restart */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command port %i to enabled\n", nPortIndex); OMX_OSAL_EventReset(pCtx->hPortEnableEvent); pCtx->nRestartPort = nPortIndex; eError = OMX_SendCommand(hWrappedComp, OMX_CommandPortEnable, nPortIndex, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hPortEnableEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Port enabled unexpectedly\n"); } /* verify port enabled, but not populated */ OMX_CONF_INIT_STRUCT(sPortDefinition, OMX_PARAM_PORTDEFINITIONTYPE); sPortDefinition.nPortIndex = nPortIndex; eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & sPortDefinition); OMX_CONF_BAIL_ON_ERROR(eError); OMX_CONF_ASSERT(eError, (OMX_TRUE == sPortDefinition.bEnabled), "Incorrect value in PortDefinition bEnabled field\n"); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bPopulated), "Incorrect value in PortDefinition bPopulated field\n"); /* allocate buffers on the port, and verify it restarts */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Allocate buffers on port %i\n", nPortIndex); eError = BufferTest_PortAllocateNumBuffers(pCtx, pPort, (pPort->sPortDef.nBufferCountActual)); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hPortEnableEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Port never enabled\n"); } /* verify port enabled and populated */ OMX_CONF_INIT_STRUCT(sPortDefinition, OMX_PARAM_PORTDEFINITIONTYPE); sPortDefinition.nPortIndex = nPortIndex; eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & sPortDefinition); OMX_CONF_BAIL_ON_ERROR(eError); OMX_CONF_ASSERT(eError, (OMX_TRUE == sPortDefinition.bEnabled), "Incorrect value in PortDefinition bEnabled field\n"); OMX_CONF_ASSERT(eError, (OMX_TRUE == sPortDefinition.bPopulated), "Incorrect value in PortDefinition bPopulated field\n"); /* stop port, verifying it does not stop */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command port %i to disabled\n", nPortIndex); OMX_OSAL_EventReset(pCtx->hPortDisableEvent); pCtx->nStopPort = nPortIndex; eError = OMX_SendCommand(hWrappedComp, OMX_CommandPortDisable, nPortIndex, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hPortDisableEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Port disabled unexpectedly\n"); } /* free buffers on the port, verifying it stops */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Free buffers on port %i\n", nPortIndex); eError = BufferTest_PortFreeNumBuffers(pCtx, pPort, LIFO_INQUEUE(pPort->pLifo)); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hPortDisableEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Port never disabled\n"); } /* verify port not enabled, not populated */ OMX_CONF_INIT_STRUCT(sPortDefinition, OMX_PARAM_PORTDEFINITIONTYPE); sPortDefinition.nPortIndex = nPortIndex; eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & sPortDefinition); OMX_CONF_BAIL_ON_ERROR(eError); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bEnabled), "Incorrect value in PortDefinition bEnabled field\n"); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bPopulated), "Incorrect value in PortDefinition bPopulated field\n"); /* enable the port and allocate buffers */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command port %i to enabled\n", nPortIndex); OMX_OSAL_EventReset(pCtx->hPortEnableEvent); eError = OMX_SendCommand(hWrappedComp, OMX_CommandPortEnable, nPortIndex, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Allocate buffers on port %i\n", nPortIndex); eError = BufferTest_PortAllocateNumBuffers(pCtx, pPort, (pPort->sPortDef.nBufferCountActual)); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hPortEnableEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Port never enabled\n"); } /* test the port errors when buffers are freed */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Free buffers on port %i\n", nPortIndex); OMX_OSAL_EventReset(pCtx->hPortErrorEvent); eError = BufferTest_PortFreeNumBuffers(pCtx, pPort, LIFO_INQUEUE(pPort->pLifo)); OMX_CONF_BAIL_ON_ERROR(eError); /* waiting for component to report error due to lost buffers */ OMX_OSAL_EventWait(pCtx->hPortErrorEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Component did not report OMX_ErrorPortUnpopulated\n"); } /* verify port enabled, but not populated */ OMX_CONF_INIT_STRUCT(sPortDefinition, OMX_PARAM_PORTDEFINITIONTYPE); sPortDefinition.nPortIndex = nPortIndex; eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & sPortDefinition); OMX_CONF_BAIL_ON_ERROR(eError); OMX_CONF_ASSERT(eError, (OMX_TRUE == sPortDefinition.bEnabled), "Incorrect value in PortDefinition bEnabled field\n"); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bPopulated), "Incorrect value in PortDefinition bPopulated field\n"); /* stop the port */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command port %i to disabled\n", nPortIndex); OMX_OSAL_EventReset(pCtx->hPortDisableEvent); pCtx->nStopPort = nPortIndex; eError = OMX_SendCommand(hWrappedComp, OMX_CommandPortDisable, nPortIndex, 0x0); OMX_OSAL_EventWait(pCtx->hPortDisableEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Port never disabled\n"); } /* verify port not enabled, but not populated */ OMX_CONF_INIT_STRUCT(sPortDefinition, OMX_PARAM_PORTDEFINITIONTYPE); sPortDefinition.nPortIndex = nPortIndex; eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & sPortDefinition); OMX_CONF_BAIL_ON_ERROR(eError); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bEnabled), "Incorrect value in PortDefinition bEnabled field\n"); OMX_CONF_ASSERT(eError, (OMX_FALSE == sPortDefinition.bPopulated), "Incorrect value in PortDefinition bPopulated field\n"); pPort++; } /* transition component from idle to loaded */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command component to OMX_StateLoaded\n"); OMX_OSAL_EventReset(pCtx->hStateChangeEvent); eError = OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateLoaded, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hStateChangeEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "Expected state transition to OMX_StateLoaded\n"); } /* restart all ports */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Command all ports to enable\n"); pCtx->bRestartAllPorts = OMX_TRUE; pCtx->nNumPortsRestarted = 0x0; OMX_OSAL_EventReset(pCtx->hPortEnableEvent); eError = OMX_SendCommand(hWrappedComp, OMX_CommandPortEnable, OMX_ALL, 0x0); OMX_CONF_BAIL_ON_ERROR(eError); OMX_OSAL_EventWait(pCtx->hPortEnableEvent, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "All ports not enabled\n"); } pCtx->bRestartAllPorts = OMX_FALSE; OMX_CONF_TEST_BAIL: eCleanupError = BufferTest_FreePortStructures(pCtx); if (hWrappedComp) { OMX_CONF_ComponentTracerDestroy(hWrappedComp); } if (hComp) { if (OMX_ErrorNone == eCleanupError) { eCleanupError = OMX_FreeHandle(hComp); } else { OMX_FreeHandle(hComp); } } if (OMX_ErrorNone != eCleanupError) { OMX_Deinit(); } else { eCleanupError = OMX_Deinit(); } OMX_OSAL_EventDestroy(pCtx->hStateChangeEvent); OMX_OSAL_EventDestroy(pCtx->hPortDisableEvent); OMX_OSAL_EventDestroy(pCtx->hPortEnableEvent); OMX_OSAL_EventDestroy(pCtx->hPortErrorEvent); if (OMX_ErrorNone == eError) { /* if there were no failures during the test, report any errors found during cleanup */ eError = eCleanupError; } return(eError); }
OMX_ERRORTYPE BufferTest_AllocatePortStructures( TEST_CTXTYPE *pCtx) { OMX_ERRORTYPE eError = OMX_ErrorNone; TEST_PORTTYPE *pPort; OMX_U32 nSize; OMX_U32 i, j; OMX_U32 nPortIndex; /* allocate port structures */ nSize = (sizeof(TEST_PORTTYPE) * pCtx->nNumPorts); pCtx->aPorts = (TEST_PORTTYPE*)OMX_OSAL_Malloc(nSize); if (0x0 == pCtx->aPorts) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "OMX_OSAL_Malloc failed\n"); } memset(pCtx->aPorts, 0x0, nSize); pPort = pCtx->aPorts; /* initialize port structures */ for (i = 0; i < NUM_DOMAINS; i++) { for (j = 0x0; j < pCtx->sPortParam[i].nPorts; j++) { nPortIndex = pCtx->sPortParam[i].nStartPortNumber + j; OMX_CONF_INIT_STRUCT(pPort->sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); pPort->sPortDef.nPortIndex = nPortIndex; eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & pPort->sPortDef); OMX_CONF_BAIL_ON_ERROR(eError); if (0x0 == pPort->sPortDef.nBufferCountMin) { /* a buffer count of 0x0 is not allowed */ OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "PortDefinition nBufferCountMin incorrect\n"); } if (pPort->sPortDef.nBufferCountMin > pPort->sPortDef.nBufferCountActual) { /* a buffer count of 0x0 is not allowed */ OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "PortDefinition nBufferCountActual incorrect\n"); } /* set the actual buffer count to min + 1 */ pPort->sPortDef.nBufferCountActual = pPort->sPortDef.nBufferCountMin + 1; /* set actual buffer count on the port */ eError = OMX_SetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & pPort->sPortDef); OMX_CONF_BAIL_ON_ERROR(eError); /* allocate LIFO with one more entry that the required minimum as the test will allocate 1 more than needed to exercise allocating buffers during the IDLE state */ LIFO_ALLOC(pPort->pLifo, (pPort->sPortDef.nBufferCountActual)); if (0x0 == pPort->pLifo) { OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "memory allocation failure\n"); } pPort++; } } OMX_CONF_TEST_BAIL: return(eError); }
OMX_ERRORTYPE OMX_CONF_PortCommunicationTest(OMX_IN OMX_STRING cComponentName) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_HANDLETYPE hComp = 0; OMX_CALLBACKTYPE sCallbacks; PortCommTestCtxt sContext; OMX_HANDLETYPE hWrappedComp = 0; OMX_CALLBACKTYPE *pWrappedCallbacks; OMX_PTR pWrappedAppData; PortCommTestCtxt *pCtxt; pCtxt = &sContext; memset(pCtxt, 0x0, sizeof(PortCommTestCtxt)); sCallbacks.EventHandler = PortCommTest_EventHandler; sCallbacks.EmptyBufferDone = PortCommTest_EmptyBufferDone; sCallbacks.FillBufferDone = PortCommTest_FillBufferDone; eError = OMX_CONF_CallbackTracerCreate(&sCallbacks, (OMX_PTR)pCtxt, cComponentName, &pWrappedCallbacks, &pWrappedAppData); /* initialize events to track callbacks */ OMX_OSAL_EventCreate(&pCtxt->hStateSetEvent); OMX_OSAL_EventReset(pCtxt->hStateSetEvent); OMX_OSAL_EventCreate(&pCtxt->hPortDisableEvent); OMX_OSAL_EventReset(pCtxt->hPortDisableEvent); OMX_OSAL_EventCreate(&pCtxt->hPortEnableEvent); OMX_OSAL_EventReset(pCtxt->hPortEnableEvent); OMX_OSAL_EventCreate(&pCtxt->hBufDoneEvent); OMX_OSAL_EventReset(pCtxt->hBufDoneEvent); OMX_OSAL_EventCreate(&pCtxt->hEmptyBufDoneEvent); OMX_OSAL_EventReset(pCtxt->hEmptyBufDoneEvent); /* Initialize OpenMax */ eError = OMX_Init(); OMX_CONF_BAIL_IF_ERROR(eError); OMX_CONF_BAIL_IF_ERROR(OMX_GetHandle(&hComp, cComponentName, pWrappedAppData, pWrappedCallbacks)); OMX_CONF_BAIL_IF_ERROR(OMX_CONF_ComponentTracerCreate(hComp, cComponentName, &hWrappedComp)); pCtxt->hWComp = hWrappedComp; /* Verify start in Loaded state */ OMX_CONF_BAIL_IF_ERROR(OMX_GetState(pCtxt->hWComp, &pCtxt->eState)); if (pCtxt->eState != OMX_StateLoaded) OMX_CONF_SET_ERROR_BAIL("Component not in loaded state at init\n", OMX_ErrorUndefined); /* detect all audio ports on the component */ OMX_CONF_INIT_STRUCT(pCtxt->sPortParam[0], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(pCtxt->hWComp, OMX_IndexParamAudioInit, (OMX_PTR) & pCtxt->sPortParam[0]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_IF_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i audio ports starting at %i \n", pCtxt->sPortParam[0].nPorts, pCtxt->sPortParam[0].nStartPortNumber); /* detect all video ports on the component */ OMX_CONF_INIT_STRUCT(pCtxt->sPortParam[1], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(pCtxt->hWComp, OMX_IndexParamVideoInit, (OMX_PTR) & pCtxt->sPortParam[1]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_IF_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i video ports starting at %i \n", pCtxt->sPortParam[1].nPorts, pCtxt->sPortParam[1].nStartPortNumber); /* detect all image ports on the component */ OMX_CONF_INIT_STRUCT(pCtxt->sPortParam[2], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(pCtxt->hWComp, OMX_IndexParamImageInit, (OMX_PTR) & pCtxt->sPortParam[2]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_IF_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i image ports starting at %i \n", pCtxt->sPortParam[2].nPorts, pCtxt->sPortParam[2].nStartPortNumber); /* detect all other ports on the component */ OMX_CONF_INIT_STRUCT(pCtxt->sPortParam[3], OMX_PORT_PARAM_TYPE); eError = OMX_GetParameter(pCtxt->hWComp, OMX_IndexParamOtherInit, (OMX_PTR) & pCtxt->sPortParam[3]); if (OMX_ErrorUnsupportedIndex == eError) eError = OMX_ErrorNone; OMX_CONF_BAIL_IF_ERROR(eError); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "detected %i other ports starting at %i \n", pCtxt->sPortParam[3].nPorts, pCtxt->sPortParam[3].nStartPortNumber); pCtxt->nPorts = pCtxt->sPortParam[0].nPorts + pCtxt->sPortParam[1].nPorts + pCtxt->sPortParam[2].nPorts + pCtxt->sPortParam[3].nPorts; /* 3.4.1. Non-Tunneling Setup Test */ /* TODO: reference core does not take null as port */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Non-Tunneling Setup Test\n"); OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pCtxt, NonTunnelTest)); /* 3.4.2. Transmit Buffers Between Input and Output Ports and Application */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Transmit Test - Client allocates - Full payload\n"); pCtxt->nBufFactor = 1; pCtxt->bClientAllocBuf = OMX_TRUE; OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pCtxt, OMX_TRUE, OMX_TRUE)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Transmit Test - Client allocates - Half payload\n"); pCtxt->nBufFactor = 2; OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pCtxt, OMX_TRUE, OMX_TRUE)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Transmit Test - Client allocates - Quarter payload\n"); pCtxt->nBufFactor = 4; OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pCtxt, OMX_TRUE, OMX_TRUE)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Transmit Test - Component allocates - Full payload\n"); pCtxt->bClientAllocBuf = OMX_FALSE; pCtxt->nBufFactor = 1; OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pCtxt, OMX_TRUE, OMX_TRUE)); /* 3.4.3. Port Repack Test */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Repack Test\n"); pCtxt->bClientAllocBuf = OMX_TRUE; OMX_CONF_BAIL_IF_ERROR(PortCommTest_RepackTest(pCtxt)); /* 3.4.4. Port Stop and Restart Test */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Port Stop and Restart Test\n"); pCtxt->nBufFactor = 1; OMX_CONF_BAIL_IF_ERROR(PortCommTest_StopRestartTest(pCtxt)); /* 3.4.5. Component Pause and Resume Test*/ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Component Pause and Resume Test\n"); OMX_CONF_BAIL_IF_ERROR(PortCommTest_PauseResume(pCtxt)); OMX_CONF_TEST_BAIL: /* cleanup: return function errors rather than closing errors if appropriate */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Cleanup\n"); if (OMX_ErrorNone == eError) { if (hWrappedComp) { eError = OMX_CONF_ComponentTracerDestroy(hWrappedComp); } if (hComp) { eError = OMX_FreeHandle(hComp); } eError = OMX_CONF_CallbackTracerDestroy(pWrappedCallbacks, pWrappedAppData); eError = OMX_Deinit(); } else { PortCommTest_TransitionWait(OMX_StateInvalid, pCtxt); PortCommTest_DeInitBuffer(pCtxt); if (hWrappedComp) { OMX_CONF_ComponentTracerDestroy(hWrappedComp); } if (hComp) { OMX_FreeHandle(hComp); } OMX_CONF_CallbackTracerDestroy(pWrappedCallbacks, pWrappedAppData); OMX_Deinit(); } OMX_OSAL_EventDestroy(pCtxt->hStateSetEvent); OMX_OSAL_EventDestroy(pCtxt->hPortDisableEvent); OMX_OSAL_EventDestroy(pCtxt->hPortEnableEvent); OMX_OSAL_EventDestroy(pCtxt->hBufDoneEvent); OMX_OSAL_EventDestroy(pCtxt->hEmptyBufDoneEvent); return eError; }
OMX_ERRORTYPE PortCommTest_StopRestartTest(PortCommTestCtxt* pContext) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_BOOL bTimeout; /* process max frames */ OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pContext, OMX_TRUE, OMX_FALSE)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Stopping all ports\n"); OMX_OSAL_EventReset(pContext->hPortDisableEvent); OMX_CONF_BAIL_IF_ERROR(OMX_SendCommand(pContext->hWComp, OMX_CommandPortDisable, OMX_ALL, 0x0)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Wait for all buffers to be returned\n"); while (pContext->nOutBufBusy || pContext->nInBufBusy) { OMX_OSAL_EventReset(pContext->hBufDoneEvent); OMX_OSAL_EventWait(pContext->hBufDoneEvent, OMX_CONF_TIMEOUT_BUFFER_TRAFFIC, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("All buffers not returned\n", OMX_ErrorUndefined); } } /* check if command completed before de-allocation*/ OMX_OSAL_EventWait(pContext->hPortDisableEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("Ports stopped unexpectedly\n", OMX_ErrorUndefined); } OMX_OSAL_EventReset(pContext->hPortDisableEvent); /* free all buffers */ OMX_CONF_BAIL_IF_ERROR(PortCommTest_DeInitBuffer(pContext)); /* wait for cmd complete */ OMX_OSAL_EventWait(pContext->hPortDisableEvent, OMX_CONF_TIMEOUT_BUFFER_TRAFFIC, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("All ports not stopped\n", OMX_ErrorUndefined); } /* ensure no more buffer done callbacks are made */ OMX_OSAL_EventReset(pContext->hBufDoneEvent); OMX_OSAL_EventWait(pContext->hBufDoneEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("callbacks made after cmdcomplete\n", OMX_ErrorUndefined); } pContext->nBufDoneCalls = 0; OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Attempting to process buffers while stopped\n"); OMX_OSAL_EventReset(pContext->hBufDoneEvent); OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pContext, EmptyFill)); OMX_OSAL_EventWait(pContext->hBufDoneEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("callbacks made while ports disabled\n", OMX_ErrorUndefined); } OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Processed %d buffers\n", pContext->nBufDoneCalls); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Restarting all ports\n"); OMX_OSAL_EventReset(pContext->hPortEnableEvent); /* send restart command */ OMX_CONF_BAIL_IF_ERROR(OMX_SendCommand(pContext->hWComp, OMX_CommandPortEnable, OMX_ALL, 0x0)); /* check if command completed before allocation*/ OMX_OSAL_EventWait(pContext->hPortEnableEvent, OMX_CONF_TIMEOUT_EXPECTING_FAILURE, &bTimeout); if (OMX_FALSE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("Ports restarted unexpectedly\n", OMX_ErrorUndefined); } OMX_OSAL_EventReset(pContext->hPortEnableEvent); /* allocate buffers */ OMX_CONF_BAIL_IF_ERROR(PortCommTest_OperateOnPorts(pContext, AllocBuf)); /* wait for command complete */ OMX_OSAL_EventWait(pContext->hPortEnableEvent, OMX_CONF_TIMEOUT_BUFFER_TRAFFIC, &bTimeout); if (OMX_TRUE == bTimeout) { OMX_CONF_SET_ERROR_BAIL("All ports not restarted\n", OMX_ErrorUndefined); } OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Process buffers after restarting\n"); OMX_CONF_BAIL_IF_ERROR(PortCommTest_TransmitTest(pContext, OMX_FALSE, OMX_TRUE)); OMX_CONF_TEST_BAIL: return eError; }
OMX_ERRORTYPE PortCommTest_OperateOnPorts(PortCommTestCtxt* pContext, PortOpType eOp) { OMX_PARAM_PORTDEFINITIONTYPE sPortDef; OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_U32 i, j; OMX_BUFFERHEADERTYPE sBufHdr; for (j = 0; j < NUM_DOMAINS; j++) { for (i = pContext->sPortParam[j].nStartPortNumber; i < pContext->sPortParam[j].nStartPortNumber + pContext->sPortParam[j].nPorts; i++) { OMX_CONF_INIT_STRUCT(sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); sPortDef.nPortIndex = i; OMX_CONF_BAIL_IF_ERROR(OMX_GetParameter(pContext->hWComp, OMX_IndexParamPortDefinition , (OMX_PTR)&sPortDef)); switch (eOp) { case AllocBuf: if (0x0 == sPortDef.nBufferCountMin || sPortDef.nBufferCountMin > sPortDef.nBufferCountActual) { OMX_CONF_SET_ERROR_BAIL("PortDefinition nBufferCount incorrect\n", OMX_ErrorUndefined); } OMX_CONF_BAIL_IF_ERROR(PortCommTest_AllocateBuffers(pContext, &sPortDef)); break; case NonTunnelTest: if (sPortDef.eDir == OMX_DirInput) { eError = OMX_SetupTunnel(NULL, 0, pContext->hWComp, sPortDef.nPortIndex); OMX_CONF_ErrorToString(eError, szDesc); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Setup tunnel reported error code %s\n", szDesc); } else { eError = OMX_SetupTunnel(pContext->hWComp, sPortDef.nPortIndex, NULL, 0); OMX_CONF_ErrorToString(eError, szDesc); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Setup tunnel reported error code %s\n", szDesc); } eError = OMX_ErrorNone; break; case OpenFile: /* set buffercount actual */ if (0x0 == sPortDef.nBufferCountMin || sPortDef.nBufferCountMin > sPortDef.nBufferCountActual) { OMX_CONF_SET_ERROR_BAIL("PortDefinition nBufferCount incorrect\n", OMX_ErrorUndefined); } sPortDef.nBufferCountActual = sPortDef.nBufferCountMin + 1; OMX_CONF_BAIL_IF_ERROR(OMX_SetParameter(pContext->hWComp, OMX_IndexParamPortDefinition, (OMX_PTR)&sPortDef)); /* open files for input ports */ if (sPortDef.eDir == OMX_DirInput) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Opened input file for port %d\n", i); OMX_CONF_BAIL_IF_ERROR(OMX_OSAL_OpenInputFile(i)); } break; case CloseFile: if (sPortDef.eDir == OMX_DirInput) { OMX_CONF_BAIL_IF_ERROR(OMX_OSAL_CloseInputFile(i)); } break; case EmptyFill: OMX_CONF_INIT_STRUCT(sBufHdr, OMX_BUFFERHEADERTYPE); if (sPortDef.eDir == OMX_DirInput) { sBufHdr.nInputPortIndex = i; eError = OMX_EmptyThisBuffer(pContext->hWComp, &sBufHdr); } else { sBufHdr.nOutputPortIndex = i; eError = OMX_FillThisBuffer(pContext->hWComp, &sBufHdr); } if (eError != OMX_ErrorIncorrectStateOperation) OMX_CONF_SET_ERROR_BAIL("Buffer handling while stopped\n", OMX_ErrorUndefined); eError = OMX_ErrorNone; break; default: eError = OMX_ErrorBadParameter; } } } OMX_CONF_TEST_BAIL: return eError; }
OMX_ERRORTYPE PortCommTest_AllocateBuffers(PortCommTestCtxt *pContext, OMX_PARAM_PORTDEFINITIONTYPE *pPortDef) { OMX_BUFFERHEADERTYPE *pBufferHdr = NULL; OMX_U8 *pBuffer = NULL; BufferList *pBufferList; BufferList *pTemp; OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_U32 i; OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Allocate buffers for port %d\n", pPortDef->nPortIndex); for (i = 0x0; i < pPortDef->nBufferCountActual; i++) { pBufferList = (BufferList *)OMX_OSAL_Malloc(sizeof(BufferList)); if (!pBufferList) OMX_CONF_SET_ERROR_BAIL("malloc failed\n", OMX_ErrorInsufficientResources); if (pContext->bClientAllocBuf) { pBuffer = (OMX_U8*)OMX_OSAL_Malloc(pPortDef->nBufferSize); if (!pBuffer) OMX_CONF_SET_ERROR_BAIL("malloc failed\n", OMX_ErrorInsufficientResources); OMX_CONF_BAIL_IF_ERROR(OMX_UseBuffer(pContext->hWComp, &pBufferHdr, pPortDef->nPortIndex, 0, pPortDef->nBufferSize, pBuffer)); } else { OMX_CONF_BAIL_IF_ERROR(OMX_AllocateBuffer(pContext->hWComp, &pBufferHdr, pPortDef->nPortIndex, 0, pPortDef->nBufferSize)); } pBufferList->pNextBuf = NULL; pBufferList->pBufHdr = pBufferHdr; pBufferList->pOrigBufHdr = pBufferHdr; if (pPortDef->eDir == OMX_DirInput) { /* check if buffer header is as expected */ if (pBufferHdr->nAllocLen != pPortDef->nBufferSize || !pBufferHdr->pBuffer || pBufferHdr->nInputPortIndex != pPortDef->nPortIndex) OMX_CONF_SET_ERROR_BAIL("Buffer header incorrect\n", OMX_ErrorUndefined); pBufferHdr->nOutputPortIndex = OMX_NOPORT; /* put it in internal list */ if (pContext->pInBufferList == NULL) pContext->pInBufferList = pBufferList; else { pTemp = pContext->pInBufferList; while (pTemp->pNextBuf) pTemp = pTemp->pNextBuf; pTemp->pNextBuf = pBufferList; } pContext->nInBuf++; } else { /* check if buffer header is as expected */ if (pBufferHdr->nAllocLen != pPortDef->nBufferSize || !pBufferHdr->pBuffer || pBufferHdr->nOutputPortIndex != pPortDef->nPortIndex) OMX_CONF_SET_ERROR_BAIL("Buffer header incorrect\n", OMX_ErrorUndefined); pBufferHdr->nInputPortIndex = OMX_NOPORT; /* put it in internal list */ if (pContext->pOutBufferList == NULL) pContext->pOutBufferList = pBufferList; else { pTemp = pContext->pOutBufferList; while (pTemp->pNextBuf) pTemp = pTemp->pNextBuf; pTemp->pNextBuf = pBufferList; } pContext->nOutBuf++; } } OMX_CONF_TEST_BAIL: return eError; }