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"
53 #include "subreader.h"
55 #include "libvo/video_out.h"
57 #include "libvo/font_load.h"
58 #include "libvo/sub.h"
61 #include "libvo/x11_common.h"
64 #include "libao2/audio_out.h"
66 #include "codec-cfg.h"
73 #include "osdep/getch2.h"
74 #include "osdep/timer.h"
76 #include "cpudetect.h"
79 #include "Gui/interface.h"
82 #include "input/input.h"
85 int player_idle_mode
=0;
87 int enable_mouse_movements
=0;
90 char * proc_priority
=NULL
;
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
97 #include <linux/rtc.h>
100 #define RTC_IRQP_SET RTCIO_IRQP_SET
101 #define RTC_PIE_ON RTCIO_PIE_ON
102 #endif /* __linux__ */
103 #endif /* HAVE_RTC */
106 #include "stream/tv.h"
109 #include "stream/stream_radio.h"
112 #ifdef HAS_DVBIN_SUPPORT
113 #include "stream/dvbin.h"
114 static int last_dvb_step
= 1;
115 static int dvbin_reopen
= 0;
116 #include "stream/cache2.h"
119 //**************************************************************************//
121 //**************************************************************************//
122 #include "playtree.h"
123 #include "playtreeparser.h"
126 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
127 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
130 play_tree_t
* playtree
;
131 play_tree_iter_t
* playtree_iter
= NULL
;
132 static int play_tree_step
= 1;
134 #define PT_NEXT_ENTRY 1
135 #define PT_PREV_ENTRY -1
136 #define PT_NEXT_SRC 2
137 #define PT_PREV_SRC -2
139 #define PT_UP_PREV -3
141 //**************************************************************************//
143 //**************************************************************************//
144 #include "parser-cfg.h"
145 #include "parser-mpcmd.h"
149 //**************************************************************************//
151 //**************************************************************************//
153 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
155 static int cfg_include(m_option_t
*conf
, char *filename
){
156 return m_config_parse_config_file(mconfig
, filename
);
159 #include "get_path.c"
161 //**************************************************************************//
163 //**************************************************************************//
166 void xscreensaver_heartbeat(void);
169 //**************************************************************************//
170 //**************************************************************************//
171 // Input media streaming & demultiplexer:
172 //**************************************************************************//
174 static int max_framesize
=0;
176 #include "stream/stream.h"
177 #include "libmpdemux/demuxer.h"
178 #include "libmpdemux/stheader.h"
179 //#include "parse_es.h"
180 #include "libmpdemux/matroska.h"
183 #include "stream/stream_dvd.h"
187 #include "stream/stream_dvdnav.h"
190 #include "libmpcodecs/dec_audio.h"
191 #include "libmpcodecs/dec_video.h"
192 #include "libmpcodecs/mp_image.h"
193 #include "libmpcodecs/vf.h"
194 #include "libmpcodecs/vd.h"
196 //**************************************************************************//
198 static void reinit_audio_chain(void);
200 //**************************************************************************//
201 //**************************************************************************//
203 // Common FIFO functions, and keyboard/event FIFO code
205 int noconsolecontrols
=0;
206 //**************************************************************************//
208 vo_functions_t
*video_out
=NULL
;
209 ao_functions_t
*audio_out
=NULL
;
215 double video_time_usage
=0;
216 double vout_time_usage
=0;
217 static double audio_time_usage
=0;
218 static int total_time_usage_start
=0;
219 static int total_frame_cnt
=0;
220 static int drop_frame_cnt
=0; // total number of dropped frames
225 static int output_quality
=0;
227 float playback_speed
=1.0;
235 static int list_properties
= 0;
237 #define MAX_OSD_LEVEL 3
238 #define MAX_TERM_OSD_LEVEL 1
241 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
242 unsigned int osd_visible
;
243 static int osd_function
=OSD_PLAY
;
244 static int osd_show_percentage
= 0;
245 static int osd_duration
= 1000;
247 static int term_osd
= 1;
248 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
249 static char* playing_msg
= NULL
;
251 static char *seek_to_sec
=NULL
;
252 static off_t seek_to_byte
=0;
253 static off_t step_sec
=0;
254 static int loop_times
=-1;
255 static int loop_seek
=0;
257 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
260 int autosync
=0; // 30 might be a good default value.
262 // may be changed by GUI: (FIXME!)
263 float rel_seek_secs
=0;
267 char **audio_codec_list
=NULL
; // override audio codec
268 char **video_codec_list
=NULL
; // override video codec
269 char **audio_fm_list
=NULL
; // override audio codec family
270 char **video_fm_list
=NULL
; // override video codec family
273 extern char *demuxer_name
; // override demuxer
274 extern char *audio_demuxer_name
; // override audio demuxer
275 extern char *sub_demuxer_name
; // override sub demuxer
282 char* audio_lang
=NULL
;
283 char* dvdsub_lang
=NULL
;
284 static char* spudec_ifo
=NULL
;
285 char* filename
=NULL
; //"MI2-Trailer.avi";
286 int forced_subs_only
=0;
290 int stream_cache_size
=-1;
291 #ifdef USE_STREAM_CACHE
292 extern int cache_fill_status
;
294 float stream_cache_min_percent
=20.0;
295 float stream_cache_seek_min_percent
=50.0;
297 #define cache_fill_status 0
301 static char *stream_dump_name
="stream.dump";
302 int stream_dump_type
=0;
305 static float default_max_pts_correction
=-1;//0.01f;
306 static float max_pts_correction
=0;//default_max_pts_correction;
307 static float c_total
=0;
309 static int ignore_start
=0;
311 static int softsleep
=0;
314 static int force_srate
=0;
315 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
316 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
317 static int play_n_frames
=-1;
318 static int play_n_frames_mf
=-1;
321 char** video_driver_list
=NULL
;
322 char** audio_driver_list
=NULL
;
324 extern char *vo_subdevice
;
325 extern char *ao_subdevice
;
327 // codec outfmt flags (defined in libmpcodecs/vd.c)
331 char *font_name
=NULL
;
332 #ifdef HAVE_FONTCONFIG
333 extern int font_fontconfig
;
335 float font_factor
=0.75;
336 char **sub_name
=NULL
;
340 char *vobsub_name
=NULL
;
341 /*DSP!!char *dsp=NULL;*/
343 int suboverlap_enabled
= 1;
345 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
346 int set_of_sub_size
= 0;
347 int set_of_sub_pos
= -1;
349 int global_sub_size
= 0; // this encompasses all subtitle sources
350 int global_sub_pos
= -1; // this encompasses all subtitle sources
351 #define SUB_SOURCE_SUBS 0
352 #define SUB_SOURCE_VOBSUB 1
353 #define SUB_SOURCE_DEMUX 2
354 #define SUB_SOURCES 3
355 int global_sub_indices
[SUB_SOURCES
];
358 #include "libass/ass.h"
359 #include "libass/ass_mp.h"
361 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
362 // or NULL if format unsupported
363 ass_track_t
* set_of_ass_tracks
[MAX_SUBTITLE_FILES
];
366 extern int mp_msg_levels
[MSGT_MAX
];
367 extern int mp_msg_level_all
;
369 static stream_t
* stream
=NULL
;
370 static demuxer_t
*demuxer
=NULL
;
371 static sh_audio_t
*sh_audio
=NULL
;
372 static sh_video_t
*sh_video
=NULL
;
373 static demux_stream_t
*d_audio
=NULL
;
374 static demux_stream_t
*d_video
=NULL
;
375 static demux_stream_t
*d_dvdsub
=NULL
;
377 char* current_module
=NULL
; // for debugging
379 extern int vo_gamma_gamma
;
380 extern int vo_gamma_brightness
;
381 extern int vo_gamma_contrast
;
382 extern int vo_gamma_saturation
;
383 extern int vo_gamma_hue
;
388 #include "m_struct.h"
389 #include "libmenu/menu.h"
390 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
391 extern vf_info_t vf_info_menu
;
392 static vf_info_t
* libmenu_vfs
[] = {
396 static vf_instance_t
* vf_menu
= NULL
;
397 static int use_menu
= 0;
398 static char* menu_cfg
= NULL
;
399 static char* menu_root
= "main";
404 static int nortc
= 1;
405 static char* rtc_device
;
408 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
409 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
410 short user_muted
= 0; ///< Stores whether user wanted muted mode.
411 short edl_muted
= 0; ///< Stores whether EDL is currently in muted mode.
412 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
413 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
414 float begin_skip
= MP_NOPTS_VALUE
; ///< start time of the current skip while on edlout mode
415 int use_filedir_conf
;
417 static unsigned int inited_flags
=0;
418 #include "mpcommon.h"
422 #define INITED_GETCH2 8
423 #define INITED_SPUDEC 32
424 #define INITED_STREAM 64
425 #define INITED_INPUT 128
426 #define INITED_VOBSUB 256
427 #define INITED_DEMUXER 512
428 #define INITED_ACODEC 1024
429 #define INITED_VCODEC 2048
430 #define INITED_ALL 0xFFFF
432 #include "metadata.h"
434 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
436 static int is_valid_metadata_type (metadata_t type
) {
439 /* check for valid video stream */
440 case META_VIDEO_CODEC
:
441 case META_VIDEO_BITRATE
:
442 case META_VIDEO_RESOLUTION
:
449 /* check for valid audio stream */
450 case META_AUDIO_CODEC
:
451 case META_AUDIO_BITRATE
:
452 case META_AUDIO_SAMPLES
:
459 /* check for valid demuxer */
460 case META_INFO_TITLE
:
461 case META_INFO_ARTIST
:
462 case META_INFO_ALBUM
:
464 case META_INFO_COMMENT
:
465 case META_INFO_TRACK
:
466 case META_INFO_GENRE
:
480 static char *get_demuxer_info (char *tag
) {
481 char **info
= demuxer
->info
;
487 for (n
= 0; info
[2*n
] != NULL
; n
++)
488 if (!strcmp (info
[2*n
], tag
))
491 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
494 char *get_metadata (metadata_t type
) {
497 if (!is_valid_metadata_type (type
))
504 return strdup (mp_basename2 (filename
));
507 case META_VIDEO_CODEC
:
509 if (sh_video
->format
== 0x10000001)
510 meta
= strdup ("mpeg1");
511 else if (sh_video
->format
== 0x10000002)
512 meta
= strdup ("mpeg2");
513 else if (sh_video
->format
== 0x10000004)
514 meta
= strdup ("mpeg4");
515 else if (sh_video
->format
== 0x10000005)
516 meta
= strdup ("h264");
517 else if (sh_video
->format
>= 0x20202020)
519 meta
= (char *) malloc (8);
520 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
524 meta
= (char *) malloc (8);
525 sprintf (meta
, "0x%08X", sh_video
->format
);
530 case META_VIDEO_BITRATE
:
532 meta
= (char *) malloc (16);
533 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
537 case META_VIDEO_RESOLUTION
:
539 meta
= (char *) malloc (16);
540 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
544 case META_AUDIO_CODEC
:
546 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
547 meta
= strdup (sh_audio
->codec
->name
);
551 case META_AUDIO_BITRATE
:
553 meta
= (char *) malloc (16);
554 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
558 case META_AUDIO_SAMPLES
:
560 meta
= (char *) malloc (16);
561 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
565 /* check for valid demuxer */
566 case META_INFO_TITLE
:
567 return get_demuxer_info ("Title");
569 case META_INFO_ARTIST
:
570 return get_demuxer_info ("Artist");
572 case META_INFO_ALBUM
:
573 return get_demuxer_info ("Album");
576 return get_demuxer_info ("Year");
578 case META_INFO_COMMENT
:
579 return get_demuxer_info ("Comment");
581 case META_INFO_TRACK
:
582 return get_demuxer_info ("Track");
584 case META_INFO_GENRE
:
585 return get_demuxer_info ("Genre");
596 /// step size of mixer changes
599 static void uninit_player(unsigned int mask
){
600 mask
=inited_flags
&mask
;
602 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
604 if(mask
&INITED_ACODEC
){
605 inited_flags
&=~INITED_ACODEC
;
606 current_module
="uninit_acodec";
607 if(sh_audio
) uninit_audio(sh_audio
);
609 guiGetEvent(guiSetAfilter
, (char *)NULL
);
614 if(mask
&INITED_VCODEC
){
615 inited_flags
&=~INITED_VCODEC
;
616 current_module
="uninit_vcodec";
617 if(sh_video
) uninit_video(sh_video
);
624 if(mask
&INITED_DEMUXER
){
625 inited_flags
&=~INITED_DEMUXER
;
626 current_module
="free_demuxer";
628 stream
=demuxer
->stream
;
629 free_demuxer(demuxer
);
634 // kill the cache process:
635 if(mask
&INITED_STREAM
){
636 inited_flags
&=~INITED_STREAM
;
637 current_module
="uninit_stream";
638 if(stream
) free_stream(stream
);
643 inited_flags
&=~INITED_VO
;
644 current_module
="uninit_vo";
649 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
650 if(mask
&INITED_GETCH2
){
651 inited_flags
&=~INITED_GETCH2
;
652 current_module
="uninit_getch2";
653 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
658 if(mask
&INITED_VOBSUB
){
659 inited_flags
&=~INITED_VOBSUB
;
660 current_module
="uninit_vobsub";
661 if(vo_vobsub
) vobsub_close(vo_vobsub
);
665 if (mask
&INITED_SPUDEC
){
666 inited_flags
&=~INITED_SPUDEC
;
667 current_module
="uninit_spudec";
668 spudec_free(vo_spudec
);
673 inited_flags
&=~INITED_AO
;
674 current_module
="uninit_ao";
675 if (user_muted
| edl_muted
) mixer_mute(&mixer
);
676 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
681 inited_flags
&=~INITED_GUI
;
682 current_module
="uninit_gui";
687 if(mask
&INITED_INPUT
){
688 inited_flags
&=~INITED_INPUT
;
689 current_module
="uninit_input";
696 static void exit_player_with_rc(const char* how
, int rc
){
698 uninit_player(INITED_ALL
);
703 vo_uninit(); // Close the X11 connection (if any is open).
707 current_module
="uninit_font";
708 if (vo_font
) free_font_desc(vo_font
);
715 ass_library_done(ass_library
);
718 current_module
="exit_player";
720 // free mplayer config
722 m_config_free(mconfig
);
725 play_tree_free(playtree
, 1);
728 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
729 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
730 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
735 void exit_player(const char* how
){
736 exit_player_with_rc(how
, 1);
740 static void child_sighandler(int x
){
742 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
747 static char *prog_path
;
748 static int crash_debug
= 0;
751 static void exit_sighandler(int x
){
752 static int sig_count
=0;
754 if (!crash_debug
|| x
!= SIGTRAP
)
757 if(inited_flags
==0 && sig_count
>1) exit(1);
760 /* We're crashing bad and can't uninit cleanly :(
761 * by popular request, we make one last (dirty)
762 * effort to restore the user's
767 if(sig_count
==6) exit(1);
771 kill(getpid(),SIGKILL
);
774 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
775 current_module
?current_module
:"unknown"
777 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
784 break; // killed from keyboard (^C) or killed [-9]
786 #ifdef RUNTIME_CPUDETECT
787 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
789 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
793 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
795 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
800 snprintf(spid
, 19, "%i", getpid());
802 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
804 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
805 if (gdb_pid
== 0) { // We are the child
806 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
807 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
808 } else if (gdb_pid
< 0)
809 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
811 waitpid(gdb_pid
, NULL
, 0);
813 if (x
== SIGTRAP
) return;
820 extern void mp_input_register_options(m_config_t
* cfg
);
822 #include "cfg-mplayer.h"
824 static void parse_cfgfiles( m_config_t
* conf
)
828 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
830 if ((conffile
= get_path("")) == NULL
) {
831 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
836 mkdir(conffile
, 0777);
839 if ((conffile
= get_path("config")) == NULL
) {
840 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
842 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
843 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
844 write(conffile_fd
, default_config
, strlen(default_config
));
847 if (m_config_parse_config_file(conf
, conffile
) < 0)
854 void load_per_file_config (m_config_t
* conf
, const char *const file
)
857 char cfg
[strlen(file
)+10];
861 sprintf (cfg
, "%s.conf", file
);
863 if (use_filedir_conf
&& !stat (cfg
, &st
))
865 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
866 m_config_parse_config_file (conf
, cfg
);
870 if ((name
= strrchr (cfg
, '/')) == NULL
)
875 if ((confpath
= get_path (name
)) != NULL
)
877 if (!stat (confpath
, &st
))
879 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
880 m_config_parse_config_file (conf
, confpath
);
887 /* When libmpdemux performs a blocking operation (network connection or
888 * cache filling) if the operation fails we use this function to check
889 * if it was interrupted by the user.
890 * The function returns a new value for eof. */
891 static int libmpdemux_was_interrupted(int eof
) {
893 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
896 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
897 case MP_CMD_PLAY_TREE_STEP
: {
898 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
899 play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
901 case MP_CMD_PLAY_TREE_UP_STEP
: {
902 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
904 case MP_CMD_PLAY_ALT_SRC_STEP
: {
905 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
913 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
915 int playtree_add_playlist(play_tree_t
* entry
)
917 play_tree_add_bpf(entry
,filename
);
922 import_playtree_playlist_into_gui(entry
, mconfig
);
923 play_tree_free_list(entry
,1);
929 entry
= playtree_iter
->tree
;
930 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
931 return PT_NEXT_ENTRY
;
933 if(playtree_iter
->tree
== entry
) { // Loop with a single file
934 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
935 return PT_NEXT_ENTRY
;
938 play_tree_remove(entry
,1,1);
941 play_tree_insert_entry(playtree_iter
->tree
,entry
);
942 play_tree_set_params_from(entry
,playtree_iter
->tree
);
943 entry
= playtree_iter
->tree
;
944 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
945 return PT_NEXT_ENTRY
;
947 play_tree_remove(entry
,1,1);
957 for (i
= 0; i
< SUB_SOURCES
; i
++) {
958 int j
= global_sub_indices
[i
];
959 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
967 void add_subtitles(char *filename
, float fps
, int silent
)
971 ass_track_t
*asst
= 0;
974 if (filename
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
978 subd
= sub_read_file(filename
, fps
);
982 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
984 asst
= ass_read_file(ass_library
, filename
, 0);
986 if (ass_enabled
&& subd
&& !asst
)
987 asst
= ass_read_subdata(ass_library
, subd
, fps
);
989 if (!asst
&& !subd
&& !silent
)
993 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
,
994 filename_recode(filename
));
997 if (!asst
&& !subd
) return;
998 set_of_ass_tracks
[set_of_sub_size
] = asst
;
1002 set_of_subtitles
[set_of_sub_size
] = subd
;
1003 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", set_of_sub_size
);
1004 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
1005 filename_recode(filename
));
1007 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, set_of_sub_size
,
1008 filename_recode(filename
));
1011 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1012 void update_set_of_subtitles(void)
1013 // subdata was changed, set_of_sub... have to be updated.
1016 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
1017 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
1018 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
1019 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
1021 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
1023 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
1024 set_of_subtitles
[set_of_sub_pos
] = subdata
;
1026 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
1027 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
1032 void init_vo_spudec(void) {
1034 spudec_free(vo_spudec
);
1035 inited_flags
&= ~INITED_SPUDEC
;
1038 unsigned int palette
[16], width
, height
;
1039 current_module
="spudec_init_vobsub";
1040 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1041 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1045 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
1046 current_module
="spudec_init_dvdread";
1047 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
1048 sh_video
->disp_w
, sh_video
->disp_h
);
1053 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
1054 unsigned int *palette
= mp_dvdnav_get_spu_clut(stream
);
1055 current_module
="spudec_init_dvdnav";
1056 vo_spudec
=spudec_new_scaled(palette
, sh_video
->disp_w
, sh_video
->disp_h
);
1060 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1061 (d_dvdsub
->sh
!= NULL
) && (((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
1062 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)d_dvdsub
->sh
;
1063 current_module
= "spudec_init_matroska";
1065 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1066 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1067 mkv_sh_sub
->height
);
1068 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1071 if (vo_spudec
==NULL
) {
1072 sh_sub_t
*sh
= (sh_sub_t
*)d_dvdsub
->sh
;
1073 unsigned int *palette
= NULL
;
1074 if (sh
&& sh
->has_palette
)
1075 palette
= sh
->palette
;
1076 current_module
="spudec_init_normal";
1077 vo_spudec
=spudec_new_scaled(palette
, sh_video
->disp_w
, sh_video
->disp_h
);
1078 spudec_set_font_factor(vo_spudec
,font_factor
);
1081 if (vo_spudec
!=NULL
)
1082 inited_flags
|=INITED_SPUDEC
;
1086 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1087 * make it all work is to use the builtin SDL-bootstrap code, which
1088 * will be done automatically by replacing our main() if we include SDL.h.
1090 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1095 * \brief append a formatted string
1096 * \param buf buffer to print into
1097 * \param pos position of terminating 0 in buf
1098 * \param len maximum number of characters in buf, not including terminating 0
1099 * \param format printf format string
1101 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1104 va_start(va
, format
);
1105 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1114 * \brief append time in the hh:mm:ss.f format
1115 * \param buf buffer to print into
1116 * \param pos position of terminating 0 in buf
1117 * \param len maximum number of characters in buf, not including terminating 0
1118 * \param time time value to convert/append
1120 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1121 long tenths
= 10 * time
;
1122 int f1
= tenths
% 10;
1123 int ss
= (tenths
/ 10) % 60;
1124 int mm
= (tenths
/ 600) % 60;
1125 int hh
= tenths
/ 36000;
1127 saddf(buf
, pos
, len
, "unknown");
1131 saddf(buf
, pos
, len
, "%2d:", hh
);
1132 if (hh
> 0 || mm
> 0)
1133 saddf(buf
, pos
, len
, "%02d:", mm
);
1134 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1138 * \brief print the status line
1139 * \param a_pos audio position
1140 * \param a_v A-V desynchronization
1141 * \param corr amount out A-V synchronization
1143 static void print_status(float a_pos
, float a_v
, float corr
)
1149 if (screen_width
> 0)
1150 width
= screen_width
;
1154 /* Windows command line is broken (MinGW's rxvt works, but we
1155 * should not depend on that). */
1158 line
= malloc(width
+ 1); // one additional char for the terminating null
1162 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1164 float len
= demuxer_get_time_length(demuxer
);
1165 saddf(line
, &pos
, width
, "(");
1166 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1167 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1168 sadd_hhmmssf(line
, &pos
, width
, len
);
1169 saddf(line
, &pos
, width
, ") ");
1175 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1178 if (sh_audio
&& sh_video
)
1179 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1183 saddf(line
, &pos
, width
, "%3d/%3d ",
1184 (int)sh_video
->num_frames
,
1185 (int)sh_video
->num_frames_decoded
);
1189 if (sh_video
->timer
> 0.5)
1190 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1191 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
1192 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
1193 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
1195 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1196 } else if (sh_audio
) {
1197 if (sh_audio
->delay
> 0.5)
1198 saddf(line
, &pos
, width
, "%4.1f%% ",
1199 100.0*audio_time_usage
/(double)sh_audio
->delay
);
1201 saddf(line
, &pos
, width
, "??,?%% ");
1206 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1208 #ifdef USE_STREAM_CACHE
1210 if (stream_cache_size
> 0)
1211 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1215 if (playback_speed
!= 1)
1216 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
1219 if (erase_to_end_of_line
) {
1221 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1223 memset(&line
[pos
], ' ', width
- pos
);
1225 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
1231 * \brief build a chain of audio filters that converts the input format
1232 * to the ao's format, taking into account the current playback_speed.
1233 * \param sh_audio describes the requested input format of the chain.
1234 * \param ao_data describes the requested output format of the chain.
1236 static int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1243 guiGetEvent(guiSetAfilter
, (char *)NULL
);
1245 mixer
.afilter
= NULL
;
1248 new_srate
= sh_audio
->samplerate
* playback_speed
;
1249 if (new_srate
!= ao_data
->samplerate
) {
1250 // limits are taken from libaf/af_resample.c
1251 if (new_srate
< 8000)
1253 if (new_srate
> 192000)
1255 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1257 result
= init_audio_filters(sh_audio
, new_srate
,
1258 sh_audio
->channels
, sh_audio
->sample_format
,
1259 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1260 ao_data
->outburst
* 4, ao_data
->buffersize
);
1261 mixer
.afilter
= sh_audio
->afilter
;
1263 guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1269 * \brief Log the currently displayed subtitle to a file
1271 * Logs the current or last displayed subtitle together with filename
1272 * and time information to ~/.mplayer/subtitle_log
1274 * Intended purpose is to allow convenient marking of bogus subtitles
1275 * which need to be fixed while watching the movie.
1278 static void log_sub(void){
1283 if (subdata
== NULL
|| vo_sub_last
== NULL
) return;
1284 fname
= get_path("subtitle_log");
1285 f
= fopen(fname
, "a");
1287 fprintf(f
, "----------------------------------------------------------\n");
1288 if (subdata
->sub_uses_time
) {
1289 fprintf(f
, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename
,
1290 vo_sub_last
->start
/360000, (vo_sub_last
->start
/6000)%60,
1291 (vo_sub_last
->start
/100)%60, vo_sub_last
->start
%100,
1292 vo_sub_last
->end
/360000, (vo_sub_last
->end
/6000)%60,
1293 (vo_sub_last
->end
/100)%60, vo_sub_last
->end
%100);
1295 fprintf(f
, "N: %s S: %ld E: %ld\n", filename
, vo_sub_last
->start
, vo_sub_last
->end
);
1297 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
1298 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
1303 /// \defgroup OSDMsgStack OSD message stack
1307 #define OSD_MSG_TV_CHANNEL 0
1308 #define OSD_MSG_TEXT 1
1309 #define OSD_MSG_SUB_DELAY 2
1310 #define OSD_MSG_SPEED 3
1311 #define OSD_MSG_OSD_STATUS 4
1312 #define OSD_MSG_BAR 5
1313 #define OSD_MSG_PAUSE 6
1314 #define OSD_MSG_RADIO_CHANNEL 7
1315 /// Base id for messages generated from the commmand to property bridge.
1316 #define OSD_MSG_PROPERTY 0x100
1319 typedef struct mp_osd_msg mp_osd_msg_t
;
1321 /// Previous message on the stack.
1325 int id
,level
,started
;
1326 /// Display duration in ms.
1330 /// OSD message stack.
1331 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1334 * \brief Add a message on the OSD message stack
1336 * If a message with the same id is already present in the stack
1337 * it is pulled on top of the stack, otherwise a new message is created.
1341 static void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1342 mp_osd_msg_t
*msg
,*last
=NULL
;
1346 // look if the id is already in the stack
1347 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1348 last
= msg
, msg
= msg
->prev
);
1349 // not found: alloc it
1351 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1352 msg
->prev
= osd_msg_stack
;
1353 osd_msg_stack
= msg
;
1354 } else if(last
) { // found, but it's not on top of the stack
1355 last
->prev
= msg
->prev
;
1356 msg
->prev
= osd_msg_stack
;
1357 osd_msg_stack
= msg
;
1361 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1363 if(r
>= 64) msg
->msg
[63] = 0;
1372 * \brief Remove a message from the OSD stack
1374 * This function can be used to get rid of a message right away.
1378 static void rm_osd_msg(int id
) {
1379 mp_osd_msg_t
*msg
,*last
=NULL
;
1381 // Search for the msg
1382 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1383 last
= msg
, msg
= msg
->prev
);
1386 // Detach it from the stack and free it
1388 last
->prev
= msg
->prev
;
1390 osd_msg_stack
= msg
->prev
;
1395 * \brief Remove all messages from the OSD stack
1399 static void clear_osd_msgs(void) {
1400 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1406 osd_msg_stack
= NULL
;
1410 * \brief Get the current message from the OSD stack.
1412 * This function decrements the message timer and destroys the old ones.
1413 * The message that should be displayed is returned (if any).
1417 static mp_osd_msg_t
* get_osd_msg(void) {
1418 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1419 static unsigned last_update
= 0;
1420 unsigned now
= GetTimerMS();
1422 char hidden_dec_done
= 0;
1424 if(!last_update
) last_update
= now
;
1425 diff
= now
>= last_update
? now
- last_update
: 0;
1429 // Look for the first message in the stack with high enough level.
1430 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1432 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1433 // The message has a high enough level or it is the first hidden one
1434 // in both cases we decrement the timer or kill it.
1435 if(!msg
->started
|| msg
->time
> diff
) {
1436 if(msg
->started
) msg
->time
-= diff
;
1437 else msg
->started
= 1;
1439 if(msg
->level
<= osd_level
) return msg
;
1440 hidden_dec_done
= 1;
1449 osd_msg_stack
= prev
;
1458 * \brief Display the OSD bar.
1460 * Display the OSD bar or fall back on a simple message.
1464 static void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1466 if(osd_level
< 1) return;
1469 osd_visible
= (GetTimerMS() + 1000) | 1;
1470 vo_osd_progbar_type
= type
;
1471 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1472 vo_osd_changed(OSDTYPE_PROGBAR
);
1476 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1477 name
,ROUND(100*(val
-min
)/(max
-min
)));
1482 * \brief Update the OSD message line.
1484 * This function displays the current message on the vo OSD or on the term.
1485 * If the stack is empty and the OSD level is high enough the timer
1486 * is displayed (only on the vo OSD).
1490 static void update_osd_msg(void) {
1492 static char osd_text
[64] = "";
1493 static char osd_text_timer
[64];
1495 // we need some mem for vo_osd_text
1496 vo_osd_text
= (unsigned char*)osd_text
;
1498 // Look if we have a msg
1499 if((msg
= get_osd_msg())) {
1500 if(strcmp(osd_text
,msg
->msg
)) {
1501 strncpy((char*)osd_text
, msg
->msg
, 63);
1502 if(sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1503 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1509 // fallback on the timer
1511 int len
= demuxer_get_time_length(demuxer
);
1512 int percentage
= -1;
1513 char percentage_text
[10];
1514 int pts
= demuxer_get_current_time(demuxer
);
1516 if (osd_show_percentage
)
1517 percentage
= demuxer_get_percent_pos(demuxer
);
1519 if (percentage
>= 0)
1520 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1522 percentage_text
[0] = 0;
1525 snprintf(osd_text_timer
, 63,
1526 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1527 osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1528 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1530 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1531 osd_function
,pts
/3600,(pts
/60)%60,
1532 pts
%60,percentage_text
);
1534 osd_text_timer
[0]=0;
1536 // always decrement the percentage timer
1537 if(osd_show_percentage
)
1538 osd_show_percentage
--;
1540 if(strcmp(osd_text
,osd_text_timer
)) {
1541 strncpy(osd_text
, osd_text_timer
, 63);
1542 vo_osd_changed(OSDTYPE_OSD
);
1547 // Clear the term osd line
1548 if(term_osd
&& osd_text
[0]) {
1550 printf("%s\n",term_osd_esc
);
1557 /// \defgroup Properties
1560 /// \defgroup GeneralProperties General properties
1561 /// \ingroup Properties
1565 static int mp_property_osdlevel(m_option_t
* prop
,int action
,void* arg
) {
1566 return m_property_choice(prop
,action
,arg
,&osd_level
);
1569 /// Playback speed (RW)
1570 static int mp_property_playback_speed(m_option_t
* prop
,int action
,void* arg
) {
1572 case M_PROPERTY_SET
:
1573 if(!arg
) return M_PROPERTY_ERROR
;
1574 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1575 playback_speed
= *(float*)arg
;
1576 build_afilter_chain(sh_audio
, &ao_data
);
1577 return M_PROPERTY_OK
;
1578 case M_PROPERTY_STEP_UP
:
1579 case M_PROPERTY_STEP_DOWN
:
1580 playback_speed
+= (arg
? *(float*)arg
: 0.1) *
1581 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1582 M_PROPERTY_CLAMP(prop
,playback_speed
);
1583 build_afilter_chain(sh_audio
, &ao_data
);
1584 return M_PROPERTY_OK
;
1586 return m_property_float_range(prop
,action
,arg
,&playback_speed
);
1589 /// filename with path (RO)
1590 static int mp_property_path(m_option_t
* prop
,int action
,void* arg
) {
1591 return m_property_string_ro(prop
,action
,arg
,filename
);
1594 /// filename without path (RO)
1595 static int mp_property_filename(m_option_t
* prop
,int action
,void* arg
) {
1597 if(!filename
) return M_PROPERTY_UNAVAILABLE
;
1598 if(((f
= strrchr(filename
,'/')) || (f
= strrchr(filename
,'\\'))) && f
[1])
1602 return m_property_string_ro(prop
,action
,arg
,f
);
1605 /// Demuxer name (RO)
1606 static int mp_property_demuxer(m_option_t
* prop
,int action
,void* arg
) {
1607 if(!demuxer
) return M_PROPERTY_UNAVAILABLE
;
1608 return m_property_string_ro(prop
,action
,arg
,(char*)demuxer
->desc
->name
);
1611 /// Position in the stream (RW)
1612 static int mp_property_stream_pos(m_option_t
* prop
,int action
,void* arg
) {
1613 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1614 if (!arg
) return M_PROPERTY_ERROR
;
1616 case M_PROPERTY_GET
:
1617 *(off_t
*)arg
= stream_tell(demuxer
->stream
);
1618 return M_PROPERTY_OK
;
1619 case M_PROPERTY_SET
:
1620 M_PROPERTY_CLAMP(prop
,*(off_t
*)arg
);
1621 stream_seek(demuxer
->stream
, *(off_t
*)arg
);
1622 return M_PROPERTY_OK
;
1624 return M_PROPERTY_NOT_IMPLEMENTED
;
1627 /// Stream start offset (RO)
1628 static int mp_property_stream_start(m_option_t
* prop
,int action
,void* arg
) {
1629 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1631 case M_PROPERTY_GET
:
1632 *(off_t
*)arg
= demuxer
->stream
->start_pos
;
1633 return M_PROPERTY_OK
;
1635 return M_PROPERTY_NOT_IMPLEMENTED
;
1638 /// Stream end offset (RO)
1639 static int mp_property_stream_end(m_option_t
* prop
,int action
,void* arg
) {
1640 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1642 case M_PROPERTY_GET
:
1643 *(off_t
*)arg
= demuxer
->stream
->end_pos
;
1644 return M_PROPERTY_OK
;
1646 return M_PROPERTY_NOT_IMPLEMENTED
;
1649 /// Stream length (RO)
1650 static int mp_property_stream_length(m_option_t
* prop
,int action
,void* arg
) {
1651 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1653 case M_PROPERTY_GET
:
1654 *(off_t
*)arg
= demuxer
->stream
->end_pos
- demuxer
->stream
->start_pos
;
1655 return M_PROPERTY_OK
;
1657 return M_PROPERTY_NOT_IMPLEMENTED
;
1660 /// Media length in seconds (RO)
1661 static int mp_property_length(m_option_t
* prop
,int action
,void* arg
) {
1665 !(int)(len
= demuxer_get_time_length(demuxer
)))
1666 return M_PROPERTY_UNAVAILABLE
;
1669 case M_PROPERTY_PRINT
:
1670 if(!arg
) return M_PROPERTY_ERROR
;
1677 *(char**)arg
= malloc(20);
1678 if(h
> 0) sprintf(*(char**)arg
,"%d:%02d:%02d",h
,m
,s
);
1679 else if(m
> 0) sprintf(*(char**)arg
,"%d:%02d",m
,s
);
1680 else sprintf(*(char**)arg
,"%d",s
);
1681 return M_PROPERTY_OK
;
1685 return m_property_double_ro(prop
,action
,arg
,len
);
1690 /// \defgroup AudioProperties Audio properties
1691 /// \ingroup Properties
1695 static int mp_property_volume(m_option_t
* prop
,int action
,void* arg
) {
1697 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1700 case M_PROPERTY_GET
:
1701 if(!arg
) return M_PROPERTY_ERROR
;
1702 mixer_getbothvolume(&mixer
,arg
);
1703 return M_PROPERTY_OK
;
1704 case M_PROPERTY_PRINT
:{
1706 if(!arg
) return M_PROPERTY_ERROR
;
1707 mixer_getbothvolume(&mixer
,&vol
);
1708 return m_property_float_range(prop
,action
,arg
,&vol
);
1710 case M_PROPERTY_STEP_UP
:
1711 case M_PROPERTY_STEP_DOWN
:
1712 case M_PROPERTY_SET
:
1715 return M_PROPERTY_NOT_IMPLEMENTED
;
1718 if (edl_muted
) return M_PROPERTY_DISABLED
;
1722 case M_PROPERTY_SET
:
1723 if(!arg
) return M_PROPERTY_ERROR
;
1724 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1725 mixer_setvolume(&mixer
,*(float*)arg
,*(float*)arg
);
1726 return M_PROPERTY_OK
;
1727 case M_PROPERTY_STEP_UP
:
1728 if(arg
&& *(float*)arg
<= 0)
1729 mixer_decvolume(&mixer
);
1731 mixer_incvolume(&mixer
);
1732 return M_PROPERTY_OK
;
1733 case M_PROPERTY_STEP_DOWN
:
1734 if(arg
&& *(float*)arg
<= 0)
1735 mixer_incvolume(&mixer
);
1737 mixer_decvolume(&mixer
);
1738 return M_PROPERTY_OK
;
1740 return M_PROPERTY_NOT_IMPLEMENTED
;
1744 static int mp_property_mute(m_option_t
* prop
,int action
,void* arg
) {
1746 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1749 case M_PROPERTY_SET
:
1750 if(edl_muted
) return M_PROPERTY_DISABLED
;
1751 if(!arg
) return M_PROPERTY_ERROR
;
1752 if((!!*(int*)arg
) != mixer
.muted
)
1754 user_muted
= mixer
.muted
;
1755 return M_PROPERTY_OK
;
1756 case M_PROPERTY_STEP_UP
:
1757 case M_PROPERTY_STEP_DOWN
:
1758 if(edl_muted
) return M_PROPERTY_DISABLED
;
1760 user_muted
= mixer
.muted
;
1761 return M_PROPERTY_OK
;
1762 case M_PROPERTY_PRINT
:
1763 if(!arg
) return M_PROPERTY_ERROR
;
1765 *(char**)arg
= strdup(MSGTR_EnabledEdl
);
1766 return M_PROPERTY_OK
;
1769 return m_property_flag(prop
,action
,arg
,&mixer
.muted
);
1774 /// Audio delay (RW)
1775 static int mp_property_audio_delay(m_option_t
* prop
,int action
,void* arg
) {
1776 if(!(sh_audio
&& sh_video
)) return M_PROPERTY_UNAVAILABLE
;
1778 case M_PROPERTY_SET
:
1779 case M_PROPERTY_STEP_UP
:
1780 case M_PROPERTY_STEP_DOWN
:
1781 if(!arg
) return M_PROPERTY_ERROR
;
1783 float delay
= audio_delay
;
1784 m_property_delay(prop
,action
,arg
,&audio_delay
);
1785 if(sh_audio
) sh_audio
->delay
-= audio_delay
-delay
;
1787 return M_PROPERTY_OK
;
1789 return m_property_delay(prop
,action
,arg
,&audio_delay
);
1793 /// Audio codec tag (RO)
1794 static int mp_property_audio_format(m_option_t
* prop
,int action
,void* arg
) {
1795 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1796 return m_property_int_ro(prop
,action
,arg
,sh_audio
->format
);
1799 /// Audio bitrate (RO)
1800 static int mp_property_audio_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1801 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1802 return m_property_int_ro(prop
,action
,arg
,sh_audio
->i_bps
);
1806 static int mp_property_samplerate(m_option_t
* prop
,int action
,void* arg
) {
1807 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1808 return m_property_int_ro(prop
,action
,arg
,sh_audio
->samplerate
);
1811 /// Number of channels (RO)
1812 static int mp_property_channels(m_option_t
* prop
,int action
,void* arg
) {
1813 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1815 case M_PROPERTY_PRINT
:
1816 if(!arg
) return M_PROPERTY_ERROR
;
1817 switch(sh_audio
->channels
) {
1818 case 1: *(char**)arg
= strdup("mono"); break;
1819 case 2: *(char**)arg
= strdup("stereo"); break;
1821 *(char**)arg
= malloc(32);
1822 sprintf(*(char**)arg
,"%d channels",sh_audio
->channels
);
1824 return M_PROPERTY_OK
;
1826 return m_property_int_ro(prop
,action
,arg
,sh_audio
->channels
);
1829 /// Selected audio id (RW)
1830 static int mp_property_audio(m_option_t
* prop
,int action
,void* arg
) {
1831 int current_id
= -1, tmp
;
1834 case M_PROPERTY_GET
:
1835 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1836 if(!arg
) return M_PROPERTY_ERROR
;
1837 *(int*)arg
= audio_id
;
1838 return M_PROPERTY_OK
;
1839 case M_PROPERTY_PRINT
:
1840 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1841 if(!arg
) return M_PROPERTY_ERROR
;
1844 *(char**)arg
= strdup(MSGTR_Disabled
);
1846 char lang
[40] = MSGTR_Unknown
;
1847 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
)
1848 demux_mkv_get_audio_lang(demuxer
, audio_id
, lang
, 9);
1850 else if(stream
->type
== STREAMTYPE_DVD
) {
1851 int code
= dvd_lang_from_aid(stream
, audio_id
);
1853 lang
[0] = code
>> 8;
1861 else if(stream
->type
== STREAMTYPE_DVDNAV
)
1862 dvdnav_lang_from_aid(stream
, audio_id
, lang
);
1864 *(char**)arg
= malloc(64);
1865 snprintf(*(char**)arg
, 64, "(%d) %s", audio_id
, lang
);
1867 return M_PROPERTY_OK
;
1869 case M_PROPERTY_STEP_UP
:
1870 case M_PROPERTY_SET
:
1871 if(action
==M_PROPERTY_SET
&& arg
)
1875 current_id
= demuxer
->audio
->id
;
1876 audio_id
= demuxer_switch_audio(demuxer
, tmp
);
1877 if(audio_id
== -2 || (audio_id
> -1 && demuxer
->audio
->id
!= current_id
&& current_id
!= -2))
1878 uninit_player(INITED_AO
| INITED_ACODEC
);
1879 if(audio_id
> -1 && demuxer
->audio
->id
!= current_id
) {
1881 sh2
= demuxer
->a_streams
[demuxer
->audio
->id
];
1883 sh2
->ds
= demuxer
->audio
;
1885 reinit_audio_chain();
1888 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", audio_id
);
1889 return M_PROPERTY_OK
;
1891 return M_PROPERTY_NOT_IMPLEMENTED
;
1896 static int reinit_video_chain(void);
1897 /// Selected video id (RW)
1898 static int mp_property_video(m_option_t
* prop
,int action
,void* arg
) {
1899 int current_id
= -1, tmp
;
1902 case M_PROPERTY_GET
:
1903 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1904 if(!arg
) return M_PROPERTY_ERROR
;
1905 *(int*)arg
= video_id
;
1906 return M_PROPERTY_OK
;
1907 case M_PROPERTY_PRINT
:
1908 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1909 if(!arg
) return M_PROPERTY_ERROR
;
1912 *(char**)arg
= strdup(MSGTR_Disabled
);
1914 char lang
[40] = MSGTR_Unknown
;
1915 *(char**)arg
= malloc(64);
1916 snprintf(*(char**)arg
, 64, "(%d) %s", video_id
, lang
);
1918 return M_PROPERTY_OK
;
1920 case M_PROPERTY_STEP_UP
:
1921 case M_PROPERTY_SET
:
1922 current_id
= demuxer
->video
->id
;
1923 if(action
==M_PROPERTY_SET
&& arg
)
1927 video_id
= demuxer_switch_video(demuxer
, tmp
);
1928 if(video_id
== -2 || (video_id
> -1 && demuxer
->video
->id
!= current_id
&& current_id
!= -2))
1929 uninit_player(INITED_VCODEC
| (fixed_vo
&& video_id
!= -2 ? 0 : INITED_VO
));
1930 if(video_id
> -1 && demuxer
->video
->id
!= current_id
) {
1932 sh2
= demuxer
->v_streams
[demuxer
->video
->id
];
1934 sh2
->ds
= demuxer
->video
;
1936 reinit_video_chain();
1939 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_TRACK=%d\n", video_id
);
1940 return M_PROPERTY_OK
;
1943 return M_PROPERTY_NOT_IMPLEMENTED
;
1947 static int mp_property_program(m_option_t
* prop
,int action
,void* arg
) {
1948 demux_program_t prog
;
1951 case M_PROPERTY_STEP_UP
:
1952 case M_PROPERTY_SET
:
1953 if(action
==M_PROPERTY_SET
&& arg
)
1954 prog
.progid
= *((int*)arg
);
1957 if(demux_control(demuxer
, DEMUXER_CTRL_IDENTIFY_PROGRAM
, &prog
) == DEMUXER_CTRL_NOTIMPL
)
1958 return M_PROPERTY_ERROR
;
1960 mp_property_do("switch_audio", M_PROPERTY_SET
, &prog
.aid
);
1961 mp_property_do("switch_video", M_PROPERTY_SET
, &prog
.vid
);
1962 return M_PROPERTY_OK
;
1965 return M_PROPERTY_NOT_IMPLEMENTED
;
1971 /// \defgroup VideoProperties Video properties
1972 /// \ingroup Properties
1975 /// Fullscreen state (RW)
1976 static int mp_property_fullscreen(m_option_t
* prop
,int action
,void* arg
) {
1978 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1981 case M_PROPERTY_SET
:
1982 if(!arg
) return M_PROPERTY_ERROR
;
1983 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1984 if(vo_fs
== !!*(int*)arg
) return M_PROPERTY_OK
;
1985 case M_PROPERTY_STEP_UP
:
1986 case M_PROPERTY_STEP_DOWN
:
1988 if(use_gui
) guiGetEvent(guiIEvent
,(char*)MP_CMD_GUI_FULLSCREEN
);
1991 if(vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
1992 return M_PROPERTY_OK
;
1994 return m_property_flag(prop
,action
,arg
,&vo_fs
);
1998 static int mp_property_deinterlace(m_option_t
* prop
,int action
,void* arg
) {
2001 if (!sh_video
|| !sh_video
->vfilter
) return M_PROPERTY_UNAVAILABLE
;
2002 vf
= sh_video
->vfilter
;
2004 case M_PROPERTY_GET
:
2005 if(!arg
) return M_PROPERTY_ERROR
;
2006 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, arg
);
2007 return M_PROPERTY_OK
;
2008 case M_PROPERTY_SET
:
2009 if(!arg
) return M_PROPERTY_ERROR
;
2010 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2011 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, arg
);
2012 return M_PROPERTY_OK
;
2013 case M_PROPERTY_STEP_UP
:
2014 case M_PROPERTY_STEP_DOWN
:
2015 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, &deinterlace
);
2016 deinterlace
= !deinterlace
;
2017 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, &deinterlace
);
2018 return M_PROPERTY_OK
;
2020 return M_PROPERTY_NOT_IMPLEMENTED
;
2024 static int mp_property_panscan(m_option_t
* prop
,int action
,void* arg
) {
2026 if(!video_out
|| video_out
->control(VOCTRL_GET_PANSCAN
,NULL
) != VO_TRUE
)
2027 return M_PROPERTY_UNAVAILABLE
;
2030 case M_PROPERTY_SET
:
2031 if(!arg
) return M_PROPERTY_ERROR
;
2032 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
2033 vo_panscan
= *(float*)arg
;
2034 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
2035 return M_PROPERTY_OK
;
2036 case M_PROPERTY_STEP_UP
:
2037 case M_PROPERTY_STEP_DOWN
:
2038 vo_panscan
+= (arg
? *(float*)arg
: 0.1) *
2039 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2040 if(vo_panscan
> 1) vo_panscan
= 1;
2041 else if(vo_panscan
< 0) vo_panscan
= 0;
2042 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
2043 return M_PROPERTY_OK
;
2045 return m_property_float_range(prop
,action
,arg
,&vo_panscan
);
2049 /// Helper to set vo flags.
2050 /** \ingroup PropertyImplHelper
2052 static int mp_property_vo_flag(m_option_t
* prop
,int action
,void* arg
,
2053 int vo_ctrl
,int* vo_var
) {
2055 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
2058 case M_PROPERTY_SET
:
2059 if(!arg
) return M_PROPERTY_ERROR
;
2060 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2061 if(*vo_var
== !!*(int*)arg
) return M_PROPERTY_OK
;
2062 case M_PROPERTY_STEP_UP
:
2063 case M_PROPERTY_STEP_DOWN
:
2064 if(vo_config_count
) video_out
->control(vo_ctrl
, 0);
2065 return M_PROPERTY_OK
;
2067 return m_property_flag(prop
,action
,arg
,vo_var
);
2071 /// Window always on top (RW)
2072 static int mp_property_ontop(m_option_t
* prop
,int action
,void* arg
) {
2073 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ONTOP
,&vo_ontop
);
2076 /// Display in the root window (RW)
2077 static int mp_property_rootwin(m_option_t
* prop
,int action
,void* arg
) {
2078 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ROOTWIN
,&vo_rootwin
);
2081 /// Show window borders (RW)
2082 static int mp_property_border(m_option_t
* prop
,int action
,void* arg
) {
2083 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_BORDER
,&vo_border
);
2086 /// Framedropping state (RW)
2087 static int mp_property_framedropping(m_option_t
* prop
,int action
,void* arg
) {
2089 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2092 case M_PROPERTY_PRINT
:
2093 if(!arg
) return M_PROPERTY_ERROR
;
2094 *(char**)arg
= strdup(frame_dropping
== 1 ? MSGTR_Enabled
:
2095 (frame_dropping
== 2 ? MSGTR_HardFrameDrop
: MSGTR_Disabled
));
2096 return M_PROPERTY_OK
;
2098 return m_property_choice(prop
,action
,arg
,&frame_dropping
);
2102 /// Color settings, try to use vf/vo then fall back on TV. (RW)
2103 static int mp_property_gamma(m_option_t
* prop
,int action
,void* arg
) {
2104 int* gamma
= prop
->priv
, r
;
2106 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2108 if(gamma
[0] == 1000) {
2110 get_video_colors (sh_video
, prop
->name
, gamma
);
2114 case M_PROPERTY_SET
:
2115 if(!arg
) return M_PROPERTY_ERROR
;
2116 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2117 *gamma
= *(int*)arg
;
2118 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
2121 case M_PROPERTY_GET
:
2122 if(!arg
) return M_PROPERTY_ERROR
;
2123 r
= get_video_colors (sh_video
, prop
->name
, arg
);
2126 case M_PROPERTY_STEP_UP
:
2127 case M_PROPERTY_STEP_DOWN
:
2128 *gamma
+= (arg
? *(int*)arg
: 1) *
2129 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2130 M_PROPERTY_CLAMP(prop
,*gamma
);
2131 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
2135 return M_PROPERTY_NOT_IMPLEMENTED
;
2139 if(demuxer
->type
== DEMUXER_TYPE_TV
) {
2140 int l
= strlen(prop
->name
);
2141 char tv_prop
[3+l
+1];
2142 sprintf(tv_prop
,"tv_%s",prop
->name
);
2143 return mp_property_do(tv_prop
,action
,arg
);
2147 return M_PROPERTY_UNAVAILABLE
;
2151 static int mp_property_vsync(m_option_t
* prop
,int action
,void* arg
) {
2152 return m_property_flag(prop
,action
,arg
,&vo_vsync
);
2155 /// Video codec tag (RO)
2156 static int mp_property_video_format(m_option_t
* prop
,int action
,void* arg
) {
2157 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2158 return m_property_int_ro(prop
,action
,arg
,sh_video
->format
);
2161 /// Video bitrate (RO)
2162 static int mp_property_video_bitrate(m_option_t
* prop
,int action
,void* arg
) {
2163 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2164 return m_property_int_ro(prop
,action
,arg
,sh_video
->i_bps
);
2167 /// Video display width (RO)
2168 static int mp_property_width(m_option_t
* prop
,int action
,void* arg
) {
2169 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2170 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_w
);
2173 /// Video display height (RO)
2174 static int mp_property_height(m_option_t
* prop
,int action
,void* arg
) {
2175 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2176 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_h
);
2180 static int mp_property_fps(m_option_t
* prop
,int action
,void* arg
) {
2181 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2182 return m_property_float_ro(prop
,action
,arg
,sh_video
->fps
);
2185 /// Video aspect (RO)
2186 static int mp_property_aspect(m_option_t
* prop
,int action
,void* arg
) {
2187 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2188 return m_property_float_ro(prop
,action
,arg
,sh_video
->aspect
);
2193 /// \defgroup SubProprties Subtitles properties
2194 /// \ingroup Properties
2197 /// Text subtitle position (RW)
2198 static int mp_property_sub_pos(m_option_t
* prop
,int action
,void* arg
) {
2199 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2202 case M_PROPERTY_SET
:
2203 if(!arg
) return M_PROPERTY_ERROR
;
2204 case M_PROPERTY_STEP_UP
:
2205 case M_PROPERTY_STEP_DOWN
:
2206 vo_osd_changed(OSDTYPE_SUBTITLE
);
2208 return m_property_int_range(prop
,action
,arg
,&sub_pos
);
2212 /// Selected subtitles (RW)
2213 static int mp_property_sub(m_option_t
* prop
,int action
,void* arg
) {
2214 int source
= -1, reset_spu
= 0;
2217 if(global_sub_size
<= 0) return M_PROPERTY_UNAVAILABLE
;
2220 case M_PROPERTY_GET
:
2221 if(!arg
) return M_PROPERTY_ERROR
;
2222 *(int*)arg
= global_sub_pos
;
2223 return M_PROPERTY_OK
;
2224 case M_PROPERTY_PRINT
:
2225 if(!arg
) return M_PROPERTY_ERROR
;
2226 *(char**)arg
= malloc(64);
2227 (*(char**)arg
)[63] = 0;
2230 sub_name
= subdata
->filename
;
2232 if (ass_track
&& ass_track
->name
)
2233 sub_name
= ass_track
->name
;
2238 if ((tmp2
= strrchr(tmp
, '/')))
2241 snprintf(*(char**)arg
, 63, "(%d) %s%s",
2243 strlen(tmp
) < 20 ? "" : "...",
2244 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
2245 return M_PROPERTY_OK
;
2249 if(stream
->type
==STREAMTYPE_DVDNAV
) {
2250 if(vo_spudec
&& dvdsub_id
>= 0) {
2251 unsigned char lang
[3];
2252 if(dvdnav_lang_from_sid(stream
, dvdsub_id
, lang
)) {
2253 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
2254 return M_PROPERTY_OK
;
2260 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
&& dvdsub_id
>= 0) {
2261 char lang
[40] = MSGTR_Unknown
;
2262 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
2263 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
2264 return M_PROPERTY_OK
;
2266 #ifdef HAVE_OGGVORBIS
2267 if (demuxer
->type
== DEMUXER_TYPE_OGG
&& d_dvdsub
&& dvdsub_id
>= 0) {
2268 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
2269 if (!lang
) lang
= MSGTR_Unknown
;
2270 snprintf(*(char**)arg
, 63, "(%d) %s",
2272 return M_PROPERTY_OK
;
2275 if (vo_vobsub
&& vobsub_id
>= 0) {
2276 const char *language
= MSGTR_Unknown
;
2277 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
2278 snprintf(*(char**)arg
, 63, "(%d) %s",
2279 vobsub_id
, language
? language
: MSGTR_Unknown
);
2280 return M_PROPERTY_OK
;
2283 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
&& dvdsub_id
>= 0) {
2285 int code
= dvd_lang_from_sid(stream
, dvdsub_id
);
2286 lang
[0] = code
>> 8;
2289 snprintf(*(char**)arg
, 63, "(%d) %s",
2291 return M_PROPERTY_OK
;
2294 if (dvdsub_id
>= 0) {
2295 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, MSGTR_Unknown
);
2296 return M_PROPERTY_OK
;
2298 snprintf(*(char**)arg
, 63, MSGTR_Disabled
);
2299 return M_PROPERTY_OK
;
2301 case M_PROPERTY_SET
:
2302 if(!arg
) return M_PROPERTY_ERROR
;
2303 if(*(int*)arg
< -1) *(int*)arg
= -1;
2304 else if(*(int*)arg
>= global_sub_size
) *(int*)arg
= global_sub_size
-1;
2305 global_sub_pos
= *(int*)arg
;
2307 case M_PROPERTY_STEP_UP
:
2308 global_sub_pos
+= 2;
2309 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2311 case M_PROPERTY_STEP_DOWN
:
2312 global_sub_pos
+= global_sub_size
+1;
2313 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2316 return M_PROPERTY_NOT_IMPLEMENTED
;
2319 if (global_sub_pos
>= 0)
2320 source
= sub_source();
2322 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
,
2323 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
2324 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
2325 global_sub_indices
[SUB_SOURCE_SUBS
],
2326 global_sub_indices
[SUB_SOURCE_DEMUX
],
2327 global_sub_pos
, source
);
2329 set_of_sub_pos
= -1;
2331 vo_sub_last
= vo_sub
= NULL
;
2336 if(d_dvdsub
->id
> -2) reset_spu
= 1;
2343 if (source
== SUB_SOURCE_VOBSUB
) {
2344 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
2345 } else if (source
== SUB_SOURCE_SUBS
) {
2346 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
2348 if (ass_enabled
&& set_of_ass_tracks
[set_of_sub_pos
])
2349 ass_track
= set_of_ass_tracks
[set_of_sub_pos
];
2353 subdata
= set_of_subtitles
[set_of_sub_pos
];
2354 vo_osd_changed(OSDTYPE_SUBTITLE
);
2356 } else if (source
== SUB_SOURCE_DEMUX
) {
2357 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
2360 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
2361 d_dvdsub
->id
= dvdsub_id
;
2366 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVDNAV
) {
2367 d_dvdsub
->id
= dvdsub_id
;
2370 if (stream
->type
!= STREAMTYPE_DVD
&& stream
->type
!= STREAMTYPE_DVDNAV
) {
2372 for (d_dvdsub
->id
= 0; d_dvdsub
->id
< MAX_S_STREAMS
; d_dvdsub
->id
++) {
2373 if (demuxer
->s_streams
[d_dvdsub
->id
]) {
2374 if (i
== dvdsub_id
) break;
2378 d_dvdsub
->sh
= demuxer
->s_streams
[d_dvdsub
->id
];
2380 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
2381 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
2383 if (d_dvdsub
->sh
&& d_dvdsub
->id
>= 0) {
2384 sh_sub_t
*sh
= d_dvdsub
->sh
;
2385 if (sh
->type
== 'v')
2388 else if (ass_enabled
&& sh
->type
== 'a')
2389 ass_track
= sh
->ass_track
;
2395 if (vo_spudec
&& (stream
->type
== STREAMTYPE_DVD
|| stream
->type
== STREAMTYPE_DVDNAV
) && dvdsub_id
< 0 && reset_spu
) {
2397 d_dvdsub
->id
= dvdsub_id
;
2400 update_subtitles(sh_video
, d_dvdsub
, 1);
2402 return M_PROPERTY_OK
;
2405 /// Subtitle delay (RW)
2406 static int mp_property_sub_delay(m_option_t
* prop
,int action
,void* arg
) {
2407 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2408 return m_property_delay(prop
,action
,arg
,&sub_delay
);
2411 /// Alignment of text subtitles (RW)
2412 static int mp_property_sub_alignment(m_option_t
* prop
,int action
,void* arg
) {
2413 char* name
[] = { MSGTR_Top
, MSGTR_Center
, MSGTR_Bottom
};
2415 if(!sh_video
|| global_sub_pos
< 0 || sub_source() != SUB_SOURCE_SUBS
)
2416 return M_PROPERTY_UNAVAILABLE
;
2419 case M_PROPERTY_PRINT
:
2420 if(!arg
) return M_PROPERTY_ERROR
;
2421 M_PROPERTY_CLAMP(prop
,sub_alignment
);
2422 *(char**)arg
= strdup(name
[sub_alignment
]);
2423 return M_PROPERTY_OK
;
2424 case M_PROPERTY_SET
:
2425 if(!arg
) return M_PROPERTY_ERROR
;
2426 case M_PROPERTY_STEP_UP
:
2427 case M_PROPERTY_STEP_DOWN
:
2428 vo_osd_changed(OSDTYPE_SUBTITLE
);
2430 return m_property_choice(prop
,action
,arg
,&sub_alignment
);
2434 /// Subtitle visibility (RW)
2435 static int mp_property_sub_visibility(m_option_t
* prop
,int action
,void* arg
) {
2436 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2439 case M_PROPERTY_SET
:
2440 if(!arg
) return M_PROPERTY_ERROR
;
2441 case M_PROPERTY_STEP_UP
:
2442 case M_PROPERTY_STEP_DOWN
:
2443 vo_osd_changed(OSDTYPE_SUBTITLE
);
2444 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2446 return m_property_flag(prop
,action
,arg
,&sub_visibility
);
2450 /// Show only forced subtitles (RW)
2451 static int mp_property_sub_forced_only(m_option_t
* prop
,int action
,void* arg
) {
2452 if(!vo_spudec
) return M_PROPERTY_UNAVAILABLE
;
2455 case M_PROPERTY_SET
:
2456 if(!arg
) return M_PROPERTY_ERROR
;
2457 case M_PROPERTY_STEP_UP
:
2458 case M_PROPERTY_STEP_DOWN
:
2459 m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2460 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
2461 return M_PROPERTY_OK
;
2463 return m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2470 /// \defgroup TVProperties TV properties
2471 /// \ingroup Properties
2476 /// TV color settings (RW)
2477 static int mp_property_tv_color(m_option_t
* prop
,int action
,void* arg
) {
2479 tvi_handle_t
* tvh
= demuxer
->priv
;
2480 if(demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
) return M_PROPERTY_UNAVAILABLE
;
2483 case M_PROPERTY_SET
:
2484 if(!arg
) return M_PROPERTY_ERROR
;
2485 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2486 return tv_set_color_options(tvh
,(int)prop
->priv
,*(int*)arg
);
2487 case M_PROPERTY_GET
:
2488 return tv_get_color_options(tvh
,(int)prop
->priv
,arg
);
2489 case M_PROPERTY_STEP_UP
:
2490 case M_PROPERTY_STEP_DOWN
:
2491 if((r
= tv_get_color_options(tvh
,(int)prop
->priv
,&val
)) >= 0) {
2492 if(!r
) return M_PROPERTY_ERROR
;
2493 val
+= (arg
? *(int*)arg
: 1) *
2494 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2495 M_PROPERTY_CLAMP(prop
,val
);
2496 return tv_set_color_options(tvh
,(int)prop
->priv
,val
);
2498 return M_PROPERTY_ERROR
;
2500 return M_PROPERTY_NOT_IMPLEMENTED
;
2507 /// All properties available in MPlayer.
2508 /** \ingroup Properties
2510 static m_option_t mp_properties
[] = {
2512 { "osdlevel", mp_property_osdlevel
, CONF_TYPE_INT
,
2513 M_OPT_RANGE
, 0, 3, NULL
},
2514 { "speed", mp_property_playback_speed
, CONF_TYPE_FLOAT
,
2515 M_OPT_RANGE
, 0.01, 100.0, NULL
},
2516 { "filename", mp_property_filename
, CONF_TYPE_STRING
,
2518 { "path", mp_property_path
, CONF_TYPE_STRING
,
2520 { "demuxer", mp_property_demuxer
, CONF_TYPE_STRING
,
2522 { "stream_pos", mp_property_stream_pos
, CONF_TYPE_POSITION
,
2523 M_OPT_MIN
, 0, 0, NULL
},
2524 { "stream_start", mp_property_stream_start
, CONF_TYPE_POSITION
,
2525 M_OPT_MIN
, 0, 0, NULL
},
2526 { "stream_end", mp_property_stream_end
, CONF_TYPE_POSITION
,
2527 M_OPT_MIN
, 0, 0, NULL
},
2528 { "stream_length", mp_property_stream_length
, CONF_TYPE_POSITION
,
2529 M_OPT_MIN
, 0, 0, NULL
},
2530 { "length", mp_property_length
, CONF_TYPE_DOUBLE
,
2534 { "volume", mp_property_volume
, CONF_TYPE_FLOAT
,
2535 M_OPT_RANGE
, 0, 100, NULL
},
2536 { "mute", mp_property_mute
, CONF_TYPE_FLAG
,
2537 M_OPT_RANGE
, 0, 1, NULL
},
2538 { "audio_delay", mp_property_audio_delay
, CONF_TYPE_FLOAT
,
2539 M_OPT_RANGE
, -100, 100, NULL
},
2540 { "audio_format", mp_property_audio_format
, CONF_TYPE_INT
,
2542 { "audio_bitrate", mp_property_audio_bitrate
, CONF_TYPE_INT
,
2544 { "samplerate", mp_property_samplerate
, CONF_TYPE_INT
,
2546 { "channels", mp_property_channels
, CONF_TYPE_INT
,
2548 { "switch_audio", mp_property_audio
, CONF_TYPE_INT
,
2549 CONF_RANGE
, -2, MAX_A_STREAMS
-1, NULL
},
2552 { "fullscreen", mp_property_fullscreen
, CONF_TYPE_FLAG
,
2553 M_OPT_RANGE
, 0, 1, NULL
},
2554 { "deinterlace", mp_property_deinterlace
, CONF_TYPE_FLAG
,
2555 M_OPT_RANGE
, 0, 1, NULL
},
2556 { "ontop", mp_property_ontop
, CONF_TYPE_FLAG
,
2557 M_OPT_RANGE
, 0, 1, NULL
},
2558 { "rootwin", mp_property_rootwin
, CONF_TYPE_FLAG
,
2559 M_OPT_RANGE
, 0, 1, NULL
},
2560 { "border", mp_property_border
, CONF_TYPE_FLAG
,
2561 M_OPT_RANGE
, 0, 1, NULL
},
2562 { "framedropping", mp_property_framedropping
, CONF_TYPE_INT
,
2563 M_OPT_RANGE
, 0, 2, NULL
},
2564 { "gamma", mp_property_gamma
, CONF_TYPE_INT
,
2565 M_OPT_RANGE
, -100, 100, &vo_gamma_gamma
},
2566 { "brightness", mp_property_gamma
, CONF_TYPE_INT
,
2567 M_OPT_RANGE
, -100, 100, &vo_gamma_brightness
},
2568 { "contrast", mp_property_gamma
, CONF_TYPE_INT
,
2569 M_OPT_RANGE
, -100, 100, &vo_gamma_contrast
},
2570 { "saturation", mp_property_gamma
, CONF_TYPE_INT
,
2571 M_OPT_RANGE
, -100, 100, &vo_gamma_saturation
},
2572 { "hue", mp_property_gamma
, CONF_TYPE_INT
,
2573 M_OPT_RANGE
, -100, 100, &vo_gamma_hue
},
2574 { "panscan", mp_property_panscan
, CONF_TYPE_FLOAT
,
2575 M_OPT_RANGE
, 0, 1, NULL
},
2576 { "vsync", mp_property_vsync
, CONF_TYPE_FLAG
,
2577 M_OPT_RANGE
, 0, 1, NULL
},
2578 { "video_format", mp_property_video_format
, CONF_TYPE_INT
,
2580 { "video_bitrate", mp_property_video_bitrate
, CONF_TYPE_INT
,
2582 { "width", mp_property_width
, CONF_TYPE_INT
,
2584 { "height", mp_property_height
, CONF_TYPE_INT
,
2586 { "fps", mp_property_fps
, CONF_TYPE_FLOAT
,
2588 { "aspect", mp_property_aspect
, CONF_TYPE_FLOAT
,
2590 { "switch_video", mp_property_video
, CONF_TYPE_INT
,
2591 CONF_RANGE
, -2, MAX_V_STREAMS
-1, NULL
},
2592 { "switch_program", mp_property_program
, CONF_TYPE_INT
,
2593 CONF_RANGE
, -1, 65535, NULL
},
2596 { "sub", mp_property_sub
, CONF_TYPE_INT
,
2597 M_OPT_MIN
, -1, 0, NULL
},
2598 { "sub_delay", mp_property_sub_delay
, CONF_TYPE_FLOAT
,
2600 { "sub_pos", mp_property_sub_pos
, CONF_TYPE_INT
,
2601 M_OPT_RANGE
, 0, 100, NULL
},
2602 { "sub_alignment", mp_property_sub_alignment
, CONF_TYPE_INT
,
2603 M_OPT_RANGE
, 0, 2, NULL
},
2604 { "sub_visibility", mp_property_sub_visibility
, CONF_TYPE_FLAG
,
2605 M_OPT_RANGE
, 0, 1, NULL
},
2606 { "sub_forced_only", mp_property_sub_forced_only
, CONF_TYPE_FLAG
,
2607 M_OPT_RANGE
, 0, 1, NULL
},
2610 { "tv_brightness", mp_property_tv_color
, CONF_TYPE_INT
,
2611 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_BRIGHTNESS
},
2612 { "tv_contrast", mp_property_tv_color
, CONF_TYPE_INT
,
2613 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_CONTRAST
},
2614 { "tv_saturation", mp_property_tv_color
, CONF_TYPE_INT
,
2615 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_SATURATION
},
2616 { "tv_hue", mp_property_tv_color
, CONF_TYPE_INT
,
2617 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_HUE
},
2620 { NULL
, NULL
, NULL
, 0, 0, 0, NULL
}
2623 m_option_t
* mp_property_find(const char* name
) {
2624 return m_option_list_find(mp_properties
,name
);
2627 int mp_property_do(const char* name
,int action
, void* val
) {
2628 m_option_t
* p
= mp_property_find(name
);
2629 if(!p
) return M_PROPERTY_UNAVAILABLE
;
2630 return m_property_do(p
,action
,val
);
2638 * \defgroup Command2Property Command to property bridge
2640 * It is used to handle most commands that just set a property
2641 * and optionally display something on the OSD.
2642 * Two kinds of commands are handled: adjust or toggle.
2644 * Adjust commands take 1 or 2 parameters: <value> <abs>
2645 * If <abs> is non-zero the property is set to the given value
2646 * otherwise it is adjusted.
2648 * Toggle commands take 0 or 1 parameters. With no parameter
2649 * or a value less than the property minimum it just steps the
2650 * property to its next value. Otherwise it sets it to the given
2656 /// List of the commands that can be handled by setting a property.
2662 /// set/adjust or toggle command
2664 /// progressbar type
2666 /// osd msg id if it must be shared
2668 /// osd msg template
2669 const char* osd_msg
;
2670 } set_prop_cmd
[] = {
2672 { "volume", MP_CMD_VOLUME
, 0, OSD_VOLUME
, -1, MSGTR_Volume
},
2673 { "mute", MP_CMD_MUTE
, 1, 0, -1, MSGTR_MuteStatus
},
2674 { "audio_delay", MP_CMD_AUDIO_DELAY
, 0, 0, -1, MSGTR_AVDelayStatus
},
2675 { "switch_audio", MP_CMD_SWITCH_AUDIO
, 1, 0, -1, MSGTR_OSDAudio
},
2677 { "fullscreen", MP_CMD_VO_FULLSCREEN
, 1, 0, -1, NULL
},
2678 { "panscan", MP_CMD_PANSCAN
, 0, OSD_PANSCAN
, -1, MSGTR_Panscan
},
2679 { "ontop", MP_CMD_VO_ONTOP
, 1, 0, -1, MSGTR_OnTopStatus
},
2680 { "rootwin", MP_CMD_VO_ROOTWIN
, 1, 0, -1, MSGTR_RootwinStatus
},
2681 { "border", MP_CMD_VO_BORDER
, 1, 0, -1, MSGTR_BorderStatus
},
2682 { "framedropping", MP_CMD_FRAMEDROPPING
, 1, 0, -1, MSGTR_FramedroppingStatus
},
2683 { "gamma", MP_CMD_GAMMA
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Gamma
},
2684 { "brightness", MP_CMD_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2685 { "contrast", MP_CMD_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2686 { "saturation", MP_CMD_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2687 { "hue", MP_CMD_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2688 { "vsync", MP_CMD_SWITCH_VSYNC
, 1, 0, -1, MSGTR_VSyncStatus
},
2690 { "sub", MP_CMD_SUB_SELECT
, 1, 0, -1, MSGTR_SubSelectStatus
},
2691 { "sub_pos", MP_CMD_SUB_POS
, 0, 0, -1, MSGTR_SubPosStatus
},
2692 { "sub_alignment", MP_CMD_SUB_ALIGNMENT
, 1, 0, -1, MSGTR_SubAlignStatus
},
2693 { "sub_delay", MP_CMD_SUB_DELAY
, 0, 0, OSD_MSG_SUB_DELAY
, MSGTR_SubDelayStatus
},
2694 { "sub_visibility", MP_CMD_SUB_VISIBILITY
, 1, 0, -1, MSGTR_SubVisibleStatus
},
2695 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY
, 1, 0, -1, MSGTR_SubForcedOnlyStatus
},
2697 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2698 { "tv_hue", MP_CMD_TV_SET_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2699 { "tv_saturation", MP_CMD_TV_SET_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2700 { "tv_contrast", MP_CMD_TV_SET_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2702 { NULL
, 0, 0, 0, -1, NULL
}
2705 /// Handle commands that set a property.
2706 static int set_property_command(mp_cmd_t
* cmd
) {
2710 // look for the command
2711 for(i
= 0 ; set_prop_cmd
[i
].name
; i
++)
2712 if(set_prop_cmd
[i
].cmd
== cmd
->id
) break;
2713 if(!set_prop_cmd
[i
].name
) return 0;
2716 prop
= mp_property_find(set_prop_cmd
[i
].name
);
2720 if(set_prop_cmd
[i
].toggle
) {
2722 if(cmd
->nargs
> 0 && cmd
->args
[0].v
.i
>= prop
->min
)
2723 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
.i
);
2725 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,NULL
);
2726 } else if(cmd
->args
[1].v
.i
) //set
2727 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
);
2729 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,&cmd
->args
[0].v
);
2731 if(r
<= 0) return 1;
2733 if(set_prop_cmd
[i
].osd_progbar
) {
2734 if(prop
->type
== CONF_TYPE_INT
) {
2735 if(m_property_do(prop
,M_PROPERTY_GET
,&r
) > 0)
2736 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2737 set_prop_cmd
[i
].osd_msg
,
2738 prop
->min
,prop
->max
,r
);
2739 } else if(prop
->type
== CONF_TYPE_FLOAT
) {
2741 if(m_property_do(prop
,M_PROPERTY_GET
,&f
) > 0)
2742 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,set_prop_cmd
[i
].osd_msg
,
2743 prop
->min
,prop
->max
,f
);
2745 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "Property use an unsupported type.\n");
2749 if(set_prop_cmd
[i
].osd_msg
) {
2750 char* val
= m_property_print(prop
);
2752 set_osd_msg(set_prop_cmd
[i
].osd_id
>= 0 ? set_prop_cmd
[i
].osd_id
:
2753 OSD_MSG_PROPERTY
+i
,1,osd_duration
,
2754 set_prop_cmd
[i
].osd_msg
,val
);
2761 static void reinit_audio_chain(void) {
2763 current_module
="init_audio_codec";
2764 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2765 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
2766 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
2770 inited_flags
|=INITED_ACODEC
;
2771 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2774 //const ao_info_t *info=audio_out->info;
2775 current_module
="af_preinit";
2776 ao_data
.samplerate
=force_srate
;
2778 ao_data
.format
=audio_output_format
;
2780 // first init to detect best values
2781 if(!preinit_audio_filters(sh_audio
,
2783 (int)(sh_audio
->samplerate
*playback_speed
),
2784 sh_audio
->channels
, sh_audio
->sample_format
,
2786 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
2787 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
2788 exit_player(MSGTR_Exit_error
);
2791 current_module
="ao2_init";
2792 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
2796 ao_data
.format
,0))){
2798 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
2799 uninit_player(INITED_ACODEC
); // close codec
2800 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
2805 inited_flags
|=INITED_AO
;
2806 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2807 audio_out
->info
->short_name
,
2808 ao_data
.samplerate
, ao_data
.channels
,
2809 af_fmt2str_short(ao_data
.format
),
2810 af_fmt2bits(ao_data
.format
)/8 );
2811 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
2812 audio_out
->info
->name
, audio_out
->info
->author
);
2813 if(strlen(audio_out
->info
->comment
) > 0)
2814 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
2815 // init audio filters:
2817 current_module
="af_init";
2818 if(!build_afilter_chain(sh_audio
, &ao_data
)) {
2819 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
2820 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2821 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2822 // sh_audio=d_audio->sh=NULL; // -> nosound
2826 mixer
.audio_out
= audio_out
;
2827 mixer
.volstep
= volstep
;
2836 // Return pts value corresponding to the end point of audio written to the
2838 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
2840 // first calculate the end pts of audio that has been output by decoder
2841 double a_pts
= sh_audio
->pts
;
2842 if (a_pts
!= MP_NOPTS_VALUE
)
2843 // Good, decoder supports new way of calculating audio pts.
2844 // sh_audio->pts is the timestamp of the latest input packet with
2845 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2846 // the amount of bytes the decoder has written after that timestamp.
2847 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
2849 // Decoder doesn't support new way of calculating pts (or we're
2850 // being called before it has decoded anything with known timestamp).
2851 // Use the old method of audio pts calculation: take the timestamp
2852 // of last packet with known pts the decoder has read data from,
2853 // and add amount of bytes read after the beginning of that packet
2854 // divided by input bps. This will be inaccurate if the input/output
2855 // ratio is not constant for every audio packet or if it is constant
2856 // but not accurately known in sh_audio->i_bps.
2858 a_pts
= d_audio
->pts
;
2859 // ds_tell_pts returns bytes read after last timestamp from
2860 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2861 // it has read but not decoded
2862 if (sh_audio
->i_bps
)
2863 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
2864 (double)sh_audio
->i_bps
;
2866 // Now a_pts hopefully holds the pts for end of audio from decoder.
2867 // Substract data in buffers between decoder and audio out.
2869 // Decoded but not filtered
2870 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
2872 // Data that was ready for ao but was buffered because ao didn't fully
2873 // accept everything to internal buffers yet
2874 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
2879 // Return pts value corresponding to currently playing audio.
2880 static double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
2881 ao_functions_t
*audio_out
)
2883 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
2884 audio_out
->get_delay();
2887 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
2889 unsigned char *start
;
2895 void *decoded_frame
;
2896 current_module
= "decode video";
2897 // XXX Time used in this call is not counted in any performance
2898 // timer now, OSD is not updated correctly for filter-added frames
2899 if (vf_output_queued_frame(sh_video
->vfilter
))
2901 current_module
= "video_read_frame";
2902 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
2904 // try to extract last frames in case of decoder lag
2909 if (in_size
> max_framesize
)
2910 max_framesize
= in_size
;
2911 if (pts
== MP_NOPTS_VALUE
)
2912 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts value from demuxer MISSING\n");
2913 current_module
= "decode video";
2914 decoded_frame
= decode_video(sh_video
, start
, in_size
, 0, pts
);
2915 if (decoded_frame
) {
2916 update_subtitles(sh_video
, d_dvdsub
, 0);
2918 current_module
= "filter video";
2919 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2928 static void rescale_input_coordinates(int ix
, int iy
, double *dx
, double *dy
) {
2929 //remove the borders, if any, and rescale to the range [0,1],[0,1]
2930 if(vo_fs
) { //we are in full-screen mode
2931 if(vo_screenwidth
> vo_dwidth
) //there are borders along the x axis
2932 ix
-= (vo_screenwidth
- vo_dwidth
) / 2;
2933 if(vo_screenheight
> vo_dheight
) //there are borders along the y axis (usual way)
2934 iy
-= (vo_screenheight
- vo_dheight
) / 2;
2936 if(ix
< 0 || ix
> vo_dwidth
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
2937 if(iy
< 0 || iy
> vo_dheight
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
2940 *dx
= (double) ix
/ (double) vo_dwidth
;
2941 *dy
= (double) iy
/ (double) vo_dheight
;
2943 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
2944 *dx
, *dy
, vo_screenwidth
, vo_screenheight
, vo_dwidth
, vo_dheight
, vo_fs
);
2951 static float timing_sleep(float time_frame
)
2955 // -------- RTC -----------
2956 current_module
="sleep_rtc";
2957 while (time_frame
> 0.000) {
2958 unsigned long rtc_ts
;
2959 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
2960 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
2961 time_frame
-= GetRelativeTime();
2967 current_module
= "sleep_darwin";
2968 while (time_frame
> 0.005) {
2969 usec_sleep(1000000*time_frame
);
2970 time_frame
-= GetRelativeTime();
2975 // assume kernel HZ=100 for softsleep, works with larger HZ but with
2976 // unnecessarily high CPU usage
2977 float margin
= softsleep
? 0.011 : 0;
2978 current_module
= "sleep_timer";
2979 while (time_frame
> margin
) {
2980 usec_sleep(1000000 * (time_frame
- margin
));
2981 time_frame
-= GetRelativeTime();
2984 current_module
= "sleep_soft";
2986 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
2987 while (time_frame
> 0)
2988 time_frame
-=GetRelativeTime(); // burn the CPU
2991 #endif /* SYS_DARWIN */
2995 static void adjust_sync_and_print_status(int between_frames
, float timing_error
)
2997 current_module
="av_sync";
3000 double a_pts
, v_pts
;
3004 * If autosync is enabled, the value for delay must be calculated
3005 * a bit differently. It is set only to the difference between
3006 * the audio and video timers. Any attempt to include the real
3007 * or corrected delay causes the pts_correction code below to
3008 * try to correct for the changes in delay which autosync is
3009 * trying to measure. This keeps the two from competing, but still
3010 * allows the code to correct for PTS drift *only*. (Using a delay
3011 * value here, even a "corrected" one, would be incompatible with
3014 a_pts
= written_audio_pts(sh_audio
, d_audio
) - sh_audio
->delay
;
3016 a_pts
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
3018 v_pts
= sh_video
->pts
;
3021 static int drop_message
=0;
3022 double AV_delay
= a_pts
- audio_delay
- v_pts
;
3024 if (AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
3026 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
3031 /* Do not correct target time for the next frame if this frame
3032 * was late not because of wrong target time but because the
3033 * target time could not be met */
3034 x
= (AV_delay
+ timing_error
* playback_speed
) * 0.1f
;
3035 if (x
< -max_pts_correction
)
3036 x
= -max_pts_correction
;
3037 else if (x
> max_pts_correction
)
3038 x
= max_pts_correction
;
3039 if (default_max_pts_correction
>= 0)
3040 max_pts_correction
= default_max_pts_correction
;
3042 max_pts_correction
= sh_video
->frametime
*0.10; // +-10% of time
3043 if (!between_frames
) {
3048 print_status(a_pts
- audio_delay
, AV_delay
, c_total
);
3055 print_status(0, 0, 0);
3059 static int fill_audio_out_buffers(void)
3068 current_module
="play_audio";
3071 // all the current uses of ao_data.pts seem to be in aos that handle
3072 // sync completely wrong; there should be no need to use ao_data.pts
3074 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3075 bytes_to_write
= audio_out
->get_space();
3076 if (sh_video
|| bytes_to_write
>= ao_data
.outburst
)
3079 // handle audio-only case:
3080 // this is where mplayer sleeps during audio-only playback
3081 // to avoid 100% CPU use
3082 usec_sleep(10000); // Wait a tick before retry
3085 while (bytes_to_write
) {
3086 playsize
= bytes_to_write
;
3087 if (playsize
> MAX_OUTBURST
)
3088 playsize
= MAX_OUTBURST
;
3089 bytes_to_write
-= playsize
;
3091 // Fill buffer if needed:
3092 current_module
="decode_audio";
3094 while (sh_audio
->a_out_buffer_len
< playsize
) {
3095 int buflen
= sh_audio
->a_out_buffer_len
;
3096 int ret
= decode_audio(sh_audio
, &sh_audio
->a_out_buffer
[buflen
],
3097 playsize
- buflen
, // min bytes
3098 sh_audio
->a_out_buffer_size
- buflen
// max
3100 if (ret
<= 0) { // EOF?
3103 if (sh_audio
->a_out_buffer_len
== 0)
3108 sh_audio
->a_out_buffer_len
+= ret
;
3111 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
3112 if (playsize
> sh_audio
->a_out_buffer_len
) {
3113 playsize
= sh_audio
->a_out_buffer_len
;
3115 playflags
|= AOPLAY_FINAL_CHUNK
;
3121 current_module
="play_audio";
3123 // Is this pts value actually useful for the aos that access it?
3124 // They're obviously badly broken in the way they handle av sync;
3125 // would not having access to this make them more broken?
3126 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3127 playsize
= audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
3130 sh_audio
->a_out_buffer_len
-= playsize
;
3131 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
3132 sh_audio
->a_out_buffer_len
);
3133 sh_audio
->delay
+= playback_speed
*playsize
/(double)ao_data
.bps
;
3135 else if (audio_eof
&& audio_out
->get_delay() < .04) {
3136 // Sanity check to avoid hanging in case current ao doesn't output
3137 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3138 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
3139 sh_audio
->a_out_buffer_len
= 0;
3145 static int sleep_until_update(float *time_frame
, float *aq_sleep_time
)
3147 int frame_time_remaining
= 0;
3148 current_module
="calc_sleep_time";
3150 *time_frame
-= GetRelativeTime(); // reset timer
3152 if (sh_audio
&& !d_audio
->eof
) {
3153 float delay
= audio_out
->get_delay();
3154 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
3158 * Adjust this raw delay value by calculating the expected
3159 * delay for this frame and generating a new value which is
3160 * weighted between the two. The higher autosync is, the
3161 * closer to the delay value gets to that which "-nosound"
3162 * would have used, and the longer it will take for A/V
3163 * sync to settle at the right value (but it eventually will.)
3164 * This settling time is very short for values below 100.
3166 float predicted
= sh_audio
->delay
/ playback_speed
+ *time_frame
;
3167 float difference
= delay
- predicted
;
3168 delay
= predicted
+ difference
/ (float)autosync
;
3171 *time_frame
= delay
- sh_audio
->delay
/ playback_speed
;
3173 // delay = amount of audio buffered in soundcard/driver
3174 if (delay
> 0.25) delay
=0.25; else
3175 if (delay
< 0.10) delay
=0.10;
3176 if (*time_frame
> delay
*0.6) {
3177 // sleep time too big - may cause audio drops (buffer underrun)
3178 frame_time_remaining
= 1;
3179 *time_frame
= delay
*0.5;
3182 // If we're lagging more than 200 ms behind the right playback rate,
3183 // don't try to "catch up".
3184 // If benchmark is set always output frames as fast as possible
3185 // without sleeping.
3186 if (*time_frame
< -0.2 || benchmark
)
3190 *aq_sleep_time
+= *time_frame
;
3193 //============================== SLEEP: ===================================
3195 // flag 256 means: libvo driver does its timing (dvb card)
3196 if (*time_frame
> 0.001 && !(vo_flags
&256))
3197 *time_frame
= timing_sleep(*time_frame
);
3198 return frame_time_remaining
;
3201 static int reinit_video_chain(void) {
3202 //================== Init VIDEO (codec & libvo) ==========================
3203 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
3204 current_module
="preinit_libvo";
3206 //shouldn't we set dvideo->id=-2 when we fail?
3208 //if((video_out->preinit(vo_subdevice))!=0){
3209 if(!(video_out
=init_best_video_out(video_driver_list
))){
3210 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
3213 sh_video
->video_out
=video_out
;
3214 inited_flags
|=INITED_VO
;
3217 current_module
="init_video_filters";
3219 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
3220 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
3224 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
3225 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
3227 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
3232 sh_video
->vfilter
=(void*)vf_menu
;
3240 for (i
= 0; vf_settings
[i
].name
; ++i
)
3241 if (strcmp(vf_settings
[i
].name
, "ass") == 0) {
3246 extern vf_info_t vf_info_ass
;
3247 vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
3248 char* vf_arg
[] = {"auto", "1", NULL
};
3249 vf_instance_t
* vf_ass
= vf_open_plugin(libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
3251 sh_video
->vfilter
=(void*)vf_ass
;
3253 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
3258 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
3262 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
3265 current_module
="init_video_codec";
3267 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3268 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
3269 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3271 if(!sh_video
->inited
){
3272 if(!fixed_vo
) uninit_player(INITED_VO
);
3276 inited_flags
|=INITED_VCODEC
;
3278 if (sh_video
->codec
)
3279 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
3281 sh_video
->last_pts
= MP_NOPTS_VALUE
;
3282 sh_video
->num_buffered_pts
= 0;
3283 sh_video
->next_frame_time
= 0;
3286 // Auto quality option enabled
3287 output_quality
=get_video_quality_max(sh_video
);
3288 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
3289 else output_quality
=auto_quality
;
3290 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
3291 set_video_quality(sh_video
,output_quality
);
3294 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3296 current_module
="init_vo";
3301 sh_video
= d_video
->sh
= NULL
;
3305 static double update_video(int *blit_frame
)
3307 //-------------------- Decode a frame: -----------------------
3309 *blit_frame
= 0; // Don't blit if we hit EOF
3311 unsigned char* start
=NULL
;
3312 void *decoded_frame
;
3316 current_module
= "video_read_frame";
3317 frame_time
= sh_video
->next_frame_time
;
3318 in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
3322 if (in_size
> max_framesize
)
3323 max_framesize
= in_size
; // stats
3324 sh_video
->timer
+= frame_time
;
3326 sh_audio
->delay
-= frame_time
;
3327 // video_read_frame can change fps (e.g. for ASF video)
3328 vo_fps
= sh_video
->fps
;
3329 // check for frame-drop:
3330 current_module
= "check_framedrop";
3331 if (sh_audio
&& !d_audio
->eof
) {
3332 static int dropped_frames
;
3333 float delay
= playback_speed
*audio_out
->get_delay();
3334 float d
= delay
-sh_audio
->delay
;
3335 // we should avoid dropping too many frames in sequence unless we
3336 // are too late. and we allow 100ms A-V delay here:
3337 if (d
< -dropped_frames
*frame_time
-0.100 &&
3338 osd_function
!= OSD_PAUSE
) {
3339 drop_frame
= frame_dropping
;
3343 drop_frame
= dropped_frames
= 0;
3346 update_subtitles(sh_video
, d_dvdsub
, 0);
3348 current_module
= "decode_video";
3349 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
3351 current_module
= "filter_video";
3352 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
3356 if (!generate_video_frame(sh_video
, d_video
))
3358 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
,
3359 VFCTRL_GET_PTS
, &sh_video
->pts
);
3360 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
3361 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
3362 sh_video
->pts
= sh_video
->last_pts
;
3364 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
3365 sh_video
->last_pts
= sh_video
->pts
;
3366 else if (sh_video
->last_pts
>= sh_video
->pts
) {
3367 sh_video
->last_pts
= sh_video
->pts
;
3368 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "pts value <= previous");
3370 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
3371 sh_video
->last_pts
= sh_video
->pts
;
3372 sh_video
->timer
+= frame_time
;
3374 sh_audio
->delay
-= frame_time
;
3380 void pause_loop(void)
3384 // Small hack to display the pause message on the OSD line.
3385 // The pause string is: "\n == PAUSE == \r" so we need to
3386 // take the first and the last char out
3387 if (term_osd
&& !sh_video
) {
3388 char msg
[128] = MSGTR_Paused
;
3389 int mlen
= strlen(msg
);
3391 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
3394 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
3395 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
3400 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
3402 if (video_out
&& sh_video
&& vo_config_count
)
3403 video_out
->control(VOCTRL_PAUSE
, NULL
);
3405 if (audio_out
&& sh_audio
)
3406 audio_out
->pause(); // pause audio, keep data if possible
3408 while ( (cmd
= mp_input_get_cmd(20, 1, 1)) == NULL
) {
3409 if (sh_video
&& video_out
&& vo_config_count
)
3410 video_out
->check_events();
3414 guiGetEvent(guiReDraw
, NULL
);
3415 if (guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
))
3421 vf_menu_pause_update(vf_menu
);
3425 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
3426 cmd
= mp_input_get_cmd(0,1,0);
3429 osd_function
=OSD_PLAY
;
3430 if (audio_out
&& sh_audio
)
3431 audio_out
->resume(); // resume audio
3432 if (video_out
&& sh_video
&& vo_config_count
)
3433 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
3434 (void)GetRelativeTime(); // ignore time that passed during pause
3437 if (guiIntfStruct
.Playing
== guiSetStop
)
3440 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
3445 void print_version(void){
3446 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s\n", MP_TITLE
);
3448 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
3449 GetCpuCaps(&gCpuCaps
);
3451 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
3452 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
3453 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
3454 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
3455 #ifdef RUNTIME_CPUDETECT
3456 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
3458 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
3460 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
3463 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
3466 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
3469 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
3472 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
3475 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
3477 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3478 #endif /* RUNTIME_CPUDETECT */
3479 #endif /* ARCH_X86 */
3482 int main(int argc
,char* argv
[]){
3487 int file_format
=DEMUXER_TYPE_UNKNOWN
;
3491 /* Flag indicating whether MPlayer should exit without playing anything. */
3494 //float a_frame=0; // Audio
3499 int gui_no_filename
=0;
3501 srand((int) time(NULL
));
3507 for(i
=1; i
<argc
; i
++)
3508 if(!strcmp(argv
[i
], "-really-quiet"))
3512 #if defined(WIN32) && defined(USE_WIN32DLL)
3514 #endif /*WIN32 && USE_WIN32DLL*/
3517 tv_param_immediate
= 1;
3520 if (argc
> 1 && argv
[1] &&
3521 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
3522 use_gui
= !strcmp(argv
[1], "-gui");
3526 char *base
= strrchr(argv
[0], '/');
3528 base
= strrchr(argv
[0], '\\');
3531 if(strstr(base
, "gmplayer"))
3535 mconfig
= m_config_new();
3536 m_config_register_options(mconfig
,mplayer_opts
);
3537 // TODO : add something to let modules register their options
3538 mp_input_register_options(mconfig
);
3539 parse_cfgfiles(mconfig
);
3542 if ( use_gui
) cfg_read();
3545 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
3546 if(playtree
== NULL
)
3549 playtree
= play_tree_cleanup(playtree
);
3551 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3553 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3554 play_tree_iter_free(playtree_iter
);
3555 playtree_iter
= NULL
;
3557 filename
= play_tree_iter_get_file(playtree_iter
,1);
3562 #if defined(WIN32) && defined(HAVE_NEW_GUI)
3563 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
3564 if(runningmplayer
&& filename
&& use_gui
){
3565 COPYDATASTRUCT csData
;
3566 char file
[MAX_PATH
];
3567 char *filepart
= filename
;
3568 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
3570 csData
.cbData
= strlen(file
)*2;
3571 csData
.lpData
= file
;
3572 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
3580 for(i
=0; priority_presets_defs
[i
].name
; i
++){
3581 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
3584 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
3585 priority_presets_defs
[i
].name
);
3586 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
3589 #ifndef HAVE_NEW_GUI
3591 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
3596 if(use_gui
&& !vo_init()){
3597 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
3601 if (use_gui
&& playtree_iter
){
3602 char cwd
[PATH_MAX
+2];
3603 // Free Playtree and Playtree-Iter as it's not used by the GUI.
3604 play_tree_iter_free(playtree_iter
);
3607 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
3610 // Prefix relative paths with current working directory
3611 play_tree_add_bpf(playtree
, cwd
);
3613 // Import initital playtree into GUI.
3614 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
3616 #endif /* HAVE_NEW_GUI */
3618 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
3623 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
3628 /* Check codecs.conf. */
3629 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
3630 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
3631 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
3632 if(!parse_codec_cfg(NULL
)){
3633 exit_player_with_rc(NULL
, 0);
3635 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
3638 free( mem_ptr
); // release the buffer created by get_path()
3642 if(video_codec_list
){
3644 video_codec
=video_codec_list
[0];
3645 for(i
=0;video_codec_list
[i
];i
++)
3646 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
3649 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
3650 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
3651 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
3653 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3656 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
3657 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
3658 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
3660 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3663 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
3665 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3668 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3670 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3673 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3679 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3681 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3685 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3686 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3687 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3689 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3692 if(list_properties
) {
3693 m_properties_print_help_list(mp_properties
);
3700 if (player_idle_mode
&& use_gui
) {
3701 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
3702 exit_player_with_rc(NULL
, 1);
3705 if(!filename
&& !player_idle_mode
){
3707 // no file/vcd/dvd -> show HELP:
3708 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
3709 exit_player_with_rc(NULL
, 0);
3710 } else gui_no_filename
=1;
3713 /* Display what configure line was used */
3714 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
3716 // Many users forget to include command line in bugreports...
3717 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3718 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
3719 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3720 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3723 //------ load global data first ------
3726 #ifdef HAVE_FREETYPE
3729 #ifdef HAVE_FONTCONFIG
3730 if(!font_fontconfig
)
3733 #ifdef HAVE_BITMAP_FONT
3735 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3736 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,
3737 filename_recode(font_name
));
3740 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3741 free(mem_ptr
); // release the buffer created by get_path()
3743 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3746 #ifdef HAVE_FONTCONFIG
3753 ass_library
= ass_init();
3759 // seteuid(0); /* Can't hurt to try to get root here */
3760 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3761 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
3762 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3764 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3766 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3767 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
3768 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
3771 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3772 /* variable only by the root */
3773 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
3777 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
3781 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
3782 // and now ? -- Pontscho
3783 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
3786 #endif /* HAVE_RTC */
3787 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3788 softsleep
?"software":timer_name
);
3791 if ( !use_gui
) load_termcap(NULL
); // load key-codes
3794 // ========== Init keyboard FIFO (connection to libvo) ============
3796 // Init input system
3797 current_module
= "init_input";
3798 mp_input_init(use_gui
);
3800 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
3802 if(keyb_fifo_get
> 0)
3803 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
3805 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
3809 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
3811 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
3813 else if(!noconsolecontrols
)
3814 #ifndef HAVE_NO_POSIX_SELECT
3815 mp_input_add_key_fd(0,1,NULL
,NULL
);
3817 mp_input_add_key_fd(0,0,NULL
,NULL
);
3820 inited_flags
|=INITED_INPUT
;
3821 current_module
= NULL
;
3825 if(menu_cfg
&& menu_init(menu_cfg
))
3826 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3828 menu_cfg
= get_path("menu.conf");
3829 if(menu_init(menu_cfg
))
3830 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3832 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
3833 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
3835 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
3845 signal(SIGCHLD
,child_sighandler
);
3849 prog_path
= argv
[0];
3851 //========= Catch terminate signals: ================
3852 // terminate requests:
3853 signal(SIGTERM
,exit_sighandler
); // kill
3854 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3856 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3858 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3859 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3860 #ifdef ENABLE_SIGHANDLER
3862 signal(SIGBUS
,exit_sighandler
); // bus error
3863 signal(SIGSEGV
,exit_sighandler
); // segfault
3864 signal(SIGILL
,exit_sighandler
); // illegal instruction
3865 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3866 signal(SIGABRT
,exit_sighandler
); // abort()
3869 signal(SIGTRAP
,exit_sighandler
);
3876 inited_flags
|=INITED_GUI
;
3877 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
3881 // ******************* Now, let's see the per-file stuff ********************
3885 // init global sub numbers
3886 global_sub_size
= 0;
3887 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
3889 if (filename
) load_per_file_config (mconfig
, filename
);
3891 // We must enable getch2 here to be able to interrupt network connection
3893 if(!noconsolecontrols
&& !slave_mode
){
3894 if(inited_flags
&INITED_GETCH2
)
3895 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
3897 getch2_enable(); // prepare stdin for hotkeys...
3898 inited_flags
|=INITED_GETCH2
;
3899 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3902 // =================== GUI idle loop (STOP state) ===========================
3905 file_format
=DEMUXER_TYPE_UNKNOWN
;
3906 guiGetEvent( guiSetDefaults
,0 );
3907 while ( guiIntfStruct
.Playing
!= 1 )
3912 guiGetEvent( guiReDraw
,NULL
);
3913 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3915 guiGetEvent( guiSetParameters
,NULL
);
3916 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
3918 play_tree_t
* entry
= play_tree_new();
3919 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
3920 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
3921 else playtree
=play_tree_new();
3922 play_tree_set_child( playtree
,entry
);
3925 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3928 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
3930 play_tree_iter_free(playtree_iter
);
3931 playtree_iter
= NULL
;
3933 filename
= play_tree_iter_get_file(playtree_iter
,1);
3938 #endif /* HAVE_NEW_GUI */
3940 while (player_idle_mode
&& !filename
) {
3941 play_tree_t
* entry
= NULL
;
3943 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
3944 if (video_out
&& vo_config_count
) video_out
->check_events();
3948 case MP_CMD_LOADFILE
:
3949 // prepare a tree entry with the new filename
3950 entry
= play_tree_new();
3951 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3952 // The entry is added to the main playtree after the switch().
3954 case MP_CMD_LOADLIST
:
3955 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
3958 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3964 if (entry
) { // user entered a command that gave a valid entry
3965 if (playtree
) // the playtree is always a node with one child. let's clear it
3966 play_tree_free_list(playtree
->child
, 1);
3967 else playtree
=play_tree_new(); // .. or make a brand new playtree
3969 if (!playtree
) continue; // couldn't make playtree! wait for next command
3971 play_tree_set_child(playtree
, entry
);
3973 /* Make iterator start at the top the of tree. */
3974 playtree_iter
= play_tree_iter_new(playtree
, mconfig
);
3975 if (!playtree_iter
) continue;
3977 // find the first real item in the tree
3978 if (play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3980 play_tree_iter_free(playtree_iter
);
3981 playtree_iter
= NULL
;
3982 continue; // wait for next command
3984 filename
= play_tree_iter_get_file(playtree_iter
, 1);
3987 //---------------------------------------------------------------------------
3990 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
,
3991 filename_recode(filename
));
3994 if (edl_records
) free_edl(edl_records
);
3995 next_edl_record
= edl_records
= edl_parse_file();
3997 if (edl_output_filename
) {
3998 if (edl_fd
) fclose(edl_fd
);
3999 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
4001 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
4002 filename_recode(edl_output_filename
));
4006 //==================== Open VOB-Sub ============================
4008 current_module
="vobsub";
4010 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
4012 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,
4013 filename_recode(vobsub_name
));
4014 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
4015 /* try to autodetect vobsub from movie filename ::atmos */
4016 char *buf
= malloc((strlen(filename
)-3)),*psub
;
4017 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
4018 strncpy(buf
, filename
, strlen(filename
)-4);
4019 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
4020 /* try from ~/.mplayer/sub */
4021 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
4024 bname
= strrchr(buf
,'/');
4026 if(!bname
) bname
= strrchr(buf
,'\\');
4030 l
= strlen(psub
) + strlen(bname
) + 1;
4031 psub
= realloc(psub
,l
);
4033 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
4039 inited_flags
|=INITED_VOBSUB
;
4040 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
4041 // check if vobsub requested only to display forced subtitles
4042 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
4044 // setup global sub numbering
4045 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
4046 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
4049 //============ Open & Sync STREAM --- fork cache2 ====================
4054 //free_demuxer_stream(d_audio);
4058 //free_demuxer_stream(d_video);
4064 current_module
="open_stream";
4065 stream
=open_stream(filename
,0,&file_format
);
4066 if(!stream
) { // error...
4067 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
4068 goto goto_next_file
;
4070 inited_flags
|=INITED_STREAM
;
4073 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
4076 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
4079 current_module
="handle_playlist";
4080 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
4081 filename_recode(filename
));
4082 entry
= parse_playtree(stream
,0);
4083 eof
=playtree_add_playlist(entry
);
4084 goto goto_next_file
;
4086 stream
->start_pos
+=seek_to_byte
;
4088 if(stream_dump_type
==5){
4089 unsigned char buf
[4096];
4092 current_module
="dumpstream";
4093 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
4094 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
4095 exit_player(MSGTR_Exit_error
);
4097 stream_reset(stream
);
4098 stream_seek(stream
,stream
->start_pos
);
4099 f
=fopen(stream_dump_name
,"wb");
4101 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
4102 exit_player(MSGTR_Exit_error
);
4104 while(!stream
->eof
){
4105 len
=stream_read(stream
,buf
,4096);
4107 if(fwrite(buf
,len
,1,f
) != 1) {
4108 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
4109 exit_player(MSGTR_Exit_error
);
4114 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
4115 exit_player(MSGTR_Exit_error
);
4117 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
4118 exit_player_with_rc(MSGTR_Exit_eof
, 0);
4122 if(stream
->type
==STREAMTYPE_DVD
){
4123 current_module
="dvd lang->id";
4124 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
4125 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
4126 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
4127 // setup global sub numbering
4128 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4129 global_sub_size
+= dvd_number_of_subs(stream
);
4130 current_module
=NULL
;
4135 if(stream
->type
==STREAMTYPE_DVDNAV
){
4136 current_module
="dvdnav lang->id";
4137 if(audio_id
==-1) audio_id
=dvdnav_aid_from_lang(stream
,audio_lang
);
4138 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
4139 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvdnav_sid_from_lang(stream
,dvdsub_lang
);
4140 // setup global sub numbering
4141 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4142 global_sub_size
+= dvdnav_number_of_subs(stream
);
4143 current_module
=NULL
;
4147 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
4149 if(stream_cache_size
>0){
4150 current_module
="enable_cache";
4151 if(!stream_enable_cache(stream
,stream_cache_size
*1024,
4152 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
4153 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
4154 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
4157 //============ Open DEMUXERS --- DETECT file type =======================
4158 current_module
="demux_open";
4160 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
4162 // HACK to get MOV Reference Files working
4164 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
4166 unsigned char* playlist_entry
;
4167 play_tree_t
*list
= NULL
, *entry
= NULL
;
4169 current_module
="handle_demux_playlist";
4170 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
4174 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
4175 filename_recode(playlist_entry
));
4177 bname
=mp_basename(playlist_entry
);
4178 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
4181 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
4184 entry
= play_tree_new();
4186 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
4188 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
4191 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
4192 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
4193 strcat(temp
, playlist_entry
);
4194 play_tree_add_file(entry
,temp
);
4195 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
4200 play_tree_add_file(entry
,playlist_entry
);
4205 play_tree_append_entry(list
,entry
);
4207 free_demuxer(demuxer
);
4212 entry
= play_tree_new();
4213 play_tree_set_child(entry
,list
);
4214 eof
=playtree_add_playlist(entry
);
4215 goto goto_next_file
;
4224 current_module
="handle_playlist";
4225 switch(stream
->type
){
4226 case STREAMTYPE_VCD
:
4227 case STREAMTYPE_DVD
:
4228 case STREAMTYPE_CDDA
:
4229 case STREAMTYPE_VCDBINCUE
:
4230 // don't try to parse raw media as playlist, it's unlikely
4231 goto goto_next_file
;
4233 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
4234 stream_reset(stream
);
4235 stream_seek(stream
,stream
->start_pos
);
4236 entry
= parse_playtree(stream
,0);
4238 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
4240 eof
=playtree_add_playlist(entry
);
4242 goto goto_next_file
;
4244 inited_flags
|=INITED_DEMUXER
;
4246 if (stream
->type
!= STREAMTYPE_DVD
&& stream
->type
!= STREAMTYPE_DVDNAV
) {
4248 // setup global sub numbering
4249 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4250 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
4251 if (demuxer
->s_streams
[i
])
4254 if (global_sub_size
<= dvdsub_id
) global_sub_size
= dvdsub_id
+ 1;
4256 current_module
="demux_open2";
4258 //file_format=demuxer->file_format;
4260 d_audio
=demuxer
->audio
;
4261 d_video
=demuxer
->video
;
4262 d_dvdsub
=demuxer
->sub
;
4265 if((stream_dump_type
)&&(stream_dump_type
<4)){
4267 demux_stream_t
*ds
=NULL
;
4268 current_module
="dump";
4269 // select stream to dump
4270 switch(stream_dump_type
){
4271 case 1: ds
=d_audio
;break;
4272 case 2: ds
=d_video
;break;
4273 case 3: ds
=d_dvdsub
;break;
4276 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
4277 exit_player(MSGTR_Exit_error
);
4279 // disable other streams:
4280 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
4281 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
4282 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
4284 f
=fopen(stream_dump_name
,"wb");
4286 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
4287 exit_player(MSGTR_Exit_error
);
4290 unsigned char* start
;
4291 int in_size
=ds_get_packet(ds
,&start
);
4292 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
4293 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
4294 if(in_size
>0) fwrite(start
,in_size
,1,f
);
4297 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
4298 exit_player_with_rc(MSGTR_Exit_eof
, 0);
4301 sh_audio
=d_audio
->sh
;
4302 sh_video
=d_video
->sh
;
4306 current_module
="video_read_properties";
4307 if(!video_read_properties(sh_video
)) {
4308 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
4309 sh_video
=d_video
->sh
=NULL
;
4311 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
4312 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
4313 sh_video
->fps
,sh_video
->frametime
4316 /* need to set fps here for output encoders to pick it up in their init */
4318 sh_video
->fps
=force_fps
;
4319 sh_video
->frametime
=1.0f
/sh_video
->fps
;
4321 vo_fps
= sh_video
->fps
;
4323 if(!sh_video
->fps
&& !force_fps
){
4324 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
4325 sh_video
=d_video
->sh
=NULL
;
4333 if(!sh_video
&& !sh_audio
){
4334 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
4335 #ifdef HAS_DVBIN_SUPPORT
4336 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4338 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4342 int v
= last_dvb_step
;
4344 dir
= DVB_CHANNEL_HIGHER
;
4346 dir
= DVB_CHANNEL_LOWER
;
4348 if(dvb_step_channel(priv
, dir
))
4349 eof
= dvbin_reopen
= 1;
4353 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
4356 /* display clip info */
4357 demux_info_print(demuxer
);
4359 //================== Read SUBTITLES (DVD & TEXT) ==========================
4360 if(vo_spudec
==NULL
&& sh_video
&&
4361 (stream
->type
==STREAMTYPE_DVD
|| stream
->type
== STREAMTYPE_DVDNAV
|| d_dvdsub
->id
>= 0)){
4365 // Apply current settings for forced subs
4366 if (vo_spudec
!=NULL
)
4367 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
4370 // after reading video params we should load subtitles because
4371 // we know fps so now we can adjust subtitle time to ~6 seconds AST
4373 current_module
="read_subtitles_file";
4375 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
4376 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
4378 if(sub_auto
) { // auto load sub file ...
4379 char *psub
= get_path( "sub/" );
4380 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
4382 free(psub
); // release the buffer created by get_path() above
4384 add_subtitles (tmp
[i
], sh_video
->fps
, 0);
4389 if (set_of_sub_size
> 0) {
4390 // setup global sub numbering
4391 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
4392 global_sub_size
+= set_of_sub_size
;
4396 if (global_sub_size
) {
4397 // find the best sub to use
4398 if (vobsub_id
>= 0) {
4399 // if user asks for a vobsub id, use that first.
4400 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
4401 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
4402 // if user asks for a dvd sub id, use that next.
4403 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
4404 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
4405 // if there are text subs to use, use those. (autosubs come last here)
4406 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
4408 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4409 // if nothing else works, get subs from the demuxer.
4410 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
4413 // nothing worth doing automatically.
4414 global_sub_pos
= -1;
4416 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
4418 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
);
4420 switch (stream_dump_type
) {
4421 case 3: list_sub_file(subdata
); break;
4422 case 4: dump_mpsub(subdata
, sh_video
->fps
); break;
4423 case 6: dump_srt(subdata
, sh_video
->fps
); break;
4424 case 7: dump_microdvd(subdata
, sh_video
->fps
); break;
4425 case 8: dump_jacosub(subdata
, sh_video
->fps
); break;
4426 case 9: dump_sami(subdata
, sh_video
->fps
); break;
4430 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
4431 filename_recode(filename
));
4432 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", demuxer
->desc
->name
);
4434 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4435 if (sh_video
->format
>= 0x20202020)
4436 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video
->format
);
4438 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
4439 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
4440 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
4441 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
4442 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
4443 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
4446 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4447 if (sh_audio
->format
>= 0x20202020)
4448 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio
->format
);
4450 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
4451 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
4452 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
4453 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
4455 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
4457 if(!sh_video
) goto main
; // audio-only
4459 if(!reinit_video_chain()) {
4461 if(!sh_audio
) goto goto_next_file
;
4462 goto main
; // exit_player(MSGTR_Exit_error);
4466 if(vo_flags
& 0x08 && vo_spudec
)
4467 spudec_set_hw_spu(vo_spudec
,video_out
);
4469 #ifdef HAVE_FREETYPE
4470 force_load_font
= 1;
4473 //================== MAIN: ==========================
4475 current_module
="main";
4478 char* msg
= m_properties_expand_string(mp_properties
,playing_msg
);
4479 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
4484 // Disable the term OSD in verbose mode
4485 if(verbose
) term_osd
= 0;
4489 //int frame_corr_num=0; //
4490 //float v_frame=0; // Video
4491 float time_frame
=0; // Timer
4492 //float num_frames=0; // number of frames played
4494 int frame_time_remaining
=0; // flag
4498 // Make sure old OSD does not stay around,
4499 // e.g. with -fixed-vo and same-resolution files
4503 //================ SETUP AUDIO ==========================
4506 reinit_audio_chain();
4507 if (sh_audio
&& sh_audio
->codec
)
4508 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
4511 current_module
="av_init";
4516 audio_delay
+= sh_video
->stream_delay
;
4520 audio_delay
-= sh_audio
->stream_delay
;
4521 sh_audio
->delay
=-audio_delay
;
4525 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
4526 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",d_audio
->packs
);
4527 ds_free_packs(d_audio
); // free buffered chunks
4528 //d_audio->id=-2; // do not read audio chunks
4529 //uninit_player(INITED_AO); // close device
4532 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
4533 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",d_video
->packs
);
4534 ds_free_packs(d_video
);
4536 //if(!fixed_vo) uninit_player(INITED_VO);
4539 if (!sh_video
&& !sh_audio
)
4540 goto goto_next_file
;
4542 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4543 if(force_fps
&& sh_video
){
4544 vo_fps
= sh_video
->fps
=force_fps
;
4545 sh_video
->frametime
=1.0f
/sh_video
->fps
;
4546 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
4551 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
4552 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
4553 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
4554 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
4555 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
4559 //==================== START PLAYING =======================
4561 if(loop_times
>1) loop_times
--; else
4562 if(loop_times
==1) loop_times
= -1;
4564 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
4566 total_time_usage_start
=GetTimer();
4567 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4568 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
4569 play_n_frames
=play_n_frames_mf
;
4571 if(play_n_frames
==0){
4572 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
4576 float aq_sleep_time
=0;
4577 if(!sh_audio
&& d_audio
->sh
) {
4578 sh_audio
= d_audio
->sh
;
4579 sh_audio
->ds
= d_audio
;
4580 reinit_audio_chain();
4583 /*========================== PLAY AUDIO ============================*/
4586 if (!fill_audio_out_buffers())
4587 // at eof, all audio at least written to ao
4589 eof
= PT_NEXT_ENTRY
;
4593 // handle audio-only case:
4595 if(!quiet
|| end_at
.type
== END_AT_TIME
)
4596 a_pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4599 print_status(a_pos
, 0, 0);
4601 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
4602 eof
= PT_NEXT_ENTRY
;
4607 /*========================== PLAY VIDEO ============================*/
4609 vo_pts
=sh_video
->timer
*90000.0;
4610 vo_fps
=sh_video
->fps
;
4612 if (!frame_time_remaining
) {
4613 double frame_time
= update_video(&blit_frame
);
4614 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
4615 if (sh_video
->vf_inited
< 0) {
4616 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
4617 eof
= 1; goto goto_next_file
;
4622 time_frame
+= frame_time
/ playback_speed
; // for nosound
4625 // ==========================================================================
4627 // current_module="draw_osd";
4628 // if(vo_config_count) video_out->draw_osd();
4631 if(use_gui
) guiEventHandling();
4634 current_module
="vo_check_events";
4635 if (vo_config_count
) video_out
->check_events();
4638 if (stop_xscreensaver
) {
4639 current_module
= "stop_xscreensaver";
4640 xscreensaver_heartbeat();
4644 frame_time_remaining
= sleep_until_update(&time_frame
, &aq_sleep_time
);
4646 //====================== FLIP PAGE (VIDEO BLT): =========================
4648 current_module
="flip_page";
4649 if (!frame_time_remaining
&& blit_frame
) {
4650 unsigned int t2
=GetTimer();
4652 if(vo_config_count
) video_out
->flip_page();
4654 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
4656 //====================== A-V TIMESTAMP CORRECTION: =========================
4658 adjust_sync_and_print_status(frame_time_remaining
, time_frame
);
4660 //============================ Auto QUALITY ============================
4662 /*Output quality adjustments:*/
4664 current_module
="autoq";
4665 // float total=0.000001f * (GetTimer()-aq_total_time);
4666 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4667 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4670 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4671 if(output_quality
>1 && aq_sleep_time
<0)
4674 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4676 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4677 set_video_quality(sh_video
,output_quality
);
4680 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
4682 if (play_n_frames
<= 0) eof
= PT_NEXT_ENTRY
;
4686 // FIXME: add size based support for -endpos
4687 if (end_at
.type
== END_AT_TIME
&&
4688 !frame_time_remaining
&& end_at
.pos
<= sh_video
->pts
)
4689 eof
= PT_NEXT_ENTRY
;
4691 } // end if(sh_video)
4694 if (stream
->type
== STREAMTYPE_DVDNAV
) {
4696 mp_dvdnav_get_highlight (stream
, &hl
);
4697 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
4698 vo_osd_changed (OSDTYPE_DVDNAV
);
4702 //============================ Handle PAUSE ===============================
4704 current_module
="pause";
4707 // 36000000 means max timed visibility is 1 hour into the future, if
4708 // the difference is greater assume it's wrapped around from below 0
4709 if (osd_visible
- GetTimerMS() > 36000000) {
4711 vo_osd_progbar_type
=-1; // disable
4712 vo_osd_changed(OSDTYPE_PROGBAR
);
4713 if (osd_function
!= OSD_PAUSE
)
4714 osd_function
= OSD_PLAY
;
4718 if (osd_function
== OSD_PAUSE
) {
4725 osd_function
=OSD_FFW
;
4726 rel_seek_secs
+=step_sec
;
4729 //================= EDL =========================================
4731 if( next_edl_record
) { // Are we (still?) doing EDL?
4733 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
4734 free_edl(edl_records
);
4735 next_edl_record
= NULL
;
4738 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
4739 if( next_edl_record
->action
== EDL_SKIP
) {
4740 osd_function
= OSD_FFW
;
4742 rel_seek_secs
= next_edl_record
->length_sec
;
4743 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
);
4745 } else if( next_edl_record
->action
== EDL_MUTE
) {
4746 edl_muted
= !edl_muted
;
4747 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4748 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
4750 next_edl_record
=next_edl_record
->next
;
4755 //================= Keyboard events, SEEKing ====================
4757 current_module
="key_events";
4762 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
4763 if(!set_property_command(cmd
))
4765 case MP_CMD_SEEK
: {
4769 osd_show_percentage
= sh_video
->fps
;
4770 v
= cmd
->args
[0].v
.f
;
4771 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
4772 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
4775 osd_function
= (v
> sh_video
->pts
) ? OSD_FFW
: OSD_REW
;
4778 else if(abs
) { /* Absolute seek by percentage */
4781 osd_function
= OSD_FFW
; // Direction isn't set correctly
4782 rel_seek_secs
= v
/100.0;
4786 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
4790 case MP_CMD_SET_PROPERTY
: {
4791 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4792 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4793 else if(m_property_parse(prop
,cmd
->args
[1].v
.s
) <= 0)
4794 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to set property '%s' to '%s'.\n",
4795 cmd
->args
[0].v
.s
,cmd
->args
[1].v
.s
);
4798 case MP_CMD_STEP_PROPERTY
: {
4799 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4800 float arg
= cmd
->args
[1].v
.f
;
4801 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
, "Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4802 else if(m_property_do(prop
,M_PROPERTY_STEP_UP
, arg
? &arg
: NULL
) <= 0)
4803 mp_msg(MSGT_CPLAYER
,MSGL_WARN
, "Failed to increment property '%s' by %f.\n",cmd
->args
[0].v
.s
, arg
);
4805 case MP_CMD_GET_PROPERTY
: {
4808 prop
= mp_property_find(cmd
->args
[0].v
.s
);
4810 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4813 /* Use m_option_print directly to get easily parseable values. */
4814 val
= calloc(1,prop
->type
->size
);
4815 if(m_property_do(prop
,M_PROPERTY_GET
,val
) <= 0) {
4816 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to get value of property '%s'.\n",
4820 tmp
= m_option_print(prop
,val
);
4821 if(!tmp
|| tmp
== (char*)-1) {
4822 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to print value of property '%s'.\n",
4826 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_%s=%s\n",cmd
->args
[0].v
.s
,tmp
);
4829 case MP_CMD_EDL_MARK
:
4831 float v
= sh_video
? sh_video
->pts
:
4832 playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4834 if(begin_skip
== MP_NOPTS_VALUE
)
4837 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutStartSkip
);
4841 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_EdloutBadStop
);
4843 fprintf(edl_fd
, "%f %f %d\n", begin_skip
, v
, 0);
4844 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutEndSkip
);
4846 begin_skip
= MP_NOPTS_VALUE
;
4850 case MP_CMD_SWITCH_RATIO
: {
4851 if (cmd
->nargs
== 0 || cmd
->args
[0].v
.f
== -1)
4852 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
4854 movie_aspect
= cmd
->args
[0].v
.f
;
4855 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
4857 case MP_CMD_SPEED_INCR
: {
4858 float v
= cmd
->args
[0].v
.f
;
4859 playback_speed
+= v
;
4860 build_afilter_chain(sh_audio
, &ao_data
);
4861 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4863 case MP_CMD_SPEED_MULT
: {
4864 float v
= cmd
->args
[0].v
.f
;
4865 playback_speed
*= v
;
4866 build_afilter_chain(sh_audio
, &ao_data
);
4867 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4869 case MP_CMD_SPEED_SET
: {
4870 float v
= cmd
->args
[0].v
.f
;
4872 build_afilter_chain(sh_audio
, &ao_data
);
4873 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4875 case MP_CMD_FRAME_STEP
:
4876 case MP_CMD_PAUSE
: {
4880 case MP_CMD_FILE_FILTER
: {
4881 file_filter
= cmd
->args
[0].v
.i
;
4884 case MP_CMD_QUIT
: {
4885 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
4887 case MP_CMD_PLAY_TREE_STEP
: {
4888 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
4889 int force
= cmd
->args
[1].v
.i
;
4898 for (i
=0;i
<-1*n
;i
++)
4903 if(!force
&& playtree_iter
) {
4904 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4906 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4907 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4908 play_tree_iter_free(i
);
4910 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4916 case MP_CMD_PLAY_TREE_UP_STEP
: {
4917 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
4918 int force
= cmd
->args
[1].v
.i
;
4920 if(!force
&& playtree_iter
) {
4921 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4922 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4923 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4924 play_tree_iter_free(i
);
4926 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4929 case MP_CMD_PLAY_ALT_SRC_STEP
: {
4930 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
4931 int v
= cmd
->args
[0].v
.i
;
4932 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
4934 else if(v
< 0 && playtree_iter
->file
> 1)
4939 case MP_CMD_SUB_STEP
: {
4941 int movement
= cmd
->args
[0].v
.i
;
4942 step_sub(subdata
, sh_video
->pts
, movement
);
4945 sub_delay
+= ass_step_sub(ass_track
, (sh_video
->pts
+ sub_delay
) * 1000 + .5, movement
) / 1000.;
4947 set_osd_msg(OSD_MSG_SUB_DELAY
,1,osd_duration
,
4948 MSGTR_OSDSubDelay
, ROUND(sub_delay
*1000));
4951 case MP_CMD_SUB_LOG
: {
4955 int v
= cmd
->args
[0].v
.i
;
4956 int max
= (term_osd
&& !sh_video
) ? MAX_TERM_OSD_LEVEL
: MAX_OSD_LEVEL
;
4957 if(osd_level
> max
) osd_level
= max
;
4959 osd_level
=(osd_level
+1)%(max
+1);
4961 osd_level
= v
> max
? max
: v
;
4962 /* Show OSD state when disabled, but not when an explicit
4963 argument is given to the OSD command, i.e. in slave mode. */
4964 if (v
== -1 && osd_level
<= 1)
4965 set_osd_msg(OSD_MSG_OSD_STATUS
,0,osd_duration
,
4966 MSGTR_OSDosd
, osd_level
? MSGTR_OSDenabled
: MSGTR_OSDdisabled
);
4968 rm_osd_msg(OSD_MSG_OSD_STATUS
);
4970 case MP_CMD_OSD_SHOW_TEXT
: {
4971 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4972 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4973 "%-.63s",cmd
->args
[0].v
.s
);
4975 case MP_CMD_OSD_SHOW_PROPERTY_TEXT
: {
4976 char* txt
= m_properties_expand_string(mp_properties
,cmd
->args
[0].v
.s
);
4977 /* if no argument supplied take default osd_duration, else <arg> ms. */
4979 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4980 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4985 case MP_CMD_LOADFILE
: {
4986 play_tree_t
* e
= play_tree_new();
4987 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
4989 if (cmd
->args
[1].v
.i
) // append
4990 play_tree_append_entry(playtree
, e
);
4992 // Go back to the starting point.
4993 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
4995 play_tree_free_list(playtree
->child
,1);
4996 play_tree_set_child(playtree
,e
);
4997 play_tree_iter_step(playtree_iter
,0,0);
5002 case MP_CMD_LOADLIST
: {
5003 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
5005 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
5007 if (cmd
->args
[1].v
.i
) // append
5008 play_tree_append_entry(playtree
, e
);
5010 // Go back to the starting point.
5011 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
5013 play_tree_free_list(playtree
->child
,1);
5014 play_tree_set_child(playtree
,e
);
5015 play_tree_iter_step(playtree_iter
,0,0);
5022 case MP_CMD_RADIO_STEP_CHANNEL
: {
5023 if (demuxer
->stream
->type
==STREAMTYPE_RADIO
) {
5024 int v
= cmd
->args
[0].v
.i
;
5026 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_HIGHER
);
5028 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_LOWER
);
5029 if (radio_get_channel_name(demuxer
->stream
)) {
5030 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
5031 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
5035 case MP_CMD_RADIO_SET_CHANNEL
: {
5036 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
) {
5037 radio_set_channel(demuxer
->stream
, cmd
->args
[0].v
.s
);
5038 if (radio_get_channel_name(demuxer
->stream
)) {
5039 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
5040 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
5044 case MP_CMD_RADIO_SET_FREQ
: {
5045 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
)
5046 radio_set_freq(demuxer
->stream
, cmd
->args
[0].v
.f
);
5048 case MP_CMD_RADIO_STEP_FREQ
:
5049 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
){
5050 radio_step_freq(demuxer
->stream
, cmd
->args
[0].v
.f
);
5055 case MP_CMD_TV_SET_FREQ
: {
5056 if (file_format
== DEMUXER_TYPE_TV
)
5057 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
5059 case MP_CMD_TV_SET_NORM
: {
5060 if (file_format
== DEMUXER_TYPE_TV
)
5061 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
5063 case MP_CMD_TV_STEP_CHANNEL
: {
5064 if (file_format
== DEMUXER_TYPE_TV
) {
5065 int v
= cmd
->args
[0].v
.i
;
5067 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
5069 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
5071 if (tv_channel_list
) {
5072 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5073 MSGTR_OSDChannel
, tv_channel_current
->name
);
5074 //vo_osd_changed(OSDTYPE_SUBTITLE);
5078 #ifdef HAS_DVBIN_SUPPORT
5079 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
5081 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
5085 int v
= cmd
->args
[0].v
.i
;
5089 dir
= DVB_CHANNEL_HIGHER
;
5091 dir
= DVB_CHANNEL_LOWER
;
5094 if(dvb_step_channel(priv
, dir
))
5095 eof
= dvbin_reopen
= 1;
5098 #endif /* HAS_DVBIN_SUPPORT */
5100 case MP_CMD_TV_SET_CHANNEL
: {
5101 if (file_format
== DEMUXER_TYPE_TV
) {
5102 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
5103 if (tv_channel_list
) {
5104 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5105 MSGTR_OSDChannel
, tv_channel_current
->name
);
5106 //vo_osd_changed(OSDTYPE_SUBTITLE);
5110 #ifdef HAS_DVBIN_SUPPORT
5111 case MP_CMD_DVB_SET_CHANNEL
:
5113 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
5115 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
5118 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
5123 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
5124 eof
= dvbin_reopen
= 1;
5129 #endif /* HAS_DVBIN_SUPPORT */
5130 case MP_CMD_TV_LAST_CHANNEL
: {
5131 if (file_format
== DEMUXER_TYPE_TV
) {
5132 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
5133 if (tv_channel_list
) {
5134 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5135 MSGTR_OSDChannel
, tv_channel_current
->name
);
5136 //vo_osd_changed(OSDTYPE_SUBTITLE);
5140 case MP_CMD_TV_STEP_NORM
: {
5141 if (file_format
== DEMUXER_TYPE_TV
)
5142 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
5144 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
5145 if (file_format
== DEMUXER_TYPE_TV
)
5146 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
5149 case MP_CMD_SUB_LOAD
:
5152 int n
= set_of_sub_size
;
5153 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
5154 if (n
!= set_of_sub_size
) {
5155 if (global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
5156 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
;
5161 case MP_CMD_SUB_REMOVE
:
5164 int v
= cmd
->args
[0].v
.i
;
5167 for (v
= 0; v
< set_of_sub_size
; ++v
) {
5168 subd
= set_of_subtitles
[v
];
5169 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1,
5170 filename_recode(subd
->filename
));
5172 set_of_subtitles
[v
] = NULL
;
5174 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5175 global_sub_size
-= set_of_sub_size
;
5176 set_of_sub_size
= 0;
5177 if (set_of_sub_pos
>= 0) {
5178 global_sub_pos
= -2;
5179 vo_sub_last
= vo_sub
= NULL
;
5180 vo_osd_changed(OSDTYPE_SUBTITLE
);
5181 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5182 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5185 else if (v
< set_of_sub_size
) {
5186 subd
= set_of_subtitles
[v
];
5187 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1,
5188 filename_recode(subd
->filename
));
5190 if (set_of_sub_pos
== v
) {
5191 global_sub_pos
= -2;
5192 vo_sub_last
= vo_sub
= NULL
;
5193 vo_osd_changed(OSDTYPE_SUBTITLE
);
5194 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5195 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5197 else if (set_of_sub_pos
> v
) {
5201 while (++v
< set_of_sub_size
)
5202 set_of_subtitles
[v
- 1] = set_of_subtitles
[v
];
5205 if (set_of_sub_size
<= 0)
5206 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5207 set_of_subtitles
[set_of_sub_size
] = NULL
;
5211 case MP_CMD_GET_SUB_VISIBILITY
:
5214 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_SUB_VISIBILITY=%d\n", sub_visibility
);
5217 case MP_CMD_SCREENSHOT
:
5218 if(vo_config_count
){
5219 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"sending VFCTRL_SCREENSHOT!\n");
5220 if(CONTROL_OK
!=((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_SCREENSHOT
, &cmd
->args
[0].v
.i
))
5221 video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
5224 case MP_CMD_VF_CHANGE_RECTANGLE
:
5225 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
5228 case MP_CMD_GET_TIME_LENGTH
: {
5229 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
5232 case MP_CMD_GET_FILENAME
: {
5233 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_FILENAME='%s'\n", get_metadata (META_NAME
));
5236 case MP_CMD_GET_VIDEO_CODEC
: {
5237 char *inf
= get_metadata (META_VIDEO_CODEC
);
5238 if (!inf
) inf
= strdup ("");
5239 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_CODEC='%s'\n", inf
);
5243 case MP_CMD_GET_VIDEO_BITRATE
: {
5244 char *inf
= get_metadata (META_VIDEO_BITRATE
);
5245 if (!inf
) inf
= strdup ("");
5246 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_BITRATE='%s'\n", inf
);
5250 case MP_CMD_GET_VIDEO_RESOLUTION
: {
5251 char *inf
= get_metadata (META_VIDEO_RESOLUTION
);
5252 if (!inf
) inf
= strdup ("");
5253 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_RESOLUTION='%s'\n", inf
);
5257 case MP_CMD_GET_AUDIO_CODEC
: {
5258 char *inf
= get_metadata (META_AUDIO_CODEC
);
5259 if (!inf
) inf
= strdup ("");
5260 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_CODEC='%s'\n", inf
);
5264 case MP_CMD_GET_AUDIO_BITRATE
: {
5265 char *inf
= get_metadata (META_AUDIO_BITRATE
);
5266 if (!inf
) inf
= strdup ("");
5267 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_BITRATE='%s'\n", inf
);
5271 case MP_CMD_GET_AUDIO_SAMPLES
: {
5272 char *inf
= get_metadata (META_AUDIO_SAMPLES
);
5273 if (!inf
) inf
= strdup ("");
5274 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_SAMPLES='%s'\n", inf
);
5278 case MP_CMD_GET_META_TITLE
: {
5279 char *inf
= get_metadata (META_INFO_TITLE
);
5280 if (!inf
) inf
= strdup ("");
5281 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TITLE='%s'\n", inf
);
5285 case MP_CMD_GET_META_ARTIST
: {
5286 char *inf
= get_metadata (META_INFO_ARTIST
);
5287 if (!inf
) inf
= strdup ("");
5288 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ARTIST='%s'\n", inf
);
5292 case MP_CMD_GET_META_ALBUM
: {
5293 char *inf
= get_metadata (META_INFO_ALBUM
);
5294 if (!inf
) inf
= strdup ("");
5295 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ALBUM='%s'\n", inf
);
5299 case MP_CMD_GET_META_YEAR
: {
5300 char *inf
= get_metadata (META_INFO_YEAR
);
5301 if (!inf
) inf
= strdup ("");
5302 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_YEAR='%s'\n", inf
);
5306 case MP_CMD_GET_META_COMMENT
: {
5307 char *inf
= get_metadata (META_INFO_COMMENT
);
5308 if (!inf
) inf
= strdup ("");
5309 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_COMMENT='%s'\n", inf
);
5313 case MP_CMD_GET_META_TRACK
: {
5314 char *inf
= get_metadata (META_INFO_TRACK
);
5315 if (!inf
) inf
= strdup ("");
5316 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TRACK='%s'\n", inf
);
5320 case MP_CMD_GET_META_GENRE
: {
5321 char *inf
= get_metadata (META_INFO_GENRE
);
5322 if (!inf
) inf
= strdup ("");
5323 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_GENRE='%s'\n", inf
);
5327 case MP_CMD_GET_VO_FULLSCREEN
: {
5328 if(video_out
&& vo_config_count
)
5329 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VO_FULLSCREEN=%d\n", vo_fs
);
5332 case MP_CMD_GET_PERCENT_POS
: {
5333 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer
));
5335 case MP_CMD_GET_TIME_POS
: {
5338 pos
= sh_video
->pts
;
5340 if (sh_audio
&& audio_out
)
5341 pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
5342 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
5347 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
5352 case MP_CMD_KEYDOWN_EVENTS
: {
5353 mplayer_put_key(cmd
->args
[0].v
.i
);
5355 case MP_CMD_SEEK_CHAPTER
: {
5356 int seek
= cmd
->args
[0].v
.i
;
5357 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
5365 chap
= demuxer_seek_chapter(demuxer
, seek
, abs
, &next_pts
, &num_chapters
, &chapter_name
);
5367 if(next_pts
> -1.0) {
5369 rel_seek_secs
= next_pts
;
5372 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
,
5373 chap
+1, chapter_name
);
5378 rel_seek_secs
= 1000000000.;
5380 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
, 0, MSGTR_Unknown
);
5384 case MP_CMD_SET_MOUSE_POS
: {
5385 int button
= -1, pointer_x
, pointer_y
;
5387 pointer_x
= cmd
->args
[0].v
.i
;
5388 pointer_y
= cmd
->args
[1].v
.i
;
5389 rescale_input_coordinates(pointer_x
, pointer_y
, &dx
, &dy
);
5391 if(stream
->type
== STREAMTYPE_DVDNAV
&& dx
> 0.0 && dy
> 0.0) {
5392 pointer_x
= (int) (dx
* (double) sh_video
->disp_w
);
5393 pointer_y
= (int) (dy
* (double) sh_video
->disp_h
);
5394 mp_dvdnav_update_mouse_pos(stream
, pointer_x
, pointer_y
, &button
);
5395 if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5401 case MP_CMD_DVDNAV
: {
5403 if(stream
->type
!= STREAMTYPE_DVDNAV
) break;
5405 if(mp_dvdnav_handle_input(stream
, cmd
->args
[0].v
.i
, &button
)) {
5406 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
|(fixed_vo
? INITED_VO
: 0)));
5407 goto goto_enable_cache
;
5408 } else if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5414 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
5417 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
5420 switch (cmd
->pausing
) {
5421 case 1: // "pausing"
5422 osd_function
= OSD_PAUSE
;
5424 case 3: // "pausing_toggle"
5425 was_paused
= !was_paused
;
5427 case 2: // "pausing_keep"
5428 if (was_paused
) osd_function
= OSD_PAUSE
;
5438 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
5439 rel_seek_secs
+= 3600*a
+60*b
+d
;
5440 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
5441 rel_seek_secs
+= 60*a
+d
;
5442 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
5448 if (end_at
.type
!= END_AT_NONE
) {
5449 if(end_at
.type
== END_AT_SIZE
) {
5450 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
5451 end_at
.type
= END_AT_NONE
;
5453 end_at
.pos
+= rel_seek_secs
;
5458 if(eof
==1 && loop_times
>=0) {
5460 play_tree_iter_step(playtree_iter
,0,0);
5462 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
5464 if(loop_times
>1) loop_times
--; else
5465 if(loop_times
==1) loop_times
=-1;
5466 play_n_frames
=play_n_frames_mf
;
5468 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
5472 if(rel_seek_secs
|| abs_seek_pos
){
5473 current_module
="seek";
5474 if(demux_seek(demuxer
,rel_seek_secs
,audio_delay
,abs_seek_pos
)){
5476 /* FIXME there should be real seeking for vobsub */
5477 if(sh_video
) sh_video
->pts
=d_video
->pts
;
5479 //vobsub_reset(vo_vobsub);
5480 vobsub_seek(vo_vobsub
,sh_video
->pts
);
5484 current_module
="seek_video_reset";
5485 resync_video_stream(sh_video
);
5486 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
5487 sh_video
->num_buffered_pts
= 0;
5488 sh_video
->last_pts
= MP_NOPTS_VALUE
;
5492 current_module
="seek_audio_reset";
5493 audio_out
->reset(); // stop audio, throwing away buffered data
5494 sh_audio
->a_buffer_len
= 0;
5495 sh_audio
->a_out_buffer_len
= 0;
5500 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer
));
5505 max_pts_correction
=0.1;
5506 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
5507 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
5510 update_subtitles(sh_video
, d_dvdsub
, 1);
5514 * We saw a seek, have to rewind the EDL operations stack
5515 * and find the next EDL action to take care of.
5519 next_edl_record
= edl_records
;
5521 while (next_edl_record
)
5523 /* Trying to remember if we need to mute/unmute first;
5524 * prior EDL implementation lacks this.
5527 if (next_edl_record
->start_sec
>= sh_video
->pts
)
5530 if (next_edl_record
->action
== EDL_MUTE
) edl_muted
= !edl_muted
;
5531 next_edl_record
= next_edl_record
->next
;
5534 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
5538 frame_time_remaining
=0;
5539 current_module
=NULL
;
5546 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
5547 // get pos from frame number / total frames
5548 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
5550 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
5551 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
5552 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
5554 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
5555 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
5556 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
5557 guiGetEvent( guiReDraw
,NULL
);
5558 guiGetEvent( guiSetVolume
,NULL
);
5559 if(guiIntfStruct
.Playing
==0) break; // STOP
5560 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
5561 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
5563 if ( stream
->type
== STREAMTYPE_DVD
)
5565 dvd_priv_t
* dvdp
= stream
->priv
;
5566 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
5570 #endif /* HAVE_NEW_GUI */
5574 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
5576 #ifdef HAS_DVBIN_SUPPORT
5580 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
5581 cache_uninit(stream
);
5583 goto goto_enable_cache
;
5588 goto_next_file
: // don't jump here after ao/vo/getch initialization!
5590 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
5593 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
5594 double total_time_usage
;
5595 total_time_usage_start
=GetTimer()-total_time_usage_start
;
5596 total_time_usage
= (float)total_time_usage_start
*0.000001;
5597 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5598 video_time_usage
,vout_time_usage
,audio_time_usage
,
5599 total_time_usage
-tot
,total_time_usage
);
5600 if(total_time_usage
>0.0)
5601 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5602 100.0*video_time_usage
/total_time_usage
,
5603 100.0*vout_time_usage
/total_time_usage
,
5604 100.0*audio_time_usage
/total_time_usage
,
5605 100.0*(total_time_usage
-tot
)/total_time_usage
,
5607 if(total_frame_cnt
&& frame_dropping
)
5608 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5609 total_frame_cnt
-drop_frame_cnt
,
5610 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
5612 100*drop_frame_cnt
/total_frame_cnt
,
5614 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
5618 // time to uninit all, except global stuff:
5619 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
5621 if ( set_of_sub_size
> 0 )
5623 current_module
="sub_free";
5624 for (i
= 0; i
< set_of_sub_size
; ++i
) {
5625 sub_free( set_of_subtitles
[i
] );
5627 if ( set_of_ass_tracks
[i
] )
5628 ass_free_track( set_of_ass_tracks
[i
] );
5631 set_of_sub_size
= 0;
5633 vo_sub_last
= vo_sub
=NULL
;
5639 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
5640 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
5641 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
5644 play_tree_iter_free(playtree_iter
);
5645 playtree_iter
= NULL
;
5648 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
5649 eof
= eof
== PT_UP_NEXT
? 1 : -1;
5650 if ( playtree_iter
) {
5651 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
5654 play_tree_iter_free(playtree_iter
);
5655 playtree_iter
= NULL
;
5658 } else { // NEXT PREV SRC
5659 eof
= eof
== PT_PREV_SRC
? -1 : 1;
5662 if(eof
== 0) eof
= 1;
5664 while(playtree_iter
!= NULL
) {
5665 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
5666 if(filename
== NULL
) {
5667 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
5668 play_tree_iter_free(playtree_iter
);
5669 playtree_iter
= NULL
;
5676 if( use_gui
&& !playtree_iter
)
5679 if ( !guiIntfStruct
.DiskChanged
)
5685 if(use_gui
|| playtree_iter
!= NULL
|| player_idle_mode
){
5686 if (!playtree_iter
) filename
= NULL
;
5688 goto play_next_file
;
5692 exit_player_with_rc(MSGTR_Exit_eof
, 0);