3 /// \ingroup Properties Command2Property OSDMsgStack
10 #if defined(__MINGW32__) || defined(__CYGWIN__)
11 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
17 // #include <sys/mman.h>
18 #include <sys/types.h>
20 #include <sys/ioctl.h>
23 #define SIGHUP 1 /* hangup */
24 #define SIGQUIT 3 /* quit */
25 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
26 #define SIGBUS 10 /* bus error */
27 #define SIGPIPE 13 /* broken pipe */
44 #define HELP_MP_DEFINE_STATIC
50 #include "access_mpcontext.h"
51 #include "m_property.h"
53 #include "cfg-mplayer-def.h"
55 #include "libavutil/intreadwrite.h"
57 #include "subreader.h"
60 #include "libvo/video_out.h"
62 #include "libvo/font_load.h"
63 #include "libvo/sub.h"
66 #include "libvo/x11_common.h"
69 #include "libao2/audio_out.h"
71 #include "codec-cfg.h"
78 #include "osdep/getch2.h"
79 #include "osdep/timer.h"
81 #include "cpudetect.h"
84 #include "gui/interface.h"
87 #include "input/input.h"
90 int player_idle_mode
=0;
92 int enable_mouse_movements
=0;
94 #if defined(__MINGW32__) || defined(__CYGWIN__)
95 char * proc_priority
=NULL
;
100 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
104 #include <linux/rtc.h>
107 #define RTC_IRQP_SET RTCIO_IRQP_SET
108 #define RTC_PIE_ON RTCIO_PIE_ON
109 #endif /* __linux__ */
110 #endif /* HAVE_RTC */
113 #include "stream/tv.h"
116 #include "stream/stream_radio.h"
120 #include "stream/dvbin.h"
121 #include "stream/cache2.h"
124 //**************************************************************************//
126 //**************************************************************************//
127 #include "playtree.h"
128 #include "playtreeparser.h"
130 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
131 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
133 //**************************************************************************//
135 //**************************************************************************//
136 #include "parser-cfg.h"
137 #include "parser-mpcmd.h"
139 //**************************************************************************//
141 //**************************************************************************//
143 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
145 #include "get_path.h"
147 //**************************************************************************//
148 //**************************************************************************//
149 // Input media streaming & demultiplexer:
150 //**************************************************************************//
152 static int max_framesize
=0;
154 #include "stream/stream.h"
155 #include "libmpdemux/demuxer.h"
156 #include "libmpdemux/stheader.h"
158 #ifdef CONFIG_DVDREAD
159 #include "stream/stream_dvd.h"
163 #include "stream/stream_dvdnav.h"
166 #include "libmpcodecs/dec_audio.h"
167 #include "libmpcodecs/dec_video.h"
168 #include "libmpcodecs/mp_image.h"
169 #include "libmpcodecs/vf.h"
170 #include "libmpcodecs/vd.h"
176 #include "defaultopts.h"
178 //**************************************************************************//
179 //**************************************************************************//
181 // Common FIFO functions, and keyboard/event FIFO code
183 int noconsolecontrols
=0;
184 //**************************************************************************//
187 double video_time_usage
=0;
188 double vout_time_usage
=0;
189 static double audio_time_usage
=0;
190 static int total_time_usage_start
=0;
191 static int total_frame_cnt
=0;
192 static int drop_frame_cnt
=0; // total number of dropped frames
197 static int output_quality
=0;
205 static int list_properties
= 0;
208 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
209 unsigned int osd_visible
;
210 int osd_duration
= 1000;
213 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
214 static char* playing_msg
= NULL
;
216 static double seek_to_sec
;
217 static off_t seek_to_byte
=0;
218 static off_t step_sec
=0;
219 static int loop_seek
=0;
221 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
224 int autosync
=0; // 30 might be a good default value.
227 char **audio_codec_list
=NULL
; // override audio codec
228 char **video_codec_list
=NULL
; // override video codec
229 char **audio_fm_list
=NULL
; // override audio codec family
230 char **video_fm_list
=NULL
; // override video codec family
233 extern char *demuxer_name
; // override demuxer
234 extern char *audio_demuxer_name
; // override audio demuxer
235 extern char *sub_demuxer_name
; // override sub demuxer
238 char* audio_lang
=NULL
;
239 char* dvdsub_lang
=NULL
;
240 static char* spudec_ifo
=NULL
;
241 int forced_subs_only
=0;
245 int stream_cache_size
=-1;
246 #ifdef CONFIG_STREAM_CACHE
247 extern int cache_fill_status
;
249 float stream_cache_min_percent
=20.0;
250 float stream_cache_seek_min_percent
=50.0;
252 #define cache_fill_status 0
256 static char *stream_dump_name
="stream.dump";
257 int stream_dump_type
=0;
260 static float default_max_pts_correction
=-1;//0.01f;
261 static float max_pts_correction
=0;//default_max_pts_correction;
262 static float c_total
=0;
264 static int ignore_start
=0;
266 static int softsleep
=0;
269 static int force_srate
=0;
270 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
271 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
272 static int play_n_frames
=-1;
273 static int play_n_frames_mf
=-1;
276 char *font_name
=NULL
;
277 char *sub_font_name
=NULL
;
278 extern int font_fontconfig
;
279 float font_factor
=0.75;
280 char **sub_name
=NULL
;
284 char *vobsub_name
=NULL
;
285 /*DSP!!char *dsp=NULL;*/
287 int suboverlap_enabled
= 1;
290 #include "libass/ass.h"
291 #include "libass/ass_mp.h"
294 char* current_module
=NULL
; // for debugging
300 #include "m_struct.h"
301 #include "libmenu/menu.h"
302 extern void vf_menu_pause_update(struct vf_instance
* vf
);
303 extern vf_info_t vf_info_menu
;
304 static const vf_info_t
* const libmenu_vfs
[] = {
308 static vf_instance_t
* vf_menu
= NULL
;
310 static char* menu_cfg
= NULL
;
311 static char* menu_root
= "main";
316 static int nortc
= 1;
317 static char* rtc_device
;
320 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
321 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
322 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
323 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
324 int use_filedir_conf
;
326 #include "mpcommon.h"
329 #include "metadata.h"
331 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
333 const void *mpctx_get_video_out(MPContext
*mpctx
)
335 return mpctx
->video_out
;
338 const void *mpctx_get_audio_out(MPContext
*mpctx
)
340 return mpctx
->audio_out
;
343 void *mpctx_get_demuxer(MPContext
*mpctx
)
345 return mpctx
->demuxer
;
348 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
350 return mpctx
->playtree_iter
;
353 void *mpctx_get_mixer(MPContext
*mpctx
)
355 return &mpctx
->mixer
;
358 int mpctx_get_global_sub_size(MPContext
*mpctx
)
360 return mpctx
->global_sub_size
;
363 int mpctx_get_osd_function(MPContext
*mpctx
)
365 return mpctx
->osd_function
;
368 static float get_relative_time(struct MPContext
*mpctx
)
370 unsigned int new_time
= GetTimer();
371 unsigned int delta
= new_time
- mpctx
->last_time
;
372 mpctx
->last_time
= new_time
;
373 return delta
* 0.000001;
376 static int is_valid_metadata_type(struct MPContext
*mpctx
, metadata_t type
) {
379 /* check for valid video stream */
380 case META_VIDEO_CODEC
:
381 case META_VIDEO_BITRATE
:
382 case META_VIDEO_RESOLUTION
:
384 if (!mpctx
->sh_video
)
389 /* check for valid audio stream */
390 case META_AUDIO_CODEC
:
391 case META_AUDIO_BITRATE
:
392 case META_AUDIO_SAMPLES
:
394 if (!mpctx
->sh_audio
)
399 /* check for valid demuxer */
400 case META_INFO_TITLE
:
401 case META_INFO_ARTIST
:
402 case META_INFO_ALBUM
:
404 case META_INFO_COMMENT
:
405 case META_INFO_TRACK
:
406 case META_INFO_GENRE
:
420 static char *get_demuxer_info(struct MPContext
*mpctx
, char *tag
) {
421 char **info
= mpctx
->demuxer
->info
;
427 for (n
= 0; info
[2*n
] != NULL
; n
++)
428 if (!strcmp (info
[2*n
], tag
))
431 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
434 char *get_metadata(struct MPContext
*mpctx
, metadata_t type
)
437 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
438 sh_video_t
* const sh_video
= mpctx
->sh_video
;
440 if (!is_valid_metadata_type(mpctx
, type
))
447 return strdup (mp_basename2 (mpctx
->filename
));
450 case META_VIDEO_CODEC
:
452 if (sh_video
->format
== 0x10000001)
453 meta
= strdup ("mpeg1");
454 else if (sh_video
->format
== 0x10000002)
455 meta
= strdup ("mpeg2");
456 else if (sh_video
->format
== 0x10000004)
457 meta
= strdup ("mpeg4");
458 else if (sh_video
->format
== 0x10000005)
459 meta
= strdup ("h264");
460 else if (sh_video
->format
>= 0x20202020)
463 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
468 sprintf (meta
, "0x%08X", sh_video
->format
);
473 case META_VIDEO_BITRATE
:
476 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
480 case META_VIDEO_RESOLUTION
:
483 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
487 case META_AUDIO_CODEC
:
489 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
490 meta
= strdup (sh_audio
->codec
->name
);
494 case META_AUDIO_BITRATE
:
497 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
501 case META_AUDIO_SAMPLES
:
504 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
508 /* check for valid demuxer */
509 case META_INFO_TITLE
:
510 return get_demuxer_info(mpctx
, "Title");
512 case META_INFO_ARTIST
:
513 return get_demuxer_info(mpctx
, "Artist");
515 case META_INFO_ALBUM
:
516 return get_demuxer_info(mpctx
, "Album");
519 return get_demuxer_info(mpctx
, "Year");
521 case META_INFO_COMMENT
:
522 return get_demuxer_info(mpctx
, "Comment");
524 case META_INFO_TRACK
:
525 return get_demuxer_info(mpctx
, "Track");
527 case META_INFO_GENRE
:
528 return get_demuxer_info(mpctx
, "Genre");
537 /// step size of mixer changes
541 static void mp_dvdnav_context_free(MPContext
*ctx
){
542 if (ctx
->nav_smpi
) free_mp_image(ctx
->nav_smpi
);
543 ctx
->nav_smpi
= NULL
;
544 if (ctx
->nav_buffer
) free(ctx
->nav_buffer
);
545 ctx
->nav_buffer
= NULL
;
546 ctx
->nav_start
= NULL
;
547 ctx
->nav_in_size
= 0;
551 void uninit_player(struct MPContext
*mpctx
, unsigned int mask
){
552 mask
=mpctx
->initialized_flags
&mask
;
554 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
556 if(mask
&INITIALIZED_ACODEC
){
557 mpctx
->initialized_flags
&=~INITIALIZED_ACODEC
;
558 current_module
="uninit_acodec";
559 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
561 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
563 mpctx
->sh_audio
=NULL
;
564 mpctx
->mixer
.afilter
= NULL
;
567 if(mask
&INITIALIZED_VCODEC
){
568 mpctx
->initialized_flags
&=~INITIALIZED_VCODEC
;
569 current_module
="uninit_vcodec";
570 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
571 mpctx
->sh_video
=NULL
;
577 if(mask
&INITIALIZED_DEMUXER
){
578 mpctx
->initialized_flags
&=~INITIALIZED_DEMUXER
;
579 current_module
="free_demuxer";
581 mpctx
->stream
=mpctx
->demuxer
->stream
;
582 free_demuxer(mpctx
->demuxer
);
587 // kill the cache process:
588 if(mask
&INITIALIZED_STREAM
){
589 mpctx
->initialized_flags
&=~INITIALIZED_STREAM
;
590 current_module
="uninit_stream";
591 if(mpctx
->stream
) free_stream(mpctx
->stream
);
595 if(mask
&INITIALIZED_VO
){
596 mpctx
->initialized_flags
&=~INITIALIZED_VO
;
597 current_module
="uninit_vo";
598 vo_destroy(mpctx
->video_out
);
599 mpctx
->video_out
=NULL
;
601 mp_dvdnav_context_free(mpctx
);
605 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
606 if(mask
&INITIALIZED_GETCH2
){
607 mpctx
->initialized_flags
&=~INITIALIZED_GETCH2
;
608 current_module
="uninit_getch2";
609 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
614 if(mask
&INITIALIZED_VOBSUB
){
615 mpctx
->initialized_flags
&=~INITIALIZED_VOBSUB
;
616 current_module
="uninit_vobsub";
617 if(vo_vobsub
) vobsub_close(vo_vobsub
);
621 if (mask
&INITIALIZED_SPUDEC
){
622 mpctx
->initialized_flags
&=~INITIALIZED_SPUDEC
;
623 current_module
="uninit_spudec";
624 spudec_free(vo_spudec
);
628 if(mask
&INITIALIZED_AO
){
629 mpctx
->initialized_flags
&=~INITIALIZED_AO
;
630 current_module
="uninit_ao";
631 if (mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
632 mpctx
->audio_out
->uninit(mpctx
->stop_play
!= AT_END_OF_FILE
);
633 mpctx
->audio_out
=NULL
;
637 if(mask
&INITIALIZED_GUI
){
638 mpctx
->initialized_flags
&=~INITIALIZED_GUI
;
639 current_module
="uninit_gui";
647 void exit_player_with_rc(struct MPContext
*mpctx
, const char* how
, int rc
){
649 if (mpctx
->user_muted
&& !mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
650 uninit_player(mpctx
, INITIALIZED_ALL
);
651 #if defined(__MINGW32__) || defined(__CYGWIN__)
658 vo_uninit(mpctx
->x11_state
); // Close the X11 connection (if any is open).
661 current_module
="uninit_input";
662 mp_input_uninit(mpctx
->input
);
668 #ifdef CONFIG_FREETYPE
669 current_module
="uninit_font";
670 if (mpctx
->osd
&& mpctx
->osd
->sub_font
!= vo_font
)
671 free_font_desc(mpctx
->osd
->sub_font
);
672 free_font_desc(vo_font
);
676 osd_free(mpctx
->osd
);
679 ass_library_done(ass_library
);
682 current_module
="exit_player";
684 // free mplayer config
686 m_config_free(mpctx
->mconfig
);
689 play_tree_free(mpctx
->playtree
, 1);
691 talloc_free(mpctx
->key_fifo
);
693 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
694 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
695 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
700 static void exit_player(struct MPContext
*mpctx
, const char* how
)
702 exit_player_with_rc(mpctx
, how
, 1);
706 static void child_sighandler(int x
){
708 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
712 #ifdef CONFIG_CRASH_DEBUG
713 static char *prog_path
;
714 static int crash_debug
= 0;
717 static void exit_sighandler(int x
){
718 static int sig_count
=0;
719 #ifdef CONFIG_CRASH_DEBUG
720 if (!crash_debug
|| x
!= SIGTRAP
)
725 /* We're crashing bad and can't uninit cleanly :(
726 * by popular request, we make one last (dirty)
727 * effort to restore the user's
732 if(sig_count
==6) exit(1);
736 kill(getpid(),SIGKILL
);
739 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
740 current_module
?current_module
:"unknown"
742 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
749 async_quit_request
= 1;
750 return; // killed from keyboard (^C) or killed [-9]
752 #ifdef RUNTIME_CPUDETECT
753 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
755 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
759 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
761 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
762 #ifdef CONFIG_CRASH_DEBUG
765 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
767 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
768 if (gdb_pid
== 0) { // We are the child
770 snprintf(spid
, sizeof(spid
), "%i", getppid());
771 getch2_disable(); // allow terminal to work properly with gdb
772 if (execlp("gdb", "gdb", prog_path
, spid
, "-ex", "bt", NULL
) == -1)
773 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
774 } else if (gdb_pid
< 0)
775 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
777 waitpid(gdb_pid
, NULL
, 0);
779 if (x
== SIGTRAP
) return;
787 #include "cfg-mplayer.h"
789 static int cfg_include(m_option_t
*conf
, char *filename
)
791 return m_config_parse_config_file(conf
->priv
, filename
);
794 static void parse_cfgfiles(struct MPContext
*mpctx
, m_config_t
* conf
)
798 if (!disable_system_conf
&&
799 m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
800 exit_player(mpctx
, NULL
);
801 if ((conffile
= get_path("")) == NULL
) {
802 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
807 mkdir(conffile
, 0777);
810 if ((conffile
= get_path("config")) == NULL
) {
811 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
813 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
814 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
815 write(conffile_fd
, default_config
, strlen(default_config
));
818 if (!disable_user_conf
&&
819 m_config_parse_config_file(conf
, conffile
) < 0)
820 exit_player(mpctx
, NULL
);
826 #define PROFILE_CFG_PROTOCOL "protocol."
828 static void load_per_protocol_config (m_config_t
* conf
, const char *const file
)
831 char protocol
[strlen (PROFILE_CFG_PROTOCOL
) + strlen (file
) + 1];
834 /* does filename actually uses a protocol ? */
835 str
= strstr (file
, "://");
839 sprintf (protocol
, "%s%s", PROFILE_CFG_PROTOCOL
, file
);
840 protocol
[strlen (PROFILE_CFG_PROTOCOL
)+strlen(file
)-strlen(str
)] = '\0';
841 p
= m_config_get_profile (conf
, protocol
);
844 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingProtocolProfile
, protocol
);
845 m_config_set_profile(conf
,p
);
849 #define PROFILE_CFG_EXTENSION "extension."
851 static void load_per_extension_config (m_config_t
* conf
, const char *const file
)
854 char extension
[strlen (PROFILE_CFG_EXTENSION
) + 8];
857 /* does filename actually have an extension ? */
858 str
= strrchr (file
, '.');
862 sprintf (extension
, PROFILE_CFG_EXTENSION
);
863 strncat (extension
, ++str
, 7);
864 p
= m_config_get_profile (conf
, extension
);
867 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingExtensionProfile
, extension
);
868 m_config_set_profile(conf
,p
);
872 #define PROFILE_CFG_VO "vo."
873 #define PROFILE_CFG_AO "ao."
875 static void load_per_output_config (m_config_t
* conf
, char *cfg
, char *out
)
877 char profile
[strlen (cfg
) + strlen (out
) + 1];
880 sprintf (profile
, "%s%s", cfg
, out
);
881 p
= m_config_get_profile (conf
, profile
);
884 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingExtensionProfile
, profile
);
885 m_config_set_profile(conf
,p
);
889 static void load_per_file_config (m_config_t
* conf
, const char *const file
)
892 char cfg
[strlen(file
)+10];
896 sprintf (cfg
, "%s.conf", file
);
898 if (use_filedir_conf
&& !stat (cfg
, &st
))
900 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
901 m_config_parse_config_file (conf
, cfg
);
905 if ((name
= strrchr (cfg
, '/')) == NULL
)
910 if ((confpath
= get_path (name
)) != NULL
)
912 if (!stat (confpath
, &st
))
914 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
915 m_config_parse_config_file (conf
, confpath
);
922 /* When libmpdemux performs a blocking operation (network connection or
923 * cache filling) if the operation fails we use this function to check
924 * if it was interrupted by the user.
925 * The function returns a new value for eof. */
926 static int libmpdemux_was_interrupted(struct MPContext
*mpctx
, int stop_play
)
929 if((cmd
= mp_input_get_cmd(mpctx
->input
, 0,0,0)) != NULL
) {
932 exit_player_with_rc(mpctx
, MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
933 case MP_CMD_PLAY_TREE_STEP
: {
934 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
935 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
937 case MP_CMD_PLAY_TREE_UP_STEP
: {
938 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
940 case MP_CMD_PLAY_ALT_SRC_STEP
: {
941 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
949 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
951 static int playtree_add_playlist(struct MPContext
*mpctx
, play_tree_t
* entry
)
953 play_tree_add_bpf(entry
,mpctx
->filename
);
958 import_playtree_playlist_into_gui(entry
, mpctx
->mconfig
);
959 play_tree_free_list(entry
,1);
965 entry
= mpctx
->playtree_iter
->tree
;
966 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
967 return PT_NEXT_ENTRY
;
969 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
970 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
971 return PT_NEXT_ENTRY
;
974 play_tree_remove(entry
,1,1);
977 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
978 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
979 entry
= mpctx
->playtree_iter
->tree
;
980 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
981 return PT_NEXT_ENTRY
;
983 play_tree_remove(entry
,1,1);
988 void add_subtitles(struct MPContext
*mpctx
, char *filename
, float fps
, int noerr
)
992 ass_track_t
*asst
= 0;
995 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
999 subd
= sub_read_file(filename
, fps
);
1003 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
1005 asst
= ass_read_file(ass_library
, filename
, 0);
1007 if (ass_enabled
&& subd
&& !asst
)
1008 asst
= ass_read_subdata(ass_library
, subd
, fps
);
1014 mp_msg(MSGT_CPLAYER
, noerr
? MSGL_WARN
: MSGL_ERR
, MSGTR_CantLoadSub
,
1015 filename_recode(filename
));
1018 if (!asst
&& !subd
) return;
1019 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
1023 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
1024 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
1025 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
1026 filename_recode(filename
));
1027 ++mpctx
->set_of_sub_size
;
1028 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, mpctx
->set_of_sub_size
,
1029 filename_recode(filename
));
1032 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1033 void update_set_of_subtitles(struct MPContext
*mpctx
)
1034 // subdata was changed, set_of_sub... have to be updated.
1036 sub_data
** const set_of_subtitles
= mpctx
->set_of_subtitles
;
1038 if (mpctx
->set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
1039 for (i
= mpctx
->set_of_sub_pos
+ 1; i
< mpctx
->set_of_sub_size
; ++i
)
1040 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
1041 set_of_subtitles
[mpctx
->set_of_sub_size
-1] = NULL
;
1042 --mpctx
->set_of_sub_size
;
1043 if (mpctx
->set_of_sub_size
> 0) subdata
= set_of_subtitles
[mpctx
->set_of_sub_pos
=0];
1045 else if (mpctx
->set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
1046 set_of_subtitles
[mpctx
->set_of_sub_pos
] = subdata
;
1048 else if (mpctx
->set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
1049 set_of_subtitles
[mpctx
->set_of_sub_pos
=mpctx
->set_of_sub_size
] = subdata
;
1050 ++mpctx
->set_of_sub_size
;
1054 void init_vo_spudec(struct MPContext
*mpctx
)
1057 spudec_free(vo_spudec
);
1058 mpctx
->initialized_flags
&= ~INITIALIZED_SPUDEC
;
1061 unsigned int palette
[16], width
, height
;
1062 current_module
="spudec_init_vobsub";
1063 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1064 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1067 #ifdef CONFIG_DVDREAD
1068 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1069 current_module
="spudec_init_dvdread";
1070 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1071 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1075 #ifdef CONFIG_DVDNAV
1076 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1077 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1078 current_module
="spudec_init_dvdnav";
1079 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1083 if ((vo_spudec
== NULL
) && (mpctx
->demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1084 (mpctx
->d_sub
->sh
!= NULL
) && (((sh_sub_t
*)mpctx
->d_sub
->sh
)->type
== 'v')) {
1085 sh_sub_t
*mkv_sh_sub
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1086 current_module
= "spudec_init_matroska";
1088 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1089 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1090 mkv_sh_sub
->height
);
1091 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1094 if (vo_spudec
==NULL
) {
1095 sh_sub_t
*sh
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1096 unsigned int *palette
= NULL
;
1097 if (sh
&& !sh
->has_palette
&& sh
->extradata_len
== 16*4) {
1099 for (i
= 0; i
< 16; i
++)
1100 sh
->palette
[i
] = AV_RB32(sh
->extradata
+ i
*4);
1101 sh
->has_palette
= 1;
1103 if (sh
&& sh
->has_palette
)
1104 palette
= sh
->palette
;
1105 current_module
="spudec_init_normal";
1106 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
);
1107 spudec_set_font_factor(vo_spudec
,font_factor
);
1110 if (vo_spudec
!=NULL
)
1111 mpctx
->initialized_flags
|=INITIALIZED_SPUDEC
;
1115 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1116 * make it all work is to use the builtin SDL-bootstrap code, which
1117 * will be done automatically by replacing our main() if we include SDL.h.
1119 #if defined(__APPLE__) && defined(CONFIG_SDL)
1124 * \brief append a formatted string
1125 * \param buf buffer to print into
1126 * \param pos position of terminating 0 in buf
1127 * \param len maximum number of characters in buf, not including terminating 0
1128 * \param format printf format string
1130 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1133 va_start(va
, format
);
1134 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1143 * \brief append time in the hh:mm:ss.f format
1144 * \param buf buffer to print into
1145 * \param pos position of terminating 0 in buf
1146 * \param len maximum number of characters in buf, not including terminating 0
1147 * \param time time value to convert/append
1149 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1150 long tenths
= 10 * time
;
1151 int f1
= tenths
% 10;
1152 int ss
= (tenths
/ 10) % 60;
1153 int mm
= (tenths
/ 600) % 60;
1154 int hh
= tenths
/ 36000;
1156 saddf(buf
, pos
, len
, "unknown");
1160 saddf(buf
, pos
, len
, "%2d:", hh
);
1161 if (hh
> 0 || mm
> 0)
1162 saddf(buf
, pos
, len
, "%02d:", mm
);
1163 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1167 * \brief print the status line
1168 * \param a_pos audio position
1169 * \param a_v A-V desynchronization
1170 * \param corr amount out A-V synchronization
1172 static void print_status(struct MPContext
*mpctx
, float a_pos
, float a_v
, float corr
)
1174 struct MPOpts
*opts
= &mpctx
->opts
;
1175 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1180 if (screen_width
> 0)
1181 width
= screen_width
;
1184 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
1185 /* Windows command line is broken (MinGW's rxvt works, but we
1186 * should not depend on that). */
1189 line
= malloc(width
+ 1); // one additional char for the terminating null
1192 if (mpctx
->sh_audio
) {
1193 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1195 float len
= demuxer_get_time_length(mpctx
->demuxer
);
1196 saddf(line
, &pos
, width
, "(");
1197 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1198 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1199 sadd_hhmmssf(line
, &pos
, width
, len
);
1200 saddf(line
, &pos
, width
, ") ");
1206 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1209 if (mpctx
->sh_audio
&& sh_video
)
1210 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
1214 saddf(line
, &pos
, width
, "%3d/%3d ",
1215 (int)sh_video
->num_frames
,
1216 (int)sh_video
->num_frames_decoded
);
1220 if (sh_video
->timer
> 0.5)
1221 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1222 (int)(100.0*video_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1223 (int)(100.0*vout_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1224 (100.0*audio_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
));
1226 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1227 } else if (mpctx
->sh_audio
) {
1228 if (mpctx
->delay
> 0.5)
1229 saddf(line
, &pos
, width
, "%4.1f%% ",
1230 100.0*audio_time_usage
/(double)mpctx
->delay
);
1232 saddf(line
, &pos
, width
, "??,?%% ");
1237 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1239 #ifdef CONFIG_STREAM_CACHE
1241 if (stream_cache_size
> 0)
1242 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1246 if (opts
->playback_speed
!= 1)
1247 saddf(line
, &pos
, width
, "%4.2fx ", opts
->playback_speed
);
1250 if (erase_to_end_of_line
) {
1252 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1254 memset(&line
[pos
], ' ', width
- pos
);
1256 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s\r", line
);
1262 * \brief build a chain of audio filters that converts the input format
1263 * to the ao's format, taking into account the current playback_speed.
1264 * \param sh_audio describes the requested input format of the chain.
1265 * \param ao_data describes the requested output format of the chain.
1267 int build_afilter_chain(struct MPContext
*mpctx
, sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1269 struct MPOpts
*opts
= &mpctx
->opts
;
1275 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
1277 mpctx
->mixer
.afilter
= NULL
;
1280 if(af_control_any_rev(sh_audio
->afilter
,
1281 AF_CONTROL_PLAYBACK_SPEED
| AF_CONTROL_SET
,
1282 &opts
->playback_speed
)) {
1283 new_srate
= sh_audio
->samplerate
;
1285 new_srate
= sh_audio
->samplerate
* opts
->playback_speed
;
1286 if (new_srate
!= ao_data
->samplerate
) {
1287 // limits are taken from libaf/af_resample.c
1288 if (new_srate
< 8000)
1290 if (new_srate
> 192000)
1292 opts
->playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1295 result
= init_audio_filters(sh_audio
, new_srate
,
1296 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
);
1297 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1299 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
1305 typedef struct mp_osd_msg mp_osd_msg_t
;
1307 /// Previous message on the stack.
1311 int id
,level
,started
;
1312 /// Display duration in ms.
1316 /// OSD message stack.
1317 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1320 * \brief Add a message on the OSD message stack
1322 * If a message with the same id is already present in the stack
1323 * it is pulled on top of the stack, otherwise a new message is created.
1327 void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1328 mp_osd_msg_t
*msg
,*last
=NULL
;
1332 // look if the id is already in the stack
1333 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1334 last
= msg
, msg
= msg
->prev
);
1335 // not found: alloc it
1337 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1338 msg
->prev
= osd_msg_stack
;
1339 osd_msg_stack
= msg
;
1340 } else if(last
) { // found, but it's not on top of the stack
1341 last
->prev
= msg
->prev
;
1342 msg
->prev
= osd_msg_stack
;
1343 osd_msg_stack
= msg
;
1347 r
= vsnprintf(msg
->msg
, 64, fmt
, va
);
1349 if(r
>= 64) msg
->msg
[63] = 0;
1358 * \brief Remove a message from the OSD stack
1360 * This function can be used to get rid of a message right away.
1364 void rm_osd_msg(int id
) {
1365 mp_osd_msg_t
*msg
,*last
=NULL
;
1367 // Search for the msg
1368 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1369 last
= msg
, msg
= msg
->prev
);
1372 // Detach it from the stack and free it
1374 last
->prev
= msg
->prev
;
1376 osd_msg_stack
= msg
->prev
;
1381 * \brief Remove all messages from the OSD stack
1385 static void clear_osd_msgs(void) {
1386 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1392 osd_msg_stack
= NULL
;
1396 * \brief Get the current message from the OSD stack.
1398 * This function decrements the message timer and destroys the old ones.
1399 * The message that should be displayed is returned (if any).
1403 static mp_osd_msg_t
* get_osd_msg(struct MPContext
*mpctx
)
1405 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1406 static unsigned last_update
= 0;
1407 unsigned now
= GetTimerMS();
1409 char hidden_dec_done
= 0;
1412 // 36000000 means max timed visibility is 1 hour into the future, if
1413 // the difference is greater assume it's wrapped around from below 0
1414 if (osd_visible
- now
> 36000000) {
1416 vo_osd_progbar_type
= -1; // disable
1417 vo_osd_changed(OSDTYPE_PROGBAR
);
1418 if (mpctx
->osd_function
!= OSD_PAUSE
)
1419 mpctx
->osd_function
= OSD_PLAY
;
1423 if(!last_update
) last_update
= now
;
1424 diff
= now
>= last_update
? now
- last_update
: 0;
1428 // Look for the first message in the stack with high enough level.
1429 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1431 if(msg
->level
> osd_level
&& hidden_dec_done
) continue;
1432 // The message has a high enough level or it is the first hidden one
1433 // in both cases we decrement the timer or kill it.
1434 if(!msg
->started
|| msg
->time
> diff
) {
1435 if(msg
->started
) msg
->time
-= diff
;
1436 else msg
->started
= 1;
1438 if(msg
->level
<= osd_level
) return msg
;
1439 hidden_dec_done
= 1;
1448 osd_msg_stack
= prev
;
1457 * \brief Display the OSD bar.
1459 * Display the OSD bar or fall back on a simple message.
1463 void set_osd_bar(struct MPContext
*mpctx
, int type
,const char* name
,double min
,double max
,double val
) {
1465 if(osd_level
< 1) return;
1467 if(mpctx
->sh_video
) {
1468 osd_visible
= (GetTimerMS() + 1000) | 1;
1469 vo_osd_progbar_type
= type
;
1470 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1471 vo_osd_changed(OSDTYPE_PROGBAR
);
1475 set_osd_msg(OSD_MSG_BAR
,1,osd_duration
,"%s: %d %%",
1476 name
,ROUND(100*(val
-min
)/(max
-min
)));
1481 * \brief Update the OSD message line.
1483 * This function displays the current message on the vo OSD or on the term.
1484 * If the stack is empty and the OSD level is high enough the timer
1485 * is displayed (only on the vo OSD).
1489 static void update_osd_msg(struct MPContext
*mpctx
)
1492 struct osd_state
*osd
= mpctx
->osd
;
1493 char osd_text_timer
[64];
1495 // Look if we have a msg
1496 if((msg
= get_osd_msg(mpctx
))) {
1497 if (strcmp(osd
->osd_text
, msg
->msg
)) {
1498 strncpy(osd
->osd_text
, msg
->msg
, 63);
1499 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1500 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1505 if(mpctx
->sh_video
) {
1506 // fallback on the timer
1508 int len
= demuxer_get_time_length(mpctx
->demuxer
);
1509 int percentage
= -1;
1510 char percentage_text
[10];
1511 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1513 if (mpctx
->osd_show_percentage
)
1514 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1516 if (percentage
>= 0)
1517 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1519 percentage_text
[0] = 0;
1522 snprintf(osd_text_timer
, 63,
1523 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1524 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1525 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1527 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1528 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1529 pts
%60,percentage_text
);
1531 osd_text_timer
[0]=0;
1533 // always decrement the percentage timer
1534 if(mpctx
->osd_show_percentage
)
1535 mpctx
->osd_show_percentage
--;
1537 if (strcmp(osd
->osd_text
, osd_text_timer
)) {
1538 strncpy(osd
->osd_text
, osd_text_timer
, 63);
1539 vo_osd_changed(OSDTYPE_OSD
);
1544 // Clear the term osd line
1545 if (term_osd
&& osd
->osd_text
[0]) {
1546 osd
->osd_text
[0] = 0;
1547 printf("%s\n",term_osd_esc
);
1555 void reinit_audio_chain(struct MPContext
*mpctx
)
1557 struct MPOpts
*opts
= &mpctx
->opts
;
1558 if(mpctx
->sh_audio
){
1559 current_module
="init_audio_codec";
1560 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1561 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1562 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // failed to init :(
1563 mpctx
->d_audio
->id
= -2;
1566 mpctx
->initialized_flags
|=INITIALIZED_ACODEC
;
1567 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1570 //const ao_info_t *info=audio_out->info;
1571 current_module
="af_preinit";
1572 ao_data
.samplerate
=force_srate
;
1574 ao_data
.format
=audio_output_format
;
1576 // first init to detect best values
1577 if(!init_audio_filters(mpctx
->sh_audio
, // preliminary init
1579 mpctx
->sh_audio
->samplerate
,
1581 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1582 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
1583 exit_player(mpctx
, MSGTR_Exit_error
);
1586 current_module
="ao2_init";
1587 if(!(mpctx
->audio_out
=init_best_audio_out(opts
->audio_driver_list
,
1591 ao_data
.format
,0))){
1593 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1594 uninit_player(mpctx
, INITIALIZED_ACODEC
); // close codec
1595 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1596 mpctx
->d_audio
->id
= -2;
1600 mpctx
->initialized_flags
|=INITIALIZED_AO
;
1601 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1602 mpctx
->audio_out
->info
->short_name
,
1603 ao_data
.samplerate
, ao_data
.channels
,
1604 af_fmt2str_short(ao_data
.format
),
1605 af_fmt2bits(ao_data
.format
)/8 );
1606 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1607 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1608 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1609 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1610 // init audio filters:
1612 current_module
="af_init";
1613 if(!build_afilter_chain(mpctx
, mpctx
->sh_audio
, &ao_data
)) {
1614 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
1615 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1616 // uninit_player(mpctx, INITIALIZED_ACODEC|INITIALIZED_AO); // close codec & ao
1617 // sh_audio=mpctx->d_audio->sh=NULL; // -> nosound
1621 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1622 mpctx
->mixer
.volstep
= volstep
;
1631 // Return pts value corresponding to the end point of audio written to the
1633 static double written_audio_pts(struct MPContext
*mpctx
)
1635 sh_audio_t
*sh_audio
= mpctx
->sh_audio
;
1636 demux_stream_t
*d_audio
= mpctx
->d_audio
;
1637 double buffered_output
;
1638 // first calculate the end pts of audio that has been output by decoder
1639 double a_pts
= sh_audio
->pts
;
1640 if (a_pts
!= MP_NOPTS_VALUE
)
1641 // Good, decoder supports new way of calculating audio pts.
1642 // sh_audio->pts is the timestamp of the latest input packet with
1643 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1644 // the amount of bytes the decoder has written after that timestamp.
1645 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1647 // Decoder doesn't support new way of calculating pts (or we're
1648 // being called before it has decoded anything with known timestamp).
1649 // Use the old method of audio pts calculation: take the timestamp
1650 // of last packet with known pts the decoder has read data from,
1651 // and add amount of bytes read after the beginning of that packet
1652 // divided by input bps. This will be inaccurate if the input/output
1653 // ratio is not constant for every audio packet or if it is constant
1654 // but not accurately known in sh_audio->i_bps.
1656 a_pts
= d_audio
->pts
;
1657 // ds_tell_pts returns bytes read after last timestamp from
1658 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1659 // it has read but not decoded
1660 if (sh_audio
->i_bps
)
1661 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1662 (double)sh_audio
->i_bps
;
1664 // Now a_pts hopefully holds the pts for end of audio from decoder.
1665 // Substract data in buffers between decoder and audio out.
1667 // Decoded but not filtered
1668 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1670 // Data buffered in audio filters, measured in bytes of "missing" output
1671 buffered_output
= af_calc_delay(sh_audio
->afilter
);
1673 // Data that was ready for ao but was buffered because ao didn't fully
1674 // accept everything to internal buffers yet
1675 buffered_output
+= sh_audio
->a_out_buffer_len
;
1677 // Filters divide audio length by playback_speed, so multiply by it
1678 // to get the length in original units without speedup or slowdown
1679 a_pts
-= buffered_output
* mpctx
->opts
.playback_speed
/ ao_data
.bps
;
1684 // Return pts value corresponding to currently playing audio.
1685 double playing_audio_pts(struct MPContext
*mpctx
)
1687 return written_audio_pts(mpctx
) - mpctx
->opts
.playback_speed
*
1688 mpctx
->audio_out
->get_delay();
1691 static int check_framedrop(struct MPContext
*mpctx
, double frame_time
) {
1692 struct MPOpts
*opts
= &mpctx
->opts
;
1693 // check for frame-drop:
1694 current_module
= "check_framedrop";
1695 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1696 static int dropped_frames
;
1697 float delay
= opts
->playback_speed
*mpctx
->audio_out
->get_delay();
1698 float d
= delay
-mpctx
->delay
;
1700 // we should avoid dropping too many frames in sequence unless we
1701 // are too late. and we allow 100ms A-V delay here:
1702 if (d
< -dropped_frames
*frame_time
-0.100 &&
1703 mpctx
->osd_function
!= OSD_PAUSE
) {
1706 return frame_dropping
;
1713 static int generate_video_frame(struct MPContext
*mpctx
)
1715 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1716 demux_stream_t
*d_video
= mpctx
->d_video
;
1718 unsigned char *start
;
1724 int drop_frame
= check_framedrop(mpctx
, sh_video
->frametime
);
1725 void *decoded_frame
;
1726 current_module
= "decode video";
1727 // XXX Time used in this call is not counted in any performance
1728 // timer now, OSD is not updated correctly for filter-added frames
1729 if (vf_output_queued_frame(sh_video
->vfilter
))
1731 current_module
= "video_read_frame";
1732 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
1734 // try to extract last frames in case of decoder lag
1739 if (in_size
> max_framesize
)
1740 max_framesize
= in_size
;
1741 current_module
= "decode video";
1742 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
, pts
);
1743 if (decoded_frame
) {
1744 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
1745 update_teletext(sh_video
, mpctx
->demuxer
, 0);
1746 update_osd_msg(mpctx
);
1747 current_module
= "filter video";
1748 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
,
1751 } else if (drop_frame
)
1763 static float timing_sleep(struct MPContext
*mpctx
, float time_frame
)
1767 // -------- RTC -----------
1768 current_module
="sleep_rtc";
1769 while (time_frame
> 0.000) {
1770 unsigned long rtc_ts
;
1771 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1772 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
1773 time_frame
-= get_relative_time(mpctx
);
1778 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1779 // unnecessarily high CPU usage
1780 float margin
= softsleep
? 0.011 : 0;
1781 current_module
= "sleep_timer";
1782 while (time_frame
> margin
) {
1783 usec_sleep(1000000 * (time_frame
- margin
));
1784 time_frame
-= get_relative_time(mpctx
);
1787 current_module
= "sleep_soft";
1789 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
1790 while (time_frame
> 0)
1791 time_frame
-= get_relative_time(mpctx
); // burn the CPU
1797 #ifdef CONFIG_DVDNAV
1801 /// store decoded video image
1802 static mp_image_t
* mp_dvdnav_copy_mpi(mp_image_t
*to_mpi
,
1803 mp_image_t
*from_mpi
) {
1806 /// Do not store B-frames
1807 if (from_mpi
->pict_type
== FF_B_TYPE
)
1811 to_mpi
->w
== from_mpi
->w
&&
1812 to_mpi
->h
== from_mpi
->h
&&
1813 to_mpi
->imgfmt
== from_mpi
->imgfmt
)
1817 free_mp_image(to_mpi
);
1818 if (from_mpi
->w
== 0 || from_mpi
->h
== 0)
1820 mpi
= alloc_mpi(from_mpi
->w
,from_mpi
->h
,from_mpi
->imgfmt
);
1823 copy_mpi(mpi
,from_mpi
);
1827 static void mp_dvdnav_reset_stream (MPContext
*ctx
) {
1828 struct MPOpts
*opts
= &ctx
->opts
;
1829 if (ctx
->sh_video
) {
1831 ctx
->d_video
->pts
= 0.0f
;
1832 ctx
->sh_video
->pts
= 0.0f
;
1833 ctx
->sh_video
->i_pts
= 0.0f
;
1834 ctx
->sh_video
->last_pts
= 0.0f
;
1835 ctx
->sh_video
->num_buffered_pts
= 0;
1836 ctx
->sh_video
->num_frames
= 0;
1837 ctx
->sh_video
->num_frames_decoded
= 0;
1838 ctx
->sh_video
->timer
= 0.0f
;
1839 ctx
->sh_video
->stream_delay
= 0.0f
;
1840 ctx
->sh_video
->timer
= 0;
1841 ctx
->demuxer
->stream_pts
= MP_NOPTS_VALUE
;
1844 if (ctx
->sh_audio
) {
1845 /// free audio packets and reset
1846 ds_free_packs(ctx
->d_audio
);
1847 audio_delay
-= ctx
->sh_audio
->stream_delay
;
1848 ctx
->delay
=- audio_delay
;
1849 ctx
->audio_out
->reset();
1850 resync_audio_stream(ctx
->sh_audio
);
1853 if (ctx
->d_sub
) opts
->sub_id
= -2;
1857 /// clear all EOF related flags
1858 ctx
->d_video
->eof
= ctx
->d_audio
->eof
= ctx
->stream
->eof
= 0;
1861 /// Restore last decoded DVDNAV (still frame)
1862 static mp_image_t
*mp_dvdnav_restore_smpi(struct MPContext
*mpctx
,
1864 unsigned char **start
,
1865 mp_image_t
*decoded_frame
)
1867 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
1868 return decoded_frame
;
1870 /// a change occured in dvdnav stream
1871 if (mp_dvdnav_cell_has_changed(mpctx
->stream
,0)) {
1872 mp_dvdnav_read_wait(mpctx
->stream
, 1, 1);
1873 mp_dvdnav_context_free(mpctx
);
1874 mp_dvdnav_reset_stream(mpctx
);
1875 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
1876 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
1882 /// Display still frame, if any
1883 if (mpctx
->nav_smpi
&& !mpctx
->nav_buffer
)
1884 decoded_frame
= mpctx
->nav_smpi
;
1886 /// increment video frame : continue playing after still frame
1887 len
= demuxer_get_time_length(mpctx
->demuxer
);
1888 if (mpctx
->sh_video
->pts
>= len
&&
1889 mpctx
->sh_video
->pts
> 0.0 && len
> 0.0) {
1890 mp_dvdnav_skip_still(mpctx
->stream
);
1891 mp_dvdnav_skip_wait(mpctx
->stream
);
1893 mpctx
->sh_video
->pts
+= 1 / mpctx
->sh_video
->fps
;
1895 if (mpctx
->nav_buffer
) {
1896 *start
= mpctx
->nav_start
;
1897 *in_size
= mpctx
->nav_in_size
;
1898 if (mpctx
->nav_start
)
1899 memcpy(*start
,mpctx
->nav_buffer
,mpctx
->nav_in_size
);
1903 return decoded_frame
;
1906 /// Save last decoded DVDNAV (still frame)
1907 static void mp_dvdnav_save_smpi(struct MPContext
*mpctx
, int in_size
,
1908 unsigned char *start
,
1909 mp_image_t
*decoded_frame
)
1911 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
1914 if (mpctx
->nav_buffer
)
1915 free(mpctx
->nav_buffer
);
1917 mpctx
->nav_buffer
= malloc(in_size
);
1918 mpctx
->nav_start
= start
;
1919 mpctx
->nav_in_size
= mpctx
->nav_buffer
? in_size
: -1;
1920 if (mpctx
->nav_buffer
)
1921 memcpy(mpctx
->nav_buffer
,start
,in_size
);
1923 if (decoded_frame
&& mpctx
->nav_smpi
!= decoded_frame
)
1924 mpctx
->nav_smpi
= mp_dvdnav_copy_mpi(mpctx
->nav_smpi
,decoded_frame
);
1926 #endif /* CONFIG_DVDNAV */
1928 static void adjust_sync_and_print_status(struct MPContext
*mpctx
,
1932 struct MPOpts
*opts
= &mpctx
->opts
;
1933 current_module
="av_sync";
1935 if(mpctx
->sh_audio
){
1936 double a_pts
, v_pts
;
1940 * If autosync is enabled, the value for delay must be calculated
1941 * a bit differently. It is set only to the difference between
1942 * the audio and video timers. Any attempt to include the real
1943 * or corrected delay causes the pts_correction code below to
1944 * try to correct for the changes in delay which autosync is
1945 * trying to measure. This keeps the two from competing, but still
1946 * allows the code to correct for PTS drift *only*. (Using a delay
1947 * value here, even a "corrected" one, would be incompatible with
1950 a_pts
= written_audio_pts(mpctx
) - mpctx
->delay
;
1952 a_pts
= playing_audio_pts(mpctx
);
1954 v_pts
= mpctx
->sh_video
->pts
;
1957 static int drop_message
=0;
1958 double AV_delay
= a_pts
- audio_delay
- v_pts
;
1960 if (AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
1962 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
1967 /* Do not correct target time for the next frame if this frame
1968 * was late not because of wrong target time but because the
1969 * target time could not be met */
1970 x
= (AV_delay
+ timing_error
* opts
->playback_speed
) * 0.1f
;
1971 if (x
< -max_pts_correction
)
1972 x
= -max_pts_correction
;
1973 else if (x
> max_pts_correction
)
1974 x
= max_pts_correction
;
1975 if (default_max_pts_correction
>= 0)
1976 max_pts_correction
= default_max_pts_correction
;
1978 max_pts_correction
= mpctx
->sh_video
->frametime
*0.10; // +-10% of time
1979 if (!between_frames
) {
1984 print_status(mpctx
, a_pts
- audio_delay
, AV_delay
, c_total
);
1991 print_status(mpctx
, 0, 0, 0);
1995 static int fill_audio_out_buffers(struct MPContext
*mpctx
)
1997 struct MPOpts
*opts
= &mpctx
->opts
;
2004 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
2006 current_module
="play_audio";
2009 // all the current uses of ao_data.pts seem to be in aos that handle
2010 // sync completely wrong; there should be no need to use ao_data.pts
2012 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2013 bytes_to_write
= mpctx
->audio_out
->get_space();
2014 if (mpctx
->sh_video
|| bytes_to_write
>= ao_data
.outburst
)
2017 // handle audio-only case:
2018 // this is where mplayer sleeps during audio-only playback
2019 // to avoid 100% CPU use
2020 usec_sleep(10000); // Wait a tick before retry
2023 while (bytes_to_write
) {
2024 playsize
= bytes_to_write
;
2025 if (playsize
> MAX_OUTBURST
)
2026 playsize
= MAX_OUTBURST
;
2027 bytes_to_write
-= playsize
;
2029 // Fill buffer if needed:
2030 current_module
="decode_audio";
2032 if (decode_audio(sh_audio
, playsize
) < 0) // EOF or error
2033 if (mpctx
->d_audio
->eof
) {
2035 if (sh_audio
->a_out_buffer_len
== 0)
2039 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2040 if (playsize
> sh_audio
->a_out_buffer_len
) {
2041 playsize
= sh_audio
->a_out_buffer_len
;
2043 playflags
|= AOPLAY_FINAL_CHUNK
;
2049 current_module
="play_audio";
2051 // Is this pts value actually useful for the aos that access it?
2052 // They're obviously badly broken in the way they handle av sync;
2053 // would not having access to this make them more broken?
2054 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2055 playsize
= mpctx
->audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
2058 sh_audio
->a_out_buffer_len
-= playsize
;
2059 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
2060 sh_audio
->a_out_buffer_len
);
2061 mpctx
->delay
+= opts
->playback_speed
*playsize
/(double)ao_data
.bps
;
2063 else if (audio_eof
&& mpctx
->audio_out
->get_delay() < .04) {
2064 // Sanity check to avoid hanging in case current ao doesn't output
2065 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
2066 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
2067 sh_audio
->a_out_buffer_len
= 0;
2073 static int sleep_until_update(struct MPContext
*mpctx
, float *time_frame
,
2074 float *aq_sleep_time
)
2076 struct MPOpts
*opts
= &mpctx
->opts
;
2077 int frame_time_remaining
= 0;
2078 current_module
="calc_sleep_time";
2080 *time_frame
-= get_relative_time(mpctx
); // reset timer
2082 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
2083 float delay
= mpctx
->audio_out
->get_delay();
2084 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
2088 * Adjust this raw delay value by calculating the expected
2089 * delay for this frame and generating a new value which is
2090 * weighted between the two. The higher autosync is, the
2091 * closer to the delay value gets to that which "-nosound"
2092 * would have used, and the longer it will take for A/V
2093 * sync to settle at the right value (but it eventually will.)
2094 * This settling time is very short for values below 100.
2096 float predicted
= mpctx
->delay
/ opts
->playback_speed
+ *time_frame
;
2097 float difference
= delay
- predicted
;
2098 delay
= predicted
+ difference
/ (float)autosync
;
2101 *time_frame
= delay
- mpctx
->delay
/ opts
->playback_speed
;
2103 // delay = amount of audio buffered in soundcard/driver
2104 if (delay
> 0.25) delay
=0.25; else
2105 if (delay
< 0.10) delay
=0.10;
2106 if (*time_frame
> delay
*0.6) {
2107 // sleep time too big - may cause audio drops (buffer underrun)
2108 frame_time_remaining
= 1;
2109 *time_frame
= delay
*0.5;
2112 // If we're lagging more than 200 ms behind the right playback rate,
2113 // don't try to "catch up".
2114 // If benchmark is set always output frames as fast as possible
2115 // without sleeping.
2116 if (*time_frame
< -0.2 || benchmark
)
2120 *aq_sleep_time
+= *time_frame
;
2123 //============================== SLEEP: ===================================
2125 // flag 256 means: libvo driver does its timing (dvb card)
2126 if (*time_frame
> 0.001 && !(mpctx
->sh_video
->output_flags
&256))
2127 *time_frame
= timing_sleep(mpctx
, *time_frame
);
2128 return frame_time_remaining
;
2131 int reinit_video_chain(struct MPContext
*mpctx
)
2133 struct MPOpts
*opts
= &mpctx
->opts
;
2134 sh_video_t
* const sh_video
= mpctx
->sh_video
;
2136 //================== Init VIDEO (codec & libvo) ==========================
2137 if(opts
->fixed_vo
|| !(mpctx
->initialized_flags
&INITIALIZED_VO
)){
2138 current_module
="preinit_libvo";
2140 //shouldn't we set dvideo->id=-2 when we fail?
2141 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
2142 if(!(mpctx
->video_out
=init_best_video_out(opts
, mpctx
->x11_state
, mpctx
->key_fifo
, mpctx
->input
))){
2143 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
2146 mpctx
->initialized_flags
|=INITIALIZED_VO
;
2149 if(stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_ASPECT_RATIO
, &ar
) != STREAM_UNSUPPORTED
)
2150 mpctx
->sh_video
->stream_aspect
= ar
;
2151 current_module
="init_video_filters";
2153 char* vf_arg
[] = { "_oldargs_", (char*)mpctx
->video_out
, NULL
};
2154 sh_video
->vfilter
= vf_open_filter(opts
, NULL
,"vo",vf_arg
);
2158 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
2159 vf_menu
= vf_open_plugin(opts
,libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
2161 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
2166 sh_video
->vfilter
= vf_menu
;
2173 if (opts
->vf_settings
)
2174 for (i
= 0; opts
->vf_settings
[i
].name
; ++i
)
2175 if (strcmp(opts
->vf_settings
[i
].name
, "ass") == 0) {
2180 extern vf_info_t vf_info_ass
;
2181 const vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
2182 char* vf_arg
[] = {"auto", "1", NULL
};
2183 vf_instance_t
* vf_ass
= vf_open_plugin(opts
, libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
2185 sh_video
->vfilter
= vf_ass
;
2187 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
2192 sh_video
->vfilter
= append_filters(sh_video
->vfilter
, opts
->vf_settings
);
2196 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
2199 current_module
="init_video_codec";
2201 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2202 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
2203 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2205 if(!sh_video
->initialized
){
2206 if(!opts
->fixed_vo
) uninit_player(mpctx
, INITIALIZED_VO
);
2210 mpctx
->initialized_flags
|=INITIALIZED_VCODEC
;
2212 if (sh_video
->codec
)
2213 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
2215 sh_video
->last_pts
= MP_NOPTS_VALUE
;
2216 sh_video
->num_buffered_pts
= 0;
2217 sh_video
->next_frame_time
= 0;
2220 // Auto quality option enabled
2221 output_quality
=get_video_quality_max(sh_video
);
2222 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
2223 else output_quality
=auto_quality
;
2224 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
2225 set_video_quality(sh_video
,output_quality
);
2228 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2230 current_module
="init_vo";
2235 mpctx
->sh_video
= mpctx
->d_video
->sh
= NULL
;
2239 static double update_video(struct MPContext
*mpctx
, int *blit_frame
)
2241 struct MPOpts
*opts
= &mpctx
->opts
;
2242 sh_video_t
* const sh_video
= mpctx
->sh_video
;
2243 //-------------------- Decode a frame: -----------------------
2245 *blit_frame
= 0; // Don't blit if we hit EOF
2246 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_SET_OSD_OBJ
,
2247 mpctx
->osd
); // hack for vf_expand
2248 if (!opts
->correct_pts
) {
2249 unsigned char* start
=NULL
;
2250 void *decoded_frame
= NULL
;
2254 current_module
= "video_read_frame";
2255 frame_time
= sh_video
->next_frame_time
;
2256 in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2258 #ifdef CONFIG_DVDNAV
2259 /// wait, still frame or EOF
2260 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
&& in_size
< 0) {
2261 if (mp_dvdnav_is_eof(mpctx
->stream
)) return -1;
2262 if (mpctx
->d_video
) mpctx
->d_video
->eof
= 0;
2263 if (mpctx
->d_audio
) mpctx
->d_audio
->eof
= 0;
2264 mpctx
->stream
->eof
= 0;
2269 if (in_size
> max_framesize
)
2270 max_framesize
= in_size
; // stats
2271 sh_video
->timer
+= frame_time
;
2272 if (mpctx
->sh_audio
)
2273 mpctx
->delay
-= frame_time
;
2274 // video_read_frame can change fps (e.g. for ASF video)
2275 vo_fps
= sh_video
->fps
;
2276 drop_frame
= check_framedrop(mpctx
, frame_time
);
2277 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
2278 update_teletext(sh_video
, mpctx
->demuxer
, 0);
2279 update_osd_msg(mpctx
);
2280 current_module
= "decode_video";
2281 #ifdef CONFIG_DVDNAV
2282 decoded_frame
= mp_dvdnav_restore_smpi(mpctx
, &in_size
,&start
,
2284 /// still frame has been reached, no need to decode
2285 if (in_size
> 0 && !decoded_frame
)
2287 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
2289 #ifdef CONFIG_DVDNAV
2290 /// save back last still frame for future display
2291 mp_dvdnav_save_smpi(mpctx
, in_size
, start
, decoded_frame
);
2293 current_module
= "filter_video";
2294 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
2299 int res
= generate_video_frame(mpctx
);
2302 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_GET_PTS
,
2304 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
2305 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
2306 sh_video
->pts
= sh_video
->last_pts
;
2308 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2309 sh_video
->last_pts
= sh_video
->pts
;
2310 else if (sh_video
->last_pts
>= sh_video
->pts
) {
2311 sh_video
->last_pts
= sh_video
->pts
;
2312 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "pts value <= previous\n");
2314 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2315 sh_video
->last_pts
= sh_video
->pts
;
2316 sh_video
->timer
+= frame_time
;
2318 mpctx
->delay
-= frame_time
;
2319 *blit_frame
= res
> 0;
2324 static void pause_loop(struct MPContext
*mpctx
)
2328 // Small hack to display the pause message on the OSD line.
2329 // The pause string is: "\n == PAUSE == \r" so we need to
2330 // take the first and the last char out
2331 if (term_osd
&& !mpctx
->sh_video
) {
2332 char msg
[128] = MSGTR_Paused
;
2333 int mlen
= strlen(msg
);
2335 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2336 update_osd_msg(mpctx
);
2338 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2339 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2343 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
2345 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2346 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2348 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2349 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2351 while ( (cmd
= mp_input_get_cmd(mpctx
->input
, 20, 1, 1)) == NULL
2352 || cmd
->id
== MP_CMD_SET_MOUSE_POS
|| cmd
->pausing
== 4) {
2354 cmd
= mp_input_get_cmd(mpctx
->input
, 0,1,0);
2355 run_command(mpctx
, cmd
);
2359 if (mpctx
->sh_video
&& mpctx
->video_out
)
2360 vo_check_events(mpctx
->video_out
);
2364 guiGetEvent(guiReDraw
, NULL
);
2365 if (guiIntfStruct
.Playing
!=2 || (mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
))
2371 vf_menu_pause_update(vf_menu
);
2375 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
2376 cmd
= mp_input_get_cmd(mpctx
->input
, 0,1,0);
2379 mpctx
->osd_function
=OSD_PLAY
;
2380 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2381 mpctx
->audio_out
->resume(); // resume audio
2382 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2383 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
); // resume video
2384 (void)get_relative_time(mpctx
); // ignore time that passed during pause
2387 if (guiIntfStruct
.Playing
== guiSetStop
)
2390 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
2395 static void print_version(void){
2396 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s\n", MP_TITLE
);
2398 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2399 GetCpuCaps(&gCpuCaps
);
2401 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2402 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
2403 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
2404 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
2405 #ifdef RUNTIME_CPUDETECT
2406 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
2408 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
2410 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
2413 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
2416 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
2419 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
2422 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
2425 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
2427 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
2428 #endif /* RUNTIME_CPUDETECT */
2429 #endif /* ARCH_X86 */
2433 // Find the right mute status and record position for new file position
2434 static void edl_seek_reset(MPContext
*mpctx
)
2436 mpctx
->edl_muted
= 0;
2437 next_edl_record
= edl_records
;
2439 while (next_edl_record
) {
2440 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2443 if (next_edl_record
->action
== EDL_MUTE
)
2444 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2445 next_edl_record
= next_edl_record
->next
;
2447 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2448 mixer_mute(&mpctx
->mixer
);
2452 // Execute EDL command for the current position if one exists
2453 static void edl_update(MPContext
*mpctx
)
2455 if (!next_edl_record
)
2458 if (!mpctx
->sh_video
) {
2459 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
2460 free_edl(edl_records
);
2461 next_edl_record
= NULL
;
2466 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2467 if (next_edl_record
->action
== EDL_SKIP
) {
2468 mpctx
->osd_function
= OSD_FFW
;
2469 mpctx
->abs_seek_pos
= 0;
2470 mpctx
->rel_seek_secs
= next_edl_record
->length_sec
;
2471 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2472 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2473 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2476 else if (next_edl_record
->action
== EDL_MUTE
) {
2477 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2478 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2479 mixer_mute(&mpctx
->mixer
);
2480 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2481 next_edl_record
->start_sec
);
2483 next_edl_record
= next_edl_record
->next
;
2488 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute
2489 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length
2490 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2491 static int seek(MPContext
*mpctx
, double amount
, int style
)
2493 current_module
= "seek";
2494 if (demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
) == 0)
2497 if (mpctx
->sh_video
) {
2498 current_module
= "seek_video_reset";
2499 resync_video_stream(mpctx
->sh_video
);
2500 if (mpctx
->video_out
->config_ok
)
2501 vo_control(mpctx
->video_out
, VOCTRL_RESET
, NULL
);
2502 mpctx
->sh_video
->num_buffered_pts
= 0;
2503 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2504 mpctx
->num_buffered_frames
= 0;
2506 // Not all demuxers set d_video->pts during seek, so this value
2507 // (which is used by at least vobsub and edl code below) may
2508 // be completely wrong (probably 0).
2509 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
;
2510 update_subtitles(mpctx
->sh_video
, mpctx
->d_sub
, 1);
2511 update_teletext(mpctx
->sh_video
, mpctx
->demuxer
, 1);
2514 if (mpctx
->sh_audio
) {
2515 current_module
= "seek_audio_reset";
2516 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2517 mpctx
->sh_audio
->a_buffer_len
= 0;
2518 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2521 if (vo_vobsub
&& mpctx
->sh_video
) {
2522 current_module
= "seek_vobsub_reset";
2523 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2526 edl_seek_reset(mpctx
);
2529 max_pts_correction
= 0.1;
2530 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2533 current_module
= NULL
;
2538 static int read_keys(void *ctx
, int fd
)
2541 return mplayer_get_key(ctx
, 0);
2545 /* This preprocessor directive is a hack to generate a mplayer-nomain.o object
2546 * file for some tools to link against. */
2547 #ifndef DISABLE_MAIN
2548 int main(int argc
,char* argv
[]){
2555 /* Flag indicating whether MPlayer should exit without playing anything. */
2558 //float a_frame=0; // Audio
2562 int gui_no_filename
=0;
2564 struct MPContext
*mpctx
= &(struct MPContext
){
2565 .osd_function
= OSD_PLAY
,
2566 .begin_skip
= MP_NOPTS_VALUE
,
2567 .play_tree_step
= 1,
2568 .global_sub_pos
= -1,
2569 .set_of_sub_pos
= -1,
2570 .file_format
= DEMUXER_TYPE_UNKNOWN
,
2575 srand(GetTimerMS());
2580 mpctx
->x11_state
= vo_x11_init_state();
2582 struct MPOpts
*opts
= &mpctx
->opts
;
2583 set_default_mplayer_options(opts
);
2584 // Create the config context and register the options
2585 mpctx
->mconfig
= m_config_new(opts
, cfg_include
);
2586 m_config_register_options(mpctx
->mconfig
,mplayer_opts
);
2587 mp_input_register_options(mpctx
->mconfig
);
2589 // Preparse the command line
2590 m_config_preparse_command_line(mpctx
->mconfig
,argc
,argv
);
2593 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
2598 stream_tv_defaults
.immediate
= 1;
2601 if (argc
> 1 && argv
[1] &&
2602 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
2603 use_gui
= !strcmp(argv
[1], "-gui");
2607 char *base
= strrchr(argv
[0], '/');
2609 base
= strrchr(argv
[0], '\\');
2612 if(strstr(base
, "gmplayer"))
2616 parse_cfgfiles(mpctx
, mpctx
->mconfig
);
2619 if ( use_gui
) cfg_read();
2622 mpctx
->playtree
= m_config_parse_mp_command_line(mpctx
->mconfig
, argc
, argv
);
2623 if(mpctx
->playtree
== NULL
)
2626 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
2627 if(mpctx
->playtree
) {
2628 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mpctx
->mconfig
);
2629 if(mpctx
->playtree_iter
) {
2630 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2631 play_tree_iter_free(mpctx
->playtree_iter
);
2632 mpctx
->playtree_iter
= NULL
;
2634 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2638 mpctx
->key_fifo
= mp_fifo_create(opts
);
2640 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_GUI)
2641 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
2642 if(runningmplayer
&& mpctx
->filename
&& use_gui
){
2643 COPYDATASTRUCT csData
;
2644 char file
[MAX_PATH
];
2645 char *filepart
= mpctx
->filename
;
2646 if(GetFullPathName(mpctx
->filename
, MAX_PATH
, file
, &filepart
)){
2648 csData
.cbData
= strlen(file
)*2;
2649 csData
.lpData
= file
;
2650 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
2655 #if defined(__MINGW32__) || defined(__CYGWIN__)
2656 // request 1ms timer resolution
2660 for(i
=0; priority_presets_defs
[i
].name
; i
++){
2661 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
2664 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_SettingProcessPriority
,
2665 priority_presets_defs
[i
].name
);
2666 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
2671 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
2675 #if !defined(__MINGW32__) && !defined(__CYGWIN__)
2676 if(use_gui
&& !vo_init()){
2677 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
2681 if (use_gui
&& mpctx
->playtree_iter
){
2682 char cwd
[PATH_MAX
+2];
2683 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2684 play_tree_iter_free(mpctx
->playtree_iter
);
2685 mpctx
->playtree_iter
=NULL
;
2687 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
2690 // Prefix relative paths with current working directory
2691 play_tree_add_bpf(mpctx
->playtree
, cwd
);
2693 // Import initital playtree into GUI.
2694 import_initial_playtree_into_gui(mpctx
->playtree
, mpctx
->mconfig
, enqueue
);
2696 #endif /* CONFIG_GUI */
2698 if(opts
->video_driver_list
&& strcmp(opts
->video_driver_list
[0],"help")==0){
2703 if(opts
->audio_driver_list
&& strcmp(opts
->audio_driver_list
[0],"help")==0){
2708 /* Check codecs.conf. */
2709 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2710 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2711 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2712 if(!parse_codec_cfg(NULL
)){
2713 exit_player_with_rc(mpctx
, NULL
, 0);
2715 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
2718 free( mem_ptr
); // release the buffer created by get_path()
2722 if(video_codec_list
){
2724 video_codec
=video_codec_list
[0];
2725 for(i
=0;video_codec_list
[i
];i
++)
2726 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2729 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2730 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
2731 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2733 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2736 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2737 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
2738 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2740 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2743 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2745 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2748 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
2750 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2753 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
2759 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
2761 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2765 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
2766 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
2767 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
2769 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2772 if(list_properties
) {
2773 property_print_help();
2778 exit_player(mpctx
, NULL
);
2780 if (player_idle_mode
&& use_gui
) {
2781 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
2782 exit_player_with_rc(mpctx
, NULL
, 1);
2785 if(!mpctx
->filename
&& !player_idle_mode
){
2787 // no file/vcd/dvd -> show HELP:
2788 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
2789 exit_player_with_rc(mpctx
, NULL
, 0);
2790 } else gui_no_filename
=1;
2793 /* Display what configure line was used */
2794 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
2796 // Many users forget to include command line in bugreports...
2797 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
2798 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
2799 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
2800 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2803 //------ load global data first ------
2805 mpctx
->osd
= osd_create();
2808 #ifdef CONFIG_FREETYPE
2811 #ifdef CONFIG_FONTCONFIG
2812 if(font_fontconfig
<= 0)
2815 #ifdef CONFIG_BITMAP_FONT
2817 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
2818 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,
2819 filename_recode(font_name
));
2822 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
2823 free(mem_ptr
); // release the buffer created by get_path()
2825 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
2828 mpctx
->osd
->sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
2830 mpctx
->osd
->sub_font
= vo_font
;
2832 #ifdef CONFIG_FONTCONFIG
2837 ass_library
= ass_init();
2843 // seteuid(0); /* Can't hurt to try to get root here */
2844 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
2845 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
2846 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
2848 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
2850 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
2851 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
2852 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
2855 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
2856 /* variable only by the root */
2857 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
2861 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
2865 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2866 // and now ? -- Pontscho
2867 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
2870 #endif /* HAVE_RTC */
2871 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
2872 softsleep
?"software":timer_name
);
2875 if ( !use_gui
) load_termcap(NULL
); // load key-codes
2878 // ========== Init keyboard FIFO (connection to libvo) ============
2880 // Init input system
2881 current_module
= "init_input";
2882 mpctx
->input
= mp_input_init(&opts
->input
, use_gui
);
2883 mp_input_add_key_fd(mpctx
->input
, -1,0,mplayer_get_key
,NULL
, mpctx
->key_fifo
);
2885 mp_input_add_cmd_fd(mpctx
->input
, 0,USE_SELECT
,MP_INPUT_SLAVE_CMD_FUNC
,NULL
);
2886 else if(!noconsolecontrols
)
2887 mp_input_add_key_fd(mpctx
->input
, 0, 1, read_keys
, NULL
, mpctx
->key_fifo
);
2888 // Set the libstream interrupt callback
2889 stream_set_interrupt_callback(mp_input_check_interrupt
, mpctx
->input
);
2893 if(menu_cfg
&& menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
2894 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2896 menu_cfg
= get_path("menu.conf");
2897 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
2898 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2900 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
,
2901 MPLAYER_CONFDIR
"/menu.conf"))
2902 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
2904 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
2912 current_module
= NULL
;
2916 signal(SIGCHLD
,child_sighandler
);
2919 #ifdef CONFIG_CRASH_DEBUG
2920 prog_path
= argv
[0];
2922 //========= Catch terminate signals: ================
2923 // terminate requests:
2924 signal(SIGTERM
,exit_sighandler
); // kill
2925 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
2927 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
2929 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
2930 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
2931 #ifdef CONFIG_SIGHANDLER
2933 signal(SIGBUS
,exit_sighandler
); // bus error
2934 signal(SIGSEGV
,exit_sighandler
); // segfault
2935 signal(SIGILL
,exit_sighandler
); // illegal instruction
2936 signal(SIGFPE
,exit_sighandler
); // floating point exc.
2937 signal(SIGABRT
,exit_sighandler
); // abort()
2938 #ifdef CONFIG_CRASH_DEBUG
2940 signal(SIGTRAP
,exit_sighandler
);
2947 guiGetEvent(guiSetContext
, mpctx
);
2948 mpctx
->initialized_flags
|=INITIALIZED_GUI
;
2949 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
2953 // ******************* Now, let's see the per-file stuff ********************
2957 // init global sub numbers
2958 mpctx
->global_sub_size
= 0;
2959 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) mpctx
->global_sub_indices
[i
] = -1; }
2961 if (mpctx
->filename
) {
2962 load_per_protocol_config (mpctx
->mconfig
, mpctx
->filename
);
2963 load_per_extension_config (mpctx
->mconfig
, mpctx
->filename
);
2964 load_per_file_config (mpctx
->mconfig
, mpctx
->filename
);
2967 if (opts
->video_driver_list
)
2968 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_VO
, opts
->video_driver_list
[0]);
2969 if (opts
->audio_driver_list
)
2970 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_AO
, opts
->audio_driver_list
[0]);
2972 // We must enable getch2 here to be able to interrupt network connection
2974 if(!noconsolecontrols
&& !slave_mode
){
2975 if(mpctx
->initialized_flags
&INITIALIZED_GETCH2
)
2976 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
2978 getch2_enable(); // prepare stdin for hotkeys...
2979 mpctx
->initialized_flags
|=INITIALIZED_GETCH2
;
2980 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
2983 // =================== GUI idle loop (STOP state) ===========================
2986 mpctx
->file_format
=DEMUXER_TYPE_UNKNOWN
;
2987 guiGetEvent( guiSetDefaults
,0 );
2988 while ( guiIntfStruct
.Playing
!= 1 )
2993 guiGetEvent( guiReDraw
,NULL
);
2994 if ( (cmd
= mp_input_get_cmd(mpctx
->input
, 0,0,0)) != NULL
) {
2995 guiGetEvent(guiIEvent
, (char *)cmd
->id
);
2999 guiGetEvent( guiSetParameters
,NULL
);
3000 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
3002 play_tree_t
* entry
= play_tree_new();
3003 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
3004 if ( mpctx
->playtree
) play_tree_free_list( mpctx
->playtree
->child
,1 );
3005 else mpctx
->playtree
=play_tree_new();
3006 play_tree_set_child( mpctx
->playtree
,entry
);
3009 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mpctx
->mconfig
);
3010 if(mpctx
->playtree_iter
)
3012 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
3014 play_tree_iter_free(mpctx
->playtree_iter
);
3015 mpctx
->playtree_iter
= NULL
;
3017 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
3022 #endif /* CONFIG_GUI */
3024 while (player_idle_mode
&& !mpctx
->filename
) {
3025 play_tree_t
* entry
= NULL
;
3027 while (!(cmd
= mp_input_get_cmd(mpctx
->input
, 0,1,0))) { // wait for command
3028 if (mpctx
->video_out
)
3029 vo_check_events(mpctx
->video_out
);
3033 case MP_CMD_LOADFILE
:
3034 // prepare a tree entry with the new filename
3035 entry
= play_tree_new();
3036 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3037 // The entry is added to the main playtree after the switch().
3039 case MP_CMD_LOADLIST
:
3040 entry
= parse_playlist_file(mpctx
->mconfig
, cmd
->args
[0].v
.s
);
3043 exit_player_with_rc(mpctx
, MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3045 case MP_CMD_GET_PROPERTY
:
3046 case MP_CMD_SET_PROPERTY
:
3047 case MP_CMD_STEP_PROPERTY
:
3048 run_command(mpctx
, cmd
);
3054 if (entry
) { // user entered a command that gave a valid entry
3055 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
3056 play_tree_free_list(mpctx
->playtree
->child
, 1);
3057 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
3059 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
3061 play_tree_set_child(mpctx
->playtree
, entry
);
3063 /* Make iterator start at the top the of tree. */
3064 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mpctx
->mconfig
);
3065 if (!mpctx
->playtree_iter
) continue;
3067 // find the first real item in the tree
3068 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3070 play_tree_iter_free(mpctx
->playtree_iter
);
3071 mpctx
->playtree_iter
= NULL
;
3072 continue; // wait for next command
3074 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
3077 //---------------------------------------------------------------------------
3080 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
,
3081 filename_recode(mpctx
->filename
));
3084 if (edl_records
) free_edl(edl_records
);
3085 next_edl_record
= edl_records
= edl_parse_file();
3087 if (edl_output_filename
) {
3088 if (edl_fd
) fclose(edl_fd
);
3089 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3091 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
3092 filename_recode(edl_output_filename
));
3096 //==================== Open VOB-Sub ============================
3098 current_module
="vobsub";
3100 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3102 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,
3103 filename_recode(vobsub_name
));
3104 } else if (sub_auto
&& mpctx
->filename
){
3105 /* try to autodetect vobsub from movie filename ::atmos */
3106 char *buf
= strdup(mpctx
->filename
), *psub
;
3107 char *pdot
= strrchr(buf
, '.');
3108 char *pslash
= strrchr(buf
, '/');
3109 #if defined(__MINGW32__) || defined(__CYGWIN__)
3110 if (!pslash
) pslash
= strrchr(buf
, '\\');
3112 if (pdot
&& (!pslash
|| pdot
> pslash
))
3114 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3115 /* try from ~/.mplayer/sub */
3116 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3119 bname
= strrchr(buf
,'/');
3120 #if defined(__MINGW32__) || defined(__CYGWIN__)
3121 if(!bname
) bname
= strrchr(buf
,'\\');
3125 l
= strlen(psub
) + strlen(bname
) + 1;
3126 psub
= realloc(psub
,l
);
3128 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3134 mpctx
->initialized_flags
|=INITIALIZED_VOBSUB
;
3135 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
3136 // check if vobsub requested only to display forced subtitles
3137 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
3139 // setup global sub numbering
3140 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] = mpctx
->global_sub_size
; // the global # of the first vobsub.
3141 mpctx
->global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
3144 //============ Open & Sync STREAM --- fork cache2 ====================
3147 mpctx
->demuxer
=NULL
;
3148 if (mpctx
->d_audio
) {
3149 //free_demuxer_stream(mpctx->d_audio);
3150 mpctx
->d_audio
=NULL
;
3152 if (mpctx
->d_video
) {
3153 //free_demuxer_stream(d_video);
3154 mpctx
->d_video
=NULL
;
3156 mpctx
->sh_audio
=NULL
;
3157 mpctx
->sh_video
=NULL
;
3159 current_module
="open_stream";
3160 mpctx
->stream
= open_stream(mpctx
->filename
, opts
, &mpctx
->file_format
);
3161 if(!mpctx
->stream
) { // error...
3162 mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
);
3163 goto goto_next_file
;
3165 mpctx
->initialized_flags
|=INITIALIZED_STREAM
;
3168 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)mpctx
->stream
);
3171 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
3172 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "\nThis looks like a playlist, but "
3173 "playlist support will not be used automatically.\n"
3174 "MPlayer's playlist code is unsafe and should only be used with "
3175 "trusted sources.\nPlayback will probably fail.\n\n");
3179 current_module
="handle_playlist";
3180 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
3181 filename_recode(mpctx
->filename
));
3182 entry
= parse_playtree(mpctx
->stream
, mpctx
->mconfig
, 0);
3183 mpctx
->eof
=playtree_add_playlist(mpctx
, entry
);
3184 goto goto_next_file
;
3187 mpctx
->stream
->start_pos
+=seek_to_byte
;
3189 if(stream_dump_type
==5){
3190 unsigned char buf
[4096];
3193 current_module
="dumpstream";
3194 if(mpctx
->stream
->type
==STREAMTYPE_STREAM
&& mpctx
->stream
->fd
<0){
3195 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
3196 exit_player(mpctx
, MSGTR_Exit_error
);
3198 stream_reset(mpctx
->stream
);
3199 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
3200 f
=fopen(stream_dump_name
,"wb");
3202 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3203 exit_player(mpctx
, MSGTR_Exit_error
);
3205 if (dvd_chapter
> 1) {
3206 int chapter
= dvd_chapter
- 1;
3207 stream_control(mpctx
->stream
, STREAM_CTRL_SEEK_TO_CHAPTER
, &chapter
);
3209 while(!mpctx
->stream
->eof
&& !async_quit_request
){
3210 len
=stream_read(mpctx
->stream
,buf
,4096);
3212 if(fwrite(buf
,len
,1,f
) != 1) {
3213 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3214 exit_player(mpctx
, MSGTR_Exit_error
);
3219 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3220 exit_player(mpctx
, MSGTR_Exit_error
);
3222 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3223 exit_player_with_rc(mpctx
, MSGTR_Exit_eof
, 0);
3226 #ifdef CONFIG_DVDREAD
3227 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
3228 current_module
="dvd lang->id";
3229 if(opts
->audio_id
==-1) opts
->audio_id
=dvd_aid_from_lang(mpctx
->stream
,audio_lang
);
3230 if(dvdsub_lang
&& opts
->sub_id
==-2) opts
->sub_id
=-1;
3231 if(dvdsub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=dvd_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3232 // setup global sub numbering
3233 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3234 mpctx
->global_sub_size
+= dvd_number_of_subs(mpctx
->stream
);
3235 current_module
=NULL
;
3239 #ifdef CONFIG_DVDNAV
3240 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
3241 current_module
="dvdnav lang->id";
3242 if(opts
->audio_id
==-1) opts
->audio_id
=mp_dvdnav_aid_from_lang(mpctx
->stream
,audio_lang
);
3243 if(dvdsub_lang
&& opts
->sub_id
==-2) opts
->sub_id
=-1;
3244 if(dvdsub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=mp_dvdnav_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3245 // setup global sub numbering
3246 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3247 mpctx
->global_sub_size
+= mp_dvdnav_number_of_subs(mpctx
->stream
);
3248 current_module
=NULL
;
3252 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3254 if(stream_cache_size
>0){
3255 current_module
="enable_cache";
3256 if(!stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
3257 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3258 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
3259 if((mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
))) goto goto_next_file
;
3262 //============ Open DEMUXERS --- DETECT file type =======================
3263 current_module
="demux_open";
3265 mpctx
->demuxer
=demux_open(opts
, mpctx
->stream
,mpctx
->file_format
,opts
->audio_id
,opts
->video_id
,opts
->sub_id
,mpctx
->filename
);
3267 // HACK to get MOV Reference Files working
3269 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3271 unsigned char* playlist_entry
;
3272 play_tree_t
*list
= NULL
, *entry
= NULL
;
3274 current_module
="handle_demux_playlist";
3275 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
3279 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
3280 filename_recode(playlist_entry
));
3282 bname
=mp_basename(playlist_entry
);
3283 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3286 if (!strncmp(bname
,mp_basename(mpctx
->filename
),strlen(bname
))) // ignoring self-reference
3289 entry
= play_tree_new();
3291 if (mpctx
->filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3293 temp
=malloc((strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))+strlen(playlist_entry
)+1));
3296 strncpy(temp
, mpctx
->filename
, strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
)));
3297 temp
[strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))]='\0';
3298 strcat(temp
, playlist_entry
);
3299 play_tree_add_file(entry
,temp
);
3300 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3305 play_tree_add_file(entry
,playlist_entry
);
3310 play_tree_append_entry(list
,entry
);
3312 free_demuxer(mpctx
->demuxer
);
3313 mpctx
->demuxer
= NULL
;
3317 entry
= play_tree_new();
3318 play_tree_set_child(entry
,list
);
3319 mpctx
->stop_play
= playtree_add_playlist(mpctx
, entry
);
3320 goto goto_next_file
;
3325 goto goto_next_file
;
3328 if (demuxer_seek_chapter(mpctx
->demuxer
, dvd_chapter
-1, 1, &pts
, NULL
, NULL
) >= 0 && pts
> -1.0)
3329 seek(mpctx
, pts
, SEEK_ABSOLUTE
);
3332 mpctx
->initialized_flags
|=INITIALIZED_DEMUXER
;
3334 if (mpctx
->stream
->type
!= STREAMTYPE_DVD
&& mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
) {
3337 // setup global sub numbering
3338 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3339 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
3340 if (mpctx
->demuxer
->s_streams
[i
])
3341 maxid
= FFMAX(maxid
, mpctx
->demuxer
->s_streams
[i
]->sid
);
3342 mpctx
->global_sub_size
+= maxid
+ 1;
3344 // Make opts->sub_id always selectable if set.
3345 if (mpctx
->global_sub_size
<= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
)
3346 mpctx
->global_sub_size
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
+ 1;
3349 if (ass_enabled
&& ass_library
) {
3350 for (i
= 0; i
< mpctx
->demuxer
->num_attachments
; ++i
) {
3351 demux_attachment_t
* att
= mpctx
->demuxer
->attachments
+ i
;
3352 if (extract_embedded_fonts
&&
3353 att
->name
&& att
->type
&& att
->data
&& att
->data_size
&&
3354 (strcmp(att
->type
, "application/x-truetype-font") == 0 ||
3355 strcmp(att
->type
, "application/x-font") == 0))
3356 ass_add_font(ass_library
, att
->name
, att
->data
, att
->data_size
);
3361 current_module
="demux_open2";
3363 //file_format=demuxer->file_format;
3365 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3366 mpctx
->d_video
=mpctx
->demuxer
->video
;
3367 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3369 // select audio stream
3370 select_audio(mpctx
->demuxer
, opts
->audio_id
, audio_lang
);
3373 if((stream_dump_type
)&&(stream_dump_type
<4)){
3375 demux_stream_t
*ds
=NULL
;
3376 current_module
="dump";
3377 // select stream to dump
3378 switch(stream_dump_type
){
3379 case 1: ds
=mpctx
->d_audio
;break;
3380 case 2: ds
=mpctx
->d_video
;break;
3381 case 3: ds
=mpctx
->d_sub
;break;
3384 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
3385 exit_player(mpctx
, MSGTR_Exit_error
);
3387 // disable other streams:
3388 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3389 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3390 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3392 f
=fopen(stream_dump_name
,"wb");
3394 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3395 exit_player(mpctx
, MSGTR_Exit_error
);
3398 unsigned char* start
;
3399 int in_size
=ds_get_packet(ds
,&start
);
3400 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3401 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3402 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3405 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3406 exit_player_with_rc(mpctx
, MSGTR_Exit_eof
, 0);
3409 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3410 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3412 if(mpctx
->sh_video
){
3414 current_module
="video_read_properties";
3415 if(!video_read_properties(mpctx
->sh_video
)) {
3416 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
3417 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3419 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_FilefmtFourccSizeFpsFtime
,
3420 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3421 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3424 /* need to set fps here for output encoders to pick it up in their init */
3426 mpctx
->sh_video
->fps
=force_fps
;
3427 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3429 vo_fps
= mpctx
->sh_video
->fps
;
3431 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3432 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
3433 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3439 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3440 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
3442 if(mpctx
->stream
->type
== STREAMTYPE_DVB
)
3445 int v
= mpctx
->last_dvb_step
;
3447 dir
= DVB_CHANNEL_HIGHER
;
3449 dir
= DVB_CHANNEL_LOWER
;
3451 if(dvb_step_channel(mpctx
->stream
, dir
)) {
3452 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3453 mpctx
->dvbin_reopen
= 1;
3457 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3460 /* display clip info */
3461 demux_info_print(mpctx
->demuxer
);
3463 //================== Read SUBTITLES (DVD & TEXT) ==========================
3464 if(vo_spudec
==NULL
&& mpctx
->sh_video
&&
3465 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
|| mpctx
->d_sub
->id
>= 0)){
3466 init_vo_spudec(mpctx
);
3469 // Apply current settings for forced subs
3470 if (vo_spudec
!=NULL
)
3471 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3473 if(mpctx
->sh_video
) {
3474 // after reading video params we should load subtitles because
3475 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3477 current_module
="read_subtitles_file";
3479 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3480 add_subtitles(mpctx
, sub_name
[i
], mpctx
->sh_video
->fps
, 0);
3482 if(sub_auto
) { // auto load sub file ...
3483 char *psub
= get_path( "sub/" );
3484 char **tmp
= sub_filenames((psub
? psub
: ""), mpctx
->filename
);
3486 free(psub
); // release the buffer created by get_path() above
3488 add_subtitles(mpctx
, tmp
[i
], mpctx
->sh_video
->fps
, 1);
3493 if (mpctx
->set_of_sub_size
> 0) {
3494 // setup global sub numbering
3495 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = mpctx
->global_sub_size
; // the global # of the first sub.
3496 mpctx
->global_sub_size
+= mpctx
->set_of_sub_size
;
3500 if (mpctx
->global_sub_size
) {
3501 // find the best sub to use
3502 int vobsub_index_id
= vobsub_get_index_by_id(vo_vobsub
, vobsub_id
);
3503 mpctx
->global_sub_pos
= -1; // no subs by default
3504 if (vobsub_index_id
>= 0) {
3505 // if user asks for a vobsub id, use that first.
3506 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_index_id
;
3507 } else if (opts
->sub_id
>= 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3508 // if user asks for a dvd sub id, use that next.
3509 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
;
3510 } else if (mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
3511 // if there are text subs to use, use those. (autosubs come last here)
3512 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
];
3513 } else if (opts
->sub_id
< 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3514 // finally select subs by language and container hints
3515 if (opts
->sub_id
< 0 && dvdsub_lang
)
3516 opts
->sub_id
= demuxer_sub_track_by_lang(mpctx
->demuxer
, dvdsub_lang
);
3517 if (opts
->sub_id
< 0)
3518 opts
->sub_id
= demuxer_default_sub_track(mpctx
->demuxer
);
3519 if (opts
->sub_id
>= 0)
3520 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
;
3522 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3523 mpctx
->global_sub_pos
--;
3524 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
, mpctx
);
3526 switch (stream_dump_type
) {
3527 case 3: list_sub_file(subdata
); break;
3528 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
3529 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
3530 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
3531 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
3532 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
3536 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
3537 filename_recode(mpctx
->filename
));
3538 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
3539 if (mpctx
->sh_video
) {
3540 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3541 if (mpctx
->sh_video
->format
>= 0x20202020)
3542 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
3544 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
3545 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
3546 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
3547 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
3548 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
3549 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
3551 if (mpctx
->sh_audio
) {
3552 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3553 if (mpctx
->sh_audio
->format
>= 0x20202020)
3554 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
3556 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
3557 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
3558 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
3559 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
3561 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(mpctx
->demuxer
));
3562 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_SEEKABLE=%d\n", mpctx
->stream
->seek
? 1 : 0);
3563 if (mpctx
->demuxer
) {
3564 if (mpctx
->demuxer
->num_chapters
== 0)
3565 stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_NUM_CHAPTERS
, &mpctx
->demuxer
->num_chapters
);
3566 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_CHAPTERS=%d\n", mpctx
->demuxer
->num_chapters
);
3569 if(!mpctx
->sh_video
) goto main
; // audio-only
3571 if(!reinit_video_chain(mpctx
)) {
3572 if(!mpctx
->sh_video
){
3573 if(!mpctx
->sh_audio
) goto goto_next_file
;
3574 goto main
; // exit_player(MSGTR_Exit_error);
3578 if(mpctx
->sh_video
->output_flags
& 0x08 && vo_spudec
)
3579 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
3581 #ifdef CONFIG_FREETYPE
3582 force_load_font
= 1;
3585 //================== MAIN: ==========================
3587 current_module
="main";
3590 char* msg
= property_expand_string(mpctx
, playing_msg
);
3591 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3596 // Disable the term OSD in verbose mode
3597 if(verbose
) term_osd
= 0;
3600 //int frame_corr_num=0; //
3601 //float v_frame=0; // Video
3602 float time_frame
=0; // Timer
3603 //float num_frames=0; // number of frames played
3605 int frame_time_remaining
=0; // flag
3607 mpctx
->num_buffered_frames
=0;
3609 // Make sure old OSD does not stay around,
3610 // e.g. with -fixed-vo and same-resolution files
3612 update_osd_msg(mpctx
);
3614 //================ SETUP AUDIO ==========================
3616 if(mpctx
->sh_audio
){
3617 reinit_audio_chain(mpctx
);
3618 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
3619 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
3622 current_module
="av_init";
3624 if(mpctx
->sh_video
){
3625 mpctx
->sh_video
->timer
=0;
3627 audio_delay
+= mpctx
->sh_video
->stream_delay
;
3629 if(mpctx
->sh_audio
){
3631 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
3632 mpctx
->delay
=-audio_delay
;
3635 if(!mpctx
->sh_audio
){
3636 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
3637 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
3638 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
3639 //mpctx->d_audio->id=-2; // do not read audio chunks
3640 //uninit_player(mpctx, INITIALIZED_AO); // close device
3642 if(!mpctx
->sh_video
){
3643 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
3644 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
3645 ds_free_packs(mpctx
->d_video
);
3646 mpctx
->d_video
->id
=-2;
3647 //if(!fixed_vo) uninit_player(mpctx, INITIALIZED_VO);
3650 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
3651 goto goto_next_file
;
3653 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3654 if(force_fps
&& mpctx
->sh_video
){
3655 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
3656 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3657 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
3662 if ( mpctx
->sh_audio
) guiIntfStruct
.AudioType
=mpctx
->sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
3663 if ( !mpctx
->sh_video
&& mpctx
->sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
3664 guiGetEvent( guiSetFileFormat
,(char *)mpctx
->demuxer
->file_format
);
3665 if ( guiGetEvent( guiSetValues
,(char *)mpctx
->sh_video
) ) goto goto_next_file
;
3666 guiGetEvent( guiSetDemuxer
,(char *)mpctx
->demuxer
);
3670 mp_input_set_section(mpctx
->input
, NULL
);
3671 //TODO: add desired (stream-based) sections here
3672 if (mpctx
->stream
->type
==STREAMTYPE_TV
) mp_input_set_section(mpctx
->input
, "tv");
3673 if (mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) mp_input_set_section(mpctx
->input
, "dvdnav");
3675 //==================== START PLAYING =======================
3677 if(opts
->loop_times
>1) opts
->loop_times
--; else
3678 if(opts
->loop_times
==1) opts
->loop_times
= -1;
3680 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);
3682 total_time_usage_start
=GetTimer();
3683 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3684 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3685 play_n_frames
=play_n_frames_mf
;
3687 if(play_n_frames
==0){
3688 mpctx
->stop_play
=PT_NEXT_ENTRY
; goto goto_next_file
;
3692 seek(mpctx
, seek_to_sec
, SEEK_ABSOLUTE
);
3693 end_at
.pos
+= seek_to_sec
;
3696 if (end_at
.type
== END_AT_SIZE
) {
3697 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
3698 end_at
.type
= END_AT_NONE
;
3701 #ifdef CONFIG_DVDNAV
3702 mp_dvdnav_context_free(mpctx
);
3703 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3704 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
3705 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
3709 get_relative_time(mpctx
); // reset current delta
3711 while(!mpctx
->stop_play
){
3712 float aq_sleep_time
=0;
3714 if(dvd_last_chapter
>0) {
3715 int cur_chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
3716 if(cur_chapter
!=-1 && cur_chapter
+1>dvd_last_chapter
)
3717 goto goto_next_file
;
3720 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
3721 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
3722 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
3723 reinit_audio_chain(mpctx
);
3726 /*========================== PLAY AUDIO ============================*/
3728 if (mpctx
->sh_audio
)
3729 if (!fill_audio_out_buffers(mpctx
))
3730 // at eof, all audio at least written to ao
3731 if (!mpctx
->sh_video
)
3732 mpctx
->stop_play
= AT_END_OF_FILE
;
3735 if(!mpctx
->sh_video
) {
3736 // handle audio-only case:
3738 // sh_audio can be NULL due to video stream switching
3739 // TODO: handle this better
3740 if(!quiet
|| end_at
.type
== END_AT_TIME
&& mpctx
->sh_audio
)
3741 a_pos
= playing_audio_pts(mpctx
);
3744 print_status(mpctx
, a_pos
, 0, 0);
3746 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
3747 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3748 update_osd_msg(mpctx
);
3752 /*========================== PLAY VIDEO ============================*/
3754 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
3755 vo_fps
=mpctx
->sh_video
->fps
;
3757 if (!mpctx
->num_buffered_frames
) {
3758 double frame_time
= update_video(mpctx
, &blit_frame
);
3759 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3760 if (mpctx
->sh_video
->vf_initialized
< 0) {
3761 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
3762 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3763 goto goto_next_file
;
3766 mpctx
->stop_play
= AT_END_OF_FILE
;
3768 // might return with !eof && !blit_frame if !correct_pts
3769 mpctx
->num_buffered_frames
+= blit_frame
;
3770 time_frame
+= frame_time
/ opts
->playback_speed
; // for nosound
3774 // ==========================================================================
3776 // current_module="draw_osd";
3777 // if(vo_config_count) mpctx->video_out->draw_osd();
3780 if(use_gui
) guiEventHandling();
3783 current_module
="vo_check_events";
3784 vo_check_events(mpctx
->video_out
);
3787 if (stop_xscreensaver
) {
3788 current_module
= "stop_xscreensaver";
3789 xscreensaver_heartbeat(mpctx
->x11_state
);
3792 if (heartbeat_cmd
) {
3793 static unsigned last_heartbeat
;
3794 unsigned now
= GetTimerMS();
3795 if (now
- last_heartbeat
> 30000) {
3796 last_heartbeat
= now
;
3797 system(heartbeat_cmd
);
3801 frame_time_remaining
= sleep_until_update(mpctx
, &time_frame
, &aq_sleep_time
);
3803 //====================== FLIP PAGE (VIDEO BLT): =========================
3805 current_module
="flip_page";
3806 if (!frame_time_remaining
&& blit_frame
) {
3807 unsigned int t2
=GetTimer();
3809 vo_flip_page(mpctx
->video_out
);
3810 mpctx
->num_buffered_frames
--;
3812 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
3814 //====================== A-V TIMESTAMP CORRECTION: =========================
3816 adjust_sync_and_print_status(mpctx
, frame_time_remaining
, time_frame
);
3818 //============================ Auto QUALITY ============================
3820 /*Output quality adjustments:*/
3822 current_module
="autoq";
3823 // float total=0.000001f * (GetTimer()-aq_total_time);
3824 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
3825 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
3828 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
3829 if(output_quality
>1 && aq_sleep_time
<0)
3832 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
3834 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
3835 set_video_quality(mpctx
->sh_video
,output_quality
);
3838 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
3840 if (play_n_frames
<= 0) mpctx
->stop_play
= PT_NEXT_ENTRY
;
3844 // FIXME: add size based support for -endpos
3845 if (end_at
.type
== END_AT_TIME
&&
3846 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
3847 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3849 } // end if(mpctx->sh_video)
3851 #ifdef CONFIG_DVDNAV
3852 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3854 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
3855 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
3856 vo_osd_changed (OSDTYPE_DVDNAV
);
3858 if (mp_dvdnav_stream_has_changed(mpctx
->stream
)) {
3860 if (stream_control (mpctx
->demuxer
->stream
,
3861 STREAM_CTRL_GET_ASPECT_RATIO
, &ar
)
3862 != STREAM_UNSUPPORTED
)
3863 mpctx
->sh_video
->stream_aspect
= ar
;
3868 //============================ Handle PAUSE ===============================
3870 current_module
="pause";
3872 if (mpctx
->osd_function
== OSD_PAUSE
) {
3873 mpctx
->was_paused
= 1;
3879 mpctx
->osd_function
=OSD_FFW
;
3880 mpctx
->rel_seek_secs
+=step_sec
;
3885 //================= Keyboard events, SEEKing ====================
3887 current_module
="key_events";
3892 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(mpctx
->input
, 0,0,0)) != NULL
) {
3893 brk_cmd
= run_command(mpctx
, cmd
);
3896 goto goto_enable_cache
;
3899 mpctx
->was_paused
= 0;
3902 if(mpctx
->stop_play
==AT_END_OF_FILE
&& opts
->loop_times
>=0) {
3903 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d\n", opts
->loop_times
);
3905 if(opts
->loop_times
>1) opts
->loop_times
--; else
3906 if(opts
->loop_times
==1) opts
->loop_times
=-1;
3907 play_n_frames
=play_n_frames_mf
;
3909 mpctx
->abs_seek_pos
=SEEK_ABSOLUTE
; mpctx
->rel_seek_secs
=seek_to_sec
;
3913 if(mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
){
3914 if (seek(mpctx
, mpctx
->rel_seek_secs
, mpctx
->abs_seek_pos
) >= 0) {
3918 set_osd_bar(mpctx
, 0,"Position",0,100,demuxer_get_percent_pos(mpctx
->demuxer
));
3922 mpctx
->rel_seek_secs
=0;
3923 mpctx
->abs_seek_pos
=0;
3931 if(mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
&& mpctx
->sh_video
&& mpctx
->sh_video
->video
.dwLength
>2){
3932 // get pos from frame number / total frames
3933 guiIntfStruct
.Position
=(float)mpctx
->d_video
->pack_no
*100.0f
/mpctx
->sh_video
->video
.dwLength
;
3935 guiIntfStruct
.Position
=demuxer_get_percent_pos(mpctx
->demuxer
);
3937 if ( mpctx
->sh_video
) guiIntfStruct
.TimeSec
=mpctx
->sh_video
->pts
;
3938 else if ( mpctx
->sh_audio
) guiIntfStruct
.TimeSec
=playing_audio_pts(mpctx
);
3939 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(mpctx
->demuxer
);
3940 guiGetEvent( guiReDraw
,NULL
);
3941 guiGetEvent( guiSetVolume
,NULL
);
3942 if(guiIntfStruct
.Playing
==0) break; // STOP
3943 if(guiIntfStruct
.Playing
==2) mpctx
->osd_function
=OSD_PAUSE
;
3944 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3945 #ifdef CONFIG_DVDREAD
3946 if ( mpctx
->stream
->type
== STREAMTYPE_DVD
)
3948 dvd_priv_t
* dvdp
= mpctx
->stream
->priv
;
3949 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3953 #endif /* CONFIG_GUI */
3955 } // while(!mpctx->stop_play)
3957 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->stop_play
);
3960 if(mpctx
->dvbin_reopen
)
3962 mpctx
->stop_play
= 0;
3963 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_GUI
|INITIALIZED_STREAM
|INITIALIZED_GETCH2
|(opts
->fixed_vo
?INITIALIZED_VO
:0)));
3964 cache_uninit(mpctx
->stream
);
3965 mpctx
->dvbin_reopen
= 0;
3966 goto goto_enable_cache
;
3971 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3973 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3976 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3977 double total_time_usage
;
3978 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3979 total_time_usage
= (float)total_time_usage_start
*0.000001;
3980 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3981 video_time_usage
,vout_time_usage
,audio_time_usage
,
3982 total_time_usage
-tot
,total_time_usage
);
3983 if(total_time_usage
>0.0)
3984 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3985 100.0*video_time_usage
/total_time_usage
,
3986 100.0*vout_time_usage
/total_time_usage
,
3987 100.0*audio_time_usage
/total_time_usage
,
3988 100.0*(total_time_usage
-tot
)/total_time_usage
,
3990 if(total_frame_cnt
&& frame_dropping
)
3991 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3992 total_frame_cnt
-drop_frame_cnt
,
3993 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3995 100*drop_frame_cnt
/total_frame_cnt
,
3997 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
4000 // time to uninit all, except global stuff:
4001 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_GUI
+(opts
->fixed_vo
?INITIALIZED_VO
:0)));
4003 if(mpctx
->set_of_sub_size
> 0) {
4004 current_module
="sub_free";
4005 for(i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
4006 sub_free(mpctx
->set_of_subtitles
[i
]);
4008 if(mpctx
->set_of_ass_tracks
[i
])
4009 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
4012 mpctx
->set_of_sub_size
= 0;
4014 vo_sub_last
= vo_sub
=NULL
;
4019 ass_clear_fonts(ass_library
);
4022 if (!mpctx
->stop_play
) // In case some goto jumped here...
4023 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4025 int playtree_direction
= 1;
4027 if(mpctx
->stop_play
== PT_NEXT_ENTRY
|| mpctx
->stop_play
== PT_PREV_ENTRY
) {
4028 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) != PLAY_TREE_ITER_ENTRY
) {
4029 play_tree_iter_free(mpctx
->playtree_iter
);
4030 mpctx
->playtree_iter
= NULL
;
4032 mpctx
->play_tree_step
= 1;
4033 } else if(mpctx
->stop_play
== PT_UP_NEXT
|| mpctx
->stop_play
== PT_UP_PREV
) {
4034 int direction
= mpctx
->stop_play
== PT_UP_NEXT
? 1 : -1;
4035 if(mpctx
->playtree_iter
) {
4036 if(play_tree_iter_up_step(mpctx
->playtree_iter
,direction
,0) != PLAY_TREE_ITER_ENTRY
) {
4037 play_tree_iter_free(mpctx
->playtree_iter
);
4038 mpctx
->playtree_iter
= NULL
;
4041 } else if (mpctx
->stop_play
== PT_STOP
) {
4042 play_tree_iter_free(mpctx
->playtree_iter
);
4043 mpctx
->playtree_iter
= NULL
;
4044 } else { // NEXT PREV SRC
4045 playtree_direction
= mpctx
->stop_play
== PT_PREV_SRC
? -1 : 1;
4048 while(mpctx
->playtree_iter
!= NULL
) {
4049 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, playtree_direction
);
4050 if(mpctx
->filename
== NULL
) {
4051 if(play_tree_iter_step(mpctx
->playtree_iter
, playtree_direction
, 0) != PLAY_TREE_ITER_ENTRY
) {
4052 play_tree_iter_free(mpctx
->playtree_iter
);
4053 mpctx
->playtree_iter
= NULL
;
4060 if(use_gui
&& !mpctx
->playtree_iter
) {
4061 #ifdef CONFIG_DVDREAD
4062 if(!guiIntfStruct
.DiskChanged
)
4068 if(use_gui
|| mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
4069 if(!mpctx
->playtree_iter
) mpctx
->filename
= NULL
;
4070 mpctx
->stop_play
= 0;
4071 goto play_next_file
;
4075 exit_player_with_rc(mpctx
, MSGTR_Exit_eof
, 0);
4079 #endif /* DISABLE_MAIN */