fix detection of iconv implementations which require libdl
[mplayer.git] / mplayer.c
blobca8be17f8c6aec87baf1da408dd755d054ddeb6c
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 // streaming:
253 int audio_id=-1;
254 int video_id=-1;
255 int dvdsub_id=-1;
256 int vobsub_id=-1;
257 char* audio_lang=NULL;
258 char* dvdsub_lang=NULL;
259 static char* spudec_ifo=NULL;
260 char* filename=NULL; //"MI2-Trailer.avi";
261 int forced_subs_only=0;
263 // cache2:
264 int stream_cache_size=-1;
265 #ifdef USE_STREAM_CACHE
266 extern int cache_fill_status;
268 float stream_cache_min_percent=20.0;
269 float stream_cache_prefill_percent=5.0;
270 #else
271 #define cache_fill_status 0
272 #endif
274 // dump:
275 static char *stream_dump_name="stream.dump";
276 int stream_dump_type=0;
278 // A-V sync:
279 static float default_max_pts_correction=-1;//0.01f;
280 static float max_pts_correction=0;//default_max_pts_correction;
281 static float c_total=0;
282 float audio_delay=0;
284 static int softsleep=0;
286 float force_fps=0;
287 static int force_srate=0;
288 static int audio_output_format=0;
289 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
290 static int play_n_frames=-1;
291 static int play_n_frames_mf=-1;
293 // screen info:
294 char** video_driver_list=NULL;
295 char** audio_driver_list=NULL;
297 extern char *vo_subdevice;
298 extern char *ao_subdevice;
300 // codec outfmt flags (defined in libmpcodecs/vd.c)
301 extern int vo_flags;
303 // sub:
304 char *font_name=NULL;
305 #ifdef HAVE_FONTCONFIG
306 extern int font_fontconfig;
307 #endif
308 float font_factor=0.75;
309 char **sub_name=NULL;
310 float sub_delay=0;
311 float sub_fps=0;
312 int sub_auto = 1;
313 char *vobsub_name=NULL;
314 /*DSP!!char *dsp=NULL;*/
315 int subcc_enabled=0;
316 int suboverlap_enabled = 1;
317 #ifdef USE_SUB
318 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
319 int set_of_sub_size = 0;
320 int set_of_sub_pos = -1;
321 float sub_last_pts = -303;
322 #endif
323 int global_sub_size = 0; // this encompasses all subtitle sources
324 int global_sub_pos = -1; // this encompasses all subtitle sources
325 #define SUB_SOURCE_SUBS 0
326 #define SUB_SOURCE_VOBSUB 1
327 #define SUB_SOURCE_DEMUX 2
328 #define SUB_SOURCES 3
329 int global_sub_indices[SUB_SOURCES];
330 int global_sub_quiet_osd_hack = 0;
332 static stream_t* stream=NULL;
333 static demuxer_t *demuxer=NULL;
334 static sh_audio_t *sh_audio=NULL;
335 static sh_video_t *sh_video=NULL;
337 char* current_module=NULL; // for debugging
339 extern int vo_gamma_gamma;
340 extern int vo_gamma_brightness;
341 extern int vo_gamma_contrast;
342 extern int vo_gamma_saturation;
343 extern int vo_gamma_hue;
345 // ---
347 #ifdef HAVE_MENU
348 #include "m_struct.h"
349 #include "libmenu/menu.h"
350 extern void vf_menu_pause_update(struct vf_instance_s* vf);
351 extern vf_info_t vf_info_menu;
352 static vf_info_t* libmenu_vfs[] = {
353 &vf_info_menu,
354 NULL
356 static vf_instance_t* vf_menu = NULL;
357 static int use_menu = 0;
358 static char* menu_cfg = NULL;
359 static char* menu_root = "main";
360 #endif
363 #ifdef HAVE_RTC
364 static int nortc;
365 static char* rtc_device;
366 #endif
368 #ifdef USE_EDL
369 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
370 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
371 short user_muted = 0; ///< Stores whether User wanted muted mode.
372 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
373 short edl_decision = 0; ///< 1 when an EDL operation has been made
374 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode
375 #endif
377 static unsigned int inited_flags=0;
378 #define INITED_VO 1
379 #define INITED_AO 2
380 #define INITED_GUI 4
381 #define INITED_GETCH2 8
382 #define INITED_SPUDEC 32
383 #define INITED_STREAM 64
384 #define INITED_INPUT 128
385 #define INITED_VOBSUB 256
386 #define INITED_DEMUXER 512
387 #define INITED_ACODEC 1024
388 #define INITED_VCODEC 2048
389 #define INITED_ALL 0xFFFF
391 static void uninit_player(unsigned int mask){
392 mask=inited_flags&mask;
394 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
396 if(mask&INITED_ACODEC){
397 inited_flags&=~INITED_ACODEC;
398 current_module="uninit_acodec";
399 if(sh_audio) uninit_audio(sh_audio);
400 #ifdef HAVE_NEW_GUI
401 guiGetEvent(guiSetAfilter, (char *)NULL);
402 #endif
403 sh_audio=NULL;
406 if(mask&INITED_VCODEC){
407 inited_flags&=~INITED_VCODEC;
408 current_module="uninit_vcodec";
409 if(sh_video) uninit_video(sh_video);
410 sh_video=NULL;
411 #ifdef HAVE_MENU
412 vf_menu=NULL;
413 #endif
416 if(mask&INITED_DEMUXER){
417 inited_flags&=~INITED_DEMUXER;
418 current_module="free_demuxer";
419 if(demuxer){
420 stream=demuxer->stream;
421 free_demuxer(demuxer);
423 demuxer=NULL;
426 // kill the cache process:
427 if(mask&INITED_STREAM){
428 inited_flags&=~INITED_STREAM;
429 current_module="uninit_stream";
430 if(stream) free_stream(stream);
431 stream=NULL;
434 if(mask&INITED_VO){
435 inited_flags&=~INITED_VO;
436 current_module="uninit_vo";
437 video_out->uninit();
438 video_out=NULL;
441 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
442 if(mask&INITED_GETCH2){
443 inited_flags&=~INITED_GETCH2;
444 current_module="uninit_getch2";
445 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
446 // restore terminal:
447 getch2_disable();
450 if(mask&INITED_VOBSUB){
451 inited_flags&=~INITED_VOBSUB;
452 current_module="uninit_vobsub";
453 if(vo_vobsub) vobsub_close(vo_vobsub);
454 vo_vobsub=NULL;
457 if (mask&INITED_SPUDEC){
458 inited_flags&=~INITED_SPUDEC;
459 current_module="uninit_spudec";
460 spudec_free(vo_spudec);
461 vo_spudec=NULL;
464 if(mask&INITED_AO){
465 inited_flags&=~INITED_AO;
466 current_module="uninit_ao";
467 audio_out->uninit(eof?0:1); audio_out=NULL;
470 #ifdef HAVE_NEW_GUI
471 if(mask&INITED_GUI){
472 inited_flags&=~INITED_GUI;
473 current_module="uninit_gui";
474 guiDone();
476 #endif
478 if(mask&INITED_INPUT){
479 inited_flags&=~INITED_INPUT;
480 current_module="uninit_input";
481 mp_input_uninit();
484 current_module=NULL;
487 static void exit_player_with_rc(char* how, int rc){
489 uninit_player(INITED_ALL);
490 #ifdef HAVE_X11
491 #ifdef HAVE_NEW_GUI
492 if ( !use_gui )
493 #endif
494 vo_uninit(); // close the X11 connection (if any opened)
495 #endif
497 #ifdef HAVE_FREETYPE
498 current_module="uninit_font";
499 if (vo_font) free_font_desc(vo_font);
500 vo_font = NULL;
501 done_freetype();
502 #endif
503 free_osd_list();
505 current_module="exit_player";
507 // free mplayer config
508 if(mconfig)
509 m_config_free(mconfig);
511 if(playtree)
512 play_tree_free(playtree, 1);
515 #ifdef USE_EDL
516 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
517 #endif
518 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));
519 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
521 exit(rc);
524 void exit_player(char* how){
525 exit_player_with_rc(how, 1);
528 #ifndef __MINGW32__
529 static void child_sighandler(int x){
530 pid_t pid;
531 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
533 #endif
535 #ifdef CRASH_DEBUG
536 static char *prog_path;
537 static int crash_debug = 0;
538 #endif
540 static void exit_sighandler(int x){
541 static int sig_count=0;
542 #ifdef CRASH_DEBUG
543 if (!crash_debug || x != SIGTRAP)
544 #endif
545 ++sig_count;
546 if(inited_flags==0 && sig_count>1) exit(1);
547 if(sig_count==5)
549 /* We're crashing bad and can't uninit cleanly :(
550 * by popular request, we make one last (dirty)
551 * effort to restore the user's
552 * terminal. */
553 getch2_disable();
554 exit(1);
556 if(sig_count==6) exit(1);
557 if(sig_count>6){
558 // can't stop :(
559 #ifndef __MINGW32__
560 kill(getpid(),SIGKILL);
561 #endif
563 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
564 current_module?current_module:mp_gettext("unknown")
566 if(sig_count<=1)
567 switch(x){
568 case SIGINT:
569 case SIGQUIT:
570 case SIGTERM:
571 case SIGKILL:
572 break; // killed from keyboard (^C) or killed [-9]
573 case SIGILL:
574 #ifdef RUNTIME_CPUDETECT
575 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
576 #else
577 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
578 #endif
579 case SIGFPE:
580 case SIGSEGV:
581 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
582 default:
583 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
584 #ifdef CRASH_DEBUG
585 if (crash_debug) {
586 int gdb_pid;
587 char spid[20];
588 snprintf(spid, 19, "%i", getpid());
589 spid[19] = 0;
590 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
591 gdb_pid = fork();
592 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
593 if (gdb_pid == 0) { // We are the child
594 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
595 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
596 } else if (gdb_pid < 0)
597 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
598 else {
599 waitpid(gdb_pid, NULL, 0);
601 if (x == SIGTRAP) return;
603 #endif
605 exit_player(NULL);
608 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
610 extern void mp_input_register_options(m_config_t* cfg);
612 #include "mixer.h"
613 mixer_t mixer;
614 /// step size of mixer changes
615 int volstep = 3;
617 #include "cfg-mplayer.h"
619 void parse_cfgfiles( m_config_t* conf )
621 char *conffile;
622 int conffile_fd;
623 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
624 exit_player(NULL);
625 if ((conffile = get_path("")) == NULL) {
626 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
627 } else {
628 #ifdef __MINGW32__
629 mkdir(conffile);
630 #else
631 mkdir(conffile, 0777);
632 #endif
633 free(conffile);
634 if ((conffile = get_path("config")) == NULL) {
635 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
636 } else {
637 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
638 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
639 write(conffile_fd, default_config, strlen(default_config));
640 close(conffile_fd);
642 if (m_config_parse_config_file(conf, conffile) < 0)
643 exit_player(NULL);
644 free(conffile);
649 void load_per_file_config (m_config_t* conf, const char *const file)
651 char *confpath;
652 char cfg[strlen(file)+10];
653 struct stat st;
654 char *name;
656 sprintf (cfg, "%s.conf", file);
658 if (!stat (cfg, &st))
660 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
661 m_config_parse_config_file (conf, cfg);
662 return;
665 if ((name = strrchr (cfg, '/')) == NULL)
666 name = cfg;
667 else
668 name++;
670 if ((confpath = get_path (name)) != NULL)
672 if (!stat (confpath, &st))
674 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
675 m_config_parse_config_file (conf, confpath);
678 free (confpath);
682 // When libmpdemux perform a blocking operation (network connection or cache filling)
683 // if the operation fail we use this function to check if it was interrupted by the user.
684 // The function return a new value for eof.
685 static int libmpdemux_was_interrupted(int eof) {
686 mp_cmd_t* cmd;
687 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
688 switch(cmd->id) {
689 case MP_CMD_QUIT:
690 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
691 case MP_CMD_PLAY_TREE_STEP: {
692 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
693 } break;
694 case MP_CMD_PLAY_TREE_UP_STEP: {
695 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
696 } break;
697 case MP_CMD_PLAY_ALT_SRC_STEP: {
698 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
699 } break;
701 mp_cmd_free(cmd);
703 return eof;
706 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
707 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
709 int playtree_add_playlist(play_tree_t* entry)
711 play_tree_add_bpf(entry,filename);
713 #ifdef HAVE_NEW_GUI
714 if (use_gui) {
715 if (entry) {
716 import_playtree_playlist_into_gui(entry, mconfig);
717 play_tree_free_list(entry,1);
719 } else
720 #endif
722 if(!entry) {
723 entry = playtree_iter->tree;
724 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
725 return PT_NEXT_ENTRY;
727 if(playtree_iter->tree == entry ) { // Loop with a single file
728 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
729 return PT_NEXT_ENTRY;
732 play_tree_remove(entry,1,1);
733 return PT_NEXT_SRC;
735 play_tree_insert_entry(playtree_iter->tree,entry);
736 play_tree_set_params_from(entry,playtree_iter->tree);
737 entry = playtree_iter->tree;
738 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
739 return PT_NEXT_ENTRY;
741 play_tree_remove(entry,1,1);
743 return PT_NEXT_SRC;
746 static int play_tree_step = 1;
748 int sub_source()
750 int source = -1;
751 int top = -1;
752 int i;
753 for (i = 0; i < SUB_SOURCES; i++) {
754 int j = global_sub_indices[i];
755 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
756 source = i;
757 top = j;
760 return source;
763 #ifdef USE_SUB
765 sub_data* subdata = NULL;
766 static subtitle* vo_sub_last = NULL;
768 void add_subtitles(char *filename, float fps, int silent)
770 sub_data *subd;
772 if (filename == NULL) {
773 return;
776 subd = sub_read_file(filename, fps);
777 if(!subd && !silent)
778 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
779 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
780 set_of_subtitles[set_of_sub_size] = subd;
781 if (identify)
783 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
784 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
786 ++set_of_sub_size;
787 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
790 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
791 void update_set_of_subtitles()
792 // subdata was changed, set_of_sub... have to be updated.
794 int i;
795 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
796 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
797 set_of_subtitles[i-1] = set_of_subtitles[i];
798 set_of_subtitles[set_of_sub_size-1] = NULL;
799 --set_of_sub_size;
800 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
802 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
803 set_of_subtitles[set_of_sub_pos] = subdata;
805 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
806 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
807 ++set_of_sub_size;
810 #endif
813 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
814 * make it all work is to use the builtin SDL-bootstrap code, which
815 * will be done automatically by replacing our main() if we include SDL.h.
817 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
818 #include <SDL.h>
819 #endif
822 * \brief append a formatted string
823 * \param buf buffer to print into
824 * \param pos position of terminating 0 in buf
825 * \param len maximum number of characters in buf, not including terminating 0
826 * \param format printf format string
828 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
830 va_list va;
831 va_start(va, format);
832 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
833 va_end(va);
834 if (*pos >= len ) {
835 buf[len] = 0;
836 *pos = len;
841 * \brief print the status line
842 * \param a_pos audio position
843 * \param a_v A-V desynchronization
844 * \param corr amount out A-V synchronization
846 static void print_status(float a_pos, float a_v, float corr)
848 int width;
849 char *line;
850 unsigned pos = 0;
851 get_screen_size();
852 if (screen_width > 0)
853 width = screen_width;
854 else
855 width = 80;
856 #ifdef WIN32
857 // windows command line is broken (MinGW's rxvt works though, but we
858 // should not depend on that).
859 width--;
860 #endif
861 line = malloc(width + 1); // one additional for terminating null
863 // Audio time
864 if (sh_audio) {
865 saddf(line, &pos, width, "A:%6.1f ", a_pos);
866 if (!sh_video) {
867 // convert time to HH:MM:SS.F format
868 long tenths = 10 * a_pos;
869 int f1 = tenths % 10;
870 int ss = (tenths / 10) % 60;
871 int mm = (tenths / 600) % 60;
872 int hh = (tenths / 36000) % 100;
873 saddf(line, &pos, width, "(");
874 if (hh > 0)
875 saddf(line, &pos, width, "%2d:", hh);
876 if (hh > 0 || mm > 0)
877 saddf(line, &pos, width, "%02d:", mm);
878 saddf(line, &pos, width, "%02d.", ss);
879 saddf(line, &pos, width, "%1d", f1);
880 saddf(line, &pos, width, ") ");
884 // Video time
885 if (sh_video)
886 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
888 // A-V sync
889 if (sh_audio && sh_video)
890 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
892 // Video stats
893 if (sh_video)
894 saddf(line, &pos, width, "%3d/%3d ",
895 (int)sh_video->num_frames,
896 (int)sh_video->num_frames_decoded);
898 // CPU usage
899 if (sh_video) {
900 if (sh_video->timer > 0.5)
901 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
902 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
903 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
904 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
905 else
906 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
907 } else if (sh_audio) {
908 if (sh_audio->delay > 0.5)
909 saddf(line, &pos, width, "%4.1f%% ",
910 100.0*audio_time_usage/(double)sh_audio->delay);
911 else
912 saddf(line, &pos, width, "??,?%% ");
915 // VO stats
916 if (sh_video)
917 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
919 #ifdef USE_STREAM_CACHE
920 // cache stats
921 if (stream_cache_size > 0)
922 saddf(line, &pos, width, "%d%% ", cache_fill_status);
923 #endif
925 // other
926 if (playback_speed != 1)
927 saddf(line, &pos, width, "%4.2fx ", playback_speed);
929 // end
930 memset(&line[pos], ' ', width - pos);
931 line[width] = 0;
932 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
933 free(line);
937 * \brief build a chain of audio filters that converts the input format
938 * to the ao's format, taking into account the current playback_speed.
939 * \param sh_audio describes the requested input format of the chain.
940 * \param ao_data describes the requested output format of the chain.
942 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
944 int new_srate;
945 int result;
946 if (!sh_audio)
948 #ifdef HAVE_NEW_GUI
949 guiGetEvent(guiSetAfilter, (char *)NULL);
950 #endif
951 mixer.afilter = NULL;
952 return 0;
954 new_srate = sh_audio->samplerate * playback_speed;
955 if (new_srate != ao_data->samplerate) {
956 // limits are taken from libaf/af_resample.c
957 if (new_srate < 8000)
958 new_srate = 8000;
959 if (new_srate > 192000)
960 new_srate = 192000;
961 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
963 result = init_audio_filters(sh_audio, new_srate,
964 sh_audio->channels, sh_audio->sample_format,
965 &ao_data->samplerate, &ao_data->channels, &ao_data->format,
966 ao_data->outburst * 4, ao_data->buffersize);
967 mixer.afilter = sh_audio->afilter;
968 #ifdef HAVE_NEW_GUI
969 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter);
970 #endif
971 return result;
974 #ifdef USE_SUB
976 * \brief Log the currently displayed subtitle to a file
978 * Logs the current or last displayed subtitle together with filename
979 * and time information to ~/.mplayer/subtitle_log
981 * Intended purpose is to allow convenient marking of bogus subtitles
982 * which need to be fixed while watching the movie.
985 static void log_sub(){
986 char *fname;
987 FILE *f;
988 int i;
990 if (subdata == NULL || vo_sub_last == NULL) return;
991 fname = get_path("subtitle_log");
992 f = fopen(fname, "a");
993 if (!f) return;
994 fprintf(f, "----------------------------------------------------------\n");
995 if (subdata->sub_uses_time) {
996 fprintf(f, "N: %s S: %02d:%02d:%02d.%02d E: %02d:%02d:%02d.%02d\n", filename,
997 vo_sub_last->start/360000, (vo_sub_last->start/6000)%60,
998 (vo_sub_last->start/100)%60, vo_sub_last->start%100,
999 vo_sub_last->end/360000, (vo_sub_last->end/6000)%60,
1000 (vo_sub_last->end/100)%60, vo_sub_last->end%100);
1001 } else {
1002 fprintf(f, "N: %s S: %d E: %d\n", filename, vo_sub_last->start, vo_sub_last->end);
1004 for (i = 0; i < vo_sub_last->lines; i++) {
1005 fprintf(f, "%s\n", vo_sub_last->text[i]);
1007 fclose(f);
1009 #endif
1011 int main(int argc,char* argv[]){
1014 char * mem_ptr;
1016 static demux_stream_t *d_audio=NULL;
1017 static demux_stream_t *d_video=NULL;
1018 static demux_stream_t *d_dvdsub=NULL;
1020 int file_format=DEMUXER_TYPE_UNKNOWN;
1022 int delay_corrected=1;
1024 // movie info:
1026 int osd_function=OSD_PLAY;
1027 int osd_last_pts=-303;
1028 int osd_show_av_delay = 0;
1029 int osd_show_text = 0;
1030 int osd_show_speed = 0;
1031 int osd_show_sub_delay = 0;
1032 int osd_show_sub_pos = 0;
1033 int osd_show_sub_visibility = 0;
1034 int osd_show_sub_alignment = 0;
1035 int osd_show_vobsub_changed = 0;
1036 int osd_show_sub_changed = 0;
1037 int osd_show_percentage = 0;
1038 int osd_show_tv_channel = 25;
1039 int osd_show_ontop = 0;
1040 int osd_show_rootwin = 0;
1041 int osd_show_framedropping = 0;
1042 int osd_show_status = 0;
1044 int rtc_fd=-1;
1046 //float a_frame=0; // Audio
1048 int i;
1049 char *tmp;
1051 int gui_no_filename=0;
1054 srand((int) time(NULL));
1056 InitTimer();
1058 mp_msg_init();
1059 mp_msg_set_level(MSGL_STATUS);
1061 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2005 MPlayer Team\n");
1062 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
1063 GetCpuCaps(&gCpuCaps);
1064 #if defined(ARCH_X86) || defined(ARCH_X86_64)
1065 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
1066 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
1067 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
1068 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
1069 #ifdef RUNTIME_CPUDETECT
1070 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
1071 #else
1072 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
1073 #ifdef HAVE_MMX
1074 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
1075 #endif
1076 #ifdef HAVE_MMX2
1077 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
1078 #endif
1079 #ifdef HAVE_3DNOW
1080 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
1081 #endif
1082 #ifdef HAVE_3DNOWEX
1083 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
1084 #endif
1085 #ifdef HAVE_SSE
1086 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
1087 #endif
1088 #ifdef HAVE_SSE2
1089 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
1090 #endif
1091 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
1092 #endif
1093 #endif
1095 #if defined(WIN32) && defined(USE_WIN32DLL)
1096 { /*make our codec dirs available for LoadLibraryA()*/
1097 char tmppath[MAX_PATH*2 + 1];
1098 char win32path[MAX_PATH];
1099 char realpath[MAX_PATH];
1100 #ifdef __CYGWIN__
1101 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
1102 strcpy(tmppath,win32path);
1103 #ifdef USE_REALCODECS
1104 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
1105 sprintf(tmppath,"%s;%s",win32path,realpath);
1106 #endif /*USE_REALCODECS*/
1107 #else
1108 if(!strstr(WIN32_PATH,":")){
1109 GetModuleFileNameA(NULL, win32path, MAX_PATH);
1110 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
1112 else strcpy(win32path,WIN32_PATH);
1113 strcpy(tmppath,win32path);
1114 #ifdef USE_REALCODECS
1115 if(!strstr(REALCODEC_PATH,":")){
1116 GetModuleFileNameA(NULL, realpath, MAX_PATH);
1117 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
1119 else strcpy(realpath,REALCODEC_PATH);
1120 sprintf(tmppath,"%s;%s",win32path,realpath);
1121 #endif /*USE_REALCODECS*/
1122 #endif /*__CYGWIN__*/
1123 SetEnvironmentVariableA("PATH", tmppath);
1125 #endif /*WIN32 && USE_WIN32DLL*/
1127 #ifdef USE_TV
1128 tv_param_immediate = 1;
1129 #endif
1131 if ( argv[0] )
1132 if(!strcmp(argv[0],"gmplayer") ||
1133 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
1134 use_gui=1;
1136 mconfig = m_config_new();
1137 m_config_register_options(mconfig,mplayer_opts);
1138 // TODO : add something to let modules register their options
1139 mp_input_register_options(mconfig);
1140 parse_cfgfiles(mconfig);
1142 #ifdef HAVE_NEW_GUI
1143 if ( use_gui ) cfg_read();
1144 #endif
1146 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
1147 if(playtree == NULL)
1148 exit_player(NULL);
1150 playtree = play_tree_cleanup(playtree);
1151 if(playtree) {
1152 playtree_iter = play_tree_iter_new(playtree,mconfig);
1153 if(playtree_iter) {
1154 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
1155 play_tree_iter_free(playtree_iter);
1156 playtree_iter = NULL;
1158 filename = play_tree_iter_get_file(playtree_iter,1);
1162 #ifdef WIN32
1163 if(proc_priority){
1164 int i;
1165 for(i=0; priority_presets_defs[i].name; i++){
1166 if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
1167 break;
1169 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",
1170 priority_presets_defs[i].name);
1171 SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
1173 #endif
1174 #ifndef HAVE_NEW_GUI
1175 if(use_gui){
1176 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
1177 use_gui=0;
1179 #else
1180 if(use_gui && !vo_init()){
1181 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
1182 use_gui=0;
1184 if (use_gui && playtree_iter){
1185 char cwd[PATH_MAX+2];
1186 // Remove Playtree and Playtree-Iter from memory as its not used by gui
1187 play_tree_iter_free(playtree_iter);
1188 playtree_iter=NULL;
1190 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
1192 strcat(cwd, "/");
1193 // Prefix relative paths with current working directory
1194 play_tree_add_bpf(playtree, cwd);
1196 // Import initital playtree into gui
1197 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
1199 #endif
1201 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
1202 list_video_out();
1203 exit_player_with_rc(NULL, 0);
1206 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
1207 list_audio_out();
1208 exit_player_with_rc(NULL, 0);
1211 // check codec.conf
1212 if(!codecs_file || !parse_codec_cfg(codecs_file)){
1213 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
1214 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
1215 if(!parse_codec_cfg(NULL)){
1216 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
1217 exit_player_with_rc(NULL, 0);
1219 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
1222 free( mem_ptr ); // release the buffer created by get_path()
1225 #if 0
1226 if(video_codec_list){
1227 int i;
1228 video_codec=video_codec_list[0];
1229 for(i=0;video_codec_list[i];i++)
1230 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
1232 #endif
1233 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
1234 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
1235 if (identify)
1236 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_CODECS\n");
1237 list_codecs(1);
1238 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1239 exit_player_with_rc(NULL, 0);
1241 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
1242 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
1243 if (identify)
1244 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VIDEO_CODECS\n");
1245 list_codecs(0);
1246 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1247 exit_player_with_rc(NULL, 0);
1249 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
1250 vfm_help();
1251 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1252 exit_player_with_rc(NULL, 0);
1254 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
1255 afm_help();
1256 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1257 exit_player_with_rc(NULL, 0);
1259 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
1260 af_help();
1261 printf("\n");
1262 exit_player_with_rc(NULL, 0);
1264 #ifdef HAVE_X11
1265 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
1266 fstype_help();
1267 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1268 exit_player_with_rc(NULL, 0);
1270 #endif
1272 #ifdef USE_EDL
1273 if (edl_check_mode() == EDL_ERROR && edl_filename)
1275 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantUseBothModes);
1276 exit_player(NULL);
1277 } else if (edl_filename)
1279 if (edl_records) free_edl(edl_records);
1280 next_edl_record = edl_records = edl_parse_file();
1281 } else if (edl_output_filename)
1283 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
1285 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
1286 edl_output_filename);
1287 exit_player(NULL);
1290 #endif
1292 if(!filename){
1293 if(!use_gui){
1294 // no file/vcd/dvd -> show HELP:
1295 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1296 exit_player_with_rc(NULL, 0);
1297 } else gui_no_filename=1;
1300 // Many users forget to include command line in bugreports...
1301 if(verbose>0){
1302 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
1303 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);
1304 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
1307 mp_msg_set_level(verbose+MSGL_STATUS);
1309 //------ load global data first ------
1311 // check font
1312 #ifdef USE_OSD
1313 #ifdef HAVE_FREETYPE
1314 init_freetype();
1315 #endif
1316 #ifdef HAVE_FONTCONFIG
1317 if(!font_fontconfig)
1319 #endif
1320 if(font_name){
1321 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1322 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1323 } else {
1324 // try default:
1325 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
1326 free(mem_ptr); // release the buffer created by get_path()
1327 if(!vo_font)
1328 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1330 #ifdef HAVE_FONTCONFIG
1332 #endif
1333 #endif
1334 vo_init_osd();
1336 #ifdef HAVE_RTC
1337 if(!nortc)
1339 // seteuid(0); /* Can't hurt to try to get root here */
1340 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
1341 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
1342 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
1343 else {
1344 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1346 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1347 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
1348 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
1349 close (rtc_fd);
1350 rtc_fd = -1;
1351 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1352 /* variable only by the root */
1353 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
1354 close (rtc_fd);
1355 rtc_fd = -1;
1356 } else
1357 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
1360 #ifdef HAVE_NEW_GUI
1361 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1362 // and now ? -- Pontscho
1363 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1364 #endif
1365 if(rtc_fd<0)
1366 #endif
1367 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
1368 softsleep?"software":timer_name);
1370 #ifdef USE_TERMCAP
1371 if ( !use_gui ) load_termcap(NULL); // load key-codes
1372 #endif
1374 // ========== Init keyboard FIFO (connection to libvo) ============
1376 // Init input system
1377 current_module = "init_input";
1378 mp_input_init();
1379 #if 0
1380 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1382 if(keyb_fifo_get > 0)
1383 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1384 #else
1385 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1386 #endif
1387 if(slave_mode)
1388 #ifndef __MINGW32__
1389 mp_input_add_cmd_fd(0,1,NULL,NULL);
1390 #else
1391 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1392 #endif
1393 else if(!noconsolecontrols)
1394 #ifndef HAVE_NO_POSIX_SELECT
1395 mp_input_add_key_fd(0,1,NULL,NULL);
1396 #else
1397 mp_input_add_key_fd(0,0,NULL,NULL);
1398 #endif
1400 inited_flags|=INITED_INPUT;
1401 current_module = NULL;
1403 #ifdef HAVE_MENU
1404 if(use_menu) {
1405 if(menu_cfg && menu_init(menu_cfg))
1406 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1407 else {
1408 menu_cfg = get_path("menu.conf");
1409 if(menu_init(menu_cfg))
1410 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1411 else {
1412 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1413 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
1414 else {
1415 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
1416 use_menu = 0;
1421 #endif
1423 /// Catch signals
1424 #ifndef __MINGW32__
1425 signal(SIGCHLD,child_sighandler);
1426 #endif
1428 #ifdef CRASH_DEBUG
1429 prog_path = argv[0];
1430 #endif
1431 //========= Catch terminate signals: ================
1432 // terminate requests:
1433 signal(SIGTERM,exit_sighandler); // kill
1434 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1436 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1438 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1439 signal(SIGPIPE,exit_sighandler); // Some window managers cause this
1440 #ifdef ENABLE_SIGHANDLER
1441 // fatal errors:
1442 signal(SIGBUS,exit_sighandler); // bus error
1443 signal(SIGSEGV,exit_sighandler); // segfault
1444 signal(SIGILL,exit_sighandler); // illegal instruction
1445 signal(SIGFPE,exit_sighandler); // floating point exc.
1446 signal(SIGABRT,exit_sighandler); // abort()
1447 #ifdef CRASH_DEBUG
1448 if (crash_debug)
1449 signal(SIGTRAP,exit_sighandler);
1450 #endif
1451 #endif
1453 #ifdef HAVE_NEW_GUI
1454 if(use_gui){
1455 guiInit();
1456 inited_flags|=INITED_GUI;
1457 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1459 #endif
1461 // ******************* Now, let's see the per-file stuff ********************
1463 play_next_file:
1465 // init global sub numbers
1466 global_sub_size = 0;
1467 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
1468 global_sub_quiet_osd_hack = 1;
1470 if (filename) load_per_file_config (mconfig, filename);
1472 // We must enable getch2 here to be able to interrupt network connection
1473 // or cache filling
1474 if(!noconsolecontrols && !slave_mode){
1475 if(inited_flags&INITED_GETCH2)
1476 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
1477 else
1478 getch2_enable(); // prepare stdin for hotkeys...
1479 inited_flags|=INITED_GETCH2;
1480 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1483 // =================== GUI idle loop (STOP state) ===========================
1484 #ifdef HAVE_NEW_GUI
1485 if ( use_gui ) {
1486 file_format=DEMUXER_TYPE_UNKNOWN;
1487 guiGetEvent( guiSetDefaults,0 );
1488 while ( guiIntfStruct.Playing != 1 )
1490 mp_cmd_t* cmd;
1491 usec_sleep(20000);
1492 guiEventHandling();
1493 guiGetEvent( guiReDraw,NULL );
1494 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1496 guiGetEvent( guiSetParameters,NULL );
1497 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1499 play_tree_t * entry = play_tree_new();
1500 play_tree_add_file( entry,guiIntfStruct.Filename );
1501 if ( playtree ) play_tree_free_list( playtree->child,1 );
1502 else playtree=play_tree_new();
1503 play_tree_set_child( playtree,entry );
1504 if(playtree)
1506 playtree_iter = play_tree_iter_new(playtree,mconfig);
1507 if(playtree_iter)
1509 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1511 play_tree_iter_free(playtree_iter);
1512 playtree_iter = NULL;
1514 filename = play_tree_iter_get_file(playtree_iter,1);
1519 #endif
1520 //---------------------------------------------------------------------------
1522 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1524 //==================== Open VOB-Sub ============================
1526 current_module="vobsub";
1527 if (vobsub_name){
1528 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1529 if(vo_vobsub==NULL)
1530 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1531 }else if(sub_auto && filename && (strlen(filename)>=5)){
1532 /* try to autodetect vobsub from movie filename ::atmos */
1533 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1534 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1535 strncpy(buf, filename, strlen(filename)-4);
1536 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1537 free(buf);
1539 if(vo_vobsub){
1540 inited_flags|=INITED_VOBSUB;
1541 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1542 // check if vobsub requested only to display forced subtitles
1543 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1545 // setup global sub numbering
1546 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
1547 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
1550 //============ Open & Sync STREAM --- fork cache2 ====================
1552 stream=NULL;
1553 demuxer=NULL;
1554 if (d_audio) {
1555 //free_demuxer_stream(d_audio);
1556 d_audio=NULL;
1558 if (d_video) {
1559 //free_demuxer_stream(d_video);
1560 d_video=NULL;
1562 sh_audio=NULL;
1563 sh_video=NULL;
1565 current_module="open_stream";
1566 stream=open_stream(filename,0,&file_format);
1567 if(!stream) { // error...
1568 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1569 goto goto_next_file;
1571 inited_flags|=INITED_STREAM;
1573 #ifdef HAVE_NEW_GUI
1574 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1575 #endif
1577 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1578 play_tree_t* entry;
1579 // Handle playlist
1580 current_module="handle_playlist";
1581 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1582 entry = parse_playtree(stream,0);
1583 eof=playtree_add_playlist(entry);
1584 goto goto_next_file;
1586 stream->start_pos+=seek_to_byte;
1588 if(stream_dump_type==5){
1589 unsigned char buf[4096];
1590 int len;
1591 FILE *f;
1592 current_module="dumpstream";
1593 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1594 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
1595 exit_player(MSGTR_Exit_error);
1597 stream_reset(stream);
1598 stream_seek(stream,stream->start_pos);
1599 f=fopen(stream_dump_name,"wb");
1600 if(!f){
1601 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1602 exit_player(MSGTR_Exit_error);
1604 while(!stream->eof){
1605 len=stream_read(stream,buf,4096);
1606 if(len>0) {
1607 if(fwrite(buf,len,1,f) != 1) {
1608 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1609 exit_player(MSGTR_Exit_error);
1613 if(fclose(f)) {
1614 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1615 exit_player(MSGTR_Exit_error);
1617 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1618 exit_player_with_rc(MSGTR_Exit_eof, 0);
1621 #ifdef USE_DVDREAD
1622 if(stream->type==STREAMTYPE_DVD){
1623 current_module="dvd lang->id";
1624 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1625 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1626 // setup global sub numbering
1627 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1628 global_sub_size += dvd_number_of_subs(stream);
1629 current_module=NULL;
1631 #endif
1633 #ifdef USE_DVDNAV
1634 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1635 #endif
1637 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1638 #ifdef HAS_DVBIN_SUPPORT
1639 goto_enable_cache:
1640 #endif
1641 if(stream_cache_size>0){
1642 current_module="enable_cache";
1643 if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024*(stream_cache_min_percent / 100.0),stream_cache_size*1024*(stream_cache_prefill_percent / 100.0)))
1644 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1647 //============ Open DEMUXERS --- DETECT file type =======================
1648 current_module="demux_open";
1650 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1652 // HACK to get MOV Reference Files working
1654 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1656 unsigned char* playlist_entry;
1657 play_tree_t *list = NULL, *entry = NULL;
1659 current_module="handle_demux_playlist";
1660 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1662 char *temp, *bname;
1664 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
1666 bname=mp_basename(playlist_entry);
1667 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1668 continue;
1670 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1671 continue;
1673 entry = play_tree_new();
1675 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1677 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1678 if (temp)
1680 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1681 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1682 strcat(temp, playlist_entry);
1683 play_tree_add_file(entry,temp);
1684 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
1685 free(temp);
1688 else
1689 play_tree_add_file(entry,playlist_entry);
1691 if(!list)
1692 list = entry;
1693 else
1694 play_tree_append_entry(list,entry);
1696 free_demuxer(demuxer);
1697 demuxer = NULL;
1699 if (list)
1701 entry = play_tree_new();
1702 play_tree_set_child(entry,list);
1703 eof=playtree_add_playlist(entry);
1704 goto goto_next_file;
1708 if(!demuxer)
1710 #if 0
1711 play_tree_t* entry;
1712 // Handle playlist
1713 current_module="handle_playlist";
1714 switch(stream->type){
1715 case STREAMTYPE_VCD:
1716 case STREAMTYPE_DVD:
1717 case STREAMTYPE_DVDNAV:
1718 case STREAMTYPE_CDDA:
1719 case STREAMTYPE_VCDBINCUE:
1720 // don't try to parse raw media as playlist, it's unlikely
1721 goto goto_next_file;
1723 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
1724 stream_reset(stream);
1725 stream_seek(stream,stream->start_pos);
1726 entry = parse_playtree(stream,0);
1727 if(!entry)
1728 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1729 else
1730 eof=playtree_add_playlist(entry);
1731 #endif
1732 goto goto_next_file;
1734 inited_flags|=INITED_DEMUXER;
1736 #ifdef HAVE_MATROSKA
1737 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
1738 // setup global sub numbering
1739 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1740 global_sub_size += demux_mkv_num_subs(demuxer);
1742 #endif
1743 #ifdef HAVE_OGGVORBIS
1744 if (demuxer->type==DEMUXER_TYPE_OGG) {
1745 // setup global sub numbering
1746 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1747 global_sub_size += demux_ogg_num_subs(demuxer);
1749 #endif
1751 current_module="demux_open2";
1753 //file_format=demuxer->file_format;
1755 d_audio=demuxer->audio;
1756 d_video=demuxer->video;
1757 d_dvdsub=demuxer->sub;
1759 // DUMP STREAMS:
1760 if((stream_dump_type)&&(stream_dump_type<4)){
1761 FILE *f;
1762 demux_stream_t *ds=NULL;
1763 current_module="dump";
1764 // select stream to dump
1765 switch(stream_dump_type){
1766 case 1: ds=d_audio;break;
1767 case 2: ds=d_video;break;
1768 case 3: ds=d_dvdsub;break;
1770 if(!ds){
1771 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1772 exit_player(MSGTR_Exit_error);
1774 // disable other streams:
1775 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1776 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1777 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1778 // let's dump it!
1779 f=fopen(stream_dump_name,"wb");
1780 if(!f){
1781 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1782 exit_player(MSGTR_Exit_error);
1784 while(!ds->eof){
1785 unsigned char* start;
1786 int in_size=ds_get_packet(ds,&start);
1787 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1788 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1789 if(in_size>0) fwrite(start,in_size,1,f);
1791 fclose(f);
1792 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1793 exit_player_with_rc(MSGTR_Exit_eof, 0);
1796 sh_audio=d_audio->sh;
1797 sh_video=d_video->sh;
1799 if(sh_video){
1801 current_module="video_read_properties";
1802 if(!video_read_properties(sh_video)) {
1803 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1804 sh_video=d_video->sh=NULL;
1805 } else {
1806 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1807 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1808 sh_video->fps,sh_video->frametime
1811 /* need to set fps here for output encoders to pick it up in their init */
1812 if(force_fps){
1813 sh_video->fps=force_fps;
1814 sh_video->frametime=1.0f/sh_video->fps;
1816 vo_fps = sh_video->fps;
1817 #ifdef HAVE_X11
1818 vo_mouse_timer_const=(int)sh_video->fps;
1819 #endif
1821 if(!sh_video->fps && !force_fps){
1822 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1823 sh_video=d_video->sh=NULL;
1829 fflush(stdout);
1831 if(!sh_video && !sh_audio){
1832 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1833 #ifdef HAS_DVBIN_SUPPORT
1834 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1836 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1837 if(priv->is_on)
1839 int dir;
1840 int v = last_dvb_step;
1841 if(v > 0)
1842 dir = DVB_CHANNEL_HIGHER;
1843 else
1844 dir = DVB_CHANNEL_LOWER;
1846 if(dvb_step_channel(priv, dir))
1848 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1849 cache_uninit(stream);
1850 goto goto_enable_cache;
1854 #endif
1855 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1858 /* display clip info */
1859 demux_info_print(demuxer);
1861 //================== Read SUBTITLES (DVD & TEXT) ==========================
1862 if(vo_spudec==NULL && sh_video &&
1863 (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA ||
1864 d_dvdsub->id >= 0)){
1866 if (spudec_ifo) {
1867 unsigned int palette[16], width, height;
1868 current_module="spudec_init_vobsub";
1869 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1870 vo_spudec=spudec_new_scaled(palette, width, height);
1873 #ifdef USE_DVDNAV
1874 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1875 current_module="spudec_init_dvdnav";
1876 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1877 sh_video->disp_w, sh_video->disp_h);
1879 #endif
1881 #ifdef USE_DVDREAD
1882 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1883 current_module="spudec_init_dvdread";
1884 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1885 sh_video->disp_w, sh_video->disp_h);
1887 #endif
1889 #ifdef HAVE_MATROSKA
1890 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1891 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1892 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
1893 current_module = "spudec_init_matroska";
1894 vo_spudec =
1895 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1896 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1897 mkv_sh_sub->height);
1898 forced_subs_only = mkv_sh_sub->forced_subs_only;
1900 #endif
1902 if (vo_spudec==NULL) {
1903 current_module="spudec_init_normal";
1904 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1905 spudec_set_font_factor(vo_spudec,font_factor);
1908 if (vo_spudec!=NULL)
1909 inited_flags|=INITED_SPUDEC;
1913 // Apply current settings for forced subs
1914 if (vo_spudec!=NULL)
1915 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1917 #ifdef USE_SUB
1918 if(sh_video) {
1919 // after reading video params we should load subtitles because
1920 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1921 // check .sub
1922 current_module="read_subtitles_file";
1923 if(sub_name){
1924 for (i = 0; sub_name[i] != NULL; ++i)
1925 add_subtitles (sub_name[i], sh_video->fps, 0);
1927 if(sub_auto) { // auto load sub file ...
1928 char *psub = get_path( "sub/" );
1929 char **tmp = sub_filenames((psub ? psub : ""), filename);
1930 int i = 0;
1931 free(psub); // release the buffer created by get_path() above
1932 while (tmp[i]) {
1933 add_subtitles (tmp[i], sh_video->fps, 0);
1934 free(tmp[i++]);
1936 free(tmp);
1937 if (set_of_sub_size == 0)
1939 add_subtitles (mem_ptr=get_path("default.sub"), sh_video->fps, 1);
1940 free(mem_ptr); // release the buffer created by get_path()
1943 if (set_of_sub_size > 0) {
1944 // setup global sub numbering
1945 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
1946 global_sub_size += set_of_sub_size;
1949 #endif
1951 if (global_sub_size) {
1952 // find the best sub to use
1953 if (vobsub_id >= 0) {
1954 // if user asks for a vobsub id, use that first.
1955 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
1956 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1957 // if user asks for a dvd sub id, use that next.
1958 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
1959 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
1960 // if there are text subs to use, use those. (autosubs come last here)
1961 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
1963 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1964 // if nothing else works, get subs from the demuxer.
1965 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1967 } else {
1968 // nothing worth doing automatically.
1969 global_sub_pos = -1;
1971 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1972 global_sub_pos--;
1973 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1976 //================== Init AUDIO (codec) ==========================
1977 if(sh_audio){
1978 // Go through the codec.conf and find the best codec...
1979 current_module="init_audio_codec";
1980 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1981 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1982 sh_audio=d_audio->sh=NULL; // failed to init :(
1983 } else
1984 inited_flags|=INITED_ACODEC;
1985 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1988 if(identify) {
1989 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
1990 if (sh_video) {
1991 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1992 if (sh_video->format >= 0x20202020)
1993 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
1994 else
1995 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
1996 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
1997 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
1998 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
1999 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
2000 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
2002 if (sh_audio) {
2003 if (sh_audio->codec)
2004 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
2005 /* Assume FOURCC if all bytes >= 0x20 (' ') */
2006 if (sh_audio->format >= 0x20202020)
2007 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
2008 else
2009 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
2010 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
2011 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
2012 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
2014 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
2017 if(!sh_video) goto main; // audio-only
2019 //================== Init VIDEO (codec & libvo) ==========================
2020 if(!fixed_vo || !(inited_flags&INITED_VO)){
2021 current_module="preinit_libvo";
2023 vo_config_count=0;
2024 //if((video_out->preinit(vo_subdevice))!=0){
2025 if(!(video_out=init_best_video_out(video_driver_list))){
2026 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
2027 goto goto_next_file; // exit_player(MSGTR_Exit_error);
2029 sh_video->video_out=video_out;
2030 inited_flags|=INITED_VO;
2033 current_module="init_video_filters";
2035 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
2036 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
2038 #ifdef HAVE_MENU
2039 if(use_menu) {
2040 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
2041 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
2042 if(!vf_menu) {
2043 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
2044 use_menu = 0;
2047 if(vf_menu)
2048 sh_video->vfilter=(void*)append_filters(vf_menu);
2049 else
2050 #endif
2051 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
2053 current_module="init_video_codec";
2055 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2056 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
2057 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2059 if(!sh_video->inited){
2060 if(!fixed_vo) uninit_player(INITED_VO);
2061 if(!sh_audio) goto goto_next_file;
2062 sh_video = d_video->sh = NULL;
2063 goto main; // exit_player(MSGTR_Exit_error);
2066 inited_flags|=INITED_VCODEC;
2068 if(auto_quality>0){
2069 // Auto quality option enabled
2070 output_quality=get_video_quality_max(sh_video);
2071 if(auto_quality>output_quality) auto_quality=output_quality;
2072 else output_quality=auto_quality;
2073 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
2074 set_video_quality(sh_video,output_quality);
2077 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2079 current_module="init_vo";
2081 if(vo_flags & 0x08 && vo_spudec)
2082 spudec_set_hw_spu(vo_spudec,video_out);
2084 #ifdef HAVE_FREETYPE
2085 force_load_font = 1;
2086 #endif
2088 //================== MAIN: ==========================
2089 main:
2090 current_module="main";
2092 // If there is no video OSD has to be disabled.
2093 // In case of playing a playtree we have to restore the
2094 // old OSD level after playing one or more audio-only files.
2095 if(!sh_video && osd_level >= 0) { // save OSD level only once
2096 osd_level_saved = osd_level;
2097 osd_level = 0;
2098 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
2099 osd_level = osd_level_saved;
2100 osd_level_saved = -1;
2103 fflush(stdout);
2105 #ifdef HAVE_NEW_GUI
2106 if ( use_gui )
2108 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
2109 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
2110 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
2111 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
2112 guiGetEvent( guiSetDemuxer,(char *)demuxer );
2114 #endif
2117 //int frame_corr_num=0; //
2118 //float v_frame=0; // Video
2119 float time_frame=0; // Timer
2120 //float num_frames=0; // number of frames played
2121 int grab_frames=0;
2122 char osd_text_buffer[64];
2123 char osd_show_text_buffer[64];
2124 int drop_frame=0; // current dropping status
2125 int dropped_frames=0; // how many frames dropped since last non-dropped frame
2126 int too_slow_frame_cnt=0;
2127 int too_fast_frame_cnt=0;
2128 // for auto-quality:
2129 float AV_delay=0; // average of A-V timestamp differences
2130 double vdecode_time;
2131 unsigned int lastframeout_ts=0;
2132 /*float time_frame_corr_avg=0;*/ /* unused */
2134 float next_frame_time=0;
2135 int frame_time_remaining=0; // flag
2136 int blit_frame=0;
2138 osd_text_buffer[0]=0;
2140 //================ SETUP AUDIO ==========================
2142 if(sh_audio){
2143 //const ao_info_t *info=audio_out->info;
2144 current_module="af_preinit";
2145 ao_data.samplerate=force_srate;
2146 ao_data.channels=0;
2147 ao_data.format=audio_output_format;
2148 #if 1
2149 // first init to detect best values
2150 if(!preinit_audio_filters(sh_audio,
2151 // input:
2152 (int)(sh_audio->samplerate*playback_speed),
2153 sh_audio->channels, sh_audio->sample_format,
2154 // output:
2155 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){
2156 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2158 #endif
2159 current_module="ao2_init";
2160 if(!(audio_out=init_best_audio_out(audio_driver_list,
2161 0, // plugin flag
2162 ao_data.samplerate,
2163 ao_data.channels,
2164 ao_data.format,0))){
2165 // FAILED:
2166 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2167 uninit_player(INITED_ACODEC); // close codec
2168 sh_audio=d_audio->sh=NULL; // -> nosound
2169 } else {
2170 // SUCCESS:
2171 inited_flags|=INITED_AO;
2172 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
2173 audio_out->info->short_name,
2174 ao_data.samplerate, ao_data.channels,
2175 af_fmt2str_short(ao_data.format),
2176 af_fmt2bits(ao_data.format)/8 );
2177 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2178 audio_out->info->name, audio_out->info->author);
2179 if(strlen(audio_out->info->comment) > 0)
2180 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2181 // init audio filters:
2182 #if 1
2183 current_module="af_init";
2184 if(!build_afilter_chain(sh_audio, &ao_data)) {
2185 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2186 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2187 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2188 // sh_audio=d_audio->sh=NULL; // -> nosound
2190 #endif
2192 mixer.audio_out = audio_out;
2193 mixer.volstep = volstep;
2196 current_module="av_init";
2198 if(sh_video) sh_video->timer=0;
2199 if(sh_audio) sh_audio->delay=-audio_delay;
2201 if(!sh_audio){
2202 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
2203 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
2204 ds_free_packs(d_audio); // free buffered chunks
2205 d_audio->id=-2; // do not read audio chunks
2206 //uninit_player(INITED_AO); // close device
2208 if(!sh_video){
2209 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
2210 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
2211 ds_free_packs(d_video);
2212 d_video->id=-2;
2213 //if(!fixed_vo) uninit_player(INITED_VO);
2216 if (!sh_video && !sh_audio)
2217 goto goto_next_file;
2219 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
2220 if(force_fps && sh_video){
2221 vo_fps = sh_video->fps=force_fps;
2222 sh_video->frametime=1.0f/sh_video->fps;
2223 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
2226 //==================== START PLAYING =======================
2228 if(loop_times>1) loop_times--; else
2229 if(loop_times==1) loop_times = -1;
2231 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
2233 #ifdef USE_DVDNAV
2234 if (stream->type==STREAMTYPE_DVDNAV) {
2235 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
2237 #endif
2239 total_time_usage_start=GetTimer();
2240 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
2241 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
2242 play_n_frames=play_n_frames_mf;
2244 if(play_n_frames==0){
2245 eof=PT_NEXT_ENTRY; goto goto_next_file;
2248 while(!eof){
2249 float aq_sleep_time=0;
2251 /*========================== PLAY AUDIO ============================*/
2253 while(sh_audio){
2254 unsigned int t;
2255 double tt;
2256 int playsize;
2258 current_module="play_audio";
2260 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2261 playsize=audio_out->get_space();
2263 // handle audio-only case:
2264 if(playsize < ao_data.outburst &&
2265 !sh_video) { // buffer is full, do not block here!!!
2266 usec_sleep(10000); // Wait a tick before retry
2267 continue;
2270 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
2272 // Fill buffer if needed:
2273 current_module="decode_audio"; // Enter AUDIO decoder module
2274 t=GetTimer();
2275 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
2276 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
2277 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
2278 if(ret<=0) break; // EOF?
2279 sh_audio->a_out_buffer_len+=ret;
2281 t=GetTimer()-t;
2282 tt = t*0.000001f; audio_time_usage+=tt;
2283 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
2285 // play audio:
2286 current_module="play_audio";
2287 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2289 if(playsize>0){
2290 sh_audio->a_out_buffer_len-=playsize;
2291 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2292 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2293 ao_data.bps : sh_audio->o_bps));
2296 break;
2297 } // while(sh_audio)
2299 if(!sh_video) {
2300 // handle audio-only case:
2301 if(!quiet) {
2302 float a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
2303 print_status(a_pos, 0, 0);
2305 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2307 } else {
2309 /*========================== PLAY VIDEO ============================*/
2311 float frame_time=next_frame_time;
2313 vo_pts=sh_video->timer*90000.0;
2314 vo_fps=sh_video->fps;
2316 if(!frame_time_remaining){
2317 //-------------------- Decode a frame: -----------------------
2318 vdecode_time=video_time_usage;
2319 while(1)
2320 { unsigned char* start=NULL;
2321 int in_size;
2322 // get it!
2323 current_module="video_read_frame";
2324 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2325 if(in_size<0){ eof=1; break; }
2326 if(in_size>max_framesize) max_framesize=in_size; // stats
2327 sh_video->timer+=frame_time;
2328 if(sh_audio) sh_audio->delay-=frame_time;
2329 time_frame+=frame_time; // for nosound
2330 // video_read_frame can change fps (e.g. for asf video)
2331 vo_fps = sh_video->fps;
2332 #ifdef HAVE_X11
2333 vo_mouse_timer_const = (int)sh_video->fps;
2334 #endif
2335 // check for frame-drop:
2336 current_module="check_framedrop";
2337 if(sh_audio && !d_audio->eof){
2338 float delay=playback_speed*audio_out->get_delay();
2339 float d=delay-sh_audio->delay;
2340 // we should avoid dropping to many frames in sequence unless we
2341 // are too late. and we allow 100ms A-V delay here:
2342 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
2343 drop_frame=frame_dropping;
2344 ++drop_frame_cnt;
2345 ++dropped_frames;
2346 } else {
2347 drop_frame=dropped_frames=0;
2349 ++total_frame_cnt;
2351 // decode:
2352 current_module="decode_video";
2353 // printf("Decode! %p %d \n",start,in_size);
2354 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2355 break;
2357 vdecode_time=video_time_usage-vdecode_time;
2358 //------------------------ frame decoded. --------------------
2360 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2362 if(sh_video->vf_inited<0){
2363 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2364 eof=1; goto goto_next_file;
2369 // ==========================================================================
2371 // current_module="draw_osd";
2372 // if(vo_config_count) video_out->draw_osd();
2374 #ifdef HAVE_NEW_GUI
2375 if(use_gui) guiEventHandling();
2376 #endif
2378 current_module="calc_sleep_time";
2380 #if 0
2381 { // debug frame dropping code
2382 float delay=audio_out->get_delay();
2383 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2384 sh_video->timer,sh_audio->timer-delay,
2385 sh_video->timer-(sh_audio->timer-delay),
2386 delay,drop_frame);
2388 #endif
2390 if(drop_frame && !frame_time_remaining && !autosync){
2392 * Note: time_frame should not be forced to 0 in autosync mode.
2393 * It is used as a cumulative counter to predict and correct the
2394 * delay measurements from the audio driver. time_frame is already
2395 * < 0, so the "time to sleep" code does not actually sleep. Also,
2396 * blit_frame is already 0 because drop_frame was true when
2397 * decode_video was called (which causes it to set blit_frame to 0.)
2398 * When autosync==0, the default behavior is still completely unchanged.
2401 time_frame=0; // don't sleep!
2402 blit_frame=0; // don't display!
2404 } else {
2406 // It's time to sleep...
2408 frame_time_remaining=0;
2409 time_frame-=GetRelativeTime(); // reset timer
2411 if(sh_audio && !d_audio->eof){
2412 float delay=playback_speed*audio_out->get_delay();
2413 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2415 if (autosync){
2417 * Adjust this raw delay value by calculating the expected
2418 * delay for this frame and generating a new value which is
2419 * weighted between the two. The higher autosync is, the
2420 * closer to the delay value gets to that which "-nosound"
2421 * would have used, and the longer it will take for A/V
2422 * sync to settle at the right value (but it eventually will.)
2423 * This settling time is very short for values below 100.
2425 float predicted = sh_audio->delay+time_frame;
2426 float difference = delay - predicted;
2427 delay = predicted + difference / (float)autosync;
2430 time_frame=delay-sh_audio->delay;
2432 // delay = amount of audio buffered in soundcard/driver
2433 if(delay>0.25) delay=0.25; else
2434 if(delay<0.10) delay=0.10;
2435 if(time_frame>delay*0.6){
2436 // sleep time too big - may cause audio drops (buffer underrun)
2437 frame_time_remaining=1;
2438 time_frame=delay*0.5;
2441 } else {
2443 // NOSOUND:
2444 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2445 time_frame=0;
2449 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2451 aq_sleep_time+=time_frame;
2453 } // !drop_frame
2455 //============================== SLEEP: ===================================
2457 time_frame/=playback_speed;
2459 // flag 256 means: libvo driver does its timing (dvb card)
2460 if(time_frame>0.001 && !(vo_flags&256)){
2462 #ifdef HAVE_RTC
2463 if(rtc_fd>=0){
2464 // -------- RTC -----------
2465 current_module="sleep_rtc";
2466 while (time_frame > 0.000) {
2467 unsigned long rtc_ts;
2468 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2469 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2470 time_frame-=GetRelativeTime();
2472 } else
2473 #endif
2474 #ifdef SYS_DARWIN
2476 current_module="sleep_darwin";
2477 while(time_frame>0.005) {
2478 usec_sleep(1000000*time_frame);
2479 time_frame-=GetRelativeTime();
2482 #else
2484 // -------- TIMER + SOFTSLEEP -----------
2485 float min=softsleep?0.021:0.005;
2486 current_module="sleep_timer";
2487 while(time_frame>min){
2488 if(time_frame<=0.020)
2489 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2490 else
2491 usec_sleep(1000000*(time_frame-0.020));
2492 time_frame-=GetRelativeTime();
2494 if(softsleep){
2495 current_module="sleep_soft";
2496 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
2497 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2500 #endif
2503 //if(!frame_time_remaining){ // should we display the frame now?
2505 //====================== FLIP PAGE (VIDEO BLT): =========================
2507 current_module="vo_check_events";
2508 if(vo_config_count) video_out->check_events();
2510 current_module="flip_page";
2511 if (!frame_time_remaining) {
2512 if(blit_frame){
2513 unsigned int t2=GetTimer();
2514 double tt;
2515 float j;
2516 #define FRAME_LAG_WARN 0.2
2517 j = ((float)t2 - lastframeout_ts) / 1000000;
2518 lastframeout_ts = GetTimer();
2519 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2520 too_fast_frame_cnt++;
2521 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2522 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2523 too_slow_frame_cnt++;
2524 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2526 if(vo_config_count) video_out->flip_page();
2527 if (play_n_frames >= 0) {
2528 --play_n_frames;
2529 if (play_n_frames < 0) eof = PT_NEXT_ENTRY;
2532 // usec_sleep(50000); // test only!
2533 t2=GetTimer()-t2;
2534 tt = t2*0.000001f;
2535 vout_time_usage+=tt;
2536 } else {
2538 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2539 otherwise A/V desync will occur. -- Alvieboy
2541 if (vo_config_count)
2542 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2545 //====================== A-V TIMESTAMP CORRECTION: =========================
2547 current_module="av_sync";
2549 if(sh_audio){
2550 float a_pts=0;
2551 float v_pts=0;
2553 // unplayed bytes in our and soundcard/dma buffer:
2554 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2556 if (autosync){
2558 * If autosync is enabled, the value for delay must be calculated
2559 * a bit differently. It is set only to the difference between
2560 * the audio and video timers. Any attempt to include the real
2561 * or corrected delay causes the pts_correction code below to
2562 * try to correct for the changes in delay which autosync is
2563 * trying to measure. This keeps the two from competing, but still
2564 * allows the code to correct for PTS drift *only*. (Using a delay
2565 * value here, even a "corrected" one, would be incompatible with
2566 * autosync mode.)
2568 delay=sh_audio->delay;
2569 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2572 #if 0
2573 if(pts_from_bps){
2574 // PTS = sample_no / samplerate
2575 unsigned int samples=
2576 // (sh_audio->audio.dwSampleSize)?
2577 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2578 ds_tell_block(d_audio); // <- used for VBR audio
2579 samples+=sh_audio->audio.dwStart; // offset
2580 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2581 delay_corrected=1;
2582 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2583 } else
2584 #endif
2586 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2587 a_pts=d_audio->pts;
2588 if(!delay_corrected) if(a_pts) delay_corrected=1;
2589 #if 0
2590 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2591 a_pts,
2592 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2593 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2594 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2595 #endif
2596 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2598 v_pts=sh_video ? sh_video->pts : d_video->pts;
2600 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);
2602 if(delay_corrected){
2603 static int drop_message=0;
2604 float x;
2605 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2606 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2607 ++drop_message;
2608 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2610 x=AV_delay*0.1f;
2611 if(x<-max_pts_correction) x=-max_pts_correction; else
2612 if(x> max_pts_correction) x= max_pts_correction;
2613 if(default_max_pts_correction>=0)
2614 max_pts_correction=default_max_pts_correction;
2615 else
2616 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2617 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2618 if(!quiet)
2619 print_status(a_pts - audio_delay - delay, AV_delay, c_total);
2622 } else {
2623 // No audio:
2625 if(!quiet)
2626 print_status(0, 0, 0);
2630 //============================ Auto QUALITY ============================
2632 /*Output quality adjustments:*/
2633 if(auto_quality>0){
2634 current_module="autoq";
2635 // float total=0.000001f * (GetTimer()-aq_total_time);
2636 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2637 if(output_quality<auto_quality && aq_sleep_time>0)
2638 ++output_quality;
2639 else
2640 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2641 if(output_quality>1 && aq_sleep_time<0)
2642 --output_quality;
2643 else
2644 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2645 output_quality=0;
2646 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2647 set_video_quality(sh_video,output_quality);
2650 } // end if(sh_video)
2652 //============================ Handle PAUSE ===============================
2654 current_module="pause";
2656 #ifdef USE_OSD
2657 if(osd_visible){
2658 if (!--osd_visible){
2659 vo_osd_progbar_type=-1; // disable
2660 vo_osd_changed(OSDTYPE_PROGBAR);
2661 if (osd_function != OSD_PAUSE)
2662 osd_function = OSD_PLAY;
2665 #endif
2667 if(osd_function==OSD_PAUSE){
2668 mp_cmd_t* cmd;
2669 if(!quiet) {
2670 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2671 if (identify)
2672 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_PAUSED\n");
2673 fflush(stdout);
2675 #ifdef HAVE_NEW_GUI
2676 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2677 #endif
2678 if (video_out && sh_video && vo_config_count)
2679 video_out->control(VOCTRL_PAUSE, NULL);
2681 if (audio_out && sh_audio)
2682 audio_out->pause(); // pause audio, keep data if possible
2684 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
2685 if(sh_video && video_out && vo_config_count) video_out->check_events();
2686 #ifdef HAVE_NEW_GUI
2687 if(use_gui){
2688 guiEventHandling();
2689 guiGetEvent( guiReDraw,NULL );
2690 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2692 #endif
2693 #ifdef HAVE_MENU
2694 if(vf_menu)
2695 vf_menu_pause_update(vf_menu);
2696 #endif
2697 usec_sleep(20000);
2699 if (cmd && cmd->id == MP_CMD_PAUSE) {
2700 cmd = mp_input_get_cmd(0,1,0);
2701 mp_cmd_free(cmd);
2703 osd_function=OSD_PLAY;
2704 if (audio_out && sh_audio)
2705 audio_out->resume(); // resume audio
2706 if (video_out && sh_video && vo_config_count)
2707 video_out->control(VOCTRL_RESUME, NULL); // resume video
2708 (void)GetRelativeTime(); // keep TF around FT in next cycle
2709 #ifdef HAVE_NEW_GUI
2710 if (use_gui)
2712 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2713 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2715 #endif
2718 // handle -sstep
2719 if(step_sec>0) {
2720 osd_function=OSD_FFW;
2721 rel_seek_secs+=step_sec;
2724 #ifdef USE_DVDNAV
2725 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2726 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2727 #endif
2729 //================= EDL =========================================
2731 #ifdef USE_EDL
2732 if( next_edl_record ) { // Are we (still?) doing EDL?
2733 if ( !sh_video ) {
2734 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
2735 free_edl(edl_records);
2736 next_edl_record = NULL;
2737 edl_records = NULL;
2738 } else {
2739 if( sh_video->pts >= next_edl_record->start_sec ) {
2740 if( next_edl_record->action == EDL_SKIP ) {
2741 osd_function = OSD_FFW;
2742 abs_seek_pos = 0;
2743 rel_seek_secs = next_edl_record->length_sec;
2744 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 );
2745 edl_decision = 1;
2746 } else if( next_edl_record->action == EDL_MUTE ) {
2747 edl_muted = !edl_muted;
2748 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
2749 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
2751 next_edl_record=next_edl_record->next;
2755 #endif
2757 //================= Keyboard events, SEEKing ====================
2759 current_module="key_events";
2762 mp_cmd_t* cmd;
2763 int brk_cmd = 0;
2764 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
2765 switch(cmd->id) {
2766 case MP_CMD_SEEK : {
2767 float v;
2768 int abs;
2769 osd_show_percentage = 25;
2770 v = cmd->args[0].v.f;
2771 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2772 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2773 abs_seek_pos = 1;
2774 if(sh_video)
2775 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2776 rel_seek_secs = v;
2778 else if(abs) { /* Absolute seek by percentage */
2779 abs_seek_pos = 3;
2780 if(sh_video)
2781 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2782 rel_seek_secs = v/100.0;
2784 else {
2785 rel_seek_secs+= v;
2786 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2788 brk_cmd = 1;
2789 } break;
2790 #ifdef USE_EDL
2791 case MP_CMD_EDL_MARK:
2792 if( edl_fd ) {
2793 float v = sh_video->pts;
2794 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2796 break;
2797 #endif
2798 case MP_CMD_SWITCH_RATIO : {
2799 if (cmd->nargs == 0)
2800 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2801 else
2802 movie_aspect = cmd->args[0].v.f;
2803 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2804 } break;
2805 case MP_CMD_AUDIO_DELAY : {
2806 float v = cmd->args[0].v.f;
2807 audio_delay += v;
2808 osd_show_av_delay = 9;
2809 if(sh_audio) sh_audio->delay+= v;
2810 } break;
2811 case MP_CMD_SPEED_INCR : {
2812 float v = cmd->args[0].v.f;
2813 playback_speed += v;
2814 if (sh_video)
2815 osd_show_speed = sh_video->fps;
2816 build_afilter_chain(sh_audio, &ao_data);
2817 } break;
2818 case MP_CMD_SPEED_MULT : {
2819 float v = cmd->args[0].v.f;
2820 playback_speed *= v;
2821 if (sh_video)
2822 osd_show_speed = sh_video->fps;
2823 build_afilter_chain(sh_audio, &ao_data);
2824 } break;
2825 case MP_CMD_SPEED_SET : {
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_FRAME_STEP :
2833 case MP_CMD_PAUSE : {
2834 cmd->pausing = 1;
2835 brk_cmd = 1;
2836 } break;
2837 case MP_CMD_QUIT : {
2838 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
2840 case MP_CMD_GRAB_FRAMES : {
2841 grab_frames=2;
2842 } break;
2843 case MP_CMD_PLAY_TREE_STEP : {
2844 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2845 int force = cmd->args[1].v.i;
2847 #ifdef HAVE_NEW_GUI
2848 if (use_gui) {
2849 int i=0;
2850 if (n>0)
2851 for (i=0;i<n;i++)
2852 mplNext();
2853 else
2854 for (i=0;i<-1*n;i++)
2855 mplPrev();
2856 } else
2857 #endif
2859 if(!force && playtree_iter) {
2860 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2862 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2863 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2864 play_tree_iter_free(i);
2865 } else
2866 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2867 if(eof)
2868 play_tree_step = n;
2869 brk_cmd = 1;
2871 } break;
2872 case MP_CMD_PLAY_TREE_UP_STEP : {
2873 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2874 int force = cmd->args[1].v.i;
2876 if(!force && playtree_iter) {
2877 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2878 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2879 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2880 play_tree_iter_free(i);
2881 } else
2882 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2883 brk_cmd = 1;
2884 } break;
2885 case MP_CMD_PLAY_ALT_SRC_STEP : {
2886 if(playtree_iter && playtree_iter->num_files > 1) {
2887 int v = cmd->args[0].v.i;
2888 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2889 eof = PT_NEXT_SRC;
2890 else if(v < 0 && playtree_iter->file > 1)
2891 eof = PT_PREV_SRC;
2893 brk_cmd = 1;
2894 } break;
2895 case MP_CMD_SUB_DELAY : {
2896 #ifdef USE_SUB
2897 if (sh_video) {
2898 int abs= cmd->args[1].v.i;
2899 float v = cmd->args[0].v.f;
2900 if(abs)
2901 sub_delay = v;
2902 else
2903 sub_delay += v;
2904 osd_show_sub_delay = 9; // show the subdelay in OSD
2906 #endif
2907 } break;
2908 case MP_CMD_SUB_STEP : {
2909 #ifdef USE_SUB
2910 if (sh_video) {
2911 int movement = cmd->args[0].v.i;
2912 step_sub(subdata, sh_video->pts, movement);
2913 osd_show_sub_delay = 9; // show the subdelay in OSD
2915 #endif
2916 } break;
2917 case MP_CMD_SUB_LOG : {
2918 #ifdef USE_SUB
2919 log_sub();
2920 #endif
2921 } break;
2922 case MP_CMD_OSD : {
2923 #ifdef USE_OSD
2924 if(sh_video) {
2925 int v = cmd->args[0].v.i;
2926 if(v < 0)
2927 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2928 else
2929 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2930 /* Show OSD state when disabled, but not when an explicit
2931 argument is given to the osd command, i.e. in slave mode. */
2932 if (v == -1 && osd_level <= 1)
2933 osd_show_status = 9;
2935 #endif
2936 } break;
2937 case MP_CMD_OSD_SHOW_TEXT : {
2938 #ifdef USE_OSD
2939 if(osd_level && sh_video){
2940 osd_show_text=sh_video->fps; // 1 sec
2941 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2943 #endif
2944 } break;
2945 case MP_CMD_VOLUME : {
2946 int v = cmd->args[0].v.i;
2948 // start change for absolute volume value
2949 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2951 #ifdef USE_EDL
2952 if (edl_muted) break;
2953 user_muted = 0;
2954 #endif
2955 if( abs )
2957 mixer_setvolume(&mixer, (float)v, (float)v );
2958 } else {
2959 if(v > 0)
2960 mixer_incvolume(&mixer);
2961 else
2962 mixer_decvolume(&mixer);
2965 #ifdef USE_OSD
2966 if(osd_level && sh_video){
2967 float vol;
2968 osd_visible=sh_video->fps; // 1 sec
2969 vo_osd_progbar_type=OSD_VOLUME;
2970 mixer_getbothvolume(&mixer, &vol);
2971 vo_osd_progbar_value=(vol*256.0)/100.0;
2972 vo_osd_changed(OSDTYPE_PROGBAR);
2974 #endif
2975 } break;
2976 case MP_CMD_MUTE:
2977 #ifdef USE_EDL
2978 user_muted = !user_muted;
2979 if ((edl_muted | user_muted) != mixer.muted)
2980 #endif
2981 mixer_mute(&mixer);
2982 break;
2983 case MP_CMD_LOADFILE : {
2984 play_tree_t* e = play_tree_new();
2985 play_tree_add_file(e,cmd->args[0].v.s);
2987 // Go back to the start point
2988 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2989 /* NOP */;
2990 play_tree_free_list(playtree->child,1);
2991 play_tree_set_child(playtree,e);
2992 play_tree_iter_step(playtree_iter,0,0);
2993 eof = PT_NEXT_SRC;
2994 brk_cmd = 1;
2995 } break;
2996 case MP_CMD_LOADLIST : {
2997 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
2998 if(!e)
2999 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
3000 else {
3001 // Go back to the start point
3002 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
3003 /* NOP */;
3004 play_tree_free_list(playtree->child,1);
3005 play_tree_set_child(playtree,e);
3006 play_tree_iter_step(playtree_iter,0,0);
3007 eof = PT_NEXT_SRC;
3009 brk_cmd = 1;
3010 } break;
3011 case MP_CMD_GAMMA : {
3012 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3014 if (!sh_video)
3015 break;
3017 if (vo_gamma_gamma == 1000)
3019 vo_gamma_gamma = 0;
3020 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
3023 if (abs)
3024 vo_gamma_gamma = v;
3025 else
3026 vo_gamma_gamma += v;
3028 if (vo_gamma_gamma > 100)
3029 vo_gamma_gamma = 100;
3030 else if (vo_gamma_gamma < -100)
3031 vo_gamma_gamma = -100;
3032 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
3033 #ifdef USE_OSD
3034 if(osd_level){
3035 osd_visible=sh_video->fps; // 1 sec
3036 vo_osd_progbar_type=OSD_BRIGHTNESS;
3037 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
3038 vo_osd_changed(OSDTYPE_PROGBAR);
3040 #endif // USE_OSD
3041 } break;
3042 case MP_CMD_BRIGHTNESS : {
3043 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3045 if (!sh_video)
3046 break;
3048 if (vo_gamma_brightness == 1000)
3050 vo_gamma_brightness = 0;
3051 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
3054 if (abs)
3055 vo_gamma_brightness = v;
3056 else
3057 vo_gamma_brightness += v;
3059 if (vo_gamma_brightness > 100)
3060 vo_gamma_brightness = 100;
3061 else if (vo_gamma_brightness < -100)
3062 vo_gamma_brightness = -100;
3063 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
3064 #ifdef USE_OSD
3065 if(osd_level){
3066 osd_visible=sh_video->fps; // 1 sec
3067 vo_osd_progbar_type=OSD_BRIGHTNESS;
3068 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
3069 vo_osd_changed(OSDTYPE_PROGBAR);
3071 #endif // USE_OSD
3073 } break;
3074 case MP_CMD_CONTRAST : {
3075 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3077 if (!sh_video)
3078 break;
3080 if (vo_gamma_contrast == 1000)
3082 vo_gamma_contrast = 0;
3083 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
3086 if (abs)
3087 vo_gamma_contrast = v;
3088 else
3089 vo_gamma_contrast += v;
3091 if (vo_gamma_contrast > 100)
3092 vo_gamma_contrast = 100;
3093 else if (vo_gamma_contrast < -100)
3094 vo_gamma_contrast = -100;
3095 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
3096 #ifdef USE_OSD
3097 if(osd_level){
3098 osd_visible=sh_video->fps; // 1 sec
3099 vo_osd_progbar_type=OSD_CONTRAST;
3100 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
3101 vo_osd_changed(OSDTYPE_PROGBAR);
3103 #endif // USE_OSD
3105 } break;
3106 case MP_CMD_SATURATION : {
3107 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3109 if (!sh_video)
3110 break;
3112 if (vo_gamma_saturation == 1000)
3114 vo_gamma_saturation = 0;
3115 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
3118 if (abs)
3119 vo_gamma_saturation = v;
3120 else
3121 vo_gamma_saturation += v;
3123 if (vo_gamma_saturation > 100)
3124 vo_gamma_saturation = 100;
3125 else if (vo_gamma_saturation < -100)
3126 vo_gamma_saturation = -100;
3127 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
3128 #ifdef USE_OSD
3129 if(osd_level){
3130 osd_visible=sh_video->fps; // 1 sec
3131 vo_osd_progbar_type=OSD_SATURATION;
3132 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
3133 vo_osd_changed(OSDTYPE_PROGBAR);
3135 #endif // USE_OSD
3137 } break;
3138 case MP_CMD_HUE : {
3139 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3141 if (!sh_video)
3142 break;
3144 if (vo_gamma_hue == 1000)
3146 vo_gamma_hue = 0;
3147 get_video_colors(sh_video, "hue", &vo_gamma_hue);
3150 if (abs)
3151 vo_gamma_hue = v;
3152 else
3153 vo_gamma_hue += v;
3155 if (vo_gamma_hue > 100)
3156 vo_gamma_hue = 100;
3157 else if (vo_gamma_hue < -100)
3158 vo_gamma_hue = -100;
3159 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
3160 #ifdef USE_OSD
3161 if(osd_level){
3162 osd_visible=sh_video->fps; // 1 sec
3163 vo_osd_progbar_type=OSD_HUE;
3164 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
3165 vo_osd_changed(OSDTYPE_PROGBAR);
3167 #endif // USE_OSD
3169 } break;
3170 case MP_CMD_FRAMEDROPPING : {
3171 int v = cmd->args[0].v.i;
3172 if(v < 0){
3173 frame_dropping = (frame_dropping+1)%3;
3174 #ifdef USE_OSD
3175 osd_show_framedropping=10;
3176 vo_osd_changed(OSDTYPE_SUBTITLE);
3177 #endif
3179 else
3180 frame_dropping = v > 2 ? 2 : v;
3181 } break;
3182 #ifdef USE_TV
3183 case MP_CMD_TV_SET_FREQ : {
3184 if (file_format == DEMUXER_TYPE_TV)
3185 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
3186 } break;
3187 case MP_CMD_TV_SET_NORM : {
3188 if (file_format == DEMUXER_TYPE_TV)
3189 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3190 } break;
3191 case MP_CMD_TV_SET_BRIGHTNESS : {
3192 if (file_format == DEMUXER_TYPE_TV)
3193 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
3194 } break;
3195 case MP_CMD_TV_SET_HUE : {
3196 if (file_format == DEMUXER_TYPE_TV)
3197 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
3198 } break;
3199 case MP_CMD_TV_SET_SATURATION : {
3200 if (file_format == DEMUXER_TYPE_TV)
3201 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
3202 } break;
3203 case MP_CMD_TV_SET_CONTRAST : {
3204 if (file_format == DEMUXER_TYPE_TV)
3205 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
3206 } break;
3207 case MP_CMD_TV_STEP_CHANNEL : {
3208 if (file_format == DEMUXER_TYPE_TV) {
3209 int v = cmd->args[0].v.i;
3210 if(v > 0){
3211 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
3212 #ifdef USE_OSD
3213 if (tv_channel_list) {
3214 osd_show_tv_channel = sh_video->fps;
3215 vo_osd_changed(OSDTYPE_SUBTITLE);
3217 #endif
3218 } else {
3219 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
3220 #ifdef USE_OSD
3221 if (tv_channel_list) {
3222 osd_show_tv_channel = sh_video->fps;
3223 vo_osd_changed(OSDTYPE_SUBTITLE);
3225 #endif
3229 #ifdef HAS_DVBIN_SUPPORT
3230 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3232 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3233 if(priv->is_on)
3235 int dir;
3236 int v = cmd->args[0].v.i;
3238 last_dvb_step = v;
3239 if(v > 0)
3240 dir = DVB_CHANNEL_HIGHER;
3241 else
3242 dir = DVB_CHANNEL_LOWER;
3245 if(dvb_step_channel(priv, dir))
3247 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3248 cache_uninit(stream);
3249 goto goto_enable_cache;
3253 #endif
3254 break;
3255 case MP_CMD_TV_SET_CHANNEL : {
3256 if (file_format == DEMUXER_TYPE_TV) {
3257 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3258 #ifdef USE_OSD
3259 if (tv_channel_list) {
3260 osd_show_tv_channel = sh_video->fps;
3261 vo_osd_changed(OSDTYPE_SUBTITLE);
3263 #endif
3265 } break;
3266 #ifdef HAS_DVBIN_SUPPORT
3267 case MP_CMD_DVB_SET_CHANNEL:
3269 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3271 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3272 if(priv->is_on)
3274 if(priv->list->current <= cmd->args[0].v.i)
3275 last_dvb_step = 1;
3276 else
3277 last_dvb_step = -1;
3279 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
3281 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3282 cache_uninit(stream);
3283 goto goto_enable_cache;
3288 #endif
3289 case MP_CMD_TV_LAST_CHANNEL : {
3290 if (file_format == DEMUXER_TYPE_TV) {
3291 tv_last_channel((tvi_handle_t*)(demuxer->priv));
3292 #ifdef USE_OSD
3293 if (tv_channel_list) {
3294 osd_show_tv_channel = sh_video->fps;
3295 vo_osd_changed(OSDTYPE_SUBTITLE);
3297 #endif
3299 } break;
3300 case MP_CMD_TV_STEP_NORM : {
3301 if (file_format == DEMUXER_TYPE_TV)
3302 tv_step_norm((tvi_handle_t*)(demuxer->priv));
3303 } break;
3304 case MP_CMD_TV_STEP_CHANNEL_LIST : {
3305 if (file_format == DEMUXER_TYPE_TV)
3306 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
3307 } break;
3308 #endif
3309 case MP_CMD_SWITCH_VSYNC: {
3310 vo_vsync = ( cmd->nargs > 0 )? cmd->args[0].v.i : !vo_vsync;
3311 } break;
3312 case MP_CMD_VO_FULLSCREEN:
3314 #ifdef HAVE_NEW_GUI
3315 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3316 else
3317 #endif
3318 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3319 } break;
3320 case MP_CMD_VO_ONTOP:
3322 if(video_out && vo_config_count) {
3323 video_out->control(VOCTRL_ONTOP, 0);
3324 #ifdef USE_OSD
3325 osd_show_ontop=10;
3326 vo_osd_changed(OSDTYPE_SUBTITLE);
3327 #endif
3330 } break;
3331 case MP_CMD_VO_ROOTWIN:
3333 if(video_out && vo_config_count) {
3334 video_out->control(VOCTRL_ROOTWIN, 0);
3335 #ifdef USE_OSD
3336 osd_show_rootwin=10;
3337 vo_osd_changed(OSDTYPE_SUBTITLE);
3338 #endif
3341 } break;
3342 case MP_CMD_PANSCAN : {
3343 if ( !video_out ) break;
3344 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3346 int abs= cmd->args[1].v.i;
3347 float v = cmd->args[0].v.f;
3348 float res;
3349 if(abs) res = v;
3350 else res = vo_panscan+v;
3351 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3352 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3353 #ifdef USE_OSD
3354 if(osd_level && sh_video){
3355 osd_visible=sh_video->fps; // 1 sec
3356 vo_osd_progbar_type=OSD_PANSCAN;
3357 vo_osd_progbar_value=vo_panscan*256;
3358 vo_osd_changed(OSDTYPE_PROGBAR);
3360 #endif
3362 } break;
3363 case MP_CMD_SUB_POS:
3365 #ifdef USE_SUB
3366 if (sh_video) {
3367 int v;
3368 v = cmd->args[0].v.i;
3370 sub_pos+=v;
3371 if(sub_pos >100) sub_pos=100;
3372 if(sub_pos <0) sub_pos=0;
3373 vo_osd_changed(OSDTYPE_SUBTITLE);
3374 osd_show_sub_pos = 9;
3376 #endif
3377 } break;
3378 case MP_CMD_SUB_ALIGNMENT:
3380 #ifdef USE_SUB
3381 if (sh_video) {
3382 if (cmd->nargs >= 1)
3383 sub_alignment = cmd->args[0].v.i;
3384 else
3385 sub_alignment = (sub_alignment+1) % 3;
3386 osd_show_sub_alignment = 9;
3387 vo_osd_changed(OSDTYPE_SUBTITLE);
3389 #endif
3390 } break;
3391 case MP_CMD_SUB_VISIBILITY:
3393 #ifdef USE_SUB
3394 if (sh_video) {
3395 sub_visibility=1-sub_visibility;
3396 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3397 vo_osd_changed(OSDTYPE_SUBTITLE);
3399 #endif
3400 } break;
3401 case MP_CMD_SUB_LOAD:
3403 #ifdef USE_SUB
3404 if (sh_video) {
3405 int n = set_of_sub_size;
3406 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
3407 if (n != set_of_sub_size) {
3408 if (global_sub_indices[SUB_SOURCE_SUBS] < 0)
3409 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size;
3410 ++global_sub_size;
3413 #endif
3414 } break;
3415 case MP_CMD_SUB_REMOVE:
3417 #ifdef USE_SUB
3418 if (sh_video) {
3419 int v = cmd->args[0].v.i;
3420 sub_data *subd;
3421 if (v < 0) {
3422 for (v = 0; v < set_of_sub_size; ++v) {
3423 subd = set_of_subtitles[v];
3424 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
3425 sub_free(subd);
3426 set_of_subtitles[v] = NULL;
3428 global_sub_indices[SUB_SOURCE_SUBS] = -1;
3429 global_sub_size -= set_of_sub_size;
3430 set_of_sub_size = 0;
3431 if (set_of_sub_pos >= 0) {
3432 global_sub_pos = -2;
3433 vo_sub_last = vo_sub = NULL;
3434 vo_osd_changed(OSDTYPE_SUBTITLE);
3435 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
3436 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3439 else if (v < set_of_sub_size) {
3440 subd = set_of_subtitles[v];
3441 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
3442 sub_free(subd);
3443 if (set_of_sub_pos == v) {
3444 global_sub_pos = -2;
3445 vo_sub_last = vo_sub = NULL;
3446 vo_osd_changed(OSDTYPE_SUBTITLE);
3447 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
3448 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3450 else if (set_of_sub_pos > v) {
3451 --set_of_sub_pos;
3452 --global_sub_pos;
3454 while (++v < set_of_sub_size)
3455 set_of_subtitles[v - 1] = set_of_subtitles[v];
3456 --set_of_sub_size;
3457 --global_sub_size;
3458 if (set_of_sub_size <= 0)
3459 global_sub_indices[SUB_SOURCE_SUBS] = -1;
3460 set_of_subtitles[set_of_sub_size] = NULL;
3463 #endif
3464 } break;
3465 case MP_CMD_GET_SUB_VISIBILITY:
3467 #ifdef USE_SUB
3468 if (sh_video) {
3469 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%ld\n", sub_visibility);
3471 #endif
3472 } break;
3473 case MP_CMD_SUB_SELECT:
3474 if (global_sub_size) {
3475 int source = -1;
3476 int v = cmd->args[0].v.i;
3478 if (v < -1)
3479 global_sub_pos++;
3480 else
3481 global_sub_pos = v;
3482 if (global_sub_pos >= global_sub_size)
3483 global_sub_pos = -1;
3484 if (global_sub_pos >= 0)
3485 source = sub_source();
3487 mp_msg(MSGT_CPLAYER, MSGL_DBG3, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3488 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
3489 global_sub_indices[SUB_SOURCE_SUBS], global_sub_indices[SUB_SOURCE_DEMUX],
3490 global_sub_pos, source);
3492 #ifdef USE_SUB
3493 set_of_sub_pos = -1;
3494 subdata = NULL;
3495 vo_sub_last = vo_sub = NULL;
3496 #endif
3497 vobsub_id = -1;
3498 dvdsub_id = -1;
3499 if (d_dvdsub) d_dvdsub->id = -1;
3501 // be careful!
3502 // if sub_changed is till on but subdata's been reset, bad things happen.
3503 osd_show_vobsub_changed = 0;
3504 osd_show_sub_changed = 0;
3506 if (source == SUB_SOURCE_VOBSUB) {
3507 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
3508 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3509 #ifdef USE_SUB
3510 } else if (source == SUB_SOURCE_SUBS) {
3511 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
3512 subdata = set_of_subtitles[set_of_sub_pos];
3513 if (!global_sub_quiet_osd_hack) osd_show_sub_changed = sh_video->fps;
3514 vo_osd_changed(OSDTYPE_SUBTITLE);
3516 // FIXME: is this the correct place for these?
3517 if(stream_dump_type==3) list_sub_file(subdata);
3518 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
3519 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
3520 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
3521 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
3522 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
3523 #endif
3524 } else if (source == SUB_SOURCE_DEMUX) {
3525 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
3526 if (d_dvdsub) {
3527 #ifdef USE_DVDREAD
3528 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
3529 d_dvdsub->id = dvdsub_id;
3530 spudec_reset(vo_spudec);
3532 #endif
3533 #ifdef HAVE_OGGVORBIS
3534 if (demuxer->type == DEMUXER_TYPE_OGG)
3535 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
3536 #endif
3537 #ifdef HAVE_MATROSKA
3538 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3539 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
3540 if (d_dvdsub->id >= 0 && ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
3541 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
3542 if (vo_spudec != NULL)
3543 spudec_free(vo_spudec);
3544 vo_spudec =
3545 spudec_new_scaled_vobsub(mkv_sh_sub->has_palette ? mkv_sh_sub->palette : NULL, mkv_sh_sub->colors,
3546 mkv_sh_sub->custom_colors,
3547 mkv_sh_sub->width,
3548 mkv_sh_sub->height);
3549 if (!forced_subs_only)
3550 forced_subs_only = mkv_sh_sub->forced_subs_only;
3551 if (vo_spudec) {
3552 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
3553 inited_flags |= INITED_SPUDEC;
3557 #endif
3559 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3560 } else { // off
3561 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3562 #ifdef USE_SUB
3563 vo_osd_changed(OSDTYPE_SUBTITLE);
3564 #endif
3566 // it's annoying and dumb to show osd saying "off" at every subless file...
3567 global_sub_quiet_osd_hack = 0;
3569 break;
3570 case MP_CMD_SUB_FORCED_ONLY:
3571 if (vo_spudec) {
3572 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3573 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3575 break;
3576 case MP_CMD_SCREENSHOT :
3577 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3578 break;
3579 case MP_CMD_VF_CHANGE_RECTANGLE:
3580 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3581 break;
3583 case MP_CMD_GET_TIME_LENGTH : {
3584 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
3585 } break;
3587 case MP_CMD_GET_VO_FULLSCREEN : {
3588 if(video_out && vo_config_count)
3589 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VO_FULLSCREEN=%ld\n", vo_fs);
3590 } break;
3592 case MP_CMD_GET_PERCENT_POS : {
3593 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer));
3594 } break;
3595 case MP_CMD_GET_TIME_POS : {
3596 float pos = 0;
3597 if (sh_video)
3598 pos = sh_video->pts;
3599 else
3600 if (sh_audio && audio_out)
3601 pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
3602 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3603 } break;
3604 case MP_CMD_SWITCH_AUDIO : {
3605 int v = demuxer_switch_audio(demuxer, cmd->args[0].v.i);
3606 if (identify)
3607 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", v);
3608 } break;
3609 case MP_CMD_RUN : {
3610 #ifndef __MINGW32__
3611 if(!fork()) {
3612 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
3613 exit(0);
3615 #endif
3616 } break;
3618 #ifdef USE_DVDNAV
3619 case MP_CMD_DVDNAV_EVENT: {
3620 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3621 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3623 /* ignore these events if we're not in dvd_nav mode */
3624 if (stream->type != STREAMTYPE_DVDNAV) break;
3626 if (!dvdnav_event) {
3627 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNullEvent);
3628 break;
3631 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3633 switch (dvdnav_event->event) {
3634 case DVDNAV_BLOCK_OK: {
3635 /* be silent about this one */
3636 break;
3638 case DVDNAV_HIGHLIGHT: {
3639 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3640 if (!hevent) {
3641 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightEventBroken);
3642 break;
3645 if (hevent->display && hevent->buttonN>0)
3647 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3648 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3649 hevent->buttonN,
3650 hevent->sx,hevent->sy,
3651 hevent->ex,hevent->ey,
3652 hevent->pts, d_video->pts);
3653 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavEvent,dvd_nav_text);
3654 //osd_show_dvd_nav_delay = 60;
3656 osd_show_dvd_nav_highlight=1;
3657 osd_show_dvd_nav_sx=hevent->sx;
3658 osd_show_dvd_nav_ex=hevent->ex;
3659 osd_show_dvd_nav_sy=hevent->sy;
3660 osd_show_dvd_nav_ey=hevent->ey;
3662 else {
3663 osd_show_dvd_nav_highlight=0;
3664 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightHide);
3666 break;
3668 case DVDNAV_STILL_FRAME: {
3669 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3671 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavStillFrame, still_event->length );
3672 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3673 usec_sleep(1000); /* 1ms */
3675 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3676 break;
3678 case DVDNAV_STOP: {
3679 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavStop );
3680 break;
3682 case DVDNAV_NOP: {
3683 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavNOP);
3684 break;
3686 case DVDNAV_SPU_STREAM_CHANGE: {
3687 #if DVDNAVVERSION > 012
3688 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3690 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChangeVerbose,
3691 stream_change->physical_wide,
3692 stream_change->physical_letterbox,
3693 stream_change->physical_pan_scan,
3694 stream_change->logical);
3696 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3697 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3698 d_dvdsub->id,stream_change->physical_wide);
3699 // FIXME: need a better way to change SPU id
3700 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3701 if (vo_spudec) spudec_reset(vo_spudec);
3703 #else
3704 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3706 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChange,
3707 stream_change->physical,
3708 stream_change->logical);
3710 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3711 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3712 d_dvdsub->id,stream_change->physical);
3713 // FIXME: need a better way to change SPU id
3714 d_dvdsub->id=dvdsub_id=stream_change->physical;
3715 if (vo_spudec) spudec_reset(vo_spudec);
3717 #endif
3718 break;
3720 case DVDNAV_AUDIO_STREAM_CHANGE: {
3721 int aid_temp;
3722 #if DVDNAVVERSION > 012
3723 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3724 #else
3725 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3726 #endif
3728 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavAudioStreamChange,
3729 stream_change->physical,
3730 stream_change->logical);
3732 aid_temp=stream_change->physical;
3733 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3734 if (d_audio && audio_id!=aid_temp) {
3735 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3736 d_audio->id,aid_temp);
3737 // FIXME: need a bettery way to change audio stream id
3738 d_audio->id=dvdsub_id=aid_temp;
3739 if(sh_audio) resync_audio_stream(sh_audio);
3742 break;
3744 case DVDNAV_VTS_CHANGE: {
3745 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavVTSChange);
3746 break;
3748 case DVDNAV_CELL_CHANGE: {
3749 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3750 cell_playback_t * cell_playback = cell_change->new_cell;
3752 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavCellChange);
3753 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3755 printf("new still time: %d\n",cell_playback->still_time);
3756 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3757 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3758 cell_playback->playback_time.hour,
3759 cell_playback->playback_time.minute,
3760 cell_playback->playback_time.second,
3761 cell_playback->playback_time.frame_u);
3764 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3765 //abs_seek_pos=0;
3766 break;
3768 case DVDNAV_NAV_PACKET: {
3769 // printf("DVDNAV Event: Nav Packet\n");
3770 break;
3772 case DVDNAV_SPU_CLUT_CHANGE: {
3773 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3775 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuClutChange);
3776 // send new palette to SPU decoder
3777 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3779 break;
3781 case DVDNAV_SEEK_DONE: {
3782 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSeekDone);
3783 break;
3787 // free the dvdnav event
3788 free(dvdnav_event->details);
3789 free(dvdnav_event);
3790 cmd->args[0].v.v=NULL;
3792 case MP_CMD_DVDNAV: {
3793 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3795 /* ignore these events if we're not in dvd_nav mode */
3796 if (stream->type != STREAMTYPE_DVDNAV) break;
3798 switch (cmd->args[0].v.i) {
3799 case MP_CMD_DVDNAV_UP:
3800 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3801 break;
3802 case MP_CMD_DVDNAV_DOWN:
3803 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3804 break;
3805 case MP_CMD_DVDNAV_LEFT:
3806 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3807 break;
3808 case MP_CMD_DVDNAV_RIGHT:
3809 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3810 break;
3811 case MP_CMD_DVDNAV_MENU:
3812 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_MenuCall);
3813 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3814 break;
3815 case MP_CMD_DVDNAV_SELECT:
3816 dvdnav_button_activate(dvdnav_priv->dvdnav);
3817 break;
3818 default:
3819 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3820 break;
3822 break;
3824 #endif
3825 default : {
3826 #ifdef HAVE_NEW_GUI
3827 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3828 else
3829 #endif
3830 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3833 if (cmd->pausing)
3834 osd_function = OSD_PAUSE;
3835 mp_cmd_free(cmd);
3839 if (seek_to_sec) {
3840 int a,b; float d;
3842 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3843 rel_seek_secs += 3600*a +60*b +d ;
3844 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3845 rel_seek_secs += 60*a +d;
3846 else if (sscanf(seek_to_sec, "%f", &d)==1)
3847 rel_seek_secs += d;
3849 seek_to_sec = NULL;
3852 /* Looping. */
3853 if(eof==1 && loop_times>=0) {
3854 int l = loop_times;
3855 play_tree_iter_step(playtree_iter,0,0);
3856 loop_times = l;
3857 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3859 if(loop_times>1) loop_times--; else
3860 if(loop_times==1) loop_times=-1;
3861 play_n_frames=play_n_frames_mf;
3862 eof=0;
3863 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3864 loop_seek = 1;
3867 if(rel_seek_secs || abs_seek_pos){
3868 current_module="seek";
3869 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3870 // success:
3871 /* FIXME there should be real seeking for vobsub */
3872 if(sh_video) sh_video->pts=d_video->pts;
3873 if (vo_vobsub)
3874 //vobsub_reset(vo_vobsub);
3875 vobsub_seek(vo_vobsub,sh_video->pts);
3876 #if 0
3877 if(sh_video && d_video->packs == 0)
3878 ds_fill_buffer(d_video);
3879 if(sh_audio){
3880 if(d_audio->packs == 0)
3881 ds_fill_buffer(d_audio);
3882 if(verbose>0){
3883 float a_pts=d_audio->pts;
3884 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3885 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);
3887 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);
3888 } else {
3889 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3891 #endif
3892 fflush(stdout);
3894 if(sh_video){
3895 current_module="seek_video_reset";
3896 resync_video_stream(sh_video);
3897 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3900 if(sh_audio){
3901 current_module="seek_audio_reset";
3902 audio_out->reset(); // stop audio, throwing away buffered data
3904 #ifdef USE_OSD
3905 // Set OSD:
3906 if(osd_level && !loop_seek){
3907 #ifdef USE_EDL
3908 if( !edl_decision ) {
3909 #else
3910 if( 1 ) { // Let the compiler optimize this out
3911 #endif
3912 if (sh_video) {
3913 osd_visible=sh_video->fps; // 1 sec
3914 vo_osd_progbar_type=0;
3915 vo_osd_progbar_value=demuxer_get_percent_pos(demuxer) * 256 / 100;
3916 vo_osd_changed(OSDTYPE_PROGBAR);
3920 #endif
3921 if(sh_video) {
3922 c_total=0;
3923 max_pts_correction=0.1;
3924 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3925 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3926 drop_frame_cnt=0;
3927 too_slow_frame_cnt=0;
3928 too_fast_frame_cnt=0;
3930 if(vo_spudec) spudec_reset(vo_spudec);
3933 #ifdef USE_EDL
3935 * We saw a seek, have to rewind the EDL operations stack
3936 * and find the next EDL action to take care of.
3939 edl_muted = 0;
3940 next_edl_record = edl_records;
3942 while (next_edl_record)
3944 /* Trying to remember if we need to mute/unmute first;
3945 * prior EDL implementation lacks this.
3948 if (next_edl_record->start_sec >= sh_video->pts)
3949 break;
3951 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
3952 next_edl_record = next_edl_record->next;
3955 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
3956 #endif
3957 rel_seek_secs=0;
3958 abs_seek_pos=0;
3959 frame_time_remaining=0;
3960 current_module=NULL;
3961 loop_seek=0;
3964 #ifdef HAVE_NEW_GUI
3965 if(use_gui){
3966 guiEventHandling();
3967 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3968 // get pos from frame number / total frames
3969 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3970 } else {
3971 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3972 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3973 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3975 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3976 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3977 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3978 guiGetEvent( guiReDraw,NULL );
3979 guiGetEvent( guiSetVolume,NULL );
3980 if(guiIntfStruct.Playing==0) break; // STOP
3981 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3982 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3983 #ifdef USE_DVDREAD
3984 if ( stream->type == STREAMTYPE_DVD )
3986 dvd_priv_t * dvdp = stream->priv;
3987 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3989 #endif
3991 #endif
3994 //================= Update OSD ====================
3995 #ifdef USE_OSD
3996 if(osd_level>=1 && sh_video){
3997 int pts=sh_video->pts;
3998 char osd_text_tmp[64];
3999 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
4000 vo_osd_text=osd_text_buffer;
4001 #ifdef USE_DVDNAV
4002 if (osd_show_dvd_nav_delay) {
4003 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
4004 osd_show_dvd_nav_delay--;
4005 } else
4006 #endif
4007 #ifdef USE_TV
4008 if (osd_show_tv_channel && tv_channel_list) {
4009 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
4010 osd_show_tv_channel--;
4011 } else
4012 #endif
4013 if (osd_show_text) {
4014 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
4015 osd_show_text--;
4016 } else
4017 if (osd_show_sub_visibility) {
4018 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
4019 osd_show_sub_visibility--;
4020 } else
4021 if (osd_show_vobsub_changed) {
4022 snprintf(osd_text_tmp, 63, "Subtitles: off");
4023 if (vo_vobsub && vobsub_id >= 0) {
4024 const char *language = "none";
4025 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
4026 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
4028 #ifdef HAVE_OGGVORBIS
4029 if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG) {
4030 if (dvdsub_id >= 0) {
4031 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
4032 if (!lang) lang = "unknown";
4033 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4036 #endif
4037 #ifdef USE_DVDREAD
4038 if (vo_spudec && (demuxer->type != DEMUXER_TYPE_MATROSKA)) {
4039 if (dvdsub_id >= 0) {
4040 char lang[5] = "none";
4041 int code = 0;
4042 code = dvd_lang_from_sid(stream, dvdsub_id);
4043 if (code) {
4044 lang[0] = code >> 8;
4045 lang[1] = code;
4046 lang[2] = 0;
4048 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4051 #endif
4052 #ifdef HAVE_MATROSKA
4053 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
4054 char lang[10] = "unknown";
4055 if (dvdsub_id >= 0) {
4056 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
4057 lang[9] = 0;
4058 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4061 #endif
4062 osd_show_vobsub_changed--;
4063 } else
4064 #ifdef USE_SUB
4065 if (osd_show_sub_changed) {
4066 char *tmp2;
4067 tmp = subdata->filename;
4068 if ((tmp2 = strrchr(tmp, '/'))) {
4069 tmp = tmp2+1;
4071 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
4072 set_of_sub_pos + 1,
4073 strlen(tmp) < 20 ? "" : "...",
4074 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
4075 osd_show_sub_changed--;
4076 } else
4077 #endif
4078 if (osd_show_sub_delay) {
4079 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
4080 osd_show_sub_delay--;
4081 } else
4082 if (osd_show_sub_pos) {
4083 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
4084 osd_show_sub_pos--;
4085 } else
4086 if (osd_show_sub_alignment) {
4087 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
4088 (sub_alignment == 2 ? "bottom" :
4089 (sub_alignment == 1 ? "center" : "top")));
4090 osd_show_sub_alignment--;
4091 } else
4092 if (osd_show_av_delay) {
4093 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
4094 osd_show_av_delay--;
4095 } else if (osd_show_speed) {
4096 snprintf(osd_text_tmp, 63, "Speed: x %6.2f", playback_speed);
4097 osd_show_speed--;
4098 } else if (osd_show_ontop) {
4099 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
4100 osd_show_ontop--;
4101 } else if (osd_show_rootwin) {
4102 snprintf(osd_text_tmp, 63, "Rootwin: %sabled", vo_rootwin?"en":"dis");
4103 osd_show_rootwin--;
4104 } else if (osd_show_framedropping) {
4105 snprintf(osd_text_tmp, 63, "Framedropping: %s",
4106 (frame_dropping == 1 ? "on" :
4107 (frame_dropping == 2 ? "hard" : "off")));
4108 osd_show_framedropping--;
4109 } else if(osd_level>=2) {
4110 int len = demuxer_get_time_length(demuxer);
4111 int percentage = -1;
4112 char percentage_text[10];
4113 if (osd_show_percentage) {
4114 percentage = demuxer_get_percent_pos(demuxer);
4115 osd_show_percentage--;
4117 if (percentage >= 0)
4118 snprintf(percentage_text, 9, " (%d%%)", percentage);
4119 else
4120 percentage_text[0] = 0;
4121 if (osd_level == 3)
4122 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);
4123 else
4124 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
4125 } else osd_text_tmp[0]=0;
4127 if(strcmp(vo_osd_text, osd_text_tmp)) {
4128 strncpy(vo_osd_text, osd_text_tmp, 63);
4129 vo_osd_changed(OSDTYPE_OSD);
4131 } else {
4132 if(vo_osd_text) {
4133 vo_osd_text=NULL;
4134 vo_osd_changed(OSDTYPE_OSD);
4137 if (osd_level <= 1 && osd_show_status > 0 && sh_video) {
4138 vo_osd_text = osd_text_buffer;
4139 snprintf(vo_osd_text, 63, "OSD: %sabled", osd_level ? "en" : "dis");
4140 vo_osd_changed(OSDTYPE_OSD);
4141 osd_show_status--;
4143 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
4144 // vo_osd_text=osd_text_buffer;
4145 #endif
4147 #ifdef USE_SUB
4148 // find sub
4149 if(subdata && sh_video && sh_video->pts>0){
4150 float pts=sh_video->pts;
4151 if(sub_fps==0) sub_fps=sh_video->fps;
4152 current_module="find_sub";
4153 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
4154 find_sub(subdata, (pts+sub_delay) *
4155 (subdata->sub_uses_time ? 100. : sub_fps));
4156 if (vo_sub) vo_sub_last = vo_sub;
4157 // FIXME! frame counter...
4158 sub_last_pts = pts;
4160 current_module=NULL;
4162 #endif
4164 #ifdef HAVE_X11
4165 if (stop_xscreensaver && sh_video) {
4166 current_module="stop_xscreensaver";
4167 xscreensaver_heartbeat();
4168 current_module=NULL;
4170 #endif
4172 // DVD sub:
4173 if(vo_config_count && vo_spudec) {
4174 unsigned char* packet=NULL;
4175 int len,timestamp;
4176 current_module="spudec";
4177 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
4178 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
4179 while(1) {
4180 // Vobsub
4181 len = 0;
4182 if(vo_vobsub) {
4183 if(sh_video->pts+sub_delay>=0) {
4184 // The + next_frame_time is there because we'll display the sub at the next frame
4185 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
4186 if(len > 0) {
4187 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
4188 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);
4191 } else {
4192 // DVD sub
4193 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
4194 if(len > 0) {
4195 float x = d_dvdsub->pts - sh_video->pts;
4196 if (x < -10 || x > 10) // prevent missing subs on pts reset
4197 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
4198 else timestamp = 90000*(sh_video->timer + sub_delay);
4199 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);
4202 if(len<=0 || !packet) break;
4203 if(timestamp < 0) timestamp = 0;
4204 else spudec_assemble(vo_spudec,packet,len,timestamp);
4207 /* detect wether the sub has changed or not */
4208 if(spudec_changed(vo_spudec))
4209 vo_osd_changed(OSDTYPE_SPU);
4210 current_module=NULL;
4213 } // while(!eof)
4215 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
4219 goto_next_file: // don't jump here after ao/vo/getch initialization!
4221 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
4223 if(benchmark){
4224 double tot=video_time_usage+vout_time_usage+audio_time_usage;
4225 double total_time_usage;
4226 total_time_usage_start=GetTimer()-total_time_usage_start;
4227 total_time_usage = (float)total_time_usage_start*0.000001;
4228 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4229 video_time_usage,vout_time_usage,audio_time_usage,
4230 total_time_usage-tot,total_time_usage);
4231 if(total_time_usage>0.0)
4232 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4233 100.0*video_time_usage/total_time_usage,
4234 100.0*vout_time_usage/total_time_usage,
4235 100.0*audio_time_usage/total_time_usage,
4236 100.0*(total_time_usage-tot)/total_time_usage,
4237 100.0);
4238 if(total_frame_cnt && frame_dropping)
4239 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4240 total_frame_cnt-drop_frame_cnt,
4241 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
4242 drop_frame_cnt,
4243 100*drop_frame_cnt/total_frame_cnt,
4244 total_frame_cnt,
4245 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
4249 // time to uninit all, except global stuff:
4250 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
4252 #ifdef USE_SUB
4253 if ( set_of_sub_size > 0 )
4255 current_module="sub_free";
4256 for (i = 0; i < set_of_sub_size; ++i)
4257 sub_free( set_of_subtitles[i] );
4258 set_of_sub_size = 0;
4259 vo_sub_last = vo_sub=NULL;
4260 subdata=NULL;
4262 #endif
4264 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
4265 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
4266 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
4267 eof = 1;
4268 } else {
4269 play_tree_iter_free(playtree_iter);
4270 playtree_iter = NULL;
4272 play_tree_step = 1;
4273 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
4274 eof = eof == PT_UP_NEXT ? 1 : -1;
4275 if ( playtree_iter ) {
4276 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
4277 eof = 1;
4278 } else {
4279 play_tree_iter_free(playtree_iter);
4280 playtree_iter = NULL;
4283 } else { // NEXT PREV SRC
4284 eof = eof == PT_PREV_SRC ? -1 : 1;
4287 if(eof == 0) eof = 1;
4289 while(playtree_iter != NULL) {
4290 filename = play_tree_iter_get_file(playtree_iter,eof);
4291 if(filename == NULL) {
4292 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
4293 play_tree_iter_free(playtree_iter);
4294 playtree_iter = NULL;
4296 } else
4297 break;
4300 #ifdef HAVE_NEW_GUI
4301 if( use_gui && !playtree_iter )
4303 #ifdef USE_DVDREAD
4304 if ( !guiIntfStruct.DiskChanged )
4305 #endif
4306 mplEnd();
4308 #endif
4310 if(use_gui || playtree_iter != NULL){
4312 eof = 0;
4313 goto play_next_file;
4317 exit_player_with_rc(MSGTR_Exit_eof, 0);
4319 return 1;