Exemplo n.º 1
0
void
cmdline_mode(int argc,
	     char *argv[]) {

  int p, t;

  AppData *appdata = g_new(AppData, 1);
  appdata->runmode = CMDLINE;
  appdata->playlist = playlist_new();
  appdata->decoder = decoder_new();
  appdata->stream = NULL;


  /* setup callbacks */
  playlist_set_play_cb(appdata->playlist, play_cb, (void *) appdata);
  playlist_next(appdata->playlist);

  while (TRUE) {
    if (decoder_is_playing(appdata->decoder)) {
      
      p = decoder_get_position(appdata->decoder);
      t = decoder_get_total(appdata->decoder);
      printf("%s: %d / %d\n", appdata->decoder->tag_title, p, t);

    } else if (decoder_has_finished(appdata->decoder)) {

      playlist_next(appdata->playlist);
    }

    usleep(500);
  }

}
Exemplo n.º 2
0
/* callback for updating status information */
static int
status_cb(AppData *appdata) {

  int p, t;

  if (! appdata->stream) {

    return TRUE;

  }
  
  else if (decoder_is_playing(appdata->decoder)) {

    p = decoder_get_position(appdata->decoder);
    t = decoder_get_total(appdata->decoder);
    gui_set_time(appdata->gui, p, t);

  } else if (decoder_has_finished(appdata->decoder)) {

    playlist_next(appdata->playlist);

  }

  return TRUE;

}
void eos_callback(void *data)
{
    fsl_player_bool brepeated = FSL_PLAYER_FALSE;
    fsl_player_handle player_handle = (fsl_player_handle)data;
    fsl_player* pplayer = (fsl_player*)player_handle;

    if( NULL == data )
    {
        return;
    }

    pplayer->klass->stop(pplayer);
    switch( opt->repeat )
    {
        case FSL_PLAYER_REPEAT_NONE:
        {
            break;
        }
        case FSL_PLAYER_REPEAT_PLAYLIST:
        {
            playlist_next(pplayer, opt);
            break;
        }
        case FSL_PLAYER_REPEAT_CURRENT:
        {
            pplayer->klass->play(pplayer);
            break;
        }
        default:
        {
            break;
        }
    }
    return;
}
Exemplo n.º 4
0
int main()
{
	kr_mkv_t *mkv_output;
	kr_mkv_t *mkv_input;
	kr_mkv_t *settings;

	krad_system_init();
//	krad_system_log_on("derp.log");
	playlist_t *playlist = playlist_init("test.txt");

	mkv_output = kr_mkv_create_stream(argv[1], atoi(argv[2]), argv[3], argv[4]);

	if(splice_init(settings, mkv_output, playlist) < 0)
	{
		perror("splice_init");
	}

	printf("resolution: %d x %d\n", mkv_output->tracks[VIDEO_TRACK].width,
					mkv_output->tracks[VIDEO_TRACK].height);

	uint32_t i;
	while(1)
	{
		playlist->current_entry = 0;
		for(i = 0; i < playlist_count(playlist); i++)
		{
			if(playlist_current_video(playlist) > 0)
			{
				printf("playing: %s\n", playlist_current_video(playlist));
				mkv_input = kr_mkv_open_file(playlist_current_video(playlist));

				if(!mkv_input)
				{
					perror(playlist_current_video(playlist));
				}

				splice(mkv_input, mkv_output);

				kr_mkv_destroy(&mkv_input);
				playlist_next(playlist);
			}
		}
	}

	kr_mkv_destroy(&mkv_output);
	playlist_destroy(playlist);

	return(0);
}
Exemplo n.º 5
0
/* callback for control buttons */
static void
control_cb(AppData *appdata,
	   int command) {

  switch (command) {
  case (PLAY):
    if (decoder_is_playing(appdata->decoder)) {
      decoder_stop(appdata->decoder);
      gui_set_paused(appdata->gui, TRUE);
    } else {
      decoder_play(appdata->decoder);
      gui_set_paused(appdata->gui, FALSE);
    }
    break;

  case (STOP):
    decoder_stop(appdata->decoder);
    decoder_seek(appdata->decoder, 0);
    appdata->current_position = decoder_get_position(appdata->decoder);
    gui_set_time(appdata->gui, 0, decoder_get_total(appdata->decoder));
    gui_set_paused(appdata->gui, FALSE);
    break;

  case (PREVIOUS):
    playlist_previous(appdata->playlist);
    break;

  case (NEXT):
    decoder_stop(appdata->decoder);
    playlist_next(appdata->playlist);
    break;

  case (CLEAR):
    playlist_clear(appdata->playlist);

  default:
    break;
  }

}
Exemplo n.º 6
0
/**
 * The player has stopped for some reason.  Check the error, and
 * decide whether to re-start playback
 */
