コード例 #1
0
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;
}
コード例 #2
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;
}
コード例 #3
0
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;
}
コード例 #4
0
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();
}
コード例 #5
0
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;
}
コード例 #6
0
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;
}
コード例 #7
0
void CPlayAudioFile::CleanupAndSetDeviceError(TPtrC16 aText)
	{
	iParent->SetVerdict(aText, EFail);
	delete iHwDevice;
	OMX_Deinit();	
	SetState(EHwDeviceError);
	}
コード例 #8
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);
}
コード例 #9
0
ファイル: core.c プロジェクト: cromarty/ttsprojects
int32_t ilctts_finalize() {
	OMX_ERRORTYPE omx_err;
	omx_err = OMX_Deinit();
	if (omx_err != OMX_ErrorNone) {
		ERROR("OMX_Deinit returned error in ilctts_finalize: %d", omx_err);
		return -1;
	}

	return 0;
} // end ilctts_finalize
コード例 #10
0
ファイル: main.c プロジェクト: makorasm/kfw_capture
/** 
********************************************************************************
 *  @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 */
コード例 #11
0
ファイル: encode_omx.cpp プロジェクト: F5OEO/v4l2tools
void encode_deinit(COMPONENT_T *handle, ILCLIENT_T *client)
{
        COMPONENT_T *list[] = {handle , NULL};

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

	ilclient_cleanup_components(list);

	OMX_Deinit();

	ilclient_destroy(client);
}
コード例 #12
0
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;
}
コード例 #13
0
ファイル: goo-component-factory.c プロジェクト: ceyusa/libgoo
static void
goo_component_factory_finalize (GObject* object)
{
	GooComponentFactory* self = GOO_COMPONENT_FACTORY (object);

	GOO_OBJECT_INFO (self, "OMX_Deinit");
	GOO_RUN (
		OMX_Deinit ()
		);

	singleton = NULL;

	(*G_OBJECT_CLASS (goo_component_factory_parent_class)->finalize) (object);
	return;
}
コード例 #14
0
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;
}
コード例 #15
0
static void omx_term()
{
	OMX_ERRORTYPE error;

	// Is there anything else that needs to be done for omx?

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

	if(audio_buffers != NULL)
	{
		delete[] audio_buffers;
		audio_buffers = NULL;
	}
}
コード例 #16
0
ファイル: main.c プロジェクト: andreimironenko/omx
/** 
********************************************************************************
 *  @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 */
コード例 #17
0
ファイル: main.c プロジェクト: andreimironenko/omx
/**
********************************************************************************
 *  @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 */
コード例 #18
0
void terminate() {
	print_log("On terminating...");

	OMX_STATETYPE state;
	OMX_BOOL bWaitForCamera, bWaitForRender;

	// Execute -> Idle
	bWaitForCamera = bWaitForRender = OMX_FALSE;
	if(isState(mContext.pCamera, OMX_StateExecuting)) {
		OMX_SendCommand(mContext.pCamera, OMX_CommandStateSet, OMX_StateIdle, NULL);
		bWaitForCamera = OMX_TRUE;
	}
	if(isState(mContext.pRender, OMX_StateExecuting)) {
		OMX_SendCommand(mContext.pRender, OMX_CommandStateSet, OMX_StateIdle, NULL);
		bWaitForRender = OMX_TRUE;
	}
	if(bWaitForCamera) wait_for_state_change(OMX_StateIdle, mContext.pCamera, NULL);
	if(bWaitForRender) wait_for_state_change(OMX_StateIdle, mContext.pRender, NULL);

	// Idle -> Loaded
	bWaitForCamera = bWaitForRender = OMX_FALSE;
	if(isState(mContext.pCamera, OMX_StateIdle)) {
		OMX_SendCommand(mContext.pCamera, OMX_CommandStateSet, OMX_StateLoaded, NULL);
		bWaitForCamera = OMX_TRUE;
	}
	if(isState(mContext.pRender, OMX_StateIdle)) {
		OMX_SendCommand(mContext.pRender, OMX_CommandStateSet, OMX_StateLoaded, NULL);
		bWaitForRender = OMX_TRUE;
	}
	if(bWaitForCamera) wait_for_state_change(OMX_StateLoaded, mContext.pCamera, NULL);
	if(bWaitForRender) wait_for_state_change(OMX_StateLoaded, mContext.pRender, NULL);

	// Loaded -> Free
	if(isState(mContext.pCamera, OMX_StateLoaded)) OMX_FreeHandle(mContext.pCamera);
	if(isState(mContext.pRender, OMX_StateLoaded)) OMX_FreeHandle(mContext.pRender);

	OMX_Deinit();

	print_log("Press enter to terminate.");
	getchar();
}
コード例 #19
0
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);
}
コード例 #20
0
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);
}
コード例 #21
0
/** mm_jpegdec_deinit:
 *
 *  Arguments:
 *    @my_obj: jpeg object
 *
 *  Return:
 *       0 for success else failure
 *
 *  Description:
 *       Deinits the jpeg client
 *
 **/
