3 /// \ingroup Properties Command2Property OSDMsgStack
10 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
16 // #include <sys/mman.h>
17 #include <sys/types.h>
19 #include <sys/ioctl.h>
22 #define SIGHUP 1 /* hangup */
23 #define SIGQUIT 3 /* quit */
24 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
25 #define SIGBUS 10 /* bus error */
26 #define SIGPIPE 13 /* broken pipe */
27 extern int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
);
44 #define HELP_MP_DEFINE_STATIC
49 #include "m_property.h"
51 #include "cfg-mplayer-def.h"
53 #include "subreader.h"
55 #include "libvo/video_out.h"
57 #include "libvo/font_load.h"
58 #include "libvo/sub.h"
61 #include "libvo/x11_common.h"
64 #include "libao2/audio_out.h"
66 #include "codec-cfg.h"
73 #include "osdep/getch2.h"
74 #include "osdep/timer.h"
76 #include "cpudetect.h"
79 #include "Gui/interface.h"
82 #include "input/input.h"
85 int player_idle_mode
=0;
87 int enable_mouse_movements
=0;
90 char * proc_priority
=NULL
;
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
97 #include <linux/rtc.h>
100 #define RTC_IRQP_SET RTCIO_IRQP_SET
101 #define RTC_PIE_ON RTCIO_PIE_ON
102 #endif /* __linux__ */
103 #endif /* HAVE_RTC */
106 #include "stream/tv.h"
109 #include "stream/stream_radio.h"
112 #ifdef HAS_DVBIN_SUPPORT
113 #include "stream/dvbin.h"
114 #include "stream/cache2.h"
117 //**************************************************************************//
119 //**************************************************************************//
120 #include "playtree.h"
121 #include "playtreeparser.h"
124 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
125 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
128 //**************************************************************************//
130 //**************************************************************************//
131 #include "parser-cfg.h"
132 #include "parser-mpcmd.h"
136 //**************************************************************************//
138 //**************************************************************************//
140 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
142 static int cfg_include(m_option_t
*conf
, char *filename
){
143 return m_config_parse_config_file(mconfig
, filename
);
146 #include "get_path.c"
148 //**************************************************************************//
150 //**************************************************************************//
153 void xscreensaver_heartbeat(void);
156 //**************************************************************************//
157 //**************************************************************************//
158 // Input media streaming & demultiplexer:
159 //**************************************************************************//
161 static int max_framesize
=0;
163 #include "stream/stream.h"
164 #include "libmpdemux/demuxer.h"
165 #include "libmpdemux/stheader.h"
166 //#include "parse_es.h"
167 #include "libmpdemux/matroska.h"
170 #include "stream/stream_dvd.h"
174 #include "stream/stream_dvdnav.h"
177 #include "libmpcodecs/dec_audio.h"
178 #include "libmpcodecs/dec_video.h"
179 #include "libmpcodecs/mp_image.h"
180 #include "libmpcodecs/vf.h"
181 #include "libmpcodecs/vd.h"
187 //**************************************************************************//
188 //**************************************************************************//
190 // Common FIFO functions, and keyboard/event FIFO code
192 int noconsolecontrols
=0;
193 //**************************************************************************//
195 // Not all functions in mplayer.c take the context as an argument yet
196 static MPContext
*mpctx
= &(MPContext
){
197 .osd_function
= OSD_PLAY
,
198 .begin_skip
= MP_NOPTS_VALUE
,
200 .global_sub_pos
= -1,
201 .set_of_sub_pos
= -1,
202 .file_format
= DEMUXER_TYPE_UNKNOWN
,
203 #ifdef HAS_DVBIN_SUPPORT
211 double video_time_usage
=0;
212 double vout_time_usage
=0;
213 static double audio_time_usage
=0;
214 static int total_time_usage_start
=0;
215 static int total_frame_cnt
=0;
216 static int drop_frame_cnt
=0; // total number of dropped frames
221 static int output_quality
=0;
223 float playback_speed
=1.0;
231 static int list_properties
= 0;
234 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
235 unsigned int osd_visible
;
236 int osd_duration
= 1000;
239 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
240 static char* playing_msg
= NULL
;
242 static double seek_to_sec
;
243 static off_t seek_to_byte
=0;
244 static off_t step_sec
=0;
245 static int loop_times
=-1;
246 static int loop_seek
=0;
248 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
251 int autosync
=0; // 30 might be a good default value.
253 // may be changed by GUI: (FIXME!)
254 float rel_seek_secs
=0;
258 char **audio_codec_list
=NULL
; // override audio codec
259 char **video_codec_list
=NULL
; // override video codec
260 char **audio_fm_list
=NULL
; // override audio codec family
261 char **video_fm_list
=NULL
; // override video codec family
264 extern char *demuxer_name
; // override demuxer
265 extern char *audio_demuxer_name
; // override audio demuxer
266 extern char *sub_demuxer_name
; // override sub demuxer
273 char* audio_lang
=NULL
;
274 char* dvdsub_lang
=NULL
;
275 static char* spudec_ifo
=NULL
;
276 char* filename
=NULL
; //"MI2-Trailer.avi";
277 int forced_subs_only
=0;
281 int stream_cache_size
=-1;
282 #ifdef USE_STREAM_CACHE
283 extern int cache_fill_status
;
285 float stream_cache_min_percent
=20.0;
286 float stream_cache_seek_min_percent
=50.0;
288 #define cache_fill_status 0
292 static char *stream_dump_name
="stream.dump";
293 int stream_dump_type
=0;
296 static float default_max_pts_correction
=-1;//0.01f;
297 static float max_pts_correction
=0;//default_max_pts_correction;
298 static float c_total
=0;
300 static int ignore_start
=0;
302 static int softsleep
=0;
305 static int force_srate
=0;
306 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
307 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
308 static int play_n_frames
=-1;
309 static int play_n_frames_mf
=-1;
312 char** video_driver_list
=NULL
;
313 char** audio_driver_list
=NULL
;
315 extern char *vo_subdevice
;
316 extern char *ao_subdevice
;
318 // codec outfmt flags (defined in libmpcodecs/vd.c)
322 char *font_name
=NULL
;
323 #ifdef HAVE_FONTCONFIG
324 extern int font_fontconfig
;
326 float font_factor
=0.75;
327 char **sub_name
=NULL
;
331 char *vobsub_name
=NULL
;
332 /*DSP!!char *dsp=NULL;*/
334 int suboverlap_enabled
= 1;
337 #include "libass/ass.h"
338 #include "libass/ass_mp.h"
341 extern int mp_msg_levels
[MSGT_MAX
];
342 extern int mp_msg_level_all
;
344 char* current_module
=NULL
; // for debugging
350 #include "m_struct.h"
351 #include "libmenu/menu.h"
352 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
353 extern vf_info_t vf_info_menu
;
354 static vf_info_t
* libmenu_vfs
[] = {
358 static vf_instance_t
* vf_menu
= NULL
;
359 static int use_menu
= 0;
360 static char* menu_cfg
= NULL
;
361 static char* menu_root
= "main";
366 static int nortc
= 1;
367 static char* rtc_device
;
370 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
371 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
372 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
373 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
374 int use_filedir_conf
;
376 static unsigned int inited_flags
=0;
377 #include "mpcommon.h"
380 #include "metadata.h"
382 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
384 void *mpctx_get_video_out(MPContext
*mpctx
)
386 return mpctx
->video_out
;
389 void *mpctx_get_audio_out(MPContext
*mpctx
)
391 return mpctx
->audio_out
;
394 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
396 return mpctx
->playtree_iter
;
399 void *mpctx_get_mixer(MPContext
*mpctx
)
401 return &mpctx
->mixer
;
404 int mpctx_get_global_sub_size(MPContext
*mpctx
)
406 return mpctx
->global_sub_size
;
409 static int is_valid_metadata_type (metadata_t type
) {
412 /* check for valid video stream */
413 case META_VIDEO_CODEC
:
414 case META_VIDEO_BITRATE
:
415 case META_VIDEO_RESOLUTION
:
417 if (!mpctx
->sh_video
)
422 /* check for valid audio stream */
423 case META_AUDIO_CODEC
:
424 case META_AUDIO_BITRATE
:
425 case META_AUDIO_SAMPLES
:
427 if (!mpctx
->sh_audio
)
432 /* check for valid demuxer */
433 case META_INFO_TITLE
:
434 case META_INFO_ARTIST
:
435 case META_INFO_ALBUM
:
437 case META_INFO_COMMENT
:
438 case META_INFO_TRACK
:
439 case META_INFO_GENRE
:
453 static char *get_demuxer_info (char *tag
) {
454 char **info
= mpctx
->demuxer
->info
;
460 for (n
= 0; info
[2*n
] != NULL
; n
++)
461 if (!strcmp (info
[2*n
], tag
))
464 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
467 char *get_metadata (metadata_t type
) {
469 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
470 sh_video_t
* const sh_video
= mpctx
->sh_video
;
472 if (!is_valid_metadata_type (type
))
479 return strdup (mp_basename2 (filename
));
482 case META_VIDEO_CODEC
:
484 if (sh_video
->format
== 0x10000001)
485 meta
= strdup ("mpeg1");
486 else if (sh_video
->format
== 0x10000002)
487 meta
= strdup ("mpeg2");
488 else if (sh_video
->format
== 0x10000004)
489 meta
= strdup ("mpeg4");
490 else if (sh_video
->format
== 0x10000005)
491 meta
= strdup ("h264");
492 else if (sh_video
->format
>= 0x20202020)
494 meta
= (char *) malloc (8);
495 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
499 meta
= (char *) malloc (8);
500 sprintf (meta
, "0x%08X", sh_video
->format
);
505 case META_VIDEO_BITRATE
:
507 meta
= (char *) malloc (16);
508 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
512 case META_VIDEO_RESOLUTION
:
514 meta
= (char *) malloc (16);
515 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
519 case META_AUDIO_CODEC
:
521 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
522 meta
= strdup (sh_audio
->codec
->name
);
526 case META_AUDIO_BITRATE
:
528 meta
= (char *) malloc (16);
529 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
533 case META_AUDIO_SAMPLES
:
535 meta
= (char *) malloc (16);
536 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
540 /* check for valid demuxer */
541 case META_INFO_TITLE
:
542 return get_demuxer_info ("Title");
544 case META_INFO_ARTIST
:
545 return get_demuxer_info ("Artist");
547 case META_INFO_ALBUM
:
548 return get_demuxer_info ("Album");
551 return get_demuxer_info ("Year");
553 case META_INFO_COMMENT
:
554 return get_demuxer_info ("Comment");
556 case META_INFO_TRACK
:
557 return get_demuxer_info ("Track");
559 case META_INFO_GENRE
:
560 return get_demuxer_info ("Genre");
569 /// step size of mixer changes
572 void uninit_player(unsigned int mask
){
573 mask
=inited_flags
&mask
;
575 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
577 if(mask
&INITED_ACODEC
){
578 inited_flags
&=~INITED_ACODEC
;
579 current_module
="uninit_acodec";
580 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
582 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
584 mpctx
->sh_audio
=NULL
;
587 if(mask
&INITED_VCODEC
){
588 inited_flags
&=~INITED_VCODEC
;
589 current_module
="uninit_vcodec";
590 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
591 mpctx
->sh_video
=NULL
;
597 if(mask
&INITED_DEMUXER
){
598 inited_flags
&=~INITED_DEMUXER
;
599 current_module
="free_demuxer";
601 mpctx
->stream
=mpctx
->demuxer
->stream
;
602 free_demuxer(mpctx
->demuxer
);
607 // kill the cache process:
608 if(mask
&INITED_STREAM
){
609 inited_flags
&=~INITED_STREAM
;
610 current_module
="uninit_stream";
611 if(mpctx
->stream
) free_stream(mpctx
->stream
);
616 inited_flags
&=~INITED_VO
;
617 current_module
="uninit_vo";
618 mpctx
->video_out
->uninit();
619 mpctx
->video_out
=NULL
;
622 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
623 if(mask
&INITED_GETCH2
){
624 inited_flags
&=~INITED_GETCH2
;
625 current_module
="uninit_getch2";
626 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
631 if(mask
&INITED_VOBSUB
){
632 inited_flags
&=~INITED_VOBSUB
;
633 current_module
="uninit_vobsub";
634 if(vo_vobsub
) vobsub_close(vo_vobsub
);
638 if (mask
&INITED_SPUDEC
){
639 inited_flags
&=~INITED_SPUDEC
;
640 current_module
="uninit_spudec";
641 spudec_free(vo_spudec
);
646 inited_flags
&=~INITED_AO
;
647 current_module
="uninit_ao";
648 if (mpctx
->user_muted
| mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
649 mpctx
->audio_out
->uninit(mpctx
->eof
?0:1); mpctx
->audio_out
=NULL
;
654 inited_flags
&=~INITED_GUI
;
655 current_module
="uninit_gui";
660 if(mask
&INITED_INPUT
){
661 inited_flags
&=~INITED_INPUT
;
662 current_module
="uninit_input";
669 void exit_player_with_rc(const char* how
, int rc
){
671 uninit_player(INITED_ALL
);
676 vo_uninit(); // Close the X11 connection (if any is open).
680 current_module
="uninit_font";
681 if (vo_font
) free_font_desc(vo_font
);
688 ass_library_done(ass_library
);
691 current_module
="exit_player";
693 // free mplayer config
695 m_config_free(mconfig
);
698 play_tree_free(mpctx
->playtree
, 1);
701 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
702 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
703 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
708 void exit_player(const char* how
){
709 exit_player_with_rc(how
, 1);
713 static void child_sighandler(int x
){
715 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
720 static char *prog_path
;
721 static int crash_debug
= 0;
724 static void exit_sighandler(int x
){
725 static int sig_count
=0;
727 if (!crash_debug
|| x
!= SIGTRAP
)
730 if(inited_flags
==0 && sig_count
>1) exit(1);
733 /* We're crashing bad and can't uninit cleanly :(
734 * by popular request, we make one last (dirty)
735 * effort to restore the user's
740 if(sig_count
==6) exit(1);
744 kill(getpid(),SIGKILL
);
747 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
748 current_module
?current_module
:"unknown"
750 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
757 break; // killed from keyboard (^C) or killed [-9]
759 #ifdef RUNTIME_CPUDETECT
760 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
762 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
766 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
768 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
773 snprintf(spid
, 19, "%i", getpid());
775 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
777 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
778 if (gdb_pid
== 0) { // We are the child
779 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
780 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
781 } else if (gdb_pid
< 0)
782 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
784 waitpid(gdb_pid
, NULL
, 0);
786 if (x
== SIGTRAP
) return;
793 extern void mp_input_register_options(m_config_t
* cfg
);
795 #include "cfg-mplayer.h"
797 static void parse_cfgfiles( m_config_t
* conf
)
801 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
803 if ((conffile
= get_path("")) == NULL
) {
804 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
809 mkdir(conffile
, 0777);
812 if ((conffile
= get_path("config")) == NULL
) {
813 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
815 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
816 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
817 write(conffile_fd
, default_config
, strlen(default_config
));
820 if (m_config_parse_config_file(conf
, conffile
) < 0)
827 void load_per_file_config (m_config_t
* conf
, const char *const file
)
830 char cfg
[strlen(file
)+10];
834 sprintf (cfg
, "%s.conf", file
);
836 if (use_filedir_conf
&& !stat (cfg
, &st
))
838 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
839 m_config_parse_config_file (conf
, cfg
);
843 if ((name
= strrchr (cfg
, '/')) == NULL
)
848 if ((confpath
= get_path (name
)) != NULL
)
850 if (!stat (confpath
, &st
))
852 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
853 m_config_parse_config_file (conf
, confpath
);
860 /* When libmpdemux performs a blocking operation (network connection or
861 * cache filling) if the operation fails we use this function to check
862 * if it was interrupted by the user.
863 * The function returns a new value for eof. */
864 static int libmpdemux_was_interrupted(int eof
) {
866 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
869 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
870 case MP_CMD_PLAY_TREE_STEP
: {
871 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
872 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
874 case MP_CMD_PLAY_TREE_UP_STEP
: {
875 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
877 case MP_CMD_PLAY_ALT_SRC_STEP
: {
878 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
886 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
888 int playtree_add_playlist(play_tree_t
* entry
)
890 play_tree_add_bpf(entry
,filename
);
895 import_playtree_playlist_into_gui(entry
, mconfig
);
896 play_tree_free_list(entry
,1);
902 entry
= mpctx
->playtree_iter
->tree
;
903 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
904 return PT_NEXT_ENTRY
;
906 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
907 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
908 return PT_NEXT_ENTRY
;
911 play_tree_remove(entry
,1,1);
914 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
915 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
916 entry
= mpctx
->playtree_iter
->tree
;
917 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
918 return PT_NEXT_ENTRY
;
920 play_tree_remove(entry
,1,1);
925 void add_subtitles(char *filename
, float fps
, int silent
)
929 ass_track_t
*asst
= 0;
932 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
936 subd
= sub_read_file(filename
, fps
);
940 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
942 asst
= ass_read_file(ass_library
, filename
, 0);
944 if (ass_enabled
&& subd
&& !asst
)
945 asst
= ass_read_subdata(ass_library
, subd
, fps
);
947 if (!asst
&& !subd
&& !silent
)
951 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
,
952 filename_recode(filename
));
955 if (!asst
&& !subd
) return;
956 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
960 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
961 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
962 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
963 filename_recode(filename
));
964 ++mpctx
->set_of_sub_size
;
965 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, mpctx
->set_of_sub_size
,
966 filename_recode(filename
));
969 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
970 void update_set_of_subtitles(void)
971 // subdata was changed, set_of_sub... have to be updated.
973 sub_data
** const set_of_subtitles
= mpctx
->set_of_subtitles
;
975 if (mpctx
->set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
976 for (i
= mpctx
->set_of_sub_pos
+ 1; i
< mpctx
->set_of_sub_size
; ++i
)
977 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
978 set_of_subtitles
[mpctx
->set_of_sub_size
-1] = NULL
;
979 --mpctx
->set_of_sub_size
;
980 if (mpctx
->set_of_sub_size
> 0) subdata
= set_of_subtitles
[mpctx
->set_of_sub_pos
=0];
982 else if (mpctx
->set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
983 set_of_subtitles
[mpctx
->set_of_sub_pos
] = subdata
;
985 else if (mpctx
->set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
986 set_of_subtitles
[mpctx
->set_of_sub_pos
=mpctx
->set_of_sub_size
] = subdata
;
987 ++mpctx
->set_of_sub_size
;
991 void init_vo_spudec(void) {
993 spudec_free(vo_spudec
);
994 inited_flags
&= ~INITED_SPUDEC
;
997 unsigned int palette
[16], width
, height
;
998 current_module
="spudec_init_vobsub";
999 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1000 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1004 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1005 current_module
="spudec_init_dvdread";
1006 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1007 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1012 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1013 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1014 current_module
="spudec_init_dvdnav";
1015 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1019 if ((vo_spudec
== NULL
) && (mpctx
->demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1020 (mpctx
->d_sub
->sh
!= NULL
) && (((sh_sub_t
*)mpctx
->d_sub
->sh
)->type
== 'v')) {
1021 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1022 current_module
= "spudec_init_matroska";
1024 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1025 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1026 mkv_sh_sub
->height
);
1027 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1030 if (vo_spudec
==NULL
) {
1031 sh_sub_t
*sh
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1032 unsigned int *palette
= NULL
;
1033 if (sh
&& sh
->has_palette
)
1034 palette
= sh
->palette
;
1035 current_module
="spudec_init_normal";
1036 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1037 spudec_set_font_factor(vo_spudec
,font_factor
);
1040 if (vo_spudec
!=NULL
)
1041 inited_flags
|=INITED_SPUDEC
;
1045 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1046 * make it all work is to use the builtin SDL-bootstrap code, which
1047 * will be done automatically by replacing our main() if we include SDL.h.
1049 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1054 * \brief append a formatted string
1055 * \param buf buffer to print into
1056 * \param pos position of terminating 0 in buf
1057 * \param len maximum number of characters in buf, not including terminating 0
1058 * \param format printf format string
1060 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1063 va_start(va
, format
);
1064 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1073 * \brief append time in the hh:mm:ss.f format
1074 * \param buf buffer to print into
1075 * \param pos position of terminating 0 in buf
1076 * \param len maximum number of characters in buf, not including terminating 0
1077 * \param time time value to convert/append
1079 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1080 long tenths
= 10 * time
;
1081 int f1
= tenths
% 10;
1082 int ss
= (tenths
/ 10) % 60;
1083 int mm
= (tenths
/ 600) % 60;
1084 int hh
= tenths
/ 36000;
1086 saddf(buf
, pos
, len
, "unknown");
1090 saddf(buf
, pos
, len
, "%2d:", hh
);
1091 if (hh
> 0 || mm
> 0)
1092 saddf(buf
, pos
, len
, "%02d:", mm
);
1093 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1097 * \brief print the status line
1098 * \param a_pos audio position
1099 * \param a_v A-V desynchronization
1100 * \param corr amount out A-V synchronization
1102 static void print_status(float a_pos
, float a_v
, float corr
)
1104 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1109 if (screen_width
> 0)
1110 width
= screen_width
;
1114 /* Windows command line is broken (MinGW's rxvt works, but we
1115 * should not depend on that). */
1118 line
= malloc(width
+ 1); // one additional char for the terminating null
1121 if (mpctx
->sh_audio
) {
1122 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1124 float len
= demuxer_get_time_length(mpctx
->demuxer
);
1125 saddf(line
, &pos
, width
, "(");
1126 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1127 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1128 sadd_hhmmssf(line
, &pos
, width
, len
);
1129 saddf(line
, &pos
, width
, ") ");
1135 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1138 if (mpctx
->sh_audio
&& sh_video
)
1139 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1143 saddf(line
, &pos
, width
, "%3d/%3d ",
1144 (int)sh_video
->num_frames
,
1145 (int)sh_video
->num_frames_decoded
);
1149 if (sh_video
->timer
> 0.5)
1150 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1151 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
1152 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
1153 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
1155 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1156 } else if (mpctx
->sh_audio
) {
1157 if (mpctx
->delay
> 0.5)
1158 saddf(line
, &pos
, width
, "%4.1f%% ",
1159 100.0*audio_time_usage
/(double)mpctx
->delay
);
1161 saddf(line
, &pos
, width
, "??,?%% ");
1166 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1168 #ifdef USE_STREAM_CACHE
1170 if (stream_cache_size
> 0)
1171 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1175 if (playback_speed
!= 1)
1176 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
1179 if (erase_to_end_of_line
) {
1181 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1183 memset(&line
[pos
], ' ', width
- pos
);
1185 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
1191 * \brief build a chain of audio filters that converts the input format
1192 * to the ao's format, taking into account the current playback_speed.
1193 * \param sh_audio describes the requested input format of the chain.
1194 * \param ao_data describes the requested output format of the chain.
1196 int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1203 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
1205 mpctx
->mixer
.afilter
= NULL
;
1208 new_srate
= sh_audio
->samplerate
* playback_speed
;
1209 if (new_srate
!= ao_data
->samplerate
) {
1210 // limits are taken from libaf/af_resample.c
1211 if (new_srate
< 8000)
1213 if (new_srate
> 192000)
1215 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1217 result
= init_audio_filters(sh_audio
, new_srate
,
1218 sh_audio
->channels
, sh_audio
->sample_format
,
1219 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
1220 ao_data
->outburst
* 4, ao_data
->buffersize
);
1221 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1223 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1229 typedef struct mp_osd_msg mp_osd_msg_t
;
1231 /// Previous message on the stack.
1235 int id
,level
,started
;
1236 /// Display duration in ms.
1240 /// OSD message stack.
1241 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1244 * \brief Add a message on the OSD message stack
1246 * If a message with the same id is already present in the stack
1247 * it is pulled on top of the stack, otherwise a new message is created.
1251 void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1252 mp_osd_msg_t
*msg
,*last
=NULL
;
1256 // look if the id is already in the stack
1257 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1258 last
= msg
, msg
= msg
->prev
);
1259 // not found: alloc it
1261 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1262 msg
->prev
= osd_msg_stack
;
1263 osd_msg_stack
= msg
;
1264 } else if(last
) { // found, but it's not on top of the stack
1265 last
->prev
= msg
->prev
;
1266 msg
->prev
= osd_msg_stack
;
1267 osd_msg_stack
= msg
;
1271 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1273 if(r
>= 64) msg
->msg
[63] = 0;
1282 * \brief Remove a message from the OSD stack
1284 * This function can be used to get rid of a message right away.
1288 void rm_osd_msg(int id
) {
1289 mp_osd_msg_t
*msg
,*last
=NULL
;
1291 // Search for the msg
1292 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1293 last
= msg
, msg
= msg
->prev
);
1296 // Detach it from the stack and free it
1298 last
->prev
= msg
->prev
;
1300 osd_msg_stack
= msg
->prev
;
1305 * \brief Remove all messages from the OSD stack
1309 static void clear_osd_msgs(void) {
1310 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1316 osd_msg_stack
= NULL
;
1320 * \brief Get the current message from the OSD stack.
1322 * This function decrements the message timer and destroys the old ones.
1323 * The message that should be displayed is returned (if any).
1327 static mp_osd_msg_t
* get_osd_msg(void) {
1328 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1329 static unsigned last_update
= 0;
1330 unsigned now
= GetTimerMS();
1332 char hidden_dec_done
= 0;
1334 if(!last_update
) last_update
= now
;
1335 diff
= now
>= last_update
? now
- last_update
: 0;
1339 // Look for the first message in the stack with high enough level.
1340 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1342 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1343 // The message has a high enough level or it is the first hidden one
1344 // in both cases we decrement the timer or kill it.
1345 if(!msg
->started
|| msg
->time
> diff
) {
1346 if(msg
->started
) msg
->time
-= diff
;
1347 else msg
->started
= 1;
1349 if(msg
->level
<= osd_level
) return msg
;
1350 hidden_dec_done
= 1;
1359 osd_msg_stack
= prev
;
1368 * \brief Display the OSD bar.
1370 * Display the OSD bar or fall back on a simple message.
1374 void set_osd_bar(int type
,const char* name
,double min
,double max
,double val
) {
1376 if(osd_level
< 1) return;
1378 if(mpctx
->sh_video
) {
1379 osd_visible
= (GetTimerMS() + 1000) | 1;
1380 vo_osd_progbar_type
= type
;
1381 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1382 vo_osd_changed(OSDTYPE_PROGBAR
);
1386 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1387 name
,ROUND(100*(val
-min
)/(max
-min
)));
1392 * \brief Update the OSD message line.
1394 * This function displays the current message on the vo OSD or on the term.
1395 * If the stack is empty and the OSD level is high enough the timer
1396 * is displayed (only on the vo OSD).
1400 static void update_osd_msg(void) {
1402 static char osd_text
[64] = "";
1403 static char osd_text_timer
[64];
1405 // we need some mem for vo_osd_text
1406 vo_osd_text
= (unsigned char*)osd_text
;
1408 // Look if we have a msg
1409 if((msg
= get_osd_msg())) {
1410 if(strcmp(osd_text
,msg
->msg
)) {
1411 strncpy((char*)osd_text
, msg
->msg
, 63);
1412 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1413 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1418 if(mpctx
->sh_video
) {
1419 // fallback on the timer
1421 int len
= demuxer_get_time_length(mpctx
->demuxer
);
1422 int percentage
= -1;
1423 char percentage_text
[10];
1424 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1426 if (mpctx
->osd_show_percentage
)
1427 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1429 if (percentage
>= 0)
1430 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1432 percentage_text
[0] = 0;
1435 snprintf(osd_text_timer
, 63,
1436 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1437 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1438 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1440 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1441 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1442 pts
%60,percentage_text
);
1444 osd_text_timer
[0]=0;
1446 // always decrement the percentage timer
1447 if(mpctx
->osd_show_percentage
)
1448 mpctx
->osd_show_percentage
--;
1450 if(strcmp(osd_text
,osd_text_timer
)) {
1451 strncpy(osd_text
, osd_text_timer
, 63);
1452 vo_osd_changed(OSDTYPE_OSD
);
1457 // Clear the term osd line
1458 if(term_osd
&& osd_text
[0]) {
1460 printf("%s\n",term_osd_esc
);
1468 void reinit_audio_chain(void) {
1469 if(mpctx
->sh_audio
){
1470 current_module
="init_audio_codec";
1471 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1472 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1473 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // failed to init :(
1474 mpctx
->d_audio
->id
= -2;
1477 inited_flags
|=INITED_ACODEC
;
1478 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1481 //const ao_info_t *info=audio_out->info;
1482 current_module
="af_preinit";
1483 ao_data
.samplerate
=force_srate
;
1485 ao_data
.format
=audio_output_format
;
1487 // first init to detect best values
1488 if(!preinit_audio_filters(mpctx
->sh_audio
,
1490 (int)(mpctx
->sh_audio
->samplerate
*playback_speed
),
1491 mpctx
->sh_audio
->channels
, mpctx
->sh_audio
->sample_format
,
1493 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1494 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
1495 exit_player(MSGTR_Exit_error
);
1498 current_module
="ao2_init";
1499 if(!(mpctx
->audio_out
=init_best_audio_out(audio_driver_list
,
1503 ao_data
.format
,0))){
1505 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1506 uninit_player(INITED_ACODEC
); // close codec
1507 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1508 mpctx
->d_audio
->id
= -2;
1512 inited_flags
|=INITED_AO
;
1513 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1514 mpctx
->audio_out
->info
->short_name
,
1515 ao_data
.samplerate
, ao_data
.channels
,
1516 af_fmt2str_short(ao_data
.format
),
1517 af_fmt2bits(ao_data
.format
)/8 );
1518 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1519 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1520 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1521 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1522 // init audio filters:
1524 current_module
="af_init";
1525 if(!build_afilter_chain(mpctx
->sh_audio
, &ao_data
)) {
1526 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
1527 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1528 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1529 // sh_audio=mpctx->d_audio->sh=NULL; // -> nosound
1533 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1534 mpctx
->mixer
.volstep
= volstep
;
1543 // Return pts value corresponding to the end point of audio written to the
1545 static double written_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
)
1547 // first calculate the end pts of audio that has been output by decoder
1548 double a_pts
= sh_audio
->pts
;
1549 if (a_pts
!= MP_NOPTS_VALUE
)
1550 // Good, decoder supports new way of calculating audio pts.
1551 // sh_audio->pts is the timestamp of the latest input packet with
1552 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1553 // the amount of bytes the decoder has written after that timestamp.
1554 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1556 // Decoder doesn't support new way of calculating pts (or we're
1557 // being called before it has decoded anything with known timestamp).
1558 // Use the old method of audio pts calculation: take the timestamp
1559 // of last packet with known pts the decoder has read data from,
1560 // and add amount of bytes read after the beginning of that packet
1561 // divided by input bps. This will be inaccurate if the input/output
1562 // ratio is not constant for every audio packet or if it is constant
1563 // but not accurately known in sh_audio->i_bps.
1565 a_pts
= d_audio
->pts
;
1566 // ds_tell_pts returns bytes read after last timestamp from
1567 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1568 // it has read but not decoded
1569 if (sh_audio
->i_bps
)
1570 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1571 (double)sh_audio
->i_bps
;
1573 // Now a_pts hopefully holds the pts for end of audio from decoder.
1574 // Substract data in buffers between decoder and audio out.
1576 // Decoded but not filtered
1577 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1579 // Data that was ready for ao but was buffered because ao didn't fully
1580 // accept everything to internal buffers yet
1581 a_pts
-= sh_audio
->a_out_buffer_len
* playback_speed
/ (double)ao_data
.bps
;
1586 // Return pts value corresponding to currently playing audio.
1587 double playing_audio_pts(sh_audio_t
*sh_audio
, demux_stream_t
*d_audio
,
1588 ao_functions_t
*audio_out
)
1590 return written_audio_pts(sh_audio
, d_audio
) - playback_speed
*
1591 audio_out
->get_delay();
1594 static int generate_video_frame(sh_video_t
*sh_video
, demux_stream_t
*d_video
)
1596 unsigned char *start
;
1602 void *decoded_frame
;
1603 current_module
= "decode video";
1604 // XXX Time used in this call is not counted in any performance
1605 // timer now, OSD is not updated correctly for filter-added frames
1606 if (vf_output_queued_frame(sh_video
->vfilter
))
1608 current_module
= "video_read_frame";
1609 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
1611 // try to extract last frames in case of decoder lag
1616 if (in_size
> max_framesize
)
1617 max_framesize
= in_size
;
1618 current_module
= "decode video";
1619 decoded_frame
= decode_video(sh_video
, start
, in_size
, 0, pts
);
1620 if (decoded_frame
) {
1621 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
1623 current_module
= "filter video";
1624 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
1637 static float timing_sleep(float time_frame
)
1641 // -------- RTC -----------
1642 current_module
="sleep_rtc";
1643 while (time_frame
> 0.000) {
1644 unsigned long rtc_ts
;
1645 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1646 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
1647 time_frame
-= GetRelativeTime();
1653 current_module
= "sleep_darwin";
1654 while (time_frame
> 0.005) {
1655 usec_sleep(1000000*time_frame
);
1656 time_frame
-= GetRelativeTime();
1661 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1662 // unnecessarily high CPU usage
1663 float margin
= softsleep
? 0.011 : 0;
1664 current_module
= "sleep_timer";
1665 while (time_frame
> margin
) {
1666 usec_sleep(1000000 * (time_frame
- margin
));
1667 time_frame
-= GetRelativeTime();
1670 current_module
= "sleep_soft";
1672 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
1673 while (time_frame
> 0)
1674 time_frame
-=GetRelativeTime(); // burn the CPU
1677 #endif /* SYS_DARWIN */
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
;
1890 //================== Init VIDEO (codec & libvo) ==========================
1891 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
1892 current_module
="preinit_libvo";
1894 //shouldn't we set dvideo->id=-2 when we fail?
1896 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
1897 if(!(mpctx
->video_out
=init_best_video_out(video_driver_list
))){
1898 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
1901 sh_video
->video_out
=mpctx
->video_out
;
1902 inited_flags
|=INITED_VO
;
1905 current_module
="init_video_filters";
1907 char* vf_arg
[] = { "_oldargs_", (char*)mpctx
->video_out
, NULL
};
1908 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
1912 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
1913 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
1915 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
1920 sh_video
->vfilter
=(void*)vf_menu
;
1928 for (i
= 0; vf_settings
[i
].name
; ++i
)
1929 if (strcmp(vf_settings
[i
].name
, "ass") == 0) {
1934 extern vf_info_t vf_info_ass
;
1935 vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
1936 char* vf_arg
[] = {"auto", "1", NULL
};
1937 vf_instance_t
* vf_ass
= vf_open_plugin(libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
1939 sh_video
->vfilter
=(void*)vf_ass
;
1941 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
1946 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
1950 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
1953 current_module
="init_video_codec";
1955 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1956 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
1957 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1959 if(!sh_video
->inited
){
1960 if(!fixed_vo
) uninit_player(INITED_VO
);
1964 inited_flags
|=INITED_VCODEC
;
1966 if (sh_video
->codec
)
1967 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
1969 sh_video
->last_pts
= MP_NOPTS_VALUE
;
1970 sh_video
->num_buffered_pts
= 0;
1971 sh_video
->next_frame_time
= 0;
1974 // Auto quality option enabled
1975 output_quality
=get_video_quality_max(sh_video
);
1976 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
1977 else output_quality
=auto_quality
;
1978 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
1979 set_video_quality(sh_video
,output_quality
);
1982 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1984 current_module
="init_vo";
1989 mpctx
->sh_video
= mpctx
->d_video
->sh
= NULL
;
1993 static double update_video(int *blit_frame
)
1995 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1996 //-------------------- Decode a frame: -----------------------
1998 *blit_frame
= 0; // Don't blit if we hit EOF
2000 unsigned char* start
=NULL
;
2001 void *decoded_frame
;
2005 current_module
= "video_read_frame";
2006 frame_time
= sh_video
->next_frame_time
;
2007 in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2011 if (in_size
> max_framesize
)
2012 max_framesize
= in_size
; // stats
2013 sh_video
->timer
+= frame_time
;
2014 if (mpctx
->sh_audio
)
2015 mpctx
->delay
-= frame_time
;
2016 // video_read_frame can change fps (e.g. for ASF video)
2017 vo_fps
= sh_video
->fps
;
2018 // check for frame-drop:
2019 current_module
= "check_framedrop";
2020 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
2021 static int dropped_frames
;
2022 float delay
= playback_speed
*mpctx
->audio_out
->get_delay();
2023 float d
= delay
-mpctx
->delay
;
2024 // we should avoid dropping too many frames in sequence unless we
2025 // are too late. and we allow 100ms A-V delay here:
2026 if (d
< -dropped_frames
*frame_time
-0.100 &&
2027 mpctx
->osd_function
!= OSD_PAUSE
) {
2028 drop_frame
= frame_dropping
;
2032 drop_frame
= dropped_frames
= 0;
2035 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
2037 current_module
= "decode_video";
2038 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
2040 current_module
= "filter_video";
2041 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
2045 if (!generate_video_frame(sh_video
, mpctx
->d_video
))
2047 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
,
2048 VFCTRL_GET_PTS
, &sh_video
->pts
);
2049 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
2050 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
2051 sh_video
->pts
= sh_video
->last_pts
;
2053 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2054 sh_video
->last_pts
= sh_video
->pts
;
2055 else if (sh_video
->last_pts
>= sh_video
->pts
) {
2056 sh_video
->last_pts
= sh_video
->pts
;
2057 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "pts value <= previous");
2059 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2060 sh_video
->last_pts
= sh_video
->pts
;
2061 sh_video
->timer
+= frame_time
;
2063 mpctx
->delay
-= frame_time
;
2069 void pause_loop(void)
2073 // Small hack to display the pause message on the OSD line.
2074 // The pause string is: "\n == PAUSE == \r" so we need to
2075 // take the first and the last char out
2076 if (term_osd
&& !mpctx
->sh_video
) {
2077 char msg
[128] = MSGTR_Paused
;
2078 int mlen
= strlen(msg
);
2080 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2083 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2084 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2088 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
2090 if (mpctx
->video_out
&& mpctx
->sh_video
&& vo_config_count
)
2091 mpctx
->video_out
->control(VOCTRL_PAUSE
, NULL
);
2093 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2094 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2096 while ( (cmd
= mp_input_get_cmd(20, 1, 1)) == NULL
) {
2097 if (mpctx
->sh_video
&& mpctx
->video_out
&& vo_config_count
)
2098 mpctx
->video_out
->check_events();
2102 guiGetEvent(guiReDraw
, NULL
);
2103 if (guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
))
2109 vf_menu_pause_update(vf_menu
);
2113 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
2114 cmd
= mp_input_get_cmd(0,1,0);
2117 mpctx
->osd_function
=OSD_PLAY
;
2118 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2119 mpctx
->audio_out
->resume(); // resume audio
2120 if (mpctx
->video_out
&& mpctx
->sh_video
&& vo_config_count
)
2121 mpctx
->video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
2122 (void)GetRelativeTime(); // ignore time that passed during pause
2125 if (guiIntfStruct
.Playing
== guiSetStop
)
2128 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
2133 void print_version(void){
2134 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s\n", MP_TITLE
);
2136 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2137 GetCpuCaps(&gCpuCaps
);
2139 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2140 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
2141 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
2142 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
2143 #ifdef RUNTIME_CPUDETECT
2144 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
2146 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
2148 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
2151 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
2154 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
2157 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
2160 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
2163 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
2165 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
2166 #endif /* RUNTIME_CPUDETECT */
2167 #endif /* ARCH_X86 */
2171 // Find the right mute status and record position for new file position
2172 static void edl_seek_reset(MPContext
*mpctx
)
2174 mpctx
->edl_muted
= 0;
2175 next_edl_record
= edl_records
;
2177 while (next_edl_record
) {
2178 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2181 if (next_edl_record
->action
== EDL_MUTE
)
2182 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2183 next_edl_record
= next_edl_record
->next
;
2185 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2186 mixer_mute(&mpctx
->mixer
);
2190 // Execute EDL command for the current position if one exists
2191 static void edl_update(MPContext
*mpctx
)
2193 if (!next_edl_record
)
2196 if (!mpctx
->sh_video
) {
2197 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
2198 free_edl(edl_records
);
2199 next_edl_record
= NULL
;
2204 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2205 if (next_edl_record
->action
== EDL_SKIP
) {
2206 mpctx
->osd_function
= OSD_FFW
;
2208 rel_seek_secs
= next_edl_record
->length_sec
;
2209 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2210 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2211 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2214 else if (next_edl_record
->action
== EDL_MUTE
) {
2215 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2216 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2217 mixer_mute(&mpctx
->mixer
);
2218 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2219 next_edl_record
->start_sec
);
2221 next_edl_record
= next_edl_record
->next
;
2226 // style & 1 == 0 means seek relative to current position, == 1 means absolute
2227 // style & 2 == 0 means amount in seconds, == 2 means fraction of file length
2228 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2229 static int seek(MPContext
*mpctx
, double amount
, int style
)
2231 current_module
= "seek";
2232 if (demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
) == 0)
2235 if (mpctx
->sh_video
) {
2236 current_module
= "seek_video_reset";
2237 resync_video_stream(mpctx
->sh_video
);
2238 if (vo_config_count
)
2239 mpctx
->video_out
->control(VOCTRL_RESET
, NULL
);
2240 mpctx
->sh_video
->num_buffered_pts
= 0;
2241 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2242 mpctx
->num_buffered_frames
= 0;
2244 // Not all demuxers set d_video->pts during seek, so this value
2245 // (which is used by at least vobsub and edl code below) may
2246 // be completely wrong (probably 0).
2247 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
;
2248 update_subtitles(mpctx
->sh_video
, mpctx
->d_sub
, 1);
2251 if (mpctx
->sh_audio
) {
2252 current_module
= "seek_audio_reset";
2253 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2254 mpctx
->sh_audio
->a_buffer_len
= 0;
2255 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2259 current_module
= "seek_vobsub_reset";
2260 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2263 edl_seek_reset(mpctx
);
2266 max_pts_correction
= 0.1;
2267 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2270 current_module
= NULL
;
2274 int main(int argc
,char* argv
[]){
2281 /* Flag indicating whether MPlayer should exit without playing anything. */
2284 //float a_frame=0; // Audio
2288 int gui_no_filename
=0;
2290 srand((int) time(NULL
));
2296 for(i
=1; i
<argc
; i
++)
2297 if(!strcmp(argv
[i
], "-really-quiet"))
2301 #if defined(WIN32) && defined(USE_WIN32DLL)
2303 #endif /*WIN32 && USE_WIN32DLL*/
2306 tv_param_immediate
= 1;
2309 if (argc
> 1 && argv
[1] &&
2310 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
2311 use_gui
= !strcmp(argv
[1], "-gui");
2315 char *base
= strrchr(argv
[0], '/');
2317 base
= strrchr(argv
[0], '\\');
2320 if(strstr(base
, "gmplayer"))
2324 mconfig
= m_config_new();
2325 m_config_register_options(mconfig
,mplayer_opts
);
2326 // TODO : add something to let modules register their options
2327 mp_input_register_options(mconfig
);
2328 parse_cfgfiles(mconfig
);
2331 if ( use_gui
) cfg_read();
2334 mpctx
->playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
2335 if(mpctx
->playtree
== NULL
)
2338 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
2339 if(mpctx
->playtree
) {
2340 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
2341 if(mpctx
->playtree_iter
) {
2342 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2343 play_tree_iter_free(mpctx
->playtree_iter
);
2344 mpctx
->playtree_iter
= NULL
;
2346 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2351 #if defined(WIN32) && defined(HAVE_NEW_GUI)
2352 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
2353 if(runningmplayer
&& filename
&& use_gui
){
2354 COPYDATASTRUCT csData
;
2355 char file
[MAX_PATH
];
2356 char *filepart
= filename
;
2357 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
2359 csData
.cbData
= strlen(file
)*2;
2360 csData
.lpData
= file
;
2361 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
2369 for(i
=0; priority_presets_defs
[i
].name
; i
++){
2370 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
2373 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
2374 priority_presets_defs
[i
].name
);
2375 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
2378 #ifndef HAVE_NEW_GUI
2380 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
2385 if(use_gui
&& !vo_init()){
2386 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
2390 if (use_gui
&& mpctx
->playtree_iter
){
2391 char cwd
[PATH_MAX
+2];
2392 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2393 play_tree_iter_free(mpctx
->playtree_iter
);
2394 mpctx
->playtree_iter
=NULL
;
2396 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
2399 // Prefix relative paths with current working directory
2400 play_tree_add_bpf(mpctx
->playtree
, cwd
);
2402 // Import initital playtree into GUI.
2403 import_initial_playtree_into_gui(mpctx
->playtree
, mconfig
, enqueue
);
2405 #endif /* HAVE_NEW_GUI */
2407 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
2412 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
2417 /* Check codecs.conf. */
2418 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2419 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2420 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2421 if(!parse_codec_cfg(NULL
)){
2422 exit_player_with_rc(NULL
, 0);
2424 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
2427 free( mem_ptr
); // release the buffer created by get_path()
2431 if(video_codec_list
){
2433 video_codec
=video_codec_list
[0];
2434 for(i
=0;video_codec_list
[i
];i
++)
2435 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2438 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2439 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
2440 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2442 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2445 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2446 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
2447 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2449 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2452 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2454 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2457 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
2459 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2462 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
2468 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
2470 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2474 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
2475 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
2476 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
2478 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2481 if(list_properties
) {
2482 property_print_help();
2489 if (player_idle_mode
&& use_gui
) {
2490 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
2491 exit_player_with_rc(NULL
, 1);
2494 if(!filename
&& !player_idle_mode
){
2496 // no file/vcd/dvd -> show HELP:
2497 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
2498 exit_player_with_rc(NULL
, 0);
2499 } else gui_no_filename
=1;
2502 /* Display what configure line was used */
2503 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
2505 // Many users forget to include command line in bugreports...
2506 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
2507 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
2508 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
2509 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2512 //------ load global data first ------
2515 #ifdef HAVE_FREETYPE
2518 #ifdef HAVE_FONTCONFIG
2519 if(!font_fontconfig
)
2522 #ifdef HAVE_BITMAP_FONT
2524 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
2525 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,
2526 filename_recode(font_name
));
2529 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
2530 free(mem_ptr
); // release the buffer created by get_path()
2532 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
2535 #ifdef HAVE_FONTCONFIG
2542 ass_library
= ass_init();
2548 // seteuid(0); /* Can't hurt to try to get root here */
2549 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
2550 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
2551 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
2553 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
2555 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
2556 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
2557 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
2560 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
2561 /* variable only by the root */
2562 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
2566 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
2570 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2571 // and now ? -- Pontscho
2572 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
2575 #endif /* HAVE_RTC */
2576 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
2577 softsleep
?"software":timer_name
);
2580 if ( !use_gui
) load_termcap(NULL
); // load key-codes
2583 // ========== Init keyboard FIFO (connection to libvo) ============
2585 // Init input system
2586 current_module
= "init_input";
2587 mp_input_init(use_gui
);
2588 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
2591 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
2593 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
2595 else if(!noconsolecontrols
)
2596 #ifndef HAVE_NO_POSIX_SELECT
2597 mp_input_add_key_fd(0,1,NULL
,NULL
);
2599 mp_input_add_key_fd(0,0,NULL
,NULL
);
2602 inited_flags
|=INITED_INPUT
;
2603 current_module
= NULL
;
2607 if(menu_cfg
&& menu_init(mpctx
, menu_cfg
))
2608 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2610 menu_cfg
= get_path("menu.conf");
2611 if(menu_init(mpctx
, menu_cfg
))
2612 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2614 if(menu_init(mpctx
, MPLAYER_CONFDIR
"/menu.conf"))
2615 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
2617 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
2627 signal(SIGCHLD
,child_sighandler
);
2631 prog_path
= argv
[0];
2633 //========= Catch terminate signals: ================
2634 // terminate requests:
2635 signal(SIGTERM
,exit_sighandler
); // kill
2636 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
2638 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
2640 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
2641 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
2642 #ifdef ENABLE_SIGHANDLER
2644 signal(SIGBUS
,exit_sighandler
); // bus error
2645 signal(SIGSEGV
,exit_sighandler
); // segfault
2646 signal(SIGILL
,exit_sighandler
); // illegal instruction
2647 signal(SIGFPE
,exit_sighandler
); // floating point exc.
2648 signal(SIGABRT
,exit_sighandler
); // abort()
2651 signal(SIGTRAP
,exit_sighandler
);
2658 guiGetEvent(guiSetContext
, mpctx
);
2659 inited_flags
|=INITED_GUI
;
2660 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
2664 // ******************* Now, let's see the per-file stuff ********************
2668 // init global sub numbers
2669 mpctx
->global_sub_size
= 0;
2670 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) mpctx
->global_sub_indices
[i
] = -1; }
2672 if (filename
) load_per_file_config (mconfig
, filename
);
2674 // We must enable getch2 here to be able to interrupt network connection
2676 if(!noconsolecontrols
&& !slave_mode
){
2677 if(inited_flags
&INITED_GETCH2
)
2678 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
2680 getch2_enable(); // prepare stdin for hotkeys...
2681 inited_flags
|=INITED_GETCH2
;
2682 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
2685 // =================== GUI idle loop (STOP state) ===========================
2688 mpctx
->file_format
=DEMUXER_TYPE_UNKNOWN
;
2689 guiGetEvent( guiSetDefaults
,0 );
2690 while ( guiIntfStruct
.Playing
!= 1 )
2695 guiGetEvent( guiReDraw
,NULL
);
2696 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
2698 guiGetEvent( guiSetParameters
,NULL
);
2699 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
2701 play_tree_t
* entry
= play_tree_new();
2702 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
2703 if ( mpctx
->playtree
) play_tree_free_list( mpctx
->playtree
->child
,1 );
2704 else mpctx
->playtree
=play_tree_new();
2705 play_tree_set_child( mpctx
->playtree
,entry
);
2708 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
2709 if(mpctx
->playtree_iter
)
2711 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
2713 play_tree_iter_free(mpctx
->playtree_iter
);
2714 mpctx
->playtree_iter
= NULL
;
2716 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2721 #endif /* HAVE_NEW_GUI */
2723 while (player_idle_mode
&& !filename
) {
2724 play_tree_t
* entry
= NULL
;
2726 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
2727 if (mpctx
->video_out
&& vo_config_count
) mpctx
->video_out
->check_events();
2731 case MP_CMD_LOADFILE
:
2732 // prepare a tree entry with the new filename
2733 entry
= play_tree_new();
2734 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
2735 // The entry is added to the main playtree after the switch().
2737 case MP_CMD_LOADLIST
:
2738 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
2741 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
2747 if (entry
) { // user entered a command that gave a valid entry
2748 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
2749 play_tree_free_list(mpctx
->playtree
->child
, 1);
2750 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
2752 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
2754 play_tree_set_child(mpctx
->playtree
, entry
);
2756 /* Make iterator start at the top the of tree. */
2757 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mconfig
);
2758 if (!mpctx
->playtree_iter
) continue;
2760 // find the first real item in the tree
2761 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2763 play_tree_iter_free(mpctx
->playtree_iter
);
2764 mpctx
->playtree_iter
= NULL
;
2765 continue; // wait for next command
2767 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
2770 //---------------------------------------------------------------------------
2773 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
,
2774 filename_recode(filename
));
2777 if (edl_records
) free_edl(edl_records
);
2778 next_edl_record
= edl_records
= edl_parse_file();
2780 if (edl_output_filename
) {
2781 if (edl_fd
) fclose(edl_fd
);
2782 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
2784 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
2785 filename_recode(edl_output_filename
));
2789 //==================== Open VOB-Sub ============================
2791 current_module
="vobsub";
2793 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
2795 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,
2796 filename_recode(vobsub_name
));
2797 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
2798 /* try to autodetect vobsub from movie filename ::atmos */
2799 char *buf
= malloc((strlen(filename
)-3)),*psub
;
2800 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
2801 strncpy(buf
, filename
, strlen(filename
)-4);
2802 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
2803 /* try from ~/.mplayer/sub */
2804 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
2807 bname
= strrchr(buf
,'/');
2809 if(!bname
) bname
= strrchr(buf
,'\\');
2813 l
= strlen(psub
) + strlen(bname
) + 1;
2814 psub
= realloc(psub
,l
);
2816 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
2822 inited_flags
|=INITED_VOBSUB
;
2823 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
2824 // check if vobsub requested only to display forced subtitles
2825 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
2827 // setup global sub numbering
2828 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] = mpctx
->global_sub_size
; // the global # of the first vobsub.
2829 mpctx
->global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
2832 //============ Open & Sync STREAM --- fork cache2 ====================
2835 mpctx
->demuxer
=NULL
;
2836 if (mpctx
->d_audio
) {
2837 //free_demuxer_stream(mpctx->d_audio);
2838 mpctx
->d_audio
=NULL
;
2840 if (mpctx
->d_video
) {
2841 //free_demuxer_stream(d_video);
2842 mpctx
->d_video
=NULL
;
2844 mpctx
->sh_audio
=NULL
;
2845 mpctx
->sh_video
=NULL
;
2847 current_module
="open_stream";
2848 mpctx
->stream
=open_stream(filename
,0,&mpctx
->file_format
);
2849 if(!mpctx
->stream
) { // error...
2850 mpctx
->eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
2851 goto goto_next_file
;
2853 inited_flags
|=INITED_STREAM
;
2856 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)mpctx
->stream
);
2859 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
2862 current_module
="handle_playlist";
2863 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
2864 filename_recode(filename
));
2865 entry
= parse_playtree(mpctx
->stream
,0);
2866 mpctx
->eof
=playtree_add_playlist(entry
);
2867 goto goto_next_file
;
2869 mpctx
->stream
->start_pos
+=seek_to_byte
;
2871 if(stream_dump_type
==5){
2872 unsigned char buf
[4096];
2875 current_module
="dumpstream";
2876 if(mpctx
->stream
->type
==STREAMTYPE_STREAM
&& mpctx
->stream
->fd
<0){
2877 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
2878 exit_player(MSGTR_Exit_error
);
2880 stream_reset(mpctx
->stream
);
2881 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
2882 f
=fopen(stream_dump_name
,"wb");
2884 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
2885 exit_player(MSGTR_Exit_error
);
2887 while(!mpctx
->stream
->eof
){
2888 len
=stream_read(mpctx
->stream
,buf
,4096);
2890 if(fwrite(buf
,len
,1,f
) != 1) {
2891 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2892 exit_player(MSGTR_Exit_error
);
2897 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
2898 exit_player(MSGTR_Exit_error
);
2900 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
2901 exit_player_with_rc(MSGTR_Exit_eof
, 0);
2905 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
2906 current_module
="dvd lang->id";
2907 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(mpctx
->stream
,audio_lang
);
2908 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
2909 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
2910 // setup global sub numbering
2911 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
2912 mpctx
->global_sub_size
+= dvd_number_of_subs(mpctx
->stream
);
2913 current_module
=NULL
;
2918 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
2919 current_module
="dvdnav lang->id";
2920 if(audio_id
==-1) audio_id
=dvdnav_aid_from_lang(mpctx
->stream
,audio_lang
);
2921 if(dvdsub_lang
&& dvdsub_id
==-2) dvdsub_id
=-1;
2922 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvdnav_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
2923 // setup global sub numbering
2924 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
2925 mpctx
->global_sub_size
+= dvdnav_number_of_subs(mpctx
->stream
);
2926 current_module
=NULL
;
2930 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
2932 if(stream_cache_size
>0){
2933 current_module
="enable_cache";
2934 if(!stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
2935 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
2936 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
2937 if((mpctx
->eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
2940 //============ Open DEMUXERS --- DETECT file type =======================
2941 current_module
="demux_open";
2943 mpctx
->demuxer
=demux_open(mpctx
->stream
,mpctx
->file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
2945 // HACK to get MOV Reference Files working
2947 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
2949 unsigned char* playlist_entry
;
2950 play_tree_t
*list
= NULL
, *entry
= NULL
;
2952 current_module
="handle_demux_playlist";
2953 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
2957 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
2958 filename_recode(playlist_entry
));
2960 bname
=mp_basename(playlist_entry
);
2961 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
2964 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
2967 entry
= play_tree_new();
2969 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
2971 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
2974 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
2975 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
2976 strcat(temp
, playlist_entry
);
2977 play_tree_add_file(entry
,temp
);
2978 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
2983 play_tree_add_file(entry
,playlist_entry
);
2988 play_tree_append_entry(list
,entry
);
2990 free_demuxer(mpctx
->demuxer
);
2991 mpctx
->demuxer
= NULL
;
2995 entry
= play_tree_new();
2996 play_tree_set_child(entry
,list
);
2997 mpctx
->eof
=playtree_add_playlist(entry
);
2998 goto goto_next_file
;
3003 goto goto_next_file
;
3004 inited_flags
|=INITED_DEMUXER
;
3006 if (mpctx
->stream
->type
!= STREAMTYPE_DVD
&& mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
) {
3008 // setup global sub numbering
3009 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3010 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
3011 if (mpctx
->demuxer
->s_streams
[i
])
3012 mpctx
->global_sub_size
++;
3014 if (mpctx
->global_sub_size
<= dvdsub_id
) mpctx
->global_sub_size
= dvdsub_id
+ 1;
3016 current_module
="demux_open2";
3018 //file_format=demuxer->file_format;
3020 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3021 mpctx
->d_video
=mpctx
->demuxer
->video
;
3022 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3025 if((stream_dump_type
)&&(stream_dump_type
<4)){
3027 demux_stream_t
*ds
=NULL
;
3028 current_module
="dump";
3029 // select stream to dump
3030 switch(stream_dump_type
){
3031 case 1: ds
=mpctx
->d_audio
;break;
3032 case 2: ds
=mpctx
->d_video
;break;
3033 case 3: ds
=mpctx
->d_sub
;break;
3036 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
3037 exit_player(MSGTR_Exit_error
);
3039 // disable other streams:
3040 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3041 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3042 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3044 f
=fopen(stream_dump_name
,"wb");
3046 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3047 exit_player(MSGTR_Exit_error
);
3050 unsigned char* start
;
3051 int in_size
=ds_get_packet(ds
,&start
);
3052 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3053 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3054 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3057 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3058 exit_player_with_rc(MSGTR_Exit_eof
, 0);
3061 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3062 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3064 if(mpctx
->sh_video
){
3066 current_module
="video_read_properties";
3067 if(!video_read_properties(mpctx
->sh_video
)) {
3068 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
3069 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3071 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3072 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3073 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3076 /* need to set fps here for output encoders to pick it up in their init */
3078 mpctx
->sh_video
->fps
=force_fps
;
3079 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3081 vo_fps
= mpctx
->sh_video
->fps
;
3083 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3084 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
3085 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3091 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3092 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
3093 #ifdef HAS_DVBIN_SUPPORT
3094 if((mpctx
->stream
->type
== STREAMTYPE_DVB
) && mpctx
->stream
->priv
)
3096 dvb_priv_t
*priv
= (dvb_priv_t
*) mpctx
->stream
->priv
;
3100 int v
= mpctx
->last_dvb_step
;
3102 dir
= DVB_CHANNEL_HIGHER
;
3104 dir
= DVB_CHANNEL_LOWER
;
3106 if(dvb_step_channel(priv
, dir
))
3107 mpctx
->eof
= mpctx
->dvbin_reopen
= 1;
3111 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3114 /* display clip info */
3115 demux_info_print(mpctx
->demuxer
);
3117 //================== Read SUBTITLES (DVD & TEXT) ==========================
3118 if(vo_spudec
==NULL
&& mpctx
->sh_video
&&
3119 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
|| mpctx
->d_sub
->id
>= 0)){
3123 // Apply current settings for forced subs
3124 if (vo_spudec
!=NULL
)
3125 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3127 if(mpctx
->sh_video
) {
3128 // after reading video params we should load subtitles because
3129 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3131 current_module
="read_subtitles_file";
3133 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3134 add_subtitles (sub_name
[i
], mpctx
->sh_video
->fps
, 0);
3136 if(sub_auto
) { // auto load sub file ...
3137 char *psub
= get_path( "sub/" );
3138 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
3140 free(psub
); // release the buffer created by get_path() above
3142 add_subtitles (tmp
[i
], mpctx
->sh_video
->fps
, 0);
3147 if (mpctx
->set_of_sub_size
> 0) {
3148 // setup global sub numbering
3149 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = mpctx
->global_sub_size
; // the global # of the first sub.
3150 mpctx
->global_sub_size
+= mpctx
->set_of_sub_size
;
3154 if (mpctx
->global_sub_size
) {
3155 // find the best sub to use
3156 if (vobsub_id
>= 0) {
3157 // if user asks for a vobsub id, use that first.
3158 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
3159 } else if (dvdsub_id
>= 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3160 // if user asks for a dvd sub id, use that next.
3161 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
3162 } else if (mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
3163 // if there are text subs to use, use those. (autosubs come last here)
3164 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
];
3166 } else if (mpctx->global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
3167 // if nothing else works, get subs from the demuxer.
3168 mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
3171 // nothing worth doing automatically.
3172 mpctx
->global_sub_pos
= -1;
3174 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3175 mpctx
->global_sub_pos
--;
3176 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
, mpctx
);
3178 switch (stream_dump_type
) {
3179 case 3: list_sub_file(subdata
); break;
3180 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
3181 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
3182 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
3183 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
3184 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
3188 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
3189 filename_recode(filename
));
3190 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
3191 if (mpctx
->sh_video
) {
3192 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3193 if (mpctx
->sh_video
->format
>= 0x20202020)
3194 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
3196 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
3197 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
3198 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
3199 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
3200 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
3201 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
3203 if (mpctx
->sh_audio
) {
3204 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3205 if (mpctx
->sh_audio
->format
>= 0x20202020)
3206 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
3208 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
3209 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
3210 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
3211 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
3213 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(mpctx
->demuxer
));
3215 if(!mpctx
->sh_video
) goto main
; // audio-only
3217 if(!reinit_video_chain()) {
3218 if(!mpctx
->sh_video
){
3219 if(!mpctx
->sh_audio
) goto goto_next_file
;
3220 goto main
; // exit_player(MSGTR_Exit_error);
3224 if(vo_flags
& 0x08 && vo_spudec
)
3225 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
3227 #ifdef HAVE_FREETYPE
3228 force_load_font
= 1;
3231 //================== MAIN: ==========================
3233 current_module
="main";
3236 char* msg
= property_expand_string(mpctx
, playing_msg
);
3237 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3242 // Disable the term OSD in verbose mode
3243 if(verbose
) term_osd
= 0;
3246 //int frame_corr_num=0; //
3247 //float v_frame=0; // Video
3248 float time_frame
=0; // Timer
3249 //float num_frames=0; // number of frames played
3251 int frame_time_remaining
=0; // flag
3253 mpctx
->num_buffered_frames
=0;
3255 // Make sure old OSD does not stay around,
3256 // e.g. with -fixed-vo and same-resolution files
3260 //================ SETUP AUDIO ==========================
3262 if(mpctx
->sh_audio
){
3263 reinit_audio_chain();
3264 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
3265 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
3268 current_module
="av_init";
3270 if(mpctx
->sh_video
){
3271 mpctx
->sh_video
->timer
=0;
3273 audio_delay
+= mpctx
->sh_video
->stream_delay
;
3275 if(mpctx
->sh_audio
){
3277 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
3278 mpctx
->delay
=-audio_delay
;
3281 if(!mpctx
->sh_audio
){
3282 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
3283 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
3284 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
3285 //mpctx->d_audio->id=-2; // do not read audio chunks
3286 //uninit_player(INITED_AO); // close device
3288 if(!mpctx
->sh_video
){
3289 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
3290 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
3291 ds_free_packs(mpctx
->d_video
);
3292 mpctx
->d_video
->id
=-2;
3293 //if(!fixed_vo) uninit_player(INITED_VO);
3296 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
3297 goto goto_next_file
;
3299 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3300 if(force_fps
&& mpctx
->sh_video
){
3301 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
3302 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3303 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
3308 if ( mpctx
->sh_audio
) guiIntfStruct
.AudioType
=mpctx
->sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
3309 if ( !mpctx
->sh_video
&& mpctx
->sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
3310 guiGetEvent( guiSetFileFormat
,(char *)mpctx
->demuxer
->file_format
);
3311 if ( guiGetEvent( guiSetValues
,(char *)mpctx
->sh_video
) ) goto goto_next_file
;
3312 guiGetEvent( guiSetDemuxer
,(char *)mpctx
->demuxer
);
3316 //==================== START PLAYING =======================
3318 if(loop_times
>1) loop_times
--; else
3319 if(loop_times
==1) loop_times
= -1;
3321 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);
3323 total_time_usage_start
=GetTimer();
3324 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3325 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3326 play_n_frames
=play_n_frames_mf
;
3328 if(play_n_frames
==0){
3329 mpctx
->eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
3333 seek(mpctx
, seek_to_sec
, 1);
3334 end_at
.pos
+= seek_to_sec
;
3337 if (end_at
.type
== END_AT_SIZE
) {
3338 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
3339 end_at
.type
= END_AT_NONE
;
3344 float aq_sleep_time
=0;
3345 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
3346 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
3347 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
3348 reinit_audio_chain();
3351 /*========================== PLAY AUDIO ============================*/
3353 if (mpctx
->sh_audio
)
3354 if (!fill_audio_out_buffers())
3355 // at eof, all audio at least written to ao
3356 if (!mpctx
->sh_video
)
3357 mpctx
->eof
= PT_NEXT_ENTRY
;
3360 if(!mpctx
->sh_video
) {
3361 // handle audio-only case:
3363 if(!quiet
|| end_at
.type
== END_AT_TIME
)
3364 a_pos
= playing_audio_pts(mpctx
->sh_audio
, mpctx
->d_audio
, mpctx
->audio_out
);
3367 print_status(a_pos
, 0, 0);
3369 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
3370 mpctx
->eof
= PT_NEXT_ENTRY
;
3375 /*========================== PLAY VIDEO ============================*/
3377 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
3378 vo_fps
=mpctx
->sh_video
->fps
;
3380 if (!mpctx
->num_buffered_frames
) {
3381 double frame_time
= update_video(&blit_frame
);
3382 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3383 if (mpctx
->sh_video
->vf_inited
< 0) {
3384 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
3385 mpctx
->eof
= 1; goto goto_next_file
;
3390 // might return with !eof && !blit_frame if !correct_pts
3391 mpctx
->num_buffered_frames
+= blit_frame
;
3392 time_frame
+= frame_time
/ playback_speed
; // for nosound
3396 // ==========================================================================
3398 // current_module="draw_osd";
3399 // if(vo_config_count) mpctx->video_out->draw_osd();
3402 if(use_gui
) guiEventHandling();
3405 current_module
="vo_check_events";
3406 if (vo_config_count
) mpctx
->video_out
->check_events();
3409 if (stop_xscreensaver
) {
3410 current_module
= "stop_xscreensaver";
3411 xscreensaver_heartbeat();
3415 frame_time_remaining
= sleep_until_update(&time_frame
, &aq_sleep_time
);
3417 //====================== FLIP PAGE (VIDEO BLT): =========================
3419 current_module
="flip_page";
3420 if (!frame_time_remaining
&& blit_frame
) {
3421 unsigned int t2
=GetTimer();
3423 if(vo_config_count
) mpctx
->video_out
->flip_page();
3424 mpctx
->num_buffered_frames
--;
3426 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
3428 //====================== A-V TIMESTAMP CORRECTION: =========================
3430 adjust_sync_and_print_status(frame_time_remaining
, time_frame
);
3432 //============================ Auto QUALITY ============================
3434 /*Output quality adjustments:*/
3436 current_module
="autoq";
3437 // float total=0.000001f * (GetTimer()-aq_total_time);
3438 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
3439 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
3442 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
3443 if(output_quality
>1 && aq_sleep_time
<0)
3446 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
3448 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
3449 set_video_quality(mpctx
->sh_video
,output_quality
);
3452 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
3454 if (play_n_frames
<= 0) mpctx
->eof
= PT_NEXT_ENTRY
;
3458 // FIXME: add size based support for -endpos
3459 if (end_at
.type
== END_AT_TIME
&&
3460 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
3461 mpctx
->eof
= PT_NEXT_ENTRY
;
3463 } // end if(mpctx->sh_video)
3466 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3468 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
3469 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
3470 vo_osd_changed (OSDTYPE_DVDNAV
);
3474 //============================ Handle PAUSE ===============================
3476 current_module
="pause";
3479 // 36000000 means max timed visibility is 1 hour into the future, if
3480 // the difference is greater assume it's wrapped around from below 0
3481 if (osd_visible
- GetTimerMS() > 36000000) {
3483 vo_osd_progbar_type
=-1; // disable
3484 vo_osd_changed(OSDTYPE_PROGBAR
);
3485 if (mpctx
->osd_function
!= OSD_PAUSE
)
3486 mpctx
->osd_function
= OSD_PLAY
;
3490 if (mpctx
->osd_function
== OSD_PAUSE
) {
3492 mpctx
->was_paused
= 1;
3497 mpctx
->osd_function
=OSD_FFW
;
3498 rel_seek_secs
+=step_sec
;
3503 //================= Keyboard events, SEEKing ====================
3505 current_module
="key_events";
3510 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
3511 brk_cmd
= run_command(mpctx
, cmd
);
3514 goto goto_enable_cache
;
3517 mpctx
->was_paused
= 0;
3520 if(mpctx
->eof
==1 && loop_times
>=0) {
3522 play_tree_iter_step(mpctx
->playtree_iter
,0,0);
3524 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,mpctx
->eof
);
3526 if(loop_times
>1) loop_times
--; else
3527 if(loop_times
==1) loop_times
=-1;
3528 play_n_frames
=play_n_frames_mf
;
3530 abs_seek_pos
=1; rel_seek_secs
=seek_to_sec
;
3534 if(rel_seek_secs
|| abs_seek_pos
){
3535 if (seek(mpctx
, rel_seek_secs
, abs_seek_pos
) >= 0) {
3539 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(mpctx
->demuxer
));
3541 // osd_function has been set (or not) by the code triggering the seek
3542 osd_visible
=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
3554 if(mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
&& mpctx
->sh_video
&& mpctx
->sh_video
->video
.dwLength
>2){
3555 // get pos from frame number / total frames
3556 guiIntfStruct
.Position
=(float)mpctx
->d_video
->pack_no
*100.0f
/mpctx
->sh_video
->video
.dwLength
;
3558 off_t len
= ( mpctx
->demuxer
->movi_end
- mpctx
->demuxer
->movi_start
);
3559 off_t pos
= ( mpctx
->demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?mpctx
->stream
->pos
:mpctx
->demuxer
->filepos
);
3560 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- mpctx
->demuxer
->movi_start
) * 100.0f
/ len
);
3562 if ( mpctx
->sh_video
) guiIntfStruct
.TimeSec
=mpctx
->sh_video
->pts
;
3563 else if ( mpctx
->sh_audio
) guiIntfStruct
.TimeSec
=mpctx
->delay
;
3564 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(mpctx
->demuxer
);
3565 guiGetEvent( guiReDraw
,NULL
);
3566 guiGetEvent( guiSetVolume
,NULL
);
3567 if(guiIntfStruct
.Playing
==0) break; // STOP
3568 if(guiIntfStruct
.Playing
==2) mpctx
->osd_function
=OSD_PAUSE
;
3569 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3571 if ( mpctx
->stream
->type
== STREAMTYPE_DVD
)
3573 dvd_priv_t
* dvdp
= mpctx
->stream
->priv
;
3574 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3578 #endif /* HAVE_NEW_GUI */
3580 } // while(!mpctx->eof)
3582 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->eof
);
3584 #ifdef HAS_DVBIN_SUPPORT
3585 if(mpctx
->dvbin_reopen
)
3588 uninit_player(INITED_ALL
-(INITED_GUI
|INITED_STREAM
|INITED_INPUT
|INITED_GETCH2
|(fixed_vo
?INITED_VO
:0)));
3589 cache_uninit(mpctx
->stream
);
3590 mpctx
->dvbin_reopen
= 0;
3591 goto goto_enable_cache
;
3596 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3598 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3601 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3602 double total_time_usage
;
3603 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3604 total_time_usage
= (float)total_time_usage_start
*0.000001;
3605 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3606 video_time_usage
,vout_time_usage
,audio_time_usage
,
3607 total_time_usage
-tot
,total_time_usage
);
3608 if(total_time_usage
>0.0)
3609 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3610 100.0*video_time_usage
/total_time_usage
,
3611 100.0*vout_time_usage
/total_time_usage
,
3612 100.0*audio_time_usage
/total_time_usage
,
3613 100.0*(total_time_usage
-tot
)/total_time_usage
,
3615 if(total_frame_cnt
&& frame_dropping
)
3616 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3617 total_frame_cnt
-drop_frame_cnt
,
3618 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3620 100*drop_frame_cnt
/total_frame_cnt
,
3622 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
3626 // time to uninit all, except global stuff:
3627 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
3629 if ( mpctx
->set_of_sub_size
> 0 )
3631 current_module
="sub_free";
3632 for (i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
3633 sub_free( mpctx
->set_of_subtitles
[i
] );
3635 if ( mpctx
->set_of_ass_tracks
[i
] )
3636 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
3639 mpctx
->set_of_sub_size
= 0;
3641 vo_sub_last
= vo_sub
=NULL
;
3647 if(mpctx
->eof
== PT_NEXT_ENTRY
|| mpctx
->eof
== PT_PREV_ENTRY
) {
3648 mpctx
->eof
= mpctx
->eof
== PT_NEXT_ENTRY
? 1 : -1;
3649 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
3652 play_tree_iter_free(mpctx
->playtree_iter
);
3653 mpctx
->playtree_iter
= NULL
;
3655 mpctx
->play_tree_step
= 1;
3656 } else if (mpctx
->eof
== PT_UP_NEXT
|| mpctx
->eof
== PT_UP_PREV
) {
3657 mpctx
->eof
= mpctx
->eof
== PT_UP_NEXT
? 1 : -1;
3658 if ( mpctx
->playtree_iter
) {
3659 if(play_tree_iter_up_step(mpctx
->playtree_iter
,mpctx
->eof
,0) == PLAY_TREE_ITER_ENTRY
) {
3662 play_tree_iter_free(mpctx
->playtree_iter
);
3663 mpctx
->playtree_iter
= NULL
;
3666 } else { // NEXT PREV SRC
3667 mpctx
->eof
= mpctx
->eof
== PT_PREV_SRC
? -1 : 1;
3670 if(mpctx
->eof
== 0) mpctx
->eof
= 1;
3672 while(mpctx
->playtree_iter
!= NULL
) {
3673 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,mpctx
->eof
);
3674 if(filename
== NULL
) {
3675 if( play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->eof
,0) != PLAY_TREE_ITER_ENTRY
) {
3676 play_tree_iter_free(mpctx
->playtree_iter
);
3677 mpctx
->playtree_iter
= NULL
;
3684 if( use_gui
&& !mpctx
->playtree_iter
)
3687 if ( !guiIntfStruct
.DiskChanged
)
3693 if(use_gui
|| mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
3694 if (!mpctx
->playtree_iter
) filename
= NULL
;
3696 goto play_next_file
;
3700 exit_player_with_rc(MSGTR_Exit_eof
, 0);