prevent possible segfault when vidmodes is freed and config() calls vo_vm_switch
[mplayer.git] / mplayer.c
blobdea449203b4d86d620ebde4af3f6588827d45779
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
6 // #include <sys/mman.h>
7 #include <sys/types.h>
8 #ifndef __MINGW32__
9 #include <sys/ioctl.h>
10 #include <sys/wait.h>
11 #else
12 #define SIGHUP 1 /* hangup */
13 #define SIGQUIT 3 /* quit */
14 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
15 #define SIGBUS 10 /* bus error */
16 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
17 #endif
19 #include <sys/time.h>
20 #include <sys/stat.h>
22 #include <signal.h>
23 #include <time.h>
24 #include <fcntl.h>
25 #include <limits.h>
27 #include <errno.h>
29 #include "version.h"
30 #include "config.h"
32 #include "mp_msg.h"
34 #define HELP_MP_DEFINE_STATIC
35 #include "help_mp.h"
37 #include "m_option.h"
38 #include "m_config.h"
40 #include "cfg-mplayer-def.h"
42 #ifdef USE_SUB
43 #include "subreader.h"
44 #endif
46 #include "libvo/video_out.h"
48 #include "libvo/font_load.h"
49 #include "libvo/sub.h"
51 #ifdef HAVE_X11
52 #include "libvo/x11_common.h"
53 #endif
55 #include "libao2/audio_out.h"
56 #include "libao2/audio_plugin.h"
58 #include "codec-cfg.h"
60 #ifdef HAVE_LIBCSS
61 #include "libmpdemux/dvdauth.h"
62 #endif
64 #ifdef USE_DVDNAV
65 #include <dvdnav.h>
66 #endif
68 #ifdef USE_EDL
69 #include "edl.h"
70 #endif
72 #include "spudec.h"
73 #include "vobsub.h"
75 #include "osdep/getch2.h"
76 #include "osdep/timer.h"
78 #include "cpudetect.h"
80 #ifdef HAVE_NEW_GUI
81 #include "Gui/interface.h"
82 #endif
84 #include "input/input.h"
86 int slave_mode=0;
87 int verbose=0;
88 int identify=0;
89 static int quiet=0;
91 #define ABS(x) (((x)>=0)?(x):(-(x)))
92 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
94 #ifdef HAVE_RTC
95 #include <linux/rtc.h>
96 #endif
98 #ifdef USE_TV
99 #include "libmpdemux/tv.h"
100 #endif
102 #ifdef HAS_DVBIN_SUPPORT
103 #include "libmpdemux/dvbin.h"
104 static int last_dvb_step = 1;
105 #endif
107 #ifdef HAVE_MATROSKA
108 #include "libmpdemux/matroska.h"
109 #endif
111 //**************************************************************************//
112 // Playtree
113 //**************************************************************************//
114 #include "playtree.h"
115 #include "playtreeparser.h"
117 #ifdef HAVE_NEW_GUI
118 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
119 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
120 #endif
122 play_tree_t* playtree;
123 play_tree_iter_t* playtree_iter = NULL;
125 #define PT_NEXT_ENTRY 1
126 #define PT_PREV_ENTRY -1
127 #define PT_NEXT_SRC 2
128 #define PT_PREV_SRC -2
129 #define PT_UP_NEXT 3
130 #define PT_UP_PREV -3
132 //**************************************************************************//
133 // Config
134 //**************************************************************************//
135 m_config_t* mconfig;
137 extern play_tree_t*
138 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
139 extern int
140 m_config_parse_config_file(m_config_t* config, char *conffile);
142 //**************************************************************************//
143 // Config file
144 //**************************************************************************//
146 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
148 static int cfg_include(m_option_t *conf, char *filename){
149 return m_config_parse_config_file(mconfig, filename);
152 #include "get_path.c"
154 //**************************************************************************//
155 // XScreensaver
156 //**************************************************************************//
158 #ifdef HAVE_X11
159 void xscreensaver_heartbeat(float time);
160 #endif
162 //**************************************************************************//
163 //**************************************************************************//
164 // Input media streaming & demultiplexer:
165 //**************************************************************************//
167 static int max_framesize=0;
169 #include "libmpdemux/stream.h"
170 #include "libmpdemux/demuxer.h"
171 #include "libmpdemux/stheader.h"
172 //#include "parse_es.h"
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 use_stdin=0;
187 //**************************************************************************//
189 vo_functions_t *video_out=NULL;
190 ao_functions_t *audio_out=NULL;
192 int fixed_vo=0;
194 // benchmark:
195 double video_time_usage=0;
196 double vout_time_usage=0;
197 static double audio_time_usage=0;
198 static int total_time_usage_start=0;
199 static int total_frame_cnt=0;
200 static int drop_frame_cnt=0; // total number of dropped frames
201 int benchmark=0;
203 // options:
204 int auto_quality=0;
205 static int output_quality=0;
207 float playback_speed=1.0;
209 int use_gui=0;
211 #ifdef HAVE_NEW_GUI
212 int enqueue=0;
213 #endif
215 #define MAX_OSD_LEVEL 3
217 int osd_level=1;
218 int osd_level_saved=-1;
219 int osd_visible=100;
221 // seek:
222 static char *seek_to_sec=NULL;
223 static off_t seek_to_byte=0;
224 static off_t step_sec=0;
225 static int loop_times=-1;
226 static int loop_seek=0;
228 // A/V sync:
229 int autosync=0; // 30 might be a good default value.
231 // may be changed by GUI: (FIXME!)
232 float rel_seek_secs=0;
233 int abs_seek_pos=0;
235 // codecs:
236 char **audio_codec_list=NULL; // override audio codec
237 char **video_codec_list=NULL; // override video codec
238 char **audio_fm_list=NULL; // override audio codec family
239 char **video_fm_list=NULL; // override video codec family
241 // streaming:
242 int audio_id=-1;
243 int video_id=-1;
244 int dvdsub_id=-1;
245 int vobsub_id=-1;
246 char* audio_lang=NULL;
247 char* dvdsub_lang=NULL;
248 static char* spudec_ifo=NULL;
249 char* filename=NULL; //"MI2-Trailer.avi";
250 int forced_subs_only=0;
252 // cache2:
253 int stream_cache_size=-1;
254 #ifdef USE_STREAM_CACHE
255 extern int cache_fill_status;
256 #else
257 #define cache_fill_status 0
258 #endif
260 // dump:
261 static char *stream_dump_name="stream.dump";
262 int stream_dump_type=0;
264 // A-V sync:
265 static float default_max_pts_correction=-1;//0.01f;
266 static float max_pts_correction=0;//default_max_pts_correction;
267 static float c_total=0;
268 float audio_delay=0;
270 static int softsleep=0;
272 float force_fps=0;
273 static int force_srate=0;
274 static int audio_output_format=0;
275 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
276 static int play_n_frames=-1;
277 static int play_n_frames_mf=-1;
279 // screen info:
280 char** video_driver_list=NULL;
281 char** audio_driver_list=NULL;
283 extern char *vo_subdevice;
284 extern char *ao_subdevice;
286 // codec outfmt flags (defined in libmpcodecs/vd.c)
287 extern int vo_flags;
289 // sub:
290 char *font_name=NULL;
291 float font_factor=0.75;
292 char **sub_name=NULL;
293 float sub_delay=0;
294 float sub_fps=0;
295 int sub_auto = 1;
296 char *vobsub_name=NULL;
297 /*DSP!!char *dsp=NULL;*/
298 int subcc_enabled=0;
299 int suboverlap_enabled = 1;
300 #ifdef USE_SUB
301 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
302 int set_of_sub_size = 0;
303 int set_of_sub_pos = -1;
304 float sub_last_pts = -303;
305 #endif
307 static stream_t* stream=NULL;
308 static demuxer_t *demuxer=NULL;
309 static sh_audio_t *sh_audio=NULL;
310 static sh_video_t *sh_video=NULL;
312 char* current_module=NULL; // for debugging
314 // also modified by Gui/mplayer/gtk/eq.c:
315 int vo_gamma_gamma = 1000;
316 int vo_gamma_brightness = 1000;
317 int vo_gamma_contrast = 1000;
318 int vo_gamma_saturation = 1000;
319 int vo_gamma_hue = 1000;
321 // ---
323 #ifdef HAVE_MENU
324 #include "m_struct.h"
325 #include "libmenu/menu.h"
326 extern void vf_menu_pause_update(struct vf_instance_s* vf);
327 extern vf_info_t vf_info_menu;
328 static vf_info_t* libmenu_vfs[] = {
329 &vf_info_menu,
330 NULL
332 static vf_instance_t* vf_menu = NULL;
333 static int use_menu = 0;
334 static char* menu_cfg = NULL;
335 static char* menu_root = "main";
336 #endif
339 #ifdef HAVE_RTC
340 static int nortc;
341 #endif
343 #ifdef USE_EDL
344 struct edl_record edl_records[ MAX_EDL_ENTRIES ];
345 int num_edl_records = 0;
346 FILE* edl_fd = NULL;
347 edl_record_ptr next_edl_record = NULL;
348 static char* edl_filename = NULL;
349 static char* edl_output_filename = NULL;
350 short edl_decision = 0;
351 #endif
353 static unsigned int inited_flags=0;
354 #define INITED_VO 1
355 #define INITED_AO 2
356 #define INITED_GUI 4
357 #define INITED_GETCH2 8
358 #define INITED_SPUDEC 32
359 #define INITED_STREAM 64
360 #define INITED_INPUT 128
361 #define INITED_VOBSUB 256
362 #define INITED_DEMUXER 512
363 #define INITED_ACODEC 1024
364 #define INITED_VCODEC 2048
365 #define INITED_ALL 0xFFFF
367 static void uninit_player(unsigned int mask){
368 mask=inited_flags&mask;
370 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
372 if(mask&INITED_ACODEC){
373 inited_flags&=~INITED_ACODEC;
374 current_module="uninit_acodec";
375 if(sh_audio) uninit_audio(sh_audio);
376 sh_audio=NULL;
379 if(mask&INITED_VCODEC){
380 inited_flags&=~INITED_VCODEC;
381 current_module="uninit_vcodec";
382 if(sh_video) uninit_video(sh_video);
383 sh_video=NULL;
384 #ifdef HAVE_MENU
385 vf_menu=NULL;
386 #endif
389 if(mask&INITED_DEMUXER){
390 inited_flags&=~INITED_DEMUXER;
391 current_module="free_demuxer";
392 if(demuxer){
393 stream=demuxer->stream;
394 free_demuxer(demuxer);
396 demuxer=NULL;
399 // kill the cache process:
400 if(mask&INITED_STREAM){
401 inited_flags&=~INITED_STREAM;
402 current_module="uninit_stream";
403 if(stream) free_stream(stream);
404 stream=NULL;
407 if(mask&INITED_VO){
408 inited_flags&=~INITED_VO;
409 current_module="uninit_vo";
410 video_out->uninit();
411 video_out=NULL;
414 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
415 if(mask&INITED_GETCH2){
416 inited_flags&=~INITED_GETCH2;
417 current_module="uninit_getch2";
418 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
419 // restore terminal:
420 getch2_disable();
423 if(mask&INITED_VOBSUB){
424 inited_flags&=~INITED_VOBSUB;
425 current_module="uninit_vobsub";
426 if(vo_vobsub) vobsub_close(vo_vobsub);
427 vo_vobsub=NULL;
430 if (mask&INITED_SPUDEC){
431 inited_flags&=~INITED_SPUDEC;
432 current_module="uninit_spudec";
433 spudec_free(vo_spudec);
434 vo_spudec=NULL;
437 if(mask&INITED_AO){
438 inited_flags&=~INITED_AO;
439 current_module="uninit_ao";
440 audio_out->uninit(); audio_out=NULL;
443 #ifdef HAVE_NEW_GUI
444 if(mask&INITED_GUI){
445 inited_flags&=~INITED_GUI;
446 current_module="uninit_gui";
447 guiDone();
449 #endif
451 if(mask&INITED_INPUT){
452 inited_flags&=~INITED_INPUT;
453 current_module="uninit_input";
454 mp_input_uninit();
457 current_module=NULL;
460 static void exit_player_with_rc(char* how, int rc){
462 uninit_player(INITED_ALL);
463 #ifdef HAVE_X11
464 #ifdef HAVE_NEW_GUI
465 if ( !use_gui )
466 #endif
467 vo_uninit(); // close the X11 connection (if any opened)
468 #endif
470 current_module="exit_player";
472 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Exiting,mp_gettext(how));
473 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
475 exit(rc);
478 void exit_player(char* how){
479 exit_player_with_rc(how, 1);
482 static void exit_sighandler(int x){
483 static int sig_count=0;
484 ++sig_count;
485 if(sig_count==5 || (inited_flags==0 && sig_count>1)) exit(1);
486 if(sig_count>5){
487 // can't stop :(
488 #ifndef __MINGW32__
489 kill(getpid(),SIGKILL);
490 #endif
492 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
493 current_module?current_module:mp_gettext("unknown")
495 if(sig_count==1)
496 switch(x){
497 case SIGINT:
498 case SIGQUIT:
499 case SIGTERM:
500 case SIGKILL:
501 break; // killed from keyboard (^C) or killed [-9]
502 case SIGILL:
503 #ifdef RUNTIME_CPUDETECT
504 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
505 #else
506 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
507 #endif
508 case SIGFPE:
509 case SIGSEGV:
510 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
511 default:
512 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
514 exit_player(NULL);
517 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
519 extern void mp_input_register_options(m_config_t* cfg);
521 #include "mixer.h"
522 #include "cfg-mplayer.h"
524 void parse_cfgfiles( m_config_t* conf )
526 char *conffile;
527 int conffile_fd;
528 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
529 exit(1);
530 if ((conffile = get_path("")) == NULL) {
531 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
532 } else {
533 #ifdef __MINGW32__
534 mkdir(conffile);
535 #else
536 mkdir(conffile, 0777);
537 #endif
538 free(conffile);
539 if ((conffile = get_path("config")) == NULL) {
540 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
541 } else {
542 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
543 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
544 write(conffile_fd, default_config, strlen(default_config));
545 close(conffile_fd);
547 if (m_config_parse_config_file(conf, conffile) < 0)
548 exit(1);
549 free(conffile);
554 void load_per_file_config (m_config_t* conf, const char *const file)
556 char *confpath;
557 char cfg[strlen(file)+10];
558 struct stat st;
559 char *name;
561 sprintf (cfg, "%s.conf", file);
563 if (!stat (cfg, &st))
565 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Loading config '%s'\n", cfg);
566 m_config_parse_config_file (conf, cfg);
567 return;
570 if ((name = strrchr (cfg, '/')) == NULL)
571 name = cfg;
572 else
573 name++;
575 if ((confpath = get_path (name)) != NULL)
577 if (!stat (confpath, &st))
579 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Loading config '%s'\n", confpath);
580 m_config_parse_config_file (conf, confpath);
583 free (confpath);
587 // When libmpdemux perform a blocking operation (network connection or cache filling)
588 // if the operation fail we use this function to check if it was interrupted by the user.
589 // The function return a new value for eof.
590 static int libmpdemux_was_interrupted(int eof) {
591 mp_cmd_t* cmd;
592 if((cmd = mp_input_get_cmd(0,0)) != NULL) {
593 switch(cmd->id) {
594 case MP_CMD_QUIT:
595 exit_player_with_rc(MSGTR_Exit_quit, 0);
596 case MP_CMD_PLAY_TREE_STEP: {
597 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
598 } break;
599 case MP_CMD_PLAY_TREE_UP_STEP: {
600 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
601 } break;
602 case MP_CMD_PLAY_ALT_SRC_STEP: {
603 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
604 } break;
606 mp_cmd_free(cmd);
608 return eof;
611 #define mp_basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
613 int playtree_add_playlist(play_tree_t* entry)
615 play_tree_add_bpf(entry,filename);
617 #ifdef HAVE_NEW_GUI
618 if (use_gui) {
619 if (entry) {
620 import_playtree_playlist_into_gui(entry, mconfig);
621 play_tree_free_list(entry,1);
623 } else
624 #endif
626 if(!entry) {
627 entry = playtree_iter->tree;
628 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
629 return PT_NEXT_ENTRY;
631 if(playtree_iter->tree == entry ) { // Loop with a single file
632 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
633 return PT_NEXT_ENTRY;
636 play_tree_remove(entry,1,1);
637 return PT_NEXT_SRC;
639 play_tree_insert_entry(playtree_iter->tree,entry);
640 play_tree_set_params_from(entry,playtree_iter->tree);
641 entry = playtree_iter->tree;
642 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
643 return PT_NEXT_ENTRY;
645 play_tree_remove(entry,1,1);
647 return PT_NEXT_SRC;
650 static int play_tree_step = 1;
652 #ifdef USE_SUB
654 sub_data* subdata = NULL;
656 void add_subtitles(char *filename, float fps, int silent)
658 sub_data *subd;
660 if (filename == NULL) {
661 subd = (sub_data*)malloc(sizeof(sub_data));
662 subd->filename = strdup("none");
663 subd->subtitles = NULL;
664 subd->sub_uses_time = 1;
665 subd->sub_num = 0;
666 subd->sub_errs = 0;
667 set_of_subtitles[set_of_sub_size] = subd;
668 ++set_of_sub_size;
669 return;
672 subd = sub_read_file(filename, fps);
673 if(!subd && !silent)
674 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
675 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
676 set_of_subtitles[set_of_sub_size] = subd;
677 ++set_of_sub_size;
678 printf("SUB: added subtitle file (%d): %s\n", set_of_sub_size, filename);
681 void update_set_of_subtitles()
682 // subdata was changed, set_of_sub... have to be updated.
684 int i;
685 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
686 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
687 set_of_subtitles[i-1] = set_of_subtitles[i];
688 set_of_subtitles[set_of_sub_size-1] = NULL;
689 --set_of_sub_size;
690 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
692 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
693 set_of_subtitles[set_of_sub_pos] = subdata;
695 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
696 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
697 ++set_of_sub_size;
700 #endif
703 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
704 * make it all work is to use the builtin SDL-bootstrap code, which
705 * will be done automatically by replacing our main() if we include SDL.h.
707 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
708 #include <SDL.h>
709 #endif
712 int main(int argc,char* argv[]){
716 static demux_stream_t *d_audio=NULL;
717 static demux_stream_t *d_video=NULL;
718 static demux_stream_t *d_dvdsub=NULL;
720 int file_format=DEMUXER_TYPE_UNKNOWN;
722 int delay_corrected=1;
724 // movie info:
725 int eof=0;
727 int osd_function=OSD_PLAY;
728 int osd_last_pts=-303;
729 int osd_show_av_delay = 0;
730 int osd_show_text = 0;
731 int osd_show_sub_delay = 0;
732 int osd_show_sub_pos = 0;
733 int osd_show_sub_visibility = 0;
734 int osd_show_sub_alignment = 0;
735 int osd_show_vobsub_changed = 0;
736 int osd_show_sub_changed = 0;
737 int osd_show_percentage = 0;
738 int osd_show_tv_channel = 25;
739 int osd_show_ontop = 0;
741 int rtc_fd=-1;
743 //float a_frame=0; // Audio
745 int i;
746 char *tmp;
748 int gui_no_filename=0;
751 srand((int) time(NULL));
753 mp_msg_init();
754 mp_msg_set_level(MSGL_STATUS);
756 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2003 MPlayer Team\n\n");
757 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
758 GetCpuCaps(&gCpuCaps);
759 #ifdef ARCH_X86
760 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
761 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
762 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
763 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
764 #ifdef RUNTIME_CPUDETECT
765 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
766 #else
767 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
768 #ifdef HAVE_MMX
769 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
770 #endif
771 #ifdef HAVE_MMX2
772 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
773 #endif
774 #ifdef HAVE_3DNOW
775 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
776 #endif
777 #ifdef HAVE_3DNOWEX
778 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
779 #endif
780 #ifdef HAVE_SSE
781 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
782 #endif
783 #ifdef HAVE_SSE2
784 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
785 #endif
786 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
787 #endif
788 #endif
790 #if defined(WIN32) && defined(USE_WIN32DLL)
791 { /*make our codec dirs available for LoadLibraryA()*/
792 char tmppath[MAX_PATH*2 + 1];
793 char win32path[MAX_PATH];
794 char realpath[MAX_PATH];
795 int WINAPI SetEnvironmentVariableA(char*,char*);
796 int WINAPI GetModuleFileNameA(void*,char*,int);
797 #ifdef __CYGWIN__
798 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
799 strcpy(tmppath,win32path);
800 #ifdef USE_REALCODECS
801 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
802 sprintf(tmppath,"%s;%s",win32path,realpath);
803 #endif /*USE_REALCODECS*/
804 #else
805 if(!strstr(WIN32_PATH,":")){
806 GetModuleFileNameA(NULL, win32path, MAX_PATH);
807 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
809 else strcpy(win32path,WIN32_PATH);
810 strcpy(tmppath,win32path);
811 #ifdef USE_REALCODECS
812 if(!strstr(REALCODEC_PATH,":")){
813 GetModuleFileNameA(NULL, realpath, MAX_PATH);
814 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
816 else strcpy(realpath,REALCODEC_PATH);
817 sprintf(tmppath,"%s;%s",win32path,realpath);
818 #endif /*USE_REALCODECS*/
819 #endif /*__CYGWIN__*/
820 SetEnvironmentVariableA("PATH", tmppath);
822 #endif /*WIN32 && USE_WIN32DLL*/
824 #ifdef USE_TV
825 tv_param_immediate = 1;
826 #endif
828 if ( argv[0] )
829 if(!strcmp(argv[0],"gmplayer") ||
830 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
831 use_gui=1;
833 mconfig = m_config_new();
834 m_config_register_options(mconfig,mplayer_opts);
835 // TODO : add something to let modules register their options
836 mp_input_register_options(mconfig);
837 parse_cfgfiles(mconfig);
839 #ifdef HAVE_NEW_GUI
840 if ( use_gui ) cfg_read();
841 #endif
843 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
844 if(playtree == NULL)
845 exit(1);
847 playtree = play_tree_cleanup(playtree);
848 if(playtree) {
849 playtree_iter = play_tree_iter_new(playtree,mconfig);
850 if(playtree_iter) {
851 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
852 play_tree_iter_free(playtree_iter);
853 playtree_iter = NULL;
855 filename = play_tree_iter_get_file(playtree_iter,1);
859 #ifndef HAVE_NEW_GUI
860 if(use_gui){
861 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
862 use_gui=0;
864 #else
865 if(use_gui && !vo_init()){
866 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
867 use_gui=0;
869 if (use_gui && playtree_iter){
870 char cwd[PATH_MAX+2];
871 // Remove Playtree and Playtree-Iter from memory as its not used by gui
872 play_tree_iter_free(playtree_iter);
873 playtree_iter=NULL;
875 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
877 strcat(cwd, "/");
878 // Prefix relative paths with current working directory
879 play_tree_add_bpf(playtree, cwd);
881 // Import initital playtree into gui
882 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
884 #endif
886 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
887 list_video_out();
888 exit(0);
891 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
892 list_audio_out();
893 exit(0);
896 // check codec.conf
897 if(!parse_codec_cfg(get_path("codecs.conf"))){
898 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
899 if(!parse_codec_cfg(NULL)){
900 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
901 exit(0);
903 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_BuiltinCodecsConf);
907 #if 0
908 if(video_codec_list){
909 int i;
910 video_codec=video_codec_list[0];
911 for(i=0;video_codec_list[i];i++)
912 printf("vc#%d: '%s'\n",i,video_codec_list[i]);
914 #endif
915 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
916 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
917 list_codecs(1);
918 printf("\n");
919 exit(0);
921 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
922 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
923 list_codecs(0);
924 printf("\n");
925 exit(0);
927 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
928 vfm_help();
929 printf("\n");
930 exit(0);
932 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
933 afm_help();
934 printf("\n");
935 exit(0);
937 #ifdef HAVE_X11
938 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
939 fstype_help();
940 printf("\n");
941 exit(0);
943 #endif
945 #ifdef USE_EDL
947 FILE* fd;
948 char line[ 100 ];
949 float start, stop, duration;
950 int action;
951 int next_edl_array_index = 0;
952 int lineCount = 0;
953 next_edl_record = edl_records;
954 if( edl_filename ) {
955 if( ( fd = fopen( edl_filename, "r" ) ) == NULL ) {
956 printf( "Error opening EDL file [%s]!\n", edl_filename );
957 next_edl_record->next = NULL;
958 } else {
959 while( fgets( line, 99, fd ) != NULL ) {
960 lineCount++;
961 if( ( sscanf( line, "%f %f %d", &start, &stop, &action ) ) == 0 ) {
962 printf( "Invalid EDL line: [%s]\n", line );
963 } else {
964 if( next_edl_array_index > 0 ) {
965 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
966 if( start <= edl_records[ next_edl_array_index-1 ].stop_sec ) {
967 printf( "Invalid EDL line [%d]: [%s]\n", lineCount, line );
968 printf( "Last stop position was [%f]; next start is [%f]. Entries must be in chronological order and cannot overlap. Discarding EDL entry.\n", edl_records[ next_edl_array_index-1 ].stop_sec, start );
969 continue;
972 if( stop <= start ) {
973 printf( "Invalid EDL line [%d]: [%s]\n", lineCount, line );
974 printf( "Stop time must follow start time. Discarding EDL entry.\n" );
975 continue;
977 edl_records[ next_edl_array_index ].action = action;
978 if( action == EDL_MUTE ) {
979 edl_records[ next_edl_array_index ].length_sec = 0;
980 edl_records[ next_edl_array_index ].start_sec = start;
981 edl_records[ next_edl_array_index ].stop_sec = start;
982 next_edl_array_index++;
983 if( next_edl_array_index >= MAX_EDL_ENTRIES-1 ) {
984 break;
986 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
987 edl_records[ next_edl_array_index ].action = EDL_MUTE;
988 edl_records[ next_edl_array_index ].length_sec = 0;
989 edl_records[ next_edl_array_index ].start_sec = stop;
990 edl_records[ next_edl_array_index ].stop_sec = stop;
991 } else {
992 edl_records[ next_edl_array_index ].length_sec = stop - start;
993 edl_records[ next_edl_array_index ].start_sec = start;
994 edl_records[ next_edl_array_index ].stop_sec = stop;
996 next_edl_array_index++;
997 if( next_edl_array_index >= MAX_EDL_ENTRIES-1 ) {
998 break;
1002 if( next_edl_array_index > 0 ) {
1003 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
1005 edl_records[ next_edl_array_index ].start_sec = -1;
1006 edl_records[ next_edl_array_index ].next = NULL;
1007 num_edl_records = ( next_edl_array_index );
1009 fclose( fd );
1010 } else {
1011 next_edl_record->next = NULL;
1013 if( edl_output_filename ) {
1014 if( edl_filename ) {
1015 printf( "Sorry; EDL mode and EDL output mode are mutually exclusive! Disabling all EDL functions.\n" );
1016 edl_output_filename = NULL;
1017 edl_filename = NULL;
1018 next_edl_record->next = NULL;
1019 } else {
1020 if( ( edl_fd = fopen( edl_output_filename, "w" ) ) == NULL ) {
1021 printf( "Error opening file [%s] for writing!\n", edl_output_filename );
1022 edl_output_filename = NULL;
1023 next_edl_record->next = NULL;
1027 #ifdef DEBUG_EDL
1029 printf( "EDL Records:\n" );
1030 if( next_edl_record->next != NULL ) {
1031 while( next_edl_record->next != NULL ) {
1032 printf( "EDL: start [%f], stop [%f], action [%d]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->action );
1033 next_edl_record = next_edl_record->next;
1035 next_edl_record = edl_records;
1038 #endif
1040 #endif
1042 if(!filename){
1043 if(!use_gui){
1044 // no file/vcd/dvd -> show HELP:
1045 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1046 exit(0);
1047 } else gui_no_filename=1;
1050 // Many users forget to include command line in bugreports...
1051 if(verbose>0){
1052 mp_msg(MSGT_CPLAYER, MSGL_INFO, "CommandLine:");
1053 for(i=1;i<argc;i++)printf(" '%s'",argv[i]);
1054 printf("\n");
1057 mp_msg_set_level(verbose+MSGL_STATUS);
1059 //------ load global data first ------
1061 #ifdef USE_OSD
1062 // check font
1063 if(font_name){
1064 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1065 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1066 } else {
1067 // try default:
1068 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1);
1069 if(!vo_font)
1070 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1072 #ifdef HAVE_FREETYPE
1073 if (!vo_font)
1074 init_freetype();
1075 #endif
1076 #endif
1077 vo_init_osd();
1079 #ifdef HAVE_RTC
1080 if(!nortc)
1082 // seteuid(0); /* Can't hurt to try to get root here */
1083 if ((rtc_fd = open("/dev/rtc", O_RDONLY)) < 0)
1084 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Failed to open /dev/rtc: %s (mplayer should be setuid root or /dev/rtc should be readable by the user.)\n", strerror(errno));
1085 else {
1086 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1088 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1089 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp, strerror(errno));
1090 mp_msg(MSGT_CPLAYER, MSGL_HINT, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp);
1091 close (rtc_fd);
1092 rtc_fd = -1;
1093 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1094 /* variable only by the root */
1095 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno));
1096 close (rtc_fd);
1097 rtc_fd = -1;
1098 } else
1099 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_UsingRTCTiming, irqp);
1102 #ifdef HAVE_NEW_GUI
1103 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1104 // and now ? -- Pontscho
1105 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1106 #endif
1107 if(rtc_fd<0)
1108 #endif
1109 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Using %s timing\n",softsleep?"software":"usleep()");
1111 #ifdef USE_TERMCAP
1112 if ( !use_gui ) load_termcap(NULL); // load key-codes
1113 #endif
1115 // ========== Init keyboard FIFO (connection to libvo) ============
1117 // Init input system
1118 current_module = "init_input";
1119 mp_input_init();
1120 #ifndef HAVE_NO_POSIX_SELECT
1121 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1123 if(keyb_fifo_get > 0)
1124 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1125 #else
1126 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1127 #endif
1128 if(slave_mode)
1129 #ifndef __MINGW32__
1130 mp_input_add_cmd_fd(0,1,NULL,NULL);
1131 #else
1132 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1133 #endif
1134 else if(!use_stdin)
1135 #ifndef HAVE_NO_POSIX_SELECT
1136 mp_input_add_key_fd(0,1,NULL,NULL);
1137 #else
1138 mp_input_add_key_fd(0,0,NULL,NULL);
1139 #endif
1141 inited_flags|=INITED_INPUT;
1142 current_module = NULL;
1144 #ifdef HAVE_MENU
1145 if(use_menu) {
1146 if(menu_cfg && menu_init(menu_cfg))
1147 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", menu_cfg);
1148 else {
1149 menu_cfg = get_path("menu.conf");
1150 if(menu_init(menu_cfg))
1151 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", menu_cfg);
1152 else {
1153 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1154 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", MPLAYER_CONFDIR"/menu.conf");
1155 else {
1156 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu init failed\n");
1157 use_menu = 0;
1162 #endif
1166 //========= Catch terminate signals: ================
1167 // terminate requests:
1168 signal(SIGTERM,exit_sighandler); // kill
1169 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1171 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1173 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1174 #ifdef ENABLE_SIGHANDLER
1175 // fatal errors:
1176 signal(SIGBUS,exit_sighandler); // bus error
1177 signal(SIGSEGV,exit_sighandler); // segfault
1178 signal(SIGILL,exit_sighandler); // illegal instruction
1179 signal(SIGFPE,exit_sighandler); // floating point exc.
1180 signal(SIGABRT,exit_sighandler); // abort()
1181 #endif
1183 #ifdef HAVE_NEW_GUI
1184 if(use_gui){
1185 guiInit();
1186 inited_flags|=INITED_GUI;
1187 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1189 #endif
1191 // ******************* Now, let's see the per-file stuff ********************
1193 play_next_file:
1195 if (filename) load_per_file_config (mconfig, filename);
1197 // We must enable getch2 here to be able to interrupt network connection
1198 // or cache filling
1199 if(!use_stdin && !slave_mode){
1200 if(inited_flags&INITED_GETCH2)
1201 mp_msg(MSGT_CPLAYER,MSGL_WARN,"WARNING: getch2_init called twice!\n");
1202 else
1203 getch2_enable(); // prepare stdin for hotkeys...
1204 inited_flags|=INITED_GETCH2;
1205 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1208 // =================== GUI idle loop (STOP state) ===========================
1209 #ifdef HAVE_NEW_GUI
1210 if ( use_gui ) {
1211 file_format=DEMUXER_TYPE_UNKNOWN;
1212 guiGetEvent( guiSetDefaults,0 );
1213 while ( guiIntfStruct.Playing != 1 )
1215 mp_cmd_t* cmd;
1216 usec_sleep(20000);
1217 guiEventHandling();
1218 guiGetEvent( guiReDraw,NULL );
1219 if ( (cmd = mp_input_get_cmd(0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1221 guiGetEvent( guiSetParameters,NULL );
1222 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1224 play_tree_t * entry = play_tree_new();
1225 play_tree_add_file( entry,guiIntfStruct.Filename );
1226 if ( playtree ) play_tree_free_list( playtree->child,1 );
1227 else playtree=play_tree_new();
1228 play_tree_set_child( playtree,entry );
1229 if(playtree)
1231 playtree_iter = play_tree_iter_new(playtree,mconfig);
1232 if(playtree_iter)
1234 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1236 play_tree_iter_free(playtree_iter);
1237 playtree_iter = NULL;
1239 filename = play_tree_iter_get_file(playtree_iter,1);
1244 #endif
1245 //---------------------------------------------------------------------------
1247 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
1248 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1250 //==================== Open VOB-Sub ============================
1252 current_module="vobsub";
1253 if (vobsub_name){
1254 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1255 if(vo_vobsub==NULL)
1256 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1257 }else if(sub_auto && filename && (strlen(filename)>=5)){
1258 /* try to autodetect vobsub from movie filename ::atmos */
1259 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1260 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1261 strncpy(buf, filename, strlen(filename)-4);
1262 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1263 free(buf);
1265 if(vo_vobsub){
1266 sub_auto=0; // don't do autosub for textsubs if vobsub found
1267 inited_flags|=INITED_VOBSUB;
1268 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1269 // check if vobsub requested only to display forced subtitles
1270 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1273 //============ Open & Sync STREAM --- fork cache2 ====================
1275 stream=NULL;
1276 demuxer=NULL;
1277 if (d_audio) {
1278 //free_demuxer_stream(d_audio);
1279 d_audio=NULL;
1281 if (d_video) {
1282 //free_demuxer_stream(d_video);
1283 d_video=NULL;
1285 sh_audio=NULL;
1286 sh_video=NULL;
1288 current_module="open_stream";
1289 stream=open_stream(filename,0,&file_format);
1290 if(!stream) { // error...
1291 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1292 goto goto_next_file;
1294 inited_flags|=INITED_STREAM;
1296 #ifdef HAVE_NEW_GUI
1297 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1298 #endif
1300 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1301 play_tree_t* entry;
1302 // Handle playlist
1303 current_module="handle_playlist";
1304 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1305 entry = parse_playtree(stream,0);
1306 eof=playtree_add_playlist(entry);
1307 goto goto_next_file;
1309 stream->start_pos+=seek_to_byte;
1311 #ifdef HAVE_LIBCSS
1312 current_module="libcss";
1313 if (dvdimportkey) {
1314 if (dvd_import_key(dvdimportkey)) {
1315 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorDVDkey);
1316 exit_player(MSGTR_Exit_error);
1318 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CmdlineDVDkey);
1320 if (dvd_auth_device) {
1321 if (dvd_auth(dvd_auth_device,filename)) {
1322 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"Error in DVD auth...\n");
1323 exit_player(MSGTR_Exit_error);
1325 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_DVDauthOk);
1327 #endif
1329 if(stream_dump_type==5){
1330 unsigned char buf[4096];
1331 int len;
1332 FILE *f;
1333 current_module="dumpstream";
1334 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1335 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"Cannot dump this stream - no 'fd' available\n");
1336 exit_player(MSGTR_Exit_error);
1338 stream_reset(stream);
1339 stream_seek(stream,stream->start_pos);
1340 f=fopen(stream_dump_name,"wb");
1341 if(!f){
1342 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1343 exit_player(MSGTR_Exit_error);
1345 while(!stream->eof){
1346 len=stream_read(stream,buf,4096);
1347 if(len>0) {
1348 if(fwrite(buf,len,1,f) != 1) {
1349 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1350 exit_player(MSGTR_Exit_error);
1354 if(fclose(f)) {
1355 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1356 exit_player(MSGTR_Exit_error);
1358 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1359 exit_player_with_rc(MSGTR_Exit_eof, 0);
1362 #ifdef USE_DVDREAD
1363 if(stream->type==STREAMTYPE_DVD){
1364 current_module="dvd lang->id";
1365 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1366 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1367 current_module=NULL;
1369 #endif
1371 #ifdef USE_DVDNAV
1372 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1373 #endif
1375 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1376 goto_enable_cache:
1377 if(stream_cache_size>0){
1378 current_module="enable_cache";
1379 if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024/5,stream_cache_size*1024/20))
1380 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1383 //============ Open DEMUXERS --- DETECT file type =======================
1384 current_module="demux_open";
1386 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1388 // HACK to get MOV Reference Files working
1390 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1392 unsigned char* playlist_entry;
1393 play_tree_t *list = NULL, *entry = NULL;
1395 current_module="handle_demux_playlist";
1396 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1398 char *temp, *bname;
1400 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry\n",playlist_entry);
1402 bname=mp_basename(playlist_entry);
1403 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1404 continue;
1406 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1407 continue;
1409 entry = play_tree_new();
1411 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1413 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1414 if (temp)
1416 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1417 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1418 strcat(temp, playlist_entry);
1419 play_tree_add_file(entry,temp);
1420 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s\n",temp);
1421 free(temp);
1424 else
1425 play_tree_add_file(entry,playlist_entry);
1427 if(!list)
1428 list = entry;
1429 else
1430 play_tree_append_entry(list,entry);
1432 free_demuxer(demuxer);
1433 demuxer = NULL;
1435 if (list)
1437 entry = play_tree_new();
1438 play_tree_set_child(entry,list);
1439 eof=playtree_add_playlist(entry);
1440 goto goto_next_file;
1444 if(!demuxer)
1446 #if 0
1447 play_tree_t* entry;
1448 // Handle playlist
1449 current_module="handle_playlist";
1450 switch(stream->type){
1451 case STREAMTYPE_VCD:
1452 case STREAMTYPE_DVD:
1453 case STREAMTYPE_DVDNAV:
1454 case STREAMTYPE_CDDA:
1455 case STREAMTYPE_VCDBINCUE:
1456 // don't try to parse raw media as playlist, it's unlikely
1457 goto goto_next_file;
1459 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Falling back on trying to parse playlist %s...\n",filename);
1460 stream_reset(stream);
1461 stream_seek(stream,stream->start_pos);
1462 entry = parse_playtree(stream,0);
1463 if(!entry)
1464 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1465 else
1466 eof=playtree_add_playlist(entry);
1467 #endif
1468 goto goto_next_file;
1470 inited_flags|=INITED_DEMUXER;
1472 current_module="demux_open2";
1474 //file_format=demuxer->file_format;
1476 d_audio=demuxer->audio;
1477 d_video=demuxer->video;
1478 d_dvdsub=demuxer->sub;
1480 // DUMP STREAMS:
1481 if((stream_dump_type)&&(stream_dump_type<4)){
1482 FILE *f;
1483 demux_stream_t *ds=NULL;
1484 current_module="dump";
1485 // select stream to dump
1486 switch(stream_dump_type){
1487 case 1: ds=d_audio;break;
1488 case 2: ds=d_video;break;
1489 case 3: ds=d_dvdsub;break;
1491 if(!ds){
1492 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1493 exit_player(MSGTR_Exit_error);
1495 // disable other streams:
1496 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1497 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1498 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1499 // let's dump it!
1500 f=fopen(stream_dump_name,"wb");
1501 if(!f){
1502 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1503 exit_player(MSGTR_Exit_error);
1505 while(!ds->eof){
1506 unsigned char* start;
1507 int in_size=ds_get_packet(ds,&start);
1508 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1509 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1510 if(in_size>0) fwrite(start,in_size,1,f);
1512 fclose(f);
1513 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1514 exit_player_with_rc(MSGTR_Exit_eof, 0);
1517 sh_audio=d_audio->sh;
1518 sh_video=d_video->sh;
1520 if(sh_video){
1522 current_module="video_read_properties";
1523 if(!video_read_properties(sh_video)) {
1524 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1525 sh_video=d_video->sh=NULL;
1526 } else {
1527 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1528 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1529 sh_video->fps,sh_video->frametime
1532 /* need to set fps here for output encoders to pick it up in their init */
1533 if(force_fps){
1534 sh_video->fps=force_fps;
1535 sh_video->frametime=1.0f/sh_video->fps;
1537 vo_fps = sh_video->fps;
1538 #ifdef HAVE_X11
1539 vo_mouse_timer_const=(int)sh_video->fps;
1540 #endif
1542 if(!sh_video->fps && !force_fps){
1543 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1544 sh_video=d_video->sh=NULL;
1550 fflush(stdout);
1552 if(!sh_video && !sh_audio){
1553 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1554 #ifdef HAS_DVBIN_SUPPORT
1555 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1557 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1558 if(priv->is_on)
1560 int dir;
1561 int v = last_dvb_step;
1562 if(v > 0)
1563 dir = DVB_CHANNEL_HIGHER;
1564 else
1565 dir = DVB_CHANNEL_LOWER;
1567 if(dvb_step_channel(priv, dir))
1569 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1570 cache_uninit(stream);
1571 goto goto_enable_cache;
1575 #endif
1576 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1579 /* display clip info */
1580 demux_info_print(demuxer);
1582 //================== Read SUBTITLES (DVD & TEXT) ==========================
1583 if(d_dvdsub->id >= 0 && vo_spudec==NULL && sh_video){
1585 if (spudec_ifo) {
1586 unsigned int palette[16], width, height;
1587 current_module="spudec_init_vobsub";
1588 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1589 vo_spudec=spudec_new_scaled(palette, width, height);
1592 #ifdef USE_DVDNAV
1593 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1594 current_module="spudec_init_dvdnav";
1595 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1596 sh_video->disp_w, sh_video->disp_h);
1598 #endif
1600 #ifdef USE_DVDREAD
1601 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1602 current_module="spudec_init_dvdread";
1603 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1604 sh_video->disp_w, sh_video->disp_h);
1606 #endif
1608 #ifdef HAVE_MATROSKA
1609 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1610 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1611 current_module = "spudec_init_matroska";
1612 vo_spudec = spudec_new_scaled(((mkv_sh_sub_t *)d_dvdsub->sh)->palette,
1613 ((mkv_sh_sub_t *)d_dvdsub->sh)->width,
1614 ((mkv_sh_sub_t *)d_dvdsub->sh)->height);
1616 #endif
1618 if (vo_spudec==NULL) {
1619 current_module="spudec_init_normal";
1620 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1621 spudec_set_font_factor(vo_spudec,font_factor);
1624 if (vo_spudec!=NULL)
1625 inited_flags|=INITED_SPUDEC;
1629 // Apply current settings for forced subs
1630 if (vo_spudec!=NULL)
1631 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1633 #ifdef USE_SUB
1634 if(sh_video) {
1635 // after reading video params we should load subtitles because
1636 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1637 // check .sub
1638 current_module="read_subtitles_file";
1639 if(sub_name){
1640 for (i = 0; sub_name[i] != NULL; ++i)
1641 add_subtitles (sub_name[i], sh_video->fps, 0);
1643 if(sub_auto) { // auto load sub file ...
1644 char **tmp = sub_filenames(get_path("sub/"), filename);
1645 char **tmp2 = tmp;
1646 while (*tmp2)
1647 add_subtitles (*tmp2++, sh_video->fps, 0);
1648 free(tmp);
1649 if (set_of_sub_size == 0)
1650 add_subtitles (get_path("default.sub"), sh_video->fps, 1);
1651 if (set_of_sub_size > 0)
1652 add_subtitles (NULL, sh_video->fps, 1);
1654 if (set_of_sub_size > 0) {
1655 //osd_show_sub_changed = sh_video->fps;
1656 subdata = set_of_subtitles[set_of_sub_pos=0];
1658 if(stream_dump_type==3) list_sub_file(subdata);
1659 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
1660 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
1661 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
1662 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
1663 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
1666 #endif
1668 //================== Init AUDIO (codec) ==========================
1669 if(sh_audio){
1670 // Go through the codec.conf and find the best codec...
1671 current_module="init_audio_codec";
1672 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1673 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1674 sh_audio=d_audio->sh=NULL; // failed to init :(
1675 } else
1676 inited_flags|=INITED_ACODEC;
1677 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1680 if(identify) {
1681 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
1682 if (sh_video) {
1683 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1684 if (sh_video->format >= 0x20202020)
1685 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
1686 else
1687 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
1688 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
1689 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
1690 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
1691 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
1692 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
1694 if (sh_audio) {
1695 if (sh_audio->codec)
1696 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
1697 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1698 if (sh_audio->format >= 0x20202020)
1699 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
1700 else
1701 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
1702 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
1703 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
1704 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
1706 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
1709 if(!sh_video) goto main; // audio-only
1711 //================== Init VIDEO (codec & libvo) ==========================
1712 if(!fixed_vo || !(inited_flags&INITED_VO)){
1713 current_module="preinit_libvo";
1715 vo_config_count=0;
1716 //if((video_out->preinit(vo_subdevice))!=0){
1717 if(!(video_out=init_best_video_out(video_driver_list))){
1718 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
1719 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1721 sh_video->video_out=video_out;
1722 inited_flags|=INITED_VO;
1725 current_module="init_video_filters";
1727 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
1728 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
1730 #ifdef HAVE_MENU
1731 if(use_menu) {
1732 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
1733 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
1734 if(!vf_menu) {
1735 mp_msg(MSGT_CPLAYER,MSGL_ERR,"Can't open libmenu video filter with root menu %s\n",menu_root);
1736 use_menu = 0;
1739 if(vf_menu)
1740 sh_video->vfilter=(void*)append_filters(vf_menu);
1741 else
1742 #endif
1743 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
1745 current_module="init_video_codec";
1747 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1748 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
1749 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1751 if(!sh_video->inited){
1752 if(!fixed_vo) uninit_player(INITED_VO);
1753 if(!sh_audio) goto goto_next_file;
1754 sh_video = d_video->sh = NULL;
1755 goto main; // exit_player(MSGTR_Exit_error);
1758 inited_flags|=INITED_VCODEC;
1760 if(auto_quality>0){
1761 // Auto quality option enabled
1762 output_quality=get_video_quality_max(sh_video);
1763 if(auto_quality>output_quality) auto_quality=output_quality;
1764 else output_quality=auto_quality;
1765 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d\n",output_quality);
1766 set_video_quality(sh_video,output_quality);
1769 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1771 current_module="init_vo";
1772 if (sh_video)
1774 if (vo_gamma_gamma != 1000)
1775 set_video_colors (sh_video, "gamma", vo_gamma_gamma);
1776 if (vo_gamma_brightness != 1000)
1777 set_video_colors(sh_video, "brightness", vo_gamma_brightness);
1778 if (vo_gamma_contrast != 1000)
1779 set_video_colors(sh_video, "contrast", vo_gamma_contrast);
1780 if (vo_gamma_saturation != 1000)
1781 set_video_colors(sh_video, "saturation", vo_gamma_saturation);
1782 if (vo_gamma_hue != 1000)
1783 set_video_colors(sh_video, "hue", vo_gamma_hue);
1786 if(vo_flags & 0x08 && vo_spudec)
1787 spudec_set_hw_spu(vo_spudec,video_out);
1789 #ifdef HAVE_FREETYPE
1790 force_load_font = 1;
1791 #endif
1793 //================== MAIN: ==========================
1794 main:
1795 current_module="main";
1797 // If there is no video OSD has to be disabled.
1798 // In case of playing a playtree we have to restore the
1799 // old OSD level after playing one or more audio-only files.
1800 if(!sh_video && osd_level >= 0) { // save OSD level only once
1801 osd_level_saved = osd_level;
1802 osd_level = 0;
1803 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
1804 osd_level = osd_level_saved;
1805 osd_level_saved = -1;
1808 fflush(stdout);
1810 #ifdef HAVE_NEW_GUI
1811 if ( use_gui )
1813 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
1814 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
1815 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
1816 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
1817 guiGetEvent( guiSetDemuxer,(char *)demuxer );
1819 #endif
1822 //int frame_corr_num=0; //
1823 //float v_frame=0; // Video
1824 float time_frame=0; // Timer
1825 //float num_frames=0; // number of frames played
1826 int grab_frames=0;
1827 char osd_text_buffer[64];
1828 char osd_show_text_buffer[64];
1829 int drop_frame=0; // current dropping status
1830 int dropped_frames=0; // how many frames dropped since last non-dropped frame
1831 int too_slow_frame_cnt=0;
1832 int too_fast_frame_cnt=0;
1833 // for auto-quality:
1834 float AV_delay=0; // average of A-V timestamp differences
1835 double vdecode_time;
1836 unsigned int lastframeout_ts=0;
1837 /*float time_frame_corr_avg=0;*/ /* unused */
1839 float next_frame_time=0;
1840 int frame_time_remaining=0; // flag
1841 int blit_frame=0;
1843 osd_text_buffer[0]=0;
1845 //================ SETUP AUDIO ==========================
1847 if(sh_audio){
1848 //const ao_info_t *info=audio_out->info;
1849 current_module="af_preinit";
1850 ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*playback_speed;
1851 ao_data.channels=audio_output_channels?audio_output_channels:sh_audio->channels;
1852 ao_data.format=audio_output_format?audio_output_format:sh_audio->sample_format;
1853 #if 1
1854 if(!preinit_audio_filters(sh_audio,
1855 // input:
1856 (int)(sh_audio->samplerate*playback_speed),
1857 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
1858 // output:
1859 &ao_data.samplerate, &ao_data.channels, &ao_data.format,
1860 audio_out_format_bits(ao_data.format)/8)){
1861 mp_msg(MSGT_CPLAYER,MSGL_ERR,"Error at audio filter chain pre-init!\n");
1862 } else {
1863 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AF_pre: %dHz %dch %s\n",
1864 ao_data.samplerate, ao_data.channels,
1865 audio_out_format_name(ao_data.format));
1867 #endif
1868 current_module="ao2_init";
1869 if(!(audio_out=init_best_audio_out(audio_driver_list,
1870 (ao_plugin_cfg.plugin_list!=NULL), // plugin flag
1871 force_srate?force_srate:ao_data.samplerate,
1872 audio_output_channels?audio_output_channels:ao_data.channels,
1873 audio_output_format?audio_output_format:ao_data.format,0))){
1874 // FAILED:
1875 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
1876 uninit_player(INITED_ACODEC); // close codec
1877 sh_audio=d_audio->sh=NULL; // -> nosound
1878 } else {
1879 // SUCCESS:
1880 inited_flags|=INITED_AO;
1881 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
1882 audio_out->info->short_name,
1883 ao_data.samplerate, ao_data.channels,
1884 audio_out_format_name(ao_data.format),
1885 audio_out_format_bits(ao_data.format)/8 );
1886 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_AODescription_AOAuthor,
1887 audio_out->info->name, audio_out->info->author);
1888 if(strlen(audio_out->info->comment) > 0)
1889 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_AOComment, audio_out->info->comment);
1890 // init audio filters:
1891 #if 1
1892 current_module="af_init";
1893 if(!init_audio_filters(sh_audio,
1894 (int)(sh_audio->samplerate*playback_speed),
1895 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
1896 ao_data.samplerate, ao_data.channels, ao_data.format,
1897 audio_out_format_bits(ao_data.format)/8, /* ao_data.bps, */
1898 ao_data.outburst*4, ao_data.buffersize)){
1899 mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format!\n");
1900 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1901 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1902 // sh_audio=d_audio->sh=NULL; // -> nosound
1904 #endif
1908 current_module="av_init";
1910 if(sh_video) sh_video->timer=0;
1911 if(sh_audio) sh_audio->delay=-audio_delay;
1913 if(!sh_audio){
1914 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
1915 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks\n",d_audio->packs);
1916 ds_free_packs(d_audio); // free buffered chunks
1917 d_audio->id=-2; // do not read audio chunks
1918 //uninit_player(INITED_AO); // close device
1920 if(!sh_video){
1921 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
1922 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks\n",d_video->packs);
1923 ds_free_packs(d_video);
1924 d_video->id=-2;
1925 //if(!fixed_vo) uninit_player(INITED_VO);
1928 if (!sh_video && !sh_audio)
1929 goto goto_next_file;
1931 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
1932 if(force_fps && sh_video){
1933 vo_fps = sh_video->fps=force_fps;
1934 sh_video->frametime=1.0f/sh_video->fps;
1935 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
1938 //==================== START PLAYING =======================
1940 if(loop_times>1) loop_times--; else
1941 if(loop_times==1) loop_times = -1;
1943 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
1945 InitTimer();
1947 #ifdef USE_DVDNAV
1948 if (stream->type==STREAMTYPE_DVDNAV) {
1949 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
1951 #endif
1953 total_time_usage_start=GetTimer();
1954 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
1955 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
1956 play_n_frames=play_n_frames_mf;
1958 if(play_n_frames==0){
1959 eof=PT_NEXT_ENTRY; goto goto_next_file;
1962 while(!eof){
1963 float aq_sleep_time=0;
1965 if(play_n_frames>=0){
1966 --play_n_frames;
1967 if(play_n_frames<0) eof = PT_NEXT_ENTRY;
1970 /*========================== PLAY AUDIO ============================*/
1972 while(sh_audio){
1973 unsigned int t;
1974 double tt;
1975 int playsize;
1977 current_module="play_audio";
1979 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
1980 playsize=audio_out->get_space();
1982 // handle audio-only case:
1983 if(!playsize && !sh_video) { // buffer is full, do not block here!!!
1984 usec_sleep(10000); // Wait a tick before retry
1985 continue;
1988 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
1990 // Fill buffer if needed:
1991 current_module="decode_audio"; // Enter AUDIO decoder module
1992 t=GetTimer();
1993 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
1994 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
1995 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
1996 if(ret<=0) break; // EOF?
1997 sh_audio->a_out_buffer_len+=ret;
1999 t=GetTimer()-t;
2000 tt = t*0.000001f; audio_time_usage+=tt;
2001 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
2003 // play audio:
2004 current_module="play_audio";
2005 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2007 if(playsize>0){
2008 sh_audio->a_out_buffer_len-=playsize;
2009 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2010 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2011 ao_data.bps : sh_audio->o_bps));
2014 break;
2015 } // while(sh_audio)
2017 if(!sh_video) {
2018 // handle audio-only case:
2019 if(!quiet) {
2021 // convert time to HH:MM:SS.F format
2023 long tenths = 10 * sh_audio->delay-audio_out->get_delay();
2024 int hh = (tenths / 36000) % 100;
2025 int mm = (tenths / 600) % 60;
2026 int ss = (tenths / 10) % 60;
2027 int f1 = tenths % 10;
2028 char hhmmssf[16]; // only really need 11, but just in case...
2029 sprintf( hhmmssf, "%2d:%2d:%2d.%1d", hh, mm, ss, f1);
2030 if (0 == hh) {
2031 hhmmssf[1] = ' ';
2032 hhmmssf[2] = ' ';
2034 // uncomment the next three lines to show leading zero ten-hours
2035 // else if (' ' == hhmmssf[0]) {
2036 // hhmmssf[0] = '0';
2037 // }
2038 if ((0 == hh) && (0 == mm)) {
2039 hhmmssf[4] = ' ';
2040 hhmmssf[5] = ' ';
2042 else if ((' ' == hhmmssf[3]) && (' ' != hhmmssf[2])) {
2043 hhmmssf[3] = '0';
2045 if ((' ' == hhmmssf[6]) && (' ' != hhmmssf[5])) {
2046 hhmmssf[6] = '0';
2048 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: %s %4.1f%% %d%% \r"
2049 ,hhmmssf
2050 ,(sh_audio->delay>0.5)?100.0*audio_time_usage/(double)sh_audio->delay:0
2051 ,cache_fill_status
2054 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2056 } else {
2058 /*========================== PLAY VIDEO ============================*/
2060 float frame_time=next_frame_time;
2062 vo_pts=sh_video->timer*90000.0;
2063 vo_fps=sh_video->fps;
2065 if(!frame_time_remaining){
2066 //-------------------- Decode a frame: -----------------------
2067 vdecode_time=video_time_usage;
2068 while(1)
2069 { unsigned char* start=NULL;
2070 int in_size;
2071 // get it!
2072 current_module="video_read_frame";
2073 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2074 if(in_size<0){ eof=1; break; }
2075 if(in_size>max_framesize) max_framesize=in_size; // stats
2076 sh_video->timer+=frame_time;
2077 if(sh_audio) sh_audio->delay-=frame_time;
2078 time_frame+=frame_time; // for nosound
2079 // check for frame-drop:
2080 current_module="check_framedrop";
2081 if(sh_audio && !d_audio->eof){
2082 float delay=playback_speed*audio_out->get_delay();
2083 float d=delay-sh_audio->delay;
2084 // we should avoid dropping to many frames in sequence unless we
2085 // are too late. and we allow 100ms A-V delay here:
2086 if(d<-dropped_frames*frame_time-0.100){
2087 drop_frame=frame_dropping;
2088 ++drop_frame_cnt;
2089 ++dropped_frames;
2090 } else {
2091 drop_frame=dropped_frames=0;
2093 ++total_frame_cnt;
2095 // decode:
2096 current_module="decode_video";
2097 // printf("Decode! %p %d \n",start,in_size);
2098 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2099 break;
2101 vdecode_time=video_time_usage-vdecode_time;
2102 //------------------------ frame decoded. --------------------
2104 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2106 if(sh_video->vf_inited<0){
2107 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2108 eof=1; goto goto_next_file;
2113 // ==========================================================================
2115 // current_module="draw_osd";
2116 // if(vo_config_count) video_out->draw_osd();
2118 #ifdef HAVE_NEW_GUI
2119 if(use_gui) guiEventHandling();
2120 #endif
2122 current_module="calc_sleep_time";
2124 #if 0
2125 { // debug frame dropping code
2126 float delay=audio_out->get_delay();
2127 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2128 sh_video->timer,sh_audio->timer-delay,
2129 sh_video->timer-(sh_audio->timer-delay),
2130 delay,drop_frame);
2132 #endif
2134 if(drop_frame && !frame_time_remaining && !autosync){
2136 * Note: time_frame should not be forced to 0 in autosync mode.
2137 * It is used as a cumulative counter to predict and correct the
2138 * delay measurements from the audio driver. time_frame is already
2139 * < 0, so the "time to sleep" code does not actually sleep. Also,
2140 * blit_frame is already 0 because drop_frame was true when
2141 * decode_video was called (which causes it to set blit_frame to 0.)
2142 * When autosync==0, the default behavior is still completely unchanged.
2145 time_frame=0; // don't sleep!
2146 blit_frame=0; // don't display!
2148 } else {
2150 // It's time to sleep...
2152 frame_time_remaining=0;
2153 time_frame-=GetRelativeTime(); // reset timer
2155 if(sh_audio && !d_audio->eof){
2156 float delay=playback_speed*audio_out->get_delay();
2157 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2159 if (autosync){
2161 * Adjust this raw delay value by calculating the expected
2162 * delay for this frame and generating a new value which is
2163 * weighted between the two. The higher autosync is, the
2164 * closer to the delay value gets to that which "-nosound"
2165 * would have used, and the longer it will take for A/V
2166 * sync to settle at the right value (but it eventually will.)
2167 * This settling time is very short for values below 100.
2169 float predicted = sh_audio->delay+time_frame;
2170 float difference = delay - predicted;
2171 delay = predicted + difference / (float)autosync;
2174 time_frame=delay-sh_audio->delay;
2176 // delay = amount of audio buffered in soundcard/driver
2177 if(delay>0.25) delay=0.25; else
2178 if(delay<0.10) delay=0.10;
2179 if(time_frame>delay*0.6){
2180 // sleep time too big - may cause audio drops (buffer underrun)
2181 frame_time_remaining=1;
2182 time_frame=delay*0.5;
2185 } else {
2187 // NOSOUND:
2188 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2189 time_frame=0;
2193 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2195 aq_sleep_time+=time_frame;
2197 } // !drop_frame
2199 //============================== SLEEP: ===================================
2201 time_frame/=playback_speed;
2203 // flag 256 means: libvo driver does its timing (dvb card)
2204 if(time_frame>0.001 && !(vo_flags&256)){
2206 #ifdef HAVE_RTC
2207 if(rtc_fd>=0){
2208 // -------- RTC -----------
2209 current_module="sleep_rtc";
2210 while (time_frame > 0.000) {
2211 unsigned long rtc_ts;
2212 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2213 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Linux RTC read error: %s\n", strerror(errno));
2214 time_frame-=GetRelativeTime();
2216 } else
2217 #endif
2219 // -------- USLEEP + SOFTSLEEP -----------
2220 float min=softsleep?0.021:0.005;
2221 current_module="sleep_usleep";
2222 while(time_frame>min){
2223 if(time_frame<=0.020)
2224 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2225 else
2226 usec_sleep(1000000*(time_frame-0.020));
2227 time_frame-=GetRelativeTime();
2229 if(softsleep){
2230 current_module="sleep_soft";
2231 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, "Warning! Softsleep underflow!\n");
2232 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2238 //if(!frame_time_remaining){ // should we display the frame now?
2240 //====================== FLIP PAGE (VIDEO BLT): =========================
2242 current_module="vo_check_events";
2243 if(vo_config_count) video_out->check_events();
2245 current_module="flip_page";
2246 if (!frame_time_remaining) {
2247 if(blit_frame){
2248 unsigned int t2=GetTimer();
2249 double tt;
2250 float j;
2251 #define FRAME_LAG_WARN 0.2
2252 j = ((float)t2 - lastframeout_ts) / 1000000;
2253 lastframeout_ts = GetTimer();
2254 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2255 too_fast_frame_cnt++;
2256 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2257 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2258 too_slow_frame_cnt++;
2259 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2261 if(vo_config_count) video_out->flip_page();
2262 // usec_sleep(50000); // test only!
2263 t2=GetTimer()-t2;
2264 tt = t2*0.000001f;
2265 vout_time_usage+=tt;
2266 } else {
2268 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2269 otherwise A/V desync will occur. -- Alvieboy
2271 if (vo_config_count)
2272 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2275 //====================== A-V TIMESTAMP CORRECTION: =========================
2277 current_module="av_sync";
2279 if(sh_audio){
2280 float a_pts=0;
2281 float v_pts=0;
2283 // unplayed bytes in our and soundcard/dma buffer:
2284 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2286 if (autosync){
2288 * If autosync is enabled, the value for delay must be calculated
2289 * a bit differently. It is set only to the difference between
2290 * the audio and video timers. Any attempt to include the real
2291 * or corrected delay causes the pts_correction code below to
2292 * try to correct for the changes in delay which autosync is
2293 * trying to measure. This keeps the two from competing, but still
2294 * allows the code to correct for PTS drift *only*. (Using a delay
2295 * value here, even a "corrected" one, would be incompatible with
2296 * autosync mode.)
2298 delay=sh_audio->delay;
2299 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2302 #if 0
2303 if(pts_from_bps){
2304 // PTS = sample_no / samplerate
2305 unsigned int samples=
2306 // (sh_audio->audio.dwSampleSize)?
2307 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2308 ds_tell_block(d_audio); // <- used for VBR audio
2309 samples+=sh_audio->audio.dwStart; // offset
2310 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2311 delay_corrected=1;
2312 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2313 } else
2314 #endif
2316 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2317 a_pts=d_audio->pts;
2318 if(!delay_corrected) if(a_pts) delay_corrected=1;
2319 #if 0
2320 printf("\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2321 a_pts,
2322 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2323 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2324 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2325 #endif
2326 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2328 v_pts=sh_video ? sh_video->pts : d_video->pts;
2330 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);
2332 if(delay_corrected){
2333 static int drop_message=0;
2334 float x;
2335 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2336 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2337 ++drop_message;
2338 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2340 x=AV_delay*0.1f;
2341 if(x<-max_pts_correction) x=-max_pts_correction; else
2342 if(x> max_pts_correction) x= max_pts_correction;
2343 if(default_max_pts_correction>=0)
2344 max_pts_correction=default_max_pts_correction;
2345 else
2346 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2347 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2348 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%%\r",
2349 a_pts-audio_delay-delay,v_pts,AV_delay,c_total,
2350 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded,
2351 (sh_video->timer>0.5)?(int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer):0,
2352 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer):0,
2353 (sh_video->timer>0.5)?(100.0*audio_time_usage*playback_speed/(double)sh_video->timer):0
2354 ,drop_frame_cnt
2355 ,output_quality
2356 ,cache_fill_status
2358 fflush(stdout);
2361 } else {
2362 // No audio:
2364 if(!quiet)
2365 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video->pts,
2366 (int)sh_video->num_frames,
2367 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
2368 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
2369 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
2370 ,drop_frame_cnt
2371 ,output_quality
2372 ,cache_fill_status
2375 fflush(stdout);
2379 //============================ Auto QUALITY ============================
2381 /*Output quality adjustments:*/
2382 if(auto_quality>0){
2383 current_module="autoq";
2384 // float total=0.000001f * (GetTimer()-aq_total_time);
2385 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2386 if(output_quality<auto_quality && aq_sleep_time>0)
2387 ++output_quality;
2388 else
2389 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2390 if(output_quality>1 && aq_sleep_time<0)
2391 --output_quality;
2392 else
2393 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2394 output_quality=0;
2395 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2396 set_video_quality(sh_video,output_quality);
2399 } // end if(sh_video)
2401 //============================ Handle PAUSE ===============================
2403 current_module="pause";
2405 #ifdef USE_OSD
2406 if(osd_visible){
2407 if (!--osd_visible){
2408 vo_osd_progbar_type=-1; // disable
2409 vo_osd_changed(OSDTYPE_PROGBAR);
2410 if (osd_function != OSD_PAUSE)
2411 osd_function = OSD_PLAY;
2414 #endif
2416 if(osd_function==OSD_PAUSE){
2417 mp_cmd_t* cmd;
2418 if(!quiet) {
2419 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2420 fflush(stdout);
2422 #ifdef HAVE_NEW_GUI
2423 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2424 #endif
2425 if (video_out && sh_video && vo_config_count)
2426 video_out->control(VOCTRL_PAUSE, NULL);
2428 if (audio_out && sh_audio)
2429 audio_out->pause(); // pause audio, keep data if possible
2431 while( (cmd = mp_input_get_cmd(20,1)) == NULL) {
2432 if(sh_video && video_out && vo_config_count) video_out->check_events();
2433 #ifdef HAVE_NEW_GUI
2434 if(use_gui){
2435 guiEventHandling();
2436 guiGetEvent( guiReDraw,NULL );
2437 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2439 #endif
2440 #ifdef HAVE_MENU
2441 if(vf_menu)
2442 vf_menu_pause_update(vf_menu);
2443 #endif
2444 usec_sleep(20000);
2446 mp_cmd_free(cmd);
2447 osd_function=OSD_PLAY;
2448 if (audio_out && sh_audio)
2449 audio_out->resume(); // resume audio
2450 if (video_out && sh_video && vo_config_count)
2451 video_out->control(VOCTRL_RESUME, NULL); // resume video
2452 (void)GetRelativeTime(); // keep TF around FT in next cycle
2453 #ifdef HAVE_NEW_GUI
2454 if (use_gui)
2456 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2457 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2459 #endif
2462 // handle -sstep
2463 if(step_sec>0) {
2464 osd_function=OSD_FFW;
2465 rel_seek_secs+=step_sec;
2468 #ifdef USE_DVDNAV
2469 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2470 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2471 #endif
2473 //================= EDL =========================================
2475 #ifdef USE_EDL
2476 if( next_edl_record->next ) { // Are we (still?) doing EDL?
2477 if( sh_video->pts >= next_edl_record->start_sec ) {
2478 if( next_edl_record->action == EDL_SKIP ) {
2479 osd_function = OSD_FFW;
2480 abs_seek_pos = 0;
2481 rel_seek_secs = next_edl_record->length_sec;
2482 #ifdef DEBUG_EDL
2483 printf( "\nEDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec );
2484 #endif
2485 edl_decision = 1;
2486 next_edl_record = next_edl_record->next;
2487 } else if( next_edl_record->action == EDL_MUTE ) {
2488 mixer_mute();
2489 #ifdef DEBUG_EDL
2490 printf( "\nEDL_MUTE: [%f]\n", next_edl_record->start_sec );
2491 #endif
2492 edl_decision = 1;
2493 next_edl_record = next_edl_record->next;
2497 #endif
2499 //================= Keyboard events, SEEKing ====================
2501 current_module="key_events";
2504 mp_cmd_t* cmd;
2505 int brk_cmd = 0;
2506 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0)) != NULL) {
2507 switch(cmd->id) {
2508 case MP_CMD_SEEK : {
2509 int v,abs;
2510 osd_show_percentage = 25;
2511 v = cmd->args[0].v.i;
2512 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2513 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2514 abs_seek_pos = 1;
2515 if(sh_video)
2516 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2517 rel_seek_secs = v;
2519 else if(abs) { /* Absolute seek by percentage */
2520 abs_seek_pos = 3;
2521 if(sh_video)
2522 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2523 rel_seek_secs = v/100.0;
2525 else {
2526 rel_seek_secs+= v;
2527 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2529 brk_cmd = 1;
2530 } break;
2531 #ifdef USE_EDL
2532 case MP_CMD_EDL_MARK:
2533 if( edl_fd ) {
2534 float v = sh_video->pts;
2535 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2537 break;
2538 #endif
2539 case MP_CMD_AUDIO_DELAY : {
2540 float v = cmd->args[0].v.f;
2541 audio_delay += v;
2542 osd_show_av_delay = 9;
2543 if(sh_audio) sh_audio->delay+= v;
2544 } break;
2545 case MP_CMD_PAUSE : {
2546 osd_function=OSD_PAUSE;
2547 brk_cmd = 1;
2548 } break;
2549 case MP_CMD_QUIT : {
2550 exit_player_with_rc(MSGTR_Exit_quit, 0);
2552 case MP_CMD_GRAB_FRAMES : {
2553 grab_frames=2;
2554 } break;
2555 case MP_CMD_PLAY_TREE_STEP : {
2556 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2557 int force = cmd->args[1].v.i;
2559 #ifdef HAVE_NEW_GUI
2560 if (use_gui) {
2561 int i=0;
2562 if (n>0)
2563 for (i=0;i<n;i++)
2564 mplNext();
2565 else
2566 for (i=0;i<-1*n;i++)
2567 mplPrev();
2568 } else
2569 #endif
2571 if(!force && playtree_iter) {
2572 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2574 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2575 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2576 play_tree_iter_free(i);
2577 } else
2578 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2579 if(eof)
2580 play_tree_step = n;
2581 brk_cmd = 1;
2583 } break;
2584 case MP_CMD_PLAY_TREE_UP_STEP : {
2585 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2586 int force = cmd->args[1].v.i;
2588 if(!force && playtree_iter) {
2589 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2590 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2591 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2592 play_tree_iter_free(i);
2593 } else
2594 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2595 brk_cmd = 1;
2596 } break;
2597 case MP_CMD_PLAY_ALT_SRC_STEP : {
2598 if(playtree_iter && playtree_iter->num_files > 1) {
2599 int v = cmd->args[0].v.i;
2600 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2601 eof = PT_NEXT_SRC;
2602 else if(v < 0 && playtree_iter->file > 1)
2603 eof = PT_PREV_SRC;
2605 brk_cmd = 1;
2606 } break;
2607 case MP_CMD_SUB_DELAY : {
2608 #ifdef USE_SUB
2609 if (sh_video) {
2610 int abs= cmd->args[1].v.i;
2611 float v = cmd->args[0].v.f;
2612 if(abs)
2613 sub_delay = v;
2614 else
2615 sub_delay += v;
2616 osd_show_sub_delay = 9; // show the subdelay in OSD
2618 #endif
2619 } break;
2620 case MP_CMD_SUB_STEP : {
2621 #ifdef USE_SUB
2622 if (sh_video) {
2623 int movement = cmd->args[0].v.i;
2624 step_sub(subdata, sh_video->pts, movement);
2625 osd_show_sub_delay = 9; // show the subdelay in OSD
2627 #endif
2628 } break;
2629 case MP_CMD_OSD : {
2630 #ifdef USE_OSD
2631 if(sh_video) {
2632 int v = cmd->args[0].v.i;
2633 if(v < 0)
2634 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2635 else
2636 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2638 #endif
2639 } break;
2640 case MP_CMD_OSD_SHOW_TEXT : {
2641 #ifdef USE_OSD
2642 if(osd_level && sh_video){
2643 osd_show_text=sh_video->fps; // 1 sec
2644 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2646 #endif
2647 } break;
2648 case MP_CMD_VOLUME : {
2649 int v = cmd->args[0].v.i;
2651 // start change for absolute volume value
2652 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2654 if( abs )
2656 mixer_setvolume( (float)v, (float)v );
2657 } else {
2658 if(v > 0)
2659 mixer_incvolume();
2660 else
2661 mixer_decvolume();
2664 #ifdef USE_OSD
2665 if(osd_level && sh_video){
2666 osd_visible=sh_video->fps; // 1 sec
2667 vo_osd_progbar_type=OSD_VOLUME;
2668 vo_osd_progbar_value=(mixer_getbothvolume()*256.0)/100.0;
2669 vo_osd_changed(OSDTYPE_PROGBAR);
2671 #endif
2672 } break;
2673 case MP_CMD_MUTE:
2674 mixer_mute();
2675 break;
2676 case MP_CMD_LOADFILE : {
2677 play_tree_t* e = play_tree_new();
2678 play_tree_add_file(e,cmd->args[0].v.s);
2680 // Go back to the start point
2681 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2682 /* NOP */;
2683 play_tree_free_list(playtree->child,1);
2684 play_tree_set_child(playtree,e);
2685 play_tree_iter_step(playtree_iter,0,0);
2686 eof = PT_NEXT_SRC;
2687 brk_cmd = 1;
2688 } break;
2689 case MP_CMD_LOADLIST : {
2690 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
2691 if(!e)
2692 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
2693 else {
2694 // Go back to the start point
2695 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2696 /* NOP */;
2697 play_tree_free_list(playtree->child,1);
2698 play_tree_set_child(playtree,e);
2699 play_tree_iter_step(playtree_iter,0,0);
2700 eof = PT_NEXT_SRC;
2702 brk_cmd = 1;
2703 } break;
2704 case MP_CMD_GAMMA : {
2705 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2707 if (!sh_video)
2708 break;
2710 if (vo_gamma_gamma == 1000)
2712 vo_gamma_gamma = 0;
2713 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
2716 if (abs)
2717 vo_gamma_gamma = v;
2718 else
2719 vo_gamma_gamma += v;
2721 if (vo_gamma_gamma > 100)
2722 vo_gamma_gamma = 100;
2723 else if (vo_gamma_gamma < -100)
2724 vo_gamma_gamma = -100;
2725 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
2726 #ifdef USE_OSD
2727 if(osd_level){
2728 osd_visible=sh_video->fps; // 1 sec
2729 vo_osd_progbar_type=OSD_BRIGHTNESS;
2730 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
2731 vo_osd_changed(OSDTYPE_PROGBAR);
2733 #endif // USE_OSD
2734 } break;
2735 case MP_CMD_BRIGHTNESS : {
2736 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2738 if (!sh_video)
2739 break;
2741 if (vo_gamma_brightness == 1000)
2743 vo_gamma_brightness = 0;
2744 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
2747 if (abs)
2748 vo_gamma_brightness = v;
2749 else
2750 vo_gamma_brightness += v;
2752 if (vo_gamma_brightness > 100)
2753 vo_gamma_brightness = 100;
2754 else if (vo_gamma_brightness < -100)
2755 vo_gamma_brightness = -100;
2756 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
2757 #ifdef USE_OSD
2758 if(osd_level){
2759 osd_visible=sh_video->fps; // 1 sec
2760 vo_osd_progbar_type=OSD_BRIGHTNESS;
2761 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
2762 vo_osd_changed(OSDTYPE_PROGBAR);
2764 #endif // USE_OSD
2766 } break;
2767 case MP_CMD_CONTRAST : {
2768 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2770 if (!sh_video)
2771 break;
2773 if (vo_gamma_contrast == 1000)
2775 vo_gamma_contrast = 0;
2776 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
2779 if (abs)
2780 vo_gamma_contrast = v;
2781 else
2782 vo_gamma_contrast += v;
2784 if (vo_gamma_contrast > 100)
2785 vo_gamma_contrast = 100;
2786 else if (vo_gamma_contrast < -100)
2787 vo_gamma_contrast = -100;
2788 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
2789 #ifdef USE_OSD
2790 if(osd_level){
2791 osd_visible=sh_video->fps; // 1 sec
2792 vo_osd_progbar_type=OSD_CONTRAST;
2793 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
2794 vo_osd_changed(OSDTYPE_PROGBAR);
2796 #endif // USE_OSD
2798 } break;
2799 case MP_CMD_SATURATION : {
2800 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2802 if (!sh_video)
2803 break;
2805 if (vo_gamma_saturation == 1000)
2807 vo_gamma_saturation = 0;
2808 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
2811 if (abs)
2812 vo_gamma_saturation = v;
2813 else
2814 vo_gamma_saturation += v;
2816 if (vo_gamma_saturation > 100)
2817 vo_gamma_saturation = 100;
2818 else if (vo_gamma_saturation < -100)
2819 vo_gamma_saturation = -100;
2820 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
2821 #ifdef USE_OSD
2822 if(osd_level){
2823 osd_visible=sh_video->fps; // 1 sec
2824 vo_osd_progbar_type=OSD_SATURATION;
2825 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
2826 vo_osd_changed(OSDTYPE_PROGBAR);
2828 #endif // USE_OSD
2830 } break;
2831 case MP_CMD_HUE : {
2832 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2834 if (!sh_video)
2835 break;
2837 if (vo_gamma_hue == 1000)
2839 vo_gamma_hue = 0;
2840 get_video_colors(sh_video, "hue", &vo_gamma_hue);
2843 if (abs)
2844 vo_gamma_hue = v;
2845 else
2846 vo_gamma_hue += v;
2848 if (vo_gamma_hue > 100)
2849 vo_gamma_hue = 100;
2850 else if (vo_gamma_hue < -100)
2851 vo_gamma_hue = -100;
2852 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
2853 #ifdef USE_OSD
2854 if(osd_level){
2855 osd_visible=sh_video->fps; // 1 sec
2856 vo_osd_progbar_type=OSD_HUE;
2857 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
2858 vo_osd_changed(OSDTYPE_PROGBAR);
2860 #endif // USE_OSD
2862 } break;
2863 case MP_CMD_FRAMEDROPPING : {
2864 int v = cmd->args[0].v.i;
2865 if(v < 0)
2866 frame_dropping = (frame_dropping+1)%3;
2867 else
2868 frame_dropping = v > 2 ? 2 : v;
2869 } break;
2870 #ifdef USE_TV
2871 case MP_CMD_TV_SET_FREQ : {
2872 if (file_format == DEMUXER_TYPE_TV)
2873 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
2874 } break;
2875 case MP_CMD_TV_SET_NORM : {
2876 if (file_format == DEMUXER_TYPE_TV)
2877 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
2878 } break;
2879 case MP_CMD_TV_SET_BRIGHTNESS : {
2880 if (file_format == DEMUXER_TYPE_TV)
2881 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
2882 } break;
2883 case MP_CMD_TV_SET_HUE : {
2884 if (file_format == DEMUXER_TYPE_TV)
2885 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
2886 } break;
2887 case MP_CMD_TV_SET_SATURATION : {
2888 if (file_format == DEMUXER_TYPE_TV)
2889 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
2890 } break;
2891 case MP_CMD_TV_SET_CONTRAST : {
2892 if (file_format == DEMUXER_TYPE_TV)
2893 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
2894 } break;
2895 case MP_CMD_TV_STEP_CHANNEL : {
2896 if (file_format == DEMUXER_TYPE_TV) {
2897 int v = cmd->args[0].v.i;
2898 if(v > 0){
2899 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
2900 #ifdef USE_OSD
2901 if (tv_channel_list) {
2902 osd_show_tv_channel = sh_video->fps;
2903 vo_osd_changed(OSDTYPE_SUBTITLE);
2905 #endif
2906 } else {
2907 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
2908 #ifdef USE_OSD
2909 if (tv_channel_list) {
2910 osd_show_tv_channel = sh_video->fps;
2911 vo_osd_changed(OSDTYPE_SUBTITLE);
2913 #endif
2917 #ifdef HAS_DVBIN_SUPPORT
2918 if((stream->type == STREAMTYPE_DVB) && stream->priv)
2920 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
2921 if(priv->is_on)
2923 int dir;
2924 int v = cmd->args[0].v.i;
2926 last_dvb_step = v;
2927 if(v > 0)
2928 dir = DVB_CHANNEL_HIGHER;
2929 else
2930 dir = DVB_CHANNEL_LOWER;
2933 if(dvb_step_channel(priv, dir))
2935 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
2936 cache_uninit(stream);
2937 goto goto_enable_cache;
2941 #endif
2942 break;
2943 case MP_CMD_TV_SET_CHANNEL : {
2944 if (file_format == DEMUXER_TYPE_TV) {
2945 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
2946 #ifdef USE_OSD
2947 if (tv_channel_list) {
2948 osd_show_tv_channel = sh_video->fps;
2949 vo_osd_changed(OSDTYPE_SUBTITLE);
2951 #endif
2953 } break;
2954 #ifdef HAS_DVBIN_SUPPORT
2955 case MP_CMD_DVB_SET_CHANNEL:
2957 if((stream->type == STREAMTYPE_DVB) && stream->priv)
2959 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
2960 if(priv->is_on)
2962 if(priv->list->current <= cmd->args[0].v.i)
2963 last_dvb_step = 1;
2964 else
2965 last_dvb_step = -1;
2967 if(dvb_set_channel(priv, cmd->args[0].v.i))
2969 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
2970 cache_uninit(stream);
2971 goto goto_enable_cache;
2976 #endif
2977 case MP_CMD_TV_LAST_CHANNEL : {
2978 if (file_format == DEMUXER_TYPE_TV) {
2979 tv_last_channel((tvi_handle_t*)(demuxer->priv));
2980 #ifdef USE_OSD
2981 if (tv_channel_list) {
2982 osd_show_tv_channel = sh_video->fps;
2983 vo_osd_changed(OSDTYPE_SUBTITLE);
2985 #endif
2987 } break;
2988 case MP_CMD_TV_STEP_NORM : {
2989 if (file_format == DEMUXER_TYPE_TV)
2990 tv_step_norm((tvi_handle_t*)(demuxer->priv));
2991 } break;
2992 case MP_CMD_TV_STEP_CHANNEL_LIST : {
2993 if (file_format == DEMUXER_TYPE_TV)
2994 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
2995 } break;
2996 #endif
2997 case MP_CMD_VO_FULLSCREEN:
2999 #ifdef HAVE_NEW_GUI
3000 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3001 else
3002 #endif
3003 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3004 } break;
3005 case MP_CMD_VO_ONTOP:
3007 if(video_out && vo_config_count) {
3008 video_out->control(VOCTRL_ONTOP, 0);
3009 #ifdef USE_OSD
3010 osd_show_ontop=10;
3011 vo_osd_changed(OSDTYPE_SUBTITLE);
3012 #endif
3015 } break;
3016 case MP_CMD_PANSCAN : {
3017 if ( !video_out ) break;
3018 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3020 int abs= cmd->args[1].v.i;
3021 float v = cmd->args[0].v.f;
3022 float res;
3023 if(abs) res = v;
3024 else res = vo_panscan+v;
3025 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3026 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3027 #ifdef USE_OSD
3028 if(osd_level && sh_video){
3029 osd_visible=sh_video->fps; // 1 sec
3030 vo_osd_progbar_type=OSD_PANSCAN;
3031 vo_osd_progbar_value=vo_panscan*256;
3032 vo_osd_changed(OSDTYPE_PROGBAR);
3033 #ifdef HAVE_FREETYPE
3034 if (subtitle_autoscale == 2 || subtitle_autoscale == 3)
3035 // force scaling font to movie width or diagonal
3036 force_load_font = 1;
3037 #endif
3039 #endif
3041 } break;
3042 case MP_CMD_SUB_POS:
3044 #ifdef USE_SUB
3045 if (sh_video) {
3046 int v;
3047 v = cmd->args[0].v.i;
3049 sub_pos+=v;
3050 if(sub_pos >100) sub_pos=100;
3051 if(sub_pos <0) sub_pos=0;
3052 vo_osd_changed(OSDTYPE_SUBTITLE);
3053 osd_show_sub_pos = 9;
3055 #endif
3056 } break;
3057 case MP_CMD_SUB_ALIGNMENT:
3059 #ifdef USE_SUB
3060 if (sh_video) {
3061 if (cmd->nargs >= 1)
3062 sub_alignment = cmd->args[0].v.i;
3063 else
3064 sub_alignment = (sub_alignment+1) % 3;
3065 osd_show_sub_alignment = 9;
3066 vo_osd_changed(OSDTYPE_SUBTITLE);
3068 #endif
3069 } break;
3070 case MP_CMD_SUB_VISIBILITY:
3072 #ifdef USE_SUB
3073 if (sh_video) {
3074 sub_visibility=1-sub_visibility;
3075 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3076 vo_osd_changed(OSDTYPE_SUBTITLE);
3078 #endif
3079 } break;
3080 case MP_CMD_GET_SUB_VISIBILITY:
3082 #ifdef USE_SUB
3083 if (sh_video) {
3084 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_SUB_VISIBILITY=%ld\n", sub_visibility);
3086 #endif
3087 } break;
3088 case MP_CMD_VOBSUB_LANG:
3089 if (vo_vobsub)
3091 int new_id = vobsub_id + 1;
3092 if (vobsub_id < 0)
3093 new_id = 0;
3094 if ((unsigned int) new_id >= vobsub_get_indexes_count(vo_vobsub))
3095 new_id = -1;
3096 if(new_id != vobsub_id)
3097 osd_show_vobsub_changed = 9;
3098 vobsub_id = new_id;
3100 #ifdef USE_SUB
3101 else if (set_of_sub_size > 0){ //change subtitle file
3102 set_of_sub_pos = (set_of_sub_pos + 1) % set_of_sub_size;
3103 subdata = set_of_subtitles[set_of_sub_pos];
3104 osd_show_sub_changed = sh_video->fps;
3105 vo_sub = NULL;
3106 vo_osd_changed(OSDTYPE_SUBTITLE);
3108 #endif
3109 break;
3110 case MP_CMD_SUB_FORCED_ONLY:
3111 if (vo_spudec) {
3112 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3113 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3115 break;
3116 case MP_CMD_SCREENSHOT :
3117 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3118 break;
3119 case MP_CMD_VF_CHANGE_RECTANGLE:
3120 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3121 break;
3123 case MP_CMD_GET_TIME_LENGTH : {
3124 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
3125 } break;
3127 case MP_CMD_GET_VO_FULLSCREEN : {
3128 if(video_out && vo_config_count)
3129 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_VO_FULLSCREEN=%ld\n", vo_fs);
3130 } break;
3132 case MP_CMD_GET_PERCENT_POS : {
3133 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer));
3134 } break;
3136 #ifdef USE_DVDNAV
3137 case MP_CMD_DVDNAV_EVENT: {
3138 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3139 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3141 /* ignore these events if we're not in dvd_nav mode */
3142 if (stream->type != STREAMTYPE_DVDNAV) break;
3144 if (!dvdnav_event) {
3145 printf("DVDNAV Event NULL?!\n");
3146 break;
3149 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3151 switch (dvdnav_event->event) {
3152 case DVDNAV_BLOCK_OK: {
3153 /* be silent about this one */
3154 break;
3156 case DVDNAV_HIGHLIGHT: {
3157 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3158 if (!hevent) {
3159 printf("DVDNAV Event: Highlight event broken\n");
3160 break;
3163 if (hevent->display && hevent->buttonN>0)
3165 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3166 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3167 hevent->buttonN,
3168 hevent->sx,hevent->sy,
3169 hevent->ex,hevent->ey,
3170 hevent->pts, d_video->pts);
3171 printf("DVDNAV Event: %s\n",dvd_nav_text);
3172 //osd_show_dvd_nav_delay = 60;
3174 osd_show_dvd_nav_highlight=1;
3175 osd_show_dvd_nav_sx=hevent->sx;
3176 osd_show_dvd_nav_ex=hevent->ex;
3177 osd_show_dvd_nav_sy=hevent->sy;
3178 osd_show_dvd_nav_ey=hevent->ey;
3180 else {
3181 osd_show_dvd_nav_highlight=0;
3182 printf("DVDNAV Event: Highlight Hide\n");
3184 break;
3186 case DVDNAV_STILL_FRAME: {
3187 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3189 printf( "######################################## DVDNAV Event: Still Frame: %d sec(s)\n", still_event->length );
3190 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3191 usec_sleep(1000); /* 1ms */
3193 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3194 break;
3196 case DVDNAV_STOP: {
3197 printf( "DVDNAV Event: Nav Stop\n" );
3198 break;
3200 case DVDNAV_NOP: {
3201 printf("DVDNAV Event: Nav NOP\n");
3202 break;
3204 case DVDNAV_SPU_STREAM_CHANGE: {
3205 #if DVDNAVVERSION > 012
3206 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3208 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d/%d/%d logical: %d\n",
3209 stream_change->physical_wide,
3210 stream_change->physical_letterbox,
3211 stream_change->physical_pan_scan,
3212 stream_change->logical);
3214 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3215 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3216 d_dvdsub->id,stream_change->physical_wide);
3217 // FIXME: need a better way to change SPU id
3218 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3219 if (vo_spudec) spudec_reset(vo_spudec);
3221 #else
3222 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3224 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n",
3225 stream_change->physical,
3226 stream_change->logical);
3228 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3229 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3230 d_dvdsub->id,stream_change->physical);
3231 // FIXME: need a better way to change SPU id
3232 d_dvdsub->id=dvdsub_id=stream_change->physical;
3233 if (vo_spudec) spudec_reset(vo_spudec);
3235 #endif
3236 break;
3238 case DVDNAV_AUDIO_STREAM_CHANGE: {
3239 int aid_temp;
3240 #if DVDNAVVERSION > 012
3241 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3242 #else
3243 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3244 #endif
3246 printf("DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n",
3247 stream_change->physical,
3248 stream_change->logical);
3250 aid_temp=stream_change->physical;
3251 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3252 if (d_audio && audio_id!=aid_temp) {
3253 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3254 d_audio->id,aid_temp);
3255 // FIXME: need a bettery way to change audio stream id
3256 d_audio->id=dvdsub_id=aid_temp;
3257 if(sh_audio) resync_audio_stream(sh_audio);
3260 break;
3262 case DVDNAV_VTS_CHANGE: {
3263 printf("DVDNAV Event: Nav VTS Change\n");
3264 break;
3266 case DVDNAV_CELL_CHANGE: {
3267 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3268 cell_playback_t * cell_playback = cell_change->new_cell;
3270 printf("DVDNAV Event: Nav Cell Change\n");
3271 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3273 printf("new still time: %d\n",cell_playback->still_time);
3274 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3275 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3276 cell_playback->playback_time.hour,
3277 cell_playback->playback_time.minute,
3278 cell_playback->playback_time.second,
3279 cell_playback->playback_time.frame_u);
3282 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3283 //abs_seek_pos=0;
3284 break;
3286 case DVDNAV_NAV_PACKET: {
3287 // printf("DVDNAV Event: Nav Packet\n");
3288 break;
3290 case DVDNAV_SPU_CLUT_CHANGE: {
3291 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3293 printf("DVDNAV Event: Nav SPU CLUT Change\n");
3294 // send new palette to SPU decoder
3295 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3297 break;
3299 case DVDNAV_SEEK_DONE: {
3300 printf("DVDNAV Event: Nav Seek Done\n");
3301 break;
3305 // free the dvdnav event
3306 free(dvdnav_event->details);
3307 free(dvdnav_event);
3308 cmd->args[0].v.v=NULL;
3310 case MP_CMD_DVDNAV: {
3311 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3313 /* ignore these events if we're not in dvd_nav mode */
3314 if (stream->type != STREAMTYPE_DVDNAV) break;
3316 switch (cmd->args[0].v.i) {
3317 case MP_CMD_DVDNAV_UP:
3318 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3319 break;
3320 case MP_CMD_DVDNAV_DOWN:
3321 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3322 break;
3323 case MP_CMD_DVDNAV_LEFT:
3324 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3325 break;
3326 case MP_CMD_DVDNAV_RIGHT:
3327 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3328 break;
3329 case MP_CMD_DVDNAV_MENU:
3330 printf("Menu call\n");
3331 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3332 break;
3333 case MP_CMD_DVDNAV_SELECT:
3334 dvdnav_button_activate(dvdnav_priv->dvdnav);
3335 break;
3336 default:
3337 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3338 break;
3340 break;
3342 #endif
3343 default : {
3344 #ifdef HAVE_NEW_GUI
3345 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3346 else
3347 #endif
3348 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3351 mp_cmd_free(cmd);
3355 if (seek_to_sec) {
3356 int a,b; float d;
3358 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3359 rel_seek_secs += 3600*a +60*b +d ;
3360 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3361 rel_seek_secs += 60*a +d;
3362 else if (sscanf(seek_to_sec, "%f", &d)==1)
3363 rel_seek_secs += d;
3365 seek_to_sec = NULL;
3368 /* Looping. */
3369 if(eof==1 && loop_times>=0) {
3370 int l = loop_times;
3371 play_tree_iter_step(playtree_iter,0,0);
3372 loop_times = l;
3373 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3375 if(loop_times>1) loop_times--; else
3376 if(loop_times==1) loop_times=-1;
3377 play_n_frames=play_n_frames_mf;
3378 eof=0;
3379 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3380 loop_seek = 1;
3383 if(rel_seek_secs || abs_seek_pos){
3384 current_module="seek";
3385 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3386 // success:
3387 /* FIXME there should be real seeking for vobsub */
3388 if(sh_video) sh_video->pts=d_video->pts;
3389 if (vo_vobsub)
3390 vobsub_reset(vo_vobsub);
3391 #if 0
3392 if(sh_video && d_video->packs == 0)
3393 ds_fill_buffer(d_video);
3394 if(sh_audio){
3395 if(d_audio->packs == 0)
3396 ds_fill_buffer(d_audio);
3397 if(verbose>0){
3398 float a_pts=d_audio->pts;
3399 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3400 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);
3402 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);
3403 } else {
3404 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3406 #endif
3407 fflush(stdout);
3409 if(sh_video){
3410 current_module="seek_video_reset";
3411 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3414 if(sh_audio){
3415 current_module="seek_audio_reset";
3416 audio_out->reset(); // stop audio, throwing away buffered data
3418 #ifdef USE_OSD
3419 // Set OSD:
3420 if(osd_level && !loop_seek){
3421 #ifdef USE_EDL
3422 if( !edl_decision ) {
3423 #else
3424 if( 1 ) { // Let the compiler optimize this out
3425 #endif
3426 int len=((demuxer->movi_end-demuxer->movi_start)>>8);
3427 if (len>0 && sh_video){
3428 osd_visible=sh_video->fps; // 1 sec
3429 vo_osd_progbar_type=0;
3430 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
3431 vo_osd_changed(OSDTYPE_PROGBAR);
3435 #endif
3436 if(sh_video) {
3437 c_total=0;
3438 max_pts_correction=0.1;
3439 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3440 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3441 drop_frame_cnt=0;
3442 too_slow_frame_cnt=0;
3443 too_fast_frame_cnt=0;
3445 if(vo_spudec) spudec_reset(vo_spudec);
3448 #ifdef USE_EDL
3450 int x;
3451 if( !edl_decision ) {
3452 for( x = 0; x < num_edl_records; x++ ) { // FIXME: do binary search
3453 // Find first EDL entry where start follows current time
3454 if( edl_records[ x ].start_sec >= sh_video->pts && edl_records[ x ].action != EDL_MUTE ) {
3455 next_edl_record = &edl_records[ x ];
3456 break;
3459 } else {
3460 edl_decision = 0;
3463 #endif
3464 rel_seek_secs=0;
3465 abs_seek_pos=0;
3466 frame_time_remaining=0;
3467 current_module=NULL;
3468 loop_seek=0;
3471 #ifdef HAVE_NEW_GUI
3472 if(use_gui){
3473 guiEventHandling();
3474 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3475 // get pos from frame number / total frames
3476 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3477 } else {
3478 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3479 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3480 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3482 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3483 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3484 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3485 guiGetEvent( guiReDraw,NULL );
3486 guiGetEvent( guiSetVolume,NULL );
3487 if(guiIntfStruct.Playing==0) break; // STOP
3488 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3489 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3490 #ifdef USE_DVDREAD
3491 if ( stream->type == STREAMTYPE_DVD )
3493 dvd_priv_t * dvdp = stream->priv;
3494 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3496 #endif
3498 #endif
3501 //================= Update OSD ====================
3502 #ifdef USE_OSD
3503 if(osd_level>=1 && sh_video){
3504 int pts=sh_video->pts;
3505 char osd_text_tmp[64];
3506 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
3507 vo_osd_text=osd_text_buffer;
3508 #ifdef USE_DVDNAV
3509 if (osd_show_dvd_nav_delay) {
3510 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
3511 osd_show_dvd_nav_delay--;
3512 } else
3513 #endif
3514 #ifdef USE_TV
3515 if (osd_show_tv_channel && tv_channel_list) {
3516 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
3517 osd_show_tv_channel--;
3518 } else
3519 #endif
3520 if (osd_show_text) {
3521 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
3522 osd_show_text--;
3523 } else
3524 if (osd_show_sub_visibility) {
3525 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
3526 osd_show_sub_visibility--;
3527 } else
3528 if (osd_show_vobsub_changed) {
3529 const char *language = "none";
3530 if (vo_vobsub && vobsub_id >= 0)
3531 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
3532 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
3533 osd_show_vobsub_changed--;
3534 } else
3535 #ifdef USE_SUB
3536 if (osd_show_sub_changed) {
3537 char *tmp2;
3538 tmp = subdata->filename;
3539 if ((tmp2 = strrchr(tmp, '/'))) {
3540 tmp = tmp2+1;
3542 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
3543 set_of_sub_pos + 1,
3544 strlen(tmp) < 20 ? "" : "...",
3545 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
3546 osd_show_sub_changed--;
3547 } else
3548 #endif
3549 if (osd_show_sub_delay) {
3550 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
3551 osd_show_sub_delay--;
3552 } else
3553 if (osd_show_sub_pos) {
3554 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
3555 osd_show_sub_pos--;
3556 } else
3557 if (osd_show_sub_alignment) {
3558 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
3559 (sub_alignment == 2 ? "bottom" :
3560 (sub_alignment == 1 ? "center" : "top")));
3561 osd_show_sub_alignment--;
3562 } else
3563 if (osd_show_av_delay) {
3564 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
3565 osd_show_av_delay--;
3566 } else if (osd_show_ontop) {
3567 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
3568 osd_show_ontop--;
3569 } else if(osd_level>=2) {
3570 int len = demuxer_get_time_length(demuxer);
3571 int percentage = -1;
3572 char percentage_text[10];
3573 if (osd_show_percentage) {
3574 percentage = demuxer_get_percent_pos(demuxer);
3575 osd_show_percentage--;
3577 if (percentage >= 0)
3578 snprintf(percentage_text, 9, " (%d%%)", percentage);
3579 else
3580 percentage_text[0] = 0;
3581 if (osd_level == 3)
3582 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);
3583 else
3584 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
3585 } else osd_text_tmp[0]=0;
3587 if(strcmp(vo_osd_text, osd_text_tmp)) {
3588 strncpy(vo_osd_text, osd_text_tmp, 63);
3589 vo_osd_changed(OSDTYPE_OSD);
3591 } else {
3592 if(vo_osd_text) {
3593 vo_osd_text=NULL;
3594 vo_osd_changed(OSDTYPE_OSD);
3597 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3598 // vo_osd_text=osd_text_buffer;
3599 #endif
3601 #ifdef USE_SUB
3602 // find sub
3603 if(subdata && sh_video->pts>0){
3604 float pts=sh_video->pts;
3605 if(sub_fps==0) sub_fps=sh_video->fps;
3606 current_module="find_sub";
3607 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
3608 find_sub(subdata, (pts+sub_delay) *
3609 (subdata->sub_uses_time ? 100. : sub_fps));
3610 // FIXME! frame counter...
3611 sub_last_pts = pts;
3613 current_module=NULL;
3615 #endif
3617 #ifdef HAVE_X11
3618 if (stop_xscreensaver && sh_video) {
3619 current_module="stop_xscreensaver";
3620 xscreensaver_heartbeat(sh_video->pts);
3621 current_module=NULL;
3623 #endif
3625 // DVD sub:
3626 if(vo_config_count && vo_spudec) {
3627 unsigned char* packet=NULL;
3628 int len,timestamp;
3629 current_module="spudec";
3630 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
3631 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3632 while(1) {
3633 // Vobsub
3634 len = 0;
3635 if(vo_vobsub) {
3636 if(sh_video->pts+sub_delay>=0) {
3637 // The + next_frame_time is there because we'll display the sub at the next frame
3638 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
3639 if(len > 0) {
3640 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
3641 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);
3644 } else {
3645 // DVD sub
3646 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
3647 if(len > 0) {
3648 float x = d_dvdsub->pts - sh_video->pts;
3649 if (x < -10 || x > 10) // prevent missing subs on pts reset
3650 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
3651 else timestamp = 90000*(sh_video->timer + sub_delay);
3652 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);
3655 if(len<=0 || !packet) break;
3656 if(timestamp < 0) timestamp = 0;
3657 else spudec_assemble(vo_spudec,packet,len,timestamp);
3660 /* detect wether the sub has changed or not */
3661 if(spudec_changed(vo_spudec))
3662 vo_osd_changed(OSDTYPE_SPU);
3663 current_module=NULL;
3666 } // while(!eof)
3668 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
3672 goto_next_file: // don't jump here after ao/vo/getch initialization!
3674 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3676 if(benchmark){
3677 double tot=video_time_usage+vout_time_usage+audio_time_usage;
3678 double total_time_usage;
3679 total_time_usage_start=GetTimer()-total_time_usage_start;
3680 total_time_usage = (float)total_time_usage_start*0.000001;
3681 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3682 video_time_usage,vout_time_usage,audio_time_usage,
3683 total_time_usage-tot,total_time_usage);
3684 if(total_time_usage>0.0)
3685 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3686 100.0*video_time_usage/total_time_usage,
3687 100.0*vout_time_usage/total_time_usage,
3688 100.0*audio_time_usage/total_time_usage,
3689 100.0*(total_time_usage-tot)/total_time_usage,
3690 100.0);
3691 if(total_frame_cnt && frame_dropping)
3692 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3693 total_frame_cnt-drop_frame_cnt,
3694 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
3695 drop_frame_cnt,
3696 100*drop_frame_cnt/total_frame_cnt,
3697 total_frame_cnt,
3698 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
3702 // time to uninit all, except global stuff:
3703 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
3705 #ifdef USE_SUB
3706 if ( set_of_sub_size > 0 )
3708 current_module="sub_free";
3709 for (i = 0; i < set_of_sub_size; ++i)
3710 sub_free( set_of_subtitles[i] );
3711 set_of_sub_size = 0;
3712 vo_sub=NULL;
3713 subdata=NULL;
3715 #endif
3717 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
3718 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
3719 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
3720 eof = 1;
3721 } else {
3722 play_tree_iter_free(playtree_iter);
3723 playtree_iter = NULL;
3725 play_tree_step = 1;
3726 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
3727 eof = eof == PT_UP_NEXT ? 1 : -1;
3728 if ( playtree_iter ) {
3729 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
3730 eof = 1;
3731 } else {
3732 play_tree_iter_free(playtree_iter);
3733 playtree_iter = NULL;
3736 } else { // NEXT PREV SRC
3737 eof = eof == PT_PREV_SRC ? -1 : 1;
3740 if(eof == 0) eof = 1;
3742 while(playtree_iter != NULL) {
3743 filename = play_tree_iter_get_file(playtree_iter,eof);
3744 if(filename == NULL) {
3745 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
3746 play_tree_iter_free(playtree_iter);
3747 playtree_iter = NULL;
3749 } else
3750 break;
3753 #ifdef HAVE_NEW_GUI
3754 if( use_gui && !playtree_iter )
3756 #ifdef USE_DVDREAD
3757 if ( !guiIntfStruct.DiskChanged )
3758 #endif
3759 mplEnd();
3761 #endif
3763 if(use_gui || playtree_iter != NULL){
3765 eof = 0;
3766 goto play_next_file;
3769 #ifdef HAVE_FREETYPE
3770 current_module="uninit_font";
3771 if (vo_font) free_font_desc(vo_font);
3772 vo_font = NULL;
3773 done_freetype();
3774 #endif
3776 exit_player_with_rc(MSGTR_Exit_eof, 0);
3778 return 1;