3 /// \ingroup Properties Command2Property OSDMsgStack
11 #if defined(__MINGW32__) || defined(__CYGWIN__)
12 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
18 // #include <sys/mman.h>
19 #include <sys/types.h>
21 #include <sys/ioctl.h>
24 #define SIGHUP 1 /* hangup */
25 #define SIGQUIT 3 /* quit */
26 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
27 #define SIGBUS 10 /* bus error */
28 #define SIGPIPE 13 /* broken pipe */
49 #include "access_mpcontext.h"
50 #include "m_property.h"
52 #include "cfg-mplayer-def.h"
54 #include "ffmpeg_files/intreadwrite.h"
55 #include "libavutil/avstring.h"
57 #include "subreader.h"
60 #include "libvo/video_out.h"
62 #include "libvo/font_load.h"
63 #include "libvo/sub.h"
66 #include "libvo/x11_common.h"
69 #include "libao2/audio_out.h"
71 #include "codec-cfg.h"
78 #include "osdep/getch2.h"
79 #include "osdep/timer.h"
80 #include "osdep/findfiles.h"
82 #include "input/input.h"
84 const int under_mencoder
= 0;
86 int player_idle_mode
=0;
88 int enable_mouse_movements
=0;
89 float start_volume
= -1;
91 #include "osdep/priority.h"
95 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
99 #include <linux/rtc.h>
102 #define RTC_IRQP_SET RTCIO_IRQP_SET
103 #define RTC_PIE_ON RTCIO_PIE_ON
104 #endif /* __linux__ */
105 #endif /* HAVE_RTC */
107 #include "stream/tv.h"
108 #include "stream/stream_radio.h"
110 #include "stream/dvbin.h"
112 #include "stream/cache2.h"
114 //**************************************************************************//
116 //**************************************************************************//
117 #include "playtree.h"
118 #include "playtreeparser.h"
120 //**************************************************************************//
122 //**************************************************************************//
123 #include "parser-cfg.h"
124 #include "parser-mpcmd.h"
126 //**************************************************************************//
128 //**************************************************************************//
130 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
132 #include "get_path.h"
134 //**************************************************************************//
135 //**************************************************************************//
136 // Input media streaming & demultiplexer:
137 //**************************************************************************//
139 static int max_framesize
=0;
141 #include "stream/stream.h"
142 #include "libmpdemux/demuxer.h"
143 #include "libmpdemux/stheader.h"
145 #ifdef CONFIG_DVDREAD
146 #include "stream/stream_dvd.h"
148 #include "stream/stream_dvdnav.h"
150 #include "libmpcodecs/dec_audio.h"
151 #include "libmpcodecs/dec_video.h"
152 #include "libmpcodecs/mp_image.h"
153 #include "libmpcodecs/vf.h"
154 #include "libmpcodecs/vd.h"
160 #include "defaultopts.h"
162 static const char help_text
[]=_(
163 "Usage: mplayer [options] [url|path/]filename\n"
165 "Basic options: (complete list in the man page)\n"
166 " -vo <drv> select video output driver ('-vo help' for a list)\n"
167 " -ao <drv> select audio output driver ('-ao help' for a list)\n"
169 " vcd://<trackno> play (S)VCD (Super Video CD) track (raw device, no mount)\n"
171 #ifdef CONFIG_DVDREAD
172 " dvd://<titleno> play DVD title from device instead of plain file\n"
174 " -alang/-slang select DVD audio/subtitle language (by 2-char country code)\n"
175 " -ss <position> seek to given (seconds or hh:mm:ss) position\n"
176 " -nosound do not play sound\n"
177 " -fs fullscreen playback (or -vm, -zoom, details in the man page)\n"
178 " -x <x> -y <y> set display resolution (for use with -vm or -zoom)\n"
179 " -sub <file> specify subtitle file to use (also see -subfps, -subdelay)\n"
180 " -playlist <file> specify playlist file\n"
181 " -vid x -aid y select video (x) and audio (y) stream to play\n"
182 " -fps x -srate y change video (x fps) and audio (y Hz) rate\n"
183 " -pp <quality> enable postprocessing filter (details in the man page)\n"
184 " -framedrop enable frame dropping (for slow machines)\n"
186 "Basic keys: (complete list in the man page, also check input.conf)\n"
187 " <- or -> seek backward/forward 10 seconds\n"
188 " down or up seek backward/forward 1 minute\n"
189 " pgdown or pgup seek backward/forward 10 minutes\n"
190 " < or > step backward/forward in playlist\n"
191 " p or SPACE pause movie (press any key to continue)\n"
192 " q or ESC stop playing and quit program\n"
193 " + or - adjust audio delay by +/- 0.1 second\n"
194 " o cycle OSD mode: none / seekbar / seekbar + timer\n"
195 " * or / increase or decrease PCM volume\n"
196 " x or z adjust subtitle delay by +/- 0.1 second\n"
197 " r or t adjust subtitle position up/down, also see -vf expand\n"
199 " * * * SEE THE MAN PAGE FOR DETAILS, FURTHER (ADVANCED) OPTIONS AND KEYS * * *\n"
203 #define Exit_SIGILL_RTCpuSel _(\
204 "- MPlayer crashed by an 'Illegal Instruction'.\n"\
205 " It may be a bug in our new runtime CPU-detection code...\n"\
206 " Please read DOCS/HTML/en/bugreports.html.\n")
208 #define Exit_SIGILL _(\
209 "- MPlayer crashed by an 'Illegal Instruction'.\n"\
210 " It usually happens when you run it on a CPU different than the one it was\n"\
211 " compiled/optimized for.\n"\
214 #define Exit_SIGSEGV_SIGFPE _(\
215 "- MPlayer crashed by bad usage of CPU/FPU/RAM.\n"\
216 " Recompile MPlayer with --enable-debug and make a 'gdb' backtrace and\n"\
217 " disassembly. Details in DOCS/HTML/en/bugreports_what.html#bugreports_crash.\n")
219 #define Exit_SIGCRASH _(\
220 "- MPlayer crashed. This shouldn't happen.\n"\
221 " It can be a bug in the MPlayer code _or_ in your drivers _or_ in your\n"\
222 " gcc version. If you think it's MPlayer's fault, please read\n"\
223 " DOCS/HTML/en/bugreports.html and follow the instructions there. We can't and\n"\
224 " won't help unless you provide this information when reporting a possible bug.\n")
226 #define SystemTooSlow _("\n\n"\
227 " ************************************************\n"\
228 " **** Your system is too SLOW to play this! ****\n"\
229 " ************************************************\n\n"\
230 "Possible reasons, problems, workarounds:\n"\
231 "- Most common: broken/buggy _audio_ driver\n"\
232 " - Try -ao sdl or use the OSS emulation of ALSA.\n"\
233 " - Experiment with different values for -autosync, 30 is a good start.\n"\
234 "- Slow video output\n"\
235 " - Try a different -vo driver (-vo help for a list) or try -framedrop!\n"\
237 " - Don't try to play a big DVD/DivX on a slow CPU! Try some of the lavdopts,\n"\
238 " e.g. -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all.\n"\
240 " - Try various combinations of -nobps -ni -forceidx -mc 0.\n"\
241 "- Slow media (NFS/SMB mounts, DVD, VCD etc)\n"\
242 " - Try -cache 8192.\n"\
243 "- Are you using -cache to play a non-interleaved AVI file?\n"\
244 " - Try -nocache.\n"\
245 "Read DOCS/HTML/en/video.html for tuning/speedup tips.\n"\
246 "If none of this helps you, read DOCS/HTML/en/bugreports.html.\n\n")
249 //**************************************************************************//
250 //**************************************************************************//
252 // Common FIFO functions, and keyboard/event FIFO code
254 int noconsolecontrols
=0;
255 //**************************************************************************//
258 double video_time_usage
=0;
259 double vout_time_usage
=0;
260 static double audio_time_usage
=0;
261 static int total_time_usage_start
=0;
262 static int total_frame_cnt
=0;
263 static int drop_frame_cnt
=0; // total number of dropped frames
268 static int output_quality
=0;
270 static int list_properties
= 0;
273 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
274 static char* playing_msg
= NULL
;
276 static double seek_to_sec
;
277 static off_t seek_to_byte
=0;
278 static off_t step_sec
=0;
280 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
283 int autosync
=0; // 30 might be a good default value.
286 char **audio_codec_list
=NULL
; // override audio codec
287 char **video_codec_list
=NULL
; // override video codec
288 char **audio_fm_list
=NULL
; // override audio codec family
289 char **video_fm_list
=NULL
; // override video codec family
292 extern char *demuxer_name
; // override demuxer
293 extern char *audio_demuxer_name
; // override audio demuxer
294 extern char *sub_demuxer_name
; // override sub demuxer
296 // this dvdsub_id was selected via slang
297 // use this to allow dvdnav to follow -slang across stream resets,
298 // in particular the subtitle ID for a language changes
301 char* audio_lang
=NULL
;
302 char* dvdsub_lang
=NULL
;
303 static char* spudec_ifo
=NULL
;
304 int forced_subs_only
=0;
308 int stream_cache_size
=-1;
309 #ifdef CONFIG_STREAM_CACHE
310 extern int cache_fill_status
;
312 float stream_cache_min_percent
=20.0;
313 float stream_cache_seek_min_percent
=50.0;
315 #define cache_fill_status 0
319 static char *stream_dump_name
="stream.dump";
320 int stream_dump_type
=0;
323 static float default_max_pts_correction
=-1;//0.01f;
325 static int ignore_start
=0;
327 static int softsleep
=0;
330 static int force_srate
=0;
331 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
332 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
333 static int play_n_frames
=-1;
334 static int play_n_frames_mf
=-1;
337 char *font_name
=NULL
;
338 char *sub_font_name
=NULL
;
339 extern int font_fontconfig
;
340 float font_factor
=0.75;
341 char **sub_name
=NULL
;
345 char *vobsub_name
=NULL
;
346 /*DSP!!char *dsp=NULL;*/
348 int suboverlap_enabled
= 1;
352 char* current_module
=NULL
; // for debugging
358 #include "m_struct.h"
359 #include "libmenu/menu.h"
360 void vf_menu_pause_update(struct vf_instance
* vf
);
361 extern vf_info_t vf_info_menu
;
362 static const vf_info_t
* const libmenu_vfs
[] = {
366 static vf_instance_t
* vf_menu
= NULL
;
368 static char* menu_cfg
= NULL
;
369 static char* menu_root
= "main";
374 static int nortc
= 1;
375 static char* rtc_device
;
378 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
379 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
380 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
381 int use_filedir_conf
;
382 int use_filename_title
;
384 #include "mpcommon.h"
387 #include "metadata.h"
389 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
391 const void *mpctx_get_video_out(MPContext
*mpctx
)
393 return mpctx
->video_out
;
396 const void *mpctx_get_audio_out(MPContext
*mpctx
)
398 return mpctx
->audio_out
;
401 void *mpctx_get_demuxer(MPContext
*mpctx
)
403 return mpctx
->demuxer
;
406 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
408 return mpctx
->playtree_iter
;
411 void *mpctx_get_mixer(MPContext
*mpctx
)
413 return &mpctx
->mixer
;
416 int mpctx_get_global_sub_size(MPContext
*mpctx
)
418 return mpctx
->global_sub_size
;
421 int mpctx_get_osd_function(MPContext
*mpctx
)
423 return mpctx
->osd_function
;
426 static float get_relative_time(struct MPContext
*mpctx
)
428 unsigned int new_time
= GetTimer();
429 unsigned int delta
= new_time
- mpctx
->last_time
;
430 mpctx
->last_time
= new_time
;
431 return delta
* 0.000001;
434 static int is_valid_metadata_type(struct MPContext
*mpctx
, metadata_t type
) {
437 /* check for valid video stream */
438 case META_VIDEO_CODEC
:
439 case META_VIDEO_BITRATE
:
440 case META_VIDEO_RESOLUTION
:
442 if (!mpctx
->sh_video
)
447 /* check for valid audio stream */
448 case META_AUDIO_CODEC
:
449 case META_AUDIO_BITRATE
:
450 case META_AUDIO_SAMPLES
:
452 if (!mpctx
->sh_audio
)
457 /* check for valid demuxer */
458 case META_INFO_TITLE
:
459 case META_INFO_ARTIST
:
460 case META_INFO_ALBUM
:
462 case META_INFO_COMMENT
:
463 case META_INFO_TRACK
:
464 case META_INFO_GENRE
:
478 static char *get_demuxer_info(struct MPContext
*mpctx
, char *tag
) {
479 char **info
= mpctx
->demuxer
->info
;
485 for (n
= 0; info
[2*n
] != NULL
; n
++)
486 if (!strcasecmp (info
[2*n
], tag
))
489 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
492 char *get_metadata(struct MPContext
*mpctx
, metadata_t type
)
495 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
496 sh_video_t
* const sh_video
= mpctx
->sh_video
;
498 if (!is_valid_metadata_type(mpctx
, type
))
505 return strdup (mp_basename2 (mpctx
->filename
));
508 case META_VIDEO_CODEC
:
510 if (sh_video
->format
== 0x10000001)
511 meta
= strdup ("mpeg1");
512 else if (sh_video
->format
== 0x10000002)
513 meta
= strdup ("mpeg2");
514 else if (sh_video
->format
== 0x10000004)
515 meta
= strdup ("mpeg4");
516 else if (sh_video
->format
== 0x10000005)
517 meta
= strdup ("h264");
518 else if (sh_video
->format
>= 0x20202020)
521 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
526 sprintf (meta
, "0x%08X", sh_video
->format
);
531 case META_VIDEO_BITRATE
:
534 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
538 case META_VIDEO_RESOLUTION
:
541 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
545 case META_AUDIO_CODEC
:
547 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
548 meta
= strdup (sh_audio
->codec
->name
);
552 case META_AUDIO_BITRATE
:
555 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
559 case META_AUDIO_SAMPLES
:
562 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
566 /* check for valid demuxer */
567 case META_INFO_TITLE
:
568 return get_demuxer_info(mpctx
, "Title");
570 case META_INFO_ARTIST
:
571 return get_demuxer_info(mpctx
, "Artist");
573 case META_INFO_ALBUM
:
574 return get_demuxer_info(mpctx
, "Album");
577 return get_demuxer_info(mpctx
, "Year");
579 case META_INFO_COMMENT
:
580 return get_demuxer_info(mpctx
, "Comment");
582 case META_INFO_TRACK
:
583 return get_demuxer_info(mpctx
, "Track");
585 case META_INFO_GENRE
:
586 return get_demuxer_info(mpctx
, "Genre");
595 /// step size of mixer changes
599 static void mp_dvdnav_context_free(MPContext
*ctx
){
600 if (ctx
->nav_smpi
) free_mp_image(ctx
->nav_smpi
);
601 ctx
->nav_smpi
= NULL
;
602 if (ctx
->nav_buffer
) free(ctx
->nav_buffer
);
603 ctx
->nav_buffer
= NULL
;
604 ctx
->nav_start
= NULL
;
605 ctx
->nav_in_size
= 0;
609 void uninit_player(struct MPContext
*mpctx
, unsigned int mask
){
610 mask
&= mpctx
->initialized_flags
;
612 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
614 if(mask
&INITIALIZED_ACODEC
){
615 mpctx
->initialized_flags
&=~INITIALIZED_ACODEC
;
616 current_module
="uninit_acodec";
617 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
618 mpctx
->sh_audio
=NULL
;
619 mpctx
->mixer
.afilter
= NULL
;
622 if(mask
&INITIALIZED_VCODEC
){
623 mpctx
->initialized_flags
&=~INITIALIZED_VCODEC
;
624 current_module
="uninit_vcodec";
625 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
626 mpctx
->sh_video
=NULL
;
632 if(mask
&INITIALIZED_DEMUXER
){
633 mpctx
->initialized_flags
&=~INITIALIZED_DEMUXER
;
634 current_module
="free_demuxer";
635 if (mpctx
->num_sources
) {
636 mpctx
->demuxer
= mpctx
->sources
[0].demuxer
;
637 for (int i
= 1; i
< mpctx
->num_sources
; i
++) {
638 free_stream(mpctx
->sources
[i
].stream
);
639 free_demuxer(mpctx
->sources
[i
].demuxer
);
642 talloc_free(mpctx
->sources
);
643 mpctx
->sources
= NULL
;
644 mpctx
->num_sources
= 0;
645 talloc_free(mpctx
->timeline
);
646 mpctx
->timeline
= NULL
;
647 mpctx
->num_timeline_parts
= 0;
648 talloc_free(mpctx
->chapters
);
649 mpctx
->chapters
= NULL
;
650 mpctx
->num_chapters
= 0;
651 mpctx
->video_offset
= 0;
653 mpctx
->stream
=mpctx
->demuxer
->stream
;
654 free_demuxer(mpctx
->demuxer
);
659 // kill the cache process:
660 if(mask
&INITIALIZED_STREAM
){
661 mpctx
->initialized_flags
&=~INITIALIZED_STREAM
;
662 current_module
="uninit_stream";
663 if(mpctx
->stream
) free_stream(mpctx
->stream
);
667 if(mask
&INITIALIZED_VO
){
668 mpctx
->initialized_flags
&=~INITIALIZED_VO
;
669 current_module
="uninit_vo";
670 vo_destroy(mpctx
->video_out
);
671 mpctx
->video_out
=NULL
;
673 mp_dvdnav_context_free(mpctx
);
677 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
678 if(mask
&INITIALIZED_GETCH2
){
679 mpctx
->initialized_flags
&=~INITIALIZED_GETCH2
;
680 current_module
="uninit_getch2";
681 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
686 if(mask
&INITIALIZED_VOBSUB
){
687 mpctx
->initialized_flags
&=~INITIALIZED_VOBSUB
;
688 current_module
="uninit_vobsub";
689 if(vo_vobsub
) vobsub_close(vo_vobsub
);
693 if (mask
&INITIALIZED_SPUDEC
){
694 mpctx
->initialized_flags
&=~INITIALIZED_SPUDEC
;
695 current_module
="uninit_spudec";
696 spudec_free(vo_spudec
);
700 if(mask
&INITIALIZED_AO
){
701 mpctx
->initialized_flags
&=~INITIALIZED_AO
;
702 current_module
="uninit_ao";
703 if (mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
704 if (mpctx
->audio_out
)
705 mpctx
->audio_out
->uninit(mpctx
->stop_play
!= AT_END_OF_FILE
);
706 mpctx
->audio_out
=NULL
;
712 void exit_player_with_rc(struct MPContext
*mpctx
, exit_reason_t how
, int rc
)
714 if (mpctx
->user_muted
&& !mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
715 uninit_player(mpctx
, INITIALIZED_ALL
);
716 #if defined(__MINGW32__) || defined(__CYGWIN__)
720 vo_uninit(mpctx
->x11_state
); // Close the X11 connection (if any is open).
723 current_module
="uninit_input";
724 mp_input_uninit(mpctx
->input
);
730 #ifdef CONFIG_FREETYPE
731 current_module
="uninit_font";
732 if (mpctx
->osd
&& mpctx
->osd
->sub_font
!= vo_font
)
733 free_font_desc(mpctx
->osd
->sub_font
);
734 free_font_desc(vo_font
);
738 osd_free(mpctx
->osd
);
741 ass_library_done(ass_library
);
745 current_module
="exit_player";
747 // free mplayer config
749 m_config_free(mpctx
->mconfig
);
750 mpctx
->mconfig
= NULL
;
752 if(mpctx
->playtree_iter
)
753 play_tree_iter_free(mpctx
->playtree_iter
);
754 mpctx
->playtree_iter
= NULL
;
756 play_tree_free(mpctx
->playtree
, 1);
757 mpctx
->playtree
= NULL
;
759 talloc_free(mpctx
->key_fifo
);
761 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
765 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Quit");
766 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=QUIT\n");
769 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","End of file");
770 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=EOF\n");
773 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Fatal error");
774 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=ERROR\n");
777 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=NONE\n");
779 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
784 static void exit_player(struct MPContext
*mpctx
, exit_reason_t how
)
786 exit_player_with_rc(mpctx
, how
, 1);
790 static void child_sighandler(int x
){
792 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
796 #ifdef CONFIG_CRASH_DEBUG
797 static char *prog_path
;
798 static int crash_debug
= 0;
801 static void exit_sighandler(int x
){
802 static int sig_count
=0;
803 #ifdef CONFIG_CRASH_DEBUG
804 if (!crash_debug
|| x
!= SIGTRAP
)
809 /* We're crashing bad and can't uninit cleanly :(
810 * by popular request, we make one last (dirty)
811 * effort to restore the user's
816 if(sig_count
==6) exit(1);
820 kill(getpid(),SIGKILL
);
823 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, "\n");
824 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,
825 "\nMPlayer interrupted by signal %d in module: %s\n", x
,
826 current_module
? current_module
: "unknown");
827 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
834 async_quit_request
= 1;
835 return; // killed from keyboard (^C) or killed [-9]
837 #if CONFIG_RUNTIME_CPUDETECT
838 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL_RTCpuSel
);
840 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL
);
844 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGSEGV_SIGFPE
);
846 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGCRASH
);
847 #ifdef CONFIG_CRASH_DEBUG
850 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
852 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
853 if (gdb_pid
== 0) { // We are the child
855 snprintf(spid
, sizeof(spid
), "%i", getppid());
856 getch2_disable(); // allow terminal to work properly with gdb
857 if (execlp("gdb", "gdb", prog_path
, spid
, "-ex", "bt", NULL
) == -1)
858 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
859 } else if (gdb_pid
< 0)
860 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
862 waitpid(gdb_pid
, NULL
, 0);
864 if (x
== SIGTRAP
) return;
872 #include "cfg-mplayer.h"
874 static int cfg_include(m_option_t
*conf
, char *filename
)
876 return m_config_parse_config_file(conf
->priv
, filename
);
879 static void parse_cfgfiles(struct MPContext
*mpctx
, m_config_t
* conf
)
883 if (!disable_system_conf
&&
884 m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
885 exit_player(mpctx
, EXIT_NONE
);
886 if ((conffile
= get_path("")) == NULL
) {
887 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"Cannot find HOME directory.\n");
892 mkdir(conffile
, 0777);
895 if ((conffile
= get_path("config")) == NULL
) {
896 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"get_path(\"config\") problem\n");
898 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
899 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Creating config file: %s\n", conffile
);
900 write(conffile_fd
, default_config
, strlen(default_config
));
903 if (!disable_user_conf
&&
904 m_config_parse_config_file(conf
, conffile
) < 0)
905 exit_player(mpctx
, EXIT_NONE
);
911 #define PROFILE_CFG_PROTOCOL "protocol."
913 static void load_per_protocol_config (m_config_t
* conf
, const char *const file
)
916 char protocol
[strlen (PROFILE_CFG_PROTOCOL
) + strlen (file
) + 1];
919 /* does filename actually uses a protocol ? */
920 str
= strstr (file
, "://");
924 sprintf (protocol
, "%s%s", PROFILE_CFG_PROTOCOL
, file
);
925 protocol
[strlen (PROFILE_CFG_PROTOCOL
)+strlen(file
)-strlen(str
)] = '\0';
926 p
= m_config_get_profile (conf
, protocol
);
929 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading protocol-related profile '%s'\n", protocol
);
930 m_config_set_profile(conf
,p
);
934 #define PROFILE_CFG_EXTENSION "extension."
936 static void load_per_extension_config (m_config_t
* conf
, const char *const file
)
939 char extension
[strlen (PROFILE_CFG_EXTENSION
) + 8];
942 /* does filename actually have an extension ? */
943 str
= strrchr (file
, '.');
947 sprintf (extension
, PROFILE_CFG_EXTENSION
);
948 strncat (extension
, ++str
, 7);
949 p
= m_config_get_profile (conf
, extension
);
952 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", extension
);
953 m_config_set_profile(conf
,p
);
957 #define PROFILE_CFG_VO "vo."
958 #define PROFILE_CFG_AO "ao."
960 static void load_per_output_config (m_config_t
* conf
, char *cfg
, char *out
)
962 char profile
[strlen (cfg
) + strlen (out
) + 1];
965 sprintf (profile
, "%s%s", cfg
, out
);
966 p
= m_config_get_profile (conf
, profile
);
969 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", profile
);
970 m_config_set_profile(conf
,p
);
975 * Tries to load a config file
976 * @return 0 if file was not found, 1 otherwise
978 static int try_load_config(m_config_t
*conf
, const char *file
)
983 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Loading config '%s'\n", file
);
984 m_config_parse_config_file (conf
, file
);
988 static void load_per_file_config (m_config_t
* conf
, const char *const file
)
994 if (strlen(file
) > PATH_MAX
- 14) {
995 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Filename is too long, can not load file or directory specific config files\n");
998 sprintf (cfg
, "%s.conf", file
);
1000 name
= strrchr(cfg
, '/');
1001 if (HAVE_DOS_PATHS
) {
1002 char *tmp
= strrchr(cfg
, '\\');
1003 if (!name
|| tmp
> name
)
1005 tmp
= strrchr(cfg
, ':');
1006 if (!name
|| tmp
> name
)
1014 if (use_filedir_conf
) {
1015 char dircfg
[PATH_MAX
];
1016 strcpy(dircfg
, cfg
);
1017 strcpy(dircfg
+ (name
- cfg
), "mplayer.conf");
1018 try_load_config(conf
, dircfg
);
1020 if (try_load_config(conf
, cfg
))
1024 if ((confpath
= get_path (name
)) != NULL
)
1026 try_load_config(conf
, confpath
);
1032 /* When libmpdemux performs a blocking operation (network connection or
1033 * cache filling) if the operation fails we use this function to check
1034 * if it was interrupted by the user.
1035 * The function returns a new value for eof. */
1036 static int libmpdemux_was_interrupted(struct MPContext
*mpctx
, int stop_play
)
1039 if((cmd
= mp_input_get_cmd(mpctx
->input
, 0,0,0)) != NULL
) {
1042 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
1043 case MP_CMD_PLAY_TREE_STEP
: {
1044 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
1045 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
1047 case MP_CMD_PLAY_TREE_UP_STEP
: {
1048 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
1050 case MP_CMD_PLAY_ALT_SRC_STEP
: {
1051 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
1059 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
1061 static int playtree_add_playlist(struct MPContext
*mpctx
, play_tree_t
* entry
)
1063 play_tree_add_bpf(entry
,mpctx
->filename
);
1067 entry
= mpctx
->playtree_iter
->tree
;
1068 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1069 return PT_NEXT_ENTRY
;
1071 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
1072 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1073 return PT_NEXT_ENTRY
;
1076 play_tree_remove(entry
,1,1);
1079 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
1080 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
1081 entry
= mpctx
->playtree_iter
->tree
;
1082 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1083 return PT_NEXT_ENTRY
;
1085 play_tree_remove(entry
,1,1);
1090 void add_subtitles(struct MPContext
*mpctx
, char *filename
, float fps
, int noerr
)
1092 struct MPOpts
*opts
= &mpctx
->opts
;
1093 sub_data
*subd
= NULL
;
1094 struct ass_track
*asst
= NULL
;
1096 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
1101 if (opts
->ass_enabled
) {
1103 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
1105 asst
= ass_read_file(ass_library
, filename
, 0);
1108 subd
= sub_read_file(filename
, fps
);
1110 asst
= ass_read_subdata(ass_library
, subd
, fps
);
1119 subd
= sub_read_file(filename
, fps
);
1122 if (!asst
&& !subd
) {
1123 mp_tmsg(MSGT_CPLAYER
, noerr
? MSGL_WARN
: MSGL_ERR
,
1124 "Cannot load subtitles: %s\n", filename_recode(filename
));
1128 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
1129 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
1130 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
1131 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
1132 filename_recode(filename
));
1133 ++mpctx
->set_of_sub_size
;
1134 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "SUB: Added subtitle file (%d): %s\n", mpctx
->set_of_sub_size
,
1135 filename_recode(filename
));
1138 void init_vo_spudec(struct MPContext
*mpctx
)
1141 spudec_free(vo_spudec
);
1142 mpctx
->initialized_flags
&= ~INITIALIZED_SPUDEC
;
1145 unsigned int palette
[16], width
, height
;
1146 current_module
="spudec_init_vobsub";
1147 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1148 vo_spudec
=spudec_new_scaled(palette
, width
, height
, NULL
, 0);
1151 #ifdef CONFIG_DVDREAD
1152 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1153 current_module
="spudec_init_dvdread";
1154 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1155 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
,
1160 #ifdef CONFIG_DVDNAV
1161 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1162 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1163 current_module
="spudec_init_dvdnav";
1164 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, NULL
, 0);
1168 if (vo_spudec
==NULL
) {
1169 sh_sub_t
*sh
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1170 current_module
="spudec_init_normal";
1171 vo_spudec
=spudec_new_scaled(NULL
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, sh
->extradata
, sh
->extradata_len
);
1172 spudec_set_font_factor(vo_spudec
,font_factor
);
1175 if (vo_spudec
!=NULL
) {
1176 mpctx
->initialized_flags
|=INITIALIZED_SPUDEC
;
1177 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
1182 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1183 * make it all work is to use the builtin SDL-bootstrap code, which
1184 * will be done automatically by replacing our main() if we include SDL.h.
1186 #if defined(__APPLE__) && defined(CONFIG_SDL)
1187 #ifdef CONFIG_SDL_SDL_H
1188 #include <SDL/SDL.h>
1195 * \brief append a formatted string
1196 * \param buf buffer to print into
1197 * \param pos position of terminating 0 in buf
1198 * \param len maximum number of characters in buf, not including terminating 0
1199 * \param format printf format string
1201 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1204 va_start(va
, format
);
1205 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1214 * \brief append time in the hh:mm:ss.f format
1215 * \param buf buffer to print into
1216 * \param pos position of terminating 0 in buf
1217 * \param len maximum number of characters in buf, not including terminating 0
1218 * \param time time value to convert/append
1220 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1221 long tenths
= 10 * time
;
1222 int f1
= tenths
% 10;
1223 int ss
= (tenths
/ 10) % 60;
1224 int mm
= (tenths
/ 600) % 60;
1225 int hh
= tenths
/ 36000;
1227 saddf(buf
, pos
, len
, "unknown");
1231 saddf(buf
, pos
, len
, "%2d:", hh
);
1232 if (hh
> 0 || mm
> 0)
1233 saddf(buf
, pos
, len
, "%02d:", mm
);
1234 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1237 static void print_status(struct MPContext
*mpctx
, double a_pos
, bool at_frame
)
1239 struct MPOpts
*opts
= &mpctx
->opts
;
1240 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1242 if (mpctx
->sh_audio
&& a_pos
== MP_NOPTS_VALUE
)
1243 a_pos
= playing_audio_pts(mpctx
);
1244 if (mpctx
->sh_audio
&& sh_video
&& at_frame
) {
1245 mpctx
->last_av_difference
= a_pos
- sh_video
->pts
- audio_delay
;
1246 if (mpctx
->time_frame
> 0)
1247 mpctx
->last_av_difference
+= mpctx
->time_frame
* opts
->playback_speed
;
1248 if (mpctx
->last_av_difference
> 0.5 && drop_frame_cnt
> 50
1249 && !mpctx
->drop_message_shown
) {
1250 mp_tmsg(MSGT_AVSYNC
,MSGL_WARN
,SystemTooSlow
);
1251 mpctx
->drop_message_shown
= true;
1262 if (screen_width
> 0)
1263 width
= screen_width
;
1266 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
1267 /* Windows command line is broken (MinGW's rxvt works, but we
1268 * should not depend on that). */
1271 line
= malloc(width
+ 1); // one additional char for the terminating null
1274 if (mpctx
->sh_audio
) {
1275 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1277 float len
= demuxer_get_time_length(mpctx
->demuxer
);
1278 saddf(line
, &pos
, width
, "(");
1279 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1280 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1281 sadd_hhmmssf(line
, &pos
, width
, len
);
1282 saddf(line
, &pos
, width
, ") ");
1288 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1291 if (mpctx
->sh_audio
&& sh_video
)
1292 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ",
1293 mpctx
->last_av_difference
, mpctx
->total_avsync_change
);
1297 saddf(line
, &pos
, width
, "%3d/%3d ",
1298 (int)sh_video
->num_frames
,
1299 (int)sh_video
->num_frames_decoded
);
1303 if (sh_video
->timer
> 0.5)
1304 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1305 (int)(100.0*video_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1306 (int)(100.0*vout_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1307 (100.0*audio_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
));
1309 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1310 } else if (mpctx
->sh_audio
) {
1311 if (mpctx
->delay
> 0.5)
1312 saddf(line
, &pos
, width
, "%4.1f%% ",
1313 100.0*audio_time_usage
/(double)mpctx
->delay
);
1315 saddf(line
, &pos
, width
, "??,?%% ");
1320 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1322 #ifdef CONFIG_STREAM_CACHE
1324 if (stream_cache_size
> 0)
1325 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1329 if (opts
->playback_speed
!= 1)
1330 saddf(line
, &pos
, width
, "%4.2fx ", opts
->playback_speed
);
1333 if (erase_to_end_of_line
) {
1335 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1337 memset(&line
[pos
], ' ', width
- pos
);
1339 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s\r", line
);
1345 * \brief build a chain of audio filters that converts the input format
1346 * to the ao's format, taking into account the current playback_speed.
1347 * \param sh_audio describes the requested input format of the chain.
1348 * \param ao_data describes the requested output format of the chain.
1350 int build_afilter_chain(struct MPContext
*mpctx
, sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1352 struct MPOpts
*opts
= &mpctx
->opts
;
1357 mpctx
->mixer
.afilter
= NULL
;
1360 if(af_control_any_rev(sh_audio
->afilter
,
1361 AF_CONTROL_PLAYBACK_SPEED
| AF_CONTROL_SET
,
1362 &opts
->playback_speed
)) {
1363 new_srate
= sh_audio
->samplerate
;
1365 new_srate
= sh_audio
->samplerate
* opts
->playback_speed
;
1366 if (new_srate
!= ao_data
->samplerate
) {
1367 // limits are taken from libaf/af_resample.c
1368 if (new_srate
< 8000)
1370 if (new_srate
> 192000)
1372 opts
->playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1375 result
= init_audio_filters(sh_audio
, new_srate
,
1376 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
);
1377 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1382 typedef struct mp_osd_msg mp_osd_msg_t
;
1384 /// Previous message on the stack.
1388 int id
,level
,started
;
1389 /// Display duration in ms.
1393 /// OSD message stack.
1394 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1397 * \brief Add a message on the OSD message stack
1399 * If a message with the same id is already present in the stack
1400 * it is pulled on top of the stack, otherwise a new message is created.
1403 static void set_osd_msg_va(int id
, int level
, int time
, const char *fmt
,
1406 mp_osd_msg_t
*msg
,*last
=NULL
;
1409 // look if the id is already in the stack
1410 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1411 last
= msg
, msg
= msg
->prev
);
1412 // not found: alloc it
1414 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1415 msg
->prev
= osd_msg_stack
;
1416 osd_msg_stack
= msg
;
1417 } else if(last
) { // found, but it's not on top of the stack
1418 last
->prev
= msg
->prev
;
1419 msg
->prev
= osd_msg_stack
;
1420 osd_msg_stack
= msg
;
1423 r
= vsnprintf(msg
->msg
, 128, fmt
, ap
);
1424 if(r
>= 128) msg
->msg
[127] = 0;
1432 void set_osd_msg(int id
, int level
, int time
, const char *fmt
, ...)
1436 set_osd_msg_va(id
, level
, time
, fmt
, ap
);
1440 void set_osd_tmsg(int id
, int level
, int time
, const char *fmt
, ...)
1444 set_osd_msg_va(id
, level
, time
, mp_gtext(fmt
), ap
);
1450 * \brief Remove a message from the OSD stack
1452 * This function can be used to get rid of a message right away.
1456 void rm_osd_msg(int id
) {
1457 mp_osd_msg_t
*msg
,*last
=NULL
;
1459 // Search for the msg
1460 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1461 last
= msg
, msg
= msg
->prev
);
1464 // Detach it from the stack and free it
1466 last
->prev
= msg
->prev
;
1468 osd_msg_stack
= msg
->prev
;
1473 * \brief Remove all messages from the OSD stack
1477 static void clear_osd_msgs(void) {
1478 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1484 osd_msg_stack
= NULL
;
1488 * \brief Get the current message from the OSD stack.
1490 * This function decrements the message timer and destroys the old ones.
1491 * The message that should be displayed is returned (if any).
1495 static mp_osd_msg_t
* get_osd_msg(struct MPContext
*mpctx
)
1497 struct MPOpts
*opts
= &mpctx
->opts
;
1498 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1499 static unsigned last_update
= 0;
1500 unsigned now
= GetTimerMS();
1502 char hidden_dec_done
= 0;
1504 if (mpctx
->osd_visible
) {
1505 // 36000000 means max timed visibility is 1 hour into the future, if
1506 // the difference is greater assume it's wrapped around from below 0
1507 if (mpctx
->osd_visible
- now
> 36000000) {
1508 mpctx
->osd_visible
= 0;
1509 vo_osd_progbar_type
= -1; // disable
1510 vo_osd_changed(OSDTYPE_PROGBAR
);
1511 mpctx
->osd_function
= mpctx
->paused
? OSD_PAUSE
: OSD_PLAY
;
1514 if (mpctx
->osd_show_percentage_until
- now
> 36000000)
1515 mpctx
->osd_show_percentage_until
= 0;
1517 if(!last_update
) last_update
= now
;
1518 diff
= now
>= last_update
? now
- last_update
: 0;
1522 // Look for the first message in the stack with high enough level.
1523 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1525 if (msg
->level
> opts
->osd_level
&& hidden_dec_done
)
1527 // The message has a high enough level or it is the first hidden one
1528 // in both cases we decrement the timer or kill it.
1529 if(!msg
->started
|| msg
->time
> diff
) {
1530 if(msg
->started
) msg
->time
-= diff
;
1531 else msg
->started
= 1;
1533 if (msg
->level
<= opts
->osd_level
)
1535 hidden_dec_done
= 1;
1544 osd_msg_stack
= prev
;
1553 * \brief Display the OSD bar.
1555 * Display the OSD bar or fall back on a simple message.
1559 void set_osd_bar(struct MPContext
*mpctx
, int type
,const char* name
,double min
,double max
,double val
) {
1560 struct MPOpts
*opts
= &mpctx
->opts
;
1561 if (opts
->osd_level
< 1)
1564 if(mpctx
->sh_video
) {
1565 mpctx
->osd_visible
= (GetTimerMS() + 1000) | 1;
1566 vo_osd_progbar_type
= type
;
1567 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1568 vo_osd_changed(OSDTYPE_PROGBAR
);
1572 set_osd_msg(OSD_MSG_BAR
, 1, opts
->osd_duration
, "%s: %d %%",
1573 name
, ROUND(100*(val
-min
)/(max
-min
)));
1577 * \brief Display text subtitles on the OSD
1579 void set_osd_subtitle(struct MPContext
*mpctx
, subtitle
*subs
)
1583 vo_osd_changed(OSDTYPE_SUBTITLE
);
1584 if (!mpctx
->sh_video
) {
1585 // reverse order, since newest set_osd_msg is displayed first
1586 for (i
= SUB_MAX_TEXT
- 1; i
>= 0; i
--) {
1587 if (!subs
|| i
>= subs
->lines
|| !subs
->text
[i
])
1588 rm_osd_msg(OSD_MSG_SUB_BASE
+ i
);
1590 // HACK: currently display time for each sub line except the last is set to 2 seconds.
1591 int display_time
= i
== subs
->lines
- 1 ? 180000 : 2000;
1592 set_osd_msg(OSD_MSG_SUB_BASE
+ i
, 1, display_time
, "%s", subs
->text
[i
]);
1599 * \brief Update the OSD message line.
1601 * This function displays the current message on the vo OSD or on the term.
1602 * If the stack is empty and the OSD level is high enough the timer
1603 * is displayed (only on the vo OSD).
1607 static void update_osd_msg(struct MPContext
*mpctx
)
1609 struct MPOpts
*opts
= &mpctx
->opts
;
1611 struct osd_state
*osd
= mpctx
->osd
;
1612 char osd_text_timer
[128];
1614 if (mpctx
->add_osd_seek_info
) {
1616 if (mpctx
->timeline
&& mpctx
->sh_video
)
1617 percentage
= mpctx
->sh_video
->pts
* 100 /
1618 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1620 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1621 set_osd_bar(mpctx
, 0, "Position", 0, 100, percentage
);
1622 if (mpctx
->sh_video
)
1623 mpctx
->osd_show_percentage_until
= (GetTimerMS() + 1000) | 1;
1624 mpctx
->add_osd_seek_info
= false;
1627 // Look if we have a msg
1628 if((msg
= get_osd_msg(mpctx
))) {
1629 if (strcmp(osd
->osd_text
, msg
->msg
)) {
1630 strncpy(osd
->osd_text
, msg
->msg
, 127);
1631 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1632 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1637 if(mpctx
->sh_video
) {
1638 // fallback on the timer
1639 if (opts
->osd_level
>= 2) {
1641 if (mpctx
->timeline
)
1642 len
= mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1644 len
= demuxer_get_time_length(mpctx
->demuxer
);
1645 int percentage
= -1;
1646 char percentage_text
[10];
1647 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1649 if (mpctx
->osd_show_percentage_until
)
1650 if (mpctx
->timeline
)
1651 percentage
= mpctx
->sh_video
->pts
* 100 /
1652 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1654 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1656 if (percentage
>= 0)
1657 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1659 percentage_text
[0] = 0;
1661 if (opts
->osd_level
== 3)
1662 snprintf(osd_text_timer
, 63,
1663 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1664 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1665 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1667 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1668 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1669 pts
%60,percentage_text
);
1671 osd_text_timer
[0]=0;
1673 if (strcmp(osd
->osd_text
, osd_text_timer
)) {
1674 strncpy(osd
->osd_text
, osd_text_timer
, 63);
1675 vo_osd_changed(OSDTYPE_OSD
);
1680 // Clear the term osd line
1681 if (term_osd
&& osd
->osd_text
[0]) {
1682 osd
->osd_text
[0] = 0;
1683 printf("%s\n",term_osd_esc
);
1691 void reinit_audio_chain(struct MPContext
*mpctx
)
1693 struct MPOpts
*opts
= &mpctx
->opts
;
1694 if (!mpctx
->sh_audio
)
1696 current_module
="init_audio_codec";
1697 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1698 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1701 mpctx
->initialized_flags
|=INITIALIZED_ACODEC
;
1702 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1705 current_module
="af_preinit";
1706 ao_data
.samplerate
=force_srate
;
1708 ao_data
.format
=audio_output_format
;
1710 // first init to detect best values
1711 if(!init_audio_filters(mpctx
->sh_audio
, // preliminary init
1713 mpctx
->sh_audio
->samplerate
,
1715 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1716 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
, "Error at audio filter chain "
1718 exit_player(mpctx
, EXIT_ERROR
);
1721 current_module
="ao2_init";
1722 mpctx
->audio_out
= init_best_audio_out(opts
->audio_driver_list
,
1727 if(!mpctx
->audio_out
){
1728 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Could not open/initialize audio device -> no sound.\n");
1731 mpctx
->initialized_flags
|=INITIALIZED_AO
;
1732 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1733 mpctx
->audio_out
->info
->short_name
,
1734 ao_data
.samplerate
, ao_data
.channels
,
1735 af_fmt2str_short(ao_data
.format
),
1736 af_fmt2bits(ao_data
.format
)/8 );
1737 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1738 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1739 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1740 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1741 // init audio filters:
1743 current_module
="af_init";
1744 if(!build_afilter_chain(mpctx
, mpctx
->sh_audio
, &ao_data
)) {
1745 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Couldn't find matching filter/ao format!\n");
1749 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1750 mpctx
->mixer
.volstep
= volstep
;
1754 uninit_player(mpctx
, INITIALIZED_ACODEC
|INITIALIZED_AO
); // close codec and possibly AO
1755 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1756 mpctx
->d_audio
->id
= -2;
1764 // Return pts value corresponding to the end point of audio written to the
1766 static double written_audio_pts(struct MPContext
*mpctx
)
1768 sh_audio_t
*sh_audio
= mpctx
->sh_audio
;
1769 demux_stream_t
*d_audio
= mpctx
->d_audio
;
1770 double buffered_output
;
1771 // first calculate the end pts of audio that has been output by decoder
1772 double a_pts
= sh_audio
->pts
;
1773 if (a_pts
!= MP_NOPTS_VALUE
)
1774 // Good, decoder supports new way of calculating audio pts.
1775 // sh_audio->pts is the timestamp of the latest input packet with
1776 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1777 // the amount of bytes the decoder has written after that timestamp.
1778 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1780 // Decoder doesn't support new way of calculating pts (or we're
1781 // being called before it has decoded anything with known timestamp).
1782 // Use the old method of audio pts calculation: take the timestamp
1783 // of last packet with known pts the decoder has read data from,
1784 // and add amount of bytes read after the beginning of that packet
1785 // divided by input bps. This will be inaccurate if the input/output
1786 // ratio is not constant for every audio packet or if it is constant
1787 // but not accurately known in sh_audio->i_bps.
1789 a_pts
= d_audio
->pts
;
1790 // ds_tell_pts returns bytes read after last timestamp from
1791 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1792 // it has read but not decoded
1793 if (sh_audio
->i_bps
)
1794 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1795 (double)sh_audio
->i_bps
;
1797 // Now a_pts hopefully holds the pts for end of audio from decoder.
1798 // Substract data in buffers between decoder and audio out.
1800 // Decoded but not filtered
1801 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1803 // Data buffered in audio filters, measured in bytes of "missing" output
1804 buffered_output
= af_calc_delay(sh_audio
->afilter
);
1806 // Data that was ready for ao but was buffered because ao didn't fully
1807 // accept everything to internal buffers yet
1808 buffered_output
+= sh_audio
->a_out_buffer_len
;
1810 // Filters divide audio length by playback_speed, so multiply by it
1811 // to get the length in original units without speedup or slowdown
1812 a_pts
-= buffered_output
* mpctx
->opts
.playback_speed
/ ao_data
.bps
;
1814 return a_pts
+ mpctx
->video_offset
;
1817 // Return pts value corresponding to currently playing audio.
1818 double playing_audio_pts(struct MPContext
*mpctx
)
1820 return written_audio_pts(mpctx
) - mpctx
->opts
.playback_speed
*
1821 mpctx
->audio_out
->get_delay();
1824 static int check_framedrop(struct MPContext
*mpctx
, double frame_time
) {
1825 struct MPOpts
*opts
= &mpctx
->opts
;
1826 // check for frame-drop:
1827 current_module
= "check_framedrop";
1828 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1829 static int dropped_frames
;
1830 float delay
= opts
->playback_speed
*mpctx
->audio_out
->get_delay();
1831 float d
= delay
-mpctx
->delay
;
1833 // we should avoid dropping too many frames in sequence unless we
1834 // are too late. and we allow 100ms A-V delay here:
1835 if (d
< -dropped_frames
*frame_time
-0.100 && !mpctx
->paused
1836 && !mpctx
->update_video_immediately
) {
1839 return frame_dropping
;
1851 static float timing_sleep(struct MPContext
*mpctx
, float time_frame
)
1855 // -------- RTC -----------
1856 current_module
="sleep_rtc";
1857 while (time_frame
> 0.000) {
1858 unsigned long rtc_ts
;
1859 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1860 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC read error: %s\n", strerror(errno
));
1861 time_frame
-= get_relative_time(mpctx
);
1866 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1867 // unnecessarily high CPU usage
1868 float margin
= softsleep
? 0.011 : 0;
1869 current_module
= "sleep_timer";
1870 while (time_frame
> margin
) {
1871 usec_sleep(1000000 * (time_frame
- margin
));
1872 time_frame
-= get_relative_time(mpctx
);
1875 current_module
= "sleep_soft";
1877 mp_tmsg(MSGT_AVSYNC
, MSGL_WARN
, "Warning! Softsleep underflow!\n");
1878 while (time_frame
> 0)
1879 time_frame
-= get_relative_time(mpctx
); // burn the CPU
1885 static void select_subtitle(MPContext
*mpctx
)
1887 struct MPOpts
*opts
= &mpctx
->opts
;
1888 // find the best sub to use
1889 int vobsub_index_id
= vobsub_get_index_by_id(vo_vobsub
, vobsub_id
);
1890 mpctx
->global_sub_pos
= -1; // no subs by default
1891 if (vobsub_index_id
>= 0) {
1892 // if user asks for a vobsub id, use that first.
1893 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_index_id
;
1894 } else if (opts
->sub_id
>= 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
1895 // if user asks for a dvd sub id, use that next.
1896 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
;
1897 } else if (mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
1898 // if there are text subs to use, use those. (autosubs come last here)
1899 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
];
1900 } else if (opts
->sub_id
== -1 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
1901 // finally select subs by language and container hints
1902 if (opts
->sub_id
== -1 && dvdsub_lang
)
1903 opts
->sub_id
= demuxer_sub_track_by_lang(mpctx
->demuxer
, dvdsub_lang
);
1904 if (opts
->sub_id
== -1)
1905 opts
->sub_id
= demuxer_default_sub_track(mpctx
->demuxer
);
1906 if (opts
->sub_id
>= 0)
1907 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
;
1909 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1910 mpctx
->global_sub_pos
--;
1911 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
, mpctx
);
1914 #ifdef CONFIG_DVDNAV
1918 /// store decoded video image
1919 static mp_image_t
* mp_dvdnav_copy_mpi(mp_image_t
*to_mpi
,
1920 mp_image_t
*from_mpi
) {
1923 /// Do not store B-frames
1924 if (from_mpi
->pict_type
== FF_B_TYPE
)
1928 to_mpi
->w
== from_mpi
->w
&&
1929 to_mpi
->h
== from_mpi
->h
&&
1930 to_mpi
->imgfmt
== from_mpi
->imgfmt
)
1934 free_mp_image(to_mpi
);
1935 if (from_mpi
->w
== 0 || from_mpi
->h
== 0)
1937 mpi
= alloc_mpi(from_mpi
->w
,from_mpi
->h
,from_mpi
->imgfmt
);
1940 copy_mpi(mpi
,from_mpi
);
1944 static void mp_dvdnav_reset_stream (MPContext
*ctx
) {
1945 struct MPOpts
*opts
= &ctx
->opts
;
1946 if (ctx
->sh_video
) {
1948 ctx
->d_video
->pts
= 0.0f
;
1949 ctx
->sh_video
->pts
= 0.0f
;
1950 ctx
->sh_video
->i_pts
= 0.0f
;
1951 ctx
->sh_video
->last_pts
= 0.0f
;
1952 ctx
->sh_video
->num_buffered_pts
= 0;
1953 ctx
->sh_video
->num_frames
= 0;
1954 ctx
->sh_video
->num_frames_decoded
= 0;
1955 ctx
->sh_video
->timer
= 0.0f
;
1956 ctx
->sh_video
->stream_delay
= 0.0f
;
1957 ctx
->sh_video
->timer
= 0;
1958 ctx
->demuxer
->stream_pts
= MP_NOPTS_VALUE
;
1961 if (ctx
->sh_audio
) {
1962 /// free audio packets and reset
1963 ds_free_packs(ctx
->d_audio
);
1964 audio_delay
-= ctx
->sh_audio
->stream_delay
;
1965 ctx
->delay
=- audio_delay
;
1966 ctx
->audio_out
->reset();
1967 resync_audio_stream(ctx
->sh_audio
);
1971 ctx
->global_sub_size
= ctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + mp_dvdnav_number_of_subs(ctx
->stream
);
1972 if (dvdsub_lang
&& opts
->sub_id
== dvdsub_lang_id
) {
1973 dvdsub_lang_id
= mp_dvdnav_sid_from_lang(ctx
->stream
, dvdsub_lang
);
1974 if (dvdsub_lang_id
!= opts
->sub_id
) {
1975 opts
->sub_id
= dvdsub_lang_id
;
1976 select_subtitle(ctx
);
1980 /// clear all EOF related flags
1981 ctx
->d_video
->eof
= ctx
->d_audio
->eof
= ctx
->stream
->eof
= 0;
1984 /// Restore last decoded DVDNAV (still frame)
1985 static mp_image_t
*mp_dvdnav_restore_smpi(struct MPContext
*mpctx
,
1987 unsigned char **start
,
1988 mp_image_t
*decoded_frame
)
1990 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
1991 return decoded_frame
;
1993 /// a change occured in dvdnav stream
1994 if (mp_dvdnav_cell_has_changed(mpctx
->stream
,0)) {
1995 mp_dvdnav_read_wait(mpctx
->stream
, 1, 1);
1996 mp_dvdnav_context_free(mpctx
);
1997 mp_dvdnav_reset_stream(mpctx
);
1998 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
1999 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
2005 /// Display still frame, if any
2006 if (mpctx
->nav_smpi
&& !mpctx
->nav_buffer
)
2007 decoded_frame
= mpctx
->nav_smpi
;
2009 /// increment video frame : continue playing after still frame
2010 len
= demuxer_get_time_length(mpctx
->demuxer
);
2011 if (mpctx
->sh_video
->pts
>= len
&&
2012 mpctx
->sh_video
->pts
> 0.0 && len
> 0.0) {
2013 mp_dvdnav_skip_still(mpctx
->stream
);
2014 mp_dvdnav_skip_wait(mpctx
->stream
);
2016 mpctx
->sh_video
->pts
+= 1 / mpctx
->sh_video
->fps
;
2018 if (mpctx
->nav_buffer
) {
2019 *start
= mpctx
->nav_start
;
2020 *in_size
= mpctx
->nav_in_size
;
2021 if (mpctx
->nav_start
)
2022 memcpy(*start
,mpctx
->nav_buffer
,mpctx
->nav_in_size
);
2026 return decoded_frame
;
2029 /// Save last decoded DVDNAV (still frame)
2030 static void mp_dvdnav_save_smpi(struct MPContext
*mpctx
, int in_size
,
2031 unsigned char *start
,
2032 mp_image_t
*decoded_frame
)
2034 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
2037 if (mpctx
->nav_buffer
)
2038 free(mpctx
->nav_buffer
);
2040 mpctx
->nav_buffer
= malloc(in_size
);
2041 mpctx
->nav_start
= start
;
2042 mpctx
->nav_in_size
= mpctx
->nav_buffer
? in_size
: -1;
2043 if (mpctx
->nav_buffer
)
2044 memcpy(mpctx
->nav_buffer
,start
,in_size
);
2046 if (decoded_frame
&& mpctx
->nav_smpi
!= decoded_frame
)
2047 mpctx
->nav_smpi
= mp_dvdnav_copy_mpi(mpctx
->nav_smpi
,decoded_frame
);
2049 #endif /* CONFIG_DVDNAV */
2051 /* Modify video timing to match the audio timeline. There are two main
2052 * reasons this is needed. First, video and audio can start from different
2053 * positions at beginning of file or after a seek (MPlayer starts both
2054 * immediately even if they have different pts). Second, the file can have
2055 * audio timestamps that are inconsistent with the duration of the audio
2056 * packets, for example two consecutive timestamp values differing by
2057 * one second but only a packet with enough samples for half a second
2058 * of playback between them.
2060 static void adjust_sync(struct MPContext
*mpctx
, double frame_time
)
2062 current_module
= "av_sync";
2064 if (!mpctx
->sh_audio
)
2067 double a_pts
= written_audio_pts(mpctx
) - mpctx
->delay
;
2068 double v_pts
= mpctx
->sh_video
->pts
;
2069 double av_delay
= a_pts
- v_pts
;
2070 // Try to sync vo_flip() so it will *finish* at given time
2071 av_delay
+= mpctx
->last_vo_flip_duration
;
2072 av_delay
-= audio_delay
; // This much pts difference is desired
2074 double change
= av_delay
* 0.1;
2075 double max_change
= default_max_pts_correction
>= 0 ?
2076 default_max_pts_correction
: frame_time
* 0.1;
2077 if (change
< -max_change
)
2078 change
= -max_change
;
2079 else if (change
> max_change
)
2080 change
= max_change
;
2081 mpctx
->delay
+= change
;
2082 mpctx
->total_avsync_change
+= change
;
2085 static int fill_audio_out_buffers(struct MPContext
*mpctx
)
2087 struct MPOpts
*opts
= &mpctx
->opts
;
2093 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
2095 current_module
="play_audio";
2099 // all the current uses of ao_data.pts seem to be in aos that handle
2100 // sync completely wrong; there should be no need to use ao_data.pts
2102 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2103 playsize
= mpctx
->audio_out
->get_space();
2104 if (mpctx
->sh_video
|| playsize
>= ao_data
.outburst
)
2107 // handle audio-only case:
2108 // this is where mplayer sleeps during audio-only playback
2109 // to avoid 100% CPU use
2110 sleep_time
= (ao_data
.outburst
- playsize
) * 1000 / ao_data
.bps
;
2111 if (sleep_time
< 10) sleep_time
= 10; // limit to 100 wakeups per second
2112 usec_sleep(sleep_time
* 1000);
2115 // Fill buffer if needed:
2116 current_module
="decode_audio";
2118 if (decode_audio(sh_audio
, playsize
) < 0) // EOF or error
2119 if (mpctx
->d_audio
->eof
) {
2121 if (sh_audio
->a_out_buffer_len
== 0)
2125 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2126 if (playsize
> sh_audio
->a_out_buffer_len
) {
2127 playsize
= sh_audio
->a_out_buffer_len
;
2129 playflags
|= AOPLAY_FINAL_CHUNK
;
2135 current_module
="play_audio";
2137 // Is this pts value actually useful for the aos that access it?
2138 // They're obviously badly broken in the way they handle av sync;
2139 // would not having access to this make them more broken?
2140 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2141 playsize
= mpctx
->audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
2144 sh_audio
->a_out_buffer_len
-= playsize
;
2145 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
2146 sh_audio
->a_out_buffer_len
);
2147 mpctx
->delay
+= opts
->playback_speed
*playsize
/(double)ao_data
.bps
;
2149 else if (audio_eof
&& mpctx
->audio_out
->get_delay() < .04) {
2150 // Sanity check to avoid hanging in case current ao doesn't output
2151 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
2152 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
2153 sh_audio
->a_out_buffer_len
= 0;
2159 static int sleep_until_update(struct MPContext
*mpctx
, float *time_frame
,
2160 float *aq_sleep_time
)
2162 struct MPOpts
*opts
= &mpctx
->opts
;
2163 int frame_time_remaining
= 0;
2164 current_module
="calc_sleep_time";
2166 *time_frame
-= get_relative_time(mpctx
); // reset timer
2168 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
2169 float delay
= mpctx
->audio_out
->get_delay();
2170 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
2174 * Adjust this raw delay value by calculating the expected
2175 * delay for this frame and generating a new value which is
2176 * weighted between the two. The higher autosync is, the
2177 * closer to the delay value gets to that which "-nosound"
2178 * would have used, and the longer it will take for A/V
2179 * sync to settle at the right value (but it eventually will.)
2180 * This settling time is very short for values below 100.
2182 float predicted
= mpctx
->delay
/ opts
->playback_speed
+ *time_frame
;
2183 float difference
= delay
- predicted
;
2184 delay
= predicted
+ difference
/ (float)autosync
;
2187 *time_frame
= delay
- mpctx
->delay
/ opts
->playback_speed
;
2189 // delay = amount of audio buffered in soundcard/driver
2190 if (delay
> 0.25) delay
=0.25; else
2191 if (delay
< 0.10) delay
=0.10;
2192 if (*time_frame
> delay
*0.6) {
2193 // sleep time too big - may cause audio drops (buffer underrun)
2194 frame_time_remaining
= 1;
2195 *time_frame
= delay
*0.5;
2198 // If we're lagging more than 200 ms behind the right playback rate,
2199 // don't try to "catch up".
2200 // If benchmark is set always output frames as fast as possible
2201 // without sleeping.
2202 if (*time_frame
< -0.2 || benchmark
)
2206 *aq_sleep_time
+= *time_frame
;
2209 //============================== SLEEP: ===================================
2211 *time_frame
-= mpctx
->video_out
->flip_queue_offset
;
2212 // flag 256 means: libvo driver does its timing (dvb card)
2213 if (*time_frame
> 0.001 && !(mpctx
->sh_video
->output_flags
&256))
2214 *time_frame
= timing_sleep(mpctx
, *time_frame
);
2215 *time_frame
+= mpctx
->video_out
->flip_queue_offset
;
2216 return frame_time_remaining
;
2219 int reinit_video_chain(struct MPContext
*mpctx
)
2221 struct MPOpts
*opts
= &mpctx
->opts
;
2222 sh_video_t
* const sh_video
= mpctx
->sh_video
;
2224 //================== Init VIDEO (codec & libvo) ==========================
2225 if (!opts
->fixed_vo
|| !(mpctx
->initialized_flags
& INITIALIZED_VO
)) {
2226 current_module
="preinit_libvo";
2228 //shouldn't we set dvideo->id=-2 when we fail?
2229 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
2230 if(!(mpctx
->video_out
=init_best_video_out(opts
, mpctx
->x11_state
, mpctx
->key_fifo
, mpctx
->input
))){
2231 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Error opening/initializing the selected video_out (-vo) device.\n");
2234 mpctx
->initialized_flags
|=INITIALIZED_VO
;
2237 if(stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_ASPECT_RATIO
, &ar
) != STREAM_UNSUPPORTED
)
2238 mpctx
->sh_video
->stream_aspect
= ar
;
2239 current_module
="init_video_filters";
2241 char* vf_arg
[] = { "_oldargs_", (char*)mpctx
->video_out
, NULL
};
2242 sh_video
->vfilter
= vf_open_filter(opts
, NULL
,"vo",vf_arg
);
2246 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
2247 vf_menu
= vf_open_plugin(opts
,libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
2249 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Can't open libmenu video filter with root menu %s.\n",menu_root
);
2254 sh_video
->vfilter
= vf_menu
;
2258 if(opts
->ass_enabled
) {
2261 if (opts
->vf_settings
)
2262 for (i
= 0; opts
->vf_settings
[i
].name
; ++i
)
2263 if (strcmp(opts
->vf_settings
[i
].name
, "ass") == 0) {
2268 extern vf_info_t vf_info_ass
;
2269 const vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
2270 char* vf_arg
[] = {"auto", "1", NULL
};
2272 struct vf_instance
*vf_ass
= vf_open_plugin_noerr(opts
, libass_vfs
,
2277 sh_video
->vfilter
= vf_ass
;
2278 else if (retcode
== -1) // vf_ass open() returns -1 if there's VO EOSD
2279 mp_msg(MSGT_CPLAYER
, MSGL_V
, "[ass] vf_ass not needed\n");
2281 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
2286 sh_video
->vfilter
= append_filters(sh_video
->vfilter
, opts
->vf_settings
);
2289 if (opts
->ass_enabled
)
2290 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
2293 current_module
="init_video_codec";
2295 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2296 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
2297 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2299 if(!sh_video
->initialized
){
2300 if(!opts
->fixed_vo
) uninit_player(mpctx
, INITIALIZED_VO
);
2304 mpctx
->initialized_flags
|=INITIALIZED_VCODEC
;
2306 if (sh_video
->codec
)
2307 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
2309 sh_video
->last_pts
= MP_NOPTS_VALUE
;
2310 sh_video
->num_buffered_pts
= 0;
2311 sh_video
->next_frame_time
= 0;
2314 // Auto quality option enabled
2315 output_quality
=get_video_quality_max(sh_video
);
2316 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
2317 else output_quality
=auto_quality
;
2318 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
2319 set_video_quality(sh_video
,output_quality
);
2322 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2324 current_module
="init_vo";
2329 mpctx
->sh_video
= mpctx
->d_video
->sh
= NULL
;
2333 static double update_video_nocorrect_pts(struct MPContext
*mpctx
)
2335 struct sh_video
*sh_video
= mpctx
->sh_video
;
2336 double frame_time
= 0;
2337 struct vo
*video_out
= mpctx
->video_out
;
2338 while (!video_out
->frame_loaded
) {
2339 current_module
= "filter_video";
2340 // In nocorrect-pts mode there is no way to properly time these frames
2341 if (vo_get_buffered_frame(video_out
, 0) >= 0)
2343 if (vf_output_queued_frame(sh_video
->vfilter
))
2345 unsigned char *packet
= NULL
;
2346 frame_time
= sh_video
->next_frame_time
;
2347 if (mpctx
->update_video_immediately
)
2349 int in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2350 &packet
, force_fps
);
2352 #ifdef CONFIG_DVDNAV
2353 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
2354 if (mp_dvdnav_is_eof(mpctx
->stream
))
2357 mpctx
->d_video
->eof
= 0;
2359 mpctx
->d_audio
->eof
= 0;
2360 mpctx
->stream
->eof
= 0;
2365 if (in_size
> max_framesize
)
2366 max_framesize
= in_size
;
2367 sh_video
->timer
+= frame_time
;
2368 if (mpctx
->sh_audio
)
2369 mpctx
->delay
-= frame_time
;
2370 // video_read_frame can change fps (e.g. for ASF video)
2371 vo_fps
= sh_video
->fps
;
2372 int framedrop_type
= check_framedrop(mpctx
, frame_time
);
2373 current_module
= "decode video";
2375 void *decoded_frame
;
2376 #ifdef CONFIG_DVDNAV
2377 decoded_frame
= mp_dvdnav_restore_smpi(mpctx
, &in_size
, &packet
, NULL
);
2378 if (in_size
>= 0 && !decoded_frame
)
2380 decoded_frame
= decode_video(sh_video
, packet
, in_size
, framedrop_type
,
2382 #ifdef CONFIG_DVDNAV
2383 // Save last still frame for future display
2384 mp_dvdnav_save_smpi(mpctx
, in_size
, packet
, decoded_frame
);
2386 if (decoded_frame
) {
2387 current_module
= "filter video";
2388 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2389 if (!video_out
->config_ok
)
2396 static void determine_frame_pts(struct MPContext
*mpctx
)
2398 struct sh_video
*sh_video
= mpctx
->sh_video
;
2399 struct MPOpts
*opts
= &mpctx
->opts
;
2401 if (opts
->user_pts_assoc_mode
) {
2402 sh_video
->pts_assoc_mode
= opts
->user_pts_assoc_mode
;
2403 } else if (sh_video
->pts_assoc_mode
== 0) {
2404 if (sh_video
->codec_reordered_pts
!= MP_NOPTS_VALUE
)
2405 sh_video
->pts_assoc_mode
= 1;
2407 sh_video
->pts_assoc_mode
= 2;
2409 int probcount1
= sh_video
->num_reordered_pts_problems
;
2410 int probcount2
= sh_video
->num_sorted_pts_problems
;
2411 if (sh_video
->pts_assoc_mode
== 2) {
2412 int tmp
= probcount1
;
2413 probcount1
= probcount2
;
2416 if (probcount1
>= probcount2
* 1.5 + 2) {
2417 sh_video
->pts_assoc_mode
= 3 - sh_video
->pts_assoc_mode
;
2418 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Switching to pts association mode "
2419 "%d.\n", sh_video
->pts_assoc_mode
);
2422 sh_video
->pts
= sh_video
->pts_assoc_mode
== 1 ?
2423 sh_video
->codec_reordered_pts
: sh_video
->sorted_pts
;
2426 static double update_video(struct MPContext
*mpctx
)
2428 struct sh_video
*sh_video
= mpctx
->sh_video
;
2429 struct vo
*video_out
= mpctx
->video_out
;
2430 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_SET_OSD_OBJ
,
2431 mpctx
->osd
); // hack for vf_expand
2432 if (!mpctx
->opts
.correct_pts
)
2433 return update_video_nocorrect_pts(mpctx
);
2437 bool hit_eof
= false;
2438 while (!video_out
->frame_loaded
) {
2439 current_module
= "filter_video";
2440 if (vo_get_buffered_frame(video_out
, hit_eof
) >= 0)
2442 // XXX Time used in this call is not counted in any performance
2443 // timer now, OSD time is not updated correctly for filter-added frames
2444 if (vf_output_queued_frame(sh_video
->vfilter
))
2448 unsigned char *packet
= NULL
;
2449 int in_size
= ds_get_packet_pts(mpctx
->d_video
, &packet
, &pts
);
2450 if (pts
!= MP_NOPTS_VALUE
)
2451 pts
+= mpctx
->video_offset
;
2453 // try to extract last frames in case of decoder lag
2458 if (in_size
> max_framesize
)
2459 max_framesize
= in_size
;
2460 current_module
= "decode video";
2461 int framedrop_type
= check_framedrop(mpctx
, sh_video
->frametime
);
2462 void *decoded_frame
= decode_video(sh_video
, packet
, in_size
,
2463 framedrop_type
, pts
);
2464 if (decoded_frame
) {
2465 determine_frame_pts(mpctx
);
2466 current_module
= "filter video";
2467 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2468 if (!video_out
->config_ok
)
2469 break; // We'd likely hang in this loop otherwise
2473 pts
= video_out
->next_pts
;
2474 if (pts
== MP_NOPTS_VALUE
) {
2475 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Video pts after filters MISSING\n");
2476 // Try to use decoder pts from before filters
2477 pts
= sh_video
->pts
;
2478 if (pts
== MP_NOPTS_VALUE
)
2479 pts
= sh_video
->last_pts
;
2481 sh_video
->pts
= pts
;
2482 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2483 sh_video
->last_pts
= sh_video
->pts
;
2484 else if (sh_video
->last_pts
> sh_video
->pts
) {
2485 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Decreasing video pts: %f < %f\n",
2486 sh_video
->pts
, sh_video
->last_pts
);
2487 /* If the difference in pts is small treat it as jitter around the
2488 * right value (possibly caused by incorrect timestamp ordering) and
2489 * just show this frame immediately after the last one.
2490 * Treat bigger differences as timestamp resets and start counting
2491 * timing of later frames from the position of this one. */
2492 if (sh_video
->last_pts
- sh_video
->pts
> 0.5)
2493 sh_video
->last_pts
= sh_video
->pts
;
2495 sh_video
->pts
= sh_video
->last_pts
;
2497 double frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2498 sh_video
->last_pts
= sh_video
->pts
;
2499 sh_video
->timer
+= frame_time
;
2500 if (mpctx
->sh_audio
)
2501 mpctx
->delay
-= frame_time
;
2505 void pause_player(struct MPContext
*mpctx
)
2510 mpctx
->step_frames
= 0;
2511 mpctx
->time_frame
-= get_relative_time(mpctx
);
2513 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2514 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2516 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2517 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2520 void unpause_player(struct MPContext
*mpctx
)
2526 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2527 mpctx
->audio_out
->resume(); // resume audio
2528 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
2529 && !mpctx
->step_frames
)
2530 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
); // resume video
2531 (void)get_relative_time(mpctx
); // ignore time that passed during pause
2534 void add_step_frame(struct MPContext
*mpctx
)
2536 mpctx
->step_frames
++;
2537 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2538 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2539 unpause_player(mpctx
);
2542 static void pause_loop(struct MPContext
*mpctx
)
2546 // Small hack to display the pause message on the OSD line.
2547 // The pause string is: "\n == PAUSE == \r" so we need to
2548 // take the first and the last char out
2549 if (term_osd
&& !mpctx
->sh_video
) {
2550 char msg
[128] = _("\n ===== PAUSE =====\r");
2551 int mlen
= strlen(msg
);
2553 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2554 update_osd_msg(mpctx
);
2556 mp_tmsg(MSGT_CPLAYER
,MSGL_STATUS
,"\n ===== PAUSE =====\r");
2557 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2560 while ( (cmd
= mp_input_get_cmd(mpctx
->input
, 20, 1, 1)) == NULL
2561 || cmd
->id
== MP_CMD_SET_MOUSE_POS
|| cmd
->pausing
== 4) {
2563 cmd
= mp_input_get_cmd(mpctx
->input
, 0,1,0);
2564 run_command(mpctx
, cmd
);
2568 if (mpctx
->sh_video
&& mpctx
->video_out
)
2569 vo_check_events(mpctx
->video_out
);
2572 vf_menu_pause_update(vf_menu
);
2575 update_osd_msg(mpctx
);
2576 int hack
= vo_osd_changed(0);
2577 vo_osd_changed(hack
);
2584 // Find the right mute status and record position for new file position
2585 static void edl_seek_reset(MPContext
*mpctx
)
2587 mpctx
->edl_muted
= 0;
2588 next_edl_record
= edl_records
;
2590 while (next_edl_record
) {
2591 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2594 if (next_edl_record
->action
== EDL_MUTE
)
2595 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2596 next_edl_record
= next_edl_record
->next
;
2598 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2599 mixer_mute(&mpctx
->mixer
);
2603 // Execute EDL command for the current position if one exists
2604 static void edl_update(MPContext
*mpctx
)
2606 if (!next_edl_record
)
2609 if (!mpctx
->sh_video
) {
2610 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Cannot use EDL without video, disabling.\n");
2611 free_edl(edl_records
);
2612 next_edl_record
= NULL
;
2617 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2618 if (next_edl_record
->action
== EDL_SKIP
) {
2619 mpctx
->osd_function
= OSD_FFW
;
2620 mpctx
->abs_seek_pos
= 0;
2621 mpctx
->rel_seek_secs
= next_edl_record
->length_sec
;
2622 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2623 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2624 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2626 else if (next_edl_record
->action
== EDL_MUTE
) {
2627 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2628 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2629 mixer_mute(&mpctx
->mixer
);
2630 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2631 next_edl_record
->start_sec
);
2633 next_edl_record
= next_edl_record
->next
;
2637 static void reinit_decoders(struct MPContext
*mpctx
)
2639 reinit_video_chain(mpctx
);
2640 reinit_audio_chain(mpctx
);
2641 mp_property_do("sub", M_PROPERTY_SET
, &mpctx
->global_sub_pos
, mpctx
);
2644 static bool timeline_set_part(struct MPContext
*mpctx
, int i
)
2646 struct timeline_part
*p
= mpctx
->timeline
+ mpctx
->timeline_part
;
2647 struct timeline_part
*n
= mpctx
->timeline
+ i
;
2648 mpctx
->timeline_part
= i
;
2649 mpctx
->video_offset
= n
->start
- n
->source_start
;
2650 if (n
->source
== p
->source
)
2652 uninit_player(mpctx
, INITIALIZED_VCODEC
| (mpctx
->opts
.fixed_vo
&& mpctx
->opts
.video_id
!= -2 ? 0 : INITIALIZED_VO
) | INITIALIZED_AO
| INITIALIZED_ACODEC
);
2653 mpctx
->demuxer
= n
->source
->demuxer
;
2654 mpctx
->d_video
= mpctx
->demuxer
->video
;
2655 mpctx
->d_audio
= mpctx
->demuxer
->audio
;
2656 mpctx
->d_sub
= mpctx
->demuxer
->sub
;
2657 mpctx
->sh_video
= mpctx
->d_video
->sh
;
2658 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
2662 // Given pts, switch playback to the corresponding part.
2663 // Return offset within that part.
2664 static double timeline_set_from_time(struct MPContext
*mpctx
, double pts
,
2669 for (int i
= 0; i
< mpctx
->num_timeline_parts
; i
++) {
2670 struct timeline_part
*p
= mpctx
->timeline
+ i
;
2671 if (pts
< (p
+1)->start
) {
2672 *need_reset
= timeline_set_part(mpctx
, i
);
2673 return pts
- p
->start
+ p
->source_start
;
2680 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute
2681 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length
2682 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2683 static int seek(MPContext
*mpctx
, double amount
, int style
)
2685 current_module
= "seek";
2686 if (mpctx
->stop_play
== AT_END_OF_FILE
)
2687 mpctx
->stop_play
= KEEP_PLAYING
;
2688 if (mpctx
->timeline
&& style
& SEEK_FACTOR
) {
2689 amount
*= mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
2690 style
&= ~SEEK_FACTOR
;
2692 if ((mpctx
->demuxer
->accurate_seek
|| mpctx
->timeline
) && mpctx
->sh_video
2693 && !(style
& (SEEK_ABSOLUTE
| SEEK_FACTOR
))) {
2694 style
|= SEEK_ABSOLUTE
;
2696 style
|= SEEK_FORWARD
;
2698 style
|= SEEK_BACKWARD
;
2699 amount
+= mpctx
->sh_video
->pts
;
2702 /* At least the liba52 decoder wants to read from the input stream
2703 * during initialization, so reinit must be done after the demux_seek()
2704 * call that clears possible stream EOF. */
2705 bool need_reset
= false;
2706 if (mpctx
->timeline
) {
2707 amount
= timeline_set_from_time(mpctx
, amount
, &need_reset
);
2709 mpctx
->stop_play
= AT_END_OF_FILE
;
2710 // Clear audio from current position
2711 if (mpctx
->sh_audio
) {
2712 mpctx
->audio_out
->reset();
2713 mpctx
->sh_audio
->a_buffer_len
= 0;
2714 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2719 int seekresult
= demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
);
2721 reinit_decoders(mpctx
);
2722 if (seekresult
== 0)
2725 if (mpctx
->sh_video
) {
2726 current_module
= "seek_video_reset";
2727 resync_video_stream(mpctx
->sh_video
);
2728 vo_seek_reset(mpctx
->video_out
);
2729 mpctx
->sh_video
->num_buffered_pts
= 0;
2730 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2732 mpctx
->time_frame
= 0;
2733 mpctx
->update_video_immediately
= true;
2734 // Not all demuxers set d_video->pts during seek, so this value
2735 // (which is used by at least vobsub and edl code below) may
2736 // be completely wrong (probably 0).
2737 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
+ mpctx
->video_offset
;
2738 update_subtitles(mpctx
, &mpctx
->opts
, mpctx
->sh_video
,
2739 mpctx
->sh_video
->pts
, mpctx
->video_offset
,
2741 update_teletext(mpctx
->sh_video
, mpctx
->demuxer
, 1);
2744 if (mpctx
->sh_audio
) {
2745 current_module
= "seek_audio_reset";
2746 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2747 mpctx
->sh_audio
->a_buffer_len
= 0;
2748 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2749 if (!mpctx
->sh_video
)
2750 update_subtitles(mpctx
, &mpctx
->opts
, NULL
, mpctx
->sh_audio
->pts
,
2751 mpctx
->video_offset
, mpctx
->d_sub
, 1);
2754 if (vo_vobsub
&& mpctx
->sh_video
) {
2755 current_module
= "seek_vobsub_reset";
2756 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2759 edl_seek_reset(mpctx
);
2761 mpctx
->total_avsync_change
= 0;
2762 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2765 current_module
= NULL
;
2769 int get_current_chapter(struct MPContext
*mpctx
)
2771 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2772 return demuxer_get_current_chapter(mpctx
->demuxer
);
2775 double current_pts
= mpctx
->sh_video
->pts
;
2776 for (i
= 1; i
< mpctx
->num_chapters
; i
++)
2777 if (current_pts
< mpctx
->chapters
[i
].start
)
2782 // currently returns a string allocated with malloc, not talloc
2783 char *chapter_display_name(struct MPContext
*mpctx
, int chapter
)
2785 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2786 return demuxer_chapter_display_name(mpctx
->demuxer
, chapter
);
2787 return strdup(mpctx
->chapters
[chapter
].name
);
2790 int seek_chapter(struct MPContext
*mpctx
, int chapter
, double *seek_pts
,
2791 char **chapter_name
)
2793 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2794 return demuxer_seek_chapter(mpctx
->demuxer
, chapter
, seek_pts
,
2796 if (chapter
>= mpctx
->num_chapters
)
2800 *seek_pts
= mpctx
->chapters
[chapter
].start
;
2802 *chapter_name
= talloc_strdup(NULL
, mpctx
->chapters
[chapter
].name
);
2806 static int find_ordered_chapter_sources(struct MPContext
*mpctx
,
2807 struct content_source
*sources
,
2809 unsigned char uid_map
[][16])
2811 int num_filenames
= 0;
2812 char **filenames
= NULL
;
2813 if (num_sources
> 1) {
2814 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "This file references data from "
2815 "other sources.\n");
2816 if (mpctx
->stream
->type
!= STREAMTYPE_FILE
) {
2817 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Playback source is not a "
2818 "normal disk file. Will not search for related files.\n");
2820 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Will scan other files in the "
2821 "same directory to find referenced sources.\n");
2822 filenames
= find_files(mpctx
->demuxer
->filename
, ".mkv",
2827 int num_left
= num_sources
- 1;
2828 for (int i
= 0; i
< num_filenames
&& num_left
> 0; i
++) {
2829 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Checking file %s\n",
2830 filename_recode(filenames
[i
]));
2832 struct stream
*s
= open_stream(filenames
[i
], &mpctx
->opts
, &format
);
2835 struct demuxer
*d
= demux_open(&mpctx
->opts
, s
, DEMUXER_TYPE_MATROSKA
,
2836 mpctx
->opts
.audio_id
,
2837 mpctx
->opts
.video_id
,
2838 mpctx
->opts
.sub_id
, filenames
[i
]);
2843 if (d
->file_format
== DEMUXER_TYPE_MATROSKA
) {
2844 for (int i
= 1; i
< num_sources
; i
++) {
2845 if (sources
[i
].demuxer
)
2847 if (!memcmp(uid_map
[i
], d
->matroska_data
.segment_uid
, 16)) {
2848 mp_msg(MSGT_CPLAYER
, MSGL_INFO
,"Match for source %d: %s\n",
2849 i
, filename_recode(d
->filename
));
2850 sources
[i
].stream
= s
;
2851 sources
[i
].demuxer
= d
;
2863 talloc_free(filenames
);
2865 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Failed to find ordered chapter part!\n"
2866 "There will be parts MISSING from the video!\n");
2867 for (int i
= 1, j
= 1; i
< num_sources
; i
++)
2868 if (sources
[i
].demuxer
) {
2869 sources
[j
] = sources
[i
];
2870 memcpy(uid_map
[j
], uid_map
[i
], 16);
2874 return num_sources
- num_left
;
2877 static void build_ordered_chapter_timeline(struct MPContext
*mpctx
)
2879 if (!mpctx
->opts
.ordered_chapters
) {
2880 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, but "
2881 "you have disabled support for them. Ignoring.\n");
2885 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, will build "
2886 "edit timeline.\n");
2888 struct demuxer
*demuxer
= mpctx
->demuxer
;
2889 struct matroska_data
*m
= &demuxer
->matroska_data
;
2891 // +1 because sources/uid_map[0] is original file even if all chapters
2892 // actually use other sources and need separate entries
2893 struct content_source
*sources
= talloc_array_ptrtype(NULL
, sources
,
2894 m
->num_ordered_chapters
+1);
2895 sources
[0].stream
= mpctx
->stream
;
2896 sources
[0].demuxer
= mpctx
->demuxer
;
2897 unsigned char uid_map
[m
->num_ordered_chapters
+1][16];
2898 int num_sources
= 1;
2899 memcpy(uid_map
[0], m
->segment_uid
, 16);
2901 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
2902 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
2903 if (!c
->has_segment_uid
)
2904 memcpy(c
->segment_uid
, m
->segment_uid
, 16);
2906 for (int j
= 0; j
< num_sources
; j
++)
2907 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
2909 memcpy(uid_map
[num_sources
], c
->segment_uid
, 16);
2910 sources
[num_sources
] = (struct content_source
){};
2916 num_sources
= find_ordered_chapter_sources(mpctx
, sources
, num_sources
,
2920 // +1 for terminating chapter with start time marking end of last real one
2921 struct timeline_part
*timeline
= talloc_array_ptrtype(NULL
, timeline
,
2922 m
->num_ordered_chapters
+ 1);
2923 struct chapter
*chapters
= talloc_array_ptrtype(NULL
, chapters
,
2924 m
->num_ordered_chapters
);
2925 uint64_t starttime
= 0;
2926 uint64_t missing_time
= 0;
2928 int num_chapters
= 0;
2929 uint64_t prev_part_offset
;
2930 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
2931 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
2934 for (j
= 0; j
< num_sources
; j
++) {
2935 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
2938 missing_time
+= c
->end
- c
->start
;
2941 chapters
[num_chapters
].start
= starttime
/ 1000.;
2942 chapters
[num_chapters
].name
= talloc_strdup(chapters
, c
->name
);
2943 /* Only add a separate part if the time or file actually changes.
2944 * Matroska files have chapter divisions that are redundant from
2945 * timeline point of view because the same chapter structure is used
2946 * both to specify the timeline and for normal chapter information.
2947 * Removing a missing inserted external chapter can also cause this. */
2948 if (part_count
== 0 || c
->start
!= starttime
+ prev_part_offset
2949 || sources
+ j
!= timeline
[part_count
- 1].source
) {
2950 timeline
[part_count
].source
= sources
+ j
;
2951 timeline
[part_count
].start
= chapters
[num_chapters
].start
;
2952 timeline
[part_count
].source_start
= c
->start
/ 1000.;
2953 prev_part_offset
= c
->start
- starttime
;
2956 starttime
+= c
->end
- c
->start
;
2959 timeline
[part_count
].start
= starttime
/ 1000.;
2962 // None of the parts come from the file itself???
2963 talloc_free(sources
);
2964 talloc_free(timeline
);
2965 talloc_free(chapters
);
2969 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline contains %d parts from %d "
2970 "sources. Total length %.3f seconds.\n", part_count
, num_sources
,
2971 timeline
[part_count
].start
);
2973 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "There are %.3f seconds missing "
2974 "from the timeline!\n", missing_time
/ 1000.);
2975 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Source files:\n");
2976 for (int i
= 0; i
< num_sources
; i
++)
2977 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%d: %s\n", i
,
2978 filename_recode(sources
[i
].demuxer
->filename
));
2979 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline parts: (number, start, "
2980 "source_start, source):\n");
2981 for (int i
= 0; i
< part_count
; i
++) {
2982 struct timeline_part
*p
= timeline
+ i
;
2983 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%3d %9.3f %9.3f %3td\n", i
, p
->start
,
2984 p
->source_start
, p
->source
- sources
);
2986 mp_msg(MSGT_CPLAYER
, MSGL_V
, "END %9.3f\n", timeline
[part_count
].start
);
2987 mpctx
->sources
= sources
;
2988 mpctx
->num_sources
= num_sources
;
2989 mpctx
->timeline
= timeline
;
2990 mpctx
->num_timeline_parts
= part_count
;
2991 mpctx
->num_chapters
= num_chapters
;
2992 mpctx
->chapters
= chapters
;
2994 mpctx
->timeline_part
= 0;
2995 mpctx
->demuxer
= timeline
[0].source
->demuxer
;
2999 static int read_keys(void *ctx
, int fd
)
3002 return mplayer_get_key(ctx
, 0);
3006 /* This preprocessor directive is a hack to generate a mplayer-nomain.o object
3007 * file for some tools to link against. */
3008 #ifndef DISABLE_MAIN
3009 int main(int argc
,char* argv
[]){
3016 /* Flag indicating whether MPlayer should exit without playing anything. */
3019 //float a_frame=0; // Audio
3023 struct MPContext
*mpctx
= &(struct MPContext
){
3024 .osd_function
= OSD_PLAY
,
3025 .begin_skip
= MP_NOPTS_VALUE
,
3026 .play_tree_step
= 1,
3027 .global_sub_pos
= -1,
3028 .set_of_sub_pos
= -1,
3029 .file_format
= DEMUXER_TYPE_UNKNOWN
,
3034 srand(GetTimerMS());
3037 set_av_log_callback();
3040 mpctx
->x11_state
= vo_x11_init_state();
3042 struct MPOpts
*opts
= &mpctx
->opts
;
3043 set_default_mplayer_options(opts
);
3044 // Create the config context and register the options
3045 mpctx
->mconfig
= m_config_new(opts
, cfg_include
);
3046 m_config_register_options(mpctx
->mconfig
,mplayer_opts
);
3047 mp_input_register_options(mpctx
->mconfig
);
3049 // Preparse the command line
3050 m_config_preparse_command_line(mpctx
->mconfig
,argc
,argv
);
3052 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
3057 stream_tv_defaults
.immediate
= 1;
3060 parse_cfgfiles(mpctx
, mpctx
->mconfig
);
3062 mpctx
->playtree
= m_config_parse_mp_command_line(mpctx
->mconfig
, argc
, argv
);
3063 if(mpctx
->playtree
== NULL
)
3066 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
3067 if(mpctx
->playtree
) {
3068 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mpctx
->mconfig
);
3069 if(mpctx
->playtree_iter
) {
3070 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3071 play_tree_iter_free(mpctx
->playtree_iter
);
3072 mpctx
->playtree_iter
= NULL
;
3074 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
3078 mpctx
->key_fifo
= mp_fifo_create(opts
);
3080 print_version("MPlayer");
3082 #if defined(__MINGW32__) || defined(__CYGWIN__)
3084 HMODULE kernel32
= GetModuleHandle("Kernel32.dll");
3085 BOOL
WINAPI (*setDEP
)(DWORD
) = NULL
;
3087 setDEP
= GetProcAddress(kernel32
, "SetProcessDEPPolicy");
3088 if (setDEP
) setDEP(3);
3090 // stop Windows from showing all kinds of annoying error dialogs
3091 SetErrorMode(0x8003);
3092 // request 1ms timer resolution
3096 #ifdef CONFIG_PRIORITY
3100 if(opts
->video_driver_list
&& strcmp(opts
->video_driver_list
[0],"help")==0){
3105 if(opts
->audio_driver_list
&& strcmp(opts
->audio_driver_list
[0],"help")==0){
3110 /* Check codecs.conf. */
3111 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
3112 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
3113 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
3114 if(!parse_codec_cfg(NULL
)){
3115 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
3117 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"Using built-in default codecs.conf.\n");
3120 free( mem_ptr
); // release the buffer created by get_path()
3124 if(video_codec_list
){
3126 video_codec
=video_codec_list
[0];
3127 for(i
=0;video_codec_list
[i
];i
++)
3128 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
3131 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
3132 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available audio codecs:\n");
3133 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
3135 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3138 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
3139 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available video codecs:\n");
3140 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
3142 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3145 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
3147 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3150 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3152 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3155 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3161 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3163 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3167 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3168 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3169 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3171 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3174 if(list_properties
) {
3175 property_print_help();
3180 exit_player(mpctx
, EXIT_NONE
);
3182 if(!mpctx
->filename
&& !player_idle_mode
){
3183 // no file/vcd/dvd -> show HELP:
3184 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s", mp_gtext(help_text
));
3185 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
3188 /* Display what configure line was used */
3189 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
3191 // Many users forget to include command line in bugreports...
3192 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3193 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "CommandLine:");
3194 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3195 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3198 //------ load global data first ------
3200 mpctx
->osd
= osd_create();
3203 #ifdef CONFIG_FREETYPE
3206 #ifdef CONFIG_FONTCONFIG
3207 if(font_fontconfig
<= 0)
3210 #ifdef CONFIG_BITMAP_FONT
3212 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3213 if(!vo_font
) mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load bitmap font: %s\n",
3214 filename_recode(font_name
));
3217 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3218 free(mem_ptr
); // release the buffer created by get_path()
3220 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3223 mpctx
->osd
->sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
3225 mpctx
->osd
->sub_font
= vo_font
;
3227 #ifdef CONFIG_FONTCONFIG
3232 ass_library
= ass_init();
3238 // seteuid(0); /* Can't hurt to try to get root here */
3239 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3240 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Failed to open %s: %s (it should be readable by the user.)\n",
3241 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3243 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3245 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3246 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp
, strerror(errno
));
3247 mp_tmsg(MSGT_CPLAYER
, MSGL_HINT
, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp
);
3250 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3251 /* variable only by the root */
3252 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno
));
3256 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Using Linux hardware RTC timing (%ldHz).\n", irqp
);
3260 #endif /* HAVE_RTC */
3261 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3262 softsleep
?"software":timer_name
);
3265 load_termcap(NULL
); // load key-codes
3268 // ========== Init keyboard FIFO (connection to libvo) ============
3270 // Init input system
3271 current_module
= "init_input";
3272 mpctx
->input
= mp_input_init(&opts
->input
);
3273 mp_input_add_key_fd(mpctx
->input
, -1,0,mplayer_get_key
,NULL
, mpctx
->key_fifo
);
3275 mp_input_add_cmd_fd(mpctx
->input
, 0,USE_SELECT
,MP_INPUT_SLAVE_CMD_FUNC
,NULL
);
3276 else if(!noconsolecontrols
)
3277 mp_input_add_key_fd(mpctx
->input
, 0, 1, read_keys
, NULL
, mpctx
->key_fifo
);
3278 // Set the libstream interrupt callback
3279 stream_set_interrupt_callback(mp_input_check_interrupt
, mpctx
->input
);
3283 if(menu_cfg
&& menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3284 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3286 menu_cfg
= get_path("menu.conf");
3287 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3288 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3290 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
,
3291 MPLAYER_CONFDIR
"/menu.conf"))
3292 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", MPLAYER_CONFDIR
"/menu.conf");
3294 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Menu init failed.\n");
3302 current_module
= NULL
;
3306 signal(SIGCHLD
,child_sighandler
);
3309 #ifdef CONFIG_CRASH_DEBUG
3310 prog_path
= argv
[0];
3312 //========= Catch terminate signals: ================
3313 // terminate requests:
3314 signal(SIGTERM
,exit_sighandler
); // kill
3315 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3317 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3319 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3320 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3321 #ifdef CONFIG_SIGHANDLER
3323 signal(SIGBUS
,exit_sighandler
); // bus error
3324 signal(SIGSEGV
,exit_sighandler
); // segfault
3325 signal(SIGILL
,exit_sighandler
); // illegal instruction
3326 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3327 signal(SIGABRT
,exit_sighandler
); // abort()
3328 #ifdef CONFIG_CRASH_DEBUG
3330 signal(SIGTRAP
,exit_sighandler
);
3334 // ******************* Now, let's see the per-file stuff ********************
3338 // init global sub numbers
3339 mpctx
->global_sub_size
= 0;
3340 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) mpctx
->global_sub_indices
[i
] = -1; }
3342 if (mpctx
->filename
) {
3343 load_per_protocol_config (mpctx
->mconfig
, mpctx
->filename
);
3344 load_per_extension_config (mpctx
->mconfig
, mpctx
->filename
);
3345 load_per_file_config (mpctx
->mconfig
, mpctx
->filename
);
3348 if (opts
->video_driver_list
)
3349 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_VO
, opts
->video_driver_list
[0]);
3350 if (opts
->audio_driver_list
)
3351 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_AO
, opts
->audio_driver_list
[0]);
3353 // We must enable getch2 here to be able to interrupt network connection
3355 if(!noconsolecontrols
&& !slave_mode
){
3356 if(mpctx
->initialized_flags
&INITIALIZED_GETCH2
)
3357 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"WARNING: getch2_init called twice!\n");
3359 getch2_enable(); // prepare stdin for hotkeys...
3360 mpctx
->initialized_flags
|=INITIALIZED_GETCH2
;
3361 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3364 // =================== GUI idle loop (STOP state) ===========================
3365 while (player_idle_mode
&& !mpctx
->filename
) {
3366 play_tree_t
* entry
= NULL
;
3368 while (!(cmd
= mp_input_get_cmd(mpctx
->input
, 0,1,0))) { // wait for command
3369 if (mpctx
->video_out
)
3370 vo_check_events(mpctx
->video_out
);
3374 case MP_CMD_LOADFILE
:
3375 // prepare a tree entry with the new filename
3376 entry
= play_tree_new();
3377 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3378 // The entry is added to the main playtree after the switch().
3380 case MP_CMD_LOADLIST
:
3381 entry
= parse_playlist_file(mpctx
->mconfig
, cmd
->args
[0].v
.s
);
3384 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3386 case MP_CMD_GET_PROPERTY
:
3387 case MP_CMD_SET_PROPERTY
:
3388 case MP_CMD_STEP_PROPERTY
:
3389 run_command(mpctx
, cmd
);
3395 if (entry
) { // user entered a command that gave a valid entry
3396 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
3397 play_tree_free_list(mpctx
->playtree
->child
, 1);
3398 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
3400 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
3402 play_tree_set_child(mpctx
->playtree
, entry
);
3404 /* Make iterator start at the top the of tree. */
3405 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mpctx
->mconfig
);
3406 if (!mpctx
->playtree_iter
) continue;
3408 // find the first real item in the tree
3409 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3411 play_tree_iter_free(mpctx
->playtree_iter
);
3412 mpctx
->playtree_iter
= NULL
;
3413 continue; // wait for next command
3415 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
3418 //---------------------------------------------------------------------------
3420 if (mpctx
->filename
) {
3421 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nPlaying %s.\n",
3422 filename_recode(mpctx
->filename
));
3423 if(use_filename_title
&& vo_wintitle
== NULL
)
3424 vo_wintitle
= strdup(mp_basename2(mpctx
->filename
));
3428 if (edl_records
) free_edl(edl_records
);
3429 next_edl_record
= edl_records
= edl_parse_file();
3431 if (edl_output_filename
) {
3432 if (edl_fd
) fclose(edl_fd
);
3433 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3435 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Can't open EDL file [%s] for writing.\n",
3436 filename_recode(edl_output_filename
));
3440 //==================== Open VOB-Sub ============================
3442 current_module
="vobsub";
3444 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3446 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load subtitles: %s\n",
3447 filename_recode(vobsub_name
));
3448 } else if (sub_auto
&& mpctx
->filename
){
3449 /* try to autodetect vobsub from movie filename ::atmos */
3450 char *buf
= strdup(mpctx
->filename
), *psub
;
3451 char *pdot
= strrchr(buf
, '.');
3452 char *pslash
= strrchr(buf
, '/');
3453 #if defined(__MINGW32__) || defined(__CYGWIN__)
3454 if (!pslash
) pslash
= strrchr(buf
, '\\');
3456 if (pdot
&& (!pslash
|| pdot
> pslash
))
3458 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3459 /* try from ~/.mplayer/sub */
3460 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3463 bname
= strrchr(buf
,'/');
3464 #if defined(__MINGW32__) || defined(__CYGWIN__)
3465 if(!bname
) bname
= strrchr(buf
,'\\');
3469 l
= strlen(psub
) + strlen(bname
) + 1;
3470 psub
= realloc(psub
,l
);
3472 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3478 mpctx
->initialized_flags
|=INITIALIZED_VOBSUB
;
3479 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
3480 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
3482 // setup global sub numbering
3483 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] = mpctx
->global_sub_size
; // the global # of the first vobsub.
3484 mpctx
->global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
3487 //============ Open & Sync STREAM --- fork cache2 ====================
3490 mpctx
->demuxer
=NULL
;
3491 if (mpctx
->d_audio
) {
3492 //free_demuxer_stream(mpctx->d_audio);
3493 mpctx
->d_audio
=NULL
;
3495 if (mpctx
->d_video
) {
3496 //free_demuxer_stream(d_video);
3497 mpctx
->d_video
=NULL
;
3499 mpctx
->sh_audio
=NULL
;
3500 mpctx
->sh_video
=NULL
;
3502 current_module
="open_stream";
3503 mpctx
->stream
= open_stream(mpctx
->filename
, opts
, &mpctx
->file_format
);
3504 if(!mpctx
->stream
) { // error...
3505 mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
);
3506 goto goto_next_file
;
3508 mpctx
->initialized_flags
|=INITIALIZED_STREAM
;
3510 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
3511 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "\nThis looks like a playlist, but "
3512 "playlist support will not be used automatically.\n"
3513 "MPlayer's playlist code is unsafe and should only be used with "
3514 "trusted sources.\nPlayback will probably fail.\n\n");
3518 current_module
="handle_playlist";
3519 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
3520 filename_recode(mpctx
->filename
));
3521 entry
= parse_playtree(mpctx
->stream
, mpctx
->mconfig
, 0);
3522 mpctx
->eof
=playtree_add_playlist(mpctx
, entry
);
3523 goto goto_next_file
;
3526 mpctx
->stream
->start_pos
+=seek_to_byte
;
3528 if(stream_dump_type
==5){
3529 unsigned char buf
[4096];
3532 current_module
="dumpstream";
3533 stream_reset(mpctx
->stream
);
3534 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
3535 f
=fopen(stream_dump_name
,"wb");
3537 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3538 exit_player(mpctx
, EXIT_ERROR
);
3540 if (dvd_chapter
> 1) {
3541 int chapter
= dvd_chapter
- 1;
3542 stream_control(mpctx
->stream
, STREAM_CTRL_SEEK_TO_CHAPTER
, &chapter
);
3544 while(!mpctx
->stream
->eof
&& !async_quit_request
){
3545 len
=stream_read(mpctx
->stream
,buf
,4096);
3547 if(fwrite(buf
,len
,1,f
) != 1) {
3548 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",stream_dump_name
);
3549 exit_player(mpctx
, EXIT_ERROR
);
3552 if(dvd_last_chapter
> 0) {
3554 if (stream_control(mpctx
->stream
, STREAM_CTRL_GET_CURRENT_CHAPTER
,
3555 &chapter
) == STREAM_OK
&& chapter
+ 1 > dvd_last_chapter
)
3560 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",stream_dump_name
);
3561 exit_player(mpctx
, EXIT_ERROR
);
3563 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3564 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3567 #ifdef CONFIG_DVDREAD
3568 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
3569 current_module
="dvd lang->id";
3570 if(opts
->audio_id
==-1) opts
->audio_id
=dvd_aid_from_lang(mpctx
->stream
,audio_lang
);
3571 if(dvdsub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=dvd_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3572 // setup global sub numbering
3573 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3574 mpctx
->global_sub_size
+= dvd_number_of_subs(mpctx
->stream
);
3575 current_module
=NULL
;
3579 #ifdef CONFIG_DVDNAV
3580 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
3581 current_module
="dvdnav lang->id";
3582 if(opts
->audio_id
==-1) opts
->audio_id
=mp_dvdnav_aid_from_lang(mpctx
->stream
,audio_lang
);
3583 dvdsub_lang_id
= -3;
3584 if(dvdsub_lang
&& opts
->sub_id
==-1)
3585 dvdsub_lang_id
= opts
->sub_id
= mp_dvdnav_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3586 // setup global sub numbering
3587 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3588 mpctx
->global_sub_size
+= mp_dvdnav_number_of_subs(mpctx
->stream
);
3589 current_module
=NULL
;
3593 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3595 if(stream_cache_size
>0){
3597 current_module
="enable_cache";
3598 res
= stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
3599 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3600 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0));
3602 if((mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
))) goto goto_next_file
;
3605 //============ Open DEMUXERS --- DETECT file type =======================
3606 current_module
="demux_open";
3608 mpctx
->demuxer
=demux_open(opts
, mpctx
->stream
,mpctx
->file_format
,opts
->audio_id
,opts
->video_id
,opts
->sub_id
,mpctx
->filename
);
3610 // HACK to get MOV Reference Files working
3612 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3614 unsigned char* playlist_entry
;
3615 play_tree_t
*list
= NULL
, *entry
= NULL
;
3617 current_module
="handle_demux_playlist";
3618 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
3622 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
3623 filename_recode(playlist_entry
));
3625 bname
=mp_basename(playlist_entry
);
3626 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3629 if (!strcmp(playlist_entry
, mpctx
->filename
)) // ignoring self-reference
3632 entry
= play_tree_new();
3634 if (mpctx
->filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3636 temp
=malloc((strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))+strlen(playlist_entry
)+1));
3639 strncpy(temp
, mpctx
->filename
, strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
)));
3640 temp
[strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))]='\0';
3641 strcat(temp
, playlist_entry
);
3642 if (!strcmp(temp
, mpctx
->filename
)) {
3646 play_tree_add_file(entry
,temp
);
3647 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3652 play_tree_add_file(entry
,playlist_entry
);
3657 play_tree_append_entry(list
,entry
);
3659 free_demuxer(mpctx
->demuxer
);
3660 mpctx
->demuxer
= NULL
;
3664 entry
= play_tree_new();
3665 play_tree_set_child(entry
,list
);
3666 mpctx
->stop_play
= playtree_add_playlist(mpctx
, entry
);
3667 goto goto_next_file
;
3672 goto goto_next_file
;
3674 if (mpctx
->demuxer
->matroska_data
.ordered_chapters
)
3675 build_ordered_chapter_timeline(mpctx
);
3677 if (!mpctx
->sources
) {
3678 mpctx
->sources
= talloc_ptrtype(NULL
, mpctx
->sources
);
3679 *mpctx
->sources
= (struct content_source
){.stream
= mpctx
->stream
,
3680 .demuxer
= mpctx
->demuxer
};
3681 mpctx
->num_sources
= 1;
3686 if (seek_chapter(mpctx
, dvd_chapter
-1, &pts
, NULL
) >= 0 && pts
> -1.0)
3687 seek(mpctx
, pts
, SEEK_ABSOLUTE
);
3690 mpctx
->initialized_flags
|=INITIALIZED_DEMUXER
;
3692 if (mpctx
->stream
->type
!= STREAMTYPE_DVD
&& mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
) {
3695 // setup global sub numbering
3696 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3697 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
3698 if (mpctx
->demuxer
->s_streams
[i
])
3699 maxid
= FFMAX(maxid
, mpctx
->demuxer
->s_streams
[i
]->sid
);
3700 mpctx
->global_sub_size
+= maxid
+ 1;
3702 // Make opts->sub_id always selectable if set.
3703 if (mpctx
->global_sub_size
<= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
)
3704 mpctx
->global_sub_size
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
+ 1;
3707 if (opts
->ass_enabled
&& ass_library
) {
3708 for (int j
= 0; j
< mpctx
->num_sources
; j
++) {
3709 struct demuxer
*d
= mpctx
->sources
[j
].demuxer
;
3710 for (int i
= 0; i
< d
->num_attachments
; i
++) {
3711 struct demux_attachment
*att
= d
->attachments
+ i
;
3712 if (use_embedded_fonts
3713 && att
->name
&& att
->type
&& att
->data
&& att
->data_size
3714 && (strcmp(att
->type
, "application/x-truetype-font") == 0
3715 || strcmp(att
->type
, "application/x-font") == 0))
3716 ass_add_font(ass_library
, att
->name
, att
->data
, att
->data_size
);
3722 current_module
="demux_open2";
3724 //file_format=demuxer->file_format;
3726 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3727 mpctx
->d_video
=mpctx
->demuxer
->video
;
3728 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3732 mp_property_do("switch_program", M_PROPERTY_SET
, &tmp
, mpctx
);
3734 // select audio stream
3735 select_audio(mpctx
->demuxer
, opts
->audio_id
, audio_lang
);
3738 if((stream_dump_type
)&&(stream_dump_type
<4)){
3740 demux_stream_t
*ds
=NULL
;
3741 current_module
="dump";
3742 // select stream to dump
3743 switch(stream_dump_type
){
3744 case 1: ds
=mpctx
->d_audio
;break;
3745 case 2: ds
=mpctx
->d_video
;break;
3746 case 3: ds
=mpctx
->d_sub
;break;
3749 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"dump: FATAL: Selected stream missing!\n");
3750 exit_player(mpctx
, EXIT_ERROR
);
3752 // disable other streams:
3753 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3754 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3755 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3757 f
=fopen(stream_dump_name
,"wb");
3759 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3760 exit_player(mpctx
, EXIT_ERROR
);
3763 unsigned char* start
;
3764 int in_size
=ds_get_packet(ds
,&start
);
3765 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3766 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3767 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3768 if(dvd_last_chapter
>0) {
3769 int cur_chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
3770 if(cur_chapter
!=-1 && cur_chapter
+1>dvd_last_chapter
)
3775 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3776 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3779 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3780 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3782 if(mpctx
->sh_video
){
3784 current_module
="video_read_properties";
3785 if(!video_read_properties(mpctx
->sh_video
)) {
3786 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Video: Cannot read properties.\n");
3787 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3789 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n",
3790 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3791 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3794 /* need to set fps here for output encoders to pick it up in their init */
3796 mpctx
->sh_video
->fps
=force_fps
;
3797 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3799 vo_fps
= mpctx
->sh_video
->fps
;
3801 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3802 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"FPS not specified in the header or invalid, use the -fps option.\n");
3803 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3809 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3810 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "No stream found.\n");
3812 if(mpctx
->stream
->type
== STREAMTYPE_DVB
)
3815 int v
= mpctx
->last_dvb_step
;
3817 dir
= DVB_CHANNEL_HIGHER
;
3819 dir
= DVB_CHANNEL_LOWER
;
3821 if(dvb_step_channel(mpctx
->stream
, dir
)) {
3822 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3823 mpctx
->dvbin_reopen
= 1;
3827 goto goto_next_file
; // exit_player(_("Fatal error"));
3830 /* display clip info */
3831 demux_info_print(mpctx
->demuxer
);
3833 //================== Read SUBTITLES (DVD & TEXT) ==========================
3834 if(vo_spudec
==NULL
&& mpctx
->sh_video
&&
3835 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
)){
3836 init_vo_spudec(mpctx
);
3839 // after reading video params we should load subtitles because
3840 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3842 current_module
="read_subtitles_file";
3843 double sub_fps
= mpctx
->sh_video
? mpctx
->sh_video
->fps
: 25;
3845 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3846 add_subtitles(mpctx
, sub_name
[i
], sub_fps
, 0);
3848 if(sub_auto
) { // auto load sub file ...
3849 char *psub
= get_path( "sub/" );
3850 char **tmp
= sub_filenames((psub
? psub
: ""), mpctx
->filename
);
3852 free(psub
); // release the buffer created by get_path() above
3854 add_subtitles(mpctx
, tmp
[i
], sub_fps
, 1);
3859 if (mpctx
->set_of_sub_size
> 0) {
3860 // setup global sub numbering
3861 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = mpctx
->global_sub_size
; // the global # of the first sub.
3862 mpctx
->global_sub_size
+= mpctx
->set_of_sub_size
;
3866 if (mpctx
->global_sub_size
) {
3867 select_subtitle(mpctx
);
3869 switch (stream_dump_type
) {
3870 case 3: list_sub_file(subdata
); break;
3871 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
3872 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
3873 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
3874 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
3875 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
3879 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
3880 filename_recode(mpctx
->filename
));
3881 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
3882 if (mpctx
->sh_video
) {
3883 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3884 if (mpctx
->sh_video
->format
>= 0x20202020)
3885 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
3887 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
3888 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
3889 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
3890 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
3891 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
3892 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
3894 if (mpctx
->sh_audio
) {
3895 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3896 if (mpctx
->sh_audio
->format
>= 0x20202020)
3897 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
3899 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
3900 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
3901 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
3902 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
3904 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2f\n", mpctx
->timeline
?
3905 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
:
3906 demuxer_get_time_length(mpctx
->demuxer
));
3907 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_SEEKABLE=%d\n",
3908 mpctx
->stream
->seek
&& (!mpctx
->demuxer
|| mpctx
->demuxer
->seekable
));
3909 if (mpctx
->demuxer
) {
3910 if (mpctx
->demuxer
->num_chapters
== 0)
3911 stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_NUM_CHAPTERS
, &mpctx
->demuxer
->num_chapters
);
3912 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_CHAPTERS=%d\n", mpctx
->demuxer
->num_chapters
);
3915 if(!mpctx
->sh_video
) goto main
; // audio-only
3917 if(!reinit_video_chain(mpctx
)) {
3918 if(!mpctx
->sh_video
){
3919 if(!mpctx
->sh_audio
) goto goto_next_file
;
3920 goto main
; // exit_player(_("Fatal error"));
3924 if(mpctx
->sh_video
->output_flags
& 0x08 && vo_spudec
)
3925 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
3927 #ifdef CONFIG_FREETYPE
3928 force_load_font
= 1;
3931 //================== MAIN: ==========================
3933 current_module
="main";
3936 char* msg
= property_expand_string(mpctx
, playing_msg
);
3937 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3942 // Disable the term OSD in verbose mode
3943 if(verbose
) term_osd
= 0;
3946 //int frame_corr_num=0; //
3947 //float v_frame=0; // Video
3948 //float num_frames=0; // number of frames played
3950 int frame_time_remaining
=0; // flag
3953 // Make sure old OSD does not stay around,
3954 // e.g. with -fixed-vo and same-resolution files
3956 update_osd_msg(mpctx
);
3958 //================ SETUP AUDIO ==========================
3960 if(mpctx
->sh_audio
){
3961 reinit_audio_chain(mpctx
);
3962 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
3963 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
3966 current_module
="av_init";
3968 if(mpctx
->sh_video
){
3969 mpctx
->sh_video
->timer
=0;
3971 audio_delay
+= mpctx
->sh_video
->stream_delay
;
3973 if(mpctx
->sh_audio
){
3974 if (start_volume
>= 0)
3975 mixer_setvolume(&mpctx
->mixer
, start_volume
, start_volume
);
3977 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
3978 mpctx
->delay
=-audio_delay
;
3981 if(!mpctx
->sh_audio
){
3982 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Audio: no sound\n");
3983 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
3984 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
3985 //mpctx->d_audio->id=-2; // do not read audio chunks
3986 //uninit_player(mpctx, INITIALIZED_AO); // close device
3988 if(!mpctx
->sh_video
){
3989 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Video: no video\n");
3990 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
3991 ds_free_packs(mpctx
->d_video
);
3992 mpctx
->d_video
->id
=-2;
3993 //if(!fixed_vo) uninit_player(mpctx, INITIALIZED_VO);
3996 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
3997 goto goto_next_file
;
3999 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4000 if(force_fps
&& mpctx
->sh_video
){
4001 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
4002 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
4003 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"FPS forced to be %5.3f (ftime: %5.3f).\n",mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
4006 mp_input_set_section(mpctx
->input
, NULL
);
4007 //TODO: add desired (stream-based) sections here
4008 if (mpctx
->stream
->type
==STREAMTYPE_TV
) mp_input_set_section(mpctx
->input
, "tv");
4009 if (mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) mp_input_set_section(mpctx
->input
, "dvdnav");
4011 //==================== START PLAYING =======================
4013 if(opts
->loop_times
>1) opts
->loop_times
--; else
4014 if(opts
->loop_times
==1) opts
->loop_times
= -1;
4016 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Starting playback...\n");
4018 total_time_usage_start
=GetTimer();
4019 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4020 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
4021 play_n_frames
=play_n_frames_mf
;
4023 if(play_n_frames
==0){
4024 mpctx
->stop_play
=PT_NEXT_ENTRY
; goto goto_next_file
;
4027 // If there's a timeline force an absolute seek to initialize state
4028 if (seek_to_sec
|| mpctx
->timeline
) {
4029 seek(mpctx
, seek_to_sec
, SEEK_ABSOLUTE
);
4030 end_at
.pos
+= seek_to_sec
;
4033 if (end_at
.type
== END_AT_SIZE
) {
4034 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Option -endpos in MPlayer does not yet support size units.\n");
4035 end_at
.type
= END_AT_NONE
;
4038 #ifdef CONFIG_DVDNAV
4039 mp_dvdnav_context_free(mpctx
);
4040 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
4041 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
4042 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
4046 get_relative_time(mpctx
); // reset current delta
4047 mpctx
->time_frame
= 0;
4048 mpctx
->drop_message_shown
= 0;
4049 mpctx
->update_video_immediately
= true;
4050 mpctx
->total_avsync_change
= 0;
4051 // Make sure VO knows current pause state
4052 if (mpctx
->sh_video
)
4053 vo_control(mpctx
->video_out
, mpctx
->paused
? VOCTRL_PAUSE
: VOCTRL_RESUME
,
4056 while(!mpctx
->stop_play
){
4057 float aq_sleep_time
=0;
4059 if(dvd_last_chapter
>0) {
4060 int cur_chapter
= get_current_chapter(mpctx
);
4061 if(cur_chapter
!=-1 && cur_chapter
+1>dvd_last_chapter
)
4062 goto goto_next_file
;
4065 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
4066 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
4067 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
4068 reinit_audio_chain(mpctx
);
4071 /*========================== PLAY AUDIO ============================*/
4073 if (mpctx
->sh_audio
&& !mpctx
->paused
)
4074 if (!fill_audio_out_buffers(mpctx
))
4075 // at eof, all audio at least written to ao
4076 if (!mpctx
->sh_video
)
4077 mpctx
->stop_play
= AT_END_OF_FILE
;
4080 if(!mpctx
->sh_video
) {
4081 // handle audio-only case:
4083 // sh_audio can be NULL due to video stream switching
4084 // TODO: handle this better
4085 if (mpctx
->sh_audio
)
4086 a_pos
= playing_audio_pts(mpctx
);
4088 print_status(mpctx
, a_pos
, false);
4090 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
4091 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4092 update_subtitles(mpctx
, &mpctx
->opts
, NULL
, a_pos
, mpctx
->video_offset
,
4094 update_osd_msg(mpctx
);
4098 /*========================== PLAY VIDEO ============================*/
4100 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
4101 vo_fps
=mpctx
->sh_video
->fps
;
4103 blit_frame
= mpctx
->video_out
->frame_loaded
;
4105 double frame_time
= update_video(mpctx
);
4106 blit_frame
= mpctx
->video_out
->frame_loaded
;
4107 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
4108 if (mpctx
->sh_video
->vf_initialized
< 0) {
4109 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "\nFATAL: Could not initialize video filters (-vf) or video output (-vo).\n");
4110 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4111 goto goto_next_file
;
4114 struct sh_video
*sh_video
= mpctx
->sh_video
;
4115 update_subtitles(mpctx
, &mpctx
->opts
, sh_video
, sh_video
->pts
,
4116 mpctx
->video_offset
, mpctx
->d_sub
, 0);
4117 update_teletext(sh_video
, mpctx
->demuxer
, 0);
4118 update_osd_msg(mpctx
);
4119 struct vf_instance
*vf
= mpctx
->sh_video
->vfilter
;
4120 vf
->control(vf
, VFCTRL_DRAW_EOSD
, NULL
);
4121 vf
->control(vf
, VFCTRL_DRAW_OSD
, mpctx
->osd
);
4125 mpctx
->stop_play
= AT_END_OF_FILE
;
4127 if (mpctx
->update_video_immediately
) {
4128 // Show this frame immediately, rest normally
4129 mpctx
->update_video_immediately
= false;
4131 mpctx
->time_frame
+= frame_time
/ opts
->playback_speed
;
4132 adjust_sync(mpctx
, frame_time
);
4136 if (mpctx
->timeline
) {
4137 struct timeline_part
*next
= mpctx
->timeline
+ mpctx
->timeline_part
+ 1;
4138 if (mpctx
->sh_video
->pts
>= next
->start
4139 || mpctx
->stop_play
== AT_END_OF_FILE
4140 && mpctx
->timeline_part
+ 1 < mpctx
->num_timeline_parts
) {
4141 seek(mpctx
, next
->start
, SEEK_ABSOLUTE
);
4146 // ==========================================================================
4148 // current_module="draw_osd";
4149 // if(vo_config_count) mpctx->video_out->draw_osd();
4151 current_module
="vo_check_events";
4152 vo_check_events(mpctx
->video_out
);
4155 if (stop_xscreensaver
) {
4156 current_module
= "stop_xscreensaver";
4157 xscreensaver_heartbeat(mpctx
->x11_state
);
4160 if (heartbeat_cmd
) {
4161 static unsigned last_heartbeat
;
4162 unsigned now
= GetTimerMS();
4163 if (now
- last_heartbeat
> 30000) {
4164 last_heartbeat
= now
;
4165 system(heartbeat_cmd
);
4169 frame_time_remaining
= sleep_until_update(mpctx
, &mpctx
->time_frame
, &aq_sleep_time
);
4171 //====================== FLIP PAGE (VIDEO BLT): =========================
4173 current_module
="flip_page";
4174 if (!frame_time_remaining
&& blit_frame
) {
4175 unsigned int t2
=GetTimer();
4176 unsigned int pts_us
= mpctx
->last_time
+ mpctx
->time_frame
* 1e6
;
4178 double pts2
= mpctx
->video_out
->next_pts2
;
4179 if (pts2
!= MP_NOPTS_VALUE
&& opts
->correct_pts
) {
4180 // expected A/V sync correction is ignored
4181 double diff
= (pts2
- mpctx
->sh_video
->pts
);
4182 diff
/= opts
->playback_speed
;
4183 if (mpctx
->time_frame
< 0)
4184 diff
+= mpctx
->time_frame
;
4189 duration
= diff
* 1e6
;
4191 vo_flip_page(mpctx
->video_out
, pts_us
|1, duration
);
4193 mpctx
->last_vo_flip_duration
= (GetTimer() - t2
) * 0.000001;
4194 vout_time_usage
+= mpctx
->last_vo_flip_duration
;
4195 if (mpctx
->video_out
->driver
->flip_page_timed
) {
4196 // No need to adjust sync based on flip speed
4197 mpctx
->last_vo_flip_duration
= 0;
4198 // For print_status - VO call finishing early is OK for sync
4199 mpctx
->time_frame
-= get_relative_time(mpctx
);
4201 print_status(mpctx
, MP_NOPTS_VALUE
, true);
4204 print_status(mpctx
, MP_NOPTS_VALUE
, false);
4206 //============================ Auto QUALITY ============================
4208 /*Output quality adjustments:*/
4210 current_module
="autoq";
4211 // float total=0.000001f * (GetTimer()-aq_total_time);
4212 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4213 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4216 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4217 if(output_quality
>1 && aq_sleep_time
<0)
4220 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4222 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4223 set_video_quality(mpctx
->sh_video
,output_quality
);
4226 if (!frame_time_remaining
&& blit_frame
) {
4227 if (play_n_frames
>= 0) {
4229 if (play_n_frames
<= 0)
4230 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4232 if (mpctx
->step_frames
> 0) {
4233 mpctx
->step_frames
--;
4234 if (mpctx
->step_frames
== 0)
4235 pause_player(mpctx
);
4240 // FIXME: add size based support for -endpos
4241 if (end_at
.type
== END_AT_TIME
&&
4242 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
4243 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4245 } // end if(mpctx->sh_video)
4247 #ifdef CONFIG_DVDNAV
4248 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
4250 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
4251 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
4252 vo_osd_changed (OSDTYPE_DVDNAV
);
4254 if (mp_dvdnav_stream_has_changed(mpctx
->stream
)) {
4256 if (stream_control (mpctx
->demuxer
->stream
,
4257 STREAM_CTRL_GET_ASPECT_RATIO
, &ar
)
4258 != STREAM_UNSUPPORTED
)
4259 mpctx
->sh_video
->stream_aspect
= ar
;
4264 //================= Keyboard events, SEEKing ====================
4266 current_module
="key_events";
4271 while ((cmd
= mp_input_get_cmd(mpctx
->input
, 0,0,0)) != NULL
) {
4272 run_command(mpctx
, cmd
);
4274 if (mpctx
->stop_play
)
4277 if (!mpctx
->paused
|| mpctx
->stop_play
|| mpctx
->rel_seek_secs
4278 || mpctx
->abs_seek_pos
)
4280 if (mpctx
->sh_video
) {
4281 update_osd_msg(mpctx
);
4282 int hack
= vo_osd_changed(0);
4283 vo_osd_changed(hack
);
4285 if (redraw_osd(mpctx
->sh_video
, mpctx
->osd
) < 0) {
4286 add_step_frame(mpctx
);
4297 if (step_sec
> 0 && !mpctx
->paused
) {
4298 mpctx
->osd_function
=OSD_FFW
;
4299 mpctx
->rel_seek_secs
+=step_sec
;
4305 if(mpctx
->stop_play
==AT_END_OF_FILE
&& opts
->loop_times
>=0) {
4306 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d\n", opts
->loop_times
);
4308 if(opts
->loop_times
>1) opts
->loop_times
--; else
4309 if(opts
->loop_times
==1) opts
->loop_times
=-1;
4310 play_n_frames
=play_n_frames_mf
;
4312 mpctx
->abs_seek_pos
=SEEK_ABSOLUTE
; mpctx
->rel_seek_secs
=seek_to_sec
;
4315 if(mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
){
4316 seek(mpctx
, mpctx
->rel_seek_secs
, mpctx
->abs_seek_pos
);
4318 mpctx
->rel_seek_secs
=0;
4319 mpctx
->abs_seek_pos
=0;
4322 } // while(!mpctx->stop_play)
4324 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->stop_play
);
4327 if(mpctx
->dvbin_reopen
)
4329 mpctx
->stop_play
= 0;
4330 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_STREAM
|INITIALIZED_GETCH2
|(opts
->fixed_vo
?INITIALIZED_VO
:0)));
4331 cache_uninit(mpctx
->stream
);
4332 mpctx
->dvbin_reopen
= 0;
4333 goto goto_enable_cache
;
4338 goto_next_file
: // don't jump here after ao/vo/getch initialization!
4340 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
4343 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
4344 double total_time_usage
;
4345 total_time_usage_start
=GetTimer()-total_time_usage_start
;
4346 total_time_usage
= (float)total_time_usage_start
*0.000001;
4347 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4348 video_time_usage
,vout_time_usage
,audio_time_usage
,
4349 total_time_usage
-tot
,total_time_usage
);
4350 if(total_time_usage
>0.0)
4351 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4352 100.0*video_time_usage
/total_time_usage
,
4353 100.0*vout_time_usage
/total_time_usage
,
4354 100.0*audio_time_usage
/total_time_usage
,
4355 100.0*(total_time_usage
-tot
)/total_time_usage
,
4357 if(total_frame_cnt
&& frame_dropping
)
4358 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4359 total_frame_cnt
-drop_frame_cnt
,
4360 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
4362 100*drop_frame_cnt
/total_frame_cnt
,
4364 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
4367 // time to uninit all, except global stuff:
4368 uninit_player(mpctx
, INITIALIZED_ALL
-(opts
->fixed_vo
?INITIALIZED_VO
:0));
4370 if(mpctx
->set_of_sub_size
> 0) {
4371 current_module
="sub_free";
4372 for(i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
4373 sub_free(mpctx
->set_of_subtitles
[i
]);
4375 if(mpctx
->set_of_ass_tracks
[i
])
4376 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
4379 mpctx
->set_of_sub_size
= 0;
4381 vo_sub_last
= vo_sub
=NULL
;
4386 ass_clear_fonts(ass_library
);
4389 if (!mpctx
->stop_play
) // In case some goto jumped here...
4390 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4392 int playtree_direction
= 1;
4394 if(mpctx
->stop_play
== PT_NEXT_ENTRY
|| mpctx
->stop_play
== PT_PREV_ENTRY
) {
4395 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) != PLAY_TREE_ITER_ENTRY
) {
4396 play_tree_iter_free(mpctx
->playtree_iter
);
4397 mpctx
->playtree_iter
= NULL
;
4399 mpctx
->play_tree_step
= 1;
4400 } else if(mpctx
->stop_play
== PT_UP_NEXT
|| mpctx
->stop_play
== PT_UP_PREV
) {
4401 int direction
= mpctx
->stop_play
== PT_UP_NEXT
? 1 : -1;
4402 if(mpctx
->playtree_iter
) {
4403 if(play_tree_iter_up_step(mpctx
->playtree_iter
,direction
,0) != PLAY_TREE_ITER_ENTRY
) {
4404 play_tree_iter_free(mpctx
->playtree_iter
);
4405 mpctx
->playtree_iter
= NULL
;
4408 } else if (mpctx
->stop_play
== PT_STOP
) {
4409 play_tree_iter_free(mpctx
->playtree_iter
);
4410 mpctx
->playtree_iter
= NULL
;
4411 } else { // NEXT PREV SRC
4412 playtree_direction
= mpctx
->stop_play
== PT_PREV_SRC
? -1 : 1;
4415 while(mpctx
->playtree_iter
!= NULL
) {
4416 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, playtree_direction
);
4417 if(mpctx
->filename
== NULL
) {
4418 if(play_tree_iter_step(mpctx
->playtree_iter
, playtree_direction
, 0) != PLAY_TREE_ITER_ENTRY
) {
4419 play_tree_iter_free(mpctx
->playtree_iter
);
4420 mpctx
->playtree_iter
= NULL
;
4426 if(mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
4427 if(!mpctx
->playtree_iter
) mpctx
->filename
= NULL
;
4428 mpctx
->stop_play
= 0;
4429 goto play_next_file
;
4433 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
4437 #endif /* DISABLE_MAIN */