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 int osd_level_saved
=-1;
242 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
243 unsigned int osd_visible
;
244 static int osd_function
=OSD_PLAY
;
245 static int osd_show_percentage
= 0;
246 static int osd_duration
= 1000;
248 static int term_osd
= 1;
249 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
250 static char* playing_msg
= NULL
;
252 static char *seek_to_sec
=NULL
;
253 static off_t seek_to_byte
=0;
254 static off_t step_sec
=0;
255 static int loop_times
=-1;
256 static int loop_seek
=0;
258 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
261 int autosync
=0; // 30 might be a good default value.
263 // may be changed by GUI: (FIXME!)
264 float rel_seek_secs
=0;
268 char **audio_codec_list
=NULL
; // override audio codec
269 char **video_codec_list
=NULL
; // override video codec
270 char **audio_fm_list
=NULL
; // override audio codec family
271 char **video_fm_list
=NULL
; // override video codec family
274 extern char *demuxer_name
; // override demuxer
275 extern char *audio_demuxer_name
; // override audio demuxer
276 extern char *sub_demuxer_name
; // override sub demuxer
283 char* audio_lang
=NULL
;
284 char* dvdsub_lang
=NULL
;
285 static char* spudec_ifo
=NULL
;
286 char* filename
=NULL
; //"MI2-Trailer.avi";
287 int forced_subs_only
=0;
291 int stream_cache_size
=-1;
292 #ifdef USE_STREAM_CACHE
293 extern int cache_fill_status
;
295 float stream_cache_min_percent
=20.0;
296 float stream_cache_seek_min_percent
=50.0;
298 #define cache_fill_status 0
302 static char *stream_dump_name
="stream.dump";
303 int stream_dump_type
=0;
306 static float default_max_pts_correction
=-1;//0.01f;
307 static float max_pts_correction
=0;//default_max_pts_correction;
308 static float c_total
=0;
310 static int ignore_start
=0;
312 static int softsleep
=0;
315 static int force_srate
=0;
316 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
317 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
318 static int play_n_frames
=-1;
319 static int play_n_frames_mf
=-1;
322 char** video_driver_list
=NULL
;
323 char** audio_driver_list
=NULL
;
325 extern char *vo_subdevice
;
326 extern char *ao_subdevice
;
328 // codec outfmt flags (defined in libmpcodecs/vd.c)
332 char *font_name
=NULL
;
333 #ifdef HAVE_FONTCONFIG
334 extern int font_fontconfig
;
336 float font_factor
=0.75;
337 char **sub_name
=NULL
;
341 char *vobsub_name
=NULL
;
342 /*DSP!!char *dsp=NULL;*/
344 int suboverlap_enabled
= 1;
346 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
347 int set_of_sub_size
= 0;
348 int set_of_sub_pos
= -1;
349 double sub_last_pts
= -303;
351 int global_sub_size
= 0; // this encompasses all subtitle sources
352 int global_sub_pos
= -1; // this encompasses all subtitle sources
353 #define SUB_SOURCE_SUBS 0
354 #define SUB_SOURCE_VOBSUB 1
355 #define SUB_SOURCE_DEMUX 2
356 #define SUB_SOURCES 3
357 int global_sub_indices
[SUB_SOURCES
];
360 #include "libass/ass.h"
361 #include "libass/ass_mp.h"
363 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
364 // or NULL if format unsupported
365 ass_track_t
* set_of_ass_tracks
[MAX_SUBTITLE_FILES
];
366 ass_track_t
* ass_track
= 0; // current track to render
369 extern int mp_msg_levels
[MSGT_MAX
];
370 extern int mp_msg_level_all
;
372 static stream_t
* stream
=NULL
;
373 static demuxer_t
*demuxer
=NULL
;
374 static sh_audio_t
*sh_audio
=NULL
;
375 static sh_video_t
*sh_video
=NULL
;
376 static demux_stream_t
*d_audio
=NULL
;
377 static demux_stream_t
*d_video
=NULL
;
378 static demux_stream_t
*d_dvdsub
=NULL
;
380 char* current_module
=NULL
; // for debugging
382 extern int vo_gamma_gamma
;
383 extern int vo_gamma_brightness
;
384 extern int vo_gamma_contrast
;
385 extern int vo_gamma_saturation
;
386 extern int vo_gamma_hue
;
391 #include "m_struct.h"
392 #include "libmenu/menu.h"
393 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
394 extern vf_info_t vf_info_menu
;
395 static vf_info_t
* libmenu_vfs
[] = {
399 static vf_instance_t
* vf_menu
= NULL
;
400 static int use_menu
= 0;
401 static char* menu_cfg
= NULL
;
402 static char* menu_root
= "main";
407 static int nortc
= 1;
408 static char* rtc_device
;
411 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
412 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
413 short user_muted
= 0; ///< Stores whether user wanted muted mode.
414 short edl_muted
= 0; ///< Stores whether EDL is currently in muted mode.
415 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
416 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
417 float begin_skip
= MP_NOPTS_VALUE
; ///< start time of the current skip while on edlout mode
418 int use_filedir_conf
;
420 static unsigned int inited_flags
=0;
424 #define INITED_GETCH2 8
425 #define INITED_SPUDEC 32
426 #define INITED_STREAM 64
427 #define INITED_INPUT 128
428 #define INITED_VOBSUB 256
429 #define INITED_DEMUXER 512
430 #define INITED_ACODEC 1024
431 #define INITED_VCODEC 2048
432 #define INITED_ALL 0xFFFF
434 #include "metadata.h"
436 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
438 static int is_valid_metadata_type (metadata_t type
) {
441 /* check for valid video stream */
442 case META_VIDEO_CODEC
:
443 case META_VIDEO_BITRATE
:
444 case META_VIDEO_RESOLUTION
:
451 /* check for valid audio stream */
452 case META_AUDIO_CODEC
:
453 case META_AUDIO_BITRATE
:
454 case META_AUDIO_SAMPLES
:
461 /* check for valid demuxer */
462 case META_INFO_TITLE
:
463 case META_INFO_ARTIST
:
464 case META_INFO_ALBUM
:
466 case META_INFO_COMMENT
:
467 case META_INFO_TRACK
:
468 case META_INFO_GENRE
:
482 static char *get_demuxer_info (char *tag
) {
483 char **info
= demuxer
->info
;
489 for (n
= 0; info
[2*n
] != NULL
; n
++)
490 if (!strcmp (info
[2*n
], tag
))
493 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
496 char *get_metadata (metadata_t type
) {
499 if (!is_valid_metadata_type (type
))
506 return strdup (mp_basename2 (filename
));
509 case META_VIDEO_CODEC
:
511 if (sh_video
->format
== 0x10000001)
512 meta
= strdup ("mpeg1");
513 else if (sh_video
->format
== 0x10000002)
514 meta
= strdup ("mpeg2");
515 else if (sh_video
->format
== 0x10000004)
516 meta
= strdup ("mpeg4");
517 else if (sh_video
->format
== 0x10000005)
518 meta
= strdup ("h264");
519 else if (sh_video
->format
>= 0x20202020)
521 meta
= (char *) malloc (8);
522 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
526 meta
= (char *) malloc (8);
527 sprintf (meta
, "0x%08X", sh_video
->format
);
532 case META_VIDEO_BITRATE
:
534 meta
= (char *) malloc (16);
535 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
539 case META_VIDEO_RESOLUTION
:
541 meta
= (char *) malloc (16);
542 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
546 case META_AUDIO_CODEC
:
548 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
549 meta
= strdup (sh_audio
->codec
->name
);
553 case META_AUDIO_BITRATE
:
555 meta
= (char *) malloc (16);
556 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
560 case META_AUDIO_SAMPLES
:
562 meta
= (char *) malloc (16);
563 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
567 /* check for valid demuxer */
568 case META_INFO_TITLE
:
569 return get_demuxer_info ("Title");
571 case META_INFO_ARTIST
:
572 return get_demuxer_info ("Artist");
574 case META_INFO_ALBUM
:
575 return get_demuxer_info ("Album");
578 return get_demuxer_info ("Year");
580 case META_INFO_COMMENT
:
581 return get_demuxer_info ("Comment");
583 case META_INFO_TRACK
:
584 return get_demuxer_info ("Track");
586 case META_INFO_GENRE
:
587 return get_demuxer_info ("Genre");
596 static void uninit_player(unsigned int mask
){
597 mask
=inited_flags
&mask
;
599 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
601 if(mask
&INITED_ACODEC
){
602 inited_flags
&=~INITED_ACODEC
;
603 current_module
="uninit_acodec";
604 if(sh_audio
) uninit_audio(sh_audio
);
606 guiGetEvent(guiSetAfilter
, (char *)NULL
);
611 if(mask
&INITED_VCODEC
){
612 inited_flags
&=~INITED_VCODEC
;
613 current_module
="uninit_vcodec";
614 if(sh_video
) uninit_video(sh_video
);
621 if(mask
&INITED_DEMUXER
){
622 inited_flags
&=~INITED_DEMUXER
;
623 current_module
="free_demuxer";
625 stream
=demuxer
->stream
;
626 free_demuxer(demuxer
);
631 // kill the cache process:
632 if(mask
&INITED_STREAM
){
633 inited_flags
&=~INITED_STREAM
;
634 current_module
="uninit_stream";
635 if(stream
) free_stream(stream
);
640 inited_flags
&=~INITED_VO
;
641 current_module
="uninit_vo";
646 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
647 if(mask
&INITED_GETCH2
){
648 inited_flags
&=~INITED_GETCH2
;
649 current_module
="uninit_getch2";
650 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
655 if(mask
&INITED_VOBSUB
){
656 inited_flags
&=~INITED_VOBSUB
;
657 current_module
="uninit_vobsub";
658 if(vo_vobsub
) vobsub_close(vo_vobsub
);
662 if (mask
&INITED_SPUDEC
){
663 inited_flags
&=~INITED_SPUDEC
;
664 current_module
="uninit_spudec";
665 spudec_free(vo_spudec
);
670 inited_flags
&=~INITED_AO
;
671 current_module
="uninit_ao";
672 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
677 inited_flags
&=~INITED_GUI
;
678 current_module
="uninit_gui";
683 if(mask
&INITED_INPUT
){
684 inited_flags
&=~INITED_INPUT
;
685 current_module
="uninit_input";
692 static void exit_player_with_rc(const char* how
, int rc
){
694 uninit_player(INITED_ALL
);
699 vo_uninit(); // Close the X11 connection (if any is open).
703 current_module
="uninit_font";
704 if (vo_font
) free_font_desc(vo_font
);
711 ass_library_done(ass_library
);
714 current_module
="exit_player";
716 // free mplayer config
718 m_config_free(mconfig
);
721 play_tree_free(playtree
, 1);
724 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
725 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
726 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
731 void exit_player(const char* how
){
732 exit_player_with_rc(how
, 1);
736 static void child_sighandler(int x
){
738 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
743 static char *prog_path
;
744 static int crash_debug
= 0;
747 static void exit_sighandler(int x
){
748 static int sig_count
=0;
750 if (!crash_debug
|| x
!= SIGTRAP
)
753 if(inited_flags
==0 && sig_count
>1) exit(1);
756 /* We're crashing bad and can't uninit cleanly :(
757 * by popular request, we make one last (dirty)
758 * effort to restore the user's
763 if(sig_count
==6) exit(1);
767 kill(getpid(),SIGKILL
);
770 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
771 current_module
?current_module
:"unknown"
773 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
780 break; // killed from keyboard (^C) or killed [-9]
782 #ifdef RUNTIME_CPUDETECT
783 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
785 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
789 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
791 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
796 snprintf(spid
, 19, "%i", getpid());
798 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
800 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
801 if (gdb_pid
== 0) { // We are the child
802 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
803 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
804 } else if (gdb_pid
< 0)
805 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
807 waitpid(gdb_pid
, NULL
, 0);
809 if (x
== SIGTRAP
) return;
816 extern void mp_input_register_options(m_config_t
* cfg
);
820 /// step size of mixer changes
823 #include "cfg-mplayer.h"
825 static void parse_cfgfiles( m_config_t
* conf
)
829 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
831 if ((conffile
= get_path("")) == NULL
) {
832 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
837 mkdir(conffile
, 0777);
840 if ((conffile
= get_path("config")) == NULL
) {
841 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
843 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
844 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
845 write(conffile_fd
, default_config
, strlen(default_config
));
848 if (m_config_parse_config_file(conf
, conffile
) < 0)
855 void load_per_file_config (m_config_t
* conf
, const char *const file
)
858 char cfg
[strlen(file
)+10];
862 sprintf (cfg
, "%s.conf", file
);
864 if (use_filedir_conf
&& !stat (cfg
, &st
))
866 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
867 m_config_parse_config_file (conf
, cfg
);
871 if ((name
= strrchr (cfg
, '/')) == NULL
)
876 if ((confpath
= get_path (name
)) != NULL
)
878 if (!stat (confpath
, &st
))
880 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
881 m_config_parse_config_file (conf
, confpath
);
888 /* When libmpdemux performs a blocking operation (network connection or
889 * cache filling) if the operation fails we use this function to check
890 * if it was interrupted by the user.
891 * The function returns a new value for eof. */
892 static int libmpdemux_was_interrupted(int eof
) {
894 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
897 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
898 case MP_CMD_PLAY_TREE_STEP
: {
899 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
900 play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
902 case MP_CMD_PLAY_TREE_UP_STEP
: {
903 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
905 case MP_CMD_PLAY_ALT_SRC_STEP
: {
906 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
914 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
916 int playtree_add_playlist(play_tree_t
* entry
)
918 play_tree_add_bpf(entry
,filename
);
923 import_playtree_playlist_into_gui(entry
, mconfig
);
924 play_tree_free_list(entry
,1);
930 entry
= playtree_iter
->tree
;
931 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
932 return PT_NEXT_ENTRY
;
934 if(playtree_iter
->tree
== entry
) { // Loop with a single file
935 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
936 return PT_NEXT_ENTRY
;
939 play_tree_remove(entry
,1,1);
942 play_tree_insert_entry(playtree_iter
->tree
,entry
);
943 play_tree_set_params_from(entry
,playtree_iter
->tree
);
944 entry
= playtree_iter
->tree
;
945 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
946 return PT_NEXT_ENTRY
;
948 play_tree_remove(entry
,1,1);
958 for (i
= 0; i
< SUB_SOURCES
; i
++) {
959 int j
= global_sub_indices
[i
];
960 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
968 sub_data
* subdata
= NULL
;
969 static subtitle
* vo_sub_last
= NULL
;
971 void add_subtitles(char *filename
, float fps
, int silent
)
975 ass_track_t
*asst
= 0;
978 if (filename
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
982 subd
= sub_read_file(filename
, fps
);
986 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
988 asst
= ass_read_file(ass_library
, filename
, 0);
990 if (ass_enabled
&& subd
&& !asst
)
991 asst
= ass_read_subdata(ass_library
, subd
, fps
);
993 if (!asst
&& !subd
&& !silent
)
997 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
1000 if (!asst
&& !subd
) return;
1001 set_of_ass_tracks
[set_of_sub_size
] = asst
;
1005 set_of_subtitles
[set_of_sub_size
] = subd
;
1006 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", set_of_sub_size
);
1007 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n", filename
);
1009 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, set_of_sub_size
, filename
);
1012 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1013 void update_set_of_subtitles(void)
1014 // subdata was changed, set_of_sub... have to be updated.
1017 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
1018 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
1019 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
1020 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
1022 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
1024 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
1025 set_of_subtitles
[set_of_sub_pos
] = subdata
;
1027 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
1028 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
1033 void init_vo_spudec(void) {
1035 spudec_free(vo_spudec
);
1036 inited_flags
&= ~INITED_SPUDEC
;
1039 unsigned int palette
[16], width
, height
;
1040 current_module
="spudec_init_vobsub";
1041 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1042 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1046 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
1047 current_module
="spudec_init_dvdread";
1048 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
1049 sh_video
->disp_w
, sh_video
->disp_h
);
1054 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
1055 unsigned int *palette
= mp_dvdnav_get_spu_clut(stream
);
1056 current_module
="spudec_init_dvdnav";
1057 vo_spudec
=spudec_new_scaled(palette
, sh_video
->disp_w
, sh_video
->disp_h
);
1061 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1062 (d_dvdsub
->sh
!= NULL
) && (((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
1063 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)d_dvdsub
->sh
;
1064 current_module
= "spudec_init_matroska";
1066 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1067 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1068 mkv_sh_sub
->height
);
1069 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1072 if (vo_spudec
==NULL
) {
1073 sh_sub_t
*sh
= (sh_sub_t
*)d_dvdsub
->sh
;
1074 unsigned int *palette
= NULL
;
1075 if (sh
&& sh
->has_palette
)
1076 palette
= sh
->palette
;
1077 current_module
="spudec_init_normal";
1078 vo_spudec
=spudec_new_scaled(palette
, sh_video
->disp_w
, sh_video
->disp_h
);
1079 spudec_set_font_factor(vo_spudec
,font_factor
);
1082 if (vo_spudec
!=NULL
)
1083 inited_flags
|=INITED_SPUDEC
;
1087 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1088 * make it all work is to use the builtin SDL-bootstrap code, which
1089 * will be done automatically by replacing our main() if we include SDL.h.
1091 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1096 * \brief append a formatted string
1097 * \param buf buffer to print into
1098 * \param pos position of terminating 0 in buf
1099 * \param len maximum number of characters in buf, not including terminating 0
1100 * \param format printf format string
1102 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1105 va_start(va
, format
);
1106 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1115 * \brief append time in the hh:mm:ss.f format
1116 * \param buf buffer to print into
1117 * \param pos position of terminating 0 in buf
1118 * \param len maximum number of characters in buf, not including terminating 0
1119 * \param time time value to convert/append
1121 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1122 long tenths
= 10 * time
;
1123 int f1
= tenths
% 10;
1124 int ss
= (tenths
/ 10) % 60;
1125 int mm
= (tenths
/ 600) % 60;
1126 int hh
= tenths
/ 36000;
1128 saddf(buf
, pos
, len
, "unknown");
1132 saddf(buf
, pos
, len
, "%2d:", hh
);
1133 if (hh
> 0 || mm
> 0)
1134 saddf(buf
, pos
, len
, "%02d:", mm
);
1135 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1139 * \brief print the status line
1140 * \param a_pos audio position
1141 * \param a_v A-V desynchronization
1142 * \param corr amount out A-V synchronization
1144 static void print_status(float a_pos
, float a_v
, float corr
)
1150 if (screen_width
> 0)
1151 width
= screen_width
;
1155 /* Windows command line is broken (MinGW's rxvt works, but we
1156 * should not depend on that). */
1159 line
= malloc(width
+ 1); // one additional char for the terminating null
1163 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1165 float len
= demuxer_get_time_length(demuxer
);
1166 saddf(line
, &pos
, width
, "(");
1167 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1168 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1169 sadd_hhmmssf(line
, &pos
, width
, len
);
1170 saddf(line
, &pos
, width
, ") ");
1176 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1179 if (sh_audio
&& sh_video
)
1180 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1184 saddf(line
, &pos
, width
, "%3d/%3d ",
1185 (int)sh_video
->num_frames
,
1186 (int)sh_video
->num_frames_decoded
);
1190 if (sh_video
->timer
> 0.5)
1191 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1192 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
1193 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
1194 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
1196 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1197 } else if (sh_audio
) {
1198 if (sh_audio
->delay
> 0.5)
1199 saddf(line
, &pos
, width
, "%4.1f%% ",
1200 100.0*audio_time_usage
/(double)sh_audio
->delay
);
1202 saddf(line
, &pos
, width
, "??,?%% ");
1207 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1209 #ifdef USE_STREAM_CACHE
1211 if (stream_cache_size
> 0)
1212 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1216 if (playback_speed
!= 1)
1217 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
1220 if (erase_to_end_of_line
) {
1222 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1224 memset(&line
[pos
], ' ', width
- pos
);
1226 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
1232 * \brief build a chain of audio filters that converts the input format
1233 * to the ao's format, taking into account the current playback_speed.
1234 * \param sh_audio describes the requested input format of the chain.
1235 * \param ao_data describes the requested output format of the chain.
1237 static int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1244 guiGetEvent(guiSetAfilter
, (char *)NULL
);
1246 mixer
.afilter
= NULL
;
1249 new_srate
= sh_audio
->samplerate
* playback_speed
;
1250 if (new_srate
!= ao_data
->samplerate
) {
1251 // limits are taken from libaf/af_resample.c
1252 if (new_srate
< 8000)
1254 if (new_srate
> 192000)
1256 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1258 result
= init_audio_filters(sh_audio
, new_srate
,
1259 sh_audio
->channels
, sh_audio
->sample_format
,
1260 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1261 ao_data
->outburst
* 4, ao_data
->buffersize
);
1262 mixer
.afilter
= sh_audio
->afilter
;
1264 guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1270 * \brief Log the currently displayed subtitle to a file
1272 * Logs the current or last displayed subtitle together with filename
1273 * and time information to ~/.mplayer/subtitle_log
1275 * Intended purpose is to allow convenient marking of bogus subtitles
1276 * which need to be fixed while watching the movie.
1279 static void log_sub(void){
1284 if (subdata
== NULL
|| vo_sub_last
== NULL
) return;
1285 fname
= get_path("subtitle_log");
1286 f
= fopen(fname
, "a");
1288 fprintf(f
, "----------------------------------------------------------\n");
1289 if (subdata
->sub_uses_time
) {
1290 fprintf(f
, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename
,
1291 vo_sub_last
->start
/360000, (vo_sub_last
->start
/6000)%60,
1292 (vo_sub_last
->start
/100)%60, vo_sub_last
->start
%100,
1293 vo_sub_last
->end
/360000, (vo_sub_last
->end
/6000)%60,
1294 (vo_sub_last
->end
/100)%60, vo_sub_last
->end
%100);
1296 fprintf(f
, "N: %s S: %ld E: %ld\n", filename
, vo_sub_last
->start
, vo_sub_last
->end
);
1298 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
1299 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
1304 /// \defgroup OSDMsgStack OSD message stack
1308 #define OSD_MSG_TV_CHANNEL 0
1309 #define OSD_MSG_TEXT 1
1310 #define OSD_MSG_SUB_DELAY 2
1311 #define OSD_MSG_SPEED 3
1312 #define OSD_MSG_OSD_STATUS 4
1313 #define OSD_MSG_BAR 5
1314 #define OSD_MSG_PAUSE 6
1315 #define OSD_MSG_RADIO_CHANNEL 7
1316 /// Base id for messages generated from the commmand to property bridge.
1317 #define OSD_MSG_PROPERTY 0x100
1320 typedef struct mp_osd_msg mp_osd_msg_t
;
1322 /// Previous message on the stack.
1326 int id
,level
,started
;
1327 /// Display duration in ms.
1331 /// OSD message stack.
1332 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1335 * \brief Add a message on the OSD message stack
1337 * If a message with the same id is already present in the stack
1338 * it is pulled on top of the stack, otherwise a new message is created.
1342 static void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1343 mp_osd_msg_t
*msg
,*last
=NULL
;
1347 // look if the id is already in the stack
1348 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1349 last
= msg
, msg
= msg
->prev
);
1350 // not found: alloc it
1352 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1353 msg
->prev
= osd_msg_stack
;
1354 osd_msg_stack
= msg
;
1355 } else if(last
) { // found, but it's not on top of the stack
1356 last
->prev
= msg
->prev
;
1357 msg
->prev
= osd_msg_stack
;
1358 osd_msg_stack
= msg
;
1362 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1364 if(r
>= 64) msg
->msg
[63] = 0;
1373 * \brief Remove a message from the OSD stack
1375 * This function can be used to get rid of a message right away.
1379 static void rm_osd_msg(int id
) {
1380 mp_osd_msg_t
*msg
,*last
=NULL
;
1382 // Search for the msg
1383 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1384 last
= msg
, msg
= msg
->prev
);
1387 // Detach it from the stack and free it
1389 last
->prev
= msg
->prev
;
1391 osd_msg_stack
= msg
->prev
;
1396 * \brief Remove all messages from the OSD stack
1400 static void clear_osd_msgs(void) {
1401 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1407 osd_msg_stack
= NULL
;
1411 * \brief Get the current message from the OSD stack.
1413 * This function decrements the message timer and destroys the old ones.
1414 * The message that should be displayed is returned (if any).
1418 static mp_osd_msg_t
* get_osd_msg(void) {
1419 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1420 static unsigned last_update
= 0;
1421 unsigned now
= GetTimerMS();
1423 char hidden_dec_done
= 0;
1425 if(!last_update
) last_update
= now
;
1426 diff
= now
>= last_update
? now
- last_update
: 0;
1430 // Look for the first message in the stack with high enough level.
1431 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1433 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1434 // The message has a high enough level or it is the first hidden one
1435 // in both cases we decrement the timer or kill it.
1436 if(!msg
->started
|| msg
->time
> diff
) {
1437 if(msg
->started
) msg
->time
-= diff
;
1438 else msg
->started
= 1;
1440 if(msg
->level
<= osd_level
) return msg
;
1441 hidden_dec_done
= 1;
1450 osd_msg_stack
= prev
;
1459 * \brief Display the OSD bar.
1461 * Display the OSD bar or fall back on a simple message.
1465 static void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1467 if(osd_level
< 1) return;
1470 osd_visible
= (GetTimerMS() + 1000) | 1;
1471 vo_osd_progbar_type
= type
;
1472 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1473 vo_osd_changed(OSDTYPE_PROGBAR
);
1477 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1478 name
,ROUND(100*(val
-min
)/(max
-min
)));
1483 * \brief Update the OSD message line.
1485 * This function displays the current message on the vo OSD or on the term.
1486 * If the stack is empty and the OSD level is high enough the timer
1487 * is displayed (only on the vo OSD).
1491 static void update_osd_msg(void) {
1493 static char osd_text
[64] = "";
1494 static char osd_text_timer
[64];
1496 // we need some mem for vo_osd_text
1497 vo_osd_text
= (unsigned char*)osd_text
;
1499 // Look if we have a msg
1500 if((msg
= get_osd_msg())) {
1501 if(strcmp(osd_text
,msg
->msg
)) {
1502 strncpy((char*)osd_text
, msg
->msg
, 63);
1503 if(sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1504 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1510 // fallback on the timer
1512 int len
= demuxer_get_time_length(demuxer
);
1513 int percentage
= -1;
1514 char percentage_text
[10];
1515 int pts
= demuxer_get_current_time(demuxer
);
1517 if (osd_show_percentage
)
1518 percentage
= demuxer_get_percent_pos(demuxer
);
1520 if (percentage
>= 0)
1521 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1523 percentage_text
[0] = 0;
1526 snprintf(osd_text_timer
, 63,
1527 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1528 osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1529 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1531 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1532 osd_function
,pts
/3600,(pts
/60)%60,
1533 pts
%60,percentage_text
);
1535 osd_text_timer
[0]=0;
1537 // always decrement the percentage timer
1538 if(osd_show_percentage
)
1539 osd_show_percentage
--;
1541 if(strcmp(osd_text
,osd_text_timer
)) {
1542 strncpy(osd_text
, osd_text_timer
, 63);
1543 vo_osd_changed(OSDTYPE_OSD
);
1548 // Clear the term osd line
1549 if(term_osd
&& osd_text
[0]) {
1551 printf("%s\n",term_osd_esc
);
1558 /// \defgroup Properties
1561 /// \defgroup GeneralProperties General properties
1562 /// \ingroup Properties
1566 static int mp_property_osdlevel(m_option_t
* prop
,int action
,void* arg
) {
1567 return m_property_choice(prop
,action
,arg
,&osd_level
);
1570 /// Playback speed (RW)
1571 static int mp_property_playback_speed(m_option_t
* prop
,int action
,void* arg
) {
1573 case M_PROPERTY_SET
:
1574 if(!arg
) return M_PROPERTY_ERROR
;
1575 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1576 playback_speed
= *(float*)arg
;
1577 build_afilter_chain(sh_audio
, &ao_data
);
1578 return M_PROPERTY_OK
;
1579 case M_PROPERTY_STEP_UP
:
1580 case M_PROPERTY_STEP_DOWN
:
1581 playback_speed
+= (arg
? *(float*)arg
: 0.1) *
1582 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1583 M_PROPERTY_CLAMP(prop
,playback_speed
);
1584 build_afilter_chain(sh_audio
, &ao_data
);
1585 return M_PROPERTY_OK
;
1587 return m_property_float_range(prop
,action
,arg
,&playback_speed
);
1590 /// filename with path (RO)
1591 static int mp_property_path(m_option_t
* prop
,int action
,void* arg
) {
1592 return m_property_string_ro(prop
,action
,arg
,filename
);
1595 /// filename without path (RO)
1596 static int mp_property_filename(m_option_t
* prop
,int action
,void* arg
) {
1598 if(!filename
) return M_PROPERTY_UNAVAILABLE
;
1599 if(((f
= strrchr(filename
,'/')) || (f
= strrchr(filename
,'\\'))) && f
[1])
1603 return m_property_string_ro(prop
,action
,arg
,f
);
1606 /// Demuxer name (RO)
1607 static int mp_property_demuxer(m_option_t
* prop
,int action
,void* arg
) {
1608 if(!demuxer
) return M_PROPERTY_UNAVAILABLE
;
1609 return m_property_string_ro(prop
,action
,arg
,(char*)demuxer
->desc
->name
);
1612 /// Position in the stream (RW)
1613 static int mp_property_stream_pos(m_option_t
* prop
,int action
,void* arg
) {
1614 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1615 if (!arg
) return M_PROPERTY_ERROR
;
1617 case M_PROPERTY_GET
:
1618 *(off_t
*)arg
= stream_tell(demuxer
->stream
);
1619 return M_PROPERTY_OK
;
1620 case M_PROPERTY_SET
:
1621 M_PROPERTY_CLAMP(prop
,*(off_t
*)arg
);
1622 stream_seek(demuxer
->stream
, *(off_t
*)arg
);
1623 return M_PROPERTY_OK
;
1625 return M_PROPERTY_NOT_IMPLEMENTED
;
1628 /// Stream start offset (RO)
1629 static int mp_property_stream_start(m_option_t
* prop
,int action
,void* arg
) {
1630 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1632 case M_PROPERTY_GET
:
1633 *(off_t
*)arg
= demuxer
->stream
->start_pos
;
1634 return M_PROPERTY_OK
;
1636 return M_PROPERTY_NOT_IMPLEMENTED
;
1639 /// Stream end offset (RO)
1640 static int mp_property_stream_end(m_option_t
* prop
,int action
,void* arg
) {
1641 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1643 case M_PROPERTY_GET
:
1644 *(off_t
*)arg
= demuxer
->stream
->end_pos
;
1645 return M_PROPERTY_OK
;
1647 return M_PROPERTY_NOT_IMPLEMENTED
;
1650 /// Stream length (RO)
1651 static int mp_property_stream_length(m_option_t
* prop
,int action
,void* arg
) {
1652 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1654 case M_PROPERTY_GET
:
1655 *(off_t
*)arg
= demuxer
->stream
->end_pos
- demuxer
->stream
->start_pos
;
1656 return M_PROPERTY_OK
;
1658 return M_PROPERTY_NOT_IMPLEMENTED
;
1661 /// Media length in seconds (RO)
1662 static int mp_property_length(m_option_t
* prop
,int action
,void* arg
) {
1666 !(int)(len
= demuxer_get_time_length(demuxer
)))
1667 return M_PROPERTY_UNAVAILABLE
;
1670 case M_PROPERTY_PRINT
:
1671 if(!arg
) return M_PROPERTY_ERROR
;
1678 *(char**)arg
= malloc(20);
1679 if(h
> 0) sprintf(*(char**)arg
,"%d:%02d:%02d",h
,m
,s
);
1680 else if(m
> 0) sprintf(*(char**)arg
,"%d:%02d",m
,s
);
1681 else sprintf(*(char**)arg
,"%d",s
);
1682 return M_PROPERTY_OK
;
1686 return m_property_double_ro(prop
,action
,arg
,len
);
1691 /// \defgroup AudioProperties Audio properties
1692 /// \ingroup Properties
1696 static int mp_property_volume(m_option_t
* prop
,int action
,void* arg
) {
1698 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1701 case M_PROPERTY_GET
:
1702 if(!arg
) return M_PROPERTY_ERROR
;
1703 mixer_getbothvolume(&mixer
,arg
);
1704 return M_PROPERTY_OK
;
1705 case M_PROPERTY_PRINT
:{
1707 if(!arg
) return M_PROPERTY_ERROR
;
1708 mixer_getbothvolume(&mixer
,&vol
);
1709 return m_property_float_range(prop
,action
,arg
,&vol
);
1711 case M_PROPERTY_STEP_UP
:
1712 case M_PROPERTY_STEP_DOWN
:
1713 case M_PROPERTY_SET
:
1716 return M_PROPERTY_NOT_IMPLEMENTED
;
1719 if (edl_muted
) return M_PROPERTY_DISABLED
;
1723 case M_PROPERTY_SET
:
1724 if(!arg
) return M_PROPERTY_ERROR
;
1725 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1726 mixer_setvolume(&mixer
,*(float*)arg
,*(float*)arg
);
1727 return M_PROPERTY_OK
;
1728 case M_PROPERTY_STEP_UP
:
1729 if(arg
&& *(float*)arg
<= 0)
1730 mixer_decvolume(&mixer
);
1732 mixer_incvolume(&mixer
);
1733 return M_PROPERTY_OK
;
1734 case M_PROPERTY_STEP_DOWN
:
1735 if(arg
&& *(float*)arg
<= 0)
1736 mixer_incvolume(&mixer
);
1738 mixer_decvolume(&mixer
);
1739 return M_PROPERTY_OK
;
1741 return M_PROPERTY_NOT_IMPLEMENTED
;
1745 static int mp_property_mute(m_option_t
* prop
,int action
,void* arg
) {
1747 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1750 case M_PROPERTY_SET
:
1751 if(edl_muted
) return M_PROPERTY_DISABLED
;
1752 if(!arg
) return M_PROPERTY_ERROR
;
1753 if((!!*(int*)arg
) != mixer
.muted
)
1755 user_muted
= mixer
.muted
;
1756 return M_PROPERTY_OK
;
1757 case M_PROPERTY_STEP_UP
:
1758 case M_PROPERTY_STEP_DOWN
:
1759 if(edl_muted
) return M_PROPERTY_DISABLED
;
1761 user_muted
= mixer
.muted
;
1762 return M_PROPERTY_OK
;
1763 case M_PROPERTY_PRINT
:
1764 if(!arg
) return M_PROPERTY_ERROR
;
1766 *(char**)arg
= strdup(MSGTR_EnabledEdl
);
1767 return M_PROPERTY_OK
;
1770 return m_property_flag(prop
,action
,arg
,&mixer
.muted
);
1775 /// Audio delay (RW)
1776 static int mp_property_audio_delay(m_option_t
* prop
,int action
,void* arg
) {
1777 if(!(sh_audio
&& sh_video
)) return M_PROPERTY_UNAVAILABLE
;
1779 case M_PROPERTY_SET
:
1780 case M_PROPERTY_STEP_UP
:
1781 case M_PROPERTY_STEP_DOWN
:
1782 if(!arg
) return M_PROPERTY_ERROR
;
1784 float delay
= audio_delay
;
1785 m_property_delay(prop
,action
,arg
,&audio_delay
);
1786 if(sh_audio
) sh_audio
->delay
-= audio_delay
-delay
;
1788 return M_PROPERTY_OK
;
1790 return m_property_delay(prop
,action
,arg
,&audio_delay
);
1794 /// Audio codec tag (RO)
1795 static int mp_property_audio_format(m_option_t
* prop
,int action
,void* arg
) {
1796 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1797 return m_property_int_ro(prop
,action
,arg
,sh_audio
->format
);
1800 /// Audio bitrate (RO)
1801 static int mp_property_audio_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1802 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1803 return m_property_int_ro(prop
,action
,arg
,sh_audio
->i_bps
);
1807 static int mp_property_samplerate(m_option_t
* prop
,int action
,void* arg
) {
1808 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1809 return m_property_int_ro(prop
,action
,arg
,sh_audio
->samplerate
);
1812 /// Number of channels (RO)
1813 static int mp_property_channels(m_option_t
* prop
,int action
,void* arg
) {
1814 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1816 case M_PROPERTY_PRINT
:
1817 if(!arg
) return M_PROPERTY_ERROR
;
1818 switch(sh_audio
->channels
) {
1819 case 1: *(char**)arg
= strdup("mono"); break;
1820 case 2: *(char**)arg
= strdup("stereo"); break;
1822 *(char**)arg
= malloc(32);
1823 sprintf(*(char**)arg
,"%d channels",sh_audio
->channels
);
1825 return M_PROPERTY_OK
;
1827 return m_property_int_ro(prop
,action
,arg
,sh_audio
->channels
);
1830 /// Selected audio id (RW)
1831 static int mp_property_audio(m_option_t
* prop
,int action
,void* arg
) {
1832 int current_id
= -1, tmp
;
1835 case M_PROPERTY_GET
:
1836 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1837 if(!arg
) return M_PROPERTY_ERROR
;
1838 *(int*)arg
= audio_id
;
1839 return M_PROPERTY_OK
;
1840 case M_PROPERTY_PRINT
:
1841 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1842 if(!arg
) return M_PROPERTY_ERROR
;
1845 *(char**)arg
= strdup(MSGTR_Disabled
);
1847 char lang
[40] = MSGTR_Unknown
;
1848 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
)
1849 demux_mkv_get_audio_lang(demuxer
, audio_id
, lang
, 9);
1851 else if(stream
->type
== STREAMTYPE_DVD
) {
1852 int code
= dvd_lang_from_aid(stream
, audio_id
);
1854 lang
[0] = code
>> 8;
1862 else if(stream
->type
== STREAMTYPE_DVDNAV
)
1863 dvdnav_lang_from_aid(stream
, audio_id
, lang
);
1865 *(char**)arg
= malloc(64);
1866 snprintf(*(char**)arg
, 64, "(%d) %s", audio_id
, lang
);
1868 return M_PROPERTY_OK
;
1870 case M_PROPERTY_STEP_UP
:
1871 case M_PROPERTY_SET
:
1872 if(action
==M_PROPERTY_SET
&& arg
)
1876 current_id
= demuxer
->audio
->id
;
1877 audio_id
= demuxer_switch_audio(demuxer
, tmp
);
1878 if(audio_id
== -2 || (audio_id
> -1 && demuxer
->audio
->id
!= current_id
&& current_id
!= -2))
1879 uninit_player(INITED_AO
| INITED_ACODEC
);
1880 if(audio_id
> -1 && demuxer
->audio
->id
!= current_id
) {
1882 sh2
= demuxer
->a_streams
[demuxer
->audio
->id
];
1884 sh2
->ds
= demuxer
->audio
;
1886 reinit_audio_chain();
1889 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", audio_id
);
1890 return M_PROPERTY_OK
;
1892 return M_PROPERTY_NOT_IMPLEMENTED
;
1897 static int reinit_video_chain(void);
1898 /// Selected video id (RW)
1899 static int mp_property_video(m_option_t
* prop
,int action
,void* arg
) {
1900 int current_id
= -1, tmp
;
1903 case M_PROPERTY_GET
:
1904 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1905 if(!arg
) return M_PROPERTY_ERROR
;
1906 *(int*)arg
= video_id
;
1907 return M_PROPERTY_OK
;
1908 case M_PROPERTY_PRINT
:
1909 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1910 if(!arg
) return M_PROPERTY_ERROR
;
1913 *(char**)arg
= strdup(MSGTR_Disabled
);
1915 char lang
[40] = MSGTR_Unknown
;
1916 *(char**)arg
= malloc(64);
1917 snprintf(*(char**)arg
, 64, "(%d) %s", video_id
, lang
);
1919 return M_PROPERTY_OK
;
1921 case M_PROPERTY_STEP_UP
:
1922 case M_PROPERTY_SET
:
1923 current_id
= demuxer
->video
->id
;
1924 if(action
==M_PROPERTY_SET
&& arg
)
1928 video_id
= demuxer_switch_video(demuxer
, tmp
);
1929 if(video_id
== -2 || (video_id
> -1 && demuxer
->video
->id
!= current_id
&& current_id
!= -2))
1930 uninit_player(INITED_VCODEC
| (fixed_vo
&& video_id
!= -2 ? 0 : INITED_VO
));
1931 if(video_id
> -1 && demuxer
->video
->id
!= current_id
) {
1933 sh2
= demuxer
->v_streams
[demuxer
->video
->id
];
1935 sh2
->ds
= demuxer
->video
;
1937 reinit_video_chain();
1940 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_TRACK=%d\n", video_id
);
1941 return M_PROPERTY_OK
;
1944 return M_PROPERTY_NOT_IMPLEMENTED
;
1948 static int mp_property_program(m_option_t
* prop
,int action
,void* arg
) {
1949 demux_program_t prog
;
1952 case M_PROPERTY_STEP_UP
:
1953 case M_PROPERTY_SET
:
1954 if(action
==M_PROPERTY_SET
&& arg
)
1955 prog
.progid
= *((int*)arg
);
1958 if(demux_control(demuxer
, DEMUXER_CTRL_IDENTIFY_PROGRAM
, &prog
) == DEMUXER_CTRL_NOTIMPL
)
1959 return M_PROPERTY_ERROR
;
1961 mp_property_do("switch_audio", M_PROPERTY_SET
, &prog
.aid
);
1962 mp_property_do("switch_video", M_PROPERTY_SET
, &prog
.vid
);
1963 return M_PROPERTY_OK
;
1966 return M_PROPERTY_NOT_IMPLEMENTED
;
1972 /// \defgroup VideoProperties Video properties
1973 /// \ingroup Properties
1976 /// Fullscreen state (RW)
1977 static int mp_property_fullscreen(m_option_t
* prop
,int action
,void* arg
) {
1979 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1982 case M_PROPERTY_SET
:
1983 if(!arg
) return M_PROPERTY_ERROR
;
1984 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1985 if(vo_fs
== !!*(int*)arg
) return M_PROPERTY_OK
;
1986 case M_PROPERTY_STEP_UP
:
1987 case M_PROPERTY_STEP_DOWN
:
1989 if(use_gui
) guiGetEvent(guiIEvent
,(char*)MP_CMD_GUI_FULLSCREEN
);
1992 if(vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
1993 return M_PROPERTY_OK
;
1995 return m_property_flag(prop
,action
,arg
,&vo_fs
);
1999 static int mp_property_deinterlace(m_option_t
* prop
,int action
,void* arg
) {
2002 if (!sh_video
|| !sh_video
->vfilter
) return M_PROPERTY_UNAVAILABLE
;
2003 vf
= sh_video
->vfilter
;
2005 case M_PROPERTY_GET
:
2006 if(!arg
) return M_PROPERTY_ERROR
;
2007 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, arg
);
2008 return M_PROPERTY_OK
;
2009 case M_PROPERTY_SET
:
2010 if(!arg
) return M_PROPERTY_ERROR
;
2011 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2012 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, arg
);
2013 return M_PROPERTY_OK
;
2014 case M_PROPERTY_STEP_UP
:
2015 case M_PROPERTY_STEP_DOWN
:
2016 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, &deinterlace
);
2017 deinterlace
= !deinterlace
;
2018 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, &deinterlace
);
2019 return M_PROPERTY_OK
;
2021 return M_PROPERTY_NOT_IMPLEMENTED
;
2025 static int mp_property_panscan(m_option_t
* prop
,int action
,void* arg
) {
2027 if(!video_out
|| video_out
->control(VOCTRL_GET_PANSCAN
,NULL
) != VO_TRUE
)
2028 return M_PROPERTY_UNAVAILABLE
;
2031 case M_PROPERTY_SET
:
2032 if(!arg
) return M_PROPERTY_ERROR
;
2033 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
2034 vo_panscan
= *(float*)arg
;
2035 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
2036 return M_PROPERTY_OK
;
2037 case M_PROPERTY_STEP_UP
:
2038 case M_PROPERTY_STEP_DOWN
:
2039 vo_panscan
+= (arg
? *(float*)arg
: 0.1) *
2040 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2041 if(vo_panscan
> 1) vo_panscan
= 1;
2042 else if(vo_panscan
< 0) vo_panscan
= 0;
2043 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
2044 return M_PROPERTY_OK
;
2046 return m_property_float_range(prop
,action
,arg
,&vo_panscan
);
2050 /// Helper to set vo flags.
2051 /** \ingroup PropertyImplHelper
2053 static int mp_property_vo_flag(m_option_t
* prop
,int action
,void* arg
,
2054 int vo_ctrl
,int* vo_var
) {
2056 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
2059 case M_PROPERTY_SET
:
2060 if(!arg
) return M_PROPERTY_ERROR
;
2061 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2062 if(*vo_var
== !!*(int*)arg
) return M_PROPERTY_OK
;
2063 case M_PROPERTY_STEP_UP
:
2064 case M_PROPERTY_STEP_DOWN
:
2065 if(vo_config_count
) video_out
->control(vo_ctrl
, 0);
2066 return M_PROPERTY_OK
;
2068 return m_property_flag(prop
,action
,arg
,vo_var
);
2072 /// Window always on top (RW)
2073 static int mp_property_ontop(m_option_t
* prop
,int action
,void* arg
) {
2074 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ONTOP
,&vo_ontop
);
2077 /// Display in the root window (RW)
2078 static int mp_property_rootwin(m_option_t
* prop
,int action
,void* arg
) {
2079 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ROOTWIN
,&vo_rootwin
);
2082 /// Show window borders (RW)
2083 static int mp_property_border(m_option_t
* prop
,int action
,void* arg
) {
2084 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_BORDER
,&vo_border
);
2087 /// Framedropping state (RW)
2088 static int mp_property_framedropping(m_option_t
* prop
,int action
,void* arg
) {
2090 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2093 case M_PROPERTY_PRINT
:
2094 if(!arg
) return M_PROPERTY_ERROR
;
2095 *(char**)arg
= strdup(frame_dropping
== 1 ? MSGTR_Enabled
:
2096 (frame_dropping
== 2 ? MSGTR_HardFrameDrop
: MSGTR_Disabled
));
2097 return M_PROPERTY_OK
;
2099 return m_property_choice(prop
,action
,arg
,&frame_dropping
);
2103 /// Color settings, try to use vf/vo then fall back on TV. (RW)
2104 static int mp_property_gamma(m_option_t
* prop
,int action
,void* arg
) {
2105 int* gamma
= prop
->priv
, r
;
2107 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2109 if(gamma
[0] == 1000) {
2111 get_video_colors (sh_video
, prop
->name
, gamma
);
2115 case M_PROPERTY_SET
:
2116 if(!arg
) return M_PROPERTY_ERROR
;
2117 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2118 *gamma
= *(int*)arg
;
2119 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
2122 case M_PROPERTY_GET
:
2123 if(!arg
) return M_PROPERTY_ERROR
;
2124 r
= get_video_colors (sh_video
, prop
->name
, arg
);
2127 case M_PROPERTY_STEP_UP
:
2128 case M_PROPERTY_STEP_DOWN
:
2129 *gamma
+= (arg
? *(int*)arg
: 1) *
2130 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2131 M_PROPERTY_CLAMP(prop
,*gamma
);
2132 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
2136 return M_PROPERTY_NOT_IMPLEMENTED
;
2140 if(demuxer
->type
== DEMUXER_TYPE_TV
) {
2141 int l
= strlen(prop
->name
);
2142 char tv_prop
[3+l
+1];
2143 sprintf(tv_prop
,"tv_%s",prop
->name
);
2144 return mp_property_do(tv_prop
,action
,arg
);
2148 return M_PROPERTY_UNAVAILABLE
;
2152 static int mp_property_vsync(m_option_t
* prop
,int action
,void* arg
) {
2153 return m_property_flag(prop
,action
,arg
,&vo_vsync
);
2156 /// Video codec tag (RO)
2157 static int mp_property_video_format(m_option_t
* prop
,int action
,void* arg
) {
2158 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2159 return m_property_int_ro(prop
,action
,arg
,sh_video
->format
);
2162 /// Video bitrate (RO)
2163 static int mp_property_video_bitrate(m_option_t
* prop
,int action
,void* arg
) {
2164 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2165 return m_property_int_ro(prop
,action
,arg
,sh_video
->i_bps
);
2168 /// Video display width (RO)
2169 static int mp_property_width(m_option_t
* prop
,int action
,void* arg
) {
2170 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2171 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_w
);
2174 /// Video display height (RO)
2175 static int mp_property_height(m_option_t
* prop
,int action
,void* arg
) {
2176 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2177 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_h
);
2181 static int mp_property_fps(m_option_t
* prop
,int action
,void* arg
) {
2182 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2183 return m_property_float_ro(prop
,action
,arg
,sh_video
->fps
);
2186 /// Video aspect (RO)
2187 static int mp_property_aspect(m_option_t
* prop
,int action
,void* arg
) {
2188 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2189 return m_property_float_ro(prop
,action
,arg
,sh_video
->aspect
);
2194 /// \defgroup SubProprties Subtitles properties
2195 /// \ingroup Properties
2198 /// Text subtitle position (RW)
2199 static int mp_property_sub_pos(m_option_t
* prop
,int action
,void* arg
) {
2200 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2203 case M_PROPERTY_SET
:
2204 if(!arg
) return M_PROPERTY_ERROR
;
2205 case M_PROPERTY_STEP_UP
:
2206 case M_PROPERTY_STEP_DOWN
:
2207 vo_osd_changed(OSDTYPE_SUBTITLE
);
2209 return m_property_int_range(prop
,action
,arg
,&sub_pos
);
2213 /// Selected subtitles (RW)
2214 static int mp_property_sub(m_option_t
* prop
,int action
,void* arg
) {
2215 int source
= -1, reset_spu
= 0;
2218 if(global_sub_size
<= 0) return M_PROPERTY_UNAVAILABLE
;
2221 case M_PROPERTY_GET
:
2222 if(!arg
) return M_PROPERTY_ERROR
;
2223 *(int*)arg
= global_sub_pos
;
2224 return M_PROPERTY_OK
;
2225 case M_PROPERTY_PRINT
:
2226 if(!arg
) return M_PROPERTY_ERROR
;
2227 *(char**)arg
= malloc(64);
2228 (*(char**)arg
)[63] = 0;
2231 sub_name
= subdata
->filename
;
2233 if (ass_track
&& ass_track
->name
)
2234 sub_name
= ass_track
->name
;
2239 if ((tmp2
= strrchr(tmp
, '/')))
2242 snprintf(*(char**)arg
, 63, "(%d) %s%s",
2244 strlen(tmp
) < 20 ? "" : "...",
2245 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
2246 return M_PROPERTY_OK
;
2250 if(stream
->type
==STREAMTYPE_DVDNAV
) {
2251 if(vo_spudec
&& dvdsub_id
>= 0) {
2252 unsigned char lang
[3];
2253 if(dvdnav_lang_from_sid(stream
, dvdsub_id
, lang
)) {
2254 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
2255 return M_PROPERTY_OK
;
2261 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
&& dvdsub_id
>= 0) {
2262 char lang
[40] = MSGTR_Unknown
;
2263 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
2264 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
2265 return M_PROPERTY_OK
;
2267 #ifdef HAVE_OGGVORBIS
2268 if (demuxer
->type
== DEMUXER_TYPE_OGG
&& d_dvdsub
&& dvdsub_id
>= 0) {
2269 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
2270 if (!lang
) lang
= MSGTR_Unknown
;
2271 snprintf(*(char**)arg
, 63, "(%d) %s",
2273 return M_PROPERTY_OK
;
2276 if (vo_vobsub
&& vobsub_id
>= 0) {
2277 const char *language
= MSGTR_Unknown
;
2278 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
2279 snprintf(*(char**)arg
, 63, "(%d) %s",
2280 vobsub_id
, language
? language
: MSGTR_Unknown
);
2281 return M_PROPERTY_OK
;
2284 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
&& dvdsub_id
>= 0) {
2286 int code
= dvd_lang_from_sid(stream
, dvdsub_id
);
2287 lang
[0] = code
>> 8;
2290 snprintf(*(char**)arg
, 63, "(%d) %s",
2292 return M_PROPERTY_OK
;
2295 if (dvdsub_id
>= 0) {
2296 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, MSGTR_Unknown
);
2297 return M_PROPERTY_OK
;
2299 snprintf(*(char**)arg
, 63, MSGTR_Disabled
);
2300 return M_PROPERTY_OK
;
2302 case M_PROPERTY_SET
:
2303 if(!arg
) return M_PROPERTY_ERROR
;
2304 if(*(int*)arg
< -1) *(int*)arg
= -1;
2305 else if(*(int*)arg
>= global_sub_size
) *(int*)arg
= global_sub_size
-1;
2306 global_sub_pos
= *(int*)arg
;
2308 case M_PROPERTY_STEP_UP
:
2309 global_sub_pos
+= 2;
2310 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2312 case M_PROPERTY_STEP_DOWN
:
2313 global_sub_pos
+= global_sub_size
+1;
2314 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2317 return M_PROPERTY_NOT_IMPLEMENTED
;
2320 if (global_sub_pos
>= 0)
2321 source
= sub_source();
2323 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
,
2324 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
2325 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
2326 global_sub_indices
[SUB_SOURCE_SUBS
],
2327 global_sub_indices
[SUB_SOURCE_DEMUX
],
2328 global_sub_pos
, source
);
2330 set_of_sub_pos
= -1;
2332 vo_sub_last
= vo_sub
= NULL
;
2337 if(d_dvdsub
->id
> -2) reset_spu
= 1;
2344 if (source
== SUB_SOURCE_VOBSUB
) {
2345 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
2346 } else if (source
== SUB_SOURCE_SUBS
) {
2347 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
2349 if (ass_enabled
&& set_of_ass_tracks
[set_of_sub_pos
])
2350 ass_track
= set_of_ass_tracks
[set_of_sub_pos
];
2354 subdata
= set_of_subtitles
[set_of_sub_pos
];
2355 vo_osd_changed(OSDTYPE_SUBTITLE
);
2357 } else if (source
== SUB_SOURCE_DEMUX
) {
2358 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
2361 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
2362 d_dvdsub
->id
= dvdsub_id
;
2363 spudec_reset(vo_spudec
);
2368 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVDNAV
) {
2369 d_dvdsub
->id
= dvdsub_id
;
2370 spudec_reset(vo_spudec
);
2373 if (stream
->type
!= STREAMTYPE_DVD
&& stream
->type
!= STREAMTYPE_DVDNAV
) {
2375 for (d_dvdsub
->id
= 0; d_dvdsub
->id
< MAX_S_STREAMS
; d_dvdsub
->id
++) {
2376 if (demuxer
->s_streams
[d_dvdsub
->id
]) {
2377 if (i
== dvdsub_id
) break;
2381 d_dvdsub
->sh
= demuxer
->s_streams
[d_dvdsub
->id
];
2383 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
2384 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
2386 if (d_dvdsub
->sh
&& d_dvdsub
->id
>= 0) {
2387 sh_sub_t
*sh
= d_dvdsub
->sh
;
2388 if (sh
->type
== 'v')
2391 else if (ass_enabled
&& sh
->type
== 'a')
2392 ass_track
= sh
->ass_track
;
2397 vo_osd_changed(OSDTYPE_SUBTITLE
);
2398 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2401 if (vo_spudec
&& (stream
->type
== STREAMTYPE_DVD
|| stream
->type
== STREAMTYPE_DVDNAV
) && dvdsub_id
< 0 && reset_spu
) {
2403 d_dvdsub
->id
= dvdsub_id
;
2404 spudec_reset(vo_spudec
);
2408 return M_PROPERTY_OK
;
2411 /// Subtitle delay (RW)
2412 static int mp_property_sub_delay(m_option_t
* prop
,int action
,void* arg
) {
2413 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2414 return m_property_delay(prop
,action
,arg
,&sub_delay
);
2417 /// Alignment of text subtitles (RW)
2418 static int mp_property_sub_alignment(m_option_t
* prop
,int action
,void* arg
) {
2419 char* name
[] = { MSGTR_Top
, MSGTR_Center
, MSGTR_Bottom
};
2421 if(!sh_video
|| global_sub_pos
< 0 || sub_source() != SUB_SOURCE_SUBS
)
2422 return M_PROPERTY_UNAVAILABLE
;
2425 case M_PROPERTY_PRINT
:
2426 if(!arg
) return M_PROPERTY_ERROR
;
2427 M_PROPERTY_CLAMP(prop
,sub_alignment
);
2428 *(char**)arg
= strdup(name
[sub_alignment
]);
2429 return M_PROPERTY_OK
;
2430 case M_PROPERTY_SET
:
2431 if(!arg
) return M_PROPERTY_ERROR
;
2432 case M_PROPERTY_STEP_UP
:
2433 case M_PROPERTY_STEP_DOWN
:
2434 vo_osd_changed(OSDTYPE_SUBTITLE
);
2436 return m_property_choice(prop
,action
,arg
,&sub_alignment
);
2440 /// Subtitle visibility (RW)
2441 static int mp_property_sub_visibility(m_option_t
* prop
,int action
,void* arg
) {
2442 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2445 case M_PROPERTY_SET
:
2446 if(!arg
) return M_PROPERTY_ERROR
;
2447 case M_PROPERTY_STEP_UP
:
2448 case M_PROPERTY_STEP_DOWN
:
2449 vo_osd_changed(OSDTYPE_SUBTITLE
);
2450 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2452 return m_property_flag(prop
,action
,arg
,&sub_visibility
);
2456 /// Show only forced subtitles (RW)
2457 static int mp_property_sub_forced_only(m_option_t
* prop
,int action
,void* arg
) {
2458 if(!vo_spudec
) return M_PROPERTY_UNAVAILABLE
;
2461 case M_PROPERTY_SET
:
2462 if(!arg
) return M_PROPERTY_ERROR
;
2463 case M_PROPERTY_STEP_UP
:
2464 case M_PROPERTY_STEP_DOWN
:
2465 m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2466 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
2467 return M_PROPERTY_OK
;
2469 return m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2476 /// \defgroup TVProperties TV properties
2477 /// \ingroup Properties
2482 /// TV color settings (RW)
2483 static int mp_property_tv_color(m_option_t
* prop
,int action
,void* arg
) {
2485 tvi_handle_t
* tvh
= demuxer
->priv
;
2486 if(demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
) return M_PROPERTY_UNAVAILABLE
;
2489 case M_PROPERTY_SET
:
2490 if(!arg
) return M_PROPERTY_ERROR
;
2491 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2492 return tv_set_color_options(tvh
,(int)prop
->priv
,*(int*)arg
);
2493 case M_PROPERTY_GET
:
2494 return tv_get_color_options(tvh
,(int)prop
->priv
,arg
);
2495 case M_PROPERTY_STEP_UP
:
2496 case M_PROPERTY_STEP_DOWN
:
2497 if((r
= tv_get_color_options(tvh
,(int)prop
->priv
,&val
)) >= 0) {
2498 if(!r
) return M_PROPERTY_ERROR
;
2499 val
+= (arg
? *(int*)arg
: 1) *
2500 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2501 M_PROPERTY_CLAMP(prop
,val
);
2502 return tv_set_color_options(tvh
,(int)prop
->priv
,val
);
2504 return M_PROPERTY_ERROR
;
2506 return M_PROPERTY_NOT_IMPLEMENTED
;
2513 /// All properties available in MPlayer.
2514 /** \ingroup Properties
2516 static m_option_t mp_properties
[] = {
2518 { "osdlevel", mp_property_osdlevel
, CONF_TYPE_INT
,
2519 M_OPT_RANGE
, 0, 3, NULL
},
2520 { "speed", mp_property_playback_speed
, CONF_TYPE_FLOAT
,
2521 M_OPT_RANGE
, 0.01, 100.0, NULL
},
2522 { "filename", mp_property_filename
, CONF_TYPE_STRING
,
2524 { "path", mp_property_path
, CONF_TYPE_STRING
,
2526 { "demuxer", mp_property_demuxer
, CONF_TYPE_STRING
,
2528 { "stream_pos", mp_property_stream_pos
, CONF_TYPE_POSITION
,
2529 M_OPT_MIN
, 0, 0, NULL
},
2530 { "stream_start", mp_property_stream_start
, CONF_TYPE_POSITION
,
2531 M_OPT_MIN
, 0, 0, NULL
},
2532 { "stream_end", mp_property_stream_end
, CONF_TYPE_POSITION
,
2533 M_OPT_MIN
, 0, 0, NULL
},
2534 { "stream_length", mp_property_stream_length
, CONF_TYPE_POSITION
,
2535 M_OPT_MIN
, 0, 0, NULL
},
2536 { "length", mp_property_length
, CONF_TYPE_DOUBLE
,
2540 { "volume", mp_property_volume
, CONF_TYPE_FLOAT
,
2541 M_OPT_RANGE
, 0, 100, NULL
},
2542 { "mute", mp_property_mute
, CONF_TYPE_FLAG
,
2543 M_OPT_RANGE
, 0, 1, NULL
},
2544 { "audio_delay", mp_property_audio_delay
, CONF_TYPE_FLOAT
,
2545 M_OPT_RANGE
, -100, 100, NULL
},
2546 { "audio_format", mp_property_audio_format
, CONF_TYPE_INT
,
2548 { "audio_bitrate", mp_property_audio_bitrate
, CONF_TYPE_INT
,
2550 { "samplerate", mp_property_samplerate
, CONF_TYPE_INT
,
2552 { "channels", mp_property_channels
, CONF_TYPE_INT
,
2554 { "switch_audio", mp_property_audio
, CONF_TYPE_INT
,
2555 CONF_RANGE
, -2, MAX_A_STREAMS
-1, NULL
},
2558 { "fullscreen", mp_property_fullscreen
, CONF_TYPE_FLAG
,
2559 M_OPT_RANGE
, 0, 1, NULL
},
2560 { "deinterlace", mp_property_deinterlace
, CONF_TYPE_FLAG
,
2561 M_OPT_RANGE
, 0, 1, NULL
},
2562 { "ontop", mp_property_ontop
, CONF_TYPE_FLAG
,
2563 M_OPT_RANGE
, 0, 1, NULL
},
2564 { "rootwin", mp_property_rootwin
, CONF_TYPE_FLAG
,
2565 M_OPT_RANGE
, 0, 1, NULL
},
2566 { "border", mp_property_border
, CONF_TYPE_FLAG
,
2567 M_OPT_RANGE
, 0, 1, NULL
},
2568 { "framedropping", mp_property_framedropping
, CONF_TYPE_INT
,
2569 M_OPT_RANGE
, 0, 2, NULL
},
2570 { "gamma", mp_property_gamma
, CONF_TYPE_INT
,
2571 M_OPT_RANGE
, -100, 100, &vo_gamma_gamma
},
2572 { "brightness", mp_property_gamma
, CONF_TYPE_INT
,
2573 M_OPT_RANGE
, -100, 100, &vo_gamma_brightness
},
2574 { "contrast", mp_property_gamma
, CONF_TYPE_INT
,
2575 M_OPT_RANGE
, -100, 100, &vo_gamma_contrast
},
2576 { "saturation", mp_property_gamma
, CONF_TYPE_INT
,
2577 M_OPT_RANGE
, -100, 100, &vo_gamma_saturation
},
2578 { "hue", mp_property_gamma
, CONF_TYPE_INT
,
2579 M_OPT_RANGE
, -100, 100, &vo_gamma_hue
},
2580 { "panscan", mp_property_panscan
, CONF_TYPE_FLOAT
,
2581 M_OPT_RANGE
, 0, 1, NULL
},
2582 { "vsync", mp_property_vsync
, CONF_TYPE_FLAG
,
2583 M_OPT_RANGE
, 0, 1, NULL
},
2584 { "video_format", mp_property_video_format
, CONF_TYPE_INT
,
2586 { "video_bitrate", mp_property_video_bitrate
, CONF_TYPE_INT
,
2588 { "width", mp_property_width
, CONF_TYPE_INT
,
2590 { "height", mp_property_height
, CONF_TYPE_INT
,
2592 { "fps", mp_property_fps
, CONF_TYPE_FLOAT
,
2594 { "aspect", mp_property_aspect
, CONF_TYPE_FLOAT
,
2596 { "switch_video", mp_property_video
, CONF_TYPE_INT
,
2597 CONF_RANGE
, -2, MAX_V_STREAMS
-1, NULL
},
2598 { "switch_program", mp_property_program
, CONF_TYPE_INT
,
2599 CONF_RANGE
, -1, 65535, NULL
},
2602 { "sub", mp_property_sub
, CONF_TYPE_INT
,
2603 M_OPT_MIN
, -1, 0, NULL
},
2604 { "sub_delay", mp_property_sub_delay
, CONF_TYPE_FLOAT
,
2606 { "sub_pos", mp_property_sub_pos
, CONF_TYPE_INT
,
2607 M_OPT_RANGE
, 0, 100, NULL
},
2608 { "sub_alignment", mp_property_sub_alignment
, CONF_TYPE_INT
,
2609 M_OPT_RANGE
, 0, 2, NULL
},
2610 { "sub_visibility", mp_property_sub_visibility
, CONF_TYPE_FLAG
,
2611 M_OPT_RANGE
, 0, 1, NULL
},
2612 { "sub_forced_only", mp_property_sub_forced_only
, CONF_TYPE_FLAG
,
2613 M_OPT_RANGE
, 0, 1, NULL
},
2616 { "tv_brightness", mp_property_tv_color
, CONF_TYPE_INT
,
2617 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_BRIGHTNESS
},
2618 { "tv_contrast", mp_property_tv_color
, CONF_TYPE_INT
,
2619 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_CONTRAST
},
2620 { "tv_saturation", mp_property_tv_color
, CONF_TYPE_INT
,
2621 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_SATURATION
},
2622 { "tv_hue", mp_property_tv_color
, CONF_TYPE_INT
,
2623 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_HUE
},
2626 { NULL
, NULL
, NULL
, 0, 0, 0, NULL
}
2629 m_option_t
* mp_property_find(const char* name
) {
2630 return m_option_list_find(mp_properties
,name
);
2633 int mp_property_do(const char* name
,int action
, void* val
) {
2634 m_option_t
* p
= mp_property_find(name
);
2635 if(!p
) return M_PROPERTY_UNAVAILABLE
;
2636 return m_property_do(p
,action
,val
);
2644 * \defgroup Command2Property Command to property bridge
2646 * It is used to handle most commands that just set a property
2647 * and optionally display something on the OSD.
2648 * Two kinds of commands are handled: adjust or toggle.
2650 * Adjust commands take 1 or 2 parameters: <value> <abs>
2651 * If <abs> is non-zero the property is set to the given value
2652 * otherwise it is adjusted.
2654 * Toggle commands take 0 or 1 parameters. With no parameter
2655 * or a value less than the property minimum it just steps the
2656 * property to its next value. Otherwise it sets it to the given
2662 /// List of the commands that can be handled by setting a property.
2668 /// set/adjust or toggle command
2670 /// progressbar type
2672 /// osd msg id if it must be shared
2674 /// osd msg template
2675 const char* osd_msg
;
2676 } set_prop_cmd
[] = {
2678 { "volume", MP_CMD_VOLUME
, 0, OSD_VOLUME
, -1, MSGTR_Volume
},
2679 { "mute", MP_CMD_MUTE
, 1, 0, -1, MSGTR_MuteStatus
},
2680 { "audio_delay", MP_CMD_AUDIO_DELAY
, 0, 0, -1, MSGTR_AVDelayStatus
},
2681 { "switch_audio", MP_CMD_SWITCH_AUDIO
, 1, 0, -1, MSGTR_OSDAudio
},
2683 { "fullscreen", MP_CMD_VO_FULLSCREEN
, 1, 0, -1, NULL
},
2684 { "panscan", MP_CMD_PANSCAN
, 0, OSD_PANSCAN
, -1, MSGTR_Panscan
},
2685 { "ontop", MP_CMD_VO_ONTOP
, 1, 0, -1, MSGTR_OnTopStatus
},
2686 { "rootwin", MP_CMD_VO_ROOTWIN
, 1, 0, -1, MSGTR_RootwinStatus
},
2687 { "border", MP_CMD_VO_BORDER
, 1, 0, -1, MSGTR_BorderStatus
},
2688 { "framedropping", MP_CMD_FRAMEDROPPING
, 1, 0, -1, MSGTR_FramedroppingStatus
},
2689 { "gamma", MP_CMD_GAMMA
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Gamma
},
2690 { "brightness", MP_CMD_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2691 { "contrast", MP_CMD_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2692 { "saturation", MP_CMD_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2693 { "hue", MP_CMD_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2694 { "vsync", MP_CMD_SWITCH_VSYNC
, 1, 0, -1, MSGTR_VSyncStatus
},
2696 { "sub", MP_CMD_SUB_SELECT
, 1, 0, -1, MSGTR_SubSelectStatus
},
2697 { "sub_pos", MP_CMD_SUB_POS
, 0, 0, -1, MSGTR_SubPosStatus
},
2698 { "sub_alignment", MP_CMD_SUB_ALIGNMENT
, 1, 0, -1, MSGTR_SubAlignStatus
},
2699 { "sub_delay", MP_CMD_SUB_DELAY
, 0, 0, OSD_MSG_SUB_DELAY
, MSGTR_SubDelayStatus
},
2700 { "sub_visibility", MP_CMD_SUB_VISIBILITY
, 1, 0, -1, MSGTR_SubVisibleStatus
},
2701 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY
, 1, 0, -1, MSGTR_SubForcedOnlyStatus
},
2703 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2704 { "tv_hue", MP_CMD_TV_SET_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2705 { "tv_saturation", MP_CMD_TV_SET_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2706 { "tv_contrast", MP_CMD_TV_SET_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2708 { NULL
, 0, 0, 0, -1, NULL
}
2711 /// Handle commands that set a property.
2712 static int set_property_command(mp_cmd_t
* cmd
) {
2716 // look for the command
2717 for(i
= 0 ; set_prop_cmd
[i
].name
; i
++)
2718 if(set_prop_cmd
[i
].cmd
== cmd
->id
) break;
2719 if(!set_prop_cmd
[i
].name
) return 0;
2722 prop
= mp_property_find(set_prop_cmd
[i
].name
);
2726 if(set_prop_cmd
[i
].toggle
) {
2728 if(cmd
->nargs
> 0 && cmd
->args
[0].v
.i
>= prop
->min
)
2729 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
.i
);
2731 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,NULL
);
2732 } else if(cmd
->args
[1].v
.i
) //set
2733 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
);
2735 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,&cmd
->args
[0].v
);
2737 if(r
<= 0) return 1;
2739 if(set_prop_cmd
[i
].osd_progbar
) {
2740 if(prop
->type
== CONF_TYPE_INT
) {
2741 if(m_property_do(prop
,M_PROPERTY_GET
,&r
) > 0)
2742 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2743 set_prop_cmd
[i
].osd_msg
,
2744 prop
->min
,prop
->max
,r
);
2745 } else if(prop
->type
== CONF_TYPE_FLOAT
) {
2747 if(m_property_do(prop
,M_PROPERTY_GET
,&f
) > 0)
2748 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,set_prop_cmd
[i
].osd_msg
,
2749 prop
->min
,prop
->max
,f
);
2751 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "Property use an unsupported type.\n");
2755 if(set_prop_cmd
[i
].osd_msg
) {
2756 char* val
= m_property_print(prop
);
2758 set_osd_msg(set_prop_cmd
[i
].osd_id
>= 0 ? set_prop_cmd
[i
].osd_id
:
2759 OSD_MSG_PROPERTY
+i
,1,osd_duration
,
2760 set_prop_cmd
[i
].osd_msg
,val
);
2767 static void reinit_audio_chain(void) {
2769 current_module
="init_audio_codec";
2770 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2771 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
2772 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
2776 inited_flags
|=INITED_ACODEC
;
2777 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2780 //const ao_info_t *info=audio_out->info;
2781 current_module
="af_preinit";
2782 ao_data
.samplerate
=force_srate
;
2784 ao_data
.format
=audio_output_format
;
2786 // first init to detect best values
2787 if(!preinit_audio_filters(sh_audio
,
2789 (int)(sh_audio
->samplerate
*playback_speed
),
2790 sh_audio
->channels
, sh_audio
->sample_format
,
2792 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
2793 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
2794 exit_player(MSGTR_Exit_error
);
2797 current_module
="ao2_init";
2798 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
2802 ao_data
.format
,0))){
2804 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
2805 uninit_player(INITED_ACODEC
); // close codec
2806 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
2811 inited_flags
|=INITED_AO
;
2812 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2813 audio_out
->info
->short_name
,
2814 ao_data
.samplerate
, ao_data
.channels
,
2815 af_fmt2str_short(ao_data
.format
),
2816 af_fmt2bits(ao_data
.format
)/8 );
2817 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
2818 audio_out
->info
->name
, audio_out
->info
->author
);
2819 if(strlen(audio_out
->info
->comment
) > 0)
2820 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
2821 // init audio filters:
2823 current_module
="af_init";
2824 if(!build_afilter_chain(sh_audio
, &ao_data
)) {
2825 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
2826 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2827 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2828 // sh_audio=d_audio->sh=NULL; // -> nosound
2832 mixer
.audio_out
= audio_out
;
2833 mixer
.volstep
= volstep
;
2842 // Return pts value corresponding to the end point of audio written to the
2844 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
2846 // first calculate the end pts of audio that has been output by decoder
2847 double a_pts
= sh_audio
->pts
;
2848 if (a_pts
!= MP_NOPTS_VALUE
)
2849 // Good, decoder supports new way of calculating audio pts.
2850 // sh_audio->pts is the timestamp of the latest input packet with
2851 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2852 // the amount of bytes the decoder has written after that timestamp.
2853 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
2855 // Decoder doesn't support new way of calculating pts (or we're
2856 // being called before it has decoded anything with known timestamp).
2857 // Use the old method of audio pts calculation: take the timestamp
2858 // of last packet with known pts the decoder has read data from,
2859 // and add amount of bytes read after the beginning of that packet
2860 // divided by input bps. This will be inaccurate if the input/output
2861 // ratio is not constant for every audio packet or if it is constant
2862 // but not accurately known in sh_audio->i_bps.
2864 a_pts
= d_audio
->pts
;
2865 // ds_tell_pts returns bytes read after last timestamp from
2866 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2867 // it has read but not decoded
2868 if (sh_audio
->i_bps
)
2869 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
2870 (double)sh_audio
->i_bps
;
2872 // Now a_pts hopefully holds the pts for end of audio from decoder.
2873 // Substract data in buffers between decoder and audio out.
2875 // Decoded but not filtered
2876 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
2878 // Data that was ready for ao but was buffered because ao didn't fully
2879 // accept everything to internal buffers yet
2880 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
2885 // Return pts value corresponding to currently playing audio.
2886 static double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
2887 ao_functions_t
*audio_out
)
2889 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
2890 audio_out
->get_delay();
2893 static void update_subtitles(void)
2897 double pts
= sh_video
->pts
;
2898 if (sub_fps
==0) sub_fps
= sh_video
->fps
;
2899 current_module
= "find_sub";
2900 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0) {
2901 find_sub(subdata
, (pts
+sub_delay
) *
2902 (subdata
->sub_uses_time
? 100. : sub_fps
));
2903 if (vo_sub
) vo_sub_last
= vo_sub
;
2904 // FIXME! frame counter...
2910 if (vo_config_count
&& vo_spudec
) {
2911 unsigned char* packet
=NULL
;
2913 current_module
= "spudec";
2914 spudec_heartbeat(vo_spudec
, 90000*sh_video
->timer
);
2915 /* Get a sub packet from the DVD or a vobsub and make a timestamp
2916 * relative to sh_video->timer */
2921 if (sh_video
->pts
+sub_delay
>= 0) {
2922 len
= vobsub_get_packet(vo_vobsub
, sh_video
->pts
+sub_delay
,
2923 (void**)&packet
, ×tamp
);
2925 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
2926 mp_dbg(MSGT_CPLAYER
,MSGL_V
,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len
,sh_video
->pts
,sh_video
->timer
,timestamp
/ 90000.0,timestamp
);
2931 len
= ds_get_packet_sub(d_dvdsub
, (unsigned char**)&packet
);
2933 // XXX This is wrong, sh_video->pts can be arbitrarily
2934 // much behind demuxing position. Unfortunately using
2935 // d_video->pts which would have been the simplest
2936 // improvement doesn't work because mpeg specific hacks
2937 // in video.c set d_video->pts to 0.
2938 float x
= d_dvdsub
->pts
- sh_video
->pts
;
2939 if (x
> -20 && x
< 20) // prevent missing subs on pts reset
2940 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
2941 + sub_delay
- sh_video
->pts
);
2942 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
2943 mp_dbg(MSGT_CPLAYER
, MSGL_V
, "\rDVD sub: len=%d "
2944 "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len
,
2945 sh_video
->pts
, d_dvdsub
->pts
, timestamp
);
2948 if (len
<=0 || !packet
) break;
2950 spudec_assemble(vo_spudec
, packet
, len
, timestamp
);
2953 if (spudec_changed(vo_spudec
))
2954 vo_osd_changed(OSDTYPE_SPU
);
2956 current_module
=NULL
;
2959 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
2961 unsigned char *start
;
2967 void *decoded_frame
;
2968 current_module
= "decode video";
2969 // XXX Time used in this call is not counted in any performance
2970 // timer now, OSD is not updated correctly for filter-added frames
2971 if (vf_output_queued_frame(sh_video
->vfilter
))
2973 current_module
= "video_read_frame";
2974 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
2976 // try to extract last frames in case of decoder lag
2981 if (in_size
> max_framesize
)
2982 max_framesize
= in_size
;
2983 if (pts
== MP_NOPTS_VALUE
)
2984 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts value from demuxer MISSING\n");
2985 current_module
= "decode video";
2986 decoded_frame
= decode_video(sh_video
, start
, in_size
, 0, pts
);
2987 if (decoded_frame
) {
2990 current_module
= "filter video";
2991 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
3000 static void rescale_input_coordinates(int ix
, int iy
, double *dx
, double *dy
) {
3001 //remove the borders, if any, and rescale to the range [0,1],[0,1]
3002 if(vo_fs
) { //we are in full-screen mode
3003 if(vo_screenwidth
> vo_dwidth
) //there are borders along the x axis
3004 ix
-= (vo_screenwidth
- vo_dwidth
) / 2;
3005 if(vo_screenheight
> vo_dheight
) //there are borders along the y axis (usual way)
3006 iy
-= (vo_screenheight
- vo_dheight
) / 2;
3008 if(ix
< 0 || ix
> vo_dwidth
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
3009 if(iy
< 0 || iy
> vo_dheight
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
3012 *dx
= (double) ix
/ (double) vo_dwidth
;
3013 *dy
= (double) iy
/ (double) vo_dheight
;
3015 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
3016 *dx
, *dy
, vo_screenwidth
, vo_screenheight
, vo_dwidth
, vo_dheight
, vo_fs
);
3023 static float timing_sleep(float time_frame
)
3027 // -------- RTC -----------
3028 current_module
="sleep_rtc";
3029 while (time_frame
> 0.000) {
3030 unsigned long rtc_ts
;
3031 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
3032 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
3033 time_frame
-= GetRelativeTime();
3039 current_module
= "sleep_darwin";
3040 while (time_frame
> 0.005) {
3041 usec_sleep(1000000*time_frame
);
3042 time_frame
-= GetRelativeTime();
3047 // assume kernel HZ=100 for softsleep, works with larger HZ but with
3048 // unnecessarily high CPU usage
3049 float margin
= softsleep
? 0.011 : 0;
3050 current_module
= "sleep_timer";
3051 while (time_frame
> margin
) {
3052 usec_sleep(1000000 * (time_frame
- margin
));
3053 time_frame
-= GetRelativeTime();
3056 current_module
= "sleep_soft";
3058 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
3059 while (time_frame
> 0)
3060 time_frame
-=GetRelativeTime(); // burn the CPU
3063 #endif /* SYS_DARWIN */
3067 static void adjust_sync_and_print_status(int between_frames
, float timing_error
)
3069 current_module
="av_sync";
3072 double a_pts
, v_pts
;
3076 * If autosync is enabled, the value for delay must be calculated
3077 * a bit differently. It is set only to the difference between
3078 * the audio and video timers. Any attempt to include the real
3079 * or corrected delay causes the pts_correction code below to
3080 * try to correct for the changes in delay which autosync is
3081 * trying to measure. This keeps the two from competing, but still
3082 * allows the code to correct for PTS drift *only*. (Using a delay
3083 * value here, even a "corrected" one, would be incompatible with
3086 a_pts
= written_audio_pts(sh_audio
, d_audio
) - sh_audio
->delay
;
3088 a_pts
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
3090 v_pts
= sh_video
->pts
;
3093 static int drop_message
=0;
3094 double AV_delay
= a_pts
- audio_delay
- v_pts
;
3096 if (AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
3098 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
3103 /* Do not correct target time for the next frame if this frame
3104 * was late not because of wrong target time but because the
3105 * target time could not be met */
3106 x
= (AV_delay
+ timing_error
* playback_speed
) * 0.1f
;
3107 if (x
< -max_pts_correction
)
3108 x
= -max_pts_correction
;
3109 else if (x
> max_pts_correction
)
3110 x
= max_pts_correction
;
3111 if (default_max_pts_correction
>= 0)
3112 max_pts_correction
= default_max_pts_correction
;
3114 max_pts_correction
= sh_video
->frametime
*0.10; // +-10% of time
3115 if (!between_frames
) {
3120 print_status(a_pts
- audio_delay
, AV_delay
, c_total
);
3127 print_status(0, 0, 0);
3131 static int fill_audio_out_buffers(void)
3140 current_module
="play_audio";
3143 // all the current uses of ao_data.pts seem to be in aos that handle
3144 // sync completely wrong; there should be no need to use ao_data.pts
3146 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3147 bytes_to_write
= audio_out
->get_space();
3148 if (sh_video
|| bytes_to_write
>= ao_data
.outburst
)
3151 // handle audio-only case:
3152 // this is where mplayer sleeps during audio-only playback
3153 // to avoid 100% CPU use
3154 usec_sleep(10000); // Wait a tick before retry
3157 while (bytes_to_write
) {
3158 playsize
= bytes_to_write
;
3159 if (playsize
> MAX_OUTBURST
)
3160 playsize
= MAX_OUTBURST
;
3161 bytes_to_write
-= playsize
;
3163 // Fill buffer if needed:
3164 current_module
="decode_audio";
3166 while (sh_audio
->a_out_buffer_len
< playsize
) {
3167 int buflen
= sh_audio
->a_out_buffer_len
;
3168 int ret
= decode_audio(sh_audio
, &sh_audio
->a_out_buffer
[buflen
],
3169 playsize
- buflen
, // min bytes
3170 sh_audio
->a_out_buffer_size
- buflen
// max
3172 if (ret
<= 0) { // EOF?
3175 if (sh_audio
->a_out_buffer_len
== 0)
3180 sh_audio
->a_out_buffer_len
+= ret
;
3183 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
3184 if (playsize
> sh_audio
->a_out_buffer_len
) {
3185 playsize
= sh_audio
->a_out_buffer_len
;
3187 playflags
|= AOPLAY_FINAL_CHUNK
;
3193 current_module
="play_audio";
3195 // Is this pts value actually useful for the aos that access it?
3196 // They're obviously badly broken in the way they handle av sync;
3197 // would not having access to this make them more broken?
3198 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3199 playsize
= audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
3202 sh_audio
->a_out_buffer_len
-= playsize
;
3203 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
3204 sh_audio
->a_out_buffer_len
);
3205 sh_audio
->delay
+= playback_speed
*playsize
/(double)ao_data
.bps
;
3207 else if (audio_eof
&& audio_out
->get_delay() < .04) {
3208 // Sanity check to avoid hanging in case current ao doesn't output
3209 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3210 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
3211 sh_audio
->a_out_buffer_len
= 0;
3217 static int sleep_until_update(float *time_frame
, float *aq_sleep_time
)
3219 int frame_time_remaining
= 0;
3220 current_module
="calc_sleep_time";
3222 *time_frame
-= GetRelativeTime(); // reset timer
3224 if (sh_audio
&& !d_audio
->eof
) {
3225 float delay
= audio_out
->get_delay();
3226 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
3230 * Adjust this raw delay value by calculating the expected
3231 * delay for this frame and generating a new value which is
3232 * weighted between the two. The higher autosync is, the
3233 * closer to the delay value gets to that which "-nosound"
3234 * would have used, and the longer it will take for A/V
3235 * sync to settle at the right value (but it eventually will.)
3236 * This settling time is very short for values below 100.
3238 float predicted
= sh_audio
->delay
/ playback_speed
+ *time_frame
;
3239 float difference
= delay
- predicted
;
3240 delay
= predicted
+ difference
/ (float)autosync
;
3243 *time_frame
= delay
- sh_audio
->delay
/ playback_speed
;
3245 // delay = amount of audio buffered in soundcard/driver
3246 if (delay
> 0.25) delay
=0.25; else
3247 if (delay
< 0.10) delay
=0.10;
3248 if (*time_frame
> delay
*0.6) {
3249 // sleep time too big - may cause audio drops (buffer underrun)
3250 frame_time_remaining
= 1;
3251 *time_frame
= delay
*0.5;
3254 // If we're lagging more than 200 ms behind the right playback rate,
3255 // don't try to "catch up".
3256 // If benchmark is set always output frames as fast as possible
3257 // without sleeping.
3258 if (*time_frame
< -0.2 || benchmark
)
3262 *aq_sleep_time
+= *time_frame
;
3265 //============================== SLEEP: ===================================
3267 // flag 256 means: libvo driver does its timing (dvb card)
3268 if (*time_frame
> 0.001 && !(vo_flags
&256))
3269 *time_frame
= timing_sleep(*time_frame
);
3270 return frame_time_remaining
;
3273 static int reinit_video_chain(void) {
3274 //================== Init VIDEO (codec & libvo) ==========================
3275 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
3276 current_module
="preinit_libvo";
3278 //shouldn't we set dvideo->id=-2 when we fail?
3280 //if((video_out->preinit(vo_subdevice))!=0){
3281 if(!(video_out
=init_best_video_out(video_driver_list
))){
3282 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
3285 sh_video
->video_out
=video_out
;
3286 inited_flags
|=INITED_VO
;
3289 current_module
="init_video_filters";
3291 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
3292 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
3296 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
3297 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
3299 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
3304 sh_video
->vfilter
=(void*)vf_menu
;
3312 for (i
= 0; vf_settings
[i
].name
; ++i
)
3313 if (strcmp(vf_settings
[i
].name
, "ass") == 0) {
3318 extern vf_info_t vf_info_ass
;
3319 vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
3320 char* vf_arg
[] = {"auto", "1", NULL
};
3321 vf_instance_t
* vf_ass
= vf_open_plugin(libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
3323 sh_video
->vfilter
=(void*)vf_ass
;
3325 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
3330 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
3334 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
3337 current_module
="init_video_codec";
3339 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3340 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
3341 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3343 if(!sh_video
->inited
){
3344 if(!fixed_vo
) uninit_player(INITED_VO
);
3348 inited_flags
|=INITED_VCODEC
;
3350 if (sh_video
->codec
)
3351 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
3353 sh_video
->last_pts
= MP_NOPTS_VALUE
;
3354 sh_video
->num_buffered_pts
= 0;
3355 sh_video
->next_frame_time
= 0;
3358 // Auto quality option enabled
3359 output_quality
=get_video_quality_max(sh_video
);
3360 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
3361 else output_quality
=auto_quality
;
3362 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
3363 set_video_quality(sh_video
,output_quality
);
3366 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3368 current_module
="init_vo";
3373 sh_video
= d_video
->sh
= NULL
;
3377 static double update_video(int *blit_frame
)
3379 //-------------------- Decode a frame: -----------------------
3381 *blit_frame
= 0; // Don't blit if we hit EOF
3383 unsigned char* start
=NULL
;
3384 void *decoded_frame
;
3388 current_module
= "video_read_frame";
3389 frame_time
= sh_video
->next_frame_time
;
3390 in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
3394 if (in_size
> max_framesize
)
3395 max_framesize
= in_size
; // stats
3396 sh_video
->timer
+= frame_time
;
3398 sh_audio
->delay
-= frame_time
;
3399 // video_read_frame can change fps (e.g. for ASF video)
3400 vo_fps
= sh_video
->fps
;
3401 // check for frame-drop:
3402 current_module
= "check_framedrop";
3403 if (sh_audio
&& !d_audio
->eof
) {
3404 static int dropped_frames
;
3405 float delay
= playback_speed
*audio_out
->get_delay();
3406 float d
= delay
-sh_audio
->delay
;
3407 // we should avoid dropping too many frames in sequence unless we
3408 // are too late. and we allow 100ms A-V delay here:
3409 if (d
< -dropped_frames
*frame_time
-0.100 &&
3410 osd_function
!= OSD_PAUSE
) {
3411 drop_frame
= frame_dropping
;
3415 drop_frame
= dropped_frames
= 0;
3420 current_module
= "decode_video";
3421 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
3423 current_module
= "filter_video";
3424 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
3428 if (!generate_video_frame(sh_video
, d_video
))
3430 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
,
3431 VFCTRL_GET_PTS
, &sh_video
->pts
);
3432 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
3433 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
3434 sh_video
->pts
= sh_video
->last_pts
;
3436 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
3437 sh_video
->last_pts
= sh_video
->pts
;
3438 else if (sh_video
->last_pts
>= sh_video
->pts
) {
3439 sh_video
->last_pts
= sh_video
->pts
;
3440 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "pts value <= previous");
3442 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
3443 sh_video
->last_pts
= sh_video
->pts
;
3444 sh_video
->timer
+= frame_time
;
3446 sh_audio
->delay
-= frame_time
;
3452 void pause_loop(void)
3456 // Small hack to display the pause message on the OSD line.
3457 // The pause string is: "\n == PAUSE == \r" so we need to
3458 // take the first and the last char out
3459 if (term_osd
&& !sh_video
) {
3460 char msg
[128] = MSGTR_Paused
;
3461 int mlen
= strlen(msg
);
3463 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
3466 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
3467 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
3472 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
3474 if (video_out
&& sh_video
&& vo_config_count
)
3475 video_out
->control(VOCTRL_PAUSE
, NULL
);
3477 if (audio_out
&& sh_audio
)
3478 audio_out
->pause(); // pause audio, keep data if possible
3480 while ( (cmd
= mp_input_get_cmd(20, 1, 1)) == NULL
) {
3481 if (sh_video
&& video_out
&& vo_config_count
)
3482 video_out
->check_events();
3486 guiGetEvent(guiReDraw
, NULL
);
3487 if (guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
))
3493 vf_menu_pause_update(vf_menu
);
3497 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
3498 cmd
= mp_input_get_cmd(0,1,0);
3501 osd_function
=OSD_PLAY
;
3502 if (audio_out
&& sh_audio
)
3503 audio_out
->resume(); // resume audio
3504 if (video_out
&& sh_video
&& vo_config_count
)
3505 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
3506 (void)GetRelativeTime(); // ignore time that passed during pause
3509 if (guiIntfStruct
.Playing
== guiSetStop
)
3512 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
3518 int main(int argc
,char* argv
[]){
3523 int file_format
=DEMUXER_TYPE_UNKNOWN
;
3527 /* Flag indicating whether MPlayer should exit without playing anything. */
3530 //float a_frame=0; // Audio
3535 int gui_no_filename
=0;
3537 srand((int) time(NULL
));
3543 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2006 MPlayer Team\n");
3544 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
3545 GetCpuCaps(&gCpuCaps
);
3547 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
3548 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
3549 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
3550 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
3551 #ifdef RUNTIME_CPUDETECT
3552 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
3554 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
3556 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
3559 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
3562 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
3565 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
3568 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
3571 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
3573 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3574 #endif /* RUNTIME_CPUDETECT */
3575 #endif /* ARCH_X86 */
3577 #if defined(WIN32) && defined(USE_WIN32DLL)
3579 #endif /*WIN32 && USE_WIN32DLL*/
3582 tv_param_immediate
= 1;
3585 if (argc
> 1 && argv
[1] &&
3586 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
3587 use_gui
= !strcmp(argv
[1], "-gui");
3591 char *base
= strrchr(argv
[0], '/');
3593 base
= strrchr(argv
[0], '\\');
3596 if(strstr(base
, "gmplayer"))
3600 mconfig
= m_config_new();
3601 m_config_register_options(mconfig
,mplayer_opts
);
3602 // TODO : add something to let modules register their options
3603 mp_input_register_options(mconfig
);
3604 parse_cfgfiles(mconfig
);
3607 if ( use_gui
) cfg_read();
3610 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
3611 if(playtree
== NULL
)
3614 playtree
= play_tree_cleanup(playtree
);
3616 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3618 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3619 play_tree_iter_free(playtree_iter
);
3620 playtree_iter
= NULL
;
3622 filename
= play_tree_iter_get_file(playtree_iter
,1);
3627 #if defined(WIN32) && defined(HAVE_NEW_GUI)
3628 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
3629 if(runningmplayer
&& filename
&& use_gui
){
3630 COPYDATASTRUCT csData
;
3631 char file
[MAX_PATH
];
3632 char *filepart
= filename
;
3633 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
3635 csData
.cbData
= strlen(file
)*2;
3636 csData
.lpData
= file
;
3637 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
3645 for(i
=0; priority_presets_defs
[i
].name
; i
++){
3646 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
3649 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
3650 priority_presets_defs
[i
].name
);
3651 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
3654 #ifndef HAVE_NEW_GUI
3656 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
3661 if(use_gui
&& !vo_init()){
3662 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
3666 if (use_gui
&& playtree_iter
){
3667 char cwd
[PATH_MAX
+2];
3668 // Free Playtree and Playtree-Iter as it's not used by the GUI.
3669 play_tree_iter_free(playtree_iter
);
3672 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
3675 // Prefix relative paths with current working directory
3676 play_tree_add_bpf(playtree
, cwd
);
3678 // Import initital playtree into GUI.
3679 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
3681 #endif /* HAVE_NEW_GUI */
3683 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
3688 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
3693 /* Check codecs.conf. */
3694 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
3695 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
3696 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
3697 if(!parse_codec_cfg(NULL
)){
3698 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
3699 exit_player_with_rc(NULL
, 0);
3701 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
3704 free( mem_ptr
); // release the buffer created by get_path()
3708 if(video_codec_list
){
3710 video_codec
=video_codec_list
[0];
3711 for(i
=0;video_codec_list
[i
];i
++)
3712 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
3715 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
3716 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
3717 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
3719 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3722 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
3723 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
3724 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
3726 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3729 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
3731 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3734 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3736 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3739 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3745 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3747 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3751 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3752 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3753 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3755 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3758 if(list_properties
) {
3759 m_properties_print_help_list(mp_properties
);
3766 if (player_idle_mode
&& use_gui
) {
3767 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
3768 exit_player_with_rc(NULL
, 1);
3771 if(!filename
&& !player_idle_mode
){
3773 // no file/vcd/dvd -> show HELP:
3774 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
3775 exit_player_with_rc(NULL
, 0);
3776 } else gui_no_filename
=1;
3779 /* Display what configure line was used */
3780 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
3782 // Many users forget to include command line in bugreports...
3783 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3784 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
3785 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3786 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3789 //------ load global data first ------
3792 #ifdef HAVE_FREETYPE
3795 #ifdef HAVE_FONTCONFIG
3796 if(!font_fontconfig
)
3799 #ifdef HAVE_BITMAP_FONT
3801 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3802 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
3805 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3806 free(mem_ptr
); // release the buffer created by get_path()
3808 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3811 #ifdef HAVE_FONTCONFIG
3818 ass_library
= ass_init();
3824 // seteuid(0); /* Can't hurt to try to get root here */
3825 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3826 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
3827 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3829 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3831 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3832 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
3833 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
3836 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3837 /* variable only by the root */
3838 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
3842 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
3846 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
3847 // and now ? -- Pontscho
3848 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
3851 #endif /* HAVE_RTC */
3852 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3853 softsleep
?"software":timer_name
);
3856 if ( !use_gui
) load_termcap(NULL
); // load key-codes
3859 // ========== Init keyboard FIFO (connection to libvo) ============
3861 // Init input system
3862 current_module
= "init_input";
3863 mp_input_init(use_gui
);
3865 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
3867 if(keyb_fifo_get
> 0)
3868 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
3870 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
3874 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
3876 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
3878 else if(!noconsolecontrols
)
3879 #ifndef HAVE_NO_POSIX_SELECT
3880 mp_input_add_key_fd(0,1,NULL
,NULL
);
3882 mp_input_add_key_fd(0,0,NULL
,NULL
);
3885 inited_flags
|=INITED_INPUT
;
3886 current_module
= NULL
;
3890 if(menu_cfg
&& menu_init(menu_cfg
))
3891 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3893 menu_cfg
= get_path("menu.conf");
3894 if(menu_init(menu_cfg
))
3895 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3897 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
3898 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
3900 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
3910 signal(SIGCHLD
,child_sighandler
);
3914 prog_path
= argv
[0];
3916 //========= Catch terminate signals: ================
3917 // terminate requests:
3918 signal(SIGTERM
,exit_sighandler
); // kill
3919 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3921 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3923 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3924 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3925 #ifdef ENABLE_SIGHANDLER
3927 signal(SIGBUS
,exit_sighandler
); // bus error
3928 signal(SIGSEGV
,exit_sighandler
); // segfault
3929 signal(SIGILL
,exit_sighandler
); // illegal instruction
3930 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3931 signal(SIGABRT
,exit_sighandler
); // abort()
3934 signal(SIGTRAP
,exit_sighandler
);
3941 inited_flags
|=INITED_GUI
;
3942 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
3946 // ******************* Now, let's see the per-file stuff ********************
3950 // init global sub numbers
3951 global_sub_size
= 0;
3952 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
3954 if (filename
) load_per_file_config (mconfig
, filename
);
3956 // We must enable getch2 here to be able to interrupt network connection
3958 if(!noconsolecontrols
&& !slave_mode
){
3959 if(inited_flags
&INITED_GETCH2
)
3960 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
3962 getch2_enable(); // prepare stdin for hotkeys...
3963 inited_flags
|=INITED_GETCH2
;
3964 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3967 // =================== GUI idle loop (STOP state) ===========================
3970 file_format
=DEMUXER_TYPE_UNKNOWN
;
3971 guiGetEvent( guiSetDefaults
,0 );
3972 while ( guiIntfStruct
.Playing
!= 1 )
3977 guiGetEvent( guiReDraw
,NULL
);
3978 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3980 guiGetEvent( guiSetParameters
,NULL
);
3981 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
3983 play_tree_t
* entry
= play_tree_new();
3984 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
3985 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
3986 else playtree
=play_tree_new();
3987 play_tree_set_child( playtree
,entry
);
3990 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3993 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
3995 play_tree_iter_free(playtree_iter
);
3996 playtree_iter
= NULL
;
3998 filename
= play_tree_iter_get_file(playtree_iter
,1);
4003 #endif /* HAVE_NEW_GUI */
4005 while (player_idle_mode
&& !filename
) {
4006 play_tree_t
* entry
= NULL
;
4008 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
4009 if (video_out
&& vo_config_count
) video_out
->check_events();
4013 case MP_CMD_LOADFILE
:
4014 // prepare a tree entry with the new filename
4015 entry
= play_tree_new();
4016 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
4017 // The entry is added to the main playtree after the switch().
4019 case MP_CMD_LOADLIST
:
4020 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
4023 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
4029 if (entry
) { // user entered a command that gave a valid entry
4030 if (playtree
) // the playtree is always a node with one child. let's clear it
4031 play_tree_free_list(playtree
->child
, 1);
4032 else playtree
=play_tree_new(); // .. or make a brand new playtree
4034 if (!playtree
) continue; // couldn't make playtree! wait for next command
4036 play_tree_set_child(playtree
, entry
);
4038 /* Make iterator start at the top the of tree. */
4039 playtree_iter
= play_tree_iter_new(playtree
, mconfig
);
4040 if (!playtree_iter
) continue;
4042 // find the first real item in the tree
4043 if (play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
4045 play_tree_iter_free(playtree_iter
);
4046 playtree_iter
= NULL
;
4047 continue; // wait for next command
4049 filename
= play_tree_iter_get_file(playtree_iter
, 1);
4052 //---------------------------------------------------------------------------
4054 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
4057 if (edl_records
) free_edl(edl_records
);
4058 next_edl_record
= edl_records
= edl_parse_file();
4060 if (edl_output_filename
) {
4061 if (edl_fd
) fclose(edl_fd
);
4062 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
4064 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
4065 edl_output_filename
);
4069 //==================== Open VOB-Sub ============================
4071 current_module
="vobsub";
4073 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
4075 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
4076 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
4077 /* try to autodetect vobsub from movie filename ::atmos */
4078 char *buf
= malloc((strlen(filename
)-3)),*psub
;
4079 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
4080 strncpy(buf
, filename
, strlen(filename
)-4);
4081 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
4082 /* try from ~/.mplayer/sub */
4083 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
4086 bname
= strrchr(buf
,'/');
4088 if(!bname
) bname
= strrchr(buf
,'\\');
4092 l
= strlen(psub
) + strlen(bname
) + 1;
4093 psub
= realloc(psub
,l
);
4095 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
4101 inited_flags
|=INITED_VOBSUB
;
4102 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
4103 // check if vobsub requested only to display forced subtitles
4104 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
4106 // setup global sub numbering
4107 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
4108 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
4111 //============ Open & Sync STREAM --- fork cache2 ====================
4116 //free_demuxer_stream(d_audio);
4120 //free_demuxer_stream(d_video);
4126 current_module
="open_stream";
4127 stream
=open_stream(filename
,0,&file_format
);
4128 if(!stream
) { // error...
4129 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
4130 goto goto_next_file
;
4132 inited_flags
|=INITED_STREAM
;
4135 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
4138 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
4141 current_module
="handle_playlist";
4142 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
4143 entry
= parse_playtree(stream
,0);
4144 eof
=playtree_add_playlist(entry
);
4145 goto goto_next_file
;
4147 stream
->start_pos
+=seek_to_byte
;
4149 if(stream_dump_type
==5){
4150 unsigned char buf
[4096];
4153 current_module
="dumpstream";
4154 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
4155 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
4156 exit_player(MSGTR_Exit_error
);
4158 stream_reset(stream
);
4159 stream_seek(stream
,stream
->start_pos
);
4160 f
=fopen(stream_dump_name
,"wb");
4162 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
4163 exit_player(MSGTR_Exit_error
);
4165 while(!stream
->eof
){
4166 len
=stream_read(stream
,buf
,4096);
4168 if(fwrite(buf
,len
,1,f
) != 1) {
4169 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
4170 exit_player(MSGTR_Exit_error
);
4175 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
4176 exit_player(MSGTR_Exit_error
);
4178 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
4179 exit_player_with_rc(MSGTR_Exit_eof
, 0);
4183 if(stream
->type
==STREAMTYPE_DVD
){
4184 current_module
="dvd lang->id";
4185 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
4186 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
4187 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
4188 // setup global sub numbering
4189 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4190 global_sub_size
+= dvd_number_of_subs(stream
);
4191 current_module
=NULL
;
4196 if(stream
->type
==STREAMTYPE_DVDNAV
){
4197 current_module
="dvdnav lang->id";
4198 if(audio_id
==-1) audio_id
=dvdnav_aid_from_lang(stream
,audio_lang
);
4199 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
4200 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvdnav_sid_from_lang(stream
,dvdsub_lang
);
4201 // setup global sub numbering
4202 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4203 global_sub_size
+= dvdnav_number_of_subs(stream
);
4204 current_module
=NULL
;
4208 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
4210 if(stream_cache_size
>0){
4211 current_module
="enable_cache";
4212 if(!stream_enable_cache(stream
,stream_cache_size
*1024,
4213 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
4214 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
4215 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
4218 //============ Open DEMUXERS --- DETECT file type =======================
4219 current_module
="demux_open";
4221 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
4223 // HACK to get MOV Reference Files working
4225 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
4227 unsigned char* playlist_entry
;
4228 play_tree_t
*list
= NULL
, *entry
= NULL
;
4230 current_module
="handle_demux_playlist";
4231 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
4235 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",playlist_entry
);
4237 bname
=mp_basename(playlist_entry
);
4238 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
4241 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
4244 entry
= play_tree_new();
4246 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
4248 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
4251 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
4252 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
4253 strcat(temp
, playlist_entry
);
4254 play_tree_add_file(entry
,temp
);
4255 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
4260 play_tree_add_file(entry
,playlist_entry
);
4265 play_tree_append_entry(list
,entry
);
4267 free_demuxer(demuxer
);
4272 entry
= play_tree_new();
4273 play_tree_set_child(entry
,list
);
4274 eof
=playtree_add_playlist(entry
);
4275 goto goto_next_file
;
4284 current_module
="handle_playlist";
4285 switch(stream
->type
){
4286 case STREAMTYPE_VCD
:
4287 case STREAMTYPE_DVD
:
4288 case STREAMTYPE_CDDA
:
4289 case STREAMTYPE_VCDBINCUE
:
4290 // don't try to parse raw media as playlist, it's unlikely
4291 goto goto_next_file
;
4293 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
4294 stream_reset(stream
);
4295 stream_seek(stream
,stream
->start_pos
);
4296 entry
= parse_playtree(stream
,0);
4298 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
4300 eof
=playtree_add_playlist(entry
);
4302 goto goto_next_file
;
4304 inited_flags
|=INITED_DEMUXER
;
4306 if (stream
->type
!= STREAMTYPE_DVD
&& stream
->type
!= STREAMTYPE_DVDNAV
) {
4308 // setup global sub numbering
4309 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4310 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
4311 if (demuxer
->s_streams
[i
])
4315 current_module
="demux_open2";
4317 //file_format=demuxer->file_format;
4319 d_audio
=demuxer
->audio
;
4320 d_video
=demuxer
->video
;
4321 d_dvdsub
=demuxer
->sub
;
4324 if((stream_dump_type
)&&(stream_dump_type
<4)){
4326 demux_stream_t
*ds
=NULL
;
4327 current_module
="dump";
4328 // select stream to dump
4329 switch(stream_dump_type
){
4330 case 1: ds
=d_audio
;break;
4331 case 2: ds
=d_video
;break;
4332 case 3: ds
=d_dvdsub
;break;
4335 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
4336 exit_player(MSGTR_Exit_error
);
4338 // disable other streams:
4339 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
4340 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
4341 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
4343 f
=fopen(stream_dump_name
,"wb");
4345 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
4346 exit_player(MSGTR_Exit_error
);
4349 unsigned char* start
;
4350 int in_size
=ds_get_packet(ds
,&start
);
4351 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
4352 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
4353 if(in_size
>0) fwrite(start
,in_size
,1,f
);
4356 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
4357 exit_player_with_rc(MSGTR_Exit_eof
, 0);
4360 sh_audio
=d_audio
->sh
;
4361 sh_video
=d_video
->sh
;
4365 current_module
="video_read_properties";
4366 if(!video_read_properties(sh_video
)) {
4367 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
4368 sh_video
=d_video
->sh
=NULL
;
4370 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
4371 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
4372 sh_video
->fps
,sh_video
->frametime
4375 /* need to set fps here for output encoders to pick it up in their init */
4377 sh_video
->fps
=force_fps
;
4378 sh_video
->frametime
=1.0f
/sh_video
->fps
;
4380 vo_fps
= sh_video
->fps
;
4382 if(!sh_video
->fps
&& !force_fps
){
4383 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
4384 sh_video
=d_video
->sh
=NULL
;
4392 if(!sh_video
&& !sh_audio
){
4393 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
4394 #ifdef HAS_DVBIN_SUPPORT
4395 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4397 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4401 int v
= last_dvb_step
;
4403 dir
= DVB_CHANNEL_HIGHER
;
4405 dir
= DVB_CHANNEL_LOWER
;
4407 if(dvb_step_channel(priv
, dir
))
4408 eof
= dvbin_reopen
= 1;
4412 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
4415 /* display clip info */
4416 demux_info_print(demuxer
);
4418 //================== Read SUBTITLES (DVD & TEXT) ==========================
4419 if(vo_spudec
==NULL
&& sh_video
&&
4420 (stream
->type
==STREAMTYPE_DVD
|| stream
->type
== STREAMTYPE_DVDNAV
|| d_dvdsub
->id
>= 0)){
4424 // Apply current settings for forced subs
4425 if (vo_spudec
!=NULL
)
4426 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
4429 // after reading video params we should load subtitles because
4430 // we know fps so now we can adjust subtitle time to ~6 seconds AST
4432 current_module
="read_subtitles_file";
4434 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
4435 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
4437 if(sub_auto
) { // auto load sub file ...
4438 char *psub
= get_path( "sub/" );
4439 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
4441 free(psub
); // release the buffer created by get_path() above
4443 add_subtitles (tmp
[i
], sh_video
->fps
, 0);
4448 if (set_of_sub_size
> 0) {
4449 // setup global sub numbering
4450 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
4451 global_sub_size
+= set_of_sub_size
;
4455 if (global_sub_size
) {
4456 // find the best sub to use
4457 if (vobsub_id
>= 0) {
4458 // if user asks for a vobsub id, use that first.
4459 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
4460 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
4461 // if user asks for a dvd sub id, use that next.
4462 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
4463 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
4464 // if there are text subs to use, use those. (autosubs come last here)
4465 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
4467 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4468 // if nothing else works, get subs from the demuxer.
4469 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
4472 // nothing worth doing automatically.
4473 global_sub_pos
= -1;
4475 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
4477 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
);
4479 switch (stream_dump_type
) {
4480 case 3: list_sub_file(subdata
); break;
4481 case 4: dump_mpsub(subdata
, sh_video
->fps
); break;
4482 case 6: dump_srt(subdata
, sh_video
->fps
); break;
4483 case 7: dump_microdvd(subdata
, sh_video
->fps
); break;
4484 case 8: dump_jacosub(subdata
, sh_video
->fps
); break;
4485 case 9: dump_sami(subdata
, sh_video
->fps
); break;
4489 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
4490 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", demuxer
->desc
->name
);
4492 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4493 if (sh_video
->format
>= 0x20202020)
4494 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video
->format
);
4496 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
4497 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
4498 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
4499 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
4500 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
4501 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
4504 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4505 if (sh_audio
->format
>= 0x20202020)
4506 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio
->format
);
4508 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
4509 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
4510 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
4511 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
4513 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
4515 if(!sh_video
) goto main
; // audio-only
4517 if(!reinit_video_chain()) {
4519 if(!sh_audio
) goto goto_next_file
;
4520 goto main
; // exit_player(MSGTR_Exit_error);
4524 if(vo_flags
& 0x08 && vo_spudec
)
4525 spudec_set_hw_spu(vo_spudec
,video_out
);
4527 #ifdef HAVE_FREETYPE
4528 force_load_font
= 1;
4531 //================== MAIN: ==========================
4533 current_module
="main";
4536 char* msg
= m_properties_expand_string(mp_properties
,playing_msg
);
4537 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
4542 // Disable the term OSD in verbose mode
4543 if(verbose
) term_osd
= 0;
4547 //int frame_corr_num=0; //
4548 //float v_frame=0; // Video
4549 float time_frame
=0; // Timer
4550 //float num_frames=0; // number of frames played
4553 int frame_time_remaining
=0; // flag
4557 // Make sure old OSD does not stay around,
4558 // e.g. with -fixed-vo and same-resolution files
4562 //================ SETUP AUDIO ==========================
4565 reinit_audio_chain();
4566 if (sh_audio
&& sh_audio
->codec
)
4567 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
4570 current_module
="av_init";
4575 audio_delay
+= sh_video
->stream_delay
;
4579 audio_delay
-= sh_audio
->stream_delay
;
4580 sh_audio
->delay
=-audio_delay
;
4584 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
4585 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",d_audio
->packs
);
4586 ds_free_packs(d_audio
); // free buffered chunks
4587 //d_audio->id=-2; // do not read audio chunks
4588 //uninit_player(INITED_AO); // close device
4591 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
4592 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",d_video
->packs
);
4593 ds_free_packs(d_video
);
4595 //if(!fixed_vo) uninit_player(INITED_VO);
4598 if (!sh_video
&& !sh_audio
)
4599 goto goto_next_file
;
4601 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4602 if(force_fps
&& sh_video
){
4603 vo_fps
= sh_video
->fps
=force_fps
;
4604 sh_video
->frametime
=1.0f
/sh_video
->fps
;
4605 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
4610 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
4611 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
4612 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
4613 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
4614 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
4618 //==================== START PLAYING =======================
4620 if(loop_times
>1) loop_times
--; else
4621 if(loop_times
==1) loop_times
= -1;
4623 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
4625 total_time_usage_start
=GetTimer();
4626 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4627 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
4628 play_n_frames
=play_n_frames_mf
;
4630 if(play_n_frames
==0){
4631 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
4635 float aq_sleep_time
=0;
4636 if(!sh_audio
&& d_audio
->sh
) {
4637 sh_audio
= d_audio
->sh
;
4638 sh_audio
->ds
= d_audio
;
4639 reinit_audio_chain();
4642 /*========================== PLAY AUDIO ============================*/
4645 if (!fill_audio_out_buffers())
4646 // at eof, all audio at least written to ao
4648 eof
= PT_NEXT_ENTRY
;
4652 // handle audio-only case:
4654 if(!quiet
|| end_at
.type
== END_AT_TIME
)
4655 a_pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4658 print_status(a_pos
, 0, 0);
4660 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
4661 eof
= PT_NEXT_ENTRY
;
4666 /*========================== PLAY VIDEO ============================*/
4668 vo_pts
=sh_video
->timer
*90000.0;
4669 vo_fps
=sh_video
->fps
;
4671 if (!frame_time_remaining
) {
4672 double frame_time
= update_video(&blit_frame
);
4673 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
4674 if (sh_video
->vf_inited
< 0) {
4675 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
4676 eof
= 1; goto goto_next_file
;
4681 time_frame
+= frame_time
/ playback_speed
; // for nosound
4684 // ==========================================================================
4686 // current_module="draw_osd";
4687 // if(vo_config_count) video_out->draw_osd();
4690 if(use_gui
) guiEventHandling();
4693 current_module
="vo_check_events";
4694 if (vo_config_count
) video_out
->check_events();
4697 if (stop_xscreensaver
) {
4698 current_module
= "stop_xscreensaver";
4699 xscreensaver_heartbeat();
4703 frame_time_remaining
= sleep_until_update(&time_frame
, &aq_sleep_time
);
4705 //====================== FLIP PAGE (VIDEO BLT): =========================
4707 current_module
="flip_page";
4708 if (!frame_time_remaining
&& blit_frame
) {
4709 unsigned int t2
=GetTimer();
4711 if(vo_config_count
) video_out
->flip_page();
4713 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
4715 //====================== A-V TIMESTAMP CORRECTION: =========================
4717 adjust_sync_and_print_status(frame_time_remaining
, time_frame
);
4719 //============================ Auto QUALITY ============================
4721 /*Output quality adjustments:*/
4723 current_module
="autoq";
4724 // float total=0.000001f * (GetTimer()-aq_total_time);
4725 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4726 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4729 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4730 if(output_quality
>1 && aq_sleep_time
<0)
4733 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4735 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4736 set_video_quality(sh_video
,output_quality
);
4739 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
4741 if (play_n_frames
<= 0) eof
= PT_NEXT_ENTRY
;
4745 // FIXME: add size based support for -endpos
4746 if (end_at
.type
== END_AT_TIME
&&
4747 !frame_time_remaining
&& end_at
.pos
<= sh_video
->pts
)
4748 eof
= PT_NEXT_ENTRY
;
4750 } // end if(sh_video)
4753 if (stream
->type
== STREAMTYPE_DVDNAV
) {
4755 mp_dvdnav_get_highlight (stream
, &hl
);
4756 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
4757 vo_osd_changed (OSDTYPE_DVDNAV
);
4761 //============================ Handle PAUSE ===============================
4763 current_module
="pause";
4766 // 36000000 means max timed visibility is 1 hour into the future, if
4767 // the difference is greater assume it's wrapped around from below 0
4768 if (osd_visible
- GetTimerMS() > 36000000) {
4770 vo_osd_progbar_type
=-1; // disable
4771 vo_osd_changed(OSDTYPE_PROGBAR
);
4772 if (osd_function
!= OSD_PAUSE
)
4773 osd_function
= OSD_PLAY
;
4777 if (osd_function
== OSD_PAUSE
) {
4784 osd_function
=OSD_FFW
;
4785 rel_seek_secs
+=step_sec
;
4788 //================= EDL =========================================
4790 if( next_edl_record
) { // Are we (still?) doing EDL?
4792 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
4793 free_edl(edl_records
);
4794 next_edl_record
= NULL
;
4797 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
4798 if( next_edl_record
->action
== EDL_SKIP
) {
4799 osd_function
= OSD_FFW
;
4801 rel_seek_secs
= next_edl_record
->length_sec
;
4802 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
);
4804 } else if( next_edl_record
->action
== EDL_MUTE
) {
4805 edl_muted
= !edl_muted
;
4806 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4807 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
4809 next_edl_record
=next_edl_record
->next
;
4814 //================= Keyboard events, SEEKing ====================
4816 current_module
="key_events";
4821 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
4822 if(!set_property_command(cmd
))
4824 case MP_CMD_SEEK
: {
4828 osd_show_percentage
= sh_video
->fps
;
4829 v
= cmd
->args
[0].v
.f
;
4830 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
4831 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
4834 osd_function
= (v
> sh_video
->pts
) ? OSD_FFW
: OSD_REW
;
4837 else if(abs
) { /* Absolute seek by percentage */
4840 osd_function
= OSD_FFW
; // Direction isn't set correctly
4841 rel_seek_secs
= v
/100.0;
4845 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
4849 case MP_CMD_SET_PROPERTY
: {
4850 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4851 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4852 else if(m_property_parse(prop
,cmd
->args
[1].v
.s
) <= 0)
4853 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to set property '%s' to '%s'.\n",
4854 cmd
->args
[0].v
.s
,cmd
->args
[1].v
.s
);
4857 case MP_CMD_STEP_PROPERTY
: {
4858 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4859 float arg
= cmd
->args
[1].v
.f
;
4860 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
, "Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4861 else if(m_property_do(prop
,M_PROPERTY_STEP_UP
, arg
? &arg
: NULL
) <= 0)
4862 mp_msg(MSGT_CPLAYER
,MSGL_WARN
, "Failed to increment property '%s' by %f.\n",cmd
->args
[0].v
.s
, arg
);
4864 case MP_CMD_GET_PROPERTY
: {
4867 prop
= mp_property_find(cmd
->args
[0].v
.s
);
4869 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4872 /* Use m_option_print directly to get easily parseable values. */
4873 val
= calloc(1,prop
->type
->size
);
4874 if(m_property_do(prop
,M_PROPERTY_GET
,val
) <= 0) {
4875 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to get value of property '%s'.\n",
4879 tmp
= m_option_print(prop
,val
);
4880 if(!tmp
|| tmp
== (char*)-1) {
4881 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to print value of property '%s'.\n",
4885 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_%s=%s\n",cmd
->args
[0].v
.s
,tmp
);
4888 case MP_CMD_EDL_MARK
:
4890 float v
= sh_video
? sh_video
->pts
:
4891 playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4893 if(begin_skip
== MP_NOPTS_VALUE
)
4896 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutStartSkip
);
4900 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_EdloutBadStop
);
4902 fprintf(edl_fd
, "%f %f %d\n", begin_skip
, v
, 0);
4903 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutEndSkip
);
4905 begin_skip
= MP_NOPTS_VALUE
;
4909 case MP_CMD_SWITCH_RATIO
: {
4910 if (cmd
->nargs
== 0 || cmd
->args
[0].v
.f
== -1)
4911 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
4913 movie_aspect
= cmd
->args
[0].v
.f
;
4914 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
4916 case MP_CMD_SPEED_INCR
: {
4917 float v
= cmd
->args
[0].v
.f
;
4918 playback_speed
+= v
;
4919 build_afilter_chain(sh_audio
, &ao_data
);
4920 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4922 case MP_CMD_SPEED_MULT
: {
4923 float v
= cmd
->args
[0].v
.f
;
4924 playback_speed
*= v
;
4925 build_afilter_chain(sh_audio
, &ao_data
);
4926 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4928 case MP_CMD_SPEED_SET
: {
4929 float v
= cmd
->args
[0].v
.f
;
4931 build_afilter_chain(sh_audio
, &ao_data
);
4932 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4934 case MP_CMD_FRAME_STEP
:
4935 case MP_CMD_PAUSE
: {
4939 case MP_CMD_FILE_FILTER
: {
4940 file_filter
= cmd
->args
[0].v
.i
;
4943 case MP_CMD_QUIT
: {
4944 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
4946 case MP_CMD_GRAB_FRAMES
: {
4949 case MP_CMD_PLAY_TREE_STEP
: {
4950 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
4951 int force
= cmd
->args
[1].v
.i
;
4960 for (i
=0;i
<-1*n
;i
++)
4965 if(!force
&& playtree_iter
) {
4966 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4968 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4969 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4970 play_tree_iter_free(i
);
4972 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4978 case MP_CMD_PLAY_TREE_UP_STEP
: {
4979 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
4980 int force
= cmd
->args
[1].v
.i
;
4982 if(!force
&& playtree_iter
) {
4983 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4984 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4985 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4986 play_tree_iter_free(i
);
4988 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4991 case MP_CMD_PLAY_ALT_SRC_STEP
: {
4992 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
4993 int v
= cmd
->args
[0].v
.i
;
4994 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
4996 else if(v
< 0 && playtree_iter
->file
> 1)
5001 case MP_CMD_SUB_STEP
: {
5003 int movement
= cmd
->args
[0].v
.i
;
5004 step_sub(subdata
, sh_video
->pts
, movement
);
5007 sub_delay
+= ass_step_sub(ass_track
, (sh_video
->pts
+ sub_delay
) * 1000 + .5, movement
) / 1000.;
5009 set_osd_msg(OSD_MSG_SUB_DELAY
,1,osd_duration
,
5010 MSGTR_OSDSubDelay
, ROUND(sub_delay
*1000));
5013 case MP_CMD_SUB_LOG
: {
5017 int v
= cmd
->args
[0].v
.i
;
5018 int max
= (term_osd
&& !sh_video
) ? MAX_TERM_OSD_LEVEL
: MAX_OSD_LEVEL
;
5019 if(osd_level
> max
) osd_level
= max
;
5021 osd_level
=(osd_level
+1)%(max
+1);
5023 osd_level
= v
> max
? max
: v
;
5024 /* Show OSD state when disabled, but not when an explicit
5025 argument is given to the OSD command, i.e. in slave mode. */
5026 if (v
== -1 && osd_level
<= 1)
5027 set_osd_msg(OSD_MSG_OSD_STATUS
,0,osd_duration
,
5028 MSGTR_OSDosd
, osd_level
? MSGTR_OSDenabled
: MSGTR_OSDdisabled
);
5030 rm_osd_msg(OSD_MSG_OSD_STATUS
);
5032 case MP_CMD_OSD_SHOW_TEXT
: {
5033 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
5034 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
5035 "%-.63s",cmd
->args
[0].v
.s
);
5037 case MP_CMD_OSD_SHOW_PROPERTY_TEXT
: {
5038 char* txt
= m_properties_expand_string(mp_properties
,cmd
->args
[0].v
.s
);
5039 /* if no argument supplied take default osd_duration, else <arg> ms. */
5041 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
5042 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
5047 case MP_CMD_LOADFILE
: {
5048 play_tree_t
* e
= play_tree_new();
5049 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
5051 if (cmd
->args
[1].v
.i
) // append
5052 play_tree_append_entry(playtree
, e
);
5054 // Go back to the starting point.
5055 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
5057 play_tree_free_list(playtree
->child
,1);
5058 play_tree_set_child(playtree
,e
);
5059 play_tree_iter_step(playtree_iter
,0,0);
5064 case MP_CMD_LOADLIST
: {
5065 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
5067 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
5069 if (cmd
->args
[1].v
.i
) // append
5070 play_tree_append_entry(playtree
, e
);
5072 // Go back to the starting point.
5073 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
5075 play_tree_free_list(playtree
->child
,1);
5076 play_tree_set_child(playtree
,e
);
5077 play_tree_iter_step(playtree_iter
,0,0);
5084 case MP_CMD_RADIO_STEP_CHANNEL
: {
5085 if (demuxer
->stream
->type
==STREAMTYPE_RADIO
) {
5086 int v
= cmd
->args
[0].v
.i
;
5088 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_HIGHER
);
5090 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_LOWER
);
5091 if (radio_get_channel_name(demuxer
->stream
)) {
5092 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
5093 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
5097 case MP_CMD_RADIO_SET_CHANNEL
: {
5098 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
) {
5099 radio_set_channel(demuxer
->stream
, cmd
->args
[0].v
.s
);
5100 if (radio_get_channel_name(demuxer
->stream
)) {
5101 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
5102 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
5106 case MP_CMD_RADIO_SET_FREQ
: {
5107 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
)
5108 radio_set_freq(demuxer
->stream
, cmd
->args
[0].v
.f
);
5110 case MP_CMD_RADIO_STEP_FREQ
:
5111 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
){
5112 radio_step_freq(demuxer
->stream
, cmd
->args
[0].v
.f
);
5117 case MP_CMD_TV_SET_FREQ
: {
5118 if (file_format
== DEMUXER_TYPE_TV
)
5119 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
5121 case MP_CMD_TV_SET_NORM
: {
5122 if (file_format
== DEMUXER_TYPE_TV
)
5123 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
5125 case MP_CMD_TV_STEP_CHANNEL
: {
5126 if (file_format
== DEMUXER_TYPE_TV
) {
5127 int v
= cmd
->args
[0].v
.i
;
5129 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
5131 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
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 #ifdef HAS_DVBIN_SUPPORT
5141 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
5143 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
5147 int v
= cmd
->args
[0].v
.i
;
5151 dir
= DVB_CHANNEL_HIGHER
;
5153 dir
= DVB_CHANNEL_LOWER
;
5156 if(dvb_step_channel(priv
, dir
))
5157 eof
= dvbin_reopen
= 1;
5160 #endif /* HAS_DVBIN_SUPPORT */
5162 case MP_CMD_TV_SET_CHANNEL
: {
5163 if (file_format
== DEMUXER_TYPE_TV
) {
5164 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
5165 if (tv_channel_list
) {
5166 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5167 MSGTR_OSDChannel
, tv_channel_current
->name
);
5168 //vo_osd_changed(OSDTYPE_SUBTITLE);
5172 #ifdef HAS_DVBIN_SUPPORT
5173 case MP_CMD_DVB_SET_CHANNEL
:
5175 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
5177 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
5180 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
5185 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
5186 eof
= dvbin_reopen
= 1;
5191 #endif /* HAS_DVBIN_SUPPORT */
5192 case MP_CMD_TV_LAST_CHANNEL
: {
5193 if (file_format
== DEMUXER_TYPE_TV
) {
5194 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
5195 if (tv_channel_list
) {
5196 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5197 MSGTR_OSDChannel
, tv_channel_current
->name
);
5198 //vo_osd_changed(OSDTYPE_SUBTITLE);
5202 case MP_CMD_TV_STEP_NORM
: {
5203 if (file_format
== DEMUXER_TYPE_TV
)
5204 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
5206 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
5207 if (file_format
== DEMUXER_TYPE_TV
)
5208 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
5211 case MP_CMD_SUB_LOAD
:
5214 int n
= set_of_sub_size
;
5215 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
5216 if (n
!= set_of_sub_size
) {
5217 if (global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
5218 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
;
5223 case MP_CMD_SUB_REMOVE
:
5226 int v
= cmd
->args
[0].v
.i
;
5229 for (v
= 0; v
< set_of_sub_size
; ++v
) {
5230 subd
= set_of_subtitles
[v
];
5231 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
5233 set_of_subtitles
[v
] = NULL
;
5235 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5236 global_sub_size
-= set_of_sub_size
;
5237 set_of_sub_size
= 0;
5238 if (set_of_sub_pos
>= 0) {
5239 global_sub_pos
= -2;
5240 vo_sub_last
= vo_sub
= NULL
;
5241 vo_osd_changed(OSDTYPE_SUBTITLE
);
5242 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5243 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5246 else if (v
< set_of_sub_size
) {
5247 subd
= set_of_subtitles
[v
];
5248 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
5250 if (set_of_sub_pos
== v
) {
5251 global_sub_pos
= -2;
5252 vo_sub_last
= vo_sub
= NULL
;
5253 vo_osd_changed(OSDTYPE_SUBTITLE
);
5254 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5255 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5257 else if (set_of_sub_pos
> v
) {
5261 while (++v
< set_of_sub_size
)
5262 set_of_subtitles
[v
- 1] = set_of_subtitles
[v
];
5265 if (set_of_sub_size
<= 0)
5266 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5267 set_of_subtitles
[set_of_sub_size
] = NULL
;
5271 case MP_CMD_GET_SUB_VISIBILITY
:
5274 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_SUB_VISIBILITY=%d\n", sub_visibility
);
5277 case MP_CMD_SCREENSHOT
:
5278 if(vo_config_count
){
5279 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"sending VFCTRL_SCREENSHOT!\n");
5280 if(CONTROL_OK
!=((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_SCREENSHOT
, &cmd
->args
[0].v
.i
))
5281 video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
5284 case MP_CMD_VF_CHANGE_RECTANGLE
:
5285 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
5288 case MP_CMD_GET_TIME_LENGTH
: {
5289 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
5292 case MP_CMD_GET_FILENAME
: {
5293 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_FILENAME='%s'\n", get_metadata (META_NAME
));
5296 case MP_CMD_GET_VIDEO_CODEC
: {
5297 char *inf
= get_metadata (META_VIDEO_CODEC
);
5298 if (!inf
) inf
= strdup ("");
5299 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_CODEC='%s'\n", inf
);
5303 case MP_CMD_GET_VIDEO_BITRATE
: {
5304 char *inf
= get_metadata (META_VIDEO_BITRATE
);
5305 if (!inf
) inf
= strdup ("");
5306 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_BITRATE='%s'\n", inf
);
5310 case MP_CMD_GET_VIDEO_RESOLUTION
: {
5311 char *inf
= get_metadata (META_VIDEO_RESOLUTION
);
5312 if (!inf
) inf
= strdup ("");
5313 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_RESOLUTION='%s'\n", inf
);
5317 case MP_CMD_GET_AUDIO_CODEC
: {
5318 char *inf
= get_metadata (META_AUDIO_CODEC
);
5319 if (!inf
) inf
= strdup ("");
5320 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_CODEC='%s'\n", inf
);
5324 case MP_CMD_GET_AUDIO_BITRATE
: {
5325 char *inf
= get_metadata (META_AUDIO_BITRATE
);
5326 if (!inf
) inf
= strdup ("");
5327 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_BITRATE='%s'\n", inf
);
5331 case MP_CMD_GET_AUDIO_SAMPLES
: {
5332 char *inf
= get_metadata (META_AUDIO_SAMPLES
);
5333 if (!inf
) inf
= strdup ("");
5334 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_SAMPLES='%s'\n", inf
);
5338 case MP_CMD_GET_META_TITLE
: {
5339 char *inf
= get_metadata (META_INFO_TITLE
);
5340 if (!inf
) inf
= strdup ("");
5341 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TITLE='%s'\n", inf
);
5345 case MP_CMD_GET_META_ARTIST
: {
5346 char *inf
= get_metadata (META_INFO_ARTIST
);
5347 if (!inf
) inf
= strdup ("");
5348 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ARTIST='%s'\n", inf
);
5352 case MP_CMD_GET_META_ALBUM
: {
5353 char *inf
= get_metadata (META_INFO_ALBUM
);
5354 if (!inf
) inf
= strdup ("");
5355 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ALBUM='%s'\n", inf
);
5359 case MP_CMD_GET_META_YEAR
: {
5360 char *inf
= get_metadata (META_INFO_YEAR
);
5361 if (!inf
) inf
= strdup ("");
5362 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_YEAR='%s'\n", inf
);
5366 case MP_CMD_GET_META_COMMENT
: {
5367 char *inf
= get_metadata (META_INFO_COMMENT
);
5368 if (!inf
) inf
= strdup ("");
5369 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_COMMENT='%s'\n", inf
);
5373 case MP_CMD_GET_META_TRACK
: {
5374 char *inf
= get_metadata (META_INFO_TRACK
);
5375 if (!inf
) inf
= strdup ("");
5376 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TRACK='%s'\n", inf
);
5380 case MP_CMD_GET_META_GENRE
: {
5381 char *inf
= get_metadata (META_INFO_GENRE
);
5382 if (!inf
) inf
= strdup ("");
5383 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_GENRE='%s'\n", inf
);
5387 case MP_CMD_GET_VO_FULLSCREEN
: {
5388 if(video_out
&& vo_config_count
)
5389 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VO_FULLSCREEN=%d\n", vo_fs
);
5392 case MP_CMD_GET_PERCENT_POS
: {
5393 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer
));
5395 case MP_CMD_GET_TIME_POS
: {
5398 pos
= sh_video
->pts
;
5400 if (sh_audio
&& audio_out
)
5401 pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
5402 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
5407 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
5412 case MP_CMD_KEYDOWN_EVENTS
: {
5413 mplayer_put_key(cmd
->args
[0].v
.i
);
5415 case MP_CMD_SEEK_CHAPTER
: {
5416 int seek
= cmd
->args
[0].v
.i
;
5417 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
5425 chap
= demuxer_seek_chapter(demuxer
, seek
, abs
, &next_pts
, &num_chapters
, &chapter_name
);
5427 if(next_pts
> -1.0) {
5429 rel_seek_secs
= next_pts
;
5432 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
,
5433 chap
+1, chapter_name
);
5438 rel_seek_secs
= 1000000000.;
5440 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
, 0, MSGTR_Unknown
);
5444 case MP_CMD_SET_MOUSE_POS
: {
5445 int button
= -1, pointer_x
, pointer_y
;
5447 pointer_x
= cmd
->args
[0].v
.i
;
5448 pointer_y
= cmd
->args
[1].v
.i
;
5449 rescale_input_coordinates(pointer_x
, pointer_y
, &dx
, &dy
);
5451 if(stream
->type
== STREAMTYPE_DVDNAV
&& dx
> 0.0 && dy
> 0.0) {
5452 pointer_x
= (int) (dx
* (double) sh_video
->disp_w
);
5453 pointer_y
= (int) (dy
* (double) sh_video
->disp_h
);
5454 mp_dvdnav_update_mouse_pos(stream
, pointer_x
, pointer_y
, &button
);
5455 if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5461 case MP_CMD_DVDNAV
: {
5463 if(stream
->type
!= STREAMTYPE_DVDNAV
) break;
5465 if(mp_dvdnav_handle_input(stream
, cmd
->args
[0].v
.i
, &button
)) {
5466 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
|(fixed_vo
? INITED_VO
: 0)));
5467 goto goto_enable_cache
;
5468 } else if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5474 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
5477 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
5480 switch (cmd
->pausing
) {
5481 case 1: // "pausing"
5482 osd_function
= OSD_PAUSE
;
5484 case 3: // "pausing_toggle"
5485 was_paused
= !was_paused
;
5487 case 2: // "pausing_keep"
5488 if (was_paused
) osd_function
= OSD_PAUSE
;
5498 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
5499 rel_seek_secs
+= 3600*a
+60*b
+d
;
5500 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
5501 rel_seek_secs
+= 60*a
+d
;
5502 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
5508 if (end_at
.type
!= END_AT_NONE
) {
5509 if(end_at
.type
== END_AT_SIZE
) {
5510 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
5511 end_at
.type
= END_AT_NONE
;
5513 end_at
.pos
+= rel_seek_secs
;
5518 if(eof
==1 && loop_times
>=0) {
5520 play_tree_iter_step(playtree_iter
,0,0);
5522 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
5524 if(loop_times
>1) loop_times
--; else
5525 if(loop_times
==1) loop_times
=-1;
5526 play_n_frames
=play_n_frames_mf
;
5528 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
5532 if(rel_seek_secs
|| abs_seek_pos
){
5533 current_module
="seek";
5534 if(demux_seek(demuxer
,rel_seek_secs
,audio_delay
,abs_seek_pos
)){
5536 /* FIXME there should be real seeking for vobsub */
5537 if(sh_video
) sh_video
->pts
=d_video
->pts
;
5539 //vobsub_reset(vo_vobsub);
5540 vobsub_seek(vo_vobsub
,sh_video
->pts
);
5544 current_module
="seek_video_reset";
5545 resync_video_stream(sh_video
);
5546 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
5547 sh_video
->num_buffered_pts
= 0;
5548 sh_video
->last_pts
= MP_NOPTS_VALUE
;
5552 current_module
="seek_audio_reset";
5553 audio_out
->reset(); // stop audio, throwing away buffered data
5554 sh_audio
->a_buffer_len
= 0;
5555 sh_audio
->a_out_buffer_len
= 0;
5560 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer
));
5565 max_pts_correction
=0.1;
5566 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
5567 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
5570 if(vo_spudec
) spudec_reset(vo_spudec
);
5574 * We saw a seek, have to rewind the EDL operations stack
5575 * and find the next EDL action to take care of.
5579 next_edl_record
= edl_records
;
5581 while (next_edl_record
)
5583 /* Trying to remember if we need to mute/unmute first;
5584 * prior EDL implementation lacks this.
5587 if (next_edl_record
->start_sec
>= sh_video
->pts
)
5590 if (next_edl_record
->action
== EDL_MUTE
) edl_muted
= !edl_muted
;
5591 next_edl_record
= next_edl_record
->next
;
5594 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
5598 frame_time_remaining
=0;
5599 current_module
=NULL
;
5606 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
5607 // get pos from frame number / total frames
5608 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
5610 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
5611 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
5612 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
5614 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
5615 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
5616 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
5617 guiGetEvent( guiReDraw
,NULL
);
5618 guiGetEvent( guiSetVolume
,NULL
);
5619 if(guiIntfStruct
.Playing
==0) break; // STOP
5620 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
5621 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
5623 if ( stream
->type
== STREAMTYPE_DVD
)
5625 dvd_priv_t
* dvdp
= stream
->priv
;
5626 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
5630 #endif /* HAVE_NEW_GUI */
5634 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
5636 #ifdef HAS_DVBIN_SUPPORT
5640 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
5641 cache_uninit(stream
);
5643 goto goto_enable_cache
;
5648 goto_next_file
: // don't jump here after ao/vo/getch initialization!
5650 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
5653 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
5654 double total_time_usage
;
5655 total_time_usage_start
=GetTimer()-total_time_usage_start
;
5656 total_time_usage
= (float)total_time_usage_start
*0.000001;
5657 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5658 video_time_usage
,vout_time_usage
,audio_time_usage
,
5659 total_time_usage
-tot
,total_time_usage
);
5660 if(total_time_usage
>0.0)
5661 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5662 100.0*video_time_usage
/total_time_usage
,
5663 100.0*vout_time_usage
/total_time_usage
,
5664 100.0*audio_time_usage
/total_time_usage
,
5665 100.0*(total_time_usage
-tot
)/total_time_usage
,
5667 if(total_frame_cnt
&& frame_dropping
)
5668 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5669 total_frame_cnt
-drop_frame_cnt
,
5670 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
5672 100*drop_frame_cnt
/total_frame_cnt
,
5674 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
5678 // time to uninit all, except global stuff:
5679 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
5681 if ( set_of_sub_size
> 0 )
5683 current_module
="sub_free";
5684 for (i
= 0; i
< set_of_sub_size
; ++i
) {
5685 sub_free( set_of_subtitles
[i
] );
5687 if ( set_of_ass_tracks
[i
] )
5688 ass_free_track( set_of_ass_tracks
[i
] );
5691 set_of_sub_size
= 0;
5693 vo_sub_last
= vo_sub
=NULL
;
5699 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
5700 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
5701 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
5704 play_tree_iter_free(playtree_iter
);
5705 playtree_iter
= NULL
;
5708 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
5709 eof
= eof
== PT_UP_NEXT
? 1 : -1;
5710 if ( playtree_iter
) {
5711 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
5714 play_tree_iter_free(playtree_iter
);
5715 playtree_iter
= NULL
;
5718 } else { // NEXT PREV SRC
5719 eof
= eof
== PT_PREV_SRC
? -1 : 1;
5722 if(eof
== 0) eof
= 1;
5724 while(playtree_iter
!= NULL
) {
5725 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
5726 if(filename
== NULL
) {
5727 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
5728 play_tree_iter_free(playtree_iter
);
5729 playtree_iter
= NULL
;
5736 if( use_gui
&& !playtree_iter
)
5739 if ( !guiIntfStruct
.DiskChanged
)
5745 if(use_gui
|| playtree_iter
!= NULL
|| player_idle_mode
){
5746 if (!playtree_iter
) filename
= NULL
;
5748 goto play_next_file
;
5752 exit_player_with_rc(MSGTR_Exit_eof
, 0);