OMX_ERRORTYPE load_component(HTEST *hTest, OMX_U32 idx)
{
	OMX_ERRORTYPE ret = OMX_ErrorNone;
	OMX_COMPONENTTYPE *hComponent = NULL;
	OMX_COMPONENTINITTYPE pInit = NULL;
	OMX_STRING cError;

	hTest->pLibHandle[idx] = dlopen(hTest->lib_name[idx], RTLD_NOW);
	if(hTest->pLibHandle[idx] == NULL)
	{
		cError = dlerror();
		printf("%s\n", cError);
		return OMX_ErrorInvalidComponentName;
	}

	pInit = (OMX_COMPONENTINITTYPE)dlsym(hTest->pLibHandle[idx], hTest->itf_name[idx]);
	if(pInit == NULL)
	{
		cError = dlerror();
		printf("%s\n", cError);
		return OMX_ErrorInvalidComponent;
	}

	hComponent = (OMX_COMPONENTTYPE*)fsl_osal_malloc_new(sizeof(OMX_COMPONENTTYPE));
	if(hComponent == NULL)
	{
		printf("Failed to allocate memory for hComponent.\n");
		return OMX_ErrorInsufficientResources;
	}
	OMX_INIT_STRUCT(hComponent, OMX_COMPONENTTYPE);

	ret = pInit((OMX_HANDLETYPE)(hComponent));
	if(ret != OMX_ErrorNone)
	{
		printf("Load component failed.\n");
		return OMX_ErrorInvalidComponentName;
	}

	hComponent->SetCallbacks(hComponent, &gCallBacks, hTest);
	hTest->component[idx].hComponent = hComponent;


	return OMX_ErrorNone;
}
示例#2
0
/* OMX_GetHandle */
OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(
   OMX_OUT OMX_HANDLETYPE* pHandle,
   OMX_IN  OMX_STRING cComponentName,
   OMX_IN  OMX_PTR pAppData,
   OMX_IN  OMX_CALLBACKTYPE* pCallBacks)
{
   OMX_ERRORTYPE eError;
   OMX_COMPONENTTYPE *pComp;
   OMX_HANDLETYPE hHandle = 0;

   if (pHandle == NULL || cComponentName == NULL || pCallBacks == NULL || ilcs_service == NULL)
   {
      if(pHandle)
         *pHandle = NULL;
      return OMX_ErrorBadParameter;
   }

   {
      pComp = (OMX_COMPONENTTYPE *)malloc(sizeof(OMX_COMPONENTTYPE));
      if (!pComp)
      {
         vcos_assert(0);
         return OMX_ErrorInsufficientResources;
      }
      memset(pComp, 0, sizeof(OMX_COMPONENTTYPE));
      hHandle = (OMX_HANDLETYPE)pComp;
      pComp->nSize = sizeof(OMX_COMPONENTTYPE);
      pComp->nVersion.nVersion = OMX_VERSION;
      eError = vcil_out_create_component(ilcs_get_common(ilcs_service), hHandle, cComponentName);

      if (eError == OMX_ErrorNone) {
         // Check that all function pointers have been filled in.
         // All fields should be non-zero.
         int i;
         uint32_t *p = (uint32_t *) pComp;
         for(i=0; i<sizeof(OMX_COMPONENTTYPE)>>2; i++)
            if(*p++ == 0)
               eError = OMX_ErrorInvalidComponent;

         if(eError != OMX_ErrorNone && pComp->ComponentDeInit)
            pComp->ComponentDeInit(hHandle);
      }

      if (eError == OMX_ErrorNone) {
         eError = pComp->SetCallbacks(hHandle,pCallBacks,pAppData);
         if (eError != OMX_ErrorNone)
            pComp->ComponentDeInit(hHandle);
      }
      if (eError == OMX_ErrorNone) {
         *pHandle = hHandle;
      }
      else {
         *pHandle = NULL;
         free(pComp);
      }
   }

   if (eError == OMX_ErrorNone) {
      vcos_mutex_lock(&lock);
      nActiveHandles++;
      vcos_mutex_unlock(&lock);
   }

   return eError;
}