OMX_ERRORTYPE test_OMX_ComponentEnumByRole(OMX_STRING role_name) { OMX_U32 no_of_comp_per_role; OMX_U8 **string_of_comp_per_role; OMX_ERRORTYPE err; int index; DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s\n", __func__); string_of_comp_per_role = malloc (10 * sizeof(OMX_STRING)); for (index = 0; index < 10; index++) { string_of_comp_per_role[index] = malloc(OMX_MAX_STRINGNAME_SIZE); } DEBUG(DEFAULT_MESSAGES, "Getting number of components per role for %s\n", role_name); err = OMX_GetComponentsOfRole(role_name, &no_of_comp_per_role, NULL); if (err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Not able to retrieve the number of components of a given role\n"); DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n", __func__, err); return err; } DEBUG(DEFAULT_MESSAGES, "Number of components per role for %s is %i\n", role_name, (int)no_of_comp_per_role); err = OMX_GetComponentsOfRole(role_name, &no_of_comp_per_role, string_of_comp_per_role); if (err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Not able to retrieve the components of a given role\n"); DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n",__func__, err); return err; } DEBUG(DEFAULT_MESSAGES, " The components are:\n"); for (index = 0; index < no_of_comp_per_role; index++) { DEBUG(DEFAULT_MESSAGES, "%s\n", string_of_comp_per_role[index]); } for (index = 0; index<10; index++) { if(string_of_comp_per_role[index]) { free(string_of_comp_per_role[index]); string_of_comp_per_role[index] = NULL; } } if(string_of_comp_per_role) { free(string_of_comp_per_role); string_of_comp_per_role = NULL; } DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result OMX_ErrorNone\n", __func__); return OMX_ErrorNone; }
OMX_API OMX_ERRORTYPE TIOMX_GetComponentsOfRole(OMX_IN OMX_STRING role, OMX_INOUT OMX_U32 * pNumComps, OMX_INOUT OMX_U8 ** compNames) { ALOGV("TIOMX_GetComponentsOfRole\n"); return OMX_GetComponentsOfRole(role, pNumComps, compNames); }
int Init_Decoder(OMX_STRING audio_component) { DEBUG_PRINT("Inside %s \n", __FUNCTION__); OMX_ERRORTYPE omxresult; OMX_U32 total = 0; typedef OMX_U8* OMX_U8_PTR; char *role ="audio_decoder.aac"; static OMX_CALLBACKTYPE call_back = { &EventHandler,&EmptyBufferDone,&FillBufferDone }; /* Init. the OpenMAX Core */ DEBUG_PRINT("\nInitializing OpenMAX Core....\n"); omxresult = OMX_Init(); if(OMX_ErrorNone != omxresult) { DEBUG_PRINT("\n Failed to Init OpenMAX core"); return -1; } else { DEBUG_PRINT("\nOpenMAX Core Init Done\n"); } /* Query for audio decoders*/ DEBUG_PRINT("Aac_test: Before entering OMX_GetComponentOfRole"); OMX_GetComponentsOfRole(role, &total, 0); DEBUG_PRINT ("\nTotal components of role=%s :%lu", role, total); omxresult = OMX_GetHandle((OMX_HANDLETYPE*)(&aac_dec_handle), (OMX_STRING)audio_component, NULL, &call_back); if (FAILED(omxresult)) { DEBUG_PRINT("\nFailed to Load the component:%s\n", audio_component); return -1; } else { DEBUG_PRINT("\nComponent %s is in LOADED state\n", audio_component); } /* Get the port information */ CONFIG_VERSION_SIZE(portParam); omxresult = OMX_GetParameter(aac_dec_handle, OMX_IndexParamAudioInit, (OMX_PTR)&portParam); if(FAILED(omxresult)) { DEBUG_PRINT("\nFailed to get Port Param\n"); return -1; } else { DEBUG_PRINT("\nportParam.nPorts:%lu\n", portParam.nPorts); DEBUG_PRINT("\nportParam.nStartPortNumber:%lu\n", portParam.nStartPortNumber); } return 0; }
/* static */ bool PureOmxPlatformLayer::FindStandardComponent(const nsACString& aMimeType, nsACString* aComponentName) { nsAutoCString role; if (!GetStandardComponentRole(aMimeType, role)) return false; OMX_U32 nComponents = 0; OMX_ERRORTYPE err; err = OMX_GetComponentsOfRole(const_cast<OMX_STRING>(role.Data()), &nComponents, nullptr); if (err != OMX_ErrorNone || nComponents <= 0) { return false; } if (!aComponentName) { return true; } // TODO: // Only the first component will be used. // We should detect the most preferred component. OMX_U8* componentNames[1]; UniquePtr<OMX_U8[]> componentName; componentName = MakeUniqueFallible<OMX_U8[]>(OMX_MAX_STRINGNAME_SIZE); componentNames[0] = componentName.get(); nComponents = 1; err = OMX_GetComponentsOfRole(const_cast<OMX_STRING>(role.Data()), &nComponents, componentNames); if (err == OMX_ErrorNone) { MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, ("PureOmxPlatformLayer::%s: A component has been found for %s: %s", __func__, aMimeType.Data(), componentNames[0])); aComponentName->Assign(reinterpret_cast<char*>(componentNames[0])); } return err == OMX_ErrorNone; }
int jpege_main(void *Param) { OMX_PARAM_PORTDEFINITIONTYPE asPortDefinition[2]; OMX_PORT_PARAM_TYPE sImageInit; OMX_IMAGE_PARAM_PORTFORMATTYPE sImageParamPortformatType; OMX_CALLBACKTYPE sCallbacks; OMX_IMAGE_PARAM_QFACTORTYPE sImageParamQFacttype; int i = 0, j = 0; OMX_ERRORTYPE err = OMX_ErrorNone; OMX_STATETYPE state = OMX_StateMax; OMX_U32 nQFactor = 0; OMX_S8 **cName; OMX_U32 numComp; char ConfigFileName[256]; OMX_S8 componentName[256]; OMX_VERSIONTYPE componentVer; OMX_VERSIONTYPE specVer; OMX_UUIDTYPE componentUUID; void *InputPortRet, *OutputPortRet, *OutputDataRet; memset(asPortDefinition, 0, sizeof(asPortDefinition)); memset(&sImageInit, 0, sizeof(sImageInit)); memset(&sImageParamPortformatType, 0, sizeof(sImageParamPortformatType)); memset(&sCallbacks, 0, sizeof(sCallbacks)); output_mode = ((VIDEODECFUNCPARAMTYPE *) Param)->Mode; nFrameWidth = ((VIDEODECFUNCPARAMTYPE *) Param)->nFrameWidth; nFrameHeight = ((VIDEODECFUNCPARAMTYPE *) Param)->nFrameHeight; eColorFormat = ((VIDEODECFUNCPARAMTYPE *) Param)->eColorFormat; nQFactor = ((VIDEODECFUNCPARAMTYPE *) Param)->nQFactor; int ret = 0, hasHandle = 0, commandValue = 0, hasNoWait = 1; /* */ ef = ff = 0; if ((frameSize = yuv_framesize(nFrameWidth, nFrameHeight, eColorFormat)) <= 0) { FILE_DBG1("[emxx_jpeglib][%d] yuv_init\n", __LINE__); return -1; } strcpy(ConfigFileName, AV_CODEC_CONFIG_FILE_NAME); err = OMF_SetLogMode(0x00000001); if (err != OMX_ErrorNone) { FILE_DBG1("[emxx_jpeglib] Can't set log mode! error code = 0x%08x\n", err); goto jpege_end; } err = OMF_SetConfiguration(ConfigFileName); if (err != OMX_ErrorNone) { FILE_DBG1("[emxx_jpeglib] Can't set configuration file! error code = 0x%08x\n", err); goto jpege_end; } err = OMX_Init(); if (err != OMX_ErrorNone) { FILE_DBG("can't initialize OMX LIb, exit\n"); goto jpege_end; } /* Get MC Name */ cName = (OMX_U8 **) malloc(sizeof(OMX_U8 *)); cName[0] = (OMX_U8 *) malloc(128 * sizeof(OMX_U8)); numComp = 1; err = OMX_GetComponentsOfRole(JPEGE_ROLE, &numComp, cName); if (err != OMX_ErrorNone) { FILE_DBG1("[emxx_jpeglib] Can't get component name! error code = 0x%8x\n", err); } else { FILE_DBG1("OMF Name = %s\n", cName[0]); } /* Get Media Component handle. */ sCallbacks.EventHandler = event_handler; sCallbacks.EmptyBufferDone = empty_buffer_done; sCallbacks.FillBufferDone = fill_buffer_done; err = OMX_GetHandle(&Video_hComponent, cName[0], NULL, &sCallbacks); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't get handle! erro code = 0x%08x\n", __LINE__, err); free(cName[0]); free(cName); ret = -1; goto jpege_end; } hasHandle = 1; free(cName[0]); free(cName); /* GetComponentVersion */ err = OMX_GetComponentVersion(Video_hComponent, componentName, &componentVer, &specVer, &componentUUID); if (err != OMX_ErrorNone) { FILE_DBG2( "[emxx_jpeglib][%d] Can't get component version! error code = 0x%08x\n", __LINE__, err); return -1; } else { printf("Component Version = 0x%08x\n", componentVer); printf("Spec Version = 0x%08x\n", specVer); } /* Get OMX_IndexParamImageInit. */ sImageInit.nSize = sizeof(OMX_PORT_PARAM_TYPE); err = OMX_GetParameter(Video_hComponent, OMX_IndexParamImageInit, &sImageInit); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't get parameter! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } /* Get & Set OMX_IndexParamPortDefinition. */ for (i = 0; i < sImageInit.nPorts; i++) { asPortDefinition[i].nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); asPortDefinition[i].nPortIndex = sImageInit.nStartPortNumber + i; err = OMX_GetParameter(Video_hComponent, OMX_IndexParamPortDefinition, &asPortDefinition[i]); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't get parameter! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } if (i == PORT_OFFSET_INPUT) /* VPB+0 */ { asPortDefinition[PORT_OFFSET_INPUT].format.image.nFrameWidth = nFrameWidth; asPortDefinition[PORT_OFFSET_INPUT].format.image.nFrameHeight = nFrameHeight; asPortDefinition[PORT_OFFSET_INPUT].format.image.eColorFormat = eColorFormat; err = OMX_SetParameter(Video_hComponent, OMX_IndexParamPortDefinition, &asPortDefinition[PORT_OFFSET_INPUT]); if (err != OMX_ErrorNone) { extern int end_flag; printf( "[emxx_jpeglib][%d] Can't set parameter! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } } } nVideoPortIndex[PORT_OFFSET_INPUT] = asPortDefinition[PORT_OFFSET_INPUT].nPortIndex; nVideoPortIndex[PORT_OFFSET_OUTPUT] = asPortDefinition[PORT_OFFSET_OUTPUT].nPortIndex; VideoInputBuffNum = asPortDefinition[PORT_OFFSET_INPUT].nBufferCountActual; VideoOutputBuffNum = asPortDefinition[PORT_OFFSET_OUTPUT].nBufferCountActual; printf("VideoInputBuffNum, %d VideoOutputBuffNum, %d\n", VideoInputBuffNum, VideoOutputBuffNum); /* Get & Set OMX_IndexParamImagePortFormat. */ sImageParamPortformatType.nSize = sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE); sImageParamPortformatType.nPortIndex = PORT_OFFSET_INPUT; sImageParamPortformatType.nIndex = nVideoPortIndex[PORT_OFFSET_INPUT]; err = OMX_GetParameter(Video_hComponent, OMX_IndexParamImagePortFormat, &sImageParamPortformatType); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't get parameter! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } sImageParamPortformatType.nSize = sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE); sImageParamPortformatType.eColorFormat = eColorFormat; err = OMX_SetParameter(Video_hComponent, OMX_IndexParamImagePortFormat, &sImageParamPortformatType); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't get parameter! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } /* Change state to OMX_StateIdle from OMX_StateLoaded. */ pthread_mutex_lock(&VideoMutex); err = OMX_SendCommand(Video_hComponent, OMX_CommandStateSet, OMX_StateIdle, NULL); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't send command! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } /* Allocate stream buffer. */ for (i = 0; i < sImageInit.nPorts; i++) { for (j = 0; j < asPortDefinition[i].nBufferCountActual; j++) { err = OMX_AllocateBuffer(Video_hComponent, &apsVideoBuffer[i][j], asPortDefinition[i].nPortIndex, NULL, asPortDefinition[i].nBufferSize); if (err != OMX_ErrorNone) { FILE_DBG2( "[emxx_jpeglib][%d] Can't allocate buffer! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } FILE_DBG2("[%d][%d] allocated\n", i, j); } } /* Complete state transition. */ pthread_cond_wait(&VideoCond, &VideoMutex); pthread_mutex_unlock(&VideoMutex); semaphore_init(CODEC_VIDEO, output_mode); #if 1 /* Create data input thread. */ if (pthread_create(&VideoInputThreadId, NULL, (void*) jpeg_input_port_thread, NULL) != 0) { FILE_DBG1("[emxx_jpeglib][%d] failed pthread_create input_port_thread\n", __LINE__); ret = -1; goto jpege_end; } /* Create data output thread. */ if (pthread_create(&VideoOutputThreadId, NULL, (void*) jpeg_output_port_thread, NULL) != 0) { FILE_DBG1("[emxx_jpeglib][%d] failed output_port_thread\n", __LINE__); ret = -1; goto jpege_end; } /* Create data output thread */ if (pthread_create(&VideoOutputDataThreadId, NULL, (void*) jpeg_output_data_thread, NULL) != 0) { FILE_DBG1("[emxx_jpeglib][%d] pthread_create output_data_thread\n", __LINE__); ret = -1; goto jpege_end; } #endif /* Change state to OMX_StateExecuting form OMX_StateIdle. */ pthread_mutex_lock(&VideoMutex); err = OMX_SendCommand(Video_hComponent, OMX_CommandStateSet, OMX_StateExecuting, NULL); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't send command! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } /* Complete state transition. */ pthread_cond_wait(&VideoCond, &VideoMutex); pthread_mutex_unlock(&VideoMutex); FILE_DBG("state has been changed to executing\n"); VideoOutputPortThreadLoopFlag = 1; while (!ef || !ff) { printf("."); } FILE_DBG("start close OMX\n"); hasNoWait = 0; VideoOutputPortThreadLoopFlag = 0; pthread_mutex_lock(&VideoMutex); err = OMX_SendCommand(Video_hComponent, OMX_CommandStateSet, OMX_StateIdle, NULL); if (err != OMX_ErrorNone) { FILE_DBG("can't send command\n"); ret = -1; goto jpege_end; } pthread_cond_wait(&VideoCond, &VideoMutex); pthread_mutex_unlock(&VideoMutex); /* Change state to OMX_StateLoaded from OMX_StateIdle. */ pthread_mutex_lock(&VideoMutex); err = OMX_SendCommand(Video_hComponent, OMX_CommandStateSet,OMX_StateLoaded, NULL); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't send command! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } FILE_DBG("changed to loaded state\n"); /* Free buffer. */ for (i = 0; i < sImageInit.nPorts; i++) { for (j = 0; j < asPortDefinition[i].nBufferCountActual; j++) { err = OMX_FreeBuffer(Video_hComponent, asPortDefinition[i].nPortIndex, apsVideoBuffer[i][j]); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't free buffer! erro code = 0x%08x\n", __LINE__, err); ret = -1; goto jpege_end; } } } /* Complete state transition. */ pthread_cond_wait(&VideoCond, &VideoMutex); pthread_mutex_unlock(&VideoMutex); jpege_end: FILE_DBG("free buffer\n"); /* Free JPEG Media Component handle. */ if (hasHandle) { err = OMX_FreeHandle(Video_hComponent); if (err != OMX_ErrorNone) { FILE_DBG2("[emxx_jpeglib][%d] Can't free handle! erro code = 0x%08x\n", __LINE__, err); ret = -1; } } semaphore_deinit(CODEC_VIDEO, output_mode); FILE_DBG("close debug file"); FILE_DBG_CLOSE(); return 0; }