static void
playlist_resume_playback(struct playlist *playlist, struct player_control *pc)
{
	enum player_error error;

	assert(playlist->playing);
	assert(pc_get_state(pc) == PLAYER_STATE_STOP);

	error = pc_get_error_type(pc);
	if (error == PLAYER_ERROR_NONE)
		playlist->error_count = 0;
	else
		++playlist->error_count;

	if ((playlist->stop_on_error && error != PLAYER_ERROR_NONE) ||
	    error == PLAYER_ERROR_OUTPUT ||
	    playlist->error_count >= queue_length(&playlist->queue))
		/* too many errors, or critical error: stop
		   playback */
		playlist_stop(playlist, pc);
	else
		/* continue playback at the next song */
		playlist_next(playlist, pc);
}
Exemplo n.º 7
0
void on_next_activate(GtkAction * action, gpointer user_data)
{
    playlist_next(get_playlist(app));
}
int main(int argc,char *argv[])
{
    fsl_player_s8 sCommand[128];
    fsl_player_s8 uri_buffer[500];
    fsl_player_thread_t display_thread;
    fsl_player_thread_t msg_thread;
    fsl_player_ret_val ret_val = FSL_PLAYER_SUCCESS;
    fsl_player_handle player_handle = NULL;
    fsl_player* pplayer = NULL;
    fsl_player_drm_format drm_format;
    fsl_player_config config;
    fsl_player_s32 ret;
    fsl_player_s32 volume = 1;

    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);
    signal(SIGABRT, signal_handler);
    signal(SIGILL,  signal_handler);
    signal(SIGFPE,  signal_handler);
    signal(SIGSEGV, signal_handler);

    if( argc < 2 ) {
        printf("Usage of command line player:\n");
        printf("    %s file_list\n", argv[0]);
        goto bail;
    }
        /* Initialisation */
    gst_init (&argc, &argv);

    // Default playbin.
    memset(&config, 0, sizeof(fsl_player_config));
    config.playbin_version = 2;
    config.api_version = GPLAYCORE_API_VERSION;
    config.features = (GPLAYCORE_FEATURE_AUTO_BUFFERING|GPLAYCORE_FEATURE_AUTO_REDIRECT_URI);
    config.timeout_second = GPLAYCORE_DEFAULT_TIMEOUT_SECOND;
    
    opt->info_interval_in_sec = 1;

    ret = parse_options(&config, opt, argc, argv);
    if( ret )
    {
        return -1;
    }

    fsl_player_element_property property[1];

    property[0].type = ELEMENT_TYPE_PLAYBIN;
    property[0].property_type = ELEMENT_PROPERTY_TYPE_INT;
    property[0].property_name = "flags";
    if (opt->enable_visual){
      property[0].value_int = 0x7f; /* default+native_video+buffering+visual */
    }else{
      property[0].value_int = 0x77; /* default+native_video+buffering */
    }
    property[0].next = NULL;
    config.ele_properties = property;

    if ((config.playbin_version==1)&&(config.video_sink_name==NULL)){
        config.video_sink_name = "autovideosink";
    }
    char *p;
    p = strrchr(opt->current->name, '.');
    PRINT("p=%s\n",p);	
    if(p&&!strncmp(p,".wav",4)){
	
        player_handle = fsl_player_initwav(&config,opt->current->name);
    }
    else 	
    player_handle = fsl_player_init(&config);
    if( NULL == player_handle )
    {
        PRINT("Failed: player_handle == NULL returned by fsl_player_init().\n");
        goto bail;
    }

    pplayer = (fsl_player*)player_handle;
    g_pplayer = pplayer;

    if (opt->info_interval_in_sec){
        FSL_PLAYER_CREATE_THREAD( &display_thread, display_thread_fun, player_handle );
    }
    FSL_PLAYER_CREATE_THREAD( &msg_thread, msg_thread_fun, player_handle );

    // Play the multimedia file directory after starting command line player.

    pplayer->klass->set_media_location(pplayer, opt->current->name, &drm_format);
    pplayer->klass->play(pplayer);

    // Print the help menu to let user know the operation.
    print_help(player_handle);

    kb_set_raw_term(STDIN_FILENO);

    while( FSL_PLAYER_FALSE == gbexit_main )
    {
        sCommand[0] = ' ';
        errno = 0;
        scanf("%s", sCommand);
        //read(STDIN_FILENO, sCommand, 1);
        if( EINTR == errno )
        {
            //printf("Timed out: EINTR == %d", errno);
        }
        switch( sCommand[0] )
        {
            case 'h': // display the operation Help.
                print_help(player_handle);
                break;

            case 'p': // Play.
             
                fsl_player_set_media_location(player_handle, filename2uri(uri_buffer,argv[1]), &drm_format);
                //pplayer->klass->set_media_location(pplayer, opt->current->name, &drm_format);
                pplayer->klass->play(pplayer);
                break;

            case 's': // Stop.
                pplayer->klass->stop(pplayer);
                break;

            case 'a': // pAuse when playing, play when paused.
                pplayer->klass->pause(pplayer);
                break;

            case 'e': // sEek.
            {
            #if 0
                fsl_player_u32 seek_point_sec = 0;
                fsl_player_u64 duration_ns = 0;
                fsl_player_u32 duration_sec = 0;
                pplayer->klass->get_property(pplayer, FSL_PLAYER_PROPERTY_DURATION, (void*)(&duration_ns));
                duration_sec = duration_ns / 1000000000;
                PRINT("Set seek point between [0,%u] seconds:", duration_sec);
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%s",sCommand);
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                seek_point_sec = atoi(sCommand);
                if( seek_point_sec<0 || seek_point_sec>duration_sec  )
                {
                    printf("Invalid seek point!\n");
                    break;
                }
                pplayer->klass->seek(pplayer, seek_point_sec*1000);
                break;
            #else
                fsl_player_u32 seek_point_sec = 0;
                fsl_player_u64 duration_ns = 0;
                fsl_player_u32 duration_sec = 0;
                fsl_player_u32 seek_portion = 0;
                fsl_player_u32 seek_mode = 0;
                fsl_player_u32 flags = 0;
                pplayer->klass->get_property(pplayer, FSL_PLAYER_PROPERTY_DURATION, (void*)(&duration_ns));
                duration_sec = duration_ns / 1000000000;
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                PRINT("Select seek mode[Fast seek:0,Accurate seek:1]:");
                scanf("%s",sCommand);
                seek_mode = atoi(sCommand);
                if( seek_mode<0 || seek_mode>1  )
                {
                    printf("Invalid seek mode!\n");
                    break;
                }else{
                    if (seek_mode){
                        flags |= FSL_PLAYER_FLAG_SEEK_ACCURATE;
                    }
                }
                PRINT("%s seek to percentage[0:100] or second [t?]:", seek_mode?"Accurate":"Normal");
                scanf("%s",sCommand);
                if (sCommand[0]=='t'){
                    seek_point_sec = atoi(&sCommand[1]);
                }else{
                    seek_portion = atoi(sCommand);
                    
                    if( seek_portion<0 || seek_portion>100  )
                    {
                        printf("Invalid seek point!\n");
                        break;
                    }
                    seek_point_sec = (fsl_player_u32)(seek_portion * duration_sec / 100);
                }
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                
                pplayer->klass->seek(pplayer, seek_point_sec*1000, flags);
                break;
            #endif
            }

            case 'v': // Volume
            {
                double volume;
                PRINT("Set volume[0-1.0]:");
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%lf",&volume);
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                pplayer->klass->set_volume(pplayer, (volume));
                break;
            }

            case 'm': // Switch to mute or not
                pplayer->klass->mute(pplayer);
                break;

            case '>': // Play next file
                printf("next\n");
                if (playlist_next(pplayer, opt)==NULL){
                    player_exit(pplayer);
                }
                break;

            case '<': // Play previous file
                printf("previous\n");
                playlist_previous(pplayer, opt);
                break;

            case 'r': // Switch to repeated mode or not
            {
                fsl_player_s32 repeated_mode;
                PRINT("input repeated mode[0 for no repeated,1 for play list repeated,2 for current file repeated]:");
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%d",&repeated_mode);
                if( repeated_mode<0 || repeated_mode>2  )
                {
                    printf("Invalid repeated mode!\n");
                }
                else
                {
                    opt->repeat = repeated_mode;
                }
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                //pplayer->klass->repeat(pplayer);
                break;
            }
#if 1
            case 'n': // Get the current video snapshot while playing
                //pplayer->klass->snapshot(pplayer);
                break;

            case 'o': // Set video output mode(LCD,NTSC,PAL,LCD&NTSC,LCD&PAL)
            {
                fsl_player_s32 mode = 0;
                PRINT("Set video output mode(LCD:0,NTSC:1,PAL:2,LCD&NTSC:3,LCD&PAL:4):");
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%d",&mode);
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                if( mode < 0 || mode >4 )
                {
                    printf("Invalid video output mode!\n");
                    break;
                }
                pplayer->klass->set_video_output(pplayer, mode);
                break;
            }

            case 'd': // Select the audio track
            {
                #if 1
                fsl_player_s32 audio_track_no = 0;
                fsl_player_s32 total_audio_no = 0;
                pplayer->klass->get_property(pplayer, FSL_PLAYER_PROPERTY_TOTAL_AUDIO_NO, (void*)(&total_audio_no));
                PRINT("input audio track number[0,%d]:",total_audio_no-1);
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%d",&audio_track_no);
                if( audio_track_no < 0 || audio_track_no > total_audio_no-1 )
                {
                    printf("Invalid audio track!\n");
                }
                else
                {
                    pplayer->klass->select_audio_track(pplayer, audio_track_no);
                }
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                #endif
                break;
            }

            case 'b': // Select the subtitle
            {
                #if 1
                fsl_player_s32 subtitle_no = 0;
                fsl_player_s32 total_subtitle_no = 0;
                pplayer->klass->get_property(pplayer, FSL_PLAYER_PROPERTY_TOTAL_SUBTITLE_NO, (void*)(&total_subtitle_no));
                PRINT("input subtitle number[0,%d]:",total_subtitle_no-1);
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%d",&subtitle_no);
                if( subtitle_no < 0 || subtitle_no > total_subtitle_no-1 )
                {
                    printf("Invalid audio track!\n");
                }
                else
                {
                    pplayer->klass->select_subtitle(pplayer, subtitle_no);
                }
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                #endif
                break;
            }
#endif
            case 'f': // Set full screen or not
                pplayer->klass->full_screen(pplayer);
                break;

            case 'y': // Set display screen mode
            {
                fsl_player_s32 display_screen_mode = 0;
                PRINT("Input screen mode[Normal:0,FullScreen:1,Zoom:2]:");
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%d",&display_screen_mode);
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                if( display_screen_mode < 0 || display_screen_mode > 2 )
                {
                    printf("Invalid display screen mode!\n");
                    break;
                }
                pplayer->klass->display_screen_mode(pplayer, display_screen_mode);
                break;
            }

            case 'z': // resize the width and height
            {
            #if 0
                fsl_player_display_parameter display_parameter;
                fsl_player_s32 width = 720;
                fsl_player_s32 height = 576;
                static fsl_player_s32 resize_index = 0;
                static float width_height_table[] = {0.25, 0.5, 0.75, 1, 2, 3, 4};
                static fsl_player_s32 offset_x_y_table[] = {600, 500, 400, 300, 200, 100, 0};
                if ((++resize_index)==6)
                    resize_index = 0;
                display_parameter.offsetx = 0;//offset_x_y_table[resize_index];
                display_parameter.offsety = 0;//offset_x_y_table[resize_index];
                display_parameter.disp_width = width_height_table[resize_index]*width;
                display_parameter.disp_height = width_height_table[resize_index]*height;
                pplayer->klass->resize(pplayer, display_parameter);
                break;
            #else
                fsl_player_display_parameter display_parameter;
                fsl_player_s8 sCommand_x[128];
                fsl_player_s8 sCommand_y[128];
                fsl_player_s8 sCommand_width[128];
                fsl_player_s8 sCommand_height[128];
                PRINT("Input [x,y,width,height]:");
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%s %s %s %s",sCommand_x,sCommand_y,sCommand_width,sCommand_height);
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                display_parameter.offsetx = atoi(sCommand_x);//offset_x_y_table[resize_index];
                display_parameter.offsety = atoi(sCommand_y);//offset_x_y_table[resize_index];
                display_parameter.disp_width = atoi(sCommand_width);
                display_parameter.disp_height = atoi(sCommand_height);
                if( display_parameter.offsetx < 0 || display_parameter.offsety < 0
                    || display_parameter.disp_width <= 0 || display_parameter.disp_height <= 0 )
                {
                    printf("Invalid resize parameters!\n");
                    break;
                }
                pplayer->klass->resize(pplayer, display_parameter);
                break;
            #endif
            }

            case 't': // Rotate 90 degree every time
            {
                fsl_player_rotation rotate_value;
                PRINT("Set rotation between 0, 90, 180, 270: ");
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%s",sCommand);
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                rotate_value = (fsl_player_rotation)atoi(sCommand);
                if( (fsl_player_s32)rotate_value != 0  && (fsl_player_s32)rotate_value != 90 &&  (fsl_player_s32)rotate_value != 180 
                &&   (fsl_player_s32)rotate_value != 270 )
                {
                    printf("Invalid rotation value=%d, rotation value should be between [0, 90, 180, 270]\n", rotate_value);
                    break;
                }
                pplayer->klass->rotate(player_handle, rotate_value);
                break;
            }

            case 'c': // playing direction and speed Control.
            {
                double playback_rate;
                PRINT("Set playing speed[-8,-4,-2,0.125,0.25,0.5,1,2,4,8]:");
                kb_restore_term(STDIN_FILENO);
                gbdisplay = FSL_PLAYER_FALSE;
                scanf("%lf",&playback_rate);
                gbdisplay = FSL_PLAYER_TRUE;
                kb_set_raw_term(STDIN_FILENO);
                pplayer->klass->set_playback_rate(pplayer, playback_rate);
                break;
            }

            case 'i': // Display Metadata Information
            {
                print_metadata(player_handle);
                break;
            }

            case 'x': // eXit
            {
                //pplayer->klass->stop(pplayer);
                //pplayer->klass->exit_message_loop(pplayer); // flush all messages left in the message queue.
                //pplayer->klass->send_message_exit(pplayer); // send a exit message.
                //gbexit_main = FSL_PLAYER_TRUE;
                pplayer->klass->send_message_exit(pplayer);
                player_exit(pplayer);
                break;
            }

            case '*': // Sleep 5 seconds
            {
                FSL_PLAYER_SLEEP(5000);
                break;
            }

            case '#': // Sleep 10 seconds
            {
                FSL_PLAYER_SLEEP(10000);
                break;
            }

            case 'P': //Property
            {
                char prop_name[64] = {0};
                PRINT("Please input property name:");
                scanf("%s",prop_name);
                prop_name[63] = '\0';
                if(FSL_PLAYER_SUCCESS != pplayer->klass->property(pplayer, prop_name)){
                    PRINT("Invalid property parameter\n");
                }
                
                break;
            }
            
            default:
                //printf("Default: Nothing has been done!\n");
                break;
        }
    }
    kb_restore_term (STDIN_FILENO);

    gbexit_display_thread = FSL_PLAYER_TRUE;
    if (opt->info_interval_in_sec){
        FSL_PLAYER_THREAD_JOIN(display_thread);
    }
    FSL_PLAYER_THREAD_JOIN(msg_thread);

    fsl_player_deinit(player_handle);

