3 /// \ingroup Properties Command2Property OSDMsgStack
10 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
16 // #include <sys/mman.h>
17 #include <sys/types.h>
19 #include <sys/ioctl.h>
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
);
44 #define HELP_MP_DEFINE_STATIC
49 #include "m_property.h"
51 #include "cfg-mplayer-def.h"
54 #include "subreader.h"
57 #include "libvo/video_out.h"
59 #include "libvo/font_load.h"
60 #include "libvo/sub.h"
63 #include "libvo/x11_common.h"
66 #include "libao2/audio_out.h"
68 #include "codec-cfg.h"
75 #include "osdep/getch2.h"
76 #include "osdep/timer.h"
78 #include "cpudetect.h"
81 #include "Gui/interface.h"
84 #include "input/input.h"
87 int player_idle_mode
=0;
92 char * proc_priority
=NULL
;
95 #define ABS(x) (((x)>=0)?(x):(-(x)))
96 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
100 #include <linux/rtc.h>
103 #define RTC_IRQP_SET RTCIO_IRQP_SET
104 #define RTC_PIE_ON RTCIO_PIE_ON
105 #endif /* __linux__ */
106 #endif /* HAVE_RTC */
109 #include "stream/tv.h"
112 #ifdef HAS_DVBIN_SUPPORT
113 #include "stream/dvbin.h"
114 static int last_dvb_step
= 1;
115 static int dvbin_reopen
= 0;
116 extern void cache_uninit(stream_t
*s
);
119 //**************************************************************************//
121 //**************************************************************************//
122 #include "playtree.h"
123 #include "playtreeparser.h"
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
);
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
139 #define PT_UP_PREV -3
141 //**************************************************************************//
143 //**************************************************************************//
147 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
);
149 m_config_parse_config_file(m_config_t
* config
, char *conffile
);
151 //**************************************************************************//
153 //**************************************************************************//
155 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
157 static int cfg_include(m_option_t
*conf
, char *filename
){
158 return m_config_parse_config_file(mconfig
, filename
);
161 #include "get_path.c"
163 //**************************************************************************//
165 //**************************************************************************//
168 void xscreensaver_heartbeat(void);
171 //**************************************************************************//
172 //**************************************************************************//
173 // Input media streaming & demultiplexer:
174 //**************************************************************************//
176 static int max_framesize
=0;
178 #include "stream/stream.h"
179 #include "libmpdemux/demuxer.h"
180 #include "libmpdemux/stheader.h"
181 //#include "parse_es.h"
182 #include "libmpdemux/matroska.h"
185 #include "stream/stream_dvd.h"
188 #include "libmpcodecs/dec_audio.h"
189 #include "libmpcodecs/dec_video.h"
190 #include "libmpcodecs/mp_image.h"
191 #include "libmpcodecs/vf.h"
192 #include "libmpcodecs/vd.h"
194 extern void vf_list_plugins(void);
196 //**************************************************************************//
197 //**************************************************************************//
199 // Common FIFO functions, and keyboard/event FIFO code
201 int noconsolecontrols
=0;
202 //**************************************************************************//
204 vo_functions_t
*video_out
=NULL
;
205 ao_functions_t
*audio_out
=NULL
;
211 double video_time_usage
=0;
212 double vout_time_usage
=0;
213 static double audio_time_usage
=0;
214 static int total_time_usage_start
=0;
215 static int total_frame_cnt
=0;
216 static int drop_frame_cnt
=0; // total number of dropped frames
221 static int output_quality
=0;
223 float playback_speed
=1.0;
231 static int list_properties
= 0;
233 #define MAX_OSD_LEVEL 3
234 #define MAX_TERM_OSD_LEVEL 1
237 int osd_level_saved
=-1;
238 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
239 unsigned int osd_visible
;
240 static int osd_function
=OSD_PLAY
;
241 static int osd_show_percentage
= 0;
242 static int osd_duration
= 1000;
244 static int term_osd
= 1;
245 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
246 static char* playing_msg
= NULL
;
248 static char *seek_to_sec
=NULL
;
249 static off_t seek_to_byte
=0;
250 static off_t step_sec
=0;
251 static int loop_times
=-1;
252 static int loop_seek
=0;
255 int autosync
=0; // 30 might be a good default value.
257 // may be changed by GUI: (FIXME!)
258 float rel_seek_secs
=0;
262 char **audio_codec_list
=NULL
; // override audio codec
263 char **video_codec_list
=NULL
; // override video codec
264 char **audio_fm_list
=NULL
; // override audio codec family
265 char **video_fm_list
=NULL
; // override video codec family
268 extern char *demuxer_name
; // override demuxer
269 extern char *audio_demuxer_name
; // override audio demuxer
270 extern char *sub_demuxer_name
; // override sub demuxer
277 char* audio_lang
=NULL
;
278 char* dvdsub_lang
=NULL
;
279 static char* spudec_ifo
=NULL
;
280 char* filename
=NULL
; //"MI2-Trailer.avi";
281 int forced_subs_only
=0;
284 int stream_cache_size
=-1;
285 #ifdef USE_STREAM_CACHE
286 extern int cache_fill_status
;
288 float stream_cache_min_percent
=20.0;
289 float stream_cache_seek_min_percent
=50.0;
291 #define cache_fill_status 0
295 static char *stream_dump_name
="stream.dump";
296 int stream_dump_type
=0;
299 static float default_max_pts_correction
=-1;//0.01f;
300 static float max_pts_correction
=0;//default_max_pts_correction;
301 static float c_total
=0;
303 static int ignore_start
=0;
305 static int softsleep
=0;
308 static int force_srate
=0;
309 static int audio_output_format
=0;
310 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
311 static int play_n_frames
=-1;
312 static int play_n_frames_mf
=-1;
315 char** video_driver_list
=NULL
;
316 char** audio_driver_list
=NULL
;
318 extern char *vo_subdevice
;
319 extern char *ao_subdevice
;
321 // codec outfmt flags (defined in libmpcodecs/vd.c)
325 char *font_name
=NULL
;
326 #ifdef HAVE_FONTCONFIG
327 extern int font_fontconfig
;
329 float font_factor
=0.75;
330 char **sub_name
=NULL
;
334 char *vobsub_name
=NULL
;
335 /*DSP!!char *dsp=NULL;*/
337 int suboverlap_enabled
= 1;
339 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
340 int set_of_sub_size
= 0;
341 int set_of_sub_pos
= -1;
342 float sub_last_pts
= -303;
344 int global_sub_size
= 0; // this encompasses all subtitle sources
345 int global_sub_pos
= -1; // this encompasses all subtitle sources
346 #define SUB_SOURCE_SUBS 0
347 #define SUB_SOURCE_VOBSUB 1
348 #define SUB_SOURCE_DEMUX 2
349 #define SUB_SOURCES 3
350 int global_sub_indices
[SUB_SOURCES
];
353 #include "libass/ass.h"
354 #include "libass/ass_mp.h"
356 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
357 // or NULL if format unsupported
358 ass_track_t
* set_of_ass_tracks
[MAX_SUBTITLE_FILES
];
359 ass_track_t
* ass_track
= 0; // current track to render
362 extern int mp_msg_levels
[MSGT_MAX
];
363 extern int mp_msg_level_all
;
365 static stream_t
* stream
=NULL
;
366 static demuxer_t
*demuxer
=NULL
;
367 static sh_audio_t
*sh_audio
=NULL
;
368 static sh_video_t
*sh_video
=NULL
;
369 static demux_stream_t
*d_audio
=NULL
;
370 static demux_stream_t
*d_video
=NULL
;
371 static demux_stream_t
*d_dvdsub
=NULL
;
373 char* current_module
=NULL
; // for debugging
375 extern int vo_gamma_gamma
;
376 extern int vo_gamma_brightness
;
377 extern int vo_gamma_contrast
;
378 extern int vo_gamma_saturation
;
379 extern int vo_gamma_hue
;
384 #include "m_struct.h"
385 #include "libmenu/menu.h"
386 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
387 extern vf_info_t vf_info_menu
;
388 static vf_info_t
* libmenu_vfs
[] = {
392 static vf_instance_t
* vf_menu
= NULL
;
393 static int use_menu
= 0;
394 static char* menu_cfg
= NULL
;
395 static char* menu_root
= "main";
401 static char* rtc_device
;
404 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
405 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
406 short user_muted
= 0; ///< Stores whether user wanted muted mode.
407 short edl_muted
= 0; ///< Stores whether EDL is currently in muted mode.
408 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
409 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
410 float begin_skip
= MP_NOPTS_VALUE
; ///< start time of the current skip while on edlout mode
412 static unsigned int inited_flags
=0;
416 #define INITED_GETCH2 8
417 #define INITED_SPUDEC 32
418 #define INITED_STREAM 64
419 #define INITED_INPUT 128
420 #define INITED_VOBSUB 256
421 #define INITED_DEMUXER 512
422 #define INITED_ACODEC 1024
423 #define INITED_VCODEC 2048
424 #define INITED_ALL 0xFFFF
426 static void uninit_player(unsigned int mask
){
427 mask
=inited_flags
&mask
;
429 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
431 if(mask
&INITED_ACODEC
){
432 inited_flags
&=~INITED_ACODEC
;
433 current_module
="uninit_acodec";
434 if(sh_audio
) uninit_audio(sh_audio
);
436 guiGetEvent(guiSetAfilter
, (char *)NULL
);
441 if(mask
&INITED_VCODEC
){
442 inited_flags
&=~INITED_VCODEC
;
443 current_module
="uninit_vcodec";
444 if(sh_video
) uninit_video(sh_video
);
451 if(mask
&INITED_DEMUXER
){
452 inited_flags
&=~INITED_DEMUXER
;
453 current_module
="free_demuxer";
455 stream
=demuxer
->stream
;
456 free_demuxer(demuxer
);
461 // kill the cache process:
462 if(mask
&INITED_STREAM
){
463 inited_flags
&=~INITED_STREAM
;
464 current_module
="uninit_stream";
465 if(stream
) free_stream(stream
);
470 inited_flags
&=~INITED_VO
;
471 current_module
="uninit_vo";
476 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
477 if(mask
&INITED_GETCH2
){
478 inited_flags
&=~INITED_GETCH2
;
479 current_module
="uninit_getch2";
480 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
485 if(mask
&INITED_VOBSUB
){
486 inited_flags
&=~INITED_VOBSUB
;
487 current_module
="uninit_vobsub";
488 if(vo_vobsub
) vobsub_close(vo_vobsub
);
492 if (mask
&INITED_SPUDEC
){
493 inited_flags
&=~INITED_SPUDEC
;
494 current_module
="uninit_spudec";
495 spudec_free(vo_spudec
);
500 inited_flags
&=~INITED_AO
;
501 current_module
="uninit_ao";
502 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
507 inited_flags
&=~INITED_GUI
;
508 current_module
="uninit_gui";
513 if(mask
&INITED_INPUT
){
514 inited_flags
&=~INITED_INPUT
;
515 current_module
="uninit_input";
522 static void exit_player_with_rc(const char* how
, int rc
){
524 uninit_player(INITED_ALL
);
529 vo_uninit(); // Close the X11 connection (if any is open).
533 current_module
="uninit_font";
534 if (vo_font
) free_font_desc(vo_font
);
540 current_module
="exit_player";
542 // free mplayer config
544 m_config_free(mconfig
);
547 play_tree_free(playtree
, 1);
550 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
551 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
552 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
557 void exit_player(const char* how
){
558 exit_player_with_rc(how
, 1);
562 static void child_sighandler(int x
){
564 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
569 static char *prog_path
;
570 static int crash_debug
= 0;
573 static void exit_sighandler(int x
){
574 static int sig_count
=0;
576 if (!crash_debug
|| x
!= SIGTRAP
)
579 if(inited_flags
==0 && sig_count
>1) exit(1);
582 /* We're crashing bad and can't uninit cleanly :(
583 * by popular request, we make one last (dirty)
584 * effort to restore the user's
589 if(sig_count
==6) exit(1);
593 kill(getpid(),SIGKILL
);
596 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
597 current_module
?current_module
:"unknown"
599 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
606 break; // killed from keyboard (^C) or killed [-9]
608 #ifdef RUNTIME_CPUDETECT
609 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
611 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
615 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
617 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
622 snprintf(spid
, 19, "%i", getpid());
624 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
626 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
627 if (gdb_pid
== 0) { // We are the child
628 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
629 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
630 } else if (gdb_pid
< 0)
631 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
633 waitpid(gdb_pid
, NULL
, 0);
635 if (x
== SIGTRAP
) return;
642 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
644 extern void mp_input_register_options(m_config_t
* cfg
);
648 /// step size of mixer changes
651 #include "cfg-mplayer.h"
653 static void parse_cfgfiles( m_config_t
* conf
)
657 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
659 if ((conffile
= get_path("")) == NULL
) {
660 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
665 mkdir(conffile
, 0777);
668 if ((conffile
= get_path("config")) == NULL
) {
669 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
671 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
672 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
673 write(conffile_fd
, default_config
, strlen(default_config
));
676 if (m_config_parse_config_file(conf
, conffile
) < 0)
683 void load_per_file_config (m_config_t
* conf
, const char *const file
)
686 char cfg
[strlen(file
)+10];
690 sprintf (cfg
, "%s.conf", file
);
692 if (!stat (cfg
, &st
))
694 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
695 m_config_parse_config_file (conf
, cfg
);
699 if ((name
= strrchr (cfg
, '/')) == NULL
)
704 if ((confpath
= get_path (name
)) != NULL
)
706 if (!stat (confpath
, &st
))
708 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
709 m_config_parse_config_file (conf
, confpath
);
716 /* When libmpdemux performs a blocking operation (network connection or
717 * cache filling) if the operation fails we use this function to check
718 * if it was interrupted by the user.
719 * The function returns a new value for eof. */
720 static int libmpdemux_was_interrupted(int eof
) {
722 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
725 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
726 case MP_CMD_PLAY_TREE_STEP
: {
727 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
728 play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
730 case MP_CMD_PLAY_TREE_UP_STEP
: {
731 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
733 case MP_CMD_PLAY_ALT_SRC_STEP
: {
734 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
742 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
743 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
745 int playtree_add_playlist(play_tree_t
* entry
)
747 play_tree_add_bpf(entry
,filename
);
752 import_playtree_playlist_into_gui(entry
, mconfig
);
753 play_tree_free_list(entry
,1);
759 entry
= playtree_iter
->tree
;
760 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
761 return PT_NEXT_ENTRY
;
763 if(playtree_iter
->tree
== entry
) { // Loop with a single file
764 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
765 return PT_NEXT_ENTRY
;
768 play_tree_remove(entry
,1,1);
771 play_tree_insert_entry(playtree_iter
->tree
,entry
);
772 play_tree_set_params_from(entry
,playtree_iter
->tree
);
773 entry
= playtree_iter
->tree
;
774 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
775 return PT_NEXT_ENTRY
;
777 play_tree_remove(entry
,1,1);
787 for (i
= 0; i
< SUB_SOURCES
; i
++) {
788 int j
= global_sub_indices
[i
];
789 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
799 sub_data
* subdata
= NULL
;
800 static subtitle
* vo_sub_last
= NULL
;
802 void add_subtitles(char *filename
, float fps
, int silent
)
806 ass_track_t
*asst
= 0;
809 if (filename
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
813 subd
= sub_read_file(filename
, fps
);
816 asst
= ass_read_file(filename
);
817 if (ass_enabled
&& !asst
)
818 asst
= ass_read_subdata(subd
, fps
);
820 if (!asst
&& !subd
&& !silent
)
824 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
827 if (!asst
&& !subd
) return;
828 set_of_ass_tracks
[set_of_sub_size
] = asst
;
832 set_of_subtitles
[set_of_sub_size
] = subd
;
833 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", set_of_sub_size
);
834 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n", filename
);
836 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, set_of_sub_size
, filename
);
839 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
840 void update_set_of_subtitles(void)
841 // subdata was changed, set_of_sub... have to be updated.
844 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
845 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
846 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
847 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
849 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
851 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
852 set_of_subtitles
[set_of_sub_pos
] = subdata
;
854 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
855 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
862 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
863 * make it all work is to use the builtin SDL-bootstrap code, which
864 * will be done automatically by replacing our main() if we include SDL.h.
866 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
871 * \brief append a formatted string
872 * \param buf buffer to print into
873 * \param pos position of terminating 0 in buf
874 * \param len maximum number of characters in buf, not including terminating 0
875 * \param format printf format string
877 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
880 va_start(va
, format
);
881 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
890 * \brief append time in the hh:mm:ss.f format
891 * \param buf buffer to print into
892 * \param pos position of terminating 0 in buf
893 * \param len maximum number of characters in buf, not including terminating 0
894 * \param time time value to convert/append
896 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
897 long tenths
= 10 * time
;
898 int f1
= tenths
% 10;
899 int ss
= (tenths
/ 10) % 60;
900 int mm
= (tenths
/ 600) % 60;
901 int hh
= tenths
/ 36000;
903 saddf(buf
, pos
, len
, "unknown");
907 saddf(buf
, pos
, len
, "%2d:", hh
);
908 if (hh
> 0 || mm
> 0)
909 saddf(buf
, pos
, len
, "%02d:", mm
);
910 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
914 * \brief print the status line
915 * \param a_pos audio position
916 * \param a_v A-V desynchronization
917 * \param corr amount out A-V synchronization
919 static void print_status(float a_pos
, float a_v
, float corr
)
925 if (screen_width
> 0)
926 width
= screen_width
;
930 /* Windows command line is broken (MinGW's rxvt works, but we
931 * should not depend on that). */
934 line
= malloc(width
+ 1); // one additional char for the terminating null
938 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
940 float len
= demuxer_get_time_length(demuxer
);
941 saddf(line
, &pos
, width
, "(");
942 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
943 saddf(line
, &pos
, width
, ") of %.1f (", len
);
944 sadd_hhmmssf(line
, &pos
, width
, len
);
945 saddf(line
, &pos
, width
, ") ");
951 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
954 if (sh_audio
&& sh_video
)
955 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
959 saddf(line
, &pos
, width
, "%3d/%3d ",
960 (int)sh_video
->num_frames
,
961 (int)sh_video
->num_frames_decoded
);
965 if (sh_video
->timer
> 0.5)
966 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
967 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
968 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
969 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
971 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
972 } else if (sh_audio
) {
973 if (sh_audio
->delay
> 0.5)
974 saddf(line
, &pos
, width
, "%4.1f%% ",
975 100.0*audio_time_usage
/(double)sh_audio
->delay
);
977 saddf(line
, &pos
, width
, "??,?%% ");
982 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
984 #ifdef USE_STREAM_CACHE
986 if (stream_cache_size
> 0)
987 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
991 if (playback_speed
!= 1)
992 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
995 if (erase_to_end_of_line
) {
997 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
999 memset(&line
[pos
], ' ', width
- pos
);
1001 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
1007 * \brief build a chain of audio filters that converts the input format
1008 * to the ao's format, taking into account the current playback_speed.
1009 * \param sh_audio describes the requested input format of the chain.
1010 * \param ao_data describes the requested output format of the chain.
1012 static int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1019 guiGetEvent(guiSetAfilter
, (char *)NULL
);
1021 mixer
.afilter
= NULL
;
1024 new_srate
= sh_audio
->samplerate
* playback_speed
;
1025 if (new_srate
!= ao_data
->samplerate
) {
1026 // limits are taken from libaf/af_resample.c
1027 if (new_srate
< 8000)
1029 if (new_srate
> 192000)
1031 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1033 result
= init_audio_filters(sh_audio
, new_srate
,
1034 sh_audio
->channels
, sh_audio
->sample_format
,
1035 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1036 ao_data
->outburst
* 4, ao_data
->buffersize
);
1037 mixer
.afilter
= sh_audio
->afilter
;
1039 guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1046 * \brief Log the currently displayed subtitle to a file
1048 * Logs the current or last displayed subtitle together with filename
1049 * and time information to ~/.mplayer/subtitle_log
1051 * Intended purpose is to allow convenient marking of bogus subtitles
1052 * which need to be fixed while watching the movie.
1055 static void log_sub(void){
1060 if (subdata
== NULL
|| vo_sub_last
== NULL
) return;
1061 fname
= get_path("subtitle_log");
1062 f
= fopen(fname
, "a");
1064 fprintf(f
, "----------------------------------------------------------\n");
1065 if (subdata
->sub_uses_time
) {
1066 fprintf(f
, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename
,
1067 vo_sub_last
->start
/360000, (vo_sub_last
->start
/6000)%60,
1068 (vo_sub_last
->start
/100)%60, vo_sub_last
->start
%100,
1069 vo_sub_last
->end
/360000, (vo_sub_last
->end
/6000)%60,
1070 (vo_sub_last
->end
/100)%60, vo_sub_last
->end
%100);
1072 fprintf(f
, "N: %s S: %ld E: %ld\n", filename
, vo_sub_last
->start
, vo_sub_last
->end
);
1074 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
1075 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
1079 #endif /* USE_SUB */
1081 /// \defgroup OSDMsgStack OSD message stack
1085 #define OSD_MSG_TV_CHANNEL 0
1086 #define OSD_MSG_TEXT 1
1087 #define OSD_MSG_SUB_DELAY 2
1088 #define OSD_MSG_SPEED 3
1089 #define OSD_MSG_OSD_STATUS 4
1090 #define OSD_MSG_BAR 5
1091 #define OSD_MSG_PAUSE 6
1092 /// Base id for messages generated from the commmand to property bridge.
1093 #define OSD_MSG_PROPERTY 0x100
1096 typedef struct mp_osd_msg mp_osd_msg_t
;
1098 /// Previous message on the stack.
1102 int id
,level
,started
;
1103 /// Display duration in ms.
1107 /// OSD message stack.
1108 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1111 * \brief Add a message on the OSD message stack
1113 * If a message with the same id is already present in the stack
1114 * it is pulled on top of the stack, otherwise a new message is created.
1118 static void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1119 mp_osd_msg_t
*msg
,*last
=NULL
;
1123 // look if the id is already in the stack
1124 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1125 last
= msg
, msg
= msg
->prev
);
1126 // not found: alloc it
1128 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1129 msg
->prev
= osd_msg_stack
;
1130 osd_msg_stack
= msg
;
1131 } else if(last
) { // found, but it's not on top of the stack
1132 last
->prev
= msg
->prev
;
1133 msg
->prev
= osd_msg_stack
;
1134 osd_msg_stack
= msg
;
1138 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1140 if(r
>= 64) msg
->msg
[63] = 0;
1149 * \brief Remove a message from the OSD stack
1151 * This function can be used to get rid of a message right away.
1155 static void rm_osd_msg(int id
) {
1156 mp_osd_msg_t
*msg
,*last
=NULL
;
1158 // Search for the msg
1159 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1160 last
= msg
, msg
= msg
->prev
);
1163 // Detach it from the stack and free it
1165 last
->prev
= msg
->prev
;
1167 osd_msg_stack
= msg
->prev
;
1172 * \brief Remove all messages from the OSD stack
1176 static void clear_osd_msgs(void) {
1177 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1183 osd_msg_stack
= NULL
;
1187 * \brief Get the current message from the OSD stack.
1189 * This function decrements the message timer and destroys the old ones.
1190 * The message that should be displayed is returned (if any).
1194 static mp_osd_msg_t
* get_osd_msg(void) {
1195 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1196 static unsigned last_update
= 0;
1197 unsigned now
= GetTimerMS();
1199 char hidden_dec_done
= 0;
1201 if(!last_update
) last_update
= now
;
1202 diff
= now
>= last_update
? now
- last_update
: 0;
1206 // Look for the first message in the stack with high enough level.
1207 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1209 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1210 // The message has a high enough level or it is the first hidden one
1211 // in both cases we decrement the timer or kill it.
1212 if(!msg
->started
|| msg
->time
> diff
) {
1213 if(msg
->started
) msg
->time
-= diff
;
1214 else msg
->started
= 1;
1216 if(msg
->level
<= osd_level
) return msg
;
1217 hidden_dec_done
= 1;
1226 osd_msg_stack
= prev
;
1234 // Make a define to test if we are using the term OSD without having
1235 // to #ifdef USE_OSD all the time.
1237 #define use_term_osd (term_osd && !sh_video)
1239 #define use_term_osd (term_osd)
1243 * \brief Display the OSD bar.
1245 * Display the OSD bar or fall back on a simple message.
1249 void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1251 if(osd_level
< 1) return;
1255 osd_visible
= (GetTimerMS() + 1000) | 1;
1256 vo_osd_progbar_type
= type
;
1257 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1258 vo_osd_changed(OSDTYPE_PROGBAR
);
1263 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1264 name
,ROUND(100*(val
-min
)/(max
-min
)));
1269 * \brief Update the OSD message line.
1271 * This function displays the current message on the vo OSD or on the term.
1272 * If the stack is empty and the OSD level is high enough the timer
1273 * is displayed (only on the vo OSD).
1277 static void update_osd_msg(void) {
1279 static char osd_text
[64] = "";
1280 static char osd_text_timer
[64];
1283 // we need some mem for vo_osd_text
1284 vo_osd_text
= (unsigned char*)osd_text
;
1287 // Look if we have a msg
1288 if((msg
= get_osd_msg())) {
1289 if(strcmp(osd_text
,msg
->msg
)) {
1290 strncpy((char*)osd_text
, msg
->msg
, 63);
1292 if(sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1294 if(term_osd
) printf("%s%s\n",term_osd_esc
,msg
->msg
);
1301 // fallback on the timer
1303 int len
= demuxer_get_time_length(demuxer
);
1304 int percentage
= -1;
1305 char percentage_text
[10];
1306 int pts
= sh_video
->pts
;
1308 if (osd_show_percentage
)
1309 percentage
= demuxer_get_percent_pos(demuxer
);
1311 if (percentage
>= 0)
1312 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1314 percentage_text
[0] = 0;
1317 snprintf(osd_text_timer
, 63,
1318 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1319 osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1320 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1322 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1323 osd_function
,pts
/3600,(pts
/60)%60,
1324 pts
%60,percentage_text
);
1326 osd_text_timer
[0]=0;
1328 // always decrement the percentage timer
1329 if(osd_show_percentage
)
1330 osd_show_percentage
--;
1332 if(strcmp(osd_text
,osd_text_timer
)) {
1333 strncpy(osd_text
, osd_text_timer
, 63);
1334 vo_osd_changed(OSDTYPE_OSD
);
1340 // Clear the term osd line
1341 if(term_osd
&& osd_text
[0]) {
1343 printf("%s\n",term_osd_esc
);
1350 /// \defgroup Properties
1353 /// \defgroup GeneralProperties General properties
1354 /// \ingroup Properties
1358 static int mp_property_osdlevel(m_option_t
* prop
,int action
,void* arg
) {
1359 return m_property_choice(prop
,action
,arg
,&osd_level
);
1362 /// Playback speed (RW)
1363 static int mp_property_playback_speed(m_option_t
* prop
,int action
,void* arg
) {
1365 case M_PROPERTY_SET
:
1367 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1368 playback_speed
= *(float*)arg
;
1369 build_afilter_chain(sh_audio
, &ao_data
);
1371 case M_PROPERTY_STEP_UP
:
1372 case M_PROPERTY_STEP_DOWN
:
1373 playback_speed
+= (arg
? *(float*)arg
: 0.1) *
1374 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1375 M_PROPERTY_CLAMP(prop
,playback_speed
);
1376 build_afilter_chain(sh_audio
, &ao_data
);
1379 return m_property_float_range(prop
,action
,arg
,&playback_speed
);
1382 /// filename with path (RO)
1383 static int mp_property_path(m_option_t
* prop
,int action
,void* arg
) {
1384 return m_property_string_ro(prop
,action
,arg
,filename
);
1387 /// filename without path (RO)
1388 static int mp_property_filename(m_option_t
* prop
,int action
,void* arg
) {
1390 if(!filename
) return M_PROPERTY_UNAVAILABLE
;
1391 if(((f
= strrchr(filename
,'/')) || (f
= strrchr(filename
,'\\'))) && f
[1])
1395 return m_property_string_ro(prop
,action
,arg
,f
);
1398 /// Demuxer name (RO)
1399 static int mp_property_demuxer(m_option_t
* prop
,int action
,void* arg
) {
1400 if(!demuxer
) return M_PROPERTY_UNAVAILABLE
;
1401 return m_property_string_ro(prop
,action
,arg
,(char*)demuxer
->desc
->name
);
1404 /// Position in the stream (RW)
1405 static int mp_property_stream_pos(m_option_t
* prop
,int action
,void* arg
) {
1406 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1407 if (!arg
) return M_PROPERTY_ERROR
;
1409 case M_PROPERTY_GET
:
1410 *(off_t
*)arg
= stream_tell(demuxer
->stream
);
1411 return M_PROPERTY_OK
;
1412 case M_PROPERTY_SET
:
1413 M_PROPERTY_CLAMP(prop
,*(off_t
*)arg
);
1414 stream_seek(demuxer
->stream
, *(off_t
*)arg
);
1415 return M_PROPERTY_OK
;
1417 return M_PROPERTY_NOT_IMPLEMENTED
;
1420 /// Stream start offset (RO)
1421 static int mp_property_stream_start(m_option_t
* prop
,int action
,void* arg
) {
1422 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1424 case M_PROPERTY_GET
:
1425 *(off_t
*)arg
= demuxer
->stream
->start_pos
;
1426 return M_PROPERTY_OK
;
1428 return M_PROPERTY_NOT_IMPLEMENTED
;
1431 /// Stream end offset (RO)
1432 static int mp_property_stream_end(m_option_t
* prop
,int action
,void* arg
) {
1433 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1435 case M_PROPERTY_GET
:
1436 *(off_t
*)arg
= demuxer
->stream
->end_pos
;
1437 return M_PROPERTY_OK
;
1439 return M_PROPERTY_NOT_IMPLEMENTED
;
1442 /// Stream length (RO)
1443 static int mp_property_stream_length(m_option_t
* prop
,int action
,void* arg
) {
1444 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1446 case M_PROPERTY_GET
:
1447 *(off_t
*)arg
= demuxer
->stream
->end_pos
- demuxer
->stream
->start_pos
;
1448 return M_PROPERTY_OK
;
1450 return M_PROPERTY_NOT_IMPLEMENTED
;
1453 /// Media length in seconds (RO)
1454 static int mp_property_length(m_option_t
* prop
,int action
,void* arg
) {
1458 !(int)(len
= demuxer_get_time_length(demuxer
)))
1459 return M_PROPERTY_UNAVAILABLE
;
1462 case M_PROPERTY_PRINT
:
1470 *(char**)arg
= malloc(20);
1471 if(h
> 0) sprintf(*(char**)arg
,"%d:%02d:%02d",h
,m
,s
);
1472 else if(m
> 0) sprintf(*(char**)arg
,"%d:%02d",m
,s
);
1473 else sprintf(*(char**)arg
,"%d",s
);
1478 return m_property_double_ro(prop
,action
,arg
,len
);
1483 /// \defgroup AudioProperties Audio properties
1484 /// \ingroup Properties
1488 static int mp_property_volume(m_option_t
* prop
,int action
,void* arg
) {
1490 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1493 case M_PROPERTY_GET
:
1495 mixer_getbothvolume(&mixer
,arg
);
1497 case M_PROPERTY_PRINT
:{
1500 mixer_getbothvolume(&mixer
,&vol
);
1501 return m_property_float_range(prop
,action
,arg
,&vol
);
1503 case M_PROPERTY_STEP_UP
:
1504 case M_PROPERTY_STEP_DOWN
:
1505 case M_PROPERTY_SET
:
1508 return M_PROPERTY_NOT_IMPLEMENTED
;
1511 if (edl_muted
) return M_PROPERTY_DISABLED
;
1515 case M_PROPERTY_SET
:
1517 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1518 mixer_setvolume(&mixer
,*(float*)arg
,*(float*)arg
);
1520 case M_PROPERTY_STEP_UP
:
1521 if(arg
&& *(float*)arg
<= 0)
1522 mixer_decvolume(&mixer
);
1524 mixer_incvolume(&mixer
);
1526 case M_PROPERTY_STEP_DOWN
:
1527 if(arg
&& *(float*)arg
<= 0)
1528 mixer_incvolume(&mixer
);
1530 mixer_decvolume(&mixer
);
1533 return M_PROPERTY_NOT_IMPLEMENTED
;
1537 static int mp_property_mute(m_option_t
* prop
,int action
,void* arg
) {
1539 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1542 case M_PROPERTY_SET
:
1543 if(edl_muted
) return M_PROPERTY_DISABLED
;
1545 if((!!*(int*)arg
) != mixer
.muted
)
1547 user_muted
= mixer
.muted
;
1549 case M_PROPERTY_STEP_UP
:
1550 case M_PROPERTY_STEP_DOWN
:
1551 if(edl_muted
) return M_PROPERTY_DISABLED
;
1553 user_muted
= mixer
.muted
;
1555 case M_PROPERTY_PRINT
:
1558 *(char**)arg
= strdup(MSGTR_EnabledEdl
);
1562 return m_property_flag(prop
,action
,arg
,&mixer
.muted
);
1567 /// Audio delay (RW)
1568 static int mp_property_audio_delay(m_option_t
* prop
,int action
,void* arg
) {
1569 if(!(sh_audio
&& sh_video
)) return M_PROPERTY_UNAVAILABLE
;
1571 case M_PROPERTY_SET
:
1572 case M_PROPERTY_STEP_UP
:
1573 case M_PROPERTY_STEP_DOWN
:
1576 float delay
= audio_delay
;
1577 m_property_delay(prop
,action
,arg
,&audio_delay
);
1578 if(sh_audio
) sh_audio
->delay
-= audio_delay
-delay
;
1582 return m_property_delay(prop
,action
,arg
,&audio_delay
);
1586 /// Audio codec tag (RO)
1587 static int mp_property_audio_format(m_option_t
* prop
,int action
,void* arg
) {
1588 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1589 return m_property_int_ro(prop
,action
,arg
,sh_audio
->format
);
1592 /// Audio bitrate (RO)
1593 static int mp_property_audio_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1594 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1595 return m_property_int_ro(prop
,action
,arg
,sh_audio
->i_bps
);
1599 static int mp_property_samplerate(m_option_t
* prop
,int action
,void* arg
) {
1600 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1601 return m_property_int_ro(prop
,action
,arg
,sh_audio
->samplerate
);
1604 /// Number of channels (RO)
1605 static int mp_property_channels(m_option_t
* prop
,int action
,void* arg
) {
1606 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1608 case M_PROPERTY_PRINT
:
1610 switch(sh_audio
->channels
) {
1611 case 1: *(char**)arg
= strdup("mono"); break;
1612 case 2: *(char**)arg
= strdup("stereo"); break;
1614 *(char**)arg
= malloc(32);
1615 sprintf(*(char**)arg
,"%d channels",sh_audio
->channels
);
1619 return m_property_int_ro(prop
,action
,arg
,sh_audio
->channels
);
1624 /// \defgroup VideoProperties Video properties
1625 /// \ingroup Properties
1628 /// Fullscreen state (RW)
1629 static int mp_property_fullscreen(m_option_t
* prop
,int action
,void* arg
) {
1631 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1634 case M_PROPERTY_SET
:
1636 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1637 if(vo_fs
== !!*(int*)arg
) return 1;
1638 case M_PROPERTY_STEP_UP
:
1639 case M_PROPERTY_STEP_DOWN
:
1641 if(use_gui
) guiGetEvent(guiIEvent
,(char*)MP_CMD_GUI_FULLSCREEN
);
1644 if(vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
1647 return m_property_flag(prop
,action
,arg
,&vo_fs
);
1652 static int mp_property_panscan(m_option_t
* prop
,int action
,void* arg
) {
1654 if(!video_out
|| video_out
->control(VOCTRL_GET_PANSCAN
,NULL
) != VO_TRUE
)
1655 return M_PROPERTY_UNAVAILABLE
;
1658 case M_PROPERTY_SET
:
1660 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1661 vo_panscan
= *(float*)arg
;
1662 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
1664 case M_PROPERTY_STEP_UP
:
1665 case M_PROPERTY_STEP_DOWN
:
1666 vo_panscan
+= (arg
? *(float*)arg
: 0.1) *
1667 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1668 if(vo_panscan
> 1) vo_panscan
= 1;
1669 else if(vo_panscan
< 0) vo_panscan
= 0;
1670 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
1673 return m_property_float_range(prop
,action
,arg
,&vo_panscan
);
1677 /// Helper to set vo flags.
1678 /** \ingroup PropertyImplHelper
1680 static int mp_property_vo_flag(m_option_t
* prop
,int action
,void* arg
,
1681 int vo_ctrl
,int* vo_var
) {
1683 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1686 case M_PROPERTY_SET
:
1688 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1689 if(*vo_var
== !!*(int*)arg
) return 1;
1690 case M_PROPERTY_STEP_UP
:
1691 case M_PROPERTY_STEP_DOWN
:
1692 if(vo_config_count
) video_out
->control(vo_ctrl
, 0);
1695 return m_property_flag(prop
,action
,arg
,vo_var
);
1699 /// Window always on top (RW)
1700 static int mp_property_ontop(m_option_t
* prop
,int action
,void* arg
) {
1701 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ONTOP
,&vo_ontop
);
1704 /// Display in the root window (RW)
1705 static int mp_property_rootwin(m_option_t
* prop
,int action
,void* arg
) {
1706 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ROOTWIN
,&vo_rootwin
);
1709 /// Show window borders (RW)
1710 static int mp_property_border(m_option_t
* prop
,int action
,void* arg
) {
1711 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_BORDER
,&vo_border
);
1714 /// Framedropping state (RW)
1715 static int mp_property_framedropping(m_option_t
* prop
,int action
,void* arg
) {
1717 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1720 case M_PROPERTY_PRINT
:
1722 *(char**)arg
= strdup(frame_dropping
== 1 ? MSGTR_Enabled
:
1723 (frame_dropping
== 2 ? MSGTR_HardFrameDrop
: MSGTR_Disabled
));
1726 return m_property_choice(prop
,action
,arg
,&frame_dropping
);
1730 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1731 static int mp_property_gamma(m_option_t
* prop
,int action
,void* arg
) {
1732 int* gamma
= prop
->priv
, r
;
1734 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1736 if(gamma
[0] == 1000) {
1738 get_video_colors (sh_video
, prop
->name
, gamma
);
1742 case M_PROPERTY_SET
:
1744 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1745 *gamma
= *(int*)arg
;
1746 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
1749 case M_PROPERTY_GET
:
1751 r
= get_video_colors (sh_video
, prop
->name
, arg
);
1754 case M_PROPERTY_STEP_UP
:
1755 case M_PROPERTY_STEP_DOWN
:
1756 *gamma
+= (arg
? *(int*)arg
: 1) *
1757 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1758 M_PROPERTY_CLAMP(prop
,*gamma
);
1759 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
1763 return M_PROPERTY_NOT_IMPLEMENTED
;
1767 if(demuxer
->type
== DEMUXER_TYPE_TV
) {
1768 int l
= strlen(prop
->name
);
1769 char tv_prop
[3+l
+1];
1770 sprintf(tv_prop
,"tv_%s",prop
->name
);
1771 return mp_property_do(tv_prop
,action
,arg
);
1775 return M_PROPERTY_UNAVAILABLE
;
1779 static int mp_property_vsync(m_option_t
* prop
,int action
,void* arg
) {
1780 return m_property_flag(prop
,action
,arg
,&vo_vsync
);
1783 /// Video codec tag (RO)
1784 static int mp_property_video_format(m_option_t
* prop
,int action
,void* arg
) {
1785 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1786 return m_property_int_ro(prop
,action
,arg
,sh_video
->format
);
1789 /// Video bitrate (RO)
1790 static int mp_property_video_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1791 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1792 return m_property_int_ro(prop
,action
,arg
,sh_video
->i_bps
);
1795 /// Video display width (RO)
1796 static int mp_property_width(m_option_t
* prop
,int action
,void* arg
) {
1797 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1798 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_w
);
1801 /// Video display height (RO)
1802 static int mp_property_height(m_option_t
* prop
,int action
,void* arg
) {
1803 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1804 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_h
);
1808 static int mp_property_fps(m_option_t
* prop
,int action
,void* arg
) {
1809 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1810 return m_property_float_ro(prop
,action
,arg
,sh_video
->fps
);
1813 /// Video aspect (RO)
1814 static int mp_property_aspect(m_option_t
* prop
,int action
,void* arg
) {
1815 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1816 return m_property_float_ro(prop
,action
,arg
,sh_video
->aspect
);
1821 /// \defgroup SubProprties Subtitles properties
1822 /// \ingroup Properties
1825 /// Text subtitle position (RW)
1826 static int mp_property_sub_pos(m_option_t
* prop
,int action
,void* arg
) {
1828 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1831 case M_PROPERTY_SET
:
1833 case M_PROPERTY_STEP_UP
:
1834 case M_PROPERTY_STEP_DOWN
:
1835 vo_osd_changed(OSDTYPE_SUBTITLE
);
1837 return m_property_int_range(prop
,action
,arg
,&sub_pos
);
1840 return M_PROPERTY_UNAVAILABLE
;
1844 /// Selected subtitles (RW)
1845 static int mp_property_sub(m_option_t
* prop
,int action
,void* arg
) {
1846 int source
= -1, reset_spu
= 0;
1849 if(global_sub_size
<= 0) return M_PROPERTY_UNAVAILABLE
;
1852 case M_PROPERTY_GET
:
1854 *(int*)arg
= global_sub_pos
;
1856 case M_PROPERTY_PRINT
:
1858 *(char**)arg
= malloc(64);
1859 (*(char**)arg
)[63] = 0;
1863 sub_name
= subdata
->filename
;
1866 if (ass_track
&& ass_track
->name
)
1867 sub_name
= ass_track
->name
;
1869 #if defined(USE_SUB) || defined(USE_ASS)
1873 if ((tmp2
= strrchr(tmp
, '/')))
1876 snprintf(*(char**)arg
, 63, "(%d) %s%s",
1878 strlen(tmp
) < 20 ? "" : "...",
1879 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
1883 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
&& dvdsub_id
>= 0) {
1884 char lang
[40] = MSGTR_Unknown
;
1885 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
1887 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
1890 #ifdef HAVE_OGGVORBIS
1891 if (demuxer
->type
== DEMUXER_TYPE_OGG
&& d_dvdsub
&& dvdsub_id
>= 0) {
1892 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
1893 if (!lang
) lang
= MSGTR_Unknown
;
1894 snprintf(*(char**)arg
, 63, "(%d) %s",
1899 if (vo_vobsub
&& vobsub_id
>= 0) {
1900 const char *language
= MSGTR_Unknown
;
1901 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
1902 snprintf(*(char**)arg
, 63, "(%d) %s",
1903 vobsub_id
, language
? language
: MSGTR_Unknown
);
1907 if (vo_spudec
&& dvdsub_id
>= 0) {
1908 char lang
[3] = "\0\0\0";
1910 code
= dvd_lang_from_sid(stream
, dvdsub_id
);
1912 lang
[0] = code
>> 8;
1916 snprintf(*(char**)arg
, 63, "(%d) %s",
1921 snprintf(*(char**)arg
, 63, MSGTR_Disabled
);
1924 case M_PROPERTY_SET
:
1926 if(*(int*)arg
< -1) *(int*)arg
= -1;
1927 else if(*(int*)arg
>= global_sub_size
) *(int*)arg
= global_sub_size
-1;
1928 global_sub_pos
= *(int*)arg
;
1930 case M_PROPERTY_STEP_UP
:
1931 global_sub_pos
+= 2;
1932 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
1934 case M_PROPERTY_STEP_DOWN
:
1935 global_sub_pos
+= global_sub_size
+1;
1936 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
1939 return M_PROPERTY_NOT_IMPLEMENTED
;
1942 if (global_sub_pos
>= 0)
1943 source
= sub_source();
1945 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
,
1946 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1947 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
1948 global_sub_indices
[SUB_SOURCE_SUBS
],
1949 global_sub_indices
[SUB_SOURCE_DEMUX
],
1950 global_sub_pos
, source
);
1953 set_of_sub_pos
= -1;
1955 vo_sub_last
= vo_sub
= NULL
;
1960 if(d_dvdsub
->id
> -2) reset_spu
= 1;
1967 if (source
== SUB_SOURCE_VOBSUB
) {
1968 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
1970 } else if (source
== SUB_SOURCE_SUBS
) {
1971 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
1973 if (ass_enabled
&& set_of_ass_tracks
[set_of_sub_pos
])
1974 ass_track
= set_of_ass_tracks
[set_of_sub_pos
];
1978 subdata
= set_of_subtitles
[set_of_sub_pos
];
1979 vo_osd_changed(OSDTYPE_SUBTITLE
);
1982 } else if (source
== SUB_SOURCE_DEMUX
) {
1983 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
1986 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
1987 d_dvdsub
->id
= dvdsub_id
;
1988 spudec_reset(vo_spudec
);
1991 #ifdef HAVE_OGGVORBIS
1992 if (demuxer
->type
== DEMUXER_TYPE_OGG
)
1993 d_dvdsub
->id
= demux_ogg_sub_id(demuxer
, dvdsub_id
);
1995 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
1996 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
1998 if (ass_enabled
&& (d_dvdsub
->id
>= 0) &&
1999 (((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'a')) {
2000 ass_track
= ((sh_sub_t
*)d_dvdsub
->sh
)->ass_track
;
2003 if (d_dvdsub
->id
>= 0 &&
2004 ((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v') {
2005 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)d_dvdsub
->sh
;
2006 if (vo_spudec
!= NULL
)
2007 spudec_free(vo_spudec
);
2009 spudec_new_scaled_vobsub(mkv_sh_sub
->has_palette
?
2010 mkv_sh_sub
->palette
:
2011 NULL
, mkv_sh_sub
->colors
,
2012 mkv_sh_sub
->custom_colors
,
2014 mkv_sh_sub
->height
);
2015 if (!forced_subs_only
)
2016 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
2018 spudec_set_forced_subs_only(vo_spudec
,
2020 inited_flags
|= INITED_SPUDEC
;
2027 vo_osd_changed(OSDTYPE_SUBTITLE
);
2029 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2032 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
&& dvdsub_id
< 0 && reset_spu
) {
2034 d_dvdsub
->id
= dvdsub_id
;
2035 spudec_reset(vo_spudec
);
2042 /// Subtitle delay (RW)
2043 static int mp_property_sub_delay(m_option_t
* prop
,int action
,void* arg
) {
2044 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2045 return m_property_delay(prop
,action
,arg
,&sub_delay
);
2048 /// Alignment of text subtitles (RW)
2049 static int mp_property_sub_alignment(m_option_t
* prop
,int action
,void* arg
) {
2051 char* name
[] = { MSGTR_Top
, MSGTR_Center
, MSGTR_Bottom
};
2053 if(!sh_video
|| global_sub_pos
< 0 || sub_source() != SUB_SOURCE_SUBS
)
2054 return M_PROPERTY_UNAVAILABLE
;
2057 case M_PROPERTY_PRINT
:
2059 M_PROPERTY_CLAMP(prop
,sub_alignment
);
2060 *(char**)arg
= strdup(name
[sub_alignment
]);
2062 case M_PROPERTY_SET
:
2064 case M_PROPERTY_STEP_UP
:
2065 case M_PROPERTY_STEP_DOWN
:
2066 vo_osd_changed(OSDTYPE_SUBTITLE
);
2068 return m_property_choice(prop
,action
,arg
,&sub_alignment
);
2071 return M_PROPERTY_UNAVAILABLE
;
2075 /// Subtitle visibility (RW)
2076 static int mp_property_sub_visibility(m_option_t
* prop
,int action
,void* arg
) {
2078 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2081 case M_PROPERTY_SET
:
2083 case M_PROPERTY_STEP_UP
:
2084 case M_PROPERTY_STEP_DOWN
:
2085 vo_osd_changed(OSDTYPE_SUBTITLE
);
2086 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2088 return m_property_flag(prop
,action
,arg
,&sub_visibility
);
2091 return M_PROPERTY_UNAVAILABLE
;
2095 /// Show only forced subtitles (RW)
2096 static int mp_property_sub_forced_only(m_option_t
* prop
,int action
,void* arg
) {
2097 if(!vo_spudec
) return M_PROPERTY_UNAVAILABLE
;
2100 case M_PROPERTY_SET
:
2102 case M_PROPERTY_STEP_UP
:
2103 case M_PROPERTY_STEP_DOWN
:
2104 m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2105 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
2108 return m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2115 /// \defgroup TVProperties TV properties
2116 /// \ingroup Properties
2121 /// TV color settings (RW)
2122 static int mp_property_tv_color(m_option_t
* prop
,int action
,void* arg
) {
2124 tvi_handle_t
* tvh
= demuxer
->priv
;
2125 if(demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
) return M_PROPERTY_UNAVAILABLE
;
2128 case M_PROPERTY_SET
:
2130 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2131 return tv_set_color_options(tvh
,(int)prop
->priv
,*(int*)arg
);
2132 case M_PROPERTY_GET
:
2133 return tv_get_color_options(tvh
,(int)prop
->priv
,arg
);
2134 case M_PROPERTY_STEP_UP
:
2135 case M_PROPERTY_STEP_DOWN
:
2136 if((r
= tv_get_color_options(tvh
,(int)prop
->priv
,&val
)) >= 0) {
2138 val
+= (arg
? *(int*)arg
: 1) *
2139 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2140 M_PROPERTY_CLAMP(prop
,val
);
2141 return tv_set_color_options(tvh
,(int)prop
->priv
,val
);
2145 return M_PROPERTY_NOT_IMPLEMENTED
;
2152 /// All properties available in MPlayer.
2153 /** \ingroup Properties
2155 static m_option_t mp_properties
[] = {
2157 { "osdlevel", mp_property_osdlevel
, CONF_TYPE_INT
,
2158 M_OPT_RANGE
, 0, 3, NULL
},
2159 { "speed", mp_property_playback_speed
, CONF_TYPE_FLOAT
,
2160 M_OPT_RANGE
, 0.01, 100.0, NULL
},
2161 { "filename", mp_property_filename
, CONF_TYPE_STRING
,
2163 { "path", mp_property_path
, CONF_TYPE_STRING
,
2165 { "demuxer", mp_property_demuxer
, CONF_TYPE_STRING
,
2167 { "stream_pos", mp_property_stream_pos
, CONF_TYPE_POSITION
,
2168 M_OPT_MIN
, 0, 0, NULL
},
2169 { "stream_start", mp_property_stream_start
, CONF_TYPE_POSITION
,
2170 M_OPT_MIN
, 0, 0, NULL
},
2171 { "stream_end", mp_property_stream_end
, CONF_TYPE_POSITION
,
2172 M_OPT_MIN
, 0, 0, NULL
},
2173 { "stream_length", mp_property_stream_length
, CONF_TYPE_POSITION
,
2174 M_OPT_MIN
, 0, 0, NULL
},
2175 { "length", mp_property_length
, CONF_TYPE_DOUBLE
,
2179 { "volume", mp_property_volume
, CONF_TYPE_FLOAT
,
2180 M_OPT_RANGE
, 0, 100, NULL
},
2181 { "mute", mp_property_mute
, CONF_TYPE_FLAG
,
2182 M_OPT_RANGE
, 0, 1, NULL
},
2183 { "audio_delay", mp_property_audio_delay
, CONF_TYPE_FLOAT
,
2184 M_OPT_RANGE
, -100, 100, NULL
},
2185 { "audio_format", mp_property_audio_format
, CONF_TYPE_INT
,
2187 { "audio_bitrate", mp_property_audio_bitrate
, CONF_TYPE_INT
,
2189 { "samplerate", mp_property_samplerate
, CONF_TYPE_INT
,
2191 { "channels", mp_property_channels
, CONF_TYPE_INT
,
2195 { "fullscreen", mp_property_fullscreen
, CONF_TYPE_FLAG
,
2196 M_OPT_RANGE
, 0, 1, NULL
},
2197 { "ontop", mp_property_ontop
, CONF_TYPE_FLAG
,
2198 M_OPT_RANGE
, 0, 1, NULL
},
2199 { "rootwin", mp_property_rootwin
, CONF_TYPE_FLAG
,
2200 M_OPT_RANGE
, 0, 1, NULL
},
2201 { "border", mp_property_border
, CONF_TYPE_FLAG
,
2202 M_OPT_RANGE
, 0, 1, NULL
},
2203 { "framedropping", mp_property_framedropping
, CONF_TYPE_INT
,
2204 M_OPT_RANGE
, 0, 2, NULL
},
2205 { "gamma", mp_property_gamma
, CONF_TYPE_INT
,
2206 M_OPT_RANGE
, -100, 100, &vo_gamma_gamma
},
2207 { "brightness", mp_property_gamma
, CONF_TYPE_INT
,
2208 M_OPT_RANGE
, -100, 100, &vo_gamma_brightness
},
2209 { "contrast", mp_property_gamma
, CONF_TYPE_INT
,
2210 M_OPT_RANGE
, -100, 100, &vo_gamma_contrast
},
2211 { "saturation", mp_property_gamma
, CONF_TYPE_INT
,
2212 M_OPT_RANGE
, -100, 100, &vo_gamma_saturation
},
2213 { "hue", mp_property_gamma
, CONF_TYPE_INT
,
2214 M_OPT_RANGE
, -100, 100, &vo_gamma_hue
},
2215 { "panscan", mp_property_panscan
, CONF_TYPE_FLOAT
,
2216 M_OPT_RANGE
, 0, 1, NULL
},
2217 { "vsync", mp_property_vsync
, CONF_TYPE_FLAG
,
2218 M_OPT_RANGE
, 0, 1, NULL
},
2219 { "video_format", mp_property_video_format
, CONF_TYPE_INT
,
2221 { "video_bitrate", mp_property_video_bitrate
, CONF_TYPE_INT
,
2223 { "width", mp_property_width
, CONF_TYPE_INT
,
2225 { "height", mp_property_height
, CONF_TYPE_INT
,
2227 { "fps", mp_property_fps
, CONF_TYPE_FLOAT
,
2229 { "aspect", mp_property_aspect
, CONF_TYPE_FLOAT
,
2233 { "sub", mp_property_sub
, CONF_TYPE_INT
,
2234 M_OPT_MIN
, -1, 0, NULL
},
2235 { "sub_delay", mp_property_sub_delay
, CONF_TYPE_FLOAT
,
2237 { "sub_pos", mp_property_sub_pos
, CONF_TYPE_INT
,
2238 M_OPT_RANGE
, 0, 100, NULL
},
2239 { "sub_alignment", mp_property_sub_alignment
, CONF_TYPE_INT
,
2240 M_OPT_RANGE
, 0, 2, NULL
},
2241 { "sub_visibility", mp_property_sub_visibility
, CONF_TYPE_FLAG
,
2242 M_OPT_RANGE
, 0, 1, NULL
},
2243 { "sub_forced_only", mp_property_sub_forced_only
, CONF_TYPE_FLAG
,
2244 M_OPT_RANGE
, 0, 1, NULL
},
2247 { "tv_brightness", mp_property_tv_color
, CONF_TYPE_INT
,
2248 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_BRIGHTNESS
},
2249 { "tv_contrast", mp_property_tv_color
, CONF_TYPE_INT
,
2250 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_CONTRAST
},
2251 { "tv_saturation", mp_property_tv_color
, CONF_TYPE_INT
,
2252 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_SATURATION
},
2253 { "tv_hue", mp_property_tv_color
, CONF_TYPE_INT
,
2254 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_HUE
},
2257 { NULL
, NULL
, NULL
, 0, 0, 0, NULL
}
2260 m_option_t
* mp_property_find(const char* name
) {
2261 return m_option_list_find(mp_properties
,name
);
2264 int mp_property_do(const char* name
,int action
, void* val
) {
2265 m_option_t
* p
= mp_property_find(name
);
2266 if(!p
) return M_PROPERTY_UNAVAILABLE
;
2267 return m_property_do(p
,action
,val
);
2275 * \defgroup Command2Property Command to property bridge
2277 * It is used to handle most commands that just set a property
2278 * and optionally display something on the OSD.
2279 * Two kinds of commands are handled: adjust or toggle.
2281 * Adjust commands take 1 or 2 parameters: <value> <abs>
2282 * If <abs> is non-zero the property is set to the given value
2283 * otherwise it is adjusted.
2285 * Toggle commands take 0 or 1 parameters. With no parameter
2286 * or a value less than the property minimum it just steps the
2287 * property to its next value. Otherwise it sets it to the given
2293 /// List of the commands that can be handled by setting a property.
2299 /// set/adjust or toggle command
2301 /// progressbar type
2303 /// osd msg id if it must be shared
2305 /// osd msg template
2306 const char* osd_msg
;
2307 } set_prop_cmd
[] = {
2309 { "volume", MP_CMD_VOLUME
, 0, OSD_VOLUME
, -1, MSGTR_Volume
},
2310 { "mute", MP_CMD_MUTE
, 1, 0, -1, MSGTR_MuteStatus
},
2311 { "audio_delay", MP_CMD_AUDIO_DELAY
, 0, 0, -1, MSGTR_AVDelayStatus
},
2313 { "fullscreen", MP_CMD_VO_FULLSCREEN
, 1, 0, -1, NULL
},
2314 { "panscan", MP_CMD_PANSCAN
, 0, OSD_PANSCAN
, -1, MSGTR_Panscan
},
2315 { "ontop", MP_CMD_VO_ONTOP
, 1, 0, -1, MSGTR_OnTopStatus
},
2316 { "rootwin", MP_CMD_VO_ROOTWIN
, 1, 0, -1, MSGTR_RootwinStatus
},
2317 { "border", MP_CMD_VO_BORDER
, 1, 0, -1, MSGTR_BorderStatus
},
2318 { "framedropping", MP_CMD_FRAMEDROPPING
, 1, 0, -1, MSGTR_FramedroppingStatus
},
2319 { "gamma", MP_CMD_GAMMA
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Gamma
},
2320 { "brightness", MP_CMD_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2321 { "contrast", MP_CMD_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2322 { "saturation", MP_CMD_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2323 { "hue", MP_CMD_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2324 { "vsync", MP_CMD_SWITCH_VSYNC
, 1, 0, -1, MSGTR_VSyncStatus
},
2326 { "sub", MP_CMD_SUB_SELECT
, 1, 0, -1, MSGTR_SubSelectStatus
},
2327 { "sub_pos", MP_CMD_SUB_POS
, 0, 0, -1, MSGTR_SubPosStatus
},
2328 { "sub_alignment", MP_CMD_SUB_ALIGNMENT
, 1, 0, -1, MSGTR_SubAlignStatus
},
2329 { "sub_delay", MP_CMD_SUB_DELAY
, 0, 0, OSD_MSG_SUB_DELAY
, MSGTR_SubDelayStatus
},
2330 { "sub_visibility", MP_CMD_SUB_VISIBILITY
, 1, 0, -1, MSGTR_SubVisibleStatus
},
2331 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY
, 1, 0, -1, MSGTR_SubForcedOnlyStatus
},
2333 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2334 { "tv_hue", MP_CMD_TV_SET_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2335 { "tv_saturation", MP_CMD_TV_SET_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2336 { "tv_contrast", MP_CMD_TV_SET_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2338 { NULL
, 0, 0, 0, -1, NULL
}
2341 /// Handle commands that set a property.
2342 static int set_property_command(mp_cmd_t
* cmd
) {
2346 // look for the command
2347 for(i
= 0 ; set_prop_cmd
[i
].name
; i
++)
2348 if(set_prop_cmd
[i
].cmd
== cmd
->id
) break;
2349 if(!set_prop_cmd
[i
].name
) return 0;
2352 prop
= mp_property_find(set_prop_cmd
[i
].name
);
2356 if(set_prop_cmd
[i
].toggle
) {
2358 if(cmd
->nargs
> 0 && cmd
->args
[0].v
.i
>= prop
->min
)
2359 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
.i
);
2361 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,NULL
);
2362 } else if(cmd
->args
[1].v
.i
) //set
2363 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
);
2365 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,&cmd
->args
[0].v
);
2367 if(r
<= 0) return 1;
2369 if(set_prop_cmd
[i
].osd_progbar
) {
2370 if(prop
->type
== CONF_TYPE_INT
) {
2371 if(m_property_do(prop
,M_PROPERTY_GET
,&r
) > 0)
2372 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2373 set_prop_cmd
[i
].osd_msg
,
2374 prop
->min
,prop
->max
,r
);
2375 } else if(prop
->type
== CONF_TYPE_FLOAT
) {
2377 if(m_property_do(prop
,M_PROPERTY_GET
,&f
) > 0)
2378 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,set_prop_cmd
[i
].osd_msg
,
2379 prop
->min
,prop
->max
,f
);
2381 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "Property use an unsupported type.\n");
2385 if(set_prop_cmd
[i
].osd_msg
) {
2386 char* val
= m_property_print(prop
);
2388 set_osd_msg(set_prop_cmd
[i
].osd_id
>= 0 ? set_prop_cmd
[i
].osd_id
:
2389 OSD_MSG_PROPERTY
+i
,1,osd_duration
,
2390 set_prop_cmd
[i
].osd_msg
,val
);
2397 static void reinit_audio_chain(void) {
2399 current_module
="init_audio_codec";
2400 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2401 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
2402 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
2406 inited_flags
|=INITED_ACODEC
;
2407 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2410 //const ao_info_t *info=audio_out->info;
2411 current_module
="af_preinit";
2412 ao_data
.samplerate
=force_srate
;
2414 ao_data
.format
=audio_output_format
;
2416 // first init to detect best values
2417 if(!preinit_audio_filters(sh_audio
,
2419 (int)(sh_audio
->samplerate
*playback_speed
),
2420 sh_audio
->channels
, sh_audio
->sample_format
,
2422 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
2423 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
2424 exit_player(MSGTR_Exit_error
);
2427 current_module
="ao2_init";
2428 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
2432 ao_data
.format
,0))){
2434 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
2435 uninit_player(INITED_ACODEC
); // close codec
2436 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
2441 inited_flags
|=INITED_AO
;
2442 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2443 audio_out
->info
->short_name
,
2444 ao_data
.samplerate
, ao_data
.channels
,
2445 af_fmt2str_short(ao_data
.format
),
2446 af_fmt2bits(ao_data
.format
)/8 );
2447 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
2448 audio_out
->info
->name
, audio_out
->info
->author
);
2449 if(strlen(audio_out
->info
->comment
) > 0)
2450 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
2451 // init audio filters:
2453 current_module
="af_init";
2454 if(!build_afilter_chain(sh_audio
, &ao_data
)) {
2455 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
2456 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2457 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2458 // sh_audio=d_audio->sh=NULL; // -> nosound
2462 mixer
.audio_out
= audio_out
;
2463 mixer
.volstep
= volstep
;
2472 // Return pts value corresponding to the end point of audio written to the
2474 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
2476 // first calculate the end pts of audio that has been output by decoder
2477 double a_pts
= sh_audio
->pts
;
2478 if (a_pts
!= MP_NOPTS_VALUE
)
2479 // Good, decoder supports new way of calculating audio pts.
2480 // sh_audio->pts is the timestamp of the latest input packet with
2481 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2482 // the amount of bytes the decoder has written after that timestamp.
2483 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
2485 // Decoder doesn't support new way of calculating pts (or we're
2486 // being called before it has decoded anything with known timestamp).
2487 // Use the old method of audio pts calculation: take the timestamp
2488 // of last packet with known pts the decoder has read data from,
2489 // and add amount of bytes read after the beginning of that packet
2490 // divided by input bps. This will be inaccurate if the input/output
2491 // ratio is not constant for every audio packet or if it is constant
2492 // but not accurately known in sh_audio->i_bps.
2494 a_pts
= d_audio
->pts
;
2495 // ds_tell_pts returns bytes read after last timestamp from
2496 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2497 // it has read but not decoded
2498 if (sh_audio
->i_bps
)
2499 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
2500 (double)sh_audio
->i_bps
;
2502 // Now a_pts hopefully holds the pts for end of audio from decoder.
2503 // Substract data in buffers between decoder and audio out.
2505 // Decoded but not filtered
2506 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
2508 // Data that was ready for ao but was buffered because ao didn't fully
2509 // accept everything to internal buffers yet
2510 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
2515 // Return pts value corresponding to currently playing audio.
2516 static double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
2517 ao_functions_t
*audio_out
)
2519 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
2520 audio_out
->get_delay();
2524 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
2526 unsigned char *start
;
2532 current_module
= "decode video";
2533 // XXX Time used in this call is not counted in any performance
2535 if (vf_output_queued_frame(sh_video
->vfilter
))
2537 current_module
= "video_read_frame";
2538 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
2540 // try to extract last frames in case of decoder lag
2545 if (in_size
> max_framesize
)
2546 max_framesize
= in_size
;
2547 if (pts
== MP_NOPTS_VALUE
)
2548 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts value from demuxer MISSING\n");
2549 if (decode_video(sh_video
, start
, in_size
, 0, pts
))
2558 int main(int argc
,char* argv
[]){
2563 int file_format
=DEMUXER_TYPE_UNKNOWN
;
2571 /* Flag indicating whether MPlayer should exit without playing anything. */
2574 //float a_frame=0; // Audio
2579 int gui_no_filename
=0;
2581 struct {double pts
; vo_functions_t
*vo
;} vf_vo_data
;
2583 srand((int) time(NULL
));
2589 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2006 MPlayer Team\n");
2590 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2591 GetCpuCaps(&gCpuCaps
);
2592 #if defined(ARCH_X86) || defined(ARCH_X86_64)
2593 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2594 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
2595 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
2596 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
2597 #ifdef RUNTIME_CPUDETECT
2598 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
2600 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
2602 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
2605 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
2608 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
2611 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
2614 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
2617 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
2619 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
2620 #endif /* RUNTIME_CPUDETECT */
2621 #endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */
2623 #if defined(WIN32) && defined(USE_WIN32DLL)
2625 #endif /*WIN32 && USE_WIN32DLL*/
2628 tv_param_immediate
= 1;
2631 if (argc
> 1 && argv
[1] &&
2632 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
2633 use_gui
= !strcmp(argv
[1], "-gui");
2637 char *base
= strrchr(argv
[0], '/');
2639 base
= strrchr(argv
[0], '\\');
2642 if(strstr(base
, "gmplayer"))
2646 mconfig
= m_config_new();
2647 m_config_register_options(mconfig
,mplayer_opts
);
2648 // TODO : add something to let modules register their options
2649 mp_input_register_options(mconfig
);
2650 parse_cfgfiles(mconfig
);
2653 if ( use_gui
) cfg_read();
2656 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
2657 if(playtree
== NULL
)
2660 playtree
= play_tree_cleanup(playtree
);
2662 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
2664 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2665 play_tree_iter_free(playtree_iter
);
2666 playtree_iter
= NULL
;
2668 filename
= play_tree_iter_get_file(playtree_iter
,1);
2673 #if defined(WIN32) && defined(HAVE_NEW_GUI)
2674 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
2675 if(runningmplayer
&& filename
&& use_gui
){
2676 COPYDATASTRUCT csData
;
2677 char file
[MAX_PATH
];
2678 char *filepart
= filename
;
2679 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
2681 csData
.cbData
= strlen(file
)*2;
2682 csData
.lpData
= file
;
2683 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
2691 for(i
=0; priority_presets_defs
[i
].name
; i
++){
2692 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
2695 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
2696 priority_presets_defs
[i
].name
);
2697 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
2700 #ifndef HAVE_NEW_GUI
2702 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
2707 if(use_gui
&& !vo_init()){
2708 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
2712 if (use_gui
&& playtree_iter
){
2713 char cwd
[PATH_MAX
+2];
2714 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2715 play_tree_iter_free(playtree_iter
);
2718 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
2721 // Prefix relative paths with current working directory
2722 play_tree_add_bpf(playtree
, cwd
);
2724 // Import initital playtree into GUI.
2725 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
2727 #endif /* HAVE_NEW_GUI */
2729 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
2734 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
2739 /* Check codecs.conf. */
2740 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2741 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2742 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2743 if(!parse_codec_cfg(NULL
)){
2744 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
2745 exit_player_with_rc(NULL
, 0);
2747 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
2750 free( mem_ptr
); // release the buffer created by get_path()
2754 if(video_codec_list
){
2756 video_codec
=video_codec_list
[0];
2757 for(i
=0;video_codec_list
[i
];i
++)
2758 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2761 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2762 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
2763 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2765 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2768 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2769 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
2770 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2772 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2775 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2777 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2780 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
2782 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2785 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
2791 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
2793 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2797 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
2798 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
2799 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
2801 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2804 if(list_properties
) {
2805 m_properties_print_help_list(mp_properties
);
2812 if (player_idle_mode
&& use_gui
) {
2813 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
2814 exit_player_with_rc(NULL
, 1);
2817 if(!filename
&& !player_idle_mode
){
2819 // no file/vcd/dvd -> show HELP:
2820 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
2821 exit_player_with_rc(NULL
, 0);
2822 } else gui_no_filename
=1;
2825 // Many users forget to include command line in bugreports...
2826 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
2827 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
2828 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
2829 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2832 //------ load global data first ------
2836 #ifdef HAVE_FREETYPE
2839 #ifdef HAVE_FONTCONFIG
2840 if(!font_fontconfig
)
2844 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
2845 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
2848 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
2849 free(mem_ptr
); // release the buffer created by get_path()
2851 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
2853 #ifdef HAVE_FONTCONFIG
2856 #endif /* USE_OSD */
2862 // seteuid(0); /* Can't hurt to try to get root here */
2863 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
2864 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
2865 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
2867 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
2869 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
2870 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
2871 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
2874 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
2875 /* variable only by the root */
2876 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
2880 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
2884 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2885 // and now ? -- Pontscho
2886 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
2889 #endif /* HAVE_RTC */
2890 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
2891 softsleep
?"software":timer_name
);
2894 if ( !use_gui
) load_termcap(NULL
); // load key-codes
2897 // ========== Init keyboard FIFO (connection to libvo) ============
2899 // Init input system
2900 current_module
= "init_input";
2901 mp_input_init(use_gui
);
2903 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
2905 if(keyb_fifo_get
> 0)
2906 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
2908 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
2912 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
2914 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
2916 else if(!noconsolecontrols
)
2917 #ifndef HAVE_NO_POSIX_SELECT
2918 mp_input_add_key_fd(0,1,NULL
,NULL
);
2920 mp_input_add_key_fd(0,0,NULL
,NULL
);
2923 inited_flags
|=INITED_INPUT
;
2924 current_module
= NULL
;
2928 if(menu_cfg
&& menu_init(menu_cfg
))
2929 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2931 menu_cfg
= get_path("menu.conf");
2932 if(menu_init(menu_cfg
))
2933 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2935 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
2936 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
2938 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
2948 signal(SIGCHLD
,child_sighandler
);
2952 prog_path
= argv
[0];
2954 //========= Catch terminate signals: ================
2955 // terminate requests:
2956 signal(SIGTERM
,exit_sighandler
); // kill
2957 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
2959 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
2961 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
2962 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
2963 #ifdef ENABLE_SIGHANDLER
2965 signal(SIGBUS
,exit_sighandler
); // bus error
2966 signal(SIGSEGV
,exit_sighandler
); // segfault
2967 signal(SIGILL
,exit_sighandler
); // illegal instruction
2968 signal(SIGFPE
,exit_sighandler
); // floating point exc.
2969 signal(SIGABRT
,exit_sighandler
); // abort()
2972 signal(SIGTRAP
,exit_sighandler
);
2979 inited_flags
|=INITED_GUI
;
2980 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
2984 // ******************* Now, let's see the per-file stuff ********************
2988 // init global sub numbers
2989 global_sub_size
= 0;
2990 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
2992 if (filename
) load_per_file_config (mconfig
, filename
);
2994 // We must enable getch2 here to be able to interrupt network connection
2996 if(!noconsolecontrols
&& !slave_mode
){
2997 if(inited_flags
&INITED_GETCH2
)
2998 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
3000 getch2_enable(); // prepare stdin for hotkeys...
3001 inited_flags
|=INITED_GETCH2
;
3002 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3005 // =================== GUI idle loop (STOP state) ===========================
3008 file_format
=DEMUXER_TYPE_UNKNOWN
;
3009 guiGetEvent( guiSetDefaults
,0 );
3010 while ( guiIntfStruct
.Playing
!= 1 )
3015 guiGetEvent( guiReDraw
,NULL
);
3016 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3018 guiGetEvent( guiSetParameters
,NULL
);
3019 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
3021 play_tree_t
* entry
= play_tree_new();
3022 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
3023 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
3024 else playtree
=play_tree_new();
3025 play_tree_set_child( playtree
,entry
);
3028 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3031 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
3033 play_tree_iter_free(playtree_iter
);
3034 playtree_iter
= NULL
;
3036 filename
= play_tree_iter_get_file(playtree_iter
,1);
3041 #endif /* HAVE_NEW_GUI */
3043 while (player_idle_mode
&& !filename
) {
3044 play_tree_t
* entry
= NULL
;
3046 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
3047 if (video_out
&& vo_config_count
) video_out
->check_events();
3051 case MP_CMD_LOADFILE
:
3052 // prepare a tree entry with the new filename
3053 entry
= play_tree_new();
3054 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3055 // The entry is added to the main playtree after the switch().
3057 case MP_CMD_LOADLIST
:
3058 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
3061 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3067 if (entry
) { // user entered a command that gave a valid entry
3068 if (playtree
) // the playtree is always a node with one child. let's clear it
3069 play_tree_free_list(playtree
->child
, 1);
3070 else playtree
=play_tree_new(); // .. or make a brand new playtree
3072 if (!playtree
) continue; // couldn't make playtree! wait for next command
3074 play_tree_set_child(playtree
, entry
);
3076 /* Make iterator start at the top the of tree. */
3077 playtree_iter
= play_tree_iter_new(playtree
, mconfig
);
3078 if (!playtree_iter
) continue;
3080 // find the first real item in the tree
3081 if (play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3083 play_tree_iter_free(playtree_iter
);
3084 playtree_iter
= NULL
;
3085 continue; // wait for next command
3087 filename
= play_tree_iter_get_file(playtree_iter
, 1);
3090 //---------------------------------------------------------------------------
3092 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
3095 if (edl_records
) free_edl(edl_records
);
3096 next_edl_record
= edl_records
= edl_parse_file();
3098 if (edl_output_filename
) {
3099 if (edl_fd
) fclose(edl_fd
);
3100 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3102 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
3103 edl_output_filename
);
3107 //==================== Open VOB-Sub ============================
3109 current_module
="vobsub";
3111 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3113 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
3114 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
3115 /* try to autodetect vobsub from movie filename ::atmos */
3116 char *buf
= malloc((strlen(filename
)-3)),*psub
;
3117 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
3118 strncpy(buf
, filename
, strlen(filename
)-4);
3119 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3120 /* try from ~/.mplayer/sub */
3121 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3124 bname
= strrchr(buf
,'/');
3126 if(!bname
) bname
= strrchr(buf
,'\\');
3130 l
= strlen(psub
) + strlen(bname
) + 1;
3131 psub
= realloc(psub
,l
);
3133 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3139 inited_flags
|=INITED_VOBSUB
;
3140 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
3141 // check if vobsub requested only to display forced subtitles
3142 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
3144 // setup global sub numbering
3145 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
3146 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
3149 //============ Open & Sync STREAM --- fork cache2 ====================
3154 //free_demuxer_stream(d_audio);
3158 //free_demuxer_stream(d_video);
3164 current_module
="open_stream";
3165 stream
=open_stream(filename
,0,&file_format
);
3166 if(!stream
) { // error...
3167 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
3168 goto goto_next_file
;
3170 inited_flags
|=INITED_STREAM
;
3173 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
3176 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
3179 current_module
="handle_playlist";
3180 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
3181 entry
= parse_playtree(stream
,0);
3182 eof
=playtree_add_playlist(entry
);
3183 goto goto_next_file
;
3185 stream
->start_pos
+=seek_to_byte
;
3187 if(stream_dump_type
==5){
3188 unsigned char buf
[4096];
3191 current_module
="dumpstream";
3192 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
3193 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
3194 exit_player(MSGTR_Exit_error
);
3196 stream_reset(stream
);
3197 stream_seek(stream
,stream
->start_pos
);
3198 f
=fopen(stream_dump_name
,"wb");
3200 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3201 exit_player(MSGTR_Exit_error
);
3203 while(!stream
->eof
){
3204 len
=stream_read(stream
,buf
,4096);
3206 if(fwrite(buf
,len
,1,f
) != 1) {
3207 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3208 exit_player(MSGTR_Exit_error
);
3213 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3214 exit_player(MSGTR_Exit_error
);
3216 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3217 exit_player_with_rc(MSGTR_Exit_eof
, 0);
3221 if(stream
->type
==STREAMTYPE_DVD
){
3222 current_module
="dvd lang->id";
3223 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
3224 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
3225 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
3226 // setup global sub numbering
3227 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3228 global_sub_size
+= dvd_number_of_subs(stream
);
3229 current_module
=NULL
;
3233 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3234 #ifdef HAS_DVBIN_SUPPORT
3237 if(stream_cache_size
>0){
3238 current_module
="enable_cache";
3239 if(!stream_enable_cache(stream
,stream_cache_size
*1024,
3240 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3241 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
3242 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
3245 //============ Open DEMUXERS --- DETECT file type =======================
3246 current_module
="demux_open";
3248 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
3250 // HACK to get MOV Reference Files working
3252 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3254 unsigned char* playlist_entry
;
3255 play_tree_t
*list
= NULL
, *entry
= NULL
;
3257 current_module
="handle_demux_playlist";
3258 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
3262 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",playlist_entry
);
3264 bname
=mp_basename(playlist_entry
);
3265 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3268 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
3271 entry
= play_tree_new();
3273 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3275 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
3278 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
3279 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
3280 strcat(temp
, playlist_entry
);
3281 play_tree_add_file(entry
,temp
);
3282 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3287 play_tree_add_file(entry
,playlist_entry
);
3292 play_tree_append_entry(list
,entry
);
3294 free_demuxer(demuxer
);
3299 entry
= play_tree_new();
3300 play_tree_set_child(entry
,list
);
3301 eof
=playtree_add_playlist(entry
);
3302 goto goto_next_file
;
3311 current_module
="handle_playlist";
3312 switch(stream
->type
){
3313 case STREAMTYPE_VCD
:
3314 case STREAMTYPE_DVD
:
3315 case STREAMTYPE_CDDA
:
3316 case STREAMTYPE_VCDBINCUE
:
3317 // don't try to parse raw media as playlist, it's unlikely
3318 goto goto_next_file
;
3320 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
3321 stream_reset(stream
);
3322 stream_seek(stream
,stream
->start_pos
);
3323 entry
= parse_playtree(stream
,0);
3325 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
3327 eof
=playtree_add_playlist(entry
);
3329 goto goto_next_file
;
3331 inited_flags
|=INITED_DEMUXER
;
3333 if (demuxer
->type
==DEMUXER_TYPE_MATROSKA
) {
3334 // setup global sub numbering
3335 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3336 global_sub_size
+= demux_mkv_num_subs(demuxer
);
3338 #ifdef HAVE_OGGVORBIS
3339 if (demuxer
->type
==DEMUXER_TYPE_OGG
) {
3340 // setup global sub numbering
3341 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3342 global_sub_size
+= demux_ogg_num_subs(demuxer
);
3346 current_module
="demux_open2";
3348 //file_format=demuxer->file_format;
3350 d_audio
=demuxer
->audio
;
3351 d_video
=demuxer
->video
;
3352 d_dvdsub
=demuxer
->sub
;
3355 if((stream_dump_type
)&&(stream_dump_type
<4)){
3357 demux_stream_t
*ds
=NULL
;
3358 current_module
="dump";
3359 // select stream to dump
3360 switch(stream_dump_type
){
3361 case 1: ds
=d_audio
;break;
3362 case 2: ds
=d_video
;break;
3363 case 3: ds
=d_dvdsub
;break;
3366 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
3367 exit_player(MSGTR_Exit_error
);
3369 // disable other streams:
3370 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
3371 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
3372 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
3374 f
=fopen(stream_dump_name
,"wb");
3376 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3377 exit_player(MSGTR_Exit_error
);
3380 unsigned char* start
;
3381 int in_size
=ds_get_packet(ds
,&start
);
3382 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3383 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3384 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3387 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3388 exit_player_with_rc(MSGTR_Exit_eof
, 0);
3391 sh_audio
=d_audio
->sh
;
3392 sh_video
=d_video
->sh
;
3396 current_module
="video_read_properties";
3397 if(!video_read_properties(sh_video
)) {
3398 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
3399 sh_video
=d_video
->sh
=NULL
;
3401 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3402 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
3403 sh_video
->fps
,sh_video
->frametime
3406 /* need to set fps here for output encoders to pick it up in their init */
3408 sh_video
->fps
=force_fps
;
3409 sh_video
->frametime
=1.0f
/sh_video
->fps
;
3411 vo_fps
= sh_video
->fps
;
3413 if(!sh_video
->fps
&& !force_fps
){
3414 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
3415 sh_video
=d_video
->sh
=NULL
;
3423 if(!sh_video
&& !sh_audio
){
3424 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
3425 #ifdef HAS_DVBIN_SUPPORT
3426 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
3428 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
3432 int v
= last_dvb_step
;
3434 dir
= DVB_CHANNEL_HIGHER
;
3436 dir
= DVB_CHANNEL_LOWER
;
3438 if(dvb_step_channel(priv
, dir
))
3439 eof
= dvbin_reopen
= 1;
3443 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3446 /* display clip info */
3447 demux_info_print(demuxer
);
3449 //================== Read SUBTITLES (DVD & TEXT) ==========================
3450 if(vo_spudec
==NULL
&& sh_video
&&
3451 (stream
->type
==STREAMTYPE_DVD
|| demuxer
->type
==DEMUXER_TYPE_MATROSKA
||
3452 d_dvdsub
->id
>= 0)){
3455 unsigned int palette
[16], width
, height
;
3456 current_module
="spudec_init_vobsub";
3457 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
3458 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
3462 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
3463 current_module
="spudec_init_dvdread";
3464 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
3465 sh_video
->disp_w
, sh_video
->disp_h
);
3469 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
3470 (d_dvdsub
->sh
!= NULL
) && (((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
3471 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)d_dvdsub
->sh
;
3472 current_module
= "spudec_init_matroska";
3474 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
3475 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
3476 mkv_sh_sub
->height
);
3477 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
3480 if (vo_spudec
==NULL
) {
3481 current_module
="spudec_init_normal";
3482 vo_spudec
=spudec_new_scaled(NULL
, sh_video
->disp_w
, sh_video
->disp_h
);
3483 spudec_set_font_factor(vo_spudec
,font_factor
);
3486 if (vo_spudec
!=NULL
)
3487 inited_flags
|=INITED_SPUDEC
;
3491 // Apply current settings for forced subs
3492 if (vo_spudec
!=NULL
)
3493 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3497 // after reading video params we should load subtitles because
3498 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3500 current_module
="read_subtitles_file";
3502 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3503 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
3505 if(sub_auto
) { // auto load sub file ...
3506 char *psub
= get_path( "sub/" );
3507 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
3509 free(psub
); // release the buffer created by get_path() above
3511 add_subtitles (tmp
[i
], sh_video
->fps
, 0);
3516 if (set_of_sub_size
> 0) {
3517 // setup global sub numbering
3518 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
3519 global_sub_size
+= set_of_sub_size
;
3522 #endif /* USE_SUB */
3524 if (global_sub_size
) {
3525 // find the best sub to use
3526 if (vobsub_id
>= 0) {
3527 // if user asks for a vobsub id, use that first.
3528 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
3529 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3530 // if user asks for a dvd sub id, use that next.
3531 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
3532 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
3533 // if there are text subs to use, use those. (autosubs come last here)
3534 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
3536 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
3537 // if nothing else works, get subs from the demuxer.
3538 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
3541 // nothing worth doing automatically.
3542 global_sub_pos
= -1;
3544 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3546 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
);
3548 switch (stream_dump_type
) {
3549 case 3: list_sub_file(subdata
); break;
3550 case 4: dump_mpsub(subdata
, sh_video
->fps
); break;
3551 case 6: dump_srt(subdata
, sh_video
->fps
); break;
3552 case 7: dump_microdvd(subdata
, sh_video
->fps
); break;
3553 case 8: dump_jacosub(subdata
, sh_video
->fps
); break;
3554 case 9: dump_sami(subdata
, sh_video
->fps
); break;
3558 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
3559 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", demuxer
->desc
->name
);
3561 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3562 if (sh_video
->format
>= 0x20202020)
3563 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video
->format
);
3565 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
3566 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
3567 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
3568 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
3569 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
3570 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
3573 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3574 if (sh_audio
->format
>= 0x20202020)
3575 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio
->format
);
3577 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
3578 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
3579 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
3580 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
3582 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
3584 if(!sh_video
) goto main
; // audio-only
3586 //================== Init VIDEO (codec & libvo) ==========================
3587 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
3588 current_module
="preinit_libvo";
3591 //if((video_out->preinit(vo_subdevice))!=0){
3592 if(!(video_out
=init_best_video_out(video_driver_list
))){
3593 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
3594 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3596 sh_video
->video_out
=video_out
;
3597 inited_flags
|=INITED_VO
;
3600 vf_vo_data
.vo
= video_out
;
3601 current_module
="init_video_filters";
3603 char* vf_arg
[] = { "_oldargs_", (char*)&vf_vo_data
, NULL
};
3604 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
3608 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
3609 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
3611 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
3616 sh_video
->vfilter
=(void*)vf_menu
;
3623 for (i
= 0; vf_settings
[i
].name
; ++i
)
3624 if (strcmp(vf_settings
[i
].name
, "ass") == 0) {
3629 extern vf_info_t vf_info_ass
;
3630 vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
3631 char* vf_arg
[] = {"auto", "1", NULL
};
3632 vf_instance_t
* vf_ass
= vf_open_plugin(libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
3634 sh_video
->vfilter
=(void*)vf_ass
;
3636 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
3640 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
3644 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_EOSD
, 0);
3647 current_module
="init_video_codec";
3649 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3650 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
3651 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3653 if(!sh_video
->inited
){
3654 if(!fixed_vo
) uninit_player(INITED_VO
);
3655 if(!sh_audio
) goto goto_next_file
;
3656 sh_video
= d_video
->sh
= NULL
;
3657 goto main
; // exit_player(MSGTR_Exit_error);
3660 inited_flags
|=INITED_VCODEC
;
3662 if (sh_video
->codec
)
3663 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
3666 // Auto quality option enabled
3667 output_quality
=get_video_quality_max(sh_video
);
3668 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
3669 else output_quality
=auto_quality
;
3670 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
3671 set_video_quality(sh_video
,output_quality
);
3674 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3676 current_module
="init_vo";
3678 if(vo_flags
& 0x08 && vo_spudec
)
3679 spudec_set_hw_spu(vo_spudec
,video_out
);
3681 #ifdef HAVE_FREETYPE
3682 force_load_font
= 1;
3685 //================== MAIN: ==========================
3687 current_module
="main";
3690 char* msg
= m_properties_expand_string(mp_properties
,playing_msg
);
3691 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3696 // Disable the term OSD in verbose mode
3697 if(verbose
) term_osd
= 0;
3703 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
3704 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
3705 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
3706 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
3707 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
3712 //int frame_corr_num=0; //
3713 //float v_frame=0; // Video
3714 float time_frame
=0; // Timer
3715 //float num_frames=0; // number of frames played
3716 double last_pts
= MP_NOPTS_VALUE
;
3718 int drop_frame
=0; // current dropping status
3719 int dropped_frames
=0; // how many frames dropped since last non-dropped frame
3720 int too_slow_frame_cnt
=0;
3721 int too_fast_frame_cnt
=0;
3722 // for auto-quality:
3723 double vdecode_time
;
3724 unsigned int lastframeout_ts
=0;
3725 /*float time_frame_corr_avg=0;*/ /* unused */
3727 float next_frame_time
=0;
3728 int frame_time_remaining
=0; // flag
3732 // Make sure old OSD does not stay around,
3733 // e.g. with -fixed-vo and same-resolution files
3737 //================ SETUP AUDIO ==========================
3740 reinit_audio_chain();
3741 if (sh_audio
&& sh_audio
->codec
)
3742 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
3745 current_module
="av_init";
3750 audio_delay
+= sh_video
->stream_delay
;
3754 audio_delay
-= sh_audio
->stream_delay
;
3755 sh_audio
->delay
=-audio_delay
;
3759 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
3760 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",d_audio
->packs
);
3761 ds_free_packs(d_audio
); // free buffered chunks
3762 //d_audio->id=-2; // do not read audio chunks
3763 //uninit_player(INITED_AO); // close device
3766 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
3767 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",d_video
->packs
);
3768 ds_free_packs(d_video
);
3770 //if(!fixed_vo) uninit_player(INITED_VO);
3773 if (!sh_video
&& !sh_audio
)
3774 goto goto_next_file
;
3776 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3777 if(force_fps
&& sh_video
){
3778 vo_fps
= sh_video
->fps
=force_fps
;
3779 sh_video
->frametime
=1.0f
/sh_video
->fps
;
3780 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
3783 //==================== START PLAYING =======================
3785 if(loop_times
>1) loop_times
--; else
3786 if(loop_times
==1) loop_times
= -1;
3788 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
3790 total_time_usage_start
=GetTimer();
3791 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3792 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3793 play_n_frames
=play_n_frames_mf
;
3795 if(play_n_frames
==0){
3796 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
3800 float aq_sleep_time
=0;
3801 if(!sh_audio
&& d_audio
->sh
) {
3802 sh_audio
= d_audio
->sh
;
3803 sh_audio
->ds
= d_audio
;
3804 reinit_audio_chain();
3807 /*========================== PLAY AUDIO ============================*/
3816 current_module
="play_audio";
3818 ao_data
.pts
=((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3819 playsize
=audio_out
->get_space();
3821 // handle audio-only case:
3822 if(playsize
< ao_data
.outburst
&&
3823 !sh_video
) { // buffer is full, do not block here!!!
3824 usec_sleep(10000); // Wait a tick before retry
3828 if(playsize
>MAX_OUTBURST
) playsize
=MAX_OUTBURST
; // we shouldn't exceed it!
3830 // Fill buffer if needed:
3831 current_module
="decode_audio"; // Enter AUDIO decoder module
3833 while (sh_audio
->a_out_buffer_len
< playsize
) {
3834 int ret
=decode_audio(sh_audio
,&sh_audio
->a_out_buffer
[sh_audio
->a_out_buffer_len
],
3835 playsize
-sh_audio
->a_out_buffer_len
,sh_audio
->a_out_buffer_size
-sh_audio
->a_out_buffer_len
);
3836 if(ret
<=0) { // EOF?
3839 if (!sh_video
&& sh_audio
->a_out_buffer_len
== 0)
3840 eof
= PT_NEXT_ENTRY
;
3844 sh_audio
->a_out_buffer_len
+=ret
;
3847 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
3848 if (playsize
> sh_audio
->a_out_buffer_len
) {
3849 playsize
= sh_audio
->a_out_buffer_len
;
3851 playflags
|= AOPLAY_FINAL_CHUNK
;
3857 current_module
="play_audio";
3858 playsize
= audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
3861 sh_audio
->a_out_buffer_len
-=playsize
;
3862 memmove(sh_audio
->a_out_buffer
,&sh_audio
->a_out_buffer
[playsize
],sh_audio
->a_out_buffer_len
);
3863 sh_audio
->delay
+=playback_speed
*playsize
/(double)ao_data
.bps
;
3865 else if (audio_eof
&& audio_out
->get_delay() < .04) {
3866 // Sanity check to avoid hanging in case current ao doesn't output
3867 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3868 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
3869 sh_audio
->a_out_buffer_len
= 0;
3872 } // while(sh_audio)
3875 // handle audio-only case:
3877 double a_pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
3878 print_status(a_pos
, 0, 0);
3882 /*========================== PLAY VIDEO ============================*/
3884 float frame_time
=next_frame_time
;
3886 vo_pts
=sh_video
->timer
*90000.0;
3887 vo_fps
=sh_video
->fps
;
3889 if(!frame_time_remaining
){
3890 //-------------------- Decode a frame: -----------------------
3891 blit_frame
= 0; // Don't blit if we hit EOF
3892 vdecode_time
=video_time_usage
;
3893 if (!correct_pts
) while(1)
3894 { unsigned char* start
=NULL
;
3897 current_module
="video_read_frame";
3898 in_size
=video_read_frame(sh_video
,&next_frame_time
,&start
,force_fps
);
3899 if(in_size
<0){ eof
=1; break; }
3900 if(in_size
>max_framesize
) max_framesize
=in_size
; // stats
3901 sh_video
->timer
+=frame_time
;
3902 if(sh_audio
) sh_audio
->delay
-=frame_time
;
3903 time_frame
+=frame_time
; // for nosound
3904 // video_read_frame can change fps (e.g. for ASF video)
3905 vo_fps
= sh_video
->fps
;
3906 // check for frame-drop:
3907 current_module
="check_framedrop";
3908 if(sh_audio
&& !d_audio
->eof
){
3909 float delay
=playback_speed
*audio_out
->get_delay();
3910 float d
=delay
-sh_audio
->delay
;
3911 // we should avoid dropping too many frames in sequence unless we
3912 // are too late. and we allow 100ms A-V delay here:
3913 if(d
<-dropped_frames
*frame_time
-0.100 && osd_function
!= OSD_PAUSE
){
3914 drop_frame
=frame_dropping
;
3918 drop_frame
=dropped_frames
=0;
3923 current_module
="decode_video";
3924 // printf("Decode! %p %d \n",start,in_size);
3925 blit_frame
=decode_video(sh_video
,start
,in_size
,drop_frame
, sh_video
->pts
);
3929 if (!generate_video_frame(sh_video
, d_video
)) {
3933 sh_video
->pts
= vf_vo_data
.pts
;
3934 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
3935 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
3936 sh_video
->pts
= last_pts
;
3938 if (last_pts
== MP_NOPTS_VALUE
)
3939 last_pts
= sh_video
->pts
;
3940 else if (last_pts
>= sh_video
->pts
) {
3941 last_pts
= sh_video
->pts
;
3942 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "pts value <= previous");
3944 frame_time
= sh_video
->pts
- last_pts
;
3945 last_pts
= sh_video
->pts
;
3946 sh_video
->timer
+= frame_time
;
3947 time_frame
+= frame_time
; // for nosound
3949 sh_audio
->delay
-= frame_time
;
3954 vdecode_time
=video_time_usage
-vdecode_time
;
3955 //------------------------ frame decoded. --------------------
3957 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3959 if(sh_video
->vf_inited
<0){
3960 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_NotInitializeVOPorVO
);
3961 eof
=1; goto goto_next_file
;
3966 // ==========================================================================
3968 // current_module="draw_osd";
3969 // if(vo_config_count) video_out->draw_osd();
3972 if(use_gui
) guiEventHandling();
3975 current_module
="calc_sleep_time";
3978 { // debug frame dropping code
3979 float delay
=audio_out
->get_delay();
3980 mp_msg(MSGT_AVSYNC
,MSGL_V
,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
3981 sh_video
->timer
,sh_audio
->timer
-delay
,
3982 sh_video
->timer
-(sh_audio
->timer
-delay
),
3987 if(drop_frame
&& !frame_time_remaining
&& !autosync
){
3989 * Note: time_frame should not be forced to 0 in autosync mode.
3990 * It is used as a cumulative counter to predict and correct the
3991 * delay measurements from the audio driver. time_frame is already
3992 * < 0, so the "time to sleep" code does not actually sleep. Also,
3993 * blit_frame is already 0 because drop_frame was true when
3994 * decode_video was called (which causes it to set blit_frame to 0.)
3995 * When autosync==0, the default behavior is still completely unchanged.
3998 time_frame
=0; // don't sleep!
3999 blit_frame
=0; // don't display!
4003 // It's time to sleep...
4005 frame_time_remaining
=0;
4006 time_frame
-=GetRelativeTime(); // reset timer
4008 if(sh_audio
&& !d_audio
->eof
){
4009 float delay
=playback_speed
*audio_out
->get_delay();
4010 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"delay=%f\n",delay
);
4014 * Adjust this raw delay value by calculating the expected
4015 * delay for this frame and generating a new value which is
4016 * weighted between the two. The higher autosync is, the
4017 * closer to the delay value gets to that which "-nosound"
4018 * would have used, and the longer it will take for A/V
4019 * sync to settle at the right value (but it eventually will.)
4020 * This settling time is very short for values below 100.
4022 float predicted
= sh_audio
->delay
+time_frame
;
4023 float difference
= delay
- predicted
;
4024 delay
= predicted
+ difference
/ (float)autosync
;
4027 time_frame
=delay
-sh_audio
->delay
;
4029 // delay = amount of audio buffered in soundcard/driver
4030 if(delay
>0.25) delay
=0.25; else
4031 if(delay
<0.10) delay
=0.10;
4032 if(time_frame
>delay
*0.6){
4033 // sleep time too big - may cause audio drops (buffer underrun)
4034 frame_time_remaining
=1;
4035 time_frame
=delay
*0.5;
4041 if( (time_frame
<-3*frame_time
|| time_frame
>3*frame_time
) || benchmark
)
4046 // if(mp_msg_test(MSGT_CPLAYER,MSGL_DBG2)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
4048 aq_sleep_time
+=time_frame
;
4052 //============================== SLEEP: ===================================
4054 time_frame
/=playback_speed
;
4056 // flag 256 means: libvo driver does its timing (dvb card)
4057 if(time_frame
>0.001 && !(vo_flags
&256)){
4061 // -------- RTC -----------
4062 current_module
="sleep_rtc";
4063 while (time_frame
> 0.000) {
4064 unsigned long rtc_ts
;
4065 if (read (rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
4066 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
4067 time_frame
-=GetRelativeTime();
4073 current_module
="sleep_darwin";
4074 while(time_frame
>0.005) {
4075 usec_sleep(1000000*time_frame
);
4076 time_frame
-=GetRelativeTime();
4081 // -------- TIMER + SOFTSLEEP -----------
4082 // assume kernel HZ=100 for softsleep, works with larger HZ but with
4083 // unnecessarily high CPU usage
4084 float margin
= softsleep
? 0.011 : 0;
4085 current_module
="sleep_timer";
4086 while (time_frame
> margin
) {
4087 usec_sleep(1000000 * (time_frame
- margin
));
4088 time_frame
-= GetRelativeTime();
4091 current_module
="sleep_soft";
4092 if(time_frame
<0) mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
4093 while(time_frame
>0) time_frame
-=GetRelativeTime(); // burn the CPU
4096 #endif /* SYS_DARWIN */
4099 //if(!frame_time_remaining){ // should we display the frame now?
4101 //====================== FLIP PAGE (VIDEO BLT): =========================
4103 current_module
="vo_check_events";
4104 if(vo_config_count
) video_out
->check_events();
4106 current_module
="flip_page";
4107 if (!frame_time_remaining
) {
4109 unsigned int t2
=GetTimer();
4112 #define FRAME_LAG_WARN 0.2
4113 j
= ((float)t2
- lastframeout_ts
) / 1000000;
4114 lastframeout_ts
= GetTimer();
4115 if (j
< frame_time
+ frame_time
* -FRAME_LAG_WARN
)
4116 too_fast_frame_cnt
++;
4117 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
4118 else if (j
> frame_time
+ frame_time
* FRAME_LAG_WARN
)
4119 too_slow_frame_cnt
++;
4120 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
4122 if(vo_config_count
) video_out
->flip_page();
4123 if (play_n_frames
>= 0) {
4125 if (play_n_frames
<= 0) eof
= PT_NEXT_ENTRY
;
4128 // usec_sleep(50000); // test only!
4131 vout_time_usage
+=tt
;
4134 Well, no blitting is needed, but some devices (such as yuv4mpeg)
4135 must output frames otherwise A/V desync will occur. -- Alvieboy
4137 if (vo_config_count
)
4138 video_out
->control(VOCTRL_DUPLICATE_FRAME
, NULL
);
4141 //====================== A-V TIMESTAMP CORRECTION: =========================
4143 current_module
="av_sync";
4146 double a_pts
, v_pts
;
4150 * If autosync is enabled, the value for delay must be calculated
4151 * a bit differently. It is set only to the difference between
4152 * the audio and video timers. Any attempt to include the real
4153 * or corrected delay causes the pts_correction code below to
4154 * try to correct for the changes in delay which autosync is
4155 * trying to measure. This keeps the two from competing, but still
4156 * allows the code to correct for PTS drift *only*. (Using a delay
4157 * value here, even a "corrected" one, would be incompatible with
4160 a_pts
= written_audio_pts(sh_audio
, d_audio
) - sh_audio
->delay
;
4162 a_pts
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4164 v_pts
=sh_video
? sh_video
->pts
: d_video
->pts
;
4167 static int drop_message
=0;
4168 double AV_delay
= a_pts
- audio_delay
- v_pts
;
4170 if(AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
4172 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
4177 /* Do not correct target time for the next frame if this frame
4178 * was late not because of wrong target time but because the
4179 * target time could not be met */
4180 x
= (AV_delay
+ time_frame
* playback_speed
) * 0.1f
;
4181 if(x
<-max_pts_correction
) x
=-max_pts_correction
; else
4182 if(x
> max_pts_correction
) x
= max_pts_correction
;
4183 if(default_max_pts_correction
>=0)
4184 max_pts_correction
=default_max_pts_correction
;
4186 max_pts_correction
=sh_video
->frametime
*0.10; // +-10% of time
4187 if(!frame_time_remaining
){ sh_audio
->delay
+=x
; c_total
+=x
;} // correction
4189 print_status(a_pts
- audio_delay
, AV_delay
, c_total
);
4196 print_status(0, 0, 0);
4200 //============================ Auto QUALITY ============================
4202 /*Output quality adjustments:*/
4204 current_module
="autoq";
4205 // float total=0.000001f * (GetTimer()-aq_total_time);
4206 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4207 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4210 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4211 if(output_quality
>1 && aq_sleep_time
<0)
4214 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4216 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4217 set_video_quality(sh_video
,output_quality
);
4220 } // end if(sh_video)
4222 //============================ Handle PAUSE ===============================
4224 current_module
="pause";
4228 // 36000000 means max timed visibility is 1 hour into the future, if
4229 // the difference is greater assume it's wrapped around from below 0
4230 if (osd_visible
- GetTimerMS() > 36000000) {
4232 vo_osd_progbar_type
=-1; // disable
4233 vo_osd_changed(OSDTYPE_PROGBAR
);
4234 if (osd_function
!= OSD_PAUSE
)
4235 osd_function
= OSD_PLAY
;
4240 if(osd_function
==OSD_PAUSE
){
4243 // Small hack to display the pause message on the OSD line.
4244 // The pause string is: "\n == PAUSE == \r" so we need to
4245 // take the first and the last char out
4247 char msg
[128] = MSGTR_Paused
;
4248 int mlen
= strlen(msg
);
4250 set_osd_msg(OSD_MSG_PAUSE
,1,0,"%s",msg
+1);
4253 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
4254 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
4258 if(use_gui
) guiGetEvent( guiCEvent
,(char *)guiSetPause
);
4260 if (video_out
&& sh_video
&& vo_config_count
)
4261 video_out
->control(VOCTRL_PAUSE
, NULL
);
4263 if (audio_out
&& sh_audio
)
4264 audio_out
->pause(); // pause audio, keep data if possible
4266 while( (cmd
= mp_input_get_cmd(20,1,1)) == NULL
) {
4267 if(sh_video
&& video_out
&& vo_config_count
) video_out
->check_events();
4271 guiGetEvent( guiReDraw
,NULL
);
4272 if(guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
)) break;
4277 vf_menu_pause_update(vf_menu
);
4281 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
4282 cmd
= mp_input_get_cmd(0,1,0);
4285 osd_function
=OSD_PLAY
;
4286 if (audio_out
&& sh_audio
)
4287 audio_out
->resume(); // resume audio
4288 if (video_out
&& sh_video
&& vo_config_count
)
4289 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
4290 (void)GetRelativeTime(); // keep TF around FT in next cycle
4294 if ( guiIntfStruct
.Playing
== guiSetStop
) goto goto_next_file
;
4295 guiGetEvent( guiCEvent
,(char *)guiSetPlay
);
4303 osd_function
=OSD_FFW
;
4304 rel_seek_secs
+=step_sec
;
4307 //================= EDL =========================================
4309 if( next_edl_record
) { // Are we (still?) doing EDL?
4311 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
4312 free_edl(edl_records
);
4313 next_edl_record
= NULL
;
4316 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
4317 if( next_edl_record
->action
== EDL_SKIP
) {
4318 osd_function
= OSD_FFW
;
4320 rel_seek_secs
= next_edl_record
->length_sec
;
4321 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record
->start_sec
, next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
4323 } else if( next_edl_record
->action
== EDL_MUTE
) {
4324 edl_muted
= !edl_muted
;
4325 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4326 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
4328 next_edl_record
=next_edl_record
->next
;
4333 //================= Keyboard events, SEEKing ====================
4335 current_module
="key_events";
4340 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
4341 if(!set_property_command(cmd
))
4343 case MP_CMD_SEEK
: {
4347 osd_show_percentage
= sh_video
->fps
;
4348 v
= cmd
->args
[0].v
.f
;
4349 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
4350 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
4353 osd_function
= (v
> sh_video
->pts
) ? OSD_FFW
: OSD_REW
;
4356 else if(abs
) { /* Absolute seek by percentage */
4359 osd_function
= OSD_FFW
; // Direction isn't set correctly
4360 rel_seek_secs
= v
/100.0;
4364 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
4368 case MP_CMD_SET_PROPERTY
: {
4369 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4370 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unkown property: '%s'\n",cmd
->args
[0].v
.s
);
4371 else if(m_property_parse(prop
,cmd
->args
[1].v
.s
) <= 0)
4372 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to set property '%s' to '%s'.\n",
4373 cmd
->args
[0].v
.s
,cmd
->args
[1].v
.s
);
4376 case MP_CMD_GET_PROPERTY
: {
4379 prop
= mp_property_find(cmd
->args
[0].v
.s
);
4381 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unkown property: '%s'\n",cmd
->args
[0].v
.s
);
4384 /* Use m_option_print directly to get easily parseable values. */
4385 val
= calloc(1,prop
->type
->size
);
4386 if(m_property_do(prop
,M_PROPERTY_GET
,val
) <= 0) {
4387 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to get value of property '%s'.\n",
4391 tmp
= m_option_print(prop
,val
);
4392 if(!tmp
|| tmp
== (char*)-1) {
4393 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to print value of property '%s'.\n",
4397 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_%s=%s\n",cmd
->args
[0].v
.s
,tmp
);
4400 case MP_CMD_EDL_MARK
:
4402 float v
= sh_video
? sh_video
->pts
:
4403 playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4405 if(begin_skip
== MP_NOPTS_VALUE
)
4408 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutStartSkip
);
4412 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_EdloutBadStop
);
4414 fprintf(edl_fd
, "%f %f %d\n", begin_skip
, v
, 0);
4415 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutEndSkip
);
4417 begin_skip
= MP_NOPTS_VALUE
;
4421 case MP_CMD_SWITCH_RATIO
: {
4422 if (cmd
->nargs
== 0 || cmd
->args
[0].v
.f
== -1)
4423 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
4425 movie_aspect
= cmd
->args
[0].v
.f
;
4426 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
4428 case MP_CMD_SPEED_INCR
: {
4429 float v
= cmd
->args
[0].v
.f
;
4430 playback_speed
+= v
;
4431 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4432 build_afilter_chain(sh_audio
, &ao_data
);
4434 case MP_CMD_SPEED_MULT
: {
4435 float v
= cmd
->args
[0].v
.f
;
4436 playback_speed
*= v
;
4437 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4438 build_afilter_chain(sh_audio
, &ao_data
);
4440 case MP_CMD_SPEED_SET
: {
4441 float v
= cmd
->args
[0].v
.f
;
4443 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4444 build_afilter_chain(sh_audio
, &ao_data
);
4446 case MP_CMD_FRAME_STEP
:
4447 case MP_CMD_PAUSE
: {
4451 case MP_CMD_QUIT
: {
4452 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
4454 case MP_CMD_GRAB_FRAMES
: {
4457 case MP_CMD_PLAY_TREE_STEP
: {
4458 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
4459 int force
= cmd
->args
[1].v
.i
;
4468 for (i
=0;i
<-1*n
;i
++)
4473 if(!force
&& playtree_iter
) {
4474 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4476 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4477 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4478 play_tree_iter_free(i
);
4480 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4486 case MP_CMD_PLAY_TREE_UP_STEP
: {
4487 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
4488 int force
= cmd
->args
[1].v
.i
;
4490 if(!force
&& playtree_iter
) {
4491 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4492 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4493 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4494 play_tree_iter_free(i
);
4496 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4499 case MP_CMD_PLAY_ALT_SRC_STEP
: {
4500 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
4501 int v
= cmd
->args
[0].v
.i
;
4502 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
4504 else if(v
< 0 && playtree_iter
->file
> 1)
4509 case MP_CMD_SUB_STEP
: {
4512 int movement
= cmd
->args
[0].v
.i
;
4513 step_sub(subdata
, sh_video
->pts
, movement
);
4516 sub_delay
+= ass_step_sub(ass_track
, (sh_video
->pts
+ sub_delay
) * 1000 + .5, movement
) / 1000.;
4518 set_osd_msg(OSD_MSG_SUB_DELAY
,1,osd_duration
,
4519 MSGTR_OSDSubDelay
, ROUND(sub_delay
*1000));
4523 case MP_CMD_SUB_LOG
: {
4529 int v
= cmd
->args
[0].v
.i
;
4530 int max
= use_term_osd
? MAX_TERM_OSD_LEVEL
: MAX_OSD_LEVEL
;
4531 if(osd_level
> max
) osd_level
= max
;
4533 osd_level
=(osd_level
+1)%(max
+1);
4535 osd_level
= v
> max
? max
: v
;
4536 /* Show OSD state when disabled, but not when an explicit
4537 argument is given to the OSD command, i.e. in slave mode. */
4538 if (v
== -1 && osd_level
<= 1)
4539 set_osd_msg(OSD_MSG_OSD_STATUS
,0,osd_duration
,
4540 MSGTR_OSDosd
, osd_level
? MSGTR_OSDenabled
: MSGTR_OSDdisabled
);
4542 rm_osd_msg(OSD_MSG_OSD_STATUS
);
4544 case MP_CMD_OSD_SHOW_TEXT
: {
4545 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4546 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4547 "%-.63s",cmd
->args
[0].v
.s
);
4549 case MP_CMD_OSD_SHOW_PROPERTY_TEXT
: {
4550 char* txt
= m_properties_expand_string(mp_properties
,cmd
->args
[0].v
.s
);
4551 /* if no argument supplied take default osd_duration, else <arg> ms. */
4553 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4554 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4559 case MP_CMD_LOADFILE
: {
4560 play_tree_t
* e
= play_tree_new();
4561 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
4563 if (cmd
->args
[1].v
.i
) // append
4564 play_tree_append_entry(playtree
, e
);
4566 // Go back to the starting point.
4567 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
4569 play_tree_free_list(playtree
->child
,1);
4570 play_tree_set_child(playtree
,e
);
4571 play_tree_iter_step(playtree_iter
,0,0);
4576 case MP_CMD_LOADLIST
: {
4577 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
4579 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
4581 if (cmd
->args
[1].v
.i
) // append
4582 play_tree_append_entry(playtree
, e
);
4584 // Go back to the starting point.
4585 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
4587 play_tree_free_list(playtree
->child
,1);
4588 play_tree_set_child(playtree
,e
);
4589 play_tree_iter_step(playtree_iter
,0,0);
4596 case MP_CMD_TV_SET_FREQ
: {
4597 if (file_format
== DEMUXER_TYPE_TV
)
4598 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
4600 case MP_CMD_TV_SET_NORM
: {
4601 if (file_format
== DEMUXER_TYPE_TV
)
4602 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
4604 case MP_CMD_TV_STEP_CHANNEL
: {
4605 if (file_format
== DEMUXER_TYPE_TV
) {
4606 int v
= cmd
->args
[0].v
.i
;
4608 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
4610 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
4612 if (tv_channel_list
) {
4613 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4614 MSGTR_OSDChannel
, tv_channel_current
->name
);
4615 //vo_osd_changed(OSDTYPE_SUBTITLE);
4619 #ifdef HAS_DVBIN_SUPPORT
4620 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4622 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4626 int v
= cmd
->args
[0].v
.i
;
4630 dir
= DVB_CHANNEL_HIGHER
;
4632 dir
= DVB_CHANNEL_LOWER
;
4635 if(dvb_step_channel(priv
, dir
))
4636 eof
= dvbin_reopen
= 1;
4639 #endif /* HAS_DVBIN_SUPPORT */
4641 case MP_CMD_TV_SET_CHANNEL
: {
4642 if (file_format
== DEMUXER_TYPE_TV
) {
4643 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
4644 if (tv_channel_list
) {
4645 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4646 MSGTR_OSDChannel
, tv_channel_current
->name
);
4647 //vo_osd_changed(OSDTYPE_SUBTITLE);
4651 #ifdef HAS_DVBIN_SUPPORT
4652 case MP_CMD_DVB_SET_CHANNEL
:
4654 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4656 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4659 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
4664 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
4665 eof
= dvbin_reopen
= 1;
4670 #endif /* HAS_DVBIN_SUPPORT */
4671 case MP_CMD_TV_LAST_CHANNEL
: {
4672 if (file_format
== DEMUXER_TYPE_TV
) {
4673 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
4674 if (tv_channel_list
) {
4675 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4676 MSGTR_OSDChannel
, tv_channel_current
->name
);
4677 //vo_osd_changed(OSDTYPE_SUBTITLE);
4681 case MP_CMD_TV_STEP_NORM
: {
4682 if (file_format
== DEMUXER_TYPE_TV
)
4683 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
4685 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
4686 if (file_format
== DEMUXER_TYPE_TV
)
4687 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
4690 case MP_CMD_SUB_LOAD
:
4694 int n
= set_of_sub_size
;
4695 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
4696 if (n
!= set_of_sub_size
) {
4697 if (global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
4698 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
;
4704 case MP_CMD_SUB_REMOVE
:
4708 int v
= cmd
->args
[0].v
.i
;
4711 for (v
= 0; v
< set_of_sub_size
; ++v
) {
4712 subd
= set_of_subtitles
[v
];
4713 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
4715 set_of_subtitles
[v
] = NULL
;
4717 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
4718 global_sub_size
-= set_of_sub_size
;
4719 set_of_sub_size
= 0;
4720 if (set_of_sub_pos
>= 0) {
4721 global_sub_pos
= -2;
4722 vo_sub_last
= vo_sub
= NULL
;
4723 vo_osd_changed(OSDTYPE_SUBTITLE
);
4724 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
4725 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
4728 else if (v
< set_of_sub_size
) {
4729 subd
= set_of_subtitles
[v
];
4730 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
4732 if (set_of_sub_pos
== v
) {
4733 global_sub_pos
= -2;
4734 vo_sub_last
= vo_sub
= NULL
;
4735 vo_osd_changed(OSDTYPE_SUBTITLE
);
4736 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
4737 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
4739 else if (set_of_sub_pos
> v
) {
4743 while (++v
< set_of_sub_size
)
4744 set_of_subtitles
[v
- 1] = set_of_subtitles
[v
];
4747 if (set_of_sub_size
<= 0)
4748 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
4749 set_of_subtitles
[set_of_sub_size
] = NULL
;
4752 #endif /* USE_SUB */
4754 case MP_CMD_GET_SUB_VISIBILITY
:
4758 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_SUB_VISIBILITY=%d\n", sub_visibility
);
4762 case MP_CMD_SCREENSHOT
:
4763 if(vo_config_count
){
4764 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"sending VFCTRL_SCREENSHOT!\n");
4765 if(CONTROL_OK
!=((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_SCREENSHOT
, 0))
4766 video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
4769 case MP_CMD_VF_CHANGE_RECTANGLE
:
4770 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
4773 case MP_CMD_GET_TIME_LENGTH
: {
4774 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
4777 case MP_CMD_GET_VO_FULLSCREEN
: {
4778 if(video_out
&& vo_config_count
)
4779 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VO_FULLSCREEN=%d\n", vo_fs
);
4782 case MP_CMD_GET_PERCENT_POS
: {
4783 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer
));
4785 case MP_CMD_GET_TIME_POS
: {
4788 pos
= sh_video
->pts
;
4790 if (sh_audio
&& audio_out
)
4791 pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4792 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
4794 case MP_CMD_SWITCH_AUDIO
: {
4795 int current_id
= demuxer
->audio
->id
;
4796 int v
= demuxer_switch_audio(demuxer
, cmd
->args
[0].v
.i
);
4797 if(v
> -1 && v
< MAX_A_STREAMS
&& v
!= current_id
) {
4799 uninit_player(INITED_AO
| INITED_ACODEC
);
4800 sh2
= demuxer
->a_streams
[v
];
4802 sh2
->ds
= demuxer
->audio
;
4804 reinit_audio_chain();
4807 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", v
);
4812 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
4817 case MP_CMD_KEYDOWN_EVENTS
: {
4818 mplayer_put_key(cmd
->args
[0].v
.i
);
4820 case MP_CMD_SEEK_CHAPTER
: {
4821 int seek
= cmd
->args
[0].v
.i
;
4822 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
4828 chap
= demuxer_seek_chapter(demuxer
, seek
, abs
, &next_pts
);
4830 if(next_pts
> -1.0) {
4832 rel_seek_secs
= next_pts
;
4834 if(demuxer
->num_chapters
> chap
)
4835 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
,
4836 chap
, demuxer
->chapters
[chap
].name
);
4839 rel_seek_secs
= 1000000000.;
4841 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
, 0, MSGTR_Unknown
);
4847 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
4850 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
4853 switch (cmd
->pausing
) {
4854 case 1: // "pausing"
4855 osd_function
= OSD_PAUSE
;
4857 case 3: // "pausing_toggle"
4858 was_paused
= !was_paused
;
4860 case 2: // "pausing_keep"
4861 if (was_paused
) osd_function
= OSD_PAUSE
;
4871 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
4872 rel_seek_secs
+= 3600*a
+60*b
+d
;
4873 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
4874 rel_seek_secs
+= 60*a
+d
;
4875 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
4882 if(eof
==1 && loop_times
>=0) {
4884 play_tree_iter_step(playtree_iter
,0,0);
4886 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
4888 if(loop_times
>1) loop_times
--; else
4889 if(loop_times
==1) loop_times
=-1;
4890 play_n_frames
=play_n_frames_mf
;
4892 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
4896 if(rel_seek_secs
|| abs_seek_pos
){
4897 current_module
="seek";
4898 if(demux_seek(demuxer
,rel_seek_secs
,audio_delay
,abs_seek_pos
)){
4900 /* FIXME there should be real seeking for vobsub */
4901 if(sh_video
) sh_video
->pts
=d_video
->pts
;
4903 //vobsub_reset(vo_vobsub);
4904 vobsub_seek(vo_vobsub
,sh_video
->pts
);
4908 current_module
="seek_video_reset";
4909 resync_video_stream(sh_video
);
4910 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
4911 sh_video
->num_buffered_pts
= 0;
4912 last_pts
= MP_NOPTS_VALUE
;
4916 current_module
="seek_audio_reset";
4917 audio_out
->reset(); // stop audio, throwing away buffered data
4918 sh_audio
->a_buffer_len
= 0;
4919 sh_audio
->a_out_buffer_len
= 0;
4924 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer
));
4929 max_pts_correction
=0.1;
4930 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
4931 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4933 too_slow_frame_cnt
=0;
4934 too_fast_frame_cnt
=0;
4936 if(vo_spudec
) spudec_reset(vo_spudec
);
4940 * We saw a seek, have to rewind the EDL operations stack
4941 * and find the next EDL action to take care of.
4945 next_edl_record
= edl_records
;
4947 while (next_edl_record
)
4949 /* Trying to remember if we need to mute/unmute first;
4950 * prior EDL implementation lacks this.
4953 if (next_edl_record
->start_sec
>= sh_video
->pts
)
4956 if (next_edl_record
->action
== EDL_MUTE
) edl_muted
= !edl_muted
;
4957 next_edl_record
= next_edl_record
->next
;
4960 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4964 frame_time_remaining
=0;
4965 current_module
=NULL
;
4972 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
4973 // get pos from frame number / total frames
4974 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
4976 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
4977 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
4978 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
4980 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
4981 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
4982 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
4983 guiGetEvent( guiReDraw
,NULL
);
4984 guiGetEvent( guiSetVolume
,NULL
);
4985 if(guiIntfStruct
.Playing
==0) break; // STOP
4986 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
4987 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
4989 if ( stream
->type
== STREAMTYPE_DVD
)
4991 dvd_priv_t
* dvdp
= stream
->priv
;
4992 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
4996 #endif /* HAVE_NEW_GUI */
4999 //================= Update OSD ====================
5005 if(subdata
&& sh_video
&& sh_video
->pts
>0){
5006 float pts
=sh_video
->pts
;
5007 if(sub_fps
==0) sub_fps
=sh_video
->fps
;
5008 current_module
="find_sub";
5009 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0 ) {
5010 find_sub(subdata
, (pts
+sub_delay
) *
5011 (subdata
->sub_uses_time
? 100. : sub_fps
));
5012 if (vo_sub
) vo_sub_last
= vo_sub
;
5013 // FIXME! frame counter...
5016 current_module
=NULL
;
5021 if (stop_xscreensaver
&& sh_video
) {
5022 current_module
="stop_xscreensaver";
5023 xscreensaver_heartbeat();
5024 current_module
=NULL
;
5029 if(vo_config_count
&& vo_spudec
) {
5030 unsigned char* packet
=NULL
;
5032 current_module
="spudec";
5033 spudec_heartbeat(vo_spudec
,90000*sh_video
->timer
);
5034 /* Get a sub packet from the DVD or a vobsub and make a timestamp
5035 relative to sh_video->timer */
5040 if(sh_video
->pts
+sub_delay
>=0) {
5041 // The + next_frame_time is there because we'll display the sub at the next frame
5042 len
= vobsub_get_packet(vo_vobsub
,sh_video
->pts
+sub_delay
+next_frame_time
,(void**)&packet
,×tamp
);
5044 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
5045 mp_dbg(MSGT_CPLAYER
,MSGL_V
,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len
,sh_video
->pts
,sh_video
->timer
,timestamp
/ 90000.0,timestamp
);
5050 len
= ds_get_packet_sub(d_dvdsub
,(unsigned char**)&packet
);
5052 float x
= d_dvdsub
->pts
- sh_video
->pts
;
5053 if (x
< -10 || x
> 10) // prevent missing subs on pts reset
5054 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
+ sub_delay
- sh_video
->pts
);
5055 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
5056 mp_dbg(MSGT_CPLAYER
,MSGL_V
,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f ts=%d \n",len
,sh_video
->pts
,d_dvdsub
->pts
,timestamp
);
5059 if(len
<=0 || !packet
) break;
5060 if(timestamp
< 0) timestamp
= 0;
5061 else spudec_assemble(vo_spudec
,packet
,len
,timestamp
);
5064 /* detect wether the sub has changed or not */
5065 if(spudec_changed(vo_spudec
))
5066 vo_osd_changed(OSDTYPE_SPU
);
5067 current_module
=NULL
;
5072 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
5074 #ifdef HAS_DVBIN_SUPPORT
5078 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
5079 cache_uninit(stream
);
5081 goto goto_enable_cache
;
5086 goto_next_file
: // don't jump here after ao/vo/getch initialization!
5088 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
5091 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
5092 double total_time_usage
;
5093 total_time_usage_start
=GetTimer()-total_time_usage_start
;
5094 total_time_usage
= (float)total_time_usage_start
*0.000001;
5095 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5096 video_time_usage
,vout_time_usage
,audio_time_usage
,
5097 total_time_usage
-tot
,total_time_usage
);
5098 if(total_time_usage
>0.0)
5099 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5100 100.0*video_time_usage
/total_time_usage
,
5101 100.0*vout_time_usage
/total_time_usage
,
5102 100.0*audio_time_usage
/total_time_usage
,
5103 100.0*(total_time_usage
-tot
)/total_time_usage
,
5105 if(total_frame_cnt
&& frame_dropping
)
5106 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5107 total_frame_cnt
-drop_frame_cnt
,
5108 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
5110 100*drop_frame_cnt
/total_frame_cnt
,
5112 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
5116 // time to uninit all, except global stuff:
5117 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
5120 if ( set_of_sub_size
> 0 )
5122 current_module
="sub_free";
5123 for (i
= 0; i
< set_of_sub_size
; ++i
) {
5124 sub_free( set_of_subtitles
[i
] );
5126 if ( set_of_ass_tracks
[i
] )
5127 ass_free_track( set_of_ass_tracks
[i
] );
5130 set_of_sub_size
= 0;
5131 vo_sub_last
= vo_sub
=NULL
;
5139 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
5140 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
5141 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
5144 play_tree_iter_free(playtree_iter
);
5145 playtree_iter
= NULL
;
5148 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
5149 eof
= eof
== PT_UP_NEXT
? 1 : -1;
5150 if ( playtree_iter
) {
5151 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
5154 play_tree_iter_free(playtree_iter
);
5155 playtree_iter
= NULL
;
5158 } else { // NEXT PREV SRC
5159 eof
= eof
== PT_PREV_SRC
? -1 : 1;
5162 if(eof
== 0) eof
= 1;
5164 while(playtree_iter
!= NULL
) {
5165 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
5166 if(filename
== NULL
) {
5167 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
5168 play_tree_iter_free(playtree_iter
);
5169 playtree_iter
= NULL
;
5176 if( use_gui
&& !playtree_iter
)
5179 if ( !guiIntfStruct
.DiskChanged
)
5185 if(use_gui
|| playtree_iter
!= NULL
|| player_idle_mode
){
5186 if (!playtree_iter
) filename
= NULL
;
5188 goto play_next_file
;
5192 exit_player_with_rc(MSGTR_Exit_eof
, 0);