3 /// \ingroup Properties Command2Property OSDMsgStack
10 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
16 // #include <sys/mman.h>
17 #include <sys/types.h>
19 #include <sys/ioctl.h>
22 #define SIGHUP 1 /* hangup */
23 #define SIGQUIT 3 /* quit */
24 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
25 #define SIGBUS 10 /* bus error */
26 #define SIGPIPE 13 /* broken pipe */
27 extern int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
);
44 #define HELP_MP_DEFINE_STATIC
49 #include "m_property.h"
51 #include "cfg-mplayer-def.h"
54 #include "subreader.h"
57 #include "libvo/video_out.h"
59 #include "libvo/font_load.h"
60 #include "libvo/sub.h"
63 #include "libvo/x11_common.h"
66 #include "libao2/audio_out.h"
68 #include "codec-cfg.h"
75 #include "osdep/getch2.h"
76 #include "osdep/timer.h"
78 #include "cpudetect.h"
81 #include "Gui/interface.h"
84 #include "input/input.h"
87 int player_idle_mode
=0;
89 int enable_mouse_movements
=0;
92 char * proc_priority
=NULL
;
95 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
99 #include <linux/rtc.h>
102 #define RTC_IRQP_SET RTCIO_IRQP_SET
103 #define RTC_PIE_ON RTCIO_PIE_ON
104 #endif /* __linux__ */
105 #endif /* HAVE_RTC */
108 #include "stream/tv.h"
111 #include "stream/stream_radio.h"
114 #ifdef HAS_DVBIN_SUPPORT
115 #include "stream/dvbin.h"
116 static int last_dvb_step
= 1;
117 static int dvbin_reopen
= 0;
118 #include "stream/cache2.h"
121 //**************************************************************************//
123 //**************************************************************************//
124 #include "playtree.h"
125 #include "playtreeparser.h"
128 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
129 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
132 play_tree_t
* playtree
;
133 play_tree_iter_t
* playtree_iter
= NULL
;
134 static int play_tree_step
= 1;
136 #define PT_NEXT_ENTRY 1
137 #define PT_PREV_ENTRY -1
138 #define PT_NEXT_SRC 2
139 #define PT_PREV_SRC -2
141 #define PT_UP_PREV -3
143 //**************************************************************************//
145 //**************************************************************************//
146 #include "parser-cfg.h"
147 #include "parser-mpcmd.h"
151 //**************************************************************************//
153 //**************************************************************************//
155 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
157 static int cfg_include(m_option_t
*conf
, char *filename
){
158 return m_config_parse_config_file(mconfig
, filename
);
161 #include "get_path.c"
163 //**************************************************************************//
165 //**************************************************************************//
168 void xscreensaver_heartbeat(void);
171 //**************************************************************************//
172 //**************************************************************************//
173 // Input media streaming & demultiplexer:
174 //**************************************************************************//
176 static int max_framesize
=0;
178 #include "stream/stream.h"
179 #include "libmpdemux/demuxer.h"
180 #include "libmpdemux/stheader.h"
181 //#include "parse_es.h"
182 #include "libmpdemux/matroska.h"
185 #include "stream/stream_dvd.h"
188 #include "libmpcodecs/dec_audio.h"
189 #include "libmpcodecs/dec_video.h"
190 #include "libmpcodecs/mp_image.h"
191 #include "libmpcodecs/vf.h"
192 #include "libmpcodecs/vd.h"
194 //**************************************************************************//
196 static void reinit_audio_chain(void);
198 //**************************************************************************//
199 //**************************************************************************//
201 // Common FIFO functions, and keyboard/event FIFO code
203 int noconsolecontrols
=0;
204 //**************************************************************************//
206 vo_functions_t
*video_out
=NULL
;
207 ao_functions_t
*audio_out
=NULL
;
213 double video_time_usage
=0;
214 double vout_time_usage
=0;
215 static double audio_time_usage
=0;
216 static int total_time_usage_start
=0;
217 static int total_frame_cnt
=0;
218 static int drop_frame_cnt
=0; // total number of dropped frames
223 static int output_quality
=0;
225 float playback_speed
=1.0;
233 static int list_properties
= 0;
235 #define MAX_OSD_LEVEL 3
236 #define MAX_TERM_OSD_LEVEL 1
239 int osd_level_saved
=-1;
240 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
241 unsigned int osd_visible
;
242 static int osd_function
=OSD_PLAY
;
243 static int osd_show_percentage
= 0;
244 static int osd_duration
= 1000;
246 static int term_osd
= 1;
247 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
248 static char* playing_msg
= NULL
;
250 static char *seek_to_sec
=NULL
;
251 static off_t seek_to_byte
=0;
252 static off_t step_sec
=0;
253 static int loop_times
=-1;
254 static int loop_seek
=0;
256 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
259 int autosync
=0; // 30 might be a good default value.
261 // may be changed by GUI: (FIXME!)
262 float rel_seek_secs
=0;
266 char **audio_codec_list
=NULL
; // override audio codec
267 char **video_codec_list
=NULL
; // override video codec
268 char **audio_fm_list
=NULL
; // override audio codec family
269 char **video_fm_list
=NULL
; // override video codec family
272 extern char *demuxer_name
; // override demuxer
273 extern char *audio_demuxer_name
; // override audio demuxer
274 extern char *sub_demuxer_name
; // override sub demuxer
281 char* audio_lang
=NULL
;
282 char* dvdsub_lang
=NULL
;
283 static char* spudec_ifo
=NULL
;
284 char* filename
=NULL
; //"MI2-Trailer.avi";
285 int forced_subs_only
=0;
289 int stream_cache_size
=-1;
290 #ifdef USE_STREAM_CACHE
291 extern int cache_fill_status
;
293 float stream_cache_min_percent
=20.0;
294 float stream_cache_seek_min_percent
=50.0;
296 #define cache_fill_status 0
300 static char *stream_dump_name
="stream.dump";
301 int stream_dump_type
=0;
304 static float default_max_pts_correction
=-1;//0.01f;
305 static float max_pts_correction
=0;//default_max_pts_correction;
306 static float c_total
=0;
308 static int ignore_start
=0;
310 static int softsleep
=0;
313 static int force_srate
=0;
314 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
315 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
316 static int play_n_frames
=-1;
317 static int play_n_frames_mf
=-1;
320 char** video_driver_list
=NULL
;
321 char** audio_driver_list
=NULL
;
323 extern char *vo_subdevice
;
324 extern char *ao_subdevice
;
326 // codec outfmt flags (defined in libmpcodecs/vd.c)
330 char *font_name
=NULL
;
331 #ifdef HAVE_FONTCONFIG
332 extern int font_fontconfig
;
334 float font_factor
=0.75;
335 char **sub_name
=NULL
;
339 char *vobsub_name
=NULL
;
340 /*DSP!!char *dsp=NULL;*/
342 int suboverlap_enabled
= 1;
344 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
345 int set_of_sub_size
= 0;
346 int set_of_sub_pos
= -1;
347 float sub_last_pts
= -303;
349 int global_sub_size
= 0; // this encompasses all subtitle sources
350 int global_sub_pos
= -1; // this encompasses all subtitle sources
351 #define SUB_SOURCE_SUBS 0
352 #define SUB_SOURCE_VOBSUB 1
353 #define SUB_SOURCE_DEMUX 2
354 #define SUB_SOURCES 3
355 int global_sub_indices
[SUB_SOURCES
];
358 #include "libass/ass.h"
359 #include "libass/ass_mp.h"
361 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
362 // or NULL if format unsupported
363 ass_track_t
* set_of_ass_tracks
[MAX_SUBTITLE_FILES
];
364 ass_track_t
* ass_track
= 0; // current track to render
367 extern int mp_msg_levels
[MSGT_MAX
];
368 extern int mp_msg_level_all
;
370 static stream_t
* stream
=NULL
;
371 static demuxer_t
*demuxer
=NULL
;
372 static sh_audio_t
*sh_audio
=NULL
;
373 static sh_video_t
*sh_video
=NULL
;
374 static demux_stream_t
*d_audio
=NULL
;
375 static demux_stream_t
*d_video
=NULL
;
376 static demux_stream_t
*d_dvdsub
=NULL
;
378 char* current_module
=NULL
; // for debugging
380 extern int vo_gamma_gamma
;
381 extern int vo_gamma_brightness
;
382 extern int vo_gamma_contrast
;
383 extern int vo_gamma_saturation
;
384 extern int vo_gamma_hue
;
389 #include "m_struct.h"
390 #include "libmenu/menu.h"
391 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
392 extern vf_info_t vf_info_menu
;
393 static vf_info_t
* libmenu_vfs
[] = {
397 static vf_instance_t
* vf_menu
= NULL
;
398 static int use_menu
= 0;
399 static char* menu_cfg
= NULL
;
400 static char* menu_root
= "main";
405 static int nortc
= 1;
406 static char* rtc_device
;
409 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
410 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
411 short user_muted
= 0; ///< Stores whether user wanted muted mode.
412 short edl_muted
= 0; ///< Stores whether EDL is currently in muted mode.
413 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
414 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
415 float begin_skip
= MP_NOPTS_VALUE
; ///< start time of the current skip while on edlout mode
416 int use_filedir_conf
;
418 static unsigned int inited_flags
=0;
422 #define INITED_GETCH2 8
423 #define INITED_SPUDEC 32
424 #define INITED_STREAM 64
425 #define INITED_INPUT 128
426 #define INITED_VOBSUB 256
427 #define INITED_DEMUXER 512
428 #define INITED_ACODEC 1024
429 #define INITED_VCODEC 2048
430 #define INITED_ALL 0xFFFF
432 #include "metadata.h"
434 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
436 static int is_valid_metadata_type (metadata_t type
) {
439 /* check for valid video stream */
440 case META_VIDEO_CODEC
:
441 case META_VIDEO_BITRATE
:
442 case META_VIDEO_RESOLUTION
:
449 /* check for valid audio stream */
450 case META_AUDIO_CODEC
:
451 case META_AUDIO_BITRATE
:
452 case META_AUDIO_SAMPLES
:
459 /* check for valid demuxer */
460 case META_INFO_TITLE
:
461 case META_INFO_ARTIST
:
462 case META_INFO_ALBUM
:
464 case META_INFO_COMMENT
:
465 case META_INFO_TRACK
:
466 case META_INFO_GENRE
:
480 static char *get_demuxer_info (char *tag
) {
481 char **info
= demuxer
->info
;
487 for (n
= 0; info
[2*n
] != NULL
; n
++)
488 if (!strcmp (info
[2*n
], tag
))
491 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
494 char *get_metadata (metadata_t type
) {
497 if (!is_valid_metadata_type (type
))
504 return strdup (mp_basename2 (filename
));
507 case META_VIDEO_CODEC
:
509 if (sh_video
->format
== 0x10000001)
510 meta
= strdup ("mpeg1");
511 else if (sh_video
->format
== 0x10000002)
512 meta
= strdup ("mpeg2");
513 else if (sh_video
->format
== 0x10000004)
514 meta
= strdup ("mpeg4");
515 else if (sh_video
->format
== 0x10000005)
516 meta
= strdup ("h264");
517 else if (sh_video
->format
>= 0x20202020)
519 meta
= (char *) malloc (8);
520 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
524 meta
= (char *) malloc (8);
525 sprintf (meta
, "0x%08X", sh_video
->format
);
530 case META_VIDEO_BITRATE
:
532 meta
= (char *) malloc (16);
533 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
537 case META_VIDEO_RESOLUTION
:
539 meta
= (char *) malloc (16);
540 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
544 case META_AUDIO_CODEC
:
546 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
547 meta
= strdup (sh_audio
->codec
->name
);
551 case META_AUDIO_BITRATE
:
553 meta
= (char *) malloc (16);
554 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
558 case META_AUDIO_SAMPLES
:
560 meta
= (char *) malloc (16);
561 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
565 /* check for valid demuxer */
566 case META_INFO_TITLE
:
567 return get_demuxer_info ("Title");
569 case META_INFO_ARTIST
:
570 return get_demuxer_info ("Artist");
572 case META_INFO_ALBUM
:
573 return get_demuxer_info ("Album");
576 return get_demuxer_info ("Year");
578 case META_INFO_COMMENT
:
579 return get_demuxer_info ("Comment");
581 case META_INFO_TRACK
:
582 return get_demuxer_info ("Track");
584 case META_INFO_GENRE
:
585 return get_demuxer_info ("Genre");
594 static void uninit_player(unsigned int mask
){
595 mask
=inited_flags
&mask
;
597 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
599 if(mask
&INITED_ACODEC
){
600 inited_flags
&=~INITED_ACODEC
;
601 current_module
="uninit_acodec";
602 if(sh_audio
) uninit_audio(sh_audio
);
604 guiGetEvent(guiSetAfilter
, (char *)NULL
);
609 if(mask
&INITED_VCODEC
){
610 inited_flags
&=~INITED_VCODEC
;
611 current_module
="uninit_vcodec";
612 if(sh_video
) uninit_video(sh_video
);
619 if(mask
&INITED_DEMUXER
){
620 inited_flags
&=~INITED_DEMUXER
;
621 current_module
="free_demuxer";
623 stream
=demuxer
->stream
;
624 free_demuxer(demuxer
);
629 // kill the cache process:
630 if(mask
&INITED_STREAM
){
631 inited_flags
&=~INITED_STREAM
;
632 current_module
="uninit_stream";
633 if(stream
) free_stream(stream
);
638 inited_flags
&=~INITED_VO
;
639 current_module
="uninit_vo";
644 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
645 if(mask
&INITED_GETCH2
){
646 inited_flags
&=~INITED_GETCH2
;
647 current_module
="uninit_getch2";
648 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
653 if(mask
&INITED_VOBSUB
){
654 inited_flags
&=~INITED_VOBSUB
;
655 current_module
="uninit_vobsub";
656 if(vo_vobsub
) vobsub_close(vo_vobsub
);
660 if (mask
&INITED_SPUDEC
){
661 inited_flags
&=~INITED_SPUDEC
;
662 current_module
="uninit_spudec";
663 spudec_free(vo_spudec
);
668 inited_flags
&=~INITED_AO
;
669 current_module
="uninit_ao";
670 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
675 inited_flags
&=~INITED_GUI
;
676 current_module
="uninit_gui";
681 if(mask
&INITED_INPUT
){
682 inited_flags
&=~INITED_INPUT
;
683 current_module
="uninit_input";
690 static void exit_player_with_rc(const char* how
, int rc
){
692 uninit_player(INITED_ALL
);
697 vo_uninit(); // Close the X11 connection (if any is open).
701 current_module
="uninit_font";
702 if (vo_font
) free_font_desc(vo_font
);
709 ass_library_done(ass_library
);
712 current_module
="exit_player";
714 // free mplayer config
716 m_config_free(mconfig
);
719 play_tree_free(playtree
, 1);
722 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
723 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
724 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
729 void exit_player(const char* how
){
730 exit_player_with_rc(how
, 1);
734 static void child_sighandler(int x
){
736 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
741 static char *prog_path
;
742 static int crash_debug
= 0;
745 static void exit_sighandler(int x
){
746 static int sig_count
=0;
748 if (!crash_debug
|| x
!= SIGTRAP
)
751 if(inited_flags
==0 && sig_count
>1) exit(1);
754 /* We're crashing bad and can't uninit cleanly :(
755 * by popular request, we make one last (dirty)
756 * effort to restore the user's
761 if(sig_count
==6) exit(1);
765 kill(getpid(),SIGKILL
);
768 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
769 current_module
?current_module
:"unknown"
771 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
778 break; // killed from keyboard (^C) or killed [-9]
780 #ifdef RUNTIME_CPUDETECT
781 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
783 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
787 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
789 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
794 snprintf(spid
, 19, "%i", getpid());
796 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
798 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
799 if (gdb_pid
== 0) { // We are the child
800 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
801 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
802 } else if (gdb_pid
< 0)
803 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
805 waitpid(gdb_pid
, NULL
, 0);
807 if (x
== SIGTRAP
) return;
814 extern void mp_input_register_options(m_config_t
* cfg
);
818 /// step size of mixer changes
821 #include "cfg-mplayer.h"
823 static void parse_cfgfiles( m_config_t
* conf
)
827 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
829 if ((conffile
= get_path("")) == NULL
) {
830 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
835 mkdir(conffile
, 0777);
838 if ((conffile
= get_path("config")) == NULL
) {
839 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
841 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
842 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
843 write(conffile_fd
, default_config
, strlen(default_config
));
846 if (m_config_parse_config_file(conf
, conffile
) < 0)
853 void load_per_file_config (m_config_t
* conf
, const char *const file
)
856 char cfg
[strlen(file
)+10];
860 sprintf (cfg
, "%s.conf", file
);
862 if (use_filedir_conf
&& !stat (cfg
, &st
))
864 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
865 m_config_parse_config_file (conf
, cfg
);
869 if ((name
= strrchr (cfg
, '/')) == NULL
)
874 if ((confpath
= get_path (name
)) != NULL
)
876 if (!stat (confpath
, &st
))
878 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
879 m_config_parse_config_file (conf
, confpath
);
886 /* When libmpdemux performs a blocking operation (network connection or
887 * cache filling) if the operation fails we use this function to check
888 * if it was interrupted by the user.
889 * The function returns a new value for eof. */
890 static int libmpdemux_was_interrupted(int eof
) {
892 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
895 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
896 case MP_CMD_PLAY_TREE_STEP
: {
897 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
898 play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
900 case MP_CMD_PLAY_TREE_UP_STEP
: {
901 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
903 case MP_CMD_PLAY_ALT_SRC_STEP
: {
904 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
912 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
914 int playtree_add_playlist(play_tree_t
* entry
)
916 play_tree_add_bpf(entry
,filename
);
921 import_playtree_playlist_into_gui(entry
, mconfig
);
922 play_tree_free_list(entry
,1);
928 entry
= playtree_iter
->tree
;
929 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
930 return PT_NEXT_ENTRY
;
932 if(playtree_iter
->tree
== entry
) { // Loop with a single file
933 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
934 return PT_NEXT_ENTRY
;
937 play_tree_remove(entry
,1,1);
940 play_tree_insert_entry(playtree_iter
->tree
,entry
);
941 play_tree_set_params_from(entry
,playtree_iter
->tree
);
942 entry
= playtree_iter
->tree
;
943 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
944 return PT_NEXT_ENTRY
;
946 play_tree_remove(entry
,1,1);
956 for (i
= 0; i
< SUB_SOURCES
; i
++) {
957 int j
= global_sub_indices
[i
];
958 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
968 sub_data
* subdata
= NULL
;
969 static subtitle
* vo_sub_last
= NULL
;
971 void add_subtitles(char *filename
, float fps
, int silent
)
975 ass_track_t
*asst
= 0;
978 if (filename
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
982 subd
= sub_read_file(filename
, fps
);
986 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
988 asst
= ass_read_file(ass_library
, filename
, 0);
990 if (ass_enabled
&& subd
&& !asst
)
991 asst
= ass_read_subdata(ass_library
, subd
, fps
);
993 if (!asst
&& !subd
&& !silent
)
997 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
1000 if (!asst
&& !subd
) return;
1001 set_of_ass_tracks
[set_of_sub_size
] = asst
;
1005 set_of_subtitles
[set_of_sub_size
] = subd
;
1006 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", set_of_sub_size
);
1007 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n", filename
);
1009 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, set_of_sub_size
, filename
);
1012 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1013 void update_set_of_subtitles(void)
1014 // subdata was changed, set_of_sub... have to be updated.
1017 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
1018 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
1019 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
1020 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
1022 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
1024 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
1025 set_of_subtitles
[set_of_sub_pos
] = subdata
;
1027 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
1028 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
1032 #endif /* USE_SUB */
1035 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1036 * make it all work is to use the builtin SDL-bootstrap code, which
1037 * will be done automatically by replacing our main() if we include SDL.h.
1039 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1044 * \brief append a formatted string
1045 * \param buf buffer to print into
1046 * \param pos position of terminating 0 in buf
1047 * \param len maximum number of characters in buf, not including terminating 0
1048 * \param format printf format string
1050 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1053 va_start(va
, format
);
1054 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1063 * \brief append time in the hh:mm:ss.f format
1064 * \param buf buffer to print into
1065 * \param pos position of terminating 0 in buf
1066 * \param len maximum number of characters in buf, not including terminating 0
1067 * \param time time value to convert/append
1069 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1070 long tenths
= 10 * time
;
1071 int f1
= tenths
% 10;
1072 int ss
= (tenths
/ 10) % 60;
1073 int mm
= (tenths
/ 600) % 60;
1074 int hh
= tenths
/ 36000;
1076 saddf(buf
, pos
, len
, "unknown");
1080 saddf(buf
, pos
, len
, "%2d:", hh
);
1081 if (hh
> 0 || mm
> 0)
1082 saddf(buf
, pos
, len
, "%02d:", mm
);
1083 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1087 * \brief print the status line
1088 * \param a_pos audio position
1089 * \param a_v A-V desynchronization
1090 * \param corr amount out A-V synchronization
1092 static void print_status(float a_pos
, float a_v
, float corr
)
1098 if (screen_width
> 0)
1099 width
= screen_width
;
1103 /* Windows command line is broken (MinGW's rxvt works, but we
1104 * should not depend on that). */
1107 line
= malloc(width
+ 1); // one additional char for the terminating null
1111 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1113 float len
= demuxer_get_time_length(demuxer
);
1114 saddf(line
, &pos
, width
, "(");
1115 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1116 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1117 sadd_hhmmssf(line
, &pos
, width
, len
);
1118 saddf(line
, &pos
, width
, ") ");
1124 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1127 if (sh_audio
&& sh_video
)
1128 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1132 saddf(line
, &pos
, width
, "%3d/%3d ",
1133 (int)sh_video
->num_frames
,
1134 (int)sh_video
->num_frames_decoded
);
1138 if (sh_video
->timer
> 0.5)
1139 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1140 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
1141 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
1142 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
1144 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1145 } else if (sh_audio
) {
1146 if (sh_audio
->delay
> 0.5)
1147 saddf(line
, &pos
, width
, "%4.1f%% ",
1148 100.0*audio_time_usage
/(double)sh_audio
->delay
);
1150 saddf(line
, &pos
, width
, "??,?%% ");
1155 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1157 #ifdef USE_STREAM_CACHE
1159 if (stream_cache_size
> 0)
1160 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1164 if (playback_speed
!= 1)
1165 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
1168 if (erase_to_end_of_line
) {
1170 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1172 memset(&line
[pos
], ' ', width
- pos
);
1174 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
1180 * \brief build a chain of audio filters that converts the input format
1181 * to the ao's format, taking into account the current playback_speed.
1182 * \param sh_audio describes the requested input format of the chain.
1183 * \param ao_data describes the requested output format of the chain.
1185 static int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1192 guiGetEvent(guiSetAfilter
, (char *)NULL
);
1194 mixer
.afilter
= NULL
;
1197 new_srate
= sh_audio
->samplerate
* playback_speed
;
1198 if (new_srate
!= ao_data
->samplerate
) {
1199 // limits are taken from libaf/af_resample.c
1200 if (new_srate
< 8000)
1202 if (new_srate
> 192000)
1204 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1206 result
= init_audio_filters(sh_audio
, new_srate
,
1207 sh_audio
->channels
, sh_audio
->sample_format
,
1208 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1209 ao_data
->outburst
* 4, ao_data
->buffersize
);
1210 mixer
.afilter
= sh_audio
->afilter
;
1212 guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1219 * \brief Log the currently displayed subtitle to a file
1221 * Logs the current or last displayed subtitle together with filename
1222 * and time information to ~/.mplayer/subtitle_log
1224 * Intended purpose is to allow convenient marking of bogus subtitles
1225 * which need to be fixed while watching the movie.
1228 static void log_sub(void){
1233 if (subdata
== NULL
|| vo_sub_last
== NULL
) return;
1234 fname
= get_path("subtitle_log");
1235 f
= fopen(fname
, "a");
1237 fprintf(f
, "----------------------------------------------------------\n");
1238 if (subdata
->sub_uses_time
) {
1239 fprintf(f
, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename
,
1240 vo_sub_last
->start
/360000, (vo_sub_last
->start
/6000)%60,
1241 (vo_sub_last
->start
/100)%60, vo_sub_last
->start
%100,
1242 vo_sub_last
->end
/360000, (vo_sub_last
->end
/6000)%60,
1243 (vo_sub_last
->end
/100)%60, vo_sub_last
->end
%100);
1245 fprintf(f
, "N: %s S: %ld E: %ld\n", filename
, vo_sub_last
->start
, vo_sub_last
->end
);
1247 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
1248 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
1252 #endif /* USE_SUB */
1254 /// \defgroup OSDMsgStack OSD message stack
1258 #define OSD_MSG_TV_CHANNEL 0
1259 #define OSD_MSG_TEXT 1
1260 #define OSD_MSG_SUB_DELAY 2
1261 #define OSD_MSG_SPEED 3
1262 #define OSD_MSG_OSD_STATUS 4
1263 #define OSD_MSG_BAR 5
1264 #define OSD_MSG_PAUSE 6
1265 #define OSD_MSG_RADIO_CHANNEL 7
1266 /// Base id for messages generated from the commmand to property bridge.
1267 #define OSD_MSG_PROPERTY 0x100
1270 typedef struct mp_osd_msg mp_osd_msg_t
;
1272 /// Previous message on the stack.
1276 int id
,level
,started
;
1277 /// Display duration in ms.
1281 /// OSD message stack.
1282 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1285 * \brief Add a message on the OSD message stack
1287 * If a message with the same id is already present in the stack
1288 * it is pulled on top of the stack, otherwise a new message is created.
1292 static void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1293 mp_osd_msg_t
*msg
,*last
=NULL
;
1297 // look if the id is already in the stack
1298 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1299 last
= msg
, msg
= msg
->prev
);
1300 // not found: alloc it
1302 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1303 msg
->prev
= osd_msg_stack
;
1304 osd_msg_stack
= msg
;
1305 } else if(last
) { // found, but it's not on top of the stack
1306 last
->prev
= msg
->prev
;
1307 msg
->prev
= osd_msg_stack
;
1308 osd_msg_stack
= msg
;
1312 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1314 if(r
>= 64) msg
->msg
[63] = 0;
1323 * \brief Remove a message from the OSD stack
1325 * This function can be used to get rid of a message right away.
1329 static void rm_osd_msg(int id
) {
1330 mp_osd_msg_t
*msg
,*last
=NULL
;
1332 // Search for the msg
1333 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1334 last
= msg
, msg
= msg
->prev
);
1337 // Detach it from the stack and free it
1339 last
->prev
= msg
->prev
;
1341 osd_msg_stack
= msg
->prev
;
1346 * \brief Remove all messages from the OSD stack
1350 static void clear_osd_msgs(void) {
1351 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1357 osd_msg_stack
= NULL
;
1361 * \brief Get the current message from the OSD stack.
1363 * This function decrements the message timer and destroys the old ones.
1364 * The message that should be displayed is returned (if any).
1368 static mp_osd_msg_t
* get_osd_msg(void) {
1369 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1370 static unsigned last_update
= 0;
1371 unsigned now
= GetTimerMS();
1373 char hidden_dec_done
= 0;
1375 if(!last_update
) last_update
= now
;
1376 diff
= now
>= last_update
? now
- last_update
: 0;
1380 // Look for the first message in the stack with high enough level.
1381 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1383 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1384 // The message has a high enough level or it is the first hidden one
1385 // in both cases we decrement the timer or kill it.
1386 if(!msg
->started
|| msg
->time
> diff
) {
1387 if(msg
->started
) msg
->time
-= diff
;
1388 else msg
->started
= 1;
1390 if(msg
->level
<= osd_level
) return msg
;
1391 hidden_dec_done
= 1;
1400 osd_msg_stack
= prev
;
1408 // Make a define to test if we are using the term OSD without having
1409 // to #ifdef USE_OSD all the time.
1411 #define use_term_osd (term_osd && !sh_video)
1413 #define use_term_osd (term_osd)
1417 * \brief Display the OSD bar.
1419 * Display the OSD bar or fall back on a simple message.
1423 void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1425 if(osd_level
< 1) return;
1429 osd_visible
= (GetTimerMS() + 1000) | 1;
1430 vo_osd_progbar_type
= type
;
1431 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1432 vo_osd_changed(OSDTYPE_PROGBAR
);
1437 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1438 name
,ROUND(100*(val
-min
)/(max
-min
)));
1443 * \brief Update the OSD message line.
1445 * This function displays the current message on the vo OSD or on the term.
1446 * If the stack is empty and the OSD level is high enough the timer
1447 * is displayed (only on the vo OSD).
1451 static void update_osd_msg(void) {
1453 static char osd_text
[64] = "";
1454 static char osd_text_timer
[64];
1457 // we need some mem for vo_osd_text
1458 vo_osd_text
= (unsigned char*)osd_text
;
1461 // Look if we have a msg
1462 if((msg
= get_osd_msg())) {
1463 if(strcmp(osd_text
,msg
->msg
)) {
1464 strncpy((char*)osd_text
, msg
->msg
, 63);
1466 if(sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1468 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1475 // fallback on the timer
1477 int len
= demuxer_get_time_length(demuxer
);
1478 int percentage
= -1;
1479 char percentage_text
[10];
1480 int pts
= demuxer_get_current_time(demuxer
);
1482 if (osd_show_percentage
)
1483 percentage
= demuxer_get_percent_pos(demuxer
);
1485 if (percentage
>= 0)
1486 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1488 percentage_text
[0] = 0;
1491 snprintf(osd_text_timer
, 63,
1492 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1493 osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1494 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1496 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1497 osd_function
,pts
/3600,(pts
/60)%60,
1498 pts
%60,percentage_text
);
1500 osd_text_timer
[0]=0;
1502 // always decrement the percentage timer
1503 if(osd_show_percentage
)
1504 osd_show_percentage
--;
1506 if(strcmp(osd_text
,osd_text_timer
)) {
1507 strncpy(osd_text
, osd_text_timer
, 63);
1508 vo_osd_changed(OSDTYPE_OSD
);
1514 // Clear the term osd line
1515 if(term_osd
&& osd_text
[0]) {
1517 printf("%s\n",term_osd_esc
);
1524 /// \defgroup Properties
1527 /// \defgroup GeneralProperties General properties
1528 /// \ingroup Properties
1532 static int mp_property_osdlevel(m_option_t
* prop
,int action
,void* arg
) {
1533 return m_property_choice(prop
,action
,arg
,&osd_level
);
1536 /// Playback speed (RW)
1537 static int mp_property_playback_speed(m_option_t
* prop
,int action
,void* arg
) {
1539 case M_PROPERTY_SET
:
1541 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1542 playback_speed
= *(float*)arg
;
1543 build_afilter_chain(sh_audio
, &ao_data
);
1545 case M_PROPERTY_STEP_UP
:
1546 case M_PROPERTY_STEP_DOWN
:
1547 playback_speed
+= (arg
? *(float*)arg
: 0.1) *
1548 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1549 M_PROPERTY_CLAMP(prop
,playback_speed
);
1550 build_afilter_chain(sh_audio
, &ao_data
);
1553 return m_property_float_range(prop
,action
,arg
,&playback_speed
);
1556 /// filename with path (RO)
1557 static int mp_property_path(m_option_t
* prop
,int action
,void* arg
) {
1558 return m_property_string_ro(prop
,action
,arg
,filename
);
1561 /// filename without path (RO)
1562 static int mp_property_filename(m_option_t
* prop
,int action
,void* arg
) {
1564 if(!filename
) return M_PROPERTY_UNAVAILABLE
;
1565 if(((f
= strrchr(filename
,'/')) || (f
= strrchr(filename
,'\\'))) && f
[1])
1569 return m_property_string_ro(prop
,action
,arg
,f
);
1572 /// Demuxer name (RO)
1573 static int mp_property_demuxer(m_option_t
* prop
,int action
,void* arg
) {
1574 if(!demuxer
) return M_PROPERTY_UNAVAILABLE
;
1575 return m_property_string_ro(prop
,action
,arg
,(char*)demuxer
->desc
->name
);
1578 /// Position in the stream (RW)
1579 static int mp_property_stream_pos(m_option_t
* prop
,int action
,void* arg
) {
1580 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1581 if (!arg
) return M_PROPERTY_ERROR
;
1583 case M_PROPERTY_GET
:
1584 *(off_t
*)arg
= stream_tell(demuxer
->stream
);
1585 return M_PROPERTY_OK
;
1586 case M_PROPERTY_SET
:
1587 M_PROPERTY_CLAMP(prop
,*(off_t
*)arg
);
1588 stream_seek(demuxer
->stream
, *(off_t
*)arg
);
1589 return M_PROPERTY_OK
;
1591 return M_PROPERTY_NOT_IMPLEMENTED
;
1594 /// Stream start offset (RO)
1595 static int mp_property_stream_start(m_option_t
* prop
,int action
,void* arg
) {
1596 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1598 case M_PROPERTY_GET
:
1599 *(off_t
*)arg
= demuxer
->stream
->start_pos
;
1600 return M_PROPERTY_OK
;
1602 return M_PROPERTY_NOT_IMPLEMENTED
;
1605 /// Stream end offset (RO)
1606 static int mp_property_stream_end(m_option_t
* prop
,int action
,void* arg
) {
1607 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1609 case M_PROPERTY_GET
:
1610 *(off_t
*)arg
= demuxer
->stream
->end_pos
;
1611 return M_PROPERTY_OK
;
1613 return M_PROPERTY_NOT_IMPLEMENTED
;
1616 /// Stream length (RO)
1617 static int mp_property_stream_length(m_option_t
* prop
,int action
,void* arg
) {
1618 if (!demuxer
|| !demuxer
->stream
) return M_PROPERTY_UNAVAILABLE
;
1620 case M_PROPERTY_GET
:
1621 *(off_t
*)arg
= demuxer
->stream
->end_pos
- demuxer
->stream
->start_pos
;
1622 return M_PROPERTY_OK
;
1624 return M_PROPERTY_NOT_IMPLEMENTED
;
1627 /// Media length in seconds (RO)
1628 static int mp_property_length(m_option_t
* prop
,int action
,void* arg
) {
1632 !(int)(len
= demuxer_get_time_length(demuxer
)))
1633 return M_PROPERTY_UNAVAILABLE
;
1636 case M_PROPERTY_PRINT
:
1644 *(char**)arg
= malloc(20);
1645 if(h
> 0) sprintf(*(char**)arg
,"%d:%02d:%02d",h
,m
,s
);
1646 else if(m
> 0) sprintf(*(char**)arg
,"%d:%02d",m
,s
);
1647 else sprintf(*(char**)arg
,"%d",s
);
1652 return m_property_double_ro(prop
,action
,arg
,len
);
1657 /// \defgroup AudioProperties Audio properties
1658 /// \ingroup Properties
1662 static int mp_property_volume(m_option_t
* prop
,int action
,void* arg
) {
1664 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1667 case M_PROPERTY_GET
:
1669 mixer_getbothvolume(&mixer
,arg
);
1671 case M_PROPERTY_PRINT
:{
1674 mixer_getbothvolume(&mixer
,&vol
);
1675 return m_property_float_range(prop
,action
,arg
,&vol
);
1677 case M_PROPERTY_STEP_UP
:
1678 case M_PROPERTY_STEP_DOWN
:
1679 case M_PROPERTY_SET
:
1682 return M_PROPERTY_NOT_IMPLEMENTED
;
1685 if (edl_muted
) return M_PROPERTY_DISABLED
;
1689 case M_PROPERTY_SET
:
1691 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1692 mixer_setvolume(&mixer
,*(float*)arg
,*(float*)arg
);
1694 case M_PROPERTY_STEP_UP
:
1695 if(arg
&& *(float*)arg
<= 0)
1696 mixer_decvolume(&mixer
);
1698 mixer_incvolume(&mixer
);
1700 case M_PROPERTY_STEP_DOWN
:
1701 if(arg
&& *(float*)arg
<= 0)
1702 mixer_incvolume(&mixer
);
1704 mixer_decvolume(&mixer
);
1707 return M_PROPERTY_NOT_IMPLEMENTED
;
1711 static int mp_property_mute(m_option_t
* prop
,int action
,void* arg
) {
1713 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1716 case M_PROPERTY_SET
:
1717 if(edl_muted
) return M_PROPERTY_DISABLED
;
1719 if((!!*(int*)arg
) != mixer
.muted
)
1721 user_muted
= mixer
.muted
;
1723 case M_PROPERTY_STEP_UP
:
1724 case M_PROPERTY_STEP_DOWN
:
1725 if(edl_muted
) return M_PROPERTY_DISABLED
;
1727 user_muted
= mixer
.muted
;
1729 case M_PROPERTY_PRINT
:
1732 *(char**)arg
= strdup(MSGTR_EnabledEdl
);
1736 return m_property_flag(prop
,action
,arg
,&mixer
.muted
);
1741 /// Audio delay (RW)
1742 static int mp_property_audio_delay(m_option_t
* prop
,int action
,void* arg
) {
1743 if(!(sh_audio
&& sh_video
)) return M_PROPERTY_UNAVAILABLE
;
1745 case M_PROPERTY_SET
:
1746 case M_PROPERTY_STEP_UP
:
1747 case M_PROPERTY_STEP_DOWN
:
1750 float delay
= audio_delay
;
1751 m_property_delay(prop
,action
,arg
,&audio_delay
);
1752 if(sh_audio
) sh_audio
->delay
-= audio_delay
-delay
;
1756 return m_property_delay(prop
,action
,arg
,&audio_delay
);
1760 /// Audio codec tag (RO)
1761 static int mp_property_audio_format(m_option_t
* prop
,int action
,void* arg
) {
1762 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1763 return m_property_int_ro(prop
,action
,arg
,sh_audio
->format
);
1766 /// Audio bitrate (RO)
1767 static int mp_property_audio_bitrate(m_option_t
* prop
,int action
,void* arg
) {
1768 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1769 return m_property_int_ro(prop
,action
,arg
,sh_audio
->i_bps
);
1773 static int mp_property_samplerate(m_option_t
* prop
,int action
,void* arg
) {
1774 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1775 return m_property_int_ro(prop
,action
,arg
,sh_audio
->samplerate
);
1778 /// Number of channels (RO)
1779 static int mp_property_channels(m_option_t
* prop
,int action
,void* arg
) {
1780 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1782 case M_PROPERTY_PRINT
:
1784 switch(sh_audio
->channels
) {
1785 case 1: *(char**)arg
= strdup("mono"); break;
1786 case 2: *(char**)arg
= strdup("stereo"); break;
1788 *(char**)arg
= malloc(32);
1789 sprintf(*(char**)arg
,"%d channels",sh_audio
->channels
);
1793 return m_property_int_ro(prop
,action
,arg
,sh_audio
->channels
);
1796 /// Selected audio id (RW)
1797 static int mp_property_audio(m_option_t
* prop
,int action
,void* arg
) {
1798 int current_id
= -1;
1800 if(!sh_audio
) return M_PROPERTY_UNAVAILABLE
;
1803 case M_PROPERTY_GET
:
1805 *(int*)arg
= audio_id
;
1807 case M_PROPERTY_PRINT
:
1811 *(char**)arg
= strdup(MSGTR_Disabled
);
1813 char lang
[40] = MSGTR_Unknown
;
1814 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
)
1815 demux_mkv_get_audio_lang(demuxer
, audio_id
, lang
, 9);
1818 int code
= dvd_lang_from_aid(stream
, audio_id
);
1820 lang
[0] = code
>> 8;
1826 *(char**)arg
= malloc(64);
1827 snprintf(*(char**)arg
, 64, "(%d) %s", audio_id
, lang
);
1831 case M_PROPERTY_STEP_UP
:
1832 current_id
= demuxer
->audio
->id
;
1833 audio_id
= demuxer_switch_audio(demuxer
, -1);
1834 if(audio_id
> -1 && demuxer
->audio
->id
!= current_id
) {
1836 uninit_player(INITED_AO
| INITED_ACODEC
);
1837 sh2
= demuxer
->a_streams
[demuxer
->audio
->id
];
1839 sh2
->ds
= demuxer
->audio
;
1841 reinit_audio_chain();
1844 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", audio_id
);
1848 return M_PROPERTY_NOT_IMPLEMENTED
;
1856 /// \defgroup VideoProperties Video properties
1857 /// \ingroup Properties
1860 /// Fullscreen state (RW)
1861 static int mp_property_fullscreen(m_option_t
* prop
,int action
,void* arg
) {
1863 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1866 case M_PROPERTY_SET
:
1868 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1869 if(vo_fs
== !!*(int*)arg
) return 1;
1870 case M_PROPERTY_STEP_UP
:
1871 case M_PROPERTY_STEP_DOWN
:
1873 if(use_gui
) guiGetEvent(guiIEvent
,(char*)MP_CMD_GUI_FULLSCREEN
);
1876 if(vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
1879 return m_property_flag(prop
,action
,arg
,&vo_fs
);
1884 static int mp_property_panscan(m_option_t
* prop
,int action
,void* arg
) {
1886 if(!video_out
|| video_out
->control(VOCTRL_GET_PANSCAN
,NULL
) != VO_TRUE
)
1887 return M_PROPERTY_UNAVAILABLE
;
1890 case M_PROPERTY_SET
:
1892 M_PROPERTY_CLAMP(prop
,*(float*)arg
);
1893 vo_panscan
= *(float*)arg
;
1894 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
1896 case M_PROPERTY_STEP_UP
:
1897 case M_PROPERTY_STEP_DOWN
:
1898 vo_panscan
+= (arg
? *(float*)arg
: 0.1) *
1899 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1900 if(vo_panscan
> 1) vo_panscan
= 1;
1901 else if(vo_panscan
< 0) vo_panscan
= 0;
1902 video_out
->control(VOCTRL_SET_PANSCAN
,NULL
);
1905 return m_property_float_range(prop
,action
,arg
,&vo_panscan
);
1909 /// Helper to set vo flags.
1910 /** \ingroup PropertyImplHelper
1912 static int mp_property_vo_flag(m_option_t
* prop
,int action
,void* arg
,
1913 int vo_ctrl
,int* vo_var
) {
1915 if(!video_out
) return M_PROPERTY_UNAVAILABLE
;
1918 case M_PROPERTY_SET
:
1920 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1921 if(*vo_var
== !!*(int*)arg
) return 1;
1922 case M_PROPERTY_STEP_UP
:
1923 case M_PROPERTY_STEP_DOWN
:
1924 if(vo_config_count
) video_out
->control(vo_ctrl
, 0);
1927 return m_property_flag(prop
,action
,arg
,vo_var
);
1931 /// Window always on top (RW)
1932 static int mp_property_ontop(m_option_t
* prop
,int action
,void* arg
) {
1933 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ONTOP
,&vo_ontop
);
1936 /// Display in the root window (RW)
1937 static int mp_property_rootwin(m_option_t
* prop
,int action
,void* arg
) {
1938 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_ROOTWIN
,&vo_rootwin
);
1941 /// Show window borders (RW)
1942 static int mp_property_border(m_option_t
* prop
,int action
,void* arg
) {
1943 return mp_property_vo_flag(prop
,action
,arg
,VOCTRL_BORDER
,&vo_border
);
1946 /// Framedropping state (RW)
1947 static int mp_property_framedropping(m_option_t
* prop
,int action
,void* arg
) {
1949 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1952 case M_PROPERTY_PRINT
:
1954 *(char**)arg
= strdup(frame_dropping
== 1 ? MSGTR_Enabled
:
1955 (frame_dropping
== 2 ? MSGTR_HardFrameDrop
: MSGTR_Disabled
));
1958 return m_property_choice(prop
,action
,arg
,&frame_dropping
);
1962 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1963 static int mp_property_gamma(m_option_t
* prop
,int action
,void* arg
) {
1964 int* gamma
= prop
->priv
, r
;
1966 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
1968 if(gamma
[0] == 1000) {
1970 get_video_colors (sh_video
, prop
->name
, gamma
);
1974 case M_PROPERTY_SET
:
1976 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
1977 *gamma
= *(int*)arg
;
1978 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
1981 case M_PROPERTY_GET
:
1983 r
= get_video_colors (sh_video
, prop
->name
, arg
);
1986 case M_PROPERTY_STEP_UP
:
1987 case M_PROPERTY_STEP_DOWN
:
1988 *gamma
+= (arg
? *(int*)arg
: 1) *
1989 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1990 M_PROPERTY_CLAMP(prop
,*gamma
);
1991 r
= set_video_colors(sh_video
, prop
->name
, *gamma
);
1995 return M_PROPERTY_NOT_IMPLEMENTED
;
1999 if(demuxer
->type
== DEMUXER_TYPE_TV
) {
2000 int l
= strlen(prop
->name
);
2001 char tv_prop
[3+l
+1];
2002 sprintf(tv_prop
,"tv_%s",prop
->name
);
2003 return mp_property_do(tv_prop
,action
,arg
);
2007 return M_PROPERTY_UNAVAILABLE
;
2011 static int mp_property_vsync(m_option_t
* prop
,int action
,void* arg
) {
2012 return m_property_flag(prop
,action
,arg
,&vo_vsync
);
2015 /// Video codec tag (RO)
2016 static int mp_property_video_format(m_option_t
* prop
,int action
,void* arg
) {
2017 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2018 return m_property_int_ro(prop
,action
,arg
,sh_video
->format
);
2021 /// Video bitrate (RO)
2022 static int mp_property_video_bitrate(m_option_t
* prop
,int action
,void* arg
) {
2023 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2024 return m_property_int_ro(prop
,action
,arg
,sh_video
->i_bps
);
2027 /// Video display width (RO)
2028 static int mp_property_width(m_option_t
* prop
,int action
,void* arg
) {
2029 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2030 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_w
);
2033 /// Video display height (RO)
2034 static int mp_property_height(m_option_t
* prop
,int action
,void* arg
) {
2035 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2036 return m_property_int_ro(prop
,action
,arg
,sh_video
->disp_h
);
2040 static int mp_property_fps(m_option_t
* prop
,int action
,void* arg
) {
2041 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2042 return m_property_float_ro(prop
,action
,arg
,sh_video
->fps
);
2045 /// Video aspect (RO)
2046 static int mp_property_aspect(m_option_t
* prop
,int action
,void* arg
) {
2047 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2048 return m_property_float_ro(prop
,action
,arg
,sh_video
->aspect
);
2053 /// \defgroup SubProprties Subtitles properties
2054 /// \ingroup Properties
2057 /// Text subtitle position (RW)
2058 static int mp_property_sub_pos(m_option_t
* prop
,int action
,void* arg
) {
2060 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2063 case M_PROPERTY_SET
:
2065 case M_PROPERTY_STEP_UP
:
2066 case M_PROPERTY_STEP_DOWN
:
2067 vo_osd_changed(OSDTYPE_SUBTITLE
);
2069 return m_property_int_range(prop
,action
,arg
,&sub_pos
);
2072 return M_PROPERTY_UNAVAILABLE
;
2076 /// Selected subtitles (RW)
2077 static int mp_property_sub(m_option_t
* prop
,int action
,void* arg
) {
2078 int source
= -1, reset_spu
= 0;
2081 if(global_sub_size
<= 0) return M_PROPERTY_UNAVAILABLE
;
2084 case M_PROPERTY_GET
:
2086 *(int*)arg
= global_sub_pos
;
2088 case M_PROPERTY_PRINT
:
2090 *(char**)arg
= malloc(64);
2091 (*(char**)arg
)[63] = 0;
2095 sub_name
= subdata
->filename
;
2098 if (ass_track
&& ass_track
->name
)
2099 sub_name
= ass_track
->name
;
2101 #if defined(USE_SUB) || defined(USE_ASS)
2105 if ((tmp2
= strrchr(tmp
, '/')))
2108 snprintf(*(char**)arg
, 63, "(%d) %s%s",
2110 strlen(tmp
) < 20 ? "" : "...",
2111 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
2115 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
&& dvdsub_id
>= 0) {
2116 char lang
[40] = MSGTR_Unknown
;
2117 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
2118 snprintf(*(char**)arg
, 63, "(%d) %s", dvdsub_id
, lang
);
2121 #ifdef HAVE_OGGVORBIS
2122 if (demuxer
->type
== DEMUXER_TYPE_OGG
&& d_dvdsub
&& dvdsub_id
>= 0) {
2123 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
2124 if (!lang
) lang
= MSGTR_Unknown
;
2125 snprintf(*(char**)arg
, 63, "(%d) %s",
2130 if (vo_vobsub
&& vobsub_id
>= 0) {
2131 const char *language
= MSGTR_Unknown
;
2132 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
2133 snprintf(*(char**)arg
, 63, "(%d) %s",
2134 vobsub_id
, language
? language
: MSGTR_Unknown
);
2138 if (vo_spudec
&& dvdsub_id
>= 0) {
2140 int code
= dvd_lang_from_sid(stream
, dvdsub_id
);
2141 lang
[0] = code
>> 8;
2144 snprintf(*(char**)arg
, 63, "(%d) %s",
2149 snprintf(*(char**)arg
, 63, MSGTR_Disabled
);
2152 case M_PROPERTY_SET
:
2154 if(*(int*)arg
< -1) *(int*)arg
= -1;
2155 else if(*(int*)arg
>= global_sub_size
) *(int*)arg
= global_sub_size
-1;
2156 global_sub_pos
= *(int*)arg
;
2158 case M_PROPERTY_STEP_UP
:
2159 global_sub_pos
+= 2;
2160 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2162 case M_PROPERTY_STEP_DOWN
:
2163 global_sub_pos
+= global_sub_size
+1;
2164 global_sub_pos
= (global_sub_pos
% (global_sub_size
+1)) - 1;
2167 return M_PROPERTY_NOT_IMPLEMENTED
;
2170 if (global_sub_pos
>= 0)
2171 source
= sub_source();
2173 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
,
2174 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
2175 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
2176 global_sub_indices
[SUB_SOURCE_SUBS
],
2177 global_sub_indices
[SUB_SOURCE_DEMUX
],
2178 global_sub_pos
, source
);
2181 set_of_sub_pos
= -1;
2183 vo_sub_last
= vo_sub
= NULL
;
2188 if(d_dvdsub
->id
> -2) reset_spu
= 1;
2195 if (source
== SUB_SOURCE_VOBSUB
) {
2196 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
2198 } else if (source
== SUB_SOURCE_SUBS
) {
2199 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
2201 if (ass_enabled
&& set_of_ass_tracks
[set_of_sub_pos
])
2202 ass_track
= set_of_ass_tracks
[set_of_sub_pos
];
2206 subdata
= set_of_subtitles
[set_of_sub_pos
];
2207 vo_osd_changed(OSDTYPE_SUBTITLE
);
2210 } else if (source
== SUB_SOURCE_DEMUX
) {
2211 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
2214 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
2215 d_dvdsub
->id
= dvdsub_id
;
2216 spudec_reset(vo_spudec
);
2219 #ifdef HAVE_OGGVORBIS
2220 if (demuxer
->type
== DEMUXER_TYPE_OGG
)
2221 d_dvdsub
->id
= demux_ogg_sub_id(demuxer
, dvdsub_id
);
2223 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
2224 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
2226 if (ass_enabled
&& (d_dvdsub
->id
>= 0) &&
2227 (((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'a')) {
2228 ass_track
= ((sh_sub_t
*)d_dvdsub
->sh
)->ass_track
;
2231 if (d_dvdsub
->id
>= 0 &&
2232 ((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v') {
2233 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)d_dvdsub
->sh
;
2234 if (vo_spudec
!= NULL
)
2235 spudec_free(vo_spudec
);
2237 spudec_new_scaled_vobsub(mkv_sh_sub
->has_palette
?
2238 mkv_sh_sub
->palette
:
2239 NULL
, mkv_sh_sub
->colors
,
2240 mkv_sh_sub
->custom_colors
,
2242 mkv_sh_sub
->height
);
2243 if (!forced_subs_only
)
2244 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
2246 spudec_set_forced_subs_only(vo_spudec
,
2248 inited_flags
|= INITED_SPUDEC
;
2255 vo_osd_changed(OSDTYPE_SUBTITLE
);
2257 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2260 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
&& dvdsub_id
< 0 && reset_spu
) {
2262 d_dvdsub
->id
= dvdsub_id
;
2263 spudec_reset(vo_spudec
);
2270 /// Subtitle delay (RW)
2271 static int mp_property_sub_delay(m_option_t
* prop
,int action
,void* arg
) {
2272 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2273 return m_property_delay(prop
,action
,arg
,&sub_delay
);
2276 /// Alignment of text subtitles (RW)
2277 static int mp_property_sub_alignment(m_option_t
* prop
,int action
,void* arg
) {
2279 char* name
[] = { MSGTR_Top
, MSGTR_Center
, MSGTR_Bottom
};
2281 if(!sh_video
|| global_sub_pos
< 0 || sub_source() != SUB_SOURCE_SUBS
)
2282 return M_PROPERTY_UNAVAILABLE
;
2285 case M_PROPERTY_PRINT
:
2287 M_PROPERTY_CLAMP(prop
,sub_alignment
);
2288 *(char**)arg
= strdup(name
[sub_alignment
]);
2290 case M_PROPERTY_SET
:
2292 case M_PROPERTY_STEP_UP
:
2293 case M_PROPERTY_STEP_DOWN
:
2294 vo_osd_changed(OSDTYPE_SUBTITLE
);
2296 return m_property_choice(prop
,action
,arg
,&sub_alignment
);
2299 return M_PROPERTY_UNAVAILABLE
;
2303 /// Subtitle visibility (RW)
2304 static int mp_property_sub_visibility(m_option_t
* prop
,int action
,void* arg
) {
2306 if(!sh_video
) return M_PROPERTY_UNAVAILABLE
;
2309 case M_PROPERTY_SET
:
2311 case M_PROPERTY_STEP_UP
:
2312 case M_PROPERTY_STEP_DOWN
:
2313 vo_osd_changed(OSDTYPE_SUBTITLE
);
2314 if(vo_spudec
) vo_osd_changed(OSDTYPE_SPU
);
2316 return m_property_flag(prop
,action
,arg
,&sub_visibility
);
2319 return M_PROPERTY_UNAVAILABLE
;
2323 /// Show only forced subtitles (RW)
2324 static int mp_property_sub_forced_only(m_option_t
* prop
,int action
,void* arg
) {
2325 if(!vo_spudec
) return M_PROPERTY_UNAVAILABLE
;
2328 case M_PROPERTY_SET
:
2330 case M_PROPERTY_STEP_UP
:
2331 case M_PROPERTY_STEP_DOWN
:
2332 m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2333 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
2336 return m_property_flag(prop
,action
,arg
,&forced_subs_only
);
2343 /// \defgroup TVProperties TV properties
2344 /// \ingroup Properties
2349 /// TV color settings (RW)
2350 static int mp_property_tv_color(m_option_t
* prop
,int action
,void* arg
) {
2352 tvi_handle_t
* tvh
= demuxer
->priv
;
2353 if(demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
) return M_PROPERTY_UNAVAILABLE
;
2356 case M_PROPERTY_SET
:
2358 M_PROPERTY_CLAMP(prop
,*(int*)arg
);
2359 return tv_set_color_options(tvh
,(int)prop
->priv
,*(int*)arg
);
2360 case M_PROPERTY_GET
:
2361 return tv_get_color_options(tvh
,(int)prop
->priv
,arg
);
2362 case M_PROPERTY_STEP_UP
:
2363 case M_PROPERTY_STEP_DOWN
:
2364 if((r
= tv_get_color_options(tvh
,(int)prop
->priv
,&val
)) >= 0) {
2366 val
+= (arg
? *(int*)arg
: 1) *
2367 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
2368 M_PROPERTY_CLAMP(prop
,val
);
2369 return tv_set_color_options(tvh
,(int)prop
->priv
,val
);
2373 return M_PROPERTY_NOT_IMPLEMENTED
;
2380 /// All properties available in MPlayer.
2381 /** \ingroup Properties
2383 static m_option_t mp_properties
[] = {
2385 { "osdlevel", mp_property_osdlevel
, CONF_TYPE_INT
,
2386 M_OPT_RANGE
, 0, 3, NULL
},
2387 { "speed", mp_property_playback_speed
, CONF_TYPE_FLOAT
,
2388 M_OPT_RANGE
, 0.01, 100.0, NULL
},
2389 { "filename", mp_property_filename
, CONF_TYPE_STRING
,
2391 { "path", mp_property_path
, CONF_TYPE_STRING
,
2393 { "demuxer", mp_property_demuxer
, CONF_TYPE_STRING
,
2395 { "stream_pos", mp_property_stream_pos
, CONF_TYPE_POSITION
,
2396 M_OPT_MIN
, 0, 0, NULL
},
2397 { "stream_start", mp_property_stream_start
, CONF_TYPE_POSITION
,
2398 M_OPT_MIN
, 0, 0, NULL
},
2399 { "stream_end", mp_property_stream_end
, CONF_TYPE_POSITION
,
2400 M_OPT_MIN
, 0, 0, NULL
},
2401 { "stream_length", mp_property_stream_length
, CONF_TYPE_POSITION
,
2402 M_OPT_MIN
, 0, 0, NULL
},
2403 { "length", mp_property_length
, CONF_TYPE_DOUBLE
,
2407 { "volume", mp_property_volume
, CONF_TYPE_FLOAT
,
2408 M_OPT_RANGE
, 0, 100, NULL
},
2409 { "mute", mp_property_mute
, CONF_TYPE_FLAG
,
2410 M_OPT_RANGE
, 0, 1, NULL
},
2411 { "audio_delay", mp_property_audio_delay
, CONF_TYPE_FLOAT
,
2412 M_OPT_RANGE
, -100, 100, NULL
},
2413 { "audio_format", mp_property_audio_format
, CONF_TYPE_INT
,
2415 { "audio_bitrate", mp_property_audio_bitrate
, CONF_TYPE_INT
,
2417 { "samplerate", mp_property_samplerate
, CONF_TYPE_INT
,
2419 { "channels", mp_property_channels
, CONF_TYPE_INT
,
2421 { "switch_audio", mp_property_audio
, CONF_TYPE_INT
,
2425 { "fullscreen", mp_property_fullscreen
, CONF_TYPE_FLAG
,
2426 M_OPT_RANGE
, 0, 1, NULL
},
2427 { "ontop", mp_property_ontop
, CONF_TYPE_FLAG
,
2428 M_OPT_RANGE
, 0, 1, NULL
},
2429 { "rootwin", mp_property_rootwin
, CONF_TYPE_FLAG
,
2430 M_OPT_RANGE
, 0, 1, NULL
},
2431 { "border", mp_property_border
, CONF_TYPE_FLAG
,
2432 M_OPT_RANGE
, 0, 1, NULL
},
2433 { "framedropping", mp_property_framedropping
, CONF_TYPE_INT
,
2434 M_OPT_RANGE
, 0, 2, NULL
},
2435 { "gamma", mp_property_gamma
, CONF_TYPE_INT
,
2436 M_OPT_RANGE
, -100, 100, &vo_gamma_gamma
},
2437 { "brightness", mp_property_gamma
, CONF_TYPE_INT
,
2438 M_OPT_RANGE
, -100, 100, &vo_gamma_brightness
},
2439 { "contrast", mp_property_gamma
, CONF_TYPE_INT
,
2440 M_OPT_RANGE
, -100, 100, &vo_gamma_contrast
},
2441 { "saturation", mp_property_gamma
, CONF_TYPE_INT
,
2442 M_OPT_RANGE
, -100, 100, &vo_gamma_saturation
},
2443 { "hue", mp_property_gamma
, CONF_TYPE_INT
,
2444 M_OPT_RANGE
, -100, 100, &vo_gamma_hue
},
2445 { "panscan", mp_property_panscan
, CONF_TYPE_FLOAT
,
2446 M_OPT_RANGE
, 0, 1, NULL
},
2447 { "vsync", mp_property_vsync
, CONF_TYPE_FLAG
,
2448 M_OPT_RANGE
, 0, 1, NULL
},
2449 { "video_format", mp_property_video_format
, CONF_TYPE_INT
,
2451 { "video_bitrate", mp_property_video_bitrate
, CONF_TYPE_INT
,
2453 { "width", mp_property_width
, CONF_TYPE_INT
,
2455 { "height", mp_property_height
, CONF_TYPE_INT
,
2457 { "fps", mp_property_fps
, CONF_TYPE_FLOAT
,
2459 { "aspect", mp_property_aspect
, CONF_TYPE_FLOAT
,
2463 { "sub", mp_property_sub
, CONF_TYPE_INT
,
2464 M_OPT_MIN
, -1, 0, NULL
},
2465 { "sub_delay", mp_property_sub_delay
, CONF_TYPE_FLOAT
,
2467 { "sub_pos", mp_property_sub_pos
, CONF_TYPE_INT
,
2468 M_OPT_RANGE
, 0, 100, NULL
},
2469 { "sub_alignment", mp_property_sub_alignment
, CONF_TYPE_INT
,
2470 M_OPT_RANGE
, 0, 2, NULL
},
2471 { "sub_visibility", mp_property_sub_visibility
, CONF_TYPE_FLAG
,
2472 M_OPT_RANGE
, 0, 1, NULL
},
2473 { "sub_forced_only", mp_property_sub_forced_only
, CONF_TYPE_FLAG
,
2474 M_OPT_RANGE
, 0, 1, NULL
},
2477 { "tv_brightness", mp_property_tv_color
, CONF_TYPE_INT
,
2478 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_BRIGHTNESS
},
2479 { "tv_contrast", mp_property_tv_color
, CONF_TYPE_INT
,
2480 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_CONTRAST
},
2481 { "tv_saturation", mp_property_tv_color
, CONF_TYPE_INT
,
2482 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_SATURATION
},
2483 { "tv_hue", mp_property_tv_color
, CONF_TYPE_INT
,
2484 M_OPT_RANGE
, -100, 100, (void*)TV_COLOR_HUE
},
2487 { NULL
, NULL
, NULL
, 0, 0, 0, NULL
}
2490 m_option_t
* mp_property_find(const char* name
) {
2491 return m_option_list_find(mp_properties
,name
);
2494 int mp_property_do(const char* name
,int action
, void* val
) {
2495 m_option_t
* p
= mp_property_find(name
);
2496 if(!p
) return M_PROPERTY_UNAVAILABLE
;
2497 return m_property_do(p
,action
,val
);
2505 * \defgroup Command2Property Command to property bridge
2507 * It is used to handle most commands that just set a property
2508 * and optionally display something on the OSD.
2509 * Two kinds of commands are handled: adjust or toggle.
2511 * Adjust commands take 1 or 2 parameters: <value> <abs>
2512 * If <abs> is non-zero the property is set to the given value
2513 * otherwise it is adjusted.
2515 * Toggle commands take 0 or 1 parameters. With no parameter
2516 * or a value less than the property minimum it just steps the
2517 * property to its next value. Otherwise it sets it to the given
2523 /// List of the commands that can be handled by setting a property.
2529 /// set/adjust or toggle command
2531 /// progressbar type
2533 /// osd msg id if it must be shared
2535 /// osd msg template
2536 const char* osd_msg
;
2537 } set_prop_cmd
[] = {
2539 { "volume", MP_CMD_VOLUME
, 0, OSD_VOLUME
, -1, MSGTR_Volume
},
2540 { "mute", MP_CMD_MUTE
, 1, 0, -1, MSGTR_MuteStatus
},
2541 { "audio_delay", MP_CMD_AUDIO_DELAY
, 0, 0, -1, MSGTR_AVDelayStatus
},
2542 { "switch_audio", MP_CMD_SWITCH_AUDIO
, 1, 0, -1, MSGTR_OSDAudio
},
2544 { "fullscreen", MP_CMD_VO_FULLSCREEN
, 1, 0, -1, NULL
},
2545 { "panscan", MP_CMD_PANSCAN
, 0, OSD_PANSCAN
, -1, MSGTR_Panscan
},
2546 { "ontop", MP_CMD_VO_ONTOP
, 1, 0, -1, MSGTR_OnTopStatus
},
2547 { "rootwin", MP_CMD_VO_ROOTWIN
, 1, 0, -1, MSGTR_RootwinStatus
},
2548 { "border", MP_CMD_VO_BORDER
, 1, 0, -1, MSGTR_BorderStatus
},
2549 { "framedropping", MP_CMD_FRAMEDROPPING
, 1, 0, -1, MSGTR_FramedroppingStatus
},
2550 { "gamma", MP_CMD_GAMMA
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Gamma
},
2551 { "brightness", MP_CMD_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2552 { "contrast", MP_CMD_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2553 { "saturation", MP_CMD_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2554 { "hue", MP_CMD_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2555 { "vsync", MP_CMD_SWITCH_VSYNC
, 1, 0, -1, MSGTR_VSyncStatus
},
2557 { "sub", MP_CMD_SUB_SELECT
, 1, 0, -1, MSGTR_SubSelectStatus
},
2558 { "sub_pos", MP_CMD_SUB_POS
, 0, 0, -1, MSGTR_SubPosStatus
},
2559 { "sub_alignment", MP_CMD_SUB_ALIGNMENT
, 1, 0, -1, MSGTR_SubAlignStatus
},
2560 { "sub_delay", MP_CMD_SUB_DELAY
, 0, 0, OSD_MSG_SUB_DELAY
, MSGTR_SubDelayStatus
},
2561 { "sub_visibility", MP_CMD_SUB_VISIBILITY
, 1, 0, -1, MSGTR_SubVisibleStatus
},
2562 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY
, 1, 0, -1, MSGTR_SubForcedOnlyStatus
},
2564 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2565 { "tv_hue", MP_CMD_TV_SET_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2566 { "tv_saturation", MP_CMD_TV_SET_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2567 { "tv_contrast", MP_CMD_TV_SET_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2569 { NULL
, 0, 0, 0, -1, NULL
}
2572 /// Handle commands that set a property.
2573 static int set_property_command(mp_cmd_t
* cmd
) {
2577 // look for the command
2578 for(i
= 0 ; set_prop_cmd
[i
].name
; i
++)
2579 if(set_prop_cmd
[i
].cmd
== cmd
->id
) break;
2580 if(!set_prop_cmd
[i
].name
) return 0;
2583 prop
= mp_property_find(set_prop_cmd
[i
].name
);
2587 if(set_prop_cmd
[i
].toggle
) {
2589 if(cmd
->nargs
> 0 && cmd
->args
[0].v
.i
>= prop
->min
)
2590 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
.i
);
2592 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,NULL
);
2593 } else if(cmd
->args
[1].v
.i
) //set
2594 r
= m_property_do(prop
,M_PROPERTY_SET
,&cmd
->args
[0].v
);
2596 r
= m_property_do(prop
,M_PROPERTY_STEP_UP
,&cmd
->args
[0].v
);
2598 if(r
<= 0) return 1;
2600 if(set_prop_cmd
[i
].osd_progbar
) {
2601 if(prop
->type
== CONF_TYPE_INT
) {
2602 if(m_property_do(prop
,M_PROPERTY_GET
,&r
) > 0)
2603 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2604 set_prop_cmd
[i
].osd_msg
,
2605 prop
->min
,prop
->max
,r
);
2606 } else if(prop
->type
== CONF_TYPE_FLOAT
) {
2608 if(m_property_do(prop
,M_PROPERTY_GET
,&f
) > 0)
2609 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,set_prop_cmd
[i
].osd_msg
,
2610 prop
->min
,prop
->max
,f
);
2612 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "Property use an unsupported type.\n");
2616 if(set_prop_cmd
[i
].osd_msg
) {
2617 char* val
= m_property_print(prop
);
2619 set_osd_msg(set_prop_cmd
[i
].osd_id
>= 0 ? set_prop_cmd
[i
].osd_id
:
2620 OSD_MSG_PROPERTY
+i
,1,osd_duration
,
2621 set_prop_cmd
[i
].osd_msg
,val
);
2628 static void reinit_audio_chain(void) {
2630 current_module
="init_audio_codec";
2631 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2632 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
2633 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
2637 inited_flags
|=INITED_ACODEC
;
2638 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2641 //const ao_info_t *info=audio_out->info;
2642 current_module
="af_preinit";
2643 ao_data
.samplerate
=force_srate
;
2645 ao_data
.format
=audio_output_format
;
2647 // first init to detect best values
2648 if(!preinit_audio_filters(sh_audio
,
2650 (int)(sh_audio
->samplerate
*playback_speed
),
2651 sh_audio
->channels
, sh_audio
->sample_format
,
2653 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
2654 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
2655 exit_player(MSGTR_Exit_error
);
2658 current_module
="ao2_init";
2659 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
2663 ao_data
.format
,0))){
2665 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
2666 uninit_player(INITED_ACODEC
); // close codec
2667 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
2672 inited_flags
|=INITED_AO
;
2673 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2674 audio_out
->info
->short_name
,
2675 ao_data
.samplerate
, ao_data
.channels
,
2676 af_fmt2str_short(ao_data
.format
),
2677 af_fmt2bits(ao_data
.format
)/8 );
2678 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
2679 audio_out
->info
->name
, audio_out
->info
->author
);
2680 if(strlen(audio_out
->info
->comment
) > 0)
2681 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
2682 // init audio filters:
2684 current_module
="af_init";
2685 if(!build_afilter_chain(sh_audio
, &ao_data
)) {
2686 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
2687 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2688 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2689 // sh_audio=d_audio->sh=NULL; // -> nosound
2693 mixer
.audio_out
= audio_out
;
2694 mixer
.volstep
= volstep
;
2703 // Return pts value corresponding to the end point of audio written to the
2705 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
2707 // first calculate the end pts of audio that has been output by decoder
2708 double a_pts
= sh_audio
->pts
;
2709 if (a_pts
!= MP_NOPTS_VALUE
)
2710 // Good, decoder supports new way of calculating audio pts.
2711 // sh_audio->pts is the timestamp of the latest input packet with
2712 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2713 // the amount of bytes the decoder has written after that timestamp.
2714 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
2716 // Decoder doesn't support new way of calculating pts (or we're
2717 // being called before it has decoded anything with known timestamp).
2718 // Use the old method of audio pts calculation: take the timestamp
2719 // of last packet with known pts the decoder has read data from,
2720 // and add amount of bytes read after the beginning of that packet
2721 // divided by input bps. This will be inaccurate if the input/output
2722 // ratio is not constant for every audio packet or if it is constant
2723 // but not accurately known in sh_audio->i_bps.
2725 a_pts
= d_audio
->pts
;
2726 // ds_tell_pts returns bytes read after last timestamp from
2727 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2728 // it has read but not decoded
2729 if (sh_audio
->i_bps
)
2730 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
2731 (double)sh_audio
->i_bps
;
2733 // Now a_pts hopefully holds the pts for end of audio from decoder.
2734 // Substract data in buffers between decoder and audio out.
2736 // Decoded but not filtered
2737 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
2739 // Data that was ready for ao but was buffered because ao didn't fully
2740 // accept everything to internal buffers yet
2741 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
2746 // Return pts value corresponding to currently playing audio.
2747 static double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
2748 ao_functions_t
*audio_out
)
2750 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
2751 audio_out
->get_delay();
2755 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
2757 unsigned char *start
;
2763 current_module
= "decode video";
2764 // XXX Time used in this call is not counted in any performance
2765 // timer now, OSD is not updated correctly for filter-added frames
2766 if (vf_output_queued_frame(sh_video
->vfilter
))
2768 current_module
= "video_read_frame";
2769 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
2771 // try to extract last frames in case of decoder lag
2776 if (in_size
> max_framesize
)
2777 max_framesize
= in_size
;
2778 if (pts
== MP_NOPTS_VALUE
)
2779 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts value from demuxer MISSING\n");
2780 current_module
= "decode video";
2781 void *decoded_frame
= decode_video(sh_video
, start
, in_size
, 0, pts
);
2782 if (decoded_frame
) {
2784 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2793 static void rescale_input_coordinates(int ix
, int iy
, double *dx
, double *dy
) {
2794 //remove the borders, if any, and rescale to the range [0,1],[0,1]
2795 if(vo_fs
) { //we are in full-screen mode
2796 if(vo_screenwidth
> vo_dwidth
) //there are borders along the x axis
2797 ix
-= (vo_screenwidth
- vo_dwidth
) / 2;
2798 if(vo_screenheight
> vo_dheight
) //there are borders along the y axis (usual way)
2799 iy
-= (vo_screenheight
- vo_dheight
) / 2;
2801 if(ix
< 0 || ix
> vo_dwidth
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
2802 if(iy
< 0 || iy
> vo_dheight
) {*dx
= *dy
= -1.0; return; } //we are on one of the borders
2805 *dx
= (double) ix
/ (double) vo_dwidth
;
2806 *dy
= (double) iy
/ (double) vo_dheight
;
2808 mp_msg(MSGT_CPLAYER
,MSGL_V
, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
2809 *dx
, *dy
, vo_screenwidth
, vo_screenheight
, vo_dwidth
, vo_dheight
, vo_fs
);
2816 static float timing_sleep(float time_frame
)
2820 // -------- RTC -----------
2821 current_module
="sleep_rtc";
2822 while (time_frame
> 0.000) {
2823 unsigned long rtc_ts
;
2824 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
2825 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
2826 time_frame
-= GetRelativeTime();
2832 current_module
= "sleep_darwin";
2833 while (time_frame
> 0.005) {
2834 usec_sleep(1000000*time_frame
);
2835 time_frame
-= GetRelativeTime();
2840 // assume kernel HZ=100 for softsleep, works with larger HZ but with
2841 // unnecessarily high CPU usage
2842 float margin
= softsleep
? 0.011 : 0;
2843 current_module
= "sleep_timer";
2844 while (time_frame
> margin
) {
2845 usec_sleep(1000000 * (time_frame
- margin
));
2846 time_frame
-= GetRelativeTime();
2849 current_module
= "sleep_soft";
2851 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
2852 while (time_frame
> 0)
2853 time_frame
-=GetRelativeTime(); // burn the CPU
2856 #endif /* SYS_DARWIN */
2860 static void adjust_sync_and_print_status(int between_frames
, float timing_error
)
2862 current_module
="av_sync";
2865 double a_pts
, v_pts
;
2869 * If autosync is enabled, the value for delay must be calculated
2870 * a bit differently. It is set only to the difference between
2871 * the audio and video timers. Any attempt to include the real
2872 * or corrected delay causes the pts_correction code below to
2873 * try to correct for the changes in delay which autosync is
2874 * trying to measure. This keeps the two from competing, but still
2875 * allows the code to correct for PTS drift *only*. (Using a delay
2876 * value here, even a "corrected" one, would be incompatible with
2879 a_pts
= written_audio_pts(sh_audio
, d_audio
) - sh_audio
->delay
;
2881 a_pts
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
2883 v_pts
= sh_video
->pts
;
2886 static int drop_message
=0;
2887 double AV_delay
= a_pts
- audio_delay
- v_pts
;
2889 if (AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
2891 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
2896 /* Do not correct target time for the next frame if this frame
2897 * was late not because of wrong target time but because the
2898 * target time could not be met */
2899 x
= (AV_delay
+ timing_error
* playback_speed
) * 0.1f
;
2900 if (x
< -max_pts_correction
)
2901 x
= -max_pts_correction
;
2902 else if (x
> max_pts_correction
)
2903 x
= max_pts_correction
;
2904 if (default_max_pts_correction
>= 0)
2905 max_pts_correction
= default_max_pts_correction
;
2907 max_pts_correction
= sh_video
->frametime
*0.10; // +-10% of time
2908 if (!between_frames
) {
2913 print_status(a_pts
- audio_delay
, AV_delay
, c_total
);
2920 print_status(0, 0, 0);
2924 int fill_audio_out_buffers(void)
2933 current_module
="play_audio";
2936 // all the current uses of ao_data.pts seem to be in aos that handle
2937 // sync completely wrong; there should be no need to use ao_data.pts
2939 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
2940 bytes_to_write
= audio_out
->get_space();
2941 if (sh_video
|| bytes_to_write
>= ao_data
.outburst
)
2944 // handle audio-only case:
2945 // this is where mplayer sleeps during audio-only playback
2946 // to avoid 100% CPU use
2947 usec_sleep(10000); // Wait a tick before retry
2950 while (bytes_to_write
) {
2951 playsize
= bytes_to_write
;
2952 if (playsize
> MAX_OUTBURST
)
2953 playsize
= MAX_OUTBURST
;
2954 bytes_to_write
-= playsize
;
2956 // Fill buffer if needed:
2957 current_module
="decode_audio";
2959 while (sh_audio
->a_out_buffer_len
< playsize
) {
2960 int buflen
= sh_audio
->a_out_buffer_len
;
2961 int ret
= decode_audio(sh_audio
, &sh_audio
->a_out_buffer
[buflen
],
2962 playsize
- buflen
, // min bytes
2963 sh_audio
->a_out_buffer_size
- buflen
// max
2965 if (ret
<= 0) { // EOF?
2968 if (sh_audio
->a_out_buffer_len
== 0)
2973 sh_audio
->a_out_buffer_len
+= ret
;
2976 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2977 if (playsize
> sh_audio
->a_out_buffer_len
) {
2978 playsize
= sh_audio
->a_out_buffer_len
;
2980 playflags
|= AOPLAY_FINAL_CHUNK
;
2986 current_module
="play_audio";
2988 // Is this pts value actually useful for the aos that access it?
2989 // They're obviously badly broken in the way they handle av sync;
2990 // would not having access to this make them more broken?
2991 ao_data
.pts
= ((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
2992 playsize
= audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
2995 sh_audio
->a_out_buffer_len
-= playsize
;
2996 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
2997 sh_audio
->a_out_buffer_len
);
2998 sh_audio
->delay
+= playback_speed
*playsize
/(double)ao_data
.bps
;
3000 else if (audio_eof
&& audio_out
->get_delay() < .04) {
3001 // Sanity check to avoid hanging in case current ao doesn't output
3002 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3003 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
3004 sh_audio
->a_out_buffer_len
= 0;
3010 int sleep_until_update(float *time_frame
, float *aq_sleep_time
)
3012 current_module
="calc_sleep_time";
3014 int frame_time_remaining
= 0;
3015 *time_frame
-= GetRelativeTime(); // reset timer
3017 if (sh_audio
&& !d_audio
->eof
) {
3018 float delay
= audio_out
->get_delay();
3019 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
3023 * Adjust this raw delay value by calculating the expected
3024 * delay for this frame and generating a new value which is
3025 * weighted between the two. The higher autosync is, the
3026 * closer to the delay value gets to that which "-nosound"
3027 * would have used, and the longer it will take for A/V
3028 * sync to settle at the right value (but it eventually will.)
3029 * This settling time is very short for values below 100.
3031 float predicted
= sh_audio
->delay
/ playback_speed
+ *time_frame
;
3032 float difference
= delay
- predicted
;
3033 delay
= predicted
+ difference
/ (float)autosync
;
3036 *time_frame
= delay
- sh_audio
->delay
/ playback_speed
;
3038 // delay = amount of audio buffered in soundcard/driver
3039 if (delay
> 0.25) delay
=0.25; else
3040 if (delay
< 0.10) delay
=0.10;
3041 if (*time_frame
> delay
*0.6) {
3042 // sleep time too big - may cause audio drops (buffer underrun)
3043 frame_time_remaining
= 1;
3044 *time_frame
= delay
*0.5;
3047 // If we're lagging more than 200 ms behind the right playback rate,
3048 // don't try to "catch up".
3049 // If benchmark is set always output frames as fast as possible
3050 // without sleeping.
3051 if (*time_frame
< -0.2 || benchmark
)
3055 *aq_sleep_time
+= *time_frame
;
3058 //============================== SLEEP: ===================================
3060 // flag 256 means: libvo driver does its timing (dvb card)
3061 if (*time_frame
> 0.001 && !(vo_flags
&256))
3062 *time_frame
= timing_sleep(*time_frame
);
3063 return frame_time_remaining
;
3067 int main(int argc
,char* argv
[]){
3072 int file_format
=DEMUXER_TYPE_UNKNOWN
;
3076 /* Flag indicating whether MPlayer should exit without playing anything. */
3079 //float a_frame=0; // Audio
3084 int gui_no_filename
=0;
3086 struct {double pts
; vo_functions_t
*vo
;} vf_vo_data
;
3088 srand((int) time(NULL
));
3094 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2006 MPlayer Team\n");
3095 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
3096 GetCpuCaps(&gCpuCaps
);
3098 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
3099 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
3100 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
3101 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
3102 #ifdef RUNTIME_CPUDETECT
3103 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
3105 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
3107 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
3110 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
3113 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
3116 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
3119 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
3122 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
3124 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3125 #endif /* RUNTIME_CPUDETECT */
3126 #endif /* ARCH_X86 */
3128 #if defined(WIN32) && defined(USE_WIN32DLL)
3130 #endif /*WIN32 && USE_WIN32DLL*/
3133 tv_param_immediate
= 1;
3136 if (argc
> 1 && argv
[1] &&
3137 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
3138 use_gui
= !strcmp(argv
[1], "-gui");
3142 char *base
= strrchr(argv
[0], '/');
3144 base
= strrchr(argv
[0], '\\');
3147 if(strstr(base
, "gmplayer"))
3151 mconfig
= m_config_new();
3152 m_config_register_options(mconfig
,mplayer_opts
);
3153 // TODO : add something to let modules register their options
3154 mp_input_register_options(mconfig
);
3155 parse_cfgfiles(mconfig
);
3158 if ( use_gui
) cfg_read();
3161 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
3162 if(playtree
== NULL
)
3165 playtree
= play_tree_cleanup(playtree
);
3167 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3169 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3170 play_tree_iter_free(playtree_iter
);
3171 playtree_iter
= NULL
;
3173 filename
= play_tree_iter_get_file(playtree_iter
,1);
3178 #if defined(WIN32) && defined(HAVE_NEW_GUI)
3179 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
3180 if(runningmplayer
&& filename
&& use_gui
){
3181 COPYDATASTRUCT csData
;
3182 char file
[MAX_PATH
];
3183 char *filepart
= filename
;
3184 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
3186 csData
.cbData
= strlen(file
)*2;
3187 csData
.lpData
= file
;
3188 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
3196 for(i
=0; priority_presets_defs
[i
].name
; i
++){
3197 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
3200 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
3201 priority_presets_defs
[i
].name
);
3202 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
3205 #ifndef HAVE_NEW_GUI
3207 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
3212 if(use_gui
&& !vo_init()){
3213 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
3217 if (use_gui
&& playtree_iter
){
3218 char cwd
[PATH_MAX
+2];
3219 // Free Playtree and Playtree-Iter as it's not used by the GUI.
3220 play_tree_iter_free(playtree_iter
);
3223 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
3226 // Prefix relative paths with current working directory
3227 play_tree_add_bpf(playtree
, cwd
);
3229 // Import initital playtree into GUI.
3230 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
3232 #endif /* HAVE_NEW_GUI */
3234 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
3239 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
3244 /* Check codecs.conf. */
3245 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
3246 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
3247 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
3248 if(!parse_codec_cfg(NULL
)){
3249 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
3250 exit_player_with_rc(NULL
, 0);
3252 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
3255 free( mem_ptr
); // release the buffer created by get_path()
3259 if(video_codec_list
){
3261 video_codec
=video_codec_list
[0];
3262 for(i
=0;video_codec_list
[i
];i
++)
3263 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
3266 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
3267 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
3268 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
3270 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3273 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
3274 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
3275 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
3277 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3280 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
3282 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3285 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3287 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3290 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3296 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3298 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3302 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3303 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3304 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3306 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3309 if(list_properties
) {
3310 m_properties_print_help_list(mp_properties
);
3317 if (player_idle_mode
&& use_gui
) {
3318 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
3319 exit_player_with_rc(NULL
, 1);
3322 if(!filename
&& !player_idle_mode
){
3324 // no file/vcd/dvd -> show HELP:
3325 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
3326 exit_player_with_rc(NULL
, 0);
3327 } else gui_no_filename
=1;
3330 // Many users forget to include command line in bugreports...
3331 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3332 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
3333 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3334 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3337 //------ load global data first ------
3341 #ifdef HAVE_FREETYPE
3344 #ifdef HAVE_FONTCONFIG
3345 if(!font_fontconfig
)
3348 #ifdef HAVE_BITMAP_FONT
3350 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3351 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
3354 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3355 free(mem_ptr
); // release the buffer created by get_path()
3357 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3360 #ifdef HAVE_FONTCONFIG
3363 #endif /* USE_OSD */
3367 ass_library
= ass_init();
3373 // seteuid(0); /* Can't hurt to try to get root here */
3374 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3375 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
3376 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3378 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3380 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3381 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
3382 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
3385 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3386 /* variable only by the root */
3387 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
3391 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
3395 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
3396 // and now ? -- Pontscho
3397 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
3400 #endif /* HAVE_RTC */
3401 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3402 softsleep
?"software":timer_name
);
3405 if ( !use_gui
) load_termcap(NULL
); // load key-codes
3408 // ========== Init keyboard FIFO (connection to libvo) ============
3410 // Init input system
3411 current_module
= "init_input";
3412 mp_input_init(use_gui
);
3414 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
3416 if(keyb_fifo_get
> 0)
3417 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
3419 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
3423 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
3425 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
3427 else if(!noconsolecontrols
)
3428 #ifndef HAVE_NO_POSIX_SELECT
3429 mp_input_add_key_fd(0,1,NULL
,NULL
);
3431 mp_input_add_key_fd(0,0,NULL
,NULL
);
3434 inited_flags
|=INITED_INPUT
;
3435 current_module
= NULL
;
3439 if(menu_cfg
&& menu_init(menu_cfg
))
3440 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3442 menu_cfg
= get_path("menu.conf");
3443 if(menu_init(menu_cfg
))
3444 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
3446 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
3447 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
3449 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
3459 signal(SIGCHLD
,child_sighandler
);
3463 prog_path
= argv
[0];
3465 //========= Catch terminate signals: ================
3466 // terminate requests:
3467 signal(SIGTERM
,exit_sighandler
); // kill
3468 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3470 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3472 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3473 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3474 #ifdef ENABLE_SIGHANDLER
3476 signal(SIGBUS
,exit_sighandler
); // bus error
3477 signal(SIGSEGV
,exit_sighandler
); // segfault
3478 signal(SIGILL
,exit_sighandler
); // illegal instruction
3479 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3480 signal(SIGABRT
,exit_sighandler
); // abort()
3483 signal(SIGTRAP
,exit_sighandler
);
3490 inited_flags
|=INITED_GUI
;
3491 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
3495 // ******************* Now, let's see the per-file stuff ********************
3499 // init global sub numbers
3500 global_sub_size
= 0;
3501 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
3503 if (filename
) load_per_file_config (mconfig
, filename
);
3505 // We must enable getch2 here to be able to interrupt network connection
3507 if(!noconsolecontrols
&& !slave_mode
){
3508 if(inited_flags
&INITED_GETCH2
)
3509 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
3511 getch2_enable(); // prepare stdin for hotkeys...
3512 inited_flags
|=INITED_GETCH2
;
3513 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3516 // =================== GUI idle loop (STOP state) ===========================
3519 file_format
=DEMUXER_TYPE_UNKNOWN
;
3520 guiGetEvent( guiSetDefaults
,0 );
3521 while ( guiIntfStruct
.Playing
!= 1 )
3526 guiGetEvent( guiReDraw
,NULL
);
3527 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3529 guiGetEvent( guiSetParameters
,NULL
);
3530 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
3532 play_tree_t
* entry
= play_tree_new();
3533 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
3534 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
3535 else playtree
=play_tree_new();
3536 play_tree_set_child( playtree
,entry
);
3539 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
3542 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
3544 play_tree_iter_free(playtree_iter
);
3545 playtree_iter
= NULL
;
3547 filename
= play_tree_iter_get_file(playtree_iter
,1);
3552 #endif /* HAVE_NEW_GUI */
3554 while (player_idle_mode
&& !filename
) {
3555 play_tree_t
* entry
= NULL
;
3557 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
3558 if (video_out
&& vo_config_count
) video_out
->check_events();
3562 case MP_CMD_LOADFILE
:
3563 // prepare a tree entry with the new filename
3564 entry
= play_tree_new();
3565 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3566 // The entry is added to the main playtree after the switch().
3568 case MP_CMD_LOADLIST
:
3569 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
3572 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3578 if (entry
) { // user entered a command that gave a valid entry
3579 if (playtree
) // the playtree is always a node with one child. let's clear it
3580 play_tree_free_list(playtree
->child
, 1);
3581 else playtree
=play_tree_new(); // .. or make a brand new playtree
3583 if (!playtree
) continue; // couldn't make playtree! wait for next command
3585 play_tree_set_child(playtree
, entry
);
3587 /* Make iterator start at the top the of tree. */
3588 playtree_iter
= play_tree_iter_new(playtree
, mconfig
);
3589 if (!playtree_iter
) continue;
3591 // find the first real item in the tree
3592 if (play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3594 play_tree_iter_free(playtree_iter
);
3595 playtree_iter
= NULL
;
3596 continue; // wait for next command
3598 filename
= play_tree_iter_get_file(playtree_iter
, 1);
3601 //---------------------------------------------------------------------------
3603 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
3606 if (edl_records
) free_edl(edl_records
);
3607 next_edl_record
= edl_records
= edl_parse_file();
3609 if (edl_output_filename
) {
3610 if (edl_fd
) fclose(edl_fd
);
3611 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3613 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
3614 edl_output_filename
);
3618 //==================== Open VOB-Sub ============================
3620 current_module
="vobsub";
3622 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3624 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
3625 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
3626 /* try to autodetect vobsub from movie filename ::atmos */
3627 char *buf
= malloc((strlen(filename
)-3)),*psub
;
3628 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
3629 strncpy(buf
, filename
, strlen(filename
)-4);
3630 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3631 /* try from ~/.mplayer/sub */
3632 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3635 bname
= strrchr(buf
,'/');
3637 if(!bname
) bname
= strrchr(buf
,'\\');
3641 l
= strlen(psub
) + strlen(bname
) + 1;
3642 psub
= realloc(psub
,l
);
3644 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3650 inited_flags
|=INITED_VOBSUB
;
3651 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
3652 // check if vobsub requested only to display forced subtitles
3653 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
3655 // setup global sub numbering
3656 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
3657 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
3660 //============ Open & Sync STREAM --- fork cache2 ====================
3665 //free_demuxer_stream(d_audio);
3669 //free_demuxer_stream(d_video);
3675 current_module
="open_stream";
3676 stream
=open_stream(filename
,0,&file_format
);
3677 if(!stream
) { // error...
3678 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
3679 goto goto_next_file
;
3681 inited_flags
|=INITED_STREAM
;
3684 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
3687 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
3690 current_module
="handle_playlist";
3691 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
3692 entry
= parse_playtree(stream
,0);
3693 eof
=playtree_add_playlist(entry
);
3694 goto goto_next_file
;
3696 stream
->start_pos
+=seek_to_byte
;
3698 if(stream_dump_type
==5){
3699 unsigned char buf
[4096];
3702 current_module
="dumpstream";
3703 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
3704 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
3705 exit_player(MSGTR_Exit_error
);
3707 stream_reset(stream
);
3708 stream_seek(stream
,stream
->start_pos
);
3709 f
=fopen(stream_dump_name
,"wb");
3711 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3712 exit_player(MSGTR_Exit_error
);
3714 while(!stream
->eof
){
3715 len
=stream_read(stream
,buf
,4096);
3717 if(fwrite(buf
,len
,1,f
) != 1) {
3718 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3719 exit_player(MSGTR_Exit_error
);
3724 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3725 exit_player(MSGTR_Exit_error
);
3727 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3728 exit_player_with_rc(MSGTR_Exit_eof
, 0);
3732 if(stream
->type
==STREAMTYPE_DVD
){
3733 current_module
="dvd lang->id";
3734 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
3735 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
3736 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
3737 // setup global sub numbering
3738 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3739 global_sub_size
+= dvd_number_of_subs(stream
);
3740 current_module
=NULL
;
3744 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3746 if(stream_cache_size
>0){
3747 current_module
="enable_cache";
3748 if(!stream_enable_cache(stream
,stream_cache_size
*1024,
3749 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3750 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
3751 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
3754 //============ Open DEMUXERS --- DETECT file type =======================
3755 current_module
="demux_open";
3757 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
3759 // HACK to get MOV Reference Files working
3761 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3763 unsigned char* playlist_entry
;
3764 play_tree_t
*list
= NULL
, *entry
= NULL
;
3766 current_module
="handle_demux_playlist";
3767 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
3771 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",playlist_entry
);
3773 bname
=mp_basename(playlist_entry
);
3774 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3777 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
3780 entry
= play_tree_new();
3782 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3784 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
3787 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
3788 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
3789 strcat(temp
, playlist_entry
);
3790 play_tree_add_file(entry
,temp
);
3791 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3796 play_tree_add_file(entry
,playlist_entry
);
3801 play_tree_append_entry(list
,entry
);
3803 free_demuxer(demuxer
);
3808 entry
= play_tree_new();
3809 play_tree_set_child(entry
,list
);
3810 eof
=playtree_add_playlist(entry
);
3811 goto goto_next_file
;
3820 current_module
="handle_playlist";
3821 switch(stream
->type
){
3822 case STREAMTYPE_VCD
:
3823 case STREAMTYPE_DVD
:
3824 case STREAMTYPE_CDDA
:
3825 case STREAMTYPE_VCDBINCUE
:
3826 // don't try to parse raw media as playlist, it's unlikely
3827 goto goto_next_file
;
3829 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
3830 stream_reset(stream
);
3831 stream_seek(stream
,stream
->start_pos
);
3832 entry
= parse_playtree(stream
,0);
3834 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
3836 eof
=playtree_add_playlist(entry
);
3838 goto goto_next_file
;
3840 inited_flags
|=INITED_DEMUXER
;
3842 if (demuxer
->type
==DEMUXER_TYPE_MATROSKA
) {
3843 // setup global sub numbering
3844 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3845 global_sub_size
+= demux_mkv_num_subs(demuxer
);
3847 #ifdef HAVE_OGGVORBIS
3848 if (demuxer
->type
==DEMUXER_TYPE_OGG
) {
3849 // setup global sub numbering
3850 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
3851 global_sub_size
+= demux_ogg_num_subs(demuxer
);
3855 current_module
="demux_open2";
3857 //file_format=demuxer->file_format;
3859 d_audio
=demuxer
->audio
;
3860 d_video
=demuxer
->video
;
3861 d_dvdsub
=demuxer
->sub
;
3864 if((stream_dump_type
)&&(stream_dump_type
<4)){
3866 demux_stream_t
*ds
=NULL
;
3867 current_module
="dump";
3868 // select stream to dump
3869 switch(stream_dump_type
){
3870 case 1: ds
=d_audio
;break;
3871 case 2: ds
=d_video
;break;
3872 case 3: ds
=d_dvdsub
;break;
3875 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
3876 exit_player(MSGTR_Exit_error
);
3878 // disable other streams:
3879 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
3880 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
3881 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
3883 f
=fopen(stream_dump_name
,"wb");
3885 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3886 exit_player(MSGTR_Exit_error
);
3889 unsigned char* start
;
3890 int in_size
=ds_get_packet(ds
,&start
);
3891 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3892 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3893 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3896 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3897 exit_player_with_rc(MSGTR_Exit_eof
, 0);
3900 sh_audio
=d_audio
->sh
;
3901 sh_video
=d_video
->sh
;
3905 current_module
="video_read_properties";
3906 if(!video_read_properties(sh_video
)) {
3907 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
3908 sh_video
=d_video
->sh
=NULL
;
3910 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3911 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
3912 sh_video
->fps
,sh_video
->frametime
3915 /* need to set fps here for output encoders to pick it up in their init */
3917 sh_video
->fps
=force_fps
;
3918 sh_video
->frametime
=1.0f
/sh_video
->fps
;
3920 vo_fps
= sh_video
->fps
;
3922 if(!sh_video
->fps
&& !force_fps
){
3923 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
3924 sh_video
=d_video
->sh
=NULL
;
3932 if(!sh_video
&& !sh_audio
){
3933 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
3934 #ifdef HAS_DVBIN_SUPPORT
3935 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
3937 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
3941 int v
= last_dvb_step
;
3943 dir
= DVB_CHANNEL_HIGHER
;
3945 dir
= DVB_CHANNEL_LOWER
;
3947 if(dvb_step_channel(priv
, dir
))
3948 eof
= dvbin_reopen
= 1;
3952 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3955 /* display clip info */
3956 demux_info_print(demuxer
);
3958 //================== Read SUBTITLES (DVD & TEXT) ==========================
3959 if(vo_spudec
==NULL
&& sh_video
&&
3960 (stream
->type
==STREAMTYPE_DVD
|| demuxer
->type
==DEMUXER_TYPE_MATROSKA
||
3961 d_dvdsub
->id
>= 0)){
3964 unsigned int palette
[16], width
, height
;
3965 current_module
="spudec_init_vobsub";
3966 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
3967 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
3971 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
3972 current_module
="spudec_init_dvdread";
3973 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
3974 sh_video
->disp_w
, sh_video
->disp_h
);
3978 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
3979 (d_dvdsub
->sh
!= NULL
) && (((sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
3980 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)d_dvdsub
->sh
;
3981 current_module
= "spudec_init_matroska";
3983 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
3984 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
3985 mkv_sh_sub
->height
);
3986 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
3989 if (vo_spudec
==NULL
) {
3990 current_module
="spudec_init_normal";
3991 vo_spudec
=spudec_new_scaled(NULL
, sh_video
->disp_w
, sh_video
->disp_h
);
3992 spudec_set_font_factor(vo_spudec
,font_factor
);
3995 if (vo_spudec
!=NULL
)
3996 inited_flags
|=INITED_SPUDEC
;
4000 // Apply current settings for forced subs
4001 if (vo_spudec
!=NULL
)
4002 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
4006 // after reading video params we should load subtitles because
4007 // we know fps so now we can adjust subtitle time to ~6 seconds AST
4009 current_module
="read_subtitles_file";
4011 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
4012 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
4014 if(sub_auto
) { // auto load sub file ...
4015 char *psub
= get_path( "sub/" );
4016 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
4018 free(psub
); // release the buffer created by get_path() above
4020 add_subtitles (tmp
[i
], sh_video
->fps
, 0);
4025 if (set_of_sub_size
> 0) {
4026 // setup global sub numbering
4027 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
4028 global_sub_size
+= set_of_sub_size
;
4031 #endif /* USE_SUB */
4033 if (global_sub_size
) {
4034 // find the best sub to use
4035 if (vobsub_id
>= 0) {
4036 // if user asks for a vobsub id, use that first.
4037 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
4038 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
4039 // if user asks for a dvd sub id, use that next.
4040 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
4041 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
4042 // if there are text subs to use, use those. (autosubs come last here)
4043 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
4045 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4046 // if nothing else works, get subs from the demuxer.
4047 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
4050 // nothing worth doing automatically.
4051 global_sub_pos
= -1;
4053 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
4055 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
);
4057 switch (stream_dump_type
) {
4058 case 3: list_sub_file(subdata
); break;
4059 case 4: dump_mpsub(subdata
, sh_video
->fps
); break;
4060 case 6: dump_srt(subdata
, sh_video
->fps
); break;
4061 case 7: dump_microdvd(subdata
, sh_video
->fps
); break;
4062 case 8: dump_jacosub(subdata
, sh_video
->fps
); break;
4063 case 9: dump_sami(subdata
, sh_video
->fps
); break;
4067 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
4068 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", demuxer
->desc
->name
);
4070 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4071 if (sh_video
->format
>= 0x20202020)
4072 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video
->format
);
4074 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
4075 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
4076 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
4077 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
4078 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
4079 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
4082 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4083 if (sh_audio
->format
>= 0x20202020)
4084 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio
->format
);
4086 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
4087 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
4088 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
4089 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
4091 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
4093 if(!sh_video
) goto main
; // audio-only
4095 //================== Init VIDEO (codec & libvo) ==========================
4096 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
4097 current_module
="preinit_libvo";
4100 //if((video_out->preinit(vo_subdevice))!=0){
4101 if(!(video_out
=init_best_video_out(video_driver_list
))){
4102 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
4103 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
4105 sh_video
->video_out
=video_out
;
4106 inited_flags
|=INITED_VO
;
4109 vf_vo_data
.vo
= video_out
;
4110 current_module
="init_video_filters";
4112 char* vf_arg
[] = { "_oldargs_", (char*)&vf_vo_data
, NULL
};
4113 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
4117 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
4118 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
4120 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
4125 sh_video
->vfilter
=(void*)vf_menu
;
4132 for (i
= 0; vf_settings
[i
].name
; ++i
)
4133 if (strcmp(vf_settings
[i
].name
, "ass") == 0) {
4138 extern vf_info_t vf_info_ass
;
4139 vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
4140 char* vf_arg
[] = {"auto", "1", NULL
};
4141 vf_instance_t
* vf_ass
= vf_open_plugin(libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
4143 sh_video
->vfilter
=(void*)vf_ass
;
4145 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
4149 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
4153 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
4156 current_module
="init_video_codec";
4158 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
4159 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
4160 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
4162 if(!sh_video
->inited
){
4163 if(!fixed_vo
) uninit_player(INITED_VO
);
4164 if(!sh_audio
) goto goto_next_file
;
4165 sh_video
= d_video
->sh
= NULL
;
4166 goto main
; // exit_player(MSGTR_Exit_error);
4169 inited_flags
|=INITED_VCODEC
;
4171 if (sh_video
->codec
)
4172 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
4175 // Auto quality option enabled
4176 output_quality
=get_video_quality_max(sh_video
);
4177 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
4178 else output_quality
=auto_quality
;
4179 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
4180 set_video_quality(sh_video
,output_quality
);
4183 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
4185 current_module
="init_vo";
4187 if(vo_flags
& 0x08 && vo_spudec
)
4188 spudec_set_hw_spu(vo_spudec
,video_out
);
4190 #ifdef HAVE_FREETYPE
4191 force_load_font
= 1;
4194 //================== MAIN: ==========================
4196 current_module
="main";
4199 char* msg
= m_properties_expand_string(mp_properties
,playing_msg
);
4200 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
4205 // Disable the term OSD in verbose mode
4206 if(verbose
) term_osd
= 0;
4210 //int frame_corr_num=0; //
4211 //float v_frame=0; // Video
4212 float time_frame
=0; // Timer
4213 //float num_frames=0; // number of frames played
4214 double last_pts
= MP_NOPTS_VALUE
;
4216 int drop_frame
=0; // current dropping status
4217 int dropped_frames
=0; // how many frames dropped since last non-dropped frame
4219 float next_frame_time
=0;
4220 int frame_time_remaining
=0; // flag
4224 // Make sure old OSD does not stay around,
4225 // e.g. with -fixed-vo and same-resolution files
4229 //================ SETUP AUDIO ==========================
4232 reinit_audio_chain();
4233 if (sh_audio
&& sh_audio
->codec
)
4234 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
4237 current_module
="av_init";
4242 audio_delay
+= sh_video
->stream_delay
;
4246 audio_delay
-= sh_audio
->stream_delay
;
4247 sh_audio
->delay
=-audio_delay
;
4251 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
4252 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",d_audio
->packs
);
4253 ds_free_packs(d_audio
); // free buffered chunks
4254 //d_audio->id=-2; // do not read audio chunks
4255 //uninit_player(INITED_AO); // close device
4258 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
4259 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",d_video
->packs
);
4260 ds_free_packs(d_video
);
4262 //if(!fixed_vo) uninit_player(INITED_VO);
4265 if (!sh_video
&& !sh_audio
)
4266 goto goto_next_file
;
4268 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4269 if(force_fps
&& sh_video
){
4270 vo_fps
= sh_video
->fps
=force_fps
;
4271 sh_video
->frametime
=1.0f
/sh_video
->fps
;
4272 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
4277 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
4278 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
4279 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
4280 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
4281 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
4285 //==================== START PLAYING =======================
4287 if(loop_times
>1) loop_times
--; else
4288 if(loop_times
==1) loop_times
= -1;
4290 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
4292 total_time_usage_start
=GetTimer();
4293 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4294 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
4295 play_n_frames
=play_n_frames_mf
;
4297 if(play_n_frames
==0){
4298 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
4302 float aq_sleep_time
=0;
4303 if(!sh_audio
&& d_audio
->sh
) {
4304 sh_audio
= d_audio
->sh
;
4305 sh_audio
->ds
= d_audio
;
4306 reinit_audio_chain();
4309 /*========================== PLAY AUDIO ============================*/
4312 if (!fill_audio_out_buffers())
4313 // at eof, all audio at least written to ao
4315 eof
= PT_NEXT_ENTRY
;
4319 // handle audio-only case:
4321 if(!quiet
|| end_at
.type
== END_AT_TIME
)
4322 a_pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4325 print_status(a_pos
, 0, 0);
4327 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
4328 eof
= PT_NEXT_ENTRY
;
4333 /*========================== PLAY VIDEO ============================*/
4335 float frame_time
=next_frame_time
;
4337 vo_pts
=sh_video
->timer
*90000.0;
4338 vo_fps
=sh_video
->fps
;
4340 if(!frame_time_remaining
){
4341 //-------------------- Decode a frame: -----------------------
4342 blit_frame
= 0; // Don't blit if we hit EOF
4343 if (!correct_pts
) while(1)
4344 { unsigned char* start
=NULL
;
4347 current_module
="video_read_frame";
4348 in_size
=video_read_frame(sh_video
,&next_frame_time
,&start
,force_fps
);
4349 if(in_size
<0){ eof
=1; break; }
4350 if(in_size
>max_framesize
) max_framesize
=in_size
; // stats
4351 sh_video
->timer
+=frame_time
;
4352 if(sh_audio
) sh_audio
->delay
-=frame_time
;
4353 time_frame
+= frame_time
/ playback_speed
; // for nosound
4354 // video_read_frame can change fps (e.g. for ASF video)
4355 vo_fps
= sh_video
->fps
;
4356 // check for frame-drop:
4357 current_module
="check_framedrop";
4358 if(sh_audio
&& !d_audio
->eof
){
4359 float delay
=playback_speed
*audio_out
->get_delay();
4360 float d
=delay
-sh_audio
->delay
;
4361 // we should avoid dropping too many frames in sequence unless we
4362 // are too late. and we allow 100ms A-V delay here:
4363 if(d
<-dropped_frames
*frame_time
-0.100 && osd_function
!= OSD_PAUSE
){
4364 drop_frame
=frame_dropping
;
4368 drop_frame
=dropped_frames
=0;
4373 current_module
="decode_video";
4374 // printf("Decode! %p %d \n",start,in_size);
4376 void *decoded_frame
= decode_video(sh_video
,start
,in_size
,drop_frame
, sh_video
->pts
);
4377 blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
4382 if (!generate_video_frame(sh_video
, d_video
)) {
4386 sh_video
->pts
= vf_vo_data
.pts
;
4387 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
4388 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
4389 sh_video
->pts
= last_pts
;
4391 if (last_pts
== MP_NOPTS_VALUE
)
4392 last_pts
= sh_video
->pts
;
4393 else if (last_pts
>= sh_video
->pts
) {
4394 last_pts
= sh_video
->pts
;
4395 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "pts value <= previous");
4397 frame_time
= sh_video
->pts
- last_pts
;
4398 last_pts
= sh_video
->pts
;
4399 sh_video
->timer
+= frame_time
;
4400 time_frame
+= frame_time
/ playback_speed
; // for nosound
4402 sh_audio
->delay
-= frame_time
;
4407 //------------------------ frame decoded. --------------------
4409 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
4411 if(sh_video
->vf_inited
<0){
4412 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_NotInitializeVOPorVO
);
4413 eof
=1; goto goto_next_file
;
4418 // ==========================================================================
4420 // current_module="draw_osd";
4421 // if(vo_config_count) video_out->draw_osd();
4424 if(use_gui
) guiEventHandling();
4427 current_module
="vo_check_events";
4428 if (vo_config_count
) video_out
->check_events();
4431 if (stop_xscreensaver
) {
4432 current_module
= "stop_xscreensaver";
4433 xscreensaver_heartbeat();
4437 frame_time_remaining
= sleep_until_update(&time_frame
, &aq_sleep_time
);
4439 //====================== FLIP PAGE (VIDEO BLT): =========================
4441 current_module
="flip_page";
4442 if (!frame_time_remaining
&& blit_frame
) {
4443 unsigned int t2
=GetTimer();
4445 if(vo_config_count
) video_out
->flip_page();
4447 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
4449 //====================== A-V TIMESTAMP CORRECTION: =========================
4451 adjust_sync_and_print_status(frame_time_remaining
, time_frame
);
4453 //============================ Auto QUALITY ============================
4455 /*Output quality adjustments:*/
4457 current_module
="autoq";
4458 // float total=0.000001f * (GetTimer()-aq_total_time);
4459 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4460 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4463 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4464 if(output_quality
>1 && aq_sleep_time
<0)
4467 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4469 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4470 set_video_quality(sh_video
,output_quality
);
4473 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
4475 if (play_n_frames
<= 0) eof
= PT_NEXT_ENTRY
;
4479 // FIXME: add size based support for -endpos
4480 if (end_at
.type
== END_AT_TIME
&&
4481 !frame_time_remaining
&& end_at
.pos
<= sh_video
->pts
)
4482 eof
= PT_NEXT_ENTRY
;
4484 } // end if(sh_video)
4486 //============================ Handle PAUSE ===============================
4488 current_module
="pause";
4492 // 36000000 means max timed visibility is 1 hour into the future, if
4493 // the difference is greater assume it's wrapped around from below 0
4494 if (osd_visible
- GetTimerMS() > 36000000) {
4496 vo_osd_progbar_type
=-1; // disable
4497 vo_osd_changed(OSDTYPE_PROGBAR
);
4498 if (osd_function
!= OSD_PAUSE
)
4499 osd_function
= OSD_PLAY
;
4504 if(osd_function
==OSD_PAUSE
){
4507 // Small hack to display the pause message on the OSD line.
4508 // The pause string is: "\n == PAUSE == \r" so we need to
4509 // take the first and the last char out
4511 char msg
[128] = MSGTR_Paused
;
4512 int mlen
= strlen(msg
);
4514 set_osd_msg(OSD_MSG_PAUSE
,1,0,"%s",msg
+1);
4517 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
4518 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
4522 if(use_gui
) guiGetEvent( guiCEvent
,(char *)guiSetPause
);
4524 if (video_out
&& sh_video
&& vo_config_count
)
4525 video_out
->control(VOCTRL_PAUSE
, NULL
);
4527 if (audio_out
&& sh_audio
)
4528 audio_out
->pause(); // pause audio, keep data if possible
4530 while( (cmd
= mp_input_get_cmd(20,1,1)) == NULL
) {
4531 if(sh_video
&& video_out
&& vo_config_count
) video_out
->check_events();
4535 guiGetEvent( guiReDraw
,NULL
);
4536 if(guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
)) break;
4541 vf_menu_pause_update(vf_menu
);
4545 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
4546 cmd
= mp_input_get_cmd(0,1,0);
4549 osd_function
=OSD_PLAY
;
4550 if (audio_out
&& sh_audio
)
4551 audio_out
->resume(); // resume audio
4552 if (video_out
&& sh_video
&& vo_config_count
)
4553 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
4554 (void)GetRelativeTime(); // keep TF around FT in next cycle
4558 if ( guiIntfStruct
.Playing
== guiSetStop
) goto goto_next_file
;
4559 guiGetEvent( guiCEvent
,(char *)guiSetPlay
);
4567 osd_function
=OSD_FFW
;
4568 rel_seek_secs
+=step_sec
;
4571 //================= EDL =========================================
4573 if( next_edl_record
) { // Are we (still?) doing EDL?
4575 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
4576 free_edl(edl_records
);
4577 next_edl_record
= NULL
;
4580 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
4581 if( next_edl_record
->action
== EDL_SKIP
) {
4582 osd_function
= OSD_FFW
;
4584 rel_seek_secs
= next_edl_record
->length_sec
;
4585 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
);
4587 } else if( next_edl_record
->action
== EDL_MUTE
) {
4588 edl_muted
= !edl_muted
;
4589 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
4590 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
4592 next_edl_record
=next_edl_record
->next
;
4597 //================= Keyboard events, SEEKing ====================
4599 current_module
="key_events";
4604 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
4605 if(!set_property_command(cmd
))
4607 case MP_CMD_SEEK
: {
4611 osd_show_percentage
= sh_video
->fps
;
4612 v
= cmd
->args
[0].v
.f
;
4613 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
4614 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
4617 osd_function
= (v
> sh_video
->pts
) ? OSD_FFW
: OSD_REW
;
4620 else if(abs
) { /* Absolute seek by percentage */
4623 osd_function
= OSD_FFW
; // Direction isn't set correctly
4624 rel_seek_secs
= v
/100.0;
4628 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
4632 case MP_CMD_SET_PROPERTY
: {
4633 m_option_t
* prop
= mp_property_find(cmd
->args
[0].v
.s
);
4634 if(!prop
) mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unkown property: '%s'\n",cmd
->args
[0].v
.s
);
4635 else if(m_property_parse(prop
,cmd
->args
[1].v
.s
) <= 0)
4636 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to set property '%s' to '%s'.\n",
4637 cmd
->args
[0].v
.s
,cmd
->args
[1].v
.s
);
4640 case MP_CMD_GET_PROPERTY
: {
4643 prop
= mp_property_find(cmd
->args
[0].v
.s
);
4645 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Unkown property: '%s'\n",cmd
->args
[0].v
.s
);
4648 /* Use m_option_print directly to get easily parseable values. */
4649 val
= calloc(1,prop
->type
->size
);
4650 if(m_property_do(prop
,M_PROPERTY_GET
,val
) <= 0) {
4651 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to get value of property '%s'.\n",
4655 tmp
= m_option_print(prop
,val
);
4656 if(!tmp
|| tmp
== (char*)-1) {
4657 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Failed to print value of property '%s'.\n",
4661 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_%s=%s\n",cmd
->args
[0].v
.s
,tmp
);
4664 case MP_CMD_EDL_MARK
:
4666 float v
= sh_video
? sh_video
->pts
:
4667 playing_audio_pts(sh_audio
, d_audio
, audio_out
);
4669 if(begin_skip
== MP_NOPTS_VALUE
)
4672 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutStartSkip
);
4676 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_EdloutBadStop
);
4678 fprintf(edl_fd
, "%f %f %d\n", begin_skip
, v
, 0);
4679 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutEndSkip
);
4681 begin_skip
= MP_NOPTS_VALUE
;
4685 case MP_CMD_SWITCH_RATIO
: {
4686 if (cmd
->nargs
== 0 || cmd
->args
[0].v
.f
== -1)
4687 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
4689 movie_aspect
= cmd
->args
[0].v
.f
;
4690 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
4692 case MP_CMD_SPEED_INCR
: {
4693 float v
= cmd
->args
[0].v
.f
;
4694 playback_speed
+= v
;
4695 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4696 build_afilter_chain(sh_audio
, &ao_data
);
4698 case MP_CMD_SPEED_MULT
: {
4699 float v
= cmd
->args
[0].v
.f
;
4700 playback_speed
*= v
;
4701 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4702 build_afilter_chain(sh_audio
, &ao_data
);
4704 case MP_CMD_SPEED_SET
: {
4705 float v
= cmd
->args
[0].v
.f
;
4707 set_osd_msg(OSD_MSG_SPEED
,1,osd_duration
,MSGTR_OSDSpeed
, playback_speed
);
4708 build_afilter_chain(sh_audio
, &ao_data
);
4710 case MP_CMD_FRAME_STEP
:
4711 case MP_CMD_PAUSE
: {
4715 case MP_CMD_FILE_FILTER
: {
4716 file_filter
= cmd
->args
[0].v
.i
;
4719 case MP_CMD_QUIT
: {
4720 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
4722 case MP_CMD_GRAB_FRAMES
: {
4725 case MP_CMD_PLAY_TREE_STEP
: {
4726 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
4727 int force
= cmd
->args
[1].v
.i
;
4736 for (i
=0;i
<-1*n
;i
++)
4741 if(!force
&& playtree_iter
) {
4742 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4744 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4745 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4746 play_tree_iter_free(i
);
4748 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
4754 case MP_CMD_PLAY_TREE_UP_STEP
: {
4755 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
4756 int force
= cmd
->args
[1].v
.i
;
4758 if(!force
&& playtree_iter
) {
4759 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
4760 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
4761 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4762 play_tree_iter_free(i
);
4764 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
4767 case MP_CMD_PLAY_ALT_SRC_STEP
: {
4768 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
4769 int v
= cmd
->args
[0].v
.i
;
4770 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
4772 else if(v
< 0 && playtree_iter
->file
> 1)
4777 case MP_CMD_SUB_STEP
: {
4780 int movement
= cmd
->args
[0].v
.i
;
4781 step_sub(subdata
, sh_video
->pts
, movement
);
4784 sub_delay
+= ass_step_sub(ass_track
, (sh_video
->pts
+ sub_delay
) * 1000 + .5, movement
) / 1000.;
4786 set_osd_msg(OSD_MSG_SUB_DELAY
,1,osd_duration
,
4787 MSGTR_OSDSubDelay
, ROUND(sub_delay
*1000));
4791 case MP_CMD_SUB_LOG
: {
4797 int v
= cmd
->args
[0].v
.i
;
4798 int max
= use_term_osd
? MAX_TERM_OSD_LEVEL
: MAX_OSD_LEVEL
;
4799 if(osd_level
> max
) osd_level
= max
;
4801 osd_level
=(osd_level
+1)%(max
+1);
4803 osd_level
= v
> max
? max
: v
;
4804 /* Show OSD state when disabled, but not when an explicit
4805 argument is given to the OSD command, i.e. in slave mode. */
4806 if (v
== -1 && osd_level
<= 1)
4807 set_osd_msg(OSD_MSG_OSD_STATUS
,0,osd_duration
,
4808 MSGTR_OSDosd
, osd_level
? MSGTR_OSDenabled
: MSGTR_OSDdisabled
);
4810 rm_osd_msg(OSD_MSG_OSD_STATUS
);
4812 case MP_CMD_OSD_SHOW_TEXT
: {
4813 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4814 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4815 "%-.63s",cmd
->args
[0].v
.s
);
4817 case MP_CMD_OSD_SHOW_PROPERTY_TEXT
: {
4818 char* txt
= m_properties_expand_string(mp_properties
,cmd
->args
[0].v
.s
);
4819 /* if no argument supplied take default osd_duration, else <arg> ms. */
4821 set_osd_msg(OSD_MSG_TEXT
,cmd
->args
[2].v
.i
,
4822 (cmd
->args
[1].v
.i
< 0 ? osd_duration
: cmd
->args
[1].v
.i
),
4827 case MP_CMD_LOADFILE
: {
4828 play_tree_t
* e
= play_tree_new();
4829 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
4831 if (cmd
->args
[1].v
.i
) // append
4832 play_tree_append_entry(playtree
, e
);
4834 // Go back to the starting point.
4835 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
4837 play_tree_free_list(playtree
->child
,1);
4838 play_tree_set_child(playtree
,e
);
4839 play_tree_iter_step(playtree_iter
,0,0);
4844 case MP_CMD_LOADLIST
: {
4845 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
4847 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
4849 if (cmd
->args
[1].v
.i
) // append
4850 play_tree_append_entry(playtree
, e
);
4852 // Go back to the starting point.
4853 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
4855 play_tree_free_list(playtree
->child
,1);
4856 play_tree_set_child(playtree
,e
);
4857 play_tree_iter_step(playtree_iter
,0,0);
4864 case MP_CMD_RADIO_STEP_CHANNEL
: {
4865 if (demuxer
->stream
->type
==STREAMTYPE_RADIO
) {
4866 int v
= cmd
->args
[0].v
.i
;
4868 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_HIGHER
);
4870 radio_step_channel(demuxer
->stream
, RADIO_CHANNEL_LOWER
);
4871 if (radio_get_channel_name(demuxer
->stream
)) {
4872 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
4873 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
4877 case MP_CMD_RADIO_SET_CHANNEL
: {
4878 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
) {
4879 radio_set_channel(demuxer
->stream
, cmd
->args
[0].v
.s
);
4880 if (radio_get_channel_name(demuxer
->stream
)) {
4881 set_osd_msg(OSD_MSG_RADIO_CHANNEL
,1,osd_duration
,
4882 MSGTR_OSDChannel
, radio_get_channel_name(demuxer
->stream
));
4886 case MP_CMD_RADIO_SET_FREQ
: {
4887 if (demuxer
->stream
->type
== STREAMTYPE_RADIO
)
4888 radio_set_freq(demuxer
->stream
, cmd
->args
[0].v
.f
);
4892 case MP_CMD_TV_SET_FREQ
: {
4893 if (file_format
== DEMUXER_TYPE_TV
)
4894 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
4896 case MP_CMD_TV_SET_NORM
: {
4897 if (file_format
== DEMUXER_TYPE_TV
)
4898 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
4900 case MP_CMD_TV_STEP_CHANNEL
: {
4901 if (file_format
== DEMUXER_TYPE_TV
) {
4902 int v
= cmd
->args
[0].v
.i
;
4904 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
4906 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
4908 if (tv_channel_list
) {
4909 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4910 MSGTR_OSDChannel
, tv_channel_current
->name
);
4911 //vo_osd_changed(OSDTYPE_SUBTITLE);
4915 #ifdef HAS_DVBIN_SUPPORT
4916 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4918 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4922 int v
= cmd
->args
[0].v
.i
;
4926 dir
= DVB_CHANNEL_HIGHER
;
4928 dir
= DVB_CHANNEL_LOWER
;
4931 if(dvb_step_channel(priv
, dir
))
4932 eof
= dvbin_reopen
= 1;
4935 #endif /* HAS_DVBIN_SUPPORT */
4937 case MP_CMD_TV_SET_CHANNEL
: {
4938 if (file_format
== DEMUXER_TYPE_TV
) {
4939 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
4940 if (tv_channel_list
) {
4941 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4942 MSGTR_OSDChannel
, tv_channel_current
->name
);
4943 //vo_osd_changed(OSDTYPE_SUBTITLE);
4947 #ifdef HAS_DVBIN_SUPPORT
4948 case MP_CMD_DVB_SET_CHANNEL
:
4950 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
4952 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
4955 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
4960 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
4961 eof
= dvbin_reopen
= 1;
4966 #endif /* HAS_DVBIN_SUPPORT */
4967 case MP_CMD_TV_LAST_CHANNEL
: {
4968 if (file_format
== DEMUXER_TYPE_TV
) {
4969 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
4970 if (tv_channel_list
) {
4971 set_osd_msg(OSD_MSG_TV_CHANNEL
,1,osd_duration
,
4972 MSGTR_OSDChannel
, tv_channel_current
->name
);
4973 //vo_osd_changed(OSDTYPE_SUBTITLE);
4977 case MP_CMD_TV_STEP_NORM
: {
4978 if (file_format
== DEMUXER_TYPE_TV
)
4979 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
4981 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
4982 if (file_format
== DEMUXER_TYPE_TV
)
4983 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
4986 case MP_CMD_SUB_LOAD
:
4990 int n
= set_of_sub_size
;
4991 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
4992 if (n
!= set_of_sub_size
) {
4993 if (global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
4994 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
;
5000 case MP_CMD_SUB_REMOVE
:
5004 int v
= cmd
->args
[0].v
.i
;
5007 for (v
= 0; v
< set_of_sub_size
; ++v
) {
5008 subd
= set_of_subtitles
[v
];
5009 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
5011 set_of_subtitles
[v
] = NULL
;
5013 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5014 global_sub_size
-= set_of_sub_size
;
5015 set_of_sub_size
= 0;
5016 if (set_of_sub_pos
>= 0) {
5017 global_sub_pos
= -2;
5018 vo_sub_last
= vo_sub
= NULL
;
5019 vo_osd_changed(OSDTYPE_SUBTITLE
);
5020 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5021 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5024 else if (v
< set_of_sub_size
) {
5025 subd
= set_of_subtitles
[v
];
5026 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
5028 if (set_of_sub_pos
== v
) {
5029 global_sub_pos
= -2;
5030 vo_sub_last
= vo_sub
= NULL
;
5031 vo_osd_changed(OSDTYPE_SUBTITLE
);
5032 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
5033 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5035 else if (set_of_sub_pos
> v
) {
5039 while (++v
< set_of_sub_size
)
5040 set_of_subtitles
[v
- 1] = set_of_subtitles
[v
];
5043 if (set_of_sub_size
<= 0)
5044 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
5045 set_of_subtitles
[set_of_sub_size
] = NULL
;
5048 #endif /* USE_SUB */
5050 case MP_CMD_GET_SUB_VISIBILITY
:
5054 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_SUB_VISIBILITY=%d\n", sub_visibility
);
5058 case MP_CMD_SCREENSHOT
:
5059 if(vo_config_count
){
5060 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"sending VFCTRL_SCREENSHOT!\n");
5061 if(CONTROL_OK
!=((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_SCREENSHOT
, &cmd
->args
[0].v
.i
))
5062 video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
5065 case MP_CMD_VF_CHANGE_RECTANGLE
:
5066 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
5069 case MP_CMD_GET_TIME_LENGTH
: {
5070 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer
));
5073 case MP_CMD_GET_FILENAME
: {
5074 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_FILENAME='%s'\n", get_metadata (META_NAME
));
5077 case MP_CMD_GET_VIDEO_CODEC
: {
5078 char *inf
= get_metadata (META_VIDEO_CODEC
);
5079 if (!inf
) inf
= strdup ("");
5080 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_CODEC='%s'\n", inf
);
5084 case MP_CMD_GET_VIDEO_BITRATE
: {
5085 char *inf
= get_metadata (META_VIDEO_BITRATE
);
5086 if (!inf
) inf
= strdup ("");
5087 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_BITRATE='%s'\n", inf
);
5091 case MP_CMD_GET_VIDEO_RESOLUTION
: {
5092 char *inf
= get_metadata (META_VIDEO_RESOLUTION
);
5093 if (!inf
) inf
= strdup ("");
5094 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VIDEO_RESOLUTION='%s'\n", inf
);
5098 case MP_CMD_GET_AUDIO_CODEC
: {
5099 char *inf
= get_metadata (META_AUDIO_CODEC
);
5100 if (!inf
) inf
= strdup ("");
5101 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_CODEC='%s'\n", inf
);
5105 case MP_CMD_GET_AUDIO_BITRATE
: {
5106 char *inf
= get_metadata (META_AUDIO_BITRATE
);
5107 if (!inf
) inf
= strdup ("");
5108 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_BITRATE='%s'\n", inf
);
5112 case MP_CMD_GET_AUDIO_SAMPLES
: {
5113 char *inf
= get_metadata (META_AUDIO_SAMPLES
);
5114 if (!inf
) inf
= strdup ("");
5115 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_AUDIO_SAMPLES='%s'\n", inf
);
5119 case MP_CMD_GET_META_TITLE
: {
5120 char *inf
= get_metadata (META_INFO_TITLE
);
5121 if (!inf
) inf
= strdup ("");
5122 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TITLE='%s'\n", inf
);
5126 case MP_CMD_GET_META_ARTIST
: {
5127 char *inf
= get_metadata (META_INFO_ARTIST
);
5128 if (!inf
) inf
= strdup ("");
5129 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ARTIST='%s'\n", inf
);
5133 case MP_CMD_GET_META_ALBUM
: {
5134 char *inf
= get_metadata (META_INFO_ALBUM
);
5135 if (!inf
) inf
= strdup ("");
5136 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_ALBUM='%s'\n", inf
);
5140 case MP_CMD_GET_META_YEAR
: {
5141 char *inf
= get_metadata (META_INFO_YEAR
);
5142 if (!inf
) inf
= strdup ("");
5143 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_YEAR='%s'\n", inf
);
5147 case MP_CMD_GET_META_COMMENT
: {
5148 char *inf
= get_metadata (META_INFO_COMMENT
);
5149 if (!inf
) inf
= strdup ("");
5150 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_COMMENT='%s'\n", inf
);
5154 case MP_CMD_GET_META_TRACK
: {
5155 char *inf
= get_metadata (META_INFO_TRACK
);
5156 if (!inf
) inf
= strdup ("");
5157 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_TRACK='%s'\n", inf
);
5161 case MP_CMD_GET_META_GENRE
: {
5162 char *inf
= get_metadata (META_INFO_GENRE
);
5163 if (!inf
) inf
= strdup ("");
5164 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_META_GENRE='%s'\n", inf
);
5168 case MP_CMD_GET_VO_FULLSCREEN
: {
5169 if(video_out
&& vo_config_count
)
5170 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VO_FULLSCREEN=%d\n", vo_fs
);
5173 case MP_CMD_GET_PERCENT_POS
: {
5174 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer
));
5176 case MP_CMD_GET_TIME_POS
: {
5179 pos
= sh_video
->pts
;
5181 if (sh_audio
&& audio_out
)
5182 pos
= playing_audio_pts(sh_audio
, d_audio
, audio_out
);
5183 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
5188 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
5193 case MP_CMD_KEYDOWN_EVENTS
: {
5194 mplayer_put_key(cmd
->args
[0].v
.i
);
5196 case MP_CMD_SEEK_CHAPTER
: {
5197 int seek
= cmd
->args
[0].v
.i
;
5198 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
5206 chap
= demuxer_seek_chapter(demuxer
, seek
, abs
, &next_pts
, &num_chapters
, &chapter_name
);
5208 if(next_pts
> -1.0) {
5210 rel_seek_secs
= next_pts
;
5213 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
,
5214 chap
+1, chapter_name
);
5219 rel_seek_secs
= 1000000000.;
5221 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, MSGTR_OSDChapter
, 0, MSGTR_Unknown
);
5225 case MP_CMD_SET_MOUSE_POS
: {
5226 int button
= -1, pointer_x
, pointer_y
;
5228 pointer_x
= cmd
->args
[0].v
.i
;
5229 pointer_y
= cmd
->args
[1].v
.i
;
5230 rescale_input_coordinates(pointer_x
, pointer_y
, &dx
, &dy
);
5232 if(stream
->type
== STREAMTYPE_DVDNAV
&& dx
> 0.0 && dy
> 0.0) {
5233 pointer_x
= (int) (dx
* (double) sh_video
->disp_w
);
5234 pointer_y
= (int) (dy
* (double) sh_video
->disp_h
);
5235 mp_dvdnav_update_mouse_pos(stream
, pointer_x
, pointer_y
, &button
);
5236 if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5242 case MP_CMD_DVDNAV
: {
5244 if(stream
->type
!= STREAMTYPE_DVDNAV
) break;
5246 if(mp_dvdnav_handle_input(stream
, cmd
->args
[0].v
.i
, &button
)) {
5247 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
|(fixed_vo
? INITED_VO
: 0)));
5248 goto goto_enable_cache
;
5249 } else if(button
>0) set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
, "Selected button number %d", button
);
5255 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
5258 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
5261 switch (cmd
->pausing
) {
5262 case 1: // "pausing"
5263 osd_function
= OSD_PAUSE
;
5265 case 3: // "pausing_toggle"
5266 was_paused
= !was_paused
;
5268 case 2: // "pausing_keep"
5269 if (was_paused
) osd_function
= OSD_PAUSE
;
5279 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
5280 rel_seek_secs
+= 3600*a
+60*b
+d
;
5281 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
5282 rel_seek_secs
+= 60*a
+d
;
5283 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
5289 if (end_at
.type
!= END_AT_NONE
) {
5290 if(end_at
.type
== END_AT_SIZE
) {
5291 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
5292 end_at
.type
= END_AT_NONE
;
5294 end_at
.pos
+= rel_seek_secs
;
5299 if(eof
==1 && loop_times
>=0) {
5301 play_tree_iter_step(playtree_iter
,0,0);
5303 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
5305 if(loop_times
>1) loop_times
--; else
5306 if(loop_times
==1) loop_times
=-1;
5307 play_n_frames
=play_n_frames_mf
;
5309 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
5313 if(rel_seek_secs
|| abs_seek_pos
){
5314 current_module
="seek";
5315 if(demux_seek(demuxer
,rel_seek_secs
,audio_delay
,abs_seek_pos
)){
5317 /* FIXME there should be real seeking for vobsub */
5318 if(sh_video
) sh_video
->pts
=d_video
->pts
;
5320 //vobsub_reset(vo_vobsub);
5321 vobsub_seek(vo_vobsub
,sh_video
->pts
);
5325 current_module
="seek_video_reset";
5326 resync_video_stream(sh_video
);
5327 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
5328 sh_video
->num_buffered_pts
= 0;
5329 last_pts
= MP_NOPTS_VALUE
;
5333 current_module
="seek_audio_reset";
5334 audio_out
->reset(); // stop audio, throwing away buffered data
5335 sh_audio
->a_buffer_len
= 0;
5336 sh_audio
->a_out_buffer_len
= 0;
5341 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer
));
5346 max_pts_correction
=0.1;
5347 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
5348 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
5351 if(vo_spudec
) spudec_reset(vo_spudec
);
5355 * We saw a seek, have to rewind the EDL operations stack
5356 * and find the next EDL action to take care of.
5360 next_edl_record
= edl_records
;
5362 while (next_edl_record
)
5364 /* Trying to remember if we need to mute/unmute first;
5365 * prior EDL implementation lacks this.
5368 if (next_edl_record
->start_sec
>= sh_video
->pts
)
5371 if (next_edl_record
->action
== EDL_MUTE
) edl_muted
= !edl_muted
;
5372 next_edl_record
= next_edl_record
->next
;
5375 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
5379 frame_time_remaining
=0;
5380 current_module
=NULL
;
5387 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
5388 // get pos from frame number / total frames
5389 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
5391 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
5392 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
5393 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
5395 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
5396 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
5397 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
5398 guiGetEvent( guiReDraw
,NULL
);
5399 guiGetEvent( guiSetVolume
,NULL
);
5400 if(guiIntfStruct
.Playing
==0) break; // STOP
5401 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
5402 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
5404 if ( stream
->type
== STREAMTYPE_DVD
)
5406 dvd_priv_t
* dvdp
= stream
->priv
;
5407 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
5411 #endif /* HAVE_NEW_GUI */
5414 //================= Update OSD ====================
5418 if(subdata
&& sh_video
&& sh_video
->pts
>0){
5419 float pts
=sh_video
->pts
;
5420 if(sub_fps
==0) sub_fps
=sh_video
->fps
;
5421 current_module
="find_sub";
5422 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0 ) {
5423 find_sub(subdata
, (pts
+sub_delay
) *
5424 (subdata
->sub_uses_time
? 100. : sub_fps
));
5425 if (vo_sub
) vo_sub_last
= vo_sub
;
5426 // FIXME! frame counter...
5429 current_module
=NULL
;
5434 if(vo_config_count
&& vo_spudec
) {
5435 unsigned char* packet
=NULL
;
5437 current_module
="spudec";
5438 spudec_heartbeat(vo_spudec
,90000*sh_video
->timer
);
5439 /* Get a sub packet from the DVD or a vobsub and make a timestamp
5440 relative to sh_video->timer */
5445 if(sh_video
->pts
+sub_delay
>=0) {
5446 // The + next_frame_time is there because we'll display the sub at the next frame
5447 len
= vobsub_get_packet(vo_vobsub
,sh_video
->pts
+sub_delay
+next_frame_time
,(void**)&packet
,×tamp
);
5449 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
5450 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
);
5455 len
= ds_get_packet_sub(d_dvdsub
,(unsigned char**)&packet
);
5457 float x
= d_dvdsub
->pts
- sh_video
->pts
;
5458 if (x
< -10 || x
> 10) // prevent missing subs on pts reset
5459 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
+ sub_delay
- sh_video
->pts
);
5460 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
5461 mp_dbg(MSGT_CPLAYER
,MSGL_V
,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f ts=%d \n",len
,sh_video
->pts
,d_dvdsub
->pts
,timestamp
);
5464 if(len
<=0 || !packet
) break;
5465 if(timestamp
< 0) timestamp
= 0;
5466 else spudec_assemble(vo_spudec
,packet
,len
,timestamp
);
5469 /* detect wether the sub has changed or not */
5470 if(spudec_changed(vo_spudec
))
5471 vo_osd_changed(OSDTYPE_SPU
);
5472 current_module
=NULL
;
5477 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
5479 #ifdef HAS_DVBIN_SUPPORT
5483 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
5484 cache_uninit(stream
);
5486 goto goto_enable_cache
;
5491 goto_next_file
: // don't jump here after ao/vo/getch initialization!
5493 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
5496 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
5497 double total_time_usage
;
5498 total_time_usage_start
=GetTimer()-total_time_usage_start
;
5499 total_time_usage
= (float)total_time_usage_start
*0.000001;
5500 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5501 video_time_usage
,vout_time_usage
,audio_time_usage
,
5502 total_time_usage
-tot
,total_time_usage
);
5503 if(total_time_usage
>0.0)
5504 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5505 100.0*video_time_usage
/total_time_usage
,
5506 100.0*vout_time_usage
/total_time_usage
,
5507 100.0*audio_time_usage
/total_time_usage
,
5508 100.0*(total_time_usage
-tot
)/total_time_usage
,
5510 if(total_frame_cnt
&& frame_dropping
)
5511 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5512 total_frame_cnt
-drop_frame_cnt
,
5513 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
5515 100*drop_frame_cnt
/total_frame_cnt
,
5517 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
5521 // time to uninit all, except global stuff:
5522 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
5525 if ( set_of_sub_size
> 0 )
5527 current_module
="sub_free";
5528 for (i
= 0; i
< set_of_sub_size
; ++i
) {
5529 sub_free( set_of_subtitles
[i
] );
5531 if ( set_of_ass_tracks
[i
] )
5532 ass_free_track( set_of_ass_tracks
[i
] );
5535 set_of_sub_size
= 0;
5537 vo_sub_last
= vo_sub
=NULL
;
5544 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
5545 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
5546 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
5549 play_tree_iter_free(playtree_iter
);
5550 playtree_iter
= NULL
;
5553 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
5554 eof
= eof
== PT_UP_NEXT
? 1 : -1;
5555 if ( playtree_iter
) {
5556 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
5559 play_tree_iter_free(playtree_iter
);
5560 playtree_iter
= NULL
;
5563 } else { // NEXT PREV SRC
5564 eof
= eof
== PT_PREV_SRC
? -1 : 1;
5567 if(eof
== 0) eof
= 1;
5569 while(playtree_iter
!= NULL
) {
5570 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
5571 if(filename
== NULL
) {
5572 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
5573 play_tree_iter_free(playtree_iter
);
5574 playtree_iter
= NULL
;
5581 if( use_gui
&& !playtree_iter
)
5584 if ( !guiIntfStruct
.DiskChanged
)
5590 if(use_gui
|| playtree_iter
!= NULL
|| player_idle_mode
){
5591 if (!playtree_iter
) filename
= NULL
;
5593 goto play_next_file
;
5597 exit_player_with_rc(MSGTR_Exit_eof
, 0);