OMX_ERRORTYPE OMX_CONF_ListComponents()
{
    OMX_ERRORTYPE  eError = OMX_ErrorNone;
    OMX_U32 i = 0;
    OMX_S8 cCompEnumName[256];
 
    OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "\nAvailable Components:\n\n"); 

    /* Initialize OpenMax */
    if (OMX_ErrorNone == (eError = OMX_Init()))
    {
        while (OMX_ErrorNone == eError) 
        {
            /* loop through all enumerated components to determine if the component name
            specificed for the test is enumerated by the OMX core */
            eError = OMX_ComponentNameEnum((OMX_STRING) cCompEnumName, 256, i);
            OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "\t%s\n", cCompEnumName);            
            i++;
        }
    }

    /* didn't find it */
    OMX_Deinit();
    return OMX_ErrorNone;
}
/** mm_jpegdec_init:
 *
 *  Arguments:
 *    @my_obj: jpeg object
 *
 *  Return:
 *       0 for success else failure
 *
 *  Description:
 *       Initializes the jpeg client
 *
 **/
int32_t mm_jpegdec_init(mm_jpeg_obj *my_obj)
{
  int32_t rc = 0;

  /* init locks */
  pthread_mutex_init(&my_obj->job_lock, NULL);

  /* init ongoing job queue */
  rc = mm_jpeg_queue_init(&my_obj->ongoing_job_q);
  if (0 != rc) {
    CDBG_ERROR("%s:%d] Error", __func__, __LINE__);
    return -1;
  }

  /* init job semaphore and launch jobmgr thread */
  CDBG("%s:%d] Launch jobmgr thread rc %d", __func__, __LINE__, rc);
  rc = mm_jpeg_jobmgr_thread_launch(my_obj);
  if (0 != rc) {
    CDBG_ERROR("%s:%d] Error", __func__, __LINE__);
    return -1;
  }

  /* load OMX */
  if (OMX_ErrorNone != OMX_Init()) {
    /* roll back in error case */
    CDBG_ERROR("%s:%d] OMX_Init failed (%d)", __func__, __LINE__, rc);
    mm_jpeg_jobmgr_thread_release(my_obj);
    mm_jpeg_queue_deinit(&my_obj->ongoing_job_q);
    pthread_mutex_destroy(&my_obj->job_lock);
  }

  return rc;
}
int main(int argc, char* argv[])
{
  OMX_Init();

  if (argc == 2)
  {
    OMX_STRING pScriptFile = (OMX_STRING) argv[1];

    RunScript(pScriptFile);
  }
  else if (argc == 4)
  {
    OMX_STRING pTestName = (OMX_STRING) argv[1];
    OMX_STRING pConfigFile = (OMX_STRING) argv[2];
    OMX_STRING pNumSession = (OMX_STRING) argv[3];
    OMX_S32 nSession;

    nSession = atoi((char*) pNumSession);

    RunTest(pTestName, pConfigFile, nSession);
  }
  else
  {
    VENC_TEST_MSG_ERROR("invalid number of command args %d", argc);
    VENC_TEST_MSG_ERROR("./mm-venc-omx-test ENCODE Config.cfg 1");
  }

  OMX_Deinit();
}
Beispiel #4
0
/**
 * @brief   Initialization of OpenMAX and structures.
 * @param   ctx     Application context to initialize.
 */
