3 /// \ingroup Properties Command2Property OSDMsgStack
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
49 #include "m_property.h"
51 #include "cfg-mplayer-def.h"
53 #include "libavutil/intreadwrite.h"
55 #include "subreader.h"
58 #include "libvo/video_out.h"
60 #include "libvo/font_load.h"
61 #include "libvo/sub.h"
64 #include "libvo/x11_common.h"
67 #include "libao2/audio_out.h"
69 #include "codec-cfg.h"
76 #include "osdep/getch2.h"
77 #include "osdep/timer.h"
79 #include "cpudetect.h"
82 #include "gui/interface.h"
85 #include "input/input.h"
88 int player_idle_mode
=0;
90 int enable_mouse_movements
=0;
93 char * proc_priority
=NULL
;
98 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
102 #include <linux/rtc.h>
105 #define RTC_IRQP_SET RTCIO_IRQP_SET
106 #define RTC_PIE_ON RTCIO_PIE_ON
107 #endif /* __linux__ */
108 #endif /* HAVE_RTC */
111 #include "stream/tv.h"
114 #include "stream/stream_radio.h"
117 #ifdef HAS_DVBIN_SUPPORT
118 #include "stream/dvbin.h"
119 #include "stream/cache2.h"
122 //**************************************************************************//
124 //**************************************************************************//
125 #include "playtree.h"
126 #include "playtreeparser.h"
128 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
129 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
131 //**************************************************************************//
133 //**************************************************************************//
134 #include "parser-cfg.h"
135 #include "parser-mpcmd.h"
139 //**************************************************************************//
141 //**************************************************************************//
143 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
145 static int cfg_include(m_option_t
*conf
, char *filename
){
146 return m_config_parse_config_file(mconfig
, filename
);
149 #include "get_path.h"
151 //**************************************************************************//
153 //**************************************************************************//
155 void xscreensaver_heartbeat(struct vo_x11_state
*);
157 //**************************************************************************//
158 //**************************************************************************//
159 // Input media streaming & demultiplexer:
160 //**************************************************************************//
162 static int max_framesize
=0;
164 #include "stream/stream.h"
165 #include "libmpdemux/demuxer.h"
166 #include "libmpdemux/stheader.h"
169 #include "stream/stream_dvd.h"
173 #include "stream/stream_dvdnav.h"
176 #include "libmpcodecs/dec_audio.h"
177 #include "libmpcodecs/dec_video.h"
178 #include "libmpcodecs/mp_image.h"
179 #include "libmpcodecs/vf.h"
180 #include "libmpcodecs/vd.h"
186 #include "defaultopts.h"
188 //**************************************************************************//
189 //**************************************************************************//
191 // Common FIFO functions, and keyboard/event FIFO code
193 int noconsolecontrols
=0;
194 //**************************************************************************//
197 double video_time_usage
=0;
198 double vout_time_usage
=0;
199 static double audio_time_usage
=0;
200 static int total_time_usage_start
=0;
201 static int total_frame_cnt
=0;
202 static int drop_frame_cnt
=0; // total number of dropped frames
207 static int output_quality
=0;
215 static int list_properties
= 0;
218 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
219 unsigned int osd_visible
;
220 int osd_duration
= 1000;
223 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
224 static char* playing_msg
= NULL
;
226 static double seek_to_sec
;
227 static off_t seek_to_byte
=0;
228 static off_t step_sec
=0;
229 static int loop_seek
=0;
231 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
234 int autosync
=0; // 30 might be a good default value.
237 char **audio_codec_list
=NULL
; // override audio codec
238 char **video_codec_list
=NULL
; // override video codec
239 char **audio_fm_list
=NULL
; // override audio codec family
240 char **video_fm_list
=NULL
; // override video codec family
243 extern char *demuxer_name
; // override demuxer
244 extern char *audio_demuxer_name
; // override audio demuxer
245 extern char *sub_demuxer_name
; // override sub demuxer
248 char* audio_lang
=NULL
;
249 char* dvdsub_lang
=NULL
;
250 static char* spudec_ifo
=NULL
;
251 char* filename
=NULL
; //"MI2-Trailer.avi";
252 int forced_subs_only
=0;
256 int stream_cache_size
=-1;
257 #ifdef USE_STREAM_CACHE
258 extern int cache_fill_status
;
260 float stream_cache_min_percent
=20.0;
261 float stream_cache_seek_min_percent
=50.0;
263 #define cache_fill_status 0
267 static char *stream_dump_name
="stream.dump";
268 int stream_dump_type
=0;
271 static float default_max_pts_correction
=-1;//0.01f;
272 static float max_pts_correction
=0;//default_max_pts_correction;
273 static float c_total
=0;
275 static int ignore_start
=0;
277 static int softsleep
=0;
280 static int force_srate
=0;
281 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
282 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
283 static int play_n_frames
=-1;
284 static int play_n_frames_mf
=-1;
287 char *font_name
=NULL
;
288 char *sub_font_name
=NULL
;
289 extern int font_fontconfig
;
290 float font_factor
=0.75;
291 char **sub_name
=NULL
;
295 char *vobsub_name
=NULL
;
296 /*DSP!!char *dsp=NULL;*/
298 int suboverlap_enabled
= 1;
301 #include "libass/ass.h"
302 #include "libass/ass_mp.h"
305 char* current_module
=NULL
; // for debugging
311 #include "m_struct.h"
312 #include "libmenu/menu.h"
313 extern void vf_menu_pause_update(struct vf_instance
* vf
);
314 extern vf_info_t vf_info_menu
;
315 static vf_info_t
* libmenu_vfs
[] = {
319 static vf_instance_t
* vf_menu
= NULL
;
321 static char* menu_cfg
= NULL
;
322 static char* menu_root
= "main";
327 static int nortc
= 1;
328 static char* rtc_device
;
331 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
332 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
333 short edl_decision
= 0; ///< 1 when an EDL operation has been made.
334 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
335 int use_filedir_conf
;
337 static unsigned int initialized_flags
=0;
338 #include "mpcommon.h"
341 #include "metadata.h"
343 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
345 const void *mpctx_get_video_out(MPContext
*mpctx
)
347 return mpctx
->video_out
;
350 void *mpctx_get_audio_out(MPContext
*mpctx
)
352 return mpctx
->audio_out
;
355 void *mpctx_get_demuxer(MPContext
*mpctx
)
357 return mpctx
->demuxer
;
360 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
362 return mpctx
->playtree_iter
;
365 void *mpctx_get_mixer(MPContext
*mpctx
)
367 return &mpctx
->mixer
;
370 int mpctx_get_global_sub_size(MPContext
*mpctx
)
372 return mpctx
->global_sub_size
;
375 int mpctx_get_osd_function(MPContext
*mpctx
)
377 return mpctx
->osd_function
;
380 static int is_valid_metadata_type(struct MPContext
*mpctx
, metadata_t type
) {
383 /* check for valid video stream */
384 case META_VIDEO_CODEC
:
385 case META_VIDEO_BITRATE
:
386 case META_VIDEO_RESOLUTION
:
388 if (!mpctx
->sh_video
)
393 /* check for valid audio stream */
394 case META_AUDIO_CODEC
:
395 case META_AUDIO_BITRATE
:
396 case META_AUDIO_SAMPLES
:
398 if (!mpctx
->sh_audio
)
403 /* check for valid demuxer */
404 case META_INFO_TITLE
:
405 case META_INFO_ARTIST
:
406 case META_INFO_ALBUM
:
408 case META_INFO_COMMENT
:
409 case META_INFO_TRACK
:
410 case META_INFO_GENRE
:
424 static char *get_demuxer_info(struct MPContext
*mpctx
, char *tag
) {
425 char **info
= mpctx
->demuxer
->info
;
431 for (n
= 0; info
[2*n
] != NULL
; n
++)
432 if (!strcmp (info
[2*n
], tag
))
435 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
438 char *get_metadata(struct MPContext
*mpctx
, metadata_t type
)
441 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
442 sh_video_t
* const sh_video
= mpctx
->sh_video
;
444 if (!is_valid_metadata_type(mpctx
, type
))
451 return strdup (mp_basename2 (filename
));
454 case META_VIDEO_CODEC
:
456 if (sh_video
->format
== 0x10000001)
457 meta
= strdup ("mpeg1");
458 else if (sh_video
->format
== 0x10000002)
459 meta
= strdup ("mpeg2");
460 else if (sh_video
->format
== 0x10000004)
461 meta
= strdup ("mpeg4");
462 else if (sh_video
->format
== 0x10000005)
463 meta
= strdup ("h264");
464 else if (sh_video
->format
>= 0x20202020)
467 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
472 sprintf (meta
, "0x%08X", sh_video
->format
);
477 case META_VIDEO_BITRATE
:
480 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
484 case META_VIDEO_RESOLUTION
:
487 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
491 case META_AUDIO_CODEC
:
493 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
494 meta
= strdup (sh_audio
->codec
->name
);
498 case META_AUDIO_BITRATE
:
501 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
505 case META_AUDIO_SAMPLES
:
508 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
512 /* check for valid demuxer */
513 case META_INFO_TITLE
:
514 return get_demuxer_info(mpctx
, "Title");
516 case META_INFO_ARTIST
:
517 return get_demuxer_info(mpctx
, "Artist");
519 case META_INFO_ALBUM
:
520 return get_demuxer_info(mpctx
, "Album");
523 return get_demuxer_info(mpctx
, "Year");
525 case META_INFO_COMMENT
:
526 return get_demuxer_info(mpctx
, "Comment");
528 case META_INFO_TRACK
:
529 return get_demuxer_info(mpctx
, "Track");
531 case META_INFO_GENRE
:
532 return get_demuxer_info(mpctx
, "Genre");
541 /// step size of mixer changes
545 static void mp_dvdnav_context_free(MPContext
*ctx
){
546 if (ctx
->nav_smpi
) free_mp_image(ctx
->nav_smpi
);
547 ctx
->nav_smpi
= NULL
;
548 if (ctx
->nav_buffer
) free(ctx
->nav_buffer
);
549 ctx
->nav_buffer
= NULL
;
550 ctx
->nav_start
= NULL
;
551 ctx
->nav_in_size
= 0;
555 void uninit_player(struct MPContext
*mpctx
, unsigned int mask
){
556 mask
=initialized_flags
&mask
;
558 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
560 if(mask
&INITIALIZED_ACODEC
){
561 initialized_flags
&=~INITIALIZED_ACODEC
;
562 current_module
="uninit_acodec";
563 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
565 if (use_gui
) guiGetEvent(guiSetAfilter
, (char *)NULL
);
567 mpctx
->sh_audio
=NULL
;
568 mpctx
->mixer
.afilter
= NULL
;
571 if(mask
&INITIALIZED_VCODEC
){
572 initialized_flags
&=~INITIALIZED_VCODEC
;
573 current_module
="uninit_vcodec";
574 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
575 mpctx
->sh_video
=NULL
;
581 if(mask
&INITIALIZED_DEMUXER
){
582 initialized_flags
&=~INITIALIZED_DEMUXER
;
583 current_module
="free_demuxer";
585 mpctx
->stream
=mpctx
->demuxer
->stream
;
586 free_demuxer(mpctx
->demuxer
);
591 // kill the cache process:
592 if(mask
&INITIALIZED_STREAM
){
593 initialized_flags
&=~INITIALIZED_STREAM
;
594 current_module
="uninit_stream";
595 if(mpctx
->stream
) free_stream(mpctx
->stream
);
599 if(mask
&INITIALIZED_VO
){
600 initialized_flags
&=~INITIALIZED_VO
;
601 current_module
="uninit_vo";
602 vo_destroy(mpctx
->video_out
);
603 mpctx
->video_out
=NULL
;
605 mp_dvdnav_context_free(mpctx
);
609 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
610 if(mask
&INITIALIZED_GETCH2
){
611 initialized_flags
&=~INITIALIZED_GETCH2
;
612 current_module
="uninit_getch2";
613 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
618 if(mask
&INITIALIZED_VOBSUB
){
619 initialized_flags
&=~INITIALIZED_VOBSUB
;
620 current_module
="uninit_vobsub";
621 if(vo_vobsub
) vobsub_close(vo_vobsub
);
625 if (mask
&INITIALIZED_SPUDEC
){
626 initialized_flags
&=~INITIALIZED_SPUDEC
;
627 current_module
="uninit_spudec";
628 spudec_free(vo_spudec
);
632 if(mask
&INITIALIZED_AO
){
633 initialized_flags
&=~INITIALIZED_AO
;
634 current_module
="uninit_ao";
635 if (mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
636 mpctx
->audio_out
->uninit(mpctx
->eof
?0:1); mpctx
->audio_out
=NULL
;
640 if(mask
&INITIALIZED_GUI
){
641 initialized_flags
&=~INITIALIZED_GUI
;
642 current_module
="uninit_gui";
647 if(mask
&INITIALIZED_INPUT
){
648 initialized_flags
&=~INITIALIZED_INPUT
;
649 current_module
="uninit_input";
660 void exit_player_with_rc(struct MPContext
*mpctx
, const char* how
, int rc
){
662 if (mpctx
->user_muted
&& !mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
663 uninit_player(mpctx
, INITIALIZED_ALL
);
668 vo_uninit(mpctx
->x11_state
); // Close the X11 connection (if any is open).
672 current_module
="uninit_font";
673 if (sub_font
&& sub_font
!= vo_font
) free_font_desc(sub_font
);
675 if (vo_font
) free_font_desc(vo_font
);
682 ass_library_done(ass_library
);
685 current_module
="exit_player";
687 // free mplayer config
689 m_config_free(mconfig
);
692 play_tree_free(mpctx
->playtree
, 1);
695 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
696 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,how
);
697 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
702 static void exit_player(struct MPContext
*mpctx
, const char* how
)
704 exit_player_with_rc(mpctx
, how
, 1);
708 static void child_sighandler(int x
){
710 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
715 static char *prog_path
;
716 static int crash_debug
= 0;
719 static void exit_sighandler(int x
){
720 static int sig_count
=0;
722 if (!crash_debug
|| x
!= SIGTRAP
)
725 if(initialized_flags
==0 && sig_count
>1) exit(1);
728 /* We're crashing bad and can't uninit cleanly :(
729 * by popular request, we make one last (dirty)
730 * effort to restore the user's
735 if(sig_count
==6) exit(1);
739 kill(getpid(),SIGKILL
);
742 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
743 current_module
?current_module
:"unknown"
745 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
752 async_quit_request
= 1;
753 return; // killed from keyboard (^C) or killed [-9]
755 #ifdef RUNTIME_CPUDETECT
756 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
758 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
762 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
764 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
768 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
770 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
771 if (gdb_pid
== 0) { // We are the child
773 snprintf(spid
, sizeof(spid
), "%i", getppid());
774 getch2_disable(); // allow terminal to work properly with gdb
775 if (execlp("gdb", "gdb", prog_path
, spid
, "-ex", "bt", NULL
) == -1)
776 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
777 } else if (gdb_pid
< 0)
778 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
780 waitpid(gdb_pid
, NULL
, 0);
782 if (x
== SIGTRAP
) return;
790 extern void mp_input_register_options(m_config_t
* cfg
);
792 #include "cfg-mplayer.h"
794 static void parse_cfgfiles(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 (filename
, '.');
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 eof
)
929 if((cmd
= mp_input_get_cmd(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 eof
= (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 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
940 case MP_CMD_PLAY_ALT_SRC_STEP
: {
941 eof
= (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
,filename
);
958 import_playtree_playlist_into_gui(entry
, 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 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
);
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
);
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 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(HAVE_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(WIN32) || 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 USE_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 static char osd_text
[64] = "";
1493 static char osd_text_timer
[64];
1495 // we need some mem for vo_osd_text
1496 vo_osd_text
= (unsigned char*)osd_text
;
1498 // Look if we have a msg
1499 if((msg
= get_osd_msg(mpctx
))) {
1500 if(strcmp(osd_text
,msg
->msg
)) {
1501 strncpy((char*)osd_text
, msg
->msg
, 63);
1502 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1503 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1508 if(mpctx
->sh_video
) {
1509 // fallback on the timer
1511 int len
= demuxer_get_time_length(mpctx
->demuxer
);
1512 int percentage
= -1;
1513 char percentage_text
[10];
1514 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1516 if (mpctx
->osd_show_percentage
)
1517 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1519 if (percentage
>= 0)
1520 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1522 percentage_text
[0] = 0;
1525 snprintf(osd_text_timer
, 63,
1526 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1527 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1528 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1530 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1531 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1532 pts
%60,percentage_text
);
1534 osd_text_timer
[0]=0;
1536 // always decrement the percentage timer
1537 if(mpctx
->osd_show_percentage
)
1538 mpctx
->osd_show_percentage
--;
1540 if(strcmp(osd_text
,osd_text_timer
)) {
1541 strncpy(osd_text
, osd_text_timer
, 63);
1542 vo_osd_changed(OSDTYPE_OSD
);
1547 // Clear the term osd line
1548 if(term_osd
&& osd_text
[0]) {
1550 printf("%s\n",term_osd_esc
);
1558 void reinit_audio_chain(struct MPContext
*mpctx
)
1560 struct MPOpts
*opts
= &mpctx
->opts
;
1561 if(mpctx
->sh_audio
){
1562 current_module
="init_audio_codec";
1563 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1564 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1565 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // failed to init :(
1566 mpctx
->d_audio
->id
= -2;
1569 initialized_flags
|=INITIALIZED_ACODEC
;
1570 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1573 //const ao_info_t *info=audio_out->info;
1574 current_module
="af_preinit";
1575 ao_data
.samplerate
=force_srate
;
1577 ao_data
.format
=audio_output_format
;
1579 // first init to detect best values
1580 if(!init_audio_filters(mpctx
->sh_audio
, // preliminary init
1582 mpctx
->sh_audio
->samplerate
,
1584 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1585 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
1586 exit_player(mpctx
, MSGTR_Exit_error
);
1589 current_module
="ao2_init";
1590 if(!(mpctx
->audio_out
=init_best_audio_out(opts
->audio_driver_list
,
1594 ao_data
.format
,0))){
1596 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1597 uninit_player(mpctx
, INITIALIZED_ACODEC
); // close codec
1598 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1599 mpctx
->d_audio
->id
= -2;
1603 initialized_flags
|=INITIALIZED_AO
;
1604 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1605 mpctx
->audio_out
->info
->short_name
,
1606 ao_data
.samplerate
, ao_data
.channels
,
1607 af_fmt2str_short(ao_data
.format
),
1608 af_fmt2bits(ao_data
.format
)/8 );
1609 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1610 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1611 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1612 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1613 // init audio filters:
1615 current_module
="af_init";
1616 if(!build_afilter_chain(mpctx
, mpctx
->sh_audio
, &ao_data
)) {
1617 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
1618 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1619 // uninit_player(mpctx, INITIALIZED_ACODEC|INITIALIZED_AO); // close codec & ao
1620 // sh_audio=mpctx->d_audio->sh=NULL; // -> nosound
1624 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1625 mpctx
->mixer
.volstep
= volstep
;
1634 // Return pts value corresponding to the end point of audio written to the
1636 static double written_audio_pts(struct MPContext
*mpctx
)
1638 sh_audio_t
*sh_audio
= mpctx
->sh_audio
;
1639 demux_stream_t
*d_audio
= mpctx
->d_audio
;
1640 double buffered_output
;
1641 // first calculate the end pts of audio that has been output by decoder
1642 double a_pts
= sh_audio
->pts
;
1643 if (a_pts
!= MP_NOPTS_VALUE
)
1644 // Good, decoder supports new way of calculating audio pts.
1645 // sh_audio->pts is the timestamp of the latest input packet with
1646 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1647 // the amount of bytes the decoder has written after that timestamp.
1648 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1650 // Decoder doesn't support new way of calculating pts (or we're
1651 // being called before it has decoded anything with known timestamp).
1652 // Use the old method of audio pts calculation: take the timestamp
1653 // of last packet with known pts the decoder has read data from,
1654 // and add amount of bytes read after the beginning of that packet
1655 // divided by input bps. This will be inaccurate if the input/output
1656 // ratio is not constant for every audio packet or if it is constant
1657 // but not accurately known in sh_audio->i_bps.
1659 a_pts
= d_audio
->pts
;
1660 // ds_tell_pts returns bytes read after last timestamp from
1661 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1662 // it has read but not decoded
1663 if (sh_audio
->i_bps
)
1664 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1665 (double)sh_audio
->i_bps
;
1667 // Now a_pts hopefully holds the pts for end of audio from decoder.
1668 // Substract data in buffers between decoder and audio out.
1670 // Decoded but not filtered
1671 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1673 // Data buffered in audio filters, measured in bytes of "missing" output
1674 buffered_output
= af_calc_delay(sh_audio
->afilter
);
1676 // Data that was ready for ao but was buffered because ao didn't fully
1677 // accept everything to internal buffers yet
1678 buffered_output
+= sh_audio
->a_out_buffer_len
;
1680 // Filters divide audio length by playback_speed, so multiply by it
1681 // to get the length in original units without speedup or slowdown
1682 a_pts
-= buffered_output
* mpctx
->opts
.playback_speed
/ ao_data
.bps
;
1687 // Return pts value corresponding to currently playing audio.
1688 double playing_audio_pts(struct MPContext
*mpctx
)
1690 return written_audio_pts(mpctx
) - mpctx
->opts
.playback_speed
*
1691 mpctx
->audio_out
->get_delay();
1694 static int check_framedrop(struct MPContext
*mpctx
, double frame_time
) {
1695 struct MPOpts
*opts
= &mpctx
->opts
;
1696 // check for frame-drop:
1697 current_module
= "check_framedrop";
1698 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1699 static int dropped_frames
;
1700 float delay
= opts
->playback_speed
*mpctx
->audio_out
->get_delay();
1701 float d
= delay
-mpctx
->delay
;
1703 // we should avoid dropping too many frames in sequence unless we
1704 // are too late. and we allow 100ms A-V delay here:
1705 if (d
< -dropped_frames
*frame_time
-0.100 &&
1706 mpctx
->osd_function
!= OSD_PAUSE
) {
1709 return frame_dropping
;
1716 static int generate_video_frame(struct MPContext
*mpctx
)
1718 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1719 demux_stream_t
*d_video
= mpctx
->d_video
;
1721 unsigned char *start
;
1727 int drop_frame
= check_framedrop(mpctx
, sh_video
->frametime
);
1728 void *decoded_frame
;
1729 current_module
= "decode video";
1730 // XXX Time used in this call is not counted in any performance
1731 // timer now, OSD is not updated correctly for filter-added frames
1732 if (vf_output_queued_frame(sh_video
->vfilter
))
1734 current_module
= "video_read_frame";
1735 in_size
= ds_get_packet_pts(d_video
, &start
, &pts
);
1737 // try to extract last frames in case of decoder lag
1742 if (in_size
> max_framesize
)
1743 max_framesize
= in_size
;
1744 current_module
= "decode video";
1745 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
, pts
);
1746 if (decoded_frame
) {
1747 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
1748 update_teletext(sh_video
, mpctx
->demuxer
, 0);
1749 update_osd_msg(mpctx
);
1750 current_module
= "filter video";
1751 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
1753 } else if (drop_frame
)
1765 static float timing_sleep(float time_frame
)
1769 // -------- RTC -----------
1770 current_module
="sleep_rtc";
1771 while (time_frame
> 0.000) {
1772 unsigned long rtc_ts
;
1773 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1774 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
1775 time_frame
-= GetRelativeTime();
1780 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1781 // unnecessarily high CPU usage
1782 float margin
= softsleep
? 0.011 : 0;
1783 current_module
= "sleep_timer";
1784 while (time_frame
> margin
) {
1785 usec_sleep(1000000 * (time_frame
- margin
));
1786 time_frame
-= GetRelativeTime();
1789 current_module
= "sleep_soft";
1791 mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
1792 while (time_frame
> 0)
1793 time_frame
-=GetRelativeTime(); // burn the CPU
1803 /// store decoded video image
1804 static mp_image_t
* mp_dvdnav_copy_mpi(mp_image_t
*to_mpi
,
1805 mp_image_t
*from_mpi
) {
1808 /// Do not store B-frames
1809 if (from_mpi
->pict_type
== FF_B_TYPE
)
1813 to_mpi
->w
== from_mpi
->w
&&
1814 to_mpi
->h
== from_mpi
->h
&&
1815 to_mpi
->imgfmt
== from_mpi
->imgfmt
)
1819 free_mp_image(to_mpi
);
1820 if (from_mpi
->w
== 0 || from_mpi
->h
== 0)
1822 mpi
= alloc_mpi(from_mpi
->w
,from_mpi
->h
,from_mpi
->imgfmt
);
1825 copy_mpi(mpi
,from_mpi
);
1829 static void mp_dvdnav_reset_stream (MPContext
*ctx
) {
1830 if (ctx
->sh_video
) {
1832 ctx
->d_video
->pts
= 0.0f
;
1833 ctx
->sh_video
->pts
= 0.0f
;
1834 ctx
->sh_video
->i_pts
= 0.0f
;
1835 ctx
->sh_video
->last_pts
= 0.0f
;
1836 ctx
->sh_video
->num_buffered_pts
= 0;
1837 ctx
->sh_video
->num_frames
= 0;
1838 ctx
->sh_video
->num_frames_decoded
= 0;
1839 ctx
->sh_video
->timer
= 0.0f
;
1840 ctx
->sh_video
->stream_delay
= 0.0f
;
1841 ctx
->sh_video
->timer
= 0;
1842 ctx
->demuxer
->stream_pts
= MP_NOPTS_VALUE
;
1845 if (ctx
->sh_audio
) {
1846 /// free audio packets and reset
1847 ds_free_packs(ctx
->d_audio
);
1848 audio_delay
-= ctx
->sh_audio
->stream_delay
;
1849 ctx
->delay
=- audio_delay
;
1850 ctx
->audio_out
->reset();
1851 resync_audio_stream(ctx
->sh_audio
);
1854 if (ctx
->d_sub
) opts
->sub_id
= -2;
1858 /// clear all EOF related flags
1859 ctx
->d_video
->eof
= ctx
->d_audio
->eof
= ctx
->stream
->eof
= 0;
1862 /// Restore last decoded DVDNAV (still frame)
1863 static mp_image_t
*mp_dvdnav_restore_smpi(int *in_size
,
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(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 /* USE_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
-= GetRelativeTime(); // 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(*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
|| !(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
))){
2143 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
2146 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
=(void*)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
=(void*)vf_menu
;
2174 for (i
= 0; vf_settings
[i
].name
; ++i
)
2175 if (strcmp(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
=(void*)vf_ass
;
2187 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
2192 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
2196 ((vf_instance_t
*)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 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 if (!opts
->correct_pts
) {
2247 unsigned char* start
=NULL
;
2248 void *decoded_frame
= NULL
;
2252 current_module
= "video_read_frame";
2253 frame_time
= sh_video
->next_frame_time
;
2254 in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2257 /// wait, still frame or EOF
2258 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
&& in_size
< 0) {
2259 if (mp_dvdnav_is_eof(mpctx
->stream
)) return -1;
2260 if (mpctx
->d_video
) mpctx
->d_video
->eof
= 0;
2261 if (mpctx
->d_audio
) mpctx
->d_audio
->eof
= 0;
2262 mpctx
->stream
->eof
= 0;
2267 if (in_size
> max_framesize
)
2268 max_framesize
= in_size
; // stats
2269 sh_video
->timer
+= frame_time
;
2270 if (mpctx
->sh_audio
)
2271 mpctx
->delay
-= frame_time
;
2272 // video_read_frame can change fps (e.g. for ASF video)
2273 vo_fps
= sh_video
->fps
;
2274 drop_frame
= check_framedrop(mpctx
, frame_time
);
2275 update_subtitles(sh_video
, mpctx
->d_sub
, 0);
2276 update_teletext(sh_video
, mpctx
->demuxer
, 0);
2277 update_osd_msg(mpctx
);
2278 current_module
= "decode_video";
2280 decoded_frame
= mp_dvdnav_restore_smpi(&in_size
,&start
,decoded_frame
);
2281 /// still frame has been reached, no need to decode
2282 if (in_size
> 0 && !decoded_frame
)
2284 decoded_frame
= decode_video(sh_video
, start
, in_size
, drop_frame
,
2287 /// save back last still frame for future display
2288 mp_dvdnav_save_smpi(in_size
,start
,decoded_frame
);
2290 current_module
= "filter_video";
2291 *blit_frame
= (decoded_frame
&& filter_video(sh_video
, decoded_frame
,
2295 int res
= generate_video_frame(mpctx
);
2298 ((vf_instance_t
*)sh_video
->vfilter
)->control(sh_video
->vfilter
,
2299 VFCTRL_GET_PTS
, &sh_video
->pts
);
2300 if (sh_video
->pts
== MP_NOPTS_VALUE
) {
2301 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "pts after filters MISSING\n");
2302 sh_video
->pts
= sh_video
->last_pts
;
2304 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2305 sh_video
->last_pts
= sh_video
->pts
;
2306 else if (sh_video
->last_pts
>= sh_video
->pts
) {
2307 sh_video
->last_pts
= sh_video
->pts
;
2308 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "pts value <= previous\n");
2310 frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2311 sh_video
->last_pts
= sh_video
->pts
;
2312 sh_video
->timer
+= frame_time
;
2314 mpctx
->delay
-= frame_time
;
2315 *blit_frame
= res
> 0;
2320 static void pause_loop(struct MPContext
*mpctx
)
2324 // Small hack to display the pause message on the OSD line.
2325 // The pause string is: "\n == PAUSE == \r" so we need to
2326 // take the first and the last char out
2327 if (term_osd
&& !mpctx
->sh_video
) {
2328 char msg
[128] = MSGTR_Paused
;
2329 int mlen
= strlen(msg
);
2331 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2332 update_osd_msg(mpctx
);
2334 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2335 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2339 guiGetEvent(guiCEvent
, (char *)guiSetPause
);
2341 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2342 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2344 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2345 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2347 while ( (cmd
= mp_input_get_cmd(20, 1, 1)) == NULL
2348 || cmd
->id
== MP_CMD_SET_MOUSE_POS
) {
2350 cmd
= mp_input_get_cmd(0,1,0);
2354 if (mpctx
->sh_video
&& mpctx
->video_out
)
2355 vo_check_events(mpctx
->video_out
);
2359 guiGetEvent(guiReDraw
, NULL
);
2360 if (guiIntfStruct
.Playing
!=2 || (mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
))
2366 vf_menu_pause_update(vf_menu
);
2370 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
2371 cmd
= mp_input_get_cmd(0,1,0);
2374 mpctx
->osd_function
=OSD_PLAY
;
2375 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2376 mpctx
->audio_out
->resume(); // resume audio
2377 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2378 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
); // resume video
2379 (void)GetRelativeTime(); // ignore time that passed during pause
2382 if (guiIntfStruct
.Playing
== guiSetStop
)
2385 guiGetEvent(guiCEvent
, (char *)guiSetPlay
);
2390 void print_version(void){
2391 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s\n", MP_TITLE
);
2393 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
2394 GetCpuCaps(&gCpuCaps
);
2396 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
2397 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
2398 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
2399 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
2400 #ifdef RUNTIME_CPUDETECT
2401 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
2403 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
2405 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
2408 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
2411 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
2414 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
2417 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
2420 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
2422 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
2423 #endif /* RUNTIME_CPUDETECT */
2424 #endif /* ARCH_X86 */
2428 // Find the right mute status and record position for new file position
2429 static void edl_seek_reset(MPContext
*mpctx
)
2431 mpctx
->edl_muted
= 0;
2432 next_edl_record
= edl_records
;
2434 while (next_edl_record
) {
2435 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2438 if (next_edl_record
->action
== EDL_MUTE
)
2439 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2440 next_edl_record
= next_edl_record
->next
;
2442 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2443 mixer_mute(&mpctx
->mixer
);
2447 // Execute EDL command for the current position if one exists
2448 static void edl_update(MPContext
*mpctx
)
2450 if (!next_edl_record
)
2453 if (!mpctx
->sh_video
) {
2454 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
2455 free_edl(edl_records
);
2456 next_edl_record
= NULL
;
2461 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2462 if (next_edl_record
->action
== EDL_SKIP
) {
2463 mpctx
->osd_function
= OSD_FFW
;
2464 mpctx
->abs_seek_pos
= 0;
2465 mpctx
->rel_seek_secs
= next_edl_record
->length_sec
;
2466 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2467 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2468 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2471 else if (next_edl_record
->action
== EDL_MUTE
) {
2472 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2473 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2474 mixer_mute(&mpctx
->mixer
);
2475 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2476 next_edl_record
->start_sec
);
2478 next_edl_record
= next_edl_record
->next
;
2483 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute
2484 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length
2485 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2486 static int seek(MPContext
*mpctx
, double amount
, int style
)
2488 current_module
= "seek";
2489 if (demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
) == 0)
2492 if (mpctx
->sh_video
) {
2493 current_module
= "seek_video_reset";
2494 resync_video_stream(mpctx
->sh_video
);
2495 if (mpctx
->video_out
->config_ok
)
2496 vo_control(mpctx
->video_out
, VOCTRL_RESET
, NULL
);
2497 mpctx
->sh_video
->num_buffered_pts
= 0;
2498 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2499 mpctx
->num_buffered_frames
= 0;
2501 // Not all demuxers set d_video->pts during seek, so this value
2502 // (which is used by at least vobsub and edl code below) may
2503 // be completely wrong (probably 0).
2504 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
;
2505 update_subtitles(mpctx
->sh_video
, mpctx
->d_sub
, 1);
2506 update_teletext(mpctx
->sh_video
, mpctx
->demuxer
, 1);
2509 if (mpctx
->sh_audio
) {
2510 current_module
= "seek_audio_reset";
2511 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2512 mpctx
->sh_audio
->a_buffer_len
= 0;
2513 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2516 if (vo_vobsub
&& mpctx
->sh_video
) {
2517 current_module
= "seek_vobsub_reset";
2518 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2521 edl_seek_reset(mpctx
);
2524 max_pts_correction
= 0.1;
2525 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2528 current_module
= NULL
;
2533 static void read_keys(void *ctx
)
2539 int main(int argc
,char* argv
[]){
2546 /* Flag indicating whether MPlayer should exit without playing anything. */
2549 //float a_frame=0; // Audio
2553 int gui_no_filename
=0;
2555 srand((int) time(NULL
));
2557 struct MPContext
*mpctx
= &(struct MPContext
){
2558 .osd_function
= OSD_PLAY
,
2559 .begin_skip
= MP_NOPTS_VALUE
,
2560 .play_tree_step
= 1,
2561 .global_sub_pos
= -1,
2562 .set_of_sub_pos
= -1,
2563 .file_format
= DEMUXER_TYPE_UNKNOWN
,
2572 mpctx
->x11_state
= talloc_ptrtype(NULL
, mpctx
->x11_state
);
2573 vo_x11_init_state(mpctx
->x11_state
);
2575 struct MPOpts
*opts
= &mpctx
->opts
;
2576 set_default_mplayer_options(opts
);
2577 // Create the config context and register the options
2578 mconfig
= m_config_new(opts
);
2579 m_config_register_options(mconfig
,mplayer_opts
);
2580 mp_input_register_options(mconfig
);
2582 // Preparse the command line
2583 m_config_preparse_command_line(mconfig
,argc
,argv
);
2586 #if defined(WIN32) && defined(USE_WIN32DLL)
2588 #endif /*WIN32 && USE_WIN32DLL*/
2591 stream_tv_defaults
.immediate
= 1;
2594 if (argc
> 1 && argv
[1] &&
2595 (!strcmp(argv
[1], "-gui") || !strcmp(argv
[1], "-nogui"))) {
2596 use_gui
= !strcmp(argv
[1], "-gui");
2600 char *base
= strrchr(argv
[0], '/');
2602 base
= strrchr(argv
[0], '\\');
2605 if(strstr(base
, "gmplayer"))
2609 parse_cfgfiles(mpctx
, mconfig
);
2612 if ( use_gui
) cfg_read();
2615 mpctx
->playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
2616 if(mpctx
->playtree
== NULL
)
2619 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
2620 if(mpctx
->playtree
) {
2621 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
2622 if(mpctx
->playtree_iter
) {
2623 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2624 play_tree_iter_free(mpctx
->playtree_iter
);
2625 mpctx
->playtree_iter
= NULL
;
2627 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2632 #if defined(WIN32) && defined(HAVE_NEW_GUI)
2633 void *runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
2634 if(runningmplayer
&& filename
&& use_gui
){
2635 COPYDATASTRUCT csData
;
2636 char file
[MAX_PATH
];
2637 char *filepart
= filename
;
2638 if(GetFullPathName(filename
, MAX_PATH
, file
, &filepart
)){
2640 csData
.cbData
= strlen(file
)*2;
2641 csData
.lpData
= file
;
2642 SendMessage(runningmplayer
, WM_COPYDATA
, (WPARAM
)runningmplayer
, (LPARAM
)&csData
);
2650 for(i
=0; priority_presets_defs
[i
].name
; i
++){
2651 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
2654 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
2655 priority_presets_defs
[i
].name
);
2656 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
2659 #ifndef HAVE_NEW_GUI
2661 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
2666 if(use_gui
&& !vo_init()){
2667 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
2671 if (use_gui
&& mpctx
->playtree_iter
){
2672 char cwd
[PATH_MAX
+2];
2673 // Free Playtree and Playtree-Iter as it's not used by the GUI.
2674 play_tree_iter_free(mpctx
->playtree_iter
);
2675 mpctx
->playtree_iter
=NULL
;
2677 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
2680 // Prefix relative paths with current working directory
2681 play_tree_add_bpf(mpctx
->playtree
, cwd
);
2683 // Import initital playtree into GUI.
2684 import_initial_playtree_into_gui(mpctx
->playtree
, mconfig
, enqueue
);
2686 #endif /* HAVE_NEW_GUI */
2688 if(opts
->video_driver_list
&& strcmp(opts
->video_driver_list
[0],"help")==0){
2693 if(opts
->audio_driver_list
&& strcmp(opts
->audio_driver_list
[0],"help")==0){
2698 /* Check codecs.conf. */
2699 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2700 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2701 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2702 if(!parse_codec_cfg(NULL
)){
2703 exit_player_with_rc(mpctx
, NULL
, 0);
2705 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
2708 free( mem_ptr
); // release the buffer created by get_path()
2712 if(video_codec_list
){
2714 video_codec
=video_codec_list
[0];
2715 for(i
=0;video_codec_list
[i
];i
++)
2716 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2719 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2720 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
2721 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2723 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2726 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2727 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
2728 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2730 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2733 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2735 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2738 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
2740 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2743 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
2749 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
2751 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2755 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
2756 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
2757 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
2759 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2762 if(list_properties
) {
2763 property_print_help();
2768 exit_player(mpctx
, NULL
);
2770 if (player_idle_mode
&& use_gui
) {
2771 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_NoIdleAndGui
);
2772 exit_player_with_rc(mpctx
, NULL
, 1);
2775 if(!filename
&& !player_idle_mode
){
2777 // no file/vcd/dvd -> show HELP:
2778 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
2779 exit_player_with_rc(mpctx
, NULL
, 0);
2780 } else gui_no_filename
=1;
2783 /* Display what configure line was used */
2784 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
2786 // Many users forget to include command line in bugreports...
2787 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
2788 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
2789 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
2790 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
2793 //------ load global data first ------
2796 #ifdef HAVE_FREETYPE
2799 #ifdef HAVE_FONTCONFIG
2800 if(font_fontconfig
<= 0)
2803 #ifdef HAVE_BITMAP_FONT
2805 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
2806 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,
2807 filename_recode(font_name
));
2810 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
2811 free(mem_ptr
); // release the buffer created by get_path()
2813 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
2816 sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
2820 #ifdef HAVE_FONTCONFIG
2827 ass_library
= ass_init();
2833 // seteuid(0); /* Can't hurt to try to get root here */
2834 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
2835 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
2836 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
2838 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
2840 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
2841 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
2842 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
2845 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
2846 /* variable only by the root */
2847 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
2851 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
2855 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
2856 // and now ? -- Pontscho
2857 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
2860 #endif /* HAVE_RTC */
2861 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
2862 softsleep
?"software":timer_name
);
2865 if ( !use_gui
) load_termcap(NULL
); // load key-codes
2868 // ========== Init keyboard FIFO (connection to libvo) ============
2870 // Init input system
2871 current_module
= "init_input";
2872 mp_input_init(use_gui
);
2873 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
2875 mp_input_add_cmd_fd(0,USE_SELECT
,MP_INPUT_SLAVE_CMD_FUNC
,NULL
);
2876 else if(!noconsolecontrols
)
2877 mp_input_add_event_fd(0, read_keys
, NULL
);
2878 // Set the libstream interrupt callback
2879 stream_set_interrupt_callback(mp_input_check_interrupt
);
2883 if(menu_cfg
&& menu_init(mpctx
, menu_cfg
))
2884 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2886 menu_cfg
= get_path("menu.conf");
2887 if(menu_init(mpctx
, menu_cfg
))
2888 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
2890 if(menu_init(mpctx
, MPLAYER_CONFDIR
"/menu.conf"))
2891 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
2893 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
2901 initialized_flags
|=INITIALIZED_INPUT
;
2902 current_module
= NULL
;
2906 signal(SIGCHLD
,child_sighandler
);
2910 prog_path
= argv
[0];
2912 //========= Catch terminate signals: ================
2913 // terminate requests:
2914 signal(SIGTERM
,exit_sighandler
); // kill
2915 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
2917 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
2919 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
2920 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
2921 #ifdef ENABLE_SIGHANDLER
2923 signal(SIGBUS
,exit_sighandler
); // bus error
2924 signal(SIGSEGV
,exit_sighandler
); // segfault
2925 signal(SIGILL
,exit_sighandler
); // illegal instruction
2926 signal(SIGFPE
,exit_sighandler
); // floating point exc.
2927 signal(SIGABRT
,exit_sighandler
); // abort()
2930 signal(SIGTRAP
,exit_sighandler
);
2937 guiGetEvent(guiSetContext
, mpctx
);
2938 initialized_flags
|=INITIALIZED_GUI
;
2939 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
2943 // ******************* Now, let's see the per-file stuff ********************
2947 // init global sub numbers
2948 mpctx
->global_sub_size
= 0;
2949 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) mpctx
->global_sub_indices
[i
] = -1; }
2952 load_per_protocol_config (mconfig
, filename
);
2953 load_per_extension_config (mconfig
, filename
);
2954 load_per_file_config (mconfig
, filename
);
2957 if (opts
->video_driver_list
)
2958 load_per_output_config (mconfig
, PROFILE_CFG_VO
, opts
->video_driver_list
[0]);
2959 if (opts
->audio_driver_list
)
2960 load_per_output_config (mconfig
, PROFILE_CFG_AO
, opts
->audio_driver_list
[0]);
2962 // We must enable getch2 here to be able to interrupt network connection
2964 if(!noconsolecontrols
&& !slave_mode
){
2965 if(initialized_flags
&INITIALIZED_GETCH2
)
2966 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
2968 getch2_enable(); // prepare stdin for hotkeys...
2969 initialized_flags
|=INITIALIZED_GETCH2
;
2970 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
2973 // =================== GUI idle loop (STOP state) ===========================
2976 mpctx
->file_format
=DEMUXER_TYPE_UNKNOWN
;
2977 guiGetEvent( guiSetDefaults
,0 );
2978 while ( guiIntfStruct
.Playing
!= 1 )
2983 guiGetEvent( guiReDraw
,NULL
);
2984 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
2985 guiGetEvent(guiIEvent
, (char *)cmd
->id
);
2989 guiGetEvent( guiSetParameters
,NULL
);
2990 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
2992 play_tree_t
* entry
= play_tree_new();
2993 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
2994 if ( mpctx
->playtree
) play_tree_free_list( mpctx
->playtree
->child
,1 );
2995 else mpctx
->playtree
=play_tree_new();
2996 play_tree_set_child( mpctx
->playtree
,entry
);
2999 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mconfig
);
3000 if(mpctx
->playtree_iter
)
3002 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
3004 play_tree_iter_free(mpctx
->playtree_iter
);
3005 mpctx
->playtree_iter
= NULL
;
3007 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
3012 #endif /* HAVE_NEW_GUI */
3014 while (player_idle_mode
&& !filename
) {
3015 play_tree_t
* entry
= NULL
;
3017 while (!(cmd
= mp_input_get_cmd(0,1,0))) { // wait for command
3018 if (mpctx
->video_out
)
3019 vo_check_events(mpctx
->video_out
);
3023 case MP_CMD_LOADFILE
:
3024 // prepare a tree entry with the new filename
3025 entry
= play_tree_new();
3026 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3027 // The entry is added to the main playtree after the switch().
3029 case MP_CMD_LOADLIST
:
3030 entry
= parse_playlist_file(cmd
->args
[0].v
.s
);
3033 exit_player_with_rc(mpctx
, MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3035 case MP_CMD_GET_PROPERTY
:
3036 case MP_CMD_SET_PROPERTY
:
3037 case MP_CMD_STEP_PROPERTY
:
3038 run_command(mpctx
, cmd
);
3044 if (entry
) { // user entered a command that gave a valid entry
3045 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
3046 play_tree_free_list(mpctx
->playtree
->child
, 1);
3047 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
3049 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
3051 play_tree_set_child(mpctx
->playtree
, entry
);
3053 /* Make iterator start at the top the of tree. */
3054 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mconfig
);
3055 if (!mpctx
->playtree_iter
) continue;
3057 // find the first real item in the tree
3058 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3060 play_tree_iter_free(mpctx
->playtree_iter
);
3061 mpctx
->playtree_iter
= NULL
;
3062 continue; // wait for next command
3064 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
3067 //---------------------------------------------------------------------------
3070 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
,
3071 filename_recode(filename
));
3074 if (edl_records
) free_edl(edl_records
);
3075 next_edl_record
= edl_records
= edl_parse_file();
3077 if (edl_output_filename
) {
3078 if (edl_fd
) fclose(edl_fd
);
3079 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3081 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
3082 filename_recode(edl_output_filename
));
3086 //==================== Open VOB-Sub ============================
3088 current_module
="vobsub";
3090 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3092 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,
3093 filename_recode(vobsub_name
));
3094 } else if (sub_auto
&& filename
){
3095 /* try to autodetect vobsub from movie filename ::atmos */
3096 char *buf
= strdup(filename
), *psub
;
3097 char *pdot
= strrchr(buf
, '.');
3098 char *pslash
= strrchr(buf
, '/');
3100 if (!pslash
) pslash
= strrchr(buf
, '\\');
3102 if (pdot
&& (!pslash
|| pdot
> pslash
))
3104 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3105 /* try from ~/.mplayer/sub */
3106 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3109 bname
= strrchr(buf
,'/');
3111 if(!bname
) bname
= strrchr(buf
,'\\');
3115 l
= strlen(psub
) + strlen(bname
) + 1;
3116 psub
= realloc(psub
,l
);
3118 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3124 initialized_flags
|=INITIALIZED_VOBSUB
;
3125 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
3126 // check if vobsub requested only to display forced subtitles
3127 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
3129 // setup global sub numbering
3130 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] = mpctx
->global_sub_size
; // the global # of the first vobsub.
3131 mpctx
->global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
3134 //============ Open & Sync STREAM --- fork cache2 ====================
3137 mpctx
->demuxer
=NULL
;
3138 if (mpctx
->d_audio
) {
3139 //free_demuxer_stream(mpctx->d_audio);
3140 mpctx
->d_audio
=NULL
;
3142 if (mpctx
->d_video
) {
3143 //free_demuxer_stream(d_video);
3144 mpctx
->d_video
=NULL
;
3146 mpctx
->sh_audio
=NULL
;
3147 mpctx
->sh_video
=NULL
;
3149 current_module
="open_stream";
3150 mpctx
->stream
= open_stream(filename
, opts
, &mpctx
->file_format
);
3151 if(!mpctx
->stream
) { // error...
3152 mpctx
->eof
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
);
3153 goto goto_next_file
;
3155 initialized_flags
|=INITIALIZED_STREAM
;
3158 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)mpctx
->stream
);
3161 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
3164 current_module
="handle_playlist";
3165 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
3166 filename_recode(filename
));
3167 entry
= parse_playtree(mpctx
->stream
,0);
3168 mpctx
->eof
=playtree_add_playlist(mpctx
, entry
);
3169 goto goto_next_file
;
3171 mpctx
->stream
->start_pos
+=seek_to_byte
;
3173 if(stream_dump_type
==5){
3174 unsigned char buf
[4096];
3177 current_module
="dumpstream";
3178 if(mpctx
->stream
->type
==STREAMTYPE_STREAM
&& mpctx
->stream
->fd
<0){
3179 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
3180 exit_player(mpctx
, MSGTR_Exit_error
);
3182 stream_reset(mpctx
->stream
);
3183 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
3184 f
=fopen(stream_dump_name
,"wb");
3186 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3187 exit_player(mpctx
, MSGTR_Exit_error
);
3189 while(!mpctx
->stream
->eof
){
3190 len
=stream_read(mpctx
->stream
,buf
,4096);
3192 if(fwrite(buf
,len
,1,f
) != 1) {
3193 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3194 exit_player(mpctx
, MSGTR_Exit_error
);
3199 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
3200 exit_player(mpctx
, MSGTR_Exit_error
);
3202 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3203 exit_player_with_rc(mpctx
, MSGTR_Exit_eof
, 0);
3207 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
3208 current_module
="dvd lang->id";
3209 if(opts
->audio_id
==-1) opts
->audio_id
=dvd_aid_from_lang(mpctx
->stream
,audio_lang
);
3210 if(dvdsub_lang
&& opts
->sub_id
==-2) opts
->sub_id
=-1;
3211 if(dvdsub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=dvd_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3212 // setup global sub numbering
3213 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3214 mpctx
->global_sub_size
+= dvd_number_of_subs(mpctx
->stream
);
3215 current_module
=NULL
;
3220 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
3221 current_module
="dvdnav lang->id";
3222 if(opts
->audio_id
==-1) opts
->audio_id
=dvdnav_aid_from_lang(mpctx
->stream
,audio_lang
);
3223 if(dvdsub_lang
&& opts
->sub_id
==-2) opts
->sub_id
=-1;
3224 if(dvdsub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=dvdnav_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3225 // setup global sub numbering
3226 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3227 mpctx
->global_sub_size
+= dvdnav_number_of_subs(mpctx
->stream
);
3228 current_module
=NULL
;
3232 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3234 if(stream_cache_size
>0){
3235 current_module
="enable_cache";
3236 if(!stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
3237 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3238 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
3239 if((mpctx
->eof
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
))) goto goto_next_file
;
3242 //============ Open DEMUXERS --- DETECT file type =======================
3243 current_module
="demux_open";
3245 mpctx
->demuxer
=demux_open(opts
, mpctx
->stream
,mpctx
->file_format
,opts
->audio_id
,opts
->video_id
,opts
->sub_id
,filename
);
3247 // HACK to get MOV Reference Files working
3249 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3251 unsigned char* playlist_entry
;
3252 play_tree_t
*list
= NULL
, *entry
= NULL
;
3254 current_module
="handle_demux_playlist";
3255 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
3259 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
3260 filename_recode(playlist_entry
));
3262 bname
=mp_basename(playlist_entry
);
3263 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3266 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
3269 entry
= play_tree_new();
3271 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3273 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1));
3276 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
3277 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
3278 strcat(temp
, playlist_entry
);
3279 play_tree_add_file(entry
,temp
);
3280 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3285 play_tree_add_file(entry
,playlist_entry
);
3290 play_tree_append_entry(list
,entry
);
3292 free_demuxer(mpctx
->demuxer
);
3293 mpctx
->demuxer
= NULL
;
3297 entry
= play_tree_new();
3298 play_tree_set_child(entry
,list
);
3299 mpctx
->eof
=playtree_add_playlist(mpctx
, entry
);
3300 goto goto_next_file
;
3305 goto goto_next_file
;
3308 if (demuxer_seek_chapter(mpctx
->demuxer
, dvd_chapter
-1, 1, &pts
, NULL
, NULL
) >= 0 && pts
> -1.0)
3309 seek(mpctx
, pts
, SEEK_ABSOLUTE
);
3312 initialized_flags
|=INITIALIZED_DEMUXER
;
3314 if (mpctx
->stream
->type
!= STREAMTYPE_DVD
&& mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
) {
3317 // setup global sub numbering
3318 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3319 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
3320 if (mpctx
->demuxer
->s_streams
[i
])
3321 maxid
= FFMAX(maxid
, mpctx
->demuxer
->s_streams
[i
]->sid
);
3322 mpctx
->global_sub_size
+= maxid
+ 1;
3324 // Make opts->sub_id always selectable if set.
3325 if (mpctx
->global_sub_size
<= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
)
3326 mpctx
->global_sub_size
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
+ 1;
3329 if (ass_enabled
&& ass_library
) {
3330 for (i
= 0; i
< mpctx
->demuxer
->num_attachments
; ++i
) {
3331 demux_attachment_t
* att
= mpctx
->demuxer
->attachments
+ i
;
3332 if (extract_embedded_fonts
&&
3333 att
->name
&& att
->type
&& att
->data
&& att
->data_size
&&
3334 (strcmp(att
->type
, "application/x-truetype-font") == 0 ||
3335 strcmp(att
->type
, "application/x-font") == 0))
3336 ass_add_font(ass_library
, att
->name
, att
->data
, att
->data_size
);
3341 current_module
="demux_open2";
3343 //file_format=demuxer->file_format;
3345 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3346 mpctx
->d_video
=mpctx
->demuxer
->video
;
3347 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3349 // select audio stream
3350 select_audio(mpctx
->demuxer
, opts
->audio_id
, audio_lang
);
3353 if((stream_dump_type
)&&(stream_dump_type
<4)){
3355 demux_stream_t
*ds
=NULL
;
3356 current_module
="dump";
3357 // select stream to dump
3358 switch(stream_dump_type
){
3359 case 1: ds
=mpctx
->d_audio
;break;
3360 case 2: ds
=mpctx
->d_video
;break;
3361 case 3: ds
=mpctx
->d_sub
;break;
3364 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
3365 exit_player(mpctx
, MSGTR_Exit_error
);
3367 // disable other streams:
3368 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3369 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3370 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3372 f
=fopen(stream_dump_name
,"wb");
3374 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
3375 exit_player(mpctx
, MSGTR_Exit_error
);
3378 unsigned char* start
;
3379 int in_size
=ds_get_packet(ds
,&start
);
3380 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3381 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3382 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3385 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
3386 exit_player_with_rc(mpctx
, MSGTR_Exit_eof
, 0);
3389 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3390 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3392 if(mpctx
->sh_video
){
3394 current_module
="video_read_properties";
3395 if(!video_read_properties(mpctx
->sh_video
)) {
3396 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
3397 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3399 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3400 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3401 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3404 /* need to set fps here for output encoders to pick it up in their init */
3406 mpctx
->sh_video
->fps
=force_fps
;
3407 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3409 vo_fps
= mpctx
->sh_video
->fps
;
3411 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3412 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
3413 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3419 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3420 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
3421 #ifdef HAS_DVBIN_SUPPORT
3422 if(mpctx
->stream
->type
== STREAMTYPE_DVB
)
3425 int v
= mpctx
->last_dvb_step
;
3427 dir
= DVB_CHANNEL_HIGHER
;
3429 dir
= DVB_CHANNEL_LOWER
;
3431 if(dvb_step_channel(mpctx
->stream
, dir
))
3432 mpctx
->eof
= mpctx
->dvbin_reopen
= 1;
3435 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
3438 /* display clip info */
3439 demux_info_print(mpctx
->demuxer
);
3441 //================== Read SUBTITLES (DVD & TEXT) ==========================
3442 if(vo_spudec
==NULL
&& mpctx
->sh_video
&&
3443 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
|| mpctx
->d_sub
->id
>= 0)){
3444 init_vo_spudec(mpctx
);
3447 // Apply current settings for forced subs
3448 if (vo_spudec
!=NULL
)
3449 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3451 if(mpctx
->sh_video
) {
3452 // after reading video params we should load subtitles because
3453 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3455 current_module
="read_subtitles_file";
3457 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3458 add_subtitles(mpctx
, sub_name
[i
], mpctx
->sh_video
->fps
, 0);
3460 if(sub_auto
) { // auto load sub file ...
3461 char *psub
= get_path( "sub/" );
3462 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
3464 free(psub
); // release the buffer created by get_path() above
3466 add_subtitles(mpctx
, tmp
[i
], mpctx
->sh_video
->fps
, 1);
3471 if (mpctx
->set_of_sub_size
> 0) {
3472 // setup global sub numbering
3473 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = mpctx
->global_sub_size
; // the global # of the first sub.
3474 mpctx
->global_sub_size
+= mpctx
->set_of_sub_size
;
3478 if (mpctx
->global_sub_size
) {
3479 // find the best sub to use
3480 int vobsub_index_id
= vobsub_get_index_by_id(vo_vobsub
, vobsub_id
);
3481 if (opts
->sub_id
< 0 && dvdsub_lang
)
3482 opts
->sub_id
= demuxer_sub_track_by_lang(mpctx
->demuxer
, dvdsub_lang
);
3483 if (opts
->sub_id
< 0)
3484 opts
->sub_id
= demuxer_default_sub_track(mpctx
->demuxer
);
3485 if (vobsub_index_id
>= 0) {
3486 // if user asks for a vobsub id, use that first.
3487 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_index_id
;
3488 } else if (opts
->sub_id
>= 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3489 // if user asks for a dvd sub id, use that next.
3490 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
;
3491 } else if (mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
3492 // if there are text subs to use, use those. (autosubs come last here)
3493 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
];
3495 } else if (mpctx->global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
3496 // if nothing else works, get subs from the demuxer.
3497 mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
3500 // nothing worth doing automatically.
3501 mpctx
->global_sub_pos
= -1;
3503 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3504 mpctx
->global_sub_pos
--;
3505 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
, mpctx
);
3507 switch (stream_dump_type
) {
3508 case 3: list_sub_file(subdata
); break;
3509 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
3510 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
3511 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
3512 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
3513 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
3517 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
3518 filename_recode(filename
));
3519 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
3520 if (mpctx
->sh_video
) {
3521 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3522 if (mpctx
->sh_video
->format
>= 0x20202020)
3523 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
3525 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
3526 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
3527 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
3528 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
3529 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
3530 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
3532 if (mpctx
->sh_audio
) {
3533 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3534 if (mpctx
->sh_audio
->format
>= 0x20202020)
3535 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
3537 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
3538 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
3539 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
3540 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
3542 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(mpctx
->demuxer
));
3543 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_SEEKABLE=%d\n", mpctx
->stream
->seek
? 1 : 0);
3545 if(!mpctx
->sh_video
) goto main
; // audio-only
3547 if(!reinit_video_chain(mpctx
)) {
3548 if(!mpctx
->sh_video
){
3549 if(!mpctx
->sh_audio
) goto goto_next_file
;
3550 goto main
; // exit_player(MSGTR_Exit_error);
3554 if(mpctx
->sh_video
->output_flags
& 0x08 && vo_spudec
)
3555 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
3557 #ifdef HAVE_FREETYPE
3558 force_load_font
= 1;
3561 //================== MAIN: ==========================
3563 current_module
="main";
3566 char* msg
= property_expand_string(mpctx
, playing_msg
);
3567 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3572 // Disable the term OSD in verbose mode
3573 if(verbose
) term_osd
= 0;
3576 //int frame_corr_num=0; //
3577 //float v_frame=0; // Video
3578 float time_frame
=0; // Timer
3579 //float num_frames=0; // number of frames played
3581 int frame_time_remaining
=0; // flag
3583 mpctx
->num_buffered_frames
=0;
3585 // Make sure old OSD does not stay around,
3586 // e.g. with -fixed-vo and same-resolution files
3588 update_osd_msg(mpctx
);
3590 //================ SETUP AUDIO ==========================
3592 if(mpctx
->sh_audio
){
3593 reinit_audio_chain(mpctx
);
3594 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
3595 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
3598 current_module
="av_init";
3600 if(mpctx
->sh_video
){
3601 mpctx
->sh_video
->timer
=0;
3603 audio_delay
+= mpctx
->sh_video
->stream_delay
;
3605 if(mpctx
->sh_audio
){
3607 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
3608 mpctx
->delay
=-audio_delay
;
3611 if(!mpctx
->sh_audio
){
3612 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
3613 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
3614 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
3615 //mpctx->d_audio->id=-2; // do not read audio chunks
3616 //uninit_player(mpctx, INITIALIZED_AO); // close device
3618 if(!mpctx
->sh_video
){
3619 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
3620 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
3621 ds_free_packs(mpctx
->d_video
);
3622 mpctx
->d_video
->id
=-2;
3623 //if(!fixed_vo) uninit_player(mpctx, INITIALIZED_VO);
3626 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
3627 goto goto_next_file
;
3629 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3630 if(force_fps
&& mpctx
->sh_video
){
3631 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
3632 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3633 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
3638 if ( mpctx
->sh_audio
) guiIntfStruct
.AudioType
=mpctx
->sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
3639 if ( !mpctx
->sh_video
&& mpctx
->sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
3640 guiGetEvent( guiSetFileFormat
,(char *)mpctx
->demuxer
->file_format
);
3641 if ( guiGetEvent( guiSetValues
,(char *)mpctx
->sh_video
) ) goto goto_next_file
;
3642 guiGetEvent( guiSetDemuxer
,(char *)mpctx
->demuxer
);
3646 mp_input_set_section(NULL
);
3647 //TODO: add desired (stream-based) sections here
3648 if (mpctx
->stream
->type
==STREAMTYPE_TV
) mp_input_set_section("tv");
3650 //==================== START PLAYING =======================
3652 if(opts
->loop_times
>1) opts
->loop_times
--; else
3653 if(opts
->loop_times
==1) opts
->loop_times
= -1;
3655 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);
3657 total_time_usage_start
=GetTimer();
3658 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3659 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3660 play_n_frames
=play_n_frames_mf
;
3662 if(play_n_frames
==0){
3663 mpctx
->eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
3667 seek(mpctx
, seek_to_sec
, SEEK_ABSOLUTE
);
3668 end_at
.pos
+= seek_to_sec
;
3671 if (end_at
.type
== END_AT_SIZE
) {
3672 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_MPEndposNoSizeBased
);
3673 end_at
.type
= END_AT_NONE
;
3677 mp_dvdnav_context_free(mpctx
);
3678 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3679 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
3680 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
3685 float aq_sleep_time
=0;
3687 if(dvd_last_chapter
>0) {
3688 int cur_chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
3689 if(cur_chapter
!=-1 && cur_chapter
+1>dvd_last_chapter
)
3690 goto goto_next_file
;
3693 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
3694 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
3695 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
3696 reinit_audio_chain(mpctx
);
3699 /*========================== PLAY AUDIO ============================*/
3701 if (mpctx
->sh_audio
)
3702 if (!fill_audio_out_buffers(mpctx
))
3703 // at eof, all audio at least written to ao
3704 if (!mpctx
->sh_video
)
3705 mpctx
->eof
= PT_NEXT_ENTRY
;
3708 if(!mpctx
->sh_video
) {
3709 // handle audio-only case:
3711 if(!quiet
|| end_at
.type
== END_AT_TIME
)
3712 a_pos
= playing_audio_pts(mpctx
);
3715 print_status(mpctx
, a_pos
, 0, 0);
3717 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
3718 mpctx
->eof
= PT_NEXT_ENTRY
;
3719 update_osd_msg(mpctx
);
3723 /*========================== PLAY VIDEO ============================*/
3725 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
3726 vo_fps
=mpctx
->sh_video
->fps
;
3728 if (!mpctx
->num_buffered_frames
) {
3729 double frame_time
= update_video(mpctx
, &blit_frame
);
3730 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3731 if (mpctx
->sh_video
->vf_initialized
< 0) {
3732 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NotInitializeVOPorVO
);
3733 mpctx
->eof
= 1; goto goto_next_file
;
3738 // might return with !eof && !blit_frame if !correct_pts
3739 mpctx
->num_buffered_frames
+= blit_frame
;
3740 time_frame
+= frame_time
/ opts
->playback_speed
; // for nosound
3744 // ==========================================================================
3746 // current_module="draw_osd";
3747 // if(vo_config_count) mpctx->video_out->draw_osd();
3750 if(use_gui
) guiEventHandling();
3753 current_module
="vo_check_events";
3754 vo_check_events(mpctx
->video_out
);
3757 if (stop_xscreensaver
) {
3758 current_module
= "stop_xscreensaver";
3759 xscreensaver_heartbeat(mpctx
->x11_state
);
3762 if (heartbeat_cmd
) {
3763 static unsigned last_heartbeat
;
3764 unsigned now
= GetTimerMS();
3765 if (now
- last_heartbeat
> 30000) {
3766 last_heartbeat
= now
;
3767 system(heartbeat_cmd
);
3771 frame_time_remaining
= sleep_until_update(mpctx
, &time_frame
, &aq_sleep_time
);
3773 //====================== FLIP PAGE (VIDEO BLT): =========================
3775 current_module
="flip_page";
3776 if (!frame_time_remaining
&& blit_frame
) {
3777 unsigned int t2
=GetTimer();
3779 vo_flip_page(mpctx
->video_out
);
3780 mpctx
->num_buffered_frames
--;
3782 vout_time_usage
+= (GetTimer() - t2
) * 0.000001;
3784 //====================== A-V TIMESTAMP CORRECTION: =========================
3786 adjust_sync_and_print_status(mpctx
, frame_time_remaining
, time_frame
);
3788 //============================ Auto QUALITY ============================
3790 /*Output quality adjustments:*/
3792 current_module
="autoq";
3793 // float total=0.000001f * (GetTimer()-aq_total_time);
3794 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
3795 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
3798 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
3799 if(output_quality
>1 && aq_sleep_time
<0)
3802 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
3804 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
3805 set_video_quality(mpctx
->sh_video
,output_quality
);
3808 if (play_n_frames
>= 0 && !frame_time_remaining
&& blit_frame
) {
3810 if (play_n_frames
<= 0) mpctx
->eof
= PT_NEXT_ENTRY
;
3814 // FIXME: add size based support for -endpos
3815 if (end_at
.type
== END_AT_TIME
&&
3816 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
3817 mpctx
->eof
= PT_NEXT_ENTRY
;
3819 } // end if(mpctx->sh_video)
3822 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3824 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
3825 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
3826 vo_osd_changed (OSDTYPE_DVDNAV
);
3828 if (mp_dvdnav_stream_has_changed(mpctx
->stream
)) {
3830 if (stream_control (mpctx
->demuxer
->stream
,
3831 STREAM_CTRL_GET_ASPECT_RATIO
, &ar
)
3832 != STREAM_UNSUPPORTED
)
3833 mpctx
->sh_video
->stream_aspect
= ar
;
3838 //============================ Handle PAUSE ===============================
3840 current_module
="pause";
3842 if (mpctx
->osd_function
== OSD_PAUSE
) {
3844 mpctx
->was_paused
= 1;
3849 mpctx
->osd_function
=OSD_FFW
;
3850 mpctx
->rel_seek_secs
+=step_sec
;
3855 //================= Keyboard events, SEEKing ====================
3857 current_module
="key_events";
3862 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
3863 brk_cmd
= run_command(mpctx
, cmd
);
3866 goto goto_enable_cache
;
3869 mpctx
->was_paused
= 0;
3872 if(mpctx
->eof
==1 && opts
->loop_times
>=0) {
3873 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", opts
->loop_times
,mpctx
->eof
);
3875 if(opts
->loop_times
>1) opts
->loop_times
--; else
3876 if(opts
->loop_times
==1) opts
->loop_times
=-1;
3877 play_n_frames
=play_n_frames_mf
;
3879 mpctx
->abs_seek_pos
=SEEK_ABSOLUTE
; mpctx
->rel_seek_secs
=seek_to_sec
;
3883 if(mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
){
3884 if (seek(mpctx
, mpctx
->rel_seek_secs
, mpctx
->abs_seek_pos
) >= 0) {
3888 set_osd_bar(mpctx
, 0,"Position",0,100,demuxer_get_percent_pos(mpctx
->demuxer
));
3892 mpctx
->rel_seek_secs
=0;
3893 mpctx
->abs_seek_pos
=0;
3901 if(mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
&& mpctx
->sh_video
&& mpctx
->sh_video
->video
.dwLength
>2){
3902 // get pos from frame number / total frames
3903 guiIntfStruct
.Position
=(float)mpctx
->d_video
->pack_no
*100.0f
/mpctx
->sh_video
->video
.dwLength
;
3905 guiIntfStruct
.Position
=demuxer_get_percent_pos(mpctx
->demuxer
);
3907 if ( mpctx
->sh_video
) guiIntfStruct
.TimeSec
=mpctx
->sh_video
->pts
;
3908 else if ( mpctx
->sh_audio
) guiIntfStruct
.TimeSec
=playing_audio_pts(mpctx
);
3909 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(mpctx
->demuxer
);
3910 guiGetEvent( guiReDraw
,NULL
);
3911 guiGetEvent( guiSetVolume
,NULL
);
3912 if(guiIntfStruct
.Playing
==0) break; // STOP
3913 if(guiIntfStruct
.Playing
==2) mpctx
->osd_function
=OSD_PAUSE
;
3914 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3916 if ( mpctx
->stream
->type
== STREAMTYPE_DVD
)
3918 dvd_priv_t
* dvdp
= mpctx
->stream
->priv
;
3919 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3923 #endif /* HAVE_NEW_GUI */
3925 } // while(!mpctx->eof)
3927 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->eof
);
3929 #ifdef HAS_DVBIN_SUPPORT
3930 if(mpctx
->dvbin_reopen
)
3933 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_GUI
|INITIALIZED_STREAM
|INITIALIZED_INPUT
|INITIALIZED_GETCH2
|(opts
->fixed_vo
?INITIALIZED_VO
:0)));
3934 cache_uninit(mpctx
->stream
);
3935 mpctx
->dvbin_reopen
= 0;
3936 goto goto_enable_cache
;
3941 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3943 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3946 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3947 double total_time_usage
;
3948 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3949 total_time_usage
= (float)total_time_usage_start
*0.000001;
3950 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3951 video_time_usage
,vout_time_usage
,audio_time_usage
,
3952 total_time_usage
-tot
,total_time_usage
);
3953 if(total_time_usage
>0.0)
3954 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3955 100.0*video_time_usage
/total_time_usage
,
3956 100.0*vout_time_usage
/total_time_usage
,
3957 100.0*audio_time_usage
/total_time_usage
,
3958 100.0*(total_time_usage
-tot
)/total_time_usage
,
3960 if(total_frame_cnt
&& frame_dropping
)
3961 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3962 total_frame_cnt
-drop_frame_cnt
,
3963 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3965 100*drop_frame_cnt
/total_frame_cnt
,
3967 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
3970 // time to uninit all, except global stuff:
3971 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_GUI
+INITIALIZED_INPUT
+(opts
->fixed_vo
?INITIALIZED_VO
:0)));
3973 if(mpctx
->set_of_sub_size
> 0) {
3974 current_module
="sub_free";
3975 for(i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
3976 sub_free(mpctx
->set_of_subtitles
[i
]);
3978 if(mpctx
->set_of_ass_tracks
[i
])
3979 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
3982 mpctx
->set_of_sub_size
= 0;
3984 vo_sub_last
= vo_sub
=NULL
;
3989 ass_clear_fonts(ass_library
);
3992 if(mpctx
->eof
== PT_NEXT_ENTRY
|| mpctx
->eof
== PT_PREV_ENTRY
) {
3993 mpctx
->eof
= mpctx
->eof
== PT_NEXT_ENTRY
? 1 : -1;
3994 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
3997 play_tree_iter_free(mpctx
->playtree_iter
);
3998 mpctx
->playtree_iter
= NULL
;
4000 mpctx
->play_tree_step
= 1;
4001 } else if(mpctx
->eof
== PT_UP_NEXT
|| mpctx
->eof
== PT_UP_PREV
) {
4002 mpctx
->eof
= mpctx
->eof
== PT_UP_NEXT
? 1 : -1;
4003 if(mpctx
->playtree_iter
) {
4004 if(play_tree_iter_up_step(mpctx
->playtree_iter
,mpctx
->eof
,0) == PLAY_TREE_ITER_ENTRY
) {
4007 play_tree_iter_free(mpctx
->playtree_iter
);
4008 mpctx
->playtree_iter
= NULL
;
4011 } else { // NEXT PREV SRC
4012 mpctx
->eof
= mpctx
->eof
== PT_PREV_SRC
? -1 : 1;
4015 if(mpctx
->eof
== 0) mpctx
->eof
= 1;
4017 while(mpctx
->playtree_iter
!= NULL
) {
4018 filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,mpctx
->eof
);
4019 if(filename
== NULL
) {
4020 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->eof
,0) != PLAY_TREE_ITER_ENTRY
) {
4021 play_tree_iter_free(mpctx
->playtree_iter
);
4022 mpctx
->playtree_iter
= NULL
;
4029 if(use_gui
&& !mpctx
->playtree_iter
) {
4031 if(!guiIntfStruct
.DiskChanged
)
4037 if(use_gui
|| mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
4038 if(!mpctx
->playtree_iter
) filename
= NULL
;
4040 goto play_next_file
;
4044 exit_player_with_rc(mpctx
, MSGTR_Exit_eof
, 0);