OMX_ERRORTYPE load_component(HTEST *hTest) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_HANDLETYPE hComponent = NULL; OMX_PARAM_PORTDEFINITIONTYPE sPortDef; OMX_U32 i; ret = OMX_GetHandle(&hComponent, hTest->name, hTest, &gCallBacks); if(ret != OMX_ErrorNone) { printf("Load component %s failed.\n", hTest->name); return ret; } hTest->hComponent = (OMX_COMPONENTTYPE*)hComponent; hTest->nPorts = get_component_ports(hComponent); OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); for(i=0; i<hTest->nPorts; i++) { sPortDef.nPortIndex = i; OMX_GetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); if (sPortDef.eDomain == OMX_PortDomainAudio) hTest->nAudioTrackNum = i; if (sPortDef.eDomain == OMX_PortDomainVideo) hTest->nVideoTrackNum = i; hTest->PortDir[i] = sPortDef.eDir; if(hTest->PortDir[i] == OMX_DirInput) hTest->bAllocater[i] = OMX_FALSE; if(hTest->PortDir[i] == OMX_DirOutput) hTest->bAllocater[i] = OMX_TRUE; } OMX_PARAM_CONTENTURITYPE *content = NULL; content =(OMX_PARAM_CONTENTURITYPE *) fsl_osal_malloc_new(sizeof(OMX_PARAM_CONTENTURITYPE) + 1024); if (!content) return OMX_ErrorInsufficientResources; fsl_osal_memset(content, 0 , sizeof(OMX_PARAM_CONTENTURITYPE)+1024); OMX_INIT_STRUCT(content,OMX_PARAM_CONTENTURITYPE); char* uri = (char*)&(content->contentURI); fsl_osal_memcpy(uri, hTest->media_name, strlen(hTest->media_name)+1); ret = OMX_SetParameter(hTest->hComponent,OMX_IndexParamContentURI,content); if (ret != OMX_ErrorNone) { OMX_FreeHandle(hTest->hComponent); hTest->hComponent = NULL; return ret; } fsl_osal_thread_create(&hTest->pThreadId, NULL, process_thread, hTest); return OMX_ErrorNone; }
OMX_ERRORTYPE load_component(HTEST *hTest) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_HANDLETYPE hComponent = NULL; OMX_PARAM_PORTDEFINITIONTYPE sPortDef; OMX_U32 i; ret = OMX_GetHandle(&hComponent, hTest->name, hTest, &gCallBacks); if(ret != OMX_ErrorNone) { printf("Load component %s failed.\n", hTest->name); return ret; } hTest->hComponent = (OMX_COMPONENTTYPE*)hComponent; OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); sPortDef.nPortIndex = 1; ret = OMX_GetParameter(hTest->hComponent,OMX_IndexParamPortDefinition,&sPortDef); if (ret != OMX_ErrorNone) return ret; sPortDef.format.video.nFrameWidth = 176; sPortDef.format.video.nFrameHeight = 144; ret = OMX_SetParameter(hTest->hComponent,OMX_IndexParamPortDefinition,&sPortDef); if (ret != OMX_ErrorNone) return ret; sPortDef.nPortIndex = 0; ret = OMX_SetParameter(hTest->hComponent,OMX_IndexParamPortDefinition,&sPortDef); if (ret != OMX_ErrorNone) return ret; hTest->nPorts = get_component_ports(hComponent); OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); for(i=0; i<hTest->nPorts; i++) { sPortDef.nPortIndex = i; OMX_GetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); if (sPortDef.eDomain == OMX_PortDomainAudio) hTest->nAudioTrackNum = i; if (sPortDef.eDomain == OMX_PortDomainVideo) hTest->nVideoTrackNum = i; hTest->PortDir[i] = sPortDef.eDir; if(hTest->PortDir[i] == OMX_DirInput) hTest->bAllocater[i] = OMX_FALSE; if(hTest->PortDir[i] == OMX_DirOutput) hTest->bAllocater[i] = OMX_TRUE; if(i == 0) hTest->bAllocater[i] = OMX_FALSE; } fsl_osal_thread_create(&hTest->pThreadId, NULL, process_thread, hTest); return OMX_ErrorNone; }
OMX_ERRORTYPE load_components(HTEST *hTest) { OMX_U32 i; for(i=0; i<hTest->nComponents; i++) load_component(hTest, i); hTest->eState = OMX_StateLoaded; fsl_osal_thread_create(&hTest->pThreadId, NULL, process_thread, hTest); return OMX_ErrorNone; }
OMX_ERRORTYPE GMSubtitlePlayer::Init() { if(fsl_osal_sem_init(&pSem, 0, 0) != E_FSL_OSAL_SUCCESS) { LOG_ERROR("Failed to create semphore for subtitle thread.\n"); return OMX_ErrorInsufficientResources; } if(E_FSL_OSAL_SUCCESS != fsl_osal_cond_create(&Cond)) { LOG_ERROR("Create condition variable for subtitle thread.\n"); return OMX_ErrorInsufficientResources; } if(E_FSL_OSAL_SUCCESS != fsl_osal_thread_create(&pThread, NULL, GMSubtitlePlayer::ThreadFunc, this)) { LOG_ERROR("Failed to create subtitle thread.\n"); return OMX_ErrorInsufficientResources; } fsl_osal_memset(&delayedSample, 0, sizeof(delayedSample)); delayedSample.nFilledLen = -1; return OMX_ErrorNone; }
OMX_ERRORTYPE load_component(HTEST *hTest) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_HANDLETYPE hComponent = NULL; OMX_PARAM_PORTDEFINITIONTYPE sPortDef; OMX_U32 i; ret = OMX_GetHandle(&hComponent, hTest->name, hTest, &gCallBacks); if(ret != OMX_ErrorNone) { printf("Load component %s failed.\n", hTest->name); return ret; } OMX_PARAM_COMPONENTROLETYPE CurRole; OMX_INIT_STRUCT(&CurRole, OMX_PARAM_COMPONENTROLETYPE); fsl_osal_memcpy(&CurRole.cRole, hTest->role, OMX_MAX_STRINGNAME_SIZE); OMX_SetParameter(hComponent, OMX_IndexParamStandardComponentRole, &CurRole); hTest->hComponent = (OMX_COMPONENTTYPE*)hComponent; hTest->nPorts = get_component_ports(hComponent); OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); for(i=0; i<hTest->nPorts; i++) { sPortDef.nPortIndex = i; OMX_GetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); hTest->PortDir[i] = sPortDef.eDir; if(hTest->PortDir[i] == OMX_DirInput) hTest->bAllocater[i] = OMX_FALSE; //in buffer allocated by client if(hTest->PortDir[i] == OMX_DirOutput) hTest->bAllocater[i] = OMX_TRUE; // out buffer allocated by component } fsl_osal_thread_create(&hTest->pThreadId, NULL, process_thread, hTest); printf("Load component %s done.\n", hTest->name); return OMX_ErrorNone; }
OMX_ERRORTYPE load_component(HTEST *hTest) { OMX_ERRORTYPE ret = OMX_ErrorNone; OMX_HANDLETYPE hComponent = NULL; OMX_PARAM_PORTDEFINITIONTYPE sPortDef; OMX_U32 i; ret = OMX_GetHandle(&hComponent, hTest->name, hTest, &gCallBacks); if(ret != OMX_ErrorNone) { printf("Load component %s failed.\n", hTest->name); return ret; } OMX_PARAM_COMPONENTROLETYPE CurRole; OMX_INIT_STRUCT(&CurRole, OMX_PARAM_COMPONENTROLETYPE); fsl_osal_memcpy(&CurRole.cRole, hTest->role, OMX_MAX_STRINGNAME_SIZE); OMX_SetParameter(hComponent, OMX_IndexParamStandardComponentRole, &CurRole); OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); sPortDef.nPortIndex = 0; OMX_GetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); sPortDef.format.video.nFrameWidth = hTest->width; sPortDef.format.video.nFrameHeight = hTest->height; sPortDef.format.video.xFramerate = 30 * Q16_SHIFT; sPortDef.nBufferSize = hTest->width * hTest->height * 3 / 2; OMX_SetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); OMX_VIDEO_PARAM_BITRATETYPE sBitrate; OMX_S32 gm_video_bitRate = hTest->bitrate; OMX_INIT_STRUCT(&sBitrate, OMX_VIDEO_PARAM_BITRATETYPE); sBitrate.nPortIndex = 1; OMX_GetParameter(hComponent, OMX_IndexParamVideoBitrate, &sBitrate); sBitrate.eControlRate = OMX_Video_ControlRateConstant; sBitrate.nTargetBitrate = gm_video_bitRate; OMX_SetParameter(hComponent, OMX_IndexParamVideoBitrate, &sBitrate); OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); sPortDef.nPortIndex = 1; OMX_GetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); sPortDef.format.video.nBitrate = gm_video_bitRate; OMX_SetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); hTest->hComponent = (OMX_COMPONENTTYPE*)hComponent; hTest->nPorts = get_component_ports(hComponent); OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE); for(i=0; i<hTest->nPorts; i++) { sPortDef.nPortIndex = i; OMX_GetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef); hTest->PortDir[i] = sPortDef.eDir; if(hTest->PortDir[i] == OMX_DirInput) hTest->bAllocater[i] = OMX_TRUE; //in buffer allocated by vpu component if(hTest->PortDir[i] == OMX_DirOutput) hTest->bAllocater[i] = OMX_TRUE; // out buffer allocated by component } fsl_osal_thread_create(&hTest->pThreadId, NULL, process_thread, hTest); printf("Load component %s done.\n", hTest->name); return OMX_ErrorNone; }