int32_t mm_jpegdec_deinit(mm_jpeg_obj *my_obj)
{
  int32_t rc = 0;

  /* release jobmgr thread */
  rc = mm_jpeg_jobmgr_thread_release(my_obj);
  if (0 != rc) {
    CDBG_ERROR("%s:%d] Error", __func__, __LINE__);
  }

  /* unload OMX engine */
  OMX_Deinit();

  /* deinit ongoing job and cb queue */
  rc = mm_jpeg_queue_deinit(&my_obj->ongoing_job_q);
  if (0 != rc) {
    CDBG_ERROR("%s:%d] Error", __func__, __LINE__);
  }

  /* destroy locks */
  pthread_mutex_destroy(&my_obj->job_lock);

  return rc;
}
コード例 #22
0
/*
    main
 */
int main(int argc, char **args)
{
    OMXCLIENT client;

    OMX_ERRORTYPE omxError;

    OMX_U32 *variance_array;

    OMX_U32 variance_array_len;

    memset(&parameters, 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, &parameters);
    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.7190.image.decoder",
                                           "image_decoder.jpeg",
                                           parameters.buffer_count);
        }
        else
        {
            omxError =
                omxclient_component_create(&client,
                                           "OMX.hantro.7190.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_jpeg(&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); */
            }

            /* 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;
}
コード例 #23
0
ファイル: video.c プロジェクト: guillaume-michel/userland_bgs
// 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;
}
    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;
    }
コード例 #25
0
// this function cleans up the decoder.
void
cleanup(OPENMAX_JPEG_DECODER * decoder)
{
    // flush everything through
    OMX_SendCommand(decoder->imageDecoder->handle,
		    OMX_CommandFlush, decoder->imageDecoder->outPort,
		    NULL);
    ilclient_wait_for_event(decoder->imageDecoder->component,
			    OMX_EventCmdComplete, OMX_CommandFlush, 0,
			    decoder->imageDecoder->outPort, 0, 0,
			    TIMEOUT_MS);

    OMX_SendCommand(decoder->imageDecoder->handle, OMX_CommandPortDisable,
		    decoder->imageDecoder->inPort, NULL);

    ilclient_wait_for_event(decoder->imageDecoder->component,
			    OMX_EventCmdComplete, OMX_CommandPortDisable,
			    0, decoder->imageDecoder->outPort, 0, 0,
			    TIMEOUT_MS);

    int             i = 0;
    for (i = 0; i < decoder->inputBufferHeaderCount; i++) {
	OMX_BUFFERHEADERTYPE *vpBufHeader =
	    decoder->ppInputBufferHeader[i];

	OMX_FreeBuffer(decoder->imageDecoder->handle,
		       decoder->imageDecoder->inPort, vpBufHeader);
    }

    ilclient_wait_for_event(decoder->imageDecoder->component,
			    OMX_EventCmdComplete, OMX_CommandPortDisable,
			    0, decoder->imageDecoder->inPort, 0, 0,
			    TIMEOUT_MS);

    OMX_FreeBuffer(decoder->imageDecoder->handle,
		   decoder->imageDecoder->outPort,
		   decoder->pOutputBufferHeader);

    ilclient_wait_for_event(decoder->imageDecoder->component,
			    OMX_EventCmdComplete, OMX_CommandPortDisable,
			    0, decoder->imageDecoder->outPort, 0, 0,
			    TIMEOUT_MS);

    ilclient_change_component_state(decoder->imageDecoder->component,
				    OMX_StateIdle);


    ilclient_change_component_state(decoder->imageDecoder->component,
				    OMX_StateLoaded);


    ilclient_wait_for_event(decoder->imageDecoder->component,
			    OMX_EventCmdComplete, OMX_CommandStateSet, 0,
			    OMX_StateLoaded, 0, 0, TIMEOUT_MS);

    OMX_Deinit();

    if (decoder->client != NULL) {
	ilclient_destroy(decoder->client);
    }
}
コード例 #26
0
void encoder_close()
{
	OMX_ERRORTYPE r;
	//say("Cleaning up...");

    // Stop capturing video with the camera
    OMX_CONFIG_PORTBOOLEANTYPE capture;
    OMX_INIT_STRUCTURE(capture);
    capture.nPortIndex = 71;
    capture.bEnabled = OMX_FALSE;
    if((r = OMX_SetParameter(ctx.camera, OMX_IndexConfigPortCapturing, &capture)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch off capture on camera video output port 71");
    }
	
    // Return the last full buffer back to the encoder component
    ctx.encoder_ppBuffer_out->nFlags = OMX_BUFFERFLAG_EOS;
    if((r = OMX_FillThisBuffer(ctx.encoder, ctx.encoder_ppBuffer_out)) != OMX_ErrorNone) {
        omx_die(r, "Failed to request filling of the output buffer on encoder output port 201");
    }
	//say("Cleaning up1...");

    // Disable all the ports
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortDisable, 73, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable camera input port 73");
    }
    //block_until_port_changed(ctx.camera, 73, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortDisable, 70, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable camera preview output port 70");
    }
    //block_until_port_changed(ctx.camera, 70, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortDisable, 71, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable camera video output port 71");
    }
    //block_until_port_changed(ctx.camera, 71, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.encoder, OMX_CommandPortDisable, 200, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable encoder input port 200");
    }
    //block_until_port_changed(ctx.encoder, 200, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.encoder, OMX_CommandPortDisable, 201, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable encoder output port 201");
    }
    //block_until_port_changed(ctx.encoder, 201, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandPortDisable, 240, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable null sink input port 240");
    }
    //block_until_port_changed(ctx.null_sink, 240, OMX_FALSE);
	//say("Cleaning up3...");
    // Free all the buffers
    if((r = OMX_FreeBuffer(ctx.camera, 73, ctx.camera_ppBuffer_in)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free buffer for camera input port 73");
    }
    if((r = OMX_FreeBuffer(ctx.encoder, 201, ctx.encoder_ppBuffer_out)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free buffer for encoder output port 201");
    }
	//say("Cleaning up4...");
    // Transition all the components to idle and then to loaded states
    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);
    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);
    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);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the camera component to loaded");
    }
    //block_until_state_changed(ctx.camera, OMX_StateLoaded);
    if((r = OMX_SendCommand(ctx.encoder, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the encoder component to loaded");
    }
    //block_until_state_changed(ctx.encoder, OMX_StateLoaded);
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the null sink component to loaded");
    }
    //block_until_state_changed(ctx.null_sink, OMX_StateLoaded);

    // Free the component handles
    if((r = OMX_FreeHandle(ctx.camera)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free camera component handle");
    }
    if((r = OMX_FreeHandle(ctx.encoder)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free encoder component handle");
    }
    if((r = OMX_FreeHandle(ctx.null_sink)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free null sink component handle");
    }

    vcos_semaphore_delete(&ctx.handler_lock);
    if((r = OMX_Deinit()) != OMX_ErrorNone) {
        omx_die(r, "OMX de-initalization failed");
    }
}
コード例 #27
0
ファイル: brcm_alsa_omx.c プロジェクト: kzlin129/tt-gpl
static int brcm_omx_vc03_stop(void)
{	
	OMX_ERRORTYPE error;
	
	//check if done?
	if (client==NULL) 
		return 0;
	
	DEBUG("\n %lx:brcm_omx_vc03_stop\n",jiffies);
	
	// cleanup
	// playback stuff
	if (play_init)
	{
		ilclient_change_component_state(&st_play, OMX_StateIdle);
		error = OMX_SendCommand(st_play.comp, OMX_CommandStateSet, OMX_StateLoaded, NULL);
		ERROR_RETURN("OMX_SendCommand",error);
	   
		if (st_play.out_list)
		{		
			DEBUG("\n OMX_FreeBuffer=%x %x\n",(int)st_play.out_list,(int)st_play.out_list->pAppPrivate);
			error = OMX_FreeBuffer(st_play.comp, 100, st_play.out_list);	  
			ERROR_RETURN("OMX_FreeBuffer",error);		
		}
		
		ilclient_cleanup_components(list_play);
		play_init=0;
	}
	

	// record stuff
	if (recd_init)
	{
		ilclient_change_component_state(&st_recd, OMX_StateIdle);
		error = OMX_SendCommand(st_recd.comp, OMX_CommandStateSet, OMX_StateLoaded, NULL);
		ERROR_RETURN("OMX_SendCommand",error);
   
		while (st_recd.out_list)
		{		
			OMX_BUFFERHEADERTYPE *next = st_recd.out_list->pAppPrivate;
			
			DEBUG("\n OMX_FreeBuffer=%x %x\n",(int)st_recd.out_list,(int)st_recd.out_list->pAppPrivate);
			error = OMX_FreeBuffer(st_recd.comp, 180, st_recd.out_list);	  
			ERROR_RETURN("OMX_FreeBuffer",error);	
			
			st_recd.out_list = next;	
		}
		
		ilclient_cleanup_components(list_recd);
		recd_init=0;
	}
	
	//
	//
	error = OMX_Deinit();
	ERROR_RETURN("OMX_Deinit",error);
	//
	ilclient_destroy(client);
	client=NULL;
	//
	
	return 0;	
}
コード例 #28
0
int main(int argc, char **argv)
{
    int bufCnt=0;
    OMX_ERRORTYPE result;
    struct sigaction sa;


    struct wav_header hdr;
    int bytes_writen = 0;

    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = &signal_handler;
    sigaction(SIGABRT, &sa, NULL);
    sigaction(SIGUSR1, &sa, NULL);
    sigaction(SIGUSR2, &sa, NULL);

    pthread_cond_init(&cond, 0);
    pthread_mutex_init(&lock, 0);


    if (argc >= 8) {
      in_filename = argv[1];
      samplerate = atoi(argv[2]);
      channels = atoi(argv[3]);
      pcmplayback = atoi(argv[4]);
      tunnel  = atoi(argv[5]);
        filewrite = atoi(argv[6]);
      sbr_ps_enabled = atoi(argv[7]);
      if (tunnel == 1) {
           pcmplayback = 0; /* This feature holds good only for non tunnel mode*/
            filewrite = 0;  /* File write not supported in tunnel mode */
      }
    } else {

        DEBUG_PRINT(" invalid format: \n");
        DEBUG_PRINT("ex: ./mm-adec-omxaac AACINPUTFILE SAMPFREQ CHANNEL PCMPLAYBACK TUNNEL FILEWRITE\n");
        DEBUG_PRINT( "PCMPLAYBACK = 1 (ENABLES PCM PLAYBACK IN NON TUNNEL MODE) \n");
        DEBUG_PRINT( "PCMPLAYBACK = 0 (DISABLES PCM PLAYBACK IN NON TUNNEL MODE) \n");
        DEBUG_PRINT( "TUNNEL = 1 (DECODED AAC SAMPLES IS PLAYED BACK)\n");
        DEBUG_PRINT( "TUNNEL = 0 (DECODED AAC SAMPLES IS LOOPED BACK TO THE USER APP)\n");
        DEBUG_PRINT( "FILEWRITE = 1 (ENABLES PCM FILEWRITE IN NON TUNNEL MODE) \n");
        DEBUG_PRINT( "FILEWRITE = 0 (DISABLES PCM FILEWRITE IN NON TUNNEL MODE) \n");
        DEBUG_PRINT( "SBR_PS_ENABLED = 0 (SBR AND PS DISABLED) \n");
        DEBUG_PRINT( "SBR_PS_ENABLED = 1 (SBR IS ENABLED) \n");
        DEBUG_PRINT( "SBR_PS_ENABLED = 2 (SBR AND PS ENABLED) \n");
        return 0;
    }

    if(tunnel == 0)
        aud_comp = "OMX.qcom.audio.decoder.aac";
    else
        aud_comp = "OMX.qcom.audio.decoder.tunneled.aac";

    printf("Init_Decoder()\n");
    if(Init_Decoder(aud_comp)!= 0x00)
    {
        DEBUG_PRINT("Decoder Init failed\n");
        return -1;
    }

    printf("Play_Decoder()\n");
    if(Play_Decoder() != 0x00)
    {
        DEBUG_PRINT("Play_Decoder failed\n");
        return -1;
    }
     printf("Play_Decoder() done\n");

    // Wait till EOS is reached...

   printf("************* before wait_for_event\n");
    wait_for_event();
   printf(" after wait_for_event bOutputEosReached %d tunnel %d bInputEosReached %d \n",bOutputEosReached,tunnel,bInputEosReached);
   if(bOutputEosReached || (tunnel && bInputEosReached)) {

        DEBUG_PRINT(" going to sleep \n");
       // sleep(15);
        DEBUG_PRINT(" wake up \n");
        /******************************************************************/
        #ifdef PCM_PLAYBACK
        if(pcmplayback == 1)
        {
            ioctl(m_pcmdrv_fd, AUDIO_STOP, 0);

            if(m_pcmdrv_fd >= 0) {
                close(m_pcmdrv_fd);
                m_pcmdrv_fd = -1;
                DEBUG_PRINT(" PCM device closed succesfully \n");
            }
            else
            {
                DEBUG_PRINT(" PCM device close failure \n");
            }
        }
        #endif // PCM_PLAYBACK

        if((tunnel == 0)&& (filewrite == 1))
        {
            hdr.riff_id = ID_RIFF;
            hdr.riff_sz = 0;
            hdr.riff_fmt = ID_WAVE;
            hdr.fmt_id = ID_FMT;
            hdr.fmt_sz = 16;
            hdr.audio_format = FORMAT_PCM;
            hdr.num_channels = channels;//2;
            hdr.sample_rate = samplerate; //SAMPLE_RATE;  //44100;
            hdr.byte_rate = hdr.sample_rate * hdr.num_channels * 2;
            hdr.block_align = hdr.num_channels * 2;
            hdr.bits_per_sample = 16;
            hdr.data_id = ID_DATA;
            hdr.data_sz = 0;

            DEBUG_PRINT("output file closed and EOS reached total decoded data length %d\n",totaldatalen);
            hdr.data_sz = totaldatalen;
            hdr.riff_sz = totaldatalen + 8 + 16 + 8;
            fseek(outputBufferFile, 0L , SEEK_SET);
            bytes_writen = fwrite(&hdr,1,sizeof(hdr),outputBufferFile);
            if (bytes_writen <= 0) {
                DEBUG_PRINT("Invalid Wav header write failed\n");
            }
            bFileclose = 1;
            fclose(outputBufferFile);
        }
        /************************************************************************************/
        DEBUG_PRINT("\nMoving the decoder to idle state \n");
        OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateIdle,0);
        wait_for_event();

        DEBUG_PRINT("\nMoving the decoder to loaded state \n");
        OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateLoaded,0);

        DEBUG_PRINT("\nFillBufferDone: Deallocating i/p buffers \n");
        for(bufCnt=0; bufCnt < input_buf_cnt; ++bufCnt) {
            OMX_FreeBuffer(aac_dec_handle, 0, pInputBufHdrs[bufCnt]);
        }

        if(tunnel == 0)
        {
            DEBUG_PRINT("\nFillBufferDone: Deallocating o/p buffers \n");
            for(bufCnt=0; bufCnt < output_buf_cnt; ++bufCnt) {
            OMX_FreeBuffer(aac_dec_handle, 1, pOutputBufHdrs[bufCnt]);
            }
        }


        ebd_cnt=0;
        bInputEosReached = false;
            wait_for_event();
            ebd_cnt=0;
        bOutputEosReached = false;
        result = OMX_FreeHandle(aac_dec_handle);
        if (result != OMX_ErrorNone) {
            DEBUG_PRINT ("\nOMX_FreeHandle error. Error code: %d\n", result);
        }
           aac_dec_handle = NULL;

        /* Deinit OpenMAX */

        OMX_Deinit();

        pthread_cond_destroy(&cond);
        pthread_mutex_destroy(&lock);
        DEBUG_PRINT("*****************************************\n");
        DEBUG_PRINT("******...TEST COMPLETED...***************\n");
        DEBUG_PRINT("*****************************************\n");
    }
    return 0;
}
コード例 #29
0
ファイル: video.c プロジェクト: drhastings/balance
void *video_decode_test(void* arg) {
    bcm_host_init();

		CUBE_STATE_T *state = (CUBE_STATE_T *)arg;

    OMX_ERRORTYPE r;

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

    // Init context
    appctx ctx;
    memset(&ctx, 0, sizeof(ctx));
    if(vcos_semaphore_create(&ctx.handler_lock, "handler_lock", 1) != VCOS_SUCCESS) {
        die("Failed to create handler lock semaphore");
    }

		ctx.eglImage = state->eglImage;

    // Init component handles
    OMX_CALLBACKTYPE callbacks;
    memset(&ctx, 0, sizeof(callbacks));
    callbacks.EventHandler = event_handler;
    callbacks.FillBufferDone = my_fill_buffer_done;

    init_component_handle("camera", &ctx.camera , &ctx, &callbacks);
    init_component_handle("egl_render", &ctx.render, &ctx, &callbacks);
    init_component_handle("null_sink", &ctx.null_sink, &ctx, &callbacks);
    init_component_handle("clock", &ctx.clock, &ctx, &callbacks);

    OMX_U32 screen_width = state->screen_width, screen_height = state->screen_height;
    if(graphics_get_display_size(DISPLAY_DEVICE, &screen_width, &screen_height) < 0) {
        die("Failed to get display size");
    }

    say("Configuring camera...");

    dump_port(ctx.clock, 80, OMX_TRUE);
    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);

		OMX_TIME_CONFIG_CLOCKSTATETYPE cstate;
		OMX_INIT_STRUCTURE(cstate);
		cstate.eState = OMX_TIME_ClockStateRunning;
		cstate.nWaitMask = 1;
    if((r = OMX_SetConfig(ctx.clock, OMX_IndexConfigTimeClockState, &cstate)) != OMX_ErrorNone) {
        omx_die(r, "Failed to request camera device number parameter change callback for camera");
    }

    // 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  = state->screen_width;
    camera_portdef.format.video.nFrameHeight = state->screen_height;
    camera_portdef.format.video.xFramerate   = VIDEO_FRAMERATE << 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 = CAM_BRIGHTNESS;
    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.bAutoShutterSpeed = OMX_TRUE;
