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