synced with 1.11
[mplayer/greg.git] / mplayer.c
blobccb3330ad2246bbe912e17f59896c85a71b21580
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 #define SIGPIPE 13 /* broken pipe */
23 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
24 #endif
26 #include <sys/time.h>
27 #include <sys/stat.h>
29 #include <signal.h>
30 #include <time.h>
31 #include <fcntl.h>
32 #include <limits.h>
34 #include <errno.h>
36 #include "version.h"
38 #include "mp_msg.h"
40 #define HELP_MP_DEFINE_STATIC
41 #include "help_mp.h"
43 #include "m_option.h"
44 #include "m_config.h"
46 #include "cfg-mplayer-def.h"
48 #ifdef USE_SUB
49 #include "subreader.h"
50 #endif
52 #include "libvo/video_out.h"
54 #include "libvo/font_load.h"
55 #include "libvo/sub.h"
57 #ifdef HAVE_X11
58 #include "libvo/x11_common.h"
59 #endif
61 #include "libao2/audio_out.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 #ifdef WIN32
93 char * proc_priority=NULL;
94 #endif
96 #define ABS(x) (((x)>=0)?(x):(-(x)))
97 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
99 #ifdef HAVE_RTC
100 #ifdef __linux__
101 #include <linux/rtc.h>
102 #else
103 #include <rtc.h>
104 #define RTC_IRQP_SET RTCIO_IRQP_SET
105 #define RTC_PIE_ON RTCIO_PIE_ON
106 #endif
107 #endif
109 #ifdef USE_TV
110 #include "libmpdemux/tv.h"
111 #endif
113 #ifdef HAS_DVBIN_SUPPORT
114 #include "libmpdemux/dvbin.h"
115 static int last_dvb_step = 1;
116 #endif
118 //**************************************************************************//
119 // Playtree
120 //**************************************************************************//
121 #include "playtree.h"
122 #include "playtreeparser.h"
124 #ifdef HAVE_NEW_GUI
125 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
126 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
127 #endif
129 play_tree_t* playtree;
130 play_tree_iter_t* playtree_iter = NULL;
132 #define PT_NEXT_ENTRY 1
133 #define PT_PREV_ENTRY -1
134 #define PT_NEXT_SRC 2
135 #define PT_PREV_SRC -2
136 #define PT_UP_NEXT 3
137 #define PT_UP_PREV -3
139 //**************************************************************************//
140 // Config
141 //**************************************************************************//
142 m_config_t* mconfig;
144 extern play_tree_t*
145 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
146 extern int
147 m_config_parse_config_file(m_config_t* config, char *conffile);
149 //**************************************************************************//
150 // Config file
151 //**************************************************************************//
153 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
155 static int cfg_include(m_option_t *conf, char *filename){
156 return m_config_parse_config_file(mconfig, filename);
159 #include "get_path.c"
161 //**************************************************************************//
162 // XScreensaver
163 //**************************************************************************//
165 #ifdef HAVE_X11
166 void xscreensaver_heartbeat(void);
167 #endif
169 //**************************************************************************//
170 //**************************************************************************//
171 // Input media streaming & demultiplexer:
172 //**************************************************************************//
174 static int max_framesize=0;
176 #include "libmpdemux/stream.h"
177 #include "libmpdemux/demuxer.h"
178 #include "libmpdemux/stheader.h"
179 //#include "parse_es.h"
180 #ifdef HAVE_MATROSKA
181 #include "libmpdemux/matroska.h"
182 #endif
184 #include "libmpcodecs/dec_audio.h"
185 #include "libmpcodecs/dec_video.h"
186 #include "libmpcodecs/mp_image.h"
187 #include "libmpcodecs/vf.h"
189 extern void vf_list_plugins();
191 //**************************************************************************//
192 //**************************************************************************//
194 // Common FIFO functions, and keyboard/event FIFO code
195 #include "fifo.c"
196 int noconsolecontrols=0;
197 //**************************************************************************//
199 vo_functions_t *video_out=NULL;
200 ao_functions_t *audio_out=NULL;
202 int fixed_vo=0;
203 int eof=0;
205 // benchmark:
206 double video_time_usage=0;
207 double vout_time_usage=0;
208 static double audio_time_usage=0;
209 static int total_time_usage_start=0;
210 static int total_frame_cnt=0;
211 static int drop_frame_cnt=0; // total number of dropped frames
212 int benchmark=0;
214 // options:
215 int auto_quality=0;
216 static int output_quality=0;
218 float playback_speed=1.0;
220 int use_gui=0;
222 #ifdef HAVE_NEW_GUI
223 int enqueue=0;
224 #endif
226 #define MAX_OSD_LEVEL 3
228 int osd_level=1;
229 int osd_level_saved=-1;
230 int osd_visible=100;
232 // seek:
233 static char *seek_to_sec=NULL;
234 static off_t seek_to_byte=0;
235 static off_t step_sec=0;
236 static int loop_times=-1;
237 static int loop_seek=0;
239 // A/V sync:
240 int autosync=0; // 30 might be a good default value.
242 // may be changed by GUI: (FIXME!)
243 float rel_seek_secs=0;
244 int abs_seek_pos=0;
246 // codecs:
247 char **audio_codec_list=NULL; // override audio codec
248 char **video_codec_list=NULL; // override video codec
249 char **audio_fm_list=NULL; // override audio codec family
250 char **video_fm_list=NULL; // override video codec family
252 // demuxer:
253 extern char *demuxer_name; // override demuxer
254 extern char *audio_demuxer_name; // override audio demuxer
255 extern char *sub_demuxer_name; // override sub demuxer
257 // streaming:
258 int audio_id=-1;
259 int video_id=-1;
260 int dvdsub_id=-1;
261 int vobsub_id=-1;
262 char* audio_lang=NULL;
263 char* dvdsub_lang=NULL;
264 static char* spudec_ifo=NULL;
265 char* filename=NULL; //"MI2-Trailer.avi";
266 int forced_subs_only=0;
268 // cache2:
269 int stream_cache_size=-1;
270 #ifdef USE_STREAM_CACHE
271 extern int cache_fill_status;
273 float stream_cache_min_percent=20.0;
274 float stream_cache_seek_min_percent=50.0;
275 #else
276 #define cache_fill_status 0
277 #endif
279 // dump:
280 static char *stream_dump_name="stream.dump";
281 int stream_dump_type=0;
283 // A-V sync:
284 static float default_max_pts_correction=-1;//0.01f;
285 static float max_pts_correction=0;//default_max_pts_correction;
286 static float c_total=0;
287 float audio_delay=0;
289 static int softsleep=0;
291 float force_fps=0;
292 static int force_srate=0;
293 static int audio_output_format=0;
294 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
295 static int play_n_frames=-1;
296 static int play_n_frames_mf=-1;
298 // screen info:
299 char** video_driver_list=NULL;
300 char** audio_driver_list=NULL;
302 extern char *vo_subdevice;
303 extern char *ao_subdevice;
305 // codec outfmt flags (defined in libmpcodecs/vd.c)
306 extern int vo_flags;
308 // sub:
309 char *font_name=NULL;
310 #ifdef HAVE_FONTCONFIG
311 extern int font_fontconfig;
312 #endif
313 float font_factor=0.75;
314 char **sub_name=NULL;
315 float sub_delay=0;
316 float sub_fps=0;
317 int sub_auto = 1;
318 char *vobsub_name=NULL;
319 /*DSP!!char *dsp=NULL;*/
320 int subcc_enabled=0;
321 int suboverlap_enabled = 1;
322 #ifdef USE_SUB
323 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
324 int set_of_sub_size = 0;
325 int set_of_sub_pos = -1;
326 float sub_last_pts = -303;
327 #endif
328 int global_sub_size = 0; // this encompasses all subtitle sources
329 int global_sub_pos = -1; // this encompasses all subtitle sources
330 #define SUB_SOURCE_SUBS 0
331 #define SUB_SOURCE_VOBSUB 1
332 #define SUB_SOURCE_DEMUX 2
333 #define SUB_SOURCES 3
334 int global_sub_indices[SUB_SOURCES];
335 int global_sub_quiet_osd_hack = 0;
337 static stream_t* stream=NULL;
338 static demuxer_t *demuxer=NULL;
339 static sh_audio_t *sh_audio=NULL;
340 static sh_video_t *sh_video=NULL;
342 char* current_module=NULL; // for debugging
344 extern int vo_gamma_gamma;
345 extern int vo_gamma_brightness;
346 extern int vo_gamma_contrast;
347 extern int vo_gamma_saturation;
348 extern int vo_gamma_hue;
350 // ---
352 #ifdef HAVE_MENU
353 #include "m_struct.h"
354 #include "libmenu/menu.h"
355 extern void vf_menu_pause_update(struct vf_instance_s* vf);
356 extern vf_info_t vf_info_menu;
357 static vf_info_t* libmenu_vfs[] = {
358 &vf_info_menu,
359 NULL
361 static vf_instance_t* vf_menu = NULL;
362 static int use_menu = 0;
363 static char* menu_cfg = NULL;
364 static char* menu_root = "main";
365 #endif
368 #ifdef HAVE_RTC
369 static int nortc;
370 static char* rtc_device;
371 #endif
373 #ifdef USE_EDL
374 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
375 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
376 short user_muted = 0; ///< Stores whether User wanted muted mode.
377 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
378 short edl_decision = 0; ///< 1 when an EDL operation has been made
379 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode
380 #endif
382 static unsigned int inited_flags=0;
383 #define INITED_VO 1
384 #define INITED_AO 2
385 #define INITED_GUI 4
386 #define INITED_GETCH2 8
387 #define INITED_SPUDEC 32
388 #define INITED_STREAM 64
389 #define INITED_INPUT 128
390 #define INITED_VOBSUB 256
391 #define INITED_DEMUXER 512
392 #define INITED_ACODEC 1024
393 #define INITED_VCODEC 2048
394 #define INITED_ALL 0xFFFF
396 static void uninit_player(unsigned int mask){
397 mask=inited_flags&mask;
399 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
401 if(mask&INITED_ACODEC){
402 inited_flags&=~INITED_ACODEC;
403 current_module="uninit_acodec";
404 if(sh_audio) uninit_audio(sh_audio);
405 #ifdef HAVE_NEW_GUI
406 guiGetEvent(guiSetAfilter, (char *)NULL);
407 #endif
408 sh_audio=NULL;
411 if(mask&INITED_VCODEC){
412 inited_flags&=~INITED_VCODEC;
413 current_module="uninit_vcodec";
414 if(sh_video) uninit_video(sh_video);
415 sh_video=NULL;
416 #ifdef HAVE_MENU
417 vf_menu=NULL;
418 #endif
421 if(mask&INITED_DEMUXER){
422 inited_flags&=~INITED_DEMUXER;
423 current_module="free_demuxer";
424 if(demuxer){
425 stream=demuxer->stream;
426 free_demuxer(demuxer);
428 demuxer=NULL;
431 // kill the cache process:
432 if(mask&INITED_STREAM){
433 inited_flags&=~INITED_STREAM;
434 current_module="uninit_stream";
435 if(stream) free_stream(stream);
436 stream=NULL;
439 if(mask&INITED_VO){
440 inited_flags&=~INITED_VO;
441 current_module="uninit_vo";
442 video_out->uninit();
443 video_out=NULL;
446 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
447 if(mask&INITED_GETCH2){
448 inited_flags&=~INITED_GETCH2;
449 current_module="uninit_getch2";
450 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
451 // restore terminal:
452 getch2_disable();
455 if(mask&INITED_VOBSUB){
456 inited_flags&=~INITED_VOBSUB;
457 current_module="uninit_vobsub";
458 if(vo_vobsub) vobsub_close(vo_vobsub);
459 vo_vobsub=NULL;
462 if (mask&INITED_SPUDEC){
463 inited_flags&=~INITED_SPUDEC;
464 current_module="uninit_spudec";
465 spudec_free(vo_spudec);
466 vo_spudec=NULL;
469 if(mask&INITED_AO){
470 inited_flags&=~INITED_AO;
471 current_module="uninit_ao";
472 audio_out->uninit(eof?0:1); audio_out=NULL;
475 #ifdef HAVE_NEW_GUI
476 if(mask&INITED_GUI){
477 inited_flags&=~INITED_GUI;
478 current_module="uninit_gui";
479 guiDone();
481 #endif
483 if(mask&INITED_INPUT){
484 inited_flags&=~INITED_INPUT;
485 current_module="uninit_input";
486 mp_input_uninit();
489 current_module=NULL;
492 static void exit_player_with_rc(char* how, int rc){
494 uninit_player(INITED_ALL);
495 #ifdef HAVE_X11
496 #ifdef HAVE_NEW_GUI
497 if ( !use_gui )
498 #endif
499 vo_uninit(); // close the X11 connection (if any opened)
500 #endif
502 #ifdef HAVE_FREETYPE
503 current_module="uninit_font";
504 if (vo_font) free_font_desc(vo_font);
505 vo_font = NULL;
506 done_freetype();
507 #endif
508 free_osd_list();
510 current_module="exit_player";
512 // free mplayer config
513 if(mconfig)
514 m_config_free(mconfig);
516 if(playtree)
517 play_tree_free(playtree, 1);
520 #ifdef USE_EDL
521 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
522 #endif
523 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));
524 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
526 exit(rc);
529 void exit_player(char* how){
530 exit_player_with_rc(how, 1);
533 #ifndef __MINGW32__
534 static void child_sighandler(int x){
535 pid_t pid;
536 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
538 #endif
540 #ifdef CRASH_DEBUG
541 static char *prog_path;
542 static int crash_debug = 0;
543 #endif
545 static void exit_sighandler(int x){
546 static int sig_count=0;
547 #ifdef CRASH_DEBUG
548 if (!crash_debug || x != SIGTRAP)
549 #endif
550 ++sig_count;
551 if(inited_flags==0 && sig_count>1) exit(1);
552 if(sig_count==5)
554 /* We're crashing bad and can't uninit cleanly :(
555 * by popular request, we make one last (dirty)
556 * effort to restore the user's
557 * terminal. */
558 getch2_disable();
559 exit(1);
561 if(sig_count==6) exit(1);
562 if(sig_count>6){
563 // can't stop :(
564 #ifndef __MINGW32__
565 kill(getpid(),SIGKILL);
566 #endif
568 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
569 current_module?current_module:mp_gettext("unknown")
571 if(sig_count<=1)
572 switch(x){
573 case SIGINT:
574 case SIGQUIT:
575 case SIGTERM:
576 case SIGKILL:
577 break; // killed from keyboard (^C) or killed [-9]
578 case SIGILL:
579 #ifdef RUNTIME_CPUDETECT
580 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
581 #else
582 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
583 #endif
584 case SIGFPE:
585 case SIGSEGV:
586 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
587 default:
588 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
589 #ifdef CRASH_DEBUG
590 if (crash_debug) {
591 int gdb_pid;
592 char spid[20];
593 snprintf(spid, 19, "%i", getpid());
594 spid[19] = 0;
595 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
596 gdb_pid = fork();
597 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
598 if (gdb_pid == 0) { // We are the child
599 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
600 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
601 } else if (gdb_pid < 0)
602 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
603 else {
604 waitpid(gdb_pid, NULL, 0);
606 if (x == SIGTRAP) return;
608 #endif
610 exit_player(NULL);
613 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
615 extern void mp_input_register_options(m_config_t* cfg);
617 #include "mixer.h"
618 mixer_t mixer;
619 /// step size of mixer changes
620 int volstep = 3;
622 #include "cfg-mplayer.h"
624 void parse_cfgfiles( m_config_t* conf )
626 char *conffile;
627 int conffile_fd;
628 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
629 exit_player(NULL);
630 if ((conffile = get_path("")) == NULL) {
631 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
632 } else {
633 #ifdef __MINGW32__
634 mkdir(conffile);
635 #else
636 mkdir(conffile, 0777);
637 #endif
638 free(conffile);
639 if ((conffile = get_path("config")) == NULL) {
640 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
641 } else {
642 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
643 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
644 write(conffile_fd, default_config, strlen(default_config));
645 close(conffile_fd);
647 if (m_config_parse_config_file(conf, conffile) < 0)
648 exit_player(NULL);
649 free(conffile);
654 void load_per_file_config (m_config_t* conf, const char *const file)
656 char *confpath;
657 char cfg[strlen(file)+10];
658 struct stat st;
659 char *name;
661 sprintf (cfg, "%s.conf", file);
663 if (!stat (cfg, &st))
665 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
666 m_config_parse_config_file (conf, cfg);
667 return;
670 if ((name = strrchr (cfg, '/')) == NULL)
671 name = cfg;
672 else
673 name++;
675 if ((confpath = get_path (name)) != NULL)
677 if (!stat (confpath, &st))
679 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
680 m_config_parse_config_file (conf, confpath);
683 free (confpath);
687 // When libmpdemux perform a blocking operation (network connection or cache filling)
688 // if the operation fail we use this function to check if it was interrupted by the user.
689 // The function return a new value for eof.
690 static int libmpdemux_was_interrupted(int eof) {
691 mp_cmd_t* cmd;
692 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
693 switch(cmd->id) {
694 case MP_CMD_QUIT:
695 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
696 case MP_CMD_PLAY_TREE_STEP: {
697 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
698 } break;
699 case MP_CMD_PLAY_TREE_UP_STEP: {
700 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
701 } break;
702 case MP_CMD_PLAY_ALT_SRC_STEP: {
703 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
704 } break;
706 mp_cmd_free(cmd);
708 return eof;
711 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
712 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
714 int playtree_add_playlist(play_tree_t* entry)
716 play_tree_add_bpf(entry,filename);
718 #ifdef HAVE_NEW_GUI
719 if (use_gui) {
720 if (entry) {
721 import_playtree_playlist_into_gui(entry, mconfig);
722 play_tree_free_list(entry,1);
724 } else
725 #endif
727 if(!entry) {
728 entry = playtree_iter->tree;
729 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
730 return PT_NEXT_ENTRY;
732 if(playtree_iter->tree == entry ) { // Loop with a single file
733 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
734 return PT_NEXT_ENTRY;
737 play_tree_remove(entry,1,1);
738 return PT_NEXT_SRC;
740 play_tree_insert_entry(playtree_iter->tree,entry);
741 play_tree_set_params_from(entry,playtree_iter->tree);
742 entry = playtree_iter->tree;
743 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
744 return PT_NEXT_ENTRY;
746 play_tree_remove(entry,1,1);
748 return PT_NEXT_SRC;
751 static int play_tree_step = 1;
753 int sub_source()
755 int source = -1;
756 int top = -1;
757 int i;
758 for (i = 0; i < SUB_SOURCES; i++) {
759 int j = global_sub_indices[i];
760 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
761 source = i;
762 top = j;
765 return source;
768 #ifdef USE_SUB
770 sub_data* subdata = NULL;
771 static subtitle* vo_sub_last = NULL;
773 void add_subtitles(char *filename, float fps, int silent)
775 sub_data *subd;
777 if (filename == NULL) {
778 return;
781 subd = sub_read_file(filename, fps);
782 if(!subd && !silent)
783 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
784 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
785 set_of_subtitles[set_of_sub_size] = subd;
786 if (identify)
788 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
789 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
791 ++set_of_sub_size;
792 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
795 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
796 void update_set_of_subtitles()
797 // subdata was changed, set_of_sub... have to be updated.
799 int i;
800 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
801 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
802 set_of_subtitles[i-1] = set_of_subtitles[i];
803 set_of_subtitles[set_of_sub_size-1] = NULL;
804 --set_of_sub_size;
805 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
807 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
808 set_of_subtitles[set_of_sub_pos] = subdata;
810 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
811 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
812 ++set_of_sub_size;
815 #endif
818 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
819 * make it all work is to use the builtin SDL-bootstrap code, which
820 * will be done automatically by replacing our main() if we include SDL.h.
822 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
823 #include <SDL.h>
824 #endif
827 * \brief append a formatted string
828 * \param buf buffer to print into
829 * \param pos position of terminating 0 in buf
830 * \param len maximum number of characters in buf, not including terminating 0
831 * \param format printf format string
833 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
835 va_list va;
836 va_start(va, format);
837 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
838 va_end(va);
839 if (*pos >= len ) {
840 buf[len] = 0;
841 *pos = len;
846 * \brief print the status line
847 * \param a_pos audio position
848 * \param a_v A-V desynchronization
849 * \param corr amount out A-V synchronization
851 static void print_status(float a_pos, float a_v, float corr)
853 int width;
854 char *line;
855 unsigned pos = 0;
856 get_screen_size();
857 if (screen_width > 0)
858 width = screen_width;
859 else
860 width = 80;
861 #ifdef WIN32
862 // windows command line is broken (MinGW's rxvt works though, but we
863 // should not depend on that).
864 width--;
865 #endif
866 line = malloc(width + 1); // one additional for terminating null
868 // Audio time
869 if (sh_audio) {
870 saddf(line, &pos, width, "A:%6.1f ", a_pos);
871 if (!sh_video) {
872 // convert time to HH:MM:SS.F format
873 long tenths = 10 * a_pos;
874 int f1 = tenths % 10;
875 int ss = (tenths / 10) % 60;
876 int mm = (tenths / 600) % 60;
877 int hh = (tenths / 36000) % 100;
878 saddf(line, &pos, width, "(");
879 if (hh > 0)
880 saddf(line, &pos, width, "%2d:", hh);
881 if (hh > 0 || mm > 0)
882 saddf(line, &pos, width, "%02d:", mm);
883 saddf(line, &pos, width, "%02d.", ss);
884 saddf(line, &pos, width, "%1d", f1);
885 saddf(line, &pos, width, ") ");
889 // Video time
890 if (sh_video)
891 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
893 // A-V sync
894 if (sh_audio && sh_video)
895 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
897 // Video stats
898 if (sh_video)
899 saddf(line, &pos, width, "%3d/%3d ",
900 (int)sh_video->num_frames,
901 (int)sh_video->num_frames_decoded);
903 // CPU usage
904 if (sh_video) {
905 if (sh_video->timer > 0.5)
906 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
907 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
908 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
909 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
910 else
911 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
912 } else if (sh_audio) {
913 if (sh_audio->delay > 0.5)
914 saddf(line, &pos, width, "%4.1f%% ",
915 100.0*audio_time_usage/(double)sh_audio->delay);
916 else
917 saddf(line, &pos, width, "??,?%% ");
920 // VO stats
921 if (sh_video)
922 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
924 #ifdef USE_STREAM_CACHE
925 // cache stats
926 if (stream_cache_size > 0)
927 saddf(line, &pos, width, "%d%% ", cache_fill_status);
928 #endif
930 // other
931 if (playback_speed != 1)
932 saddf(line, &pos, width, "%4.2fx ", playback_speed);
934 // end
935 memset(&line[pos], ' ', width - pos);
936 line[width] = 0;
937 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
938 free(line);
942 * \brief build a chain of audio filters that converts the input format
943 * to the ao's format, taking into account the current playback_speed.
944 * \param sh_audio describes the requested input format of the chain.
945 * \param ao_data describes the requested output format of the chain.
947 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
949 int new_srate;
950 int result;
951 if (!sh_audio)
953 #ifdef HAVE_NEW_GUI
954 guiGetEvent(guiSetAfilter, (char *)NULL);
955 #endif
956 mixer.afilter = NULL;
957 return 0;
959 new_srate = sh_audio->samplerate * playback_speed;
960 if (new_srate != ao_data->samplerate) {
961 // limits are taken from libaf/af_resample.c
962 if (new_srate < 8000)
963 new_srate = 8000;
964 if (new_srate > 192000)
965 new_srate = 192000;
966 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
968 result = init_audio_filters(sh_audio, new_srate,
969 sh_audio->channels, sh_audio->sample_format,
970 &ao_data->samplerate, &ao_data->channels, &ao_data->format,
971 ao_data->outburst * 4, ao_data->buffersize);
972 mixer.afilter = sh_audio->afilter;
973 #ifdef HAVE_NEW_GUI
974 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter);
975 #endif
976 return result;
979 #ifdef USE_SUB
981 * \brief Log the currently displayed subtitle to a file
983 * Logs the current or last displayed subtitle together with filename
984 * and time information to ~/.mplayer/subtitle_log
986 * Intended purpose is to allow convenient marking of bogus subtitles
987 * which need to be fixed while watching the movie.
990 static void log_sub(){
991 char *fname;
992 FILE *f;
993 int i;
995 if (subdata == NULL || vo_sub_last == NULL) return;
996 fname = get_path("subtitle_log");
997 f = fopen(fname, "a");
998 if (!f) return;
999 fprintf(f, "----------------------------------------------------------\n");
1000 if (subdata->sub_uses_time) {
1001 fprintf(f, "N: %s S: %02d:%02d:%02d.%02d E: %02d:%02d:%02d.%02d\n", filename,
1002 vo_sub_last->start/360000, (vo_sub_last->start/6000)%60,
1003 (vo_sub_last->start/100)%60, vo_sub_last->start%100,
1004 vo_sub_last->end/360000, (vo_sub_last->end/6000)%60,
1005 (vo_sub_last->end/100)%60, vo_sub_last->end%100);
1006 } else {
1007 fprintf(f, "N: %s S: %d E: %d\n", filename, vo_sub_last->start, vo_sub_last->end);
1009 for (i = 0; i < vo_sub_last->lines; i++) {
1010 fprintf(f, "%s\n", vo_sub_last->text[i]);
1012 fclose(f);
1014 #endif
1016 int main(int argc,char* argv[]){
1019 char * mem_ptr;
1021 static demux_stream_t *d_audio=NULL;
1022 static demux_stream_t *d_video=NULL;
1023 static demux_stream_t *d_dvdsub=NULL;
1025 int file_format=DEMUXER_TYPE_UNKNOWN;
1027 int delay_corrected=1;
1029 // movie info:
1031 int osd_function=OSD_PLAY;
1032 int osd_last_pts=-303;
1033 int osd_show_av_delay = 0;
1034 int osd_show_text = 0;
1035 int osd_show_speed = 0;
1036 int osd_show_sub_delay = 0;
1037 int osd_show_sub_pos = 0;
1038 int osd_show_sub_visibility = 0;
1039 int osd_show_sub_alignment = 0;
1040 int osd_show_vobsub_changed = 0;
1041 int osd_show_sub_changed = 0;
1042 int osd_show_percentage = 0;
1043 int osd_show_tv_channel = 25;
1044 int osd_show_ontop = 0;
1045 int osd_show_rootwin = 0;
1046 int osd_show_framedropping = 0;
1047 int osd_show_status = 0;
1049 int rtc_fd=-1;
1051 //float a_frame=0; // Audio
1053 int i;
1054 char *tmp;
1056 int gui_no_filename=0;
1059 srand((int) time(NULL));
1061 InitTimer();
1063 mp_msg_init();
1064 mp_msg_set_level(MSGL_STATUS);
1066 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2005 MPlayer Team\n");
1067 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
1068 GetCpuCaps(&gCpuCaps);
1069 #if defined(ARCH_X86) || defined(ARCH_X86_64)
1070 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
1071 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
1072 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
1073 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
1074 #ifdef RUNTIME_CPUDETECT
1075 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
1076 #else
1077 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
1078 #ifdef HAVE_MMX
1079 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
1080 #endif
1081 #ifdef HAVE_MMX2
1082 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
1083 #endif
1084 #ifdef HAVE_3DNOW
1085 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
1086 #endif
1087 #ifdef HAVE_3DNOWEX
1088 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
1089 #endif
1090 #ifdef HAVE_SSE
1091 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
1092 #endif
1093 #ifdef HAVE_SSE2
1094 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
1095 #endif
1096 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
1097 #endif
1098 #endif
1100 #if defined(WIN32) && defined(USE_WIN32DLL)
1101 { /*make our codec dirs available for LoadLibraryA()*/
1102 char tmppath[MAX_PATH*2 + 1];
1103 char win32path[MAX_PATH];
1104 char realpath[MAX_PATH];
1105 #ifdef __CYGWIN__
1106 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
1107 strcpy(tmppath,win32path);
1108 #ifdef USE_REALCODECS
1109 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
1110 sprintf(tmppath,"%s;%s",win32path,realpath);
1111 #endif /*USE_REALCODECS*/
1112 #else
1113 if(!strstr(WIN32_PATH,":")){
1114 GetModuleFileNameA(NULL, win32path, MAX_PATH);
1115 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
1117 else strcpy(win32path,WIN32_PATH);
1118 strcpy(tmppath,win32path);
1119 #ifdef USE_REALCODECS
1120 if(!strstr(REALCODEC_PATH,":")){
1121 GetModuleFileNameA(NULL, realpath, MAX_PATH);
1122 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
1124 else strcpy(realpath,REALCODEC_PATH);
1125 sprintf(tmppath,"%s;%s",win32path,realpath);
1126 #endif /*USE_REALCODECS*/
1127 #endif /*__CYGWIN__*/
1128 SetEnvironmentVariableA("PATH", tmppath);
1130 #endif /*WIN32 && USE_WIN32DLL*/
1132 #ifdef USE_TV
1133 tv_param_immediate = 1;
1134 #endif
1136 if ( argv[0] )
1137 if(!strcmp(argv[0],"gmplayer") ||
1138 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
1139 use_gui=1;
1141 mconfig = m_config_new();
1142 m_config_register_options(mconfig,mplayer_opts);
1143 // TODO : add something to let modules register their options
1144 mp_input_register_options(mconfig);
1145 parse_cfgfiles(mconfig);
1147 #ifdef HAVE_NEW_GUI
1148 if ( use_gui ) cfg_read();
1149 #endif
1151 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
1152 if(playtree == NULL)
1153 exit_player(NULL);
1155 playtree = play_tree_cleanup(playtree);
1156 if(playtree) {
1157 playtree_iter = play_tree_iter_new(playtree,mconfig);
1158 if(playtree_iter) {
1159 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
1160 play_tree_iter_free(playtree_iter);
1161 playtree_iter = NULL;
1163 filename = play_tree_iter_get_file(playtree_iter,1);
1167 #ifdef WIN32
1168 if(proc_priority){
1169 int i;
1170 for(i=0; priority_presets_defs[i].name; i++){
1171 if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
1172 break;
1174 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",
1175 priority_presets_defs[i].name);
1176 SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
1178 #endif
1179 #ifndef HAVE_NEW_GUI
1180 if(use_gui){
1181 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
1182 use_gui=0;
1184 #else
1185 if(use_gui && !vo_init()){
1186 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
1187 use_gui=0;
1189 if (use_gui && playtree_iter){
1190 char cwd[PATH_MAX+2];
1191 // Remove Playtree and Playtree-Iter from memory as its not used by gui
1192 play_tree_iter_free(playtree_iter);
1193 playtree_iter=NULL;
1195 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
1197 strcat(cwd, "/");
1198 // Prefix relative paths with current working directory
1199 play_tree_add_bpf(playtree, cwd);
1201 // Import initital playtree into gui
1202 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
1204 #endif
1206 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
1207 list_video_out();
1208 exit_player_with_rc(NULL, 0);
1211 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
1212 list_audio_out();
1213 exit_player_with_rc(NULL, 0);
1216 // check codec.conf
1217 if(!codecs_file || !parse_codec_cfg(codecs_file)){
1218 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
1219 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
1220 if(!parse_codec_cfg(NULL)){
1221 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
1222 exit_player_with_rc(NULL, 0);
1224 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
1227 free( mem_ptr ); // release the buffer created by get_path()
1230 #if 0
1231 if(video_codec_list){
1232 int i;
1233 video_codec=video_codec_list[0];
1234 for(i=0;video_codec_list[i];i++)
1235 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
1237 #endif
1238 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
1239 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
1240 if (identify)
1241 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_CODECS\n");
1242 list_codecs(1);
1243 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1244 exit_player_with_rc(NULL, 0);
1246 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
1247 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
1248 if (identify)
1249 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VIDEO_CODECS\n");
1250 list_codecs(0);
1251 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1252 exit_player_with_rc(NULL, 0);
1254 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
1255 vfm_help();
1256 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1257 exit_player_with_rc(NULL, 0);
1259 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
1260 afm_help();
1261 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1262 exit_player_with_rc(NULL, 0);
1264 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
1265 af_help();
1266 printf("\n");
1267 exit_player_with_rc(NULL, 0);
1269 #ifdef HAVE_X11
1270 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
1271 fstype_help();
1272 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1273 exit_player_with_rc(NULL, 0);
1275 #endif
1276 if((demuxer_name && strcmp(demuxer_name,"help")==0) ||
1277 (audio_demuxer_name && strcmp(audio_demuxer_name,"help")==0) ||
1278 (sub_demuxer_name && strcmp(sub_demuxer_name,"help")==0)){
1279 demuxer_help();
1280 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
1281 exit_player_with_rc(NULL, 0);
1284 #ifdef USE_EDL
1285 if (edl_check_mode() == EDL_ERROR && edl_filename)
1287 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantUseBothModes);
1288 exit_player(NULL);
1289 } else if (edl_filename)
1291 if (edl_records) free_edl(edl_records);
1292 next_edl_record = edl_records = edl_parse_file();
1293 } else if (edl_output_filename)
1295 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
1297 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
1298 edl_output_filename);
1299 exit_player(NULL);
1302 #endif
1304 if(!filename){
1305 if(!use_gui){
1306 // no file/vcd/dvd -> show HELP:
1307 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1308 exit_player_with_rc(NULL, 0);
1309 } else gui_no_filename=1;
1312 // Many users forget to include command line in bugreports...
1313 if(verbose>0){
1314 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
1315 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);
1316 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
1319 mp_msg_set_level(verbose+MSGL_STATUS);
1321 //------ load global data first ------
1323 // check font
1324 #ifdef USE_OSD
1325 #ifdef HAVE_FREETYPE
1326 init_freetype();
1327 #endif
1328 #ifdef HAVE_FONTCONFIG
1329 if(!font_fontconfig)
1331 #endif
1332 if(font_name){
1333 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1334 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1335 } else {
1336 // try default:
1337 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
1338 free(mem_ptr); // release the buffer created by get_path()
1339 if(!vo_font)
1340 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1342 #ifdef HAVE_FONTCONFIG
1344 #endif
1345 #endif
1346 vo_init_osd();
1348 #ifdef HAVE_RTC
1349 if(!nortc)
1351 // seteuid(0); /* Can't hurt to try to get root here */
1352 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
1353 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
1354 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
1355 else {
1356 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1358 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1359 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
1360 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
1361 close (rtc_fd);
1362 rtc_fd = -1;
1363 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1364 /* variable only by the root */
1365 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
1366 close (rtc_fd);
1367 rtc_fd = -1;
1368 } else
1369 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
1372 #ifdef HAVE_NEW_GUI
1373 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1374 // and now ? -- Pontscho
1375 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1376 #endif
1377 if(rtc_fd<0)
1378 #endif
1379 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
1380 softsleep?"software":timer_name);
1382 #ifdef USE_TERMCAP
1383 if ( !use_gui ) load_termcap(NULL); // load key-codes
1384 #endif
1386 // ========== Init keyboard FIFO (connection to libvo) ============
1388 // Init input system
1389 current_module = "init_input";
1390 mp_input_init();
1391 #if 0
1392 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1394 if(keyb_fifo_get > 0)
1395 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1396 #else
1397 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1398 #endif
1399 if(slave_mode)
1400 #ifndef __MINGW32__
1401 mp_input_add_cmd_fd(0,1,NULL,NULL);
1402 #else
1403 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1404 #endif
1405 else if(!noconsolecontrols)
1406 #ifndef HAVE_NO_POSIX_SELECT
1407 mp_input_add_key_fd(0,1,NULL,NULL);
1408 #else
1409 mp_input_add_key_fd(0,0,NULL,NULL);
1410 #endif
1412 inited_flags|=INITED_INPUT;
1413 current_module = NULL;
1415 #ifdef HAVE_MENU
1416 if(use_menu) {
1417 if(menu_cfg && menu_init(menu_cfg))
1418 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1419 else {
1420 menu_cfg = get_path("menu.conf");
1421 if(menu_init(menu_cfg))
1422 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1423 else {
1424 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1425 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
1426 else {
1427 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
1428 use_menu = 0;
1433 #endif
1435 /// Catch signals
1436 #ifndef __MINGW32__
1437 signal(SIGCHLD,child_sighandler);
1438 #endif
1440 #ifdef CRASH_DEBUG
1441 prog_path = argv[0];
1442 #endif
1443 //========= Catch terminate signals: ================
1444 // terminate requests:
1445 signal(SIGTERM,exit_sighandler); // kill
1446 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1448 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1450 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1451 signal(SIGPIPE,exit_sighandler); // Some window managers cause this
1452 #ifdef ENABLE_SIGHANDLER
1453 // fatal errors:
1454 signal(SIGBUS,exit_sighandler); // bus error
1455 signal(SIGSEGV,exit_sighandler); // segfault
1456 signal(SIGILL,exit_sighandler); // illegal instruction
1457 signal(SIGFPE,exit_sighandler); // floating point exc.
1458 signal(SIGABRT,exit_sighandler); // abort()
1459 #ifdef CRASH_DEBUG
1460 if (crash_debug)
1461 signal(SIGTRAP,exit_sighandler);
1462 #endif
1463 #endif
1465 #ifdef HAVE_NEW_GUI
1466 if(use_gui){
1467 guiInit();
1468 inited_flags|=INITED_GUI;
1469 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1471 #endif
1473 // ******************* Now, let's see the per-file stuff ********************
1475 play_next_file:
1477 // init global sub numbers
1478 global_sub_size = 0;
1479 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
1480 global_sub_quiet_osd_hack = 1;
1482 if (filename) load_per_file_config (mconfig, filename);
1484 // We must enable getch2 here to be able to interrupt network connection
1485 // or cache filling
1486 if(!noconsolecontrols && !slave_mode){
1487 if(inited_flags&INITED_GETCH2)
1488 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
1489 else
1490 getch2_enable(); // prepare stdin for hotkeys...
1491 inited_flags|=INITED_GETCH2;
1492 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1495 // =================== GUI idle loop (STOP state) ===========================
1496 #ifdef HAVE_NEW_GUI
1497 if ( use_gui ) {
1498 file_format=DEMUXER_TYPE_UNKNOWN;
1499 guiGetEvent( guiSetDefaults,0 );
1500 while ( guiIntfStruct.Playing != 1 )
1502 mp_cmd_t* cmd;
1503 usec_sleep(20000);
1504 guiEventHandling();
1505 guiGetEvent( guiReDraw,NULL );
1506 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1508 guiGetEvent( guiSetParameters,NULL );
1509 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1511 play_tree_t * entry = play_tree_new();
1512 play_tree_add_file( entry,guiIntfStruct.Filename );
1513 if ( playtree ) play_tree_free_list( playtree->child,1 );
1514 else playtree=play_tree_new();
1515 play_tree_set_child( playtree,entry );
1516 if(playtree)
1518 playtree_iter = play_tree_iter_new(playtree,mconfig);
1519 if(playtree_iter)
1521 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1523 play_tree_iter_free(playtree_iter);
1524 playtree_iter = NULL;
1526 filename = play_tree_iter_get_file(playtree_iter,1);
1531 #endif
1532 //---------------------------------------------------------------------------
1534 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1536 //==================== Open VOB-Sub ============================
1538 current_module="vobsub";
1539 if (vobsub_name){
1540 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1541 if(vo_vobsub==NULL)
1542 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1543 }else if(sub_auto && filename && (strlen(filename)>=5)){
1544 /* try to autodetect vobsub from movie filename ::atmos */
1545 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1546 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1547 strncpy(buf, filename, strlen(filename)-4);
1548 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1549 free(buf);
1551 if(vo_vobsub){
1552 inited_flags|=INITED_VOBSUB;
1553 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1554 // check if vobsub requested only to display forced subtitles
1555 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1557 // setup global sub numbering
1558 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
1559 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
1562 //============ Open & Sync STREAM --- fork cache2 ====================
1564 stream=NULL;
1565 demuxer=NULL;
1566 if (d_audio) {
1567 //free_demuxer_stream(d_audio);
1568 d_audio=NULL;
1570 if (d_video) {
1571 //free_demuxer_stream(d_video);
1572 d_video=NULL;
1574 sh_audio=NULL;
1575 sh_video=NULL;
1577 current_module="open_stream";
1578 stream=open_stream(filename,0,&file_format);
1579 if(!stream) { // error...
1580 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1581 goto goto_next_file;
1583 inited_flags|=INITED_STREAM;
1585 #ifdef HAVE_NEW_GUI
1586 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1587 #endif
1589 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1590 play_tree_t* entry;
1591 // Handle playlist
1592 current_module="handle_playlist";
1593 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1594 entry = parse_playtree(stream,0);
1595 eof=playtree_add_playlist(entry);
1596 goto goto_next_file;
1598 stream->start_pos+=seek_to_byte;
1600 if(stream_dump_type==5){
1601 unsigned char buf[4096];
1602 int len;
1603 FILE *f;
1604 current_module="dumpstream";
1605 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1606 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
1607 exit_player(MSGTR_Exit_error);
1609 stream_reset(stream);
1610 stream_seek(stream,stream->start_pos);
1611 f=fopen(stream_dump_name,"wb");
1612 if(!f){
1613 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1614 exit_player(MSGTR_Exit_error);
1616 while(!stream->eof){
1617 len=stream_read(stream,buf,4096);
1618 if(len>0) {
1619 if(fwrite(buf,len,1,f) != 1) {
1620 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1621 exit_player(MSGTR_Exit_error);
1625 if(fclose(f)) {
1626 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1627 exit_player(MSGTR_Exit_error);
1629 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1630 exit_player_with_rc(MSGTR_Exit_eof, 0);
1633 #ifdef USE_DVDREAD
1634 if(stream->type==STREAMTYPE_DVD){
1635 current_module="dvd lang->id";
1636 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1637 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1638 // setup global sub numbering
1639 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1640 global_sub_size += dvd_number_of_subs(stream);
1641 current_module=NULL;
1643 #endif
1645 #ifdef USE_DVDNAV
1646 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1647 #endif
1649 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1650 #ifdef HAS_DVBIN_SUPPORT
1651 goto_enable_cache:
1652 #endif
1653 if(stream_cache_size>0){
1654 current_module="enable_cache";
1655 if(!stream_enable_cache(stream,stream_cache_size*1024,
1656 stream_cache_size*1024*(stream_cache_min_percent / 100.0),
1657 stream_cache_size*1024*(stream_cache_seek_min_percent / 100.0)))
1658 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1661 //============ Open DEMUXERS --- DETECT file type =======================
1662 current_module="demux_open";
1664 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1666 // HACK to get MOV Reference Files working
1668 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1670 unsigned char* playlist_entry;
1671 play_tree_t *list = NULL, *entry = NULL;
1673 current_module="handle_demux_playlist";
1674 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1676 char *temp, *bname;
1678 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
1680 bname=mp_basename(playlist_entry);
1681 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1682 continue;
1684 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1685 continue;
1687 entry = play_tree_new();
1689 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1691 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1692 if (temp)
1694 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1695 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1696 strcat(temp, playlist_entry);
1697 play_tree_add_file(entry,temp);
1698 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
1699 free(temp);
1702 else
1703 play_tree_add_file(entry,playlist_entry);
1705 if(!list)
1706 list = entry;
1707 else
1708 play_tree_append_entry(list,entry);
1710 free_demuxer(demuxer);
1711 demuxer = NULL;
1713 if (list)
1715 entry = play_tree_new();
1716 play_tree_set_child(entry,list);
1717 eof=playtree_add_playlist(entry);
1718 goto goto_next_file;
1722 if(!demuxer)
1724 #if 0
1725 play_tree_t* entry;
1726 // Handle playlist
1727 current_module="handle_playlist";
1728 switch(stream->type){
1729 case STREAMTYPE_VCD:
1730 case STREAMTYPE_DVD:
1731 case STREAMTYPE_DVDNAV:
1732 case STREAMTYPE_CDDA:
1733 case STREAMTYPE_VCDBINCUE:
1734 // don't try to parse raw media as playlist, it's unlikely
1735 goto goto_next_file;
1737 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
1738 stream_reset(stream);
1739 stream_seek(stream,stream->start_pos);
1740 entry = parse_playtree(stream,0);
1741 if(!entry)
1742 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1743 else
1744 eof=playtree_add_playlist(entry);
1745 #endif
1746 goto goto_next_file;
1748 inited_flags|=INITED_DEMUXER;
1750 #ifdef HAVE_MATROSKA
1751 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
1752 // setup global sub numbering
1753 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1754 global_sub_size += demux_mkv_num_subs(demuxer);
1756 #endif
1757 #ifdef HAVE_OGGVORBIS
1758 if (demuxer->type==DEMUXER_TYPE_OGG) {
1759 // setup global sub numbering
1760 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1761 global_sub_size += demux_ogg_num_subs(demuxer);
1763 #endif
1765 current_module="demux_open2";
1767 //file_format=demuxer->file_format;
1769 d_audio=demuxer->audio;
1770 d_video=demuxer->video;
1771 d_dvdsub=demuxer->sub;
1773 // DUMP STREAMS:
1774 if((stream_dump_type)&&(stream_dump_type<4)){
1775 FILE *f;
1776 demux_stream_t *ds=NULL;
1777 current_module="dump";
1778 // select stream to dump
1779 switch(stream_dump_type){
1780 case 1: ds=d_audio;break;
1781 case 2: ds=d_video;break;
1782 case 3: ds=d_dvdsub;break;
1784 if(!ds){
1785 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1786 exit_player(MSGTR_Exit_error);
1788 // disable other streams:
1789 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1790 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1791 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1792 // let's dump it!
1793 f=fopen(stream_dump_name,"wb");
1794 if(!f){
1795 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1796 exit_player(MSGTR_Exit_error);
1798 while(!ds->eof){
1799 unsigned char* start;
1800 int in_size=ds_get_packet(ds,&start);
1801 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1802 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1803 if(in_size>0) fwrite(start,in_size,1,f);
1805 fclose(f);
1806 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1807 exit_player_with_rc(MSGTR_Exit_eof, 0);
1810 sh_audio=d_audio->sh;
1811 sh_video=d_video->sh;
1813 if(sh_video){
1815 current_module="video_read_properties";
1816 if(!video_read_properties(sh_video)) {
1817 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1818 sh_video=d_video->sh=NULL;
1819 } else {
1820 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1821 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1822 sh_video->fps,sh_video->frametime
1825 /* need to set fps here for output encoders to pick it up in their init */
1826 if(force_fps){
1827 sh_video->fps=force_fps;
1828 sh_video->frametime=1.0f/sh_video->fps;
1830 vo_fps = sh_video->fps;
1831 #ifdef HAVE_X11
1832 vo_mouse_timer_const=(int)sh_video->fps;
1833 #endif
1835 if(!sh_video->fps && !force_fps){
1836 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1837 sh_video=d_video->sh=NULL;
1843 fflush(stdout);
1845 if(!sh_video && !sh_audio){
1846 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1847 #ifdef HAS_DVBIN_SUPPORT
1848 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1850 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1851 if(priv->is_on)
1853 int dir;
1854 int v = last_dvb_step;
1855 if(v > 0)
1856 dir = DVB_CHANNEL_HIGHER;
1857 else
1858 dir = DVB_CHANNEL_LOWER;
1860 if(dvb_step_channel(priv, dir))
1862 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1863 cache_uninit(stream);
1864 goto goto_enable_cache;
1868 #endif
1869 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1872 /* display clip info */
1873 demux_info_print(demuxer);
1875 //================== Read SUBTITLES (DVD & TEXT) ==========================
1876 if(vo_spudec==NULL && sh_video &&
1877 (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA ||
1878 d_dvdsub->id >= 0)){
1880 if (spudec_ifo) {
1881 unsigned int palette[16], width, height;
1882 current_module="spudec_init_vobsub";
1883 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1884 vo_spudec=spudec_new_scaled(palette, width, height);
1887 #ifdef USE_DVDNAV
1888 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1889 current_module="spudec_init_dvdnav";
1890 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1891 sh_video->disp_w, sh_video->disp_h);
1893 #endif
1895 #ifdef USE_DVDREAD
1896 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1897 current_module="spudec_init_dvdread";
1898 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1899 sh_video->disp_w, sh_video->disp_h);
1901 #endif
1903 #ifdef HAVE_MATROSKA
1904 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1905 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1906 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
1907 current_module = "spudec_init_matroska";
1908 vo_spudec =
1909 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1910 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1911 mkv_sh_sub->height);
1912 forced_subs_only = mkv_sh_sub->forced_subs_only;
1914 #endif
1916 if (vo_spudec==NULL) {
1917 current_module="spudec_init_normal";
1918 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1919 spudec_set_font_factor(vo_spudec,font_factor);
1922 if (vo_spudec!=NULL)
1923 inited_flags|=INITED_SPUDEC;
1927 // Apply current settings for forced subs
1928 if (vo_spudec!=NULL)
1929 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1931 #ifdef USE_SUB
1932 if(sh_video) {
1933 // after reading video params we should load subtitles because
1934 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1935 // check .sub
1936 current_module="read_subtitles_file";
1937 if(sub_name){
1938 for (i = 0; sub_name[i] != NULL; ++i)
1939 add_subtitles (sub_name[i], sh_video->fps, 0);
1941 if(sub_auto) { // auto load sub file ...
1942 char *psub = get_path( "sub/" );
1943 char **tmp = sub_filenames((psub ? psub : ""), filename);
1944 int i = 0;
1945 free(psub); // release the buffer created by get_path() above
1946 while (tmp[i]) {
1947 add_subtitles (tmp[i], sh_video->fps, 0);
1948 free(tmp[i++]);
1950 free(tmp);
1951 if (set_of_sub_size == 0)
1953 add_subtitles (mem_ptr=get_path("default.sub"), sh_video->fps, 1);
1954 free(mem_ptr); // release the buffer created by get_path()
1957 if (set_of_sub_size > 0) {
1958 // setup global sub numbering
1959 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
1960 global_sub_size += set_of_sub_size;
1963 #endif
1965 if (global_sub_size) {
1966 // find the best sub to use
1967 if (vobsub_id >= 0) {
1968 // if user asks for a vobsub id, use that first.
1969 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
1970 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1971 // if user asks for a dvd sub id, use that next.
1972 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
1973 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
1974 // if there are text subs to use, use those. (autosubs come last here)
1975 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
1977 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1978 // if nothing else works, get subs from the demuxer.
1979 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1981 } else {
1982 // nothing worth doing automatically.
1983 global_sub_pos = -1;
1985 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1986 global_sub_pos--;
1987 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1990 //================== Init AUDIO (codec) ==========================
1991 if(sh_audio){
1992 // Go through the codec.conf and find the best codec...
1993 current_module="init_audio_codec";
1994 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1995 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1996 sh_audio=d_audio->sh=NULL; // failed to init :(
1997 } else
1998 inited_flags|=INITED_ACODEC;
1999 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2002 if(identify) {
2003 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
2004 if (sh_video) {
2005 /* Assume FOURCC if all bytes >= 0x20 (' ') */
2006 if (sh_video->format >= 0x20202020)
2007 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
2008 else
2009 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
2010 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
2011 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
2012 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
2013 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
2014 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
2016 if (sh_audio) {
2017 if (sh_audio->codec)
2018 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
2019 /* Assume FOURCC if all bytes >= 0x20 (' ') */
2020 if (sh_audio->format >= 0x20202020)
2021 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
2022 else
2023 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
2024 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
2025 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
2026 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
2028 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
2031 if(!sh_video) goto main; // audio-only
2033 //================== Init VIDEO (codec & libvo) ==========================
2034 if(!fixed_vo || !(inited_flags&INITED_VO)){
2035 current_module="preinit_libvo";
2037 vo_config_count=0;
2038 //if((video_out->preinit(vo_subdevice))!=0){
2039 if(!(video_out=init_best_video_out(video_driver_list))){
2040 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
2041 goto goto_next_file; // exit_player(MSGTR_Exit_error);
2043 sh_video->video_out=video_out;
2044 inited_flags|=INITED_VO;
2047 current_module="init_video_filters";
2049 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
2050 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
2052 #ifdef HAVE_MENU
2053 if(use_menu) {
2054 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
2055 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
2056 if(!vf_menu) {
2057 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
2058 use_menu = 0;
2061 if(vf_menu)
2062 sh_video->vfilter=(void*)append_filters(vf_menu);
2063 else
2064 #endif
2065 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
2067 current_module="init_video_codec";
2069 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2070 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
2071 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2073 if(!sh_video->inited){
2074 if(!fixed_vo) uninit_player(INITED_VO);
2075 if(!sh_audio) goto goto_next_file;
2076 sh_video = d_video->sh = NULL;
2077 goto main; // exit_player(MSGTR_Exit_error);
2080 inited_flags|=INITED_VCODEC;
2082 if(auto_quality>0){
2083 // Auto quality option enabled
2084 output_quality=get_video_quality_max(sh_video);
2085 if(auto_quality>output_quality) auto_quality=output_quality;
2086 else output_quality=auto_quality;
2087 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
2088 set_video_quality(sh_video,output_quality);
2091 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2093 current_module="init_vo";
2095 if(vo_flags & 0x08 && vo_spudec)
2096 spudec_set_hw_spu(vo_spudec,video_out);
2098 #ifdef HAVE_FREETYPE
2099 force_load_font = 1;
2100 #endif
2102 //================== MAIN: ==========================
2103 main:
2104 current_module="main";
2106 // If there is no video OSD has to be disabled.
2107 // In case of playing a playtree we have to restore the
2108 // old OSD level after playing one or more audio-only files.
2109 if(!sh_video && osd_level >= 0) { // save OSD level only once
2110 osd_level_saved = osd_level;
2111 osd_level = 0;
2112 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
2113 osd_level = osd_level_saved;
2114 osd_level_saved = -1;
2117 fflush(stdout);
2119 #ifdef HAVE_NEW_GUI
2120 if ( use_gui )
2122 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
2123 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
2124 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
2125 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
2126 guiGetEvent( guiSetDemuxer,(char *)demuxer );
2128 #endif
2131 //int frame_corr_num=0; //
2132 //float v_frame=0; // Video
2133 float time_frame=0; // Timer
2134 //float num_frames=0; // number of frames played
2135 int grab_frames=0;
2136 char osd_text_buffer[64];
2137 char osd_show_text_buffer[64];
2138 int drop_frame=0; // current dropping status
2139 int dropped_frames=0; // how many frames dropped since last non-dropped frame
2140 int too_slow_frame_cnt=0;
2141 int too_fast_frame_cnt=0;
2142 // for auto-quality:
2143 float AV_delay=0; // average of A-V timestamp differences
2144 double vdecode_time;
2145 unsigned int lastframeout_ts=0;
2146 /*float time_frame_corr_avg=0;*/ /* unused */
2148 float next_frame_time=0;
2149 int frame_time_remaining=0; // flag
2150 int blit_frame=0;
2152 osd_text_buffer[0]=0;
2154 //================ SETUP AUDIO ==========================
2156 if(sh_audio){
2157 //const ao_info_t *info=audio_out->info;
2158 current_module="af_preinit";
2159 ao_data.samplerate=force_srate;
2160 ao_data.channels=0;
2161 ao_data.format=audio_output_format;
2162 #if 1
2163 // first init to detect best values
2164 if(!preinit_audio_filters(sh_audio,
2165 // input:
2166 (int)(sh_audio->samplerate*playback_speed),
2167 sh_audio->channels, sh_audio->sample_format,
2168 // output:
2169 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){
2170 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2172 #endif
2173 current_module="ao2_init";
2174 if(!(audio_out=init_best_audio_out(audio_driver_list,
2175 0, // plugin flag
2176 ao_data.samplerate,
2177 ao_data.channels,
2178 ao_data.format,0))){
2179 // FAILED:
2180 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2181 uninit_player(INITED_ACODEC); // close codec
2182 sh_audio=d_audio->sh=NULL; // -> nosound
2183 } else {
2184 // SUCCESS:
2185 inited_flags|=INITED_AO;
2186 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
2187 audio_out->info->short_name,
2188 ao_data.samplerate, ao_data.channels,
2189 af_fmt2str_short(ao_data.format),
2190 af_fmt2bits(ao_data.format)/8 );
2191 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2192 audio_out->info->name, audio_out->info->author);
2193 if(strlen(audio_out->info->comment) > 0)
2194 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2195 // init audio filters:
2196 #if 1
2197 current_module="af_init";
2198 if(!build_afilter_chain(sh_audio, &ao_data)) {
2199 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2200 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2201 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2202 // sh_audio=d_audio->sh=NULL; // -> nosound
2204 #endif
2206 mixer.audio_out = audio_out;
2207 mixer.volstep = volstep;
2210 current_module="av_init";
2212 if(sh_video) sh_video->timer=0;
2213 if(sh_audio) sh_audio->delay=-audio_delay;
2215 if(!sh_audio){
2216 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
2217 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
2218 ds_free_packs(d_audio); // free buffered chunks
2219 d_audio->id=-2; // do not read audio chunks
2220 //uninit_player(INITED_AO); // close device
2222 if(!sh_video){
2223 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
2224 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
2225 ds_free_packs(d_video);
2226 d_video->id=-2;
2227 //if(!fixed_vo) uninit_player(INITED_VO);
2230 if (!sh_video && !sh_audio)
2231 goto goto_next_file;
2233 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
2234 if(force_fps && sh_video){
2235 vo_fps = sh_video->fps=force_fps;
2236 sh_video->frametime=1.0f/sh_video->fps;
2237 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
2240 //==================== START PLAYING =======================
2242 if(loop_times>1) loop_times--; else
2243 if(loop_times==1) loop_times = -1;
2245 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
2247 #ifdef USE_DVDNAV
2248 if (stream->type==STREAMTYPE_DVDNAV) {
2249 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
2251 #endif
2253 total_time_usage_start=GetTimer();
2254 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
2255 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
2256 play_n_frames=play_n_frames_mf;
2258 if(play_n_frames==0){
2259 eof=PT_NEXT_ENTRY; goto goto_next_file;
2262 while(!eof){
2263 float aq_sleep_time=0;
2265 /*========================== PLAY AUDIO ============================*/
2267 while(sh_audio){
2268 unsigned int t;
2269 double tt;
2270 int playsize;
2272 current_module="play_audio";
2274 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2275 playsize=audio_out->get_space();
2277 // handle audio-only case:
2278 if(playsize < ao_data.outburst &&
2279 !sh_video) { // buffer is full, do not block here!!!
2280 usec_sleep(10000); // Wait a tick before retry
2281 continue;
2284 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
2286 // Fill buffer if needed:
2287 current_module="decode_audio"; // Enter AUDIO decoder module
2288 t=GetTimer();
2289 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
2290 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
2291 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
2292 if(ret<=0) break; // EOF?
2293 sh_audio->a_out_buffer_len+=ret;
2295 t=GetTimer()-t;
2296 tt = t*0.000001f; audio_time_usage+=tt;
2297 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
2299 // play audio:
2300 current_module="play_audio";
2301 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2303 if(playsize>0){
2304 sh_audio->a_out_buffer_len-=playsize;
2305 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2306 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2307 ao_data.bps : sh_audio->o_bps));
2310 break;
2311 } // while(sh_audio)
2313 if(!sh_video) {
2314 // handle audio-only case:
2315 if(!quiet) {
2316 float a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
2317 print_status(a_pos, 0, 0);
2319 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2321 } else {
2323 /*========================== PLAY VIDEO ============================*/
2325 float frame_time=next_frame_time;
2327 vo_pts=sh_video->timer*90000.0;
2328 vo_fps=sh_video->fps;
2330 if(!frame_time_remaining){
2331 //-------------------- Decode a frame: -----------------------
2332 vdecode_time=video_time_usage;
2333 while(1)
2334 { unsigned char* start=NULL;
2335 int in_size;
2336 // get it!
2337 current_module="video_read_frame";
2338 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2339 if(in_size<0){ eof=1; break; }
2340 if(in_size>max_framesize) max_framesize=in_size; // stats
2341 sh_video->timer+=frame_time;
2342 if(sh_audio) sh_audio->delay-=frame_time;
2343 time_frame+=frame_time; // for nosound
2344 // video_read_frame can change fps (e.g. for asf video)
2345 vo_fps = sh_video->fps;
2346 #ifdef HAVE_X11
2347 vo_mouse_timer_const = (int)sh_video->fps;
2348 #endif
2349 // check for frame-drop:
2350 current_module="check_framedrop";
2351 if(sh_audio && !d_audio->eof){
2352 float delay=playback_speed*audio_out->get_delay();
2353 float d=delay-sh_audio->delay;
2354 // we should avoid dropping to many frames in sequence unless we
2355 // are too late. and we allow 100ms A-V delay here:
2356 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
2357 drop_frame=frame_dropping;
2358 ++drop_frame_cnt;
2359 ++dropped_frames;
2360 } else {
2361 drop_frame=dropped_frames=0;
2363 ++total_frame_cnt;
2365 // decode:
2366 current_module="decode_video";
2367 // printf("Decode! %p %d \n",start,in_size);
2368 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2369 break;
2371 vdecode_time=video_time_usage-vdecode_time;
2372 //------------------------ frame decoded. --------------------
2374 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2376 if(sh_video->vf_inited<0){
2377 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2378 eof=1; goto goto_next_file;
2383 // ==========================================================================
2385 // current_module="draw_osd";
2386 // if(vo_config_count) video_out->draw_osd();
2388 #ifdef HAVE_NEW_GUI
2389 if(use_gui) guiEventHandling();
2390 #endif
2392 current_module="calc_sleep_time";
2394 #if 0
2395 { // debug frame dropping code
2396 float delay=audio_out->get_delay();
2397 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2398 sh_video->timer,sh_audio->timer-delay,
2399 sh_video->timer-(sh_audio->timer-delay),
2400 delay,drop_frame);
2402 #endif
2404 if(drop_frame && !frame_time_remaining && !autosync){
2406 * Note: time_frame should not be forced to 0 in autosync mode.
2407 * It is used as a cumulative counter to predict and correct the
2408 * delay measurements from the audio driver. time_frame is already
2409 * < 0, so the "time to sleep" code does not actually sleep. Also,
2410 * blit_frame is already 0 because drop_frame was true when
2411 * decode_video was called (which causes it to set blit_frame to 0.)
2412 * When autosync==0, the default behavior is still completely unchanged.
2415 time_frame=0; // don't sleep!
2416 blit_frame=0; // don't display!
2418 } else {
2420 // It's time to sleep...
2422 frame_time_remaining=0;
2423 time_frame-=GetRelativeTime(); // reset timer
2425 if(sh_audio && !d_audio->eof){
2426 float delay=playback_speed*audio_out->get_delay();
2427 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2429 if (autosync){
2431 * Adjust this raw delay value by calculating the expected
2432 * delay for this frame and generating a new value which is
2433 * weighted between the two. The higher autosync is, the
2434 * closer to the delay value gets to that which "-nosound"
2435 * would have used, and the longer it will take for A/V
2436 * sync to settle at the right value (but it eventually will.)
2437 * This settling time is very short for values below 100.
2439 float predicted = sh_audio->delay+time_frame;
2440 float difference = delay - predicted;
2441 delay = predicted + difference / (float)autosync;
2444 time_frame=delay-sh_audio->delay;
2446 // delay = amount of audio buffered in soundcard/driver
2447 if(delay>0.25) delay=0.25; else
2448 if(delay<0.10) delay=0.10;
2449 if(time_frame>delay*0.6){
2450 // sleep time too big - may cause audio drops (buffer underrun)
2451 frame_time_remaining=1;
2452 time_frame=delay*0.5;
2455 } else {
2457 // NOSOUND:
2458 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2459 time_frame=0;
2463 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2465 aq_sleep_time+=time_frame;
2467 } // !drop_frame
2469 //============================== SLEEP: ===================================
2471 time_frame/=playback_speed;
2473 // flag 256 means: libvo driver does its timing (dvb card)
2474 if(time_frame>0.001 && !(vo_flags&256)){
2476 #ifdef HAVE_RTC
2477 if(rtc_fd>=0){
2478 // -------- RTC -----------
2479 current_module="sleep_rtc";
2480 while (time_frame > 0.000) {
2481 unsigned long rtc_ts;
2482 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2483 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2484 time_frame-=GetRelativeTime();
2486 } else
2487 #endif
2488 #ifdef SYS_DARWIN
2490 current_module="sleep_darwin";
2491 while(time_frame>0.005) {
2492 usec_sleep(1000000*time_frame);
2493 time_frame-=GetRelativeTime();
2496 #else
2498 // -------- TIMER + SOFTSLEEP -----------
2499 float min=softsleep?0.021:0.005;
2500 current_module="sleep_timer";
2501 while(time_frame>min){
2502 if(time_frame<=0.020)
2503 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2504 else
2505 usec_sleep(1000000*(time_frame-0.020));
2506 time_frame-=GetRelativeTime();
2508 if(softsleep){
2509 current_module="sleep_soft";
2510 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
2511 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2514 #endif
2517 //if(!frame_time_remaining){ // should we display the frame now?
2519 //====================== FLIP PAGE (VIDEO BLT): =========================
2521 current_module="vo_check_events";
2522 if(vo_config_count) video_out->check_events();
2524 current_module="flip_page";
2525 if (!frame_time_remaining) {
2526 if(blit_frame){
2527 unsigned int t2=GetTimer();
2528 double tt;
2529 float j;
2530 #define FRAME_LAG_WARN 0.2
2531 j = ((float)t2 - lastframeout_ts) / 1000000;
2532 lastframeout_ts = GetTimer();
2533 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2534 too_fast_frame_cnt++;
2535 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2536 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2537 too_slow_frame_cnt++;
2538 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2540 if(vo_config_count) video_out->flip_page();
2541 if (play_n_frames >= 0) {
2542 --play_n_frames;
2543 if (play_n_frames < 0) eof = PT_NEXT_ENTRY;
2546 // usec_sleep(50000); // test only!
2547 t2=GetTimer()-t2;
2548 tt = t2*0.000001f;
2549 vout_time_usage+=tt;
2550 } else {
2552 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2553 otherwise A/V desync will occur. -- Alvieboy
2555 if (vo_config_count)
2556 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2559 //====================== A-V TIMESTAMP CORRECTION: =========================
2561 current_module="av_sync";
2563 if(sh_audio){
2564 float a_pts=0;
2565 float v_pts=0;
2567 // unplayed bytes in our and soundcard/dma buffer:
2568 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2570 if (autosync){
2572 * If autosync is enabled, the value for delay must be calculated
2573 * a bit differently. It is set only to the difference between
2574 * the audio and video timers. Any attempt to include the real
2575 * or corrected delay causes the pts_correction code below to
2576 * try to correct for the changes in delay which autosync is
2577 * trying to measure. This keeps the two from competing, but still
2578 * allows the code to correct for PTS drift *only*. (Using a delay
2579 * value here, even a "corrected" one, would be incompatible with
2580 * autosync mode.)
2582 delay=sh_audio->delay;
2583 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2586 #if 0
2587 if(pts_from_bps){
2588 // PTS = sample_no / samplerate
2589 unsigned int samples=
2590 // (sh_audio->audio.dwSampleSize)?
2591 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2592 ds_tell_block(d_audio); // <- used for VBR audio
2593 samples+=sh_audio->audio.dwStart; // offset
2594 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2595 delay_corrected=1;
2596 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2597 } else
2598 #endif
2600 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2601 a_pts=d_audio->pts;
2602 if(!delay_corrected) if(a_pts) delay_corrected=1;
2603 #if 0
2604 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2605 a_pts,
2606 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2607 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2608 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2609 #endif
2610 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2612 v_pts=sh_video ? sh_video->pts : d_video->pts;
2614 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);
2616 if(delay_corrected){
2617 static int drop_message=0;
2618 float x;
2619 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2620 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2621 ++drop_message;
2622 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2624 x=AV_delay*0.1f;
2625 if(x<-max_pts_correction) x=-max_pts_correction; else
2626 if(x> max_pts_correction) x= max_pts_correction;
2627 if(default_max_pts_correction>=0)
2628 max_pts_correction=default_max_pts_correction;
2629 else
2630 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2631 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2632 if(!quiet)
2633 print_status(a_pts - audio_delay - delay, AV_delay, c_total);
2636 } else {
2637 // No audio:
2639 if(!quiet)
2640 print_status(0, 0, 0);
2644 //============================ Auto QUALITY ============================
2646 /*Output quality adjustments:*/
2647 if(auto_quality>0){
2648 current_module="autoq";
2649 // float total=0.000001f * (GetTimer()-aq_total_time);
2650 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2651 if(output_quality<auto_quality && aq_sleep_time>0)
2652 ++output_quality;
2653 else
2654 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2655 if(output_quality>1 && aq_sleep_time<0)
2656 --output_quality;
2657 else
2658 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2659 output_quality=0;
2660 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2661 set_video_quality(sh_video,output_quality);
2664 } // end if(sh_video)
2666 //============================ Handle PAUSE ===============================
2668 current_module="pause";
2670 #ifdef USE_OSD
2671 if(osd_visible){
2672 if (!--osd_visible){
2673 vo_osd_progbar_type=-1; // disable
2674 vo_osd_changed(OSDTYPE_PROGBAR);
2675 if (osd_function != OSD_PAUSE)
2676 osd_function = OSD_PLAY;
2679 #endif
2681 if(osd_function==OSD_PAUSE){
2682 mp_cmd_t* cmd;
2683 if(!quiet) {
2684 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2685 if (identify)
2686 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_PAUSED\n");
2687 fflush(stdout);
2689 #ifdef HAVE_NEW_GUI
2690 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2691 #endif
2692 if (video_out && sh_video && vo_config_count)
2693 video_out->control(VOCTRL_PAUSE, NULL);
2695 if (audio_out && sh_audio)
2696 audio_out->pause(); // pause audio, keep data if possible
2698 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
2699 if(sh_video && video_out && vo_config_count) video_out->check_events();
2700 #ifdef HAVE_NEW_GUI
2701 if(use_gui){
2702 guiEventHandling();
2703 guiGetEvent( guiReDraw,NULL );
2704 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2706 #endif
2707 #ifdef HAVE_MENU
2708 if(vf_menu)
2709 vf_menu_pause_update(vf_menu);
2710 #endif
2711 usec_sleep(20000);
2713 if (cmd && cmd->id == MP_CMD_PAUSE) {
2714 cmd = mp_input_get_cmd(0,1,0);
2715 mp_cmd_free(cmd);
2717 osd_function=OSD_PLAY;
2718 if (audio_out && sh_audio)
2719 audio_out->resume(); // resume audio
2720 if (video_out && sh_video && vo_config_count)
2721 video_out->control(VOCTRL_RESUME, NULL); // resume video
2722 (void)GetRelativeTime(); // keep TF around FT in next cycle
2723 #ifdef HAVE_NEW_GUI
2724 if (use_gui)
2726 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2727 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2729 #endif
2732 // handle -sstep
2733 if(step_sec>0) {
2734 osd_function=OSD_FFW;
2735 rel_seek_secs+=step_sec;
2738 #ifdef USE_DVDNAV
2739 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2740 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2741 #endif
2743 //================= EDL =========================================
2745 #ifdef USE_EDL
2746 if( next_edl_record ) { // Are we (still?) doing EDL?
2747 if ( !sh_video ) {
2748 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
2749 free_edl(edl_records);
2750 next_edl_record = NULL;
2751 edl_records = NULL;
2752 } else {
2753 if( sh_video->pts >= next_edl_record->start_sec ) {
2754 if( next_edl_record->action == EDL_SKIP ) {
2755 osd_function = OSD_FFW;
2756 abs_seek_pos = 0;
2757 rel_seek_secs = next_edl_record->length_sec;
2758 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec );
2759 edl_decision = 1;
2760 } else if( next_edl_record->action == EDL_MUTE ) {
2761 edl_muted = !edl_muted;
2762 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
2763 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
2765 next_edl_record=next_edl_record->next;
2769 #endif
2771 //================= Keyboard events, SEEKing ====================
2773 current_module="key_events";
2776 mp_cmd_t* cmd;
2777 int brk_cmd = 0;
2778 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
2779 switch(cmd->id) {
2780 case MP_CMD_SEEK : {
2781 float v;
2782 int abs;
2783 osd_show_percentage = 25;
2784 v = cmd->args[0].v.f;
2785 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2786 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2787 abs_seek_pos = 1;
2788 if(sh_video)
2789 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2790 rel_seek_secs = v;
2792 else if(abs) { /* Absolute seek by percentage */
2793 abs_seek_pos = 3;
2794 if(sh_video)
2795 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2796 rel_seek_secs = v/100.0;
2798 else {
2799 rel_seek_secs+= v;
2800 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2802 brk_cmd = 1;
2803 } break;
2804 #ifdef USE_EDL
2805 case MP_CMD_EDL_MARK:
2806 if( edl_fd ) {
2807 float v = sh_video->pts;
2808 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2810 break;
2811 #endif
2812 case MP_CMD_SWITCH_RATIO : {
2813 if (cmd->nargs == 0)
2814 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2815 else
2816 movie_aspect = cmd->args[0].v.f;
2817 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2818 } break;
2819 case MP_CMD_AUDIO_DELAY : {
2820 float v = cmd->args[0].v.f;
2821 audio_delay += v;
2822 osd_show_av_delay = 9;
2823 if(sh_audio) sh_audio->delay+= v;
2824 } break;
2825 case MP_CMD_SPEED_INCR : {
2826 float v = cmd->args[0].v.f;
2827 playback_speed += v;
2828 if (sh_video)
2829 osd_show_speed = sh_video->fps;
2830 build_afilter_chain(sh_audio, &ao_data);
2831 } break;
2832 case MP_CMD_SPEED_MULT : {
2833 float v = cmd->args[0].v.f;
2834 playback_speed *= v;
2835 if (sh_video)
2836 osd_show_speed = sh_video->fps;
2837 build_afilter_chain(sh_audio, &ao_data);
2838 } break;
2839 case MP_CMD_SPEED_SET : {
2840 float v = cmd->args[0].v.f;
2841 playback_speed = v;
2842 if (sh_video)
2843 osd_show_speed = sh_video->fps;
2844 build_afilter_chain(sh_audio, &ao_data);
2845 } break;
2846 case MP_CMD_FRAME_STEP :
2847 case MP_CMD_PAUSE : {
2848 cmd->pausing = 1;
2849 brk_cmd = 1;
2850 } break;
2851 case MP_CMD_QUIT : {
2852 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
2854 case MP_CMD_GRAB_FRAMES : {
2855 grab_frames=2;
2856 } break;
2857 case MP_CMD_PLAY_TREE_STEP : {
2858 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2859 int force = cmd->args[1].v.i;
2861 #ifdef HAVE_NEW_GUI
2862 if (use_gui) {
2863 int i=0;
2864 if (n>0)
2865 for (i=0;i<n;i++)
2866 mplNext();
2867 else
2868 for (i=0;i<-1*n;i++)
2869 mplPrev();
2870 } else
2871 #endif
2873 if(!force && playtree_iter) {
2874 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2876 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2877 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2878 play_tree_iter_free(i);
2879 } else
2880 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2881 if(eof)
2882 play_tree_step = n;
2883 brk_cmd = 1;
2885 } break;
2886 case MP_CMD_PLAY_TREE_UP_STEP : {
2887 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2888 int force = cmd->args[1].v.i;
2890 if(!force && playtree_iter) {
2891 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2892 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2893 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2894 play_tree_iter_free(i);
2895 } else
2896 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2897 brk_cmd = 1;
2898 } break;
2899 case MP_CMD_PLAY_ALT_SRC_STEP : {
2900 if(playtree_iter && playtree_iter->num_files > 1) {
2901 int v = cmd->args[0].v.i;
2902 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2903 eof = PT_NEXT_SRC;
2904 else if(v < 0 && playtree_iter->file > 1)
2905 eof = PT_PREV_SRC;
2907 brk_cmd = 1;
2908 } break;
2909 case MP_CMD_SUB_DELAY : {
2910 #ifdef USE_SUB
2911 if (sh_video) {
2912 int abs= cmd->args[1].v.i;
2913 float v = cmd->args[0].v.f;
2914 if(abs)
2915 sub_delay = v;
2916 else
2917 sub_delay += v;
2918 osd_show_sub_delay = 9; // show the subdelay in OSD
2920 #endif
2921 } break;
2922 case MP_CMD_SUB_STEP : {
2923 #ifdef USE_SUB
2924 if (sh_video) {
2925 int movement = cmd->args[0].v.i;
2926 step_sub(subdata, sh_video->pts, movement);
2927 osd_show_sub_delay = 9; // show the subdelay in OSD
2929 #endif
2930 } break;
2931 case MP_CMD_SUB_LOG : {
2932 #ifdef USE_SUB
2933 log_sub();
2934 #endif
2935 } break;
2936 case MP_CMD_OSD : {
2937 #ifdef USE_OSD
2938 if(sh_video) {
2939 int v = cmd->args[0].v.i;
2940 if(v < 0)
2941 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2942 else
2943 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2944 /* Show OSD state when disabled, but not when an explicit
2945 argument is given to the osd command, i.e. in slave mode. */
2946 if (v == -1 && osd_level <= 1)
2947 osd_show_status = 9;
2949 #endif
2950 } break;
2951 case MP_CMD_OSD_SHOW_TEXT : {
2952 #ifdef USE_OSD
2953 if(osd_level && sh_video){
2954 osd_show_text=sh_video->fps; // 1 sec
2955 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2957 #endif
2958 } break;
2959 case MP_CMD_VOLUME : {
2960 int v = cmd->args[0].v.i;
2962 // start change for absolute volume value
2963 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2965 #ifdef USE_EDL
2966 if (edl_muted) break;
2967 user_muted = 0;
2968 #endif
2969 if( abs )
2971 mixer_setvolume(&mixer, (float)v, (float)v );
2972 } else {
2973 if(v > 0)
2974 mixer_incvolume(&mixer);
2975 else
2976 mixer_decvolume(&mixer);
2979 #ifdef USE_OSD
2980 if(osd_level && sh_video){
2981 float vol;
2982 osd_visible=sh_video->fps; // 1 sec
2983 vo_osd_progbar_type=OSD_VOLUME;
2984 mixer_getbothvolume(&mixer, &vol);
2985 vo_osd_progbar_value=(vol*256.0)/100.0;
2986 vo_osd_changed(OSDTYPE_PROGBAR);
2988 #endif
2989 } break;
2990 case MP_CMD_MUTE:
2991 #ifdef USE_EDL
2992 user_muted = !user_muted;
2993 if ((edl_muted | user_muted) != mixer.muted)
2994 #endif
2995 mixer_mute(&mixer);
2996 break;
2997 case MP_CMD_LOADFILE : {
2998 play_tree_t* e = play_tree_new();
2999 play_tree_add_file(e,cmd->args[0].v.s);
3001 if (cmd->args[1].v.i) // append
3002 play_tree_append_entry(playtree, e);
3003 else {
3004 // Go back to the start point
3005 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
3006 /* NOP */;
3007 play_tree_free_list(playtree->child,1);
3008 play_tree_set_child(playtree,e);
3009 play_tree_iter_step(playtree_iter,0,0);
3010 eof = PT_NEXT_SRC;
3012 brk_cmd = 1;
3013 } break;
3014 case MP_CMD_LOADLIST : {
3015 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
3016 if(!e)
3017 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
3018 else {
3019 if (cmd->args[1].v.i) // append
3020 play_tree_append_entry(playtree, e);
3021 else {
3022 // Go back to the start point
3023 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
3024 /* NOP */;
3025 play_tree_free_list(playtree->child,1);
3026 play_tree_set_child(playtree,e);
3027 play_tree_iter_step(playtree_iter,0,0);
3028 eof = PT_NEXT_SRC;
3031 brk_cmd = 1;
3032 } break;
3033 case MP_CMD_GAMMA : {
3034 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3036 if (!sh_video)
3037 break;
3039 if (vo_gamma_gamma == 1000)
3041 vo_gamma_gamma = 0;
3042 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
3045 if (abs)
3046 vo_gamma_gamma = v;
3047 else
3048 vo_gamma_gamma += v;
3050 if (vo_gamma_gamma > 100)
3051 vo_gamma_gamma = 100;
3052 else if (vo_gamma_gamma < -100)
3053 vo_gamma_gamma = -100;
3054 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
3055 #ifdef USE_OSD
3056 if(osd_level){
3057 osd_visible=sh_video->fps; // 1 sec
3058 vo_osd_progbar_type=OSD_BRIGHTNESS;
3059 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
3060 vo_osd_changed(OSDTYPE_PROGBAR);
3062 #endif // USE_OSD
3063 } break;
3064 case MP_CMD_BRIGHTNESS : {
3065 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3067 if (!sh_video)
3068 break;
3070 if (vo_gamma_brightness == 1000)
3072 vo_gamma_brightness = 0;
3073 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
3076 if (abs)
3077 vo_gamma_brightness = v;
3078 else
3079 vo_gamma_brightness += v;
3081 if (vo_gamma_brightness > 100)
3082 vo_gamma_brightness = 100;
3083 else if (vo_gamma_brightness < -100)
3084 vo_gamma_brightness = -100;
3085 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
3086 #ifdef USE_OSD
3087 if(osd_level){
3088 osd_visible=sh_video->fps; // 1 sec
3089 vo_osd_progbar_type=OSD_BRIGHTNESS;
3090 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
3091 vo_osd_changed(OSDTYPE_PROGBAR);
3093 #endif // USE_OSD
3095 } break;
3096 case MP_CMD_CONTRAST : {
3097 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3099 if (!sh_video)
3100 break;
3102 if (vo_gamma_contrast == 1000)
3104 vo_gamma_contrast = 0;
3105 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
3108 if (abs)
3109 vo_gamma_contrast = v;
3110 else
3111 vo_gamma_contrast += v;
3113 if (vo_gamma_contrast > 100)
3114 vo_gamma_contrast = 100;
3115 else if (vo_gamma_contrast < -100)
3116 vo_gamma_contrast = -100;
3117 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
3118 #ifdef USE_OSD
3119 if(osd_level){
3120 osd_visible=sh_video->fps; // 1 sec
3121 vo_osd_progbar_type=OSD_CONTRAST;
3122 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
3123 vo_osd_changed(OSDTYPE_PROGBAR);
3125 #endif // USE_OSD
3127 } break;
3128 case MP_CMD_SATURATION : {
3129 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3131 if (!sh_video)
3132 break;
3134 if (vo_gamma_saturation == 1000)
3136 vo_gamma_saturation = 0;
3137 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
3140 if (abs)
3141 vo_gamma_saturation = v;
3142 else
3143 vo_gamma_saturation += v;
3145 if (vo_gamma_saturation > 100)
3146 vo_gamma_saturation = 100;
3147 else if (vo_gamma_saturation < -100)
3148 vo_gamma_saturation = -100;
3149 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
3150 #ifdef USE_OSD
3151 if(osd_level){
3152 osd_visible=sh_video->fps; // 1 sec
3153 vo_osd_progbar_type=OSD_SATURATION;
3154 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
3155 vo_osd_changed(OSDTYPE_PROGBAR);
3157 #endif // USE_OSD
3159 } break;
3160 case MP_CMD_HUE : {
3161 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3163 if (!sh_video)
3164 break;
3166 if (vo_gamma_hue == 1000)
3168 vo_gamma_hue = 0;
3169 get_video_colors(sh_video, "hue", &vo_gamma_hue);
3172 if (abs)
3173 vo_gamma_hue = v;
3174 else
3175 vo_gamma_hue += v;
3177 if (vo_gamma_hue > 100)
3178 vo_gamma_hue = 100;
3179 else if (vo_gamma_hue < -100)
3180 vo_gamma_hue = -100;
3181 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
3182 #ifdef USE_OSD
3183 if(osd_level){
3184 osd_visible=sh_video->fps; // 1 sec
3185 vo_osd_progbar_type=OSD_HUE;
3186 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
3187 vo_osd_changed(OSDTYPE_PROGBAR);
3189 #endif // USE_OSD
3191 } break;
3192 case MP_CMD_FRAMEDROPPING : {
3193 int v = cmd->args[0].v.i;
3194 if(v < 0){
3195 frame_dropping = (frame_dropping+1)%3;
3196 #ifdef USE_OSD
3197 osd_show_framedropping=10;
3198 vo_osd_changed(OSDTYPE_SUBTITLE);
3199 #endif
3201 else
3202 frame_dropping = v > 2 ? 2 : v;
3203 } break;
3204 #ifdef USE_TV
3205 case MP_CMD_TV_SET_FREQ : {
3206 if (file_format == DEMUXER_TYPE_TV)
3207 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
3208 } break;
3209 case MP_CMD_TV_SET_NORM : {
3210 if (file_format == DEMUXER_TYPE_TV)
3211 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3212 } break;
3213 case MP_CMD_TV_SET_BRIGHTNESS : {
3214 if (file_format == DEMUXER_TYPE_TV)
3215 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
3216 } break;
3217 case MP_CMD_TV_SET_HUE : {
3218 if (file_format == DEMUXER_TYPE_TV)
3219 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
3220 } break;
3221 case MP_CMD_TV_SET_SATURATION : {
3222 if (file_format == DEMUXER_TYPE_TV)
3223 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
3224 } break;
3225 case MP_CMD_TV_SET_CONTRAST : {
3226 if (file_format == DEMUXER_TYPE_TV)
3227 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
3228 } break;
3229 case MP_CMD_TV_STEP_CHANNEL : {
3230 if (file_format == DEMUXER_TYPE_TV) {
3231 int v = cmd->args[0].v.i;
3232 if(v > 0){
3233 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
3234 #ifdef USE_OSD
3235 if (tv_channel_list) {
3236 osd_show_tv_channel = sh_video->fps;
3237 vo_osd_changed(OSDTYPE_SUBTITLE);
3239 #endif
3240 } else {
3241 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
3242 #ifdef USE_OSD
3243 if (tv_channel_list) {
3244 osd_show_tv_channel = sh_video->fps;
3245 vo_osd_changed(OSDTYPE_SUBTITLE);
3247 #endif
3251 #ifdef HAS_DVBIN_SUPPORT
3252 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3254 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3255 if(priv->is_on)
3257 int dir;
3258 int v = cmd->args[0].v.i;
3260 last_dvb_step = v;
3261 if(v > 0)
3262 dir = DVB_CHANNEL_HIGHER;
3263 else
3264 dir = DVB_CHANNEL_LOWER;
3267 if(dvb_step_channel(priv, dir))
3269 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3270 cache_uninit(stream);
3271 goto goto_enable_cache;
3275 #endif
3276 break;
3277 case MP_CMD_TV_SET_CHANNEL : {
3278 if (file_format == DEMUXER_TYPE_TV) {
3279 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3280 #ifdef USE_OSD
3281 if (tv_channel_list) {
3282 osd_show_tv_channel = sh_video->fps;
3283 vo_osd_changed(OSDTYPE_SUBTITLE);
3285 #endif
3287 } break;
3288 #ifdef HAS_DVBIN_SUPPORT
3289 case MP_CMD_DVB_SET_CHANNEL:
3291 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3293 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3294 if(priv->is_on)
3296 if(priv->list->current <= cmd->args[0].v.i)
3297 last_dvb_step = 1;
3298 else
3299 last_dvb_step = -1;
3301 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
3303 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3304 cache_uninit(stream);
3305 goto goto_enable_cache;
3310 #endif
3311 case MP_CMD_TV_LAST_CHANNEL : {
3312 if (file_format == DEMUXER_TYPE_TV) {
3313 tv_last_channel((tvi_handle_t*)(demuxer->priv));
3314 #ifdef USE_OSD
3315 if (tv_channel_list) {
3316 osd_show_tv_channel = sh_video->fps;
3317 vo_osd_changed(OSDTYPE_SUBTITLE);
3319 #endif
3321 } break;
3322 case MP_CMD_TV_STEP_NORM : {
3323 if (file_format == DEMUXER_TYPE_TV)
3324 tv_step_norm((tvi_handle_t*)(demuxer->priv));
3325 } break;
3326 case MP_CMD_TV_STEP_CHANNEL_LIST : {
3327 if (file_format == DEMUXER_TYPE_TV)
3328 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
3329 } break;
3330 #endif
3331 case MP_CMD_SWITCH_VSYNC: {
3332 vo_vsync = ( cmd->nargs > 0 )? cmd->args[0].v.i : !vo_vsync;
3333 } break;
3334 case MP_CMD_VO_FULLSCREEN:
3336 #ifdef HAVE_NEW_GUI
3337 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3338 else
3339 #endif
3340 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3341 } break;
3342 case MP_CMD_VO_ONTOP:
3344 if(video_out && vo_config_count) {
3345 video_out->control(VOCTRL_ONTOP, 0);
3346 #ifdef USE_OSD
3347 osd_show_ontop=10;
3348 vo_osd_changed(OSDTYPE_SUBTITLE);
3349 #endif
3352 } break;
3353 case MP_CMD_VO_ROOTWIN:
3355 if(video_out && vo_config_count) {
3356 video_out->control(VOCTRL_ROOTWIN, 0);
3357 #ifdef USE_OSD
3358 osd_show_rootwin=10;
3359 vo_osd_changed(OSDTYPE_SUBTITLE);
3360 #endif
3363 } break;
3364 case MP_CMD_PANSCAN : {
3365 if ( !video_out ) break;
3366 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3368 int abs= cmd->args[1].v.i;
3369 float v = cmd->args[0].v.f;
3370 float res;
3371 if(abs) res = v;
3372 else res = vo_panscan+v;
3373 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3374 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3375 #ifdef USE_OSD
3376 if(osd_level && sh_video){
3377 osd_visible=sh_video->fps; // 1 sec
3378 vo_osd_progbar_type=OSD_PANSCAN;
3379 vo_osd_progbar_value=vo_panscan*256;
3380 vo_osd_changed(OSDTYPE_PROGBAR);
3382 #endif
3384 } break;
3385 case MP_CMD_SUB_POS:
3387 #ifdef USE_SUB
3388 if (sh_video) {
3389 int v;
3390 v = cmd->args[0].v.i;
3392 sub_pos+=v;
3393 if(sub_pos >100) sub_pos=100;
3394 if(sub_pos <0) sub_pos=0;
3395 vo_osd_changed(OSDTYPE_SUBTITLE);
3396 osd_show_sub_pos = 9;
3398 #endif
3399 } break;
3400 case MP_CMD_SUB_ALIGNMENT:
3402 #ifdef USE_SUB
3403 if (sh_video) {
3404 if (cmd->nargs >= 1)
3405 sub_alignment = cmd->args[0].v.i;
3406 else
3407 sub_alignment = (sub_alignment+1) % 3;
3408 osd_show_sub_alignment = 9;
3409 vo_osd_changed(OSDTYPE_SUBTITLE);
3411 #endif
3412 } break;
3413 case MP_CMD_SUB_VISIBILITY:
3415 #ifdef USE_SUB
3416 if (sh_video) {
3417 sub_visibility=1-sub_visibility;
3418 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3419 vo_osd_changed(OSDTYPE_SUBTITLE);
3421 #endif
3422 } break;
3423 case MP_CMD_SUB_LOAD:
3425 #ifdef USE_SUB
3426 if (sh_video) {
3427 int n = set_of_sub_size;
3428 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
3429 if (n != set_of_sub_size) {
3430 if (global_sub_indices[SUB_SOURCE_SUBS] < 0)
3431 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size;
3432 ++global_sub_size;
3435 #endif
3436 } break;
3437 case MP_CMD_SUB_REMOVE:
3439 #ifdef USE_SUB
3440 if (sh_video) {
3441 int v = cmd->args[0].v.i;
3442 sub_data *subd;
3443 if (v < 0) {
3444 for (v = 0; v < set_of_sub_size; ++v) {
3445 subd = set_of_subtitles[v];
3446 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
3447 sub_free(subd);
3448 set_of_subtitles[v] = NULL;
3450 global_sub_indices[SUB_SOURCE_SUBS] = -1;
3451 global_sub_size -= set_of_sub_size;
3452 set_of_sub_size = 0;
3453 if (set_of_sub_pos >= 0) {
3454 global_sub_pos = -2;
3455 vo_sub_last = vo_sub = NULL;
3456 vo_osd_changed(OSDTYPE_SUBTITLE);
3457 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
3458 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3461 else if (v < set_of_sub_size) {
3462 subd = set_of_subtitles[v];
3463 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
3464 sub_free(subd);
3465 if (set_of_sub_pos == v) {
3466 global_sub_pos = -2;
3467 vo_sub_last = vo_sub = NULL;
3468 vo_osd_changed(OSDTYPE_SUBTITLE);
3469 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
3470 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3472 else if (set_of_sub_pos > v) {
3473 --set_of_sub_pos;
3474 --global_sub_pos;
3476 while (++v < set_of_sub_size)
3477 set_of_subtitles[v - 1] = set_of_subtitles[v];
3478 --set_of_sub_size;
3479 --global_sub_size;
3480 if (set_of_sub_size <= 0)
3481 global_sub_indices[SUB_SOURCE_SUBS] = -1;
3482 set_of_subtitles[set_of_sub_size] = NULL;
3485 #endif
3486 } break;
3487 case MP_CMD_GET_SUB_VISIBILITY:
3489 #ifdef USE_SUB
3490 if (sh_video) {
3491 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%ld\n", sub_visibility);
3493 #endif
3494 } break;
3495 case MP_CMD_SUB_SELECT:
3496 if (global_sub_size) {
3497 int source = -1;
3498 int v = cmd->args[0].v.i;
3500 if (v < -1)
3501 global_sub_pos++;
3502 else
3503 global_sub_pos = v;
3504 if (global_sub_pos >= global_sub_size)
3505 global_sub_pos = -1;
3506 if (global_sub_pos >= 0)
3507 source = sub_source();
3509 mp_msg(MSGT_CPLAYER, MSGL_DBG3, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3510 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
3511 global_sub_indices[SUB_SOURCE_SUBS], global_sub_indices[SUB_SOURCE_DEMUX],
3512 global_sub_pos, source);
3514 #ifdef USE_SUB
3515 set_of_sub_pos = -1;
3516 subdata = NULL;
3517 vo_sub_last = vo_sub = NULL;
3518 #endif
3519 vobsub_id = -1;
3520 dvdsub_id = -1;
3521 if (d_dvdsub) d_dvdsub->id = -1;
3523 // be careful!
3524 // if sub_changed is till on but subdata's been reset, bad things happen.
3525 osd_show_vobsub_changed = 0;
3526 osd_show_sub_changed = 0;
3528 if (source == SUB_SOURCE_VOBSUB) {
3529 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
3530 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3531 #ifdef USE_SUB
3532 } else if (source == SUB_SOURCE_SUBS) {
3533 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
3534 subdata = set_of_subtitles[set_of_sub_pos];
3535 if (!global_sub_quiet_osd_hack) osd_show_sub_changed = sh_video->fps;
3536 vo_osd_changed(OSDTYPE_SUBTITLE);
3538 // FIXME: is this the correct place for these?
3539 if(stream_dump_type==3) list_sub_file(subdata);
3540 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
3541 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
3542 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
3543 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
3544 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
3545 #endif
3546 } else if (source == SUB_SOURCE_DEMUX) {
3547 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
3548 if (d_dvdsub) {
3549 #ifdef USE_DVDREAD
3550 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
3551 d_dvdsub->id = dvdsub_id;
3552 spudec_reset(vo_spudec);
3554 #endif
3555 #ifdef HAVE_OGGVORBIS
3556 if (demuxer->type == DEMUXER_TYPE_OGG)
3557 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
3558 #endif
3559 #ifdef HAVE_MATROSKA
3560 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3561 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
3562 if (d_dvdsub->id >= 0 && ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
3563 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
3564 if (vo_spudec != NULL)
3565 spudec_free(vo_spudec);
3566 vo_spudec =
3567 spudec_new_scaled_vobsub(mkv_sh_sub->has_palette ? mkv_sh_sub->palette : NULL, mkv_sh_sub->colors,
3568 mkv_sh_sub->custom_colors,
3569 mkv_sh_sub->width,
3570 mkv_sh_sub->height);
3571 if (!forced_subs_only)
3572 forced_subs_only = mkv_sh_sub->forced_subs_only;
3573 if (vo_spudec) {
3574 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
3575 inited_flags |= INITED_SPUDEC;
3579 #endif
3581 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3582 } else { // off
3583 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3584 #ifdef USE_SUB
3585 vo_osd_changed(OSDTYPE_SUBTITLE);
3586 #endif
3588 // it's annoying and dumb to show osd saying "off" at every subless file...
3589 global_sub_quiet_osd_hack = 0;
3591 break;
3592 case MP_CMD_SUB_FORCED_ONLY:
3593 if (vo_spudec) {
3594 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3595 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3597 break;
3598 case MP_CMD_SCREENSHOT :
3599 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3600 break;
3601 case MP_CMD_VF_CHANGE_RECTANGLE:
3602 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3603 break;
3605 case MP_CMD_GET_TIME_LENGTH : {
3606 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
3607 } break;
3609 case MP_CMD_GET_VO_FULLSCREEN : {
3610 if(video_out && vo_config_count)
3611 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VO_FULLSCREEN=%ld\n", vo_fs);
3612 } break;
3614 case MP_CMD_GET_PERCENT_POS : {
3615 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer));
3616 } break;
3617 case MP_CMD_GET_TIME_POS : {
3618 float pos = 0;
3619 if (sh_video)
3620 pos = sh_video->pts;
3621 else
3622 if (sh_audio && audio_out)
3623 pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
3624 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3625 } break;
3626 case MP_CMD_SWITCH_AUDIO : {
3627 int v = demuxer_switch_audio(demuxer, cmd->args[0].v.i);
3628 if (identify)
3629 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", v);
3630 } break;
3631 case MP_CMD_RUN : {
3632 #ifndef __MINGW32__
3633 if(!fork()) {
3634 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
3635 exit(0);
3637 #endif
3638 } break;
3640 #ifdef USE_DVDNAV
3641 case MP_CMD_DVDNAV_EVENT: {
3642 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3643 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3645 /* ignore these events if we're not in dvd_nav mode */
3646 if (stream->type != STREAMTYPE_DVDNAV) break;
3648 if (!dvdnav_event) {
3649 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNullEvent);
3650 break;
3653 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3655 switch (dvdnav_event->event) {
3656 case DVDNAV_BLOCK_OK: {
3657 /* be silent about this one */
3658 break;
3660 case DVDNAV_HIGHLIGHT: {
3661 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3662 if (!hevent) {
3663 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightEventBroken);
3664 break;
3667 if (hevent->display && hevent->buttonN>0)
3669 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3670 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3671 hevent->buttonN,
3672 hevent->sx,hevent->sy,
3673 hevent->ex,hevent->ey,
3674 hevent->pts, d_video->pts);
3675 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavEvent,dvd_nav_text);
3676 //osd_show_dvd_nav_delay = 60;
3678 osd_show_dvd_nav_highlight=1;
3679 osd_show_dvd_nav_sx=hevent->sx;
3680 osd_show_dvd_nav_ex=hevent->ex;
3681 osd_show_dvd_nav_sy=hevent->sy;
3682 osd_show_dvd_nav_ey=hevent->ey;
3684 else {
3685 osd_show_dvd_nav_highlight=0;
3686 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightHide);
3688 break;
3690 case DVDNAV_STILL_FRAME: {
3691 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3693 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavStillFrame, still_event->length );
3694 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3695 usec_sleep(1000); /* 1ms */
3697 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3698 break;
3700 case DVDNAV_STOP: {
3701 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavStop );
3702 break;
3704 case DVDNAV_NOP: {
3705 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavNOP);
3706 break;
3708 case DVDNAV_SPU_STREAM_CHANGE: {
3709 #if DVDNAVVERSION > 012
3710 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3712 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChangeVerbose,
3713 stream_change->physical_wide,
3714 stream_change->physical_letterbox,
3715 stream_change->physical_pan_scan,
3716 stream_change->logical);
3718 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3719 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3720 d_dvdsub->id,stream_change->physical_wide);
3721 // FIXME: need a better way to change SPU id
3722 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3723 if (vo_spudec) spudec_reset(vo_spudec);
3725 #else
3726 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3728 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChange,
3729 stream_change->physical,
3730 stream_change->logical);
3732 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3733 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3734 d_dvdsub->id,stream_change->physical);
3735 // FIXME: need a better way to change SPU id
3736 d_dvdsub->id=dvdsub_id=stream_change->physical;
3737 if (vo_spudec) spudec_reset(vo_spudec);
3739 #endif
3740 break;
3742 case DVDNAV_AUDIO_STREAM_CHANGE: {
3743 int aid_temp;
3744 #if DVDNAVVERSION > 012
3745 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3746 #else
3747 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3748 #endif
3750 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavAudioStreamChange,
3751 stream_change->physical,
3752 stream_change->logical);
3754 aid_temp=stream_change->physical;
3755 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3756 if (d_audio && audio_id!=aid_temp) {
3757 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3758 d_audio->id,aid_temp);
3759 // FIXME: need a bettery way to change audio stream id
3760 d_audio->id=dvdsub_id=aid_temp;
3761 if(sh_audio) resync_audio_stream(sh_audio);
3764 break;
3766 case DVDNAV_VTS_CHANGE: {
3767 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavVTSChange);
3768 break;
3770 case DVDNAV_CELL_CHANGE: {
3771 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3772 cell_playback_t * cell_playback = cell_change->new_cell;
3774 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavCellChange);
3775 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3777 printf("new still time: %d\n",cell_playback->still_time);
3778 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3779 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3780 cell_playback->playback_time.hour,
3781 cell_playback->playback_time.minute,
3782 cell_playback->playback_time.second,
3783 cell_playback->playback_time.frame_u);
3786 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3787 //abs_seek_pos=0;
3788 break;
3790 case DVDNAV_NAV_PACKET: {
3791 // printf("DVDNAV Event: Nav Packet\n");
3792 break;
3794 case DVDNAV_SPU_CLUT_CHANGE: {
3795 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3797 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuClutChange);
3798 // send new palette to SPU decoder
3799 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3801 break;
3803 case DVDNAV_SEEK_DONE: {
3804 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSeekDone);
3805 break;
3809 // free the dvdnav event
3810 free(dvdnav_event->details);
3811 free(dvdnav_event);
3812 cmd->args[0].v.v=NULL;
3814 case MP_CMD_DVDNAV: {
3815 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3817 /* ignore these events if we're not in dvd_nav mode */
3818 if (stream->type != STREAMTYPE_DVDNAV) break;
3820 switch (cmd->args[0].v.i) {
3821 case MP_CMD_DVDNAV_UP:
3822 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3823 break;
3824 case MP_CMD_DVDNAV_DOWN:
3825 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3826 break;
3827 case MP_CMD_DVDNAV_LEFT:
3828 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3829 break;
3830 case MP_CMD_DVDNAV_RIGHT:
3831 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3832 break;
3833 case MP_CMD_DVDNAV_MENU:
3834 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_MenuCall);
3835 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3836 break;
3837 case MP_CMD_DVDNAV_SELECT:
3838 dvdnav_button_activate(dvdnav_priv->dvdnav);
3839 break;
3840 default:
3841 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3842 break;
3844 break;
3846 #endif
3847 default : {
3848 #ifdef HAVE_NEW_GUI
3849 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3850 else
3851 #endif
3852 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3855 if (cmd->pausing)
3856 osd_function = OSD_PAUSE;
3857 mp_cmd_free(cmd);
3861 if (seek_to_sec) {
3862 int a,b; float d;
3864 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3865 rel_seek_secs += 3600*a +60*b +d ;
3866 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3867 rel_seek_secs += 60*a +d;
3868 else if (sscanf(seek_to_sec, "%f", &d)==1)
3869 rel_seek_secs += d;
3871 seek_to_sec = NULL;
3874 /* Looping. */
3875 if(eof==1 && loop_times>=0) {
3876 int l = loop_times;
3877 play_tree_iter_step(playtree_iter,0,0);
3878 loop_times = l;
3879 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3881 if(loop_times>1) loop_times--; else
3882 if(loop_times==1) loop_times=-1;
3883 play_n_frames=play_n_frames_mf;
3884 eof=0;
3885 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3886 loop_seek = 1;
3889 if(rel_seek_secs || abs_seek_pos){
3890 current_module="seek";
3891 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3892 // success:
3893 /* FIXME there should be real seeking for vobsub */
3894 if(sh_video) sh_video->pts=d_video->pts;
3895 if (vo_vobsub)
3896 //vobsub_reset(vo_vobsub);
3897 vobsub_seek(vo_vobsub,sh_video->pts);
3898 #if 0
3899 if(sh_video && d_video->packs == 0)
3900 ds_fill_buffer(d_video);
3901 if(sh_audio){
3902 if(d_audio->packs == 0)
3903 ds_fill_buffer(d_audio);
3904 if(verbose>0){
3905 float a_pts=d_audio->pts;
3906 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3907 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);
3909 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);
3910 } else {
3911 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3913 #endif
3914 fflush(stdout);
3916 if(sh_video){
3917 current_module="seek_video_reset";
3918 resync_video_stream(sh_video);
3919 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3922 if(sh_audio){
3923 current_module="seek_audio_reset";
3924 audio_out->reset(); // stop audio, throwing away buffered data
3926 #ifdef USE_OSD
3927 // Set OSD:
3928 if(osd_level && !loop_seek){
3929 #ifdef USE_EDL
3930 if( !edl_decision ) {
3931 #else
3932 if( 1 ) { // Let the compiler optimize this out
3933 #endif
3934 if (sh_video) {
3935 osd_visible=sh_video->fps; // 1 sec
3936 vo_osd_progbar_type=0;
3937 vo_osd_progbar_value=demuxer_get_percent_pos(demuxer) * 256 / 100;
3938 vo_osd_changed(OSDTYPE_PROGBAR);
3942 #endif
3943 if(sh_video) {
3944 c_total=0;
3945 max_pts_correction=0.1;
3946 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3947 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3948 drop_frame_cnt=0;
3949 too_slow_frame_cnt=0;
3950 too_fast_frame_cnt=0;
3952 if(vo_spudec) spudec_reset(vo_spudec);
3955 #ifdef USE_EDL
3957 * We saw a seek, have to rewind the EDL operations stack
3958 * and find the next EDL action to take care of.
3961 edl_muted = 0;
3962 next_edl_record = edl_records;
3964 while (next_edl_record)
3966 /* Trying to remember if we need to mute/unmute first;
3967 * prior EDL implementation lacks this.
3970 if (next_edl_record->start_sec >= sh_video->pts)
3971 break;
3973 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
3974 next_edl_record = next_edl_record->next;
3977 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
3978 #endif
3979 rel_seek_secs=0;
3980 abs_seek_pos=0;
3981 frame_time_remaining=0;
3982 current_module=NULL;
3983 loop_seek=0;
3986 #ifdef HAVE_NEW_GUI
3987 if(use_gui){
3988 guiEventHandling();
3989 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3990 // get pos from frame number / total frames
3991 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3992 } else {
3993 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3994 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3995 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3997 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3998 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3999 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
4000 guiGetEvent( guiReDraw,NULL );
4001 guiGetEvent( guiSetVolume,NULL );
4002 if(guiIntfStruct.Playing==0) break; // STOP
4003 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
4004 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
4005 #ifdef USE_DVDREAD
4006 if ( stream->type == STREAMTYPE_DVD )
4008 dvd_priv_t * dvdp = stream->priv;
4009 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
4011 #endif
4013 #endif
4016 //================= Update OSD ====================
4017 #ifdef USE_OSD
4018 if(osd_level>=1 && sh_video){
4019 int pts=sh_video->pts;
4020 char osd_text_tmp[64];
4021 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
4022 vo_osd_text=osd_text_buffer;
4023 #ifdef USE_DVDNAV
4024 if (osd_show_dvd_nav_delay) {
4025 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
4026 osd_show_dvd_nav_delay--;
4027 } else
4028 #endif
4029 #ifdef USE_TV
4030 if (osd_show_tv_channel && tv_channel_list) {
4031 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
4032 osd_show_tv_channel--;
4033 } else
4034 #endif
4035 if (osd_show_text) {
4036 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
4037 osd_show_text--;
4038 } else
4039 if (osd_show_sub_visibility) {
4040 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
4041 osd_show_sub_visibility--;
4042 } else
4043 if (osd_show_vobsub_changed) {
4044 snprintf(osd_text_tmp, 63, "Subtitles: off");
4045 if (vo_vobsub && vobsub_id >= 0) {
4046 const char *language = "none";
4047 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
4048 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
4050 #ifdef HAVE_OGGVORBIS
4051 if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG) {
4052 if (dvdsub_id >= 0) {
4053 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
4054 if (!lang) lang = "unknown";
4055 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4058 #endif
4059 #ifdef USE_DVDREAD
4060 if (vo_spudec && (demuxer->type != DEMUXER_TYPE_MATROSKA)) {
4061 if (dvdsub_id >= 0) {
4062 char lang[5] = "none";
4063 int code = 0;
4064 code = dvd_lang_from_sid(stream, dvdsub_id);
4065 if (code) {
4066 lang[0] = code >> 8;
4067 lang[1] = code;
4068 lang[2] = 0;
4070 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4073 #endif
4074 #ifdef HAVE_MATROSKA
4075 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
4076 char lang[10] = "unknown";
4077 if (dvdsub_id >= 0) {
4078 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
4079 lang[9] = 0;
4080 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4083 #endif
4084 osd_show_vobsub_changed--;
4085 } else
4086 #ifdef USE_SUB
4087 if (osd_show_sub_changed) {
4088 char *tmp2;
4089 tmp = subdata->filename;
4090 if ((tmp2 = strrchr(tmp, '/'))) {
4091 tmp = tmp2+1;
4093 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
4094 set_of_sub_pos + 1,
4095 strlen(tmp) < 20 ? "" : "...",
4096 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
4097 osd_show_sub_changed--;
4098 } else
4099 #endif
4100 if (osd_show_sub_delay) {
4101 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
4102 osd_show_sub_delay--;
4103 } else
4104 if (osd_show_sub_pos) {
4105 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
4106 osd_show_sub_pos--;
4107 } else
4108 if (osd_show_sub_alignment) {
4109 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
4110 (sub_alignment == 2 ? "bottom" :
4111 (sub_alignment == 1 ? "center" : "top")));
4112 osd_show_sub_alignment--;
4113 } else
4114 if (osd_show_av_delay) {
4115 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
4116 osd_show_av_delay--;
4117 } else if (osd_show_speed) {
4118 snprintf(osd_text_tmp, 63, "Speed: x %6.2f", playback_speed);
4119 osd_show_speed--;
4120 } else if (osd_show_ontop) {
4121 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
4122 osd_show_ontop--;
4123 } else if (osd_show_rootwin) {
4124 snprintf(osd_text_tmp, 63, "Rootwin: %sabled", vo_rootwin?"en":"dis");
4125 osd_show_rootwin--;
4126 } else if (osd_show_framedropping) {
4127 snprintf(osd_text_tmp, 63, "Framedropping: %s",
4128 (frame_dropping == 1 ? "on" :
4129 (frame_dropping == 2 ? "hard" : "off")));
4130 osd_show_framedropping--;
4131 } else if(osd_level>=2) {
4132 int len = demuxer_get_time_length(demuxer);
4133 int percentage = -1;
4134 char percentage_text[10];
4135 if (osd_show_percentage) {
4136 percentage = demuxer_get_percent_pos(demuxer);
4137 osd_show_percentage--;
4139 if (percentage >= 0)
4140 snprintf(percentage_text, 9, " (%d%%)", percentage);
4141 else
4142 percentage_text[0] = 0;
4143 if (osd_level == 3)
4144 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);
4145 else
4146 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
4147 } else osd_text_tmp[0]=0;
4149 if(strcmp(vo_osd_text, osd_text_tmp)) {
4150 strncpy(vo_osd_text, osd_text_tmp, 63);
4151 vo_osd_changed(OSDTYPE_OSD);
4153 } else {
4154 if(vo_osd_text) {
4155 vo_osd_text=NULL;
4156 vo_osd_changed(OSDTYPE_OSD);
4159 if (osd_level <= 1 && osd_show_status > 0 && sh_video) {
4160 vo_osd_text = osd_text_buffer;
4161 snprintf(vo_osd_text, 63, "OSD: %sabled", osd_level ? "en" : "dis");
4162 vo_osd_changed(OSDTYPE_OSD);
4163 osd_show_status--;
4165 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
4166 // vo_osd_text=osd_text_buffer;
4167 #endif
4169 #ifdef USE_SUB
4170 // find sub
4171 if(subdata && sh_video && sh_video->pts>0){
4172 float pts=sh_video->pts;
4173 if(sub_fps==0) sub_fps=sh_video->fps;
4174 current_module="find_sub";
4175 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
4176 find_sub(subdata, (pts+sub_delay) *
4177 (subdata->sub_uses_time ? 100. : sub_fps));
4178 if (vo_sub) vo_sub_last = vo_sub;
4179 // FIXME! frame counter...
4180 sub_last_pts = pts;
4182 current_module=NULL;
4184 #endif
4186 #ifdef HAVE_X11
4187 if (stop_xscreensaver && sh_video) {
4188 current_module="stop_xscreensaver";
4189 xscreensaver_heartbeat();
4190 current_module=NULL;
4192 #endif
4194 // DVD sub:
4195 if(vo_config_count && vo_spudec) {
4196 unsigned char* packet=NULL;
4197 int len,timestamp;
4198 current_module="spudec";
4199 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
4200 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
4201 while(1) {
4202 // Vobsub
4203 len = 0;
4204 if(vo_vobsub) {
4205 if(sh_video->pts+sub_delay>=0) {
4206 // The + next_frame_time is there because we'll display the sub at the next frame
4207 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
4208 if(len > 0) {
4209 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
4210 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);
4213 } else {
4214 // DVD sub
4215 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
4216 if(len > 0) {
4217 float x = d_dvdsub->pts - sh_video->pts;
4218 if (x < -10 || x > 10) // prevent missing subs on pts reset
4219 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
4220 else timestamp = 90000*(sh_video->timer + sub_delay);
4221 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);
4224 if(len<=0 || !packet) break;
4225 if(timestamp < 0) timestamp = 0;
4226 else spudec_assemble(vo_spudec,packet,len,timestamp);
4229 /* detect wether the sub has changed or not */
4230 if(spudec_changed(vo_spudec))
4231 vo_osd_changed(OSDTYPE_SPU);
4232 current_module=NULL;
4235 } // while(!eof)
4237 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
4241 goto_next_file: // don't jump here after ao/vo/getch initialization!
4243 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
4245 if(benchmark){
4246 double tot=video_time_usage+vout_time_usage+audio_time_usage;
4247 double total_time_usage;
4248 total_time_usage_start=GetTimer()-total_time_usage_start;
4249 total_time_usage = (float)total_time_usage_start*0.000001;
4250 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4251 video_time_usage,vout_time_usage,audio_time_usage,
4252 total_time_usage-tot,total_time_usage);
4253 if(total_time_usage>0.0)
4254 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4255 100.0*video_time_usage/total_time_usage,
4256 100.0*vout_time_usage/total_time_usage,
4257 100.0*audio_time_usage/total_time_usage,
4258 100.0*(total_time_usage-tot)/total_time_usage,
4259 100.0);
4260 if(total_frame_cnt && frame_dropping)
4261 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4262 total_frame_cnt-drop_frame_cnt,
4263 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
4264 drop_frame_cnt,
4265 100*drop_frame_cnt/total_frame_cnt,
4266 total_frame_cnt,
4267 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
4271 // time to uninit all, except global stuff:
4272 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
4274 #ifdef USE_SUB
4275 if ( set_of_sub_size > 0 )
4277 current_module="sub_free";
4278 for (i = 0; i < set_of_sub_size; ++i)
4279 sub_free( set_of_subtitles[i] );
4280 set_of_sub_size = 0;
4281 vo_sub_last = vo_sub=NULL;
4282 subdata=NULL;
4284 #endif
4286 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
4287 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
4288 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
4289 eof = 1;
4290 } else {
4291 play_tree_iter_free(playtree_iter);
4292 playtree_iter = NULL;
4294 play_tree_step = 1;
4295 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
4296 eof = eof == PT_UP_NEXT ? 1 : -1;
4297 if ( playtree_iter ) {
4298 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
4299 eof = 1;
4300 } else {
4301 play_tree_iter_free(playtree_iter);
4302 playtree_iter = NULL;
4305 } else { // NEXT PREV SRC
4306 eof = eof == PT_PREV_SRC ? -1 : 1;
4309 if(eof == 0) eof = 1;
4311 while(playtree_iter != NULL) {
4312 filename = play_tree_iter_get_file(playtree_iter,eof);
4313 if(filename == NULL) {
4314 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
4315 play_tree_iter_free(playtree_iter);
4316 playtree_iter = NULL;
4318 } else
4319 break;
4322 #ifdef HAVE_NEW_GUI
4323 if( use_gui && !playtree_iter )
4325 #ifdef USE_DVDREAD
4326 if ( !guiIntfStruct.DiskChanged )
4327 #endif
4328 mplEnd();
4330 #endif
4332 if(use_gui || playtree_iter != NULL){
4334 eof = 0;
4335 goto play_next_file;
4339 exit_player_with_rc(MSGTR_Exit_eof, 0);
4341 return 1;