OMX_ERRORTYPE OMX_CONF_WaitForResourcesTest(OMX_IN OMX_STRING cComponentName) { /* Interop test 4.7: Wait For Resources */ /* --------------------------------------- * 1. Load component * 2. Transition to idle * 3. Repeat from steps 1-3 until transition to idle returns * OMX_ErrorInsufficientResources and transitions to Wait state * 4. Switch one of the previous components to the loaded state to free resources * 5. Verify the component in the WaitForResources state transitions to idle */ OMX_HANDLETYPE hComp[1000]; OMX_U32 i, nComp = 0; OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_CALLBACKTYPE oCallbacks; OMXWFRTESTDATA oAppData[1000]; OMX_STATETYPE eState = OMX_StateLoaded; OMX_BOOL bTimeout = OMX_FALSE; OMX_PRIORITYMGMTTYPE oPriority; OMX_HANDLETYPE hTraceComp[1000]; OMX_HANDLETYPE hEventStateChange; OMX_ERRORTYPE eErrorCleanup; OMX_PTR pWrappedAppData[1000]; OMX_CALLBACKTYPE *pWrappedCallbacks[1000]; char szInstantiationName[256]; /* Initialize data */ oCallbacks.EventHandler = WaitResEventHandler; oCallbacks.EmptyBufferDone = StubbedEmptyBufferDone; oCallbacks.FillBufferDone = StubbedFillBufferDone; /* Begin test */ eError = OMX_Init(); if (OMX_ErrorNone != eError) return OMX_ErrorUndefined; hEventStateChange = 0; hEventStateChangeIdle = 0; hEventStateChangeLoaded = 0; eError = OMX_OSAL_EventCreate(&hEventStateChange); OMX_CONF_FAIL_IF_ERROR(eError); eError = OMX_OSAL_EventCreate(&hEventStateChangeIdle); OMX_CONF_FAIL_IF_ERROR(eError); eError = OMX_OSAL_EventCreate(&hEventStateChangeLoaded); OMX_CONF_FAIL_IF_ERROR(eError); INIT_PARAM(oPriority); oPriority.nGroupPriority = OMX_RESOURCETEST_PRIORITY_LOW; oPriority.nGroupID = 1; nComp = 0; do { hComp[nComp] = hTraceComp[nComp] = NULL; GetInstantiationName(cComponentName, nComp, szInstantiationName); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Trying to create and idle instantiation %i (priority = %i)\n", nComp, OMX_RESOURCETEST_PRIORITY_LOW); if (nComp >= 1000) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Test unable to complete. Too many components requested (%d)\n", nComp); eError = OMX_ErrorUndefined; goto OMX_CONF_TEST_FAIL; } oAppData[nComp].bErrorInsufficientResources = OMX_FALSE; oAppData[nComp].hEventStateChange = hEventStateChange; oAppData[nComp].nInstantiation = nComp; eError = OMX_CONF_CallbackTracerCreate(&oCallbacks, (OMX_PTR) & oAppData[nComp], szInstantiationName, &pWrappedCallbacks[nComp], &pWrappedAppData[nComp]); OMX_CONF_FAIL_IF_ERROR(eError); hComp[nComp] = NULL; eError = OMX_GetHandle(&hComp[nComp], cComponentName, pWrappedAppData[nComp], pWrappedCallbacks[nComp]); OMX_CONF_FAIL_IF_ERROR(eError); /* Problem acquiring handle. bail. */ eError = OMX_CONF_ComponentTracerCreate(hComp[nComp], szInstantiationName, &hTraceComp[nComp]); OMX_CONF_FAIL_IF_ERROR(eError); /* Set priority and transition to idle */ eError = OMX_SetParameter(hTraceComp[nComp], OMX_IndexParamPriorityMgmt, &oPriority); OMX_CONF_FAIL_IF_ERROR(eError); /* Disable all ports so we can go idle without buffers */ eError = DisableAllPorts(hTraceComp[nComp]); OMX_CONF_FAIL_IF_ERROR(eError); eError = OMX_SendCommand(hTraceComp[nComp], OMX_CommandStateSet, OMX_StateIdle, 0); OMX_CONF_FAIL_IF_ERROR(eError); OMX_OSAL_EventWait(hEventStateChange, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (bTimeout == OMX_TRUE) { eError = OMX_ErrorTimeout; goto OMX_CONF_TEST_FAIL; } OMX_OSAL_EventReset(hEventStateChange); eError = OMX_GetState(hTraceComp[nComp], &eState); OMX_CONF_FAIL_IF_ERROR(eError); nComp++; } while (!oAppData[nComp-1].bErrorInsufficientResources); nComp--; /* check that the last try stayed in loaded because of insufficient resources */ if ((eState != OMX_StateLoaded) || !oAppData[nComp].bErrorInsufficientResources) { eError = OMX_ErrorUndefined; goto OMX_CONF_TEST_FAIL; } OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Instantiation %i failed to idle (insuffient resources)\n", nComp); /* tell last try it to wait for resources */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Telling instantiation %i to wait for resources\n", nComp); OMX_OSAL_EventReset(hEventStateChange); OMX_CONF_FAIL_IF_ERROR(OMX_SendCommand(hTraceComp[nComp], OMX_CommandStateSet, OMX_StateWaitForResources, 0)); OMX_OSAL_EventWait(hEventStateChange, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (bTimeout == OMX_TRUE) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-ERROR: Timed out waiting for state change from instantiation %i\n", nComp); eError = OMX_ErrorTimeout; goto OMX_CONF_TEST_FAIL; } OMX_CONF_FAIL_IF_ERROR(OMX_GetState(hTraceComp[nComp], &eState)); if (eState != OMX_StateWaitForResources) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-ERROR: State of instantiation %i is not OMX_StateWaitForResources\n", nComp); eError = OMX_ErrorUndefined; goto OMX_CONF_TEST_FAIL; } /* transition first try to loaded */ OMX_OSAL_EventReset(hEventStateChange); OMX_OSAL_EventReset(hEventStateChangeIdle); OMX_OSAL_EventReset(hEventStateChangeLoaded); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Telling instantiation 0 to go to loaded\n", nComp); OMX_CONF_FAIL_IF_ERROR(OMX_SendCommand(hTraceComp[0], OMX_CommandStateSet, OMX_StateLoaded, 0)); OMX_OSAL_EventWait(hEventStateChangeLoaded, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (bTimeout == OMX_TRUE) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-ERROR: Timed out waiting for state change from instantiation 0\n"); eError = OMX_ErrorTimeout; goto OMX_CONF_TEST_FAIL; } OMX_CONF_FAIL_IF_ERROR(OMX_GetState(hTraceComp[0], &eState)); if (eState != OMX_StateLoaded) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-ERROR: State of instantiation 0 is not OMX_StateLoaded\n"); eError = OMX_ErrorUndefined; goto OMX_CONF_TEST_FAIL; } /* wait for last try to get resources */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Waiting for instantiation %i to go to idle\n", nComp); OMX_OSAL_EventWait(hEventStateChangeIdle, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); if (bTimeout == OMX_TRUE) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-ERROR: Timed out waiting for state change from instantiation %i\n", nComp); eError = OMX_ErrorTimeout; goto OMX_CONF_TEST_FAIL; } OMX_CONF_FAIL_IF_ERROR(OMX_GetState(hTraceComp[nComp], &eState)); if (eState != OMX_StateIdle) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-ERROR: State of instantiation %i is not OMX_StateIdle\n", nComp); eError = OMX_ErrorUndefined; goto OMX_CONF_TEST_FAIL; } OMX_CONF_TEST_FAIL: /* Cleanup */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Cleaning up\n"); for (i = 1;i <= nComp;i++) { OMX_ERRORTYPE eErrorCleanup; if (hTraceComp[i] != NULL) { OMX_OSAL_EventReset(hEventStateChange); eErrorCleanup = OMX_SendCommand(hTraceComp[i], OMX_CommandStateSet, OMX_StateLoaded, 0); if (OMX_ErrorNone == eErrorCleanup) { OMX_OSAL_EventWait(hEventStateChange, OMX_CONF_TIMEOUT_EXPECTING_SUCCESS, &bTimeout); } } } for (i = 0;i <= nComp;i++) { OMX_OSAL_EventReset(hEventStateChange); OMX_OSAL_EventWait(hEventStateChange, 20, &bTimeout); if (hComp[i] != NULL) eErrorCleanup = OMX_FreeHandle(hComp[i]); } for (i = 0;i <= nComp;i++) { /* unset trace component */ if (hTraceComp[i] != NULL) OMX_CONF_ComponentTracerDestroy(hTraceComp[i]); } for (i = 0;i <= nComp;i++) { OMX_CONF_CallbackTracerDestroy(pWrappedCallbacks[i], pWrappedAppData[i]); } if (hEventStateChange) { OMX_OSAL_EventDestroy(hEventStateChange); } if (hEventStateChangeIdle) { OMX_OSAL_EventDestroy(hEventStateChangeIdle); } if (hEventStateChangeLoaded) { OMX_OSAL_EventDestroy(hEventStateChangeLoaded); } OMX_Deinit(); return eError; }
bool COMXCoreComponent::Initialize( const std::string &component_name, OMX_INDEXTYPE index) { OMX_ERRORTYPE omx_err; if(!m_DllOMX->Load()) return false; m_DllOMXOpen = true; m_componentName = component_name; m_callbacks.EventHandler = &COMXCoreComponent::DecoderEventHandlerCallback; m_callbacks.EmptyBufferDone = &COMXCoreComponent::DecoderEmptyBufferDoneCallback; m_callbacks.FillBufferDone = &COMXCoreComponent::DecoderFillBufferDoneCallback; // Get video component handle setting up callbacks, component is in loaded state on return. omx_err = m_DllOMX->OMX_GetHandle(&m_handle, (char*)component_name.c_str(), this, &m_callbacks); if (omx_err != OMX_ErrorNone) { CLog::Log(LOGERROR, "COMXCoreComponent::Initialize - could not get component handle for %s omx_err(0x%08x)\n", component_name.c_str(), (int)omx_err); Deinitialize(); return false; } OMX_PORT_PARAM_TYPE port_param; OMX_INIT_STRUCTURE(port_param); omx_err = OMX_GetParameter(m_handle, index, &port_param); if (omx_err != OMX_ErrorNone) { CLog::Log(LOGERROR, "COMXCoreComponent::Initialize - could not get port_param for component %s omx_err(0x%08x)\n", component_name.c_str(), (int)omx_err); } omx_err = DisableAllPorts(); if (omx_err != OMX_ErrorNone) { CLog::Log(LOGERROR, "COMXCoreComponent::Initialize - error disable ports on component %s omx_err(0x%08x)\n", component_name.c_str(), (int)omx_err); } m_input_port = port_param.nStartPortNumber; m_output_port = m_input_port + 1; if(m_componentName == "OMX.broadcom.audio_mixer") { m_input_port = port_param.nStartPortNumber + 1; m_output_port = port_param.nStartPortNumber; } if (m_output_port > port_param.nStartPortNumber+port_param.nPorts-1) m_output_port = port_param.nStartPortNumber+port_param.nPorts-1; CLog::Log(LOGDEBUG, "COMXCoreComponent::Initialize %s input port %d output port %d\n", m_componentName.c_str(), m_input_port, m_output_port); m_exit = false; m_flush_input = false; m_flush_output = false; return true; }
bool COMXCoreComponent::Initialize( const std::string &component_name, OMX_INDEXTYPE index) { OMX_ERRORTYPE omx_err; if(!m_DllOMXOpen) return false; m_resource_error = false; m_componentName = component_name; m_callbacks.EventHandler = &COMXCoreComponent::DecoderEventHandlerCallback; m_callbacks.EmptyBufferDone = &COMXCoreComponent::DecoderEmptyBufferDoneCallback; m_callbacks.FillBufferDone = &COMXCoreComponent::DecoderFillBufferDoneCallback; if(!m_handle) { omx_err = OMX_GetHandle(&m_handle, (char*)component_name.c_str(), this, &m_callbacks); if (!m_handle || omx_err != OMX_ErrorNone) { Logger::LogOut(LOG_LEVEL_ERROR, "COMXCoreComponent::Initialize - could not get component handle for %s omx_err(0x%08x)", component_name.c_str(), (int)omx_err); Deinitialize(true); return false; } Logger::LogOut(LOG_LEVEL_DEBUG, "COMXCoreComponent::Initialize : %s handle %p dllopen : %d", m_componentName.c_str(), m_handle, m_DllOMXOpen); } OMX_PORT_PARAM_TYPE port_param; OMX_INIT_STRUCTURE(port_param); omx_err = OMX_GetParameter(m_handle, index, &port_param); if (omx_err != OMX_ErrorNone) { Logger::LogOut(LOG_LEVEL_ERROR, "COMXCoreComponent::Initialize - could not get port_param for component %s omx_err(0x%08x)", component_name.c_str(), (int)omx_err); } omx_err = DisableAllPorts(); if (omx_err != OMX_ErrorNone) { Logger::LogOut(LOG_LEVEL_ERROR, "COMXCoreComponent::Initialize - error disable ports on component %s omx_err(0x%08x)", component_name.c_str(), (int)omx_err); } m_input_port = port_param.nStartPortNumber; m_output_port = m_input_port + 1; if(m_componentName == "OMX.broadcom.audio_mixer") { m_input_port = port_param.nStartPortNumber + 1; m_output_port = port_param.nStartPortNumber; } if (m_output_port > port_param.nStartPortNumber+port_param.nPorts-1) m_output_port = port_param.nStartPortNumber+port_param.nPorts-1; Logger::LogOut(LOG_LEVEL_DEBUG, "COMXCoreComponent::Initialize %s input port %d output port %d", m_componentName.c_str(), m_input_port, m_output_port); m_exit = false; m_flush_input = false; m_flush_output = false; return true; }