disable all unknown formats in the windows aos
[mplayer/greg.git] / mplayer.c
blobfb47735c56aa53b6256853a7f61423ed611c26af
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "config.h"
5 #ifdef WIN32
6 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
7 #include <windows.h>
8 #endif
9 #include <string.h>
10 #include <unistd.h>
12 // #include <sys/mman.h>
13 #include <sys/types.h>
14 #ifndef __MINGW32__
15 #include <sys/ioctl.h>
16 #include <sys/wait.h>
17 #else
18 #define SIGHUP 1 /* hangup */
19 #define SIGQUIT 3 /* quit */
20 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
21 #define SIGBUS 10 /* bus error */
22 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
23 #endif
25 #include <sys/time.h>
26 #include <sys/stat.h>
28 #include <signal.h>
29 #include <time.h>
30 #include <fcntl.h>
31 #include <limits.h>
33 #include <errno.h>
35 #include "version.h"
37 #include "mp_msg.h"
39 #define HELP_MP_DEFINE_STATIC
40 #include "help_mp.h"
42 #include "m_option.h"
43 #include "m_config.h"
45 #include "cfg-mplayer-def.h"
47 #ifdef USE_SUB
48 #include "subreader.h"
49 #endif
51 #include "libvo/video_out.h"
53 #include "libvo/font_load.h"
54 #include "libvo/sub.h"
56 #ifdef HAVE_X11
57 #include "libvo/x11_common.h"
58 #endif
60 #include "libao2/audio_out.h"
61 #include "libao2/audio_plugin.h"
63 #include "codec-cfg.h"
65 #ifdef USE_DVDNAV
66 #include <dvdnav.h>
67 #endif
69 #ifdef USE_EDL
70 #include "edl.h"
71 #endif
73 #include "spudec.h"
74 #include "vobsub.h"
76 #include "osdep/getch2.h"
77 #include "osdep/timer.h"
79 #include "cpudetect.h"
81 #ifdef HAVE_NEW_GUI
82 #include "Gui/interface.h"
83 #endif
85 #include "input/input.h"
87 int slave_mode=0;
88 int verbose=0;
89 int identify=0;
90 int quiet=0;
92 #define ABS(x) (((x)>=0)?(x):(-(x)))
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
95 #ifdef HAVE_RTC
96 #include <linux/rtc.h>
97 #endif
99 #ifdef USE_TV
100 #include "libmpdemux/tv.h"
101 #endif
103 #ifdef HAS_DVBIN_SUPPORT
104 #include "libmpdemux/dvbin.h"
105 static int last_dvb_step = 1;
106 #endif
108 //**************************************************************************//
109 // Playtree
110 //**************************************************************************//
111 #include "playtree.h"
112 #include "playtreeparser.h"
114 #ifdef HAVE_NEW_GUI
115 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
116 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
117 #endif
119 play_tree_t* playtree;
120 play_tree_iter_t* playtree_iter = NULL;
122 #define PT_NEXT_ENTRY 1
123 #define PT_PREV_ENTRY -1
124 #define PT_NEXT_SRC 2
125 #define PT_PREV_SRC -2
126 #define PT_UP_NEXT 3
127 #define PT_UP_PREV -3
129 //**************************************************************************//
130 // Config
131 //**************************************************************************//
132 m_config_t* mconfig;
134 extern play_tree_t*
135 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
136 extern int
137 m_config_parse_config_file(m_config_t* config, char *conffile);
139 //**************************************************************************//
140 // Config file
141 //**************************************************************************//
143 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
145 static int cfg_include(m_option_t *conf, char *filename){
146 return m_config_parse_config_file(mconfig, filename);
149 #include "get_path.c"
151 //**************************************************************************//
152 // XScreensaver
153 //**************************************************************************//
155 #ifdef HAVE_X11
156 void xscreensaver_heartbeat(void);
157 #endif
159 //**************************************************************************//
160 //**************************************************************************//
161 // Input media streaming & demultiplexer:
162 //**************************************************************************//
164 static int max_framesize=0;
166 #include "libmpdemux/stream.h"
167 #include "libmpdemux/demuxer.h"
168 #include "libmpdemux/stheader.h"
169 //#include "parse_es.h"
170 #ifdef HAVE_MATROSKA
171 #include "libmpdemux/matroska.h"
172 #endif
174 #include "libmpcodecs/dec_audio.h"
175 #include "libmpcodecs/dec_video.h"
176 #include "libmpcodecs/mp_image.h"
177 #include "libmpcodecs/vf.h"
179 extern void vf_list_plugins();
181 //**************************************************************************//
182 //**************************************************************************//
184 // Common FIFO functions, and keyboard/event FIFO code
185 #include "fifo.c"
186 int noconsolecontrols=0;
187 //**************************************************************************//
189 vo_functions_t *video_out=NULL;
190 ao_functions_t *audio_out=NULL;
192 int fixed_vo=0;
193 int eof=0;
195 // benchmark:
196 double video_time_usage=0;
197 double vout_time_usage=0;
198 static double audio_time_usage=0;
199 static int total_time_usage_start=0;
200 static int total_frame_cnt=0;
201 static int drop_frame_cnt=0; // total number of dropped frames
202 int benchmark=0;
204 // options:
205 int auto_quality=0;
206 static int output_quality=0;
208 float playback_speed=1.0;
210 int use_gui=0;
212 #ifdef HAVE_NEW_GUI
213 int enqueue=0;
214 #endif
216 #define MAX_OSD_LEVEL 3
218 int osd_level=1;
219 int osd_level_saved=-1;
220 int osd_visible=100;
222 // seek:
223 static char *seek_to_sec=NULL;
224 static off_t seek_to_byte=0;
225 static off_t step_sec=0;
226 static int loop_times=-1;
227 static int loop_seek=0;
229 // A/V sync:
230 int autosync=0; // 30 might be a good default value.
232 // may be changed by GUI: (FIXME!)
233 float rel_seek_secs=0;
234 int abs_seek_pos=0;
236 // codecs:
237 char **audio_codec_list=NULL; // override audio codec
238 char **video_codec_list=NULL; // override video codec
239 char **audio_fm_list=NULL; // override audio codec family
240 char **video_fm_list=NULL; // override video codec family
242 // streaming:
243 int audio_id=-1;
244 int video_id=-1;
245 int dvdsub_id=-1;
246 int vobsub_id=-1;
247 char* audio_lang=NULL;
248 char* dvdsub_lang=NULL;
249 static char* spudec_ifo=NULL;
250 char* filename=NULL; //"MI2-Trailer.avi";
251 int forced_subs_only=0;
253 // cache2:
254 int stream_cache_size=-1;
255 #ifdef USE_STREAM_CACHE
256 extern int cache_fill_status;
258 float stream_cache_min_percent=20.0;
259 float stream_cache_prefill_percent=5.0;
260 #else
261 #define cache_fill_status 0
262 #endif
264 // dump:
265 static char *stream_dump_name="stream.dump";
266 int stream_dump_type=0;
268 // A-V sync:
269 static float default_max_pts_correction=-1;//0.01f;
270 static float max_pts_correction=0;//default_max_pts_correction;
271 static float c_total=0;
272 float audio_delay=0;
274 static int softsleep=0;
276 float force_fps=0;
277 static int force_srate=0;
278 static int audio_output_format=0;
279 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
280 static int play_n_frames=-1;
281 static int play_n_frames_mf=-1;
283 // screen info:
284 char** video_driver_list=NULL;
285 char** audio_driver_list=NULL;
287 extern char *vo_subdevice;
288 extern char *ao_subdevice;
290 // codec outfmt flags (defined in libmpcodecs/vd.c)
291 extern int vo_flags;
293 // sub:
294 char *font_name=NULL;
295 #ifdef HAVE_FONTCONFIG
296 extern int font_fontconfig;
297 #endif
298 float font_factor=0.75;
299 char **sub_name=NULL;
300 float sub_delay=0;
301 float sub_fps=0;
302 int sub_auto = 1;
303 char *vobsub_name=NULL;
304 /*DSP!!char *dsp=NULL;*/
305 int subcc_enabled=0;
306 int suboverlap_enabled = 1;
307 #ifdef USE_SUB
308 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
309 int set_of_sub_size = 0;
310 int set_of_sub_pos = -1;
311 float sub_last_pts = -303;
312 #endif
313 int global_sub_size = 0; // this encompasses all subtitle sources
314 int global_sub_pos = -1; // this encompasses all subtitle sources
315 #define SUB_SOURCE_SUBS 0
316 #define SUB_SOURCE_VOBSUB 1
317 #define SUB_SOURCE_DEMUX 2
318 #define SUB_SOURCES 3
319 int global_sub_indices[SUB_SOURCES];
320 int global_sub_quiet_osd_hack = 0;
322 static stream_t* stream=NULL;
323 static demuxer_t *demuxer=NULL;
324 static sh_audio_t *sh_audio=NULL;
325 static sh_video_t *sh_video=NULL;
327 char* current_module=NULL; // for debugging
329 extern int vo_gamma_gamma;
330 extern int vo_gamma_brightness;
331 extern int vo_gamma_contrast;
332 extern int vo_gamma_saturation;
333 extern int vo_gamma_hue;
335 // ---
337 #ifdef HAVE_MENU
338 #include "m_struct.h"
339 #include "libmenu/menu.h"
340 extern void vf_menu_pause_update(struct vf_instance_s* vf);
341 extern vf_info_t vf_info_menu;
342 static vf_info_t* libmenu_vfs[] = {
343 &vf_info_menu,
344 NULL
346 static vf_instance_t* vf_menu = NULL;
347 static int use_menu = 0;
348 static char* menu_cfg = NULL;
349 static char* menu_root = "main";
350 #endif
353 #ifdef HAVE_RTC
354 static int nortc;
355 static char* rtc_device;
356 #endif
358 #ifdef USE_EDL
359 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
360 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
361 int edl_memory_slots = 0; ///< number of EDL entries (1 for skip + 2 for each mute)
362 int edl_operations = 0; ///< number of EDL operations, skip + mute
363 short user_muted = 0; ///< Stores whether User wanted muted mode.
364 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
365 short edl_decision = 0; ///< 1 when an EDL operation has been made
366 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode
367 #endif
369 static unsigned int inited_flags=0;
370 #define INITED_VO 1
371 #define INITED_AO 2
372 #define INITED_GUI 4
373 #define INITED_GETCH2 8
374 #define INITED_SPUDEC 32
375 #define INITED_STREAM 64
376 #define INITED_INPUT 128
377 #define INITED_VOBSUB 256
378 #define INITED_DEMUXER 512
379 #define INITED_ACODEC 1024
380 #define INITED_VCODEC 2048
381 #define INITED_ALL 0xFFFF
383 static void uninit_player(unsigned int mask){
384 mask=inited_flags&mask;
386 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
388 if(mask&INITED_ACODEC){
389 inited_flags&=~INITED_ACODEC;
390 current_module="uninit_acodec";
391 if(sh_audio) uninit_audio(sh_audio);
392 sh_audio=NULL;
395 if(mask&INITED_VCODEC){
396 inited_flags&=~INITED_VCODEC;
397 current_module="uninit_vcodec";
398 if(sh_video) uninit_video(sh_video);
399 sh_video=NULL;
400 #ifdef HAVE_MENU
401 vf_menu=NULL;
402 #endif
405 if(mask&INITED_DEMUXER){
406 inited_flags&=~INITED_DEMUXER;
407 current_module="free_demuxer";
408 if(demuxer){
409 stream=demuxer->stream;
410 free_demuxer(demuxer);
412 demuxer=NULL;
415 // kill the cache process:
416 if(mask&INITED_STREAM){
417 inited_flags&=~INITED_STREAM;
418 current_module="uninit_stream";
419 if(stream) free_stream(stream);
420 stream=NULL;
423 if(mask&INITED_VO){
424 inited_flags&=~INITED_VO;
425 current_module="uninit_vo";
426 video_out->uninit();
427 video_out=NULL;
430 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
431 if(mask&INITED_GETCH2){
432 inited_flags&=~INITED_GETCH2;
433 current_module="uninit_getch2";
434 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
435 // restore terminal:
436 getch2_disable();
439 if(mask&INITED_VOBSUB){
440 inited_flags&=~INITED_VOBSUB;
441 current_module="uninit_vobsub";
442 if(vo_vobsub) vobsub_close(vo_vobsub);
443 vo_vobsub=NULL;
446 if (mask&INITED_SPUDEC){
447 inited_flags&=~INITED_SPUDEC;
448 current_module="uninit_spudec";
449 spudec_free(vo_spudec);
450 vo_spudec=NULL;
453 if(mask&INITED_AO){
454 inited_flags&=~INITED_AO;
455 current_module="uninit_ao";
456 audio_out->uninit(eof?0:1); audio_out=NULL;
459 #ifdef HAVE_NEW_GUI
460 if(mask&INITED_GUI){
461 inited_flags&=~INITED_GUI;
462 current_module="uninit_gui";
463 guiDone();
465 #endif
467 if(mask&INITED_INPUT){
468 inited_flags&=~INITED_INPUT;
469 current_module="uninit_input";
470 mp_input_uninit();
473 current_module=NULL;
476 static void exit_player_with_rc(char* how, int rc){
478 uninit_player(INITED_ALL);
479 #ifdef HAVE_X11
480 #ifdef HAVE_NEW_GUI
481 if ( !use_gui )
482 #endif
483 vo_uninit(); // close the X11 connection (if any opened)
484 #endif
486 #ifdef HAVE_FREETYPE
487 current_module="uninit_font";
488 if (vo_font) free_font_desc(vo_font);
489 vo_font = NULL;
490 done_freetype();
491 #endif
493 current_module="exit_player";
495 // free mplayer config
496 free(mconfig);
498 #ifdef USE_EDL
499 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
500 #endif
501 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));
502 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
504 exit(rc);
507 void exit_player(char* how){
508 exit_player_with_rc(how, 1);
511 #ifndef __MINGW32__
512 static void child_sighandler(int x){
513 pid_t pid;
514 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
516 #endif
518 #ifdef CRASH_DEBUG
519 static char *prog_path;
520 static int crash_debug = 0;
521 #endif
523 static void exit_sighandler(int x){
524 static int sig_count=0;
525 #ifdef CRASH_DEBUG
526 if (!crash_debug || x != SIGTRAP)
527 #endif
528 ++sig_count;
529 if(inited_flags==0 && sig_count>1) exit(1);
530 if(sig_count==5)
532 /* We're crashing bad and can't uninit cleanly :(
533 * by popular request, we make one last (dirty)
534 * effort to restore the user's
535 * terminal. */
536 getch2_disable();
537 exit(1);
539 if(sig_count==6) exit(1);
540 if(sig_count>6){
541 // can't stop :(
542 #ifndef __MINGW32__
543 kill(getpid(),SIGKILL);
544 #endif
546 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
547 current_module?current_module:mp_gettext("unknown")
549 if(sig_count<=1)
550 switch(x){
551 case SIGINT:
552 case SIGQUIT:
553 case SIGTERM:
554 case SIGKILL:
555 break; // killed from keyboard (^C) or killed [-9]
556 case SIGILL:
557 #ifdef RUNTIME_CPUDETECT
558 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
559 #else
560 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
561 #endif
562 case SIGFPE:
563 case SIGSEGV:
564 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
565 default:
566 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
567 #ifdef CRASH_DEBUG
568 if (crash_debug) {
569 int gdb_pid;
570 char spid[20];
571 snprintf(spid, 19, "%i", getpid());
572 spid[19] = 0;
573 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
574 gdb_pid = fork();
575 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
576 if (gdb_pid == 0) { // We are the child
577 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
578 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
579 } else if (gdb_pid < 0)
580 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
581 else {
582 waitpid(gdb_pid, NULL, 0);
584 if (x == SIGTRAP) return;
586 #endif
588 exit_player(NULL);
591 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
593 extern void mp_input_register_options(m_config_t* cfg);
595 #include "mixer.h"
596 mixer_t mixer;
597 /// step size of mixer changes
598 int volstep = 3;
600 #include "cfg-mplayer.h"
602 void parse_cfgfiles( m_config_t* conf )
604 char *conffile;
605 int conffile_fd;
606 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
607 exit_player(NULL);
608 if ((conffile = get_path("")) == NULL) {
609 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
610 } else {
611 #ifdef __MINGW32__
612 mkdir(conffile);
613 #else
614 mkdir(conffile, 0777);
615 #endif
616 free(conffile);
617 if ((conffile = get_path("config")) == NULL) {
618 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
619 } else {
620 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
621 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
622 write(conffile_fd, default_config, strlen(default_config));
623 close(conffile_fd);
625 if (m_config_parse_config_file(conf, conffile) < 0)
626 exit_player(NULL);
627 free(conffile);
632 void load_per_file_config (m_config_t* conf, const char *const file)
634 char *confpath;
635 char cfg[strlen(file)+10];
636 struct stat st;
637 char *name;
639 sprintf (cfg, "%s.conf", file);
641 if (!stat (cfg, &st))
643 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
644 m_config_parse_config_file (conf, cfg);
645 return;
648 if ((name = strrchr (cfg, '/')) == NULL)
649 name = cfg;
650 else
651 name++;
653 if ((confpath = get_path (name)) != NULL)
655 if (!stat (confpath, &st))
657 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
658 m_config_parse_config_file (conf, confpath);
661 free (confpath);
665 // When libmpdemux perform a blocking operation (network connection or cache filling)
666 // if the operation fail we use this function to check if it was interrupted by the user.
667 // The function return a new value for eof.
668 static int libmpdemux_was_interrupted(int eof) {
669 mp_cmd_t* cmd;
670 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
671 switch(cmd->id) {
672 case MP_CMD_QUIT:
673 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
674 case MP_CMD_PLAY_TREE_STEP: {
675 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
676 } break;
677 case MP_CMD_PLAY_TREE_UP_STEP: {
678 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
679 } break;
680 case MP_CMD_PLAY_ALT_SRC_STEP: {
681 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
682 } break;
684 mp_cmd_free(cmd);
686 return eof;
689 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
690 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
692 int playtree_add_playlist(play_tree_t* entry)
694 play_tree_add_bpf(entry,filename);
696 #ifdef HAVE_NEW_GUI
697 if (use_gui) {
698 if (entry) {
699 import_playtree_playlist_into_gui(entry, mconfig);
700 play_tree_free_list(entry,1);
702 } else
703 #endif
705 if(!entry) {
706 entry = playtree_iter->tree;
707 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
708 return PT_NEXT_ENTRY;
710 if(playtree_iter->tree == entry ) { // Loop with a single file
711 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
712 return PT_NEXT_ENTRY;
715 play_tree_remove(entry,1,1);
716 return PT_NEXT_SRC;
718 play_tree_insert_entry(playtree_iter->tree,entry);
719 play_tree_set_params_from(entry,playtree_iter->tree);
720 entry = playtree_iter->tree;
721 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
722 return PT_NEXT_ENTRY;
724 play_tree_remove(entry,1,1);
726 return PT_NEXT_SRC;
729 static int play_tree_step = 1;
731 int sub_source()
733 int source = -1;
734 int top = -1;
735 int i;
736 for (i = 0; i < SUB_SOURCES; i++) {
737 int j = global_sub_indices[i];
738 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
739 source = i;
740 top = j;
743 return source;
746 #ifdef USE_SUB
748 sub_data* subdata = NULL;
750 void add_subtitles(char *filename, float fps, int silent)
752 sub_data *subd;
754 if (filename == NULL) {
755 return;
758 subd = sub_read_file(filename, fps);
759 if(!subd && !silent)
760 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
761 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
762 set_of_subtitles[set_of_sub_size] = subd;
763 if (identify)
765 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
766 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
768 ++set_of_sub_size;
769 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
772 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
773 void update_set_of_subtitles()
774 // subdata was changed, set_of_sub... have to be updated.
776 int i;
777 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
778 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
779 set_of_subtitles[i-1] = set_of_subtitles[i];
780 set_of_subtitles[set_of_sub_size-1] = NULL;
781 --set_of_sub_size;
782 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
784 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
785 set_of_subtitles[set_of_sub_pos] = subdata;
787 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
788 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
789 ++set_of_sub_size;
792 #endif
795 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
796 * make it all work is to use the builtin SDL-bootstrap code, which
797 * will be done automatically by replacing our main() if we include SDL.h.
799 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
800 #include <SDL.h>
801 #endif
804 * \brief append a formatted string
805 * \param buf buffer to print into
806 * \param pos position of terminating 0 in buf
807 * \param len maximum number of characters in buf, not including terminating 0
808 * \param format printf format string
810 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
812 va_list va;
813 va_start(va, format);
814 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
815 va_end(va);
816 if (*pos >= len ) {
817 buf[len] = 0;
818 *pos = len;
823 * \brief print the status line
824 * \param a_pos audio position
825 * \param a_v A-V desynchronization
826 * \param corr amount out A-V synchronization
828 static void print_status(float a_pos, float a_v, float corr)
830 int width;
831 char *line;
832 unsigned pos = 0;
833 get_screen_size();
834 if (screen_width > 0)
835 width = screen_width;
836 else
837 width = 80;
838 #ifdef WIN32
839 // windows command line is broken (MinGW's rxvt works though, but we
840 // should not depend on that).
841 width--;
842 #endif
843 line = malloc(width + 1); // one additional for terminating null
845 // Audio time
846 if (sh_audio) {
847 saddf(line, &pos, width, "A:%6.1f ", a_pos);
848 if (!sh_video) {
849 // convert time to HH:MM:SS.F format
850 long tenths = 10 * a_pos;
851 int f1 = tenths % 10;
852 int ss = (tenths / 10) % 60;
853 int mm = (tenths / 600) % 60;
854 int hh = (tenths / 36000) % 100;
855 saddf(line, &pos, width, "(");
856 if (hh > 0)
857 saddf(line, &pos, width, "%2d:", hh);
858 if (hh > 0 || mm > 0)
859 saddf(line, &pos, width, "%02d:", mm);
860 saddf(line, &pos, width, "%02d.", ss);
861 saddf(line, &pos, width, "%1d", f1);
862 saddf(line, &pos, width, ") ");
866 // Video time
867 if (sh_video)
868 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
870 // A-V sync
871 if (sh_audio && sh_video)
872 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
874 // Video stats
875 if (sh_video)
876 saddf(line, &pos, width, "%3d/%3d ",
877 (int)sh_video->num_frames,
878 (int)sh_video->num_frames_decoded);
880 // CPU usage
881 if (sh_video) {
882 if (sh_video->timer > 0.5)
883 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
884 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
885 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
886 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
887 else
888 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
889 } else if (sh_audio) {
890 if (sh_audio->delay > 0.5)
891 saddf(line, &pos, width, "%4.1f%% ",
892 100.0*audio_time_usage/(double)sh_audio->delay);
893 else
894 saddf(line, &pos, width, "??,?%% ");
897 // VO stats
898 if (sh_video)
899 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
901 #ifdef USE_STREAM_CACHE
902 // cache stats
903 if (stream_cache_size > 0)
904 saddf(line, &pos, width, "%d%% ", cache_fill_status);
905 #endif
907 // other
908 if (playback_speed != 1)
909 saddf(line, &pos, width, "%4.2fx ", playback_speed);
911 // end
912 memset(&line[pos], ' ', width - pos);
913 line[width] = 0;
914 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
915 free(line);
919 * \brief build a chain of audio filters that converts the input format
920 * to the ao's format, taking into account the current playback_speed.
921 * \param sh_audio describes the requested input format of the chain.
922 * \param ao_data describes the requested output format of the chain.
924 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
926 int new_srate = sh_audio->samplerate * playback_speed;
927 if (!sh_audio)
928 return 0;
929 if (new_srate != ao_data->samplerate) {
930 // limits are taken from libaf/af_resample.c
931 if (new_srate < 8000)
932 new_srate = 8000;
933 if (new_srate > 192000)
934 new_srate = 192000;
935 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
937 return init_audio_filters(sh_audio, new_srate,
938 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
939 ao_data->samplerate, ao_data->channels, ao_data->format,
940 audio_out_format_bits(ao_data->format) / 8, /* ao_data.bps, */
941 ao_data->outburst * 4, ao_data->buffersize);
944 int main(int argc,char* argv[]){
947 char * mem_ptr;
949 static demux_stream_t *d_audio=NULL;
950 static demux_stream_t *d_video=NULL;
951 static demux_stream_t *d_dvdsub=NULL;
953 int file_format=DEMUXER_TYPE_UNKNOWN;
955 int delay_corrected=1;
957 // movie info:
959 int osd_function=OSD_PLAY;
960 int osd_last_pts=-303;
961 int osd_show_av_delay = 0;
962 int osd_show_text = 0;
963 int osd_show_speed = 0;
964 int osd_show_sub_delay = 0;
965 int osd_show_sub_pos = 0;
966 int osd_show_sub_visibility = 0;
967 int osd_show_sub_alignment = 0;
968 int osd_show_vobsub_changed = 0;
969 int osd_show_sub_changed = 0;
970 int osd_show_percentage = 0;
971 int osd_show_tv_channel = 25;
972 int osd_show_ontop = 0;
973 int osd_show_rootwin = 0;
974 int osd_show_framedropping = 0;
976 int rtc_fd=-1;
978 //float a_frame=0; // Audio
980 int i;
981 char *tmp;
983 int gui_no_filename=0;
986 srand((int) time(NULL));
988 mp_msg_init();
989 mp_msg_set_level(MSGL_STATUS);
991 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2004 MPlayer Team\n");
992 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
993 GetCpuCaps(&gCpuCaps);
994 #ifdef ARCH_X86
995 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
996 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
997 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
998 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
999 #ifdef RUNTIME_CPUDETECT
1000 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
1001 #else
1002 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
1003 #ifdef HAVE_MMX
1004 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
1005 #endif
1006 #ifdef HAVE_MMX2
1007 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
1008 #endif
1009 #ifdef HAVE_3DNOW
1010 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
1011 #endif
1012 #ifdef HAVE_3DNOWEX
1013 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
1014 #endif
1015 #ifdef HAVE_SSE
1016 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
1017 #endif
1018 #ifdef HAVE_SSE2
1019 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
1020 #endif
1021 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
1022 #endif
1023 #endif
1025 #if defined(WIN32) && defined(USE_WIN32DLL)
1026 { /*make our codec dirs available for LoadLibraryA()*/
1027 char tmppath[MAX_PATH*2 + 1];
1028 char win32path[MAX_PATH];
1029 char realpath[MAX_PATH];
1030 #ifdef __CYGWIN__
1031 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
1032 strcpy(tmppath,win32path);
1033 #ifdef USE_REALCODECS
1034 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
1035 sprintf(tmppath,"%s;%s",win32path,realpath);
1036 #endif /*USE_REALCODECS*/
1037 #else
1038 if(!strstr(WIN32_PATH,":")){
1039 GetModuleFileNameA(NULL, win32path, MAX_PATH);
1040 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
1042 else strcpy(win32path,WIN32_PATH);
1043 strcpy(tmppath,win32path);
1044 #ifdef USE_REALCODECS
1045 if(!strstr(REALCODEC_PATH,":")){
1046 GetModuleFileNameA(NULL, realpath, MAX_PATH);
1047 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
1049 else strcpy(realpath,REALCODEC_PATH);
1050 sprintf(tmppath,"%s;%s",win32path,realpath);
1051 #endif /*USE_REALCODECS*/
1052 #endif /*__CYGWIN__*/
1053 SetEnvironmentVariableA("PATH", tmppath);
1055 #endif /*WIN32 && USE_WIN32DLL*/
1057 #ifdef USE_TV
1058 tv_param_immediate = 1;
1059 #endif
1061 if ( argv[0] )
1062 if(!strcmp(argv[0],"gmplayer") ||
1063 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
1064 use_gui=1;
1066 mconfig = m_config_new();
1067 m_config_register_options(mconfig,mplayer_opts);
1068 // TODO : add something to let modules register their options
1069 mp_input_register_options(mconfig);
1070 parse_cfgfiles(mconfig);
1072 #ifdef HAVE_NEW_GUI
1073 if ( use_gui ) cfg_read();
1074 #endif
1076 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
1077 if(playtree == NULL)
1078 exit_player(NULL);
1080 playtree = play_tree_cleanup(playtree);
1081 if(playtree) {
1082 playtree_iter = play_tree_iter_new(playtree,mconfig);
1083 if(playtree_iter) {
1084 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
1085 play_tree_iter_free(playtree_iter);
1086 playtree_iter = NULL;
1088 filename = play_tree_iter_get_file(playtree_iter,1);
1092 #ifndef HAVE_NEW_GUI
1093 if(use_gui){
1094 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
1095 use_gui=0;
1097 #else
1098 if(use_gui && !vo_init()){
1099 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
1100 use_gui=0;
1102 if (use_gui && playtree_iter){
1103 char cwd[PATH_MAX+2];
1104 // Remove Playtree and Playtree-Iter from memory as its not used by gui
1105 play_tree_iter_free(playtree_iter);
1106 playtree_iter=NULL;
1108 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
1110 strcat(cwd, "/");
1111 // Prefix relative paths with current working directory
1112 play_tree_add_bpf(playtree, cwd);
1114 // Import initital playtree into gui
1115 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
1117 #endif
1119 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
1120 list_video_out();
1121 exit_player_with_rc(NULL, 0);
1124 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
1125 list_audio_out();
1126 exit_player_with_rc(NULL, 0);
1129 // check codec.conf
1130 if(!codecs_file || !parse_codec_cfg(codecs_file)){
1131 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
1132 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
1133 if(!parse_codec_cfg(NULL)){
1134 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
1135 exit_player_with_rc(NULL, 0);
1137 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
1140 free( mem_ptr ); // release the buffer created by get_path()
1143 #if 0
1144 if(video_codec_list){
1145 int i;
1146 video_codec=video_codec_list[0];
1147 for(i=0;video_codec_list[i];i++)
1148 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
1150 #endif
1151 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
1152 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
1153 list_codecs(1);
1154 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1155 exit_player_with_rc(NULL, 0);
1157 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
1158 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
1159 list_codecs(0);
1160 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1161 exit_player_with_rc(NULL, 0);
1163 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
1164 vfm_help();
1165 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1166 exit_player_with_rc(NULL, 0);
1168 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
1169 afm_help();
1170 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1171 exit_player_with_rc(NULL, 0);
1173 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
1174 af_help();
1175 printf("\n");
1176 exit_player_with_rc(NULL, 0);
1178 #ifdef HAVE_X11
1179 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
1180 fstype_help();
1181 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1182 exit_player_with_rc(NULL, 0);
1184 #endif
1186 #ifdef USE_EDL
1187 if (edl_check_mode() == EDL_ERROR && edl_filename)
1189 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantUseBothModes);
1190 exit_player(NULL);
1191 } else if (edl_filename)
1193 edl_memory_slots = edl_count_entries();
1194 if (edl_memory_slots > 0)
1196 edl_records = calloc(edl_memory_slots, sizeof(struct edl_record));
1197 if (edl_records == NULL)
1199 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_EdlOutOfMem);
1200 exit_player(NULL);
1201 } else
1203 if ((edl_operations = edl_parse_file(edl_records)) > 0)
1205 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlRecordsNo,
1206 edl_operations);
1207 } else
1210 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlQueueEmpty);
1215 next_edl_record = edl_records;
1217 } else if (edl_output_filename)
1219 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
1221 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
1222 edl_output_filename);
1223 exit_player(NULL);
1226 #endif
1228 if(!filename){
1229 if(!use_gui){
1230 // no file/vcd/dvd -> show HELP:
1231 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1232 exit_player_with_rc(NULL, 0);
1233 } else gui_no_filename=1;
1236 // Many users forget to include command line in bugreports...
1237 if(verbose>0){
1238 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
1239 for(i=1;i<argc;i++)mp_msg(MSGT_FIXME, MSGL_FIXME," '%s'",argv[i]);
1240 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1243 mp_msg_set_level(verbose+MSGL_STATUS);
1245 //------ load global data first ------
1247 // check font
1248 #ifdef USE_OSD
1249 #ifdef HAVE_FREETYPE
1250 init_freetype();
1251 #endif
1252 #ifdef HAVE_FONTCONFIG
1253 if(!font_fontconfig)
1255 #endif
1256 if(font_name){
1257 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1258 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1259 } else {
1260 // try default:
1261 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
1262 free(mem_ptr); // release the buffer created by get_path()
1263 if(!vo_font)
1264 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1266 #ifdef HAVE_FONTCONFIG
1268 #endif
1269 #endif
1270 vo_init_osd();
1272 #ifdef HAVE_RTC
1273 if(!nortc)
1275 // seteuid(0); /* Can't hurt to try to get root here */
1276 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
1277 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
1278 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
1279 else {
1280 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1282 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1283 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
1284 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
1285 close (rtc_fd);
1286 rtc_fd = -1;
1287 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1288 /* variable only by the root */
1289 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
1290 close (rtc_fd);
1291 rtc_fd = -1;
1292 } else
1293 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
1296 #ifdef HAVE_NEW_GUI
1297 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1298 // and now ? -- Pontscho
1299 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1300 #endif
1301 if(rtc_fd<0)
1302 #endif
1303 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
1304 softsleep?"software":timer_name);
1306 #ifdef USE_TERMCAP
1307 if ( !use_gui ) load_termcap(NULL); // load key-codes
1308 #endif
1310 // ========== Init keyboard FIFO (connection to libvo) ============
1312 // Init input system
1313 current_module = "init_input";
1314 mp_input_init();
1315 #if 0
1316 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1318 if(keyb_fifo_get > 0)
1319 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1320 #else
1321 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1322 #endif
1323 if(slave_mode)
1324 #ifndef __MINGW32__
1325 mp_input_add_cmd_fd(0,1,NULL,NULL);
1326 #else
1327 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1328 #endif
1329 else if(!noconsolecontrols)
1330 #ifndef HAVE_NO_POSIX_SELECT
1331 mp_input_add_key_fd(0,1,NULL,NULL);
1332 #else
1333 mp_input_add_key_fd(0,0,NULL,NULL);
1334 #endif
1336 inited_flags|=INITED_INPUT;
1337 current_module = NULL;
1339 #ifdef HAVE_MENU
1340 if(use_menu) {
1341 if(menu_cfg && menu_init(menu_cfg))
1342 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1343 else {
1344 menu_cfg = get_path("menu.conf");
1345 if(menu_init(menu_cfg))
1346 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1347 else {
1348 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1349 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
1350 else {
1351 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
1352 use_menu = 0;
1357 #endif
1359 /// Catch signals
1360 #ifndef __MINGW32__
1361 signal(SIGCHLD,child_sighandler);
1362 #endif
1364 #ifdef CRASH_DEBUG
1365 prog_path = argv[0];
1366 #endif
1367 //========= Catch terminate signals: ================
1368 // terminate requests:
1369 signal(SIGTERM,exit_sighandler); // kill
1370 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1372 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1374 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1375 #ifdef ENABLE_SIGHANDLER
1376 // fatal errors:
1377 signal(SIGBUS,exit_sighandler); // bus error
1378 signal(SIGSEGV,exit_sighandler); // segfault
1379 signal(SIGILL,exit_sighandler); // illegal instruction
1380 signal(SIGFPE,exit_sighandler); // floating point exc.
1381 signal(SIGABRT,exit_sighandler); // abort()
1382 #ifdef CRASH_DEBUG
1383 if (crash_debug)
1384 signal(SIGTRAP,exit_sighandler);
1385 #endif
1386 #endif
1388 #ifdef HAVE_NEW_GUI
1389 if(use_gui){
1390 guiInit();
1391 inited_flags|=INITED_GUI;
1392 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1394 #endif
1396 // ******************* Now, let's see the per-file stuff ********************
1398 play_next_file:
1400 // init global sub numbers
1401 global_sub_size = 0;
1402 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
1403 global_sub_quiet_osd_hack = 1;
1405 if (filename) load_per_file_config (mconfig, filename);
1407 // We must enable getch2 here to be able to interrupt network connection
1408 // or cache filling
1409 if(!noconsolecontrols && !slave_mode){
1410 if(inited_flags&INITED_GETCH2)
1411 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
1412 else
1413 getch2_enable(); // prepare stdin for hotkeys...
1414 inited_flags|=INITED_GETCH2;
1415 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1418 // =================== GUI idle loop (STOP state) ===========================
1419 #ifdef HAVE_NEW_GUI
1420 if ( use_gui ) {
1421 file_format=DEMUXER_TYPE_UNKNOWN;
1422 guiGetEvent( guiSetDefaults,0 );
1423 while ( guiIntfStruct.Playing != 1 )
1425 mp_cmd_t* cmd;
1426 usec_sleep(20000);
1427 guiEventHandling();
1428 guiGetEvent( guiReDraw,NULL );
1429 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1431 guiGetEvent( guiSetParameters,NULL );
1432 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1434 play_tree_t * entry = play_tree_new();
1435 play_tree_add_file( entry,guiIntfStruct.Filename );
1436 if ( playtree ) play_tree_free_list( playtree->child,1 );
1437 else playtree=play_tree_new();
1438 play_tree_set_child( playtree,entry );
1439 if(playtree)
1441 playtree_iter = play_tree_iter_new(playtree,mconfig);
1442 if(playtree_iter)
1444 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1446 play_tree_iter_free(playtree_iter);
1447 playtree_iter = NULL;
1449 filename = play_tree_iter_get_file(playtree_iter,1);
1454 #endif
1455 //---------------------------------------------------------------------------
1457 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1459 //==================== Open VOB-Sub ============================
1461 current_module="vobsub";
1462 if (vobsub_name){
1463 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1464 if(vo_vobsub==NULL)
1465 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1466 }else if(sub_auto && filename && (strlen(filename)>=5)){
1467 /* try to autodetect vobsub from movie filename ::atmos */
1468 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1469 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1470 strncpy(buf, filename, strlen(filename)-4);
1471 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1472 free(buf);
1474 if(vo_vobsub){
1475 inited_flags|=INITED_VOBSUB;
1476 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1477 // check if vobsub requested only to display forced subtitles
1478 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1480 // setup global sub numbering
1481 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
1482 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
1485 //============ Open & Sync STREAM --- fork cache2 ====================
1487 stream=NULL;
1488 demuxer=NULL;
1489 if (d_audio) {
1490 //free_demuxer_stream(d_audio);
1491 d_audio=NULL;
1493 if (d_video) {
1494 //free_demuxer_stream(d_video);
1495 d_video=NULL;
1497 sh_audio=NULL;
1498 sh_video=NULL;
1500 current_module="open_stream";
1501 stream=open_stream(filename,0,&file_format);
1502 if(!stream) { // error...
1503 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1504 goto goto_next_file;
1506 inited_flags|=INITED_STREAM;
1508 #ifdef HAVE_NEW_GUI
1509 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1510 #endif
1512 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1513 play_tree_t* entry;
1514 // Handle playlist
1515 current_module="handle_playlist";
1516 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1517 entry = parse_playtree(stream,0);
1518 eof=playtree_add_playlist(entry);
1519 goto goto_next_file;
1521 stream->start_pos+=seek_to_byte;
1523 if(stream_dump_type==5){
1524 unsigned char buf[4096];
1525 int len;
1526 FILE *f;
1527 current_module="dumpstream";
1528 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1529 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
1530 exit_player(MSGTR_Exit_error);
1532 stream_reset(stream);
1533 stream_seek(stream,stream->start_pos);
1534 f=fopen(stream_dump_name,"wb");
1535 if(!f){
1536 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1537 exit_player(MSGTR_Exit_error);
1539 while(!stream->eof){
1540 len=stream_read(stream,buf,4096);
1541 if(len>0) {
1542 if(fwrite(buf,len,1,f) != 1) {
1543 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1544 exit_player(MSGTR_Exit_error);
1548 if(fclose(f)) {
1549 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1550 exit_player(MSGTR_Exit_error);
1552 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1553 exit_player_with_rc(MSGTR_Exit_eof, 0);
1556 #ifdef USE_DVDREAD
1557 if(stream->type==STREAMTYPE_DVD){
1558 current_module="dvd lang->id";
1559 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1560 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1561 // setup global sub numbering
1562 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1563 global_sub_size += dvd_number_of_subs(stream);
1564 current_module=NULL;
1566 #endif
1568 #ifdef USE_DVDNAV
1569 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1570 #endif
1572 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1573 #ifdef HAS_DVBIN_SUPPORT
1574 goto_enable_cache:
1575 #endif
1576 if(stream_cache_size>0){
1577 current_module="enable_cache";
1578 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)))
1579 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1582 //============ Open DEMUXERS --- DETECT file type =======================
1583 current_module="demux_open";
1585 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1587 // HACK to get MOV Reference Files working
1589 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1591 unsigned char* playlist_entry;
1592 play_tree_t *list = NULL, *entry = NULL;
1594 current_module="handle_demux_playlist";
1595 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1597 char *temp, *bname;
1599 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
1601 bname=mp_basename(playlist_entry);
1602 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1603 continue;
1605 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1606 continue;
1608 entry = play_tree_new();
1610 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1612 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1613 if (temp)
1615 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1616 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1617 strcat(temp, playlist_entry);
1618 play_tree_add_file(entry,temp);
1619 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
1620 free(temp);
1623 else
1624 play_tree_add_file(entry,playlist_entry);
1626 if(!list)
1627 list = entry;
1628 else
1629 play_tree_append_entry(list,entry);
1631 free_demuxer(demuxer);
1632 demuxer = NULL;
1634 if (list)
1636 entry = play_tree_new();
1637 play_tree_set_child(entry,list);
1638 eof=playtree_add_playlist(entry);
1639 goto goto_next_file;
1643 if(!demuxer)
1645 #if 0
1646 play_tree_t* entry;
1647 // Handle playlist
1648 current_module="handle_playlist";
1649 switch(stream->type){
1650 case STREAMTYPE_VCD:
1651 case STREAMTYPE_DVD:
1652 case STREAMTYPE_DVDNAV:
1653 case STREAMTYPE_CDDA:
1654 case STREAMTYPE_VCDBINCUE:
1655 // don't try to parse raw media as playlist, it's unlikely
1656 goto goto_next_file;
1658 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
1659 stream_reset(stream);
1660 stream_seek(stream,stream->start_pos);
1661 entry = parse_playtree(stream,0);
1662 if(!entry)
1663 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1664 else
1665 eof=playtree_add_playlist(entry);
1666 #endif
1667 goto goto_next_file;
1669 inited_flags|=INITED_DEMUXER;
1671 #ifdef HAVE_MATROSKA
1672 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
1673 // setup global sub numbering
1674 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1675 global_sub_size += demux_mkv_num_subs(demuxer);
1677 #endif
1678 #ifdef HAVE_OGGVORBIS
1679 if (demuxer->type==DEMUXER_TYPE_OGG) {
1680 // setup global sub numbering
1681 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1682 global_sub_size += demux_ogg_num_subs(demuxer);
1684 #endif
1686 current_module="demux_open2";
1688 //file_format=demuxer->file_format;
1690 d_audio=demuxer->audio;
1691 d_video=demuxer->video;
1692 d_dvdsub=demuxer->sub;
1694 // DUMP STREAMS:
1695 if((stream_dump_type)&&(stream_dump_type<4)){
1696 FILE *f;
1697 demux_stream_t *ds=NULL;
1698 current_module="dump";
1699 // select stream to dump
1700 switch(stream_dump_type){
1701 case 1: ds=d_audio;break;
1702 case 2: ds=d_video;break;
1703 case 3: ds=d_dvdsub;break;
1705 if(!ds){
1706 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1707 exit_player(MSGTR_Exit_error);
1709 // disable other streams:
1710 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1711 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1712 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1713 // let's dump it!
1714 f=fopen(stream_dump_name,"wb");
1715 if(!f){
1716 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1717 exit_player(MSGTR_Exit_error);
1719 while(!ds->eof){
1720 unsigned char* start;
1721 int in_size=ds_get_packet(ds,&start);
1722 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1723 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1724 if(in_size>0) fwrite(start,in_size,1,f);
1726 fclose(f);
1727 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1728 exit_player_with_rc(MSGTR_Exit_eof, 0);
1731 sh_audio=d_audio->sh;
1732 sh_video=d_video->sh;
1734 if(sh_video){
1736 current_module="video_read_properties";
1737 if(!video_read_properties(sh_video)) {
1738 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1739 sh_video=d_video->sh=NULL;
1740 } else {
1741 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1742 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1743 sh_video->fps,sh_video->frametime
1746 /* need to set fps here for output encoders to pick it up in their init */
1747 if(force_fps){
1748 sh_video->fps=force_fps;
1749 sh_video->frametime=1.0f/sh_video->fps;
1751 vo_fps = sh_video->fps;
1752 #ifdef HAVE_X11
1753 vo_mouse_timer_const=(int)sh_video->fps;
1754 #endif
1756 if(!sh_video->fps && !force_fps){
1757 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1758 sh_video=d_video->sh=NULL;
1764 fflush(stdout);
1766 if(!sh_video && !sh_audio){
1767 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1768 #ifdef HAS_DVBIN_SUPPORT
1769 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1771 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1772 if(priv->is_on)
1774 int dir;
1775 int v = last_dvb_step;
1776 if(v > 0)
1777 dir = DVB_CHANNEL_HIGHER;
1778 else
1779 dir = DVB_CHANNEL_LOWER;
1781 if(dvb_step_channel(priv, dir))
1783 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1784 cache_uninit(stream);
1785 goto goto_enable_cache;
1789 #endif
1790 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1793 /* display clip info */
1794 demux_info_print(demuxer);
1796 //================== Read SUBTITLES (DVD & TEXT) ==========================
1797 if(vo_spudec==NULL && sh_video && (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA)){
1799 if (spudec_ifo) {
1800 unsigned int palette[16], width, height;
1801 current_module="spudec_init_vobsub";
1802 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1803 vo_spudec=spudec_new_scaled(palette, width, height);
1806 #ifdef USE_DVDNAV
1807 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1808 current_module="spudec_init_dvdnav";
1809 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1810 sh_video->disp_w, sh_video->disp_h);
1812 #endif
1814 #ifdef USE_DVDREAD
1815 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1816 current_module="spudec_init_dvdread";
1817 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1818 sh_video->disp_w, sh_video->disp_h);
1820 #endif
1822 #ifdef HAVE_MATROSKA
1823 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1824 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1825 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
1826 current_module = "spudec_init_matroska";
1827 vo_spudec =
1828 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1829 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1830 mkv_sh_sub->height);
1831 forced_subs_only = mkv_sh_sub->forced_subs_only;
1833 #endif
1835 if (vo_spudec==NULL) {
1836 current_module="spudec_init_normal";
1837 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1838 spudec_set_font_factor(vo_spudec,font_factor);
1841 if (vo_spudec!=NULL)
1842 inited_flags|=INITED_SPUDEC;
1846 // Apply current settings for forced subs
1847 if (vo_spudec!=NULL)
1848 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1850 #ifdef USE_SUB
1851 if(sh_video) {
1852 // after reading video params we should load subtitles because
1853 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1854 // check .sub
1855 current_module="read_subtitles_file";
1856 if(sub_name){
1857 for (i = 0; sub_name[i] != NULL; ++i)
1858 add_subtitles (sub_name[i], sh_video->fps, 0);
1860 if(sub_auto) { // auto load sub file ...
1861 char *psub = get_path( "sub/" );
1862 char **tmp = sub_filenames((psub ? psub : ""), filename);
1863 char **tmp2 = tmp;
1864 free(psub); // release the buffer created by get_path() above
1865 while (*tmp2)
1866 add_subtitles (*tmp2++, sh_video->fps, 0);
1867 free(tmp);
1868 if (set_of_sub_size == 0)
1870 add_subtitles (mem_ptr=get_path("default.sub"), sh_video->fps, 1);
1871 free(mem_ptr); // release the buffer created by get_path()
1873 if (set_of_sub_size > 0)
1874 add_subtitles (NULL, sh_video->fps, 1);
1876 if (set_of_sub_size > 0) {
1877 // setup global sub numbering
1878 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
1879 global_sub_size += set_of_sub_size;
1882 #endif
1884 if (global_sub_size) {
1885 // find the best sub to use
1886 if (vobsub_id >= 0) {
1887 // if user asks for a vobsub id, use that first.
1888 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
1889 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1890 // if user asks for a dvd sub id, use that next.
1891 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
1892 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
1893 // if there are text subs to use, use those. (autosubs come last here)
1894 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
1896 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1897 // if nothing else works, get subs from the demuxer.
1898 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1900 } else {
1901 // nothing worth doing automatically.
1902 global_sub_pos = -1;
1904 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1905 global_sub_pos--;
1906 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1909 //================== Init AUDIO (codec) ==========================
1910 if(sh_audio){
1911 // Go through the codec.conf and find the best codec...
1912 current_module="init_audio_codec";
1913 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1914 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1915 sh_audio=d_audio->sh=NULL; // failed to init :(
1916 } else
1917 inited_flags|=INITED_ACODEC;
1918 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1921 if(identify) {
1922 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
1923 if (sh_video) {
1924 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1925 if (sh_video->format >= 0x20202020)
1926 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
1927 else
1928 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
1929 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
1930 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
1931 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
1932 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
1933 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
1935 if (sh_audio) {
1936 if (sh_audio->codec)
1937 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
1938 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1939 if (sh_audio->format >= 0x20202020)
1940 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
1941 else
1942 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
1943 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
1944 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
1945 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
1947 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
1950 if(!sh_video) goto main; // audio-only
1952 //================== Init VIDEO (codec & libvo) ==========================
1953 if(!fixed_vo || !(inited_flags&INITED_VO)){
1954 current_module="preinit_libvo";
1956 vo_config_count=0;
1957 //if((video_out->preinit(vo_subdevice))!=0){
1958 if(!(video_out=init_best_video_out(video_driver_list))){
1959 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
1960 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1962 sh_video->video_out=video_out;
1963 inited_flags|=INITED_VO;
1966 current_module="init_video_filters";
1968 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
1969 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
1971 #ifdef HAVE_MENU
1972 if(use_menu) {
1973 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
1974 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
1975 if(!vf_menu) {
1976 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
1977 use_menu = 0;
1980 if(vf_menu)
1981 sh_video->vfilter=(void*)append_filters(vf_menu);
1982 else
1983 #endif
1984 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
1986 current_module="init_video_codec";
1988 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1989 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
1990 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1992 if(!sh_video->inited){
1993 if(!fixed_vo) uninit_player(INITED_VO);
1994 if(!sh_audio) goto goto_next_file;
1995 sh_video = d_video->sh = NULL;
1996 goto main; // exit_player(MSGTR_Exit_error);
1999 inited_flags|=INITED_VCODEC;
2001 if(auto_quality>0){
2002 // Auto quality option enabled
2003 output_quality=get_video_quality_max(sh_video);
2004 if(auto_quality>output_quality) auto_quality=output_quality;
2005 else output_quality=auto_quality;
2006 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
2007 set_video_quality(sh_video,output_quality);
2010 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2012 current_module="init_vo";
2014 if(vo_flags & 0x08 && vo_spudec)
2015 spudec_set_hw_spu(vo_spudec,video_out);
2017 #ifdef HAVE_FREETYPE
2018 force_load_font = 1;
2019 #endif
2021 //================== MAIN: ==========================
2022 main:
2023 current_module="main";
2025 // If there is no video OSD has to be disabled.
2026 // In case of playing a playtree we have to restore the
2027 // old OSD level after playing one or more audio-only files.
2028 if(!sh_video && osd_level >= 0) { // save OSD level only once
2029 osd_level_saved = osd_level;
2030 osd_level = 0;
2031 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
2032 osd_level = osd_level_saved;
2033 osd_level_saved = -1;
2036 fflush(stdout);
2038 #ifdef HAVE_NEW_GUI
2039 if ( use_gui )
2041 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
2042 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
2043 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
2044 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
2045 guiGetEvent( guiSetDemuxer,(char *)demuxer );
2047 #endif
2050 //int frame_corr_num=0; //
2051 //float v_frame=0; // Video
2052 float time_frame=0; // Timer
2053 //float num_frames=0; // number of frames played
2054 int grab_frames=0;
2055 char osd_text_buffer[64];
2056 char osd_show_text_buffer[64];
2057 int drop_frame=0; // current dropping status
2058 int dropped_frames=0; // how many frames dropped since last non-dropped frame
2059 int too_slow_frame_cnt=0;
2060 int too_fast_frame_cnt=0;
2061 // for auto-quality:
2062 float AV_delay=0; // average of A-V timestamp differences
2063 double vdecode_time;
2064 unsigned int lastframeout_ts=0;
2065 /*float time_frame_corr_avg=0;*/ /* unused */
2067 float next_frame_time=0;
2068 int frame_time_remaining=0; // flag
2069 int blit_frame=0;
2071 osd_text_buffer[0]=0;
2073 //================ SETUP AUDIO ==========================
2075 if(sh_audio){
2076 //const ao_info_t *info=audio_out->info;
2077 current_module="af_preinit";
2078 ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*playback_speed;
2079 ao_data.channels=audio_output_channels?audio_output_channels:sh_audio->channels;
2080 ao_data.format=audio_output_format?audio_output_format:sh_audio->sample_format;
2081 #if 1
2082 if(!preinit_audio_filters(sh_audio,
2083 // input:
2084 (int)(sh_audio->samplerate*playback_speed),
2085 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
2086 // output:
2087 &ao_data.samplerate, &ao_data.channels, &ao_data.format,
2088 audio_out_format_bits(ao_data.format)/8)){
2089 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2090 } else {
2091 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AF_pre: %dHz %dch %s\n",
2092 ao_data.samplerate, ao_data.channels,
2093 audio_out_format_name(ao_data.format));
2095 #endif
2096 current_module="ao2_init";
2097 if(!(audio_out=init_best_audio_out(audio_driver_list,
2098 (ao_plugin_cfg.plugin_list!=NULL), // plugin flag
2099 force_srate?force_srate:ao_data.samplerate,
2100 audio_output_channels?audio_output_channels:ao_data.channels,
2101 audio_output_format?audio_output_format:ao_data.format,0))){
2102 // FAILED:
2103 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2104 uninit_player(INITED_ACODEC); // close codec
2105 sh_audio=d_audio->sh=NULL; // -> nosound
2106 } else {
2107 // SUCCESS:
2108 inited_flags|=INITED_AO;
2109 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
2110 audio_out->info->short_name,
2111 ao_data.samplerate, ao_data.channels,
2112 audio_out_format_name(ao_data.format),
2113 audio_out_format_bits(ao_data.format)/8 );
2114 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2115 audio_out->info->name, audio_out->info->author);
2116 if(strlen(audio_out->info->comment) > 0)
2117 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2118 // init audio filters:
2119 #if 1
2120 current_module="af_init";
2121 if(!build_afilter_chain(sh_audio, &ao_data)) {
2122 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2123 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2124 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2125 // sh_audio=d_audio->sh=NULL; // -> nosound
2127 #endif
2129 mixer.audio_out = audio_out;
2130 mixer.afilter = sh_audio ? sh_audio->afilter : NULL;
2131 mixer.volstep = volstep;
2134 current_module="av_init";
2136 if(sh_video) sh_video->timer=0;
2137 if(sh_audio) sh_audio->delay=-audio_delay;
2139 if(!sh_audio){
2140 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
2141 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
2142 ds_free_packs(d_audio); // free buffered chunks
2143 d_audio->id=-2; // do not read audio chunks
2144 //uninit_player(INITED_AO); // close device
2146 if(!sh_video){
2147 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
2148 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
2149 ds_free_packs(d_video);
2150 d_video->id=-2;
2151 //if(!fixed_vo) uninit_player(INITED_VO);
2154 if (!sh_video && !sh_audio)
2155 goto goto_next_file;
2157 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
2158 if(force_fps && sh_video){
2159 vo_fps = sh_video->fps=force_fps;
2160 sh_video->frametime=1.0f/sh_video->fps;
2161 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
2164 //==================== START PLAYING =======================
2166 if(loop_times>1) loop_times--; else
2167 if(loop_times==1) loop_times = -1;
2169 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
2171 InitTimer();
2173 #ifdef USE_DVDNAV
2174 if (stream->type==STREAMTYPE_DVDNAV) {
2175 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
2177 #endif
2179 total_time_usage_start=GetTimer();
2180 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
2181 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
2182 play_n_frames=play_n_frames_mf;
2184 if(play_n_frames==0){
2185 eof=PT_NEXT_ENTRY; goto goto_next_file;
2188 while(!eof){
2189 float aq_sleep_time=0;
2191 if(play_n_frames>=0){
2192 --play_n_frames;
2193 if(play_n_frames<0) eof = PT_NEXT_ENTRY;
2196 /*========================== PLAY AUDIO ============================*/
2198 while(sh_audio){
2199 unsigned int t;
2200 double tt;
2201 int playsize;
2203 current_module="play_audio";
2205 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2206 playsize=audio_out->get_space();
2208 // handle audio-only case:
2209 if(playsize < ao_data.outburst &&
2210 !sh_video) { // buffer is full, do not block here!!!
2211 usec_sleep(10000); // Wait a tick before retry
2212 continue;
2215 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
2217 // Fill buffer if needed:
2218 current_module="decode_audio"; // Enter AUDIO decoder module
2219 t=GetTimer();
2220 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
2221 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
2222 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
2223 if(ret<=0) break; // EOF?
2224 sh_audio->a_out_buffer_len+=ret;
2226 t=GetTimer()-t;
2227 tt = t*0.000001f; audio_time_usage+=tt;
2228 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
2230 // play audio:
2231 current_module="play_audio";
2232 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2234 if(playsize>0){
2235 sh_audio->a_out_buffer_len-=playsize;
2236 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2237 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2238 ao_data.bps : sh_audio->o_bps));
2241 break;
2242 } // while(sh_audio)
2244 if(!sh_video) {
2245 // handle audio-only case:
2246 if(!quiet) {
2247 float a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
2248 print_status(a_pos, 0, 0);
2250 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2252 } else {
2254 /*========================== PLAY VIDEO ============================*/
2256 float frame_time=next_frame_time;
2258 vo_pts=sh_video->timer*90000.0;
2259 vo_fps=sh_video->fps;
2261 if(!frame_time_remaining){
2262 //-------------------- Decode a frame: -----------------------
2263 vdecode_time=video_time_usage;
2264 while(1)
2265 { unsigned char* start=NULL;
2266 int in_size;
2267 // get it!
2268 current_module="video_read_frame";
2269 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2270 if(in_size<0){ eof=1; break; }
2271 if(in_size>max_framesize) max_framesize=in_size; // stats
2272 sh_video->timer+=frame_time;
2273 if(sh_audio) sh_audio->delay-=frame_time;
2274 time_frame+=frame_time; // for nosound
2275 // check for frame-drop:
2276 current_module="check_framedrop";
2277 if(sh_audio && !d_audio->eof){
2278 float delay=playback_speed*audio_out->get_delay();
2279 float d=delay-sh_audio->delay;
2280 // we should avoid dropping to many frames in sequence unless we
2281 // are too late. and we allow 100ms A-V delay here:
2282 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
2283 drop_frame=frame_dropping;
2284 ++drop_frame_cnt;
2285 ++dropped_frames;
2286 } else {
2287 drop_frame=dropped_frames=0;
2289 ++total_frame_cnt;
2291 // decode:
2292 current_module="decode_video";
2293 // printf("Decode! %p %d \n",start,in_size);
2294 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2295 break;
2297 vdecode_time=video_time_usage-vdecode_time;
2298 //------------------------ frame decoded. --------------------
2300 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2302 if(sh_video->vf_inited<0){
2303 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2304 eof=1; goto goto_next_file;
2309 // ==========================================================================
2311 // current_module="draw_osd";
2312 // if(vo_config_count) video_out->draw_osd();
2314 #ifdef HAVE_NEW_GUI
2315 if(use_gui) guiEventHandling();
2316 #endif
2318 current_module="calc_sleep_time";
2320 #if 0
2321 { // debug frame dropping code
2322 float delay=audio_out->get_delay();
2323 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2324 sh_video->timer,sh_audio->timer-delay,
2325 sh_video->timer-(sh_audio->timer-delay),
2326 delay,drop_frame);
2328 #endif
2330 if(drop_frame && !frame_time_remaining && !autosync){
2332 * Note: time_frame should not be forced to 0 in autosync mode.
2333 * It is used as a cumulative counter to predict and correct the
2334 * delay measurements from the audio driver. time_frame is already
2335 * < 0, so the "time to sleep" code does not actually sleep. Also,
2336 * blit_frame is already 0 because drop_frame was true when
2337 * decode_video was called (which causes it to set blit_frame to 0.)
2338 * When autosync==0, the default behavior is still completely unchanged.
2341 time_frame=0; // don't sleep!
2342 blit_frame=0; // don't display!
2344 } else {
2346 // It's time to sleep...
2348 frame_time_remaining=0;
2349 time_frame-=GetRelativeTime(); // reset timer
2351 if(sh_audio && !d_audio->eof){
2352 float delay=playback_speed*audio_out->get_delay();
2353 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2355 if (autosync){
2357 * Adjust this raw delay value by calculating the expected
2358 * delay for this frame and generating a new value which is
2359 * weighted between the two. The higher autosync is, the
2360 * closer to the delay value gets to that which "-nosound"
2361 * would have used, and the longer it will take for A/V
2362 * sync to settle at the right value (but it eventually will.)
2363 * This settling time is very short for values below 100.
2365 float predicted = sh_audio->delay+time_frame;
2366 float difference = delay - predicted;
2367 delay = predicted + difference / (float)autosync;
2370 time_frame=delay-sh_audio->delay;
2372 // delay = amount of audio buffered in soundcard/driver
2373 if(delay>0.25) delay=0.25; else
2374 if(delay<0.10) delay=0.10;
2375 if(time_frame>delay*0.6){
2376 // sleep time too big - may cause audio drops (buffer underrun)
2377 frame_time_remaining=1;
2378 time_frame=delay*0.5;
2381 } else {
2383 // NOSOUND:
2384 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2385 time_frame=0;
2389 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2391 aq_sleep_time+=time_frame;
2393 } // !drop_frame
2395 //============================== SLEEP: ===================================
2397 time_frame/=playback_speed;
2399 // flag 256 means: libvo driver does its timing (dvb card)
2400 if(time_frame>0.001 && !(vo_flags&256)){
2402 #ifdef HAVE_RTC
2403 if(rtc_fd>=0){
2404 // -------- RTC -----------
2405 current_module="sleep_rtc";
2406 while (time_frame > 0.000) {
2407 unsigned long rtc_ts;
2408 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2409 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2410 time_frame-=GetRelativeTime();
2412 } else
2413 #endif
2415 // -------- TIMER + SOFTSLEEP -----------
2416 float min=softsleep?0.021:0.005;
2417 current_module="sleep_timer";
2418 while(time_frame>min){
2419 if(time_frame<=0.020)
2420 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2421 else
2422 usec_sleep(1000000*(time_frame-0.020));
2423 time_frame-=GetRelativeTime();
2425 if(softsleep){
2426 current_module="sleep_soft";
2427 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
2428 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2434 //if(!frame_time_remaining){ // should we display the frame now?
2436 //====================== FLIP PAGE (VIDEO BLT): =========================
2438 current_module="vo_check_events";
2439 if(vo_config_count) video_out->check_events();
2441 current_module="flip_page";
2442 if (!frame_time_remaining) {
2443 if(blit_frame){
2444 unsigned int t2=GetTimer();
2445 double tt;
2446 float j;
2447 #define FRAME_LAG_WARN 0.2
2448 j = ((float)t2 - lastframeout_ts) / 1000000;
2449 lastframeout_ts = GetTimer();
2450 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2451 too_fast_frame_cnt++;
2452 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2453 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2454 too_slow_frame_cnt++;
2455 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2457 if(vo_config_count) video_out->flip_page();
2458 // usec_sleep(50000); // test only!
2459 t2=GetTimer()-t2;
2460 tt = t2*0.000001f;
2461 vout_time_usage+=tt;
2462 } else {
2464 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2465 otherwise A/V desync will occur. -- Alvieboy
2467 if (vo_config_count)
2468 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2471 //====================== A-V TIMESTAMP CORRECTION: =========================
2473 current_module="av_sync";
2475 if(sh_audio){
2476 float a_pts=0;
2477 float v_pts=0;
2479 // unplayed bytes in our and soundcard/dma buffer:
2480 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2482 if (autosync){
2484 * If autosync is enabled, the value for delay must be calculated
2485 * a bit differently. It is set only to the difference between
2486 * the audio and video timers. Any attempt to include the real
2487 * or corrected delay causes the pts_correction code below to
2488 * try to correct for the changes in delay which autosync is
2489 * trying to measure. This keeps the two from competing, but still
2490 * allows the code to correct for PTS drift *only*. (Using a delay
2491 * value here, even a "corrected" one, would be incompatible with
2492 * autosync mode.)
2494 delay=sh_audio->delay;
2495 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2498 #if 0
2499 if(pts_from_bps){
2500 // PTS = sample_no / samplerate
2501 unsigned int samples=
2502 // (sh_audio->audio.dwSampleSize)?
2503 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2504 ds_tell_block(d_audio); // <- used for VBR audio
2505 samples+=sh_audio->audio.dwStart; // offset
2506 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2507 delay_corrected=1;
2508 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2509 } else
2510 #endif
2512 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2513 a_pts=d_audio->pts;
2514 if(!delay_corrected) if(a_pts) delay_corrected=1;
2515 #if 0
2516 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2517 a_pts,
2518 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2519 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2520 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2521 #endif
2522 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2524 v_pts=sh_video ? sh_video->pts : d_video->pts;
2526 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);
2528 if(delay_corrected){
2529 static int drop_message=0;
2530 float x;
2531 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2532 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2533 ++drop_message;
2534 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2536 x=AV_delay*0.1f;
2537 if(x<-max_pts_correction) x=-max_pts_correction; else
2538 if(x> max_pts_correction) x= max_pts_correction;
2539 if(default_max_pts_correction>=0)
2540 max_pts_correction=default_max_pts_correction;
2541 else
2542 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2543 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2544 if(!quiet)
2545 print_status(a_pts - audio_delay - delay, AV_delay, c_total);
2548 } else {
2549 // No audio:
2551 if(!quiet)
2552 print_status(0, 0, 0);
2556 //============================ Auto QUALITY ============================
2558 /*Output quality adjustments:*/
2559 if(auto_quality>0){
2560 current_module="autoq";
2561 // float total=0.000001f * (GetTimer()-aq_total_time);
2562 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2563 if(output_quality<auto_quality && aq_sleep_time>0)
2564 ++output_quality;
2565 else
2566 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2567 if(output_quality>1 && aq_sleep_time<0)
2568 --output_quality;
2569 else
2570 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2571 output_quality=0;
2572 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2573 set_video_quality(sh_video,output_quality);
2576 } // end if(sh_video)
2578 //============================ Handle PAUSE ===============================
2580 current_module="pause";
2582 #ifdef USE_OSD
2583 if(osd_visible){
2584 if (!--osd_visible){
2585 vo_osd_progbar_type=-1; // disable
2586 vo_osd_changed(OSDTYPE_PROGBAR);
2587 if (osd_function != OSD_PAUSE)
2588 osd_function = OSD_PLAY;
2591 #endif
2593 if(osd_function==OSD_PAUSE){
2594 mp_cmd_t* cmd;
2595 if(!quiet) {
2596 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2597 fflush(stdout);
2599 #ifdef HAVE_NEW_GUI
2600 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2601 #endif
2602 if (video_out && sh_video && vo_config_count)
2603 video_out->control(VOCTRL_PAUSE, NULL);
2605 if (audio_out && sh_audio)
2606 audio_out->pause(); // pause audio, keep data if possible
2608 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
2609 if(sh_video && video_out && vo_config_count) video_out->check_events();
2610 #ifdef HAVE_NEW_GUI
2611 if(use_gui){
2612 guiEventHandling();
2613 guiGetEvent( guiReDraw,NULL );
2614 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2616 #endif
2617 #ifdef HAVE_MENU
2618 if(vf_menu)
2619 vf_menu_pause_update(vf_menu);
2620 #endif
2621 usec_sleep(20000);
2623 if (cmd && cmd->id == MP_CMD_PAUSE) {
2624 cmd = mp_input_get_cmd(0,1,0);
2625 mp_cmd_free(cmd);
2627 osd_function=OSD_PLAY;
2628 if (audio_out && sh_audio)
2629 audio_out->resume(); // resume audio
2630 if (video_out && sh_video && vo_config_count)
2631 video_out->control(VOCTRL_RESUME, NULL); // resume video
2632 (void)GetRelativeTime(); // keep TF around FT in next cycle
2633 #ifdef HAVE_NEW_GUI
2634 if (use_gui)
2636 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2637 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2639 #endif
2642 // handle -sstep
2643 if(step_sec>0) {
2644 osd_function=OSD_FFW;
2645 rel_seek_secs+=step_sec;
2648 #ifdef USE_DVDNAV
2649 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2650 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2651 #endif
2653 //================= EDL =========================================
2655 #ifdef USE_EDL
2656 if( next_edl_record ) { // Are we (still?) doing EDL?
2657 if ( !sh_video ) {
2658 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
2659 free(edl_records);
2660 next_edl_record = NULL;
2661 edl_records = NULL;
2662 } else {
2663 if( sh_video->pts >= next_edl_record->start_sec ) {
2664 if( next_edl_record->action == EDL_SKIP ) {
2665 osd_function = OSD_FFW;
2666 abs_seek_pos = 0;
2667 rel_seek_secs = next_edl_record->length_sec;
2668 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 );
2669 edl_decision = 1;
2670 } else if( next_edl_record->action == EDL_MUTE ) {
2671 edl_muted = !edl_muted;
2672 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
2673 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
2675 next_edl_record=next_edl_record->next;
2679 #endif
2681 //================= Keyboard events, SEEKing ====================
2683 current_module="key_events";
2686 mp_cmd_t* cmd;
2687 int brk_cmd = 0;
2688 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
2689 switch(cmd->id) {
2690 case MP_CMD_SEEK : {
2691 int v,abs;
2692 osd_show_percentage = 25;
2693 v = cmd->args[0].v.i;
2694 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2695 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2696 abs_seek_pos = 1;
2697 if(sh_video)
2698 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2699 rel_seek_secs = v;
2701 else if(abs) { /* Absolute seek by percentage */
2702 abs_seek_pos = 3;
2703 if(sh_video)
2704 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2705 rel_seek_secs = v/100.0;
2707 else {
2708 rel_seek_secs+= v;
2709 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2711 brk_cmd = 1;
2712 } break;
2713 #ifdef USE_EDL
2714 case MP_CMD_EDL_MARK:
2715 if( edl_fd ) {
2716 float v = sh_video->pts;
2717 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2719 break;
2720 #endif
2721 case MP_CMD_SWITCH_RATIO : {
2722 if (cmd->nargs == 0)
2723 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2724 else
2725 movie_aspect = cmd->args[0].v.f;
2726 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2727 } break;
2728 case MP_CMD_AUDIO_DELAY : {
2729 float v = cmd->args[0].v.f;
2730 audio_delay += v;
2731 osd_show_av_delay = 9;
2732 if(sh_audio) sh_audio->delay+= v;
2733 } break;
2734 case MP_CMD_SPEED_INCR : {
2735 float v = cmd->args[0].v.f;
2736 playback_speed += v;
2737 if (sh_video)
2738 osd_show_speed = sh_video->fps;
2739 build_afilter_chain(sh_audio, &ao_data);
2740 } break;
2741 case MP_CMD_SPEED_MULT : {
2742 float v = cmd->args[0].v.f;
2743 playback_speed *= v;
2744 if (sh_video)
2745 osd_show_speed = sh_video->fps;
2746 build_afilter_chain(sh_audio, &ao_data);
2747 } break;
2748 case MP_CMD_SPEED_SET : {
2749 float v = cmd->args[0].v.f;
2750 playback_speed = v;
2751 if (sh_video)
2752 osd_show_speed = sh_video->fps;
2753 build_afilter_chain(sh_audio, &ao_data);
2754 } break;
2755 case MP_CMD_FRAME_STEP :
2756 case MP_CMD_PAUSE : {
2757 cmd->pausing = 1;
2758 brk_cmd = 1;
2759 } break;
2760 case MP_CMD_QUIT : {
2761 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
2763 case MP_CMD_GRAB_FRAMES : {
2764 grab_frames=2;
2765 } break;
2766 case MP_CMD_PLAY_TREE_STEP : {
2767 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2768 int force = cmd->args[1].v.i;
2770 #ifdef HAVE_NEW_GUI
2771 if (use_gui) {
2772 int i=0;
2773 if (n>0)
2774 for (i=0;i<n;i++)
2775 mplNext();
2776 else
2777 for (i=0;i<-1*n;i++)
2778 mplPrev();
2779 } else
2780 #endif
2782 if(!force && playtree_iter) {
2783 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2785 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2786 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2787 play_tree_iter_free(i);
2788 } else
2789 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2790 if(eof)
2791 play_tree_step = n;
2792 brk_cmd = 1;
2794 } break;
2795 case MP_CMD_PLAY_TREE_UP_STEP : {
2796 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2797 int force = cmd->args[1].v.i;
2799 if(!force && playtree_iter) {
2800 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2801 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2802 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2803 play_tree_iter_free(i);
2804 } else
2805 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2806 brk_cmd = 1;
2807 } break;
2808 case MP_CMD_PLAY_ALT_SRC_STEP : {
2809 if(playtree_iter && playtree_iter->num_files > 1) {
2810 int v = cmd->args[0].v.i;
2811 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2812 eof = PT_NEXT_SRC;
2813 else if(v < 0 && playtree_iter->file > 1)
2814 eof = PT_PREV_SRC;
2816 brk_cmd = 1;
2817 } break;
2818 case MP_CMD_SUB_DELAY : {
2819 #ifdef USE_SUB
2820 if (sh_video) {
2821 int abs= cmd->args[1].v.i;
2822 float v = cmd->args[0].v.f;
2823 if(abs)
2824 sub_delay = v;
2825 else
2826 sub_delay += v;
2827 osd_show_sub_delay = 9; // show the subdelay in OSD
2829 #endif
2830 } break;
2831 case MP_CMD_SUB_STEP : {
2832 #ifdef USE_SUB
2833 if (sh_video) {
2834 int movement = cmd->args[0].v.i;
2835 step_sub(subdata, sh_video->pts, movement);
2836 osd_show_sub_delay = 9; // show the subdelay in OSD
2838 #endif
2839 } break;
2840 case MP_CMD_OSD : {
2841 #ifdef USE_OSD
2842 if(sh_video) {
2843 int v = cmd->args[0].v.i;
2844 if(v < 0)
2845 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2846 else
2847 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2849 #endif
2850 } break;
2851 case MP_CMD_OSD_SHOW_TEXT : {
2852 #ifdef USE_OSD
2853 if(osd_level && sh_video){
2854 osd_show_text=sh_video->fps; // 1 sec
2855 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2857 #endif
2858 } break;
2859 case MP_CMD_VOLUME : {
2860 int v = cmd->args[0].v.i;
2862 // start change for absolute volume value
2863 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2865 #ifdef USE_EDL
2866 if (edl_muted) break;
2867 user_muted = 0;
2868 #endif
2869 if( abs )
2871 mixer_setvolume(&mixer, (float)v, (float)v );
2872 } else {
2873 if(v > 0)
2874 mixer_incvolume(&mixer);
2875 else
2876 mixer_decvolume(&mixer);
2879 #ifdef USE_OSD
2880 if(osd_level && sh_video){
2881 float vol;
2882 osd_visible=sh_video->fps; // 1 sec
2883 vo_osd_progbar_type=OSD_VOLUME;
2884 mixer_getbothvolume(&mixer, &vol);
2885 vo_osd_progbar_value=(vol*256.0)/100.0;
2886 vo_osd_changed(OSDTYPE_PROGBAR);
2888 #endif
2889 } break;
2890 case MP_CMD_MUTE:
2891 #ifdef USE_EDL
2892 user_muted = !user_muted;
2893 if ((edl_muted | user_muted) != mixer.muted)
2894 #endif
2895 mixer_mute(&mixer);
2896 break;
2897 case MP_CMD_LOADFILE : {
2898 play_tree_t* e = play_tree_new();
2899 play_tree_add_file(e,cmd->args[0].v.s);
2901 // Go back to the start point
2902 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2903 /* NOP */;
2904 play_tree_free_list(playtree->child,1);
2905 play_tree_set_child(playtree,e);
2906 play_tree_iter_step(playtree_iter,0,0);
2907 eof = PT_NEXT_SRC;
2908 brk_cmd = 1;
2909 } break;
2910 case MP_CMD_LOADLIST : {
2911 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
2912 if(!e)
2913 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
2914 else {
2915 // Go back to the start point
2916 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2917 /* NOP */;
2918 play_tree_free_list(playtree->child,1);
2919 play_tree_set_child(playtree,e);
2920 play_tree_iter_step(playtree_iter,0,0);
2921 eof = PT_NEXT_SRC;
2923 brk_cmd = 1;
2924 } break;
2925 case MP_CMD_GAMMA : {
2926 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2928 if (!sh_video)
2929 break;
2931 if (vo_gamma_gamma == 1000)
2933 vo_gamma_gamma = 0;
2934 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
2937 if (abs)
2938 vo_gamma_gamma = v;
2939 else
2940 vo_gamma_gamma += v;
2942 if (vo_gamma_gamma > 100)
2943 vo_gamma_gamma = 100;
2944 else if (vo_gamma_gamma < -100)
2945 vo_gamma_gamma = -100;
2946 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
2947 #ifdef USE_OSD
2948 if(osd_level){
2949 osd_visible=sh_video->fps; // 1 sec
2950 vo_osd_progbar_type=OSD_BRIGHTNESS;
2951 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
2952 vo_osd_changed(OSDTYPE_PROGBAR);
2954 #endif // USE_OSD
2955 } break;
2956 case MP_CMD_BRIGHTNESS : {
2957 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2959 if (!sh_video)
2960 break;
2962 if (vo_gamma_brightness == 1000)
2964 vo_gamma_brightness = 0;
2965 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
2968 if (abs)
2969 vo_gamma_brightness = v;
2970 else
2971 vo_gamma_brightness += v;
2973 if (vo_gamma_brightness > 100)
2974 vo_gamma_brightness = 100;
2975 else if (vo_gamma_brightness < -100)
2976 vo_gamma_brightness = -100;
2977 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
2978 #ifdef USE_OSD
2979 if(osd_level){
2980 osd_visible=sh_video->fps; // 1 sec
2981 vo_osd_progbar_type=OSD_BRIGHTNESS;
2982 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
2983 vo_osd_changed(OSDTYPE_PROGBAR);
2985 #endif // USE_OSD
2987 } break;
2988 case MP_CMD_CONTRAST : {
2989 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2991 if (!sh_video)
2992 break;
2994 if (vo_gamma_contrast == 1000)
2996 vo_gamma_contrast = 0;
2997 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
3000 if (abs)
3001 vo_gamma_contrast = v;
3002 else
3003 vo_gamma_contrast += v;
3005 if (vo_gamma_contrast > 100)
3006 vo_gamma_contrast = 100;
3007 else if (vo_gamma_contrast < -100)
3008 vo_gamma_contrast = -100;
3009 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
3010 #ifdef USE_OSD
3011 if(osd_level){
3012 osd_visible=sh_video->fps; // 1 sec
3013 vo_osd_progbar_type=OSD_CONTRAST;
3014 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
3015 vo_osd_changed(OSDTYPE_PROGBAR);
3017 #endif // USE_OSD
3019 } break;
3020 case MP_CMD_SATURATION : {
3021 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3023 if (!sh_video)
3024 break;
3026 if (vo_gamma_saturation == 1000)
3028 vo_gamma_saturation = 0;
3029 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
3032 if (abs)
3033 vo_gamma_saturation = v;
3034 else
3035 vo_gamma_saturation += v;
3037 if (vo_gamma_saturation > 100)
3038 vo_gamma_saturation = 100;
3039 else if (vo_gamma_saturation < -100)
3040 vo_gamma_saturation = -100;
3041 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
3042 #ifdef USE_OSD
3043 if(osd_level){
3044 osd_visible=sh_video->fps; // 1 sec
3045 vo_osd_progbar_type=OSD_SATURATION;
3046 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
3047 vo_osd_changed(OSDTYPE_PROGBAR);
3049 #endif // USE_OSD
3051 } break;
3052 case MP_CMD_HUE : {
3053 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
3055 if (!sh_video)
3056 break;
3058 if (vo_gamma_hue == 1000)
3060 vo_gamma_hue = 0;
3061 get_video_colors(sh_video, "hue", &vo_gamma_hue);
3064 if (abs)
3065 vo_gamma_hue = v;
3066 else
3067 vo_gamma_hue += v;
3069 if (vo_gamma_hue > 100)
3070 vo_gamma_hue = 100;
3071 else if (vo_gamma_hue < -100)
3072 vo_gamma_hue = -100;
3073 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
3074 #ifdef USE_OSD
3075 if(osd_level){
3076 osd_visible=sh_video->fps; // 1 sec
3077 vo_osd_progbar_type=OSD_HUE;
3078 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
3079 vo_osd_changed(OSDTYPE_PROGBAR);
3081 #endif // USE_OSD
3083 } break;
3084 case MP_CMD_FRAMEDROPPING : {
3085 int v = cmd->args[0].v.i;
3086 if(v < 0){
3087 frame_dropping = (frame_dropping+1)%3;
3088 #ifdef USE_OSD
3089 osd_show_framedropping=10;
3090 vo_osd_changed(OSDTYPE_SUBTITLE);
3091 #endif
3093 else
3094 frame_dropping = v > 2 ? 2 : v;
3095 } break;
3096 #ifdef USE_TV
3097 case MP_CMD_TV_SET_FREQ : {
3098 if (file_format == DEMUXER_TYPE_TV)
3099 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
3100 } break;
3101 case MP_CMD_TV_SET_NORM : {
3102 if (file_format == DEMUXER_TYPE_TV)
3103 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3104 } break;
3105 case MP_CMD_TV_SET_BRIGHTNESS : {
3106 if (file_format == DEMUXER_TYPE_TV)
3107 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
3108 } break;
3109 case MP_CMD_TV_SET_HUE : {
3110 if (file_format == DEMUXER_TYPE_TV)
3111 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
3112 } break;
3113 case MP_CMD_TV_SET_SATURATION : {
3114 if (file_format == DEMUXER_TYPE_TV)
3115 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
3116 } break;
3117 case MP_CMD_TV_SET_CONTRAST : {
3118 if (file_format == DEMUXER_TYPE_TV)
3119 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
3120 } break;
3121 case MP_CMD_TV_STEP_CHANNEL : {
3122 if (file_format == DEMUXER_TYPE_TV) {
3123 int v = cmd->args[0].v.i;
3124 if(v > 0){
3125 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
3126 #ifdef USE_OSD
3127 if (tv_channel_list) {
3128 osd_show_tv_channel = sh_video->fps;
3129 vo_osd_changed(OSDTYPE_SUBTITLE);
3131 #endif
3132 } else {
3133 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
3134 #ifdef USE_OSD
3135 if (tv_channel_list) {
3136 osd_show_tv_channel = sh_video->fps;
3137 vo_osd_changed(OSDTYPE_SUBTITLE);
3139 #endif
3143 #ifdef HAS_DVBIN_SUPPORT
3144 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3146 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3147 if(priv->is_on)
3149 int dir;
3150 int v = cmd->args[0].v.i;
3152 last_dvb_step = v;
3153 if(v > 0)
3154 dir = DVB_CHANNEL_HIGHER;
3155 else
3156 dir = DVB_CHANNEL_LOWER;
3159 if(dvb_step_channel(priv, dir))
3161 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3162 cache_uninit(stream);
3163 goto goto_enable_cache;
3167 #endif
3168 break;
3169 case MP_CMD_TV_SET_CHANNEL : {
3170 if (file_format == DEMUXER_TYPE_TV) {
3171 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3172 #ifdef USE_OSD
3173 if (tv_channel_list) {
3174 osd_show_tv_channel = sh_video->fps;
3175 vo_osd_changed(OSDTYPE_SUBTITLE);
3177 #endif
3179 } break;
3180 #ifdef HAS_DVBIN_SUPPORT
3181 case MP_CMD_DVB_SET_CHANNEL:
3183 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3185 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3186 if(priv->is_on)
3188 if(priv->list->current <= cmd->args[0].v.i)
3189 last_dvb_step = 1;
3190 else
3191 last_dvb_step = -1;
3193 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
3195 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3196 cache_uninit(stream);
3197 goto goto_enable_cache;
3202 #endif
3203 case MP_CMD_TV_LAST_CHANNEL : {
3204 if (file_format == DEMUXER_TYPE_TV) {
3205 tv_last_channel((tvi_handle_t*)(demuxer->priv));
3206 #ifdef USE_OSD
3207 if (tv_channel_list) {
3208 osd_show_tv_channel = sh_video->fps;
3209 vo_osd_changed(OSDTYPE_SUBTITLE);
3211 #endif
3213 } break;
3214 case MP_CMD_TV_STEP_NORM : {
3215 if (file_format == DEMUXER_TYPE_TV)
3216 tv_step_norm((tvi_handle_t*)(demuxer->priv));
3217 } break;
3218 case MP_CMD_TV_STEP_CHANNEL_LIST : {
3219 if (file_format == DEMUXER_TYPE_TV)
3220 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
3221 } break;
3222 #endif
3223 case MP_CMD_SWITCH_VSYNC: {
3224 vo_vsync = ( cmd->nargs > 0 )? cmd->args[0].v.i : !vo_vsync;
3225 } break;
3226 case MP_CMD_VO_FULLSCREEN:
3228 #ifdef HAVE_NEW_GUI
3229 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3230 else
3231 #endif
3232 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3233 } break;
3234 case MP_CMD_VO_ONTOP:
3236 if(video_out && vo_config_count) {
3237 video_out->control(VOCTRL_ONTOP, 0);
3238 #ifdef USE_OSD
3239 osd_show_ontop=10;
3240 vo_osd_changed(OSDTYPE_SUBTITLE);
3241 #endif
3244 } break;
3245 case MP_CMD_VO_ROOTWIN:
3247 if(video_out && vo_config_count) {
3248 video_out->control(VOCTRL_ROOTWIN, 0);
3249 #ifdef USE_OSD
3250 osd_show_rootwin=10;
3251 vo_osd_changed(OSDTYPE_SUBTITLE);
3252 #endif
3255 } break;
3256 case MP_CMD_PANSCAN : {
3257 if ( !video_out ) break;
3258 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3260 int abs= cmd->args[1].v.i;
3261 float v = cmd->args[0].v.f;
3262 float res;
3263 if(abs) res = v;
3264 else res = vo_panscan+v;
3265 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3266 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3267 #ifdef USE_OSD
3268 if(osd_level && sh_video){
3269 osd_visible=sh_video->fps; // 1 sec
3270 vo_osd_progbar_type=OSD_PANSCAN;
3271 vo_osd_progbar_value=vo_panscan*256;
3272 vo_osd_changed(OSDTYPE_PROGBAR);
3274 #ifdef HAVE_FREETYPE
3275 if (sh_video && (subtitle_autoscale == 2 || subtitle_autoscale == 3))
3276 // force scaling font to movie width or diagonal
3277 force_load_font = 1;
3278 #endif
3279 #endif
3281 } break;
3282 case MP_CMD_SUB_POS:
3284 #ifdef USE_SUB
3285 if (sh_video) {
3286 int v;
3287 v = cmd->args[0].v.i;
3289 sub_pos+=v;
3290 if(sub_pos >100) sub_pos=100;
3291 if(sub_pos <0) sub_pos=0;
3292 vo_osd_changed(OSDTYPE_SUBTITLE);
3293 osd_show_sub_pos = 9;
3295 #endif
3296 } break;
3297 case MP_CMD_SUB_ALIGNMENT:
3299 #ifdef USE_SUB
3300 if (sh_video) {
3301 if (cmd->nargs >= 1)
3302 sub_alignment = cmd->args[0].v.i;
3303 else
3304 sub_alignment = (sub_alignment+1) % 3;
3305 osd_show_sub_alignment = 9;
3306 vo_osd_changed(OSDTYPE_SUBTITLE);
3308 #endif
3309 } break;
3310 case MP_CMD_SUB_VISIBILITY:
3312 #ifdef USE_SUB
3313 if (sh_video) {
3314 sub_visibility=1-sub_visibility;
3315 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3316 vo_osd_changed(OSDTYPE_SUBTITLE);
3318 #endif
3319 } break;
3320 case MP_CMD_GET_SUB_VISIBILITY:
3322 #ifdef USE_SUB
3323 if (sh_video) {
3324 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsSubVisibility, sub_visibility);
3326 #endif
3327 } break;
3328 case MP_CMD_SUB_SELECT:
3329 if (global_sub_size) {
3330 int source = -1;
3332 global_sub_pos++;
3333 if (global_sub_pos >= global_sub_size)
3334 global_sub_pos = -1;
3335 if (global_sub_pos >= 0)
3336 source = sub_source();
3338 mp_msg(MSGT_CPLAYER, MSGL_DBG3, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3339 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
3340 global_sub_indices[SUB_SOURCE_SUBS], global_sub_indices[SUB_SOURCE_DEMUX],
3341 global_sub_pos, source);
3343 #ifdef USE_SUB
3344 set_of_sub_pos = -1;
3345 subdata = NULL;
3346 vo_sub = NULL;
3347 #endif
3348 vobsub_id = -1;
3349 dvdsub_id = -1;
3350 if (d_dvdsub) d_dvdsub->id = -1;
3352 // be careful!
3353 // if sub_changed is till on but subdata's been reset, bad things happen.
3354 osd_show_vobsub_changed = 0;
3355 osd_show_sub_changed = 0;
3357 if (source == SUB_SOURCE_VOBSUB) {
3358 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
3359 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3360 #ifdef USE_SUB
3361 } else if (source == SUB_SOURCE_SUBS) {
3362 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
3363 subdata = set_of_subtitles[set_of_sub_pos];
3364 if (!global_sub_quiet_osd_hack) osd_show_sub_changed = sh_video->fps;
3365 vo_osd_changed(OSDTYPE_SUBTITLE);
3367 // FIXME: is this the correct place for these?
3368 if(stream_dump_type==3) list_sub_file(subdata);
3369 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
3370 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
3371 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
3372 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
3373 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
3374 #endif
3375 } else if (source == SUB_SOURCE_DEMUX) {
3376 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
3377 if (d_dvdsub) {
3378 #ifdef USE_DVDREAD
3379 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
3380 d_dvdsub->id = dvdsub_id;
3381 spudec_reset(vo_spudec);
3383 #endif
3384 #ifdef HAVE_OGGVORBIS
3385 if (demuxer->type == DEMUXER_TYPE_OGG)
3386 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
3387 #endif
3388 #ifdef HAVE_MATROSKA
3389 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3390 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
3391 if (d_dvdsub->id >= 0 && ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
3392 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
3393 if (vo_spudec != NULL)
3394 spudec_free(vo_spudec);
3395 vo_spudec =
3396 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
3397 mkv_sh_sub->custom_colors,
3398 mkv_sh_sub->width,
3399 mkv_sh_sub->height);
3400 if (!forced_subs_only)
3401 forced_subs_only = mkv_sh_sub->forced_subs_only;
3402 if (vo_spudec) {
3403 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
3404 inited_flags |= INITED_SPUDEC;
3408 #endif
3410 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3411 } else { // off
3412 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3413 #ifdef USE_SUB
3414 vo_osd_changed(OSDTYPE_SUBTITLE);
3415 #endif
3417 // it's annoying and dumb to show osd saying "off" at every subless file...
3418 global_sub_quiet_osd_hack = 0;
3420 break;
3421 case MP_CMD_SUB_FORCED_ONLY:
3422 if (vo_spudec) {
3423 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3424 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3426 break;
3427 case MP_CMD_SCREENSHOT :
3428 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3429 break;
3430 case MP_CMD_VF_CHANGE_RECTANGLE:
3431 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3432 break;
3434 case MP_CMD_GET_TIME_LENGTH : {
3435 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsLength, demuxer_get_time_length(demuxer));
3436 } break;
3438 case MP_CMD_GET_VO_FULLSCREEN : {
3439 if(video_out && vo_config_count)
3440 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsVoFullscreen, vo_fs);
3441 } break;
3443 case MP_CMD_GET_PERCENT_POS : {
3444 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsPercentPos, demuxer_get_percent_pos(demuxer));
3445 } break;
3446 case MP_CMD_RUN : {
3447 #ifndef __MINGW32__
3448 if(!fork()) {
3449 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
3450 exit(0);
3452 #endif
3453 } break;
3455 #ifdef USE_DVDNAV
3456 case MP_CMD_DVDNAV_EVENT: {
3457 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3458 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3460 /* ignore these events if we're not in dvd_nav mode */
3461 if (stream->type != STREAMTYPE_DVDNAV) break;
3463 if (!dvdnav_event) {
3464 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNullEvent);
3465 break;
3468 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3470 switch (dvdnav_event->event) {
3471 case DVDNAV_BLOCK_OK: {
3472 /* be silent about this one */
3473 break;
3475 case DVDNAV_HIGHLIGHT: {
3476 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3477 if (!hevent) {
3478 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightEventBroken);
3479 break;
3482 if (hevent->display && hevent->buttonN>0)
3484 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3485 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3486 hevent->buttonN,
3487 hevent->sx,hevent->sy,
3488 hevent->ex,hevent->ey,
3489 hevent->pts, d_video->pts);
3490 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavEvent,dvd_nav_text);
3491 //osd_show_dvd_nav_delay = 60;
3493 osd_show_dvd_nav_highlight=1;
3494 osd_show_dvd_nav_sx=hevent->sx;
3495 osd_show_dvd_nav_ex=hevent->ex;
3496 osd_show_dvd_nav_sy=hevent->sy;
3497 osd_show_dvd_nav_ey=hevent->ey;
3499 else {
3500 osd_show_dvd_nav_highlight=0;
3501 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightHide);
3503 break;
3505 case DVDNAV_STILL_FRAME: {
3506 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3508 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavStillFrame, still_event->length );
3509 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3510 usec_sleep(1000); /* 1ms */
3512 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3513 break;
3515 case DVDNAV_STOP: {
3516 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavStop );
3517 break;
3519 case DVDNAV_NOP: {
3520 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavNOP);
3521 break;
3523 case DVDNAV_SPU_STREAM_CHANGE: {
3524 #if DVDNAVVERSION > 012
3525 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3527 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChangeVerbose,
3528 stream_change->physical_wide,
3529 stream_change->physical_letterbox,
3530 stream_change->physical_pan_scan,
3531 stream_change->logical);
3533 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3534 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3535 d_dvdsub->id,stream_change->physical_wide);
3536 // FIXME: need a better way to change SPU id
3537 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3538 if (vo_spudec) spudec_reset(vo_spudec);
3540 #else
3541 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3543 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChange,
3544 stream_change->physical,
3545 stream_change->logical);
3547 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3548 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3549 d_dvdsub->id,stream_change->physical);
3550 // FIXME: need a better way to change SPU id
3551 d_dvdsub->id=dvdsub_id=stream_change->physical;
3552 if (vo_spudec) spudec_reset(vo_spudec);
3554 #endif
3555 break;
3557 case DVDNAV_AUDIO_STREAM_CHANGE: {
3558 int aid_temp;
3559 #if DVDNAVVERSION > 012
3560 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3561 #else
3562 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3563 #endif
3565 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavAudioStreamChange,
3566 stream_change->physical,
3567 stream_change->logical);
3569 aid_temp=stream_change->physical;
3570 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3571 if (d_audio && audio_id!=aid_temp) {
3572 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3573 d_audio->id,aid_temp);
3574 // FIXME: need a bettery way to change audio stream id
3575 d_audio->id=dvdsub_id=aid_temp;
3576 if(sh_audio) resync_audio_stream(sh_audio);
3579 break;
3581 case DVDNAV_VTS_CHANGE: {
3582 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavVTSChange);
3583 break;
3585 case DVDNAV_CELL_CHANGE: {
3586 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3587 cell_playback_t * cell_playback = cell_change->new_cell;
3589 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavCellChange);
3590 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3592 printf("new still time: %d\n",cell_playback->still_time);
3593 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3594 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3595 cell_playback->playback_time.hour,
3596 cell_playback->playback_time.minute,
3597 cell_playback->playback_time.second,
3598 cell_playback->playback_time.frame_u);
3601 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3602 //abs_seek_pos=0;
3603 break;
3605 case DVDNAV_NAV_PACKET: {
3606 // printf("DVDNAV Event: Nav Packet\n");
3607 break;
3609 case DVDNAV_SPU_CLUT_CHANGE: {
3610 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3612 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuClutChange);
3613 // send new palette to SPU decoder
3614 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3616 break;
3618 case DVDNAV_SEEK_DONE: {
3619 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSeekDone);
3620 break;
3624 // free the dvdnav event
3625 free(dvdnav_event->details);
3626 free(dvdnav_event);
3627 cmd->args[0].v.v=NULL;
3629 case MP_CMD_DVDNAV: {
3630 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3632 /* ignore these events if we're not in dvd_nav mode */
3633 if (stream->type != STREAMTYPE_DVDNAV) break;
3635 switch (cmd->args[0].v.i) {
3636 case MP_CMD_DVDNAV_UP:
3637 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3638 break;
3639 case MP_CMD_DVDNAV_DOWN:
3640 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3641 break;
3642 case MP_CMD_DVDNAV_LEFT:
3643 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3644 break;
3645 case MP_CMD_DVDNAV_RIGHT:
3646 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3647 break;
3648 case MP_CMD_DVDNAV_MENU:
3649 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_MenuCall);
3650 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3651 break;
3652 case MP_CMD_DVDNAV_SELECT:
3653 dvdnav_button_activate(dvdnav_priv->dvdnav);
3654 break;
3655 default:
3656 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3657 break;
3659 break;
3661 #endif
3662 default : {
3663 #ifdef HAVE_NEW_GUI
3664 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3665 else
3666 #endif
3667 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3670 if (cmd->pausing)
3671 osd_function = OSD_PAUSE;
3672 mp_cmd_free(cmd);
3676 if (seek_to_sec) {
3677 int a,b; float d;
3679 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3680 rel_seek_secs += 3600*a +60*b +d ;
3681 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3682 rel_seek_secs += 60*a +d;
3683 else if (sscanf(seek_to_sec, "%f", &d)==1)
3684 rel_seek_secs += d;
3686 seek_to_sec = NULL;
3689 /* Looping. */
3690 if(eof==1 && loop_times>=0) {
3691 int l = loop_times;
3692 play_tree_iter_step(playtree_iter,0,0);
3693 loop_times = l;
3694 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3696 if(loop_times>1) loop_times--; else
3697 if(loop_times==1) loop_times=-1;
3698 play_n_frames=play_n_frames_mf;
3699 eof=0;
3700 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3701 loop_seek = 1;
3704 if(rel_seek_secs || abs_seek_pos){
3705 current_module="seek";
3706 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3707 // success:
3708 /* FIXME there should be real seeking for vobsub */
3709 if(sh_video) sh_video->pts=d_video->pts;
3710 if (vo_vobsub)
3711 //vobsub_reset(vo_vobsub);
3712 vobsub_seek(vo_vobsub,sh_video->pts);
3713 #if 0
3714 if(sh_video && d_video->packs == 0)
3715 ds_fill_buffer(d_video);
3716 if(sh_audio){
3717 if(d_audio->packs == 0)
3718 ds_fill_buffer(d_audio);
3719 if(verbose>0){
3720 float a_pts=d_audio->pts;
3721 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3722 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);
3724 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);
3725 } else {
3726 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3728 #endif
3729 fflush(stdout);
3731 if(sh_video){
3732 current_module="seek_video_reset";
3733 resync_video_stream(sh_video);
3734 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3737 if(sh_audio){
3738 current_module="seek_audio_reset";
3739 audio_out->reset(); // stop audio, throwing away buffered data
3741 #ifdef USE_OSD
3742 // Set OSD:
3743 if(osd_level && !loop_seek){
3744 #ifdef USE_EDL
3745 if( !edl_decision ) {
3746 #else
3747 if( 1 ) { // Let the compiler optimize this out
3748 #endif
3749 int len=((demuxer->movi_end-demuxer->movi_start)>>8);
3750 if (len>0 && sh_video){
3751 osd_visible=sh_video->fps; // 1 sec
3752 vo_osd_progbar_type=0;
3753 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
3754 vo_osd_changed(OSDTYPE_PROGBAR);
3758 #endif
3759 if(sh_video) {
3760 c_total=0;
3761 max_pts_correction=0.1;
3762 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3763 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3764 drop_frame_cnt=0;
3765 too_slow_frame_cnt=0;
3766 too_fast_frame_cnt=0;
3768 if(vo_spudec) spudec_reset(vo_spudec);
3771 #ifdef USE_EDL
3773 * We saw a seek, have to rewind the EDL operations stack
3774 * and find the next EDL action to take care of.
3777 edl_muted = 0;
3778 next_edl_record = edl_records;
3780 while (next_edl_record)
3782 /* Trying to remember if we need to mute/unmute first;
3783 * prior EDL implementation lacks this.
3786 if (next_edl_record->start_sec >= sh_video->pts)
3787 break;
3789 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
3790 next_edl_record = next_edl_record->next;
3793 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
3794 #endif
3795 rel_seek_secs=0;
3796 abs_seek_pos=0;
3797 frame_time_remaining=0;
3798 current_module=NULL;
3799 loop_seek=0;
3802 #ifdef HAVE_NEW_GUI
3803 if(use_gui){
3804 guiEventHandling();
3805 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3806 // get pos from frame number / total frames
3807 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3808 } else {
3809 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3810 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3811 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3813 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3814 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3815 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3816 guiGetEvent( guiReDraw,NULL );
3817 guiGetEvent( guiSetVolume,NULL );
3818 if(guiIntfStruct.Playing==0) break; // STOP
3819 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3820 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3821 #ifdef USE_DVDREAD
3822 if ( stream->type == STREAMTYPE_DVD )
3824 dvd_priv_t * dvdp = stream->priv;
3825 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3827 #endif
3829 #endif
3832 //================= Update OSD ====================
3833 #ifdef USE_OSD
3834 if(osd_level>=1 && sh_video){
3835 int pts=sh_video->pts;
3836 char osd_text_tmp[64];
3837 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
3838 vo_osd_text=osd_text_buffer;
3839 #ifdef USE_DVDNAV
3840 if (osd_show_dvd_nav_delay) {
3841 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
3842 osd_show_dvd_nav_delay--;
3843 } else
3844 #endif
3845 #ifdef USE_TV
3846 if (osd_show_tv_channel && tv_channel_list) {
3847 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
3848 osd_show_tv_channel--;
3849 } else
3850 #endif
3851 if (osd_show_text) {
3852 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
3853 osd_show_text--;
3854 } else
3855 if (osd_show_sub_visibility) {
3856 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
3857 osd_show_sub_visibility--;
3858 } else
3859 if (osd_show_vobsub_changed) {
3860 if (vo_vobsub && vobsub_id >= 0) {
3861 const char *language = "none";
3862 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
3863 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
3865 #ifdef HAVE_OGGVORBIS
3866 if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG) {
3867 if (dvdsub_id < 0)
3868 snprintf(osd_text_tmp, 63, "Subtitles: (off)");
3869 else {
3870 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
3871 if (!lang) lang = "unknown";
3872 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3875 #endif
3876 #ifdef USE_DVDREAD
3877 if (vo_spudec && (demuxer->type != DEMUXER_TYPE_MATROSKA)) {
3878 char lang[5] = "none";
3879 int code = 0;
3880 if (dvdsub_id >= 0) code = dvd_lang_from_sid(stream, dvdsub_id);
3881 if (code) {
3882 lang[0] = code >> 8;
3883 lang[1] = code;
3884 lang[2] = 0;
3886 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3888 #endif
3889 #ifdef HAVE_MATROSKA
3890 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3891 char lang[10] = "unknown";
3892 if (dvdsub_id >= 0) {
3893 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
3894 lang[9] = 0;
3895 } else
3896 strcpy(lang, "off");
3897 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3899 #endif
3900 osd_show_vobsub_changed--;
3901 } else
3902 #ifdef USE_SUB
3903 if (osd_show_sub_changed) {
3904 char *tmp2;
3905 tmp = subdata->filename;
3906 if ((tmp2 = strrchr(tmp, '/'))) {
3907 tmp = tmp2+1;
3909 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
3910 set_of_sub_pos + 1,
3911 strlen(tmp) < 20 ? "" : "...",
3912 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
3913 osd_show_sub_changed--;
3914 } else
3915 #endif
3916 if (osd_show_sub_delay) {
3917 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
3918 osd_show_sub_delay--;
3919 } else
3920 if (osd_show_sub_pos) {
3921 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
3922 osd_show_sub_pos--;
3923 } else
3924 if (osd_show_sub_alignment) {
3925 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
3926 (sub_alignment == 2 ? "bottom" :
3927 (sub_alignment == 1 ? "center" : "top")));
3928 osd_show_sub_alignment--;
3929 } else
3930 if (osd_show_av_delay) {
3931 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
3932 osd_show_av_delay--;
3933 } else if (osd_show_speed) {
3934 snprintf(osd_text_tmp, 63, "Speed: x %6.2f", playback_speed);
3935 osd_show_speed--;
3936 } else if (osd_show_ontop) {
3937 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
3938 osd_show_ontop--;
3939 } else if (osd_show_rootwin) {
3940 snprintf(osd_text_tmp, 63, "Rootwin: %sabled", vo_rootwin?"en":"dis");
3941 osd_show_rootwin--;
3942 } else if (osd_show_framedropping) {
3943 snprintf(osd_text_tmp, 63, "Framedropping: %s",
3944 (frame_dropping == 1 ? "on" :
3945 (frame_dropping == 2 ? "hard" : "off")));
3946 osd_show_framedropping--;
3947 } else if(osd_level>=2) {
3948 int len = demuxer_get_time_length(demuxer);
3949 int percentage = -1;
3950 char percentage_text[10];
3951 if (osd_show_percentage) {
3952 percentage = demuxer_get_percent_pos(demuxer);
3953 osd_show_percentage--;
3955 if (percentage >= 0)
3956 snprintf(percentage_text, 9, " (%d%%)", percentage);
3957 else
3958 percentage_text[0] = 0;
3959 if (osd_level == 3)
3960 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);
3961 else
3962 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
3963 } else osd_text_tmp[0]=0;
3965 if(strcmp(vo_osd_text, osd_text_tmp)) {
3966 strncpy(vo_osd_text, osd_text_tmp, 63);
3967 vo_osd_changed(OSDTYPE_OSD);
3969 } else {
3970 if(vo_osd_text) {
3971 vo_osd_text=NULL;
3972 vo_osd_changed(OSDTYPE_OSD);
3975 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3976 // vo_osd_text=osd_text_buffer;
3977 #endif
3979 #ifdef USE_SUB
3980 // find sub
3981 if(subdata && sh_video->pts>0){
3982 float pts=sh_video->pts;
3983 if(sub_fps==0) sub_fps=sh_video->fps;
3984 current_module="find_sub";
3985 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
3986 find_sub(subdata, (pts+sub_delay) *
3987 (subdata->sub_uses_time ? 100. : sub_fps));
3988 // FIXME! frame counter...
3989 sub_last_pts = pts;
3991 current_module=NULL;
3993 #endif
3995 #ifdef HAVE_X11
3996 if (stop_xscreensaver && sh_video) {
3997 current_module="stop_xscreensaver";
3998 xscreensaver_heartbeat();
3999 current_module=NULL;
4001 #endif
4003 // DVD sub:
4004 if(vo_config_count && vo_spudec) {
4005 unsigned char* packet=NULL;
4006 int len,timestamp;
4007 current_module="spudec";
4008 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
4009 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
4010 while(1) {
4011 // Vobsub
4012 len = 0;
4013 if(vo_vobsub) {
4014 if(sh_video->pts+sub_delay>=0) {
4015 // The + next_frame_time is there because we'll display the sub at the next frame
4016 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
4017 if(len > 0) {
4018 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
4019 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);
4022 } else {
4023 // DVD sub
4024 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
4025 if(len > 0) {
4026 float x = d_dvdsub->pts - sh_video->pts;
4027 if (x < -10 || x > 10) // prevent missing subs on pts reset
4028 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
4029 else timestamp = 90000*(sh_video->timer + sub_delay);
4030 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);
4033 if(len<=0 || !packet) break;
4034 if(timestamp < 0) timestamp = 0;
4035 else spudec_assemble(vo_spudec,packet,len,timestamp);
4038 /* detect wether the sub has changed or not */
4039 if(spudec_changed(vo_spudec))
4040 vo_osd_changed(OSDTYPE_SPU);
4041 current_module=NULL;
4044 } // while(!eof)
4046 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
4050 goto_next_file: // don't jump here after ao/vo/getch initialization!
4052 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
4054 if(benchmark){
4055 double tot=video_time_usage+vout_time_usage+audio_time_usage;
4056 double total_time_usage;
4057 total_time_usage_start=GetTimer()-total_time_usage_start;
4058 total_time_usage = (float)total_time_usage_start*0.000001;
4059 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4060 video_time_usage,vout_time_usage,audio_time_usage,
4061 total_time_usage-tot,total_time_usage);
4062 if(total_time_usage>0.0)
4063 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4064 100.0*video_time_usage/total_time_usage,
4065 100.0*vout_time_usage/total_time_usage,
4066 100.0*audio_time_usage/total_time_usage,
4067 100.0*(total_time_usage-tot)/total_time_usage,
4068 100.0);
4069 if(total_frame_cnt && frame_dropping)
4070 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4071 total_frame_cnt-drop_frame_cnt,
4072 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
4073 drop_frame_cnt,
4074 100*drop_frame_cnt/total_frame_cnt,
4075 total_frame_cnt,
4076 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
4080 // time to uninit all, except global stuff:
4081 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
4083 #ifdef USE_SUB
4084 if ( set_of_sub_size > 0 )
4086 current_module="sub_free";
4087 for (i = 0; i < set_of_sub_size; ++i)
4088 sub_free( set_of_subtitles[i] );
4089 set_of_sub_size = 0;
4090 vo_sub=NULL;
4091 subdata=NULL;
4093 #endif
4095 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
4096 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
4097 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
4098 eof = 1;
4099 } else {
4100 play_tree_iter_free(playtree_iter);
4101 playtree_iter = NULL;
4103 play_tree_step = 1;
4104 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
4105 eof = eof == PT_UP_NEXT ? 1 : -1;
4106 if ( playtree_iter ) {
4107 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
4108 eof = 1;
4109 } else {
4110 play_tree_iter_free(playtree_iter);
4111 playtree_iter = NULL;
4114 } else { // NEXT PREV SRC
4115 eof = eof == PT_PREV_SRC ? -1 : 1;
4118 if(eof == 0) eof = 1;
4120 while(playtree_iter != NULL) {
4121 filename = play_tree_iter_get_file(playtree_iter,eof);
4122 if(filename == NULL) {
4123 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
4124 play_tree_iter_free(playtree_iter);
4125 playtree_iter = NULL;
4127 } else
4128 break;
4131 #ifdef HAVE_NEW_GUI
4132 if( use_gui && !playtree_iter )
4134 #ifdef USE_DVDREAD
4135 if ( !guiIntfStruct.DiskChanged )
4136 #endif
4137 mplEnd();
4139 #endif
4141 if(use_gui || playtree_iter != NULL){
4143 eof = 0;
4144 goto play_next_file;
4148 exit_player_with_rc(MSGTR_Exit_eof, 0);
4150 return 1;