I420 support patch by Benjamin Zores <ben@tutuxclan.org>
[mplayer.git] / mplayer.c
blob144ad24ae8cc41d25fdc7d72c1608e52b8b7a3b1
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "config.h"
5 #ifdef WIN32
6 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
7 #include <windows.h>
8 #endif
9 #include <string.h>
10 #include <unistd.h>
12 // #include <sys/mman.h>
13 #include <sys/types.h>
14 #ifndef __MINGW32__
15 #include <sys/ioctl.h>
16 #include <sys/wait.h>
17 #else
18 #define SIGHUP 1 /* hangup */
19 #define SIGQUIT 3 /* quit */
20 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
21 #define SIGBUS 10 /* bus error */
22 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
23 #endif
25 #include <sys/time.h>
26 #include <sys/stat.h>
28 #include <signal.h>
29 #include <time.h>
30 #include <fcntl.h>
31 #include <limits.h>
33 #include <errno.h>
35 #include "version.h"
37 #include "mp_msg.h"
39 #define HELP_MP_DEFINE_STATIC
40 #include "help_mp.h"
42 #include "m_option.h"
43 #include "m_config.h"
45 #include "cfg-mplayer-def.h"
47 #ifdef USE_SUB
48 #include "subreader.h"
49 #endif
51 #include "libvo/video_out.h"
53 #include "libvo/font_load.h"
54 #include "libvo/sub.h"
56 #ifdef HAVE_X11
57 #include "libvo/x11_common.h"
58 #endif
60 #include "libao2/audio_out.h"
61 #include "libao2/audio_plugin.h"
63 #include "codec-cfg.h"
65 #ifdef USE_DVDNAV
66 #include <dvdnav.h>
67 #endif
69 #ifdef USE_EDL
70 #include "edl.h"
71 #endif
73 #include "spudec.h"
74 #include "vobsub.h"
76 #include "osdep/getch2.h"
77 #include "osdep/timer.h"
79 #include "cpudetect.h"
81 #ifdef HAVE_NEW_GUI
82 #include "Gui/interface.h"
83 #endif
85 #include "input/input.h"
87 int slave_mode=0;
88 int verbose=0;
89 int identify=0;
90 int quiet=0;
92 #define ABS(x) (((x)>=0)?(x):(-(x)))
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
95 #ifdef HAVE_RTC
96 #include <linux/rtc.h>
97 #endif
99 #ifdef USE_TV
100 #include "libmpdemux/tv.h"
101 #endif
103 #ifdef HAS_DVBIN_SUPPORT
104 #include "libmpdemux/dvbin.h"
105 static int last_dvb_step = 1;
106 #endif
108 //**************************************************************************//
109 // Playtree
110 //**************************************************************************//
111 #include "playtree.h"
112 #include "playtreeparser.h"
114 #ifdef HAVE_NEW_GUI
115 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
116 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
117 #endif
119 play_tree_t* playtree;
120 play_tree_iter_t* playtree_iter = NULL;
122 #define PT_NEXT_ENTRY 1
123 #define PT_PREV_ENTRY -1
124 #define PT_NEXT_SRC 2
125 #define PT_PREV_SRC -2
126 #define PT_UP_NEXT 3
127 #define PT_UP_PREV -3
129 //**************************************************************************//
130 // Config
131 //**************************************************************************//
132 m_config_t* mconfig;
134 extern play_tree_t*
135 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
136 extern int
137 m_config_parse_config_file(m_config_t* config, char *conffile);
139 //**************************************************************************//
140 // Config file
141 //**************************************************************************//
143 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
145 static int cfg_include(m_option_t *conf, char *filename){
146 return m_config_parse_config_file(mconfig, filename);
149 #include "get_path.c"
151 //**************************************************************************//
152 // XScreensaver
153 //**************************************************************************//
155 #ifdef HAVE_X11
156 void xscreensaver_heartbeat(void);
157 #endif
159 //**************************************************************************//
160 //**************************************************************************//
161 // Input media streaming & demultiplexer:
162 //**************************************************************************//
164 static int max_framesize=0;
166 #include "libmpdemux/stream.h"
167 #include "libmpdemux/demuxer.h"
168 #include "libmpdemux/stheader.h"
169 //#include "parse_es.h"
170 #ifdef HAVE_MATROSKA
171 #include "libmpdemux/matroska.h"
172 #endif
174 #include "libmpcodecs/dec_audio.h"
175 #include "libmpcodecs/dec_video.h"
176 #include "libmpcodecs/mp_image.h"
177 #include "libmpcodecs/vf.h"
179 extern void vf_list_plugins();
181 //**************************************************************************//
182 //**************************************************************************//
184 // Common FIFO functions, and keyboard/event FIFO code
185 #include "fifo.c"
186 int noconsolecontrols=0;
187 //**************************************************************************//
189 vo_functions_t *video_out=NULL;
190 ao_functions_t *audio_out=NULL;
192 int fixed_vo=0;
193 int eof=0;
195 // benchmark:
196 double video_time_usage=0;
197 double vout_time_usage=0;
198 static double audio_time_usage=0;
199 static int total_time_usage_start=0;
200 static int total_frame_cnt=0;
201 static int drop_frame_cnt=0; // total number of dropped frames
202 int benchmark=0;
204 // options:
205 int auto_quality=0;
206 static int output_quality=0;
208 float playback_speed=1.0;
210 int use_gui=0;
212 #ifdef HAVE_NEW_GUI
213 int enqueue=0;
214 #endif
216 #define MAX_OSD_LEVEL 3
218 int osd_level=1;
219 int osd_level_saved=-1;
220 int osd_visible=100;
222 // seek:
223 static char *seek_to_sec=NULL;
224 static off_t seek_to_byte=0;
225 static off_t step_sec=0;
226 static int loop_times=-1;
227 static int loop_seek=0;
229 // A/V sync:
230 int autosync=0; // 30 might be a good default value.
232 // may be changed by GUI: (FIXME!)
233 float rel_seek_secs=0;
234 int abs_seek_pos=0;
236 // codecs:
237 char **audio_codec_list=NULL; // override audio codec
238 char **video_codec_list=NULL; // override video codec
239 char **audio_fm_list=NULL; // override audio codec family
240 char **video_fm_list=NULL; // override video codec family
242 // streaming:
243 int audio_id=-1;
244 int video_id=-1;
245 int dvdsub_id=-1;
246 int vobsub_id=-1;
247 char* audio_lang=NULL;
248 char* dvdsub_lang=NULL;
249 static char* spudec_ifo=NULL;
250 char* filename=NULL; //"MI2-Trailer.avi";
251 int forced_subs_only=0;
253 // cache2:
254 int stream_cache_size=-1;
255 #ifdef USE_STREAM_CACHE
256 extern int cache_fill_status;
258 float stream_cache_min_percent=20.0;
259 float stream_cache_prefill_percent=5.0;
260 #else
261 #define cache_fill_status 0
262 #endif
264 // dump:
265 static char *stream_dump_name="stream.dump";
266 int stream_dump_type=0;
268 // A-V sync:
269 static float default_max_pts_correction=-1;//0.01f;
270 static float max_pts_correction=0;//default_max_pts_correction;
271 static float c_total=0;
272 float audio_delay=0;
274 static int softsleep=0;
276 float force_fps=0;
277 static int force_srate=0;
278 static int audio_output_format=0;
279 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
280 static int play_n_frames=-1;
281 static int play_n_frames_mf=-1;
283 // screen info:
284 char** video_driver_list=NULL;
285 char** audio_driver_list=NULL;
287 extern char *vo_subdevice;
288 extern char *ao_subdevice;
290 // codec outfmt flags (defined in libmpcodecs/vd.c)
291 extern int vo_flags;
293 // sub:
294 char *font_name=NULL;
295 #ifdef HAVE_FONTCONFIG
296 extern int font_fontconfig;
297 #endif
298 float font_factor=0.75;
299 char **sub_name=NULL;
300 float sub_delay=0;
301 float sub_fps=0;
302 int sub_auto = 1;
303 char *vobsub_name=NULL;
304 /*DSP!!char *dsp=NULL;*/
305 int subcc_enabled=0;
306 int suboverlap_enabled = 1;
307 #ifdef USE_SUB
308 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
309 int set_of_sub_size = 0;
310 int set_of_sub_pos = -1;
311 float sub_last_pts = -303;
312 #endif
313 int global_sub_size = 0; // this encompasses all subtitle sources
314 int global_sub_pos = -1; // this encompasses all subtitle sources
315 #define SUB_SOURCE_SUBS 0
316 #define SUB_SOURCE_VOBSUB 1
317 #define SUB_SOURCE_DEMUX 2
318 #define SUB_SOURCES 3
319 int global_sub_indices[SUB_SOURCES];
320 int global_sub_quiet_osd_hack = 0;
322 static stream_t* stream=NULL;
323 static demuxer_t *demuxer=NULL;
324 static sh_audio_t *sh_audio=NULL;
325 static sh_video_t *sh_video=NULL;
327 char* current_module=NULL; // for debugging
329 extern int vo_gamma_gamma;
330 extern int vo_gamma_brightness;
331 extern int vo_gamma_contrast;
332 extern int vo_gamma_saturation;
333 extern int vo_gamma_hue;
335 // ---
337 #ifdef HAVE_MENU
338 #include "m_struct.h"
339 #include "libmenu/menu.h"
340 extern void vf_menu_pause_update(struct vf_instance_s* vf);
341 extern vf_info_t vf_info_menu;
342 static vf_info_t* libmenu_vfs[] = {
343 &vf_info_menu,
344 NULL
346 static vf_instance_t* vf_menu = NULL;
347 static int use_menu = 0;
348 static char* menu_cfg = NULL;
349 static char* menu_root = "main";
350 #endif
353 #ifdef HAVE_RTC
354 static int nortc;
355 static char* rtc_device;
356 #endif
358 #ifdef USE_EDL
359 edl_record_ptr edl_records = NULL; /// EDL entries memory area
360 edl_record_ptr next_edl_record = NULL; /// only for traversing edl_records
361 int edl_memory_slots = 0; /// number of EDL entries (1 for skip + 2 for each mute)
362 int edl_operations = 0; /// number of EDL operations, skip + mute
363 short edl_decision = 0; /// 1 when an EDL operation has been made
364 FILE* edl_fd = NULL; /// fd to write to when in -edlout mode
365 int edl_mute_count = 0; /// even number when mute and unmute has been matched
366 #endif
368 static unsigned int inited_flags=0;
369 #define INITED_VO 1
370 #define INITED_AO 2
371 #define INITED_GUI 4
372 #define INITED_GETCH2 8
373 #define INITED_SPUDEC 32
374 #define INITED_STREAM 64
375 #define INITED_INPUT 128
376 #define INITED_VOBSUB 256
377 #define INITED_DEMUXER 512
378 #define INITED_ACODEC 1024
379 #define INITED_VCODEC 2048
380 #define INITED_ALL 0xFFFF
382 static void uninit_player(unsigned int mask){
383 mask=inited_flags&mask;
385 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
387 if(mask&INITED_ACODEC){
388 inited_flags&=~INITED_ACODEC;
389 current_module="uninit_acodec";
390 if(sh_audio) uninit_audio(sh_audio);
391 sh_audio=NULL;
394 if(mask&INITED_VCODEC){
395 inited_flags&=~INITED_VCODEC;
396 current_module="uninit_vcodec";
397 if(sh_video) uninit_video(sh_video);
398 sh_video=NULL;
399 #ifdef HAVE_MENU
400 vf_menu=NULL;
401 #endif
404 if(mask&INITED_DEMUXER){
405 inited_flags&=~INITED_DEMUXER;
406 current_module="free_demuxer";
407 if(demuxer){
408 stream=demuxer->stream;
409 free_demuxer(demuxer);
411 demuxer=NULL;
414 // kill the cache process:
415 if(mask&INITED_STREAM){
416 inited_flags&=~INITED_STREAM;
417 current_module="uninit_stream";
418 if(stream) free_stream(stream);
419 stream=NULL;
422 if(mask&INITED_VO){
423 inited_flags&=~INITED_VO;
424 current_module="uninit_vo";
425 video_out->uninit();
426 video_out=NULL;
429 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
430 if(mask&INITED_GETCH2){
431 inited_flags&=~INITED_GETCH2;
432 current_module="uninit_getch2";
433 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
434 // restore terminal:
435 getch2_disable();
438 if(mask&INITED_VOBSUB){
439 inited_flags&=~INITED_VOBSUB;
440 current_module="uninit_vobsub";
441 if(vo_vobsub) vobsub_close(vo_vobsub);
442 vo_vobsub=NULL;
445 if (mask&INITED_SPUDEC){
446 inited_flags&=~INITED_SPUDEC;
447 current_module="uninit_spudec";
448 spudec_free(vo_spudec);
449 vo_spudec=NULL;
452 if(mask&INITED_AO){
453 inited_flags&=~INITED_AO;
454 current_module="uninit_ao";
455 audio_out->uninit(eof?0:1); audio_out=NULL;
458 #ifdef HAVE_NEW_GUI
459 if(mask&INITED_GUI){
460 inited_flags&=~INITED_GUI;
461 current_module="uninit_gui";
462 guiDone();
464 #endif
466 if(mask&INITED_INPUT){
467 inited_flags&=~INITED_INPUT;
468 current_module="uninit_input";
469 mp_input_uninit();
472 current_module=NULL;
475 static void exit_player_with_rc(char* how, int rc){
477 uninit_player(INITED_ALL);
478 #ifdef HAVE_X11
479 #ifdef HAVE_NEW_GUI
480 if ( !use_gui )
481 #endif
482 vo_uninit(); // close the X11 connection (if any opened)
483 #endif
485 current_module="exit_player";
487 #ifdef USE_EDL
488 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
489 #endif
490 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));
491 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
493 exit(rc);
496 void exit_player(char* how){
497 exit_player_with_rc(how, 1);
500 #ifndef __MINGW32__
501 static void child_sighandler(int x){
502 pid_t pid;
503 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
505 #endif
507 static void exit_sighandler(int x){
508 static int sig_count=0;
509 ++sig_count;
510 if(inited_flags==0 && sig_count>1) exit(1);
511 if(sig_count==5)
513 /* We're crashing bad and can't uninit cleanly :(
514 * by popular request, we make one last (dirty)
515 * effort to restore the user's
516 * terminal. */
517 getch2_disable();
518 exit(1);
520 if(sig_count==6) exit(1);
521 if(sig_count>6){
522 // can't stop :(
523 #ifndef __MINGW32__
524 kill(getpid(),SIGKILL);
525 #endif
527 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
528 current_module?current_module:mp_gettext("unknown")
530 if(sig_count==1)
531 switch(x){
532 case SIGINT:
533 case SIGQUIT:
534 case SIGTERM:
535 case SIGKILL:
536 break; // killed from keyboard (^C) or killed [-9]
537 case SIGILL:
538 #ifdef RUNTIME_CPUDETECT
539 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
540 #else
541 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
542 #endif
543 case SIGFPE:
544 case SIGSEGV:
545 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
546 default:
547 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
549 exit_player(NULL);
552 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
554 extern void mp_input_register_options(m_config_t* cfg);
556 #include "mixer.h"
557 mixer_t mixer;
558 /// step size of mixer changes
559 int volstep = 3;
561 #include "cfg-mplayer.h"
563 void parse_cfgfiles( m_config_t* conf )
565 char *conffile;
566 int conffile_fd;
567 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
568 exit_player(NULL);
569 if ((conffile = get_path("")) == NULL) {
570 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
571 } else {
572 #ifdef __MINGW32__
573 mkdir(conffile);
574 #else
575 mkdir(conffile, 0777);
576 #endif
577 free(conffile);
578 if ((conffile = get_path("config")) == NULL) {
579 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
580 } else {
581 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
582 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
583 write(conffile_fd, default_config, strlen(default_config));
584 close(conffile_fd);
586 if (m_config_parse_config_file(conf, conffile) < 0)
587 exit_player(NULL);
588 free(conffile);
593 void load_per_file_config (m_config_t* conf, const char *const file)
595 char *confpath;
596 char cfg[strlen(file)+10];
597 struct stat st;
598 char *name;
600 sprintf (cfg, "%s.conf", file);
602 if (!stat (cfg, &st))
604 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
605 m_config_parse_config_file (conf, cfg);
606 return;
609 if ((name = strrchr (cfg, '/')) == NULL)
610 name = cfg;
611 else
612 name++;
614 if ((confpath = get_path (name)) != NULL)
616 if (!stat (confpath, &st))
618 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
619 m_config_parse_config_file (conf, confpath);
622 free (confpath);
626 // When libmpdemux perform a blocking operation (network connection or cache filling)
627 // if the operation fail we use this function to check if it was interrupted by the user.
628 // The function return a new value for eof.
629 static int libmpdemux_was_interrupted(int eof) {
630 mp_cmd_t* cmd;
631 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
632 switch(cmd->id) {
633 case MP_CMD_QUIT:
634 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
635 case MP_CMD_PLAY_TREE_STEP: {
636 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
637 } break;
638 case MP_CMD_PLAY_TREE_UP_STEP: {
639 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
640 } break;
641 case MP_CMD_PLAY_ALT_SRC_STEP: {
642 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
643 } break;
645 mp_cmd_free(cmd);
647 return eof;
650 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
651 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
653 int playtree_add_playlist(play_tree_t* entry)
655 play_tree_add_bpf(entry,filename);
657 #ifdef HAVE_NEW_GUI
658 if (use_gui) {
659 if (entry) {
660 import_playtree_playlist_into_gui(entry, mconfig);
661 play_tree_free_list(entry,1);
663 } else
664 #endif
666 if(!entry) {
667 entry = playtree_iter->tree;
668 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
669 return PT_NEXT_ENTRY;
671 if(playtree_iter->tree == entry ) { // Loop with a single file
672 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
673 return PT_NEXT_ENTRY;
676 play_tree_remove(entry,1,1);
677 return PT_NEXT_SRC;
679 play_tree_insert_entry(playtree_iter->tree,entry);
680 play_tree_set_params_from(entry,playtree_iter->tree);
681 entry = playtree_iter->tree;
682 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
683 return PT_NEXT_ENTRY;
685 play_tree_remove(entry,1,1);
687 return PT_NEXT_SRC;
690 static int play_tree_step = 1;
692 int sub_source()
694 int source = -1;
695 int top = -1;
696 int i;
697 for (i = 0; i < SUB_SOURCES; i++) {
698 int j = global_sub_indices[i];
699 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
700 source = i;
701 top = j;
704 return source;
707 #ifdef USE_SUB
709 sub_data* subdata = NULL;
711 void add_subtitles(char *filename, float fps, int silent)
713 sub_data *subd;
715 if (filename == NULL) {
716 return;
719 subd = sub_read_file(filename, fps);
720 if(!subd && !silent)
721 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
722 if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
723 set_of_subtitles[set_of_sub_size] = subd;
724 ++set_of_sub_size;
725 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
728 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
729 void update_set_of_subtitles()
730 // subdata was changed, set_of_sub... have to be updated.
732 int i;
733 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
734 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
735 set_of_subtitles[i-1] = set_of_subtitles[i];
736 set_of_subtitles[set_of_sub_size-1] = NULL;
737 --set_of_sub_size;
738 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
740 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
741 set_of_subtitles[set_of_sub_pos] = subdata;
743 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
744 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
745 ++set_of_sub_size;
748 #endif
751 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
752 * make it all work is to use the builtin SDL-bootstrap code, which
753 * will be done automatically by replacing our main() if we include SDL.h.
755 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
756 #include <SDL.h>
757 #endif
760 int main(int argc,char* argv[]){
763 char * mem_ptr;
765 static demux_stream_t *d_audio=NULL;
766 static demux_stream_t *d_video=NULL;
767 static demux_stream_t *d_dvdsub=NULL;
769 int file_format=DEMUXER_TYPE_UNKNOWN;
771 int delay_corrected=1;
773 // movie info:
775 int osd_function=OSD_PLAY;
776 int osd_last_pts=-303;
777 int osd_show_av_delay = 0;
778 int osd_show_text = 0;
779 int osd_show_sub_delay = 0;
780 int osd_show_sub_pos = 0;
781 int osd_show_sub_visibility = 0;
782 int osd_show_sub_alignment = 0;
783 int osd_show_vobsub_changed = 0;
784 int osd_show_sub_changed = 0;
785 int osd_show_percentage = 0;
786 int osd_show_tv_channel = 25;
787 int osd_show_ontop = 0;
788 int osd_show_rootwin = 0;
789 int osd_show_framedropping = 0;
791 int rtc_fd=-1;
793 //float a_frame=0; // Audio
795 int i;
796 char *tmp;
798 int gui_no_filename=0;
801 srand((int) time(NULL));
803 mp_msg_init();
804 mp_msg_set_level(MSGL_STATUS);
806 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2004 MPlayer Team\n\n");
807 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
808 GetCpuCaps(&gCpuCaps);
809 #ifdef ARCH_X86
810 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
811 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
812 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
813 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
814 #ifdef RUNTIME_CPUDETECT
815 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
816 #else
817 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
818 #ifdef HAVE_MMX
819 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
820 #endif
821 #ifdef HAVE_MMX2
822 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
823 #endif
824 #ifdef HAVE_3DNOW
825 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
826 #endif
827 #ifdef HAVE_3DNOWEX
828 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
829 #endif
830 #ifdef HAVE_SSE
831 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
832 #endif
833 #ifdef HAVE_SSE2
834 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
835 #endif
836 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
837 #endif
838 #endif
840 #if defined(WIN32) && defined(USE_WIN32DLL)
841 { /*make our codec dirs available for LoadLibraryA()*/
842 char tmppath[MAX_PATH*2 + 1];
843 char win32path[MAX_PATH];
844 char realpath[MAX_PATH];
845 #ifdef __CYGWIN__
846 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
847 strcpy(tmppath,win32path);
848 #ifdef USE_REALCODECS
849 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
850 sprintf(tmppath,"%s;%s",win32path,realpath);
851 #endif /*USE_REALCODECS*/
852 #else
853 if(!strstr(WIN32_PATH,":")){
854 GetModuleFileNameA(NULL, win32path, MAX_PATH);
855 strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);
857 else strcpy(win32path,WIN32_PATH);
858 strcpy(tmppath,win32path);
859 #ifdef USE_REALCODECS
860 if(!strstr(REALCODEC_PATH,":")){
861 GetModuleFileNameA(NULL, realpath, MAX_PATH);
862 strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);
864 else strcpy(realpath,REALCODEC_PATH);
865 sprintf(tmppath,"%s;%s",win32path,realpath);
866 #endif /*USE_REALCODECS*/
867 #endif /*__CYGWIN__*/
868 SetEnvironmentVariableA("PATH", tmppath);
870 #endif /*WIN32 && USE_WIN32DLL*/
872 #ifdef USE_TV
873 tv_param_immediate = 1;
874 #endif
876 if ( argv[0] )
877 if(!strcmp(argv[0],"gmplayer") ||
878 (strrchr(argv[0],'/') && !strcmp(strrchr(argv[0],'/'),"/gmplayer") ) )
879 use_gui=1;
881 mconfig = m_config_new();
882 m_config_register_options(mconfig,mplayer_opts);
883 // TODO : add something to let modules register their options
884 mp_input_register_options(mconfig);
885 parse_cfgfiles(mconfig);
887 #ifdef HAVE_NEW_GUI
888 if ( use_gui ) cfg_read();
889 #endif
891 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
892 if(playtree == NULL)
893 exit_player(NULL);
895 playtree = play_tree_cleanup(playtree);
896 if(playtree) {
897 playtree_iter = play_tree_iter_new(playtree,mconfig);
898 if(playtree_iter) {
899 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
900 play_tree_iter_free(playtree_iter);
901 playtree_iter = NULL;
903 filename = play_tree_iter_get_file(playtree_iter,1);
907 #ifndef HAVE_NEW_GUI
908 if(use_gui){
909 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
910 use_gui=0;
912 #else
913 if(use_gui && !vo_init()){
914 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
915 use_gui=0;
917 if (use_gui && playtree_iter){
918 char cwd[PATH_MAX+2];
919 // Remove Playtree and Playtree-Iter from memory as its not used by gui
920 play_tree_iter_free(playtree_iter);
921 playtree_iter=NULL;
923 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
925 strcat(cwd, "/");
926 // Prefix relative paths with current working directory
927 play_tree_add_bpf(playtree, cwd);
929 // Import initital playtree into gui
930 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
932 #endif
934 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
935 list_video_out();
936 exit_player_with_rc(NULL, 0);
939 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
940 list_audio_out();
941 exit_player_with_rc(NULL, 0);
944 // check codec.conf
945 if(!codecs_file || !parse_codec_cfg(codecs_file)){
946 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
947 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
948 if(!parse_codec_cfg(NULL)){
949 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
950 exit_player_with_rc(NULL, 0);
952 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_BuiltinCodecsConf);
955 free( mem_ptr ); // release the buffer created by get_path()
958 #if 0
959 if(video_codec_list){
960 int i;
961 video_codec=video_codec_list[0];
962 for(i=0;video_codec_list[i];i++)
963 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
965 #endif
966 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
967 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
968 list_codecs(1);
969 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
970 exit_player_with_rc(NULL, 0);
972 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
973 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
974 list_codecs(0);
975 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
976 exit_player_with_rc(NULL, 0);
978 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
979 vfm_help();
980 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
981 exit_player_with_rc(NULL, 0);
983 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
984 afm_help();
985 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
986 exit_player_with_rc(NULL, 0);
988 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
989 af_help();
990 printf("\n");
991 exit_player_with_rc(NULL, 0);
993 #ifdef HAVE_X11
994 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
995 fstype_help();
996 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
997 exit_player_with_rc(NULL, 0);
999 #endif
1001 #ifdef USE_EDL
1002 if (edl_check_mode() == EDL_ERROR && edl_filename)
1004 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantUseBothModes);
1005 exit_player(NULL);
1006 } else if (edl_filename)
1008 edl_memory_slots = edl_count_entries();
1009 if (edl_memory_slots > 0)
1011 edl_records = calloc(edl_memory_slots, sizeof(struct edl_record));
1012 if (edl_records == NULL)
1014 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_EdlOutOfMem);
1015 exit_player(NULL);
1016 } else
1018 if ((edl_operations = edl_parse_file(edl_records)) > 0)
1020 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlRecordsNo,
1021 edl_operations);
1022 } else
1025 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlQueueEmpty);
1030 next_edl_record = edl_records;
1032 } else if (edl_output_filename)
1034 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
1036 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
1037 edl_output_filename);
1038 exit_player(NULL);
1041 #endif
1043 if(!filename){
1044 if(!use_gui){
1045 // no file/vcd/dvd -> show HELP:
1046 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
1047 exit_player_with_rc(NULL, 0);
1048 } else gui_no_filename=1;
1051 // Many users forget to include command line in bugreports...
1052 if(verbose>0){
1053 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
1054 for(i=1;i<argc;i++)mp_msg(MSGT_FIXME, MSGL_FIXME," '%s'",argv[i]);
1055 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
1058 mp_msg_set_level(verbose+MSGL_STATUS);
1060 //------ load global data first ------
1062 // check font
1063 #ifdef USE_OSD
1064 #ifdef HAVE_FREETYPE
1065 init_freetype();
1066 #endif
1067 #ifdef HAVE_FONTCONFIG
1068 if(!font_fontconfig)
1070 #endif
1071 if(font_name){
1072 vo_font=read_font_desc(font_name,font_factor,verbose>1);
1073 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
1074 } else {
1075 // try default:
1076 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
1077 free(mem_ptr); // release the buffer created by get_path()
1078 if(!vo_font)
1079 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
1081 #ifdef HAVE_FONTCONFIG
1083 #endif
1084 #endif
1085 vo_init_osd();
1087 #ifdef HAVE_RTC
1088 if(!nortc)
1090 // seteuid(0); /* Can't hurt to try to get root here */
1091 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
1092 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
1093 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
1094 else {
1095 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
1097 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
1098 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
1099 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
1100 close (rtc_fd);
1101 rtc_fd = -1;
1102 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
1103 /* variable only by the root */
1104 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
1105 close (rtc_fd);
1106 rtc_fd = -1;
1107 } else
1108 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_UsingRTCTiming, irqp);
1111 #ifdef HAVE_NEW_GUI
1112 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1113 // and now ? -- Pontscho
1114 if(use_gui) setuid( getuid() ); // strongly test, please check this.
1115 #endif
1116 if(rtc_fd<0)
1117 #endif
1118 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Using %s timing\n",
1119 softsleep?"software":timer_name);
1121 #ifdef USE_TERMCAP
1122 if ( !use_gui ) load_termcap(NULL); // load key-codes
1123 #endif
1125 // ========== Init keyboard FIFO (connection to libvo) ============
1127 // Init input system
1128 current_module = "init_input";
1129 mp_input_init();
1130 #ifndef HAVE_NO_POSIX_SELECT
1131 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
1133 if(keyb_fifo_get > 0)
1134 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
1135 #else
1136 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
1137 #endif
1138 if(slave_mode)
1139 #ifndef __MINGW32__
1140 mp_input_add_cmd_fd(0,1,NULL,NULL);
1141 #else
1142 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
1143 #endif
1144 else if(!noconsolecontrols)
1145 #ifndef HAVE_NO_POSIX_SELECT
1146 mp_input_add_key_fd(0,1,NULL,NULL);
1147 #else
1148 mp_input_add_key_fd(0,0,NULL,NULL);
1149 #endif
1151 inited_flags|=INITED_INPUT;
1152 current_module = NULL;
1154 #ifdef HAVE_MENU
1155 if(use_menu) {
1156 if(menu_cfg && menu_init(menu_cfg))
1157 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1158 else {
1159 menu_cfg = get_path("menu.conf");
1160 if(menu_init(menu_cfg))
1161 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
1162 else {
1163 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
1164 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
1165 else {
1166 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
1167 use_menu = 0;
1172 #endif
1174 /// Catch signals
1175 #ifndef __MINGW32__
1176 signal(SIGCHLD,child_sighandler);
1177 #endif
1179 //========= Catch terminate signals: ================
1180 // terminate requests:
1181 signal(SIGTERM,exit_sighandler); // kill
1182 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
1184 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
1186 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
1187 #ifdef ENABLE_SIGHANDLER
1188 // fatal errors:
1189 signal(SIGBUS,exit_sighandler); // bus error
1190 signal(SIGSEGV,exit_sighandler); // segfault
1191 signal(SIGILL,exit_sighandler); // illegal instruction
1192 signal(SIGFPE,exit_sighandler); // floating point exc.
1193 signal(SIGABRT,exit_sighandler); // abort()
1194 #endif
1196 #ifdef HAVE_NEW_GUI
1197 if(use_gui){
1198 guiInit();
1199 inited_flags|=INITED_GUI;
1200 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
1202 #endif
1204 // ******************* Now, let's see the per-file stuff ********************
1206 play_next_file:
1208 // init global sub numbers
1209 global_sub_size = 0;
1210 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
1211 global_sub_quiet_osd_hack = 1;
1213 if (filename) load_per_file_config (mconfig, filename);
1215 // We must enable getch2 here to be able to interrupt network connection
1216 // or cache filling
1217 if(!noconsolecontrols && !slave_mode){
1218 if(inited_flags&INITED_GETCH2)
1219 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
1220 else
1221 getch2_enable(); // prepare stdin for hotkeys...
1222 inited_flags|=INITED_GETCH2;
1223 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
1226 // =================== GUI idle loop (STOP state) ===========================
1227 #ifdef HAVE_NEW_GUI
1228 if ( use_gui ) {
1229 file_format=DEMUXER_TYPE_UNKNOWN;
1230 guiGetEvent( guiSetDefaults,0 );
1231 while ( guiIntfStruct.Playing != 1 )
1233 mp_cmd_t* cmd;
1234 usec_sleep(20000);
1235 guiEventHandling();
1236 guiGetEvent( guiReDraw,NULL );
1237 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
1239 guiGetEvent( guiSetParameters,NULL );
1240 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
1242 play_tree_t * entry = play_tree_new();
1243 play_tree_add_file( entry,guiIntfStruct.Filename );
1244 if ( playtree ) play_tree_free_list( playtree->child,1 );
1245 else playtree=play_tree_new();
1246 play_tree_set_child( playtree,entry );
1247 if(playtree)
1249 playtree_iter = play_tree_iter_new(playtree,mconfig);
1250 if(playtree_iter)
1252 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
1254 play_tree_iter_free(playtree_iter);
1255 playtree_iter = NULL;
1257 filename = play_tree_iter_get_file(playtree_iter,1);
1262 #endif
1263 //---------------------------------------------------------------------------
1265 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
1266 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
1268 //==================== Open VOB-Sub ============================
1270 current_module="vobsub";
1271 if (vobsub_name){
1272 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
1273 if(vo_vobsub==NULL)
1274 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
1275 }else if(sub_auto && filename && (strlen(filename)>=5)){
1276 /* try to autodetect vobsub from movie filename ::atmos */
1277 char *buf = malloc((strlen(filename)-3) * sizeof(char));
1278 memset(buf,0,strlen(filename)-3); // make sure string is terminated
1279 strncpy(buf, filename, strlen(filename)-4);
1280 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
1281 free(buf);
1283 if(vo_vobsub){
1284 inited_flags|=INITED_VOBSUB;
1285 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
1286 // check if vobsub requested only to display forced subtitles
1287 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
1289 // setup global sub numbering
1290 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
1291 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
1294 //============ Open & Sync STREAM --- fork cache2 ====================
1296 stream=NULL;
1297 demuxer=NULL;
1298 if (d_audio) {
1299 //free_demuxer_stream(d_audio);
1300 d_audio=NULL;
1302 if (d_video) {
1303 //free_demuxer_stream(d_video);
1304 d_video=NULL;
1306 sh_audio=NULL;
1307 sh_video=NULL;
1309 current_module="open_stream";
1310 stream=open_stream(filename,0,&file_format);
1311 if(!stream) { // error...
1312 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
1313 goto goto_next_file;
1315 inited_flags|=INITED_STREAM;
1317 #ifdef HAVE_NEW_GUI
1318 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
1319 #endif
1321 if(file_format == DEMUXER_TYPE_PLAYLIST) {
1322 play_tree_t* entry;
1323 // Handle playlist
1324 current_module="handle_playlist";
1325 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
1326 entry = parse_playtree(stream,0);
1327 eof=playtree_add_playlist(entry);
1328 goto goto_next_file;
1330 stream->start_pos+=seek_to_byte;
1332 if(stream_dump_type==5){
1333 unsigned char buf[4096];
1334 int len;
1335 FILE *f;
1336 current_module="dumpstream";
1337 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
1338 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
1339 exit_player(MSGTR_Exit_error);
1341 stream_reset(stream);
1342 stream_seek(stream,stream->start_pos);
1343 f=fopen(stream_dump_name,"wb");
1344 if(!f){
1345 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1346 exit_player(MSGTR_Exit_error);
1348 while(!stream->eof){
1349 len=stream_read(stream,buf,4096);
1350 if(len>0) {
1351 if(fwrite(buf,len,1,f) != 1) {
1352 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1353 exit_player(MSGTR_Exit_error);
1357 if(fclose(f)) {
1358 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
1359 exit_player(MSGTR_Exit_error);
1361 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1362 exit_player_with_rc(MSGTR_Exit_eof, 0);
1365 #ifdef USE_DVDREAD
1366 if(stream->type==STREAMTYPE_DVD){
1367 current_module="dvd lang->id";
1368 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
1369 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
1370 // setup global sub numbering
1371 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1372 global_sub_size += dvd_number_of_subs(stream);
1373 current_module=NULL;
1375 #endif
1377 #ifdef USE_DVDNAV
1378 if (stream->type==STREAMTYPE_DVDNAV) stream_cache_size=0; // must disable caching...
1379 #endif
1381 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1382 #ifdef HAS_DVBIN_SUPPORT
1383 goto_enable_cache:
1384 #endif
1385 if(stream_cache_size>0){
1386 current_module="enable_cache";
1387 if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024*(stream_cache_min_percent / 100.0),stream_cache_size*1024*(stream_cache_prefill_percent / 100.0)))
1388 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
1391 //============ Open DEMUXERS --- DETECT file type =======================
1392 current_module="demux_open";
1394 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
1396 // HACK to get MOV Reference Files working
1398 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
1400 unsigned char* playlist_entry;
1401 play_tree_t *list = NULL, *entry = NULL;
1403 current_module="handle_demux_playlist";
1404 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
1406 char *temp, *bname;
1408 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
1410 bname=mp_basename(playlist_entry);
1411 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
1412 continue;
1414 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
1415 continue;
1417 entry = play_tree_new();
1419 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
1421 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
1422 if (temp)
1424 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
1425 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
1426 strcat(temp, playlist_entry);
1427 play_tree_add_file(entry,temp);
1428 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
1429 free(temp);
1432 else
1433 play_tree_add_file(entry,playlist_entry);
1435 if(!list)
1436 list = entry;
1437 else
1438 play_tree_append_entry(list,entry);
1440 free_demuxer(demuxer);
1441 demuxer = NULL;
1443 if (list)
1445 entry = play_tree_new();
1446 play_tree_set_child(entry,list);
1447 eof=playtree_add_playlist(entry);
1448 goto goto_next_file;
1452 if(!demuxer)
1454 #if 0
1455 play_tree_t* entry;
1456 // Handle playlist
1457 current_module="handle_playlist";
1458 switch(stream->type){
1459 case STREAMTYPE_VCD:
1460 case STREAMTYPE_DVD:
1461 case STREAMTYPE_DVDNAV:
1462 case STREAMTYPE_CDDA:
1463 case STREAMTYPE_VCDBINCUE:
1464 // don't try to parse raw media as playlist, it's unlikely
1465 goto goto_next_file;
1467 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
1468 stream_reset(stream);
1469 stream_seek(stream,stream->start_pos);
1470 entry = parse_playtree(stream,0);
1471 if(!entry)
1472 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
1473 else
1474 eof=playtree_add_playlist(entry);
1475 #endif
1476 goto goto_next_file;
1478 inited_flags|=INITED_DEMUXER;
1480 #ifdef HAVE_MATROSKA
1481 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
1482 // setup global sub numbering
1483 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1484 global_sub_size += demux_mkv_num_subs(demuxer);
1486 #endif
1487 #ifdef HAVE_OGGVORBIS
1488 if (demuxer->type==DEMUXER_TYPE_OGG) {
1489 // setup global sub numbering
1490 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
1491 global_sub_size += demux_ogg_num_subs(demuxer);
1493 #endif
1495 current_module="demux_open2";
1497 //file_format=demuxer->file_format;
1499 d_audio=demuxer->audio;
1500 d_video=demuxer->video;
1501 d_dvdsub=demuxer->sub;
1503 // DUMP STREAMS:
1504 if((stream_dump_type)&&(stream_dump_type<4)){
1505 FILE *f;
1506 demux_stream_t *ds=NULL;
1507 current_module="dump";
1508 // select stream to dump
1509 switch(stream_dump_type){
1510 case 1: ds=d_audio;break;
1511 case 2: ds=d_video;break;
1512 case 3: ds=d_dvdsub;break;
1514 if(!ds){
1515 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
1516 exit_player(MSGTR_Exit_error);
1518 // disable other streams:
1519 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
1520 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
1521 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
1522 // let's dump it!
1523 f=fopen(stream_dump_name,"wb");
1524 if(!f){
1525 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
1526 exit_player(MSGTR_Exit_error);
1528 while(!ds->eof){
1529 unsigned char* start;
1530 int in_size=ds_get_packet(ds,&start);
1531 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
1532 && stream_dump_type==2) fwrite(&in_size,1,4,f);
1533 if(in_size>0) fwrite(start,in_size,1,f);
1535 fclose(f);
1536 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
1537 exit_player_with_rc(MSGTR_Exit_eof, 0);
1540 sh_audio=d_audio->sh;
1541 sh_video=d_video->sh;
1543 if(sh_video){
1545 current_module="video_read_properties";
1546 if(!video_read_properties(sh_video)) {
1547 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
1548 sh_video=d_video->sh=NULL;
1549 } else {
1550 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1551 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
1552 sh_video->fps,sh_video->frametime
1555 /* need to set fps here for output encoders to pick it up in their init */
1556 if(force_fps){
1557 sh_video->fps=force_fps;
1558 sh_video->frametime=1.0f/sh_video->fps;
1560 vo_fps = sh_video->fps;
1561 #ifdef HAVE_X11
1562 vo_mouse_timer_const=(int)sh_video->fps;
1563 #endif
1565 if(!sh_video->fps && !force_fps){
1566 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
1567 sh_video=d_video->sh=NULL;
1573 fflush(stdout);
1575 if(!sh_video && !sh_audio){
1576 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
1577 #ifdef HAS_DVBIN_SUPPORT
1578 if((stream->type == STREAMTYPE_DVB) && stream->priv)
1580 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
1581 if(priv->is_on)
1583 int dir;
1584 int v = last_dvb_step;
1585 if(v > 0)
1586 dir = DVB_CHANNEL_HIGHER;
1587 else
1588 dir = DVB_CHANNEL_LOWER;
1590 if(dvb_step_channel(priv, dir))
1592 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
1593 cache_uninit(stream);
1594 goto goto_enable_cache;
1598 #endif
1599 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1602 /* display clip info */
1603 demux_info_print(demuxer);
1605 //================== Read SUBTITLES (DVD & TEXT) ==========================
1606 if(vo_spudec==NULL && sh_video && (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA)){
1608 if (spudec_ifo) {
1609 unsigned int palette[16], width, height;
1610 current_module="spudec_init_vobsub";
1611 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1612 vo_spudec=spudec_new_scaled(palette, width, height);
1615 #ifdef USE_DVDNAV
1616 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1617 current_module="spudec_init_dvdnav";
1618 vo_spudec=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t*)(stream->priv)),
1619 sh_video->disp_w, sh_video->disp_h);
1621 #endif
1623 #ifdef USE_DVDREAD
1624 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1625 current_module="spudec_init_dvdread";
1626 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1627 sh_video->disp_w, sh_video->disp_h);
1629 #endif
1631 #ifdef HAVE_MATROSKA
1632 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1633 (d_dvdsub->sh != NULL) && (((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1634 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
1635 current_module = "spudec_init_matroska";
1636 vo_spudec =
1637 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1638 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1639 mkv_sh_sub->height);
1640 forced_subs_only = mkv_sh_sub->forced_subs_only;
1642 #endif
1644 if (vo_spudec==NULL) {
1645 current_module="spudec_init_normal";
1646 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
1647 spudec_set_font_factor(vo_spudec,font_factor);
1650 if (vo_spudec!=NULL)
1651 inited_flags|=INITED_SPUDEC;
1655 // Apply current settings for forced subs
1656 if (vo_spudec!=NULL)
1657 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1659 #ifdef USE_SUB
1660 if(sh_video) {
1661 // after reading video params we should load subtitles because
1662 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1663 // check .sub
1664 current_module="read_subtitles_file";
1665 if(sub_name){
1666 for (i = 0; sub_name[i] != NULL; ++i)
1667 add_subtitles (sub_name[i], sh_video->fps, 0);
1669 if(sub_auto) { // auto load sub file ...
1670 char *psub = get_path( "sub/" );
1671 char **tmp = sub_filenames((psub ? psub : ""), filename);
1672 char **tmp2 = tmp;
1673 free(psub); // release the buffer created by get_path() above
1674 while (*tmp2)
1675 add_subtitles (*tmp2++, sh_video->fps, 0);
1676 free(tmp);
1677 if (set_of_sub_size == 0)
1679 add_subtitles (mem_ptr=get_path("default.sub"), sh_video->fps, 1);
1680 free(mem_ptr); // release the buffer created by get_path()
1682 if (set_of_sub_size > 0)
1683 add_subtitles (NULL, sh_video->fps, 1);
1685 if (set_of_sub_size > 0) {
1686 // setup global sub numbering
1687 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
1688 global_sub_size += set_of_sub_size;
1691 #endif
1693 if (global_sub_size) {
1694 // find the best sub to use
1695 if (vobsub_id >= 0) {
1696 // if user asks for a vobsub id, use that first.
1697 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
1698 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1699 // if user asks for a dvd sub id, use that next.
1700 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
1701 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
1702 // if there are text subs to use, use those. (autosubs come last here)
1703 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
1705 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1706 // if nothing else works, get subs from the demuxer.
1707 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1709 } else {
1710 // nothing worth doing automatically.
1711 global_sub_pos = -1;
1713 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1714 global_sub_pos--;
1715 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1718 //================== Init AUDIO (codec) ==========================
1719 if(sh_audio){
1720 // Go through the codec.conf and find the best codec...
1721 current_module="init_audio_codec";
1722 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1723 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
1724 sh_audio=d_audio->sh=NULL; // failed to init :(
1725 } else
1726 inited_flags|=INITED_ACODEC;
1727 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1730 if(identify) {
1731 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_FILENAME=%s\n", filename);
1732 if (sh_video) {
1733 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1734 if (sh_video->format >= 0x20202020)
1735 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", &sh_video->format);
1736 else
1737 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
1738 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
1739 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
1740 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
1741 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
1742 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
1744 if (sh_audio) {
1745 if (sh_audio->codec)
1746 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
1747 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1748 if (sh_audio->format >= 0x20202020)
1749 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio->format);
1750 else
1751 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
1752 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
1753 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
1754 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
1756 mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer));
1759 if(!sh_video) goto main; // audio-only
1761 //================== Init VIDEO (codec & libvo) ==========================
1762 if(!fixed_vo || !(inited_flags&INITED_VO)){
1763 current_module="preinit_libvo";
1765 vo_config_count=0;
1766 //if((video_out->preinit(vo_subdevice))!=0){
1767 if(!(video_out=init_best_video_out(video_driver_list))){
1768 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
1769 goto goto_next_file; // exit_player(MSGTR_Exit_error);
1771 sh_video->video_out=video_out;
1772 inited_flags|=INITED_VO;
1775 current_module="init_video_filters";
1777 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
1778 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
1780 #ifdef HAVE_MENU
1781 if(use_menu) {
1782 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
1783 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
1784 if(!vf_menu) {
1785 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
1786 use_menu = 0;
1789 if(vf_menu)
1790 sh_video->vfilter=(void*)append_filters(vf_menu);
1791 else
1792 #endif
1793 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
1795 current_module="init_video_codec";
1797 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1798 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
1799 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
1801 if(!sh_video->inited){
1802 if(!fixed_vo) uninit_player(INITED_VO);
1803 if(!sh_audio) goto goto_next_file;
1804 sh_video = d_video->sh = NULL;
1805 goto main; // exit_player(MSGTR_Exit_error);
1808 inited_flags|=INITED_VCODEC;
1810 if(auto_quality>0){
1811 // Auto quality option enabled
1812 output_quality=get_video_quality_max(sh_video);
1813 if(auto_quality>output_quality) auto_quality=output_quality;
1814 else output_quality=auto_quality;
1815 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
1816 set_video_quality(sh_video,output_quality);
1819 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1821 current_module="init_vo";
1823 if(vo_flags & 0x08 && vo_spudec)
1824 spudec_set_hw_spu(vo_spudec,video_out);
1826 #ifdef HAVE_FREETYPE
1827 force_load_font = 1;
1828 #endif
1830 //================== MAIN: ==========================
1831 main:
1832 current_module="main";
1834 // If there is no video OSD has to be disabled.
1835 // In case of playing a playtree we have to restore the
1836 // old OSD level after playing one or more audio-only files.
1837 if(!sh_video && osd_level >= 0) { // save OSD level only once
1838 osd_level_saved = osd_level;
1839 osd_level = 0;
1840 } else if (osd_level_saved > -1) { // if there is a saved OSD level, restore it
1841 osd_level = osd_level_saved;
1842 osd_level_saved = -1;
1845 fflush(stdout);
1847 #ifdef HAVE_NEW_GUI
1848 if ( use_gui )
1850 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
1851 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
1852 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
1853 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
1854 guiGetEvent( guiSetDemuxer,(char *)demuxer );
1856 #endif
1859 //int frame_corr_num=0; //
1860 //float v_frame=0; // Video
1861 float time_frame=0; // Timer
1862 //float num_frames=0; // number of frames played
1863 int grab_frames=0;
1864 char osd_text_buffer[64];
1865 char osd_show_text_buffer[64];
1866 int drop_frame=0; // current dropping status
1867 int dropped_frames=0; // how many frames dropped since last non-dropped frame
1868 int too_slow_frame_cnt=0;
1869 int too_fast_frame_cnt=0;
1870 // for auto-quality:
1871 float AV_delay=0; // average of A-V timestamp differences
1872 double vdecode_time;
1873 unsigned int lastframeout_ts=0;
1874 /*float time_frame_corr_avg=0;*/ /* unused */
1876 float next_frame_time=0;
1877 int frame_time_remaining=0; // flag
1878 int blit_frame=0;
1880 osd_text_buffer[0]=0;
1882 //================ SETUP AUDIO ==========================
1884 if(sh_audio){
1885 //const ao_info_t *info=audio_out->info;
1886 current_module="af_preinit";
1887 ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*playback_speed;
1888 ao_data.channels=audio_output_channels?audio_output_channels:sh_audio->channels;
1889 ao_data.format=audio_output_format?audio_output_format:sh_audio->sample_format;
1890 #if 1
1891 if(!preinit_audio_filters(sh_audio,
1892 // input:
1893 (int)(sh_audio->samplerate*playback_speed),
1894 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
1895 // output:
1896 &ao_data.samplerate, &ao_data.channels, &ao_data.format,
1897 audio_out_format_bits(ao_data.format)/8)){
1898 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
1899 } else {
1900 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AF_pre: %dHz %dch %s\n",
1901 ao_data.samplerate, ao_data.channels,
1902 audio_out_format_name(ao_data.format));
1904 #endif
1905 current_module="ao2_init";
1906 if(!(audio_out=init_best_audio_out(audio_driver_list,
1907 (ao_plugin_cfg.plugin_list!=NULL), // plugin flag
1908 force_srate?force_srate:ao_data.samplerate,
1909 audio_output_channels?audio_output_channels:ao_data.channels,
1910 audio_output_format?audio_output_format:ao_data.format,0))){
1911 // FAILED:
1912 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
1913 uninit_player(INITED_ACODEC); // close codec
1914 sh_audio=d_audio->sh=NULL; // -> nosound
1915 } else {
1916 // SUCCESS:
1917 inited_flags|=INITED_AO;
1918 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n",
1919 audio_out->info->short_name,
1920 ao_data.samplerate, ao_data.channels,
1921 audio_out_format_name(ao_data.format),
1922 audio_out_format_bits(ao_data.format)/8 );
1923 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
1924 audio_out->info->name, audio_out->info->author);
1925 if(strlen(audio_out->info->comment) > 0)
1926 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
1927 // init audio filters:
1928 #if 1
1929 current_module="af_init";
1930 if(!init_audio_filters(sh_audio,
1931 (int)(sh_audio->samplerate*playback_speed),
1932 sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
1933 ao_data.samplerate, ao_data.channels, ao_data.format,
1934 audio_out_format_bits(ao_data.format)/8, /* ao_data.bps, */
1935 ao_data.outburst*4, ao_data.buffersize)){
1936 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
1937 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1938 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1939 // sh_audio=d_audio->sh=NULL; // -> nosound
1941 #endif
1943 mixer.audio_out = audio_out;
1944 mixer.afilter = sh_audio ? sh_audio->afilter : NULL;
1945 mixer.volstep = volstep;
1948 current_module="av_init";
1950 if(sh_video) sh_video->timer=0;
1951 if(sh_audio) sh_audio->delay=-audio_delay;
1953 if(!sh_audio){
1954 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
1955 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %s unused audio chunks.\n",d_audio->packs);
1956 ds_free_packs(d_audio); // free buffered chunks
1957 d_audio->id=-2; // do not read audio chunks
1958 //uninit_player(INITED_AO); // close device
1960 if(!sh_video){
1961 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
1962 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %s unused video chunks.\n",d_video->packs);
1963 ds_free_packs(d_video);
1964 d_video->id=-2;
1965 //if(!fixed_vo) uninit_player(INITED_VO);
1968 if (!sh_video && !sh_audio)
1969 goto goto_next_file;
1971 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
1972 if(force_fps && sh_video){
1973 vo_fps = sh_video->fps=force_fps;
1974 sh_video->frametime=1.0f/sh_video->fps;
1975 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
1978 //==================== START PLAYING =======================
1980 if(loop_times>1) loop_times--; else
1981 if(loop_times==1) loop_times = -1;
1983 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
1985 InitTimer();
1987 #ifdef USE_DVDNAV
1988 if (stream->type==STREAMTYPE_DVDNAV) {
1989 dvdnav_stream_fullstart((dvdnav_priv_t *)stream->priv);
1991 #endif
1993 total_time_usage_start=GetTimer();
1994 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
1995 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
1996 play_n_frames=play_n_frames_mf;
1998 if(play_n_frames==0){
1999 eof=PT_NEXT_ENTRY; goto goto_next_file;
2002 while(!eof){
2003 float aq_sleep_time=0;
2005 if(play_n_frames>=0){
2006 --play_n_frames;
2007 if(play_n_frames<0) eof = PT_NEXT_ENTRY;
2010 /*========================== PLAY AUDIO ============================*/
2012 while(sh_audio){
2013 unsigned int t;
2014 double tt;
2015 int playsize;
2017 current_module="play_audio";
2019 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2020 playsize=audio_out->get_space();
2022 // handle audio-only case:
2023 if(!playsize && !sh_video) { // buffer is full, do not block here!!!
2024 usec_sleep(10000); // Wait a tick before retry
2025 continue;
2028 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
2030 // Fill buffer if needed:
2031 current_module="decode_audio"; // Enter AUDIO decoder module
2032 t=GetTimer();
2033 while(sh_audio->a_out_buffer_len<playsize && !d_audio->eof){
2034 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
2035 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
2036 if(ret<=0) break; // EOF?
2037 sh_audio->a_out_buffer_len+=ret;
2039 t=GetTimer()-t;
2040 tt = t*0.000001f; audio_time_usage+=tt;
2041 if(playsize>sh_audio->a_out_buffer_len) playsize=sh_audio->a_out_buffer_len;
2043 // play audio:
2044 current_module="play_audio";
2045 playsize=audio_out->play(sh_audio->a_out_buffer,playsize,0);
2047 if(playsize>0){
2048 sh_audio->a_out_buffer_len-=playsize;
2049 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
2050 sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ?
2051 ao_data.bps : sh_audio->o_bps));
2054 break;
2055 } // while(sh_audio)
2057 if(!sh_video) {
2058 // handle audio-only case:
2059 if(!quiet) {
2061 // convert time to HH:MM:SS.F format
2063 long tenths = 10 * (sh_audio->delay-audio_out->get_delay()*playback_speed);
2064 int hh = (tenths / 36000) % 100;
2065 int mm = (tenths / 600) % 60;
2066 int ss = (tenths / 10) % 60;
2067 int f1 = tenths % 10;
2068 char hhmmssf[16]; // only really need 11, but just in case...
2069 sprintf( hhmmssf, "%2d:%2d:%2d.%1d", hh, mm, ss, f1);
2070 if (0 == hh) {
2071 hhmmssf[1] = ' ';
2072 hhmmssf[2] = ' ';
2074 // uncomment the next three lines to show leading zero ten-hours
2075 // else if (' ' == hhmmssf[0]) {
2076 // hhmmssf[0] = '0';
2077 // }
2078 if ((0 == hh) && (0 == mm)) {
2079 hhmmssf[4] = ' ';
2080 hhmmssf[5] = ' ';
2082 else if ((' ' == hhmmssf[3]) && (' ' != hhmmssf[2])) {
2083 hhmmssf[3] = '0';
2085 if ((' ' == hhmmssf[6]) && (' ' != hhmmssf[5])) {
2086 hhmmssf[6] = '0';
2088 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: %s %4.1f%% %d%% \r"
2089 ,hhmmssf
2090 ,(sh_audio->delay>0.5)?100.0*audio_time_usage/(double)sh_audio->delay:0
2091 ,cache_fill_status
2094 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2096 } else {
2098 /*========================== PLAY VIDEO ============================*/
2100 float frame_time=next_frame_time;
2102 vo_pts=sh_video->timer*90000.0;
2103 vo_fps=sh_video->fps;
2105 if(!frame_time_remaining){
2106 //-------------------- Decode a frame: -----------------------
2107 vdecode_time=video_time_usage;
2108 while(1)
2109 { unsigned char* start=NULL;
2110 int in_size;
2111 // get it!
2112 current_module="video_read_frame";
2113 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
2114 if(in_size<0){ eof=1; break; }
2115 if(in_size>max_framesize) max_framesize=in_size; // stats
2116 sh_video->timer+=frame_time;
2117 if(sh_audio) sh_audio->delay-=frame_time;
2118 time_frame+=frame_time; // for nosound
2119 // check for frame-drop:
2120 current_module="check_framedrop";
2121 if(sh_audio && !d_audio->eof){
2122 float delay=playback_speed*audio_out->get_delay();
2123 float d=delay-sh_audio->delay;
2124 // we should avoid dropping to many frames in sequence unless we
2125 // are too late. and we allow 100ms A-V delay here:
2126 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
2127 drop_frame=frame_dropping;
2128 ++drop_frame_cnt;
2129 ++dropped_frames;
2130 } else {
2131 drop_frame=dropped_frames=0;
2133 ++total_frame_cnt;
2135 // decode:
2136 current_module="decode_video";
2137 // printf("Decode! %p %d \n",start,in_size);
2138 blit_frame=decode_video(sh_video,start,in_size,drop_frame);
2139 break;
2141 vdecode_time=video_time_usage-vdecode_time;
2142 //------------------------ frame decoded. --------------------
2144 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
2146 if(sh_video->vf_inited<0){
2147 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
2148 eof=1; goto goto_next_file;
2153 // ==========================================================================
2155 // current_module="draw_osd";
2156 // if(vo_config_count) video_out->draw_osd();
2158 #ifdef HAVE_NEW_GUI
2159 if(use_gui) guiEventHandling();
2160 #endif
2162 current_module="calc_sleep_time";
2164 #if 0
2165 { // debug frame dropping code
2166 float delay=audio_out->get_delay();
2167 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2168 sh_video->timer,sh_audio->timer-delay,
2169 sh_video->timer-(sh_audio->timer-delay),
2170 delay,drop_frame);
2172 #endif
2174 if(drop_frame && !frame_time_remaining && !autosync){
2176 * Note: time_frame should not be forced to 0 in autosync mode.
2177 * It is used as a cumulative counter to predict and correct the
2178 * delay measurements from the audio driver. time_frame is already
2179 * < 0, so the "time to sleep" code does not actually sleep. Also,
2180 * blit_frame is already 0 because drop_frame was true when
2181 * decode_video was called (which causes it to set blit_frame to 0.)
2182 * When autosync==0, the default behavior is still completely unchanged.
2185 time_frame=0; // don't sleep!
2186 blit_frame=0; // don't display!
2188 } else {
2190 // It's time to sleep...
2192 frame_time_remaining=0;
2193 time_frame-=GetRelativeTime(); // reset timer
2195 if(sh_audio && !d_audio->eof){
2196 float delay=playback_speed*audio_out->get_delay();
2197 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
2199 if (autosync){
2201 * Adjust this raw delay value by calculating the expected
2202 * delay for this frame and generating a new value which is
2203 * weighted between the two. The higher autosync is, the
2204 * closer to the delay value gets to that which "-nosound"
2205 * would have used, and the longer it will take for A/V
2206 * sync to settle at the right value (but it eventually will.)
2207 * This settling time is very short for values below 100.
2209 float predicted = sh_audio->delay+time_frame;
2210 float difference = delay - predicted;
2211 delay = predicted + difference / (float)autosync;
2214 time_frame=delay-sh_audio->delay;
2216 // delay = amount of audio buffered in soundcard/driver
2217 if(delay>0.25) delay=0.25; else
2218 if(delay<0.10) delay=0.10;
2219 if(time_frame>delay*0.6){
2220 // sleep time too big - may cause audio drops (buffer underrun)
2221 frame_time_remaining=1;
2222 time_frame=delay*0.5;
2225 } else {
2227 // NOSOUND:
2228 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
2229 time_frame=0;
2233 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2235 aq_sleep_time+=time_frame;
2237 } // !drop_frame
2239 //============================== SLEEP: ===================================
2241 time_frame/=playback_speed;
2243 // flag 256 means: libvo driver does its timing (dvb card)
2244 if(time_frame>0.001 && !(vo_flags&256)){
2246 #ifdef HAVE_RTC
2247 if(rtc_fd>=0){
2248 // -------- RTC -----------
2249 current_module="sleep_rtc";
2250 while (time_frame > 0.000) {
2251 unsigned long rtc_ts;
2252 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2253 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2254 time_frame-=GetRelativeTime();
2256 } else
2257 #endif
2259 // -------- TIMER + SOFTSLEEP -----------
2260 float min=softsleep?0.021:0.005;
2261 current_module="sleep_timer";
2262 while(time_frame>min){
2263 if(time_frame<=0.020)
2264 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2265 else
2266 usec_sleep(1000000*(time_frame-0.020));
2267 time_frame-=GetRelativeTime();
2269 if(softsleep){
2270 current_module="sleep_soft";
2271 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
2272 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
2278 //if(!frame_time_remaining){ // should we display the frame now?
2280 //====================== FLIP PAGE (VIDEO BLT): =========================
2282 current_module="vo_check_events";
2283 if(vo_config_count) video_out->check_events();
2285 current_module="flip_page";
2286 if (!frame_time_remaining) {
2287 if(blit_frame){
2288 unsigned int t2=GetTimer();
2289 double tt;
2290 float j;
2291 #define FRAME_LAG_WARN 0.2
2292 j = ((float)t2 - lastframeout_ts) / 1000000;
2293 lastframeout_ts = GetTimer();
2294 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
2295 too_fast_frame_cnt++;
2296 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2297 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
2298 too_slow_frame_cnt++;
2299 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2301 if(vo_config_count) video_out->flip_page();
2302 // usec_sleep(50000); // test only!
2303 t2=GetTimer()-t2;
2304 tt = t2*0.000001f;
2305 vout_time_usage+=tt;
2306 } else {
2308 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2309 otherwise A/V desync will occur. -- Alvieboy
2311 if (vo_config_count)
2312 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
2315 //====================== A-V TIMESTAMP CORRECTION: =========================
2317 current_module="av_sync";
2319 if(sh_audio){
2320 float a_pts=0;
2321 float v_pts=0;
2323 // unplayed bytes in our and soundcard/dma buffer:
2324 float delay=playback_speed*audio_out->get_delay()+(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2326 if (autosync){
2328 * If autosync is enabled, the value for delay must be calculated
2329 * a bit differently. It is set only to the difference between
2330 * the audio and video timers. Any attempt to include the real
2331 * or corrected delay causes the pts_correction code below to
2332 * try to correct for the changes in delay which autosync is
2333 * trying to measure. This keeps the two from competing, but still
2334 * allows the code to correct for PTS drift *only*. (Using a delay
2335 * value here, even a "corrected" one, would be incompatible with
2336 * autosync mode.)
2338 delay=sh_audio->delay;
2339 delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
2342 #if 0
2343 if(pts_from_bps){
2344 // PTS = sample_no / samplerate
2345 unsigned int samples=
2346 // (sh_audio->audio.dwSampleSize)?
2347 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2348 ds_tell_block(d_audio); // <- used for VBR audio
2349 samples+=sh_audio->audio.dwStart; // offset
2350 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
2351 delay_corrected=1;
2352 a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2353 } else
2354 #endif
2356 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2357 a_pts=d_audio->pts;
2358 if(!delay_corrected) if(a_pts) delay_corrected=1;
2359 #if 0
2360 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2361 a_pts,
2362 ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
2363 -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
2364 a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
2365 #endif
2366 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
2368 v_pts=sh_video ? sh_video->pts : d_video->pts;
2370 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);
2372 if(delay_corrected){
2373 static int drop_message=0;
2374 float x;
2375 AV_delay=(a_pts-delay-audio_delay)-v_pts;
2376 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2377 ++drop_message;
2378 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2380 x=AV_delay*0.1f;
2381 if(x<-max_pts_correction) x=-max_pts_correction; else
2382 if(x> max_pts_correction) x= max_pts_correction;
2383 if(default_max_pts_correction>=0)
2384 max_pts_correction=default_max_pts_correction;
2385 else
2386 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2387 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2388 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",
2389 a_pts-audio_delay-delay,v_pts,AV_delay,c_total,
2390 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded,
2391 (sh_video->timer>0.5)?(int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer):0,
2392 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer):0,
2393 (sh_video->timer>0.5)?(100.0*audio_time_usage*playback_speed/(double)sh_video->timer):0
2394 ,drop_frame_cnt
2395 ,output_quality
2396 ,cache_fill_status
2398 fflush(stdout);
2401 } else {
2402 // No audio:
2404 if(!quiet)
2405 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video->pts,
2406 (int)sh_video->num_frames,
2407 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
2408 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
2409 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
2410 ,drop_frame_cnt
2411 ,output_quality
2412 ,cache_fill_status
2415 fflush(stdout);
2419 //============================ Auto QUALITY ============================
2421 /*Output quality adjustments:*/
2422 if(auto_quality>0){
2423 current_module="autoq";
2424 // float total=0.000001f * (GetTimer()-aq_total_time);
2425 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2426 if(output_quality<auto_quality && aq_sleep_time>0)
2427 ++output_quality;
2428 else
2429 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2430 if(output_quality>1 && aq_sleep_time<0)
2431 --output_quality;
2432 else
2433 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
2434 output_quality=0;
2435 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2436 set_video_quality(sh_video,output_quality);
2439 } // end if(sh_video)
2441 //============================ Handle PAUSE ===============================
2443 current_module="pause";
2445 #ifdef USE_OSD
2446 if(osd_visible){
2447 if (!--osd_visible){
2448 vo_osd_progbar_type=-1; // disable
2449 vo_osd_changed(OSDTYPE_PROGBAR);
2450 if (osd_function != OSD_PAUSE)
2451 osd_function = OSD_PLAY;
2454 #endif
2456 if(osd_function==OSD_PAUSE){
2457 mp_cmd_t* cmd;
2458 if(!quiet) {
2459 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
2460 fflush(stdout);
2462 #ifdef HAVE_NEW_GUI
2463 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
2464 #endif
2465 if (video_out && sh_video && vo_config_count)
2466 video_out->control(VOCTRL_PAUSE, NULL);
2468 if (audio_out && sh_audio)
2469 audio_out->pause(); // pause audio, keep data if possible
2471 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
2472 if(sh_video && video_out && vo_config_count) video_out->check_events();
2473 #ifdef HAVE_NEW_GUI
2474 if(use_gui){
2475 guiEventHandling();
2476 guiGetEvent( guiReDraw,NULL );
2477 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
2479 #endif
2480 #ifdef HAVE_MENU
2481 if(vf_menu)
2482 vf_menu_pause_update(vf_menu);
2483 #endif
2484 usec_sleep(20000);
2486 if (cmd->id == MP_CMD_PAUSE) {
2487 cmd = mp_input_get_cmd(0,1,0);
2488 mp_cmd_free(cmd);
2490 osd_function=OSD_PLAY;
2491 if (audio_out && sh_audio)
2492 audio_out->resume(); // resume audio
2493 if (video_out && sh_video && vo_config_count)
2494 video_out->control(VOCTRL_RESUME, NULL); // resume video
2495 (void)GetRelativeTime(); // keep TF around FT in next cycle
2496 #ifdef HAVE_NEW_GUI
2497 if (use_gui)
2499 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
2500 guiGetEvent( guiCEvent,(char *)guiSetPlay );
2502 #endif
2505 // handle -sstep
2506 if(step_sec>0) {
2507 osd_function=OSD_FFW;
2508 rel_seek_secs+=step_sec;
2511 #ifdef USE_DVDNAV
2512 if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
2513 dvdnav_stream_sleeping((dvdnav_priv_t*)stream->priv);
2514 #endif
2516 //================= EDL =========================================
2518 #ifdef USE_EDL
2519 if( next_edl_record ) { // Are we (still?) doing EDL?
2520 if ( !sh_video ) {
2521 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
2522 next_edl_record->next = NULL;
2523 } else {
2524 if( sh_video->pts >= next_edl_record->start_sec ) {
2525 if( next_edl_record->action == EDL_SKIP ) {
2526 osd_function = OSD_FFW;
2527 abs_seek_pos = 0;
2528 rel_seek_secs = next_edl_record->length_sec;
2529 #ifdef DEBUG_EDL
2530 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_EDLSKIPStartStopLength, next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec );
2531 #endif
2532 edl_decision = 1;
2533 } else if( next_edl_record->action == EDL_MUTE ) {
2534 mixer_mute(&mixer);
2535 edl_mute_count++; // new EDL seek behavior needs this
2536 #ifdef DEBUG_EDL
2537 mp_msg(MSGT_FIXME, MSGL_FIXME, "\nEDL_MUTE: [%f]\n", next_edl_record->start_sec );
2538 #endif
2539 edl_decision = 1;
2541 next_edl_record=next_edl_record->next;
2545 #endif
2547 //================= Keyboard events, SEEKing ====================
2549 current_module="key_events";
2552 mp_cmd_t* cmd;
2553 int brk_cmd = 0;
2554 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
2555 switch(cmd->id) {
2556 case MP_CMD_SEEK : {
2557 int v,abs;
2558 osd_show_percentage = 25;
2559 v = cmd->args[0].v.i;
2560 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2561 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
2562 abs_seek_pos = 1;
2563 if(sh_video)
2564 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2565 rel_seek_secs = v;
2567 else if(abs) { /* Absolute seek by percentage */
2568 abs_seek_pos = 3;
2569 if(sh_video)
2570 osd_function= (v > sh_video->timer) ? OSD_FFW : OSD_REW;
2571 rel_seek_secs = v/100.0;
2573 else {
2574 rel_seek_secs+= v;
2575 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
2577 brk_cmd = 1;
2578 } break;
2579 #ifdef USE_EDL
2580 case MP_CMD_EDL_MARK:
2581 if( edl_fd ) {
2582 float v = sh_video->pts;
2583 fprintf( edl_fd, "%f %f %d\n", v-2, v, 0 );
2585 break;
2586 #endif
2587 case MP_CMD_SWITCH_RATIO : {
2588 if (cmd->nargs == 0)
2589 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2590 else
2591 movie_aspect = cmd->args[0].v.f;
2592 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2593 } break;
2594 case MP_CMD_AUDIO_DELAY : {
2595 float v = cmd->args[0].v.f;
2596 audio_delay += v;
2597 osd_show_av_delay = 9;
2598 if(sh_audio) sh_audio->delay+= v;
2599 } break;
2600 case MP_CMD_FRAME_STEP :
2601 case MP_CMD_PAUSE : {
2602 osd_function=OSD_PAUSE;
2603 brk_cmd = 1;
2604 } break;
2605 case MP_CMD_QUIT : {
2606 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
2608 case MP_CMD_GRAB_FRAMES : {
2609 grab_frames=2;
2610 } break;
2611 case MP_CMD_PLAY_TREE_STEP : {
2612 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2613 int force = cmd->args[1].v.i;
2615 #ifdef HAVE_NEW_GUI
2616 if (use_gui) {
2617 int i=0;
2618 if (n>0)
2619 for (i=0;i<n;i++)
2620 mplNext();
2621 else
2622 for (i=0;i<-1*n;i++)
2623 mplPrev();
2624 } else
2625 #endif
2627 if(!force && playtree_iter) {
2628 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2630 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2631 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2632 play_tree_iter_free(i);
2633 } else
2634 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2635 if(eof)
2636 play_tree_step = n;
2637 brk_cmd = 1;
2639 } break;
2640 case MP_CMD_PLAY_TREE_UP_STEP : {
2641 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2642 int force = cmd->args[1].v.i;
2644 if(!force && playtree_iter) {
2645 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
2646 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
2647 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2648 play_tree_iter_free(i);
2649 } else
2650 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2651 brk_cmd = 1;
2652 } break;
2653 case MP_CMD_PLAY_ALT_SRC_STEP : {
2654 if(playtree_iter && playtree_iter->num_files > 1) {
2655 int v = cmd->args[0].v.i;
2656 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
2657 eof = PT_NEXT_SRC;
2658 else if(v < 0 && playtree_iter->file > 1)
2659 eof = PT_PREV_SRC;
2661 brk_cmd = 1;
2662 } break;
2663 case MP_CMD_SUB_DELAY : {
2664 #ifdef USE_SUB
2665 if (sh_video) {
2666 int abs= cmd->args[1].v.i;
2667 float v = cmd->args[0].v.f;
2668 if(abs)
2669 sub_delay = v;
2670 else
2671 sub_delay += v;
2672 osd_show_sub_delay = 9; // show the subdelay in OSD
2674 #endif
2675 } break;
2676 case MP_CMD_SUB_STEP : {
2677 #ifdef USE_SUB
2678 if (sh_video) {
2679 int movement = cmd->args[0].v.i;
2680 step_sub(subdata, sh_video->pts, movement);
2681 osd_show_sub_delay = 9; // show the subdelay in OSD
2683 #endif
2684 } break;
2685 case MP_CMD_OSD : {
2686 #ifdef USE_OSD
2687 if(sh_video) {
2688 int v = cmd->args[0].v.i;
2689 if(v < 0)
2690 osd_level=(osd_level+1)%(MAX_OSD_LEVEL+1);
2691 else
2692 osd_level= v > MAX_OSD_LEVEL ? MAX_OSD_LEVEL : v;
2694 #endif
2695 } break;
2696 case MP_CMD_OSD_SHOW_TEXT : {
2697 #ifdef USE_OSD
2698 if(osd_level && sh_video){
2699 osd_show_text=sh_video->fps; // 1 sec
2700 strncpy(osd_show_text_buffer, cmd->args[0].v.s, 64);
2702 #endif
2703 } break;
2704 case MP_CMD_VOLUME : {
2705 int v = cmd->args[0].v.i;
2707 // start change for absolute volume value
2708 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2710 if( abs )
2712 mixer_setvolume(&mixer, (float)v, (float)v );
2713 } else {
2714 if(v > 0)
2715 mixer_incvolume(&mixer);
2716 else
2717 mixer_decvolume(&mixer);
2720 #ifdef USE_OSD
2721 if(osd_level && sh_video){
2722 float vol;
2723 osd_visible=sh_video->fps; // 1 sec
2724 vo_osd_progbar_type=OSD_VOLUME;
2725 mixer_getbothvolume(&mixer, &vol);
2726 vo_osd_progbar_value=(vol*256.0)/100.0;
2727 vo_osd_changed(OSDTYPE_PROGBAR);
2729 #endif
2730 } break;
2731 case MP_CMD_MUTE:
2732 mixer_mute(&mixer);
2733 break;
2734 case MP_CMD_LOADFILE : {
2735 play_tree_t* e = play_tree_new();
2736 play_tree_add_file(e,cmd->args[0].v.s);
2738 // Go back to the start point
2739 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2740 /* NOP */;
2741 play_tree_free_list(playtree->child,1);
2742 play_tree_set_child(playtree,e);
2743 play_tree_iter_step(playtree_iter,0,0);
2744 eof = PT_NEXT_SRC;
2745 brk_cmd = 1;
2746 } break;
2747 case MP_CMD_LOADLIST : {
2748 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
2749 if(!e)
2750 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
2751 else {
2752 // Go back to the start point
2753 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
2754 /* NOP */;
2755 play_tree_free_list(playtree->child,1);
2756 play_tree_set_child(playtree,e);
2757 play_tree_iter_step(playtree_iter,0,0);
2758 eof = PT_NEXT_SRC;
2760 brk_cmd = 1;
2761 } break;
2762 case MP_CMD_GAMMA : {
2763 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2765 if (!sh_video)
2766 break;
2768 if (vo_gamma_gamma == 1000)
2770 vo_gamma_gamma = 0;
2771 get_video_colors (sh_video, "gamma", &vo_gamma_gamma);
2774 if (abs)
2775 vo_gamma_gamma = v;
2776 else
2777 vo_gamma_gamma += v;
2779 if (vo_gamma_gamma > 100)
2780 vo_gamma_gamma = 100;
2781 else if (vo_gamma_gamma < -100)
2782 vo_gamma_gamma = -100;
2783 set_video_colors(sh_video, "gamma", vo_gamma_gamma);
2784 #ifdef USE_OSD
2785 if(osd_level){
2786 osd_visible=sh_video->fps; // 1 sec
2787 vo_osd_progbar_type=OSD_BRIGHTNESS;
2788 vo_osd_progbar_value=(vo_gamma_gamma<<7)/100 + 128;
2789 vo_osd_changed(OSDTYPE_PROGBAR);
2791 #endif // USE_OSD
2792 } break;
2793 case MP_CMD_BRIGHTNESS : {
2794 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2796 if (!sh_video)
2797 break;
2799 if (vo_gamma_brightness == 1000)
2801 vo_gamma_brightness = 0;
2802 get_video_colors(sh_video, "brightness", &vo_gamma_brightness);
2805 if (abs)
2806 vo_gamma_brightness = v;
2807 else
2808 vo_gamma_brightness += v;
2810 if (vo_gamma_brightness > 100)
2811 vo_gamma_brightness = 100;
2812 else if (vo_gamma_brightness < -100)
2813 vo_gamma_brightness = -100;
2814 if(set_video_colors(sh_video, "brightness", vo_gamma_brightness)){
2815 #ifdef USE_OSD
2816 if(osd_level){
2817 osd_visible=sh_video->fps; // 1 sec
2818 vo_osd_progbar_type=OSD_BRIGHTNESS;
2819 vo_osd_progbar_value=(vo_gamma_brightness<<7)/100 + 128;
2820 vo_osd_changed(OSDTYPE_PROGBAR);
2822 #endif // USE_OSD
2824 } break;
2825 case MP_CMD_CONTRAST : {
2826 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2828 if (!sh_video)
2829 break;
2831 if (vo_gamma_contrast == 1000)
2833 vo_gamma_contrast = 0;
2834 get_video_colors(sh_video, "contrast", &vo_gamma_contrast);
2837 if (abs)
2838 vo_gamma_contrast = v;
2839 else
2840 vo_gamma_contrast += v;
2842 if (vo_gamma_contrast > 100)
2843 vo_gamma_contrast = 100;
2844 else if (vo_gamma_contrast < -100)
2845 vo_gamma_contrast = -100;
2846 if(set_video_colors(sh_video, "contrast", vo_gamma_contrast)){
2847 #ifdef USE_OSD
2848 if(osd_level){
2849 osd_visible=sh_video->fps; // 1 sec
2850 vo_osd_progbar_type=OSD_CONTRAST;
2851 vo_osd_progbar_value=(vo_gamma_contrast<<7)/100 + 128;
2852 vo_osd_changed(OSDTYPE_PROGBAR);
2854 #endif // USE_OSD
2856 } break;
2857 case MP_CMD_SATURATION : {
2858 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2860 if (!sh_video)
2861 break;
2863 if (vo_gamma_saturation == 1000)
2865 vo_gamma_saturation = 0;
2866 get_video_colors(sh_video, "saturation", &vo_gamma_saturation);
2869 if (abs)
2870 vo_gamma_saturation = v;
2871 else
2872 vo_gamma_saturation += v;
2874 if (vo_gamma_saturation > 100)
2875 vo_gamma_saturation = 100;
2876 else if (vo_gamma_saturation < -100)
2877 vo_gamma_saturation = -100;
2878 if(set_video_colors(sh_video, "saturation", vo_gamma_saturation)){
2879 #ifdef USE_OSD
2880 if(osd_level){
2881 osd_visible=sh_video->fps; // 1 sec
2882 vo_osd_progbar_type=OSD_SATURATION;
2883 vo_osd_progbar_value=(vo_gamma_saturation<<7)/100 + 128;
2884 vo_osd_changed(OSDTYPE_PROGBAR);
2886 #endif // USE_OSD
2888 } break;
2889 case MP_CMD_HUE : {
2890 int v = cmd->args[0].v.i, abs = cmd->args[1].v.i;
2892 if (!sh_video)
2893 break;
2895 if (vo_gamma_hue == 1000)
2897 vo_gamma_hue = 0;
2898 get_video_colors(sh_video, "hue", &vo_gamma_hue);
2901 if (abs)
2902 vo_gamma_hue = v;
2903 else
2904 vo_gamma_hue += v;
2906 if (vo_gamma_hue > 100)
2907 vo_gamma_hue = 100;
2908 else if (vo_gamma_hue < -100)
2909 vo_gamma_hue = -100;
2910 if(set_video_colors(sh_video, "hue", vo_gamma_hue)){
2911 #ifdef USE_OSD
2912 if(osd_level){
2913 osd_visible=sh_video->fps; // 1 sec
2914 vo_osd_progbar_type=OSD_HUE;
2915 vo_osd_progbar_value=(vo_gamma_hue<<7)/100 + 128;
2916 vo_osd_changed(OSDTYPE_PROGBAR);
2918 #endif // USE_OSD
2920 } break;
2921 case MP_CMD_FRAMEDROPPING : {
2922 int v = cmd->args[0].v.i;
2923 if(v < 0){
2924 frame_dropping = (frame_dropping+1)%3;
2925 #ifdef USE_OSD
2926 osd_show_framedropping=10;
2927 vo_osd_changed(OSDTYPE_SUBTITLE);
2928 #endif
2930 else
2931 frame_dropping = v > 2 ? 2 : v;
2932 } break;
2933 #ifdef USE_TV
2934 case MP_CMD_TV_SET_FREQ : {
2935 if (file_format == DEMUXER_TYPE_TV)
2936 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
2937 } break;
2938 case MP_CMD_TV_SET_NORM : {
2939 if (file_format == DEMUXER_TYPE_TV)
2940 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
2941 } break;
2942 case MP_CMD_TV_SET_BRIGHTNESS : {
2943 if (file_format == DEMUXER_TYPE_TV)
2944 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_BRIGHTNESS, cmd->args[0].v.i);
2945 } break;
2946 case MP_CMD_TV_SET_HUE : {
2947 if (file_format == DEMUXER_TYPE_TV)
2948 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_HUE, cmd->args[0].v.i);
2949 } break;
2950 case MP_CMD_TV_SET_SATURATION : {
2951 if (file_format == DEMUXER_TYPE_TV)
2952 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_SATURATION, cmd->args[0].v.i);
2953 } break;
2954 case MP_CMD_TV_SET_CONTRAST : {
2955 if (file_format == DEMUXER_TYPE_TV)
2956 tv_set_color_options((tvi_handle_t*)(demuxer->priv), TV_COLOR_CONTRAST, cmd->args[0].v.i);
2957 } break;
2958 case MP_CMD_TV_STEP_CHANNEL : {
2959 if (file_format == DEMUXER_TYPE_TV) {
2960 int v = cmd->args[0].v.i;
2961 if(v > 0){
2962 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
2963 #ifdef USE_OSD
2964 if (tv_channel_list) {
2965 osd_show_tv_channel = sh_video->fps;
2966 vo_osd_changed(OSDTYPE_SUBTITLE);
2968 #endif
2969 } else {
2970 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
2971 #ifdef USE_OSD
2972 if (tv_channel_list) {
2973 osd_show_tv_channel = sh_video->fps;
2974 vo_osd_changed(OSDTYPE_SUBTITLE);
2976 #endif
2980 #ifdef HAS_DVBIN_SUPPORT
2981 if((stream->type == STREAMTYPE_DVB) && stream->priv)
2983 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
2984 if(priv->is_on)
2986 int dir;
2987 int v = cmd->args[0].v.i;
2989 last_dvb_step = v;
2990 if(v > 0)
2991 dir = DVB_CHANNEL_HIGHER;
2992 else
2993 dir = DVB_CHANNEL_LOWER;
2996 if(dvb_step_channel(priv, dir))
2998 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
2999 cache_uninit(stream);
3000 goto goto_enable_cache;
3004 #endif
3005 break;
3006 case MP_CMD_TV_SET_CHANNEL : {
3007 if (file_format == DEMUXER_TYPE_TV) {
3008 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
3009 #ifdef USE_OSD
3010 if (tv_channel_list) {
3011 osd_show_tv_channel = sh_video->fps;
3012 vo_osd_changed(OSDTYPE_SUBTITLE);
3014 #endif
3016 } break;
3017 #ifdef HAS_DVBIN_SUPPORT
3018 case MP_CMD_DVB_SET_CHANNEL:
3020 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3022 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3023 if(priv->is_on)
3025 if(priv->list->current <= cmd->args[0].v.i)
3026 last_dvb_step = 1;
3027 else
3028 last_dvb_step = -1;
3030 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
3032 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
3033 cache_uninit(stream);
3034 goto goto_enable_cache;
3039 #endif
3040 case MP_CMD_TV_LAST_CHANNEL : {
3041 if (file_format == DEMUXER_TYPE_TV) {
3042 tv_last_channel((tvi_handle_t*)(demuxer->priv));
3043 #ifdef USE_OSD
3044 if (tv_channel_list) {
3045 osd_show_tv_channel = sh_video->fps;
3046 vo_osd_changed(OSDTYPE_SUBTITLE);
3048 #endif
3050 } break;
3051 case MP_CMD_TV_STEP_NORM : {
3052 if (file_format == DEMUXER_TYPE_TV)
3053 tv_step_norm((tvi_handle_t*)(demuxer->priv));
3054 } break;
3055 case MP_CMD_TV_STEP_CHANNEL_LIST : {
3056 if (file_format == DEMUXER_TYPE_TV)
3057 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
3058 } break;
3059 #endif
3060 case MP_CMD_SWITCH_VSYNC: {
3061 vo_vsync = ( cmd->nargs > 0 )? cmd->args[0].v.i : !vo_vsync;
3062 } break;
3063 case MP_CMD_VO_FULLSCREEN:
3065 #ifdef HAVE_NEW_GUI
3066 if ( use_gui ) guiGetEvent( guiIEvent,(char *)MP_CMD_GUI_FULLSCREEN );
3067 else
3068 #endif
3069 if(video_out && vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
3070 } break;
3071 case MP_CMD_VO_ONTOP:
3073 if(video_out && vo_config_count) {
3074 video_out->control(VOCTRL_ONTOP, 0);
3075 #ifdef USE_OSD
3076 osd_show_ontop=10;
3077 vo_osd_changed(OSDTYPE_SUBTITLE);
3078 #endif
3081 } break;
3082 case MP_CMD_VO_ROOTWIN:
3084 if(video_out && vo_config_count) {
3085 video_out->control(VOCTRL_ROOTWIN, 0);
3086 #ifdef USE_OSD
3087 osd_show_rootwin=10;
3088 vo_osd_changed(OSDTYPE_SUBTITLE);
3089 #endif
3092 } break;
3093 case MP_CMD_PANSCAN : {
3094 if ( !video_out ) break;
3095 if ( video_out->control( VOCTRL_GET_PANSCAN,NULL ) == VO_TRUE )
3097 int abs= cmd->args[1].v.i;
3098 float v = cmd->args[0].v.f;
3099 float res;
3100 if(abs) res = v;
3101 else res = vo_panscan+v;
3102 vo_panscan = res > 1 ? 1 : res < 0 ? 0 : res;
3103 video_out->control( VOCTRL_SET_PANSCAN,NULL );
3104 #ifdef USE_OSD
3105 if(osd_level && sh_video){
3106 osd_visible=sh_video->fps; // 1 sec
3107 vo_osd_progbar_type=OSD_PANSCAN;
3108 vo_osd_progbar_value=vo_panscan*256;
3109 vo_osd_changed(OSDTYPE_PROGBAR);
3110 #ifdef HAVE_FREETYPE
3111 if (subtitle_autoscale == 2 || subtitle_autoscale == 3)
3112 // force scaling font to movie width or diagonal
3113 force_load_font = 1;
3114 #endif
3116 #endif
3118 } break;
3119 case MP_CMD_SUB_POS:
3121 #ifdef USE_SUB
3122 if (sh_video) {
3123 int v;
3124 v = cmd->args[0].v.i;
3126 sub_pos+=v;
3127 if(sub_pos >100) sub_pos=100;
3128 if(sub_pos <0) sub_pos=0;
3129 vo_osd_changed(OSDTYPE_SUBTITLE);
3130 osd_show_sub_pos = 9;
3132 #endif
3133 } break;
3134 case MP_CMD_SUB_ALIGNMENT:
3136 #ifdef USE_SUB
3137 if (sh_video) {
3138 if (cmd->nargs >= 1)
3139 sub_alignment = cmd->args[0].v.i;
3140 else
3141 sub_alignment = (sub_alignment+1) % 3;
3142 osd_show_sub_alignment = 9;
3143 vo_osd_changed(OSDTYPE_SUBTITLE);
3145 #endif
3146 } break;
3147 case MP_CMD_SUB_VISIBILITY:
3149 #ifdef USE_SUB
3150 if (sh_video) {
3151 sub_visibility=1-sub_visibility;
3152 osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
3153 vo_osd_changed(OSDTYPE_SUBTITLE);
3155 #endif
3156 } break;
3157 case MP_CMD_GET_SUB_VISIBILITY:
3159 #ifdef USE_SUB
3160 if (sh_video) {
3161 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsSubVisibility, sub_visibility);
3163 #endif
3164 } break;
3165 case MP_CMD_SUB_SELECT:
3166 if (global_sub_size) {
3167 int source = -1;
3169 global_sub_pos++;
3170 if (global_sub_pos >= global_sub_size)
3171 global_sub_pos = -1;
3172 if (global_sub_pos >= 0)
3173 source = sub_source();
3175 mp_msg(MSGT_CPLAYER, MSGL_DBG3, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3176 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
3177 global_sub_indices[SUB_SOURCE_SUBS], global_sub_indices[SUB_SOURCE_DEMUX],
3178 global_sub_pos, source);
3180 #ifdef USE_SUB
3181 set_of_sub_pos = -1;
3182 subdata = NULL;
3183 vo_sub = NULL;
3184 #endif
3185 vobsub_id = -1;
3186 dvdsub_id = -1;
3187 if (d_dvdsub) d_dvdsub->id = -1;
3189 // be careful!
3190 // if sub_changed is till on but subdata's been reset, bad things happen.
3191 osd_show_vobsub_changed = 0;
3192 osd_show_sub_changed = 0;
3194 if (source == SUB_SOURCE_VOBSUB) {
3195 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
3196 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3197 #ifdef USE_SUB
3198 } else if (source == SUB_SOURCE_SUBS) {
3199 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
3200 subdata = set_of_subtitles[set_of_sub_pos];
3201 if (!global_sub_quiet_osd_hack) osd_show_sub_changed = sh_video->fps;
3202 vo_osd_changed(OSDTYPE_SUBTITLE);
3204 // FIXME: is this the correct place for these?
3205 if(stream_dump_type==3) list_sub_file(subdata);
3206 if(stream_dump_type==4) dump_mpsub(subdata, sh_video->fps);
3207 if(stream_dump_type==6) dump_srt(subdata, sh_video->fps);
3208 if(stream_dump_type==7) dump_microdvd(subdata, sh_video->fps);
3209 if(stream_dump_type==8) dump_jacosub(subdata, sh_video->fps);
3210 if(stream_dump_type==9) dump_sami(subdata, sh_video->fps);
3211 #endif
3212 } else if (source == SUB_SOURCE_DEMUX) {
3213 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
3214 if (d_dvdsub) {
3215 #ifdef USE_DVDREAD
3216 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
3217 d_dvdsub->id = dvdsub_id;
3218 spudec_reset(vo_spudec);
3220 #endif
3221 #ifdef HAVE_OGGVORBIS
3222 if (demuxer->type == DEMUXER_TYPE_OGG)
3223 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
3224 #endif
3225 #ifdef HAVE_MATROSKA
3226 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3227 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
3228 if (d_dvdsub->id >= 0 && ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
3229 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
3230 if (vo_spudec != NULL)
3231 spudec_free(vo_spudec);
3232 vo_spudec =
3233 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
3234 mkv_sh_sub->custom_colors,
3235 mkv_sh_sub->width,
3236 mkv_sh_sub->height);
3237 if (!forced_subs_only)
3238 forced_subs_only = mkv_sh_sub->forced_subs_only;
3239 if (vo_spudec) {
3240 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
3241 inited_flags |= INITED_SPUDEC;
3245 #endif
3247 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3248 } else { // off
3249 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
3250 #ifdef USE_SUB
3251 vo_osd_changed(OSDTYPE_SUBTITLE);
3252 #endif
3254 // it's annoying and dumb to show osd saying "off" at every subless file...
3255 global_sub_quiet_osd_hack = 0;
3257 break;
3258 case MP_CMD_SUB_FORCED_ONLY:
3259 if (vo_spudec) {
3260 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
3261 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3263 break;
3264 case MP_CMD_SCREENSHOT :
3265 if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
3266 break;
3267 case MP_CMD_VF_CHANGE_RECTANGLE:
3268 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3269 break;
3271 case MP_CMD_GET_TIME_LENGTH : {
3272 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsLength, demuxer_get_time_length(demuxer));
3273 } break;
3275 case MP_CMD_GET_VO_FULLSCREEN : {
3276 if(video_out && vo_config_count)
3277 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsVoFullscreen, vo_fs);
3278 } break;
3280 case MP_CMD_GET_PERCENT_POS : {
3281 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsPercentPos, demuxer_get_percent_pos(demuxer));
3282 } break;
3283 #ifdef HAVE_MENU
3284 case MP_CMD_CRUN : {
3285 #ifndef __MINGW32__
3286 if(!fork()) {
3287 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
3288 exit(0);
3290 #endif
3291 } break;
3292 #endif
3294 #ifdef USE_DVDNAV
3295 case MP_CMD_DVDNAV_EVENT: {
3296 dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
3297 dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
3299 /* ignore these events if we're not in dvd_nav mode */
3300 if (stream->type != STREAMTYPE_DVDNAV) break;
3302 if (!dvdnav_event) {
3303 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNullEvent);
3304 break;
3307 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3309 switch (dvdnav_event->event) {
3310 case DVDNAV_BLOCK_OK: {
3311 /* be silent about this one */
3312 break;
3314 case DVDNAV_HIGHLIGHT: {
3315 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(dvdnav_event->details);
3316 if (!hevent) {
3317 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightEventBroken);
3318 break;
3321 if (hevent->display && hevent->buttonN>0)
3323 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3324 sprintf( dvd_nav_text, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3325 hevent->buttonN,
3326 hevent->sx,hevent->sy,
3327 hevent->ex,hevent->ey,
3328 hevent->pts, d_video->pts);
3329 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavEvent,dvd_nav_text);
3330 //osd_show_dvd_nav_delay = 60;
3332 osd_show_dvd_nav_highlight=1;
3333 osd_show_dvd_nav_sx=hevent->sx;
3334 osd_show_dvd_nav_ex=hevent->ex;
3335 osd_show_dvd_nav_sy=hevent->sy;
3336 osd_show_dvd_nav_ey=hevent->ey;
3338 else {
3339 osd_show_dvd_nav_highlight=0;
3340 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavHighlightHide);
3342 break;
3344 case DVDNAV_STILL_FRAME: {
3345 dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(dvdnav_event->details);
3347 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavStillFrame, still_event->length );
3348 while (dvdnav_stream_sleeping(dvdnav_priv)) {
3349 usec_sleep(1000); /* 1ms */
3351 dvdnav_stream_sleep(dvdnav_priv,still_event->length);
3352 break;
3354 case DVDNAV_STOP: {
3355 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavStop );
3356 break;
3358 case DVDNAV_NOP: {
3359 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavNOP);
3360 break;
3362 case DVDNAV_SPU_STREAM_CHANGE: {
3363 #if DVDNAVVERSION > 012
3364 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t*)(dvdnav_event->details);
3366 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChangeVerbose,
3367 stream_change->physical_wide,
3368 stream_change->physical_letterbox,
3369 stream_change->physical_pan_scan,
3370 stream_change->logical);
3372 if (vo_spudec && dvdsub_id!=stream_change->physical_wide) {
3373 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3374 d_dvdsub->id,stream_change->physical_wide);
3375 // FIXME: need a better way to change SPU id
3376 d_dvdsub->id=dvdsub_id=stream_change->physical_wide;
3377 if (vo_spudec) spudec_reset(vo_spudec);
3379 #else
3380 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3382 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuStreamChange,
3383 stream_change->physical,
3384 stream_change->logical);
3386 if (vo_spudec && dvdsub_id!=stream_change->physical) {
3387 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",
3388 d_dvdsub->id,stream_change->physical);
3389 // FIXME: need a better way to change SPU id
3390 d_dvdsub->id=dvdsub_id=stream_change->physical;
3391 if (vo_spudec) spudec_reset(vo_spudec);
3393 #endif
3394 break;
3396 case DVDNAV_AUDIO_STREAM_CHANGE: {
3397 int aid_temp;
3398 #if DVDNAVVERSION > 012
3399 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t*)(dvdnav_event->details);
3400 #else
3401 dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(dvdnav_event->details);
3402 #endif
3404 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavAudioStreamChange,
3405 stream_change->physical,
3406 stream_change->logical);
3408 aid_temp=stream_change->physical;
3409 if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
3410 if (d_audio && audio_id!=aid_temp) {
3411 mp_msg(MSGT_INPUT,MSGL_DBG2,"d_audio->id change: was %d is now %d\n",
3412 d_audio->id,aid_temp);
3413 // FIXME: need a bettery way to change audio stream id
3414 d_audio->id=dvdsub_id=aid_temp;
3415 if(sh_audio) resync_audio_stream(sh_audio);
3418 break;
3420 case DVDNAV_VTS_CHANGE: {
3421 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavVTSChange);
3422 break;
3424 case DVDNAV_CELL_CHANGE: {
3425 dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(dvdnav_event->details);
3426 cell_playback_t * cell_playback = cell_change->new_cell;
3428 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavCellChange);
3429 osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
3431 printf("new still time: %d\n",cell_playback->still_time);
3432 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3433 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3434 cell_playback->playback_time.hour,
3435 cell_playback->playback_time.minute,
3436 cell_playback->playback_time.second,
3437 cell_playback->playback_time.frame_u);
3440 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3441 //abs_seek_pos=0;
3442 break;
3444 case DVDNAV_NAV_PACKET: {
3445 // printf("DVDNAV Event: Nav Packet\n");
3446 break;
3448 case DVDNAV_SPU_CLUT_CHANGE: {
3449 uint32_t * new_clut = (uint32_t *)(dvdnav_event->details);
3451 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSpuClutChange);
3452 // send new palette to SPU decoder
3453 if (vo_spudec) spudec_update_palette(vo_spudec,new_clut);
3455 break;
3457 case DVDNAV_SEEK_DONE: {
3458 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_DvdnavNavSeekDone);
3459 break;
3463 // free the dvdnav event
3464 free(dvdnav_event->details);
3465 free(dvdnav_event);
3466 cmd->args[0].v.v=NULL;
3468 case MP_CMD_DVDNAV: {
3469 dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
3471 /* ignore these events if we're not in dvd_nav mode */
3472 if (stream->type != STREAMTYPE_DVDNAV) break;
3474 switch (cmd->args[0].v.i) {
3475 case MP_CMD_DVDNAV_UP:
3476 dvdnav_upper_button_select(dvdnav_priv->dvdnav);
3477 break;
3478 case MP_CMD_DVDNAV_DOWN:
3479 dvdnav_lower_button_select(dvdnav_priv->dvdnav);
3480 break;
3481 case MP_CMD_DVDNAV_LEFT:
3482 dvdnav_left_button_select(dvdnav_priv->dvdnav);
3483 break;
3484 case MP_CMD_DVDNAV_RIGHT:
3485 dvdnav_right_button_select(dvdnav_priv->dvdnav);
3486 break;
3487 case MP_CMD_DVDNAV_MENU:
3488 mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_MenuCall);
3489 dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
3490 break;
3491 case MP_CMD_DVDNAV_SELECT:
3492 dvdnav_button_activate(dvdnav_priv->dvdnav);
3493 break;
3494 default:
3495 mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
3496 break;
3498 break;
3500 #endif
3501 default : {
3502 #ifdef HAVE_NEW_GUI
3503 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
3504 else
3505 #endif
3506 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
3509 mp_cmd_free(cmd);
3513 if (seek_to_sec) {
3514 int a,b; float d;
3516 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
3517 rel_seek_secs += 3600*a +60*b +d ;
3518 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
3519 rel_seek_secs += 60*a +d;
3520 else if (sscanf(seek_to_sec, "%f", &d)==1)
3521 rel_seek_secs += d;
3523 seek_to_sec = NULL;
3526 /* Looping. */
3527 if(eof==1 && loop_times>=0) {
3528 int l = loop_times;
3529 play_tree_iter_step(playtree_iter,0,0);
3530 loop_times = l;
3531 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
3533 if(loop_times>1) loop_times--; else
3534 if(loop_times==1) loop_times=-1;
3535 play_n_frames=play_n_frames_mf;
3536 eof=0;
3537 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
3538 loop_seek = 1;
3541 if(rel_seek_secs || abs_seek_pos){
3542 current_module="seek";
3543 if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){
3544 // success:
3545 /* FIXME there should be real seeking for vobsub */
3546 if(sh_video) sh_video->pts=d_video->pts;
3547 if (vo_vobsub)
3548 //vobsub_reset(vo_vobsub);
3549 vobsub_seek(vo_vobsub,sh_video->pts);
3550 #if 0
3551 if(sh_video && d_video->packs == 0)
3552 ds_fill_buffer(d_video);
3553 if(sh_audio){
3554 if(d_audio->packs == 0)
3555 ds_fill_buffer(d_audio);
3556 if(verbose>0){
3557 float a_pts=d_audio->pts;
3558 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
3559 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);
3561 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);
3562 } else {
3563 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: --- V:%6.1f \r",d_video->pts);
3565 #endif
3566 fflush(stdout);
3568 if(sh_video){
3569 current_module="seek_video_reset";
3570 resync_video_stream(sh_video);
3571 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
3574 if(sh_audio){
3575 current_module="seek_audio_reset";
3576 audio_out->reset(); // stop audio, throwing away buffered data
3578 #ifdef USE_OSD
3579 // Set OSD:
3580 if(osd_level && !loop_seek){
3581 #ifdef USE_EDL
3582 if( !edl_decision ) {
3583 #else
3584 if( 1 ) { // Let the compiler optimize this out
3585 #endif
3586 int len=((demuxer->movi_end-demuxer->movi_start)>>8);
3587 if (len>0 && sh_video){
3588 osd_visible=sh_video->fps; // 1 sec
3589 vo_osd_progbar_type=0;
3590 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
3591 vo_osd_changed(OSDTYPE_PROGBAR);
3595 #endif
3596 if(sh_video) {
3597 c_total=0;
3598 max_pts_correction=0.1;
3599 osd_visible=sh_video->fps; // to rewert to PLAY pointer after 1 sec
3600 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3601 drop_frame_cnt=0;
3602 too_slow_frame_cnt=0;
3603 too_fast_frame_cnt=0;
3605 if(vo_spudec) spudec_reset(vo_spudec);
3608 #ifdef USE_EDL
3610 * We saw a seek, have to rewind the EDL operations stack
3611 * and find the next EDL action to take care of.
3614 next_edl_record = edl_records;
3616 while (next_edl_record)
3618 /* Trying to remember if we need to mute/unmute first;
3619 * prior EDL implementation lacks this.
3622 if (next_edl_record->start_sec >= sh_video->pts)
3624 if (edl_mute_count > 0)
3626 if ((edl_mute_count % 2) == 0 &&
3627 next_edl_record->mute_state == EDL_MUTE_END)
3629 mixer_mute(&mixer);
3630 edl_mute_count++;
3632 if ((edl_mute_count % 2) != 0 &&
3633 next_edl_record->mute_state == EDL_MUTE_START)
3635 mixer_mute(&mixer);
3636 edl_mute_count++;
3638 } else if (next_edl_record->mute_state == EDL_MUTE_END)
3640 mixer_mute(&mixer);
3641 edl_mute_count++;
3643 break;
3646 next_edl_record = next_edl_record->next;
3648 if (!next_edl_record && (edl_mute_count % 2) != 0
3649 && edl_mute_count > 0)
3651 mixer_mute(&mixer);
3652 edl_mute_count++;
3655 #endif
3656 rel_seek_secs=0;
3657 abs_seek_pos=0;
3658 frame_time_remaining=0;
3659 current_module=NULL;
3660 loop_seek=0;
3663 #ifdef HAVE_NEW_GUI
3664 if(use_gui){
3665 guiEventHandling();
3666 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
3667 // get pos from frame number / total frames
3668 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
3669 } else {
3670 off_t len = ( demuxer->movi_end - demuxer->movi_start );
3671 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
3672 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
3674 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
3675 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
3676 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
3677 guiGetEvent( guiReDraw,NULL );
3678 guiGetEvent( guiSetVolume,NULL );
3679 if(guiIntfStruct.Playing==0) break; // STOP
3680 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
3681 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
3682 #ifdef USE_DVDREAD
3683 if ( stream->type == STREAMTYPE_DVD )
3685 dvd_priv_t * dvdp = stream->priv;
3686 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
3688 #endif
3690 #endif
3693 //================= Update OSD ====================
3694 #ifdef USE_OSD
3695 if(osd_level>=1 && sh_video){
3696 int pts=sh_video->pts;
3697 char osd_text_tmp[64];
3698 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
3699 vo_osd_text=osd_text_buffer;
3700 #ifdef USE_DVDNAV
3701 if (osd_show_dvd_nav_delay) {
3702 snprintf(osd_text_tmp, 63, "DVDNAV: %s", dvd_nav_text);
3703 osd_show_dvd_nav_delay--;
3704 } else
3705 #endif
3706 #ifdef USE_TV
3707 if (osd_show_tv_channel && tv_channel_list) {
3708 snprintf(osd_text_tmp, 63, "Channel: %s", tv_channel_current->name);
3709 osd_show_tv_channel--;
3710 } else
3711 #endif
3712 if (osd_show_text) {
3713 snprintf(osd_text_tmp, 63, "%s", osd_show_text_buffer);
3714 osd_show_text--;
3715 } else
3716 if (osd_show_sub_visibility) {
3717 snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
3718 osd_show_sub_visibility--;
3719 } else
3720 if (osd_show_vobsub_changed) {
3721 if (vo_vobsub && vobsub_id >= 0) {
3722 const char *language = "none";
3723 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
3724 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
3726 #ifdef HAVE_OGGVORBIS
3727 if (d_dvdsub && demuxer->type == DEMUXER_TYPE_OGG) {
3728 if (dvdsub_id < 0)
3729 snprintf(osd_text_tmp, 63, "Subtitles: (off)");
3730 else {
3731 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
3732 if (!lang) lang = "unknown";
3733 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3736 #endif
3737 #ifdef USE_DVDREAD
3738 if (vo_spudec && (demuxer->type != DEMUXER_TYPE_MATROSKA)) {
3739 char lang[5] = "none";
3740 int code = 0;
3741 if (dvdsub_id >= 0) code = dvd_lang_from_sid(stream, dvdsub_id);
3742 if (code) {
3743 lang[0] = code >> 8;
3744 lang[1] = code;
3745 lang[2] = 0;
3747 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3749 #endif
3750 #ifdef HAVE_MATROSKA
3751 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
3752 char lang[10] = "unknown";
3753 if (dvdsub_id >= 0) {
3754 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
3755 lang[9] = 0;
3756 } else
3757 strcpy(lang, "off");
3758 snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
3760 #endif
3761 osd_show_vobsub_changed--;
3762 } else
3763 #ifdef USE_SUB
3764 if (osd_show_sub_changed) {
3765 char *tmp2;
3766 tmp = subdata->filename;
3767 if ((tmp2 = strrchr(tmp, '/'))) {
3768 tmp = tmp2+1;
3770 snprintf(osd_text_tmp, 63, "Sub: (%d) %s%s",
3771 set_of_sub_pos + 1,
3772 strlen(tmp) < 20 ? "" : "...",
3773 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
3774 osd_show_sub_changed--;
3775 } else
3776 #endif
3777 if (osd_show_sub_delay) {
3778 snprintf(osd_text_tmp, 63, "Sub delay: %d ms", ROUND(sub_delay*1000));
3779 osd_show_sub_delay--;
3780 } else
3781 if (osd_show_sub_pos) {
3782 snprintf(osd_text_tmp, 63, "Sub position: %d/100", sub_pos);
3783 osd_show_sub_pos--;
3784 } else
3785 if (osd_show_sub_alignment) {
3786 snprintf(osd_text_tmp, 63, "Sub alignment: %s",
3787 (sub_alignment == 2 ? "bottom" :
3788 (sub_alignment == 1 ? "center" : "top")));
3789 osd_show_sub_alignment--;
3790 } else
3791 if (osd_show_av_delay) {
3792 snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000));
3793 osd_show_av_delay--;
3794 } else if (osd_show_ontop) {
3795 snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis");
3796 osd_show_ontop--;
3797 } else if (osd_show_rootwin) {
3798 snprintf(osd_text_tmp, 63, "Rootwin: %sabled", vo_rootwin?"en":"dis");
3799 osd_show_rootwin--;
3800 } else if (osd_show_framedropping) {
3801 snprintf(osd_text_tmp, 63, "Framedropping: %s",
3802 (frame_dropping == 1 ? "on" :
3803 (frame_dropping == 2 ? "hard" : "off")));
3804 osd_show_framedropping--;
3805 } else if(osd_level>=2) {
3806 int len = demuxer_get_time_length(demuxer);
3807 int percentage = -1;
3808 char percentage_text[10];
3809 if (osd_show_percentage) {
3810 percentage = demuxer_get_percent_pos(demuxer);
3811 osd_show_percentage--;
3813 if (percentage >= 0)
3814 snprintf(percentage_text, 9, " (%d%%)", percentage);
3815 else
3816 percentage_text[0] = 0;
3817 if (osd_level == 3)
3818 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);
3819 else
3820 snprintf(osd_text_tmp, 63, "%c %02d:%02d:%02d%s",osd_function,pts/3600,(pts/60)%60,pts%60,percentage_text);
3821 } else osd_text_tmp[0]=0;
3823 if(strcmp(vo_osd_text, osd_text_tmp)) {
3824 strncpy(vo_osd_text, osd_text_tmp, 63);
3825 vo_osd_changed(OSDTYPE_OSD);
3827 } else {
3828 if(vo_osd_text) {
3829 vo_osd_text=NULL;
3830 vo_osd_changed(OSDTYPE_OSD);
3833 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3834 // vo_osd_text=osd_text_buffer;
3835 #endif
3837 #ifdef USE_SUB
3838 // find sub
3839 if(subdata && sh_video->pts>0){
3840 float pts=sh_video->pts;
3841 if(sub_fps==0) sub_fps=sh_video->fps;
3842 current_module="find_sub";
3843 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
3844 find_sub(subdata, (pts+sub_delay) *
3845 (subdata->sub_uses_time ? 100. : sub_fps));
3846 // FIXME! frame counter...
3847 sub_last_pts = pts;
3849 current_module=NULL;
3851 #endif
3853 #ifdef HAVE_X11
3854 if (stop_xscreensaver && sh_video) {
3855 current_module="stop_xscreensaver";
3856 xscreensaver_heartbeat();
3857 current_module=NULL;
3859 #endif
3861 // DVD sub:
3862 if(vo_config_count && vo_spudec) {
3863 unsigned char* packet=NULL;
3864 int len,timestamp;
3865 current_module="spudec";
3866 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
3867 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3868 while(1) {
3869 // Vobsub
3870 len = 0;
3871 if(vo_vobsub) {
3872 if(sh_video->pts+sub_delay>=0) {
3873 // The + next_frame_time is there because we'll display the sub at the next frame
3874 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
3875 if(len > 0) {
3876 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
3877 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);
3880 } else {
3881 // DVD sub
3882 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
3883 if(len > 0) {
3884 float x = d_dvdsub->pts - sh_video->pts;
3885 if (x < -10 || x > 10) // prevent missing subs on pts reset
3886 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
3887 else timestamp = 90000*(sh_video->timer + sub_delay);
3888 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);
3891 if(len<=0 || !packet) break;
3892 if(timestamp < 0) timestamp = 0;
3893 else spudec_assemble(vo_spudec,packet,len,timestamp);
3896 /* detect wether the sub has changed or not */
3897 if(spudec_changed(vo_spudec))
3898 vo_osd_changed(OSDTYPE_SPU);
3899 current_module=NULL;
3902 } // while(!eof)
3904 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
3908 goto_next_file: // don't jump here after ao/vo/getch initialization!
3910 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3912 if(benchmark){
3913 double tot=video_time_usage+vout_time_usage+audio_time_usage;
3914 double total_time_usage;
3915 total_time_usage_start=GetTimer()-total_time_usage_start;
3916 total_time_usage = (float)total_time_usage_start*0.000001;
3917 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3918 video_time_usage,vout_time_usage,audio_time_usage,
3919 total_time_usage-tot,total_time_usage);
3920 if(total_time_usage>0.0)
3921 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3922 100.0*video_time_usage/total_time_usage,
3923 100.0*vout_time_usage/total_time_usage,
3924 100.0*audio_time_usage/total_time_usage,
3925 100.0*(total_time_usage-tot)/total_time_usage,
3926 100.0);
3927 if(total_frame_cnt && frame_dropping)
3928 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3929 total_frame_cnt-drop_frame_cnt,
3930 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
3931 drop_frame_cnt,
3932 100*drop_frame_cnt/total_frame_cnt,
3933 total_frame_cnt,
3934 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
3938 // time to uninit all, except global stuff:
3939 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
3941 #ifdef USE_SUB
3942 if ( set_of_sub_size > 0 )
3944 current_module="sub_free";
3945 for (i = 0; i < set_of_sub_size; ++i)
3946 sub_free( set_of_subtitles[i] );
3947 set_of_sub_size = 0;
3948 vo_sub=NULL;
3949 subdata=NULL;
3951 #endif
3953 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
3954 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
3955 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
3956 eof = 1;
3957 } else {
3958 play_tree_iter_free(playtree_iter);
3959 playtree_iter = NULL;
3961 play_tree_step = 1;
3962 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
3963 eof = eof == PT_UP_NEXT ? 1 : -1;
3964 if ( playtree_iter ) {
3965 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
3966 eof = 1;
3967 } else {
3968 play_tree_iter_free(playtree_iter);
3969 playtree_iter = NULL;
3972 } else { // NEXT PREV SRC
3973 eof = eof == PT_PREV_SRC ? -1 : 1;
3976 if(eof == 0) eof = 1;
3978 while(playtree_iter != NULL) {
3979 filename = play_tree_iter_get_file(playtree_iter,eof);
3980 if(filename == NULL) {
3981 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
3982 play_tree_iter_free(playtree_iter);
3983 playtree_iter = NULL;
3985 } else
3986 break;
3989 #ifdef HAVE_NEW_GUI
3990 if( use_gui && !playtree_iter )
3992 #ifdef USE_DVDREAD
3993 if ( !guiIntfStruct.DiskChanged )
3994 #endif
3995 mplEnd();
3997 #endif
3999 if(use_gui || playtree_iter != NULL){
4001 eof = 0;
4002 goto play_next_file;
4005 #ifdef HAVE_FREETYPE
4006 current_module="uninit_font";
4007 if (vo_font) free_font_desc(vo_font);
4008 vo_font = NULL;
4009 done_freetype();
4010 #endif
4012 exit_player_with_rc(MSGTR_Exit_eof, 0);
4014 return 1;