2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 /// \ingroup Properties Command2Property OSDMsgStack
28 #if defined(__MINGW32__) || defined(__CYGWIN__)
29 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
35 // #include <sys/mman.h>
36 #include <sys/types.h>
38 #include <sys/ioctl.h>
41 #define SIGHUP 1 /* hangup */
42 #define SIGQUIT 3 /* quit */
43 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
44 #define SIGBUS 10 /* bus error */
45 #define SIGPIPE 13 /* broken pipe */
65 #include "access_mpcontext.h"
66 #include "m_property.h"
68 #include "cfg-mplayer-def.h"
70 #include "libavutil/avstring.h"
72 #include "subreader.h"
75 #include "libvo/video_out.h"
77 #include "libvo/font_load.h"
78 #include "libvo/sub.h"
81 #include "libvo/x11_common.h"
84 #include "libao2/audio_out.h"
86 #include "codec-cfg.h"
93 #include "osdep/getch2.h"
94 #include "osdep/timer.h"
95 #include "osdep/findfiles.h"
97 #include "input/input.h"
99 const int under_mencoder
= 0;
101 int player_idle_mode
=0;
103 int enable_mouse_movements
=0;
104 float start_volume
= -1;
106 #include "osdep/priority.h"
110 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
114 #include <linux/rtc.h>
117 #define RTC_IRQP_SET RTCIO_IRQP_SET
118 #define RTC_PIE_ON RTCIO_PIE_ON
119 #endif /* __linux__ */
120 #endif /* HAVE_RTC */
122 #include "stream/tv.h"
123 #include "stream/stream_radio.h"
125 #include "stream/dvbin.h"
127 #include "stream/cache2.h"
129 //**************************************************************************//
131 //**************************************************************************//
132 #include "playtree.h"
133 #include "playtreeparser.h"
135 //**************************************************************************//
137 //**************************************************************************//
138 #include "parser-cfg.h"
139 #include "parser-mpcmd.h"
141 //**************************************************************************//
143 //**************************************************************************//
145 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
149 //**************************************************************************//
150 //**************************************************************************//
151 // Input media streaming & demultiplexer:
152 //**************************************************************************//
154 static int max_framesize
=0;
156 #include "stream/stream.h"
157 #include "libmpdemux/demuxer.h"
158 #include "libmpdemux/stheader.h"
160 #ifdef CONFIG_DVDREAD
161 #include "stream/stream_dvd.h"
163 #include "stream/stream_dvdnav.h"
165 #include "libmpcodecs/dec_audio.h"
166 #include "libmpcodecs/dec_video.h"
167 #include "libmpcodecs/mp_image.h"
168 #include "libmpcodecs/vf.h"
169 #include "libmpcodecs/vd.h"
175 #include "defaultopts.h"
177 static const char help_text
[]=_(
178 "Usage: mplayer [options] [url|path/]filename\n"
180 "Basic options: (complete list in the man page)\n"
181 " -vo <drv> select video output driver ('-vo help' for a list)\n"
182 " -ao <drv> select audio output driver ('-ao help' for a list)\n"
184 " vcd://<trackno> play (S)VCD (Super Video CD) track (raw device, no mount)\n"
186 #ifdef CONFIG_DVDREAD
187 " dvd://<titleno> play DVD title from device instead of plain file\n"
189 " -alang/-slang select DVD audio/subtitle language (by 2-char country code)\n"
190 " -ss <position> seek to given (seconds or hh:mm:ss) position\n"
191 " -nosound do not play sound\n"
192 " -fs fullscreen playback (or -vm, -zoom, details in the man page)\n"
193 " -x <x> -y <y> set display resolution (for use with -vm or -zoom)\n"
194 " -sub <file> specify subtitle file to use (also see -subfps, -subdelay)\n"
195 " -playlist <file> specify playlist file\n"
196 " -vid x -aid y select video (x) and audio (y) stream to play\n"
197 " -fps x -srate y change video (x fps) and audio (y Hz) rate\n"
198 " -pp <quality> enable postprocessing filter (details in the man page)\n"
199 " -framedrop enable frame dropping (for slow machines)\n"
201 "Basic keys: (complete list in the man page, also check input.conf)\n"
202 " <- or -> seek backward/forward 10 seconds\n"
203 " down or up seek backward/forward 1 minute\n"
204 " pgdown or pgup seek backward/forward 10 minutes\n"
205 " < or > step backward/forward in playlist\n"
206 " p or SPACE pause movie (press any key to continue)\n"
207 " q or ESC stop playing and quit program\n"
208 " + or - adjust audio delay by +/- 0.1 second\n"
209 " o cycle OSD mode: none / seekbar / seekbar + timer\n"
210 " * or / increase or decrease PCM volume\n"
211 " x or z adjust subtitle delay by +/- 0.1 second\n"
212 " r or t adjust subtitle position up/down, also see -vf expand\n"
214 " * * * SEE THE MAN PAGE FOR DETAILS, FURTHER (ADVANCED) OPTIONS AND KEYS * * *\n"
218 #define Exit_SIGILL_RTCpuSel _(\
219 "- MPlayer crashed by an 'Illegal Instruction'.\n"\
220 " It may be a bug in our new runtime CPU-detection code...\n"\
221 " Please read DOCS/HTML/en/bugreports.html.\n")
223 #define Exit_SIGILL _(\
224 "- MPlayer crashed by an 'Illegal Instruction'.\n"\
225 " It usually happens when you run it on a CPU different than the one it was\n"\
226 " compiled/optimized for.\n"\
229 #define Exit_SIGSEGV_SIGFPE _(\
230 "- MPlayer crashed by bad usage of CPU/FPU/RAM.\n"\
231 " Recompile MPlayer with --enable-debug and make a 'gdb' backtrace and\n"\
232 " disassembly. Details in DOCS/HTML/en/bugreports_what.html#bugreports_crash.\n")
234 #define Exit_SIGCRASH _(\
235 "- MPlayer crashed. This shouldn't happen.\n"\
236 " It can be a bug in the MPlayer code _or_ in your drivers _or_ in your\n"\
237 " gcc version. If you think it's MPlayer's fault, please read\n"\
238 " DOCS/HTML/en/bugreports.html and follow the instructions there. We can't and\n"\
239 " won't help unless you provide this information when reporting a possible bug.\n")
241 #define SystemTooSlow _("\n\n"\
242 " ************************************************\n"\
243 " **** Your system is too SLOW to play this! ****\n"\
244 " ************************************************\n\n"\
245 "Possible reasons, problems, workarounds:\n"\
246 "- Most common: broken/buggy _audio_ driver\n"\
247 " - Try -ao sdl or use the OSS emulation of ALSA.\n"\
248 " - Experiment with different values for -autosync, 30 is a good start.\n"\
249 "- Slow video output\n"\
250 " - Try a different -vo driver (-vo help for a list) or try -framedrop!\n"\
252 " - Don't try to play a big DVD/DivX on a slow CPU! Try some of the lavdopts,\n"\
253 " e.g. -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all.\n"\
255 " - Try various combinations of -nobps -ni -forceidx -mc 0.\n"\
256 "- Slow media (NFS/SMB mounts, DVD, VCD etc)\n"\
257 " - Try -cache 8192.\n"\
258 "- Are you using -cache to play a non-interleaved AVI file?\n"\
259 " - Try -nocache.\n"\
260 "Read DOCS/HTML/en/video.html for tuning/speedup tips.\n"\
261 "If none of this helps you, read DOCS/HTML/en/bugreports.html.\n\n")
264 //**************************************************************************//
265 //**************************************************************************//
267 // Common FIFO functions, and keyboard/event FIFO code
269 int noconsolecontrols
=0;
270 //**************************************************************************//
273 double video_time_usage
=0;
274 double vout_time_usage
=0;
275 static double audio_time_usage
=0;
276 static int total_time_usage_start
=0;
277 static int total_frame_cnt
=0;
278 static int drop_frame_cnt
=0; // total number of dropped frames
283 static int output_quality
=0;
285 static int list_properties
= 0;
288 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
289 static char* playing_msg
= NULL
;
291 static double seek_to_sec
;
292 static off_t seek_to_byte
=0;
293 static off_t step_sec
=0;
295 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
298 int autosync
=0; // 30 might be a good default value.
301 char **audio_codec_list
=NULL
; // override audio codec
302 char **video_codec_list
=NULL
; // override video codec
303 char **audio_fm_list
=NULL
; // override audio codec family
304 char **video_fm_list
=NULL
; // override video codec family
307 extern char *demuxer_name
; // override demuxer
308 extern char *audio_demuxer_name
; // override audio demuxer
309 extern char *sub_demuxer_name
; // override sub demuxer
311 // this dvdsub_id was selected via slang
312 // use this to allow dvdnav to follow -slang across stream resets,
313 // in particular the subtitle ID for a language changes
316 static char* spudec_ifo
=NULL
;
317 int forced_subs_only
=0;
321 int stream_cache_size
=-1;
322 #ifdef CONFIG_STREAM_CACHE
323 float stream_cache_min_percent
=20.0;
324 float stream_cache_seek_min_percent
=50.0;
328 int stream_dump_type
=0;
331 static float default_max_pts_correction
=-1;//0.01f;
333 static int ignore_start
=0;
335 static int softsleep
=0;
338 static int force_srate
=0;
339 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
340 static int play_n_frames
=-1;
341 static int play_n_frames_mf
=-1;
344 char *font_name
=NULL
;
345 char *sub_font_name
=NULL
;
346 extern int font_fontconfig
;
347 float font_factor
=0.75;
348 char **sub_name
=NULL
;
352 char *vobsub_name
=NULL
;
354 int suboverlap_enabled
= 1;
358 char* current_module
=NULL
; // for debugging
364 #include "m_struct.h"
365 #include "libmenu/menu.h"
366 static const vf_info_t
* const libmenu_vfs
[] = {
370 static vf_instance_t
* vf_menu
= NULL
;
372 static char* menu_cfg
= NULL
;
373 static char* menu_root
= "main";
378 static int nortc
= 1;
379 static char* rtc_device
;
382 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
383 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
384 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
385 int use_filedir_conf
;
386 int use_filename_title
;
388 #include "mpcommon.h"
391 #include "metadata.h"
393 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
395 const void *mpctx_get_video_out(MPContext
*mpctx
)
397 return mpctx
->video_out
;
400 const void *mpctx_get_audio_out(MPContext
*mpctx
)
402 return mpctx
->audio_out
;
405 void *mpctx_get_demuxer(MPContext
*mpctx
)
407 return mpctx
->demuxer
;
410 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
412 return mpctx
->playtree_iter
;
415 void *mpctx_get_mixer(MPContext
*mpctx
)
417 return &mpctx
->mixer
;
420 int mpctx_get_global_sub_size(MPContext
*mpctx
)
422 return mpctx
->global_sub_size
;
425 int mpctx_get_osd_function(MPContext
*mpctx
)
427 return mpctx
->osd_function
;
430 static float get_relative_time(struct MPContext
*mpctx
)
432 unsigned int new_time
= GetTimer();
433 unsigned int delta
= new_time
- mpctx
->last_time
;
434 mpctx
->last_time
= new_time
;
435 return delta
* 0.000001;
438 static int is_valid_metadata_type(struct MPContext
*mpctx
, metadata_t type
) {
441 /* check for valid video stream */
442 case META_VIDEO_CODEC
:
443 case META_VIDEO_BITRATE
:
444 case META_VIDEO_RESOLUTION
:
446 if (!mpctx
->sh_video
)
451 /* check for valid audio stream */
452 case META_AUDIO_CODEC
:
453 case META_AUDIO_BITRATE
:
454 case META_AUDIO_SAMPLES
:
456 if (!mpctx
->sh_audio
)
461 /* check for valid demuxer */
462 case META_INFO_TITLE
:
463 case META_INFO_ARTIST
:
464 case META_INFO_ALBUM
:
466 case META_INFO_COMMENT
:
467 case META_INFO_TRACK
:
468 case META_INFO_GENRE
:
482 static char *get_demuxer_info(struct MPContext
*mpctx
, char *tag
) {
483 char **info
= mpctx
->demuxer
->info
;
489 for (n
= 0; info
[2*n
] != NULL
; n
++)
490 if (!strcasecmp (info
[2*n
], tag
))
493 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
496 char *get_metadata(struct MPContext
*mpctx
, metadata_t type
)
499 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
500 sh_video_t
* const sh_video
= mpctx
->sh_video
;
502 if (!is_valid_metadata_type(mpctx
, type
))
509 return strdup (mp_basename2 (mpctx
->filename
));
512 case META_VIDEO_CODEC
:
514 if (sh_video
->format
== 0x10000001)
515 meta
= strdup ("mpeg1");
516 else if (sh_video
->format
== 0x10000002)
517 meta
= strdup ("mpeg2");
518 else if (sh_video
->format
== 0x10000004)
519 meta
= strdup ("mpeg4");
520 else if (sh_video
->format
== 0x10000005)
521 meta
= strdup ("h264");
522 else if (sh_video
->format
>= 0x20202020)
525 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
530 sprintf (meta
, "0x%08X", sh_video
->format
);
535 case META_VIDEO_BITRATE
:
538 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
542 case META_VIDEO_RESOLUTION
:
545 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
549 case META_AUDIO_CODEC
:
551 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
552 meta
= strdup (sh_audio
->codec
->name
);
556 case META_AUDIO_BITRATE
:
559 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
563 case META_AUDIO_SAMPLES
:
566 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
570 /* check for valid demuxer */
571 case META_INFO_TITLE
:
572 return get_demuxer_info(mpctx
, "Title");
574 case META_INFO_ARTIST
:
575 return get_demuxer_info(mpctx
, "Artist");
577 case META_INFO_ALBUM
:
578 return get_demuxer_info(mpctx
, "Album");
581 return get_demuxer_info(mpctx
, "Year");
583 case META_INFO_COMMENT
:
584 return get_demuxer_info(mpctx
, "Comment");
586 case META_INFO_TRACK
:
587 return get_demuxer_info(mpctx
, "Track");
589 case META_INFO_GENRE
:
590 return get_demuxer_info(mpctx
, "Genre");
599 static void print_file_properties(struct MPContext
*mpctx
, const char *filename
)
601 double start_pts
= MP_NOPTS_VALUE
;
602 double video_start_pts
= MP_NOPTS_VALUE
;
603 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
604 filename_recode(filename
));
605 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
606 if (mpctx
->sh_video
) {
607 /* Assume FOURCC if all bytes >= 0x20 (' ') */
608 if (mpctx
->sh_video
->format
>= 0x20202020)
609 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
611 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
612 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
613 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
614 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
615 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
616 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
617 video_start_pts
= ds_get_next_pts(mpctx
->d_video
);
619 if (mpctx
->sh_audio
) {
620 /* Assume FOURCC if all bytes >= 0x20 (' ') */
621 if (mpctx
->sh_audio
->format
>= 0x20202020)
622 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
624 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
625 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
626 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
627 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
628 start_pts
= ds_get_next_pts(mpctx
->d_audio
);
630 if (video_start_pts
!= MP_NOPTS_VALUE
) {
631 if (start_pts
== MP_NOPTS_VALUE
|| !mpctx
->sh_audio
||
632 (mpctx
->sh_video
&& video_start_pts
< start_pts
))
633 start_pts
= video_start_pts
;
635 if (start_pts
!= MP_NOPTS_VALUE
)
636 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_START_TIME=%.2f\n", start_pts
);
638 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_START_TIME=unknown\n");
639 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2f\n", get_time_length(mpctx
));
640 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_SEEKABLE=%d\n",
641 mpctx
->stream
->seek
&& (!mpctx
->demuxer
|| mpctx
->demuxer
->seekable
));
642 if (mpctx
->demuxer
) {
643 if (mpctx
->demuxer
->num_chapters
== 0)
644 stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_NUM_CHAPTERS
, &mpctx
->demuxer
->num_chapters
);
645 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_CHAPTERS=%d\n", mpctx
->demuxer
->num_chapters
);
649 /// step size of mixer changes
653 static void mp_dvdnav_context_free(MPContext
*ctx
){
654 if (ctx
->nav_smpi
) free_mp_image(ctx
->nav_smpi
);
655 ctx
->nav_smpi
= NULL
;
656 free(ctx
->nav_buffer
);
657 ctx
->nav_buffer
= NULL
;
658 ctx
->nav_start
= NULL
;
659 ctx
->nav_in_size
= 0;
663 void uninit_player(struct MPContext
*mpctx
, unsigned int mask
){
664 mask
&= mpctx
->initialized_flags
;
666 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
668 if(mask
&INITIALIZED_ACODEC
){
669 mpctx
->initialized_flags
&=~INITIALIZED_ACODEC
;
670 current_module
="uninit_acodec";
671 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
672 mpctx
->sh_audio
=NULL
;
673 mpctx
->mixer
.afilter
= NULL
;
676 if(mask
&INITIALIZED_VCODEC
){
677 mpctx
->initialized_flags
&=~INITIALIZED_VCODEC
;
678 current_module
="uninit_vcodec";
679 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
680 mpctx
->sh_video
=NULL
;
686 if(mask
&INITIALIZED_DEMUXER
){
687 mpctx
->initialized_flags
&=~INITIALIZED_DEMUXER
;
688 current_module
="free_demuxer";
689 if (mpctx
->num_sources
) {
690 mpctx
->demuxer
= mpctx
->sources
[0].demuxer
;
691 for (int i
= 1; i
< mpctx
->num_sources
; i
++) {
692 free_stream(mpctx
->sources
[i
].stream
);
693 free_demuxer(mpctx
->sources
[i
].demuxer
);
696 talloc_free(mpctx
->sources
);
697 mpctx
->sources
= NULL
;
698 mpctx
->num_sources
= 0;
699 talloc_free(mpctx
->timeline
);
700 mpctx
->timeline
= NULL
;
701 mpctx
->num_timeline_parts
= 0;
702 talloc_free(mpctx
->chapters
);
703 mpctx
->chapters
= NULL
;
704 mpctx
->num_chapters
= 0;
705 mpctx
->video_offset
= 0;
707 mpctx
->stream
=mpctx
->demuxer
->stream
;
708 free_demuxer(mpctx
->demuxer
);
713 // kill the cache process:
714 if(mask
&INITIALIZED_STREAM
){
715 mpctx
->initialized_flags
&=~INITIALIZED_STREAM
;
716 current_module
="uninit_stream";
717 if(mpctx
->stream
) free_stream(mpctx
->stream
);
721 if(mask
&INITIALIZED_VO
){
722 mpctx
->initialized_flags
&=~INITIALIZED_VO
;
723 current_module
="uninit_vo";
724 vo_destroy(mpctx
->video_out
);
725 mpctx
->video_out
=NULL
;
727 mp_dvdnav_context_free(mpctx
);
731 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
732 if(mask
&INITIALIZED_GETCH2
){
733 mpctx
->initialized_flags
&=~INITIALIZED_GETCH2
;
734 current_module
="uninit_getch2";
735 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
740 if(mask
&INITIALIZED_VOBSUB
){
741 mpctx
->initialized_flags
&=~INITIALIZED_VOBSUB
;
742 current_module
="uninit_vobsub";
743 if(vo_vobsub
) vobsub_close(vo_vobsub
);
747 if (mask
&INITIALIZED_SPUDEC
){
748 mpctx
->initialized_flags
&=~INITIALIZED_SPUDEC
;
749 current_module
="uninit_spudec";
750 spudec_free(vo_spudec
);
754 if(mask
&INITIALIZED_AO
){
755 mpctx
->initialized_flags
&=~INITIALIZED_AO
;
756 current_module
="uninit_ao";
757 if (mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
758 if (mpctx
->audio_out
)
759 mpctx
->audio_out
->uninit(mpctx
->stop_play
!= AT_END_OF_FILE
);
760 mpctx
->audio_out
=NULL
;
766 void exit_player_with_rc(struct MPContext
*mpctx
, enum exit_reason how
, int rc
)
768 if (mpctx
->user_muted
&& !mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
769 uninit_player(mpctx
, INITIALIZED_ALL
);
770 #if defined(__MINGW32__) || defined(__CYGWIN__)
774 vo_uninit(mpctx
->x11_state
); // Close the X11 connection (if any is open).
777 current_module
="uninit_input";
778 mp_input_uninit(mpctx
->input
);
784 #ifdef CONFIG_FREETYPE
785 current_module
="uninit_font";
786 if (mpctx
->osd
&& mpctx
->osd
->sub_font
!= vo_font
)
787 free_font_desc(mpctx
->osd
->sub_font
);
788 free_font_desc(vo_font
);
792 osd_free(mpctx
->osd
);
795 ass_library_done(ass_library
);
799 current_module
="exit_player";
801 // free mplayer config
803 m_config_free(mpctx
->mconfig
);
804 mpctx
->mconfig
= NULL
;
806 if(mpctx
->playtree_iter
)
807 play_tree_iter_free(mpctx
->playtree_iter
);
808 mpctx
->playtree_iter
= NULL
;
810 play_tree_free(mpctx
->playtree
, 1);
811 mpctx
->playtree
= NULL
;
813 talloc_free(mpctx
->key_fifo
);
815 free(edl_records
); // free mem allocated for EDL
819 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Quit");
820 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=QUIT\n");
823 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","End of file");
824 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=EOF\n");
827 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Fatal error");
828 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=ERROR\n");
831 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=NONE\n");
833 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
838 static void exit_player(struct MPContext
*mpctx
, enum exit_reason how
)
840 exit_player_with_rc(mpctx
, how
, 1);
844 static void child_sighandler(int x
){
846 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
850 #ifdef CONFIG_CRASH_DEBUG
851 static char *prog_path
;
852 static int crash_debug
= 0;
855 static void exit_sighandler(int x
){
856 static int sig_count
=0;
857 #ifdef CONFIG_CRASH_DEBUG
858 if (!crash_debug
|| x
!= SIGTRAP
)
863 /* We're crashing bad and can't uninit cleanly :(
864 * by popular request, we make one last (dirty)
865 * effort to restore the user's
870 if(sig_count
==6) exit(1);
874 kill(getpid(),SIGKILL
);
877 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, "\n");
878 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,
879 "\nMPlayer interrupted by signal %d in module: %s\n", x
,
880 current_module
? current_module
: "unknown");
881 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
889 async_quit_request
= 1;
890 return; // killed from keyboard (^C) or killed [-9]
892 #if CONFIG_RUNTIME_CPUDETECT
893 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL_RTCpuSel
);
895 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL
);
899 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGSEGV_SIGFPE
);
901 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGCRASH
);
902 #ifdef CONFIG_CRASH_DEBUG
905 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
907 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
908 if (gdb_pid
== 0) { // We are the child
910 snprintf(spid
, sizeof(spid
), "%i", getppid());
911 getch2_disable(); // allow terminal to work properly with gdb
912 if (execlp("gdb", "gdb", prog_path
, spid
, "-ex", "bt", NULL
) == -1)
913 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
914 } else if (gdb_pid
< 0)
915 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
917 waitpid(gdb_pid
, NULL
, 0);
919 if (x
== SIGTRAP
) return;
927 #include "cfg-mplayer.h"
929 static int cfg_include(m_option_t
*conf
, char *filename
)
931 return m_config_parse_config_file(conf
->priv
, filename
);
934 static void parse_cfgfiles(struct MPContext
*mpctx
, m_config_t
* conf
)
938 if (!disable_system_conf
&&
939 m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
940 exit_player(mpctx
, EXIT_NONE
);
941 if ((conffile
= get_path("")) == NULL
) {
942 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"Cannot find HOME directory.\n");
947 mkdir(conffile
, 0777);
950 if ((conffile
= get_path("config")) == NULL
) {
951 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"get_path(\"config\") problem\n");
953 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
954 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Creating config file: %s\n", conffile
);
955 write(conffile_fd
, default_config
, strlen(default_config
));
958 if (!disable_user_conf
&&
959 m_config_parse_config_file(conf
, conffile
) < 0)
960 exit_player(mpctx
, EXIT_NONE
);
966 #define PROFILE_CFG_PROTOCOL "protocol."
968 static void load_per_protocol_config (m_config_t
* conf
, const char *const file
)
971 char protocol
[strlen (PROFILE_CFG_PROTOCOL
) + strlen (file
) + 1];
974 /* does filename actually uses a protocol ? */
975 str
= strstr (file
, "://");
979 sprintf (protocol
, "%s%s", PROFILE_CFG_PROTOCOL
, file
);
980 protocol
[strlen (PROFILE_CFG_PROTOCOL
)+strlen(file
)-strlen(str
)] = '\0';
981 p
= m_config_get_profile (conf
, protocol
);
984 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading protocol-related profile '%s'\n", protocol
);
985 m_config_set_profile(conf
,p
);
989 #define PROFILE_CFG_EXTENSION "extension."
991 static void load_per_extension_config (m_config_t
* conf
, const char *const file
)
994 char extension
[strlen (PROFILE_CFG_EXTENSION
) + 8];
997 /* does filename actually have an extension ? */
998 str
= strrchr (file
, '.');
1002 sprintf (extension
, PROFILE_CFG_EXTENSION
);
1003 strncat (extension
, ++str
, 7);
1004 p
= m_config_get_profile (conf
, extension
);
1007 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", extension
);
1008 m_config_set_profile(conf
,p
);
1012 #define PROFILE_CFG_VO "vo."
1013 #define PROFILE_CFG_AO "ao."
1015 static void load_per_output_config (m_config_t
* conf
, char *cfg
, char *out
)
1017 char profile
[strlen (cfg
) + strlen (out
) + 1];
1020 sprintf (profile
, "%s%s", cfg
, out
);
1021 p
= m_config_get_profile (conf
, profile
);
1024 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", profile
);
1025 m_config_set_profile(conf
,p
);
1030 * Tries to load a config file
1031 * @return 0 if file was not found, 1 otherwise
1033 static int try_load_config(m_config_t
*conf
, const char *file
)
1036 if (stat(file
, &st
))
1038 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Loading config '%s'\n", file
);
1039 m_config_parse_config_file (conf
, file
);
1043 static void load_per_file_config (m_config_t
* conf
, const char *const file
)
1049 if (strlen(file
) > PATH_MAX
- 14) {
1050 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Filename is too long, can not load file or directory specific config files\n");
1053 sprintf (cfg
, "%s.conf", file
);
1055 name
= strrchr(cfg
, '/');
1056 if (HAVE_DOS_PATHS
) {
1057 char *tmp
= strrchr(cfg
, '\\');
1058 if (!name
|| tmp
> name
)
1060 tmp
= strrchr(cfg
, ':');
1061 if (!name
|| tmp
> name
)
1069 if (use_filedir_conf
) {
1070 char dircfg
[PATH_MAX
];
1071 strcpy(dircfg
, cfg
);
1072 strcpy(dircfg
+ (name
- cfg
), "mplayer.conf");
1073 try_load_config(conf
, dircfg
);
1075 if (try_load_config(conf
, cfg
))
1079 if ((confpath
= get_path (name
)) != NULL
)
1081 try_load_config(conf
, confpath
);
1087 /* When libmpdemux performs a blocking operation (network connection or
1088 * cache filling) if the operation fails we use this function to check
1089 * if it was interrupted by the user.
1090 * The function returns a new value for eof. */
1091 static int libmpdemux_was_interrupted(struct MPContext
*mpctx
, int stop_play
)
1094 if((cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0)) != NULL
) {
1097 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
1098 case MP_CMD_PLAY_TREE_STEP
: {
1099 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
1100 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
1102 case MP_CMD_PLAY_TREE_UP_STEP
: {
1103 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
1105 case MP_CMD_PLAY_ALT_SRC_STEP
: {
1106 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
1114 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
1116 static int playtree_add_playlist(struct MPContext
*mpctx
, play_tree_t
* entry
)
1118 play_tree_add_bpf(entry
,mpctx
->filename
);
1122 entry
= mpctx
->playtree_iter
->tree
;
1123 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1124 return PT_NEXT_ENTRY
;
1126 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
1127 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1128 return PT_NEXT_ENTRY
;
1131 play_tree_remove(entry
,1,1);
1134 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
1135 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
1136 entry
= mpctx
->playtree_iter
->tree
;
1137 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1138 return PT_NEXT_ENTRY
;
1140 play_tree_remove(entry
,1,1);
1145 void add_subtitles(struct MPContext
*mpctx
, char *filename
, float fps
, int noerr
)
1147 struct MPOpts
*opts
= &mpctx
->opts
;
1148 sub_data
*subd
= NULL
;
1149 struct ass_track
*asst
= NULL
;
1151 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
1156 if (opts
->ass_enabled
) {
1158 asst
= ass_read_stream(ass_library
, filename
, sub_cp
);
1160 asst
= ass_read_stream(ass_library
, filename
, 0);
1163 subd
= sub_read_file(filename
, fps
);
1165 asst
= ass_read_subdata(ass_library
, subd
, fps
);
1174 subd
= sub_read_file(filename
, fps
);
1177 if (!asst
&& !subd
) {
1178 mp_tmsg(MSGT_CPLAYER
, noerr
? MSGL_WARN
: MSGL_ERR
,
1179 "Cannot load subtitles: %s\n", filename_recode(filename
));
1183 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
1184 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
1185 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
1186 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
1187 filename_recode(filename
));
1188 ++mpctx
->set_of_sub_size
;
1189 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "SUB: Added subtitle file (%d): %s\n", mpctx
->set_of_sub_size
,
1190 filename_recode(filename
));
1193 void init_vo_spudec(struct MPContext
*mpctx
)
1196 spudec_free(vo_spudec
);
1197 mpctx
->initialized_flags
&= ~INITIALIZED_SPUDEC
;
1200 // we currently can't work without video stream
1201 if (!mpctx
->sh_video
)
1205 unsigned int palette
[16], width
, height
;
1206 current_module
="spudec_init_vobsub";
1207 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1208 vo_spudec
=spudec_new_scaled(palette
, width
, height
, NULL
, 0);
1211 #ifdef CONFIG_DVDREAD
1212 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1213 current_module
="spudec_init_dvdread";
1214 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1215 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
,
1220 #ifdef CONFIG_DVDNAV
1221 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1222 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1223 current_module
="spudec_init_dvdnav";
1224 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, NULL
, 0);
1228 if (vo_spudec
==NULL
) {
1229 sh_sub_t
*sh
= mpctx
->d_sub
->sh
;
1230 current_module
="spudec_init_normal";
1231 vo_spudec
=spudec_new_scaled(NULL
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, sh
->extradata
, sh
->extradata_len
);
1232 spudec_set_font_factor(vo_spudec
,font_factor
);
1235 if (vo_spudec
!=NULL
) {
1236 mpctx
->initialized_flags
|=INITIALIZED_SPUDEC
;
1237 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
1242 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1243 * make it all work is to use the builtin SDL-bootstrap code, which
1244 * will be done automatically by replacing our main() if we include SDL.h.
1246 #if defined(__APPLE__) && defined(CONFIG_SDL)
1247 #ifdef CONFIG_SDL_SDL_H
1248 #include <SDL/SDL.h>
1255 * \brief append a formatted string
1256 * \param buf buffer to print into
1257 * \param pos position of terminating 0 in buf
1258 * \param len maximum number of characters in buf, not including terminating 0
1259 * \param format printf format string
1261 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1264 va_start(va
, format
);
1265 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1274 * \brief append time in the hh:mm:ss.f format
1275 * \param buf buffer to print into
1276 * \param pos position of terminating 0 in buf
1277 * \param len maximum number of characters in buf, not including terminating 0
1278 * \param time time value to convert/append
1280 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1281 int64_t tenths
= 10 * time
;
1282 int f1
= tenths
% 10;
1283 int ss
= (tenths
/ 10) % 60;
1284 int mm
= (tenths
/ 600) % 60;
1285 int hh
= tenths
/ 36000;
1287 saddf(buf
, pos
, len
, "unknown");
1291 saddf(buf
, pos
, len
, "%2d:", hh
);
1292 if (hh
> 0 || mm
> 0)
1293 saddf(buf
, pos
, len
, "%02d:", mm
);
1294 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1297 static void print_status(struct MPContext
*mpctx
, double a_pos
, bool at_frame
)
1299 struct MPOpts
*opts
= &mpctx
->opts
;
1300 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1302 if (mpctx
->sh_audio
&& a_pos
== MP_NOPTS_VALUE
)
1303 a_pos
= playing_audio_pts(mpctx
);
1304 if (mpctx
->sh_audio
&& sh_video
&& at_frame
) {
1305 mpctx
->last_av_difference
= a_pos
- sh_video
->pts
- audio_delay
;
1306 if (mpctx
->time_frame
> 0)
1307 mpctx
->last_av_difference
+= mpctx
->time_frame
* opts
->playback_speed
;
1308 if (mpctx
->last_av_difference
> 0.5 && drop_frame_cnt
> 50
1309 && !mpctx
->drop_message_shown
) {
1310 mp_tmsg(MSGT_AVSYNC
,MSGL_WARN
,SystemTooSlow
);
1311 mpctx
->drop_message_shown
= true;
1322 if (screen_width
> 0)
1323 width
= screen_width
;
1326 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
1327 /* Windows command line is broken (MinGW's rxvt works, but we
1328 * should not depend on that). */
1331 line
= malloc(width
+ 1); // one additional char for the terminating null
1334 if (mpctx
->sh_audio
) {
1335 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1337 float len
= get_time_length(mpctx
);
1338 saddf(line
, &pos
, width
, "(");
1339 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1340 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1341 sadd_hhmmssf(line
, &pos
, width
, len
);
1342 saddf(line
, &pos
, width
, ") ");
1348 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1351 if (mpctx
->sh_audio
&& sh_video
)
1352 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ",
1353 mpctx
->last_av_difference
, mpctx
->total_avsync_change
);
1357 saddf(line
, &pos
, width
, "%3d/%3d ",
1358 (int)sh_video
->num_frames
,
1359 (int)sh_video
->num_frames_decoded
);
1363 if (sh_video
->timer
> 0.5)
1364 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1365 (int)(100.0*video_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1366 (int)(100.0*vout_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1367 (100.0*audio_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
));
1369 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1370 } else if (mpctx
->sh_audio
) {
1371 if (mpctx
->delay
> 0.5)
1372 saddf(line
, &pos
, width
, "%4.1f%% ",
1373 100.0*audio_time_usage
/(double)mpctx
->delay
);
1375 saddf(line
, &pos
, width
, "??,?%% ");
1380 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1382 #ifdef CONFIG_STREAM_CACHE
1384 if (stream_cache_size
> 0)
1385 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1389 if (opts
->playback_speed
!= 1)
1390 saddf(line
, &pos
, width
, "%4.2fx ", opts
->playback_speed
);
1393 if (erase_to_end_of_line
) {
1395 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1397 memset(&line
[pos
], ' ', width
- pos
);
1399 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s\r", line
);
1405 * \brief build a chain of audio filters that converts the input format
1406 * to the ao's format, taking into account the current playback_speed.
1407 * \param sh_audio describes the requested input format of the chain.
1408 * \param ao_data describes the requested output format of the chain.
1410 int build_afilter_chain(struct MPContext
*mpctx
, sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1412 struct MPOpts
*opts
= &mpctx
->opts
;
1417 mpctx
->mixer
.afilter
= NULL
;
1420 if(af_control_any_rev(sh_audio
->afilter
,
1421 AF_CONTROL_PLAYBACK_SPEED
| AF_CONTROL_SET
,
1422 &opts
->playback_speed
)) {
1423 new_srate
= sh_audio
->samplerate
;
1425 new_srate
= sh_audio
->samplerate
* opts
->playback_speed
;
1426 if (new_srate
!= ao_data
->samplerate
) {
1427 // limits are taken from libaf/af_resample.c
1428 if (new_srate
< 8000)
1430 if (new_srate
> 192000)
1432 opts
->playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1435 result
= init_audio_filters(sh_audio
, new_srate
,
1436 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
);
1437 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1442 typedef struct mp_osd_msg mp_osd_msg_t
;
1444 /// Previous message on the stack.
1448 int id
,level
,started
;
1449 /// Display duration in ms.
1453 /// OSD message stack.
1454 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1457 * \brief Add a message on the OSD message stack
1459 * If a message with the same id is already present in the stack
1460 * it is pulled on top of the stack, otherwise a new message is created.
1463 static void set_osd_msg_va(int id
, int level
, int time
, const char *fmt
,
1466 mp_osd_msg_t
*msg
,*last
=NULL
;
1469 // look if the id is already in the stack
1470 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1471 last
= msg
, msg
= msg
->prev
);
1472 // not found: alloc it
1474 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1475 msg
->prev
= osd_msg_stack
;
1476 osd_msg_stack
= msg
;
1477 } else if(last
) { // found, but it's not on top of the stack
1478 last
->prev
= msg
->prev
;
1479 msg
->prev
= osd_msg_stack
;
1480 osd_msg_stack
= msg
;
1483 r
= vsnprintf(msg
->msg
, 128, fmt
, ap
);
1484 if(r
>= 128) msg
->msg
[127] = 0;
1492 void set_osd_msg(int id
, int level
, int time
, const char *fmt
, ...)
1496 set_osd_msg_va(id
, level
, time
, fmt
, ap
);
1500 void set_osd_tmsg(int id
, int level
, int time
, const char *fmt
, ...)
1504 set_osd_msg_va(id
, level
, time
, mp_gtext(fmt
), ap
);
1510 * \brief Remove a message from the OSD stack
1512 * This function can be used to get rid of a message right away.
1516 void rm_osd_msg(int id
) {
1517 mp_osd_msg_t
*msg
,*last
=NULL
;
1519 // Search for the msg
1520 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1521 last
= msg
, msg
= msg
->prev
);
1524 // Detach it from the stack and free it
1526 last
->prev
= msg
->prev
;
1528 osd_msg_stack
= msg
->prev
;
1533 * \brief Remove all messages from the OSD stack
1537 static void clear_osd_msgs(void) {
1538 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1544 osd_msg_stack
= NULL
;
1548 * \brief Get the current message from the OSD stack.
1550 * This function decrements the message timer and destroys the old ones.
1551 * The message that should be displayed is returned (if any).
1555 static mp_osd_msg_t
* get_osd_msg(struct MPContext
*mpctx
)
1557 struct MPOpts
*opts
= &mpctx
->opts
;
1558 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1559 static unsigned last_update
= 0;
1560 unsigned now
= GetTimerMS();
1562 char hidden_dec_done
= 0;
1564 if (mpctx
->osd_visible
) {
1565 // 36000000 means max timed visibility is 1 hour into the future, if
1566 // the difference is greater assume it's wrapped around from below 0
1567 if (mpctx
->osd_visible
- now
> 36000000) {
1568 mpctx
->osd_visible
= 0;
1569 vo_osd_progbar_type
= -1; // disable
1570 vo_osd_changed(OSDTYPE_PROGBAR
);
1571 mpctx
->osd_function
= mpctx
->paused
? OSD_PAUSE
: OSD_PLAY
;
1574 if (mpctx
->osd_show_percentage_until
- now
> 36000000)
1575 mpctx
->osd_show_percentage_until
= 0;
1577 if(!last_update
) last_update
= now
;
1578 diff
= now
>= last_update
? now
- last_update
: 0;
1582 // Look for the first message in the stack with high enough level.
1583 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1585 if (msg
->level
> opts
->osd_level
&& hidden_dec_done
)
1587 // The message has a high enough level or it is the first hidden one
1588 // in both cases we decrement the timer or kill it.
1589 if(!msg
->started
|| msg
->time
> diff
) {
1590 if(msg
->started
) msg
->time
-= diff
;
1591 else msg
->started
= 1;
1593 if (msg
->level
<= opts
->osd_level
)
1595 hidden_dec_done
= 1;
1604 osd_msg_stack
= prev
;
1613 * \brief Display the OSD bar.
1615 * Display the OSD bar or fall back on a simple message.
1619 void set_osd_bar(struct MPContext
*mpctx
, int type
,const char* name
,double min
,double max
,double val
) {
1620 struct MPOpts
*opts
= &mpctx
->opts
;
1621 if (opts
->osd_level
< 1)
1624 if(mpctx
->sh_video
) {
1625 mpctx
->osd_visible
= (GetTimerMS() + 1000) | 1;
1626 vo_osd_progbar_type
= type
;
1627 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1628 vo_osd_changed(OSDTYPE_PROGBAR
);
1632 set_osd_msg(OSD_MSG_BAR
, 1, opts
->osd_duration
, "%s: %d %%",
1633 name
, ROUND(100*(val
-min
)/(max
-min
)));
1637 * \brief Display text subtitles on the OSD
1639 void set_osd_subtitle(struct MPContext
*mpctx
, subtitle
*subs
)
1643 vo_osd_changed(OSDTYPE_SUBTITLE
);
1644 if (!mpctx
->sh_video
) {
1645 // reverse order, since newest set_osd_msg is displayed first
1646 for (i
= SUB_MAX_TEXT
- 1; i
>= 0; i
--) {
1647 if (!subs
|| i
>= subs
->lines
|| !subs
->text
[i
])
1648 rm_osd_msg(OSD_MSG_SUB_BASE
+ i
);
1650 // HACK: currently display time for each sub line except the last is set to 2 seconds.
1651 int display_time
= i
== subs
->lines
- 1 ? 180000 : 2000;
1652 set_osd_msg(OSD_MSG_SUB_BASE
+ i
, 1, display_time
, "%s", subs
->text
[i
]);
1659 * \brief Update the OSD message line.
1661 * This function displays the current message on the vo OSD or on the term.
1662 * If the stack is empty and the OSD level is high enough the timer
1663 * is displayed (only on the vo OSD).
1667 static void update_osd_msg(struct MPContext
*mpctx
)
1669 struct MPOpts
*opts
= &mpctx
->opts
;
1671 struct osd_state
*osd
= mpctx
->osd
;
1672 char osd_text_timer
[128];
1674 if (mpctx
->add_osd_seek_info
) {
1675 double percentage
= get_percent_pos(mpctx
);
1676 set_osd_bar(mpctx
, 0, "Position", 0, 100, percentage
);
1677 if (mpctx
->sh_video
)
1678 mpctx
->osd_show_percentage_until
= (GetTimerMS() + 1000) | 1;
1679 mpctx
->add_osd_seek_info
= false;
1682 // Look if we have a msg
1683 if((msg
= get_osd_msg(mpctx
))) {
1684 if (strcmp(osd
->osd_text
, msg
->msg
)) {
1685 strncpy(osd
->osd_text
, msg
->msg
, 127);
1686 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1687 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1692 if(mpctx
->sh_video
) {
1693 // fallback on the timer
1694 if (opts
->osd_level
>= 2) {
1695 int len
= get_time_length(mpctx
);
1696 int percentage
= -1;
1697 char percentage_text
[10];
1698 int pts
= get_current_time(mpctx
);
1700 if (mpctx
->osd_show_percentage_until
)
1701 percentage
= get_percent_pos(mpctx
);
1703 if (percentage
>= 0)
1704 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1706 percentage_text
[0] = 0;
1708 if (opts
->osd_level
== 3)
1709 snprintf(osd_text_timer
, 63,
1710 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1711 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1712 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1714 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1715 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1716 pts
%60,percentage_text
);
1718 osd_text_timer
[0]=0;
1720 if (strcmp(osd
->osd_text
, osd_text_timer
)) {
1721 strncpy(osd
->osd_text
, osd_text_timer
, 63);
1722 vo_osd_changed(OSDTYPE_OSD
);
1727 // Clear the term osd line
1728 if (term_osd
&& osd
->osd_text
[0]) {
1729 osd
->osd_text
[0] = 0;
1730 printf("%s\n",term_osd_esc
);
1738 void reinit_audio_chain(struct MPContext
*mpctx
)
1740 struct MPOpts
*opts
= &mpctx
->opts
;
1741 if (!mpctx
->sh_audio
)
1743 if (!(mpctx
->initialized_flags
& INITIALIZED_ACODEC
)) {
1744 current_module
="init_audio_codec";
1745 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1746 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1749 mpctx
->initialized_flags
|=INITIALIZED_ACODEC
;
1750 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1754 if (!(mpctx
->initialized_flags
& INITIALIZED_AO
)) {
1755 current_module
="af_preinit";
1756 ao_data
.samplerate
=force_srate
;
1758 ao_data
.format
= opts
->audio_output_format
;
1759 // first init to detect best values
1760 if(!init_audio_filters(mpctx
->sh_audio
, // preliminary init
1762 mpctx
->sh_audio
->samplerate
,
1764 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1765 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
, "Error at audio filter chain "
1767 exit_player(mpctx
, EXIT_ERROR
);
1769 current_module
="ao2_init";
1770 mpctx
->audio_out
= init_best_audio_out(opts
->audio_driver_list
,
1775 if(!mpctx
->audio_out
){
1776 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Could not open/initialize audio device -> no sound.\n");
1779 mpctx
->initialized_flags
|=INITIALIZED_AO
;
1780 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1781 mpctx
->audio_out
->info
->short_name
,
1782 ao_data
.samplerate
, ao_data
.channels
,
1783 af_fmt2str_short(ao_data
.format
),
1784 af_fmt2bits(ao_data
.format
)/8 );
1785 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1786 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1787 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1788 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1791 // init audio filters:
1792 current_module
="af_init";
1793 if(!build_afilter_chain(mpctx
, mpctx
->sh_audio
, &ao_data
)) {
1794 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Couldn't find matching filter/ao format!\n");
1797 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1798 mpctx
->mixer
.volstep
= volstep
;
1802 uninit_player(mpctx
, INITIALIZED_ACODEC
|INITIALIZED_AO
); // close codec and possibly AO
1803 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1804 mpctx
->d_audio
->id
= -2;
1812 // Return pts value corresponding to the end point of audio written to the
1814 static double written_audio_pts(struct MPContext
*mpctx
)
1816 sh_audio_t
*sh_audio
= mpctx
->sh_audio
;
1817 demux_stream_t
*d_audio
= mpctx
->d_audio
;
1818 double buffered_output
;
1819 // first calculate the end pts of audio that has been output by decoder
1820 double a_pts
= sh_audio
->pts
;
1821 if (a_pts
!= MP_NOPTS_VALUE
)
1822 // Good, decoder supports new way of calculating audio pts.
1823 // sh_audio->pts is the timestamp of the latest input packet with
1824 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1825 // the amount of bytes the decoder has written after that timestamp.
1826 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1828 // Decoder doesn't support new way of calculating pts (or we're
1829 // being called before it has decoded anything with known timestamp).
1830 // Use the old method of audio pts calculation: take the timestamp
1831 // of last packet with known pts the decoder has read data from,
1832 // and add amount of bytes read after the beginning of that packet
1833 // divided by input bps. This will be inaccurate if the input/output
1834 // ratio is not constant for every audio packet or if it is constant
1835 // but not accurately known in sh_audio->i_bps.
1837 a_pts
= d_audio
->pts
;
1838 // ds_tell_pts returns bytes read after last timestamp from
1839 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1840 // it has read but not decoded
1841 if (sh_audio
->i_bps
)
1842 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1843 (double)sh_audio
->i_bps
;
1845 // Now a_pts hopefully holds the pts for end of audio from decoder.
1846 // Substract data in buffers between decoder and audio out.
1848 // Decoded but not filtered
1849 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1851 // Data buffered in audio filters, measured in bytes of "missing" output
1852 buffered_output
= af_calc_delay(sh_audio
->afilter
);
1854 // Data that was ready for ao but was buffered because ao didn't fully
1855 // accept everything to internal buffers yet
1856 buffered_output
+= sh_audio
->a_out_buffer_len
;
1858 // Filters divide audio length by playback_speed, so multiply by it
1859 // to get the length in original units without speedup or slowdown
1860 a_pts
-= buffered_output
* mpctx
->opts
.playback_speed
/ ao_data
.bps
;
1862 return a_pts
+ mpctx
->video_offset
;
1865 // Return pts value corresponding to currently playing audio.
1866 double playing_audio_pts(struct MPContext
*mpctx
)
1868 return written_audio_pts(mpctx
) - mpctx
->opts
.playback_speed
*
1869 mpctx
->audio_out
->get_delay();
1872 static int check_framedrop(struct MPContext
*mpctx
, double frame_time
) {
1873 struct MPOpts
*opts
= &mpctx
->opts
;
1874 // check for frame-drop:
1875 current_module
= "check_framedrop";
1876 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1877 static int dropped_frames
;
1878 float delay
= opts
->playback_speed
*mpctx
->audio_out
->get_delay();
1879 float d
= delay
-mpctx
->delay
;
1881 // we should avoid dropping too many frames in sequence unless we
1882 // are too late. and we allow 100ms A-V delay here:
1883 if (d
< -dropped_frames
*frame_time
-0.100 && !mpctx
->paused
1884 && !mpctx
->update_video_immediately
) {
1887 return frame_dropping
;
1899 static float timing_sleep(struct MPContext
*mpctx
, float time_frame
)
1903 // -------- RTC -----------
1904 current_module
="sleep_rtc";
1905 while (time_frame
> 0.000) {
1906 unsigned long rtc_ts
;
1907 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1908 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC read error: %s\n", strerror(errno
));
1909 time_frame
-= get_relative_time(mpctx
);
1914 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1915 // unnecessarily high CPU usage
1916 float margin
= softsleep
? 0.011 : 0;
1917 current_module
= "sleep_timer";
1918 while (time_frame
> margin
) {
1919 usec_sleep(1000000 * (time_frame
- margin
));
1920 time_frame
-= get_relative_time(mpctx
);
1923 current_module
= "sleep_soft";
1925 mp_tmsg(MSGT_AVSYNC
, MSGL_WARN
, "Warning! Softsleep underflow!\n");
1926 while (time_frame
> 0)
1927 time_frame
-= get_relative_time(mpctx
); // burn the CPU
1933 static int select_subtitle(MPContext
*mpctx
)
1935 struct MPOpts
*opts
= &mpctx
->opts
;
1936 // find the best sub to use
1939 mpctx
->global_sub_pos
= -1; // no subs by default
1940 if (vobsub_id
>= 0) {
1941 // if user asks for a vobsub id, use that first.
1943 found
= mp_property_do("sub_vob", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1946 if (!found
&& opts
->sub_id
>= 0) {
1947 // if user asks for a dvd sub id, use that next.
1949 found
= mp_property_do("sub_demux", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1953 // if there are text subs to use, use those. (autosubs come last here)
1955 found
= mp_property_do("sub_file", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1958 if (!found
&& opts
->sub_id
== -1) {
1959 // finally select subs by language and container hints
1960 if (opts
->sub_id
== -1 && opts
->sub_lang
)
1961 opts
->sub_id
= demuxer_sub_track_by_lang(mpctx
->d_sub
->demuxer
,
1963 if (opts
->sub_id
== -1)
1964 opts
->sub_id
= demuxer_default_sub_track(mpctx
->d_sub
->demuxer
);
1965 if (opts
->sub_id
>= 0) {
1967 found
= mp_property_do("sub_demux", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1973 #ifdef CONFIG_DVDNAV
1977 /// store decoded video image
1978 static mp_image_t
* mp_dvdnav_copy_mpi(mp_image_t
*to_mpi
,
1979 mp_image_t
*from_mpi
) {
1982 /// Do not store B-frames
1983 if (from_mpi
->pict_type
== FF_B_TYPE
)
1987 to_mpi
->w
== from_mpi
->w
&&
1988 to_mpi
->h
== from_mpi
->h
&&
1989 to_mpi
->imgfmt
== from_mpi
->imgfmt
)
1993 free_mp_image(to_mpi
);
1994 if (from_mpi
->w
== 0 || from_mpi
->h
== 0)
1996 mpi
= alloc_mpi(from_mpi
->w
,from_mpi
->h
,from_mpi
->imgfmt
);
1999 copy_mpi(mpi
,from_mpi
);
2003 static void mp_dvdnav_reset_stream (MPContext
*ctx
) {
2004 struct MPOpts
*opts
= &ctx
->opts
;
2005 if (ctx
->sh_video
) {
2007 ctx
->d_video
->pts
= 0.0f
;
2008 ctx
->sh_video
->pts
= 0.0f
;
2009 ctx
->sh_video
->i_pts
= 0.0f
;
2010 ctx
->sh_video
->last_pts
= 0.0f
;
2011 ctx
->sh_video
->num_buffered_pts
= 0;
2012 ctx
->sh_video
->num_frames
= 0;
2013 ctx
->sh_video
->num_frames_decoded
= 0;
2014 ctx
->sh_video
->timer
= 0.0f
;
2015 ctx
->sh_video
->stream_delay
= 0.0f
;
2016 ctx
->sh_video
->timer
= 0;
2017 ctx
->demuxer
->stream_pts
= MP_NOPTS_VALUE
;
2020 if (ctx
->sh_audio
) {
2021 /// free audio packets and reset
2022 ds_free_packs(ctx
->d_audio
);
2023 audio_delay
-= ctx
->sh_audio
->stream_delay
;
2024 ctx
->delay
=- audio_delay
;
2025 ctx
->audio_out
->reset();
2026 resync_audio_stream(ctx
->sh_audio
);
2030 ctx
->sub_counts
[SUB_SOURCE_DEMUX
] = mp_dvdnav_number_of_subs(ctx
->stream
);
2031 if (opts
->sub_lang
&& opts
->sub_id
== dvdsub_lang_id
) {
2032 dvdsub_lang_id
= mp_dvdnav_sid_from_lang(ctx
->stream
, opts
->sub_lang
);
2033 if (dvdsub_lang_id
!= opts
->sub_id
) {
2034 opts
->sub_id
= dvdsub_lang_id
;
2035 select_subtitle(ctx
);
2039 /// clear all EOF related flags
2040 ctx
->d_video
->eof
= ctx
->d_audio
->eof
= ctx
->stream
->eof
= 0;
2043 /// Restore last decoded DVDNAV (still frame)
2044 static mp_image_t
*mp_dvdnav_restore_smpi(struct MPContext
*mpctx
,
2046 unsigned char **start
,
2047 mp_image_t
*decoded_frame
)
2049 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
2050 return decoded_frame
;
2052 /// a change occured in dvdnav stream
2053 if (mp_dvdnav_cell_has_changed(mpctx
->stream
,0)) {
2054 mp_dvdnav_read_wait(mpctx
->stream
, 1, 1);
2055 mp_dvdnav_context_free(mpctx
);
2056 mp_dvdnav_reset_stream(mpctx
);
2057 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
2058 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
2064 /// Display still frame, if any
2065 if (mpctx
->nav_smpi
&& !mpctx
->nav_buffer
)
2066 decoded_frame
= mpctx
->nav_smpi
;
2068 /// increment video frame : continue playing after still frame
2069 len
= get_time_length(mpctx
);
2070 if (mpctx
->sh_video
->pts
>= len
&&
2071 mpctx
->sh_video
->pts
> 0.0 && len
> 0.0) {
2072 mp_dvdnav_skip_still(mpctx
->stream
);
2073 mp_dvdnav_skip_wait(mpctx
->stream
);
2075 mpctx
->sh_video
->pts
+= 1 / mpctx
->sh_video
->fps
;
2077 if (mpctx
->nav_buffer
) {
2078 *start
= mpctx
->nav_start
;
2079 *in_size
= mpctx
->nav_in_size
;
2080 if (mpctx
->nav_start
)
2081 memcpy(*start
,mpctx
->nav_buffer
,mpctx
->nav_in_size
);
2085 return decoded_frame
;
2088 /// Save last decoded DVDNAV (still frame)
2089 static void mp_dvdnav_save_smpi(struct MPContext
*mpctx
, int in_size
,
2090 unsigned char *start
,
2091 mp_image_t
*decoded_frame
)
2093 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
2096 free(mpctx
->nav_buffer
);
2098 mpctx
->nav_buffer
= malloc(in_size
);
2099 mpctx
->nav_start
= start
;
2100 mpctx
->nav_in_size
= mpctx
->nav_buffer
? in_size
: -1;
2101 if (mpctx
->nav_buffer
)
2102 memcpy(mpctx
->nav_buffer
,start
,in_size
);
2104 if (decoded_frame
&& mpctx
->nav_smpi
!= decoded_frame
)
2105 mpctx
->nav_smpi
= mp_dvdnav_copy_mpi(mpctx
->nav_smpi
,decoded_frame
);
2107 #endif /* CONFIG_DVDNAV */
2109 /* Modify video timing to match the audio timeline. There are two main
2110 * reasons this is needed. First, video and audio can start from different
2111 * positions at beginning of file or after a seek (MPlayer starts both
2112 * immediately even if they have different pts). Second, the file can have
2113 * audio timestamps that are inconsistent with the duration of the audio
2114 * packets, for example two consecutive timestamp values differing by
2115 * one second but only a packet with enough samples for half a second
2116 * of playback between them.
2118 static void adjust_sync(struct MPContext
*mpctx
, double frame_time
)
2120 current_module
= "av_sync";
2122 if (!mpctx
->sh_audio
)
2125 double a_pts
= written_audio_pts(mpctx
) - mpctx
->delay
;
2126 double v_pts
= mpctx
->sh_video
->pts
;
2127 double av_delay
= a_pts
- v_pts
;
2128 // Try to sync vo_flip() so it will *finish* at given time
2129 av_delay
+= mpctx
->last_vo_flip_duration
;
2130 av_delay
-= audio_delay
; // This much pts difference is desired
2132 double change
= av_delay
* 0.1;
2133 double max_change
= default_max_pts_correction
>= 0 ?
2134 default_max_pts_correction
: frame_time
* 0.1;
2135 if (change
< -max_change
)
2136 change
= -max_change
;
2137 else if (change
> max_change
)
2138 change
= max_change
;
2139 mpctx
->delay
+= change
;
2140 mpctx
->total_avsync_change
+= change
;
2143 static int fill_audio_out_buffers(struct MPContext
*mpctx
)
2145 struct MPOpts
*opts
= &mpctx
->opts
;
2151 bool format_change
= false;
2152 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
2154 current_module
="play_audio";
2158 // all the current uses of ao_data.pts seem to be in aos that handle
2159 // sync completely wrong; there should be no need to use ao_data.pts
2161 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2162 playsize
= mpctx
->audio_out
->get_space();
2163 if (mpctx
->sh_video
|| playsize
>= ao_data
.outburst
)
2166 // handle audio-only case:
2167 // this is where mplayer sleeps during audio-only playback
2168 // to avoid 100% CPU use
2169 sleep_time
= (ao_data
.outburst
- playsize
) * 1000 / ao_data
.bps
;
2170 if (sleep_time
< 10) sleep_time
= 10; // limit to 100 wakeups per second
2171 usec_sleep(sleep_time
* 1000);
2174 // Fill buffer if needed:
2175 current_module
="decode_audio";
2177 int res
= decode_audio(sh_audio
, playsize
);
2178 if (res
< 0) { // EOF, error or format change
2180 format_change
= true;
2181 else if (mpctx
->d_audio
->eof
) {
2183 if (sh_audio
->a_out_buffer_len
== 0)
2188 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2189 if (playsize
> sh_audio
->a_out_buffer_len
) {
2190 playsize
= sh_audio
->a_out_buffer_len
;
2192 playflags
|= AOPLAY_FINAL_CHUNK
;
2198 current_module
="play_audio";
2200 // Is this pts value actually useful for the aos that access it?
2201 // They're obviously badly broken in the way they handle av sync;
2202 // would not having access to this make them more broken?
2203 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2204 playsize
= mpctx
->audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
2207 sh_audio
->a_out_buffer_len
-= playsize
;
2208 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
2209 sh_audio
->a_out_buffer_len
);
2210 mpctx
->delay
+= opts
->playback_speed
*playsize
/(double)ao_data
.bps
;
2212 else if (audio_eof
&& mpctx
->audio_out
->get_delay() < .04) {
2213 // Sanity check to avoid hanging in case current ao doesn't output
2214 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
2215 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
2216 sh_audio
->a_out_buffer_len
= 0;
2219 /* The format change isn't handled too gracefully. A more precise
2220 * implementation would require draining buffered old-format audio
2221 * while displaying video, then doing the output format switch.
2223 if (format_change
) {
2224 uninit_player(mpctx
, INITIALIZED_AO
);
2225 reinit_audio_chain(mpctx
);
2231 static int sleep_until_update(struct MPContext
*mpctx
, float *time_frame
,
2232 float *aq_sleep_time
)
2234 struct MPOpts
*opts
= &mpctx
->opts
;
2235 int frame_time_remaining
= 0;
2236 current_module
="calc_sleep_time";
2238 *time_frame
-= get_relative_time(mpctx
); // reset timer
2240 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
2241 float delay
= mpctx
->audio_out
->get_delay();
2242 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
2246 * Adjust this raw delay value by calculating the expected
2247 * delay for this frame and generating a new value which is
2248 * weighted between the two. The higher autosync is, the
2249 * closer to the delay value gets to that which "-nosound"
2250 * would have used, and the longer it will take for A/V
2251 * sync to settle at the right value (but it eventually will.)
2252 * This settling time is very short for values below 100.
2254 float predicted
= mpctx
->delay
/ opts
->playback_speed
+ *time_frame
;
2255 float difference
= delay
- predicted
;
2256 delay
= predicted
+ difference
/ (float)autosync
;
2259 *time_frame
= delay
- mpctx
->delay
/ opts
->playback_speed
;
2260 *time_frame
-= mpctx
->video_out
->flip_queue_offset
;
2262 // delay = amount of audio buffered in soundcard/driver
2263 if (delay
> 0.25) delay
=0.25; else
2264 if (delay
< 0.10) delay
=0.10;
2266 if (*time_frame
> delay
*0.6) {
2267 // sleep time too big - may cause audio drops (buffer underrun)
2268 frame_time_remaining
= 1;
2269 *time_frame
= delay
*0.5;
2272 // If we're lagging more than 200 ms behind the right playback rate,
2273 // don't try to "catch up".
2274 // If benchmark is set always output frames as fast as possible
2275 // without sleeping.
2276 if (*time_frame
< -0.2 || benchmark
)
2278 *time_frame
-= mpctx
->video_out
->flip_queue_offset
;
2281 *aq_sleep_time
+= *time_frame
;
2284 //============================== SLEEP: ===================================
2286 // flag 256 means: libvo driver does its timing (dvb card)
2287 if (*time_frame
> 0.001 && !(mpctx
->sh_video
->output_flags
&256))
2288 *time_frame
= timing_sleep(mpctx
, *time_frame
);
2289 *time_frame
+= mpctx
->video_out
->flip_queue_offset
;
2290 return frame_time_remaining
;
2293 int reinit_video_chain(struct MPContext
*mpctx
)
2295 struct MPOpts
*opts
= &mpctx
->opts
;
2296 sh_video_t
* const sh_video
= mpctx
->sh_video
;
2298 //================== Init VIDEO (codec & libvo) ==========================
2299 if (!opts
->fixed_vo
|| !(mpctx
->initialized_flags
& INITIALIZED_VO
)) {
2300 current_module
="preinit_libvo";
2302 //shouldn't we set dvideo->id=-2 when we fail?
2303 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
2304 if(!(mpctx
->video_out
=init_best_video_out(opts
, mpctx
->x11_state
, mpctx
->key_fifo
, mpctx
->input
))){
2305 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Error opening/initializing the selected video_out (-vo) device.\n");
2308 mpctx
->initialized_flags
|=INITIALIZED_VO
;
2311 if(stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_ASPECT_RATIO
, &ar
) != STREAM_UNSUPPORTED
)
2312 mpctx
->sh_video
->stream_aspect
= ar
;
2313 current_module
="init_video_filters";
2315 char* vf_arg
[] = { "_oldargs_", (char*)mpctx
->video_out
, NULL
};
2316 sh_video
->vfilter
= vf_open_filter(opts
, NULL
,"vo",vf_arg
);
2320 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
2321 vf_menu
= vf_open_plugin(opts
,libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
2323 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Can't open libmenu video filter with root menu %s.\n",menu_root
);
2328 sh_video
->vfilter
= vf_menu
;
2332 if(opts
->ass_enabled
) {
2335 if (opts
->vf_settings
)
2336 for (i
= 0; opts
->vf_settings
[i
].name
; ++i
)
2337 if (strcmp(opts
->vf_settings
[i
].name
, "ass") == 0) {
2342 extern vf_info_t vf_info_ass
;
2343 const vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
2344 char* vf_arg
[] = {"auto", "1", NULL
};
2346 struct vf_instance
*vf_ass
= vf_open_plugin_noerr(opts
, libass_vfs
,
2351 sh_video
->vfilter
= vf_ass
;
2352 else if (retcode
== -1) // vf_ass open() returns -1 if there's VO EOSD
2353 mp_msg(MSGT_CPLAYER
, MSGL_V
, "[ass] vf_ass not needed\n");
2355 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
2360 sh_video
->vfilter
= append_filters(sh_video
->vfilter
, opts
->vf_settings
);
2363 if (opts
->ass_enabled
)
2364 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
2367 current_module
="init_video_codec";
2369 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2370 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
2371 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2373 if(!sh_video
->initialized
){
2374 if(!opts
->fixed_vo
) uninit_player(mpctx
, INITIALIZED_VO
);
2378 mpctx
->initialized_flags
|=INITIALIZED_VCODEC
;
2380 if (sh_video
->codec
)
2381 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
2383 sh_video
->last_pts
= MP_NOPTS_VALUE
;
2384 sh_video
->num_buffered_pts
= 0;
2385 sh_video
->next_frame_time
= 0;
2388 // Auto quality option enabled
2389 output_quality
=get_video_quality_max(sh_video
);
2390 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
2391 else output_quality
=auto_quality
;
2392 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
2393 set_video_quality(sh_video
,output_quality
);
2396 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2398 current_module
="init_vo";
2403 mpctx
->sh_video
= mpctx
->d_video
->sh
= NULL
;
2407 static double update_video_nocorrect_pts(struct MPContext
*mpctx
)
2409 struct sh_video
*sh_video
= mpctx
->sh_video
;
2410 double frame_time
= 0;
2411 struct vo
*video_out
= mpctx
->video_out
;
2412 while (!video_out
->frame_loaded
) {
2413 current_module
= "filter_video";
2414 // In nocorrect-pts mode there is no way to properly time these frames
2415 if (vo_get_buffered_frame(video_out
, 0) >= 0)
2417 if (vf_output_queued_frame(sh_video
->vfilter
))
2419 unsigned char *packet
= NULL
;
2420 frame_time
= sh_video
->next_frame_time
;
2421 if (mpctx
->update_video_immediately
)
2423 int in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2424 &packet
, force_fps
);
2426 #ifdef CONFIG_DVDNAV
2427 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
2428 if (mp_dvdnav_is_eof(mpctx
->stream
))
2431 mpctx
->d_video
->eof
= 0;
2433 mpctx
->d_audio
->eof
= 0;
2434 mpctx
->stream
->eof
= 0;
2439 if (in_size
> max_framesize
)
2440 max_framesize
= in_size
;
2441 sh_video
->timer
+= frame_time
;
2442 if (mpctx
->sh_audio
)
2443 mpctx
->delay
-= frame_time
;
2444 // video_read_frame can change fps (e.g. for ASF video)
2445 vo_fps
= sh_video
->fps
;
2446 int framedrop_type
= check_framedrop(mpctx
, frame_time
);
2447 current_module
= "decode video";
2449 void *decoded_frame
;
2450 #ifdef CONFIG_DVDNAV
2451 decoded_frame
= mp_dvdnav_restore_smpi(mpctx
, &in_size
, &packet
, NULL
);
2452 if (in_size
>= 0 && !decoded_frame
)
2454 decoded_frame
= decode_video(sh_video
, packet
, in_size
, framedrop_type
,
2456 #ifdef CONFIG_DVDNAV
2457 // Save last still frame for future display
2458 mp_dvdnav_save_smpi(mpctx
, in_size
, packet
, decoded_frame
);
2460 if (decoded_frame
) {
2461 current_module
= "filter video";
2462 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2463 if (!video_out
->config_ok
)
2470 static void determine_frame_pts(struct MPContext
*mpctx
)
2472 struct sh_video
*sh_video
= mpctx
->sh_video
;
2473 struct MPOpts
*opts
= &mpctx
->opts
;
2475 if (opts
->user_pts_assoc_mode
) {
2476 sh_video
->pts_assoc_mode
= opts
->user_pts_assoc_mode
;
2477 } else if (sh_video
->pts_assoc_mode
== 0) {
2478 if (sh_video
->codec_reordered_pts
!= MP_NOPTS_VALUE
)
2479 sh_video
->pts_assoc_mode
= 1;
2481 sh_video
->pts_assoc_mode
= 2;
2483 int probcount1
= sh_video
->num_reordered_pts_problems
;
2484 int probcount2
= sh_video
->num_sorted_pts_problems
;
2485 if (sh_video
->pts_assoc_mode
== 2) {
2486 int tmp
= probcount1
;
2487 probcount1
= probcount2
;
2490 if (probcount1
>= probcount2
* 1.5 + 2) {
2491 sh_video
->pts_assoc_mode
= 3 - sh_video
->pts_assoc_mode
;
2492 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Switching to pts association mode "
2493 "%d.\n", sh_video
->pts_assoc_mode
);
2496 sh_video
->pts
= sh_video
->pts_assoc_mode
== 1 ?
2497 sh_video
->codec_reordered_pts
: sh_video
->sorted_pts
;
2500 static double update_video(struct MPContext
*mpctx
)
2502 struct sh_video
*sh_video
= mpctx
->sh_video
;
2503 struct vo
*video_out
= mpctx
->video_out
;
2504 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_SET_OSD_OBJ
,
2505 mpctx
->osd
); // hack for vf_expand
2506 if (!mpctx
->opts
.correct_pts
)
2507 return update_video_nocorrect_pts(mpctx
);
2511 bool hit_eof
= false;
2512 while (!video_out
->frame_loaded
) {
2513 current_module
= "filter_video";
2514 if (vo_get_buffered_frame(video_out
, hit_eof
) >= 0)
2516 // XXX Time used in this call is not counted in any performance
2517 // timer now, OSD time is not updated correctly for filter-added frames
2518 if (vf_output_queued_frame(sh_video
->vfilter
))
2522 unsigned char *packet
= NULL
;
2523 int in_size
= ds_get_packet_pts(mpctx
->d_video
, &packet
, &pts
);
2524 if (pts
!= MP_NOPTS_VALUE
)
2525 pts
+= mpctx
->video_offset
;
2527 // try to extract last frames in case of decoder lag
2529 pts
= MP_NOPTS_VALUE
;
2532 if (in_size
> max_framesize
)
2533 max_framesize
= in_size
;
2534 current_module
= "decode video";
2535 int framedrop_type
= check_framedrop(mpctx
, sh_video
->frametime
);
2536 void *decoded_frame
= decode_video(sh_video
, packet
, in_size
,
2537 framedrop_type
, pts
);
2538 if (decoded_frame
) {
2539 determine_frame_pts(mpctx
);
2540 current_module
= "filter video";
2541 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2542 if (!video_out
->config_ok
)
2543 break; // We'd likely hang in this loop otherwise
2547 pts
= video_out
->next_pts
;
2548 if (pts
== MP_NOPTS_VALUE
) {
2549 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Video pts after filters MISSING\n");
2550 // Try to use decoder pts from before filters
2551 pts
= sh_video
->pts
;
2552 if (pts
== MP_NOPTS_VALUE
)
2553 pts
= sh_video
->last_pts
;
2555 sh_video
->pts
= pts
;
2556 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2557 sh_video
->last_pts
= sh_video
->pts
;
2558 else if (sh_video
->last_pts
> sh_video
->pts
) {
2559 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Decreasing video pts: %f < %f\n",
2560 sh_video
->pts
, sh_video
->last_pts
);
2561 /* If the difference in pts is small treat it as jitter around the
2562 * right value (possibly caused by incorrect timestamp ordering) and
2563 * just show this frame immediately after the last one.
2564 * Treat bigger differences as timestamp resets and start counting
2565 * timing of later frames from the position of this one. */
2566 if (sh_video
->last_pts
- sh_video
->pts
> 0.5)
2567 sh_video
->last_pts
= sh_video
->pts
;
2569 sh_video
->pts
= sh_video
->last_pts
;
2571 double frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2572 sh_video
->last_pts
= sh_video
->pts
;
2573 sh_video
->timer
+= frame_time
;
2574 if (mpctx
->sh_audio
)
2575 mpctx
->delay
-= frame_time
;
2579 void pause_player(struct MPContext
*mpctx
)
2584 mpctx
->step_frames
= 0;
2585 mpctx
->time_frame
-= get_relative_time(mpctx
);
2587 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2588 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2590 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2591 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2594 void unpause_player(struct MPContext
*mpctx
)
2600 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2601 mpctx
->audio_out
->resume(); // resume audio
2602 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
2603 && !mpctx
->step_frames
)
2604 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
); // resume video
2605 (void)get_relative_time(mpctx
); // ignore time that passed during pause
2608 void add_step_frame(struct MPContext
*mpctx
)
2610 mpctx
->step_frames
++;
2611 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2612 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2613 unpause_player(mpctx
);
2616 static void pause_loop(struct MPContext
*mpctx
)
2620 // Small hack to display the pause message on the OSD line.
2621 // The pause string is: "\n == PAUSE == \r" so we need to
2622 // take the first and the last char out
2623 if (term_osd
&& !mpctx
->sh_video
) {
2624 char msg
[128] = _("\n ===== PAUSE =====\r");
2625 int mlen
= strlen(msg
);
2627 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2628 update_osd_msg(mpctx
);
2630 mp_tmsg(MSGT_CPLAYER
,MSGL_STATUS
,"\n ===== PAUSE =====\r");
2631 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2634 while ( (cmd
= mp_input_get_cmd(mpctx
->input
, 20, 1)) == NULL
2635 || cmd
->id
== MP_CMD_SET_MOUSE_POS
|| cmd
->pausing
== 4) {
2637 cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0);
2638 run_command(mpctx
, cmd
);
2642 if (mpctx
->sh_video
&& mpctx
->video_out
)
2643 vo_check_events(mpctx
->video_out
);
2646 vf_menu_pause_update(vf_menu
);
2649 update_osd_msg(mpctx
);
2650 int hack
= vo_osd_changed(0);
2651 vo_osd_changed(hack
);
2658 // Find the right mute status and record position for new file position
2659 static void edl_seek_reset(MPContext
*mpctx
)
2661 mpctx
->edl_muted
= 0;
2662 next_edl_record
= edl_records
;
2664 while (next_edl_record
) {
2665 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2668 if (next_edl_record
->action
== EDL_MUTE
)
2669 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2670 next_edl_record
= next_edl_record
->next
;
2672 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2673 mixer_mute(&mpctx
->mixer
);
2677 // Execute EDL command for the current position if one exists
2678 static void edl_update(MPContext
*mpctx
)
2680 if (!next_edl_record
)
2683 if (!mpctx
->sh_video
) {
2684 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Cannot use EDL without video, disabling.\n");
2685 free_edl(edl_records
);
2686 next_edl_record
= NULL
;
2691 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2692 if (next_edl_record
->action
== EDL_SKIP
) {
2693 mpctx
->osd_function
= OSD_FFW
;
2694 mpctx
->abs_seek_pos
= 0;
2695 mpctx
->rel_seek_secs
= next_edl_record
->length_sec
;
2696 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2697 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2698 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2700 else if (next_edl_record
->action
== EDL_MUTE
) {
2701 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2702 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2703 mixer_mute(&mpctx
->mixer
);
2704 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2705 next_edl_record
->start_sec
);
2707 next_edl_record
= next_edl_record
->next
;
2711 static void reinit_decoders(struct MPContext
*mpctx
)
2713 reinit_video_chain(mpctx
);
2714 reinit_audio_chain(mpctx
);
2715 mp_property_do("sub", M_PROPERTY_SET
, &mpctx
->global_sub_pos
, mpctx
);
2718 static void seek_reset(struct MPContext
*mpctx
)
2720 if (mpctx
->sh_video
) {
2721 current_module
= "seek_video_reset";
2722 resync_video_stream(mpctx
->sh_video
);
2723 mpctx
->sh_video
->timer
= 0;
2724 vo_seek_reset(mpctx
->video_out
);
2725 mpctx
->sh_video
->timer
= 0;
2726 mpctx
->sh_video
->num_buffered_pts
= 0;
2727 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2729 mpctx
->time_frame
= 0;
2730 mpctx
->update_video_immediately
= true;
2731 // Not all demuxers set d_video->pts during seek, so this value
2732 // (which is used by at least vobsub and edl code below) may
2733 // be completely wrong (probably 0).
2734 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
+ mpctx
->video_offset
;
2735 update_subtitles(mpctx
, &mpctx
->opts
, mpctx
->sh_video
,
2736 mpctx
->sh_video
->pts
, mpctx
->video_offset
,
2738 update_teletext(mpctx
->sh_video
, mpctx
->demuxer
, 1);
2741 if (mpctx
->sh_audio
) {
2742 current_module
= "seek_audio_reset";
2743 resync_audio_stream(mpctx
->sh_audio
);
2744 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2745 mpctx
->sh_audio
->a_buffer_len
= 0;
2746 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2747 if (!mpctx
->sh_video
)
2748 update_subtitles(mpctx
, &mpctx
->opts
, NULL
, mpctx
->sh_audio
->pts
,
2749 mpctx
->video_offset
, mpctx
->d_sub
, 1);
2752 if (vo_vobsub
&& mpctx
->sh_video
) {
2753 current_module
= "seek_vobsub_reset";
2754 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2757 edl_seek_reset(mpctx
);
2759 mpctx
->total_avsync_change
= 0;
2760 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2763 current_module
= NULL
;
2766 static bool timeline_set_part(struct MPContext
*mpctx
, int i
)
2768 struct timeline_part
*p
= mpctx
->timeline
+ mpctx
->timeline_part
;
2769 struct timeline_part
*n
= mpctx
->timeline
+ i
;
2770 mpctx
->timeline_part
= i
;
2771 mpctx
->video_offset
= n
->start
- n
->source_start
;
2772 if (n
->source
== p
->source
)
2774 uninit_player(mpctx
, INITIALIZED_VCODEC
| (mpctx
->opts
.fixed_vo
&& mpctx
->opts
.video_id
!= -2 ? 0 : INITIALIZED_VO
) | INITIALIZED_AO
| INITIALIZED_ACODEC
);
2775 mpctx
->demuxer
= n
->source
->demuxer
;
2776 mpctx
->d_video
= mpctx
->demuxer
->video
;
2777 mpctx
->d_audio
= mpctx
->demuxer
->audio
;
2778 mpctx
->d_sub
= mpctx
->demuxer
->sub
;
2779 mpctx
->sh_video
= mpctx
->d_video
->sh
;
2780 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
2784 // Given pts, switch playback to the corresponding part.
2785 // Return offset within that part.
2786 static double timeline_set_from_time(struct MPContext
*mpctx
, double pts
,
2791 for (int i
= 0; i
< mpctx
->num_timeline_parts
; i
++) {
2792 struct timeline_part
*p
= mpctx
->timeline
+ i
;
2793 if (pts
< (p
+1)->start
) {
2794 *need_reset
= timeline_set_part(mpctx
, i
);
2795 return pts
- p
->start
+ p
->source_start
;
2802 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute
2803 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length
2804 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2805 static int seek(MPContext
*mpctx
, double amount
, int style
)
2807 current_module
= "seek";
2808 if (mpctx
->stop_play
== AT_END_OF_FILE
)
2809 mpctx
->stop_play
= KEEP_PLAYING
;
2810 if (style
& SEEK_FACTOR
2811 || style
& SEEK_ABSOLUTE
&& amount
< mpctx
->last_chapter_pts
2813 mpctx
->last_chapter_seek
= -1;
2814 if (mpctx
->timeline
&& style
& SEEK_FACTOR
) {
2815 amount
*= mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
2816 style
&= ~SEEK_FACTOR
;
2818 if ((mpctx
->demuxer
->accurate_seek
|| mpctx
->timeline
) && mpctx
->sh_video
2819 && !(style
& (SEEK_ABSOLUTE
| SEEK_FACTOR
))) {
2820 style
|= SEEK_ABSOLUTE
;
2822 style
|= SEEK_FORWARD
;
2824 style
|= SEEK_BACKWARD
;
2825 amount
+= mpctx
->sh_video
->pts
;
2828 /* At least the liba52 decoder wants to read from the input stream
2829 * during initialization, so reinit must be done after the demux_seek()
2830 * call that clears possible stream EOF. */
2831 bool need_reset
= false;
2832 if (mpctx
->timeline
) {
2833 amount
= timeline_set_from_time(mpctx
, amount
, &need_reset
);
2835 mpctx
->stop_play
= AT_END_OF_FILE
;
2836 // Clear audio from current position
2837 if (mpctx
->sh_audio
) {
2838 mpctx
->audio_out
->reset();
2839 mpctx
->sh_audio
->a_buffer_len
= 0;
2840 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2845 int seekresult
= demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
);
2847 reinit_decoders(mpctx
);
2848 if (seekresult
== 0)
2856 double get_time_length(struct MPContext
*mpctx
)
2858 if (mpctx
->timeline
)
2859 return mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
2861 struct demuxer
*demuxer
= mpctx
->demuxer
;
2862 double get_time_ans
;
2863 // <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW
2864 if (demux_control(demuxer
, DEMUXER_CTRL_GET_TIME_LENGTH
,
2865 (void *) &get_time_ans
) > 0)
2866 return get_time_ans
;
2868 struct sh_video
*sh_video
= mpctx
->d_video
->sh
;
2869 struct sh_audio
*sh_audio
= mpctx
->d_audio
->sh
;
2870 if (sh_video
&& sh_video
->i_bps
&& sh_audio
&& sh_audio
->i_bps
)
2871 return (double) (demuxer
->movi_end
- demuxer
->movi_start
) /
2872 (sh_video
->i_bps
+ sh_audio
->i_bps
);
2873 if (sh_video
&& sh_video
->i_bps
)
2874 return (double) (demuxer
->movi_end
- demuxer
->movi_start
) /
2876 if (sh_audio
&& sh_audio
->i_bps
)
2877 return (double) (demuxer
->movi_end
- demuxer
->movi_start
) /
2882 /* If there are timestamps from stream level then use those (for example
2883 * DVDs can have consistent times there while the MPEG-level timestamps
2885 double get_current_time(struct MPContext
*mpctx
)
2887 struct demuxer
*demuxer
= mpctx
->demuxer
;
2888 if (demuxer
->stream_pts
!= MP_NOPTS_VALUE
)
2889 return demuxer
->stream_pts
;
2890 struct sh_video
*sh_video
= demuxer
->video
->sh
;
2892 return sh_video
->pts
;
2893 return playing_audio_pts(mpctx
);
2896 int get_percent_pos(struct MPContext
*mpctx
)
2898 struct demuxer
*demuxer
= mpctx
->demuxer
;
2900 if (mpctx
->timeline
)
2901 ans
= get_current_time(mpctx
) * 100 /
2902 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
2903 else if (demux_control(demuxer
, DEMUXER_CTRL_GET_PERCENT_POS
, &ans
) > 0)
2906 int len
= (demuxer
->movi_end
- demuxer
->movi_start
) / 100;
2907 off_t pos
= demuxer
->filepos
> 0 ?
2908 demuxer
->filepos
: stream_tell(demuxer
->stream
);
2910 ans
= (pos
- demuxer
->movi_start
) / len
;
2921 // -2 is no chapters, -1 is before first chapter
2922 int get_current_chapter(struct MPContext
*mpctx
)
2924 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2925 return FFMAX(mpctx
->last_chapter_seek
,
2926 demuxer_get_current_chapter(mpctx
->demuxer
));
2929 double current_pts
= mpctx
->sh_video
->pts
;
2930 for (i
= 1; i
< mpctx
->num_chapters
; i
++)
2931 if (current_pts
< mpctx
->chapters
[i
].start
)
2933 return FFMAX(mpctx
->last_chapter_seek
, i
- 1);
2936 // currently returns a string allocated with malloc, not talloc
2937 char *chapter_display_name(struct MPContext
*mpctx
, int chapter
)
2939 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2940 return demuxer_chapter_display_name(mpctx
->demuxer
, chapter
);
2941 return strdup(mpctx
->chapters
[chapter
].name
);
2944 int seek_chapter(struct MPContext
*mpctx
, int chapter
, double *seek_pts
,
2945 char **chapter_name
)
2947 mpctx
->last_chapter_seek
= -1;
2948 if (!mpctx
->chapters
|| !mpctx
->sh_video
) {
2949 int res
= demuxer_seek_chapter(mpctx
->demuxer
, chapter
, seek_pts
,
2952 if (*seek_pts
== -1)
2955 mpctx
->last_chapter_seek
= res
;
2956 mpctx
->last_chapter_pts
= *seek_pts
;
2962 if (chapter
>= mpctx
->num_chapters
)
2966 *seek_pts
= mpctx
->chapters
[chapter
].start
;
2967 mpctx
->last_chapter_seek
= chapter
;
2968 mpctx
->last_chapter_pts
= *seek_pts
;
2970 *chapter_name
= talloc_strdup(NULL
, mpctx
->chapters
[chapter
].name
);
2974 static int find_ordered_chapter_sources(struct MPContext
*mpctx
,
2975 struct content_source
*sources
,
2977 unsigned char uid_map
[][16])
2979 int num_filenames
= 0;
2980 char **filenames
= NULL
;
2981 if (num_sources
> 1) {
2982 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "This file references data from "
2983 "other sources.\n");
2984 if (mpctx
->stream
->type
!= STREAMTYPE_FILE
) {
2985 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Playback source is not a "
2986 "normal disk file. Will not search for related files.\n");
2988 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Will scan other files in the "
2989 "same directory to find referenced sources.\n");
2990 filenames
= find_files(mpctx
->demuxer
->filename
, ".mkv",
2995 int num_left
= num_sources
- 1;
2996 for (int i
= 0; i
< num_filenames
&& num_left
> 0; i
++) {
2997 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Checking file %s\n",
2998 filename_recode(filenames
[i
]));
3000 struct stream
*s
= open_stream(filenames
[i
], &mpctx
->opts
, &format
);
3003 struct demuxer
*d
= demux_open(&mpctx
->opts
, s
, DEMUXER_TYPE_MATROSKA
,
3004 mpctx
->opts
.audio_id
,
3005 mpctx
->opts
.video_id
,
3006 mpctx
->opts
.sub_id
, filenames
[i
]);
3011 if (d
->file_format
== DEMUXER_TYPE_MATROSKA
) {
3012 for (int i
= 1; i
< num_sources
; i
++) {
3013 if (sources
[i
].demuxer
)
3015 if (!memcmp(uid_map
[i
], d
->matroska_data
.segment_uid
, 16)) {
3016 mp_msg(MSGT_CPLAYER
, MSGL_INFO
,"Match for source %d: %s\n",
3017 i
, filename_recode(d
->filename
));
3018 sources
[i
].stream
= s
;
3019 sources
[i
].demuxer
= d
;
3031 talloc_free(filenames
);
3033 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Failed to find ordered chapter part!\n"
3034 "There will be parts MISSING from the video!\n");
3035 for (int i
= 1, j
= 1; i
< num_sources
; i
++)
3036 if (sources
[i
].demuxer
) {
3037 sources
[j
] = sources
[i
];
3038 memcpy(uid_map
[j
], uid_map
[i
], 16);
3042 return num_sources
- num_left
;
3045 static void build_ordered_chapter_timeline(struct MPContext
*mpctx
)
3047 if (!mpctx
->opts
.ordered_chapters
) {
3048 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, but "
3049 "you have disabled support for them. Ignoring.\n");
3053 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, will build "
3054 "edit timeline.\n");
3056 struct demuxer
*demuxer
= mpctx
->demuxer
;
3057 struct matroska_data
*m
= &demuxer
->matroska_data
;
3059 // +1 because sources/uid_map[0] is original file even if all chapters
3060 // actually use other sources and need separate entries
3061 struct content_source
*sources
= talloc_array_ptrtype(NULL
, sources
,
3062 m
->num_ordered_chapters
+1);
3063 sources
[0].stream
= mpctx
->stream
;
3064 sources
[0].demuxer
= mpctx
->demuxer
;
3065 unsigned char uid_map
[m
->num_ordered_chapters
+1][16];
3066 int num_sources
= 1;
3067 memcpy(uid_map
[0], m
->segment_uid
, 16);
3069 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
3070 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
3071 if (!c
->has_segment_uid
)
3072 memcpy(c
->segment_uid
, m
->segment_uid
, 16);
3074 for (int j
= 0; j
< num_sources
; j
++)
3075 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
3077 memcpy(uid_map
[num_sources
], c
->segment_uid
, 16);
3078 sources
[num_sources
] = (struct content_source
){};
3084 num_sources
= find_ordered_chapter_sources(mpctx
, sources
, num_sources
,
3088 // +1 for terminating chapter with start time marking end of last real one
3089 struct timeline_part
*timeline
= talloc_array_ptrtype(NULL
, timeline
,
3090 m
->num_ordered_chapters
+ 1);
3091 struct chapter
*chapters
= talloc_array_ptrtype(NULL
, chapters
,
3092 m
->num_ordered_chapters
);
3093 uint64_t starttime
= 0;
3094 uint64_t missing_time
= 0;
3096 int num_chapters
= 0;
3097 uint64_t prev_part_offset
= 0;
3098 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
3099 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
3102 for (j
= 0; j
< num_sources
; j
++) {
3103 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
3106 missing_time
+= c
->end
- c
->start
;
3109 chapters
[num_chapters
].start
= starttime
/ 1000.;
3110 chapters
[num_chapters
].name
= talloc_strdup(chapters
, c
->name
);
3111 /* Only add a separate part if the time or file actually changes.
3112 * Matroska files have chapter divisions that are redundant from
3113 * timeline point of view because the same chapter structure is used
3114 * both to specify the timeline and for normal chapter information.
3115 * Removing a missing inserted external chapter can also cause this. */
3116 if (part_count
== 0 || c
->start
!= starttime
+ prev_part_offset
3117 || sources
+ j
!= timeline
[part_count
- 1].source
) {
3118 timeline
[part_count
].source
= sources
+ j
;
3119 timeline
[part_count
].start
= chapters
[num_chapters
].start
;
3120 timeline
[part_count
].source_start
= c
->start
/ 1000.;
3121 prev_part_offset
= c
->start
- starttime
;
3124 starttime
+= c
->end
- c
->start
;
3127 timeline
[part_count
].start
= starttime
/ 1000.;
3130 // None of the parts come from the file itself???
3131 talloc_free(sources
);
3132 talloc_free(timeline
);
3133 talloc_free(chapters
);
3137 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline contains %d parts from %d "
3138 "sources. Total length %.3f seconds.\n", part_count
, num_sources
,
3139 timeline
[part_count
].start
);
3141 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "There are %.3f seconds missing "
3142 "from the timeline!\n", missing_time
/ 1000.);
3143 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Source files:\n");
3144 for (int i
= 0; i
< num_sources
; i
++)
3145 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%d: %s\n", i
,
3146 filename_recode(sources
[i
].demuxer
->filename
));
3147 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline parts: (number, start, "
3148 "source_start, source):\n");
3149 for (int i
= 0; i
< part_count
; i
++) {
3150 struct timeline_part
*p
= timeline
+ i
;
3151 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%3d %9.3f %9.3f %3td\n", i
, p
->start
,
3152 p
->source_start
, p
->source
- sources
);
3154 mp_msg(MSGT_CPLAYER
, MSGL_V
, "END %9.3f\n", timeline
[part_count
].start
);
3155 mpctx
->sources
= sources
;
3156 mpctx
->num_sources
= num_sources
;
3157 mpctx
->timeline
= timeline
;
3158 mpctx
->num_timeline_parts
= part_count
;
3159 mpctx
->num_chapters
= num_chapters
;
3160 mpctx
->chapters
= chapters
;
3162 mpctx
->timeline_part
= 0;
3163 mpctx
->demuxer
= timeline
[0].source
->demuxer
;
3167 static int read_keys(void *ctx
, int fd
)
3170 return mplayer_get_key(ctx
, 0);
3174 /* This preprocessor directive is a hack to generate a mplayer-nomain.o object
3175 * file for some tools to link against. */
3176 #ifndef DISABLE_MAIN
3177 int main(int argc
,char* argv
[]){
3184 /* Flag indicating whether MPlayer should exit without playing anything. */
3188 struct MPContext
*mpctx
= &(struct MPContext
){
3189 .osd_function
= OSD_PLAY
,
3190 .begin_skip
= MP_NOPTS_VALUE
,
3191 .play_tree_step
= 1,
3192 .global_sub_pos
= -1,
3193 .set_of_sub_pos
= -1,
3194 .file_format
= DEMUXER_TYPE_UNKNOWN
,
3199 srand(GetTimerMS());
3202 set_av_log_callback();
3205 mpctx
->x11_state
= vo_x11_init_state();
3207 struct MPOpts
*opts
= &mpctx
->opts
;
3208 set_default_mplayer_options(opts
);
3209 // Create the config context and register the options
3210 mpctx
->mconfig
= m_config_new(opts
, cfg_include
);
3211 m_config_register_options(mpctx
->mconfig
,mplayer_opts
);
3212 m_config_register_options(mpctx
->mconfig
, common_opts
);
3213 mp_input_register_options(mpctx
->mconfig
);
3215 // Preparse the command line
3216 m_config_preparse_command_line(mpctx
->mconfig
,argc
,argv
);
3218 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
3223 stream_tv_defaults
.immediate
= 1;
3226 parse_cfgfiles(mpctx
, mpctx
->mconfig
);
3228 mpctx
->playtree
= m_config_parse_mp_command_line(mpctx
->mconfig
, argc
, argv
);
3229 if(mpctx
->playtree
== NULL
)
3232 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
3233 if(mpctx
->playtree
) {
3234 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mpctx
->mconfig
);
3235 if(mpctx
->playtree_iter
) {
3236 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3237 play_tree_iter_free(mpctx
->playtree_iter
);
3238 mpctx
->playtree_iter
= NULL
;
3240 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
3244 mpctx
->key_fifo
= mp_fifo_create(opts
);
3246 print_version("MPlayer");
3248 #if defined(__MINGW32__) || defined(__CYGWIN__)
3250 HMODULE kernel32
= GetModuleHandle("Kernel32.dll");
3251 BOOL
WINAPI (*setDEP
)(DWORD
) = NULL
;
3252 BOOL
WINAPI (*setDllDir
)(LPCTSTR
) = NULL
;
3254 setDEP
= GetProcAddress(kernel32
, "SetProcessDEPPolicy");
3255 setDllDir
= GetProcAddress(kernel32
, "SetDllDirectoryA");
3257 if (setDEP
) setDEP(3);
3258 if (setDllDir
) setDllDir("");
3260 // stop Windows from showing all kinds of annoying error dialogs
3261 SetErrorMode(0x8003);
3262 // request 1ms timer resolution
3266 #ifdef CONFIG_PRIORITY
3271 set_codec_path(codec_path
);
3273 if(opts
->video_driver_list
&& strcmp(opts
->video_driver_list
[0],"help")==0){
3278 if(opts
->audio_driver_list
&& strcmp(opts
->audio_driver_list
[0],"help")==0){
3283 /* Check codecs.conf. */
3284 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
3285 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
3286 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
3287 if(!parse_codec_cfg(NULL
)){
3288 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
3290 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"Using built-in default codecs.conf.\n");
3293 free( mem_ptr
); // release the buffer created by get_path()
3296 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
3297 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available audio codecs:\n");
3298 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
3300 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3303 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
3304 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available video codecs:\n");
3305 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
3307 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3310 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
3312 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3315 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3317 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3320 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3326 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3328 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3332 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3333 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3334 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3336 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3339 if(list_properties
) {
3340 property_print_help();
3345 exit_player(mpctx
, EXIT_NONE
);
3347 if(!mpctx
->filename
&& !player_idle_mode
){
3348 // no file/vcd/dvd -> show HELP:
3349 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s", mp_gtext(help_text
));
3350 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
3353 /* Display what configure line was used */
3354 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
3356 // Many users forget to include command line in bugreports...
3357 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3358 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "CommandLine:");
3359 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3360 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3363 //------ load global data first ------
3365 mpctx
->osd
= osd_create();
3368 #ifdef CONFIG_FREETYPE
3371 #ifdef CONFIG_FONTCONFIG
3372 if(font_fontconfig
<= 0)
3375 #ifdef CONFIG_BITMAP_FONT
3377 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3378 if(!vo_font
) mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load bitmap font: %s\n",
3379 filename_recode(font_name
));
3382 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3383 free(mem_ptr
); // release the buffer created by get_path()
3385 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3388 mpctx
->osd
->sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
3390 mpctx
->osd
->sub_font
= vo_font
;
3392 #ifdef CONFIG_FONTCONFIG
3397 ass_library
= ass_init();
3403 // seteuid(0); /* Can't hurt to try to get root here */
3404 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3405 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Failed to open %s: %s (it should be readable by the user.)\n",
3406 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3408 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3410 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3411 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp
, strerror(errno
));
3412 mp_tmsg(MSGT_CPLAYER
, MSGL_HINT
, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp
);
3415 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3416 /* variable only by the root */
3417 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno
));
3421 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Using Linux hardware RTC timing (%ldHz).\n", irqp
);
3425 #endif /* HAVE_RTC */
3426 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3427 softsleep
?"software":timer_name
);
3430 load_termcap(NULL
); // load key-codes
3433 // ========== Init keyboard FIFO (connection to libvo) ============
3435 // Init input system
3436 current_module
= "init_input";
3437 mpctx
->input
= mp_input_init(&opts
->input
);
3438 mp_input_add_key_fd(mpctx
->input
, -1,0,mplayer_get_key
,NULL
, mpctx
->key_fifo
);
3440 mp_input_add_cmd_fd(mpctx
->input
, 0,USE_SELECT
,MP_INPUT_SLAVE_CMD_FUNC
,NULL
);
3441 else if(!noconsolecontrols
)
3442 mp_input_add_key_fd(mpctx
->input
, 0, 1, read_keys
, NULL
, mpctx
->key_fifo
);
3443 // Set the libstream interrupt callback
3444 stream_set_interrupt_callback(mp_input_check_interrupt
, mpctx
->input
);
3448 if(menu_cfg
&& menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3449 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3451 menu_cfg
= get_path("menu.conf");
3452 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3453 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3455 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
,
3456 MPLAYER_CONFDIR
"/menu.conf"))
3457 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", MPLAYER_CONFDIR
"/menu.conf");
3459 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Menu init failed.\n");
3467 current_module
= NULL
;
3471 signal(SIGCHLD
,child_sighandler
);
3474 #ifdef CONFIG_CRASH_DEBUG
3475 prog_path
= argv
[0];
3477 //========= Catch terminate signals: ================
3478 // terminate requests:
3479 signal(SIGTERM
,exit_sighandler
); // kill
3480 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3482 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3484 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3485 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3486 #ifdef CONFIG_SIGHANDLER
3488 signal(SIGBUS
,exit_sighandler
); // bus error
3489 signal(SIGSEGV
,exit_sighandler
); // segfault
3490 signal(SIGILL
,exit_sighandler
); // illegal instruction
3491 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3492 signal(SIGABRT
,exit_sighandler
); // abort()
3493 #ifdef CONFIG_CRASH_DEBUG
3495 signal(SIGTRAP
,exit_sighandler
);
3499 // ******************* Now, let's see the per-file stuff ********************
3503 // init global sub numbers
3504 mpctx
->global_sub_size
= 0;
3505 memset(mpctx
->sub_counts
, 0, sizeof(mpctx
->sub_counts
));
3507 if (mpctx
->filename
) {
3508 load_per_protocol_config (mpctx
->mconfig
, mpctx
->filename
);
3509 load_per_extension_config (mpctx
->mconfig
, mpctx
->filename
);
3510 load_per_file_config (mpctx
->mconfig
, mpctx
->filename
);
3513 if (opts
->video_driver_list
)
3514 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_VO
, opts
->video_driver_list
[0]);
3515 if (opts
->audio_driver_list
)
3516 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_AO
, opts
->audio_driver_list
[0]);
3518 // We must enable getch2 here to be able to interrupt network connection
3520 if(!noconsolecontrols
&& !slave_mode
){
3521 if(mpctx
->initialized_flags
&INITIALIZED_GETCH2
)
3522 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"WARNING: getch2_init called twice!\n");
3524 getch2_enable(); // prepare stdin for hotkeys...
3525 mpctx
->initialized_flags
|=INITIALIZED_GETCH2
;
3526 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3529 // =================== GUI idle loop (STOP state) ===========================
3530 while (player_idle_mode
&& !mpctx
->filename
) {
3531 play_tree_t
* entry
= NULL
;
3533 if (mpctx
->video_out
&& mpctx
->video_out
->config_ok
)
3534 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
3535 while (!(cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0))) { // wait for command
3536 if (mpctx
->video_out
)
3537 vo_check_events(mpctx
->video_out
);
3541 case MP_CMD_LOADFILE
:
3542 // prepare a tree entry with the new filename
3543 entry
= play_tree_new();
3544 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3545 // The entry is added to the main playtree after the switch().
3547 case MP_CMD_LOADLIST
:
3548 entry
= parse_playlist_file(mpctx
->mconfig
, cmd
->args
[0].v
.s
);
3551 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3553 case MP_CMD_VO_FULLSCREEN
:
3554 case MP_CMD_GET_PROPERTY
:
3555 case MP_CMD_SET_PROPERTY
:
3556 case MP_CMD_STEP_PROPERTY
:
3557 run_command(mpctx
, cmd
);
3563 if (entry
) { // user entered a command that gave a valid entry
3564 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
3565 play_tree_free_list(mpctx
->playtree
->child
, 1);
3566 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
3568 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
3570 play_tree_set_child(mpctx
->playtree
, entry
);
3572 /* Make iterator start at the top the of tree. */
3573 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mpctx
->mconfig
);
3574 if (!mpctx
->playtree_iter
) continue;
3576 // find the first real item in the tree
3577 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3579 play_tree_iter_free(mpctx
->playtree_iter
);
3580 mpctx
->playtree_iter
= NULL
;
3581 continue; // wait for next command
3583 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
3586 //---------------------------------------------------------------------------
3588 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
3589 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
);
3591 if (mpctx
->filename
) {
3592 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nPlaying %s.\n",
3593 filename_recode(mpctx
->filename
));
3594 if(use_filename_title
&& opts
->vo_wintitle
== NULL
)
3595 opts
->vo_wintitle
= strdup(mp_basename2(mpctx
->filename
));
3599 if (edl_records
) free_edl(edl_records
);
3600 next_edl_record
= edl_records
= edl_parse_file();
3602 if (edl_output_filename
) {
3603 if (edl_fd
) fclose(edl_fd
);
3604 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3606 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Can't open EDL file [%s] for writing.\n",
3607 filename_recode(edl_output_filename
));
3611 //==================== Open VOB-Sub ============================
3613 current_module
="vobsub";
3615 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3617 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load subtitles: %s\n",
3618 filename_recode(vobsub_name
));
3619 } else if (sub_auto
&& mpctx
->filename
){
3620 /* try to autodetect vobsub from movie filename ::atmos */
3621 char *buf
= strdup(mpctx
->filename
), *psub
;
3622 char *pdot
= strrchr(buf
, '.');
3623 char *pslash
= strrchr(buf
, '/');
3624 #if defined(__MINGW32__) || defined(__CYGWIN__)
3625 if (!pslash
) pslash
= strrchr(buf
, '\\');
3627 if (pdot
&& (!pslash
|| pdot
> pslash
))
3629 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3630 /* try from ~/.mplayer/sub */
3631 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3634 bname
= strrchr(buf
,'/');
3635 #if defined(__MINGW32__) || defined(__CYGWIN__)
3636 if(!bname
) bname
= strrchr(buf
,'\\');
3640 l
= strlen(psub
) + strlen(bname
) + 1;
3641 psub
= realloc(psub
,l
);
3643 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3649 mpctx
->initialized_flags
|=INITIALIZED_VOBSUB
;
3650 vobsub_set_from_lang(vo_vobsub
, opts
->sub_lang
);
3651 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
3653 // setup global sub numbering
3654 mpctx
->sub_counts
[SUB_SOURCE_VOBSUB
] = vobsub_get_indexes_count(vo_vobsub
);
3657 //============ Open & Sync STREAM --- fork cache2 ====================
3660 mpctx
->demuxer
=NULL
;
3661 if (mpctx
->d_audio
) {
3662 //free_demuxer_stream(mpctx->d_audio);
3663 mpctx
->d_audio
=NULL
;
3665 if (mpctx
->d_video
) {
3666 //free_demuxer_stream(d_video);
3667 mpctx
->d_video
=NULL
;
3669 mpctx
->sh_audio
=NULL
;
3670 mpctx
->sh_video
=NULL
;
3672 current_module
="open_stream";
3673 mpctx
->stream
= open_stream(mpctx
->filename
, opts
, &mpctx
->file_format
);
3674 if(!mpctx
->stream
) { // error...
3675 mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
);
3676 goto goto_next_file
;
3678 mpctx
->initialized_flags
|=INITIALIZED_STREAM
;
3680 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
3681 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "\nThis looks like a playlist, but "
3682 "playlist support will not be used automatically.\n"
3683 "MPlayer's playlist code is unsafe and should only be used with "
3684 "trusted sources.\nPlayback will probably fail.\n\n");
3688 current_module
="handle_playlist";
3689 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
3690 filename_recode(mpctx
->filename
));
3691 entry
= parse_playtree(mpctx
->stream
, mpctx
->mconfig
, 0);
3692 mpctx
->eof
=playtree_add_playlist(mpctx
, entry
);
3693 goto goto_next_file
;
3696 mpctx
->stream
->start_pos
+=seek_to_byte
;
3698 if(stream_dump_type
==5){
3699 unsigned char buf
[4096];
3702 current_module
="dumpstream";
3703 stream_reset(mpctx
->stream
);
3704 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
3705 f
=fopen(opts
->stream_dump_name
,"wb");
3707 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3708 exit_player(mpctx
, EXIT_ERROR
);
3710 if (opts
->chapterrange
[0] > 1) {
3711 int chapter
= opts
->chapterrange
[0] - 1;
3712 stream_control(mpctx
->stream
, STREAM_CTRL_SEEK_TO_CHAPTER
, &chapter
);
3714 while(!mpctx
->stream
->eof
&& !async_quit_request
){
3715 len
=stream_read(mpctx
->stream
,buf
,4096);
3717 if(fwrite(buf
,len
,1,f
) != 1) {
3718 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",opts
->stream_dump_name
);
3719 exit_player(mpctx
, EXIT_ERROR
);
3722 if (opts
->chapterrange
[1] > 0) {
3724 if (stream_control(mpctx
->stream
, STREAM_CTRL_GET_CURRENT_CHAPTER
,
3725 &chapter
) == STREAM_OK
3726 && chapter
+ 1 > opts
->chapterrange
[1])
3731 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",opts
->stream_dump_name
);
3732 exit_player(mpctx
, EXIT_ERROR
);
3734 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3735 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3738 #ifdef CONFIG_DVDREAD
3739 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
3740 current_module
="dvd lang->id";
3741 if(opts
->audio_lang
&& opts
->audio_id
==-1) opts
->audio_id
=dvd_aid_from_lang(mpctx
->stream
,opts
->audio_lang
);
3742 if(opts
->sub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=dvd_sid_from_lang(mpctx
->stream
,opts
->sub_lang
);
3743 // setup global sub numbering
3744 mpctx
->sub_counts
[SUB_SOURCE_DEMUX
] = dvd_number_of_subs(mpctx
->stream
);
3745 current_module
=NULL
;
3749 #ifdef CONFIG_DVDNAV
3750 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
3751 current_module
="dvdnav lang->id";
3752 if(opts
->audio_lang
&& opts
->audio_id
==-1) opts
->audio_id
=mp_dvdnav_aid_from_lang(mpctx
->stream
,opts
->audio_lang
);
3753 dvdsub_lang_id
= -3;
3754 if(opts
->sub_lang
&& opts
->sub_id
==-1)
3755 dvdsub_lang_id
= opts
->sub_id
= mp_dvdnav_sid_from_lang(mpctx
->stream
,opts
->sub_lang
);
3756 // setup global sub numbering
3757 mpctx
->sub_counts
[SUB_SOURCE_DEMUX
] = mp_dvdnav_number_of_subs(mpctx
->stream
);
3758 current_module
=NULL
;
3762 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3764 if(stream_cache_size
>0){
3766 current_module
="enable_cache";
3767 res
= stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
3768 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3769 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0));
3771 if((mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
))) goto goto_next_file
;
3774 //============ Open DEMUXERS --- DETECT file type =======================
3775 current_module
="demux_open";
3777 mpctx
->demuxer
=demux_open(opts
, mpctx
->stream
,mpctx
->file_format
,opts
->audio_id
,opts
->video_id
,opts
->sub_id
,mpctx
->filename
);
3779 // HACK to get MOV Reference Files working
3781 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3783 unsigned char* playlist_entry
;
3784 play_tree_t
*list
= NULL
, *entry
= NULL
;
3786 current_module
="handle_demux_playlist";
3787 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
3791 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
3792 filename_recode(playlist_entry
));
3794 bname
=mp_basename(playlist_entry
);
3795 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3798 if (!strcmp(playlist_entry
, mpctx
->filename
)) // ignoring self-reference
3801 entry
= play_tree_new();
3803 if (mpctx
->filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3805 temp
=malloc((strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))+strlen(playlist_entry
)+1));
3808 strncpy(temp
, mpctx
->filename
, strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
)));
3809 temp
[strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))]='\0';
3810 strcat(temp
, playlist_entry
);
3811 if (!strcmp(temp
, mpctx
->filename
)) {
3815 play_tree_add_file(entry
,temp
);
3816 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3821 play_tree_add_file(entry
,playlist_entry
);
3826 play_tree_append_entry(list
,entry
);
3828 free_demuxer(mpctx
->demuxer
);
3829 mpctx
->demuxer
= NULL
;
3833 entry
= play_tree_new();
3834 play_tree_set_child(entry
,list
);
3835 mpctx
->stop_play
= playtree_add_playlist(mpctx
, entry
);
3836 goto goto_next_file
;
3841 goto goto_next_file
;
3843 if (mpctx
->demuxer
->matroska_data
.ordered_chapters
)
3844 build_ordered_chapter_timeline(mpctx
);
3846 if (!mpctx
->sources
) {
3847 mpctx
->sources
= talloc_ptrtype(NULL
, mpctx
->sources
);
3848 *mpctx
->sources
= (struct content_source
){.stream
= mpctx
->stream
,
3849 .demuxer
= mpctx
->demuxer
};
3850 mpctx
->num_sources
= 1;
3853 mpctx
->initialized_flags
|=INITIALIZED_DEMUXER
;
3856 if (opts
->ass_enabled
&& ass_library
) {
3857 for (int j
= 0; j
< mpctx
->num_sources
; j
++) {
3858 struct demuxer
*d
= mpctx
->sources
[j
].demuxer
;
3859 for (int i
= 0; i
< d
->num_attachments
; i
++) {
3860 struct demux_attachment
*att
= d
->attachments
+ i
;
3861 if (use_embedded_fonts
&& attachment_is_font(att
))
3862 ass_add_font(ass_library
, att
->name
, att
->data
, att
->data_size
);
3868 current_module
="demux_open2";
3870 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3871 mpctx
->d_video
=mpctx
->demuxer
->video
;
3872 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3876 mp_property_do("switch_program", M_PROPERTY_SET
, &tmp
, mpctx
);
3878 // select audio stream
3879 if (mpctx
->num_sources
)
3880 for (int i
= 0; i
< mpctx
->num_sources
; i
++)
3881 select_audio(mpctx
->sources
[i
].demuxer
, opts
->audio_id
,
3884 select_audio(mpctx
->d_audio
->demuxer
, opts
->audio_id
, opts
->audio_lang
);
3887 if((stream_dump_type
)&&(stream_dump_type
<4)){
3889 demux_stream_t
*ds
=NULL
;
3890 current_module
="dump";
3891 // select stream to dump
3892 switch(stream_dump_type
){
3893 case 1: ds
=mpctx
->d_audio
;break;
3894 case 2: ds
=mpctx
->d_video
;break;
3895 case 3: ds
=mpctx
->d_sub
;break;
3898 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"dump: FATAL: Selected stream missing!\n");
3899 exit_player(mpctx
, EXIT_ERROR
);
3901 // disable other streams:
3902 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3903 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3904 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3906 f
=fopen(opts
->stream_dump_name
,"wb");
3908 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3909 exit_player(mpctx
, EXIT_ERROR
);
3912 unsigned char* start
;
3913 int in_size
=ds_get_packet(ds
,&start
);
3914 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3915 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3916 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3917 if (opts
->chapterrange
[1] > 0) {
3918 int cur_chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
3919 if(cur_chapter
!=-1 && cur_chapter
+1 > opts
->chapterrange
[1])
3924 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3925 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3928 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3929 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3931 if(mpctx
->sh_video
){
3933 current_module
="video_read_properties";
3934 if(!video_read_properties(mpctx
->sh_video
)) {
3935 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Video: Cannot read properties.\n");
3936 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3938 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n",
3939 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3940 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3943 /* need to set fps here for output encoders to pick it up in their init */
3945 mpctx
->sh_video
->fps
=force_fps
;
3946 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3948 vo_fps
= mpctx
->sh_video
->fps
;
3950 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3951 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"FPS not specified in the header or invalid, use the -fps option.\n");
3952 mpctx
->opts
.correct_pts
= 1;
3958 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3959 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "No stream found.\n");
3961 if(mpctx
->stream
->type
== STREAMTYPE_DVB
)
3964 int v
= mpctx
->last_dvb_step
;
3966 dir
= DVB_CHANNEL_HIGHER
;
3968 dir
= DVB_CHANNEL_LOWER
;
3970 if(dvb_step_channel(mpctx
->stream
, dir
)) {
3971 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3972 mpctx
->dvbin_reopen
= 1;
3976 goto goto_next_file
; // exit_player(_("Fatal error"));
3979 /* display clip info */
3980 demux_info_print(mpctx
->demuxer
);
3982 //================== Read SUBTITLES (DVD & TEXT) ==========================
3983 if(vo_spudec
==NULL
&&
3984 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
)){
3985 init_vo_spudec(mpctx
);
3988 // after reading video params we should load subtitles because
3989 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3991 current_module
="read_subtitles_file";
3992 double sub_fps
= mpctx
->sh_video
? mpctx
->sh_video
->fps
: 25;
3994 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3995 add_subtitles(mpctx
, sub_name
[i
], sub_fps
, 0);
3997 if(sub_auto
) { // auto load sub file ...
3998 char *psub
= get_path( "sub/" );
3999 char **tmp
= sub_filenames((psub
? psub
: ""), mpctx
->filename
);
4001 free(psub
); // release the buffer created by get_path() above
4003 add_subtitles(mpctx
, tmp
[i
], sub_fps
, 1);
4008 if (mpctx
->set_of_sub_size
> 0)
4009 mpctx
->sub_counts
[SUB_SOURCE_SUBS
] = mpctx
->set_of_sub_size
;
4011 if (select_subtitle(mpctx
)) {
4013 switch (stream_dump_type
) {
4014 case 3: list_sub_file(subdata
); break;
4015 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
4016 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
4017 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
4018 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
4019 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
4023 print_file_properties(mpctx
, mpctx
->filename
);
4025 if(!mpctx
->sh_video
) goto main
; // audio-only
4027 if(!reinit_video_chain(mpctx
)) {
4028 if(!mpctx
->sh_video
){
4029 if(!mpctx
->sh_audio
) goto goto_next_file
;
4030 goto main
; // exit_player(_("Fatal error"));
4034 if(mpctx
->sh_video
->output_flags
& 0x08 && vo_spudec
)
4035 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
4037 #ifdef CONFIG_FREETYPE
4038 force_load_font
= 1;
4041 //================== MAIN: ==========================
4043 current_module
="main";
4046 char* msg
= property_expand_string(mpctx
, playing_msg
);
4047 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
4052 // Disable the term OSD in verbose mode
4053 if(verbose
) term_osd
= 0;
4056 int frame_time_remaining
=0; // flag
4059 // Make sure old OSD does not stay around,
4060 // e.g. with -fixed-vo and same-resolution files
4062 update_osd_msg(mpctx
);
4064 //================ SETUP AUDIO ==========================
4066 if(mpctx
->sh_audio
){
4067 reinit_audio_chain(mpctx
);
4068 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
4069 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
4072 current_module
="av_init";
4074 if(mpctx
->sh_video
){
4075 mpctx
->sh_video
->timer
=0;
4077 audio_delay
+= mpctx
->sh_video
->stream_delay
;
4079 if(mpctx
->sh_audio
){
4080 if (start_volume
>= 0)
4081 mixer_setvolume(&mpctx
->mixer
, start_volume
, start_volume
);
4083 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
4084 mpctx
->delay
=-audio_delay
;
4087 if(!mpctx
->sh_audio
){
4088 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Audio: no sound\n");
4089 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
4090 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
4091 //mpctx->d_audio->id=-2; // do not read audio chunks
4092 //uninit_player(mpctx, INITIALIZED_AO); // close device
4094 if(!mpctx
->sh_video
){
4095 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Video: no video\n");
4096 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
4097 ds_free_packs(mpctx
->d_video
);
4098 mpctx
->d_video
->id
=-2;
4099 //if(!fixed_vo) uninit_player(mpctx, INITIALIZED_VO);
4102 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
4103 goto goto_next_file
;
4105 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4106 if(force_fps
&& mpctx
->sh_video
){
4107 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
4108 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
4109 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"FPS forced to be %5.3f (ftime: %5.3f).\n",mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
4112 mp_input_set_section(mpctx
->input
, NULL
);
4113 //TODO: add desired (stream-based) sections here
4114 if (mpctx
->stream
->type
==STREAMTYPE_TV
) mp_input_set_section(mpctx
->input
, "tv");
4115 if (mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) mp_input_set_section(mpctx
->input
, "dvdnav");
4117 //==================== START PLAYING =======================
4119 if(opts
->loop_times
>1) opts
->loop_times
--; else
4120 if(opts
->loop_times
==1) opts
->loop_times
= -1;
4122 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Starting playback...\n");
4124 total_time_usage_start
=GetTimer();
4125 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4126 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
4127 play_n_frames
=play_n_frames_mf
;
4129 if(play_n_frames
==0){
4130 mpctx
->stop_play
=PT_NEXT_ENTRY
; goto goto_next_file
;
4133 // If there's a timeline force an absolute seek to initialize state
4134 if (seek_to_sec
|| mpctx
->timeline
) {
4135 seek(mpctx
, seek_to_sec
, SEEK_ABSOLUTE
);
4136 end_at
.pos
+= seek_to_sec
;
4138 if (opts
->chapterrange
[0] > 0) {
4140 if (seek_chapter(mpctx
, opts
->chapterrange
[0]-1, &pts
, NULL
) >= 0
4142 seek(mpctx
, pts
, SEEK_ABSOLUTE
);
4145 if (end_at
.type
== END_AT_SIZE
) {
4146 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Option -endpos in MPlayer does not yet support size units.\n");
4147 end_at
.type
= END_AT_NONE
;
4150 #ifdef CONFIG_DVDNAV
4151 mp_dvdnav_context_free(mpctx
);
4152 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
4153 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
4154 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
4158 get_relative_time(mpctx
); // reset current delta
4159 mpctx
->time_frame
= 0;
4160 mpctx
->drop_message_shown
= 0;
4161 mpctx
->update_video_immediately
= true;
4162 mpctx
->total_avsync_change
= 0;
4163 mpctx
->last_chapter_seek
= -1;
4164 // Make sure VO knows current pause state
4165 if (mpctx
->sh_video
)
4166 vo_control(mpctx
->video_out
, mpctx
->paused
? VOCTRL_PAUSE
: VOCTRL_RESUME
,
4169 while(!mpctx
->stop_play
){
4170 float aq_sleep_time
=0;
4172 if (opts
->chapterrange
[1] > 0) {
4173 int cur_chapter
= get_current_chapter(mpctx
);
4174 if(cur_chapter
!=-1 && cur_chapter
+1 > opts
->chapterrange
[1])
4175 goto goto_next_file
;
4178 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
4179 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
4180 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
4181 reinit_audio_chain(mpctx
);
4184 /*========================== PLAY AUDIO ============================*/
4186 if (mpctx
->sh_audio
&& !mpctx
->paused
)
4187 if (!fill_audio_out_buffers(mpctx
))
4188 // at eof, all audio at least written to ao
4189 if (!mpctx
->sh_video
)
4190 mpctx
->stop_play
= AT_END_OF_FILE
;
4193 if(!mpctx
->sh_video
) {
4194 // handle audio-only case:
4196 // sh_audio can be NULL due to video stream switching
4197 // TODO: handle this better
4198 if (mpctx
->sh_audio
)
4199 a_pos
= playing_audio_pts(mpctx
);
4201 print_status(mpctx
, a_pos
, false);
4203 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
4204 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4205 update_subtitles(mpctx
, &mpctx
->opts
, NULL
, a_pos
, mpctx
->video_offset
,
4207 update_osd_msg(mpctx
);
4211 /*========================== PLAY VIDEO ============================*/
4213 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
4214 vo_fps
=mpctx
->sh_video
->fps
;
4216 blit_frame
= mpctx
->video_out
->frame_loaded
;
4218 double frame_time
= update_video(mpctx
);
4219 blit_frame
= mpctx
->video_out
->frame_loaded
;
4220 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
4221 if (mpctx
->sh_video
->vf_initialized
< 0) {
4222 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "\nFATAL: Could not initialize video filters (-vf) or video output (-vo).\n");
4223 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4224 goto goto_next_file
;
4227 struct sh_video
*sh_video
= mpctx
->sh_video
;
4228 update_subtitles(mpctx
, &mpctx
->opts
, sh_video
, sh_video
->pts
,
4229 mpctx
->video_offset
, mpctx
->d_sub
, 0);
4230 update_teletext(sh_video
, mpctx
->demuxer
, 0);
4231 update_osd_msg(mpctx
);
4232 struct vf_instance
*vf
= mpctx
->sh_video
->vfilter
;
4233 vf
->control(vf
, VFCTRL_DRAW_EOSD
, NULL
);
4234 vf
->control(vf
, VFCTRL_DRAW_OSD
, mpctx
->osd
);
4238 mpctx
->stop_play
= AT_END_OF_FILE
;
4240 if (mpctx
->update_video_immediately
) {
4241 // Show this frame immediately, rest normally
4242 mpctx
->update_video_immediately
= false;
4244 mpctx
->time_frame
+= frame_time
/ opts
->playback_speed
;
4245 adjust_sync(mpctx
, frame_time
);
4249 if (mpctx
->timeline
) {
4250 struct timeline_part
*next
= mpctx
->timeline
+ mpctx
->timeline_part
+ 1;
4251 if (mpctx
->sh_video
->pts
>= next
->start
4252 || mpctx
->stop_play
== AT_END_OF_FILE
4253 && mpctx
->timeline_part
+ 1 < mpctx
->num_timeline_parts
) {
4254 seek(mpctx
, next
->start
, SEEK_ABSOLUTE
);
4259 // ==========================================================================
4261 // current_module="draw_osd";
4262 // if(vo_config_count) mpctx->video_out->draw_osd();
4264 current_module
="vo_check_events";
4265 vo_check_events(mpctx
->video_out
);
4268 if (stop_xscreensaver
) {
4269 current_module
= "stop_xscreensaver";
4270 xscreensaver_heartbeat(mpctx
->x11_state
);
4273 if (heartbeat_cmd
) {
4274 static unsigned last_heartbeat
;
4275 unsigned now
= GetTimerMS();
4276 if (now
- last_heartbeat
> 30000) {
4277 last_heartbeat
= now
;
4278 system(heartbeat_cmd
);
4282 frame_time_remaining
= sleep_until_update(mpctx
, &mpctx
->time_frame
, &aq_sleep_time
);
4284 //====================== FLIP PAGE (VIDEO BLT): =========================
4286 current_module
="flip_page";
4287 if (!frame_time_remaining
&& blit_frame
) {
4288 unsigned int t2
=GetTimer();
4289 unsigned int pts_us
= mpctx
->last_time
+ mpctx
->time_frame
* 1e6
;
4291 double pts2
= mpctx
->video_out
->next_pts2
;
4292 if (pts2
!= MP_NOPTS_VALUE
&& opts
->correct_pts
) {
4293 // expected A/V sync correction is ignored
4294 double diff
= (pts2
- mpctx
->sh_video
->pts
);
4295 diff
/= opts
->playback_speed
;
4296 if (mpctx
->time_frame
< 0)
4297 diff
+= mpctx
->time_frame
;
4302 duration
= diff
* 1e6
;
4304 vo_flip_page(mpctx
->video_out
, pts_us
|1, duration
);
4306 mpctx
->last_vo_flip_duration
= (GetTimer() - t2
) * 0.000001;
4307 vout_time_usage
+= mpctx
->last_vo_flip_duration
;
4308 if (mpctx
->video_out
->driver
->flip_page_timed
) {
4309 // No need to adjust sync based on flip speed
4310 mpctx
->last_vo_flip_duration
= 0;
4311 // For print_status - VO call finishing early is OK for sync
4312 mpctx
->time_frame
-= get_relative_time(mpctx
);
4314 print_status(mpctx
, MP_NOPTS_VALUE
, true);
4317 print_status(mpctx
, MP_NOPTS_VALUE
, false);
4319 //============================ Auto QUALITY ============================
4321 /*Output quality adjustments:*/
4323 current_module
="autoq";
4324 // float total=0.000001f * (GetTimer()-aq_total_time);
4325 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4326 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4329 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4330 if(output_quality
>1 && aq_sleep_time
<0)
4333 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4335 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4336 set_video_quality(mpctx
->sh_video
,output_quality
);
4339 if (!frame_time_remaining
&& blit_frame
) {
4340 if (play_n_frames
>= 0) {
4342 if (play_n_frames
<= 0)
4343 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4345 if (mpctx
->step_frames
> 0) {
4346 mpctx
->step_frames
--;
4347 if (mpctx
->step_frames
== 0)
4348 pause_player(mpctx
);
4353 // FIXME: add size based support for -endpos
4354 if (end_at
.type
== END_AT_TIME
&&
4355 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
4356 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4358 } // end if(mpctx->sh_video)
4360 #ifdef CONFIG_DVDNAV
4361 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
4363 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
4364 if (!vo_spudec
|| !spudec_apply_palette_crop(vo_spudec
, hl
.palette
, hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
)) {
4365 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
4366 vo_osd_changed (OSDTYPE_DVDNAV
);
4368 osd_set_nav_box(0, 0, 0, 0);
4369 vo_osd_changed(OSDTYPE_DVDNAV
);
4370 vo_osd_changed(OSDTYPE_SPU
);
4373 if (mp_dvdnav_stream_has_changed(mpctx
->stream
)) {
4375 if (mpctx
->sh_video
&&
4376 stream_control (mpctx
->demuxer
->stream
,
4377 STREAM_CTRL_GET_ASPECT_RATIO
, &ar
)
4378 != STREAM_UNSUPPORTED
)
4379 mpctx
->sh_video
->stream_aspect
= ar
;
4384 //================= Keyboard events, SEEKing ====================
4386 current_module
="key_events";
4391 while ((cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0)) != NULL
) {
4392 run_command(mpctx
, cmd
);
4394 if (mpctx
->stop_play
)
4396 if (mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
) {
4397 cmd
= mp_input_get_cmd(mpctx
->input
, 0, 1);
4398 /* Allow seek commands to be combined, but execute the real seek
4399 * before processing other commands */
4400 if (!cmd
|| cmd
->id
!= MP_CMD_SEEK
)
4404 if (!mpctx
->paused
|| mpctx
->stop_play
|| mpctx
->rel_seek_secs
4405 || mpctx
->abs_seek_pos
)
4407 if (mpctx
->sh_video
) {
4408 update_osd_msg(mpctx
);
4409 int hack
= vo_osd_changed(0);
4410 vo_osd_changed(hack
);
4412 if (redraw_osd(mpctx
->sh_video
, mpctx
->osd
) < 0) {
4413 add_step_frame(mpctx
);
4425 if (step_sec
> 0 && !mpctx
->paused
) {
4426 mpctx
->osd_function
=OSD_FFW
;
4427 mpctx
->rel_seek_secs
+=step_sec
;
4433 if(mpctx
->stop_play
==AT_END_OF_FILE
&& opts
->loop_times
>=0) {
4434 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d\n", opts
->loop_times
);
4436 if(opts
->loop_times
>1) opts
->loop_times
--; else
4437 if(opts
->loop_times
==1) opts
->loop_times
=-1;
4438 play_n_frames
=play_n_frames_mf
;
4440 mpctx
->abs_seek_pos
=SEEK_ABSOLUTE
; mpctx
->rel_seek_secs
=seek_to_sec
;
4443 if(mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
){
4444 seek(mpctx
, mpctx
->rel_seek_secs
, mpctx
->abs_seek_pos
);
4446 mpctx
->rel_seek_secs
=0;
4447 mpctx
->abs_seek_pos
=0;
4450 } // while(!mpctx->stop_play)
4452 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->stop_play
);
4455 if(mpctx
->dvbin_reopen
)
4457 mpctx
->stop_play
= 0;
4458 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_STREAM
|INITIALIZED_GETCH2
|(opts
->fixed_vo
?INITIALIZED_VO
:0)));
4459 cache_uninit(mpctx
->stream
);
4460 mpctx
->dvbin_reopen
= 0;
4461 goto goto_enable_cache
;
4466 goto_next_file
: // don't jump here after ao/vo/getch initialization!
4468 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
4471 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
4472 double total_time_usage
;
4473 total_time_usage_start
=GetTimer()-total_time_usage_start
;
4474 total_time_usage
= (float)total_time_usage_start
*0.000001;
4475 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4476 video_time_usage
,vout_time_usage
,audio_time_usage
,
4477 total_time_usage
-tot
,total_time_usage
);
4478 if(total_time_usage
>0.0)
4479 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4480 100.0*video_time_usage
/total_time_usage
,
4481 100.0*vout_time_usage
/total_time_usage
,
4482 100.0*audio_time_usage
/total_time_usage
,
4483 100.0*(total_time_usage
-tot
)/total_time_usage
,
4485 if(total_frame_cnt
&& frame_dropping
)
4486 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4487 total_frame_cnt
-drop_frame_cnt
,
4488 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
4490 100*drop_frame_cnt
/total_frame_cnt
,
4492 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
4495 // time to uninit all, except global stuff:
4496 uninit_player(mpctx
, INITIALIZED_ALL
-(opts
->fixed_vo
?INITIALIZED_VO
:0));
4498 if(mpctx
->set_of_sub_size
> 0) {
4499 current_module
="sub_free";
4500 for(i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
4501 sub_free(mpctx
->set_of_subtitles
[i
]);
4503 if(mpctx
->set_of_ass_tracks
[i
])
4504 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
4507 mpctx
->set_of_sub_size
= 0;
4509 vo_sub_last
= vo_sub
=NULL
;
4514 ass_clear_fonts(ass_library
);
4517 if (!mpctx
->stop_play
) // In case some goto jumped here...
4518 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4520 int playtree_direction
= 1;
4522 if(mpctx
->stop_play
== PT_NEXT_ENTRY
|| mpctx
->stop_play
== PT_PREV_ENTRY
) {
4523 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) != PLAY_TREE_ITER_ENTRY
) {
4524 play_tree_iter_free(mpctx
->playtree_iter
);
4525 mpctx
->playtree_iter
= NULL
;
4527 mpctx
->play_tree_step
= 1;
4528 } else if(mpctx
->stop_play
== PT_UP_NEXT
|| mpctx
->stop_play
== PT_UP_PREV
) {
4529 int direction
= mpctx
->stop_play
== PT_UP_NEXT
? 1 : -1;
4530 if(mpctx
->playtree_iter
) {
4531 if(play_tree_iter_up_step(mpctx
->playtree_iter
,direction
,0) != PLAY_TREE_ITER_ENTRY
) {
4532 play_tree_iter_free(mpctx
->playtree_iter
);
4533 mpctx
->playtree_iter
= NULL
;
4536 } else if (mpctx
->stop_play
== PT_STOP
) {
4537 play_tree_iter_free(mpctx
->playtree_iter
);
4538 mpctx
->playtree_iter
= NULL
;
4539 } else { // NEXT PREV SRC
4540 playtree_direction
= mpctx
->stop_play
== PT_PREV_SRC
? -1 : 1;
4543 while(mpctx
->playtree_iter
!= NULL
) {
4544 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, playtree_direction
);
4545 if(mpctx
->filename
== NULL
) {
4546 if(play_tree_iter_step(mpctx
->playtree_iter
, playtree_direction
, 0) != PLAY_TREE_ITER_ENTRY
) {
4547 play_tree_iter_free(mpctx
->playtree_iter
);
4548 mpctx
->playtree_iter
= NULL
;
4554 if(mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
4555 if(!mpctx
->playtree_iter
) mpctx
->filename
= NULL
;
4556 mpctx
->stop_play
= 0;
4557 goto play_next_file
;
4561 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
4565 #endif /* DISABLE_MAIN */