//		exposure_value.nShutterSpeedMsec = 10;
    exposure_value.nSensitivity = CAM_EXPOSURE_ISO_SENSITIVITY;
		exposure_value.eMetering = OMX_MeteringModeAverage;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonExposureValue, &exposure_value)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera exposure value configuration");
    }
	  OMX_CONFIG_EXPOSURECONTROLTYPE exposure;
 	  OMX_INIT_STRUCTURE(exposure);
	  exposure.nPortIndex = OMX_ALL;
	  exposure.eExposureControl = OMX_ExposureControlAuto;
 	  OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonExposure, &exposure);
    // 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_LIGHTNESSTYPE lightness_control;
    OMX_INIT_STRUCTURE(lightness_control);
    lightness_control.nPortIndex = OMX_ALL;
    lightness_control.nLightness = 0;
    if((r = OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonLightness, &lightness_control)) != OMX_ErrorNone) {
        omx_die(r, "Failed to set camera frame white balance 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");
    }
  /* 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;
  OMX_SetConfig(ctx.camera, OMX_IndexConfigCommonColorEnhancement, &colour);

    // 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 render...");

    say("Default port definition for render input port 90");
    dump_port(ctx.render, 220, OMX_TRUE);

    // Render input port definition is done automatically upon tunneling


    say("Configuring null sink...");

    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.clock, 80, ctx.camera, 73)) != OMX_ErrorNone) {
        omx_die(r, "Failed to setup tunnel between camera preview output port 70 and null sink input port 240");
    }
    // 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 render input port
    say("Setting up tunnel from camera video output port 71 to render input port 220...");
    if((r = OMX_SetupTunnel(ctx.camera, 71, ctx.render, 220)) != OMX_ErrorNone) {
        omx_die(r, "Failed to setup tunnel between camera video output port 71 and render input port 90");
    }

    // Switch components to idle state
    say("Switching state of the camera component to idle...");
    if((r = OMX_SendCommand(ctx.clock, 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.clock, OMX_StateIdle);    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 render component to idle...");
    if((r = OMX_SendCommand(ctx.render, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the render component to idle");
    }
    block_until_state_changed(ctx.render, 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.clock, OMX_CommandPortEnable, 80, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable camera input port 73");
    }
    block_until_port_changed(ctx.clock, 80, OMX_TRUE);    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.render, OMX_CommandPortEnable, 220, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable render input port 220");
    }
    block_until_port_changed(ctx.render, 220, OMX_TRUE);
   if((r = OMX_SendCommand(ctx.render, OMX_CommandPortEnable, 221, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to enable render input port 221");
    }
    block_until_port_changed(ctx.render, 220, 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, buffers for tunneled
    // ports are allocated internally by OMX

		if((r = OMX_UseEGLImage(ctx.render, &ctx.eglBuffer, 221, NULL, ctx.eglImage)) != OMX_ErrorNone)
		{
        omx_die(r, "Failed to use eglimage");
		}

    // 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.clock, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the camera component to executing");
    }    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 render component to executing...");
    if((r = OMX_SendCommand(ctx.render, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the render component to executing");
    }
    block_until_state_changed(ctx.render, 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);

    // Start capturing video with the camera
    say("Switching on capture on camera video output port 71...");
    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 render input port 90");
    dump_port(ctx.render, 220, OMX_FALSE);
    say("Configured port definition for null sink input port 240");
    dump_port(ctx.null_sink, 240, OMX_FALSE);

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

		if((r = OMX_FillThisBuffer(ctx.render, ctx.eglBuffer)) != OMX_ErrorNone)
		{
      omx_die(r, "Failed to fill buffer");
		}

    signal(SIGINT,  signal_handler);
    signal(SIGTERM, signal_handler);
    signal(SIGQUIT, signal_handler);

    while(!want_quit) {
        // Would be better to use signaling here but hey this works too
        usleep(1000);
    }
    say("Cleaning up...");

    // Restore signal handlers
    signal(SIGINT,  SIG_DFL);
    signal(SIGTERM, SIG_DFL);
    signal(SIGQUIT, SIG_DFL);

    // Stop capturing video with the camera
    OMX_INIT_STRUCTURE(capture);
    capture.nPortIndex = 71;
    capture.bEnabled = OMX_FALSE;
    if((r = OMX_SetParameter(ctx.camera, OMX_IndexConfigPortCapturing, &capture)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch off capture on camera video output port 71");
    }

    // Flush the buffers on each component
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandFlush, 73, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to flush buffers of camera input port 73");
    }
    block_until_flushed(&ctx);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandFlush, 70, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to flush buffers of camera preview output port 70");
    }
    block_until_flushed(&ctx);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandFlush, 71, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to flush buffers of camera video output port 71");
    }
    block_until_flushed(&ctx);
    if((r = OMX_SendCommand(ctx.render, OMX_CommandFlush, 220, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to flush buffers of render input port 220");
    }
    block_until_flushed(&ctx);
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandFlush, 240, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to flush buffers of null sink input port 240");
    }
    block_until_flushed(&ctx);

    // Disable all the ports
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortDisable, 73, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable camera input port 73");
    }
    block_until_port_changed(ctx.camera, 73, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortDisable, 70, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable camera preview output port 70");
    }
    block_until_port_changed(ctx.camera, 70, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandPortDisable, 71, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable camera video output port 71");
    }
    block_until_port_changed(ctx.camera, 71, OMX_FALSE);
    if((r = OMX_SendCommand(ctx.render, OMX_CommandPortDisable, 220, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable render input port 90");
    }
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandPortDisable, 240, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to disable null sink input port 240");
    }
    block_until_port_changed(ctx.null_sink, 240, OMX_FALSE);

    // Free all the buffers
    if((r = OMX_FreeBuffer(ctx.camera, 73, ctx.camera_ppBuffer_in)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free buffer for camera input port 73");
    }

    // Transition all the components to idle and then to loaded states
    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);
    if((r = OMX_SendCommand(ctx.render, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the render component to idle");
    }
    block_until_state_changed(ctx.render, OMX_StateIdle);
    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);
    if((r = OMX_SendCommand(ctx.camera, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the camera component to loaded");
    }
    block_until_state_changed(ctx.camera, OMX_StateLoaded);
    if((r = OMX_SendCommand(ctx.render, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the render component to loaded");
    }
    block_until_state_changed(ctx.render, OMX_StateLoaded);
    if((r = OMX_SendCommand(ctx.null_sink, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
        omx_die(r, "Failed to switch state of the null sink component to loaded");
    }
    block_until_state_changed(ctx.null_sink, OMX_StateLoaded);

    // Free the component handles
    if((r = OMX_FreeHandle(ctx.camera)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free camera component handle");
    }
    if((r = OMX_FreeHandle(ctx.render)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free render component handle");
    }
    if((r = OMX_FreeHandle(ctx.null_sink)) != OMX_ErrorNone) {
        omx_die(r, "Failed to free null sink component handle");
    }

    // Exit
    vcos_semaphore_delete(&ctx.handler_lock);
    if((r = OMX_Deinit()) != OMX_ErrorNone) {
        omx_die(r, "OMX de-initalization failed");
    }

    say("Exit!");

    return 0;
}
コード例 #30
0
ファイル: video.c プロジェクト: 1ee7/rpi-firmware
static int video_decode_test(char *filename)
{
   OMX_VIDEO_PARAM_PORTFORMATTYPE format;
   OMX_TIME_CONFIG_CLOCKSTATETYPE cstate;
   COMPONENT_T *video_decode = NULL, *video_scheduler = NULL, *video_render = NULL, *clock = NULL;
   COMPONENT_T *list[5];
   TUNNEL_T tunnel[4];
   ILCLIENT_T *client;
   FILE *in;
   int status = 0;
   unsigned int data_len = 0;

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

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

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

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

   // 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)
      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+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;

         data_len += fread(dest, 1, buf->nAllocLen-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;
            }

            ilclient_change_component_state(video_render, OMX_StateExecuting);
         }
         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);

   }

   fclose(in);

   ilclient_disable_tunnel(tunnel);
   ilclient_disable_tunnel(tunnel+1);
   ilclient_disable_tunnel(tunnel+2);
   ilclient_disable_port_buffers(video_decode, 130, NULL, NULL, NULL);
   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 status;
}