示例#1
0
/** @brief The OMX_Init standard function
 *
 * This function calls the init function of each component loader added. If there
 * is no component loaders present, the ST default component loader (static libraries)
 * is loaded as default component loader.
 *
 * @return OMX_ErrorNone
 */
OSCL_EXPORT_REF OMX_ERRORTYPE OMX_Init()
{
    if (pthread_mutex_lock(&mutex) != 0)
    {
        return OMX_ErrorUndefined;
    }
    if (initialized == 0)
    {
        if (createComponentLoaders())
        {
            DEBUG(DEB_LEV_ERR, "error of %s,OMX_Init is %d\n", __func__, __LINE__);
            xmlflg = 0;
        }
		else
		{
			xmlflg = 1;
		}
    }
	initialized++;
	
    if (pthread_mutex_unlock(&mutex) != 0)
    {
        return OMX_ErrorUndefined;
    }
    ALOGV("Out of %s, initialized = %d", __func__, initialized);
    return OMX_ErrorNone;
}
/** @brief The OMX_Init standard function
 *
 * This function calls the init function of each component loader added. If there
 * is no component loaders present, the ST default component loader (static libraries)
 * is loaded as default component loader.
 *
 * @return OMX_ErrorNone
 */
OMX_ERRORTYPE OMX_Init() {
  int i = 0;
  OMX_ERRORTYPE err = OMX_ErrorNone, errLoader = OMX_ErrorInsufficientResources;

  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);

  /* Get a lock in case multiple thread are calling OMX_Init at the same time */
  tsem_down(&initSem);
  
  if(initialized == 0) {
    
    if (createComponentLoaders()) {
      tsem_up(&initSem);
      return OMX_ErrorInsufficientResources;
    }
    
    for (i = 0; i < bosa_loaders; i++) {
      err = loadersList[i]->BOSA_InitComponentLoader((struct BOSA_COMPONENTLOADER *) loadersList[i]);
      if (err != OMX_ErrorNone) {
	
	DEBUG(DEB_LEV_ERR, "Component loader %d constructor fails. Error= 0x%08x \n",i, err);
	
	/* The loader failed to initialize itself -> discarding it for the session */
	free((void *) loadersList[i]);
	loadersList[i] = 0;
      }
      
      // Returning OMX_ErrorNone if at least one loader has been able to initialize itself
      if (err == OMX_ErrorNone) {
	errLoader = OMX_ErrorNone;
      }
    }
  } else {
    /* In case core already initialized things are fine */
    errLoader = OMX_ErrorNone;
  }
  initialized ++;
  tsem_up(&initSem);
  
  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
  return errLoader;
}