report if the service creation failed
[mplayer/greg.git] / mplayer.c
bloba495537029d10d1970dea4d0177b55264c614375
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "config.h"
5 #ifdef WIN32
6 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
7 #include <windows.h>
8 #endif
9 #include <string.h>
10 #include <unistd.h>
12 // #include <sys/mman.h>
13 #include <sys/types.h>
14 #ifndef __MINGW32__
15 #include <sys/ioctl.h>
16 #include <sys/wait.h>
17 #else
18 #define SIGHUP 1 /* hangup */
19 #define SIGQUIT 3 /* quit */
20 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
21 #define SIGBUS 10 /* bus error */
22 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
23 #endif
25 #include <sys/time.h>
26 #include <sys/stat.h>
28 #include <signal.h>
29 #include <time.h>
30 #include <fcntl.h>
31 #include <limits.h>
33 #include <errno.h>
35 #include "version.h"
37 #include "mp_msg.h"
39 #define HELP_MP_DEFINE_STATIC
40 #include "help_mp.h"
42 #include "m_option.h"
43 #include "m_config.h"
45 #include "cfg-mplayer-def.h"
47 #ifdef USE_SUB
48 #include "subreader.h"
49 #endif
51 #include "libvo/video_out.h"
53 #include "libvo/font_load.h"
54 #include "libvo/sub.h"
56 #ifdef HAVE_X11
57 #include "libvo/x11_common.h"
58 #endif
60 #include "libao2/audio_out.h"
61 #include "libao2/audio_plugin.h"
63 #include "codec-cfg.h"
65 #ifdef USE_DVDNAV
66 #include <dvdnav.h>
67 #endif
69 #ifdef USE_EDL
70 #include "edl.h"
71 #endif
73 #include "spudec.h"
74 #include "vobsub.h"
76 #include "osdep/getch2.h"
77 #include "osdep/timer.h"
79 #include "cpudetect.h"
81 #ifdef HAVE_NEW_GUI
82 #include "Gui/interface.h"
83 #endif
85 #include "input/input.h"
87 int slave_mode=0;
88 int verbose=0;
89 int identify=0;
90 int quiet=0;
92 #define ABS(x) (((x)>=0)?(x):(-(x)))
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
95 #ifdef HAVE_RTC
96 #include <linux/rtc.h>
97 #endif
99 #ifdef USE_TV
100 #include "libmpdemux/tv.h"
101 #endif
103 #ifdef HAS_DVBIN_SUPPORT
104 #include "libmpdemux/dvbin.h"
105 static int last_dvb_step = 1;
106 #endif
108 #ifdef HAVE_MATROSKA
109 #include "libmpdemux/matroska.h"
110 #endif
112 //**************************************************************************//
113 // Playtree
114 //**************************************************************************//
115 #include "playtree.h"
116 #include "playtreeparser.h"
118 #ifdef HAVE_NEW_GUI
119 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
120 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
121 #endif
123 play_tree_t* playtree;
124 play_tree_iter_t* playtree_iter = NULL;
126 #define PT_NEXT_ENTRY 1
127 #define PT_PREV_ENTRY -1
128 #define PT_NEXT_SRC 2
129 #define PT_PREV_SRC -2
130 #define PT_UP_NEXT 3
131 #define PT_UP_PREV -3
133 //**************************************************************************//
134 // Config
135 //**************************************************************************//
136 m_config_t* mconfig;
138 extern play_tree_t*
139 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
140 extern int
141 m_config_parse_config_file(m_config_t* config, char *conffile);
143 //**************************************************************************//
144 // Config file
145 //**************************************************************************//
147 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
149 static int cfg_include(m_option_t *conf, char *filename){
150 return m_config_parse_config_file(mconfig, filename);
153 #include "get_path.c"
155 //**************************************************************************//
156 // XScreensaver
157 //**************************************************************************//
159 #ifdef HAVE_X11
160 void xscreensaver_heartbeat(void);
161 #endif
163 //**************************************************************************//
164 //**************************************************************************//
165 // Input media streaming & demultiplexer:
166 //**************************************************************************//
168 static int max_framesize=0;
170 #include "libmpdemux/stream.h"
171 #include "libmpdemux/demuxer.h"
172 #include "libmpdemux/stheader.h"
173 //#include "parse_es.h"
175 #include "libmpcodecs/dec_audio.h"
176 #include "libmpcodecs/dec_video.h"
177 #include "libmpcodecs/mp_image.h"
178 #include "libmpcodecs/vf.h"
180 extern void vf_list_plugins();
182 //**************************************************************************//
183 //**************************************************************************//
185 // Common FIFO functions, and keyboard/event FIFO code
186 #include "fifo.c"
187 int use_stdin=0;
188 //**************************************************************************//
190 vo_functions_t *video_out=NULL;
191 ao_functions_t *audio_out=NULL;
193 int fixed_vo=0;
194 int eof=0;
196 // benchmark:
197 double video_time_usage=0;
198 double vout_time_usage=0;
199 static double audio_time_usage=0;
200 static int total_time_usage_start=0;
201 static int total_frame_cnt=0;
202 static int drop_frame_cnt=0; // total number of dropped frames
203 int benchmark=0;
205 // options:
206 int auto_quality=0;
207 static int output_quality=0;
209 float playback_speed=1.0;
211 int use_gui=0;
213 #ifdef HAVE_NEW_GUI
214 int enqueue=0;
215 #endif
217 #define MAX_OSD_LEVEL 3
219 int osd_level=1;
220 int osd_level_saved=-1;
221 int osd_visible=100;
223 // seek:
224 static char *seek_to_sec=NULL;
225 static off_t seek_to_byte=0;
226 static off_t step_sec=0;
227 static int loop_times=-1;
228 static int loop_seek=0;
230 // A/V sync:
231 int autosync=0; // 30 might be a good default value.
233 // may be changed by GUI: (FIXME!)
234 float rel_seek_secs=0;
235 int abs_seek_pos=0;
237 // codecs:
238 char **audio_codec_list=NULL; // override audio codec
239 char **video_codec_list=NULL; // override video codec
240 char **audio_fm_list=NULL; // override audio codec family
241 char **video_fm_list=NULL; // override video codec family
243 // streaming:
244 int audio_id=-1;
245 int video_id=-1;
246 int dvdsub_id=-1;
247 int vobsub_id=-1;
248 char* audio_lang=NULL;
249 char* dvdsub_lang=NULL;
250 static char* spudec_ifo=NULL;
251 char* filename=NULL; //"MI2-Trailer.avi";
252 int forced_subs_only=0;
254 // cache2:
255 int stream_cache_size=-1;
256 #ifdef USE_STREAM_CACHE
257 extern int cache_fill_status;
258 #else
259 #define cache_fill_status 0
260 #endif
262 // dump:
263 static char *stream_dump_name="stream.dump";
264 int stream_dump_type=0;
266 // A-V sync:
267 static float default_max_pts_correction=-1;//0.01f;
268 static float max_pts_correction=0;//default_max_pts_correction;
269 static float c_total=0;
270 float audio_delay=0;
272 static int softsleep=0;
274 float force_fps=0;
275 static int force_srate=0;
276 static int audio_output_format=0;
277 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
278 static int play_n_frames=-1;
279 static int play_n_frames_mf=-1;
281 // screen info:
282 char** video_driver_list=NULL;
283 char** audio_driver_list=NULL;
285 extern char *vo_subdevice;
286 extern char *ao_subdevice;
288 // codec outfmt flags (defined in libmpcodecs/vd.c)
289 extern int vo_flags;
291 // sub:
292 char *font_name=NULL;
293 #ifdef HAVE_FONTCONFIG
294 extern int font_fontconfig;
295 #endif
296 float font_factor=0.75;
297 char **sub_name=NULL;
298 float sub_delay=0;
299 float sub_fps=0;
300 int sub_auto = 1;
301 char *vobsub_name=NULL;
302 /*DSP!!char *dsp=NULL;*/
303 int subcc_enabled=0;
304 int suboverlap_enabled = 1;
305 #ifdef USE_SUB
306 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
307 int set_of_sub_size = 0;
308 int set_of_sub_pos = -1;
309 float sub_last_pts = -303;
310 #endif
312 static stream_t* stream=NULL;
313 static demuxer_t *demuxer=NULL;
314 static sh_audio_t *sh_audio=NULL;
315 static sh_video_t *sh_video=NULL;
317 char* current_module=NULL; // for debugging
319 // also modified by Gui/mplayer/gtk/eq.c:
320 int vo_gamma_gamma = 1000;
321 int vo_gamma_brightness = 1000;
322 int vo_gamma_contrast = 1000;
323 int vo_gamma_saturation = 1000;
324 int vo_gamma_hue = 1000;
326 // ---
328 #ifdef HAVE_MENU
329 #include "m_struct.h"
330 #include "libmenu/menu.h"
331 extern void vf_menu_pause_update(struct vf_instance_s* vf);
332 extern vf_info_t vf_info_menu;
333 static vf_info_t* libmenu_vfs[] = {
334 &vf_info_menu,
335 NULL
337 static vf_instance_t* vf_menu = NULL;
338 static int use_menu = 0;
339 static char* menu_cfg = NULL;
340 static char* menu_root = "main";
341 #endif
344 #ifdef HAVE_RTC
345 static int nortc;
346 #endif
348 #ifdef USE_EDL
349 struct edl_record edl_records[ MAX_EDL_ENTRIES ];
350 int num_edl_records = 0;
351 FILE* edl_fd = NULL;
352 edl_record_ptr next_edl_record = NULL;
353 static char* edl_filename = NULL;
354 static char* edl_output_filename = NULL;
355 short edl_decision = 0;
356 #endif
358 static unsigned int inited_flags=0;
359 #define INITED_VO 1
360 #define INITED_AO 2
361 #define INITED_GUI 4
362 #define INITED_GETCH2 8
363 #define INITED_SPUDEC 32
364 #define INITED_STREAM 64
365 #define INITED_INPUT 128
366 #define INITED_VOBSUB 256
367 #define INITED_DEMUXER 512
368 #define INITED_ACODEC 1024
369 #define INITED_VCODEC 2048
370 #define INITED_ALL 0xFFFF
372 static void uninit_player(unsigned int mask){
373 mask=inited_flags&mask;
375 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
377 if(mask&INITED_ACODEC){
378 inited_flags&=~INITED_ACODEC;
379 current_module="uninit_acodec";
380 if(sh_audio) uninit_audio(sh_audio);
381 sh_audio=NULL;
384 if(mask&INITED_VCODEC){
385 inited_flags&=~INITED_VCODEC;
386 current_module="uninit_vcodec";
387 if(sh_video) uninit_video(sh_video);
388 sh_video=NULL;
389 #ifdef HAVE_MENU
390 vf_menu=NULL;
391 #endif
394 if(mask&INITED_DEMUXER){
395 inited_flags&=~INITED_DEMUXER;
396 current_module="free_demuxer";
397 if(demuxer){
398 stream=demuxer->stream;
399 free_demuxer(demuxer);
401 demuxer=NULL;
404 // kill the cache process:
405 if(mask&INITED_STREAM){
406 inited_flags&=~INITED_STREAM;
407 current_module="uninit_stream";
408 if(stream) free_stream(stream);
409 stream=NULL;
412 if(mask&INITED_VO){
413 inited_flags&=~INITED_VO;
414 current_module="uninit_vo";
415 video_out->uninit();
416 video_out=NULL;
419 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
420 if(mask&INITED_GETCH2){
421 inited_flags&=~INITED_GETCH2;
422 current_module="uninit_getch2";
423 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
424 // restore terminal:
425 getch2_disable();
428 if(mask&INITED_VOBSUB){
429 inited_flags&=~INITED_VOBSUB;
430 current_module="uninit_vobsub";
431 if(vo_vobsub) vobsub_close(vo_vobsub);
432 vo_vobsub=NULL;
435 if (mask&INITED_SPUDEC){
436 inited_flags&=~INITED_SPUDEC;
437 current_module="uninit_spudec";
438 spudec_free(vo_spudec);
439 vo_spudec=NULL;
442 if(mask&INITED_AO){
443 inited_flags&=~INITED_AO;
444 current_module="uninit_ao";
445 audio_out->uninit(eof?0:1); audio_out=NULL;
448 #ifdef HAVE_NEW_GUI
449 if(mask&INITED_GUI){
450 inited_flags&=~INITED_GUI;
451 current_module="uninit_gui";
452 guiDone();
454 #endif
456 if(mask&INITED_INPUT){
457 inited_flags&=~INITED_INPUT;
458 current_module="uninit_input";
459 mp_input_uninit();
462 current_module=NULL;
465 static void exit_player_with_rc(char* how, int rc){
467 uninit_player(INITED_ALL);
468 #ifdef HAVE_X11
469 #ifdef HAVE_NEW_GUI
470 if ( !use_gui )
471 #endif
472 vo_uninit(); // close the X11 connection (if any opened)
473 #endif
475 current_module="exit_player";
477 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Exiting,mp_gettext(how));
478 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
480 exit(rc);
483 void exit_player(char* how){
484 exit_player_with_rc(how, 1);
487 static void exit_sighandler(int x){
488 static int sig_count=0;
489 ++sig_count;
490 if(sig_count==5 || (inited_flags==0 && sig_count>1)) exit(1);
491 if(sig_count>5){
492 // can't stop :(
493 #ifndef __MINGW32__
494 kill(getpid(),SIGKILL);
495 #endif
497 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
498 current_module?current_module:mp_gettext("unknown")
500 if(sig_count==1)
501 switch(x){
502 case SIGINT:
503 case SIGQUIT:
504 case SIGTERM:
505 case SIGKILL:
506 break; // killed from keyboard (^C) or killed [-9]
507 case SIGILL:
508 #ifdef RUNTIME_CPUDETECT
509 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
510 #else
511 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
512 #endif
513 case SIGFPE:
514 case SIGSEGV:
515 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
516 default:
517 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
519 exit_player(NULL);
522 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
524 extern void mp_input_register_options(m_config_t* cfg);
526 #include "mixer.h"
527 #include "cfg-mplayer.h"
529 void parse_cfgfiles( m_config_t* conf )
531 char *conffile;
532 int conffile_fd;
533 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
534 exit(1);
535 if ((conffile = get_path("")) == NULL) {
536 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
537 } else {
538 #ifdef __MINGW32__
539 mkdir(conffile);
540 #else
541 mkdir(conffile, 0777);
542 #endif
543 free(conffile);
544 if ((conffile = get_path("config")) == NULL) {
545 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
546 } else {
547 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
548 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
549 write(conffile_fd, default_config, strlen(default_config));
550 close(conffile_fd);
552 if (m_config_parse_config_file(conf, conffile) < 0)
553 exit(1);
554 free(conffile);
559 void load_per_file_config (m_config_t* conf, const char *const file)
561 char *confpath;
562 char cfg[strlen(file)+10];
563 struct stat st;
564 char *name;
566 sprintf (cfg, "%s.conf", file);
568 if (!stat (cfg, &st))
570 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Loading config '%s'\n", cfg);
571 m_config_parse_config_file (conf, cfg);
572 return;
575 if ((name = strrchr (cfg, '/')) == NULL)
576 name = cfg;
577 else
578 name++;
580 if ((confpath = get_path (name)) != NULL)
582 if (!stat (confpath, &st))
584 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Loading config '%s'\n", confpath);
585 m_config_parse_config_file (conf, confpath);
588 free (confpath);
592 // When libmpdemux perform a blocking operation (network connection or cache filling)
593 // if the operation fail we use this function to check if it was interrupted by the user.
594 // The function return a new value for eof.
595 static int libmpdemux_was_interrupted(int eof) {
596 mp_cmd_t* cmd;
597 if((cmd = mp_input_get_cmd(0,0)) != NULL) {
598 switch(cmd->id) {
599 case MP_CMD_QUIT:
600 exit_player_with_rc(MSGTR_Exit_quit, 0);
601 case MP_CMD_PLAY_TREE_STEP: {
602 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
603 } break;
604 case MP_CMD_PLAY_TREE_UP_STEP: {
605 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
606 } break;
607 case MP_CMD_PLAY_ALT_SRC_STEP: {
608 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
609 } break;
611 mp_cmd_free(cmd);
613 return eof;
616 #define mp_basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
618 int playtree_add_playlist(play_tree_t* entry)
620 play_tree_add_bpf(entry,filename);
622 #ifdef HAVE_NEW_GUI
623 if (use_gui) {
624 if (entry) {
625 import_playtree_playlist_into_gui(entry, mconfig);
626 play_tree_free_list(entry,1);
628 } else
629 #endif
631 if(!entry) {
632 entry = playtree_iter->tree;
633 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
634 return PT_NEXT_ENTRY;
636 if(playtree_iter->tree == entry ) { // Loop with a single file
637 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
638 return PT_NEXT_ENTRY;
641 play_tree_remove(entry,1,1);
642 return PT_NEXT_SRC;
644 play_tree_insert_entry(playtree_iter->tree,entry);
645 play_tree_set_params_from(entry,playtree_iter->tree);
646 entry = playtree_iter->tree;
647 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
648 return PT_NEXT_ENTRY;
650 play_tree_remove(entry,1,1);
652 return PT_NEXT_SRC;
655 static int play_tree_step = 1;
657 #ifdef USE_SUB
659 sub_data* subdata = NULL;
661 void add_subtitles(char *filename, float fps, int silent)
663 sub_data *subd;
665 if (filename == NULL) {
666 subd = (sub_data*)malloc(sizeof(sub_data));
667 subd->filename = strdup("none");
668 subd->subtitles = NULL;
669 subd->sub_uses_time = 1;
670 subd->sub_num = 0;
671 subd->sub_errs = 0;
672 set_of_subtitles[set_of_sub_size] = subd;
673 ++set_of_sub_size;
674 return;
677 subd = sub_read_file(filename, fps);
678 if(!subd && !silent)
679 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
680 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
681 set_of_subtitles[set_of_sub_size] = subd;
682 ++set_of_sub_size;
683 printf("SUB: added subtitle file (%d): %s\n", set_of_sub_size, filename);
686 void update_set_of_subtitles()
687 // subdata was changed, set_of_sub... have to be updated.
689 int i;
690 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
691 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
692 set_of_subtitles[i-1] = set_of_subtitles[i];
693 set_of_subtitles[set_of_sub_size-1] = NULL;
694 --set_of_sub_size;
695 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
697 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
698 set_of_subtitles[set_of_sub_pos] = subdata;
700 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
701 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
702 ++set_of_sub_size;
705 #endif
708 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
709 * make it all work is to use the builtin SDL-bootstrap code, which
710 * will be done automatically by replacing our main() if we include SDL.h.
712 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
713 #include <SDL.h>
714 #endif
717 int main(int argc,char* argv[]){
721 static demux_stream_t *d_audio=NULL;
722 static demux_stream_t *d_video=NULL;
723 static demux_stream_t *d_dvdsub=NULL;
725 int file_format=DEMUXER_TYPE_UNKNOWN;
727 int delay_corrected=1;
729 // movie info:
731 int osd_function=OSD_PLAY;
732 int osd_last_pts=-303;
733 int osd_show_av_delay = 0;
734 int osd_show_text = 0;
735 int osd_show_sub_delay = 0;
736 int osd_show_sub_pos = 0;
737 int osd_show_sub_visibility = 0;
738 int osd_show_sub_alignment = 0;
739 int osd_show_vobsub_changed = 0;
740 int osd_show_sub_changed = 0;
741 int osd_show_percentage = 0;
742 int osd_show_tv_channel = 25;
743 int osd_show_ontop = 0;
744 int osd_show_framedropping = 0;
746 int rtc_fd=-1;
748 //float a_frame=0; // Audio
750 int i;
751 char *tmp;
753 int gui_no_filename=0;
756 srand((int) time(NULL));
758 mp_msg_init();
759 mp_msg_set_level(MSGL_STATUS);
761 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2004 MPlayer Team\n\n");
762 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
763 GetCpuCaps(&gCpuCaps);
764 #ifdef ARCH_X86
765 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
766 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
767 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
768 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
769 #ifdef RUNTIME_CPUDETECT
770 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
771 #else
772 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
773 #ifdef HAVE_MMX
774 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
775 #endif
776 #ifdef HAVE_MMX2
777 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
778 #endif
779 #ifdef HAVE_3DNOW
780 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
781 #endif
782 #ifdef HAVE_3DNOWEX
783 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
784 #endif
785 #ifdef HAVE_SSE
786 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
787 #endif
788 #ifdef HAVE_SSE2
789 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
790 #endif
791 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
792 #endif
793 #endif
795 #if defined(WIN32) && defined(USE_WIN32DLL)
796 { /*make our codec dirs available for LoadLibraryA()*/
797 char tmppath[MAX_PATH*2 + 1];
798 char win32path[MAX_PATH];
799 char realpath[MAX_PATH];
800 #ifdef __CYGWIN__
801 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
802 strcpy(tmppath,win32path);
803 #ifdef USE_REALCODECS
804 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
805 sprintf(tmppath,"%s;%s",win32path,realpath);
806 #endif /*USE_REALCODECS*/
807 #else
808 if(!strstr(WIN32_PATH,":")){
809 GetModuleFileNameA(NULL, win32path, MAX_PATH);
810 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
812 else strcpy(win32path,WIN32_PATH);
813 strcpy(tmppath,win32path);
814 #ifdef USE_REALCODECS
815 if(!strstr(REALCODEC_PATH,":")){
816 GetModuleFileNameA(NULL, realpath, MAX_PATH);
817 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
819 else strcpy(realpath,REALCODEC_PATH);
820 sprintf(tmppath,"%s;%s",win32path,realpath);
821 #endif /*USE_REALCODECS*/
822 #endif /*__CYGWIN__*/
823 SetEnvironmentVariableA("PATH", tmppath);
825 #endif /*WIN32 && USE_WIN32DLL*/
827 #ifdef USE_TV
828 tv_param_immediate = 1;
829 #endif
831 if ( argv[0] )
832 if(!strcmp(argv[0],"gmplayer") ||
833 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
834 use_gui=1;
836 mconfig = m_config_new();
837 m_config_register_options(mconfig,mplayer_opts);
838 // TODO : add something to let modules register their options
839 mp_input_register_options(mconfig);
840 parse_cfgfiles(mconfig);
842 #ifdef HAVE_NEW_GUI
843 if ( use_gui ) cfg_read();
844 #endif
846 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
847 if(playtree == NULL)
848 exit(1);
850 playtree = play_tree_cleanup(playtree);
851 if(playtree) {
852 playtree_iter = play_tree_iter_new(playtree,mconfig);
853 if(playtree_iter) {
854 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
855 play_tree_iter_free(playtree_iter);
856 playtree_iter = NULL;
858 filename = play_tree_iter_get_file(playtree_iter,1);
862 #ifndef HAVE_NEW_GUI
863 if(use_gui){
864 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
865 use_gui=0;
867 #else
868 if(use_gui && !vo_init()){
869 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
870 use_gui=0;
872 if (use_gui && playtree_iter){
873 char cwd[PATH_MAX+2];
874 // Remove Playtree and Playtree-Iter from memory as its not used by gui
875 play_tree_iter_free(playtree_iter);
876 playtree_iter=NULL;
878 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
880 strcat(cwd, "/");
881 // Prefix relative paths with current working directory
882 play_tree_add_bpf(playtree, cwd);
884 // Import initital playtree into gui
885 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
887 #endif
889 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
890 list_video_out();
891 exit(0);
894 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
895 list_audio_out();
896 exit(0);
899 // check codec.conf
900 if(!codecs_file || !parse_codec_cfg(codecs_file)){
901 if(!parse_codec_cfg(get_path("codecs.conf"))){
902 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
903 if(!parse_codec_cfg(NULL)){
904 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
905 exit(0);
907 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_BuiltinCodecsConf);
912 #if 0
913 if(video_codec_list){
914 int i;
915 video_codec=video_codec_list[0];
916 for(i=0;video_codec_list[i];i++)
917 printf("vc#%d: '%s'\n",i,video_codec_list[i]);
919 #endif
920 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
921 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
922 list_codecs(1);
923 printf("\n");
924 exit(0);
926 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
927 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
928 list_codecs(0);
929 printf("\n");
930 exit(0);
932 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
933 vfm_help();
934 printf("\n");
935 exit(0);
937 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
938 afm_help();
939 printf("\n");
940 exit(0);
942 #ifdef HAVE_X11
943 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
944 fstype_help();
945 printf("\n");
946 exit(0);
948 #endif
950 #ifdef USE_EDL
952 FILE* fd;
953 char line[ 100 ];
954 float start, stop, duration;
955 int action;
956 int next_edl_array_index = 0;
957 int lineCount = 0;
958 next_edl_record = edl_records;
959 if( edl_filename ) {
960 if( ( fd = fopen( edl_filename, "r" ) ) == NULL ) {
961 printf( "Error opening EDL file [%s]!\n", edl_filename );
962 next_edl_record->next = NULL;
963 } else {
964 while( fgets( line, 99, fd ) != NULL ) {
965 lineCount++;
966 if( ( sscanf( line, "%f %f %d", &start, &stop, &action ) ) == 0 ) {
967 printf( "Invalid EDL line: [%s]\n", line );
968 } else {
969 if( next_edl_array_index > 0 ) {
970 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
971 if( start <= edl_records[ next_edl_array_index-1 ].stop_sec ) {
972 printf( "Invalid EDL line [%d]: [%s]\n", lineCount, line );
973 printf( "Last stop position was [%f]; next start is [%f]. Entries must be in chronological order and cannot overlap. Discarding EDL entry.\n", edl_records[ next_edl_array_index-1 ].stop_sec, start );
974 continue;
977 if( stop <= start ) {
978 printf( "Invalid EDL line [%d]: [%s]\n", lineCount, line );
979 printf( "Stop time must follow start time. Discarding EDL entry.\n" );
980 continue;
982 edl_records[ next_edl_array_index ].action = action;
983 if( action == EDL_MUTE ) {
984 edl_records[ next_edl_array_index ].length_sec = 0;
985 edl_records[ next_edl_array_index ].start_sec = start;
986 edl_records[ next_edl_array_index ].stop_sec = start;
987 next_edl_array_index++;
988 if( next_edl_array_index >= MAX_EDL_ENTRIES-1 ) {
989 break;
991 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
992 edl_records[ next_edl_array_index ].action = EDL_MUTE;
993 edl_records[ next_edl_array_index ].length_sec = 0;
994 edl_records[ next_edl_array_index ].start_sec = stop;
995 edl_records[ next_edl_array_index ].stop_sec = stop;
996 } else {
997 edl_records[ next_edl_array_index ].length_sec = stop - start;
998 edl_records[ next_edl_array_index ].start_sec = start;
999 edl_records[ next_edl_array_index ].stop_sec = stop;
1001 next_edl_array_index++;
1002 if( next_edl_array_index >= MAX_EDL_ENTRIES-1 ) {
1003 break;
1007 if( next_edl_array_index > 0 ) {
1008 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
1010 edl_records[ next_edl_array_index ].start_sec = -1;
1011 edl_records[ next_edl_array_index ].next = NULL;
1012 num_edl_records = ( next_edl_array_index );
1014 fclose( fd );
1015 } else {
1016 next_edl_record->next = NULL;
1018 if( edl_output_filename ) {
1019 if( edl_filename ) {
1020 printf( "Sorry; EDL mode and EDL output mode are mutually exclusive! Disabling all EDL functions.\n" );
1021 edl_output_filename = NULL;
1022 edl_filename = NULL;
1023 next_edl_record->next = NULL;
1024 } else {
1025 if( ( edl_fd = fopen( edl_output_filename, "w" ) ) == NULL ) {
1026 printf( "Error opening file [%s] for writing!\n", edl_output_filename );
1027 edl_output_filename = NULL;
1028 next_edl_record->next = NULL;
1032 #ifdef DEBUG_EDL
1034 printf( "EDL Records:\n" );
1035 if( next_edl_record->next != NULL ) {
1036 while( next_edl_record->next != NULL ) {
1037 printf( "EDL: start [%f], stop [%f], action [%d]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->action );
1038 next_edl_record = next_edl_record->next;
1040 next_edl_record = edl_records;
1043 #endif
1045 #endif
1047 if(!filename){
1048 if(!use_gui){
1049 // no file/vcd/dvd -> show HELP:
1050 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1051 exit(0);
1052 } else gui_no_filename=1;
1055 // Many users forget to include command line in bugreports...
1056 if(verbose>0){
1057 mp_msg(MSGT_CPLAYER, MSGL_INFO, "CommandLine:");
1058 for(i=1;i<argc;i++)printf(" '%s'",argv[i]);
1059 printf("\n");
1062 mp_msg_set_level(verbose+MSGL_STATUS);
1064 //------ load global data first ------
1066 // check font
1067 #ifdef USE_OSD
1068 #ifdef HAVE_FREETYPE
1069 init_freetype();
1070 #endif
1071 #ifdef HAVE_FONTCONFIG
1072 if(!font_fontconfig)
1074 #endif
1075 if(font_name){
1076 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1077 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1078 } else {
1079 // try default:
1080 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1);
1081 if(!vo_font)
1082 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1084 #ifdef HAVE_FONTCONFIG
1086 #endif
1087 #endif
1088 vo_init_osd();
1090 #ifdef HAVE_RTC
1091 if(!nortc)
1093 // seteuid(0); /* Can't hurt to try to get root here */
1094 if ((rtc_fd = open("/dev/rtc", O_RDONLY)) < 0)
1095 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Failed to open /dev/rtc: %s (/dev/rtc should be readable by the user.)\n", strerror(errno));
1096 else {
1097 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1099 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1100 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp, strerror(errno));
1101 mp_msg(MSGT_CPLAYER, MSGL_HINT, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp);
1102 close (rtc_fd);
1103 rtc_fd = -1;
1104 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1105 /* variable only by the root */
1106 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno));
1107 close (rtc_fd);
1108 rtc_fd = -1;
1109 } else
1110 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_UsingRTCTiming, irqp);
1113 #ifdef HAVE_NEW_GUI
1114 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1115 // and now ? -- Pontscho
1116 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1117 #endif
1118 if(rtc_fd<0)
1119 #endif
1120 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Using %s timing\n",softsleep?"software":"usleep()");
1122 #ifdef USE_TERMCAP
1123 if ( !use_gui ) load_termcap(NULL); // load key-codes
1124 #endif
1126 // ========== Init keyboard FIFO (connection to libvo) ============
1128 // Init input system
1129 current_module = "init_input";
1130 mp_input_init();
1131 #ifndef HAVE_NO_POSIX_SELECT
1132 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1134 if(keyb_fifo_get > 0)
1135 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1136 #else
1137 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1138 #endif
1139 if(slave_mode)
1140 #ifndef __MINGW32__
1141 mp_input_add_cmd_fd(0,1,NULL,NULL);
1142 #else
1143 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1144 #endif
1145 else if(!use_stdin)
1146 #ifndef HAVE_NO_POSIX_SELECT
1147 mp_input_add_key_fd(0,1,NULL,NULL);
1148 #else
1149 mp_input_add_key_fd(0,0,NULL,NULL);
1150 #endif
1152 inited_flags|=INITED_INPUT;
1153 current_module = NULL;
1155 #ifdef HAVE_MENU
1156 if(use_menu) {
1157 if(menu_cfg && menu_init(menu_cfg))
1158 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", menu_cfg);
1159 else {
1160 menu_cfg = get_path("menu.conf");
1161 if(menu_init(menu_cfg))
1162 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", menu_cfg);
1163 else {
1164 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1165 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", MPLAYER_CONFDIR"/menu.conf");
1166 else {
1167 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu init failed\n");
1168 use_menu = 0;
1173 #endif
1177 //========= Catch terminate signals: ================
1178 // terminate requests:
1179 signal(SIGTERM,exit_sighandler); // kill
1180 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1182 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1184 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1185 #ifdef ENABLE_SIGHANDLER
1186 // fatal errors:
1187 signal(SIGBUS,exit_sighandler); // bus error
1188 signal(SIGSEGV,exit_sighandler); // segfault
1189 signal(SIGILL,exit_sighandler); // illegal instruction
1190 signal(SIGFPE,exit_sighandler); // floating point exc.
1191 signal(SIGABRT,exit_sighandler); // abort()
1192 #endif
1194 #ifdef HAVE_NEW_GUI
1195 if(use_gui){
1196 guiInit();
1197 inited_flags|=INITED_GUI;
1198 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1200 #endif
1202 // ******************* Now, let's see the per-file stuff ********************
1204 play_next_file:
1206 if (filename) load_per_file_config (mconfig, filename);
1208 // We must enable getch2 here to be able to interrupt network connection
1209 // or cache filling
1210 if(!use_stdin && !slave_mode){
1211 if(inited_flags&INITED_GETCH2)
1212 mp_msg(MSGT_CPLAYER,MSGL_WARN,"WARNING: getch2_init called twice!\n");
1213 else
1214 getch2_enable(); // prepare stdin for hotkeys...
1215 inited_flags|=INITED_GETCH2;
1216 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1219 // =================== GUI idle loop (STOP state) ===========================
1220 #ifdef HAVE_NEW_GUI
1221 if ( use_gui ) {
1222 file_format=DEMUXER_TYPE_UNKNOWN;
1223 guiGetEvent( guiSetDefaults,0 );
1224 while ( guiIntfStruct.Playing != 1 )
1226 mp_cmd_t* cmd;
1227 usec_sleep(20000);
1228 guiEventHandling();
1229 guiGetEvent( guiReDraw,NULL );
1230 if ( (cmd = mp_input_get_cmd(0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1232 guiGetEvent( guiSetParameters,NULL );
1233 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1235 play_tree_t * entry = play_tree_new();
1236 play_tree_add_file( entry,guiIntfStruct.Filename );
1237 if ( playtree ) play_tree_free_list( playtree->child,1 );
1238 else playtree=play_tree_new();
1239 play_tree_set_child( playtree,entry );
1240 if(playtree)
1242 playtree_iter = play_tree_iter_new(playtree,mconfig);
1243 if(playtree_iter)
1245 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1247 play_tree_iter_free(playtree_iter);
1248 playtree_iter = NULL;
1250 filename = play_tree_iter_get_file(playtree_iter,1);
1255 #endif
1256 //---------------------------------------------------------------------------
1258 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
1259 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1261 //==================== Open VOB-Sub ============================
1263 current_module="vobsub";
1264 if (vobsub_name){
1265 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1266 if(vo_vobsub==NULL)
1267 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1268 }else if(sub_auto && filename && (strlen(filename)>=5)){
1269 /* try to autodetect vobsub from movie filename ::atmos */
1270 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1271 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1272 strncpy(buf, filename, strlen(filename)-4);
1273 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1274 free(buf);
1276 if(vo_vobsub){
1277 sub_auto=0; // don't do autosub for textsubs if vobsub found
1278 inited_flags|=INITED_VOBSUB;
1279 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1280 // check if vobsub requested only to display forced subtitles
1281 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1284 //============ Open & Sync STREAM --- fork cache2 ====================
1286 stream=NULL;
1287 demuxer=NULL;
1288 if (d_audio) {
1289 //free_demuxer_stream(d_audio);
1290 d_audio=NULL;
1292 if (d_video) {
1293 //free_demuxer_stream(d_video);
1294 d_video=NULL;
1296 sh_audio=NULL;
1297 sh_video=NULL;
1299 current_module="open_stream";
1300 stream=open_stream(filename,0,&file_format);
1301 if(!stream) { // error...
1302 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1303 goto goto_next_file;
1305 inited_flags|=INITED_STREAM;
1307 #ifdef HAVE_NEW_GUI
1308 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1309 #endif
1311 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1312 play_tree_t* entry;
1313 // Handle playlist
1314 current_module="handle_playlist";
1315 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1316 entry = parse_playtree(stream,0);
1317 eof=playtree_add_playlist(entry);
1318 goto goto_next_file;
1320 stream->start_pos+=seek_to_byte;
1322 if(stream_dump_type==5){
1323 unsigned char buf[4096];
1324 int len;
1325 FILE *f;
1326 current_module="dumpstream";
1327 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1328 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"Cannot dump this stream - no 'fd' available\n");
1329 exit_player(MSGTR_Exit_error);
1331 stream_reset(stream);
1332 stream_seek(stream,stream->start_pos);
1333 f=fopen(stream_dump_name,"wb");
1334 if(!f){
1335 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1336 exit_player(MSGTR_Exit_error);
1338 while(!stream->eof){
1339 len=stream_read(stream,buf,4096);
1340 if(len>0) {
1341 if(fwrite(buf,len,1,f) != 1) {
1342 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1343 exit_player(MSGTR_Exit_error);
1347 if(fclose(f)) {
1348 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1349 exit_player(MSGTR_Exit_error);
1351 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1352 exit_player_with_rc(MSGTR_Exit_eof, 0);
1355 #ifdef USE_DVDREAD
1356 if(stream->type==STREAMTYPE_DVD){
1357 current_module="dvd lang->id";
1358 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1359 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1360 current_module=NULL;
1362 #endif
1364 #ifdef USE_DVDNAV
1365 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1366 #endif
1368 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1369 #ifdef HAS_DVBIN_SUPPORT
1370 goto_enable_cache:
1371 #endif
1372 if(stream_cache_size>0){
1373 current_module="enable_cache";
1374 if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024/5,stream_cache_size*1024/20))
1375 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1378 //============ Open DEMUXERS --- DETECT file type =======================
1379 current_module="demux_open";
1381 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1383 // HACK to get MOV Reference Files working
1385 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1387 unsigned char* playlist_entry;
1388 play_tree_t *list = NULL, *entry = NULL;
1390 current_module="handle_demux_playlist";
1391 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1393 char *temp, *bname;
1395 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry\n",playlist_entry);
1397 bname=mp_basename(playlist_entry);
1398 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1399 continue;
1401 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1402 continue;
1404 entry = play_tree_new();
1406 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1408 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1409 if (temp)
1411 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1412 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1413 strcat(temp, playlist_entry);
1414 play_tree_add_file(entry,temp);
1415 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s\n",temp);
1416 free(temp);
1419 else
1420 play_tree_add_file(entry,playlist_entry);
1422 if(!list)
1423 list = entry;
1424 else
1425 play_tree_append_entry(list,entry);
1427 free_demuxer(demuxer);
1428 demuxer = NULL;
1430 if (list)
1432 entry = play_tree_new();
1433 play_tree_set_child(entry,list);
1434 eof=playtree_add_playlist(entry);
1435 goto goto_next_file;
1439 if(!demuxer)
1441 #if 0
1442 play_tree_t* entry;
1443 // Handle playlist
1444 current_module="handle_playlist";
1445 switch(stream->type){
1446 case STREAMTYPE_VCD:
1447 case STREAMTYPE_DVD:
1448 case STREAMTYPE_DVDNAV:
1449 case STREAMTYPE_CDDA:
1450 case STREAMTYPE_VCDBINCUE:
1451 // don't try to parse raw media as playlist, it's unlikely
1452 goto goto_next_file;
1454 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Falling back on trying to parse playlist %s...\n",filename);
1455 stream_reset(stream);
1456 stream_seek(stream,stream->start_pos);
1457 entry = parse_playtree(stream,0);
1458 if(!entry)
1459 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1460 else
1461 eof=playtree_add_playlist(entry);
1462 #endif
1463 goto goto_next_file;
1465 inited_flags|=INITED_DEMUXER;
1467 current_module="demux_open2";
1469 //file_format=demuxer->file_format;
1471 d_audio=demuxer->audio;
1472 d_video=demuxer->video;
1473 d_dvdsub=demuxer->sub;
1475 // DUMP STREAMS:
1476 if((stream_dump_type)&&(stream_dump_type<4)){
1477 FILE *f;
1478 demux_stream_t *ds=NULL;
1479 current_module="dump";
1480 // select stream to dump
1481 switch(stream_dump_type){
1482 case 1: ds=d_audio;break;
1483 case 2: ds=d_video;break;
1484 case 3: ds=d_dvdsub;break;
1486 if(!ds){
1487 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1488 exit_player(MSGTR_Exit_error);
1490 // disable other streams:
1491 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1492 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1493 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1494 // let's dump it!
1495 f=fopen(stream_dump_name,"wb");
1496 if(!f){
1497 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1498 exit_player(MSGTR_Exit_error);
1500 while(!ds->eof){
1501 unsigned char* start;
1502 int in_size=ds_get_packet(ds,&start);
1503 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1504 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1505 if(in_size>0) fwrite(start,in_size,1,f);
1507 fclose(f);
1508 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1509 exit_player_with_rc(MSGTR_Exit_eof, 0);
1512 sh_audio=d_audio->sh;
1513 sh_video=d_video->sh;
1515 if(sh_video){
1517 current_module="video_read_properties";
1518 if(!video_read_properties(sh_video)) {
1519 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1520 sh_video=d_video->sh=NULL;
1521 } else {
1522 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1523 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1524 sh_video->fps,sh_video->frametime
1527 /* need to set fps here for output encoders to pick it up in their init */
1528 if(force_fps){
1529 sh_video->fps=force_fps;
1530 sh_video->frametime=1.0f/sh_video->fps;
1532 vo_fps = sh_video->fps;
1533 #ifdef HAVE_X11
1534 vo_mouse_timer_const=(int)sh_video->fps;
1535 #endif
1537 if(!sh_video->fps && !force_fps){
1538 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1539 sh_video=d_video->sh=NULL;
1545 fflush(stdout);
1547 if(!sh_video && !sh_audio){
1548 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1549 #ifdef HAS_DVBIN_SUPPORT
1550 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1552 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1553 if(priv->is_on)
1555 int dir;
1556 int v = last_dvb_step;
1557 if(v > 0)
1558 dir = DVB_CHANNEL_HIGHER;
1559 else
1560 dir = DVB_CHANNEL_LOWER;
1562 if(dvb_step_channel(priv, dir))
1564 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1565 cache_uninit(stream);
1566 goto goto_enable_cache;
1570 #endif
1571 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1574 /* display clip info */
1575 demux_info_print(demuxer);
1577 //================== Read SUBTITLES (DVD & TEXT) ==========================
1578 if(d_dvdsub->id >= 0 && vo_spudec==NULL && sh_video){
1580 if (spudec_ifo) {
1581 unsigned int palette[16], width, height;
1582 current_module="spudec_init_vobsub";
1583 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1584 vo_spudec=spudec_new_scaled(palette, width, height);
1587 #ifdef USE_DVDNAV
1588 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1589 current_module="spudec_init_dvdnav";
1590 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1591 sh_video->disp_w, sh_video->disp_h);
1593 #endif
1595 #ifdef USE_DVDREAD
1596 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1597 current_module="spudec_init_dvdread";
1598 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1599 sh_video->disp_w, sh_video->disp_h);
1601 #endif
1603 #ifdef HAVE_MATROSKA
1604 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1605 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1606 current_module = "spudec_init_matroska";
1607 vo_spudec = spudec_new_scaled(((mkv_sh_sub_t *)d_dvdsub->sh)->palette,
1608 ((mkv_sh_sub_t *)d_dvdsub->sh)->width,
1609 ((mkv_sh_sub_t *)d_dvdsub->sh)->height);
1611 #endif
1613 if (vo_spudec==NULL) {
1614 current_module="spudec_init_normal";
1615 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1616 spudec_set_font_factor(vo_spudec,font_factor);
1619 if (vo_spudec!=NULL)
1620 inited_flags|=INITED_SPUDEC;
1624 // Apply current settings for forced subs
1625 if (vo_spudec!=NULL)
1626 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1628 #ifdef USE_SUB
1629 if(sh_video) {
1630 // after reading video params we should load subtitles because
1631 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1632 // check .sub
1633 current_module="read_subtitles_file";
1634 if(sub_name){
1635 for (i = 0; sub_name[i] != NULL; ++i)
1636 add_subtitles (sub_name[i], sh_video->fps, 0);
1638 if(sub_auto) { // auto load sub file ...
1639 char *psub = get_path( "sub/" );
1640 char **tmp = sub_filenames((psub ? psub : ""), filename);
1641 char **tmp2 = tmp;
1642 while (*tmp2)
1643 add_subtitles (*tmp2++, sh_video->fps, 0);
1644 free(tmp);
1645 if (set_of_sub_size == 0)
1646 add_subtitles (get_path("default.sub"), sh_video->fps, 1);
1647 if (set_of_sub_size > 0)
1648 add_subtitles (NULL, sh_video->fps, 1);
1650 if (set_of_sub_size > 0) {
1651 //osd_show_sub_changed = sh_video->fps;
1652 subdata = set_of_subtitles[set_of_sub_pos=0];
1654 if(stream_dump_type==3) list_sub_file(subdata);
1655 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
1656 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
1657 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
1658 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
1659 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
1662 #endif
1664 //================== Init AUDIO (codec) ==========================
1665 if(sh_audio){
1666 // Go through the codec.conf and find the best codec...
1667 current_module="init_audio_codec";
1668 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1669 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1670 sh_audio=d_audio->sh=NULL; // failed to init :(
1671 } else
1672 inited_flags|=INITED_ACODEC;
1673 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1676 if(identify) {
1677 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
1678 if (sh_video) {
1679 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1680 if (sh_video->format >= 0x20202020)
1681 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
1682 else
1683 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
1684 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
1685 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
1686 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
1687 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
1688 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
1690 if (sh_audio) {
1691 if (sh_audio->codec)
1692 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
1693 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1694 if (sh_audio->format >= 0x20202020)
1695 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
1696 else
1697 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
1698 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
1699 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
1700 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
1702 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
1705 if(!sh_video) goto main; // audio-only
1707 //================== Init VIDEO (codec & libvo) ==========================
1708 if(!fixed_vo || !(inited_flags&INITED_VO)){
1709 current_module="preinit_libvo";
1711 vo_config_count=0;
1712 //if((video_out->preinit(vo_subdevice))!=0){
1713 if(!(video_out=init_best_video_out(video_driver_list))){
1714 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
1715 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1717 sh_video->video_out=video_out;
1718 inited_flags|=INITED_VO;
1721 current_module="init_video_filters";
1723 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
1724 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
1726 #ifdef HAVE_MENU
1727 if(use_menu) {
1728 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
1729 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
1730 if(!vf_menu) {
1731 mp_msg(MSGT_CPLAYER,MSGL_ERR,"Can't open libmenu video filter with root menu %s\n",menu_root);
1732 use_menu = 0;
1735 if(vf_menu)
1736 sh_video->vfilter=(void*)append_filters(vf_menu);
1737 else
1738 #endif
1739 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
1741 current_module="init_video_codec";
1743 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1744 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
1745 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1747 if(!sh_video->inited){
1748 if(!fixed_vo) uninit_player(INITED_VO);
1749 if(!sh_audio) goto goto_next_file;
1750 sh_video = d_video->sh = NULL;
1751 goto main; // exit_player(MSGTR_Exit_error);
1754 inited_flags|=INITED_VCODEC;
1756 if(auto_quality>0){
1757 // Auto quality option enabled
1758 output_quality=get_video_quality_max(sh_video);
1759 if(auto_quality>output_quality) auto_quality=output_quality;
1760 else output_quality=auto_quality;
1761 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d\n",output_quality);
1762 set_video_quality(sh_video,output_quality);
1765 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1767 current_module="init_vo";
1768 if (sh_video)
1770 if (vo_gamma_gamma != 1000)
1771 set_video_colors (sh_video, "gamma", vo_gamma_gamma);
1772 if (vo_gamma_brightness != 1000)
1773 set_video_colors(sh_video, "brightness", vo_gamma_brightness);
1774 if (vo_gamma_contrast != 1000)
1775 set_video_colors(sh_video, "contrast", vo_gamma_contrast);
1776 if (vo_gamma_saturation != 1000)
1777 set_video_colors(sh_video, "saturation", vo_gamma_saturation);
1778 if (vo_gamma_hue != 1000)
1779 set_video_colors(sh_video, "hue", vo_gamma_hue);
1782 if(vo_flags & 0x08 && vo_spudec)
1783 spudec_set_hw_spu(vo_spudec,video_out);
1785 #ifdef HAVE_FREETYPE
1786 force_load_font = 1;
1787 #endif
1789 //================== MAIN: ==========================
1790 main:
1791 current_module="main";
1793 // If there is no video OSD has to be disabled.
1794 // In case of playing a playtree we have to restore the
1795 // old OSD level after playing one or more audio-only files.
1796 if(!sh_video && osd_level >= 0) { // save OSD level only once
1797 osd_level_saved = osd_level;
1798 osd_level = 0;
1799 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
1800 osd_level = osd_level_saved;
1801 osd_level_saved = -1;
1804 fflush(stdout);
1806 #ifdef HAVE_NEW_GUI
1807 if ( use_gui )
1809 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
1810 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
1811 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
1812 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
1813 guiGetEvent( guiSetDemuxer,(char *)demuxer );
1815 #endif
1818 //int frame_corr_num=0; //
1819 //float v_frame=0; // Video
1820 float time_frame=0; // Timer
1821 //float num_frames=0; // number of frames played
1822 int grab_frames=0;
1823 char osd_text_buffer[64];
1824 char osd_show_text_buffer[64];
1825 int drop_frame=0; // current dropping status
1826 int dropped_frames=0; // how many frames dropped since last non-dropped frame
1827 int too_slow_frame_cnt=0;
1828 int too_fast_frame_cnt=0;
1829 // for auto-quality:
1830 float AV_delay=0; // average of A-V timestamp differences
1831 double vdecode_time;
1832 unsigned int lastframeout_ts=0;
1833 /*float time_frame_corr_avg=0;*/ /* unused */
1835 float next_frame_time=0;
1836 int frame_time_remaining=0; // flag
1837 int blit_frame=0;
1839 osd_text_buffer[0]=0;
1841 //================ SETUP AUDIO ==========================
1843 if(sh_audio){
1844 //const ao_info_t *info=audio_out->info;
1845 current_module="af_preinit";
1846 ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*playback_speed;
1847 ao_data.channels=audio_output_channels?audio_output_channels:sh_audio->channels;
1848 ao_data.format=audio_output_format?audio_output_format:sh_audio->sample_format;
1849 #if 1
1850 if(!preinit_audio_filters(sh_audio,
1851 // input:
1852 (int)(sh_audio->samplerate*playback_speed),
1853 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
1854 // output:
1855 &ao_data.samplerate, &ao_data.channels, &ao_data.format,
1856 audio_out_format_bits(ao_data.format)/8)){
1857 mp_msg(MSGT_CPLAYER,MSGL_ERR,"Error at audio filter chain pre-init!\n");
1858 } else {
1859 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AF_pre: %dHz %dch %s\n",
1860 ao_data.samplerate, ao_data.channels,
1861 audio_out_format_name(ao_data.format));
1863 #endif
1864 current_module="ao2_init";
1865 if(!(audio_out=init_best_audio_out(audio_driver_list,
1866 (ao_plugin_cfg.plugin_list!=NULL), // plugin flag
1867 force_srate?force_srate:ao_data.samplerate,
1868 audio_output_channels?audio_output_channels:ao_data.channels,
1869 audio_output_format?audio_output_format:ao_data.format,0))){
1870 // FAILED:
1871 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
1872 uninit_player(INITED_ACODEC); // close codec
1873 sh_audio=d_audio->sh=NULL; // -> nosound
1874 } else {
1875 // SUCCESS:
1876 inited_flags|=INITED_AO;
1877 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
1878 audio_out->info->short_name,
1879 ao_data.samplerate, ao_data.channels,
1880 audio_out_format_name(ao_data.format),
1881 audio_out_format_bits(ao_data.format)/8 );
1882 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_AODescription_AOAuthor,
1883 audio_out->info->name, audio_out->info->author);
1884 if(strlen(audio_out->info->comment) > 0)
1885 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_AOComment, audio_out->info->comment);
1886 // init audio filters:
1887 #if 1
1888 current_module="af_init";
1889 if(!init_audio_filters(sh_audio,
1890 (int)(sh_audio->samplerate*playback_speed),
1891 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
1892 ao_data.samplerate, ao_data.channels, ao_data.format,
1893 audio_out_format_bits(ao_data.format)/8, /* ao_data.bps, */
1894 ao_data.outburst*4, ao_data.buffersize)){
1895 mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format!\n");
1896 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1897 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1898 // sh_audio=d_audio->sh=NULL; // -> nosound
1900 #endif
1904 current_module="av_init";
1906 if(sh_video) sh_video->timer=0;
1907 if(sh_audio) sh_audio->delay=-audio_delay;
1909 if(!sh_audio){
1910 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
1911 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks\n",d_audio->packs);
1912 ds_free_packs(d_audio); // free buffered chunks
1913 d_audio->id=-2; // do not read audio chunks
1914 //uninit_player(INITED_AO); // close device
1916 if(!sh_video){
1917 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
1918 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks\n",d_video->packs);
1919 ds_free_packs(d_video);
1920 d_video->id=-2;
1921 //if(!fixed_vo) uninit_player(INITED_VO);
1924 if (!sh_video && !sh_audio)
1925 goto goto_next_file;
1927 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
1928 if(force_fps && sh_video){
1929 vo_fps = sh_video->fps=force_fps;
1930 sh_video->frametime=1.0f/sh_video->fps;
1931 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
1934 //==================== START PLAYING =======================
1936 if(loop_times>1) loop_times--; else
1937 if(loop_times==1) loop_times = -1;
1939 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
1941 InitTimer();
1943 #ifdef USE_DVDNAV
1944 if (stream->type==STREAMTYPE_DVDNAV) {
1945 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
1947 #endif
1949 total_time_usage_start=GetTimer();
1950 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
1951 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
1952 play_n_frames=play_n_frames_mf;
1954 if(play_n_frames==0){
1955 eof=PT_NEXT_ENTRY; goto goto_next_file;
1958 while(!eof){
1959 float aq_sleep_time=0;
1961 if(play_n_frames>=0){
1962 --play_n_frames;
1963 if(play_n_frames<0) eof = PT_NEXT_ENTRY;
1966 /*========================== PLAY AUDIO ============================*/
1968 while(sh_audio){
1969 unsigned int t;
1970 double tt;
1971 int playsize;
1973 current_module="play_audio";
1975 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
1976 playsize=audio_out->get_space();
1978 // handle audio-only case:
1979 if(!playsize && !sh_video) { // buffer is full, do not block here!!!
1980 usec_sleep(10000); // Wait a tick before retry
1981 continue;
1984 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
1986 // Fill buffer if needed:
1987 current_module="decode_audio"; // Enter AUDIO decoder module
1988 t=GetTimer();
1989 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
1990 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
1991 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
1992 if(ret<=0) break; // EOF?
1993 sh_audio->a_out_buffer_len+=ret;
1995 t=GetTimer()-t;
1996 tt = t*0.000001f; audio_time_usage+=tt;
1997 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
1999 // play audio:
2000 current_module="play_audio";
2001 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2003 if(playsize>0){
2004 sh_audio->a_out_buffer_len-=playsize;
2005 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2006 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2007 ao_data.bps : sh_audio->o_bps));
2010 break;
2011 } // while(sh_audio)
2013 if(!sh_video) {
2014 // handle audio-only case:
2015 if(!quiet) {
2017 // convert time to HH:MM:SS.F format
2019 long tenths = 10 * sh_audio->delay-audio_out->get_delay();
2020 int hh = (tenths / 36000) % 100;
2021 int mm = (tenths / 600) % 60;
2022 int ss = (tenths / 10) % 60;
2023 int f1 = tenths % 10;
2024 char hhmmssf[16]; // only really need 11, but just in case...
2025 sprintf( hhmmssf, "%2d:%2d:%2d.%1d", hh, mm, ss, f1);
2026 if (0 == hh) {
2027 hhmmssf[1] = ' ';
2028 hhmmssf[2] = ' ';
2030 // uncomment the next three lines to show leading zero ten-hours
2031 // else if (' ' == hhmmssf[0]) {
2032 // hhmmssf[0] = '0';
2033 // }
2034 if ((0 == hh) && (0 == mm)) {
2035 hhmmssf[4] = ' ';
2036 hhmmssf[5] = ' ';
2038 else if ((' ' == hhmmssf[3]) && (' ' != hhmmssf[2])) {
2039 hhmmssf[3] = '0';
2041 if ((' ' == hhmmssf[6]) && (' ' != hhmmssf[5])) {
2042 hhmmssf[6] = '0';
2044 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: %s %4.1f%% %d%% \r"
2045 ,hhmmssf
2046 ,(sh_audio->delay>0.5)?100.0*audio_time_usage/(double)sh_audio->delay:0
2047 ,cache_fill_status
2050 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2052 } else {
2054 /*========================== PLAY VIDEO ============================*/
2056 float frame_time=next_frame_time;
2058 vo_pts=sh_video->timer*90000.0;
2059 vo_fps=sh_video->fps;
2061 if(!frame_time_remaining){
2062 //-------------------- Decode a frame: -----------------------
2063 vdecode_time=video_time_usage;
2064 while(1)
2065 { unsigned char* start=NULL;
2066 int in_size;
2067 // get it!
2068 current_module="video_read_frame";
2069 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2070 if(in_size<0){ eof=1; break; }
2071 if(in_size>max_framesize) max_framesize=in_size; // stats
2072 sh_video->timer+=frame_time;
2073 if(sh_audio) sh_audio->delay-=frame_time;
2074 time_frame+=frame_time; // for nosound
2075 // check for frame-drop:
2076 current_module="check_framedrop";
2077 if(sh_audio && !d_audio->eof){
2078 float delay=playback_speed*audio_out->get_delay();
2079 float d=delay-sh_audio->delay;
2080 // we should avoid dropping to many frames in sequence unless we
2081 // are too late. and we allow 100ms A-V delay here:
2082 if(d<-dropped_frames*frame_time-0.100){
2083 drop_frame=frame_dropping;
2084 ++drop_frame_cnt;
2085 ++dropped_frames;
2086 } else {
2087 drop_frame=dropped_frames=0;
2089 ++total_frame_cnt;
2091 // decode:
2092 current_module="decode_video";
2093 // printf("Decode! %p %d \n",start,in_size);
2094 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2095 break;
2097 vdecode_time=video_time_usage-vdecode_time;
2098 //------------------------ frame decoded. --------------------
2100 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2102 if(sh_video->vf_inited<0){
2103 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2104 eof=1; goto goto_next_file;
2109 // ==========================================================================
2111 // current_module="draw_osd";
2112 // if(vo_config_count) video_out->draw_osd();
2114 #ifdef HAVE_NEW_GUI
2115 if(use_gui) guiEventHandling();
2116 #endif
2118 current_module="calc_sleep_time";
2120 #if 0
2121 { // debug frame dropping code
2122 float delay=audio_out->get_delay();
2123 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2124 sh_video->timer,sh_audio->timer-delay,
2125 sh_video->timer-(sh_audio->timer-delay),
2126 delay,drop_frame);
2128 #endif
2130 if(drop_frame && !frame_time_remaining && !autosync){
2132 * Note: time_frame should not be forced to 0 in autosync mode.
2133 * It is used as a cumulative counter to predict and correct the
2134 * delay measurements from the audio driver. time_frame is already
2135 * < 0, so the "time to sleep" code does not actually sleep. Also,
2136 * blit_frame is already 0 because drop_frame was true when
2137 * decode_video was called (which causes it to set blit_frame to 0.)
2138 * When autosync==0, the default behavior is still completely unchanged.
2141 time_frame=0; // don't sleep!
2142 blit_frame=0; // don't display!
2144 } else {
2146 // It's time to sleep...
2148 frame_time_remaining=0;
2149 time_frame-=GetRelativeTime(); // reset timer
2151 if(sh_audio && !d_audio->eof){
2152 float delay=playback_speed*audio_out->get_delay();
2153 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2155 if (autosync){
2157 * Adjust this raw delay value by calculating the expected
2158 * delay for this frame and generating a new value which is
2159 * weighted between the two. The higher autosync is, the
2160 * closer to the delay value gets to that which "-nosound"
2161 * would have used, and the longer it will take for A/V
2162 * sync to settle at the right value (but it eventually will.)
2163 * This settling time is very short for values below 100.
2165 float predicted = sh_audio->delay+time_frame;
2166 float difference = delay - predicted;
2167 delay = predicted + difference / (float)autosync;
2170 time_frame=delay-sh_audio->delay;
2172 // delay = amount of audio buffered in soundcard/driver
2173 if(delay>0.25) delay=0.25; else
2174 if(delay<0.10) delay=0.10;
2175 if(time_frame>delay*0.6){
2176 // sleep time too big - may cause audio drops (buffer underrun)
2177 frame_time_remaining=1;
2178 time_frame=delay*0.5;
2181 } else {
2183 // NOSOUND:
2184 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2185 time_frame=0;
2189 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2191 aq_sleep_time+=time_frame;
2193 } // !drop_frame
2195 //============================== SLEEP: ===================================
2197 time_frame/=playback_speed;
2199 // flag 256 means: libvo driver does its timing (dvb card)
2200 if(time_frame>0.001 && !(vo_flags&256)){
2202 #ifdef HAVE_RTC
2203 if(rtc_fd>=0){
2204 // -------- RTC -----------
2205 current_module="sleep_rtc";
2206 while (time_frame > 0.000) {
2207 unsigned long rtc_ts;
2208 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2209 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Linux RTC read error: %s\n", strerror(errno));
2210 time_frame-=GetRelativeTime();
2212 } else
2213 #endif
2215 // -------- USLEEP + SOFTSLEEP -----------
2216 float min=softsleep?0.021:0.005;
2217 current_module="sleep_usleep";
2218 while(time_frame>min){
2219 if(time_frame<=0.020)
2220 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2221 else
2222 usec_sleep(1000000*(time_frame-0.020));
2223 time_frame-=GetRelativeTime();
2225 if(softsleep){
2226 current_module="sleep_soft";
2227 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, "Warning! Softsleep underflow!\n");
2228 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2234 //if(!frame_time_remaining){ // should we display the frame now?
2236 //====================== FLIP PAGE (VIDEO BLT): =========================
2238 current_module="vo_check_events";
2239 if(vo_config_count) video_out->check_events();
2241 current_module="flip_page";
2242 if (!frame_time_remaining) {
2243 if(blit_frame){
2244 unsigned int t2=GetTimer();
2245 double tt;
2246 float j;
2247 #define FRAME_LAG_WARN 0.2
2248 j = ((float)t2 - lastframeout_ts) / 1000000;
2249 lastframeout_ts = GetTimer();
2250 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2251 too_fast_frame_cnt++;
2252 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2253 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2254 too_slow_frame_cnt++;
2255 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2257 if(vo_config_count) video_out->flip_page();
2258 // usec_sleep(50000); // test only!
2259 t2=GetTimer()-t2;
2260 tt = t2*0.000001f;
2261 vout_time_usage+=tt;
2262 } else {
2264 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2265 otherwise A/V desync will occur. -- Alvieboy
2267 if (vo_config_count)
2268 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2271 //====================== A-V TIMESTAMP CORRECTION: =========================
2273 current_module="av_sync";
2275 if(sh_audio){
2276 float a_pts=0;
2277 float v_pts=0;
2279 // unplayed bytes in our and soundcard/dma buffer:
2280 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2282 if (autosync){
2284 * If autosync is enabled, the value for delay must be calculated
2285 * a bit differently. It is set only to the difference between
2286 * the audio and video timers. Any attempt to include the real
2287 * or corrected delay causes the pts_correction code below to
2288 * try to correct for the changes in delay which autosync is
2289 * trying to measure. This keeps the two from competing, but still
2290 * allows the code to correct for PTS drift *only*. (Using a delay
2291 * value here, even a "corrected" one, would be incompatible with
2292 * autosync mode.)
2294 delay=sh_audio->delay;
2295 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2298 #if 0
2299 if(pts_from_bps){
2300 // PTS = sample_no / samplerate
2301 unsigned int samples=
2302 // (sh_audio->audio.dwSampleSize)?
2303 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2304 ds_tell_block(d_audio); // <- used for VBR audio
2305 samples+=sh_audio->audio.dwStart; // offset
2306 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2307 delay_corrected=1;
2308 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2309 } else
2310 #endif
2312 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2313 a_pts=d_audio->pts;
2314 if(!delay_corrected) if(a_pts) delay_corrected=1;
2315 #if 0
2316 printf("\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2317 a_pts,
2318 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2319 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2320 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2321 #endif
2322 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2324 v_pts=sh_video ? sh_video->pts : d_video->pts;
2326 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"### A:%8.3f (%8.3f) V:%8.3f A-V:%7.4f \n",a_pts,a_pts-audio_delay-delay,v_pts,(a_pts-delay-audio_delay)-v_pts);
2328 if(delay_corrected){
2329 static int drop_message=0;
2330 float x;
2331 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2332 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2333 ++drop_message;
2334 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2336 x=AV_delay*0.1f;
2337 if(x<-max_pts_correction) x=-max_pts_correction; else
2338 if(x> max_pts_correction) x= max_pts_correction;
2339 if(default_max_pts_correction>=0)
2340 max_pts_correction=default_max_pts_correction;
2341 else
2342 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2343 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2344 if(!quiet) mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",
2345 a_pts-audio_delay-delay,v_pts,AV_delay,c_total,
2346 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded,
2347 (sh_video->timer>0.5)?(int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer):0,
2348 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer):0,
2349 (sh_video->timer>0.5)?(100.0*audio_time_usage*playback_speed/(double)sh_video->timer):0
2350 ,drop_frame_cnt
2351 ,output_quality
2352 ,cache_fill_status
2354 fflush(stdout);
2357 } else {
2358 // No audio:
2360 if(!quiet)
2361 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video->pts,
2362 (int)sh_video->num_frames,
2363 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
2364 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
2365 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
2366 ,drop_frame_cnt
2367 ,output_quality
2368 ,cache_fill_status
2371 fflush(stdout);
2375 //============================ Auto QUALITY ============================
2377 /*Output quality adjustments:*/
2378 if(auto_quality>0){
2379 current_module="autoq";
2380 // float total=0.000001f * (GetTimer()-aq_total_time);
2381 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2382 if(output_quality<auto_quality && aq_sleep_time>0)
2383 ++output_quality;
2384 else
2385 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2386 if(output_quality>1 && aq_sleep_time<0)
2387 --output_quality;
2388 else
2389 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2390 output_quality=0;
2391 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2392 set_video_quality(sh_video,output_quality);
2395 } // end if(sh_video)
2397 //============================ Handle PAUSE ===============================
2399 current_module="pause";
2401 #ifdef USE_OSD
2402 if(osd_visible){
2403 if (!--osd_visible){
2404 vo_osd_progbar_type=-1; // disable
2405 vo_osd_changed(OSDTYPE_PROGBAR);
2406 if (osd_function != OSD_PAUSE)
2407 osd_function = OSD_PLAY;
2410 #endif
2412 if(osd_function==OSD_PAUSE){
2413 mp_cmd_t* cmd;
2414 if(!quiet) {
2415 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2416 fflush(stdout);
2418 #ifdef HAVE_NEW_GUI
2419 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2420 #endif
2421 if (video_out && sh_video && vo_config_count)
2422 video_out->control(VOCTRL_PAUSE, NULL);
2424 if (audio_out && sh_audio)
2425 audio_out->pause(); // pause audio, keep data if possible
2427 while( (cmd = mp_input_get_cmd(20,1)) == NULL) {
2428 if(sh_video && video_out && vo_config_count) video_out->check_events();
2429 #ifdef HAVE_NEW_GUI
2430 if(use_gui){
2431 guiEventHandling();
2432 guiGetEvent( guiReDraw,NULL );
2433 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2435 #endif
2436 #ifdef HAVE_MENU
2437 if(vf_menu)
2438 vf_menu_pause_update(vf_menu);
2439 #endif
2440 usec_sleep(20000);
2442 mp_cmd_free(cmd);
2443 osd_function=OSD_PLAY;
2444 if (audio_out && sh_audio)
2445 audio_out->resume(); // resume audio
2446 if (video_out && sh_video && vo_config_count)
2447 video_out->control(VOCTRL_RESUME, NULL); // resume video
2448 (void)GetRelativeTime(); // keep TF around FT in next cycle
2449 #ifdef HAVE_NEW_GUI
2450 if (use_gui)
2452 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2453 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2455 #endif
2458 // handle -sstep
2459 if(step_sec>0) {
2460 osd_function=OSD_FFW;
2461 rel_seek_secs+=step_sec;
2464 #ifdef USE_DVDNAV
2465 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2466 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2467 #endif
2469 //================= EDL =========================================
2471 #ifdef USE_EDL
2472 if( next_edl_record->next ) { // Are we (still?) doing EDL?
2473 if ( !sh_video ) {
2474 mp_msg( MSGT_CPLAYER, MSGL_ERR, "Cannot use edit list without video. EDL disabled.\n" );
2475 next_edl_record->next = NULL;
2476 } else {
2477 if( sh_video->pts >= next_edl_record->start_sec ) {
2478 if( next_edl_record->action == EDL_SKIP ) {
2479 osd_function = OSD_FFW;
2480 abs_seek_pos = 0;
2481 rel_seek_secs = next_edl_record->length_sec;
2482 #ifdef DEBUG_EDL
2483 printf( "\nEDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec );
2484 #endif
2485 edl_decision = 1;
2486 next_edl_record = next_edl_record->next;
2487 } else if( next_edl_record->action == EDL_MUTE ) {
2488 mixer_mute();
2489 #ifdef DEBUG_EDL
2490 printf( "\nEDL_MUTE: [%f]\n", next_edl_record->start_sec );
2491 #endif
2492 edl_decision = 1;
2493 next_edl_record = next_edl_record->next;
2498 #endif
2500 //================= Keyboard events, SEEKing ====================
2502 current_module="key_events";
2505 mp_cmd_t* cmd;
2506 int brk_cmd = 0;
2507 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0)) != NULL) {
2508 switch(cmd->id) {
2509 case MP_CMD_SEEK : {
2510 int v,abs;
2511 osd_show_percentage = 25;
2512 v = cmd->args[0].v.i;
2513 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2514 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2515 abs_seek_pos = 1;
2516 if(sh_video)
2517 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2518 rel_seek_secs = v;
2520 else if(abs) { /* Absolute seek by percentage */
2521 abs_seek_pos = 3;
2522 if(sh_video)
2523 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2524 rel_seek_secs = v/100.0;
2526 else {
2527 rel_seek_secs+= v;
2528 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2530 brk_cmd = 1;
2531 } break;
2532 #ifdef USE_EDL
2533 case MP_CMD_EDL_MARK:
2534 if( edl_fd ) {
2535 float v = sh_video->pts;
2536 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2538 break;
2539 #endif
2540 case MP_CMD_AUDIO_DELAY : {
2541 float v = cmd->args[0].v.f;
2542 audio_delay += v;
2543 osd_show_av_delay = 9;
2544 if(sh_audio) sh_audio->delay+= v;
2545 } break;
2546 case MP_CMD_PAUSE : {
2547 osd_function=OSD_PAUSE;
2548 brk_cmd = 1;
2549 } break;
2550 case MP_CMD_QUIT : {
2551 exit_player_with_rc(MSGTR_Exit_quit, 0);
2553 case MP_CMD_GRAB_FRAMES : {
2554 grab_frames=2;
2555 } break;
2556 case MP_CMD_PLAY_TREE_STEP : {
2557 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2558 int force = cmd->args[1].v.i;
2560 #ifdef HAVE_NEW_GUI
2561 if (use_gui) {
2562 int i=0;
2563 if (n>0)
2564 for (i=0;i<n;i++)
2565 mplNext();
2566 else
2567 for (i=0;i<-1*n;i++)
2568 mplPrev();
2569 } else
2570 #endif
2572 if(!force && playtree_iter) {
2573 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2575 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2576 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2577 play_tree_iter_free(i);
2578 } else
2579 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2580 if(eof)
2581 play_tree_step = n;
2582 brk_cmd = 1;
2584 } break;
2585 case MP_CMD_PLAY_TREE_UP_STEP : {
2586 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2587 int force = cmd->args[1].v.i;
2589 if(!force && playtree_iter) {
2590 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2591 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2592 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2593 play_tree_iter_free(i);
2594 } else
2595 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2596 brk_cmd = 1;
2597 } break;
2598 case MP_CMD_PLAY_ALT_SRC_STEP : {
2599 if(playtree_iter && playtree_iter->num_files > 1) {
2600 int v = cmd->args[0].v.i;
2601 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2602 eof = PT_NEXT_SRC;
2603 else if(v < 0 && playtree_iter->file > 1)
2604 eof = PT_PREV_SRC;
2606 brk_cmd = 1;
2607 } break;
2608 case MP_CMD_SUB_DELAY : {
2609 #ifdef USE_SUB
2610 if (sh_video) {
2611 int abs= cmd->args[1].v.i;
2612 float v = cmd->args[0].v.f;
2613 if(abs)
2614 sub_delay = v;
2615 else
2616 sub_delay += v;
2617 osd_show_sub_delay = 9; // show the subdelay in OSD
2619 #endif
2620 } break;
2621 case MP_CMD_SUB_STEP : {
2622 #ifdef USE_SUB
2623 if (sh_video) {
2624 int movement = cmd->args[0].v.i;
2625 step_sub(subdata, sh_video->pts, movement);
2626 osd_show_sub_delay = 9; // show the subdelay in OSD
2628 #endif
2629 } break;
2630 case MP_CMD_OSD : {
2631 #ifdef USE_OSD
2632 if(sh_video) {
2633 int v = cmd->args[0].v.i;
2634 if(v < 0)
2635 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2636 else
2637 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2639 #endif
2640 } break;
2641 case MP_CMD_OSD_SHOW_TEXT : {
2642 #ifdef USE_OSD
2643 if(osd_level && sh_video){
2644 osd_show_text=sh_video->fps; // 1 sec
2645 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2647 #endif
2648 } break;
2649 case MP_CMD_VOLUME : {
2650 int v = cmd->args[0].v.i;
2652 // start change for absolute volume value
2653 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2655 if( abs )
2657 mixer_setvolume( (float)v, (float)v );
2658 } else {
2659 if(v > 0)
2660 mixer_incvolume();
2661 else
2662 mixer_decvolume();
2665 #ifdef USE_OSD
2666 if(osd_level && sh_video){
2667 osd_visible=sh_video->fps; // 1 sec
2668 vo_osd_progbar_type=OSD_VOLUME;
2669 vo_osd_progbar_value=(mixer_getbothvolume()*256.0)/100.0;
2670 vo_osd_changed(OSDTYPE_PROGBAR);
2672 #endif
2673 } break;
2674 case MP_CMD_MUTE:
2675 mixer_mute();
2676 break;
2677 case MP_CMD_LOADFILE : {
2678 play_tree_t* e = play_tree_new();
2679 play_tree_add_file(e,cmd->args[0].v.s);
2681 // Go back to the start point
2682 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2683 /* NOP */;
2684 play_tree_free_list(playtree->child,1);
2685 play_tree_set_child(playtree,e);
2686 play_tree_iter_step(playtree_iter,0,0);
2687 eof = PT_NEXT_SRC;
2688 brk_cmd = 1;
2689 } break;
2690 case MP_CMD_LOADLIST : {
2691 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
2692 if(!e)
2693 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
2694 else {
2695 // Go back to the start point
2696 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2697 /* NOP */;
2698 play_tree_free_list(playtree->child,1);
2699 play_tree_set_child(playtree,e);
2700 play_tree_iter_step(playtree_iter,0,0);
2701 eof = PT_NEXT_SRC;
2703 brk_cmd = 1;
2704 } break;
2705 case MP_CMD_GAMMA : {
2706 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2708 if (!sh_video)
2709 break;
2711 if (vo_gamma_gamma == 1000)
2713 vo_gamma_gamma = 0;
2714 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
2717 if (abs)
2718 vo_gamma_gamma = v;
2719 else
2720 vo_gamma_gamma += v;
2722 if (vo_gamma_gamma > 100)
2723 vo_gamma_gamma = 100;
2724 else if (vo_gamma_gamma < -100)
2725 vo_gamma_gamma = -100;
2726 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
2727 #ifdef USE_OSD
2728 if(osd_level){
2729 osd_visible=sh_video->fps; // 1 sec
2730 vo_osd_progbar_type=OSD_BRIGHTNESS;
2731 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
2732 vo_osd_changed(OSDTYPE_PROGBAR);
2734 #endif // USE_OSD
2735 } break;
2736 case MP_CMD_BRIGHTNESS : {
2737 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2739 if (!sh_video)
2740 break;
2742 if (vo_gamma_brightness == 1000)
2744 vo_gamma_brightness = 0;
2745 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
2748 if (abs)
2749 vo_gamma_brightness = v;
2750 else
2751 vo_gamma_brightness += v;
2753 if (vo_gamma_brightness > 100)
2754 vo_gamma_brightness = 100;
2755 else if (vo_gamma_brightness < -100)
2756 vo_gamma_brightness = -100;
2757 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
2758 #ifdef USE_OSD
2759 if(osd_level){
2760 osd_visible=sh_video->fps; // 1 sec
2761 vo_osd_progbar_type=OSD_BRIGHTNESS;
2762 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
2763 vo_osd_changed(OSDTYPE_PROGBAR);
2765 #endif // USE_OSD
2767 } break;
2768 case MP_CMD_CONTRAST : {
2769 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2771 if (!sh_video)
2772 break;
2774 if (vo_gamma_contrast == 1000)
2776 vo_gamma_contrast = 0;
2777 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
2780 if (abs)
2781 vo_gamma_contrast = v;
2782 else
2783 vo_gamma_contrast += v;
2785 if (vo_gamma_contrast > 100)
2786 vo_gamma_contrast = 100;
2787 else if (vo_gamma_contrast < -100)
2788 vo_gamma_contrast = -100;
2789 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
2790 #ifdef USE_OSD
2791 if(osd_level){
2792 osd_visible=sh_video->fps; // 1 sec
2793 vo_osd_progbar_type=OSD_CONTRAST;
2794 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
2795 vo_osd_changed(OSDTYPE_PROGBAR);
2797 #endif // USE_OSD
2799 } break;
2800 case MP_CMD_SATURATION : {
2801 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2803 if (!sh_video)
2804 break;
2806 if (vo_gamma_saturation == 1000)
2808 vo_gamma_saturation = 0;
2809 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
2812 if (abs)
2813 vo_gamma_saturation = v;
2814 else
2815 vo_gamma_saturation += v;
2817 if (vo_gamma_saturation > 100)
2818 vo_gamma_saturation = 100;
2819 else if (vo_gamma_saturation < -100)
2820 vo_gamma_saturation = -100;
2821 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
2822 #ifdef USE_OSD
2823 if(osd_level){
2824 osd_visible=sh_video->fps; // 1 sec
2825 vo_osd_progbar_type=OSD_SATURATION;
2826 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
2827 vo_osd_changed(OSDTYPE_PROGBAR);
2829 #endif // USE_OSD
2831 } break;
2832 case MP_CMD_HUE : {
2833 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2835 if (!sh_video)
2836 break;
2838 if (vo_gamma_hue == 1000)
2840 vo_gamma_hue = 0;
2841 get_video_colors(sh_video, "hue", &vo_gamma_hue);
2844 if (abs)
2845 vo_gamma_hue = v;
2846 else
2847 vo_gamma_hue += v;
2849 if (vo_gamma_hue > 100)
2850 vo_gamma_hue = 100;
2851 else if (vo_gamma_hue < -100)
2852 vo_gamma_hue = -100;
2853 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
2854 #ifdef USE_OSD
2855 if(osd_level){
2856 osd_visible=sh_video->fps; // 1 sec
2857 vo_osd_progbar_type=OSD_HUE;
2858 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
2859 vo_osd_changed(OSDTYPE_PROGBAR);
2861 #endif // USE_OSD
2863 } break;
2864 case MP_CMD_FRAMEDROPPING : {
2865 int v = cmd->args[0].v.i;
2866 if(v < 0){
2867 frame_dropping = (frame_dropping+1)%3;
2868 #ifdef USE_OSD
2869 osd_show_framedropping=10;
2870 vo_osd_changed(OSDTYPE_SUBTITLE);
2871 #endif
2873 else
2874 frame_dropping = v > 2 ? 2 : v;
2875 } break;
2876 #ifdef USE_TV
2877 case MP_CMD_TV_SET_FREQ : {
2878 if (file_format == DEMUXER_TYPE_TV)
2879 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
2880 } break;
2881 case MP_CMD_TV_SET_NORM : {
2882 if (file_format == DEMUXER_TYPE_TV)
2883 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
2884 } break;
2885 case MP_CMD_TV_SET_BRIGHTNESS : {
2886 if (file_format == DEMUXER_TYPE_TV)
2887 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
2888 } break;
2889 case MP_CMD_TV_SET_HUE : {
2890 if (file_format == DEMUXER_TYPE_TV)
2891 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
2892 } break;
2893 case MP_CMD_TV_SET_SATURATION : {
2894 if (file_format == DEMUXER_TYPE_TV)
2895 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
2896 } break;
2897 case MP_CMD_TV_SET_CONTRAST : {
2898 if (file_format == DEMUXER_TYPE_TV)
2899 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
2900 } break;
2901 case MP_CMD_TV_STEP_CHANNEL : {
2902 if (file_format == DEMUXER_TYPE_TV) {
2903 int v = cmd->args[0].v.i;
2904 if(v > 0){
2905 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
2906 #ifdef USE_OSD
2907 if (tv_channel_list) {
2908 osd_show_tv_channel = sh_video->fps;
2909 vo_osd_changed(OSDTYPE_SUBTITLE);
2911 #endif
2912 } else {
2913 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
2914 #ifdef USE_OSD
2915 if (tv_channel_list) {
2916 osd_show_tv_channel = sh_video->fps;
2917 vo_osd_changed(OSDTYPE_SUBTITLE);
2919 #endif
2923 #ifdef HAS_DVBIN_SUPPORT
2924 if((stream->type == STREAMTYPE_DVB) && stream->priv)
2926 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
2927 if(priv->is_on)
2929 int dir;
2930 int v = cmd->args[0].v.i;
2932 last_dvb_step = v;
2933 if(v > 0)
2934 dir = DVB_CHANNEL_HIGHER;
2935 else
2936 dir = DVB_CHANNEL_LOWER;
2939 if(dvb_step_channel(priv, dir))
2941 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
2942 cache_uninit(stream);
2943 goto goto_enable_cache;
2947 #endif
2948 break;
2949 case MP_CMD_TV_SET_CHANNEL : {
2950 if (file_format == DEMUXER_TYPE_TV) {
2951 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
2952 #ifdef USE_OSD
2953 if (tv_channel_list) {
2954 osd_show_tv_channel = sh_video->fps;
2955 vo_osd_changed(OSDTYPE_SUBTITLE);
2957 #endif
2959 } break;
2960 #ifdef HAS_DVBIN_SUPPORT
2961 case MP_CMD_DVB_SET_CHANNEL:
2963 if((stream->type == STREAMTYPE_DVB) && stream->priv)
2965 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
2966 if(priv->is_on)
2968 if(priv->list->current <= cmd->args[0].v.i)
2969 last_dvb_step = 1;
2970 else
2971 last_dvb_step = -1;
2973 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
2975 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
2976 cache_uninit(stream);
2977 goto goto_enable_cache;
2982 #endif
2983 case MP_CMD_TV_LAST_CHANNEL : {
2984 if (file_format == DEMUXER_TYPE_TV) {
2985 tv_last_channel((tvi_handle_t*)(demuxer->priv));
2986 #ifdef USE_OSD
2987 if (tv_channel_list) {
2988 osd_show_tv_channel = sh_video->fps;
2989 vo_osd_changed(OSDTYPE_SUBTITLE);
2991 #endif
2993 } break;
2994 case MP_CMD_TV_STEP_NORM : {
2995 if (file_format == DEMUXER_TYPE_TV)
2996 tv_step_norm((tvi_handle_t*)(demuxer->priv));
2997 } break;
2998 case MP_CMD_TV_STEP_CHANNEL_LIST : {
2999 if (file_format == DEMUXER_TYPE_TV)
3000 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
3001 } break;
3002 #endif
3003 case MP_CMD_VO_FULLSCREEN:
3005 #ifdef HAVE_NEW_GUI
3006 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3007 else
3008 #endif
3009 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3010 } break;
3011 case MP_CMD_VO_ONTOP:
3013 if(video_out && vo_config_count) {
3014 video_out->control(VOCTRL_ONTOP, 0);
3015 #ifdef USE_OSD
3016 osd_show_ontop=10;
3017 vo_osd_changed(OSDTYPE_SUBTITLE);
3018 #endif
3021 } break;
3022 case MP_CMD_PANSCAN : {
3023 if ( !video_out ) break;
3024 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3026 int abs= cmd->args[1].v.i;
3027 float v = cmd->args[0].v.f;
3028 float res;
3029 if(abs) res = v;
3030 else res = vo_panscan+v;
3031 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3032 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3033 #ifdef USE_OSD
3034 if(osd_level && sh_video){
3035 osd_visible=sh_video->fps; // 1 sec
3036 vo_osd_progbar_type=OSD_PANSCAN;
3037 vo_osd_progbar_value=vo_panscan*256;
3038 vo_osd_changed(OSDTYPE_PROGBAR);
3039 #ifdef HAVE_FREETYPE
3040 if (subtitle_autoscale == 2 || subtitle_autoscale == 3)
3041 // force scaling font to movie width or diagonal
3042 force_load_font = 1;
3043 #endif
3045 #endif
3047 } break;
3048 case MP_CMD_SUB_POS:
3050 #ifdef USE_SUB
3051 if (sh_video) {
3052 int v;
3053 v = cmd->args[0].v.i;
3055 sub_pos+=v;
3056 if(sub_pos >100) sub_pos=100;
3057 if(sub_pos <0) sub_pos=0;
3058 vo_osd_changed(OSDTYPE_SUBTITLE);
3059 osd_show_sub_pos = 9;
3061 #endif
3062 } break;
3063 case MP_CMD_SUB_ALIGNMENT:
3065 #ifdef USE_SUB
3066 if (sh_video) {
3067 if (cmd->nargs >= 1)
3068 sub_alignment = cmd->args[0].v.i;
3069 else
3070 sub_alignment = (sub_alignment+1) % 3;
3071 osd_show_sub_alignment = 9;
3072 vo_osd_changed(OSDTYPE_SUBTITLE);
3074 #endif
3075 } break;
3076 case MP_CMD_SUB_VISIBILITY:
3078 #ifdef USE_SUB
3079 if (sh_video) {
3080 sub_visibility=1-sub_visibility;
3081 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3082 vo_osd_changed(OSDTYPE_SUBTITLE);
3084 #endif
3085 } break;
3086 case MP_CMD_GET_SUB_VISIBILITY:
3088 #ifdef USE_SUB
3089 if (sh_video) {
3090 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_SUB_VISIBILITY=%ld\n", sub_visibility);
3092 #endif
3093 } break;
3094 case MP_CMD_VOBSUB_LANG:
3095 if (vo_vobsub)
3097 int new_id = vobsub_id + 1;
3098 if (vobsub_id < 0)
3099 new_id = 0;
3100 if ((unsigned int) new_id >= vobsub_get_indexes_count(vo_vobsub))
3101 new_id = -1;
3102 if(new_id != vobsub_id)
3103 osd_show_vobsub_changed = 9;
3104 vobsub_id = new_id;
3106 #ifdef USE_SUB
3107 else if (set_of_sub_size > 0){ //change subtitle file
3108 set_of_sub_pos = (set_of_sub_pos + 1) % set_of_sub_size;
3109 subdata = set_of_subtitles[set_of_sub_pos];
3110 osd_show_sub_changed = sh_video->fps;
3111 vo_sub = NULL;
3112 vo_osd_changed(OSDTYPE_SUBTITLE);
3114 #endif
3115 break;
3116 case MP_CMD_SUB_FORCED_ONLY:
3117 if (vo_spudec) {
3118 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3119 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3121 break;
3122 case MP_CMD_SCREENSHOT :
3123 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3124 break;
3125 case MP_CMD_VF_CHANGE_RECTANGLE:
3126 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3127 break;
3129 case MP_CMD_GET_TIME_LENGTH : {
3130 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
3131 } break;
3133 case MP_CMD_GET_VO_FULLSCREEN : {
3134 if(video_out && vo_config_count)
3135 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_VO_FULLSCREEN=%ld\n", vo_fs);
3136 } break;
3138 case MP_CMD_GET_PERCENT_POS : {
3139 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer));
3140 } break;
3142 #ifdef USE_DVDNAV
3143 case MP_CMD_DVDNAV_EVENT: {
3144 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3145 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3147 /* ignore these events if we're not in dvd_nav mode */
3148 if (stream->type != STREAMTYPE_DVDNAV) break;
3150 if (!dvdnav_event) {
3151 printf("DVDNAV Event NULL?!\n");
3152 break;
3155 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3157 switch (dvdnav_event->event) {
3158 case DVDNAV_BLOCK_OK: {
3159 /* be silent about this one */
3160 break;
3162 case DVDNAV_HIGHLIGHT: {
3163 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3164 if (!hevent) {
3165 printf("DVDNAV Event: Highlight event broken\n");
3166 break;
3169 if (hevent->display && hevent->buttonN>0)
3171 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3172 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3173 hevent->buttonN,
3174 hevent->sx,hevent->sy,
3175 hevent->ex,hevent->ey,
3176 hevent->pts, d_video->pts);
3177 printf("DVDNAV Event: %s\n",dvd_nav_text);
3178 //osd_show_dvd_nav_delay = 60;
3180 osd_show_dvd_nav_highlight=1;
3181 osd_show_dvd_nav_sx=hevent->sx;
3182 osd_show_dvd_nav_ex=hevent->ex;
3183 osd_show_dvd_nav_sy=hevent->sy;
3184 osd_show_dvd_nav_ey=hevent->ey;
3186 else {
3187 osd_show_dvd_nav_highlight=0;
3188 printf("DVDNAV Event: Highlight Hide\n");
3190 break;
3192 case DVDNAV_STILL_FRAME: {
3193 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3195 printf( "######################################## DVDNAV Event: Still Frame: %d sec(s)\n", still_event->length );
3196 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3197 usec_sleep(1000); /* 1ms */
3199 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3200 break;
3202 case DVDNAV_STOP: {
3203 printf( "DVDNAV Event: Nav Stop\n" );
3204 break;
3206 case DVDNAV_NOP: {
3207 printf("DVDNAV Event: Nav NOP\n");
3208 break;
3210 case DVDNAV_SPU_STREAM_CHANGE: {
3211 #if DVDNAVVERSION > 012
3212 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3214 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d/%d/%d logical: %d\n",
3215 stream_change->physical_wide,
3216 stream_change->physical_letterbox,
3217 stream_change->physical_pan_scan,
3218 stream_change->logical);
3220 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3221 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3222 d_dvdsub->id,stream_change->physical_wide);
3223 // FIXME: need a better way to change SPU id
3224 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3225 if (vo_spudec) spudec_reset(vo_spudec);
3227 #else
3228 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3230 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n",
3231 stream_change->physical,
3232 stream_change->logical);
3234 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3235 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3236 d_dvdsub->id,stream_change->physical);
3237 // FIXME: need a better way to change SPU id
3238 d_dvdsub->id=dvdsub_id=stream_change->physical;
3239 if (vo_spudec) spudec_reset(vo_spudec);
3241 #endif
3242 break;
3244 case DVDNAV_AUDIO_STREAM_CHANGE: {
3245 int aid_temp;
3246 #if DVDNAVVERSION > 012
3247 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3248 #else
3249 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3250 #endif
3252 printf("DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n",
3253 stream_change->physical,
3254 stream_change->logical);
3256 aid_temp=stream_change->physical;
3257 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3258 if (d_audio && audio_id!=aid_temp) {
3259 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3260 d_audio->id,aid_temp);
3261 // FIXME: need a bettery way to change audio stream id
3262 d_audio->id=dvdsub_id=aid_temp;
3263 if(sh_audio) resync_audio_stream(sh_audio);
3266 break;
3268 case DVDNAV_VTS_CHANGE: {
3269 printf("DVDNAV Event: Nav VTS Change\n");
3270 break;
3272 case DVDNAV_CELL_CHANGE: {
3273 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3274 cell_playback_t * cell_playback = cell_change->new_cell;
3276 printf("DVDNAV Event: Nav Cell Change\n");
3277 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3279 printf("new still time: %d\n",cell_playback->still_time);
3280 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3281 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3282 cell_playback->playback_time.hour,
3283 cell_playback->playback_time.minute,
3284 cell_playback->playback_time.second,
3285 cell_playback->playback_time.frame_u);
3288 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3289 //abs_seek_pos=0;
3290 break;
3292 case DVDNAV_NAV_PACKET: {
3293 // printf("DVDNAV Event: Nav Packet\n");
3294 break;
3296 case DVDNAV_SPU_CLUT_CHANGE: {
3297 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3299 printf("DVDNAV Event: Nav SPU CLUT Change\n");
3300 // send new palette to SPU decoder
3301 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3303 break;
3305 case DVDNAV_SEEK_DONE: {
3306 printf("DVDNAV Event: Nav Seek Done\n");
3307 break;
3311 // free the dvdnav event
3312 free(dvdnav_event->details);
3313 free(dvdnav_event);
3314 cmd->args[0].v.v=NULL;
3316 case MP_CMD_DVDNAV: {
3317 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3319 /* ignore these events if we're not in dvd_nav mode */
3320 if (stream->type != STREAMTYPE_DVDNAV) break;
3322 switch (cmd->args[0].v.i) {
3323 case MP_CMD_DVDNAV_UP:
3324 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3325 break;
3326 case MP_CMD_DVDNAV_DOWN:
3327 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3328 break;
3329 case MP_CMD_DVDNAV_LEFT:
3330 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3331 break;
3332 case MP_CMD_DVDNAV_RIGHT:
3333 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3334 break;
3335 case MP_CMD_DVDNAV_MENU:
3336 printf("Menu call\n");
3337 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3338 break;
3339 case MP_CMD_DVDNAV_SELECT:
3340 dvdnav_button_activate(dvdnav_priv->dvdnav);
3341 break;
3342 default:
3343 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3344 break;
3346 break;
3348 #endif
3349 default : {
3350 #ifdef HAVE_NEW_GUI
3351 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3352 else
3353 #endif
3354 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3357 mp_cmd_free(cmd);
3361 if (seek_to_sec) {
3362 int a,b; float d;
3364 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3365 rel_seek_secs += 3600*a +60*b +d ;
3366 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3367 rel_seek_secs += 60*a +d;
3368 else if (sscanf(seek_to_sec, "%f", &d)==1)
3369 rel_seek_secs += d;
3371 seek_to_sec = NULL;
3374 /* Looping. */
3375 if(eof==1 && loop_times>=0) {
3376 int l = loop_times;
3377 play_tree_iter_step(playtree_iter,0,0);
3378 loop_times = l;
3379 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3381 if(loop_times>1) loop_times--; else
3382 if(loop_times==1) loop_times=-1;
3383 play_n_frames=play_n_frames_mf;
3384 eof=0;
3385 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3386 loop_seek = 1;
3389 if(rel_seek_secs || abs_seek_pos){
3390 current_module="seek";
3391 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3392 // success:
3393 /* FIXME there should be real seeking for vobsub */
3394 if(sh_video) sh_video->pts=d_video->pts;
3395 if (vo_vobsub)
3396 //vobsub_reset(vo_vobsub);
3397 vobsub_seek(vo_vobsub,sh_video->pts);
3398 #if 0
3399 if(sh_video && d_video->packs == 0)
3400 ds_fill_buffer(d_video);
3401 if(sh_audio){
3402 if(d_audio->packs == 0)
3403 ds_fill_buffer(d_audio);
3404 if(verbose>0){
3405 float a_pts=d_audio->pts;
3406 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3407 mp_msg(MSGT_AVSYNC,MSGL_V,"SEEK: A: %5.3f V: %5.3f A-V: %5.3f \n",a_pts,d_video->pts,a_pts-d_video->pts);
3409 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct: ? \r",d_audio->pts,d_video->pts,0.0f);
3410 } else {
3411 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3413 #endif
3414 fflush(stdout);
3416 if(sh_video){
3417 current_module="seek_video_reset";
3418 resync_video_stream(sh_video);
3419 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3422 if(sh_audio){
3423 current_module="seek_audio_reset";
3424 audio_out->reset(); // stop audio, throwing away buffered data
3426 #ifdef USE_OSD
3427 // Set OSD:
3428 if(osd_level && !loop_seek){
3429 #ifdef USE_EDL
3430 if( !edl_decision ) {
3431 #else
3432 if( 1 ) { // Let the compiler optimize this out
3433 #endif
3434 int len=((demuxer->movi_end-demuxer->movi_start)>>8);
3435 if (len>0 && sh_video){
3436 osd_visible=sh_video->fps; // 1 sec
3437 vo_osd_progbar_type=0;
3438 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
3439 vo_osd_changed(OSDTYPE_PROGBAR);
3443 #endif
3444 if(sh_video) {
3445 c_total=0;
3446 max_pts_correction=0.1;
3447 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3448 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3449 drop_frame_cnt=0;
3450 too_slow_frame_cnt=0;
3451 too_fast_frame_cnt=0;
3453 if(vo_spudec) spudec_reset(vo_spudec);
3456 #ifdef USE_EDL
3458 int x;
3459 if( !edl_decision ) {
3460 for( x = 0; x < num_edl_records; x++ ) { // FIXME: do binary search
3461 // Find first EDL entry where start follows current time
3462 if( edl_records[ x ].start_sec >= sh_video->pts && edl_records[ x ].action != EDL_MUTE ) {
3463 next_edl_record = &edl_records[ x ];
3464 break;
3467 } else {
3468 edl_decision = 0;
3471 #endif
3472 rel_seek_secs=0;
3473 abs_seek_pos=0;
3474 frame_time_remaining=0;
3475 current_module=NULL;
3476 loop_seek=0;
3479 #ifdef HAVE_NEW_GUI
3480 if(use_gui){
3481 guiEventHandling();
3482 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3483 // get pos from frame number / total frames
3484 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3485 } else {
3486 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3487 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3488 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3490 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3491 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3492 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3493 guiGetEvent( guiReDraw,NULL );
3494 guiGetEvent( guiSetVolume,NULL );
3495 if(guiIntfStruct.Playing==0) break; // STOP
3496 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3497 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3498 #ifdef USE_DVDREAD
3499 if ( stream->type == STREAMTYPE_DVD )
3501 dvd_priv_t * dvdp = stream->priv;
3502 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3504 #endif
3506 #endif
3509 //================= Update OSD ====================
3510 #ifdef USE_OSD
3511 if(osd_level>=1 && sh_video){
3512 int pts=sh_video->pts;
3513 char osd_text_tmp[64];
3514 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
3515 vo_osd_text=osd_text_buffer;
3516 #ifdef USE_DVDNAV
3517 if (osd_show_dvd_nav_delay) {
3518 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
3519 osd_show_dvd_nav_delay--;
3520 } else
3521 #endif
3522 #ifdef USE_TV
3523 if (osd_show_tv_channel && tv_channel_list) {
3524 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
3525 osd_show_tv_channel--;
3526 } else
3527 #endif
3528 if (osd_show_text) {
3529 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
3530 osd_show_text--;
3531 } else
3532 if (osd_show_sub_visibility) {
3533 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
3534 osd_show_sub_visibility--;
3535 } else
3536 if (osd_show_vobsub_changed) {
3537 const char *language = "none";
3538 if (vo_vobsub && vobsub_id >= 0)
3539 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
3540 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
3541 osd_show_vobsub_changed--;
3542 } else
3543 #ifdef USE_SUB
3544 if (osd_show_sub_changed) {
3545 char *tmp2;
3546 tmp = subdata->filename;
3547 if ((tmp2 = strrchr(tmp, '/'))) {
3548 tmp = tmp2+1;
3550 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
3551 set_of_sub_pos + 1,
3552 strlen(tmp) < 20 ? "" : "...",
3553 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
3554 osd_show_sub_changed--;
3555 } else
3556 #endif
3557 if (osd_show_sub_delay) {
3558 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
3559 osd_show_sub_delay--;
3560 } else
3561 if (osd_show_sub_pos) {
3562 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
3563 osd_show_sub_pos--;
3564 } else
3565 if (osd_show_sub_alignment) {
3566 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
3567 (sub_alignment == 2 ? "bottom" :
3568 (sub_alignment == 1 ? "center" : "top")));
3569 osd_show_sub_alignment--;
3570 } else
3571 if (osd_show_av_delay) {
3572 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
3573 osd_show_av_delay--;
3574 } else if (osd_show_ontop) {
3575 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
3576 osd_show_ontop--;
3577 } else if (osd_show_framedropping) {
3578 snprintf(osd_text_tmp, 63, "Framedropping: %s",
3579 (frame_dropping == 1 ? "on" :
3580 (frame_dropping == 2 ? "hard" : "off")));
3581 osd_show_framedropping--;
3582 } else if(osd_level>=2) {
3583 int len = demuxer_get_time_length(demuxer);
3584 int percentage = -1;
3585 char percentage_text[10];
3586 if (osd_show_percentage) {
3587 percentage = demuxer_get_percent_pos(demuxer);
3588 osd_show_percentage--;
3590 if (percentage >= 0)
3591 snprintf(percentage_text, 9, " (%d%%)", percentage);
3592 else
3593 percentage_text[0] = 0;
3594 if (osd_level == 3)
3595 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d / %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,len/3600,(len/60)%60,len%60,percentage_text);
3596 else
3597 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
3598 } else osd_text_tmp[0]=0;
3600 if(strcmp(vo_osd_text, osd_text_tmp)) {
3601 strncpy(vo_osd_text, osd_text_tmp, 63);
3602 vo_osd_changed(OSDTYPE_OSD);
3604 } else {
3605 if(vo_osd_text) {
3606 vo_osd_text=NULL;
3607 vo_osd_changed(OSDTYPE_OSD);
3610 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3611 // vo_osd_text=osd_text_buffer;
3612 #endif
3614 #ifdef USE_SUB
3615 // find sub
3616 if(subdata && sh_video->pts>0){
3617 float pts=sh_video->pts;
3618 if(sub_fps==0) sub_fps=sh_video->fps;
3619 current_module="find_sub";
3620 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
3621 find_sub(subdata, (pts+sub_delay) *
3622 (subdata->sub_uses_time ? 100. : sub_fps));
3623 // FIXME! frame counter...
3624 sub_last_pts = pts;
3626 current_module=NULL;
3628 #endif
3630 #ifdef HAVE_X11
3631 if (stop_xscreensaver && sh_video) {
3632 current_module="stop_xscreensaver";
3633 xscreensaver_heartbeat();
3634 current_module=NULL;
3636 #endif
3638 // DVD sub:
3639 if(vo_config_count && vo_spudec) {
3640 unsigned char* packet=NULL;
3641 int len,timestamp;
3642 current_module="spudec";
3643 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
3644 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3645 while(1) {
3646 // Vobsub
3647 len = 0;
3648 if(vo_vobsub) {
3649 if(sh_video->pts+sub_delay>=0) {
3650 // The + next_frame_time is there because we'll display the sub at the next frame
3651 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
3652 if(len > 0) {
3653 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
3654 mp_dbg(MSGT_CPLAYER,MSGL_V,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len,sh_video->pts,sh_video->timer,timestamp / 90000.0,timestamp);
3657 } else {
3658 // DVD sub
3659 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
3660 if(len > 0) {
3661 float x = d_dvdsub->pts - sh_video->pts;
3662 if (x < -10 || x > 10) // prevent missing subs on pts reset
3663 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
3664 else timestamp = 90000*(sh_video->timer + sub_delay);
3665 mp_dbg(MSGT_CPLAYER,MSGL_V,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f ts=%d \n",len,sh_video->pts,d_dvdsub->pts,timestamp);
3668 if(len<=0 || !packet) break;
3669 if(timestamp < 0) timestamp = 0;
3670 else spudec_assemble(vo_spudec,packet,len,timestamp);
3673 /* detect wether the sub has changed or not */
3674 if(spudec_changed(vo_spudec))
3675 vo_osd_changed(OSDTYPE_SPU);
3676 current_module=NULL;
3679 } // while(!eof)
3681 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
3685 goto_next_file: // don't jump here after ao/vo/getch initialization!
3687 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3689 if(benchmark){
3690 double tot=video_time_usage+vout_time_usage+audio_time_usage;
3691 double total_time_usage;
3692 total_time_usage_start=GetTimer()-total_time_usage_start;
3693 total_time_usage = (float)total_time_usage_start*0.000001;
3694 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3695 video_time_usage,vout_time_usage,audio_time_usage,
3696 total_time_usage-tot,total_time_usage);
3697 if(total_time_usage>0.0)
3698 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3699 100.0*video_time_usage/total_time_usage,
3700 100.0*vout_time_usage/total_time_usage,
3701 100.0*audio_time_usage/total_time_usage,
3702 100.0*(total_time_usage-tot)/total_time_usage,
3703 100.0);
3704 if(total_frame_cnt && frame_dropping)
3705 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3706 total_frame_cnt-drop_frame_cnt,
3707 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
3708 drop_frame_cnt,
3709 100*drop_frame_cnt/total_frame_cnt,
3710 total_frame_cnt,
3711 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
3715 // time to uninit all, except global stuff:
3716 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
3718 #ifdef USE_SUB
3719 if ( set_of_sub_size > 0 )
3721 current_module="sub_free";
3722 for (i = 0; i < set_of_sub_size; ++i)
3723 sub_free( set_of_subtitles[i] );
3724 set_of_sub_size = 0;
3725 vo_sub=NULL;
3726 subdata=NULL;
3728 #endif
3730 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
3731 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
3732 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
3733 eof = 1;
3734 } else {
3735 play_tree_iter_free(playtree_iter);
3736 playtree_iter = NULL;
3738 play_tree_step = 1;
3739 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
3740 eof = eof == PT_UP_NEXT ? 1 : -1;
3741 if ( playtree_iter ) {
3742 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
3743 eof = 1;
3744 } else {
3745 play_tree_iter_free(playtree_iter);
3746 playtree_iter = NULL;
3749 } else { // NEXT PREV SRC
3750 eof = eof == PT_PREV_SRC ? -1 : 1;
3753 if(eof == 0) eof = 1;
3755 while(playtree_iter != NULL) {
3756 filename = play_tree_iter_get_file(playtree_iter,eof);
3757 if(filename == NULL) {
3758 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
3759 play_tree_iter_free(playtree_iter);
3760 playtree_iter = NULL;
3762 } else
3763 break;
3766 #ifdef HAVE_NEW_GUI
3767 if( use_gui && !playtree_iter )
3769 #ifdef USE_DVDREAD
3770 if ( !guiIntfStruct.DiskChanged )
3771 #endif
3772 mplEnd();
3774 #endif
3776 if(use_gui || playtree_iter != NULL){
3778 eof = 0;
3779 goto play_next_file;
3782 #ifdef HAVE_FREETYPE
3783 current_module="uninit_font";
3784 if (vo_font) free_font_desc(vo_font);
3785 vo_font = NULL;
3786 done_freetype();
3787 #endif
3789 exit_player_with_rc(MSGTR_Exit_eof, 0);
3791 return 1;