Esempio n. 1
0
int32_t ilctts_delete(TTSRENDER_STATE_T *st) {
	int32_t ret;
	OMX_ERRORTYPE omx_err;

	ret = ilclient_change_component_state(st->audio_render, OMX_StateIdle);
	if (ret < 0) {
		ERROR("ilctts_change_component_state returned error in ilctts_delete: %d", ret);
		return -1;
	}

	omx_err = OMX_SendCommand(ILC_GET_HANDLE(st->audio_render), OMX_CommandStateSet, OMX_StateLoaded, NULL);
	if (omx_err != OMX_ErrorNone) {
		ERROR("OMX_SendCommand returned error in ilctts_delete: %d", omx_err);
		return -1;
	}


	ilclient_disable_port_buffers(st->audio_render, 100, st->user_buffer_list, NULL, NULL);
	ilclient_change_component_state(st->audio_render, OMX_StateLoaded);
	ilclient_cleanup_components(st->list);

	ilclient_destroy(st->client);
	//sem_destroy(&st->buffer_list_sema);
	destroy_semaphores(st);
	destroy_mutexes(st);
	free(st);
	return 0;
} // end ilctts_delete
Esempio n. 2
0
static void omx_renderer_cleanup() {
  if (decoder != NULL)
    opus_multistream_decoder_destroy(decoder);
  if (handle != NULL) {
    if((buf = ilclient_get_input_buffer(component, 100, 1)) == NULL){
      fprintf(stderr, "Can't get audio buffer\n");
      exit(EXIT_FAILURE);
    }

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

    if(OMX_EmptyThisBuffer(ILC_GET_HANDLE(component), buf) != OMX_ErrorNone){
      fprintf(stderr, "Can't empty audio buffer\n");
      return;
    }

    ilclient_disable_port_buffers(component, 100, NULL, NULL, NULL);
    ilclient_change_component_state(component, OMX_StateIdle);
    ilclient_change_component_state(component, OMX_StateLoaded);
  }
}
Esempio n. 3
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;
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
int main(int argc, char **argv)
{

    int i;
    char *decodeComponentName;
    char *renderComponentName;
    int err;
    ILCLIENT_T *handle;
    COMPONENT_T *decodeComponent;
    COMPONENT_T *renderComponent;
    COMPONENT_T *fxComponent;
    int do_deinterlace = 0;

    if (argc >= 2)
    {
        IMG = argv[1];
    }
    if (argc >= 3)
    {
        if (strcmp(argv[2],"d")==0)
            do_deinterlace = 1;
    }

    FILE *fp = fopen(IMG, "r");
    int toread = get_file_size(IMG);
    OMX_BUFFERHEADERTYPE *buff_header;

    decodeComponentName = "video_decode";
    renderComponentName = "video_render";

    bcm_host_init();

    handle = ilclient_init();
    if (handle == NULL)
    {
        fprintf(stderr, "IL client init failed\n");
        exit(1);
    }

    if (OMX_Init() != OMX_ErrorNone)
    {
        ilclient_destroy(handle);
        fprintf(stderr, "OMX init failed\n");
        exit(1);
    }

    ilclient_set_error_callback(handle,
                                error_callback,
                                NULL);
    ilclient_set_eos_callback(handle,
                              eos_callback,
                              NULL);

    setup_decodeComponent(handle, decodeComponentName, &decodeComponent);
    setup_renderComponent(handle, renderComponentName, &renderComponent);
    if (do_deinterlace)
        setup_fxComponent(handle, "image_fx", &fxComponent);
    // both components now in Idle state, no buffers, ports disabled

    // input port
    ilclient_enable_port_buffers(decodeComponent, 130,
                                 NULL, NULL, NULL);
    ilclient_enable_port(decodeComponent, 130);

    err = ilclient_change_component_state(decodeComponent,
                                          OMX_StateExecuting);
    if (err < 0)
    {
        fprintf(stderr, "Couldn't change state to Executing\n");
        exit(1);
    }
    printState(ilclient_get_handle(decodeComponent));

    // Read the first block so that the decodeComponent can get
    // the dimensions of the video and call port settings
    // changed on the output port to configure it
    while (toread > 0)
    {
        buff_header =
            ilclient_get_input_buffer(decodeComponent,
                                      130,
                                      1 /* block */);
        if (buff_header != NULL)
        {
            read_into_buffer_and_empty(fp,
                                       decodeComponent,
                                       buff_header,
                                       &toread);

            // If all the file has been read in, then
            // we have to re-read this first block.
            // Broadcom bug?
            if (toread <= 0)
            {
                printf("Rewinding\n");
                // wind back to start and repeat
                fp = freopen(IMG, "r", fp);
                toread = get_file_size(IMG);
            }
        }

        if (toread > 0 && ilclient_remove_event(decodeComponent, OMX_EventPortSettingsChanged, 131, 0, 0, 1) == 0)
        {
            printf("Removed port settings event\n");
            break;
        }
        else
        {
            printf("No port setting seen yet\n");
        }
        // wait for first input block to set params for output port
        if (toread == 0)
        {
            // wait for first input block to set params for output port
            err = ilclient_wait_for_event(decodeComponent,
                                          OMX_EventPortSettingsChanged,
                                          131, 0, 0, 1,
                                          ILCLIENT_EVENT_ERROR | ILCLIENT_PARAMETER_CHANGED,
                                          2000);
            if (err < 0)
            {
                fprintf(stderr, "No port settings change\n");
                //exit(1);
            }
            else
            {
                printf("Port settings changed\n");
                break;
            }
        }
    }

    // set the decode component to idle and disable its ports
    err = ilclient_change_component_state(decodeComponent,
                                          OMX_StateIdle);
    if (err < 0)
    {
        fprintf(stderr, "Couldn't change state to Idle\n");
        exit(1);
    }
    ilclient_disable_port(decodeComponent, 131);
    ilclient_disable_port_buffers(decodeComponent, 131,
                                  NULL, NULL, NULL);

    if (do_deinterlace)
    {
        // set up the tunnel between decode and fx ports
        err = OMX_SetupTunnel(ilclient_get_handle(decodeComponent),
                            131,
                            ilclient_get_handle(fxComponent),
                            190);
        if (err != OMX_ErrorNone)
        {
            fprintf(stderr, "Error setting up tunnel 1 %X\n", err);
            exit(1);
        }
        else
        {
            printf("Tunnel 1 set up ok\n");
        }

        // set up the tunnel between fx and render ports
        err = OMX_SetupTunnel(ilclient_get_handle(fxComponent),
                            191,
                            ilclient_get_handle(renderComponent),
                            90);
        if (err != OMX_ErrorNone)
        {
            fprintf(stderr, "Error setting up tunnel 2 %X\n", err);
            exit(1);
        }
        else
        {
            printf("Tunnel 2 set up ok\n");
        }
    }
    else
    {
        // set up the tunnel between decode and render ports
        err = OMX_SetupTunnel(ilclient_get_handle(decodeComponent),
                            131,
                            ilclient_get_handle(renderComponent),
                            90);
        if (err != OMX_ErrorNone)
        {
            fprintf(stderr, "Error setting up tunnel %X\n", err);
        exit(1);
        }
        else
        {
            printf("Tunnel set up ok\n");
        }
    }
    // Okay to go back to processing data
    // enable the decode output ports

//UNNECESSARY?? PGB    OMX_SendCommand(ilclient_get_handle(decodeComponent),
//UNNECESSARY?? PGB                    OMX_CommandPortEnable, 131, NULL);

    ilclient_enable_port(decodeComponent, 131);

    if (do_deinterlace)
    {
        setup_shared_buffer_format(decodeComponent, 131, fxComponent, 191);
        // enable fx ports
        ilclient_enable_port(fxComponent, 190);
        ilclient_enable_port(fxComponent, 191);

//UNNECESSARY?? PGB    OMX_SendCommand(ilclient_get_handle(renderComponent),
//UNNECESSARY?? PGB                    OMX_CommandPortEnable, 90, NULL);

        // setup_shared_buffer_format(fxComponent, renderComponent);
    }
    // enable the render output ports
    ilclient_enable_port(renderComponent, 90);

    // set all components to executing state
    err = ilclient_change_component_state(decodeComponent,
                                          OMX_StateExecuting);
    if (err < 0)
    {
        fprintf(stderr, "Couldn't change decode to Executing\n");
        exit(1);
    }
    if (do_deinterlace)
    {
        err = ilclient_change_component_state(fxComponent,
                                            OMX_StateExecuting);
        if (err < 0)
        {
            fprintf(stderr, "Couldn't change fx to Executing\n");
            exit(1);
        }
    }
    err = ilclient_change_component_state(renderComponent,
                                          OMX_StateExecuting);
    if (err < 0)
    {
        fprintf(stderr, "Couldn't change render to Executing\n");
        exit(1);
    }

    print_port_info(ilclient_get_handle(decodeComponent), 131);
    if (do_deinterlace)
    {
        print_port_info(ilclient_get_handle(fxComponent), 190);
        print_port_info(ilclient_get_handle(fxComponent), 191);
    }
    print_port_info(ilclient_get_handle(renderComponent), 90);

    // now work through the file
    while (toread > 0)
    {
        OMX_ERRORTYPE r;

        // do we have a decode input buffer we can fill and empty?
        buff_header =
            ilclient_get_input_buffer(decodeComponent,
                                      130,
                                      1 /* block */);
        if (buff_header != NULL)
        {
            read_into_buffer_and_empty(fp,
                                       decodeComponent,
                                       buff_header,
                                       &toread);
        }
        usleep(100000);
        // print_port_info(ilclient_get_handle(renderComponent), 90);
    }


    ilclient_wait_for_event(renderComponent,
                            OMX_EventBufferFlag,
                            90, 0, OMX_BUFFERFLAG_EOS, 0,
                            ILCLIENT_BUFFER_FLAG_EOS, 10000);
    printf("EOS on render\n");

    sleep(100);

    exit(0);
}
Esempio n. 6
0
static int image_decode_test(char *filename)
{

     OMX_BUFFERHEADERTYPE *pIbuf;
     int bytes_read;
     int status = 0, ret;
     int port_settings_changed = 0;

     OMX_IMAGE_PARAM_PORTFORMATTYPE imagePortFormat;
     COMPONENT_T *image_decode = NULL;
     COMPONENT_T *video_render = NULL;
     COMPONENT_T *list[3];
     TUNNEL_T tunnel[2];
     ILCLIENT_T *client;
     FILE *fin;

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

     if((fin = fopen(filename, "rb")) == NULL ) {
	  perror(filename);
	  return -1;
     }

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

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

#if 0 //this was an attempt to use the image_read component
     COMPONENT_T *image_read;
     // create image_read
     if(ilclient_create_component(client, &image_read, "image_read",
				  ILCLIENT_DISABLE_ALL_PORTS ) != 0)
	  status = -14;


     //set URI
     OMX_PARAM_CONTENTURITYPE *pUri;
     sz = sizeof(pUri)+strlen(filename);
     pUri = (OMX_PARAM_CONTENTURITYPE*)calloc(1, sz);
     pUri->nSize = sz;
     pUri->nVersion.nVersion = OMX_VERSION;
     strcpy(pUri->contentURI, filename);
     if(image_read != NULL && OMX_SetParameter(ILC_GET_HANDLE(image_read), OMX_IndexParamContentURI, pUri) != 0)
	  status = -17;

     //enable port
     ilclient_enable_port(image_read, 310);

     //get OMX_IndexParamPortDefinition
     {
	  OMX_PARAM_PORTDEFINITIONTYPE portDef;
	  portDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
	  portDef.nVersion.nVersion = OMX_VERSION;
	  portDef.nPortIndex = 310;
	  ret = OMX_GetParameter(ILC_GET_HANDLE(image_read), OMX_IndexParamPortDefinition, &portDef);
     }

     //get OMX_IndexParamImagePortFormat
     i=0;
     while(ret == 0) {
	  OMX_IMAGE_PARAM_PORTFORMATTYPE portFormat;
	  portFormat.nSize = sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE);
	  portFormat.nVersion.nVersion = OMX_VERSION;
	  portFormat.nPortIndex = 310;
	  portFormat.nIndex = i;
	  ret = OMX_GetParameter(ILC_GET_HANDLE(image_read), OMX_IndexParamImagePortFormat, &portFormat);
	  i++;
     }

     {
	  OMX_IMAGE_PARAM_PORTFORMATTYPE portFormat;
	  portFormat.nSize = sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE);
	  portFormat.nVersion.nVersion = OMX_VERSION;
	  portFormat.nPortIndex = 310;
	  portFormat.eCompressionFormat = OMX_IMAGE_CodingJPEG;

	  ret = OMX_SetParameter(ILC_GET_HANDLE(image_read), OMX_IndexParamImagePortFormat, &portFormat);
     }

     if((ret = ilclient_change_component_state(image_read, OMX_StateIdle) < 0)) //this fails
	  printf("Cannot change image_read component state to OMX_StateIdle\n"); 