bail:
    destroyPlayList(opt->pl);

    return 0;
}
fsl_player_s32 msg_thread_fun(fsl_player_handle handle)
{
    fsl_player* pplayer = (fsl_player*)handle;
    fsl_player_ui_msg * msg;

    while(1)
    {
        if( FSL_PLAYER_TRUE == gbexit_msg_thread )
        {
            return 0;
        }

        msg = NULL;
        if( FSL_PLAYER_SUCCESS == pplayer->klass->wait_message( handle, &msg, FSL_PLAYER_FOREVER) )
        {
            switch( msg->msg_id )
            {
                case FSL_PLAYER_UI_MSG_EOS:
                {
                    printf("FSL_PLAYER_UI_MSG_EOS\n");
                    pplayer->klass->stop(handle);
                    // Wait until eos message has been processed completely. Fix the bug of play/stop hang problem.
                    pplayer->klass->post_eos_semaphore(handle);
                    //printf("\nmsg_thread_fun:=======================================================\n");
                    if (playlist_next(handle, opt)==NULL){
                      player_exit(handle);
                    }
                    fsl_player_ui_msg_free(msg);
                    break;
                }
                case FSL_PLAYER_UI_MSG_EXIT:
                {
                    printf("FSL_PLAYER_UI_MSG_EXIT\n");
                    fsl_player_ui_msg_free(msg);
                    return 0;
                }
                case FSL_PLAYER_UI_MSG_INTERNAL_ERROR:
                {
                    printf("FSL_PLAYER_UI_MSG_INTERNAL_ERROR: internal error message received.\n");
                    fsl_player_ui_msg_free(msg);
                    player_exit(handle);
                    return 0;
                }
                case FSL_PLAYER_UI_MSG_BUFFERING:
                {
                    fsl_player_ui_msg_body_buffering * pbody = (fsl_player_ui_msg_body_buffering *)(msg->msg_body);

                    if (opt->handle_buffering){
                        if (pbody->percent==0){
                            pplayer->klass->pause(pplayer);
                        }else if (pbody->percent>=100){
                            pplayer->klass->pause(pplayer);

                        }
                    }
                    fsl_player_ui_msg_free(msg);
                    break;
                 }
                default:
                {
                    fsl_player_ui_msg_free(msg);
                    break;
                }
            }


        }
    }

    return 0;
}
Exemplo n.º 10
0
void*
video_read_start(void *arg)
{
	pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
	int ret;
	int n = 0, len = 0, reset = 1;
	int sent_idle_notify;
	demux_attr_t *attr;
	video_info_t *vi;
	int set_aspect = 1;
	char *inbuf = inbuf_static;
	char *tsbuf;
	int tslen;
	int tsmode = TS_MODE_UNKNOWN;
	av_state_t state;

	pthread_mutex_lock(&mutex);

	printf("mpeg read thread started (pid %d)\n", getpid());
	pthread_cond_wait(&video_cond, &mutex);

	while (1) {
		sent_idle_notify = 0;
		while (!video_playing) {
			demux_reset(handle);
			ts_demux_reset(tshandle);
			demux_seek(handle);
			vid_event_discontinuity_possible();
			if ( !(sent_idle_notify) ) {
				if ( video_functions != NULL &&
				     video_functions->notify != NULL ) {
					video_functions->notify(MVP_READ_THREAD_IDLE);
				}
				printf("mpeg read thread sleeping...\n");
				sent_idle_notify = 1;
			}
			pthread_cond_wait(&video_cond, &mutex);
			TRC("%s: past pthread_cond_wait(&video_cond, &mutex)\n", __FUNCTION__);
		}

#ifdef STREAM_TEST
		if ( stream_test_started == 0 ) {
			stream_test_started = 1;
			//Get start time
			gettimeofday(&start_tv, NULL);
		}
#endif

		if (video_reopen) {
		        vid_event_clear();
			if (video_functions->open() == 0) {
				/* Jump to the start of the new file */
				jump_target = 0;
				jumping = 1;
				video_reopen = 0;
				tsmode = TS_MODE_UNKNOWN;
			} else {
				fprintf(stderr, "video open failed!\n");
				video_playing = 0;
				continue;
			}
			len = 0;
			reset = 1;
			set_aspect = 1;
		}

		if ((seeking && reset) || jumping) {
			demux_reset(handle);
			ts_demux_reset(tshandle);
			demux_seek(handle);
			av_get_state(&state);
			av_reset();
			av_reset_stc();
			vid_event_discontinuity_possible();
			if (seeking)
				reset = 0;
			if (state.mute)
				av_set_mute(1);
			if (paused) {
				av_play();
				paused = 0;
				mvpw_hide(pause_widget);
				screensaver_disable();
			}
			pcm_decoded = 0;
			ac3len = 0;
			len = 0;
			if (jumping) {
				while (jump_target < 0)
					usleep(1000);
				video_functions->seek(jump_target, SEEK_SET);
			}
			jumping = 0;
		}

		if ( !video_playing ) {
			continue;
		}

		if (len == 0) {

			if ( video_functions->read_dynb != NULL ){
				tslen = video_functions->read_dynb(&tsbuf, 1024 * 256);
			}
			else {
				tsbuf = tsbuf_static;
				do {
					tslen = video_functions->read(tsbuf,
						      sizeof(tsbuf_static));
				} while ( tslen==-1 && errno==EAGAIN);
			}
			thruput_count += tslen;
			inbuf = inbuf_static;

			if (tsmode == TS_MODE_UNKNOWN) {
				if (tslen > 0) {
					tsmode = ts_demux_is_ts(tshandle, tsbuf, tslen);
					printf("auto detection transport stream returned %d\n", tsmode);
					if (tsmode == TS_MODE_NO)
						len = tslen;
			    	}
			} else if (tsmode == TS_MODE_NO) {
				len = tslen;
			} else {
				len = ts_demux_transform(tshandle, tsbuf, tslen, inbuf, sizeof(inbuf_static));
				int resyncs = ts_demux_resync_count(tshandle);
				if (resyncs > 50) {
					printf("resync count = %d, switch back to unknown mode\n", resyncs);
					tsmode = TS_MODE_UNKNOWN;
					ts_demux_reset(tshandle);
				}
			}
			n = 0;
			if (len == 0 && playlist ) {
				video_reopen = 2;
				playlist_next();
			}
		}

		if ( !video_playing ) {
			continue;
		}

#ifdef STREAM_TEST
		stream_test_cnt += len;
		len = 0;

		if ( stream_test_cnt > 1024*1024*20 ) {
			unsigned int delta_ms;

			gettimeofday(&done_tv, NULL);
			if ( done_tv.tv_usec < start_tv.tv_usec ) {
				done_tv.tv_usec += 1000000;
				done_tv.tv_sec	 -= 1;
			}
			delta_ms = (done_tv.tv_sec - start_tv.tv_sec) * 1000;
			delta_ms += (done_tv.tv_usec - start_tv.tv_usec) / 1000;
			printf("Test Done\n");
			printf("Bytes transferred: %u\n", stream_test_cnt);
			printf("Elapsed time %u mS\n", delta_ms);
			while ( 1 ) {
				sleep(10);
				printf("Test Done....\n");
			}
		}
		continue;
#else
		if (tsmode == TS_MODE_YES)
			ret = DEMUX_PUT(handle, inbuf+n, len-n);
		else
			ret = DEMUX_PUT(handle, tsbuf+n, len-n);
#endif

		if ((ret <= 0) && (!seeking)) {
			pthread_cond_broadcast(&video_cond);
			usleep(1000);
			continue;
		}

		if (seeking) { 
			if (do_seek()) {
				len = 0;
				continue;
			} else {
				reset = 1;
			}
		}

		n += ret;
		if (n == len)
			len = 0;

		pthread_cond_broadcast(&video_cond);

		attr = demux_get_attr(handle);
		vi = &attr->video.stats.info.video;
		if (attr->audio.type != audio_type) {
			audio_type = attr->audio.type;
			switch (audio_type) {
			case AUDIO_MODE_AC3:
				if (audio_output_mode == AUD_OUTPUT_PASSTHRU ) {
					if (av_set_audio_output(AV_AUDIO_AC3) < 0) {
						/* revert to downmixing */
						audio_output_mode = AUD_OUTPUT_STEREO;
					    // fall through to PCM
					} else {
                                    // don't set audio_type
						audio_output = AV_AUDIO_AC3;
						printf("switch to AC3 Passthru\n");
						break;
					}
				}
			case AUDIO_MODE_PCM:
				audio_output = AV_AUDIO_PCM;
				printf("switch to PCM audio output device\n");
				break;
			default:
				av_set_audio_type(audio_type);
				audio_output = AV_AUDIO_MPEG;
				printf("switch to MPEG audio output device\n");
				break;
			}
			av_set_audio_output(audio_output);
		} else {
			if (audio_type==AUDIO_MODE_AC3){
				sync_ac3_audio();
			}
		}

	} //while

	return NULL;
}