Make compilation depending on USE_OSD unconditional.
[mplayer.git] / mplayer.c
blob13889605d43dd01b804e2c6ef586191ff01c2881
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 #include "subreader.h"
55 #include "libvo/video_out.h"
57 #include "libvo/font_load.h"
58 #include "libvo/sub.h"
60 #ifdef HAVE_X11
61 #include "libvo/x11_common.h"
62 #endif
64 #include "libao2/audio_out.h"
66 #include "codec-cfg.h"
68 #include "edl.h"
70 #include "spudec.h"
71 #include "vobsub.h"
73 #include "osdep/getch2.h"
74 #include "osdep/timer.h"
76 #include "cpudetect.h"
78 #ifdef HAVE_NEW_GUI
79 #include "Gui/interface.h"
80 #endif
82 #include "input/input.h"
84 int slave_mode=0;
85 int player_idle_mode=0;
86 int quiet=0;
87 int enable_mouse_movements=0;
89 #ifdef WIN32
90 char * proc_priority=NULL;
91 #endif
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
95 #ifdef HAVE_RTC
96 #ifdef __linux__
97 #include <linux/rtc.h>
98 #else
99 #include <rtc.h>
100 #define RTC_IRQP_SET RTCIO_IRQP_SET
101 #define RTC_PIE_ON RTCIO_PIE_ON
102 #endif /* __linux__ */
103 #endif /* HAVE_RTC */
105 #ifdef USE_TV
106 #include "stream/tv.h"
107 #endif
108 #ifdef USE_RADIO
109 #include "stream/stream_radio.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 #include "stream/cache2.h"
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 #include "parser-cfg.h"
145 #include "parser-mpcmd.h"
147 m_config_t* mconfig;
149 //**************************************************************************//
150 // Config file
151 //**************************************************************************//
153 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
155 static int cfg_include(m_option_t *conf, char *filename){
156 return m_config_parse_config_file(mconfig, filename);
159 #include "get_path.c"
161 //**************************************************************************//
162 // XScreensaver
163 //**************************************************************************//
165 #ifdef HAVE_X11
166 void xscreensaver_heartbeat(void);
167 #endif
169 //**************************************************************************//
170 //**************************************************************************//
171 // Input media streaming & demultiplexer:
172 //**************************************************************************//
174 static int max_framesize=0;
176 #include "stream/stream.h"
177 #include "libmpdemux/demuxer.h"
178 #include "libmpdemux/stheader.h"
179 //#include "parse_es.h"
180 #include "libmpdemux/matroska.h"
182 #ifdef USE_DVDREAD
183 #include "stream/stream_dvd.h"
184 #endif
186 #include "libmpcodecs/dec_audio.h"
187 #include "libmpcodecs/dec_video.h"
188 #include "libmpcodecs/mp_image.h"
189 #include "libmpcodecs/vf.h"
190 #include "libmpcodecs/vd.h"
192 //**************************************************************************//
194 static void reinit_audio_chain(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 static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 };
256 // A/V sync:
257 int autosync=0; // 30 might be a good default value.
259 // may be changed by GUI: (FIXME!)
260 float rel_seek_secs=0;
261 int abs_seek_pos=0;
263 // codecs:
264 char **audio_codec_list=NULL; // override audio codec
265 char **video_codec_list=NULL; // override video codec
266 char **audio_fm_list=NULL; // override audio codec family
267 char **video_fm_list=NULL; // override video codec family
269 // demuxer:
270 extern char *demuxer_name; // override demuxer
271 extern char *audio_demuxer_name; // override audio demuxer
272 extern char *sub_demuxer_name; // override sub demuxer
274 // streaming:
275 int audio_id=-1;
276 int video_id=-1;
277 int dvdsub_id=-2;
278 int vobsub_id=-1;
279 char* audio_lang=NULL;
280 char* dvdsub_lang=NULL;
281 static char* spudec_ifo=NULL;
282 char* filename=NULL; //"MI2-Trailer.avi";
283 int forced_subs_only=0;
284 int file_filter=1;
286 // cache2:
287 int stream_cache_size=-1;
288 #ifdef USE_STREAM_CACHE
289 extern int cache_fill_status;
291 float stream_cache_min_percent=20.0;
292 float stream_cache_seek_min_percent=50.0;
293 #else
294 #define cache_fill_status 0
295 #endif
297 // dump:
298 static char *stream_dump_name="stream.dump";
299 int stream_dump_type=0;
301 // A-V sync:
302 static float default_max_pts_correction=-1;//0.01f;
303 static float max_pts_correction=0;//default_max_pts_correction;
304 static float c_total=0;
305 float audio_delay=0;
306 static int ignore_start=0;
308 static int softsleep=0;
310 float force_fps=0;
311 static int force_srate=0;
312 static int audio_output_format=-1; // AF_FORMAT_UNKNOWN
313 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
314 static int play_n_frames=-1;
315 static int play_n_frames_mf=-1;
317 // screen info:
318 char** video_driver_list=NULL;
319 char** audio_driver_list=NULL;
321 extern char *vo_subdevice;
322 extern char *ao_subdevice;
324 // codec outfmt flags (defined in libmpcodecs/vd.c)
325 extern int vo_flags;
327 // sub:
328 char *font_name=NULL;
329 #ifdef HAVE_FONTCONFIG
330 extern int font_fontconfig;
331 #endif
332 float font_factor=0.75;
333 char **sub_name=NULL;
334 float sub_delay=0;
335 float sub_fps=0;
336 int sub_auto = 1;
337 char *vobsub_name=NULL;
338 /*DSP!!char *dsp=NULL;*/
339 int subcc_enabled=0;
340 int suboverlap_enabled = 1;
342 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
343 int set_of_sub_size = 0;
344 int set_of_sub_pos = -1;
345 double sub_last_pts = -303;
347 int global_sub_size = 0; // this encompasses all subtitle sources
348 int global_sub_pos = -1; // this encompasses all subtitle sources
349 #define SUB_SOURCE_SUBS 0
350 #define SUB_SOURCE_VOBSUB 1
351 #define SUB_SOURCE_DEMUX 2
352 #define SUB_SOURCES 3
353 int global_sub_indices[SUB_SOURCES];
355 #ifdef USE_ASS
356 #include "libass/ass.h"
357 #include "libass/ass_mp.h"
359 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
360 // or NULL if format unsupported
361 ass_track_t* set_of_ass_tracks[MAX_SUBTITLE_FILES];
362 ass_track_t* ass_track = 0; // current track to render
363 #endif
365 extern int mp_msg_levels[MSGT_MAX];
366 extern int mp_msg_level_all;
368 static stream_t* stream=NULL;
369 static demuxer_t *demuxer=NULL;
370 static sh_audio_t *sh_audio=NULL;
371 static sh_video_t *sh_video=NULL;
372 static demux_stream_t *d_audio=NULL;
373 static demux_stream_t *d_video=NULL;
374 static demux_stream_t *d_dvdsub=NULL;
376 char* current_module=NULL; // for debugging
378 extern int vo_gamma_gamma;
379 extern int vo_gamma_brightness;
380 extern int vo_gamma_contrast;
381 extern int vo_gamma_saturation;
382 extern int vo_gamma_hue;
384 // ---
386 #ifdef HAVE_MENU
387 #include "m_struct.h"
388 #include "libmenu/menu.h"
389 extern void vf_menu_pause_update(struct vf_instance_s* vf);
390 extern vf_info_t vf_info_menu;
391 static vf_info_t* libmenu_vfs[] = {
392 &vf_info_menu,
393 NULL
395 static vf_instance_t* vf_menu = NULL;
396 static int use_menu = 0;
397 static char* menu_cfg = NULL;
398 static char* menu_root = "main";
399 #endif
402 #ifdef HAVE_RTC
403 static int nortc = 1;
404 static char* rtc_device;
405 #endif
407 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
408 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
409 short user_muted = 0; ///< Stores whether user wanted muted mode.
410 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
411 short edl_decision = 0; ///< 1 when an EDL operation has been made.
412 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode.
413 float begin_skip = MP_NOPTS_VALUE; ///< start time of the current skip while on edlout mode
414 int use_filedir_conf;
416 static unsigned int inited_flags=0;
417 #define INITED_VO 1
418 #define INITED_AO 2
419 #define INITED_GUI 4
420 #define INITED_GETCH2 8
421 #define INITED_SPUDEC 32
422 #define INITED_STREAM 64
423 #define INITED_INPUT 128
424 #define INITED_VOBSUB 256
425 #define INITED_DEMUXER 512
426 #define INITED_ACODEC 1024
427 #define INITED_VCODEC 2048
428 #define INITED_ALL 0xFFFF
430 #include "metadata.h"
432 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
434 static int is_valid_metadata_type (metadata_t type) {
435 switch (type)
437 /* check for valid video stream */
438 case META_VIDEO_CODEC:
439 case META_VIDEO_BITRATE:
440 case META_VIDEO_RESOLUTION:
442 if (!sh_video)
443 return 0;
444 break;
447 /* check for valid audio stream */
448 case META_AUDIO_CODEC:
449 case META_AUDIO_BITRATE:
450 case META_AUDIO_SAMPLES:
452 if (!sh_audio)
453 return 0;
454 break;
457 /* check for valid demuxer */
458 case META_INFO_TITLE:
459 case META_INFO_ARTIST:
460 case META_INFO_ALBUM:
461 case META_INFO_YEAR:
462 case META_INFO_COMMENT:
463 case META_INFO_TRACK:
464 case META_INFO_GENRE:
466 if (!demuxer)
467 return 0;
468 break;
471 default:
472 break;
475 return 1;
478 static char *get_demuxer_info (char *tag) {
479 char **info = demuxer->info;
480 int n;
482 if (!info || !tag)
483 return NULL;
485 for (n = 0; info[2*n] != NULL ; n++)
486 if (!strcmp (info[2*n], tag))
487 break;
489 return info[2*n+1] ? strdup (info[2*n+1]) : NULL;
492 char *get_metadata (metadata_t type) {
493 char *meta = NULL;
495 if (!is_valid_metadata_type (type))
496 return NULL;
498 switch (type)
500 case META_NAME:
502 return strdup (mp_basename2 (filename));
505 case META_VIDEO_CODEC:
507 if (sh_video->format == 0x10000001)
508 meta = strdup ("mpeg1");
509 else if (sh_video->format == 0x10000002)
510 meta = strdup ("mpeg2");
511 else if (sh_video->format == 0x10000004)
512 meta = strdup ("mpeg4");
513 else if (sh_video->format == 0x10000005)
514 meta = strdup ("h264");
515 else if (sh_video->format >= 0x20202020)
517 meta = (char *) malloc (8);
518 sprintf (meta, "%.4s", (char *) &sh_video->format);
520 else
522 meta = (char *) malloc (8);
523 sprintf (meta, "0x%08X", sh_video->format);
525 return meta;
528 case META_VIDEO_BITRATE:
530 meta = (char *) malloc (16);
531 sprintf (meta, "%d kbps", (int) (sh_video->i_bps * 8 / 1024));
532 return meta;
535 case META_VIDEO_RESOLUTION:
537 meta = (char *) malloc (16);
538 sprintf (meta, "%d x %d", sh_video->disp_w, sh_video->disp_h);
539 return meta;
542 case META_AUDIO_CODEC:
544 if (sh_audio->codec && sh_audio->codec->name)
545 meta = strdup (sh_audio->codec->name);
546 return meta;
549 case META_AUDIO_BITRATE:
551 meta = (char *) malloc (16);
552 sprintf (meta, "%d kbps", (int) (sh_audio->i_bps * 8/1000));
553 return meta;
556 case META_AUDIO_SAMPLES:
558 meta = (char *) malloc (16);
559 sprintf (meta, "%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels);
560 return meta;
563 /* check for valid demuxer */
564 case META_INFO_TITLE:
565 return get_demuxer_info ("Title");
567 case META_INFO_ARTIST:
568 return get_demuxer_info ("Artist");
570 case META_INFO_ALBUM:
571 return get_demuxer_info ("Album");
573 case META_INFO_YEAR:
574 return get_demuxer_info ("Year");
576 case META_INFO_COMMENT:
577 return get_demuxer_info ("Comment");
579 case META_INFO_TRACK:
580 return get_demuxer_info ("Track");
582 case META_INFO_GENRE:
583 return get_demuxer_info ("Genre");
585 default:
586 break;
589 return meta;
592 static void uninit_player(unsigned int mask){
593 mask=inited_flags&mask;
595 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
597 if(mask&INITED_ACODEC){
598 inited_flags&=~INITED_ACODEC;
599 current_module="uninit_acodec";
600 if(sh_audio) uninit_audio(sh_audio);
601 #ifdef HAVE_NEW_GUI
602 guiGetEvent(guiSetAfilter, (char *)NULL);
603 #endif
604 sh_audio=NULL;
607 if(mask&INITED_VCODEC){
608 inited_flags&=~INITED_VCODEC;
609 current_module="uninit_vcodec";
610 if(sh_video) uninit_video(sh_video);
611 sh_video=NULL;
612 #ifdef HAVE_MENU
613 vf_menu=NULL;
614 #endif
617 if(mask&INITED_DEMUXER){
618 inited_flags&=~INITED_DEMUXER;
619 current_module="free_demuxer";
620 if(demuxer){
621 stream=demuxer->stream;
622 free_demuxer(demuxer);
624 demuxer=NULL;
627 // kill the cache process:
628 if(mask&INITED_STREAM){
629 inited_flags&=~INITED_STREAM;
630 current_module="uninit_stream";
631 if(stream) free_stream(stream);
632 stream=NULL;
635 if(mask&INITED_VO){
636 inited_flags&=~INITED_VO;
637 current_module="uninit_vo";
638 video_out->uninit();
639 video_out=NULL;
642 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
643 if(mask&INITED_GETCH2){
644 inited_flags&=~INITED_GETCH2;
645 current_module="uninit_getch2";
646 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
647 // restore terminal:
648 getch2_disable();
651 if(mask&INITED_VOBSUB){
652 inited_flags&=~INITED_VOBSUB;
653 current_module="uninit_vobsub";
654 if(vo_vobsub) vobsub_close(vo_vobsub);
655 vo_vobsub=NULL;
658 if (mask&INITED_SPUDEC){
659 inited_flags&=~INITED_SPUDEC;
660 current_module="uninit_spudec";
661 spudec_free(vo_spudec);
662 vo_spudec=NULL;
665 if(mask&INITED_AO){
666 inited_flags&=~INITED_AO;
667 current_module="uninit_ao";
668 audio_out->uninit(eof?0:1); audio_out=NULL;
671 #ifdef HAVE_NEW_GUI
672 if(mask&INITED_GUI){
673 inited_flags&=~INITED_GUI;
674 current_module="uninit_gui";
675 guiDone();
677 #endif
679 if(mask&INITED_INPUT){
680 inited_flags&=~INITED_INPUT;
681 current_module="uninit_input";
682 mp_input_uninit();
685 current_module=NULL;
688 static void exit_player_with_rc(const char* how, int rc){
690 uninit_player(INITED_ALL);
691 #ifdef HAVE_X11
692 #ifdef HAVE_NEW_GUI
693 if ( !use_gui )
694 #endif
695 vo_uninit(); // Close the X11 connection (if any is open).
696 #endif
698 #ifdef HAVE_FREETYPE
699 current_module="uninit_font";
700 if (vo_font) free_font_desc(vo_font);
701 vo_font = NULL;
702 done_freetype();
703 #endif
704 free_osd_list();
706 #ifdef USE_ASS
707 ass_library_done(ass_library);
708 #endif
710 current_module="exit_player";
712 // free mplayer config
713 if(mconfig)
714 m_config_free(mconfig);
716 if(playtree)
717 play_tree_free(playtree, 1);
720 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
721 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,how);
722 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
724 exit(rc);
727 void exit_player(const char* how){
728 exit_player_with_rc(how, 1);
731 #ifndef __MINGW32__
732 static void child_sighandler(int x){
733 pid_t pid;
734 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
736 #endif
738 #ifdef CRASH_DEBUG
739 static char *prog_path;
740 static int crash_debug = 0;
741 #endif
743 static void exit_sighandler(int x){
744 static int sig_count=0;
745 #ifdef CRASH_DEBUG
746 if (!crash_debug || x != SIGTRAP)
747 #endif
748 ++sig_count;
749 if(inited_flags==0 && sig_count>1) exit(1);
750 if(sig_count==5)
752 /* We're crashing bad and can't uninit cleanly :(
753 * by popular request, we make one last (dirty)
754 * effort to restore the user's
755 * terminal. */
756 getch2_disable();
757 exit(1);
759 if(sig_count==6) exit(1);
760 if(sig_count>6){
761 // can't stop :(
762 #ifndef __MINGW32__
763 kill(getpid(),SIGKILL);
764 #endif
766 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
767 current_module?current_module:"unknown"
769 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x);
770 if(sig_count<=1)
771 switch(x){
772 case SIGINT:
773 case SIGQUIT:
774 case SIGTERM:
775 case SIGKILL:
776 break; // killed from keyboard (^C) or killed [-9]
777 case SIGILL:
778 #ifdef RUNTIME_CPUDETECT
779 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
780 #else
781 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
782 #endif
783 case SIGFPE:
784 case SIGSEGV:
785 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
786 default:
787 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
788 #ifdef CRASH_DEBUG
789 if (crash_debug) {
790 int gdb_pid;
791 char spid[20];
792 snprintf(spid, 19, "%i", getpid());
793 spid[19] = 0;
794 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
795 gdb_pid = fork();
796 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
797 if (gdb_pid == 0) { // We are the child
798 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
799 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
800 } else if (gdb_pid < 0)
801 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
802 else {
803 waitpid(gdb_pid, NULL, 0);
805 if (x == SIGTRAP) return;
807 #endif
809 exit_player(NULL);
812 extern void mp_input_register_options(m_config_t* cfg);
814 #include "mixer.h"
815 mixer_t mixer;
816 /// step size of mixer changes
817 int volstep = 3;
819 #include "cfg-mplayer.h"
821 static void parse_cfgfiles( m_config_t* conf )
823 char *conffile;
824 int conffile_fd;
825 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
826 exit_player(NULL);
827 if ((conffile = get_path("")) == NULL) {
828 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
829 } else {
830 #ifdef __MINGW32__
831 mkdir(conffile);
832 #else
833 mkdir(conffile, 0777);
834 #endif
835 free(conffile);
836 if ((conffile = get_path("config")) == NULL) {
837 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
838 } else {
839 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
840 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
841 write(conffile_fd, default_config, strlen(default_config));
842 close(conffile_fd);
844 if (m_config_parse_config_file(conf, conffile) < 0)
845 exit_player(NULL);
846 free(conffile);
851 void load_per_file_config (m_config_t* conf, const char *const file)
853 char *confpath;
854 char cfg[strlen(file)+10];
855 struct stat st;
856 char *name;
858 sprintf (cfg, "%s.conf", file);
860 if (use_filedir_conf && !stat (cfg, &st))
862 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
863 m_config_parse_config_file (conf, cfg);
864 return;
867 if ((name = strrchr (cfg, '/')) == NULL)
868 name = cfg;
869 else
870 name++;
872 if ((confpath = get_path (name)) != NULL)
874 if (!stat (confpath, &st))
876 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
877 m_config_parse_config_file (conf, confpath);
880 free (confpath);
884 /* When libmpdemux performs a blocking operation (network connection or
885 * cache filling) if the operation fails we use this function to check
886 * if it was interrupted by the user.
887 * The function returns a new value for eof. */
888 static int libmpdemux_was_interrupted(int eof) {
889 mp_cmd_t* cmd;
890 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
891 switch(cmd->id) {
892 case MP_CMD_QUIT:
893 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
894 case MP_CMD_PLAY_TREE_STEP: {
895 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
896 play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i;
897 } break;
898 case MP_CMD_PLAY_TREE_UP_STEP: {
899 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
900 } break;
901 case MP_CMD_PLAY_ALT_SRC_STEP: {
902 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
903 } break;
905 mp_cmd_free(cmd);
907 return eof;
910 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
912 int playtree_add_playlist(play_tree_t* entry)
914 play_tree_add_bpf(entry,filename);
916 #ifdef HAVE_NEW_GUI
917 if (use_gui) {
918 if (entry) {
919 import_playtree_playlist_into_gui(entry, mconfig);
920 play_tree_free_list(entry,1);
922 } else
923 #endif
925 if(!entry) {
926 entry = playtree_iter->tree;
927 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
928 return PT_NEXT_ENTRY;
930 if(playtree_iter->tree == entry ) { // Loop with a single file
931 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
932 return PT_NEXT_ENTRY;
935 play_tree_remove(entry,1,1);
936 return PT_NEXT_SRC;
938 play_tree_insert_entry(playtree_iter->tree,entry);
939 play_tree_set_params_from(entry,playtree_iter->tree);
940 entry = playtree_iter->tree;
941 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
942 return PT_NEXT_ENTRY;
944 play_tree_remove(entry,1,1);
946 return PT_NEXT_SRC;
949 int sub_source(void)
951 int source = -1;
952 int top = -1;
953 int i;
954 for (i = 0; i < SUB_SOURCES; i++) {
955 int j = global_sub_indices[i];
956 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
957 source = i;
958 top = j;
961 return source;
964 sub_data* subdata = NULL;
965 static subtitle* vo_sub_last = NULL;
967 void add_subtitles(char *filename, float fps, int silent)
969 sub_data *subd;
970 #ifdef USE_ASS
971 ass_track_t *asst = 0;
972 #endif
974 if (filename == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) {
975 return;
978 subd = sub_read_file(filename, fps);
979 #ifdef USE_ASS
980 if (ass_enabled)
981 #ifdef USE_ICONV
982 asst = ass_read_file(ass_library, filename, sub_cp);
983 #else
984 asst = ass_read_file(ass_library, filename, 0);
985 #endif
986 if (ass_enabled && subd && !asst)
987 asst = ass_read_subdata(ass_library, subd, fps);
989 if (!asst && !subd && !silent)
990 #else
991 if(!subd && !silent)
992 #endif
993 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
995 #ifdef USE_ASS
996 if (!asst && !subd) return;
997 set_of_ass_tracks[set_of_sub_size] = asst;
998 #else
999 if (!subd) return;
1000 #endif
1001 set_of_subtitles[set_of_sub_size] = subd;
1002 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
1003 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
1004 ++set_of_sub_size;
1005 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
1008 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1009 void update_set_of_subtitles(void)
1010 // subdata was changed, set_of_sub... have to be updated.
1012 int i;
1013 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
1014 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
1015 set_of_subtitles[i-1] = set_of_subtitles[i];
1016 set_of_subtitles[set_of_sub_size-1] = NULL;
1017 --set_of_sub_size;
1018 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
1020 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
1021 set_of_subtitles[set_of_sub_pos] = subdata;
1023 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
1024 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
1025 ++set_of_sub_size;
1029 void init_vo_spudec(void) {
1030 if (vo_spudec)
1031 spudec_free(vo_spudec);
1032 inited_flags &= ~INITED_SPUDEC;
1033 vo_spudec = NULL;
1034 if (spudec_ifo) {
1035 unsigned int palette[16], width, height;
1036 current_module="spudec_init_vobsub";
1037 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1038 vo_spudec=spudec_new_scaled(palette, width, height);
1041 #ifdef USE_DVDREAD
1042 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1043 current_module="spudec_init_dvdread";
1044 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1045 sh_video->disp_w, sh_video->disp_h);
1047 #endif
1049 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1050 (d_dvdsub->sh != NULL) && (((sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1051 sh_sub_t *mkv_sh_sub = (sh_sub_t *)d_dvdsub->sh;
1052 current_module = "spudec_init_matroska";
1053 vo_spudec =
1054 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1055 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1056 mkv_sh_sub->height);
1057 forced_subs_only = mkv_sh_sub->forced_subs_only;
1060 if (vo_spudec==NULL) {
1061 sh_sub_t *sh = (sh_sub_t *)d_dvdsub->sh;
1062 unsigned int *palette = NULL;
1063 if (sh && sh->has_palette)
1064 palette = sh->palette;
1065 current_module="spudec_init_normal";
1066 vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h);
1067 spudec_set_font_factor(vo_spudec,font_factor);
1070 if (vo_spudec!=NULL)
1071 inited_flags|=INITED_SPUDEC;
1075 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1076 * make it all work is to use the builtin SDL-bootstrap code, which
1077 * will be done automatically by replacing our main() if we include SDL.h.
1079 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1080 #include <SDL.h>
1081 #endif
1084 * \brief append a formatted string
1085 * \param buf buffer to print into
1086 * \param pos position of terminating 0 in buf
1087 * \param len maximum number of characters in buf, not including terminating 0
1088 * \param format printf format string
1090 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
1092 va_list va;
1093 va_start(va, format);
1094 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
1095 va_end(va);
1096 if (*pos >= len ) {
1097 buf[len] = 0;
1098 *pos = len;
1103 * \brief append time in the hh:mm:ss.f format
1104 * \param buf buffer to print into
1105 * \param pos position of terminating 0 in buf
1106 * \param len maximum number of characters in buf, not including terminating 0
1107 * \param time time value to convert/append
1109 static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) {
1110 long tenths = 10 * time;
1111 int f1 = tenths % 10;
1112 int ss = (tenths / 10) % 60;
1113 int mm = (tenths / 600) % 60;
1114 int hh = tenths / 36000;
1115 if (time <= 0) {
1116 saddf(buf, pos, len, "unknown");
1117 return;
1119 if (hh > 0)
1120 saddf(buf, pos, len, "%2d:", hh);
1121 if (hh > 0 || mm > 0)
1122 saddf(buf, pos, len, "%02d:", mm);
1123 saddf(buf, pos, len, "%02d.%1d", ss, f1);
1127 * \brief print the status line
1128 * \param a_pos audio position
1129 * \param a_v A-V desynchronization
1130 * \param corr amount out A-V synchronization
1132 static void print_status(float a_pos, float a_v, float corr)
1134 int width;
1135 char *line;
1136 unsigned pos = 0;
1137 get_screen_size();
1138 if (screen_width > 0)
1139 width = screen_width;
1140 else
1141 width = 80;
1142 #ifdef WIN32
1143 /* Windows command line is broken (MinGW's rxvt works, but we
1144 * should not depend on that). */
1145 width--;
1146 #endif
1147 line = malloc(width + 1); // one additional char for the terminating null
1149 // Audio time
1150 if (sh_audio) {
1151 saddf(line, &pos, width, "A:%6.1f ", a_pos);
1152 if (!sh_video) {
1153 float len = demuxer_get_time_length(demuxer);
1154 saddf(line, &pos, width, "(");
1155 sadd_hhmmssf(line, &pos, width, a_pos);
1156 saddf(line, &pos, width, ") of %.1f (", len);
1157 sadd_hhmmssf(line, &pos, width, len);
1158 saddf(line, &pos, width, ") ");
1162 // Video time
1163 if (sh_video)
1164 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
1166 // A-V sync
1167 if (sh_audio && sh_video)
1168 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
1170 // Video stats
1171 if (sh_video)
1172 saddf(line, &pos, width, "%3d/%3d ",
1173 (int)sh_video->num_frames,
1174 (int)sh_video->num_frames_decoded);
1176 // CPU usage
1177 if (sh_video) {
1178 if (sh_video->timer > 0.5)
1179 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
1180 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
1181 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
1182 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
1183 else
1184 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
1185 } else if (sh_audio) {
1186 if (sh_audio->delay > 0.5)
1187 saddf(line, &pos, width, "%4.1f%% ",
1188 100.0*audio_time_usage/(double)sh_audio->delay);
1189 else
1190 saddf(line, &pos, width, "??,?%% ");
1193 // VO stats
1194 if (sh_video)
1195 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
1197 #ifdef USE_STREAM_CACHE
1198 // cache stats
1199 if (stream_cache_size > 0)
1200 saddf(line, &pos, width, "%d%% ", cache_fill_status);
1201 #endif
1203 // other
1204 if (playback_speed != 1)
1205 saddf(line, &pos, width, "%4.2fx ", playback_speed);
1207 // end
1208 if (erase_to_end_of_line) {
1209 line[pos] = 0;
1210 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s%s\r", line, erase_to_end_of_line);
1211 } else {
1212 memset(&line[pos], ' ', width - pos);
1213 line[width] = 0;
1214 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
1216 free(line);
1220 * \brief build a chain of audio filters that converts the input format
1221 * to the ao's format, taking into account the current playback_speed.
1222 * \param sh_audio describes the requested input format of the chain.
1223 * \param ao_data describes the requested output format of the chain.
1225 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
1227 int new_srate;
1228 int result;
1229 if (!sh_audio)
1231 #ifdef HAVE_NEW_GUI
1232 guiGetEvent(guiSetAfilter, (char *)NULL);
1233 #endif
1234 mixer.afilter = NULL;
1235 return 0;
1237 new_srate = sh_audio->samplerate * playback_speed;
1238 if (new_srate != ao_data->samplerate) {
1239 // limits are taken from libaf/af_resample.c
1240 if (new_srate < 8000)
1241 new_srate = 8000;
1242 if (new_srate > 192000)
1243 new_srate = 192000;
1244 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
1246 result = init_audio_filters(sh_audio, new_srate,
1247 sh_audio->channels, sh_audio->sample_format,
1248 &ao_data->samplerate, &ao_data->channels, &ao_data->format,
1249 ao_data->outburst * 4, ao_data->buffersize);
1250 mixer.afilter = sh_audio->afilter;
1251 #ifdef HAVE_NEW_GUI
1252 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter);
1253 #endif
1254 return result;
1258 * \brief Log the currently displayed subtitle to a file
1260 * Logs the current or last displayed subtitle together with filename
1261 * and time information to ~/.mplayer/subtitle_log
1263 * Intended purpose is to allow convenient marking of bogus subtitles
1264 * which need to be fixed while watching the movie.
1267 static void log_sub(void){
1268 char *fname;
1269 FILE *f;
1270 int i;
1272 if (subdata == NULL || vo_sub_last == NULL) return;
1273 fname = get_path("subtitle_log");
1274 f = fopen(fname, "a");
1275 if (!f) return;
1276 fprintf(f, "----------------------------------------------------------\n");
1277 if (subdata->sub_uses_time) {
1278 fprintf(f, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename,
1279 vo_sub_last->start/360000, (vo_sub_last->start/6000)%60,
1280 (vo_sub_last->start/100)%60, vo_sub_last->start%100,
1281 vo_sub_last->end/360000, (vo_sub_last->end/6000)%60,
1282 (vo_sub_last->end/100)%60, vo_sub_last->end%100);
1283 } else {
1284 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start, vo_sub_last->end);
1286 for (i = 0; i < vo_sub_last->lines; i++) {
1287 fprintf(f, "%s\n", vo_sub_last->text[i]);
1289 fclose(f);
1292 /// \defgroup OSDMsgStack OSD message stack
1294 ///@{
1296 #define OSD_MSG_TV_CHANNEL 0
1297 #define OSD_MSG_TEXT 1
1298 #define OSD_MSG_SUB_DELAY 2
1299 #define OSD_MSG_SPEED 3
1300 #define OSD_MSG_OSD_STATUS 4
1301 #define OSD_MSG_BAR 5
1302 #define OSD_MSG_PAUSE 6
1303 #define OSD_MSG_RADIO_CHANNEL 7
1304 /// Base id for messages generated from the commmand to property bridge.
1305 #define OSD_MSG_PROPERTY 0x100
1308 typedef struct mp_osd_msg mp_osd_msg_t;
1309 struct mp_osd_msg {
1310 /// Previous message on the stack.
1311 mp_osd_msg_t* prev;
1312 /// Message text.
1313 char msg[64];
1314 int id,level,started;
1315 /// Display duration in ms.
1316 unsigned time;
1319 /// OSD message stack.
1320 static mp_osd_msg_t* osd_msg_stack = NULL;
1323 * \brief Add a message on the OSD message stack
1325 * If a message with the same id is already present in the stack
1326 * it is pulled on top of the stack, otherwise a new message is created.
1330 static void set_osd_msg(int id, int level, int time, const char* fmt, ...) {
1331 mp_osd_msg_t *msg,*last=NULL;
1332 va_list va;
1333 int r;
1335 // look if the id is already in the stack
1336 for(msg = osd_msg_stack ; msg && msg->id != id ;
1337 last = msg, msg = msg->prev);
1338 // not found: alloc it
1339 if(!msg) {
1340 msg = calloc(1,sizeof(mp_osd_msg_t));
1341 msg->prev = osd_msg_stack;
1342 osd_msg_stack = msg;
1343 } else if(last) { // found, but it's not on top of the stack
1344 last->prev = msg->prev;
1345 msg->prev = osd_msg_stack;
1346 osd_msg_stack = msg;
1348 // write the msg
1349 va_start(va,fmt);
1350 r = vsnprintf(msg->msg, 64, fmt, va);
1351 va_end(va);
1352 if(r >= 64) msg->msg[63] = 0;
1353 // set id and time
1354 msg->id = id;
1355 msg->level = level;
1356 msg->time = time;
1361 * \brief Remove a message from the OSD stack
1363 * This function can be used to get rid of a message right away.
1367 static void rm_osd_msg(int id) {
1368 mp_osd_msg_t *msg,*last=NULL;
1370 // Search for the msg
1371 for(msg = osd_msg_stack ; msg && msg->id != id ;
1372 last = msg, msg = msg->prev);
1373 if(!msg) return;
1375 // Detach it from the stack and free it
1376 if(last)
1377 last->prev = msg->prev;
1378 else
1379 osd_msg_stack = msg->prev;
1380 free(msg);
1384 * \brief Remove all messages from the OSD stack
1388 static void clear_osd_msgs(void) {
1389 mp_osd_msg_t* msg = osd_msg_stack, *prev = NULL;
1390 while(msg) {
1391 prev = msg->prev;
1392 free(msg);
1393 msg = prev;
1395 osd_msg_stack = NULL;
1399 * \brief Get the current message from the OSD stack.
1401 * This function decrements the message timer and destroys the old ones.
1402 * The message that should be displayed is returned (if any).
1406 static mp_osd_msg_t* get_osd_msg(void) {
1407 mp_osd_msg_t *msg,*prev,*last = NULL;
1408 static unsigned last_update = 0;
1409 unsigned now = GetTimerMS();
1410 unsigned diff;
1411 char hidden_dec_done = 0;
1413 if(!last_update) last_update = now;
1414 diff = now >= last_update ? now - last_update : 0;
1416 last_update = now;
1418 // Look for the first message in the stack with high enough level.
1419 for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) {
1420 prev = msg->prev;
1421 if(msg->level > osd_level && hidden_dec_done) continue;
1422 // The message has a high enough level or it is the first hidden one
1423 // in both cases we decrement the timer or kill it.
1424 if(!msg->started || msg->time > diff) {
1425 if(msg->started) msg->time -= diff;
1426 else msg->started = 1;
1427 // display it
1428 if(msg->level <= osd_level) return msg;
1429 hidden_dec_done = 1;
1430 continue;
1432 // kill the message
1433 free(msg);
1434 if(last) {
1435 last->prev = prev;
1436 msg = last;
1437 } else {
1438 osd_msg_stack = prev;
1439 msg = NULL;
1442 // Nothing found
1443 return NULL;
1447 * \brief Display the OSD bar.
1449 * Display the OSD bar or fall back on a simple message.
1453 static void set_osd_bar(int type,const char* name,double min,double max,double val) {
1455 if(osd_level < 1) return;
1457 if(sh_video) {
1458 osd_visible = (GetTimerMS() + 1000) | 1;
1459 vo_osd_progbar_type = type;
1460 vo_osd_progbar_value = 256*(val-min)/(max-min);
1461 vo_osd_changed(OSDTYPE_PROGBAR);
1462 return;
1465 set_osd_msg(OSD_MSG_BAR,1,osd_duration,"%s: %d %%",
1466 name,ROUND(100*(val-min)/(max-min)));
1471 * \brief Update the OSD message line.
1473 * This function displays the current message on the vo OSD or on the term.
1474 * If the stack is empty and the OSD level is high enough the timer
1475 * is displayed (only on the vo OSD).
1479 static void update_osd_msg(void) {
1480 mp_osd_msg_t *msg;
1481 static char osd_text[64] = "";
1482 static char osd_text_timer[64];
1484 // we need some mem for vo_osd_text
1485 vo_osd_text = (unsigned char*)osd_text;
1487 // Look if we have a msg
1488 if((msg = get_osd_msg())) {
1489 if(strcmp(osd_text,msg->msg)) {
1490 strncpy((char*)osd_text, msg->msg, 63);
1491 if(sh_video) vo_osd_changed(OSDTYPE_OSD); else
1492 if(term_osd) mp_msg(MSGT_CPLAYER,MSGL_STATUS,"%s%s\n",term_osd_esc,msg->msg);
1494 return;
1497 if(sh_video) {
1498 // fallback on the timer
1499 if(osd_level>=2) {
1500 int len = demuxer_get_time_length(demuxer);
1501 int percentage = -1;
1502 char percentage_text[10];
1503 int pts = demuxer_get_current_time(demuxer);
1505 if (osd_show_percentage)
1506 percentage = demuxer_get_percent_pos(demuxer);
1508 if (percentage >= 0)
1509 snprintf(percentage_text, 9, " (%d%%)", percentage);
1510 else
1511 percentage_text[0] = 0;
1513 if (osd_level == 3)
1514 snprintf(osd_text_timer, 63,
1515 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1516 osd_function,pts/3600,(pts/60)%60,pts%60,
1517 len/3600,(len/60)%60,len%60,percentage_text);
1518 else
1519 snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s",
1520 osd_function,pts/3600,(pts/60)%60,
1521 pts%60,percentage_text);
1522 } else
1523 osd_text_timer[0]=0;
1525 // always decrement the percentage timer
1526 if(osd_show_percentage)
1527 osd_show_percentage--;
1529 if(strcmp(osd_text,osd_text_timer)) {
1530 strncpy(osd_text, osd_text_timer, 63);
1531 vo_osd_changed(OSDTYPE_OSD);
1533 return;
1536 // Clear the term osd line
1537 if(term_osd && osd_text[0]) {
1538 osd_text[0] = 0;
1539 printf("%s\n",term_osd_esc);
1543 ///@}
1544 // OSDMsgStack
1546 /// \defgroup Properties
1547 ///@{
1549 /// \defgroup GeneralProperties General properties
1550 /// \ingroup Properties
1551 ///@{
1553 /// OSD level (RW)
1554 static int mp_property_osdlevel(m_option_t* prop,int action,void* arg) {
1555 return m_property_choice(prop,action,arg,&osd_level);
1558 /// Playback speed (RW)
1559 static int mp_property_playback_speed(m_option_t* prop,int action,void* arg) {
1560 switch(action) {
1561 case M_PROPERTY_SET:
1562 if(!arg) return M_PROPERTY_ERROR;
1563 M_PROPERTY_CLAMP(prop,*(float*)arg);
1564 playback_speed = *(float*)arg;
1565 build_afilter_chain(sh_audio, &ao_data);
1566 return M_PROPERTY_OK;
1567 case M_PROPERTY_STEP_UP:
1568 case M_PROPERTY_STEP_DOWN:
1569 playback_speed += (arg ? *(float*)arg : 0.1) *
1570 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1571 M_PROPERTY_CLAMP(prop,playback_speed);
1572 build_afilter_chain(sh_audio, &ao_data);
1573 return M_PROPERTY_OK;
1575 return m_property_float_range(prop,action,arg,&playback_speed);
1578 /// filename with path (RO)
1579 static int mp_property_path(m_option_t* prop,int action,void* arg) {
1580 return m_property_string_ro(prop,action,arg,filename);
1583 /// filename without path (RO)
1584 static int mp_property_filename(m_option_t* prop,int action,void* arg) {
1585 char* f;
1586 if(!filename) return M_PROPERTY_UNAVAILABLE;
1587 if(((f = strrchr(filename,'/')) || (f = strrchr(filename,'\\'))) && f[1])
1588 f++;
1589 else
1590 f = filename;
1591 return m_property_string_ro(prop,action,arg,f);
1594 /// Demuxer name (RO)
1595 static int mp_property_demuxer(m_option_t* prop,int action,void* arg) {
1596 if(!demuxer) return M_PROPERTY_UNAVAILABLE;
1597 return m_property_string_ro(prop,action,arg,(char*)demuxer->desc->name);
1600 /// Position in the stream (RW)
1601 static int mp_property_stream_pos(m_option_t* prop,int action,void* arg) {
1602 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1603 if (!arg) return M_PROPERTY_ERROR;
1604 switch (action) {
1605 case M_PROPERTY_GET:
1606 *(off_t*)arg = stream_tell(demuxer->stream);
1607 return M_PROPERTY_OK;
1608 case M_PROPERTY_SET:
1609 M_PROPERTY_CLAMP(prop,*(off_t*)arg);
1610 stream_seek(demuxer->stream, *(off_t*)arg);
1611 return M_PROPERTY_OK;
1613 return M_PROPERTY_NOT_IMPLEMENTED;
1616 /// Stream start offset (RO)
1617 static int mp_property_stream_start(m_option_t* prop,int action,void* arg) {
1618 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1619 switch (action) {
1620 case M_PROPERTY_GET:
1621 *(off_t*)arg = demuxer->stream->start_pos;
1622 return M_PROPERTY_OK;
1624 return M_PROPERTY_NOT_IMPLEMENTED;
1627 /// Stream end offset (RO)
1628 static int mp_property_stream_end(m_option_t* prop,int action,void* arg) {
1629 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1630 switch (action) {
1631 case M_PROPERTY_GET:
1632 *(off_t*)arg = demuxer->stream->end_pos;
1633 return M_PROPERTY_OK;
1635 return M_PROPERTY_NOT_IMPLEMENTED;
1638 /// Stream length (RO)
1639 static int mp_property_stream_length(m_option_t* prop,int action,void* arg) {
1640 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1641 switch (action) {
1642 case M_PROPERTY_GET:
1643 *(off_t*)arg = demuxer->stream->end_pos - demuxer->stream->start_pos;
1644 return M_PROPERTY_OK;
1646 return M_PROPERTY_NOT_IMPLEMENTED;
1649 /// Media length in seconds (RO)
1650 static int mp_property_length(m_option_t* prop,int action,void* arg) {
1651 double len;
1653 if(!demuxer ||
1654 !(int)(len = demuxer_get_time_length(demuxer)))
1655 return M_PROPERTY_UNAVAILABLE;
1657 switch(action) {
1658 case M_PROPERTY_PRINT:
1659 if(!arg) return M_PROPERTY_ERROR;
1660 else {
1661 int h, m, s = len;
1662 h = s/3600;
1663 s -= h*3600;
1664 m = s/60;
1665 s -= m*60;
1666 *(char**)arg = malloc(20);
1667 if(h > 0) sprintf(*(char**)arg,"%d:%02d:%02d",h,m,s);
1668 else if(m > 0) sprintf(*(char**)arg,"%d:%02d",m,s);
1669 else sprintf(*(char**)arg,"%d",s);
1670 return M_PROPERTY_OK;
1672 break;
1674 return m_property_double_ro(prop,action,arg,len);
1677 ///@}
1679 /// \defgroup AudioProperties Audio properties
1680 /// \ingroup Properties
1681 ///@{
1683 /// Volume (RW)
1684 static int mp_property_volume(m_option_t* prop,int action,void* arg) {
1686 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1688 switch(action) {
1689 case M_PROPERTY_GET:
1690 if(!arg) return M_PROPERTY_ERROR;
1691 mixer_getbothvolume(&mixer,arg);
1692 return M_PROPERTY_OK;
1693 case M_PROPERTY_PRINT:{
1694 float vol;
1695 if(!arg) return M_PROPERTY_ERROR;
1696 mixer_getbothvolume(&mixer,&vol);
1697 return m_property_float_range(prop,action,arg,&vol);
1699 case M_PROPERTY_STEP_UP:
1700 case M_PROPERTY_STEP_DOWN:
1701 case M_PROPERTY_SET:
1702 break;
1703 default:
1704 return M_PROPERTY_NOT_IMPLEMENTED;
1707 if (edl_muted) return M_PROPERTY_DISABLED;
1708 user_muted = 0;
1710 switch(action) {
1711 case M_PROPERTY_SET:
1712 if(!arg) return M_PROPERTY_ERROR;
1713 M_PROPERTY_CLAMP(prop,*(float*)arg);
1714 mixer_setvolume(&mixer,*(float*)arg,*(float*)arg);
1715 return M_PROPERTY_OK;
1716 case M_PROPERTY_STEP_UP:
1717 if(arg && *(float*)arg <= 0)
1718 mixer_decvolume(&mixer);
1719 else
1720 mixer_incvolume(&mixer);
1721 return M_PROPERTY_OK;
1722 case M_PROPERTY_STEP_DOWN:
1723 if(arg && *(float*)arg <= 0)
1724 mixer_incvolume(&mixer);
1725 else
1726 mixer_decvolume(&mixer);
1727 return M_PROPERTY_OK;
1729 return M_PROPERTY_NOT_IMPLEMENTED;
1732 /// Mute (RW)
1733 static int mp_property_mute(m_option_t* prop,int action,void* arg) {
1735 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1737 switch(action) {
1738 case M_PROPERTY_SET:
1739 if(edl_muted) return M_PROPERTY_DISABLED;
1740 if(!arg) return M_PROPERTY_ERROR;
1741 if((!!*(int*)arg) != mixer.muted)
1742 mixer_mute(&mixer);
1743 user_muted = mixer.muted;
1744 return M_PROPERTY_OK;
1745 case M_PROPERTY_STEP_UP:
1746 case M_PROPERTY_STEP_DOWN:
1747 if(edl_muted) return M_PROPERTY_DISABLED;
1748 mixer_mute(&mixer);
1749 user_muted = mixer.muted;
1750 return M_PROPERTY_OK;
1751 case M_PROPERTY_PRINT:
1752 if(!arg) return M_PROPERTY_ERROR;
1753 if(edl_muted) {
1754 *(char**)arg = strdup(MSGTR_EnabledEdl);
1755 return M_PROPERTY_OK;
1757 default:
1758 return m_property_flag(prop,action,arg,&mixer.muted);
1763 /// Audio delay (RW)
1764 static int mp_property_audio_delay(m_option_t* prop,int action,void* arg) {
1765 if(!(sh_audio && sh_video)) return M_PROPERTY_UNAVAILABLE;
1766 switch(action) {
1767 case M_PROPERTY_SET:
1768 case M_PROPERTY_STEP_UP:
1769 case M_PROPERTY_STEP_DOWN:
1770 if(!arg) return M_PROPERTY_ERROR;
1771 else {
1772 float delay = audio_delay;
1773 m_property_delay(prop,action,arg,&audio_delay);
1774 if(sh_audio) sh_audio->delay -= audio_delay-delay;
1776 return M_PROPERTY_OK;
1777 default:
1778 return m_property_delay(prop,action,arg,&audio_delay);
1782 /// Audio codec tag (RO)
1783 static int mp_property_audio_format(m_option_t* prop,int action,void* arg) {
1784 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1785 return m_property_int_ro(prop,action,arg,sh_audio->format);
1788 /// Audio bitrate (RO)
1789 static int mp_property_audio_bitrate(m_option_t* prop,int action,void* arg) {
1790 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1791 return m_property_int_ro(prop,action,arg,sh_audio->i_bps);
1794 /// Samplerate (RO)
1795 static int mp_property_samplerate(m_option_t* prop,int action,void* arg) {
1796 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1797 return m_property_int_ro(prop,action,arg,sh_audio->samplerate);
1800 /// Number of channels (RO)
1801 static int mp_property_channels(m_option_t* prop,int action,void* arg) {
1802 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1803 switch(action) {
1804 case M_PROPERTY_PRINT:
1805 if(!arg) return M_PROPERTY_ERROR;
1806 switch(sh_audio->channels) {
1807 case 1: *(char**)arg = strdup("mono"); break;
1808 case 2: *(char**)arg = strdup("stereo"); break;
1809 default:
1810 *(char**)arg = malloc(32);
1811 sprintf(*(char**)arg,"%d channels",sh_audio->channels);
1813 return M_PROPERTY_OK;
1815 return m_property_int_ro(prop,action,arg,sh_audio->channels);
1818 /// Selected audio id (RW)
1819 static int mp_property_audio(m_option_t* prop,int action,void* arg) {
1820 int current_id = -1, tmp;
1822 switch(action) {
1823 case M_PROPERTY_GET:
1824 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1825 if(!arg) return M_PROPERTY_ERROR;
1826 *(int*)arg = audio_id;
1827 return M_PROPERTY_OK;
1828 case M_PROPERTY_PRINT:
1829 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1830 if(!arg) return M_PROPERTY_ERROR;
1832 if (audio_id < 0)
1833 *(char**)arg = strdup(MSGTR_Disabled);
1834 else {
1835 char lang[40] = MSGTR_Unknown;
1836 if (demuxer->type == DEMUXER_TYPE_MATROSKA)
1837 demux_mkv_get_audio_lang(demuxer, audio_id, lang, 9);
1838 #ifdef USE_DVDREAD
1839 else {
1840 int code = dvd_lang_from_aid(stream, audio_id);
1841 if (code) {
1842 lang[0] = code >> 8;
1843 lang[1] = code;
1844 lang[2] = 0;
1847 #endif
1848 *(char**)arg = malloc(64);
1849 snprintf(*(char**)arg, 64, "(%d) %s", audio_id, lang);
1851 return M_PROPERTY_OK;
1853 case M_PROPERTY_STEP_UP:
1854 case M_PROPERTY_SET:
1855 if(action==M_PROPERTY_SET && arg)
1856 tmp = *((int*)arg);
1857 else
1858 tmp = -1;
1859 current_id = demuxer->audio->id;
1860 audio_id = demuxer_switch_audio(demuxer, tmp);
1861 if(audio_id == -2 || (audio_id > -1 && demuxer->audio->id != current_id && current_id != -2))
1862 uninit_player(INITED_AO | INITED_ACODEC);
1863 if(audio_id > -1 && demuxer->audio->id != current_id) {
1864 sh_audio_t *sh2;
1865 sh2 = demuxer->a_streams[demuxer->audio->id];
1866 if(sh2) {
1867 sh2->ds = demuxer->audio;
1868 sh_audio = sh2;
1869 reinit_audio_chain();
1872 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
1873 return M_PROPERTY_OK;
1874 default:
1875 return M_PROPERTY_NOT_IMPLEMENTED;
1880 static int reinit_video_chain(void);
1881 /// Selected video id (RW)
1882 static int mp_property_video(m_option_t* prop,int action,void* arg) {
1883 int current_id = -1, tmp;
1885 switch(action) {
1886 case M_PROPERTY_GET:
1887 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1888 if(!arg) return M_PROPERTY_ERROR;
1889 *(int*)arg = video_id;
1890 return M_PROPERTY_OK;
1891 case M_PROPERTY_PRINT:
1892 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1893 if(!arg) return M_PROPERTY_ERROR;
1895 if (video_id < 0)
1896 *(char**)arg = strdup(MSGTR_Disabled);
1897 else {
1898 char lang[40] = MSGTR_Unknown;
1899 *(char**)arg = malloc(64);
1900 snprintf(*(char**)arg, 64, "(%d) %s", video_id, lang);
1902 return M_PROPERTY_OK;
1904 case M_PROPERTY_STEP_UP:
1905 case M_PROPERTY_SET:
1906 current_id = demuxer->video->id;
1907 if(action==M_PROPERTY_SET && arg)
1908 tmp = *((int*)arg);
1909 else
1910 tmp = -1;
1911 video_id = demuxer_switch_video(demuxer, tmp);
1912 if(video_id == -2 || (video_id > -1 && demuxer->video->id != current_id && current_id != -2))
1913 uninit_player(INITED_VCODEC | (fixed_vo && video_id != -2 ? 0 : INITED_VO));
1914 if(video_id > -1 && demuxer->video->id != current_id) {
1915 sh_video_t *sh2;
1916 sh2 = demuxer->v_streams[demuxer->video->id];
1917 if(sh2) {
1918 sh2->ds = demuxer->video;
1919 sh_video = sh2;
1920 reinit_video_chain();
1923 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
1924 return M_PROPERTY_OK;
1926 default:
1927 return M_PROPERTY_NOT_IMPLEMENTED;
1931 static int mp_property_program(m_option_t* prop,int action,void* arg) {
1932 demux_program_t prog;
1934 switch(action) {
1935 case M_PROPERTY_STEP_UP:
1936 case M_PROPERTY_SET:
1937 if(action==M_PROPERTY_SET && arg)
1938 prog.progid = *((int*)arg);
1939 else
1940 prog.progid = -1;
1941 if(demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) == DEMUXER_CTRL_NOTIMPL)
1942 return M_PROPERTY_ERROR;
1944 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid);
1945 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid);
1946 return M_PROPERTY_OK;
1948 default:
1949 return M_PROPERTY_NOT_IMPLEMENTED;
1953 ///@}
1955 /// \defgroup VideoProperties Video properties
1956 /// \ingroup Properties
1957 ///@{
1959 /// Fullscreen state (RW)
1960 static int mp_property_fullscreen(m_option_t* prop,int action,void* arg) {
1962 if(!video_out) return M_PROPERTY_UNAVAILABLE;
1964 switch(action) {
1965 case M_PROPERTY_SET:
1966 if(!arg) return M_PROPERTY_ERROR;
1967 M_PROPERTY_CLAMP(prop,*(int*)arg);
1968 if(vo_fs == !!*(int*)arg) return M_PROPERTY_OK;
1969 case M_PROPERTY_STEP_UP:
1970 case M_PROPERTY_STEP_DOWN:
1971 #ifdef HAVE_NEW_GUI
1972 if(use_gui) guiGetEvent(guiIEvent,(char*)MP_CMD_GUI_FULLSCREEN);
1973 else
1974 #endif
1975 if(vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
1976 return M_PROPERTY_OK;
1977 default:
1978 return m_property_flag(prop,action,arg,&vo_fs);
1982 static int mp_property_deinterlace(m_option_t* prop,int action,void* arg) {
1983 int deinterlace;
1984 vf_instance_t *vf;
1985 if (!sh_video || !sh_video->vfilter) return M_PROPERTY_UNAVAILABLE;
1986 vf = sh_video->vfilter;
1987 switch(action) {
1988 case M_PROPERTY_GET:
1989 if(!arg) return M_PROPERTY_ERROR;
1990 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1991 return M_PROPERTY_OK;
1992 case M_PROPERTY_SET:
1993 if(!arg) return M_PROPERTY_ERROR;
1994 M_PROPERTY_CLAMP(prop,*(int*)arg);
1995 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1996 return M_PROPERTY_OK;
1997 case M_PROPERTY_STEP_UP:
1998 case M_PROPERTY_STEP_DOWN:
1999 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
2000 deinterlace = !deinterlace;
2001 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
2002 return M_PROPERTY_OK;
2004 return M_PROPERTY_NOT_IMPLEMENTED;
2007 /// Panscan (RW)
2008 static int mp_property_panscan(m_option_t* prop,int action,void* arg) {
2010 if(!video_out || video_out->control(VOCTRL_GET_PANSCAN,NULL ) != VO_TRUE)
2011 return M_PROPERTY_UNAVAILABLE;
2013 switch(action) {
2014 case M_PROPERTY_SET:
2015 if(!arg) return M_PROPERTY_ERROR;
2016 M_PROPERTY_CLAMP(prop,*(float*)arg);
2017 vo_panscan = *(float*)arg;
2018 video_out->control(VOCTRL_SET_PANSCAN,NULL);
2019 return M_PROPERTY_OK;
2020 case M_PROPERTY_STEP_UP:
2021 case M_PROPERTY_STEP_DOWN:
2022 vo_panscan += (arg ? *(float*)arg : 0.1) *
2023 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2024 if(vo_panscan > 1) vo_panscan = 1;
2025 else if(vo_panscan < 0) vo_panscan = 0;
2026 video_out->control(VOCTRL_SET_PANSCAN,NULL);
2027 return M_PROPERTY_OK;
2028 default:
2029 return m_property_float_range(prop,action,arg,&vo_panscan);
2033 /// Helper to set vo flags.
2034 /** \ingroup PropertyImplHelper
2036 static int mp_property_vo_flag(m_option_t* prop,int action,void* arg,
2037 int vo_ctrl,int* vo_var) {
2039 if(!video_out) return M_PROPERTY_UNAVAILABLE;
2041 switch(action) {
2042 case M_PROPERTY_SET:
2043 if(!arg) return M_PROPERTY_ERROR;
2044 M_PROPERTY_CLAMP(prop,*(int*)arg);
2045 if(*vo_var == !!*(int*)arg) return M_PROPERTY_OK;
2046 case M_PROPERTY_STEP_UP:
2047 case M_PROPERTY_STEP_DOWN:
2048 if(vo_config_count) video_out->control(vo_ctrl, 0);
2049 return M_PROPERTY_OK;
2050 default:
2051 return m_property_flag(prop,action,arg,vo_var);
2055 /// Window always on top (RW)
2056 static int mp_property_ontop(m_option_t* prop,int action,void* arg) {
2057 return mp_property_vo_flag(prop,action,arg,VOCTRL_ONTOP,&vo_ontop);
2060 /// Display in the root window (RW)
2061 static int mp_property_rootwin(m_option_t* prop,int action,void* arg) {
2062 return mp_property_vo_flag(prop,action,arg,VOCTRL_ROOTWIN,&vo_rootwin);
2065 /// Show window borders (RW)
2066 static int mp_property_border(m_option_t* prop,int action,void* arg) {
2067 return mp_property_vo_flag(prop,action,arg,VOCTRL_BORDER,&vo_border);
2070 /// Framedropping state (RW)
2071 static int mp_property_framedropping(m_option_t* prop,int action,void* arg) {
2073 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2075 switch(action) {
2076 case M_PROPERTY_PRINT:
2077 if(!arg) return M_PROPERTY_ERROR;
2078 *(char**)arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
2079 (frame_dropping == 2 ? MSGTR_HardFrameDrop : MSGTR_Disabled));
2080 return M_PROPERTY_OK;
2081 default:
2082 return m_property_choice(prop,action,arg,&frame_dropping);
2086 /// Color settings, try to use vf/vo then fall back on TV. (RW)
2087 static int mp_property_gamma(m_option_t* prop,int action,void* arg) {
2088 int* gamma = prop->priv, r;
2090 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2092 if(gamma[0] == 1000) {
2093 gamma[0] = 0;
2094 get_video_colors (sh_video, prop->name, gamma);
2097 switch(action) {
2098 case M_PROPERTY_SET:
2099 if(!arg) return M_PROPERTY_ERROR;
2100 M_PROPERTY_CLAMP(prop,*(int*)arg);
2101 *gamma = *(int*)arg;
2102 r = set_video_colors(sh_video, prop->name, *gamma);
2103 if(r <= 0) break;
2104 return r;
2105 case M_PROPERTY_GET:
2106 if(!arg) return M_PROPERTY_ERROR;
2107 r = get_video_colors (sh_video, prop->name, arg);
2108 if(r <= 0) break;
2109 return r;
2110 case M_PROPERTY_STEP_UP:
2111 case M_PROPERTY_STEP_DOWN:
2112 *gamma += (arg ? *(int*)arg : 1) *
2113 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2114 M_PROPERTY_CLAMP(prop,*gamma);
2115 r = set_video_colors(sh_video, prop->name, *gamma);
2116 if(r <= 0) break;
2117 return r;
2118 default:
2119 return M_PROPERTY_NOT_IMPLEMENTED;
2122 #ifdef USE_TV
2123 if(demuxer->type == DEMUXER_TYPE_TV) {
2124 int l = strlen(prop->name);
2125 char tv_prop[3+l+1];
2126 sprintf(tv_prop,"tv_%s",prop->name);
2127 return mp_property_do(tv_prop,action,arg);
2129 #endif
2131 return M_PROPERTY_UNAVAILABLE;
2134 /// VSync (RW)
2135 static int mp_property_vsync(m_option_t* prop,int action,void* arg) {
2136 return m_property_flag(prop,action,arg,&vo_vsync);
2139 /// Video codec tag (RO)
2140 static int mp_property_video_format(m_option_t* prop,int action,void* arg) {
2141 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2142 return m_property_int_ro(prop,action,arg,sh_video->format);
2145 /// Video bitrate (RO)
2146 static int mp_property_video_bitrate(m_option_t* prop,int action,void* arg) {
2147 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2148 return m_property_int_ro(prop,action,arg,sh_video->i_bps);
2151 /// Video display width (RO)
2152 static int mp_property_width(m_option_t* prop,int action,void* arg) {
2153 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2154 return m_property_int_ro(prop,action,arg,sh_video->disp_w);
2157 /// Video display height (RO)
2158 static int mp_property_height(m_option_t* prop,int action,void* arg) {
2159 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2160 return m_property_int_ro(prop,action,arg,sh_video->disp_h);
2163 /// Video fps (RO)
2164 static int mp_property_fps(m_option_t* prop,int action,void* arg) {
2165 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2166 return m_property_float_ro(prop,action,arg,sh_video->fps);
2169 /// Video aspect (RO)
2170 static int mp_property_aspect(m_option_t* prop,int action,void* arg) {
2171 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2172 return m_property_float_ro(prop,action,arg,sh_video->aspect);
2175 ///@}
2177 /// \defgroup SubProprties Subtitles properties
2178 /// \ingroup Properties
2179 ///@{
2181 /// Text subtitle position (RW)
2182 static int mp_property_sub_pos(m_option_t* prop,int action,void* arg) {
2183 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2185 switch(action) {
2186 case M_PROPERTY_SET:
2187 if(!arg) return M_PROPERTY_ERROR;
2188 case M_PROPERTY_STEP_UP:
2189 case M_PROPERTY_STEP_DOWN:
2190 vo_osd_changed(OSDTYPE_SUBTITLE);
2191 default:
2192 return m_property_int_range(prop,action,arg,&sub_pos);
2196 /// Selected subtitles (RW)
2197 static int mp_property_sub(m_option_t* prop,int action,void* arg) {
2198 int source = -1, reset_spu = 0;
2199 char* sub_name;
2201 if(global_sub_size <= 0) return M_PROPERTY_UNAVAILABLE;
2203 switch(action) {
2204 case M_PROPERTY_GET:
2205 if(!arg) return M_PROPERTY_ERROR;
2206 *(int*)arg = global_sub_pos;
2207 return M_PROPERTY_OK;
2208 case M_PROPERTY_PRINT:
2209 if(!arg) return M_PROPERTY_ERROR;
2210 *(char**)arg = malloc(64);
2211 (*(char**)arg)[63] = 0;
2212 sub_name = 0;
2213 if(subdata)
2214 sub_name = subdata->filename;
2215 #ifdef USE_ASS
2216 if (ass_track && ass_track->name)
2217 sub_name = ass_track->name;
2218 #endif
2219 if(sub_name) {
2220 char *tmp,*tmp2;
2221 tmp = sub_name;
2222 if ((tmp2 = strrchr(tmp, '/')))
2223 tmp = tmp2+1;
2225 snprintf(*(char**)arg, 63, "(%d) %s%s",
2226 set_of_sub_pos + 1,
2227 strlen(tmp) < 20 ? "" : "...",
2228 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
2229 return M_PROPERTY_OK;
2231 if (demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
2232 char lang[40] = MSGTR_Unknown;
2233 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
2234 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, lang);
2235 return M_PROPERTY_OK;
2237 #ifdef HAVE_OGGVORBIS
2238 if (demuxer->type == DEMUXER_TYPE_OGG && d_dvdsub && dvdsub_id >= 0) {
2239 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
2240 if (!lang) lang = MSGTR_Unknown;
2241 snprintf(*(char**)arg, 63, "(%d) %s",
2242 dvdsub_id, lang);
2243 return M_PROPERTY_OK;
2245 #endif
2246 if (vo_vobsub && vobsub_id >= 0) {
2247 const char *language = MSGTR_Unknown;
2248 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
2249 snprintf(*(char**)arg, 63, "(%d) %s",
2250 vobsub_id, language ? language : MSGTR_Unknown);
2251 return M_PROPERTY_OK;
2253 #ifdef USE_DVDREAD
2254 if (vo_spudec && dvdsub_id >= 0) {
2255 char lang[3];
2256 int code = dvd_lang_from_sid(stream, dvdsub_id);
2257 lang[0] = code >> 8;
2258 lang[1] = code;
2259 lang[2] = 0;
2260 snprintf(*(char**)arg, 63, "(%d) %s",
2261 dvdsub_id, lang);
2262 return M_PROPERTY_OK;
2264 #endif
2265 if (dvdsub_id >= 0) {
2266 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
2267 return M_PROPERTY_OK;
2269 snprintf(*(char**)arg, 63, MSGTR_Disabled);
2270 return M_PROPERTY_OK;
2272 case M_PROPERTY_SET:
2273 if(!arg) return M_PROPERTY_ERROR;
2274 if(*(int*)arg < -1) *(int*)arg = -1;
2275 else if(*(int*)arg >= global_sub_size) *(int*)arg = global_sub_size-1;
2276 global_sub_pos = *(int*)arg;
2277 break;
2278 case M_PROPERTY_STEP_UP:
2279 global_sub_pos += 2;
2280 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
2281 break;
2282 case M_PROPERTY_STEP_DOWN:
2283 global_sub_pos += global_sub_size+1;
2284 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
2285 break;
2286 default:
2287 return M_PROPERTY_NOT_IMPLEMENTED;
2290 if (global_sub_pos >= 0)
2291 source = sub_source();
2293 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
2294 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
2295 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
2296 global_sub_indices[SUB_SOURCE_SUBS],
2297 global_sub_indices[SUB_SOURCE_DEMUX],
2298 global_sub_pos, source);
2300 set_of_sub_pos = -1;
2301 subdata = NULL;
2302 vo_sub_last = vo_sub = NULL;
2304 vobsub_id = -1;
2305 dvdsub_id = -1;
2306 if (d_dvdsub) {
2307 if(d_dvdsub->id > -2) reset_spu = 1;
2308 d_dvdsub->id = -2;
2310 #ifdef USE_ASS
2311 ass_track = 0;
2312 #endif
2314 if (source == SUB_SOURCE_VOBSUB) {
2315 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
2316 } else if (source == SUB_SOURCE_SUBS) {
2317 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
2318 #ifdef USE_ASS
2319 if (ass_enabled && set_of_ass_tracks[set_of_sub_pos])
2320 ass_track = set_of_ass_tracks[set_of_sub_pos];
2321 else
2322 #endif
2324 subdata = set_of_subtitles[set_of_sub_pos];
2325 vo_osd_changed(OSDTYPE_SUBTITLE);
2327 } else if (source == SUB_SOURCE_DEMUX) {
2328 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
2329 if (d_dvdsub) {
2330 #ifdef USE_DVDREAD
2331 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
2332 d_dvdsub->id = dvdsub_id;
2333 spudec_reset(vo_spudec);
2335 #endif
2336 if (stream->type != STREAMTYPE_DVD) {
2337 int i = 0;
2338 for (d_dvdsub->id = 0; d_dvdsub->id < MAX_S_STREAMS; d_dvdsub->id++) {
2339 if (demuxer->s_streams[d_dvdsub->id]) {
2340 if (i == dvdsub_id) break;
2341 i++;
2344 d_dvdsub->sh = demuxer->s_streams[d_dvdsub->id];
2346 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
2347 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
2349 if (d_dvdsub->sh && d_dvdsub->id >= 0) {
2350 sh_sub_t *sh = d_dvdsub->sh;
2351 if (sh->type == 'v')
2352 init_vo_spudec();
2353 #ifdef USE_ASS
2354 else if (ass_enabled && sh->type == 'a')
2355 ass_track = sh->ass_track;
2356 #endif
2359 } else { // off
2360 vo_osd_changed(OSDTYPE_SUBTITLE);
2361 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2363 #ifdef USE_DVDREAD
2364 if (vo_spudec && stream->type == STREAMTYPE_DVD && dvdsub_id < 0 && reset_spu) {
2365 dvdsub_id = -2;
2366 d_dvdsub->id = dvdsub_id;
2367 spudec_reset(vo_spudec);
2369 #endif
2371 return M_PROPERTY_OK;
2374 /// Subtitle delay (RW)
2375 static int mp_property_sub_delay(m_option_t* prop,int action,void* arg) {
2376 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2377 return m_property_delay(prop,action,arg,&sub_delay);
2380 /// Alignment of text subtitles (RW)
2381 static int mp_property_sub_alignment(m_option_t* prop,int action,void* arg) {
2382 char* name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
2384 if(!sh_video || global_sub_pos < 0 || sub_source() != SUB_SOURCE_SUBS)
2385 return M_PROPERTY_UNAVAILABLE;
2387 switch(action) {
2388 case M_PROPERTY_PRINT:
2389 if(!arg) return M_PROPERTY_ERROR;
2390 M_PROPERTY_CLAMP(prop,sub_alignment);
2391 *(char**)arg = strdup(name[sub_alignment]);
2392 return M_PROPERTY_OK;
2393 case M_PROPERTY_SET:
2394 if(!arg) return M_PROPERTY_ERROR;
2395 case M_PROPERTY_STEP_UP:
2396 case M_PROPERTY_STEP_DOWN:
2397 vo_osd_changed(OSDTYPE_SUBTITLE);
2398 default:
2399 return m_property_choice(prop,action,arg,&sub_alignment);
2403 /// Subtitle visibility (RW)
2404 static int mp_property_sub_visibility(m_option_t* prop,int action,void* arg) {
2405 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2407 switch(action) {
2408 case M_PROPERTY_SET:
2409 if(!arg) return M_PROPERTY_ERROR;
2410 case M_PROPERTY_STEP_UP:
2411 case M_PROPERTY_STEP_DOWN:
2412 vo_osd_changed(OSDTYPE_SUBTITLE);
2413 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2414 default:
2415 return m_property_flag(prop,action,arg,&sub_visibility);
2419 /// Show only forced subtitles (RW)
2420 static int mp_property_sub_forced_only(m_option_t* prop,int action,void* arg) {
2421 if(!vo_spudec) return M_PROPERTY_UNAVAILABLE;
2423 switch(action) {
2424 case M_PROPERTY_SET:
2425 if(!arg) return M_PROPERTY_ERROR;
2426 case M_PROPERTY_STEP_UP:
2427 case M_PROPERTY_STEP_DOWN:
2428 m_property_flag(prop,action,arg,&forced_subs_only);
2429 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
2430 return M_PROPERTY_OK;
2431 default:
2432 return m_property_flag(prop,action,arg,&forced_subs_only);
2437 ///@}
2439 /// \defgroup TVProperties TV properties
2440 /// \ingroup Properties
2441 ///@{
2443 #ifdef USE_TV
2445 /// TV color settings (RW)
2446 static int mp_property_tv_color(m_option_t* prop,int action,void* arg) {
2447 int r,val;
2448 tvi_handle_t* tvh = demuxer->priv;
2449 if(demuxer->type != DEMUXER_TYPE_TV || !tvh) return M_PROPERTY_UNAVAILABLE;
2451 switch(action) {
2452 case M_PROPERTY_SET:
2453 if(!arg) return M_PROPERTY_ERROR;
2454 M_PROPERTY_CLAMP(prop,*(int*)arg);
2455 return tv_set_color_options(tvh,(int)prop->priv,*(int*)arg);
2456 case M_PROPERTY_GET:
2457 return tv_get_color_options(tvh,(int)prop->priv,arg);
2458 case M_PROPERTY_STEP_UP:
2459 case M_PROPERTY_STEP_DOWN:
2460 if((r = tv_get_color_options(tvh,(int)prop->priv,&val)) >= 0) {
2461 if(!r) return M_PROPERTY_ERROR;
2462 val += (arg ? *(int*)arg : 1) *
2463 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2464 M_PROPERTY_CLAMP(prop,val);
2465 return tv_set_color_options(tvh,(int)prop->priv,val);
2467 return M_PROPERTY_ERROR;
2469 return M_PROPERTY_NOT_IMPLEMENTED;
2472 #endif
2474 ///@}
2476 /// All properties available in MPlayer.
2477 /** \ingroup Properties
2479 static m_option_t mp_properties[] = {
2480 // General
2481 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2482 M_OPT_RANGE, 0, 3, NULL },
2483 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2484 M_OPT_RANGE, 0.01, 100.0, NULL },
2485 { "filename", mp_property_filename, CONF_TYPE_STRING,
2486 0, 0, 0, NULL },
2487 { "path", mp_property_path, CONF_TYPE_STRING,
2488 0, 0, 0, NULL },
2489 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2490 0, 0, 0, NULL },
2491 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2492 M_OPT_MIN, 0, 0, NULL },
2493 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2494 M_OPT_MIN, 0, 0, NULL },
2495 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2496 M_OPT_MIN, 0, 0, NULL },
2497 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2498 M_OPT_MIN, 0, 0, NULL },
2499 { "length", mp_property_length, CONF_TYPE_DOUBLE,
2500 0, 0, 0, NULL },
2502 // Audio
2503 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2504 M_OPT_RANGE, 0, 100, NULL },
2505 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2506 M_OPT_RANGE, 0, 1, NULL },
2507 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2508 M_OPT_RANGE, -100, 100, NULL },
2509 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2510 0, 0, 0, NULL },
2511 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2512 0, 0, 0, NULL },
2513 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2514 0, 0, 0, NULL },
2515 { "channels", mp_property_channels, CONF_TYPE_INT,
2516 0, 0, 0, NULL },
2517 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2518 CONF_RANGE, -2, MAX_A_STREAMS-1, NULL },
2520 // Video
2521 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2522 M_OPT_RANGE, 0, 1, NULL },
2523 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2524 M_OPT_RANGE, 0, 1, NULL },
2525 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2526 M_OPT_RANGE, 0, 1, NULL },
2527 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2528 M_OPT_RANGE, 0, 1, NULL },
2529 { "border", mp_property_border, CONF_TYPE_FLAG,
2530 M_OPT_RANGE, 0, 1, NULL },
2531 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2532 M_OPT_RANGE, 0, 2, NULL },
2533 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2534 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2535 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2536 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2537 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2538 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2539 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2540 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2541 { "hue", mp_property_gamma, CONF_TYPE_INT,
2542 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2543 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2544 M_OPT_RANGE, 0, 1, NULL },
2545 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2546 M_OPT_RANGE, 0, 1, NULL },
2547 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2548 0, 0, 0, NULL },
2549 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2550 0, 0, 0, NULL },
2551 { "width", mp_property_width, CONF_TYPE_INT,
2552 0, 0, 0, NULL },
2553 { "height", mp_property_height, CONF_TYPE_INT,
2554 0, 0, 0, NULL },
2555 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2556 0, 0, 0, NULL },
2557 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2558 0, 0, 0, NULL },
2559 { "switch_video", mp_property_video, CONF_TYPE_INT,
2560 CONF_RANGE, -2, MAX_V_STREAMS-1, NULL },
2561 { "switch_program", mp_property_program, CONF_TYPE_INT,
2562 CONF_RANGE, -1, 65535, NULL },
2564 // Subs
2565 { "sub", mp_property_sub, CONF_TYPE_INT,
2566 M_OPT_MIN, -1, 0, NULL },
2567 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2568 0, 0, 0, NULL },
2569 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2570 M_OPT_RANGE, 0, 100, NULL },
2571 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2572 M_OPT_RANGE, 0, 2, NULL },
2573 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2574 M_OPT_RANGE, 0, 1, NULL },
2575 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2576 M_OPT_RANGE, 0, 1, NULL },
2578 #ifdef USE_TV
2579 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2580 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_BRIGHTNESS },
2581 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2582 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_CONTRAST },
2583 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2584 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_SATURATION },
2585 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2586 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_HUE },
2587 #endif
2589 { NULL, NULL, NULL, 0, 0, 0, NULL }
2592 m_option_t* mp_property_find(const char* name) {
2593 return m_option_list_find(mp_properties,name);
2596 int mp_property_do(const char* name,int action, void* val) {
2597 m_option_t* p = mp_property_find(name);
2598 if(!p) return M_PROPERTY_UNAVAILABLE;
2599 return m_property_do(p,action,val);
2602 ///@}
2603 // Properties group
2607 * \defgroup Command2Property Command to property bridge
2609 * It is used to handle most commands that just set a property
2610 * and optionally display something on the OSD.
2611 * Two kinds of commands are handled: adjust or toggle.
2613 * Adjust commands take 1 or 2 parameters: <value> <abs>
2614 * If <abs> is non-zero the property is set to the given value
2615 * otherwise it is adjusted.
2617 * Toggle commands take 0 or 1 parameters. With no parameter
2618 * or a value less than the property minimum it just steps the
2619 * property to its next value. Otherwise it sets it to the given
2620 * value.
2625 /// List of the commands that can be handled by setting a property.
2626 static struct {
2627 /// property name
2628 const char* name;
2629 /// cmd id
2630 int cmd;
2631 /// set/adjust or toggle command
2632 int toggle;
2633 /// progressbar type
2634 int osd_progbar;
2635 /// osd msg id if it must be shared
2636 int osd_id;
2637 /// osd msg template
2638 const char* osd_msg;
2639 } set_prop_cmd[] = {
2640 // audio
2641 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2642 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2643 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2644 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2645 // video
2646 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2647 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2648 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2649 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2650 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2651 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2652 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2653 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2654 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2655 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2656 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2657 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2658 // subs
2659 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2660 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2661 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2662 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2663 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2664 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2665 #ifdef USE_TV
2666 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2667 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2668 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2669 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2670 #endif
2671 { NULL, 0, 0, 0, -1, NULL }
2674 /// Handle commands that set a property.
2675 static int set_property_command(mp_cmd_t* cmd) {
2676 int i,r;
2677 m_option_t* prop;
2679 // look for the command
2680 for(i = 0 ; set_prop_cmd[i].name ; i++)
2681 if(set_prop_cmd[i].cmd == cmd->id) break;
2682 if(!set_prop_cmd[i].name) return 0;
2684 // get the property
2685 prop = mp_property_find(set_prop_cmd[i].name);
2686 if(!prop) return 0;
2688 // toggle command
2689 if(set_prop_cmd[i].toggle) {
2690 // set to value
2691 if(cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2692 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v.i);
2693 else
2694 r = m_property_do(prop,M_PROPERTY_STEP_UP,NULL);
2695 } else if(cmd->args[1].v.i) //set
2696 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v);
2697 else // adjust
2698 r = m_property_do(prop,M_PROPERTY_STEP_UP,&cmd->args[0].v);
2700 if(r <= 0) return 1;
2702 if(set_prop_cmd[i].osd_progbar) {
2703 if(prop->type == CONF_TYPE_INT) {
2704 if(m_property_do(prop,M_PROPERTY_GET,&r) > 0)
2705 set_osd_bar(set_prop_cmd[i].osd_progbar,
2706 set_prop_cmd[i].osd_msg,
2707 prop->min,prop->max,r);
2708 } else if(prop->type == CONF_TYPE_FLOAT) {
2709 float f;
2710 if(m_property_do(prop,M_PROPERTY_GET,&f) > 0)
2711 set_osd_bar(set_prop_cmd[i].osd_progbar,set_prop_cmd[i].osd_msg,
2712 prop->min,prop->max,f);
2713 } else
2714 mp_msg(MSGT_CPLAYER,MSGL_ERR, "Property use an unsupported type.\n");
2715 return 1;
2718 if(set_prop_cmd[i].osd_msg) {
2719 char* val = m_property_print(prop);
2720 if(val) {
2721 set_osd_msg(set_prop_cmd[i].osd_id >= 0 ? set_prop_cmd[i].osd_id :
2722 OSD_MSG_PROPERTY+i,1,osd_duration,
2723 set_prop_cmd[i].osd_msg,val);
2724 free(val);
2727 return 1;
2730 static void reinit_audio_chain(void) {
2731 if(sh_audio){
2732 current_module="init_audio_codec";
2733 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2734 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
2735 sh_audio=d_audio->sh=NULL; // failed to init :(
2736 d_audio->id = -2;
2737 return;
2738 } else
2739 inited_flags|=INITED_ACODEC;
2740 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2743 //const ao_info_t *info=audio_out->info;
2744 current_module="af_preinit";
2745 ao_data.samplerate=force_srate;
2746 ao_data.channels=0;
2747 ao_data.format=audio_output_format;
2748 #if 1
2749 // first init to detect best values
2750 if(!preinit_audio_filters(sh_audio,
2751 // input:
2752 (int)(sh_audio->samplerate*playback_speed),
2753 sh_audio->channels, sh_audio->sample_format,
2754 // output:
2755 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){
2756 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2757 exit_player(MSGTR_Exit_error);
2759 #endif
2760 current_module="ao2_init";
2761 if(!(audio_out=init_best_audio_out(audio_driver_list,
2762 0, // plugin flag
2763 ao_data.samplerate,
2764 ao_data.channels,
2765 ao_data.format,0))){
2766 // FAILED:
2767 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2768 uninit_player(INITED_ACODEC); // close codec
2769 sh_audio=d_audio->sh=NULL; // -> nosound
2770 d_audio->id = -2;
2771 return;
2772 } else {
2773 // SUCCESS:
2774 inited_flags|=INITED_AO;
2775 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2776 audio_out->info->short_name,
2777 ao_data.samplerate, ao_data.channels,
2778 af_fmt2str_short(ao_data.format),
2779 af_fmt2bits(ao_data.format)/8 );
2780 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2781 audio_out->info->name, audio_out->info->author);
2782 if(strlen(audio_out->info->comment) > 0)
2783 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2784 // init audio filters:
2785 #if 1
2786 current_module="af_init";
2787 if(!build_afilter_chain(sh_audio, &ao_data)) {
2788 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2789 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2790 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2791 // sh_audio=d_audio->sh=NULL; // -> nosound
2793 #endif
2795 mixer.audio_out = audio_out;
2796 mixer.volstep = volstep;
2801 ///@}
2802 // Command2Property
2805 // Return pts value corresponding to the end point of audio written to the
2806 // ao so far.
2807 static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio)
2809 // first calculate the end pts of audio that has been output by decoder
2810 double a_pts = sh_audio->pts;
2811 if (a_pts != MP_NOPTS_VALUE)
2812 // Good, decoder supports new way of calculating audio pts.
2813 // sh_audio->pts is the timestamp of the latest input packet with
2814 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2815 // the amount of bytes the decoder has written after that timestamp.
2816 a_pts += sh_audio->pts_bytes / (double) sh_audio->o_bps;
2817 else {
2818 // Decoder doesn't support new way of calculating pts (or we're
2819 // being called before it has decoded anything with known timestamp).
2820 // Use the old method of audio pts calculation: take the timestamp
2821 // of last packet with known pts the decoder has read data from,
2822 // and add amount of bytes read after the beginning of that packet
2823 // divided by input bps. This will be inaccurate if the input/output
2824 // ratio is not constant for every audio packet or if it is constant
2825 // but not accurately known in sh_audio->i_bps.
2827 a_pts = d_audio->pts;
2828 // ds_tell_pts returns bytes read after last timestamp from
2829 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2830 // it has read but not decoded
2831 if (sh_audio->i_bps)
2832 a_pts += (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len) /
2833 (double)sh_audio->i_bps;
2835 // Now a_pts hopefully holds the pts for end of audio from decoder.
2836 // Substract data in buffers between decoder and audio out.
2838 // Decoded but not filtered
2839 a_pts -= sh_audio->a_buffer_len / (double)sh_audio->o_bps;
2841 // Data that was ready for ao but was buffered because ao didn't fully
2842 // accept everything to internal buffers yet
2843 a_pts -= sh_audio->a_out_buffer_len * playback_speed / (double)ao_data.bps;
2845 return a_pts;
2848 // Return pts value corresponding to currently playing audio.
2849 static double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio,
2850 ao_functions_t *audio_out)
2852 return written_audio_pts(sh_audio, d_audio) - playback_speed *
2853 audio_out->get_delay();
2856 static void update_subtitles(void)
2858 // find sub
2859 if (subdata) {
2860 double pts = sh_video->pts;
2861 if (sub_fps==0) sub_fps = sh_video->fps;
2862 current_module = "find_sub";
2863 if (pts > sub_last_pts || pts < sub_last_pts-1.0) {
2864 find_sub(subdata, (pts+sub_delay) *
2865 (subdata->sub_uses_time ? 100. : sub_fps));
2866 if (vo_sub) vo_sub_last = vo_sub;
2867 // FIXME! frame counter...
2868 sub_last_pts = pts;
2872 // DVD sub:
2873 if (vo_config_count && vo_spudec) {
2874 unsigned char* packet=NULL;
2875 int len, timestamp;
2876 current_module = "spudec";
2877 spudec_heartbeat(vo_spudec, 90000*sh_video->timer);
2878 /* Get a sub packet from the DVD or a vobsub and make a timestamp
2879 * relative to sh_video->timer */
2880 while(1) {
2881 // Vobsub
2882 len = 0;
2883 if (vo_vobsub) {
2884 if (sh_video->pts+sub_delay >= 0) {
2885 len = vobsub_get_packet(vo_vobsub, sh_video->pts+sub_delay,
2886 (void**)&packet, &timestamp);
2887 if (len > 0) {
2888 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
2889 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);
2892 } else {
2893 // DVD sub
2894 len = ds_get_packet_sub(d_dvdsub, (unsigned char**)&packet);
2895 if (len > 0) {
2896 // XXX This is wrong, sh_video->pts can be arbitrarily
2897 // much behind demuxing position. Unfortunately using
2898 // d_video->pts which would have been the simplest
2899 // improvement doesn't work because mpeg specific hacks
2900 // in video.c set d_video->pts to 0.
2901 float x = d_dvdsub->pts - sh_video->pts;
2902 if (x > -20 && x < 20) // prevent missing subs on pts reset
2903 timestamp = 90000*(sh_video->timer + d_dvdsub->pts
2904 + sub_delay - sh_video->pts);
2905 else timestamp = 90000*(sh_video->timer + sub_delay);
2906 mp_dbg(MSGT_CPLAYER, MSGL_V, "\rDVD sub: len=%d "
2907 "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len,
2908 sh_video->pts, d_dvdsub->pts, timestamp);
2911 if (len<=0 || !packet) break;
2912 if (timestamp >= 0)
2913 spudec_assemble(vo_spudec, packet, len, timestamp);
2916 if (spudec_changed(vo_spudec))
2917 vo_osd_changed(OSDTYPE_SPU);
2919 current_module=NULL;
2922 static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video)
2924 unsigned char *start;
2925 int in_size;
2926 int hit_eof=0;
2927 double pts;
2929 while (1) {
2930 void *decoded_frame;
2931 current_module = "decode video";
2932 // XXX Time used in this call is not counted in any performance
2933 // timer now, OSD is not updated correctly for filter-added frames
2934 if (vf_output_queued_frame(sh_video->vfilter))
2935 break;
2936 current_module = "video_read_frame";
2937 in_size = ds_get_packet_pts(d_video, &start, &pts);
2938 if (in_size < 0) {
2939 // try to extract last frames in case of decoder lag
2940 in_size = 0;
2941 pts = 1e300;
2942 hit_eof = 1;
2944 if (in_size > max_framesize)
2945 max_framesize = in_size;
2946 if (pts == MP_NOPTS_VALUE)
2947 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts value from demuxer MISSING\n");
2948 current_module = "decode video";
2949 decoded_frame = decode_video(sh_video, start, in_size, 0, pts);
2950 if (decoded_frame) {
2951 update_subtitles();
2952 update_osd_msg();
2953 current_module = "filter video";
2954 if (filter_video(sh_video, decoded_frame, sh_video->pts))
2955 break;
2957 if (hit_eof)
2958 return 0;
2960 return 1;
2963 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy) {
2964 //remove the borders, if any, and rescale to the range [0,1],[0,1]
2965 if(vo_fs) { //we are in full-screen mode
2966 if(vo_screenwidth > vo_dwidth) //there are borders along the x axis
2967 ix -= (vo_screenwidth - vo_dwidth) / 2;
2968 if(vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
2969 iy -= (vo_screenheight - vo_dheight) / 2;
2971 if(ix < 0 || ix > vo_dwidth) {*dx = *dy = -1.0; return; } //we are on one of the borders
2972 if(iy < 0 || iy > vo_dheight) {*dx = *dy = -1.0; return; } //we are on one of the borders
2975 *dx = (double) ix / (double) vo_dwidth;
2976 *dy = (double) iy / (double) vo_dheight;
2978 mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
2979 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth, vo_dheight, vo_fs);
2982 #ifdef HAVE_RTC
2983 int rtc_fd = -1;
2984 #endif
2986 static float timing_sleep(float time_frame)
2988 #ifdef HAVE_RTC
2989 if (rtc_fd >= 0){
2990 // -------- RTC -----------
2991 current_module="sleep_rtc";
2992 while (time_frame > 0.000) {
2993 unsigned long rtc_ts;
2994 if (read(rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2995 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2996 time_frame -= GetRelativeTime();
2998 } else
2999 #endif
3000 #ifdef SYS_DARWIN
3002 current_module = "sleep_darwin";
3003 while (time_frame > 0.005) {
3004 usec_sleep(1000000*time_frame);
3005 time_frame -= GetRelativeTime();
3008 #else
3010 // assume kernel HZ=100 for softsleep, works with larger HZ but with
3011 // unnecessarily high CPU usage
3012 float margin = softsleep ? 0.011 : 0;
3013 current_module = "sleep_timer";
3014 while (time_frame > margin) {
3015 usec_sleep(1000000 * (time_frame - margin));
3016 time_frame -= GetRelativeTime();
3018 if (softsleep){
3019 current_module = "sleep_soft";
3020 if (time_frame < 0)
3021 mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
3022 while (time_frame > 0)
3023 time_frame-=GetRelativeTime(); // burn the CPU
3026 #endif /* SYS_DARWIN */
3027 return time_frame;
3030 static void adjust_sync_and_print_status(int between_frames, float timing_error)
3032 current_module="av_sync";
3034 if(sh_audio){
3035 double a_pts, v_pts;
3037 if (autosync)
3039 * If autosync is enabled, the value for delay must be calculated
3040 * a bit differently. It is set only to the difference between
3041 * the audio and video timers. Any attempt to include the real
3042 * or corrected delay causes the pts_correction code below to
3043 * try to correct for the changes in delay which autosync is
3044 * trying to measure. This keeps the two from competing, but still
3045 * allows the code to correct for PTS drift *only*. (Using a delay
3046 * value here, even a "corrected" one, would be incompatible with
3047 * autosync mode.)
3049 a_pts = written_audio_pts(sh_audio, d_audio) - sh_audio->delay;
3050 else
3051 a_pts = playing_audio_pts(sh_audio, d_audio, audio_out);
3053 v_pts = sh_video->pts;
3056 static int drop_message=0;
3057 double AV_delay = a_pts - audio_delay - v_pts;
3058 double x;
3059 if (AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
3060 ++drop_message;
3061 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
3063 if (autosync)
3064 x = AV_delay*0.1f;
3065 else
3066 /* Do not correct target time for the next frame if this frame
3067 * was late not because of wrong target time but because the
3068 * target time could not be met */
3069 x = (AV_delay + timing_error * playback_speed) * 0.1f;
3070 if (x < -max_pts_correction)
3071 x = -max_pts_correction;
3072 else if (x> max_pts_correction)
3073 x = max_pts_correction;
3074 if (default_max_pts_correction >= 0)
3075 max_pts_correction = default_max_pts_correction;
3076 else
3077 max_pts_correction = sh_video->frametime*0.10; // +-10% of time
3078 if (!between_frames) {
3079 sh_audio->delay+=x;
3080 c_total+=x;
3082 if(!quiet)
3083 print_status(a_pts - audio_delay, AV_delay, c_total);
3086 } else {
3087 // No audio:
3089 if (!quiet)
3090 print_status(0, 0, 0);
3094 static int fill_audio_out_buffers(void)
3096 unsigned int t;
3097 double tt;
3098 int playsize;
3099 int playflags=0;
3100 int audio_eof=0;
3101 int bytes_to_write;
3103 current_module="play_audio";
3105 while (1) {
3106 // all the current uses of ao_data.pts seem to be in aos that handle
3107 // sync completely wrong; there should be no need to use ao_data.pts
3108 // in get_space()
3109 ao_data.pts = ((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
3110 bytes_to_write = audio_out->get_space();
3111 if (sh_video || bytes_to_write >= ao_data.outburst)
3112 break;
3114 // handle audio-only case:
3115 // this is where mplayer sleeps during audio-only playback
3116 // to avoid 100% CPU use
3117 usec_sleep(10000); // Wait a tick before retry
3120 while (bytes_to_write) {
3121 playsize = bytes_to_write;
3122 if (playsize > MAX_OUTBURST)
3123 playsize = MAX_OUTBURST;
3124 bytes_to_write -= playsize;
3126 // Fill buffer if needed:
3127 current_module="decode_audio";
3128 t = GetTimer();
3129 while (sh_audio->a_out_buffer_len < playsize) {
3130 int buflen = sh_audio->a_out_buffer_len;
3131 int ret = decode_audio(sh_audio, &sh_audio->a_out_buffer[buflen],
3132 playsize - buflen, // min bytes
3133 sh_audio->a_out_buffer_size - buflen // max
3135 if (ret <= 0) { // EOF?
3136 if (d_audio->eof) {
3137 audio_eof = 1;
3138 if (sh_audio->a_out_buffer_len == 0)
3139 return 0;
3141 break;
3143 sh_audio->a_out_buffer_len += ret;
3145 t = GetTimer() - t;
3146 tt = t*0.000001f; audio_time_usage+=tt;
3147 if (playsize > sh_audio->a_out_buffer_len) {
3148 playsize = sh_audio->a_out_buffer_len;
3149 if (audio_eof)
3150 playflags |= AOPLAY_FINAL_CHUNK;
3152 if (!playsize)
3153 break;
3155 // play audio:
3156 current_module="play_audio";
3158 // Is this pts value actually useful for the aos that access it?
3159 // They're obviously badly broken in the way they handle av sync;
3160 // would not having access to this make them more broken?
3161 ao_data.pts = ((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
3162 playsize = audio_out->play(sh_audio->a_out_buffer, playsize, playflags);
3164 if (playsize > 0) {
3165 sh_audio->a_out_buffer_len -= playsize;
3166 memmove(sh_audio->a_out_buffer, &sh_audio->a_out_buffer[playsize],
3167 sh_audio->a_out_buffer_len);
3168 sh_audio->delay += playback_speed*playsize/(double)ao_data.bps;
3170 else if (audio_eof && audio_out->get_delay() < .04) {
3171 // Sanity check to avoid hanging in case current ao doesn't output
3172 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3173 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n");
3174 sh_audio->a_out_buffer_len = 0;
3177 return 1;
3180 static int sleep_until_update(float *time_frame, float *aq_sleep_time)
3182 int frame_time_remaining = 0;
3183 current_module="calc_sleep_time";
3185 *time_frame -= GetRelativeTime(); // reset timer
3187 if (sh_audio && !d_audio->eof) {
3188 float delay = audio_out->get_delay();
3189 mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "delay=%f\n", delay);
3191 if (autosync) {
3193 * Adjust this raw delay value by calculating the expected
3194 * delay for this frame and generating a new value which is
3195 * weighted between the two. The higher autosync is, the
3196 * closer to the delay value gets to that which "-nosound"
3197 * would have used, and the longer it will take for A/V
3198 * sync to settle at the right value (but it eventually will.)
3199 * This settling time is very short for values below 100.
3201 float predicted = sh_audio->delay / playback_speed + *time_frame;
3202 float difference = delay - predicted;
3203 delay = predicted + difference / (float)autosync;
3206 *time_frame = delay - sh_audio->delay / playback_speed;
3208 // delay = amount of audio buffered in soundcard/driver
3209 if (delay > 0.25) delay=0.25; else
3210 if (delay < 0.10) delay=0.10;
3211 if (*time_frame > delay*0.6) {
3212 // sleep time too big - may cause audio drops (buffer underrun)
3213 frame_time_remaining = 1;
3214 *time_frame = delay*0.5;
3216 } else {
3217 // If we're lagging more than 200 ms behind the right playback rate,
3218 // don't try to "catch up".
3219 // If benchmark is set always output frames as fast as possible
3220 // without sleeping.
3221 if (*time_frame < -0.2 || benchmark)
3222 *time_frame = 0;
3225 *aq_sleep_time += *time_frame;
3228 //============================== SLEEP: ===================================
3230 // flag 256 means: libvo driver does its timing (dvb card)
3231 if (*time_frame > 0.001 && !(vo_flags&256))
3232 *time_frame = timing_sleep(*time_frame);
3233 return frame_time_remaining;
3236 static int reinit_video_chain(void) {
3237 //================== Init VIDEO (codec & libvo) ==========================
3238 if(!fixed_vo || !(inited_flags&INITED_VO)){
3239 current_module="preinit_libvo";
3241 //shouldn't we set dvideo->id=-2 when we fail?
3242 vo_config_count=0;
3243 //if((video_out->preinit(vo_subdevice))!=0){
3244 if(!(video_out=init_best_video_out(video_driver_list))){
3245 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
3246 goto err_out;
3248 sh_video->video_out=video_out;
3249 inited_flags|=INITED_VO;
3252 current_module="init_video_filters";
3254 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
3255 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
3257 #ifdef HAVE_MENU
3258 if(use_menu) {
3259 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
3260 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
3261 if(!vf_menu) {
3262 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
3263 use_menu = 0;
3266 if(vf_menu)
3267 sh_video->vfilter=(void*)vf_menu;
3268 #endif
3270 #ifdef USE_ASS
3271 if(ass_enabled) {
3272 int i;
3273 int insert = 1;
3274 if (vf_settings)
3275 for (i = 0; vf_settings[i].name; ++i)
3276 if (strcmp(vf_settings[i].name, "ass") == 0) {
3277 insert = 0;
3278 break;
3280 if (insert) {
3281 extern vf_info_t vf_info_ass;
3282 vf_info_t* libass_vfs[] = {&vf_info_ass, NULL};
3283 char* vf_arg[] = {"auto", "1", NULL};
3284 vf_instance_t* vf_ass = vf_open_plugin(libass_vfs,sh_video->vfilter,"ass",vf_arg);
3285 if (vf_ass)
3286 sh_video->vfilter=(void*)vf_ass;
3287 else
3288 mp_msg(MSGT_CPLAYER,MSGL_ERR, "ASS: cannot add video filter\n");
3291 #endif
3293 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
3295 #ifdef USE_ASS
3296 if (ass_enabled)
3297 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_INIT_EOSD, ass_library);
3298 #endif
3300 current_module="init_video_codec";
3302 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
3303 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
3304 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
3306 if(!sh_video->inited){
3307 if(!fixed_vo) uninit_player(INITED_VO);
3308 goto err_out;
3311 inited_flags|=INITED_VCODEC;
3313 if (sh_video->codec)
3314 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", sh_video->codec->name);
3316 sh_video->last_pts = MP_NOPTS_VALUE;
3317 sh_video->num_buffered_pts = 0;
3318 sh_video->next_frame_time = 0;
3320 if(auto_quality>0){
3321 // Auto quality option enabled
3322 output_quality=get_video_quality_max(sh_video);
3323 if(auto_quality>output_quality) auto_quality=output_quality;
3324 else output_quality=auto_quality;
3325 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
3326 set_video_quality(sh_video,output_quality);
3329 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3331 current_module="init_vo";
3333 return 1;
3335 err_out:
3336 sh_video = d_video->sh = NULL;
3337 return 0;
3340 static double update_video(int *blit_frame)
3342 //-------------------- Decode a frame: -----------------------
3343 double frame_time;
3344 *blit_frame = 0; // Don't blit if we hit EOF
3345 if (!correct_pts) {
3346 unsigned char* start=NULL;
3347 void *decoded_frame;
3348 int drop_frame=0;
3349 int in_size;
3351 current_module = "video_read_frame";
3352 frame_time = sh_video->next_frame_time;
3353 in_size = video_read_frame(sh_video, &sh_video->next_frame_time,
3354 &start, force_fps);
3355 if (in_size < 0)
3356 return -1;
3357 if (in_size > max_framesize)
3358 max_framesize = in_size; // stats
3359 sh_video->timer += frame_time;
3360 if (sh_audio)
3361 sh_audio->delay -= frame_time;
3362 // video_read_frame can change fps (e.g. for ASF video)
3363 vo_fps = sh_video->fps;
3364 // check for frame-drop:
3365 current_module = "check_framedrop";
3366 if (sh_audio && !d_audio->eof) {
3367 static int dropped_frames;
3368 float delay = playback_speed*audio_out->get_delay();
3369 float d = delay-sh_audio->delay;
3370 // we should avoid dropping too many frames in sequence unless we
3371 // are too late. and we allow 100ms A-V delay here:
3372 if (d < -dropped_frames*frame_time-0.100 &&
3373 osd_function != OSD_PAUSE) {
3374 drop_frame = frame_dropping;
3375 ++drop_frame_cnt;
3376 ++dropped_frames;
3377 } else
3378 drop_frame = dropped_frames = 0;
3379 ++total_frame_cnt;
3381 update_subtitles();
3382 update_osd_msg();
3383 current_module = "decode_video";
3384 decoded_frame = decode_video(sh_video, start, in_size, drop_frame,
3385 sh_video->pts);
3386 current_module = "filter_video";
3387 *blit_frame = (decoded_frame && filter_video(sh_video, decoded_frame,
3388 sh_video->pts));
3390 else {
3391 if (!generate_video_frame(sh_video, d_video))
3392 return -1;
3393 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter,
3394 VFCTRL_GET_PTS, &sh_video->pts);
3395 if (sh_video->pts == MP_NOPTS_VALUE) {
3396 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts after filters MISSING\n");
3397 sh_video->pts = sh_video->last_pts;
3399 if (sh_video->last_pts == MP_NOPTS_VALUE)
3400 sh_video->last_pts= sh_video->pts;
3401 else if (sh_video->last_pts >= sh_video->pts) {
3402 sh_video->last_pts = sh_video->pts;
3403 mp_msg(MSGT_CPLAYER, MSGL_WARN, "pts value <= previous");
3405 frame_time = sh_video->pts - sh_video->last_pts;
3406 sh_video->last_pts = sh_video->pts;
3407 sh_video->timer += frame_time;
3408 if(sh_audio)
3409 sh_audio->delay -= frame_time;
3410 *blit_frame = 1;
3412 return frame_time;
3415 void pause_loop(void)
3417 mp_cmd_t* cmd;
3418 if (!quiet) {
3419 // Small hack to display the pause message on the OSD line.
3420 // The pause string is: "\n == PAUSE == \r" so we need to
3421 // take the first and the last char out
3422 if (term_osd && !sh_video) {
3423 char msg[128] = MSGTR_Paused;
3424 int mlen = strlen(msg);
3425 msg[mlen-1] = '\0';
3426 set_osd_msg(OSD_MSG_PAUSE, 1, 0, "%s", msg+1);
3427 update_osd_msg();
3428 } else
3429 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
3430 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_PAUSED\n");
3431 fflush(stdout);
3433 #ifdef HAVE_NEW_GUI
3434 if (use_gui)
3435 guiGetEvent(guiCEvent, (char *)guiSetPause);
3436 #endif
3437 if (video_out && sh_video && vo_config_count)
3438 video_out->control(VOCTRL_PAUSE, NULL);
3440 if (audio_out && sh_audio)
3441 audio_out->pause(); // pause audio, keep data if possible
3443 while ( (cmd = mp_input_get_cmd(20, 1, 1)) == NULL) {
3444 if (sh_video && video_out && vo_config_count)
3445 video_out->check_events();
3446 #ifdef HAVE_NEW_GUI
3447 if (use_gui) {
3448 guiEventHandling();
3449 guiGetEvent(guiReDraw, NULL);
3450 if (guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos))
3451 break;
3453 #endif
3454 #ifdef HAVE_MENU
3455 if (vf_menu)
3456 vf_menu_pause_update(vf_menu);
3457 #endif
3458 usec_sleep(20000);
3460 if (cmd && cmd->id == MP_CMD_PAUSE) {
3461 cmd = mp_input_get_cmd(0,1,0);
3462 mp_cmd_free(cmd);
3464 osd_function=OSD_PLAY;
3465 if (audio_out && sh_audio)
3466 audio_out->resume(); // resume audio
3467 if (video_out && sh_video && vo_config_count)
3468 video_out->control(VOCTRL_RESUME, NULL); // resume video
3469 (void)GetRelativeTime(); // ignore time that passed during pause
3470 #ifdef HAVE_NEW_GUI
3471 if (use_gui) {
3472 if (guiIntfStruct.Playing == guiSetStop)
3473 eof = 1;
3474 else
3475 guiGetEvent(guiCEvent, (char *)guiSetPlay);
3477 #endif
3481 int main(int argc,char* argv[]){
3484 char * mem_ptr;
3486 int file_format=DEMUXER_TYPE_UNKNOWN;
3488 // movie info:
3490 /* Flag indicating whether MPlayer should exit without playing anything. */
3491 int opt_exit = 0;
3493 //float a_frame=0; // Audio
3495 int i;
3496 char *tmp;
3498 int gui_no_filename=0;
3500 srand((int) time(NULL));
3502 InitTimer();
3504 mp_msg_init();
3506 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2006 MPlayer Team\n");
3507 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
3508 GetCpuCaps(&gCpuCaps);
3509 #ifdef ARCH_X86
3510 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
3511 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
3512 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
3513 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
3514 #ifdef RUNTIME_CPUDETECT
3515 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
3516 #else
3517 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
3518 #ifdef HAVE_MMX
3519 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
3520 #endif
3521 #ifdef HAVE_MMX2
3522 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
3523 #endif
3524 #ifdef HAVE_3DNOW
3525 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
3526 #endif
3527 #ifdef HAVE_3DNOWEX
3528 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
3529 #endif
3530 #ifdef HAVE_SSE
3531 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
3532 #endif
3533 #ifdef HAVE_SSE2
3534 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
3535 #endif
3536 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3537 #endif /* RUNTIME_CPUDETECT */
3538 #endif /* ARCH_X86 */
3540 #if defined(WIN32) && defined(USE_WIN32DLL)
3541 set_path_env();
3542 #endif /*WIN32 && USE_WIN32DLL*/
3544 #ifdef USE_TV
3545 tv_param_immediate = 1;
3546 #endif
3548 if (argc > 1 && argv[1] &&
3549 (!strcmp(argv[1], "-gui") || !strcmp(argv[1], "-nogui"))) {
3550 use_gui = !strcmp(argv[1], "-gui");
3551 } else
3552 if ( argv[0] )
3554 char *base = strrchr(argv[0], '/');
3555 if (!base)
3556 base = strrchr(argv[0], '\\');
3557 if (!base)
3558 base = argv[0];
3559 if(strstr(base, "gmplayer"))
3560 use_gui=1;
3563 mconfig = m_config_new();
3564 m_config_register_options(mconfig,mplayer_opts);
3565 // TODO : add something to let modules register their options
3566 mp_input_register_options(mconfig);
3567 parse_cfgfiles(mconfig);
3569 #ifdef HAVE_NEW_GUI
3570 if ( use_gui ) cfg_read();
3571 #endif
3573 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
3574 if(playtree == NULL)
3575 opt_exit = 1;
3576 else {
3577 playtree = play_tree_cleanup(playtree);
3578 if(playtree) {
3579 playtree_iter = play_tree_iter_new(playtree,mconfig);
3580 if(playtree_iter) {
3581 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
3582 play_tree_iter_free(playtree_iter);
3583 playtree_iter = NULL;
3585 filename = play_tree_iter_get_file(playtree_iter,1);
3590 #if defined(WIN32) && defined(HAVE_NEW_GUI)
3591 void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
3592 if(runningmplayer && filename && use_gui){
3593 COPYDATASTRUCT csData;
3594 char file[MAX_PATH];
3595 char *filepart = filename;
3596 if(GetFullPathName(filename, MAX_PATH, file, &filepart)){
3597 csData.dwData = 0;
3598 csData.cbData = strlen(file)*2;
3599 csData.lpData = file;
3600 SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData);
3603 #endif
3605 #ifdef WIN32
3606 if(proc_priority){
3607 int i;
3608 for(i=0; priority_presets_defs[i].name; i++){
3609 if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
3610 break;
3612 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",
3613 priority_presets_defs[i].name);
3614 SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
3616 #endif
3617 #ifndef HAVE_NEW_GUI
3618 if(use_gui){
3619 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
3620 use_gui=0;
3622 #else
3623 #ifndef WIN32
3624 if(use_gui && !vo_init()){
3625 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
3626 use_gui=0;
3628 #endif
3629 if (use_gui && playtree_iter){
3630 char cwd[PATH_MAX+2];
3631 // Free Playtree and Playtree-Iter as it's not used by the GUI.
3632 play_tree_iter_free(playtree_iter);
3633 playtree_iter=NULL;
3635 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
3637 strcat(cwd, "/");
3638 // Prefix relative paths with current working directory
3639 play_tree_add_bpf(playtree, cwd);
3641 // Import initital playtree into GUI.
3642 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
3644 #endif /* HAVE_NEW_GUI */
3646 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
3647 list_video_out();
3648 opt_exit = 1;
3651 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
3652 list_audio_out();
3653 opt_exit = 1;
3656 /* Check codecs.conf. */
3657 if(!codecs_file || !parse_codec_cfg(codecs_file)){
3658 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
3659 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
3660 if(!parse_codec_cfg(NULL)){
3661 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
3662 exit_player_with_rc(NULL, 0);
3664 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
3667 free( mem_ptr ); // release the buffer created by get_path()
3670 #if 0
3671 if(video_codec_list){
3672 int i;
3673 video_codec=video_codec_list[0];
3674 for(i=0;video_codec_list[i];i++)
3675 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
3677 #endif
3678 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
3679 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
3680 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODECS\n");
3681 list_codecs(1);
3682 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3683 opt_exit = 1;
3685 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
3686 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
3687 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODECS\n");
3688 list_codecs(0);
3689 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3690 opt_exit = 1;
3692 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
3693 vfm_help();
3694 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3695 opt_exit = 1;
3697 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
3698 afm_help();
3699 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3700 opt_exit = 1;
3702 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
3703 af_help();
3704 printf("\n");
3705 opt_exit = 1;
3707 #ifdef HAVE_X11
3708 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
3709 fstype_help();
3710 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3711 opt_exit = 1;
3713 #endif
3714 if((demuxer_name && strcmp(demuxer_name,"help")==0) ||
3715 (audio_demuxer_name && strcmp(audio_demuxer_name,"help")==0) ||
3716 (sub_demuxer_name && strcmp(sub_demuxer_name,"help")==0)){
3717 demuxer_help();
3718 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
3719 opt_exit = 1;
3721 if(list_properties) {
3722 m_properties_print_help_list(mp_properties);
3723 opt_exit = 1;
3726 if(opt_exit)
3727 exit_player(NULL);
3729 if (player_idle_mode && use_gui) {
3730 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NoIdleAndGui);
3731 exit_player_with_rc(NULL, 1);
3734 if(!filename && !player_idle_mode){
3735 if(!use_gui){
3736 // no file/vcd/dvd -> show HELP:
3737 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
3738 exit_player_with_rc(NULL, 0);
3739 } else gui_no_filename=1;
3742 // Many users forget to include command line in bugreports...
3743 if( mp_msg_test(MSGT_CPLAYER,MSGL_V) ){
3744 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
3745 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);
3746 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
3749 //------ load global data first ------
3751 // check font
3752 #ifdef HAVE_FREETYPE
3753 init_freetype();
3754 #endif
3755 #ifdef HAVE_FONTCONFIG
3756 if(!font_fontconfig)
3758 #endif
3759 #ifdef HAVE_BITMAP_FONT
3760 if(font_name){
3761 vo_font=read_font_desc(font_name,font_factor,verbose>1);
3762 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
3763 } else {
3764 // try default:
3765 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
3766 free(mem_ptr); // release the buffer created by get_path()
3767 if(!vo_font)
3768 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
3770 #endif
3771 #ifdef HAVE_FONTCONFIG
3773 #endif
3775 vo_init_osd();
3777 #ifdef USE_ASS
3778 ass_library = ass_init();
3779 #endif
3781 #ifdef HAVE_RTC
3782 if(!nortc)
3784 // seteuid(0); /* Can't hurt to try to get root here */
3785 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
3786 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
3787 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
3788 else {
3789 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
3791 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
3792 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
3793 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
3794 close (rtc_fd);
3795 rtc_fd = -1;
3796 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
3797 /* variable only by the root */
3798 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
3799 close (rtc_fd);
3800 rtc_fd = -1;
3801 } else
3802 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
3805 #ifdef HAVE_NEW_GUI
3806 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
3807 // and now ? -- Pontscho
3808 if(use_gui) setuid( getuid() ); // strongly test, please check this.
3809 #endif
3810 if(rtc_fd<0)
3811 #endif /* HAVE_RTC */
3812 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
3813 softsleep?"software":timer_name);
3815 #ifdef USE_TERMCAP
3816 if ( !use_gui ) load_termcap(NULL); // load key-codes
3817 #endif
3819 // ========== Init keyboard FIFO (connection to libvo) ============
3821 // Init input system
3822 current_module = "init_input";
3823 mp_input_init(use_gui);
3824 #if 0
3825 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
3827 if(keyb_fifo_get > 0)
3828 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
3829 #else
3830 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
3831 #endif
3832 if(slave_mode)
3833 #ifndef __MINGW32__
3834 mp_input_add_cmd_fd(0,1,NULL,NULL);
3835 #else
3836 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
3837 #endif
3838 else if(!noconsolecontrols)
3839 #ifndef HAVE_NO_POSIX_SELECT
3840 mp_input_add_key_fd(0,1,NULL,NULL);
3841 #else
3842 mp_input_add_key_fd(0,0,NULL,NULL);
3843 #endif
3845 inited_flags|=INITED_INPUT;
3846 current_module = NULL;
3848 #ifdef HAVE_MENU
3849 if(use_menu) {
3850 if(menu_cfg && menu_init(menu_cfg))
3851 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
3852 else {
3853 menu_cfg = get_path("menu.conf");
3854 if(menu_init(menu_cfg))
3855 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
3856 else {
3857 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
3858 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
3859 else {
3860 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
3861 use_menu = 0;
3866 #endif
3868 /// Catch signals
3869 #ifndef __MINGW32__
3870 signal(SIGCHLD,child_sighandler);
3871 #endif
3873 #ifdef CRASH_DEBUG
3874 prog_path = argv[0];
3875 #endif
3876 //========= Catch terminate signals: ================
3877 // terminate requests:
3878 signal(SIGTERM,exit_sighandler); // kill
3879 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
3881 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
3883 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
3884 signal(SIGPIPE,exit_sighandler); // Some window managers cause this
3885 #ifdef ENABLE_SIGHANDLER
3886 // fatal errors:
3887 signal(SIGBUS,exit_sighandler); // bus error
3888 signal(SIGSEGV,exit_sighandler); // segfault
3889 signal(SIGILL,exit_sighandler); // illegal instruction
3890 signal(SIGFPE,exit_sighandler); // floating point exc.
3891 signal(SIGABRT,exit_sighandler); // abort()
3892 #ifdef CRASH_DEBUG
3893 if (crash_debug)
3894 signal(SIGTRAP,exit_sighandler);
3895 #endif
3896 #endif
3898 #ifdef HAVE_NEW_GUI
3899 if(use_gui){
3900 guiInit();
3901 inited_flags|=INITED_GUI;
3902 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
3904 #endif
3906 // ******************* Now, let's see the per-file stuff ********************
3908 play_next_file:
3910 // init global sub numbers
3911 global_sub_size = 0;
3912 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
3914 if (filename) load_per_file_config (mconfig, filename);
3916 // We must enable getch2 here to be able to interrupt network connection
3917 // or cache filling
3918 if(!noconsolecontrols && !slave_mode){
3919 if(inited_flags&INITED_GETCH2)
3920 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
3921 else
3922 getch2_enable(); // prepare stdin for hotkeys...
3923 inited_flags|=INITED_GETCH2;
3924 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
3927 // =================== GUI idle loop (STOP state) ===========================
3928 #ifdef HAVE_NEW_GUI
3929 if ( use_gui ) {
3930 file_format=DEMUXER_TYPE_UNKNOWN;
3931 guiGetEvent( guiSetDefaults,0 );
3932 while ( guiIntfStruct.Playing != 1 )
3934 mp_cmd_t* cmd;
3935 usec_sleep(20000);
3936 guiEventHandling();
3937 guiGetEvent( guiReDraw,NULL );
3938 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
3940 guiGetEvent( guiSetParameters,NULL );
3941 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
3943 play_tree_t * entry = play_tree_new();
3944 play_tree_add_file( entry,guiIntfStruct.Filename );
3945 if ( playtree ) play_tree_free_list( playtree->child,1 );
3946 else playtree=play_tree_new();
3947 play_tree_set_child( playtree,entry );
3948 if(playtree)
3950 playtree_iter = play_tree_iter_new(playtree,mconfig);
3951 if(playtree_iter)
3953 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
3955 play_tree_iter_free(playtree_iter);
3956 playtree_iter = NULL;
3958 filename = play_tree_iter_get_file(playtree_iter,1);
3963 #endif /* HAVE_NEW_GUI */
3965 while (player_idle_mode && !filename) {
3966 play_tree_t * entry = NULL;
3967 mp_cmd_t * cmd;
3968 while (!(cmd = mp_input_get_cmd(0,1,0))) { // wait for command
3969 if (video_out && vo_config_count) video_out->check_events();
3970 usec_sleep(20000);
3972 switch (cmd->id) {
3973 case MP_CMD_LOADFILE:
3974 // prepare a tree entry with the new filename
3975 entry = play_tree_new();
3976 play_tree_add_file(entry, cmd->args[0].v.s);
3977 // The entry is added to the main playtree after the switch().
3978 break;
3979 case MP_CMD_LOADLIST:
3980 entry = parse_playlist_file(cmd->args[0].v.s);
3981 break;
3982 case MP_CMD_QUIT:
3983 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
3984 break;
3987 mp_cmd_free(cmd);
3989 if (entry) { // user entered a command that gave a valid entry
3990 if (playtree) // the playtree is always a node with one child. let's clear it
3991 play_tree_free_list(playtree->child, 1);
3992 else playtree=play_tree_new(); // .. or make a brand new playtree
3994 if (!playtree) continue; // couldn't make playtree! wait for next command
3996 play_tree_set_child(playtree, entry);
3998 /* Make iterator start at the top the of tree. */
3999 playtree_iter = play_tree_iter_new(playtree, mconfig);
4000 if (!playtree_iter) continue;
4002 // find the first real item in the tree
4003 if (play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
4004 // no items!
4005 play_tree_iter_free(playtree_iter);
4006 playtree_iter = NULL;
4007 continue; // wait for next command
4009 filename = play_tree_iter_get_file(playtree_iter, 1);
4012 //---------------------------------------------------------------------------
4014 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
4016 if (edl_filename) {
4017 if (edl_records) free_edl(edl_records);
4018 next_edl_record = edl_records = edl_parse_file();
4020 if (edl_output_filename) {
4021 if (edl_fd) fclose(edl_fd);
4022 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
4024 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
4025 edl_output_filename);
4029 //==================== Open VOB-Sub ============================
4031 current_module="vobsub";
4032 if (vobsub_name){
4033 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
4034 if(vo_vobsub==NULL)
4035 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
4036 }else if(sub_auto && filename && (strlen(filename)>=5)){
4037 /* try to autodetect vobsub from movie filename ::atmos */
4038 char *buf = malloc((strlen(filename)-3)),*psub;
4039 memset(buf,0,strlen(filename)-3); // make sure string is terminated
4040 strncpy(buf, filename, strlen(filename)-4);
4041 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
4042 /* try from ~/.mplayer/sub */
4043 if(!vo_vobsub && (psub = get_path( "sub/" ))) {
4044 char *bname;
4045 int l;
4046 bname = strrchr(buf,'/');
4047 #ifdef WIN32
4048 if(!bname) bname = strrchr(buf,'\\');
4049 #endif
4050 if(bname) bname++;
4051 else bname = buf;
4052 l = strlen(psub) + strlen(bname) + 1;
4053 psub = realloc(psub,l);
4054 strcat(psub,bname);
4055 vo_vobsub=vobsub_open(psub,spudec_ifo,0,&vo_spudec);
4056 free(psub);
4058 free(buf);
4060 if(vo_vobsub){
4061 inited_flags|=INITED_VOBSUB;
4062 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
4063 // check if vobsub requested only to display forced subtitles
4064 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
4066 // setup global sub numbering
4067 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
4068 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
4071 //============ Open & Sync STREAM --- fork cache2 ====================
4073 stream=NULL;
4074 demuxer=NULL;
4075 if (d_audio) {
4076 //free_demuxer_stream(d_audio);
4077 d_audio=NULL;
4079 if (d_video) {
4080 //free_demuxer_stream(d_video);
4081 d_video=NULL;
4083 sh_audio=NULL;
4084 sh_video=NULL;
4086 current_module="open_stream";
4087 stream=open_stream(filename,0,&file_format);
4088 if(!stream) { // error...
4089 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
4090 goto goto_next_file;
4092 inited_flags|=INITED_STREAM;
4094 #ifdef HAVE_NEW_GUI
4095 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
4096 #endif
4098 if(file_format == DEMUXER_TYPE_PLAYLIST) {
4099 play_tree_t* entry;
4100 // Handle playlist
4101 current_module="handle_playlist";
4102 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
4103 entry = parse_playtree(stream,0);
4104 eof=playtree_add_playlist(entry);
4105 goto goto_next_file;
4107 stream->start_pos+=seek_to_byte;
4109 if(stream_dump_type==5){
4110 unsigned char buf[4096];
4111 int len;
4112 FILE *f;
4113 current_module="dumpstream";
4114 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
4115 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
4116 exit_player(MSGTR_Exit_error);
4118 stream_reset(stream);
4119 stream_seek(stream,stream->start_pos);
4120 f=fopen(stream_dump_name,"wb");
4121 if(!f){
4122 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
4123 exit_player(MSGTR_Exit_error);
4125 while(!stream->eof){
4126 len=stream_read(stream,buf,4096);
4127 if(len>0) {
4128 if(fwrite(buf,len,1,f) != 1) {
4129 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
4130 exit_player(MSGTR_Exit_error);
4134 if(fclose(f)) {
4135 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
4136 exit_player(MSGTR_Exit_error);
4138 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
4139 exit_player_with_rc(MSGTR_Exit_eof, 0);
4142 #ifdef USE_DVDREAD
4143 if(stream->type==STREAMTYPE_DVD){
4144 current_module="dvd lang->id";
4145 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
4146 if(dvdsub_lang && dvdsub_id==-2) dvdsub_id=-1;
4147 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
4148 // setup global sub numbering
4149 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
4150 global_sub_size += dvd_number_of_subs(stream);
4151 current_module=NULL;
4153 #endif
4155 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
4156 goto_enable_cache:
4157 if(stream_cache_size>0){
4158 current_module="enable_cache";
4159 if(!stream_enable_cache(stream,stream_cache_size*1024,
4160 stream_cache_size*1024*(stream_cache_min_percent / 100.0),
4161 stream_cache_size*1024*(stream_cache_seek_min_percent / 100.0)))
4162 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
4165 //============ Open DEMUXERS --- DETECT file type =======================
4166 current_module="demux_open";
4168 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
4170 // HACK to get MOV Reference Files working
4172 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
4174 unsigned char* playlist_entry;
4175 play_tree_t *list = NULL, *entry = NULL;
4177 current_module="handle_demux_playlist";
4178 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
4180 char *temp, *bname;
4182 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
4184 bname=mp_basename(playlist_entry);
4185 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
4186 continue;
4188 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
4189 continue;
4191 entry = play_tree_new();
4193 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
4195 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1));
4196 if (temp)
4198 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
4199 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
4200 strcat(temp, playlist_entry);
4201 play_tree_add_file(entry,temp);
4202 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
4203 free(temp);
4206 else
4207 play_tree_add_file(entry,playlist_entry);
4209 if(!list)
4210 list = entry;
4211 else
4212 play_tree_append_entry(list,entry);
4214 free_demuxer(demuxer);
4215 demuxer = NULL;
4217 if (list)
4219 entry = play_tree_new();
4220 play_tree_set_child(entry,list);
4221 eof=playtree_add_playlist(entry);
4222 goto goto_next_file;
4226 if(!demuxer)
4228 #if 0
4229 play_tree_t* entry;
4230 // Handle playlist
4231 current_module="handle_playlist";
4232 switch(stream->type){
4233 case STREAMTYPE_VCD:
4234 case STREAMTYPE_DVD:
4235 case STREAMTYPE_CDDA:
4236 case STREAMTYPE_VCDBINCUE:
4237 // don't try to parse raw media as playlist, it's unlikely
4238 goto goto_next_file;
4240 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
4241 stream_reset(stream);
4242 stream_seek(stream,stream->start_pos);
4243 entry = parse_playtree(stream,0);
4244 if(!entry)
4245 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
4246 else
4247 eof=playtree_add_playlist(entry);
4248 #endif
4249 goto goto_next_file;
4251 inited_flags|=INITED_DEMUXER;
4253 if (stream->type != STREAMTYPE_DVD) {
4254 int i;
4255 // setup global sub numbering
4256 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
4257 for (i = 0; i < MAX_S_STREAMS; i++)
4258 if (demuxer->s_streams[i])
4259 global_sub_size++;
4262 current_module="demux_open2";
4264 //file_format=demuxer->file_format;
4266 d_audio=demuxer->audio;
4267 d_video=demuxer->video;
4268 d_dvdsub=demuxer->sub;
4270 // DUMP STREAMS:
4271 if((stream_dump_type)&&(stream_dump_type<4)){
4272 FILE *f;
4273 demux_stream_t *ds=NULL;
4274 current_module="dump";
4275 // select stream to dump
4276 switch(stream_dump_type){
4277 case 1: ds=d_audio;break;
4278 case 2: ds=d_video;break;
4279 case 3: ds=d_dvdsub;break;
4281 if(!ds){
4282 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
4283 exit_player(MSGTR_Exit_error);
4285 // disable other streams:
4286 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
4287 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
4288 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
4289 // let's dump it!
4290 f=fopen(stream_dump_name,"wb");
4291 if(!f){
4292 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
4293 exit_player(MSGTR_Exit_error);
4295 while(!ds->eof){
4296 unsigned char* start;
4297 int in_size=ds_get_packet(ds,&start);
4298 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
4299 && stream_dump_type==2) fwrite(&in_size,1,4,f);
4300 if(in_size>0) fwrite(start,in_size,1,f);
4302 fclose(f);
4303 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
4304 exit_player_with_rc(MSGTR_Exit_eof, 0);
4307 sh_audio=d_audio->sh;
4308 sh_video=d_video->sh;
4310 if(sh_video){
4312 current_module="video_read_properties";
4313 if(!video_read_properties(sh_video)) {
4314 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
4315 sh_video=d_video->sh=NULL;
4316 } else {
4317 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
4318 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
4319 sh_video->fps,sh_video->frametime
4322 /* need to set fps here for output encoders to pick it up in their init */
4323 if(force_fps){
4324 sh_video->fps=force_fps;
4325 sh_video->frametime=1.0f/sh_video->fps;
4327 vo_fps = sh_video->fps;
4329 if(!sh_video->fps && !force_fps){
4330 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
4331 sh_video=d_video->sh=NULL;
4337 fflush(stdout);
4339 if(!sh_video && !sh_audio){
4340 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
4341 #ifdef HAS_DVBIN_SUPPORT
4342 if((stream->type == STREAMTYPE_DVB) && stream->priv)
4344 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
4345 if(priv->is_on)
4347 int dir;
4348 int v = last_dvb_step;
4349 if(v > 0)
4350 dir = DVB_CHANNEL_HIGHER;
4351 else
4352 dir = DVB_CHANNEL_LOWER;
4354 if(dvb_step_channel(priv, dir))
4355 eof = dvbin_reopen = 1;
4358 #endif
4359 goto goto_next_file; // exit_player(MSGTR_Exit_error);
4362 /* display clip info */
4363 demux_info_print(demuxer);
4365 //================== Read SUBTITLES (DVD & TEXT) ==========================
4366 if(vo_spudec==NULL && sh_video &&
4367 (stream->type==STREAMTYPE_DVD || d_dvdsub->id >= 0)){
4368 init_vo_spudec();
4371 // Apply current settings for forced subs
4372 if (vo_spudec!=NULL)
4373 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
4375 if(sh_video) {
4376 // after reading video params we should load subtitles because
4377 // we know fps so now we can adjust subtitle time to ~6 seconds AST
4378 // check .sub
4379 current_module="read_subtitles_file";
4380 if(sub_name){
4381 for (i = 0; sub_name[i] != NULL; ++i)
4382 add_subtitles (sub_name[i], sh_video->fps, 0);
4384 if(sub_auto) { // auto load sub file ...
4385 char *psub = get_path( "sub/" );
4386 char **tmp = sub_filenames((psub ? psub : ""), filename);
4387 int i = 0;
4388 free(psub); // release the buffer created by get_path() above
4389 while (tmp[i]) {
4390 add_subtitles (tmp[i], sh_video->fps, 0);
4391 free(tmp[i++]);
4393 free(tmp);
4395 if (set_of_sub_size > 0) {
4396 // setup global sub numbering
4397 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
4398 global_sub_size += set_of_sub_size;
4402 if (global_sub_size) {
4403 // find the best sub to use
4404 if (vobsub_id >= 0) {
4405 // if user asks for a vobsub id, use that first.
4406 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
4407 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4408 // if user asks for a dvd sub id, use that next.
4409 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
4410 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
4411 // if there are text subs to use, use those. (autosubs come last here)
4412 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
4414 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4415 // if nothing else works, get subs from the demuxer.
4416 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
4418 } else {
4419 // nothing worth doing automatically.
4420 global_sub_pos = -1;
4422 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
4423 global_sub_pos--;
4424 mp_property_do("sub",M_PROPERTY_STEP_UP,NULL);
4425 if(subdata)
4426 switch (stream_dump_type) {
4427 case 3: list_sub_file(subdata); break;
4428 case 4: dump_mpsub(subdata, sh_video->fps); break;
4429 case 6: dump_srt(subdata, sh_video->fps); break;
4430 case 7: dump_microdvd(subdata, sh_video->fps); break;
4431 case 8: dump_jacosub(subdata, sh_video->fps); break;
4432 case 9: dump_sami(subdata, sh_video->fps); break;
4436 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n", filename);
4437 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_DEMUXER=%s\n", demuxer->desc->name);
4438 if (sh_video) {
4439 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4440 if (sh_video->format >= 0x20202020)
4441 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video->format);
4442 else
4443 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
4444 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
4445 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
4446 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
4447 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
4448 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
4450 if (sh_audio) {
4451 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4452 if (sh_audio->format >= 0x20202020)
4453 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio->format);
4454 else
4455 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
4456 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
4457 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
4458 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
4460 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
4462 if(!sh_video) goto main; // audio-only
4464 if(!reinit_video_chain()) {
4465 if(!sh_video){
4466 if(!sh_audio) goto goto_next_file;
4467 goto main; // exit_player(MSGTR_Exit_error);
4471 if(vo_flags & 0x08 && vo_spudec)
4472 spudec_set_hw_spu(vo_spudec,video_out);
4474 #ifdef HAVE_FREETYPE
4475 force_load_font = 1;
4476 #endif
4478 //================== MAIN: ==========================
4479 main:
4480 current_module="main";
4482 if(playing_msg) {
4483 char* msg = m_properties_expand_string(mp_properties,playing_msg);
4484 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",msg);
4485 free(msg);
4489 // Disable the term OSD in verbose mode
4490 if(verbose) term_osd = 0;
4491 fflush(stdout);
4494 //int frame_corr_num=0; //
4495 //float v_frame=0; // Video
4496 float time_frame=0; // Timer
4497 //float num_frames=0; // number of frames played
4498 int grab_frames=0;
4500 int frame_time_remaining=0; // flag
4501 int blit_frame=0;
4502 int was_paused=0;
4504 // Make sure old OSD does not stay around,
4505 // e.g. with -fixed-vo and same-resolution files
4506 clear_osd_msgs();
4507 update_osd_msg();
4509 //================ SETUP AUDIO ==========================
4511 if(sh_audio){
4512 reinit_audio_chain();
4513 if (sh_audio && sh_audio->codec)
4514 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
4517 current_module="av_init";
4519 if(sh_video){
4520 sh_video->timer=0;
4521 if (! ignore_start)
4522 audio_delay += sh_video->stream_delay;
4524 if(sh_audio){
4525 if (! ignore_start)
4526 audio_delay -= sh_audio->stream_delay;
4527 sh_audio->delay=-audio_delay;
4530 if(!sh_audio){
4531 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
4532 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
4533 ds_free_packs(d_audio); // free buffered chunks
4534 //d_audio->id=-2; // do not read audio chunks
4535 //uninit_player(INITED_AO); // close device
4537 if(!sh_video){
4538 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
4539 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
4540 ds_free_packs(d_video);
4541 d_video->id=-2;
4542 //if(!fixed_vo) uninit_player(INITED_VO);
4545 if (!sh_video && !sh_audio)
4546 goto goto_next_file;
4548 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4549 if(force_fps && sh_video){
4550 vo_fps = sh_video->fps=force_fps;
4551 sh_video->frametime=1.0f/sh_video->fps;
4552 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
4555 #ifdef HAVE_NEW_GUI
4556 if ( use_gui ) {
4557 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
4558 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
4559 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
4560 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
4561 guiGetEvent( guiSetDemuxer,(char *)demuxer );
4563 #endif
4565 //==================== START PLAYING =======================
4567 if(loop_times>1) loop_times--; else
4568 if(loop_times==1) loop_times = -1;
4570 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
4572 total_time_usage_start=GetTimer();
4573 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
4574 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
4575 play_n_frames=play_n_frames_mf;
4577 if(play_n_frames==0){
4578 eof=PT_NEXT_ENTRY; goto goto_next_file;
4581 while(!eof){
4582 float aq_sleep_time=0;
4583 if(!sh_audio && d_audio->sh) {
4584 sh_audio = d_audio->sh;
4585 sh_audio->ds = d_audio;
4586 reinit_audio_chain();
4589 /*========================== PLAY AUDIO ============================*/
4591 if (sh_audio)
4592 if (!fill_audio_out_buffers())
4593 // at eof, all audio at least written to ao
4594 if (!sh_video)
4595 eof = PT_NEXT_ENTRY;
4598 if(!sh_video) {
4599 // handle audio-only case:
4600 double a_pos=0;
4601 if(!quiet || end_at.type == END_AT_TIME )
4602 a_pos = playing_audio_pts(sh_audio, d_audio, audio_out);
4604 if(!quiet)
4605 print_status(a_pos, 0, 0);
4607 if(end_at.type == END_AT_TIME && end_at.pos < a_pos)
4608 eof = PT_NEXT_ENTRY;
4609 update_osd_msg();
4611 } else {
4613 /*========================== PLAY VIDEO ============================*/
4615 vo_pts=sh_video->timer*90000.0;
4616 vo_fps=sh_video->fps;
4618 if (!frame_time_remaining) {
4619 double frame_time = update_video(&blit_frame);
4620 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
4621 if (sh_video->vf_inited < 0) {
4622 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NotInitializeVOPorVO);
4623 eof = 1; goto goto_next_file;
4625 if (frame_time < 0)
4626 eof = 1;
4627 else
4628 time_frame += frame_time / playback_speed; // for nosound
4631 // ==========================================================================
4633 // current_module="draw_osd";
4634 // if(vo_config_count) video_out->draw_osd();
4636 #ifdef HAVE_NEW_GUI
4637 if(use_gui) guiEventHandling();
4638 #endif
4640 current_module="vo_check_events";
4641 if (vo_config_count) video_out->check_events();
4643 #ifdef HAVE_X11
4644 if (stop_xscreensaver) {
4645 current_module = "stop_xscreensaver";
4646 xscreensaver_heartbeat();
4648 #endif
4650 frame_time_remaining = sleep_until_update(&time_frame, &aq_sleep_time);
4652 //====================== FLIP PAGE (VIDEO BLT): =========================
4654 current_module="flip_page";
4655 if (!frame_time_remaining && blit_frame) {
4656 unsigned int t2=GetTimer();
4658 if(vo_config_count) video_out->flip_page();
4660 vout_time_usage += (GetTimer() - t2) * 0.000001;
4662 //====================== A-V TIMESTAMP CORRECTION: =========================
4664 adjust_sync_and_print_status(frame_time_remaining, time_frame);
4666 //============================ Auto QUALITY ============================
4668 /*Output quality adjustments:*/
4669 if(auto_quality>0){
4670 current_module="autoq";
4671 // float total=0.000001f * (GetTimer()-aq_total_time);
4672 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4673 if(output_quality<auto_quality && aq_sleep_time>0)
4674 ++output_quality;
4675 else
4676 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4677 if(output_quality>1 && aq_sleep_time<0)
4678 --output_quality;
4679 else
4680 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
4681 output_quality=0;
4682 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4683 set_video_quality(sh_video,output_quality);
4686 if (play_n_frames >= 0 && !frame_time_remaining && blit_frame) {
4687 --play_n_frames;
4688 if (play_n_frames <= 0) eof = PT_NEXT_ENTRY;
4692 // FIXME: add size based support for -endpos
4693 if (end_at.type == END_AT_TIME &&
4694 !frame_time_remaining && end_at.pos <= sh_video->pts)
4695 eof = PT_NEXT_ENTRY;
4697 } // end if(sh_video)
4699 //============================ Handle PAUSE ===============================
4701 current_module="pause";
4703 if(osd_visible){
4704 // 36000000 means max timed visibility is 1 hour into the future, if
4705 // the difference is greater assume it's wrapped around from below 0
4706 if (osd_visible - GetTimerMS() > 36000000) {
4707 osd_visible = 0;
4708 vo_osd_progbar_type=-1; // disable
4709 vo_osd_changed(OSDTYPE_PROGBAR);
4710 if (osd_function != OSD_PAUSE)
4711 osd_function = OSD_PLAY;
4715 if (osd_function == OSD_PAUSE) {
4716 pause_loop();
4717 was_paused = 1;
4720 // handle -sstep
4721 if(step_sec>0) {
4722 osd_function=OSD_FFW;
4723 rel_seek_secs+=step_sec;
4726 //================= EDL =========================================
4728 if( next_edl_record ) { // Are we (still?) doing EDL?
4729 if ( !sh_video ) {
4730 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
4731 free_edl(edl_records);
4732 next_edl_record = NULL;
4733 edl_records = NULL;
4734 } else {
4735 if( sh_video->pts >= next_edl_record->start_sec ) {
4736 if( next_edl_record->action == EDL_SKIP ) {
4737 osd_function = OSD_FFW;
4738 abs_seek_pos = 0;
4739 rel_seek_secs = next_edl_record->length_sec;
4740 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 );
4741 edl_decision = 1;
4742 } else if( next_edl_record->action == EDL_MUTE ) {
4743 edl_muted = !edl_muted;
4744 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
4745 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
4747 next_edl_record=next_edl_record->next;
4752 //================= Keyboard events, SEEKing ====================
4754 current_module="key_events";
4757 mp_cmd_t* cmd;
4758 int brk_cmd = 0;
4759 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
4760 if(!set_property_command(cmd))
4761 switch(cmd->id) {
4762 case MP_CMD_SEEK : {
4763 float v;
4764 int abs;
4765 if(sh_video)
4766 osd_show_percentage = sh_video->fps;
4767 v = cmd->args[0].v.f;
4768 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
4769 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
4770 abs_seek_pos = 1;
4771 if(sh_video)
4772 osd_function= (v > sh_video->pts) ? OSD_FFW : OSD_REW;
4773 rel_seek_secs = v;
4775 else if(abs) { /* Absolute seek by percentage */
4776 abs_seek_pos = 3;
4777 if(sh_video)
4778 osd_function= OSD_FFW; // Direction isn't set correctly
4779 rel_seek_secs = v/100.0;
4781 else {
4782 rel_seek_secs+= v;
4783 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
4785 brk_cmd = 1;
4786 } break;
4787 case MP_CMD_SET_PROPERTY: {
4788 m_option_t* prop = mp_property_find(cmd->args[0].v.s);
4789 if(!prop) mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unknown property: '%s'\n",cmd->args[0].v.s);
4790 else if(m_property_parse(prop,cmd->args[1].v.s) <= 0)
4791 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to set property '%s' to '%s'.\n",
4792 cmd->args[0].v.s,cmd->args[1].v.s);
4794 } break;
4795 case MP_CMD_STEP_PROPERTY: {
4796 m_option_t* prop = mp_property_find(cmd->args[0].v.s);
4797 float arg = cmd->args[1].v.f;
4798 if(!prop) mp_msg(MSGT_CPLAYER,MSGL_WARN, "Unknown property: '%s'\n",cmd->args[0].v.s);
4799 else if(m_property_do(prop,M_PROPERTY_STEP_UP, arg ? &arg : NULL) <= 0)
4800 mp_msg(MSGT_CPLAYER,MSGL_WARN, "Failed to increment property '%s' by %f.\n",cmd->args[0].v.s, arg);
4801 } break;
4802 case MP_CMD_GET_PROPERTY: {
4803 m_option_t* prop;
4804 void* val;
4805 prop = mp_property_find(cmd->args[0].v.s);
4806 if(!prop) {
4807 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unknown property: '%s'\n",cmd->args[0].v.s);
4808 break;
4810 /* Use m_option_print directly to get easily parseable values. */
4811 val = calloc(1,prop->type->size);
4812 if(m_property_do(prop,M_PROPERTY_GET,val) <= 0) {
4813 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to get value of property '%s'.\n",
4814 cmd->args[0].v.s);
4815 break;
4817 tmp = m_option_print(prop,val);
4818 if(!tmp || tmp == (char*)-1) {
4819 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to print value of property '%s'.\n",
4820 cmd->args[0].v.s);
4821 break;
4823 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_%s=%s\n",cmd->args[0].v.s,tmp);
4824 free(tmp);
4825 } break;
4826 case MP_CMD_EDL_MARK:
4827 if( edl_fd ) {
4828 float v = sh_video ? sh_video->pts :
4829 playing_audio_pts(sh_audio, d_audio, audio_out);
4831 if(begin_skip == MP_NOPTS_VALUE)
4833 begin_skip = v;
4834 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
4835 }else{
4836 if(begin_skip > v)
4838 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
4839 }else{
4840 fprintf(edl_fd, "%f %f %d\n", begin_skip, v, 0);
4841 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
4843 begin_skip = MP_NOPTS_VALUE;
4846 break;
4847 case MP_CMD_SWITCH_RATIO : {
4848 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
4849 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
4850 else
4851 movie_aspect = cmd->args[0].v.f;
4852 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
4853 } break;
4854 case MP_CMD_SPEED_INCR : {
4855 float v = cmd->args[0].v.f;
4856 playback_speed += v;
4857 build_afilter_chain(sh_audio, &ao_data);
4858 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4859 } break;
4860 case MP_CMD_SPEED_MULT : {
4861 float v = cmd->args[0].v.f;
4862 playback_speed *= v;
4863 build_afilter_chain(sh_audio, &ao_data);
4864 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4865 } break;
4866 case MP_CMD_SPEED_SET : {
4867 float v = cmd->args[0].v.f;
4868 playback_speed = v;
4869 build_afilter_chain(sh_audio, &ao_data);
4870 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4871 } break;
4872 case MP_CMD_FRAME_STEP :
4873 case MP_CMD_PAUSE : {
4874 cmd->pausing = 1;
4875 brk_cmd = 1;
4876 } break;
4877 case MP_CMD_FILE_FILTER : {
4878 file_filter = cmd->args[0].v.i;
4879 break;
4881 case MP_CMD_QUIT : {
4882 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
4884 case MP_CMD_GRAB_FRAMES : {
4885 grab_frames=2;
4886 } break;
4887 case MP_CMD_PLAY_TREE_STEP : {
4888 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
4889 int force = cmd->args[1].v.i;
4891 #ifdef HAVE_NEW_GUI
4892 if (use_gui) {
4893 int i=0;
4894 if (n>0)
4895 for (i=0;i<n;i++)
4896 mplNext();
4897 else
4898 for (i=0;i<-1*n;i++)
4899 mplPrev();
4900 } else
4901 #endif
4903 if(!force && playtree_iter) {
4904 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
4906 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
4907 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
4908 play_tree_iter_free(i);
4909 } else
4910 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
4911 if(eof)
4912 play_tree_step = n;
4913 brk_cmd = 1;
4915 } break;
4916 case MP_CMD_PLAY_TREE_UP_STEP : {
4917 int n = cmd->args[0].v.i > 0 ? 1 : -1;
4918 int force = cmd->args[1].v.i;
4920 if(!force && playtree_iter) {
4921 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
4922 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
4923 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
4924 play_tree_iter_free(i);
4925 } else
4926 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
4927 brk_cmd = 1;
4928 } break;
4929 case MP_CMD_PLAY_ALT_SRC_STEP : {
4930 if(playtree_iter && playtree_iter->num_files > 1) {
4931 int v = cmd->args[0].v.i;
4932 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
4933 eof = PT_NEXT_SRC;
4934 else if(v < 0 && playtree_iter->file > 1)
4935 eof = PT_PREV_SRC;
4937 brk_cmd = 1;
4938 } break;
4939 case MP_CMD_SUB_STEP : {
4940 if (sh_video) {
4941 int movement = cmd->args[0].v.i;
4942 step_sub(subdata, sh_video->pts, movement);
4943 #ifdef USE_ASS
4944 if (ass_track)
4945 sub_delay += ass_step_sub(ass_track, (sh_video->pts + sub_delay) * 1000 + .5, movement) / 1000.;
4946 #endif
4947 set_osd_msg(OSD_MSG_SUB_DELAY,1,osd_duration,
4948 MSGTR_OSDSubDelay, ROUND(sub_delay*1000));
4950 } break;
4951 case MP_CMD_SUB_LOG : {
4952 log_sub();
4953 } break;
4954 case MP_CMD_OSD : {
4955 int v = cmd->args[0].v.i;
4956 int max = (term_osd && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
4957 if(osd_level > max) osd_level = max;
4958 if(v < 0)
4959 osd_level=(osd_level+1)%(max+1);
4960 else
4961 osd_level= v > max ? max : v;
4962 /* Show OSD state when disabled, but not when an explicit
4963 argument is given to the OSD command, i.e. in slave mode. */
4964 if (v == -1 && osd_level <= 1)
4965 set_osd_msg(OSD_MSG_OSD_STATUS,0,osd_duration,
4966 MSGTR_OSDosd, osd_level ? MSGTR_OSDenabled : MSGTR_OSDdisabled);
4967 else
4968 rm_osd_msg(OSD_MSG_OSD_STATUS);
4969 } break;
4970 case MP_CMD_OSD_SHOW_TEXT : {
4971 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
4972 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
4973 "%-.63s",cmd->args[0].v.s);
4974 } break;
4975 case MP_CMD_OSD_SHOW_PROPERTY_TEXT : {
4976 char* txt = m_properties_expand_string(mp_properties,cmd->args[0].v.s);
4977 /* if no argument supplied take default osd_duration, else <arg> ms. */
4978 if(txt) {
4979 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
4980 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
4981 "%-.63s",txt);
4982 free(txt);
4984 } break;
4985 case MP_CMD_LOADFILE : {
4986 play_tree_t* e = play_tree_new();
4987 play_tree_add_file(e,cmd->args[0].v.s);
4989 if (cmd->args[1].v.i) // append
4990 play_tree_append_entry(playtree, e);
4991 else {
4992 // Go back to the starting point.
4993 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
4994 /* NOP */;
4995 play_tree_free_list(playtree->child,1);
4996 play_tree_set_child(playtree,e);
4997 play_tree_iter_step(playtree_iter,0,0);
4998 eof = PT_NEXT_SRC;
5000 brk_cmd = 1;
5001 } break;
5002 case MP_CMD_LOADLIST : {
5003 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
5004 if(!e)
5005 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
5006 else {
5007 if (cmd->args[1].v.i) // append
5008 play_tree_append_entry(playtree, e);
5009 else {
5010 // Go back to the starting point.
5011 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
5012 /* NOP */;
5013 play_tree_free_list(playtree->child,1);
5014 play_tree_set_child(playtree,e);
5015 play_tree_iter_step(playtree_iter,0,0);
5016 eof = PT_NEXT_SRC;
5019 brk_cmd = 1;
5020 } break;
5021 #ifdef USE_RADIO
5022 case MP_CMD_RADIO_STEP_CHANNEL : {
5023 if (demuxer->stream->type==STREAMTYPE_RADIO) {
5024 int v = cmd->args[0].v.i;
5025 if(v > 0)
5026 radio_step_channel(demuxer->stream, RADIO_CHANNEL_HIGHER);
5027 else
5028 radio_step_channel(demuxer->stream, RADIO_CHANNEL_LOWER);
5029 if (radio_get_channel_name(demuxer->stream)) {
5030 set_osd_msg(OSD_MSG_RADIO_CHANNEL,1,osd_duration,
5031 MSGTR_OSDChannel, radio_get_channel_name(demuxer->stream));
5034 } break;
5035 case MP_CMD_RADIO_SET_CHANNEL : {
5036 if (demuxer->stream->type== STREAMTYPE_RADIO) {
5037 radio_set_channel(demuxer->stream, cmd->args[0].v.s);
5038 if (radio_get_channel_name(demuxer->stream)) {
5039 set_osd_msg(OSD_MSG_RADIO_CHANNEL,1,osd_duration,
5040 MSGTR_OSDChannel, radio_get_channel_name(demuxer->stream));
5043 } break;
5044 case MP_CMD_RADIO_SET_FREQ : {
5045 if (demuxer->stream->type== STREAMTYPE_RADIO)
5046 radio_set_freq(demuxer->stream, cmd->args[0].v.f);
5047 } break;
5048 case MP_CMD_RADIO_STEP_FREQ :
5049 if (demuxer->stream->type == STREAMTYPE_RADIO){
5050 radio_step_freq(demuxer->stream, cmd->args[0].v.f);
5052 break;
5053 #endif
5054 #ifdef USE_TV
5055 case MP_CMD_TV_SET_FREQ : {
5056 if (file_format == DEMUXER_TYPE_TV)
5057 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
5058 } break;
5059 case MP_CMD_TV_SET_NORM : {
5060 if (file_format == DEMUXER_TYPE_TV)
5061 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
5062 } break;
5063 case MP_CMD_TV_STEP_CHANNEL : {
5064 if (file_format == DEMUXER_TYPE_TV) {
5065 int v = cmd->args[0].v.i;
5066 if(v > 0){
5067 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
5068 } else {
5069 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
5071 if (tv_channel_list) {
5072 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
5073 MSGTR_OSDChannel, tv_channel_current->name);
5074 //vo_osd_changed(OSDTYPE_SUBTITLE);
5078 #ifdef HAS_DVBIN_SUPPORT
5079 if((stream->type == STREAMTYPE_DVB) && stream->priv)
5081 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
5082 if(priv->is_on)
5084 int dir;
5085 int v = cmd->args[0].v.i;
5087 last_dvb_step = v;
5088 if(v > 0)
5089 dir = DVB_CHANNEL_HIGHER;
5090 else
5091 dir = DVB_CHANNEL_LOWER;
5094 if(dvb_step_channel(priv, dir))
5095 eof = dvbin_reopen = 1;
5098 #endif /* HAS_DVBIN_SUPPORT */
5099 break;
5100 case MP_CMD_TV_SET_CHANNEL : {
5101 if (file_format == DEMUXER_TYPE_TV) {
5102 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
5103 if (tv_channel_list) {
5104 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
5105 MSGTR_OSDChannel, tv_channel_current->name);
5106 //vo_osd_changed(OSDTYPE_SUBTITLE);
5109 } break;
5110 #ifdef HAS_DVBIN_SUPPORT
5111 case MP_CMD_DVB_SET_CHANNEL:
5113 if((stream->type == STREAMTYPE_DVB) && stream->priv)
5115 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
5116 if(priv->is_on)
5118 if(priv->list->current <= cmd->args[0].v.i)
5119 last_dvb_step = 1;
5120 else
5121 last_dvb_step = -1;
5123 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
5124 eof = dvbin_reopen = 1;
5128 break;
5129 #endif /* HAS_DVBIN_SUPPORT */
5130 case MP_CMD_TV_LAST_CHANNEL : {
5131 if (file_format == DEMUXER_TYPE_TV) {
5132 tv_last_channel((tvi_handle_t*)(demuxer->priv));
5133 if (tv_channel_list) {
5134 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
5135 MSGTR_OSDChannel, tv_channel_current->name);
5136 //vo_osd_changed(OSDTYPE_SUBTITLE);
5139 } break;
5140 case MP_CMD_TV_STEP_NORM : {
5141 if (file_format == DEMUXER_TYPE_TV)
5142 tv_step_norm((tvi_handle_t*)(demuxer->priv));
5143 } break;
5144 case MP_CMD_TV_STEP_CHANNEL_LIST : {
5145 if (file_format == DEMUXER_TYPE_TV)
5146 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
5147 } break;
5148 #endif /* USE_TV */
5149 case MP_CMD_SUB_LOAD:
5151 if (sh_video) {
5152 int n = set_of_sub_size;
5153 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
5154 if (n != set_of_sub_size) {
5155 if (global_sub_indices[SUB_SOURCE_SUBS] < 0)
5156 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size;
5157 ++global_sub_size;
5160 } break;
5161 case MP_CMD_SUB_REMOVE:
5163 if (sh_video) {
5164 int v = cmd->args[0].v.i;
5165 sub_data *subd;
5166 if (v < 0) {
5167 for (v = 0; v < set_of_sub_size; ++v) {
5168 subd = set_of_subtitles[v];
5169 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
5170 sub_free(subd);
5171 set_of_subtitles[v] = NULL;
5173 global_sub_indices[SUB_SOURCE_SUBS] = -1;
5174 global_sub_size -= set_of_sub_size;
5175 set_of_sub_size = 0;
5176 if (set_of_sub_pos >= 0) {
5177 global_sub_pos = -2;
5178 vo_sub_last = vo_sub = NULL;
5179 vo_osd_changed(OSDTYPE_SUBTITLE);
5180 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
5181 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5184 else if (v < set_of_sub_size) {
5185 subd = set_of_subtitles[v];
5186 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
5187 sub_free(subd);
5188 if (set_of_sub_pos == v) {
5189 global_sub_pos = -2;
5190 vo_sub_last = vo_sub = NULL;
5191 vo_osd_changed(OSDTYPE_SUBTITLE);
5192 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
5193 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5195 else if (set_of_sub_pos > v) {
5196 --set_of_sub_pos;
5197 --global_sub_pos;
5199 while (++v < set_of_sub_size)
5200 set_of_subtitles[v - 1] = set_of_subtitles[v];
5201 --set_of_sub_size;
5202 --global_sub_size;
5203 if (set_of_sub_size <= 0)
5204 global_sub_indices[SUB_SOURCE_SUBS] = -1;
5205 set_of_subtitles[set_of_sub_size] = NULL;
5208 } break;
5209 case MP_CMD_GET_SUB_VISIBILITY:
5211 if (sh_video) {
5212 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
5214 } break;
5215 case MP_CMD_SCREENSHOT :
5216 if(vo_config_count){
5217 mp_msg(MSGT_CPLAYER,MSGL_INFO,"sending VFCTRL_SCREENSHOT!\n");
5218 if(CONTROL_OK!=((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SCREENSHOT, &cmd->args[0].v.i))
5219 video_out->control(VOCTRL_SCREENSHOT, NULL);
5221 break;
5222 case MP_CMD_VF_CHANGE_RECTANGLE:
5223 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
5224 break;
5226 case MP_CMD_GET_TIME_LENGTH : {
5227 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
5228 } break;
5230 case MP_CMD_GET_FILENAME : {
5231 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_FILENAME='%s'\n", get_metadata (META_NAME));
5232 } break;
5234 case MP_CMD_GET_VIDEO_CODEC : {
5235 char *inf = get_metadata (META_VIDEO_CODEC);
5236 if (!inf) inf = strdup ("");
5237 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
5238 free (inf);
5239 } break;
5241 case MP_CMD_GET_VIDEO_BITRATE : {
5242 char *inf = get_metadata (META_VIDEO_BITRATE);
5243 if (!inf) inf = strdup ("");
5244 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
5245 free (inf);
5246 } break;
5248 case MP_CMD_GET_VIDEO_RESOLUTION : {
5249 char *inf = get_metadata (META_VIDEO_RESOLUTION);
5250 if (!inf) inf = strdup ("");
5251 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
5252 free (inf);
5253 } break;
5255 case MP_CMD_GET_AUDIO_CODEC : {
5256 char *inf = get_metadata (META_AUDIO_CODEC);
5257 if (!inf) inf = strdup ("");
5258 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
5259 free (inf);
5260 } break;
5262 case MP_CMD_GET_AUDIO_BITRATE : {
5263 char *inf = get_metadata (META_AUDIO_BITRATE);
5264 if (!inf) inf = strdup ("");
5265 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
5266 free (inf);
5267 } break;
5269 case MP_CMD_GET_AUDIO_SAMPLES : {
5270 char *inf = get_metadata (META_AUDIO_SAMPLES);
5271 if (!inf) inf = strdup ("");
5272 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
5273 free (inf);
5274 } break;
5276 case MP_CMD_GET_META_TITLE : {
5277 char *inf = get_metadata (META_INFO_TITLE);
5278 if (!inf) inf = strdup ("");
5279 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
5280 free (inf);
5281 } break;
5283 case MP_CMD_GET_META_ARTIST : {
5284 char *inf = get_metadata (META_INFO_ARTIST);
5285 if (!inf) inf = strdup ("");
5286 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
5287 free (inf);
5288 } break;
5290 case MP_CMD_GET_META_ALBUM : {
5291 char *inf = get_metadata (META_INFO_ALBUM);
5292 if (!inf) inf = strdup ("");
5293 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
5294 free (inf);
5295 } break;
5297 case MP_CMD_GET_META_YEAR : {
5298 char *inf = get_metadata (META_INFO_YEAR);
5299 if (!inf) inf = strdup ("");
5300 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
5301 free (inf);
5302 } break;
5304 case MP_CMD_GET_META_COMMENT : {
5305 char *inf = get_metadata (META_INFO_COMMENT);
5306 if (!inf) inf = strdup ("");
5307 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
5308 free (inf);
5309 } break;
5311 case MP_CMD_GET_META_TRACK : {
5312 char *inf = get_metadata (META_INFO_TRACK);
5313 if (!inf) inf = strdup ("");
5314 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
5315 free (inf);
5316 } break;
5318 case MP_CMD_GET_META_GENRE : {
5319 char *inf = get_metadata (META_INFO_GENRE);
5320 if (!inf) inf = strdup ("");
5321 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
5322 free (inf);
5323 } break;
5325 case MP_CMD_GET_VO_FULLSCREEN : {
5326 if(video_out && vo_config_count)
5327 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
5328 } break;
5330 case MP_CMD_GET_PERCENT_POS : {
5331 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer));
5332 } break;
5333 case MP_CMD_GET_TIME_POS : {
5334 float pos = 0;
5335 if (sh_video)
5336 pos = sh_video->pts;
5337 else
5338 if (sh_audio && audio_out)
5339 pos = playing_audio_pts(sh_audio, d_audio, audio_out);
5340 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
5341 } break;
5342 case MP_CMD_RUN : {
5343 #ifndef __MINGW32__
5344 if(!fork()) {
5345 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
5346 exit(0);
5348 #endif
5349 } break;
5350 case MP_CMD_KEYDOWN_EVENTS : {
5351 mplayer_put_key(cmd->args[0].v.i);
5352 } break;
5353 case MP_CMD_SEEK_CHAPTER : {
5354 int seek = cmd->args[0].v.i;
5355 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
5356 int chap;
5357 float next_pts = 0;
5358 int num_chapters;
5359 char *chapter_name;
5361 rel_seek_secs = 0;
5362 abs_seek_pos = 0;
5363 chap = demuxer_seek_chapter(demuxer, seek, abs, &next_pts, &num_chapters, &chapter_name);
5364 if(chap != -1) {
5365 if(next_pts > -1.0) {
5366 abs_seek_pos = 1;
5367 rel_seek_secs = next_pts;
5369 if(chapter_name) {
5370 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter,
5371 chap+1, chapter_name);
5372 free(chapter_name);
5374 } else {
5375 if (seek > 0)
5376 rel_seek_secs = 1000000000.;
5377 else
5378 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter, 0, MSGTR_Unknown);
5380 break;
5381 } break;
5382 case MP_CMD_SET_MOUSE_POS: {
5383 int button = -1, pointer_x, pointer_y;
5384 double dx, dy;
5385 pointer_x = cmd->args[0].v.i;
5386 pointer_y = cmd->args[1].v.i;
5387 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
5388 #ifdef USE_DVDNAV
5389 if(stream->type == STREAMTYPE_DVDNAV && dx > 0.0 && dy > 0.0) {
5390 pointer_x = (int) (dx * (double) sh_video->disp_w);
5391 pointer_y = (int) (dy * (double) sh_video->disp_h);
5392 mp_dvdnav_update_mouse_pos(stream, pointer_x, pointer_y, &button);
5393 if(button>0) set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button);
5395 #endif
5396 break;
5398 #ifdef USE_DVDNAV
5399 case MP_CMD_DVDNAV: {
5400 int button = -1;
5401 if(stream->type != STREAMTYPE_DVDNAV) break;
5403 if(mp_dvdnav_handle_input(stream, cmd->args[0].v.i, &button)) {
5404 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT|(fixed_vo ? INITED_VO : 0)));
5405 goto goto_enable_cache;
5406 } else if(button>0) set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button);
5407 break;
5409 #endif
5410 default : {
5411 #ifdef HAVE_NEW_GUI
5412 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
5413 else
5414 #endif
5415 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
5418 switch (cmd->pausing) {
5419 case 1: // "pausing"
5420 osd_function = OSD_PAUSE;
5421 break;
5422 case 3: // "pausing_toggle"
5423 was_paused = !was_paused;
5424 // fall through
5425 case 2: // "pausing_keep"
5426 if (was_paused) osd_function = OSD_PAUSE;
5428 mp_cmd_free(cmd);
5431 was_paused = 0;
5433 if (seek_to_sec) {
5434 int a,b; float d;
5436 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
5437 rel_seek_secs += 3600*a +60*b +d ;
5438 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
5439 rel_seek_secs += 60*a +d;
5440 else if (sscanf(seek_to_sec, "%f", &d)==1)
5441 rel_seek_secs += d;
5443 seek_to_sec = NULL;
5446 if (end_at.type != END_AT_NONE) {
5447 if(end_at.type == END_AT_SIZE) {
5448 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_MPEndposNoSizeBased);
5449 end_at.type = END_AT_NONE;
5450 } else {
5451 end_at.pos += rel_seek_secs;
5455 /* Looping. */
5456 if(eof==1 && loop_times>=0) {
5457 int l = loop_times;
5458 play_tree_iter_step(playtree_iter,0,0);
5459 loop_times = l;
5460 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
5462 if(loop_times>1) loop_times--; else
5463 if(loop_times==1) loop_times=-1;
5464 play_n_frames=play_n_frames_mf;
5465 eof=0;
5466 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
5467 loop_seek = 1;
5470 if(rel_seek_secs || abs_seek_pos){
5471 current_module="seek";
5472 if(demux_seek(demuxer,rel_seek_secs,audio_delay,abs_seek_pos)){
5473 // success:
5474 /* FIXME there should be real seeking for vobsub */
5475 if(sh_video) sh_video->pts=d_video->pts;
5476 if (vo_vobsub)
5477 //vobsub_reset(vo_vobsub);
5478 vobsub_seek(vo_vobsub,sh_video->pts);
5479 fflush(stdout);
5481 if(sh_video){
5482 current_module="seek_video_reset";
5483 resync_video_stream(sh_video);
5484 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
5485 sh_video->num_buffered_pts = 0;
5486 sh_video->last_pts = MP_NOPTS_VALUE;
5489 if(sh_audio){
5490 current_module="seek_audio_reset";
5491 audio_out->reset(); // stop audio, throwing away buffered data
5492 sh_audio->a_buffer_len = 0;
5493 sh_audio->a_out_buffer_len = 0;
5495 // Set OSD:
5496 if(!loop_seek){
5497 if( !edl_decision )
5498 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer));
5501 if(sh_video) {
5502 c_total=0;
5503 max_pts_correction=0.1;
5504 osd_visible=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
5505 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
5506 drop_frame_cnt=0;
5508 if(vo_spudec) spudec_reset(vo_spudec);
5512 * We saw a seek, have to rewind the EDL operations stack
5513 * and find the next EDL action to take care of.
5516 edl_muted = 0;
5517 next_edl_record = edl_records;
5519 while (next_edl_record)
5521 /* Trying to remember if we need to mute/unmute first;
5522 * prior EDL implementation lacks this.
5525 if (next_edl_record->start_sec >= sh_video->pts)
5526 break;
5528 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
5529 next_edl_record = next_edl_record->next;
5532 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
5534 rel_seek_secs=0;
5535 abs_seek_pos=0;
5536 frame_time_remaining=0;
5537 current_module=NULL;
5538 loop_seek=0;
5541 #ifdef HAVE_NEW_GUI
5542 if(use_gui){
5543 guiEventHandling();
5544 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
5545 // get pos from frame number / total frames
5546 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
5547 } else {
5548 off_t len = ( demuxer->movi_end - demuxer->movi_start );
5549 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
5550 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
5552 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
5553 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
5554 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
5555 guiGetEvent( guiReDraw,NULL );
5556 guiGetEvent( guiSetVolume,NULL );
5557 if(guiIntfStruct.Playing==0) break; // STOP
5558 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
5559 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
5560 #ifdef USE_DVDREAD
5561 if ( stream->type == STREAMTYPE_DVD )
5563 dvd_priv_t * dvdp = stream->priv;
5564 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
5566 #endif
5568 #endif /* HAVE_NEW_GUI */
5570 } // while(!eof)
5572 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
5574 #ifdef HAS_DVBIN_SUPPORT
5575 if(dvbin_reopen)
5577 eof = 0;
5578 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
5579 cache_uninit(stream);
5580 dvbin_reopen = 0;
5581 goto goto_enable_cache;
5583 #endif
5586 goto_next_file: // don't jump here after ao/vo/getch initialization!
5588 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
5590 if(benchmark){
5591 double tot=video_time_usage+vout_time_usage+audio_time_usage;
5592 double total_time_usage;
5593 total_time_usage_start=GetTimer()-total_time_usage_start;
5594 total_time_usage = (float)total_time_usage_start*0.000001;
5595 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5596 video_time_usage,vout_time_usage,audio_time_usage,
5597 total_time_usage-tot,total_time_usage);
5598 if(total_time_usage>0.0)
5599 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5600 100.0*video_time_usage/total_time_usage,
5601 100.0*vout_time_usage/total_time_usage,
5602 100.0*audio_time_usage/total_time_usage,
5603 100.0*(total_time_usage-tot)/total_time_usage,
5604 100.0);
5605 if(total_frame_cnt && frame_dropping)
5606 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5607 total_frame_cnt-drop_frame_cnt,
5608 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
5609 drop_frame_cnt,
5610 100*drop_frame_cnt/total_frame_cnt,
5611 total_frame_cnt,
5612 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
5616 // time to uninit all, except global stuff:
5617 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
5619 if ( set_of_sub_size > 0 )
5621 current_module="sub_free";
5622 for (i = 0; i < set_of_sub_size; ++i) {
5623 sub_free( set_of_subtitles[i] );
5624 #ifdef USE_ASS
5625 if ( set_of_ass_tracks[i] )
5626 ass_free_track( set_of_ass_tracks[i] );
5627 #endif
5629 set_of_sub_size = 0;
5631 vo_sub_last = vo_sub=NULL;
5632 subdata=NULL;
5633 #ifdef USE_ASS
5634 ass_track = NULL;
5635 #endif
5637 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
5638 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
5639 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
5640 eof = 1;
5641 } else {
5642 play_tree_iter_free(playtree_iter);
5643 playtree_iter = NULL;
5645 play_tree_step = 1;
5646 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
5647 eof = eof == PT_UP_NEXT ? 1 : -1;
5648 if ( playtree_iter ) {
5649 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
5650 eof = 1;
5651 } else {
5652 play_tree_iter_free(playtree_iter);
5653 playtree_iter = NULL;
5656 } else { // NEXT PREV SRC
5657 eof = eof == PT_PREV_SRC ? -1 : 1;
5660 if(eof == 0) eof = 1;
5662 while(playtree_iter != NULL) {
5663 filename = play_tree_iter_get_file(playtree_iter,eof);
5664 if(filename == NULL) {
5665 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
5666 play_tree_iter_free(playtree_iter);
5667 playtree_iter = NULL;
5669 } else
5670 break;
5673 #ifdef HAVE_NEW_GUI
5674 if( use_gui && !playtree_iter )
5676 #ifdef USE_DVDREAD
5677 if ( !guiIntfStruct.DiskChanged )
5678 #endif
5679 mplEnd();
5681 #endif
5683 if(use_gui || playtree_iter != NULL || player_idle_mode){
5684 if (!playtree_iter) filename = NULL;
5685 eof = 0;
5686 goto play_next_file;
5690 exit_player_with_rc(MSGTR_Exit_eof, 0);
5692 return 1;