void video_progress(mvp_widget_t *widget) { long long offset = 0, size; int off; char buf[32]; if ((size=video_functions->size()) < 0) { disable_osd(); mvpw_hide(osd_widget); mvpw_hide(mute_widget); mvpw_hide(pause_widget); mvpw_hide(ffwd_widget); mvpw_hide(zoom_widget); display_on = 0; zoomed = 0; return; } if (video_functions->seek) offset = video_functions->seek(0, SEEK_CUR); off = (int)((double)(offset/1000) / (double)(size/1000) * 100.0); snprintf(buf, sizeof(buf), "%d%%", off); mvpw_set_text_str(offset_widget, buf); mvpw_set_graph_current(offset_bar, off); mvpw_expose(offset_widget); }
void mvpw_set_array_cell_span(mvp_widget_t * widget, int x, int y, int span) { int i = widget->data.array.cols * y + x; if(x>widget->data.array.cols || y>widget->data.array.rows) { PRINTF("** SSDEBUG: ERROR %s indexes out of range (%d,%d).\n", __FUNCTION__, x, y); return; } mvpw_resize(widget->data.array.cells[i], widget->data.array.cell_width*span, widget->data.array.cell_height); switch(span) { case 1: widget->data.array.cell_viz[i] = 1; mvpw_show(widget->data.array.cells[i]); break; case 2: widget->data.array.cell_viz[i+1] = 0; mvpw_hide(widget->data.array.cells[i+1]); break; case 3: widget->data.array.cell_viz[i+1] = 0; mvpw_hide(widget->data.array.cells[i+1]); widget->data.array.cell_viz[i+2] = 0; mvpw_hide(widget->data.array.cells[i+2]); break; } widget->data.array.dirty = 1; }
void seek_to(long long seek_offset) { long long offset; if (video_functions->seek == NULL) { fprintf(stderr, "cannot seek on this video!\n"); return; } if (video_write_thread) { pthread_kill(video_write_thread, SIGURG); } if (audio_write_thread) { pthread_kill(audio_write_thread, SIGURG); } if (mvpw_visible(ffwd_widget)) { mvpw_hide(ffwd_widget); av_ffwd(); } offset = video_functions->seek(seek_offset, SEEK_SET); jump_target = seek_offset; jumping = 1; PRINTF("-> %lld\n", offset); pthread_cond_broadcast(&video_cond); }
static void show(mvp_widget_t *widget, bool shw) { int r, c, i; PRINTF("** SSDEBUG: %s col labels\n", shw?"showing":"hiding"); if (widget->data.array.col_labels) { for(c=0;c<widget->data.array.cols+1;c++) { if(widget->data.array.col_labels[c]) { if(shw) mvpw_show(widget->data.array.col_labels[c]); else mvpw_hide(widget->data.array.col_labels[c]); } } } PRINTF("** SSDEBUG: %s row labels\n", shw?"showing":"hiding"); if (widget->data.array.row_labels) { for(r=0;r<widget->data.array.rows;r++) { if(widget->data.array.row_labels[r]) { if(shw) mvpw_show(widget->data.array.row_labels[r]); else mvpw_hide(widget->data.array.row_labels[r]); } } } PRINTF("** SSDEBUG: %s cells\n", shw?"showing":"hiding"); for(r = 0; r < widget->data.array.rows; r++) for(c = 0; c < widget->data.array.cols; c++) { i = widget->data.array.cols * r + c; if(widget->data.array.cells[i]) { /*PRINTF("** SSDEBUG: %s cell(%d)\n", shw?"showing":"hiding",i);*/ if(shw && widget->data.array.cell_viz[i]) mvpw_show(widget->data.array.cells[i]); else mvpw_hide(widget->data.array.cells[i]); } } widget->data.array.dirty = 1; }
void mvpw_destroy(mvp_widget_t *widget) { mvpw_hide(widget); if (widget->callback_destroy) widget->callback_destroy(widget); if (widget->destroy) widget->destroy(widget); remove_widget(widget); GrDestroyWindow(widget->wid); free(widget); }
static void video_subtitle_display(mvp_widget_t *widget) { spu_item_t *spu; spu = demux_spu_get_next(handle); if (spu) { char *image; if ((image=demux_spu_decompress(handle, spu)) != NULL) { mvpw_bitmap_attr_t bitmap; if (spu_widget) { mvpw_hide(spu_widget); mvpw_expose(root); mvpw_destroy(spu_widget); } spu_widget = mvpw_create_bitmap(NULL, spu->x, spu->y, spu->w, spu->h, 0, 0, 0); bitmap.image = image; /* * XXX: we really should wait until the proper * moment to display the subtitle */ if (spu_widget) { mvpw_set_bitmap(spu_widget, &bitmap); mvpw_lower(spu_widget); mvpw_show(spu_widget); mvpw_expose(spu_widget); } free(image); } else { printf("fb: got subtitle, decompress failed\n"); } free(spu); } }
void fb_exit(void) { audio_stop = 1; audio_clear(); pthread_kill(audio_thread, SIGURG); if (current) { free(current); current = NULL; } mvpw_hide(fb_progress); video_clear(); av_stop(); if (!mvpw_visible(playlist_widget)) playlist_clear(); }
static void select_callback(mvp_widget_t *widget, char *item, void *key) { char path[1024], *ptr; struct stat64 sb; sprintf(path, "%s/%s", cwd, item); if (stat64(path, &sb)!=0) { printf("Could not stat %s error %d\n",item,errno); if (strcmp(item,"../")==0 ) { // probably lost network put you back in root strcpy(cwd,"/"); strcpy(path,"/"); stat64(path, &sb); } } if (current_pl && !is_playlist(item)) { free(current_pl); current_pl = NULL; } if (current_pl && (playlist == NULL)) { free(current_pl); current_pl = NULL; } printf("%s(): path '%s'\n", __FUNCTION__, path); if (current && (strcmp(path, current) == 0)) { printf("selected current item\n"); if (is_video(item) || (is_streaming(item) > 100)) { mvpw_hide(widget); mvpw_hide(fb_progress); av_move(0, 0, 0); screensaver_disable(); return; } } if (current_pl && (strcmp(path, current_pl) == 0)) { if (is_playlist(item)) { mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); mvpw_hide(widget); printf("Show playlist menu\n"); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); return; } } if (S_ISDIR(sb.st_mode)) { if (strcmp(item, "../") == 0) { strcpy(path, cwd); if (path[strlen(path)-1] == '/') path[strlen(path)-1] = '\0'; if ((ptr=strrchr(path, '/')) != NULL) *ptr = '\0'; if (path[0] == '\0') sprintf(path, "/"); } else { if ((ptr=strrchr(path, '/')) != NULL) *ptr = '\0'; } if (strstr(path,"/uPnP")!=NULL && strstr(cwd,"/uPnP")==NULL ){ mount_djmount(path); } else if (strstr(path,"/uPnP")==NULL && strstr(cwd,"/uPnP")!=NULL ) { unmount_djmount(); } strncpy(cwd, path, sizeof(cwd)); while ((cwd[0] == '/') && (cwd[1] == '/')) memmove(cwd, cwd+1, strlen(cwd)); mvpw_clear_menu(widget); mvpw_set_menu_title(widget, cwd); busy_start(); add_dirs(widget); add_files(widget); busy_end(); mvpw_expose(widget); } else { switch_hw_state(MVPMC_STATE_FILEBROWSER); if (current) free(current); current = NULL; audio_stop = 1; pthread_kill(audio_thread, SIGURG); while (audio_playing) usleep(1000); current = strdup(path); if (is_streaming(item) > 100) { // Use VLC callbacks for streaming items video_functions = &vlc_functions; // Allow broadcast messages to be sent so // we can tell VLC to start the stream vlc_broadcast_enabled = 1; } else { video_functions = &file_functions; } add_osd_widget(fb_program_widget, OSD_PROGRAM, osd_settings.program, NULL); mvpw_set_text_str(fb_name, item); /* * This code sends the currently playing file name to the display. */ snprintf(display_message, sizeof(display_message), "File:%s\n", item); display_send(display_message); audio_clear(); video_clear(); playlist_clear(); if (is_video(item)) { if (key != NULL) { mvpw_hide(widget); mvpw_hide(fb_progress); av_move(0, 0, 0); } else { mvpw_show(fb_progress); } mvpw_set_timer(fb_progress, fb_osd_update, 500); video_play(NULL); mvpw_show(root); mvpw_expose(root); mvpw_focus(root); } else if (is_audio(item) || is_streaming(item)>=0 ) { mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); audio_play(NULL); } else if (is_image(item)) { mvpw_hide(widget); printf("Displaying image '%s'\n", path); if (mvpw_load_image_jpeg(iw, path) == 0) { mvpw_show_image_jpeg(iw); av_wss_update_aspect(WSS_ASPECT_UNKNOWN); } else { mvpw_set_image(iw, path); } mvpw_show(iw); mvpw_focus(iw); loaded_offset = 0; loaded_status = 0; fb_next_image(1); } else if (is_playlist(item)) { if (current_pl) free(current_pl); current_pl = strdup(path); mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); mvpw_hide(widget); printf("Show playlist menu\n"); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); playlist_clear(); playlist_play(NULL); } } }
void video_callback(mvp_widget_t *widget, char key) { int jump; long long offset, size; pts_sync_data_t async, vsync; av_state_t state; /* printf("**SSDEBUG: In video_callback and got key %d \n",key); */ if (!video_playing) return; if(showing_guide) { if(mvp_tvguide_callback(widget, key) == 1) return; } if ( video_functions->key != NULL ) { if ( video_functions->key(key) == 1 ) { return; } } switch (key) { case MVPW_KEY_GO: case MVPW_KEY_GUIDE: if(showing_guide == 0 && showing_guide == 0) { printf("In %s showing guide %d \n",__FUNCTION__, key); showing_guide = 1; mvp_tvguide_video_topright(1); mvp_tvguide_show(mythtv_livetv_program_list, mythtv_livetv_description, mythtv_livetv_clock); break; } /* if the guide button is pressed while guide is active fall through to go back to remove guide and return to TV */ case MVPW_KEY_TV: if(showing_guide == 1) { printf("In %s hiding guide %d \n", __FUNCTION__, key); showing_guide = 0; mvp_tvguide_video_topright(0); mvp_tvguide_hide(mythtv_livetv_program_list, mythtv_livetv_description, mythtv_livetv_clock); } break; case MVPW_KEY_STOP: case MVPW_KEY_EXIT: back_to_guide_menu(); new_live_tv = 0; break; case MVPW_KEY_PAUSE: if (av_pause()) { mvpw_show(pause_widget); mvpw_hide(ffwd_widget); paused = 1; if (pause_osd && !display_on && (display_on_alt < 2)) { display_on_alt = 2; enable_osd(); } screensaver_enable(); } else { if (pause_osd && !display_on && (display_on_alt == 2)) { display_on_alt = 0; disable_osd(); mvpw_expose(root); } av_get_state(&state); if (state.mute) mvpw_show(mute_widget); else mvpw_hide(mute_widget); mvpw_hide(pause_widget); paused = 0; screensaver_disable(); } break; case MVPW_KEY_PLAY: if ( paused ) { /* * play key can be used to un-pause */ av_pause(); if (pause_osd && !display_on && (display_on_alt == 2)) { display_on_alt = 0; disable_osd(); mvpw_expose(root); } mvpw_hide(pause_widget); mvpw_hide(mute_widget); paused = 0; screensaver_disable(); } break; case MVPW_KEY_REPLAY: seek_by(-30); timed_osd(seek_osd_timeout*1000); break; case MVPW_KEY_REWIND: seek_by(-10); timed_osd(seek_osd_timeout*1000); break; case MVPW_KEY_SKIP: if (mythtv_seek_amount == 0 ) { seek_by(30); } else if (mythtv_seek_amount == 1 ) { seek_by(60); } else { seek_by(30); } timed_osd(seek_osd_timeout*1000); break; case MVPW_KEY_FFWD: if (av_ffwd() == 0) { demux_flush(handle); demux_seek(handle); av_get_state(&state); av_stop(); av_reset(); if (state.mute) { av_set_mute(1); } av_play(); mvpw_hide(ffwd_widget); } else { av_get_state(&state); mvpw_show(ffwd_widget); mvpw_hide(pause_widget); screensaver_disable(); } timed_osd(seek_osd_timeout*1000); break; case MVPW_KEY_LEFT: if (video_functions->seek) { size = video_functions->size(); jump_target = -1; jumping = 1; if (video_write_thread) { pthread_kill(video_write_thread, SIGURG); } if (audio_write_thread) { pthread_kill(audio_write_thread, SIGURG); } offset = video_functions->seek(0, SEEK_CUR); jump_target = ((-size / 100.0) + offset); pthread_cond_broadcast(&video_cond); } break; case MVPW_KEY_RIGHT: if (video_functions->seek) { size = video_functions->size(); jump_target = -1; jumping = 1; if (video_write_thread) { pthread_kill(video_write_thread, SIGURG); } if (audio_write_thread) { pthread_kill(audio_write_thread, SIGURG); } offset = video_functions->seek(0, SEEK_CUR); jump_target = ((size / 100.0) + offset); pthread_cond_broadcast(&video_cond); timed_osd(seek_osd_timeout*1000); } break; case MVPW_KEY_ZERO ... MVPW_KEY_NINE: if(new_live_tv) { printf("In %s showing guide %d \n",__FUNCTION__, key); showing_guide = 1; mvp_tvguide_video_topright(1); mvp_tvguide_show(mythtv_livetv_program_list, mythtv_livetv_description, mythtv_livetv_clock); mvp_tvguide_callback(widget, key); } else if (mythtv_livetv) { back_to_guide_menu(); mythtv_key_callback(mythtv_browser, key); } else { size = video_functions->size(); jump_target = -1; jumping = 1; if (video_write_thread) { pthread_kill(video_write_thread, SIGURG); } if (audio_write_thread) { pthread_kill(audio_write_thread, SIGURG); } jump = key; jump_target = size * (jump / 10.0); pthread_cond_broadcast(&video_cond); timed_osd(seek_osd_timeout*1000); } break; case MVPW_KEY_MENU: mvpw_show(popup_menu); mvpw_focus(popup_menu); break; case MVPW_KEY_MUTE: if (mvpw_visible(ffwd_widget)) { mvpw_hide(mute_widget); break; } if (av_mute() == 1) { mvpw_show(mute_widget); } else { mvpw_hide(mute_widget); } break; case MVPW_KEY_BLANK: case MVPW_KEY_OK: if (display_on || display_on_alt) { disable_osd(); mvpw_expose(root); display_on = 1; display_on_alt = 0; } else { enable_osd(); } display_on = !display_on; break; case MVPW_KEY_FULL: case MVPW_KEY_PREV_CHAN: if(IS_4x3(av_get_tv_aspect())) { if(av_get_tv_aspect() == AV_TV_ASPECT_4x3_CCO) av_set_tv_aspect(AV_TV_ASPECT_4x3); else av_set_tv_aspect(AV_TV_ASPECT_4x3_CCO); } break; case MVPW_KEY_CHAN_UP: case MVPW_KEY_UP: if (mythtv_livetv) mythtv_channel_up(); break; case MVPW_KEY_CHAN_DOWN: case MVPW_KEY_DOWN: if (mythtv_livetv) mythtv_channel_down(); break; case MVPW_KEY_RECORD: /* * XXX: This is a temporary hack until we figure out how * to tell when the audio and video are out of sync, * and correct it automatically. */ av_get_audio_sync(&async); av_get_video_sync(&vsync); printf("PRE SYNC: a 0x%"PRIx64" 0x%"PRIx64" v 0x%"PRIx64" 0x%"PRIx64"\n", async.stc, async.pts, vsync.stc, vsync.pts); av_delay_video(1000); av_get_audio_sync(&async); av_get_video_sync(&vsync); printf("POST SYNC: a 0x%"PRIx64" 0x%"PRIx64" v 0x%"PRIx64" 0x%"PRIx64"\n", async.stc, async.pts, vsync.stc, vsync.pts); break; case MVPW_KEY_VOL_UP: case MVPW_KEY_VOL_DOWN: volume_key_callback(volume_dialog, key); mvpw_show(volume_dialog); mvpw_set_timer(volume_dialog, timer_hide, 3000); break; default: PRINTF("button %d\n", key); break; } }
void back_to_guide_menu() { disable_osd(); if ( !running_replaytv ) { video_thumbnail(AV_THUMBNAIL_EIGTH,VID_THUMB_BOTTOM_RIGHT); } if (spu_widget) { mvpw_hide(spu_widget); mvpw_expose(root); mvpw_destroy(spu_widget); spu_widget = NULL; mvpw_set_timer(root, NULL, 0); } mvpw_hide(osd_widget); mvpw_hide(mute_widget); mvpw_hide(pause_widget); mvpw_hide(ffwd_widget); mvpw_hide(zoom_widget); display_on = 0; zoomed = 0; switch (gui_state) { case MVPMC_STATE_NONE: case MVPMC_STATE_EMULATE: case MVPMC_STATE_EMULATE_SHUTDOWN: case MVPMC_STATE_WEATHER: /* * XXX: redisplay the main menu? */ break; case MVPMC_STATE_MYTHTV: case MVPMC_STATE_MYTHTV_SHUTDOWN: printf("%s(): %d\n", __FUNCTION__, __LINE__); if (mythtv_livetv == 1) { if (mythtv_state == MYTHTV_STATE_LIVETV) { if (mvpw_visible(mythtv_browser) || new_live_tv) { mythtv_livetv_stop(); mythtv_livetv = 0; running_mythtv = 0; if(new_live_tv) { switch_gui_state(MVPMC_STATE_MYTHTV); mvpw_show(mythtv_logo); mvpw_show(mythtv_menu); mvpw_focus(mythtv_menu); } } else { mvpw_show(mythtv_channel); mvpw_show(mythtv_date); mvpw_show(mythtv_description); mvpw_show(mythtv_logo); mvpw_show(mythtv_browser); mvpw_focus(mythtv_browser); video_thumbnail(AV_THUMBNAIL_EIGTH,VID_THUMB_BOTTOM_RIGHT); } } else if (mythtv_state == MYTHTV_STATE_MAIN) { mvpw_show(mythtv_logo); mvpw_show(mythtv_menu); } else { mythtv_show_widgets(); } } else if (mythtv_main_menu) { mvpw_show(mythtv_logo); mvpw_show(mythtv_menu); mvpw_focus(mythtv_menu); } else if (running_mythtv) { printf("%s(): %d\n", __FUNCTION__, __LINE__); mythtv_show_widgets(); mvpw_focus(mythtv_browser); } break; case MVPMC_STATE_REPLAYTV: case MVPMC_STATE_REPLAYTV_SHUTDOWN: video_playing = 0; replaytv_back_from_video(); break; case MVPMC_STATE_FILEBROWSER: case MVPMC_STATE_FILEBROWSER_SHUTDOWN: case MVPMC_STATE_HTTP: case MVPMC_STATE_HTTP_SHUTDOWN: if (playlist) { mvpw_show(fb_progress); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); } else { mvpw_show(fb_progress); mvpw_show(file_browser); mvpw_focus(file_browser); } break; case MVPMC_STATE_MCLIENT: case MVPMC_STATE_MCLIENT_SHUTDOWN: /* * No code is necessary here because: * - The key is already trapped / processed in gui.c/mclient_key_callback. * - And the mclient show / focus is in gui.c/main_select_callback. */ break; } mvpw_expose(root); }
static void seek_by(int seconds) { demux_attr_t *attr = demux_get_attr(handle); int delta; int stc_time, gop_time, pts_time; long long offset, size; if (video_functions->seek == NULL) { fprintf(stderr, "cannot seek on this video!\n"); return; } if (video_write_thread) { pthread_kill(video_write_thread, SIGURG); } if (audio_write_thread) { pthread_kill(audio_write_thread, SIGURG); } if (mvpw_visible(ffwd_widget)) { mvpw_hide(ffwd_widget); av_ffwd(); } gop_seek_attempts = 0; pts_seek_attempts = 0; av_current_stc(&seek_stc); seek_Bps = ((1024*1024) * 4) / 8; /* default to 4 megabits per second */ gop_time = 0; if ( attr->gop_valid ) { gop_time = (attr->gop.hour*60 + attr->gop.minute)*60 + attr->gop.second; if (attr->Bps) seek_Bps = attr->Bps; } pts_time = attr->gop.pts/PTS_HZ; stc_time = (seek_stc.hour*60 + seek_stc.minute)*60 + seek_stc.second; /* * If the STC and GOP timestamps are close, use the STC timestamp as * the starting point, because it is the timestamp for the frame the * hardware is currently playing. If GOP time not set use STC anyway. */ if (abs(gop_time - stc_time) < 10) { printf("STC SEEK from: %d, (%d)\n", stc_time, gop_time); seek_start_seconds = stc_time; gop_seek_attempts = 4; } else if (gop_time) { printf("GOP SEEK from: %d, (%d)\n", gop_time, pts_time); seek_start_seconds = gop_time; gop_seek_attempts = 4; } else { printf("PTS SEEK from: %d, (%d)\n", pts_time, gop_time); seek_start_seconds = pts_time; pts_seek_attempts = 4; } seek_start_pos = video_functions->seek(0, SEEK_CUR); size = video_functions->size(); seek_seconds = seek_start_seconds + seconds; /* The mvpmc hardware can only handle 12Mbps and some off-air DVB/ATSC * SD broadcasts appear to some way result in huge (200+Mbps) values * to appear in the seeks and cause 30 seconds seeks to go for a lot * longer */ if ( seek_Bps > (12/8)*1024*1024) { printf("Calculated Seek Bps was %d kbps, which is too high " \ "- set to 4Mbps\n",8*seek_Bps/1024); seek_Bps = (4/8) * 1024 * 1024; } delta = seek_Bps * seconds; /* * Abort the seek if near the end of the file */ if ((size < 0) || (seek_start_pos + delta > size)) { fprintf(stderr, "near end of file, seek aborted\n"); return; } PRINTF("%d Bps, currently %lld + %d\n", seek_Bps, seek_start_pos, delta); gettimeofday((struct timeval*)&seek_timeval, NULL); seek_attempts = 16; seeking = 1; offset = video_functions->seek(delta, SEEK_CUR); PRINTF("-> %lld\n", offset); pthread_cond_broadcast(&video_cond); }
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; }