#endif //image_read attempt


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

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

     ret = ilclient_change_component_state(image_decode, OMX_StateIdle);

     set_tunnel(tunnel, image_decode, 321, video_render, 90);

#if 0 //not necessary
     {
	  //get OMX_IndexParamPortDefinition
	  OMX_PARAM_PORTDEFINITIONTYPE portDef;
	  portDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
	  portDef.nVersion.nVersion = OMX_VERSION;
	  portDef.nPortIndex = 320;
	  ret = OMX_GetParameter(ILC_GET_HANDLE(image_decode), OMX_IndexParamPortDefinition, &portDef);
     }
#endif

     {
	  // OMX_IndexParamImagePortFormat
	  imagePortFormat.nSize = sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE);
	  imagePortFormat.nVersion.nVersion = OMX_VERSION;
	  imagePortFormat.nPortIndex = 320;
	  imagePortFormat.eCompressionFormat = OMX_IMAGE_CodingJPEG;
//	  imagePortFormat.eCompressionFormat = OMX_IMAGE_CodingPNG; //does not seem to work
//	  imagePortFormat.eCompressionFormat = OMX_IMAGE_CodingAutoDetect; //does not seem to work.

	  ret = OMX_SetParameter(ILC_GET_HANDLE(image_decode), OMX_IndexParamImagePortFormat, &imagePortFormat);
     }

     ret = ilclient_enable_port_buffers(image_decode, 320, NULL, NULL, NULL);

     ret = ilclient_change_component_state(image_decode, OMX_StateExecuting);

     while( (pIbuf = ilclient_get_input_buffer(image_decode, 320, 1)) != NULL ) {
	  bytes_read = fread(pIbuf->pBuffer, 1, pIbuf->nAllocLen, fin);

	  if( port_settings_changed == 0 &&
	      (( bytes_read > 0 && ilclient_remove_event(image_decode, OMX_EventPortSettingsChanged, 321, 0, 0, 1) == 0) ||
	       ( bytes_read == 0 && ilclient_wait_for_event(image_decode, OMX_EventPortSettingsChanged, 321, 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_render, OMX_StateExecuting);

	  }

	  if(!bytes_read)
	       break;
	       
	  pIbuf->nFilledLen = bytes_read;
	  pIbuf->nOffset = 0;
	  pIbuf->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN;

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

     pIbuf->nFilledLen = 0;
     pIbuf->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN | OMX_BUFFERFLAG_EOS;
      
     if(OMX_EmptyThisBuffer(ILC_GET_HANDLE(image_decode), pIbuf) != 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);
      

     printf("Press ENTER to continue...\n");
     fflush(stdout);
     getchar();

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

     ilclient_disable_port_buffers(image_decode, 320, NULL, NULL, NULL);

     fclose(fin);

     ilclient_disable_tunnel(tunnel);
     ilclient_teardown_tunnels(tunnel);

      
     ret = ilclient_change_component_state(image_decode, OMX_StateIdle);
     ret = ilclient_change_component_state(image_decode, OMX_StateLoaded);
     
     ilclient_cleanup_components(list);
     OMX_Deinit();
     ilclient_destroy(client);
     return status;
}
Esempio n. 7
0
// Modified function prototype to work with pthreads
void *video_decode_test(void* arg)
{
    pthread_mutex_init(&m_lock, NULL);
    printf("OMX version : %d.%d.%d-%d\n",OMX_VERSION_MAJOR, OMX_VERSION_MINOR, OMX_VERSION_REVISION, OMX_VERSION_STEP);

   printf("file to read : %s\n", filename);
   
   eglImage = arg;

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

   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, &omx_clock, "clock", ILCLIENT_DISABLE_ALL_PORTS) != 0)
      status = -14;
   list[2] = omx_clock;

    memset(&cstate, 0, sizeof(cstate));
    cstate.nSize = sizeof(cstate);
    cstate.nVersion.nVersion = OMX_VERSION;
    cstate.eState = OMX_TIME_ClockStateWaitingForStartTime;
    cstate.nWaitMask = 1;
    if(omx_clock != NULL && OMX_SetParameter(ILC_GET_HANDLE(omx_clock), OMX_IndexConfigTimeClockState, &cstate) != OMX_ErrorNone)
      status = -13;
      
    // set the clock refenrece to "none"
    memset(&cref,0,sizeof(cref));
    cref.nSize = sizeof(cref);
    cref.nVersion.nVersion = OMX_VERSION;
    cref.eClock = OMX_TIME_RefClockNone;

    if(omx_clock != NULL && OMX_SetParameter(ILC_GET_HANDLE(omx_clock), OMX_IndexConfigTimeActiveRefClock, &cref) != OMX_ErrorNone){
      status = -13;
      printf("error setting refclock\n");
  }
    

   // 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, omx_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(omx_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 && stop_flag==0 )
      {
         // 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;
         }
      }
      printf("loop ends, now flush the buffer\n");
      
        OMX_SendCommand(ILC_GET_HANDLE(video_decode),OMX_CommandFlush,130,NULL);
        OMX_SendCommand(ILC_GET_HANDLE(video_decode),OMX_CommandFlush,131,NULL);
      
        ilclient_wait_for_event(video_decode, OMX_EventCmdComplete, OMX_CommandFlush, 0, 130, 0, ILCLIENT_PORT_FLUSH, -1);
        ilclient_wait_for_event(video_decode, OMX_EventCmdComplete, OMX_CommandFlush, 0, 131, 0, ILCLIENT_PORT_FLUSH, -1);
        
        data_len=0;        
           
        memset(&cstate, 0, sizeof(cstate));
        cstate.nSize = sizeof(cstate);
        cstate.nVersion.nVersion = OMX_VERSION;
        cstate.eState = OMX_TIME_ClockStateStopped;
        cstate.nWaitMask = 1;
        OMX_SetParameter(ILC_GET_HANDLE(omx_clock), OMX_IndexConfigTimeClockState, &cstate);
                  
        memset(&cstate, 0, sizeof(cstate));
        cstate.nSize = sizeof(cstate);
        cstate.nVersion.nVersion = OMX_VERSION;
        cstate.eState = OMX_TIME_ClockStateWaitingForStartTime;
        cstate.nWaitMask = 1;
        OMX_SetParameter(ILC_GET_HANDLE(omx_clock), OMX_IndexConfigTimeClockState, &cstate);
        
        //~ scheduler should be stopped...

      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
      //~ printf("wait for EOS from render\n");
      //~ ilclient_wait_for_event(video_render, OMX_EventBufferFlag, 90, 0, OMX_BUFFERFLAG_EOS, 0,
                              //~ ILCLIENT_BUFFER_FLAG_EOS, 10000);
        while ((ilclient_remove_event(video_render, OMX_EventBufferFlag, 90, 0, OMX_BUFFERFLAG_EOS, 0) <0 ) && !stop_flag){
       }

        printf("flush the render\n");
      // 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);
   }
    printf("close file\n");
   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);
   printf("thread will return...\n");
   
   pthread_mutex_destroy(&m_lock);
   return (void *)status;
}
Esempio n. 8
0
void encode_deactivate(COMPONENT_T* handle)
{
	fprintf(stderr, "disabling port buffers for 200 and 201...\n");
	ilclient_disable_port_buffers(handle, 200, NULL, NULL, NULL);
	ilclient_disable_port_buffers(handle, 201, NULL, NULL, NULL);
}