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"
79 #include "osdep/getch2.h"
80 #include "osdep/timer.h"
82 #include "cpudetect.h"
85 #include "Gui/interface.h"
88 #include "input/input.h"
91 int player_idle_mode
=0;
96 char * proc_priority
=NULL
;
99 #define ABS(x) (((x)>=0)?(x):(-(x)))
100 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
104 #include <linux/rtc.h>
107 #define RTC_IRQP_SET RTCIO_IRQP_SET
108 #define RTC_PIE_ON RTCIO_PIE_ON
109 #endif /* __linux__ */
110 #endif /* HAVE_RTC */
113 #include "libmpdemux/tv.h"
116 #ifdef HAS_DVBIN_SUPPORT
117 #include "libmpdemux/dvbin.h"
118 static int last_dvb_step
= 1;
119 static int dvbin_reopen
= 0;
120 extern void cache_uninit(stream_t
*s
);
123 //**************************************************************************//
125 //**************************************************************************//
126 #include "playtree.h"
127 #include "playtreeparser.h"
130 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
131 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
134 play_tree_t
* playtree
;
135 play_tree_iter_t
* playtree_iter
= NULL
;
136 static int play_tree_step
= 1;
138 #define PT_NEXT_ENTRY 1
139 #define PT_PREV_ENTRY -1
140 #define PT_NEXT_SRC 2
141 #define PT_PREV_SRC -2
143 #define PT_UP_PREV -3
145 //**************************************************************************//
147 //**************************************************************************//
151 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
);
153 m_config_parse_config_file(m_config_t
* config
, char *conffile
);
155 //**************************************************************************//
157 //**************************************************************************//
159 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
161 static int cfg_include(m_option_t
*conf
, char *filename
){
162 return m_config_parse_config_file(mconfig
, filename
);
165 #include "get_path.c"
167 //**************************************************************************//
169 //**************************************************************************//
172 void xscreensaver_heartbeat(void);
175 //**************************************************************************//
176 //**************************************************************************//
177 // Input media streaming & demultiplexer:
178 //**************************************************************************//
180 static int max_framesize
=0;
182 #include "libmpdemux/stream.h"
183 #include "libmpdemux/demuxer.h"
184 #include "libmpdemux/stheader.h"
185 //#include "parse_es.h"
186 #include "libmpdemux/matroska.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
];
352 extern int mp_msg_levels
[MSGT_MAX
];
353 extern int mp_msg_level_all
;
355 static stream_t
* stream
=NULL
;
356 static demuxer_t
*demuxer
=NULL
;
357 static sh_audio_t
*sh_audio
=NULL
;
358 static sh_video_t
*sh_video
=NULL
;
359 static demux_stream_t
*d_audio
=NULL
;
360 static demux_stream_t
*d_video
=NULL
;
361 static demux_stream_t
*d_dvdsub
=NULL
;
363 char* current_module
=NULL
; // for debugging
365 extern int vo_gamma_gamma
;
366 extern int vo_gamma_brightness
;
367 extern int vo_gamma_contrast
;
368 extern int vo_gamma_saturation
;
369 extern int vo_gamma_hue
;
374 #include "m_struct.h"
375 #include "libmenu/menu.h"
376 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
377 extern vf_info_t vf_info_menu
;
378 static vf_info_t
* libmenu_vfs
[] = {
382 static vf_instance_t
* vf_menu
= NULL
;
383 static int use_menu
= 0;
384 static char* menu_cfg
= NULL
;
385 static char* menu_root
= "main";
391 static char* rtc_device
;
394 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
395 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
396 short user_muted
= 0; ///< Stores whether user wanted muted mode.
397 short edl_muted
= 0; ///< Stores whether EDL is currently in muted mode.
398 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
399 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
401 static unsigned int inited_flags
=0;
405 #define INITED_GETCH2 8
406 #define INITED_SPUDEC 32
407 #define INITED_STREAM 64
408 #define INITED_INPUT 128
409 #define INITED_VOBSUB 256
410 #define INITED_DEMUXER 512
411 #define INITED_ACODEC 1024
412 #define INITED_VCODEC 2048
413 #define INITED_ALL 0xFFFF
415 static void uninit_player(unsigned int mask
){
416 mask
=inited_flags
&mask
;
418 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
420 if(mask
&INITED_ACODEC
){
421 inited_flags
&=~INITED_ACODEC
;
422 current_module
="uninit_acodec";
423 if(sh_audio
) uninit_audio(sh_audio
);
425 guiGetEvent(guiSetAfilter
, (char *)NULL
);
430 if(mask
&INITED_VCODEC
){
431 inited_flags
&=~INITED_VCODEC
;
432 current_module
="uninit_vcodec";
433 if(sh_video
) uninit_video(sh_video
);
440 if(mask
&INITED_DEMUXER
){
441 inited_flags
&=~INITED_DEMUXER
;
442 current_module
="free_demuxer";
444 stream
=demuxer
->stream
;
445 free_demuxer(demuxer
);
450 // kill the cache process:
451 if(mask
&INITED_STREAM
){
452 inited_flags
&=~INITED_STREAM
;
453 current_module
="uninit_stream";
454 if(stream
) free_stream(stream
);
459 inited_flags
&=~INITED_VO
;
460 current_module
="uninit_vo";
465 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
466 if(mask
&INITED_GETCH2
){
467 inited_flags
&=~INITED_GETCH2
;
468 current_module
="uninit_getch2";
469 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
474 if(mask
&INITED_VOBSUB
){
475 inited_flags
&=~INITED_VOBSUB
;
476 current_module
="uninit_vobsub";
477 if(vo_vobsub
) vobsub_close(vo_vobsub
);
481 if (mask
&INITED_SPUDEC
){
482 inited_flags
&=~INITED_SPUDEC
;
483 current_module
="uninit_spudec";
484 spudec_free(vo_spudec
);
489 inited_flags
&=~INITED_AO
;
490 current_module
="uninit_ao";
491 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
496 inited_flags
&=~INITED_GUI
;
497 current_module
="uninit_gui";
502 if(mask
&INITED_INPUT
){
503 inited_flags
&=~INITED_INPUT
;
504 current_module
="uninit_input";
511 static void exit_player_with_rc(char* how
, int rc
){
513 uninit_player(INITED_ALL
);
518 vo_uninit(); // Close the X11 connection (if any is open).
522 current_module
="uninit_font";
523 if (vo_font
) free_font_desc(vo_font
);
529 current_module
="exit_player";
531 // free mplayer config
533 m_config_free(mconfig
);
536 play_tree_free(playtree
, 1);
539 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
540 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
541 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
546 void exit_player(char* how
){
547 exit_player_with_rc(how
, 1);
551 static void child_sighandler(int x
){
553 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
558 static char *prog_path
;
559 static int crash_debug
= 0;
562 static void exit_sighandler(int x
){
563 static int sig_count
=0;
565 if (!crash_debug
|| x
!= SIGTRAP
)
568 if(inited_flags
==0 && sig_count
>1) exit(1);
571 /* We're crashing bad and can't uninit cleanly :(
572 * by popular request, we make one last (dirty)
573 * effort to restore the user's
578 if(sig_count
==6) exit(1);
582 kill(getpid(),SIGKILL
);
585 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
586 current_module
?current_module
:"unknown"
588 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
595 break; // killed from keyboard (^C) or killed [-9]
597 #ifdef RUNTIME_CPUDETECT
598 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
600 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
604 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
606 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
611 snprintf(spid
, 19, "%i", getpid());
613 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
615 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
616 if (gdb_pid
== 0) { // We are the child
617 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
618 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
619 } else if (gdb_pid
< 0)
620 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
622 waitpid(gdb_pid
, NULL
, 0);
624 if (x
== SIGTRAP
) return;
631 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
633 extern void mp_input_register_options(m_config_t
* cfg
);
637 /// step size of mixer changes
640 #include "cfg-mplayer.h"
642 void parse_cfgfiles( m_config_t
* conf
)
646 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
648 if ((conffile
= get_path("")) == NULL
) {
649 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
654 mkdir(conffile
, 0777);
657 if ((conffile
= get_path("config")) == NULL
) {
658 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
660 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
661 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
662 write(conffile_fd
, default_config
, strlen(default_config
));
665 if (m_config_parse_config_file(conf
, conffile
) < 0)
672 void load_per_file_config (m_config_t
* conf
, const char *const file
)
675 char cfg
[strlen(file
)+10];
679 sprintf (cfg
, "%s.conf", file
);
681 if (!stat (cfg
, &st
))
683 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
684 m_config_parse_config_file (conf
, cfg
);
688 if ((name
= strrchr (cfg
, '/')) == NULL
)
693 if ((confpath
= get_path (name
)) != NULL
)
695 if (!stat (confpath
, &st
))
697 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
698 m_config_parse_config_file (conf
, confpath
);
705 /* When libmpdemux performs a blocking operation (network connection or
706 * cache filling) if the operation fails we use this function to check
707 * if it was interrupted by the user.
708 * The function returns a new value for eof. */
709 static int libmpdemux_was_interrupted(int eof
) {
711 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
714 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
715 case MP_CMD_PLAY_TREE_STEP
: {
716 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
717 play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
719 case MP_CMD_PLAY_TREE_UP_STEP
: {
720 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
722 case MP_CMD_PLAY_ALT_SRC_STEP
: {
723 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
731 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
732 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
734 int playtree_add_playlist(play_tree_t
* entry
)
736 play_tree_add_bpf(entry
,filename
);
741 import_playtree_playlist_into_gui(entry
, mconfig
);
742 play_tree_free_list(entry
,1);
748 entry
= playtree_iter
->tree
;
749 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
750 return PT_NEXT_ENTRY
;
752 if(playtree_iter
->tree
== entry
) { // Loop with a single file
753 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
754 return PT_NEXT_ENTRY
;
757 play_tree_remove(entry
,1,1);
760 play_tree_insert_entry(playtree_iter
->tree
,entry
);
761 play_tree_set_params_from(entry
,playtree_iter
->tree
);
762 entry
= playtree_iter
->tree
;
763 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
764 return PT_NEXT_ENTRY
;
766 play_tree_remove(entry
,1,1);
776 for (i
= 0; i
< SUB_SOURCES
; i
++) {
777 int j
= global_sub_indices
[i
];
778 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
788 sub_data
* subdata
= NULL
;
789 static subtitle
* vo_sub_last
= NULL
;
791 void add_subtitles(char *filename
, float fps
, int silent
)
795 if (filename
== NULL
) {
799 subd
= sub_read_file(filename
, fps
);
801 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
802 if (subd
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) return;
803 set_of_subtitles
[set_of_sub_size
] = subd
;
804 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", set_of_sub_size
);
805 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n", filename
);
807 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, set_of_sub_size
, filename
);
810 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
811 void update_set_of_subtitles(void)
812 // subdata was changed, set_of_sub... have to be updated.
815 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
816 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
817 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
818 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
820 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
822 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
823 set_of_subtitles
[set_of_sub_pos
] = subdata
;
825 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
826 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
833 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
834 * make it all work is to use the builtin SDL-bootstrap code, which
835 * will be done automatically by replacing our main() if we include SDL.h.
837 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
842 * \brief append a formatted string
843 * \param buf buffer to print into
844 * \param pos position of terminating 0 in buf
845 * \param len maximum number of characters in buf, not including terminating 0
846 * \param format printf format string
848 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
851 va_start(va
, format
);
852 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
861 * \brief append time in the hh:mm:ss.f format
862 * \param buf buffer to print into
863 * \param pos position of terminating 0 in buf
864 * \param len maximum number of characters in buf, not including terminating 0
865 * \param time time value to convert/append
867 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
868 long tenths
= 10 * time
;
869 int f1
= tenths
% 10;
870 int ss
= (tenths
/ 10) % 60;
871 int mm
= (tenths
/ 600) % 60;
872 int hh
= tenths
/ 36000;
874 saddf(buf
, pos
, len
, "unknown");
878 saddf(buf
, pos
, len
, "%2d:", hh
);
879 if (hh
> 0 || mm
> 0)
880 saddf(buf
, pos
, len
, "%02d:", mm
);
881 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
885 * \brief print the status line
886 * \param a_pos audio position
887 * \param a_v A-V desynchronization
888 * \param corr amount out A-V synchronization
890 static void print_status(float a_pos
, float a_v
, float corr
)
896 if (screen_width
> 0)
897 width
= screen_width
;
901 /* Windows command line is broken (MinGW's rxvt works, but we
902 * should not depend on that). */
905 line
= malloc(width
+ 1); // one additional char for the terminating null
909 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
911 float len
= demuxer_get_time_length(demuxer
);
912 saddf(line
, &pos
, width
, "(");
913 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
914 saddf(line
, &pos
, width
, ") of %.1f (", len
);
915 sadd_hhmmssf(line
, &pos
, width
, len
);
916 saddf(line
, &pos
, width
, ") ");
922 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
925 if (sh_audio
&& sh_video
)
926 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
930 saddf(line
, &pos
, width
, "%3d/%3d ",
931 (int)sh_video
->num_frames
,
932 (int)sh_video
->num_frames_decoded
);
936 if (sh_video
->timer
> 0.5)
937 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
938 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
939 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
940 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
942 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
943 } else if (sh_audio
) {
944 if (sh_audio
->delay
> 0.5)
945 saddf(line
, &pos
, width
, "%4.1f%% ",
946 100.0*audio_time_usage
/(double)sh_audio
->delay
);
948 saddf(line
, &pos
, width
, "??,?%% ");
953 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
955 #ifdef USE_STREAM_CACHE
957 if (stream_cache_size
> 0)
958 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
962 if (playback_speed
!= 1)
963 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
966 if (erase_to_end_of_line
) {
968 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
970 memset(&line
[pos
], ' ', width
- pos
);
972 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
978 * \brief build a chain of audio filters that converts the input format
979 * to the ao's format, taking into account the current playback_speed.
980 * \param sh_audio describes the requested input format of the chain.
981 * \param ao_data describes the requested output format of the chain.
983 static int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
990 guiGetEvent(guiSetAfilter
, (char *)NULL
);
992 mixer
.afilter
= NULL
;
995 new_srate
= sh_audio
->samplerate
* playback_speed
;
996 if (new_srate
!= ao_data
->samplerate
) {
997 // limits are taken from libaf/af_resample.c
998 if (new_srate
< 8000)
1000 if (new_srate
> 192000)
1002 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1004 result
= init_audio_filters(sh_audio
, new_srate
,
1005 sh_audio
->channels
, sh_audio
->sample_format
,
1006 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1007 ao_data
->outburst
* 4, ao_data
->buffersize
);
1008 mixer
.afilter
= sh_audio
->afilter
;
1010 guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1017 * \brief Log the currently displayed subtitle to a file
1019 * Logs the current or last displayed subtitle together with filename
1020 * and time information to ~/.mplayer/subtitle_log
1022 * Intended purpose is to allow convenient marking of bogus subtitles
1023 * which need to be fixed while watching the movie.
1026 static void log_sub(void){
1031 if (subdata
== NULL
|| vo_sub_last
== NULL
) return;
1032 fname
= get_path("subtitle_log");
1033 f
= fopen(fname
, "a");
1035 fprintf(f
, "----------------------------------------------------------\n");
1036 if (subdata
->sub_uses_time
) {
1037 fprintf(f
, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename
,
1038 vo_sub_last
->start
/360000, (vo_sub_last
->start
/6000)%60,
1039 (vo_sub_last
->start
/100)%60, vo_sub_last
->start
%100,
1040 vo_sub_last
->end
/360000, (vo_sub_last
->end
/6000)%60,
1041 (vo_sub_last
->end
/100)%60, vo_sub_last
->end
%100);
1043 fprintf(f
, "N: %s S: %ld E: %ld\n", filename
, vo_sub_last
->start
, vo_sub_last
->end
);
1045 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
1046 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
1050 #endif /* USE_SUB */
1052 /// \defgroup OSDMsgStack OSD message stack
1056 #define OSD_MSG_TV_CHANNEL 0
1057 #define OSD_MSG_TEXT 1
1058 #define OSD_MSG_SUB_DELAY 2
1059 #define OSD_MSG_SPEED 3
1060 #define OSD_MSG_OSD_STATUS 4
1061 #define OSD_MSG_BAR 5
1062 #define OSD_MSG_PAUSE 6
1063 /// Base id for messages generated from the commmand to property bridge.
1064 #define OSD_MSG_PROPERTY 0x100
1067 typedef struct mp_osd_msg mp_osd_msg_t
;
1069 /// Previous message on the stack.
1073 int id
,level
,started
;
1074 /// Display duration in ms.
1078 /// OSD message stack.
1079 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1082 * \brief Add a message on the OSD message stack
1084 * If a message with the same id is already present in the stack
1085 * it is pulled on top of the stack, otherwise a new message is created.
1089 static void set_osd_msg(int id
, int level
, int time
, char* fmt
, ...) {
1090 mp_osd_msg_t
*msg
,*last
=NULL
;
1094 // look if the id is already in the stack
1095 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1096 last
= msg
, msg
= msg
->prev
);
1097 // not found: alloc it
1099 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1100 msg
->prev
= osd_msg_stack
;
1101 osd_msg_stack
= msg
;
1102 } else if(last
) { // found, but it's not on top of the stack
1103 last
->prev
= msg
->prev
;
1104 msg
->prev
= osd_msg_stack
;
1105 osd_msg_stack
= msg
;
1109 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1111 if(r
>= 64) msg
->msg
[63] = 0;
1120 * \brief Remove a message from the OSD stack
1122 * This function can be used to get rid of a message right away.
1126 static void rm_osd_msg(int id
) {
1127 mp_osd_msg_t
*msg
,*last
=NULL
;
1129 // Search for the msg
1130 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1131 last
= msg
, msg
= msg
->prev
);
1134 // Detach it from the stack and free it
1136 last
->prev
= msg
->prev
;
1138 osd_msg_stack
= msg
->prev
;
1143 * \brief Remove all messages from the OSD stack
1147 static void clear_osd_msgs(void) {
1148 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1154 osd_msg_stack
= NULL
;
1158 * \brief Get the current message from the OSD stack.
1160 * This function decrements the message timer and destroys the old ones.
1161 * The message that should be displayed is returned (if any).
1165 static mp_osd_msg_t
* get_osd_msg(void) {
1166 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1167 static unsigned last_update
= 0;
1168 unsigned now
= GetTimerMS();
1170 char hidden_dec_done
= 0;
1172 if(!last_update
) last_update
= now
;
1173 diff
= now
>= last_update
? now
- last_update
: 0;
1177 // Look for the first message in the stack with high enough level.
1178 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1180 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1181 // The message has a high enough level or it is the first hidden one
1182 // in both cases we decrement the timer or kill it.
1183 if(!msg
->started
|| msg
->time
> diff
) {
1184 if(msg
->started
) msg
->time
-= diff
;
1185 else msg
->started
= 1;
1187 if(msg
->level
<= osd_level
) return msg
;
1188 hidden_dec_done
= 1;
1197 osd_msg_stack
= prev
;
1205 // Make a define to test if we are using the term OSD without having
1206 // to #ifdef USE_OSD all the time.
1208 #define use_term_osd (term_osd && !sh_video)
1210 #define use_term_osd (term_osd)
1214 * \brief Display the OSD bar.
1216 * Display the OSD bar or fall back on a simple message.
1220 void set_osd_bar(int type
,char* name
,double min
,double max
,double val
) {
1222 if(osd_level
< 1) return;
1226 osd_visible
= (GetTimerMS() + 1000) | 1;
1227 vo_osd_progbar_type
= type
;
1228 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1229 vo_osd_changed(OSDTYPE_PROGBAR
);
1234 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1235 name
,ROUND(100*(val
-min
)/(max
-min
)));
1240 * \brief Update the OSD message line.
1242 * This function displays the current message on the vo OSD or on the term.
1243 * If the stack is empty and the OSD level is high enough the timer
1244 * is displayed (only on the vo OSD).
1248 static void update_osd_msg(void) {
1250 static char osd_text
[64] = "";
1251 static char osd_text_timer
[64];
1254 // we need some mem for vo_osd_text
1255 vo_osd_text
= (unsigned char*)osd_text
;
1258 // Look if we have a msg
1259 if((msg
= get_osd_msg())) {
1260 if(strcmp(osd_text
,msg
->msg
)) {
1261 strncpy((char*)osd_text
, msg
->msg
, 63);
1263 if(sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1265 if(term_osd
) printf("%s%s\n",term_osd_esc
,msg
->msg
);
1272 // fallback on the timer
1274 int len
= demuxer_get_time_length(demuxer
);
1275 int percentage
= -1;
1276 char percentage_text
[10];
1277 static int last_pts
= -303;
1278 int pts
= sh_video
->pts
;
1279 if(pts
==last_pts
-1) ++pts
; else last_pts
=pts
;
1281 if (osd_show_percentage
)
1282 percentage
= demuxer_get_percent_pos(demuxer
);
1284 if (percentage
>= 0)
1285 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1287 percentage_text
[0] = 0;
1290 snprintf(osd_text_timer
, 63,
1291 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1292 osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1293 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1295 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1296 osd_function
,pts
/3600,(pts
/60)%60,
1297 pts
%60,percentage_text
);
1299 osd_text_timer
[0]=0;
1301 // always decrement the percentage timer
1302 if(osd_show_percentage
)
1303 osd_show_percentage
--;
1305 if(strcmp(osd_text
,osd_text_timer
)) {
1306 strncpy(osd_text
, osd_text_timer
, 63);
1307 vo_osd_changed(OSDTYPE_OSD
);
1313 // Clear the term osd line
1314 if(term_osd
&& osd_text
[0]) {
1316 printf("%s\n",term_osd_esc
);
1323 /// \defgroup Properties
1326 /// \defgroup GeneralProperties General properties
1327 /// \ingroup Properties
1331 static int mp_property_osdlevel(m_option_t
* prop
,int action
,void* arg
) {
1332 return m_property_choice(prop
,action
,arg
,&osd_level
);
1335 /// Playback speed (RW)
1336 static int mp_property_playback_speed(m_option_t
* prop
,int action
,void* arg
) {
1338 case M_PROPERTY_SET
:
1340 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1341 playback_speed
= *(float*)arg
;
1342 build_afilter_chain(sh_audio
, &ao_data
);
1344 case M_PROPERTY_STEP_UP
:
1345 case M_PROPERTY_STEP_DOWN
:
1346 playback_speed
+= (arg
? *(float*)arg
: 0.1) *
1347 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1348 M_PROPERTY_CLAMP(prop
,playback_speed
);
1349 build_afilter_chain(sh_audio
, &ao_data
);
1352 return m_property_float_range(prop
,action
,arg
,&playback_speed
);
1355 /// filename with path (RO)
1356 static int mp_property_path(m_option_t
* prop
,int action
,void* arg
) {
1357 return m_property_string_ro(prop
,action
,arg
,filename
);
1360 /// filename without path (RO)
1361 static int mp_property_filename(m_option_t
* prop
,int action
,void* arg
) {
1363 if(!filename
) return M_PROPERTY_UNAVAILABLE
;
1364 if(((f
= strrchr(filename
,'/')) || (f
= strrchr(filename
,'\\'))) && f
[1])
1368 return m_property_string_ro(prop
,action
,arg
,f
);
1371 /// Demuxer name (RO)
1372 static int mp_property_demuxer(m_option_t
* prop
,int action
,void* arg
) {
1373 if(!demuxer
) return M_PROPERTY_UNAVAILABLE
;
1374 return m_property_string_ro(prop
,action
,arg
,(char*)demuxer
->desc
->name
);
1377 /// Position in the stream (RW)
1378 static int mp_property_stream_pos(m_option_t
* prop
,int action
,void* arg
) {
1379 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1380 if (!arg
) return M_PROPERTY_ERROR
;
1382 case M_PROPERTY_GET
:
1383 *(off_t
*)arg
= stream_tell(demuxer
->stream
);
1384 return M_PROPERTY_OK
;
1385 case M_PROPERTY_SET
:
1386 M_PROPERTY_CLAMP(prop
,*(off_t
*)arg
);
1387 stream_seek(demuxer
->stream
, *(off_t
*)arg
);
1388 return M_PROPERTY_OK
;
1390 return M_PROPERTY_NOT_IMPLEMENTED
;
1393 /// Stream start offset (RO)
1394 static int mp_property_stream_start(m_option_t
* prop
,int action
,void* arg
) {
1395 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1397 case M_PROPERTY_GET
:
1398 *(off_t
*)arg
= demuxer
->stream
->start_pos
;
1399 return M_PROPERTY_OK
;
1401 return M_PROPERTY_NOT_IMPLEMENTED
;
1404 /// Stream end offset (RO)
1405 static int mp_property_stream_end(m_option_t
* prop
,int action
,void* arg
) {
1406 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1408 case M_PROPERTY_GET
:
1409 *(off_t
*)arg
= demuxer
->stream
->end_pos
;
1410 return M_PROPERTY_OK
;
1412 return M_PROPERTY_NOT_IMPLEMENTED
;
1415 /// Stream length (RO)
1416 static int mp_property_stream_length(m_option_t
* prop
,int action
,void* arg
) {
1417 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1419 case M_PROPERTY_GET
:
1420 *(off_t
*)arg
= demuxer
->stream
->end_pos
- demuxer
->stream
->start_pos
;
1421 return M_PROPERTY_OK
;
1423 return M_PROPERTY_NOT_IMPLEMENTED
;
1426 /// Media length in seconds (RO)
1427 static int mp_property_length(m_option_t
* prop
,int action
,void* arg
) {
1431 !(int)(len
= demuxer_get_time_length(demuxer
)))
1432 return M_PROPERTY_UNAVAILABLE
;
1435 case M_PROPERTY_PRINT
:
1443 *(char**)arg
= malloc(20);
1444 if(h
> 0) sprintf(*(char**)arg
,"%d:%02d:%02d",h
,m
,s
);
1445 else if(m
> 0) sprintf(*(char**)arg
,"%d:%02d",m
,s
);
1446 else sprintf(*(char**)arg
,"%d",s
);
1451 return m_property_double_ro(prop
,action
,arg
,len
);
1456 /// \defgroup AudioProperties Audio properties
1457 /// \ingroup Properties
1461 static int mp_property_volume(m_option_t
* prop
,int action
,void* arg
) {
1463 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1466 case M_PROPERTY_GET
:
1468 mixer_getbothvolume(&mixer
,arg
);
1470 case M_PROPERTY_PRINT
:{
1473 mixer_getbothvolume(&mixer
,&vol
);
1474 return m_property_float_range(prop
,action
,arg
,&vol
);
1476 case M_PROPERTY_STEP_UP
:
1477 case M_PROPERTY_STEP_DOWN
:
1478 case M_PROPERTY_SET
:
1481 return M_PROPERTY_NOT_IMPLEMENTED
;
1484 if (edl_muted
) return M_PROPERTY_DISABLED
;
1488 case M_PROPERTY_SET
:
1490 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1491 mixer_setvolume(&mixer
,*(float*)arg
,*(float*)arg
);
1493 case M_PROPERTY_STEP_UP
:
1494 if(arg
&& *(float*)arg
<= 0)
1495 mixer_decvolume(&mixer
);
1497 mixer_incvolume(&mixer
);
1499 case M_PROPERTY_STEP_DOWN
:
1500 if(arg
&& *(float*)arg
<= 0)
1501 mixer_incvolume(&mixer
);
1503 mixer_decvolume(&mixer
);
1506 return M_PROPERTY_NOT_IMPLEMENTED
;
1510 static int mp_property_mute(m_option_t
* prop
,int action
,void* arg
) {
1512 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1515 case M_PROPERTY_SET
:
1516 if(edl_muted
) return M_PROPERTY_DISABLED
;
1518 if((!!*(int*)arg
) != mixer
.muted
)
1521 case M_PROPERTY_STEP_UP
:
1522 case M_PROPERTY_STEP_DOWN
:
1523 if(edl_muted
) return M_PROPERTY_DISABLED
;
1526 case M_PROPERTY_PRINT
:
1529 *(char**)arg
= strdup(MSGTR_EnabledEdl
);
1533 return m_property_flag(prop
,action
,arg
,&mixer
.muted
);
1538 /// Audio delay (RW)
1539 static int mp_property_audio_delay(m_option_t
* prop
,int action
,void* arg
) {
1540 if(!(sh_audio
&& sh_video
)) return M_PROPERTY_UNAVAILABLE
;
1542 case M_PROPERTY_SET
:
1543 case M_PROPERTY_STEP_UP
:
1544 case M_PROPERTY_STEP_DOWN
:
1547 float delay
= audio_delay
;
1548 m_property_delay(prop
,action
,arg
,&audio_delay
);
1549 if(sh_audio
) sh_audio
->delay
-= audio_delay
-delay
;
1553 return m_property_delay(prop
,action
,arg
,&audio_delay
);
1557 /// Audio codec tag (RO)
1558 static int mp_property_audio_format(m_option_t
* prop
,int action
,void* arg
) {
1559 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1560 return m_property_int_ro(prop
,action
,arg
,sh_audio
->format
);
1563 /// Audio bitrate (RO)
1564 static int mp_property_audio_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1565 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1566 return m_property_int_ro(prop
,action
,arg
,sh_audio
->i_bps
);
1570 static int mp_property_samplerate(m_option_t
* prop
,int action
,void* arg
) {
1571 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1572 return m_property_int_ro(prop
,action
,arg
,sh_audio
->samplerate
);
1575 /// Number of channels (RO)
1576 static int mp_property_channels(m_option_t
* prop
,int action
,void* arg
) {
1577 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1579 case M_PROPERTY_PRINT
:
1581 switch(sh_audio
->channels
) {
1582 case 1: *(char**)arg
= strdup("mono"); break;
1583 case 2: *(char**)arg
= strdup("stereo"); break;
1585 *(char**)arg
= malloc(32);
1586 sprintf(*(char**)arg
,"%d channels",sh_audio
->channels
);
1590 return m_property_int_ro(prop
,action
,arg
,sh_audio
->channels
);
1595 /// \defgroup VideoProperties Video properties
1596 /// \ingroup Properties
1599 /// Fullscreen state (RW)
1600 static int mp_property_fullscreen(m_option_t
* prop
,int action
,void* arg
) {
1602 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1605 case M_PROPERTY_SET
:
1607 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1608 if(vo_fs
== !!*(int*)arg
) return 1;
1609 case M_PROPERTY_STEP_UP
:
1610 case M_PROPERTY_STEP_DOWN
:
1612 if(use_gui
) guiGetEvent(guiIEvent
,(char*)MP_CMD_GUI_FULLSCREEN
);
1615 if(vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
1618 return m_property_flag(prop
,action
,arg
,&vo_fs
);
1623 static int mp_property_panscan(m_option_t
* prop
,int action
,void* arg
) {
1625 if(!video_out
|| video_out
->control(VOCTRL_GET_PANSCAN
,NULL
) != VO_TRUE
)
1626 return M_PROPERTY_UNAVAILABLE
;
1629 case M_PROPERTY_SET
:
1631 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1632 vo_panscan
= *(float*)arg
;
1633 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
1635 case M_PROPERTY_STEP_UP
:
1636 case M_PROPERTY_STEP_DOWN
:
1637 vo_panscan
+= (arg
? *(float*)arg
: 0.1) *
1638 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1639 if(vo_panscan
> 1) vo_panscan
= 1;
1640 else if(vo_panscan
< 0) vo_panscan
= 0;
1641 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
1644 return m_property_float_range(prop
,action
,arg
,&vo_panscan
);
1648 /// Helper to set vo flags.
1649 /** \ingroup PropertyImplHelper
1651 static int mp_property_vo_flag(m_option_t
* prop
,int action
,void* arg
,
1652 int vo_ctrl
,int* vo_var
) {
1654 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1657 case M_PROPERTY_SET
:
1659 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1660 if(*vo_var
== !!*(int*)arg
) return 1;
1661 case M_PROPERTY_STEP_UP
:
1662 case M_PROPERTY_STEP_DOWN
:
1663 if(vo_config_count
) video_out
->control(vo_ctrl
, 0);
1666 return m_property_flag(prop
,action
,arg
,vo_var
);
1670 /// Window always on top (RW)
1671 static int mp_property_ontop(m_option_t
* prop
,int action
,void* arg
) {
1672 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ONTOP
,&vo_ontop
);
1675 /// Display in the root window (RW)
1676 static int mp_property_rootwin(m_option_t
* prop
,int action
,void* arg
) {
1677 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ROOTWIN
,&vo_rootwin
);
1680 /// Show window borders (RW)
1681 static int mp_property_border(m_option_t
* prop
,int action
,void* arg
) {
1682 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_BORDER
,&vo_border
);
1685 /// Framedropping state (RW)
1686 static int mp_property_framedropping(m_option_t
* prop
,int action
,void* arg
) {
1688 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1691 case M_PROPERTY_PRINT
:
1693 *(char**)arg
= strdup(frame_dropping
== 1 ? MSGTR_Enabled
:
1694 (frame_dropping
== 2 ? MSGTR_HardFrameDrop
: MSGTR_Disabled
));
1697 return m_property_choice(prop
,action
,arg
,&frame_dropping
);
1701 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1702 static int mp_property_gamma(m_option_t
* prop
,int action
,void* arg
) {
1703 int* gamma
= prop
->priv
, r
;
1705 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1707 if(gamma
[0] == 1000) {
1709 get_video_colors (sh_video
, prop
->name
, gamma
);
1713 case M_PROPERTY_SET
:
1715 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1716 *gamma
= *(int*)arg
;
1717 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
1720 case M_PROPERTY_GET
:
1722 r
= get_video_colors (sh_video
, prop
->name
, arg
);
1725 case M_PROPERTY_STEP_UP
:
1726 case M_PROPERTY_STEP_DOWN
:
1727 *gamma
+= (arg
? *(int*)arg
: 1) *
1728 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1729 M_PROPERTY_CLAMP(prop
,*gamma
);
1730 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
1734 return M_PROPERTY_NOT_IMPLEMENTED
;
1738 if(demuxer
->type
== DEMUXER_TYPE_TV
) {
1739 int l
= strlen(prop
->name
);
1740 char tv_prop
[3+l
+1];
1741 sprintf(tv_prop
,"tv_%s",prop
->name
);
1742 return mp_property_do(tv_prop
,action
,arg
);
1746 return M_PROPERTY_UNAVAILABLE
;
1750 static int mp_property_vsync(m_option_t
* prop
,int action
,void* arg
) {
1751 return m_property_flag(prop
,action
,arg
,&vo_vsync
);
1754 /// Video codec tag (RO)
1755 static int mp_property_video_format(m_option_t
* prop
,int action
,void* arg
) {
1756 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1757 return m_property_int_ro(prop
,action
,arg
,sh_video
->format
);
1760 /// Video bitrate (RO)
1761 static int mp_property_video_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1762 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1763 return m_property_int_ro(prop
,action
,arg
,sh_video
->i_bps
);
1766 /// Video display width (RO)
1767 static int mp_property_width(m_option_t
* prop
,int action
,void* arg
) {
1768 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1769 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_w
);
1772 /// Video display height (RO)
1773 static int mp_property_height(m_option_t
* prop
,int action
,void* arg
) {
1774 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1775 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_h
);
1779 static int mp_property_fps(m_option_t
* prop
,int action
,void* arg
) {
1780 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1781 return m_property_float_ro(prop
,action
,arg
,sh_video
->fps
);
1784 /// Video aspect (RO)
1785 static int mp_property_aspect(m_option_t
* prop
,int action
,void* arg
) {
1786 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1787 return m_property_float_ro(prop
,action
,arg
,sh_video
->aspect
);
1792 /// \defgroup SubProprties Subtitles properties
1793 /// \ingroup Properties
1796 /// Text subtitle position (RW)
1797 static int mp_property_sub_pos(m_option_t
* prop
,int action
,void* arg
) {
1799 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1802 case M_PROPERTY_SET
:
1804 case M_PROPERTY_STEP_UP
:
1805 case M_PROPERTY_STEP_DOWN
:
1806 vo_osd_changed(OSDTYPE_SUBTITLE
);
1808 return m_property_int_range(prop
,action
,arg
,&sub_pos
);
1811 return M_PROPERTY_UNAVAILABLE
;
1815 /// Selected subtitles (RW)
1816 static int mp_property_sub(m_option_t
* prop
,int action
,void* arg
) {
1817 int source
= -1, reset_spu
= 0;
1819 if(global_sub_size
<= 0) return M_PROPERTY_UNAVAILABLE
;
1822 case M_PROPERTY_GET
:
1824 *(int*)arg
= global_sub_pos
;
1826 case M_PROPERTY_PRINT
:
1828 *(char**)arg
= malloc(64);
1829 (*(char**)arg
)[63] = 0;
1833 tmp
= subdata
->filename
;
1834 if ((tmp2
= strrchr(tmp
, '/')))
1837 snprintf(*(char**)arg
, 63, "(%d) %s%s",
1839 strlen(tmp
) < 20 ? "" : "...",
1840 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
1844 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
&& dvdsub_id
>= 0) {
1845 char lang
[40] = MSGTR_Unknown
;
1846 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
1848 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
1851 #ifdef HAVE_OGGVORBIS
1852 if (demuxer
->type
== DEMUXER_TYPE_OGG
&& d_dvdsub
&& dvdsub_id
>= 0) {
1853 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
1854 if (!lang
) lang
= MSGTR_Unknown
;
1855 snprintf(*(char**)arg
, 63, "(%d) %s",
1860 if (vo_vobsub
&& vobsub_id
>= 0) {
1861 const char *language
= MSGTR_Unknown
;
1862 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
1863 snprintf(*(char**)arg
, 63, "(%d) %s",
1864 vobsub_id
, language
? language
: MSGTR_Unknown
);
1868 if (vo_spudec
&& dvdsub_id
>= 0) {
1869 char lang
[3] = "\0\0\0";
1871 code
= dvd_lang_from_sid(stream
, dvdsub_id
);
1873 lang
[0] = code
>> 8;
1877 snprintf(*(char**)arg
, 63, "(%d) %s",
1882 snprintf(*(char**)arg
, 63, MSGTR_Disabled
);
1885 case M_PROPERTY_SET
:
1887 if(*(int*)arg
< -1) *(int*)arg
= -1;
1888 else if(*(int*)arg
>= global_sub_size
) *(int*)arg
= global_sub_size
-1;
1889 global_sub_pos
= *(int*)arg
;
1891 case M_PROPERTY_STEP_UP
:
1892 global_sub_pos
+= 2;
1893 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
1895 case M_PROPERTY_STEP_DOWN
:
1896 global_sub_pos
+= global_sub_size
+1;
1897 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
1900 return M_PROPERTY_NOT_IMPLEMENTED
;
1903 if (global_sub_pos
>= 0)
1904 source
= sub_source();
1906 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
,
1907 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1908 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
1909 global_sub_indices
[SUB_SOURCE_SUBS
],
1910 global_sub_indices
[SUB_SOURCE_DEMUX
],
1911 global_sub_pos
, source
);
1914 set_of_sub_pos
= -1;
1916 vo_sub_last
= vo_sub
= NULL
;
1921 if(d_dvdsub
->id
> -2) reset_spu
= 1;
1925 if (source
== SUB_SOURCE_VOBSUB
) {
1926 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
1928 } else if (source
== SUB_SOURCE_SUBS
) {
1929 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
1930 subdata
= set_of_subtitles
[set_of_sub_pos
];
1931 vo_osd_changed(OSDTYPE_SUBTITLE
);
1933 } else if (source
== SUB_SOURCE_DEMUX
) {
1934 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
1937 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
1938 d_dvdsub
->id
= dvdsub_id
;
1939 spudec_reset(vo_spudec
);
1942 #ifdef HAVE_OGGVORBIS
1943 if (demuxer
->type
== DEMUXER_TYPE_OGG
)
1944 d_dvdsub
->id
= demux_ogg_sub_id(demuxer
, dvdsub_id
);
1946 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
1947 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
1948 if (d_dvdsub
->id
>= 0 &&
1949 ((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v') {
1950 mkv_sh_sub_t
*mkv_sh_sub
= (mkv_sh_sub_t
*)d_dvdsub
->sh
;
1951 if (vo_spudec
!= NULL
)
1952 spudec_free(vo_spudec
);
1954 spudec_new_scaled_vobsub(mkv_sh_sub
->has_palette
?
1955 mkv_sh_sub
->palette
:
1956 NULL
, mkv_sh_sub
->colors
,
1957 mkv_sh_sub
->custom_colors
,
1959 mkv_sh_sub
->height
);
1960 if (!forced_subs_only
)
1961 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1963 spudec_set_forced_subs_only(vo_spudec
,
1965 inited_flags
|= INITED_SPUDEC
;
1972 vo_osd_changed(OSDTYPE_SUBTITLE
);
1974 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
1977 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
&& dvdsub_id
< 0 && reset_spu
) {
1979 d_dvdsub
->id
= dvdsub_id
;
1980 spudec_reset(vo_spudec
);
1987 /// Subtitle delay (RW)
1988 static int mp_property_sub_delay(m_option_t
* prop
,int action
,void* arg
) {
1989 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1990 return m_property_delay(prop
,action
,arg
,&sub_delay
);
1993 /// Alignment of text subtitles (RW)
1994 static int mp_property_sub_alignment(m_option_t
* prop
,int action
,void* arg
) {
1996 char* name
[] = { MSGTR_Top
, MSGTR_Center
, MSGTR_Bottom
};
1998 if(!sh_video
|| global_sub_pos
< 0 || sub_source() != SUB_SOURCE_SUBS
)
1999 return M_PROPERTY_UNAVAILABLE
;
2002 case M_PROPERTY_PRINT
:
2004 M_PROPERTY_CLAMP(prop
,sub_alignment
);
2005 *(char**)arg
= strdup(name
[sub_alignment
]);
2007 case M_PROPERTY_SET
:
2009 case M_PROPERTY_STEP_UP
:
2010 case M_PROPERTY_STEP_DOWN
:
2011 vo_osd_changed(OSDTYPE_SUBTITLE
);
2013 return m_property_choice(prop
,action
,arg
,&sub_alignment
);
2016 return M_PROPERTY_UNAVAILABLE
;
2020 /// Subtitle visibility (RW)
2021 static int mp_property_sub_visibility(m_option_t
* prop
,int action
,void* arg
) {
2023 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2026 case M_PROPERTY_SET
:
2028 case M_PROPERTY_STEP_UP
:
2029 case M_PROPERTY_STEP_DOWN
:
2030 vo_osd_changed(OSDTYPE_SUBTITLE
);
2031 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2033 return m_property_flag(prop
,action
,arg
,&sub_visibility
);
2036 return M_PROPERTY_UNAVAILABLE
;
2040 /// Show only forced subtitles (RW)
2041 static int mp_property_sub_forced_only(m_option_t
* prop
,int action
,void* arg
) {
2042 if(!vo_spudec
) return M_PROPERTY_UNAVAILABLE
;
2045 case M_PROPERTY_SET
:
2047 case M_PROPERTY_STEP_UP
:
2048 case M_PROPERTY_STEP_DOWN
:
2049 m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2050 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
2053 return m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2060 /// \defgroup TVProperties TV properties
2061 /// \ingroup Properties
2066 /// TV color settings (RW)
2067 static int mp_property_tv_color(m_option_t
* prop
,int action
,void* arg
) {
2069 tvi_handle_t
* tvh
= demuxer
->priv
;
2070 if(demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
) return M_PROPERTY_UNAVAILABLE
;
2073 case M_PROPERTY_SET
:
2075 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2076 return tv_set_color_options(tvh
,(int)prop
->priv
,*(int*)arg
);
2077 case M_PROPERTY_GET
:
2078 return tv_get_color_options(tvh
,(int)prop
->priv
,arg
);
2079 case M_PROPERTY_STEP_UP
:
2080 case M_PROPERTY_STEP_DOWN
:
2081 if((r
= tv_get_color_options(tvh
,(int)prop
->priv
,&val
)) >= 0) {
2083 val
+= (arg
? *(int*)arg
: 1) *
2084 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2085 M_PROPERTY_CLAMP(prop
,val
);
2086 return tv_set_color_options(tvh
,(int)prop
->priv
,val
);
2090 return M_PROPERTY_NOT_IMPLEMENTED
;
2097 /// All properties available in MPlayer.
2098 /** \ingroup Properties
2100 static m_option_t mp_properties
[] = {
2102 { "osdlevel", mp_property_osdlevel
, CONF_TYPE_INT
,
2103 M_OPT_RANGE
, 0, 3, NULL
},
2104 { "speed", mp_property_playback_speed
, CONF_TYPE_FLOAT
,
2105 M_OPT_RANGE
, 0.01, 100.0, NULL
},
2106 { "filename", mp_property_filename
, CONF_TYPE_STRING
,
2108 { "path", mp_property_path
, CONF_TYPE_STRING
,
2110 { "demuxer", mp_property_demuxer
, CONF_TYPE_STRING
,
2112 { "stream_pos", mp_property_stream_pos
, CONF_TYPE_POSITION
,
2113 M_OPT_MIN
, 0, 0, NULL
},
2114 { "stream_start", mp_property_stream_start
, CONF_TYPE_POSITION
,
2115 M_OPT_MIN
, 0, 0, NULL
},
2116 { "stream_end", mp_property_stream_end
, CONF_TYPE_POSITION
,
2117 M_OPT_MIN
, 0, 0, NULL
},
2118 { "stream_length", mp_property_stream_length
, CONF_TYPE_POSITION
,
2119 M_OPT_MIN
, 0, 0, NULL
},
2120 { "length", mp_property_length
, CONF_TYPE_DOUBLE
,
2124 { "volume", mp_property_volume
, CONF_TYPE_FLOAT
,
2125 M_OPT_RANGE
, 0, 100, NULL
},
2126 { "mute", mp_property_mute
, CONF_TYPE_FLAG
,
2127 M_OPT_RANGE
, 0, 1, NULL
},
2128 { "audio_delay", mp_property_audio_delay
, CONF_TYPE_FLOAT
,
2129 M_OPT_RANGE
, -100, 100, NULL
},
2130 { "audio_format", mp_property_audio_format
, CONF_TYPE_INT
,
2132 { "audio_bitrate", mp_property_audio_bitrate
, CONF_TYPE_INT
,
2134 { "samplerate", mp_property_samplerate
, CONF_TYPE_INT
,
2136 { "channels", mp_property_channels
, CONF_TYPE_INT
,
2140 { "fullscreen", mp_property_fullscreen
, CONF_TYPE_FLAG
,
2141 M_OPT_RANGE
, 0, 1, NULL
},
2142 { "ontop", mp_property_ontop
, CONF_TYPE_FLAG
,
2143 M_OPT_RANGE
, 0, 1, NULL
},
2144 { "rootwin", mp_property_rootwin
, CONF_TYPE_FLAG
,
2145 M_OPT_RANGE
, 0, 1, NULL
},
2146 { "border", mp_property_border
, CONF_TYPE_FLAG
,
2147 M_OPT_RANGE
, 0, 1, NULL
},
2148 { "framedropping", mp_property_framedropping
, CONF_TYPE_INT
,
2149 M_OPT_RANGE
, 0, 2, NULL
},
2150 { "gamma", mp_property_gamma
, CONF_TYPE_INT
,
2151 M_OPT_RANGE
, -100, 100, &vo_gamma_gamma
},
2152 { "brightness", mp_property_gamma
, CONF_TYPE_INT
,
2153 M_OPT_RANGE
, -100, 100, &vo_gamma_brightness
},
2154 { "contrast", mp_property_gamma
, CONF_TYPE_INT
,
2155 M_OPT_RANGE
, -100, 100, &vo_gamma_contrast
},
2156 { "saturation", mp_property_gamma
, CONF_TYPE_INT
,
2157 M_OPT_RANGE
, -100, 100, &vo_gamma_saturation
},
2158 { "hue", mp_property_gamma
, CONF_TYPE_INT
,
2159 M_OPT_RANGE
, -100, 100, &vo_gamma_hue
},
2160 { "panscan", mp_property_panscan
, CONF_TYPE_FLOAT
,
2161 M_OPT_RANGE
, 0, 1, NULL
},
2162 { "vsync", mp_property_vsync
, CONF_TYPE_FLAG
,
2163 M_OPT_RANGE
, 0, 1, NULL
},
2164 { "video_format", mp_property_video_format
, CONF_TYPE_INT
,
2166 { "video_bitrate", mp_property_video_bitrate
, CONF_TYPE_INT
,
2168 { "width", mp_property_width
, CONF_TYPE_INT
,
2170 { "height", mp_property_height
, CONF_TYPE_INT
,
2172 { "fps", mp_property_fps
, CONF_TYPE_FLOAT
,
2174 { "aspect", mp_property_aspect
, CONF_TYPE_FLOAT
,
2178 { "sub", mp_property_sub
, CONF_TYPE_INT
,
2179 M_OPT_MIN
, -1, 0, NULL
},
2180 { "sub_delay", mp_property_sub_delay
, CONF_TYPE_FLOAT
,
2182 { "sub_pos", mp_property_sub_pos
, CONF_TYPE_INT
,
2183 M_OPT_RANGE
, 0, 100, NULL
},
2184 { "sub_alignment", mp_property_sub_alignment
, CONF_TYPE_INT
,
2185 M_OPT_RANGE
, 0, 2, NULL
},
2186 { "sub_visibility", mp_property_sub_visibility
, CONF_TYPE_FLAG
,
2187 M_OPT_RANGE
, 0, 1, NULL
},
2188 { "sub_forced_only", mp_property_sub_forced_only
, CONF_TYPE_FLAG
,
2189 M_OPT_RANGE
, 0, 1, NULL
},
2192 { "tv_brightness", mp_property_tv_color
, CONF_TYPE_INT
,
2193 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_BRIGHTNESS
},
2194 { "tv_contrast", mp_property_tv_color
, CONF_TYPE_INT
,
2195 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_CONTRAST
},
2196 { "tv_saturation", mp_property_tv_color
, CONF_TYPE_INT
,
2197 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_SATURATION
},
2198 { "tv_hue", mp_property_tv_color
, CONF_TYPE_INT
,
2199 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_HUE
},
2202 { NULL
, NULL
, NULL
, 0, 0, 0, NULL
}
2205 m_option_t
* mp_property_find(char* name
) {
2206 return m_option_list_find(mp_properties
,name
);
2209 int mp_property_do(char* name
,int action
, void* val
) {
2210 m_option_t
* p
= mp_property_find(name
);
2211 if(!p
) return M_PROPERTY_UNAVAILABLE
;
2212 return m_property_do(p
,action
,val
);
2220 * \defgroup Command2Property Command to property bridge
2222 * It is used to handle most commands that just set a property
2223 * and optionally display something on the OSD.
2224 * Two kinds of commands are handled: adjust or toggle.
2226 * Adjust commands take 1 or 2 parameters: <value> <abs>
2227 * If <abs> is non-zero the property is set to the given value
2228 * otherwise it is adjusted.
2230 * Toggle commands take 0 or 1 parameters. With no parameter
2231 * or a value less than the property minimum it just steps the
2232 * property to its next value. Otherwise it sets it to the given
2238 /// List of the commands that can be handled by setting a property.
2244 /// set/adjust or toggle command
2246 /// progressbar type
2248 /// osd msg id if it must be shared
2250 /// osd msg template
2252 } set_prop_cmd
[] = {
2254 { "volume", MP_CMD_VOLUME
, 0, OSD_VOLUME
, -1, MSGTR_Volume
},
2255 { "mute", MP_CMD_MUTE
, 1, 0, -1, MSGTR_MuteStatus
},
2256 { "audio_delay", MP_CMD_AUDIO_DELAY
, 0, 0, -1, MSGTR_AVDelayStatus
},
2258 { "fullscreen", MP_CMD_VO_FULLSCREEN
, 1, 0, -1, NULL
},
2259 { "panscan", MP_CMD_PANSCAN
, 0, OSD_PANSCAN
, -1, MSGTR_Panscan
},
2260 { "ontop", MP_CMD_VO_ONTOP
, 1, 0, -1, MSGTR_OnTopStatus
},
2261 { "rootwin", MP_CMD_VO_ROOTWIN
, 1, 0, -1, MSGTR_RootwinStatus
},
2262 { "border", MP_CMD_VO_BORDER
, 1, 0, -1, MSGTR_BorderStatus
},
2263 { "framedropping", MP_CMD_FRAMEDROPPING
, 1, 0, -1, MSGTR_FramedroppingStatus
},
2264 { "gamma", MP_CMD_GAMMA
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Gamma
},
2265 { "brightness", MP_CMD_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2266 { "contrast", MP_CMD_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2267 { "saturation", MP_CMD_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2268 { "hue", MP_CMD_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2269 { "vsync", MP_CMD_SWITCH_VSYNC
, 1, 0, -1, MSGTR_VSyncStatus
},
2271 { "sub", MP_CMD_SUB_SELECT
, 1, 0, -1, MSGTR_SubSelectStatus
},
2272 { "sub_pos", MP_CMD_SUB_POS
, 0, 0, -1, MSGTR_SubPosStatus
},
2273 { "sub_alignment", MP_CMD_SUB_ALIGNMENT
, 1, 0, -1, MSGTR_SubAlignStatus
},
2274 { "sub_delay", MP_CMD_SUB_DELAY
, 0, 0, OSD_MSG_SUB_DELAY
, MSGTR_SubDelayStatus
},
2275 { "sub_visibility", MP_CMD_SUB_VISIBILITY
, 1, 0, -1, MSGTR_SubVisibleStatus
},
2276 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY
, 1, 0, -1, MSGTR_SubForcedOnlyStatus
},
2278 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2279 { "tv_hue", MP_CMD_TV_SET_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2280 { "tv_saturation", MP_CMD_TV_SET_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2281 { "tv_contrast", MP_CMD_TV_SET_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2283 { NULL
, 0, 0, 0, -1, NULL
}
2286 /// Handle commands that set a property.
2287 static int set_property_command(mp_cmd_t
* cmd
) {
2291 // look for the command
2292 for(i
= 0 ; set_prop_cmd
[i
].name
; i
++)
2293 if(set_prop_cmd
[i
].cmd
== cmd
->id
) break;
2294 if(!set_prop_cmd
[i
].name
) return 0;
2297 prop
= mp_property_find(set_prop_cmd
[i
].name
);
2301 if(set_prop_cmd
[i
].toggle
) {
2303 if(cmd
->nargs
> 0 && cmd
->args
[0].v
.i
>= prop
->min
)
2304 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
.i
);
2306 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,NULL
);
2307 } else if(cmd
->args
[1].v
.i
) //set
2308 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
);
2310 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,&cmd
->args
[0].v
);
2312 if(r
<= 0) return 1;
2314 if(set_prop_cmd
[i
].osd_progbar
) {
2315 if(prop
->type
== CONF_TYPE_INT
) {
2316 if(m_property_do(prop
,M_PROPERTY_GET
,&r
) > 0)
2317 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2318 set_prop_cmd
[i
].osd_msg
,
2319 prop
->min
,prop
->max
,r
);
2320 } else if(prop
->type
== CONF_TYPE_FLOAT
) {
2322 if(m_property_do(prop
,M_PROPERTY_GET
,&f
) > 0)
2323 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,set_prop_cmd
[i
].osd_msg
,
2324 prop
->min
,prop
->max
,f
);
2326 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "Property use an unsupported type.\n");
2330 if(set_prop_cmd
[i
].osd_msg
) {
2331 char* val
= m_property_print(prop
);
2333 set_osd_msg(set_prop_cmd
[i
].osd_id
>= 0 ? set_prop_cmd
[i
].osd_id
:
2334 OSD_MSG_PROPERTY
+i
,1,osd_duration
,
2335 set_prop_cmd
[i
].osd_msg
,val
);
2345 int main(int argc
,char* argv
[]){
2350 int file_format
=DEMUXER_TYPE_UNKNOWN
;
2358 /* Flag indicating whether MPlayer should exit without playing anything. */
2361 //float a_frame=0; // Audio
2366 int gui_no_filename
=0;
2369 srand((int) time(NULL
));
2375 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2006 MPlayer Team\n");
2376 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2377 GetCpuCaps(&gCpuCaps
);
2378 #if defined(ARCH_X86) || defined(ARCH_X86_64)
2379 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2380 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
2381 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
2382 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
2383 #ifdef RUNTIME_CPUDETECT
2384 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
2386 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
2388 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
2391 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
2394 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
2397 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
2400 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
2403 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
2405 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
2406 #endif /* RUNTIME_CPUDETECT */
2407 #endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */
2409 #if defined(WIN32) && defined(USE_WIN32DLL)
2411 #endif /*WIN32 && USE_WIN32DLL*/
2414 tv_param_immediate
= 1;
2418 if(!strcmp(argv
[0],"gmplayer") ||
2419 (strrchr(argv
[0],'/') && !strcmp(strrchr(argv
[0],'/'),"/gmplayer") ) )
2422 mconfig
= m_config_new();
2423 m_config_register_options(mconfig
,mplayer_opts
);
2424 // TODO : add something to let modules register their options
2425 mp_input_register_options(mconfig
);
2426 parse_cfgfiles(mconfig
);
2429 if ( use_gui
) cfg_read();
2432 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
2433 if(playtree
== NULL
)
2436 playtree
= play_tree_cleanup(playtree
);
2438 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
2440 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2441 play_tree_iter_free(playtree_iter
);
2442 playtree_iter
= NULL
;
2444 filename
= play_tree_iter_get_file(playtree_iter
,1);
2452 for(i
=0; priority_presets_defs
[i
].name
; i
++){
2453 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
2456 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
2457 priority_presets_defs
[i
].name
);
2458 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
2461 #ifndef HAVE_NEW_GUI
2463 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
2467 if(use_gui
&& !vo_init()){
2468 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
2471 if (use_gui
&& playtree_iter
){
2472 char cwd
[PATH_MAX
+2];
2473 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2474 play_tree_iter_free(playtree_iter
);
2477 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
2480 // Prefix relative paths with current working directory
2481 play_tree_add_bpf(playtree
, cwd
);
2483 // Import initital playtree into GUI.
2484 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
2486 #endif /* HAVE_NEW_GUI */
2488 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
2493 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
2498 /* Check codecs.conf. */
2499 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2500 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2501 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2502 if(!parse_codec_cfg(NULL
)){
2503 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
2504 exit_player_with_rc(NULL
, 0);
2506 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
2509 free( mem_ptr
); // release the buffer created by get_path()
2513 if(video_codec_list
){
2515 video_codec
=video_codec_list
[0];
2516 for(i
=0;video_codec_list
[i
];i
++)
2517 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2520 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2521 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
2522 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2524 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2527 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2528 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
2529 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2531 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2534 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2536 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2539 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
2541 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2544 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
2550 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
2552 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2556 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
2557 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
2558 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
2560 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2563 if(list_properties
) {
2564 m_properties_print_help_list(mp_properties
);
2571 if (player_idle_mode
&& use_gui
) {
2572 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
2573 exit_player_with_rc(NULL
, 1);
2576 if(!filename
&& !player_idle_mode
){
2578 // no file/vcd/dvd -> show HELP:
2579 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
2580 exit_player_with_rc(NULL
, 0);
2581 } else gui_no_filename
=1;
2584 // Many users forget to include command line in bugreports...
2585 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
2586 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
2587 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
2588 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2591 //------ load global data first ------
2595 #ifdef HAVE_FREETYPE
2598 #ifdef HAVE_FONTCONFIG
2599 if(!font_fontconfig
)
2603 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
2604 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
2607 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
2608 free(mem_ptr
); // release the buffer created by get_path()
2610 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
2612 #ifdef HAVE_FONTCONFIG
2615 #endif /* USE_OSD */
2621 // seteuid(0); /* Can't hurt to try to get root here */
2622 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
2623 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
2624 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
2626 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
2628 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
2629 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
2630 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
2633 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
2634 /* variable only by the root */
2635 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
2639 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
2643 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2644 // and now ? -- Pontscho
2645 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
2648 #endif /* HAVE_RTC */
2649 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
2650 softsleep
?"software":timer_name
);
2653 if ( !use_gui
) load_termcap(NULL
); // load key-codes
2656 // ========== Init keyboard FIFO (connection to libvo) ============
2658 // Init input system
2659 current_module
= "init_input";
2660 mp_input_init(use_gui
);
2662 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
2664 if(keyb_fifo_get
> 0)
2665 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
2667 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
2671 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
2673 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
2675 else if(!noconsolecontrols
)
2676 #ifndef HAVE_NO_POSIX_SELECT
2677 mp_input_add_key_fd(0,1,NULL
,NULL
);
2679 mp_input_add_key_fd(0,0,NULL
,NULL
);
2682 inited_flags
|=INITED_INPUT
;
2683 current_module
= NULL
;
2687 if(menu_cfg
&& menu_init(menu_cfg
))
2688 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2690 menu_cfg
= get_path("menu.conf");
2691 if(menu_init(menu_cfg
))
2692 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2694 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
2695 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
2697 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
2707 signal(SIGCHLD
,child_sighandler
);
2711 prog_path
= argv
[0];
2713 //========= Catch terminate signals: ================
2714 // terminate requests:
2715 signal(SIGTERM
,exit_sighandler
); // kill
2716 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
2718 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
2720 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
2721 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
2722 #ifdef ENABLE_SIGHANDLER
2724 signal(SIGBUS
,exit_sighandler
); // bus error
2725 signal(SIGSEGV
,exit_sighandler
); // segfault
2726 signal(SIGILL
,exit_sighandler
); // illegal instruction
2727 signal(SIGFPE
,exit_sighandler
); // floating point exc.
2728 signal(SIGABRT
,exit_sighandler
); // abort()
2731 signal(SIGTRAP
,exit_sighandler
);
2738 inited_flags
|=INITED_GUI
;
2739 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
2743 // ******************* Now, let's see the per-file stuff ********************
2747 // init global sub numbers
2748 global_sub_size
= 0;
2749 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
2751 if (filename
) load_per_file_config (mconfig
, filename
);
2753 // We must enable getch2 here to be able to interrupt network connection
2755 if(!noconsolecontrols
&& !slave_mode
){
2756 if(inited_flags
&INITED_GETCH2
)
2757 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
2759 getch2_enable(); // prepare stdin for hotkeys...
2760 inited_flags
|=INITED_GETCH2
;
2761 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
2764 // =================== GUI idle loop (STOP state) ===========================
2767 file_format
=DEMUXER_TYPE_UNKNOWN
;
2768 guiGetEvent( guiSetDefaults
,0 );
2769 while ( guiIntfStruct
.Playing
!= 1 )
2774 guiGetEvent( guiReDraw
,NULL
);
2775 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
2777 guiGetEvent( guiSetParameters
,NULL
);
2778 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
2780 play_tree_t
* entry
= play_tree_new();
2781 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
2782 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
2783 else playtree
=play_tree_new();
2784 play_tree_set_child( playtree
,entry
);
2787 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
2790 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
2792 play_tree_iter_free(playtree_iter
);
2793 playtree_iter
= NULL
;
2795 filename
= play_tree_iter_get_file(playtree_iter
,1);
2800 #endif /* HAVE_NEW_GUI */
2802 while (player_idle_mode
&& !filename
) {
2803 play_tree_t
* entry
= NULL
;
2805 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
2806 if (video_out
&& vo_config_count
) video_out
->check_events();
2810 case MP_CMD_LOADFILE
:
2811 // prepare a tree entry with the new filename
2812 entry
= play_tree_new();
2813 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
2814 // The entry is added to the main playtree after the switch().
2816 case MP_CMD_LOADLIST
:
2817 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
2820 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
2826 if (entry
) { // user entered a command that gave a valid entry
2827 if (playtree
) // the playtree is always a node with one child. let's clear it
2828 play_tree_free_list(playtree
->child
, 1);
2829 else playtree
=play_tree_new(); // .. or make a brand new playtree
2831 if (!playtree
) continue; // couldn't make playtree! wait for next command
2833 play_tree_set_child(playtree
, entry
);
2835 /* Make iterator start at the top the of tree. */
2836 playtree_iter
= play_tree_iter_new(playtree
, mconfig
);
2837 if (!playtree_iter
) continue;
2839 // find the first real item in the tree
2840 if (play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2842 play_tree_iter_free(playtree_iter
);
2843 playtree_iter
= NULL
;
2844 continue; // wait for next command
2846 filename
= play_tree_iter_get_file(playtree_iter
, 1);
2849 //---------------------------------------------------------------------------
2851 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
2854 if (edl_records
) free_edl(edl_records
);
2855 next_edl_record
= edl_records
= edl_parse_file();
2857 if (edl_output_filename
) {
2858 if (edl_fd
) fclose(edl_fd
);
2859 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
2861 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
2862 edl_output_filename
);
2866 //==================== Open VOB-Sub ============================
2868 current_module
="vobsub";
2870 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
2872 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
2873 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
2874 /* try to autodetect vobsub from movie filename ::atmos */
2875 char *buf
= malloc((strlen(filename
)-3) * sizeof(char)),*psub
;
2876 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
2877 strncpy(buf
, filename
, strlen(filename
)-4);
2878 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
2879 /* try from ~/.mplayer/sub */
2880 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
2883 bname
= strrchr(buf
,'/');
2885 if(!bname
) bname
= strrchr(buf
,'\\');
2889 l
= strlen(psub
) + strlen(bname
) + 1;
2890 psub
= realloc(psub
,l
);
2892 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
2898 inited_flags
|=INITED_VOBSUB
;
2899 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
2900 // check if vobsub requested only to display forced subtitles
2901 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
2903 // setup global sub numbering
2904 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
2905 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
2908 //============ Open & Sync STREAM --- fork cache2 ====================
2913 //free_demuxer_stream(d_audio);
2917 //free_demuxer_stream(d_video);
2923 current_module
="open_stream";
2924 stream
=open_stream(filename
,0,&file_format
);
2925 if(!stream
) { // error...
2926 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
2927 goto goto_next_file
;
2929 inited_flags
|=INITED_STREAM
;
2932 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
2935 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
2938 current_module
="handle_playlist";
2939 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
2940 entry
= parse_playtree(stream
,0);
2941 eof
=playtree_add_playlist(entry
);
2942 goto goto_next_file
;
2944 stream
->start_pos
+=seek_to_byte
;
2946 if(stream_dump_type
==5){
2947 unsigned char buf
[4096];
2950 current_module
="dumpstream";
2951 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
2952 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
2953 exit_player(MSGTR_Exit_error
);
2955 stream_reset(stream
);
2956 stream_seek(stream
,stream
->start_pos
);
2957 f
=fopen(stream_dump_name
,"wb");
2959 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
2960 exit_player(MSGTR_Exit_error
);
2962 while(!stream
->eof
){
2963 len
=stream_read(stream
,buf
,4096);
2965 if(fwrite(buf
,len
,1,f
) != 1) {
2966 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2967 exit_player(MSGTR_Exit_error
);
2972 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2973 exit_player(MSGTR_Exit_error
);
2975 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
2976 exit_player_with_rc(MSGTR_Exit_eof
, 0);
2980 if(stream
->type
==STREAMTYPE_DVD
){
2981 current_module
="dvd lang->id";
2982 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
2983 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
2984 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
2985 // setup global sub numbering
2986 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
2987 global_sub_size
+= dvd_number_of_subs(stream
);
2988 current_module
=NULL
;
2993 if (stream
->type
==STREAMTYPE_DVDNAV
) stream_cache_size
=0; // must disable caching...
2996 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
2997 #ifdef HAS_DVBIN_SUPPORT
3000 if(stream_cache_size
>0){
3001 current_module
="enable_cache";
3002 if(!stream_enable_cache(stream
,stream_cache_size
*1024,
3003 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3004 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
3005 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
3008 //============ Open DEMUXERS --- DETECT file type =======================
3009 current_module
="demux_open";
3011 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
3013 // HACK to get MOV Reference Files working
3015 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3017 unsigned char* playlist_entry
;
3018 play_tree_t
*list
= NULL
, *entry
= NULL
;
3020 current_module
="handle_demux_playlist";
3021 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
3025 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",playlist_entry
);
3027 bname
=mp_basename(playlist_entry
);
3028 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3031 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
3034 entry
= play_tree_new();
3036 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3038 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1)*sizeof(char));
3041 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
3042 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
3043 strcat(temp
, playlist_entry
);
3044 play_tree_add_file(entry
,temp
);
3045 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3050 play_tree_add_file(entry
,playlist_entry
);
3055 play_tree_append_entry(list
,entry
);
3057 free_demuxer(demuxer
);
3062 entry
= play_tree_new();
3063 play_tree_set_child(entry
,list
);
3064 eof
=playtree_add_playlist(entry
);
3065 goto goto_next_file
;
3074 current_module
="handle_playlist";
3075 switch(stream
->type
){
3076 case STREAMTYPE_VCD
:
3077 case STREAMTYPE_DVD
:
3078 case STREAMTYPE_DVDNAV
:
3079 case STREAMTYPE_CDDA
:
3080 case STREAMTYPE_VCDBINCUE
:
3081 // don't try to parse raw media as playlist, it's unlikely
3082 goto goto_next_file
;
3084 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
3085 stream_reset(stream
);
3086 stream_seek(stream
,stream
->start_pos
);
3087 entry
= parse_playtree(stream
,0);
3089 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
3091 eof
=playtree_add_playlist(entry
);
3093 goto goto_next_file
;
3095 inited_flags
|=INITED_DEMUXER
;
3097 if (demuxer
->type
==DEMUXER_TYPE_MATROSKA
) {
3098 // setup global sub numbering
3099 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3100 global_sub_size
+= demux_mkv_num_subs(demuxer
);
3102 #ifdef HAVE_OGGVORBIS
3103 if (demuxer
->type
==DEMUXER_TYPE_OGG
) {
3104 // setup global sub numbering
3105 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3106 global_sub_size
+= demux_ogg_num_subs(demuxer
);
3110 current_module
="demux_open2";
3112 //file_format=demuxer->file_format;
3114 d_audio
=demuxer
->audio
;
3115 d_video
=demuxer
->video
;
3116 d_dvdsub
=demuxer
->sub
;
3119 if((stream_dump_type
)&&(stream_dump_type
<4)){
3121 demux_stream_t
*ds
=NULL
;
3122 current_module
="dump";
3123 // select stream to dump
3124 switch(stream_dump_type
){
3125 case 1: ds
=d_audio
;break;
3126 case 2: ds
=d_video
;break;
3127 case 3: ds
=d_dvdsub
;break;
3130 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
3131 exit_player(MSGTR_Exit_error
);
3133 // disable other streams:
3134 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
3135 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
3136 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
3138 f
=fopen(stream_dump_name
,"wb");
3140 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3141 exit_player(MSGTR_Exit_error
);
3144 unsigned char* start
;
3145 int in_size
=ds_get_packet(ds
,&start
);
3146 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3147 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3148 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3151 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3152 exit_player_with_rc(MSGTR_Exit_eof
, 0);
3155 sh_audio
=d_audio
->sh
;
3156 sh_video
=d_video
->sh
;
3160 current_module
="video_read_properties";
3161 if(!video_read_properties(sh_video
)) {
3162 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
3163 sh_video
=d_video
->sh
=NULL
;
3165 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3166 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
3167 sh_video
->fps
,sh_video
->frametime
3170 /* need to set fps here for output encoders to pick it up in their init */
3172 sh_video
->fps
=force_fps
;
3173 sh_video
->frametime
=1.0f
/sh_video
->fps
;
3175 vo_fps
= sh_video
->fps
;
3177 if(!sh_video
->fps
&& !force_fps
){
3178 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
3179 sh_video
=d_video
->sh
=NULL
;
3187 if(!sh_video
&& !sh_audio
){
3188 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
3189 #ifdef HAS_DVBIN_SUPPORT
3190 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
3192 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
3196 int v
= last_dvb_step
;
3198 dir
= DVB_CHANNEL_HIGHER
;
3200 dir
= DVB_CHANNEL_LOWER
;
3202 if(dvb_step_channel(priv
, dir
))
3203 eof
= dvbin_reopen
= 1;
3207 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3210 /* display clip info */
3211 demux_info_print(demuxer
);
3213 //================== Read SUBTITLES (DVD & TEXT) ==========================
3214 if(vo_spudec
==NULL
&& sh_video
&&
3215 (stream
->type
==STREAMTYPE_DVD
|| demuxer
->type
==DEMUXER_TYPE_MATROSKA
||
3216 d_dvdsub
->id
>= 0)){
3219 unsigned int palette
[16], width
, height
;
3220 current_module
="spudec_init_vobsub";
3221 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
3222 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
3226 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
3227 current_module
="spudec_init_dvdnav";
3228 vo_spudec
=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t
*)(stream
->priv
)),
3229 sh_video
->disp_w
, sh_video
->disp_h
);
3234 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
3235 current_module
="spudec_init_dvdread";
3236 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
3237 sh_video
->disp_w
, sh_video
->disp_h
);
3241 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
3242 (d_dvdsub
->sh
!= NULL
) && (((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
3243 mkv_sh_sub_t
*mkv_sh_sub
= (mkv_sh_sub_t
*)d_dvdsub
->sh
;
3244 current_module
= "spudec_init_matroska";
3246 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
3247 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
3248 mkv_sh_sub
->height
);
3249 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
3252 if (vo_spudec
==NULL
) {
3253 current_module
="spudec_init_normal";
3254 vo_spudec
=spudec_new_scaled(NULL
, sh_video
->disp_w
, sh_video
->disp_h
);
3255 spudec_set_font_factor(vo_spudec
,font_factor
);
3258 if (vo_spudec
!=NULL
)
3259 inited_flags
|=INITED_SPUDEC
;
3263 // Apply current settings for forced subs
3264 if (vo_spudec
!=NULL
)
3265 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3269 // after reading video params we should load subtitles because
3270 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3272 current_module
="read_subtitles_file";
3274 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3275 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
3277 if(sub_auto
) { // auto load sub file ...
3278 char *psub
= get_path( "sub/" );
3279 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
3281 free(psub
); // release the buffer created by get_path() above
3283 add_subtitles (tmp
[i
], sh_video
->fps
, 0);
3288 if (set_of_sub_size
> 0) {
3289 // setup global sub numbering
3290 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
3291 global_sub_size
+= set_of_sub_size
;
3294 #endif /* USE_SUB */
3296 if (global_sub_size
) {
3297 // find the best sub to use
3298 if (vobsub_id
>= 0) {
3299 // if user asks for a vobsub id, use that first.
3300 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
3301 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3302 // if user asks for a dvd sub id, use that next.
3303 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
3304 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
3305 // if there are text subs to use, use those. (autosubs come last here)
3306 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
3308 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
3309 // if nothing else works, get subs from the demuxer.
3310 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
3313 // nothing worth doing automatically.
3314 global_sub_pos
= -1;
3316 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3318 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
);
3320 switch (stream_dump_type
) {
3321 case 3: list_sub_file(subdata
); break;
3322 case 4: dump_mpsub(subdata
, sh_video
->fps
); break;
3323 case 6: dump_srt(subdata
, sh_video
->fps
); break;
3324 case 7: dump_microdvd(subdata
, sh_video
->fps
); break;
3325 case 8: dump_jacosub(subdata
, sh_video
->fps
); break;
3326 case 9: dump_sami(subdata
, sh_video
->fps
); break;
3330 //================== Init AUDIO (codec) ==========================
3332 /* Go through codecs.conf and find the best codec... */
3333 current_module
="init_audio_codec";
3334 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3335 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
3336 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
3338 inited_flags
|=INITED_ACODEC
;
3339 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3342 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
3343 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", demuxer
->desc
->name
);
3345 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3346 if (sh_video
->format
>= 0x20202020)
3347 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video
->format
);
3349 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
3350 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
3351 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
3352 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
3353 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
3354 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
3357 if (sh_audio
->codec
)
3358 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
3359 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3360 if (sh_audio
->format
>= 0x20202020)
3361 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio
->format
);
3363 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
3364 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
3365 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
3366 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
3368 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
3370 if(!sh_video
) goto main
; // audio-only
3372 //================== Init VIDEO (codec & libvo) ==========================
3373 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
3374 current_module
="preinit_libvo";
3377 //if((video_out->preinit(vo_subdevice))!=0){
3378 if(!(video_out
=init_best_video_out(video_driver_list
))){
3379 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
3380 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3382 sh_video
->video_out
=video_out
;
3383 inited_flags
|=INITED_VO
;
3386 current_module
="init_video_filters";
3388 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
3389 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
3393 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
3394 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
3396 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
3401 sh_video
->vfilter
=(void*)append_filters(vf_menu
);
3404 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
3406 current_module
="init_video_codec";
3408 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3409 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
3410 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3412 if(!sh_video
->inited
){
3413 if(!fixed_vo
) uninit_player(INITED_VO
);
3414 if(!sh_audio
) goto goto_next_file
;
3415 sh_video
= d_video
->sh
= NULL
;
3416 goto main
; // exit_player(MSGTR_Exit_error);
3419 inited_flags
|=INITED_VCODEC
;
3421 if (sh_video
->codec
)
3422 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
3425 // Auto quality option enabled
3426 output_quality
=get_video_quality_max(sh_video
);
3427 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
3428 else output_quality
=auto_quality
;
3429 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
3430 set_video_quality(sh_video
,output_quality
);
3433 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3435 current_module
="init_vo";
3437 if(vo_flags
& 0x08 && vo_spudec
)
3438 spudec_set_hw_spu(vo_spudec
,video_out
);
3440 #ifdef HAVE_FREETYPE
3441 force_load_font
= 1;
3444 //================== MAIN: ==========================
3446 current_module
="main";
3449 char* msg
= m_properties_expand_string(mp_properties
,playing_msg
);
3450 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3455 // Disable the term OSD in verbose mode
3456 if(verbose
) term_osd
= 0;
3462 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
3463 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
3464 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
3465 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
3466 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
3471 //int frame_corr_num=0; //
3472 //float v_frame=0; // Video
3473 float time_frame
=0; // Timer
3474 //float num_frames=0; // number of frames played
3476 int drop_frame
=0; // current dropping status
3477 int dropped_frames
=0; // how many frames dropped since last non-dropped frame
3478 int too_slow_frame_cnt
=0;
3479 int too_fast_frame_cnt
=0;
3480 // for auto-quality:
3481 float AV_delay
=0; // average of A-V timestamp differences
3482 double vdecode_time
;
3483 unsigned int lastframeout_ts
=0;
3484 /*float time_frame_corr_avg=0;*/ /* unused */
3486 float next_frame_time
=0;
3487 int frame_time_remaining
=0; // flag
3491 // Make sure old OSD does not stay around,
3492 // e.g. with -fixed-vo and same-resolution files
3496 //================ SETUP AUDIO ==========================
3499 //const ao_info_t *info=audio_out->info;
3500 current_module
="af_preinit";
3501 ao_data
.samplerate
=force_srate
;
3503 ao_data
.format
=audio_output_format
;
3505 // first init to detect best values
3506 if(!preinit_audio_filters(sh_audio
,
3508 (int)(sh_audio
->samplerate
*playback_speed
),
3509 sh_audio
->channels
, sh_audio
->sample_format
,
3511 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
3512 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
3513 exit_player(MSGTR_Exit_error
);
3516 current_module
="ao2_init";
3517 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
3521 ao_data
.format
,0))){
3523 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
3524 uninit_player(INITED_ACODEC
); // close codec
3525 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
3528 inited_flags
|=INITED_AO
;
3529 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
3530 audio_out
->info
->short_name
,
3531 ao_data
.samplerate
, ao_data
.channels
,
3532 af_fmt2str_short(ao_data
.format
),
3533 af_fmt2bits(ao_data
.format
)/8 );
3534 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
3535 audio_out
->info
->name
, audio_out
->info
->author
);
3536 if(strlen(audio_out
->info
->comment
) > 0)
3537 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
3538 // init audio filters:
3540 current_module
="af_init";
3541 if(!build_afilter_chain(sh_audio
, &ao_data
)) {
3542 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
3543 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
3544 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
3545 // sh_audio=d_audio->sh=NULL; // -> nosound
3549 mixer
.audio_out
= audio_out
;
3550 mixer
.volstep
= volstep
;
3553 current_module
="av_init";
3558 audio_delay
+= sh_video
->stream_delay
;
3562 audio_delay
-= sh_audio
->stream_delay
;
3563 sh_audio
->delay
=-audio_delay
;
3567 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
3568 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",d_audio
->packs
);
3569 ds_free_packs(d_audio
); // free buffered chunks
3570 d_audio
->id
=-2; // do not read audio chunks
3571 //uninit_player(INITED_AO); // close device
3574 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
3575 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",d_video
->packs
);
3576 ds_free_packs(d_video
);
3578 //if(!fixed_vo) uninit_player(INITED_VO);
3581 if (!sh_video
&& !sh_audio
)
3582 goto goto_next_file
;
3584 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3585 if(force_fps
&& sh_video
){
3586 vo_fps
= sh_video
->fps
=force_fps
;
3587 sh_video
->frametime
=1.0f
/sh_video
->fps
;
3588 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
3591 //==================== START PLAYING =======================
3593 if(loop_times
>1) loop_times
--; else
3594 if(loop_times
==1) loop_times
= -1;
3596 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
3599 if (stream
->type
==STREAMTYPE_DVDNAV
) {
3600 dvdnav_stream_fullstart((dvdnav_priv_t
*)stream
->priv
);
3604 total_time_usage_start
=GetTimer();
3605 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3606 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3607 play_n_frames
=play_n_frames_mf
;
3609 if(play_n_frames
==0){
3610 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
3614 float aq_sleep_time
=0;
3616 /*========================== PLAY AUDIO ============================*/
3623 current_module
="play_audio";
3625 ao_data
.pts
=((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3626 playsize
=audio_out
->get_space();
3628 // handle audio-only case:
3629 if(playsize
< ao_data
.outburst
&&
3630 !sh_video
) { // buffer is full, do not block here!!!
3631 usec_sleep(10000); // Wait a tick before retry
3635 if(playsize
>MAX_OUTBURST
) playsize
=MAX_OUTBURST
; // we shouldn't exceed it!
3637 // Fill buffer if needed:
3638 current_module
="decode_audio"; // Enter AUDIO decoder module
3640 while(sh_audio
->a_out_buffer_len
<playsize
&&
3641 (!d_audio
->eof
|| sh_audio
->a_in_buffer_len
> 0 || sh_audio
->a_buffer_len
> 0)){
3642 int ret
=decode_audio(sh_audio
,&sh_audio
->a_out_buffer
[sh_audio
->a_out_buffer_len
],
3643 playsize
-sh_audio
->a_out_buffer_len
,sh_audio
->a_out_buffer_size
-sh_audio
->a_out_buffer_len
);
3644 if(ret
<=0) { // EOF?
3646 sh_audio
->a_in_buffer_len
= 0; // make sure we don't hang if something's broken
3649 sh_audio
->a_out_buffer_len
+=ret
;
3652 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
3653 if(playsize
>sh_audio
->a_out_buffer_len
) playsize
=sh_audio
->a_out_buffer_len
;
3656 current_module
="play_audio";
3657 playsize
=audio_out
->play(sh_audio
->a_out_buffer
,playsize
,0);
3660 sh_audio
->a_out_buffer_len
-=playsize
;
3661 memmove(sh_audio
->a_out_buffer
,&sh_audio
->a_out_buffer
[playsize
],sh_audio
->a_out_buffer_len
);
3662 sh_audio
->delay
+=playback_speed
*playsize
/(double)ao_data
.bps
;
3666 } // while(sh_audio)
3669 // handle audio-only case:
3671 float a_pos
= sh_audio
->delay
- audio_out
->get_delay() * playback_speed
;
3672 print_status(a_pos
, 0, 0);
3674 if(d_audio
->eof
&& sh_audio
->a_in_buffer_len
<= 0 && sh_audio
->a_buffer_len
<= 0) eof
= PT_NEXT_ENTRY
;
3678 /*========================== PLAY VIDEO ============================*/
3680 float frame_time
=next_frame_time
;
3682 vo_pts
=sh_video
->timer
*90000.0;
3683 vo_fps
=sh_video
->fps
;
3685 if(!frame_time_remaining
){
3686 //-------------------- Decode a frame: -----------------------
3687 blit_frame
= 0; // Don't blit if we hit EOF
3688 vdecode_time
=video_time_usage
;
3690 { unsigned char* start
=NULL
;
3693 current_module
="video_read_frame";
3694 in_size
=video_read_frame(sh_video
,&next_frame_time
,&start
,force_fps
);
3695 if(in_size
<0){ eof
=1; break; }
3696 if(in_size
>max_framesize
) max_framesize
=in_size
; // stats
3697 sh_video
->timer
+=frame_time
;
3698 if(sh_audio
) sh_audio
->delay
-=frame_time
;
3699 time_frame
+=frame_time
; // for nosound
3700 // video_read_frame can change fps (e.g. for ASF video)
3701 vo_fps
= sh_video
->fps
;
3702 // check for frame-drop:
3703 current_module
="check_framedrop";
3704 if(sh_audio
&& !d_audio
->eof
){
3705 float delay
=playback_speed
*audio_out
->get_delay();
3706 float d
=delay
-sh_audio
->delay
;
3707 // we should avoid dropping too many frames in sequence unless we
3708 // are too late. and we allow 100ms A-V delay here:
3709 if(d
<-dropped_frames
*frame_time
-0.100 && osd_function
!= OSD_PAUSE
){
3710 drop_frame
=frame_dropping
;
3714 drop_frame
=dropped_frames
=0;
3719 current_module
="decode_video";
3720 // printf("Decode! %p %d \n",start,in_size);
3721 blit_frame
=decode_video(sh_video
,start
,in_size
,drop_frame
, MP_NOPTS_VALUE
);
3724 vdecode_time
=video_time_usage
-vdecode_time
;
3725 //------------------------ frame decoded. --------------------
3727 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3729 if(sh_video
->vf_inited
<0){
3730 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_NotInitializeVOPorVO
);
3731 eof
=1; goto goto_next_file
;
3736 // ==========================================================================
3738 // current_module="draw_osd";
3739 // if(vo_config_count) video_out->draw_osd();
3742 if(use_gui
) guiEventHandling();
3745 current_module
="calc_sleep_time";
3748 { // debug frame dropping code
3749 float delay
=audio_out
->get_delay();
3750 mp_msg(MSGT_AVSYNC
,MSGL_V
,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
3751 sh_video
->timer
,sh_audio
->timer
-delay
,
3752 sh_video
->timer
-(sh_audio
->timer
-delay
),
3757 if(drop_frame
&& !frame_time_remaining
&& !autosync
){
3759 * Note: time_frame should not be forced to 0 in autosync mode.
3760 * It is used as a cumulative counter to predict and correct the
3761 * delay measurements from the audio driver. time_frame is already
3762 * < 0, so the "time to sleep" code does not actually sleep. Also,
3763 * blit_frame is already 0 because drop_frame was true when
3764 * decode_video was called (which causes it to set blit_frame to 0.)
3765 * When autosync==0, the default behavior is still completely unchanged.
3768 time_frame
=0; // don't sleep!
3769 blit_frame
=0; // don't display!
3773 // It's time to sleep...
3775 frame_time_remaining
=0;
3776 time_frame
-=GetRelativeTime(); // reset timer
3778 if(sh_audio
&& !d_audio
->eof
){
3779 float delay
=playback_speed
*audio_out
->get_delay();
3780 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"delay=%f\n",delay
);
3784 * Adjust this raw delay value by calculating the expected
3785 * delay for this frame and generating a new value which is
3786 * weighted between the two. The higher autosync is, the
3787 * closer to the delay value gets to that which "-nosound"
3788 * would have used, and the longer it will take for A/V
3789 * sync to settle at the right value (but it eventually will.)
3790 * This settling time is very short for values below 100.
3792 float predicted
= sh_audio
->delay
+time_frame
;
3793 float difference
= delay
- predicted
;
3794 delay
= predicted
+ difference
/ (float)autosync
;
3797 time_frame
=delay
-sh_audio
->delay
;
3799 // delay = amount of audio buffered in soundcard/driver
3800 if(delay
>0.25) delay
=0.25; else
3801 if(delay
<0.10) delay
=0.10;
3802 if(time_frame
>delay
*0.6){
3803 // sleep time too big - may cause audio drops (buffer underrun)
3804 frame_time_remaining
=1;
3805 time_frame
=delay
*0.5;
3811 if( (time_frame
<-3*frame_time
|| time_frame
>3*frame_time
) || benchmark
)
3816 // 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);
3818 aq_sleep_time
+=time_frame
;
3822 //============================== SLEEP: ===================================
3824 time_frame
/=playback_speed
;
3826 // flag 256 means: libvo driver does its timing (dvb card)
3827 if(time_frame
>0.001 && !(vo_flags
&256)){
3831 // -------- RTC -----------
3832 current_module
="sleep_rtc";
3833 while (time_frame
> 0.000) {
3834 unsigned long rtc_ts
;
3835 if (read (rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
3836 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
3837 time_frame
-=GetRelativeTime();
3843 current_module
="sleep_darwin";
3844 while(time_frame
>0.005) {
3845 usec_sleep(1000000*time_frame
);
3846 time_frame
-=GetRelativeTime();
3851 // -------- TIMER + SOFTSLEEP -----------
3852 // assume kernel HZ=100 for softsleep, works with larger HZ but with
3853 // unnecessarily high CPU usage
3854 float margin
= softsleep
? 0.011 : 0;
3855 current_module
="sleep_timer";
3856 while (time_frame
> margin
) {
3857 usec_sleep(1000000 * (time_frame
- margin
));
3858 time_frame
-= GetRelativeTime();
3861 current_module
="sleep_soft";
3862 if(time_frame
<0) mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
3863 while(time_frame
>0) time_frame
-=GetRelativeTime(); // burn the CPU
3866 #endif /* SYS_DARWIN */
3869 //if(!frame_time_remaining){ // should we display the frame now?
3871 //====================== FLIP PAGE (VIDEO BLT): =========================
3873 current_module
="vo_check_events";
3874 if(vo_config_count
) video_out
->check_events();
3876 current_module
="flip_page";
3877 if (!frame_time_remaining
) {
3879 unsigned int t2
=GetTimer();
3882 #define FRAME_LAG_WARN 0.2
3883 j
= ((float)t2
- lastframeout_ts
) / 1000000;
3884 lastframeout_ts
= GetTimer();
3885 if (j
< frame_time
+ frame_time
* -FRAME_LAG_WARN
)
3886 too_fast_frame_cnt
++;
3887 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
3888 else if (j
> frame_time
+ frame_time
* FRAME_LAG_WARN
)
3889 too_slow_frame_cnt
++;
3890 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
3892 if(vo_config_count
) video_out
->flip_page();
3893 if (play_n_frames
>= 0) {
3895 if (play_n_frames
<= 0) eof
= PT_NEXT_ENTRY
;
3898 // usec_sleep(50000); // test only!
3901 vout_time_usage
+=tt
;
3904 Well, no blitting is needed, but some devices (such as yuv4mpeg)
3905 must output frames otherwise A/V desync will occur. -- Alvieboy
3907 if (vo_config_count
)
3908 video_out
->control(VOCTRL_DUPLICATE_FRAME
, NULL
);
3911 //====================== A-V TIMESTAMP CORRECTION: =========================
3913 current_module
="av_sync";
3919 // unplayed bytes in our and soundcard/dma buffer:
3920 float delay
=playback_speed
*audio_out
->get_delay()+(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
3924 * If autosync is enabled, the value for delay must be calculated
3925 * a bit differently. It is set only to the difference between
3926 * the audio and video timers. Any attempt to include the real
3927 * or corrected delay causes the pts_correction code below to
3928 * try to correct for the changes in delay which autosync is
3929 * trying to measure. This keeps the two from competing, but still
3930 * allows the code to correct for PTS drift *only*. (Using a delay
3931 * value here, even a "corrected" one, would be incompatible with
3934 delay
=sh_audio
->delay
;
3935 delay
+=(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
3937 delay
+= sh_audio
->a_out_buffer_len
*playback_speed
/(float)ao_data
.bps
;
3940 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
3941 a_pts
= sh_audio
->pts
;
3942 if (a_pts
== MP_NOPTS_VALUE
) {
3943 // Decoder doesn't support tracking timestamps or demuxer doesn't
3944 // set them properly in individual packets, use old inaccurate method
3946 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
3949 a_pts
+= sh_audio
->pts_bytes
/ (float)sh_audio
->o_bps
;
3951 v_pts
=sh_video
? sh_video
->pts
: d_video
->pts
;
3953 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"### A:%8.3f (%8.3f) V:%8.3f A-V:%7.4f \n",a_pts
,a_pts
-audio_delay
-delay
,v_pts
,(a_pts
-delay
-audio_delay
)-v_pts
);
3956 static int drop_message
=0;
3958 AV_delay
=(a_pts
-delay
-audio_delay
)-v_pts
;
3959 if(AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
3961 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
3966 /* Do not correct target time for the next frame if this frame
3967 * was late not because of wrong target time but because the
3968 * target time could not be met */
3969 x
= (AV_delay
+ time_frame
* playback_speed
) * 0.1f
;
3970 if(x
<-max_pts_correction
) x
=-max_pts_correction
; else
3971 if(x
> max_pts_correction
) x
= max_pts_correction
;
3972 if(default_max_pts_correction
>=0)
3973 max_pts_correction
=default_max_pts_correction
;
3975 max_pts_correction
=sh_video
->frametime
*0.10; // +-10% of time
3976 if(!frame_time_remaining
){ sh_audio
->delay
+=x
; c_total
+=x
;} // correction
3978 print_status(a_pts
- audio_delay
- delay
, AV_delay
, c_total
);
3985 print_status(0, 0, 0);
3989 //============================ Auto QUALITY ============================
3991 /*Output quality adjustments:*/
3993 current_module
="autoq";
3994 // float total=0.000001f * (GetTimer()-aq_total_time);
3995 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
3996 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
3999 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4000 if(output_quality
>1 && aq_sleep_time
<0)
4003 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4005 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4006 set_video_quality(sh_video
,output_quality
);
4009 } // end if(sh_video)
4011 //============================ Handle PAUSE ===============================
4013 current_module
="pause";
4017 // 36000000 means max timed visibility is 1 hour into the future, if
4018 // the difference is greater assume it's wrapped around from below 0
4019 if (osd_visible
- GetTimerMS() > 36000000) {
4021 vo_osd_progbar_type
=-1; // disable
4022 vo_osd_changed(OSDTYPE_PROGBAR
);
4023 if (osd_function
!= OSD_PAUSE
)
4024 osd_function
= OSD_PLAY
;
4029 if(osd_function
==OSD_PAUSE
){
4032 // Small hack to display the pause message on the OSD line.
4033 // The pause string is: "\n == PAUSE == \r" so we need to
4034 // take the first and the last char out
4036 char msg
[128] = MSGTR_Paused
;
4037 int mlen
= strlen(msg
);
4039 set_osd_msg(OSD_MSG_PAUSE
,1,0,"%s",msg
+1);
4042 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
4043 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
4047 if(use_gui
) guiGetEvent( guiCEvent
,(char *)guiSetPause
);
4049 if (video_out
&& sh_video
&& vo_config_count
)
4050 video_out
->control(VOCTRL_PAUSE
, NULL
);
4052 if (audio_out
&& sh_audio
)
4053 audio_out
->pause(); // pause audio, keep data if possible
4055 while( (cmd
= mp_input_get_cmd(20,1,1)) == NULL
) {
4056 if(sh_video
&& video_out
&& vo_config_count
) video_out
->check_events();
4060 guiGetEvent( guiReDraw
,NULL
);
4061 if(guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
)) break;
4066 vf_menu_pause_update(vf_menu
);
4070 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
4071 cmd
= mp_input_get_cmd(0,1,0);
4074 osd_function
=OSD_PLAY
;
4075 if (audio_out
&& sh_audio
)
4076 audio_out
->resume(); // resume audio
4077 if (video_out
&& sh_video
&& vo_config_count
)
4078 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
4079 (void)GetRelativeTime(); // keep TF around FT in next cycle
4083 if ( guiIntfStruct
.Playing
== guiSetStop
) goto goto_next_file
;
4084 guiGetEvent( guiCEvent
,(char *)guiSetPlay
);
4092 osd_function
=OSD_FFW
;
4093 rel_seek_secs
+=step_sec
;
4097 if (stream
->type
==STREAMTYPE_DVDNAV
&& dvd_nav_still
)
4098 dvdnav_stream_sleeping((dvdnav_priv_t
*)stream
->priv
);
4101 //================= EDL =========================================
4103 if( next_edl_record
) { // Are we (still?) doing EDL?
4105 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
4106 free_edl(edl_records
);
4107 next_edl_record
= NULL
;
4110 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
4111 if( next_edl_record
->action
== EDL_SKIP
) {
4112 osd_function
= OSD_FFW
;
4114 rel_seek_secs
= next_edl_record
->length_sec
;
4115 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
);
4117 } else if( next_edl_record
->action
== EDL_MUTE
) {
4118 edl_muted
= !edl_muted
;
4119 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4120 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
4122 next_edl_record
=next_edl_record
->next
;
4127 //================= Keyboard events, SEEKing ====================
4129 current_module
="key_events";
4134 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
4135 if(!set_property_command(cmd
))
4137 case MP_CMD_SEEK
: {
4141 osd_show_percentage
= sh_video
->fps
;
4142 v
= cmd
->args
[0].v
.f
;
4143 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
4144 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
4147 osd_function
= (v
> sh_video
->pts
) ? OSD_FFW
: OSD_REW
;
4150 else if(abs
) { /* Absolute seek by percentage */
4153 osd_function
= OSD_FFW
; // Direction isn't set correctly
4154 rel_seek_secs
= v
/100.0;
4158 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
4162 case MP_CMD_SET_PROPERTY
: {
4163 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4164 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unkown property: '%s'\n",cmd
->args
[0].v
.s
);
4165 else if(m_property_parse(prop
,cmd
->args
[1].v
.s
) <= 0)
4166 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to set property '%s' to '%s'.\n",
4167 cmd
->args
[0].v
.s
,cmd
->args
[1].v
.s
);
4170 case MP_CMD_GET_PROPERTY
: {
4173 prop
= mp_property_find(cmd
->args
[0].v
.s
);
4174 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unkown property: '%s'\n",cmd
->args
[0].v
.s
);
4175 /* Use m_option_print directly to get easily parseable values. */
4176 val
= calloc(1,prop
->type
->size
);
4177 if(m_property_do(prop
,M_PROPERTY_GET
,val
) <= 0) {
4178 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to get value of property '%s'.\n",
4182 tmp
= m_option_print(prop
,val
);
4183 if(!tmp
|| tmp
== (char*)-1) {
4184 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to print value of property '%s'.\n",
4188 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_%s=%s\n",cmd
->args
[0].v
.s
,tmp
);
4191 case MP_CMD_EDL_MARK
:
4193 float v
= sh_video
->pts
;
4194 fprintf( edl_fd
, "%f %f %d\n", v
-2, v
, 0 );
4197 case MP_CMD_SWITCH_RATIO
: {
4198 if (cmd
->nargs
== 0)
4199 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
4201 movie_aspect
= cmd
->args
[0].v
.f
;
4202 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
4204 case MP_CMD_SPEED_INCR
: {
4205 float v
= cmd
->args
[0].v
.f
;
4206 playback_speed
+= v
;
4207 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4208 build_afilter_chain(sh_audio
, &ao_data
);
4210 case MP_CMD_SPEED_MULT
: {
4211 float v
= cmd
->args
[0].v
.f
;
4212 playback_speed
*= v
;
4213 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4214 build_afilter_chain(sh_audio
, &ao_data
);
4216 case MP_CMD_SPEED_SET
: {
4217 float v
= cmd
->args
[0].v
.f
;
4219 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4220 build_afilter_chain(sh_audio
, &ao_data
);
4222 case MP_CMD_FRAME_STEP
:
4223 case MP_CMD_PAUSE
: {
4227 case MP_CMD_QUIT
: {
4228 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
4230 case MP_CMD_GRAB_FRAMES
: {
4233 case MP_CMD_PLAY_TREE_STEP
: {
4234 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
4235 int force
= cmd
->args
[1].v
.i
;
4244 for (i
=0;i
<-1*n
;i
++)
4249 if(!force
&& playtree_iter
) {
4250 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4252 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4253 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4254 play_tree_iter_free(i
);
4256 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4262 case MP_CMD_PLAY_TREE_UP_STEP
: {
4263 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
4264 int force
= cmd
->args
[1].v
.i
;
4266 if(!force
&& playtree_iter
) {
4267 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4268 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4269 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4270 play_tree_iter_free(i
);
4272 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4275 case MP_CMD_PLAY_ALT_SRC_STEP
: {
4276 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
4277 int v
= cmd
->args
[0].v
.i
;
4278 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
4280 else if(v
< 0 && playtree_iter
->file
> 1)
4285 case MP_CMD_SUB_STEP
: {
4288 int movement
= cmd
->args
[0].v
.i
;
4289 step_sub(subdata
, sh_video
->pts
, movement
);
4290 set_osd_msg(OSD_MSG_SUB_DELAY
,1,osd_duration
,
4291 MSGTR_OSDSubDelay
, ROUND(sub_delay
*1000));
4295 case MP_CMD_SUB_LOG
: {
4301 int v
= cmd
->args
[0].v
.i
;
4302 int max
= use_term_osd
? MAX_TERM_OSD_LEVEL
: MAX_OSD_LEVEL
;
4303 if(osd_level
> max
) osd_level
= max
;
4305 osd_level
=(osd_level
+1)%(max
+1);
4307 osd_level
= v
> max
? max
: v
;
4308 /* Show OSD state when disabled, but not when an explicit
4309 argument is given to the OSD command, i.e. in slave mode. */
4310 if (v
== -1 && osd_level
<= 1)
4311 set_osd_msg(OSD_MSG_OSD_STATUS
,0,osd_duration
,
4312 MSGTR_OSDosd
, osd_level
? MSGTR_OSDenabled
: MSGTR_OSDdisabled
);
4314 rm_osd_msg(OSD_MSG_OSD_STATUS
);
4316 case MP_CMD_OSD_SHOW_TEXT
: {
4317 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4318 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4319 "%-.63s",cmd
->args
[0].v
.s
);
4321 case MP_CMD_OSD_SHOW_PROPERTY_TEXT
: {
4322 char* txt
= m_properties_expand_string(mp_properties
,cmd
->args
[0].v
.s
);
4323 /* if no argument supplied take default osd_duration, else <arg> ms. */
4325 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4326 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4331 case MP_CMD_LOADFILE
: {
4332 play_tree_t
* e
= play_tree_new();
4333 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
4335 if (cmd
->args
[1].v
.i
) // append
4336 play_tree_append_entry(playtree
, e
);
4338 // Go back to the starting point.
4339 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
4341 play_tree_free_list(playtree
->child
,1);
4342 play_tree_set_child(playtree
,e
);
4343 play_tree_iter_step(playtree_iter
,0,0);
4348 case MP_CMD_LOADLIST
: {
4349 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
4351 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
4353 if (cmd
->args
[1].v
.i
) // append
4354 play_tree_append_entry(playtree
, e
);
4356 // Go back to the starting point.
4357 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
4359 play_tree_free_list(playtree
->child
,1);
4360 play_tree_set_child(playtree
,e
);
4361 play_tree_iter_step(playtree_iter
,0,0);
4368 case MP_CMD_TV_SET_FREQ
: {
4369 if (file_format
== DEMUXER_TYPE_TV
)
4370 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
4372 case MP_CMD_TV_SET_NORM
: {
4373 if (file_format
== DEMUXER_TYPE_TV
)
4374 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
4376 case MP_CMD_TV_STEP_CHANNEL
: {
4377 if (file_format
== DEMUXER_TYPE_TV
) {
4378 int v
= cmd
->args
[0].v
.i
;
4380 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
4382 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
4384 if (tv_channel_list
) {
4385 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4386 MSGTR_OSDChannel
, tv_channel_current
->name
);
4387 //vo_osd_changed(OSDTYPE_SUBTITLE);
4391 #ifdef HAS_DVBIN_SUPPORT
4392 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4394 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4398 int v
= cmd
->args
[0].v
.i
;
4402 dir
= DVB_CHANNEL_HIGHER
;
4404 dir
= DVB_CHANNEL_LOWER
;
4407 if(dvb_step_channel(priv
, dir
))
4408 eof
= dvbin_reopen
= 1;
4411 #endif /* HAS_DVBIN_SUPPORT */
4413 case MP_CMD_TV_SET_CHANNEL
: {
4414 if (file_format
== DEMUXER_TYPE_TV
) {
4415 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
4416 if (tv_channel_list
) {
4417 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4418 MSGTR_OSDChannel
, tv_channel_current
->name
);
4419 //vo_osd_changed(OSDTYPE_SUBTITLE);
4423 #ifdef HAS_DVBIN_SUPPORT
4424 case MP_CMD_DVB_SET_CHANNEL
:
4426 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4428 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4431 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
4436 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
4437 eof
= dvbin_reopen
= 1;
4442 #endif /* HAS_DVBIN_SUPPORT */
4443 case MP_CMD_TV_LAST_CHANNEL
: {
4444 if (file_format
== DEMUXER_TYPE_TV
) {
4445 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
4446 if (tv_channel_list
) {
4447 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4448 MSGTR_OSDChannel
, tv_channel_current
->name
);
4449 //vo_osd_changed(OSDTYPE_SUBTITLE);
4453 case MP_CMD_TV_STEP_NORM
: {
4454 if (file_format
== DEMUXER_TYPE_TV
)
4455 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
4457 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
4458 if (file_format
== DEMUXER_TYPE_TV
)
4459 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
4462 case MP_CMD_SUB_LOAD
:
4466 int n
= set_of_sub_size
;
4467 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
4468 if (n
!= set_of_sub_size
) {
4469 if (global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
4470 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
;
4476 case MP_CMD_SUB_REMOVE
:
4480 int v
= cmd
->args
[0].v
.i
;
4483 for (v
= 0; v
< set_of_sub_size
; ++v
) {
4484 subd
= set_of_subtitles
[v
];
4485 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
4487 set_of_subtitles
[v
] = NULL
;
4489 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
4490 global_sub_size
-= set_of_sub_size
;
4491 set_of_sub_size
= 0;
4492 if (set_of_sub_pos
>= 0) {
4493 global_sub_pos
= -2;
4494 vo_sub_last
= vo_sub
= NULL
;
4495 vo_osd_changed(OSDTYPE_SUBTITLE
);
4496 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
4497 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
4500 else if (v
< set_of_sub_size
) {
4501 subd
= set_of_subtitles
[v
];
4502 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
4504 if (set_of_sub_pos
== v
) {
4505 global_sub_pos
= -2;
4506 vo_sub_last
= vo_sub
= NULL
;
4507 vo_osd_changed(OSDTYPE_SUBTITLE
);
4508 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
4509 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
4511 else if (set_of_sub_pos
> v
) {
4515 while (++v
< set_of_sub_size
)
4516 set_of_subtitles
[v
- 1] = set_of_subtitles
[v
];
4519 if (set_of_sub_size
<= 0)
4520 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
4521 set_of_subtitles
[set_of_sub_size
] = NULL
;
4524 #endif /* USE_SUB */
4526 case MP_CMD_GET_SUB_VISIBILITY
:
4530 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_SUB_VISIBILITY=%d\n", sub_visibility
);
4534 case MP_CMD_SCREENSHOT
:
4535 if(vo_config_count
){
4536 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"sending VFCTRL_SCREENSHOT!\n");
4537 if(CONTROL_OK
!=((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_SCREENSHOT
, 0))
4538 video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
4541 case MP_CMD_VF_CHANGE_RECTANGLE
:
4542 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
4545 case MP_CMD_GET_TIME_LENGTH
: {
4546 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
4549 case MP_CMD_GET_VO_FULLSCREEN
: {
4550 if(video_out
&& vo_config_count
)
4551 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VO_FULLSCREEN=%d\n", vo_fs
);
4554 case MP_CMD_GET_PERCENT_POS
: {
4555 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer
));
4557 case MP_CMD_GET_TIME_POS
: {
4560 pos
= sh_video
->pts
;
4562 if (sh_audio
&& audio_out
)
4563 pos
= sh_audio
->delay
- audio_out
->get_delay() * playback_speed
;
4564 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
4566 case MP_CMD_SWITCH_AUDIO
: {
4567 int v
= demuxer_switch_audio(demuxer
, cmd
->args
[0].v
.i
);
4568 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", v
);
4573 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
4578 case MP_CMD_KEYDOWN_EVENTS
: {
4579 mplayer_put_key(cmd
->args
[0].v
.i
);
4582 case MP_CMD_DVDNAV_EVENT
: {
4583 dvdnav_priv_t
* dvdnav_priv
= (dvdnav_priv_t
*)(stream
->priv
);
4584 dvdnav_event_t
* dvdnav_event
= (dvdnav_event_t
*)(cmd
->args
[0].v
.v
);
4586 /* ignore these events if we're not in dvd_nav mode */
4587 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
4589 if (!dvdnav_event
) {
4590 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNullEvent
);
4594 //printf("mplayer: got event: %d\n",dvdnav_event->event);
4596 switch (dvdnav_event
->event
) {
4597 case DVDNAV_BLOCK_OK
: {
4598 /* be silent about this one */
4601 case DVDNAV_HIGHLIGHT
: {
4602 dvdnav_highlight_event_t
*hevent
= (dvdnav_highlight_event_t
*)(dvdnav_event
->details
);
4604 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavHighlightEventBroken
);
4608 if (hevent
->display
&& hevent
->buttonN
>0)
4610 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
4611 sprintf( dvd_nav_text
, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
4613 hevent
->sx
,hevent
->sy
,
4614 hevent
->ex
,hevent
->ey
,
4615 hevent
->pts
, d_video
->pts
);
4616 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavEvent
,dvd_nav_text
);
4617 //osd_show_dvd_nav_delay = 60;
4619 osd_show_dvd_nav_highlight
=1; /* this is just a flag */
4620 osd_show_dvd_nav_sx
=hevent
->sx
;
4621 osd_show_dvd_nav_ex
=hevent
->ex
;
4622 osd_show_dvd_nav_sy
=hevent
->sy
;
4623 osd_show_dvd_nav_ey
=hevent
->ey
;
4626 osd_show_dvd_nav_highlight
=0;
4627 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavHighlightHide
);
4631 case DVDNAV_STILL_FRAME
: {
4632 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*)(dvdnav_event
->details
);
4634 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavStillFrame
, still_event
->length
);
4635 while (dvdnav_stream_sleeping(dvdnav_priv
)) {
4636 usec_sleep(1000); /* 1ms */
4638 dvdnav_stream_sleep(dvdnav_priv
,still_event
->length
);
4642 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavStop
);
4646 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavNOP
);
4649 case DVDNAV_SPU_STREAM_CHANGE
: {
4650 #if DVDNAVVERSION > 012
4651 dvdnav_spu_stream_change_event_t
*stream_change
= (dvdnav_spu_stream_change_event_t
*)(dvdnav_event
->details
);
4653 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuStreamChangeVerbose
,
4654 stream_change
->physical_wide
,
4655 stream_change
->physical_letterbox
,
4656 stream_change
->physical_pan_scan
,
4657 stream_change
->logical
);
4659 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical_wide
) {
4660 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
4661 d_dvdsub
->id
,stream_change
->physical_wide
);
4662 // FIXME: need a better way to change SPU id
4663 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical_wide
;
4664 if (vo_spudec
) spudec_reset(vo_spudec
);
4667 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
4669 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuStreamChange
,
4670 stream_change
->physical
,
4671 stream_change
->logical
);
4673 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical
) {
4674 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
4675 d_dvdsub
->id
,stream_change
->physical
);
4676 // FIXME: need a better way to change SPU id
4677 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical
;
4678 if (vo_spudec
) spudec_reset(vo_spudec
);
4680 #endif /* DVDNAVVERSION > 012 */
4683 case DVDNAV_AUDIO_STREAM_CHANGE
: {
4685 #if DVDNAVVERSION > 012
4686 dvdnav_audio_stream_change_event_t
*stream_change
= (dvdnav_audio_stream_change_event_t
*)(dvdnav_event
->details
);
4688 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
4691 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavAudioStreamChange
,
4692 stream_change
->physical
,
4693 stream_change
->logical
);
4695 aid_temp
=stream_change
->physical
;
4696 if (aid_temp
>=0) aid_temp
+=128; // FIXME: is this sane?
4697 if (d_audio
&& audio_id
!=aid_temp
) {
4698 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_audio->id change: was %d is now %d\n",
4699 d_audio
->id
,aid_temp
);
4700 // FIXME: need a better way to change audio stream id
4701 d_audio
->id
=dvdsub_id
=aid_temp
;
4702 if(sh_audio
) resync_audio_stream(sh_audio
);
4707 case DVDNAV_VTS_CHANGE
: {
4708 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavVTSChange
);
4711 case DVDNAV_CELL_CHANGE
: {
4712 dvdnav_cell_change_event_t
*cell_change
= (dvdnav_cell_change_event_t
*)(dvdnav_event
->details
);
4713 cell_playback_t
* cell_playback
= cell_change
->new_cell
;
4715 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavCellChange
);
4716 osd_show_dvd_nav_highlight
=0; /* screen changed, disable menu */
4718 printf("new still time: %d\n",cell_playback->still_time);
4719 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
4720 printf("new playback_time: %02d:%02d:%02d.%02d\n",
4721 cell_playback->playback_time.hour,
4722 cell_playback->playback_time.minute,
4723 cell_playback->playback_time.second,
4724 cell_playback->playback_time.frame_u);
4727 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
4731 case DVDNAV_NAV_PACKET
: {
4732 // printf("DVDNAV Event: Nav Packet\n");
4735 case DVDNAV_SPU_CLUT_CHANGE
: {
4736 uint32_t * new_clut
= (uint32_t *)(dvdnav_event
->details
);
4738 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuClutChange
);
4739 // send new palette to SPU decoder
4740 if (vo_spudec
) spudec_update_palette(vo_spudec
,new_clut
);
4744 case DVDNAV_SEEK_DONE
: {
4745 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSeekDone
);
4750 // free the dvdnav event
4751 free(dvdnav_event
->details
);
4753 cmd
->args
[0].v
.v
=NULL
;
4755 case MP_CMD_DVDNAV
: {
4756 dvdnav_priv_t
* dvdnav_priv
=(dvdnav_priv_t
*)stream
->priv
;
4758 /* ignore these events if we're not in dvd_nav mode */
4759 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
4761 switch (cmd
->args
[0].v
.i
) {
4762 case MP_CMD_DVDNAV_UP
:
4763 dvdnav_upper_button_select(dvdnav_priv
->dvdnav
);
4765 case MP_CMD_DVDNAV_DOWN
:
4766 dvdnav_lower_button_select(dvdnav_priv
->dvdnav
);
4768 case MP_CMD_DVDNAV_LEFT
:
4769 dvdnav_left_button_select(dvdnav_priv
->dvdnav
);
4771 case MP_CMD_DVDNAV_RIGHT
:
4772 dvdnav_right_button_select(dvdnav_priv
->dvdnav
);
4774 case MP_CMD_DVDNAV_MENU
:
4775 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_MenuCall
);
4776 dvdnav_menu_call(dvdnav_priv
->dvdnav
,DVD_MENU_Root
);
4778 case MP_CMD_DVDNAV_SELECT
:
4779 dvdnav_button_activate(dvdnav_priv
->dvdnav
);
4782 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Weird DVD Nav cmd %d\n",cmd
->args
[0].v
.i
);
4787 #endif /* USE_DVDNAV */
4790 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
4793 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
4796 switch (cmd
->pausing
) {
4797 case 1: // "pausing"
4798 osd_function
= OSD_PAUSE
;
4800 case 3: // "pausing_toggle"
4801 was_paused
= !was_paused
;
4803 case 2: // "pausing_keep"
4804 if (was_paused
) osd_function
= OSD_PAUSE
;
4814 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
4815 rel_seek_secs
+= 3600*a
+60*b
+d
;
4816 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
4817 rel_seek_secs
+= 60*a
+d
;
4818 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
4825 if(eof
==1 && loop_times
>=0) {
4827 play_tree_iter_step(playtree_iter
,0,0);
4829 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
4831 if(loop_times
>1) loop_times
--; else
4832 if(loop_times
==1) loop_times
=-1;
4833 play_n_frames
=play_n_frames_mf
;
4835 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
4839 if(rel_seek_secs
|| abs_seek_pos
){
4840 current_module
="seek";
4841 if(demux_seek(demuxer
,rel_seek_secs
,audio_delay
,abs_seek_pos
)){
4843 /* FIXME there should be real seeking for vobsub */
4844 if(sh_video
) sh_video
->pts
=d_video
->pts
;
4846 //vobsub_reset(vo_vobsub);
4847 vobsub_seek(vo_vobsub
,sh_video
->pts
);
4851 current_module
="seek_video_reset";
4852 resync_video_stream(sh_video
);
4853 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
4857 current_module
="seek_audio_reset";
4858 audio_out
->reset(); // stop audio, throwing away buffered data
4859 sh_audio
->a_buffer_len
= 0;
4860 sh_audio
->a_out_buffer_len
= 0;
4865 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer
));
4870 max_pts_correction
=0.1;
4871 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
4872 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4874 too_slow_frame_cnt
=0;
4875 too_fast_frame_cnt
=0;
4877 if(vo_spudec
) spudec_reset(vo_spudec
);
4881 * We saw a seek, have to rewind the EDL operations stack
4882 * and find the next EDL action to take care of.
4886 next_edl_record
= edl_records
;
4888 while (next_edl_record
)
4890 /* Trying to remember if we need to mute/unmute first;
4891 * prior EDL implementation lacks this.
4894 if (next_edl_record
->start_sec
>= sh_video
->pts
)
4897 if (next_edl_record
->action
== EDL_MUTE
) edl_muted
= !edl_muted
;
4898 next_edl_record
= next_edl_record
->next
;
4901 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4905 frame_time_remaining
=0;
4906 current_module
=NULL
;
4913 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
4914 // get pos from frame number / total frames
4915 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
4917 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
4918 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
4919 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
4921 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
4922 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
4923 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
4924 guiGetEvent( guiReDraw
,NULL
);
4925 guiGetEvent( guiSetVolume
,NULL
);
4926 if(guiIntfStruct
.Playing
==0) break; // STOP
4927 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
4928 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
4930 if ( stream
->type
== STREAMTYPE_DVD
)
4932 dvd_priv_t
* dvdp
= stream
->priv
;
4933 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
4937 #endif /* HAVE_NEW_GUI */
4940 //================= Update OSD ====================
4946 if(subdata
&& sh_video
&& sh_video
->pts
>0){
4947 float pts
=sh_video
->pts
;
4948 if(sub_fps
==0) sub_fps
=sh_video
->fps
;
4949 current_module
="find_sub";
4950 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0 ) {
4951 find_sub(subdata
, (pts
+sub_delay
) *
4952 (subdata
->sub_uses_time
? 100. : sub_fps
));
4953 if (vo_sub
) vo_sub_last
= vo_sub
;
4954 // FIXME! frame counter...
4957 current_module
=NULL
;
4962 if (stop_xscreensaver
&& sh_video
) {
4963 current_module
="stop_xscreensaver";
4964 xscreensaver_heartbeat();
4965 current_module
=NULL
;
4970 if(vo_config_count
&& vo_spudec
) {
4971 unsigned char* packet
=NULL
;
4973 current_module
="spudec";
4974 spudec_heartbeat(vo_spudec
,90000*sh_video
->timer
);
4975 /* Get a sub packet from the DVD or a vobsub and make a timestamp
4976 relative to sh_video->timer */
4981 if(sh_video
->pts
+sub_delay
>=0) {
4982 // The + next_frame_time is there because we'll display the sub at the next frame
4983 len
= vobsub_get_packet(vo_vobsub
,sh_video
->pts
+sub_delay
+next_frame_time
,(void**)&packet
,×tamp
);
4985 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
4986 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
);
4991 len
= ds_get_packet_sub(d_dvdsub
,(unsigned char**)&packet
);
4993 float x
= d_dvdsub
->pts
- sh_video
->pts
;
4994 if (x
< -10 || x
> 10) // prevent missing subs on pts reset
4995 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
+ sub_delay
- sh_video
->pts
);
4996 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
4997 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
);
5000 if(len
<=0 || !packet
) break;
5001 if(timestamp
< 0) timestamp
= 0;
5002 else spudec_assemble(vo_spudec
,packet
,len
,timestamp
);
5005 /* detect wether the sub has changed or not */
5006 if(spudec_changed(vo_spudec
))
5007 vo_osd_changed(OSDTYPE_SPU
);
5008 current_module
=NULL
;
5013 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
5015 #ifdef HAS_DVBIN_SUPPORT
5019 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
5020 cache_uninit(stream
);
5022 goto goto_enable_cache
;
5027 goto_next_file
: // don't jump here after ao/vo/getch initialization!
5029 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
5032 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
5033 double total_time_usage
;
5034 total_time_usage_start
=GetTimer()-total_time_usage_start
;
5035 total_time_usage
= (float)total_time_usage_start
*0.000001;
5036 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5037 video_time_usage
,vout_time_usage
,audio_time_usage
,
5038 total_time_usage
-tot
,total_time_usage
);
5039 if(total_time_usage
>0.0)
5040 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5041 100.0*video_time_usage
/total_time_usage
,
5042 100.0*vout_time_usage
/total_time_usage
,
5043 100.0*audio_time_usage
/total_time_usage
,
5044 100.0*(total_time_usage
-tot
)/total_time_usage
,
5046 if(total_frame_cnt
&& frame_dropping
)
5047 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5048 total_frame_cnt
-drop_frame_cnt
,
5049 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
5051 100*drop_frame_cnt
/total_frame_cnt
,
5053 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
5057 // time to uninit all, except global stuff:
5058 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
5061 if ( set_of_sub_size
> 0 )
5063 current_module
="sub_free";
5064 for (i
= 0; i
< set_of_sub_size
; ++i
)
5065 sub_free( set_of_subtitles
[i
] );
5066 set_of_sub_size
= 0;
5067 vo_sub_last
= vo_sub
=NULL
;
5072 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
5073 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
5074 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
5077 play_tree_iter_free(playtree_iter
);
5078 playtree_iter
= NULL
;
5081 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
5082 eof
= eof
== PT_UP_NEXT
? 1 : -1;
5083 if ( playtree_iter
) {
5084 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
5087 play_tree_iter_free(playtree_iter
);
5088 playtree_iter
= NULL
;
5091 } else { // NEXT PREV SRC
5092 eof
= eof
== PT_PREV_SRC
? -1 : 1;
5095 if(eof
== 0) eof
= 1;
5097 while(playtree_iter
!= NULL
) {
5098 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
5099 if(filename
== NULL
) {
5100 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
5101 play_tree_iter_free(playtree_iter
);
5102 playtree_iter
= NULL
;
5109 if( use_gui
&& !playtree_iter
)
5112 if ( !guiIntfStruct
.DiskChanged
)
5118 if(use_gui
|| playtree_iter
!= NULL
|| player_idle_mode
){
5119 if (!playtree_iter
) filename
= NULL
;
5121 goto play_next_file
;
5125 exit_player_with_rc(MSGTR_Exit_eof
, 0);