help_mp-hu.h synced with r19462
[mplayer/greg.git] / mplayer.c
blob98ca062461a7a46d2d9a43dbe3163dfe7a60d429
2 /// \file
3 /// \ingroup Properties Command2Property OSDMsgStack
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "config.h"
9 #ifdef WIN32
10 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
11 #include <windows.h>
12 #endif
13 #include <string.h>
14 #include <unistd.h>
16 // #include <sys/mman.h>
17 #include <sys/types.h>
18 #ifndef __MINGW32__
19 #include <sys/ioctl.h>
20 #include <sys/wait.h>
21 #else
22 #define SIGHUP 1 /* hangup */
23 #define SIGQUIT 3 /* quit */
24 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
25 #define SIGBUS 10 /* bus error */
26 #define SIGPIPE 13 /* broken pipe */
27 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
28 #endif
30 #include <sys/time.h>
31 #include <sys/stat.h>
33 #include <signal.h>
34 #include <time.h>
35 #include <fcntl.h>
36 #include <limits.h>
38 #include <errno.h>
40 #include "version.h"
42 #include "mp_msg.h"
44 #define HELP_MP_DEFINE_STATIC
45 #include "help_mp.h"
47 #include "m_option.h"
48 #include "m_config.h"
49 #include "m_property.h"
51 #include "cfg-mplayer-def.h"
53 #ifdef USE_SUB
54 #include "subreader.h"
55 #endif
57 #include "libvo/video_out.h"
59 #include "libvo/font_load.h"
60 #include "libvo/sub.h"
62 #ifdef HAVE_X11
63 #include "libvo/x11_common.h"
64 #endif
66 #include "libao2/audio_out.h"
68 #include "codec-cfg.h"
70 #include "edl.h"
72 #include "spudec.h"
73 #include "vobsub.h"
75 #include "osdep/getch2.h"
76 #include "osdep/timer.h"
78 #include "cpudetect.h"
80 #ifdef HAVE_NEW_GUI
81 #include "Gui/interface.h"
82 #endif
84 #include "input/input.h"
86 int slave_mode=0;
87 int player_idle_mode=0;
88 extern int verbose;
89 int quiet=0;
91 #ifdef WIN32
92 char * proc_priority=NULL;
93 #endif
95 #define ABS(x) (((x)>=0)?(x):(-(x)))
96 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
98 #ifdef HAVE_RTC
99 #ifdef __linux__
100 #include <linux/rtc.h>
101 #else
102 #include <rtc.h>
103 #define RTC_IRQP_SET RTCIO_IRQP_SET
104 #define RTC_PIE_ON RTCIO_PIE_ON
105 #endif /* __linux__ */
106 #endif /* HAVE_RTC */
108 #ifdef USE_TV
109 #include "stream/tv.h"
110 #endif
112 #ifdef HAS_DVBIN_SUPPORT
113 #include "stream/dvbin.h"
114 static int last_dvb_step = 1;
115 static int dvbin_reopen = 0;
116 extern void cache_uninit(stream_t *s);
117 #endif
119 //**************************************************************************//
120 // Playtree
121 //**************************************************************************//
122 #include "playtree.h"
123 #include "playtreeparser.h"
125 #ifdef HAVE_NEW_GUI
126 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
127 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
128 #endif
130 play_tree_t* playtree;
131 play_tree_iter_t* playtree_iter = NULL;
132 static int play_tree_step = 1;
134 #define PT_NEXT_ENTRY 1
135 #define PT_PREV_ENTRY -1
136 #define PT_NEXT_SRC 2
137 #define PT_PREV_SRC -2
138 #define PT_UP_NEXT 3
139 #define PT_UP_PREV -3
141 //**************************************************************************//
142 // Config
143 //**************************************************************************//
144 m_config_t* mconfig;
146 extern play_tree_t*
147 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
148 extern int
149 m_config_parse_config_file(m_config_t* config, char *conffile);
151 //**************************************************************************//
152 // Config file
153 //**************************************************************************//
155 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
157 static int cfg_include(m_option_t *conf, char *filename){
158 return m_config_parse_config_file(mconfig, filename);
161 #include "get_path.c"
163 //**************************************************************************//
164 // XScreensaver
165 //**************************************************************************//
167 #ifdef HAVE_X11
168 void xscreensaver_heartbeat(void);
169 #endif
171 //**************************************************************************//
172 //**************************************************************************//
173 // Input media streaming & demultiplexer:
174 //**************************************************************************//
176 static int max_framesize=0;
178 #include "stream/stream.h"
179 #include "libmpdemux/demuxer.h"
180 #include "libmpdemux/stheader.h"
181 //#include "parse_es.h"
182 #include "libmpdemux/matroska.h"
184 #ifdef USE_DVDREAD
185 #include "stream/stream_dvd.h"
186 #endif
188 #include "libmpcodecs/dec_audio.h"
189 #include "libmpcodecs/dec_video.h"
190 #include "libmpcodecs/mp_image.h"
191 #include "libmpcodecs/vf.h"
192 #include "libmpcodecs/vd.h"
194 extern void vf_list_plugins(void);
196 //**************************************************************************//
197 //**************************************************************************//
199 // Common FIFO functions, and keyboard/event FIFO code
200 #include "fifo.c"
201 int noconsolecontrols=0;
202 //**************************************************************************//
204 vo_functions_t *video_out=NULL;
205 ao_functions_t *audio_out=NULL;
207 int fixed_vo=0;
208 int eof=0;
210 // benchmark:
211 double video_time_usage=0;
212 double vout_time_usage=0;
213 static double audio_time_usage=0;
214 static int total_time_usage_start=0;
215 static int total_frame_cnt=0;
216 static int drop_frame_cnt=0; // total number of dropped frames
217 int benchmark=0;
219 // options:
220 int auto_quality=0;
221 static int output_quality=0;
223 float playback_speed=1.0;
225 int use_gui=0;
227 #ifdef HAVE_NEW_GUI
228 int enqueue=0;
229 #endif
231 static int list_properties = 0;
233 #define MAX_OSD_LEVEL 3
234 #define MAX_TERM_OSD_LEVEL 1
236 int osd_level=1;
237 int osd_level_saved=-1;
238 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
239 unsigned int osd_visible;
240 static int osd_function=OSD_PLAY;
241 static int osd_show_percentage = 0;
242 static int osd_duration = 1000;
244 static int term_osd = 1;
245 static char* term_osd_esc = "\x1b[A\r\x1b[K";
246 static char* playing_msg = NULL;
247 // seek:
248 static char *seek_to_sec=NULL;
249 static off_t seek_to_byte=0;
250 static off_t step_sec=0;
251 static int loop_times=-1;
252 static int loop_seek=0;
254 // A/V sync:
255 int autosync=0; // 30 might be a good default value.
257 // may be changed by GUI: (FIXME!)
258 float rel_seek_secs=0;
259 int abs_seek_pos=0;
261 // codecs:
262 char **audio_codec_list=NULL; // override audio codec
263 char **video_codec_list=NULL; // override video codec
264 char **audio_fm_list=NULL; // override audio codec family
265 char **video_fm_list=NULL; // override video codec family
267 // demuxer:
268 extern char *demuxer_name; // override demuxer
269 extern char *audio_demuxer_name; // override audio demuxer
270 extern char *sub_demuxer_name; // override sub demuxer
272 // streaming:
273 int audio_id=-1;
274 int video_id=-1;
275 int dvdsub_id=-2;
276 int vobsub_id=-1;
277 char* audio_lang=NULL;
278 char* dvdsub_lang=NULL;
279 static char* spudec_ifo=NULL;
280 char* filename=NULL; //"MI2-Trailer.avi";
281 int forced_subs_only=0;
283 // cache2:
284 int stream_cache_size=-1;
285 #ifdef USE_STREAM_CACHE
286 extern int cache_fill_status;
288 float stream_cache_min_percent=20.0;
289 float stream_cache_seek_min_percent=50.0;
290 #else
291 #define cache_fill_status 0
292 #endif
294 // dump:
295 static char *stream_dump_name="stream.dump";
296 int stream_dump_type=0;
298 // A-V sync:
299 static float default_max_pts_correction=-1;//0.01f;
300 static float max_pts_correction=0;//default_max_pts_correction;
301 static float c_total=0;
302 float audio_delay=0;
303 static int ignore_start=0;
305 static int softsleep=0;
307 float force_fps=0;
308 static int force_srate=0;
309 static int audio_output_format=0;
310 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
311 static int play_n_frames=-1;
312 static int play_n_frames_mf=-1;
314 // screen info:
315 char** video_driver_list=NULL;
316 char** audio_driver_list=NULL;
318 extern char *vo_subdevice;
319 extern char *ao_subdevice;
321 // codec outfmt flags (defined in libmpcodecs/vd.c)
322 extern int vo_flags;
324 // sub:
325 char *font_name=NULL;
326 #ifdef HAVE_FONTCONFIG
327 extern int font_fontconfig;
328 #endif
329 float font_factor=0.75;
330 char **sub_name=NULL;
331 float sub_delay=0;
332 float sub_fps=0;
333 int sub_auto = 1;
334 char *vobsub_name=NULL;
335 /*DSP!!char *dsp=NULL;*/
336 int subcc_enabled=0;
337 int suboverlap_enabled = 1;
338 #ifdef USE_SUB
339 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
340 int set_of_sub_size = 0;
341 int set_of_sub_pos = -1;
342 float sub_last_pts = -303;
343 #endif
344 int global_sub_size = 0; // this encompasses all subtitle sources
345 int global_sub_pos = -1; // this encompasses all subtitle sources
346 #define SUB_SOURCE_SUBS 0
347 #define SUB_SOURCE_VOBSUB 1
348 #define SUB_SOURCE_DEMUX 2
349 #define SUB_SOURCES 3
350 int global_sub_indices[SUB_SOURCES];
352 #ifdef USE_ASS
353 #include "libass/ass.h"
354 #include "libass/ass_mp.h"
356 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
357 // or NULL if format unsupported
358 ass_track_t* set_of_ass_tracks[MAX_SUBTITLE_FILES];
359 ass_track_t* ass_track = 0; // current track to render
360 #endif
362 extern int mp_msg_levels[MSGT_MAX];
363 extern int mp_msg_level_all;
365 static stream_t* stream=NULL;
366 static demuxer_t *demuxer=NULL;
367 static sh_audio_t *sh_audio=NULL;
368 static sh_video_t *sh_video=NULL;
369 static demux_stream_t *d_audio=NULL;
370 static demux_stream_t *d_video=NULL;
371 static demux_stream_t *d_dvdsub=NULL;
373 char* current_module=NULL; // for debugging
375 extern int vo_gamma_gamma;
376 extern int vo_gamma_brightness;
377 extern int vo_gamma_contrast;
378 extern int vo_gamma_saturation;
379 extern int vo_gamma_hue;
381 // ---
383 #ifdef HAVE_MENU
384 #include "m_struct.h"
385 #include "libmenu/menu.h"
386 extern void vf_menu_pause_update(struct vf_instance_s* vf);
387 extern vf_info_t vf_info_menu;
388 static vf_info_t* libmenu_vfs[] = {
389 &vf_info_menu,
390 NULL
392 static vf_instance_t* vf_menu = NULL;
393 static int use_menu = 0;
394 static char* menu_cfg = NULL;
395 static char* menu_root = "main";
396 #endif
399 #ifdef HAVE_RTC
400 static int nortc;
401 static char* rtc_device;
402 #endif
404 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
405 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
406 short user_muted = 0; ///< Stores whether user wanted muted mode.
407 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
408 short edl_decision = 0; ///< 1 when an EDL operation has been made.
409 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode.
410 float begin_skip = MP_NOPTS_VALUE; ///< start time of the current skip while on edlout mode
412 static unsigned int inited_flags=0;
413 #define INITED_VO 1
414 #define INITED_AO 2
415 #define INITED_GUI 4
416 #define INITED_GETCH2 8
417 #define INITED_SPUDEC 32
418 #define INITED_STREAM 64
419 #define INITED_INPUT 128
420 #define INITED_VOBSUB 256
421 #define INITED_DEMUXER 512
422 #define INITED_ACODEC 1024
423 #define INITED_VCODEC 2048
424 #define INITED_ALL 0xFFFF
426 static void uninit_player(unsigned int mask){
427 mask=inited_flags&mask;
429 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
431 if(mask&INITED_ACODEC){
432 inited_flags&=~INITED_ACODEC;
433 current_module="uninit_acodec";
434 if(sh_audio) uninit_audio(sh_audio);
435 #ifdef HAVE_NEW_GUI
436 guiGetEvent(guiSetAfilter, (char *)NULL);
437 #endif
438 sh_audio=NULL;
441 if(mask&INITED_VCODEC){
442 inited_flags&=~INITED_VCODEC;
443 current_module="uninit_vcodec";
444 if(sh_video) uninit_video(sh_video);
445 sh_video=NULL;
446 #ifdef HAVE_MENU
447 vf_menu=NULL;
448 #endif
451 if(mask&INITED_DEMUXER){
452 inited_flags&=~INITED_DEMUXER;
453 current_module="free_demuxer";
454 if(demuxer){
455 stream=demuxer->stream;
456 free_demuxer(demuxer);
458 demuxer=NULL;
461 // kill the cache process:
462 if(mask&INITED_STREAM){
463 inited_flags&=~INITED_STREAM;
464 current_module="uninit_stream";
465 if(stream) free_stream(stream);
466 stream=NULL;
469 if(mask&INITED_VO){
470 inited_flags&=~INITED_VO;
471 current_module="uninit_vo";
472 video_out->uninit();
473 video_out=NULL;
476 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
477 if(mask&INITED_GETCH2){
478 inited_flags&=~INITED_GETCH2;
479 current_module="uninit_getch2";
480 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
481 // restore terminal:
482 getch2_disable();
485 if(mask&INITED_VOBSUB){
486 inited_flags&=~INITED_VOBSUB;
487 current_module="uninit_vobsub";
488 if(vo_vobsub) vobsub_close(vo_vobsub);
489 vo_vobsub=NULL;
492 if (mask&INITED_SPUDEC){
493 inited_flags&=~INITED_SPUDEC;
494 current_module="uninit_spudec";
495 spudec_free(vo_spudec);
496 vo_spudec=NULL;
499 if(mask&INITED_AO){
500 inited_flags&=~INITED_AO;
501 current_module="uninit_ao";
502 audio_out->uninit(eof?0:1); audio_out=NULL;
505 #ifdef HAVE_NEW_GUI
506 if(mask&INITED_GUI){
507 inited_flags&=~INITED_GUI;
508 current_module="uninit_gui";
509 guiDone();
511 #endif
513 if(mask&INITED_INPUT){
514 inited_flags&=~INITED_INPUT;
515 current_module="uninit_input";
516 mp_input_uninit();
519 current_module=NULL;
522 static void exit_player_with_rc(const char* how, int rc){
524 uninit_player(INITED_ALL);
525 #ifdef HAVE_X11
526 #ifdef HAVE_NEW_GUI
527 if ( !use_gui )
528 #endif
529 vo_uninit(); // Close the X11 connection (if any is open).
530 #endif
532 #ifdef HAVE_FREETYPE
533 current_module="uninit_font";
534 if (vo_font) free_font_desc(vo_font);
535 vo_font = NULL;
536 done_freetype();
537 #endif
538 free_osd_list();
540 current_module="exit_player";
542 // free mplayer config
543 if(mconfig)
544 m_config_free(mconfig);
546 if(playtree)
547 play_tree_free(playtree, 1);
550 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
551 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,how);
552 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
554 exit(rc);
557 void exit_player(const char* how){
558 exit_player_with_rc(how, 1);
561 #ifndef __MINGW32__
562 static void child_sighandler(int x){
563 pid_t pid;
564 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
566 #endif
568 #ifdef CRASH_DEBUG
569 static char *prog_path;
570 static int crash_debug = 0;
571 #endif
573 static void exit_sighandler(int x){
574 static int sig_count=0;
575 #ifdef CRASH_DEBUG
576 if (!crash_debug || x != SIGTRAP)
577 #endif
578 ++sig_count;
579 if(inited_flags==0 && sig_count>1) exit(1);
580 if(sig_count==5)
582 /* We're crashing bad and can't uninit cleanly :(
583 * by popular request, we make one last (dirty)
584 * effort to restore the user's
585 * terminal. */
586 getch2_disable();
587 exit(1);
589 if(sig_count==6) exit(1);
590 if(sig_count>6){
591 // can't stop :(
592 #ifndef __MINGW32__
593 kill(getpid(),SIGKILL);
594 #endif
596 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
597 current_module?current_module:"unknown"
599 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x);
600 if(sig_count<=1)
601 switch(x){
602 case SIGINT:
603 case SIGQUIT:
604 case SIGTERM:
605 case SIGKILL:
606 break; // killed from keyboard (^C) or killed [-9]
607 case SIGILL:
608 #ifdef RUNTIME_CPUDETECT
609 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
610 #else
611 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
612 #endif
613 case SIGFPE:
614 case SIGSEGV:
615 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
616 default:
617 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
618 #ifdef CRASH_DEBUG
619 if (crash_debug) {
620 int gdb_pid;
621 char spid[20];
622 snprintf(spid, 19, "%i", getpid());
623 spid[19] = 0;
624 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
625 gdb_pid = fork();
626 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
627 if (gdb_pid == 0) { // We are the child
628 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
629 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
630 } else if (gdb_pid < 0)
631 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
632 else {
633 waitpid(gdb_pid, NULL, 0);
635 if (x == SIGTRAP) return;
637 #endif
639 exit_player(NULL);
642 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
644 extern void mp_input_register_options(m_config_t* cfg);
646 #include "mixer.h"
647 mixer_t mixer;
648 /// step size of mixer changes
649 int volstep = 3;
651 #include "cfg-mplayer.h"
653 static void parse_cfgfiles( m_config_t* conf )
655 char *conffile;
656 int conffile_fd;
657 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
658 exit_player(NULL);
659 if ((conffile = get_path("")) == NULL) {
660 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
661 } else {
662 #ifdef __MINGW32__
663 mkdir(conffile);
664 #else
665 mkdir(conffile, 0777);
666 #endif
667 free(conffile);
668 if ((conffile = get_path("config")) == NULL) {
669 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
670 } else {
671 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
672 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
673 write(conffile_fd, default_config, strlen(default_config));
674 close(conffile_fd);
676 if (m_config_parse_config_file(conf, conffile) < 0)
677 exit_player(NULL);
678 free(conffile);
683 void load_per_file_config (m_config_t* conf, const char *const file)
685 char *confpath;
686 char cfg[strlen(file)+10];
687 struct stat st;
688 char *name;
690 sprintf (cfg, "%s.conf", file);
692 if (!stat (cfg, &st))
694 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
695 m_config_parse_config_file (conf, cfg);
696 return;
699 if ((name = strrchr (cfg, '/')) == NULL)
700 name = cfg;
701 else
702 name++;
704 if ((confpath = get_path (name)) != NULL)
706 if (!stat (confpath, &st))
708 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
709 m_config_parse_config_file (conf, confpath);
712 free (confpath);
716 /* When libmpdemux performs a blocking operation (network connection or
717 * cache filling) if the operation fails we use this function to check
718 * if it was interrupted by the user.
719 * The function returns a new value for eof. */
720 static int libmpdemux_was_interrupted(int eof) {
721 mp_cmd_t* cmd;
722 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
723 switch(cmd->id) {
724 case MP_CMD_QUIT:
725 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
726 case MP_CMD_PLAY_TREE_STEP: {
727 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
728 play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i;
729 } break;
730 case MP_CMD_PLAY_TREE_UP_STEP: {
731 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
732 } break;
733 case MP_CMD_PLAY_ALT_SRC_STEP: {
734 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
735 } break;
737 mp_cmd_free(cmd);
739 return eof;
742 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
743 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
745 int playtree_add_playlist(play_tree_t* entry)
747 play_tree_add_bpf(entry,filename);
749 #ifdef HAVE_NEW_GUI
750 if (use_gui) {
751 if (entry) {
752 import_playtree_playlist_into_gui(entry, mconfig);
753 play_tree_free_list(entry,1);
755 } else
756 #endif
758 if(!entry) {
759 entry = playtree_iter->tree;
760 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
761 return PT_NEXT_ENTRY;
763 if(playtree_iter->tree == entry ) { // Loop with a single file
764 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
765 return PT_NEXT_ENTRY;
768 play_tree_remove(entry,1,1);
769 return PT_NEXT_SRC;
771 play_tree_insert_entry(playtree_iter->tree,entry);
772 play_tree_set_params_from(entry,playtree_iter->tree);
773 entry = playtree_iter->tree;
774 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
775 return PT_NEXT_ENTRY;
777 play_tree_remove(entry,1,1);
779 return PT_NEXT_SRC;
782 int sub_source(void)
784 int source = -1;
785 int top = -1;
786 int i;
787 for (i = 0; i < SUB_SOURCES; i++) {
788 int j = global_sub_indices[i];
789 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
790 source = i;
791 top = j;
794 return source;
797 #ifdef USE_SUB
799 sub_data* subdata = NULL;
800 static subtitle* vo_sub_last = NULL;
802 void add_subtitles(char *filename, float fps, int silent)
804 sub_data *subd;
805 #ifdef USE_ASS
806 ass_track_t *asst = 0;
807 #endif
809 if (filename == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) {
810 return;
813 subd = sub_read_file(filename, fps);
814 #ifdef USE_ASS
815 if (ass_enabled)
816 asst = ass_read_file(filename);
817 if (ass_enabled && !asst)
818 asst = ass_read_subdata(subd, fps);
820 if (!asst && !subd && !silent)
821 #else
822 if(!subd && !silent)
823 #endif
824 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
826 #ifdef USE_ASS
827 if (!asst && !subd) return;
828 set_of_ass_tracks[set_of_sub_size] = asst;
829 #else
830 if (!subd) return;
831 #endif
832 set_of_subtitles[set_of_sub_size] = subd;
833 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
834 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
835 ++set_of_sub_size;
836 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
839 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
840 void update_set_of_subtitles(void)
841 // subdata was changed, set_of_sub... have to be updated.
843 int i;
844 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
845 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
846 set_of_subtitles[i-1] = set_of_subtitles[i];
847 set_of_subtitles[set_of_sub_size-1] = NULL;
848 --set_of_sub_size;
849 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
851 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
852 set_of_subtitles[set_of_sub_pos] = subdata;
854 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
855 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
856 ++set_of_sub_size;
859 #endif /* USE_SUB */
862 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
863 * make it all work is to use the builtin SDL-bootstrap code, which
864 * will be done automatically by replacing our main() if we include SDL.h.
866 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
867 #include <SDL.h>
868 #endif
871 * \brief append a formatted string
872 * \param buf buffer to print into
873 * \param pos position of terminating 0 in buf
874 * \param len maximum number of characters in buf, not including terminating 0
875 * \param format printf format string
877 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
879 va_list va;
880 va_start(va, format);
881 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
882 va_end(va);
883 if (*pos >= len ) {
884 buf[len] = 0;
885 *pos = len;
890 * \brief append time in the hh:mm:ss.f format
891 * \param buf buffer to print into
892 * \param pos position of terminating 0 in buf
893 * \param len maximum number of characters in buf, not including terminating 0
894 * \param time time value to convert/append
896 static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) {
897 long tenths = 10 * time;
898 int f1 = tenths % 10;
899 int ss = (tenths / 10) % 60;
900 int mm = (tenths / 600) % 60;
901 int hh = tenths / 36000;
902 if (time <= 0) {
903 saddf(buf, pos, len, "unknown");
904 return;
906 if (hh > 0)
907 saddf(buf, pos, len, "%2d:", hh);
908 if (hh > 0 || mm > 0)
909 saddf(buf, pos, len, "%02d:", mm);
910 saddf(buf, pos, len, "%02d.%1d", ss, f1);
914 * \brief print the status line
915 * \param a_pos audio position
916 * \param a_v A-V desynchronization
917 * \param corr amount out A-V synchronization
919 static void print_status(float a_pos, float a_v, float corr)
921 int width;
922 char *line;
923 unsigned pos = 0;
924 get_screen_size();
925 if (screen_width > 0)
926 width = screen_width;
927 else
928 width = 80;
929 #ifdef WIN32
930 /* Windows command line is broken (MinGW's rxvt works, but we
931 * should not depend on that). */
932 width--;
933 #endif
934 line = malloc(width + 1); // one additional char for the terminating null
936 // Audio time
937 if (sh_audio) {
938 saddf(line, &pos, width, "A:%6.1f ", a_pos);
939 if (!sh_video) {
940 float len = demuxer_get_time_length(demuxer);
941 saddf(line, &pos, width, "(");
942 sadd_hhmmssf(line, &pos, width, a_pos);
943 saddf(line, &pos, width, ") of %.1f (", len);
944 sadd_hhmmssf(line, &pos, width, len);
945 saddf(line, &pos, width, ") ");
949 // Video time
950 if (sh_video)
951 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
953 // A-V sync
954 if (sh_audio && sh_video)
955 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
957 // Video stats
958 if (sh_video)
959 saddf(line, &pos, width, "%3d/%3d ",
960 (int)sh_video->num_frames,
961 (int)sh_video->num_frames_decoded);
963 // CPU usage
964 if (sh_video) {
965 if (sh_video->timer > 0.5)
966 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
967 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
968 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
969 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
970 else
971 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
972 } else if (sh_audio) {
973 if (sh_audio->delay > 0.5)
974 saddf(line, &pos, width, "%4.1f%% ",
975 100.0*audio_time_usage/(double)sh_audio->delay);
976 else
977 saddf(line, &pos, width, "??,?%% ");
980 // VO stats
981 if (sh_video)
982 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
984 #ifdef USE_STREAM_CACHE
985 // cache stats
986 if (stream_cache_size > 0)
987 saddf(line, &pos, width, "%d%% ", cache_fill_status);
988 #endif
990 // other
991 if (playback_speed != 1)
992 saddf(line, &pos, width, "%4.2fx ", playback_speed);
994 // end
995 if (erase_to_end_of_line) {
996 line[pos] = 0;
997 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s%s\r", line, erase_to_end_of_line);
998 } else {
999 memset(&line[pos], ' ', width - pos);
1000 line[width] = 0;
1001 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
1003 free(line);
1007 * \brief build a chain of audio filters that converts the input format
1008 * to the ao's format, taking into account the current playback_speed.
1009 * \param sh_audio describes the requested input format of the chain.
1010 * \param ao_data describes the requested output format of the chain.
1012 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
1014 int new_srate;
1015 int result;
1016 if (!sh_audio)
1018 #ifdef HAVE_NEW_GUI
1019 guiGetEvent(guiSetAfilter, (char *)NULL);
1020 #endif
1021 mixer.afilter = NULL;
1022 return 0;
1024 new_srate = sh_audio->samplerate * playback_speed;
1025 if (new_srate != ao_data->samplerate) {
1026 // limits are taken from libaf/af_resample.c
1027 if (new_srate < 8000)
1028 new_srate = 8000;
1029 if (new_srate > 192000)
1030 new_srate = 192000;
1031 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
1033 result = init_audio_filters(sh_audio, new_srate,
1034 sh_audio->channels, sh_audio->sample_format,
1035 &ao_data->samplerate, &ao_data->channels, &ao_data->format,
1036 ao_data->outburst * 4, ao_data->buffersize);
1037 mixer.afilter = sh_audio->afilter;
1038 #ifdef HAVE_NEW_GUI
1039 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter);
1040 #endif
1041 return result;
1044 #ifdef USE_SUB
1046 * \brief Log the currently displayed subtitle to a file
1048 * Logs the current or last displayed subtitle together with filename
1049 * and time information to ~/.mplayer/subtitle_log
1051 * Intended purpose is to allow convenient marking of bogus subtitles
1052 * which need to be fixed while watching the movie.
1055 static void log_sub(void){
1056 char *fname;
1057 FILE *f;
1058 int i;
1060 if (subdata == NULL || vo_sub_last == NULL) return;
1061 fname = get_path("subtitle_log");
1062 f = fopen(fname, "a");
1063 if (!f) return;
1064 fprintf(f, "----------------------------------------------------------\n");
1065 if (subdata->sub_uses_time) {
1066 fprintf(f, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename,
1067 vo_sub_last->start/360000, (vo_sub_last->start/6000)%60,
1068 (vo_sub_last->start/100)%60, vo_sub_last->start%100,
1069 vo_sub_last->end/360000, (vo_sub_last->end/6000)%60,
1070 (vo_sub_last->end/100)%60, vo_sub_last->end%100);
1071 } else {
1072 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start, vo_sub_last->end);
1074 for (i = 0; i < vo_sub_last->lines; i++) {
1075 fprintf(f, "%s\n", vo_sub_last->text[i]);
1077 fclose(f);
1079 #endif /* USE_SUB */
1081 /// \defgroup OSDMsgStack OSD message stack
1083 ///@{
1085 #define OSD_MSG_TV_CHANNEL 0
1086 #define OSD_MSG_TEXT 1
1087 #define OSD_MSG_SUB_DELAY 2
1088 #define OSD_MSG_SPEED 3
1089 #define OSD_MSG_OSD_STATUS 4
1090 #define OSD_MSG_BAR 5
1091 #define OSD_MSG_PAUSE 6
1092 /// Base id for messages generated from the commmand to property bridge.
1093 #define OSD_MSG_PROPERTY 0x100
1096 typedef struct mp_osd_msg mp_osd_msg_t;
1097 struct mp_osd_msg {
1098 /// Previous message on the stack.
1099 mp_osd_msg_t* prev;
1100 /// Message text.
1101 char msg[64];
1102 int id,level,started;
1103 /// Display duration in ms.
1104 unsigned time;
1107 /// OSD message stack.
1108 static mp_osd_msg_t* osd_msg_stack = NULL;
1111 * \brief Add a message on the OSD message stack
1113 * If a message with the same id is already present in the stack
1114 * it is pulled on top of the stack, otherwise a new message is created.
1118 static void set_osd_msg(int id, int level, int time, const char* fmt, ...) {
1119 mp_osd_msg_t *msg,*last=NULL;
1120 va_list va;
1121 int r;
1123 // look if the id is already in the stack
1124 for(msg = osd_msg_stack ; msg && msg->id != id ;
1125 last = msg, msg = msg->prev);
1126 // not found: alloc it
1127 if(!msg) {
1128 msg = calloc(1,sizeof(mp_osd_msg_t));
1129 msg->prev = osd_msg_stack;
1130 osd_msg_stack = msg;
1131 } else if(last) { // found, but it's not on top of the stack
1132 last->prev = msg->prev;
1133 msg->prev = osd_msg_stack;
1134 osd_msg_stack = msg;
1136 // write the msg
1137 va_start(va,fmt);
1138 r = vsnprintf(msg->msg, 64, fmt, va);
1139 va_end(va);
1140 if(r >= 64) msg->msg[63] = 0;
1141 // set id and time
1142 msg->id = id;
1143 msg->level = level;
1144 msg->time = time;
1149 * \brief Remove a message from the OSD stack
1151 * This function can be used to get rid of a message right away.
1155 static void rm_osd_msg(int id) {
1156 mp_osd_msg_t *msg,*last=NULL;
1158 // Search for the msg
1159 for(msg = osd_msg_stack ; msg && msg->id != id ;
1160 last = msg, msg = msg->prev);
1161 if(!msg) return;
1163 // Detach it from the stack and free it
1164 if(last)
1165 last->prev = msg->prev;
1166 else
1167 osd_msg_stack = msg->prev;
1168 free(msg);
1172 * \brief Remove all messages from the OSD stack
1176 static void clear_osd_msgs(void) {
1177 mp_osd_msg_t* msg = osd_msg_stack, *prev = NULL;
1178 while(msg) {
1179 prev = msg->prev;
1180 free(msg);
1181 msg = prev;
1183 osd_msg_stack = NULL;
1187 * \brief Get the current message from the OSD stack.
1189 * This function decrements the message timer and destroys the old ones.
1190 * The message that should be displayed is returned (if any).
1194 static mp_osd_msg_t* get_osd_msg(void) {
1195 mp_osd_msg_t *msg,*prev,*last = NULL;
1196 static unsigned last_update = 0;
1197 unsigned now = GetTimerMS();
1198 unsigned diff;
1199 char hidden_dec_done = 0;
1201 if(!last_update) last_update = now;
1202 diff = now >= last_update ? now - last_update : 0;
1204 last_update = now;
1206 // Look for the first message in the stack with high enough level.
1207 for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) {
1208 prev = msg->prev;
1209 if(msg->level > osd_level && hidden_dec_done) continue;
1210 // The message has a high enough level or it is the first hidden one
1211 // in both cases we decrement the timer or kill it.
1212 if(!msg->started || msg->time > diff) {
1213 if(msg->started) msg->time -= diff;
1214 else msg->started = 1;
1215 // display it
1216 if(msg->level <= osd_level) return msg;
1217 hidden_dec_done = 1;
1218 continue;
1220 // kill the message
1221 free(msg);
1222 if(last) {
1223 last->prev = prev;
1224 msg = last;
1225 } else {
1226 osd_msg_stack = prev;
1227 msg = NULL;
1230 // Nothing found
1231 return NULL;
1234 // Make a define to test if we are using the term OSD without having
1235 // to #ifdef USE_OSD all the time.
1236 #ifdef USE_OSD
1237 #define use_term_osd (term_osd && !sh_video)
1238 #else
1239 #define use_term_osd (term_osd)
1240 #endif
1243 * \brief Display the OSD bar.
1245 * Display the OSD bar or fall back on a simple message.
1249 void set_osd_bar(int type,const char* name,double min,double max,double val) {
1251 if(osd_level < 1) return;
1253 #ifdef USE_OSD
1254 if(sh_video) {
1255 osd_visible = (GetTimerMS() + 1000) | 1;
1256 vo_osd_progbar_type = type;
1257 vo_osd_progbar_value = 256*(val-min)/(max-min);
1258 vo_osd_changed(OSDTYPE_PROGBAR);
1259 return;
1261 #endif
1263 set_osd_msg(OSD_MSG_BAR,1,osd_duration,"%s: %d %%",
1264 name,ROUND(100*(val-min)/(max-min)));
1269 * \brief Update the OSD message line.
1271 * This function displays the current message on the vo OSD or on the term.
1272 * If the stack is empty and the OSD level is high enough the timer
1273 * is displayed (only on the vo OSD).
1277 static void update_osd_msg(void) {
1278 mp_osd_msg_t *msg;
1279 static char osd_text[64] = "";
1280 static char osd_text_timer[64];
1282 #ifdef USE_OSD
1283 // we need some mem for vo_osd_text
1284 vo_osd_text = (unsigned char*)osd_text;
1285 #endif
1287 // Look if we have a msg
1288 if((msg = get_osd_msg())) {
1289 if(strcmp(osd_text,msg->msg)) {
1290 strncpy((char*)osd_text, msg->msg, 63);
1291 #ifdef USE_OSD
1292 if(sh_video) vo_osd_changed(OSDTYPE_OSD); else
1293 #endif
1294 if(term_osd) printf("%s%s\n",term_osd_esc,msg->msg);
1296 return;
1299 #ifdef USE_OSD
1300 if(sh_video) {
1301 // fallback on the timer
1302 if(osd_level>=2) {
1303 int len = demuxer_get_time_length(demuxer);
1304 int percentage = -1;
1305 char percentage_text[10];
1306 int pts = sh_video->pts;
1308 if (osd_show_percentage)
1309 percentage = demuxer_get_percent_pos(demuxer);
1311 if (percentage >= 0)
1312 snprintf(percentage_text, 9, " (%d%%)", percentage);
1313 else
1314 percentage_text[0] = 0;
1316 if (osd_level == 3)
1317 snprintf(osd_text_timer, 63,
1318 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1319 osd_function,pts/3600,(pts/60)%60,pts%60,
1320 len/3600,(len/60)%60,len%60,percentage_text);
1321 else
1322 snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s",
1323 osd_function,pts/3600,(pts/60)%60,
1324 pts%60,percentage_text);
1325 } else
1326 osd_text_timer[0]=0;
1328 // always decrement the percentage timer
1329 if(osd_show_percentage)
1330 osd_show_percentage--;
1332 if(strcmp(osd_text,osd_text_timer)) {
1333 strncpy(osd_text, osd_text_timer, 63);
1334 vo_osd_changed(OSDTYPE_OSD);
1336 return;
1338 #endif
1340 // Clear the term osd line
1341 if(term_osd && osd_text[0]) {
1342 osd_text[0] = 0;
1343 printf("%s\n",term_osd_esc);
1347 ///@}
1348 // OSDMsgStack
1350 /// \defgroup Properties
1351 ///@{
1353 /// \defgroup GeneralProperties General properties
1354 /// \ingroup Properties
1355 ///@{
1357 /// OSD level (RW)
1358 static int mp_property_osdlevel(m_option_t* prop,int action,void* arg) {
1359 return m_property_choice(prop,action,arg,&osd_level);
1362 /// Playback speed (RW)
1363 static int mp_property_playback_speed(m_option_t* prop,int action,void* arg) {
1364 switch(action) {
1365 case M_PROPERTY_SET:
1366 if(!arg) return 0;
1367 M_PROPERTY_CLAMP(prop,*(float*)arg);
1368 playback_speed = *(float*)arg;
1369 build_afilter_chain(sh_audio, &ao_data);
1370 return 1;
1371 case M_PROPERTY_STEP_UP:
1372 case M_PROPERTY_STEP_DOWN:
1373 playback_speed += (arg ? *(float*)arg : 0.1) *
1374 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1375 M_PROPERTY_CLAMP(prop,playback_speed);
1376 build_afilter_chain(sh_audio, &ao_data);
1377 return 1;
1379 return m_property_float_range(prop,action,arg,&playback_speed);
1382 /// filename with path (RO)
1383 static int mp_property_path(m_option_t* prop,int action,void* arg) {
1384 return m_property_string_ro(prop,action,arg,filename);
1387 /// filename without path (RO)
1388 static int mp_property_filename(m_option_t* prop,int action,void* arg) {
1389 char* f;
1390 if(!filename) return M_PROPERTY_UNAVAILABLE;
1391 if(((f = strrchr(filename,'/')) || (f = strrchr(filename,'\\'))) && f[1])
1392 f++;
1393 else
1394 f = filename;
1395 return m_property_string_ro(prop,action,arg,f);
1398 /// Demuxer name (RO)
1399 static int mp_property_demuxer(m_option_t* prop,int action,void* arg) {
1400 if(!demuxer) return M_PROPERTY_UNAVAILABLE;
1401 return m_property_string_ro(prop,action,arg,(char*)demuxer->desc->name);
1404 /// Position in the stream (RW)
1405 static int mp_property_stream_pos(m_option_t* prop,int action,void* arg) {
1406 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1407 if (!arg) return M_PROPERTY_ERROR;
1408 switch (action) {
1409 case M_PROPERTY_GET:
1410 *(off_t*)arg = stream_tell(demuxer->stream);
1411 return M_PROPERTY_OK;
1412 case M_PROPERTY_SET:
1413 M_PROPERTY_CLAMP(prop,*(off_t*)arg);
1414 stream_seek(demuxer->stream, *(off_t*)arg);
1415 return M_PROPERTY_OK;
1417 return M_PROPERTY_NOT_IMPLEMENTED;
1420 /// Stream start offset (RO)
1421 static int mp_property_stream_start(m_option_t* prop,int action,void* arg) {
1422 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1423 switch (action) {
1424 case M_PROPERTY_GET:
1425 *(off_t*)arg = demuxer->stream->start_pos;
1426 return M_PROPERTY_OK;
1428 return M_PROPERTY_NOT_IMPLEMENTED;
1431 /// Stream end offset (RO)
1432 static int mp_property_stream_end(m_option_t* prop,int action,void* arg) {
1433 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1434 switch (action) {
1435 case M_PROPERTY_GET:
1436 *(off_t*)arg = demuxer->stream->end_pos;
1437 return M_PROPERTY_OK;
1439 return M_PROPERTY_NOT_IMPLEMENTED;
1442 /// Stream length (RO)
1443 static int mp_property_stream_length(m_option_t* prop,int action,void* arg) {
1444 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1445 switch (action) {
1446 case M_PROPERTY_GET:
1447 *(off_t*)arg = demuxer->stream->end_pos - demuxer->stream->start_pos;
1448 return M_PROPERTY_OK;
1450 return M_PROPERTY_NOT_IMPLEMENTED;
1453 /// Media length in seconds (RO)
1454 static int mp_property_length(m_option_t* prop,int action,void* arg) {
1455 double len;
1457 if(!demuxer ||
1458 !(int)(len = demuxer_get_time_length(demuxer)))
1459 return M_PROPERTY_UNAVAILABLE;
1461 switch(action) {
1462 case M_PROPERTY_PRINT:
1463 if(!arg) return 0;
1464 else {
1465 int h, m, s = len;
1466 h = s/3600;
1467 s -= h*3600;
1468 m = s/60;
1469 s -= m*60;
1470 *(char**)arg = malloc(20);
1471 if(h > 0) sprintf(*(char**)arg,"%d:%02d:%02d",h,m,s);
1472 else if(m > 0) sprintf(*(char**)arg,"%d:%02d",m,s);
1473 else sprintf(*(char**)arg,"%d",s);
1474 return 1;
1476 break;
1478 return m_property_double_ro(prop,action,arg,len);
1481 ///@}
1483 /// \defgroup AudioProperties Audio properties
1484 /// \ingroup Properties
1485 ///@{
1487 /// Volume (RW)
1488 static int mp_property_volume(m_option_t* prop,int action,void* arg) {
1490 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1492 switch(action) {
1493 case M_PROPERTY_GET:
1494 if(!arg) return 0;
1495 mixer_getbothvolume(&mixer,arg);
1496 return 1;
1497 case M_PROPERTY_PRINT:{
1498 float vol;
1499 if(!arg) return 0;
1500 mixer_getbothvolume(&mixer,&vol);
1501 return m_property_float_range(prop,action,arg,&vol);
1503 case M_PROPERTY_STEP_UP:
1504 case M_PROPERTY_STEP_DOWN:
1505 case M_PROPERTY_SET:
1506 break;
1507 default:
1508 return M_PROPERTY_NOT_IMPLEMENTED;
1511 if (edl_muted) return M_PROPERTY_DISABLED;
1512 user_muted = 0;
1514 switch(action) {
1515 case M_PROPERTY_SET:
1516 if(!arg) return 0;
1517 M_PROPERTY_CLAMP(prop,*(float*)arg);
1518 mixer_setvolume(&mixer,*(float*)arg,*(float*)arg);
1519 return 1;
1520 case M_PROPERTY_STEP_UP:
1521 if(arg && *(float*)arg <= 0)
1522 mixer_decvolume(&mixer);
1523 else
1524 mixer_incvolume(&mixer);
1525 return 1;
1526 case M_PROPERTY_STEP_DOWN:
1527 if(arg && *(float*)arg <= 0)
1528 mixer_incvolume(&mixer);
1529 else
1530 mixer_decvolume(&mixer);
1531 return 1;
1533 return M_PROPERTY_NOT_IMPLEMENTED;
1536 /// Mute (RW)
1537 static int mp_property_mute(m_option_t* prop,int action,void* arg) {
1539 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1541 switch(action) {
1542 case M_PROPERTY_SET:
1543 if(edl_muted) return M_PROPERTY_DISABLED;
1544 if(!arg) return 0;
1545 if((!!*(int*)arg) != mixer.muted)
1546 mixer_mute(&mixer);
1547 user_muted = mixer.muted;
1548 return 1;
1549 case M_PROPERTY_STEP_UP:
1550 case M_PROPERTY_STEP_DOWN:
1551 if(edl_muted) return M_PROPERTY_DISABLED;
1552 mixer_mute(&mixer);
1553 user_muted = mixer.muted;
1554 return 1;
1555 case M_PROPERTY_PRINT:
1556 if(!arg) return 0;
1557 if(edl_muted) {
1558 *(char**)arg = strdup(MSGTR_EnabledEdl);
1559 return 1;
1561 default:
1562 return m_property_flag(prop,action,arg,&mixer.muted);
1567 /// Audio delay (RW)
1568 static int mp_property_audio_delay(m_option_t* prop,int action,void* arg) {
1569 if(!(sh_audio && sh_video)) return M_PROPERTY_UNAVAILABLE;
1570 switch(action) {
1571 case M_PROPERTY_SET:
1572 case M_PROPERTY_STEP_UP:
1573 case M_PROPERTY_STEP_DOWN:
1574 if(!arg) return 0;
1575 else {
1576 float delay = audio_delay;
1577 m_property_delay(prop,action,arg,&audio_delay);
1578 if(sh_audio) sh_audio->delay -= audio_delay-delay;
1580 return 1;
1581 default:
1582 return m_property_delay(prop,action,arg,&audio_delay);
1586 /// Audio codec tag (RO)
1587 static int mp_property_audio_format(m_option_t* prop,int action,void* arg) {
1588 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1589 return m_property_int_ro(prop,action,arg,sh_audio->format);
1592 /// Audio bitrate (RO)
1593 static int mp_property_audio_bitrate(m_option_t* prop,int action,void* arg) {
1594 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1595 return m_property_int_ro(prop,action,arg,sh_audio->i_bps);
1598 /// Samplerate (RO)
1599 static int mp_property_samplerate(m_option_t* prop,int action,void* arg) {
1600 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1601 return m_property_int_ro(prop,action,arg,sh_audio->samplerate);
1604 /// Number of channels (RO)
1605 static int mp_property_channels(m_option_t* prop,int action,void* arg) {
1606 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1607 switch(action) {
1608 case M_PROPERTY_PRINT:
1609 if(!arg) return 0;
1610 switch(sh_audio->channels) {
1611 case 1: *(char**)arg = strdup("mono"); break;
1612 case 2: *(char**)arg = strdup("stereo"); break;
1613 default:
1614 *(char**)arg = malloc(32);
1615 sprintf(*(char**)arg,"%d channels",sh_audio->channels);
1617 return 1;
1619 return m_property_int_ro(prop,action,arg,sh_audio->channels);
1622 ///@}
1624 /// \defgroup VideoProperties Video properties
1625 /// \ingroup Properties
1626 ///@{
1628 /// Fullscreen state (RW)
1629 static int mp_property_fullscreen(m_option_t* prop,int action,void* arg) {
1631 if(!video_out) return M_PROPERTY_UNAVAILABLE;
1633 switch(action) {
1634 case M_PROPERTY_SET:
1635 if(!arg) return 0;
1636 M_PROPERTY_CLAMP(prop,*(int*)arg);
1637 if(vo_fs == !!*(int*)arg) return 1;
1638 case M_PROPERTY_STEP_UP:
1639 case M_PROPERTY_STEP_DOWN:
1640 #ifdef HAVE_NEW_GUI
1641 if(use_gui) guiGetEvent(guiIEvent,(char*)MP_CMD_GUI_FULLSCREEN);
1642 else
1643 #endif
1644 if(vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
1645 return 1;
1646 default:
1647 return m_property_flag(prop,action,arg,&vo_fs);
1651 /// Panscan (RW)
1652 static int mp_property_panscan(m_option_t* prop,int action,void* arg) {
1654 if(!video_out || video_out->control(VOCTRL_GET_PANSCAN,NULL ) != VO_TRUE)
1655 return M_PROPERTY_UNAVAILABLE;
1657 switch(action) {
1658 case M_PROPERTY_SET:
1659 if(!arg) return 0;
1660 M_PROPERTY_CLAMP(prop,*(float*)arg);
1661 vo_panscan = *(float*)arg;
1662 video_out->control(VOCTRL_SET_PANSCAN,NULL);
1663 return 1;
1664 case M_PROPERTY_STEP_UP:
1665 case M_PROPERTY_STEP_DOWN:
1666 vo_panscan += (arg ? *(float*)arg : 0.1) *
1667 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1668 if(vo_panscan > 1) vo_panscan = 1;
1669 else if(vo_panscan < 0) vo_panscan = 0;
1670 video_out->control(VOCTRL_SET_PANSCAN,NULL);
1671 return 1;
1672 default:
1673 return m_property_float_range(prop,action,arg,&vo_panscan);
1677 /// Helper to set vo flags.
1678 /** \ingroup PropertyImplHelper
1680 static int mp_property_vo_flag(m_option_t* prop,int action,void* arg,
1681 int vo_ctrl,int* vo_var) {
1683 if(!video_out) return M_PROPERTY_UNAVAILABLE;
1685 switch(action) {
1686 case M_PROPERTY_SET:
1687 if(!arg) return 0;
1688 M_PROPERTY_CLAMP(prop,*(int*)arg);
1689 if(*vo_var == !!*(int*)arg) return 1;
1690 case M_PROPERTY_STEP_UP:
1691 case M_PROPERTY_STEP_DOWN:
1692 if(vo_config_count) video_out->control(vo_ctrl, 0);
1693 return 1;
1694 default:
1695 return m_property_flag(prop,action,arg,vo_var);
1699 /// Window always on top (RW)
1700 static int mp_property_ontop(m_option_t* prop,int action,void* arg) {
1701 return mp_property_vo_flag(prop,action,arg,VOCTRL_ONTOP,&vo_ontop);
1704 /// Display in the root window (RW)
1705 static int mp_property_rootwin(m_option_t* prop,int action,void* arg) {
1706 return mp_property_vo_flag(prop,action,arg,VOCTRL_ROOTWIN,&vo_rootwin);
1709 /// Show window borders (RW)
1710 static int mp_property_border(m_option_t* prop,int action,void* arg) {
1711 return mp_property_vo_flag(prop,action,arg,VOCTRL_BORDER,&vo_border);
1714 /// Framedropping state (RW)
1715 static int mp_property_framedropping(m_option_t* prop,int action,void* arg) {
1717 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1719 switch(action) {
1720 case M_PROPERTY_PRINT:
1721 if(!arg) return 0;
1722 *(char**)arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1723 (frame_dropping == 2 ? MSGTR_HardFrameDrop : MSGTR_Disabled));
1724 return 1;
1725 default:
1726 return m_property_choice(prop,action,arg,&frame_dropping);
1730 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1731 static int mp_property_gamma(m_option_t* prop,int action,void* arg) {
1732 int* gamma = prop->priv, r;
1734 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1736 if(gamma[0] == 1000) {
1737 gamma[0] = 0;
1738 get_video_colors (sh_video, prop->name, gamma);
1741 switch(action) {
1742 case M_PROPERTY_SET:
1743 if(!arg) return 0;
1744 M_PROPERTY_CLAMP(prop,*(int*)arg);
1745 *gamma = *(int*)arg;
1746 r = set_video_colors(sh_video, prop->name, *gamma);
1747 if(r <= 0) break;
1748 return r;
1749 case M_PROPERTY_GET:
1750 if(!arg) return 0;
1751 r = get_video_colors (sh_video, prop->name, arg);
1752 if(r <= 0) break;
1753 return r;
1754 case M_PROPERTY_STEP_UP:
1755 case M_PROPERTY_STEP_DOWN:
1756 *gamma += (arg ? *(int*)arg : 1) *
1757 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1758 M_PROPERTY_CLAMP(prop,*gamma);
1759 r = set_video_colors(sh_video, prop->name, *gamma);
1760 if(r <= 0) break;
1761 return r;
1762 default:
1763 return M_PROPERTY_NOT_IMPLEMENTED;
1766 #ifdef USE_TV
1767 if(demuxer->type == DEMUXER_TYPE_TV) {
1768 int l = strlen(prop->name);
1769 char tv_prop[3+l+1];
1770 sprintf(tv_prop,"tv_%s",prop->name);
1771 return mp_property_do(tv_prop,action,arg);
1773 #endif
1775 return M_PROPERTY_UNAVAILABLE;
1778 /// VSync (RW)
1779 static int mp_property_vsync(m_option_t* prop,int action,void* arg) {
1780 return m_property_flag(prop,action,arg,&vo_vsync);
1783 /// Video codec tag (RO)
1784 static int mp_property_video_format(m_option_t* prop,int action,void* arg) {
1785 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1786 return m_property_int_ro(prop,action,arg,sh_video->format);
1789 /// Video bitrate (RO)
1790 static int mp_property_video_bitrate(m_option_t* prop,int action,void* arg) {
1791 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1792 return m_property_int_ro(prop,action,arg,sh_video->i_bps);
1795 /// Video display width (RO)
1796 static int mp_property_width(m_option_t* prop,int action,void* arg) {
1797 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1798 return m_property_int_ro(prop,action,arg,sh_video->disp_w);
1801 /// Video display height (RO)
1802 static int mp_property_height(m_option_t* prop,int action,void* arg) {
1803 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1804 return m_property_int_ro(prop,action,arg,sh_video->disp_h);
1807 /// Video fps (RO)
1808 static int mp_property_fps(m_option_t* prop,int action,void* arg) {
1809 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1810 return m_property_float_ro(prop,action,arg,sh_video->fps);
1813 /// Video aspect (RO)
1814 static int mp_property_aspect(m_option_t* prop,int action,void* arg) {
1815 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1816 return m_property_float_ro(prop,action,arg,sh_video->aspect);
1819 ///@}
1821 /// \defgroup SubProprties Subtitles properties
1822 /// \ingroup Properties
1823 ///@{
1825 /// Text subtitle position (RW)
1826 static int mp_property_sub_pos(m_option_t* prop,int action,void* arg) {
1827 #ifdef USE_SUB
1828 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1830 switch(action) {
1831 case M_PROPERTY_SET:
1832 if(!arg) return 0;
1833 case M_PROPERTY_STEP_UP:
1834 case M_PROPERTY_STEP_DOWN:
1835 vo_osd_changed(OSDTYPE_SUBTITLE);
1836 default:
1837 return m_property_int_range(prop,action,arg,&sub_pos);
1839 #else
1840 return M_PROPERTY_UNAVAILABLE;
1841 #endif
1844 /// Selected subtitles (RW)
1845 static int mp_property_sub(m_option_t* prop,int action,void* arg) {
1846 int source = -1, reset_spu = 0;
1847 char* sub_name;
1849 if(global_sub_size <= 0) return M_PROPERTY_UNAVAILABLE;
1851 switch(action) {
1852 case M_PROPERTY_GET:
1853 if(!arg) return 0;
1854 *(int*)arg = global_sub_pos;
1855 return 1;
1856 case M_PROPERTY_PRINT:
1857 if(!arg) return 0;
1858 *(char**)arg = malloc(64);
1859 (*(char**)arg)[63] = 0;
1860 sub_name = 0;
1861 #ifdef USE_SUB
1862 if(subdata)
1863 sub_name = subdata->filename;
1864 #endif
1865 #ifdef USE_ASS
1866 if (ass_track && ass_track->name)
1867 sub_name = ass_track->name;
1868 #endif
1869 #if defined(USE_SUB) || defined(USE_ASS)
1870 if(sub_name) {
1871 char *tmp,*tmp2;
1872 tmp = sub_name;
1873 if ((tmp2 = strrchr(tmp, '/')))
1874 tmp = tmp2+1;
1876 snprintf(*(char**)arg, 63, "(%d) %s%s",
1877 set_of_sub_pos + 1,
1878 strlen(tmp) < 20 ? "" : "...",
1879 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
1880 return 1;
1882 #endif
1883 if (demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1884 char lang[40] = MSGTR_Unknown;
1885 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
1886 lang[39] = 0;
1887 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, lang);
1888 return 1;
1890 #ifdef HAVE_OGGVORBIS
1891 if (demuxer->type == DEMUXER_TYPE_OGG && d_dvdsub && dvdsub_id >= 0) {
1892 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
1893 if (!lang) lang = MSGTR_Unknown;
1894 snprintf(*(char**)arg, 63, "(%d) %s",
1895 dvdsub_id, lang);
1896 return 1;
1898 #endif
1899 if (vo_vobsub && vobsub_id >= 0) {
1900 const char *language = MSGTR_Unknown;
1901 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1902 snprintf(*(char**)arg, 63, "(%d) %s",
1903 vobsub_id, language ? language : MSGTR_Unknown);
1904 return 1;
1906 #ifdef USE_DVDREAD
1907 if (vo_spudec && dvdsub_id >= 0) {
1908 char lang[3] = "\0\0\0";
1909 int code = 0;
1910 code = dvd_lang_from_sid(stream, dvdsub_id);
1911 if (code) {
1912 lang[0] = code >> 8;
1913 lang[1] = code;
1914 lang[2] = 0;
1916 snprintf(*(char**)arg, 63, "(%d) %s",
1917 dvdsub_id, lang);
1918 return 1;
1920 #endif
1921 snprintf(*(char**)arg, 63, MSGTR_Disabled);
1922 return 1;
1924 case M_PROPERTY_SET:
1925 if(!arg) return 0;
1926 if(*(int*)arg < -1) *(int*)arg = -1;
1927 else if(*(int*)arg >= global_sub_size) *(int*)arg = global_sub_size-1;
1928 global_sub_pos = *(int*)arg;
1929 break;
1930 case M_PROPERTY_STEP_UP:
1931 global_sub_pos += 2;
1932 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
1933 break;
1934 case M_PROPERTY_STEP_DOWN:
1935 global_sub_pos += global_sub_size+1;
1936 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
1937 break;
1938 default:
1939 return M_PROPERTY_NOT_IMPLEMENTED;
1942 if (global_sub_pos >= 0)
1943 source = sub_source();
1945 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1946 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1947 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
1948 global_sub_indices[SUB_SOURCE_SUBS],
1949 global_sub_indices[SUB_SOURCE_DEMUX],
1950 global_sub_pos, source);
1952 #ifdef USE_SUB
1953 set_of_sub_pos = -1;
1954 subdata = NULL;
1955 vo_sub_last = vo_sub = NULL;
1956 #endif
1957 vobsub_id = -1;
1958 dvdsub_id = -1;
1959 if (d_dvdsub) {
1960 if(d_dvdsub->id > -2) reset_spu = 1;
1961 d_dvdsub->id = -2;
1963 #ifdef USE_ASS
1964 ass_track = 0;
1965 #endif
1967 if (source == SUB_SOURCE_VOBSUB) {
1968 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
1969 #ifdef USE_SUB
1970 } else if (source == SUB_SOURCE_SUBS) {
1971 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
1972 #ifdef USE_ASS
1973 if (ass_enabled && set_of_ass_tracks[set_of_sub_pos])
1974 ass_track = set_of_ass_tracks[set_of_sub_pos];
1975 else
1976 #endif
1978 subdata = set_of_subtitles[set_of_sub_pos];
1979 vo_osd_changed(OSDTYPE_SUBTITLE);
1981 #endif
1982 } else if (source == SUB_SOURCE_DEMUX) {
1983 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
1984 if (d_dvdsub) {
1985 #ifdef USE_DVDREAD
1986 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
1987 d_dvdsub->id = dvdsub_id;
1988 spudec_reset(vo_spudec);
1990 #endif
1991 #ifdef HAVE_OGGVORBIS
1992 if (demuxer->type == DEMUXER_TYPE_OGG)
1993 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
1994 #endif
1995 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
1996 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
1997 #ifdef USE_ASS
1998 if (ass_enabled && (d_dvdsub->id >= 0) &&
1999 (((sh_sub_t *)d_dvdsub->sh)->type == 'a')) {
2000 ass_track = ((sh_sub_t *)d_dvdsub->sh)->ass_track;
2002 #endif
2003 if (d_dvdsub->id >= 0 &&
2004 ((sh_sub_t *)d_dvdsub->sh)->type == 'v') {
2005 sh_sub_t *mkv_sh_sub = (sh_sub_t *)d_dvdsub->sh;
2006 if (vo_spudec != NULL)
2007 spudec_free(vo_spudec);
2008 vo_spudec =
2009 spudec_new_scaled_vobsub(mkv_sh_sub->has_palette ?
2010 mkv_sh_sub->palette :
2011 NULL, mkv_sh_sub->colors,
2012 mkv_sh_sub->custom_colors,
2013 mkv_sh_sub->width,
2014 mkv_sh_sub->height);
2015 if (!forced_subs_only)
2016 forced_subs_only = mkv_sh_sub->forced_subs_only;
2017 if (vo_spudec) {
2018 spudec_set_forced_subs_only(vo_spudec,
2019 forced_subs_only);
2020 inited_flags |= INITED_SPUDEC;
2025 } else { // off
2026 #ifdef USE_SUB
2027 vo_osd_changed(OSDTYPE_SUBTITLE);
2028 #endif
2029 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2031 #ifdef USE_DVDREAD
2032 if (vo_spudec && stream->type == STREAMTYPE_DVD && dvdsub_id < 0 && reset_spu) {
2033 dvdsub_id = -2;
2034 d_dvdsub->id = dvdsub_id;
2035 spudec_reset(vo_spudec);
2037 #endif
2039 return 1;
2042 /// Subtitle delay (RW)
2043 static int mp_property_sub_delay(m_option_t* prop,int action,void* arg) {
2044 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2045 return m_property_delay(prop,action,arg,&sub_delay);
2048 /// Alignment of text subtitles (RW)
2049 static int mp_property_sub_alignment(m_option_t* prop,int action,void* arg) {
2050 #ifdef USE_SUB
2051 char* name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
2053 if(!sh_video || global_sub_pos < 0 || sub_source() != SUB_SOURCE_SUBS)
2054 return M_PROPERTY_UNAVAILABLE;
2056 switch(action) {
2057 case M_PROPERTY_PRINT:
2058 if(!arg) return 0;
2059 M_PROPERTY_CLAMP(prop,sub_alignment);
2060 *(char**)arg = strdup(name[sub_alignment]);
2061 return 1;
2062 case M_PROPERTY_SET:
2063 if(!arg) return 0;
2064 case M_PROPERTY_STEP_UP:
2065 case M_PROPERTY_STEP_DOWN:
2066 vo_osd_changed(OSDTYPE_SUBTITLE);
2067 default:
2068 return m_property_choice(prop,action,arg,&sub_alignment);
2070 #else
2071 return M_PROPERTY_UNAVAILABLE;
2072 #endif
2075 /// Subtitle visibility (RW)
2076 static int mp_property_sub_visibility(m_option_t* prop,int action,void* arg) {
2077 #ifdef USE_SUB
2078 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2080 switch(action) {
2081 case M_PROPERTY_SET:
2082 if(!arg) return 0;
2083 case M_PROPERTY_STEP_UP:
2084 case M_PROPERTY_STEP_DOWN:
2085 vo_osd_changed(OSDTYPE_SUBTITLE);
2086 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2087 default:
2088 return m_property_flag(prop,action,arg,&sub_visibility);
2090 #else
2091 return M_PROPERTY_UNAVAILABLE;
2092 #endif
2095 /// Show only forced subtitles (RW)
2096 static int mp_property_sub_forced_only(m_option_t* prop,int action,void* arg) {
2097 if(!vo_spudec) return M_PROPERTY_UNAVAILABLE;
2099 switch(action) {
2100 case M_PROPERTY_SET:
2101 if(!arg) return 0;
2102 case M_PROPERTY_STEP_UP:
2103 case M_PROPERTY_STEP_DOWN:
2104 m_property_flag(prop,action,arg,&forced_subs_only);
2105 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
2106 return 1;
2107 default:
2108 return m_property_flag(prop,action,arg,&forced_subs_only);
2113 ///@}
2115 /// \defgroup TVProperties TV properties
2116 /// \ingroup Properties
2117 ///@{
2119 #ifdef USE_TV
2121 /// TV color settings (RW)
2122 static int mp_property_tv_color(m_option_t* prop,int action,void* arg) {
2123 int r,val;
2124 tvi_handle_t* tvh = demuxer->priv;
2125 if(demuxer->type != DEMUXER_TYPE_TV || !tvh) return M_PROPERTY_UNAVAILABLE;
2127 switch(action) {
2128 case M_PROPERTY_SET:
2129 if(!arg) return 0;
2130 M_PROPERTY_CLAMP(prop,*(int*)arg);
2131 return tv_set_color_options(tvh,(int)prop->priv,*(int*)arg);
2132 case M_PROPERTY_GET:
2133 return tv_get_color_options(tvh,(int)prop->priv,arg);
2134 case M_PROPERTY_STEP_UP:
2135 case M_PROPERTY_STEP_DOWN:
2136 if((r = tv_get_color_options(tvh,(int)prop->priv,&val)) >= 0) {
2137 if(!r) return 0;
2138 val += (arg ? *(int*)arg : 1) *
2139 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2140 M_PROPERTY_CLAMP(prop,val);
2141 return tv_set_color_options(tvh,(int)prop->priv,val);
2143 return 0;
2145 return M_PROPERTY_NOT_IMPLEMENTED;
2148 #endif
2150 ///@}
2152 /// All properties available in MPlayer.
2153 /** \ingroup Properties
2155 static m_option_t mp_properties[] = {
2156 // General
2157 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2158 M_OPT_RANGE, 0, 3, NULL },
2159 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2160 M_OPT_RANGE, 0.01, 100.0, NULL },
2161 { "filename", mp_property_filename, CONF_TYPE_STRING,
2162 0, 0, 0, NULL },
2163 { "path", mp_property_path, CONF_TYPE_STRING,
2164 0, 0, 0, NULL },
2165 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2166 0, 0, 0, NULL },
2167 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2168 M_OPT_MIN, 0, 0, NULL },
2169 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2170 M_OPT_MIN, 0, 0, NULL },
2171 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2172 M_OPT_MIN, 0, 0, NULL },
2173 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2174 M_OPT_MIN, 0, 0, NULL },
2175 { "length", mp_property_length, CONF_TYPE_DOUBLE,
2176 0, 0, 0, NULL },
2178 // Audio
2179 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2180 M_OPT_RANGE, 0, 100, NULL },
2181 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2182 M_OPT_RANGE, 0, 1, NULL },
2183 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2184 M_OPT_RANGE, -100, 100, NULL },
2185 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2186 0, 0, 0, NULL },
2187 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2188 0, 0, 0, NULL },
2189 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2190 0, 0, 0, NULL },
2191 { "channels", mp_property_channels, CONF_TYPE_INT,
2192 0, 0, 0, NULL },
2194 // Video
2195 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2196 M_OPT_RANGE, 0, 1, NULL },
2197 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2198 M_OPT_RANGE, 0, 1, NULL },
2199 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2200 M_OPT_RANGE, 0, 1, NULL },
2201 { "border", mp_property_border, CONF_TYPE_FLAG,
2202 M_OPT_RANGE, 0, 1, NULL },
2203 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2204 M_OPT_RANGE, 0, 2, NULL },
2205 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2206 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2207 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2208 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2209 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2210 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2211 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2212 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2213 { "hue", mp_property_gamma, CONF_TYPE_INT,
2214 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2215 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2216 M_OPT_RANGE, 0, 1, NULL },
2217 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2218 M_OPT_RANGE, 0, 1, NULL },
2219 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2220 0, 0, 0, NULL },
2221 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2222 0, 0, 0, NULL },
2223 { "width", mp_property_width, CONF_TYPE_INT,
2224 0, 0, 0, NULL },
2225 { "height", mp_property_height, CONF_TYPE_INT,
2226 0, 0, 0, NULL },
2227 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2228 0, 0, 0, NULL },
2229 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2230 0, 0, 0, NULL },
2232 // Subs
2233 { "sub", mp_property_sub, CONF_TYPE_INT,
2234 M_OPT_MIN, -1, 0, NULL },
2235 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2236 0, 0, 0, NULL },
2237 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2238 M_OPT_RANGE, 0, 100, NULL },
2239 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2240 M_OPT_RANGE, 0, 2, NULL },
2241 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2242 M_OPT_RANGE, 0, 1, NULL },
2243 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2244 M_OPT_RANGE, 0, 1, NULL },
2246 #ifdef USE_TV
2247 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2248 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_BRIGHTNESS },
2249 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2250 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_CONTRAST },
2251 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2252 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_SATURATION },
2253 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2254 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_HUE },
2255 #endif
2257 { NULL, NULL, NULL, 0, 0, 0, NULL }
2260 m_option_t* mp_property_find(const char* name) {
2261 return m_option_list_find(mp_properties,name);
2264 int mp_property_do(const char* name,int action, void* val) {
2265 m_option_t* p = mp_property_find(name);
2266 if(!p) return M_PROPERTY_UNAVAILABLE;
2267 return m_property_do(p,action,val);
2270 ///@}
2271 // Properties group
2275 * \defgroup Command2Property Command to property bridge
2277 * It is used to handle most commands that just set a property
2278 * and optionally display something on the OSD.
2279 * Two kinds of commands are handled: adjust or toggle.
2281 * Adjust commands take 1 or 2 parameters: <value> <abs>
2282 * If <abs> is non-zero the property is set to the given value
2283 * otherwise it is adjusted.
2285 * Toggle commands take 0 or 1 parameters. With no parameter
2286 * or a value less than the property minimum it just steps the
2287 * property to its next value. Otherwise it sets it to the given
2288 * value.
2293 /// List of the commands that can be handled by setting a property.
2294 static struct {
2295 /// property name
2296 const char* name;
2297 /// cmd id
2298 int cmd;
2299 /// set/adjust or toggle command
2300 int toggle;
2301 /// progressbar type
2302 int osd_progbar;
2303 /// osd msg id if it must be shared
2304 int osd_id;
2305 /// osd msg template
2306 const char* osd_msg;
2307 } set_prop_cmd[] = {
2308 // audio
2309 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2310 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2311 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2312 // video
2313 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2314 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2315 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2316 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2317 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2318 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2319 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2320 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2321 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2322 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2323 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2324 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2325 // subs
2326 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2327 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2328 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2329 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2330 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2331 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2332 #ifdef USE_TV
2333 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2334 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2335 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2336 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2337 #endif
2338 { NULL, 0, 0, 0, -1, NULL }
2341 /// Handle commands that set a property.
2342 static int set_property_command(mp_cmd_t* cmd) {
2343 int i,r;
2344 m_option_t* prop;
2346 // look for the command
2347 for(i = 0 ; set_prop_cmd[i].name ; i++)
2348 if(set_prop_cmd[i].cmd == cmd->id) break;
2349 if(!set_prop_cmd[i].name) return 0;
2351 // get the property
2352 prop = mp_property_find(set_prop_cmd[i].name);
2353 if(!prop) return 0;
2355 // toggle command
2356 if(set_prop_cmd[i].toggle) {
2357 // set to value
2358 if(cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2359 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v.i);
2360 else
2361 r = m_property_do(prop,M_PROPERTY_STEP_UP,NULL);
2362 } else if(cmd->args[1].v.i) //set
2363 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v);
2364 else // adjust
2365 r = m_property_do(prop,M_PROPERTY_STEP_UP,&cmd->args[0].v);
2367 if(r <= 0) return 1;
2369 if(set_prop_cmd[i].osd_progbar) {
2370 if(prop->type == CONF_TYPE_INT) {
2371 if(m_property_do(prop,M_PROPERTY_GET,&r) > 0)
2372 set_osd_bar(set_prop_cmd[i].osd_progbar,
2373 set_prop_cmd[i].osd_msg,
2374 prop->min,prop->max,r);
2375 } else if(prop->type == CONF_TYPE_FLOAT) {
2376 float f;
2377 if(m_property_do(prop,M_PROPERTY_GET,&f) > 0)
2378 set_osd_bar(set_prop_cmd[i].osd_progbar,set_prop_cmd[i].osd_msg,
2379 prop->min,prop->max,f);
2380 } else
2381 mp_msg(MSGT_CPLAYER,MSGL_ERR, "Property use an unsupported type.\n");
2382 return 1;
2385 if(set_prop_cmd[i].osd_msg) {
2386 char* val = m_property_print(prop);
2387 if(val) {
2388 set_osd_msg(set_prop_cmd[i].osd_id >= 0 ? set_prop_cmd[i].osd_id :
2389 OSD_MSG_PROPERTY+i,1,osd_duration,
2390 set_prop_cmd[i].osd_msg,val);
2391 free(val);
2394 return 1;
2397 static void reinit_audio_chain(void) {
2398 if(sh_audio){
2399 current_module="init_audio_codec";
2400 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2401 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
2402 sh_audio=d_audio->sh=NULL; // failed to init :(
2403 d_audio->id = -2;
2404 return;
2405 } else
2406 inited_flags|=INITED_ACODEC;
2407 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2410 //const ao_info_t *info=audio_out->info;
2411 current_module="af_preinit";
2412 ao_data.samplerate=force_srate;
2413 ao_data.channels=0;
2414 ao_data.format=audio_output_format;
2415 #if 1
2416 // first init to detect best values
2417 if(!preinit_audio_filters(sh_audio,
2418 // input:
2419 (int)(sh_audio->samplerate*playback_speed),
2420 sh_audio->channels, sh_audio->sample_format,
2421 // output:
2422 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){
2423 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2424 exit_player(MSGTR_Exit_error);
2426 #endif
2427 current_module="ao2_init";
2428 if(!(audio_out=init_best_audio_out(audio_driver_list,
2429 0, // plugin flag
2430 ao_data.samplerate,
2431 ao_data.channels,
2432 ao_data.format,0))){
2433 // FAILED:
2434 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2435 uninit_player(INITED_ACODEC); // close codec
2436 sh_audio=d_audio->sh=NULL; // -> nosound
2437 d_audio->id = -2;
2438 return;
2439 } else {
2440 // SUCCESS:
2441 inited_flags|=INITED_AO;
2442 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2443 audio_out->info->short_name,
2444 ao_data.samplerate, ao_data.channels,
2445 af_fmt2str_short(ao_data.format),
2446 af_fmt2bits(ao_data.format)/8 );
2447 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2448 audio_out->info->name, audio_out->info->author);
2449 if(strlen(audio_out->info->comment) > 0)
2450 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2451 // init audio filters:
2452 #if 1
2453 current_module="af_init";
2454 if(!build_afilter_chain(sh_audio, &ao_data)) {
2455 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2456 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2457 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2458 // sh_audio=d_audio->sh=NULL; // -> nosound
2460 #endif
2462 mixer.audio_out = audio_out;
2463 mixer.volstep = volstep;
2468 ///@}
2469 // Command2Property
2472 // Return pts value corresponding to the end point of audio written to the
2473 // ao so far.
2474 static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio)
2476 // first calculate the end pts of audio that has been output by decoder
2477 double a_pts = sh_audio->pts;
2478 if (a_pts != MP_NOPTS_VALUE)
2479 // Good, decoder supports new way of calculating audio pts.
2480 // sh_audio->pts is the timestamp of the latest input packet with
2481 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2482 // the amount of bytes the decoder has written after that timestamp.
2483 a_pts += sh_audio->pts_bytes / (double) sh_audio->o_bps;
2484 else {
2485 // Decoder doesn't support new way of calculating pts (or we're
2486 // being called before it has decoded anything with known timestamp).
2487 // Use the old method of audio pts calculation: take the timestamp
2488 // of last packet with known pts the decoder has read data from,
2489 // and add amount of bytes read after the beginning of that packet
2490 // divided by input bps. This will be inaccurate if the input/output
2491 // ratio is not constant for every audio packet or if it is constant
2492 // but not accurately known in sh_audio->i_bps.
2494 a_pts = d_audio->pts;
2495 // ds_tell_pts returns bytes read after last timestamp from
2496 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2497 // it has read but not decoded
2498 if (sh_audio->i_bps)
2499 a_pts += (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len) /
2500 (double)sh_audio->i_bps;
2502 // Now a_pts hopefully holds the pts for end of audio from decoder.
2503 // Substract data in buffers between decoder and audio out.
2505 // Decoded but not filtered
2506 a_pts -= sh_audio->a_buffer_len / (double)sh_audio->o_bps;
2508 // Data that was ready for ao but was buffered because ao didn't fully
2509 // accept everything to internal buffers yet
2510 a_pts -= sh_audio->a_out_buffer_len * playback_speed / (double)ao_data.bps;
2512 return a_pts;
2515 // Return pts value corresponding to currently playing audio.
2516 static double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio,
2517 ao_functions_t *audio_out)
2519 return written_audio_pts(sh_audio, d_audio) - playback_speed *
2520 audio_out->get_delay();
2524 static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video)
2526 unsigned char *start;
2527 int in_size;
2528 int hit_eof=0;
2529 double pts;
2531 while (1) {
2532 current_module = "decode video";
2533 // XXX Time used in this call is not counted in any performance
2534 // timer now
2535 if (vf_output_queued_frame(sh_video->vfilter))
2536 break;
2537 current_module = "video_read_frame";
2538 in_size = ds_get_packet_pts(d_video, &start, &pts);
2539 if (in_size < 0) {
2540 // try to extract last frames in case of decoder lag
2541 in_size = 0;
2542 pts = 1e300;
2543 hit_eof = 1;
2545 if (in_size > max_framesize)
2546 max_framesize = in_size;
2547 if (pts == MP_NOPTS_VALUE)
2548 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts value from demuxer MISSING\n");
2549 if (decode_video(sh_video, start, in_size, 0, pts))
2550 break;
2551 if (hit_eof)
2552 return 0;
2554 return 1;
2558 int main(int argc,char* argv[]){
2561 char * mem_ptr;
2563 int file_format=DEMUXER_TYPE_UNKNOWN;
2565 // movie info:
2567 #ifdef HAVE_RTC
2568 int rtc_fd=-1;
2569 #endif
2571 /* Flag indicating whether MPlayer should exit without playing anything. */
2572 int opt_exit = 0;
2574 //float a_frame=0; // Audio
2576 int i;
2577 char *tmp;
2579 int gui_no_filename=0;
2581 struct {double pts; vo_functions_t *vo;} vf_vo_data;
2583 srand((int) time(NULL));
2585 InitTimer();
2587 mp_msg_init();
2589 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2006 MPlayer Team\n");
2590 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2591 GetCpuCaps(&gCpuCaps);
2592 #if defined(ARCH_X86) || defined(ARCH_X86_64)
2593 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2594 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
2595 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
2596 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
2597 #ifdef RUNTIME_CPUDETECT
2598 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
2599 #else
2600 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
2601 #ifdef HAVE_MMX
2602 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
2603 #endif
2604 #ifdef HAVE_MMX2
2605 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
2606 #endif
2607 #ifdef HAVE_3DNOW
2608 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
2609 #endif
2610 #ifdef HAVE_3DNOWEX
2611 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
2612 #endif
2613 #ifdef HAVE_SSE
2614 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
2615 #endif
2616 #ifdef HAVE_SSE2
2617 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
2618 #endif
2619 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
2620 #endif /* RUNTIME_CPUDETECT */
2621 #endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */
2623 #if defined(WIN32) && defined(USE_WIN32DLL)
2624 set_path_env();
2625 #endif /*WIN32 && USE_WIN32DLL*/
2627 #ifdef USE_TV
2628 tv_param_immediate = 1;
2629 #endif
2631 if (argc > 1 && argv[1] &&
2632 (!strcmp(argv[1], "-gui") || !strcmp(argv[1], "-nogui"))) {
2633 use_gui = !strcmp(argv[1], "-gui");
2634 } else
2635 if ( argv[0] )
2637 char *base = strrchr(argv[0], '/');
2638 if (!base)
2639 base = strrchr(argv[0], '\\');
2640 if (!base)
2641 base = argv[0];
2642 if(strstr(base, "gmplayer"))
2643 use_gui=1;
2646 mconfig = m_config_new();
2647 m_config_register_options(mconfig,mplayer_opts);
2648 // TODO : add something to let modules register their options
2649 mp_input_register_options(mconfig);
2650 parse_cfgfiles(mconfig);
2652 #ifdef HAVE_NEW_GUI
2653 if ( use_gui ) cfg_read();
2654 #endif
2656 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
2657 if(playtree == NULL)
2658 opt_exit = 1;
2659 else {
2660 playtree = play_tree_cleanup(playtree);
2661 if(playtree) {
2662 playtree_iter = play_tree_iter_new(playtree,mconfig);
2663 if(playtree_iter) {
2664 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
2665 play_tree_iter_free(playtree_iter);
2666 playtree_iter = NULL;
2668 filename = play_tree_iter_get_file(playtree_iter,1);
2673 #if defined(WIN32) && defined(HAVE_NEW_GUI)
2674 void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
2675 if(runningmplayer && filename && use_gui){
2676 COPYDATASTRUCT csData;
2677 char file[MAX_PATH];
2678 char *filepart = filename;
2679 if(GetFullPathName(filename, MAX_PATH, file, &filepart)){
2680 csData.dwData = 0;
2681 csData.cbData = strlen(file)*2;
2682 csData.lpData = file;
2683 SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData);
2686 #endif
2688 #ifdef WIN32
2689 if(proc_priority){
2690 int i;
2691 for(i=0; priority_presets_defs[i].name; i++){
2692 if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
2693 break;
2695 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",
2696 priority_presets_defs[i].name);
2697 SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
2699 #endif
2700 #ifndef HAVE_NEW_GUI
2701 if(use_gui){
2702 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
2703 use_gui=0;
2705 #else
2706 #ifndef WIN32
2707 if(use_gui && !vo_init()){
2708 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
2709 use_gui=0;
2711 #endif
2712 if (use_gui && playtree_iter){
2713 char cwd[PATH_MAX+2];
2714 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2715 play_tree_iter_free(playtree_iter);
2716 playtree_iter=NULL;
2718 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
2720 strcat(cwd, "/");
2721 // Prefix relative paths with current working directory
2722 play_tree_add_bpf(playtree, cwd);
2724 // Import initital playtree into GUI.
2725 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
2727 #endif /* HAVE_NEW_GUI */
2729 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
2730 list_video_out();
2731 opt_exit = 1;
2734 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
2735 list_audio_out();
2736 opt_exit = 1;
2739 /* Check codecs.conf. */
2740 if(!codecs_file || !parse_codec_cfg(codecs_file)){
2741 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
2742 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
2743 if(!parse_codec_cfg(NULL)){
2744 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
2745 exit_player_with_rc(NULL, 0);
2747 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
2750 free( mem_ptr ); // release the buffer created by get_path()
2753 #if 0
2754 if(video_codec_list){
2755 int i;
2756 video_codec=video_codec_list[0];
2757 for(i=0;video_codec_list[i];i++)
2758 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
2760 #endif
2761 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
2762 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
2763 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODECS\n");
2764 list_codecs(1);
2765 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
2766 opt_exit = 1;
2768 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
2769 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
2770 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODECS\n");
2771 list_codecs(0);
2772 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
2773 opt_exit = 1;
2775 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
2776 vfm_help();
2777 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
2778 opt_exit = 1;
2780 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
2781 afm_help();
2782 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
2783 opt_exit = 1;
2785 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
2786 af_help();
2787 printf("\n");
2788 opt_exit = 1;
2790 #ifdef HAVE_X11
2791 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
2792 fstype_help();
2793 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
2794 opt_exit = 1;
2796 #endif
2797 if((demuxer_name && strcmp(demuxer_name,"help")==0) ||
2798 (audio_demuxer_name && strcmp(audio_demuxer_name,"help")==0) ||
2799 (sub_demuxer_name && strcmp(sub_demuxer_name,"help")==0)){
2800 demuxer_help();
2801 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
2802 opt_exit = 1;
2804 if(list_properties) {
2805 m_properties_print_help_list(mp_properties);
2806 opt_exit = 1;
2809 if(opt_exit)
2810 exit_player(NULL);
2812 if (player_idle_mode && use_gui) {
2813 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NoIdleAndGui);
2814 exit_player_with_rc(NULL, 1);
2817 if(!filename && !player_idle_mode){
2818 if(!use_gui){
2819 // no file/vcd/dvd -> show HELP:
2820 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
2821 exit_player_with_rc(NULL, 0);
2822 } else gui_no_filename=1;
2825 // Many users forget to include command line in bugreports...
2826 if( mp_msg_test(MSGT_CPLAYER,MSGL_V) ){
2827 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
2828 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);
2829 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
2832 //------ load global data first ------
2834 // check font
2835 #ifdef USE_OSD
2836 #ifdef HAVE_FREETYPE
2837 init_freetype();
2838 #endif
2839 #ifdef HAVE_FONTCONFIG
2840 if(!font_fontconfig)
2842 #endif
2843 if(font_name){
2844 vo_font=read_font_desc(font_name,font_factor,verbose>1);
2845 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
2846 } else {
2847 // try default:
2848 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
2849 free(mem_ptr); // release the buffer created by get_path()
2850 if(!vo_font)
2851 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
2853 #ifdef HAVE_FONTCONFIG
2855 #endif
2856 #endif /* USE_OSD */
2857 vo_init_osd();
2859 #ifdef HAVE_RTC
2860 if(!nortc)
2862 // seteuid(0); /* Can't hurt to try to get root here */
2863 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
2864 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
2865 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
2866 else {
2867 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
2869 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
2870 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
2871 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
2872 close (rtc_fd);
2873 rtc_fd = -1;
2874 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
2875 /* variable only by the root */
2876 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
2877 close (rtc_fd);
2878 rtc_fd = -1;
2879 } else
2880 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
2883 #ifdef HAVE_NEW_GUI
2884 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2885 // and now ? -- Pontscho
2886 if(use_gui) setuid( getuid() ); // strongly test, please check this.
2887 #endif
2888 if(rtc_fd<0)
2889 #endif /* HAVE_RTC */
2890 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
2891 softsleep?"software":timer_name);
2893 #ifdef USE_TERMCAP
2894 if ( !use_gui ) load_termcap(NULL); // load key-codes
2895 #endif
2897 // ========== Init keyboard FIFO (connection to libvo) ============
2899 // Init input system
2900 current_module = "init_input";
2901 mp_input_init(use_gui);
2902 #if 0
2903 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
2905 if(keyb_fifo_get > 0)
2906 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
2907 #else
2908 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
2909 #endif
2910 if(slave_mode)
2911 #ifndef __MINGW32__
2912 mp_input_add_cmd_fd(0,1,NULL,NULL);
2913 #else
2914 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
2915 #endif
2916 else if(!noconsolecontrols)
2917 #ifndef HAVE_NO_POSIX_SELECT
2918 mp_input_add_key_fd(0,1,NULL,NULL);
2919 #else
2920 mp_input_add_key_fd(0,0,NULL,NULL);
2921 #endif
2923 inited_flags|=INITED_INPUT;
2924 current_module = NULL;
2926 #ifdef HAVE_MENU
2927 if(use_menu) {
2928 if(menu_cfg && menu_init(menu_cfg))
2929 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
2930 else {
2931 menu_cfg = get_path("menu.conf");
2932 if(menu_init(menu_cfg))
2933 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
2934 else {
2935 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
2936 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
2937 else {
2938 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
2939 use_menu = 0;
2944 #endif
2946 /// Catch signals
2947 #ifndef __MINGW32__
2948 signal(SIGCHLD,child_sighandler);
2949 #endif
2951 #ifdef CRASH_DEBUG
2952 prog_path = argv[0];
2953 #endif
2954 //========= Catch terminate signals: ================
2955 // terminate requests:
2956 signal(SIGTERM,exit_sighandler); // kill
2957 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
2959 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
2961 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
2962 signal(SIGPIPE,exit_sighandler); // Some window managers cause this
2963 #ifdef ENABLE_SIGHANDLER
2964 // fatal errors:
2965 signal(SIGBUS,exit_sighandler); // bus error
2966 signal(SIGSEGV,exit_sighandler); // segfault
2967 signal(SIGILL,exit_sighandler); // illegal instruction
2968 signal(SIGFPE,exit_sighandler); // floating point exc.
2969 signal(SIGABRT,exit_sighandler); // abort()
2970 #ifdef CRASH_DEBUG
2971 if (crash_debug)
2972 signal(SIGTRAP,exit_sighandler);
2973 #endif
2974 #endif
2976 #ifdef HAVE_NEW_GUI
2977 if(use_gui){
2978 guiInit();
2979 inited_flags|=INITED_GUI;
2980 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
2982 #endif
2984 // ******************* Now, let's see the per-file stuff ********************
2986 play_next_file:
2988 // init global sub numbers
2989 global_sub_size = 0;
2990 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
2992 if (filename) load_per_file_config (mconfig, filename);
2994 // We must enable getch2 here to be able to interrupt network connection
2995 // or cache filling
2996 if(!noconsolecontrols && !slave_mode){
2997 if(inited_flags&INITED_GETCH2)
2998 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
2999 else
3000 getch2_enable(); // prepare stdin for hotkeys...
3001 inited_flags|=INITED_GETCH2;
3002 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
3005 // =================== GUI idle loop (STOP state) ===========================
3006 #ifdef HAVE_NEW_GUI
3007 if ( use_gui ) {
3008 file_format=DEMUXER_TYPE_UNKNOWN;
3009 guiGetEvent( guiSetDefaults,0 );
3010 while ( guiIntfStruct.Playing != 1 )
3012 mp_cmd_t* cmd;
3013 usec_sleep(20000);
3014 guiEventHandling();
3015 guiGetEvent( guiReDraw,NULL );
3016 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
3018 guiGetEvent( guiSetParameters,NULL );
3019 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
3021 play_tree_t * entry = play_tree_new();
3022 play_tree_add_file( entry,guiIntfStruct.Filename );
3023 if ( playtree ) play_tree_free_list( playtree->child,1 );
3024 else playtree=play_tree_new();
3025 play_tree_set_child( playtree,entry );
3026 if(playtree)
3028 playtree_iter = play_tree_iter_new(playtree,mconfig);
3029 if(playtree_iter)
3031 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
3033 play_tree_iter_free(playtree_iter);
3034 playtree_iter = NULL;
3036 filename = play_tree_iter_get_file(playtree_iter,1);
3041 #endif /* HAVE_NEW_GUI */
3043 while (player_idle_mode && !filename) {
3044 play_tree_t * entry = NULL;
3045 mp_cmd_t * cmd;
3046 while (!(cmd = mp_input_get_cmd(0,1,0))) { // wait for command
3047 if (video_out && vo_config_count) video_out->check_events();
3048 usec_sleep(20000);
3050 switch (cmd->id) {
3051 case MP_CMD_LOADFILE:
3052 // prepare a tree entry with the new filename
3053 entry = play_tree_new();
3054 play_tree_add_file(entry, cmd->args[0].v.s);
3055 // The entry is added to the main playtree after the switch().
3056 break;
3057 case MP_CMD_LOADLIST:
3058 entry = parse_playlist_file(cmd->args[0].v.s);
3059 break;
3060 case MP_CMD_QUIT:
3061 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
3062 break;
3065 mp_cmd_free(cmd);
3067 if (entry) { // user entered a command that gave a valid entry
3068 if (playtree) // the playtree is always a node with one child. let's clear it
3069 play_tree_free_list(playtree->child, 1);
3070 else playtree=play_tree_new(); // .. or make a brand new playtree
3072 if (!playtree) continue; // couldn't make playtree! wait for next command
3074 play_tree_set_child(playtree, entry);
3076 /* Make iterator start at the top the of tree. */
3077 playtree_iter = play_tree_iter_new(playtree, mconfig);
3078 if (!playtree_iter) continue;
3080 // find the first real item in the tree
3081 if (play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
3082 // no items!
3083 play_tree_iter_free(playtree_iter);
3084 playtree_iter = NULL;
3085 continue; // wait for next command
3087 filename = play_tree_iter_get_file(playtree_iter, 1);
3090 //---------------------------------------------------------------------------
3092 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
3094 if (edl_filename) {
3095 if (edl_records) free_edl(edl_records);
3096 next_edl_record = edl_records = edl_parse_file();
3098 if (edl_output_filename) {
3099 if (edl_fd) fclose(edl_fd);
3100 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
3102 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
3103 edl_output_filename);
3107 //==================== Open VOB-Sub ============================
3109 current_module="vobsub";
3110 if (vobsub_name){
3111 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
3112 if(vo_vobsub==NULL)
3113 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
3114 }else if(sub_auto && filename && (strlen(filename)>=5)){
3115 /* try to autodetect vobsub from movie filename ::atmos */
3116 char *buf = malloc((strlen(filename)-3)),*psub;
3117 memset(buf,0,strlen(filename)-3); // make sure string is terminated
3118 strncpy(buf, filename, strlen(filename)-4);
3119 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
3120 /* try from ~/.mplayer/sub */
3121 if(!vo_vobsub && (psub = get_path( "sub/" ))) {
3122 char *bname;
3123 int l;
3124 bname = strrchr(buf,'/');
3125 #ifdef WIN32
3126 if(!bname) bname = strrchr(buf,'\\');
3127 #endif
3128 if(bname) bname++;
3129 else bname = buf;
3130 l = strlen(psub) + strlen(bname) + 1;
3131 psub = realloc(psub,l);
3132 strcat(psub,bname);
3133 vo_vobsub=vobsub_open(psub,spudec_ifo,0,&vo_spudec);
3134 free(psub);
3136 free(buf);
3138 if(vo_vobsub){
3139 inited_flags|=INITED_VOBSUB;
3140 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
3141 // check if vobsub requested only to display forced subtitles
3142 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
3144 // setup global sub numbering
3145 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
3146 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
3149 //============ Open & Sync STREAM --- fork cache2 ====================
3151 stream=NULL;
3152 demuxer=NULL;
3153 if (d_audio) {
3154 //free_demuxer_stream(d_audio);
3155 d_audio=NULL;
3157 if (d_video) {
3158 //free_demuxer_stream(d_video);
3159 d_video=NULL;
3161 sh_audio=NULL;
3162 sh_video=NULL;
3164 current_module="open_stream";
3165 stream=open_stream(filename,0,&file_format);
3166 if(!stream) { // error...
3167 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
3168 goto goto_next_file;
3170 inited_flags|=INITED_STREAM;
3172 #ifdef HAVE_NEW_GUI
3173 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
3174 #endif
3176 if(file_format == DEMUXER_TYPE_PLAYLIST) {
3177 play_tree_t* entry;
3178 // Handle playlist
3179 current_module="handle_playlist";
3180 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
3181 entry = parse_playtree(stream,0);
3182 eof=playtree_add_playlist(entry);
3183 goto goto_next_file;
3185 stream->start_pos+=seek_to_byte;
3187 if(stream_dump_type==5){
3188 unsigned char buf[4096];
3189 int len;
3190 FILE *f;
3191 current_module="dumpstream";
3192 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
3193 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
3194 exit_player(MSGTR_Exit_error);
3196 stream_reset(stream);
3197 stream_seek(stream,stream->start_pos);
3198 f=fopen(stream_dump_name,"wb");
3199 if(!f){
3200 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
3201 exit_player(MSGTR_Exit_error);
3203 while(!stream->eof){
3204 len=stream_read(stream,buf,4096);
3205 if(len>0) {
3206 if(fwrite(buf,len,1,f) != 1) {
3207 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
3208 exit_player(MSGTR_Exit_error);
3212 if(fclose(f)) {
3213 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
3214 exit_player(MSGTR_Exit_error);
3216 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
3217 exit_player_with_rc(MSGTR_Exit_eof, 0);
3220 #ifdef USE_DVDREAD
3221 if(stream->type==STREAMTYPE_DVD){
3222 current_module="dvd lang->id";
3223 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
3224 if(dvdsub_lang && dvdsub_id==-2) dvdsub_id=-1;
3225 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
3226 // setup global sub numbering
3227 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
3228 global_sub_size += dvd_number_of_subs(stream);
3229 current_module=NULL;
3231 #endif
3233 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3234 #ifdef HAS_DVBIN_SUPPORT
3235 goto_enable_cache:
3236 #endif
3237 if(stream_cache_size>0){
3238 current_module="enable_cache";
3239 if(!stream_enable_cache(stream,stream_cache_size*1024,
3240 stream_cache_size*1024*(stream_cache_min_percent / 100.0),
3241 stream_cache_size*1024*(stream_cache_seek_min_percent / 100.0)))
3242 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
3245 //============ Open DEMUXERS --- DETECT file type =======================
3246 current_module="demux_open";
3248 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
3250 // HACK to get MOV Reference Files working
3252 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
3254 unsigned char* playlist_entry;
3255 play_tree_t *list = NULL, *entry = NULL;
3257 current_module="handle_demux_playlist";
3258 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
3260 char *temp, *bname;
3262 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
3264 bname=mp_basename(playlist_entry);
3265 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
3266 continue;
3268 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
3269 continue;
3271 entry = play_tree_new();
3273 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
3275 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1));
3276 if (temp)
3278 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
3279 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
3280 strcat(temp, playlist_entry);
3281 play_tree_add_file(entry,temp);
3282 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
3283 free(temp);
3286 else
3287 play_tree_add_file(entry,playlist_entry);
3289 if(!list)
3290 list = entry;
3291 else
3292 play_tree_append_entry(list,entry);
3294 free_demuxer(demuxer);
3295 demuxer = NULL;
3297 if (list)
3299 entry = play_tree_new();
3300 play_tree_set_child(entry,list);
3301 eof=playtree_add_playlist(entry);
3302 goto goto_next_file;
3306 if(!demuxer)
3308 #if 0
3309 play_tree_t* entry;
3310 // Handle playlist
3311 current_module="handle_playlist";
3312 switch(stream->type){
3313 case STREAMTYPE_VCD:
3314 case STREAMTYPE_DVD:
3315 case STREAMTYPE_CDDA:
3316 case STREAMTYPE_VCDBINCUE:
3317 // don't try to parse raw media as playlist, it's unlikely
3318 goto goto_next_file;
3320 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
3321 stream_reset(stream);
3322 stream_seek(stream,stream->start_pos);
3323 entry = parse_playtree(stream,0);
3324 if(!entry)
3325 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
3326 else
3327 eof=playtree_add_playlist(entry);
3328 #endif
3329 goto goto_next_file;
3331 inited_flags|=INITED_DEMUXER;
3333 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
3334 // setup global sub numbering
3335 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
3336 global_sub_size += demux_mkv_num_subs(demuxer);
3338 #ifdef HAVE_OGGVORBIS
3339 if (demuxer->type==DEMUXER_TYPE_OGG) {
3340 // setup global sub numbering
3341 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
3342 global_sub_size += demux_ogg_num_subs(demuxer);
3344 #endif
3346 current_module="demux_open2";
3348 //file_format=demuxer->file_format;
3350 d_audio=demuxer->audio;
3351 d_video=demuxer->video;
3352 d_dvdsub=demuxer->sub;
3354 // DUMP STREAMS:
3355 if((stream_dump_type)&&(stream_dump_type<4)){
3356 FILE *f;
3357 demux_stream_t *ds=NULL;
3358 current_module="dump";
3359 // select stream to dump
3360 switch(stream_dump_type){
3361 case 1: ds=d_audio;break;
3362 case 2: ds=d_video;break;
3363 case 3: ds=d_dvdsub;break;
3365 if(!ds){
3366 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
3367 exit_player(MSGTR_Exit_error);
3369 // disable other streams:
3370 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
3371 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
3372 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
3373 // let's dump it!
3374 f=fopen(stream_dump_name,"wb");
3375 if(!f){
3376 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
3377 exit_player(MSGTR_Exit_error);
3379 while(!ds->eof){
3380 unsigned char* start;
3381 int in_size=ds_get_packet(ds,&start);
3382 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
3383 && stream_dump_type==2) fwrite(&in_size,1,4,f);
3384 if(in_size>0) fwrite(start,in_size,1,f);
3386 fclose(f);
3387 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
3388 exit_player_with_rc(MSGTR_Exit_eof, 0);
3391 sh_audio=d_audio->sh;
3392 sh_video=d_video->sh;
3394 if(sh_video){
3396 current_module="video_read_properties";
3397 if(!video_read_properties(sh_video)) {
3398 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
3399 sh_video=d_video->sh=NULL;
3400 } else {
3401 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3402 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
3403 sh_video->fps,sh_video->frametime
3406 /* need to set fps here for output encoders to pick it up in their init */
3407 if(force_fps){
3408 sh_video->fps=force_fps;
3409 sh_video->frametime=1.0f/sh_video->fps;
3411 vo_fps = sh_video->fps;
3413 if(!sh_video->fps && !force_fps){
3414 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
3415 sh_video=d_video->sh=NULL;
3421 fflush(stdout);
3423 if(!sh_video && !sh_audio){
3424 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
3425 #ifdef HAS_DVBIN_SUPPORT
3426 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3428 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3429 if(priv->is_on)
3431 int dir;
3432 int v = last_dvb_step;
3433 if(v > 0)
3434 dir = DVB_CHANNEL_HIGHER;
3435 else
3436 dir = DVB_CHANNEL_LOWER;
3438 if(dvb_step_channel(priv, dir))
3439 eof = dvbin_reopen = 1;
3442 #endif
3443 goto goto_next_file; // exit_player(MSGTR_Exit_error);
3446 /* display clip info */
3447 demux_info_print(demuxer);
3449 //================== Read SUBTITLES (DVD & TEXT) ==========================
3450 if(vo_spudec==NULL && sh_video &&
3451 (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA ||
3452 d_dvdsub->id >= 0)){
3454 if (spudec_ifo) {
3455 unsigned int palette[16], width, height;
3456 current_module="spudec_init_vobsub";
3457 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
3458 vo_spudec=spudec_new_scaled(palette, width, height);
3461 #ifdef USE_DVDREAD
3462 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
3463 current_module="spudec_init_dvdread";
3464 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
3465 sh_video->disp_w, sh_video->disp_h);
3467 #endif
3469 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
3470 (d_dvdsub->sh != NULL) && (((sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
3471 sh_sub_t *mkv_sh_sub = (sh_sub_t *)d_dvdsub->sh;
3472 current_module = "spudec_init_matroska";
3473 vo_spudec =
3474 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
3475 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
3476 mkv_sh_sub->height);
3477 forced_subs_only = mkv_sh_sub->forced_subs_only;
3480 if (vo_spudec==NULL) {
3481 current_module="spudec_init_normal";
3482 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
3483 spudec_set_font_factor(vo_spudec,font_factor);
3486 if (vo_spudec!=NULL)
3487 inited_flags|=INITED_SPUDEC;
3491 // Apply current settings for forced subs
3492 if (vo_spudec!=NULL)
3493 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
3495 #ifdef USE_SUB
3496 if(sh_video) {
3497 // after reading video params we should load subtitles because
3498 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3499 // check .sub
3500 current_module="read_subtitles_file";
3501 if(sub_name){
3502 for (i = 0; sub_name[i] != NULL; ++i)
3503 add_subtitles (sub_name[i], sh_video->fps, 0);
3505 if(sub_auto) { // auto load sub file ...
3506 char *psub = get_path( "sub/" );
3507 char **tmp = sub_filenames((psub ? psub : ""), filename);
3508 int i = 0;
3509 free(psub); // release the buffer created by get_path() above
3510 while (tmp[i]) {
3511 add_subtitles (tmp[i], sh_video->fps, 0);
3512 free(tmp[i++]);
3514 free(tmp);
3516 if (set_of_sub_size > 0) {
3517 // setup global sub numbering
3518 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
3519 global_sub_size += set_of_sub_size;
3522 #endif /* USE_SUB */
3524 if (global_sub_size) {
3525 // find the best sub to use
3526 if (vobsub_id >= 0) {
3527 // if user asks for a vobsub id, use that first.
3528 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
3529 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
3530 // if user asks for a dvd sub id, use that next.
3531 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
3532 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
3533 // if there are text subs to use, use those. (autosubs come last here)
3534 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
3536 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
3537 // if nothing else works, get subs from the demuxer.
3538 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
3540 } else {
3541 // nothing worth doing automatically.
3542 global_sub_pos = -1;
3544 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3545 global_sub_pos--;
3546 mp_property_do("sub",M_PROPERTY_STEP_UP,NULL);
3547 if(subdata)
3548 switch (stream_dump_type) {
3549 case 3: list_sub_file(subdata); break;
3550 case 4: dump_mpsub(subdata, sh_video->fps); break;
3551 case 6: dump_srt(subdata, sh_video->fps); break;
3552 case 7: dump_microdvd(subdata, sh_video->fps); break;
3553 case 8: dump_jacosub(subdata, sh_video->fps); break;
3554 case 9: dump_sami(subdata, sh_video->fps); break;
3558 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n", filename);
3559 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_DEMUXER=%s\n", demuxer->desc->name);
3560 if (sh_video) {
3561 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3562 if (sh_video->format >= 0x20202020)
3563 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video->format);
3564 else
3565 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
3566 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
3567 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
3568 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
3569 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
3570 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
3572 if (sh_audio) {
3573 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3574 if (sh_audio->format >= 0x20202020)
3575 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio->format);
3576 else
3577 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
3578 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
3579 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
3580 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
3582 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
3584 if(!sh_video) goto main; // audio-only
3586 //================== Init VIDEO (codec & libvo) ==========================
3587 if(!fixed_vo || !(inited_flags&INITED_VO)){
3588 current_module="preinit_libvo";
3590 vo_config_count=0;
3591 //if((video_out->preinit(vo_subdevice))!=0){
3592 if(!(video_out=init_best_video_out(video_driver_list))){
3593 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
3594 goto goto_next_file; // exit_player(MSGTR_Exit_error);
3596 sh_video->video_out=video_out;
3597 inited_flags|=INITED_VO;
3600 vf_vo_data.vo = video_out;
3601 current_module="init_video_filters";
3603 char* vf_arg[] = { "_oldargs_", (char*)&vf_vo_data , NULL };
3604 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
3606 #ifdef HAVE_MENU
3607 if(use_menu) {
3608 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
3609 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
3610 if(!vf_menu) {
3611 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
3612 use_menu = 0;
3615 if(vf_menu)
3616 sh_video->vfilter=(void*)vf_menu;
3617 #endif
3618 #ifdef USE_ASS
3619 if(ass_enabled) {
3620 int i;
3621 int insert = 1;
3622 if (vf_settings)
3623 for (i = 0; vf_settings[i].name; ++i)
3624 if (strcmp(vf_settings[i].name, "ass") == 0) {
3625 insert = 0;
3626 break;
3628 if (insert) {
3629 extern vf_info_t vf_info_ass;
3630 vf_info_t* libass_vfs[] = {&vf_info_ass, NULL};
3631 char* vf_arg[] = {"auto", "1", NULL};
3632 vf_instance_t* vf_ass = vf_open_plugin(libass_vfs,sh_video->vfilter,"ass",vf_arg);
3633 if (vf_ass)
3634 sh_video->vfilter=(void*)vf_ass;
3635 else
3636 mp_msg(MSGT_CPLAYER,MSGL_ERR, "ASS: cannot add video filter\n");
3639 #endif
3640 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
3642 #ifdef USE_ASS
3643 if (ass_enabled)
3644 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_EOSD, 0);
3645 #endif
3647 current_module="init_video_codec";
3649 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
3650 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
3651 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
3653 if(!sh_video->inited){
3654 if(!fixed_vo) uninit_player(INITED_VO);
3655 if(!sh_audio) goto goto_next_file;
3656 sh_video = d_video->sh = NULL;
3657 goto main; // exit_player(MSGTR_Exit_error);
3660 inited_flags|=INITED_VCODEC;
3662 if (sh_video->codec)
3663 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", sh_video->codec->name);
3665 if(auto_quality>0){
3666 // Auto quality option enabled
3667 output_quality=get_video_quality_max(sh_video);
3668 if(auto_quality>output_quality) auto_quality=output_quality;
3669 else output_quality=auto_quality;
3670 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
3671 set_video_quality(sh_video,output_quality);
3674 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3676 current_module="init_vo";
3678 if(vo_flags & 0x08 && vo_spudec)
3679 spudec_set_hw_spu(vo_spudec,video_out);
3681 #ifdef HAVE_FREETYPE
3682 force_load_font = 1;
3683 #endif
3685 //================== MAIN: ==========================
3686 main:
3687 current_module="main";
3689 if(playing_msg) {
3690 char* msg = m_properties_expand_string(mp_properties,playing_msg);
3691 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",msg);
3692 free(msg);
3696 // Disable the term OSD in verbose mode
3697 if(verbose) term_osd = 0;
3698 fflush(stdout);
3700 #ifdef HAVE_NEW_GUI
3701 if ( use_gui )
3703 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
3704 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
3705 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
3706 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
3707 guiGetEvent( guiSetDemuxer,(char *)demuxer );
3709 #endif
3712 //int frame_corr_num=0; //
3713 //float v_frame=0; // Video
3714 float time_frame=0; // Timer
3715 //float num_frames=0; // number of frames played
3716 double last_pts = MP_NOPTS_VALUE;
3717 int grab_frames=0;
3718 int drop_frame=0; // current dropping status
3719 int dropped_frames=0; // how many frames dropped since last non-dropped frame
3720 int too_slow_frame_cnt=0;
3721 int too_fast_frame_cnt=0;
3722 // for auto-quality:
3723 double vdecode_time;
3724 unsigned int lastframeout_ts=0;
3725 /*float time_frame_corr_avg=0;*/ /* unused */
3727 float next_frame_time=0;
3728 int frame_time_remaining=0; // flag
3729 int blit_frame=0;
3730 int was_paused=0;
3732 // Make sure old OSD does not stay around,
3733 // e.g. with -fixed-vo and same-resolution files
3734 clear_osd_msgs();
3735 update_osd_msg();
3737 //================ SETUP AUDIO ==========================
3739 if(sh_audio){
3740 reinit_audio_chain();
3741 if (sh_audio && sh_audio->codec)
3742 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
3745 current_module="av_init";
3747 if(sh_video){
3748 sh_video->timer=0;
3749 if (! ignore_start)
3750 audio_delay += sh_video->stream_delay;
3752 if(sh_audio){
3753 if (! ignore_start)
3754 audio_delay -= sh_audio->stream_delay;
3755 sh_audio->delay=-audio_delay;
3758 if(!sh_audio){
3759 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
3760 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
3761 ds_free_packs(d_audio); // free buffered chunks
3762 //d_audio->id=-2; // do not read audio chunks
3763 //uninit_player(INITED_AO); // close device
3765 if(!sh_video){
3766 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
3767 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
3768 ds_free_packs(d_video);
3769 d_video->id=-2;
3770 //if(!fixed_vo) uninit_player(INITED_VO);
3773 if (!sh_video && !sh_audio)
3774 goto goto_next_file;
3776 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3777 if(force_fps && sh_video){
3778 vo_fps = sh_video->fps=force_fps;
3779 sh_video->frametime=1.0f/sh_video->fps;
3780 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
3783 //==================== START PLAYING =======================
3785 if(loop_times>1) loop_times--; else
3786 if(loop_times==1) loop_times = -1;
3788 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
3790 total_time_usage_start=GetTimer();
3791 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
3792 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
3793 play_n_frames=play_n_frames_mf;
3795 if(play_n_frames==0){
3796 eof=PT_NEXT_ENTRY; goto goto_next_file;
3799 while(!eof){
3800 float aq_sleep_time=0;
3801 if(!sh_audio && d_audio->sh) {
3802 sh_audio = d_audio->sh;
3803 sh_audio->ds = d_audio;
3804 reinit_audio_chain();
3807 /*========================== PLAY AUDIO ============================*/
3809 while(sh_audio){
3810 unsigned int t;
3811 double tt;
3812 int playsize;
3813 int playflags=0;
3814 int audio_eof=0;
3816 current_module="play_audio";
3818 ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
3819 playsize=audio_out->get_space();
3821 // handle audio-only case:
3822 if(playsize < ao_data.outburst &&
3823 !sh_video) { // buffer is full, do not block here!!!
3824 usec_sleep(10000); // Wait a tick before retry
3825 continue;
3828 if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
3830 // Fill buffer if needed:
3831 current_module="decode_audio"; // Enter AUDIO decoder module
3832 t=GetTimer();
3833 while (sh_audio->a_out_buffer_len < playsize) {
3834 int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
3835 playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
3836 if(ret<=0) { // EOF?
3837 if (d_audio->eof) {
3838 audio_eof = 1;
3839 if (!sh_video && sh_audio->a_out_buffer_len == 0)
3840 eof = PT_NEXT_ENTRY;
3842 break;
3844 sh_audio->a_out_buffer_len+=ret;
3846 t=GetTimer()-t;
3847 tt = t*0.000001f; audio_time_usage+=tt;
3848 if (playsize > sh_audio->a_out_buffer_len) {
3849 playsize = sh_audio->a_out_buffer_len;
3850 if (audio_eof)
3851 playflags |= AOPLAY_FINAL_CHUNK;
3853 if (!playsize)
3854 break;
3856 // play audio:
3857 current_module="play_audio";
3858 playsize = audio_out->play(sh_audio->a_out_buffer, playsize, playflags);
3860 if(playsize>0){
3861 sh_audio->a_out_buffer_len-=playsize;
3862 memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len);
3863 sh_audio->delay+=playback_speed*playsize/(double)ao_data.bps;
3865 else if (audio_eof && audio_out->get_delay() < .04) {
3866 // Sanity check to avoid hanging in case current ao doesn't output
3867 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3868 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n");
3869 sh_audio->a_out_buffer_len = 0;
3871 break;
3872 } // while(sh_audio)
3874 if(!sh_video) {
3875 // handle audio-only case:
3876 if(!quiet) {
3877 double a_pos = playing_audio_pts(sh_audio, d_audio, audio_out);
3878 print_status(a_pos, 0, 0);
3880 } else {
3882 /*========================== PLAY VIDEO ============================*/
3884 float frame_time=next_frame_time;
3886 vo_pts=sh_video->timer*90000.0;
3887 vo_fps=sh_video->fps;
3889 if(!frame_time_remaining){
3890 //-------------------- Decode a frame: -----------------------
3891 blit_frame = 0; // Don't blit if we hit EOF
3892 vdecode_time=video_time_usage;
3893 if (!correct_pts) while(1)
3894 { unsigned char* start=NULL;
3895 int in_size;
3896 // get it!
3897 current_module="video_read_frame";
3898 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
3899 if(in_size<0){ eof=1; break; }
3900 if(in_size>max_framesize) max_framesize=in_size; // stats
3901 sh_video->timer+=frame_time;
3902 if(sh_audio) sh_audio->delay-=frame_time;
3903 time_frame+=frame_time; // for nosound
3904 // video_read_frame can change fps (e.g. for ASF video)
3905 vo_fps = sh_video->fps;
3906 // check for frame-drop:
3907 current_module="check_framedrop";
3908 if(sh_audio && !d_audio->eof){
3909 float delay=playback_speed*audio_out->get_delay();
3910 float d=delay-sh_audio->delay;
3911 // we should avoid dropping too many frames in sequence unless we
3912 // are too late. and we allow 100ms A-V delay here:
3913 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
3914 drop_frame=frame_dropping;
3915 ++drop_frame_cnt;
3916 ++dropped_frames;
3917 } else {
3918 drop_frame=dropped_frames=0;
3920 ++total_frame_cnt;
3922 // decode:
3923 current_module="decode_video";
3924 // printf("Decode! %p %d \n",start,in_size);
3925 blit_frame=decode_video(sh_video,start,in_size,drop_frame, sh_video->pts);
3926 break;
3928 else while (1) {
3929 if (!generate_video_frame(sh_video, d_video)) {
3930 eof = 1;
3931 break;
3933 sh_video->pts = vf_vo_data.pts;
3934 if (sh_video->pts == MP_NOPTS_VALUE) {
3935 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts after filters MISSING\n");
3936 sh_video->pts = last_pts;
3938 if (last_pts == MP_NOPTS_VALUE)
3939 last_pts = sh_video->pts;
3940 else if (last_pts >= sh_video->pts) {
3941 last_pts = sh_video->pts;
3942 mp_msg(MSGT_CPLAYER, MSGL_WARN, "pts value <= previous");
3944 frame_time = sh_video->pts - last_pts;
3945 last_pts = sh_video->pts;
3946 sh_video->timer += frame_time;
3947 time_frame += frame_time; // for nosound
3948 if(sh_audio)
3949 sh_audio->delay -= frame_time;
3950 blit_frame = 1;
3951 break;
3954 vdecode_time=video_time_usage-vdecode_time;
3955 //------------------------ frame decoded. --------------------
3957 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
3959 if(sh_video->vf_inited<0){
3960 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
3961 eof=1; goto goto_next_file;
3966 // ==========================================================================
3968 // current_module="draw_osd";
3969 // if(vo_config_count) video_out->draw_osd();
3971 #ifdef HAVE_NEW_GUI
3972 if(use_gui) guiEventHandling();
3973 #endif
3975 current_module="calc_sleep_time";
3977 #if 0
3978 { // debug frame dropping code
3979 float delay=audio_out->get_delay();
3980 mp_msg(MSGT_AVSYNC,MSGL_V,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
3981 sh_video->timer,sh_audio->timer-delay,
3982 sh_video->timer-(sh_audio->timer-delay),
3983 delay,drop_frame);
3985 #endif
3987 if(drop_frame && !frame_time_remaining && !autosync){
3989 * Note: time_frame should not be forced to 0 in autosync mode.
3990 * It is used as a cumulative counter to predict and correct the
3991 * delay measurements from the audio driver. time_frame is already
3992 * < 0, so the "time to sleep" code does not actually sleep. Also,
3993 * blit_frame is already 0 because drop_frame was true when
3994 * decode_video was called (which causes it to set blit_frame to 0.)
3995 * When autosync==0, the default behavior is still completely unchanged.
3998 time_frame=0; // don't sleep!
3999 blit_frame=0; // don't display!
4001 } else {
4003 // It's time to sleep...
4005 frame_time_remaining=0;
4006 time_frame-=GetRelativeTime(); // reset timer
4008 if(sh_audio && !d_audio->eof){
4009 float delay=playback_speed*audio_out->get_delay();
4010 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"delay=%f\n",delay);
4012 if (autosync){
4014 * Adjust this raw delay value by calculating the expected
4015 * delay for this frame and generating a new value which is
4016 * weighted between the two. The higher autosync is, the
4017 * closer to the delay value gets to that which "-nosound"
4018 * would have used, and the longer it will take for A/V
4019 * sync to settle at the right value (but it eventually will.)
4020 * This settling time is very short for values below 100.
4022 float predicted = sh_audio->delay+time_frame;
4023 float difference = delay - predicted;
4024 delay = predicted + difference / (float)autosync;
4027 time_frame=delay-sh_audio->delay;
4029 // delay = amount of audio buffered in soundcard/driver
4030 if(delay>0.25) delay=0.25; else
4031 if(delay<0.10) delay=0.10;
4032 if(time_frame>delay*0.6){
4033 // sleep time too big - may cause audio drops (buffer underrun)
4034 frame_time_remaining=1;
4035 time_frame=delay*0.5;
4038 } else {
4040 // NOSOUND:
4041 if( (time_frame<-3*frame_time || time_frame>3*frame_time) || benchmark)
4042 time_frame=0;
4046 // if(mp_msg_test(MSGT_CPLAYER,MSGL_DBG2)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
4048 aq_sleep_time+=time_frame;
4050 } // !drop_frame
4052 //============================== SLEEP: ===================================
4054 time_frame/=playback_speed;
4056 // flag 256 means: libvo driver does its timing (dvb card)
4057 if(time_frame>0.001 && !(vo_flags&256)){
4059 #ifdef HAVE_RTC
4060 if(rtc_fd>=0){
4061 // -------- RTC -----------
4062 current_module="sleep_rtc";
4063 while (time_frame > 0.000) {
4064 unsigned long rtc_ts;
4065 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
4066 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
4067 time_frame-=GetRelativeTime();
4069 } else
4070 #endif
4071 #ifdef SYS_DARWIN
4073 current_module="sleep_darwin";
4074 while(time_frame>0.005) {
4075 usec_sleep(1000000*time_frame);
4076 time_frame-=GetRelativeTime();
4079 #else
4081 // -------- TIMER + SOFTSLEEP -----------
4082 // assume kernel HZ=100 for softsleep, works with larger HZ but with
4083 // unnecessarily high CPU usage
4084 float margin = softsleep ? 0.011 : 0;
4085 current_module="sleep_timer";
4086 while (time_frame > margin) {
4087 usec_sleep(1000000 * (time_frame - margin));
4088 time_frame -= GetRelativeTime();
4090 if(softsleep){
4091 current_module="sleep_soft";
4092 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
4093 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU
4096 #endif /* SYS_DARWIN */
4099 //if(!frame_time_remaining){ // should we display the frame now?
4101 //====================== FLIP PAGE (VIDEO BLT): =========================
4103 current_module="vo_check_events";
4104 if(vo_config_count) video_out->check_events();
4106 current_module="flip_page";
4107 if (!frame_time_remaining) {
4108 if(blit_frame){
4109 unsigned int t2=GetTimer();
4110 double tt;
4111 float j;
4112 #define FRAME_LAG_WARN 0.2
4113 j = ((float)t2 - lastframeout_ts) / 1000000;
4114 lastframeout_ts = GetTimer();
4115 if (j < frame_time + frame_time * -FRAME_LAG_WARN)
4116 too_fast_frame_cnt++;
4117 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
4118 else if (j > frame_time + frame_time * FRAME_LAG_WARN)
4119 too_slow_frame_cnt++;
4120 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
4122 if(vo_config_count) video_out->flip_page();
4123 if (play_n_frames >= 0) {
4124 --play_n_frames;
4125 if (play_n_frames <= 0) eof = PT_NEXT_ENTRY;
4128 // usec_sleep(50000); // test only!
4129 t2=GetTimer()-t2;
4130 tt = t2*0.000001f;
4131 vout_time_usage+=tt;
4132 } else {
4134 Well, no blitting is needed, but some devices (such as yuv4mpeg)
4135 must output frames otherwise A/V desync will occur. -- Alvieboy
4137 if (vo_config_count)
4138 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL);
4141 //====================== A-V TIMESTAMP CORRECTION: =========================
4143 current_module="av_sync";
4145 if(sh_audio){
4146 double a_pts, v_pts;
4148 if (autosync)
4150 * If autosync is enabled, the value for delay must be calculated
4151 * a bit differently. It is set only to the difference between
4152 * the audio and video timers. Any attempt to include the real
4153 * or corrected delay causes the pts_correction code below to
4154 * try to correct for the changes in delay which autosync is
4155 * trying to measure. This keeps the two from competing, but still
4156 * allows the code to correct for PTS drift *only*. (Using a delay
4157 * value here, even a "corrected" one, would be incompatible with
4158 * autosync mode.)
4160 a_pts = written_audio_pts(sh_audio, d_audio) - sh_audio->delay;
4161 else
4162 a_pts = playing_audio_pts(sh_audio, d_audio, audio_out);
4164 v_pts=sh_video ? sh_video->pts : d_video->pts;
4167 static int drop_message=0;
4168 double AV_delay = a_pts - audio_delay - v_pts;
4169 double x;
4170 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
4171 ++drop_message;
4172 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
4174 if (autosync)
4175 x = AV_delay*0.1f;
4176 else
4177 /* Do not correct target time for the next frame if this frame
4178 * was late not because of wrong target time but because the
4179 * target time could not be met */
4180 x = (AV_delay + time_frame * playback_speed) * 0.1f;
4181 if(x<-max_pts_correction) x=-max_pts_correction; else
4182 if(x> max_pts_correction) x= max_pts_correction;
4183 if(default_max_pts_correction>=0)
4184 max_pts_correction=default_max_pts_correction;
4185 else
4186 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
4187 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
4188 if(!quiet)
4189 print_status(a_pts - audio_delay, AV_delay, c_total);
4192 } else {
4193 // No audio:
4195 if(!quiet)
4196 print_status(0, 0, 0);
4200 //============================ Auto QUALITY ============================
4202 /*Output quality adjustments:*/
4203 if(auto_quality>0){
4204 current_module="autoq";
4205 // float total=0.000001f * (GetTimer()-aq_total_time);
4206 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4207 if(output_quality<auto_quality && aq_sleep_time>0)
4208 ++output_quality;
4209 else
4210 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4211 if(output_quality>1 && aq_sleep_time<0)
4212 --output_quality;
4213 else
4214 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
4215 output_quality=0;
4216 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4217 set_video_quality(sh_video,output_quality);
4220 } // end if(sh_video)
4222 //============================ Handle PAUSE ===============================
4224 current_module="pause";
4226 #ifdef USE_OSD
4227 if(osd_visible){
4228 // 36000000 means max timed visibility is 1 hour into the future, if
4229 // the difference is greater assume it's wrapped around from below 0
4230 if (osd_visible - GetTimerMS() > 36000000) {
4231 osd_visible = 0;
4232 vo_osd_progbar_type=-1; // disable
4233 vo_osd_changed(OSDTYPE_PROGBAR);
4234 if (osd_function != OSD_PAUSE)
4235 osd_function = OSD_PLAY;
4238 #endif
4240 if(osd_function==OSD_PAUSE){
4241 mp_cmd_t* cmd;
4242 if(!quiet) {
4243 // Small hack to display the pause message on the OSD line.
4244 // The pause string is: "\n == PAUSE == \r" so we need to
4245 // take the first and the last char out
4246 if(use_term_osd) {
4247 char msg[128] = MSGTR_Paused;
4248 int mlen = strlen(msg);
4249 msg[mlen-1] = '\0';
4250 set_osd_msg(OSD_MSG_PAUSE,1,0,"%s",msg+1);
4251 update_osd_msg();
4252 } else
4253 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
4254 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_PAUSED\n");
4255 fflush(stdout);
4257 #ifdef HAVE_NEW_GUI
4258 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
4259 #endif
4260 if (video_out && sh_video && vo_config_count)
4261 video_out->control(VOCTRL_PAUSE, NULL);
4263 if (audio_out && sh_audio)
4264 audio_out->pause(); // pause audio, keep data if possible
4266 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
4267 if(sh_video && video_out && vo_config_count) video_out->check_events();
4268 #ifdef HAVE_NEW_GUI
4269 if(use_gui){
4270 guiEventHandling();
4271 guiGetEvent( guiReDraw,NULL );
4272 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
4274 #endif
4275 #ifdef HAVE_MENU
4276 if(vf_menu)
4277 vf_menu_pause_update(vf_menu);
4278 #endif
4279 usec_sleep(20000);
4281 if (cmd && cmd->id == MP_CMD_PAUSE) {
4282 cmd = mp_input_get_cmd(0,1,0);
4283 mp_cmd_free(cmd);
4285 osd_function=OSD_PLAY;
4286 if (audio_out && sh_audio)
4287 audio_out->resume(); // resume audio
4288 if (video_out && sh_video && vo_config_count)
4289 video_out->control(VOCTRL_RESUME, NULL); // resume video
4290 (void)GetRelativeTime(); // keep TF around FT in next cycle
4291 #ifdef HAVE_NEW_GUI
4292 if (use_gui)
4294 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
4295 guiGetEvent( guiCEvent,(char *)guiSetPlay );
4297 #endif
4298 was_paused = 1;
4301 // handle -sstep
4302 if(step_sec>0) {
4303 osd_function=OSD_FFW;
4304 rel_seek_secs+=step_sec;
4307 //================= EDL =========================================
4309 if( next_edl_record ) { // Are we (still?) doing EDL?
4310 if ( !sh_video ) {
4311 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
4312 free_edl(edl_records);
4313 next_edl_record = NULL;
4314 edl_records = NULL;
4315 } else {
4316 if( sh_video->pts >= next_edl_record->start_sec ) {
4317 if( next_edl_record->action == EDL_SKIP ) {
4318 osd_function = OSD_FFW;
4319 abs_seek_pos = 0;
4320 rel_seek_secs = next_edl_record->length_sec;
4321 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec );
4322 edl_decision = 1;
4323 } else if( next_edl_record->action == EDL_MUTE ) {
4324 edl_muted = !edl_muted;
4325 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
4326 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
4328 next_edl_record=next_edl_record->next;
4333 //================= Keyboard events, SEEKing ====================
4335 current_module="key_events";
4338 mp_cmd_t* cmd;
4339 int brk_cmd = 0;
4340 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
4341 if(!set_property_command(cmd))
4342 switch(cmd->id) {
4343 case MP_CMD_SEEK : {
4344 float v;
4345 int abs;
4346 if(sh_video)
4347 osd_show_percentage = sh_video->fps;
4348 v = cmd->args[0].v.f;
4349 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
4350 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
4351 abs_seek_pos = 1;
4352 if(sh_video)
4353 osd_function= (v > sh_video->pts) ? OSD_FFW : OSD_REW;
4354 rel_seek_secs = v;
4356 else if(abs) { /* Absolute seek by percentage */
4357 abs_seek_pos = 3;
4358 if(sh_video)
4359 osd_function= OSD_FFW; // Direction isn't set correctly
4360 rel_seek_secs = v/100.0;
4362 else {
4363 rel_seek_secs+= v;
4364 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
4366 brk_cmd = 1;
4367 } break;
4368 case MP_CMD_SET_PROPERTY: {
4369 m_option_t* prop = mp_property_find(cmd->args[0].v.s);
4370 if(!prop) mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unkown property: '%s'\n",cmd->args[0].v.s);
4371 else if(m_property_parse(prop,cmd->args[1].v.s) <= 0)
4372 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to set property '%s' to '%s'.\n",
4373 cmd->args[0].v.s,cmd->args[1].v.s);
4375 } break;
4376 case MP_CMD_GET_PROPERTY: {
4377 m_option_t* prop;
4378 void* val;
4379 prop = mp_property_find(cmd->args[0].v.s);
4380 if(!prop) {
4381 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unkown property: '%s'\n",cmd->args[0].v.s);
4382 break;
4384 /* Use m_option_print directly to get easily parseable values. */
4385 val = calloc(1,prop->type->size);
4386 if(m_property_do(prop,M_PROPERTY_GET,val) <= 0) {
4387 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to get value of property '%s'.\n",
4388 cmd->args[0].v.s);
4389 break;
4391 tmp = m_option_print(prop,val);
4392 if(!tmp || tmp == (char*)-1) {
4393 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to print value of property '%s'.\n",
4394 cmd->args[0].v.s);
4395 break;
4397 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_%s=%s\n",cmd->args[0].v.s,tmp);
4398 free(tmp);
4399 } break;
4400 case MP_CMD_EDL_MARK:
4401 if( edl_fd ) {
4402 float v = sh_video ? sh_video->pts :
4403 playing_audio_pts(sh_audio, d_audio, audio_out);
4405 if(begin_skip == MP_NOPTS_VALUE)
4407 begin_skip = v;
4408 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
4409 }else{
4410 if(begin_skip > v)
4412 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
4413 }else{
4414 fprintf(edl_fd, "%f %f %d\n", begin_skip, v, 0);
4415 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
4417 begin_skip = MP_NOPTS_VALUE;
4420 break;
4421 case MP_CMD_SWITCH_RATIO : {
4422 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
4423 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
4424 else
4425 movie_aspect = cmd->args[0].v.f;
4426 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
4427 } break;
4428 case MP_CMD_SPEED_INCR : {
4429 float v = cmd->args[0].v.f;
4430 playback_speed += v;
4431 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4432 build_afilter_chain(sh_audio, &ao_data);
4433 } break;
4434 case MP_CMD_SPEED_MULT : {
4435 float v = cmd->args[0].v.f;
4436 playback_speed *= v;
4437 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4438 build_afilter_chain(sh_audio, &ao_data);
4439 } break;
4440 case MP_CMD_SPEED_SET : {
4441 float v = cmd->args[0].v.f;
4442 playback_speed = v;
4443 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4444 build_afilter_chain(sh_audio, &ao_data);
4445 } break;
4446 case MP_CMD_FRAME_STEP :
4447 case MP_CMD_PAUSE : {
4448 cmd->pausing = 1;
4449 brk_cmd = 1;
4450 } break;
4451 case MP_CMD_QUIT : {
4452 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
4454 case MP_CMD_GRAB_FRAMES : {
4455 grab_frames=2;
4456 } break;
4457 case MP_CMD_PLAY_TREE_STEP : {
4458 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
4459 int force = cmd->args[1].v.i;
4461 #ifdef HAVE_NEW_GUI
4462 if (use_gui) {
4463 int i=0;
4464 if (n>0)
4465 for (i=0;i<n;i++)
4466 mplNext();
4467 else
4468 for (i=0;i<-1*n;i++)
4469 mplPrev();
4470 } else
4471 #endif
4473 if(!force && playtree_iter) {
4474 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
4476 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
4477 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
4478 play_tree_iter_free(i);
4479 } else
4480 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
4481 if(eof)
4482 play_tree_step = n;
4483 brk_cmd = 1;
4485 } break;
4486 case MP_CMD_PLAY_TREE_UP_STEP : {
4487 int n = cmd->args[0].v.i > 0 ? 1 : -1;
4488 int force = cmd->args[1].v.i;
4490 if(!force && playtree_iter) {
4491 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
4492 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
4493 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
4494 play_tree_iter_free(i);
4495 } else
4496 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
4497 brk_cmd = 1;
4498 } break;
4499 case MP_CMD_PLAY_ALT_SRC_STEP : {
4500 if(playtree_iter && playtree_iter->num_files > 1) {
4501 int v = cmd->args[0].v.i;
4502 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
4503 eof = PT_NEXT_SRC;
4504 else if(v < 0 && playtree_iter->file > 1)
4505 eof = PT_PREV_SRC;
4507 brk_cmd = 1;
4508 } break;
4509 case MP_CMD_SUB_STEP : {
4510 #ifdef USE_SUB
4511 if (sh_video) {
4512 int movement = cmd->args[0].v.i;
4513 step_sub(subdata, sh_video->pts, movement);
4514 #ifdef USE_ASS
4515 if (ass_track)
4516 sub_delay += ass_step_sub(ass_track, (sh_video->pts + sub_delay) * 1000 + .5, movement) / 1000.;
4517 #endif
4518 set_osd_msg(OSD_MSG_SUB_DELAY,1,osd_duration,
4519 MSGTR_OSDSubDelay, ROUND(sub_delay*1000));
4521 #endif
4522 } break;
4523 case MP_CMD_SUB_LOG : {
4524 #ifdef USE_SUB
4525 log_sub();
4526 #endif
4527 } break;
4528 case MP_CMD_OSD : {
4529 int v = cmd->args[0].v.i;
4530 int max = use_term_osd ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
4531 if(osd_level > max) osd_level = max;
4532 if(v < 0)
4533 osd_level=(osd_level+1)%(max+1);
4534 else
4535 osd_level= v > max ? max : v;
4536 /* Show OSD state when disabled, but not when an explicit
4537 argument is given to the OSD command, i.e. in slave mode. */
4538 if (v == -1 && osd_level <= 1)
4539 set_osd_msg(OSD_MSG_OSD_STATUS,0,osd_duration,
4540 MSGTR_OSDosd, osd_level ? MSGTR_OSDenabled : MSGTR_OSDdisabled);
4541 else
4542 rm_osd_msg(OSD_MSG_OSD_STATUS);
4543 } break;
4544 case MP_CMD_OSD_SHOW_TEXT : {
4545 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
4546 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
4547 "%-.63s",cmd->args[0].v.s);
4548 } break;
4549 case MP_CMD_OSD_SHOW_PROPERTY_TEXT : {
4550 char* txt = m_properties_expand_string(mp_properties,cmd->args[0].v.s);
4551 /* if no argument supplied take default osd_duration, else <arg> ms. */
4552 if(txt) {
4553 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
4554 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
4555 "%-.63s",txt);
4556 free(txt);
4558 } break;
4559 case MP_CMD_LOADFILE : {
4560 play_tree_t* e = play_tree_new();
4561 play_tree_add_file(e,cmd->args[0].v.s);
4563 if (cmd->args[1].v.i) // append
4564 play_tree_append_entry(playtree, e);
4565 else {
4566 // Go back to the starting point.
4567 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
4568 /* NOP */;
4569 play_tree_free_list(playtree->child,1);
4570 play_tree_set_child(playtree,e);
4571 play_tree_iter_step(playtree_iter,0,0);
4572 eof = PT_NEXT_SRC;
4574 brk_cmd = 1;
4575 } break;
4576 case MP_CMD_LOADLIST : {
4577 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
4578 if(!e)
4579 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
4580 else {
4581 if (cmd->args[1].v.i) // append
4582 play_tree_append_entry(playtree, e);
4583 else {
4584 // Go back to the starting point.
4585 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
4586 /* NOP */;
4587 play_tree_free_list(playtree->child,1);
4588 play_tree_set_child(playtree,e);
4589 play_tree_iter_step(playtree_iter,0,0);
4590 eof = PT_NEXT_SRC;
4593 brk_cmd = 1;
4594 } break;
4595 #ifdef USE_TV
4596 case MP_CMD_TV_SET_FREQ : {
4597 if (file_format == DEMUXER_TYPE_TV)
4598 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
4599 } break;
4600 case MP_CMD_TV_SET_NORM : {
4601 if (file_format == DEMUXER_TYPE_TV)
4602 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
4603 } break;
4604 case MP_CMD_TV_STEP_CHANNEL : {
4605 if (file_format == DEMUXER_TYPE_TV) {
4606 int v = cmd->args[0].v.i;
4607 if(v > 0){
4608 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
4609 } else {
4610 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
4612 if (tv_channel_list) {
4613 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
4614 MSGTR_OSDChannel, tv_channel_current->name);
4615 //vo_osd_changed(OSDTYPE_SUBTITLE);
4619 #ifdef HAS_DVBIN_SUPPORT
4620 if((stream->type == STREAMTYPE_DVB) && stream->priv)
4622 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
4623 if(priv->is_on)
4625 int dir;
4626 int v = cmd->args[0].v.i;
4628 last_dvb_step = v;
4629 if(v > 0)
4630 dir = DVB_CHANNEL_HIGHER;
4631 else
4632 dir = DVB_CHANNEL_LOWER;
4635 if(dvb_step_channel(priv, dir))
4636 eof = dvbin_reopen = 1;
4639 #endif /* HAS_DVBIN_SUPPORT */
4640 break;
4641 case MP_CMD_TV_SET_CHANNEL : {
4642 if (file_format == DEMUXER_TYPE_TV) {
4643 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
4644 if (tv_channel_list) {
4645 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
4646 MSGTR_OSDChannel, tv_channel_current->name);
4647 //vo_osd_changed(OSDTYPE_SUBTITLE);
4650 } break;
4651 #ifdef HAS_DVBIN_SUPPORT
4652 case MP_CMD_DVB_SET_CHANNEL:
4654 if((stream->type == STREAMTYPE_DVB) && stream->priv)
4656 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
4657 if(priv->is_on)
4659 if(priv->list->current <= cmd->args[0].v.i)
4660 last_dvb_step = 1;
4661 else
4662 last_dvb_step = -1;
4664 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
4665 eof = dvbin_reopen = 1;
4669 break;
4670 #endif /* HAS_DVBIN_SUPPORT */
4671 case MP_CMD_TV_LAST_CHANNEL : {
4672 if (file_format == DEMUXER_TYPE_TV) {
4673 tv_last_channel((tvi_handle_t*)(demuxer->priv));
4674 if (tv_channel_list) {
4675 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
4676 MSGTR_OSDChannel, tv_channel_current->name);
4677 //vo_osd_changed(OSDTYPE_SUBTITLE);
4680 } break;
4681 case MP_CMD_TV_STEP_NORM : {
4682 if (file_format == DEMUXER_TYPE_TV)
4683 tv_step_norm((tvi_handle_t*)(demuxer->priv));
4684 } break;
4685 case MP_CMD_TV_STEP_CHANNEL_LIST : {
4686 if (file_format == DEMUXER_TYPE_TV)
4687 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
4688 } break;
4689 #endif /* USE_TV */
4690 case MP_CMD_SUB_LOAD:
4692 #ifdef USE_SUB
4693 if (sh_video) {
4694 int n = set_of_sub_size;
4695 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
4696 if (n != set_of_sub_size) {
4697 if (global_sub_indices[SUB_SOURCE_SUBS] < 0)
4698 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size;
4699 ++global_sub_size;
4702 #endif
4703 } break;
4704 case MP_CMD_SUB_REMOVE:
4706 #ifdef USE_SUB
4707 if (sh_video) {
4708 int v = cmd->args[0].v.i;
4709 sub_data *subd;
4710 if (v < 0) {
4711 for (v = 0; v < set_of_sub_size; ++v) {
4712 subd = set_of_subtitles[v];
4713 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
4714 sub_free(subd);
4715 set_of_subtitles[v] = NULL;
4717 global_sub_indices[SUB_SOURCE_SUBS] = -1;
4718 global_sub_size -= set_of_sub_size;
4719 set_of_sub_size = 0;
4720 if (set_of_sub_pos >= 0) {
4721 global_sub_pos = -2;
4722 vo_sub_last = vo_sub = NULL;
4723 vo_osd_changed(OSDTYPE_SUBTITLE);
4724 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
4725 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
4728 else if (v < set_of_sub_size) {
4729 subd = set_of_subtitles[v];
4730 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
4731 sub_free(subd);
4732 if (set_of_sub_pos == v) {
4733 global_sub_pos = -2;
4734 vo_sub_last = vo_sub = NULL;
4735 vo_osd_changed(OSDTYPE_SUBTITLE);
4736 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
4737 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
4739 else if (set_of_sub_pos > v) {
4740 --set_of_sub_pos;
4741 --global_sub_pos;
4743 while (++v < set_of_sub_size)
4744 set_of_subtitles[v - 1] = set_of_subtitles[v];
4745 --set_of_sub_size;
4746 --global_sub_size;
4747 if (set_of_sub_size <= 0)
4748 global_sub_indices[SUB_SOURCE_SUBS] = -1;
4749 set_of_subtitles[set_of_sub_size] = NULL;
4752 #endif /* USE_SUB */
4753 } break;
4754 case MP_CMD_GET_SUB_VISIBILITY:
4756 #ifdef USE_SUB
4757 if (sh_video) {
4758 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
4760 #endif
4761 } break;
4762 case MP_CMD_SCREENSHOT :
4763 if(vo_config_count){
4764 mp_msg(MSGT_CPLAYER,MSGL_INFO,"sending VFCTRL_SCREENSHOT!\n");
4765 if(CONTROL_OK!=((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SCREENSHOT, 0))
4766 video_out->control(VOCTRL_SCREENSHOT, NULL);
4768 break;
4769 case MP_CMD_VF_CHANGE_RECTANGLE:
4770 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
4771 break;
4773 case MP_CMD_GET_TIME_LENGTH : {
4774 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
4775 } break;
4777 case MP_CMD_GET_VO_FULLSCREEN : {
4778 if(video_out && vo_config_count)
4779 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
4780 } break;
4782 case MP_CMD_GET_PERCENT_POS : {
4783 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer));
4784 } break;
4785 case MP_CMD_GET_TIME_POS : {
4786 float pos = 0;
4787 if (sh_video)
4788 pos = sh_video->pts;
4789 else
4790 if (sh_audio && audio_out)
4791 pos = playing_audio_pts(sh_audio, d_audio, audio_out);
4792 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
4793 } break;
4794 case MP_CMD_SWITCH_AUDIO : {
4795 int current_id = demuxer->audio->id;
4796 int v = demuxer_switch_audio(demuxer, cmd->args[0].v.i);
4797 if(v > -1 && v < MAX_A_STREAMS && v != current_id) {
4798 sh_audio_t *sh2;
4799 uninit_player(INITED_AO | INITED_ACODEC);
4800 sh2 = demuxer->a_streams[v];
4801 if(sh2) {
4802 sh2->ds = demuxer->audio;
4803 sh_audio = sh2;
4804 reinit_audio_chain();
4807 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", v);
4808 } break;
4809 case MP_CMD_RUN : {
4810 #ifndef __MINGW32__
4811 if(!fork()) {
4812 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
4813 exit(0);
4815 #endif
4816 } break;
4817 case MP_CMD_KEYDOWN_EVENTS : {
4818 mplayer_put_key(cmd->args[0].v.i);
4819 } break;
4820 case MP_CMD_SEEK_CHAPTER : {
4821 int seek = cmd->args[0].v.i;
4822 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
4823 int chap;
4824 float next_pts = 0;
4826 rel_seek_secs = 0;
4827 abs_seek_pos = 0;
4828 chap = demuxer_seek_chapter(demuxer, seek, abs, &next_pts);
4829 if(chap != -1) {
4830 if(next_pts > -1.0) {
4831 abs_seek_pos = 1;
4832 rel_seek_secs = next_pts;
4834 if(demuxer->num_chapters > chap)
4835 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter,
4836 chap, demuxer->chapters[chap].name);
4837 } else {
4838 if (seek > 0)
4839 rel_seek_secs = 1000000000.;
4840 else
4841 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter, 0, MSGTR_Unknown);
4843 break;
4844 } break;
4845 default : {
4846 #ifdef HAVE_NEW_GUI
4847 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
4848 else
4849 #endif
4850 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
4853 switch (cmd->pausing) {
4854 case 1: // "pausing"
4855 osd_function = OSD_PAUSE;
4856 break;
4857 case 3: // "pausing_toggle"
4858 was_paused = !was_paused;
4859 // fall through
4860 case 2: // "pausing_keep"
4861 if (was_paused) osd_function = OSD_PAUSE;
4863 mp_cmd_free(cmd);
4866 was_paused = 0;
4868 if (seek_to_sec) {
4869 int a,b; float d;
4871 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
4872 rel_seek_secs += 3600*a +60*b +d ;
4873 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
4874 rel_seek_secs += 60*a +d;
4875 else if (sscanf(seek_to_sec, "%f", &d)==1)
4876 rel_seek_secs += d;
4878 seek_to_sec = NULL;
4881 /* Looping. */
4882 if(eof==1 && loop_times>=0) {
4883 int l = loop_times;
4884 play_tree_iter_step(playtree_iter,0,0);
4885 loop_times = l;
4886 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
4888 if(loop_times>1) loop_times--; else
4889 if(loop_times==1) loop_times=-1;
4890 play_n_frames=play_n_frames_mf;
4891 eof=0;
4892 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
4893 loop_seek = 1;
4896 if(rel_seek_secs || abs_seek_pos){
4897 current_module="seek";
4898 if(demux_seek(demuxer,rel_seek_secs,audio_delay,abs_seek_pos)){
4899 // success:
4900 /* FIXME there should be real seeking for vobsub */
4901 if(sh_video) sh_video->pts=d_video->pts;
4902 if (vo_vobsub)
4903 //vobsub_reset(vo_vobsub);
4904 vobsub_seek(vo_vobsub,sh_video->pts);
4905 fflush(stdout);
4907 if(sh_video){
4908 current_module="seek_video_reset";
4909 resync_video_stream(sh_video);
4910 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
4911 sh_video->num_buffered_pts = 0;
4912 last_pts = MP_NOPTS_VALUE;
4915 if(sh_audio){
4916 current_module="seek_audio_reset";
4917 audio_out->reset(); // stop audio, throwing away buffered data
4918 sh_audio->a_buffer_len = 0;
4919 sh_audio->a_out_buffer_len = 0;
4921 // Set OSD:
4922 if(!loop_seek){
4923 if( !edl_decision )
4924 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer));
4927 if(sh_video) {
4928 c_total=0;
4929 max_pts_correction=0.1;
4930 osd_visible=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
4931 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
4932 drop_frame_cnt=0;
4933 too_slow_frame_cnt=0;
4934 too_fast_frame_cnt=0;
4936 if(vo_spudec) spudec_reset(vo_spudec);
4940 * We saw a seek, have to rewind the EDL operations stack
4941 * and find the next EDL action to take care of.
4944 edl_muted = 0;
4945 next_edl_record = edl_records;
4947 while (next_edl_record)
4949 /* Trying to remember if we need to mute/unmute first;
4950 * prior EDL implementation lacks this.
4953 if (next_edl_record->start_sec >= sh_video->pts)
4954 break;
4956 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
4957 next_edl_record = next_edl_record->next;
4960 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
4962 rel_seek_secs=0;
4963 abs_seek_pos=0;
4964 frame_time_remaining=0;
4965 current_module=NULL;
4966 loop_seek=0;
4969 #ifdef HAVE_NEW_GUI
4970 if(use_gui){
4971 guiEventHandling();
4972 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
4973 // get pos from frame number / total frames
4974 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
4975 } else {
4976 off_t len = ( demuxer->movi_end - demuxer->movi_start );
4977 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
4978 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
4980 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
4981 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
4982 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
4983 guiGetEvent( guiReDraw,NULL );
4984 guiGetEvent( guiSetVolume,NULL );
4985 if(guiIntfStruct.Playing==0) break; // STOP
4986 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
4987 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
4988 #ifdef USE_DVDREAD
4989 if ( stream->type == STREAMTYPE_DVD )
4991 dvd_priv_t * dvdp = stream->priv;
4992 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
4994 #endif
4996 #endif /* HAVE_NEW_GUI */
4999 //================= Update OSD ====================
5001 update_osd_msg();
5003 #ifdef USE_SUB
5004 // find sub
5005 if(subdata && sh_video && sh_video->pts>0){
5006 float pts=sh_video->pts;
5007 if(sub_fps==0) sub_fps=sh_video->fps;
5008 current_module="find_sub";
5009 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
5010 find_sub(subdata, (pts+sub_delay) *
5011 (subdata->sub_uses_time ? 100. : sub_fps));
5012 if (vo_sub) vo_sub_last = vo_sub;
5013 // FIXME! frame counter...
5014 sub_last_pts = pts;
5016 current_module=NULL;
5018 #endif
5020 #ifdef HAVE_X11
5021 if (stop_xscreensaver && sh_video) {
5022 current_module="stop_xscreensaver";
5023 xscreensaver_heartbeat();
5024 current_module=NULL;
5026 #endif
5028 // DVD sub:
5029 if(vo_config_count && vo_spudec) {
5030 unsigned char* packet=NULL;
5031 int len,timestamp;
5032 current_module="spudec";
5033 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
5034 /* Get a sub packet from the DVD or a vobsub and make a timestamp
5035 relative to sh_video->timer */
5036 while(1) {
5037 // Vobsub
5038 len = 0;
5039 if(vo_vobsub) {
5040 if(sh_video->pts+sub_delay>=0) {
5041 // The + next_frame_time is there because we'll display the sub at the next frame
5042 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
5043 if(len > 0) {
5044 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
5045 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);
5048 } else {
5049 // DVD sub
5050 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
5051 if(len > 0) {
5052 float x = d_dvdsub->pts - sh_video->pts;
5053 if (x < -10 || x > 10) // prevent missing subs on pts reset
5054 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
5055 else timestamp = 90000*(sh_video->timer + sub_delay);
5056 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);
5059 if(len<=0 || !packet) break;
5060 if(timestamp < 0) timestamp = 0;
5061 else spudec_assemble(vo_spudec,packet,len,timestamp);
5064 /* detect wether the sub has changed or not */
5065 if(spudec_changed(vo_spudec))
5066 vo_osd_changed(OSDTYPE_SPU);
5067 current_module=NULL;
5070 } // while(!eof)
5072 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
5074 #ifdef HAS_DVBIN_SUPPORT
5075 if(dvbin_reopen)
5077 eof = 0;
5078 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
5079 cache_uninit(stream);
5080 dvbin_reopen = 0;
5081 goto goto_enable_cache;
5083 #endif
5086 goto_next_file: // don't jump here after ao/vo/getch initialization!
5088 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
5090 if(benchmark){
5091 double tot=video_time_usage+vout_time_usage+audio_time_usage;
5092 double total_time_usage;
5093 total_time_usage_start=GetTimer()-total_time_usage_start;
5094 total_time_usage = (float)total_time_usage_start*0.000001;
5095 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5096 video_time_usage,vout_time_usage,audio_time_usage,
5097 total_time_usage-tot,total_time_usage);
5098 if(total_time_usage>0.0)
5099 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5100 100.0*video_time_usage/total_time_usage,
5101 100.0*vout_time_usage/total_time_usage,
5102 100.0*audio_time_usage/total_time_usage,
5103 100.0*(total_time_usage-tot)/total_time_usage,
5104 100.0);
5105 if(total_frame_cnt && frame_dropping)
5106 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5107 total_frame_cnt-drop_frame_cnt,
5108 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
5109 drop_frame_cnt,
5110 100*drop_frame_cnt/total_frame_cnt,
5111 total_frame_cnt,
5112 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
5116 // time to uninit all, except global stuff:
5117 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
5119 #ifdef USE_SUB
5120 if ( set_of_sub_size > 0 )
5122 current_module="sub_free";
5123 for (i = 0; i < set_of_sub_size; ++i) {
5124 sub_free( set_of_subtitles[i] );
5125 #ifdef USE_ASS
5126 if ( set_of_ass_tracks[i] )
5127 ass_free_track( set_of_ass_tracks[i] );
5128 #endif
5130 set_of_sub_size = 0;
5131 vo_sub_last = vo_sub=NULL;
5132 subdata=NULL;
5133 #ifdef USE_ASS
5134 ass_track = NULL;
5135 #endif
5137 #endif
5139 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
5140 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
5141 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
5142 eof = 1;
5143 } else {
5144 play_tree_iter_free(playtree_iter);
5145 playtree_iter = NULL;
5147 play_tree_step = 1;
5148 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
5149 eof = eof == PT_UP_NEXT ? 1 : -1;
5150 if ( playtree_iter ) {
5151 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
5152 eof = 1;
5153 } else {
5154 play_tree_iter_free(playtree_iter);
5155 playtree_iter = NULL;
5158 } else { // NEXT PREV SRC
5159 eof = eof == PT_PREV_SRC ? -1 : 1;
5162 if(eof == 0) eof = 1;
5164 while(playtree_iter != NULL) {
5165 filename = play_tree_iter_get_file(playtree_iter,eof);
5166 if(filename == NULL) {
5167 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
5168 play_tree_iter_free(playtree_iter);
5169 playtree_iter = NULL;
5171 } else
5172 break;
5175 #ifdef HAVE_NEW_GUI
5176 if( use_gui && !playtree_iter )
5178 #ifdef USE_DVDREAD
5179 if ( !guiIntfStruct.DiskChanged )
5180 #endif
5181 mplEnd();
5183 #endif
5185 if(use_gui || playtree_iter != NULL || player_idle_mode){
5186 if (!playtree_iter) filename = NULL;
5187 eof = 0;
5188 goto play_next_file;
5192 exit_player_with_rc(MSGTR_Exit_eof, 0);
5194 return 1;