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 */
43 #define HELP_MP_DEFINE_STATIC
48 #include "m_property.h"
50 #include "cfg-mplayer-def.h"
52 #include "subreader.h"
54 #include "libvo/video_out.h"
56 #include "libvo/font_load.h"
57 #include "libvo/sub.h"
60 #include "libvo/x11_common.h"
63 #include "libao2/audio_out.h"
65 #include "codec-cfg.h"
72 #include "osdep/getch2.h"
73 #include "osdep/timer.h"
75 #include "cpudetect.h"
78 #include "gui/interface.h"
81 #include "input/input.h"
84 int player_idle_mode
=0;
86 int enable_mouse_movements
=0;
89 char * proc_priority
=NULL
;
92 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
96 #include <linux/rtc.h>
99 #define RTC_IRQP_SET RTCIO_IRQP_SET
100 #define RTC_PIE_ON RTCIO_PIE_ON
101 #endif /* __linux__ */
102 #endif /* HAVE_RTC */
105 #include "stream/tv.h"
108 #include "stream/stream_radio.h"
111 #ifdef HAS_DVBIN_SUPPORT
112 #include "stream/dvbin.h"
113 #include "stream/cache2.h"
116 //**************************************************************************//
118 //**************************************************************************//
119 #include "playtree.h"
120 #include "playtreeparser.h"
123 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
124 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
127 //**************************************************************************//
129 //**************************************************************************//
130 #include "parser-cfg.h"
131 #include "parser-mpcmd.h"
135 //**************************************************************************//
137 //**************************************************************************//
139 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
141 static int cfg_include(m_option_t
*conf
, char *filename
){
142 return m_config_parse_config_file(mconfig
, filename
);
145 #include "get_path.h"
147 //**************************************************************************//
149 //**************************************************************************//
152 void xscreensaver_heartbeat(void);
155 //**************************************************************************//
156 //**************************************************************************//
157 // Input media streaming & demultiplexer:
158 //**************************************************************************//
160 static int max_framesize
=0;
162 #include "stream/stream.h"
163 #include "libmpdemux/demuxer.h"
164 #include "libmpdemux/stheader.h"
165 //#include "parse_es.h"
166 #include "libmpdemux/matroska.h"
169 #include "stream/stream_dvd.h"
173 #include "stream/stream_dvdnav.h"
176 #include "libmpcodecs/dec_audio.h"
177 #include "libmpcodecs/dec_video.h"
178 #include "libmpcodecs/mp_image.h"
179 #include "libmpcodecs/vf.h"
180 #include "libmpcodecs/vd.h"
186 //**************************************************************************//
187 //**************************************************************************//
189 // Common FIFO functions, and keyboard/event FIFO code
191 int noconsolecontrols
=0;
192 //**************************************************************************//
194 // Not all functions in mplayer.c take the context as an argument yet
195 static MPContext mpctx_s
= {
196 .osd_function
= OSD_PLAY
,
197 .begin_skip
= MP_NOPTS_VALUE
,
199 .global_sub_pos
= -1,
200 .set_of_sub_pos
= -1,
201 .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_seek
=0;
249 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
252 int autosync
=0; // 30 might be a good default value.
254 // may be changed by GUI: (FIXME!)
255 float rel_seek_secs
=0;
259 char **audio_codec_list
=NULL
; // override audio codec
260 char **video_codec_list
=NULL
; // override video codec
261 char **audio_fm_list
=NULL
; // override audio codec family
262 char **video_fm_list
=NULL
; // override video codec family
265 extern char *demuxer_name
; // override demuxer
266 extern char *audio_demuxer_name
; // override audio demuxer
267 extern char *sub_demuxer_name
; // override sub demuxer
274 char* audio_lang
=NULL
;
275 char* dvdsub_lang
=NULL
;
276 static char* spudec_ifo
=NULL
;
277 char* filename
=NULL
; //"MI2-Trailer.avi";
278 int forced_subs_only
=0;
282 int stream_cache_size
=-1;
283 #ifdef USE_STREAM_CACHE
284 extern int cache_fill_status
;
286 float stream_cache_min_percent
=20.0;
287 float stream_cache_seek_min_percent
=50.0;
289 #define cache_fill_status 0
293 static char *stream_dump_name
="stream.dump";
294 int stream_dump_type
=0;
297 static float default_max_pts_correction
=-1;//0.01f;
298 static float max_pts_correction
=0;//default_max_pts_correction;
299 static float c_total
=0;
301 static int ignore_start
=0;
303 static int softsleep
=0;
306 static int force_srate
=0;
307 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
308 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
309 static int play_n_frames
=-1;
310 static int play_n_frames_mf
=-1;
313 char** video_driver_list
=NULL
;
314 char** audio_driver_list
=NULL
;
317 char *font_name
=NULL
;
318 char *sub_font_name
=NULL
;
319 #ifdef HAVE_FONTCONFIG
320 extern int font_fontconfig
;
322 float font_factor
=0.75;
323 char **sub_name
=NULL
;
327 char *vobsub_name
=NULL
;
328 /*DSP!!char *dsp=NULL;*/
330 int suboverlap_enabled
= 1;
333 #include "libass/ass.h"
334 #include "libass/ass_mp.h"
337 extern int mp_msg_levels
[MSGT_MAX
];
338 extern int mp_msg_level_all
;
340 char* current_module
=NULL
; // for debugging
346 #include "m_struct.h"
347 #include "libmenu/menu.h"
348 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
349 extern vf_info_t vf_info_menu
;
350 static vf_info_t
* libmenu_vfs
[] = {
354 static vf_instance_t
* vf_menu
= NULL
;
355 static int use_menu
= 0;
356 static char* menu_cfg
= NULL
;
357 static char* menu_root
= "main";
362 static int nortc
= 1;
363 static char* rtc_device
;
366 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
367 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
368 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
369 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
370 int use_filedir_conf
;
372 static unsigned int inited_flags
=0;
373 #include "mpcommon.h"
376 #include "metadata.h"
378 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
380 void *mpctx_get_video_out(MPContext
*mpctx
)
382 return mpctx
->video_out
;
385 void *mpctx_get_audio_out(MPContext
*mpctx
)
387 return mpctx
->audio_out
;
390 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
392 return mpctx
->playtree_iter
;
395 void *mpctx_get_mixer(MPContext
*mpctx
)
397 return &mpctx
->mixer
;
400 int mpctx_get_global_sub_size(MPContext
*mpctx
)
402 return mpctx
->global_sub_size
;
405 static int is_valid_metadata_type (metadata_t type
) {
408 /* check for valid video stream */
409 case META_VIDEO_CODEC
:
410 case META_VIDEO_BITRATE
:
411 case META_VIDEO_RESOLUTION
:
413 if (!mpctx
->sh_video
)
418 /* check for valid audio stream */
419 case META_AUDIO_CODEC
:
420 case META_AUDIO_BITRATE
:
421 case META_AUDIO_SAMPLES
:
423 if (!mpctx
->sh_audio
)
428 /* check for valid demuxer */
429 case META_INFO_TITLE
:
430 case META_INFO_ARTIST
:
431 case META_INFO_ALBUM
:
433 case META_INFO_COMMENT
:
434 case META_INFO_TRACK
:
435 case META_INFO_GENRE
:
449 static char *get_demuxer_info (char *tag
) {
450 char **info
= mpctx
->demuxer
->info
;
456 for (n
= 0; info
[2*n
] != NULL
; n
++)
457 if (!strcmp (info
[2*n
], tag
))
460 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
463 char *get_metadata (metadata_t type
) {
465 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
466 sh_video_t
* const sh_video
= mpctx
->sh_video
;
468 if (!is_valid_metadata_type (type
))
475 return strdup (mp_basename2 (filename
));
478 case META_VIDEO_CODEC
:
480 if (sh_video
->format
== 0x10000001)
481 meta
= strdup ("mpeg1");
482 else if (sh_video
->format
== 0x10000002)
483 meta
= strdup ("mpeg2");
484 else if (sh_video
->format
== 0x10000004)
485 meta
= strdup ("mpeg4");
486 else if (sh_video
->format
== 0x10000005)
487 meta
= strdup ("h264");
488 else if (sh_video
->format
>= 0x20202020)
491 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
496 sprintf (meta
, "0x%08X", sh_video
->format
);
501 case META_VIDEO_BITRATE
:
504 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
508 case META_VIDEO_RESOLUTION
:
511 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
515 case META_AUDIO_CODEC
:
517 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
518 meta
= strdup (sh_audio
->codec
->name
);
522 case META_AUDIO_BITRATE
:
525 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
529 case META_AUDIO_SAMPLES
:
532 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
536 /* check for valid demuxer */
537 case META_INFO_TITLE
:
538 return get_demuxer_info ("Title");
540 case META_INFO_ARTIST
:
541 return get_demuxer_info ("Artist");
543 case META_INFO_ALBUM
:
544 return get_demuxer_info ("Album");
547 return get_demuxer_info ("Year");
549 case META_INFO_COMMENT
:
550 return get_demuxer_info ("Comment");
552 case META_INFO_TRACK
:
553 return get_demuxer_info ("Track");
555 case META_INFO_GENRE
:
556 return get_demuxer_info ("Genre");
565 /// step size of mixer changes
568 void uninit_player(unsigned int mask
){
569 mask
=inited_flags
&mask
;
571 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
573 if(mask
&INITED_ACODEC
){
574 inited_flags
&=~INITED_ACODEC
;
575 current_module
="uninit_acodec";
576 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
578 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
580 mpctx
->sh_audio
=NULL
;
581 mpctx
->mixer
.afilter
= NULL
;
584 if(mask
&INITED_VCODEC
){
585 inited_flags
&=~INITED_VCODEC
;
586 current_module
="uninit_vcodec";
587 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
588 mpctx
->sh_video
=NULL
;
594 if(mask
&INITED_DEMUXER
){
595 inited_flags
&=~INITED_DEMUXER
;
596 current_module
="free_demuxer";
598 mpctx
->stream
=mpctx
->demuxer
->stream
;
599 free_demuxer(mpctx
->demuxer
);
604 // kill the cache process:
605 if(mask
&INITED_STREAM
){
606 inited_flags
&=~INITED_STREAM
;
607 current_module
="uninit_stream";
608 if(mpctx
->stream
) free_stream(mpctx
->stream
);
613 inited_flags
&=~INITED_VO
;
614 current_module
="uninit_vo";
615 mpctx
->video_out
->uninit();
616 mpctx
->video_out
=NULL
;
619 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
620 if(mask
&INITED_GETCH2
){
621 inited_flags
&=~INITED_GETCH2
;
622 current_module
="uninit_getch2";
623 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
628 if(mask
&INITED_VOBSUB
){
629 inited_flags
&=~INITED_VOBSUB
;
630 current_module
="uninit_vobsub";
631 if(vo_vobsub
) vobsub_close(vo_vobsub
);
635 if (mask
&INITED_SPUDEC
){
636 inited_flags
&=~INITED_SPUDEC
;
637 current_module
="uninit_spudec";
638 spudec_free(vo_spudec
);
643 inited_flags
&=~INITED_AO
;
644 current_module
="uninit_ao";
645 if (mpctx
->user_muted
| mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
646 mpctx
->audio_out
->uninit(mpctx
->eof
?0:1); mpctx
->audio_out
=NULL
;
651 inited_flags
&=~INITED_GUI
;
652 current_module
="uninit_gui";
657 if(mask
&INITED_INPUT
){
658 inited_flags
&=~INITED_INPUT
;
659 current_module
="uninit_input";
666 void exit_player_with_rc(const char* how
, int rc
){
668 uninit_player(INITED_ALL
);
673 vo_uninit(); // Close the X11 connection (if any is open).
677 current_module
="uninit_font";
678 if (vo_font
) free_font_desc(vo_font
);
685 ass_library_done(ass_library
);
688 current_module
="exit_player";
690 // free mplayer config
692 m_config_free(mconfig
);
695 play_tree_free(mpctx
->playtree
, 1);
698 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
699 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
700 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
705 void exit_player(const char* how
){
706 exit_player_with_rc(how
, 1);
710 static void child_sighandler(int x
){
712 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
717 static char *prog_path
;
718 static int crash_debug
= 0;
721 static void exit_sighandler(int x
){
722 static int sig_count
=0;
724 if (!crash_debug
|| x
!= SIGTRAP
)
727 if(inited_flags
==0 && sig_count
>1) exit(1);
730 /* We're crashing bad and can't uninit cleanly :(
731 * by popular request, we make one last (dirty)
732 * effort to restore the user's
737 if(sig_count
==6) exit(1);
741 kill(getpid(),SIGKILL
);
744 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
745 current_module
?current_module
:"unknown"
747 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
754 break; // killed from keyboard (^C) or killed [-9]
756 #ifdef RUNTIME_CPUDETECT
757 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
759 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
763 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
765 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
770 snprintf(spid
, 19, "%i", getpid());
772 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
774 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
775 if (gdb_pid
== 0) { // We are the child
776 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
777 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
778 } else if (gdb_pid
< 0)
779 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
781 waitpid(gdb_pid
, NULL
, 0);
783 if (x
== SIGTRAP
) return;
790 extern void mp_input_register_options(m_config_t
* cfg
);
792 #include "cfg-mplayer.h"
794 static void parse_cfgfiles( m_config_t
* conf
)
798 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
800 if ((conffile
= get_path("")) == NULL
) {
801 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
806 mkdir(conffile
, 0777);
809 if ((conffile
= get_path("config")) == NULL
) {
810 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
812 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
813 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
814 write(conffile_fd
, default_config
, strlen(default_config
));
817 if (m_config_parse_config_file(conf
, conffile
) < 0)
824 void load_per_file_config (m_config_t
* conf
, const char *const file
)
827 char cfg
[strlen(file
)+10];
831 sprintf (cfg
, "%s.conf", file
);
833 if (use_filedir_conf
&& !stat (cfg
, &st
))
835 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
836 m_config_parse_config_file (conf
, cfg
);
840 if ((name
= strrchr (cfg
, '/')) == NULL
)
845 if ((confpath
= get_path (name
)) != NULL
)
847 if (!stat (confpath
, &st
))
849 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
850 m_config_parse_config_file (conf
, confpath
);
857 /* When libmpdemux performs a blocking operation (network connection or
858 * cache filling) if the operation fails we use this function to check
859 * if it was interrupted by the user.
860 * The function returns a new value for eof. */
861 static int libmpdemux_was_interrupted(int eof
) {
863 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
866 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
867 case MP_CMD_PLAY_TREE_STEP
: {
868 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
869 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
871 case MP_CMD_PLAY_TREE_UP_STEP
: {
872 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
874 case MP_CMD_PLAY_ALT_SRC_STEP
: {
875 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
883 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
885 int playtree_add_playlist(play_tree_t
* entry
)
887 play_tree_add_bpf(entry
,filename
);
892 import_playtree_playlist_into_gui(entry
, mconfig
);
893 play_tree_free_list(entry
,1);
899 entry
= mpctx
->playtree_iter
->tree
;
900 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
901 return PT_NEXT_ENTRY
;
903 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
904 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
905 return PT_NEXT_ENTRY
;
908 play_tree_remove(entry
,1,1);
911 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
912 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
913 entry
= mpctx
->playtree_iter
->tree
;
914 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
915 return PT_NEXT_ENTRY
;
917 play_tree_remove(entry
,1,1);
922 void add_subtitles(char *filename
, float fps
, int silent
)
926 ass_track_t
*asst
= 0;
929 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
933 subd
= sub_read_file(filename
, fps
);
937 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
939 asst
= ass_read_file(ass_library
, filename
, 0);
941 if (ass_enabled
&& subd
&& !asst
)
942 asst
= ass_read_subdata(ass_library
, subd
, fps
);
944 if (!asst
&& !subd
&& !silent
)
948 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
,
949 filename_recode(filename
));
952 if (!asst
&& !subd
) return;
953 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
957 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
958 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
959 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
960 filename_recode(filename
));
961 ++mpctx
->set_of_sub_size
;
962 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, mpctx
->set_of_sub_size
,
963 filename_recode(filename
));
966 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
967 void update_set_of_subtitles(void)
968 // subdata was changed, set_of_sub... have to be updated.
970 sub_data
** const set_of_subtitles
= mpctx
->set_of_subtitles
;
972 if (mpctx
->set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
973 for (i
= mpctx
->set_of_sub_pos
+ 1; i
< mpctx
->set_of_sub_size
; ++i
)
974 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
975 set_of_subtitles
[mpctx
->set_of_sub_size
-1] = NULL
;
976 --mpctx
->set_of_sub_size
;
977 if (mpctx
->set_of_sub_size
> 0) subdata
= set_of_subtitles
[mpctx
->set_of_sub_pos
=0];
979 else if (mpctx
->set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
980 set_of_subtitles
[mpctx
->set_of_sub_pos
] = subdata
;
982 else if (mpctx
->set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
983 set_of_subtitles
[mpctx
->set_of_sub_pos
=mpctx
->set_of_sub_size
] = subdata
;
984 ++mpctx
->set_of_sub_size
;
988 void init_vo_spudec(void) {
990 spudec_free(vo_spudec
);
991 inited_flags
&= ~INITED_SPUDEC
;
994 unsigned int palette
[16], width
, height
;
995 current_module
="spudec_init_vobsub";
996 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
997 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1001 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1002 current_module
="spudec_init_dvdread";
1003 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1004 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1009 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1010 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1011 current_module
="spudec_init_dvdnav";
1012 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1016 if ((vo_spudec
== NULL
) && (mpctx
->demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1017 (mpctx
->d_sub
->sh
!= NULL
) && (((sh_sub_t
*)mpctx
->d_sub
->sh
)->type
== 'v')) {
1018 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1019 current_module
= "spudec_init_matroska";
1021 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1022 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1023 mkv_sh_sub
->height
);
1024 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1027 if (vo_spudec
==NULL
) {
1028 sh_sub_t
*sh
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1029 unsigned int *palette
= NULL
;
1030 if (sh
&& sh
->has_palette
)
1031 palette
= sh
->palette
;
1032 current_module
="spudec_init_normal";
1033 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1034 spudec_set_font_factor(vo_spudec
,font_factor
);
1037 if (vo_spudec
!=NULL
)
1038 inited_flags
|=INITED_SPUDEC
;
1042 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1043 * make it all work is to use the builtin SDL-bootstrap code, which
1044 * will be done automatically by replacing our main() if we include SDL.h.
1046 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1051 * \brief append a formatted string
1052 * \param buf buffer to print into
1053 * \param pos position of terminating 0 in buf
1054 * \param len maximum number of characters in buf, not including terminating 0
1055 * \param format printf format string
1057 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1060 va_start(va
, format
);
1061 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1070 * \brief append time in the hh:mm:ss.f format
1071 * \param buf buffer to print into
1072 * \param pos position of terminating 0 in buf
1073 * \param len maximum number of characters in buf, not including terminating 0
1074 * \param time time value to convert/append
1076 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1077 long tenths
= 10 * time
;
1078 int f1
= tenths
% 10;
1079 int ss
= (tenths
/ 10) % 60;
1080 int mm
= (tenths
/ 600) % 60;
1081 int hh
= tenths
/ 36000;
1083 saddf(buf
, pos
, len
, "unknown");
1087 saddf(buf
, pos
, len
, "%2d:", hh
);
1088 if (hh
> 0 || mm
> 0)
1089 saddf(buf
, pos
, len
, "%02d:", mm
);
1090 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1094 * \brief print the status line
1095 * \param a_pos audio position
1096 * \param a_v A-V desynchronization
1097 * \param corr amount out A-V synchronization
1099 static void print_status(float a_pos
, float a_v
, float corr
)
1101 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1106 if (screen_width
> 0)
1107 width
= screen_width
;
1111 /* Windows command line is broken (MinGW's rxvt works, but we
1112 * should not depend on that). */
1115 line
= malloc(width
+ 1); // one additional char for the terminating null
1118 if (mpctx
->sh_audio
) {
1119 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1121 float len
= demuxer_get_time_length(mpctx
->demuxer
);
1122 saddf(line
, &pos
, width
, "(");
1123 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1124 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1125 sadd_hhmmssf(line
, &pos
, width
, len
);
1126 saddf(line
, &pos
, width
, ") ");
1132 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1135 if (mpctx
->sh_audio
&& sh_video
)
1136 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1140 saddf(line
, &pos
, width
, "%3d/%3d ",
1141 (int)sh_video
->num_frames
,
1142 (int)sh_video
->num_frames_decoded
);
1146 if (sh_video
->timer
> 0.5)
1147 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1148 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
1149 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
1150 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
1152 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1153 } else if (mpctx
->sh_audio
) {
1154 if (mpctx
->delay
> 0.5)
1155 saddf(line
, &pos
, width
, "%4.1f%% ",
1156 100.0*audio_time_usage
/(double)mpctx
->delay
);
1158 saddf(line
, &pos
, width
, "??,?%% ");
1163 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1165 #ifdef USE_STREAM_CACHE
1167 if (stream_cache_size
> 0)
1168 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1172 if (playback_speed
!= 1)
1173 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
1176 if (erase_to_end_of_line
) {
1178 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1180 memset(&line
[pos
], ' ', width
- pos
);
1182 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s\r", line
);
1188 * \brief build a chain of audio filters that converts the input format
1189 * to the ao's format, taking into account the current playback_speed.
1190 * \param sh_audio describes the requested input format of the chain.
1191 * \param ao_data describes the requested output format of the chain.
1193 int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1200 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
1202 mpctx
->mixer
.afilter
= NULL
;
1205 new_srate
= sh_audio
->samplerate
* playback_speed
;
1206 if (new_srate
!= ao_data
->samplerate
) {
1207 // limits are taken from libaf/af_resample.c
1208 if (new_srate
< 8000)
1210 if (new_srate
> 192000)
1212 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1214 result
= init_audio_filters(sh_audio
, new_srate
,
1215 sh_audio
->channels
, sh_audio
->sample_format
,
1216 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1217 ao_data
->outburst
* 4, ao_data
->buffersize
);
1218 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1220 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1226 typedef struct mp_osd_msg mp_osd_msg_t
;
1228 /// Previous message on the stack.
1232 int id
,level
,started
;
1233 /// Display duration in ms.
1237 /// OSD message stack.
1238 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1241 * \brief Add a message on the OSD message stack
1243 * If a message with the same id is already present in the stack
1244 * it is pulled on top of the stack, otherwise a new message is created.
1248 void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1249 mp_osd_msg_t
*msg
,*last
=NULL
;
1253 // look if the id is already in the stack
1254 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1255 last
= msg
, msg
= msg
->prev
);
1256 // not found: alloc it
1258 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1259 msg
->prev
= osd_msg_stack
;
1260 osd_msg_stack
= msg
;
1261 } else if(last
) { // found, but it's not on top of the stack
1262 last
->prev
= msg
->prev
;
1263 msg
->prev
= osd_msg_stack
;
1264 osd_msg_stack
= msg
;
1268 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1270 if(r
>= 64) msg
->msg
[63] = 0;
1279 * \brief Remove a message from the OSD stack
1281 * This function can be used to get rid of a message right away.
1285 void rm_osd_msg(int id
) {
1286 mp_osd_msg_t
*msg
,*last
=NULL
;
1288 // Search for the msg
1289 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1290 last
= msg
, msg
= msg
->prev
);
1293 // Detach it from the stack and free it
1295 last
->prev
= msg
->prev
;
1297 osd_msg_stack
= msg
->prev
;
1302 * \brief Remove all messages from the OSD stack
1306 static void clear_osd_msgs(void) {
1307 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1313 osd_msg_stack
= NULL
;
1317 * \brief Get the current message from the OSD stack.
1319 * This function decrements the message timer and destroys the old ones.
1320 * The message that should be displayed is returned (if any).
1324 static mp_osd_msg_t
* get_osd_msg(void) {
1325 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1326 static unsigned last_update
= 0;
1327 unsigned now
= GetTimerMS();
1329 char hidden_dec_done
= 0;
1332 // 36000000 means max timed visibility is 1 hour into the future, if
1333 // the difference is greater assume it's wrapped around from below 0
1334 if (osd_visible
- now
> 36000000) {
1336 vo_osd_progbar_type
= -1; // disable
1337 vo_osd_changed(OSDTYPE_PROGBAR
);
1338 if (mpctx
->osd_function
!= OSD_PAUSE
)
1339 mpctx
->osd_function
= OSD_PLAY
;
1343 if(!last_update
) last_update
= now
;
1344 diff
= now
>= last_update
? now
- last_update
: 0;
1348 // Look for the first message in the stack with high enough level.
1349 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1351 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1352 // The message has a high enough level or it is the first hidden one
1353 // in both cases we decrement the timer or kill it.
1354 if(!msg
->started
|| msg
->time
> diff
) {
1355 if(msg
->started
) msg
->time
-= diff
;
1356 else msg
->started
= 1;
1358 if(msg
->level
<= osd_level
) return msg
;
1359 hidden_dec_done
= 1;
1368 osd_msg_stack
= prev
;
1377 * \brief Display the OSD bar.
1379 * Display the OSD bar or fall back on a simple message.
1383 void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1385 if(osd_level
< 1) return;
1387 if(mpctx
->sh_video
) {
1388 osd_visible
= (GetTimerMS() + 1000) | 1;
1389 vo_osd_progbar_type
= type
;
1390 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1391 vo_osd_changed(OSDTYPE_PROGBAR
);
1395 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1396 name
,ROUND(100*(val
-min
)/(max
-min
)));
1401 * \brief Update the OSD message line.
1403 * This function displays the current message on the vo OSD or on the term.
1404 * If the stack is empty and the OSD level is high enough the timer
1405 * is displayed (only on the vo OSD).
1409 static void update_osd_msg(void) {
1411 static char osd_text
[64] = "";
1412 static char osd_text_timer
[64];
1414 // we need some mem for vo_osd_text
1415 vo_osd_text
= (unsigned char*)osd_text
;
1417 // Look if we have a msg
1418 if((msg
= get_osd_msg())) {
1419 if(strcmp(osd_text
,msg
->msg
)) {
1420 strncpy((char*)osd_text
, msg
->msg
, 63);
1421 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1422 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1427 if(mpctx
->sh_video
) {
1428 // fallback on the timer
1430 int len
= demuxer_get_time_length(mpctx
->demuxer
);
1431 int percentage
= -1;
1432 char percentage_text
[10];
1433 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1435 if (mpctx
->osd_show_percentage
)
1436 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1438 if (percentage
>= 0)
1439 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1441 percentage_text
[0] = 0;
1444 snprintf(osd_text_timer
, 63,
1445 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1446 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1447 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1449 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1450 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1451 pts
%60,percentage_text
);
1453 osd_text_timer
[0]=0;
1455 // always decrement the percentage timer
1456 if(mpctx
->osd_show_percentage
)
1457 mpctx
->osd_show_percentage
--;
1459 if(strcmp(osd_text
,osd_text_timer
)) {
1460 strncpy(osd_text
, osd_text_timer
, 63);
1461 vo_osd_changed(OSDTYPE_OSD
);
1466 // Clear the term osd line
1467 if(term_osd
&& osd_text
[0]) {
1469 printf("%s\n",term_osd_esc
);
1477 void reinit_audio_chain(void) {
1478 if(mpctx
->sh_audio
){
1479 current_module
="init_audio_codec";
1480 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1481 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1482 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // failed to init :(
1483 mpctx
->d_audio
->id
= -2;
1486 inited_flags
|=INITED_ACODEC
;
1487 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1490 //const ao_info_t *info=audio_out->info;
1491 current_module
="af_preinit";
1492 ao_data
.samplerate
=force_srate
;
1494 ao_data
.format
=audio_output_format
;
1496 // first init to detect best values
1497 if(!preinit_audio_filters(mpctx
->sh_audio
,
1499 (int)(mpctx
->sh_audio
->samplerate
*playback_speed
),
1500 mpctx
->sh_audio
->channels
, mpctx
->sh_audio
->sample_format
,
1502 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1503 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
1504 exit_player(MSGTR_Exit_error
);
1507 current_module
="ao2_init";
1508 if(!(mpctx
->audio_out
=init_best_audio_out(audio_driver_list
,
1512 ao_data
.format
,0))){
1514 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1515 uninit_player(INITED_ACODEC
); // close codec
1516 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1517 mpctx
->d_audio
->id
= -2;
1521 inited_flags
|=INITED_AO
;
1522 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1523 mpctx
->audio_out
->info
->short_name
,
1524 ao_data
.samplerate
, ao_data
.channels
,
1525 af_fmt2str_short(ao_data
.format
),
1526 af_fmt2bits(ao_data
.format
)/8 );
1527 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1528 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1529 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1530 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1531 // init audio filters:
1533 current_module
="af_init";
1534 if(!build_afilter_chain(mpctx
->sh_audio
, &ao_data
)) {
1535 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
1536 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1537 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1538 // sh_audio=mpctx->d_audio->sh=NULL; // -> nosound
1542 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1543 mpctx
->mixer
.volstep
= volstep
;
1552 // Return pts value corresponding to the end point of audio written to the
1554 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
1556 // first calculate the end pts of audio that has been output by decoder
1557 double a_pts
= sh_audio
->pts
;
1558 if (a_pts
!= MP_NOPTS_VALUE
)
1559 // Good, decoder supports new way of calculating audio pts.
1560 // sh_audio->pts is the timestamp of the latest input packet with
1561 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1562 // the amount of bytes the decoder has written after that timestamp.
1563 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1565 // Decoder doesn't support new way of calculating pts (or we're
1566 // being called before it has decoded anything with known timestamp).
1567 // Use the old method of audio pts calculation: take the timestamp
1568 // of last packet with known pts the decoder has read data from,
1569 // and add amount of bytes read after the beginning of that packet
1570 // divided by input bps. This will be inaccurate if the input/output
1571 // ratio is not constant for every audio packet or if it is constant
1572 // but not accurately known in sh_audio->i_bps.
1574 a_pts
= d_audio
->pts
;
1575 // ds_tell_pts returns bytes read after last timestamp from
1576 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1577 // it has read but not decoded
1578 if (sh_audio
->i_bps
)
1579 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1580 (double)sh_audio
->i_bps
;
1582 // Now a_pts hopefully holds the pts for end of audio from decoder.
1583 // Substract data in buffers between decoder and audio out.
1585 // Decoded but not filtered
1586 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1588 // Data that was ready for ao but was buffered because ao didn't fully
1589 // accept everything to internal buffers yet
1590 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
1595 // Return pts value corresponding to currently playing audio.
1596 double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
1597 ao_functions_t
*audio_out
)
1599 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
1600 audio_out
->get_delay();
1603 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
1605 unsigned char *start
;
1611 void *decoded_frame
;
1612 current_module
= "decode video";
1613 // XXX Time used in this call is not counted in any performance
1614 // timer now, OSD is not updated correctly for filter-added frames
1615 if (vf_output_queued_frame(sh_video
->vfilter
))
1617 current_module
= "video_read_frame";
1618 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
1620 // try to extract last frames in case of decoder lag
1625 if (in_size
> max_framesize
)
1626 max_framesize
= in_size
;
1627 current_module
= "decode video";
1628 decoded_frame
= decode_video(sh_video
, start
, in_size
, 0, pts
);
1629 if (decoded_frame
) {
1630 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
1631 update_teletext(sh_video
, mpctx
->demuxer
, 0);
1633 current_module
= "filter video";
1634 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
1647 static float timing_sleep(float time_frame
)
1651 // -------- RTC -----------
1652 current_module
="sleep_rtc";
1653 while (time_frame
> 0.000) {
1654 unsigned long rtc_ts
;
1655 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1656 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
1657 time_frame
-= GetRelativeTime();
1662 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1663 // unnecessarily high CPU usage
1664 float margin
= softsleep
? 0.011 : 0;
1665 current_module
= "sleep_timer";
1666 while (time_frame
> margin
) {
1667 usec_sleep(1000000 * (time_frame
- margin
));
1668 time_frame
-= GetRelativeTime();
1671 current_module
= "sleep_soft";
1673 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
1674 while (time_frame
> 0)
1675 time_frame
-=GetRelativeTime(); // burn the CPU
1681 static void adjust_sync_and_print_status(int between_frames
, float timing_error
)
1683 current_module
="av_sync";
1685 if(mpctx
->sh_audio
){
1686 double a_pts
, v_pts
;
1690 * If autosync is enabled, the value for delay must be calculated
1691 * a bit differently. It is set only to the difference between
1692 * the audio and video timers. Any attempt to include the real
1693 * or corrected delay causes the pts_correction code below to
1694 * try to correct for the changes in delay which autosync is
1695 * trying to measure. This keeps the two from competing, but still
1696 * allows the code to correct for PTS drift *only*. (Using a delay
1697 * value here, even a "corrected" one, would be incompatible with
1700 a_pts
= written_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
) - mpctx
->delay
;
1702 a_pts
= playing_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
, mpctx
->audio_out
);
1704 v_pts
= mpctx
->sh_video
->pts
;
1707 static int drop_message
=0;
1708 double AV_delay
= a_pts
- audio_delay
- v_pts
;
1710 if (AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
1712 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
1717 /* Do not correct target time for the next frame if this frame
1718 * was late not because of wrong target time but because the
1719 * target time could not be met */
1720 x
= (AV_delay
+ timing_error
* playback_speed
) * 0.1f
;
1721 if (x
< -max_pts_correction
)
1722 x
= -max_pts_correction
;
1723 else if (x
> max_pts_correction
)
1724 x
= max_pts_correction
;
1725 if (default_max_pts_correction
>= 0)
1726 max_pts_correction
= default_max_pts_correction
;
1728 max_pts_correction
= mpctx
->sh_video
->frametime
*0.10; // +-10% of time
1729 if (!between_frames
) {
1734 print_status(a_pts
- audio_delay
, AV_delay
, c_total
);
1741 print_status(0, 0, 0);
1745 static int fill_audio_out_buffers(void)
1753 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
1755 current_module
="play_audio";
1758 // all the current uses of ao_data.pts seem to be in aos that handle
1759 // sync completely wrong; there should be no need to use ao_data.pts
1761 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
1762 bytes_to_write
= mpctx
->audio_out
->get_space();
1763 if (mpctx
->sh_video
|| bytes_to_write
>= ao_data
.outburst
)
1766 // handle audio-only case:
1767 // this is where mplayer sleeps during audio-only playback
1768 // to avoid 100% CPU use
1769 usec_sleep(10000); // Wait a tick before retry
1772 while (bytes_to_write
) {
1773 playsize
= bytes_to_write
;
1774 if (playsize
> MAX_OUTBURST
)
1775 playsize
= MAX_OUTBURST
;
1776 bytes_to_write
-= playsize
;
1778 // Fill buffer if needed:
1779 current_module
="decode_audio";
1781 while (sh_audio
->a_out_buffer_len
< playsize
) {
1782 int buflen
= sh_audio
->a_out_buffer_len
;
1783 int ret
= decode_audio(sh_audio
, &sh_audio
->a_out_buffer
[buflen
],
1784 playsize
- buflen
, // min bytes
1785 sh_audio
->a_out_buffer_size
- buflen
// max
1787 if (ret
<= 0) { // EOF?
1788 if (mpctx
->d_audio
->eof
) {
1790 if (sh_audio
->a_out_buffer_len
== 0)
1795 sh_audio
->a_out_buffer_len
+= ret
;
1798 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
1799 if (playsize
> sh_audio
->a_out_buffer_len
) {
1800 playsize
= sh_audio
->a_out_buffer_len
;
1802 playflags
|= AOPLAY_FINAL_CHUNK
;
1808 current_module
="play_audio";
1810 // Is this pts value actually useful for the aos that access it?
1811 // They're obviously badly broken in the way they handle av sync;
1812 // would not having access to this make them more broken?
1813 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
1814 playsize
= mpctx
->audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
1817 sh_audio
->a_out_buffer_len
-= playsize
;
1818 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
1819 sh_audio
->a_out_buffer_len
);
1820 mpctx
->delay
+= playback_speed
*playsize
/(double)ao_data
.bps
;
1822 else if (audio_eof
&& mpctx
->audio_out
->get_delay() < .04) {
1823 // Sanity check to avoid hanging in case current ao doesn't output
1824 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
1825 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
1826 sh_audio
->a_out_buffer_len
= 0;
1832 static int sleep_until_update(float *time_frame
, float *aq_sleep_time
)
1834 int frame_time_remaining
= 0;
1835 current_module
="calc_sleep_time";
1837 *time_frame
-= GetRelativeTime(); // reset timer
1839 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1840 float delay
= mpctx
->audio_out
->get_delay();
1841 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
1845 * Adjust this raw delay value by calculating the expected
1846 * delay for this frame and generating a new value which is
1847 * weighted between the two. The higher autosync is, the
1848 * closer to the delay value gets to that which "-nosound"
1849 * would have used, and the longer it will take for A/V
1850 * sync to settle at the right value (but it eventually will.)
1851 * This settling time is very short for values below 100.
1853 float predicted
= mpctx
->delay
/ playback_speed
+ *time_frame
;
1854 float difference
= delay
- predicted
;
1855 delay
= predicted
+ difference
/ (float)autosync
;
1858 *time_frame
= delay
- mpctx
->delay
/ playback_speed
;
1860 // delay = amount of audio buffered in soundcard/driver
1861 if (delay
> 0.25) delay
=0.25; else
1862 if (delay
< 0.10) delay
=0.10;
1863 if (*time_frame
> delay
*0.6) {
1864 // sleep time too big - may cause audio drops (buffer underrun)
1865 frame_time_remaining
= 1;
1866 *time_frame
= delay
*0.5;
1869 // If we're lagging more than 200 ms behind the right playback rate,
1870 // don't try to "catch up".
1871 // If benchmark is set always output frames as fast as possible
1872 // without sleeping.
1873 if (*time_frame
< -0.2 || benchmark
)
1877 *aq_sleep_time
+= *time_frame
;
1880 //============================== SLEEP: ===================================
1882 // flag 256 means: libvo driver does its timing (dvb card)
1883 if (*time_frame
> 0.001 && !(vo_flags
&256))
1884 *time_frame
= timing_sleep(*time_frame
);
1885 return frame_time_remaining
;
1888 int reinit_video_chain(void) {
1889 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1891 //================== Init VIDEO (codec & libvo) ==========================
1892 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
1893 current_module
="preinit_libvo";
1895 //shouldn't we set dvideo->id=-2 when we fail?
1897 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
1898 if(!(mpctx
->video_out
=init_best_video_out(video_driver_list
))){
1899 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
1902 sh_video
->video_out
=mpctx
->video_out
;
1903 inited_flags
|=INITED_VO
;
1906 if(stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_ASPECT_RATIO
, &ar
) != STREAM_UNSUPPORTED
)
1907 mpctx
->sh_video
->stream_aspect
= ar
;
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);
2039 update_teletext(sh_video
, mpctx
->demuxer
, 0);
2041 current_module
= "decode_video";
2042 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
2044 current_module
= "filter_video";
2045 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
2049 if (!generate_video_frame(sh_video
, mpctx
->d_video
))
2051 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
,
2052 VFCTRL_GET_PTS
, &sh_video
->pts
);
2053 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
2054 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
2055 sh_video
->pts
= sh_video
->last_pts
;
2057 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2058 sh_video
->last_pts
= sh_video
->pts
;
2059 else if (sh_video
->last_pts
>= sh_video
->pts
) {
2060 sh_video
->last_pts
= sh_video
->pts
;
2061 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "pts value <= previous\n");
2063 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2064 sh_video
->last_pts
= sh_video
->pts
;
2065 sh_video
->timer
+= frame_time
;
2067 mpctx
->delay
-= frame_time
;
2073 void pause_loop(void)
2077 // Small hack to display the pause message on the OSD line.
2078 // The pause string is: "\n == PAUSE == \r" so we need to
2079 // take the first and the last char out
2080 if (term_osd
&& !mpctx
->sh_video
) {
2081 char msg
[128] = MSGTR_Paused
;
2082 int mlen
= strlen(msg
);
2084 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2087 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2088 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2092 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
2094 if (mpctx
->video_out
&& mpctx
->sh_video
&& vo_config_count
)
2095 mpctx
->video_out
->control(VOCTRL_PAUSE
, NULL
);
2097 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2098 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2100 while ( (cmd
= mp_input_get_cmd(20, 1, 1)) == NULL
) {
2101 if (mpctx
->sh_video
&& mpctx
->video_out
&& vo_config_count
)
2102 mpctx
->video_out
->check_events();
2106 guiGetEvent(guiReDraw
, NULL
);
2107 if (guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
))
2113 vf_menu_pause_update(vf_menu
);
2117 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
2118 cmd
= mp_input_get_cmd(0,1,0);
2121 mpctx
->osd_function
=OSD_PLAY
;
2122 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2123 mpctx
->audio_out
->resume(); // resume audio
2124 if (mpctx
->video_out
&& mpctx
->sh_video
&& vo_config_count
)
2125 mpctx
->video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
2126 (void)GetRelativeTime(); // ignore time that passed during pause
2129 if (guiIntfStruct
.Playing
== guiSetStop
)
2132 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
2137 void print_version(void){
2138 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s\n", MP_TITLE
);
2140 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2141 GetCpuCaps(&gCpuCaps
);
2143 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2144 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
2145 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
2146 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
2147 #ifdef RUNTIME_CPUDETECT
2148 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
2150 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
2152 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
2155 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
2158 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
2161 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
2164 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
2167 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
2169 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
2170 #endif /* RUNTIME_CPUDETECT */
2171 #endif /* ARCH_X86 */
2175 // Find the right mute status and record position for new file position
2176 static void edl_seek_reset(MPContext
*mpctx
)
2178 mpctx
->edl_muted
= 0;
2179 next_edl_record
= edl_records
;
2181 while (next_edl_record
) {
2182 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2185 if (next_edl_record
->action
== EDL_MUTE
)
2186 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2187 next_edl_record
= next_edl_record
->next
;
2189 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2190 mixer_mute(&mpctx
->mixer
);
2194 // Execute EDL command for the current position if one exists
2195 static void edl_update(MPContext
*mpctx
)
2197 if (!next_edl_record
)
2200 if (!mpctx
->sh_video
) {
2201 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
2202 free_edl(edl_records
);
2203 next_edl_record
= NULL
;
2208 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2209 if (next_edl_record
->action
== EDL_SKIP
) {
2210 mpctx
->osd_function
= OSD_FFW
;
2212 rel_seek_secs
= next_edl_record
->length_sec
;
2213 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2214 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2215 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2218 else if (next_edl_record
->action
== EDL_MUTE
) {
2219 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2220 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2221 mixer_mute(&mpctx
->mixer
);
2222 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2223 next_edl_record
->start_sec
);
2225 next_edl_record
= next_edl_record
->next
;
2230 // style & 1 == 0 means seek relative to current position, == 1 means absolute
2231 // style & 2 == 0 means amount in seconds, == 2 means fraction of file length
2232 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2233 static int seek(MPContext
*mpctx
, double amount
, int style
)
2235 current_module
= "seek";
2236 if (demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
) == 0)
2239 if (mpctx
->sh_video
) {
2240 current_module
= "seek_video_reset";
2241 resync_video_stream(mpctx
->sh_video
);
2242 if (vo_config_count
)
2243 mpctx
->video_out
->control(VOCTRL_RESET
, NULL
);
2244 mpctx
->sh_video
->num_buffered_pts
= 0;
2245 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2246 mpctx
->num_buffered_frames
= 0;
2248 // Not all demuxers set d_video->pts during seek, so this value
2249 // (which is used by at least vobsub and edl code below) may
2250 // be completely wrong (probably 0).
2251 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
;
2252 update_subtitles(mpctx
->sh_video
, mpctx
->d_sub
, 1);
2253 update_teletext(mpctx
->sh_video
, mpctx
->demuxer
, 1);
2256 if (mpctx
->sh_audio
) {
2257 current_module
= "seek_audio_reset";
2258 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2259 mpctx
->sh_audio
->a_buffer_len
= 0;
2260 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2264 current_module
= "seek_vobsub_reset";
2265 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2268 edl_seek_reset(mpctx
);
2271 max_pts_correction
= 0.1;
2272 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2275 current_module
= NULL
;
2279 int main(int argc
,char* argv
[]){
2286 /* Flag indicating whether MPlayer should exit without playing anything. */
2289 //float a_frame=0; // Audio
2293 int gui_no_filename
=0;
2295 srand((int) time(NULL
));
2301 for(i
=1; i
<argc
; i
++)
2302 if(!strcmp(argv
[i
], "-really-quiet"))
2306 #if defined(WIN32) && defined(USE_WIN32DLL)
2308 #endif /*WIN32 && USE_WIN32DLL*/
2311 stream_tv_defaults
.immediate
= 1;
2314 if (argc
> 1 && argv
[1] &&
2315 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
2316 use_gui
= !strcmp(argv
[1], "-gui");
2320 char *base
= strrchr(argv
[0], '/');
2322 base
= strrchr(argv
[0], '\\');
2325 if(strstr(base
, "gmplayer"))
2329 mconfig
= m_config_new();
2330 m_config_register_options(mconfig
,mplayer_opts
);
2331 // TODO : add something to let modules register their options
2332 mp_input_register_options(mconfig
);
2333 parse_cfgfiles(mconfig
);
2336 if ( use_gui
) cfg_read();
2339 mpctx
->playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
2340 if(mpctx
->playtree
== NULL
)
2343 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
2344 if(mpctx
->playtree
) {
2345 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
2346 if(mpctx
->playtree_iter
) {
2347 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2348 play_tree_iter_free(mpctx
->playtree_iter
);
2349 mpctx
->playtree_iter
= NULL
;
2351 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2356 #if defined(WIN32) && defined(HAVE_NEW_GUI)
2357 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
2358 if(runningmplayer
&& filename
&& use_gui
){
2359 COPYDATASTRUCT csData
;
2360 char file
[MAX_PATH
];
2361 char *filepart
= filename
;
2362 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
2364 csData
.cbData
= strlen(file
)*2;
2365 csData
.lpData
= file
;
2366 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
2374 for(i
=0; priority_presets_defs
[i
].name
; i
++){
2375 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
2378 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
2379 priority_presets_defs
[i
].name
);
2380 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
2383 #ifndef HAVE_NEW_GUI
2385 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
2390 if(use_gui
&& !vo_init()){
2391 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
2395 if (use_gui
&& mpctx
->playtree_iter
){
2396 char cwd
[PATH_MAX
+2];
2397 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2398 play_tree_iter_free(mpctx
->playtree_iter
);
2399 mpctx
->playtree_iter
=NULL
;
2401 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
2404 // Prefix relative paths with current working directory
2405 play_tree_add_bpf(mpctx
->playtree
, cwd
);
2407 // Import initital playtree into GUI.
2408 import_initial_playtree_into_gui(mpctx
->playtree
, mconfig
, enqueue
);
2410 #endif /* HAVE_NEW_GUI */
2412 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
2417 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
2422 /* Check codecs.conf. */
2423 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2424 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2425 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2426 if(!parse_codec_cfg(NULL
)){
2427 exit_player_with_rc(NULL
, 0);
2429 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
2432 free( mem_ptr
); // release the buffer created by get_path()
2436 if(video_codec_list
){
2438 video_codec
=video_codec_list
[0];
2439 for(i
=0;video_codec_list
[i
];i
++)
2440 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2443 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2444 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
2445 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2447 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2450 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2451 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
2452 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2454 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2457 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2459 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2462 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
2464 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2467 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
2473 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
2475 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2479 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
2480 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
2481 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
2483 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2486 if(list_properties
) {
2487 property_print_help();
2494 if (player_idle_mode
&& use_gui
) {
2495 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
2496 exit_player_with_rc(NULL
, 1);
2499 if(!filename
&& !player_idle_mode
){
2501 // no file/vcd/dvd -> show HELP:
2502 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
2503 exit_player_with_rc(NULL
, 0);
2504 } else gui_no_filename
=1;
2507 /* Display what configure line was used */
2508 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
2510 // Many users forget to include command line in bugreports...
2511 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
2512 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
2513 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
2514 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2517 //------ load global data first ------
2520 #ifdef HAVE_FREETYPE
2523 #ifdef HAVE_FONTCONFIG
2524 if(!font_fontconfig
)
2527 #ifdef HAVE_BITMAP_FONT
2529 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
2530 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,
2531 filename_recode(font_name
));
2534 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
2535 free(mem_ptr
); // release the buffer created by get_path()
2537 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
2540 sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
2544 #ifdef HAVE_FONTCONFIG
2551 ass_library
= ass_init();
2557 // seteuid(0); /* Can't hurt to try to get root here */
2558 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
2559 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
2560 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
2562 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
2564 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
2565 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
2566 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
2569 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
2570 /* variable only by the root */
2571 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
2575 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
2579 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2580 // and now ? -- Pontscho
2581 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
2584 #endif /* HAVE_RTC */
2585 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
2586 softsleep
?"software":timer_name
);
2589 if ( !use_gui
) load_termcap(NULL
); // load key-codes
2592 // ========== Init keyboard FIFO (connection to libvo) ============
2594 // Init input system
2595 current_module
= "init_input";
2596 mp_input_init(use_gui
);
2597 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
2600 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
2602 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
2604 else if(!noconsolecontrols
)
2605 mp_input_add_event_fd(0, getch2
);
2607 inited_flags
|=INITED_INPUT
;
2608 current_module
= NULL
;
2612 if(menu_cfg
&& menu_init(mpctx
, menu_cfg
))
2613 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2615 menu_cfg
= get_path("menu.conf");
2616 if(menu_init(mpctx
, menu_cfg
))
2617 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2619 if(menu_init(mpctx
, MPLAYER_CONFDIR
"/menu.conf"))
2620 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
2622 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
2632 signal(SIGCHLD
,child_sighandler
);
2636 prog_path
= argv
[0];
2638 //========= Catch terminate signals: ================
2639 // terminate requests:
2640 signal(SIGTERM
,exit_sighandler
); // kill
2641 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
2643 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
2645 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
2646 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
2647 #ifdef ENABLE_SIGHANDLER
2649 signal(SIGBUS
,exit_sighandler
); // bus error
2650 signal(SIGSEGV
,exit_sighandler
); // segfault
2651 signal(SIGILL
,exit_sighandler
); // illegal instruction
2652 signal(SIGFPE
,exit_sighandler
); // floating point exc.
2653 signal(SIGABRT
,exit_sighandler
); // abort()
2656 signal(SIGTRAP
,exit_sighandler
);
2663 guiGetEvent(guiSetContext
, mpctx
);
2664 inited_flags
|=INITED_GUI
;
2665 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
2669 // ******************* Now, let's see the per-file stuff ********************
2673 // init global sub numbers
2674 mpctx
->global_sub_size
= 0;
2675 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) mpctx
->global_sub_indices
[i
] = -1; }
2677 if (filename
) load_per_file_config (mconfig
, filename
);
2679 // We must enable getch2 here to be able to interrupt network connection
2681 if(!noconsolecontrols
&& !slave_mode
){
2682 if(inited_flags
&INITED_GETCH2
)
2683 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
2685 getch2_enable(); // prepare stdin for hotkeys...
2686 inited_flags
|=INITED_GETCH2
;
2687 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
2690 // =================== GUI idle loop (STOP state) ===========================
2693 mpctx
->file_format
=DEMUXER_TYPE_UNKNOWN
;
2694 guiGetEvent( guiSetDefaults
,0 );
2695 while ( guiIntfStruct
.Playing
!= 1 )
2700 guiGetEvent( guiReDraw
,NULL
);
2701 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
2703 guiGetEvent( guiSetParameters
,NULL
);
2704 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
2706 play_tree_t
* entry
= play_tree_new();
2707 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
2708 if ( mpctx
->playtree
) play_tree_free_list( mpctx
->playtree
->child
,1 );
2709 else mpctx
->playtree
=play_tree_new();
2710 play_tree_set_child( mpctx
->playtree
,entry
);
2713 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
2714 if(mpctx
->playtree_iter
)
2716 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
2718 play_tree_iter_free(mpctx
->playtree_iter
);
2719 mpctx
->playtree_iter
= NULL
;
2721 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2726 #endif /* HAVE_NEW_GUI */
2728 while (player_idle_mode
&& !filename
) {
2729 play_tree_t
* entry
= NULL
;
2731 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
2732 if (mpctx
->video_out
&& vo_config_count
) mpctx
->video_out
->check_events();
2736 case MP_CMD_LOADFILE
:
2737 // prepare a tree entry with the new filename
2738 entry
= play_tree_new();
2739 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
2740 // The entry is added to the main playtree after the switch().
2742 case MP_CMD_LOADLIST
:
2743 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
2746 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
2752 if (entry
) { // user entered a command that gave a valid entry
2753 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
2754 play_tree_free_list(mpctx
->playtree
->child
, 1);
2755 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
2757 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
2759 play_tree_set_child(mpctx
->playtree
, entry
);
2761 /* Make iterator start at the top the of tree. */
2762 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mconfig
);
2763 if (!mpctx
->playtree_iter
) continue;
2765 // find the first real item in the tree
2766 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2768 play_tree_iter_free(mpctx
->playtree_iter
);
2769 mpctx
->playtree_iter
= NULL
;
2770 continue; // wait for next command
2772 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
2775 //---------------------------------------------------------------------------
2778 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
,
2779 filename_recode(filename
));
2782 if (edl_records
) free_edl(edl_records
);
2783 next_edl_record
= edl_records
= edl_parse_file();
2785 if (edl_output_filename
) {
2786 if (edl_fd
) fclose(edl_fd
);
2787 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
2789 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
2790 filename_recode(edl_output_filename
));
2794 //==================== Open VOB-Sub ============================
2796 current_module
="vobsub";
2798 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
2800 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,
2801 filename_recode(vobsub_name
));
2802 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
2803 /* try to autodetect vobsub from movie filename ::atmos */
2804 char *buf
= malloc((strlen(filename
)-3)),*psub
;
2805 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
2806 strncpy(buf
, filename
, strlen(filename
)-4);
2807 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
2808 /* try from ~/.mplayer/sub */
2809 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
2812 bname
= strrchr(buf
,'/');
2814 if(!bname
) bname
= strrchr(buf
,'\\');
2818 l
= strlen(psub
) + strlen(bname
) + 1;
2819 psub
= realloc(psub
,l
);
2821 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
2827 inited_flags
|=INITED_VOBSUB
;
2828 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
2829 // check if vobsub requested only to display forced subtitles
2830 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
2832 // setup global sub numbering
2833 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] = mpctx
->global_sub_size
; // the global # of the first vobsub.
2834 mpctx
->global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
2837 //============ Open & Sync STREAM --- fork cache2 ====================
2840 mpctx
->demuxer
=NULL
;
2841 if (mpctx
->d_audio
) {
2842 //free_demuxer_stream(mpctx->d_audio);
2843 mpctx
->d_audio
=NULL
;
2845 if (mpctx
->d_video
) {
2846 //free_demuxer_stream(d_video);
2847 mpctx
->d_video
=NULL
;
2849 mpctx
->sh_audio
=NULL
;
2850 mpctx
->sh_video
=NULL
;
2852 current_module
="open_stream";
2853 mpctx
->stream
=open_stream(filename
,0,&mpctx
->file_format
);
2854 if(!mpctx
->stream
) { // error...
2855 mpctx
->eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
2856 goto goto_next_file
;
2858 inited_flags
|=INITED_STREAM
;
2861 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)mpctx
->stream
);
2864 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
2867 current_module
="handle_playlist";
2868 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
2869 filename_recode(filename
));
2870 entry
= parse_playtree(mpctx
->stream
,0);
2871 mpctx
->eof
=playtree_add_playlist(entry
);
2872 goto goto_next_file
;
2874 mpctx
->stream
->start_pos
+=seek_to_byte
;
2876 if(stream_dump_type
==5){
2877 unsigned char buf
[4096];
2880 current_module
="dumpstream";
2881 if(mpctx
->stream
->type
==STREAMTYPE_STREAM
&& mpctx
->stream
->fd
<0){
2882 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
2883 exit_player(MSGTR_Exit_error
);
2885 stream_reset(mpctx
->stream
);
2886 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
2887 f
=fopen(stream_dump_name
,"wb");
2889 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
2890 exit_player(MSGTR_Exit_error
);
2892 while(!mpctx
->stream
->eof
){
2893 len
=stream_read(mpctx
->stream
,buf
,4096);
2895 if(fwrite(buf
,len
,1,f
) != 1) {
2896 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2897 exit_player(MSGTR_Exit_error
);
2902 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2903 exit_player(MSGTR_Exit_error
);
2905 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
2906 exit_player_with_rc(MSGTR_Exit_eof
, 0);
2910 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
2911 current_module
="dvd lang->id";
2912 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(mpctx
->stream
,audio_lang
);
2913 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
2914 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
2915 // setup global sub numbering
2916 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
2917 mpctx
->global_sub_size
+= dvd_number_of_subs(mpctx
->stream
);
2918 current_module
=NULL
;
2923 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
2924 current_module
="dvdnav lang->id";
2925 if(audio_id
==-1) audio_id
=dvdnav_aid_from_lang(mpctx
->stream
,audio_lang
);
2926 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
2927 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvdnav_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
2928 // setup global sub numbering
2929 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
2930 mpctx
->global_sub_size
+= dvdnav_number_of_subs(mpctx
->stream
);
2931 current_module
=NULL
;
2935 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
2937 if(stream_cache_size
>0){
2938 current_module
="enable_cache";
2939 if(!stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
2940 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
2941 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
2942 if((mpctx
->eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
2945 //============ Open DEMUXERS --- DETECT file type =======================
2946 current_module
="demux_open";
2948 mpctx
->demuxer
=demux_open(mpctx
->stream
,mpctx
->file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
2950 // HACK to get MOV Reference Files working
2952 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
2954 unsigned char* playlist_entry
;
2955 play_tree_t
*list
= NULL
, *entry
= NULL
;
2957 current_module
="handle_demux_playlist";
2958 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
2962 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
2963 filename_recode(playlist_entry
));
2965 bname
=mp_basename(playlist_entry
);
2966 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
2969 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
2972 entry
= play_tree_new();
2974 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
2976 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
2979 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
2980 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
2981 strcat(temp
, playlist_entry
);
2982 play_tree_add_file(entry
,temp
);
2983 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
2988 play_tree_add_file(entry
,playlist_entry
);
2993 play_tree_append_entry(list
,entry
);
2995 free_demuxer(mpctx
->demuxer
);
2996 mpctx
->demuxer
= NULL
;
3000 entry
= play_tree_new();
3001 play_tree_set_child(entry
,list
);
3002 mpctx
->eof
=playtree_add_playlist(entry
);
3003 goto goto_next_file
;
3008 goto goto_next_file
;
3009 inited_flags
|=INITED_DEMUXER
;
3011 if (mpctx
->stream
->type
!= STREAMTYPE_DVD
&& mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
) {
3014 // setup global sub numbering
3015 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3016 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
3017 if (mpctx
->demuxer
->s_streams
[i
])
3018 maxid
= FFMAX(maxid
, ((sh_sub_t
*)mpctx
->demuxer
->s_streams
[i
])->sid
);
3019 mpctx
->global_sub_size
+= maxid
+ 1;
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 mp_input_set_section(NULL
);
3324 //TODO: add desired (stream-based) sections here
3325 if (mpctx
->stream
->type
==STREAMTYPE_TV
) mp_input_set_section("tv");
3327 //==================== START PLAYING =======================
3329 if(mpctx
->loop_times
>1) mpctx
->loop_times
--; else
3330 if(mpctx
->loop_times
==1) mpctx
->loop_times
= -1;
3332 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);
3334 total_time_usage_start
=GetTimer();
3335 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3336 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3337 play_n_frames
=play_n_frames_mf
;
3339 if(play_n_frames
==0){
3340 mpctx
->eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
3344 seek(mpctx
, seek_to_sec
, 1);
3345 end_at
.pos
+= seek_to_sec
;
3348 if (end_at
.type
== END_AT_SIZE
) {
3349 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
3350 end_at
.type
= END_AT_NONE
;
3355 float aq_sleep_time
=0;
3356 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
3357 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
3358 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
3359 reinit_audio_chain();
3362 /*========================== PLAY AUDIO ============================*/
3364 if (mpctx
->sh_audio
)
3365 if (!fill_audio_out_buffers())
3366 // at eof, all audio at least written to ao
3367 if (!mpctx
->sh_video
)
3368 mpctx
->eof
= PT_NEXT_ENTRY
;
3371 if(!mpctx
->sh_video
) {
3372 // handle audio-only case:
3374 if(!quiet
|| end_at
.type
== END_AT_TIME
)
3375 a_pos
= playing_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
, mpctx
->audio_out
);
3378 print_status(a_pos
, 0, 0);
3380 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
3381 mpctx
->eof
= PT_NEXT_ENTRY
;
3386 /*========================== PLAY VIDEO ============================*/
3388 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
3389 vo_fps
=mpctx
->sh_video
->fps
;
3391 if (!mpctx
->num_buffered_frames
) {
3392 double frame_time
= update_video(&blit_frame
);
3393 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3394 if (mpctx
->sh_video
->vf_inited
< 0) {
3395 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
3396 mpctx
->eof
= 1; goto goto_next_file
;
3401 // might return with !eof && !blit_frame if !correct_pts
3402 mpctx
->num_buffered_frames
+= blit_frame
;
3403 time_frame
+= frame_time
/ playback_speed
; // for nosound
3407 // ==========================================================================
3409 // current_module="draw_osd";
3410 // if(vo_config_count) mpctx->video_out->draw_osd();
3413 if(use_gui
) guiEventHandling();
3416 current_module
="vo_check_events";
3417 if (vo_config_count
) mpctx
->video_out
->check_events();
3420 if (stop_xscreensaver
) {
3421 current_module
= "stop_xscreensaver";
3422 xscreensaver_heartbeat();
3426 frame_time_remaining
= sleep_until_update(&time_frame
, &aq_sleep_time
);
3428 //====================== FLIP PAGE (VIDEO BLT): =========================
3430 current_module
="flip_page";
3431 if (!frame_time_remaining
&& blit_frame
) {
3432 unsigned int t2
=GetTimer();
3434 if(vo_config_count
) mpctx
->video_out
->flip_page();
3435 mpctx
->num_buffered_frames
--;
3437 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
3439 //====================== A-V TIMESTAMP CORRECTION: =========================
3441 adjust_sync_and_print_status(frame_time_remaining
, time_frame
);
3443 //============================ Auto QUALITY ============================
3445 /*Output quality adjustments:*/
3447 current_module
="autoq";
3448 // float total=0.000001f * (GetTimer()-aq_total_time);
3449 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
3450 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
3453 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
3454 if(output_quality
>1 && aq_sleep_time
<0)
3457 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
3459 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
3460 set_video_quality(mpctx
->sh_video
,output_quality
);
3463 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
3465 if (play_n_frames
<= 0) mpctx
->eof
= PT_NEXT_ENTRY
;
3469 // FIXME: add size based support for -endpos
3470 if (end_at
.type
== END_AT_TIME
&&
3471 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
3472 mpctx
->eof
= PT_NEXT_ENTRY
;
3474 } // end if(mpctx->sh_video)
3477 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3479 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
3480 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
3481 vo_osd_changed (OSDTYPE_DVDNAV
);
3485 //============================ Handle PAUSE ===============================
3487 current_module
="pause";
3489 if (mpctx
->osd_function
== OSD_PAUSE
) {
3491 mpctx
->was_paused
= 1;
3496 mpctx
->osd_function
=OSD_FFW
;
3497 rel_seek_secs
+=step_sec
;
3502 //================= Keyboard events, SEEKing ====================
3504 current_module
="key_events";
3509 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
3510 brk_cmd
= run_command(mpctx
, cmd
);
3513 goto goto_enable_cache
;
3516 mpctx
->was_paused
= 0;
3519 if(mpctx
->eof
==1 && mpctx
->loop_times
>=0) {
3520 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", mpctx
->loop_times
,mpctx
->eof
);
3522 if(mpctx
->loop_times
>1) mpctx
->loop_times
--; else
3523 if(mpctx
->loop_times
==1) mpctx
->loop_times
=-1;
3524 play_n_frames
=play_n_frames_mf
;
3526 abs_seek_pos
=1; rel_seek_secs
=seek_to_sec
;
3530 if(rel_seek_secs
|| abs_seek_pos
){
3531 if (seek(mpctx
, rel_seek_secs
, abs_seek_pos
) >= 0) {
3535 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(mpctx
->demuxer
));
3548 if(mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
&& mpctx
->sh_video
&& mpctx
->sh_video
->video
.dwLength
>2){
3549 // get pos from frame number / total frames
3550 guiIntfStruct
.Position
=(float)mpctx
->d_video
->pack_no
*100.0f
/mpctx
->sh_video
->video
.dwLength
;
3552 guiIntfStruct
.Position
=demuxer_get_percent_pos(mpctx
->demuxer
);
3554 if ( mpctx
->sh_video
) guiIntfStruct
.TimeSec
=mpctx
->sh_video
->pts
;
3555 else if ( mpctx
->sh_audio
) guiIntfStruct
.TimeSec
=playing_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
, mpctx
->audio_out
);
3556 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(mpctx
->demuxer
);
3557 guiGetEvent( guiReDraw
,NULL
);
3558 guiGetEvent( guiSetVolume
,NULL
);
3559 if(guiIntfStruct
.Playing
==0) break; // STOP
3560 if(guiIntfStruct
.Playing
==2) mpctx
->osd_function
=OSD_PAUSE
;
3561 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3563 if ( mpctx
->stream
->type
== STREAMTYPE_DVD
)
3565 dvd_priv_t
* dvdp
= mpctx
->stream
->priv
;
3566 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3570 #endif /* HAVE_NEW_GUI */
3572 } // while(!mpctx->eof)
3574 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->eof
);
3576 #ifdef HAS_DVBIN_SUPPORT
3577 if(mpctx
->dvbin_reopen
)
3580 uninit_player(INITED_ALL
-(INITED_GUI
|INITED_STREAM
|INITED_INPUT
|INITED_GETCH2
|(fixed_vo
?INITED_VO
:0)));
3581 cache_uninit(mpctx
->stream
);
3582 mpctx
->dvbin_reopen
= 0;
3583 goto goto_enable_cache
;
3588 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3590 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3593 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3594 double total_time_usage
;
3595 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3596 total_time_usage
= (float)total_time_usage_start
*0.000001;
3597 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3598 video_time_usage
,vout_time_usage
,audio_time_usage
,
3599 total_time_usage
-tot
,total_time_usage
);
3600 if(total_time_usage
>0.0)
3601 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3602 100.0*video_time_usage
/total_time_usage
,
3603 100.0*vout_time_usage
/total_time_usage
,
3604 100.0*audio_time_usage
/total_time_usage
,
3605 100.0*(total_time_usage
-tot
)/total_time_usage
,
3607 if(total_frame_cnt
&& frame_dropping
)
3608 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3609 total_frame_cnt
-drop_frame_cnt
,
3610 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3612 100*drop_frame_cnt
/total_frame_cnt
,
3614 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
3618 // time to uninit all, except global stuff:
3619 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
3621 if ( mpctx
->set_of_sub_size
> 0 )
3623 current_module
="sub_free";
3624 for (i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
3625 sub_free( mpctx
->set_of_subtitles
[i
] );
3627 if ( mpctx
->set_of_ass_tracks
[i
] )
3628 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
3631 mpctx
->set_of_sub_size
= 0;
3633 vo_sub_last
= vo_sub
=NULL
;
3639 if(mpctx
->eof
== PT_NEXT_ENTRY
|| mpctx
->eof
== PT_PREV_ENTRY
) {
3640 mpctx
->eof
= mpctx
->eof
== PT_NEXT_ENTRY
? 1 : -1;
3641 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
3644 play_tree_iter_free(mpctx
->playtree_iter
);
3645 mpctx
->playtree_iter
= NULL
;
3647 mpctx
->play_tree_step
= 1;
3648 } else if (mpctx
->eof
== PT_UP_NEXT
|| mpctx
->eof
== PT_UP_PREV
) {
3649 mpctx
->eof
= mpctx
->eof
== PT_UP_NEXT
? 1 : -1;
3650 if ( mpctx
->playtree_iter
) {
3651 if(play_tree_iter_up_step(mpctx
->playtree_iter
,mpctx
->eof
,0) == PLAY_TREE_ITER_ENTRY
) {
3654 play_tree_iter_free(mpctx
->playtree_iter
);
3655 mpctx
->playtree_iter
= NULL
;
3658 } else { // NEXT PREV SRC
3659 mpctx
->eof
= mpctx
->eof
== PT_PREV_SRC
? -1 : 1;
3662 if(mpctx
->eof
== 0) mpctx
->eof
= 1;
3664 while(mpctx
->playtree_iter
!= NULL
) {
3665 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,mpctx
->eof
);
3666 if(filename
== NULL
) {
3667 if( play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->eof
,0) != PLAY_TREE_ITER_ENTRY
) {
3668 play_tree_iter_free(mpctx
->playtree_iter
);
3669 mpctx
->playtree_iter
= NULL
;
3676 if( use_gui
&& !mpctx
->playtree_iter
)
3679 if ( !guiIntfStruct
.DiskChanged
)
3685 if(use_gui
|| mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
3686 if (!mpctx
->playtree_iter
) filename
= NULL
;
3688 goto play_next_file
;
3692 exit_player_with_rc(MSGTR_Exit_eof
, 0);