mf demuxer only works with mf:// urls, so check for that.
[mplayer/glamo.git] / mplayer.c
blob27621bdaf0fa997e9faacf8af853ae75e05e5849
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 #ifdef USE_DVDNAV
187 #include "stream/stream_dvdnav.h"
188 #endif
190 #include "libmpcodecs/dec_audio.h"
191 #include "libmpcodecs/dec_video.h"
192 #include "libmpcodecs/mp_image.h"
193 #include "libmpcodecs/vf.h"
194 #include "libmpcodecs/vd.h"
196 //**************************************************************************//
198 static void reinit_audio_chain(void);
200 //**************************************************************************//
201 //**************************************************************************//
203 // Common FIFO functions, and keyboard/event FIFO code
204 #include "fifo.c"
205 int noconsolecontrols=0;
206 //**************************************************************************//
208 vo_functions_t *video_out=NULL;
209 ao_functions_t *audio_out=NULL;
211 int fixed_vo=0;
212 int eof=0;
214 // benchmark:
215 double video_time_usage=0;
216 double vout_time_usage=0;
217 static double audio_time_usage=0;
218 static int total_time_usage_start=0;
219 static int total_frame_cnt=0;
220 static int drop_frame_cnt=0; // total number of dropped frames
221 int benchmark=0;
223 // options:
224 int auto_quality=0;
225 static int output_quality=0;
227 float playback_speed=1.0;
229 int use_gui=0;
231 #ifdef HAVE_NEW_GUI
232 int enqueue=0;
233 #endif
235 static int list_properties = 0;
237 #define MAX_OSD_LEVEL 3
238 #define MAX_TERM_OSD_LEVEL 1
240 int osd_level=1;
241 int osd_level_saved=-1;
242 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
243 unsigned int osd_visible;
244 static int osd_function=OSD_PLAY;
245 static int osd_show_percentage = 0;
246 static int osd_duration = 1000;
248 static int term_osd = 1;
249 static char* term_osd_esc = "\x1b[A\r\x1b[K";
250 static char* playing_msg = NULL;
251 // seek:
252 static char *seek_to_sec=NULL;
253 static off_t seek_to_byte=0;
254 static off_t step_sec=0;
255 static int loop_times=-1;
256 static int loop_seek=0;
258 static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 };
260 // A/V sync:
261 int autosync=0; // 30 might be a good default value.
263 // may be changed by GUI: (FIXME!)
264 float rel_seek_secs=0;
265 int abs_seek_pos=0;
267 // codecs:
268 char **audio_codec_list=NULL; // override audio codec
269 char **video_codec_list=NULL; // override video codec
270 char **audio_fm_list=NULL; // override audio codec family
271 char **video_fm_list=NULL; // override video codec family
273 // demuxer:
274 extern char *demuxer_name; // override demuxer
275 extern char *audio_demuxer_name; // override audio demuxer
276 extern char *sub_demuxer_name; // override sub demuxer
278 // streaming:
279 int audio_id=-1;
280 int video_id=-1;
281 int dvdsub_id=-2;
282 int vobsub_id=-1;
283 char* audio_lang=NULL;
284 char* dvdsub_lang=NULL;
285 static char* spudec_ifo=NULL;
286 char* filename=NULL; //"MI2-Trailer.avi";
287 int forced_subs_only=0;
288 int file_filter=1;
290 // cache2:
291 int stream_cache_size=-1;
292 #ifdef USE_STREAM_CACHE
293 extern int cache_fill_status;
295 float stream_cache_min_percent=20.0;
296 float stream_cache_seek_min_percent=50.0;
297 #else
298 #define cache_fill_status 0
299 #endif
301 // dump:
302 static char *stream_dump_name="stream.dump";
303 int stream_dump_type=0;
305 // A-V sync:
306 static float default_max_pts_correction=-1;//0.01f;
307 static float max_pts_correction=0;//default_max_pts_correction;
308 static float c_total=0;
309 float audio_delay=0;
310 static int ignore_start=0;
312 static int softsleep=0;
314 float force_fps=0;
315 static int force_srate=0;
316 static int audio_output_format=-1; // AF_FORMAT_UNKNOWN
317 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
318 static int play_n_frames=-1;
319 static int play_n_frames_mf=-1;
321 // screen info:
322 char** video_driver_list=NULL;
323 char** audio_driver_list=NULL;
325 extern char *vo_subdevice;
326 extern char *ao_subdevice;
328 // codec outfmt flags (defined in libmpcodecs/vd.c)
329 extern int vo_flags;
331 // sub:
332 char *font_name=NULL;
333 #ifdef HAVE_FONTCONFIG
334 extern int font_fontconfig;
335 #endif
336 float font_factor=0.75;
337 char **sub_name=NULL;
338 float sub_delay=0;
339 float sub_fps=0;
340 int sub_auto = 1;
341 char *vobsub_name=NULL;
342 /*DSP!!char *dsp=NULL;*/
343 int subcc_enabled=0;
344 int suboverlap_enabled = 1;
346 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
347 int set_of_sub_size = 0;
348 int set_of_sub_pos = -1;
349 double sub_last_pts = -303;
351 int global_sub_size = 0; // this encompasses all subtitle sources
352 int global_sub_pos = -1; // this encompasses all subtitle sources
353 #define SUB_SOURCE_SUBS 0
354 #define SUB_SOURCE_VOBSUB 1
355 #define SUB_SOURCE_DEMUX 2
356 #define SUB_SOURCES 3
357 int global_sub_indices[SUB_SOURCES];
359 #ifdef USE_ASS
360 #include "libass/ass.h"
361 #include "libass/ass_mp.h"
363 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
364 // or NULL if format unsupported
365 ass_track_t* set_of_ass_tracks[MAX_SUBTITLE_FILES];
366 ass_track_t* ass_track = 0; // current track to render
367 #endif
369 extern int mp_msg_levels[MSGT_MAX];
370 extern int mp_msg_level_all;
372 static stream_t* stream=NULL;
373 static demuxer_t *demuxer=NULL;
374 static sh_audio_t *sh_audio=NULL;
375 static sh_video_t *sh_video=NULL;
376 static demux_stream_t *d_audio=NULL;
377 static demux_stream_t *d_video=NULL;
378 static demux_stream_t *d_dvdsub=NULL;
380 char* current_module=NULL; // for debugging
382 extern int vo_gamma_gamma;
383 extern int vo_gamma_brightness;
384 extern int vo_gamma_contrast;
385 extern int vo_gamma_saturation;
386 extern int vo_gamma_hue;
388 // ---
390 #ifdef HAVE_MENU
391 #include "m_struct.h"
392 #include "libmenu/menu.h"
393 extern void vf_menu_pause_update(struct vf_instance_s* vf);
394 extern vf_info_t vf_info_menu;
395 static vf_info_t* libmenu_vfs[] = {
396 &vf_info_menu,
397 NULL
399 static vf_instance_t* vf_menu = NULL;
400 static int use_menu = 0;
401 static char* menu_cfg = NULL;
402 static char* menu_root = "main";
403 #endif
406 #ifdef HAVE_RTC
407 static int nortc = 1;
408 static char* rtc_device;
409 #endif
411 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
412 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
413 short user_muted = 0; ///< Stores whether user wanted muted mode.
414 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
415 short edl_decision = 0; ///< 1 when an EDL operation has been made.
416 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode.
417 float begin_skip = MP_NOPTS_VALUE; ///< start time of the current skip while on edlout mode
418 int use_filedir_conf;
420 static unsigned int inited_flags=0;
421 #define INITED_VO 1
422 #define INITED_AO 2
423 #define INITED_GUI 4
424 #define INITED_GETCH2 8
425 #define INITED_SPUDEC 32
426 #define INITED_STREAM 64
427 #define INITED_INPUT 128
428 #define INITED_VOBSUB 256
429 #define INITED_DEMUXER 512
430 #define INITED_ACODEC 1024
431 #define INITED_VCODEC 2048
432 #define INITED_ALL 0xFFFF
434 #include "metadata.h"
436 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
438 static int is_valid_metadata_type (metadata_t type) {
439 switch (type)
441 /* check for valid video stream */
442 case META_VIDEO_CODEC:
443 case META_VIDEO_BITRATE:
444 case META_VIDEO_RESOLUTION:
446 if (!sh_video)
447 return 0;
448 break;
451 /* check for valid audio stream */
452 case META_AUDIO_CODEC:
453 case META_AUDIO_BITRATE:
454 case META_AUDIO_SAMPLES:
456 if (!sh_audio)
457 return 0;
458 break;
461 /* check for valid demuxer */
462 case META_INFO_TITLE:
463 case META_INFO_ARTIST:
464 case META_INFO_ALBUM:
465 case META_INFO_YEAR:
466 case META_INFO_COMMENT:
467 case META_INFO_TRACK:
468 case META_INFO_GENRE:
470 if (!demuxer)
471 return 0;
472 break;
475 default:
476 break;
479 return 1;
482 static char *get_demuxer_info (char *tag) {
483 char **info = demuxer->info;
484 int n;
486 if (!info || !tag)
487 return NULL;
489 for (n = 0; info[2*n] != NULL ; n++)
490 if (!strcmp (info[2*n], tag))
491 break;
493 return info[2*n+1] ? strdup (info[2*n+1]) : NULL;
496 char *get_metadata (metadata_t type) {
497 char *meta = NULL;
499 if (!is_valid_metadata_type (type))
500 return NULL;
502 switch (type)
504 case META_NAME:
506 return strdup (mp_basename2 (filename));
509 case META_VIDEO_CODEC:
511 if (sh_video->format == 0x10000001)
512 meta = strdup ("mpeg1");
513 else if (sh_video->format == 0x10000002)
514 meta = strdup ("mpeg2");
515 else if (sh_video->format == 0x10000004)
516 meta = strdup ("mpeg4");
517 else if (sh_video->format == 0x10000005)
518 meta = strdup ("h264");
519 else if (sh_video->format >= 0x20202020)
521 meta = (char *) malloc (8);
522 sprintf (meta, "%.4s", (char *) &sh_video->format);
524 else
526 meta = (char *) malloc (8);
527 sprintf (meta, "0x%08X", sh_video->format);
529 return meta;
532 case META_VIDEO_BITRATE:
534 meta = (char *) malloc (16);
535 sprintf (meta, "%d kbps", (int) (sh_video->i_bps * 8 / 1024));
536 return meta;
539 case META_VIDEO_RESOLUTION:
541 meta = (char *) malloc (16);
542 sprintf (meta, "%d x %d", sh_video->disp_w, sh_video->disp_h);
543 return meta;
546 case META_AUDIO_CODEC:
548 if (sh_audio->codec && sh_audio->codec->name)
549 meta = strdup (sh_audio->codec->name);
550 return meta;
553 case META_AUDIO_BITRATE:
555 meta = (char *) malloc (16);
556 sprintf (meta, "%d kbps", (int) (sh_audio->i_bps * 8/1000));
557 return meta;
560 case META_AUDIO_SAMPLES:
562 meta = (char *) malloc (16);
563 sprintf (meta, "%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels);
564 return meta;
567 /* check for valid demuxer */
568 case META_INFO_TITLE:
569 return get_demuxer_info ("Title");
571 case META_INFO_ARTIST:
572 return get_demuxer_info ("Artist");
574 case META_INFO_ALBUM:
575 return get_demuxer_info ("Album");
577 case META_INFO_YEAR:
578 return get_demuxer_info ("Year");
580 case META_INFO_COMMENT:
581 return get_demuxer_info ("Comment");
583 case META_INFO_TRACK:
584 return get_demuxer_info ("Track");
586 case META_INFO_GENRE:
587 return get_demuxer_info ("Genre");
589 default:
590 break;
593 return meta;
596 #include "mixer.h"
597 mixer_t mixer;
598 /// step size of mixer changes
599 int volstep = 3;
601 static void uninit_player(unsigned int mask){
602 mask=inited_flags&mask;
604 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
606 if(mask&INITED_ACODEC){
607 inited_flags&=~INITED_ACODEC;
608 current_module="uninit_acodec";
609 if(sh_audio) uninit_audio(sh_audio);
610 #ifdef HAVE_NEW_GUI
611 guiGetEvent(guiSetAfilter, (char *)NULL);
612 #endif
613 sh_audio=NULL;
616 if(mask&INITED_VCODEC){
617 inited_flags&=~INITED_VCODEC;
618 current_module="uninit_vcodec";
619 if(sh_video) uninit_video(sh_video);
620 sh_video=NULL;
621 #ifdef HAVE_MENU
622 vf_menu=NULL;
623 #endif
626 if(mask&INITED_DEMUXER){
627 inited_flags&=~INITED_DEMUXER;
628 current_module="free_demuxer";
629 if(demuxer){
630 stream=demuxer->stream;
631 free_demuxer(demuxer);
633 demuxer=NULL;
636 // kill the cache process:
637 if(mask&INITED_STREAM){
638 inited_flags&=~INITED_STREAM;
639 current_module="uninit_stream";
640 if(stream) free_stream(stream);
641 stream=NULL;
644 if(mask&INITED_VO){
645 inited_flags&=~INITED_VO;
646 current_module="uninit_vo";
647 video_out->uninit();
648 video_out=NULL;
651 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
652 if(mask&INITED_GETCH2){
653 inited_flags&=~INITED_GETCH2;
654 current_module="uninit_getch2";
655 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
656 // restore terminal:
657 getch2_disable();
660 if(mask&INITED_VOBSUB){
661 inited_flags&=~INITED_VOBSUB;
662 current_module="uninit_vobsub";
663 if(vo_vobsub) vobsub_close(vo_vobsub);
664 vo_vobsub=NULL;
667 if (mask&INITED_SPUDEC){
668 inited_flags&=~INITED_SPUDEC;
669 current_module="uninit_spudec";
670 spudec_free(vo_spudec);
671 vo_spudec=NULL;
674 if(mask&INITED_AO){
675 inited_flags&=~INITED_AO;
676 current_module="uninit_ao";
677 if (user_muted | edl_muted) mixer_mute(&mixer);
678 audio_out->uninit(eof?0:1); audio_out=NULL;
681 #ifdef HAVE_NEW_GUI
682 if(mask&INITED_GUI){
683 inited_flags&=~INITED_GUI;
684 current_module="uninit_gui";
685 guiDone();
687 #endif
689 if(mask&INITED_INPUT){
690 inited_flags&=~INITED_INPUT;
691 current_module="uninit_input";
692 mp_input_uninit();
695 current_module=NULL;
698 static void exit_player_with_rc(const char* how, int rc){
700 uninit_player(INITED_ALL);
701 #ifdef HAVE_X11
702 #ifdef HAVE_NEW_GUI
703 if ( !use_gui )
704 #endif
705 vo_uninit(); // Close the X11 connection (if any is open).
706 #endif
708 #ifdef HAVE_FREETYPE
709 current_module="uninit_font";
710 if (vo_font) free_font_desc(vo_font);
711 vo_font = NULL;
712 done_freetype();
713 #endif
714 free_osd_list();
716 #ifdef USE_ASS
717 ass_library_done(ass_library);
718 #endif
720 current_module="exit_player";
722 // free mplayer config
723 if(mconfig)
724 m_config_free(mconfig);
726 if(playtree)
727 play_tree_free(playtree, 1);
730 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
731 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,how);
732 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
734 exit(rc);
737 void exit_player(const char* how){
738 exit_player_with_rc(how, 1);
741 #ifndef __MINGW32__
742 static void child_sighandler(int x){
743 pid_t pid;
744 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
746 #endif
748 #ifdef CRASH_DEBUG
749 static char *prog_path;
750 static int crash_debug = 0;
751 #endif
753 static void exit_sighandler(int x){
754 static int sig_count=0;
755 #ifdef CRASH_DEBUG
756 if (!crash_debug || x != SIGTRAP)
757 #endif
758 ++sig_count;
759 if(inited_flags==0 && sig_count>1) exit(1);
760 if(sig_count==5)
762 /* We're crashing bad and can't uninit cleanly :(
763 * by popular request, we make one last (dirty)
764 * effort to restore the user's
765 * terminal. */
766 getch2_disable();
767 exit(1);
769 if(sig_count==6) exit(1);
770 if(sig_count>6){
771 // can't stop :(
772 #ifndef __MINGW32__
773 kill(getpid(),SIGKILL);
774 #endif
776 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
777 current_module?current_module:"unknown"
779 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x);
780 if(sig_count<=1)
781 switch(x){
782 case SIGINT:
783 case SIGQUIT:
784 case SIGTERM:
785 case SIGKILL:
786 break; // killed from keyboard (^C) or killed [-9]
787 case SIGILL:
788 #ifdef RUNTIME_CPUDETECT
789 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
790 #else
791 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
792 #endif
793 case SIGFPE:
794 case SIGSEGV:
795 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
796 default:
797 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
798 #ifdef CRASH_DEBUG
799 if (crash_debug) {
800 int gdb_pid;
801 char spid[20];
802 snprintf(spid, 19, "%i", getpid());
803 spid[19] = 0;
804 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
805 gdb_pid = fork();
806 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
807 if (gdb_pid == 0) { // We are the child
808 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
809 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
810 } else if (gdb_pid < 0)
811 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
812 else {
813 waitpid(gdb_pid, NULL, 0);
815 if (x == SIGTRAP) return;
817 #endif
819 exit_player(NULL);
822 extern void mp_input_register_options(m_config_t* cfg);
824 #include "cfg-mplayer.h"
826 static void parse_cfgfiles( m_config_t* conf )
828 char *conffile;
829 int conffile_fd;
830 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
831 exit_player(NULL);
832 if ((conffile = get_path("")) == NULL) {
833 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
834 } else {
835 #ifdef __MINGW32__
836 mkdir(conffile);
837 #else
838 mkdir(conffile, 0777);
839 #endif
840 free(conffile);
841 if ((conffile = get_path("config")) == NULL) {
842 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
843 } else {
844 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
845 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
846 write(conffile_fd, default_config, strlen(default_config));
847 close(conffile_fd);
849 if (m_config_parse_config_file(conf, conffile) < 0)
850 exit_player(NULL);
851 free(conffile);
856 void load_per_file_config (m_config_t* conf, const char *const file)
858 char *confpath;
859 char cfg[strlen(file)+10];
860 struct stat st;
861 char *name;
863 sprintf (cfg, "%s.conf", file);
865 if (use_filedir_conf && !stat (cfg, &st))
867 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
868 m_config_parse_config_file (conf, cfg);
869 return;
872 if ((name = strrchr (cfg, '/')) == NULL)
873 name = cfg;
874 else
875 name++;
877 if ((confpath = get_path (name)) != NULL)
879 if (!stat (confpath, &st))
881 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
882 m_config_parse_config_file (conf, confpath);
885 free (confpath);
889 /* When libmpdemux performs a blocking operation (network connection or
890 * cache filling) if the operation fails we use this function to check
891 * if it was interrupted by the user.
892 * The function returns a new value for eof. */
893 static int libmpdemux_was_interrupted(int eof) {
894 mp_cmd_t* cmd;
895 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
896 switch(cmd->id) {
897 case MP_CMD_QUIT:
898 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
899 case MP_CMD_PLAY_TREE_STEP: {
900 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
901 play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i;
902 } break;
903 case MP_CMD_PLAY_TREE_UP_STEP: {
904 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
905 } break;
906 case MP_CMD_PLAY_ALT_SRC_STEP: {
907 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
908 } break;
910 mp_cmd_free(cmd);
912 return eof;
915 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
917 int playtree_add_playlist(play_tree_t* entry)
919 play_tree_add_bpf(entry,filename);
921 #ifdef HAVE_NEW_GUI
922 if (use_gui) {
923 if (entry) {
924 import_playtree_playlist_into_gui(entry, mconfig);
925 play_tree_free_list(entry,1);
927 } else
928 #endif
930 if(!entry) {
931 entry = playtree_iter->tree;
932 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
933 return PT_NEXT_ENTRY;
935 if(playtree_iter->tree == entry ) { // Loop with a single file
936 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
937 return PT_NEXT_ENTRY;
940 play_tree_remove(entry,1,1);
941 return PT_NEXT_SRC;
943 play_tree_insert_entry(playtree_iter->tree,entry);
944 play_tree_set_params_from(entry,playtree_iter->tree);
945 entry = playtree_iter->tree;
946 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
947 return PT_NEXT_ENTRY;
949 play_tree_remove(entry,1,1);
951 return PT_NEXT_SRC;
954 int sub_source(void)
956 int source = -1;
957 int top = -1;
958 int i;
959 for (i = 0; i < SUB_SOURCES; i++) {
960 int j = global_sub_indices[i];
961 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
962 source = i;
963 top = j;
966 return source;
969 sub_data* subdata = NULL;
970 static subtitle* vo_sub_last = NULL;
972 void add_subtitles(char *filename, float fps, int silent)
974 sub_data *subd;
975 #ifdef USE_ASS
976 ass_track_t *asst = 0;
977 #endif
979 if (filename == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) {
980 return;
983 subd = sub_read_file(filename, fps);
984 #ifdef USE_ASS
985 if (ass_enabled)
986 #ifdef USE_ICONV
987 asst = ass_read_file(ass_library, filename, sub_cp);
988 #else
989 asst = ass_read_file(ass_library, filename, 0);
990 #endif
991 if (ass_enabled && subd && !asst)
992 asst = ass_read_subdata(ass_library, subd, fps);
994 if (!asst && !subd && !silent)
995 #else
996 if(!subd && !silent)
997 #endif
998 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub,
999 filename_recode(filename));
1001 #ifdef USE_ASS
1002 if (!asst && !subd) return;
1003 set_of_ass_tracks[set_of_sub_size] = asst;
1004 #else
1005 if (!subd) return;
1006 #endif
1007 set_of_subtitles[set_of_sub_size] = subd;
1008 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
1009 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n",
1010 filename_recode(filename));
1011 ++set_of_sub_size;
1012 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size,
1013 filename_recode(filename));
1016 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1017 void update_set_of_subtitles(void)
1018 // subdata was changed, set_of_sub... have to be updated.
1020 int i;
1021 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
1022 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
1023 set_of_subtitles[i-1] = set_of_subtitles[i];
1024 set_of_subtitles[set_of_sub_size-1] = NULL;
1025 --set_of_sub_size;
1026 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
1028 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
1029 set_of_subtitles[set_of_sub_pos] = subdata;
1031 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
1032 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
1033 ++set_of_sub_size;
1037 void init_vo_spudec(void) {
1038 if (vo_spudec)
1039 spudec_free(vo_spudec);
1040 inited_flags &= ~INITED_SPUDEC;
1041 vo_spudec = NULL;
1042 if (spudec_ifo) {
1043 unsigned int palette[16], width, height;
1044 current_module="spudec_init_vobsub";
1045 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
1046 vo_spudec=spudec_new_scaled(palette, width, height);
1049 #ifdef USE_DVDREAD
1050 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
1051 current_module="spudec_init_dvdread";
1052 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
1053 sh_video->disp_w, sh_video->disp_h);
1055 #endif
1057 #ifdef USE_DVDNAV
1058 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) {
1059 unsigned int *palette = mp_dvdnav_get_spu_clut(stream);
1060 current_module="spudec_init_dvdnav";
1061 vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h);
1063 #endif
1065 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
1066 (d_dvdsub->sh != NULL) && (((sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
1067 sh_sub_t *mkv_sh_sub = (sh_sub_t *)d_dvdsub->sh;
1068 current_module = "spudec_init_matroska";
1069 vo_spudec =
1070 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
1071 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
1072 mkv_sh_sub->height);
1073 forced_subs_only = mkv_sh_sub->forced_subs_only;
1076 if (vo_spudec==NULL) {
1077 sh_sub_t *sh = (sh_sub_t *)d_dvdsub->sh;
1078 unsigned int *palette = NULL;
1079 if (sh && sh->has_palette)
1080 palette = sh->palette;
1081 current_module="spudec_init_normal";
1082 vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h);
1083 spudec_set_font_factor(vo_spudec,font_factor);
1086 if (vo_spudec!=NULL)
1087 inited_flags|=INITED_SPUDEC;
1091 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1092 * make it all work is to use the builtin SDL-bootstrap code, which
1093 * will be done automatically by replacing our main() if we include SDL.h.
1095 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1096 #include <SDL.h>
1097 #endif
1100 * \brief append a formatted string
1101 * \param buf buffer to print into
1102 * \param pos position of terminating 0 in buf
1103 * \param len maximum number of characters in buf, not including terminating 0
1104 * \param format printf format string
1106 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
1108 va_list va;
1109 va_start(va, format);
1110 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
1111 va_end(va);
1112 if (*pos >= len ) {
1113 buf[len] = 0;
1114 *pos = len;
1119 * \brief append time in the hh:mm:ss.f format
1120 * \param buf buffer to print into
1121 * \param pos position of terminating 0 in buf
1122 * \param len maximum number of characters in buf, not including terminating 0
1123 * \param time time value to convert/append
1125 static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) {
1126 long tenths = 10 * time;
1127 int f1 = tenths % 10;
1128 int ss = (tenths / 10) % 60;
1129 int mm = (tenths / 600) % 60;
1130 int hh = tenths / 36000;
1131 if (time <= 0) {
1132 saddf(buf, pos, len, "unknown");
1133 return;
1135 if (hh > 0)
1136 saddf(buf, pos, len, "%2d:", hh);
1137 if (hh > 0 || mm > 0)
1138 saddf(buf, pos, len, "%02d:", mm);
1139 saddf(buf, pos, len, "%02d.%1d", ss, f1);
1143 * \brief print the status line
1144 * \param a_pos audio position
1145 * \param a_v A-V desynchronization
1146 * \param corr amount out A-V synchronization
1148 static void print_status(float a_pos, float a_v, float corr)
1150 int width;
1151 char *line;
1152 unsigned pos = 0;
1153 get_screen_size();
1154 if (screen_width > 0)
1155 width = screen_width;
1156 else
1157 width = 80;
1158 #ifdef WIN32
1159 /* Windows command line is broken (MinGW's rxvt works, but we
1160 * should not depend on that). */
1161 width--;
1162 #endif
1163 line = malloc(width + 1); // one additional char for the terminating null
1165 // Audio time
1166 if (sh_audio) {
1167 saddf(line, &pos, width, "A:%6.1f ", a_pos);
1168 if (!sh_video) {
1169 float len = demuxer_get_time_length(demuxer);
1170 saddf(line, &pos, width, "(");
1171 sadd_hhmmssf(line, &pos, width, a_pos);
1172 saddf(line, &pos, width, ") of %.1f (", len);
1173 sadd_hhmmssf(line, &pos, width, len);
1174 saddf(line, &pos, width, ") ");
1178 // Video time
1179 if (sh_video)
1180 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
1182 // A-V sync
1183 if (sh_audio && sh_video)
1184 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
1186 // Video stats
1187 if (sh_video)
1188 saddf(line, &pos, width, "%3d/%3d ",
1189 (int)sh_video->num_frames,
1190 (int)sh_video->num_frames_decoded);
1192 // CPU usage
1193 if (sh_video) {
1194 if (sh_video->timer > 0.5)
1195 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
1196 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
1197 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
1198 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
1199 else
1200 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
1201 } else if (sh_audio) {
1202 if (sh_audio->delay > 0.5)
1203 saddf(line, &pos, width, "%4.1f%% ",
1204 100.0*audio_time_usage/(double)sh_audio->delay);
1205 else
1206 saddf(line, &pos, width, "??,?%% ");
1209 // VO stats
1210 if (sh_video)
1211 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
1213 #ifdef USE_STREAM_CACHE
1214 // cache stats
1215 if (stream_cache_size > 0)
1216 saddf(line, &pos, width, "%d%% ", cache_fill_status);
1217 #endif
1219 // other
1220 if (playback_speed != 1)
1221 saddf(line, &pos, width, "%4.2fx ", playback_speed);
1223 // end
1224 if (erase_to_end_of_line) {
1225 line[pos] = 0;
1226 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s%s\r", line, erase_to_end_of_line);
1227 } else {
1228 memset(&line[pos], ' ', width - pos);
1229 line[width] = 0;
1230 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
1232 free(line);
1236 * \brief build a chain of audio filters that converts the input format
1237 * to the ao's format, taking into account the current playback_speed.
1238 * \param sh_audio describes the requested input format of the chain.
1239 * \param ao_data describes the requested output format of the chain.
1241 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
1243 int new_srate;
1244 int result;
1245 if (!sh_audio)
1247 #ifdef HAVE_NEW_GUI
1248 guiGetEvent(guiSetAfilter, (char *)NULL);
1249 #endif
1250 mixer.afilter = NULL;
1251 return 0;
1253 new_srate = sh_audio->samplerate * playback_speed;
1254 if (new_srate != ao_data->samplerate) {
1255 // limits are taken from libaf/af_resample.c
1256 if (new_srate < 8000)
1257 new_srate = 8000;
1258 if (new_srate > 192000)
1259 new_srate = 192000;
1260 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
1262 result = init_audio_filters(sh_audio, new_srate,
1263 sh_audio->channels, sh_audio->sample_format,
1264 &ao_data->samplerate, &ao_data->channels, &ao_data->format,
1265 ao_data->outburst * 4, ao_data->buffersize);
1266 mixer.afilter = sh_audio->afilter;
1267 #ifdef HAVE_NEW_GUI
1268 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter);
1269 #endif
1270 return result;
1274 * \brief Log the currently displayed subtitle to a file
1276 * Logs the current or last displayed subtitle together with filename
1277 * and time information to ~/.mplayer/subtitle_log
1279 * Intended purpose is to allow convenient marking of bogus subtitles
1280 * which need to be fixed while watching the movie.
1283 static void log_sub(void){
1284 char *fname;
1285 FILE *f;
1286 int i;
1288 if (subdata == NULL || vo_sub_last == NULL) return;
1289 fname = get_path("subtitle_log");
1290 f = fopen(fname, "a");
1291 if (!f) return;
1292 fprintf(f, "----------------------------------------------------------\n");
1293 if (subdata->sub_uses_time) {
1294 fprintf(f, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename,
1295 vo_sub_last->start/360000, (vo_sub_last->start/6000)%60,
1296 (vo_sub_last->start/100)%60, vo_sub_last->start%100,
1297 vo_sub_last->end/360000, (vo_sub_last->end/6000)%60,
1298 (vo_sub_last->end/100)%60, vo_sub_last->end%100);
1299 } else {
1300 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start, vo_sub_last->end);
1302 for (i = 0; i < vo_sub_last->lines; i++) {
1303 fprintf(f, "%s\n", vo_sub_last->text[i]);
1305 fclose(f);
1308 /// \defgroup OSDMsgStack OSD message stack
1310 ///@{
1312 #define OSD_MSG_TV_CHANNEL 0
1313 #define OSD_MSG_TEXT 1
1314 #define OSD_MSG_SUB_DELAY 2
1315 #define OSD_MSG_SPEED 3
1316 #define OSD_MSG_OSD_STATUS 4
1317 #define OSD_MSG_BAR 5
1318 #define OSD_MSG_PAUSE 6
1319 #define OSD_MSG_RADIO_CHANNEL 7
1320 /// Base id for messages generated from the commmand to property bridge.
1321 #define OSD_MSG_PROPERTY 0x100
1324 typedef struct mp_osd_msg mp_osd_msg_t;
1325 struct mp_osd_msg {
1326 /// Previous message on the stack.
1327 mp_osd_msg_t* prev;
1328 /// Message text.
1329 char msg[64];
1330 int id,level,started;
1331 /// Display duration in ms.
1332 unsigned time;
1335 /// OSD message stack.
1336 static mp_osd_msg_t* osd_msg_stack = NULL;
1339 * \brief Add a message on the OSD message stack
1341 * If a message with the same id is already present in the stack
1342 * it is pulled on top of the stack, otherwise a new message is created.
1346 static void set_osd_msg(int id, int level, int time, const char* fmt, ...) {
1347 mp_osd_msg_t *msg,*last=NULL;
1348 va_list va;
1349 int r;
1351 // look if the id is already in the stack
1352 for(msg = osd_msg_stack ; msg && msg->id != id ;
1353 last = msg, msg = msg->prev);
1354 // not found: alloc it
1355 if(!msg) {
1356 msg = calloc(1,sizeof(mp_osd_msg_t));
1357 msg->prev = osd_msg_stack;
1358 osd_msg_stack = msg;
1359 } else if(last) { // found, but it's not on top of the stack
1360 last->prev = msg->prev;
1361 msg->prev = osd_msg_stack;
1362 osd_msg_stack = msg;
1364 // write the msg
1365 va_start(va,fmt);
1366 r = vsnprintf(msg->msg, 64, fmt, va);
1367 va_end(va);
1368 if(r >= 64) msg->msg[63] = 0;
1369 // set id and time
1370 msg->id = id;
1371 msg->level = level;
1372 msg->time = time;
1377 * \brief Remove a message from the OSD stack
1379 * This function can be used to get rid of a message right away.
1383 static void rm_osd_msg(int id) {
1384 mp_osd_msg_t *msg,*last=NULL;
1386 // Search for the msg
1387 for(msg = osd_msg_stack ; msg && msg->id != id ;
1388 last = msg, msg = msg->prev);
1389 if(!msg) return;
1391 // Detach it from the stack and free it
1392 if(last)
1393 last->prev = msg->prev;
1394 else
1395 osd_msg_stack = msg->prev;
1396 free(msg);
1400 * \brief Remove all messages from the OSD stack
1404 static void clear_osd_msgs(void) {
1405 mp_osd_msg_t* msg = osd_msg_stack, *prev = NULL;
1406 while(msg) {
1407 prev = msg->prev;
1408 free(msg);
1409 msg = prev;
1411 osd_msg_stack = NULL;
1415 * \brief Get the current message from the OSD stack.
1417 * This function decrements the message timer and destroys the old ones.
1418 * The message that should be displayed is returned (if any).
1422 static mp_osd_msg_t* get_osd_msg(void) {
1423 mp_osd_msg_t *msg,*prev,*last = NULL;
1424 static unsigned last_update = 0;
1425 unsigned now = GetTimerMS();
1426 unsigned diff;
1427 char hidden_dec_done = 0;
1429 if(!last_update) last_update = now;
1430 diff = now >= last_update ? now - last_update : 0;
1432 last_update = now;
1434 // Look for the first message in the stack with high enough level.
1435 for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) {
1436 prev = msg->prev;
1437 if(msg->level > osd_level && hidden_dec_done) continue;
1438 // The message has a high enough level or it is the first hidden one
1439 // in both cases we decrement the timer or kill it.
1440 if(!msg->started || msg->time > diff) {
1441 if(msg->started) msg->time -= diff;
1442 else msg->started = 1;
1443 // display it
1444 if(msg->level <= osd_level) return msg;
1445 hidden_dec_done = 1;
1446 continue;
1448 // kill the message
1449 free(msg);
1450 if(last) {
1451 last->prev = prev;
1452 msg = last;
1453 } else {
1454 osd_msg_stack = prev;
1455 msg = NULL;
1458 // Nothing found
1459 return NULL;
1463 * \brief Display the OSD bar.
1465 * Display the OSD bar or fall back on a simple message.
1469 static void set_osd_bar(int type,const char* name,double min,double max,double val) {
1471 if(osd_level < 1) return;
1473 if(sh_video) {
1474 osd_visible = (GetTimerMS() + 1000) | 1;
1475 vo_osd_progbar_type = type;
1476 vo_osd_progbar_value = 256*(val-min)/(max-min);
1477 vo_osd_changed(OSDTYPE_PROGBAR);
1478 return;
1481 set_osd_msg(OSD_MSG_BAR,1,osd_duration,"%s: %d %%",
1482 name,ROUND(100*(val-min)/(max-min)));
1487 * \brief Update the OSD message line.
1489 * This function displays the current message on the vo OSD or on the term.
1490 * If the stack is empty and the OSD level is high enough the timer
1491 * is displayed (only on the vo OSD).
1495 static void update_osd_msg(void) {
1496 mp_osd_msg_t *msg;
1497 static char osd_text[64] = "";
1498 static char osd_text_timer[64];
1500 // we need some mem for vo_osd_text
1501 vo_osd_text = (unsigned char*)osd_text;
1503 // Look if we have a msg
1504 if((msg = get_osd_msg())) {
1505 if(strcmp(osd_text,msg->msg)) {
1506 strncpy((char*)osd_text, msg->msg, 63);
1507 if(sh_video) vo_osd_changed(OSDTYPE_OSD); else
1508 if(term_osd) mp_msg(MSGT_CPLAYER,MSGL_STATUS,"%s%s\n",term_osd_esc,msg->msg);
1510 return;
1513 if(sh_video) {
1514 // fallback on the timer
1515 if(osd_level>=2) {
1516 int len = demuxer_get_time_length(demuxer);
1517 int percentage = -1;
1518 char percentage_text[10];
1519 int pts = demuxer_get_current_time(demuxer);
1521 if (osd_show_percentage)
1522 percentage = demuxer_get_percent_pos(demuxer);
1524 if (percentage >= 0)
1525 snprintf(percentage_text, 9, " (%d%%)", percentage);
1526 else
1527 percentage_text[0] = 0;
1529 if (osd_level == 3)
1530 snprintf(osd_text_timer, 63,
1531 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1532 osd_function,pts/3600,(pts/60)%60,pts%60,
1533 len/3600,(len/60)%60,len%60,percentage_text);
1534 else
1535 snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s",
1536 osd_function,pts/3600,(pts/60)%60,
1537 pts%60,percentage_text);
1538 } else
1539 osd_text_timer[0]=0;
1541 // always decrement the percentage timer
1542 if(osd_show_percentage)
1543 osd_show_percentage--;
1545 if(strcmp(osd_text,osd_text_timer)) {
1546 strncpy(osd_text, osd_text_timer, 63);
1547 vo_osd_changed(OSDTYPE_OSD);
1549 return;
1552 // Clear the term osd line
1553 if(term_osd && osd_text[0]) {
1554 osd_text[0] = 0;
1555 printf("%s\n",term_osd_esc);
1559 ///@}
1560 // OSDMsgStack
1562 /// \defgroup Properties
1563 ///@{
1565 /// \defgroup GeneralProperties General properties
1566 /// \ingroup Properties
1567 ///@{
1569 /// OSD level (RW)
1570 static int mp_property_osdlevel(m_option_t* prop,int action,void* arg) {
1571 return m_property_choice(prop,action,arg,&osd_level);
1574 /// Playback speed (RW)
1575 static int mp_property_playback_speed(m_option_t* prop,int action,void* arg) {
1576 switch(action) {
1577 case M_PROPERTY_SET:
1578 if(!arg) return M_PROPERTY_ERROR;
1579 M_PROPERTY_CLAMP(prop,*(float*)arg);
1580 playback_speed = *(float*)arg;
1581 build_afilter_chain(sh_audio, &ao_data);
1582 return M_PROPERTY_OK;
1583 case M_PROPERTY_STEP_UP:
1584 case M_PROPERTY_STEP_DOWN:
1585 playback_speed += (arg ? *(float*)arg : 0.1) *
1586 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1587 M_PROPERTY_CLAMP(prop,playback_speed);
1588 build_afilter_chain(sh_audio, &ao_data);
1589 return M_PROPERTY_OK;
1591 return m_property_float_range(prop,action,arg,&playback_speed);
1594 /// filename with path (RO)
1595 static int mp_property_path(m_option_t* prop,int action,void* arg) {
1596 return m_property_string_ro(prop,action,arg,filename);
1599 /// filename without path (RO)
1600 static int mp_property_filename(m_option_t* prop,int action,void* arg) {
1601 char* f;
1602 if(!filename) return M_PROPERTY_UNAVAILABLE;
1603 if(((f = strrchr(filename,'/')) || (f = strrchr(filename,'\\'))) && f[1])
1604 f++;
1605 else
1606 f = filename;
1607 return m_property_string_ro(prop,action,arg,f);
1610 /// Demuxer name (RO)
1611 static int mp_property_demuxer(m_option_t* prop,int action,void* arg) {
1612 if(!demuxer) return M_PROPERTY_UNAVAILABLE;
1613 return m_property_string_ro(prop,action,arg,(char*)demuxer->desc->name);
1616 /// Position in the stream (RW)
1617 static int mp_property_stream_pos(m_option_t* prop,int action,void* arg) {
1618 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1619 if (!arg) return M_PROPERTY_ERROR;
1620 switch (action) {
1621 case M_PROPERTY_GET:
1622 *(off_t*)arg = stream_tell(demuxer->stream);
1623 return M_PROPERTY_OK;
1624 case M_PROPERTY_SET:
1625 M_PROPERTY_CLAMP(prop,*(off_t*)arg);
1626 stream_seek(demuxer->stream, *(off_t*)arg);
1627 return M_PROPERTY_OK;
1629 return M_PROPERTY_NOT_IMPLEMENTED;
1632 /// Stream start offset (RO)
1633 static int mp_property_stream_start(m_option_t* prop,int action,void* arg) {
1634 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1635 switch (action) {
1636 case M_PROPERTY_GET:
1637 *(off_t*)arg = demuxer->stream->start_pos;
1638 return M_PROPERTY_OK;
1640 return M_PROPERTY_NOT_IMPLEMENTED;
1643 /// Stream end offset (RO)
1644 static int mp_property_stream_end(m_option_t* prop,int action,void* arg) {
1645 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1646 switch (action) {
1647 case M_PROPERTY_GET:
1648 *(off_t*)arg = demuxer->stream->end_pos;
1649 return M_PROPERTY_OK;
1651 return M_PROPERTY_NOT_IMPLEMENTED;
1654 /// Stream length (RO)
1655 static int mp_property_stream_length(m_option_t* prop,int action,void* arg) {
1656 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1657 switch (action) {
1658 case M_PROPERTY_GET:
1659 *(off_t*)arg = demuxer->stream->end_pos - demuxer->stream->start_pos;
1660 return M_PROPERTY_OK;
1662 return M_PROPERTY_NOT_IMPLEMENTED;
1665 /// Media length in seconds (RO)
1666 static int mp_property_length(m_option_t* prop,int action,void* arg) {
1667 double len;
1669 if(!demuxer ||
1670 !(int)(len = demuxer_get_time_length(demuxer)))
1671 return M_PROPERTY_UNAVAILABLE;
1673 switch(action) {
1674 case M_PROPERTY_PRINT:
1675 if(!arg) return M_PROPERTY_ERROR;
1676 else {
1677 int h, m, s = len;
1678 h = s/3600;
1679 s -= h*3600;
1680 m = s/60;
1681 s -= m*60;
1682 *(char**)arg = malloc(20);
1683 if(h > 0) sprintf(*(char**)arg,"%d:%02d:%02d",h,m,s);
1684 else if(m > 0) sprintf(*(char**)arg,"%d:%02d",m,s);
1685 else sprintf(*(char**)arg,"%d",s);
1686 return M_PROPERTY_OK;
1688 break;
1690 return m_property_double_ro(prop,action,arg,len);
1693 ///@}
1695 /// \defgroup AudioProperties Audio properties
1696 /// \ingroup Properties
1697 ///@{
1699 /// Volume (RW)
1700 static int mp_property_volume(m_option_t* prop,int action,void* arg) {
1702 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1704 switch(action) {
1705 case M_PROPERTY_GET:
1706 if(!arg) return M_PROPERTY_ERROR;
1707 mixer_getbothvolume(&mixer,arg);
1708 return M_PROPERTY_OK;
1709 case M_PROPERTY_PRINT:{
1710 float vol;
1711 if(!arg) return M_PROPERTY_ERROR;
1712 mixer_getbothvolume(&mixer,&vol);
1713 return m_property_float_range(prop,action,arg,&vol);
1715 case M_PROPERTY_STEP_UP:
1716 case M_PROPERTY_STEP_DOWN:
1717 case M_PROPERTY_SET:
1718 break;
1719 default:
1720 return M_PROPERTY_NOT_IMPLEMENTED;
1723 if (edl_muted) return M_PROPERTY_DISABLED;
1724 user_muted = 0;
1726 switch(action) {
1727 case M_PROPERTY_SET:
1728 if(!arg) return M_PROPERTY_ERROR;
1729 M_PROPERTY_CLAMP(prop,*(float*)arg);
1730 mixer_setvolume(&mixer,*(float*)arg,*(float*)arg);
1731 return M_PROPERTY_OK;
1732 case M_PROPERTY_STEP_UP:
1733 if(arg && *(float*)arg <= 0)
1734 mixer_decvolume(&mixer);
1735 else
1736 mixer_incvolume(&mixer);
1737 return M_PROPERTY_OK;
1738 case M_PROPERTY_STEP_DOWN:
1739 if(arg && *(float*)arg <= 0)
1740 mixer_incvolume(&mixer);
1741 else
1742 mixer_decvolume(&mixer);
1743 return M_PROPERTY_OK;
1745 return M_PROPERTY_NOT_IMPLEMENTED;
1748 /// Mute (RW)
1749 static int mp_property_mute(m_option_t* prop,int action,void* arg) {
1751 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1753 switch(action) {
1754 case M_PROPERTY_SET:
1755 if(edl_muted) return M_PROPERTY_DISABLED;
1756 if(!arg) return M_PROPERTY_ERROR;
1757 if((!!*(int*)arg) != mixer.muted)
1758 mixer_mute(&mixer);
1759 user_muted = mixer.muted;
1760 return M_PROPERTY_OK;
1761 case M_PROPERTY_STEP_UP:
1762 case M_PROPERTY_STEP_DOWN:
1763 if(edl_muted) return M_PROPERTY_DISABLED;
1764 mixer_mute(&mixer);
1765 user_muted = mixer.muted;
1766 return M_PROPERTY_OK;
1767 case M_PROPERTY_PRINT:
1768 if(!arg) return M_PROPERTY_ERROR;
1769 if(edl_muted) {
1770 *(char**)arg = strdup(MSGTR_EnabledEdl);
1771 return M_PROPERTY_OK;
1773 default:
1774 return m_property_flag(prop,action,arg,&mixer.muted);
1779 /// Audio delay (RW)
1780 static int mp_property_audio_delay(m_option_t* prop,int action,void* arg) {
1781 if(!(sh_audio && sh_video)) return M_PROPERTY_UNAVAILABLE;
1782 switch(action) {
1783 case M_PROPERTY_SET:
1784 case M_PROPERTY_STEP_UP:
1785 case M_PROPERTY_STEP_DOWN:
1786 if(!arg) return M_PROPERTY_ERROR;
1787 else {
1788 float delay = audio_delay;
1789 m_property_delay(prop,action,arg,&audio_delay);
1790 if(sh_audio) sh_audio->delay -= audio_delay-delay;
1792 return M_PROPERTY_OK;
1793 default:
1794 return m_property_delay(prop,action,arg,&audio_delay);
1798 /// Audio codec tag (RO)
1799 static int mp_property_audio_format(m_option_t* prop,int action,void* arg) {
1800 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1801 return m_property_int_ro(prop,action,arg,sh_audio->format);
1804 /// Audio bitrate (RO)
1805 static int mp_property_audio_bitrate(m_option_t* prop,int action,void* arg) {
1806 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1807 return m_property_int_ro(prop,action,arg,sh_audio->i_bps);
1810 /// Samplerate (RO)
1811 static int mp_property_samplerate(m_option_t* prop,int action,void* arg) {
1812 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1813 return m_property_int_ro(prop,action,arg,sh_audio->samplerate);
1816 /// Number of channels (RO)
1817 static int mp_property_channels(m_option_t* prop,int action,void* arg) {
1818 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1819 switch(action) {
1820 case M_PROPERTY_PRINT:
1821 if(!arg) return M_PROPERTY_ERROR;
1822 switch(sh_audio->channels) {
1823 case 1: *(char**)arg = strdup("mono"); break;
1824 case 2: *(char**)arg = strdup("stereo"); break;
1825 default:
1826 *(char**)arg = malloc(32);
1827 sprintf(*(char**)arg,"%d channels",sh_audio->channels);
1829 return M_PROPERTY_OK;
1831 return m_property_int_ro(prop,action,arg,sh_audio->channels);
1834 /// Selected audio id (RW)
1835 static int mp_property_audio(m_option_t* prop,int action,void* arg) {
1836 int current_id = -1, tmp;
1838 switch(action) {
1839 case M_PROPERTY_GET:
1840 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1841 if(!arg) return M_PROPERTY_ERROR;
1842 *(int*)arg = audio_id;
1843 return M_PROPERTY_OK;
1844 case M_PROPERTY_PRINT:
1845 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1846 if(!arg) return M_PROPERTY_ERROR;
1848 if (audio_id < 0)
1849 *(char**)arg = strdup(MSGTR_Disabled);
1850 else {
1851 char lang[40] = MSGTR_Unknown;
1852 if (demuxer->type == DEMUXER_TYPE_MATROSKA)
1853 demux_mkv_get_audio_lang(demuxer, audio_id, lang, 9);
1854 #ifdef USE_DVDREAD
1855 else if(stream->type == STREAMTYPE_DVD) {
1856 int code = dvd_lang_from_aid(stream, audio_id);
1857 if (code) {
1858 lang[0] = code >> 8;
1859 lang[1] = code;
1860 lang[2] = 0;
1863 #endif
1865 #ifdef USE_DVDNAV
1866 else if(stream->type == STREAMTYPE_DVDNAV)
1867 dvdnav_lang_from_aid(stream, audio_id, lang);
1868 #endif
1869 *(char**)arg = malloc(64);
1870 snprintf(*(char**)arg, 64, "(%d) %s", audio_id, lang);
1872 return M_PROPERTY_OK;
1874 case M_PROPERTY_STEP_UP:
1875 case M_PROPERTY_SET:
1876 if(action==M_PROPERTY_SET && arg)
1877 tmp = *((int*)arg);
1878 else
1879 tmp = -1;
1880 current_id = demuxer->audio->id;
1881 audio_id = demuxer_switch_audio(demuxer, tmp);
1882 if(audio_id == -2 || (audio_id > -1 && demuxer->audio->id != current_id && current_id != -2))
1883 uninit_player(INITED_AO | INITED_ACODEC);
1884 if(audio_id > -1 && demuxer->audio->id != current_id) {
1885 sh_audio_t *sh2;
1886 sh2 = demuxer->a_streams[demuxer->audio->id];
1887 if(sh2) {
1888 sh2->ds = demuxer->audio;
1889 sh_audio = sh2;
1890 reinit_audio_chain();
1893 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
1894 return M_PROPERTY_OK;
1895 default:
1896 return M_PROPERTY_NOT_IMPLEMENTED;
1901 static int reinit_video_chain(void);
1902 /// Selected video id (RW)
1903 static int mp_property_video(m_option_t* prop,int action,void* arg) {
1904 int current_id = -1, tmp;
1906 switch(action) {
1907 case M_PROPERTY_GET:
1908 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1909 if(!arg) return M_PROPERTY_ERROR;
1910 *(int*)arg = video_id;
1911 return M_PROPERTY_OK;
1912 case M_PROPERTY_PRINT:
1913 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1914 if(!arg) return M_PROPERTY_ERROR;
1916 if (video_id < 0)
1917 *(char**)arg = strdup(MSGTR_Disabled);
1918 else {
1919 char lang[40] = MSGTR_Unknown;
1920 *(char**)arg = malloc(64);
1921 snprintf(*(char**)arg, 64, "(%d) %s", video_id, lang);
1923 return M_PROPERTY_OK;
1925 case M_PROPERTY_STEP_UP:
1926 case M_PROPERTY_SET:
1927 current_id = demuxer->video->id;
1928 if(action==M_PROPERTY_SET && arg)
1929 tmp = *((int*)arg);
1930 else
1931 tmp = -1;
1932 video_id = demuxer_switch_video(demuxer, tmp);
1933 if(video_id == -2 || (video_id > -1 && demuxer->video->id != current_id && current_id != -2))
1934 uninit_player(INITED_VCODEC | (fixed_vo && video_id != -2 ? 0 : INITED_VO));
1935 if(video_id > -1 && demuxer->video->id != current_id) {
1936 sh_video_t *sh2;
1937 sh2 = demuxer->v_streams[demuxer->video->id];
1938 if(sh2) {
1939 sh2->ds = demuxer->video;
1940 sh_video = sh2;
1941 reinit_video_chain();
1944 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
1945 return M_PROPERTY_OK;
1947 default:
1948 return M_PROPERTY_NOT_IMPLEMENTED;
1952 static int mp_property_program(m_option_t* prop,int action,void* arg) {
1953 demux_program_t prog;
1955 switch(action) {
1956 case M_PROPERTY_STEP_UP:
1957 case M_PROPERTY_SET:
1958 if(action==M_PROPERTY_SET && arg)
1959 prog.progid = *((int*)arg);
1960 else
1961 prog.progid = -1;
1962 if(demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) == DEMUXER_CTRL_NOTIMPL)
1963 return M_PROPERTY_ERROR;
1965 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid);
1966 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid);
1967 return M_PROPERTY_OK;
1969 default:
1970 return M_PROPERTY_NOT_IMPLEMENTED;
1974 ///@}
1976 /// \defgroup VideoProperties Video properties
1977 /// \ingroup Properties
1978 ///@{
1980 /// Fullscreen state (RW)
1981 static int mp_property_fullscreen(m_option_t* prop,int action,void* arg) {
1983 if(!video_out) return M_PROPERTY_UNAVAILABLE;
1985 switch(action) {
1986 case M_PROPERTY_SET:
1987 if(!arg) return M_PROPERTY_ERROR;
1988 M_PROPERTY_CLAMP(prop,*(int*)arg);
1989 if(vo_fs == !!*(int*)arg) return M_PROPERTY_OK;
1990 case M_PROPERTY_STEP_UP:
1991 case M_PROPERTY_STEP_DOWN:
1992 #ifdef HAVE_NEW_GUI
1993 if(use_gui) guiGetEvent(guiIEvent,(char*)MP_CMD_GUI_FULLSCREEN);
1994 else
1995 #endif
1996 if(vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
1997 return M_PROPERTY_OK;
1998 default:
1999 return m_property_flag(prop,action,arg,&vo_fs);
2003 static int mp_property_deinterlace(m_option_t* prop,int action,void* arg) {
2004 int deinterlace;
2005 vf_instance_t *vf;
2006 if (!sh_video || !sh_video->vfilter) return M_PROPERTY_UNAVAILABLE;
2007 vf = sh_video->vfilter;
2008 switch(action) {
2009 case M_PROPERTY_GET:
2010 if(!arg) return M_PROPERTY_ERROR;
2011 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
2012 return M_PROPERTY_OK;
2013 case M_PROPERTY_SET:
2014 if(!arg) return M_PROPERTY_ERROR;
2015 M_PROPERTY_CLAMP(prop,*(int*)arg);
2016 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
2017 return M_PROPERTY_OK;
2018 case M_PROPERTY_STEP_UP:
2019 case M_PROPERTY_STEP_DOWN:
2020 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
2021 deinterlace = !deinterlace;
2022 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
2023 return M_PROPERTY_OK;
2025 return M_PROPERTY_NOT_IMPLEMENTED;
2028 /// Panscan (RW)
2029 static int mp_property_panscan(m_option_t* prop,int action,void* arg) {
2031 if(!video_out || video_out->control(VOCTRL_GET_PANSCAN,NULL ) != VO_TRUE)
2032 return M_PROPERTY_UNAVAILABLE;
2034 switch(action) {
2035 case M_PROPERTY_SET:
2036 if(!arg) return M_PROPERTY_ERROR;
2037 M_PROPERTY_CLAMP(prop,*(float*)arg);
2038 vo_panscan = *(float*)arg;
2039 video_out->control(VOCTRL_SET_PANSCAN,NULL);
2040 return M_PROPERTY_OK;
2041 case M_PROPERTY_STEP_UP:
2042 case M_PROPERTY_STEP_DOWN:
2043 vo_panscan += (arg ? *(float*)arg : 0.1) *
2044 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2045 if(vo_panscan > 1) vo_panscan = 1;
2046 else if(vo_panscan < 0) vo_panscan = 0;
2047 video_out->control(VOCTRL_SET_PANSCAN,NULL);
2048 return M_PROPERTY_OK;
2049 default:
2050 return m_property_float_range(prop,action,arg,&vo_panscan);
2054 /// Helper to set vo flags.
2055 /** \ingroup PropertyImplHelper
2057 static int mp_property_vo_flag(m_option_t* prop,int action,void* arg,
2058 int vo_ctrl,int* vo_var) {
2060 if(!video_out) return M_PROPERTY_UNAVAILABLE;
2062 switch(action) {
2063 case M_PROPERTY_SET:
2064 if(!arg) return M_PROPERTY_ERROR;
2065 M_PROPERTY_CLAMP(prop,*(int*)arg);
2066 if(*vo_var == !!*(int*)arg) return M_PROPERTY_OK;
2067 case M_PROPERTY_STEP_UP:
2068 case M_PROPERTY_STEP_DOWN:
2069 if(vo_config_count) video_out->control(vo_ctrl, 0);
2070 return M_PROPERTY_OK;
2071 default:
2072 return m_property_flag(prop,action,arg,vo_var);
2076 /// Window always on top (RW)
2077 static int mp_property_ontop(m_option_t* prop,int action,void* arg) {
2078 return mp_property_vo_flag(prop,action,arg,VOCTRL_ONTOP,&vo_ontop);
2081 /// Display in the root window (RW)
2082 static int mp_property_rootwin(m_option_t* prop,int action,void* arg) {
2083 return mp_property_vo_flag(prop,action,arg,VOCTRL_ROOTWIN,&vo_rootwin);
2086 /// Show window borders (RW)
2087 static int mp_property_border(m_option_t* prop,int action,void* arg) {
2088 return mp_property_vo_flag(prop,action,arg,VOCTRL_BORDER,&vo_border);
2091 /// Framedropping state (RW)
2092 static int mp_property_framedropping(m_option_t* prop,int action,void* arg) {
2094 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2096 switch(action) {
2097 case M_PROPERTY_PRINT:
2098 if(!arg) return M_PROPERTY_ERROR;
2099 *(char**)arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
2100 (frame_dropping == 2 ? MSGTR_HardFrameDrop : MSGTR_Disabled));
2101 return M_PROPERTY_OK;
2102 default:
2103 return m_property_choice(prop,action,arg,&frame_dropping);
2107 /// Color settings, try to use vf/vo then fall back on TV. (RW)
2108 static int mp_property_gamma(m_option_t* prop,int action,void* arg) {
2109 int* gamma = prop->priv, r;
2111 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2113 if(gamma[0] == 1000) {
2114 gamma[0] = 0;
2115 get_video_colors (sh_video, prop->name, gamma);
2118 switch(action) {
2119 case M_PROPERTY_SET:
2120 if(!arg) return M_PROPERTY_ERROR;
2121 M_PROPERTY_CLAMP(prop,*(int*)arg);
2122 *gamma = *(int*)arg;
2123 r = set_video_colors(sh_video, prop->name, *gamma);
2124 if(r <= 0) break;
2125 return r;
2126 case M_PROPERTY_GET:
2127 if(!arg) return M_PROPERTY_ERROR;
2128 r = get_video_colors (sh_video, prop->name, arg);
2129 if(r <= 0) break;
2130 return r;
2131 case M_PROPERTY_STEP_UP:
2132 case M_PROPERTY_STEP_DOWN:
2133 *gamma += (arg ? *(int*)arg : 1) *
2134 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2135 M_PROPERTY_CLAMP(prop,*gamma);
2136 r = set_video_colors(sh_video, prop->name, *gamma);
2137 if(r <= 0) break;
2138 return r;
2139 default:
2140 return M_PROPERTY_NOT_IMPLEMENTED;
2143 #ifdef USE_TV
2144 if(demuxer->type == DEMUXER_TYPE_TV) {
2145 int l = strlen(prop->name);
2146 char tv_prop[3+l+1];
2147 sprintf(tv_prop,"tv_%s",prop->name);
2148 return mp_property_do(tv_prop,action,arg);
2150 #endif
2152 return M_PROPERTY_UNAVAILABLE;
2155 /// VSync (RW)
2156 static int mp_property_vsync(m_option_t* prop,int action,void* arg) {
2157 return m_property_flag(prop,action,arg,&vo_vsync);
2160 /// Video codec tag (RO)
2161 static int mp_property_video_format(m_option_t* prop,int action,void* arg) {
2162 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2163 return m_property_int_ro(prop,action,arg,sh_video->format);
2166 /// Video bitrate (RO)
2167 static int mp_property_video_bitrate(m_option_t* prop,int action,void* arg) {
2168 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2169 return m_property_int_ro(prop,action,arg,sh_video->i_bps);
2172 /// Video display width (RO)
2173 static int mp_property_width(m_option_t* prop,int action,void* arg) {
2174 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2175 return m_property_int_ro(prop,action,arg,sh_video->disp_w);
2178 /// Video display height (RO)
2179 static int mp_property_height(m_option_t* prop,int action,void* arg) {
2180 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2181 return m_property_int_ro(prop,action,arg,sh_video->disp_h);
2184 /// Video fps (RO)
2185 static int mp_property_fps(m_option_t* prop,int action,void* arg) {
2186 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2187 return m_property_float_ro(prop,action,arg,sh_video->fps);
2190 /// Video aspect (RO)
2191 static int mp_property_aspect(m_option_t* prop,int action,void* arg) {
2192 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2193 return m_property_float_ro(prop,action,arg,sh_video->aspect);
2196 ///@}
2198 /// \defgroup SubProprties Subtitles properties
2199 /// \ingroup Properties
2200 ///@{
2202 /// Text subtitle position (RW)
2203 static int mp_property_sub_pos(m_option_t* prop,int action,void* arg) {
2204 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2206 switch(action) {
2207 case M_PROPERTY_SET:
2208 if(!arg) return M_PROPERTY_ERROR;
2209 case M_PROPERTY_STEP_UP:
2210 case M_PROPERTY_STEP_DOWN:
2211 vo_osd_changed(OSDTYPE_SUBTITLE);
2212 default:
2213 return m_property_int_range(prop,action,arg,&sub_pos);
2217 /// Selected subtitles (RW)
2218 static int mp_property_sub(m_option_t* prop,int action,void* arg) {
2219 int source = -1, reset_spu = 0;
2220 char* sub_name;
2222 if(global_sub_size <= 0) return M_PROPERTY_UNAVAILABLE;
2224 switch(action) {
2225 case M_PROPERTY_GET:
2226 if(!arg) return M_PROPERTY_ERROR;
2227 *(int*)arg = global_sub_pos;
2228 return M_PROPERTY_OK;
2229 case M_PROPERTY_PRINT:
2230 if(!arg) return M_PROPERTY_ERROR;
2231 *(char**)arg = malloc(64);
2232 (*(char**)arg)[63] = 0;
2233 sub_name = 0;
2234 if(subdata)
2235 sub_name = subdata->filename;
2236 #ifdef USE_ASS
2237 if (ass_track && ass_track->name)
2238 sub_name = ass_track->name;
2239 #endif
2240 if(sub_name) {
2241 char *tmp,*tmp2;
2242 tmp = sub_name;
2243 if ((tmp2 = strrchr(tmp, '/')))
2244 tmp = tmp2+1;
2246 snprintf(*(char**)arg, 63, "(%d) %s%s",
2247 set_of_sub_pos + 1,
2248 strlen(tmp) < 20 ? "" : "...",
2249 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
2250 return M_PROPERTY_OK;
2253 #ifdef USE_DVDNAV
2254 if(stream->type==STREAMTYPE_DVDNAV) {
2255 if(vo_spudec && dvdsub_id >= 0) {
2256 unsigned char lang[3];
2257 if(dvdnav_lang_from_sid(stream, dvdsub_id, lang)) {
2258 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, lang);
2259 return M_PROPERTY_OK;
2263 #endif
2265 if (demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
2266 char lang[40] = MSGTR_Unknown;
2267 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
2268 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, lang);
2269 return M_PROPERTY_OK;
2271 #ifdef HAVE_OGGVORBIS
2272 if (demuxer->type == DEMUXER_TYPE_OGG && d_dvdsub && dvdsub_id >= 0) {
2273 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
2274 if (!lang) lang = MSGTR_Unknown;
2275 snprintf(*(char**)arg, 63, "(%d) %s",
2276 dvdsub_id, lang);
2277 return M_PROPERTY_OK;
2279 #endif
2280 if (vo_vobsub && vobsub_id >= 0) {
2281 const char *language = MSGTR_Unknown;
2282 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
2283 snprintf(*(char**)arg, 63, "(%d) %s",
2284 vobsub_id, language ? language : MSGTR_Unknown);
2285 return M_PROPERTY_OK;
2287 #ifdef USE_DVDREAD
2288 if (vo_spudec && stream->type == STREAMTYPE_DVD && dvdsub_id >= 0) {
2289 char lang[3];
2290 int code = dvd_lang_from_sid(stream, dvdsub_id);
2291 lang[0] = code >> 8;
2292 lang[1] = code;
2293 lang[2] = 0;
2294 snprintf(*(char**)arg, 63, "(%d) %s",
2295 dvdsub_id, lang);
2296 return M_PROPERTY_OK;
2298 #endif
2299 if (dvdsub_id >= 0) {
2300 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
2301 return M_PROPERTY_OK;
2303 snprintf(*(char**)arg, 63, MSGTR_Disabled);
2304 return M_PROPERTY_OK;
2306 case M_PROPERTY_SET:
2307 if(!arg) return M_PROPERTY_ERROR;
2308 if(*(int*)arg < -1) *(int*)arg = -1;
2309 else if(*(int*)arg >= global_sub_size) *(int*)arg = global_sub_size-1;
2310 global_sub_pos = *(int*)arg;
2311 break;
2312 case M_PROPERTY_STEP_UP:
2313 global_sub_pos += 2;
2314 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
2315 break;
2316 case M_PROPERTY_STEP_DOWN:
2317 global_sub_pos += global_sub_size+1;
2318 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
2319 break;
2320 default:
2321 return M_PROPERTY_NOT_IMPLEMENTED;
2324 if (global_sub_pos >= 0)
2325 source = sub_source();
2327 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
2328 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
2329 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
2330 global_sub_indices[SUB_SOURCE_SUBS],
2331 global_sub_indices[SUB_SOURCE_DEMUX],
2332 global_sub_pos, source);
2334 set_of_sub_pos = -1;
2335 subdata = NULL;
2336 vo_sub_last = vo_sub = NULL;
2338 vobsub_id = -1;
2339 dvdsub_id = -1;
2340 if (d_dvdsub) {
2341 if(d_dvdsub->id > -2) reset_spu = 1;
2342 d_dvdsub->id = -2;
2344 #ifdef USE_ASS
2345 ass_track = 0;
2346 #endif
2348 if (source == SUB_SOURCE_VOBSUB) {
2349 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
2350 } else if (source == SUB_SOURCE_SUBS) {
2351 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
2352 #ifdef USE_ASS
2353 if (ass_enabled && set_of_ass_tracks[set_of_sub_pos])
2354 ass_track = set_of_ass_tracks[set_of_sub_pos];
2355 else
2356 #endif
2358 subdata = set_of_subtitles[set_of_sub_pos];
2359 vo_osd_changed(OSDTYPE_SUBTITLE);
2361 } else if (source == SUB_SOURCE_DEMUX) {
2362 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
2363 if (d_dvdsub) {
2364 #ifdef USE_DVDREAD
2365 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
2366 d_dvdsub->id = dvdsub_id;
2367 spudec_reset(vo_spudec);
2369 #endif
2371 #ifdef USE_DVDNAV
2372 if (vo_spudec && stream->type == STREAMTYPE_DVDNAV) {
2373 d_dvdsub->id = dvdsub_id;
2374 spudec_reset(vo_spudec);
2376 #endif
2377 if (stream->type != STREAMTYPE_DVD && stream->type != STREAMTYPE_DVDNAV) {
2378 int i = 0;
2379 for (d_dvdsub->id = 0; d_dvdsub->id < MAX_S_STREAMS; d_dvdsub->id++) {
2380 if (demuxer->s_streams[d_dvdsub->id]) {
2381 if (i == dvdsub_id) break;
2382 i++;
2385 d_dvdsub->sh = demuxer->s_streams[d_dvdsub->id];
2387 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
2388 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
2390 if (d_dvdsub->sh && d_dvdsub->id >= 0) {
2391 sh_sub_t *sh = d_dvdsub->sh;
2392 if (sh->type == 'v')
2393 init_vo_spudec();
2394 #ifdef USE_ASS
2395 else if (ass_enabled && sh->type == 'a')
2396 ass_track = sh->ass_track;
2397 #endif
2400 } else { // off
2401 vo_osd_changed(OSDTYPE_SUBTITLE);
2402 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2404 #ifdef USE_DVDREAD
2405 if (vo_spudec && (stream->type == STREAMTYPE_DVD || stream->type == STREAMTYPE_DVDNAV) && dvdsub_id < 0 && reset_spu) {
2406 dvdsub_id = -2;
2407 d_dvdsub->id = dvdsub_id;
2408 spudec_reset(vo_spudec);
2410 #endif
2412 return M_PROPERTY_OK;
2415 /// Subtitle delay (RW)
2416 static int mp_property_sub_delay(m_option_t* prop,int action,void* arg) {
2417 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2418 return m_property_delay(prop,action,arg,&sub_delay);
2421 /// Alignment of text subtitles (RW)
2422 static int mp_property_sub_alignment(m_option_t* prop,int action,void* arg) {
2423 char* name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
2425 if(!sh_video || global_sub_pos < 0 || sub_source() != SUB_SOURCE_SUBS)
2426 return M_PROPERTY_UNAVAILABLE;
2428 switch(action) {
2429 case M_PROPERTY_PRINT:
2430 if(!arg) return M_PROPERTY_ERROR;
2431 M_PROPERTY_CLAMP(prop,sub_alignment);
2432 *(char**)arg = strdup(name[sub_alignment]);
2433 return M_PROPERTY_OK;
2434 case M_PROPERTY_SET:
2435 if(!arg) return M_PROPERTY_ERROR;
2436 case M_PROPERTY_STEP_UP:
2437 case M_PROPERTY_STEP_DOWN:
2438 vo_osd_changed(OSDTYPE_SUBTITLE);
2439 default:
2440 return m_property_choice(prop,action,arg,&sub_alignment);
2444 /// Subtitle visibility (RW)
2445 static int mp_property_sub_visibility(m_option_t* prop,int action,void* arg) {
2446 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2448 switch(action) {
2449 case M_PROPERTY_SET:
2450 if(!arg) return M_PROPERTY_ERROR;
2451 case M_PROPERTY_STEP_UP:
2452 case M_PROPERTY_STEP_DOWN:
2453 vo_osd_changed(OSDTYPE_SUBTITLE);
2454 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2455 default:
2456 return m_property_flag(prop,action,arg,&sub_visibility);
2460 /// Show only forced subtitles (RW)
2461 static int mp_property_sub_forced_only(m_option_t* prop,int action,void* arg) {
2462 if(!vo_spudec) return M_PROPERTY_UNAVAILABLE;
2464 switch(action) {
2465 case M_PROPERTY_SET:
2466 if(!arg) return M_PROPERTY_ERROR;
2467 case M_PROPERTY_STEP_UP:
2468 case M_PROPERTY_STEP_DOWN:
2469 m_property_flag(prop,action,arg,&forced_subs_only);
2470 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
2471 return M_PROPERTY_OK;
2472 default:
2473 return m_property_flag(prop,action,arg,&forced_subs_only);
2478 ///@}
2480 /// \defgroup TVProperties TV properties
2481 /// \ingroup Properties
2482 ///@{
2484 #ifdef USE_TV
2486 /// TV color settings (RW)
2487 static int mp_property_tv_color(m_option_t* prop,int action,void* arg) {
2488 int r,val;
2489 tvi_handle_t* tvh = demuxer->priv;
2490 if(demuxer->type != DEMUXER_TYPE_TV || !tvh) return M_PROPERTY_UNAVAILABLE;
2492 switch(action) {
2493 case M_PROPERTY_SET:
2494 if(!arg) return M_PROPERTY_ERROR;
2495 M_PROPERTY_CLAMP(prop,*(int*)arg);
2496 return tv_set_color_options(tvh,(int)prop->priv,*(int*)arg);
2497 case M_PROPERTY_GET:
2498 return tv_get_color_options(tvh,(int)prop->priv,arg);
2499 case M_PROPERTY_STEP_UP:
2500 case M_PROPERTY_STEP_DOWN:
2501 if((r = tv_get_color_options(tvh,(int)prop->priv,&val)) >= 0) {
2502 if(!r) return M_PROPERTY_ERROR;
2503 val += (arg ? *(int*)arg : 1) *
2504 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2505 M_PROPERTY_CLAMP(prop,val);
2506 return tv_set_color_options(tvh,(int)prop->priv,val);
2508 return M_PROPERTY_ERROR;
2510 return M_PROPERTY_NOT_IMPLEMENTED;
2513 #endif
2515 ///@}
2517 /// All properties available in MPlayer.
2518 /** \ingroup Properties
2520 static m_option_t mp_properties[] = {
2521 // General
2522 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2523 M_OPT_RANGE, 0, 3, NULL },
2524 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2525 M_OPT_RANGE, 0.01, 100.0, NULL },
2526 { "filename", mp_property_filename, CONF_TYPE_STRING,
2527 0, 0, 0, NULL },
2528 { "path", mp_property_path, CONF_TYPE_STRING,
2529 0, 0, 0, NULL },
2530 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2531 0, 0, 0, NULL },
2532 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2533 M_OPT_MIN, 0, 0, NULL },
2534 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2535 M_OPT_MIN, 0, 0, NULL },
2536 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2537 M_OPT_MIN, 0, 0, NULL },
2538 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2539 M_OPT_MIN, 0, 0, NULL },
2540 { "length", mp_property_length, CONF_TYPE_DOUBLE,
2541 0, 0, 0, NULL },
2543 // Audio
2544 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2545 M_OPT_RANGE, 0, 100, NULL },
2546 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2547 M_OPT_RANGE, 0, 1, NULL },
2548 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2549 M_OPT_RANGE, -100, 100, NULL },
2550 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2551 0, 0, 0, NULL },
2552 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2553 0, 0, 0, NULL },
2554 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2555 0, 0, 0, NULL },
2556 { "channels", mp_property_channels, CONF_TYPE_INT,
2557 0, 0, 0, NULL },
2558 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2559 CONF_RANGE, -2, MAX_A_STREAMS-1, NULL },
2561 // Video
2562 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2563 M_OPT_RANGE, 0, 1, NULL },
2564 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2565 M_OPT_RANGE, 0, 1, NULL },
2566 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2567 M_OPT_RANGE, 0, 1, NULL },
2568 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2569 M_OPT_RANGE, 0, 1, NULL },
2570 { "border", mp_property_border, CONF_TYPE_FLAG,
2571 M_OPT_RANGE, 0, 1, NULL },
2572 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2573 M_OPT_RANGE, 0, 2, NULL },
2574 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2575 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2576 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2577 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2578 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2579 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2580 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2581 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2582 { "hue", mp_property_gamma, CONF_TYPE_INT,
2583 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2584 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2585 M_OPT_RANGE, 0, 1, NULL },
2586 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2587 M_OPT_RANGE, 0, 1, NULL },
2588 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2589 0, 0, 0, NULL },
2590 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2591 0, 0, 0, NULL },
2592 { "width", mp_property_width, CONF_TYPE_INT,
2593 0, 0, 0, NULL },
2594 { "height", mp_property_height, CONF_TYPE_INT,
2595 0, 0, 0, NULL },
2596 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2597 0, 0, 0, NULL },
2598 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2599 0, 0, 0, NULL },
2600 { "switch_video", mp_property_video, CONF_TYPE_INT,
2601 CONF_RANGE, -2, MAX_V_STREAMS-1, NULL },
2602 { "switch_program", mp_property_program, CONF_TYPE_INT,
2603 CONF_RANGE, -1, 65535, NULL },
2605 // Subs
2606 { "sub", mp_property_sub, CONF_TYPE_INT,
2607 M_OPT_MIN, -1, 0, NULL },
2608 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2609 0, 0, 0, NULL },
2610 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2611 M_OPT_RANGE, 0, 100, NULL },
2612 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2613 M_OPT_RANGE, 0, 2, NULL },
2614 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2615 M_OPT_RANGE, 0, 1, NULL },
2616 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2617 M_OPT_RANGE, 0, 1, NULL },
2619 #ifdef USE_TV
2620 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2621 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_BRIGHTNESS },
2622 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2623 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_CONTRAST },
2624 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2625 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_SATURATION },
2626 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2627 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_HUE },
2628 #endif
2630 { NULL, NULL, NULL, 0, 0, 0, NULL }
2633 m_option_t* mp_property_find(const char* name) {
2634 return m_option_list_find(mp_properties,name);
2637 int mp_property_do(const char* name,int action, void* val) {
2638 m_option_t* p = mp_property_find(name);
2639 if(!p) return M_PROPERTY_UNAVAILABLE;
2640 return m_property_do(p,action,val);
2643 ///@}
2644 // Properties group
2648 * \defgroup Command2Property Command to property bridge
2650 * It is used to handle most commands that just set a property
2651 * and optionally display something on the OSD.
2652 * Two kinds of commands are handled: adjust or toggle.
2654 * Adjust commands take 1 or 2 parameters: <value> <abs>
2655 * If <abs> is non-zero the property is set to the given value
2656 * otherwise it is adjusted.
2658 * Toggle commands take 0 or 1 parameters. With no parameter
2659 * or a value less than the property minimum it just steps the
2660 * property to its next value. Otherwise it sets it to the given
2661 * value.
2666 /// List of the commands that can be handled by setting a property.
2667 static struct {
2668 /// property name
2669 const char* name;
2670 /// cmd id
2671 int cmd;
2672 /// set/adjust or toggle command
2673 int toggle;
2674 /// progressbar type
2675 int osd_progbar;
2676 /// osd msg id if it must be shared
2677 int osd_id;
2678 /// osd msg template
2679 const char* osd_msg;
2680 } set_prop_cmd[] = {
2681 // audio
2682 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2683 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2684 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2685 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2686 // video
2687 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2688 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2689 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2690 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2691 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2692 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2693 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2694 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2695 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2696 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2697 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2698 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2699 // subs
2700 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2701 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2702 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2703 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2704 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2705 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2706 #ifdef USE_TV
2707 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2708 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2709 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2710 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2711 #endif
2712 { NULL, 0, 0, 0, -1, NULL }
2715 /// Handle commands that set a property.
2716 static int set_property_command(mp_cmd_t* cmd) {
2717 int i,r;
2718 m_option_t* prop;
2720 // look for the command
2721 for(i = 0 ; set_prop_cmd[i].name ; i++)
2722 if(set_prop_cmd[i].cmd == cmd->id) break;
2723 if(!set_prop_cmd[i].name) return 0;
2725 // get the property
2726 prop = mp_property_find(set_prop_cmd[i].name);
2727 if(!prop) return 0;
2729 // toggle command
2730 if(set_prop_cmd[i].toggle) {
2731 // set to value
2732 if(cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2733 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v.i);
2734 else
2735 r = m_property_do(prop,M_PROPERTY_STEP_UP,NULL);
2736 } else if(cmd->args[1].v.i) //set
2737 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v);
2738 else // adjust
2739 r = m_property_do(prop,M_PROPERTY_STEP_UP,&cmd->args[0].v);
2741 if(r <= 0) return 1;
2743 if(set_prop_cmd[i].osd_progbar) {
2744 if(prop->type == CONF_TYPE_INT) {
2745 if(m_property_do(prop,M_PROPERTY_GET,&r) > 0)
2746 set_osd_bar(set_prop_cmd[i].osd_progbar,
2747 set_prop_cmd[i].osd_msg,
2748 prop->min,prop->max,r);
2749 } else if(prop->type == CONF_TYPE_FLOAT) {
2750 float f;
2751 if(m_property_do(prop,M_PROPERTY_GET,&f) > 0)
2752 set_osd_bar(set_prop_cmd[i].osd_progbar,set_prop_cmd[i].osd_msg,
2753 prop->min,prop->max,f);
2754 } else
2755 mp_msg(MSGT_CPLAYER,MSGL_ERR, "Property use an unsupported type.\n");
2756 return 1;
2759 if(set_prop_cmd[i].osd_msg) {
2760 char* val = m_property_print(prop);
2761 if(val) {
2762 set_osd_msg(set_prop_cmd[i].osd_id >= 0 ? set_prop_cmd[i].osd_id :
2763 OSD_MSG_PROPERTY+i,1,osd_duration,
2764 set_prop_cmd[i].osd_msg,val);
2765 free(val);
2768 return 1;
2771 static void reinit_audio_chain(void) {
2772 if(sh_audio){
2773 current_module="init_audio_codec";
2774 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2775 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
2776 sh_audio=d_audio->sh=NULL; // failed to init :(
2777 d_audio->id = -2;
2778 return;
2779 } else
2780 inited_flags|=INITED_ACODEC;
2781 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2784 //const ao_info_t *info=audio_out->info;
2785 current_module="af_preinit";
2786 ao_data.samplerate=force_srate;
2787 ao_data.channels=0;
2788 ao_data.format=audio_output_format;
2789 #if 1
2790 // first init to detect best values
2791 if(!preinit_audio_filters(sh_audio,
2792 // input:
2793 (int)(sh_audio->samplerate*playback_speed),
2794 sh_audio->channels, sh_audio->sample_format,
2795 // output:
2796 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){
2797 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2798 exit_player(MSGTR_Exit_error);
2800 #endif
2801 current_module="ao2_init";
2802 if(!(audio_out=init_best_audio_out(audio_driver_list,
2803 0, // plugin flag
2804 ao_data.samplerate,
2805 ao_data.channels,
2806 ao_data.format,0))){
2807 // FAILED:
2808 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2809 uninit_player(INITED_ACODEC); // close codec
2810 sh_audio=d_audio->sh=NULL; // -> nosound
2811 d_audio->id = -2;
2812 return;
2813 } else {
2814 // SUCCESS:
2815 inited_flags|=INITED_AO;
2816 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2817 audio_out->info->short_name,
2818 ao_data.samplerate, ao_data.channels,
2819 af_fmt2str_short(ao_data.format),
2820 af_fmt2bits(ao_data.format)/8 );
2821 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2822 audio_out->info->name, audio_out->info->author);
2823 if(strlen(audio_out->info->comment) > 0)
2824 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2825 // init audio filters:
2826 #if 1
2827 current_module="af_init";
2828 if(!build_afilter_chain(sh_audio, &ao_data)) {
2829 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2830 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2831 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2832 // sh_audio=d_audio->sh=NULL; // -> nosound
2834 #endif
2836 mixer.audio_out = audio_out;
2837 mixer.volstep = volstep;
2842 ///@}
2843 // Command2Property
2846 // Return pts value corresponding to the end point of audio written to the
2847 // ao so far.
2848 static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio)
2850 // first calculate the end pts of audio that has been output by decoder
2851 double a_pts = sh_audio->pts;
2852 if (a_pts != MP_NOPTS_VALUE)
2853 // Good, decoder supports new way of calculating audio pts.
2854 // sh_audio->pts is the timestamp of the latest input packet with
2855 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2856 // the amount of bytes the decoder has written after that timestamp.
2857 a_pts += sh_audio->pts_bytes / (double) sh_audio->o_bps;
2858 else {
2859 // Decoder doesn't support new way of calculating pts (or we're
2860 // being called before it has decoded anything with known timestamp).
2861 // Use the old method of audio pts calculation: take the timestamp
2862 // of last packet with known pts the decoder has read data from,
2863 // and add amount of bytes read after the beginning of that packet
2864 // divided by input bps. This will be inaccurate if the input/output
2865 // ratio is not constant for every audio packet or if it is constant
2866 // but not accurately known in sh_audio->i_bps.
2868 a_pts = d_audio->pts;
2869 // ds_tell_pts returns bytes read after last timestamp from
2870 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2871 // it has read but not decoded
2872 if (sh_audio->i_bps)
2873 a_pts += (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len) /
2874 (double)sh_audio->i_bps;
2876 // Now a_pts hopefully holds the pts for end of audio from decoder.
2877 // Substract data in buffers between decoder and audio out.
2879 // Decoded but not filtered
2880 a_pts -= sh_audio->a_buffer_len / (double)sh_audio->o_bps;
2882 // Data that was ready for ao but was buffered because ao didn't fully
2883 // accept everything to internal buffers yet
2884 a_pts -= sh_audio->a_out_buffer_len * playback_speed / (double)ao_data.bps;
2886 return a_pts;
2889 // Return pts value corresponding to currently playing audio.
2890 static double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio,
2891 ao_functions_t *audio_out)
2893 return written_audio_pts(sh_audio, d_audio) - playback_speed *
2894 audio_out->get_delay();
2897 static void update_subtitles(void)
2899 unsigned char *packet=NULL;
2900 int len;
2901 char type = d_dvdsub->sh ? ((sh_sub_t *)d_dvdsub->sh)->type : 'v';
2902 // find sub
2903 if (subdata) {
2904 double pts = sh_video->pts;
2905 if (sub_fps==0) sub_fps = sh_video->fps;
2906 current_module = "find_sub";
2907 if (pts > sub_last_pts || pts < sub_last_pts-1.0) {
2908 find_sub(subdata, (pts+sub_delay) *
2909 (subdata->sub_uses_time ? 100. : sub_fps));
2910 if (vo_sub) vo_sub_last = vo_sub;
2911 // FIXME! frame counter...
2912 sub_last_pts = pts;
2916 // DVD sub:
2917 if (vo_config_count && vo_spudec && type == 'v') {
2918 int timestamp;
2919 current_module = "spudec";
2920 spudec_heartbeat(vo_spudec, 90000*sh_video->timer);
2921 /* Get a sub packet from the DVD or a vobsub and make a timestamp
2922 * relative to sh_video->timer */
2923 while(1) {
2924 // Vobsub
2925 len = 0;
2926 if (vo_vobsub) {
2927 if (sh_video->pts+sub_delay >= 0) {
2928 len = vobsub_get_packet(vo_vobsub, sh_video->pts+sub_delay,
2929 (void**)&packet, &timestamp);
2930 if (len > 0) {
2931 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
2932 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);
2935 } else {
2936 // DVD sub
2937 len = ds_get_packet_sub(d_dvdsub, (unsigned char**)&packet);
2938 if (len > 0) {
2939 // XXX This is wrong, sh_video->pts can be arbitrarily
2940 // much behind demuxing position. Unfortunately using
2941 // d_video->pts which would have been the simplest
2942 // improvement doesn't work because mpeg specific hacks
2943 // in video.c set d_video->pts to 0.
2944 float x = d_dvdsub->pts - sh_video->pts;
2945 if (x > -20 && x < 20) // prevent missing subs on pts reset
2946 timestamp = 90000*(sh_video->timer + d_dvdsub->pts
2947 + sub_delay - sh_video->pts);
2948 else timestamp = 90000*(sh_video->timer + sub_delay);
2949 mp_dbg(MSGT_CPLAYER, MSGL_V, "\rDVD sub: len=%d "
2950 "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len,
2951 sh_video->pts, d_dvdsub->pts, timestamp);
2954 if (len<=0 || !packet) break;
2955 if (timestamp >= 0)
2956 spudec_assemble(vo_spudec, packet, len, timestamp);
2959 if (spudec_changed(vo_spudec))
2960 vo_osd_changed(OSDTYPE_SPU);
2961 } else if (dvdsub_id >= 0 && type == 't') {
2962 double pts = MP_NOPTS_VALUE;
2963 while (d_dvdsub->first) {
2964 double nextpts = ds_get_next_pts(d_dvdsub);
2965 if (nextpts == MP_NOPTS_VALUE || nextpts - sub_delay > sh_video->pts)
2966 break;
2967 len = ds_get_packet_sub(d_dvdsub, &packet);
2968 pts = nextpts - sub_delay;
2970 if (pts != MP_NOPTS_VALUE) {
2971 static subtitle subs;
2972 sub_clear_text(&subs, MP_NOPTS_VALUE);
2973 sub_add_text(&subs, packet, len, MP_NOPTS_VALUE);
2974 vo_sub = &subs;
2975 vo_osd_changed(OSDTYPE_SUBTITLE);
2978 current_module=NULL;
2981 static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video)
2983 unsigned char *start;
2984 int in_size;
2985 int hit_eof=0;
2986 double pts;
2988 while (1) {
2989 void *decoded_frame;
2990 current_module = "decode video";
2991 // XXX Time used in this call is not counted in any performance
2992 // timer now, OSD is not updated correctly for filter-added frames
2993 if (vf_output_queued_frame(sh_video->vfilter))
2994 break;
2995 current_module = "video_read_frame";
2996 in_size = ds_get_packet_pts(d_video, &start, &pts);
2997 if (in_size < 0) {
2998 // try to extract last frames in case of decoder lag
2999 in_size = 0;
3000 pts = 1e300;
3001 hit_eof = 1;
3003 if (in_size > max_framesize)
3004 max_framesize = in_size;
3005 if (pts == MP_NOPTS_VALUE)
3006 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts value from demuxer MISSING\n");
3007 current_module = "decode video";
3008 decoded_frame = decode_video(sh_video, start, in_size, 0, pts);
3009 if (decoded_frame) {
3010 update_subtitles();
3011 update_osd_msg();
3012 current_module = "filter video";
3013 if (filter_video(sh_video, decoded_frame, sh_video->pts))
3014 break;
3016 if (hit_eof)
3017 return 0;
3019 return 1;
3022 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy) {
3023 //remove the borders, if any, and rescale to the range [0,1],[0,1]
3024 if(vo_fs) { //we are in full-screen mode
3025 if(vo_screenwidth > vo_dwidth) //there are borders along the x axis
3026 ix -= (vo_screenwidth - vo_dwidth) / 2;
3027 if(vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
3028 iy -= (vo_screenheight - vo_dheight) / 2;
3030 if(ix < 0 || ix > vo_dwidth) {*dx = *dy = -1.0; return; } //we are on one of the borders
3031 if(iy < 0 || iy > vo_dheight) {*dx = *dy = -1.0; return; } //we are on one of the borders
3034 *dx = (double) ix / (double) vo_dwidth;
3035 *dy = (double) iy / (double) vo_dheight;
3037 mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
3038 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth, vo_dheight, vo_fs);
3041 #ifdef HAVE_RTC
3042 int rtc_fd = -1;
3043 #endif
3045 static float timing_sleep(float time_frame)
3047 #ifdef HAVE_RTC
3048 if (rtc_fd >= 0){
3049 // -------- RTC -----------
3050 current_module="sleep_rtc";
3051 while (time_frame > 0.000) {
3052 unsigned long rtc_ts;
3053 if (read(rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
3054 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
3055 time_frame -= GetRelativeTime();
3057 } else
3058 #endif
3059 #ifdef SYS_DARWIN
3061 current_module = "sleep_darwin";
3062 while (time_frame > 0.005) {
3063 usec_sleep(1000000*time_frame);
3064 time_frame -= GetRelativeTime();
3067 #else
3069 // assume kernel HZ=100 for softsleep, works with larger HZ but with
3070 // unnecessarily high CPU usage
3071 float margin = softsleep ? 0.011 : 0;
3072 current_module = "sleep_timer";
3073 while (time_frame > margin) {
3074 usec_sleep(1000000 * (time_frame - margin));
3075 time_frame -= GetRelativeTime();
3077 if (softsleep){
3078 current_module = "sleep_soft";
3079 if (time_frame < 0)
3080 mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
3081 while (time_frame > 0)
3082 time_frame-=GetRelativeTime(); // burn the CPU
3085 #endif /* SYS_DARWIN */
3086 return time_frame;
3089 static void adjust_sync_and_print_status(int between_frames, float timing_error)
3091 current_module="av_sync";
3093 if(sh_audio){
3094 double a_pts, v_pts;
3096 if (autosync)
3098 * If autosync is enabled, the value for delay must be calculated
3099 * a bit differently. It is set only to the difference between
3100 * the audio and video timers. Any attempt to include the real
3101 * or corrected delay causes the pts_correction code below to
3102 * try to correct for the changes in delay which autosync is
3103 * trying to measure. This keeps the two from competing, but still
3104 * allows the code to correct for PTS drift *only*. (Using a delay
3105 * value here, even a "corrected" one, would be incompatible with
3106 * autosync mode.)
3108 a_pts = written_audio_pts(sh_audio, d_audio) - sh_audio->delay;
3109 else
3110 a_pts = playing_audio_pts(sh_audio, d_audio, audio_out);
3112 v_pts = sh_video->pts;
3115 static int drop_message=0;
3116 double AV_delay = a_pts - audio_delay - v_pts;
3117 double x;
3118 if (AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
3119 ++drop_message;
3120 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
3122 if (autosync)
3123 x = AV_delay*0.1f;
3124 else
3125 /* Do not correct target time for the next frame if this frame
3126 * was late not because of wrong target time but because the
3127 * target time could not be met */
3128 x = (AV_delay + timing_error * playback_speed) * 0.1f;
3129 if (x < -max_pts_correction)
3130 x = -max_pts_correction;
3131 else if (x> max_pts_correction)
3132 x = max_pts_correction;
3133 if (default_max_pts_correction >= 0)
3134 max_pts_correction = default_max_pts_correction;
3135 else
3136 max_pts_correction = sh_video->frametime*0.10; // +-10% of time
3137 if (!between_frames) {
3138 sh_audio->delay+=x;
3139 c_total+=x;
3141 if(!quiet)
3142 print_status(a_pts - audio_delay, AV_delay, c_total);
3145 } else {
3146 // No audio:
3148 if (!quiet)
3149 print_status(0, 0, 0);
3153 static int fill_audio_out_buffers(void)
3155 unsigned int t;
3156 double tt;
3157 int playsize;
3158 int playflags=0;
3159 int audio_eof=0;
3160 int bytes_to_write;
3162 current_module="play_audio";
3164 while (1) {
3165 // all the current uses of ao_data.pts seem to be in aos that handle
3166 // sync completely wrong; there should be no need to use ao_data.pts
3167 // in get_space()
3168 ao_data.pts = ((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
3169 bytes_to_write = audio_out->get_space();
3170 if (sh_video || bytes_to_write >= ao_data.outburst)
3171 break;
3173 // handle audio-only case:
3174 // this is where mplayer sleeps during audio-only playback
3175 // to avoid 100% CPU use
3176 usec_sleep(10000); // Wait a tick before retry
3179 while (bytes_to_write) {
3180 playsize = bytes_to_write;
3181 if (playsize > MAX_OUTBURST)
3182 playsize = MAX_OUTBURST;
3183 bytes_to_write -= playsize;
3185 // Fill buffer if needed:
3186 current_module="decode_audio";
3187 t = GetTimer();
3188 while (sh_audio->a_out_buffer_len < playsize) {
3189 int buflen = sh_audio->a_out_buffer_len;
3190 int ret = decode_audio(sh_audio, &sh_audio->a_out_buffer[buflen],
3191 playsize - buflen, // min bytes
3192 sh_audio->a_out_buffer_size - buflen // max
3194 if (ret <= 0) { // EOF?
3195 if (d_audio->eof) {
3196 audio_eof = 1;
3197 if (sh_audio->a_out_buffer_len == 0)
3198 return 0;
3200 break;
3202 sh_audio->a_out_buffer_len += ret;
3204 t = GetTimer() - t;
3205 tt = t*0.000001f; audio_time_usage+=tt;
3206 if (playsize > sh_audio->a_out_buffer_len) {
3207 playsize = sh_audio->a_out_buffer_len;
3208 if (audio_eof)
3209 playflags |= AOPLAY_FINAL_CHUNK;
3211 if (!playsize)
3212 break;
3214 // play audio:
3215 current_module="play_audio";
3217 // Is this pts value actually useful for the aos that access it?
3218 // They're obviously badly broken in the way they handle av sync;
3219 // would not having access to this make them more broken?
3220 ao_data.pts = ((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
3221 playsize = audio_out->play(sh_audio->a_out_buffer, playsize, playflags);
3223 if (playsize > 0) {
3224 sh_audio->a_out_buffer_len -= playsize;
3225 memmove(sh_audio->a_out_buffer, &sh_audio->a_out_buffer[playsize],
3226 sh_audio->a_out_buffer_len);
3227 sh_audio->delay += playback_speed*playsize/(double)ao_data.bps;
3229 else if (audio_eof && audio_out->get_delay() < .04) {
3230 // Sanity check to avoid hanging in case current ao doesn't output
3231 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3232 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n");
3233 sh_audio->a_out_buffer_len = 0;
3236 return 1;
3239 static int sleep_until_update(float *time_frame, float *aq_sleep_time)
3241 int frame_time_remaining = 0;
3242 current_module="calc_sleep_time";
3244 *time_frame -= GetRelativeTime(); // reset timer
3246 if (sh_audio && !d_audio->eof) {
3247 float delay = audio_out->get_delay();
3248 mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "delay=%f\n", delay);
3250 if (autosync) {
3252 * Adjust this raw delay value by calculating the expected
3253 * delay for this frame and generating a new value which is
3254 * weighted between the two. The higher autosync is, the
3255 * closer to the delay value gets to that which "-nosound"
3256 * would have used, and the longer it will take for A/V
3257 * sync to settle at the right value (but it eventually will.)
3258 * This settling time is very short for values below 100.
3260 float predicted = sh_audio->delay / playback_speed + *time_frame;
3261 float difference = delay - predicted;
3262 delay = predicted + difference / (float)autosync;
3265 *time_frame = delay - sh_audio->delay / playback_speed;
3267 // delay = amount of audio buffered in soundcard/driver
3268 if (delay > 0.25) delay=0.25; else
3269 if (delay < 0.10) delay=0.10;
3270 if (*time_frame > delay*0.6) {
3271 // sleep time too big - may cause audio drops (buffer underrun)
3272 frame_time_remaining = 1;
3273 *time_frame = delay*0.5;
3275 } else {
3276 // If we're lagging more than 200 ms behind the right playback rate,
3277 // don't try to "catch up".
3278 // If benchmark is set always output frames as fast as possible
3279 // without sleeping.
3280 if (*time_frame < -0.2 || benchmark)
3281 *time_frame = 0;
3284 *aq_sleep_time += *time_frame;
3287 //============================== SLEEP: ===================================
3289 // flag 256 means: libvo driver does its timing (dvb card)
3290 if (*time_frame > 0.001 && !(vo_flags&256))
3291 *time_frame = timing_sleep(*time_frame);
3292 return frame_time_remaining;
3295 static int reinit_video_chain(void) {
3296 //================== Init VIDEO (codec & libvo) ==========================
3297 if(!fixed_vo || !(inited_flags&INITED_VO)){
3298 current_module="preinit_libvo";
3300 //shouldn't we set dvideo->id=-2 when we fail?
3301 vo_config_count=0;
3302 //if((video_out->preinit(vo_subdevice))!=0){
3303 if(!(video_out=init_best_video_out(video_driver_list))){
3304 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
3305 goto err_out;
3307 sh_video->video_out=video_out;
3308 inited_flags|=INITED_VO;
3311 current_module="init_video_filters";
3313 char* vf_arg[] = { "_oldargs_", (char*)video_out , NULL };
3314 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
3316 #ifdef HAVE_MENU
3317 if(use_menu) {
3318 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
3319 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
3320 if(!vf_menu) {
3321 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
3322 use_menu = 0;
3325 if(vf_menu)
3326 sh_video->vfilter=(void*)vf_menu;
3327 #endif
3329 #ifdef USE_ASS
3330 if(ass_enabled) {
3331 int i;
3332 int insert = 1;
3333 if (vf_settings)
3334 for (i = 0; vf_settings[i].name; ++i)
3335 if (strcmp(vf_settings[i].name, "ass") == 0) {
3336 insert = 0;
3337 break;
3339 if (insert) {
3340 extern vf_info_t vf_info_ass;
3341 vf_info_t* libass_vfs[] = {&vf_info_ass, NULL};
3342 char* vf_arg[] = {"auto", "1", NULL};
3343 vf_instance_t* vf_ass = vf_open_plugin(libass_vfs,sh_video->vfilter,"ass",vf_arg);
3344 if (vf_ass)
3345 sh_video->vfilter=(void*)vf_ass;
3346 else
3347 mp_msg(MSGT_CPLAYER,MSGL_ERR, "ASS: cannot add video filter\n");
3350 #endif
3352 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
3354 #ifdef USE_ASS
3355 if (ass_enabled)
3356 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_INIT_EOSD, ass_library);
3357 #endif
3359 current_module="init_video_codec";
3361 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
3362 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
3363 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
3365 if(!sh_video->inited){
3366 if(!fixed_vo) uninit_player(INITED_VO);
3367 goto err_out;
3370 inited_flags|=INITED_VCODEC;
3372 if (sh_video->codec)
3373 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", sh_video->codec->name);
3375 sh_video->last_pts = MP_NOPTS_VALUE;
3376 sh_video->num_buffered_pts = 0;
3377 sh_video->next_frame_time = 0;
3379 if(auto_quality>0){
3380 // Auto quality option enabled
3381 output_quality=get_video_quality_max(sh_video);
3382 if(auto_quality>output_quality) auto_quality=output_quality;
3383 else output_quality=auto_quality;
3384 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
3385 set_video_quality(sh_video,output_quality);
3388 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3390 current_module="init_vo";
3392 return 1;
3394 err_out:
3395 sh_video = d_video->sh = NULL;
3396 return 0;
3399 static double update_video(int *blit_frame)
3401 //-------------------- Decode a frame: -----------------------
3402 double frame_time;
3403 *blit_frame = 0; // Don't blit if we hit EOF
3404 if (!correct_pts) {
3405 unsigned char* start=NULL;
3406 void *decoded_frame;
3407 int drop_frame=0;
3408 int in_size;
3410 current_module = "video_read_frame";
3411 frame_time = sh_video->next_frame_time;
3412 in_size = video_read_frame(sh_video, &sh_video->next_frame_time,
3413 &start, force_fps);
3414 if (in_size < 0)
3415 return -1;
3416 if (in_size > max_framesize)
3417 max_framesize = in_size; // stats
3418 sh_video->timer += frame_time;
3419 if (sh_audio)
3420 sh_audio->delay -= frame_time;
3421 // video_read_frame can change fps (e.g. for ASF video)
3422 vo_fps = sh_video->fps;
3423 // check for frame-drop:
3424 current_module = "check_framedrop";
3425 if (sh_audio && !d_audio->eof) {
3426 static int dropped_frames;
3427 float delay = playback_speed*audio_out->get_delay();
3428 float d = delay-sh_audio->delay;
3429 // we should avoid dropping too many frames in sequence unless we
3430 // are too late. and we allow 100ms A-V delay here:
3431 if (d < -dropped_frames*frame_time-0.100 &&
3432 osd_function != OSD_PAUSE) {
3433 drop_frame = frame_dropping;
3434 ++drop_frame_cnt;
3435 ++dropped_frames;
3436 } else
3437 drop_frame = dropped_frames = 0;
3438 ++total_frame_cnt;
3440 update_subtitles();
3441 update_osd_msg();
3442 current_module = "decode_video";
3443 decoded_frame = decode_video(sh_video, start, in_size, drop_frame,
3444 sh_video->pts);
3445 current_module = "filter_video";
3446 *blit_frame = (decoded_frame && filter_video(sh_video, decoded_frame,
3447 sh_video->pts));
3449 else {
3450 if (!generate_video_frame(sh_video, d_video))
3451 return -1;
3452 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter,
3453 VFCTRL_GET_PTS, &sh_video->pts);
3454 if (sh_video->pts == MP_NOPTS_VALUE) {
3455 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts after filters MISSING\n");
3456 sh_video->pts = sh_video->last_pts;
3458 if (sh_video->last_pts == MP_NOPTS_VALUE)
3459 sh_video->last_pts= sh_video->pts;
3460 else if (sh_video->last_pts >= sh_video->pts) {
3461 sh_video->last_pts = sh_video->pts;
3462 mp_msg(MSGT_CPLAYER, MSGL_WARN, "pts value <= previous");
3464 frame_time = sh_video->pts - sh_video->last_pts;
3465 sh_video->last_pts = sh_video->pts;
3466 sh_video->timer += frame_time;
3467 if(sh_audio)
3468 sh_audio->delay -= frame_time;
3469 *blit_frame = 1;
3471 return frame_time;
3474 void pause_loop(void)
3476 mp_cmd_t* cmd;
3477 if (!quiet) {
3478 // Small hack to display the pause message on the OSD line.
3479 // The pause string is: "\n == PAUSE == \r" so we need to
3480 // take the first and the last char out
3481 if (term_osd && !sh_video) {
3482 char msg[128] = MSGTR_Paused;
3483 int mlen = strlen(msg);
3484 msg[mlen-1] = '\0';
3485 set_osd_msg(OSD_MSG_PAUSE, 1, 0, "%s", msg+1);
3486 update_osd_msg();
3487 } else
3488 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
3489 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_PAUSED\n");
3490 fflush(stdout);
3492 #ifdef HAVE_NEW_GUI
3493 if (use_gui)
3494 guiGetEvent(guiCEvent, (char *)guiSetPause);
3495 #endif
3496 if (video_out && sh_video && vo_config_count)
3497 video_out->control(VOCTRL_PAUSE, NULL);
3499 if (audio_out && sh_audio)
3500 audio_out->pause(); // pause audio, keep data if possible
3502 while ( (cmd = mp_input_get_cmd(20, 1, 1)) == NULL) {
3503 if (sh_video && video_out && vo_config_count)
3504 video_out->check_events();
3505 #ifdef HAVE_NEW_GUI
3506 if (use_gui) {
3507 guiEventHandling();
3508 guiGetEvent(guiReDraw, NULL);
3509 if (guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos))
3510 break;
3512 #endif
3513 #ifdef HAVE_MENU
3514 if (vf_menu)
3515 vf_menu_pause_update(vf_menu);
3516 #endif
3517 usec_sleep(20000);
3519 if (cmd && cmd->id == MP_CMD_PAUSE) {
3520 cmd = mp_input_get_cmd(0,1,0);
3521 mp_cmd_free(cmd);
3523 osd_function=OSD_PLAY;
3524 if (audio_out && sh_audio)
3525 audio_out->resume(); // resume audio
3526 if (video_out && sh_video && vo_config_count)
3527 video_out->control(VOCTRL_RESUME, NULL); // resume video
3528 (void)GetRelativeTime(); // ignore time that passed during pause
3529 #ifdef HAVE_NEW_GUI
3530 if (use_gui) {
3531 if (guiIntfStruct.Playing == guiSetStop)
3532 eof = 1;
3533 else
3534 guiGetEvent(guiCEvent, (char *)guiSetPlay);
3536 #endif
3539 void print_version(void){
3540 mp_msg(MSGT_CPLAYER, MSGL_INFO, "%s\n", MP_TITLE);
3542 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
3543 GetCpuCaps(&gCpuCaps);
3544 #ifdef ARCH_X86
3545 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
3546 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
3547 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
3548 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
3549 #ifdef RUNTIME_CPUDETECT
3550 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
3551 #else
3552 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
3553 #ifdef HAVE_MMX
3554 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
3555 #endif
3556 #ifdef HAVE_MMX2
3557 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
3558 #endif
3559 #ifdef HAVE_3DNOW
3560 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
3561 #endif
3562 #ifdef HAVE_3DNOWEX
3563 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
3564 #endif
3565 #ifdef HAVE_SSE
3566 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
3567 #endif
3568 #ifdef HAVE_SSE2
3569 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
3570 #endif
3571 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3572 #endif /* RUNTIME_CPUDETECT */
3573 #endif /* ARCH_X86 */
3576 int main(int argc,char* argv[]){
3579 char * mem_ptr;
3581 int file_format=DEMUXER_TYPE_UNKNOWN;
3583 // movie info:
3585 /* Flag indicating whether MPlayer should exit without playing anything. */
3586 int opt_exit = 0;
3588 //float a_frame=0; // Audio
3590 int i;
3591 char *tmp;
3593 int gui_no_filename=0;
3595 srand((int) time(NULL));
3597 InitTimer();
3599 mp_msg_init();
3601 for(i=1; i<argc; i++)
3602 if(!strcmp(argv[i], "-really-quiet"))
3603 verbose= -10;
3605 print_version();
3606 #if defined(WIN32) && defined(USE_WIN32DLL)
3607 set_path_env();
3608 #endif /*WIN32 && USE_WIN32DLL*/
3610 #ifdef USE_TV
3611 tv_param_immediate = 1;
3612 #endif
3614 if (argc > 1 && argv[1] &&
3615 (!strcmp(argv[1], "-gui") || !strcmp(argv[1], "-nogui"))) {
3616 use_gui = !strcmp(argv[1], "-gui");
3617 } else
3618 if ( argv[0] )
3620 char *base = strrchr(argv[0], '/');
3621 if (!base)
3622 base = strrchr(argv[0], '\\');
3623 if (!base)
3624 base = argv[0];
3625 if(strstr(base, "gmplayer"))
3626 use_gui=1;
3629 mconfig = m_config_new();
3630 m_config_register_options(mconfig,mplayer_opts);
3631 // TODO : add something to let modules register their options
3632 mp_input_register_options(mconfig);
3633 parse_cfgfiles(mconfig);
3635 #ifdef HAVE_NEW_GUI
3636 if ( use_gui ) cfg_read();
3637 #endif
3639 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
3640 if(playtree == NULL)
3641 opt_exit = 1;
3642 else {
3643 playtree = play_tree_cleanup(playtree);
3644 if(playtree) {
3645 playtree_iter = play_tree_iter_new(playtree,mconfig);
3646 if(playtree_iter) {
3647 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
3648 play_tree_iter_free(playtree_iter);
3649 playtree_iter = NULL;
3651 filename = play_tree_iter_get_file(playtree_iter,1);
3656 #if defined(WIN32) && defined(HAVE_NEW_GUI)
3657 void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
3658 if(runningmplayer && filename && use_gui){
3659 COPYDATASTRUCT csData;
3660 char file[MAX_PATH];
3661 char *filepart = filename;
3662 if(GetFullPathName(filename, MAX_PATH, file, &filepart)){
3663 csData.dwData = 0;
3664 csData.cbData = strlen(file)*2;
3665 csData.lpData = file;
3666 SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData);
3669 #endif
3671 #ifdef WIN32
3672 if(proc_priority){
3673 int i;
3674 for(i=0; priority_presets_defs[i].name; i++){
3675 if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
3676 break;
3678 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",
3679 priority_presets_defs[i].name);
3680 SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
3682 #endif
3683 #ifndef HAVE_NEW_GUI
3684 if(use_gui){
3685 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
3686 use_gui=0;
3688 #else
3689 #ifndef WIN32
3690 if(use_gui && !vo_init()){
3691 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
3692 use_gui=0;
3694 #endif
3695 if (use_gui && playtree_iter){
3696 char cwd[PATH_MAX+2];
3697 // Free Playtree and Playtree-Iter as it's not used by the GUI.
3698 play_tree_iter_free(playtree_iter);
3699 playtree_iter=NULL;
3701 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
3703 strcat(cwd, "/");
3704 // Prefix relative paths with current working directory
3705 play_tree_add_bpf(playtree, cwd);
3707 // Import initital playtree into GUI.
3708 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
3710 #endif /* HAVE_NEW_GUI */
3712 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
3713 list_video_out();
3714 opt_exit = 1;
3717 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
3718 list_audio_out();
3719 opt_exit = 1;
3722 /* Check codecs.conf. */
3723 if(!codecs_file || !parse_codec_cfg(codecs_file)){
3724 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
3725 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
3726 if(!parse_codec_cfg(NULL)){
3727 exit_player_with_rc(NULL, 0);
3729 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
3732 free( mem_ptr ); // release the buffer created by get_path()
3735 #if 0
3736 if(video_codec_list){
3737 int i;
3738 video_codec=video_codec_list[0];
3739 for(i=0;video_codec_list[i];i++)
3740 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
3742 #endif
3743 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
3744 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
3745 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODECS\n");
3746 list_codecs(1);
3747 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3748 opt_exit = 1;
3750 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
3751 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
3752 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODECS\n");
3753 list_codecs(0);
3754 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3755 opt_exit = 1;
3757 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
3758 vfm_help();
3759 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3760 opt_exit = 1;
3762 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
3763 afm_help();
3764 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3765 opt_exit = 1;
3767 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
3768 af_help();
3769 printf("\n");
3770 opt_exit = 1;
3772 #ifdef HAVE_X11
3773 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
3774 fstype_help();
3775 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3776 opt_exit = 1;
3778 #endif
3779 if((demuxer_name && strcmp(demuxer_name,"help")==0) ||
3780 (audio_demuxer_name && strcmp(audio_demuxer_name,"help")==0) ||
3781 (sub_demuxer_name && strcmp(sub_demuxer_name,"help")==0)){
3782 demuxer_help();
3783 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
3784 opt_exit = 1;
3786 if(list_properties) {
3787 m_properties_print_help_list(mp_properties);
3788 opt_exit = 1;
3791 if(opt_exit)
3792 exit_player(NULL);
3794 if (player_idle_mode && use_gui) {
3795 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NoIdleAndGui);
3796 exit_player_with_rc(NULL, 1);
3799 if(!filename && !player_idle_mode){
3800 if(!use_gui){
3801 // no file/vcd/dvd -> show HELP:
3802 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
3803 exit_player_with_rc(NULL, 0);
3804 } else gui_no_filename=1;
3807 /* Display what configure line was used */
3808 mp_msg(MSGT_CPLAYER, MSGL_V, "Configuration: " CONFIGURATION "\n");
3810 // Many users forget to include command line in bugreports...
3811 if( mp_msg_test(MSGT_CPLAYER,MSGL_V) ){
3812 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
3813 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);
3814 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
3817 //------ load global data first ------
3819 // check font
3820 #ifdef HAVE_FREETYPE
3821 init_freetype();
3822 #endif
3823 #ifdef HAVE_FONTCONFIG
3824 if(!font_fontconfig)
3826 #endif
3827 #ifdef HAVE_BITMAP_FONT
3828 if(font_name){
3829 vo_font=read_font_desc(font_name,font_factor,verbose>1);
3830 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,
3831 filename_recode(font_name));
3832 } else {
3833 // try default:
3834 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
3835 free(mem_ptr); // release the buffer created by get_path()
3836 if(!vo_font)
3837 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
3839 #endif
3840 #ifdef HAVE_FONTCONFIG
3842 #endif
3844 vo_init_osd();
3846 #ifdef USE_ASS
3847 ass_library = ass_init();
3848 #endif
3850 #ifdef HAVE_RTC
3851 if(!nortc)
3853 // seteuid(0); /* Can't hurt to try to get root here */
3854 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
3855 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
3856 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
3857 else {
3858 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
3860 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
3861 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
3862 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
3863 close (rtc_fd);
3864 rtc_fd = -1;
3865 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
3866 /* variable only by the root */
3867 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
3868 close (rtc_fd);
3869 rtc_fd = -1;
3870 } else
3871 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
3874 #ifdef HAVE_NEW_GUI
3875 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
3876 // and now ? -- Pontscho
3877 if(use_gui) setuid( getuid() ); // strongly test, please check this.
3878 #endif
3879 if(rtc_fd<0)
3880 #endif /* HAVE_RTC */
3881 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
3882 softsleep?"software":timer_name);
3884 #ifdef USE_TERMCAP
3885 if ( !use_gui ) load_termcap(NULL); // load key-codes
3886 #endif
3888 // ========== Init keyboard FIFO (connection to libvo) ============
3890 // Init input system
3891 current_module = "init_input";
3892 mp_input_init(use_gui);
3893 #if 0
3894 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
3896 if(keyb_fifo_get > 0)
3897 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
3898 #else
3899 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
3900 #endif
3901 if(slave_mode)
3902 #ifndef __MINGW32__
3903 mp_input_add_cmd_fd(0,1,NULL,NULL);
3904 #else
3905 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
3906 #endif
3907 else if(!noconsolecontrols)
3908 #ifndef HAVE_NO_POSIX_SELECT
3909 mp_input_add_key_fd(0,1,NULL,NULL);
3910 #else
3911 mp_input_add_key_fd(0,0,NULL,NULL);
3912 #endif
3914 inited_flags|=INITED_INPUT;
3915 current_module = NULL;
3917 #ifdef HAVE_MENU
3918 if(use_menu) {
3919 if(menu_cfg && menu_init(menu_cfg))
3920 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
3921 else {
3922 menu_cfg = get_path("menu.conf");
3923 if(menu_init(menu_cfg))
3924 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
3925 else {
3926 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
3927 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
3928 else {
3929 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
3930 use_menu = 0;
3935 #endif
3937 /// Catch signals
3938 #ifndef __MINGW32__
3939 signal(SIGCHLD,child_sighandler);
3940 #endif
3942 #ifdef CRASH_DEBUG
3943 prog_path = argv[0];
3944 #endif
3945 //========= Catch terminate signals: ================
3946 // terminate requests:
3947 signal(SIGTERM,exit_sighandler); // kill
3948 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
3950 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
3952 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
3953 signal(SIGPIPE,exit_sighandler); // Some window managers cause this
3954 #ifdef ENABLE_SIGHANDLER
3955 // fatal errors:
3956 signal(SIGBUS,exit_sighandler); // bus error
3957 signal(SIGSEGV,exit_sighandler); // segfault
3958 signal(SIGILL,exit_sighandler); // illegal instruction
3959 signal(SIGFPE,exit_sighandler); // floating point exc.
3960 signal(SIGABRT,exit_sighandler); // abort()
3961 #ifdef CRASH_DEBUG
3962 if (crash_debug)
3963 signal(SIGTRAP,exit_sighandler);
3964 #endif
3965 #endif
3967 #ifdef HAVE_NEW_GUI
3968 if(use_gui){
3969 guiInit();
3970 inited_flags|=INITED_GUI;
3971 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
3973 #endif
3975 // ******************* Now, let's see the per-file stuff ********************
3977 play_next_file:
3979 // init global sub numbers
3980 global_sub_size = 0;
3981 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
3983 if (filename) load_per_file_config (mconfig, filename);
3985 // We must enable getch2 here to be able to interrupt network connection
3986 // or cache filling
3987 if(!noconsolecontrols && !slave_mode){
3988 if(inited_flags&INITED_GETCH2)
3989 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
3990 else
3991 getch2_enable(); // prepare stdin for hotkeys...
3992 inited_flags|=INITED_GETCH2;
3993 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
3996 // =================== GUI idle loop (STOP state) ===========================
3997 #ifdef HAVE_NEW_GUI
3998 if ( use_gui ) {
3999 file_format=DEMUXER_TYPE_UNKNOWN;
4000 guiGetEvent( guiSetDefaults,0 );
4001 while ( guiIntfStruct.Playing != 1 )
4003 mp_cmd_t* cmd;
4004 usec_sleep(20000);
4005 guiEventHandling();
4006 guiGetEvent( guiReDraw,NULL );
4007 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
4009 guiGetEvent( guiSetParameters,NULL );
4010 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
4012 play_tree_t * entry = play_tree_new();
4013 play_tree_add_file( entry,guiIntfStruct.Filename );
4014 if ( playtree ) play_tree_free_list( playtree->child,1 );
4015 else playtree=play_tree_new();
4016 play_tree_set_child( playtree,entry );
4017 if(playtree)
4019 playtree_iter = play_tree_iter_new(playtree,mconfig);
4020 if(playtree_iter)
4022 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
4024 play_tree_iter_free(playtree_iter);
4025 playtree_iter = NULL;
4027 filename = play_tree_iter_get_file(playtree_iter,1);
4032 #endif /* HAVE_NEW_GUI */
4034 while (player_idle_mode && !filename) {
4035 play_tree_t * entry = NULL;
4036 mp_cmd_t * cmd;
4037 while (!(cmd = mp_input_get_cmd(0,1,0))) { // wait for command
4038 if (video_out && vo_config_count) video_out->check_events();
4039 usec_sleep(20000);
4041 switch (cmd->id) {
4042 case MP_CMD_LOADFILE:
4043 // prepare a tree entry with the new filename
4044 entry = play_tree_new();
4045 play_tree_add_file(entry, cmd->args[0].v.s);
4046 // The entry is added to the main playtree after the switch().
4047 break;
4048 case MP_CMD_LOADLIST:
4049 entry = parse_playlist_file(cmd->args[0].v.s);
4050 break;
4051 case MP_CMD_QUIT:
4052 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
4053 break;
4056 mp_cmd_free(cmd);
4058 if (entry) { // user entered a command that gave a valid entry
4059 if (playtree) // the playtree is always a node with one child. let's clear it
4060 play_tree_free_list(playtree->child, 1);
4061 else playtree=play_tree_new(); // .. or make a brand new playtree
4063 if (!playtree) continue; // couldn't make playtree! wait for next command
4065 play_tree_set_child(playtree, entry);
4067 /* Make iterator start at the top the of tree. */
4068 playtree_iter = play_tree_iter_new(playtree, mconfig);
4069 if (!playtree_iter) continue;
4071 // find the first real item in the tree
4072 if (play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
4073 // no items!
4074 play_tree_iter_free(playtree_iter);
4075 playtree_iter = NULL;
4076 continue; // wait for next command
4078 filename = play_tree_iter_get_file(playtree_iter, 1);
4081 //---------------------------------------------------------------------------
4083 if(filename)
4084 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing,
4085 filename_recode(filename));
4087 if (edl_filename) {
4088 if (edl_records) free_edl(edl_records);
4089 next_edl_record = edl_records = edl_parse_file();
4091 if (edl_output_filename) {
4092 if (edl_fd) fclose(edl_fd);
4093 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
4095 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
4096 filename_recode(edl_output_filename));
4100 //==================== Open VOB-Sub ============================
4102 current_module="vobsub";
4103 if (vobsub_name){
4104 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
4105 if(vo_vobsub==NULL)
4106 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,
4107 filename_recode(vobsub_name));
4108 }else if(sub_auto && filename && (strlen(filename)>=5)){
4109 /* try to autodetect vobsub from movie filename ::atmos */
4110 char *buf = malloc((strlen(filename)-3)),*psub;
4111 memset(buf,0,strlen(filename)-3); // make sure string is terminated
4112 strncpy(buf, filename, strlen(filename)-4);
4113 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
4114 /* try from ~/.mplayer/sub */
4115 if(!vo_vobsub && (psub = get_path( "sub/" ))) {
4116 char *bname;
4117 int l;
4118 bname = strrchr(buf,'/');
4119 #ifdef WIN32
4120 if(!bname) bname = strrchr(buf,'\\');
4121 #endif
4122 if(bname) bname++;
4123 else bname = buf;
4124 l = strlen(psub) + strlen(bname) + 1;
4125 psub = realloc(psub,l);
4126 strcat(psub,bname);
4127 vo_vobsub=vobsub_open(psub,spudec_ifo,0,&vo_spudec);
4128 free(psub);
4130 free(buf);
4132 if(vo_vobsub){
4133 inited_flags|=INITED_VOBSUB;
4134 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
4135 // check if vobsub requested only to display forced subtitles
4136 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
4138 // setup global sub numbering
4139 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
4140 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
4143 //============ Open & Sync STREAM --- fork cache2 ====================
4145 stream=NULL;
4146 demuxer=NULL;
4147 if (d_audio) {
4148 //free_demuxer_stream(d_audio);
4149 d_audio=NULL;
4151 if (d_video) {
4152 //free_demuxer_stream(d_video);
4153 d_video=NULL;
4155 sh_audio=NULL;
4156 sh_video=NULL;
4158 current_module="open_stream";
4159 stream=open_stream(filename,0,&file_format);
4160 if(!stream) { // error...
4161 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
4162 goto goto_next_file;
4164 inited_flags|=INITED_STREAM;
4166 #ifdef HAVE_NEW_GUI
4167 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
4168 #endif
4170 if(file_format == DEMUXER_TYPE_PLAYLIST) {
4171 play_tree_t* entry;
4172 // Handle playlist
4173 current_module="handle_playlist";
4174 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",
4175 filename_recode(filename));
4176 entry = parse_playtree(stream,0);
4177 eof=playtree_add_playlist(entry);
4178 goto goto_next_file;
4180 stream->start_pos+=seek_to_byte;
4182 if(stream_dump_type==5){
4183 unsigned char buf[4096];
4184 int len;
4185 FILE *f;
4186 current_module="dumpstream";
4187 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
4188 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
4189 exit_player(MSGTR_Exit_error);
4191 stream_reset(stream);
4192 stream_seek(stream,stream->start_pos);
4193 f=fopen(stream_dump_name,"wb");
4194 if(!f){
4195 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
4196 exit_player(MSGTR_Exit_error);
4198 while(!stream->eof){
4199 len=stream_read(stream,buf,4096);
4200 if(len>0) {
4201 if(fwrite(buf,len,1,f) != 1) {
4202 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
4203 exit_player(MSGTR_Exit_error);
4207 if(fclose(f)) {
4208 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
4209 exit_player(MSGTR_Exit_error);
4211 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
4212 exit_player_with_rc(MSGTR_Exit_eof, 0);
4215 #ifdef USE_DVDREAD
4216 if(stream->type==STREAMTYPE_DVD){
4217 current_module="dvd lang->id";
4218 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
4219 if(dvdsub_lang && dvdsub_id==-2) dvdsub_id=-1;
4220 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
4221 // setup global sub numbering
4222 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
4223 global_sub_size += dvd_number_of_subs(stream);
4224 current_module=NULL;
4226 #endif
4228 #ifdef USE_DVDNAV
4229 if(stream->type==STREAMTYPE_DVDNAV){
4230 current_module="dvdnav lang->id";
4231 if(audio_id==-1) audio_id=dvdnav_aid_from_lang(stream,audio_lang);
4232 if(dvdsub_lang && dvdsub_id==-2) dvdsub_id=-1;
4233 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvdnav_sid_from_lang(stream,dvdsub_lang);
4234 // setup global sub numbering
4235 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
4236 global_sub_size += dvdnav_number_of_subs(stream);
4237 current_module=NULL;
4239 #endif
4241 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
4242 goto_enable_cache:
4243 if(stream_cache_size>0){
4244 current_module="enable_cache";
4245 if(!stream_enable_cache(stream,stream_cache_size*1024,
4246 stream_cache_size*1024*(stream_cache_min_percent / 100.0),
4247 stream_cache_size*1024*(stream_cache_seek_min_percent / 100.0)))
4248 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
4251 //============ Open DEMUXERS --- DETECT file type =======================
4252 current_module="demux_open";
4254 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
4256 // HACK to get MOV Reference Files working
4258 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
4260 unsigned char* playlist_entry;
4261 play_tree_t *list = NULL, *entry = NULL;
4263 current_module="handle_demux_playlist";
4264 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
4266 char *temp, *bname;
4268 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",
4269 filename_recode(playlist_entry));
4271 bname=mp_basename(playlist_entry);
4272 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
4273 continue;
4275 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
4276 continue;
4278 entry = play_tree_new();
4280 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
4282 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1));
4283 if (temp)
4285 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
4286 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
4287 strcat(temp, playlist_entry);
4288 play_tree_add_file(entry,temp);
4289 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
4290 free(temp);
4293 else
4294 play_tree_add_file(entry,playlist_entry);
4296 if(!list)
4297 list = entry;
4298 else
4299 play_tree_append_entry(list,entry);
4301 free_demuxer(demuxer);
4302 demuxer = NULL;
4304 if (list)
4306 entry = play_tree_new();
4307 play_tree_set_child(entry,list);
4308 eof=playtree_add_playlist(entry);
4309 goto goto_next_file;
4313 if(!demuxer)
4315 #if 0
4316 play_tree_t* entry;
4317 // Handle playlist
4318 current_module="handle_playlist";
4319 switch(stream->type){
4320 case STREAMTYPE_VCD:
4321 case STREAMTYPE_DVD:
4322 case STREAMTYPE_CDDA:
4323 case STREAMTYPE_VCDBINCUE:
4324 // don't try to parse raw media as playlist, it's unlikely
4325 goto goto_next_file;
4327 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
4328 stream_reset(stream);
4329 stream_seek(stream,stream->start_pos);
4330 entry = parse_playtree(stream,0);
4331 if(!entry)
4332 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
4333 else
4334 eof=playtree_add_playlist(entry);
4335 #endif
4336 goto goto_next_file;
4338 inited_flags|=INITED_DEMUXER;
4340 if (stream->type != STREAMTYPE_DVD && stream->type != STREAMTYPE_DVDNAV) {
4341 int i;
4342 // setup global sub numbering
4343 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
4344 for (i = 0; i < MAX_S_STREAMS; i++)
4345 if (demuxer->s_streams[i])
4346 global_sub_size++;
4349 current_module="demux_open2";
4351 //file_format=demuxer->file_format;
4353 d_audio=demuxer->audio;
4354 d_video=demuxer->video;
4355 d_dvdsub=demuxer->sub;
4357 // DUMP STREAMS:
4358 if((stream_dump_type)&&(stream_dump_type<4)){
4359 FILE *f;
4360 demux_stream_t *ds=NULL;
4361 current_module="dump";
4362 // select stream to dump
4363 switch(stream_dump_type){
4364 case 1: ds=d_audio;break;
4365 case 2: ds=d_video;break;
4366 case 3: ds=d_dvdsub;break;
4368 if(!ds){
4369 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
4370 exit_player(MSGTR_Exit_error);
4372 // disable other streams:
4373 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
4374 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
4375 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
4376 // let's dump it!
4377 f=fopen(stream_dump_name,"wb");
4378 if(!f){
4379 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
4380 exit_player(MSGTR_Exit_error);
4382 while(!ds->eof){
4383 unsigned char* start;
4384 int in_size=ds_get_packet(ds,&start);
4385 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
4386 && stream_dump_type==2) fwrite(&in_size,1,4,f);
4387 if(in_size>0) fwrite(start,in_size,1,f);
4389 fclose(f);
4390 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
4391 exit_player_with_rc(MSGTR_Exit_eof, 0);
4394 sh_audio=d_audio->sh;
4395 sh_video=d_video->sh;
4397 if(sh_video){
4399 current_module="video_read_properties";
4400 if(!video_read_properties(sh_video)) {
4401 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
4402 sh_video=d_video->sh=NULL;
4403 } else {
4404 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
4405 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
4406 sh_video->fps,sh_video->frametime
4409 /* need to set fps here for output encoders to pick it up in their init */
4410 if(force_fps){
4411 sh_video->fps=force_fps;
4412 sh_video->frametime=1.0f/sh_video->fps;
4414 vo_fps = sh_video->fps;
4416 if(!sh_video->fps && !force_fps){
4417 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
4418 sh_video=d_video->sh=NULL;
4424 fflush(stdout);
4426 if(!sh_video && !sh_audio){
4427 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
4428 #ifdef HAS_DVBIN_SUPPORT
4429 if((stream->type == STREAMTYPE_DVB) && stream->priv)
4431 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
4432 if(priv->is_on)
4434 int dir;
4435 int v = last_dvb_step;
4436 if(v > 0)
4437 dir = DVB_CHANNEL_HIGHER;
4438 else
4439 dir = DVB_CHANNEL_LOWER;
4441 if(dvb_step_channel(priv, dir))
4442 eof = dvbin_reopen = 1;
4445 #endif
4446 goto goto_next_file; // exit_player(MSGTR_Exit_error);
4449 /* display clip info */
4450 demux_info_print(demuxer);
4452 //================== Read SUBTITLES (DVD & TEXT) ==========================
4453 if(vo_spudec==NULL && sh_video &&
4454 (stream->type==STREAMTYPE_DVD || stream->type == STREAMTYPE_DVDNAV || d_dvdsub->id >= 0)){
4455 init_vo_spudec();
4458 // Apply current settings for forced subs
4459 if (vo_spudec!=NULL)
4460 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
4462 if(sh_video) {
4463 // after reading video params we should load subtitles because
4464 // we know fps so now we can adjust subtitle time to ~6 seconds AST
4465 // check .sub
4466 current_module="read_subtitles_file";
4467 if(sub_name){
4468 for (i = 0; sub_name[i] != NULL; ++i)
4469 add_subtitles (sub_name[i], sh_video->fps, 0);
4471 if(sub_auto) { // auto load sub file ...
4472 char *psub = get_path( "sub/" );
4473 char **tmp = sub_filenames((psub ? psub : ""), filename);
4474 int i = 0;
4475 free(psub); // release the buffer created by get_path() above
4476 while (tmp[i]) {
4477 add_subtitles (tmp[i], sh_video->fps, 0);
4478 free(tmp[i++]);
4480 free(tmp);
4482 if (set_of_sub_size > 0) {
4483 // setup global sub numbering
4484 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
4485 global_sub_size += set_of_sub_size;
4489 if (global_sub_size) {
4490 // find the best sub to use
4491 if (vobsub_id >= 0) {
4492 // if user asks for a vobsub id, use that first.
4493 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
4494 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4495 // if user asks for a dvd sub id, use that next.
4496 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
4497 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
4498 // if there are text subs to use, use those. (autosubs come last here)
4499 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
4501 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4502 // if nothing else works, get subs from the demuxer.
4503 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
4505 } else {
4506 // nothing worth doing automatically.
4507 global_sub_pos = -1;
4509 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
4510 global_sub_pos--;
4511 mp_property_do("sub",M_PROPERTY_STEP_UP,NULL);
4512 if(subdata)
4513 switch (stream_dump_type) {
4514 case 3: list_sub_file(subdata); break;
4515 case 4: dump_mpsub(subdata, sh_video->fps); break;
4516 case 6: dump_srt(subdata, sh_video->fps); break;
4517 case 7: dump_microdvd(subdata, sh_video->fps); break;
4518 case 8: dump_jacosub(subdata, sh_video->fps); break;
4519 case 9: dump_sami(subdata, sh_video->fps); break;
4523 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n",
4524 filename_recode(filename));
4525 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_DEMUXER=%s\n", demuxer->desc->name);
4526 if (sh_video) {
4527 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4528 if (sh_video->format >= 0x20202020)
4529 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video->format);
4530 else
4531 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
4532 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
4533 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
4534 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
4535 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
4536 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
4538 if (sh_audio) {
4539 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4540 if (sh_audio->format >= 0x20202020)
4541 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio->format);
4542 else
4543 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
4544 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
4545 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
4546 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
4548 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
4550 if(!sh_video) goto main; // audio-only
4552 if(!reinit_video_chain()) {
4553 if(!sh_video){
4554 if(!sh_audio) goto goto_next_file;
4555 goto main; // exit_player(MSGTR_Exit_error);
4559 if(vo_flags & 0x08 && vo_spudec)
4560 spudec_set_hw_spu(vo_spudec,video_out);
4562 #ifdef HAVE_FREETYPE
4563 force_load_font = 1;
4564 #endif
4566 //================== MAIN: ==========================
4567 main:
4568 current_module="main";
4570 if(playing_msg) {
4571 char* msg = m_properties_expand_string(mp_properties,playing_msg);
4572 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",msg);
4573 free(msg);
4577 // Disable the term OSD in verbose mode
4578 if(verbose) term_osd = 0;
4579 fflush(stdout);
4582 //int frame_corr_num=0; //
4583 //float v_frame=0; // Video
4584 float time_frame=0; // Timer
4585 //float num_frames=0; // number of frames played
4586 int grab_frames=0;
4588 int frame_time_remaining=0; // flag
4589 int blit_frame=0;
4590 int was_paused=0;
4592 // Make sure old OSD does not stay around,
4593 // e.g. with -fixed-vo and same-resolution files
4594 clear_osd_msgs();
4595 update_osd_msg();
4597 //================ SETUP AUDIO ==========================
4599 if(sh_audio){
4600 reinit_audio_chain();
4601 if (sh_audio && sh_audio->codec)
4602 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
4605 current_module="av_init";
4607 if(sh_video){
4608 sh_video->timer=0;
4609 if (! ignore_start)
4610 audio_delay += sh_video->stream_delay;
4612 if(sh_audio){
4613 if (! ignore_start)
4614 audio_delay -= sh_audio->stream_delay;
4615 sh_audio->delay=-audio_delay;
4618 if(!sh_audio){
4619 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
4620 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
4621 ds_free_packs(d_audio); // free buffered chunks
4622 //d_audio->id=-2; // do not read audio chunks
4623 //uninit_player(INITED_AO); // close device
4625 if(!sh_video){
4626 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
4627 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
4628 ds_free_packs(d_video);
4629 d_video->id=-2;
4630 //if(!fixed_vo) uninit_player(INITED_VO);
4633 if (!sh_video && !sh_audio)
4634 goto goto_next_file;
4636 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4637 if(force_fps && sh_video){
4638 vo_fps = sh_video->fps=force_fps;
4639 sh_video->frametime=1.0f/sh_video->fps;
4640 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
4643 #ifdef HAVE_NEW_GUI
4644 if ( use_gui ) {
4645 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
4646 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
4647 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
4648 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
4649 guiGetEvent( guiSetDemuxer,(char *)demuxer );
4651 #endif
4653 //==================== START PLAYING =======================
4655 if(loop_times>1) loop_times--; else
4656 if(loop_times==1) loop_times = -1;
4658 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
4660 total_time_usage_start=GetTimer();
4661 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
4662 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
4663 play_n_frames=play_n_frames_mf;
4665 if(play_n_frames==0){
4666 eof=PT_NEXT_ENTRY; goto goto_next_file;
4669 while(!eof){
4670 float aq_sleep_time=0;
4671 if(!sh_audio && d_audio->sh) {
4672 sh_audio = d_audio->sh;
4673 sh_audio->ds = d_audio;
4674 reinit_audio_chain();
4677 /*========================== PLAY AUDIO ============================*/
4679 if (sh_audio)
4680 if (!fill_audio_out_buffers())
4681 // at eof, all audio at least written to ao
4682 if (!sh_video)
4683 eof = PT_NEXT_ENTRY;
4686 if(!sh_video) {
4687 // handle audio-only case:
4688 double a_pos=0;
4689 if(!quiet || end_at.type == END_AT_TIME )
4690 a_pos = playing_audio_pts(sh_audio, d_audio, audio_out);
4692 if(!quiet)
4693 print_status(a_pos, 0, 0);
4695 if(end_at.type == END_AT_TIME && end_at.pos < a_pos)
4696 eof = PT_NEXT_ENTRY;
4697 update_osd_msg();
4699 } else {
4701 /*========================== PLAY VIDEO ============================*/
4703 vo_pts=sh_video->timer*90000.0;
4704 vo_fps=sh_video->fps;
4706 if (!frame_time_remaining) {
4707 double frame_time = update_video(&blit_frame);
4708 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
4709 if (sh_video->vf_inited < 0) {
4710 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NotInitializeVOPorVO);
4711 eof = 1; goto goto_next_file;
4713 if (frame_time < 0)
4714 eof = 1;
4715 else
4716 time_frame += frame_time / playback_speed; // for nosound
4719 // ==========================================================================
4721 // current_module="draw_osd";
4722 // if(vo_config_count) video_out->draw_osd();
4724 #ifdef HAVE_NEW_GUI
4725 if(use_gui) guiEventHandling();
4726 #endif
4728 current_module="vo_check_events";
4729 if (vo_config_count) video_out->check_events();
4731 #ifdef HAVE_X11
4732 if (stop_xscreensaver) {
4733 current_module = "stop_xscreensaver";
4734 xscreensaver_heartbeat();
4736 #endif
4738 frame_time_remaining = sleep_until_update(&time_frame, &aq_sleep_time);
4740 //====================== FLIP PAGE (VIDEO BLT): =========================
4742 current_module="flip_page";
4743 if (!frame_time_remaining && blit_frame) {
4744 unsigned int t2=GetTimer();
4746 if(vo_config_count) video_out->flip_page();
4748 vout_time_usage += (GetTimer() - t2) * 0.000001;
4750 //====================== A-V TIMESTAMP CORRECTION: =========================
4752 adjust_sync_and_print_status(frame_time_remaining, time_frame);
4754 //============================ Auto QUALITY ============================
4756 /*Output quality adjustments:*/
4757 if(auto_quality>0){
4758 current_module="autoq";
4759 // float total=0.000001f * (GetTimer()-aq_total_time);
4760 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4761 if(output_quality<auto_quality && aq_sleep_time>0)
4762 ++output_quality;
4763 else
4764 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4765 if(output_quality>1 && aq_sleep_time<0)
4766 --output_quality;
4767 else
4768 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
4769 output_quality=0;
4770 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4771 set_video_quality(sh_video,output_quality);
4774 if (play_n_frames >= 0 && !frame_time_remaining && blit_frame) {
4775 --play_n_frames;
4776 if (play_n_frames <= 0) eof = PT_NEXT_ENTRY;
4780 // FIXME: add size based support for -endpos
4781 if (end_at.type == END_AT_TIME &&
4782 !frame_time_remaining && end_at.pos <= sh_video->pts)
4783 eof = PT_NEXT_ENTRY;
4785 } // end if(sh_video)
4787 #ifdef USE_DVDNAV
4788 if (stream->type == STREAMTYPE_DVDNAV) {
4789 nav_highlight_t hl;
4790 mp_dvdnav_get_highlight (stream, &hl);
4791 osd_set_nav_box (hl.sx, hl.sy, hl.ex, hl.ey);
4792 vo_osd_changed (OSDTYPE_DVDNAV);
4794 #endif
4796 //============================ Handle PAUSE ===============================
4798 current_module="pause";
4800 if(osd_visible){
4801 // 36000000 means max timed visibility is 1 hour into the future, if
4802 // the difference is greater assume it's wrapped around from below 0
4803 if (osd_visible - GetTimerMS() > 36000000) {
4804 osd_visible = 0;
4805 vo_osd_progbar_type=-1; // disable
4806 vo_osd_changed(OSDTYPE_PROGBAR);
4807 if (osd_function != OSD_PAUSE)
4808 osd_function = OSD_PLAY;
4812 if (osd_function == OSD_PAUSE) {
4813 pause_loop();
4814 was_paused = 1;
4817 // handle -sstep
4818 if(step_sec>0) {
4819 osd_function=OSD_FFW;
4820 rel_seek_secs+=step_sec;
4823 //================= EDL =========================================
4825 if( next_edl_record ) { // Are we (still?) doing EDL?
4826 if ( !sh_video ) {
4827 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
4828 free_edl(edl_records);
4829 next_edl_record = NULL;
4830 edl_records = NULL;
4831 } else {
4832 if( sh_video->pts >= next_edl_record->start_sec ) {
4833 if( next_edl_record->action == EDL_SKIP ) {
4834 osd_function = OSD_FFW;
4835 abs_seek_pos = 0;
4836 rel_seek_secs = next_edl_record->length_sec;
4837 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 );
4838 edl_decision = 1;
4839 } else if( next_edl_record->action == EDL_MUTE ) {
4840 edl_muted = !edl_muted;
4841 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
4842 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
4844 next_edl_record=next_edl_record->next;
4849 //================= Keyboard events, SEEKing ====================
4851 current_module="key_events";
4854 mp_cmd_t* cmd;
4855 int brk_cmd = 0;
4856 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
4857 if(!set_property_command(cmd))
4858 switch(cmd->id) {
4859 case MP_CMD_SEEK : {
4860 float v;
4861 int abs;
4862 if(sh_video)
4863 osd_show_percentage = sh_video->fps;
4864 v = cmd->args[0].v.f;
4865 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
4866 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
4867 abs_seek_pos = 1;
4868 if(sh_video)
4869 osd_function= (v > sh_video->pts) ? OSD_FFW : OSD_REW;
4870 rel_seek_secs = v;
4872 else if(abs) { /* Absolute seek by percentage */
4873 abs_seek_pos = 3;
4874 if(sh_video)
4875 osd_function= OSD_FFW; // Direction isn't set correctly
4876 rel_seek_secs = v/100.0;
4878 else {
4879 rel_seek_secs+= v;
4880 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
4882 brk_cmd = 1;
4883 } break;
4884 case MP_CMD_SET_PROPERTY: {
4885 m_option_t* prop = mp_property_find(cmd->args[0].v.s);
4886 if(!prop) mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unknown property: '%s'\n",cmd->args[0].v.s);
4887 else if(m_property_parse(prop,cmd->args[1].v.s) <= 0)
4888 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to set property '%s' to '%s'.\n",
4889 cmd->args[0].v.s,cmd->args[1].v.s);
4891 } break;
4892 case MP_CMD_STEP_PROPERTY: {
4893 m_option_t* prop = mp_property_find(cmd->args[0].v.s);
4894 float arg = cmd->args[1].v.f;
4895 if(!prop) mp_msg(MSGT_CPLAYER,MSGL_WARN, "Unknown property: '%s'\n",cmd->args[0].v.s);
4896 else if(m_property_do(prop,M_PROPERTY_STEP_UP, arg ? &arg : NULL) <= 0)
4897 mp_msg(MSGT_CPLAYER,MSGL_WARN, "Failed to increment property '%s' by %f.\n",cmd->args[0].v.s, arg);
4898 } break;
4899 case MP_CMD_GET_PROPERTY: {
4900 m_option_t* prop;
4901 void* val;
4902 prop = mp_property_find(cmd->args[0].v.s);
4903 if(!prop) {
4904 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unknown property: '%s'\n",cmd->args[0].v.s);
4905 break;
4907 /* Use m_option_print directly to get easily parseable values. */
4908 val = calloc(1,prop->type->size);
4909 if(m_property_do(prop,M_PROPERTY_GET,val) <= 0) {
4910 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to get value of property '%s'.\n",
4911 cmd->args[0].v.s);
4912 break;
4914 tmp = m_option_print(prop,val);
4915 if(!tmp || tmp == (char*)-1) {
4916 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to print value of property '%s'.\n",
4917 cmd->args[0].v.s);
4918 break;
4920 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_%s=%s\n",cmd->args[0].v.s,tmp);
4921 free(tmp);
4922 } break;
4923 case MP_CMD_EDL_MARK:
4924 if( edl_fd ) {
4925 float v = sh_video ? sh_video->pts :
4926 playing_audio_pts(sh_audio, d_audio, audio_out);
4928 if(begin_skip == MP_NOPTS_VALUE)
4930 begin_skip = v;
4931 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
4932 }else{
4933 if(begin_skip > v)
4935 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
4936 }else{
4937 fprintf(edl_fd, "%f %f %d\n", begin_skip, v, 0);
4938 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
4940 begin_skip = MP_NOPTS_VALUE;
4943 break;
4944 case MP_CMD_SWITCH_RATIO : {
4945 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
4946 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
4947 else
4948 movie_aspect = cmd->args[0].v.f;
4949 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
4950 } break;
4951 case MP_CMD_SPEED_INCR : {
4952 float v = cmd->args[0].v.f;
4953 playback_speed += v;
4954 build_afilter_chain(sh_audio, &ao_data);
4955 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4956 } break;
4957 case MP_CMD_SPEED_MULT : {
4958 float v = cmd->args[0].v.f;
4959 playback_speed *= v;
4960 build_afilter_chain(sh_audio, &ao_data);
4961 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4962 } break;
4963 case MP_CMD_SPEED_SET : {
4964 float v = cmd->args[0].v.f;
4965 playback_speed = v;
4966 build_afilter_chain(sh_audio, &ao_data);
4967 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4968 } break;
4969 case MP_CMD_FRAME_STEP :
4970 case MP_CMD_PAUSE : {
4971 cmd->pausing = 1;
4972 brk_cmd = 1;
4973 } break;
4974 case MP_CMD_FILE_FILTER : {
4975 file_filter = cmd->args[0].v.i;
4976 break;
4978 case MP_CMD_QUIT : {
4979 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
4981 case MP_CMD_GRAB_FRAMES : {
4982 grab_frames=2;
4983 } break;
4984 case MP_CMD_PLAY_TREE_STEP : {
4985 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
4986 int force = cmd->args[1].v.i;
4988 #ifdef HAVE_NEW_GUI
4989 if (use_gui) {
4990 int i=0;
4991 if (n>0)
4992 for (i=0;i<n;i++)
4993 mplNext();
4994 else
4995 for (i=0;i<-1*n;i++)
4996 mplPrev();
4997 } else
4998 #endif
5000 if(!force && playtree_iter) {
5001 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
5003 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
5004 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
5005 play_tree_iter_free(i);
5006 } else
5007 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
5008 if(eof)
5009 play_tree_step = n;
5010 brk_cmd = 1;
5012 } break;
5013 case MP_CMD_PLAY_TREE_UP_STEP : {
5014 int n = cmd->args[0].v.i > 0 ? 1 : -1;
5015 int force = cmd->args[1].v.i;
5017 if(!force && playtree_iter) {
5018 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
5019 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
5020 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
5021 play_tree_iter_free(i);
5022 } else
5023 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
5024 brk_cmd = 1;
5025 } break;
5026 case MP_CMD_PLAY_ALT_SRC_STEP : {
5027 if(playtree_iter && playtree_iter->num_files > 1) {
5028 int v = cmd->args[0].v.i;
5029 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
5030 eof = PT_NEXT_SRC;
5031 else if(v < 0 && playtree_iter->file > 1)
5032 eof = PT_PREV_SRC;
5034 brk_cmd = 1;
5035 } break;
5036 case MP_CMD_SUB_STEP : {
5037 if (sh_video) {
5038 int movement = cmd->args[0].v.i;
5039 step_sub(subdata, sh_video->pts, movement);
5040 #ifdef USE_ASS
5041 if (ass_track)
5042 sub_delay += ass_step_sub(ass_track, (sh_video->pts + sub_delay) * 1000 + .5, movement) / 1000.;
5043 #endif
5044 set_osd_msg(OSD_MSG_SUB_DELAY,1,osd_duration,
5045 MSGTR_OSDSubDelay, ROUND(sub_delay*1000));
5047 } break;
5048 case MP_CMD_SUB_LOG : {
5049 log_sub();
5050 } break;
5051 case MP_CMD_OSD : {
5052 int v = cmd->args[0].v.i;
5053 int max = (term_osd && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
5054 if(osd_level > max) osd_level = max;
5055 if(v < 0)
5056 osd_level=(osd_level+1)%(max+1);
5057 else
5058 osd_level= v > max ? max : v;
5059 /* Show OSD state when disabled, but not when an explicit
5060 argument is given to the OSD command, i.e. in slave mode. */
5061 if (v == -1 && osd_level <= 1)
5062 set_osd_msg(OSD_MSG_OSD_STATUS,0,osd_duration,
5063 MSGTR_OSDosd, osd_level ? MSGTR_OSDenabled : MSGTR_OSDdisabled);
5064 else
5065 rm_osd_msg(OSD_MSG_OSD_STATUS);
5066 } break;
5067 case MP_CMD_OSD_SHOW_TEXT : {
5068 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
5069 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
5070 "%-.63s",cmd->args[0].v.s);
5071 } break;
5072 case MP_CMD_OSD_SHOW_PROPERTY_TEXT : {
5073 char* txt = m_properties_expand_string(mp_properties,cmd->args[0].v.s);
5074 /* if no argument supplied take default osd_duration, else <arg> ms. */
5075 if(txt) {
5076 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
5077 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
5078 "%-.63s",txt);
5079 free(txt);
5081 } break;
5082 case MP_CMD_LOADFILE : {
5083 play_tree_t* e = play_tree_new();
5084 play_tree_add_file(e,cmd->args[0].v.s);
5086 if (cmd->args[1].v.i) // append
5087 play_tree_append_entry(playtree, e);
5088 else {
5089 // Go back to the starting point.
5090 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
5091 /* NOP */;
5092 play_tree_free_list(playtree->child,1);
5093 play_tree_set_child(playtree,e);
5094 play_tree_iter_step(playtree_iter,0,0);
5095 eof = PT_NEXT_SRC;
5097 brk_cmd = 1;
5098 } break;
5099 case MP_CMD_LOADLIST : {
5100 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
5101 if(!e)
5102 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
5103 else {
5104 if (cmd->args[1].v.i) // append
5105 play_tree_append_entry(playtree, e);
5106 else {
5107 // Go back to the starting point.
5108 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
5109 /* NOP */;
5110 play_tree_free_list(playtree->child,1);
5111 play_tree_set_child(playtree,e);
5112 play_tree_iter_step(playtree_iter,0,0);
5113 eof = PT_NEXT_SRC;
5116 brk_cmd = 1;
5117 } break;
5118 #ifdef USE_RADIO
5119 case MP_CMD_RADIO_STEP_CHANNEL : {
5120 if (demuxer->stream->type==STREAMTYPE_RADIO) {
5121 int v = cmd->args[0].v.i;
5122 if(v > 0)
5123 radio_step_channel(demuxer->stream, RADIO_CHANNEL_HIGHER);
5124 else
5125 radio_step_channel(demuxer->stream, RADIO_CHANNEL_LOWER);
5126 if (radio_get_channel_name(demuxer->stream)) {
5127 set_osd_msg(OSD_MSG_RADIO_CHANNEL,1,osd_duration,
5128 MSGTR_OSDChannel, radio_get_channel_name(demuxer->stream));
5131 } break;
5132 case MP_CMD_RADIO_SET_CHANNEL : {
5133 if (demuxer->stream->type== STREAMTYPE_RADIO) {
5134 radio_set_channel(demuxer->stream, cmd->args[0].v.s);
5135 if (radio_get_channel_name(demuxer->stream)) {
5136 set_osd_msg(OSD_MSG_RADIO_CHANNEL,1,osd_duration,
5137 MSGTR_OSDChannel, radio_get_channel_name(demuxer->stream));
5140 } break;
5141 case MP_CMD_RADIO_SET_FREQ : {
5142 if (demuxer->stream->type== STREAMTYPE_RADIO)
5143 radio_set_freq(demuxer->stream, cmd->args[0].v.f);
5144 } break;
5145 case MP_CMD_RADIO_STEP_FREQ :
5146 if (demuxer->stream->type == STREAMTYPE_RADIO){
5147 radio_step_freq(demuxer->stream, cmd->args[0].v.f);
5149 break;
5150 #endif
5151 #ifdef USE_TV
5152 case MP_CMD_TV_SET_FREQ : {
5153 if (file_format == DEMUXER_TYPE_TV)
5154 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
5155 } break;
5156 case MP_CMD_TV_SET_NORM : {
5157 if (file_format == DEMUXER_TYPE_TV)
5158 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
5159 } break;
5160 case MP_CMD_TV_STEP_CHANNEL : {
5161 if (file_format == DEMUXER_TYPE_TV) {
5162 int v = cmd->args[0].v.i;
5163 if(v > 0){
5164 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
5165 } else {
5166 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
5168 if (tv_channel_list) {
5169 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
5170 MSGTR_OSDChannel, tv_channel_current->name);
5171 //vo_osd_changed(OSDTYPE_SUBTITLE);
5175 #ifdef HAS_DVBIN_SUPPORT
5176 if((stream->type == STREAMTYPE_DVB) && stream->priv)
5178 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
5179 if(priv->is_on)
5181 int dir;
5182 int v = cmd->args[0].v.i;
5184 last_dvb_step = v;
5185 if(v > 0)
5186 dir = DVB_CHANNEL_HIGHER;
5187 else
5188 dir = DVB_CHANNEL_LOWER;
5191 if(dvb_step_channel(priv, dir))
5192 eof = dvbin_reopen = 1;
5195 #endif /* HAS_DVBIN_SUPPORT */
5196 break;
5197 case MP_CMD_TV_SET_CHANNEL : {
5198 if (file_format == DEMUXER_TYPE_TV) {
5199 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
5200 if (tv_channel_list) {
5201 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
5202 MSGTR_OSDChannel, tv_channel_current->name);
5203 //vo_osd_changed(OSDTYPE_SUBTITLE);
5206 } break;
5207 #ifdef HAS_DVBIN_SUPPORT
5208 case MP_CMD_DVB_SET_CHANNEL:
5210 if((stream->type == STREAMTYPE_DVB) && stream->priv)
5212 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
5213 if(priv->is_on)
5215 if(priv->list->current <= cmd->args[0].v.i)
5216 last_dvb_step = 1;
5217 else
5218 last_dvb_step = -1;
5220 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
5221 eof = dvbin_reopen = 1;
5225 break;
5226 #endif /* HAS_DVBIN_SUPPORT */
5227 case MP_CMD_TV_LAST_CHANNEL : {
5228 if (file_format == DEMUXER_TYPE_TV) {
5229 tv_last_channel((tvi_handle_t*)(demuxer->priv));
5230 if (tv_channel_list) {
5231 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
5232 MSGTR_OSDChannel, tv_channel_current->name);
5233 //vo_osd_changed(OSDTYPE_SUBTITLE);
5236 } break;
5237 case MP_CMD_TV_STEP_NORM : {
5238 if (file_format == DEMUXER_TYPE_TV)
5239 tv_step_norm((tvi_handle_t*)(demuxer->priv));
5240 } break;
5241 case MP_CMD_TV_STEP_CHANNEL_LIST : {
5242 if (file_format == DEMUXER_TYPE_TV)
5243 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
5244 } break;
5245 #endif /* USE_TV */
5246 case MP_CMD_SUB_LOAD:
5248 if (sh_video) {
5249 int n = set_of_sub_size;
5250 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
5251 if (n != set_of_sub_size) {
5252 if (global_sub_indices[SUB_SOURCE_SUBS] < 0)
5253 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size;
5254 ++global_sub_size;
5257 } break;
5258 case MP_CMD_SUB_REMOVE:
5260 if (sh_video) {
5261 int v = cmd->args[0].v.i;
5262 sub_data *subd;
5263 if (v < 0) {
5264 for (v = 0; v < set_of_sub_size; ++v) {
5265 subd = set_of_subtitles[v];
5266 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1,
5267 filename_recode(subd->filename));
5268 sub_free(subd);
5269 set_of_subtitles[v] = NULL;
5271 global_sub_indices[SUB_SOURCE_SUBS] = -1;
5272 global_sub_size -= set_of_sub_size;
5273 set_of_sub_size = 0;
5274 if (set_of_sub_pos >= 0) {
5275 global_sub_pos = -2;
5276 vo_sub_last = vo_sub = NULL;
5277 vo_osd_changed(OSDTYPE_SUBTITLE);
5278 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
5279 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5282 else if (v < set_of_sub_size) {
5283 subd = set_of_subtitles[v];
5284 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1,
5285 filename_recode(subd->filename));
5286 sub_free(subd);
5287 if (set_of_sub_pos == v) {
5288 global_sub_pos = -2;
5289 vo_sub_last = vo_sub = NULL;
5290 vo_osd_changed(OSDTYPE_SUBTITLE);
5291 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
5292 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5294 else if (set_of_sub_pos > v) {
5295 --set_of_sub_pos;
5296 --global_sub_pos;
5298 while (++v < set_of_sub_size)
5299 set_of_subtitles[v - 1] = set_of_subtitles[v];
5300 --set_of_sub_size;
5301 --global_sub_size;
5302 if (set_of_sub_size <= 0)
5303 global_sub_indices[SUB_SOURCE_SUBS] = -1;
5304 set_of_subtitles[set_of_sub_size] = NULL;
5307 } break;
5308 case MP_CMD_GET_SUB_VISIBILITY:
5310 if (sh_video) {
5311 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
5313 } break;
5314 case MP_CMD_SCREENSHOT :
5315 if(vo_config_count){
5316 mp_msg(MSGT_CPLAYER,MSGL_INFO,"sending VFCTRL_SCREENSHOT!\n");
5317 if(CONTROL_OK!=((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SCREENSHOT, &cmd->args[0].v.i))
5318 video_out->control(VOCTRL_SCREENSHOT, NULL);
5320 break;
5321 case MP_CMD_VF_CHANGE_RECTANGLE:
5322 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
5323 break;
5325 case MP_CMD_GET_TIME_LENGTH : {
5326 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
5327 } break;
5329 case MP_CMD_GET_FILENAME : {
5330 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_FILENAME='%s'\n", get_metadata (META_NAME));
5331 } break;
5333 case MP_CMD_GET_VIDEO_CODEC : {
5334 char *inf = get_metadata (META_VIDEO_CODEC);
5335 if (!inf) inf = strdup ("");
5336 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
5337 free (inf);
5338 } break;
5340 case MP_CMD_GET_VIDEO_BITRATE : {
5341 char *inf = get_metadata (META_VIDEO_BITRATE);
5342 if (!inf) inf = strdup ("");
5343 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
5344 free (inf);
5345 } break;
5347 case MP_CMD_GET_VIDEO_RESOLUTION : {
5348 char *inf = get_metadata (META_VIDEO_RESOLUTION);
5349 if (!inf) inf = strdup ("");
5350 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
5351 free (inf);
5352 } break;
5354 case MP_CMD_GET_AUDIO_CODEC : {
5355 char *inf = get_metadata (META_AUDIO_CODEC);
5356 if (!inf) inf = strdup ("");
5357 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
5358 free (inf);
5359 } break;
5361 case MP_CMD_GET_AUDIO_BITRATE : {
5362 char *inf = get_metadata (META_AUDIO_BITRATE);
5363 if (!inf) inf = strdup ("");
5364 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
5365 free (inf);
5366 } break;
5368 case MP_CMD_GET_AUDIO_SAMPLES : {
5369 char *inf = get_metadata (META_AUDIO_SAMPLES);
5370 if (!inf) inf = strdup ("");
5371 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
5372 free (inf);
5373 } break;
5375 case MP_CMD_GET_META_TITLE : {
5376 char *inf = get_metadata (META_INFO_TITLE);
5377 if (!inf) inf = strdup ("");
5378 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
5379 free (inf);
5380 } break;
5382 case MP_CMD_GET_META_ARTIST : {
5383 char *inf = get_metadata (META_INFO_ARTIST);
5384 if (!inf) inf = strdup ("");
5385 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
5386 free (inf);
5387 } break;
5389 case MP_CMD_GET_META_ALBUM : {
5390 char *inf = get_metadata (META_INFO_ALBUM);
5391 if (!inf) inf = strdup ("");
5392 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
5393 free (inf);
5394 } break;
5396 case MP_CMD_GET_META_YEAR : {
5397 char *inf = get_metadata (META_INFO_YEAR);
5398 if (!inf) inf = strdup ("");
5399 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
5400 free (inf);
5401 } break;
5403 case MP_CMD_GET_META_COMMENT : {
5404 char *inf = get_metadata (META_INFO_COMMENT);
5405 if (!inf) inf = strdup ("");
5406 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
5407 free (inf);
5408 } break;
5410 case MP_CMD_GET_META_TRACK : {
5411 char *inf = get_metadata (META_INFO_TRACK);
5412 if (!inf) inf = strdup ("");
5413 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
5414 free (inf);
5415 } break;
5417 case MP_CMD_GET_META_GENRE : {
5418 char *inf = get_metadata (META_INFO_GENRE);
5419 if (!inf) inf = strdup ("");
5420 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
5421 free (inf);
5422 } break;
5424 case MP_CMD_GET_VO_FULLSCREEN : {
5425 if(video_out && vo_config_count)
5426 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
5427 } break;
5429 case MP_CMD_GET_PERCENT_POS : {
5430 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer));
5431 } break;
5432 case MP_CMD_GET_TIME_POS : {
5433 float pos = 0;
5434 if (sh_video)
5435 pos = sh_video->pts;
5436 else
5437 if (sh_audio && audio_out)
5438 pos = playing_audio_pts(sh_audio, d_audio, audio_out);
5439 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
5440 } break;
5441 case MP_CMD_RUN : {
5442 #ifndef __MINGW32__
5443 if(!fork()) {
5444 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
5445 exit(0);
5447 #endif
5448 } break;
5449 case MP_CMD_KEYDOWN_EVENTS : {
5450 mplayer_put_key(cmd->args[0].v.i);
5451 } break;
5452 case MP_CMD_SEEK_CHAPTER : {
5453 int seek = cmd->args[0].v.i;
5454 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
5455 int chap;
5456 float next_pts = 0;
5457 int num_chapters;
5458 char *chapter_name;
5460 rel_seek_secs = 0;
5461 abs_seek_pos = 0;
5462 chap = demuxer_seek_chapter(demuxer, seek, abs, &next_pts, &num_chapters, &chapter_name);
5463 if(chap != -1) {
5464 if(next_pts > -1.0) {
5465 abs_seek_pos = 1;
5466 rel_seek_secs = next_pts;
5468 if(chapter_name) {
5469 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter,
5470 chap+1, chapter_name);
5471 free(chapter_name);
5473 } else {
5474 if (seek > 0)
5475 rel_seek_secs = 1000000000.;
5476 else
5477 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter, 0, MSGTR_Unknown);
5479 break;
5480 } break;
5481 case MP_CMD_SET_MOUSE_POS: {
5482 int button = -1, pointer_x, pointer_y;
5483 double dx, dy;
5484 pointer_x = cmd->args[0].v.i;
5485 pointer_y = cmd->args[1].v.i;
5486 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
5487 #ifdef USE_DVDNAV
5488 if(stream->type == STREAMTYPE_DVDNAV && dx > 0.0 && dy > 0.0) {
5489 pointer_x = (int) (dx * (double) sh_video->disp_w);
5490 pointer_y = (int) (dy * (double) sh_video->disp_h);
5491 mp_dvdnav_update_mouse_pos(stream, pointer_x, pointer_y, &button);
5492 if(button>0) set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button);
5494 #endif
5495 break;
5497 #ifdef USE_DVDNAV
5498 case MP_CMD_DVDNAV: {
5499 int button = -1;
5500 if(stream->type != STREAMTYPE_DVDNAV) break;
5502 if(mp_dvdnav_handle_input(stream, cmd->args[0].v.i, &button)) {
5503 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT|(fixed_vo ? INITED_VO : 0)));
5504 goto goto_enable_cache;
5505 } else if(button>0) set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button);
5506 break;
5508 #endif
5509 default : {
5510 #ifdef HAVE_NEW_GUI
5511 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
5512 else
5513 #endif
5514 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
5517 switch (cmd->pausing) {
5518 case 1: // "pausing"
5519 osd_function = OSD_PAUSE;
5520 break;
5521 case 3: // "pausing_toggle"
5522 was_paused = !was_paused;
5523 // fall through
5524 case 2: // "pausing_keep"
5525 if (was_paused) osd_function = OSD_PAUSE;
5527 mp_cmd_free(cmd);
5530 was_paused = 0;
5532 if (seek_to_sec) {
5533 int a,b; float d;
5535 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
5536 rel_seek_secs += 3600*a +60*b +d ;
5537 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
5538 rel_seek_secs += 60*a +d;
5539 else if (sscanf(seek_to_sec, "%f", &d)==1)
5540 rel_seek_secs += d;
5542 seek_to_sec = NULL;
5545 if (end_at.type != END_AT_NONE) {
5546 if(end_at.type == END_AT_SIZE) {
5547 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_MPEndposNoSizeBased);
5548 end_at.type = END_AT_NONE;
5549 } else {
5550 end_at.pos += rel_seek_secs;
5554 /* Looping. */
5555 if(eof==1 && loop_times>=0) {
5556 int l = loop_times;
5557 play_tree_iter_step(playtree_iter,0,0);
5558 loop_times = l;
5559 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
5561 if(loop_times>1) loop_times--; else
5562 if(loop_times==1) loop_times=-1;
5563 play_n_frames=play_n_frames_mf;
5564 eof=0;
5565 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
5566 loop_seek = 1;
5569 if(rel_seek_secs || abs_seek_pos){
5570 current_module="seek";
5571 if(demux_seek(demuxer,rel_seek_secs,audio_delay,abs_seek_pos)){
5572 // success:
5573 /* FIXME there should be real seeking for vobsub */
5574 if(sh_video) sh_video->pts=d_video->pts;
5575 if (vo_vobsub)
5576 //vobsub_reset(vo_vobsub);
5577 vobsub_seek(vo_vobsub,sh_video->pts);
5578 fflush(stdout);
5580 if(sh_video){
5581 current_module="seek_video_reset";
5582 resync_video_stream(sh_video);
5583 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
5584 sh_video->num_buffered_pts = 0;
5585 sh_video->last_pts = MP_NOPTS_VALUE;
5588 if(sh_audio){
5589 current_module="seek_audio_reset";
5590 audio_out->reset(); // stop audio, throwing away buffered data
5591 sh_audio->a_buffer_len = 0;
5592 sh_audio->a_out_buffer_len = 0;
5594 // Set OSD:
5595 if(!loop_seek){
5596 if( !edl_decision )
5597 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer));
5600 if(sh_video) {
5601 c_total=0;
5602 max_pts_correction=0.1;
5603 osd_visible=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
5604 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
5605 drop_frame_cnt=0;
5607 if(vo_spudec) spudec_reset(vo_spudec);
5611 * We saw a seek, have to rewind the EDL operations stack
5612 * and find the next EDL action to take care of.
5615 edl_muted = 0;
5616 next_edl_record = edl_records;
5618 while (next_edl_record)
5620 /* Trying to remember if we need to mute/unmute first;
5621 * prior EDL implementation lacks this.
5624 if (next_edl_record->start_sec >= sh_video->pts)
5625 break;
5627 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
5628 next_edl_record = next_edl_record->next;
5631 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
5633 rel_seek_secs=0;
5634 abs_seek_pos=0;
5635 frame_time_remaining=0;
5636 current_module=NULL;
5637 loop_seek=0;
5640 #ifdef HAVE_NEW_GUI
5641 if(use_gui){
5642 guiEventHandling();
5643 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
5644 // get pos from frame number / total frames
5645 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
5646 } else {
5647 off_t len = ( demuxer->movi_end - demuxer->movi_start );
5648 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
5649 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
5651 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
5652 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
5653 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
5654 guiGetEvent( guiReDraw,NULL );
5655 guiGetEvent( guiSetVolume,NULL );
5656 if(guiIntfStruct.Playing==0) break; // STOP
5657 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
5658 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
5659 #ifdef USE_DVDREAD
5660 if ( stream->type == STREAMTYPE_DVD )
5662 dvd_priv_t * dvdp = stream->priv;
5663 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
5665 #endif
5667 #endif /* HAVE_NEW_GUI */
5669 } // while(!eof)
5671 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
5673 #ifdef HAS_DVBIN_SUPPORT
5674 if(dvbin_reopen)
5676 eof = 0;
5677 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
5678 cache_uninit(stream);
5679 dvbin_reopen = 0;
5680 goto goto_enable_cache;
5682 #endif
5685 goto_next_file: // don't jump here after ao/vo/getch initialization!
5687 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
5689 if(benchmark){
5690 double tot=video_time_usage+vout_time_usage+audio_time_usage;
5691 double total_time_usage;
5692 total_time_usage_start=GetTimer()-total_time_usage_start;
5693 total_time_usage = (float)total_time_usage_start*0.000001;
5694 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5695 video_time_usage,vout_time_usage,audio_time_usage,
5696 total_time_usage-tot,total_time_usage);
5697 if(total_time_usage>0.0)
5698 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5699 100.0*video_time_usage/total_time_usage,
5700 100.0*vout_time_usage/total_time_usage,
5701 100.0*audio_time_usage/total_time_usage,
5702 100.0*(total_time_usage-tot)/total_time_usage,
5703 100.0);
5704 if(total_frame_cnt && frame_dropping)
5705 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5706 total_frame_cnt-drop_frame_cnt,
5707 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
5708 drop_frame_cnt,
5709 100*drop_frame_cnt/total_frame_cnt,
5710 total_frame_cnt,
5711 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
5715 // time to uninit all, except global stuff:
5716 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
5718 if ( set_of_sub_size > 0 )
5720 current_module="sub_free";
5721 for (i = 0; i < set_of_sub_size; ++i) {
5722 sub_free( set_of_subtitles[i] );
5723 #ifdef USE_ASS
5724 if ( set_of_ass_tracks[i] )
5725 ass_free_track( set_of_ass_tracks[i] );
5726 #endif
5728 set_of_sub_size = 0;
5730 vo_sub_last = vo_sub=NULL;
5731 subdata=NULL;
5732 #ifdef USE_ASS
5733 ass_track = NULL;
5734 #endif
5736 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
5737 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
5738 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
5739 eof = 1;
5740 } else {
5741 play_tree_iter_free(playtree_iter);
5742 playtree_iter = NULL;
5744 play_tree_step = 1;
5745 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
5746 eof = eof == PT_UP_NEXT ? 1 : -1;
5747 if ( playtree_iter ) {
5748 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
5749 eof = 1;
5750 } else {
5751 play_tree_iter_free(playtree_iter);
5752 playtree_iter = NULL;
5755 } else { // NEXT PREV SRC
5756 eof = eof == PT_PREV_SRC ? -1 : 1;
5759 if(eof == 0) eof = 1;
5761 while(playtree_iter != NULL) {
5762 filename = play_tree_iter_get_file(playtree_iter,eof);
5763 if(filename == NULL) {
5764 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
5765 play_tree_iter_free(playtree_iter);
5766 playtree_iter = NULL;
5768 } else
5769 break;
5772 #ifdef HAVE_NEW_GUI
5773 if( use_gui && !playtree_iter )
5775 #ifdef USE_DVDREAD
5776 if ( !guiIntfStruct.DiskChanged )
5777 #endif
5778 mplEnd();
5780 #endif
5782 if(use_gui || playtree_iter != NULL || player_idle_mode){
5783 if (!playtree_iter) filename = NULL;
5784 eof = 0;
5785 goto play_next_file;
5789 exit_player_with_rc(MSGTR_Exit_eof, 0);
5791 return 1;