static void initAppOMX(AppOMXContext* ctx) {
    bcm_host_init() ;

    log_printer("Initialization...") ;

    {
        OMX_ERRORTYPE error = OMX_Init() ;
        if (error != OMX_ErrorNone) {
	        omx_die(error, "OMX initialization failed...") ;
        	return ;
        }
    }


    // Initialize the application context for video capture
    AppOMXContext_Memset(ctx, 0, sizeof(*ctx)) ;
    if (vcos_semaphore_create(ctx -> getHandlerLock(ctx), "handler_lock", 1) != VCOS_SUCCESS)
        die("Failed to create handler lock semaphore...\n") ;

    // Initialize component handles
    OMX_CALLBACKTYPE callbacks ;
    AppOMXContext_Memset(ctx, 0, sizeof(callbacks)) ;
    callbacks.EventHandler = event_handler ;
    callbacks.FillBufferDone = fill_output_buffer_done_handler ;

    init_component_handle("camera", ctx -> getCamera(ctx) , ctx, &callbacks) ;
    init_component_handle("video_encode", ctx -> getEncoder(ctx) , ctx, &callbacks) ;
    init_component_handle("null_sink", ctx -> getNullSink(ctx) , ctx, &callbacks) ;
}
int main(int argc, char *argv[])
{
    HTEST *hTest = NULL;
    OMX_STRING component = NULL;
    OMX_STRING dump_file = NULL;

    if(argc < 2) {
        printf("Usage: ./bin <dump_file>\n");
        return 0;
    }
    
    OMX_Init();
    component = "OMX.Freescale.std.video_source.v4l.sw-based";
    dump_file = argv[1];
    hTest = create_test(component, dump_file);
    hTest->media_name = argv[1];
    if(hTest == NULL) {
        printf("Create test failed.\n");
        return 0;
    }
            
    load_component(hTest);
    StateTrans(hTest, (OMX_STATETYPE)2);
    StateTrans(hTest, (OMX_STATETYPE)3);
    cmd_process(hTest);
    delete_test(hTest);
    OMX_Deinit();

    return 1;
}
Beispiel #6
0
// this function run the boilerplate to setup the openmax components;
int
setupOpenMaxJpegDecoder(OPENMAX_JPEG_DECODER ** pDecoder)
{
    *pDecoder = malloc(sizeof(OPENMAX_JPEG_DECODER));
    if (pDecoder[0] == NULL) {
	perror("malloc decoder");
	return OMXJPEG_ERROR_MEMORY;
    }
    memset(*pDecoder, 0, sizeof(OPENMAX_JPEG_DECODER));

    if ((pDecoder[0]->client = ilclient_init()) == NULL) {
	perror("ilclient_init");
	return OMXJPEG_ERROR_ILCLIENT_INIT;
    }

    if (OMX_Init() != OMX_ErrorNone) {
	ilclient_destroy(pDecoder[0]->client);
	perror("OMX_Init");
	return OMXJPEG_ERROR_OMX_INIT;
    }
    // prepare the image decoder
    int             ret = prepareImageDecoder(pDecoder[0]);
    if (ret != OMXJPEG_OK)
	return ret;

    ret = prepareResizer(pDecoder[0]);
    if (ret != OMXJPEG_OK)
	return ret;

    ret = startupImageDecoder(pDecoder[0]);
    if (ret != OMXJPEG_OK)
	return ret;

    return OMXJPEG_OK;
}
int main(int argc, char** argv) {

  int index;
  char name[256];
  OMX_ERRORTYPE err = OMX_ErrorNone;

  err = OMX_Init();
  if(err != OMX_ErrorNone) {
    DEBUG(DEB_LEV_ERR, "OMX_Init() failed\n");
    exit(1);
  }

  index = 0;
  while(err == OMX_ErrorNone)
  {
    err = OMX_ComponentNameEnum(name, 256, index);
    if (err == OMX_ErrorNone)
    {
        printf("Component %d is %s\n", index, name);
    }
    index++;
  }

  printf("Hit any key\n");
  getchar();

  OMX_Deinit();

  return 0;
}
END_TEST
START_TEST (test_ilcore_init_and_deinit_get_hdl_free_hdl)
{
  OMX_ERRORTYPE error = OMX_ErrorNone;
  OMX_HANDLETYPE p_hdl = NULL;
  OMX_U32 appData;
  OMX_CALLBACKTYPE callBacks;

  error = OMX_Init ();
  fail_if (error != OMX_ErrorNone);

  error = OMX_GetHandle (&p_hdl,
                         TIZ_CORE_TEST_COMPONENT_NAME,
                         (OMX_PTR *) (&appData), &callBacks);
  TIZ_LOG (TIZ_PRIORITY_TRACE, "OMX_GetHandle error [%s]", tiz_err_to_str (error));
  fail_if (error != OMX_ErrorNone);

  TIZ_LOG (TIZ_PRIORITY_TRACE, "p_hdl [%p]", p_hdl);

  error = OMX_FreeHandle (p_hdl);
  fail_if (error != OMX_ErrorNone);

  error = OMX_Deinit ();
  fail_if (error != OMX_ErrorNone);
}
OMX_BOOL OMX_CONF_ComponentExists(OMX_IN OMX_STRING cComponentName)
{
    OMX_ERRORTYPE  eError = OMX_ErrorNone;
    OMX_U32 i = 0;
    OMX_S8 cCompEnumName[256];
    
    /* Initialize OpenMax */
    if (OMX_ErrorNone == (eError = OMX_Init()))
    {
        while (OMX_ErrorNone == eError) 
        {
            /* loop through all enumerated components to determine if the component name
            specificed for the test is enumerated by the OMX core */
            eError = OMX_ComponentNameEnum((OMX_STRING) cCompEnumName, 256, i);
            if (OMX_ErrorNone == eError){
                if (!strcmp((OMX_STRING) cCompEnumName, cComponentName)) {
                    /* found it */    
                    OMX_Deinit();
                    return OMX_TRUE;
                }
            } 
            i++;
        }
    }

    /* didn't find it */
    OMX_Deinit();
    return OMX_FALSE;
}
Beispiel #10
0
ILCLIENT_T * encode_init(COMPONENT_T **video_encode)
{
	ILCLIENT_T *client = ilclient_init();
	if (client == NULL)
	{
		return NULL;
	}

	if (OMX_Init() != OMX_ErrorNone)
	{
		ilclient_destroy(client);
		return NULL;
	}

	// create video_encode
	int omx_return = ilclient_create_component(client, video_encode, "video_encode",
				(ILCLIENT_CREATE_FLAGS_T)(ILCLIENT_DISABLE_ALL_PORTS |
				ILCLIENT_ENABLE_INPUT_BUFFERS |
				ILCLIENT_ENABLE_OUTPUT_BUFFERS));
	if (omx_return != 0)
	{
		fprintf(stderr, "ilclient_create_component() for video_encode failed with %x!\n", omx_return);
		ilclient_destroy(client);
		return NULL;
	}

	return client;
}
Beispiel #11
0
void
omx_init(void)
{
  OMX_Init();

  media_pipe_init_extra = omx_mp_init;
  media_pipe_fini_extra = omx_mp_fini;
}
int Init_Decoder(OMX_STRING audio_component)
{
    DEBUG_PRINT("Inside %s \n", __FUNCTION__);
    OMX_ERRORTYPE omxresult;
    OMX_U32 total = 0;
    typedef OMX_U8* OMX_U8_PTR;
    char *role ="audio_decoder.aac";

    static OMX_CALLBACKTYPE call_back = {
        &EventHandler,&EmptyBufferDone,&FillBufferDone
    };

    /* Init. the OpenMAX Core */
    DEBUG_PRINT("\nInitializing OpenMAX Core....\n");
    omxresult = OMX_Init();

    if(OMX_ErrorNone != omxresult) {
        DEBUG_PRINT("\n Failed to Init OpenMAX core");
          return -1;
    }
    else {
        DEBUG_PRINT("\nOpenMAX Core Init Done\n");
    }

    /* Query for audio decoders*/
    DEBUG_PRINT("Aac_test: Before entering OMX_GetComponentOfRole");
    OMX_GetComponentsOfRole(role, &total, 0);
    DEBUG_PRINT ("\nTotal components of role=%s :%lu", role, total);


    omxresult = OMX_GetHandle((OMX_HANDLETYPE*)(&aac_dec_handle),
                        (OMX_STRING)audio_component, NULL, &call_back);
    if (FAILED(omxresult)) {
        DEBUG_PRINT("\nFailed to Load the component:%s\n", audio_component);
    return -1;
    }
    else
    {
        DEBUG_PRINT("\nComponent %s is in LOADED state\n", audio_component);
    }

    /* Get the port information */
    CONFIG_VERSION_SIZE(portParam);
    omxresult = OMX_GetParameter(aac_dec_handle, OMX_IndexParamAudioInit,
                                (OMX_PTR)&portParam);

    if(FAILED(omxresult)) {
        DEBUG_PRINT("\nFailed to get Port Param\n");
    return -1;
    }
    else
    {
        DEBUG_PRINT("\nportParam.nPorts:%lu\n", portParam.nPorts);
    DEBUG_PRINT("\nportParam.nStartPortNumber:%lu\n",
                                             portParam.nStartPortNumber);
    }
    return 0;
}
/* detect the compliance profile(s) that the component is eligible for */
OMX_U32 DetectComplianceProfile(OMX_STRING sArgument)
{
    OMX_U32 detectedCompliance;
    OMX_HANDLETYPE hThread, hComp, hTTC;
    OMX_CALLBACKTYPE oDummyCallbacks;
    OMX_TIME_CONFIG_TIMESTAMPTYPE oTimeStamp;
    OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE oRefClock;

    detectedCompliance = OMX_CONF_TestFlag_Base|OMX_CONF_TestFlag_AutoOutput;

    /* try to create a thread -> implies threading compliance */
    if (OMX_ErrorNone == OMX_OSAL_ThreadCreate( DummyThreadFunction, 0, 0, &hThread)){
        if (OMX_ErrorNone == OMX_OSAL_ThreadDestroy( hThread)){
            detectedCompliance |= OMX_CONF_TestFlag_Threaded;
        }
    }
    oDummyCallbacks.EmptyBufferDone = StubbedEmptyBufferDone;
    oDummyCallbacks.FillBufferDone = StubbedFillBufferDone;
    oDummyCallbacks.EventHandler = StubbedEventHandler;
    if (OMX_ErrorNone != OMX_Init()){
        return 0;
    }
    if (OMX_ErrorNone != OMX_GetHandle(&hComp, sArgument, NULL, &oDummyCallbacks)){
        OMX_Deinit();
        return 0;
    }
    if (OMX_ErrorNone != OMX_CONF_GetTunnelTestComponentHandle(&hTTC, NULL, &oDummyCallbacks)){
        OMX_FreeHandle(hComp);
        OMX_Deinit();
        return 0;
    }

    if (OMX_ErrorNone == OMX_CONF_TTCConnectAllPorts(hTTC, hComp))
    {
        INIT_PARAM(oRefClock);
        INIT_PARAM(oTimeStamp);
        oTimeStamp.nPortIndex = 0;

        detectedCompliance |= OMX_CONF_TestFlag_Interop;

        /* try to set active ref clock -> implies clock component compliance */
        if (OMX_ErrorUnsupportedIndex != OMX_SetConfig(hComp, OMX_IndexConfigTimeActiveRefClock, &oRefClock)){
            detectedCompliance &= ~OMX_CONF_TestFlag_AutoOutput; /* only clock component doesn't have autooutput */
            detectedCompliance |=  OMX_CONF_TestFlag_ClockComp; 
        } 

        /* try to set time position -> implies seeking compliance */
        if (OMX_ErrorUnsupportedIndex != OMX_SetConfig(hComp, OMX_IndexConfigTimePosition, &oTimeStamp)){
            detectedCompliance |=  OMX_CONF_TestFlag_Seeking; 
        }
    }

    OMX_CONF_FreeTunnelTestComponentHandle(hTTC);
    OMX_FreeHandle(hComp);
    OMX_Deinit();

    return detectedCompliance;
}
Beispiel #14
0
int32_t ilctts_initialize() {
	OMX_ERRORTYPE omx_err;
	bcm_host_init();
	omx_err = OMX_Init();
	if (omx_err != OMX_ErrorNone) {
		ERROR("OMX_Init returned error in ilctts_initialize: %d", omx_err);
	}
	return (omx_err == OMX_ErrorNone ? 0 : -1);
} // end ilctts_initialize
void AnatomyOMXClient::init() {
	OMX_HANDLETYPE handle = NULL;
	char componentName[256];
	OMX_Init();
	OMX_ComponentNameEnum(componentName, 256, 0);
	OMX_GetHandle(&handle, componentName, this, &AnatomyOMXClient::kCallbacks);
	CHECK(handle != NULL);

	mComponentHandle = handle;
}
void tiz::omxutil::init ()
{
  OMX_ERRORTYPE ret = OMX_ErrorNone;

  if (OMX_ErrorNone != (ret = OMX_Init ()))
  {
    fprintf (stderr, "FATAL. Could not init OpenMAX IL : %s",
             tiz_err_to_str (ret));
    exit (EXIT_FAILURE);
  }
}
Beispiel #17
0
int emxx_yuv_to_jpeg(unsigned char *srcYUVData, int width, int height, FILE *dstJPGfp, 
        int quality,int yuvType)
{
    VIDEODECFUNCPARAMTYPE  VideoParam;
    int ret;

    //Initialize
    ParamInit(&VideoParam);
    yuvData = NULL; //save yuv data
    jpgFile = NULL;

    yuvData = srcYUVData;
    jpgFile = dstJPGfp;

    switch (yuvType)
    {
        case OMF_MC_JPEGD_SAMPLING11:
            VideoParam.eColorFormat = (OMX_COLOR_FORMATTYPE)OMF_MC_COLOR_FormatYUV444HV11;
            break;
        case OMF_MC_JPEGD_SAMPLING21:
            VideoParam.eColorFormat = (OMX_COLOR_FORMATTYPE)OMF_MC_COLOR_FormatYUV422HV21;
            break;
        case OMF_MC_JPEGD_SAMPLING12:
            VideoParam.eColorFormat = (OMX_COLOR_FORMATTYPE)OMF_MC_COLOR_FormatYUV422HV12;
            break;
        case OMF_MC_JPEGD_SAMPLING22:
            VideoParam.eColorFormat = (OMX_COLOR_FORMATTYPE)OMF_MC_COLOR_FormatYUV411HV22;
            break;
        case OMF_MC_JPEGD_SAMPLING41:
            VideoParam.eColorFormat = (OMX_COLOR_FORMATTYPE)OMF_MC_COLOR_FormatYUV411HV41;
            break;
        default:
            FILE_DBG("Invalid H:V Ratio, use HV22 instead");
            VideoParam.eColorFormat = (OMX_COLOR_FORMATTYPE)OMF_MC_COLOR_FormatYUV411HV22;
            break;

    }

    //width setting
    VideoParam.nFrameWidth = width;
    VideoParam.resize = 1;

    //height setting
    VideoParam.nFrameHeight = height;
    VideoParam.resize = 1;

    VideoParam.nQFactor = quality; 

    OMX_Init();
    printf("start encoding...\n");
    FILE_DBG("start encoding...");
    return jpege_main(&VideoParam);

}
Beispiel #18
0
/** 
********************************************************************************
 *  @fn     main
 *  @brief  This function does the platform specific initialization and just 
 *          sleeps. The test application that runs in the vpss-m3 instantiates
 *          components such as VSNK (proxy the video encoder) and VSRC (proxy 
 *          for decoder and tunnels the data to and from those components 
 *          respectively.
 * 
 *  @param[in ]  arg1  : FrameWidth
 *  @param[in ]  arg2  : nFrameHeight
 *  @param[in]   arg3  : Input File Name
 * 
 *  @returns none 
********************************************************************************
*/
int main (int argc, char *argv[])
{
  IL_ARGS args;
  ConfigureUIA uiaCfg;

  //parse_args(argc, argv, &args);
 
//  strncpy (argsp->output_file, "sample.h264", MAX_FILE_NAME_SIZE);
  args.frame_rate = 60;
  args.bit_rate = 16000000;
  args.num_frames = 1000;
  strncpy (args.mode, "720p", MAX_MODE_NAME_SIZE);
  args.display_id = 0;
	


  printf (" Capture-Encode example \n");
  printf ("===============================\n");

  /* do omx_init for sytem level initialization */
  /* Initializing OMX core , functions related to platform specific
     initialization could be placed inside this */

  OMX_Init ();

  printf (" OMX_Init completed \n ");


  /* UIA is an utility to get the logs from firmware on Linux terminal, and also
     to use System Analyzer, Following UIA configuration is required to change 
     the default debug logging configuration, and is optional  */

  /* Configuring logging options on slave cores */
  /* can be 0 or 1 */
  uiaCfg.enableAnalysisEvents = 0;
  /* can be 0 or 1 */
  uiaCfg.enableStatusLogger = 1;
  /* can be OMX_DEBUG_LEVEL1|2|3|4|5 */
  uiaCfg.debugLevel = OMX_DEBUG_LEVEL1;
  /* configureUiaLoggerClient( COREID, &Cfg); */
  configureUiaLoggerClient(2, &uiaCfg);
  configureUiaLoggerClient(1, &uiaCfg);

 /* OMX IL client for decoder component */
  Capture_Encode_Example (&args);
  
  /* de initialze the DOMX / memory configuration */
  
  OMX_Deinit();
  
  exit (0);
}/* main */
int main(int argc, char *argv[])
{
    HTEST *hTest = NULL;
    OMX_STRING component = NULL;
    OMX_STRING in_file = NULL, out_file = NULL;
	OMX_S32 width, height, bitrate;
    FORMAT fmt;

    if(argc < 6) {
        printf("Unit test of vpu encoder component.\n");
        printf("This test read data from in_file then store the encoded data to out_file.\n");
        printf("Usage: ./bin <in_file> <width> <height> <out_file> <bitrate>\n");
        return 0;
    }

    OMX_Init();
    in_file = argv[1];
	width = atoi(argv[2]);
	height = atoi(argv[3]);
    out_file = argv[4];
	bitrate = atoi(argv[5]);
	fmt = H264;
	if (fmt == H264) {
		component = "OMX.Freescale.std.video_encoder.avc.hw-based";
	} else if (fmt == H263) {
		component = "OMX.Freescale.std.video_encoder.h263.hw-based";
	} else {
		printf("wrong format.\n");
		return 0;
	}
    hTest = create_test(component, in_file, width, height, out_file, fmt, bitrate);
    if(hTest == NULL) {
        printf("Create test failed.\n");
        return 0;
    }

    load_component(hTest);
    StateTrans(hTest, OMX_StateIdle);
    StateTrans(hTest, OMX_StateExecuting);
    wait_eos(hTest);
    StateTrans(hTest, OMX_StateIdle);
    StateTrans(hTest, OMX_StateLoaded);
    unload_component(hTest);

    delete_test(hTest);
    OMX_Deinit();

    printf("Vpu component test is done.\n");

    return 1;
}
int main(int argc, char *argv[])
{
	HTEST *hTest = NULL;
	OMX_STRING component = NULL;
	OMX_STRING in_file = NULL, out_file = NULL;
	FORMAT fmt;

	if(argc < 4)
	{
		printf("Unit test of vpu component.\n");
		printf("This test read data from in_file then store the decoded data to out_file.\n");
		printf("Usage: ./bin <in_file> <out_file> <format>\n");
		printf("format: 0 -- mpeg4\n");
		printf("        1 -- h264\n");
		return 0;
	}

	OMX_Init();
	component = "OMX.Freescale.std.video_decoder.avc.v3.hw-based";
	in_file = argv[1];
	out_file = argv[2];
	fmt = (FORMAT) atoi(argv[3]);
	hTest = create_test(component, in_file, out_file, fmt);
	if(hTest == NULL)
	{
		printf("Create test failed.\n");
		return 0;
	}

#if 1
	load_component(hTest);
	StateTrans(hTest, OMX_StateIdle);
	StateTrans(hTest, OMX_StateExecuting);
	wait_eos(hTest);
	StateTrans(hTest, OMX_StateIdle);
	StateTrans(hTest, OMX_StateLoaded);
	unload_component(hTest);
#else
	cmd_process(hTest);
#endif

	delete_test(hTest);
	OMX_Deinit();

	printf("Vpu component test is done.\n");

	return 1;
}
Beispiel #21
0
/** 
********************************************************************************
 *  @fn     main
 *  @brief  This function does the platform specific initialization and just 
 *          sleeps. The test application that runs in the vpss-m3 instantiates
 *          components such as VSNK (proxy the video encoder) and VSRC (proxy 
 *          for decoder and tunnels the data to and from those components 
 *          respectively.
 * 
 *  @param[in ]  arg1  : FrameWidth
 *  @param[in ]  arg2  : nFrameHeight
 *  @param[in]   arg3  : Input File Name
 * 
 *  @returns none 
********************************************************************************
*/
int main (int argc, char *argv[])
{
  IL_ARGS args;
  ConfigureUIA uiaCfg;

  parse_args(argc, argv, &args);
 
  printf (" Capture-Encode example \n");
  printf ("===============================\n");

  /* install signal handler on SIGINT */  
  signal(SIGINT, IL_ClientSIGINTHandler);  

  /* do omx_init for sytem level initialization */
  /* Initializing OMX core , functions related to platform specific
     initialization could be placed inside this */

  OMX_Init ();

  printf (" OMX_Init completed \n ");


  /* UIA is an utility to get the logs from firmware on Linux terminal, and also
     to use System Analyzer, Following UIA configuration is required to change 
     the default debug logging configuration, and is optional  */

  /* Configuring logging options on slave cores */
  /* can be 0 or 1 */
  uiaCfg.enableAnalysisEvents = 0;
  /* can be 0 or 1 */
  uiaCfg.enableStatusLogger = 1;
  /* can be OMX_DEBUG_LEVEL1|2|3|4|5 */
  uiaCfg.debugLevel = OMX_DEBUG_LEVEL1;
  /* configureUiaLoggerClient( COREID, &Cfg); */
  configureUiaLoggerClient(2, &uiaCfg);
  configureUiaLoggerClient(1, &uiaCfg);

 /* OMX IL client for decoder component */
  Capture_Encode_Example (&args);
  
  /* de initialze the DOMX / memory configuration */
  
  OMX_Deinit();
  
  exit (0);
}/* main */
/* static */ bool
PureOmxPlatformLayer::Init(void)
{
  if (!OmxCoreLibLinker::Link()) {
    return false;
  }

  OMX_ERRORTYPE err = OMX_Init();
  if (err != OMX_ErrorNone) {
    MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug,
            ("PureOmxPlatformLayer::%s: Failed to initialize OMXCore: 0x%08x",
             __func__, err));
    return false;
  }

  return true;
}
Beispiel #23
0
static void
goo_component_factory_init (GooComponentFactory *self)
{
	self->components = goo_component_list_new ();

	if (!g_thread_supported ())
	{
		GOO_OBJECT_DEBUG (self, "Starting thread subsystem");
		g_thread_init (NULL);
	}

	GOO_INFO ("OMX_Init");
	GOO_RUN (
		OMX_Init ()
		);

	return;
}
Beispiel #24
0
/**
********************************************************************************
 *  @fn     main 
 *  @brief  This function does the platform specific initialization and calls .
 *          the application specific test function OMX_Audio_Decode_Test()   
 *  @param[in ]  arg1  : input stream file
 *  @param[in ]  arg2  : output stream file
 *  @param[in ]  arg3  : decoder type 0:MP3 1:AAC]
 *  @param[in ]  arg4  : AAC stream format type 0:RAW 1:ADTS/ADIF]
 *  @param[in ]  arg5  : AAC RAW Source Sample Rate]
 *
 *  @returns none
********************************************************************************
*/
int main (int argc, char *argv[])
{
  //unsigned int eError;
  /*ConfigureUIA uiaCfg;*/
  IL_ARGS args;

  parse_args (argc, argv, &args);
  
  
  printf ("Audio Decoder example \n");
  printf ("===============================\n");


  /* Initializing OMX core , functions releated to platform specific
     initialization could be placed inside this */

   OMX_Init ();

  /* UIA is an utility to get the logs from firmware on Linux terminal, and also
     to use System Analyzer, Following UIA configuration is required to change 
     the default debug logging configuration, and is optional  */

  /* Configuring logging options on slave cores */
  /* can be 0 or 1 */
  /*uiaCfg.enableAnalysisEvents = 0;*/
  /* can be 0 or 1 */
  /*uiaCfg.enableStatusLogger = 1;*/
  /* can be OMX_DEBUG_LEVEL1|2|3|4|5 */
  /*uiaCfg.debugLevel = OMX_DEBUG_LEVEL1;*/
  /* configureUiaLoggerClient( COREID, &Cfg); */
  /*configureUiaLoggerClient(0, &uiaCfg);*/

  /* OMX IL client for decoder component */
  OMX_Audio_Decode_Test( args.input_file, args.output_file, args.codec,
	  atoi(args.rawFormat), atoi(args.sampleRate));

  OMX_Deinit();


  exit (0);

}/* main */
END_TEST
START_TEST (test_ilcore_role_of_comp_enum)
{
  OMX_ERRORTYPE error = OMX_ErrorNone;
  OMX_U32 index = 0;
  OMX_S8 role[OMX_MAX_STRINGNAME_SIZE];

  error = OMX_Init ();
  fail_if (error != OMX_ErrorNone);

  do
    {
      error = OMX_RoleOfComponentEnum ((OMX_STRING) role,
                                       TIZ_CORE_TEST_COMPONENT_NAME, index++);
      TIZ_LOG (TIZ_PRIORITY_TRACE, "[%s] : Role [%s] error [%s]",
               TIZ_CORE_TEST_COMPONENT_NAME, role, tiz_err_to_str (error));
    } while (OMX_ErrorNone == error);

  fail_if (OMX_ErrorNoMore != error);

  error = OMX_Deinit ();
  fail_if (error != OMX_ErrorNone);
}
END_TEST
START_TEST (test_ilcore_comp_of_role_enum)
{
  OMX_ERRORTYPE error = OMX_ErrorNone;
  OMX_U32 index = 0;
  OMX_S8 comp_name[OMX_MAX_STRINGNAME_SIZE];

  error = OMX_Init ();
  fail_if (error != OMX_ErrorNone);

  do
    {
      error = OMX_ComponentOfRoleEnum ((OMX_STRING) comp_name,
                                       TIZ_CORE_TEST_COMPONENT_ROLE, index++);
      TIZ_LOG (TIZ_PRIORITY_TRACE, "[%s] : component [%s] error [%s]",
               TIZ_CORE_TEST_COMPONENT_ROLE, comp_name, tiz_err_to_str (error));
    } while (OMX_ErrorNone == error);

  fail_if (OMX_ErrorNoMore != error);
  fail_if (index != 2);

  error = OMX_Deinit ();
  fail_if (error != OMX_ErrorNone);
}
Beispiel #27
0
// Modified function prototype to work with pthreads
void *video_decode_test(void* arg)
{
    const char* filename = "/opt/vc/src/hello_pi/hello_video/test.h264";
    eglImage = arg;

    if (eglImage == 0)
    {
        printf("eglImage is null.\n");
        exit(1);
    }

    OMX_VIDEO_PARAM_PORTFORMATTYPE format;
    OMX_TIME_CONFIG_CLOCKSTATETYPE cstate;
    COMPONENT_T *video_decode = NULL, *video_scheduler = NULL, *clock = NULL;
    COMPONENT_T *list[5];
    TUNNEL_T tunnel[4];
    ILCLIENT_T *client;
    FILE *in;
    int status = 0;
    unsigned int data_len = 0;
    int packet_size = 80<<10;

    memset(list, 0, sizeof(list));
    memset(tunnel, 0, sizeof(tunnel));

    if((in = fopen(filename, "rb")) == NULL)
        return (void *)-2;

    if((client = ilclient_init()) == NULL)
    {
        fclose(in);
        return (void *)-3;
    }

    if(OMX_Init() != OMX_ErrorNone)
    {
        ilclient_destroy(client);
        fclose(in);
        return (void *)-4;
    }

    // callback
    ilclient_set_fill_buffer_done_callback(client, my_fill_buffer_done, 0);

    // create video_decode
    if(ilclient_create_component(client, &video_decode, "video_decode", ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0)
        status = -14;
    list[0] = video_decode;

    // create video_render
    //if(status == 0 && ilclient_create_component(client, &video_render, "video_render", ILCLIENT_DISABLE_ALL_PORTS) != 0)
    if(status == 0 && ilclient_create_component(client, &video_render, "egl_render", ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_OUTPUT_BUFFERS) != 0)
        status = -14;
    list[1] = video_render;

    // create clock
    if(status == 0 && ilclient_create_component(client, &clock, "clock", ILCLIENT_DISABLE_ALL_PORTS) != 0)
        status = -14;
    list[2] = clock;

    memset(&cstate, 0, sizeof(cstate));
    cstate.nSize = sizeof(cstate);
    cstate.nVersion.nVersion = OMX_VERSION;
    cstate.eState = OMX_TIME_ClockStateWaitingForStartTime;
    cstate.nWaitMask = 1;
    if(clock != NULL && OMX_SetParameter(ILC_GET_HANDLE(clock), OMX_IndexConfigTimeClockState, &cstate) != OMX_ErrorNone)
        status = -13;

    // create video_scheduler
    if(status == 0 && ilclient_create_component(client, &video_scheduler, "video_scheduler", ILCLIENT_DISABLE_ALL_PORTS) != 0)
        status = -14;
    list[3] = video_scheduler;

    set_tunnel(tunnel, video_decode, 131, video_scheduler, 10);
    //set_tunnel(tunnel+1, video_scheduler, 11, video_render, 90);
    set_tunnel(tunnel+1, video_scheduler, 11, video_render, 220);
    set_tunnel(tunnel+2, clock, 80, video_scheduler, 12);

    // setup clock tunnel first
    if(status == 0 && ilclient_setup_tunnel(tunnel+2, 0, 0) != 0)
        status = -15;
    else
        ilclient_change_component_state(clock, OMX_StateExecuting);

    if(status == 0)
        ilclient_change_component_state(video_decode, OMX_StateIdle);

    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;

    if(status == 0 &&
            OMX_SetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamVideoPortFormat, &format) == OMX_ErrorNone &&
            ilclient_enable_port_buffers(video_decode, 130, NULL, NULL, NULL) == 0)
    {
        OMX_BUFFERHEADERTYPE *buf;
        int port_settings_changed = 0;
        int first_packet = 1;

        ilclient_change_component_state(video_decode, OMX_StateExecuting);

        while((buf = ilclient_get_input_buffer(video_decode, 130, 1)) != NULL)
        {
            // feed data and wait until we get port settings changed
            unsigned char *dest = buf->pBuffer;

            // loop if at end
            if (feof(in))
                rewind(in);

            data_len += fread(dest, 1, packet_size-data_len, in);

            if(port_settings_changed == 0 &&
                    ((data_len > 0 && ilclient_remove_event(video_decode, OMX_EventPortSettingsChanged, 131, 0, 0, 1) == 0) ||
                     (data_len == 0 && ilclient_wait_for_event(video_decode, OMX_EventPortSettingsChanged, 131, 0, 0, 1,
                             ILCLIENT_EVENT_ERROR | ILCLIENT_PARAMETER_CHANGED, 10000) == 0)))
            {
                port_settings_changed = 1;

                if(ilclient_setup_tunnel(tunnel, 0, 0) != 0)
                {
                    status = -7;
                    break;
                }

                ilclient_change_component_state(video_scheduler, OMX_StateExecuting);

                // now setup tunnel to video_render
                if(ilclient_setup_tunnel(tunnel+1, 0, 1000) != 0)
                {
                    status = -12;
                    break;
                }

                // Set egl_render to idle
                ilclient_change_component_state(video_render, OMX_StateIdle);

                // Enable the output port and tell egl_render to use the texture as a buffer
                //ilclient_enable_port(video_render, 221); THIS BLOCKS SO CANT BE USED
                if (OMX_SendCommand(ILC_GET_HANDLE(video_render), OMX_CommandPortEnable, 221, NULL) != OMX_ErrorNone)
                {
                    printf("OMX_CommandPortEnable failed.\n");
                    exit(1);
                }

                if (OMX_UseEGLImage(ILC_GET_HANDLE(video_render), &eglBuffer, 221, NULL, eglImage) != OMX_ErrorNone)
                {
                    printf("OMX_UseEGLImage failed.\n");
                    exit(1);
                }

                // Set egl_render to executing
                ilclient_change_component_state(video_render, OMX_StateExecuting);


                // Request egl_render to write data to the texture buffer
                if(OMX_FillThisBuffer(ILC_GET_HANDLE(video_render), eglBuffer) != OMX_ErrorNone)
                {
                    printf("OMX_FillThisBuffer failed.\n");
                    exit(1);
                }
            }
            if(!data_len)
                break;

            buf->nFilledLen = data_len;
            data_len = 0;

            buf->nOffset = 0;
            if(first_packet)
            {
                buf->nFlags = OMX_BUFFERFLAG_STARTTIME;
                first_packet = 0;
            }
            else
                buf->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN;

            if(OMX_EmptyThisBuffer(ILC_GET_HANDLE(video_decode), buf) != OMX_ErrorNone)
            {
                status = -6;
                break;
            }
        }

        buf->nFilledLen = 0;
        buf->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN | OMX_BUFFERFLAG_EOS;

        if(OMX_EmptyThisBuffer(ILC_GET_HANDLE(video_decode), buf) != OMX_ErrorNone)
            status = -20;

        // wait for EOS from render
        ilclient_wait_for_event(video_render, OMX_EventBufferFlag, 90, 0, OMX_BUFFERFLAG_EOS, 0,
                                ILCLIENT_BUFFER_FLAG_EOS, 10000);

        // need to flush the renderer to allow video_decode to disable its input port
        ilclient_flush_tunnels(tunnel, 0);

        ilclient_disable_port_buffers(video_decode, 130, NULL, NULL, NULL);
    }

    fclose(in);

    ilclient_disable_tunnel(tunnel);
    ilclient_disable_tunnel(tunnel+1);
    ilclient_disable_tunnel(tunnel+2);
    ilclient_teardown_tunnels(tunnel);

    ilclient_state_transition(list, OMX_StateIdle);
    ilclient_state_transition(list, OMX_StateLoaded);

    ilclient_cleanup_components(list);

    OMX_Deinit();

    ilclient_destroy(client);
    return (void *)status;
}
static void omx_init(audio_backend_pull_callback_t pull_callback)
{
	OMX_ERRORTYPE error;

	error = OMX_Init();
	if(error != OMX_ErrorNone)
	{
		fprintf(stderr, "OMX: OMX_Init() failed. Error 0x%X\n", error);
		return;
	}

	// Initialize settings
	latency_max = settings.omx.Audio_Latency;
	buffer_size = settings.aica.BufferSize * 4;
	buffer_count = 2 + OUTPUT_FREQ * latency_max / (buffer_size * 1000);

	OMX_CALLBACKTYPE callbacks;
	callbacks.EventHandler = EventHandler;
	callbacks.EmptyBufferDone = EmptyBufferDone;
	callbacks.EmptyBufferDone = FillBufferDone;

	error = OMX_GetHandle(&omx_handle, (OMX_STRING)"OMX.broadcom.audio_render", NULL, &callbacks);
	if(error != OMX_ErrorNone)
	{
		fprintf(stderr, "OMX: OMX_GetHandle() failed. Error 0x%X\n", error);
		return;
	}

	OMX_PARAM_PORTDEFINITIONTYPE param;
	memset(&param, 0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
	param.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
	param.nVersion.nVersion = OMX_VERSION;
	param.nPortIndex = PORT_INDEX;
	param.nBufferSize = buffer_size;
	param.nBufferCountActual = buffer_count;
	param.format.audio.eEncoding = OMX_AUDIO_CodingPCM;

	error = OMX_SetParameter(omx_handle, OMX_IndexParamPortDefinition, &param);
	if(error != OMX_ErrorNone)
		fprintf(stderr, "OMX: failed to set OMX_IndexParamPortDefinition. Error 0x%X\n", error);

	OMX_AUDIO_PARAM_PCMMODETYPE pcm;
	memset(&pcm, 0, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
	pcm.nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE);
	pcm.nVersion.nVersion = OMX_VERSION;
	pcm.nPortIndex = PORT_INDEX;
	pcm.nChannels = 2;
	pcm.eNumData = OMX_NumericalDataSigned;
	pcm.eEndian = OMX_EndianLittle;
	pcm.nSamplingRate = OUTPUT_FREQ;
	pcm.bInterleaved = OMX_TRUE;
	pcm.nBitPerSample = 16;
	pcm.ePCMMode = OMX_AUDIO_PCMModeLinear;
	pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
	pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF;

	error = OMX_SetParameter(omx_handle, OMX_IndexParamAudioPcm, &pcm);
	if(error != OMX_ErrorNone)
		fprintf(stderr, "OMX: failed to set OMX_IndexParamAudioPcm. Error 0x%X\n", error);

	// Disable all ports
	error = OMX_SendCommand(omx_handle, OMX_CommandPortDisable, PORT_INDEX, NULL);
	if(error != OMX_ErrorNone)
		fprintf(stderr, "OMX: failed to do OMX_CommandPortDisable. Error 0x%X\n", error);

	OMX_PORT_PARAM_TYPE param2;
	memset(&param2, 0, sizeof(OMX_PORT_PARAM_TYPE));
	param2.nSize = sizeof(OMX_PORT_PARAM_TYPE);
	param2.nVersion.nVersion = OMX_VERSION;
	error = OMX_GetParameter(omx_handle, OMX_IndexParamOtherInit, &param2);
	if(error != OMX_ErrorNone)
	{
		fprintf(stderr, "OMX: failed to get OMX_IndexParamOtherInit. Error 0x%X\n", error);
	}
	else
	{
		for(u32 i = 0; i < param2.nPorts; i++)
		{
			u32 port = param2.nStartPortNumber + i;
			error = OMX_SendCommand(omx_handle, OMX_CommandPortDisable, port, NULL);
			if(error != OMX_ErrorNone)
				fprintf(stderr, "OMX: failed to do OMX_CommandPortDisable on port %u. Error 0x%X\n", port, error);
		}
	}

	// Go into idle state
	error = OMX_SendCommand(omx_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
	if(error != OMX_ErrorNone)
	{
		fprintf(stderr, "OMX: failed to set OMX_CommandStateSet. Error 0x%X\n", error);
		return;
	}
	omx_wait_for_state(OMX_StateIdle);

	// Check if we're in a state able to recieve buffers
	OMX_STATETYPE state;
	error = OMX_GetState(omx_handle, &state);
	if(error != OMX_ErrorNone || !(state == OMX_StateIdle || state == OMX_StateExecuting || state == OMX_StatePause))
	{
		fprintf(stderr, "OMX: state is incorrect. State 0x%X; Error 0x%X\n", state, error);
		return;
	}

	// Create audio buffers
	fprintf(stderr, "OMX: creating %u buffers\n", buffer_count);

	// Enable port
	error = OMX_SendCommand(omx_handle, OMX_CommandPortEnable, PORT_INDEX, NULL);
	if(error != OMX_ErrorNone)
		fprintf(stderr, "OMX: failed to do OMX_CommandPortEnable. Error 0x%X\n", error);

	// Free audio buffers if they're allocated
	if(audio_buffers != NULL)
		delete[] audio_buffers;

	// Allocate buffers
	audio_buffers = new OMX_BUFFERHEADERTYPE*[buffer_count];
	for(size_t i = 0; i < buffer_count; i++)
	{
		error = OMX_AllocateBuffer(omx_handle, &audio_buffers[i], PORT_INDEX, NULL, buffer_size);
		if(error != OMX_ErrorNone)
		{
			fprintf(stderr, "OMX: failed to allocate buffer[%u]. Error 0x%X\n", i, error);
			return;
		}
	}

	// Set state to executing
	error = OMX_SendCommand(omx_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
	if(error != OMX_ErrorNone)
	{
		fprintf(stderr, "OMX: failed to do OMX_CommandStateSet. Error 0x%X\n", error);
		return;
	}
	omx_wait_for_state(OMX_StateExecuting);

	// Empty buffers
	for(size_t i = 0; i < buffer_count; i++)
	{
		memset(audio_buffers[i]->pBuffer, 0, buffer_size);
		audio_buffers[i]->nOffset = 0;
		audio_buffers[i]->nFilledLen = buffer_size;

		error = OMX_EmptyThisBuffer(omx_handle, audio_buffers[i]);
		if(error != OMX_ErrorNone)
			fprintf(stderr, "OMX: failed to empty buffer[%u]. Error 0x%X\n", i, error);
	}

	char* output_device = "local";
	if(settings.omx.Audio_HDMI)
		output_device = (char*)"hdmi";

	// Set audio destination
	OMX_CONFIG_BRCMAUDIODESTINATIONTYPE ar_dest;
	memset(&ar_dest, 0, sizeof(ar_dest));
	ar_dest.nSize = sizeof(OMX_CONFIG_BRCMAUDIODESTINATIONTYPE);
	ar_dest.nVersion.nVersion = OMX_VERSION;
	strcpy((char *)ar_dest.sName, output_device);
	error = OMX_SetConfig(omx_handle, OMX_IndexConfigBrcmAudioDestination, &ar_dest);
	if(error != OMX_ErrorNone)
	{
		fprintf(stderr, "OMX: failed to set OMX configuration (OMX_IndexConfigBrcmAudioDestination). Error 0x%X\n", error);
		return;
	}

	audio_buffer_idx = 0;
	buffer_length = 0;

	fprintf(stderr, "OMX: audio output to '%s'\n", ar_dest.sName);
}
    OMX_ERRORTYPE OMX_CONF_ComponentNameTest(OMX_IN OMX_STRING cComponentName)
    {
        OMX_ERRORTYPE  eError = OMX_ErrorNone;
        OMX_HANDLETYPE hComp  = 0;
        OMX_U32 i = 0;
        OMX_BOOL bNameValid = OMX_FALSE;
        OMX_BOOL bFound = OMX_FALSE;
        OMX_S8 cCompEnumName[TEST_COMPONENT_NAME_SIZE];
        OMX_CALLBACKTYPE sCallbacks;

        sCallbacks.EventHandler    = ComponentNameTest_EventHandler;
        sCallbacks.EmptyBufferDone = ComponentNameTest_EmptyBufferDone;
        sCallbacks.FillBufferDone  = ComponentNameTest_FillBufferDone;

        /* Initialize OpenMax */
        eError = OMX_Init();
        if (eError != OMX_ErrorNone)
        {
            goto OMX_CONF_TEST_BAIL;
        }

        while (OMX_ErrorNone == eError)
        {
            /* loop through all enumerated components to determine if the component name
               specificed for the test is enumerated by the OMX core */
            eError = OMX_ComponentNameEnum((OMX_STRING) cCompEnumName, TEST_COMPONENT_NAME_SIZE, i);
            if (OMX_ErrorNone == eError)
            {
                OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "OMX_ComponenNameEnum enumerated %s at index %i\n",
                               cCompEnumName, i);

                if (!strcmp((OMX_STRING) cCompEnumName, cComponentName))
                {
                    /* component name enumerated by OMX_CORE */
                    bFound = OMX_TRUE;

                    eError = OMX_GetHandle(&hComp, (OMX_STRING) cCompEnumName, 0x0, &sCallbacks);
                    if (eError == OMX_ErrorNone)
                    {
                        /* validate the first 4 characters of the name match
                           the OMX standard */
                        if (!strncmp("OMX.", cComponentName, 4))
                        {
                            bNameValid = OMX_TRUE;
                        }

                        eError = OMX_FreeHandle(hComp);

                    }
                    else
                    {
                        OMX_CONF_ErrorToString(eError, szDesc);
                        OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "%s error=0x%X (%s) from OMX_GetHandle\n",
                                       cCompEnumName, eError, szDesc);

                    }

                }

            }
            else if (OMX_ErrorNoMore != eError)
            {
                /* OMX_CORE reported unexpected error other than no more components */
                OMX_CONF_ErrorToString(eError, szDesc);
                OMX_OSAL_Trace(OMX_OSAL_TRACE_ERROR, "unexepected error=0x%X (%s) from OMX_ComponenNameEnum\n",
                               eError, szDesc);
            }
            i++;

        }

        if (OMX_ErrorNoMore == eError)
        {
            /* not an error, so clear the error code */
            eError = OMX_ErrorNone;
        }


OMX_CONF_TEST_BAIL:

        if (OMX_ErrorNone == eError)
        {
            eError = OMX_Deinit();

        }
        else
        {
            OMX_Deinit();
        }

        return eError;
    }
int encoder_init(struct picture_t *info,int fps,int bright,int video_bitrate)
{
	//tem_width=info->width;
	bcm_host_init();
	
    OMX_ERRORTYPE r;

    if((r = OMX_Init()) != OMX_ErrorNone) {
        omx_die(r, "OMX initalization failed");
    }

    // Init context
    
    memset(&ctx, 0, sizeof(ctx));
    if(vcos_semaphore_create(&ctx.handler_lock, "handler_lock", 1) != VCOS_SUCCESS) {
        die("Failed to create handler lock semaphore");
    }
	
    // Init component handles
    OMX_CALLBACKTYPE callbacks;
    memset(&ctx, 0, sizeof(callbacks));
    callbacks.EventHandler   = event_handler;
    callbacks.FillBufferDone = fill_output_buffer_done_handler;

    init_component_handle("camera", &ctx.camera , &ctx, &callbacks);
    init_component_handle("video_encode", &ctx.encoder, &ctx, &callbacks);
    init_component_handle("null_sink", &ctx.null_sink, &ctx, &callbacks);
    
    /*
    OMX_CALLBACKTYPE callbacks1;
    memset(&ctx, 0, sizeof(callbacks1));
    callbacks1.EventHandler   = event_handler;
    callbacks1.FillBufferDone = fill_camera_output_buffer_done_handler;
*/
    init_component_handle("camera", &ctx.camera , &ctx, &callbacks);
	//===============change^^^^================
	
    //say("Configuring camera...");

    //say("Default port definition for camera input port 73");
    dump_port(ctx.camera, 73, OMX_TRUE);
    //say("Default port definition for camera preview output port 70");
    dump_port(ctx.camera, 70, OMX_TRUE);
    //say("Default port definition for camera video output port 71");
    dump_port(ctx.camera, 71, OMX_TRUE);

    // Request a callback to be made when OMX_IndexParamCameraDeviceNumber is
    // changed signaling that the camera device is ready for use.
    OMX_CONFIG_REQUESTCALLBACKTYPE cbtype;
    OMX_INIT_STRUCTURE(cbtype);
    cbtype.nPortIndex = OMX_ALL;
    cbtype.nIndex     = OMX_IndexParamCameraDeviceNumber;
    cbtype.bEnable    = OMX_TRUE;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigRequestCallback, &cbtype)) != OMX_ErrorNone) {
        omx_die(r, "Failed to request camera device number parameter change callback for camera");
    }
    // Set device number, this triggers the callback configured just above
    OMX_PARAM_U32TYPE device;
    OMX_INIT_STRUCTURE(device);
    device.nPortIndex = OMX_ALL;
    device.nU32 = CAM_DEVICE_NUMBER;
    if((r = OMX_SetParameter(ctx.camera, OMX_IndexParamCameraDeviceNumber, &device)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera parameter device number");
    }
    // Configure video format emitted by camera preview output port
    OMX_PARAM_PORTDEFINITIONTYPE camera_portdef;
    OMX_INIT_STRUCTURE(camera_portdef);
    camera_portdef.nPortIndex = 70;
    if((r = OMX_GetParameter(ctx.camera, OMX_IndexParamPortDefinition, &camera_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to get port definition for camera preview output port 70");
    }
    camera_portdef.format.video.nFrameWidth  = info->width;
    camera_portdef.format.video.nFrameHeight = info->height;
    camera_portdef.format.video.xFramerate   = fps << 16;
    // Stolen from gstomxvideodec.c of gst-omx
    camera_portdef.format.video.nStride      = (camera_portdef.format.video.nFrameWidth + camera_portdef.nBufferAlignment - 1) & (~(camera_portdef.nBufferAlignment - 1));
    camera_portdef.format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
    if((r = OMX_SetParameter(ctx.camera, OMX_IndexParamPortDefinition, &camera_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set port definition for camera preview output port 70");
    }
    // Configure video format emitted by camera video output port
    // Use configuration from camera preview output as basis for
    // camera video output configuration
    OMX_INIT_STRUCTURE(camera_portdef);
    camera_portdef.nPortIndex = 70;
    if((r = OMX_GetParameter(ctx.camera, OMX_IndexParamPortDefinition, &camera_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to get port definition for camera preview output port 70");
    }
    camera_portdef.nPortIndex = 71;
    if((r = OMX_SetParameter(ctx.camera, OMX_IndexParamPortDefinition, &camera_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set port definition for camera video output port 71");
    }
    // Configure frame rate
    OMX_CONFIG_FRAMERATETYPE framerate;
    OMX_INIT_STRUCTURE(framerate);
    framerate.nPortIndex = 70;
    framerate.xEncodeFramerate = camera_portdef.format.video.xFramerate;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigVideoFramerate, &framerate)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set framerate configuration for camera preview output port 70");
    }
    framerate.nPortIndex = 71;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigVideoFramerate, &framerate)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set framerate configuration for camera video output port 71");
    }
    // Configure sharpness
    OMX_CONFIG_SHARPNESSTYPE sharpness;
    OMX_INIT_STRUCTURE(sharpness);
    sharpness.nPortIndex = OMX_ALL;
    sharpness.nSharpness = CAM_SHARPNESS;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonSharpness, &sharpness)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera sharpness configuration");
    }
    // Configure contrast
    OMX_CONFIG_CONTRASTTYPE contrast;
    OMX_INIT_STRUCTURE(contrast);
    contrast.nPortIndex = OMX_ALL;
    contrast.nContrast = CAM_CONTRAST;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonContrast, &contrast)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera contrast configuration");
    }
    // Configure saturation
    OMX_CONFIG_SATURATIONTYPE saturation;
    OMX_INIT_STRUCTURE(saturation);
    saturation.nPortIndex = OMX_ALL;
    saturation.nSaturation = CAM_SATURATION;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonSaturation, &saturation)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera saturation configuration");
    }
    // Configure brightness
    OMX_CONFIG_BRIGHTNESSTYPE brightness;
    OMX_INIT_STRUCTURE(brightness);
    brightness.nPortIndex = OMX_ALL;
    brightness.nBrightness = bright;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonBrightness, &brightness)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera brightness configuration");
    }
    // Configure exposure value
    OMX_CONFIG_EXPOSUREVALUETYPE exposure_value;
    OMX_INIT_STRUCTURE(exposure_value);
    exposure_value.nPortIndex = OMX_ALL;
    exposure_value.xEVCompensation = CAM_EXPOSURE_VALUE_COMPENSTAION;
    exposure_value.bAutoSensitivity = CAM_EXPOSURE_AUTO_SENSITIVITY;
    exposure_value.nSensitivity = CAM_EXPOSURE_ISO_SENSITIVITY;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonExposureValue, &exposure_value)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera exposure value configuration");
    }
    // Configure frame frame stabilisation
    OMX_CONFIG_FRAMESTABTYPE frame_stabilisation_control;
    OMX_INIT_STRUCTURE(frame_stabilisation_control);
    frame_stabilisation_control.nPortIndex = OMX_ALL;
    frame_stabilisation_control.bStab = CAM_FRAME_STABILISATION;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonFrameStabilisation, &frame_stabilisation_control)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera frame frame stabilisation control configuration");
    }
    // Configure frame white balance control
    OMX_CONFIG_WHITEBALCONTROLTYPE white_balance_control;
    OMX_INIT_STRUCTURE(white_balance_control);
    white_balance_control.nPortIndex = OMX_ALL;
    white_balance_control.eWhiteBalControl = CAM_WHITE_BALANCE_CONTROL;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonWhiteBalance, &white_balance_control)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera frame white balance control configuration");
    }
    // Configure image filter
    OMX_CONFIG_IMAGEFILTERTYPE image_filter;
    OMX_INIT_STRUCTURE(image_filter);
    image_filter.nPortIndex = OMX_ALL;
    image_filter.eImageFilter = CAM_IMAGE_FILTER;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonImageFilter, &image_filter)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera image filter configuration");
    }
    // Configure mirror
    OMX_MIRRORTYPE eMirror = OMX_MirrorNone;
    if(CAM_FLIP_HORIZONTAL && !CAM_FLIP_VERTICAL) {
        eMirror = OMX_MirrorHorizontal;
    } else if(!CAM_FLIP_HORIZONTAL && CAM_FLIP_VERTICAL) {
        eMirror = OMX_MirrorVertical;
    } else if(CAM_FLIP_HORIZONTAL && CAM_FLIP_VERTICAL) {
        eMirror = OMX_MirrorBoth;
    }
    OMX_CONFIG_MIRRORTYPE mirror;
    OMX_INIT_STRUCTURE(mirror);
    mirror.nPortIndex = 71;
    mirror.eMirror = eMirror;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonMirror, &mirror)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set mirror configuration for camera video output port 71");
    }

    // Ensure camera is ready
    while(!ctx.camera_ready) {
        usleep(10000);
    }

    //say("Configuring encoder...");

    //say("Default port definition for encoder input port 200");
    dump_port(ctx.encoder, 200, OMX_TRUE);
    //say("Default port definition for encoder output port 201");
    dump_port(ctx.encoder, 201, OMX_TRUE);

    // Encoder input port definition is done automatically upon tunneling

    // Configure video format emitted by encoder output port
    OMX_PARAM_PORTDEFINITIONTYPE encoder_portdef;
    OMX_INIT_STRUCTURE(encoder_portdef);
    encoder_portdef.nPortIndex = 201;
    if((r = OMX_GetParameter(ctx.encoder, OMX_IndexParamPortDefinition, &encoder_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to get port definition for encoder output port 201");
    }
    // Copy some of the encoder output port configuration
    // from camera output port
    encoder_portdef.format.video.nFrameWidth  = camera_portdef.format.video.nFrameWidth;
    encoder_portdef.format.video.nFrameHeight = camera_portdef.format.video.nFrameHeight;
    encoder_portdef.format.video.xFramerate   = camera_portdef.format.video.xFramerate;
    encoder_portdef.format.video.nStride      = camera_portdef.format.video.nStride;
    // Which one is effective, this or the configuration just below?
    encoder_portdef.format.video.nBitrate     = video_bitrate;
    if((r = OMX_SetParameter(ctx.encoder, OMX_IndexParamPortDefinition, &encoder_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set port definition for encoder output port 201");
    }
    // Configure bitrate
    OMX_VIDEO_PARAM_BITRATETYPE bitrate;
    OMX_INIT_STRUCTURE(bitrate);
    bitrate.eControlRate = OMX_Video_ControlRateVariable;
    bitrate.nTargetBitrate = encoder_portdef.format.video.nBitrate;
    bitrate.nPortIndex = 201;
    if((r = OMX_SetParameter(ctx.encoder, OMX_IndexParamVideoBitrate, &bitrate)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set bitrate for encoder output port 201");
    }
    // Configure format
    OMX_VIDEO_PARAM_PORTFORMATTYPE format;
    OMX_INIT_STRUCTURE(format);
    format.nPortIndex = 201;
    format.eCompressionFormat = OMX_VIDEO_CodingAVC;
    if((r = OMX_SetParameter(ctx.encoder, OMX_IndexParamVideoPortFormat, &format)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set video format for encoder output port 201");
    }
	
	OMX_CONFIG_PORTBOOLEANTYPE inlineHeader;
    OMX_INIT_STRUCTURE(inlineHeader);
    inlineHeader.nPortIndex = 201;
    inlineHeader.bEnabled = OMX_TRUE; 
    if((r = OMX_SetParameter(ctx.encoder, OMX_IndexParamBrcmVideoAVCInlineHeaderEnable, &inlineHeader)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch on inlineHeader on video encoder output port 201");
    }
	
	 OMX_VIDEO_PARAM_AVCTYPE avc_st;
  OMX_INIT_STRUCTURE (avc_st);
  avc_st.nPortIndex = 201;
  if ((r = OMX_GetParameter (ctx.encoder,
      OMX_IndexParamVideoAvc, &avc_st))){
    omx_die(r, "Failed to switch on avc_st on video encoder output port 201");
  }
  avc_st.nPFrames = VIDEO_FRAMERATE-1;
  if ((r = OMX_SetParameter (ctx.encoder,
      OMX_IndexParamVideoAvc, &avc_st))){
    omx_die(r, "Failed to switch on avc_st on video encoder output port 201");
  }
	

    //say("Default port definition for null sink input port 240");
    dump_port(ctx.null_sink, 240, OMX_TRUE);

    // Null sink input port definition is done automatically upon tunneling

    // Tunnel camera preview output port and null sink input port
    //say("Setting up tunnel from camera preview output port 70 to null sink input port 240...");
    if((r = OMX_SetupTunnel(ctx.camera, 70, ctx.null_sink, 240)) != OMX_ErrorNone) {
        omx_die(r, "Failed to setup tunnel between camera preview output port 70 and null sink input port 240");
    }

    // Tunnel camera video output port and encoder input port
    //say("Setting up tunnel from camera video output port 71 to encoder input port 200...");
    if((r = OMX_SetupTunnel(ctx.camera, 71, ctx.encoder, 200)) != OMX_ErrorNone) {
        omx_die(r, "Failed to setup tunnel between camera video output port 71 and encoder input port 200");
    }

    // Switch components to idle state
    //say("Switching state of the camera component to idle...");
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the camera component to idle");
    }
    block_until_state_changed(ctx.camera, OMX_StateIdle);
    //say("Switching state of the encoder component to idle...");
    if((r = OMX_SendCommand(ctx.encoder, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the encoder component to idle");
    }
    block_until_state_changed(ctx.encoder, OMX_StateIdle);
    //say("Switching state of the null sink component to idle...");
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the null sink component to idle");
    }
    block_until_state_changed(ctx.null_sink, OMX_StateIdle);

    // Enable ports
    //say("Enabling ports...");
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortEnable, 73, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable camera input port 73");
    }
    block_until_port_changed(ctx.camera, 73, OMX_TRUE);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortEnable, 70, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable camera preview output port 70");
    }
    block_until_port_changed(ctx.camera, 70, OMX_TRUE);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortEnable, 71, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable camera video output port 71");
    }
    block_until_port_changed(ctx.camera, 71, OMX_TRUE);
    if((r = OMX_SendCommand(ctx.encoder, OMX_CommandPortEnable, 200, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable encoder input port 200");
    }
    block_until_port_changed(ctx.encoder, 200, OMX_TRUE);
    if((r = OMX_SendCommand(ctx.encoder, OMX_CommandPortEnable, 201, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable encoder output port 201");
    }
    block_until_port_changed(ctx.encoder, 201, OMX_TRUE);
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandPortEnable, 240, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable null sink input port 240");
    }
    block_until_port_changed(ctx.null_sink, 240, OMX_TRUE);

    // Allocate camera input buffer and encoder output buffer,
    // buffers for tunneled ports are allocated internally by OMX
    //say("Allocating buffers...");
    OMX_INIT_STRUCTURE(camera_portdef);
    camera_portdef.nPortIndex = 73;
    if((r = OMX_GetParameter(ctx.camera, OMX_IndexParamPortDefinition, &camera_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to get port definition for camera input port 73");
    }
    if((r = OMX_AllocateBuffer(ctx.camera, &ctx.camera_ppBuffer_in, 73, NULL, camera_portdef.nBufferSize)) != OMX_ErrorNone) {
        omx_die(r, "Failed to allocate buffer for camera input port 73");
    }
    /*
    camera_portdef.nPortIndex = 71;
    if((r = OMX_AllocateBuffer(ctx.camera, &ctx.camera_ppBuffer_out, 71, NULL, camera_portdef.nBufferSize)) != OMX_ErrorNone) {
        omx_die(r, "Failed to allocate buffer for camera output port 71");
    }
    */
    OMX_INIT_STRUCTURE(encoder_portdef);
    encoder_portdef.nPortIndex = 201;
    if((r = OMX_GetParameter(ctx.encoder, OMX_IndexParamPortDefinition, &encoder_portdef)) != OMX_ErrorNone) {
        omx_die(r, "Failed to get port definition for encoder output port 201");
    }
    if((r = OMX_AllocateBuffer(ctx.encoder, &ctx.encoder_ppBuffer_out, 201, NULL, encoder_portdef.nBufferSize)) != OMX_ErrorNone) {
        omx_die(r, "Failed to allocate buffer for encoder output port 201");
    }

    // Switch state of the components prior to starting
    // the video capture and encoding loop
    //say("Switching state of the camera component to executing...");
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the camera component to executing");
    }
    block_until_state_changed(ctx.camera, OMX_StateExecuting);
    //say("Switching state of the encoder component to executing...");
    if((r = OMX_SendCommand(ctx.encoder, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the encoder component to executing");
    }
    block_until_state_changed(ctx.encoder, OMX_StateExecuting);
    //say("Switching state of the null sink component to executing...");
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the null sink component to executing");
    }
    block_until_state_changed(ctx.null_sink, OMX_StateExecuting);


    OMX_CONFIG_PORTBOOLEANTYPE capture;
    OMX_INIT_STRUCTURE(capture);
    capture.nPortIndex = 71;
    capture.bEnabled = OMX_TRUE;
    if((r = OMX_SetParameter(ctx.camera, OMX_IndexConfigPortCapturing, &capture)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch on capture on camera video output port 71");
    }
	
    //say("Configured port definition for camera input port 73");
    dump_port(ctx.camera, 73, OMX_FALSE);
    //say("Configured port definition for camera preview output port 70");
    dump_port(ctx.camera, 70, OMX_FALSE);
    //say("Configured port definition for camera video output port 71");
    dump_port(ctx.camera, 71, OMX_FALSE);
    //say("Configured port definition for encoder input port 200");
    dump_port(ctx.encoder, 200, OMX_FALSE);
    //say("Configured port definition for encoder output port 201");
    dump_port(ctx.encoder, 201, OMX_FALSE);
    //say("Configured port definition for null sink input port 240");
    dump_port(ctx.null_sink, 240, OMX_FALSE);

    //say("Enter capture and encode loop, press Ctrl-C to quit...");

    return 1;
}