OMX_ERRORTYPE setFbsinkParameters() { OMX_ERRORTYPE errRet = OMX_ErrorNone; OMX_ERRORTYPE err = OMX_ErrorNone; OMX_VIDEO_PARAM_PORTFORMATTYPE sVideoPortFormat; OMX_PARAM_PORTDEFINITIONTYPE sOmxPortDefinition; OMX_CONFIG_RECTTYPE sConfigCrop; OMX_CONFIG_POINTTYPE sConfigOutputPosition; /* set input port */ setHeader(&sVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); sVideoPortFormat.nPortIndex = 0; sVideoPortFormat.nIndex = 0; if ((err = OMX_GetParameter(appPriv->fbsinkhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Getting fbsink input port video format failed!\n"); errRet = err; } else { sVideoPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused; sVideoPortFormat.eColorFormat = DEFAULT_FBSINK_COLOR_FORMAT; sVideoPortFormat.xFramerate = 0; if ((err = OMX_SetParameter(appPriv->fbsinkhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Setting fbsink input port video format failed!\n"); errRet = err; } } setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); sOmxPortDefinition.nPortIndex = 0; if ((err = OMX_GetParameter(appPriv->fbsinkhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Getting fbsink input port parameters failed!\n"); errRet = err; } else { sOmxPortDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; sOmxPortDefinition.format.video.nFrameHeight = DEFAULT_FRAME_HEIGHT; sOmxPortDefinition.format.video.nStride = DEFAULT_FRAME_WIDTH; sOmxPortDefinition.format.video.nSliceHeight = DEFAULT_FRAME_HEIGHT; sOmxPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; sOmxPortDefinition.format.video.eColorFormat = DEFAULT_FBSINK_COLOR_FORMAT; sOmxPortDefinition.nBufferSize = sOmxPortDefinition.format.video.nStride * sOmxPortDefinition.format.video.nFrameHeight * 3; if ((err = OMX_SetParameter(appPriv->fbsinkhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Setting fbsink input port parameters failed!\n"); errRet = err; } } setHeader(&sConfigCrop, sizeof(OMX_CONFIG_RECTTYPE)); sConfigCrop.nPortIndex = 0; if ((err = OMX_GetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonInputCrop, &sConfigCrop)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Getting fbsink input port Crop config failed!\n"); errRet = err; } else { sConfigCrop.nLeft = 0; sConfigCrop.nTop = 0; sConfigCrop.nWidth = DEFAULT_FRAME_WIDTH; sConfigCrop.nHeight = DEFAULT_FRAME_HEIGHT; if ((err = OMX_SetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonInputCrop, &sConfigCrop)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Setting fbsink input port Crop config failed!\n"); errRet = err; } } /* set display position (x, y) */ setHeader(&sConfigOutputPosition, sizeof(OMX_CONFIG_POINTTYPE)); sConfigOutputPosition.nPortIndex = 0; if ((err = OMX_GetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonOutputPosition, &sConfigOutputPosition)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Getting fbsink output port Position config failed!\n"); errRet = err; } else { sConfigOutputPosition.nX = 0; sConfigOutputPosition.nY = 0; if ((err = OMX_SetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonOutputPosition, &sConfigOutputPosition)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Setting fbsink output port Position config failed!\n"); errRet = err; } } return errRet; }
/* Main entrypoint into the Seeking Component Test */ OMX_ERRORTYPE OMX_CONF_SeekingComponentTest(OMX_IN OMX_STRING cComponentName) { OMX_TIME_CONFIG_SEEKMODETYPE oSeekMode; OMX_TIME_CONFIG_TIMESTAMPTYPE oTimeStamp; OMX_PTR pWrappedAppData; OMX_CALLBACKTYPE *pWrappedCallbacks; OMX_HANDLETYPE hComp, hWrappedComp, hTTComp, hWrappedTTComp; OMX_ERRORTYPE eTemp, eError = OMX_ErrorNone; OMX_CALLBACKTYPE oCallbacks; SCTDATATYPE oAppData; /* create state change event */ OMX_OSAL_EventCreate(&oAppData.hStateChangeEvent); OMX_OSAL_EventReset(oAppData.hStateChangeEvent); OMX_OSAL_EventCreate(&oAppData.hEOSEvent); OMX_OSAL_EventReset(oAppData.hEOSEvent); /* init component handles */ hComp = hWrappedComp = hTTComp = hWrappedTTComp = 0; oCallbacks.EventHandler = SCTEventHandler; oCallbacks.EmptyBufferDone = StubbedEmptyBufferDone; oCallbacks.FillBufferDone = StubbedFillBufferDone; eError = OMX_CONF_CallbackTracerCreate(&oCallbacks, (OMX_PTR) & oAppData, cComponentName, &pWrappedCallbacks, &pWrappedAppData); /* Initialize OpenMax */ eError = OMX_Init(); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Creating component under test and tunnel test component.\n"); /* Acquire component under test handle */ OMX_CONF_FAIL_IF_ERROR(OMX_GetHandle(&hComp, cComponentName, pWrappedAppData, pWrappedCallbacks)); OMX_CONF_FAIL_IF_ERROR(OMX_CONF_ComponentTracerCreate(hComp, cComponentName, &hWrappedComp)); oAppData.hCUT = hComp; /* Acquire tunnel test component handle */ OMX_CONF_FAIL_IF_ERROR(OMX_CONF_GetTunnelTestComponentHandle(&hTTComp, pWrappedAppData, pWrappedCallbacks)); OMX_CONF_FAIL_IF_ERROR(OMX_CONF_ComponentTracerCreate(hTTComp, "OMX.CONF.tunnel.test", &hWrappedTTComp)); /* Set the OnEmptyThisBuffer callback */ OMX_CONF_SetTTCOnEmptyThisBuffer(hTTComp, SCTOnEmptyThisBuffer); /* Connect CUT to TTC */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Connecting all ports.\n"); OMX_CONF_FAIL_IF_ERROR(OMX_CONF_TTCConnectAllPorts(hWrappedTTComp, hWrappedComp)); /* Force all CUT ports to be suppliers */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Forcing all component ports to be suppliers.\n"); OMX_CONF_FAIL_IF_ERROR(OMX_CONF_ForceSuppliers(hWrappedComp, OMX_TRUE)); OMX_CONF_FAIL_IF_ERROR(OMX_CONF_ForceSuppliers(hWrappedTTComp, OMX_FALSE)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Transitioning to executing.\n"); /* transition CUT to idle */ OMX_CONF_FAIL_IF_ERROR(OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateIdle, 0)); /* transition TTC to idle */ OMX_CONF_FAIL_IF_ERROR(OMX_SendCommand(hWrappedTTComp, OMX_CommandStateSet, OMX_StateIdle, 0)); /* transition CUT to executing */ OMX_CONF_FAIL_IF_ERROR(SCTWaitForState(&oAppData, OMX_StateIdle)); OMX_OSAL_EventReset(oAppData.hStateChangeEvent); OMX_CONF_FAIL_IF_ERROR(OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateExecuting, 0)); OMX_CONF_FAIL_IF_ERROR(SCTWaitForState(&oAppData, OMX_StateExecuting)); /* transition TTC to executing */ OMX_CONF_FAIL_IF_ERROR(OMX_SendCommand(hWrappedTTComp, OMX_CommandStateSet, OMX_StateExecuting, 0)); OMX_CONF_FAIL_IF_ERROR(OMX_CONF_WaitForBufferTraffic(hTTComp)); /* Get/Set OMX_IndexConfigTimeSeekMode */ INIT_CONFIG(oSeekMode); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Confirm support for OMX_IndexConfigTimeSeekMode\n"); OMX_CONF_FAIL_IF_ERROR(OMX_GetConfig(hComp, OMX_IndexConfigTimeSeekMode, (OMX_PTR)&oSeekMode)); oSeekMode.eType = OMX_TIME_SeekModeAccurate; OMX_CONF_FAIL_IF_ERROR(OMX_SetConfig(hComp, OMX_IndexConfigTimeSeekMode, (OMX_PTR)&oSeekMode)); /* Get OMX_IndexConfigTimePosition */ INIT_CONFIG(oTimeStamp); oTimeStamp.nPortIndex = 0; /* ignored - but we clear it anyway */ OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Confirm support for OMX_IndexConfigTimePosition\n"); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-Get the current position (remember it for later).\n"); OMX_CONF_FAIL_IF_ERROR(OMX_GetConfig(hComp, OMX_IndexConfigTimePosition, (OMX_PTR)&oTimeStamp)); /* Set OMX_IndexConfigTimePosition */ /* Wait for the position to move on and then return to it */ g_StartTimeDetected = OMX_FALSE; OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-Run for a while.\n"); OMX_CONF_FAIL_IF_ERROR(OMX_CONF_WaitForBufferTraffic(hTTComp)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-Seek to the remembered position.\n"); OMX_CONF_FAIL_IF_ERROR(OMX_SetConfig(hComp, OMX_IndexConfigTimePosition, (OMX_PTR)&oTimeStamp)); OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "-Run for a while - wait for seek (i.e. a OMX_BUFFERFLAG_STARTTIME).\n"); OMX_CONF_WaitForBufferTraffic(hTTComp); if (g_StartTimeDetected) { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "--OK: Saw OMX_BUFFERFLAG_STARTTIME.\n"); } else { OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "--ERROR: No OMX_BUFFERFLAG_STARTTIME.\n"); eError = OMX_ErrorUndefined; } OMX_CONF_TEST_FAIL: /* Cleanup: Return function errors rather than closing errors if appropriate */ /* transition CUT and TTC to Loaded state */ if (hWrappedComp) { OMX_OSAL_EventReset(oAppData.hStateChangeEvent); OMX_CONF_REMEMBER_ERROR(OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateIdle, 0)); } if (hWrappedTTComp) { OMX_CONF_REMEMBER_ERROR(OMX_SendCommand(hWrappedTTComp, OMX_CommandStateSet, OMX_StateIdle, 0)); TTCReleaseBuffers(hTTComp); } if (hWrappedComp) { OMX_CONF_REMEMBER_ERROR(SCTWaitForState(&oAppData, OMX_StateIdle)); OMX_OSAL_EventReset(oAppData.hStateChangeEvent); OMX_CONF_REMEMBER_ERROR(OMX_SendCommand(hWrappedComp, OMX_CommandStateSet, OMX_StateLoaded, 0)); OMX_CONF_REMEMBER_ERROR(SCTWaitForState(&oAppData, OMX_StateLoaded)); } if (hWrappedTTComp) { OMX_CONF_REMEMBER_ERROR(OMX_SendCommand(hWrappedTTComp, OMX_CommandStateSet, OMX_StateLoaded, 0)); } /* destroy state change event */ OMX_OSAL_EventDestroy(oAppData.hStateChangeEvent); OMX_OSAL_EventDestroy(oAppData.hEOSEvent); if (hWrappedComp) { OMX_CONF_REMEMBER_ERROR(OMX_CONF_ComponentTracerDestroy(hWrappedComp)); } if (hComp) { OMX_CONF_REMEMBER_ERROR(OMX_FreeHandle(hComp)); } if (hTTComp) { OMX_CONF_REMEMBER_ERROR(OMX_CONF_FreeTunnelTestComponentHandle(hTTComp)); OMX_CONF_REMEMBER_ERROR(OMX_CONF_ComponentTracerDestroy(hWrappedTTComp)); } OMX_CONF_REMEMBER_ERROR(OMX_CONF_CallbackTracerDestroy(pWrappedCallbacks, pWrappedAppData)); OMX_CONF_REMEMBER_ERROR(OMX_Deinit()); return eError; }
static int Open(vlc_object_t *p_this) { vout_display_t *vd = (vout_display_t *)p_this; vout_display_t *p_dec = vd; char ppsz_components[MAX_COMPONENTS_LIST_SIZE][OMX_MAX_STRINGNAME_SIZE]; picture_t** pictures = NULL; OMX_PARAM_PORTDEFINITIONTYPE *def; static OMX_CALLBACKTYPE callbacks = { OmxEventHandler, OmxEmptyBufferDone, OmxFillBufferDone }; if (InitOmxCore(p_this) != VLC_SUCCESS) return VLC_EGENERIC; int components = CreateComponentsList(p_this, "iv_renderer", ppsz_components); if (components <= 0) { DeinitOmxCore(); return VLC_EGENERIC; } /* Allocate structure */ vout_display_sys_t *p_sys = (struct vout_display_sys_t*) calloc(1, sizeof(*p_sys)); if (!p_sys) { DeinitOmxCore(); return VLC_ENOMEM; } vd->sys = p_sys; strcpy(p_sys->psz_component, ppsz_components[0]); /* Load component */ OMX_ERRORTYPE omx_error = pf_get_handle(&p_sys->omx_handle, p_sys->psz_component, vd, &callbacks); CHECK_ERROR(omx_error, "OMX_GetHandle(%s) failed (%x: %s)", p_sys->psz_component, omx_error, ErrorToString(omx_error)); InitOmxEventQueue(&p_sys->event_queue); OMX_FIFO_INIT(&p_sys->port.fifo, pOutputPortPrivate); p_sys->port.b_direct = false; p_sys->port.b_flushed = true; OMX_PORT_PARAM_TYPE param; OMX_INIT_STRUCTURE(param); omx_error = OMX_GetParameter(p_sys->omx_handle, OMX_IndexParamVideoInit, ¶m); CHECK_ERROR(omx_error, "OMX_GetParameter(OMX_IndexParamVideoInit) failed (%x: %s)", omx_error, ErrorToString(omx_error)); p_sys->port.i_port_index = param.nStartPortNumber; p_sys->port.b_valid = true; p_sys->port.omx_handle = p_sys->omx_handle; def = &p_sys->port.definition; OMX_INIT_STRUCTURE(*def); def->nPortIndex = p_sys->port.i_port_index; omx_error = OMX_GetParameter(p_sys->omx_handle, OMX_IndexParamPortDefinition, def); CHECK_ERROR(omx_error, "OMX_GetParameter(OMX_IndexParamPortDefinition) failed (%x: %s)", omx_error, ErrorToString(omx_error)); #define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) def->format.video.nFrameWidth = vd->fmt.i_width; def->format.video.nFrameHeight = vd->fmt.i_height; def->format.video.nStride = 0; def->format.video.nSliceHeight = 0; p_sys->port.definition.format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar; if (!strcmp(p_sys->psz_component, "OMX.broadcom.video_render")) { def->format.video.nSliceHeight = ALIGN(def->format.video.nFrameHeight, 16); } omx_error = OMX_SetParameter(p_sys->omx_handle, OMX_IndexParamPortDefinition, &p_sys->port.definition); CHECK_ERROR(omx_error, "OMX_SetParameter(OMX_IndexParamPortDefinition) failed (%x: %s)", omx_error, ErrorToString(omx_error)); OMX_GetParameter(p_sys->omx_handle, OMX_IndexParamPortDefinition, &p_sys->port.definition); if (def->format.video.nStride < (int) def->format.video.nFrameWidth) def->format.video.nStride = def->format.video.nFrameWidth; if (def->format.video.nSliceHeight < def->format.video.nFrameHeight) def->format.video.nSliceHeight = def->format.video.nFrameHeight; p_sys->port.pp_buffers = malloc(p_sys->port.definition.nBufferCountActual * sizeof(OMX_BUFFERHEADERTYPE*)); p_sys->port.i_buffers = p_sys->port.definition.nBufferCountActual; omx_error = OMX_SendCommand(p_sys->omx_handle, OMX_CommandStateSet, OMX_StateIdle, 0); CHECK_ERROR(omx_error, "OMX_CommandStateSet Idle failed (%x: %s)", omx_error, ErrorToString(omx_error)); unsigned int i; for (i = 0; i < p_sys->port.i_buffers; i++) { omx_error = OMX_AllocateBuffer(p_sys->omx_handle, &p_sys->port.pp_buffers[i], p_sys->port.i_port_index, 0, p_sys->port.definition.nBufferSize); if (omx_error != OMX_ErrorNone) break; OMX_FIFO_PUT(&p_sys->port.fifo, p_sys->port.pp_buffers[i]); } if (omx_error != OMX_ErrorNone) { p_sys->port.i_buffers = i; for (i = 0; i < p_sys->port.i_buffers; i++) OMX_FreeBuffer(p_sys->omx_handle, p_sys->port.i_port_index, p_sys->port.pp_buffers[i]); msg_Err(vd, "OMX_AllocateBuffer failed (%x: %s)", omx_error, ErrorToString(omx_error)); goto error; } omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0); CHECK_ERROR(omx_error, "Wait for Idle failed (%x: %s)", omx_error, ErrorToString(omx_error)); omx_error = OMX_SendCommand(p_sys->omx_handle, OMX_CommandStateSet, OMX_StateExecuting, 0); CHECK_ERROR(omx_error, "OMX_CommandStateSet Executing failed (%x: %s)", omx_error, ErrorToString(omx_error)); omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0); CHECK_ERROR(omx_error, "Wait for Executing failed (%x: %s)", omx_error, ErrorToString(omx_error)); if (!strcmp(p_sys->psz_component, "OMX.broadcom.video_render")) { OMX_CONFIG_DISPLAYREGIONTYPE config_display; OMX_INIT_STRUCTURE(config_display); config_display.nPortIndex = p_sys->port.i_port_index; config_display.set = OMX_DISPLAY_SET_SRC_RECT; config_display.src_rect.width = vd->cfg->display.width; config_display.src_rect.height = vd->cfg->display.height; OMX_SetConfig(p_sys->omx_handle, OMX_IndexConfigDisplayRegion, &config_display); config_display.set = OMX_DISPLAY_SET_FULLSCREEN; config_display.fullscreen = OMX_TRUE; OMX_SetConfig(p_sys->omx_handle, OMX_IndexConfigDisplayRegion, &config_display); UpdateDisplaySize(vd, vd->cfg); } /* Setup chroma */ video_format_t fmt = vd->fmt; fmt.i_chroma = VLC_CODEC_I420; video_format_FixRgb(&fmt); /* Setup vout_display */ vd->fmt = fmt; vd->pool = Pool; vd->display = Display; vd->control = Control; vd->prepare = NULL; vd->manage = NULL; /* Create the associated picture */ pictures = calloc(p_sys->port.i_buffers, sizeof(*pictures)); if (!pictures) goto error; for (unsigned int i = 0; i < p_sys->port.i_buffers; i++) { picture_sys_t *picsys = malloc(sizeof(*picsys)); if (unlikely(picsys == NULL)) goto error; picsys->sys = p_sys; picture_resource_t resource = { .p_sys = picsys }; picture_t *picture = picture_NewFromResource(&fmt, &resource); if (unlikely(picture == NULL)) { free(picsys); goto error; } pictures[i] = picture; } /* Wrap it into a picture pool */ picture_pool_configuration_t pool_cfg; memset(&pool_cfg, 0, sizeof(pool_cfg)); pool_cfg.picture_count = p_sys->port.i_buffers; pool_cfg.picture = pictures; pool_cfg.lock = LockSurface; pool_cfg.unlock = UnlockSurface; p_sys->pool = picture_pool_NewExtended(&pool_cfg); if (!p_sys->pool) { for (unsigned int i = 0; i < p_sys->port.i_buffers; i++) picture_Release(pictures[i]); goto error; } /* Fix initial state */ vout_display_SendEventFullscreen(vd, true); free(pictures); return VLC_SUCCESS; error: free(pictures); Close(p_this); return VLC_EGENERIC; }
/* main */ int main(int argc, char **args) { OMXCLIENT client; OMX_ERRORTYPE omxError; OMX_U32 *variance_array; OMX_U32 variance_array_len; memset(¶meters, 0, sizeof(OMXDECODER_PARAMETERS)); arg_count = argc; arguments = args; parameters.buffer_size = 0; //640 * 480 * 3 / 2; parameters.buffer_count = 3; omxError = process_parameters(argc, args, ¶meters); if(omxError != OMX_ErrorNone) { print_usage(args[0]); return omxError; } variance_array_len = 0; variance_array = 0; if(parameters.varfile && (omxError = omxclient_read_variance_file(&variance_array, &variance_array_len, parameters.varfile)) != OMX_ErrorNone) { return omxError; } omxError = OMX_Init(); if(omxError == OMX_ErrorNone) { if(parameters.jpeg_input) { omxError = omxclient_component_create(&client, "OMX.hantro.81x0.image.decoder", "image_decoder.jpeg", parameters.buffer_count); } else { omxError = omxclient_component_create(&client, "OMX.hantro.81x0.video.decoder", "video_decoder.h263", parameters.buffer_count); } client.store_buffers = parameters.splitted_output; client.output_name = parameters.outfile; if(omxError == OMX_ErrorNone) { omxError = omxclient_check_component_version(client.component); } else { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "Component creation failed: '%s'\n", OMX_OSAL_TraceErrorStr(omxError)); } if(omxError == OMX_ErrorNone) { if(parameters.jpeg_input) omxError = omxclient_component_initialize_image(&client, &omx_decoder_port_initialize); else omxError = omxclient_component_initialize(&client, &omx_decoder_port_initialize); if(omxError == OMX_ErrorNone) { omxError = omxlclient_initialize_buffers_fixed(&client, parameters.buffer_size, parameters. buffer_count); /* re-allocation of buffers after this is not properly defined, can't rely on port * configuration */ /* omxError = omxlclient_initialize_buffers(&client); */ } if(omxError != OMX_ErrorNone) { OMX_ERRORTYPE error = omxclient_component_free_buffers(&client); if (error != OMX_ErrorNone) { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "FreeBuffer failed: %s\n", OMX_OSAL_TraceErrorStr(omxError)); } } /* set rotation */ if(parameters.rotation != 0) { OMX_CONFIG_ROTATIONTYPE rotation; omxclient_struct_init(&rotation, OMX_CONFIG_ROTATIONTYPE); rotation.nPortIndex = 1; rotation.nRotation = parameters.rotation; if((omxError = OMX_SetConfig(client.component, OMX_IndexConfigCommonRotate, &rotation)) != OMX_ErrorNone) { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "Rotation could not be set: %s\n", OMX_OSAL_TraceErrorStr(omxError)); return omxError; } } /* set mirroring */ if(parameters.mirror != OMX_MirrorMax) { OMX_CONFIG_MIRRORTYPE mirror; omxclient_struct_init(&mirror, OMX_CONFIG_MIRRORTYPE); mirror.nPortIndex = 1; mirror.eMirror = parameters.mirror; if((omxError = OMX_SetConfig(client.component, OMX_IndexConfigCommonMirror, &mirror)) != OMX_ErrorNone) { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "Mirroring could not be set: %s\n", OMX_OSAL_TraceErrorStr(omxError)); return omxError; } } if(omxError == OMX_ErrorNone) { /* disable post-processor port */ omxError = OMX_SendCommand(client.component, OMX_CommandPortDisable, 2, NULL); if(omxError != OMX_ErrorNone) { return omxError; } /* execute conversion */ if(parameters.rcv_input) omxError = omxclient_execute_rcv(&client, parameters.infile, parameters.outfile); else omxError = omxclient_execute(&client, parameters.infile, variance_array, variance_array_len, parameters.outfile); if(omxError != OMX_ErrorNone) { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "Video processing failed: '%s'\n", OMX_OSAL_TraceErrorStr(omxError)); } } else { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "Component video initialization failed: '%s'\n", OMX_OSAL_TraceErrorStr(omxError)); } /* destroy the component since it was succesfully created */ omxError = omxclient_component_destroy(&client); if(omxError != OMX_ErrorNone) { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "Component destroy failed: '%s'\n", OMX_OSAL_TraceErrorStr(omxError)); } } OMX_Deinit(); } else { OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "OMX initialization failed: '%s'\n", OMX_OSAL_TraceErrorStr(omxError)); /* FAIL: OMX initialization failed, reason */ } return omxError; }
/* ------------------------------------------------- / audioplay_create() / Create audio decoder & render & other hardware component /---------------------------------------------------*/ static INT32 audioplay_create( AUDIOPLAY_STATE_T **handle, UINT32 sample_rate, UINT32 num_channels, UINT32 bit_depth, UINT32 num_buffers, ///< 100 UINT32 buffer_size ///< 480*(16/8)*2 = 1920 ){ OMX_AUDIO_PARAM_PCMMODETYPE pcm; UINT32 bytes_per_sample = (bit_depth * num_channels) >> 3; INT32 ret = -1; int rv; *handle = NULL; /* TODO basic sanity check on arguments */ if(sample_rate >= 8000 && sample_rate <= 96000 && (num_channels == 1 || num_channels == 2 || num_channels == 4 || num_channels == 8) && (bit_depth == 16 || bit_depth == 32) && (num_buffers > 0) && (buffer_size >= bytes_per_sample)){ /* TODO buffer length must be 16 bytes aligned for VCHI */ int size = (buffer_size + 15) & ~15; /* TODO buffer length must be 16 bytes aligned for VCHI */ st = calloc(1, sizeof(AUDIOPLAY_STATE_T)); assert(st != NULL); OMX_ERRORTYPE error; OMX_PARAM_PORTDEFINITIONTYPE param; INT32 s; ret = 0; /* TODO combine with st = calloc()?*/ *handle = st; /* create and start up audio codec hardware component */ /* TODO semaphore */ s = sem_init(&st->sema, 0 ,1); assert(s == 0); st->bytes_per_sample = bytes_per_sample; st->num_buffers = num_buffers; st->client = ilclient_init(); assert(st->client != NULL); /*TODO input_buffer_callback*/ ilclient_set_empty_buffer_done_callback(st->client, input_buffer_callback, st); error = OMX_Init(); assert(error == OMX_ErrorNone); /* Create audio render */ ilclient_create_component(st->client, &(st->audio_render), "audio_render", ILCLIENT_ENABLE_INPUT_BUFFERS | ILCLIENT_DISABLE_ALL_PORTS); assert(st->audio_render != NULL); st->list[0] = st->audio_render; /* Create clock component */ ilclient_create_component(st->client, &(st->clock), "clock", ILCLIENT_DISABLE_ALL_PORTS); assert(st->clock != NULL); st->list[1] = st->clock; /* Configure clock */ OMX_TIME_CONFIG_CLOCKSTATETYPE cstate; memset(&cstate, 0, sizeof(cstate)); cstate.nSize = sizeof(cstate); cstate.nVersion.nVersion = OMX_VERSION; cstate.eState = OMX_TIME_ClockStateWaitingForStartTime; cstate.nWaitMask = 1; //TODO error = OMX_SetParameter(ILC_GET_HANDLE(st->clock), OMX_IndexConfigTimeClockState, &cstate); assert(error == 0); /* Setup tunnel to connect clock and audio render */ set_tunnel(&st->tunnel, st->clock, 80, st->audio_render, 101); rv = ilclient_setup_tunnel(&st->tunnel, 0, 0); assert(rv == 0); /* kick off clock */ ilclient_change_component_state(st->clock, OMX_StateExecuting); /* Set audio render port definition */ /* Set up the number/size of buffers */ memset(¶m, 0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); param.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); param.nVersion.nVersion = OMX_VERSION; param.nPortIndex = 100; error = OMX_GetParameter(ILC_GET_HANDLE(st->audio_render), OMX_IndexParamPortDefinition, ¶m); assert(error == OMX_ErrorNone); param.nBufferSize = size; param.nBufferCountActual = num_buffers; error = OMX_SetParameter(ILC_GET_HANDLE(st->audio_render), OMX_IndexParamPortDefinition, ¶m); assert(error == OMX_ErrorNone); /* Set audio render PCM definition */ memset(&pcm, 0, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); pcm.nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE); pcm.nVersion.nVersion = OMX_VERSION; pcm.nPortIndex = 100; pcm.nChannels = num_channels; pcm.eNumData = OMX_NumericalDataSigned; //TODO pcm.eEndian = OMX_EndianLittle; pcm.nSamplingRate = sample_rate; pcm.bInterleaved = OMX_TRUE; pcm.nBitPerSample = bit_depth; pcm.ePCMMode = OMX_AUDIO_PCMModeLinear; switch(num_channels){ case 1: { pcm.eChannelMapping[0] = OMX_AUDIO_ChannelCF; break; } case 8: { /*TODO*/ pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF; pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF; pcm.eChannelMapping[2] = OMX_AUDIO_ChannelCF; pcm.eChannelMapping[3] = OMX_AUDIO_ChannelLFE; pcm.eChannelMapping[4] = OMX_AUDIO_ChannelLR; pcm.eChannelMapping[5] = OMX_AUDIO_ChannelRR; pcm.eChannelMapping[6] = OMX_AUDIO_ChannelLS; pcm.eChannelMapping[7] = OMX_AUDIO_ChannelRS; break; } case 4: { pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF; pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF; pcm.eChannelMapping[2] = OMX_AUDIO_ChannelLR; pcm.eChannelMapping[3] = OMX_AUDIO_ChannelRR; break; } case 2: { pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF; pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF; break; } } error = OMX_SetParameter(ILC_GET_HANDLE(st->audio_render), OMX_IndexParamAudioPcm, &pcm); assert(error == OMX_ErrorNone); /* Set audio reference clock */ OMX_CONFIG_BOOLEANTYPE ref_clock; memset(&ref_clock, 0, sizeof(OMX_CONFIG_BOOLEANTYPE)); param.nSize = sizeof(OMX_CONFIG_BOOLEANTYPE); param.nVersion.nVersion = OMX_VERSION; param.bEnabled = OMX_FALSE; error = OMX_SetConfig(ILC_GET_HANDLE(st->audio_render), OMX_IndexConfigBrcmClockReferenceSource, &ref_clock); assert(error == OMX_ErrorNone); /* Enable audio render */ ilclient_change_component_state(st->audio_render, OMX_StateIdle); if(ilclient_enable_port_buffers(st->audio_render, 100, NULL, NULL, NULL) < 0){ /* Error situation */ ilclient_change_component_state(st->audio_render, OMX_StateLoaded); ilclient_cleanup_components(st->list); error = OMX_Deinit(); assert(error == OMX_ErrorNone); ilclient_destroy(st->client); sem_destroy(&st->sema); free(st); *handle = NULL; return -1; } ilclient_change_component_state(st->audio_render, OMX_StateExecuting); } return ret; }
OMX_ERRORTYPE omx_setup_camera_pipeline(struct omx_pipeline_t* pipe) { // Create component. omx_init_component(pipe, &pipe->camera, "OMX.broadcom.camera"); // Use OMX_IndexConfigRequestCallback to request callbacks on OMX_IndexParamCameraDeviceNumber. OMX_CONFIG_REQUESTCALLBACKTYPE cbtype; OMX_INIT_STRUCTURE(cbtype); cbtype.nPortIndex=OMX_ALL; cbtype.nIndex=OMX_IndexParamCameraDeviceNumber; cbtype.bEnable = OMX_TRUE; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigRequestCallback, &cbtype)); // Set OMX_IndexParamISPTunerName. // Set OMX_IndexParamCameraFlashType. // Set OMX_IndexParamCameraDeviceNumber. OMX_PARAM_U32TYPE device; OMX_INIT_STRUCTURE(device); device.nPortIndex = OMX_ALL; device.nU32 = 0; OERR(OMX_SetParameter(pipe->camera.h, OMX_IndexParamCameraDeviceNumber, &device)); dumpport(pipe->camera.h, 71); /* Set the resolution */ OMX_PARAM_PORTDEFINITIONTYPE portdef; OMX_INIT_STRUCTURE(portdef); portdef.nPortIndex = 71; OERR(OMX_GetParameter(pipe->camera.h, OMX_IndexParamPortDefinition, &portdef)); portdef.format.image.nFrameWidth = 640; portdef.format.image.nFrameHeight = 360; portdef.format.image.nStride = 640; OERR(OMX_SetParameter(pipe->camera.h, OMX_IndexParamPortDefinition, &portdef)); /* Set the framerate */ OMX_CONFIG_FRAMERATETYPE framerate; OMX_INIT_STRUCTURE(framerate); framerate.nPortIndex = 71; framerate.xEncodeFramerate = 25 << 16; // Q16 format - 25fps OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigVideoFramerate, &framerate)); /* Set the sharpness */ OMX_CONFIG_SHARPNESSTYPE sharpness; OMX_INIT_STRUCTURE(sharpness); sharpness.nPortIndex = OMX_ALL; sharpness.nSharpness = -50; /* -100 to 100 */ OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonSharpness, &sharpness)); /* Set the contrast */ OMX_CONFIG_CONTRASTTYPE contrast; OMX_INIT_STRUCTURE(contrast); contrast.nPortIndex = OMX_ALL; contrast.nContrast = -10; /* -100 to 100 */ OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonContrast, &contrast)); /* Set the brightness */ OMX_CONFIG_BRIGHTNESSTYPE brightness; OMX_INIT_STRUCTURE(brightness); brightness.nPortIndex = OMX_ALL; brightness.nBrightness = 50; /* 0 to 100 */ OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonBrightness, &brightness)); /* Set the saturation */ OMX_CONFIG_SATURATIONTYPE saturation; OMX_INIT_STRUCTURE(saturation); saturation.nPortIndex = OMX_ALL; saturation.nSaturation = 0; /* -100 to 100 */ OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonSaturation, &saturation)); /* Video stabilisation */ OMX_CONFIG_FRAMESTABTYPE framestab; OMX_INIT_STRUCTURE(framestab); framestab.nPortIndex = OMX_ALL; framestab.bStab = OMX_FALSE; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonFrameStabilisation, &framestab)); /* Set EV compensation, ISO and metering mode */ OMX_CONFIG_EXPOSUREVALUETYPE exposurevalue; OMX_INIT_STRUCTURE(exposurevalue); exposurevalue.nPortIndex = OMX_ALL; OERR(OMX_GetConfig(pipe->camera.h, OMX_IndexConfigCommonExposureValue, &exposurevalue)); fprintf(stderr,"nSensitivity=%d\n",exposurevalue.nSensitivity); exposurevalue.xEVCompensation = 0; /* Fixed point value stored as Q16 */ exposurevalue.nSensitivity = 100; /**< e.g. nSensitivity = 100 implies "ISO 100" */ exposurevalue.bAutoSensitivity = OMX_FALSE; exposurevalue.eMetering = OMX_MeteringModeAverage; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonExposureValue, &exposurevalue)); /* Set exposure mode */ OMX_CONFIG_EXPOSURECONTROLTYPE exposure; OMX_INIT_STRUCTURE(exposure); exposure.nPortIndex = OMX_ALL; exposure.eExposureControl = OMX_ExposureControlAuto; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonExposure, &exposure)); /* Set AWB mode */ OMX_CONFIG_WHITEBALCONTROLTYPE awb; OMX_INIT_STRUCTURE(awb); awb.nPortIndex = OMX_ALL; awb.eWhiteBalControl = OMX_WhiteBalControlAuto; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonWhiteBalance, &awb)); /* Set image effect */ OMX_CONFIG_IMAGEFILTERTYPE imagefilter; OMX_INIT_STRUCTURE(imagefilter); imagefilter.nPortIndex = OMX_ALL; imagefilter.eImageFilter = OMX_ImageFilterNone; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonImageFilter, &imagefilter)); /* Set colour effect */ OMX_CONFIG_COLORENHANCEMENTTYPE colour; OMX_INIT_STRUCTURE(colour); colour.nPortIndex = OMX_ALL; colour.bColorEnhancement = OMX_FALSE; colour.nCustomizedU = 128; colour.nCustomizedV = 128; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigCommonColorEnhancement, &colour)); /* Turn off the LED - doesn't work! */ OMX_CONFIG_PRIVACYINDICATORTYPE privacy; OMX_INIT_STRUCTURE(privacy); privacy.ePrivacyIndicatorMode = OMX_PrivacyIndicatorOff; OERR(OMX_SetConfig(pipe->camera.h, OMX_IndexConfigPrivacyIndicator, &privacy)); // Wait for the callback that OMX_IndexParamCameraDeviceNumber has // changed. At this point, all the drivers have been loaded. Other // settings can be applied whilst waiting for this event. fprintf(stderr,"Waiting for camera config to change\n"); while (!pipe->camera.config_changed); /* TODO: Use a condition variable */ fprintf(stderr,"Config changed\n"); // Query for OMX_IndexConfigCameraSensorModes as required. // Change state to IDLE, and proceed as required. omx_send_command_and_wait(&pipe->camera, OMX_CommandStateSet, OMX_StateIdle, NULL); OMX_CONFIG_PORTBOOLEANTYPE cameraport; OMX_INIT_STRUCTURE(cameraport); cameraport.nPortIndex = 71; cameraport.bEnabled = OMX_TRUE; OERR(OMX_SetParameter(pipe->camera.h, OMX_IndexConfigPortCapturing, &cameraport)); omx_init_component(pipe, &pipe->video_render, "OMX.broadcom.video_render"); omx_send_command_and_wait(&pipe->video_render, OMX_CommandStateSet, OMX_StateIdle, NULL); OERR(OMX_SetupTunnel(pipe->camera.h, 71, pipe->video_render.h, 90)); /* Camera capture port to video render */ omx_send_command_and_wait(&pipe->camera, OMX_CommandPortEnable, 71, NULL); omx_send_command_and_wait(&pipe->video_render, OMX_CommandPortEnable, 90, NULL); omx_send_command_and_wait(&pipe->video_render, OMX_CommandStateSet, OMX_StateExecuting, NULL); omx_send_command_and_wait(&pipe->camera, OMX_CommandStateSet, OMX_StateExecuting, NULL); omx_set_display_region(pipe, 1200, 180, 640, 360); OMX_CONFIG_DISPLAYREGIONTYPE region; OMX_INIT_STRUCTURE(region); region.nPortIndex = 90; /* Video render input port */ region.set = OMX_DISPLAY_SET_LAYER; region.layer = 10; OERR(OMX_SetParameter(pipe->video_render.h, OMX_IndexConfigDisplayRegion, ®ion)); fprintf(stderr,"Camera pipeline configured\n"); dumpport(pipe->camera.h, 71); }
OMX_ERRORTYPE omx_setup_pipeline(struct omx_pipeline_t* pipe, OMX_VIDEO_CODINGTYPE video_codec, char* audio_dest, int is_hd) { OMX_VIDEO_PARAM_PORTFORMATTYPE format; OMX_TIME_CONFIG_CLOCKSTATETYPE cstate; OMX_CONFIG_BOOLEANTYPE configBoolTrue; OMX_INIT_STRUCTURE(configBoolTrue); configBoolTrue.bEnabled = OMX_TRUE; pipe->do_deinterlace = 0; if (((is_hd == 0) && (global_settings.deinterlace_sd)) || ((is_hd == 1) && (global_settings.deinterlace_hd))) { DEBUGF("Enabling de-interlace\n"); pipe->do_deinterlace = 1; } omx_init_component(pipe, &pipe->video_decode, "OMX.broadcom.video_decode"); omx_init_component(pipe, &pipe->video_render, "OMX.broadcom.video_render"); if (pipe->do_deinterlace) { DEBUGF("Enabling de-interlacer\n"); /* De-interlacer. Input port 190, Output port 191. Insert between decoder and scheduler */ omx_init_component(pipe, &pipe->image_fx, "OMX.broadcom.image_fx"); /* Configure image_fx */ omx_send_command_and_wait(&pipe->image_fx, OMX_CommandStateSet, OMX_StateIdle, NULL); OMX_CONFIG_IMAGEFILTERPARAMSTYPE imagefilter; OMX_INIT_STRUCTURE(imagefilter); imagefilter.nPortIndex=191; imagefilter.nNumParams=1; imagefilter.nParams[0]=3; //??? imagefilter.eImageFilter=OMX_ImageFilterDeInterlaceAdvanced; OERR(OMX_SetConfig(pipe->image_fx.h, OMX_IndexConfigCommonImageFilterParameters, &imagefilter)); } else { memset(&pipe->image_fx,0,sizeof(struct omx_component_t)); } omx_init_component(pipe, &pipe->clock, "OMX.broadcom.clock"); OMX_INIT_STRUCTURE(cstate); cstate.eState = OMX_TIME_ClockStateWaitingForStartTime; cstate.nWaitMask = OMX_CLOCKPORT0|OMX_CLOCKPORT1; OERR(OMX_SetParameter(pipe->clock.h, OMX_IndexConfigTimeClockState, &cstate)); OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refClock; OMX_INIT_STRUCTURE(refClock); refClock.eClock = OMX_TIME_RefClockAudio; OERR(OMX_SetConfig(pipe->clock.h, OMX_IndexConfigTimeActiveRefClock, &refClock)); omx_init_component(pipe, &pipe->video_scheduler, "OMX.broadcom.video_scheduler"); /* Initialise audio output - hardcoded to 48000/Stereo/16-bit */ omx_init_component(pipe, &pipe->audio_render, "OMX.broadcom.audio_render"); OMX_PARAM_PORTDEFINITIONTYPE param; OMX_INIT_STRUCTURE(param); param.nPortIndex = 100; OERR(OMX_GetParameter(pipe->audio_render.h, OMX_IndexParamPortDefinition, ¶m)); param.nBufferSize = 8192; /* Needs to be big enough for one frame of data */ param.nBufferCountActual = 32; /* Arbitrary */ OERR(OMX_SetParameter(pipe->audio_render.h, OMX_IndexParamPortDefinition, ¶m)); omx_config_pcm(&pipe->audio_render, 48000, 2, 16, audio_dest); OERR(OMX_SetConfig(pipe->audio_render.h, OMX_IndexConfigBrcmClockReferenceSource, &configBoolTrue)); omx_send_command_and_wait(&pipe->audio_render, OMX_CommandStateSet, OMX_StateIdle, NULL); omx_send_command_and_wait0(&pipe->audio_render, OMX_CommandPortEnable, 100, NULL); omx_alloc_buffers(&pipe->audio_render, 100); omx_send_command_and_wait1(&pipe->audio_render, OMX_CommandPortEnable, 100, NULL); /* Setup clock tunnels first */ omx_send_command_and_wait(&pipe->clock, OMX_CommandStateSet, OMX_StateIdle, NULL); OERR(OMX_SetupTunnel(pipe->clock.h, 80, pipe->audio_render.h, 101)); OERR(OMX_SetupTunnel(pipe->clock.h, 81, pipe->video_scheduler.h, 12)); OERR(OMX_SendCommand(pipe->clock.h, OMX_CommandPortEnable, 80, NULL)); OERR(OMX_SendCommand(pipe->video_scheduler.h, OMX_CommandPortEnable, 12, NULL)); OERR(OMX_SendCommand(pipe->clock.h, OMX_CommandPortEnable, 81, NULL)); OERR(OMX_SendCommand(pipe->audio_render.h, OMX_CommandPortEnable, 101, NULL)); omx_send_command_and_wait(&pipe->video_scheduler, OMX_CommandStateSet, OMX_StateIdle, NULL); omx_send_command_and_wait(&pipe->clock, OMX_CommandStateSet, OMX_StateExecuting, NULL); /* Configure video_decoder */ omx_send_command_and_wait(&pipe->video_decode, OMX_CommandStateSet, OMX_StateIdle, NULL); /* Enable lazy image pool destroying */ OERR(OMX_SetConfig(pipe->video_decode.h, OMX_IndexParamBrcmLazyImagePoolDestroy, &configBoolTrue)); OMX_INIT_STRUCTURE(format); format.nPortIndex = 130; format.eCompressionFormat = video_codec; OERR(OMX_SetParameter(pipe->video_decode.h, OMX_IndexParamVideoPortFormat, &format)); /* Enable error concealment for H264 only - without this, HD channels don't work reliably */ if (video_codec == OMX_VIDEO_CodingAVC) { OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE ec; OMX_INIT_STRUCTURE(ec); ec.bStartWithValidFrame = OMX_FALSE; OERR(OMX_SetParameter(pipe->video_decode.h, OMX_IndexParamBrcmVideoDecodeErrorConcealment, &ec)); } /* Enable video decoder input port */ omx_send_command_and_wait0(&pipe->video_decode, OMX_CommandPortEnable, 130, NULL); /* Allocate input buffers */ omx_alloc_buffers(&pipe->video_decode, 130); /* Wait for input port to be enabled */ omx_send_command_and_wait1(&pipe->video_decode, OMX_CommandPortEnable, 130, NULL); /* Change video_decode to OMX_StateExecuting */ omx_send_command_and_wait(&pipe->video_decode, OMX_CommandStateSet, OMX_StateExecuting, NULL); /* Change audio_render to OMX_StateExecuting */ omx_send_command_and_wait(&pipe->audio_render, OMX_CommandStateSet, OMX_StateExecuting, NULL); /* Enable passing of buffer marks */ OERR(OMX_SetParameter(pipe->video_decode.h, OMX_IndexParamPassBufferMarks, &configBoolTrue)); OERR(OMX_SetParameter(pipe->video_render.h, OMX_IndexParamPassBufferMarks, &configBoolTrue)); return OMX_ErrorNone; }
static int rpi_codec_create(media_codec_t *mc, const media_codec_params_t *mcp, media_pipe_t *mp) { int fmt; switch(mc->codec_id) { case CODEC_ID_H264: fmt = OMX_VIDEO_CodingAVC; break; case CODEC_ID_MPEG2VIDEO: if(!omx_enable_mpg2) return 1; fmt = OMX_VIDEO_CodingMPEG2; break; #if 0 case CODEC_ID_VC1: case CODEC_ID_WMV3: if(mcp->extradata_size == 0) return 1; mc->decode = vc1_pt_decode; return 0; #endif default: return 1; } rpi_video_codec_t *rvc = calloc(1, sizeof(rpi_video_codec_t)); hts_cond_init(&rvc->rvc_avail_cond, &mp->mp_mutex); omx_component_t *d = omx_component_create("OMX.broadcom.video_decode", &mp->mp_mutex, &rvc->rvc_avail_cond); if(d == NULL) { hts_cond_destroy(&rvc->rvc_avail_cond); free(rvc); return 1; } rvc->rvc_decoder = d; omx_set_state(d, OMX_StateIdle); OMX_VIDEO_PARAM_PORTFORMATTYPE format; OMX_INIT_STRUCTURE(format); format.nPortIndex = 130; format.eCompressionFormat = fmt; omxchk(OMX_SetParameter(d->oc_handle, OMX_IndexParamVideoPortFormat, &format)); OMX_PARAM_BRCMVIDEODECODEERRORCONCEALMENTTYPE ec; OMX_INIT_STRUCTURE(ec); ec.bStartWithValidFrame = OMX_FALSE; omxchk(OMX_SetParameter(d->oc_handle, OMX_IndexParamBrcmVideoDecodeErrorConcealment, &ec)); OMX_CONFIG_BOOLEANTYPE bt; OMX_INIT_STRUCTURE(bt); bt.bEnabled = 1; omxchk(OMX_SetConfig(d->oc_handle, OMX_IndexParamBrcmInterpolateMissingTimestamps, &bt)); omx_alloc_buffers(d, 130); omx_set_state(d, OMX_StateExecuting); if(mcp->extradata_size) { hts_mutex_lock(&mp->mp_mutex); OMX_BUFFERHEADERTYPE *buf = omx_get_buffer_locked(rvc->rvc_decoder); hts_mutex_unlock(&mp->mp_mutex); buf->nOffset = 0; buf->nFilledLen = mcp->extradata_size; memcpy(buf->pBuffer, mcp->extradata, buf->nFilledLen); buf->nFlags = OMX_BUFFERFLAG_CODECCONFIG; omxchk(OMX_EmptyThisBuffer(rvc->rvc_decoder->oc_handle, buf)); } mc->opaque = rvc; mc->close = rpi_codec_close; mc->decode = rpi_codec_decode; mc->flush = rpi_codec_flush; return 0; }
int bufHandleTest() { OMX_ERRORTYPE err = OMX_ErrorNone; OMX_BOOL bOmxInitialized = OMX_FALSE; OMX_PARAM_PORTDEFINITIONTYPE sOmxPortDefinition; OMX_CONFIG_BOOLEANTYPE sOmxCapturing; OMX_CONFIG_BOOLEANTYPE sOmxAutoPause; OMX_STATETYPE sOmxState; OMX_U32 nBufferCount; OMX_U32 nBufferSize; OMX_U32 nPortIndex; OMX_U32 i; unsigned int nPreviewTime = 5;/* By default, running for 5 sec for preview */ unsigned int nCaptureTime = 5;/* By default, running for 5 sec for video capture */ OMX_BOOL bCameraStillImageMode = OMX_FALSE; /* By default, the camera is running in video capture mode */ OMX_BOOL bCameraAutoPause = OMX_FALSE; /* By default, the camera is not running in autopause mode */ unsigned int nMaxRunCount = 1;/* By default, running once */ unsigned int nRunCount = 0; buffer_handle_t bufHandle; OMX_S32 bufStride; int ret = 0; surface_display_main_init(DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HEIGHT); /* Init the Omx core */ DEBUG(DEB_LEV_SIMPLE_SEQ, "Init the OMX core\n"); if ((err = OMX_Init()) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "The OpenMAX core can not be initialized. Exiting...\n"); goto EXIT; } bOmxInitialized = OMX_TRUE; /* Initialize application private data */ appPriv = malloc(sizeof(appPrivateType)); if (appPriv == NULL) { DEBUG(DEB_LEV_ERR, "Allocate app private data failed!Exiting...\n"); err = OMX_ErrorInsufficientResources; goto EXIT; } memset(appPriv, 0, sizeof(appPrivateType)); memset(&sCameraPortBufferList, 0, NUM_CAMERAPORTS * sizeof(OMX_PORTBUFFERCTXT)); /* Getting camera component handle */ if ((err = OMX_GetHandle(&appPriv->camerahandle, "OMX.Action.Camera.Yuv", appPriv, &camera_source_callbacks)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Getting camera component handle failed!Exiting...\n"); goto EXIT; } //sensor select { OMX_PARAM_SENSORSELECTTYPE sensorType; setHeader(&sensorType, sizeof(OMX_PARAM_SENSORSELECTTYPE)); sensorType.eSensor = OMX_PrimarySensor; if ((err = OMX_SetParameter(appPriv->camerahandle, OMX_ACT_IndexParamSensorSelect, &sensorType)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Set sensor type failed!Exiting...\n"); goto EXIT; } } /* Setting parameters for camera component */ if ((err = setCameraParameters(bCameraStillImageMode)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Set camera parameters failed! Use default settings...\n"); /* Do not exit! */ } //set store metadata { for (nPortIndex = OMX_CAMPORT_INDEX_VF; nPortIndex <= OMX_CAMPORT_INDEX_CP; nPortIndex++) { StoreMetaDataInBuffersParams storeMetaData; setHeader(&storeMetaData, sizeof(StoreMetaDataInBuffersParams)); storeMetaData.bStoreMetaData = OMX_TRUE; storeMetaData.nPortIndex = nPortIndex; if ((err = OMX_SetParameter(appPriv->camerahandle, OMX_IndexParameterStoreMediaData, &storeMetaData)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Set store metadata failed!Exiting...\n"); goto EXIT; } } } /* Allocate and init semaphores */ appPriv->cameraSourceEventSem = malloc(sizeof(tsem_t)); if (appPriv->cameraSourceEventSem == NULL) { DEBUG(DEB_LEV_ERR, "Allocate camera event semaphore failed!Exiting...\n"); err = OMX_ErrorInsufficientResources; goto EXIT; } tsem_init(appPriv->cameraSourceEventSem, 0); RUN_AGAIN: for (nPortIndex = OMX_CAMPORT_INDEX_VF; nPortIndex <= OMX_CAMPORT_INDEX_CP; nPortIndex++) { if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandPortEnable, nPortIndex, NULL)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Camera Idle-->Exec failed!Exiting...\n"); goto EXIT; } tsem_down(appPriv->cameraSourceEventSem); } /* Transition camera component Loaded-->Idle */ if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Camera Loaded-->Idle failed!Exiting...\n"); goto EXIT; } /* Allocate port buffers for camera component */ for (nPortIndex = OMX_CAMPORT_INDEX_VF; nPortIndex <= OMX_CAMPORT_INDEX_CP; nPortIndex++) { setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); sOmxPortDefinition.nPortIndex = nPortIndex; if ((err = OMX_GetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) { DEBUG( DEB_LEV_ERR, "OMX_GetParameter for camera on OMX_IndexParamPortDefinition index failed!Exiting...\n"); goto EXIT; } nBufferCount = sOmxPortDefinition.nBufferCountActual; nBufferSize = sOmxPortDefinition.nBufferSize; DEBUG( DEB_LEV_SIMPLE_SEQ, "Camera port[%ld] needs %ld buffers each of which is %ld bytes\n", nPortIndex, nBufferCount, nBufferSize); for (i = 0; i < nBufferCount; i++) { ret = bufferHandleAlloc(nBufferSize, 1, HAL_PIXEL_FORMAT_RGB_565,GRALLOC_USAGE_HW_CAMERA, &bufHandle,(int32_t *)&bufStride); if(ret != 0) { DEBUG(DEB_LEV_ERR, "Allocate port handle buffer for camera failed!Exiting...\n"); goto EXIT; } if ((err = OMX_UseBuffer(appPriv->camerahandle, &sCameraPortBufferList[nPortIndex].pBufHeaderList[i], nPortIndex, NULL, nBufferSize, (OMX_U8 *)bufHandle)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Allocate port buffer for camera failed!Exiting...\n"); goto EXIT; } sCameraPortBufferList[nPortIndex].nBufferCountActual++; } } /* Wait camera (Loaded-->Idle) to complete */ tsem_down(appPriv->cameraSourceEventSem); /* Transition camera component Idle-->Exec */ if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Camera Idle-->Exec failed!Exiting...\n"); goto EXIT; } /* Wait camera (Idle-->Exec) to complete */ tsem_down(appPriv->cameraSourceEventSem); /* Fill buffers to camera preview port */ for (i = 0; i < sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].nBufferCountActual; i++) { sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i]->nFilledLen = 0; sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i]->nOffset = 0; if ((err = OMX_FillThisBuffer(appPriv->camerahandle, sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i])) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Fill buffer to camera capture port failed!Exiting...,%d\n",__LINE__); goto EXIT; } DEBUG( DEB_LEV_SIMPLE_SEQ, "%s: Fill buffer[%ld] (0x%lX) to camera capture port\n", __func__, i, (OMX_U32) sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i]); } /* Fill buffers to camera capture port */ for (i = 0; i < sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].nBufferCountActual; i++) { sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]->nFilledLen = 0; sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]->nOffset = 0; if ((err = OMX_FillThisBuffer(appPriv->camerahandle, sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i])) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Fill buffer to camera capture port failed!Exiting...%d\n",__LINE__); goto EXIT; } DEBUG( DEB_LEV_SIMPLE_SEQ, "%s: Fill buffer[%ld] (0x%lX) to camera capture port\n", __func__, i, (OMX_U32) sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]); } fprintf(stdout, "Start preview, for %d sec...\n", nPreviewTime); sleep(nPreviewTime); /* Set up autopause mode */ setHeader(&sOmxAutoPause, sizeof(OMX_CONFIG_BOOLEANTYPE)); sOmxAutoPause.bEnabled = bCameraAutoPause; if ((err = OMX_SetConfig(appPriv->camerahandle, OMX_IndexAutoPauseAfterCapture, &sOmxAutoPause)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Set autopause mode failed!Use default settings...\n"); /* Do not exit */ } /* Start capturing */ setHeader(&sOmxCapturing, sizeof(OMX_CONFIG_BOOLEANTYPE)); sOmxCapturing.bEnabled = OMX_TRUE; if ((err = OMX_SetConfig(appPriv->camerahandle, OMX_IndexConfigCapturing, &sOmxCapturing)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Start capturing failed!Exiting...\n"); goto EXIT; } fprintf(stdout, "Start capturing, for %d sec...\n", nCaptureTime); DEBUG(DEB_LEV_ERR, "Start capturing, for %d sec...\n", nCaptureTime); sleep(nCaptureTime); /* Stop capturing */ if (!bCameraStillImageMode) { setHeader(&sOmxCapturing, sizeof(OMX_CONFIG_BOOLEANTYPE)); sOmxCapturing.bEnabled = OMX_FALSE; if ((err = OMX_SetConfig(appPriv->camerahandle, OMX_IndexConfigCapturing, &sOmxCapturing)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Stop capturing failed!Exiting...\n"); goto EXIT; } fprintf(stdout, "Stop capturing...\n"); } /* If in autopause mode, stay for a while before exit */ if (bCameraAutoPause) { fprintf( stdout,"pause state for capture, sleep(%d)\n",5); sleep(5); /* Stop autopause mode */ if ((err = OMX_GetState(appPriv->camerahandle, &sOmxState)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Get camera state failed!Exiting...\n"); goto EXIT; } if (sOmxState == OMX_StatePause) { if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateExecuting, 0)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Pause-->Exec failed!Exiting...\n"); goto EXIT; } /* Wait camera (Pause-->Exec) to complete */ tsem_down(appPriv->cameraSourceEventSem); fprintf( stdout, "Now the camera is out of autopause mode, wait for %d sec before exit...\n", 5); sleep(5); } else { DEBUG(DEB_LEV_ERR, "The camera is not in Pause state in autopause mode, ignore...\n"); } } #if 1 #if 0 /* Transition camera component Exec-->Idle */ if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Camera Exec-->Idle failed!Exiting...\n"); goto EXIT; } /* Wait camera (Exec-->Idle) to complete */ tsem_down(appPriv->cameraSourceEventSem); /* Transition camera component Idle-->Exec */ if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Camera Idle-->Exec failed!Exiting...\n"); goto EXIT; } /* Wait camera (Idle-->Exec) to complete */ tsem_down(appPriv->cameraSourceEventSem); /* Fill buffers to camera preview port */ for (i = 0; i < sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].nBufferCountActual; i++) { sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i]->nFilledLen = 0; sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i]->nOffset = 0; if ((err = OMX_FillThisBuffer(appPriv->camerahandle, sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i])) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Fill buffer to camera capture port failed!Exiting...%d\n",__LINE__); goto EXIT; } DEBUG( DEB_LEV_SIMPLE_SEQ, "%s: Fill buffer[%ld] (0x%lX) to camera capture port\n", __func__, i, (OMX_U32) sCameraPortBufferList[OMX_CAMPORT_INDEX_VF].pBufHeaderList[i]); } /* Fill buffers to camera capture port */ for (i = 0; i < sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].nBufferCountActual; i++) { sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]->nFilledLen = 0; sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]->nOffset = 0; if ((err = OMX_FillThisBuffer(appPriv->camerahandle, sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i])) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Fill buffer to camera capture port failed!Exiting...%d\n",__LINE__); goto EXIT; } DEBUG( DEB_LEV_SIMPLE_SEQ, "%s: Fill buffer[%ld] (0x%lX) to camera capture port\n", __func__, i, (OMX_U32) sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]); } #endif fprintf(stdout, "Continue to preview, for %d sec...\n", nPreviewTime); sleep(nPreviewTime); #endif /* Transition camera component Exec-->Idle */ if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Camera Exec-->Idle failed!Exiting...\n"); goto EXIT; } /* Wait camera (Exec-->Idle) to complete */ tsem_down(appPriv->cameraSourceEventSem); /* Transition camera component Idle-->Loaded */ if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Camera Idle-->Loaded failed!Exiting...\n"); goto EXIT; } #if 1 /* Free bufers for each non-tunneled port of camera component */ for (nPortIndex = OMX_CAMPORT_INDEX_VF; nPortIndex <= OMX_CAMPORT_INDEX_CP; nPortIndex++) { for (i = 0; i < sCameraPortBufferList[nPortIndex].nBufferCountActual; i++) { if (sCameraPortBufferList[nPortIndex].pBufHeaderList[i] != NULL) { bufHandle = (buffer_handle_t)sCameraPortBufferList[nPortIndex].pBufHeaderList[i]->pBuffer; OMX_FreeBuffer(appPriv->camerahandle, nPortIndex, sCameraPortBufferList[nPortIndex].pBufHeaderList[i]); bufferHandleAllocFree(bufHandle); } } sCameraPortBufferList[nPortIndex].nBufferCountActual = 0; } #endif /* Wait camera (Idle-->Loaded) to complete */ tsem_down(appPriv->cameraSourceEventSem); nRunCount++; if (nRunCount < nMaxRunCount) { goto RUN_AGAIN; } EXIT: for (nPortIndex = OMX_CAMPORT_INDEX_VF; nPortIndex <= OMX_CAMPORT_INDEX_CP; nPortIndex++) { for (i = 0; i < sCameraPortBufferList[nPortIndex].nBufferCountActual; i++) { if (sCameraPortBufferList[nPortIndex].pBufHeaderList[i] != NULL) { bufHandle = (buffer_handle_t)sCameraPortBufferList[nPortIndex].pBufHeaderList[i]->pBuffer; OMX_FreeBuffer(appPriv->camerahandle, nPortIndex, sCameraPortBufferList[nPortIndex].pBufHeaderList[i]); DEBUG(DEB_LEV_ERR, "bufferHandleAllocFree...%d\n",__LINE__); bufferHandleAllocFree(bufHandle); } } sCameraPortBufferList[nPortIndex].nBufferCountActual = 0; } /* Free app private data */ if (appPriv != NULL) { /* Free semaphores */ if (appPriv->cameraSourceEventSem != NULL) { tsem_deinit(appPriv->cameraSourceEventSem); free(appPriv->cameraSourceEventSem); } /* Free camera component handle */ if (appPriv->camerahandle != NULL) { OMX_FreeHandle(appPriv->camerahandle); } free(appPriv); } /* Deinit the Omx core */ if (bOmxInitialized) { OMX_Deinit(); } return (int) err; }
///////////////////////////////////////////////////////// // savePhoto() saves a photo locally // needs to be passed camera component and image_encode component // because it has to directly manipulate the ports on both void savePhoto(COMPONENT_T *camera, COMPONENT_T *image_encode, char *filePrefix, char *filePostFix) { printf("in savePhoto\n"); OMX_ERRORTYPE OMXstatus; OMX_BUFFERHEADERTYPE *decode_out; printf("filePreFix = %s filePostFix = %s", filePrefix, filePostFix); printf("%s\n", fileFindNext(filePrefix, filePostFix)); FILE *file_out; file_out = fopen(fileFindNext(filePrefix, filePostFix), "wb"); //check file? printf("capture started\n"); // needed to notify camera component of image capture OMX_CONFIG_PORTBOOLEANTYPE still_capture_in_progress; memset(&still_capture_in_progress, 0, sizeof(still_capture_in_progress)); still_capture_in_progress.nVersion.nVersion = OMX_VERSION; still_capture_in_progress.nSize = sizeof(still_capture_in_progress); still_capture_in_progress.nPortIndex = 72; still_capture_in_progress.bEnabled = OMX_FALSE; //tell camera component port is taking picture - appears to be nessesery! still_capture_in_progress.bEnabled = OMX_TRUE; OMXstatus = OMX_SetConfig(ilclient_get_handle(camera), OMX_IndexConfigPortCapturing, &still_capture_in_progress); if (OMXstatus != OMX_ErrorNone) { fprintf(stderr, "unable to set Config (1)\n"); exit(EXIT_FAILURE); } while(1) { decode_out = ilclient_get_output_buffer(image_encode, 341, 1/*blocking*/); printf("decode_out bytes = %d : ", decode_out->nFilledLen); printf("decode_out bufferflags = %d\n", decode_out->nFlags); if(decode_out->nFilledLen != 0) { fwrite(decode_out->pBuffer, 1, decode_out->nFilledLen, file_out); } if(decode_out->nFlags == 1) { fwrite(decode_out->pBuffer, 1, decode_out->nFilledLen, file_out); OMX_FillThisBuffer(ilclient_get_handle(image_encode), decode_out); break; } //crashes if starts with 0 buffer? OMX_FillThisBuffer(ilclient_get_handle(image_encode), decode_out); } //tell API port is finished capture memset(&still_capture_in_progress, 0, sizeof(still_capture_in_progress)); still_capture_in_progress.nVersion.nVersion = OMX_VERSION; still_capture_in_progress.nSize = sizeof(still_capture_in_progress); still_capture_in_progress.nPortIndex = 72; still_capture_in_progress.bEnabled = OMX_FALSE; OMXstatus = OMX_SetConfig(ilclient_get_handle(camera), OMX_IndexConfigPortCapturing, &still_capture_in_progress); if (OMXstatus != OMX_ErrorNone) { fprintf(stderr, "unable to set Config (1)\n"); exit(EXIT_FAILURE); } fclose(file_out); printf("captureSaved\n"); }
/* ------------------------------------------------- / sx_video_sink_init() / /---------------------------------------------------*/ void sx_video_sink_init(void){ OMX_VIDEO_PARAM_PORTFORMATTYPE format; OMX_TIME_CONFIG_CLOCKSTATETYPE cstate; int rc; /* Init compoent & tunnel */ memset(comp_list, 0, sizeof(comp_list)); memset(tunnel, 0, sizeof(tunnel)); /* Init Broadcom host */ bcm_host_init(); /* Init il client */ client = ilclient_init(); assert(client != NULL); /* Init OpenMax */ rc = OMX_Init(); assert(rc == OMX_ErrorNone); /* Create Decoder Component,beacuse enable input buffers,so in the end need to OMX_EmptyThisBuffer */ rc = ilclient_create_component( client, &video_decode, "video_decode", ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS); assert(rc == 0); comp_list[0] = video_decode; /* Create video render */ rc = ilclient_create_component( client, &video_render, "video_render", ILCLIENT_DISABLE_ALL_PORTS); assert(rc == 0); comp_list[1] = video_render; /* Create clock */ rc = ilclient_create_component( client, &video_clock, "clock", ILCLIENT_DISABLE_ALL_PORTS); assert(rc == 0); comp_list[2] = video_clock; /* Configure clock */ memset(&cstate, 0, sizeof(cstate)); cstate.nSize = sizeof(cstate); cstate.nVersion.nVersion = OMX_VERSION; cstate.eState = OMX_TIME_ClockStateWaitingForStartTime; cstate.nWaitMask = 1; rc = OMX_SetParameter(ILC_GET_HANDLE(video_clock), OMX_IndexConfigTimeClockState, &cstate); assert(rc == 0); /* Create video scheduler */ rc = ilclient_create_component( client, &video_scheduler, "video_scheduler", ILCLIENT_DISABLE_ALL_PORTS); assert(rc == 0); comp_list[3] = video_scheduler; /* Set tunnels */ /* Connect decode to scheduler */ set_tunnel(tunnel, video_decode, 131, video_scheduler, 10); /* Connect scheduler to render */ set_tunnel(tunnel+1, video_scheduler, 11, video_render, 90); /* Connect clock to scheduler */ set_tunnel(tunnel+2, video_clock, 80, video_scheduler, 12); /* Setup clock tunnel first */ rc = ilclient_setup_tunnel(tunnel+2, 0, 0); assert(rc == 0); /* Kick start the clock */ ilclient_change_component_state(video_clock, OMX_StateExecuting); #define AUTO_FULLSCREEN #if 1 OMX_CONFIG_DISPLAYREGIONTYPE drt; memset(&drt, 0, sizeof(drt)); drt.nVersion.nVersion = OMX_VERSION; drt.nSize = sizeof(drt); drt.nPortIndex = 90; /* if not defined AUTO_FULLSCREEN it means that set other display region type */ #if 0 #if !defined(AUTO_FULLSCREEN) /*TODO*/ drt.src_rect.x_offset = 0; drt.src_rect.y_offset = 0; drt.src_rect.width = sx_mgmt_env_get(MGMT_ENV_VAR_SESSION_WIDTH); drt.src_rect.height = sx_mgmt_env_get(MGMT_ENV_VAR_SESSION_HEIGHT); drt.dest_rect.x_offset = -56; drt.dest_rect.y_offset = 0; drt.dest_rect.width = 1792; drt.dest_rect.height = 1050; #endif #endif #if !defined(AUTO_FULLSCREEN) drt.fullscreen = OMX_FALSE; #else /* define AUTO_FULLSCREEN */ drt.fullscreen = OMX_TRUE; #endif drt.noaspect = OMX_TRUE; drt.mode = OMX_DISPLAY_MODE_FILL; #if !defined(AUTO_FULLSCREEN) /*TODO*/ drt.set = (OMX_DISPLAYSETTYPE) ( OMX_DISPLAY_SET_SRC_RECT | OMX_DISPLAY_SET_DEST_RECT | OMX_DISPLAY_SET_FULLSCREEN | OMX_DISPLAY_SET_NOASPECT); #else drt.set = (OMX_DISPLAYSETTYPE) (OMX_DISPLAY_SET_FULLSCREEN | OMX_DISPLAY_SET_NOASPECT); #endif rc = OMX_SetConfig(ILC_GET_HANDLE(video_render), OMX_IndexConfigDisplayRegion, &drt); assert(rc==0); #endif /* Kick start video decoder */ ilclient_change_component_state(video_decode, OMX_StateIdle); /*TODO Configure decoder */ memset(&format, 0, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE)); format.nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE); format.nVersion.nVersion = OMX_VERSION; format.nPortIndex = 130; format.eCompressionFormat = OMX_VIDEO_CodingAVC; rc = OMX_SetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamVideoPortFormat, &format); assert(rc == 0); /* Enable video decode */ rc = ilclient_enable_port_buffers(video_decode, 130, NULL, NULL, NULL); assert(rc ==0); /* Kick start video decode */ ilclient_change_component_state(video_decode, OMX_StateExecuting); printf("decoder_hw: initialized"); }
// sets the preview size and position // takes the enum displayTypes the contents of which should hopefully be self explanitory void setRenderConfig(COMPONENT_T *video_render, enum displayTypes presetScreenConfig) { struct screenSizeStruct currentScreenSize; currentScreenSize = returnScreenSize(); int screenWidth = currentScreenSize.width; int screenHeight = currentScreenSize.height; printf("in setRenderConfig\n"); OMX_ERRORTYPE OMXstatus; OMX_CONFIG_DISPLAYREGIONTYPE render_config; memset(&render_config, 0, sizeof(render_config)); render_config.nVersion.nVersion = OMX_VERSION; render_config.nSize = sizeof(render_config); render_config.nPortIndex = 90; //curently only does fullscreen modify the stucture below with switch/if statements for the others render_config.set = (OMX_DISPLAYSETTYPE)(OMX_DISPLAY_SET_DEST_RECT |OMX_DISPLAY_SET_FULLSCREEN |OMX_DISPLAY_SET_NOASPECT |OMX_DISPLAY_SET_MODE); //FULLSCREEN if(presetScreenConfig == DISPLAY_FULLSCREEN) { render_config.dest_rect.width = screenWidth; render_config.dest_rect.height = screenHeight; render_config.dest_rect.x_offset = 0; render_config.dest_rect.y_offset = 0; } //SIDEBYSIDE else if(presetScreenConfig == DISPLAY_SIDEBYSIDE_LEFT) { render_config.dest_rect.width = screenWidth/2; render_config.dest_rect.height = screenHeight; render_config.dest_rect.x_offset = 0; render_config.dest_rect.y_offset = 0; } else if(presetScreenConfig == DISPLAY_SIDEBYSIDE_RIGHT) { render_config.dest_rect.width = screenWidth/2; render_config.dest_rect.height = screenHeight; render_config.dest_rect.x_offset = screenWidth/2; render_config.dest_rect.y_offset = 0; } //QUARTER else if(presetScreenConfig == DISPLAY_QUARTER_TOP_LEFT) { render_config.dest_rect.width = screenWidth/2; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = 0; render_config.dest_rect.y_offset = 0; } else if(presetScreenConfig == DISPLAY_QUARTER_TOP_RIGHT) { render_config.dest_rect.width = screenWidth/2; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = screenWidth/2;; render_config.dest_rect.y_offset = 0; } else if(presetScreenConfig == DISPLAY_QUARTER_BOTTOM_LEFT) { render_config.dest_rect.width = screenWidth/2; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = 0; render_config.dest_rect.y_offset = screenHeight/2; } else if(presetScreenConfig == DISPLAY_QUARTER_BOTTOM_RIGHT) { render_config.dest_rect.width = screenWidth/2; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = screenWidth/2; render_config.dest_rect.y_offset = screenHeight/2; } //SIXTH else if(presetScreenConfig == DISPLAY_SIXTH_TOP_LEFT) { render_config.dest_rect.width = screenWidth/3; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = 0; render_config.dest_rect.y_offset = 0; } else if(presetScreenConfig == DISPLAY_SIXTH_TOP_MIDDLE) { render_config.dest_rect.width = screenWidth/3; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = screenWidth/3; render_config.dest_rect.y_offset = 0; } else if(presetScreenConfig == DISPLAY_SIXTH_TOP_RIGHT) { render_config.dest_rect.width = screenWidth/3; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = (screenWidth/3)*2; render_config.dest_rect.y_offset = 0; } else if(presetScreenConfig == DISPLAY_SIXTH_BOTTOM_LEFT) { render_config.dest_rect.width = screenWidth/3; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = 0; render_config.dest_rect.y_offset = screenHeight/2; } else if(presetScreenConfig == DISPLAY_SIXTH_BOTTOM_MIDDLE) { render_config.dest_rect.width = screenWidth/3; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = screenWidth/3; render_config.dest_rect.y_offset = screenHeight/2; } else if(presetScreenConfig == DISPLAY_SIXTH_BOTTOM_RIGHT) { render_config.dest_rect.width = screenWidth/3; render_config.dest_rect.height = screenHeight/2; render_config.dest_rect.x_offset = (screenWidth/3)*2; render_config.dest_rect.y_offset = screenHeight/2; } render_config.fullscreen = OMX_FALSE; render_config.noaspect = OMX_FALSE; render_config.mode = OMX_DISPLAY_MODE_LETTERBOX; OMXstatus = OMX_SetConfig(ilclient_get_handle(video_render), OMX_IndexConfigDisplayRegion, &render_config); if(OMXstatus != OMX_ErrorNone) printf("Error Setting Parameter. Error = %s\n", err2str(OMXstatus)); }
void *initServerRcam(void *VoidPtrArgs) { struct cameraControl *currentArgs = VoidPtrArgs; pthread_mutex_lock(¤tArgs->mutexPtr); ILCLIENT_T *client = currentArgs->client; pthread_mutex_unlock(¤tArgs->mutexPtr); /////////////////////////////////////////// // Variables COMPONENT_T *client_video_render = NULL; OMX_ERRORTYPE OMXstatus; OMX_BUFFERHEADERTYPE *client_video_render_in; OMX_PARAM_PORTDEFINITIONTYPE render_params; memset(&render_params, 0, sizeof(render_params)); render_params.nVersion.nVersion = OMX_VERSION; render_params.nSize = sizeof(render_params); render_params.nPortIndex = 90; enum rcam_command rcam_command = NO_COMMAND; /////////////////////////////////////////// ////Initialise client video render pthread_mutex_lock(¤tArgs->mutexPtr); ilclient_create_component(client, &client_video_render, "video_render", ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS); OMXstatus = ilclient_change_component_state(client_video_render, OMX_StateIdle); if (OMXstatus != OMX_ErrorNone) { fprintf(stderr, "unable to move render component to Idle (1)\n"); exit(EXIT_FAILURE); } //set the port params to the same as remoteCam.c // !!! // needs the checks that the local camera does // to ensure sanity as only particular values excepted (OR DOES IT ALREADY DO THIS ? IT MIGHT BE) OMXstatus = OMX_GetConfig(ilclient_get_handle(client_video_render), OMX_IndexParamPortDefinition, &render_params); if (OMXstatus != OMX_ErrorNone) printf("Error Getting video render port parameters (1)"); render_params.format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar; render_params.format.video.nFrameWidth = currentArgs->previewWidth; render_params.format.video.nFrameHeight = currentArgs->previewHeight; render_params.format.video.nStride = currentArgs->previewWidth; render_params.format.video.nSliceHeight = currentArgs->previewHeight; render_params.format.video.xFramerate = currentArgs->previewFramerate << 16; OMXstatus = OMX_SetConfig(ilclient_get_handle(client_video_render), OMX_IndexParamPortDefinition, &render_params); if (OMXstatus != OMX_ErrorNone) printf("Error Setting video render port parameters (1)"); //check(print) the port params memset(&render_params, 0, sizeof(render_params)); render_params.nVersion.nVersion = OMX_VERSION; render_params.nSize = sizeof(render_params); render_params.nPortIndex = 90; OMXstatus = OMX_GetConfig(ilclient_get_handle(client_video_render), OMX_IndexParamPortDefinition, &render_params); if (OMXstatus != OMX_ErrorNone) printf("Error Getting video render port parameters (1)"); print_OMX_PARAM_PORTDEFINITIONTYPE(render_params); //ask ilclient to allocate buffers for client_video_render //printf("enable client_video_render_input port\n"); ilclient_enable_port_buffers(client_video_render, 90, NULL, NULL, NULL); ilclient_enable_port(client_video_render, 90); //change preview render to executing OMXstatus = ilclient_change_component_state(client_video_render, OMX_StateExecuting); if (OMXstatus != OMX_ErrorNone) { fprintf(stderr, "unable to move video render component to Executing (1)\n"); exit(EXIT_FAILURE); } printf("client_video_render state is "); printState(ilclient_get_handle(client_video_render)); printf("***\n"); //set the position on the screen setRenderConfig(client_video_render, currentArgs->displayType); ///////////////////////////////////////////////////////////////// // SOCKET STUFF printf("start of socket stuff in rcam\n"); int socket_fd = 0, client_socket_fd = 0; socket_fd = getAndBindTCPServerSocket(PORT); printf("waiting for remotecam to connect\n"); client_socket_fd = listenAndAcceptTCPServerSocket(socket_fd, 10/*backlog*/); //////////////////////////////////////////////////////////// // INITIATE RCAM_REMOTE_SLAVE char char_buffer[12]; //handshake printf("waiting to recive handshake ... \n"); read(client_socket_fd, char_buffer, 11); printf("handshake result = %s", char_buffer); write(client_socket_fd, "got\0", sizeof(char)*4); //initalize preview write(client_socket_fd, ¤tArgs->previewWidth, sizeof(currentArgs->previewWidth)); write(client_socket_fd, ¤tArgs->previewHeight, sizeof(currentArgs->previewHeight)); write(client_socket_fd, ¤tArgs->previewFramerate, sizeof(currentArgs->previewFramerate)); //initalize capture write(client_socket_fd, ¤tArgs->photoWidth, sizeof(currentArgs->photoWidth)); write(client_socket_fd, ¤tArgs->photoHeight, sizeof(currentArgs->photoHeight)); pthread_mutex_unlock(¤tArgs->mutexPtr); //////////////////////////////////////////////////////////// //// Main Thread Loop void * preview_buffer; preview_buffer = malloc(render_params.nBufferSize + 1 ); printf("***preview nBufferSize = %d\n", render_params.nBufferSize); int photo_buffer_size; void * photo_buffer; //photo_buffer = malloc(); long int num_bytes = 0; enum rcam_command current_command = START_PREVIEW; printf("current_command = %d\n", current_command); printf("sending command ..."); write(client_socket_fd, ¤t_command, sizeof(current_command)); printf("sent command\n"); current_command = NO_COMMAND; // possibly abandon current command struct // and serialize the cameraControlStruct and sent that instead // see: http://stackoverflow.com/questions/1577161/passing-a-structure-through-sockets-in-c int count = 500; while(1) { pthread_mutex_lock(¤tArgs->mutexPtr); if (currentArgs->previewChanged == true) { printf("In previewChanged\n"); //needs to: //change the renderer params this side OMXstatus = ilclient_change_component_state(client_video_render, OMX_StateIdle); memset(&render_params, 0, sizeof(render_params)); render_params.nVersion.nVersion = OMX_VERSION; render_params.nSize = sizeof(render_params); render_params.nPortIndex = 90; OMXstatus = OMX_GetConfig(ilclient_get_handle(client_video_render), OMX_IndexParamPortDefinition, &render_params); if (OMXstatus != OMX_ErrorNone) printf("Error Getting video render port parameters (in loop)"); render_params.format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar; render_params.format.video.nFrameWidth = currentArgs->previewWidth; render_params.format.video.nFrameHeight = currentArgs->previewHeight; render_params.format.video.nStride = currentArgs->previewWidth; render_params.format.video.nSliceHeight = currentArgs->previewHeight; render_params.format.video.xFramerate = currentArgs->previewFramerate << 16; OMXstatus = OMX_SetConfig(ilclient_get_handle(client_video_render), OMX_IndexParamPortDefinition, &render_params); if (OMXstatus != OMX_ErrorNone) printf("Error Setting video render port parameters (in loop)"); OMXstatus = ilclient_change_component_state(client_video_render, OMX_StateExecuting); //resize the preview buffer memset(&render_params, 0, sizeof(render_params)); render_params.nVersion.nVersion = OMX_VERSION; render_params.nSize = sizeof(render_params); render_params.nPortIndex = 90; OMXstatus = OMX_GetConfig(ilclient_get_handle(client_video_render), OMX_IndexParamPortDefinition, &render_params); if (OMXstatus != OMX_ErrorNone) printf("Error Getting video render port parameters (in loop)"); free(preview_buffer); preview_buffer = malloc(render_params.nBufferSize + 1); //change the preview on the remote side current_command = SET_PREVIEW_RES; write(client_socket_fd, ¤t_command, sizeof(current_command)); //send needed paramaters to rcam_remote_slave for the preview change write(client_socket_fd, ¤tArgs->previewWidth, sizeof(currentArgs->previewWidth)); write(client_socket_fd, ¤tArgs->previewHeight, sizeof(currentArgs->previewHeight)); write(client_socket_fd, ¤tArgs->previewFramerate, sizeof(currentArgs->previewFramerate)); //!!! //possibly wait for confirmation currentArgs->previewChanged = false; sleep(1); } else if (currentArgs->photoChanged == true) { printf("in photoChanged !\n"); //needs to: //change the capture res on the remote side current_command = SET_CAPTURE_RES; write(client_socket_fd, ¤t_command, sizeof(current_command)); //send needed paramaters to rcam_remote_slave for the photo change write(client_socket_fd, ¤tArgs->previewWidth, sizeof(currentArgs->previewWidth)); write(client_socket_fd, ¤tArgs->previewHeight, sizeof(currentArgs->previewHeight)); //change the photo_buffer?? read(client_socket_fd, &photo_buffer_size, sizeof(photo_buffer_size)); free(photo_buffer); photo_buffer = malloc(photo_buffer_size + 1); //!!! //possibly wait for confirmation currentArgs->photoChanged = false; } else if (currentArgs->displayChanged == true) { printf("in displayChanged !\n"); setRenderConfig(client_video_render, currentArgs->displayType); currentArgs->displayChanged = false; } else if (currentArgs->takePhoto == true) { printf("in takePhoto !\n"); //needs to: //send command and then recive the capture current_command = TAKE_PHOTO; write(client_socket_fd, ¤t_command, sizeof(current_command)); currentArgs->takePhoto = false; printf("end of take photo\n"); } //loop terminationcurrent_command = TAKE_PHOTO; else if(currentArgs->rcamDeInit) { printf("in rcamDiInit !\n"); current_command = END_REMOTE_CAM; write(client_socket_fd, ¤t_command, sizeof(current_command)); printf("END_REMOTE_CAM sent\n"); break; //exits loop and ultimatly ends this pthread } else { printf("no commands in struct to parse !\n"); //send no command current_command = NO_COMMAND; write(client_socket_fd, ¤t_command, sizeof(current_command)); //printf("get a buffer to process\n"); //printf("waiting to recv buffer of size %d... ", render_params.nBufferSize); num_bytes = read(client_socket_fd, preview_buffer, render_params.nBufferSize); while (num_bytes < render_params.nBufferSize) { num_bytes += read(client_socket_fd, preview_buffer + num_bytes, render_params.nBufferSize - num_bytes); } //printf("buffer recived, recived %ld bytes\n", num_bytes); //change nAllocLen in bufferheader client_video_render_in = ilclient_get_input_buffer(client_video_render, 90, 1); memcpy(client_video_render_in->pBuffer, preview_buffer, render_params.nBufferSize); //printf("copied buffer form preview_buffer into client_video_render_in\n"); client_video_render_in->nFilledLen = render_params.nBufferSize; //empty buffer into render component OMX_EmptyThisBuffer(ilclient_get_handle(client_video_render), client_video_render_in); count++; //printf("Emptied buffer --- count = %d\n", count); } pthread_mutex_unlock(¤tArgs->mutexPtr); usleep(500); } //////////////////////////////////////////////////////////// //// end of thread, Cleanup //free buffer memory free(preview_buffer); printf("preview_buffer memory free\n"); //!free ilobjects and make sure all allocated memory is free! //!free sockets try to ensure no zombies printf("exiting rcam thread"); pthread_exit(NULL); }
void native_audio_init() { OMX_ERRORTYPE error; OMX_PARAM_PORTDEFINITIONTYPE param; OMX_AUDIO_PARAM_PCMMODETYPE pcm; int32_t s; // create and start up everything client = ilclient_init(); assert(client != NULL); error = OMX_Init(); assert(error == OMX_ErrorNone); ilclient_create_component(client, &audio_render, "audio_render", ILCLIENT_ENABLE_INPUT_BUFFERS | ILCLIENT_DISABLE_ALL_PORTS); assert(audio_render != NULL); // set up the number/size of buffers memset(¶m, 0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); param.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); param.nVersion.nVersion = OMX_VERSION; param.nPortIndex = 100; error = OMX_GetParameter(ILC_GET_HANDLE(audio_render), OMX_IndexParamPortDefinition, ¶m); assert(error == OMX_ErrorNone); int size = scaled_buffer_size(NUM_SAMPLES); size = (size + 15) & ~15; param.nBufferSize = size; param.nBufferCountActual = 2; error = OMX_SetParameter(ILC_GET_HANDLE(audio_render), OMX_IndexParamPortDefinition, ¶m); assert(error == OMX_ErrorNone); // set the pcm parameters memset(&pcm, 0, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); pcm.nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE); pcm.nVersion.nVersion = OMX_VERSION; pcm.nPortIndex = 100; pcm.nChannels = 2; pcm.eNumData = OMX_NumericalDataSigned; pcm.eEndian = OMX_EndianLittle; pcm.nSamplingRate = SAMPLE_FREQ; pcm.bInterleaved = OMX_TRUE; pcm.nBitPerSample = 16; pcm.ePCMMode = OMX_AUDIO_PCMModeLinear; pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF; pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF; error = OMX_SetParameter(ILC_GET_HANDLE(audio_render), OMX_IndexParamAudioPcm, &pcm); assert(error == OMX_ErrorNone); assert(ilclient_change_component_state(audio_render, OMX_StateIdle) == 0); if(ilclient_enable_port_buffers(audio_render, 100, NULL, NULL, NULL) < 0) { // error ilclient_change_component_state(audio_render, OMX_StateLoaded); COMPONENT_T* list[2]; list[0] = audio_render; list[1] = 0; ilclient_cleanup_components(list); error = OMX_Deinit(); assert(error == OMX_ErrorNone); ilclient_destroy(client); exit(-1); } assert(ilclient_change_component_state(audio_render, OMX_StateExecuting) == 0); // set the destination OMX_CONFIG_BRCMAUDIODESTINATIONTYPE ar_dest; const char* name = "hdmi"; 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, name); error = OMX_SetConfig(ILC_GET_HANDLE(audio_render), OMX_IndexConfigBrcmAudioDestination, &ar_dest); assert(error == OMX_ErrorNone); // get the buffer flow going pthread_create(&audio_thread, NULL, audio_exec, NULL); }
int main(int argc, char** argv) { int argn_dec; OMX_ERRORTYPE err; OMX_INDEXTYPE eIndexParamFilename; int gain=-1; OMX_AUDIO_CONFIG_VOLUMETYPE sVolume; OMX_TIME_CONFIG_TIMESTAMPTYPE sTimeStamp; OMX_PARAM_COMPONENTROLETYPE sComponentRole; char *stream_dir=NULL; DIR *dirp; struct dirent *dp; int seek=1; flagSetupTunnel = 1; flagPlaybackOn = 1; flagUsingFFMpeg = 1; flagIsGain = 0; if(argc <= 3) { argn_dec = 1; while (argn_dec<argc) { if (*(argv[argn_dec]) =='-') { switch (*(argv[argn_dec]+1)) { case 's': seek = 0; break; //case 't': // flagSetupTunnel = 0; // break; default: display_help(); } } else { stream_dir = malloc(strlen(argv[argn_dec]) * sizeof(char) + 1); strcpy(stream_dir,argv[argn_dec]); } argn_dec++; } } else if(argc > 3) { display_help(); } if(stream_dir==NULL) { stream_dir = malloc(strlen(getenv("HOME")) * sizeof(char) + 20); memset(stream_dir, 0, sizeof(stream_dir)); strcat(stream_dir, getenv("HOME")); strcat(stream_dir, "/stream/audio/"); } DEBUG(DEFAULT_MESSAGES, "Directory Name=%s\n",stream_dir); /* Populate the registry file */ dirp = opendir(stream_dir); if(dirp == NULL){ int err = errno; DEBUG(DEB_LEV_ERR, "Cannot open directory %s\n", stream_dir); return err; } /** initializing appPriv structure */ appPriv = malloc(sizeof(appPrivateType)); appPriv->filereaderEventSem = malloc(sizeof(tsem_t)); appPriv->decoderEventSem = malloc(sizeof(tsem_t)); appPriv->eofSem = malloc(sizeof(tsem_t)); if (flagPlaybackOn) { appPriv->sinkEventSem = malloc(sizeof(tsem_t)); tsem_init(appPriv->sinkEventSem, 0); appPriv->volumeEventSem = malloc(sizeof(tsem_t)); tsem_init(appPriv->volumeEventSem, 0); } tsem_init(appPriv->filereaderEventSem, 0); tsem_init(appPriv->decoderEventSem, 0); tsem_init(appPriv->eofSem, 0); /** initialising openmax */ err = OMX_Init(); if (err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "The OpenMAX core can not be initialized. Exiting...\n"); exit(1); } if(flagUsingFFMpeg) { DEBUG(DEB_LEV_SIMPLE_SEQ, "Using File Reader\n"); /** file reader component name -- gethandle*/ err = OMX_GetHandle(&appPriv->filereaderhandle, FILE_READER, NULL , &filereadercallbacks); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "FileReader Component Not Found\n"); exit(1); } err = OMX_GetExtensionIndex(appPriv->filereaderhandle,"OMX.ST.index.param.inputfilename",&eIndexParamFilename); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"\n error in get extension index\n"); exit(1); } } /** getting the handle of audio decoder */ err = OMX_GetHandle(&appPriv->audiodechandle, COMPONENT_NAME_BASE, NULL , &audiodeccallbacks); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Audio Decoder Component Not Found\n"); exit(1); } DEBUG(DEFAULT_MESSAGES, "Component %s opened\n", COMPONENT_NAME_BASE); if (flagPlaybackOn) { err = OMX_GetHandle(&appPriv->audiosinkhandle, SINK_NAME, NULL , &audiosinkcallbacks); if(err != OMX_ErrorNone){ DEBUG(DEB_LEV_ERR, "No sink found. Exiting...\n"); exit(1); } DEBUG(DEFAULT_MESSAGES, "Getting Handle for Component %s\n", AUDIO_EFFECT); err = OMX_GetHandle(&appPriv->volumehandle, AUDIO_EFFECT, NULL , &volumecallbacks); if(err != OMX_ErrorNone){ DEBUG(DEB_LEV_ERR, "No sink found. Exiting...\n"); exit(1); } if((gain >= 0) && (gain <100)) { err = OMX_GetConfig(appPriv->volumehandle, OMX_IndexConfigAudioVolume, &sVolume); if(err!=OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"Error %08x In OMX_GetConfig 0 \n",err); } sVolume.sVolume.nValue = gain; DEBUG(DEFAULT_MESSAGES, "Setting Gain %d \n", gain); err = OMX_SetConfig(appPriv->volumehandle, OMX_IndexConfigAudioVolume, &sVolume); if(err!=OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig 0 \n",err); } } } if (flagSetupTunnel) { DEBUG(DEB_LEV_SIMPLE_SEQ, "Setting up Tunnel\n"); if(flagUsingFFMpeg) { err = OMX_SetupTunnel(appPriv->filereaderhandle, 0, appPriv->audiodechandle, 0); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Set up Tunnel Failed\n"); exit(1); } } err = OMX_SetupTunnel(appPriv->audiodechandle, 1, appPriv->volumehandle, 0); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Set up Tunnel Failed\n"); exit(1); } err = OMX_SetupTunnel(appPriv->volumehandle, 1, appPriv->audiosinkhandle, 0); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR, "Set up Tunnel Failed\n"); exit(1); } DEBUG(DEB_LEV_SIMPLE_SEQ, "Set up Tunnel Completed\n"); } if(flagUsingFFMpeg) { /** now set the filereader component to idle and executing state */ OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StateIdle, NULL); } /*Send State Change Idle command to Audio Decoder*/ DEBUG(DEB_LEV_SIMPLE_SEQ, "Send Command Idle to Audio Dec\n"); err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandStateSet, OMX_StateIdle, NULL); if (flagPlaybackOn) { DEBUG(DEB_LEV_SIMPLE_SEQ, "Send Command Idle to Audio Sink\n"); err = OMX_SendCommand(appPriv->volumehandle, OMX_CommandStateSet, OMX_StateIdle, NULL); err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateIdle, NULL); } if(flagUsingFFMpeg) { /*Wait for File reader state change to */ tsem_down(appPriv->filereaderEventSem); DEBUG(DEFAULT_MESSAGES,"File reader idle state \n"); } tsem_down(appPriv->decoderEventSem); if (flagPlaybackOn) { tsem_down(appPriv->volumeEventSem); DEBUG(DEFAULT_MESSAGES,"volume state idle\n"); tsem_down(appPriv->sinkEventSem); DEBUG(DEFAULT_MESSAGES,"audio sink state idle\n"); } if (flagPlaybackOn) { err = OMX_SendCommand(appPriv->volumehandle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"volume state executing failed\n"); exit(1); } DEBUG(DEB_LEV_SIMPLE_SEQ,"waiting for volume state executing\n"); tsem_down(appPriv->volumeEventSem); DEBUG(DEB_LEV_SIMPLE_SEQ,"sending audio sink state executing\n"); err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"audio sink state executing failed\n"); exit(1); } DEBUG(DEB_LEV_SIMPLE_SEQ,"waiting for audio sink state executing\n"); tsem_down(appPriv->sinkEventSem); DEBUG(DEB_LEV_SIMPLE_SEQ, "audio sink state executing successful\n"); } setHeader(&sComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); strcpy((char*)&sComponentRole.cRole[0], MP3_ROLE); while((dp = readdir(dirp)) != NULL) { int len = strlen(dp->d_name); if(len >= 3){ if(strncmp(dp->d_name+len-4, ".mp3", 4) == 0){ if(input_file!=NULL) { free(input_file); input_file=NULL; } input_file = malloc(strlen(stream_dir) * sizeof(char) + sizeof(dp->d_name) +1); strcpy(input_file,stream_dir); strcat(input_file, dp->d_name); DEBUG(DEFAULT_MESSAGES, "Input Mp3 File Name=%s\n",input_file); flagUsingFFMpeg = 1; strcpy((char*)&sComponentRole.cRole[0], MP3_ROLE); } else if(strncmp(dp->d_name+len-4, ".ogg", 4) == 0){ if(input_file!=NULL) { free(input_file); input_file=NULL; } input_file = malloc(strlen(stream_dir) * sizeof(char) + sizeof(dp->d_name) +1); strcpy(input_file,stream_dir); strcat(input_file, dp->d_name); DEBUG(DEFAULT_MESSAGES, "Input Vorbis File Name=%s\n",input_file); flagUsingFFMpeg = 1; strcpy((char*)&sComponentRole.cRole[0], VORBIS_ROLE); } else if(strncmp(dp->d_name+len-4, ".aac", 4) == 0){ if(input_file!=NULL) { free(input_file); input_file=NULL; } input_file = malloc(strlen(stream_dir) * sizeof(char) + sizeof(dp->d_name) +1); strcpy(input_file,stream_dir); strcat(input_file, dp->d_name); DEBUG(DEFAULT_MESSAGES, "Input AAC File Name=%s\n",input_file); flagUsingFFMpeg = 1; strcpy((char*)&sComponentRole.cRole[0], AAC_ROLE); } else { continue; } } else { continue; } /*Reset Global Variables*/ tsem_reset(appPriv->eofSem); bEOS=OMX_FALSE; if (flagUsingFFMpeg) { DEBUG(DEB_LEV_SIMPLE_SEQ,"Sending Port Disable Command State Idle\n"); /*Port Disable for filereader is sent from Port Settings Changed event of FileReader*/ err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandPortDisable, 0, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"file reader port disable failed\n"); exit(1); } err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandPortDisable, OMX_ALL, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"audio decoder port disable failed\n"); exit(1); } err = OMX_SendCommand(appPriv->volumehandle, OMX_CommandPortDisable, 0, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"audio sink port disable failed\n"); exit(1); } DEBUG(DEB_LEV_SIMPLE_SEQ,"Waiting File reader Port Disable event \n"); /*Wait for File Reader Ports Disable Event*/ tsem_down(appPriv->filereaderEventSem); DEBUG(DEB_LEV_SIMPLE_SEQ,"File reader Port Disable State Idle\n"); /*Wait for Audio Decoder Ports Disable Event*/ tsem_down(appPriv->decoderEventSem); tsem_down(appPriv->decoderEventSem); tsem_down(appPriv->volumeEventSem); err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandStateSet, OMX_StateLoaded, NULL); tsem_down(appPriv->decoderEventSem); } DEBUG(DEB_LEV_SIMPLE_SEQ,"Setting Role\n"); err = OMX_SetParameter(appPriv->audiodechandle,OMX_IndexParamStandardComponentRole,&sComponentRole); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"\n error in input audio format - exiting\n"); exit(1); } if(flagUsingFFMpeg) { /** setting the input audio format in file reader */ DEBUG(DEB_LEV_SIMPLE_SEQ,"FileName Param index : %x \n",eIndexParamFilename); err = OMX_SetParameter(appPriv->filereaderhandle,eIndexParamFilename,input_file); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"\n error in input audio format - exiting\n"); exit(1); } } if (flagUsingFFMpeg) { DEBUG(DEB_LEV_SIMPLE_SEQ,"Sending Port Enable Command State Idle\n"); err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandStateSet, OMX_StateIdle, NULL); tsem_down(appPriv->decoderEventSem); err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandPortEnable, 0, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"file reader port enable failed\n"); exit(1); } err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandPortEnable, OMX_ALL, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"audio decoder port enable failed\n"); exit(1); } err = OMX_SendCommand(appPriv->volumehandle, OMX_CommandPortEnable, 0, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"audio sink port enable failed\n"); exit(1); } DEBUG(DEB_LEV_SIMPLE_SEQ,"Waiting File reader Port Disable event \n"); /*Wait for File Reader Ports Disable Event*/ tsem_down(appPriv->filereaderEventSem); DEBUG(DEB_LEV_SIMPLE_SEQ,"File reader Port Disable State Idle\n"); /*Wait for Audio Decoder Ports Disable Event*/ tsem_down(appPriv->decoderEventSem); tsem_down(appPriv->decoderEventSem); tsem_down(appPriv->volumeEventSem); } if(flagUsingFFMpeg) { err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"file reader state executing failed\n"); exit(1); } /*Wait for File reader state change to executing*/ tsem_down(appPriv->filereaderEventSem); DEBUG(DEFAULT_MESSAGES,"File reader executing state \n"); } err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"audio decoder state executing failed\n"); exit(1); } DEBUG(DEB_LEV_SIMPLE_SEQ,"Waiting for audio dec state exec\n"); /*Wait for decoder state change to executing*/ tsem_down(appPriv->decoderEventSem); DEBUG(DEB_LEV_SIMPLE_SEQ,"All Component state changed to Executing\n"); DEBUG(DEFAULT_MESSAGES,"Waiting for EOS = %d\n",appPriv->eofSem->semval); if (seek==1) { DEBUG(DEFAULT_MESSAGES,"Sleeping for 5 Secs \n"); /* Play for 5 Secs */ sleep(5); DEBUG(DEFAULT_MESSAGES,"Sleep for 5 Secs is over\n"); /*Then Pause the filereader component*/ err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StatePause, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"file reader state executing failed\n"); exit(1); } /*Wait for File reader state change to Pause*/ tsem_down(appPriv->filereaderEventSem); setHeader(&sTimeStamp, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE)); sTimeStamp.nPortIndex=0; /*Seek to 30 secs and play for 10 secs*/ sTimeStamp.nTimestamp = 2351*38*30; // 23.51ms*38fps*30secs //sTimeStamp.nTimestamp = 2351*38*60*3; // 23.51ms*38fps*60secs*4mins DEBUG(DEFAULT_MESSAGES, "nTimestamp %llx \n", sTimeStamp.nTimestamp); err = OMX_SetConfig(appPriv->filereaderhandle, OMX_IndexConfigTimePosition, &sTimeStamp); if(err!=OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetParameter 0 \n",err); } err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"file reader state executing failed\n"); exit(1); } /*Wait for File reader state change to Pause*/ tsem_down(appPriv->filereaderEventSem); DEBUG(DEFAULT_MESSAGES,"Sleeping for 10 Secs \n"); /*Play for 10 secs*/ sleep(10); DEBUG(DEFAULT_MESSAGES,"Sleep for 10 Secs is over\n"); if(!bEOS) { /*Then Pause the filereader component*/ err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StatePause, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"file reader state executing failed\n"); exit(1); } /*Wait for File reader state change to Pause*/ tsem_down(appPriv->filereaderEventSem); /*Seek to 5 mins or EOF*/ sTimeStamp.nTimestamp = 2351*38*60*5; // 23.51ms*38fps*30secs //sTimeStamp.nTimestamp = 2351*38*60*3; // 23.51ms*38fps*60secs*4mins DEBUG(DEFAULT_MESSAGES, "nTimestamp %llx \n", sTimeStamp.nTimestamp); err = OMX_SetConfig(appPriv->filereaderhandle, OMX_IndexConfigTimePosition, &sTimeStamp); if(err!=OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetParameter 0 \n",err); } err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL); if(err != OMX_ErrorNone) { DEBUG(DEB_LEV_ERR,"file reader state executing failed\n"); exit(1); } /*Wait for File reader state change to Pause*/ tsem_down(appPriv->filereaderEventSem); } } tsem_down(appPriv->eofSem); DEBUG(DEFAULT_MESSAGES,"Received EOS \n"); /*Send Idle Command to all components*/ DEBUG(DEFAULT_MESSAGES, "The execution of the decoding process is terminated\n"); if(flagUsingFFMpeg) { err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StateIdle, NULL); } err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandStateSet, OMX_StateIdle, NULL); if(flagUsingFFMpeg) { tsem_down(appPriv->filereaderEventSem); DEBUG(DEFAULT_MESSAGES,"File reader idle state \n"); } tsem_down(appPriv->decoderEventSem); DEBUG(DEFAULT_MESSAGES, "All component Transitioned to Idle\n"); } /*Loop While Play List*/ if (flagPlaybackOn) { err = OMX_SendCommand(appPriv->volumehandle, OMX_CommandStateSet, OMX_StateIdle, NULL); err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateIdle, NULL); } if (flagPlaybackOn) { tsem_down(appPriv->volumeEventSem); tsem_down(appPriv->sinkEventSem); } /*Send Loaded Command to all components*/ if(flagUsingFFMpeg) { err = OMX_SendCommand(appPriv->filereaderhandle, OMX_CommandStateSet, OMX_StateLoaded, NULL); } err = OMX_SendCommand(appPriv->audiodechandle, OMX_CommandStateSet, OMX_StateLoaded, NULL); if (flagPlaybackOn) { err = OMX_SendCommand(appPriv->volumehandle, OMX_CommandStateSet, OMX_StateLoaded, NULL); err = OMX_SendCommand(appPriv->audiosinkhandle, OMX_CommandStateSet, OMX_StateLoaded, NULL); } DEBUG(DEFAULT_MESSAGES, "Audio dec to loaded\n"); if(flagUsingFFMpeg) { tsem_down(appPriv->filereaderEventSem); DEBUG(DEFAULT_MESSAGES,"File reader loaded state \n"); } tsem_down(appPriv->decoderEventSem); if (flagPlaybackOn) { tsem_down(appPriv->volumeEventSem); tsem_down(appPriv->sinkEventSem); } if(input_file!=NULL) { free(input_file); input_file=NULL; } closedir(dirp); DEBUG(DEFAULT_MESSAGES, "All components released\n"); /** freeing all handles and deinit omx */ OMX_FreeHandle(appPriv->audiodechandle); DEBUG(DEB_LEV_SIMPLE_SEQ, "audiodec dec freed\n"); if(flagUsingFFMpeg) { OMX_FreeHandle(appPriv->filereaderhandle); DEBUG(DEB_LEV_SIMPLE_SEQ, "filereader freed\n"); } if (flagPlaybackOn) { OMX_FreeHandle(appPriv->volumehandle); DEBUG(DEB_LEV_SIMPLE_SEQ, "volume component freed\n"); OMX_FreeHandle(appPriv->audiosinkhandle); DEBUG(DEB_LEV_SIMPLE_SEQ, "audiosink freed\n"); } OMX_Deinit(); DEBUG(DEB_LEV_SIMPLE_SEQ, "All components freed. Closing...\n"); free(appPriv->filereaderEventSem); appPriv->filereaderEventSem = NULL; free(appPriv->decoderEventSem); appPriv->decoderEventSem = NULL; if (flagPlaybackOn) { free(appPriv->volumeEventSem); appPriv->volumeEventSem = NULL; free(appPriv->sinkEventSem); appPriv->sinkEventSem = NULL; } free(appPriv->eofSem); appPriv->eofSem = NULL; free(appPriv); appPriv = NULL; if(input_file) { free(input_file); } return 0; }
OMX_ERRORTYPE EnableDataFlow::configPorts(const ImageInfo &aThumbnailInfo, const ImageInfo &aPreviewInfo) { DBGT_PROLOG("Thumbnail Width: %d Height: %d \nPreview Width: %d Heidht: %d\n", aThumbnailInfo.getWidth(), aThumbnailInfo.getHeight(), aPreviewInfo.getAlignedWidth(), aPreviewInfo.getAlignedHeight()); DBGT_ASSERT(0 != aThumbnailInfo.getWidth(), "invalid width"); DBGT_ASSERT(0 != aThumbnailInfo.getHeight(), "invalid height"); DBGT_ASSERT(0 != aPreviewInfo.getAlignedWidth(), "invalid Preview Width"); DBGT_ASSERT(0 != aPreviewInfo.getAlignedHeight(), "invalid Preview Height"); OMX_ERRORTYPE err = OMX_ErrorNone; /****************************************************************************/ // Initialize ARM IV input /****************************************************************************/ err = OMX_GetParameter(mArmIvProc, OMX_IndexParamPortDefinition, &mParamArmIvInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mArmIvProc port0 failed err = %d", err); DBGT_EPILOG(""); return err; } mParamArmIvInput.nBufferCountActual = 1; // the index of the input port. Should be modified. //Here, the min number of buffers to be used is retrieved OMX_VIDEO_PORTDEFINITIONTYPE *pt_armivinput = &(mParamArmIvInput.format.video); pt_armivinput->cMIMEType = (OMX_STRING)""; pt_armivinput->pNativeRender = (OMX_NATIVE_DEVICETYPE)NULL; pt_armivinput->nFrameWidth = (OMX_U32)aPreviewInfo.getAlignedWidth(); pt_armivinput->nFrameHeight = (OMX_U32)aPreviewInfo.getAlignedHeight(); pt_armivinput->nStride = (OMX_U32)(2 * aPreviewInfo.getAlignedWidth()); pt_armivinput->nSliceHeight = (OMX_U32)aPreviewInfo.getAlignedHeight(); pt_armivinput->bFlagErrorConcealment = (OMX_BOOL)OMX_FALSE; pt_armivinput->eCompressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_IMAGE_CodingUnused; pt_armivinput->eColorFormat = mPreviewOmxColorFormat; pt_armivinput->pNativeWindow = (OMX_NATIVE_DEVICETYPE)NULL; err = OMX_SetParameter(mArmIvProc, OMX_IndexParamPortDefinition, &mParamArmIvInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Setparameter OMX_IndexParamPortDefinition for mArmIvProc port0 failed err = %d", err); DBGT_EPILOG(""); return err; } err = OMX_GetParameter(mArmIvProc, OMX_IndexParamPortDefinition, &mParamArmIvInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mArmIvProc port0 failed err = %d", err); DBGT_EPILOG(""); return err; } //dump DBGT_PTRACE("Dumping params for ARM IV input"); OmxUtils::dump(mParamArmIvInput); //***********Set Rotation value in ARMIVPRoc if((aThumbnailInfo.getRotation() == 90)||(aThumbnailInfo.getRotation() == 270)){ OmxUtils::StructContainer<OMX_CONFIG_ROTATIONTYPE> rfactor; rfactor.ptr()->nPortIndex = 1; rfactor.ptr()->nRotation = (aThumbnailInfo.getRotation()+180)%360; err = OMX_SetConfig(mArmIvProc, OMX_IndexConfigCommonRotate, rfactor.ptr()); if(OMX_ErrorNone != err) { DBGT_CRITICAL("SetConfig for mArmIvProc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } } //*********** /****************************************************************************/ // Initialize ARM IV output /****************************************************************************/ err = OMX_GetParameter(mArmIvProc, OMX_IndexParamPortDefinition, &mParamArmIvOutput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mArmIvProc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } mParamArmIvOutput.nBufferCountActual = 1; OMX_VIDEO_PORTDEFINITIONTYPE *pt_armivoutput = &(mParamArmIvOutput.format.video); pt_armivoutput->cMIMEType = (OMX_STRING)""; pt_armivoutput->pNativeRender = (OMX_NATIVE_DEVICETYPE)NULL; pt_armivoutput->nFrameWidth = (OMX_U32) aThumbnailInfo.getAlignedWidth(); pt_armivoutput->nFrameHeight = (OMX_U32)aThumbnailInfo.getAlignedHeight(); pt_armivoutput->nSliceHeight = (OMX_U32)aThumbnailInfo.getAlignedHeight(); pt_armivoutput->nStride = 0; pt_armivoutput->bFlagErrorConcealment = (OMX_BOOL)OMX_FALSE; pt_armivoutput->eCompressionFormat = (OMX_VIDEO_CODINGTYPE)OMX_IMAGE_CodingUnused; pt_armivoutput->eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_COLOR_FormatCbYCrY; pt_armivoutput->pNativeWindow = (OMX_NATIVE_DEVICETYPE)NULL; err = OMX_SetParameter(mArmIvProc, OMX_IndexParamPortDefinition, &mParamArmIvOutput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Setparameter OMX_IndexParamPortDefinition for mArmIvProc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } err = OMX_GetParameter(mArmIvProc, OMX_IndexParamPortDefinition, &mParamArmIvOutput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mArmIvProc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } //dump DBGT_PTRACE("Dumping params for ARM IV output"); OmxUtils::dump(mParamArmIvOutput); /****************************************************************************/ // Initialize SW JPEG Encoder Input for DCF thumbnail /****************************************************************************/ err = OMX_GetParameter(mSwJpegEnc, OMX_IndexParamPortDefinition, &mParamSwJpegInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mSwJpegEnc port0 failed err = %d", err); DBGT_EPILOG(""); return err; } mParamSwJpegInput.nBufferCountActual = 1; // the index of the input port. Should be modified. OMX_IMAGE_PORTDEFINITIONTYPE *pt_swjpeginput = &(mParamSwJpegInput.format.image); pt_swjpeginput->cMIMEType = (OMX_STRING)""; pt_swjpeginput->pNativeRender = (OMX_NATIVE_DEVICETYPE)NULL; pt_swjpeginput->nFrameWidth = (OMX_U32) aThumbnailInfo.getAlignedWidth(); pt_swjpeginput->nFrameHeight = (OMX_U32)aThumbnailInfo.getAlignedHeight(); pt_swjpeginput->nStride = (OMX_U32) (aThumbnailInfo.getAlignedWidth() * 3 / 2); pt_swjpeginput->nSliceHeight = (OMX_U32)aThumbnailInfo.getAlignedHeight(); pt_swjpeginput->bFlagErrorConcealment = (OMX_BOOL)OMX_FALSE; pt_swjpeginput->eCompressionFormat = (OMX_IMAGE_CODINGTYPE)OMX_IMAGE_CodingUnused; pt_swjpeginput->eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_COLOR_FormatCbYCrY; pt_swjpeginput->pNativeWindow = (OMX_NATIVE_DEVICETYPE)NULL; err = OMX_SetParameter(mSwJpegEnc, OMX_IndexParamPortDefinition, &mParamSwJpegInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Setparameter OMX_IndexParamPortDefinition for mSwJpegEnc port0 failed err = %d", err); DBGT_EPILOG(""); return err; } err = OMX_GetParameter(mSwJpegEnc, OMX_IndexParamPortDefinition, &mParamSwJpegInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mSwJpegEnc port0 failed err = %d", err); DBGT_EPILOG(""); return err; } //dump DBGT_PTRACE("Dumping params for mParamSwJpegInput"); OmxUtils::dump(mParamSwJpegInput); /****************************************************************************/ // Initialize SW JPEG Encoder Ouput for DCF thumbnail /****************************************************************************/ if (aThumbnailInfo.invalidQuality() != aThumbnailInfo.getQuality()) { //setup thumbnail quality OmxUtils::StructContainer<OMX_IMAGE_PARAM_QFACTORTYPE> qfactor; qfactor.ptr()->nPortIndex = 1; qfactor.ptr()->nQFactor = aThumbnailInfo.getQuality(); DBGT_PTRACE("Setting JPEG Thumbnail Quality: %lu ", qfactor.ptr()->nQFactor); err = OMX_SetConfig(mSwJpegEnc, OMX_IndexParamQFactor, qfactor.ptr()); if(OMX_ErrorNone != err) { DBGT_CRITICAL("SetConfig mSwJpegEnc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } } err = OMX_GetParameter(mSwJpegEnc, OMX_IndexParamPortDefinition, &mParamSwJpegOutput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mSwJpegEnc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } mParamSwJpegOutput.nBufferCountActual = 1; // the index of the input port. Should be modified. OMX_IMAGE_PORTDEFINITIONTYPE *pt_swjpegoutput = &(mParamSwJpegOutput.format.image); pt_swjpegoutput->cMIMEType = (OMX_STRING)""; pt_swjpegoutput->pNativeRender = (OMX_NATIVE_DEVICETYPE)NULL; pt_swjpegoutput->nFrameWidth = (OMX_U32)aThumbnailInfo.getWidth(); pt_swjpegoutput->nFrameHeight = (OMX_U32)aThumbnailInfo.getHeight(); pt_swjpegoutput->nStride = (OMX_U32)(aThumbnailInfo.getWidth() * 3 / 2); pt_swjpegoutput->nSliceHeight = (OMX_U32)aThumbnailInfo.getHeight(); pt_swjpegoutput->bFlagErrorConcealment = (OMX_BOOL)OMX_FALSE; pt_swjpegoutput->eCompressionFormat = (OMX_IMAGE_CODINGTYPE)OMX_IMAGE_CodingJPEG; pt_swjpegoutput->eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_COLOR_FormatUnused; pt_swjpegoutput->pNativeWindow = (OMX_NATIVE_DEVICETYPE)NULL; err = OMX_SetParameter(mSwJpegEnc, OMX_IndexParamPortDefinition, &mParamSwJpegOutput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Setparameter OMX_IndexParamPortDefinition for mSwJpegEnc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } err = STECamera::cropOutputSize(mSwJpegEnc, aThumbnailInfo.getWidth(), aThumbnailInfo.getHeight()); if(OMX_ErrorNone != err) { DBGT_CRITICAL("cropOutputSize for mSwJpegEnc failed err = %d", err); DBGT_EPILOG(""); return err; } err = OMX_GetParameter(mSwJpegEnc, OMX_IndexParamPortDefinition, &mParamSwJpegOutput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter OMX_IndexParamPortDefinition for mSwJpegEnc port1 failed err = %d", err); DBGT_EPILOG(""); return err; } DBGT_PTRACE("Dumping params for mParamSwJpegOutput"); OmxUtils::dump(mParamSwJpegOutput); /****************************************************************************/ // Reconfigure ExifMixer port 0 /****************************************************************************/ err = OMX_GetParameter(mExifMixer, OMX_IndexParamPortDefinition, &mParamExifInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter mExifMixer port 0 failed err = %d", err); DBGT_EPILOG(""); return err; } mParamExifInput.nBufferCountActual = 1; // the index of the input port. Should be modified. OMX_IMAGE_PORTDEFINITIONTYPE *pt_exifinput1 = &(mParamExifInput.format.image); pt_exifinput1->cMIMEType = (OMX_STRING)""; pt_exifinput1->pNativeRender = (OMX_NATIVE_DEVICETYPE)NULL; pt_exifinput1->nFrameWidth = (OMX_U32)aThumbnailInfo.getWidth(); pt_exifinput1->nFrameHeight = (OMX_U32)aThumbnailInfo.getHeight(); pt_exifinput1->nStride = (OMX_U32)(aThumbnailInfo.getWidth() * 3 / 2); pt_exifinput1->bFlagErrorConcealment = (OMX_BOOL)OMX_FALSE; pt_exifinput1->eCompressionFormat = (OMX_IMAGE_CODINGTYPE)OMX_IMAGE_CodingJPEG; pt_exifinput1->eColorFormat = (OMX_COLOR_FORMATTYPE)OMX_COLOR_FormatUnused; pt_exifinput1->pNativeWindow = (OMX_NATIVE_DEVICETYPE)NULL; err = OMX_SetParameter(mExifMixer, OMX_IndexParamPortDefinition, &mParamExifInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Setparameter mExifMixer port 0 failed err = %d", err); DBGT_EPILOG(""); return err; } //dump err = OMX_GetParameter(mExifMixer, OMX_IndexParamPortDefinition, &mParamExifInput); if(OMX_ErrorNone != err) { DBGT_CRITICAL("Getparameter mExifMixer port 0 failed err = %d", err); DBGT_EPILOG(""); return err; } DBGT_PTRACE("Dumping params for mParamExifInput"); OmxUtils::dump(mParamExifInput); DBGT_EPILOG(""); return err; }