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 extern int cache_fill_status
;
325 float stream_cache_min_percent
=20.0;
326 float stream_cache_seek_min_percent
=50.0;
328 #define cache_fill_status 0
332 static char *stream_dump_name
="stream.dump";
333 int stream_dump_type
=0;
336 static float default_max_pts_correction
=-1;//0.01f;
338 static int ignore_start
=0;
340 static int softsleep
=0;
343 static int force_srate
=0;
344 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
345 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
346 static int play_n_frames
=-1;
347 static int play_n_frames_mf
=-1;
350 char *font_name
=NULL
;
351 char *sub_font_name
=NULL
;
352 extern int font_fontconfig
;
353 float font_factor
=0.75;
354 char **sub_name
=NULL
;
358 char *vobsub_name
=NULL
;
359 /*DSP!!char *dsp=NULL;*/
361 int suboverlap_enabled
= 1;
365 char* current_module
=NULL
; // for debugging
371 #include "m_struct.h"
372 #include "libmenu/menu.h"
373 extern vf_info_t vf_info_menu
;
374 static const vf_info_t
* const libmenu_vfs
[] = {
378 static vf_instance_t
* vf_menu
= NULL
;
380 static char* menu_cfg
= NULL
;
381 static char* menu_root
= "main";
386 static int nortc
= 1;
387 static char* rtc_device
;
390 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
391 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
392 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
393 int use_filedir_conf
;
394 int use_filename_title
;
396 #include "mpcommon.h"
399 #include "metadata.h"
401 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
403 const void *mpctx_get_video_out(MPContext
*mpctx
)
405 return mpctx
->video_out
;
408 const void *mpctx_get_audio_out(MPContext
*mpctx
)
410 return mpctx
->audio_out
;
413 void *mpctx_get_demuxer(MPContext
*mpctx
)
415 return mpctx
->demuxer
;
418 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
420 return mpctx
->playtree_iter
;
423 void *mpctx_get_mixer(MPContext
*mpctx
)
425 return &mpctx
->mixer
;
428 int mpctx_get_global_sub_size(MPContext
*mpctx
)
430 return mpctx
->global_sub_size
;
433 int mpctx_get_osd_function(MPContext
*mpctx
)
435 return mpctx
->osd_function
;
438 static float get_relative_time(struct MPContext
*mpctx
)
440 unsigned int new_time
= GetTimer();
441 unsigned int delta
= new_time
- mpctx
->last_time
;
442 mpctx
->last_time
= new_time
;
443 return delta
* 0.000001;
446 static int is_valid_metadata_type(struct MPContext
*mpctx
, metadata_t type
) {
449 /* check for valid video stream */
450 case META_VIDEO_CODEC
:
451 case META_VIDEO_BITRATE
:
452 case META_VIDEO_RESOLUTION
:
454 if (!mpctx
->sh_video
)
459 /* check for valid audio stream */
460 case META_AUDIO_CODEC
:
461 case META_AUDIO_BITRATE
:
462 case META_AUDIO_SAMPLES
:
464 if (!mpctx
->sh_audio
)
469 /* check for valid demuxer */
470 case META_INFO_TITLE
:
471 case META_INFO_ARTIST
:
472 case META_INFO_ALBUM
:
474 case META_INFO_COMMENT
:
475 case META_INFO_TRACK
:
476 case META_INFO_GENRE
:
490 static char *get_demuxer_info(struct MPContext
*mpctx
, char *tag
) {
491 char **info
= mpctx
->demuxer
->info
;
497 for (n
= 0; info
[2*n
] != NULL
; n
++)
498 if (!strcasecmp (info
[2*n
], tag
))
501 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
504 char *get_metadata(struct MPContext
*mpctx
, metadata_t type
)
507 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
508 sh_video_t
* const sh_video
= mpctx
->sh_video
;
510 if (!is_valid_metadata_type(mpctx
, type
))
517 return strdup (mp_basename2 (mpctx
->filename
));
520 case META_VIDEO_CODEC
:
522 if (sh_video
->format
== 0x10000001)
523 meta
= strdup ("mpeg1");
524 else if (sh_video
->format
== 0x10000002)
525 meta
= strdup ("mpeg2");
526 else if (sh_video
->format
== 0x10000004)
527 meta
= strdup ("mpeg4");
528 else if (sh_video
->format
== 0x10000005)
529 meta
= strdup ("h264");
530 else if (sh_video
->format
>= 0x20202020)
533 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
538 sprintf (meta
, "0x%08X", sh_video
->format
);
543 case META_VIDEO_BITRATE
:
546 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
550 case META_VIDEO_RESOLUTION
:
553 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
557 case META_AUDIO_CODEC
:
559 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
560 meta
= strdup (sh_audio
->codec
->name
);
564 case META_AUDIO_BITRATE
:
567 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
571 case META_AUDIO_SAMPLES
:
574 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
578 /* check for valid demuxer */
579 case META_INFO_TITLE
:
580 return get_demuxer_info(mpctx
, "Title");
582 case META_INFO_ARTIST
:
583 return get_demuxer_info(mpctx
, "Artist");
585 case META_INFO_ALBUM
:
586 return get_demuxer_info(mpctx
, "Album");
589 return get_demuxer_info(mpctx
, "Year");
591 case META_INFO_COMMENT
:
592 return get_demuxer_info(mpctx
, "Comment");
594 case META_INFO_TRACK
:
595 return get_demuxer_info(mpctx
, "Track");
597 case META_INFO_GENRE
:
598 return get_demuxer_info(mpctx
, "Genre");
607 static void print_file_properties(const MPContext
*mpctx
, const char *filename
)
609 double start_pts
= MP_NOPTS_VALUE
;
610 double video_start_pts
= MP_NOPTS_VALUE
;
611 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
612 filename_recode(filename
));
613 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
614 if (mpctx
->sh_video
) {
615 /* Assume FOURCC if all bytes >= 0x20 (' ') */
616 if (mpctx
->sh_video
->format
>= 0x20202020)
617 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
619 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
620 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
621 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
622 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
623 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
624 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
625 video_start_pts
= ds_get_next_pts(mpctx
->d_video
);
627 if (mpctx
->sh_audio
) {
628 /* Assume FOURCC if all bytes >= 0x20 (' ') */
629 if (mpctx
->sh_audio
->format
>= 0x20202020)
630 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
632 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
633 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
634 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
635 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
636 start_pts
= ds_get_next_pts(mpctx
->d_audio
);
638 if (video_start_pts
!= MP_NOPTS_VALUE
) {
639 if (start_pts
== MP_NOPTS_VALUE
|| !mpctx
->sh_audio
||
640 (mpctx
->sh_video
&& video_start_pts
< start_pts
))
641 start_pts
= video_start_pts
;
643 if (start_pts
!= MP_NOPTS_VALUE
)
644 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_START_TIME=%.2f\n", start_pts
);
646 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_START_TIME=unknown\n");
647 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2f\n", mpctx
->timeline
?
648 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
:
649 demuxer_get_time_length(mpctx
->demuxer
));
650 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_SEEKABLE=%d\n",
651 mpctx
->stream
->seek
&& (!mpctx
->demuxer
|| mpctx
->demuxer
->seekable
));
652 if (mpctx
->demuxer
) {
653 if (mpctx
->demuxer
->num_chapters
== 0)
654 stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_NUM_CHAPTERS
, &mpctx
->demuxer
->num_chapters
);
655 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_CHAPTERS=%d\n", mpctx
->demuxer
->num_chapters
);
659 /// step size of mixer changes
663 static void mp_dvdnav_context_free(MPContext
*ctx
){
664 if (ctx
->nav_smpi
) free_mp_image(ctx
->nav_smpi
);
665 ctx
->nav_smpi
= NULL
;
666 if (ctx
->nav_buffer
) free(ctx
->nav_buffer
);
667 ctx
->nav_buffer
= NULL
;
668 ctx
->nav_start
= NULL
;
669 ctx
->nav_in_size
= 0;
673 void uninit_player(struct MPContext
*mpctx
, unsigned int mask
){
674 mask
&= mpctx
->initialized_flags
;
676 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
678 if(mask
&INITIALIZED_ACODEC
){
679 mpctx
->initialized_flags
&=~INITIALIZED_ACODEC
;
680 current_module
="uninit_acodec";
681 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
682 mpctx
->sh_audio
=NULL
;
683 mpctx
->mixer
.afilter
= NULL
;
686 if(mask
&INITIALIZED_VCODEC
){
687 mpctx
->initialized_flags
&=~INITIALIZED_VCODEC
;
688 current_module
="uninit_vcodec";
689 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
690 mpctx
->sh_video
=NULL
;
696 if(mask
&INITIALIZED_DEMUXER
){
697 mpctx
->initialized_flags
&=~INITIALIZED_DEMUXER
;
698 current_module
="free_demuxer";
699 if (mpctx
->num_sources
) {
700 mpctx
->demuxer
= mpctx
->sources
[0].demuxer
;
701 for (int i
= 1; i
< mpctx
->num_sources
; i
++) {
702 free_stream(mpctx
->sources
[i
].stream
);
703 free_demuxer(mpctx
->sources
[i
].demuxer
);
706 talloc_free(mpctx
->sources
);
707 mpctx
->sources
= NULL
;
708 mpctx
->num_sources
= 0;
709 talloc_free(mpctx
->timeline
);
710 mpctx
->timeline
= NULL
;
711 mpctx
->num_timeline_parts
= 0;
712 talloc_free(mpctx
->chapters
);
713 mpctx
->chapters
= NULL
;
714 mpctx
->num_chapters
= 0;
715 mpctx
->video_offset
= 0;
717 mpctx
->stream
=mpctx
->demuxer
->stream
;
718 free_demuxer(mpctx
->demuxer
);
723 // kill the cache process:
724 if(mask
&INITIALIZED_STREAM
){
725 mpctx
->initialized_flags
&=~INITIALIZED_STREAM
;
726 current_module
="uninit_stream";
727 if(mpctx
->stream
) free_stream(mpctx
->stream
);
731 if(mask
&INITIALIZED_VO
){
732 mpctx
->initialized_flags
&=~INITIALIZED_VO
;
733 current_module
="uninit_vo";
734 vo_destroy(mpctx
->video_out
);
735 mpctx
->video_out
=NULL
;
737 mp_dvdnav_context_free(mpctx
);
741 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
742 if(mask
&INITIALIZED_GETCH2
){
743 mpctx
->initialized_flags
&=~INITIALIZED_GETCH2
;
744 current_module
="uninit_getch2";
745 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
750 if(mask
&INITIALIZED_VOBSUB
){
751 mpctx
->initialized_flags
&=~INITIALIZED_VOBSUB
;
752 current_module
="uninit_vobsub";
753 if(vo_vobsub
) vobsub_close(vo_vobsub
);
757 if (mask
&INITIALIZED_SPUDEC
){
758 mpctx
->initialized_flags
&=~INITIALIZED_SPUDEC
;
759 current_module
="uninit_spudec";
760 spudec_free(vo_spudec
);
764 if(mask
&INITIALIZED_AO
){
765 mpctx
->initialized_flags
&=~INITIALIZED_AO
;
766 current_module
="uninit_ao";
767 if (mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
768 if (mpctx
->audio_out
)
769 mpctx
->audio_out
->uninit(mpctx
->stop_play
!= AT_END_OF_FILE
);
770 mpctx
->audio_out
=NULL
;
776 void exit_player_with_rc(struct MPContext
*mpctx
, enum exit_reason how
, int rc
)
778 if (mpctx
->user_muted
&& !mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
779 uninit_player(mpctx
, INITIALIZED_ALL
);
780 #if defined(__MINGW32__) || defined(__CYGWIN__)
784 vo_uninit(mpctx
->x11_state
); // Close the X11 connection (if any is open).
787 current_module
="uninit_input";
788 mp_input_uninit(mpctx
->input
);
794 #ifdef CONFIG_FREETYPE
795 current_module
="uninit_font";
796 if (mpctx
->osd
&& mpctx
->osd
->sub_font
!= vo_font
)
797 free_font_desc(mpctx
->osd
->sub_font
);
798 free_font_desc(vo_font
);
802 osd_free(mpctx
->osd
);
805 ass_library_done(ass_library
);
809 current_module
="exit_player";
811 // free mplayer config
813 m_config_free(mpctx
->mconfig
);
814 mpctx
->mconfig
= NULL
;
816 if(mpctx
->playtree_iter
)
817 play_tree_iter_free(mpctx
->playtree_iter
);
818 mpctx
->playtree_iter
= NULL
;
820 play_tree_free(mpctx
->playtree
, 1);
821 mpctx
->playtree
= NULL
;
823 talloc_free(mpctx
->key_fifo
);
825 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
829 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Quit");
830 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=QUIT\n");
833 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","End of file");
834 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=EOF\n");
837 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Fatal error");
838 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=ERROR\n");
841 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=NONE\n");
843 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
848 static void exit_player(struct MPContext
*mpctx
, enum exit_reason how
)
850 exit_player_with_rc(mpctx
, how
, 1);
854 static void child_sighandler(int x
){
856 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
860 #ifdef CONFIG_CRASH_DEBUG
861 static char *prog_path
;
862 static int crash_debug
= 0;
865 static void exit_sighandler(int x
){
866 static int sig_count
=0;
867 #ifdef CONFIG_CRASH_DEBUG
868 if (!crash_debug
|| x
!= SIGTRAP
)
873 /* We're crashing bad and can't uninit cleanly :(
874 * by popular request, we make one last (dirty)
875 * effort to restore the user's
880 if(sig_count
==6) exit(1);
884 kill(getpid(),SIGKILL
);
887 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, "\n");
888 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,
889 "\nMPlayer interrupted by signal %d in module: %s\n", x
,
890 current_module
? current_module
: "unknown");
891 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
899 async_quit_request
= 1;
900 return; // killed from keyboard (^C) or killed [-9]
902 #if CONFIG_RUNTIME_CPUDETECT
903 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL_RTCpuSel
);
905 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL
);
909 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGSEGV_SIGFPE
);
911 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGCRASH
);
912 #ifdef CONFIG_CRASH_DEBUG
915 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
917 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
918 if (gdb_pid
== 0) { // We are the child
920 snprintf(spid
, sizeof(spid
), "%i", getppid());
921 getch2_disable(); // allow terminal to work properly with gdb
922 if (execlp("gdb", "gdb", prog_path
, spid
, "-ex", "bt", NULL
) == -1)
923 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
924 } else if (gdb_pid
< 0)
925 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
927 waitpid(gdb_pid
, NULL
, 0);
929 if (x
== SIGTRAP
) return;
937 #include "cfg-mplayer.h"
939 static int cfg_include(m_option_t
*conf
, char *filename
)
941 return m_config_parse_config_file(conf
->priv
, filename
);
944 static void parse_cfgfiles(struct MPContext
*mpctx
, m_config_t
* conf
)
948 if (!disable_system_conf
&&
949 m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
950 exit_player(mpctx
, EXIT_NONE
);
951 if ((conffile
= get_path("")) == NULL
) {
952 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"Cannot find HOME directory.\n");
957 mkdir(conffile
, 0777);
960 if ((conffile
= get_path("config")) == NULL
) {
961 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"get_path(\"config\") problem\n");
963 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
964 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Creating config file: %s\n", conffile
);
965 write(conffile_fd
, default_config
, strlen(default_config
));
968 if (!disable_user_conf
&&
969 m_config_parse_config_file(conf
, conffile
) < 0)
970 exit_player(mpctx
, EXIT_NONE
);
976 #define PROFILE_CFG_PROTOCOL "protocol."
978 static void load_per_protocol_config (m_config_t
* conf
, const char *const file
)
981 char protocol
[strlen (PROFILE_CFG_PROTOCOL
) + strlen (file
) + 1];
984 /* does filename actually uses a protocol ? */
985 str
= strstr (file
, "://");
989 sprintf (protocol
, "%s%s", PROFILE_CFG_PROTOCOL
, file
);
990 protocol
[strlen (PROFILE_CFG_PROTOCOL
)+strlen(file
)-strlen(str
)] = '\0';
991 p
= m_config_get_profile (conf
, protocol
);
994 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading protocol-related profile '%s'\n", protocol
);
995 m_config_set_profile(conf
,p
);
999 #define PROFILE_CFG_EXTENSION "extension."
1001 static void load_per_extension_config (m_config_t
* conf
, const char *const file
)
1004 char extension
[strlen (PROFILE_CFG_EXTENSION
) + 8];
1007 /* does filename actually have an extension ? */
1008 str
= strrchr (file
, '.');
1012 sprintf (extension
, PROFILE_CFG_EXTENSION
);
1013 strncat (extension
, ++str
, 7);
1014 p
= m_config_get_profile (conf
, extension
);
1017 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", extension
);
1018 m_config_set_profile(conf
,p
);
1022 #define PROFILE_CFG_VO "vo."
1023 #define PROFILE_CFG_AO "ao."
1025 static void load_per_output_config (m_config_t
* conf
, char *cfg
, char *out
)
1027 char profile
[strlen (cfg
) + strlen (out
) + 1];
1030 sprintf (profile
, "%s%s", cfg
, out
);
1031 p
= m_config_get_profile (conf
, profile
);
1034 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", profile
);
1035 m_config_set_profile(conf
,p
);
1040 * Tries to load a config file
1041 * @return 0 if file was not found, 1 otherwise
1043 static int try_load_config(m_config_t
*conf
, const char *file
)
1046 if (stat(file
, &st
))
1048 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Loading config '%s'\n", file
);
1049 m_config_parse_config_file (conf
, file
);
1053 static void load_per_file_config (m_config_t
* conf
, const char *const file
)
1059 if (strlen(file
) > PATH_MAX
- 14) {
1060 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Filename is too long, can not load file or directory specific config files\n");
1063 sprintf (cfg
, "%s.conf", file
);
1065 name
= strrchr(cfg
, '/');
1066 if (HAVE_DOS_PATHS
) {
1067 char *tmp
= strrchr(cfg
, '\\');
1068 if (!name
|| tmp
> name
)
1070 tmp
= strrchr(cfg
, ':');
1071 if (!name
|| tmp
> name
)
1079 if (use_filedir_conf
) {
1080 char dircfg
[PATH_MAX
];
1081 strcpy(dircfg
, cfg
);
1082 strcpy(dircfg
+ (name
- cfg
), "mplayer.conf");
1083 try_load_config(conf
, dircfg
);
1085 if (try_load_config(conf
, cfg
))
1089 if ((confpath
= get_path (name
)) != NULL
)
1091 try_load_config(conf
, confpath
);
1097 /* When libmpdemux performs a blocking operation (network connection or
1098 * cache filling) if the operation fails we use this function to check
1099 * if it was interrupted by the user.
1100 * The function returns a new value for eof. */
1101 static int libmpdemux_was_interrupted(struct MPContext
*mpctx
, int stop_play
)
1104 if((cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0)) != NULL
) {
1107 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
1108 case MP_CMD_PLAY_TREE_STEP
: {
1109 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
1110 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
1112 case MP_CMD_PLAY_TREE_UP_STEP
: {
1113 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
1115 case MP_CMD_PLAY_ALT_SRC_STEP
: {
1116 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
1124 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
1126 static int playtree_add_playlist(struct MPContext
*mpctx
, play_tree_t
* entry
)
1128 play_tree_add_bpf(entry
,mpctx
->filename
);
1132 entry
= mpctx
->playtree_iter
->tree
;
1133 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1134 return PT_NEXT_ENTRY
;
1136 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
1137 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1138 return PT_NEXT_ENTRY
;
1141 play_tree_remove(entry
,1,1);
1144 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
1145 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
1146 entry
= mpctx
->playtree_iter
->tree
;
1147 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1148 return PT_NEXT_ENTRY
;
1150 play_tree_remove(entry
,1,1);
1155 void add_subtitles(struct MPContext
*mpctx
, char *filename
, float fps
, int noerr
)
1157 struct MPOpts
*opts
= &mpctx
->opts
;
1158 sub_data
*subd
= NULL
;
1159 struct ass_track
*asst
= NULL
;
1161 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
1166 if (opts
->ass_enabled
) {
1168 asst
= ass_read_stream(ass_library
, filename
, sub_cp
);
1170 asst
= ass_read_stream(ass_library
, filename
, 0);
1173 subd
= sub_read_file(filename
, fps
);
1175 asst
= ass_read_subdata(ass_library
, subd
, fps
);
1184 subd
= sub_read_file(filename
, fps
);
1187 if (!asst
&& !subd
) {
1188 mp_tmsg(MSGT_CPLAYER
, noerr
? MSGL_WARN
: MSGL_ERR
,
1189 "Cannot load subtitles: %s\n", filename_recode(filename
));
1193 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
1194 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
1195 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
1196 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
1197 filename_recode(filename
));
1198 ++mpctx
->set_of_sub_size
;
1199 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "SUB: Added subtitle file (%d): %s\n", mpctx
->set_of_sub_size
,
1200 filename_recode(filename
));
1203 void init_vo_spudec(struct MPContext
*mpctx
)
1206 spudec_free(vo_spudec
);
1207 mpctx
->initialized_flags
&= ~INITIALIZED_SPUDEC
;
1210 // we currently can't work without video stream
1211 if (!mpctx
->sh_video
)
1215 unsigned int palette
[16], width
, height
;
1216 current_module
="spudec_init_vobsub";
1217 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1218 vo_spudec
=spudec_new_scaled(palette
, width
, height
, NULL
, 0);
1221 #ifdef CONFIG_DVDREAD
1222 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1223 current_module
="spudec_init_dvdread";
1224 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1225 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
,
1230 #ifdef CONFIG_DVDNAV
1231 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1232 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1233 current_module
="spudec_init_dvdnav";
1234 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, NULL
, 0);
1238 if (vo_spudec
==NULL
) {
1239 sh_sub_t
*sh
= mpctx
->d_sub
->sh
;
1240 current_module
="spudec_init_normal";
1241 vo_spudec
=spudec_new_scaled(NULL
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, sh
->extradata
, sh
->extradata_len
);
1242 spudec_set_font_factor(vo_spudec
,font_factor
);
1245 if (vo_spudec
!=NULL
) {
1246 mpctx
->initialized_flags
|=INITIALIZED_SPUDEC
;
1247 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
1252 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1253 * make it all work is to use the builtin SDL-bootstrap code, which
1254 * will be done automatically by replacing our main() if we include SDL.h.
1256 #if defined(__APPLE__) && defined(CONFIG_SDL)
1257 #ifdef CONFIG_SDL_SDL_H
1258 #include <SDL/SDL.h>
1265 * \brief append a formatted string
1266 * \param buf buffer to print into
1267 * \param pos position of terminating 0 in buf
1268 * \param len maximum number of characters in buf, not including terminating 0
1269 * \param format printf format string
1271 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1274 va_start(va
, format
);
1275 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1284 * \brief append time in the hh:mm:ss.f format
1285 * \param buf buffer to print into
1286 * \param pos position of terminating 0 in buf
1287 * \param len maximum number of characters in buf, not including terminating 0
1288 * \param time time value to convert/append
1290 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1291 int64_t tenths
= 10 * time
;
1292 int f1
= tenths
% 10;
1293 int ss
= (tenths
/ 10) % 60;
1294 int mm
= (tenths
/ 600) % 60;
1295 int hh
= tenths
/ 36000;
1297 saddf(buf
, pos
, len
, "unknown");
1301 saddf(buf
, pos
, len
, "%2d:", hh
);
1302 if (hh
> 0 || mm
> 0)
1303 saddf(buf
, pos
, len
, "%02d:", mm
);
1304 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1307 static void print_status(struct MPContext
*mpctx
, double a_pos
, bool at_frame
)
1309 struct MPOpts
*opts
= &mpctx
->opts
;
1310 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1312 if (mpctx
->sh_audio
&& a_pos
== MP_NOPTS_VALUE
)
1313 a_pos
= playing_audio_pts(mpctx
);
1314 if (mpctx
->sh_audio
&& sh_video
&& at_frame
) {
1315 mpctx
->last_av_difference
= a_pos
- sh_video
->pts
- audio_delay
;
1316 if (mpctx
->time_frame
> 0)
1317 mpctx
->last_av_difference
+= mpctx
->time_frame
* opts
->playback_speed
;
1318 if (mpctx
->last_av_difference
> 0.5 && drop_frame_cnt
> 50
1319 && !mpctx
->drop_message_shown
) {
1320 mp_tmsg(MSGT_AVSYNC
,MSGL_WARN
,SystemTooSlow
);
1321 mpctx
->drop_message_shown
= true;
1332 if (screen_width
> 0)
1333 width
= screen_width
;
1336 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
1337 /* Windows command line is broken (MinGW's rxvt works, but we
1338 * should not depend on that). */
1341 line
= malloc(width
+ 1); // one additional char for the terminating null
1344 if (mpctx
->sh_audio
) {
1345 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1347 float len
= demuxer_get_time_length(mpctx
->demuxer
);
1348 saddf(line
, &pos
, width
, "(");
1349 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1350 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1351 sadd_hhmmssf(line
, &pos
, width
, len
);
1352 saddf(line
, &pos
, width
, ") ");
1358 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1361 if (mpctx
->sh_audio
&& sh_video
)
1362 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ",
1363 mpctx
->last_av_difference
, mpctx
->total_avsync_change
);
1367 saddf(line
, &pos
, width
, "%3d/%3d ",
1368 (int)sh_video
->num_frames
,
1369 (int)sh_video
->num_frames_decoded
);
1373 if (sh_video
->timer
> 0.5)
1374 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1375 (int)(100.0*video_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1376 (int)(100.0*vout_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1377 (100.0*audio_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
));
1379 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1380 } else if (mpctx
->sh_audio
) {
1381 if (mpctx
->delay
> 0.5)
1382 saddf(line
, &pos
, width
, "%4.1f%% ",
1383 100.0*audio_time_usage
/(double)mpctx
->delay
);
1385 saddf(line
, &pos
, width
, "??,?%% ");
1390 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1392 #ifdef CONFIG_STREAM_CACHE
1394 if (stream_cache_size
> 0)
1395 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1399 if (opts
->playback_speed
!= 1)
1400 saddf(line
, &pos
, width
, "%4.2fx ", opts
->playback_speed
);
1403 if (erase_to_end_of_line
) {
1405 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1407 memset(&line
[pos
], ' ', width
- pos
);
1409 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s\r", line
);
1415 * \brief build a chain of audio filters that converts the input format
1416 * to the ao's format, taking into account the current playback_speed.
1417 * \param sh_audio describes the requested input format of the chain.
1418 * \param ao_data describes the requested output format of the chain.
1420 int build_afilter_chain(struct MPContext
*mpctx
, sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1422 struct MPOpts
*opts
= &mpctx
->opts
;
1427 mpctx
->mixer
.afilter
= NULL
;
1430 if(af_control_any_rev(sh_audio
->afilter
,
1431 AF_CONTROL_PLAYBACK_SPEED
| AF_CONTROL_SET
,
1432 &opts
->playback_speed
)) {
1433 new_srate
= sh_audio
->samplerate
;
1435 new_srate
= sh_audio
->samplerate
* opts
->playback_speed
;
1436 if (new_srate
!= ao_data
->samplerate
) {
1437 // limits are taken from libaf/af_resample.c
1438 if (new_srate
< 8000)
1440 if (new_srate
> 192000)
1442 opts
->playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1445 result
= init_audio_filters(sh_audio
, new_srate
,
1446 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
);
1447 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1452 typedef struct mp_osd_msg mp_osd_msg_t
;
1454 /// Previous message on the stack.
1458 int id
,level
,started
;
1459 /// Display duration in ms.
1463 /// OSD message stack.
1464 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1467 * \brief Add a message on the OSD message stack
1469 * If a message with the same id is already present in the stack
1470 * it is pulled on top of the stack, otherwise a new message is created.
1473 static void set_osd_msg_va(int id
, int level
, int time
, const char *fmt
,
1476 mp_osd_msg_t
*msg
,*last
=NULL
;
1479 // look if the id is already in the stack
1480 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1481 last
= msg
, msg
= msg
->prev
);
1482 // not found: alloc it
1484 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1485 msg
->prev
= osd_msg_stack
;
1486 osd_msg_stack
= msg
;
1487 } else if(last
) { // found, but it's not on top of the stack
1488 last
->prev
= msg
->prev
;
1489 msg
->prev
= osd_msg_stack
;
1490 osd_msg_stack
= msg
;
1493 r
= vsnprintf(msg
->msg
, 128, fmt
, ap
);
1494 if(r
>= 128) msg
->msg
[127] = 0;
1502 void set_osd_msg(int id
, int level
, int time
, const char *fmt
, ...)
1506 set_osd_msg_va(id
, level
, time
, fmt
, ap
);
1510 void set_osd_tmsg(int id
, int level
, int time
, const char *fmt
, ...)
1514 set_osd_msg_va(id
, level
, time
, mp_gtext(fmt
), ap
);
1520 * \brief Remove a message from the OSD stack
1522 * This function can be used to get rid of a message right away.
1526 void rm_osd_msg(int id
) {
1527 mp_osd_msg_t
*msg
,*last
=NULL
;
1529 // Search for the msg
1530 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1531 last
= msg
, msg
= msg
->prev
);
1534 // Detach it from the stack and free it
1536 last
->prev
= msg
->prev
;
1538 osd_msg_stack
= msg
->prev
;
1543 * \brief Remove all messages from the OSD stack
1547 static void clear_osd_msgs(void) {
1548 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1554 osd_msg_stack
= NULL
;
1558 * \brief Get the current message from the OSD stack.
1560 * This function decrements the message timer and destroys the old ones.
1561 * The message that should be displayed is returned (if any).
1565 static mp_osd_msg_t
* get_osd_msg(struct MPContext
*mpctx
)
1567 struct MPOpts
*opts
= &mpctx
->opts
;
1568 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1569 static unsigned last_update
= 0;
1570 unsigned now
= GetTimerMS();
1572 char hidden_dec_done
= 0;
1574 if (mpctx
->osd_visible
) {
1575 // 36000000 means max timed visibility is 1 hour into the future, if
1576 // the difference is greater assume it's wrapped around from below 0
1577 if (mpctx
->osd_visible
- now
> 36000000) {
1578 mpctx
->osd_visible
= 0;
1579 vo_osd_progbar_type
= -1; // disable
1580 vo_osd_changed(OSDTYPE_PROGBAR
);
1581 mpctx
->osd_function
= mpctx
->paused
? OSD_PAUSE
: OSD_PLAY
;
1584 if (mpctx
->osd_show_percentage_until
- now
> 36000000)
1585 mpctx
->osd_show_percentage_until
= 0;
1587 if(!last_update
) last_update
= now
;
1588 diff
= now
>= last_update
? now
- last_update
: 0;
1592 // Look for the first message in the stack with high enough level.
1593 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1595 if (msg
->level
> opts
->osd_level
&& hidden_dec_done
)
1597 // The message has a high enough level or it is the first hidden one
1598 // in both cases we decrement the timer or kill it.
1599 if(!msg
->started
|| msg
->time
> diff
) {
1600 if(msg
->started
) msg
->time
-= diff
;
1601 else msg
->started
= 1;
1603 if (msg
->level
<= opts
->osd_level
)
1605 hidden_dec_done
= 1;
1614 osd_msg_stack
= prev
;
1623 * \brief Display the OSD bar.
1625 * Display the OSD bar or fall back on a simple message.
1629 void set_osd_bar(struct MPContext
*mpctx
, int type
,const char* name
,double min
,double max
,double val
) {
1630 struct MPOpts
*opts
= &mpctx
->opts
;
1631 if (opts
->osd_level
< 1)
1634 if(mpctx
->sh_video
) {
1635 mpctx
->osd_visible
= (GetTimerMS() + 1000) | 1;
1636 vo_osd_progbar_type
= type
;
1637 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1638 vo_osd_changed(OSDTYPE_PROGBAR
);
1642 set_osd_msg(OSD_MSG_BAR
, 1, opts
->osd_duration
, "%s: %d %%",
1643 name
, ROUND(100*(val
-min
)/(max
-min
)));
1647 * \brief Display text subtitles on the OSD
1649 void set_osd_subtitle(struct MPContext
*mpctx
, subtitle
*subs
)
1653 vo_osd_changed(OSDTYPE_SUBTITLE
);
1654 if (!mpctx
->sh_video
) {
1655 // reverse order, since newest set_osd_msg is displayed first
1656 for (i
= SUB_MAX_TEXT
- 1; i
>= 0; i
--) {
1657 if (!subs
|| i
>= subs
->lines
|| !subs
->text
[i
])
1658 rm_osd_msg(OSD_MSG_SUB_BASE
+ i
);
1660 // HACK: currently display time for each sub line except the last is set to 2 seconds.
1661 int display_time
= i
== subs
->lines
- 1 ? 180000 : 2000;
1662 set_osd_msg(OSD_MSG_SUB_BASE
+ i
, 1, display_time
, "%s", subs
->text
[i
]);
1669 * \brief Update the OSD message line.
1671 * This function displays the current message on the vo OSD or on the term.
1672 * If the stack is empty and the OSD level is high enough the timer
1673 * is displayed (only on the vo OSD).
1677 static void update_osd_msg(struct MPContext
*mpctx
)
1679 struct MPOpts
*opts
= &mpctx
->opts
;
1681 struct osd_state
*osd
= mpctx
->osd
;
1682 char osd_text_timer
[128];
1684 if (mpctx
->add_osd_seek_info
) {
1686 if (mpctx
->timeline
&& mpctx
->sh_video
)
1687 percentage
= mpctx
->sh_video
->pts
* 100 /
1688 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1690 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1691 set_osd_bar(mpctx
, 0, "Position", 0, 100, percentage
);
1692 if (mpctx
->sh_video
)
1693 mpctx
->osd_show_percentage_until
= (GetTimerMS() + 1000) | 1;
1694 mpctx
->add_osd_seek_info
= false;
1697 // Look if we have a msg
1698 if((msg
= get_osd_msg(mpctx
))) {
1699 if (strcmp(osd
->osd_text
, msg
->msg
)) {
1700 strncpy(osd
->osd_text
, msg
->msg
, 127);
1701 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1702 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1707 if(mpctx
->sh_video
) {
1708 // fallback on the timer
1709 if (opts
->osd_level
>= 2) {
1711 if (mpctx
->timeline
)
1712 len
= mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1714 len
= demuxer_get_time_length(mpctx
->demuxer
);
1715 int percentage
= -1;
1716 char percentage_text
[10];
1717 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1719 if (mpctx
->osd_show_percentage_until
) {
1720 if (mpctx
->timeline
)
1721 percentage
= mpctx
->sh_video
->pts
* 100 /
1722 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1724 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1727 if (percentage
>= 0)
1728 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1730 percentage_text
[0] = 0;
1732 if (opts
->osd_level
== 3)
1733 snprintf(osd_text_timer
, 63,
1734 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1735 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1736 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1738 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1739 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1740 pts
%60,percentage_text
);
1742 osd_text_timer
[0]=0;
1744 if (strcmp(osd
->osd_text
, osd_text_timer
)) {
1745 strncpy(osd
->osd_text
, osd_text_timer
, 63);
1746 vo_osd_changed(OSDTYPE_OSD
);
1751 // Clear the term osd line
1752 if (term_osd
&& osd
->osd_text
[0]) {
1753 osd
->osd_text
[0] = 0;
1754 printf("%s\n",term_osd_esc
);
1762 void reinit_audio_chain(struct MPContext
*mpctx
)
1764 struct MPOpts
*opts
= &mpctx
->opts
;
1765 if (!mpctx
->sh_audio
)
1767 if (!(mpctx
->initialized_flags
& INITIALIZED_ACODEC
)) {
1768 current_module
="init_audio_codec";
1769 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1770 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1773 mpctx
->initialized_flags
|=INITIALIZED_ACODEC
;
1774 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1778 if (!(mpctx
->initialized_flags
& INITIALIZED_AO
)) {
1779 current_module
="af_preinit";
1780 ao_data
.samplerate
=force_srate
;
1782 ao_data
.format
=audio_output_format
;
1783 // first init to detect best values
1784 if(!init_audio_filters(mpctx
->sh_audio
, // preliminary init
1786 mpctx
->sh_audio
->samplerate
,
1788 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1789 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
, "Error at audio filter chain "
1791 exit_player(mpctx
, EXIT_ERROR
);
1793 current_module
="ao2_init";
1794 mpctx
->audio_out
= init_best_audio_out(opts
->audio_driver_list
,
1799 if(!mpctx
->audio_out
){
1800 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Could not open/initialize audio device -> no sound.\n");
1803 mpctx
->initialized_flags
|=INITIALIZED_AO
;
1804 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1805 mpctx
->audio_out
->info
->short_name
,
1806 ao_data
.samplerate
, ao_data
.channels
,
1807 af_fmt2str_short(ao_data
.format
),
1808 af_fmt2bits(ao_data
.format
)/8 );
1809 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1810 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1811 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1812 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1815 // init audio filters:
1816 current_module
="af_init";
1817 if(!build_afilter_chain(mpctx
, mpctx
->sh_audio
, &ao_data
)) {
1818 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Couldn't find matching filter/ao format!\n");
1821 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1822 mpctx
->mixer
.volstep
= volstep
;
1826 uninit_player(mpctx
, INITIALIZED_ACODEC
|INITIALIZED_AO
); // close codec and possibly AO
1827 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1828 mpctx
->d_audio
->id
= -2;
1836 // Return pts value corresponding to the end point of audio written to the
1838 static double written_audio_pts(struct MPContext
*mpctx
)
1840 sh_audio_t
*sh_audio
= mpctx
->sh_audio
;
1841 demux_stream_t
*d_audio
= mpctx
->d_audio
;
1842 double buffered_output
;
1843 // first calculate the end pts of audio that has been output by decoder
1844 double a_pts
= sh_audio
->pts
;
1845 if (a_pts
!= MP_NOPTS_VALUE
)
1846 // Good, decoder supports new way of calculating audio pts.
1847 // sh_audio->pts is the timestamp of the latest input packet with
1848 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1849 // the amount of bytes the decoder has written after that timestamp.
1850 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1852 // Decoder doesn't support new way of calculating pts (or we're
1853 // being called before it has decoded anything with known timestamp).
1854 // Use the old method of audio pts calculation: take the timestamp
1855 // of last packet with known pts the decoder has read data from,
1856 // and add amount of bytes read after the beginning of that packet
1857 // divided by input bps. This will be inaccurate if the input/output
1858 // ratio is not constant for every audio packet or if it is constant
1859 // but not accurately known in sh_audio->i_bps.
1861 a_pts
= d_audio
->pts
;
1862 // ds_tell_pts returns bytes read after last timestamp from
1863 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1864 // it has read but not decoded
1865 if (sh_audio
->i_bps
)
1866 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1867 (double)sh_audio
->i_bps
;
1869 // Now a_pts hopefully holds the pts for end of audio from decoder.
1870 // Substract data in buffers between decoder and audio out.
1872 // Decoded but not filtered
1873 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1875 // Data buffered in audio filters, measured in bytes of "missing" output
1876 buffered_output
= af_calc_delay(sh_audio
->afilter
);
1878 // Data that was ready for ao but was buffered because ao didn't fully
1879 // accept everything to internal buffers yet
1880 buffered_output
+= sh_audio
->a_out_buffer_len
;
1882 // Filters divide audio length by playback_speed, so multiply by it
1883 // to get the length in original units without speedup or slowdown
1884 a_pts
-= buffered_output
* mpctx
->opts
.playback_speed
/ ao_data
.bps
;
1886 return a_pts
+ mpctx
->video_offset
;
1889 // Return pts value corresponding to currently playing audio.
1890 double playing_audio_pts(struct MPContext
*mpctx
)
1892 return written_audio_pts(mpctx
) - mpctx
->opts
.playback_speed
*
1893 mpctx
->audio_out
->get_delay();
1896 static int check_framedrop(struct MPContext
*mpctx
, double frame_time
) {
1897 struct MPOpts
*opts
= &mpctx
->opts
;
1898 // check for frame-drop:
1899 current_module
= "check_framedrop";
1900 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1901 static int dropped_frames
;
1902 float delay
= opts
->playback_speed
*mpctx
->audio_out
->get_delay();
1903 float d
= delay
-mpctx
->delay
;
1905 // we should avoid dropping too many frames in sequence unless we
1906 // are too late. and we allow 100ms A-V delay here:
1907 if (d
< -dropped_frames
*frame_time
-0.100 && !mpctx
->paused
1908 && !mpctx
->update_video_immediately
) {
1911 return frame_dropping
;
1923 static float timing_sleep(struct MPContext
*mpctx
, float time_frame
)
1927 // -------- RTC -----------
1928 current_module
="sleep_rtc";
1929 while (time_frame
> 0.000) {
1930 unsigned long rtc_ts
;
1931 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1932 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC read error: %s\n", strerror(errno
));
1933 time_frame
-= get_relative_time(mpctx
);
1938 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1939 // unnecessarily high CPU usage
1940 float margin
= softsleep
? 0.011 : 0;
1941 current_module
= "sleep_timer";
1942 while (time_frame
> margin
) {
1943 usec_sleep(1000000 * (time_frame
- margin
));
1944 time_frame
-= get_relative_time(mpctx
);
1947 current_module
= "sleep_soft";
1949 mp_tmsg(MSGT_AVSYNC
, MSGL_WARN
, "Warning! Softsleep underflow!\n");
1950 while (time_frame
> 0)
1951 time_frame
-= get_relative_time(mpctx
); // burn the CPU
1957 static int select_subtitle(MPContext
*mpctx
)
1959 struct MPOpts
*opts
= &mpctx
->opts
;
1960 // find the best sub to use
1963 mpctx
->global_sub_pos
= -1; // no subs by default
1964 if (vobsub_id
>= 0) {
1965 // if user asks for a vobsub id, use that first.
1967 found
= mp_property_do("sub_vob", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1970 if (!found
&& opts
->sub_id
>= 0) {
1971 // if user asks for a dvd sub id, use that next.
1973 found
= mp_property_do("sub_demux", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1977 // if there are text subs to use, use those. (autosubs come last here)
1979 found
= mp_property_do("sub_file", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1982 if (!found
&& opts
->sub_id
== -1) {
1983 // finally select subs by language and container hints
1984 if (opts
->sub_id
== -1 && opts
->sub_lang
)
1985 opts
->sub_id
= demuxer_sub_track_by_lang(mpctx
->demuxer
, opts
->sub_lang
);
1986 if (opts
->sub_id
== -1)
1987 opts
->sub_id
= demuxer_default_sub_track(mpctx
->demuxer
);
1988 if (opts
->sub_id
>= 0) {
1990 found
= mp_property_do("sub_demux", M_PROPERTY_SET
, &id
, mpctx
) == M_PROPERTY_OK
;
1996 #ifdef CONFIG_DVDNAV
2000 /// store decoded video image
2001 static mp_image_t
* mp_dvdnav_copy_mpi(mp_image_t
*to_mpi
,
2002 mp_image_t
*from_mpi
) {
2005 /// Do not store B-frames
2006 if (from_mpi
->pict_type
== FF_B_TYPE
)
2010 to_mpi
->w
== from_mpi
->w
&&
2011 to_mpi
->h
== from_mpi
->h
&&
2012 to_mpi
->imgfmt
== from_mpi
->imgfmt
)
2016 free_mp_image(to_mpi
);
2017 if (from_mpi
->w
== 0 || from_mpi
->h
== 0)
2019 mpi
= alloc_mpi(from_mpi
->w
,from_mpi
->h
,from_mpi
->imgfmt
);
2022 copy_mpi(mpi
,from_mpi
);
2026 static void mp_dvdnav_reset_stream (MPContext
*ctx
) {
2027 struct MPOpts
*opts
= &ctx
->opts
;
2028 if (ctx
->sh_video
) {
2030 ctx
->d_video
->pts
= 0.0f
;
2031 ctx
->sh_video
->pts
= 0.0f
;
2032 ctx
->sh_video
->i_pts
= 0.0f
;
2033 ctx
->sh_video
->last_pts
= 0.0f
;
2034 ctx
->sh_video
->num_buffered_pts
= 0;
2035 ctx
->sh_video
->num_frames
= 0;
2036 ctx
->sh_video
->num_frames_decoded
= 0;
2037 ctx
->sh_video
->timer
= 0.0f
;
2038 ctx
->sh_video
->stream_delay
= 0.0f
;
2039 ctx
->sh_video
->timer
= 0;
2040 ctx
->demuxer
->stream_pts
= MP_NOPTS_VALUE
;
2043 if (ctx
->sh_audio
) {
2044 /// free audio packets and reset
2045 ds_free_packs(ctx
->d_audio
);
2046 audio_delay
-= ctx
->sh_audio
->stream_delay
;
2047 ctx
->delay
=- audio_delay
;
2048 ctx
->audio_out
->reset();
2049 resync_audio_stream(ctx
->sh_audio
);
2053 ctx
->sub_counts
[SUB_SOURCE_DEMUX
] = mp_dvdnav_number_of_subs(ctx
->stream
);
2054 if (opts
->sub_lang
&& opts
->sub_id
== dvdsub_lang_id
) {
2055 dvdsub_lang_id
= mp_dvdnav_sid_from_lang(ctx
->stream
, opts
->sub_lang
);
2056 if (dvdsub_lang_id
!= opts
->sub_id
) {
2057 opts
->sub_id
= dvdsub_lang_id
;
2058 select_subtitle(ctx
);
2062 /// clear all EOF related flags
2063 ctx
->d_video
->eof
= ctx
->d_audio
->eof
= ctx
->stream
->eof
= 0;
2066 /// Restore last decoded DVDNAV (still frame)
2067 static mp_image_t
*mp_dvdnav_restore_smpi(struct MPContext
*mpctx
,
2069 unsigned char **start
,
2070 mp_image_t
*decoded_frame
)
2072 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
2073 return decoded_frame
;
2075 /// a change occured in dvdnav stream
2076 if (mp_dvdnav_cell_has_changed(mpctx
->stream
,0)) {
2077 mp_dvdnav_read_wait(mpctx
->stream
, 1, 1);
2078 mp_dvdnav_context_free(mpctx
);
2079 mp_dvdnav_reset_stream(mpctx
);
2080 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
2081 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
2087 /// Display still frame, if any
2088 if (mpctx
->nav_smpi
&& !mpctx
->nav_buffer
)
2089 decoded_frame
= mpctx
->nav_smpi
;
2091 /// increment video frame : continue playing after still frame
2092 len
= demuxer_get_time_length(mpctx
->demuxer
);
2093 if (mpctx
->sh_video
->pts
>= len
&&
2094 mpctx
->sh_video
->pts
> 0.0 && len
> 0.0) {
2095 mp_dvdnav_skip_still(mpctx
->stream
);
2096 mp_dvdnav_skip_wait(mpctx
->stream
);
2098 mpctx
->sh_video
->pts
+= 1 / mpctx
->sh_video
->fps
;
2100 if (mpctx
->nav_buffer
) {
2101 *start
= mpctx
->nav_start
;
2102 *in_size
= mpctx
->nav_in_size
;
2103 if (mpctx
->nav_start
)
2104 memcpy(*start
,mpctx
->nav_buffer
,mpctx
->nav_in_size
);
2108 return decoded_frame
;
2111 /// Save last decoded DVDNAV (still frame)
2112 static void mp_dvdnav_save_smpi(struct MPContext
*mpctx
, int in_size
,
2113 unsigned char *start
,
2114 mp_image_t
*decoded_frame
)
2116 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
2119 if (mpctx
->nav_buffer
)
2120 free(mpctx
->nav_buffer
);
2122 mpctx
->nav_buffer
= malloc(in_size
);
2123 mpctx
->nav_start
= start
;
2124 mpctx
->nav_in_size
= mpctx
->nav_buffer
? in_size
: -1;
2125 if (mpctx
->nav_buffer
)
2126 memcpy(mpctx
->nav_buffer
,start
,in_size
);
2128 if (decoded_frame
&& mpctx
->nav_smpi
!= decoded_frame
)
2129 mpctx
->nav_smpi
= mp_dvdnav_copy_mpi(mpctx
->nav_smpi
,decoded_frame
);
2131 #endif /* CONFIG_DVDNAV */
2133 /* Modify video timing to match the audio timeline. There are two main
2134 * reasons this is needed. First, video and audio can start from different
2135 * positions at beginning of file or after a seek (MPlayer starts both
2136 * immediately even if they have different pts). Second, the file can have
2137 * audio timestamps that are inconsistent with the duration of the audio
2138 * packets, for example two consecutive timestamp values differing by
2139 * one second but only a packet with enough samples for half a second
2140 * of playback between them.
2142 static void adjust_sync(struct MPContext
*mpctx
, double frame_time
)
2144 current_module
= "av_sync";
2146 if (!mpctx
->sh_audio
)
2149 double a_pts
= written_audio_pts(mpctx
) - mpctx
->delay
;
2150 double v_pts
= mpctx
->sh_video
->pts
;
2151 double av_delay
= a_pts
- v_pts
;
2152 // Try to sync vo_flip() so it will *finish* at given time
2153 av_delay
+= mpctx
->last_vo_flip_duration
;
2154 av_delay
-= audio_delay
; // This much pts difference is desired
2156 double change
= av_delay
* 0.1;
2157 double max_change
= default_max_pts_correction
>= 0 ?
2158 default_max_pts_correction
: frame_time
* 0.1;
2159 if (change
< -max_change
)
2160 change
= -max_change
;
2161 else if (change
> max_change
)
2162 change
= max_change
;
2163 mpctx
->delay
+= change
;
2164 mpctx
->total_avsync_change
+= change
;
2167 static int fill_audio_out_buffers(struct MPContext
*mpctx
)
2169 struct MPOpts
*opts
= &mpctx
->opts
;
2175 bool format_change
= false;
2176 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
2178 current_module
="play_audio";
2182 // all the current uses of ao_data.pts seem to be in aos that handle
2183 // sync completely wrong; there should be no need to use ao_data.pts
2185 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2186 playsize
= mpctx
->audio_out
->get_space();
2187 if (mpctx
->sh_video
|| playsize
>= ao_data
.outburst
)
2190 // handle audio-only case:
2191 // this is where mplayer sleeps during audio-only playback
2192 // to avoid 100% CPU use
2193 sleep_time
= (ao_data
.outburst
- playsize
) * 1000 / ao_data
.bps
;
2194 if (sleep_time
< 10) sleep_time
= 10; // limit to 100 wakeups per second
2195 usec_sleep(sleep_time
* 1000);
2198 // Fill buffer if needed:
2199 current_module
="decode_audio";
2201 int res
= decode_audio(sh_audio
, playsize
);
2202 if (res
< 0) { // EOF, error or format change
2204 format_change
= true;
2205 else if (mpctx
->d_audio
->eof
) {
2207 if (sh_audio
->a_out_buffer_len
== 0)
2212 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2213 if (playsize
> sh_audio
->a_out_buffer_len
) {
2214 playsize
= sh_audio
->a_out_buffer_len
;
2216 playflags
|= AOPLAY_FINAL_CHUNK
;
2222 current_module
="play_audio";
2224 // Is this pts value actually useful for the aos that access it?
2225 // They're obviously badly broken in the way they handle av sync;
2226 // would not having access to this make them more broken?
2227 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2228 playsize
= mpctx
->audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
2231 sh_audio
->a_out_buffer_len
-= playsize
;
2232 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
2233 sh_audio
->a_out_buffer_len
);
2234 mpctx
->delay
+= opts
->playback_speed
*playsize
/(double)ao_data
.bps
;
2236 else if (audio_eof
&& mpctx
->audio_out
->get_delay() < .04) {
2237 // Sanity check to avoid hanging in case current ao doesn't output
2238 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
2239 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
2240 sh_audio
->a_out_buffer_len
= 0;
2243 /* The format change isn't handled too gracefully. A more precise
2244 * implementation would require draining buffered old-format audio
2245 * while displaying video, then doing the output format switch.
2247 if (format_change
) {
2248 uninit_player(mpctx
, INITIALIZED_AO
);
2249 reinit_audio_chain(mpctx
);
2255 static int sleep_until_update(struct MPContext
*mpctx
, float *time_frame
,
2256 float *aq_sleep_time
)
2258 struct MPOpts
*opts
= &mpctx
->opts
;
2259 int frame_time_remaining
= 0;
2260 current_module
="calc_sleep_time";
2262 *time_frame
-= get_relative_time(mpctx
); // reset timer
2264 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
2265 float delay
= mpctx
->audio_out
->get_delay();
2266 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
2270 * Adjust this raw delay value by calculating the expected
2271 * delay for this frame and generating a new value which is
2272 * weighted between the two. The higher autosync is, the
2273 * closer to the delay value gets to that which "-nosound"
2274 * would have used, and the longer it will take for A/V
2275 * sync to settle at the right value (but it eventually will.)
2276 * This settling time is very short for values below 100.
2278 float predicted
= mpctx
->delay
/ opts
->playback_speed
+ *time_frame
;
2279 float difference
= delay
- predicted
;
2280 delay
= predicted
+ difference
/ (float)autosync
;
2283 *time_frame
= delay
- mpctx
->delay
/ opts
->playback_speed
;
2284 *time_frame
-= mpctx
->video_out
->flip_queue_offset
;
2286 // delay = amount of audio buffered in soundcard/driver
2287 if (delay
> 0.25) delay
=0.25; else
2288 if (delay
< 0.10) delay
=0.10;
2290 if (*time_frame
> delay
*0.6) {
2291 // sleep time too big - may cause audio drops (buffer underrun)
2292 frame_time_remaining
= 1;
2293 *time_frame
= delay
*0.5;
2296 // If we're lagging more than 200 ms behind the right playback rate,
2297 // don't try to "catch up".
2298 // If benchmark is set always output frames as fast as possible
2299 // without sleeping.
2300 if (*time_frame
< -0.2 || benchmark
)
2302 *time_frame
-= mpctx
->video_out
->flip_queue_offset
;
2305 *aq_sleep_time
+= *time_frame
;
2308 //============================== SLEEP: ===================================
2310 // flag 256 means: libvo driver does its timing (dvb card)
2311 if (*time_frame
> 0.001 && !(mpctx
->sh_video
->output_flags
&256))
2312 *time_frame
= timing_sleep(mpctx
, *time_frame
);
2313 *time_frame
+= mpctx
->video_out
->flip_queue_offset
;
2314 return frame_time_remaining
;
2317 int reinit_video_chain(struct MPContext
*mpctx
)
2319 struct MPOpts
*opts
= &mpctx
->opts
;
2320 sh_video_t
* const sh_video
= mpctx
->sh_video
;
2322 //================== Init VIDEO (codec & libvo) ==========================
2323 if (!opts
->fixed_vo
|| !(mpctx
->initialized_flags
& INITIALIZED_VO
)) {
2324 current_module
="preinit_libvo";
2326 //shouldn't we set dvideo->id=-2 when we fail?
2327 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
2328 if(!(mpctx
->video_out
=init_best_video_out(opts
, mpctx
->x11_state
, mpctx
->key_fifo
, mpctx
->input
))){
2329 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Error opening/initializing the selected video_out (-vo) device.\n");
2332 mpctx
->initialized_flags
|=INITIALIZED_VO
;
2335 if(stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_ASPECT_RATIO
, &ar
) != STREAM_UNSUPPORTED
)
2336 mpctx
->sh_video
->stream_aspect
= ar
;
2337 current_module
="init_video_filters";
2339 char* vf_arg
[] = { "_oldargs_", (char*)mpctx
->video_out
, NULL
};
2340 sh_video
->vfilter
= vf_open_filter(opts
, NULL
,"vo",vf_arg
);
2344 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
2345 vf_menu
= vf_open_plugin(opts
,libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
2347 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Can't open libmenu video filter with root menu %s.\n",menu_root
);
2352 sh_video
->vfilter
= vf_menu
;
2356 if(opts
->ass_enabled
) {
2359 if (opts
->vf_settings
)
2360 for (i
= 0; opts
->vf_settings
[i
].name
; ++i
)
2361 if (strcmp(opts
->vf_settings
[i
].name
, "ass") == 0) {
2366 extern vf_info_t vf_info_ass
;
2367 const vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
2368 char* vf_arg
[] = {"auto", "1", NULL
};
2370 struct vf_instance
*vf_ass
= vf_open_plugin_noerr(opts
, libass_vfs
,
2375 sh_video
->vfilter
= vf_ass
;
2376 else if (retcode
== -1) // vf_ass open() returns -1 if there's VO EOSD
2377 mp_msg(MSGT_CPLAYER
, MSGL_V
, "[ass] vf_ass not needed\n");
2379 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
2384 sh_video
->vfilter
= append_filters(sh_video
->vfilter
, opts
->vf_settings
);
2387 if (opts
->ass_enabled
)
2388 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
2391 current_module
="init_video_codec";
2393 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2394 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
2395 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2397 if(!sh_video
->initialized
){
2398 if(!opts
->fixed_vo
) uninit_player(mpctx
, INITIALIZED_VO
);
2402 mpctx
->initialized_flags
|=INITIALIZED_VCODEC
;
2404 if (sh_video
->codec
)
2405 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
2407 sh_video
->last_pts
= MP_NOPTS_VALUE
;
2408 sh_video
->num_buffered_pts
= 0;
2409 sh_video
->next_frame_time
= 0;
2412 // Auto quality option enabled
2413 output_quality
=get_video_quality_max(sh_video
);
2414 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
2415 else output_quality
=auto_quality
;
2416 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
2417 set_video_quality(sh_video
,output_quality
);
2420 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2422 current_module
="init_vo";
2427 mpctx
->sh_video
= mpctx
->d_video
->sh
= NULL
;
2431 static double update_video_nocorrect_pts(struct MPContext
*mpctx
)
2433 struct sh_video
*sh_video
= mpctx
->sh_video
;
2434 double frame_time
= 0;
2435 struct vo
*video_out
= mpctx
->video_out
;
2436 while (!video_out
->frame_loaded
) {
2437 current_module
= "filter_video";
2438 // In nocorrect-pts mode there is no way to properly time these frames
2439 if (vo_get_buffered_frame(video_out
, 0) >= 0)
2441 if (vf_output_queued_frame(sh_video
->vfilter
))
2443 unsigned char *packet
= NULL
;
2444 frame_time
= sh_video
->next_frame_time
;
2445 if (mpctx
->update_video_immediately
)
2447 int in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2448 &packet
, force_fps
);
2450 #ifdef CONFIG_DVDNAV
2451 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
2452 if (mp_dvdnav_is_eof(mpctx
->stream
))
2455 mpctx
->d_video
->eof
= 0;
2457 mpctx
->d_audio
->eof
= 0;
2458 mpctx
->stream
->eof
= 0;
2463 if (in_size
> max_framesize
)
2464 max_framesize
= in_size
;
2465 sh_video
->timer
+= frame_time
;
2466 if (mpctx
->sh_audio
)
2467 mpctx
->delay
-= frame_time
;
2468 // video_read_frame can change fps (e.g. for ASF video)
2469 vo_fps
= sh_video
->fps
;
2470 int framedrop_type
= check_framedrop(mpctx
, frame_time
);
2471 current_module
= "decode video";
2473 void *decoded_frame
;
2474 #ifdef CONFIG_DVDNAV
2475 decoded_frame
= mp_dvdnav_restore_smpi(mpctx
, &in_size
, &packet
, NULL
);
2476 if (in_size
>= 0 && !decoded_frame
)
2478 decoded_frame
= decode_video(sh_video
, packet
, in_size
, framedrop_type
,
2480 #ifdef CONFIG_DVDNAV
2481 // Save last still frame for future display
2482 mp_dvdnav_save_smpi(mpctx
, in_size
, packet
, decoded_frame
);
2484 if (decoded_frame
) {
2485 current_module
= "filter video";
2486 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2487 if (!video_out
->config_ok
)
2494 static void determine_frame_pts(struct MPContext
*mpctx
)
2496 struct sh_video
*sh_video
= mpctx
->sh_video
;
2497 struct MPOpts
*opts
= &mpctx
->opts
;
2499 if (opts
->user_pts_assoc_mode
) {
2500 sh_video
->pts_assoc_mode
= opts
->user_pts_assoc_mode
;
2501 } else if (sh_video
->pts_assoc_mode
== 0) {
2502 if (sh_video
->codec_reordered_pts
!= MP_NOPTS_VALUE
)
2503 sh_video
->pts_assoc_mode
= 1;
2505 sh_video
->pts_assoc_mode
= 2;
2507 int probcount1
= sh_video
->num_reordered_pts_problems
;
2508 int probcount2
= sh_video
->num_sorted_pts_problems
;
2509 if (sh_video
->pts_assoc_mode
== 2) {
2510 int tmp
= probcount1
;
2511 probcount1
= probcount2
;
2514 if (probcount1
>= probcount2
* 1.5 + 2) {
2515 sh_video
->pts_assoc_mode
= 3 - sh_video
->pts_assoc_mode
;
2516 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Switching to pts association mode "
2517 "%d.\n", sh_video
->pts_assoc_mode
);
2520 sh_video
->pts
= sh_video
->pts_assoc_mode
== 1 ?
2521 sh_video
->codec_reordered_pts
: sh_video
->sorted_pts
;
2524 static double update_video(struct MPContext
*mpctx
)
2526 struct sh_video
*sh_video
= mpctx
->sh_video
;
2527 struct vo
*video_out
= mpctx
->video_out
;
2528 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_SET_OSD_OBJ
,
2529 mpctx
->osd
); // hack for vf_expand
2530 if (!mpctx
->opts
.correct_pts
)
2531 return update_video_nocorrect_pts(mpctx
);
2535 bool hit_eof
= false;
2536 while (!video_out
->frame_loaded
) {
2537 current_module
= "filter_video";
2538 if (vo_get_buffered_frame(video_out
, hit_eof
) >= 0)
2540 // XXX Time used in this call is not counted in any performance
2541 // timer now, OSD time is not updated correctly for filter-added frames
2542 if (vf_output_queued_frame(sh_video
->vfilter
))
2546 unsigned char *packet
= NULL
;
2547 int in_size
= ds_get_packet_pts(mpctx
->d_video
, &packet
, &pts
);
2548 if (pts
!= MP_NOPTS_VALUE
)
2549 pts
+= mpctx
->video_offset
;
2551 // try to extract last frames in case of decoder lag
2553 pts
= MP_NOPTS_VALUE
;
2556 if (in_size
> max_framesize
)
2557 max_framesize
= in_size
;
2558 current_module
= "decode video";
2559 int framedrop_type
= check_framedrop(mpctx
, sh_video
->frametime
);
2560 void *decoded_frame
= decode_video(sh_video
, packet
, in_size
,
2561 framedrop_type
, pts
);
2562 if (decoded_frame
) {
2563 determine_frame_pts(mpctx
);
2564 current_module
= "filter video";
2565 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2566 if (!video_out
->config_ok
)
2567 break; // We'd likely hang in this loop otherwise
2571 pts
= video_out
->next_pts
;
2572 if (pts
== MP_NOPTS_VALUE
) {
2573 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Video pts after filters MISSING\n");
2574 // Try to use decoder pts from before filters
2575 pts
= sh_video
->pts
;
2576 if (pts
== MP_NOPTS_VALUE
)
2577 pts
= sh_video
->last_pts
;
2579 sh_video
->pts
= pts
;
2580 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2581 sh_video
->last_pts
= sh_video
->pts
;
2582 else if (sh_video
->last_pts
> sh_video
->pts
) {
2583 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Decreasing video pts: %f < %f\n",
2584 sh_video
->pts
, sh_video
->last_pts
);
2585 /* If the difference in pts is small treat it as jitter around the
2586 * right value (possibly caused by incorrect timestamp ordering) and
2587 * just show this frame immediately after the last one.
2588 * Treat bigger differences as timestamp resets and start counting
2589 * timing of later frames from the position of this one. */
2590 if (sh_video
->last_pts
- sh_video
->pts
> 0.5)
2591 sh_video
->last_pts
= sh_video
->pts
;
2593 sh_video
->pts
= sh_video
->last_pts
;
2595 double frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2596 sh_video
->last_pts
= sh_video
->pts
;
2597 sh_video
->timer
+= frame_time
;
2598 if (mpctx
->sh_audio
)
2599 mpctx
->delay
-= frame_time
;
2603 void pause_player(struct MPContext
*mpctx
)
2608 mpctx
->step_frames
= 0;
2609 mpctx
->time_frame
-= get_relative_time(mpctx
);
2611 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2612 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2614 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2615 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2618 void unpause_player(struct MPContext
*mpctx
)
2624 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2625 mpctx
->audio_out
->resume(); // resume audio
2626 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
2627 && !mpctx
->step_frames
)
2628 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
); // resume video
2629 (void)get_relative_time(mpctx
); // ignore time that passed during pause
2632 void add_step_frame(struct MPContext
*mpctx
)
2634 mpctx
->step_frames
++;
2635 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2636 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2637 unpause_player(mpctx
);
2640 static void pause_loop(struct MPContext
*mpctx
)
2644 // Small hack to display the pause message on the OSD line.
2645 // The pause string is: "\n == PAUSE == \r" so we need to
2646 // take the first and the last char out
2647 if (term_osd
&& !mpctx
->sh_video
) {
2648 char msg
[128] = _("\n ===== PAUSE =====\r");
2649 int mlen
= strlen(msg
);
2651 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2652 update_osd_msg(mpctx
);
2654 mp_tmsg(MSGT_CPLAYER
,MSGL_STATUS
,"\n ===== PAUSE =====\r");
2655 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2658 while ( (cmd
= mp_input_get_cmd(mpctx
->input
, 20, 1)) == NULL
2659 || cmd
->id
== MP_CMD_SET_MOUSE_POS
|| cmd
->pausing
== 4) {
2661 cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0);
2662 run_command(mpctx
, cmd
);
2666 if (mpctx
->sh_video
&& mpctx
->video_out
)
2667 vo_check_events(mpctx
->video_out
);
2670 vf_menu_pause_update(vf_menu
);
2673 update_osd_msg(mpctx
);
2674 int hack
= vo_osd_changed(0);
2675 vo_osd_changed(hack
);
2682 // Find the right mute status and record position for new file position
2683 static void edl_seek_reset(MPContext
*mpctx
)
2685 mpctx
->edl_muted
= 0;
2686 next_edl_record
= edl_records
;
2688 while (next_edl_record
) {
2689 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2692 if (next_edl_record
->action
== EDL_MUTE
)
2693 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2694 next_edl_record
= next_edl_record
->next
;
2696 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2697 mixer_mute(&mpctx
->mixer
);
2701 // Execute EDL command for the current position if one exists
2702 static void edl_update(MPContext
*mpctx
)
2704 if (!next_edl_record
)
2707 if (!mpctx
->sh_video
) {
2708 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Cannot use EDL without video, disabling.\n");
2709 free_edl(edl_records
);
2710 next_edl_record
= NULL
;
2715 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2716 if (next_edl_record
->action
== EDL_SKIP
) {
2717 mpctx
->osd_function
= OSD_FFW
;
2718 mpctx
->abs_seek_pos
= 0;
2719 mpctx
->rel_seek_secs
= next_edl_record
->length_sec
;
2720 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2721 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2722 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2724 else if (next_edl_record
->action
== EDL_MUTE
) {
2725 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2726 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2727 mixer_mute(&mpctx
->mixer
);
2728 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2729 next_edl_record
->start_sec
);
2731 next_edl_record
= next_edl_record
->next
;
2735 static void reinit_decoders(struct MPContext
*mpctx
)
2737 reinit_video_chain(mpctx
);
2738 reinit_audio_chain(mpctx
);
2739 mp_property_do("sub", M_PROPERTY_SET
, &mpctx
->global_sub_pos
, mpctx
);
2742 static void seek_reset(struct MPContext
*mpctx
)
2744 if (mpctx
->sh_video
) {
2745 current_module
= "seek_video_reset";
2746 resync_video_stream(mpctx
->sh_video
);
2747 mpctx
->sh_video
->timer
= 0;
2748 vo_seek_reset(mpctx
->video_out
);
2749 mpctx
->sh_video
->timer
= 0;
2750 mpctx
->sh_video
->num_buffered_pts
= 0;
2751 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2753 mpctx
->time_frame
= 0;
2754 mpctx
->update_video_immediately
= true;
2755 // Not all demuxers set d_video->pts during seek, so this value
2756 // (which is used by at least vobsub and edl code below) may
2757 // be completely wrong (probably 0).
2758 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
+ mpctx
->video_offset
;
2759 update_subtitles(mpctx
, &mpctx
->opts
, mpctx
->sh_video
,
2760 mpctx
->sh_video
->pts
, mpctx
->video_offset
,
2762 update_teletext(mpctx
->sh_video
, mpctx
->demuxer
, 1);
2765 if (mpctx
->sh_audio
) {
2766 current_module
= "seek_audio_reset";
2767 resync_audio_stream(mpctx
->sh_audio
);
2768 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2769 mpctx
->sh_audio
->a_buffer_len
= 0;
2770 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2771 if (!mpctx
->sh_video
)
2772 update_subtitles(mpctx
, &mpctx
->opts
, NULL
, mpctx
->sh_audio
->pts
,
2773 mpctx
->video_offset
, mpctx
->d_sub
, 1);
2776 if (vo_vobsub
&& mpctx
->sh_video
) {
2777 current_module
= "seek_vobsub_reset";
2778 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2781 edl_seek_reset(mpctx
);
2783 mpctx
->total_avsync_change
= 0;
2784 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2787 current_module
= NULL
;
2790 static bool timeline_set_part(struct MPContext
*mpctx
, int i
)
2792 struct timeline_part
*p
= mpctx
->timeline
+ mpctx
->timeline_part
;
2793 struct timeline_part
*n
= mpctx
->timeline
+ i
;
2794 mpctx
->timeline_part
= i
;
2795 mpctx
->video_offset
= n
->start
- n
->source_start
;
2796 if (n
->source
== p
->source
)
2798 uninit_player(mpctx
, INITIALIZED_VCODEC
| (mpctx
->opts
.fixed_vo
&& mpctx
->opts
.video_id
!= -2 ? 0 : INITIALIZED_VO
) | INITIALIZED_AO
| INITIALIZED_ACODEC
);
2799 mpctx
->demuxer
= n
->source
->demuxer
;
2800 mpctx
->d_video
= mpctx
->demuxer
->video
;
2801 mpctx
->d_audio
= mpctx
->demuxer
->audio
;
2802 mpctx
->d_sub
= mpctx
->demuxer
->sub
;
2803 mpctx
->sh_video
= mpctx
->d_video
->sh
;
2804 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
2808 // Given pts, switch playback to the corresponding part.
2809 // Return offset within that part.
2810 static double timeline_set_from_time(struct MPContext
*mpctx
, double pts
,
2815 for (int i
= 0; i
< mpctx
->num_timeline_parts
; i
++) {
2816 struct timeline_part
*p
= mpctx
->timeline
+ i
;
2817 if (pts
< (p
+1)->start
) {
2818 *need_reset
= timeline_set_part(mpctx
, i
);
2819 return pts
- p
->start
+ p
->source_start
;
2826 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute
2827 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length
2828 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2829 static int seek(MPContext
*mpctx
, double amount
, int style
)
2831 current_module
= "seek";
2832 if (mpctx
->stop_play
== AT_END_OF_FILE
)
2833 mpctx
->stop_play
= KEEP_PLAYING
;
2834 if (style
& SEEK_FACTOR
2835 || style
& SEEK_ABSOLUTE
&& amount
< mpctx
->last_chapter_pts
2837 mpctx
->last_chapter_seek
= -1;
2838 if (mpctx
->timeline
&& style
& SEEK_FACTOR
) {
2839 amount
*= mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
2840 style
&= ~SEEK_FACTOR
;
2842 if ((mpctx
->demuxer
->accurate_seek
|| mpctx
->timeline
) && mpctx
->sh_video
2843 && !(style
& (SEEK_ABSOLUTE
| SEEK_FACTOR
))) {
2844 style
|= SEEK_ABSOLUTE
;
2846 style
|= SEEK_FORWARD
;
2848 style
|= SEEK_BACKWARD
;
2849 amount
+= mpctx
->sh_video
->pts
;
2852 /* At least the liba52 decoder wants to read from the input stream
2853 * during initialization, so reinit must be done after the demux_seek()
2854 * call that clears possible stream EOF. */
2855 bool need_reset
= false;
2856 if (mpctx
->timeline
) {
2857 amount
= timeline_set_from_time(mpctx
, amount
, &need_reset
);
2859 mpctx
->stop_play
= AT_END_OF_FILE
;
2860 // Clear audio from current position
2861 if (mpctx
->sh_audio
) {
2862 mpctx
->audio_out
->reset();
2863 mpctx
->sh_audio
->a_buffer_len
= 0;
2864 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2869 int seekresult
= demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
);
2871 reinit_decoders(mpctx
);
2872 if (seekresult
== 0)
2879 // -2 is no chapters, -1 is before first chapter
2880 int get_current_chapter(struct MPContext
*mpctx
)
2882 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2883 return FFMAX(mpctx
->last_chapter_seek
,
2884 demuxer_get_current_chapter(mpctx
->demuxer
));
2887 double current_pts
= mpctx
->sh_video
->pts
;
2888 for (i
= 1; i
< mpctx
->num_chapters
; i
++)
2889 if (current_pts
< mpctx
->chapters
[i
].start
)
2891 return FFMAX(mpctx
->last_chapter_seek
, i
- 1);
2894 // currently returns a string allocated with malloc, not talloc
2895 char *chapter_display_name(struct MPContext
*mpctx
, int chapter
)
2897 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2898 return demuxer_chapter_display_name(mpctx
->demuxer
, chapter
);
2899 return strdup(mpctx
->chapters
[chapter
].name
);
2902 int seek_chapter(struct MPContext
*mpctx
, int chapter
, double *seek_pts
,
2903 char **chapter_name
)
2905 mpctx
->last_chapter_seek
= -1;
2906 if (!mpctx
->chapters
|| !mpctx
->sh_video
) {
2907 int res
= demuxer_seek_chapter(mpctx
->demuxer
, chapter
, seek_pts
,
2910 if (*seek_pts
== -1)
2913 mpctx
->last_chapter_seek
= res
;
2914 mpctx
->last_chapter_pts
= *seek_pts
;
2920 if (chapter
>= mpctx
->num_chapters
)
2924 *seek_pts
= mpctx
->chapters
[chapter
].start
;
2925 mpctx
->last_chapter_seek
= chapter
;
2926 mpctx
->last_chapter_pts
= *seek_pts
;
2928 *chapter_name
= talloc_strdup(NULL
, mpctx
->chapters
[chapter
].name
);
2932 static int find_ordered_chapter_sources(struct MPContext
*mpctx
,
2933 struct content_source
*sources
,
2935 unsigned char uid_map
[][16])
2937 int num_filenames
= 0;
2938 char **filenames
= NULL
;
2939 if (num_sources
> 1) {
2940 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "This file references data from "
2941 "other sources.\n");
2942 if (mpctx
->stream
->type
!= STREAMTYPE_FILE
) {
2943 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Playback source is not a "
2944 "normal disk file. Will not search for related files.\n");
2946 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Will scan other files in the "
2947 "same directory to find referenced sources.\n");
2948 filenames
= find_files(mpctx
->demuxer
->filename
, ".mkv",
2953 int num_left
= num_sources
- 1;
2954 for (int i
= 0; i
< num_filenames
&& num_left
> 0; i
++) {
2955 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Checking file %s\n",
2956 filename_recode(filenames
[i
]));
2958 struct stream
*s
= open_stream(filenames
[i
], &mpctx
->opts
, &format
);
2961 struct demuxer
*d
= demux_open(&mpctx
->opts
, s
, DEMUXER_TYPE_MATROSKA
,
2962 mpctx
->opts
.audio_id
,
2963 mpctx
->opts
.video_id
,
2964 mpctx
->opts
.sub_id
, filenames
[i
]);
2969 if (d
->file_format
== DEMUXER_TYPE_MATROSKA
) {
2970 for (int i
= 1; i
< num_sources
; i
++) {
2971 if (sources
[i
].demuxer
)
2973 if (!memcmp(uid_map
[i
], d
->matroska_data
.segment_uid
, 16)) {
2974 mp_msg(MSGT_CPLAYER
, MSGL_INFO
,"Match for source %d: %s\n",
2975 i
, filename_recode(d
->filename
));
2976 sources
[i
].stream
= s
;
2977 sources
[i
].demuxer
= d
;
2989 talloc_free(filenames
);
2991 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Failed to find ordered chapter part!\n"
2992 "There will be parts MISSING from the video!\n");
2993 for (int i
= 1, j
= 1; i
< num_sources
; i
++)
2994 if (sources
[i
].demuxer
) {
2995 sources
[j
] = sources
[i
];
2996 memcpy(uid_map
[j
], uid_map
[i
], 16);
3000 return num_sources
- num_left
;
3003 static void build_ordered_chapter_timeline(struct MPContext
*mpctx
)
3005 if (!mpctx
->opts
.ordered_chapters
) {
3006 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, but "
3007 "you have disabled support for them. Ignoring.\n");
3011 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, will build "
3012 "edit timeline.\n");
3014 struct demuxer
*demuxer
= mpctx
->demuxer
;
3015 struct matroska_data
*m
= &demuxer
->matroska_data
;
3017 // +1 because sources/uid_map[0] is original file even if all chapters
3018 // actually use other sources and need separate entries
3019 struct content_source
*sources
= talloc_array_ptrtype(NULL
, sources
,
3020 m
->num_ordered_chapters
+1);
3021 sources
[0].stream
= mpctx
->stream
;
3022 sources
[0].demuxer
= mpctx
->demuxer
;
3023 unsigned char uid_map
[m
->num_ordered_chapters
+1][16];
3024 int num_sources
= 1;
3025 memcpy(uid_map
[0], m
->segment_uid
, 16);
3027 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
3028 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
3029 if (!c
->has_segment_uid
)
3030 memcpy(c
->segment_uid
, m
->segment_uid
, 16);
3032 for (int j
= 0; j
< num_sources
; j
++)
3033 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
3035 memcpy(uid_map
[num_sources
], c
->segment_uid
, 16);
3036 sources
[num_sources
] = (struct content_source
){};
3042 num_sources
= find_ordered_chapter_sources(mpctx
, sources
, num_sources
,
3046 // +1 for terminating chapter with start time marking end of last real one
3047 struct timeline_part
*timeline
= talloc_array_ptrtype(NULL
, timeline
,
3048 m
->num_ordered_chapters
+ 1);
3049 struct chapter
*chapters
= talloc_array_ptrtype(NULL
, chapters
,
3050 m
->num_ordered_chapters
);
3051 uint64_t starttime
= 0;
3052 uint64_t missing_time
= 0;
3054 int num_chapters
= 0;
3055 uint64_t prev_part_offset
= 0;
3056 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
3057 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
3060 for (j
= 0; j
< num_sources
; j
++) {
3061 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
3064 missing_time
+= c
->end
- c
->start
;
3067 chapters
[num_chapters
].start
= starttime
/ 1000.;
3068 chapters
[num_chapters
].name
= talloc_strdup(chapters
, c
->name
);
3069 /* Only add a separate part if the time or file actually changes.
3070 * Matroska files have chapter divisions that are redundant from
3071 * timeline point of view because the same chapter structure is used
3072 * both to specify the timeline and for normal chapter information.
3073 * Removing a missing inserted external chapter can also cause this. */
3074 if (part_count
== 0 || c
->start
!= starttime
+ prev_part_offset
3075 || sources
+ j
!= timeline
[part_count
- 1].source
) {
3076 timeline
[part_count
].source
= sources
+ j
;
3077 timeline
[part_count
].start
= chapters
[num_chapters
].start
;
3078 timeline
[part_count
].source_start
= c
->start
/ 1000.;
3079 prev_part_offset
= c
->start
- starttime
;
3082 starttime
+= c
->end
- c
->start
;
3085 timeline
[part_count
].start
= starttime
/ 1000.;
3088 // None of the parts come from the file itself???
3089 talloc_free(sources
);
3090 talloc_free(timeline
);
3091 talloc_free(chapters
);
3095 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline contains %d parts from %d "
3096 "sources. Total length %.3f seconds.\n", part_count
, num_sources
,
3097 timeline
[part_count
].start
);
3099 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "There are %.3f seconds missing "
3100 "from the timeline!\n", missing_time
/ 1000.);
3101 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Source files:\n");
3102 for (int i
= 0; i
< num_sources
; i
++)
3103 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%d: %s\n", i
,
3104 filename_recode(sources
[i
].demuxer
->filename
));
3105 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline parts: (number, start, "
3106 "source_start, source):\n");
3107 for (int i
= 0; i
< part_count
; i
++) {
3108 struct timeline_part
*p
= timeline
+ i
;
3109 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%3d %9.3f %9.3f %3td\n", i
, p
->start
,
3110 p
->source_start
, p
->source
- sources
);
3112 mp_msg(MSGT_CPLAYER
, MSGL_V
, "END %9.3f\n", timeline
[part_count
].start
);
3113 mpctx
->sources
= sources
;
3114 mpctx
->num_sources
= num_sources
;
3115 mpctx
->timeline
= timeline
;
3116 mpctx
->num_timeline_parts
= part_count
;
3117 mpctx
->num_chapters
= num_chapters
;
3118 mpctx
->chapters
= chapters
;
3120 mpctx
->timeline_part
= 0;
3121 mpctx
->demuxer
= timeline
[0].source
->demuxer
;
3125 static int read_keys(void *ctx
, int fd
)
3128 return mplayer_get_key(ctx
, 0);
3132 /* This preprocessor directive is a hack to generate a mplayer-nomain.o object
3133 * file for some tools to link against. */
3134 #ifndef DISABLE_MAIN
3135 int main(int argc
,char* argv
[]){
3142 /* Flag indicating whether MPlayer should exit without playing anything. */
3145 //float a_frame=0; // Audio
3149 struct MPContext
*mpctx
= &(struct MPContext
){
3150 .osd_function
= OSD_PLAY
,
3151 .begin_skip
= MP_NOPTS_VALUE
,
3152 .play_tree_step
= 1,
3153 .global_sub_pos
= -1,
3154 .set_of_sub_pos
= -1,
3155 .file_format
= DEMUXER_TYPE_UNKNOWN
,
3160 srand(GetTimerMS());
3163 set_av_log_callback();
3166 mpctx
->x11_state
= vo_x11_init_state();
3168 struct MPOpts
*opts
= &mpctx
->opts
;
3169 set_default_mplayer_options(opts
);
3170 // Create the config context and register the options
3171 mpctx
->mconfig
= m_config_new(opts
, cfg_include
);
3172 m_config_register_options(mpctx
->mconfig
,mplayer_opts
);
3173 m_config_register_options(mpctx
->mconfig
, common_opts
);
3174 mp_input_register_options(mpctx
->mconfig
);
3176 // Preparse the command line
3177 m_config_preparse_command_line(mpctx
->mconfig
,argc
,argv
);
3179 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
3184 stream_tv_defaults
.immediate
= 1;
3187 parse_cfgfiles(mpctx
, mpctx
->mconfig
);
3189 mpctx
->playtree
= m_config_parse_mp_command_line(mpctx
->mconfig
, argc
, argv
);
3190 if(mpctx
->playtree
== NULL
)
3193 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
3194 if(mpctx
->playtree
) {
3195 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mpctx
->mconfig
);
3196 if(mpctx
->playtree_iter
) {
3197 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3198 play_tree_iter_free(mpctx
->playtree_iter
);
3199 mpctx
->playtree_iter
= NULL
;
3201 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
3205 mpctx
->key_fifo
= mp_fifo_create(opts
);
3207 print_version("MPlayer");
3209 #if defined(__MINGW32__) || defined(__CYGWIN__)
3211 HMODULE kernel32
= GetModuleHandle("Kernel32.dll");
3212 BOOL
WINAPI (*setDEP
)(DWORD
) = NULL
;
3214 setDEP
= GetProcAddress(kernel32
, "SetProcessDEPPolicy");
3215 if (setDEP
) setDEP(3);
3217 // stop Windows from showing all kinds of annoying error dialogs
3218 SetErrorMode(0x8003);
3219 // request 1ms timer resolution
3223 #ifdef CONFIG_PRIORITY
3228 set_codec_path(codec_path
);
3230 if(opts
->video_driver_list
&& strcmp(opts
->video_driver_list
[0],"help")==0){
3235 if(opts
->audio_driver_list
&& strcmp(opts
->audio_driver_list
[0],"help")==0){
3240 /* Check codecs.conf. */
3241 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
3242 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
3243 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
3244 if(!parse_codec_cfg(NULL
)){
3245 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
3247 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"Using built-in default codecs.conf.\n");
3250 free( mem_ptr
); // release the buffer created by get_path()
3254 if(video_codec_list
){
3256 video_codec
=video_codec_list
[0];
3257 for(i
=0;video_codec_list
[i
];i
++)
3258 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
3261 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
3262 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available audio codecs:\n");
3263 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
3265 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3268 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
3269 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available video codecs:\n");
3270 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
3272 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3275 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
3277 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3280 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3282 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3285 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3291 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3293 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3297 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3298 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3299 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3301 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3304 if(list_properties
) {
3305 property_print_help();
3310 exit_player(mpctx
, EXIT_NONE
);
3312 if(!mpctx
->filename
&& !player_idle_mode
){
3313 // no file/vcd/dvd -> show HELP:
3314 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "%s", mp_gtext(help_text
));
3315 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
3318 /* Display what configure line was used */
3319 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
3321 // Many users forget to include command line in bugreports...
3322 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3323 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "CommandLine:");
3324 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3325 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3328 //------ load global data first ------
3330 mpctx
->osd
= osd_create();
3333 #ifdef CONFIG_FREETYPE
3336 #ifdef CONFIG_FONTCONFIG
3337 if(font_fontconfig
<= 0)
3340 #ifdef CONFIG_BITMAP_FONT
3342 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3343 if(!vo_font
) mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load bitmap font: %s\n",
3344 filename_recode(font_name
));
3347 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3348 free(mem_ptr
); // release the buffer created by get_path()
3350 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3353 mpctx
->osd
->sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
3355 mpctx
->osd
->sub_font
= vo_font
;
3357 #ifdef CONFIG_FONTCONFIG
3362 ass_library
= ass_init();
3368 // seteuid(0); /* Can't hurt to try to get root here */
3369 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3370 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Failed to open %s: %s (it should be readable by the user.)\n",
3371 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3373 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3375 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3376 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp
, strerror(errno
));
3377 mp_tmsg(MSGT_CPLAYER
, MSGL_HINT
, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp
);
3380 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3381 /* variable only by the root */
3382 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno
));
3386 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Using Linux hardware RTC timing (%ldHz).\n", irqp
);
3390 #endif /* HAVE_RTC */
3391 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3392 softsleep
?"software":timer_name
);
3395 load_termcap(NULL
); // load key-codes
3398 // ========== Init keyboard FIFO (connection to libvo) ============
3400 // Init input system
3401 current_module
= "init_input";
3402 mpctx
->input
= mp_input_init(&opts
->input
);
3403 mp_input_add_key_fd(mpctx
->input
, -1,0,mplayer_get_key
,NULL
, mpctx
->key_fifo
);
3405 mp_input_add_cmd_fd(mpctx
->input
, 0,USE_SELECT
,MP_INPUT_SLAVE_CMD_FUNC
,NULL
);
3406 else if(!noconsolecontrols
)
3407 mp_input_add_key_fd(mpctx
->input
, 0, 1, read_keys
, NULL
, mpctx
->key_fifo
);
3408 // Set the libstream interrupt callback
3409 stream_set_interrupt_callback(mp_input_check_interrupt
, mpctx
->input
);
3413 if(menu_cfg
&& menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3414 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3416 menu_cfg
= get_path("menu.conf");
3417 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3418 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3420 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
,
3421 MPLAYER_CONFDIR
"/menu.conf"))
3422 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", MPLAYER_CONFDIR
"/menu.conf");
3424 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Menu init failed.\n");
3432 current_module
= NULL
;
3436 signal(SIGCHLD
,child_sighandler
);
3439 #ifdef CONFIG_CRASH_DEBUG
3440 prog_path
= argv
[0];
3442 //========= Catch terminate signals: ================
3443 // terminate requests:
3444 signal(SIGTERM
,exit_sighandler
); // kill
3445 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3447 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3449 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3450 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3451 #ifdef CONFIG_SIGHANDLER
3453 signal(SIGBUS
,exit_sighandler
); // bus error
3454 signal(SIGSEGV
,exit_sighandler
); // segfault
3455 signal(SIGILL
,exit_sighandler
); // illegal instruction
3456 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3457 signal(SIGABRT
,exit_sighandler
); // abort()
3458 #ifdef CONFIG_CRASH_DEBUG
3460 signal(SIGTRAP
,exit_sighandler
);
3464 // ******************* Now, let's see the per-file stuff ********************
3468 // init global sub numbers
3469 mpctx
->global_sub_size
= 0;
3470 memset(mpctx
->sub_counts
, 0, sizeof(mpctx
->sub_counts
));
3472 if (mpctx
->filename
) {
3473 load_per_protocol_config (mpctx
->mconfig
, mpctx
->filename
);
3474 load_per_extension_config (mpctx
->mconfig
, mpctx
->filename
);
3475 load_per_file_config (mpctx
->mconfig
, mpctx
->filename
);
3478 if (opts
->video_driver_list
)
3479 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_VO
, opts
->video_driver_list
[0]);
3480 if (opts
->audio_driver_list
)
3481 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_AO
, opts
->audio_driver_list
[0]);
3483 // We must enable getch2 here to be able to interrupt network connection
3485 if(!noconsolecontrols
&& !slave_mode
){
3486 if(mpctx
->initialized_flags
&INITIALIZED_GETCH2
)
3487 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"WARNING: getch2_init called twice!\n");
3489 getch2_enable(); // prepare stdin for hotkeys...
3490 mpctx
->initialized_flags
|=INITIALIZED_GETCH2
;
3491 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3494 // =================== GUI idle loop (STOP state) ===========================
3495 while (player_idle_mode
&& !mpctx
->filename
) {
3496 play_tree_t
* entry
= NULL
;
3498 if (mpctx
->video_out
&& mpctx
->video_out
->config_ok
)
3499 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
3500 while (!(cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0))) { // wait for command
3501 if (mpctx
->video_out
)
3502 vo_check_events(mpctx
->video_out
);
3506 case MP_CMD_LOADFILE
:
3507 // prepare a tree entry with the new filename
3508 entry
= play_tree_new();
3509 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3510 // The entry is added to the main playtree after the switch().
3512 case MP_CMD_LOADLIST
:
3513 entry
= parse_playlist_file(mpctx
->mconfig
, cmd
->args
[0].v
.s
);
3516 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3518 case MP_CMD_VO_FULLSCREEN
:
3519 case MP_CMD_GET_PROPERTY
:
3520 case MP_CMD_SET_PROPERTY
:
3521 case MP_CMD_STEP_PROPERTY
:
3522 run_command(mpctx
, cmd
);
3528 if (entry
) { // user entered a command that gave a valid entry
3529 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
3530 play_tree_free_list(mpctx
->playtree
->child
, 1);
3531 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
3533 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
3535 play_tree_set_child(mpctx
->playtree
, entry
);
3537 /* Make iterator start at the top the of tree. */
3538 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mpctx
->mconfig
);
3539 if (!mpctx
->playtree_iter
) continue;
3541 // find the first real item in the tree
3542 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3544 play_tree_iter_free(mpctx
->playtree_iter
);
3545 mpctx
->playtree_iter
= NULL
;
3546 continue; // wait for next command
3548 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
3551 //---------------------------------------------------------------------------
3553 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
3554 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
);
3556 if (mpctx
->filename
) {
3557 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nPlaying %s.\n",
3558 filename_recode(mpctx
->filename
));
3559 if(use_filename_title
&& vo_wintitle
== NULL
)
3560 vo_wintitle
= strdup(mp_basename2(mpctx
->filename
));
3564 if (edl_records
) free_edl(edl_records
);
3565 next_edl_record
= edl_records
= edl_parse_file();
3567 if (edl_output_filename
) {
3568 if (edl_fd
) fclose(edl_fd
);
3569 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3571 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Can't open EDL file [%s] for writing.\n",
3572 filename_recode(edl_output_filename
));
3576 //==================== Open VOB-Sub ============================
3578 current_module
="vobsub";
3580 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3582 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load subtitles: %s\n",
3583 filename_recode(vobsub_name
));
3584 } else if (sub_auto
&& mpctx
->filename
){
3585 /* try to autodetect vobsub from movie filename ::atmos */
3586 char *buf
= strdup(mpctx
->filename
), *psub
;
3587 char *pdot
= strrchr(buf
, '.');
3588 char *pslash
= strrchr(buf
, '/');
3589 #if defined(__MINGW32__) || defined(__CYGWIN__)
3590 if (!pslash
) pslash
= strrchr(buf
, '\\');
3592 if (pdot
&& (!pslash
|| pdot
> pslash
))
3594 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3595 /* try from ~/.mplayer/sub */
3596 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3599 bname
= strrchr(buf
,'/');
3600 #if defined(__MINGW32__) || defined(__CYGWIN__)
3601 if(!bname
) bname
= strrchr(buf
,'\\');
3605 l
= strlen(psub
) + strlen(bname
) + 1;
3606 psub
= realloc(psub
,l
);
3608 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3614 mpctx
->initialized_flags
|=INITIALIZED_VOBSUB
;
3615 vobsub_set_from_lang(vo_vobsub
, opts
->sub_lang
);
3616 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
3618 // setup global sub numbering
3619 mpctx
->sub_counts
[SUB_SOURCE_VOBSUB
] = vobsub_get_indexes_count(vo_vobsub
);
3622 //============ Open & Sync STREAM --- fork cache2 ====================
3625 mpctx
->demuxer
=NULL
;
3626 if (mpctx
->d_audio
) {
3627 //free_demuxer_stream(mpctx->d_audio);
3628 mpctx
->d_audio
=NULL
;
3630 if (mpctx
->d_video
) {
3631 //free_demuxer_stream(d_video);
3632 mpctx
->d_video
=NULL
;
3634 mpctx
->sh_audio
=NULL
;
3635 mpctx
->sh_video
=NULL
;
3637 current_module
="open_stream";
3638 mpctx
->stream
= open_stream(mpctx
->filename
, opts
, &mpctx
->file_format
);
3639 if(!mpctx
->stream
) { // error...
3640 mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
);
3641 goto goto_next_file
;
3643 mpctx
->initialized_flags
|=INITIALIZED_STREAM
;
3645 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
3646 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "\nThis looks like a playlist, but "
3647 "playlist support will not be used automatically.\n"
3648 "MPlayer's playlist code is unsafe and should only be used with "
3649 "trusted sources.\nPlayback will probably fail.\n\n");
3653 current_module
="handle_playlist";
3654 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
3655 filename_recode(mpctx
->filename
));
3656 entry
= parse_playtree(mpctx
->stream
, mpctx
->mconfig
, 0);
3657 mpctx
->eof
=playtree_add_playlist(mpctx
, entry
);
3658 goto goto_next_file
;
3661 mpctx
->stream
->start_pos
+=seek_to_byte
;
3663 if(stream_dump_type
==5){
3664 unsigned char buf
[4096];
3667 current_module
="dumpstream";
3668 stream_reset(mpctx
->stream
);
3669 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
3670 f
=fopen(stream_dump_name
,"wb");
3672 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3673 exit_player(mpctx
, EXIT_ERROR
);
3675 if (opts
->chapterrange
[0] > 1) {
3676 int chapter
= opts
->chapterrange
[0] - 1;
3677 stream_control(mpctx
->stream
, STREAM_CTRL_SEEK_TO_CHAPTER
, &chapter
);
3679 while(!mpctx
->stream
->eof
&& !async_quit_request
){
3680 len
=stream_read(mpctx
->stream
,buf
,4096);
3682 if(fwrite(buf
,len
,1,f
) != 1) {
3683 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",stream_dump_name
);
3684 exit_player(mpctx
, EXIT_ERROR
);
3687 if (opts
->chapterrange
[1] > 0) {
3689 if (stream_control(mpctx
->stream
, STREAM_CTRL_GET_CURRENT_CHAPTER
,
3690 &chapter
) == STREAM_OK
3691 && chapter
+ 1 > opts
->chapterrange
[1])
3696 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",stream_dump_name
);
3697 exit_player(mpctx
, EXIT_ERROR
);
3699 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3700 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3703 #ifdef CONFIG_DVDREAD
3704 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
3705 current_module
="dvd lang->id";
3706 if(opts
->audio_lang
&& opts
->audio_id
==-1) opts
->audio_id
=dvd_aid_from_lang(mpctx
->stream
,opts
->audio_lang
);
3707 if(opts
->sub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=dvd_sid_from_lang(mpctx
->stream
,opts
->sub_lang
);
3708 // setup global sub numbering
3709 mpctx
->sub_counts
[SUB_SOURCE_DEMUX
] = dvd_number_of_subs(mpctx
->stream
);
3710 current_module
=NULL
;
3714 #ifdef CONFIG_DVDNAV
3715 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
3716 current_module
="dvdnav lang->id";
3717 if(opts
->audio_lang
&& opts
->audio_id
==-1) opts
->audio_id
=mp_dvdnav_aid_from_lang(mpctx
->stream
,opts
->audio_lang
);
3718 dvdsub_lang_id
= -3;
3719 if(opts
->sub_lang
&& opts
->sub_id
==-1)
3720 dvdsub_lang_id
= opts
->sub_id
= mp_dvdnav_sid_from_lang(mpctx
->stream
,opts
->sub_lang
);
3721 // setup global sub numbering
3722 mpctx
->sub_counts
[SUB_SOURCE_DEMUX
] = mp_dvdnav_number_of_subs(mpctx
->stream
);
3723 current_module
=NULL
;
3727 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3729 if(stream_cache_size
>0){
3731 current_module
="enable_cache";
3732 res
= stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
3733 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3734 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0));
3736 if((mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
))) goto goto_next_file
;
3739 //============ Open DEMUXERS --- DETECT file type =======================
3740 current_module
="demux_open";
3742 mpctx
->demuxer
=demux_open(opts
, mpctx
->stream
,mpctx
->file_format
,opts
->audio_id
,opts
->video_id
,opts
->sub_id
,mpctx
->filename
);
3744 // HACK to get MOV Reference Files working
3746 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3748 unsigned char* playlist_entry
;
3749 play_tree_t
*list
= NULL
, *entry
= NULL
;
3751 current_module
="handle_demux_playlist";
3752 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
3756 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
3757 filename_recode(playlist_entry
));
3759 bname
=mp_basename(playlist_entry
);
3760 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3763 if (!strcmp(playlist_entry
, mpctx
->filename
)) // ignoring self-reference
3766 entry
= play_tree_new();
3768 if (mpctx
->filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3770 temp
=malloc((strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))+strlen(playlist_entry
)+1));
3773 strncpy(temp
, mpctx
->filename
, strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
)));
3774 temp
[strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))]='\0';
3775 strcat(temp
, playlist_entry
);
3776 if (!strcmp(temp
, mpctx
->filename
)) {
3780 play_tree_add_file(entry
,temp
);
3781 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3786 play_tree_add_file(entry
,playlist_entry
);
3791 play_tree_append_entry(list
,entry
);
3793 free_demuxer(mpctx
->demuxer
);
3794 mpctx
->demuxer
= NULL
;
3798 entry
= play_tree_new();
3799 play_tree_set_child(entry
,list
);
3800 mpctx
->stop_play
= playtree_add_playlist(mpctx
, entry
);
3801 goto goto_next_file
;
3806 goto goto_next_file
;
3808 if (mpctx
->demuxer
->matroska_data
.ordered_chapters
)
3809 build_ordered_chapter_timeline(mpctx
);
3811 if (!mpctx
->sources
) {
3812 mpctx
->sources
= talloc_ptrtype(NULL
, mpctx
->sources
);
3813 *mpctx
->sources
= (struct content_source
){.stream
= mpctx
->stream
,
3814 .demuxer
= mpctx
->demuxer
};
3815 mpctx
->num_sources
= 1;
3818 mpctx
->initialized_flags
|=INITIALIZED_DEMUXER
;
3821 if (opts
->ass_enabled
&& ass_library
) {
3822 for (int j
= 0; j
< mpctx
->num_sources
; j
++) {
3823 struct demuxer
*d
= mpctx
->sources
[j
].demuxer
;
3824 for (int i
= 0; i
< d
->num_attachments
; i
++) {
3825 struct demux_attachment
*att
= d
->attachments
+ i
;
3826 if (use_embedded_fonts
&& attachment_is_font(att
))
3827 ass_add_font(ass_library
, att
->name
, att
->data
, att
->data_size
);
3833 current_module
="demux_open2";
3835 //file_format=demuxer->file_format;
3837 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3838 mpctx
->d_video
=mpctx
->demuxer
->video
;
3839 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3843 mp_property_do("switch_program", M_PROPERTY_SET
, &tmp
, mpctx
);
3845 // select audio stream
3846 if (mpctx
->num_sources
)
3847 for (int i
= 0; i
< mpctx
->num_sources
; i
++)
3848 select_audio(mpctx
->sources
[i
].demuxer
, opts
->audio_id
,
3851 select_audio(mpctx
->demuxer
, opts
->audio_id
, opts
->audio_lang
);
3854 if((stream_dump_type
)&&(stream_dump_type
<4)){
3856 demux_stream_t
*ds
=NULL
;
3857 current_module
="dump";
3858 // select stream to dump
3859 switch(stream_dump_type
){
3860 case 1: ds
=mpctx
->d_audio
;break;
3861 case 2: ds
=mpctx
->d_video
;break;
3862 case 3: ds
=mpctx
->d_sub
;break;
3865 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"dump: FATAL: Selected stream missing!\n");
3866 exit_player(mpctx
, EXIT_ERROR
);
3868 // disable other streams:
3869 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3870 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3871 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3873 f
=fopen(stream_dump_name
,"wb");
3875 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3876 exit_player(mpctx
, EXIT_ERROR
);
3879 unsigned char* start
;
3880 int in_size
=ds_get_packet(ds
,&start
);
3881 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3882 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3883 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3884 if (opts
->chapterrange
[1] > 0) {
3885 int cur_chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
3886 if(cur_chapter
!=-1 && cur_chapter
+1 > opts
->chapterrange
[1])
3891 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3892 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3895 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3896 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3898 if(mpctx
->sh_video
){
3900 current_module
="video_read_properties";
3901 if(!video_read_properties(mpctx
->sh_video
)) {
3902 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Video: Cannot read properties.\n");
3903 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3905 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n",
3906 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3907 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3910 /* need to set fps here for output encoders to pick it up in their init */
3912 mpctx
->sh_video
->fps
=force_fps
;
3913 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3915 vo_fps
= mpctx
->sh_video
->fps
;
3917 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3918 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"FPS not specified in the header or invalid, use the -fps option.\n");
3919 mpctx
->opts
.correct_pts
= 1;
3925 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3926 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "No stream found.\n");
3928 if(mpctx
->stream
->type
== STREAMTYPE_DVB
)
3931 int v
= mpctx
->last_dvb_step
;
3933 dir
= DVB_CHANNEL_HIGHER
;
3935 dir
= DVB_CHANNEL_LOWER
;
3937 if(dvb_step_channel(mpctx
->stream
, dir
)) {
3938 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3939 mpctx
->dvbin_reopen
= 1;
3943 goto goto_next_file
; // exit_player(_("Fatal error"));
3946 /* display clip info */
3947 demux_info_print(mpctx
->demuxer
);
3949 //================== Read SUBTITLES (DVD & TEXT) ==========================
3950 if(vo_spudec
==NULL
&&
3951 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
)){
3952 init_vo_spudec(mpctx
);
3955 // after reading video params we should load subtitles because
3956 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3958 current_module
="read_subtitles_file";
3959 double sub_fps
= mpctx
->sh_video
? mpctx
->sh_video
->fps
: 25;
3961 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3962 add_subtitles(mpctx
, sub_name
[i
], sub_fps
, 0);
3964 if(sub_auto
) { // auto load sub file ...
3965 char *psub
= get_path( "sub/" );
3966 char **tmp
= sub_filenames((psub
? psub
: ""), mpctx
->filename
);
3968 free(psub
); // release the buffer created by get_path() above
3970 add_subtitles(mpctx
, tmp
[i
], sub_fps
, 1);
3975 if (mpctx
->set_of_sub_size
> 0)
3976 mpctx
->sub_counts
[SUB_SOURCE_SUBS
] = mpctx
->set_of_sub_size
;
3978 if (select_subtitle(mpctx
)) {
3980 switch (stream_dump_type
) {
3981 case 3: list_sub_file(subdata
); break;
3982 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
3983 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
3984 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
3985 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
3986 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
3990 print_file_properties(mpctx
, mpctx
->filename
);
3992 if(!mpctx
->sh_video
) goto main
; // audio-only
3994 if(!reinit_video_chain(mpctx
)) {
3995 if(!mpctx
->sh_video
){
3996 if(!mpctx
->sh_audio
) goto goto_next_file
;
3997 goto main
; // exit_player(_("Fatal error"));
4001 if(mpctx
->sh_video
->output_flags
& 0x08 && vo_spudec
)
4002 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
4004 #ifdef CONFIG_FREETYPE
4005 force_load_font
= 1;
4008 //================== MAIN: ==========================
4010 current_module
="main";
4013 char* msg
= property_expand_string(mpctx
, playing_msg
);
4014 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
4019 // Disable the term OSD in verbose mode
4020 if(verbose
) term_osd
= 0;
4023 //int frame_corr_num=0; //
4024 //float v_frame=0; // Video
4025 //float num_frames=0; // number of frames played
4027 int frame_time_remaining
=0; // flag
4030 // Make sure old OSD does not stay around,
4031 // e.g. with -fixed-vo and same-resolution files
4033 update_osd_msg(mpctx
);
4035 //================ SETUP AUDIO ==========================
4037 if(mpctx
->sh_audio
){
4038 reinit_audio_chain(mpctx
);
4039 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
4040 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
4043 current_module
="av_init";
4045 if(mpctx
->sh_video
){
4046 mpctx
->sh_video
->timer
=0;
4048 audio_delay
+= mpctx
->sh_video
->stream_delay
;
4050 if(mpctx
->sh_audio
){
4051 if (start_volume
>= 0)
4052 mixer_setvolume(&mpctx
->mixer
, start_volume
, start_volume
);
4054 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
4055 mpctx
->delay
=-audio_delay
;
4058 if(!mpctx
->sh_audio
){
4059 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Audio: no sound\n");
4060 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
4061 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
4062 //mpctx->d_audio->id=-2; // do not read audio chunks
4063 //uninit_player(mpctx, INITIALIZED_AO); // close device
4065 if(!mpctx
->sh_video
){
4066 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Video: no video\n");
4067 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
4068 ds_free_packs(mpctx
->d_video
);
4069 mpctx
->d_video
->id
=-2;
4070 //if(!fixed_vo) uninit_player(mpctx, INITIALIZED_VO);
4073 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
4074 goto goto_next_file
;
4076 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4077 if(force_fps
&& mpctx
->sh_video
){
4078 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
4079 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
4080 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"FPS forced to be %5.3f (ftime: %5.3f).\n",mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
4083 mp_input_set_section(mpctx
->input
, NULL
);
4084 //TODO: add desired (stream-based) sections here
4085 if (mpctx
->stream
->type
==STREAMTYPE_TV
) mp_input_set_section(mpctx
->input
, "tv");
4086 if (mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) mp_input_set_section(mpctx
->input
, "dvdnav");
4088 //==================== START PLAYING =======================
4090 if(opts
->loop_times
>1) opts
->loop_times
--; else
4091 if(opts
->loop_times
==1) opts
->loop_times
= -1;
4093 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Starting playback...\n");
4095 total_time_usage_start
=GetTimer();
4096 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
4097 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
4098 play_n_frames
=play_n_frames_mf
;
4100 if(play_n_frames
==0){
4101 mpctx
->stop_play
=PT_NEXT_ENTRY
; goto goto_next_file
;
4104 // If there's a timeline force an absolute seek to initialize state
4105 if (seek_to_sec
|| mpctx
->timeline
) {
4106 seek(mpctx
, seek_to_sec
, SEEK_ABSOLUTE
);
4107 end_at
.pos
+= seek_to_sec
;
4109 if (opts
->chapterrange
[0] > 0) {
4111 if (seek_chapter(mpctx
, opts
->chapterrange
[0]-1, &pts
, NULL
) >= 0
4113 seek(mpctx
, pts
, SEEK_ABSOLUTE
);
4116 if (end_at
.type
== END_AT_SIZE
) {
4117 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Option -endpos in MPlayer does not yet support size units.\n");
4118 end_at
.type
= END_AT_NONE
;
4121 #ifdef CONFIG_DVDNAV
4122 mp_dvdnav_context_free(mpctx
);
4123 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
4124 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
4125 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
4129 get_relative_time(mpctx
); // reset current delta
4130 mpctx
->time_frame
= 0;
4131 mpctx
->drop_message_shown
= 0;
4132 mpctx
->update_video_immediately
= true;
4133 mpctx
->total_avsync_change
= 0;
4134 mpctx
->last_chapter_seek
= -1;
4135 // Make sure VO knows current pause state
4136 if (mpctx
->sh_video
)
4137 vo_control(mpctx
->video_out
, mpctx
->paused
? VOCTRL_PAUSE
: VOCTRL_RESUME
,
4140 while(!mpctx
->stop_play
){
4141 float aq_sleep_time
=0;
4143 if (opts
->chapterrange
[1] > 0) {
4144 int cur_chapter
= get_current_chapter(mpctx
);
4145 if(cur_chapter
!=-1 && cur_chapter
+1 > opts
->chapterrange
[1])
4146 goto goto_next_file
;
4149 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
4150 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
4151 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
4152 reinit_audio_chain(mpctx
);
4155 /*========================== PLAY AUDIO ============================*/
4157 if (mpctx
->sh_audio
&& !mpctx
->paused
)
4158 if (!fill_audio_out_buffers(mpctx
))
4159 // at eof, all audio at least written to ao
4160 if (!mpctx
->sh_video
)
4161 mpctx
->stop_play
= AT_END_OF_FILE
;
4164 if(!mpctx
->sh_video
) {
4165 // handle audio-only case:
4167 // sh_audio can be NULL due to video stream switching
4168 // TODO: handle this better
4169 if (mpctx
->sh_audio
)
4170 a_pos
= playing_audio_pts(mpctx
);
4172 print_status(mpctx
, a_pos
, false);
4174 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
4175 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4176 update_subtitles(mpctx
, &mpctx
->opts
, NULL
, a_pos
, mpctx
->video_offset
,
4178 update_osd_msg(mpctx
);
4182 /*========================== PLAY VIDEO ============================*/
4184 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
4185 vo_fps
=mpctx
->sh_video
->fps
;
4187 blit_frame
= mpctx
->video_out
->frame_loaded
;
4189 double frame_time
= update_video(mpctx
);
4190 blit_frame
= mpctx
->video_out
->frame_loaded
;
4191 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
4192 if (mpctx
->sh_video
->vf_initialized
< 0) {
4193 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "\nFATAL: Could not initialize video filters (-vf) or video output (-vo).\n");
4194 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4195 goto goto_next_file
;
4198 struct sh_video
*sh_video
= mpctx
->sh_video
;
4199 update_subtitles(mpctx
, &mpctx
->opts
, sh_video
, sh_video
->pts
,
4200 mpctx
->video_offset
, mpctx
->d_sub
, 0);
4201 update_teletext(sh_video
, mpctx
->demuxer
, 0);
4202 update_osd_msg(mpctx
);
4203 struct vf_instance
*vf
= mpctx
->sh_video
->vfilter
;
4204 vf
->control(vf
, VFCTRL_DRAW_EOSD
, NULL
);
4205 vf
->control(vf
, VFCTRL_DRAW_OSD
, mpctx
->osd
);
4209 mpctx
->stop_play
= AT_END_OF_FILE
;
4211 if (mpctx
->update_video_immediately
) {
4212 // Show this frame immediately, rest normally
4213 mpctx
->update_video_immediately
= false;
4215 mpctx
->time_frame
+= frame_time
/ opts
->playback_speed
;
4216 adjust_sync(mpctx
, frame_time
);
4220 if (mpctx
->timeline
) {
4221 struct timeline_part
*next
= mpctx
->timeline
+ mpctx
->timeline_part
+ 1;
4222 if (mpctx
->sh_video
->pts
>= next
->start
4223 || mpctx
->stop_play
== AT_END_OF_FILE
4224 && mpctx
->timeline_part
+ 1 < mpctx
->num_timeline_parts
) {
4225 seek(mpctx
, next
->start
, SEEK_ABSOLUTE
);
4230 // ==========================================================================
4232 // current_module="draw_osd";
4233 // if(vo_config_count) mpctx->video_out->draw_osd();
4235 current_module
="vo_check_events";
4236 vo_check_events(mpctx
->video_out
);
4239 if (stop_xscreensaver
) {
4240 current_module
= "stop_xscreensaver";
4241 xscreensaver_heartbeat(mpctx
->x11_state
);
4244 if (heartbeat_cmd
) {
4245 static unsigned last_heartbeat
;
4246 unsigned now
= GetTimerMS();
4247 if (now
- last_heartbeat
> 30000) {
4248 last_heartbeat
= now
;
4249 system(heartbeat_cmd
);
4253 frame_time_remaining
= sleep_until_update(mpctx
, &mpctx
->time_frame
, &aq_sleep_time
);
4255 //====================== FLIP PAGE (VIDEO BLT): =========================
4257 current_module
="flip_page";
4258 if (!frame_time_remaining
&& blit_frame
) {
4259 unsigned int t2
=GetTimer();
4260 unsigned int pts_us
= mpctx
->last_time
+ mpctx
->time_frame
* 1e6
;
4262 double pts2
= mpctx
->video_out
->next_pts2
;
4263 if (pts2
!= MP_NOPTS_VALUE
&& opts
->correct_pts
) {
4264 // expected A/V sync correction is ignored
4265 double diff
= (pts2
- mpctx
->sh_video
->pts
);
4266 diff
/= opts
->playback_speed
;
4267 if (mpctx
->time_frame
< 0)
4268 diff
+= mpctx
->time_frame
;
4273 duration
= diff
* 1e6
;
4275 vo_flip_page(mpctx
->video_out
, pts_us
|1, duration
);
4277 mpctx
->last_vo_flip_duration
= (GetTimer() - t2
) * 0.000001;
4278 vout_time_usage
+= mpctx
->last_vo_flip_duration
;
4279 if (mpctx
->video_out
->driver
->flip_page_timed
) {
4280 // No need to adjust sync based on flip speed
4281 mpctx
->last_vo_flip_duration
= 0;
4282 // For print_status - VO call finishing early is OK for sync
4283 mpctx
->time_frame
-= get_relative_time(mpctx
);
4285 print_status(mpctx
, MP_NOPTS_VALUE
, true);
4288 print_status(mpctx
, MP_NOPTS_VALUE
, false);
4290 //============================ Auto QUALITY ============================
4292 /*Output quality adjustments:*/
4294 current_module
="autoq";
4295 // float total=0.000001f * (GetTimer()-aq_total_time);
4296 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4297 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4300 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4301 if(output_quality
>1 && aq_sleep_time
<0)
4304 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4306 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4307 set_video_quality(mpctx
->sh_video
,output_quality
);
4310 if (!frame_time_remaining
&& blit_frame
) {
4311 if (play_n_frames
>= 0) {
4313 if (play_n_frames
<= 0)
4314 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4316 if (mpctx
->step_frames
> 0) {
4317 mpctx
->step_frames
--;
4318 if (mpctx
->step_frames
== 0)
4319 pause_player(mpctx
);
4324 // FIXME: add size based support for -endpos
4325 if (end_at
.type
== END_AT_TIME
&&
4326 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
4327 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4329 } // end if(mpctx->sh_video)
4331 #ifdef CONFIG_DVDNAV
4332 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
4334 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
4335 if (!vo_spudec
|| !spudec_apply_palette_crop(vo_spudec
, hl
.palette
, hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
)) {
4336 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
4337 vo_osd_changed (OSDTYPE_DVDNAV
);
4339 osd_set_nav_box(0, 0, 0, 0);
4340 vo_osd_changed(OSDTYPE_DVDNAV
);
4341 vo_osd_changed(OSDTYPE_SPU
);
4344 if (mp_dvdnav_stream_has_changed(mpctx
->stream
)) {
4346 if (mpctx
->sh_video
&&
4347 stream_control (mpctx
->demuxer
->stream
,
4348 STREAM_CTRL_GET_ASPECT_RATIO
, &ar
)
4349 != STREAM_UNSUPPORTED
)
4350 mpctx
->sh_video
->stream_aspect
= ar
;
4355 //================= Keyboard events, SEEKing ====================
4357 current_module
="key_events";
4362 while ((cmd
= mp_input_get_cmd(mpctx
->input
, 0, 0)) != NULL
) {
4363 run_command(mpctx
, cmd
);
4365 if (mpctx
->stop_play
)
4367 if (mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
) {
4368 cmd
= mp_input_get_cmd(mpctx
->input
, 0, 1);
4369 /* Allow seek commands to be combined, but execute the real seek
4370 * before processing other commands */
4371 if (!cmd
|| cmd
->id
!= MP_CMD_SEEK
)
4375 if (!mpctx
->paused
|| mpctx
->stop_play
|| mpctx
->rel_seek_secs
4376 || mpctx
->abs_seek_pos
)
4378 if (mpctx
->sh_video
) {
4379 update_osd_msg(mpctx
);
4380 int hack
= vo_osd_changed(0);
4381 vo_osd_changed(hack
);
4383 if (redraw_osd(mpctx
->sh_video
, mpctx
->osd
) < 0) {
4384 add_step_frame(mpctx
);
4396 if (step_sec
> 0 && !mpctx
->paused
) {
4397 mpctx
->osd_function
=OSD_FFW
;
4398 mpctx
->rel_seek_secs
+=step_sec
;
4404 if(mpctx
->stop_play
==AT_END_OF_FILE
&& opts
->loop_times
>=0) {
4405 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d\n", opts
->loop_times
);
4407 if(opts
->loop_times
>1) opts
->loop_times
--; else
4408 if(opts
->loop_times
==1) opts
->loop_times
=-1;
4409 play_n_frames
=play_n_frames_mf
;
4411 mpctx
->abs_seek_pos
=SEEK_ABSOLUTE
; mpctx
->rel_seek_secs
=seek_to_sec
;
4414 if(mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
){
4415 seek(mpctx
, mpctx
->rel_seek_secs
, mpctx
->abs_seek_pos
);
4417 mpctx
->rel_seek_secs
=0;
4418 mpctx
->abs_seek_pos
=0;
4421 } // while(!mpctx->stop_play)
4423 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->stop_play
);
4426 if(mpctx
->dvbin_reopen
)
4428 mpctx
->stop_play
= 0;
4429 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_STREAM
|INITIALIZED_GETCH2
|(opts
->fixed_vo
?INITIALIZED_VO
:0)));
4430 cache_uninit(mpctx
->stream
);
4431 mpctx
->dvbin_reopen
= 0;
4432 goto goto_enable_cache
;
4437 goto_next_file
: // don't jump here after ao/vo/getch initialization!
4439 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
4442 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
4443 double total_time_usage
;
4444 total_time_usage_start
=GetTimer()-total_time_usage_start
;
4445 total_time_usage
= (float)total_time_usage_start
*0.000001;
4446 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4447 video_time_usage
,vout_time_usage
,audio_time_usage
,
4448 total_time_usage
-tot
,total_time_usage
);
4449 if(total_time_usage
>0.0)
4450 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4451 100.0*video_time_usage
/total_time_usage
,
4452 100.0*vout_time_usage
/total_time_usage
,
4453 100.0*audio_time_usage
/total_time_usage
,
4454 100.0*(total_time_usage
-tot
)/total_time_usage
,
4456 if(total_frame_cnt
&& frame_dropping
)
4457 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4458 total_frame_cnt
-drop_frame_cnt
,
4459 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
4461 100*drop_frame_cnt
/total_frame_cnt
,
4463 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
4466 // time to uninit all, except global stuff:
4467 uninit_player(mpctx
, INITIALIZED_ALL
-(opts
->fixed_vo
?INITIALIZED_VO
:0));
4469 if(mpctx
->set_of_sub_size
> 0) {
4470 current_module
="sub_free";
4471 for(i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
4472 sub_free(mpctx
->set_of_subtitles
[i
]);
4474 if(mpctx
->set_of_ass_tracks
[i
])
4475 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
4478 mpctx
->set_of_sub_size
= 0;
4480 vo_sub_last
= vo_sub
=NULL
;
4485 ass_clear_fonts(ass_library
);
4488 if (!mpctx
->stop_play
) // In case some goto jumped here...
4489 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4491 int playtree_direction
= 1;
4493 if(mpctx
->stop_play
== PT_NEXT_ENTRY
|| mpctx
->stop_play
== PT_PREV_ENTRY
) {
4494 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) != PLAY_TREE_ITER_ENTRY
) {
4495 play_tree_iter_free(mpctx
->playtree_iter
);
4496 mpctx
->playtree_iter
= NULL
;
4498 mpctx
->play_tree_step
= 1;
4499 } else if(mpctx
->stop_play
== PT_UP_NEXT
|| mpctx
->stop_play
== PT_UP_PREV
) {
4500 int direction
= mpctx
->stop_play
== PT_UP_NEXT
? 1 : -1;
4501 if(mpctx
->playtree_iter
) {
4502 if(play_tree_iter_up_step(mpctx
->playtree_iter
,direction
,0) != PLAY_TREE_ITER_ENTRY
) {
4503 play_tree_iter_free(mpctx
->playtree_iter
);
4504 mpctx
->playtree_iter
= NULL
;
4507 } else if (mpctx
->stop_play
== PT_STOP
) {
4508 play_tree_iter_free(mpctx
->playtree_iter
);
4509 mpctx
->playtree_iter
= NULL
;
4510 } else { // NEXT PREV SRC
4511 playtree_direction
= mpctx
->stop_play
== PT_PREV_SRC
? -1 : 1;
4514 while(mpctx
->playtree_iter
!= NULL
) {
4515 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, playtree_direction
);
4516 if(mpctx
->filename
== NULL
) {
4517 if(play_tree_iter_step(mpctx
->playtree_iter
, playtree_direction
, 0) != PLAY_TREE_ITER_ENTRY
) {
4518 play_tree_iter_free(mpctx
->playtree_iter
);
4519 mpctx
->playtree_iter
= NULL
;
4525 if(mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
4526 if(!mpctx
->playtree_iter
) mpctx
->filename
= NULL
;
4527 mpctx
->stop_play
= 0;
4528 goto play_next_file
;
4532 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
4536 #endif /* DISABLE_MAIN */