10000l : fix a crash on x86 due to an horrible mistake in my x86_64 patch
[mplayer.git] / mplayer.c
blob6d132c410c71a5fd6cfd33b408088de5d496189c
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 edl_decision = 0; /// 1 when an EDL operation has been made
364 FILE* edl_fd = NULL; /// fd to write to when in -edlout mode
365 int edl_mute_count = 0; /// even number when mute and unmute has been matched
366 #endif
368 static unsigned int inited_flags=0;
369 #define INITED_VO 1
370 #define INITED_AO 2
371 #define INITED_GUI 4
372 #define INITED_GETCH2 8
373 #define INITED_SPUDEC 32
374 #define INITED_STREAM 64
375 #define INITED_INPUT 128
376 #define INITED_VOBSUB 256
377 #define INITED_DEMUXER 512
378 #define INITED_ACODEC 1024
379 #define INITED_VCODEC 2048
380 #define INITED_ALL 0xFFFF
382 static void uninit_player(unsigned int mask){
383 mask=inited_flags&mask;
385 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
387 if(mask&INITED_ACODEC){
388 inited_flags&=~INITED_ACODEC;
389 current_module="uninit_acodec";
390 if(sh_audio) uninit_audio(sh_audio);
391 sh_audio=NULL;
394 if(mask&INITED_VCODEC){
395 inited_flags&=~INITED_VCODEC;
396 current_module="uninit_vcodec";
397 if(sh_video) uninit_video(sh_video);
398 sh_video=NULL;
399 #ifdef HAVE_MENU
400 vf_menu=NULL;
401 #endif
404 if(mask&INITED_DEMUXER){
405 inited_flags&=~INITED_DEMUXER;
406 current_module="free_demuxer";
407 if(demuxer){
408 stream=demuxer->stream;
409 free_demuxer(demuxer);
411 demuxer=NULL;
414 // kill the cache process:
415 if(mask&INITED_STREAM){
416 inited_flags&=~INITED_STREAM;
417 current_module="uninit_stream";
418 if(stream) free_stream(stream);
419 stream=NULL;
422 if(mask&INITED_VO){
423 inited_flags&=~INITED_VO;
424 current_module="uninit_vo";
425 video_out->uninit();
426 video_out=NULL;
429 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
430 if(mask&INITED_GETCH2){
431 inited_flags&=~INITED_GETCH2;
432 current_module="uninit_getch2";
433 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
434 // restore terminal:
435 getch2_disable();
438 if(mask&INITED_VOBSUB){
439 inited_flags&=~INITED_VOBSUB;
440 current_module="uninit_vobsub";
441 if(vo_vobsub) vobsub_close(vo_vobsub);
442 vo_vobsub=NULL;
445 if (mask&INITED_SPUDEC){
446 inited_flags&=~INITED_SPUDEC;
447 current_module="uninit_spudec";
448 spudec_free(vo_spudec);
449 vo_spudec=NULL;
452 if(mask&INITED_AO){
453 inited_flags&=~INITED_AO;
454 current_module="uninit_ao";
455 audio_out->uninit(eof?0:1); audio_out=NULL;
458 #ifdef HAVE_NEW_GUI
459 if(mask&INITED_GUI){
460 inited_flags&=~INITED_GUI;
461 current_module="uninit_gui";
462 guiDone();
464 #endif
466 if(mask&INITED_INPUT){
467 inited_flags&=~INITED_INPUT;
468 current_module="uninit_input";
469 mp_input_uninit();
472 current_module=NULL;
475 static void exit_player_with_rc(char* how, int rc){
477 uninit_player(INITED_ALL);
478 #ifdef HAVE_X11
479 #ifdef HAVE_NEW_GUI
480 if ( !use_gui )
481 #endif
482 vo_uninit(); // close the X11 connection (if any opened)
483 #endif
485 current_module="exit_player";
487 #ifdef USE_EDL
488 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
489 #endif
490 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));
491 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
493 exit(rc);
496 void exit_player(char* how){
497 exit_player_with_rc(how, 1);
500 #ifndef __MINGW32__
501 static void child_sighandler(int x){
502 pid_t pid;
503 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
505 #endif
507 static void exit_sighandler(int x){
508 static int sig_count=0;
509 ++sig_count;
510 if(inited_flags==0 && sig_count>1) exit(1);
511 if(sig_count==5)
513 /* We're crashing bad and can't uninit cleanly :(
514 * by popular request, we make one last (dirty)
515 * effort to restore the user's
516 * terminal. */
517 getch2_disable();
518 exit(1);
520 if(sig_count==6) exit(1);
521 if(sig_count>6){
522 // can't stop :(
523 #ifndef __MINGW32__
524 kill(getpid(),SIGKILL);
525 #endif
527 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
528 current_module?current_module:mp_gettext("unknown")
530 if(sig_count==1)
531 switch(x){
532 case SIGINT:
533 case SIGQUIT:
534 case SIGTERM:
535 case SIGKILL:
536 break; // killed from keyboard (^C) or killed [-9]
537 case SIGILL:
538 #ifdef RUNTIME_CPUDETECT
539 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
540 #else
541 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
542 #endif
543 case SIGFPE:
544 case SIGSEGV:
545 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
546 default:
547 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
549 exit_player(NULL);
552 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
554 extern void mp_input_register_options(m_config_t* cfg);
556 #include "mixer.h"
557 mixer_t mixer;
558 /// step size of mixer changes
559 int volstep = 3;
561 #include "cfg-mplayer.h"
563 void parse_cfgfiles( m_config_t* conf )
565 char *conffile;
566 int conffile_fd;
567 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
568 exit_player(NULL);
569 if ((conffile = get_path("")) == NULL) {
570 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
571 } else {
572 #ifdef __MINGW32__
573 mkdir(conffile);
574 #else
575 mkdir(conffile, 0777);
576 #endif
577 free(conffile);
578 if ((conffile = get_path("config")) == NULL) {
579 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
580 } else {
581 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
582 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
583 write(conffile_fd, default_config, strlen(default_config));
584 close(conffile_fd);
586 if (m_config_parse_config_file(conf, conffile) < 0)
587 exit_player(NULL);
588 free(conffile);
593 void load_per_file_config (m_config_t* conf, const char *const file)
595 char *confpath;
596 char cfg[strlen(file)+10];
597 struct stat st;
598 char *name;
600 sprintf (cfg, "%s.conf", file);
602 if (!stat (cfg, &st))
604 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
605 m_config_parse_config_file (conf, cfg);
606 return;
609 if ((name = strrchr (cfg, '/')) == NULL)
610 name = cfg;
611 else
612 name++;
614 if ((confpath = get_path (name)) != NULL)
616 if (!stat (confpath, &st))
618 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
619 m_config_parse_config_file (conf, confpath);
622 free (confpath);
626 // When libmpdemux perform a blocking operation (network connection or cache filling)
627 // if the operation fail we use this function to check if it was interrupted by the user.
628 // The function return a new value for eof.
629 static int libmpdemux_was_interrupted(int eof) {
630 mp_cmd_t* cmd;
631 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
632 switch(cmd->id) {
633 case MP_CMD_QUIT:
634 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
635 case MP_CMD_PLAY_TREE_STEP: {
636 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
637 } break;
638 case MP_CMD_PLAY_TREE_UP_STEP: {
639 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
640 } break;
641 case MP_CMD_PLAY_ALT_SRC_STEP: {
642 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
643 } break;
645 mp_cmd_free(cmd);
647 return eof;
650 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
651 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
653 int playtree_add_playlist(play_tree_t* entry)
655 play_tree_add_bpf(entry,filename);
657 #ifdef HAVE_NEW_GUI
658 if (use_gui) {
659 if (entry) {
660 import_playtree_playlist_into_gui(entry, mconfig);
661 play_tree_free_list(entry,1);
663 } else
664 #endif
666 if(!entry) {
667 entry = playtree_iter->tree;
668 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
669 return PT_NEXT_ENTRY;
671 if(playtree_iter->tree == entry ) { // Loop with a single file
672 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
673 return PT_NEXT_ENTRY;
676 play_tree_remove(entry,1,1);
677 return PT_NEXT_SRC;
679 play_tree_insert_entry(playtree_iter->tree,entry);
680 play_tree_set_params_from(entry,playtree_iter->tree);
681 entry = playtree_iter->tree;
682 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
683 return PT_NEXT_ENTRY;
685 play_tree_remove(entry,1,1);
687 return PT_NEXT_SRC;
690 static int play_tree_step = 1;
692 int sub_source()
694 int source = -1;
695 int top = -1;
696 int i;
697 for (i = 0; i < SUB_SOURCES; i++) {
698 int j = global_sub_indices[i];
699 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
700 source = i;
701 top = j;
704 return source;
707 #ifdef USE_SUB
709 sub_data* subdata = NULL;
711 void add_subtitles(char *filename, float fps, int silent)
713 sub_data *subd;
715 if (filename == NULL) {
716 return;
719 subd = sub_read_file(filename, fps);
720 if(!subd && !silent)
721 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
722 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
723 set_of_subtitles[set_of_sub_size] = subd;
724 ++set_of_sub_size;
725 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
728 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
729 void update_set_of_subtitles()
730 // subdata was changed, set_of_sub... have to be updated.
732 int i;
733 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
734 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
735 set_of_subtitles[i-1] = set_of_subtitles[i];
736 set_of_subtitles[set_of_sub_size-1] = NULL;
737 --set_of_sub_size;
738 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
740 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
741 set_of_subtitles[set_of_sub_pos] = subdata;
743 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
744 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
745 ++set_of_sub_size;
748 #endif
751 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
752 * make it all work is to use the builtin SDL-bootstrap code, which
753 * will be done automatically by replacing our main() if we include SDL.h.
755 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
756 #include <SDL.h>
757 #endif
760 * \brief build a chain of audio filters that converts the input format
761 * to the ao's format, taking into account the current playback_speed.
762 * \param sh_audio describes the requested input format of the chain.
763 * \param ao_data describes the requested output format of the chain.
765 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
767 int new_srate = sh_audio->samplerate * playback_speed;
768 if (!sh_audio)
769 return 0;
770 if (new_srate != ao_data->samplerate) {
771 // limits are taken from libaf/af_resample.c
772 if (new_srate < 8000)
773 new_srate = 8000;
774 if (new_srate > 192000)
775 new_srate = 192000;
776 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
778 return init_audio_filters(sh_audio, new_srate,
779 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
780 ao_data->samplerate, ao_data->channels, ao_data->format,
781 audio_out_format_bits(ao_data->format) / 8, /* ao_data.bps, */
782 ao_data->outburst * 4, ao_data->buffersize);
785 int main(int argc,char* argv[]){
788 char * mem_ptr;
790 static demux_stream_t *d_audio=NULL;
791 static demux_stream_t *d_video=NULL;
792 static demux_stream_t *d_dvdsub=NULL;
794 int file_format=DEMUXER_TYPE_UNKNOWN;
796 int delay_corrected=1;
798 // movie info:
800 int osd_function=OSD_PLAY;
801 int osd_last_pts=-303;
802 int osd_show_av_delay = 0;
803 int osd_show_text = 0;
804 int osd_show_speed = 0;
805 int osd_show_sub_delay = 0;
806 int osd_show_sub_pos = 0;
807 int osd_show_sub_visibility = 0;
808 int osd_show_sub_alignment = 0;
809 int osd_show_vobsub_changed = 0;
810 int osd_show_sub_changed = 0;
811 int osd_show_percentage = 0;
812 int osd_show_tv_channel = 25;
813 int osd_show_ontop = 0;
814 int osd_show_rootwin = 0;
815 int osd_show_framedropping = 0;
817 int rtc_fd=-1;
819 //float a_frame=0; // Audio
821 int i;
822 char *tmp;
824 int gui_no_filename=0;
827 srand((int) time(NULL));
829 mp_msg_init();
830 mp_msg_set_level(MSGL_STATUS);
832 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2004 MPlayer Team\n\n");
833 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
834 GetCpuCaps(&gCpuCaps);
835 #ifdef ARCH_X86
836 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
837 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
838 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
839 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
840 #ifdef RUNTIME_CPUDETECT
841 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
842 #else
843 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
844 #ifdef HAVE_MMX
845 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
846 #endif
847 #ifdef HAVE_MMX2
848 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
849 #endif
850 #ifdef HAVE_3DNOW
851 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
852 #endif
853 #ifdef HAVE_3DNOWEX
854 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
855 #endif
856 #ifdef HAVE_SSE
857 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
858 #endif
859 #ifdef HAVE_SSE2
860 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
861 #endif
862 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
863 #endif
864 #endif
866 #if defined(WIN32) && defined(USE_WIN32DLL)
867 { /*make our codec dirs available for LoadLibraryA()*/
868 char tmppath[MAX_PATH*2 + 1];
869 char win32path[MAX_PATH];
870 char realpath[MAX_PATH];
871 #ifdef __CYGWIN__
872 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
873 strcpy(tmppath,win32path);
874 #ifdef USE_REALCODECS
875 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
876 sprintf(tmppath,"%s;%s",win32path,realpath);
877 #endif /*USE_REALCODECS*/
878 #else
879 if(!strstr(WIN32_PATH,":")){
880 GetModuleFileNameA(NULL, win32path, MAX_PATH);
881 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
883 else strcpy(win32path,WIN32_PATH);
884 strcpy(tmppath,win32path);
885 #ifdef USE_REALCODECS
886 if(!strstr(REALCODEC_PATH,":")){
887 GetModuleFileNameA(NULL, realpath, MAX_PATH);
888 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
890 else strcpy(realpath,REALCODEC_PATH);
891 sprintf(tmppath,"%s;%s",win32path,realpath);
892 #endif /*USE_REALCODECS*/
893 #endif /*__CYGWIN__*/
894 SetEnvironmentVariableA("PATH", tmppath);
896 #endif /*WIN32 && USE_WIN32DLL*/
898 #ifdef USE_TV
899 tv_param_immediate = 1;
900 #endif
902 if ( argv[0] )
903 if(!strcmp(argv[0],"gmplayer") ||
904 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
905 use_gui=1;
907 mconfig = m_config_new();
908 m_config_register_options(mconfig,mplayer_opts);
909 // TODO : add something to let modules register their options
910 mp_input_register_options(mconfig);
911 parse_cfgfiles(mconfig);
913 #ifdef HAVE_NEW_GUI
914 if ( use_gui ) cfg_read();
915 #endif
917 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
918 if(playtree == NULL)
919 exit_player(NULL);
921 playtree = play_tree_cleanup(playtree);
922 if(playtree) {
923 playtree_iter = play_tree_iter_new(playtree,mconfig);
924 if(playtree_iter) {
925 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
926 play_tree_iter_free(playtree_iter);
927 playtree_iter = NULL;
929 filename = play_tree_iter_get_file(playtree_iter,1);
933 #ifndef HAVE_NEW_GUI
934 if(use_gui){
935 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
936 use_gui=0;
938 #else
939 if(use_gui && !vo_init()){
940 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
941 use_gui=0;
943 if (use_gui && playtree_iter){
944 char cwd[PATH_MAX+2];
945 // Remove Playtree and Playtree-Iter from memory as its not used by gui
946 play_tree_iter_free(playtree_iter);
947 playtree_iter=NULL;
949 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
951 strcat(cwd, "/");
952 // Prefix relative paths with current working directory
953 play_tree_add_bpf(playtree, cwd);
955 // Import initital playtree into gui
956 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
958 #endif
960 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
961 list_video_out();
962 exit_player_with_rc(NULL, 0);
965 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
966 list_audio_out();
967 exit_player_with_rc(NULL, 0);
970 // check codec.conf
971 if(!codecs_file || !parse_codec_cfg(codecs_file)){
972 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
973 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
974 if(!parse_codec_cfg(NULL)){
975 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
976 exit_player_with_rc(NULL, 0);
978 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_BuiltinCodecsConf);
981 free( mem_ptr ); // release the buffer created by get_path()
984 #if 0
985 if(video_codec_list){
986 int i;
987 video_codec=video_codec_list[0];
988 for(i=0;video_codec_list[i];i++)
989 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
991 #endif
992 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
993 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
994 list_codecs(1);
995 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
996 exit_player_with_rc(NULL, 0);
998 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
999 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
1000 list_codecs(0);
1001 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1002 exit_player_with_rc(NULL, 0);
1004 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
1005 vfm_help();
1006 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1007 exit_player_with_rc(NULL, 0);
1009 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
1010 afm_help();
1011 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1012 exit_player_with_rc(NULL, 0);
1014 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
1015 af_help();
1016 printf("\n");
1017 exit_player_with_rc(NULL, 0);
1019 #ifdef HAVE_X11
1020 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
1021 fstype_help();
1022 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1023 exit_player_with_rc(NULL, 0);
1025 #endif
1027 #ifdef USE_EDL
1028 if (edl_check_mode() == EDL_ERROR && edl_filename)
1030 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantUseBothModes);
1031 exit_player(NULL);
1032 } else if (edl_filename)
1034 edl_memory_slots = edl_count_entries();
1035 if (edl_memory_slots > 0)
1037 edl_records = calloc(edl_memory_slots, sizeof(struct edl_record));
1038 if (edl_records == NULL)
1040 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_EdlOutOfMem);
1041 exit_player(NULL);
1042 } else
1044 if ((edl_operations = edl_parse_file(edl_records)) > 0)
1046 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlRecordsNo,
1047 edl_operations);
1048 } else
1051 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlQueueEmpty);
1056 next_edl_record = edl_records;
1058 } else if (edl_output_filename)
1060 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
1062 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
1063 edl_output_filename);
1064 exit_player(NULL);
1067 #endif
1069 if(!filename){
1070 if(!use_gui){
1071 // no file/vcd/dvd -> show HELP:
1072 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1073 exit_player_with_rc(NULL, 0);
1074 } else gui_no_filename=1;
1077 // Many users forget to include command line in bugreports...
1078 if(verbose>0){
1079 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
1080 for(i=1;i<argc;i++)mp_msg(MSGT_FIXME, MSGL_FIXME," '%s'",argv[i]);
1081 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1084 mp_msg_set_level(verbose+MSGL_STATUS);
1086 //------ load global data first ------
1088 // check font
1089 #ifdef USE_OSD
1090 #ifdef HAVE_FREETYPE
1091 init_freetype();
1092 #endif
1093 #ifdef HAVE_FONTCONFIG
1094 if(!font_fontconfig)
1096 #endif
1097 if(font_name){
1098 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1099 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1100 } else {
1101 // try default:
1102 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
1103 free(mem_ptr); // release the buffer created by get_path()
1104 if(!vo_font)
1105 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1107 #ifdef HAVE_FONTCONFIG
1109 #endif
1110 #endif
1111 vo_init_osd();
1113 #ifdef HAVE_RTC
1114 if(!nortc)
1116 // seteuid(0); /* Can't hurt to try to get root here */
1117 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
1118 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
1119 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
1120 else {
1121 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1123 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1124 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
1125 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
1126 close (rtc_fd);
1127 rtc_fd = -1;
1128 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1129 /* variable only by the root */
1130 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
1131 close (rtc_fd);
1132 rtc_fd = -1;
1133 } else
1134 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_UsingRTCTiming, irqp);
1137 #ifdef HAVE_NEW_GUI
1138 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1139 // and now ? -- Pontscho
1140 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1141 #endif
1142 if(rtc_fd<0)
1143 #endif
1144 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Using %s timing\n",
1145 softsleep?"software":timer_name);
1147 #ifdef USE_TERMCAP
1148 if ( !use_gui ) load_termcap(NULL); // load key-codes
1149 #endif
1151 // ========== Init keyboard FIFO (connection to libvo) ============
1153 // Init input system
1154 current_module = "init_input";
1155 mp_input_init();
1156 #ifndef HAVE_NO_POSIX_SELECT
1157 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1159 if(keyb_fifo_get > 0)
1160 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1161 #else
1162 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1163 #endif
1164 if(slave_mode)
1165 #ifndef __MINGW32__
1166 mp_input_add_cmd_fd(0,1,NULL,NULL);
1167 #else
1168 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1169 #endif
1170 else if(!noconsolecontrols)
1171 #ifndef HAVE_NO_POSIX_SELECT
1172 mp_input_add_key_fd(0,1,NULL,NULL);
1173 #else
1174 mp_input_add_key_fd(0,0,NULL,NULL);
1175 #endif
1177 inited_flags|=INITED_INPUT;
1178 current_module = NULL;
1180 #ifdef HAVE_MENU
1181 if(use_menu) {
1182 if(menu_cfg && menu_init(menu_cfg))
1183 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1184 else {
1185 menu_cfg = get_path("menu.conf");
1186 if(menu_init(menu_cfg))
1187 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1188 else {
1189 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1190 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
1191 else {
1192 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
1193 use_menu = 0;
1198 #endif
1200 /// Catch signals
1201 #ifndef __MINGW32__
1202 signal(SIGCHLD,child_sighandler);
1203 #endif
1205 //========= Catch terminate signals: ================
1206 // terminate requests:
1207 signal(SIGTERM,exit_sighandler); // kill
1208 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1210 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1212 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1213 #ifdef ENABLE_SIGHANDLER
1214 // fatal errors:
1215 signal(SIGBUS,exit_sighandler); // bus error
1216 signal(SIGSEGV,exit_sighandler); // segfault
1217 signal(SIGILL,exit_sighandler); // illegal instruction
1218 signal(SIGFPE,exit_sighandler); // floating point exc.
1219 signal(SIGABRT,exit_sighandler); // abort()
1220 #endif
1222 #ifdef HAVE_NEW_GUI
1223 if(use_gui){
1224 guiInit();
1225 inited_flags|=INITED_GUI;
1226 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1228 #endif
1230 // ******************* Now, let's see the per-file stuff ********************
1232 play_next_file:
1234 // init global sub numbers
1235 global_sub_size = 0;
1236 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
1237 global_sub_quiet_osd_hack = 1;
1239 if (filename) load_per_file_config (mconfig, filename);
1241 // We must enable getch2 here to be able to interrupt network connection
1242 // or cache filling
1243 if(!noconsolecontrols && !slave_mode){
1244 if(inited_flags&INITED_GETCH2)
1245 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
1246 else
1247 getch2_enable(); // prepare stdin for hotkeys...
1248 inited_flags|=INITED_GETCH2;
1249 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1252 // =================== GUI idle loop (STOP state) ===========================
1253 #ifdef HAVE_NEW_GUI
1254 if ( use_gui ) {
1255 file_format=DEMUXER_TYPE_UNKNOWN;
1256 guiGetEvent( guiSetDefaults,0 );
1257 while ( guiIntfStruct.Playing != 1 )
1259 mp_cmd_t* cmd;
1260 usec_sleep(20000);
1261 guiEventHandling();
1262 guiGetEvent( guiReDraw,NULL );
1263 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1265 guiGetEvent( guiSetParameters,NULL );
1266 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1268 play_tree_t * entry = play_tree_new();
1269 play_tree_add_file( entry,guiIntfStruct.Filename );
1270 if ( playtree ) play_tree_free_list( playtree->child,1 );
1271 else playtree=play_tree_new();
1272 play_tree_set_child( playtree,entry );
1273 if(playtree)
1275 playtree_iter = play_tree_iter_new(playtree,mconfig);
1276 if(playtree_iter)
1278 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1280 play_tree_iter_free(playtree_iter);
1281 playtree_iter = NULL;
1283 filename = play_tree_iter_get_file(playtree_iter,1);
1288 #endif
1289 //---------------------------------------------------------------------------
1291 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
1292 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1294 //==================== Open VOB-Sub ============================
1296 current_module="vobsub";
1297 if (vobsub_name){
1298 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1299 if(vo_vobsub==NULL)
1300 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1301 }else if(sub_auto && filename && (strlen(filename)>=5)){
1302 /* try to autodetect vobsub from movie filename ::atmos */
1303 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1304 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1305 strncpy(buf, filename, strlen(filename)-4);
1306 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1307 free(buf);
1309 if(vo_vobsub){
1310 inited_flags|=INITED_VOBSUB;
1311 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1312 // check if vobsub requested only to display forced subtitles
1313 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1315 // setup global sub numbering
1316 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
1317 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
1320 //============ Open & Sync STREAM --- fork cache2 ====================
1322 stream=NULL;
1323 demuxer=NULL;
1324 if (d_audio) {
1325 //free_demuxer_stream(d_audio);
1326 d_audio=NULL;
1328 if (d_video) {
1329 //free_demuxer_stream(d_video);
1330 d_video=NULL;
1332 sh_audio=NULL;
1333 sh_video=NULL;
1335 current_module="open_stream";
1336 stream=open_stream(filename,0,&file_format);
1337 if(!stream) { // error...
1338 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1339 goto goto_next_file;
1341 inited_flags|=INITED_STREAM;
1343 #ifdef HAVE_NEW_GUI
1344 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1345 #endif
1347 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1348 play_tree_t* entry;
1349 // Handle playlist
1350 current_module="handle_playlist";
1351 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1352 entry = parse_playtree(stream,0);
1353 eof=playtree_add_playlist(entry);
1354 goto goto_next_file;
1356 stream->start_pos+=seek_to_byte;
1358 if(stream_dump_type==5){
1359 unsigned char buf[4096];
1360 int len;
1361 FILE *f;
1362 current_module="dumpstream";
1363 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1364 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
1365 exit_player(MSGTR_Exit_error);
1367 stream_reset(stream);
1368 stream_seek(stream,stream->start_pos);
1369 f=fopen(stream_dump_name,"wb");
1370 if(!f){
1371 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1372 exit_player(MSGTR_Exit_error);
1374 while(!stream->eof){
1375 len=stream_read(stream,buf,4096);
1376 if(len>0) {
1377 if(fwrite(buf,len,1,f) != 1) {
1378 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1379 exit_player(MSGTR_Exit_error);
1383 if(fclose(f)) {
1384 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1385 exit_player(MSGTR_Exit_error);
1387 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1388 exit_player_with_rc(MSGTR_Exit_eof, 0);
1391 #ifdef USE_DVDREAD
1392 if(stream->type==STREAMTYPE_DVD){
1393 current_module="dvd lang->id";
1394 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1395 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1396 // setup global sub numbering
1397 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1398 global_sub_size += dvd_number_of_subs(stream);
1399 current_module=NULL;
1401 #endif
1403 #ifdef USE_DVDNAV
1404 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1405 #endif
1407 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1408 #ifdef HAS_DVBIN_SUPPORT
1409 goto_enable_cache:
1410 #endif
1411 if(stream_cache_size>0){
1412 current_module="enable_cache";
1413 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)))
1414 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1417 //============ Open DEMUXERS --- DETECT file type =======================
1418 current_module="demux_open";
1420 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1422 // HACK to get MOV Reference Files working
1424 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1426 unsigned char* playlist_entry;
1427 play_tree_t *list = NULL, *entry = NULL;
1429 current_module="handle_demux_playlist";
1430 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1432 char *temp, *bname;
1434 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
1436 bname=mp_basename(playlist_entry);
1437 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1438 continue;
1440 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1441 continue;
1443 entry = play_tree_new();
1445 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1447 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1448 if (temp)
1450 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1451 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1452 strcat(temp, playlist_entry);
1453 play_tree_add_file(entry,temp);
1454 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
1455 free(temp);
1458 else
1459 play_tree_add_file(entry,playlist_entry);
1461 if(!list)
1462 list = entry;
1463 else
1464 play_tree_append_entry(list,entry);
1466 free_demuxer(demuxer);
1467 demuxer = NULL;
1469 if (list)
1471 entry = play_tree_new();
1472 play_tree_set_child(entry,list);
1473 eof=playtree_add_playlist(entry);
1474 goto goto_next_file;
1478 if(!demuxer)
1480 #if 0
1481 play_tree_t* entry;
1482 // Handle playlist
1483 current_module="handle_playlist";
1484 switch(stream->type){
1485 case STREAMTYPE_VCD:
1486 case STREAMTYPE_DVD:
1487 case STREAMTYPE_DVDNAV:
1488 case STREAMTYPE_CDDA:
1489 case STREAMTYPE_VCDBINCUE:
1490 // don't try to parse raw media as playlist, it's unlikely
1491 goto goto_next_file;
1493 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
1494 stream_reset(stream);
1495 stream_seek(stream,stream->start_pos);
1496 entry = parse_playtree(stream,0);
1497 if(!entry)
1498 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1499 else
1500 eof=playtree_add_playlist(entry);
1501 #endif
1502 goto goto_next_file;
1504 inited_flags|=INITED_DEMUXER;
1506 #ifdef HAVE_MATROSKA
1507 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
1508 // setup global sub numbering
1509 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1510 global_sub_size += demux_mkv_num_subs(demuxer);
1512 #endif
1513 #ifdef HAVE_OGGVORBIS
1514 if (demuxer->type==DEMUXER_TYPE_OGG) {
1515 // setup global sub numbering
1516 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1517 global_sub_size += demux_ogg_num_subs(demuxer);
1519 #endif
1521 current_module="demux_open2";
1523 //file_format=demuxer->file_format;
1525 d_audio=demuxer->audio;
1526 d_video=demuxer->video;
1527 d_dvdsub=demuxer->sub;
1529 // DUMP STREAMS:
1530 if((stream_dump_type)&&(stream_dump_type<4)){
1531 FILE *f;
1532 demux_stream_t *ds=NULL;
1533 current_module="dump";
1534 // select stream to dump
1535 switch(stream_dump_type){
1536 case 1: ds=d_audio;break;
1537 case 2: ds=d_video;break;
1538 case 3: ds=d_dvdsub;break;
1540 if(!ds){
1541 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1542 exit_player(MSGTR_Exit_error);
1544 // disable other streams:
1545 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1546 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1547 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1548 // let's dump it!
1549 f=fopen(stream_dump_name,"wb");
1550 if(!f){
1551 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1552 exit_player(MSGTR_Exit_error);
1554 while(!ds->eof){
1555 unsigned char* start;
1556 int in_size=ds_get_packet(ds,&start);
1557 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1558 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1559 if(in_size>0) fwrite(start,in_size,1,f);
1561 fclose(f);
1562 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1563 exit_player_with_rc(MSGTR_Exit_eof, 0);
1566 sh_audio=d_audio->sh;
1567 sh_video=d_video->sh;
1569 if(sh_video){
1571 current_module="video_read_properties";
1572 if(!video_read_properties(sh_video)) {
1573 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1574 sh_video=d_video->sh=NULL;
1575 } else {
1576 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1577 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1578 sh_video->fps,sh_video->frametime
1581 /* need to set fps here for output encoders to pick it up in their init */
1582 if(force_fps){
1583 sh_video->fps=force_fps;
1584 sh_video->frametime=1.0f/sh_video->fps;
1586 vo_fps = sh_video->fps;
1587 #ifdef HAVE_X11
1588 vo_mouse_timer_const=(int)sh_video->fps;
1589 #endif
1591 if(!sh_video->fps && !force_fps){
1592 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1593 sh_video=d_video->sh=NULL;
1599 fflush(stdout);
1601 if(!sh_video && !sh_audio){
1602 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1603 #ifdef HAS_DVBIN_SUPPORT
1604 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1606 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1607 if(priv->is_on)
1609 int dir;
1610 int v = last_dvb_step;
1611 if(v > 0)
1612 dir = DVB_CHANNEL_HIGHER;
1613 else
1614 dir = DVB_CHANNEL_LOWER;
1616 if(dvb_step_channel(priv, dir))
1618 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1619 cache_uninit(stream);
1620 goto goto_enable_cache;
1624 #endif
1625 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1628 /* display clip info */
1629 demux_info_print(demuxer);
1631 //================== Read SUBTITLES (DVD & TEXT) ==========================
1632 if(vo_spudec==NULL && sh_video && (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA)){
1634 if (spudec_ifo) {
1635 unsigned int palette[16], width, height;
1636 current_module="spudec_init_vobsub";
1637 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1638 vo_spudec=spudec_new_scaled(palette, width, height);
1641 #ifdef USE_DVDNAV
1642 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1643 current_module="spudec_init_dvdnav";
1644 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1645 sh_video->disp_w, sh_video->disp_h);
1647 #endif
1649 #ifdef USE_DVDREAD
1650 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1651 current_module="spudec_init_dvdread";
1652 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1653 sh_video->disp_w, sh_video->disp_h);
1655 #endif
1657 #ifdef HAVE_MATROSKA
1658 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1659 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1660 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
1661 current_module = "spudec_init_matroska";
1662 vo_spudec =
1663 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1664 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1665 mkv_sh_sub->height);
1666 forced_subs_only = mkv_sh_sub->forced_subs_only;
1668 #endif
1670 if (vo_spudec==NULL) {
1671 current_module="spudec_init_normal";
1672 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1673 spudec_set_font_factor(vo_spudec,font_factor);
1676 if (vo_spudec!=NULL)
1677 inited_flags|=INITED_SPUDEC;
1681 // Apply current settings for forced subs
1682 if (vo_spudec!=NULL)
1683 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1685 #ifdef USE_SUB
1686 if(sh_video) {
1687 // after reading video params we should load subtitles because
1688 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1689 // check .sub
1690 current_module="read_subtitles_file";
1691 if(sub_name){
1692 for (i = 0; sub_name[i] != NULL; ++i)
1693 add_subtitles (sub_name[i], sh_video->fps, 0);
1695 if(sub_auto) { // auto load sub file ...
1696 char *psub = get_path( "sub/" );
1697 char **tmp = sub_filenames((psub ? psub : ""), filename);
1698 char **tmp2 = tmp;
1699 free(psub); // release the buffer created by get_path() above
1700 while (*tmp2)
1701 add_subtitles (*tmp2++, sh_video->fps, 0);
1702 free(tmp);
1703 if (set_of_sub_size == 0)
1705 add_subtitles (mem_ptr=get_path("default.sub"), sh_video->fps, 1);
1706 free(mem_ptr); // release the buffer created by get_path()
1708 if (set_of_sub_size > 0)
1709 add_subtitles (NULL, sh_video->fps, 1);
1711 if (set_of_sub_size > 0) {
1712 // setup global sub numbering
1713 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
1714 global_sub_size += set_of_sub_size;
1717 #endif
1719 if (global_sub_size) {
1720 // find the best sub to use
1721 if (vobsub_id >= 0) {
1722 // if user asks for a vobsub id, use that first.
1723 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
1724 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1725 // if user asks for a dvd sub id, use that next.
1726 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
1727 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
1728 // if there are text subs to use, use those. (autosubs come last here)
1729 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
1731 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1732 // if nothing else works, get subs from the demuxer.
1733 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1735 } else {
1736 // nothing worth doing automatically.
1737 global_sub_pos = -1;
1739 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1740 global_sub_pos--;
1741 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1744 //================== Init AUDIO (codec) ==========================
1745 if(sh_audio){
1746 // Go through the codec.conf and find the best codec...
1747 current_module="init_audio_codec";
1748 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1749 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1750 sh_audio=d_audio->sh=NULL; // failed to init :(
1751 } else
1752 inited_flags|=INITED_ACODEC;
1753 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1756 if(identify) {
1757 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
1758 if (sh_video) {
1759 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1760 if (sh_video->format >= 0x20202020)
1761 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
1762 else
1763 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
1764 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
1765 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
1766 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
1767 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
1768 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
1770 if (sh_audio) {
1771 if (sh_audio->codec)
1772 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
1773 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1774 if (sh_audio->format >= 0x20202020)
1775 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
1776 else
1777 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
1778 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
1779 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
1780 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
1782 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
1785 if(!sh_video) goto main; // audio-only
1787 //================== Init VIDEO (codec & libvo) ==========================
1788 if(!fixed_vo || !(inited_flags&INITED_VO)){
1789 current_module="preinit_libvo";
1791 vo_config_count=0;
1792 //if((video_out->preinit(vo_subdevice))!=0){
1793 if(!(video_out=init_best_video_out(video_driver_list))){
1794 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
1795 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1797 sh_video->video_out=video_out;
1798 inited_flags|=INITED_VO;
1801 current_module="init_video_filters";
1803 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
1804 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
1806 #ifdef HAVE_MENU
1807 if(use_menu) {
1808 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
1809 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
1810 if(!vf_menu) {
1811 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
1812 use_menu = 0;
1815 if(vf_menu)
1816 sh_video->vfilter=(void*)append_filters(vf_menu);
1817 else
1818 #endif
1819 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
1821 current_module="init_video_codec";
1823 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1824 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
1825 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1827 if(!sh_video->inited){
1828 if(!fixed_vo) uninit_player(INITED_VO);
1829 if(!sh_audio) goto goto_next_file;
1830 sh_video = d_video->sh = NULL;
1831 goto main; // exit_player(MSGTR_Exit_error);
1834 inited_flags|=INITED_VCODEC;
1836 if(auto_quality>0){
1837 // Auto quality option enabled
1838 output_quality=get_video_quality_max(sh_video);
1839 if(auto_quality>output_quality) auto_quality=output_quality;
1840 else output_quality=auto_quality;
1841 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
1842 set_video_quality(sh_video,output_quality);
1845 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1847 current_module="init_vo";
1849 if(vo_flags & 0x08 && vo_spudec)
1850 spudec_set_hw_spu(vo_spudec,video_out);
1852 #ifdef HAVE_FREETYPE
1853 force_load_font = 1;
1854 #endif
1856 //================== MAIN: ==========================
1857 main:
1858 current_module="main";
1860 // If there is no video OSD has to be disabled.
1861 // In case of playing a playtree we have to restore the
1862 // old OSD level after playing one or more audio-only files.
1863 if(!sh_video && osd_level >= 0) { // save OSD level only once
1864 osd_level_saved = osd_level;
1865 osd_level = 0;
1866 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
1867 osd_level = osd_level_saved;
1868 osd_level_saved = -1;
1871 fflush(stdout);
1873 #ifdef HAVE_NEW_GUI
1874 if ( use_gui )
1876 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
1877 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
1878 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
1879 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
1880 guiGetEvent( guiSetDemuxer,(char *)demuxer );
1882 #endif
1885 //int frame_corr_num=0; //
1886 //float v_frame=0; // Video
1887 float time_frame=0; // Timer
1888 //float num_frames=0; // number of frames played
1889 int grab_frames=0;
1890 char osd_text_buffer[64];
1891 char osd_show_text_buffer[64];
1892 int drop_frame=0; // current dropping status
1893 int dropped_frames=0; // how many frames dropped since last non-dropped frame
1894 int too_slow_frame_cnt=0;
1895 int too_fast_frame_cnt=0;
1896 // for auto-quality:
1897 float AV_delay=0; // average of A-V timestamp differences
1898 double vdecode_time;
1899 unsigned int lastframeout_ts=0;
1900 /*float time_frame_corr_avg=0;*/ /* unused */
1902 float next_frame_time=0;
1903 int frame_time_remaining=0; // flag
1904 int blit_frame=0;
1906 osd_text_buffer[0]=0;
1908 //================ SETUP AUDIO ==========================
1910 if(sh_audio){
1911 //const ao_info_t *info=audio_out->info;
1912 current_module="af_preinit";
1913 ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*playback_speed;
1914 ao_data.channels=audio_output_channels?audio_output_channels:sh_audio->channels;
1915 ao_data.format=audio_output_format?audio_output_format:sh_audio->sample_format;
1916 #if 1
1917 if(!preinit_audio_filters(sh_audio,
1918 // input:
1919 (int)(sh_audio->samplerate*playback_speed),
1920 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
1921 // output:
1922 &ao_data.samplerate, &ao_data.channels, &ao_data.format,
1923 audio_out_format_bits(ao_data.format)/8)){
1924 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
1925 } else {
1926 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AF_pre: %dHz %dch %s\n",
1927 ao_data.samplerate, ao_data.channels,
1928 audio_out_format_name(ao_data.format));
1930 #endif
1931 current_module="ao2_init";
1932 if(!(audio_out=init_best_audio_out(audio_driver_list,
1933 (ao_plugin_cfg.plugin_list!=NULL), // plugin flag
1934 force_srate?force_srate:ao_data.samplerate,
1935 audio_output_channels?audio_output_channels:ao_data.channels,
1936 audio_output_format?audio_output_format:ao_data.format,0))){
1937 // FAILED:
1938 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
1939 uninit_player(INITED_ACODEC); // close codec
1940 sh_audio=d_audio->sh=NULL; // -> nosound
1941 } else {
1942 // SUCCESS:
1943 inited_flags|=INITED_AO;
1944 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
1945 audio_out->info->short_name,
1946 ao_data.samplerate, ao_data.channels,
1947 audio_out_format_name(ao_data.format),
1948 audio_out_format_bits(ao_data.format)/8 );
1949 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
1950 audio_out->info->name, audio_out->info->author);
1951 if(strlen(audio_out->info->comment) > 0)
1952 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
1953 // init audio filters:
1954 #if 1
1955 current_module="af_init";
1956 if(!build_afilter_chain(sh_audio, &ao_data)) {
1957 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
1958 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1959 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1960 // sh_audio=d_audio->sh=NULL; // -> nosound
1962 #endif
1964 mixer.audio_out = audio_out;
1965 mixer.afilter = sh_audio ? sh_audio->afilter : NULL;
1966 mixer.volstep = volstep;
1969 current_module="av_init";
1971 if(sh_video) sh_video->timer=0;
1972 if(sh_audio) sh_audio->delay=-audio_delay;
1974 if(!sh_audio){
1975 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
1976 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
1977 ds_free_packs(d_audio); // free buffered chunks
1978 d_audio->id=-2; // do not read audio chunks
1979 //uninit_player(INITED_AO); // close device
1981 if(!sh_video){
1982 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
1983 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
1984 ds_free_packs(d_video);
1985 d_video->id=-2;
1986 //if(!fixed_vo) uninit_player(INITED_VO);
1989 if (!sh_video && !sh_audio)
1990 goto goto_next_file;
1992 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
1993 if(force_fps && sh_video){
1994 vo_fps = sh_video->fps=force_fps;
1995 sh_video->frametime=1.0f/sh_video->fps;
1996 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
1999 //==================== START PLAYING =======================
2001 if(loop_times>1) loop_times--; else
2002 if(loop_times==1) loop_times = -1;
2004 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
2006 InitTimer();
2008 #ifdef USE_DVDNAV
2009 if (stream->type==STREAMTYPE_DVDNAV) {
2010 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
2012 #endif
2014 total_time_usage_start=GetTimer();
2015 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
2016 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
2017 play_n_frames=play_n_frames_mf;
2019 if(play_n_frames==0){
2020 eof=PT_NEXT_ENTRY; goto goto_next_file;
2023 while(!eof){
2024 float aq_sleep_time=0;
2026 if(play_n_frames>=0){
2027 --play_n_frames;
2028 if(play_n_frames<0) eof = PT_NEXT_ENTRY;
2031 /*========================== PLAY AUDIO ============================*/
2033 while(sh_audio){
2034 unsigned int t;
2035 double tt;
2036 int playsize;
2038 current_module="play_audio";
2040 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2041 playsize=audio_out->get_space();
2043 // handle audio-only case:
2044 if(!playsize && !sh_video) { // buffer is full, do not block here!!!
2045 usec_sleep(10000); // Wait a tick before retry
2046 continue;
2049 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
2051 // Fill buffer if needed:
2052 current_module="decode_audio"; // Enter AUDIO decoder module
2053 t=GetTimer();
2054 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
2055 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
2056 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
2057 if(ret<=0) break; // EOF?
2058 sh_audio->a_out_buffer_len+=ret;
2060 t=GetTimer()-t;
2061 tt = t*0.000001f; audio_time_usage+=tt;
2062 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
2064 // play audio:
2065 current_module="play_audio";
2066 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2068 if(playsize>0){
2069 sh_audio->a_out_buffer_len-=playsize;
2070 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2071 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2072 ao_data.bps : sh_audio->o_bps));
2075 break;
2076 } // while(sh_audio)
2078 if(!sh_video) {
2079 // handle audio-only case:
2080 if(!quiet) {
2082 // convert time to HH:MM:SS.F format
2084 long tenths = 10 * (sh_audio->delay-audio_out->get_delay()*playback_speed);
2085 int hh = (tenths / 36000) % 100;
2086 int mm = (tenths / 600) % 60;
2087 int ss = (tenths / 10) % 60;
2088 int f1 = tenths % 10;
2089 char hhmmssf[16]; // only really need 11, but just in case...
2090 sprintf( hhmmssf, "%2d:%2d:%2d.%1d", hh, mm, ss, f1);
2091 if (0 == hh) {
2092 hhmmssf[1] = ' ';
2093 hhmmssf[2] = ' ';
2095 // uncomment the next three lines to show leading zero ten-hours
2096 // else if (' ' == hhmmssf[0]) {
2097 // hhmmssf[0] = '0';
2098 // }
2099 if ((0 == hh) && (0 == mm)) {
2100 hhmmssf[4] = ' ';
2101 hhmmssf[5] = ' ';
2103 else if ((' ' == hhmmssf[3]) && (' ' != hhmmssf[2])) {
2104 hhmmssf[3] = '0';
2106 if ((' ' == hhmmssf[6]) && (' ' != hhmmssf[5])) {
2107 hhmmssf[6] = '0';
2109 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: %s %4.1f%% %d%% %4.2fx \r"
2110 ,hhmmssf
2111 ,(sh_audio->delay>0.5)?100.0*audio_time_usage/(double)sh_audio->delay:0
2112 ,cache_fill_status
2115 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2117 } else {
2119 /*========================== PLAY VIDEO ============================*/
2121 float frame_time=next_frame_time;
2123 vo_pts=sh_video->timer*90000.0;
2124 vo_fps=sh_video->fps;
2126 if(!frame_time_remaining){
2127 //-------------------- Decode a frame: -----------------------
2128 vdecode_time=video_time_usage;
2129 while(1)
2130 { unsigned char* start=NULL;
2131 int in_size;
2132 // get it!
2133 current_module="video_read_frame";
2134 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2135 if(in_size<0){ eof=1; break; }
2136 if(in_size>max_framesize) max_framesize=in_size; // stats
2137 sh_video->timer+=frame_time;
2138 if(sh_audio) sh_audio->delay-=frame_time;
2139 time_frame+=frame_time; // for nosound
2140 // check for frame-drop:
2141 current_module="check_framedrop";
2142 if(sh_audio && !d_audio->eof){
2143 float delay=playback_speed*audio_out->get_delay();
2144 float d=delay-sh_audio->delay;
2145 // we should avoid dropping to many frames in sequence unless we
2146 // are too late. and we allow 100ms A-V delay here:
2147 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
2148 drop_frame=frame_dropping;
2149 ++drop_frame_cnt;
2150 ++dropped_frames;
2151 } else {
2152 drop_frame=dropped_frames=0;
2154 ++total_frame_cnt;
2156 // decode:
2157 current_module="decode_video";
2158 // printf("Decode! %p %d \n",start,in_size);
2159 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2160 break;
2162 vdecode_time=video_time_usage-vdecode_time;
2163 //------------------------ frame decoded. --------------------
2165 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2167 if(sh_video->vf_inited<0){
2168 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2169 eof=1; goto goto_next_file;
2174 // ==========================================================================
2176 // current_module="draw_osd";
2177 // if(vo_config_count) video_out->draw_osd();
2179 #ifdef HAVE_NEW_GUI
2180 if(use_gui) guiEventHandling();
2181 #endif
2183 current_module="calc_sleep_time";
2185 #if 0
2186 { // debug frame dropping code
2187 float delay=audio_out->get_delay();
2188 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2189 sh_video->timer,sh_audio->timer-delay,
2190 sh_video->timer-(sh_audio->timer-delay),
2191 delay,drop_frame);
2193 #endif
2195 if(drop_frame && !frame_time_remaining && !autosync){
2197 * Note: time_frame should not be forced to 0 in autosync mode.
2198 * It is used as a cumulative counter to predict and correct the
2199 * delay measurements from the audio driver. time_frame is already
2200 * < 0, so the "time to sleep" code does not actually sleep. Also,
2201 * blit_frame is already 0 because drop_frame was true when
2202 * decode_video was called (which causes it to set blit_frame to 0.)
2203 * When autosync==0, the default behavior is still completely unchanged.
2206 time_frame=0; // don't sleep!
2207 blit_frame=0; // don't display!
2209 } else {
2211 // It's time to sleep...
2213 frame_time_remaining=0;
2214 time_frame-=GetRelativeTime(); // reset timer
2216 if(sh_audio && !d_audio->eof){
2217 float delay=playback_speed*audio_out->get_delay();
2218 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2220 if (autosync){
2222 * Adjust this raw delay value by calculating the expected
2223 * delay for this frame and generating a new value which is
2224 * weighted between the two. The higher autosync is, the
2225 * closer to the delay value gets to that which "-nosound"
2226 * would have used, and the longer it will take for A/V
2227 * sync to settle at the right value (but it eventually will.)
2228 * This settling time is very short for values below 100.
2230 float predicted = sh_audio->delay+time_frame;
2231 float difference = delay - predicted;
2232 delay = predicted + difference / (float)autosync;
2235 time_frame=delay-sh_audio->delay;
2237 // delay = amount of audio buffered in soundcard/driver
2238 if(delay>0.25) delay=0.25; else
2239 if(delay<0.10) delay=0.10;
2240 if(time_frame>delay*0.6){
2241 // sleep time too big - may cause audio drops (buffer underrun)
2242 frame_time_remaining=1;
2243 time_frame=delay*0.5;
2246 } else {
2248 // NOSOUND:
2249 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2250 time_frame=0;
2254 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2256 aq_sleep_time+=time_frame;
2258 } // !drop_frame
2260 //============================== SLEEP: ===================================
2262 time_frame/=playback_speed;
2264 // flag 256 means: libvo driver does its timing (dvb card)
2265 if(time_frame>0.001 && !(vo_flags&256)){
2267 #ifdef HAVE_RTC
2268 if(rtc_fd>=0){
2269 // -------- RTC -----------
2270 current_module="sleep_rtc";
2271 while (time_frame > 0.000) {
2272 unsigned long rtc_ts;
2273 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2274 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2275 time_frame-=GetRelativeTime();
2277 } else
2278 #endif
2280 // -------- TIMER + SOFTSLEEP -----------
2281 float min=softsleep?0.021:0.005;
2282 current_module="sleep_timer";
2283 while(time_frame>min){
2284 if(time_frame<=0.020)
2285 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2286 else
2287 usec_sleep(1000000*(time_frame-0.020));
2288 time_frame-=GetRelativeTime();
2290 if(softsleep){
2291 current_module="sleep_soft";
2292 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
2293 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2299 //if(!frame_time_remaining){ // should we display the frame now?
2301 //====================== FLIP PAGE (VIDEO BLT): =========================
2303 current_module="vo_check_events";
2304 if(vo_config_count) video_out->check_events();
2306 current_module="flip_page";
2307 if (!frame_time_remaining) {
2308 if(blit_frame){
2309 unsigned int t2=GetTimer();
2310 double tt;
2311 float j;
2312 #define FRAME_LAG_WARN 0.2
2313 j = ((float)t2 - lastframeout_ts) / 1000000;
2314 lastframeout_ts = GetTimer();
2315 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2316 too_fast_frame_cnt++;
2317 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2318 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2319 too_slow_frame_cnt++;
2320 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2322 if(vo_config_count) video_out->flip_page();
2323 // usec_sleep(50000); // test only!
2324 t2=GetTimer()-t2;
2325 tt = t2*0.000001f;
2326 vout_time_usage+=tt;
2327 } else {
2329 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2330 otherwise A/V desync will occur. -- Alvieboy
2332 if (vo_config_count)
2333 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2336 //====================== A-V TIMESTAMP CORRECTION: =========================
2338 current_module="av_sync";
2340 if(sh_audio){
2341 float a_pts=0;
2342 float v_pts=0;
2344 // unplayed bytes in our and soundcard/dma buffer:
2345 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2347 if (autosync){
2349 * If autosync is enabled, the value for delay must be calculated
2350 * a bit differently. It is set only to the difference between
2351 * the audio and video timers. Any attempt to include the real
2352 * or corrected delay causes the pts_correction code below to
2353 * try to correct for the changes in delay which autosync is
2354 * trying to measure. This keeps the two from competing, but still
2355 * allows the code to correct for PTS drift *only*. (Using a delay
2356 * value here, even a "corrected" one, would be incompatible with
2357 * autosync mode.)
2359 delay=sh_audio->delay;
2360 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2363 #if 0
2364 if(pts_from_bps){
2365 // PTS = sample_no / samplerate
2366 unsigned int samples=
2367 // (sh_audio->audio.dwSampleSize)?
2368 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2369 ds_tell_block(d_audio); // <- used for VBR audio
2370 samples+=sh_audio->audio.dwStart; // offset
2371 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2372 delay_corrected=1;
2373 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2374 } else
2375 #endif
2377 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2378 a_pts=d_audio->pts;
2379 if(!delay_corrected) if(a_pts) delay_corrected=1;
2380 #if 0
2381 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2382 a_pts,
2383 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2384 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2385 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2386 #endif
2387 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2389 v_pts=sh_video ? sh_video->pts : d_video->pts;
2391 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);
2393 if(delay_corrected){
2394 static int drop_message=0;
2395 float x;
2396 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2397 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2398 ++drop_message;
2399 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2401 x=AV_delay*0.1f;
2402 if(x<-max_pts_correction) x=-max_pts_correction; else
2403 if(x> max_pts_correction) x= max_pts_correction;
2404 if(default_max_pts_correction>=0)
2405 max_pts_correction=default_max_pts_correction;
2406 else
2407 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2408 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2409 if(!quiet) mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d %d %d%% %4.2fx\r",
2410 a_pts-audio_delay-delay,v_pts,AV_delay,c_total,
2411 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded,
2412 (sh_video->timer>0.5)?(int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer):0,
2413 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer):0,
2414 (sh_video->timer>0.5)?(100.0*audio_time_usage*playback_speed/(double)sh_video->timer):0
2415 ,drop_frame_cnt
2416 ,output_quality
2417 ,cache_fill_status
2418 ,playback_speed
2420 fflush(stdout);
2423 } else {
2424 // No audio:
2426 if(!quiet)
2427 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video->pts,
2428 (int)sh_video->num_frames,
2429 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
2430 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
2431 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
2432 ,drop_frame_cnt
2433 ,output_quality
2434 ,cache_fill_status
2437 fflush(stdout);
2441 //============================ Auto QUALITY ============================
2443 /*Output quality adjustments:*/
2444 if(auto_quality>0){
2445 current_module="autoq";
2446 // float total=0.000001f * (GetTimer()-aq_total_time);
2447 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2448 if(output_quality<auto_quality && aq_sleep_time>0)
2449 ++output_quality;
2450 else
2451 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2452 if(output_quality>1 && aq_sleep_time<0)
2453 --output_quality;
2454 else
2455 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2456 output_quality=0;
2457 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2458 set_video_quality(sh_video,output_quality);
2461 } // end if(sh_video)
2463 //============================ Handle PAUSE ===============================
2465 current_module="pause";
2467 #ifdef USE_OSD
2468 if(osd_visible){
2469 if (!--osd_visible){
2470 vo_osd_progbar_type=-1; // disable
2471 vo_osd_changed(OSDTYPE_PROGBAR);
2472 if (osd_function != OSD_PAUSE)
2473 osd_function = OSD_PLAY;
2476 #endif
2478 if(osd_function==OSD_PAUSE){
2479 mp_cmd_t* cmd;
2480 if(!quiet) {
2481 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2482 fflush(stdout);
2484 #ifdef HAVE_NEW_GUI
2485 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2486 #endif
2487 if (video_out && sh_video && vo_config_count)
2488 video_out->control(VOCTRL_PAUSE, NULL);
2490 if (audio_out && sh_audio)
2491 audio_out->pause(); // pause audio, keep data if possible
2493 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
2494 if(sh_video && video_out && vo_config_count) video_out->check_events();
2495 #ifdef HAVE_NEW_GUI
2496 if(use_gui){
2497 guiEventHandling();
2498 guiGetEvent( guiReDraw,NULL );
2499 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2501 #endif
2502 #ifdef HAVE_MENU
2503 if(vf_menu)
2504 vf_menu_pause_update(vf_menu);
2505 #endif
2506 usec_sleep(20000);
2508 if (cmd->id == MP_CMD_PAUSE) {
2509 cmd = mp_input_get_cmd(0,1,0);
2510 mp_cmd_free(cmd);
2512 osd_function=OSD_PLAY;
2513 if (audio_out && sh_audio)
2514 audio_out->resume(); // resume audio
2515 if (video_out && sh_video && vo_config_count)
2516 video_out->control(VOCTRL_RESUME, NULL); // resume video
2517 (void)GetRelativeTime(); // keep TF around FT in next cycle
2518 #ifdef HAVE_NEW_GUI
2519 if (use_gui)
2521 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2522 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2524 #endif
2527 // handle -sstep
2528 if(step_sec>0) {
2529 osd_function=OSD_FFW;
2530 rel_seek_secs+=step_sec;
2533 #ifdef USE_DVDNAV
2534 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2535 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2536 #endif
2538 //================= EDL =========================================
2540 #ifdef USE_EDL
2541 if( next_edl_record ) { // Are we (still?) doing EDL?
2542 if ( !sh_video ) {
2543 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
2544 next_edl_record->next = NULL;
2545 } else {
2546 if( sh_video->pts >= next_edl_record->start_sec ) {
2547 if( next_edl_record->action == EDL_SKIP ) {
2548 osd_function = OSD_FFW;
2549 abs_seek_pos = 0;
2550 rel_seek_secs = next_edl_record->length_sec;
2551 #ifdef DEBUG_EDL
2552 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_EDLSKIPStartStopLength, next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec );
2553 #endif
2554 edl_decision = 1;
2555 } else if( next_edl_record->action == EDL_MUTE ) {
2556 mixer_mute(&mixer);
2557 edl_mute_count++; // new EDL seek behavior needs this
2558 #ifdef DEBUG_EDL
2559 mp_msg(MSGT_FIXME, MSGL_FIXME, "\nEDL_MUTE: [%f]\n", next_edl_record->start_sec );
2560 #endif
2561 edl_decision = 1;
2563 next_edl_record=next_edl_record->next;
2567 #endif
2569 //================= Keyboard events, SEEKing ====================
2571 current_module="key_events";
2574 mp_cmd_t* cmd;
2575 int brk_cmd = 0;
2576 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
2577 switch(cmd->id) {
2578 case MP_CMD_SEEK : {
2579 int v,abs;
2580 osd_show_percentage = 25;
2581 v = cmd->args[0].v.i;
2582 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2583 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2584 abs_seek_pos = 1;
2585 if(sh_video)
2586 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2587 rel_seek_secs = v;
2589 else if(abs) { /* Absolute seek by percentage */
2590 abs_seek_pos = 3;
2591 if(sh_video)
2592 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2593 rel_seek_secs = v/100.0;
2595 else {
2596 rel_seek_secs+= v;
2597 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2599 brk_cmd = 1;
2600 } break;
2601 #ifdef USE_EDL
2602 case MP_CMD_EDL_MARK:
2603 if( edl_fd ) {
2604 float v = sh_video->pts;
2605 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2607 break;
2608 #endif
2609 case MP_CMD_SWITCH_RATIO : {
2610 if (cmd->nargs == 0)
2611 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2612 else
2613 movie_aspect = cmd->args[0].v.f;
2614 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2615 } break;
2616 case MP_CMD_AUDIO_DELAY : {
2617 float v = cmd->args[0].v.f;
2618 audio_delay += v;
2619 osd_show_av_delay = 9;
2620 if(sh_audio) sh_audio->delay+= v;
2621 } break;
2622 case MP_CMD_SPEED_INCR : {
2623 float v = cmd->args[0].v.f;
2624 playback_speed += v;
2625 osd_show_speed = sh_video->fps;
2626 build_afilter_chain(sh_audio, &ao_data);
2627 } break;
2628 case MP_CMD_SPEED_MULT : {
2629 float v = cmd->args[0].v.f;
2630 playback_speed *= v;
2631 osd_show_speed = sh_video->fps;
2632 build_afilter_chain(sh_audio, &ao_data);
2633 } break;
2634 case MP_CMD_SPEED_SET : {
2635 float v = cmd->args[0].v.f;
2636 playback_speed = v;
2637 osd_show_speed = sh_video->fps;
2638 build_afilter_chain(sh_audio, &ao_data);
2639 } break;
2640 case MP_CMD_FRAME_STEP :
2641 case MP_CMD_PAUSE : {
2642 osd_function=OSD_PAUSE;
2643 brk_cmd = 1;
2644 } break;
2645 case MP_CMD_QUIT : {
2646 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
2648 case MP_CMD_GRAB_FRAMES : {
2649 grab_frames=2;
2650 } break;
2651 case MP_CMD_PLAY_TREE_STEP : {
2652 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2653 int force = cmd->args[1].v.i;
2655 #ifdef HAVE_NEW_GUI
2656 if (use_gui) {
2657 int i=0;
2658 if (n>0)
2659 for (i=0;i<n;i++)
2660 mplNext();
2661 else
2662 for (i=0;i<-1*n;i++)
2663 mplPrev();
2664 } else
2665 #endif
2667 if(!force && playtree_iter) {
2668 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2670 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2671 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2672 play_tree_iter_free(i);
2673 } else
2674 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2675 if(eof)
2676 play_tree_step = n;
2677 brk_cmd = 1;
2679 } break;
2680 case MP_CMD_PLAY_TREE_UP_STEP : {
2681 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2682 int force = cmd->args[1].v.i;
2684 if(!force && playtree_iter) {
2685 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2686 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2687 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2688 play_tree_iter_free(i);
2689 } else
2690 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2691 brk_cmd = 1;
2692 } break;
2693 case MP_CMD_PLAY_ALT_SRC_STEP : {
2694 if(playtree_iter && playtree_iter->num_files > 1) {
2695 int v = cmd->args[0].v.i;
2696 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2697 eof = PT_NEXT_SRC;
2698 else if(v < 0 && playtree_iter->file > 1)
2699 eof = PT_PREV_SRC;
2701 brk_cmd = 1;
2702 } break;
2703 case MP_CMD_SUB_DELAY : {
2704 #ifdef USE_SUB
2705 if (sh_video) {
2706 int abs= cmd->args[1].v.i;
2707 float v = cmd->args[0].v.f;
2708 if(abs)
2709 sub_delay = v;
2710 else
2711 sub_delay += v;
2712 osd_show_sub_delay = 9; // show the subdelay in OSD
2714 #endif
2715 } break;
2716 case MP_CMD_SUB_STEP : {
2717 #ifdef USE_SUB
2718 if (sh_video) {
2719 int movement = cmd->args[0].v.i;
2720 step_sub(subdata, sh_video->pts, movement);
2721 osd_show_sub_delay = 9; // show the subdelay in OSD
2723 #endif
2724 } break;
2725 case MP_CMD_OSD : {
2726 #ifdef USE_OSD
2727 if(sh_video) {
2728 int v = cmd->args[0].v.i;
2729 if(v < 0)
2730 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2731 else
2732 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2734 #endif
2735 } break;
2736 case MP_CMD_OSD_SHOW_TEXT : {
2737 #ifdef USE_OSD
2738 if(osd_level && sh_video){
2739 osd_show_text=sh_video->fps; // 1 sec
2740 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2742 #endif
2743 } break;
2744 case MP_CMD_VOLUME : {
2745 int v = cmd->args[0].v.i;
2747 // start change for absolute volume value
2748 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2750 if( abs )
2752 mixer_setvolume(&mixer, (float)v, (float)v );
2753 } else {
2754 if(v > 0)
2755 mixer_incvolume(&mixer);
2756 else
2757 mixer_decvolume(&mixer);
2760 #ifdef USE_OSD
2761 if(osd_level && sh_video){
2762 float vol;
2763 osd_visible=sh_video->fps; // 1 sec
2764 vo_osd_progbar_type=OSD_VOLUME;
2765 mixer_getbothvolume(&mixer, &vol);
2766 vo_osd_progbar_value=(vol*256.0)/100.0;
2767 vo_osd_changed(OSDTYPE_PROGBAR);
2769 #endif
2770 } break;
2771 case MP_CMD_MUTE:
2772 mixer_mute(&mixer);
2773 break;
2774 case MP_CMD_LOADFILE : {
2775 play_tree_t* e = play_tree_new();
2776 play_tree_add_file(e,cmd->args[0].v.s);
2778 // Go back to the start point
2779 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2780 /* NOP */;
2781 play_tree_free_list(playtree->child,1);
2782 play_tree_set_child(playtree,e);
2783 play_tree_iter_step(playtree_iter,0,0);
2784 eof = PT_NEXT_SRC;
2785 brk_cmd = 1;
2786 } break;
2787 case MP_CMD_LOADLIST : {
2788 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
2789 if(!e)
2790 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
2791 else {
2792 // Go back to the start point
2793 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2794 /* NOP */;
2795 play_tree_free_list(playtree->child,1);
2796 play_tree_set_child(playtree,e);
2797 play_tree_iter_step(playtree_iter,0,0);
2798 eof = PT_NEXT_SRC;
2800 brk_cmd = 1;
2801 } break;
2802 case MP_CMD_GAMMA : {
2803 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2805 if (!sh_video)
2806 break;
2808 if (vo_gamma_gamma == 1000)
2810 vo_gamma_gamma = 0;
2811 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
2814 if (abs)
2815 vo_gamma_gamma = v;
2816 else
2817 vo_gamma_gamma += v;
2819 if (vo_gamma_gamma > 100)
2820 vo_gamma_gamma = 100;
2821 else if (vo_gamma_gamma < -100)
2822 vo_gamma_gamma = -100;
2823 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
2824 #ifdef USE_OSD
2825 if(osd_level){
2826 osd_visible=sh_video->fps; // 1 sec
2827 vo_osd_progbar_type=OSD_BRIGHTNESS;
2828 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
2829 vo_osd_changed(OSDTYPE_PROGBAR);
2831 #endif // USE_OSD
2832 } break;
2833 case MP_CMD_BRIGHTNESS : {
2834 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2836 if (!sh_video)
2837 break;
2839 if (vo_gamma_brightness == 1000)
2841 vo_gamma_brightness = 0;
2842 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
2845 if (abs)
2846 vo_gamma_brightness = v;
2847 else
2848 vo_gamma_brightness += v;
2850 if (vo_gamma_brightness > 100)
2851 vo_gamma_brightness = 100;
2852 else if (vo_gamma_brightness < -100)
2853 vo_gamma_brightness = -100;
2854 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
2855 #ifdef USE_OSD
2856 if(osd_level){
2857 osd_visible=sh_video->fps; // 1 sec
2858 vo_osd_progbar_type=OSD_BRIGHTNESS;
2859 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
2860 vo_osd_changed(OSDTYPE_PROGBAR);
2862 #endif // USE_OSD
2864 } break;
2865 case MP_CMD_CONTRAST : {
2866 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2868 if (!sh_video)
2869 break;
2871 if (vo_gamma_contrast == 1000)
2873 vo_gamma_contrast = 0;
2874 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
2877 if (abs)
2878 vo_gamma_contrast = v;
2879 else
2880 vo_gamma_contrast += v;
2882 if (vo_gamma_contrast > 100)
2883 vo_gamma_contrast = 100;
2884 else if (vo_gamma_contrast < -100)
2885 vo_gamma_contrast = -100;
2886 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
2887 #ifdef USE_OSD
2888 if(osd_level){
2889 osd_visible=sh_video->fps; // 1 sec
2890 vo_osd_progbar_type=OSD_CONTRAST;
2891 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
2892 vo_osd_changed(OSDTYPE_PROGBAR);
2894 #endif // USE_OSD
2896 } break;
2897 case MP_CMD_SATURATION : {
2898 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2900 if (!sh_video)
2901 break;
2903 if (vo_gamma_saturation == 1000)
2905 vo_gamma_saturation = 0;
2906 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
2909 if (abs)
2910 vo_gamma_saturation = v;
2911 else
2912 vo_gamma_saturation += v;
2914 if (vo_gamma_saturation > 100)
2915 vo_gamma_saturation = 100;
2916 else if (vo_gamma_saturation < -100)
2917 vo_gamma_saturation = -100;
2918 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
2919 #ifdef USE_OSD
2920 if(osd_level){
2921 osd_visible=sh_video->fps; // 1 sec
2922 vo_osd_progbar_type=OSD_SATURATION;
2923 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
2924 vo_osd_changed(OSDTYPE_PROGBAR);
2926 #endif // USE_OSD
2928 } break;
2929 case MP_CMD_HUE : {
2930 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2932 if (!sh_video)
2933 break;
2935 if (vo_gamma_hue == 1000)
2937 vo_gamma_hue = 0;
2938 get_video_colors(sh_video, "hue", &vo_gamma_hue);
2941 if (abs)
2942 vo_gamma_hue = v;
2943 else
2944 vo_gamma_hue += v;
2946 if (vo_gamma_hue > 100)
2947 vo_gamma_hue = 100;
2948 else if (vo_gamma_hue < -100)
2949 vo_gamma_hue = -100;
2950 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
2951 #ifdef USE_OSD
2952 if(osd_level){
2953 osd_visible=sh_video->fps; // 1 sec
2954 vo_osd_progbar_type=OSD_HUE;
2955 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
2956 vo_osd_changed(OSDTYPE_PROGBAR);
2958 #endif // USE_OSD
2960 } break;
2961 case MP_CMD_FRAMEDROPPING : {
2962 int v = cmd->args[0].v.i;
2963 if(v < 0){
2964 frame_dropping = (frame_dropping+1)%3;
2965 #ifdef USE_OSD
2966 osd_show_framedropping=10;
2967 vo_osd_changed(OSDTYPE_SUBTITLE);
2968 #endif
2970 else
2971 frame_dropping = v > 2 ? 2 : v;
2972 } break;
2973 #ifdef USE_TV
2974 case MP_CMD_TV_SET_FREQ : {
2975 if (file_format == DEMUXER_TYPE_TV)
2976 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
2977 } break;
2978 case MP_CMD_TV_SET_NORM : {
2979 if (file_format == DEMUXER_TYPE_TV)
2980 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
2981 } break;
2982 case MP_CMD_TV_SET_BRIGHTNESS : {
2983 if (file_format == DEMUXER_TYPE_TV)
2984 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
2985 } break;
2986 case MP_CMD_TV_SET_HUE : {
2987 if (file_format == DEMUXER_TYPE_TV)
2988 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
2989 } break;
2990 case MP_CMD_TV_SET_SATURATION : {
2991 if (file_format == DEMUXER_TYPE_TV)
2992 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
2993 } break;
2994 case MP_CMD_TV_SET_CONTRAST : {
2995 if (file_format == DEMUXER_TYPE_TV)
2996 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
2997 } break;
2998 case MP_CMD_TV_STEP_CHANNEL : {
2999 if (file_format == DEMUXER_TYPE_TV) {
3000 int v = cmd->args[0].v.i;
3001 if(v > 0){
3002 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
3003 #ifdef USE_OSD
3004 if (tv_channel_list) {
3005 osd_show_tv_channel = sh_video->fps;
3006 vo_osd_changed(OSDTYPE_SUBTITLE);
3008 #endif
3009 } else {
3010 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
3011 #ifdef USE_OSD
3012 if (tv_channel_list) {
3013 osd_show_tv_channel = sh_video->fps;
3014 vo_osd_changed(OSDTYPE_SUBTITLE);
3016 #endif
3020 #ifdef HAS_DVBIN_SUPPORT
3021 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3023 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3024 if(priv->is_on)
3026 int dir;
3027 int v = cmd->args[0].v.i;
3029 last_dvb_step = v;
3030 if(v > 0)
3031 dir = DVB_CHANNEL_HIGHER;
3032 else
3033 dir = DVB_CHANNEL_LOWER;
3036 if(dvb_step_channel(priv, dir))
3038 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3039 cache_uninit(stream);
3040 goto goto_enable_cache;
3044 #endif
3045 break;
3046 case MP_CMD_TV_SET_CHANNEL : {
3047 if (file_format == DEMUXER_TYPE_TV) {
3048 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3049 #ifdef USE_OSD
3050 if (tv_channel_list) {
3051 osd_show_tv_channel = sh_video->fps;
3052 vo_osd_changed(OSDTYPE_SUBTITLE);
3054 #endif
3056 } break;
3057 #ifdef HAS_DVBIN_SUPPORT
3058 case MP_CMD_DVB_SET_CHANNEL:
3060 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3062 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3063 if(priv->is_on)
3065 if(priv->list->current <= cmd->args[0].v.i)
3066 last_dvb_step = 1;
3067 else
3068 last_dvb_step = -1;
3070 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
3072 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3073 cache_uninit(stream);
3074 goto goto_enable_cache;
3079 #endif
3080 case MP_CMD_TV_LAST_CHANNEL : {
3081 if (file_format == DEMUXER_TYPE_TV) {
3082 tv_last_channel((tvi_handle_t*)(demuxer->priv));
3083 #ifdef USE_OSD
3084 if (tv_channel_list) {
3085 osd_show_tv_channel = sh_video->fps;
3086 vo_osd_changed(OSDTYPE_SUBTITLE);
3088 #endif
3090 } break;
3091 case MP_CMD_TV_STEP_NORM : {
3092 if (file_format == DEMUXER_TYPE_TV)
3093 tv_step_norm((tvi_handle_t*)(demuxer->priv));
3094 } break;
3095 case MP_CMD_TV_STEP_CHANNEL_LIST : {
3096 if (file_format == DEMUXER_TYPE_TV)
3097 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
3098 } break;
3099 #endif
3100 case MP_CMD_SWITCH_VSYNC: {
3101 vo_vsync = ( cmd->nargs > 0 )? cmd->args[0].v.i : !vo_vsync;
3102 } break;
3103 case MP_CMD_VO_FULLSCREEN:
3105 #ifdef HAVE_NEW_GUI
3106 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3107 else
3108 #endif
3109 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3110 } break;
3111 case MP_CMD_VO_ONTOP:
3113 if(video_out && vo_config_count) {
3114 video_out->control(VOCTRL_ONTOP, 0);
3115 #ifdef USE_OSD
3116 osd_show_ontop=10;
3117 vo_osd_changed(OSDTYPE_SUBTITLE);
3118 #endif
3121 } break;
3122 case MP_CMD_VO_ROOTWIN:
3124 if(video_out && vo_config_count) {
3125 video_out->control(VOCTRL_ROOTWIN, 0);
3126 #ifdef USE_OSD
3127 osd_show_rootwin=10;
3128 vo_osd_changed(OSDTYPE_SUBTITLE);
3129 #endif
3132 } break;
3133 case MP_CMD_PANSCAN : {
3134 if ( !video_out ) break;
3135 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3137 int abs= cmd->args[1].v.i;
3138 float v = cmd->args[0].v.f;
3139 float res;
3140 if(abs) res = v;
3141 else res = vo_panscan+v;
3142 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3143 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3144 #ifdef USE_OSD
3145 if(osd_level && sh_video){
3146 osd_visible=sh_video->fps; // 1 sec
3147 vo_osd_progbar_type=OSD_PANSCAN;
3148 vo_osd_progbar_value=vo_panscan*256;
3149 vo_osd_changed(OSDTYPE_PROGBAR);
3150 #ifdef HAVE_FREETYPE
3151 if (subtitle_autoscale == 2 || subtitle_autoscale == 3)
3152 // force scaling font to movie width or diagonal
3153 force_load_font = 1;
3154 #endif
3156 #endif
3158 } break;
3159 case MP_CMD_SUB_POS:
3161 #ifdef USE_SUB
3162 if (sh_video) {
3163 int v;
3164 v = cmd->args[0].v.i;
3166 sub_pos+=v;
3167 if(sub_pos >100) sub_pos=100;
3168 if(sub_pos <0) sub_pos=0;
3169 vo_osd_changed(OSDTYPE_SUBTITLE);
3170 osd_show_sub_pos = 9;
3172 #endif
3173 } break;
3174 case MP_CMD_SUB_ALIGNMENT:
3176 #ifdef USE_SUB
3177 if (sh_video) {
3178 if (cmd->nargs >= 1)
3179 sub_alignment = cmd->args[0].v.i;
3180 else
3181 sub_alignment = (sub_alignment+1) % 3;
3182 osd_show_sub_alignment = 9;
3183 vo_osd_changed(OSDTYPE_SUBTITLE);
3185 #endif
3186 } break;
3187 case MP_CMD_SUB_VISIBILITY:
3189 #ifdef USE_SUB
3190 if (sh_video) {
3191 sub_visibility=1-sub_visibility;
3192 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3193 vo_osd_changed(OSDTYPE_SUBTITLE);
3195 #endif
3196 } break;
3197 case MP_CMD_GET_SUB_VISIBILITY:
3199 #ifdef USE_SUB
3200 if (sh_video) {
3201 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsSubVisibility, sub_visibility);
3203 #endif
3204 } break;
3205 case MP_CMD_SUB_SELECT:
3206 if (global_sub_size) {
3207 int source = -1;
3209 global_sub_pos++;
3210 if (global_sub_pos >= global_sub_size)
3211 global_sub_pos = -1;
3212 if (global_sub_pos >= 0)
3213 source = sub_source();
3215 mp_msg(MSGT_CPLAYER, MSGL_DBG3, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3216 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
3217 global_sub_indices[SUB_SOURCE_SUBS], global_sub_indices[SUB_SOURCE_DEMUX],
3218 global_sub_pos, source);
3220 #ifdef USE_SUB
3221 set_of_sub_pos = -1;
3222 subdata = NULL;
3223 vo_sub = NULL;
3224 #endif
3225 vobsub_id = -1;
3226 dvdsub_id = -1;
3227 if (d_dvdsub) d_dvdsub->id = -1;
3229 // be careful!
3230 // if sub_changed is till on but subdata's been reset, bad things happen.
3231 osd_show_vobsub_changed = 0;
3232 osd_show_sub_changed = 0;
3234 if (source == SUB_SOURCE_VOBSUB) {
3235 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
3236 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3237 #ifdef USE_SUB
3238 } else if (source == SUB_SOURCE_SUBS) {
3239 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
3240 subdata = set_of_subtitles[set_of_sub_pos];
3241 if (!global_sub_quiet_osd_hack) osd_show_sub_changed = sh_video->fps;
3242 vo_osd_changed(OSDTYPE_SUBTITLE);
3244 // FIXME: is this the correct place for these?
3245 if(stream_dump_type==3) list_sub_file(subdata);
3246 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
3247 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
3248 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
3249 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
3250 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
3251 #endif
3252 } else if (source == SUB_SOURCE_DEMUX) {
3253 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
3254 if (d_dvdsub) {
3255 #ifdef USE_DVDREAD
3256 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
3257 d_dvdsub->id = dvdsub_id;
3258 spudec_reset(vo_spudec);
3260 #endif
3261 #ifdef HAVE_OGGVORBIS
3262 if (demuxer->type == DEMUXER_TYPE_OGG)
3263 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
3264 #endif
3265 #ifdef HAVE_MATROSKA
3266 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3267 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
3268 if (d_dvdsub->id >= 0 && ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
3269 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
3270 if (vo_spudec != NULL)
3271 spudec_free(vo_spudec);
3272 vo_spudec =
3273 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
3274 mkv_sh_sub->custom_colors,
3275 mkv_sh_sub->width,
3276 mkv_sh_sub->height);
3277 if (!forced_subs_only)
3278 forced_subs_only = mkv_sh_sub->forced_subs_only;
3279 if (vo_spudec) {
3280 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
3281 inited_flags |= INITED_SPUDEC;
3285 #endif
3287 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3288 } else { // off
3289 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3290 #ifdef USE_SUB
3291 vo_osd_changed(OSDTYPE_SUBTITLE);
3292 #endif
3294 // it's annoying and dumb to show osd saying "off" at every subless file...
3295 global_sub_quiet_osd_hack = 0;
3297 break;
3298 case MP_CMD_SUB_FORCED_ONLY:
3299 if (vo_spudec) {
3300 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3301 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3303 break;
3304 case MP_CMD_SCREENSHOT :
3305 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3306 break;
3307 case MP_CMD_VF_CHANGE_RECTANGLE:
3308 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3309 break;
3311 case MP_CMD_GET_TIME_LENGTH : {
3312 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsLength, demuxer_get_time_length(demuxer));
3313 } break;
3315 case MP_CMD_GET_VO_FULLSCREEN : {
3316 if(video_out && vo_config_count)
3317 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsVoFullscreen, vo_fs);
3318 } break;
3320 case MP_CMD_GET_PERCENT_POS : {
3321 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsPercentPos, demuxer_get_percent_pos(demuxer));
3322 } break;
3323 #ifdef HAVE_MENU
3324 case MP_CMD_CRUN : {
3325 #ifndef __MINGW32__
3326 if(!fork()) {
3327 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
3328 exit(0);
3330 #endif
3331 } break;
3332 #endif
3334 #ifdef USE_DVDNAV
3335 case MP_CMD_DVDNAV_EVENT: {
3336 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3337 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3339 /* ignore these events if we're not in dvd_nav mode */
3340 if (stream->type != STREAMTYPE_DVDNAV) break;
3342 if (!dvdnav_event) {
3343 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNullEvent);
3344 break;
3347 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3349 switch (dvdnav_event->event) {
3350 case DVDNAV_BLOCK_OK: {
3351 /* be silent about this one */
3352 break;
3354 case DVDNAV_HIGHLIGHT: {
3355 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3356 if (!hevent) {
3357 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightEventBroken);
3358 break;
3361 if (hevent->display && hevent->buttonN>0)
3363 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3364 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3365 hevent->buttonN,
3366 hevent->sx,hevent->sy,
3367 hevent->ex,hevent->ey,
3368 hevent->pts, d_video->pts);
3369 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavEvent,dvd_nav_text);
3370 //osd_show_dvd_nav_delay = 60;
3372 osd_show_dvd_nav_highlight=1;
3373 osd_show_dvd_nav_sx=hevent->sx;
3374 osd_show_dvd_nav_ex=hevent->ex;
3375 osd_show_dvd_nav_sy=hevent->sy;
3376 osd_show_dvd_nav_ey=hevent->ey;
3378 else {
3379 osd_show_dvd_nav_highlight=0;
3380 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightHide);
3382 break;
3384 case DVDNAV_STILL_FRAME: {
3385 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3387 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavStillFrame, still_event->length );
3388 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3389 usec_sleep(1000); /* 1ms */
3391 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3392 break;
3394 case DVDNAV_STOP: {
3395 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavStop );
3396 break;
3398 case DVDNAV_NOP: {
3399 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavNOP);
3400 break;
3402 case DVDNAV_SPU_STREAM_CHANGE: {
3403 #if DVDNAVVERSION > 012
3404 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3406 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChangeVerbose,
3407 stream_change->physical_wide,
3408 stream_change->physical_letterbox,
3409 stream_change->physical_pan_scan,
3410 stream_change->logical);
3412 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3413 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3414 d_dvdsub->id,stream_change->physical_wide);
3415 // FIXME: need a better way to change SPU id
3416 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3417 if (vo_spudec) spudec_reset(vo_spudec);
3419 #else
3420 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3422 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChange,
3423 stream_change->physical,
3424 stream_change->logical);
3426 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3427 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3428 d_dvdsub->id,stream_change->physical);
3429 // FIXME: need a better way to change SPU id
3430 d_dvdsub->id=dvdsub_id=stream_change->physical;
3431 if (vo_spudec) spudec_reset(vo_spudec);
3433 #endif
3434 break;
3436 case DVDNAV_AUDIO_STREAM_CHANGE: {
3437 int aid_temp;
3438 #if DVDNAVVERSION > 012
3439 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3440 #else
3441 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3442 #endif
3444 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavAudioStreamChange,
3445 stream_change->physical,
3446 stream_change->logical);
3448 aid_temp=stream_change->physical;
3449 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3450 if (d_audio && audio_id!=aid_temp) {
3451 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3452 d_audio->id,aid_temp);
3453 // FIXME: need a bettery way to change audio stream id
3454 d_audio->id=dvdsub_id=aid_temp;
3455 if(sh_audio) resync_audio_stream(sh_audio);
3458 break;
3460 case DVDNAV_VTS_CHANGE: {
3461 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavVTSChange);
3462 break;
3464 case DVDNAV_CELL_CHANGE: {
3465 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3466 cell_playback_t * cell_playback = cell_change->new_cell;
3468 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavCellChange);
3469 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3471 printf("new still time: %d\n",cell_playback->still_time);
3472 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3473 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3474 cell_playback->playback_time.hour,
3475 cell_playback->playback_time.minute,
3476 cell_playback->playback_time.second,
3477 cell_playback->playback_time.frame_u);
3480 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3481 //abs_seek_pos=0;
3482 break;
3484 case DVDNAV_NAV_PACKET: {
3485 // printf("DVDNAV Event: Nav Packet\n");
3486 break;
3488 case DVDNAV_SPU_CLUT_CHANGE: {
3489 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3491 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuClutChange);
3492 // send new palette to SPU decoder
3493 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3495 break;
3497 case DVDNAV_SEEK_DONE: {
3498 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSeekDone);
3499 break;
3503 // free the dvdnav event
3504 free(dvdnav_event->details);
3505 free(dvdnav_event);
3506 cmd->args[0].v.v=NULL;
3508 case MP_CMD_DVDNAV: {
3509 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3511 /* ignore these events if we're not in dvd_nav mode */
3512 if (stream->type != STREAMTYPE_DVDNAV) break;
3514 switch (cmd->args[0].v.i) {
3515 case MP_CMD_DVDNAV_UP:
3516 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3517 break;
3518 case MP_CMD_DVDNAV_DOWN:
3519 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3520 break;
3521 case MP_CMD_DVDNAV_LEFT:
3522 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3523 break;
3524 case MP_CMD_DVDNAV_RIGHT:
3525 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3526 break;
3527 case MP_CMD_DVDNAV_MENU:
3528 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_MenuCall);
3529 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3530 break;
3531 case MP_CMD_DVDNAV_SELECT:
3532 dvdnav_button_activate(dvdnav_priv->dvdnav);
3533 break;
3534 default:
3535 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3536 break;
3538 break;
3540 #endif
3541 default : {
3542 #ifdef HAVE_NEW_GUI
3543 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3544 else
3545 #endif
3546 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3549 mp_cmd_free(cmd);
3553 if (seek_to_sec) {
3554 int a,b; float d;
3556 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3557 rel_seek_secs += 3600*a +60*b +d ;
3558 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3559 rel_seek_secs += 60*a +d;
3560 else if (sscanf(seek_to_sec, "%f", &d)==1)
3561 rel_seek_secs += d;
3563 seek_to_sec = NULL;
3566 /* Looping. */
3567 if(eof==1 && loop_times>=0) {
3568 int l = loop_times;
3569 play_tree_iter_step(playtree_iter,0,0);
3570 loop_times = l;
3571 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3573 if(loop_times>1) loop_times--; else
3574 if(loop_times==1) loop_times=-1;
3575 play_n_frames=play_n_frames_mf;
3576 eof=0;
3577 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3578 loop_seek = 1;
3581 if(rel_seek_secs || abs_seek_pos){
3582 current_module="seek";
3583 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3584 // success:
3585 /* FIXME there should be real seeking for vobsub */
3586 if(sh_video) sh_video->pts=d_video->pts;
3587 if (vo_vobsub)
3588 //vobsub_reset(vo_vobsub);
3589 vobsub_seek(vo_vobsub,sh_video->pts);
3590 #if 0
3591 if(sh_video && d_video->packs == 0)
3592 ds_fill_buffer(d_video);
3593 if(sh_audio){
3594 if(d_audio->packs == 0)
3595 ds_fill_buffer(d_audio);
3596 if(verbose>0){
3597 float a_pts=d_audio->pts;
3598 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3599 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);
3601 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);
3602 } else {
3603 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3605 #endif
3606 fflush(stdout);
3608 if(sh_video){
3609 current_module="seek_video_reset";
3610 resync_video_stream(sh_video);
3611 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3614 if(sh_audio){
3615 current_module="seek_audio_reset";
3616 audio_out->reset(); // stop audio, throwing away buffered data
3618 #ifdef USE_OSD
3619 // Set OSD:
3620 if(osd_level && !loop_seek){
3621 #ifdef USE_EDL
3622 if( !edl_decision ) {
3623 #else
3624 if( 1 ) { // Let the compiler optimize this out
3625 #endif
3626 int len=((demuxer->movi_end-demuxer->movi_start)>>8);
3627 if (len>0 && sh_video){
3628 osd_visible=sh_video->fps; // 1 sec
3629 vo_osd_progbar_type=0;
3630 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
3631 vo_osd_changed(OSDTYPE_PROGBAR);
3635 #endif
3636 if(sh_video) {
3637 c_total=0;
3638 max_pts_correction=0.1;
3639 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3640 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3641 drop_frame_cnt=0;
3642 too_slow_frame_cnt=0;
3643 too_fast_frame_cnt=0;
3645 if(vo_spudec) spudec_reset(vo_spudec);
3648 #ifdef USE_EDL
3650 * We saw a seek, have to rewind the EDL operations stack
3651 * and find the next EDL action to take care of.
3654 next_edl_record = edl_records;
3656 while (next_edl_record)
3658 /* Trying to remember if we need to mute/unmute first;
3659 * prior EDL implementation lacks this.
3662 if (next_edl_record->start_sec >= sh_video->pts)
3664 if (edl_mute_count > 0)
3666 if ((edl_mute_count % 2) == 0 &&
3667 next_edl_record->mute_state == EDL_MUTE_END)
3669 mixer_mute(&mixer);
3670 edl_mute_count++;
3672 if ((edl_mute_count % 2) != 0 &&
3673 next_edl_record->mute_state == EDL_MUTE_START)
3675 mixer_mute(&mixer);
3676 edl_mute_count++;
3678 } else if (next_edl_record->mute_state == EDL_MUTE_END)
3680 mixer_mute(&mixer);
3681 edl_mute_count++;
3683 break;
3686 next_edl_record = next_edl_record->next;
3688 if (!next_edl_record && (edl_mute_count % 2) != 0
3689 && edl_mute_count > 0)
3691 mixer_mute(&mixer);
3692 edl_mute_count++;
3695 #endif
3696 rel_seek_secs=0;
3697 abs_seek_pos=0;
3698 frame_time_remaining=0;
3699 current_module=NULL;
3700 loop_seek=0;
3703 #ifdef HAVE_NEW_GUI
3704 if(use_gui){
3705 guiEventHandling();
3706 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3707 // get pos from frame number / total frames
3708 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3709 } else {
3710 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3711 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3712 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3714 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3715 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3716 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3717 guiGetEvent( guiReDraw,NULL );
3718 guiGetEvent( guiSetVolume,NULL );
3719 if(guiIntfStruct.Playing==0) break; // STOP
3720 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3721 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3722 #ifdef USE_DVDREAD
3723 if ( stream->type == STREAMTYPE_DVD )
3725 dvd_priv_t * dvdp = stream->priv;
3726 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3728 #endif
3730 #endif
3733 //================= Update OSD ====================
3734 #ifdef USE_OSD
3735 if(osd_level>=1 && sh_video){
3736 int pts=sh_video->pts;
3737 char osd_text_tmp[64];
3738 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
3739 vo_osd_text=osd_text_buffer;
3740 #ifdef USE_DVDNAV
3741 if (osd_show_dvd_nav_delay) {
3742 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
3743 osd_show_dvd_nav_delay--;
3744 } else
3745 #endif
3746 #ifdef USE_TV
3747 if (osd_show_tv_channel && tv_channel_list) {
3748 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
3749 osd_show_tv_channel--;
3750 } else
3751 #endif
3752 if (osd_show_text) {
3753 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
3754 osd_show_text--;
3755 } else
3756 if (osd_show_sub_visibility) {
3757 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
3758 osd_show_sub_visibility--;
3759 } else
3760 if (osd_show_vobsub_changed) {
3761 if (vo_vobsub && vobsub_id >= 0) {
3762 const char *language = "none";
3763 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
3764 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
3766 #ifdef HAVE_OGGVORBIS
3767 if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG) {
3768 if (dvdsub_id < 0)
3769 snprintf(osd_text_tmp, 63, "Subtitles: (off)");
3770 else {
3771 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
3772 if (!lang) lang = "unknown";
3773 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3776 #endif
3777 #ifdef USE_DVDREAD
3778 if (vo_spudec && (demuxer->type != DEMUXER_TYPE_MATROSKA)) {
3779 char lang[5] = "none";
3780 int code = 0;
3781 if (dvdsub_id >= 0) code = dvd_lang_from_sid(stream, dvdsub_id);
3782 if (code) {
3783 lang[0] = code >> 8;
3784 lang[1] = code;
3785 lang[2] = 0;
3787 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3789 #endif
3790 #ifdef HAVE_MATROSKA
3791 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3792 char lang[10] = "unknown";
3793 if (dvdsub_id >= 0) {
3794 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
3795 lang[9] = 0;
3796 } else
3797 strcpy(lang, "off");
3798 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3800 #endif
3801 osd_show_vobsub_changed--;
3802 } else
3803 #ifdef USE_SUB
3804 if (osd_show_sub_changed) {
3805 char *tmp2;
3806 tmp = subdata->filename;
3807 if ((tmp2 = strrchr(tmp, '/'))) {
3808 tmp = tmp2+1;
3810 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
3811 set_of_sub_pos + 1,
3812 strlen(tmp) < 20 ? "" : "...",
3813 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
3814 osd_show_sub_changed--;
3815 } else
3816 #endif
3817 if (osd_show_sub_delay) {
3818 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
3819 osd_show_sub_delay--;
3820 } else
3821 if (osd_show_sub_pos) {
3822 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
3823 osd_show_sub_pos--;
3824 } else
3825 if (osd_show_sub_alignment) {
3826 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
3827 (sub_alignment == 2 ? "bottom" :
3828 (sub_alignment == 1 ? "center" : "top")));
3829 osd_show_sub_alignment--;
3830 } else
3831 if (osd_show_av_delay) {
3832 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
3833 osd_show_av_delay--;
3834 } else if (osd_show_speed) {
3835 snprintf(osd_text_tmp, 63, "Speed: x %6.2f", playback_speed);
3836 osd_show_speed--;
3837 } else if (osd_show_ontop) {
3838 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
3839 osd_show_ontop--;
3840 } else if (osd_show_rootwin) {
3841 snprintf(osd_text_tmp, 63, "Rootwin: %sabled", vo_rootwin?"en":"dis");
3842 osd_show_rootwin--;
3843 } else if (osd_show_framedropping) {
3844 snprintf(osd_text_tmp, 63, "Framedropping: %s",
3845 (frame_dropping == 1 ? "on" :
3846 (frame_dropping == 2 ? "hard" : "off")));
3847 osd_show_framedropping--;
3848 } else if(osd_level>=2) {
3849 int len = demuxer_get_time_length(demuxer);
3850 int percentage = -1;
3851 char percentage_text[10];
3852 if (osd_show_percentage) {
3853 percentage = demuxer_get_percent_pos(demuxer);
3854 osd_show_percentage--;
3856 if (percentage >= 0)
3857 snprintf(percentage_text, 9, " (%d%%)", percentage);
3858 else
3859 percentage_text[0] = 0;
3860 if (osd_level == 3)
3861 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);
3862 else
3863 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
3864 } else osd_text_tmp[0]=0;
3866 if(strcmp(vo_osd_text, osd_text_tmp)) {
3867 strncpy(vo_osd_text, osd_text_tmp, 63);
3868 vo_osd_changed(OSDTYPE_OSD);
3870 } else {
3871 if(vo_osd_text) {
3872 vo_osd_text=NULL;
3873 vo_osd_changed(OSDTYPE_OSD);
3876 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3877 // vo_osd_text=osd_text_buffer;
3878 #endif
3880 #ifdef USE_SUB
3881 // find sub
3882 if(subdata && sh_video->pts>0){
3883 float pts=sh_video->pts;
3884 if(sub_fps==0) sub_fps=sh_video->fps;
3885 current_module="find_sub";
3886 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
3887 find_sub(subdata, (pts+sub_delay) *
3888 (subdata->sub_uses_time ? 100. : sub_fps));
3889 // FIXME! frame counter...
3890 sub_last_pts = pts;
3892 current_module=NULL;
3894 #endif
3896 #ifdef HAVE_X11
3897 if (stop_xscreensaver && sh_video) {
3898 current_module="stop_xscreensaver";
3899 xscreensaver_heartbeat();
3900 current_module=NULL;
3902 #endif
3904 // DVD sub:
3905 if(vo_config_count && vo_spudec) {
3906 unsigned char* packet=NULL;
3907 int len,timestamp;
3908 current_module="spudec";
3909 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
3910 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3911 while(1) {
3912 // Vobsub
3913 len = 0;
3914 if(vo_vobsub) {
3915 if(sh_video->pts+sub_delay>=0) {
3916 // The + next_frame_time is there because we'll display the sub at the next frame
3917 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
3918 if(len > 0) {
3919 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
3920 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);
3923 } else {
3924 // DVD sub
3925 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
3926 if(len > 0) {
3927 float x = d_dvdsub->pts - sh_video->pts;
3928 if (x < -10 || x > 10) // prevent missing subs on pts reset
3929 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
3930 else timestamp = 90000*(sh_video->timer + sub_delay);
3931 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);
3934 if(len<=0 || !packet) break;
3935 if(timestamp < 0) timestamp = 0;
3936 else spudec_assemble(vo_spudec,packet,len,timestamp);
3939 /* detect wether the sub has changed or not */
3940 if(spudec_changed(vo_spudec))
3941 vo_osd_changed(OSDTYPE_SPU);
3942 current_module=NULL;
3945 } // while(!eof)
3947 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
3951 goto_next_file: // don't jump here after ao/vo/getch initialization!
3953 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3955 if(benchmark){
3956 double tot=video_time_usage+vout_time_usage+audio_time_usage;
3957 double total_time_usage;
3958 total_time_usage_start=GetTimer()-total_time_usage_start;
3959 total_time_usage = (float)total_time_usage_start*0.000001;
3960 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3961 video_time_usage,vout_time_usage,audio_time_usage,
3962 total_time_usage-tot,total_time_usage);
3963 if(total_time_usage>0.0)
3964 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3965 100.0*video_time_usage/total_time_usage,
3966 100.0*vout_time_usage/total_time_usage,
3967 100.0*audio_time_usage/total_time_usage,
3968 100.0*(total_time_usage-tot)/total_time_usage,
3969 100.0);
3970 if(total_frame_cnt && frame_dropping)
3971 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3972 total_frame_cnt-drop_frame_cnt,
3973 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
3974 drop_frame_cnt,
3975 100*drop_frame_cnt/total_frame_cnt,
3976 total_frame_cnt,
3977 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
3981 // time to uninit all, except global stuff:
3982 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
3984 #ifdef USE_SUB
3985 if ( set_of_sub_size > 0 )
3987 current_module="sub_free";
3988 for (i = 0; i < set_of_sub_size; ++i)
3989 sub_free( set_of_subtitles[i] );
3990 set_of_sub_size = 0;
3991 vo_sub=NULL;
3992 subdata=NULL;
3994 #endif
3996 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
3997 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
3998 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
3999 eof = 1;
4000 } else {
4001 play_tree_iter_free(playtree_iter);
4002 playtree_iter = NULL;
4004 play_tree_step = 1;
4005 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
4006 eof = eof == PT_UP_NEXT ? 1 : -1;
4007 if ( playtree_iter ) {
4008 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
4009 eof = 1;
4010 } else {
4011 play_tree_iter_free(playtree_iter);
4012 playtree_iter = NULL;
4015 } else { // NEXT PREV SRC
4016 eof = eof == PT_PREV_SRC ? -1 : 1;
4019 if(eof == 0) eof = 1;
4021 while(playtree_iter != NULL) {
4022 filename = play_tree_iter_get_file(playtree_iter,eof);
4023 if(filename == NULL) {
4024 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
4025 play_tree_iter_free(playtree_iter);
4026 playtree_iter = NULL;
4028 } else
4029 break;
4032 #ifdef HAVE_NEW_GUI
4033 if( use_gui && !playtree_iter )
4035 #ifdef USE_DVDREAD
4036 if ( !guiIntfStruct.DiskChanged )
4037 #endif
4038 mplEnd();
4040 #endif
4042 if(use_gui || playtree_iter != NULL){
4044 eof = 0;
4045 goto play_next_file;
4048 #ifdef HAVE_FREETYPE
4049 current_module="uninit_font";
4050 if (vo_font) free_font_desc(vo_font);
4051 vo_font = NULL;
4052 done_freetype();
4053 #endif
4055 exit_player_with_rc(MSGTR_Exit_eof, 0);
4057 return 1;