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");
598 /// step size of mixer changes
601 static void uninit_player(unsigned int mask
){
602 mask
=inited_flags
&mask
;
604 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
606 if(mask
&INITED_ACODEC
){
607 inited_flags
&=~INITED_ACODEC
;
608 current_module
="uninit_acodec";
609 if(sh_audio
) uninit_audio(sh_audio
);
611 guiGetEvent(guiSetAfilter
, (char *)NULL
);
616 if(mask
&INITED_VCODEC
){
617 inited_flags
&=~INITED_VCODEC
;
618 current_module
="uninit_vcodec";
619 if(sh_video
) uninit_video(sh_video
);
626 if(mask
&INITED_DEMUXER
){
627 inited_flags
&=~INITED_DEMUXER
;
628 current_module
="free_demuxer";
630 stream
=demuxer
->stream
;
631 free_demuxer(demuxer
);
636 // kill the cache process:
637 if(mask
&INITED_STREAM
){
638 inited_flags
&=~INITED_STREAM
;
639 current_module
="uninit_stream";
640 if(stream
) free_stream(stream
);
645 inited_flags
&=~INITED_VO
;
646 current_module
="uninit_vo";
651 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
652 if(mask
&INITED_GETCH2
){
653 inited_flags
&=~INITED_GETCH2
;
654 current_module
="uninit_getch2";
655 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
660 if(mask
&INITED_VOBSUB
){
661 inited_flags
&=~INITED_VOBSUB
;
662 current_module
="uninit_vobsub";
663 if(vo_vobsub
) vobsub_close(vo_vobsub
);
667 if (mask
&INITED_SPUDEC
){
668 inited_flags
&=~INITED_SPUDEC
;
669 current_module
="uninit_spudec";
670 spudec_free(vo_spudec
);
675 inited_flags
&=~INITED_AO
;
676 current_module
="uninit_ao";
677 if (user_muted
| edl_muted
) mixer_mute(&mixer
);
678 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
683 inited_flags
&=~INITED_GUI
;
684 current_module
="uninit_gui";
689 if(mask
&INITED_INPUT
){
690 inited_flags
&=~INITED_INPUT
;
691 current_module
="uninit_input";
698 static void exit_player_with_rc(const char* how
, int rc
){
700 uninit_player(INITED_ALL
);
705 vo_uninit(); // Close the X11 connection (if any is open).
709 current_module
="uninit_font";
710 if (vo_font
) free_font_desc(vo_font
);
717 ass_library_done(ass_library
);
720 current_module
="exit_player";
722 // free mplayer config
724 m_config_free(mconfig
);
727 play_tree_free(playtree
, 1);
730 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
731 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
732 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
737 void exit_player(const char* how
){
738 exit_player_with_rc(how
, 1);
742 static void child_sighandler(int x
){
744 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
749 static char *prog_path
;
750 static int crash_debug
= 0;
753 static void exit_sighandler(int x
){
754 static int sig_count
=0;
756 if (!crash_debug
|| x
!= SIGTRAP
)
759 if(inited_flags
==0 && sig_count
>1) exit(1);
762 /* We're crashing bad and can't uninit cleanly :(
763 * by popular request, we make one last (dirty)
764 * effort to restore the user's
769 if(sig_count
==6) exit(1);
773 kill(getpid(),SIGKILL
);
776 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
777 current_module
?current_module
:"unknown"
779 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
786 break; // killed from keyboard (^C) or killed [-9]
788 #ifdef RUNTIME_CPUDETECT
789 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
791 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
795 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
797 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
802 snprintf(spid
, 19, "%i", getpid());
804 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
806 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
807 if (gdb_pid
== 0) { // We are the child
808 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
809 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
810 } else if (gdb_pid
< 0)
811 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
813 waitpid(gdb_pid
, NULL
, 0);
815 if (x
== SIGTRAP
) return;
822 extern void mp_input_register_options(m_config_t
* cfg
);
824 #include "cfg-mplayer.h"
826 static void parse_cfgfiles( m_config_t
* conf
)
830 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
832 if ((conffile
= get_path("")) == NULL
) {
833 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
838 mkdir(conffile
, 0777);
841 if ((conffile
= get_path("config")) == NULL
) {
842 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
844 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
845 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
846 write(conffile_fd
, default_config
, strlen(default_config
));
849 if (m_config_parse_config_file(conf
, conffile
) < 0)
856 void load_per_file_config (m_config_t
* conf
, const char *const file
)
859 char cfg
[strlen(file
)+10];
863 sprintf (cfg
, "%s.conf", file
);
865 if (use_filedir_conf
&& !stat (cfg
, &st
))
867 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
868 m_config_parse_config_file (conf
, cfg
);
872 if ((name
= strrchr (cfg
, '/')) == NULL
)
877 if ((confpath
= get_path (name
)) != NULL
)
879 if (!stat (confpath
, &st
))
881 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
882 m_config_parse_config_file (conf
, confpath
);
889 /* When libmpdemux performs a blocking operation (network connection or
890 * cache filling) if the operation fails we use this function to check
891 * if it was interrupted by the user.
892 * The function returns a new value for eof. */
893 static int libmpdemux_was_interrupted(int eof
) {
895 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
898 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
899 case MP_CMD_PLAY_TREE_STEP
: {
900 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
901 play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
903 case MP_CMD_PLAY_TREE_UP_STEP
: {
904 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
906 case MP_CMD_PLAY_ALT_SRC_STEP
: {
907 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
915 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
917 int playtree_add_playlist(play_tree_t
* entry
)
919 play_tree_add_bpf(entry
,filename
);
924 import_playtree_playlist_into_gui(entry
, mconfig
);
925 play_tree_free_list(entry
,1);
931 entry
= playtree_iter
->tree
;
932 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
933 return PT_NEXT_ENTRY
;
935 if(playtree_iter
->tree
== entry
) { // Loop with a single file
936 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
937 return PT_NEXT_ENTRY
;
940 play_tree_remove(entry
,1,1);
943 play_tree_insert_entry(playtree_iter
->tree
,entry
);
944 play_tree_set_params_from(entry
,playtree_iter
->tree
);
945 entry
= playtree_iter
->tree
;
946 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
947 return PT_NEXT_ENTRY
;
949 play_tree_remove(entry
,1,1);
959 for (i
= 0; i
< SUB_SOURCES
; i
++) {
960 int j
= global_sub_indices
[i
];
961 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
969 sub_data
* subdata
= NULL
;
970 static subtitle
* vo_sub_last
= NULL
;
972 void add_subtitles(char *filename
, float fps
, int silent
)
976 ass_track_t
*asst
= 0;
979 if (filename
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
983 subd
= sub_read_file(filename
, fps
);
987 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
989 asst
= ass_read_file(ass_library
, filename
, 0);
991 if (ass_enabled
&& subd
&& !asst
)
992 asst
= ass_read_subdata(ass_library
, subd
, fps
);
994 if (!asst
&& !subd
&& !silent
)
998 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
,
999 filename_recode(filename
));
1002 if (!asst
&& !subd
) return;
1003 set_of_ass_tracks
[set_of_sub_size
] = asst
;
1007 set_of_subtitles
[set_of_sub_size
] = subd
;
1008 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", set_of_sub_size
);
1009 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
1010 filename_recode(filename
));
1012 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, set_of_sub_size
,
1013 filename_recode(filename
));
1016 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1017 void update_set_of_subtitles(void)
1018 // subdata was changed, set_of_sub... have to be updated.
1021 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
1022 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
1023 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
1024 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
1026 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
1028 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
1029 set_of_subtitles
[set_of_sub_pos
] = subdata
;
1031 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
1032 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
1037 void init_vo_spudec(void) {
1039 spudec_free(vo_spudec
);
1040 inited_flags
&= ~INITED_SPUDEC
;
1043 unsigned int palette
[16], width
, height
;
1044 current_module
="spudec_init_vobsub";
1045 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1046 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1050 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
1051 current_module
="spudec_init_dvdread";
1052 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
1053 sh_video
->disp_w
, sh_video
->disp_h
);
1058 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
1059 unsigned int *palette
= mp_dvdnav_get_spu_clut(stream
);
1060 current_module
="spudec_init_dvdnav";
1061 vo_spudec
=spudec_new_scaled(palette
, sh_video
->disp_w
, sh_video
->disp_h
);
1065 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1066 (d_dvdsub
->sh
!= NULL
) && (((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
1067 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)d_dvdsub
->sh
;
1068 current_module
= "spudec_init_matroska";
1070 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1071 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1072 mkv_sh_sub
->height
);
1073 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1076 if (vo_spudec
==NULL
) {
1077 sh_sub_t
*sh
= (sh_sub_t
*)d_dvdsub
->sh
;
1078 unsigned int *palette
= NULL
;
1079 if (sh
&& sh
->has_palette
)
1080 palette
= sh
->palette
;
1081 current_module
="spudec_init_normal";
1082 vo_spudec
=spudec_new_scaled(palette
, sh_video
->disp_w
, sh_video
->disp_h
);
1083 spudec_set_font_factor(vo_spudec
,font_factor
);
1086 if (vo_spudec
!=NULL
)
1087 inited_flags
|=INITED_SPUDEC
;
1091 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1092 * make it all work is to use the builtin SDL-bootstrap code, which
1093 * will be done automatically by replacing our main() if we include SDL.h.
1095 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1100 * \brief append a formatted string
1101 * \param buf buffer to print into
1102 * \param pos position of terminating 0 in buf
1103 * \param len maximum number of characters in buf, not including terminating 0
1104 * \param format printf format string
1106 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1109 va_start(va
, format
);
1110 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1119 * \brief append time in the hh:mm:ss.f format
1120 * \param buf buffer to print into
1121 * \param pos position of terminating 0 in buf
1122 * \param len maximum number of characters in buf, not including terminating 0
1123 * \param time time value to convert/append
1125 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1126 long tenths
= 10 * time
;
1127 int f1
= tenths
% 10;
1128 int ss
= (tenths
/ 10) % 60;
1129 int mm
= (tenths
/ 600) % 60;
1130 int hh
= tenths
/ 36000;
1132 saddf(buf
, pos
, len
, "unknown");
1136 saddf(buf
, pos
, len
, "%2d:", hh
);
1137 if (hh
> 0 || mm
> 0)
1138 saddf(buf
, pos
, len
, "%02d:", mm
);
1139 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1143 * \brief print the status line
1144 * \param a_pos audio position
1145 * \param a_v A-V desynchronization
1146 * \param corr amount out A-V synchronization
1148 static void print_status(float a_pos
, float a_v
, float corr
)
1154 if (screen_width
> 0)
1155 width
= screen_width
;
1159 /* Windows command line is broken (MinGW's rxvt works, but we
1160 * should not depend on that). */
1163 line
= malloc(width
+ 1); // one additional char for the terminating null
1167 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1169 float len
= demuxer_get_time_length(demuxer
);
1170 saddf(line
, &pos
, width
, "(");
1171 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1172 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1173 sadd_hhmmssf(line
, &pos
, width
, len
);
1174 saddf(line
, &pos
, width
, ") ");
1180 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1183 if (sh_audio
&& sh_video
)
1184 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1188 saddf(line
, &pos
, width
, "%3d/%3d ",
1189 (int)sh_video
->num_frames
,
1190 (int)sh_video
->num_frames_decoded
);
1194 if (sh_video
->timer
> 0.5)
1195 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1196 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
1197 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
1198 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
1200 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1201 } else if (sh_audio
) {
1202 if (sh_audio
->delay
> 0.5)
1203 saddf(line
, &pos
, width
, "%4.1f%% ",
1204 100.0*audio_time_usage
/(double)sh_audio
->delay
);
1206 saddf(line
, &pos
, width
, "??,?%% ");
1211 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1213 #ifdef USE_STREAM_CACHE
1215 if (stream_cache_size
> 0)
1216 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1220 if (playback_speed
!= 1)
1221 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
1224 if (erase_to_end_of_line
) {
1226 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1228 memset(&line
[pos
], ' ', width
- pos
);
1230 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
1236 * \brief build a chain of audio filters that converts the input format
1237 * to the ao's format, taking into account the current playback_speed.
1238 * \param sh_audio describes the requested input format of the chain.
1239 * \param ao_data describes the requested output format of the chain.
1241 static int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1248 guiGetEvent(guiSetAfilter
, (char *)NULL
);
1250 mixer
.afilter
= NULL
;
1253 new_srate
= sh_audio
->samplerate
* playback_speed
;
1254 if (new_srate
!= ao_data
->samplerate
) {
1255 // limits are taken from libaf/af_resample.c
1256 if (new_srate
< 8000)
1258 if (new_srate
> 192000)
1260 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1262 result
= init_audio_filters(sh_audio
, new_srate
,
1263 sh_audio
->channels
, sh_audio
->sample_format
,
1264 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1265 ao_data
->outburst
* 4, ao_data
->buffersize
);
1266 mixer
.afilter
= sh_audio
->afilter
;
1268 guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1274 * \brief Log the currently displayed subtitle to a file
1276 * Logs the current or last displayed subtitle together with filename
1277 * and time information to ~/.mplayer/subtitle_log
1279 * Intended purpose is to allow convenient marking of bogus subtitles
1280 * which need to be fixed while watching the movie.
1283 static void log_sub(void){
1288 if (subdata
== NULL
|| vo_sub_last
== NULL
) return;
1289 fname
= get_path("subtitle_log");
1290 f
= fopen(fname
, "a");
1292 fprintf(f
, "----------------------------------------------------------\n");
1293 if (subdata
->sub_uses_time
) {
1294 fprintf(f
, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename
,
1295 vo_sub_last
->start
/360000, (vo_sub_last
->start
/6000)%60,
1296 (vo_sub_last
->start
/100)%60, vo_sub_last
->start
%100,
1297 vo_sub_last
->end
/360000, (vo_sub_last
->end
/6000)%60,
1298 (vo_sub_last
->end
/100)%60, vo_sub_last
->end
%100);
1300 fprintf(f
, "N: %s S: %ld E: %ld\n", filename
, vo_sub_last
->start
, vo_sub_last
->end
);
1302 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
1303 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
1308 /// \defgroup OSDMsgStack OSD message stack
1312 #define OSD_MSG_TV_CHANNEL 0
1313 #define OSD_MSG_TEXT 1
1314 #define OSD_MSG_SUB_DELAY 2
1315 #define OSD_MSG_SPEED 3
1316 #define OSD_MSG_OSD_STATUS 4
1317 #define OSD_MSG_BAR 5
1318 #define OSD_MSG_PAUSE 6
1319 #define OSD_MSG_RADIO_CHANNEL 7
1320 /// Base id for messages generated from the commmand to property bridge.
1321 #define OSD_MSG_PROPERTY 0x100
1324 typedef struct mp_osd_msg mp_osd_msg_t
;
1326 /// Previous message on the stack.
1330 int id
,level
,started
;
1331 /// Display duration in ms.
1335 /// OSD message stack.
1336 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1339 * \brief Add a message on the OSD message stack
1341 * If a message with the same id is already present in the stack
1342 * it is pulled on top of the stack, otherwise a new message is created.
1346 static void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1347 mp_osd_msg_t
*msg
,*last
=NULL
;
1351 // look if the id is already in the stack
1352 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1353 last
= msg
, msg
= msg
->prev
);
1354 // not found: alloc it
1356 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1357 msg
->prev
= osd_msg_stack
;
1358 osd_msg_stack
= msg
;
1359 } else if(last
) { // found, but it's not on top of the stack
1360 last
->prev
= msg
->prev
;
1361 msg
->prev
= osd_msg_stack
;
1362 osd_msg_stack
= msg
;
1366 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1368 if(r
>= 64) msg
->msg
[63] = 0;
1377 * \brief Remove a message from the OSD stack
1379 * This function can be used to get rid of a message right away.
1383 static void rm_osd_msg(int id
) {
1384 mp_osd_msg_t
*msg
,*last
=NULL
;
1386 // Search for the msg
1387 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1388 last
= msg
, msg
= msg
->prev
);
1391 // Detach it from the stack and free it
1393 last
->prev
= msg
->prev
;
1395 osd_msg_stack
= msg
->prev
;
1400 * \brief Remove all messages from the OSD stack
1404 static void clear_osd_msgs(void) {
1405 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1411 osd_msg_stack
= NULL
;
1415 * \brief Get the current message from the OSD stack.
1417 * This function decrements the message timer and destroys the old ones.
1418 * The message that should be displayed is returned (if any).
1422 static mp_osd_msg_t
* get_osd_msg(void) {
1423 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1424 static unsigned last_update
= 0;
1425 unsigned now
= GetTimerMS();
1427 char hidden_dec_done
= 0;
1429 if(!last_update
) last_update
= now
;
1430 diff
= now
>= last_update
? now
- last_update
: 0;
1434 // Look for the first message in the stack with high enough level.
1435 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1437 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1438 // The message has a high enough level or it is the first hidden one
1439 // in both cases we decrement the timer or kill it.
1440 if(!msg
->started
|| msg
->time
> diff
) {
1441 if(msg
->started
) msg
->time
-= diff
;
1442 else msg
->started
= 1;
1444 if(msg
->level
<= osd_level
) return msg
;
1445 hidden_dec_done
= 1;
1454 osd_msg_stack
= prev
;
1463 * \brief Display the OSD bar.
1465 * Display the OSD bar or fall back on a simple message.
1469 static void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1471 if(osd_level
< 1) return;
1474 osd_visible
= (GetTimerMS() + 1000) | 1;
1475 vo_osd_progbar_type
= type
;
1476 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1477 vo_osd_changed(OSDTYPE_PROGBAR
);
1481 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1482 name
,ROUND(100*(val
-min
)/(max
-min
)));
1487 * \brief Update the OSD message line.
1489 * This function displays the current message on the vo OSD or on the term.
1490 * If the stack is empty and the OSD level is high enough the timer
1491 * is displayed (only on the vo OSD).
1495 static void update_osd_msg(void) {
1497 static char osd_text
[64] = "";
1498 static char osd_text_timer
[64];
1500 // we need some mem for vo_osd_text
1501 vo_osd_text
= (unsigned char*)osd_text
;
1503 // Look if we have a msg
1504 if((msg
= get_osd_msg())) {
1505 if(strcmp(osd_text
,msg
->msg
)) {
1506 strncpy((char*)osd_text
, msg
->msg
, 63);
1507 if(sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1508 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1514 // fallback on the timer
1516 int len
= demuxer_get_time_length(demuxer
);
1517 int percentage
= -1;
1518 char percentage_text
[10];
1519 int pts
= demuxer_get_current_time(demuxer
);
1521 if (osd_show_percentage
)
1522 percentage
= demuxer_get_percent_pos(demuxer
);
1524 if (percentage
>= 0)
1525 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1527 percentage_text
[0] = 0;
1530 snprintf(osd_text_timer
, 63,
1531 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1532 osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1533 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1535 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1536 osd_function
,pts
/3600,(pts
/60)%60,
1537 pts
%60,percentage_text
);
1539 osd_text_timer
[0]=0;
1541 // always decrement the percentage timer
1542 if(osd_show_percentage
)
1543 osd_show_percentage
--;
1545 if(strcmp(osd_text
,osd_text_timer
)) {
1546 strncpy(osd_text
, osd_text_timer
, 63);
1547 vo_osd_changed(OSDTYPE_OSD
);
1552 // Clear the term osd line
1553 if(term_osd
&& osd_text
[0]) {
1555 printf("%s\n",term_osd_esc
);
1562 /// \defgroup Properties
1565 /// \defgroup GeneralProperties General properties
1566 /// \ingroup Properties
1570 static int mp_property_osdlevel(m_option_t
* prop
,int action
,void* arg
) {
1571 return m_property_choice(prop
,action
,arg
,&osd_level
);
1574 /// Playback speed (RW)
1575 static int mp_property_playback_speed(m_option_t
* prop
,int action
,void* arg
) {
1577 case M_PROPERTY_SET
:
1578 if(!arg
) return M_PROPERTY_ERROR
;
1579 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1580 playback_speed
= *(float*)arg
;
1581 build_afilter_chain(sh_audio
, &ao_data
);
1582 return M_PROPERTY_OK
;
1583 case M_PROPERTY_STEP_UP
:
1584 case M_PROPERTY_STEP_DOWN
:
1585 playback_speed
+= (arg
? *(float*)arg
: 0.1) *
1586 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1587 M_PROPERTY_CLAMP(prop
,playback_speed
);
1588 build_afilter_chain(sh_audio
, &ao_data
);
1589 return M_PROPERTY_OK
;
1591 return m_property_float_range(prop
,action
,arg
,&playback_speed
);
1594 /// filename with path (RO)
1595 static int mp_property_path(m_option_t
* prop
,int action
,void* arg
) {
1596 return m_property_string_ro(prop
,action
,arg
,filename
);
1599 /// filename without path (RO)
1600 static int mp_property_filename(m_option_t
* prop
,int action
,void* arg
) {
1602 if(!filename
) return M_PROPERTY_UNAVAILABLE
;
1603 if(((f
= strrchr(filename
,'/')) || (f
= strrchr(filename
,'\\'))) && f
[1])
1607 return m_property_string_ro(prop
,action
,arg
,f
);
1610 /// Demuxer name (RO)
1611 static int mp_property_demuxer(m_option_t
* prop
,int action
,void* arg
) {
1612 if(!demuxer
) return M_PROPERTY_UNAVAILABLE
;
1613 return m_property_string_ro(prop
,action
,arg
,(char*)demuxer
->desc
->name
);
1616 /// Position in the stream (RW)
1617 static int mp_property_stream_pos(m_option_t
* prop
,int action
,void* arg
) {
1618 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1619 if (!arg
) return M_PROPERTY_ERROR
;
1621 case M_PROPERTY_GET
:
1622 *(off_t
*)arg
= stream_tell(demuxer
->stream
);
1623 return M_PROPERTY_OK
;
1624 case M_PROPERTY_SET
:
1625 M_PROPERTY_CLAMP(prop
,*(off_t
*)arg
);
1626 stream_seek(demuxer
->stream
, *(off_t
*)arg
);
1627 return M_PROPERTY_OK
;
1629 return M_PROPERTY_NOT_IMPLEMENTED
;
1632 /// Stream start offset (RO)
1633 static int mp_property_stream_start(m_option_t
* prop
,int action
,void* arg
) {
1634 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1636 case M_PROPERTY_GET
:
1637 *(off_t
*)arg
= demuxer
->stream
->start_pos
;
1638 return M_PROPERTY_OK
;
1640 return M_PROPERTY_NOT_IMPLEMENTED
;
1643 /// Stream end offset (RO)
1644 static int mp_property_stream_end(m_option_t
* prop
,int action
,void* arg
) {
1645 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1647 case M_PROPERTY_GET
:
1648 *(off_t
*)arg
= demuxer
->stream
->end_pos
;
1649 return M_PROPERTY_OK
;
1651 return M_PROPERTY_NOT_IMPLEMENTED
;
1654 /// Stream length (RO)
1655 static int mp_property_stream_length(m_option_t
* prop
,int action
,void* arg
) {
1656 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1658 case M_PROPERTY_GET
:
1659 *(off_t
*)arg
= demuxer
->stream
->end_pos
- demuxer
->stream
->start_pos
;
1660 return M_PROPERTY_OK
;
1662 return M_PROPERTY_NOT_IMPLEMENTED
;
1665 /// Media length in seconds (RO)
1666 static int mp_property_length(m_option_t
* prop
,int action
,void* arg
) {
1670 !(int)(len
= demuxer_get_time_length(demuxer
)))
1671 return M_PROPERTY_UNAVAILABLE
;
1674 case M_PROPERTY_PRINT
:
1675 if(!arg
) return M_PROPERTY_ERROR
;
1682 *(char**)arg
= malloc(20);
1683 if(h
> 0) sprintf(*(char**)arg
,"%d:%02d:%02d",h
,m
,s
);
1684 else if(m
> 0) sprintf(*(char**)arg
,"%d:%02d",m
,s
);
1685 else sprintf(*(char**)arg
,"%d",s
);
1686 return M_PROPERTY_OK
;
1690 return m_property_double_ro(prop
,action
,arg
,len
);
1695 /// \defgroup AudioProperties Audio properties
1696 /// \ingroup Properties
1700 static int mp_property_volume(m_option_t
* prop
,int action
,void* arg
) {
1702 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1705 case M_PROPERTY_GET
:
1706 if(!arg
) return M_PROPERTY_ERROR
;
1707 mixer_getbothvolume(&mixer
,arg
);
1708 return M_PROPERTY_OK
;
1709 case M_PROPERTY_PRINT
:{
1711 if(!arg
) return M_PROPERTY_ERROR
;
1712 mixer_getbothvolume(&mixer
,&vol
);
1713 return m_property_float_range(prop
,action
,arg
,&vol
);
1715 case M_PROPERTY_STEP_UP
:
1716 case M_PROPERTY_STEP_DOWN
:
1717 case M_PROPERTY_SET
:
1720 return M_PROPERTY_NOT_IMPLEMENTED
;
1723 if (edl_muted
) return M_PROPERTY_DISABLED
;
1727 case M_PROPERTY_SET
:
1728 if(!arg
) return M_PROPERTY_ERROR
;
1729 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1730 mixer_setvolume(&mixer
,*(float*)arg
,*(float*)arg
);
1731 return M_PROPERTY_OK
;
1732 case M_PROPERTY_STEP_UP
:
1733 if(arg
&& *(float*)arg
<= 0)
1734 mixer_decvolume(&mixer
);
1736 mixer_incvolume(&mixer
);
1737 return M_PROPERTY_OK
;
1738 case M_PROPERTY_STEP_DOWN
:
1739 if(arg
&& *(float*)arg
<= 0)
1740 mixer_incvolume(&mixer
);
1742 mixer_decvolume(&mixer
);
1743 return M_PROPERTY_OK
;
1745 return M_PROPERTY_NOT_IMPLEMENTED
;
1749 static int mp_property_mute(m_option_t
* prop
,int action
,void* arg
) {
1751 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1754 case M_PROPERTY_SET
:
1755 if(edl_muted
) return M_PROPERTY_DISABLED
;
1756 if(!arg
) return M_PROPERTY_ERROR
;
1757 if((!!*(int*)arg
) != mixer
.muted
)
1759 user_muted
= mixer
.muted
;
1760 return M_PROPERTY_OK
;
1761 case M_PROPERTY_STEP_UP
:
1762 case M_PROPERTY_STEP_DOWN
:
1763 if(edl_muted
) return M_PROPERTY_DISABLED
;
1765 user_muted
= mixer
.muted
;
1766 return M_PROPERTY_OK
;
1767 case M_PROPERTY_PRINT
:
1768 if(!arg
) return M_PROPERTY_ERROR
;
1770 *(char**)arg
= strdup(MSGTR_EnabledEdl
);
1771 return M_PROPERTY_OK
;
1774 return m_property_flag(prop
,action
,arg
,&mixer
.muted
);
1779 /// Audio delay (RW)
1780 static int mp_property_audio_delay(m_option_t
* prop
,int action
,void* arg
) {
1781 if(!(sh_audio
&& sh_video
)) return M_PROPERTY_UNAVAILABLE
;
1783 case M_PROPERTY_SET
:
1784 case M_PROPERTY_STEP_UP
:
1785 case M_PROPERTY_STEP_DOWN
:
1786 if(!arg
) return M_PROPERTY_ERROR
;
1788 float delay
= audio_delay
;
1789 m_property_delay(prop
,action
,arg
,&audio_delay
);
1790 if(sh_audio
) sh_audio
->delay
-= audio_delay
-delay
;
1792 return M_PROPERTY_OK
;
1794 return m_property_delay(prop
,action
,arg
,&audio_delay
);
1798 /// Audio codec tag (RO)
1799 static int mp_property_audio_format(m_option_t
* prop
,int action
,void* arg
) {
1800 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1801 return m_property_int_ro(prop
,action
,arg
,sh_audio
->format
);
1804 /// Audio bitrate (RO)
1805 static int mp_property_audio_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1806 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1807 return m_property_int_ro(prop
,action
,arg
,sh_audio
->i_bps
);
1811 static int mp_property_samplerate(m_option_t
* prop
,int action
,void* arg
) {
1812 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1813 return m_property_int_ro(prop
,action
,arg
,sh_audio
->samplerate
);
1816 /// Number of channels (RO)
1817 static int mp_property_channels(m_option_t
* prop
,int action
,void* arg
) {
1818 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1820 case M_PROPERTY_PRINT
:
1821 if(!arg
) return M_PROPERTY_ERROR
;
1822 switch(sh_audio
->channels
) {
1823 case 1: *(char**)arg
= strdup("mono"); break;
1824 case 2: *(char**)arg
= strdup("stereo"); break;
1826 *(char**)arg
= malloc(32);
1827 sprintf(*(char**)arg
,"%d channels",sh_audio
->channels
);
1829 return M_PROPERTY_OK
;
1831 return m_property_int_ro(prop
,action
,arg
,sh_audio
->channels
);
1834 /// Selected audio id (RW)
1835 static int mp_property_audio(m_option_t
* prop
,int action
,void* arg
) {
1836 int current_id
= -1, tmp
;
1839 case M_PROPERTY_GET
:
1840 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1841 if(!arg
) return M_PROPERTY_ERROR
;
1842 *(int*)arg
= audio_id
;
1843 return M_PROPERTY_OK
;
1844 case M_PROPERTY_PRINT
:
1845 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1846 if(!arg
) return M_PROPERTY_ERROR
;
1849 *(char**)arg
= strdup(MSGTR_Disabled
);
1851 char lang
[40] = MSGTR_Unknown
;
1852 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
)
1853 demux_mkv_get_audio_lang(demuxer
, audio_id
, lang
, 9);
1855 else if(stream
->type
== STREAMTYPE_DVD
) {
1856 int code
= dvd_lang_from_aid(stream
, audio_id
);
1858 lang
[0] = code
>> 8;
1866 else if(stream
->type
== STREAMTYPE_DVDNAV
)
1867 dvdnav_lang_from_aid(stream
, audio_id
, lang
);
1869 *(char**)arg
= malloc(64);
1870 snprintf(*(char**)arg
, 64, "(%d) %s", audio_id
, lang
);
1872 return M_PROPERTY_OK
;
1874 case M_PROPERTY_STEP_UP
:
1875 case M_PROPERTY_SET
:
1876 if(action
==M_PROPERTY_SET
&& arg
)
1880 current_id
= demuxer
->audio
->id
;
1881 audio_id
= demuxer_switch_audio(demuxer
, tmp
);
1882 if(audio_id
== -2 || (audio_id
> -1 && demuxer
->audio
->id
!= current_id
&& current_id
!= -2))
1883 uninit_player(INITED_AO
| INITED_ACODEC
);
1884 if(audio_id
> -1 && demuxer
->audio
->id
!= current_id
) {
1886 sh2
= demuxer
->a_streams
[demuxer
->audio
->id
];
1888 sh2
->ds
= demuxer
->audio
;
1890 reinit_audio_chain();
1893 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", audio_id
);
1894 return M_PROPERTY_OK
;
1896 return M_PROPERTY_NOT_IMPLEMENTED
;
1901 static int reinit_video_chain(void);
1902 /// Selected video id (RW)
1903 static int mp_property_video(m_option_t
* prop
,int action
,void* arg
) {
1904 int current_id
= -1, tmp
;
1907 case M_PROPERTY_GET
:
1908 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1909 if(!arg
) return M_PROPERTY_ERROR
;
1910 *(int*)arg
= video_id
;
1911 return M_PROPERTY_OK
;
1912 case M_PROPERTY_PRINT
:
1913 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1914 if(!arg
) return M_PROPERTY_ERROR
;
1917 *(char**)arg
= strdup(MSGTR_Disabled
);
1919 char lang
[40] = MSGTR_Unknown
;
1920 *(char**)arg
= malloc(64);
1921 snprintf(*(char**)arg
, 64, "(%d) %s", video_id
, lang
);
1923 return M_PROPERTY_OK
;
1925 case M_PROPERTY_STEP_UP
:
1926 case M_PROPERTY_SET
:
1927 current_id
= demuxer
->video
->id
;
1928 if(action
==M_PROPERTY_SET
&& arg
)
1932 video_id
= demuxer_switch_video(demuxer
, tmp
);
1933 if(video_id
== -2 || (video_id
> -1 && demuxer
->video
->id
!= current_id
&& current_id
!= -2))
1934 uninit_player(INITED_VCODEC
| (fixed_vo
&& video_id
!= -2 ? 0 : INITED_VO
));
1935 if(video_id
> -1 && demuxer
->video
->id
!= current_id
) {
1937 sh2
= demuxer
->v_streams
[demuxer
->video
->id
];
1939 sh2
->ds
= demuxer
->video
;
1941 reinit_video_chain();
1944 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_TRACK=%d\n", video_id
);
1945 return M_PROPERTY_OK
;
1948 return M_PROPERTY_NOT_IMPLEMENTED
;
1952 static int mp_property_program(m_option_t
* prop
,int action
,void* arg
) {
1953 demux_program_t prog
;
1956 case M_PROPERTY_STEP_UP
:
1957 case M_PROPERTY_SET
:
1958 if(action
==M_PROPERTY_SET
&& arg
)
1959 prog
.progid
= *((int*)arg
);
1962 if(demux_control(demuxer
, DEMUXER_CTRL_IDENTIFY_PROGRAM
, &prog
) == DEMUXER_CTRL_NOTIMPL
)
1963 return M_PROPERTY_ERROR
;
1965 mp_property_do("switch_audio", M_PROPERTY_SET
, &prog
.aid
);
1966 mp_property_do("switch_video", M_PROPERTY_SET
, &prog
.vid
);
1967 return M_PROPERTY_OK
;
1970 return M_PROPERTY_NOT_IMPLEMENTED
;
1976 /// \defgroup VideoProperties Video properties
1977 /// \ingroup Properties
1980 /// Fullscreen state (RW)
1981 static int mp_property_fullscreen(m_option_t
* prop
,int action
,void* arg
) {
1983 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1986 case M_PROPERTY_SET
:
1987 if(!arg
) return M_PROPERTY_ERROR
;
1988 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1989 if(vo_fs
== !!*(int*)arg
) return M_PROPERTY_OK
;
1990 case M_PROPERTY_STEP_UP
:
1991 case M_PROPERTY_STEP_DOWN
:
1993 if(use_gui
) guiGetEvent(guiIEvent
,(char*)MP_CMD_GUI_FULLSCREEN
);
1996 if(vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
1997 return M_PROPERTY_OK
;
1999 return m_property_flag(prop
,action
,arg
,&vo_fs
);
2003 static int mp_property_deinterlace(m_option_t
* prop
,int action
,void* arg
) {
2006 if (!sh_video
|| !sh_video
->vfilter
) return M_PROPERTY_UNAVAILABLE
;
2007 vf
= sh_video
->vfilter
;
2009 case M_PROPERTY_GET
:
2010 if(!arg
) return M_PROPERTY_ERROR
;
2011 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, arg
);
2012 return M_PROPERTY_OK
;
2013 case M_PROPERTY_SET
:
2014 if(!arg
) return M_PROPERTY_ERROR
;
2015 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2016 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, arg
);
2017 return M_PROPERTY_OK
;
2018 case M_PROPERTY_STEP_UP
:
2019 case M_PROPERTY_STEP_DOWN
:
2020 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, &deinterlace
);
2021 deinterlace
= !deinterlace
;
2022 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, &deinterlace
);
2023 return M_PROPERTY_OK
;
2025 return M_PROPERTY_NOT_IMPLEMENTED
;
2029 static int mp_property_panscan(m_option_t
* prop
,int action
,void* arg
) {
2031 if(!video_out
|| video_out
->control(VOCTRL_GET_PANSCAN
,NULL
) != VO_TRUE
)
2032 return M_PROPERTY_UNAVAILABLE
;
2035 case M_PROPERTY_SET
:
2036 if(!arg
) return M_PROPERTY_ERROR
;
2037 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
2038 vo_panscan
= *(float*)arg
;
2039 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
2040 return M_PROPERTY_OK
;
2041 case M_PROPERTY_STEP_UP
:
2042 case M_PROPERTY_STEP_DOWN
:
2043 vo_panscan
+= (arg
? *(float*)arg
: 0.1) *
2044 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2045 if(vo_panscan
> 1) vo_panscan
= 1;
2046 else if(vo_panscan
< 0) vo_panscan
= 0;
2047 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
2048 return M_PROPERTY_OK
;
2050 return m_property_float_range(prop
,action
,arg
,&vo_panscan
);
2054 /// Helper to set vo flags.
2055 /** \ingroup PropertyImplHelper
2057 static int mp_property_vo_flag(m_option_t
* prop
,int action
,void* arg
,
2058 int vo_ctrl
,int* vo_var
) {
2060 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
2063 case M_PROPERTY_SET
:
2064 if(!arg
) return M_PROPERTY_ERROR
;
2065 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2066 if(*vo_var
== !!*(int*)arg
) return M_PROPERTY_OK
;
2067 case M_PROPERTY_STEP_UP
:
2068 case M_PROPERTY_STEP_DOWN
:
2069 if(vo_config_count
) video_out
->control(vo_ctrl
, 0);
2070 return M_PROPERTY_OK
;
2072 return m_property_flag(prop
,action
,arg
,vo_var
);
2076 /// Window always on top (RW)
2077 static int mp_property_ontop(m_option_t
* prop
,int action
,void* arg
) {
2078 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ONTOP
,&vo_ontop
);
2081 /// Display in the root window (RW)
2082 static int mp_property_rootwin(m_option_t
* prop
,int action
,void* arg
) {
2083 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ROOTWIN
,&vo_rootwin
);
2086 /// Show window borders (RW)
2087 static int mp_property_border(m_option_t
* prop
,int action
,void* arg
) {
2088 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_BORDER
,&vo_border
);
2091 /// Framedropping state (RW)
2092 static int mp_property_framedropping(m_option_t
* prop
,int action
,void* arg
) {
2094 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2097 case M_PROPERTY_PRINT
:
2098 if(!arg
) return M_PROPERTY_ERROR
;
2099 *(char**)arg
= strdup(frame_dropping
== 1 ? MSGTR_Enabled
:
2100 (frame_dropping
== 2 ? MSGTR_HardFrameDrop
: MSGTR_Disabled
));
2101 return M_PROPERTY_OK
;
2103 return m_property_choice(prop
,action
,arg
,&frame_dropping
);
2107 /// Color settings, try to use vf/vo then fall back on TV. (RW)
2108 static int mp_property_gamma(m_option_t
* prop
,int action
,void* arg
) {
2109 int* gamma
= prop
->priv
, r
;
2111 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2113 if(gamma
[0] == 1000) {
2115 get_video_colors (sh_video
, prop
->name
, gamma
);
2119 case M_PROPERTY_SET
:
2120 if(!arg
) return M_PROPERTY_ERROR
;
2121 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2122 *gamma
= *(int*)arg
;
2123 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
2126 case M_PROPERTY_GET
:
2127 if(!arg
) return M_PROPERTY_ERROR
;
2128 r
= get_video_colors (sh_video
, prop
->name
, arg
);
2131 case M_PROPERTY_STEP_UP
:
2132 case M_PROPERTY_STEP_DOWN
:
2133 *gamma
+= (arg
? *(int*)arg
: 1) *
2134 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2135 M_PROPERTY_CLAMP(prop
,*gamma
);
2136 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
2140 return M_PROPERTY_NOT_IMPLEMENTED
;
2144 if(demuxer
->type
== DEMUXER_TYPE_TV
) {
2145 int l
= strlen(prop
->name
);
2146 char tv_prop
[3+l
+1];
2147 sprintf(tv_prop
,"tv_%s",prop
->name
);
2148 return mp_property_do(tv_prop
,action
,arg
);
2152 return M_PROPERTY_UNAVAILABLE
;
2156 static int mp_property_vsync(m_option_t
* prop
,int action
,void* arg
) {
2157 return m_property_flag(prop
,action
,arg
,&vo_vsync
);
2160 /// Video codec tag (RO)
2161 static int mp_property_video_format(m_option_t
* prop
,int action
,void* arg
) {
2162 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2163 return m_property_int_ro(prop
,action
,arg
,sh_video
->format
);
2166 /// Video bitrate (RO)
2167 static int mp_property_video_bitrate(m_option_t
* prop
,int action
,void* arg
) {
2168 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2169 return m_property_int_ro(prop
,action
,arg
,sh_video
->i_bps
);
2172 /// Video display width (RO)
2173 static int mp_property_width(m_option_t
* prop
,int action
,void* arg
) {
2174 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2175 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_w
);
2178 /// Video display height (RO)
2179 static int mp_property_height(m_option_t
* prop
,int action
,void* arg
) {
2180 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2181 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_h
);
2185 static int mp_property_fps(m_option_t
* prop
,int action
,void* arg
) {
2186 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2187 return m_property_float_ro(prop
,action
,arg
,sh_video
->fps
);
2190 /// Video aspect (RO)
2191 static int mp_property_aspect(m_option_t
* prop
,int action
,void* arg
) {
2192 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2193 return m_property_float_ro(prop
,action
,arg
,sh_video
->aspect
);
2198 /// \defgroup SubProprties Subtitles properties
2199 /// \ingroup Properties
2202 /// Text subtitle position (RW)
2203 static int mp_property_sub_pos(m_option_t
* prop
,int action
,void* arg
) {
2204 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2207 case M_PROPERTY_SET
:
2208 if(!arg
) return M_PROPERTY_ERROR
;
2209 case M_PROPERTY_STEP_UP
:
2210 case M_PROPERTY_STEP_DOWN
:
2211 vo_osd_changed(OSDTYPE_SUBTITLE
);
2213 return m_property_int_range(prop
,action
,arg
,&sub_pos
);
2217 /// Selected subtitles (RW)
2218 static int mp_property_sub(m_option_t
* prop
,int action
,void* arg
) {
2219 int source
= -1, reset_spu
= 0;
2222 if(global_sub_size
<= 0) return M_PROPERTY_UNAVAILABLE
;
2225 case M_PROPERTY_GET
:
2226 if(!arg
) return M_PROPERTY_ERROR
;
2227 *(int*)arg
= global_sub_pos
;
2228 return M_PROPERTY_OK
;
2229 case M_PROPERTY_PRINT
:
2230 if(!arg
) return M_PROPERTY_ERROR
;
2231 *(char**)arg
= malloc(64);
2232 (*(char**)arg
)[63] = 0;
2235 sub_name
= subdata
->filename
;
2237 if (ass_track
&& ass_track
->name
)
2238 sub_name
= ass_track
->name
;
2243 if ((tmp2
= strrchr(tmp
, '/')))
2246 snprintf(*(char**)arg
, 63, "(%d) %s%s",
2248 strlen(tmp
) < 20 ? "" : "...",
2249 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
2250 return M_PROPERTY_OK
;
2254 if(stream
->type
==STREAMTYPE_DVDNAV
) {
2255 if(vo_spudec
&& dvdsub_id
>= 0) {
2256 unsigned char lang
[3];
2257 if(dvdnav_lang_from_sid(stream
, dvdsub_id
, lang
)) {
2258 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
2259 return M_PROPERTY_OK
;
2265 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
&& dvdsub_id
>= 0) {
2266 char lang
[40] = MSGTR_Unknown
;
2267 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
2268 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
2269 return M_PROPERTY_OK
;
2271 #ifdef HAVE_OGGVORBIS
2272 if (demuxer
->type
== DEMUXER_TYPE_OGG
&& d_dvdsub
&& dvdsub_id
>= 0) {
2273 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
2274 if (!lang
) lang
= MSGTR_Unknown
;
2275 snprintf(*(char**)arg
, 63, "(%d) %s",
2277 return M_PROPERTY_OK
;
2280 if (vo_vobsub
&& vobsub_id
>= 0) {
2281 const char *language
= MSGTR_Unknown
;
2282 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
2283 snprintf(*(char**)arg
, 63, "(%d) %s",
2284 vobsub_id
, language
? language
: MSGTR_Unknown
);
2285 return M_PROPERTY_OK
;
2288 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
&& dvdsub_id
>= 0) {
2290 int code
= dvd_lang_from_sid(stream
, dvdsub_id
);
2291 lang
[0] = code
>> 8;
2294 snprintf(*(char**)arg
, 63, "(%d) %s",
2296 return M_PROPERTY_OK
;
2299 if (dvdsub_id
>= 0) {
2300 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, MSGTR_Unknown
);
2301 return M_PROPERTY_OK
;
2303 snprintf(*(char**)arg
, 63, MSGTR_Disabled
);
2304 return M_PROPERTY_OK
;
2306 case M_PROPERTY_SET
:
2307 if(!arg
) return M_PROPERTY_ERROR
;
2308 if(*(int*)arg
< -1) *(int*)arg
= -1;
2309 else if(*(int*)arg
>= global_sub_size
) *(int*)arg
= global_sub_size
-1;
2310 global_sub_pos
= *(int*)arg
;
2312 case M_PROPERTY_STEP_UP
:
2313 global_sub_pos
+= 2;
2314 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2316 case M_PROPERTY_STEP_DOWN
:
2317 global_sub_pos
+= global_sub_size
+1;
2318 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2321 return M_PROPERTY_NOT_IMPLEMENTED
;
2324 if (global_sub_pos
>= 0)
2325 source
= sub_source();
2327 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
,
2328 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
2329 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
2330 global_sub_indices
[SUB_SOURCE_SUBS
],
2331 global_sub_indices
[SUB_SOURCE_DEMUX
],
2332 global_sub_pos
, source
);
2334 set_of_sub_pos
= -1;
2336 vo_sub_last
= vo_sub
= NULL
;
2341 if(d_dvdsub
->id
> -2) reset_spu
= 1;
2348 if (source
== SUB_SOURCE_VOBSUB
) {
2349 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
2350 } else if (source
== SUB_SOURCE_SUBS
) {
2351 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
2353 if (ass_enabled
&& set_of_ass_tracks
[set_of_sub_pos
])
2354 ass_track
= set_of_ass_tracks
[set_of_sub_pos
];
2358 subdata
= set_of_subtitles
[set_of_sub_pos
];
2359 vo_osd_changed(OSDTYPE_SUBTITLE
);
2361 } else if (source
== SUB_SOURCE_DEMUX
) {
2362 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
2365 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
2366 d_dvdsub
->id
= dvdsub_id
;
2367 spudec_reset(vo_spudec
);
2372 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVDNAV
) {
2373 d_dvdsub
->id
= dvdsub_id
;
2374 spudec_reset(vo_spudec
);
2377 if (stream
->type
!= STREAMTYPE_DVD
&& stream
->type
!= STREAMTYPE_DVDNAV
) {
2379 for (d_dvdsub
->id
= 0; d_dvdsub
->id
< MAX_S_STREAMS
; d_dvdsub
->id
++) {
2380 if (demuxer
->s_streams
[d_dvdsub
->id
]) {
2381 if (i
== dvdsub_id
) break;
2385 d_dvdsub
->sh
= demuxer
->s_streams
[d_dvdsub
->id
];
2387 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
2388 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
2390 if (d_dvdsub
->sh
&& d_dvdsub
->id
>= 0) {
2391 sh_sub_t
*sh
= d_dvdsub
->sh
;
2392 if (sh
->type
== 'v')
2395 else if (ass_enabled
&& sh
->type
== 'a')
2396 ass_track
= sh
->ass_track
;
2401 vo_osd_changed(OSDTYPE_SUBTITLE
);
2402 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2405 if (vo_spudec
&& (stream
->type
== STREAMTYPE_DVD
|| stream
->type
== STREAMTYPE_DVDNAV
) && dvdsub_id
< 0 && reset_spu
) {
2407 d_dvdsub
->id
= dvdsub_id
;
2408 spudec_reset(vo_spudec
);
2412 return M_PROPERTY_OK
;
2415 /// Subtitle delay (RW)
2416 static int mp_property_sub_delay(m_option_t
* prop
,int action
,void* arg
) {
2417 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2418 return m_property_delay(prop
,action
,arg
,&sub_delay
);
2421 /// Alignment of text subtitles (RW)
2422 static int mp_property_sub_alignment(m_option_t
* prop
,int action
,void* arg
) {
2423 char* name
[] = { MSGTR_Top
, MSGTR_Center
, MSGTR_Bottom
};
2425 if(!sh_video
|| global_sub_pos
< 0 || sub_source() != SUB_SOURCE_SUBS
)
2426 return M_PROPERTY_UNAVAILABLE
;
2429 case M_PROPERTY_PRINT
:
2430 if(!arg
) return M_PROPERTY_ERROR
;
2431 M_PROPERTY_CLAMP(prop
,sub_alignment
);
2432 *(char**)arg
= strdup(name
[sub_alignment
]);
2433 return M_PROPERTY_OK
;
2434 case M_PROPERTY_SET
:
2435 if(!arg
) return M_PROPERTY_ERROR
;
2436 case M_PROPERTY_STEP_UP
:
2437 case M_PROPERTY_STEP_DOWN
:
2438 vo_osd_changed(OSDTYPE_SUBTITLE
);
2440 return m_property_choice(prop
,action
,arg
,&sub_alignment
);
2444 /// Subtitle visibility (RW)
2445 static int mp_property_sub_visibility(m_option_t
* prop
,int action
,void* arg
) {
2446 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2449 case M_PROPERTY_SET
:
2450 if(!arg
) return M_PROPERTY_ERROR
;
2451 case M_PROPERTY_STEP_UP
:
2452 case M_PROPERTY_STEP_DOWN
:
2453 vo_osd_changed(OSDTYPE_SUBTITLE
);
2454 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2456 return m_property_flag(prop
,action
,arg
,&sub_visibility
);
2460 /// Show only forced subtitles (RW)
2461 static int mp_property_sub_forced_only(m_option_t
* prop
,int action
,void* arg
) {
2462 if(!vo_spudec
) return M_PROPERTY_UNAVAILABLE
;
2465 case M_PROPERTY_SET
:
2466 if(!arg
) return M_PROPERTY_ERROR
;
2467 case M_PROPERTY_STEP_UP
:
2468 case M_PROPERTY_STEP_DOWN
:
2469 m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2470 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
2471 return M_PROPERTY_OK
;
2473 return m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2480 /// \defgroup TVProperties TV properties
2481 /// \ingroup Properties
2486 /// TV color settings (RW)
2487 static int mp_property_tv_color(m_option_t
* prop
,int action
,void* arg
) {
2489 tvi_handle_t
* tvh
= demuxer
->priv
;
2490 if(demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
) return M_PROPERTY_UNAVAILABLE
;
2493 case M_PROPERTY_SET
:
2494 if(!arg
) return M_PROPERTY_ERROR
;
2495 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2496 return tv_set_color_options(tvh
,(int)prop
->priv
,*(int*)arg
);
2497 case M_PROPERTY_GET
:
2498 return tv_get_color_options(tvh
,(int)prop
->priv
,arg
);
2499 case M_PROPERTY_STEP_UP
:
2500 case M_PROPERTY_STEP_DOWN
:
2501 if((r
= tv_get_color_options(tvh
,(int)prop
->priv
,&val
)) >= 0) {
2502 if(!r
) return M_PROPERTY_ERROR
;
2503 val
+= (arg
? *(int*)arg
: 1) *
2504 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2505 M_PROPERTY_CLAMP(prop
,val
);
2506 return tv_set_color_options(tvh
,(int)prop
->priv
,val
);
2508 return M_PROPERTY_ERROR
;
2510 return M_PROPERTY_NOT_IMPLEMENTED
;
2517 /// All properties available in MPlayer.
2518 /** \ingroup Properties
2520 static m_option_t mp_properties
[] = {
2522 { "osdlevel", mp_property_osdlevel
, CONF_TYPE_INT
,
2523 M_OPT_RANGE
, 0, 3, NULL
},
2524 { "speed", mp_property_playback_speed
, CONF_TYPE_FLOAT
,
2525 M_OPT_RANGE
, 0.01, 100.0, NULL
},
2526 { "filename", mp_property_filename
, CONF_TYPE_STRING
,
2528 { "path", mp_property_path
, CONF_TYPE_STRING
,
2530 { "demuxer", mp_property_demuxer
, CONF_TYPE_STRING
,
2532 { "stream_pos", mp_property_stream_pos
, CONF_TYPE_POSITION
,
2533 M_OPT_MIN
, 0, 0, NULL
},
2534 { "stream_start", mp_property_stream_start
, CONF_TYPE_POSITION
,
2535 M_OPT_MIN
, 0, 0, NULL
},
2536 { "stream_end", mp_property_stream_end
, CONF_TYPE_POSITION
,
2537 M_OPT_MIN
, 0, 0, NULL
},
2538 { "stream_length", mp_property_stream_length
, CONF_TYPE_POSITION
,
2539 M_OPT_MIN
, 0, 0, NULL
},
2540 { "length", mp_property_length
, CONF_TYPE_DOUBLE
,
2544 { "volume", mp_property_volume
, CONF_TYPE_FLOAT
,
2545 M_OPT_RANGE
, 0, 100, NULL
},
2546 { "mute", mp_property_mute
, CONF_TYPE_FLAG
,
2547 M_OPT_RANGE
, 0, 1, NULL
},
2548 { "audio_delay", mp_property_audio_delay
, CONF_TYPE_FLOAT
,
2549 M_OPT_RANGE
, -100, 100, NULL
},
2550 { "audio_format", mp_property_audio_format
, CONF_TYPE_INT
,
2552 { "audio_bitrate", mp_property_audio_bitrate
, CONF_TYPE_INT
,
2554 { "samplerate", mp_property_samplerate
, CONF_TYPE_INT
,
2556 { "channels", mp_property_channels
, CONF_TYPE_INT
,
2558 { "switch_audio", mp_property_audio
, CONF_TYPE_INT
,
2559 CONF_RANGE
, -2, MAX_A_STREAMS
-1, NULL
},
2562 { "fullscreen", mp_property_fullscreen
, CONF_TYPE_FLAG
,
2563 M_OPT_RANGE
, 0, 1, NULL
},
2564 { "deinterlace", mp_property_deinterlace
, CONF_TYPE_FLAG
,
2565 M_OPT_RANGE
, 0, 1, NULL
},
2566 { "ontop", mp_property_ontop
, CONF_TYPE_FLAG
,
2567 M_OPT_RANGE
, 0, 1, NULL
},
2568 { "rootwin", mp_property_rootwin
, CONF_TYPE_FLAG
,
2569 M_OPT_RANGE
, 0, 1, NULL
},
2570 { "border", mp_property_border
, CONF_TYPE_FLAG
,
2571 M_OPT_RANGE
, 0, 1, NULL
},
2572 { "framedropping", mp_property_framedropping
, CONF_TYPE_INT
,
2573 M_OPT_RANGE
, 0, 2, NULL
},
2574 { "gamma", mp_property_gamma
, CONF_TYPE_INT
,
2575 M_OPT_RANGE
, -100, 100, &vo_gamma_gamma
},
2576 { "brightness", mp_property_gamma
, CONF_TYPE_INT
,
2577 M_OPT_RANGE
, -100, 100, &vo_gamma_brightness
},
2578 { "contrast", mp_property_gamma
, CONF_TYPE_INT
,
2579 M_OPT_RANGE
, -100, 100, &vo_gamma_contrast
},
2580 { "saturation", mp_property_gamma
, CONF_TYPE_INT
,
2581 M_OPT_RANGE
, -100, 100, &vo_gamma_saturation
},
2582 { "hue", mp_property_gamma
, CONF_TYPE_INT
,
2583 M_OPT_RANGE
, -100, 100, &vo_gamma_hue
},
2584 { "panscan", mp_property_panscan
, CONF_TYPE_FLOAT
,
2585 M_OPT_RANGE
, 0, 1, NULL
},
2586 { "vsync", mp_property_vsync
, CONF_TYPE_FLAG
,
2587 M_OPT_RANGE
, 0, 1, NULL
},
2588 { "video_format", mp_property_video_format
, CONF_TYPE_INT
,
2590 { "video_bitrate", mp_property_video_bitrate
, CONF_TYPE_INT
,
2592 { "width", mp_property_width
, CONF_TYPE_INT
,
2594 { "height", mp_property_height
, CONF_TYPE_INT
,
2596 { "fps", mp_property_fps
, CONF_TYPE_FLOAT
,
2598 { "aspect", mp_property_aspect
, CONF_TYPE_FLOAT
,
2600 { "switch_video", mp_property_video
, CONF_TYPE_INT
,
2601 CONF_RANGE
, -2, MAX_V_STREAMS
-1, NULL
},
2602 { "switch_program", mp_property_program
, CONF_TYPE_INT
,
2603 CONF_RANGE
, -1, 65535, NULL
},
2606 { "sub", mp_property_sub
, CONF_TYPE_INT
,
2607 M_OPT_MIN
, -1, 0, NULL
},
2608 { "sub_delay", mp_property_sub_delay
, CONF_TYPE_FLOAT
,
2610 { "sub_pos", mp_property_sub_pos
, CONF_TYPE_INT
,
2611 M_OPT_RANGE
, 0, 100, NULL
},
2612 { "sub_alignment", mp_property_sub_alignment
, CONF_TYPE_INT
,
2613 M_OPT_RANGE
, 0, 2, NULL
},
2614 { "sub_visibility", mp_property_sub_visibility
, CONF_TYPE_FLAG
,
2615 M_OPT_RANGE
, 0, 1, NULL
},
2616 { "sub_forced_only", mp_property_sub_forced_only
, CONF_TYPE_FLAG
,
2617 M_OPT_RANGE
, 0, 1, NULL
},
2620 { "tv_brightness", mp_property_tv_color
, CONF_TYPE_INT
,
2621 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_BRIGHTNESS
},
2622 { "tv_contrast", mp_property_tv_color
, CONF_TYPE_INT
,
2623 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_CONTRAST
},
2624 { "tv_saturation", mp_property_tv_color
, CONF_TYPE_INT
,
2625 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_SATURATION
},
2626 { "tv_hue", mp_property_tv_color
, CONF_TYPE_INT
,
2627 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_HUE
},
2630 { NULL
, NULL
, NULL
, 0, 0, 0, NULL
}
2633 m_option_t
* mp_property_find(const char* name
) {
2634 return m_option_list_find(mp_properties
,name
);
2637 int mp_property_do(const char* name
,int action
, void* val
) {
2638 m_option_t
* p
= mp_property_find(name
);
2639 if(!p
) return M_PROPERTY_UNAVAILABLE
;
2640 return m_property_do(p
,action
,val
);
2648 * \defgroup Command2Property Command to property bridge
2650 * It is used to handle most commands that just set a property
2651 * and optionally display something on the OSD.
2652 * Two kinds of commands are handled: adjust or toggle.
2654 * Adjust commands take 1 or 2 parameters: <value> <abs>
2655 * If <abs> is non-zero the property is set to the given value
2656 * otherwise it is adjusted.
2658 * Toggle commands take 0 or 1 parameters. With no parameter
2659 * or a value less than the property minimum it just steps the
2660 * property to its next value. Otherwise it sets it to the given
2666 /// List of the commands that can be handled by setting a property.
2672 /// set/adjust or toggle command
2674 /// progressbar type
2676 /// osd msg id if it must be shared
2678 /// osd msg template
2679 const char* osd_msg
;
2680 } set_prop_cmd
[] = {
2682 { "volume", MP_CMD_VOLUME
, 0, OSD_VOLUME
, -1, MSGTR_Volume
},
2683 { "mute", MP_CMD_MUTE
, 1, 0, -1, MSGTR_MuteStatus
},
2684 { "audio_delay", MP_CMD_AUDIO_DELAY
, 0, 0, -1, MSGTR_AVDelayStatus
},
2685 { "switch_audio", MP_CMD_SWITCH_AUDIO
, 1, 0, -1, MSGTR_OSDAudio
},
2687 { "fullscreen", MP_CMD_VO_FULLSCREEN
, 1, 0, -1, NULL
},
2688 { "panscan", MP_CMD_PANSCAN
, 0, OSD_PANSCAN
, -1, MSGTR_Panscan
},
2689 { "ontop", MP_CMD_VO_ONTOP
, 1, 0, -1, MSGTR_OnTopStatus
},
2690 { "rootwin", MP_CMD_VO_ROOTWIN
, 1, 0, -1, MSGTR_RootwinStatus
},
2691 { "border", MP_CMD_VO_BORDER
, 1, 0, -1, MSGTR_BorderStatus
},
2692 { "framedropping", MP_CMD_FRAMEDROPPING
, 1, 0, -1, MSGTR_FramedroppingStatus
},
2693 { "gamma", MP_CMD_GAMMA
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Gamma
},
2694 { "brightness", MP_CMD_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2695 { "contrast", MP_CMD_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2696 { "saturation", MP_CMD_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2697 { "hue", MP_CMD_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2698 { "vsync", MP_CMD_SWITCH_VSYNC
, 1, 0, -1, MSGTR_VSyncStatus
},
2700 { "sub", MP_CMD_SUB_SELECT
, 1, 0, -1, MSGTR_SubSelectStatus
},
2701 { "sub_pos", MP_CMD_SUB_POS
, 0, 0, -1, MSGTR_SubPosStatus
},
2702 { "sub_alignment", MP_CMD_SUB_ALIGNMENT
, 1, 0, -1, MSGTR_SubAlignStatus
},
2703 { "sub_delay", MP_CMD_SUB_DELAY
, 0, 0, OSD_MSG_SUB_DELAY
, MSGTR_SubDelayStatus
},
2704 { "sub_visibility", MP_CMD_SUB_VISIBILITY
, 1, 0, -1, MSGTR_SubVisibleStatus
},
2705 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY
, 1, 0, -1, MSGTR_SubForcedOnlyStatus
},
2707 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2708 { "tv_hue", MP_CMD_TV_SET_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2709 { "tv_saturation", MP_CMD_TV_SET_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2710 { "tv_contrast", MP_CMD_TV_SET_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2712 { NULL
, 0, 0, 0, -1, NULL
}
2715 /// Handle commands that set a property.
2716 static int set_property_command(mp_cmd_t
* cmd
) {
2720 // look for the command
2721 for(i
= 0 ; set_prop_cmd
[i
].name
; i
++)
2722 if(set_prop_cmd
[i
].cmd
== cmd
->id
) break;
2723 if(!set_prop_cmd
[i
].name
) return 0;
2726 prop
= mp_property_find(set_prop_cmd
[i
].name
);
2730 if(set_prop_cmd
[i
].toggle
) {
2732 if(cmd
->nargs
> 0 && cmd
->args
[0].v
.i
>= prop
->min
)
2733 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
.i
);
2735 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,NULL
);
2736 } else if(cmd
->args
[1].v
.i
) //set
2737 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
);
2739 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,&cmd
->args
[0].v
);
2741 if(r
<= 0) return 1;
2743 if(set_prop_cmd
[i
].osd_progbar
) {
2744 if(prop
->type
== CONF_TYPE_INT
) {
2745 if(m_property_do(prop
,M_PROPERTY_GET
,&r
) > 0)
2746 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2747 set_prop_cmd
[i
].osd_msg
,
2748 prop
->min
,prop
->max
,r
);
2749 } else if(prop
->type
== CONF_TYPE_FLOAT
) {
2751 if(m_property_do(prop
,M_PROPERTY_GET
,&f
) > 0)
2752 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,set_prop_cmd
[i
].osd_msg
,
2753 prop
->min
,prop
->max
,f
);
2755 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "Property use an unsupported type.\n");
2759 if(set_prop_cmd
[i
].osd_msg
) {
2760 char* val
= m_property_print(prop
);
2762 set_osd_msg(set_prop_cmd
[i
].osd_id
>= 0 ? set_prop_cmd
[i
].osd_id
:
2763 OSD_MSG_PROPERTY
+i
,1,osd_duration
,
2764 set_prop_cmd
[i
].osd_msg
,val
);
2771 static void reinit_audio_chain(void) {
2773 current_module
="init_audio_codec";
2774 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2775 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
2776 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
2780 inited_flags
|=INITED_ACODEC
;
2781 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2784 //const ao_info_t *info=audio_out->info;
2785 current_module
="af_preinit";
2786 ao_data
.samplerate
=force_srate
;
2788 ao_data
.format
=audio_output_format
;
2790 // first init to detect best values
2791 if(!preinit_audio_filters(sh_audio
,
2793 (int)(sh_audio
->samplerate
*playback_speed
),
2794 sh_audio
->channels
, sh_audio
->sample_format
,
2796 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
2797 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
2798 exit_player(MSGTR_Exit_error
);
2801 current_module
="ao2_init";
2802 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
2806 ao_data
.format
,0))){
2808 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
2809 uninit_player(INITED_ACODEC
); // close codec
2810 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
2815 inited_flags
|=INITED_AO
;
2816 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2817 audio_out
->info
->short_name
,
2818 ao_data
.samplerate
, ao_data
.channels
,
2819 af_fmt2str_short(ao_data
.format
),
2820 af_fmt2bits(ao_data
.format
)/8 );
2821 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
2822 audio_out
->info
->name
, audio_out
->info
->author
);
2823 if(strlen(audio_out
->info
->comment
) > 0)
2824 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
2825 // init audio filters:
2827 current_module
="af_init";
2828 if(!build_afilter_chain(sh_audio
, &ao_data
)) {
2829 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
2830 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2831 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2832 // sh_audio=d_audio->sh=NULL; // -> nosound
2836 mixer
.audio_out
= audio_out
;
2837 mixer
.volstep
= volstep
;
2846 // Return pts value corresponding to the end point of audio written to the
2848 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
2850 // first calculate the end pts of audio that has been output by decoder
2851 double a_pts
= sh_audio
->pts
;
2852 if (a_pts
!= MP_NOPTS_VALUE
)
2853 // Good, decoder supports new way of calculating audio pts.
2854 // sh_audio->pts is the timestamp of the latest input packet with
2855 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2856 // the amount of bytes the decoder has written after that timestamp.
2857 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
2859 // Decoder doesn't support new way of calculating pts (or we're
2860 // being called before it has decoded anything with known timestamp).
2861 // Use the old method of audio pts calculation: take the timestamp
2862 // of last packet with known pts the decoder has read data from,
2863 // and add amount of bytes read after the beginning of that packet
2864 // divided by input bps. This will be inaccurate if the input/output
2865 // ratio is not constant for every audio packet or if it is constant
2866 // but not accurately known in sh_audio->i_bps.
2868 a_pts
= d_audio
->pts
;
2869 // ds_tell_pts returns bytes read after last timestamp from
2870 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2871 // it has read but not decoded
2872 if (sh_audio
->i_bps
)
2873 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
2874 (double)sh_audio
->i_bps
;
2876 // Now a_pts hopefully holds the pts for end of audio from decoder.
2877 // Substract data in buffers between decoder and audio out.
2879 // Decoded but not filtered
2880 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
2882 // Data that was ready for ao but was buffered because ao didn't fully
2883 // accept everything to internal buffers yet
2884 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
2889 // Return pts value corresponding to currently playing audio.
2890 static double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
2891 ao_functions_t
*audio_out
)
2893 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
2894 audio_out
->get_delay();
2897 static void update_subtitles(void)
2899 unsigned char *packet
=NULL
;
2901 char type
= d_dvdsub
->sh
? ((sh_sub_t
*)d_dvdsub
->sh
)->type
: 'v';
2909 double pts
= sh_video
->pts
;
2910 if (sub_fps
==0) sub_fps
= sh_video
->fps
;
2911 current_module
= "find_sub";
2912 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0) {
2913 find_sub(subdata
, (pts
+sub_delay
) *
2914 (subdata
->sub_uses_time
? 100. : sub_fps
));
2915 if (vo_sub
) vo_sub_last
= vo_sub
;
2916 // FIXME! frame counter...
2922 if (vo_config_count
&& vo_spudec
&& type
== 'v') {
2924 current_module
= "spudec";
2925 spudec_heartbeat(vo_spudec
, 90000*sh_video
->timer
);
2926 /* Get a sub packet from the DVD or a vobsub and make a timestamp
2927 * relative to sh_video->timer */
2932 if (sh_video
->pts
+sub_delay
>= 0) {
2933 len
= vobsub_get_packet(vo_vobsub
, sh_video
->pts
+sub_delay
,
2934 (void**)&packet
, ×tamp
);
2936 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
2937 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
);
2942 len
= ds_get_packet_sub(d_dvdsub
, (unsigned char**)&packet
);
2944 // XXX This is wrong, sh_video->pts can be arbitrarily
2945 // much behind demuxing position. Unfortunately using
2946 // d_video->pts which would have been the simplest
2947 // improvement doesn't work because mpeg specific hacks
2948 // in video.c set d_video->pts to 0.
2949 float x
= d_dvdsub
->pts
- sh_video
->pts
;
2950 if (x
> -20 && x
< 20) // prevent missing subs on pts reset
2951 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
2952 + sub_delay
- sh_video
->pts
);
2953 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
2954 mp_dbg(MSGT_CPLAYER
, MSGL_V
, "\rDVD sub: len=%d "
2955 "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len
,
2956 sh_video
->pts
, d_dvdsub
->pts
, timestamp
);
2959 if (len
<=0 || !packet
) break;
2961 spudec_assemble(vo_spudec
, packet
, len
, timestamp
);
2964 if (spudec_changed(vo_spudec
))
2965 vo_osd_changed(OSDTYPE_SPU
);
2966 } else if (dvdsub_id
>= 0 && type
== 't') {
2967 static subtitle subs
;
2968 double curpts
= sh_video
->pts
+ sub_delay
;
2971 while (d_dvdsub
->first
) {
2972 double pts
= ds_get_next_pts(d_dvdsub
);
2975 endpts
= d_dvdsub
->first
->endpts
;
2976 len
= ds_get_packet_sub(d_dvdsub
, &packet
);
2979 static ass_track_t
*global_ass_track
= NULL
;
2980 if (!global_ass_track
) global_ass_track
= ass_default_track(ass_library
);
2981 ass_track
= global_ass_track
;
2983 if (pts
!= MP_NOPTS_VALUE
) {
2984 if (endpts
== MP_NOPTS_VALUE
) endpts
= pts
+ 3;
2985 sub_clear_text(&subs
, MP_NOPTS_VALUE
);
2986 sub_add_text(&subs
, packet
, len
, endpts
);
2987 subs
.start
= pts
* 100;
2988 subs
.end
= endpts
* 100;
2989 ass_process_subtitle(ass_track
, &subs
);
2993 if (pts
!= MP_NOPTS_VALUE
) {
2994 if (endpts
== MP_NOPTS_VALUE
)
2995 sub_clear_text(&subs
, MP_NOPTS_VALUE
);
2996 sub_add_text(&subs
, packet
, len
, endpts
);
2997 vo_osd_changed(OSDTYPE_SUBTITLE
);
3000 if (sub_clear_text(&subs
, curpts
))
3001 vo_osd_changed(OSDTYPE_SUBTITLE
);
3003 current_module
=NULL
;
3006 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
3008 unsigned char *start
;
3014 void *decoded_frame
;
3015 current_module
= "decode video";
3016 // XXX Time used in this call is not counted in any performance
3017 // timer now, OSD is not updated correctly for filter-added frames
3018 if (vf_output_queued_frame(sh_video
->vfilter
))
3020 current_module
= "video_read_frame";
3021 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
3023 // try to extract last frames in case of decoder lag
3028 if (in_size
> max_framesize
)
3029 max_framesize
= in_size
;
3030 if (pts
== MP_NOPTS_VALUE
)
3031 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts value from demuxer MISSING\n");
3032 current_module
= "decode video";
3033 decoded_frame
= decode_video(sh_video
, start
, in_size
, 0, pts
);
3034 if (decoded_frame
) {
3037 current_module
= "filter video";
3038 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
3047 static void rescale_input_coordinates(int ix
, int iy
, double *dx
, double *dy
) {
3048 //remove the borders, if any, and rescale to the range [0,1],[0,1]
3049 if(vo_fs
) { //we are in full-screen mode
3050 if(vo_screenwidth
> vo_dwidth
) //there are borders along the x axis
3051 ix
-= (vo_screenwidth
- vo_dwidth
) / 2;
3052 if(vo_screenheight
> vo_dheight
) //there are borders along the y axis (usual way)
3053 iy
-= (vo_screenheight
- vo_dheight
) / 2;
3055 if(ix
< 0 || ix
> vo_dwidth
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
3056 if(iy
< 0 || iy
> vo_dheight
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
3059 *dx
= (double) ix
/ (double) vo_dwidth
;
3060 *dy
= (double) iy
/ (double) vo_dheight
;
3062 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
3063 *dx
, *dy
, vo_screenwidth
, vo_screenheight
, vo_dwidth
, vo_dheight
, vo_fs
);
3070 static float timing_sleep(float time_frame
)
3074 // -------- RTC -----------
3075 current_module
="sleep_rtc";
3076 while (time_frame
> 0.000) {
3077 unsigned long rtc_ts
;
3078 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
3079 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
3080 time_frame
-= GetRelativeTime();
3086 current_module
= "sleep_darwin";
3087 while (time_frame
> 0.005) {
3088 usec_sleep(1000000*time_frame
);
3089 time_frame
-= GetRelativeTime();
3094 // assume kernel HZ=100 for softsleep, works with larger HZ but with
3095 // unnecessarily high CPU usage
3096 float margin
= softsleep
? 0.011 : 0;
3097 current_module
= "sleep_timer";
3098 while (time_frame
> margin
) {
3099 usec_sleep(1000000 * (time_frame
- margin
));
3100 time_frame
-= GetRelativeTime();
3103 current_module
= "sleep_soft";
3105 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
3106 while (time_frame
> 0)
3107 time_frame
-=GetRelativeTime(); // burn the CPU
3110 #endif /* SYS_DARWIN */
3114 static void adjust_sync_and_print_status(int between_frames
, float timing_error
)
3116 current_module
="av_sync";
3119 double a_pts
, v_pts
;
3123 * If autosync is enabled, the value for delay must be calculated
3124 * a bit differently. It is set only to the difference between
3125 * the audio and video timers. Any attempt to include the real
3126 * or corrected delay causes the pts_correction code below to
3127 * try to correct for the changes in delay which autosync is
3128 * trying to measure. This keeps the two from competing, but still
3129 * allows the code to correct for PTS drift *only*. (Using a delay
3130 * value here, even a "corrected" one, would be incompatible with
3133 a_pts
= written_audio_pts(sh_audio
, d_audio
) - sh_audio
->delay
;
3135 a_pts
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
3137 v_pts
= sh_video
->pts
;
3140 static int drop_message
=0;
3141 double AV_delay
= a_pts
- audio_delay
- v_pts
;
3143 if (AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
3145 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
3150 /* Do not correct target time for the next frame if this frame
3151 * was late not because of wrong target time but because the
3152 * target time could not be met */
3153 x
= (AV_delay
+ timing_error
* playback_speed
) * 0.1f
;
3154 if (x
< -max_pts_correction
)
3155 x
= -max_pts_correction
;
3156 else if (x
> max_pts_correction
)
3157 x
= max_pts_correction
;
3158 if (default_max_pts_correction
>= 0)
3159 max_pts_correction
= default_max_pts_correction
;
3161 max_pts_correction
= sh_video
->frametime
*0.10; // +-10% of time
3162 if (!between_frames
) {
3167 print_status(a_pts
- audio_delay
, AV_delay
, c_total
);
3174 print_status(0, 0, 0);
3178 static int fill_audio_out_buffers(void)
3187 current_module
="play_audio";
3190 // all the current uses of ao_data.pts seem to be in aos that handle
3191 // sync completely wrong; there should be no need to use ao_data.pts
3193 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3194 bytes_to_write
= audio_out
->get_space();
3195 if (sh_video
|| bytes_to_write
>= ao_data
.outburst
)
3198 // handle audio-only case:
3199 // this is where mplayer sleeps during audio-only playback
3200 // to avoid 100% CPU use
3201 usec_sleep(10000); // Wait a tick before retry
3204 while (bytes_to_write
) {
3205 playsize
= bytes_to_write
;
3206 if (playsize
> MAX_OUTBURST
)
3207 playsize
= MAX_OUTBURST
;
3208 bytes_to_write
-= playsize
;
3210 // Fill buffer if needed:
3211 current_module
="decode_audio";
3213 while (sh_audio
->a_out_buffer_len
< playsize
) {
3214 int buflen
= sh_audio
->a_out_buffer_len
;
3215 int ret
= decode_audio(sh_audio
, &sh_audio
->a_out_buffer
[buflen
],
3216 playsize
- buflen
, // min bytes
3217 sh_audio
->a_out_buffer_size
- buflen
// max
3219 if (ret
<= 0) { // EOF?
3222 if (sh_audio
->a_out_buffer_len
== 0)
3227 sh_audio
->a_out_buffer_len
+= ret
;
3230 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
3231 if (playsize
> sh_audio
->a_out_buffer_len
) {
3232 playsize
= sh_audio
->a_out_buffer_len
;
3234 playflags
|= AOPLAY_FINAL_CHUNK
;
3240 current_module
="play_audio";
3242 // Is this pts value actually useful for the aos that access it?
3243 // They're obviously badly broken in the way they handle av sync;
3244 // would not having access to this make them more broken?
3245 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
3246 playsize
= audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
3249 sh_audio
->a_out_buffer_len
-= playsize
;
3250 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
3251 sh_audio
->a_out_buffer_len
);
3252 sh_audio
->delay
+= playback_speed
*playsize
/(double)ao_data
.bps
;
3254 else if (audio_eof
&& audio_out
->get_delay() < .04) {
3255 // Sanity check to avoid hanging in case current ao doesn't output
3256 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3257 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
3258 sh_audio
->a_out_buffer_len
= 0;
3264 static int sleep_until_update(float *time_frame
, float *aq_sleep_time
)
3266 int frame_time_remaining
= 0;
3267 current_module
="calc_sleep_time";
3269 *time_frame
-= GetRelativeTime(); // reset timer
3271 if (sh_audio
&& !d_audio
->eof
) {
3272 float delay
= audio_out
->get_delay();
3273 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
3277 * Adjust this raw delay value by calculating the expected
3278 * delay for this frame and generating a new value which is
3279 * weighted between the two. The higher autosync is, the
3280 * closer to the delay value gets to that which "-nosound"
3281 * would have used, and the longer it will take for A/V
3282 * sync to settle at the right value (but it eventually will.)
3283 * This settling time is very short for values below 100.
3285 float predicted
= sh_audio
->delay
/ playback_speed
+ *time_frame
;
3286 float difference
= delay
- predicted
;
3287 delay
= predicted
+ difference
/ (float)autosync
;
3290 *time_frame
= delay
- sh_audio
->delay
/ playback_speed
;
3292 // delay = amount of audio buffered in soundcard/driver
3293 if (delay
> 0.25) delay
=0.25; else
3294 if (delay
< 0.10) delay
=0.10;
3295 if (*time_frame
> delay
*0.6) {
3296 // sleep time too big - may cause audio drops (buffer underrun)
3297 frame_time_remaining
= 1;
3298 *time_frame
= delay
*0.5;
3301 // If we're lagging more than 200 ms behind the right playback rate,
3302 // don't try to "catch up".
3303 // If benchmark is set always output frames as fast as possible
3304 // without sleeping.
3305 if (*time_frame
< -0.2 || benchmark
)
3309 *aq_sleep_time
+= *time_frame
;
3312 //============================== SLEEP: ===================================
3314 // flag 256 means: libvo driver does its timing (dvb card)
3315 if (*time_frame
> 0.001 && !(vo_flags
&256))
3316 *time_frame
= timing_sleep(*time_frame
);
3317 return frame_time_remaining
;
3320 static int reinit_video_chain(void) {
3321 //================== Init VIDEO (codec & libvo) ==========================
3322 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
3323 current_module
="preinit_libvo";
3325 //shouldn't we set dvideo->id=-2 when we fail?
3327 //if((video_out->preinit(vo_subdevice))!=0){
3328 if(!(video_out
=init_best_video_out(video_driver_list
))){
3329 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
3332 sh_video
->video_out
=video_out
;
3333 inited_flags
|=INITED_VO
;
3336 current_module
="init_video_filters";
3338 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
3339 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
3343 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
3344 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
3346 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
3351 sh_video
->vfilter
=(void*)vf_menu
;
3359 for (i
= 0; vf_settings
[i
].name
; ++i
)
3360 if (strcmp(vf_settings
[i
].name
, "ass") == 0) {
3365 extern vf_info_t vf_info_ass
;
3366 vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
3367 char* vf_arg
[] = {"auto", "1", NULL
};
3368 vf_instance_t
* vf_ass
= vf_open_plugin(libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
3370 sh_video
->vfilter
=(void*)vf_ass
;
3372 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
3377 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
3381 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
3384 current_module
="init_video_codec";
3386 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3387 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
3388 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
3390 if(!sh_video
->inited
){
3391 if(!fixed_vo
) uninit_player(INITED_VO
);
3395 inited_flags
|=INITED_VCODEC
;
3397 if (sh_video
->codec
)
3398 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
3400 sh_video
->last_pts
= MP_NOPTS_VALUE
;
3401 sh_video
->num_buffered_pts
= 0;
3402 sh_video
->next_frame_time
= 0;
3405 // Auto quality option enabled
3406 output_quality
=get_video_quality_max(sh_video
);
3407 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
3408 else output_quality
=auto_quality
;
3409 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
3410 set_video_quality(sh_video
,output_quality
);
3413 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
3415 current_module
="init_vo";
3420 sh_video
= d_video
->sh
= NULL
;
3424 static double update_video(int *blit_frame
)
3426 //-------------------- Decode a frame: -----------------------
3428 *blit_frame
= 0; // Don't blit if we hit EOF
3430 unsigned char* start
=NULL
;
3431 void *decoded_frame
;
3435 current_module
= "video_read_frame";
3436 frame_time
= sh_video
->next_frame_time
;
3437 in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
3441 if (in_size
> max_framesize
)
3442 max_framesize
= in_size
; // stats
3443 sh_video
->timer
+= frame_time
;
3445 sh_audio
->delay
-= frame_time
;
3446 // video_read_frame can change fps (e.g. for ASF video)
3447 vo_fps
= sh_video
->fps
;
3448 // check for frame-drop:
3449 current_module
= "check_framedrop";
3450 if (sh_audio
&& !d_audio
->eof
) {
3451 static int dropped_frames
;
3452 float delay
= playback_speed
*audio_out
->get_delay();
3453 float d
= delay
-sh_audio
->delay
;
3454 // we should avoid dropping too many frames in sequence unless we
3455 // are too late. and we allow 100ms A-V delay here:
3456 if (d
< -dropped_frames
*frame_time
-0.100 &&
3457 osd_function
!= OSD_PAUSE
) {
3458 drop_frame
= frame_dropping
;
3462 drop_frame
= dropped_frames
= 0;
3467 current_module
= "decode_video";
3468 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
3470 current_module
= "filter_video";
3471 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
3475 if (!generate_video_frame(sh_video
, d_video
))
3477 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
,
3478 VFCTRL_GET_PTS
, &sh_video
->pts
);
3479 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
3480 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
3481 sh_video
->pts
= sh_video
->last_pts
;
3483 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
3484 sh_video
->last_pts
= sh_video
->pts
;
3485 else if (sh_video
->last_pts
>= sh_video
->pts
) {
3486 sh_video
->last_pts
= sh_video
->pts
;
3487 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "pts value <= previous");
3489 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
3490 sh_video
->last_pts
= sh_video
->pts
;
3491 sh_video
->timer
+= frame_time
;
3493 sh_audio
->delay
-= frame_time
;
3499 void pause_loop(void)
3503 // Small hack to display the pause message on the OSD line.
3504 // The pause string is: "\n == PAUSE == \r" so we need to
3505 // take the first and the last char out
3506 if (term_osd
&& !sh_video
) {
3507 char msg
[128] = MSGTR_Paused
;
3508 int mlen
= strlen(msg
);
3510 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
3513 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
3514 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
3519 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
3521 if (video_out
&& sh_video
&& vo_config_count
)
3522 video_out
->control(VOCTRL_PAUSE
, NULL
);
3524 if (audio_out
&& sh_audio
)
3525 audio_out
->pause(); // pause audio, keep data if possible
3527 while ( (cmd
= mp_input_get_cmd(20, 1, 1)) == NULL
) {
3528 if (sh_video
&& video_out
&& vo_config_count
)
3529 video_out
->check_events();
3533 guiGetEvent(guiReDraw
, NULL
);
3534 if (guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
))
3540 vf_menu_pause_update(vf_menu
);
3544 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
3545 cmd
= mp_input_get_cmd(0,1,0);
3548 osd_function
=OSD_PLAY
;
3549 if (audio_out
&& sh_audio
)
3550 audio_out
->resume(); // resume audio
3551 if (video_out
&& sh_video
&& vo_config_count
)
3552 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
3553 (void)GetRelativeTime(); // ignore time that passed during pause
3556 if (guiIntfStruct
.Playing
== guiSetStop
)
3559 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
3564 void print_version(void){
3565 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s\n", MP_TITLE
);
3567 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
3568 GetCpuCaps(&gCpuCaps
);
3570 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
3571 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
3572 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
3573 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
3574 #ifdef RUNTIME_CPUDETECT
3575 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
3577 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
3579 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
3582 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
3585 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
3588 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
3591 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
3594 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
3596 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3597 #endif /* RUNTIME_CPUDETECT */
3598 #endif /* ARCH_X86 */
3601 int main(int argc
,char* argv
[]){
3606 int file_format
=DEMUXER_TYPE_UNKNOWN
;
3610 /* Flag indicating whether MPlayer should exit without playing anything. */
3613 //float a_frame=0; // Audio
3618 int gui_no_filename
=0;
3620 srand((int) time(NULL
));
3626 for(i
=1; i
<argc
; i
++)
3627 if(!strcmp(argv
[i
], "-really-quiet"))
3631 #if defined(WIN32) && defined(USE_WIN32DLL)
3633 #endif /*WIN32 && USE_WIN32DLL*/
3636 tv_param_immediate
= 1;
3639 if (argc
> 1 && argv
[1] &&
3640 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
3641 use_gui
= !strcmp(argv
[1], "-gui");
3645 char *base
= strrchr(argv
[0], '/');
3647 base
= strrchr(argv
[0], '\\');
3650 if(strstr(base
, "gmplayer"))
3654 mconfig
= m_config_new();
3655 m_config_register_options(mconfig
,mplayer_opts
);
3656 // TODO : add something to let modules register their options
3657 mp_input_register_options(mconfig
);
3658 parse_cfgfiles(mconfig
);
3661 if ( use_gui
) cfg_read();
3664 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
3665 if(playtree
== NULL
)
3668 playtree
= play_tree_cleanup(playtree
);
3670 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3672 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3673 play_tree_iter_free(playtree_iter
);
3674 playtree_iter
= NULL
;
3676 filename
= play_tree_iter_get_file(playtree_iter
,1);
3681 #if defined(WIN32) && defined(HAVE_NEW_GUI)
3682 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
3683 if(runningmplayer
&& filename
&& use_gui
){
3684 COPYDATASTRUCT csData
;
3685 char file
[MAX_PATH
];
3686 char *filepart
= filename
;
3687 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
3689 csData
.cbData
= strlen(file
)*2;
3690 csData
.lpData
= file
;
3691 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
3699 for(i
=0; priority_presets_defs
[i
].name
; i
++){
3700 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
3703 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
3704 priority_presets_defs
[i
].name
);
3705 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
3708 #ifndef HAVE_NEW_GUI
3710 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
3715 if(use_gui
&& !vo_init()){
3716 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
3720 if (use_gui
&& playtree_iter
){
3721 char cwd
[PATH_MAX
+2];
3722 // Free Playtree and Playtree-Iter as it's not used by the GUI.
3723 play_tree_iter_free(playtree_iter
);
3726 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
3729 // Prefix relative paths with current working directory
3730 play_tree_add_bpf(playtree
, cwd
);
3732 // Import initital playtree into GUI.
3733 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
3735 #endif /* HAVE_NEW_GUI */
3737 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
3742 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
3747 /* Check codecs.conf. */
3748 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
3749 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
3750 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
3751 if(!parse_codec_cfg(NULL
)){
3752 exit_player_with_rc(NULL
, 0);
3754 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
3757 free( mem_ptr
); // release the buffer created by get_path()
3761 if(video_codec_list
){
3763 video_codec
=video_codec_list
[0];
3764 for(i
=0;video_codec_list
[i
];i
++)
3765 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
3768 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
3769 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
3770 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
3772 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3775 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
3776 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
3777 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
3779 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3782 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
3784 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3787 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3789 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3792 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3798 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3800 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3804 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3805 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3806 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3808 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3811 if(list_properties
) {
3812 m_properties_print_help_list(mp_properties
);
3819 if (player_idle_mode
&& use_gui
) {
3820 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
3821 exit_player_with_rc(NULL
, 1);
3824 if(!filename
&& !player_idle_mode
){
3826 // no file/vcd/dvd -> show HELP:
3827 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
3828 exit_player_with_rc(NULL
, 0);
3829 } else gui_no_filename
=1;
3832 /* Display what configure line was used */
3833 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
3835 // Many users forget to include command line in bugreports...
3836 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3837 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
3838 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3839 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3842 //------ load global data first ------
3845 #ifdef HAVE_FREETYPE
3848 #ifdef HAVE_FONTCONFIG
3849 if(!font_fontconfig
)
3852 #ifdef HAVE_BITMAP_FONT
3854 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3855 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,
3856 filename_recode(font_name
));
3859 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3860 free(mem_ptr
); // release the buffer created by get_path()
3862 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3865 #ifdef HAVE_FONTCONFIG
3872 ass_library
= ass_init();
3878 // seteuid(0); /* Can't hurt to try to get root here */
3879 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3880 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
3881 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3883 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3885 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3886 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
3887 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
3890 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3891 /* variable only by the root */
3892 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
3896 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
3900 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
3901 // and now ? -- Pontscho
3902 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
3905 #endif /* HAVE_RTC */
3906 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3907 softsleep
?"software":timer_name
);
3910 if ( !use_gui
) load_termcap(NULL
); // load key-codes
3913 // ========== Init keyboard FIFO (connection to libvo) ============
3915 // Init input system
3916 current_module
= "init_input";
3917 mp_input_init(use_gui
);
3919 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
3921 if(keyb_fifo_get
> 0)
3922 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
3924 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
3928 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
3930 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
3932 else if(!noconsolecontrols
)
3933 #ifndef HAVE_NO_POSIX_SELECT
3934 mp_input_add_key_fd(0,1,NULL
,NULL
);
3936 mp_input_add_key_fd(0,0,NULL
,NULL
);
3939 inited_flags
|=INITED_INPUT
;
3940 current_module
= NULL
;
3944 if(menu_cfg
&& menu_init(menu_cfg
))
3945 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3947 menu_cfg
= get_path("menu.conf");
3948 if(menu_init(menu_cfg
))
3949 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3951 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
3952 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
3954 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
3964 signal(SIGCHLD
,child_sighandler
);
3968 prog_path
= argv
[0];
3970 //========= Catch terminate signals: ================
3971 // terminate requests:
3972 signal(SIGTERM
,exit_sighandler
); // kill
3973 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3975 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3977 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3978 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3979 #ifdef ENABLE_SIGHANDLER
3981 signal(SIGBUS
,exit_sighandler
); // bus error
3982 signal(SIGSEGV
,exit_sighandler
); // segfault
3983 signal(SIGILL
,exit_sighandler
); // illegal instruction
3984 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3985 signal(SIGABRT
,exit_sighandler
); // abort()
3988 signal(SIGTRAP
,exit_sighandler
);
3995 inited_flags
|=INITED_GUI
;
3996 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
4000 // ******************* Now, let's see the per-file stuff ********************
4004 // init global sub numbers
4005 global_sub_size
= 0;
4006 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
4008 if (filename
) load_per_file_config (mconfig
, filename
);
4010 // We must enable getch2 here to be able to interrupt network connection
4012 if(!noconsolecontrols
&& !slave_mode
){
4013 if(inited_flags
&INITED_GETCH2
)
4014 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
4016 getch2_enable(); // prepare stdin for hotkeys...
4017 inited_flags
|=INITED_GETCH2
;
4018 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
4021 // =================== GUI idle loop (STOP state) ===========================
4024 file_format
=DEMUXER_TYPE_UNKNOWN
;
4025 guiGetEvent( guiSetDefaults
,0 );
4026 while ( guiIntfStruct
.Playing
!= 1 )
4031 guiGetEvent( guiReDraw
,NULL
);
4032 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
4034 guiGetEvent( guiSetParameters
,NULL
);
4035 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
4037 play_tree_t
* entry
= play_tree_new();
4038 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
4039 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
4040 else playtree
=play_tree_new();
4041 play_tree_set_child( playtree
,entry
);
4044 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
4047 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
4049 play_tree_iter_free(playtree_iter
);
4050 playtree_iter
= NULL
;
4052 filename
= play_tree_iter_get_file(playtree_iter
,1);
4057 #endif /* HAVE_NEW_GUI */
4059 while (player_idle_mode
&& !filename
) {
4060 play_tree_t
* entry
= NULL
;
4062 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
4063 if (video_out
&& vo_config_count
) video_out
->check_events();
4067 case MP_CMD_LOADFILE
:
4068 // prepare a tree entry with the new filename
4069 entry
= play_tree_new();
4070 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
4071 // The entry is added to the main playtree after the switch().
4073 case MP_CMD_LOADLIST
:
4074 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
4077 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
4083 if (entry
) { // user entered a command that gave a valid entry
4084 if (playtree
) // the playtree is always a node with one child. let's clear it
4085 play_tree_free_list(playtree
->child
, 1);
4086 else playtree
=play_tree_new(); // .. or make a brand new playtree
4088 if (!playtree
) continue; // couldn't make playtree! wait for next command
4090 play_tree_set_child(playtree
, entry
);
4092 /* Make iterator start at the top the of tree. */
4093 playtree_iter
= play_tree_iter_new(playtree
, mconfig
);
4094 if (!playtree_iter
) continue;
4096 // find the first real item in the tree
4097 if (play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
4099 play_tree_iter_free(playtree_iter
);
4100 playtree_iter
= NULL
;
4101 continue; // wait for next command
4103 filename
= play_tree_iter_get_file(playtree_iter
, 1);
4106 //---------------------------------------------------------------------------
4109 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
,
4110 filename_recode(filename
));
4113 if (edl_records
) free_edl(edl_records
);
4114 next_edl_record
= edl_records
= edl_parse_file();
4116 if (edl_output_filename
) {
4117 if (edl_fd
) fclose(edl_fd
);
4118 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
4120 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
4121 filename_recode(edl_output_filename
));
4125 //==================== Open VOB-Sub ============================
4127 current_module
="vobsub";
4129 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
4131 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,
4132 filename_recode(vobsub_name
));
4133 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
4134 /* try to autodetect vobsub from movie filename ::atmos */
4135 char *buf
= malloc((strlen(filename
)-3)),*psub
;
4136 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
4137 strncpy(buf
, filename
, strlen(filename
)-4);
4138 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
4139 /* try from ~/.mplayer/sub */
4140 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
4143 bname
= strrchr(buf
,'/');
4145 if(!bname
) bname
= strrchr(buf
,'\\');
4149 l
= strlen(psub
) + strlen(bname
) + 1;
4150 psub
= realloc(psub
,l
);
4152 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
4158 inited_flags
|=INITED_VOBSUB
;
4159 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
4160 // check if vobsub requested only to display forced subtitles
4161 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
4163 // setup global sub numbering
4164 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
4165 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
4168 //============ Open & Sync STREAM --- fork cache2 ====================
4173 //free_demuxer_stream(d_audio);
4177 //free_demuxer_stream(d_video);
4183 current_module
="open_stream";
4184 stream
=open_stream(filename
,0,&file_format
);
4185 if(!stream
) { // error...
4186 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
4187 goto goto_next_file
;
4189 inited_flags
|=INITED_STREAM
;
4192 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
4195 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
4198 current_module
="handle_playlist";
4199 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
4200 filename_recode(filename
));
4201 entry
= parse_playtree(stream
,0);
4202 eof
=playtree_add_playlist(entry
);
4203 goto goto_next_file
;
4205 stream
->start_pos
+=seek_to_byte
;
4207 if(stream_dump_type
==5){
4208 unsigned char buf
[4096];
4211 current_module
="dumpstream";
4212 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
4213 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
4214 exit_player(MSGTR_Exit_error
);
4216 stream_reset(stream
);
4217 stream_seek(stream
,stream
->start_pos
);
4218 f
=fopen(stream_dump_name
,"wb");
4220 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
4221 exit_player(MSGTR_Exit_error
);
4223 while(!stream
->eof
){
4224 len
=stream_read(stream
,buf
,4096);
4226 if(fwrite(buf
,len
,1,f
) != 1) {
4227 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
4228 exit_player(MSGTR_Exit_error
);
4233 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
4234 exit_player(MSGTR_Exit_error
);
4236 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
4237 exit_player_with_rc(MSGTR_Exit_eof
, 0);
4241 if(stream
->type
==STREAMTYPE_DVD
){
4242 current_module
="dvd lang->id";
4243 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
4244 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
4245 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
4246 // setup global sub numbering
4247 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4248 global_sub_size
+= dvd_number_of_subs(stream
);
4249 current_module
=NULL
;
4254 if(stream
->type
==STREAMTYPE_DVDNAV
){
4255 current_module
="dvdnav lang->id";
4256 if(audio_id
==-1) audio_id
=dvdnav_aid_from_lang(stream
,audio_lang
);
4257 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
4258 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvdnav_sid_from_lang(stream
,dvdsub_lang
);
4259 // setup global sub numbering
4260 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4261 global_sub_size
+= dvdnav_number_of_subs(stream
);
4262 current_module
=NULL
;
4266 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
4268 if(stream_cache_size
>0){
4269 current_module
="enable_cache";
4270 if(!stream_enable_cache(stream
,stream_cache_size
*1024,
4271 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
4272 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
4273 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
4276 //============ Open DEMUXERS --- DETECT file type =======================
4277 current_module
="demux_open";
4279 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
4281 // HACK to get MOV Reference Files working
4283 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
4285 unsigned char* playlist_entry
;
4286 play_tree_t
*list
= NULL
, *entry
= NULL
;
4288 current_module
="handle_demux_playlist";
4289 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
4293 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
4294 filename_recode(playlist_entry
));
4296 bname
=mp_basename(playlist_entry
);
4297 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
4300 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
4303 entry
= play_tree_new();
4305 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
4307 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
4310 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
4311 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
4312 strcat(temp
, playlist_entry
);
4313 play_tree_add_file(entry
,temp
);
4314 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
4319 play_tree_add_file(entry
,playlist_entry
);
4324 play_tree_append_entry(list
,entry
);
4326 free_demuxer(demuxer
);
4331 entry
= play_tree_new();
4332 play_tree_set_child(entry
,list
);
4333 eof
=playtree_add_playlist(entry
);
4334 goto goto_next_file
;
4343 current_module
="handle_playlist";
4344 switch(stream
->type
){
4345 case STREAMTYPE_VCD
:
4346 case STREAMTYPE_DVD
:
4347 case STREAMTYPE_CDDA
:
4348 case STREAMTYPE_VCDBINCUE
:
4349 // don't try to parse raw media as playlist, it's unlikely
4350 goto goto_next_file
;
4352 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
4353 stream_reset(stream
);
4354 stream_seek(stream
,stream
->start_pos
);
4355 entry
= parse_playtree(stream
,0);
4357 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
4359 eof
=playtree_add_playlist(entry
);
4361 goto goto_next_file
;
4363 inited_flags
|=INITED_DEMUXER
;
4365 if (stream
->type
!= STREAMTYPE_DVD
&& stream
->type
!= STREAMTYPE_DVDNAV
) {
4367 // setup global sub numbering
4368 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
4369 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
4370 if (demuxer
->s_streams
[i
])
4374 current_module
="demux_open2";
4376 //file_format=demuxer->file_format;
4378 d_audio
=demuxer
->audio
;
4379 d_video
=demuxer
->video
;
4380 d_dvdsub
=demuxer
->sub
;
4383 if((stream_dump_type
)&&(stream_dump_type
<4)){
4385 demux_stream_t
*ds
=NULL
;
4386 current_module
="dump";
4387 // select stream to dump
4388 switch(stream_dump_type
){
4389 case 1: ds
=d_audio
;break;
4390 case 2: ds
=d_video
;break;
4391 case 3: ds
=d_dvdsub
;break;
4394 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
4395 exit_player(MSGTR_Exit_error
);
4397 // disable other streams:
4398 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
4399 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
4400 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
4402 f
=fopen(stream_dump_name
,"wb");
4404 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
4405 exit_player(MSGTR_Exit_error
);
4408 unsigned char* start
;
4409 int in_size
=ds_get_packet(ds
,&start
);
4410 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
4411 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
4412 if(in_size
>0) fwrite(start
,in_size
,1,f
);
4415 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
4416 exit_player_with_rc(MSGTR_Exit_eof
, 0);
4419 sh_audio
=d_audio
->sh
;
4420 sh_video
=d_video
->sh
;
4424 current_module
="video_read_properties";
4425 if(!video_read_properties(sh_video
)) {
4426 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
4427 sh_video
=d_video
->sh
=NULL
;
4429 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
4430 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
4431 sh_video
->fps
,sh_video
->frametime
4434 /* need to set fps here for output encoders to pick it up in their init */
4436 sh_video
->fps
=force_fps
;
4437 sh_video
->frametime
=1.0f
/sh_video
->fps
;
4439 vo_fps
= sh_video
->fps
;
4441 if(!sh_video
->fps
&& !force_fps
){
4442 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
4443 sh_video
=d_video
->sh
=NULL
;
4451 if(!sh_video
&& !sh_audio
){
4452 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
4453 #ifdef HAS_DVBIN_SUPPORT
4454 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4456 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4460 int v
= last_dvb_step
;
4462 dir
= DVB_CHANNEL_HIGHER
;
4464 dir
= DVB_CHANNEL_LOWER
;
4466 if(dvb_step_channel(priv
, dir
))
4467 eof
= dvbin_reopen
= 1;
4471 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
4474 /* display clip info */
4475 demux_info_print(demuxer
);
4477 //================== Read SUBTITLES (DVD & TEXT) ==========================
4478 if(vo_spudec
==NULL
&& sh_video
&&
4479 (stream
->type
==STREAMTYPE_DVD
|| stream
->type
== STREAMTYPE_DVDNAV
|| d_dvdsub
->id
>= 0)){
4483 // Apply current settings for forced subs
4484 if (vo_spudec
!=NULL
)
4485 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
4488 // after reading video params we should load subtitles because
4489 // we know fps so now we can adjust subtitle time to ~6 seconds AST
4491 current_module
="read_subtitles_file";
4493 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
4494 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
4496 if(sub_auto
) { // auto load sub file ...
4497 char *psub
= get_path( "sub/" );
4498 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
4500 free(psub
); // release the buffer created by get_path() above
4502 add_subtitles (tmp
[i
], sh_video
->fps
, 0);
4507 if (set_of_sub_size
> 0) {
4508 // setup global sub numbering
4509 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
4510 global_sub_size
+= set_of_sub_size
;
4514 if (global_sub_size
) {
4515 // find the best sub to use
4516 if (vobsub_id
>= 0) {
4517 // if user asks for a vobsub id, use that first.
4518 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
4519 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
4520 // if user asks for a dvd sub id, use that next.
4521 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
4522 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
4523 // if there are text subs to use, use those. (autosubs come last here)
4524 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
4526 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4527 // if nothing else works, get subs from the demuxer.
4528 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
4531 // nothing worth doing automatically.
4532 global_sub_pos
= -1;
4534 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
4536 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
);
4538 switch (stream_dump_type
) {
4539 case 3: list_sub_file(subdata
); break;
4540 case 4: dump_mpsub(subdata
, sh_video
->fps
); break;
4541 case 6: dump_srt(subdata
, sh_video
->fps
); break;
4542 case 7: dump_microdvd(subdata
, sh_video
->fps
); break;
4543 case 8: dump_jacosub(subdata
, sh_video
->fps
); break;
4544 case 9: dump_sami(subdata
, sh_video
->fps
); break;
4548 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
4549 filename_recode(filename
));
4550 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", demuxer
->desc
->name
);
4552 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4553 if (sh_video
->format
>= 0x20202020)
4554 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video
->format
);
4556 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
4557 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
4558 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
4559 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
4560 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
4561 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
4564 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4565 if (sh_audio
->format
>= 0x20202020)
4566 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio
->format
);
4568 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
4569 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
4570 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
4571 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
4573 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
4575 if(!sh_video
) goto main
; // audio-only
4577 if(!reinit_video_chain()) {
4579 if(!sh_audio
) goto goto_next_file
;
4580 goto main
; // exit_player(MSGTR_Exit_error);
4584 if(vo_flags
& 0x08 && vo_spudec
)
4585 spudec_set_hw_spu(vo_spudec
,video_out
);
4587 #ifdef HAVE_FREETYPE
4588 force_load_font
= 1;
4591 //================== MAIN: ==========================
4593 current_module
="main";
4596 char* msg
= m_properties_expand_string(mp_properties
,playing_msg
);
4597 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
4602 // Disable the term OSD in verbose mode
4603 if(verbose
) term_osd
= 0;
4607 //int frame_corr_num=0; //
4608 //float v_frame=0; // Video
4609 float time_frame
=0; // Timer
4610 //float num_frames=0; // number of frames played
4613 int frame_time_remaining
=0; // flag
4617 // Make sure old OSD does not stay around,
4618 // e.g. with -fixed-vo and same-resolution files
4622 //================ SETUP AUDIO ==========================
4625 reinit_audio_chain();
4626 if (sh_audio
&& sh_audio
->codec
)
4627 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
4630 current_module
="av_init";
4635 audio_delay
+= sh_video
->stream_delay
;
4639 audio_delay
-= sh_audio
->stream_delay
;
4640 sh_audio
->delay
=-audio_delay
;
4644 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
4645 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",d_audio
->packs
);
4646 ds_free_packs(d_audio
); // free buffered chunks
4647 //d_audio->id=-2; // do not read audio chunks
4648 //uninit_player(INITED_AO); // close device
4651 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
4652 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",d_video
->packs
);
4653 ds_free_packs(d_video
);
4655 //if(!fixed_vo) uninit_player(INITED_VO);
4658 if (!sh_video
&& !sh_audio
)
4659 goto goto_next_file
;
4661 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4662 if(force_fps
&& sh_video
){
4663 vo_fps
= sh_video
->fps
=force_fps
;
4664 sh_video
->frametime
=1.0f
/sh_video
->fps
;
4665 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
4670 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
4671 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
4672 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
4673 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
4674 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
4678 //==================== START PLAYING =======================
4680 if(loop_times
>1) loop_times
--; else
4681 if(loop_times
==1) loop_times
= -1;
4683 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
4685 total_time_usage_start
=GetTimer();
4686 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4687 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
4688 play_n_frames
=play_n_frames_mf
;
4690 if(play_n_frames
==0){
4691 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
4695 float aq_sleep_time
=0;
4696 if(!sh_audio
&& d_audio
->sh
) {
4697 sh_audio
= d_audio
->sh
;
4698 sh_audio
->ds
= d_audio
;
4699 reinit_audio_chain();
4702 /*========================== PLAY AUDIO ============================*/
4705 if (!fill_audio_out_buffers())
4706 // at eof, all audio at least written to ao
4708 eof
= PT_NEXT_ENTRY
;
4712 // handle audio-only case:
4714 if(!quiet
|| end_at
.type
== END_AT_TIME
)
4715 a_pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4718 print_status(a_pos
, 0, 0);
4720 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
4721 eof
= PT_NEXT_ENTRY
;
4726 /*========================== PLAY VIDEO ============================*/
4728 vo_pts
=sh_video
->timer
*90000.0;
4729 vo_fps
=sh_video
->fps
;
4731 if (!frame_time_remaining
) {
4732 double frame_time
= update_video(&blit_frame
);
4733 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
4734 if (sh_video
->vf_inited
< 0) {
4735 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
4736 eof
= 1; goto goto_next_file
;
4741 time_frame
+= frame_time
/ playback_speed
; // for nosound
4744 // ==========================================================================
4746 // current_module="draw_osd";
4747 // if(vo_config_count) video_out->draw_osd();
4750 if(use_gui
) guiEventHandling();
4753 current_module
="vo_check_events";
4754 if (vo_config_count
) video_out
->check_events();
4757 if (stop_xscreensaver
) {
4758 current_module
= "stop_xscreensaver";
4759 xscreensaver_heartbeat();
4763 frame_time_remaining
= sleep_until_update(&time_frame
, &aq_sleep_time
);
4765 //====================== FLIP PAGE (VIDEO BLT): =========================
4767 current_module
="flip_page";
4768 if (!frame_time_remaining
&& blit_frame
) {
4769 unsigned int t2
=GetTimer();
4771 if(vo_config_count
) video_out
->flip_page();
4773 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
4775 //====================== A-V TIMESTAMP CORRECTION: =========================
4777 adjust_sync_and_print_status(frame_time_remaining
, time_frame
);
4779 //============================ Auto QUALITY ============================
4781 /*Output quality adjustments:*/
4783 current_module
="autoq";
4784 // float total=0.000001f * (GetTimer()-aq_total_time);
4785 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4786 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4789 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4790 if(output_quality
>1 && aq_sleep_time
<0)
4793 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4795 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4796 set_video_quality(sh_video
,output_quality
);
4799 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
4801 if (play_n_frames
<= 0) eof
= PT_NEXT_ENTRY
;
4805 // FIXME: add size based support for -endpos
4806 if (end_at
.type
== END_AT_TIME
&&
4807 !frame_time_remaining
&& end_at
.pos
<= sh_video
->pts
)
4808 eof
= PT_NEXT_ENTRY
;
4810 } // end if(sh_video)
4813 if (stream
->type
== STREAMTYPE_DVDNAV
) {
4815 mp_dvdnav_get_highlight (stream
, &hl
);
4816 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
4817 vo_osd_changed (OSDTYPE_DVDNAV
);
4821 //============================ Handle PAUSE ===============================
4823 current_module
="pause";
4826 // 36000000 means max timed visibility is 1 hour into the future, if
4827 // the difference is greater assume it's wrapped around from below 0
4828 if (osd_visible
- GetTimerMS() > 36000000) {
4830 vo_osd_progbar_type
=-1; // disable
4831 vo_osd_changed(OSDTYPE_PROGBAR
);
4832 if (osd_function
!= OSD_PAUSE
)
4833 osd_function
= OSD_PLAY
;
4837 if (osd_function
== OSD_PAUSE
) {
4844 osd_function
=OSD_FFW
;
4845 rel_seek_secs
+=step_sec
;
4848 //================= EDL =========================================
4850 if( next_edl_record
) { // Are we (still?) doing EDL?
4852 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
4853 free_edl(edl_records
);
4854 next_edl_record
= NULL
;
4857 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
4858 if( next_edl_record
->action
== EDL_SKIP
) {
4859 osd_function
= OSD_FFW
;
4861 rel_seek_secs
= next_edl_record
->length_sec
;
4862 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
);
4864 } else if( next_edl_record
->action
== EDL_MUTE
) {
4865 edl_muted
= !edl_muted
;
4866 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4867 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
4869 next_edl_record
=next_edl_record
->next
;
4874 //================= Keyboard events, SEEKing ====================
4876 current_module
="key_events";
4881 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
4882 if(!set_property_command(cmd
))
4884 case MP_CMD_SEEK
: {
4888 osd_show_percentage
= sh_video
->fps
;
4889 v
= cmd
->args
[0].v
.f
;
4890 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
4891 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
4894 osd_function
= (v
> sh_video
->pts
) ? OSD_FFW
: OSD_REW
;
4897 else if(abs
) { /* Absolute seek by percentage */
4900 osd_function
= OSD_FFW
; // Direction isn't set correctly
4901 rel_seek_secs
= v
/100.0;
4905 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
4909 case MP_CMD_SET_PROPERTY
: {
4910 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4911 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4912 else if(m_property_parse(prop
,cmd
->args
[1].v
.s
) <= 0)
4913 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to set property '%s' to '%s'.\n",
4914 cmd
->args
[0].v
.s
,cmd
->args
[1].v
.s
);
4917 case MP_CMD_STEP_PROPERTY
: {
4918 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4919 float arg
= cmd
->args
[1].v
.f
;
4920 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
, "Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4921 else if(m_property_do(prop
,M_PROPERTY_STEP_UP
, arg
? &arg
: NULL
) <= 0)
4922 mp_msg(MSGT_CPLAYER
,MSGL_WARN
, "Failed to increment property '%s' by %f.\n",cmd
->args
[0].v
.s
, arg
);
4924 case MP_CMD_GET_PROPERTY
: {
4927 prop
= mp_property_find(cmd
->args
[0].v
.s
);
4929 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unknown property: '%s'\n",cmd
->args
[0].v
.s
);
4932 /* Use m_option_print directly to get easily parseable values. */
4933 val
= calloc(1,prop
->type
->size
);
4934 if(m_property_do(prop
,M_PROPERTY_GET
,val
) <= 0) {
4935 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to get value of property '%s'.\n",
4939 tmp
= m_option_print(prop
,val
);
4940 if(!tmp
|| tmp
== (char*)-1) {
4941 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to print value of property '%s'.\n",
4945 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_%s=%s\n",cmd
->args
[0].v
.s
,tmp
);
4948 case MP_CMD_EDL_MARK
:
4950 float v
= sh_video
? sh_video
->pts
:
4951 playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4953 if(begin_skip
== MP_NOPTS_VALUE
)
4956 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutStartSkip
);
4960 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_EdloutBadStop
);
4962 fprintf(edl_fd
, "%f %f %d\n", begin_skip
, v
, 0);
4963 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutEndSkip
);
4965 begin_skip
= MP_NOPTS_VALUE
;
4969 case MP_CMD_SWITCH_RATIO
: {
4970 if (cmd
->nargs
== 0 || cmd
->args
[0].v
.f
== -1)
4971 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
4973 movie_aspect
= cmd
->args
[0].v
.f
;
4974 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
4976 case MP_CMD_SPEED_INCR
: {
4977 float v
= cmd
->args
[0].v
.f
;
4978 playback_speed
+= v
;
4979 build_afilter_chain(sh_audio
, &ao_data
);
4980 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4982 case MP_CMD_SPEED_MULT
: {
4983 float v
= cmd
->args
[0].v
.f
;
4984 playback_speed
*= v
;
4985 build_afilter_chain(sh_audio
, &ao_data
);
4986 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4988 case MP_CMD_SPEED_SET
: {
4989 float v
= cmd
->args
[0].v
.f
;
4991 build_afilter_chain(sh_audio
, &ao_data
);
4992 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4994 case MP_CMD_FRAME_STEP
:
4995 case MP_CMD_PAUSE
: {
4999 case MP_CMD_FILE_FILTER
: {
5000 file_filter
= cmd
->args
[0].v
.i
;
5003 case MP_CMD_QUIT
: {
5004 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
5006 case MP_CMD_GRAB_FRAMES
: {
5009 case MP_CMD_PLAY_TREE_STEP
: {
5010 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
5011 int force
= cmd
->args
[1].v
.i
;
5020 for (i
=0;i
<-1*n
;i
++)
5025 if(!force
&& playtree_iter
) {
5026 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
5028 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
5029 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
5030 play_tree_iter_free(i
);
5032 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
5038 case MP_CMD_PLAY_TREE_UP_STEP
: {
5039 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
5040 int force
= cmd
->args
[1].v
.i
;
5042 if(!force
&& playtree_iter
) {
5043 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
5044 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
5045 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
5046 play_tree_iter_free(i
);
5048 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
5051 case MP_CMD_PLAY_ALT_SRC_STEP
: {
5052 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
5053 int v
= cmd
->args
[0].v
.i
;
5054 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
5056 else if(v
< 0 && playtree_iter
->file
> 1)
5061 case MP_CMD_SUB_STEP
: {
5063 int movement
= cmd
->args
[0].v
.i
;
5064 step_sub(subdata
, sh_video
->pts
, movement
);
5067 sub_delay
+= ass_step_sub(ass_track
, (sh_video
->pts
+ sub_delay
) * 1000 + .5, movement
) / 1000.;
5069 set_osd_msg(OSD_MSG_SUB_DELAY
,1,osd_duration
,
5070 MSGTR_OSDSubDelay
, ROUND(sub_delay
*1000));
5073 case MP_CMD_SUB_LOG
: {
5077 int v
= cmd
->args
[0].v
.i
;
5078 int max
= (term_osd
&& !sh_video
) ? MAX_TERM_OSD_LEVEL
: MAX_OSD_LEVEL
;
5079 if(osd_level
> max
) osd_level
= max
;
5081 osd_level
=(osd_level
+1)%(max
+1);
5083 osd_level
= v
> max
? max
: v
;
5084 /* Show OSD state when disabled, but not when an explicit
5085 argument is given to the OSD command, i.e. in slave mode. */
5086 if (v
== -1 && osd_level
<= 1)
5087 set_osd_msg(OSD_MSG_OSD_STATUS
,0,osd_duration
,
5088 MSGTR_OSDosd
, osd_level
? MSGTR_OSDenabled
: MSGTR_OSDdisabled
);
5090 rm_osd_msg(OSD_MSG_OSD_STATUS
);
5092 case MP_CMD_OSD_SHOW_TEXT
: {
5093 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
5094 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
5095 "%-.63s",cmd
->args
[0].v
.s
);
5097 case MP_CMD_OSD_SHOW_PROPERTY_TEXT
: {
5098 char* txt
= m_properties_expand_string(mp_properties
,cmd
->args
[0].v
.s
);
5099 /* if no argument supplied take default osd_duration, else <arg> ms. */
5101 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
5102 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
5107 case MP_CMD_LOADFILE
: {
5108 play_tree_t
* e
= play_tree_new();
5109 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
5111 if (cmd
->args
[1].v
.i
) // append
5112 play_tree_append_entry(playtree
, e
);
5114 // Go back to the starting point.
5115 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
5117 play_tree_free_list(playtree
->child
,1);
5118 play_tree_set_child(playtree
,e
);
5119 play_tree_iter_step(playtree_iter
,0,0);
5124 case MP_CMD_LOADLIST
: {
5125 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
5127 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
5129 if (cmd
->args
[1].v
.i
) // append
5130 play_tree_append_entry(playtree
, e
);
5132 // Go back to the starting point.
5133 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
5135 play_tree_free_list(playtree
->child
,1);
5136 play_tree_set_child(playtree
,e
);
5137 play_tree_iter_step(playtree_iter
,0,0);
5144 case MP_CMD_RADIO_STEP_CHANNEL
: {
5145 if (demuxer
->stream
->type
==STREAMTYPE_RADIO
) {
5146 int v
= cmd
->args
[0].v
.i
;
5148 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_HIGHER
);
5150 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_LOWER
);
5151 if (radio_get_channel_name(demuxer
->stream
)) {
5152 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
5153 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
5157 case MP_CMD_RADIO_SET_CHANNEL
: {
5158 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
) {
5159 radio_set_channel(demuxer
->stream
, cmd
->args
[0].v
.s
);
5160 if (radio_get_channel_name(demuxer
->stream
)) {
5161 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
5162 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
5166 case MP_CMD_RADIO_SET_FREQ
: {
5167 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
)
5168 radio_set_freq(demuxer
->stream
, cmd
->args
[0].v
.f
);
5170 case MP_CMD_RADIO_STEP_FREQ
:
5171 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
){
5172 radio_step_freq(demuxer
->stream
, cmd
->args
[0].v
.f
);
5177 case MP_CMD_TV_SET_FREQ
: {
5178 if (file_format
== DEMUXER_TYPE_TV
)
5179 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
5181 case MP_CMD_TV_SET_NORM
: {
5182 if (file_format
== DEMUXER_TYPE_TV
)
5183 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
5185 case MP_CMD_TV_STEP_CHANNEL
: {
5186 if (file_format
== DEMUXER_TYPE_TV
) {
5187 int v
= cmd
->args
[0].v
.i
;
5189 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
5191 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
5193 if (tv_channel_list
) {
5194 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5195 MSGTR_OSDChannel
, tv_channel_current
->name
);
5196 //vo_osd_changed(OSDTYPE_SUBTITLE);
5200 #ifdef HAS_DVBIN_SUPPORT
5201 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
5203 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
5207 int v
= cmd
->args
[0].v
.i
;
5211 dir
= DVB_CHANNEL_HIGHER
;
5213 dir
= DVB_CHANNEL_LOWER
;
5216 if(dvb_step_channel(priv
, dir
))
5217 eof
= dvbin_reopen
= 1;
5220 #endif /* HAS_DVBIN_SUPPORT */
5222 case MP_CMD_TV_SET_CHANNEL
: {
5223 if (file_format
== DEMUXER_TYPE_TV
) {
5224 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
5225 if (tv_channel_list
) {
5226 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5227 MSGTR_OSDChannel
, tv_channel_current
->name
);
5228 //vo_osd_changed(OSDTYPE_SUBTITLE);
5232 #ifdef HAS_DVBIN_SUPPORT
5233 case MP_CMD_DVB_SET_CHANNEL
:
5235 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
5237 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
5240 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
5245 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
5246 eof
= dvbin_reopen
= 1;
5251 #endif /* HAS_DVBIN_SUPPORT */
5252 case MP_CMD_TV_LAST_CHANNEL
: {
5253 if (file_format
== DEMUXER_TYPE_TV
) {
5254 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
5255 if (tv_channel_list
) {
5256 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
5257 MSGTR_OSDChannel
, tv_channel_current
->name
);
5258 //vo_osd_changed(OSDTYPE_SUBTITLE);
5262 case MP_CMD_TV_STEP_NORM
: {
5263 if (file_format
== DEMUXER_TYPE_TV
)
5264 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
5266 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
5267 if (file_format
== DEMUXER_TYPE_TV
)
5268 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
5271 case MP_CMD_SUB_LOAD
:
5274 int n
= set_of_sub_size
;
5275 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
5276 if (n
!= set_of_sub_size
) {
5277 if (global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
5278 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
;
5283 case MP_CMD_SUB_REMOVE
:
5286 int v
= cmd
->args
[0].v
.i
;
5289 for (v
= 0; v
< set_of_sub_size
; ++v
) {
5290 subd
= set_of_subtitles
[v
];
5291 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1,
5292 filename_recode(subd
->filename
));
5294 set_of_subtitles
[v
] = NULL
;
5296 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5297 global_sub_size
-= set_of_sub_size
;
5298 set_of_sub_size
= 0;
5299 if (set_of_sub_pos
>= 0) {
5300 global_sub_pos
= -2;
5301 vo_sub_last
= vo_sub
= NULL
;
5302 vo_osd_changed(OSDTYPE_SUBTITLE
);
5303 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5304 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5307 else if (v
< set_of_sub_size
) {
5308 subd
= set_of_subtitles
[v
];
5309 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1,
5310 filename_recode(subd
->filename
));
5312 if (set_of_sub_pos
== v
) {
5313 global_sub_pos
= -2;
5314 vo_sub_last
= vo_sub
= NULL
;
5315 vo_osd_changed(OSDTYPE_SUBTITLE
);
5316 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5317 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5319 else if (set_of_sub_pos
> v
) {
5323 while (++v
< set_of_sub_size
)
5324 set_of_subtitles
[v
- 1] = set_of_subtitles
[v
];
5327 if (set_of_sub_size
<= 0)
5328 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5329 set_of_subtitles
[set_of_sub_size
] = NULL
;
5333 case MP_CMD_GET_SUB_VISIBILITY
:
5336 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_SUB_VISIBILITY=%d\n", sub_visibility
);
5339 case MP_CMD_SCREENSHOT
:
5340 if(vo_config_count
){
5341 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"sending VFCTRL_SCREENSHOT!\n");
5342 if(CONTROL_OK
!=((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_SCREENSHOT
, &cmd
->args
[0].v
.i
))
5343 video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
5346 case MP_CMD_VF_CHANGE_RECTANGLE
:
5347 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
5350 case MP_CMD_GET_TIME_LENGTH
: {
5351 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
5354 case MP_CMD_GET_FILENAME
: {
5355 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_FILENAME='%s'\n", get_metadata (META_NAME
));
5358 case MP_CMD_GET_VIDEO_CODEC
: {
5359 char *inf
= get_metadata (META_VIDEO_CODEC
);
5360 if (!inf
) inf
= strdup ("");
5361 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_CODEC='%s'\n", inf
);
5365 case MP_CMD_GET_VIDEO_BITRATE
: {
5366 char *inf
= get_metadata (META_VIDEO_BITRATE
);
5367 if (!inf
) inf
= strdup ("");
5368 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_BITRATE='%s'\n", inf
);
5372 case MP_CMD_GET_VIDEO_RESOLUTION
: {
5373 char *inf
= get_metadata (META_VIDEO_RESOLUTION
);
5374 if (!inf
) inf
= strdup ("");
5375 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_RESOLUTION='%s'\n", inf
);
5379 case MP_CMD_GET_AUDIO_CODEC
: {
5380 char *inf
= get_metadata (META_AUDIO_CODEC
);
5381 if (!inf
) inf
= strdup ("");
5382 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_CODEC='%s'\n", inf
);
5386 case MP_CMD_GET_AUDIO_BITRATE
: {
5387 char *inf
= get_metadata (META_AUDIO_BITRATE
);
5388 if (!inf
) inf
= strdup ("");
5389 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_BITRATE='%s'\n", inf
);
5393 case MP_CMD_GET_AUDIO_SAMPLES
: {
5394 char *inf
= get_metadata (META_AUDIO_SAMPLES
);
5395 if (!inf
) inf
= strdup ("");
5396 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_SAMPLES='%s'\n", inf
);
5400 case MP_CMD_GET_META_TITLE
: {
5401 char *inf
= get_metadata (META_INFO_TITLE
);
5402 if (!inf
) inf
= strdup ("");
5403 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TITLE='%s'\n", inf
);
5407 case MP_CMD_GET_META_ARTIST
: {
5408 char *inf
= get_metadata (META_INFO_ARTIST
);
5409 if (!inf
) inf
= strdup ("");
5410 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ARTIST='%s'\n", inf
);
5414 case MP_CMD_GET_META_ALBUM
: {
5415 char *inf
= get_metadata (META_INFO_ALBUM
);
5416 if (!inf
) inf
= strdup ("");
5417 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ALBUM='%s'\n", inf
);
5421 case MP_CMD_GET_META_YEAR
: {
5422 char *inf
= get_metadata (META_INFO_YEAR
);
5423 if (!inf
) inf
= strdup ("");
5424 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_YEAR='%s'\n", inf
);
5428 case MP_CMD_GET_META_COMMENT
: {
5429 char *inf
= get_metadata (META_INFO_COMMENT
);
5430 if (!inf
) inf
= strdup ("");
5431 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_COMMENT='%s'\n", inf
);
5435 case MP_CMD_GET_META_TRACK
: {
5436 char *inf
= get_metadata (META_INFO_TRACK
);
5437 if (!inf
) inf
= strdup ("");
5438 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TRACK='%s'\n", inf
);
5442 case MP_CMD_GET_META_GENRE
: {
5443 char *inf
= get_metadata (META_INFO_GENRE
);
5444 if (!inf
) inf
= strdup ("");
5445 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_GENRE='%s'\n", inf
);
5449 case MP_CMD_GET_VO_FULLSCREEN
: {
5450 if(video_out
&& vo_config_count
)
5451 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VO_FULLSCREEN=%d\n", vo_fs
);
5454 case MP_CMD_GET_PERCENT_POS
: {
5455 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer
));
5457 case MP_CMD_GET_TIME_POS
: {
5460 pos
= sh_video
->pts
;
5462 if (sh_audio
&& audio_out
)
5463 pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
5464 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
5469 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
5474 case MP_CMD_KEYDOWN_EVENTS
: {
5475 mplayer_put_key(cmd
->args
[0].v
.i
);
5477 case MP_CMD_SEEK_CHAPTER
: {
5478 int seek
= cmd
->args
[0].v
.i
;
5479 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
5487 chap
= demuxer_seek_chapter(demuxer
, seek
, abs
, &next_pts
, &num_chapters
, &chapter_name
);
5489 if(next_pts
> -1.0) {
5491 rel_seek_secs
= next_pts
;
5494 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
,
5495 chap
+1, chapter_name
);
5500 rel_seek_secs
= 1000000000.;
5502 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
, 0, MSGTR_Unknown
);
5506 case MP_CMD_SET_MOUSE_POS
: {
5507 int button
= -1, pointer_x
, pointer_y
;
5509 pointer_x
= cmd
->args
[0].v
.i
;
5510 pointer_y
= cmd
->args
[1].v
.i
;
5511 rescale_input_coordinates(pointer_x
, pointer_y
, &dx
, &dy
);
5513 if(stream
->type
== STREAMTYPE_DVDNAV
&& dx
> 0.0 && dy
> 0.0) {
5514 pointer_x
= (int) (dx
* (double) sh_video
->disp_w
);
5515 pointer_y
= (int) (dy
* (double) sh_video
->disp_h
);
5516 mp_dvdnav_update_mouse_pos(stream
, pointer_x
, pointer_y
, &button
);
5517 if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5523 case MP_CMD_DVDNAV
: {
5525 if(stream
->type
!= STREAMTYPE_DVDNAV
) break;
5527 if(mp_dvdnav_handle_input(stream
, cmd
->args
[0].v
.i
, &button
)) {
5528 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
|(fixed_vo
? INITED_VO
: 0)));
5529 goto goto_enable_cache
;
5530 } else if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5536 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
5539 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
5542 switch (cmd
->pausing
) {
5543 case 1: // "pausing"
5544 osd_function
= OSD_PAUSE
;
5546 case 3: // "pausing_toggle"
5547 was_paused
= !was_paused
;
5549 case 2: // "pausing_keep"
5550 if (was_paused
) osd_function
= OSD_PAUSE
;
5560 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
5561 rel_seek_secs
+= 3600*a
+60*b
+d
;
5562 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
5563 rel_seek_secs
+= 60*a
+d
;
5564 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
5570 if (end_at
.type
!= END_AT_NONE
) {
5571 if(end_at
.type
== END_AT_SIZE
) {
5572 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
5573 end_at
.type
= END_AT_NONE
;
5575 end_at
.pos
+= rel_seek_secs
;
5580 if(eof
==1 && loop_times
>=0) {
5582 play_tree_iter_step(playtree_iter
,0,0);
5584 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
5586 if(loop_times
>1) loop_times
--; else
5587 if(loop_times
==1) loop_times
=-1;
5588 play_n_frames
=play_n_frames_mf
;
5590 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
5594 if(rel_seek_secs
|| abs_seek_pos
){
5595 current_module
="seek";
5596 if(demux_seek(demuxer
,rel_seek_secs
,audio_delay
,abs_seek_pos
)){
5598 /* FIXME there should be real seeking for vobsub */
5599 if(sh_video
) sh_video
->pts
=d_video
->pts
;
5601 //vobsub_reset(vo_vobsub);
5602 vobsub_seek(vo_vobsub
,sh_video
->pts
);
5606 current_module
="seek_video_reset";
5607 resync_video_stream(sh_video
);
5608 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
5609 sh_video
->num_buffered_pts
= 0;
5610 sh_video
->last_pts
= MP_NOPTS_VALUE
;
5614 current_module
="seek_audio_reset";
5615 audio_out
->reset(); // stop audio, throwing away buffered data
5616 sh_audio
->a_buffer_len
= 0;
5617 sh_audio
->a_out_buffer_len
= 0;
5622 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer
));
5627 max_pts_correction
=0.1;
5628 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
5629 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
5632 if(vo_spudec
) spudec_reset(vo_spudec
);
5636 * We saw a seek, have to rewind the EDL operations stack
5637 * and find the next EDL action to take care of.
5641 next_edl_record
= edl_records
;
5643 while (next_edl_record
)
5645 /* Trying to remember if we need to mute/unmute first;
5646 * prior EDL implementation lacks this.
5649 if (next_edl_record
->start_sec
>= sh_video
->pts
)
5652 if (next_edl_record
->action
== EDL_MUTE
) edl_muted
= !edl_muted
;
5653 next_edl_record
= next_edl_record
->next
;
5656 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
5660 frame_time_remaining
=0;
5661 current_module
=NULL
;
5668 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
5669 // get pos from frame number / total frames
5670 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
5672 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
5673 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
5674 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
5676 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
5677 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
5678 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
5679 guiGetEvent( guiReDraw
,NULL
);
5680 guiGetEvent( guiSetVolume
,NULL
);
5681 if(guiIntfStruct
.Playing
==0) break; // STOP
5682 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
5683 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
5685 if ( stream
->type
== STREAMTYPE_DVD
)
5687 dvd_priv_t
* dvdp
= stream
->priv
;
5688 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
5692 #endif /* HAVE_NEW_GUI */
5696 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
5698 #ifdef HAS_DVBIN_SUPPORT
5702 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
5703 cache_uninit(stream
);
5705 goto goto_enable_cache
;
5710 goto_next_file
: // don't jump here after ao/vo/getch initialization!
5712 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
5715 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
5716 double total_time_usage
;
5717 total_time_usage_start
=GetTimer()-total_time_usage_start
;
5718 total_time_usage
= (float)total_time_usage_start
*0.000001;
5719 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5720 video_time_usage
,vout_time_usage
,audio_time_usage
,
5721 total_time_usage
-tot
,total_time_usage
);
5722 if(total_time_usage
>0.0)
5723 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5724 100.0*video_time_usage
/total_time_usage
,
5725 100.0*vout_time_usage
/total_time_usage
,
5726 100.0*audio_time_usage
/total_time_usage
,
5727 100.0*(total_time_usage
-tot
)/total_time_usage
,
5729 if(total_frame_cnt
&& frame_dropping
)
5730 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5731 total_frame_cnt
-drop_frame_cnt
,
5732 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
5734 100*drop_frame_cnt
/total_frame_cnt
,
5736 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
5740 // time to uninit all, except global stuff:
5741 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
5743 if ( set_of_sub_size
> 0 )
5745 current_module
="sub_free";
5746 for (i
= 0; i
< set_of_sub_size
; ++i
) {
5747 sub_free( set_of_subtitles
[i
] );
5749 if ( set_of_ass_tracks
[i
] )
5750 ass_free_track( set_of_ass_tracks
[i
] );
5753 set_of_sub_size
= 0;
5755 vo_sub_last
= vo_sub
=NULL
;
5761 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
5762 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
5763 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
5766 play_tree_iter_free(playtree_iter
);
5767 playtree_iter
= NULL
;
5770 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
5771 eof
= eof
== PT_UP_NEXT
? 1 : -1;
5772 if ( playtree_iter
) {
5773 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
5776 play_tree_iter_free(playtree_iter
);
5777 playtree_iter
= NULL
;
5780 } else { // NEXT PREV SRC
5781 eof
= eof
== PT_PREV_SRC
? -1 : 1;
5784 if(eof
== 0) eof
= 1;
5786 while(playtree_iter
!= NULL
) {
5787 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
5788 if(filename
== NULL
) {
5789 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
5790 play_tree_iter_free(playtree_iter
);
5791 playtree_iter
= NULL
;
5798 if( use_gui
&& !playtree_iter
)
5801 if ( !guiIntfStruct
.DiskChanged
)
5807 if(use_gui
|| playtree_iter
!= NULL
|| player_idle_mode
){
5808 if (!playtree_iter
) filename
= NULL
;
5810 goto play_next_file
;
5814 exit_player_with_rc(MSGTR_Exit_eof
, 0);