ret_code_t ilcore_init_comp(ilcore_comp_h *h, OMX_CALLBACKTYPE *cb, char *name) { OMX_ERRORTYPE err; ilcore_comp_ctx_t *ctx; ctx = (ilcore_comp_ctx_t *)malloc(sizeof(ilcore_comp_ctx_t)); if (!ctx) { DBG_E("Memory allocation failed\n"); return L_FAILED; } memset(ctx, 0, sizeof(ilcore_comp_ctx_t)); slist_init(&ctx->event_list); msleep_init(&ctx->event_sleep); ctx->name = strdup(name); if (!ctx->name) { DBG_E("strdup failed\n"); return L_FAILED; } err = OMX_GetHandle(&ctx->handle, name, ctx, cb); if (err != OMX_ErrorNone) { DBG_E("OMX_GetHandle failed. err=%d\n", err); return L_FAILED; } *h = ctx; return L_OK; }
OMX_ERRORTYPE PureOmxPlatformLayer::CreateComponent(const nsACString* aComponentName) { nsAutoCString componentName; if (aComponentName) { componentName = *aComponentName; } else if (!FindStandardComponent(mInfo->mMimeType, &componentName)) { return OMX_ErrorComponentNotFound; } OMX_ERRORTYPE err; err = OMX_GetHandle(&mComponent, const_cast<OMX_STRING>(componentName.Data()), this, &sCallbacks); const char* mime = mInfo->mMimeType.Data(); if (err == OMX_ErrorNone) { LOG("Succeeded to create the component for %s", mime); } else { LOG("Failed to create the component for %s: 0x%08x", mime, err); } return err; }
END_TEST START_TEST (test_ilcore_init_and_deinit_get_hdl_free_hdl) { OMX_ERRORTYPE error = OMX_ErrorNone; OMX_HANDLETYPE p_hdl = NULL; OMX_U32 appData; OMX_CALLBACKTYPE callBacks; error = OMX_Init (); fail_if (error != OMX_ErrorNone); error = OMX_GetHandle (&p_hdl, TIZ_CORE_TEST_COMPONENT_NAME, (OMX_PTR *) (&appData), &callBacks); TIZ_LOG (TIZ_PRIORITY_TRACE, "OMX_GetHandle error [%s]", tiz_err_to_str (error)); fail_if (error != OMX_ErrorNone); TIZ_LOG (TIZ_PRIORITY_TRACE, "p_hdl [%p]", p_hdl); error = OMX_FreeHandle (p_hdl); fail_if (error != OMX_ErrorNone); error = OMX_Deinit (); fail_if (error != OMX_ErrorNone); }
OMX_ERRORTYPE omx_init_component(struct omx_pipeline_t* pipe, struct omx_component_t* component, char* compname) { memset(component,0,sizeof(struct omx_component_t)); pthread_mutex_init(&component->cmd_queue_mutex, NULL); pthread_cond_init(&component->cmd_queue_count_cv,NULL); component->buf_notempty = 1; pthread_cond_init(&component->buf_notempty_cv,NULL); pthread_cond_init(&component->eos_cv,NULL); pthread_mutex_init(&component->eos_mutex,NULL); component->callbacks.EventHandler = omx_event_handler; component->callbacks.EmptyBufferDone = omx_empty_buffer_done; component->callbacks.FillBufferDone = omx_fill_buffer_done; component->pipe = pipe; component->name = compname; /* Create OMX component */ OERR(OMX_GetHandle(&component->h, compname, component, &component->callbacks)); /* Disable all ports */ omx_disable_all_ports(component); }
/** mm_jpegdec_session_create: * * Arguments: * @p_session: job session * * Return: * OMX error types * * Description: * Create a jpeg encode session * **/ OMX_ERRORTYPE mm_jpegdec_session_create(mm_jpeg_job_session_t* p_session) { OMX_ERRORTYPE rc = OMX_ErrorNone; pthread_mutex_init(&p_session->lock, NULL); pthread_cond_init(&p_session->cond, NULL); cirq_reset(&p_session->cb_q); p_session->state_change_pending = OMX_FALSE; p_session->abort_state = MM_JPEG_ABORT_NONE; p_session->error_flag = OMX_ErrorNone; p_session->ebd_count = 0; p_session->fbd_count = 0; p_session->encode_pid = -1; p_session->config = OMX_FALSE; p_session->omx_callbacks.EmptyBufferDone = mm_jpegdec_ebd; p_session->omx_callbacks.FillBufferDone = mm_jpegdec_fbd; p_session->omx_callbacks.EventHandler = mm_jpegdec_event_handler; p_session->exif_count_local = 0; rc = OMX_GetHandle(&p_session->omx_handle, "OMX.qcom.image.jpeg.decoder", (void *)p_session, &p_session->omx_callbacks); if (OMX_ErrorNone != rc) { CDBG_ERROR("%s:%d] OMX_GetHandle failed (%d)", __func__, __LINE__, rc); return rc; } return rc; }
/* detect the compliance profile(s) that the component is eligible for */ OMX_U32 DetectComplianceProfile(OMX_STRING sArgument) { OMX_U32 detectedCompliance; OMX_HANDLETYPE hThread, hComp, hTTC; OMX_CALLBACKTYPE oDummyCallbacks; OMX_TIME_CONFIG_TIMESTAMPTYPE oTimeStamp; OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE oRefClock; detectedCompliance = OMX_CONF_TestFlag_Base|OMX_CONF_TestFlag_AutoOutput; /* try to create a thread -> implies threading compliance */ if (OMX_ErrorNone == OMX_OSAL_ThreadCreate( DummyThreadFunction, 0, 0, &hThread)){ if (OMX_ErrorNone == OMX_OSAL_ThreadDestroy( hThread)){ detectedCompliance |= OMX_CONF_TestFlag_Threaded; } } oDummyCallbacks.EmptyBufferDone = StubbedEmptyBufferDone; oDummyCallbacks.FillBufferDone = StubbedFillBufferDone; oDummyCallbacks.EventHandler = StubbedEventHandler; if (OMX_ErrorNone != OMX_Init()){ return 0; } if (OMX_ErrorNone != OMX_GetHandle(&hComp, sArgument, NULL, &oDummyCallbacks)){ OMX_Deinit(); return 0; } if (OMX_ErrorNone != OMX_CONF_GetTunnelTestComponentHandle(&hTTC, NULL, &oDummyCallbacks)){ OMX_FreeHandle(hComp); OMX_Deinit(); return 0; } if (OMX_ErrorNone == OMX_CONF_TTCConnectAllPorts(hTTC, hComp)) { INIT_PARAM(oRefClock); INIT_PARAM(oTimeStamp); oTimeStamp.nPortIndex = 0; detectedCompliance |= OMX_CONF_TestFlag_Interop; /* try to set active ref clock -> implies clock component compliance */ if (OMX_ErrorUnsupportedIndex != OMX_SetConfig(hComp, OMX_IndexConfigTimeActiveRefClock, &oRefClock)){ detectedCompliance &= ~OMX_CONF_TestFlag_AutoOutput; /* only clock component doesn't have autooutput */ detectedCompliance |= OMX_CONF_TestFlag_ClockComp; } /* try to set time position -> implies seeking compliance */ if (OMX_ErrorUnsupportedIndex != OMX_SetConfig(hComp, OMX_IndexConfigTimePosition, &oTimeStamp)){ detectedCompliance |= OMX_CONF_TestFlag_Seeking; } } OMX_CONF_FreeTunnelTestComponentHandle(hTTC); OMX_FreeHandle(hComp); OMX_Deinit(); return detectedCompliance; }
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; }
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_API OMX_ERRORTYPE TIOMX_GetHandle(OMX_OUT OMX_HANDLETYPE * pHandle, OMX_IN OMX_STRING cComponentName, OMX_IN OMX_PTR pAppData, OMX_IN OMX_CALLBACKTYPE * pCallBacks) { ALOGV("TIOMX_GetHandle\n"); return OMX_GetHandle(pHandle, cComponentName, pAppData, pCallBacks); }
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; }
void AnatomyOMXClient::init() { OMX_HANDLETYPE handle = NULL; char componentName[256]; OMX_Init(); OMX_ComponentNameEnum(componentName, 256, 0); OMX_GetHandle(&handle, componentName, this, &AnatomyOMXClient::kCallbacks); CHECK(handle != NULL); mComponentHandle = handle; }
void componentLoad(OMX_CALLBACKTYPE* pCallbackOMX) { OMX_ERRORTYPE err; // Loading component print_log("Load %s", COMPONENT_CAMERA); if((err = OMX_GetHandle(&mContext.pCamera, COMPONENT_CAMERA, &mContext, pCallbackOMX)) != OMX_ErrorNone ) { print_omx_error(err, "FAIL"); terminate(); exit(-1); } print_log("Handler address : 0x%08x", mContext.pCamera); print_log("Load %s", COMPONENT_RENDER); if((err = OMX_GetHandle(&mContext.pRender, COMPONENT_RENDER, &mContext, pCallbackOMX)) != OMX_ErrorNone ) { print_omx_error(err, "FAIL"); terminate(); exit(-1); } print_log("Handler address : 0x%08x", mContext.pRender); }
OMX_ERRORTYPE test_OpenClose(OMX_STRING component_name) { OMX_ERRORTYPE err = OMX_ErrorNone; DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s\n",__func__); err = OMX_GetHandle(&appPriv->audiosrchandle, component_name, NULL, &audiosrccallbacks); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "No component found\n"); } else { err = OMX_FreeHandle(appPriv->audiosrchandle); } DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n", __func__, err); return err; }
void NonTextureEngine::setup(OMXCameraSettings& omxCameraSettings) { this->omxCameraSettings = omxCameraSettings; if (omxCameraSettings.doRecordingPreview) { //validate the settings omxCameraSettings.enablePreview(); } OMX_ERRORTYPE error = OMX_ErrorNone; OMX_CALLBACKTYPE cameraCallbacks; cameraCallbacks.EventHandler = &NonTextureEngine::cameraEventHandlerCallback; string cameraComponentName = "OMX.broadcom.camera"; error = OMX_GetHandle(&camera, (OMX_STRING)cameraComponentName.c_str(), this , &cameraCallbacks); if(error != OMX_ErrorNone) { ofLog(OF_LOG_ERROR, "camera OMX_GetHandle FAIL error: 0x%08x", error); } configureCameraResolution(); if (omxCameraSettings.doRecording && omxCameraSettings.doRecordingPreview) { OMX_PARAM_PORTDEFINITIONTYPE cameraPreviewPortDefinition; OMX_INIT_STRUCTURE(cameraPreviewPortDefinition); cameraPreviewPortDefinition.nPortIndex = CAMERA_PREVIEW_PORT; error = OMX_GetParameter(camera, OMX_IndexParamPortDefinition, &cameraPreviewPortDefinition); if(error != OMX_ErrorNone) { ofLog(OF_LOG_ERROR, "cameraPreviewPortDefinition OMX_GetParameter OMX_IndexParamPortDefinition FAIL error: 0x%08x", error); } cameraPreviewPortDefinition.format.video.nFrameWidth = omxCameraSettings.previewWidth; cameraPreviewPortDefinition.format.video.nFrameHeight = omxCameraSettings.previewHeight; cameraPreviewPortDefinition.format.video.nStride = omxCameraSettings.previewWidth; error = OMX_SetParameter(camera, OMX_IndexParamPortDefinition, &cameraPreviewPortDefinition); if(error != OMX_ErrorNone) { ofLog(OF_LOG_ERROR, "cameraPreviewPortDefinition OMX_SetParameter OMX_IndexParamPortDefinition FAIL error: 0x%08x", error); } } }
omx_component_t * omx_component_create(const char *name, hts_mutex_t *mtx, hts_cond_t *avail_cond) { omx_component_t *oc = calloc(1, sizeof(omx_component_t)); OMX_CALLBACKTYPE cb; const OMX_INDEXTYPE types[] = {OMX_IndexParamAudioInit, OMX_IndexParamVideoInit, OMX_IndexParamImageInit, OMX_IndexParamOtherInit}; assert(mtx != NULL); oc->oc_mtx = mtx; oc->oc_avail_cond = avail_cond; hts_cond_init(&oc->oc_event_cond, oc->oc_mtx); oc->oc_name = strdup(name); cb.EventHandler = oc_event_handler; cb.EmptyBufferDone = oc_empty_buffer_done; cb.FillBufferDone = oc_fill_buffer_done; // omxdbg("Creating %s\n", oc->oc_name); omxchk(OMX_GetHandle(&oc->oc_handle, oc->oc_name, oc, &cb)); // Initially disable ports int i; for(i = 0; i < 4; i++) { OMX_PORT_PARAM_TYPE ports; ports.nSize = sizeof(OMX_PORT_PARAM_TYPE); ports.nVersion.nVersion = OMX_VERSION; omxchk(OMX_GetParameter(oc->oc_handle, types[i], &ports)); omxdbg("%s: type:%d: ports: %d +%d\n", name, i, ports.nStartPortNumber, ports.nPorts); if(ports.nPorts > 0) { oc->oc_inport = ports.nStartPortNumber; oc->oc_outport = ports.nStartPortNumber + 1; } for(int j = 0; j < ports.nPorts; j++) omx_send_command(oc, OMX_CommandPortDisable, ports.nStartPortNumber + j, NULL, 1); } return oc; }
bool Component::init( std::string& component_name, OMX_INDEXTYPE index) { componentName = component_name; callbacks.EventHandler = &Component::EventHandlerCallback; callbacks.EmptyBufferDone = &Component::EmptyBufferDoneCallback; callbacks.FillBufferDone = &Component::FillBufferDoneCallback; // Get video component handle setting up callbacks, component is in loaded state on return. OMX_ERRORTYPE error = OMX_GetHandle(&handle, (char*)component_name.c_str(), this, &callbacks); OMX_TRACE(error); if (error != OMX_ErrorNone) { ofLogError(__func__) << componentName << " FAIL "; return false; } OMX_PORT_PARAM_TYPE port_param; OMX_INIT_STRUCTURE(port_param); error = OMX_GetParameter(handle, index, &port_param); OMX_TRACE(error); disableAllPorts(); inputPort = port_param.nStartPortNumber; outputPort = inputPort + 1; if(componentName == "OMX.broadcom.audio_mixer") { inputPort = 232; outputPort = 231; } if (outputPort > port_param.nStartPortNumber+port_param.nPorts-1) { outputPort = port_param.nStartPortNumber+port_param.nPorts-1; } return true; }
static gboolean goo_ti_clock_load (GooComponent* self) { GOO_OBJECT_LOCK (self); RETURN_GOO_RUN ( OMX_GetHandle (&self->handle, self->id, self, &self->callbacks) ); GOO_RUN ( OMX_GetState (self->handle, &self->cur_state) ); GOO_OBJECT_UNLOCK (self); GOO_OBJECT_DEBUG (self, ""); return TRUE; }
OMX_ERRORTYPE ResourceExhaustionTest_LOAD(ResourceExhaustionTestContext *pCtxt, OMX_STRING cComponentName, OMX_PTR pWAppData, OMX_PTR pWCallbacks) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_STATETYPE eState; eError = OMX_GetHandle(&pCtxt->hComp[pCtxt->nInst], cComponentName, pWAppData, pWCallbacks); OMX_CONF_BAIL_IF_ERROR(eError); eError = OMX_CONF_ComponentTracerCreate(pCtxt->hComp[pCtxt->nInst], cComponentName, &pCtxt->hWComp[pCtxt->nInst]); OMX_CONF_BAIL_IF_ERROR(eError); eError = OMX_GetState(pCtxt->hWComp[pCtxt->nInst], &eState); OMX_CONF_BAIL_IF_ERROR(eError); if (eState != OMX_StateLoaded) OMX_CONF_SET_ERROR_BAIL("Not in loaded state\n", OMX_ErrorUndefined); OMX_CONF_TEST_BAIL: return eError; }
CComponent::CComponent(std::string sName, CGraph* pGraph) : m_sName(std::move(sName)), m_hComponent(NULL), m_pGraph(pGraph) { std::string sStateChangedEventName(m_sName); sStateChangedEventName.append(":state_changed_event"); CHECK_VCOS(vcos_event_create(&m_StateChangedEvent, sStateChangedEventName.c_str()), "failed to create vcos event"); std::string sEventThreadName(m_sName); sEventThreadName.append(":event_thread"); m_EventThread.Start(&CComponent::EventThreadProc, this, sEventThreadName.c_str()); std::string sEventQueueMutexName(m_sName); sEventQueueMutexName.append(":event_queue_mutex"); vcos_mutex_create(&m_EventQueueMutex, sEventThreadName.c_str()); OMX_CALLBACKTYPE Callbacks; Callbacks.EventHandler = &CComponent::EventHandler; Callbacks.EmptyBufferDone = &CComponent::EmptyBufferDone; Callbacks.FillBufferDone = &CComponent::FillBufferDone; std::string sError("failed to create component "); sError.append(m_sName); CHECK_OMX(OMX_GetHandle(&m_hComponent, const_cast<char*>(m_sName.c_str()), this, &Callbacks), sError.c_str()); }
static void init_component_handle( const char *name, OMX_HANDLETYPE* hComponent, OMX_PTR pAppData, OMX_CALLBACKTYPE* callbacks) { OMX_ERRORTYPE r; char fullname[32]; // Get handle memset(fullname, 0, sizeof(fullname)); strcat(fullname, "OMX.broadcom."); strncat(fullname, name, strlen(fullname) - 1); //say("Initializing component %s", fullname); if((r = OMX_GetHandle(hComponent, fullname, pAppData, callbacks)) != OMX_ErrorNone) { omx_die(r, "Failed to get handle for component %s", fullname); } // Disable ports OMX_INDEXTYPE types[] = { OMX_IndexParamAudioInit, OMX_IndexParamVideoInit, OMX_IndexParamImageInit, OMX_IndexParamOtherInit }; OMX_PORT_PARAM_TYPE ports; OMX_INIT_STRUCTURE(ports); OMX_GetParameter(*hComponent, OMX_IndexParamVideoInit, &ports); int i; for(i = 0; i < 4; i++) { if(OMX_GetParameter(*hComponent, types[i], &ports) == OMX_ErrorNone) { OMX_U32 nPortIndex; for(nPortIndex = ports.nStartPortNumber; nPortIndex < ports.nStartPortNumber + ports.nPorts; nPortIndex++) { //say("Disabling port %d of component %s", nPortIndex, fullname); if((r = OMX_SendCommand(*hComponent, OMX_CommandPortDisable, nPortIndex, NULL)) != OMX_ErrorNone) { omx_die(r, "Failed to disable port %d of component %s", nPortIndex, fullname); } block_until_port_changed(*hComponent, nPortIndex, OMX_FALSE); } } } }
omxil_comp::omxil_comp(const char *comp_name) : comp(nullptr), state_done(OMX_StateInvalid) { char namebuf[OMX_MAX_STRINGNAME_SIZE] = ""; OMX_ERRORTYPE result; //Save arguments name = comp_name; //Get handle snprintf(namebuf, sizeof(namebuf) - 1, "%s", name.c_str()); namebuf[sizeof(namebuf) - 1] = '\0'; callbacks.EventHandler = gate_EventHandler; callbacks.EmptyBufferDone = gate_EmptyBufferDone; callbacks.FillBufferDone = gate_FillBufferDone; result = OMX_GetHandle(&comp, namebuf, this, &callbacks); if (result != OMX_ErrorNone) { fprintf(stderr, "OMX_GetHandle failed."); } }
OMX_ERRORTYPE NonTextureEngine::setupRenderer() { //Set up renderer OMX_CALLBACKTYPE renderCallbacks; renderCallbacks.EventHandler = &BaseEngine::renderEventHandlerCallback; renderCallbacks.EmptyBufferDone = &BaseEngine::renderEmptyBufferDone; renderCallbacks.FillBufferDone = &BaseEngine::renderFillBufferDone; string renderComponentName = "OMX.broadcom.video_render"; OMX_GetHandle(&render, (OMX_STRING)renderComponentName.c_str(), this , &renderCallbacks); OMXCameraUtils::disableAllPortsForComponent(&render); //Set renderer to Idle OMX_ERRORTYPE error = OMX_SendCommand(render, OMX_CommandStateSet, OMX_StateIdle, NULL); if (error != OMX_ErrorNone) { ofLog(OF_LOG_ERROR, "render OMX_SendCommand OMX_StateIdle FAIL error: 0x%08x", error); } return error; }
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; }
static void omx_init(audio_backend_pull_callback_t pull_callback) { OMX_ERRORTYPE error; error = OMX_Init(); if(error != OMX_ErrorNone) { fprintf(stderr, "OMX: OMX_Init() failed. Error 0x%X\n", error); return; } // Initialize settings latency_max = settings.omx.Audio_Latency; buffer_size = settings.aica.BufferSize * 4; buffer_count = 2 + OUTPUT_FREQ * latency_max / (buffer_size * 1000); OMX_CALLBACKTYPE callbacks; callbacks.EventHandler = EventHandler; callbacks.EmptyBufferDone = EmptyBufferDone; callbacks.EmptyBufferDone = FillBufferDone; error = OMX_GetHandle(&omx_handle, (OMX_STRING)"OMX.broadcom.audio_render", NULL, &callbacks); if(error != OMX_ErrorNone) { fprintf(stderr, "OMX: OMX_GetHandle() failed. Error 0x%X\n", error); return; } OMX_PARAM_PORTDEFINITIONTYPE param; memset(¶m, 0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); param.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); param.nVersion.nVersion = OMX_VERSION; param.nPortIndex = PORT_INDEX; param.nBufferSize = buffer_size; param.nBufferCountActual = buffer_count; param.format.audio.eEncoding = OMX_AUDIO_CodingPCM; error = OMX_SetParameter(omx_handle, OMX_IndexParamPortDefinition, ¶m); if(error != OMX_ErrorNone) fprintf(stderr, "OMX: failed to set OMX_IndexParamPortDefinition. Error 0x%X\n", error); OMX_AUDIO_PARAM_PCMMODETYPE pcm; memset(&pcm, 0, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); pcm.nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE); pcm.nVersion.nVersion = OMX_VERSION; pcm.nPortIndex = PORT_INDEX; pcm.nChannels = 2; pcm.eNumData = OMX_NumericalDataSigned; pcm.eEndian = OMX_EndianLittle; pcm.nSamplingRate = OUTPUT_FREQ; pcm.bInterleaved = OMX_TRUE; pcm.nBitPerSample = 16; pcm.ePCMMode = OMX_AUDIO_PCMModeLinear; pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF; pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF; error = OMX_SetParameter(omx_handle, OMX_IndexParamAudioPcm, &pcm); if(error != OMX_ErrorNone) fprintf(stderr, "OMX: failed to set OMX_IndexParamAudioPcm. Error 0x%X\n", error); // Disable all ports error = OMX_SendCommand(omx_handle, OMX_CommandPortDisable, PORT_INDEX, NULL); if(error != OMX_ErrorNone) fprintf(stderr, "OMX: failed to do OMX_CommandPortDisable. Error 0x%X\n", error); OMX_PORT_PARAM_TYPE param2; memset(¶m2, 0, sizeof(OMX_PORT_PARAM_TYPE)); param2.nSize = sizeof(OMX_PORT_PARAM_TYPE); param2.nVersion.nVersion = OMX_VERSION; error = OMX_GetParameter(omx_handle, OMX_IndexParamOtherInit, ¶m2); if(error != OMX_ErrorNone) { fprintf(stderr, "OMX: failed to get OMX_IndexParamOtherInit. Error 0x%X\n", error); } else { for(u32 i = 0; i < param2.nPorts; i++) { u32 port = param2.nStartPortNumber + i; error = OMX_SendCommand(omx_handle, OMX_CommandPortDisable, port, NULL); if(error != OMX_ErrorNone) fprintf(stderr, "OMX: failed to do OMX_CommandPortDisable on port %u. Error 0x%X\n", port, error); } } // Go into idle state error = OMX_SendCommand(omx_handle, OMX_CommandStateSet, OMX_StateIdle, NULL); if(error != OMX_ErrorNone) { fprintf(stderr, "OMX: failed to set OMX_CommandStateSet. Error 0x%X\n", error); return; } omx_wait_for_state(OMX_StateIdle); // Check if we're in a state able to recieve buffers OMX_STATETYPE state; error = OMX_GetState(omx_handle, &state); if(error != OMX_ErrorNone || !(state == OMX_StateIdle || state == OMX_StateExecuting || state == OMX_StatePause)) { fprintf(stderr, "OMX: state is incorrect. State 0x%X; Error 0x%X\n", state, error); return; } // Create audio buffers fprintf(stderr, "OMX: creating %u buffers\n", buffer_count); // Enable port error = OMX_SendCommand(omx_handle, OMX_CommandPortEnable, PORT_INDEX, NULL); if(error != OMX_ErrorNone) fprintf(stderr, "OMX: failed to do OMX_CommandPortEnable. Error 0x%X\n", error); // Free audio buffers if they're allocated if(audio_buffers != NULL) delete[] audio_buffers; // Allocate buffers audio_buffers = new OMX_BUFFERHEADERTYPE*[buffer_count]; for(size_t i = 0; i < buffer_count; i++) { error = OMX_AllocateBuffer(omx_handle, &audio_buffers[i], PORT_INDEX, NULL, buffer_size); if(error != OMX_ErrorNone) { fprintf(stderr, "OMX: failed to allocate buffer[%u]. Error 0x%X\n", i, error); return; } } // Set state to executing error = OMX_SendCommand(omx_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(error != OMX_ErrorNone) { fprintf(stderr, "OMX: failed to do OMX_CommandStateSet. Error 0x%X\n", error); return; } omx_wait_for_state(OMX_StateExecuting); // Empty buffers for(size_t i = 0; i < buffer_count; i++) { memset(audio_buffers[i]->pBuffer, 0, buffer_size); audio_buffers[i]->nOffset = 0; audio_buffers[i]->nFilledLen = buffer_size; error = OMX_EmptyThisBuffer(omx_handle, audio_buffers[i]); if(error != OMX_ErrorNone) fprintf(stderr, "OMX: failed to empty buffer[%u]. Error 0x%X\n", i, error); } char* output_device = "local"; if(settings.omx.Audio_HDMI) output_device = (char*)"hdmi"; // Set audio destination OMX_CONFIG_BRCMAUDIODESTINATIONTYPE ar_dest; memset(&ar_dest, 0, sizeof(ar_dest)); ar_dest.nSize = sizeof(OMX_CONFIG_BRCMAUDIODESTINATIONTYPE); ar_dest.nVersion.nVersion = OMX_VERSION; strcpy((char *)ar_dest.sName, output_device); error = OMX_SetConfig(omx_handle, OMX_IndexConfigBrcmAudioDestination, &ar_dest); if(error != OMX_ErrorNone) { fprintf(stderr, "OMX: failed to set OMX configuration (OMX_IndexConfigBrcmAudioDestination). Error 0x%X\n", error); return; } audio_buffer_idx = 0; buffer_length = 0; fprintf(stderr, "OMX: audio output to '%s'\n", ar_dest.sName); }
OMX_ERRORTYPE OMX_CONF_ComponentNameTest(OMX_IN OMX_STRING cComponentName) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_HANDLETYPE hComp = 0; OMX_U32 i = 0; OMX_BOOL bNameValid = OMX_FALSE; OMX_BOOL bFound = OMX_FALSE; OMX_S8 cCompEnumName[TEST_COMPONENT_NAME_SIZE]; OMX_CALLBACKTYPE sCallbacks; sCallbacks.EventHandler = ComponentNameTest_EventHandler; sCallbacks.EmptyBufferDone = ComponentNameTest_EmptyBufferDone; sCallbacks.FillBufferDone = ComponentNameTest_FillBufferDone; /* Initialize OpenMax */ eError = OMX_Init(); if (eError != OMX_ErrorNone) { goto OMX_CONF_TEST_BAIL; } while (OMX_ErrorNone == eError) { /* loop through all enumerated components to determine if the component name specificed for the test is enumerated by the OMX core */ eError = OMX_ComponentNameEnum((OMX_STRING) cCompEnumName, TEST_COMPONENT_NAME_SIZE, i); if (OMX_ErrorNone == eError) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "OMX_ComponenNameEnum enumerated %s at index %i\n", cCompEnumName, i); if (!strcmp((OMX_STRING) cCompEnumName, cComponentName)) { /* component name enumerated by OMX_CORE */ bFound = OMX_TRUE; eError = OMX_GetHandle(&hComp, (OMX_STRING) cCompEnumName, 0x0, &sCallbacks); if (eError == OMX_ErrorNone) { /* validate the first 4 characters of the name match the OMX standard */ if (!strncmp("OMX.", cComponentName, 4)) { bNameValid = OMX_TRUE; } eError = OMX_FreeHandle(hComp); } else { OMX_CONF_ErrorToString(eError, szDesc); OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "%s error=0x%X (%s) from OMX_GetHandle\n", cCompEnumName, eError, szDesc); } } } else if (OMX_ErrorNoMore != eError) { /* OMX_CORE reported unexpected error other than no more components */ OMX_CONF_ErrorToString(eError, szDesc); OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "unexepected error=0x%X (%s) from OMX_ComponenNameEnum\n", eError, szDesc); } i++; } if (OMX_ErrorNoMore == eError) { /* not an error, so clear the error code */ eError = OMX_ErrorNone; } OMX_CONF_TEST_BAIL: if (OMX_ErrorNone == eError) { eError = OMX_Deinit(); } else { OMX_Deinit(); } return eError; }
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; }
static void handle_msg(int fd, struct msg* m) { switch (m->type) { case MSG_GET_HANDLE: { struct comp* c = (struct comp*) malloc(sizeof(struct comp)); fprintf(stderr, "ILSRV: GetHandle '%s'\n", m->cmd.get_handle.name); m->result = OMX_GetHandle(&c->real_handle, m->cmd.get_handle.name, c, &callbacks); m->cmd.get_handle.out_srv_handle = (int) c; c->client_handle = m->cmd.get_handle.in_client_handle; c->client_fd = fd; c->state = OMX_StateLoaded; strncpy(c->name, m->cmd.get_handle.name, sizeof(c->name)); c->name[sizeof(c->name)-1]=0; add_component(c); fprintf(stderr, "ILSRV: %08X [%20s] --> %s%s\n", c->real_handle, last_part(c->name), m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_SET_PARAM:{ struct comp* c = (struct comp*) m->cmd.param.srv_handle; verify_component(c); fprintf(stderr, "ILSRV: %08X [%20s] SetParam %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index)); m->result = OMX_SetParameter(c->real_handle, (OMX_INDEXTYPE) m->cmd.param.index, m->cmd.param.buf); // TODO: Protect fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_GET_PARAM:{ struct comp* c = (struct comp*) m->cmd.param.srv_handle; verify_component(c); fprintf(stderr, "ILSRV: %08X [%20s] GetParam %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index)); m->result = OMX_GetParameter(c->real_handle, (OMX_INDEXTYPE)m->cmd.param.index, m->cmd.param.buf); // TODO: Protect fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_GET_CONFIG:{ struct comp* c = (struct comp*) m->cmd.param.srv_handle; verify_component(c); fprintf(stderr, "ILSRV: %08X [%20s] GetConfig %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index)); m->result = OMX_GetConfig(c->real_handle, (OMX_INDEXTYPE)m->cmd.param.index, m->cmd.param.buf); // TODO: Protect fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_SET_CONFIG: { struct comp* c = (struct comp*) m->cmd.param.srv_handle; verify_component(c); fprintf(stderr, "ILSRV: %08X [%20s] SetConfig %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index)); m->result = OMX_SetConfig(c->real_handle, (OMX_INDEXTYPE)m->cmd.param.index, m->cmd.param.buf); // TODO: Protect fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_FREE_HANDLE: { struct comp* c = (struct comp*) m->cmd.free_handle.srv_handle; verify_component(c); if (c->state != OMX_StateLoaded) { fprintf(stderr, "ILSRV: FreeHandle called for %X which is in wrong state (%s)\m", c->real_handle, adm_log_state2str(c->state)); error_found(); } fprintf(stderr, "ILSRV: %08X [%20s] Freehandle (internal=%X)\n", c->real_handle, last_part(c->name), c); m->result = OMX_FreeHandle(c->real_handle); fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); del_component(c); memset(c, 0xFE, sizeof(*c)); free(c); return; } case MSG_SEND_COMMAND: { struct comp* c = (struct comp*) m->cmd.free_handle.srv_handle; verify_component(c); if (m->cmd.command.cmd == OMX_CommandStateSet) { fprintf(stderr, "ILSRV: %08X [%20s] SendCommand StateSet %s\n", c->real_handle, last_part(c->name), adm_log_state2str((OMX_STATETYPE) m->cmd.command.nParam1)); } else { fprintf(stderr, "ILSRV: %08X [%20s] SendCommand StateSet %s 0x%X\n", c->real_handle, last_part(c->name), adm_log_cmd2str(m->cmd.command.cmd), m->cmd.command.nParam1); } m->result = OMX_SendCommand(c->real_handle, m->cmd.command.cmd, m->cmd.command.nParam1, 0); fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_SETUP_TUNNEL: { struct comp* c_in = (struct comp*) m->cmd.tunnel.srv_handle_in; struct comp* c_out = (struct comp*) m->cmd.tunnel.srv_handle_out; verify_component(c_in); verify_component(c_out); fprintf(stderr, "ILSRV: SetupTunnel %08X [%20s].%d --> %08X [%20s].%d\n", c_out->real_handle, last_part(c_out->name), m->cmd.tunnel.port_out, c_in->real_handle, last_part(c_in->name), m->cmd.tunnel.port_in); m->result = OMX_SetupTunnel(c_out->real_handle, m->cmd.tunnel.port_out, c_in->real_handle, m->cmd.tunnel.port_in); fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_GET_STATE: { struct comp* c = (struct comp*) m->cmd.get_state.in_srv_handle; verify_component(c); fprintf(stderr, "ILSRV: %08X [%20s] GetState\n", c->real_handle, last_part(c->name)); m->result = OMX_GetState(c->real_handle, &m->cmd.get_state.out_state); fprintf(stderr, "ILSRV: --> %s %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result), adm_log_state2str(m->cmd.get_state.out_state)); return; } case MSG_ALLOC_BUFFER: { struct comp* c = (struct comp*) m->cmd.alloc_buffer.in_srv_handle; verify_component(c); OMX_BUFFERHEADERTYPE* bufhdr; fprintf(stderr, "ILSRV: %08X [%20s] AllocBuf port=%d size=%d\n", c->real_handle, last_part(c->name), m->cmd.alloc_buffer.port, m->cmd.alloc_buffer.size); m->result = OMX_AllocateBuffer(c->real_handle, &bufhdr, m->cmd.alloc_buffer.port, (void*) m->cmd.alloc_buffer.in_client_buf_hdr, m->cmd.alloc_buffer.size); if (m->result == OMX_ErrorNone) { memcpy(&m->cmd.alloc_buffer.out_buf_hdr, bufhdr, sizeof(OMX_BUFFERHEADERTYPE)); m->cmd.alloc_buffer.out_srv_buf_hdr = (int) bufhdr; add_bufhdr(bufhdr); } fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_EMPTY_BUFFER: { struct comp* c = (struct comp*) m->cmd.empty_buffer.in_srv_handle; verify_component(c); OMX_BUFFERHEADERTYPE* client_bufhdr = (OMX_BUFFERHEADERTYPE*) &m->cmd.empty_buffer.in_buf_hdr; OMX_BUFFERHEADERTYPE* bufhdr = (OMX_BUFFERHEADERTYPE*) client_bufhdr->pPlatformPrivate; verify_bufhdr(bufhdr); if (bufhdr->nAllocLen <= sizeof(m->cmd.empty_buffer.in_buf)) { bufhdr->nOffset = client_bufhdr->nOffset; bufhdr->nTimeStamp = client_bufhdr->nTimeStamp; bufhdr->nFilledLen = client_bufhdr->nFilledLen; bufhdr->nFlags = client_bufhdr->nFlags; memcpy(bufhdr->pBuffer, &m->cmd.empty_buffer.in_buf, bufhdr->nAllocLen); fprintf(stderr, "ILSRV: %08X [%20s] EmptyBuffer port=%d size=%d\n", c->real_handle, last_part(c->name), bufhdr->nInputPortIndex, bufhdr->nAllocLen); m->result = OMX_EmptyThisBuffer(c->real_handle, bufhdr); fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); } else { assert(0); } return; } case MSG_FILL_BUFFER: { struct comp* c = (struct comp*) m->cmd.empty_buffer.in_srv_handle; verify_component(c); OMX_BUFFERHEADERTYPE* client_bufhdr = (OMX_BUFFERHEADERTYPE*) &m->cmd.fill_buffer.in_buf_hdr; OMX_BUFFERHEADERTYPE* bufhdr = (OMX_BUFFERHEADERTYPE*) client_bufhdr->pPlatformPrivate; verify_bufhdr(bufhdr); fprintf(stderr, "ILSRV: %08X [%20s] FillBuffer port=%d size=%d\n", c->real_handle, last_part(c->name), bufhdr->nOutputPortIndex, bufhdr->nAllocLen); m->result = OMX_FillThisBuffer(c->real_handle, bufhdr); fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } case MSG_FREE_BUFFER: { struct comp* c = (struct comp*) m->cmd.empty_buffer.in_srv_handle; verify_component(c); OMX_BUFFERHEADERTYPE* bufhdr = (OMX_BUFFERHEADERTYPE*) m->cmd.free_buffer.in_srv_buf_hdr; verify_bufhdr(bufhdr); del_bufhdr(bufhdr); fprintf(stderr, "ILSRV: %08X [%20s] FreeBuffer\n", c->real_handle, last_part(c->name)); m->result = OMX_FreeBuffer(c->real_handle, m->cmd.free_buffer.in_port, bufhdr); fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result)); return; } default: fprintf(stderr, "ILSRV: Unhandled request received\n"); m->result = OMX_ErrorNotImplemented; error_found(); return; }
int main(int argc, char *argv[]) { AVFormatContext *ic; char *iname; char *oname; char *size; int err; int vidindex; int i, j; OMX_ERRORTYPE oerr; OMX_HANDLETYPE m2 = NULL, m4 = NULL, resize = NULL; OMX_VIDEO_PARAM_PORTFORMATTYPE *pfmt; OMX_PORT_PARAM_TYPE *porttype; OMX_PARAM_PORTDEFINITIONTYPE *portdef; OMX_BUFFERHEADERTYPE *decbufs; OMX_VIDEO_PORTDEFINITIONTYPE *viddef; OMX_VIDEO_PARAM_PROFILELEVELTYPE *level; int decportidx = 200; int resizeportidx = 60; int encportidx = 130; int fd; time_t start, end; int offset; AVPacket *p, *rp; int ish264; int filtertest; int opt; ILCLIENT_T *client; if (argc < 3) usage(argv[0]); ctx.bitrate = 2*1024*1024; ctx.verbose = 0; ctx.width = 0; ctx.height = 0; while ((opt = getopt(argc, argv, ":b:vs:")) != -1) { switch (opt) { case 'b': //bitrate ctx.bitrate = atoi(optarg); printf("bitrate = %d\n", ctx.bitrate); break; case 'v': //verbose` ctx.verbose = 1; break; case 's': //WxH ctx.width = atoi(optarg); if ((atoi(optarg) % 16) != 0) { printf("W = %d is not a multiple of 16\n", ctx.width); usage(argv[0]); } if (ctx.width <16 || ctx.width > 1080) { printf("W = %d should be between 16 and 1080\n", ctx.width); usage(argv[0]); } printf("W = %d\n", ctx.width); if ((size = strchr(optarg, 'x')) == NULL) { printf("wrong size parameter (no 'x') exiting\n"); usage(argv[0]); } ctx.height = atoi(size+1); if ((atoi(size+1) % 16) != 0) { printf("H = %d is not a multiple of 16\n", ctx.height); usage(argv[0]); } if (ctx.height <16 || ctx.height > 1080) { printf("H = %d should be between 16 and 1080\n", ctx.height); usage(argv[0]); } printf("H = %d\n", ctx.height); break; case '?': usage(argv[0]); } } if ((client = ilclient_init()) == NULL) return -2; iname = argv[optind++]; oname = argv[optind++]; MAKEME(porttype, OMX_PORT_PARAM_TYPE); MAKEME(portdef, OMX_PARAM_PORTDEFINITIONTYPE); MAKEME(pfmt, OMX_VIDEO_PARAM_PORTFORMATTYPE); av_register_all(); ic = NULL; ish264 = 0; pthread_mutex_init(&ctx.lock, NULL); #if 0 fmt = av_oformat_next(fmt); while (fmt) { printf("Found '%s'\t\t'%s'\n", fmt->name, fmt->long_name); fmt = av_oformat_next(fmt); } #endif /* Input init: */ if ((err = avformat_open_input(&ic, iname, NULL, NULL) != 0)) { fprintf(stderr, "Failed to open '%s': %s\n", iname, strerror(err)); exit(1); } ctx.ic = ic; if (avformat_find_stream_info(ic, NULL) < 0) { fprintf(stderr, "Failed to find streams in '%s'\n", iname); exit(1); } av_dump_format(ic, 0, iname, 0); vidindex = av_find_best_stream(ic, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); if (vidindex < 0) { fprintf(stderr, "Failed to find a video stream in '%s'\n", iname); exit(1); } printf("Found a video at index %d\n", vidindex); printf("Frame size: %dx%d\n", ic->streams[vidindex]->codec->width, ic->streams[vidindex]->codec->height); ish264 = (ic->streams[vidindex]->codec->codec_id == CODEC_ID_H264); /* Output init: */ ctx.fd = fd = open(oname, O_CREAT | O_LARGEFILE | O_WRONLY | O_TRUNC, 0666); printf("File descriptor %d\n", fd); #if 0 avformat_alloc_output_context(&oc, NULL, /*NULL,*/ oname); if (!oc) { printf("Couldn't determine output from '%s'; using MPEG.\n", oname); avformat_alloc_output_context(&oc, NULL, /*"matroska",*/ oname); } #endif // if (!oc) // exit(1); // fmt = oc->oformat; for (i = 0; i < ic->nb_streams; i++) { printf("Found stream %d, context %p\n", ic->streams[i]->index, ic->streams[i]->codec); } bcm_host_init(); OERR(OMX_Init(), ctx.verbose); OERR(OMX_GetHandle(&m2, DECNAME, &ctx, &decevents), ctx.verbose); OERR(OMX_GetHandle(&m4, ENCNAME, &ctx, &encevents), ctx.verbose); OERR(OMX_GetHandle(&resize, RESIZENAME, &ctx, &resizeevents), ctx.verbose); ctx.m2 = m2; ctx.m4 = m4; ctx.resize = resize; if (ctx.verbose) printf("Obtained handles. %p decode, %p resize, %p encode\n", m2, resize, m4); OERR(OMX_GetParameter(m2, OMX_IndexParamVideoInit, porttype), ctx.verbose); if (ctx.verbose) printf("Found %d ports, starting at %d (%x) on decoder\n", porttype->nPorts, porttype->nStartPortNumber, porttype->nStartPortNumber); ctx.decportidx = decportidx = porttype->nStartPortNumber; OERR(OMX_GetParameter(resize, OMX_IndexParamImageInit, porttype), ctx.verbose); if (ctx.verbose) printf("Found %d ports, starting at %d (%x) on resizer\n", porttype->nPorts, porttype->nStartPortNumber, porttype->nStartPortNumber); ctx.resizeportidx = resizeportidx = porttype->nStartPortNumber; OERR(OMX_GetParameter(m4, OMX_IndexParamVideoInit, porttype), ctx.verbose); if (ctx.verbose) printf("Found %d ports, starting at %d (%x) on encoder\n", porttype->nPorts, porttype->nStartPortNumber, porttype->nStartPortNumber); ctx.encportidx = encportidx = porttype->nStartPortNumber; free(porttype); OERR(OMX_SendCommand(m2, OMX_CommandPortDisable, decportidx, NULL), ctx.verbose); OERR(OMX_SendCommand(m2, OMX_CommandPortDisable, decportidx+1, NULL), ctx.verbose); OERR(OMX_SendCommand(resize, OMX_CommandPortDisable, resizeportidx, NULL), ctx.verbose); OERR(OMX_SendCommand(resize, OMX_CommandPortDisable, resizeportidx+1, NULL), ctx.verbose); OERR(OMX_SendCommand(m4, OMX_CommandPortDisable, encportidx, NULL), ctx.verbose); OERR(OMX_SendCommand(m4, OMX_CommandPortDisable, encportidx+1, NULL), ctx.verbose); portdef->nPortIndex = decportidx; OERR(OMX_GetParameter(m2, OMX_IndexParamPortDefinition, portdef), ctx.verbose); viddef = &portdef->format.video; viddef->nFrameWidth = ic->streams[vidindex]->codec->width; viddef->nFrameHeight = ic->streams[vidindex]->codec->height; printf("Mapping codec %d to %d\n", ic->streams[vidindex]->codec->codec_id, mapcodec(ic->streams[vidindex]->codec->codec_id)); viddef->eCompressionFormat = mapcodec(ic->streams[vidindex]->codec->codec_id); viddef->bFlagErrorConcealment = 0; // viddef->xFramerate = 25<<16; OERR(OMX_SetParameter(m2, OMX_IndexParamPortDefinition, portdef), ctx.verbose); free(portdef); #if 0 /* It appears these have limited effect: */ dataunit->nPortIndex = decportidx; dataunit->eUnitType = OMX_DataUnitCodedPicture; dataunit->eEncapsulationType = OMX_DataEncapsulationGenericPayload; OERR(OMX_SetParameter(m2, OMX_IndexParamBrcmDataUnit, dataunit), ctx.verbose); if (ish264) { naltype->nPortIndex = decportidx; naltype->eNaluFormat = OMX_NaluFormatStartCodes; OERR(OMX_SetParameter(m2, OMX_IndexParamNalStreamFormatSelect, naltype), ctx.verbose); } #endif MAKEME(level, OMX_VIDEO_PARAM_PROFILELEVELTYPE); level->nPortIndex = encportidx+1; /* Dump what the encoder is capable of: */ if (ctx.verbose) print_codecs(); if (ctx.verbose) { for (oerr = OMX_ErrorNone, i = 0; oerr == OMX_ErrorNone; i++) { pfmt->nIndex = i; oerr = OMX_GetParameter(m4, OMX_IndexParamVideoPortFormat, pfmt); if (oerr == OMX_ErrorNoMore) break; printf("Codecs supported:\n" "\tIndex:\t\t%d\n" "\tCodec:\t\t%d (%x)\n" "\tColour:\t\t%d\n" "\tFramerate:\t%x (%f)\n", pfmt->nIndex, pfmt->eCompressionFormat, pfmt->eCompressionFormat, pfmt->eColorFormat, pfmt->xFramerate, ((float)pfmt->xFramerate/(float)65536)); } for (oerr = OMX_ErrorNone, i = 0; oerr == OMX_ErrorNone; i++) { level->nProfileIndex = i; oerr = OMX_GetParameter(m4, OMX_IndexParamVideoProfileLevelQuerySupported, level); if (oerr == OMX_ErrorNoMore) break; printf("Levels supported:\n" "\tIndex:\t\t%d\n" "\tProfile:\t%d\n" "\tLevel:\t\t%d\n", level->nProfileIndex, level->eProfile, level->eLevel); } } free(pfmt); free(level); /* Dump current port states: */ if (ctx.verbose) { dumpport(m2, decportidx); dumpport(m2, decportidx+1); dumpport(resize, resizeportidx); dumpport(resize, resizeportidx+1); dumpport(m4, encportidx); dumpport(m4, encportidx+1); } OERR(OMX_SendCommand(m2, OMX_CommandStateSet, OMX_StateIdle, NULL), ctx.verbose); decbufs = allocbufs(m2, decportidx, 1); /* Start the initial loop. Process until we have a state change on port 131 */ ctx.decstate = DECINIT; ctx.encstate = ENCPREINIT; OERR(OMX_SendCommand(m2, OMX_CommandStateSet, OMX_StateExecuting, NULL), ctx.verbose); rp = calloc(sizeof(AVPacket), 1); filtertest = ish264; for (offset = i = j = 0; ctx.decstate != DECFAILED; i++, j++) { int rc; int k; int size, nsize; OMX_BUFFERHEADERTYPE *spare; if (offset == 0 && ctx.decstate != DECFLUSH) { rc = av_read_frame(ic, rp); if (rc != 0) { if (ic->pb->eof_reached) ctx.decstate = DECFLUSH; break; } if (rp->stream_index != vidindex) { i--; av_free_packet(rp); continue; } size = rp->size; ctx.fps++; ctx.framecount++; if (ish264 && filtertest) { filtertest = 0; ctx.bsfc = dofiltertest(rp); } if (ctx.bsfc) { p = filter(&ctx, rp); } else { p = rp; } } switch (ctx.decstate) { case DECTUNNELSETUP: start = time(NULL); //printf("NOW to CONFIGURE !!!!!!!!!!!!!!\n\n"); configure(&ctx); ctx.decstate = DECRUNNING; break; case DECFLUSH: size = 0; /* Add the flush code here */ printf("IN FLUSH NOW\n\n"); break; case DECINIT: if (i < 120) /* Bail; decoder doesn't like it */ break; ctx.decstate = DECFAILED; /* Drop through */ case DECFAILED: fprintf(stderr, "Failed to set the parameters after " "%d video frames. Giving up.\n", i); dumpport(m2, decportidx); dumpport(m2, decportidx+1); dumpport(resize, resizeportidx); dumpport(resize, resizeportidx+1); dumpport(m4, encportidx); dumpport(m4, encportidx+1); exit(1); break; default: break; /* Shuts the compiler up */ } for (spare = NULL; !spare; usleep(10)) { pthread_mutex_lock(&ctx.lock); spare = ctx.bufhead; ctx.bufhead = NULL; ctx.flags &= ~FLAGS_DECEMPTIEDBUF; pthread_mutex_unlock(&ctx.lock); while (spare) { write(fd, &spare->pBuffer[spare->nOffset], spare->nFilledLen); spare->nFilledLen = 0; spare->nOffset = 0; OERRq(OMX_FillThisBuffer(m4, spare)); spare = spare->pAppPrivate; } spare = decbufs; for (k = 0; spare && spare->nFilledLen != 0; k++) spare = spare->pAppPrivate; } if (size > spare->nAllocLen) { nsize = spare->nAllocLen; } else { nsize = size; } if (ctx.decstate != DECFLUSH) { memcpy(spare->pBuffer, &(p->data[offset]), nsize); spare->nFlags = i == 0 ? OMX_BUFFERFLAG_STARTTIME : 0; spare->nFlags |= size == nsize ? OMX_BUFFERFLAG_ENDOFFRAME : 0; } else { spare->nFlags = OMX_BUFFERFLAG_STARTTIME | OMX_BUFFERFLAG_EOS; } spare->nFilledLen = nsize; spare->nOffset = 0; OERRq(OMX_EmptyThisBuffer(m2, spare)); size -= nsize; if (size) { offset += nsize; } else { offset = 0; av_free_packet(p); } } close(fd); end = time(NULL); printf("Processed %d frames in %d seconds; %df/s\n", ctx.framecount, end-start, (ctx.framecount/(end-start))); // flush the encoder // OERR(OMX_SendCommand(m4, OMX_CommandFlush, encportidx, NULL), ctx.verbose); // OERR(OMX_SendCommand(m4, OMX_CommandFlush, encportidx+ctx.verbose, NULL), ctx.verbose); // tear down the tunnels OERR(OMX_SendCommand(m2, OMX_CommandStateSet, OMX_StateIdle, NULL), ctx.verbose); OERR(OMX_SendCommand(resize, OMX_CommandStateSet, OMX_StateIdle, NULL), ctx.verbose); OERR(OMX_SendCommand(m4, OMX_CommandStateSet, OMX_StateIdle, NULL), ctx.verbose); OERR(OMX_SendCommand(m2, OMX_CommandStateSet, OMX_StateLoaded, NULL), ctx.verbose); OERR(OMX_SendCommand(resize, OMX_CommandStateSet, OMX_StateLoaded, NULL), ctx.verbose); OERR(OMX_SendCommand(m4, OMX_CommandStateSet, OMX_StateLoaded, NULL), ctx.verbose); // free buffers vcos_free(decbufs); vcos_free(ctx.encbufs); // Apparantly the teardwon function is not implemented. Use setup function instead //OERR(OMX_TeardownTunnel(m2, decportidx+ctx.verbose, resize, resizeportidx), ctx.verbose); //OERR(OMX_TeardownTunnel(resize, resizeportidx+ctx.verbose, m4, encportidx), ctx.verbose); OERR(OMX_SendCommand(m2, OMX_CommandPortDisable, decportidx, NULL), ctx.verbose); OERR(OMX_SendCommand(m2, OMX_CommandPortDisable, decportidx+ctx.verbose, NULL), ctx.verbose); OERR(OMX_SendCommand(resize, OMX_CommandPortDisable, resizeportidx, NULL), ctx.verbose); OERR(OMX_SendCommand(resize, OMX_CommandPortDisable, resizeportidx+ctx.verbose, NULL), ctx.verbose); OERR(OMX_SendCommand(m4, OMX_CommandPortDisable, encportidx, NULL), ctx.verbose); OERR(OMX_SendCommand(m4, OMX_CommandPortDisable, encportidx+ctx.verbose, NULL), ctx.verbose); // ilclient_disable_port_buffers(m2, decportidx, NULL, NULL, NULL); // ilclient_disable_port_buffers(m4, encportidx, NULL, NULL, NULL); OERR(OMX_SetupTunnel(m2, decportidx+ctx.verbose, NULL, 0), ctx.verbose); OERR(OMX_SetupTunnel(resize, resizeportidx, NULL, 0), ctx.verbose); OERR(OMX_SetupTunnel(resize, resizeportidx+ctx.verbose, NULL, 0), ctx.verbose); OERR(OMX_SetupTunnel(m4, encportidx, NULL, 0), ctx.verbose); OERR(OMX_FreeHandle(m2), ctx.verbose); OERR(OMX_FreeHandle(resize), ctx.verbose); OERR(OMX_FreeHandle(m4), ctx.verbose); // free(porttype); // free(portdef); // free(pfmt); // free(level); return 0; }
static int init() { OMX_ERRORTYPE err; OMX_PARAM_PORTDEFINITIONTYPE paramPort; err = OMX_Init(); printf("om init %d\n", err); if (err != OMX_ErrorNone) { return 0; } sem_init(&wait_for_state, 0, 0); sem_init(&wait_for_parameters, 0, 0); sem_init(&buffer_out_filled, 0, 0); err = OMX_GetHandle(&decoderhandle, COMPONENT, NULL, &decodercallbacks); OMXE(err); // set filepath NVX_PARAM_FILENAME filename; OMX_INDEXTYPE filename_idx; err=OMX_GetExtensionIndex(decoderhandle, FILENAME, &filename_idx); OMXE(err); printf("filename: %d\n"); setHeader(&filename, sizeof(filename)); filename.pFilename = "test.mp4"; err=OMX_SetParameter(decoderhandle, filename_idx, &filename); OMXE(err); err = OMX_SendCommand(decoderhandle, OMX_CommandPortDisable, 1, 0); OMXE(err); setHeader(¶mPort, sizeof(paramPort)); paramPort.nPortIndex = 0; err=OMX_GetParameter(decoderhandle, OMX_IndexParamPortDefinition, ¶mPort); OMXE(err); #ifdef DEBUG printf("Codec=%d\n", paramPort.format.video.eCompressionFormat); printf("Color=%d\n", paramPort.format.video.eColorFormat); printf("Size=%dx%d\n", paramPort.format.video.nFrameWidth, paramPort.format.video.nFrameHeight); printf("Rate=%d\n", paramPort.format.video.xFramerate); printf("Requesting %d buffers of %d bytes\n", paramPort.nBufferCountMin, paramPort.nBufferSize); #endif int i; for(i=0; i<paramPort.nBufferCountMin; ++i) { err = OMX_AllocateBuffer(decoderhandle, &omx_buffers_out[i], 0, NULL, paramPort.nBufferSize); OMXE(err); #ifdef DEBUG printf("buf_out[%d]=%p\n", i, omx_buffers_out[i]); #endif } buffer_out_nb = paramPort.nBufferCountMin; buffer_out_ap = buffer_out_nb; buffer_out_avp = 0; buffer_out_pos=0; buffer_out_size=paramPort.nBufferSize; printf("idle\n"); GoToState(OMX_StateIdle); printf("go executing\n"); GoToState(OMX_StateExecuting); return 1; }
int main(int argc, char** argv) { OMX_PORT_PARAM_TYPE param; OMX_PARAM_PORTDEFINITIONTYPE sPortDef; OMX_AUDIO_PORTDEFINITIONTYPE sAudioPortDef; OMX_AUDIO_PARAM_PORTFORMATTYPE sAudioPortFormat; OMX_AUDIO_PARAM_PCMMODETYPE sPCMMode; OMX_BUFFERHEADERTYPE **inBuffers[2]; char *componentName = "OMX.broadcom.video_render"; unsigned char name[OMX_MAX_STRINGNAME_SIZE]; OMX_UUIDTYPE uid; int startPortNumber; int nPorts; int i, n; bcm_host_init(); fprintf(stderr, "Thread id is %p\n", pthread_self()); if(argc < 2){ display_help(argv); exit(1); } fd = open(argv[1], O_RDONLY); if(fd < 0){ perror("Error opening input file\n"); exit(1); } filesize = getFileSize(fd); err = OMX_Init(); if(err != OMX_ErrorNone) { fprintf(stderr, "OMX_Init() failed\n", 0); exit(1); } /** Ask the core for a handle to the audio render component */ err = OMX_GetHandle(&handle, componentName, NULL /*app private data */, &callbacks); if(err != OMX_ErrorNone) { fprintf(stderr, "OMX_GetHandle failed\n", 0); exit(1); } err = OMX_GetComponentVersion(handle, name, &compVersion, &specVersion, &uid); if(err != OMX_ErrorNone) { fprintf(stderr, "OMX_GetComponentVersion failed\n", 0); exit(1); } /** disable other ports */ disablePort(OMX_IndexParamOtherInit); /** Get audio port information */ setHeader(¶m, sizeof(OMX_PORT_PARAM_TYPE)); err = OMX_GetParameter(handle, OMX_IndexParamVideoInit, ¶m); if(err != OMX_ErrorNone){ fprintf(stderr, "Error in getting OMX_PORT_PARAM_TYPE parameter\n", 0); exit(1); } startPortNumber = ((OMX_PORT_PARAM_TYPE)param).nStartPortNumber; nPorts = ((OMX_PORT_PARAM_TYPE)param).nPorts; if (nPorts > 2) { fprintf(stderr, "Image device has more than one port\n"); exit(1); } for (i = 0; i < nPorts; i++) { /* Get and check port information */ setHeader(&sPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); sPortDef.nPortIndex = startPortNumber + i; err = OMX_GetParameter(handle, OMX_IndexParamPortDefinition, &sPortDef); if(err != OMX_ErrorNone) { fprintf(stderr, "Error in getting OMX_PORT_DEFINITION_TYPE parameter\n", 0); exit(1); } if (sPortDef.eDomain != OMX_PortDomainVideo) { fprintf(stderr, "Port %d is not a video port\n", sPortDef.nPortIndex); exit(1); } if (sPortDef.eDir == OMX_DirInput) fprintf(stdout, "Port %d is an input port\n", sPortDef.nPortIndex); else fprintf(stdout, "Port %d is an output port\n", sPortDef.nPortIndex); if (sPortDef.format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar) fprintf(stderr, "Port color Format is YUV420PackedPlanar\n"); else fprintf(stderr, "Port has unknown color format\n"); /* Set Image Format -- FIXME: hardcoded */ sPortDef.format.video.nFrameWidth = 1920; sPortDef.format.video.nFrameHeight = 1080; sPortDef.format.video.nStride = ALIGN(sPortDef.format.video.nFrameWidth, 32); sPortDef.format.image.nSliceHeight = ALIGN(sPortDef.format.video.nFrameHeight, 16); sPortDef.nBufferSize = sPortDef.format.image.nStride * sPortDef.format.image.nSliceHeight * 3 / 2; /* Create minimum number of buffers for the port */ nBuffers = sPortDef.nBufferCountActual = sPortDef.nBufferCountMin; fprintf(stderr, "Number of bufers is %d\n", nBuffers); err = OMX_SetParameter(handle, OMX_IndexParamPortDefinition, &sPortDef); if(err != OMX_ErrorNone){ fprintf(stderr, "Error in setting OMX_PORT_PARAM_TYPE parameter\n", 0); exit(1); } if (sPortDef.bEnabled) { fprintf(stderr, "Port %d is enabled\n", sPortDef.nPortIndex); } else { fprintf(stderr, "Port %d is not enabled\n", sPortDef.nPortIndex); } } /* call to put state into idle before allocating buffers */ printf("OMX_CommandStateSet, OMX_StateIdle\n"); err = OMX_SendCommand(handle, OMX_CommandStateSet, OMX_StateIdle, NULL); if (err != OMX_ErrorNone) { fprintf(stderr, "Error on setting state to idle\n"); exit(1); } for (i = 0; i < nPorts; i++) { /* Get and check port information */ setHeader(&sPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); sPortDef.nPortIndex = startPortNumber + i; err = OMX_GetParameter(handle, OMX_IndexParamPortDefinition, &sPortDef); if(err != OMX_ErrorNone) { fprintf(stderr, "Error in getting OMX_PORT_DEFINITION_TYPE parameter\n", 0); exit(1); } if (!sPortDef.bEnabled) { printf("OMX_CommandPortEnable, %d\n", startPortNumber); err = OMX_SendCommand(handle, OMX_CommandPortEnable, startPortNumber, NULL); if (err != OMX_ErrorNone) { fprintf(stderr, "Error on setting port to enabled\n"); exit(1); } } } /* Configure buffers for the port */ for (i = 0; i < nPorts; i++) { setHeader(&sPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); sPortDef.nPortIndex = startPortNumber + i; err = OMX_GetParameter(handle, OMX_IndexParamPortDefinition, &sPortDef); nBufferSize = sPortDef.nBufferSize; fprintf(stderr, "Port %d has %d buffers of size %d\n", sPortDef.nPortIndex, nBuffers, nBufferSize); inBuffers[i] = malloc(nBuffers * sizeof(OMX_BUFFERHEADERTYPE *)); if (inBuffers[i] == NULL) { fprintf(stderr, "Can't allocate buffers\n"); exit(1); } for (n = 0; n < nBuffers; n++) { err = OMX_AllocateBuffer(handle, inBuffers[i] + n, startPortNumber + i, NULL, nBufferSize); if (err != OMX_ErrorNone) { fprintf(stderr, "Error on AllocateBuffer in 1%i\n", err); exit(1); } } } printf("Transition to Idle\n"); /* Make sure we've reached Idle state */ waitFor(OMX_StateIdle); printf("Transition to Executing\n"); /* Now try to switch to Executing state */ err = OMX_SendCommand(handle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(err != OMX_ErrorNone){ exit(1); } /* One buffer is the minimum for Broadcom component, so use that */ pEmptyBuffer = inBuffers[0][0]; emptyState = 1; /* Fill and empty buffer */ for (;;) { int data_read = read(fd, pEmptyBuffer->pBuffer, nBufferSize); pEmptyBuffer->nFilledLen = data_read; pEmptyBuffer->nOffset = 0; filesize -= data_read; if (filesize <= 0) { pEmptyBuffer->nFlags = OMX_BUFFERFLAG_EOS; } fprintf(stderr, "Emptying again buffer %p %d bytes, %d to go\n", pEmptyBuffer, data_read, filesize); err = OMX_EmptyThisBuffer(handle, pEmptyBuffer); waitForEmpty(); fprintf(stderr, "Waited for empty\n"); if (bEOS) { fprintf(stderr, "Exiting loop\n"); break; } } fprintf(stderr, "Buffers emptied\n"); exit(0); }