constant qscale was broken due to libavcodec changes, fix taken from ve_lavc.c
[mplayer/greg.git] / mplayer.c
blob07098f8ecdbf6b2597012ed70ca3254579fe6af1
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;
740 int rtc_fd=-1;
742 //float a_frame=0; // Audio
744 int i;
745 char *tmp;
747 int gui_no_filename=0;
750 srand((int) time(NULL));
752 mp_msg_init();
753 mp_msg_set_level(MSGL_STATUS);
755 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2003 MPlayer Team\n\n");
756 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
757 GetCpuCaps(&gCpuCaps);
758 #ifdef ARCH_X86
759 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
760 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
761 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
762 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
763 #ifdef RUNTIME_CPUDETECT
764 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
765 #else
766 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
767 #ifdef HAVE_MMX
768 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
769 #endif
770 #ifdef HAVE_MMX2
771 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
772 #endif
773 #ifdef HAVE_3DNOW
774 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
775 #endif
776 #ifdef HAVE_3DNOWEX
777 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
778 #endif
779 #ifdef HAVE_SSE
780 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
781 #endif
782 #ifdef HAVE_SSE2
783 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
784 #endif
785 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
786 #endif
787 #endif
789 #if defined(WIN32) && defined(USE_WIN32DLL)
790 { /*make our codec dirs available for LoadLibraryA()*/
791 char tmppath[MAX_PATH*2 + 1];
792 char win32path[MAX_PATH];
793 char realpath[MAX_PATH];
794 int WINAPI SetEnvironmentVariableA(char*,char*);
795 int WINAPI GetModuleFileNameA(void*,char*,int);
796 #ifdef __CYGWIN__
797 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
798 strcpy(tmppath,win32path);
799 #ifdef USE_REALCODECS
800 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
801 sprintf(tmppath,"%s;%s",win32path,realpath);
802 #endif /*USE_REALCODECS*/
803 #else
804 if(!strstr(WIN32_PATH,":")){
805 GetModuleFileNameA(NULL, win32path, MAX_PATH);
806 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
808 else strcpy(win32path,WIN32_PATH);
809 strcpy(tmppath,win32path);
810 #ifdef USE_REALCODECS
811 if(!strstr(REALCODEC_PATH,":")){
812 GetModuleFileNameA(NULL, realpath, MAX_PATH);
813 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
815 else strcpy(realpath,REALCODEC_PATH);
816 sprintf(tmppath,"%s;%s",win32path,realpath);
817 #endif /*USE_REALCODECS*/
818 #endif /*__CYGWIN__*/
819 SetEnvironmentVariableA("PATH", tmppath);
821 #endif /*WIN32 && USE_WIN32DLL*/
823 #ifdef USE_TV
824 tv_param_immediate = 1;
825 #endif
827 if ( argv[0] )
828 if(!strcmp(argv[0],"gmplayer") ||
829 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
830 use_gui=1;
832 mconfig = m_config_new();
833 m_config_register_options(mconfig,mplayer_opts);
834 // TODO : add something to let modules register their options
835 mp_input_register_options(mconfig);
836 parse_cfgfiles(mconfig);
838 #ifdef HAVE_NEW_GUI
839 if ( use_gui ) cfg_read();
840 #endif
842 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
843 if(playtree == NULL)
844 exit(1);
846 playtree = play_tree_cleanup(playtree);
847 if(playtree) {
848 playtree_iter = play_tree_iter_new(playtree,mconfig);
849 if(playtree_iter) {
850 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
851 play_tree_iter_free(playtree_iter);
852 playtree_iter = NULL;
854 filename = play_tree_iter_get_file(playtree_iter,1);
858 #ifndef HAVE_NEW_GUI
859 if(use_gui){
860 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
861 use_gui=0;
863 #else
864 if(use_gui && !vo_init()){
865 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
866 use_gui=0;
868 if (use_gui && playtree_iter){
869 char cwd[PATH_MAX+2];
870 // Remove Playtree and Playtree-Iter from memory as its not used by gui
871 play_tree_iter_free(playtree_iter);
872 playtree_iter=NULL;
874 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
876 strcat(cwd, "/");
877 // Prefix relative paths with current working directory
878 play_tree_add_bpf(playtree, cwd);
880 // Import initital playtree into gui
881 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
883 #endif
885 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
886 list_video_out();
887 exit(0);
890 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
891 list_audio_out();
892 exit(0);
895 // check codec.conf
896 if(!parse_codec_cfg(get_path("codecs.conf"))){
897 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
898 if(!parse_codec_cfg(NULL)){
899 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
900 exit(0);
902 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_BuiltinCodecsConf);
906 #if 0
907 if(video_codec_list){
908 int i;
909 video_codec=video_codec_list[0];
910 for(i=0;video_codec_list[i];i++)
911 printf("vc#%d: '%s'\n",i,video_codec_list[i]);
913 #endif
914 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
915 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
916 list_codecs(1);
917 printf("\n");
918 exit(0);
920 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
921 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
922 list_codecs(0);
923 printf("\n");
924 exit(0);
926 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
927 vfm_help();
928 printf("\n");
929 exit(0);
931 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
932 afm_help();
933 printf("\n");
934 exit(0);
936 #ifdef HAVE_X11
937 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
938 fstype_help();
939 printf("\n");
940 exit(0);
942 #endif
944 #ifdef USE_EDL
946 FILE* fd;
947 char line[ 100 ];
948 float start, stop, duration;
949 int action;
950 int next_edl_array_index = 0;
951 int lineCount = 0;
952 next_edl_record = edl_records;
953 if( edl_filename ) {
954 if( ( fd = fopen( edl_filename, "r" ) ) == NULL ) {
955 printf( "Error opening EDL file [%s]!\n", edl_filename );
956 next_edl_record->next = NULL;
957 } else {
958 while( fgets( line, 99, fd ) != NULL ) {
959 lineCount++;
960 if( ( sscanf( line, "%f %f %d", &start, &stop, &action ) ) == 0 ) {
961 printf( "Invalid EDL line: [%s]\n", line );
962 } else {
963 if( next_edl_array_index > 0 ) {
964 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
965 if( start <= edl_records[ next_edl_array_index-1 ].stop_sec ) {
966 printf( "Invalid EDL line [%d]: [%s]\n", lineCount, line );
967 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 );
968 continue;
971 if( stop <= start ) {
972 printf( "Invalid EDL line [%d]: [%s]\n", lineCount, line );
973 printf( "Stop time must follow start time. Discarding EDL entry.\n" );
974 continue;
976 edl_records[ next_edl_array_index ].action = action;
977 if( action == EDL_MUTE ) {
978 edl_records[ next_edl_array_index ].length_sec = 0;
979 edl_records[ next_edl_array_index ].start_sec = start;
980 edl_records[ next_edl_array_index ].stop_sec = start;
981 next_edl_array_index++;
982 if( next_edl_array_index >= MAX_EDL_ENTRIES-1 ) {
983 break;
985 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
986 edl_records[ next_edl_array_index ].action = EDL_MUTE;
987 edl_records[ next_edl_array_index ].length_sec = 0;
988 edl_records[ next_edl_array_index ].start_sec = stop;
989 edl_records[ next_edl_array_index ].stop_sec = stop;
990 } else {
991 edl_records[ next_edl_array_index ].length_sec = stop - start;
992 edl_records[ next_edl_array_index ].start_sec = start;
993 edl_records[ next_edl_array_index ].stop_sec = stop;
995 next_edl_array_index++;
996 if( next_edl_array_index >= MAX_EDL_ENTRIES-1 ) {
997 break;
1001 if( next_edl_array_index > 0 ) {
1002 edl_records[ next_edl_array_index-1 ].next = &edl_records[ next_edl_array_index ];
1004 edl_records[ next_edl_array_index ].start_sec = -1;
1005 edl_records[ next_edl_array_index ].next = NULL;
1006 num_edl_records = ( next_edl_array_index );
1008 fclose( fd );
1009 } else {
1010 next_edl_record->next = NULL;
1012 if( edl_output_filename ) {
1013 if( edl_filename ) {
1014 printf( "Sorry; EDL mode and EDL output mode are mutually exclusive! Disabling all EDL functions.\n" );
1015 edl_output_filename = NULL;
1016 edl_filename = NULL;
1017 next_edl_record->next = NULL;
1018 } else {
1019 if( ( edl_fd = fopen( edl_output_filename, "w" ) ) == NULL ) {
1020 printf( "Error opening file [%s] for writing!\n", edl_output_filename );
1021 edl_output_filename = NULL;
1022 next_edl_record->next = NULL;
1026 #ifdef DEBUG_EDL
1028 printf( "EDL Records:\n" );
1029 if( next_edl_record->next != NULL ) {
1030 while( next_edl_record->next != NULL ) {
1031 printf( "EDL: start [%f], stop [%f], action [%d]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->action );
1032 next_edl_record = next_edl_record->next;
1034 next_edl_record = edl_records;
1037 #endif
1039 #endif
1041 if(!filename){
1042 if(!use_gui){
1043 // no file/vcd/dvd -> show HELP:
1044 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1045 exit(0);
1046 } else gui_no_filename=1;
1049 // Many users forget to include command line in bugreports...
1050 if(verbose>0){
1051 mp_msg(MSGT_CPLAYER, MSGL_INFO, "CommandLine:");
1052 for(i=1;i<argc;i++)printf(" '%s'",argv[i]);
1053 printf("\n");
1056 mp_msg_set_level(verbose+MSGL_STATUS);
1058 //------ load global data first ------
1060 #ifdef USE_OSD
1061 // check font
1062 if(font_name){
1063 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1064 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1065 } else {
1066 // try default:
1067 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1);
1068 if(!vo_font)
1069 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1071 #ifdef HAVE_FREETYPE
1072 if (!vo_font)
1073 init_freetype();
1074 #endif
1075 #endif
1076 vo_init_osd();
1078 #ifdef HAVE_RTC
1079 if(!nortc)
1081 // seteuid(0); /* Can't hurt to try to get root here */
1082 if ((rtc_fd = open("/dev/rtc", O_RDONLY)) < 0)
1083 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));
1084 else {
1085 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1087 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1088 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp, strerror(errno));
1089 mp_msg(MSGT_CPLAYER, MSGL_HINT, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp);
1090 close (rtc_fd);
1091 rtc_fd = -1;
1092 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1093 /* variable only by the root */
1094 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno));
1095 close (rtc_fd);
1096 rtc_fd = -1;
1097 } else
1098 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_UsingRTCTiming, irqp);
1101 #ifdef HAVE_NEW_GUI
1102 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1103 // and now ? -- Pontscho
1104 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1105 #endif
1106 if(rtc_fd<0)
1107 #endif
1108 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Using %s timing\n",softsleep?"software":"usleep()");
1110 #ifdef USE_TERMCAP
1111 if ( !use_gui ) load_termcap(NULL); // load key-codes
1112 #endif
1114 // ========== Init keyboard FIFO (connection to libvo) ============
1116 // Init input system
1117 current_module = "init_input";
1118 mp_input_init();
1119 #ifndef HAVE_NO_POSIX_SELECT
1120 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1122 if(keyb_fifo_get > 0)
1123 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1124 #else
1125 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1126 #endif
1127 if(slave_mode)
1128 #ifndef __MINGW32__
1129 mp_input_add_cmd_fd(0,1,NULL,NULL);
1130 #else
1131 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1132 #endif
1133 else if(!use_stdin)
1134 #ifndef HAVE_NO_POSIX_SELECT
1135 mp_input_add_key_fd(0,1,NULL,NULL);
1136 #else
1137 mp_input_add_key_fd(0,0,NULL,NULL);
1138 #endif
1140 inited_flags|=INITED_INPUT;
1141 current_module = NULL;
1143 #ifdef HAVE_MENU
1144 if(use_menu) {
1145 if(menu_cfg && menu_init(menu_cfg))
1146 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", menu_cfg);
1147 else {
1148 menu_cfg = get_path("menu.conf");
1149 if(menu_init(menu_cfg))
1150 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", menu_cfg);
1151 else {
1152 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1153 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu inited: %s\n", MPLAYER_CONFDIR"/menu.conf");
1154 else {
1155 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Menu init failed\n");
1156 use_menu = 0;
1161 #endif
1165 //========= Catch terminate signals: ================
1166 // terminate requests:
1167 signal(SIGTERM,exit_sighandler); // kill
1168 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1170 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1172 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1173 #ifdef ENABLE_SIGHANDLER
1174 // fatal errors:
1175 signal(SIGBUS,exit_sighandler); // bus error
1176 signal(SIGSEGV,exit_sighandler); // segfault
1177 signal(SIGILL,exit_sighandler); // illegal instruction
1178 signal(SIGFPE,exit_sighandler); // floating point exc.
1179 signal(SIGABRT,exit_sighandler); // abort()
1180 #endif
1182 #ifdef HAVE_NEW_GUI
1183 if(use_gui){
1184 guiInit();
1185 inited_flags|=INITED_GUI;
1186 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1188 #endif
1190 // ******************* Now, let's see the per-file stuff ********************
1192 play_next_file:
1194 if (filename) load_per_file_config (mconfig, filename);
1196 // We must enable getch2 here to be able to interrupt network connection
1197 // or cache filling
1198 if(!use_stdin && !slave_mode){
1199 if(inited_flags&INITED_GETCH2)
1200 mp_msg(MSGT_CPLAYER,MSGL_WARN,"WARNING: getch2_init called twice!\n");
1201 else
1202 getch2_enable(); // prepare stdin for hotkeys...
1203 inited_flags|=INITED_GETCH2;
1204 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1207 // =================== GUI idle loop (STOP state) ===========================
1208 #ifdef HAVE_NEW_GUI
1209 if ( use_gui ) {
1210 file_format=DEMUXER_TYPE_UNKNOWN;
1211 guiGetEvent( guiSetDefaults,0 );
1212 while ( guiIntfStruct.Playing != 1 )
1214 mp_cmd_t* cmd;
1215 usec_sleep(20000);
1216 guiEventHandling();
1217 guiGetEvent( guiReDraw,NULL );
1218 if ( (cmd = mp_input_get_cmd(0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1220 guiGetEvent( guiSetParameters,NULL );
1221 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1223 play_tree_t * entry = play_tree_new();
1224 play_tree_add_file( entry,guiIntfStruct.Filename );
1225 if ( playtree ) play_tree_free_list( playtree->child,1 );
1226 else playtree=play_tree_new();
1227 play_tree_set_child( playtree,entry );
1228 if(playtree)
1230 playtree_iter = play_tree_iter_new(playtree,mconfig);
1231 if(playtree_iter)
1233 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1235 play_tree_iter_free(playtree_iter);
1236 playtree_iter = NULL;
1238 filename = play_tree_iter_get_file(playtree_iter,1);
1243 #endif
1244 //---------------------------------------------------------------------------
1246 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
1247 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1249 //==================== Open VOB-Sub ============================
1251 current_module="vobsub";
1252 if (vobsub_name){
1253 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1254 if(vo_vobsub==NULL)
1255 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1256 }else if(sub_auto && filename && (strlen(filename)>=5)){
1257 /* try to autodetect vobsub from movie filename ::atmos */
1258 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1259 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1260 strncpy(buf, filename, strlen(filename)-4);
1261 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1262 free(buf);
1264 if(vo_vobsub){
1265 sub_auto=0; // don't do autosub for textsubs if vobsub found
1266 inited_flags|=INITED_VOBSUB;
1267 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1268 // check if vobsub requested only to display forced subtitles
1269 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1272 //============ Open & Sync STREAM --- fork cache2 ====================
1274 stream=NULL;
1275 demuxer=NULL;
1276 if (d_audio) {
1277 //free_demuxer_stream(d_audio);
1278 d_audio=NULL;
1280 if (d_video) {
1281 //free_demuxer_stream(d_video);
1282 d_video=NULL;
1284 sh_audio=NULL;
1285 sh_video=NULL;
1287 current_module="open_stream";
1288 stream=open_stream(filename,0,&file_format);
1289 if(!stream) { // error...
1290 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1291 goto goto_next_file;
1293 inited_flags|=INITED_STREAM;
1295 #ifdef HAVE_NEW_GUI
1296 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1297 #endif
1299 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1300 play_tree_t* entry;
1301 // Handle playlist
1302 current_module="handle_playlist";
1303 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1304 entry = parse_playtree(stream,0);
1305 eof=playtree_add_playlist(entry);
1306 goto goto_next_file;
1308 stream->start_pos+=seek_to_byte;
1310 #ifdef HAVE_LIBCSS
1311 current_module="libcss";
1312 if (dvdimportkey) {
1313 if (dvd_import_key(dvdimportkey)) {
1314 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorDVDkey);
1315 exit_player(MSGTR_Exit_error);
1317 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CmdlineDVDkey);
1319 if (dvd_auth_device) {
1320 if (dvd_auth(dvd_auth_device,filename)) {
1321 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"Error in DVD auth...\n");
1322 exit_player(MSGTR_Exit_error);
1324 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_DVDauthOk);
1326 #endif
1328 if(stream_dump_type==5){
1329 unsigned char buf[4096];
1330 int len;
1331 FILE *f;
1332 current_module="dumpstream";
1333 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1334 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"Cannot dump this stream - no 'fd' available\n");
1335 exit_player(MSGTR_Exit_error);
1337 stream_reset(stream);
1338 stream_seek(stream,stream->start_pos);
1339 f=fopen(stream_dump_name,"wb");
1340 if(!f){
1341 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1342 exit_player(MSGTR_Exit_error);
1344 while(!stream->eof){
1345 len=stream_read(stream,buf,4096);
1346 if(len>0) {
1347 if(fwrite(buf,len,1,f) != 1) {
1348 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1349 exit_player(MSGTR_Exit_error);
1353 if(fclose(f)) {
1354 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1355 exit_player(MSGTR_Exit_error);
1357 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1358 exit_player_with_rc(MSGTR_Exit_eof, 0);
1361 #ifdef USE_DVDREAD
1362 if(stream->type==STREAMTYPE_DVD){
1363 current_module="dvd lang->id";
1364 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1365 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1366 current_module=NULL;
1368 #endif
1370 #ifdef USE_DVDNAV
1371 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1372 #endif
1374 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1375 if(stream_cache_size>0){
1376 current_module="enable_cache";
1377 if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024/5,stream_cache_size*1024/20))
1378 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1381 //============ Open DEMUXERS --- DETECT file type =======================
1382 #ifdef HAS_DVBIN_SUPPORT
1383 goto_open_demuxer:
1384 #endif
1385 current_module="demux_open";
1387 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1389 // HACK to get MOV Reference Files working
1391 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1393 unsigned char* playlist_entry;
1394 play_tree_t *list = NULL, *entry = NULL;
1396 current_module="handle_demux_playlist";
1397 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1399 char *temp, *bname;
1401 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry\n",playlist_entry);
1403 bname=mp_basename(playlist_entry);
1404 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1405 continue;
1407 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1408 continue;
1410 entry = play_tree_new();
1412 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1414 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1415 if (temp)
1417 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1418 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1419 strcat(temp, playlist_entry);
1420 play_tree_add_file(entry,temp);
1421 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s\n",temp);
1422 free(temp);
1425 else
1426 play_tree_add_file(entry,playlist_entry);
1428 if(!list)
1429 list = entry;
1430 else
1431 play_tree_append_entry(list,entry);
1433 free_demuxer(demuxer);
1434 demuxer = NULL;
1436 if (list)
1438 entry = play_tree_new();
1439 play_tree_set_child(entry,list);
1440 eof=playtree_add_playlist(entry);
1441 goto goto_next_file;
1445 if(!demuxer)
1447 #if 0
1448 play_tree_t* entry;
1449 // Handle playlist
1450 current_module="handle_playlist";
1451 switch(stream->type){
1452 case STREAMTYPE_VCD:
1453 case STREAMTYPE_DVD:
1454 case STREAMTYPE_DVDNAV:
1455 case STREAMTYPE_CDDA:
1456 case STREAMTYPE_VCDBINCUE:
1457 // don't try to parse raw media as playlist, it's unlikely
1458 goto goto_next_file;
1460 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Falling back on trying to parse playlist %s...\n",filename);
1461 stream_reset(stream);
1462 stream_seek(stream,stream->start_pos);
1463 entry = parse_playtree(stream,0);
1464 if(!entry)
1465 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1466 else
1467 eof=playtree_add_playlist(entry);
1468 #endif
1469 goto goto_next_file;
1471 inited_flags|=INITED_DEMUXER;
1473 current_module="demux_open2";
1475 //file_format=demuxer->file_format;
1477 d_audio=demuxer->audio;
1478 d_video=demuxer->video;
1479 d_dvdsub=demuxer->sub;
1481 // DUMP STREAMS:
1482 if((stream_dump_type)&&(stream_dump_type<4)){
1483 FILE *f;
1484 demux_stream_t *ds=NULL;
1485 current_module="dump";
1486 // select stream to dump
1487 switch(stream_dump_type){
1488 case 1: ds=d_audio;break;
1489 case 2: ds=d_video;break;
1490 case 3: ds=d_dvdsub;break;
1492 if(!ds){
1493 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1494 exit_player(MSGTR_Exit_error);
1496 // disable other streams:
1497 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1498 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1499 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1500 // let's dump it!
1501 f=fopen(stream_dump_name,"wb");
1502 if(!f){
1503 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1504 exit_player(MSGTR_Exit_error);
1506 while(!ds->eof){
1507 unsigned char* start;
1508 int in_size=ds_get_packet(ds,&start);
1509 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1510 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1511 if(in_size>0) fwrite(start,in_size,1,f);
1513 fclose(f);
1514 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1515 exit_player_with_rc(MSGTR_Exit_eof, 0);
1518 sh_audio=d_audio->sh;
1519 sh_video=d_video->sh;
1521 if(sh_video){
1523 current_module="video_read_properties";
1524 if(!video_read_properties(sh_video)) {
1525 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1526 sh_video=d_video->sh=NULL;
1527 } else {
1528 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1529 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1530 sh_video->fps,sh_video->frametime
1533 /* need to set fps here for output encoders to pick it up in their init */
1534 if(force_fps){
1535 sh_video->fps=force_fps;
1536 sh_video->frametime=1.0f/sh_video->fps;
1538 vo_fps = sh_video->fps;
1539 #ifdef HAVE_X11
1540 vo_mouse_timer_const=(int)sh_video->fps;
1541 #endif
1543 if(!sh_video->fps && !force_fps){
1544 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1545 sh_video=d_video->sh=NULL;
1551 fflush(stdout);
1553 if(!sh_video && !sh_audio){
1554 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1555 #ifdef HAS_DVBIN_SUPPORT
1556 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1558 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1559 if(priv->is_on)
1561 int dir;
1562 int v = last_dvb_step;
1563 if(v > 0)
1564 dir = DVB_CHANNEL_HIGHER;
1565 else
1566 dir = DVB_CHANNEL_LOWER;
1568 if(dvb_step_channel(priv, dir))
1570 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1571 goto goto_open_demuxer;
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 printf("UNINIT COMPLETE\n");
2937 goto goto_open_demuxer;
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 goto goto_open_demuxer;
2975 #endif
2976 case MP_CMD_TV_LAST_CHANNEL : {
2977 if (file_format == DEMUXER_TYPE_TV) {
2978 tv_last_channel((tvi_handle_t*)(demuxer->priv));
2979 #ifdef USE_OSD
2980 if (tv_channel_list) {
2981 osd_show_tv_channel = sh_video->fps;
2982 vo_osd_changed(OSDTYPE_SUBTITLE);
2984 #endif
2986 } break;
2987 case MP_CMD_TV_STEP_NORM : {
2988 if (file_format == DEMUXER_TYPE_TV)
2989 tv_step_norm((tvi_handle_t*)(demuxer->priv));
2990 } break;
2991 case MP_CMD_TV_STEP_CHANNEL_LIST : {
2992 if (file_format == DEMUXER_TYPE_TV)
2993 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
2994 } break;
2995 #endif
2996 case MP_CMD_VO_FULLSCREEN:
2998 #ifdef HAVE_NEW_GUI
2999 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3000 else
3001 #endif
3002 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3003 } break;
3004 case MP_CMD_PANSCAN : {
3005 if ( !video_out ) break;
3006 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3008 int abs= cmd->args[1].v.i;
3009 float v = cmd->args[0].v.f;
3010 float res;
3011 if(abs) res = v;
3012 else res = vo_panscan+v;
3013 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3014 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3015 #ifdef USE_OSD
3016 if(osd_level && sh_video){
3017 osd_visible=sh_video->fps; // 1 sec
3018 vo_osd_progbar_type=OSD_PANSCAN;
3019 vo_osd_progbar_value=vo_panscan*256;
3020 vo_osd_changed(OSDTYPE_PROGBAR);
3021 #ifdef HAVE_FREETYPE
3022 if (subtitle_autoscale == 2 || subtitle_autoscale == 3)
3023 // force scaling font to movie width or diagonal
3024 force_load_font = 1;
3025 #endif
3027 #endif
3029 } break;
3030 case MP_CMD_SUB_POS:
3032 #ifdef USE_SUB
3033 if (sh_video) {
3034 int v;
3035 v = cmd->args[0].v.i;
3037 sub_pos+=v;
3038 if(sub_pos >100) sub_pos=100;
3039 if(sub_pos <0) sub_pos=0;
3040 vo_osd_changed(OSDTYPE_SUBTITLE);
3041 osd_show_sub_pos = 9;
3043 #endif
3044 } break;
3045 case MP_CMD_SUB_ALIGNMENT:
3047 #ifdef USE_SUB
3048 if (sh_video) {
3049 if (cmd->nargs >= 1)
3050 sub_alignment = cmd->args[0].v.i;
3051 else
3052 sub_alignment = (sub_alignment+1) % 3;
3053 osd_show_sub_alignment = 9;
3054 vo_osd_changed(OSDTYPE_SUBTITLE);
3056 #endif
3057 } break;
3058 case MP_CMD_SUB_VISIBILITY:
3060 #ifdef USE_SUB
3061 if (sh_video) {
3062 sub_visibility=1-sub_visibility;
3063 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3064 vo_osd_changed(OSDTYPE_SUBTITLE);
3066 #endif
3067 } break;
3068 case MP_CMD_GET_SUB_VISIBILITY:
3070 #ifdef USE_SUB
3071 if (sh_video) {
3072 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_SUB_VISIBILITY=%ld\n", sub_visibility);
3074 #endif
3075 } break;
3076 case MP_CMD_VOBSUB_LANG:
3077 if (vo_vobsub)
3079 int new_id = vobsub_id + 1;
3080 if (vobsub_id < 0)
3081 new_id = 0;
3082 if ((unsigned int) new_id >= vobsub_get_indexes_count(vo_vobsub))
3083 new_id = -1;
3084 if(new_id != vobsub_id)
3085 osd_show_vobsub_changed = 9;
3086 vobsub_id = new_id;
3088 #ifdef USE_SUB
3089 else if (set_of_sub_size > 0){ //change subtitle file
3090 set_of_sub_pos = (set_of_sub_pos + 1) % set_of_sub_size;
3091 subdata = set_of_subtitles[set_of_sub_pos];
3092 osd_show_sub_changed = sh_video->fps;
3093 vo_sub = NULL;
3094 vo_osd_changed(OSDTYPE_SUBTITLE);
3096 #endif
3097 break;
3098 case MP_CMD_SUB_FORCED_ONLY:
3099 if (vo_spudec) {
3100 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3101 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3103 break;
3104 case MP_CMD_SCREENSHOT :
3105 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3106 break;
3107 case MP_CMD_VF_CHANGE_RECTANGLE:
3108 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3109 break;
3111 case MP_CMD_GET_TIME_LENGTH : {
3112 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
3113 } break;
3115 case MP_CMD_GET_VO_FULLSCREEN : {
3116 if(video_out && vo_config_count)
3117 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_VO_FULLSCREEN=%ld\n", vo_fs);
3118 } break;
3120 case MP_CMD_GET_PERCENT_POS : {
3121 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer));
3122 } break;
3124 #ifdef USE_DVDNAV
3125 case MP_CMD_DVDNAV_EVENT: {
3126 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3127 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3129 /* ignore these events if we're not in dvd_nav mode */
3130 if (stream->type != STREAMTYPE_DVDNAV) break;
3132 if (!dvdnav_event) {
3133 printf("DVDNAV Event NULL?!\n");
3134 break;
3137 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3139 switch (dvdnav_event->event) {
3140 case DVDNAV_BLOCK_OK: {
3141 /* be silent about this one */
3142 break;
3144 case DVDNAV_HIGHLIGHT: {
3145 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3146 if (!hevent) {
3147 printf("DVDNAV Event: Highlight event broken\n");
3148 break;
3151 if (hevent->display && hevent->buttonN>0)
3153 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3154 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3155 hevent->buttonN,
3156 hevent->sx,hevent->sy,
3157 hevent->ex,hevent->ey,
3158 hevent->pts, d_video->pts);
3159 printf("DVDNAV Event: %s\n",dvd_nav_text);
3160 //osd_show_dvd_nav_delay = 60;
3162 osd_show_dvd_nav_highlight=1;
3163 osd_show_dvd_nav_sx=hevent->sx;
3164 osd_show_dvd_nav_ex=hevent->ex;
3165 osd_show_dvd_nav_sy=hevent->sy;
3166 osd_show_dvd_nav_ey=hevent->ey;
3168 else {
3169 osd_show_dvd_nav_highlight=0;
3170 printf("DVDNAV Event: Highlight Hide\n");
3172 break;
3174 case DVDNAV_STILL_FRAME: {
3175 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3177 printf( "######################################## DVDNAV Event: Still Frame: %d sec(s)\n", still_event->length );
3178 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3179 usec_sleep(1000); /* 1ms */
3181 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3182 break;
3184 case DVDNAV_STOP: {
3185 printf( "DVDNAV Event: Nav Stop\n" );
3186 break;
3188 case DVDNAV_NOP: {
3189 printf("DVDNAV Event: Nav NOP\n");
3190 break;
3192 case DVDNAV_SPU_STREAM_CHANGE: {
3193 #if DVDNAVVERSION > 012
3194 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3196 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d/%d/%d logical: %d\n",
3197 stream_change->physical_wide,
3198 stream_change->physical_letterbox,
3199 stream_change->physical_pan_scan,
3200 stream_change->logical);
3202 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3203 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3204 d_dvdsub->id,stream_change->physical_wide);
3205 // FIXME: need a better way to change SPU id
3206 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3207 if (vo_spudec) spudec_reset(vo_spudec);
3209 #else
3210 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3212 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n",
3213 stream_change->physical,
3214 stream_change->logical);
3216 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3217 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3218 d_dvdsub->id,stream_change->physical);
3219 // FIXME: need a better way to change SPU id
3220 d_dvdsub->id=dvdsub_id=stream_change->physical;
3221 if (vo_spudec) spudec_reset(vo_spudec);
3223 #endif
3224 break;
3226 case DVDNAV_AUDIO_STREAM_CHANGE: {
3227 int aid_temp;
3228 #if DVDNAVVERSION > 012
3229 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3230 #else
3231 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3232 #endif
3234 printf("DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n",
3235 stream_change->physical,
3236 stream_change->logical);
3238 aid_temp=stream_change->physical;
3239 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3240 if (d_audio && audio_id!=aid_temp) {
3241 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3242 d_audio->id,aid_temp);
3243 // FIXME: need a bettery way to change audio stream id
3244 d_audio->id=dvdsub_id=aid_temp;
3245 if(sh_audio) resync_audio_stream(sh_audio);
3248 break;
3250 case DVDNAV_VTS_CHANGE: {
3251 printf("DVDNAV Event: Nav VTS Change\n");
3252 break;
3254 case DVDNAV_CELL_CHANGE: {
3255 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3256 cell_playback_t * cell_playback = cell_change->new_cell;
3258 printf("DVDNAV Event: Nav Cell Change\n");
3259 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3261 printf("new still time: %d\n",cell_playback->still_time);
3262 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3263 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3264 cell_playback->playback_time.hour,
3265 cell_playback->playback_time.minute,
3266 cell_playback->playback_time.second,
3267 cell_playback->playback_time.frame_u);
3270 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3271 //abs_seek_pos=0;
3272 break;
3274 case DVDNAV_NAV_PACKET: {
3275 // printf("DVDNAV Event: Nav Packet\n");
3276 break;
3278 case DVDNAV_SPU_CLUT_CHANGE: {
3279 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3281 printf("DVDNAV Event: Nav SPU CLUT Change\n");
3282 // send new palette to SPU decoder
3283 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3285 break;
3287 case DVDNAV_SEEK_DONE: {
3288 printf("DVDNAV Event: Nav Seek Done\n");
3289 break;
3293 // free the dvdnav event
3294 free(dvdnav_event->details);
3295 free(dvdnav_event);
3296 cmd->args[0].v.v=NULL;
3298 case MP_CMD_DVDNAV: {
3299 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3301 /* ignore these events if we're not in dvd_nav mode */
3302 if (stream->type != STREAMTYPE_DVDNAV) break;
3304 switch (cmd->args[0].v.i) {
3305 case MP_CMD_DVDNAV_UP:
3306 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3307 break;
3308 case MP_CMD_DVDNAV_DOWN:
3309 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3310 break;
3311 case MP_CMD_DVDNAV_LEFT:
3312 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3313 break;
3314 case MP_CMD_DVDNAV_RIGHT:
3315 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3316 break;
3317 case MP_CMD_DVDNAV_MENU:
3318 printf("Menu call\n");
3319 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3320 break;
3321 case MP_CMD_DVDNAV_SELECT:
3322 dvdnav_button_activate(dvdnav_priv->dvdnav);
3323 break;
3324 default:
3325 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3326 break;
3328 break;
3330 #endif
3331 default : {
3332 #ifdef HAVE_NEW_GUI
3333 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3334 else
3335 #endif
3336 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3339 mp_cmd_free(cmd);
3343 if (seek_to_sec) {
3344 int a,b; float d;
3346 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3347 rel_seek_secs += 3600*a +60*b +d ;
3348 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3349 rel_seek_secs += 60*a +d;
3350 else if (sscanf(seek_to_sec, "%f", &d)==1)
3351 rel_seek_secs += d;
3353 seek_to_sec = NULL;
3356 /* Looping. */
3357 if(eof==1 && loop_times>=0) {
3358 int l = loop_times;
3359 play_tree_iter_step(playtree_iter,0,0);
3360 loop_times = l;
3361 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3363 if(loop_times>1) loop_times--; else
3364 if(loop_times==1) loop_times=-1;
3365 play_n_frames=play_n_frames_mf;
3366 eof=0;
3367 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3368 loop_seek = 1;
3371 if(rel_seek_secs || abs_seek_pos){
3372 current_module="seek";
3373 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3374 // success:
3375 /* FIXME there should be real seeking for vobsub */
3376 if(sh_video) sh_video->pts=d_video->pts;
3377 if (vo_vobsub)
3378 vobsub_reset(vo_vobsub);
3379 #if 0
3380 if(sh_video && d_video->packs == 0)
3381 ds_fill_buffer(d_video);
3382 if(sh_audio){
3383 if(d_audio->packs == 0)
3384 ds_fill_buffer(d_audio);
3385 if(verbose>0){
3386 float a_pts=d_audio->pts;
3387 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3388 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);
3390 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);
3391 } else {
3392 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3394 #endif
3395 fflush(stdout);
3397 if(sh_video){
3398 current_module="seek_video_reset";
3399 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3402 if(sh_audio){
3403 current_module="seek_audio_reset";
3404 audio_out->reset(); // stop audio, throwing away buffered data
3406 #ifdef USE_OSD
3407 // Set OSD:
3408 if(osd_level && !loop_seek){
3409 #ifdef USE_EDL
3410 if( !edl_decision ) {
3411 #else
3412 if( 1 ) { // Let the compiler optimize this out
3413 #endif
3414 int len=((demuxer->movi_end-demuxer->movi_start)>>8);
3415 if (len>0 && sh_video){
3416 osd_visible=sh_video->fps; // 1 sec
3417 vo_osd_progbar_type=0;
3418 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
3419 vo_osd_changed(OSDTYPE_PROGBAR);
3423 #endif
3424 if(sh_video) {
3425 c_total=0;
3426 max_pts_correction=0.1;
3427 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3428 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3429 drop_frame_cnt=0;
3430 too_slow_frame_cnt=0;
3431 too_fast_frame_cnt=0;
3433 if(vo_spudec) spudec_reset(vo_spudec);
3436 #ifdef USE_EDL
3438 int x;
3439 if( !edl_decision ) {
3440 for( x = 0; x < num_edl_records; x++ ) { // FIXME: do binary search
3441 // Find first EDL entry where start follows current time
3442 if( edl_records[ x ].start_sec >= sh_video->pts && edl_records[ x ].action != EDL_MUTE ) {
3443 next_edl_record = &edl_records[ x ];
3444 break;
3447 } else {
3448 edl_decision = 0;
3451 #endif
3452 rel_seek_secs=0;
3453 abs_seek_pos=0;
3454 frame_time_remaining=0;
3455 current_module=NULL;
3456 loop_seek=0;
3459 #ifdef HAVE_NEW_GUI
3460 if(use_gui){
3461 guiEventHandling();
3462 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3463 // get pos from frame number / total frames
3464 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3465 } else {
3466 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3467 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3468 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3470 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3471 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3472 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3473 guiGetEvent( guiReDraw,NULL );
3474 guiGetEvent( guiSetVolume,NULL );
3475 if(guiIntfStruct.Playing==0) break; // STOP
3476 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3477 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3478 #ifdef USE_DVDREAD
3479 if ( stream->type == STREAMTYPE_DVD )
3481 dvd_priv_t * dvdp = stream->priv;
3482 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3484 #endif
3486 #endif
3489 //================= Update OSD ====================
3490 #ifdef USE_OSD
3491 if(osd_level>=1 && sh_video){
3492 int pts=sh_video->pts;
3493 char osd_text_tmp[64];
3494 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
3495 vo_osd_text=osd_text_buffer;
3496 #ifdef USE_DVDNAV
3497 if (osd_show_dvd_nav_delay) {
3498 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
3499 osd_show_dvd_nav_delay--;
3500 } else
3501 #endif
3502 #ifdef USE_TV
3503 if (osd_show_tv_channel && tv_channel_list) {
3504 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
3505 osd_show_tv_channel--;
3506 } else
3507 #endif
3508 if (osd_show_text) {
3509 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
3510 osd_show_text--;
3511 } else
3512 if (osd_show_sub_visibility) {
3513 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
3514 osd_show_sub_visibility--;
3515 } else
3516 if (osd_show_vobsub_changed) {
3517 const char *language = "none";
3518 if (vo_vobsub && vobsub_id >= 0)
3519 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
3520 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
3521 osd_show_vobsub_changed--;
3522 } else
3523 #ifdef USE_SUB
3524 if (osd_show_sub_changed) {
3525 char *tmp2;
3526 tmp = subdata->filename;
3527 if ((tmp2 = strrchr(tmp, '/'))) {
3528 tmp = tmp2+1;
3530 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
3531 set_of_sub_pos + 1,
3532 strlen(tmp) < 20 ? "" : "...",
3533 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
3534 osd_show_sub_changed--;
3535 } else
3536 #endif
3537 if (osd_show_sub_delay) {
3538 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
3539 osd_show_sub_delay--;
3540 } else
3541 if (osd_show_sub_pos) {
3542 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
3543 osd_show_sub_pos--;
3544 } else
3545 if (osd_show_sub_alignment) {
3546 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
3547 (sub_alignment == 2 ? "bottom" :
3548 (sub_alignment == 1 ? "center" : "top")));
3549 osd_show_sub_alignment--;
3550 } else
3551 if (osd_show_av_delay) {
3552 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
3553 osd_show_av_delay--;
3554 } else if(osd_level>=2) {
3555 int len = demuxer_get_time_length(demuxer);
3556 int percentage = -1;
3557 char percentage_text[10];
3558 if (osd_show_percentage) {
3559 percentage = demuxer_get_percent_pos(demuxer);
3560 osd_show_percentage--;
3562 if (percentage >= 0)
3563 snprintf(percentage_text, 9, " (%d%%)", percentage);
3564 else
3565 percentage_text[0] = 0;
3566 if (osd_level == 3)
3567 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);
3568 else
3569 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
3570 } else osd_text_tmp[0]=0;
3572 if(strcmp(vo_osd_text, osd_text_tmp)) {
3573 strncpy(vo_osd_text, osd_text_tmp, 63);
3574 vo_osd_changed(OSDTYPE_OSD);
3576 } else {
3577 if(vo_osd_text) {
3578 vo_osd_text=NULL;
3579 vo_osd_changed(OSDTYPE_OSD);
3582 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3583 // vo_osd_text=osd_text_buffer;
3584 #endif
3586 #ifdef USE_SUB
3587 // find sub
3588 if(subdata && sh_video->pts>0){
3589 float pts=sh_video->pts;
3590 if(sub_fps==0) sub_fps=sh_video->fps;
3591 current_module="find_sub";
3592 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
3593 find_sub(subdata, (pts+sub_delay) *
3594 (subdata->sub_uses_time ? 100. : sub_fps));
3595 // FIXME! frame counter...
3596 sub_last_pts = pts;
3598 current_module=NULL;
3600 #endif
3602 #ifdef HAVE_X11
3603 if (stop_xscreensaver && sh_video) {
3604 current_module="stop_xscreensaver";
3605 xscreensaver_heartbeat(sh_video->pts);
3606 current_module=NULL;
3608 #endif
3610 // DVD sub:
3611 if(vo_config_count && vo_spudec) {
3612 unsigned char* packet=NULL;
3613 int len,timestamp;
3614 current_module="spudec";
3615 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
3616 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3617 while(1) {
3618 // Vobsub
3619 len = 0;
3620 if(vo_vobsub) {
3621 if(sh_video->pts+sub_delay>=0) {
3622 // The + next_frame_time is there because we'll display the sub at the next frame
3623 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
3624 if(len > 0) {
3625 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
3626 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);
3629 } else {
3630 // DVD sub
3631 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
3632 if(len > 0) {
3633 float x = d_dvdsub->pts - sh_video->pts;
3634 if (x < -10 || x > 10) // prevent missing subs on pts reset
3635 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
3636 else timestamp = 90000*(sh_video->timer + sub_delay);
3637 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);
3640 if(len<=0 || !packet) break;
3641 if(timestamp < 0) timestamp = 0;
3642 spudec_assemble(vo_spudec,packet,len,timestamp);
3645 /* detect wether the sub has changed or not */
3646 if(spudec_changed(vo_spudec))
3647 vo_osd_changed(OSDTYPE_SPU);
3648 current_module=NULL;
3651 } // while(!eof)
3653 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
3657 goto_next_file: // don't jump here after ao/vo/getch initialization!
3659 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3661 if(benchmark){
3662 double tot=video_time_usage+vout_time_usage+audio_time_usage;
3663 double total_time_usage;
3664 total_time_usage_start=GetTimer()-total_time_usage_start;
3665 total_time_usage = (float)total_time_usage_start*0.000001;
3666 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3667 video_time_usage,vout_time_usage,audio_time_usage,
3668 total_time_usage-tot,total_time_usage);
3669 if(total_time_usage>0.0)
3670 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3671 100.0*video_time_usage/total_time_usage,
3672 100.0*vout_time_usage/total_time_usage,
3673 100.0*audio_time_usage/total_time_usage,
3674 100.0*(total_time_usage-tot)/total_time_usage,
3675 100.0);
3676 if(total_frame_cnt && frame_dropping)
3677 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3678 total_frame_cnt-drop_frame_cnt,
3679 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
3680 drop_frame_cnt,
3681 100*drop_frame_cnt/total_frame_cnt,
3682 total_frame_cnt,
3683 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
3687 // time to uninit all, except global stuff:
3688 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
3690 #ifdef USE_SUB
3691 if ( set_of_sub_size > 0 )
3693 current_module="sub_free";
3694 for (i = 0; i < set_of_sub_size; ++i)
3695 sub_free( set_of_subtitles[i] );
3696 set_of_sub_size = 0;
3697 vo_sub=NULL;
3698 subdata=NULL;
3700 #endif
3702 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
3703 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
3704 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
3705 eof = 1;
3706 } else {
3707 play_tree_iter_free(playtree_iter);
3708 playtree_iter = NULL;
3710 play_tree_step = 1;
3711 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
3712 eof = eof == PT_UP_NEXT ? 1 : -1;
3713 if ( playtree_iter ) {
3714 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
3715 eof = 1;
3716 } else {
3717 play_tree_iter_free(playtree_iter);
3718 playtree_iter = NULL;
3721 } else { // NEXT PREV SRC
3722 eof = eof == PT_PREV_SRC ? -1 : 1;
3725 if(eof == 0) eof = 1;
3727 while(playtree_iter != NULL) {
3728 filename = play_tree_iter_get_file(playtree_iter,eof);
3729 if(filename == NULL) {
3730 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
3731 play_tree_iter_free(playtree_iter);
3732 playtree_iter = NULL;
3734 } else
3735 break;
3738 #ifdef HAVE_NEW_GUI
3739 if( use_gui && !playtree_iter )
3741 #ifdef USE_DVDREAD
3742 if ( !guiIntfStruct.DiskChanged )
3743 #endif
3744 mplEnd();
3746 #endif
3748 if(use_gui || playtree_iter != NULL){
3750 eof = 0;
3751 goto play_next_file;
3754 #ifdef HAVE_FREETYPE
3755 current_module="uninit_font";
3756 if (vo_font) free_font_desc(vo_font);
3757 vo_font = NULL;
3758 done_freetype();
3759 #endif
3761 exit_player_with_rc(MSGTR_Exit_eof, 0);
3763 return 1;