avi subtitle stream dumper
[mplayer/greg.git] / mplayer.c
blob5e19a12515b58c19cdad7ec39f68c5a8baee6b6f
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "config.h"
5 #ifdef WIN32
6 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
7 #include <windows.h>
8 #endif
9 #include <string.h>
10 #include <unistd.h>
12 // #include <sys/mman.h>
13 #include <sys/types.h>
14 #ifndef __MINGW32__
15 #include <sys/ioctl.h>
16 #include <sys/wait.h>
17 #else
18 #define SIGHUP 1 /* hangup */
19 #define SIGQUIT 3 /* quit */
20 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
21 #define SIGBUS 10 /* bus error */
22 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
23 #endif
25 #include <sys/time.h>
26 #include <sys/stat.h>
28 #include <signal.h>
29 #include <time.h>
30 #include <fcntl.h>
31 #include <limits.h>
33 #include <errno.h>
35 #include "version.h"
37 #include "mp_msg.h"
39 #define HELP_MP_DEFINE_STATIC
40 #include "help_mp.h"
42 #include "m_option.h"
43 #include "m_config.h"
45 #include "cfg-mplayer-def.h"
47 #ifdef USE_SUB
48 #include "subreader.h"
49 #endif
51 #include "libvo/video_out.h"
53 #include "libvo/font_load.h"
54 #include "libvo/sub.h"
56 #ifdef HAVE_X11
57 #include "libvo/x11_common.h"
58 #endif
60 #include "libao2/audio_out.h"
62 #include "codec-cfg.h"
64 #ifdef USE_DVDNAV
65 #include <dvdnav.h>
66 #endif
68 #ifdef USE_EDL
69 #include "edl.h"
70 #endif
72 #include "spudec.h"
73 #include "vobsub.h"
75 #include "osdep/getch2.h"
76 #include "osdep/timer.h"
78 #include "cpudetect.h"
80 #ifdef HAVE_NEW_GUI
81 #include "Gui/interface.h"
82 #endif
84 #include "input/input.h"
86 int slave_mode=0;
87 int verbose=0;
88 int identify=0;
89 int quiet=0;
91 #ifdef WIN32
92 char * proc_priority=NULL;
93 #endif
95 #define ABS(x) (((x)>=0)?(x):(-(x)))
96 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
98 #ifdef HAVE_RTC
99 #ifdef __linux__
100 #include <linux/rtc.h>
101 #else
102 #include <rtc.h>
103 #define RTC_IRQP_SET RTCIO_IRQP_SET
104 #define RTC_PIE_ON RTCIO_PIE_ON
105 #endif
106 #endif
108 #ifdef USE_TV
109 #include "libmpdemux/tv.h"
110 #endif
112 #ifdef HAS_DVBIN_SUPPORT
113 #include "libmpdemux/dvbin.h"
114 static int last_dvb_step = 1;
115 #endif
117 //**************************************************************************//
118 // Playtree
119 //**************************************************************************//
120 #include "playtree.h"
121 #include "playtreeparser.h"
123 #ifdef HAVE_NEW_GUI
124 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
125 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
126 #endif
128 play_tree_t* playtree;
129 play_tree_iter_t* playtree_iter = NULL;
131 #define PT_NEXT_ENTRY 1
132 #define PT_PREV_ENTRY -1
133 #define PT_NEXT_SRC 2
134 #define PT_PREV_SRC -2
135 #define PT_UP_NEXT 3
136 #define PT_UP_PREV -3
138 //**************************************************************************//
139 // Config
140 //**************************************************************************//
141 m_config_t* mconfig;
143 extern play_tree_t*
144 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
145 extern int
146 m_config_parse_config_file(m_config_t* config, char *conffile);
148 //**************************************************************************//
149 // Config file
150 //**************************************************************************//
152 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
154 static int cfg_include(m_option_t *conf, char *filename){
155 return m_config_parse_config_file(mconfig, filename);
158 #include "get_path.c"
160 //**************************************************************************//
161 // XScreensaver
162 //**************************************************************************//
164 #ifdef HAVE_X11
165 void xscreensaver_heartbeat(void);
166 #endif
168 //**************************************************************************//
169 //**************************************************************************//
170 // Input media streaming & demultiplexer:
171 //**************************************************************************//
173 static int max_framesize=0;
175 #include "libmpdemux/stream.h"
176 #include "libmpdemux/demuxer.h"
177 #include "libmpdemux/stheader.h"
178 //#include "parse_es.h"
179 #ifdef HAVE_MATROSKA
180 #include "libmpdemux/matroska.h"
181 #endif
183 #include "libmpcodecs/dec_audio.h"
184 #include "libmpcodecs/dec_video.h"
185 #include "libmpcodecs/mp_image.h"
186 #include "libmpcodecs/vf.h"
188 extern void vf_list_plugins();
190 //**************************************************************************//
191 //**************************************************************************//
193 // Common FIFO functions, and keyboard/event FIFO code
194 #include "fifo.c"
195 int noconsolecontrols=0;
196 //**************************************************************************//
198 vo_functions_t *video_out=NULL;
199 ao_functions_t *audio_out=NULL;
201 int fixed_vo=0;
202 int eof=0;
204 // benchmark:
205 double video_time_usage=0;
206 double vout_time_usage=0;
207 static double audio_time_usage=0;
208 static int total_time_usage_start=0;
209 static int total_frame_cnt=0;
210 static int drop_frame_cnt=0; // total number of dropped frames
211 int benchmark=0;
213 // options:
214 int auto_quality=0;
215 static int output_quality=0;
217 float playback_speed=1.0;
219 int use_gui=0;
221 #ifdef HAVE_NEW_GUI
222 int enqueue=0;
223 #endif
225 #define MAX_OSD_LEVEL 3
227 int osd_level=1;
228 int osd_level_saved=-1;
229 int osd_visible=100;
231 // seek:
232 static char *seek_to_sec=NULL;
233 static off_t seek_to_byte=0;
234 static off_t step_sec=0;
235 static int loop_times=-1;
236 static int loop_seek=0;
238 // A/V sync:
239 int autosync=0; // 30 might be a good default value.
241 // may be changed by GUI: (FIXME!)
242 float rel_seek_secs=0;
243 int abs_seek_pos=0;
245 // codecs:
246 char **audio_codec_list=NULL; // override audio codec
247 char **video_codec_list=NULL; // override video codec
248 char **audio_fm_list=NULL; // override audio codec family
249 char **video_fm_list=NULL; // override video codec family
251 // streaming:
252 int audio_id=-1;
253 int video_id=-1;
254 int dvdsub_id=-1;
255 int vobsub_id=-1;
256 char* audio_lang=NULL;
257 char* dvdsub_lang=NULL;
258 static char* spudec_ifo=NULL;
259 char* filename=NULL; //"MI2-Trailer.avi";
260 int forced_subs_only=0;
262 // cache2:
263 int stream_cache_size=-1;
264 #ifdef USE_STREAM_CACHE
265 extern int cache_fill_status;
267 float stream_cache_min_percent=20.0;
268 float stream_cache_prefill_percent=5.0;
269 #else
270 #define cache_fill_status 0
271 #endif
273 // dump:
274 static char *stream_dump_name="stream.dump";
275 int stream_dump_type=0;
277 // A-V sync:
278 static float default_max_pts_correction=-1;//0.01f;
279 static float max_pts_correction=0;//default_max_pts_correction;
280 static float c_total=0;
281 float audio_delay=0;
283 static int softsleep=0;
285 float force_fps=0;
286 static int force_srate=0;
287 static int audio_output_format=0;
288 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
289 static int play_n_frames=-1;
290 static int play_n_frames_mf=-1;
292 // screen info:
293 char** video_driver_list=NULL;
294 char** audio_driver_list=NULL;
296 extern char *vo_subdevice;
297 extern char *ao_subdevice;
299 // codec outfmt flags (defined in libmpcodecs/vd.c)
300 extern int vo_flags;
302 // sub:
303 char *font_name=NULL;
304 #ifdef HAVE_FONTCONFIG
305 extern int font_fontconfig;
306 #endif
307 float font_factor=0.75;
308 char **sub_name=NULL;
309 float sub_delay=0;
310 float sub_fps=0;
311 int sub_auto = 1;
312 char *vobsub_name=NULL;
313 /*DSP!!char *dsp=NULL;*/
314 int subcc_enabled=0;
315 int suboverlap_enabled = 1;
316 #ifdef USE_SUB
317 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
318 int set_of_sub_size = 0;
319 int set_of_sub_pos = -1;
320 float sub_last_pts = -303;
321 #endif
322 int global_sub_size = 0; // this encompasses all subtitle sources
323 int global_sub_pos = -1; // this encompasses all subtitle sources
324 #define SUB_SOURCE_SUBS 0
325 #define SUB_SOURCE_VOBSUB 1
326 #define SUB_SOURCE_DEMUX 2
327 #define SUB_SOURCES 3
328 int global_sub_indices[SUB_SOURCES];
329 int global_sub_quiet_osd_hack = 0;
331 static stream_t* stream=NULL;
332 static demuxer_t *demuxer=NULL;
333 static sh_audio_t *sh_audio=NULL;
334 static sh_video_t *sh_video=NULL;
336 char* current_module=NULL; // for debugging
338 extern int vo_gamma_gamma;
339 extern int vo_gamma_brightness;
340 extern int vo_gamma_contrast;
341 extern int vo_gamma_saturation;
342 extern int vo_gamma_hue;
344 // ---
346 #ifdef HAVE_MENU
347 #include "m_struct.h"
348 #include "libmenu/menu.h"
349 extern void vf_menu_pause_update(struct vf_instance_s* vf);
350 extern vf_info_t vf_info_menu;
351 static vf_info_t* libmenu_vfs[] = {
352 &vf_info_menu,
353 NULL
355 static vf_instance_t* vf_menu = NULL;
356 static int use_menu = 0;
357 static char* menu_cfg = NULL;
358 static char* menu_root = "main";
359 #endif
362 #ifdef HAVE_RTC
363 static int nortc;
364 static char* rtc_device;
365 #endif
367 #ifdef USE_EDL
368 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
369 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
370 short user_muted = 0; ///< Stores whether User wanted muted mode.
371 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
372 short edl_decision = 0; ///< 1 when an EDL operation has been made
373 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode
374 #endif
376 static unsigned int inited_flags=0;
377 #define INITED_VO 1
378 #define INITED_AO 2
379 #define INITED_GUI 4
380 #define INITED_GETCH2 8
381 #define INITED_SPUDEC 32
382 #define INITED_STREAM 64
383 #define INITED_INPUT 128
384 #define INITED_VOBSUB 256
385 #define INITED_DEMUXER 512
386 #define INITED_ACODEC 1024
387 #define INITED_VCODEC 2048
388 #define INITED_ALL 0xFFFF
390 static void uninit_player(unsigned int mask){
391 mask=inited_flags&mask;
393 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
395 if(mask&INITED_ACODEC){
396 inited_flags&=~INITED_ACODEC;
397 current_module="uninit_acodec";
398 if(sh_audio) uninit_audio(sh_audio);
399 #ifdef HAVE_NEW_GUI
400 guiGetEvent(guiSetAfilter, (char *)NULL);
401 #endif
402 sh_audio=NULL;
405 if(mask&INITED_VCODEC){
406 inited_flags&=~INITED_VCODEC;
407 current_module="uninit_vcodec";
408 if(sh_video) uninit_video(sh_video);
409 sh_video=NULL;
410 #ifdef HAVE_MENU
411 vf_menu=NULL;
412 #endif
415 if(mask&INITED_DEMUXER){
416 inited_flags&=~INITED_DEMUXER;
417 current_module="free_demuxer";
418 if(demuxer){
419 stream=demuxer->stream;
420 free_demuxer(demuxer);
422 demuxer=NULL;
425 // kill the cache process:
426 if(mask&INITED_STREAM){
427 inited_flags&=~INITED_STREAM;
428 current_module="uninit_stream";
429 if(stream) free_stream(stream);
430 stream=NULL;
433 if(mask&INITED_VO){
434 inited_flags&=~INITED_VO;
435 current_module="uninit_vo";
436 video_out->uninit();
437 video_out=NULL;
440 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
441 if(mask&INITED_GETCH2){
442 inited_flags&=~INITED_GETCH2;
443 current_module="uninit_getch2";
444 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
445 // restore terminal:
446 getch2_disable();
449 if(mask&INITED_VOBSUB){
450 inited_flags&=~INITED_VOBSUB;
451 current_module="uninit_vobsub";
452 if(vo_vobsub) vobsub_close(vo_vobsub);
453 vo_vobsub=NULL;
456 if (mask&INITED_SPUDEC){
457 inited_flags&=~INITED_SPUDEC;
458 current_module="uninit_spudec";
459 spudec_free(vo_spudec);
460 vo_spudec=NULL;
463 if(mask&INITED_AO){
464 inited_flags&=~INITED_AO;
465 current_module="uninit_ao";
466 audio_out->uninit(eof?0:1); audio_out=NULL;
469 #ifdef HAVE_NEW_GUI
470 if(mask&INITED_GUI){
471 inited_flags&=~INITED_GUI;
472 current_module="uninit_gui";
473 guiDone();
475 #endif
477 if(mask&INITED_INPUT){
478 inited_flags&=~INITED_INPUT;
479 current_module="uninit_input";
480 mp_input_uninit();
483 current_module=NULL;
486 static void exit_player_with_rc(char* how, int rc){
488 uninit_player(INITED_ALL);
489 #ifdef HAVE_X11
490 #ifdef HAVE_NEW_GUI
491 if ( !use_gui )
492 #endif
493 vo_uninit(); // close the X11 connection (if any opened)
494 #endif
496 #ifdef HAVE_FREETYPE
497 current_module="uninit_font";
498 if (vo_font) free_font_desc(vo_font);
499 vo_font = NULL;
500 done_freetype();
501 #endif
503 current_module="exit_player";
505 // free mplayer config
506 free(mconfig);
508 #ifdef USE_EDL
509 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
510 #endif
511 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));
512 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
514 exit(rc);
517 void exit_player(char* how){
518 exit_player_with_rc(how, 1);
521 #ifndef __MINGW32__
522 static void child_sighandler(int x){
523 pid_t pid;
524 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
526 #endif
528 #ifdef CRASH_DEBUG
529 static char *prog_path;
530 static int crash_debug = 0;
531 #endif
533 static void exit_sighandler(int x){
534 static int sig_count=0;
535 #ifdef CRASH_DEBUG
536 if (!crash_debug || x != SIGTRAP)
537 #endif
538 ++sig_count;
539 if(inited_flags==0 && sig_count>1) exit(1);
540 if(sig_count==5)
542 /* We're crashing bad and can't uninit cleanly :(
543 * by popular request, we make one last (dirty)
544 * effort to restore the user's
545 * terminal. */
546 getch2_disable();
547 exit(1);
549 if(sig_count==6) exit(1);
550 if(sig_count>6){
551 // can't stop :(
552 #ifndef __MINGW32__
553 kill(getpid(),SIGKILL);
554 #endif
556 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
557 current_module?current_module:mp_gettext("unknown")
559 if(sig_count<=1)
560 switch(x){
561 case SIGINT:
562 case SIGQUIT:
563 case SIGTERM:
564 case SIGKILL:
565 break; // killed from keyboard (^C) or killed [-9]
566 case SIGILL:
567 #ifdef RUNTIME_CPUDETECT
568 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
569 #else
570 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
571 #endif
572 case SIGFPE:
573 case SIGSEGV:
574 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
575 default:
576 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
577 #ifdef CRASH_DEBUG
578 if (crash_debug) {
579 int gdb_pid;
580 char spid[20];
581 snprintf(spid, 19, "%i", getpid());
582 spid[19] = 0;
583 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
584 gdb_pid = fork();
585 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
586 if (gdb_pid == 0) { // We are the child
587 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
588 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
589 } else if (gdb_pid < 0)
590 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
591 else {
592 waitpid(gdb_pid, NULL, 0);
594 if (x == SIGTRAP) return;
596 #endif
598 exit_player(NULL);
601 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
603 extern void mp_input_register_options(m_config_t* cfg);
605 #include "mixer.h"
606 mixer_t mixer;
607 /// step size of mixer changes
608 int volstep = 3;
610 #include "cfg-mplayer.h"
612 void parse_cfgfiles( m_config_t* conf )
614 char *conffile;
615 int conffile_fd;
616 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
617 exit_player(NULL);
618 if ((conffile = get_path("")) == NULL) {
619 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
620 } else {
621 #ifdef __MINGW32__
622 mkdir(conffile);
623 #else
624 mkdir(conffile, 0777);
625 #endif
626 free(conffile);
627 if ((conffile = get_path("config")) == NULL) {
628 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
629 } else {
630 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
631 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
632 write(conffile_fd, default_config, strlen(default_config));
633 close(conffile_fd);
635 if (m_config_parse_config_file(conf, conffile) < 0)
636 exit_player(NULL);
637 free(conffile);
642 void load_per_file_config (m_config_t* conf, const char *const file)
644 char *confpath;
645 char cfg[strlen(file)+10];
646 struct stat st;
647 char *name;
649 sprintf (cfg, "%s.conf", file);
651 if (!stat (cfg, &st))
653 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
654 m_config_parse_config_file (conf, cfg);
655 return;
658 if ((name = strrchr (cfg, '/')) == NULL)
659 name = cfg;
660 else
661 name++;
663 if ((confpath = get_path (name)) != NULL)
665 if (!stat (confpath, &st))
667 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
668 m_config_parse_config_file (conf, confpath);
671 free (confpath);
675 // When libmpdemux perform a blocking operation (network connection or cache filling)
676 // if the operation fail we use this function to check if it was interrupted by the user.
677 // The function return a new value for eof.
678 static int libmpdemux_was_interrupted(int eof) {
679 mp_cmd_t* cmd;
680 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
681 switch(cmd->id) {
682 case MP_CMD_QUIT:
683 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
684 case MP_CMD_PLAY_TREE_STEP: {
685 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
686 } break;
687 case MP_CMD_PLAY_TREE_UP_STEP: {
688 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
689 } break;
690 case MP_CMD_PLAY_ALT_SRC_STEP: {
691 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
692 } break;
694 mp_cmd_free(cmd);
696 return eof;
699 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
700 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
702 int playtree_add_playlist(play_tree_t* entry)
704 play_tree_add_bpf(entry,filename);
706 #ifdef HAVE_NEW_GUI
707 if (use_gui) {
708 if (entry) {
709 import_playtree_playlist_into_gui(entry, mconfig);
710 play_tree_free_list(entry,1);
712 } else
713 #endif
715 if(!entry) {
716 entry = playtree_iter->tree;
717 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
718 return PT_NEXT_ENTRY;
720 if(playtree_iter->tree == entry ) { // Loop with a single file
721 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
722 return PT_NEXT_ENTRY;
725 play_tree_remove(entry,1,1);
726 return PT_NEXT_SRC;
728 play_tree_insert_entry(playtree_iter->tree,entry);
729 play_tree_set_params_from(entry,playtree_iter->tree);
730 entry = playtree_iter->tree;
731 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
732 return PT_NEXT_ENTRY;
734 play_tree_remove(entry,1,1);
736 return PT_NEXT_SRC;
739 static int play_tree_step = 1;
741 int sub_source()
743 int source = -1;
744 int top = -1;
745 int i;
746 for (i = 0; i < SUB_SOURCES; i++) {
747 int j = global_sub_indices[i];
748 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
749 source = i;
750 top = j;
753 return source;
756 #ifdef USE_SUB
758 sub_data* subdata = NULL;
759 static subtitle* vo_sub_last = NULL;
761 void add_subtitles(char *filename, float fps, int silent)
763 sub_data *subd;
765 if (filename == NULL) {
766 return;
769 subd = sub_read_file(filename, fps);
770 if(!subd && !silent)
771 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
772 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
773 set_of_subtitles[set_of_sub_size] = subd;
774 if (identify)
776 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
777 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
779 ++set_of_sub_size;
780 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
783 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
784 void update_set_of_subtitles()
785 // subdata was changed, set_of_sub... have to be updated.
787 int i;
788 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
789 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
790 set_of_subtitles[i-1] = set_of_subtitles[i];
791 set_of_subtitles[set_of_sub_size-1] = NULL;
792 --set_of_sub_size;
793 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
795 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
796 set_of_subtitles[set_of_sub_pos] = subdata;
798 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
799 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
800 ++set_of_sub_size;
803 #endif
806 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
807 * make it all work is to use the builtin SDL-bootstrap code, which
808 * will be done automatically by replacing our main() if we include SDL.h.
810 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
811 #include <SDL.h>
812 #endif
815 * \brief append a formatted string
816 * \param buf buffer to print into
817 * \param pos position of terminating 0 in buf
818 * \param len maximum number of characters in buf, not including terminating 0
819 * \param format printf format string
821 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
823 va_list va;
824 va_start(va, format);
825 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
826 va_end(va);
827 if (*pos >= len ) {
828 buf[len] = 0;
829 *pos = len;
834 * \brief print the status line
835 * \param a_pos audio position
836 * \param a_v A-V desynchronization
837 * \param corr amount out A-V synchronization
839 static void print_status(float a_pos, float a_v, float corr)
841 int width;
842 char *line;
843 unsigned pos = 0;
844 get_screen_size();
845 if (screen_width > 0)
846 width = screen_width;
847 else
848 width = 80;
849 #ifdef WIN32
850 // windows command line is broken (MinGW's rxvt works though, but we
851 // should not depend on that).
852 width--;
853 #endif
854 line = malloc(width + 1); // one additional for terminating null
856 // Audio time
857 if (sh_audio) {
858 saddf(line, &pos, width, "A:%6.1f ", a_pos);
859 if (!sh_video) {
860 // convert time to HH:MM:SS.F format
861 long tenths = 10 * a_pos;
862 int f1 = tenths % 10;
863 int ss = (tenths / 10) % 60;
864 int mm = (tenths / 600) % 60;
865 int hh = (tenths / 36000) % 100;
866 saddf(line, &pos, width, "(");
867 if (hh > 0)
868 saddf(line, &pos, width, "%2d:", hh);
869 if (hh > 0 || mm > 0)
870 saddf(line, &pos, width, "%02d:", mm);
871 saddf(line, &pos, width, "%02d.", ss);
872 saddf(line, &pos, width, "%1d", f1);
873 saddf(line, &pos, width, ") ");
877 // Video time
878 if (sh_video)
879 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
881 // A-V sync
882 if (sh_audio && sh_video)
883 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
885 // Video stats
886 if (sh_video)
887 saddf(line, &pos, width, "%3d/%3d ",
888 (int)sh_video->num_frames,
889 (int)sh_video->num_frames_decoded);
891 // CPU usage
892 if (sh_video) {
893 if (sh_video->timer > 0.5)
894 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
895 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
896 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
897 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
898 else
899 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
900 } else if (sh_audio) {
901 if (sh_audio->delay > 0.5)
902 saddf(line, &pos, width, "%4.1f%% ",
903 100.0*audio_time_usage/(double)sh_audio->delay);
904 else
905 saddf(line, &pos, width, "??,?%% ");
908 // VO stats
909 if (sh_video)
910 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
912 #ifdef USE_STREAM_CACHE
913 // cache stats
914 if (stream_cache_size > 0)
915 saddf(line, &pos, width, "%d%% ", cache_fill_status);
916 #endif
918 // other
919 if (playback_speed != 1)
920 saddf(line, &pos, width, "%4.2fx ", playback_speed);
922 // end
923 memset(&line[pos], ' ', width - pos);
924 line[width] = 0;
925 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
926 free(line);
930 * \brief build a chain of audio filters that converts the input format
931 * to the ao's format, taking into account the current playback_speed.
932 * \param sh_audio describes the requested input format of the chain.
933 * \param ao_data describes the requested output format of the chain.
935 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
937 int new_srate;
938 int result;
939 if (!sh_audio)
941 #ifdef HAVE_NEW_GUI
942 guiGetEvent(guiSetAfilter, (char *)NULL);
943 #endif
944 mixer.afilter = NULL;
945 return 0;
947 new_srate = sh_audio->samplerate * playback_speed;
948 if (new_srate != ao_data->samplerate) {
949 // limits are taken from libaf/af_resample.c
950 if (new_srate < 8000)
951 new_srate = 8000;
952 if (new_srate > 192000)
953 new_srate = 192000;
954 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
956 result = init_audio_filters(sh_audio, new_srate,
957 sh_audio->channels, sh_audio->sample_format,
958 &ao_data->samplerate, &ao_data->channels, &ao_data->format,
959 ao_data->outburst * 4, ao_data->buffersize);
960 mixer.afilter = sh_audio->afilter;
961 #ifdef HAVE_NEW_GUI
962 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter);
963 #endif
964 return result;
967 #ifdef USE_SUB
969 * \brief Log the currently displayed subtitle to a file
971 * Logs the current or last displayed subtitle together with filename
972 * and time information to ~/.mplayer/subtitle_log
974 * Intended purpose is to allow convenient marking of bogus subtitles
975 * which need to be fixed while watching the movie.
978 static void log_sub(){
979 char *fname;
980 FILE *f;
981 int i;
983 if (subdata == NULL || vo_sub_last == NULL) return;
984 fname = get_path("subtitle_log");
985 f = fopen(fname, "a");
986 if (!f) return;
987 fprintf(f, "----------------------------------------------------------\n");
988 if (subdata->sub_uses_time) {
989 fprintf(f, "N: %s S: %02d:%02d:%02d.%02d E: %02d:%02d:%02d.%02d\n", filename,
990 vo_sub_last->start/360000, (vo_sub_last->start/6000)%60,
991 (vo_sub_last->start/100)%60, vo_sub_last->start%100,
992 vo_sub_last->end/360000, (vo_sub_last->end/6000)%60,
993 (vo_sub_last->end/100)%60, vo_sub_last->end%100);
994 } else {
995 fprintf(f, "N: %s S: %d E: %d\n", filename, vo_sub_last->start, vo_sub_last->end);
997 for (i = 0; i < vo_sub_last->lines; i++) {
998 fprintf(f, "%s\n", vo_sub_last->text[i]);
1000 fclose(f);
1002 #endif
1004 int main(int argc,char* argv[]){
1007 char * mem_ptr;
1009 static demux_stream_t *d_audio=NULL;
1010 static demux_stream_t *d_video=NULL;
1011 static demux_stream_t *d_dvdsub=NULL;
1013 int file_format=DEMUXER_TYPE_UNKNOWN;
1015 int delay_corrected=1;
1017 // movie info:
1019 int osd_function=OSD_PLAY;
1020 int osd_last_pts=-303;
1021 int osd_show_av_delay = 0;
1022 int osd_show_text = 0;
1023 int osd_show_speed = 0;
1024 int osd_show_sub_delay = 0;
1025 int osd_show_sub_pos = 0;
1026 int osd_show_sub_visibility = 0;
1027 int osd_show_sub_alignment = 0;
1028 int osd_show_vobsub_changed = 0;
1029 int osd_show_sub_changed = 0;
1030 int osd_show_percentage = 0;
1031 int osd_show_tv_channel = 25;
1032 int osd_show_ontop = 0;
1033 int osd_show_rootwin = 0;
1034 int osd_show_framedropping = 0;
1035 int osd_show_status = 0;
1037 int rtc_fd=-1;
1039 //float a_frame=0; // Audio
1041 int i;
1042 char *tmp;
1044 int gui_no_filename=0;
1047 srand((int) time(NULL));
1049 InitTimer();
1051 mp_msg_init();
1052 mp_msg_set_level(MSGL_STATUS);
1054 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2005 MPlayer Team\n");
1055 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
1056 GetCpuCaps(&gCpuCaps);
1057 #if defined(ARCH_X86) || defined(ARCH_X86_64)
1058 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
1059 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
1060 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
1061 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
1062 #ifdef RUNTIME_CPUDETECT
1063 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
1064 #else
1065 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
1066 #ifdef HAVE_MMX
1067 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
1068 #endif
1069 #ifdef HAVE_MMX2
1070 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
1071 #endif
1072 #ifdef HAVE_3DNOW
1073 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
1074 #endif
1075 #ifdef HAVE_3DNOWEX
1076 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
1077 #endif
1078 #ifdef HAVE_SSE
1079 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
1080 #endif
1081 #ifdef HAVE_SSE2
1082 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
1083 #endif
1084 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
1085 #endif
1086 #endif
1088 #if defined(WIN32) && defined(USE_WIN32DLL)
1089 { /*make our codec dirs available for LoadLibraryA()*/
1090 char tmppath[MAX_PATH*2 + 1];
1091 char win32path[MAX_PATH];
1092 char realpath[MAX_PATH];
1093 #ifdef __CYGWIN__
1094 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
1095 strcpy(tmppath,win32path);
1096 #ifdef USE_REALCODECS
1097 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
1098 sprintf(tmppath,"%s;%s",win32path,realpath);
1099 #endif /*USE_REALCODECS*/
1100 #else
1101 if(!strstr(WIN32_PATH,":")){
1102 GetModuleFileNameA(NULL, win32path, MAX_PATH);
1103 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
1105 else strcpy(win32path,WIN32_PATH);
1106 strcpy(tmppath,win32path);
1107 #ifdef USE_REALCODECS
1108 if(!strstr(REALCODEC_PATH,":")){
1109 GetModuleFileNameA(NULL, realpath, MAX_PATH);
1110 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
1112 else strcpy(realpath,REALCODEC_PATH);
1113 sprintf(tmppath,"%s;%s",win32path,realpath);
1114 #endif /*USE_REALCODECS*/
1115 #endif /*__CYGWIN__*/
1116 SetEnvironmentVariableA("PATH", tmppath);
1118 #endif /*WIN32 && USE_WIN32DLL*/
1120 #ifdef USE_TV
1121 tv_param_immediate = 1;
1122 #endif
1124 if ( argv[0] )
1125 if(!strcmp(argv[0],"gmplayer") ||
1126 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
1127 use_gui=1;
1129 mconfig = m_config_new();
1130 m_config_register_options(mconfig,mplayer_opts);
1131 // TODO : add something to let modules register their options
1132 mp_input_register_options(mconfig);
1133 parse_cfgfiles(mconfig);
1135 #ifdef HAVE_NEW_GUI
1136 if ( use_gui ) cfg_read();
1137 #endif
1139 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
1140 if(playtree == NULL)
1141 exit_player(NULL);
1143 playtree = play_tree_cleanup(playtree);
1144 if(playtree) {
1145 playtree_iter = play_tree_iter_new(playtree,mconfig);
1146 if(playtree_iter) {
1147 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
1148 play_tree_iter_free(playtree_iter);
1149 playtree_iter = NULL;
1151 filename = play_tree_iter_get_file(playtree_iter,1);
1155 #ifdef WIN32
1156 if(proc_priority){
1157 int i;
1158 for(i=0; priority_presets_defs[i].name; i++){
1159 if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
1160 break;
1162 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",
1163 priority_presets_defs[i].name);
1164 SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
1166 #endif
1167 #ifndef HAVE_NEW_GUI
1168 if(use_gui){
1169 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
1170 use_gui=0;
1172 #else
1173 if(use_gui && !vo_init()){
1174 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
1175 use_gui=0;
1177 if (use_gui && playtree_iter){
1178 char cwd[PATH_MAX+2];
1179 // Remove Playtree and Playtree-Iter from memory as its not used by gui
1180 play_tree_iter_free(playtree_iter);
1181 playtree_iter=NULL;
1183 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
1185 strcat(cwd, "/");
1186 // Prefix relative paths with current working directory
1187 play_tree_add_bpf(playtree, cwd);
1189 // Import initital playtree into gui
1190 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
1192 #endif
1194 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
1195 list_video_out();
1196 exit_player_with_rc(NULL, 0);
1199 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
1200 list_audio_out();
1201 exit_player_with_rc(NULL, 0);
1204 // check codec.conf
1205 if(!codecs_file || !parse_codec_cfg(codecs_file)){
1206 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
1207 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
1208 if(!parse_codec_cfg(NULL)){
1209 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
1210 exit_player_with_rc(NULL, 0);
1212 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
1215 free( mem_ptr ); // release the buffer created by get_path()
1218 #if 0
1219 if(video_codec_list){
1220 int i;
1221 video_codec=video_codec_list[0];
1222 for(i=0;video_codec_list[i];i++)
1223 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
1225 #endif
1226 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
1227 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
1228 if (identify)
1229 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_CODECS\n");
1230 list_codecs(1);
1231 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1232 exit_player_with_rc(NULL, 0);
1234 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
1235 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
1236 if (identify)
1237 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VIDEO_CODECS\n");
1238 list_codecs(0);
1239 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1240 exit_player_with_rc(NULL, 0);
1242 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
1243 vfm_help();
1244 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1245 exit_player_with_rc(NULL, 0);
1247 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
1248 afm_help();
1249 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1250 exit_player_with_rc(NULL, 0);
1252 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
1253 af_help();
1254 printf("\n");
1255 exit_player_with_rc(NULL, 0);
1257 #ifdef HAVE_X11
1258 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
1259 fstype_help();
1260 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1261 exit_player_with_rc(NULL, 0);
1263 #endif
1265 #ifdef USE_EDL
1266 if (edl_check_mode() == EDL_ERROR && edl_filename)
1268 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantUseBothModes);
1269 exit_player(NULL);
1270 } else if (edl_filename)
1272 if (edl_records) free_edl(edl_records);
1273 next_edl_record = edl_records = edl_parse_file();
1274 } else if (edl_output_filename)
1276 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
1278 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
1279 edl_output_filename);
1280 exit_player(NULL);
1283 #endif
1285 if(!filename){
1286 if(!use_gui){
1287 // no file/vcd/dvd -> show HELP:
1288 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1289 exit_player_with_rc(NULL, 0);
1290 } else gui_no_filename=1;
1293 // Many users forget to include command line in bugreports...
1294 if(verbose>0){
1295 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
1296 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);
1297 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
1300 mp_msg_set_level(verbose+MSGL_STATUS);
1302 //------ load global data first ------
1304 // check font
1305 #ifdef USE_OSD
1306 #ifdef HAVE_FREETYPE
1307 init_freetype();
1308 #endif
1309 #ifdef HAVE_FONTCONFIG
1310 if(!font_fontconfig)
1312 #endif
1313 if(font_name){
1314 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1315 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1316 } else {
1317 // try default:
1318 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
1319 free(mem_ptr); // release the buffer created by get_path()
1320 if(!vo_font)
1321 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1323 #ifdef HAVE_FONTCONFIG
1325 #endif
1326 #endif
1327 vo_init_osd();
1329 #ifdef HAVE_RTC
1330 if(!nortc)
1332 // seteuid(0); /* Can't hurt to try to get root here */
1333 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
1334 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
1335 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
1336 else {
1337 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1339 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1340 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
1341 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
1342 close (rtc_fd);
1343 rtc_fd = -1;
1344 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1345 /* variable only by the root */
1346 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
1347 close (rtc_fd);
1348 rtc_fd = -1;
1349 } else
1350 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
1353 #ifdef HAVE_NEW_GUI
1354 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1355 // and now ? -- Pontscho
1356 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1357 #endif
1358 if(rtc_fd<0)
1359 #endif
1360 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
1361 softsleep?"software":timer_name);
1363 #ifdef USE_TERMCAP
1364 if ( !use_gui ) load_termcap(NULL); // load key-codes
1365 #endif
1367 // ========== Init keyboard FIFO (connection to libvo) ============
1369 // Init input system
1370 current_module = "init_input";
1371 mp_input_init();
1372 #if 0
1373 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1375 if(keyb_fifo_get > 0)
1376 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1377 #else
1378 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1379 #endif
1380 if(slave_mode)
1381 #ifndef __MINGW32__
1382 mp_input_add_cmd_fd(0,1,NULL,NULL);
1383 #else
1384 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1385 #endif
1386 else if(!noconsolecontrols)
1387 #ifndef HAVE_NO_POSIX_SELECT
1388 mp_input_add_key_fd(0,1,NULL,NULL);
1389 #else
1390 mp_input_add_key_fd(0,0,NULL,NULL);
1391 #endif
1393 inited_flags|=INITED_INPUT;
1394 current_module = NULL;
1396 #ifdef HAVE_MENU
1397 if(use_menu) {
1398 if(menu_cfg && menu_init(menu_cfg))
1399 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1400 else {
1401 menu_cfg = get_path("menu.conf");
1402 if(menu_init(menu_cfg))
1403 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1404 else {
1405 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1406 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
1407 else {
1408 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
1409 use_menu = 0;
1414 #endif
1416 /// Catch signals
1417 #ifndef __MINGW32__
1418 signal(SIGCHLD,child_sighandler);
1419 #endif
1421 #ifdef CRASH_DEBUG
1422 prog_path = argv[0];
1423 #endif
1424 //========= Catch terminate signals: ================
1425 // terminate requests:
1426 signal(SIGTERM,exit_sighandler); // kill
1427 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1429 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1431 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1432 #ifdef ENABLE_SIGHANDLER
1433 // fatal errors:
1434 signal(SIGBUS,exit_sighandler); // bus error
1435 signal(SIGSEGV,exit_sighandler); // segfault
1436 signal(SIGILL,exit_sighandler); // illegal instruction
1437 signal(SIGFPE,exit_sighandler); // floating point exc.
1438 signal(SIGABRT,exit_sighandler); // abort()
1439 #ifdef CRASH_DEBUG
1440 if (crash_debug)
1441 signal(SIGTRAP,exit_sighandler);
1442 #endif
1443 #endif
1445 #ifdef HAVE_NEW_GUI
1446 if(use_gui){
1447 guiInit();
1448 inited_flags|=INITED_GUI;
1449 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1451 #endif
1453 // ******************* Now, let's see the per-file stuff ********************
1455 play_next_file:
1457 // init global sub numbers
1458 global_sub_size = 0;
1459 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
1460 global_sub_quiet_osd_hack = 1;
1462 if (filename) load_per_file_config (mconfig, filename);
1464 // We must enable getch2 here to be able to interrupt network connection
1465 // or cache filling
1466 if(!noconsolecontrols && !slave_mode){
1467 if(inited_flags&INITED_GETCH2)
1468 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
1469 else
1470 getch2_enable(); // prepare stdin for hotkeys...
1471 inited_flags|=INITED_GETCH2;
1472 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1475 // =================== GUI idle loop (STOP state) ===========================
1476 #ifdef HAVE_NEW_GUI
1477 if ( use_gui ) {
1478 file_format=DEMUXER_TYPE_UNKNOWN;
1479 guiGetEvent( guiSetDefaults,0 );
1480 while ( guiIntfStruct.Playing != 1 )
1482 mp_cmd_t* cmd;
1483 usec_sleep(20000);
1484 guiEventHandling();
1485 guiGetEvent( guiReDraw,NULL );
1486 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1488 guiGetEvent( guiSetParameters,NULL );
1489 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1491 play_tree_t * entry = play_tree_new();
1492 play_tree_add_file( entry,guiIntfStruct.Filename );
1493 if ( playtree ) play_tree_free_list( playtree->child,1 );
1494 else playtree=play_tree_new();
1495 play_tree_set_child( playtree,entry );
1496 if(playtree)
1498 playtree_iter = play_tree_iter_new(playtree,mconfig);
1499 if(playtree_iter)
1501 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1503 play_tree_iter_free(playtree_iter);
1504 playtree_iter = NULL;
1506 filename = play_tree_iter_get_file(playtree_iter,1);
1511 #endif
1512 //---------------------------------------------------------------------------
1514 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1516 //==================== Open VOB-Sub ============================
1518 current_module="vobsub";
1519 if (vobsub_name){
1520 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1521 if(vo_vobsub==NULL)
1522 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1523 }else if(sub_auto && filename && (strlen(filename)>=5)){
1524 /* try to autodetect vobsub from movie filename ::atmos */
1525 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1526 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1527 strncpy(buf, filename, strlen(filename)-4);
1528 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1529 free(buf);
1531 if(vo_vobsub){
1532 inited_flags|=INITED_VOBSUB;
1533 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1534 // check if vobsub requested only to display forced subtitles
1535 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1537 // setup global sub numbering
1538 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
1539 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
1542 //============ Open & Sync STREAM --- fork cache2 ====================
1544 stream=NULL;
1545 demuxer=NULL;
1546 if (d_audio) {
1547 //free_demuxer_stream(d_audio);
1548 d_audio=NULL;
1550 if (d_video) {
1551 //free_demuxer_stream(d_video);
1552 d_video=NULL;
1554 sh_audio=NULL;
1555 sh_video=NULL;
1557 current_module="open_stream";
1558 stream=open_stream(filename,0,&file_format);
1559 if(!stream) { // error...
1560 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1561 goto goto_next_file;
1563 inited_flags|=INITED_STREAM;
1565 #ifdef HAVE_NEW_GUI
1566 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1567 #endif
1569 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1570 play_tree_t* entry;
1571 // Handle playlist
1572 current_module="handle_playlist";
1573 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1574 entry = parse_playtree(stream,0);
1575 eof=playtree_add_playlist(entry);
1576 goto goto_next_file;
1578 stream->start_pos+=seek_to_byte;
1580 if(stream_dump_type==5){
1581 unsigned char buf[4096];
1582 int len;
1583 FILE *f;
1584 current_module="dumpstream";
1585 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1586 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
1587 exit_player(MSGTR_Exit_error);
1589 stream_reset(stream);
1590 stream_seek(stream,stream->start_pos);
1591 f=fopen(stream_dump_name,"wb");
1592 if(!f){
1593 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1594 exit_player(MSGTR_Exit_error);
1596 while(!stream->eof){
1597 len=stream_read(stream,buf,4096);
1598 if(len>0) {
1599 if(fwrite(buf,len,1,f) != 1) {
1600 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1601 exit_player(MSGTR_Exit_error);
1605 if(fclose(f)) {
1606 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1607 exit_player(MSGTR_Exit_error);
1609 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1610 exit_player_with_rc(MSGTR_Exit_eof, 0);
1613 #ifdef USE_DVDREAD
1614 if(stream->type==STREAMTYPE_DVD){
1615 current_module="dvd lang->id";
1616 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1617 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1618 // setup global sub numbering
1619 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1620 global_sub_size += dvd_number_of_subs(stream);
1621 current_module=NULL;
1623 #endif
1625 #ifdef USE_DVDNAV
1626 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1627 #endif
1629 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1630 #ifdef HAS_DVBIN_SUPPORT
1631 goto_enable_cache:
1632 #endif
1633 if(stream_cache_size>0){
1634 current_module="enable_cache";
1635 if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024*(stream_cache_min_percent / 100.0),stream_cache_size*1024*(stream_cache_prefill_percent / 100.0)))
1636 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1639 //============ Open DEMUXERS --- DETECT file type =======================
1640 current_module="demux_open";
1642 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1644 // HACK to get MOV Reference Files working
1646 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1648 unsigned char* playlist_entry;
1649 play_tree_t *list = NULL, *entry = NULL;
1651 current_module="handle_demux_playlist";
1652 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1654 char *temp, *bname;
1656 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
1658 bname=mp_basename(playlist_entry);
1659 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1660 continue;
1662 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1663 continue;
1665 entry = play_tree_new();
1667 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1669 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1670 if (temp)
1672 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1673 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1674 strcat(temp, playlist_entry);
1675 play_tree_add_file(entry,temp);
1676 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
1677 free(temp);
1680 else
1681 play_tree_add_file(entry,playlist_entry);
1683 if(!list)
1684 list = entry;
1685 else
1686 play_tree_append_entry(list,entry);
1688 free_demuxer(demuxer);
1689 demuxer = NULL;
1691 if (list)
1693 entry = play_tree_new();
1694 play_tree_set_child(entry,list);
1695 eof=playtree_add_playlist(entry);
1696 goto goto_next_file;
1700 if(!demuxer)
1702 #if 0
1703 play_tree_t* entry;
1704 // Handle playlist
1705 current_module="handle_playlist";
1706 switch(stream->type){
1707 case STREAMTYPE_VCD:
1708 case STREAMTYPE_DVD:
1709 case STREAMTYPE_DVDNAV:
1710 case STREAMTYPE_CDDA:
1711 case STREAMTYPE_VCDBINCUE:
1712 // don't try to parse raw media as playlist, it's unlikely
1713 goto goto_next_file;
1715 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
1716 stream_reset(stream);
1717 stream_seek(stream,stream->start_pos);
1718 entry = parse_playtree(stream,0);
1719 if(!entry)
1720 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1721 else
1722 eof=playtree_add_playlist(entry);
1723 #endif
1724 goto goto_next_file;
1726 inited_flags|=INITED_DEMUXER;
1728 #ifdef HAVE_MATROSKA
1729 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
1730 // setup global sub numbering
1731 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1732 global_sub_size += demux_mkv_num_subs(demuxer);
1734 #endif
1735 #ifdef HAVE_OGGVORBIS
1736 if (demuxer->type==DEMUXER_TYPE_OGG) {
1737 // setup global sub numbering
1738 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1739 global_sub_size += demux_ogg_num_subs(demuxer);
1741 #endif
1743 current_module="demux_open2";
1745 //file_format=demuxer->file_format;
1747 d_audio=demuxer->audio;
1748 d_video=demuxer->video;
1749 d_dvdsub=demuxer->sub;
1751 // DUMP STREAMS:
1752 if((stream_dump_type)&&(stream_dump_type<4)){
1753 FILE *f;
1754 demux_stream_t *ds=NULL;
1755 current_module="dump";
1756 // select stream to dump
1757 switch(stream_dump_type){
1758 case 1: ds=d_audio;break;
1759 case 2: ds=d_video;break;
1760 case 3: ds=d_dvdsub;break;
1762 if(!ds){
1763 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1764 exit_player(MSGTR_Exit_error);
1766 // disable other streams:
1767 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1768 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1769 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1770 // let's dump it!
1771 f=fopen(stream_dump_name,"wb");
1772 if(!f){
1773 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1774 exit_player(MSGTR_Exit_error);
1776 while(!ds->eof){
1777 unsigned char* start;
1778 int in_size=ds_get_packet(ds,&start);
1779 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1780 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1781 if(in_size>0) fwrite(start,in_size,1,f);
1783 fclose(f);
1784 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1785 exit_player_with_rc(MSGTR_Exit_eof, 0);
1788 sh_audio=d_audio->sh;
1789 sh_video=d_video->sh;
1791 if(sh_video){
1793 current_module="video_read_properties";
1794 if(!video_read_properties(sh_video)) {
1795 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1796 sh_video=d_video->sh=NULL;
1797 } else {
1798 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1799 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1800 sh_video->fps,sh_video->frametime
1803 /* need to set fps here for output encoders to pick it up in their init */
1804 if(force_fps){
1805 sh_video->fps=force_fps;
1806 sh_video->frametime=1.0f/sh_video->fps;
1808 vo_fps = sh_video->fps;
1809 #ifdef HAVE_X11
1810 vo_mouse_timer_const=(int)sh_video->fps;
1811 #endif
1813 if(!sh_video->fps && !force_fps){
1814 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1815 sh_video=d_video->sh=NULL;
1821 fflush(stdout);
1823 if(!sh_video && !sh_audio){
1824 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1825 #ifdef HAS_DVBIN_SUPPORT
1826 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1828 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1829 if(priv->is_on)
1831 int dir;
1832 int v = last_dvb_step;
1833 if(v > 0)
1834 dir = DVB_CHANNEL_HIGHER;
1835 else
1836 dir = DVB_CHANNEL_LOWER;
1838 if(dvb_step_channel(priv, dir))
1840 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1841 cache_uninit(stream);
1842 goto goto_enable_cache;
1846 #endif
1847 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1850 /* display clip info */
1851 demux_info_print(demuxer);
1853 //================== Read SUBTITLES (DVD & TEXT) ==========================
1854 if(vo_spudec==NULL && sh_video &&
1855 (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA ||
1856 d_dvdsub->id >= 0)){
1858 if (spudec_ifo) {
1859 unsigned int palette[16], width, height;
1860 current_module="spudec_init_vobsub";
1861 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1862 vo_spudec=spudec_new_scaled(palette, width, height);
1865 #ifdef USE_DVDNAV
1866 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1867 current_module="spudec_init_dvdnav";
1868 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1869 sh_video->disp_w, sh_video->disp_h);
1871 #endif
1873 #ifdef USE_DVDREAD
1874 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1875 current_module="spudec_init_dvdread";
1876 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1877 sh_video->disp_w, sh_video->disp_h);
1879 #endif
1881 #ifdef HAVE_MATROSKA
1882 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1883 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1884 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
1885 current_module = "spudec_init_matroska";
1886 vo_spudec =
1887 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1888 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1889 mkv_sh_sub->height);
1890 forced_subs_only = mkv_sh_sub->forced_subs_only;
1892 #endif
1894 if (vo_spudec==NULL) {
1895 current_module="spudec_init_normal";
1896 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1897 spudec_set_font_factor(vo_spudec,font_factor);
1900 if (vo_spudec!=NULL)
1901 inited_flags|=INITED_SPUDEC;
1905 // Apply current settings for forced subs
1906 if (vo_spudec!=NULL)
1907 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1909 #ifdef USE_SUB
1910 if(sh_video) {
1911 // after reading video params we should load subtitles because
1912 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1913 // check .sub
1914 current_module="read_subtitles_file";
1915 if(sub_name){
1916 for (i = 0; sub_name[i] != NULL; ++i)
1917 add_subtitles (sub_name[i], sh_video->fps, 0);
1919 if(sub_auto) { // auto load sub file ...
1920 char *psub = get_path( "sub/" );
1921 char **tmp = sub_filenames((psub ? psub : ""), filename);
1922 int i = 0;
1923 free(psub); // release the buffer created by get_path() above
1924 while (tmp[i]) {
1925 add_subtitles (tmp[i], sh_video->fps, 0);
1926 free(tmp[i++]);
1928 free(tmp);
1929 if (set_of_sub_size == 0)
1931 add_subtitles (mem_ptr=get_path("default.sub"), sh_video->fps, 1);
1932 free(mem_ptr); // release the buffer created by get_path()
1935 if (set_of_sub_size > 0) {
1936 // setup global sub numbering
1937 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
1938 global_sub_size += set_of_sub_size;
1941 #endif
1943 if (global_sub_size) {
1944 // find the best sub to use
1945 if (vobsub_id >= 0) {
1946 // if user asks for a vobsub id, use that first.
1947 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
1948 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1949 // if user asks for a dvd sub id, use that next.
1950 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
1951 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
1952 // if there are text subs to use, use those. (autosubs come last here)
1953 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
1955 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1956 // if nothing else works, get subs from the demuxer.
1957 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1959 } else {
1960 // nothing worth doing automatically.
1961 global_sub_pos = -1;
1963 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1964 global_sub_pos--;
1965 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1968 //================== Init AUDIO (codec) ==========================
1969 if(sh_audio){
1970 // Go through the codec.conf and find the best codec...
1971 current_module="init_audio_codec";
1972 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1973 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1974 sh_audio=d_audio->sh=NULL; // failed to init :(
1975 } else
1976 inited_flags|=INITED_ACODEC;
1977 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1980 if(identify) {
1981 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
1982 if (sh_video) {
1983 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1984 if (sh_video->format >= 0x20202020)
1985 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
1986 else
1987 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
1988 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
1989 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
1990 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
1991 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
1992 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
1994 if (sh_audio) {
1995 if (sh_audio->codec)
1996 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
1997 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1998 if (sh_audio->format >= 0x20202020)
1999 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
2000 else
2001 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
2002 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
2003 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
2004 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
2006 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
2009 if(!sh_video) goto main; // audio-only
2011 //================== Init VIDEO (codec & libvo) ==========================
2012 if(!fixed_vo || !(inited_flags&INITED_VO)){
2013 current_module="preinit_libvo";
2015 vo_config_count=0;
2016 //if((video_out->preinit(vo_subdevice))!=0){
2017 if(!(video_out=init_best_video_out(video_driver_list))){
2018 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
2019 goto goto_next_file; // exit_player(MSGTR_Exit_error);
2021 sh_video->video_out=video_out;
2022 inited_flags|=INITED_VO;
2025 current_module="init_video_filters";
2027 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
2028 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
2030 #ifdef HAVE_MENU
2031 if(use_menu) {
2032 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
2033 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
2034 if(!vf_menu) {
2035 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
2036 use_menu = 0;
2039 if(vf_menu)
2040 sh_video->vfilter=(void*)append_filters(vf_menu);
2041 else
2042 #endif
2043 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
2045 current_module="init_video_codec";
2047 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2048 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
2049 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2051 if(!sh_video->inited){
2052 if(!fixed_vo) uninit_player(INITED_VO);
2053 if(!sh_audio) goto goto_next_file;
2054 sh_video = d_video->sh = NULL;
2055 goto main; // exit_player(MSGTR_Exit_error);
2058 inited_flags|=INITED_VCODEC;
2060 if(auto_quality>0){
2061 // Auto quality option enabled
2062 output_quality=get_video_quality_max(sh_video);
2063 if(auto_quality>output_quality) auto_quality=output_quality;
2064 else output_quality=auto_quality;
2065 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
2066 set_video_quality(sh_video,output_quality);
2069 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2071 current_module="init_vo";
2073 if(vo_flags & 0x08 && vo_spudec)
2074 spudec_set_hw_spu(vo_spudec,video_out);
2076 #ifdef HAVE_FREETYPE
2077 force_load_font = 1;
2078 #endif
2080 //================== MAIN: ==========================
2081 main:
2082 current_module="main";
2084 // If there is no video OSD has to be disabled.
2085 // In case of playing a playtree we have to restore the
2086 // old OSD level after playing one or more audio-only files.
2087 if(!sh_video && osd_level >= 0) { // save OSD level only once
2088 osd_level_saved = osd_level;
2089 osd_level = 0;
2090 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
2091 osd_level = osd_level_saved;
2092 osd_level_saved = -1;
2095 fflush(stdout);
2097 #ifdef HAVE_NEW_GUI
2098 if ( use_gui )
2100 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
2101 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
2102 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
2103 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
2104 guiGetEvent( guiSetDemuxer,(char *)demuxer );
2106 #endif
2109 //int frame_corr_num=0; //
2110 //float v_frame=0; // Video
2111 float time_frame=0; // Timer
2112 //float num_frames=0; // number of frames played
2113 int grab_frames=0;
2114 char osd_text_buffer[64];
2115 char osd_show_text_buffer[64];
2116 int drop_frame=0; // current dropping status
2117 int dropped_frames=0; // how many frames dropped since last non-dropped frame
2118 int too_slow_frame_cnt=0;
2119 int too_fast_frame_cnt=0;
2120 // for auto-quality:
2121 float AV_delay=0; // average of A-V timestamp differences
2122 double vdecode_time;
2123 unsigned int lastframeout_ts=0;
2124 /*float time_frame_corr_avg=0;*/ /* unused */
2126 float next_frame_time=0;
2127 int frame_time_remaining=0; // flag
2128 int blit_frame=0;
2130 osd_text_buffer[0]=0;
2132 //================ SETUP AUDIO ==========================
2134 if(sh_audio){
2135 //const ao_info_t *info=audio_out->info;
2136 current_module="af_preinit";
2137 ao_data.samplerate=force_srate;
2138 ao_data.channels=0;
2139 ao_data.format=audio_output_format;
2140 #if 1
2141 // first init to detect best values
2142 if(!preinit_audio_filters(sh_audio,
2143 // input:
2144 (int)(sh_audio->samplerate*playback_speed),
2145 sh_audio->channels, sh_audio->sample_format,
2146 // output:
2147 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){
2148 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2150 #endif
2151 current_module="ao2_init";
2152 if(!(audio_out=init_best_audio_out(audio_driver_list,
2153 0, // plugin flag
2154 ao_data.samplerate,
2155 ao_data.channels,
2156 ao_data.format,0))){
2157 // FAILED:
2158 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2159 uninit_player(INITED_ACODEC); // close codec
2160 sh_audio=d_audio->sh=NULL; // -> nosound
2161 } else {
2162 // SUCCESS:
2163 inited_flags|=INITED_AO;
2164 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
2165 audio_out->info->short_name,
2166 ao_data.samplerate, ao_data.channels,
2167 af_fmt2str_short(ao_data.format),
2168 af_fmt2bits(ao_data.format)/8 );
2169 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2170 audio_out->info->name, audio_out->info->author);
2171 if(strlen(audio_out->info->comment) > 0)
2172 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2173 // init audio filters:
2174 #if 1
2175 current_module="af_init";
2176 if(!build_afilter_chain(sh_audio, &ao_data)) {
2177 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2178 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2179 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2180 // sh_audio=d_audio->sh=NULL; // -> nosound
2182 #endif
2184 mixer.audio_out = audio_out;
2185 mixer.volstep = volstep;
2188 current_module="av_init";
2190 if(sh_video) sh_video->timer=0;
2191 if(sh_audio) sh_audio->delay=-audio_delay;
2193 if(!sh_audio){
2194 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
2195 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
2196 ds_free_packs(d_audio); // free buffered chunks
2197 d_audio->id=-2; // do not read audio chunks
2198 //uninit_player(INITED_AO); // close device
2200 if(!sh_video){
2201 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
2202 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
2203 ds_free_packs(d_video);
2204 d_video->id=-2;
2205 //if(!fixed_vo) uninit_player(INITED_VO);
2208 if (!sh_video && !sh_audio)
2209 goto goto_next_file;
2211 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
2212 if(force_fps && sh_video){
2213 vo_fps = sh_video->fps=force_fps;
2214 sh_video->frametime=1.0f/sh_video->fps;
2215 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
2218 //==================== START PLAYING =======================
2220 if(loop_times>1) loop_times--; else
2221 if(loop_times==1) loop_times = -1;
2223 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
2225 #ifdef USE_DVDNAV
2226 if (stream->type==STREAMTYPE_DVDNAV) {
2227 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
2229 #endif
2231 total_time_usage_start=GetTimer();
2232 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
2233 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
2234 play_n_frames=play_n_frames_mf;
2236 if(play_n_frames==0){
2237 eof=PT_NEXT_ENTRY; goto goto_next_file;
2240 while(!eof){
2241 float aq_sleep_time=0;
2243 if(play_n_frames>=0){
2244 --play_n_frames;
2245 if(play_n_frames<0) eof = PT_NEXT_ENTRY;
2248 /*========================== PLAY AUDIO ============================*/
2250 while(sh_audio){
2251 unsigned int t;
2252 double tt;
2253 int playsize;
2255 current_module="play_audio";
2257 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2258 playsize=audio_out->get_space();
2260 // handle audio-only case:
2261 if(playsize < ao_data.outburst &&
2262 !sh_video) { // buffer is full, do not block here!!!
2263 usec_sleep(10000); // Wait a tick before retry
2264 continue;
2267 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
2269 // Fill buffer if needed:
2270 current_module="decode_audio"; // Enter AUDIO decoder module
2271 t=GetTimer();
2272 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
2273 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
2274 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
2275 if(ret<=0) break; // EOF?
2276 sh_audio->a_out_buffer_len+=ret;
2278 t=GetTimer()-t;
2279 tt = t*0.000001f; audio_time_usage+=tt;
2280 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
2282 // play audio:
2283 current_module="play_audio";
2284 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2286 if(playsize>0){
2287 sh_audio->a_out_buffer_len-=playsize;
2288 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2289 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2290 ao_data.bps : sh_audio->o_bps));
2293 break;
2294 } // while(sh_audio)
2296 if(!sh_video) {
2297 // handle audio-only case:
2298 if(!quiet) {
2299 float a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
2300 print_status(a_pos, 0, 0);
2302 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2304 } else {
2306 /*========================== PLAY VIDEO ============================*/
2308 float frame_time=next_frame_time;
2310 vo_pts=sh_video->timer*90000.0;
2311 vo_fps=sh_video->fps;
2313 if(!frame_time_remaining){
2314 //-------------------- Decode a frame: -----------------------
2315 vdecode_time=video_time_usage;
2316 while(1)
2317 { unsigned char* start=NULL;
2318 int in_size;
2319 // get it!
2320 current_module="video_read_frame";
2321 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2322 if(in_size<0){ eof=1; break; }
2323 if(in_size>max_framesize) max_framesize=in_size; // stats
2324 sh_video->timer+=frame_time;
2325 if(sh_audio) sh_audio->delay-=frame_time;
2326 time_frame+=frame_time; // for nosound
2327 // video_read_frame can change fps (e.g. for asf video)
2328 vo_fps = sh_video->fps;
2329 #ifdef HAVE_X11
2330 vo_mouse_timer_const = (int)sh_video->fps;
2331 #endif
2332 // check for frame-drop:
2333 current_module="check_framedrop";
2334 if(sh_audio && !d_audio->eof){
2335 float delay=playback_speed*audio_out->get_delay();
2336 float d=delay-sh_audio->delay;
2337 // we should avoid dropping to many frames in sequence unless we
2338 // are too late. and we allow 100ms A-V delay here:
2339 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
2340 drop_frame=frame_dropping;
2341 ++drop_frame_cnt;
2342 ++dropped_frames;
2343 } else {
2344 drop_frame=dropped_frames=0;
2346 ++total_frame_cnt;
2348 // decode:
2349 current_module="decode_video";
2350 // printf("Decode! %p %d \n",start,in_size);
2351 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2352 break;
2354 vdecode_time=video_time_usage-vdecode_time;
2355 //------------------------ frame decoded. --------------------
2357 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2359 if(sh_video->vf_inited<0){
2360 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2361 eof=1; goto goto_next_file;
2366 // ==========================================================================
2368 // current_module="draw_osd";
2369 // if(vo_config_count) video_out->draw_osd();
2371 #ifdef HAVE_NEW_GUI
2372 if(use_gui) guiEventHandling();
2373 #endif
2375 current_module="calc_sleep_time";
2377 #if 0
2378 { // debug frame dropping code
2379 float delay=audio_out->get_delay();
2380 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2381 sh_video->timer,sh_audio->timer-delay,
2382 sh_video->timer-(sh_audio->timer-delay),
2383 delay,drop_frame);
2385 #endif
2387 if(drop_frame && !frame_time_remaining && !autosync){
2389 * Note: time_frame should not be forced to 0 in autosync mode.
2390 * It is used as a cumulative counter to predict and correct the
2391 * delay measurements from the audio driver. time_frame is already
2392 * < 0, so the "time to sleep" code does not actually sleep. Also,
2393 * blit_frame is already 0 because drop_frame was true when
2394 * decode_video was called (which causes it to set blit_frame to 0.)
2395 * When autosync==0, the default behavior is still completely unchanged.
2398 time_frame=0; // don't sleep!
2399 blit_frame=0; // don't display!
2401 } else {
2403 // It's time to sleep...
2405 frame_time_remaining=0;
2406 time_frame-=GetRelativeTime(); // reset timer
2408 if(sh_audio && !d_audio->eof){
2409 float delay=playback_speed*audio_out->get_delay();
2410 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2412 if (autosync){
2414 * Adjust this raw delay value by calculating the expected
2415 * delay for this frame and generating a new value which is
2416 * weighted between the two. The higher autosync is, the
2417 * closer to the delay value gets to that which "-nosound"
2418 * would have used, and the longer it will take for A/V
2419 * sync to settle at the right value (but it eventually will.)
2420 * This settling time is very short for values below 100.
2422 float predicted = sh_audio->delay+time_frame;
2423 float difference = delay - predicted;
2424 delay = predicted + difference / (float)autosync;
2427 time_frame=delay-sh_audio->delay;
2429 // delay = amount of audio buffered in soundcard/driver
2430 if(delay>0.25) delay=0.25; else
2431 if(delay<0.10) delay=0.10;
2432 if(time_frame>delay*0.6){
2433 // sleep time too big - may cause audio drops (buffer underrun)
2434 frame_time_remaining=1;
2435 time_frame=delay*0.5;
2438 } else {
2440 // NOSOUND:
2441 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2442 time_frame=0;
2446 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2448 aq_sleep_time+=time_frame;
2450 } // !drop_frame
2452 //============================== SLEEP: ===================================
2454 time_frame/=playback_speed;
2456 // flag 256 means: libvo driver does its timing (dvb card)
2457 if(time_frame>0.001 && !(vo_flags&256)){
2459 #ifdef HAVE_RTC
2460 if(rtc_fd>=0){
2461 // -------- RTC -----------
2462 current_module="sleep_rtc";
2463 while (time_frame > 0.000) {
2464 unsigned long rtc_ts;
2465 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2466 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2467 time_frame-=GetRelativeTime();
2469 } else
2470 #endif
2471 #ifdef SYS_DARWIN
2473 current_module="sleep_darwin";
2474 while(time_frame>0.005) {
2475 usec_sleep(1000000*time_frame);
2476 time_frame-=GetRelativeTime();
2479 #else
2481 // -------- TIMER + SOFTSLEEP -----------
2482 float min=softsleep?0.021:0.005;
2483 current_module="sleep_timer";
2484 while(time_frame>min){
2485 if(time_frame<=0.020)
2486 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2487 else
2488 usec_sleep(1000000*(time_frame-0.020));
2489 time_frame-=GetRelativeTime();
2491 if(softsleep){
2492 current_module="sleep_soft";
2493 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
2494 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2497 #endif
2500 //if(!frame_time_remaining){ // should we display the frame now?
2502 //====================== FLIP PAGE (VIDEO BLT): =========================
2504 current_module="vo_check_events";
2505 if(vo_config_count) video_out->check_events();
2507 current_module="flip_page";
2508 if (!frame_time_remaining) {
2509 if(blit_frame){
2510 unsigned int t2=GetTimer();
2511 double tt;
2512 float j;
2513 #define FRAME_LAG_WARN 0.2
2514 j = ((float)t2 - lastframeout_ts) / 1000000;
2515 lastframeout_ts = GetTimer();
2516 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2517 too_fast_frame_cnt++;
2518 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2519 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2520 too_slow_frame_cnt++;
2521 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2523 if(vo_config_count) video_out->flip_page();
2524 // usec_sleep(50000); // test only!
2525 t2=GetTimer()-t2;
2526 tt = t2*0.000001f;
2527 vout_time_usage+=tt;
2528 } else {
2530 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2531 otherwise A/V desync will occur. -- Alvieboy
2533 if (vo_config_count)
2534 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2537 //====================== A-V TIMESTAMP CORRECTION: =========================
2539 current_module="av_sync";
2541 if(sh_audio){
2542 float a_pts=0;
2543 float v_pts=0;
2545 // unplayed bytes in our and soundcard/dma buffer:
2546 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2548 if (autosync){
2550 * If autosync is enabled, the value for delay must be calculated
2551 * a bit differently. It is set only to the difference between
2552 * the audio and video timers. Any attempt to include the real
2553 * or corrected delay causes the pts_correction code below to
2554 * try to correct for the changes in delay which autosync is
2555 * trying to measure. This keeps the two from competing, but still
2556 * allows the code to correct for PTS drift *only*. (Using a delay
2557 * value here, even a "corrected" one, would be incompatible with
2558 * autosync mode.)
2560 delay=sh_audio->delay;
2561 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2564 #if 0
2565 if(pts_from_bps){
2566 // PTS = sample_no / samplerate
2567 unsigned int samples=
2568 // (sh_audio->audio.dwSampleSize)?
2569 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2570 ds_tell_block(d_audio); // <- used for VBR audio
2571 samples+=sh_audio->audio.dwStart; // offset
2572 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2573 delay_corrected=1;
2574 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2575 } else
2576 #endif
2578 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2579 a_pts=d_audio->pts;
2580 if(!delay_corrected) if(a_pts) delay_corrected=1;
2581 #if 0
2582 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2583 a_pts,
2584 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2585 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2586 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2587 #endif
2588 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2590 v_pts=sh_video ? sh_video->pts : d_video->pts;
2592 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);
2594 if(delay_corrected){
2595 static int drop_message=0;
2596 float x;
2597 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2598 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2599 ++drop_message;
2600 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2602 x=AV_delay*0.1f;
2603 if(x<-max_pts_correction) x=-max_pts_correction; else
2604 if(x> max_pts_correction) x= max_pts_correction;
2605 if(default_max_pts_correction>=0)
2606 max_pts_correction=default_max_pts_correction;
2607 else
2608 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2609 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2610 if(!quiet)
2611 print_status(a_pts - audio_delay - delay, AV_delay, c_total);
2614 } else {
2615 // No audio:
2617 if(!quiet)
2618 print_status(0, 0, 0);
2622 //============================ Auto QUALITY ============================
2624 /*Output quality adjustments:*/
2625 if(auto_quality>0){
2626 current_module="autoq";
2627 // float total=0.000001f * (GetTimer()-aq_total_time);
2628 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2629 if(output_quality<auto_quality && aq_sleep_time>0)
2630 ++output_quality;
2631 else
2632 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2633 if(output_quality>1 && aq_sleep_time<0)
2634 --output_quality;
2635 else
2636 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2637 output_quality=0;
2638 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2639 set_video_quality(sh_video,output_quality);
2642 } // end if(sh_video)
2644 //============================ Handle PAUSE ===============================
2646 current_module="pause";
2648 #ifdef USE_OSD
2649 if(osd_visible){
2650 if (!--osd_visible){
2651 vo_osd_progbar_type=-1; // disable
2652 vo_osd_changed(OSDTYPE_PROGBAR);
2653 if (osd_function != OSD_PAUSE)
2654 osd_function = OSD_PLAY;
2657 #endif
2659 if(osd_function==OSD_PAUSE){
2660 mp_cmd_t* cmd;
2661 if(!quiet) {
2662 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2663 if (identify)
2664 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_PAUSED\n");
2665 fflush(stdout);
2667 #ifdef HAVE_NEW_GUI
2668 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2669 #endif
2670 if (video_out && sh_video && vo_config_count)
2671 video_out->control(VOCTRL_PAUSE, NULL);
2673 if (audio_out && sh_audio)
2674 audio_out->pause(); // pause audio, keep data if possible
2676 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
2677 if(sh_video && video_out && vo_config_count) video_out->check_events();
2678 #ifdef HAVE_NEW_GUI
2679 if(use_gui){
2680 guiEventHandling();
2681 guiGetEvent( guiReDraw,NULL );
2682 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2684 #endif
2685 #ifdef HAVE_MENU
2686 if(vf_menu)
2687 vf_menu_pause_update(vf_menu);
2688 #endif
2689 usec_sleep(20000);
2691 if (cmd && cmd->id == MP_CMD_PAUSE) {
2692 cmd = mp_input_get_cmd(0,1,0);
2693 mp_cmd_free(cmd);
2695 osd_function=OSD_PLAY;
2696 if (audio_out && sh_audio)
2697 audio_out->resume(); // resume audio
2698 if (video_out && sh_video && vo_config_count)
2699 video_out->control(VOCTRL_RESUME, NULL); // resume video
2700 (void)GetRelativeTime(); // keep TF around FT in next cycle
2701 #ifdef HAVE_NEW_GUI
2702 if (use_gui)
2704 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2705 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2707 #endif
2710 // handle -sstep
2711 if(step_sec>0) {
2712 osd_function=OSD_FFW;
2713 rel_seek_secs+=step_sec;
2716 #ifdef USE_DVDNAV
2717 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2718 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2719 #endif
2721 //================= EDL =========================================
2723 #ifdef USE_EDL
2724 if( next_edl_record ) { // Are we (still?) doing EDL?
2725 if ( !sh_video ) {
2726 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
2727 free_edl(edl_records);
2728 next_edl_record = NULL;
2729 edl_records = NULL;
2730 } else {
2731 if( sh_video->pts >= next_edl_record->start_sec ) {
2732 if( next_edl_record->action == EDL_SKIP ) {
2733 osd_function = OSD_FFW;
2734 abs_seek_pos = 0;
2735 rel_seek_secs = next_edl_record->length_sec;
2736 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 );
2737 edl_decision = 1;
2738 } else if( next_edl_record->action == EDL_MUTE ) {
2739 edl_muted = !edl_muted;
2740 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
2741 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
2743 next_edl_record=next_edl_record->next;
2747 #endif
2749 //================= Keyboard events, SEEKing ====================
2751 current_module="key_events";
2754 mp_cmd_t* cmd;
2755 int brk_cmd = 0;
2756 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
2757 switch(cmd->id) {
2758 case MP_CMD_SEEK : {
2759 float v;
2760 int abs;
2761 osd_show_percentage = 25;
2762 v = cmd->args[0].v.f;
2763 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2764 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2765 abs_seek_pos = 1;
2766 if(sh_video)
2767 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2768 rel_seek_secs = v;
2770 else if(abs) { /* Absolute seek by percentage */
2771 abs_seek_pos = 3;
2772 if(sh_video)
2773 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2774 rel_seek_secs = v/100.0;
2776 else {
2777 rel_seek_secs+= v;
2778 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2780 brk_cmd = 1;
2781 } break;
2782 #ifdef USE_EDL
2783 case MP_CMD_EDL_MARK:
2784 if( edl_fd ) {
2785 float v = sh_video->pts;
2786 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2788 break;
2789 #endif
2790 case MP_CMD_SWITCH_RATIO : {
2791 if (cmd->nargs == 0)
2792 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2793 else
2794 movie_aspect = cmd->args[0].v.f;
2795 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2796 } break;
2797 case MP_CMD_AUDIO_DELAY : {
2798 float v = cmd->args[0].v.f;
2799 audio_delay += v;
2800 osd_show_av_delay = 9;
2801 if(sh_audio) sh_audio->delay+= v;
2802 } break;
2803 case MP_CMD_SPEED_INCR : {
2804 float v = cmd->args[0].v.f;
2805 playback_speed += v;
2806 if (sh_video)
2807 osd_show_speed = sh_video->fps;
2808 build_afilter_chain(sh_audio, &ao_data);
2809 } break;
2810 case MP_CMD_SPEED_MULT : {
2811 float v = cmd->args[0].v.f;
2812 playback_speed *= v;
2813 if (sh_video)
2814 osd_show_speed = sh_video->fps;
2815 build_afilter_chain(sh_audio, &ao_data);
2816 } break;
2817 case MP_CMD_SPEED_SET : {
2818 float v = cmd->args[0].v.f;
2819 playback_speed = v;
2820 if (sh_video)
2821 osd_show_speed = sh_video->fps;
2822 build_afilter_chain(sh_audio, &ao_data);
2823 } break;
2824 case MP_CMD_FRAME_STEP :
2825 case MP_CMD_PAUSE : {
2826 cmd->pausing = 1;
2827 brk_cmd = 1;
2828 } break;
2829 case MP_CMD_QUIT : {
2830 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
2832 case MP_CMD_GRAB_FRAMES : {
2833 grab_frames=2;
2834 } break;
2835 case MP_CMD_PLAY_TREE_STEP : {
2836 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2837 int force = cmd->args[1].v.i;
2839 #ifdef HAVE_NEW_GUI
2840 if (use_gui) {
2841 int i=0;
2842 if (n>0)
2843 for (i=0;i<n;i++)
2844 mplNext();
2845 else
2846 for (i=0;i<-1*n;i++)
2847 mplPrev();
2848 } else
2849 #endif
2851 if(!force && playtree_iter) {
2852 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2854 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2855 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2856 play_tree_iter_free(i);
2857 } else
2858 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2859 if(eof)
2860 play_tree_step = n;
2861 brk_cmd = 1;
2863 } break;
2864 case MP_CMD_PLAY_TREE_UP_STEP : {
2865 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2866 int force = cmd->args[1].v.i;
2868 if(!force && playtree_iter) {
2869 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2870 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2871 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2872 play_tree_iter_free(i);
2873 } else
2874 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2875 brk_cmd = 1;
2876 } break;
2877 case MP_CMD_PLAY_ALT_SRC_STEP : {
2878 if(playtree_iter && playtree_iter->num_files > 1) {
2879 int v = cmd->args[0].v.i;
2880 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2881 eof = PT_NEXT_SRC;
2882 else if(v < 0 && playtree_iter->file > 1)
2883 eof = PT_PREV_SRC;
2885 brk_cmd = 1;
2886 } break;
2887 case MP_CMD_SUB_DELAY : {
2888 #ifdef USE_SUB
2889 if (sh_video) {
2890 int abs= cmd->args[1].v.i;
2891 float v = cmd->args[0].v.f;
2892 if(abs)
2893 sub_delay = v;
2894 else
2895 sub_delay += v;
2896 osd_show_sub_delay = 9; // show the subdelay in OSD
2898 #endif
2899 } break;
2900 case MP_CMD_SUB_STEP : {
2901 #ifdef USE_SUB
2902 if (sh_video) {
2903 int movement = cmd->args[0].v.i;
2904 step_sub(subdata, sh_video->pts, movement);
2905 osd_show_sub_delay = 9; // show the subdelay in OSD
2907 #endif
2908 } break;
2909 case MP_CMD_SUB_LOG : {
2910 #ifdef USE_SUB
2911 log_sub();
2912 #endif
2913 } break;
2914 case MP_CMD_OSD : {
2915 #ifdef USE_OSD
2916 if(sh_video) {
2917 int v = cmd->args[0].v.i;
2918 if(v < 0)
2919 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2920 else
2921 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2922 /* Show OSD state when disabled, but not when an explicit
2923 argument is given to the osd command, i.e. in slave mode. */
2924 if (v == -1 && osd_level <= 1)
2925 osd_show_status = 9;
2927 #endif
2928 } break;
2929 case MP_CMD_OSD_SHOW_TEXT : {
2930 #ifdef USE_OSD
2931 if(osd_level && sh_video){
2932 osd_show_text=sh_video->fps; // 1 sec
2933 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2935 #endif
2936 } break;
2937 case MP_CMD_VOLUME : {
2938 int v = cmd->args[0].v.i;
2940 // start change for absolute volume value
2941 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2943 #ifdef USE_EDL
2944 if (edl_muted) break;
2945 user_muted = 0;
2946 #endif
2947 if( abs )
2949 mixer_setvolume(&mixer, (float)v, (float)v );
2950 } else {
2951 if(v > 0)
2952 mixer_incvolume(&mixer);
2953 else
2954 mixer_decvolume(&mixer);
2957 #ifdef USE_OSD
2958 if(osd_level && sh_video){
2959 float vol;
2960 osd_visible=sh_video->fps; // 1 sec
2961 vo_osd_progbar_type=OSD_VOLUME;
2962 mixer_getbothvolume(&mixer, &vol);
2963 vo_osd_progbar_value=(vol*256.0)/100.0;
2964 vo_osd_changed(OSDTYPE_PROGBAR);
2966 #endif
2967 } break;
2968 case MP_CMD_MUTE:
2969 #ifdef USE_EDL
2970 user_muted = !user_muted;
2971 if ((edl_muted | user_muted) != mixer.muted)
2972 #endif
2973 mixer_mute(&mixer);
2974 break;
2975 case MP_CMD_LOADFILE : {
2976 play_tree_t* e = play_tree_new();
2977 play_tree_add_file(e,cmd->args[0].v.s);
2979 // Go back to the start point
2980 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2981 /* NOP */;
2982 play_tree_free_list(playtree->child,1);
2983 play_tree_set_child(playtree,e);
2984 play_tree_iter_step(playtree_iter,0,0);
2985 eof = PT_NEXT_SRC;
2986 brk_cmd = 1;
2987 } break;
2988 case MP_CMD_LOADLIST : {
2989 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
2990 if(!e)
2991 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
2992 else {
2993 // Go back to the start point
2994 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2995 /* NOP */;
2996 play_tree_free_list(playtree->child,1);
2997 play_tree_set_child(playtree,e);
2998 play_tree_iter_step(playtree_iter,0,0);
2999 eof = PT_NEXT_SRC;
3001 brk_cmd = 1;
3002 } break;
3003 case MP_CMD_GAMMA : {
3004 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3006 if (!sh_video)
3007 break;
3009 if (vo_gamma_gamma == 1000)
3011 vo_gamma_gamma = 0;
3012 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
3015 if (abs)
3016 vo_gamma_gamma = v;
3017 else
3018 vo_gamma_gamma += v;
3020 if (vo_gamma_gamma > 100)
3021 vo_gamma_gamma = 100;
3022 else if (vo_gamma_gamma < -100)
3023 vo_gamma_gamma = -100;
3024 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
3025 #ifdef USE_OSD
3026 if(osd_level){
3027 osd_visible=sh_video->fps; // 1 sec
3028 vo_osd_progbar_type=OSD_BRIGHTNESS;
3029 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
3030 vo_osd_changed(OSDTYPE_PROGBAR);
3032 #endif // USE_OSD
3033 } break;
3034 case MP_CMD_BRIGHTNESS : {
3035 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3037 if (!sh_video)
3038 break;
3040 if (vo_gamma_brightness == 1000)
3042 vo_gamma_brightness = 0;
3043 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
3046 if (abs)
3047 vo_gamma_brightness = v;
3048 else
3049 vo_gamma_brightness += v;
3051 if (vo_gamma_brightness > 100)
3052 vo_gamma_brightness = 100;
3053 else if (vo_gamma_brightness < -100)
3054 vo_gamma_brightness = -100;
3055 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
3056 #ifdef USE_OSD
3057 if(osd_level){
3058 osd_visible=sh_video->fps; // 1 sec
3059 vo_osd_progbar_type=OSD_BRIGHTNESS;
3060 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
3061 vo_osd_changed(OSDTYPE_PROGBAR);
3063 #endif // USE_OSD
3065 } break;
3066 case MP_CMD_CONTRAST : {
3067 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3069 if (!sh_video)
3070 break;
3072 if (vo_gamma_contrast == 1000)
3074 vo_gamma_contrast = 0;
3075 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
3078 if (abs)
3079 vo_gamma_contrast = v;
3080 else
3081 vo_gamma_contrast += v;
3083 if (vo_gamma_contrast > 100)
3084 vo_gamma_contrast = 100;
3085 else if (vo_gamma_contrast < -100)
3086 vo_gamma_contrast = -100;
3087 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
3088 #ifdef USE_OSD
3089 if(osd_level){
3090 osd_visible=sh_video->fps; // 1 sec
3091 vo_osd_progbar_type=OSD_CONTRAST;
3092 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
3093 vo_osd_changed(OSDTYPE_PROGBAR);
3095 #endif // USE_OSD
3097 } break;
3098 case MP_CMD_SATURATION : {
3099 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3101 if (!sh_video)
3102 break;
3104 if (vo_gamma_saturation == 1000)
3106 vo_gamma_saturation = 0;
3107 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
3110 if (abs)
3111 vo_gamma_saturation = v;
3112 else
3113 vo_gamma_saturation += v;
3115 if (vo_gamma_saturation > 100)
3116 vo_gamma_saturation = 100;
3117 else if (vo_gamma_saturation < -100)
3118 vo_gamma_saturation = -100;
3119 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
3120 #ifdef USE_OSD
3121 if(osd_level){
3122 osd_visible=sh_video->fps; // 1 sec
3123 vo_osd_progbar_type=OSD_SATURATION;
3124 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
3125 vo_osd_changed(OSDTYPE_PROGBAR);
3127 #endif // USE_OSD
3129 } break;
3130 case MP_CMD_HUE : {
3131 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3133 if (!sh_video)
3134 break;
3136 if (vo_gamma_hue == 1000)
3138 vo_gamma_hue = 0;
3139 get_video_colors(sh_video, "hue", &vo_gamma_hue);
3142 if (abs)
3143 vo_gamma_hue = v;
3144 else
3145 vo_gamma_hue += v;
3147 if (vo_gamma_hue > 100)
3148 vo_gamma_hue = 100;
3149 else if (vo_gamma_hue < -100)
3150 vo_gamma_hue = -100;
3151 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
3152 #ifdef USE_OSD
3153 if(osd_level){
3154 osd_visible=sh_video->fps; // 1 sec
3155 vo_osd_progbar_type=OSD_HUE;
3156 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
3157 vo_osd_changed(OSDTYPE_PROGBAR);
3159 #endif // USE_OSD
3161 } break;
3162 case MP_CMD_FRAMEDROPPING : {
3163 int v = cmd->args[0].v.i;
3164 if(v < 0){
3165 frame_dropping = (frame_dropping+1)%3;
3166 #ifdef USE_OSD
3167 osd_show_framedropping=10;
3168 vo_osd_changed(OSDTYPE_SUBTITLE);
3169 #endif
3171 else
3172 frame_dropping = v > 2 ? 2 : v;
3173 } break;
3174 #ifdef USE_TV
3175 case MP_CMD_TV_SET_FREQ : {
3176 if (file_format == DEMUXER_TYPE_TV)
3177 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
3178 } break;
3179 case MP_CMD_TV_SET_NORM : {
3180 if (file_format == DEMUXER_TYPE_TV)
3181 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3182 } break;
3183 case MP_CMD_TV_SET_BRIGHTNESS : {
3184 if (file_format == DEMUXER_TYPE_TV)
3185 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
3186 } break;
3187 case MP_CMD_TV_SET_HUE : {
3188 if (file_format == DEMUXER_TYPE_TV)
3189 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
3190 } break;
3191 case MP_CMD_TV_SET_SATURATION : {
3192 if (file_format == DEMUXER_TYPE_TV)
3193 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
3194 } break;
3195 case MP_CMD_TV_SET_CONTRAST : {
3196 if (file_format == DEMUXER_TYPE_TV)
3197 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
3198 } break;
3199 case MP_CMD_TV_STEP_CHANNEL : {
3200 if (file_format == DEMUXER_TYPE_TV) {
3201 int v = cmd->args[0].v.i;
3202 if(v > 0){
3203 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
3204 #ifdef USE_OSD
3205 if (tv_channel_list) {
3206 osd_show_tv_channel = sh_video->fps;
3207 vo_osd_changed(OSDTYPE_SUBTITLE);
3209 #endif
3210 } else {
3211 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
3212 #ifdef USE_OSD
3213 if (tv_channel_list) {
3214 osd_show_tv_channel = sh_video->fps;
3215 vo_osd_changed(OSDTYPE_SUBTITLE);
3217 #endif
3221 #ifdef HAS_DVBIN_SUPPORT
3222 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3224 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3225 if(priv->is_on)
3227 int dir;
3228 int v = cmd->args[0].v.i;
3230 last_dvb_step = v;
3231 if(v > 0)
3232 dir = DVB_CHANNEL_HIGHER;
3233 else
3234 dir = DVB_CHANNEL_LOWER;
3237 if(dvb_step_channel(priv, dir))
3239 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3240 cache_uninit(stream);
3241 goto goto_enable_cache;
3245 #endif
3246 break;
3247 case MP_CMD_TV_SET_CHANNEL : {
3248 if (file_format == DEMUXER_TYPE_TV) {
3249 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3250 #ifdef USE_OSD
3251 if (tv_channel_list) {
3252 osd_show_tv_channel = sh_video->fps;
3253 vo_osd_changed(OSDTYPE_SUBTITLE);
3255 #endif
3257 } break;
3258 #ifdef HAS_DVBIN_SUPPORT
3259 case MP_CMD_DVB_SET_CHANNEL:
3261 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3263 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3264 if(priv->is_on)
3266 if(priv->list->current <= cmd->args[0].v.i)
3267 last_dvb_step = 1;
3268 else
3269 last_dvb_step = -1;
3271 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
3273 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3274 cache_uninit(stream);
3275 goto goto_enable_cache;
3280 #endif
3281 case MP_CMD_TV_LAST_CHANNEL : {
3282 if (file_format == DEMUXER_TYPE_TV) {
3283 tv_last_channel((tvi_handle_t*)(demuxer->priv));
3284 #ifdef USE_OSD
3285 if (tv_channel_list) {
3286 osd_show_tv_channel = sh_video->fps;
3287 vo_osd_changed(OSDTYPE_SUBTITLE);
3289 #endif
3291 } break;
3292 case MP_CMD_TV_STEP_NORM : {
3293 if (file_format == DEMUXER_TYPE_TV)
3294 tv_step_norm((tvi_handle_t*)(demuxer->priv));
3295 } break;
3296 case MP_CMD_TV_STEP_CHANNEL_LIST : {
3297 if (file_format == DEMUXER_TYPE_TV)
3298 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
3299 } break;
3300 #endif
3301 case MP_CMD_SWITCH_VSYNC: {
3302 vo_vsync = ( cmd->nargs > 0 )? cmd->args[0].v.i : !vo_vsync;
3303 } break;
3304 case MP_CMD_VO_FULLSCREEN:
3306 #ifdef HAVE_NEW_GUI
3307 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3308 else
3309 #endif
3310 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3311 } break;
3312 case MP_CMD_VO_ONTOP:
3314 if(video_out && vo_config_count) {
3315 video_out->control(VOCTRL_ONTOP, 0);
3316 #ifdef USE_OSD
3317 osd_show_ontop=10;
3318 vo_osd_changed(OSDTYPE_SUBTITLE);
3319 #endif
3322 } break;
3323 case MP_CMD_VO_ROOTWIN:
3325 if(video_out && vo_config_count) {
3326 video_out->control(VOCTRL_ROOTWIN, 0);
3327 #ifdef USE_OSD
3328 osd_show_rootwin=10;
3329 vo_osd_changed(OSDTYPE_SUBTITLE);
3330 #endif
3333 } break;
3334 case MP_CMD_PANSCAN : {
3335 if ( !video_out ) break;
3336 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3338 int abs= cmd->args[1].v.i;
3339 float v = cmd->args[0].v.f;
3340 float res;
3341 if(abs) res = v;
3342 else res = vo_panscan+v;
3343 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3344 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3345 #ifdef USE_OSD
3346 if(osd_level && sh_video){
3347 osd_visible=sh_video->fps; // 1 sec
3348 vo_osd_progbar_type=OSD_PANSCAN;
3349 vo_osd_progbar_value=vo_panscan*256;
3350 vo_osd_changed(OSDTYPE_PROGBAR);
3352 #endif
3354 } break;
3355 case MP_CMD_SUB_POS:
3357 #ifdef USE_SUB
3358 if (sh_video) {
3359 int v;
3360 v = cmd->args[0].v.i;
3362 sub_pos+=v;
3363 if(sub_pos >100) sub_pos=100;
3364 if(sub_pos <0) sub_pos=0;
3365 vo_osd_changed(OSDTYPE_SUBTITLE);
3366 osd_show_sub_pos = 9;
3368 #endif
3369 } break;
3370 case MP_CMD_SUB_ALIGNMENT:
3372 #ifdef USE_SUB
3373 if (sh_video) {
3374 if (cmd->nargs >= 1)
3375 sub_alignment = cmd->args[0].v.i;
3376 else
3377 sub_alignment = (sub_alignment+1) % 3;
3378 osd_show_sub_alignment = 9;
3379 vo_osd_changed(OSDTYPE_SUBTITLE);
3381 #endif
3382 } break;
3383 case MP_CMD_SUB_VISIBILITY:
3385 #ifdef USE_SUB
3386 if (sh_video) {
3387 sub_visibility=1-sub_visibility;
3388 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3389 vo_osd_changed(OSDTYPE_SUBTITLE);
3391 #endif
3392 } break;
3393 case MP_CMD_SUB_LOAD:
3395 #ifdef USE_SUB
3396 if (sh_video) {
3397 int n = set_of_sub_size;
3398 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
3399 if (n != set_of_sub_size) {
3400 if (global_sub_indices[SUB_SOURCE_SUBS] < 0)
3401 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size;
3402 ++global_sub_size;
3405 #endif
3406 } break;
3407 case MP_CMD_SUB_REMOVE:
3409 #ifdef USE_SUB
3410 if (sh_video) {
3411 int v = cmd->args[0].v.i;
3412 sub_data *subd;
3413 if (v < 0) {
3414 for (v = 0; v < set_of_sub_size; ++v) {
3415 subd = set_of_subtitles[v];
3416 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
3417 sub_free(subd);
3418 set_of_subtitles[v] = NULL;
3420 global_sub_indices[SUB_SOURCE_SUBS] = -1;
3421 global_sub_size -= set_of_sub_size;
3422 set_of_sub_size = 0;
3423 if (set_of_sub_pos >= 0) {
3424 global_sub_pos = -2;
3425 vo_sub_last = vo_sub = NULL;
3426 vo_osd_changed(OSDTYPE_SUBTITLE);
3427 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
3428 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3431 else if (v < set_of_sub_size) {
3432 subd = set_of_subtitles[v];
3433 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
3434 sub_free(subd);
3435 if (set_of_sub_pos == v) {
3436 global_sub_pos = -2;
3437 vo_sub_last = vo_sub = NULL;
3438 vo_osd_changed(OSDTYPE_SUBTITLE);
3439 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
3440 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3442 else if (set_of_sub_pos > v) {
3443 --set_of_sub_pos;
3444 --global_sub_pos;
3446 while (++v < set_of_sub_size)
3447 set_of_subtitles[v - 1] = set_of_subtitles[v];
3448 --set_of_sub_size;
3449 --global_sub_size;
3450 if (set_of_sub_size <= 0)
3451 global_sub_indices[SUB_SOURCE_SUBS] = -1;
3452 set_of_subtitles[set_of_sub_size] = NULL;
3455 #endif
3456 } break;
3457 case MP_CMD_GET_SUB_VISIBILITY:
3459 #ifdef USE_SUB
3460 if (sh_video) {
3461 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsSubVisibility, sub_visibility);
3463 #endif
3464 } break;
3465 case MP_CMD_SUB_SELECT:
3466 if (global_sub_size) {
3467 int source = -1;
3468 int v = cmd->args[0].v.i;
3470 if (v < -1)
3471 global_sub_pos++;
3472 else
3473 global_sub_pos = v;
3474 if (global_sub_pos >= global_sub_size)
3475 global_sub_pos = -1;
3476 if (global_sub_pos >= 0)
3477 source = sub_source();
3479 mp_msg(MSGT_CPLAYER, MSGL_DBG3, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3480 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
3481 global_sub_indices[SUB_SOURCE_SUBS], global_sub_indices[SUB_SOURCE_DEMUX],
3482 global_sub_pos, source);
3484 #ifdef USE_SUB
3485 set_of_sub_pos = -1;
3486 subdata = NULL;
3487 vo_sub_last = vo_sub = NULL;
3488 #endif
3489 vobsub_id = -1;
3490 dvdsub_id = -1;
3491 if (d_dvdsub) d_dvdsub->id = -1;
3493 // be careful!
3494 // if sub_changed is till on but subdata's been reset, bad things happen.
3495 osd_show_vobsub_changed = 0;
3496 osd_show_sub_changed = 0;
3498 if (source == SUB_SOURCE_VOBSUB) {
3499 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
3500 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3501 #ifdef USE_SUB
3502 } else if (source == SUB_SOURCE_SUBS) {
3503 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
3504 subdata = set_of_subtitles[set_of_sub_pos];
3505 if (!global_sub_quiet_osd_hack) osd_show_sub_changed = sh_video->fps;
3506 vo_osd_changed(OSDTYPE_SUBTITLE);
3508 // FIXME: is this the correct place for these?
3509 if(stream_dump_type==3) list_sub_file(subdata);
3510 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
3511 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
3512 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
3513 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
3514 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
3515 #endif
3516 } else if (source == SUB_SOURCE_DEMUX) {
3517 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
3518 if (d_dvdsub) {
3519 #ifdef USE_DVDREAD
3520 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
3521 d_dvdsub->id = dvdsub_id;
3522 spudec_reset(vo_spudec);
3524 #endif
3525 #ifdef HAVE_OGGVORBIS
3526 if (demuxer->type == DEMUXER_TYPE_OGG)
3527 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
3528 #endif
3529 #ifdef HAVE_MATROSKA
3530 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3531 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
3532 if (d_dvdsub->id >= 0 && ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
3533 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
3534 if (vo_spudec != NULL)
3535 spudec_free(vo_spudec);
3536 vo_spudec =
3537 spudec_new_scaled_vobsub(mkv_sh_sub->has_palette ? mkv_sh_sub->palette : NULL, mkv_sh_sub->colors,
3538 mkv_sh_sub->custom_colors,
3539 mkv_sh_sub->width,
3540 mkv_sh_sub->height);
3541 if (!forced_subs_only)
3542 forced_subs_only = mkv_sh_sub->forced_subs_only;
3543 if (vo_spudec) {
3544 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
3545 inited_flags |= INITED_SPUDEC;
3549 #endif
3551 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3552 } else { // off
3553 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3554 #ifdef USE_SUB
3555 vo_osd_changed(OSDTYPE_SUBTITLE);
3556 #endif
3558 // it's annoying and dumb to show osd saying "off" at every subless file...
3559 global_sub_quiet_osd_hack = 0;
3561 break;
3562 case MP_CMD_SUB_FORCED_ONLY:
3563 if (vo_spudec) {
3564 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3565 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3567 break;
3568 case MP_CMD_SCREENSHOT :
3569 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3570 break;
3571 case MP_CMD_VF_CHANGE_RECTANGLE:
3572 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3573 break;
3575 case MP_CMD_GET_TIME_LENGTH : {
3576 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsLength, demuxer_get_time_length(demuxer));
3577 } break;
3579 case MP_CMD_GET_VO_FULLSCREEN : {
3580 if(video_out && vo_config_count)
3581 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsVoFullscreen, vo_fs);
3582 } break;
3584 case MP_CMD_GET_PERCENT_POS : {
3585 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsPercentPos, demuxer_get_percent_pos(demuxer));
3586 } break;
3587 case MP_CMD_GET_TIME_POS : {
3588 float pos = 0;
3589 if (sh_video)
3590 pos = sh_video->pts;
3591 else
3592 if (sh_audio && audio_out)
3593 pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
3594 mp_msg(MSGT_GLOBAL, MSGL_INFO, MSGTR_AnsTimePos, pos);
3595 } break;
3596 case MP_CMD_SWITCH_AUDIO : {
3597 int v = demuxer_switch_audio(demuxer, cmd->args[0].v.i);
3598 if (identify)
3599 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", v);
3600 } break;
3601 case MP_CMD_RUN : {
3602 #ifndef __MINGW32__
3603 if(!fork()) {
3604 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
3605 exit(0);
3607 #endif
3608 } break;
3610 #ifdef USE_DVDNAV
3611 case MP_CMD_DVDNAV_EVENT: {
3612 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3613 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3615 /* ignore these events if we're not in dvd_nav mode */
3616 if (stream->type != STREAMTYPE_DVDNAV) break;
3618 if (!dvdnav_event) {
3619 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNullEvent);
3620 break;
3623 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3625 switch (dvdnav_event->event) {
3626 case DVDNAV_BLOCK_OK: {
3627 /* be silent about this one */
3628 break;
3630 case DVDNAV_HIGHLIGHT: {
3631 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3632 if (!hevent) {
3633 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightEventBroken);
3634 break;
3637 if (hevent->display && hevent->buttonN>0)
3639 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3640 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3641 hevent->buttonN,
3642 hevent->sx,hevent->sy,
3643 hevent->ex,hevent->ey,
3644 hevent->pts, d_video->pts);
3645 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavEvent,dvd_nav_text);
3646 //osd_show_dvd_nav_delay = 60;
3648 osd_show_dvd_nav_highlight=1;
3649 osd_show_dvd_nav_sx=hevent->sx;
3650 osd_show_dvd_nav_ex=hevent->ex;
3651 osd_show_dvd_nav_sy=hevent->sy;
3652 osd_show_dvd_nav_ey=hevent->ey;
3654 else {
3655 osd_show_dvd_nav_highlight=0;
3656 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightHide);
3658 break;
3660 case DVDNAV_STILL_FRAME: {
3661 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3663 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavStillFrame, still_event->length );
3664 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3665 usec_sleep(1000); /* 1ms */
3667 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3668 break;
3670 case DVDNAV_STOP: {
3671 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavStop );
3672 break;
3674 case DVDNAV_NOP: {
3675 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavNOP);
3676 break;
3678 case DVDNAV_SPU_STREAM_CHANGE: {
3679 #if DVDNAVVERSION > 012
3680 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3682 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChangeVerbose,
3683 stream_change->physical_wide,
3684 stream_change->physical_letterbox,
3685 stream_change->physical_pan_scan,
3686 stream_change->logical);
3688 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3689 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3690 d_dvdsub->id,stream_change->physical_wide);
3691 // FIXME: need a better way to change SPU id
3692 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3693 if (vo_spudec) spudec_reset(vo_spudec);
3695 #else
3696 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3698 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChange,
3699 stream_change->physical,
3700 stream_change->logical);
3702 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3703 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3704 d_dvdsub->id,stream_change->physical);
3705 // FIXME: need a better way to change SPU id
3706 d_dvdsub->id=dvdsub_id=stream_change->physical;
3707 if (vo_spudec) spudec_reset(vo_spudec);
3709 #endif
3710 break;
3712 case DVDNAV_AUDIO_STREAM_CHANGE: {
3713 int aid_temp;
3714 #if DVDNAVVERSION > 012
3715 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3716 #else
3717 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3718 #endif
3720 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavAudioStreamChange,
3721 stream_change->physical,
3722 stream_change->logical);
3724 aid_temp=stream_change->physical;
3725 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3726 if (d_audio && audio_id!=aid_temp) {
3727 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3728 d_audio->id,aid_temp);
3729 // FIXME: need a bettery way to change audio stream id
3730 d_audio->id=dvdsub_id=aid_temp;
3731 if(sh_audio) resync_audio_stream(sh_audio);
3734 break;
3736 case DVDNAV_VTS_CHANGE: {
3737 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavVTSChange);
3738 break;
3740 case DVDNAV_CELL_CHANGE: {
3741 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3742 cell_playback_t * cell_playback = cell_change->new_cell;
3744 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavCellChange);
3745 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3747 printf("new still time: %d\n",cell_playback->still_time);
3748 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3749 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3750 cell_playback->playback_time.hour,
3751 cell_playback->playback_time.minute,
3752 cell_playback->playback_time.second,
3753 cell_playback->playback_time.frame_u);
3756 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3757 //abs_seek_pos=0;
3758 break;
3760 case DVDNAV_NAV_PACKET: {
3761 // printf("DVDNAV Event: Nav Packet\n");
3762 break;
3764 case DVDNAV_SPU_CLUT_CHANGE: {
3765 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3767 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuClutChange);
3768 // send new palette to SPU decoder
3769 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3771 break;
3773 case DVDNAV_SEEK_DONE: {
3774 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSeekDone);
3775 break;
3779 // free the dvdnav event
3780 free(dvdnav_event->details);
3781 free(dvdnav_event);
3782 cmd->args[0].v.v=NULL;
3784 case MP_CMD_DVDNAV: {
3785 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3787 /* ignore these events if we're not in dvd_nav mode */
3788 if (stream->type != STREAMTYPE_DVDNAV) break;
3790 switch (cmd->args[0].v.i) {
3791 case MP_CMD_DVDNAV_UP:
3792 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3793 break;
3794 case MP_CMD_DVDNAV_DOWN:
3795 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3796 break;
3797 case MP_CMD_DVDNAV_LEFT:
3798 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3799 break;
3800 case MP_CMD_DVDNAV_RIGHT:
3801 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3802 break;
3803 case MP_CMD_DVDNAV_MENU:
3804 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_MenuCall);
3805 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3806 break;
3807 case MP_CMD_DVDNAV_SELECT:
3808 dvdnav_button_activate(dvdnav_priv->dvdnav);
3809 break;
3810 default:
3811 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3812 break;
3814 break;
3816 #endif
3817 default : {
3818 #ifdef HAVE_NEW_GUI
3819 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3820 else
3821 #endif
3822 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3825 if (cmd->pausing)
3826 osd_function = OSD_PAUSE;
3827 mp_cmd_free(cmd);
3831 if (seek_to_sec) {
3832 int a,b; float d;
3834 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3835 rel_seek_secs += 3600*a +60*b +d ;
3836 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3837 rel_seek_secs += 60*a +d;
3838 else if (sscanf(seek_to_sec, "%f", &d)==1)
3839 rel_seek_secs += d;
3841 seek_to_sec = NULL;
3844 /* Looping. */
3845 if(eof==1 && loop_times>=0) {
3846 int l = loop_times;
3847 play_tree_iter_step(playtree_iter,0,0);
3848 loop_times = l;
3849 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3851 if(loop_times>1) loop_times--; else
3852 if(loop_times==1) loop_times=-1;
3853 play_n_frames=play_n_frames_mf;
3854 eof=0;
3855 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3856 loop_seek = 1;
3859 if(rel_seek_secs || abs_seek_pos){
3860 current_module="seek";
3861 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3862 // success:
3863 /* FIXME there should be real seeking for vobsub */
3864 if(sh_video) sh_video->pts=d_video->pts;
3865 if (vo_vobsub)
3866 //vobsub_reset(vo_vobsub);
3867 vobsub_seek(vo_vobsub,sh_video->pts);
3868 #if 0
3869 if(sh_video && d_video->packs == 0)
3870 ds_fill_buffer(d_video);
3871 if(sh_audio){
3872 if(d_audio->packs == 0)
3873 ds_fill_buffer(d_audio);
3874 if(verbose>0){
3875 float a_pts=d_audio->pts;
3876 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3877 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);
3879 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);
3880 } else {
3881 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3883 #endif
3884 fflush(stdout);
3886 if(sh_video){
3887 current_module="seek_video_reset";
3888 resync_video_stream(sh_video);
3889 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3892 if(sh_audio){
3893 current_module="seek_audio_reset";
3894 audio_out->reset(); // stop audio, throwing away buffered data
3896 #ifdef USE_OSD
3897 // Set OSD:
3898 if(osd_level && !loop_seek){
3899 #ifdef USE_EDL
3900 if( !edl_decision ) {
3901 #else
3902 if( 1 ) { // Let the compiler optimize this out
3903 #endif
3904 if (sh_video) {
3905 osd_visible=sh_video->fps; // 1 sec
3906 vo_osd_progbar_type=0;
3907 vo_osd_progbar_value=demuxer_get_percent_pos(demuxer) * 256 / 100;
3908 vo_osd_changed(OSDTYPE_PROGBAR);
3912 #endif
3913 if(sh_video) {
3914 c_total=0;
3915 max_pts_correction=0.1;
3916 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3917 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3918 drop_frame_cnt=0;
3919 too_slow_frame_cnt=0;
3920 too_fast_frame_cnt=0;
3922 if(vo_spudec) spudec_reset(vo_spudec);
3925 #ifdef USE_EDL
3927 * We saw a seek, have to rewind the EDL operations stack
3928 * and find the next EDL action to take care of.
3931 edl_muted = 0;
3932 next_edl_record = edl_records;
3934 while (next_edl_record)
3936 /* Trying to remember if we need to mute/unmute first;
3937 * prior EDL implementation lacks this.
3940 if (next_edl_record->start_sec >= sh_video->pts)
3941 break;
3943 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
3944 next_edl_record = next_edl_record->next;
3947 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
3948 #endif
3949 rel_seek_secs=0;
3950 abs_seek_pos=0;
3951 frame_time_remaining=0;
3952 current_module=NULL;
3953 loop_seek=0;
3956 #ifdef HAVE_NEW_GUI
3957 if(use_gui){
3958 guiEventHandling();
3959 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3960 // get pos from frame number / total frames
3961 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3962 } else {
3963 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3964 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3965 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3967 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3968 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3969 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3970 guiGetEvent( guiReDraw,NULL );
3971 guiGetEvent( guiSetVolume,NULL );
3972 if(guiIntfStruct.Playing==0) break; // STOP
3973 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3974 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3975 #ifdef USE_DVDREAD
3976 if ( stream->type == STREAMTYPE_DVD )
3978 dvd_priv_t * dvdp = stream->priv;
3979 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3981 #endif
3983 #endif
3986 //================= Update OSD ====================
3987 #ifdef USE_OSD
3988 if(osd_level>=1 && sh_video){
3989 int pts=sh_video->pts;
3990 char osd_text_tmp[64];
3991 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
3992 vo_osd_text=osd_text_buffer;
3993 #ifdef USE_DVDNAV
3994 if (osd_show_dvd_nav_delay) {
3995 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
3996 osd_show_dvd_nav_delay--;
3997 } else
3998 #endif
3999 #ifdef USE_TV
4000 if (osd_show_tv_channel && tv_channel_list) {
4001 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
4002 osd_show_tv_channel--;
4003 } else
4004 #endif
4005 if (osd_show_text) {
4006 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
4007 osd_show_text--;
4008 } else
4009 if (osd_show_sub_visibility) {
4010 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
4011 osd_show_sub_visibility--;
4012 } else
4013 if (osd_show_vobsub_changed) {
4014 snprintf(osd_text_tmp, 63, "Subtitles: off");
4015 if (vo_vobsub && vobsub_id >= 0) {
4016 const char *language = "none";
4017 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
4018 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
4020 #ifdef HAVE_OGGVORBIS
4021 if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG) {
4022 if (dvdsub_id >= 0) {
4023 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
4024 if (!lang) lang = "unknown";
4025 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4028 #endif
4029 #ifdef USE_DVDREAD
4030 if (vo_spudec && (demuxer->type != DEMUXER_TYPE_MATROSKA)) {
4031 if (dvdsub_id >= 0) {
4032 char lang[5] = "none";
4033 int code = 0;
4034 code = dvd_lang_from_sid(stream, dvdsub_id);
4035 if (code) {
4036 lang[0] = code >> 8;
4037 lang[1] = code;
4038 lang[2] = 0;
4040 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4043 #endif
4044 #ifdef HAVE_MATROSKA
4045 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
4046 char lang[10] = "unknown";
4047 if (dvdsub_id >= 0) {
4048 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
4049 lang[9] = 0;
4050 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
4053 #endif
4054 osd_show_vobsub_changed--;
4055 } else
4056 #ifdef USE_SUB
4057 if (osd_show_sub_changed) {
4058 char *tmp2;
4059 tmp = subdata->filename;
4060 if ((tmp2 = strrchr(tmp, '/'))) {
4061 tmp = tmp2+1;
4063 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
4064 set_of_sub_pos + 1,
4065 strlen(tmp) < 20 ? "" : "...",
4066 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
4067 osd_show_sub_changed--;
4068 } else
4069 #endif
4070 if (osd_show_sub_delay) {
4071 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
4072 osd_show_sub_delay--;
4073 } else
4074 if (osd_show_sub_pos) {
4075 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
4076 osd_show_sub_pos--;
4077 } else
4078 if (osd_show_sub_alignment) {
4079 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
4080 (sub_alignment == 2 ? "bottom" :
4081 (sub_alignment == 1 ? "center" : "top")));
4082 osd_show_sub_alignment--;
4083 } else
4084 if (osd_show_av_delay) {
4085 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
4086 osd_show_av_delay--;
4087 } else if (osd_show_speed) {
4088 snprintf(osd_text_tmp, 63, "Speed: x %6.2f", playback_speed);
4089 osd_show_speed--;
4090 } else if (osd_show_ontop) {
4091 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
4092 osd_show_ontop--;
4093 } else if (osd_show_rootwin) {
4094 snprintf(osd_text_tmp, 63, "Rootwin: %sabled", vo_rootwin?"en":"dis");
4095 osd_show_rootwin--;
4096 } else if (osd_show_framedropping) {
4097 snprintf(osd_text_tmp, 63, "Framedropping: %s",
4098 (frame_dropping == 1 ? "on" :
4099 (frame_dropping == 2 ? "hard" : "off")));
4100 osd_show_framedropping--;
4101 } else if(osd_level>=2) {
4102 int len = demuxer_get_time_length(demuxer);
4103 int percentage = -1;
4104 char percentage_text[10];
4105 if (osd_show_percentage) {
4106 percentage = demuxer_get_percent_pos(demuxer);
4107 osd_show_percentage--;
4109 if (percentage >= 0)
4110 snprintf(percentage_text, 9, " (%d%%)", percentage);
4111 else
4112 percentage_text[0] = 0;
4113 if (osd_level == 3)
4114 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);
4115 else
4116 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
4117 } else osd_text_tmp[0]=0;
4119 if(strcmp(vo_osd_text, osd_text_tmp)) {
4120 strncpy(vo_osd_text, osd_text_tmp, 63);
4121 vo_osd_changed(OSDTYPE_OSD);
4123 } else {
4124 if(vo_osd_text) {
4125 vo_osd_text=NULL;
4126 vo_osd_changed(OSDTYPE_OSD);
4129 if (osd_level <= 1 && osd_show_status > 0 && sh_video) {
4130 vo_osd_text = osd_text_buffer;
4131 snprintf(vo_osd_text, 63, "OSD: %sabled", osd_level ? "en" : "dis");
4132 vo_osd_changed(OSDTYPE_OSD);
4133 osd_show_status--;
4135 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
4136 // vo_osd_text=osd_text_buffer;
4137 #endif
4139 #ifdef USE_SUB
4140 // find sub
4141 if(subdata && sh_video && sh_video->pts>0){
4142 float pts=sh_video->pts;
4143 if(sub_fps==0) sub_fps=sh_video->fps;
4144 current_module="find_sub";
4145 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
4146 find_sub(subdata, (pts+sub_delay) *
4147 (subdata->sub_uses_time ? 100. : sub_fps));
4148 if (vo_sub) vo_sub_last = vo_sub;
4149 // FIXME! frame counter...
4150 sub_last_pts = pts;
4152 current_module=NULL;
4154 #endif
4156 #ifdef HAVE_X11
4157 if (stop_xscreensaver && sh_video) {
4158 current_module="stop_xscreensaver";
4159 xscreensaver_heartbeat();
4160 current_module=NULL;
4162 #endif
4164 // DVD sub:
4165 if(vo_config_count && vo_spudec) {
4166 unsigned char* packet=NULL;
4167 int len,timestamp;
4168 current_module="spudec";
4169 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
4170 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
4171 while(1) {
4172 // Vobsub
4173 len = 0;
4174 if(vo_vobsub) {
4175 if(sh_video->pts+sub_delay>=0) {
4176 // The + next_frame_time is there because we'll display the sub at the next frame
4177 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
4178 if(len > 0) {
4179 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
4180 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);
4183 } else {
4184 // DVD sub
4185 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
4186 if(len > 0) {
4187 float x = d_dvdsub->pts - sh_video->pts;
4188 if (x < -10 || x > 10) // prevent missing subs on pts reset
4189 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
4190 else timestamp = 90000*(sh_video->timer + sub_delay);
4191 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);
4194 if(len<=0 || !packet) break;
4195 if(timestamp < 0) timestamp = 0;
4196 else spudec_assemble(vo_spudec,packet,len,timestamp);
4199 /* detect wether the sub has changed or not */
4200 if(spudec_changed(vo_spudec))
4201 vo_osd_changed(OSDTYPE_SPU);
4202 current_module=NULL;
4205 } // while(!eof)
4207 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
4211 goto_next_file: // don't jump here after ao/vo/getch initialization!
4213 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
4215 if(benchmark){
4216 double tot=video_time_usage+vout_time_usage+audio_time_usage;
4217 double total_time_usage;
4218 total_time_usage_start=GetTimer()-total_time_usage_start;
4219 total_time_usage = (float)total_time_usage_start*0.000001;
4220 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4221 video_time_usage,vout_time_usage,audio_time_usage,
4222 total_time_usage-tot,total_time_usage);
4223 if(total_time_usage>0.0)
4224 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4225 100.0*video_time_usage/total_time_usage,
4226 100.0*vout_time_usage/total_time_usage,
4227 100.0*audio_time_usage/total_time_usage,
4228 100.0*(total_time_usage-tot)/total_time_usage,
4229 100.0);
4230 if(total_frame_cnt && frame_dropping)
4231 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4232 total_frame_cnt-drop_frame_cnt,
4233 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
4234 drop_frame_cnt,
4235 100*drop_frame_cnt/total_frame_cnt,
4236 total_frame_cnt,
4237 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
4241 // time to uninit all, except global stuff:
4242 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
4244 #ifdef USE_SUB
4245 if ( set_of_sub_size > 0 )
4247 current_module="sub_free";
4248 for (i = 0; i < set_of_sub_size; ++i)
4249 sub_free( set_of_subtitles[i] );
4250 set_of_sub_size = 0;
4251 vo_sub_last = vo_sub=NULL;
4252 subdata=NULL;
4254 #endif
4256 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
4257 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
4258 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
4259 eof = 1;
4260 } else {
4261 play_tree_iter_free(playtree_iter);
4262 playtree_iter = NULL;
4264 play_tree_step = 1;
4265 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
4266 eof = eof == PT_UP_NEXT ? 1 : -1;
4267 if ( playtree_iter ) {
4268 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
4269 eof = 1;
4270 } else {
4271 play_tree_iter_free(playtree_iter);
4272 playtree_iter = NULL;
4275 } else { // NEXT PREV SRC
4276 eof = eof == PT_PREV_SRC ? -1 : 1;
4279 if(eof == 0) eof = 1;
4281 while(playtree_iter != NULL) {
4282 filename = play_tree_iter_get_file(playtree_iter,eof);
4283 if(filename == NULL) {
4284 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
4285 play_tree_iter_free(playtree_iter);
4286 playtree_iter = NULL;
4288 } else
4289 break;
4292 #ifdef HAVE_NEW_GUI
4293 if( use_gui && !playtree_iter )
4295 #ifdef USE_DVDREAD
4296 if ( !guiIntfStruct.DiskChanged )
4297 #endif
4298 mplEnd();
4300 #endif
4302 if(use_gui || playtree_iter != NULL){
4304 eof = 0;
4305 goto play_next_file;
4309 exit_player_with_rc(MSGTR_Exit_eof, 0);
4311 return 1;