3 /// \ingroup Properties Command2Property OSDMsgStack
10 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
16 // #include <sys/mman.h>
17 #include <sys/types.h>
19 #include <sys/ioctl.h>
22 #define SIGHUP 1 /* hangup */
23 #define SIGQUIT 3 /* quit */
24 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
25 #define SIGBUS 10 /* bus error */
26 #define SIGPIPE 13 /* broken pipe */
27 extern int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
);
44 #define HELP_MP_DEFINE_STATIC
49 #include "m_property.h"
51 #include "cfg-mplayer-def.h"
53 #include "subreader.h"
55 #include "libvo/video_out.h"
57 #include "libvo/font_load.h"
58 #include "libvo/sub.h"
61 #include "libvo/x11_common.h"
64 #include "libao2/audio_out.h"
66 #include "codec-cfg.h"
73 #include "osdep/getch2.h"
74 #include "osdep/timer.h"
76 #include "cpudetect.h"
79 #include "gui/interface.h"
82 #include "input/input.h"
85 int player_idle_mode
=0;
87 int enable_mouse_movements
=0;
90 char * proc_priority
=NULL
;
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
97 #include <linux/rtc.h>
100 #define RTC_IRQP_SET RTCIO_IRQP_SET
101 #define RTC_PIE_ON RTCIO_PIE_ON
102 #endif /* __linux__ */
103 #endif /* HAVE_RTC */
106 #include "stream/tv.h"
109 #include "stream/stream_radio.h"
112 #ifdef HAS_DVBIN_SUPPORT
113 #include "stream/dvbin.h"
114 #include "stream/cache2.h"
117 //**************************************************************************//
119 //**************************************************************************//
120 #include "playtree.h"
121 #include "playtreeparser.h"
124 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
125 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
128 //**************************************************************************//
130 //**************************************************************************//
131 #include "parser-cfg.h"
132 #include "parser-mpcmd.h"
136 //**************************************************************************//
138 //**************************************************************************//
140 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
142 static int cfg_include(m_option_t
*conf
, char *filename
){
143 return m_config_parse_config_file(mconfig
, filename
);
146 #include "get_path.c"
148 //**************************************************************************//
150 //**************************************************************************//
153 void xscreensaver_heartbeat(void);
156 //**************************************************************************//
157 //**************************************************************************//
158 // Input media streaming & demultiplexer:
159 //**************************************************************************//
161 static int max_framesize
=0;
163 #include "stream/stream.h"
164 #include "libmpdemux/demuxer.h"
165 #include "libmpdemux/stheader.h"
166 //#include "parse_es.h"
167 #include "libmpdemux/matroska.h"
170 #include "stream/stream_dvd.h"
174 #include "stream/stream_dvdnav.h"
177 #include "libmpcodecs/dec_audio.h"
178 #include "libmpcodecs/dec_video.h"
179 #include "libmpcodecs/mp_image.h"
180 #include "libmpcodecs/vf.h"
181 #include "libmpcodecs/vd.h"
187 //**************************************************************************//
188 //**************************************************************************//
190 // Common FIFO functions, and keyboard/event FIFO code
192 int noconsolecontrols
=0;
193 //**************************************************************************//
195 // Not all functions in mplayer.c take the context as an argument yet
196 static MPContext mpctx_s
= {
197 .osd_function
= OSD_PLAY
,
198 .begin_skip
= MP_NOPTS_VALUE
,
200 .global_sub_pos
= -1,
201 .set_of_sub_pos
= -1,
202 .file_format
= DEMUXER_TYPE_UNKNOWN
,
203 #ifdef HAS_DVBIN_SUPPORT
208 static MPContext
*mpctx
= &mpctx_s
;
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;
236 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
237 unsigned int osd_visible
;
238 int osd_duration
= 1000;
241 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
242 static char* playing_msg
= NULL
;
244 static double seek_to_sec
;
245 static off_t seek_to_byte
=0;
246 static off_t step_sec
=0;
247 static int loop_times
=-1;
248 static int loop_seek
=0;
250 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
253 int autosync
=0; // 30 might be a good default value.
255 // may be changed by GUI: (FIXME!)
256 float rel_seek_secs
=0;
260 char **audio_codec_list
=NULL
; // override audio codec
261 char **video_codec_list
=NULL
; // override video codec
262 char **audio_fm_list
=NULL
; // override audio codec family
263 char **video_fm_list
=NULL
; // override video codec family
266 extern char *demuxer_name
; // override demuxer
267 extern char *audio_demuxer_name
; // override audio demuxer
268 extern char *sub_demuxer_name
; // override sub demuxer
275 char* audio_lang
=NULL
;
276 char* dvdsub_lang
=NULL
;
277 static char* spudec_ifo
=NULL
;
278 char* filename
=NULL
; //"MI2-Trailer.avi";
279 int forced_subs_only
=0;
283 int stream_cache_size
=-1;
284 #ifdef USE_STREAM_CACHE
285 extern int cache_fill_status
;
287 float stream_cache_min_percent
=20.0;
288 float stream_cache_seek_min_percent
=50.0;
290 #define cache_fill_status 0
294 static char *stream_dump_name
="stream.dump";
295 int stream_dump_type
=0;
298 static float default_max_pts_correction
=-1;//0.01f;
299 static float max_pts_correction
=0;//default_max_pts_correction;
300 static float c_total
=0;
302 static int ignore_start
=0;
304 static int softsleep
=0;
307 static int force_srate
=0;
308 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
309 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
310 static int play_n_frames
=-1;
311 static int play_n_frames_mf
=-1;
314 char** video_driver_list
=NULL
;
315 char** audio_driver_list
=NULL
;
317 extern char *vo_subdevice
;
318 extern char *ao_subdevice
;
320 // codec outfmt flags (defined in libmpcodecs/vd.c)
324 char *font_name
=NULL
;
325 char *sub_font_name
=NULL
;
326 #ifdef HAVE_FONTCONFIG
327 extern int font_fontconfig
;
329 float font_factor
=0.75;
330 char **sub_name
=NULL
;
334 char *vobsub_name
=NULL
;
335 /*DSP!!char *dsp=NULL;*/
337 int suboverlap_enabled
= 1;
340 #include "libass/ass.h"
341 #include "libass/ass_mp.h"
344 extern int mp_msg_levels
[MSGT_MAX
];
345 extern int mp_msg_level_all
;
347 char* current_module
=NULL
; // for debugging
353 #include "m_struct.h"
354 #include "libmenu/menu.h"
355 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
356 extern vf_info_t vf_info_menu
;
357 static vf_info_t
* libmenu_vfs
[] = {
361 static vf_instance_t
* vf_menu
= NULL
;
362 static int use_menu
= 0;
363 static char* menu_cfg
= NULL
;
364 static char* menu_root
= "main";
369 static int nortc
= 1;
370 static char* rtc_device
;
373 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
374 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
375 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
376 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
377 int use_filedir_conf
;
379 static unsigned int inited_flags
=0;
380 #include "mpcommon.h"
383 #include "metadata.h"
385 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
387 void *mpctx_get_video_out(MPContext
*mpctx
)
389 return mpctx
->video_out
;
392 void *mpctx_get_audio_out(MPContext
*mpctx
)
394 return mpctx
->audio_out
;
397 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
399 return mpctx
->playtree_iter
;
402 void *mpctx_get_mixer(MPContext
*mpctx
)
404 return &mpctx
->mixer
;
407 int mpctx_get_global_sub_size(MPContext
*mpctx
)
409 return mpctx
->global_sub_size
;
412 static int is_valid_metadata_type (metadata_t type
) {
415 /* check for valid video stream */
416 case META_VIDEO_CODEC
:
417 case META_VIDEO_BITRATE
:
418 case META_VIDEO_RESOLUTION
:
420 if (!mpctx
->sh_video
)
425 /* check for valid audio stream */
426 case META_AUDIO_CODEC
:
427 case META_AUDIO_BITRATE
:
428 case META_AUDIO_SAMPLES
:
430 if (!mpctx
->sh_audio
)
435 /* check for valid demuxer */
436 case META_INFO_TITLE
:
437 case META_INFO_ARTIST
:
438 case META_INFO_ALBUM
:
440 case META_INFO_COMMENT
:
441 case META_INFO_TRACK
:
442 case META_INFO_GENRE
:
456 static char *get_demuxer_info (char *tag
) {
457 char **info
= mpctx
->demuxer
->info
;
463 for (n
= 0; info
[2*n
] != NULL
; n
++)
464 if (!strcmp (info
[2*n
], tag
))
467 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
470 char *get_metadata (metadata_t type
) {
472 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
473 sh_video_t
* const sh_video
= mpctx
->sh_video
;
475 if (!is_valid_metadata_type (type
))
482 return strdup (mp_basename2 (filename
));
485 case META_VIDEO_CODEC
:
487 if (sh_video
->format
== 0x10000001)
488 meta
= strdup ("mpeg1");
489 else if (sh_video
->format
== 0x10000002)
490 meta
= strdup ("mpeg2");
491 else if (sh_video
->format
== 0x10000004)
492 meta
= strdup ("mpeg4");
493 else if (sh_video
->format
== 0x10000005)
494 meta
= strdup ("h264");
495 else if (sh_video
->format
>= 0x20202020)
497 meta
= (char *) malloc (8);
498 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
502 meta
= (char *) malloc (8);
503 sprintf (meta
, "0x%08X", sh_video
->format
);
508 case META_VIDEO_BITRATE
:
510 meta
= (char *) malloc (16);
511 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
515 case META_VIDEO_RESOLUTION
:
517 meta
= (char *) malloc (16);
518 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
522 case META_AUDIO_CODEC
:
524 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
525 meta
= strdup (sh_audio
->codec
->name
);
529 case META_AUDIO_BITRATE
:
531 meta
= (char *) malloc (16);
532 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
536 case META_AUDIO_SAMPLES
:
538 meta
= (char *) malloc (16);
539 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
543 /* check for valid demuxer */
544 case META_INFO_TITLE
:
545 return get_demuxer_info ("Title");
547 case META_INFO_ARTIST
:
548 return get_demuxer_info ("Artist");
550 case META_INFO_ALBUM
:
551 return get_demuxer_info ("Album");
554 return get_demuxer_info ("Year");
556 case META_INFO_COMMENT
:
557 return get_demuxer_info ("Comment");
559 case META_INFO_TRACK
:
560 return get_demuxer_info ("Track");
562 case META_INFO_GENRE
:
563 return get_demuxer_info ("Genre");
572 /// step size of mixer changes
575 void uninit_player(unsigned int mask
){
576 mask
=inited_flags
&mask
;
578 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
580 if(mask
&INITED_ACODEC
){
581 inited_flags
&=~INITED_ACODEC
;
582 current_module
="uninit_acodec";
583 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
585 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
587 mpctx
->sh_audio
=NULL
;
590 if(mask
&INITED_VCODEC
){
591 inited_flags
&=~INITED_VCODEC
;
592 current_module
="uninit_vcodec";
593 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
594 mpctx
->sh_video
=NULL
;
600 if(mask
&INITED_DEMUXER
){
601 inited_flags
&=~INITED_DEMUXER
;
602 current_module
="free_demuxer";
604 mpctx
->stream
=mpctx
->demuxer
->stream
;
605 free_demuxer(mpctx
->demuxer
);
610 // kill the cache process:
611 if(mask
&INITED_STREAM
){
612 inited_flags
&=~INITED_STREAM
;
613 current_module
="uninit_stream";
614 if(mpctx
->stream
) free_stream(mpctx
->stream
);
619 inited_flags
&=~INITED_VO
;
620 current_module
="uninit_vo";
621 mpctx
->video_out
->uninit();
622 mpctx
->video_out
=NULL
;
625 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
626 if(mask
&INITED_GETCH2
){
627 inited_flags
&=~INITED_GETCH2
;
628 current_module
="uninit_getch2";
629 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
634 if(mask
&INITED_VOBSUB
){
635 inited_flags
&=~INITED_VOBSUB
;
636 current_module
="uninit_vobsub";
637 if(vo_vobsub
) vobsub_close(vo_vobsub
);
641 if (mask
&INITED_SPUDEC
){
642 inited_flags
&=~INITED_SPUDEC
;
643 current_module
="uninit_spudec";
644 spudec_free(vo_spudec
);
649 inited_flags
&=~INITED_AO
;
650 current_module
="uninit_ao";
651 if (mpctx
->user_muted
| mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
652 mpctx
->audio_out
->uninit(mpctx
->eof
?0:1); mpctx
->audio_out
=NULL
;
657 inited_flags
&=~INITED_GUI
;
658 current_module
="uninit_gui";
663 if(mask
&INITED_INPUT
){
664 inited_flags
&=~INITED_INPUT
;
665 current_module
="uninit_input";
672 void exit_player_with_rc(const char* how
, int rc
){
674 uninit_player(INITED_ALL
);
679 vo_uninit(); // Close the X11 connection (if any is open).
683 current_module
="uninit_font";
684 if (vo_font
) free_font_desc(vo_font
);
691 ass_library_done(ass_library
);
694 current_module
="exit_player";
696 // free mplayer config
698 m_config_free(mconfig
);
701 play_tree_free(mpctx
->playtree
, 1);
704 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
705 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
706 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
711 void exit_player(const char* how
){
712 exit_player_with_rc(how
, 1);
716 static void child_sighandler(int x
){
718 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
723 static char *prog_path
;
724 static int crash_debug
= 0;
727 static void exit_sighandler(int x
){
728 static int sig_count
=0;
730 if (!crash_debug
|| x
!= SIGTRAP
)
733 if(inited_flags
==0 && sig_count
>1) exit(1);
736 /* We're crashing bad and can't uninit cleanly :(
737 * by popular request, we make one last (dirty)
738 * effort to restore the user's
743 if(sig_count
==6) exit(1);
747 kill(getpid(),SIGKILL
);
750 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
751 current_module
?current_module
:"unknown"
753 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
760 break; // killed from keyboard (^C) or killed [-9]
762 #ifdef RUNTIME_CPUDETECT
763 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
765 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
769 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
771 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
776 snprintf(spid
, 19, "%i", getpid());
778 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
780 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
781 if (gdb_pid
== 0) { // We are the child
782 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
783 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
784 } else if (gdb_pid
< 0)
785 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
787 waitpid(gdb_pid
, NULL
, 0);
789 if (x
== SIGTRAP
) return;
796 extern void mp_input_register_options(m_config_t
* cfg
);
798 #include "cfg-mplayer.h"
800 static void parse_cfgfiles( m_config_t
* conf
)
804 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
806 if ((conffile
= get_path("")) == NULL
) {
807 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
812 mkdir(conffile
, 0777);
815 if ((conffile
= get_path("config")) == NULL
) {
816 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
818 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
819 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
820 write(conffile_fd
, default_config
, strlen(default_config
));
823 if (m_config_parse_config_file(conf
, conffile
) < 0)
830 void load_per_file_config (m_config_t
* conf
, const char *const file
)
833 char cfg
[strlen(file
)+10];
837 sprintf (cfg
, "%s.conf", file
);
839 if (use_filedir_conf
&& !stat (cfg
, &st
))
841 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
842 m_config_parse_config_file (conf
, cfg
);
846 if ((name
= strrchr (cfg
, '/')) == NULL
)
851 if ((confpath
= get_path (name
)) != NULL
)
853 if (!stat (confpath
, &st
))
855 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
856 m_config_parse_config_file (conf
, confpath
);
863 /* When libmpdemux performs a blocking operation (network connection or
864 * cache filling) if the operation fails we use this function to check
865 * if it was interrupted by the user.
866 * The function returns a new value for eof. */
867 static int libmpdemux_was_interrupted(int eof
) {
869 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
872 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
873 case MP_CMD_PLAY_TREE_STEP
: {
874 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
875 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
877 case MP_CMD_PLAY_TREE_UP_STEP
: {
878 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
880 case MP_CMD_PLAY_ALT_SRC_STEP
: {
881 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
889 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
891 int playtree_add_playlist(play_tree_t
* entry
)
893 play_tree_add_bpf(entry
,filename
);
898 import_playtree_playlist_into_gui(entry
, mconfig
);
899 play_tree_free_list(entry
,1);
905 entry
= mpctx
->playtree_iter
->tree
;
906 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
907 return PT_NEXT_ENTRY
;
909 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
910 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
911 return PT_NEXT_ENTRY
;
914 play_tree_remove(entry
,1,1);
917 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
918 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
919 entry
= mpctx
->playtree_iter
->tree
;
920 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
921 return PT_NEXT_ENTRY
;
923 play_tree_remove(entry
,1,1);
928 void add_subtitles(char *filename
, float fps
, int silent
)
932 ass_track_t
*asst
= 0;
935 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
939 subd
= sub_read_file(filename
, fps
);
943 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
945 asst
= ass_read_file(ass_library
, filename
, 0);
947 if (ass_enabled
&& subd
&& !asst
)
948 asst
= ass_read_subdata(ass_library
, subd
, fps
);
950 if (!asst
&& !subd
&& !silent
)
954 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
,
955 filename_recode(filename
));
958 if (!asst
&& !subd
) return;
959 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
963 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
964 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
965 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
966 filename_recode(filename
));
967 ++mpctx
->set_of_sub_size
;
968 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, mpctx
->set_of_sub_size
,
969 filename_recode(filename
));
972 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
973 void update_set_of_subtitles(void)
974 // subdata was changed, set_of_sub... have to be updated.
976 sub_data
** const set_of_subtitles
= mpctx
->set_of_subtitles
;
978 if (mpctx
->set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
979 for (i
= mpctx
->set_of_sub_pos
+ 1; i
< mpctx
->set_of_sub_size
; ++i
)
980 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
981 set_of_subtitles
[mpctx
->set_of_sub_size
-1] = NULL
;
982 --mpctx
->set_of_sub_size
;
983 if (mpctx
->set_of_sub_size
> 0) subdata
= set_of_subtitles
[mpctx
->set_of_sub_pos
=0];
985 else if (mpctx
->set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
986 set_of_subtitles
[mpctx
->set_of_sub_pos
] = subdata
;
988 else if (mpctx
->set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
989 set_of_subtitles
[mpctx
->set_of_sub_pos
=mpctx
->set_of_sub_size
] = subdata
;
990 ++mpctx
->set_of_sub_size
;
994 void init_vo_spudec(void) {
996 spudec_free(vo_spudec
);
997 inited_flags
&= ~INITED_SPUDEC
;
1000 unsigned int palette
[16], width
, height
;
1001 current_module
="spudec_init_vobsub";
1002 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1003 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1007 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1008 current_module
="spudec_init_dvdread";
1009 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1010 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1015 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1016 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1017 current_module
="spudec_init_dvdnav";
1018 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1022 if ((vo_spudec
== NULL
) && (mpctx
->demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1023 (mpctx
->d_sub
->sh
!= NULL
) && (((sh_sub_t
*)mpctx
->d_sub
->sh
)->type
== 'v')) {
1024 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1025 current_module
= "spudec_init_matroska";
1027 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1028 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1029 mkv_sh_sub
->height
);
1030 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1033 if (vo_spudec
==NULL
) {
1034 sh_sub_t
*sh
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1035 unsigned int *palette
= NULL
;
1036 if (sh
&& sh
->has_palette
)
1037 palette
= sh
->palette
;
1038 current_module
="spudec_init_normal";
1039 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1040 spudec_set_font_factor(vo_spudec
,font_factor
);
1043 if (vo_spudec
!=NULL
)
1044 inited_flags
|=INITED_SPUDEC
;
1048 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1049 * make it all work is to use the builtin SDL-bootstrap code, which
1050 * will be done automatically by replacing our main() if we include SDL.h.
1052 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1057 * \brief append a formatted string
1058 * \param buf buffer to print into
1059 * \param pos position of terminating 0 in buf
1060 * \param len maximum number of characters in buf, not including terminating 0
1061 * \param format printf format string
1063 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1066 va_start(va
, format
);
1067 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1076 * \brief append time in the hh:mm:ss.f format
1077 * \param buf buffer to print into
1078 * \param pos position of terminating 0 in buf
1079 * \param len maximum number of characters in buf, not including terminating 0
1080 * \param time time value to convert/append
1082 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1083 long tenths
= 10 * time
;
1084 int f1
= tenths
% 10;
1085 int ss
= (tenths
/ 10) % 60;
1086 int mm
= (tenths
/ 600) % 60;
1087 int hh
= tenths
/ 36000;
1089 saddf(buf
, pos
, len
, "unknown");
1093 saddf(buf
, pos
, len
, "%2d:", hh
);
1094 if (hh
> 0 || mm
> 0)
1095 saddf(buf
, pos
, len
, "%02d:", mm
);
1096 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1100 * \brief print the status line
1101 * \param a_pos audio position
1102 * \param a_v A-V desynchronization
1103 * \param corr amount out A-V synchronization
1105 static void print_status(float a_pos
, float a_v
, float corr
)
1107 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1112 if (screen_width
> 0)
1113 width
= screen_width
;
1117 /* Windows command line is broken (MinGW's rxvt works, but we
1118 * should not depend on that). */
1121 line
= malloc(width
+ 1); // one additional char for the terminating null
1124 if (mpctx
->sh_audio
) {
1125 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1127 float len
= demuxer_get_time_length(mpctx
->demuxer
);
1128 saddf(line
, &pos
, width
, "(");
1129 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1130 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1131 sadd_hhmmssf(line
, &pos
, width
, len
);
1132 saddf(line
, &pos
, width
, ") ");
1138 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1141 if (mpctx
->sh_audio
&& sh_video
)
1142 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1146 saddf(line
, &pos
, width
, "%3d/%3d ",
1147 (int)sh_video
->num_frames
,
1148 (int)sh_video
->num_frames_decoded
);
1152 if (sh_video
->timer
> 0.5)
1153 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1154 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
1155 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
1156 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
1158 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1159 } else if (mpctx
->sh_audio
) {
1160 if (mpctx
->delay
> 0.5)
1161 saddf(line
, &pos
, width
, "%4.1f%% ",
1162 100.0*audio_time_usage
/(double)mpctx
->delay
);
1164 saddf(line
, &pos
, width
, "??,?%% ");
1169 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1171 #ifdef USE_STREAM_CACHE
1173 if (stream_cache_size
> 0)
1174 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1178 if (playback_speed
!= 1)
1179 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
1182 if (erase_to_end_of_line
) {
1184 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1186 memset(&line
[pos
], ' ', width
- pos
);
1188 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s\r", line
);
1194 * \brief build a chain of audio filters that converts the input format
1195 * to the ao's format, taking into account the current playback_speed.
1196 * \param sh_audio describes the requested input format of the chain.
1197 * \param ao_data describes the requested output format of the chain.
1199 int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1206 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
1208 mpctx
->mixer
.afilter
= NULL
;
1211 new_srate
= sh_audio
->samplerate
* playback_speed
;
1212 if (new_srate
!= ao_data
->samplerate
) {
1213 // limits are taken from libaf/af_resample.c
1214 if (new_srate
< 8000)
1216 if (new_srate
> 192000)
1218 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1220 result
= init_audio_filters(sh_audio
, new_srate
,
1221 sh_audio
->channels
, sh_audio
->sample_format
,
1222 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1223 ao_data
->outburst
* 4, ao_data
->buffersize
);
1224 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1226 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1232 typedef struct mp_osd_msg mp_osd_msg_t
;
1234 /// Previous message on the stack.
1238 int id
,level
,started
;
1239 /// Display duration in ms.
1243 /// OSD message stack.
1244 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1247 * \brief Add a message on the OSD message stack
1249 * If a message with the same id is already present in the stack
1250 * it is pulled on top of the stack, otherwise a new message is created.
1254 void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1255 mp_osd_msg_t
*msg
,*last
=NULL
;
1259 // look if the id is already in the stack
1260 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1261 last
= msg
, msg
= msg
->prev
);
1262 // not found: alloc it
1264 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1265 msg
->prev
= osd_msg_stack
;
1266 osd_msg_stack
= msg
;
1267 } else if(last
) { // found, but it's not on top of the stack
1268 last
->prev
= msg
->prev
;
1269 msg
->prev
= osd_msg_stack
;
1270 osd_msg_stack
= msg
;
1274 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1276 if(r
>= 64) msg
->msg
[63] = 0;
1285 * \brief Remove a message from the OSD stack
1287 * This function can be used to get rid of a message right away.
1291 void rm_osd_msg(int id
) {
1292 mp_osd_msg_t
*msg
,*last
=NULL
;
1294 // Search for the msg
1295 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1296 last
= msg
, msg
= msg
->prev
);
1299 // Detach it from the stack and free it
1301 last
->prev
= msg
->prev
;
1303 osd_msg_stack
= msg
->prev
;
1308 * \brief Remove all messages from the OSD stack
1312 static void clear_osd_msgs(void) {
1313 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1319 osd_msg_stack
= NULL
;
1323 * \brief Get the current message from the OSD stack.
1325 * This function decrements the message timer and destroys the old ones.
1326 * The message that should be displayed is returned (if any).
1330 static mp_osd_msg_t
* get_osd_msg(void) {
1331 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1332 static unsigned last_update
= 0;
1333 unsigned now
= GetTimerMS();
1335 char hidden_dec_done
= 0;
1337 if(!last_update
) last_update
= now
;
1338 diff
= now
>= last_update
? now
- last_update
: 0;
1342 // Look for the first message in the stack with high enough level.
1343 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1345 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1346 // The message has a high enough level or it is the first hidden one
1347 // in both cases we decrement the timer or kill it.
1348 if(!msg
->started
|| msg
->time
> diff
) {
1349 if(msg
->started
) msg
->time
-= diff
;
1350 else msg
->started
= 1;
1352 if(msg
->level
<= osd_level
) return msg
;
1353 hidden_dec_done
= 1;
1362 osd_msg_stack
= prev
;
1371 * \brief Display the OSD bar.
1373 * Display the OSD bar or fall back on a simple message.
1377 void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1379 if(osd_level
< 1) return;
1381 if(mpctx
->sh_video
) {
1382 osd_visible
= (GetTimerMS() + 1000) | 1;
1383 vo_osd_progbar_type
= type
;
1384 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1385 vo_osd_changed(OSDTYPE_PROGBAR
);
1389 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1390 name
,ROUND(100*(val
-min
)/(max
-min
)));
1395 * \brief Update the OSD message line.
1397 * This function displays the current message on the vo OSD or on the term.
1398 * If the stack is empty and the OSD level is high enough the timer
1399 * is displayed (only on the vo OSD).
1403 static void update_osd_msg(void) {
1405 static char osd_text
[64] = "";
1406 static char osd_text_timer
[64];
1408 // we need some mem for vo_osd_text
1409 vo_osd_text
= (unsigned char*)osd_text
;
1411 // Look if we have a msg
1412 if((msg
= get_osd_msg())) {
1413 if(strcmp(osd_text
,msg
->msg
)) {
1414 strncpy((char*)osd_text
, msg
->msg
, 63);
1415 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1416 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1421 if(mpctx
->sh_video
) {
1422 // fallback on the timer
1424 int len
= demuxer_get_time_length(mpctx
->demuxer
);
1425 int percentage
= -1;
1426 char percentage_text
[10];
1427 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1429 if (mpctx
->osd_show_percentage
)
1430 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1432 if (percentage
>= 0)
1433 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1435 percentage_text
[0] = 0;
1438 snprintf(osd_text_timer
, 63,
1439 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1440 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1441 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1443 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1444 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1445 pts
%60,percentage_text
);
1447 osd_text_timer
[0]=0;
1449 // always decrement the percentage timer
1450 if(mpctx
->osd_show_percentage
)
1451 mpctx
->osd_show_percentage
--;
1453 if(strcmp(osd_text
,osd_text_timer
)) {
1454 strncpy(osd_text
, osd_text_timer
, 63);
1455 vo_osd_changed(OSDTYPE_OSD
);
1460 // Clear the term osd line
1461 if(term_osd
&& osd_text
[0]) {
1463 printf("%s\n",term_osd_esc
);
1471 void reinit_audio_chain(void) {
1472 if(mpctx
->sh_audio
){
1473 current_module
="init_audio_codec";
1474 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1475 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1476 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // failed to init :(
1477 mpctx
->d_audio
->id
= -2;
1480 inited_flags
|=INITED_ACODEC
;
1481 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1484 //const ao_info_t *info=audio_out->info;
1485 current_module
="af_preinit";
1486 ao_data
.samplerate
=force_srate
;
1488 ao_data
.format
=audio_output_format
;
1490 // first init to detect best values
1491 if(!preinit_audio_filters(mpctx
->sh_audio
,
1493 (int)(mpctx
->sh_audio
->samplerate
*playback_speed
),
1494 mpctx
->sh_audio
->channels
, mpctx
->sh_audio
->sample_format
,
1496 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1497 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
1498 exit_player(MSGTR_Exit_error
);
1501 current_module
="ao2_init";
1502 if(!(mpctx
->audio_out
=init_best_audio_out(audio_driver_list
,
1506 ao_data
.format
,0))){
1508 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1509 uninit_player(INITED_ACODEC
); // close codec
1510 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1511 mpctx
->d_audio
->id
= -2;
1515 inited_flags
|=INITED_AO
;
1516 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1517 mpctx
->audio_out
->info
->short_name
,
1518 ao_data
.samplerate
, ao_data
.channels
,
1519 af_fmt2str_short(ao_data
.format
),
1520 af_fmt2bits(ao_data
.format
)/8 );
1521 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1522 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1523 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1524 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1525 // init audio filters:
1527 current_module
="af_init";
1528 if(!build_afilter_chain(mpctx
->sh_audio
, &ao_data
)) {
1529 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
1530 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1531 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1532 // sh_audio=mpctx->d_audio->sh=NULL; // -> nosound
1536 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1537 mpctx
->mixer
.volstep
= volstep
;
1546 // Return pts value corresponding to the end point of audio written to the
1548 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
1550 // first calculate the end pts of audio that has been output by decoder
1551 double a_pts
= sh_audio
->pts
;
1552 if (a_pts
!= MP_NOPTS_VALUE
)
1553 // Good, decoder supports new way of calculating audio pts.
1554 // sh_audio->pts is the timestamp of the latest input packet with
1555 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1556 // the amount of bytes the decoder has written after that timestamp.
1557 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1559 // Decoder doesn't support new way of calculating pts (or we're
1560 // being called before it has decoded anything with known timestamp).
1561 // Use the old method of audio pts calculation: take the timestamp
1562 // of last packet with known pts the decoder has read data from,
1563 // and add amount of bytes read after the beginning of that packet
1564 // divided by input bps. This will be inaccurate if the input/output
1565 // ratio is not constant for every audio packet or if it is constant
1566 // but not accurately known in sh_audio->i_bps.
1568 a_pts
= d_audio
->pts
;
1569 // ds_tell_pts returns bytes read after last timestamp from
1570 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1571 // it has read but not decoded
1572 if (sh_audio
->i_bps
)
1573 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1574 (double)sh_audio
->i_bps
;
1576 // Now a_pts hopefully holds the pts for end of audio from decoder.
1577 // Substract data in buffers between decoder and audio out.
1579 // Decoded but not filtered
1580 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1582 // Data that was ready for ao but was buffered because ao didn't fully
1583 // accept everything to internal buffers yet
1584 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
1589 // Return pts value corresponding to currently playing audio.
1590 double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
1591 ao_functions_t
*audio_out
)
1593 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
1594 audio_out
->get_delay();
1597 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
1599 unsigned char *start
;
1605 void *decoded_frame
;
1606 current_module
= "decode video";
1607 // XXX Time used in this call is not counted in any performance
1608 // timer now, OSD is not updated correctly for filter-added frames
1609 if (vf_output_queued_frame(sh_video
->vfilter
))
1611 current_module
= "video_read_frame";
1612 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
1614 // try to extract last frames in case of decoder lag
1619 if (in_size
> max_framesize
)
1620 max_framesize
= in_size
;
1621 current_module
= "decode video";
1622 decoded_frame
= decode_video(sh_video
, start
, in_size
, 0, pts
);
1623 if (decoded_frame
) {
1624 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
1626 current_module
= "filter video";
1627 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
1640 static float timing_sleep(float time_frame
)
1644 // -------- RTC -----------
1645 current_module
="sleep_rtc";
1646 while (time_frame
> 0.000) {
1647 unsigned long rtc_ts
;
1648 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1649 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
1650 time_frame
-= GetRelativeTime();
1656 current_module
= "sleep_darwin";
1657 while (time_frame
> 0.005) {
1658 usec_sleep(1000000*time_frame
);
1659 time_frame
-= GetRelativeTime();
1664 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1665 // unnecessarily high CPU usage
1666 float margin
= softsleep
? 0.011 : 0;
1667 current_module
= "sleep_timer";
1668 while (time_frame
> margin
) {
1669 usec_sleep(1000000 * (time_frame
- margin
));
1670 time_frame
-= GetRelativeTime();
1673 current_module
= "sleep_soft";
1675 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
1676 while (time_frame
> 0)
1677 time_frame
-=GetRelativeTime(); // burn the CPU
1680 #endif /* SYS_DARWIN */
1684 static void adjust_sync_and_print_status(int between_frames
, float timing_error
)
1686 current_module
="av_sync";
1688 if(mpctx
->sh_audio
){
1689 double a_pts
, v_pts
;
1693 * If autosync is enabled, the value for delay must be calculated
1694 * a bit differently. It is set only to the difference between
1695 * the audio and video timers. Any attempt to include the real
1696 * or corrected delay causes the pts_correction code below to
1697 * try to correct for the changes in delay which autosync is
1698 * trying to measure. This keeps the two from competing, but still
1699 * allows the code to correct for PTS drift *only*. (Using a delay
1700 * value here, even a "corrected" one, would be incompatible with
1703 a_pts
= written_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
) - mpctx
->delay
;
1705 a_pts
= playing_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
, mpctx
->audio_out
);
1707 v_pts
= mpctx
->sh_video
->pts
;
1710 static int drop_message
=0;
1711 double AV_delay
= a_pts
- audio_delay
- v_pts
;
1713 if (AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
1715 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
1720 /* Do not correct target time for the next frame if this frame
1721 * was late not because of wrong target time but because the
1722 * target time could not be met */
1723 x
= (AV_delay
+ timing_error
* playback_speed
) * 0.1f
;
1724 if (x
< -max_pts_correction
)
1725 x
= -max_pts_correction
;
1726 else if (x
> max_pts_correction
)
1727 x
= max_pts_correction
;
1728 if (default_max_pts_correction
>= 0)
1729 max_pts_correction
= default_max_pts_correction
;
1731 max_pts_correction
= mpctx
->sh_video
->frametime
*0.10; // +-10% of time
1732 if (!between_frames
) {
1737 print_status(a_pts
- audio_delay
, AV_delay
, c_total
);
1744 print_status(0, 0, 0);
1748 static int fill_audio_out_buffers(void)
1756 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
1758 current_module
="play_audio";
1761 // all the current uses of ao_data.pts seem to be in aos that handle
1762 // sync completely wrong; there should be no need to use ao_data.pts
1764 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
1765 bytes_to_write
= mpctx
->audio_out
->get_space();
1766 if (mpctx
->sh_video
|| bytes_to_write
>= ao_data
.outburst
)
1769 // handle audio-only case:
1770 // this is where mplayer sleeps during audio-only playback
1771 // to avoid 100% CPU use
1772 usec_sleep(10000); // Wait a tick before retry
1775 while (bytes_to_write
) {
1776 playsize
= bytes_to_write
;
1777 if (playsize
> MAX_OUTBURST
)
1778 playsize
= MAX_OUTBURST
;
1779 bytes_to_write
-= playsize
;
1781 // Fill buffer if needed:
1782 current_module
="decode_audio";
1784 while (sh_audio
->a_out_buffer_len
< playsize
) {
1785 int buflen
= sh_audio
->a_out_buffer_len
;
1786 int ret
= decode_audio(sh_audio
, &sh_audio
->a_out_buffer
[buflen
],
1787 playsize
- buflen
, // min bytes
1788 sh_audio
->a_out_buffer_size
- buflen
// max
1790 if (ret
<= 0) { // EOF?
1791 if (mpctx
->d_audio
->eof
) {
1793 if (sh_audio
->a_out_buffer_len
== 0)
1798 sh_audio
->a_out_buffer_len
+= ret
;
1801 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
1802 if (playsize
> sh_audio
->a_out_buffer_len
) {
1803 playsize
= sh_audio
->a_out_buffer_len
;
1805 playflags
|= AOPLAY_FINAL_CHUNK
;
1811 current_module
="play_audio";
1813 // Is this pts value actually useful for the aos that access it?
1814 // They're obviously badly broken in the way they handle av sync;
1815 // would not having access to this make them more broken?
1816 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
1817 playsize
= mpctx
->audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
1820 sh_audio
->a_out_buffer_len
-= playsize
;
1821 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
1822 sh_audio
->a_out_buffer_len
);
1823 mpctx
->delay
+= playback_speed
*playsize
/(double)ao_data
.bps
;
1825 else if (audio_eof
&& mpctx
->audio_out
->get_delay() < .04) {
1826 // Sanity check to avoid hanging in case current ao doesn't output
1827 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
1828 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
1829 sh_audio
->a_out_buffer_len
= 0;
1835 static int sleep_until_update(float *time_frame
, float *aq_sleep_time
)
1837 int frame_time_remaining
= 0;
1838 current_module
="calc_sleep_time";
1840 *time_frame
-= GetRelativeTime(); // reset timer
1842 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1843 float delay
= mpctx
->audio_out
->get_delay();
1844 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
1848 * Adjust this raw delay value by calculating the expected
1849 * delay for this frame and generating a new value which is
1850 * weighted between the two. The higher autosync is, the
1851 * closer to the delay value gets to that which "-nosound"
1852 * would have used, and the longer it will take for A/V
1853 * sync to settle at the right value (but it eventually will.)
1854 * This settling time is very short for values below 100.
1856 float predicted
= mpctx
->delay
/ playback_speed
+ *time_frame
;
1857 float difference
= delay
- predicted
;
1858 delay
= predicted
+ difference
/ (float)autosync
;
1861 *time_frame
= delay
- mpctx
->delay
/ playback_speed
;
1863 // delay = amount of audio buffered in soundcard/driver
1864 if (delay
> 0.25) delay
=0.25; else
1865 if (delay
< 0.10) delay
=0.10;
1866 if (*time_frame
> delay
*0.6) {
1867 // sleep time too big - may cause audio drops (buffer underrun)
1868 frame_time_remaining
= 1;
1869 *time_frame
= delay
*0.5;
1872 // If we're lagging more than 200 ms behind the right playback rate,
1873 // don't try to "catch up".
1874 // If benchmark is set always output frames as fast as possible
1875 // without sleeping.
1876 if (*time_frame
< -0.2 || benchmark
)
1880 *aq_sleep_time
+= *time_frame
;
1883 //============================== SLEEP: ===================================
1885 // flag 256 means: libvo driver does its timing (dvb card)
1886 if (*time_frame
> 0.001 && !(vo_flags
&256))
1887 *time_frame
= timing_sleep(*time_frame
);
1888 return frame_time_remaining
;
1891 int reinit_video_chain(void) {
1892 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1893 //================== Init VIDEO (codec & libvo) ==========================
1894 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
1895 current_module
="preinit_libvo";
1897 //shouldn't we set dvideo->id=-2 when we fail?
1899 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
1900 if(!(mpctx
->video_out
=init_best_video_out(video_driver_list
))){
1901 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
1904 sh_video
->video_out
=mpctx
->video_out
;
1905 inited_flags
|=INITED_VO
;
1908 current_module
="init_video_filters";
1910 char* vf_arg
[] = { "_oldargs_", (char*)mpctx
->video_out
, NULL
};
1911 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
1915 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
1916 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
1918 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
1923 sh_video
->vfilter
=(void*)vf_menu
;
1931 for (i
= 0; vf_settings
[i
].name
; ++i
)
1932 if (strcmp(vf_settings
[i
].name
, "ass") == 0) {
1937 extern vf_info_t vf_info_ass
;
1938 vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
1939 char* vf_arg
[] = {"auto", "1", NULL
};
1940 vf_instance_t
* vf_ass
= vf_open_plugin(libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
1942 sh_video
->vfilter
=(void*)vf_ass
;
1944 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
1949 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
1953 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
1956 current_module
="init_video_codec";
1958 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1959 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
1960 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1962 if(!sh_video
->inited
){
1963 if(!fixed_vo
) uninit_player(INITED_VO
);
1967 inited_flags
|=INITED_VCODEC
;
1969 if (sh_video
->codec
)
1970 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
1972 sh_video
->last_pts
= MP_NOPTS_VALUE
;
1973 sh_video
->num_buffered_pts
= 0;
1974 sh_video
->next_frame_time
= 0;
1977 // Auto quality option enabled
1978 output_quality
=get_video_quality_max(sh_video
);
1979 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
1980 else output_quality
=auto_quality
;
1981 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
1982 set_video_quality(sh_video
,output_quality
);
1985 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1987 current_module
="init_vo";
1992 mpctx
->sh_video
= mpctx
->d_video
->sh
= NULL
;
1996 static double update_video(int *blit_frame
)
1998 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1999 //-------------------- Decode a frame: -----------------------
2001 *blit_frame
= 0; // Don't blit if we hit EOF
2003 unsigned char* start
=NULL
;
2004 void *decoded_frame
;
2008 current_module
= "video_read_frame";
2009 frame_time
= sh_video
->next_frame_time
;
2010 in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2014 if (in_size
> max_framesize
)
2015 max_framesize
= in_size
; // stats
2016 sh_video
->timer
+= frame_time
;
2017 if (mpctx
->sh_audio
)
2018 mpctx
->delay
-= frame_time
;
2019 // video_read_frame can change fps (e.g. for ASF video)
2020 vo_fps
= sh_video
->fps
;
2021 // check for frame-drop:
2022 current_module
= "check_framedrop";
2023 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
2024 static int dropped_frames
;
2025 float delay
= playback_speed
*mpctx
->audio_out
->get_delay();
2026 float d
= delay
-mpctx
->delay
;
2027 // we should avoid dropping too many frames in sequence unless we
2028 // are too late. and we allow 100ms A-V delay here:
2029 if (d
< -dropped_frames
*frame_time
-0.100 &&
2030 mpctx
->osd_function
!= OSD_PAUSE
) {
2031 drop_frame
= frame_dropping
;
2035 drop_frame
= dropped_frames
= 0;
2038 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
2040 current_module
= "decode_video";
2041 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
2043 current_module
= "filter_video";
2044 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
2048 if (!generate_video_frame(sh_video
, mpctx
->d_video
))
2050 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
,
2051 VFCTRL_GET_PTS
, &sh_video
->pts
);
2052 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
2053 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
2054 sh_video
->pts
= sh_video
->last_pts
;
2056 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2057 sh_video
->last_pts
= sh_video
->pts
;
2058 else if (sh_video
->last_pts
>= sh_video
->pts
) {
2059 sh_video
->last_pts
= sh_video
->pts
;
2060 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "pts value <= previous\n");
2062 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2063 sh_video
->last_pts
= sh_video
->pts
;
2064 sh_video
->timer
+= frame_time
;
2066 mpctx
->delay
-= frame_time
;
2072 void pause_loop(void)
2076 // Small hack to display the pause message on the OSD line.
2077 // The pause string is: "\n == PAUSE == \r" so we need to
2078 // take the first and the last char out
2079 if (term_osd
&& !mpctx
->sh_video
) {
2080 char msg
[128] = MSGTR_Paused
;
2081 int mlen
= strlen(msg
);
2083 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2086 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2087 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2091 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
2093 if (mpctx
->video_out
&& mpctx
->sh_video
&& vo_config_count
)
2094 mpctx
->video_out
->control(VOCTRL_PAUSE
, NULL
);
2096 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2097 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2099 while ( (cmd
= mp_input_get_cmd(20, 1, 1)) == NULL
) {
2100 if (mpctx
->sh_video
&& mpctx
->video_out
&& vo_config_count
)
2101 mpctx
->video_out
->check_events();
2105 guiGetEvent(guiReDraw
, NULL
);
2106 if (guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
))
2112 vf_menu_pause_update(vf_menu
);
2116 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
2117 cmd
= mp_input_get_cmd(0,1,0);
2120 mpctx
->osd_function
=OSD_PLAY
;
2121 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2122 mpctx
->audio_out
->resume(); // resume audio
2123 if (mpctx
->video_out
&& mpctx
->sh_video
&& vo_config_count
)
2124 mpctx
->video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
2125 (void)GetRelativeTime(); // ignore time that passed during pause
2128 if (guiIntfStruct
.Playing
== guiSetStop
)
2131 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
2136 void print_version(void){
2137 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s\n", MP_TITLE
);
2139 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2140 GetCpuCaps(&gCpuCaps
);
2142 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2143 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
2144 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
2145 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
2146 #ifdef RUNTIME_CPUDETECT
2147 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
2149 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
2151 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
2154 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
2157 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
2160 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
2163 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
2166 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
2168 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
2169 #endif /* RUNTIME_CPUDETECT */
2170 #endif /* ARCH_X86 */
2174 // Find the right mute status and record position for new file position
2175 static void edl_seek_reset(MPContext
*mpctx
)
2177 mpctx
->edl_muted
= 0;
2178 next_edl_record
= edl_records
;
2180 while (next_edl_record
) {
2181 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2184 if (next_edl_record
->action
== EDL_MUTE
)
2185 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2186 next_edl_record
= next_edl_record
->next
;
2188 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2189 mixer_mute(&mpctx
->mixer
);
2193 // Execute EDL command for the current position if one exists
2194 static void edl_update(MPContext
*mpctx
)
2196 if (!next_edl_record
)
2199 if (!mpctx
->sh_video
) {
2200 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
2201 free_edl(edl_records
);
2202 next_edl_record
= NULL
;
2207 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2208 if (next_edl_record
->action
== EDL_SKIP
) {
2209 mpctx
->osd_function
= OSD_FFW
;
2211 rel_seek_secs
= next_edl_record
->length_sec
;
2212 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2213 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2214 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2217 else if (next_edl_record
->action
== EDL_MUTE
) {
2218 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2219 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2220 mixer_mute(&mpctx
->mixer
);
2221 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2222 next_edl_record
->start_sec
);
2224 next_edl_record
= next_edl_record
->next
;
2229 // style & 1 == 0 means seek relative to current position, == 1 means absolute
2230 // style & 2 == 0 means amount in seconds, == 2 means fraction of file length
2231 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2232 static int seek(MPContext
*mpctx
, double amount
, int style
)
2234 current_module
= "seek";
2235 if (demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
) == 0)
2238 if (mpctx
->sh_video
) {
2239 current_module
= "seek_video_reset";
2240 resync_video_stream(mpctx
->sh_video
);
2241 if (vo_config_count
)
2242 mpctx
->video_out
->control(VOCTRL_RESET
, NULL
);
2243 mpctx
->sh_video
->num_buffered_pts
= 0;
2244 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2245 mpctx
->num_buffered_frames
= 0;
2247 // Not all demuxers set d_video->pts during seek, so this value
2248 // (which is used by at least vobsub and edl code below) may
2249 // be completely wrong (probably 0).
2250 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
;
2251 update_subtitles(mpctx
->sh_video
, mpctx
->d_sub
, 1);
2254 if (mpctx
->sh_audio
) {
2255 current_module
= "seek_audio_reset";
2256 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2257 mpctx
->sh_audio
->a_buffer_len
= 0;
2258 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2262 current_module
= "seek_vobsub_reset";
2263 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2266 edl_seek_reset(mpctx
);
2269 max_pts_correction
= 0.1;
2270 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2273 current_module
= NULL
;
2277 int main(int argc
,char* argv
[]){
2284 /* Flag indicating whether MPlayer should exit without playing anything. */
2287 //float a_frame=0; // Audio
2291 int gui_no_filename
=0;
2293 srand((int) time(NULL
));
2299 for(i
=1; i
<argc
; i
++)
2300 if(!strcmp(argv
[i
], "-really-quiet"))
2304 #if defined(WIN32) && defined(USE_WIN32DLL)
2306 #endif /*WIN32 && USE_WIN32DLL*/
2309 tv_param_immediate
= 1;
2312 if (argc
> 1 && argv
[1] &&
2313 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
2314 use_gui
= !strcmp(argv
[1], "-gui");
2318 char *base
= strrchr(argv
[0], '/');
2320 base
= strrchr(argv
[0], '\\');
2323 if(strstr(base
, "gmplayer"))
2327 mconfig
= m_config_new();
2328 m_config_register_options(mconfig
,mplayer_opts
);
2329 // TODO : add something to let modules register their options
2330 mp_input_register_options(mconfig
);
2331 parse_cfgfiles(mconfig
);
2334 if ( use_gui
) cfg_read();
2337 mpctx
->playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
2338 if(mpctx
->playtree
== NULL
)
2341 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
2342 if(mpctx
->playtree
) {
2343 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
2344 if(mpctx
->playtree_iter
) {
2345 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2346 play_tree_iter_free(mpctx
->playtree_iter
);
2347 mpctx
->playtree_iter
= NULL
;
2349 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2354 #if defined(WIN32) && defined(HAVE_NEW_GUI)
2355 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
2356 if(runningmplayer
&& filename
&& use_gui
){
2357 COPYDATASTRUCT csData
;
2358 char file
[MAX_PATH
];
2359 char *filepart
= filename
;
2360 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
2362 csData
.cbData
= strlen(file
)*2;
2363 csData
.lpData
= file
;
2364 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
2372 for(i
=0; priority_presets_defs
[i
].name
; i
++){
2373 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
2376 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
2377 priority_presets_defs
[i
].name
);
2378 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
2381 #ifndef HAVE_NEW_GUI
2383 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
2388 if(use_gui
&& !vo_init()){
2389 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
2393 if (use_gui
&& mpctx
->playtree_iter
){
2394 char cwd
[PATH_MAX
+2];
2395 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2396 play_tree_iter_free(mpctx
->playtree_iter
);
2397 mpctx
->playtree_iter
=NULL
;
2399 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
2402 // Prefix relative paths with current working directory
2403 play_tree_add_bpf(mpctx
->playtree
, cwd
);
2405 // Import initital playtree into GUI.
2406 import_initial_playtree_into_gui(mpctx
->playtree
, mconfig
, enqueue
);
2408 #endif /* HAVE_NEW_GUI */
2410 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
2415 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
2420 /* Check codecs.conf. */
2421 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2422 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2423 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2424 if(!parse_codec_cfg(NULL
)){
2425 exit_player_with_rc(NULL
, 0);
2427 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
2430 free( mem_ptr
); // release the buffer created by get_path()
2434 if(video_codec_list
){
2436 video_codec
=video_codec_list
[0];
2437 for(i
=0;video_codec_list
[i
];i
++)
2438 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2441 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2442 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
2443 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2445 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2448 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2449 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
2450 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2452 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2455 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2457 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2460 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
2462 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2465 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
2471 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
2473 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2477 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
2478 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
2479 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
2481 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2484 if(list_properties
) {
2485 property_print_help();
2492 if (player_idle_mode
&& use_gui
) {
2493 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
2494 exit_player_with_rc(NULL
, 1);
2497 if(!filename
&& !player_idle_mode
){
2499 // no file/vcd/dvd -> show HELP:
2500 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
2501 exit_player_with_rc(NULL
, 0);
2502 } else gui_no_filename
=1;
2505 /* Display what configure line was used */
2506 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
2508 // Many users forget to include command line in bugreports...
2509 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
2510 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
2511 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
2512 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2515 //------ load global data first ------
2518 #ifdef HAVE_FREETYPE
2521 #ifdef HAVE_FONTCONFIG
2522 if(!font_fontconfig
)
2525 #ifdef HAVE_BITMAP_FONT
2527 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
2528 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,
2529 filename_recode(font_name
));
2532 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
2533 free(mem_ptr
); // release the buffer created by get_path()
2535 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
2538 sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
2542 #ifdef HAVE_FONTCONFIG
2549 ass_library
= ass_init();
2555 // seteuid(0); /* Can't hurt to try to get root here */
2556 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
2557 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
2558 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
2560 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
2562 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
2563 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
2564 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
2567 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
2568 /* variable only by the root */
2569 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
2573 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
2577 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2578 // and now ? -- Pontscho
2579 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
2582 #endif /* HAVE_RTC */
2583 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
2584 softsleep
?"software":timer_name
);
2587 if ( !use_gui
) load_termcap(NULL
); // load key-codes
2590 // ========== Init keyboard FIFO (connection to libvo) ============
2592 // Init input system
2593 current_module
= "init_input";
2594 mp_input_init(use_gui
);
2595 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
2598 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
2600 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
2602 else if(!noconsolecontrols
)
2603 #ifdef HAVE_POSIX_SELECT
2604 mp_input_add_key_fd(0,1,NULL
,NULL
);
2606 mp_input_add_key_fd(0,0,NULL
,NULL
);
2609 inited_flags
|=INITED_INPUT
;
2610 current_module
= NULL
;
2614 if(menu_cfg
&& menu_init(mpctx
, menu_cfg
))
2615 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2617 menu_cfg
= get_path("menu.conf");
2618 if(menu_init(mpctx
, menu_cfg
))
2619 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2621 if(menu_init(mpctx
, MPLAYER_CONFDIR
"/menu.conf"))
2622 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
2624 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
2634 signal(SIGCHLD
,child_sighandler
);
2638 prog_path
= argv
[0];
2640 //========= Catch terminate signals: ================
2641 // terminate requests:
2642 signal(SIGTERM
,exit_sighandler
); // kill
2643 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
2645 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
2647 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
2648 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
2649 #ifdef ENABLE_SIGHANDLER
2651 signal(SIGBUS
,exit_sighandler
); // bus error
2652 signal(SIGSEGV
,exit_sighandler
); // segfault
2653 signal(SIGILL
,exit_sighandler
); // illegal instruction
2654 signal(SIGFPE
,exit_sighandler
); // floating point exc.
2655 signal(SIGABRT
,exit_sighandler
); // abort()
2658 signal(SIGTRAP
,exit_sighandler
);
2665 guiGetEvent(guiSetContext
, mpctx
);
2666 inited_flags
|=INITED_GUI
;
2667 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
2671 // ******************* Now, let's see the per-file stuff ********************
2675 // init global sub numbers
2676 mpctx
->global_sub_size
= 0;
2677 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) mpctx
->global_sub_indices
[i
] = -1; }
2679 if (filename
) load_per_file_config (mconfig
, filename
);
2681 // We must enable getch2 here to be able to interrupt network connection
2683 if(!noconsolecontrols
&& !slave_mode
){
2684 if(inited_flags
&INITED_GETCH2
)
2685 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
2687 getch2_enable(); // prepare stdin for hotkeys...
2688 inited_flags
|=INITED_GETCH2
;
2689 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
2692 // =================== GUI idle loop (STOP state) ===========================
2695 mpctx
->file_format
=DEMUXER_TYPE_UNKNOWN
;
2696 guiGetEvent( guiSetDefaults
,0 );
2697 while ( guiIntfStruct
.Playing
!= 1 )
2702 guiGetEvent( guiReDraw
,NULL
);
2703 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
2705 guiGetEvent( guiSetParameters
,NULL
);
2706 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
2708 play_tree_t
* entry
= play_tree_new();
2709 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
2710 if ( mpctx
->playtree
) play_tree_free_list( mpctx
->playtree
->child
,1 );
2711 else mpctx
->playtree
=play_tree_new();
2712 play_tree_set_child( mpctx
->playtree
,entry
);
2715 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
2716 if(mpctx
->playtree_iter
)
2718 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
2720 play_tree_iter_free(mpctx
->playtree_iter
);
2721 mpctx
->playtree_iter
= NULL
;
2723 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2728 #endif /* HAVE_NEW_GUI */
2730 while (player_idle_mode
&& !filename
) {
2731 play_tree_t
* entry
= NULL
;
2733 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
2734 if (mpctx
->video_out
&& vo_config_count
) mpctx
->video_out
->check_events();
2738 case MP_CMD_LOADFILE
:
2739 // prepare a tree entry with the new filename
2740 entry
= play_tree_new();
2741 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
2742 // The entry is added to the main playtree after the switch().
2744 case MP_CMD_LOADLIST
:
2745 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
2748 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
2754 if (entry
) { // user entered a command that gave a valid entry
2755 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
2756 play_tree_free_list(mpctx
->playtree
->child
, 1);
2757 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
2759 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
2761 play_tree_set_child(mpctx
->playtree
, entry
);
2763 /* Make iterator start at the top the of tree. */
2764 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mconfig
);
2765 if (!mpctx
->playtree_iter
) continue;
2767 // find the first real item in the tree
2768 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2770 play_tree_iter_free(mpctx
->playtree_iter
);
2771 mpctx
->playtree_iter
= NULL
;
2772 continue; // wait for next command
2774 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
2777 //---------------------------------------------------------------------------
2780 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
,
2781 filename_recode(filename
));
2784 if (edl_records
) free_edl(edl_records
);
2785 next_edl_record
= edl_records
= edl_parse_file();
2787 if (edl_output_filename
) {
2788 if (edl_fd
) fclose(edl_fd
);
2789 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
2791 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
2792 filename_recode(edl_output_filename
));
2796 //==================== Open VOB-Sub ============================
2798 current_module
="vobsub";
2800 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
2802 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,
2803 filename_recode(vobsub_name
));
2804 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
2805 /* try to autodetect vobsub from movie filename ::atmos */
2806 char *buf
= malloc((strlen(filename
)-3)),*psub
;
2807 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
2808 strncpy(buf
, filename
, strlen(filename
)-4);
2809 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
2810 /* try from ~/.mplayer/sub */
2811 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
2814 bname
= strrchr(buf
,'/');
2816 if(!bname
) bname
= strrchr(buf
,'\\');
2820 l
= strlen(psub
) + strlen(bname
) + 1;
2821 psub
= realloc(psub
,l
);
2823 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
2829 inited_flags
|=INITED_VOBSUB
;
2830 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
2831 // check if vobsub requested only to display forced subtitles
2832 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
2834 // setup global sub numbering
2835 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] = mpctx
->global_sub_size
; // the global # of the first vobsub.
2836 mpctx
->global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
2839 //============ Open & Sync STREAM --- fork cache2 ====================
2842 mpctx
->demuxer
=NULL
;
2843 if (mpctx
->d_audio
) {
2844 //free_demuxer_stream(mpctx->d_audio);
2845 mpctx
->d_audio
=NULL
;
2847 if (mpctx
->d_video
) {
2848 //free_demuxer_stream(d_video);
2849 mpctx
->d_video
=NULL
;
2851 mpctx
->sh_audio
=NULL
;
2852 mpctx
->sh_video
=NULL
;
2854 current_module
="open_stream";
2855 mpctx
->stream
=open_stream(filename
,0,&mpctx
->file_format
);
2856 if(!mpctx
->stream
) { // error...
2857 mpctx
->eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
2858 goto goto_next_file
;
2860 inited_flags
|=INITED_STREAM
;
2863 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)mpctx
->stream
);
2866 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
2869 current_module
="handle_playlist";
2870 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
2871 filename_recode(filename
));
2872 entry
= parse_playtree(mpctx
->stream
,0);
2873 mpctx
->eof
=playtree_add_playlist(entry
);
2874 goto goto_next_file
;
2876 mpctx
->stream
->start_pos
+=seek_to_byte
;
2878 if(stream_dump_type
==5){
2879 unsigned char buf
[4096];
2882 current_module
="dumpstream";
2883 if(mpctx
->stream
->type
==STREAMTYPE_STREAM
&& mpctx
->stream
->fd
<0){
2884 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
2885 exit_player(MSGTR_Exit_error
);
2887 stream_reset(mpctx
->stream
);
2888 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
2889 f
=fopen(stream_dump_name
,"wb");
2891 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
2892 exit_player(MSGTR_Exit_error
);
2894 while(!mpctx
->stream
->eof
){
2895 len
=stream_read(mpctx
->stream
,buf
,4096);
2897 if(fwrite(buf
,len
,1,f
) != 1) {
2898 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2899 exit_player(MSGTR_Exit_error
);
2904 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2905 exit_player(MSGTR_Exit_error
);
2907 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
2908 exit_player_with_rc(MSGTR_Exit_eof
, 0);
2912 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
2913 current_module
="dvd lang->id";
2914 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(mpctx
->stream
,audio_lang
);
2915 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
2916 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
2917 // setup global sub numbering
2918 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
2919 mpctx
->global_sub_size
+= dvd_number_of_subs(mpctx
->stream
);
2920 current_module
=NULL
;
2925 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
2926 current_module
="dvdnav lang->id";
2927 if(audio_id
==-1) audio_id
=dvdnav_aid_from_lang(mpctx
->stream
,audio_lang
);
2928 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
2929 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvdnav_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
2930 // setup global sub numbering
2931 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
2932 mpctx
->global_sub_size
+= dvdnav_number_of_subs(mpctx
->stream
);
2933 current_module
=NULL
;
2937 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
2939 if(stream_cache_size
>0){
2940 current_module
="enable_cache";
2941 if(!stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
2942 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
2943 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
2944 if((mpctx
->eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
2947 //============ Open DEMUXERS --- DETECT file type =======================
2948 current_module
="demux_open";
2950 mpctx
->demuxer
=demux_open(mpctx
->stream
,mpctx
->file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
2952 // HACK to get MOV Reference Files working
2954 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
2956 unsigned char* playlist_entry
;
2957 play_tree_t
*list
= NULL
, *entry
= NULL
;
2959 current_module
="handle_demux_playlist";
2960 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
2964 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
2965 filename_recode(playlist_entry
));
2967 bname
=mp_basename(playlist_entry
);
2968 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
2971 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
2974 entry
= play_tree_new();
2976 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
2978 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
2981 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
2982 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
2983 strcat(temp
, playlist_entry
);
2984 play_tree_add_file(entry
,temp
);
2985 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
2990 play_tree_add_file(entry
,playlist_entry
);
2995 play_tree_append_entry(list
,entry
);
2997 free_demuxer(mpctx
->demuxer
);
2998 mpctx
->demuxer
= NULL
;
3002 entry
= play_tree_new();
3003 play_tree_set_child(entry
,list
);
3004 mpctx
->eof
=playtree_add_playlist(entry
);
3005 goto goto_next_file
;
3010 goto goto_next_file
;
3011 inited_flags
|=INITED_DEMUXER
;
3013 if (mpctx
->stream
->type
!= STREAMTYPE_DVD
&& mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
) {
3015 // setup global sub numbering
3016 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3017 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
3018 if (mpctx
->demuxer
->s_streams
[i
])
3019 mpctx
->global_sub_size
++;
3021 if (mpctx
->global_sub_size
<= dvdsub_id
) mpctx
->global_sub_size
= dvdsub_id
+ 1;
3023 current_module
="demux_open2";
3025 //file_format=demuxer->file_format;
3027 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3028 mpctx
->d_video
=mpctx
->demuxer
->video
;
3029 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3032 if((stream_dump_type
)&&(stream_dump_type
<4)){
3034 demux_stream_t
*ds
=NULL
;
3035 current_module
="dump";
3036 // select stream to dump
3037 switch(stream_dump_type
){
3038 case 1: ds
=mpctx
->d_audio
;break;
3039 case 2: ds
=mpctx
->d_video
;break;
3040 case 3: ds
=mpctx
->d_sub
;break;
3043 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
3044 exit_player(MSGTR_Exit_error
);
3046 // disable other streams:
3047 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3048 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3049 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3051 f
=fopen(stream_dump_name
,"wb");
3053 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3054 exit_player(MSGTR_Exit_error
);
3057 unsigned char* start
;
3058 int in_size
=ds_get_packet(ds
,&start
);
3059 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3060 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3061 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3064 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3065 exit_player_with_rc(MSGTR_Exit_eof
, 0);
3068 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3069 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3071 if(mpctx
->sh_video
){
3073 current_module
="video_read_properties";
3074 if(!video_read_properties(mpctx
->sh_video
)) {
3075 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
3076 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3078 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3079 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3080 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3083 /* need to set fps here for output encoders to pick it up in their init */
3085 mpctx
->sh_video
->fps
=force_fps
;
3086 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3088 vo_fps
= mpctx
->sh_video
->fps
;
3090 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3091 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
3092 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3098 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3099 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
3100 #ifdef HAS_DVBIN_SUPPORT
3101 if((mpctx
->stream
->type
== STREAMTYPE_DVB
) && mpctx
->stream
->priv
)
3103 dvb_priv_t
*priv
= (dvb_priv_t
*) mpctx
->stream
->priv
;
3107 int v
= mpctx
->last_dvb_step
;
3109 dir
= DVB_CHANNEL_HIGHER
;
3111 dir
= DVB_CHANNEL_LOWER
;
3113 if(dvb_step_channel(priv
, dir
))
3114 mpctx
->eof
= mpctx
->dvbin_reopen
= 1;
3118 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3121 /* display clip info */
3122 demux_info_print(mpctx
->demuxer
);
3124 //================== Read SUBTITLES (DVD & TEXT) ==========================
3125 if(vo_spudec
==NULL
&& mpctx
->sh_video
&&
3126 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
|| mpctx
->d_sub
->id
>= 0)){
3130 // Apply current settings for forced subs
3131 if (vo_spudec
!=NULL
)
3132 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3134 if(mpctx
->sh_video
) {
3135 // after reading video params we should load subtitles because
3136 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3138 current_module
="read_subtitles_file";
3140 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3141 add_subtitles (sub_name
[i
], mpctx
->sh_video
->fps
, 0);
3143 if(sub_auto
) { // auto load sub file ...
3144 char *psub
= get_path( "sub/" );
3145 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
3147 free(psub
); // release the buffer created by get_path() above
3149 add_subtitles (tmp
[i
], mpctx
->sh_video
->fps
, 0);
3154 if (mpctx
->set_of_sub_size
> 0) {
3155 // setup global sub numbering
3156 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = mpctx
->global_sub_size
; // the global # of the first sub.
3157 mpctx
->global_sub_size
+= mpctx
->set_of_sub_size
;
3161 if (mpctx
->global_sub_size
) {
3162 // find the best sub to use
3163 if (vobsub_id
>= 0) {
3164 // if user asks for a vobsub id, use that first.
3165 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
3166 } else if (dvdsub_id
>= 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3167 // if user asks for a dvd sub id, use that next.
3168 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
3169 } else if (mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
3170 // if there are text subs to use, use those. (autosubs come last here)
3171 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
];
3173 } else if (mpctx->global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
3174 // if nothing else works, get subs from the demuxer.
3175 mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
3178 // nothing worth doing automatically.
3179 mpctx
->global_sub_pos
= -1;
3181 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3182 mpctx
->global_sub_pos
--;
3183 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
, mpctx
);
3185 switch (stream_dump_type
) {
3186 case 3: list_sub_file(subdata
); break;
3187 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
3188 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
3189 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
3190 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
3191 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
3195 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
3196 filename_recode(filename
));
3197 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
3198 if (mpctx
->sh_video
) {
3199 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3200 if (mpctx
->sh_video
->format
>= 0x20202020)
3201 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
3203 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
3204 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
3205 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
3206 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
3207 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
3208 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
3210 if (mpctx
->sh_audio
) {
3211 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3212 if (mpctx
->sh_audio
->format
>= 0x20202020)
3213 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
3215 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
3216 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
3217 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
3218 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
3220 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(mpctx
->demuxer
));
3222 if(!mpctx
->sh_video
) goto main
; // audio-only
3224 if(!reinit_video_chain()) {
3225 if(!mpctx
->sh_video
){
3226 if(!mpctx
->sh_audio
) goto goto_next_file
;
3227 goto main
; // exit_player(MSGTR_Exit_error);
3231 if(vo_flags
& 0x08 && vo_spudec
)
3232 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
3234 #ifdef HAVE_FREETYPE
3235 force_load_font
= 1;
3238 //================== MAIN: ==========================
3240 current_module
="main";
3243 char* msg
= property_expand_string(mpctx
, playing_msg
);
3244 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3249 // Disable the term OSD in verbose mode
3250 if(verbose
) term_osd
= 0;
3253 //int frame_corr_num=0; //
3254 //float v_frame=0; // Video
3255 float time_frame
=0; // Timer
3256 //float num_frames=0; // number of frames played
3258 int frame_time_remaining
=0; // flag
3260 mpctx
->num_buffered_frames
=0;
3262 // Make sure old OSD does not stay around,
3263 // e.g. with -fixed-vo and same-resolution files
3267 //================ SETUP AUDIO ==========================
3269 if(mpctx
->sh_audio
){
3270 reinit_audio_chain();
3271 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
3272 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
3275 current_module
="av_init";
3277 if(mpctx
->sh_video
){
3278 mpctx
->sh_video
->timer
=0;
3280 audio_delay
+= mpctx
->sh_video
->stream_delay
;
3282 if(mpctx
->sh_audio
){
3284 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
3285 mpctx
->delay
=-audio_delay
;
3288 if(!mpctx
->sh_audio
){
3289 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
3290 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
3291 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
3292 //mpctx->d_audio->id=-2; // do not read audio chunks
3293 //uninit_player(INITED_AO); // close device
3295 if(!mpctx
->sh_video
){
3296 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
3297 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
3298 ds_free_packs(mpctx
->d_video
);
3299 mpctx
->d_video
->id
=-2;
3300 //if(!fixed_vo) uninit_player(INITED_VO);
3303 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
3304 goto goto_next_file
;
3306 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3307 if(force_fps
&& mpctx
->sh_video
){
3308 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
3309 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3310 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
3315 if ( mpctx
->sh_audio
) guiIntfStruct
.AudioType
=mpctx
->sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
3316 if ( !mpctx
->sh_video
&& mpctx
->sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
3317 guiGetEvent( guiSetFileFormat
,(char *)mpctx
->demuxer
->file_format
);
3318 if ( guiGetEvent( guiSetValues
,(char *)mpctx
->sh_video
) ) goto goto_next_file
;
3319 guiGetEvent( guiSetDemuxer
,(char *)mpctx
->demuxer
);
3323 //==================== START PLAYING =======================
3325 if(loop_times
>1) loop_times
--; else
3326 if(loop_times
==1) loop_times
= -1;
3328 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);
3330 total_time_usage_start
=GetTimer();
3331 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3332 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3333 play_n_frames
=play_n_frames_mf
;
3335 if(play_n_frames
==0){
3336 mpctx
->eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
3340 seek(mpctx
, seek_to_sec
, 1);
3341 end_at
.pos
+= seek_to_sec
;
3344 if (end_at
.type
== END_AT_SIZE
) {
3345 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
3346 end_at
.type
= END_AT_NONE
;
3351 float aq_sleep_time
=0;
3352 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
3353 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
3354 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
3355 reinit_audio_chain();
3358 /*========================== PLAY AUDIO ============================*/
3360 if (mpctx
->sh_audio
)
3361 if (!fill_audio_out_buffers())
3362 // at eof, all audio at least written to ao
3363 if (!mpctx
->sh_video
)
3364 mpctx
->eof
= PT_NEXT_ENTRY
;
3367 if(!mpctx
->sh_video
) {
3368 // handle audio-only case:
3370 if(!quiet
|| end_at
.type
== END_AT_TIME
)
3371 a_pos
= playing_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
, mpctx
->audio_out
);
3374 print_status(a_pos
, 0, 0);
3376 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
3377 mpctx
->eof
= PT_NEXT_ENTRY
;
3382 /*========================== PLAY VIDEO ============================*/
3384 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
3385 vo_fps
=mpctx
->sh_video
->fps
;
3387 if (!mpctx
->num_buffered_frames
) {
3388 double frame_time
= update_video(&blit_frame
);
3389 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3390 if (mpctx
->sh_video
->vf_inited
< 0) {
3391 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
3392 mpctx
->eof
= 1; goto goto_next_file
;
3397 // might return with !eof && !blit_frame if !correct_pts
3398 mpctx
->num_buffered_frames
+= blit_frame
;
3399 time_frame
+= frame_time
/ playback_speed
; // for nosound
3403 // ==========================================================================
3405 // current_module="draw_osd";
3406 // if(vo_config_count) mpctx->video_out->draw_osd();
3409 if(use_gui
) guiEventHandling();
3412 current_module
="vo_check_events";
3413 if (vo_config_count
) mpctx
->video_out
->check_events();
3416 if (stop_xscreensaver
) {
3417 current_module
= "stop_xscreensaver";
3418 xscreensaver_heartbeat();
3422 frame_time_remaining
= sleep_until_update(&time_frame
, &aq_sleep_time
);
3424 //====================== FLIP PAGE (VIDEO BLT): =========================
3426 current_module
="flip_page";
3427 if (!frame_time_remaining
&& blit_frame
) {
3428 unsigned int t2
=GetTimer();
3430 if(vo_config_count
) mpctx
->video_out
->flip_page();
3431 mpctx
->num_buffered_frames
--;
3433 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
3435 //====================== A-V TIMESTAMP CORRECTION: =========================
3437 adjust_sync_and_print_status(frame_time_remaining
, time_frame
);
3439 //============================ Auto QUALITY ============================
3441 /*Output quality adjustments:*/
3443 current_module
="autoq";
3444 // float total=0.000001f * (GetTimer()-aq_total_time);
3445 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
3446 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
3449 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
3450 if(output_quality
>1 && aq_sleep_time
<0)
3453 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
3455 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
3456 set_video_quality(mpctx
->sh_video
,output_quality
);
3459 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
3461 if (play_n_frames
<= 0) mpctx
->eof
= PT_NEXT_ENTRY
;
3465 // FIXME: add size based support for -endpos
3466 if (end_at
.type
== END_AT_TIME
&&
3467 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
3468 mpctx
->eof
= PT_NEXT_ENTRY
;
3470 } // end if(mpctx->sh_video)
3473 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3475 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
3476 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
3477 vo_osd_changed (OSDTYPE_DVDNAV
);
3481 //============================ Handle PAUSE ===============================
3483 current_module
="pause";
3486 // 36000000 means max timed visibility is 1 hour into the future, if
3487 // the difference is greater assume it's wrapped around from below 0
3488 if (osd_visible
- GetTimerMS() > 36000000) {
3490 vo_osd_progbar_type
=-1; // disable
3491 vo_osd_changed(OSDTYPE_PROGBAR
);
3492 if (mpctx
->osd_function
!= OSD_PAUSE
)
3493 mpctx
->osd_function
= OSD_PLAY
;
3497 if (mpctx
->osd_function
== OSD_PAUSE
) {
3499 mpctx
->was_paused
= 1;
3504 mpctx
->osd_function
=OSD_FFW
;
3505 rel_seek_secs
+=step_sec
;
3510 //================= Keyboard events, SEEKing ====================
3512 current_module
="key_events";
3517 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
3518 brk_cmd
= run_command(mpctx
, cmd
);
3521 goto goto_enable_cache
;
3524 mpctx
->was_paused
= 0;
3527 if(mpctx
->eof
==1 && loop_times
>=0) {
3529 play_tree_iter_step(mpctx
->playtree_iter
,0,0);
3531 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,mpctx
->eof
);
3533 if(loop_times
>1) loop_times
--; else
3534 if(loop_times
==1) loop_times
=-1;
3535 play_n_frames
=play_n_frames_mf
;
3537 abs_seek_pos
=1; rel_seek_secs
=seek_to_sec
;
3541 if(rel_seek_secs
|| abs_seek_pos
){
3542 if (seek(mpctx
, rel_seek_secs
, abs_seek_pos
) >= 0) {
3546 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(mpctx
->demuxer
));
3548 // osd_function has been set (or not) by the code triggering the seek
3549 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
3561 if(mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
&& mpctx
->sh_video
&& mpctx
->sh_video
->video
.dwLength
>2){
3562 // get pos from frame number / total frames
3563 guiIntfStruct
.Position
=(float)mpctx
->d_video
->pack_no
*100.0f
/mpctx
->sh_video
->video
.dwLength
;
3565 guiIntfStruct
.Position
=demuxer_get_percent_pos(mpctx
->demuxer
);
3567 if ( mpctx
->sh_video
) guiIntfStruct
.TimeSec
=mpctx
->sh_video
->pts
;
3568 else if ( mpctx
->sh_audio
) guiIntfStruct
.TimeSec
=playing_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
, mpctx
->audio_out
);
3569 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(mpctx
->demuxer
);
3570 guiGetEvent( guiReDraw
,NULL
);
3571 guiGetEvent( guiSetVolume
,NULL
);
3572 if(guiIntfStruct
.Playing
==0) break; // STOP
3573 if(guiIntfStruct
.Playing
==2) mpctx
->osd_function
=OSD_PAUSE
;
3574 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3576 if ( mpctx
->stream
->type
== STREAMTYPE_DVD
)
3578 dvd_priv_t
* dvdp
= mpctx
->stream
->priv
;
3579 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3583 #endif /* HAVE_NEW_GUI */
3585 } // while(!mpctx->eof)
3587 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->eof
);
3589 #ifdef HAS_DVBIN_SUPPORT
3590 if(mpctx
->dvbin_reopen
)
3593 uninit_player(INITED_ALL
-(INITED_GUI
|INITED_STREAM
|INITED_INPUT
|INITED_GETCH2
|(fixed_vo
?INITED_VO
:0)));
3594 cache_uninit(mpctx
->stream
);
3595 mpctx
->dvbin_reopen
= 0;
3596 goto goto_enable_cache
;
3601 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3603 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3606 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3607 double total_time_usage
;
3608 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3609 total_time_usage
= (float)total_time_usage_start
*0.000001;
3610 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3611 video_time_usage
,vout_time_usage
,audio_time_usage
,
3612 total_time_usage
-tot
,total_time_usage
);
3613 if(total_time_usage
>0.0)
3614 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3615 100.0*video_time_usage
/total_time_usage
,
3616 100.0*vout_time_usage
/total_time_usage
,
3617 100.0*audio_time_usage
/total_time_usage
,
3618 100.0*(total_time_usage
-tot
)/total_time_usage
,
3620 if(total_frame_cnt
&& frame_dropping
)
3621 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3622 total_frame_cnt
-drop_frame_cnt
,
3623 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3625 100*drop_frame_cnt
/total_frame_cnt
,
3627 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
3631 // time to uninit all, except global stuff:
3632 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
3634 if ( mpctx
->set_of_sub_size
> 0 )
3636 current_module
="sub_free";
3637 for (i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
3638 sub_free( mpctx
->set_of_subtitles
[i
] );
3640 if ( mpctx
->set_of_ass_tracks
[i
] )
3641 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
3644 mpctx
->set_of_sub_size
= 0;
3646 vo_sub_last
= vo_sub
=NULL
;
3652 if(mpctx
->eof
== PT_NEXT_ENTRY
|| mpctx
->eof
== PT_PREV_ENTRY
) {
3653 mpctx
->eof
= mpctx
->eof
== PT_NEXT_ENTRY
? 1 : -1;
3654 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
3657 play_tree_iter_free(mpctx
->playtree_iter
);
3658 mpctx
->playtree_iter
= NULL
;
3660 mpctx
->play_tree_step
= 1;
3661 } else if (mpctx
->eof
== PT_UP_NEXT
|| mpctx
->eof
== PT_UP_PREV
) {
3662 mpctx
->eof
= mpctx
->eof
== PT_UP_NEXT
? 1 : -1;
3663 if ( mpctx
->playtree_iter
) {
3664 if(play_tree_iter_up_step(mpctx
->playtree_iter
,mpctx
->eof
,0) == PLAY_TREE_ITER_ENTRY
) {
3667 play_tree_iter_free(mpctx
->playtree_iter
);
3668 mpctx
->playtree_iter
= NULL
;
3671 } else { // NEXT PREV SRC
3672 mpctx
->eof
= mpctx
->eof
== PT_PREV_SRC
? -1 : 1;
3675 if(mpctx
->eof
== 0) mpctx
->eof
= 1;
3677 while(mpctx
->playtree_iter
!= NULL
) {
3678 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,mpctx
->eof
);
3679 if(filename
== NULL
) {
3680 if( play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->eof
,0) != PLAY_TREE_ITER_ENTRY
) {
3681 play_tree_iter_free(mpctx
->playtree_iter
);
3682 mpctx
->playtree_iter
= NULL
;
3689 if( use_gui
&& !mpctx
->playtree_iter
)
3692 if ( !guiIntfStruct
.DiskChanged
)
3698 if(use_gui
|| mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
3699 if (!mpctx
->playtree_iter
) filename
= NULL
;
3701 goto play_next_file
;
3705 exit_player_with_rc(MSGTR_Exit_eof
, 0);