3 /// \ingroup Properties Command2Property OSDMsgStack
11 #if defined(__MINGW32__) || defined(__CYGWIN__)
12 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
18 // #include <sys/mman.h>
19 #include <sys/types.h>
21 #include <sys/ioctl.h>
24 #define SIGHUP 1 /* hangup */
25 #define SIGQUIT 3 /* quit */
26 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
27 #define SIGBUS 10 /* bus error */
28 #define SIGPIPE 13 /* broken pipe */
43 #define HELP_MP_DEFINE_STATIC
49 #include "access_mpcontext.h"
50 #include "m_property.h"
52 #include "cfg-mplayer-def.h"
54 #include "ffmpeg_files/intreadwrite.h"
55 #include "libavutil/avstring.h"
57 #include "subreader.h"
60 #include "libvo/video_out.h"
62 #include "libvo/font_load.h"
63 #include "libvo/sub.h"
66 #include "libvo/x11_common.h"
69 #include "libao2/audio_out.h"
71 #include "codec-cfg.h"
78 #include "osdep/getch2.h"
79 #include "osdep/timer.h"
80 #include "osdep/findfiles.h"
82 #include "input/input.h"
84 const int under_mencoder
= 0;
86 int player_idle_mode
=0;
88 int enable_mouse_movements
=0;
89 float start_volume
= -1;
91 #include "osdep/priority.h"
95 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
99 #include <linux/rtc.h>
102 #define RTC_IRQP_SET RTCIO_IRQP_SET
103 #define RTC_PIE_ON RTCIO_PIE_ON
104 #endif /* __linux__ */
105 #endif /* HAVE_RTC */
107 #include "stream/tv.h"
108 #include "stream/stream_radio.h"
110 #include "stream/dvbin.h"
112 #include "stream/cache2.h"
114 //**************************************************************************//
116 //**************************************************************************//
117 #include "playtree.h"
118 #include "playtreeparser.h"
120 //**************************************************************************//
122 //**************************************************************************//
123 #include "parser-cfg.h"
124 #include "parser-mpcmd.h"
126 //**************************************************************************//
128 //**************************************************************************//
130 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
132 #include "get_path.h"
134 //**************************************************************************//
135 //**************************************************************************//
136 // Input media streaming & demultiplexer:
137 //**************************************************************************//
139 static int max_framesize
=0;
141 #include "stream/stream.h"
142 #include "libmpdemux/demuxer.h"
143 #include "libmpdemux/stheader.h"
145 #ifdef CONFIG_DVDREAD
146 #include "stream/stream_dvd.h"
148 #include "stream/stream_dvdnav.h"
150 #include "libmpcodecs/dec_audio.h"
151 #include "libmpcodecs/dec_video.h"
152 #include "libmpcodecs/mp_image.h"
153 #include "libmpcodecs/vf.h"
154 #include "libmpcodecs/vd.h"
160 #include "defaultopts.h"
162 #define Exit_SIGILL_RTCpuSel _(\
163 "- MPlayer crashed by an 'Illegal Instruction'.\n"\
164 " It may be a bug in our new runtime CPU-detection code...\n"\
165 " Please read DOCS/HTML/en/bugreports.html.\n")
167 #define Exit_SIGILL _(\
168 "- MPlayer crashed by an 'Illegal Instruction'.\n"\
169 " It usually happens when you run it on a CPU different than the one it was\n"\
170 " compiled/optimized for.\n"\
173 #define Exit_SIGSEGV_SIGFPE _(\
174 "- MPlayer crashed by bad usage of CPU/FPU/RAM.\n"\
175 " Recompile MPlayer with --enable-debug and make a 'gdb' backtrace and\n"\
176 " disassembly. Details in DOCS/HTML/en/bugreports_what.html#bugreports_crash.\n")
178 #define Exit_SIGCRASH _(\
179 "- MPlayer crashed. This shouldn't happen.\n"\
180 " It can be a bug in the MPlayer code _or_ in your drivers _or_ in your\n"\
181 " gcc version. If you think it's MPlayer's fault, please read\n"\
182 " DOCS/HTML/en/bugreports.html and follow the instructions there. We can't and\n"\
183 " won't help unless you provide this information when reporting a possible bug.\n")
185 #define SystemTooSlow _("\n\n"\
186 " ************************************************\n"\
187 " **** Your system is too SLOW to play this! ****\n"\
188 " ************************************************\n\n"\
189 "Possible reasons, problems, workarounds:\n"\
190 "- Most common: broken/buggy _audio_ driver\n"\
191 " - Try -ao sdl or use the OSS emulation of ALSA.\n"\
192 " - Experiment with different values for -autosync, 30 is a good start.\n"\
193 "- Slow video output\n"\
194 " - Try a different -vo driver (-vo help for a list) or try -framedrop!\n"\
196 " - Don't try to play a big DVD/DivX on a slow CPU! Try some of the lavdopts,\n"\
197 " e.g. -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all.\n"\
199 " - Try various combinations of -nobps -ni -forceidx -mc 0.\n"\
200 "- Slow media (NFS/SMB mounts, DVD, VCD etc)\n"\
201 " - Try -cache 8192.\n"\
202 "- Are you using -cache to play a non-interleaved AVI file?\n"\
203 " - Try -nocache.\n"\
204 "Read DOCS/HTML/en/video.html for tuning/speedup tips.\n"\
205 "If none of this helps you, read DOCS/HTML/en/bugreports.html.\n\n")
208 //**************************************************************************//
209 //**************************************************************************//
211 // Common FIFO functions, and keyboard/event FIFO code
213 int noconsolecontrols
=0;
214 //**************************************************************************//
217 double video_time_usage
=0;
218 double vout_time_usage
=0;
219 static double audio_time_usage
=0;
220 static int total_time_usage_start
=0;
221 static int total_frame_cnt
=0;
222 static int drop_frame_cnt
=0; // total number of dropped frames
227 static int output_quality
=0;
229 static int list_properties
= 0;
232 static char* term_osd_esc
= "\x1b[A\r\x1b[K";
233 static char* playing_msg
= NULL
;
235 static double seek_to_sec
;
236 static off_t seek_to_byte
=0;
237 static off_t step_sec
=0;
239 static m_time_size_t end_at
= { .type
= END_AT_NONE
, .pos
= 0 };
242 int autosync
=0; // 30 might be a good default value.
245 char **audio_codec_list
=NULL
; // override audio codec
246 char **video_codec_list
=NULL
; // override video codec
247 char **audio_fm_list
=NULL
; // override audio codec family
248 char **video_fm_list
=NULL
; // override video codec family
251 extern char *demuxer_name
; // override demuxer
252 extern char *audio_demuxer_name
; // override audio demuxer
253 extern char *sub_demuxer_name
; // override sub demuxer
256 char* audio_lang
=NULL
;
257 char* dvdsub_lang
=NULL
;
258 static char* spudec_ifo
=NULL
;
259 int forced_subs_only
=0;
263 int stream_cache_size
=-1;
264 #ifdef CONFIG_STREAM_CACHE
265 extern int cache_fill_status
;
267 float stream_cache_min_percent
=20.0;
268 float stream_cache_seek_min_percent
=50.0;
270 #define cache_fill_status 0
274 static char *stream_dump_name
="stream.dump";
275 int stream_dump_type
=0;
278 static float default_max_pts_correction
=-1;//0.01f;
280 static int ignore_start
=0;
282 static int softsleep
=0;
285 static int force_srate
=0;
286 static int audio_output_format
=-1; // AF_FORMAT_UNKNOWN
287 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
288 static int play_n_frames
=-1;
289 static int play_n_frames_mf
=-1;
292 char *font_name
=NULL
;
293 char *sub_font_name
=NULL
;
294 extern int font_fontconfig
;
295 float font_factor
=0.75;
296 char **sub_name
=NULL
;
300 char *vobsub_name
=NULL
;
301 /*DSP!!char *dsp=NULL;*/
303 int suboverlap_enabled
= 1;
307 char* current_module
=NULL
; // for debugging
313 #include "m_struct.h"
314 #include "libmenu/menu.h"
315 void vf_menu_pause_update(struct vf_instance
* vf
);
316 extern vf_info_t vf_info_menu
;
317 static const vf_info_t
* const libmenu_vfs
[] = {
321 static vf_instance_t
* vf_menu
= NULL
;
323 static char* menu_cfg
= NULL
;
324 static char* menu_root
= "main";
329 static int nortc
= 1;
330 static char* rtc_device
;
333 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
334 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
335 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode.
336 int use_filedir_conf
;
338 #include "mpcommon.h"
341 #include "metadata.h"
343 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
345 const void *mpctx_get_video_out(MPContext
*mpctx
)
347 return mpctx
->video_out
;
350 const void *mpctx_get_audio_out(MPContext
*mpctx
)
352 return mpctx
->audio_out
;
355 void *mpctx_get_demuxer(MPContext
*mpctx
)
357 return mpctx
->demuxer
;
360 void *mpctx_get_playtree_iter(MPContext
*mpctx
)
362 return mpctx
->playtree_iter
;
365 void *mpctx_get_mixer(MPContext
*mpctx
)
367 return &mpctx
->mixer
;
370 int mpctx_get_global_sub_size(MPContext
*mpctx
)
372 return mpctx
->global_sub_size
;
375 int mpctx_get_osd_function(MPContext
*mpctx
)
377 return mpctx
->osd_function
;
380 static float get_relative_time(struct MPContext
*mpctx
)
382 unsigned int new_time
= GetTimer();
383 unsigned int delta
= new_time
- mpctx
->last_time
;
384 mpctx
->last_time
= new_time
;
385 return delta
* 0.000001;
388 static int is_valid_metadata_type(struct MPContext
*mpctx
, metadata_t type
) {
391 /* check for valid video stream */
392 case META_VIDEO_CODEC
:
393 case META_VIDEO_BITRATE
:
394 case META_VIDEO_RESOLUTION
:
396 if (!mpctx
->sh_video
)
401 /* check for valid audio stream */
402 case META_AUDIO_CODEC
:
403 case META_AUDIO_BITRATE
:
404 case META_AUDIO_SAMPLES
:
406 if (!mpctx
->sh_audio
)
411 /* check for valid demuxer */
412 case META_INFO_TITLE
:
413 case META_INFO_ARTIST
:
414 case META_INFO_ALBUM
:
416 case META_INFO_COMMENT
:
417 case META_INFO_TRACK
:
418 case META_INFO_GENRE
:
432 static char *get_demuxer_info(struct MPContext
*mpctx
, char *tag
) {
433 char **info
= mpctx
->demuxer
->info
;
439 for (n
= 0; info
[2*n
] != NULL
; n
++)
440 if (!strcasecmp (info
[2*n
], tag
))
443 return info
[2*n
+1] ? strdup (info
[2*n
+1]) : NULL
;
446 char *get_metadata(struct MPContext
*mpctx
, metadata_t type
)
449 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
450 sh_video_t
* const sh_video
= mpctx
->sh_video
;
452 if (!is_valid_metadata_type(mpctx
, type
))
459 return strdup (mp_basename2 (mpctx
->filename
));
462 case META_VIDEO_CODEC
:
464 if (sh_video
->format
== 0x10000001)
465 meta
= strdup ("mpeg1");
466 else if (sh_video
->format
== 0x10000002)
467 meta
= strdup ("mpeg2");
468 else if (sh_video
->format
== 0x10000004)
469 meta
= strdup ("mpeg4");
470 else if (sh_video
->format
== 0x10000005)
471 meta
= strdup ("h264");
472 else if (sh_video
->format
>= 0x20202020)
475 sprintf (meta
, "%.4s", (char *) &sh_video
->format
);
480 sprintf (meta
, "0x%08X", sh_video
->format
);
485 case META_VIDEO_BITRATE
:
488 sprintf (meta
, "%d kbps", (int) (sh_video
->i_bps
* 8 / 1024));
492 case META_VIDEO_RESOLUTION
:
495 sprintf (meta
, "%d x %d", sh_video
->disp_w
, sh_video
->disp_h
);
499 case META_AUDIO_CODEC
:
501 if (sh_audio
->codec
&& sh_audio
->codec
->name
)
502 meta
= strdup (sh_audio
->codec
->name
);
506 case META_AUDIO_BITRATE
:
509 sprintf (meta
, "%d kbps", (int) (sh_audio
->i_bps
* 8/1000));
513 case META_AUDIO_SAMPLES
:
516 sprintf (meta
, "%d Hz, %d ch.", sh_audio
->samplerate
, sh_audio
->channels
);
520 /* check for valid demuxer */
521 case META_INFO_TITLE
:
522 return get_demuxer_info(mpctx
, "Title");
524 case META_INFO_ARTIST
:
525 return get_demuxer_info(mpctx
, "Artist");
527 case META_INFO_ALBUM
:
528 return get_demuxer_info(mpctx
, "Album");
531 return get_demuxer_info(mpctx
, "Year");
533 case META_INFO_COMMENT
:
534 return get_demuxer_info(mpctx
, "Comment");
536 case META_INFO_TRACK
:
537 return get_demuxer_info(mpctx
, "Track");
539 case META_INFO_GENRE
:
540 return get_demuxer_info(mpctx
, "Genre");
549 /// step size of mixer changes
553 static void mp_dvdnav_context_free(MPContext
*ctx
){
554 if (ctx
->nav_smpi
) free_mp_image(ctx
->nav_smpi
);
555 ctx
->nav_smpi
= NULL
;
556 if (ctx
->nav_buffer
) free(ctx
->nav_buffer
);
557 ctx
->nav_buffer
= NULL
;
558 ctx
->nav_start
= NULL
;
559 ctx
->nav_in_size
= 0;
563 void uninit_player(struct MPContext
*mpctx
, unsigned int mask
){
564 mask
=mpctx
->initialized_flags
&mask
;
566 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
568 if(mask
&INITIALIZED_ACODEC
){
569 mpctx
->initialized_flags
&=~INITIALIZED_ACODEC
;
570 current_module
="uninit_acodec";
571 if(mpctx
->sh_audio
) uninit_audio(mpctx
->sh_audio
);
572 mpctx
->sh_audio
=NULL
;
573 mpctx
->mixer
.afilter
= NULL
;
576 if(mask
&INITIALIZED_VCODEC
){
577 mpctx
->initialized_flags
&=~INITIALIZED_VCODEC
;
578 current_module
="uninit_vcodec";
579 if(mpctx
->sh_video
) uninit_video(mpctx
->sh_video
);
580 mpctx
->sh_video
=NULL
;
586 if(mask
&INITIALIZED_DEMUXER
){
587 mpctx
->initialized_flags
&=~INITIALIZED_DEMUXER
;
588 current_module
="free_demuxer";
589 if (mpctx
->num_sources
) {
590 mpctx
->demuxer
= mpctx
->sources
[0].demuxer
;
591 for (int i
= 1; i
< mpctx
->num_sources
; i
++) {
592 free_stream(mpctx
->sources
[i
].stream
);
593 free_demuxer(mpctx
->sources
[i
].demuxer
);
596 talloc_free(mpctx
->sources
);
597 mpctx
->sources
= NULL
;
598 mpctx
->num_sources
= 0;
599 talloc_free(mpctx
->timeline
);
600 mpctx
->timeline
= NULL
;
601 mpctx
->num_timeline_parts
= 0;
602 talloc_free(mpctx
->chapters
);
603 mpctx
->chapters
= NULL
;
604 mpctx
->num_chapters
= 0;
605 mpctx
->video_offset
= 0;
607 mpctx
->stream
=mpctx
->demuxer
->stream
;
608 free_demuxer(mpctx
->demuxer
);
613 // kill the cache process:
614 if(mask
&INITIALIZED_STREAM
){
615 mpctx
->initialized_flags
&=~INITIALIZED_STREAM
;
616 current_module
="uninit_stream";
617 if(mpctx
->stream
) free_stream(mpctx
->stream
);
621 if(mask
&INITIALIZED_VO
){
622 mpctx
->initialized_flags
&=~INITIALIZED_VO
;
623 current_module
="uninit_vo";
624 vo_destroy(mpctx
->video_out
);
625 mpctx
->video_out
=NULL
;
627 mp_dvdnav_context_free(mpctx
);
631 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
632 if(mask
&INITIALIZED_GETCH2
){
633 mpctx
->initialized_flags
&=~INITIALIZED_GETCH2
;
634 current_module
="uninit_getch2";
635 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
640 if(mask
&INITIALIZED_VOBSUB
){
641 mpctx
->initialized_flags
&=~INITIALIZED_VOBSUB
;
642 current_module
="uninit_vobsub";
643 if(vo_vobsub
) vobsub_close(vo_vobsub
);
647 if (mask
&INITIALIZED_SPUDEC
){
648 mpctx
->initialized_flags
&=~INITIALIZED_SPUDEC
;
649 current_module
="uninit_spudec";
650 spudec_free(vo_spudec
);
654 if(mask
&INITIALIZED_AO
){
655 mpctx
->initialized_flags
&=~INITIALIZED_AO
;
656 current_module
="uninit_ao";
657 if (mpctx
->edl_muted
) mixer_mute(&mpctx
->mixer
);
658 mpctx
->audio_out
->uninit(mpctx
->stop_play
!= AT_END_OF_FILE
);
659 mpctx
->audio_out
=NULL
;
665 void exit_player_with_rc(struct MPContext
*mpctx
, exit_reason_t how
, int rc
)
667 uninit_player(mpctx
, INITIALIZED_ALL
);
668 #if defined(__MINGW32__) || defined(__CYGWIN__)
672 vo_uninit(mpctx
->x11_state
); // Close the X11 connection (if any is open).
675 current_module
="uninit_input";
676 mp_input_uninit(mpctx
->input
);
682 #ifdef CONFIG_FREETYPE
683 current_module
="uninit_font";
684 if (mpctx
->osd
&& mpctx
->osd
->sub_font
!= vo_font
)
685 free_font_desc(mpctx
->osd
->sub_font
);
686 free_font_desc(vo_font
);
690 osd_free(mpctx
->osd
);
693 ass_library_done(ass_library
);
696 current_module
="exit_player";
698 // free mplayer config
700 m_config_free(mpctx
->mconfig
);
703 play_tree_free(mpctx
->playtree
, 1);
705 talloc_free(mpctx
->key_fifo
);
707 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
710 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Quit");
711 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=QUIT\n");
714 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","End of file");
715 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=EOF\n");
718 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nExiting... (%s)\n","Fatal error");
719 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=ERROR\n");
722 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_EXIT=NONE\n");
724 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
729 static void exit_player(struct MPContext
*mpctx
, exit_reason_t how
)
731 exit_player_with_rc(mpctx
, how
, 1);
735 static void child_sighandler(int x
){
737 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
741 #ifdef CONFIG_CRASH_DEBUG
742 static char *prog_path
;
743 static int crash_debug
= 0;
746 static void exit_sighandler(int x
){
747 static int sig_count
=0;
748 #ifdef CONFIG_CRASH_DEBUG
749 if (!crash_debug
|| x
!= SIGTRAP
)
754 /* We're crashing bad and can't uninit cleanly :(
755 * by popular request, we make one last (dirty)
756 * effort to restore the user's
761 if(sig_count
==6) exit(1);
765 kill(getpid(),SIGKILL
);
768 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" "\nMPlayer interrupted by signal %d in module: %s\n",x
,
769 current_module
?current_module
:"unknown"
771 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_SIGNAL=%d\n", x
);
778 async_quit_request
= 1;
779 return; // killed from keyboard (^C) or killed [-9]
781 #if CONFIG_RUNTIME_CPUDETECT
782 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL_RTCpuSel
);
784 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGILL
);
788 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGSEGV_SIGFPE
);
790 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,Exit_SIGCRASH
);
791 #ifdef CONFIG_CRASH_DEBUG
794 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
796 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
797 if (gdb_pid
== 0) { // We are the child
799 snprintf(spid
, sizeof(spid
), "%i", getppid());
800 getch2_disable(); // allow terminal to work properly with gdb
801 if (execlp("gdb", "gdb", prog_path
, spid
, "-ex", "bt", NULL
) == -1)
802 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
803 } else if (gdb_pid
< 0)
804 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
806 waitpid(gdb_pid
, NULL
, 0);
808 if (x
== SIGTRAP
) return;
816 #include "cfg-mplayer.h"
818 static int cfg_include(m_option_t
*conf
, char *filename
)
820 return m_config_parse_config_file(conf
->priv
, filename
);
823 static void parse_cfgfiles(struct MPContext
*mpctx
, m_config_t
* conf
)
827 if (!disable_system_conf
&&
828 m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
829 exit_player(mpctx
, EXIT_NONE
);
830 if ((conffile
= get_path("")) == NULL
) {
831 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"Cannot find HOME directory.\n");
836 mkdir(conffile
, 0777);
839 if ((conffile
= get_path("config")) == NULL
) {
840 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"get_path(\"config\") problem\n");
842 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
843 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Creating config file: %s\n", conffile
);
844 write(conffile_fd
, default_config
, strlen(default_config
));
847 if (!disable_user_conf
&&
848 m_config_parse_config_file(conf
, conffile
) < 0)
849 exit_player(mpctx
, EXIT_NONE
);
855 #define PROFILE_CFG_PROTOCOL "protocol."
857 static void load_per_protocol_config (m_config_t
* conf
, const char *const file
)
860 char protocol
[strlen (PROFILE_CFG_PROTOCOL
) + strlen (file
) + 1];
863 /* does filename actually uses a protocol ? */
864 str
= strstr (file
, "://");
868 sprintf (protocol
, "%s%s", PROFILE_CFG_PROTOCOL
, file
);
869 protocol
[strlen (PROFILE_CFG_PROTOCOL
)+strlen(file
)-strlen(str
)] = '\0';
870 p
= m_config_get_profile (conf
, protocol
);
873 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading protocol-related profile '%s'\n", protocol
);
874 m_config_set_profile(conf
,p
);
878 #define PROFILE_CFG_EXTENSION "extension."
880 static void load_per_extension_config (m_config_t
* conf
, const char *const file
)
883 char extension
[strlen (PROFILE_CFG_EXTENSION
) + 8];
886 /* does filename actually have an extension ? */
887 str
= strrchr (file
, '.');
891 sprintf (extension
, PROFILE_CFG_EXTENSION
);
892 strncat (extension
, ++str
, 7);
893 p
= m_config_get_profile (conf
, extension
);
896 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", extension
);
897 m_config_set_profile(conf
,p
);
901 #define PROFILE_CFG_VO "vo."
902 #define PROFILE_CFG_AO "ao."
904 static void load_per_output_config (m_config_t
* conf
, char *cfg
, char *out
)
906 char profile
[strlen (cfg
) + strlen (out
) + 1];
909 sprintf (profile
, "%s%s", cfg
, out
);
910 p
= m_config_get_profile (conf
, profile
);
913 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Loading extension-related profile '%s'\n", profile
);
914 m_config_set_profile(conf
,p
);
919 * Tries to load a config file
920 * @return 0 if file was not found, 1 otherwise
922 static int try_load_config(m_config_t
*conf
, const char *file
)
927 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Loading config '%s'\n", file
);
928 m_config_parse_config_file (conf
, file
);
932 static void load_per_file_config (m_config_t
* conf
, const char *const file
)
938 if (strlen(file
) > PATH_MAX
- 14) {
939 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Filename is too long, can not load file or directory specific config files\n");
942 sprintf (cfg
, "%s.conf", file
);
944 name
= strrchr(cfg
, '/');
945 if (HAVE_DOS_PATHS
) {
946 char *tmp
= strrchr(cfg
, '\\');
947 if (!name
|| tmp
> name
)
949 tmp
= strrchr(cfg
, ':');
950 if (!name
|| tmp
> name
)
958 if (use_filedir_conf
) {
959 char dircfg
[PATH_MAX
];
961 strcpy(dircfg
+ (name
- cfg
), "mplayer.conf");
962 try_load_config(conf
, dircfg
);
964 if (try_load_config(conf
, cfg
))
968 if ((confpath
= get_path (name
)) != NULL
)
970 try_load_config(conf
, confpath
);
976 /* When libmpdemux performs a blocking operation (network connection or
977 * cache filling) if the operation fails we use this function to check
978 * if it was interrupted by the user.
979 * The function returns a new value for eof. */
980 static int libmpdemux_was_interrupted(struct MPContext
*mpctx
, int stop_play
)
983 if((cmd
= mp_input_get_cmd(mpctx
->input
, 0,0,0)) != NULL
) {
986 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
987 case MP_CMD_PLAY_TREE_STEP
: {
988 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
989 mpctx
->play_tree_step
= (cmd
->args
[0].v
.i
== 0) ? 1 : cmd
->args
[0].v
.i
;
991 case MP_CMD_PLAY_TREE_UP_STEP
: {
992 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
994 case MP_CMD_PLAY_ALT_SRC_STEP
: {
995 stop_play
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
1003 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
1005 static int playtree_add_playlist(struct MPContext
*mpctx
, play_tree_t
* entry
)
1007 play_tree_add_bpf(entry
,mpctx
->filename
);
1011 entry
= mpctx
->playtree_iter
->tree
;
1012 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1013 return PT_NEXT_ENTRY
;
1015 if(mpctx
->playtree_iter
->tree
== entry
) { // Loop with a single file
1016 if(play_tree_iter_up_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1017 return PT_NEXT_ENTRY
;
1020 play_tree_remove(entry
,1,1);
1023 play_tree_insert_entry(mpctx
->playtree_iter
->tree
,entry
);
1024 play_tree_set_params_from(entry
,mpctx
->playtree_iter
->tree
);
1025 entry
= mpctx
->playtree_iter
->tree
;
1026 if(play_tree_iter_step(mpctx
->playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
1027 return PT_NEXT_ENTRY
;
1029 play_tree_remove(entry
,1,1);
1034 void add_subtitles(struct MPContext
*mpctx
, char *filename
, float fps
, int noerr
)
1038 ASS_Track
*asst
= 0;
1041 if (filename
== NULL
|| mpctx
->set_of_sub_size
>= MAX_SUBTITLE_FILES
) {
1045 subd
= sub_read_file(filename
, fps
);
1049 asst
= ass_read_file(ass_library
, filename
, sub_cp
);
1051 asst
= ass_read_file(ass_library
, filename
, 0);
1053 if (ass_enabled
&& subd
&& !asst
)
1054 asst
= ass_read_subdata(ass_library
, subd
, fps
);
1060 mp_tmsg(MSGT_CPLAYER
, noerr
? MSGL_WARN
: MSGL_ERR
, "Cannot load subtitles: %s\n",
1061 filename_recode(filename
));
1062 #if defined(_WIN32) && !defined(HAVE_NEW_GUI)
1064 static char message
[MAX_PATH
+ 1];
1065 char *s
= strrchr(filename
, '\\');
1066 if (!s
) s
= strrchr(filename
, '/');
1067 if (s
) s
++; else s
= filename
;
1069 snprintf(message
, MAX_PATH
, "MPlayer: %s", filename_recode(s
));
1070 message
[MAX_PATH
] = 0;
1071 SetConsoleTitle(message
);
1076 if (!asst
&& !subd
) return;
1077 mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_size
] = asst
;
1081 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = subd
;
1082 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", mpctx
->set_of_sub_size
);
1083 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n",
1084 filename_recode(filename
));
1085 ++mpctx
->set_of_sub_size
;
1086 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "SUB: Added subtitle file (%d): %s\n", mpctx
->set_of_sub_size
,
1087 filename_recode(filename
));
1090 void init_vo_spudec(struct MPContext
*mpctx
)
1093 spudec_free(vo_spudec
);
1094 mpctx
->initialized_flags
&= ~INITIALIZED_SPUDEC
;
1097 unsigned int palette
[16], width
, height
;
1098 current_module
="spudec_init_vobsub";
1099 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1100 vo_spudec
=spudec_new_scaled(palette
, width
, height
, NULL
, 0);
1103 #ifdef CONFIG_DVDREAD
1104 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVD
) {
1105 current_module
="spudec_init_dvdread";
1106 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(mpctx
->stream
->priv
))->cur_pgc
->palette
,
1107 mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
,
1112 #ifdef CONFIG_DVDNAV
1113 if (vo_spudec
==NULL
&& mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) {
1114 unsigned int *palette
= mp_dvdnav_get_spu_clut(mpctx
->stream
);
1115 current_module
="spudec_init_dvdnav";
1116 vo_spudec
=spudec_new_scaled(palette
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, NULL
, 0);
1120 if (vo_spudec
==NULL
) {
1121 sh_sub_t
*sh
= (sh_sub_t
*)mpctx
->d_sub
->sh
;
1122 current_module
="spudec_init_normal";
1123 vo_spudec
=spudec_new_scaled(NULL
, mpctx
->sh_video
->disp_w
, mpctx
->sh_video
->disp_h
, sh
->extradata
, sh
->extradata_len
);
1124 spudec_set_font_factor(vo_spudec
,font_factor
);
1127 if (vo_spudec
!=NULL
) {
1128 mpctx
->initialized_flags
|=INITIALIZED_SPUDEC
;
1129 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
1134 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1135 * make it all work is to use the builtin SDL-bootstrap code, which
1136 * will be done automatically by replacing our main() if we include SDL.h.
1138 #if defined(__APPLE__) && defined(CONFIG_SDL)
1143 * \brief append a formatted string
1144 * \param buf buffer to print into
1145 * \param pos position of terminating 0 in buf
1146 * \param len maximum number of characters in buf, not including terminating 0
1147 * \param format printf format string
1149 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
1152 va_start(va
, format
);
1153 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
1162 * \brief append time in the hh:mm:ss.f format
1163 * \param buf buffer to print into
1164 * \param pos position of terminating 0 in buf
1165 * \param len maximum number of characters in buf, not including terminating 0
1166 * \param time time value to convert/append
1168 static void sadd_hhmmssf(char *buf
, unsigned *pos
, int len
, float time
) {
1169 long tenths
= 10 * time
;
1170 int f1
= tenths
% 10;
1171 int ss
= (tenths
/ 10) % 60;
1172 int mm
= (tenths
/ 600) % 60;
1173 int hh
= tenths
/ 36000;
1175 saddf(buf
, pos
, len
, "unknown");
1179 saddf(buf
, pos
, len
, "%2d:", hh
);
1180 if (hh
> 0 || mm
> 0)
1181 saddf(buf
, pos
, len
, "%02d:", mm
);
1182 saddf(buf
, pos
, len
, "%02d.%1d", ss
, f1
);
1185 static void print_status(struct MPContext
*mpctx
, double a_pos
, bool at_frame
)
1187 struct MPOpts
*opts
= &mpctx
->opts
;
1188 sh_video_t
* const sh_video
= mpctx
->sh_video
;
1190 if (mpctx
->sh_audio
&& a_pos
== MP_NOPTS_VALUE
)
1191 a_pos
= playing_audio_pts(mpctx
);
1192 if (mpctx
->sh_audio
&& sh_video
&& at_frame
) {
1193 mpctx
->last_av_difference
= a_pos
- sh_video
->pts
- audio_delay
;
1194 if (mpctx
->last_av_difference
> 0.5 && drop_frame_cnt
> 50
1195 && !mpctx
->drop_message_shown
) {
1196 mp_tmsg(MSGT_AVSYNC
,MSGL_WARN
,SystemTooSlow
);
1197 mpctx
->drop_message_shown
= true;
1208 if (screen_width
> 0)
1209 width
= screen_width
;
1212 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
1213 /* Windows command line is broken (MinGW's rxvt works, but we
1214 * should not depend on that). */
1217 line
= malloc(width
+ 1); // one additional char for the terminating null
1220 if (mpctx
->sh_audio
) {
1221 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
1223 float len
= demuxer_get_time_length(mpctx
->demuxer
);
1224 saddf(line
, &pos
, width
, "(");
1225 sadd_hhmmssf(line
, &pos
, width
, a_pos
);
1226 saddf(line
, &pos
, width
, ") of %.1f (", len
);
1227 sadd_hhmmssf(line
, &pos
, width
, len
);
1228 saddf(line
, &pos
, width
, ") ");
1234 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
1237 if (mpctx
->sh_audio
&& sh_video
)
1238 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ",
1239 mpctx
->last_av_difference
, mpctx
->total_avsync_change
);
1243 saddf(line
, &pos
, width
, "%3d/%3d ",
1244 (int)sh_video
->num_frames
,
1245 (int)sh_video
->num_frames_decoded
);
1249 if (sh_video
->timer
> 0.5)
1250 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
1251 (int)(100.0*video_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1252 (int)(100.0*vout_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
),
1253 (100.0*audio_time_usage
*opts
->playback_speed
/(double)sh_video
->timer
));
1255 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
1256 } else if (mpctx
->sh_audio
) {
1257 if (mpctx
->delay
> 0.5)
1258 saddf(line
, &pos
, width
, "%4.1f%% ",
1259 100.0*audio_time_usage
/(double)mpctx
->delay
);
1261 saddf(line
, &pos
, width
, "??,?%% ");
1266 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
1268 #ifdef CONFIG_STREAM_CACHE
1270 if (stream_cache_size
> 0)
1271 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
1275 if (opts
->playback_speed
!= 1)
1276 saddf(line
, &pos
, width
, "%4.2fx ", opts
->playback_speed
);
1279 if (erase_to_end_of_line
) {
1281 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s%s\r", line
, erase_to_end_of_line
);
1283 memset(&line
[pos
], ' ', width
- pos
);
1285 mp_msg(MSGT_STATUSLINE
, MSGL_STATUS
, "%s\r", line
);
1291 * \brief build a chain of audio filters that converts the input format
1292 * to the ao's format, taking into account the current playback_speed.
1293 * \param sh_audio describes the requested input format of the chain.
1294 * \param ao_data describes the requested output format of the chain.
1296 int build_afilter_chain(struct MPContext
*mpctx
, sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
1298 struct MPOpts
*opts
= &mpctx
->opts
;
1303 mpctx
->mixer
.afilter
= NULL
;
1306 if(af_control_any_rev(sh_audio
->afilter
,
1307 AF_CONTROL_PLAYBACK_SPEED
| AF_CONTROL_SET
,
1308 &opts
->playback_speed
)) {
1309 new_srate
= sh_audio
->samplerate
;
1311 new_srate
= sh_audio
->samplerate
* opts
->playback_speed
;
1312 if (new_srate
!= ao_data
->samplerate
) {
1313 // limits are taken from libaf/af_resample.c
1314 if (new_srate
< 8000)
1316 if (new_srate
> 192000)
1318 opts
->playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
1321 result
= init_audio_filters(sh_audio
, new_srate
,
1322 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
);
1323 mpctx
->mixer
.afilter
= sh_audio
->afilter
;
1328 typedef struct mp_osd_msg mp_osd_msg_t
;
1330 /// Previous message on the stack.
1334 int id
,level
,started
;
1335 /// Display duration in ms.
1339 /// OSD message stack.
1340 static mp_osd_msg_t
* osd_msg_stack
= NULL
;
1343 * \brief Add a message on the OSD message stack
1345 * If a message with the same id is already present in the stack
1346 * it is pulled on top of the stack, otherwise a new message is created.
1350 void set_osd_msg(int id
, int level
, int time
, const char* fmt
, ...) {
1351 mp_osd_msg_t
*msg
,*last
=NULL
;
1355 // look if the id is already in the stack
1356 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1357 last
= msg
, msg
= msg
->prev
);
1358 // not found: alloc it
1360 msg
= calloc(1,sizeof(mp_osd_msg_t
));
1361 msg
->prev
= osd_msg_stack
;
1362 osd_msg_stack
= msg
;
1363 } else if(last
) { // found, but it's not on top of the stack
1364 last
->prev
= msg
->prev
;
1365 msg
->prev
= osd_msg_stack
;
1366 osd_msg_stack
= msg
;
1370 r
= vsnprintf(msg
->msg
, 128, fmt
, va
);
1372 if(r
>= 128) msg
->msg
[127] = 0;
1381 * \brief Remove a message from the OSD stack
1383 * This function can be used to get rid of a message right away.
1387 void rm_osd_msg(int id
) {
1388 mp_osd_msg_t
*msg
,*last
=NULL
;
1390 // Search for the msg
1391 for(msg
= osd_msg_stack
; msg
&& msg
->id
!= id
;
1392 last
= msg
, msg
= msg
->prev
);
1395 // Detach it from the stack and free it
1397 last
->prev
= msg
->prev
;
1399 osd_msg_stack
= msg
->prev
;
1404 * \brief Remove all messages from the OSD stack
1408 static void clear_osd_msgs(void) {
1409 mp_osd_msg_t
* msg
= osd_msg_stack
, *prev
= NULL
;
1415 osd_msg_stack
= NULL
;
1419 * \brief Get the current message from the OSD stack.
1421 * This function decrements the message timer and destroys the old ones.
1422 * The message that should be displayed is returned (if any).
1426 static mp_osd_msg_t
* get_osd_msg(struct MPContext
*mpctx
)
1428 struct MPOpts
*opts
= &mpctx
->opts
;
1429 mp_osd_msg_t
*msg
,*prev
,*last
= NULL
;
1430 static unsigned last_update
= 0;
1431 unsigned now
= GetTimerMS();
1433 char hidden_dec_done
= 0;
1435 if (mpctx
->osd_visible
) {
1436 // 36000000 means max timed visibility is 1 hour into the future, if
1437 // the difference is greater assume it's wrapped around from below 0
1438 if (mpctx
->osd_visible
- now
> 36000000) {
1439 mpctx
->osd_visible
= 0;
1440 vo_osd_progbar_type
= -1; // disable
1441 vo_osd_changed(OSDTYPE_PROGBAR
);
1442 mpctx
->osd_function
= mpctx
->paused
? OSD_PAUSE
: OSD_PLAY
;
1445 if (mpctx
->osd_show_percentage_until
- now
> 36000000)
1446 mpctx
->osd_show_percentage_until
= 0;
1448 if(!last_update
) last_update
= now
;
1449 diff
= now
>= last_update
? now
- last_update
: 0;
1453 // Look for the first message in the stack with high enough level.
1454 for(msg
= osd_msg_stack
; msg
; last
= msg
, msg
= prev
) {
1456 if (msg
->level
> opts
->osd_level
&& hidden_dec_done
)
1458 // The message has a high enough level or it is the first hidden one
1459 // in both cases we decrement the timer or kill it.
1460 if(!msg
->started
|| msg
->time
> diff
) {
1461 if(msg
->started
) msg
->time
-= diff
;
1462 else msg
->started
= 1;
1464 if (msg
->level
<= opts
->osd_level
)
1466 hidden_dec_done
= 1;
1475 osd_msg_stack
= prev
;
1484 * \brief Display the OSD bar.
1486 * Display the OSD bar or fall back on a simple message.
1490 void set_osd_bar(struct MPContext
*mpctx
, int type
,const char* name
,double min
,double max
,double val
) {
1491 struct MPOpts
*opts
= &mpctx
->opts
;
1492 if (opts
->osd_level
< 1)
1495 if(mpctx
->sh_video
) {
1496 mpctx
->osd_visible
= (GetTimerMS() + 1000) | 1;
1497 vo_osd_progbar_type
= type
;
1498 vo_osd_progbar_value
= 256*(val
-min
)/(max
-min
);
1499 vo_osd_changed(OSDTYPE_PROGBAR
);
1503 set_osd_msg(OSD_MSG_BAR
, 1, opts
->osd_duration
, "%s: %d %%",
1504 name
, ROUND(100*(val
-min
)/(max
-min
)));
1509 * \brief Update the OSD message line.
1511 * This function displays the current message on the vo OSD or on the term.
1512 * If the stack is empty and the OSD level is high enough the timer
1513 * is displayed (only on the vo OSD).
1517 static void update_osd_msg(struct MPContext
*mpctx
)
1519 struct MPOpts
*opts
= &mpctx
->opts
;
1521 struct osd_state
*osd
= mpctx
->osd
;
1522 char osd_text_timer
[128];
1524 if (mpctx
->add_osd_seek_info
) {
1526 if (mpctx
->timeline
&& mpctx
->sh_video
)
1527 percentage
= mpctx
->sh_video
->pts
* 100 /
1528 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1530 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1531 set_osd_bar(mpctx
, 0, "Position", 0, 100, percentage
);
1532 if (mpctx
->sh_video
)
1533 mpctx
->osd_show_percentage_until
= (GetTimerMS() + 1000) | 1;
1534 mpctx
->add_osd_seek_info
= false;
1537 // Look if we have a msg
1538 if((msg
= get_osd_msg(mpctx
))) {
1539 if (strcmp(osd
->osd_text
, msg
->msg
)) {
1540 strncpy(osd
->osd_text
, msg
->msg
, 127);
1541 if(mpctx
->sh_video
) vo_osd_changed(OSDTYPE_OSD
); else
1542 if(term_osd
) mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"%s%s\n",term_osd_esc
,msg
->msg
);
1547 if(mpctx
->sh_video
) {
1548 // fallback on the timer
1549 if (opts
->osd_level
>= 2) {
1551 if (mpctx
->timeline
)
1552 len
= mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1554 len
= demuxer_get_time_length(mpctx
->demuxer
);
1555 int percentage
= -1;
1556 char percentage_text
[10];
1557 int pts
= demuxer_get_current_time(mpctx
->demuxer
);
1559 if (mpctx
->osd_show_percentage_until
)
1560 if (mpctx
->timeline
)
1561 percentage
= mpctx
->sh_video
->pts
* 100 /
1562 mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
1564 percentage
= demuxer_get_percent_pos(mpctx
->demuxer
);
1566 if (percentage
>= 0)
1567 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
1569 percentage_text
[0] = 0;
1571 if (opts
->osd_level
== 3)
1572 snprintf(osd_text_timer
, 63,
1573 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1574 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,pts
%60,
1575 len
/3600,(len
/60)%60,len
%60,percentage_text
);
1577 snprintf(osd_text_timer
, 63, "%c %02d:%02d:%02d%s",
1578 mpctx
->osd_function
,pts
/3600,(pts
/60)%60,
1579 pts
%60,percentage_text
);
1581 osd_text_timer
[0]=0;
1583 if (strcmp(osd
->osd_text
, osd_text_timer
)) {
1584 strncpy(osd
->osd_text
, osd_text_timer
, 63);
1585 vo_osd_changed(OSDTYPE_OSD
);
1590 // Clear the term osd line
1591 if (term_osd
&& osd
->osd_text
[0]) {
1592 osd
->osd_text
[0] = 0;
1593 printf("%s\n",term_osd_esc
);
1601 void reinit_audio_chain(struct MPContext
*mpctx
)
1603 struct MPOpts
*opts
= &mpctx
->opts
;
1604 if(mpctx
->sh_audio
){
1605 current_module
="init_audio_codec";
1606 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1607 if(!init_best_audio_codec(mpctx
->sh_audio
,audio_codec_list
,audio_fm_list
)){
1608 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // failed to init :(
1609 mpctx
->d_audio
->id
= -2;
1612 mpctx
->initialized_flags
|=INITIALIZED_ACODEC
;
1613 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1616 //const ao_info_t *info=audio_out->info;
1617 current_module
="af_preinit";
1618 ao_data
.samplerate
=force_srate
;
1620 ao_data
.format
=audio_output_format
;
1622 // first init to detect best values
1623 if(!init_audio_filters(mpctx
->sh_audio
, // preliminary init
1625 mpctx
->sh_audio
->samplerate
,
1627 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
1628 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Error at audio filter chain pre-init!\n");
1629 exit_player(mpctx
, EXIT_ERROR
);
1632 current_module
="ao2_init";
1633 if(!(mpctx
->audio_out
=init_best_audio_out(opts
->audio_driver_list
,
1637 ao_data
.format
,0))){
1639 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Could not open/initialize audio device -> no sound.\n");
1640 uninit_player(mpctx
, INITIALIZED_ACODEC
); // close codec
1641 mpctx
->sh_audio
=mpctx
->d_audio
->sh
=NULL
; // -> nosound
1642 mpctx
->d_audio
->id
= -2;
1646 mpctx
->initialized_flags
|=INITIALIZED_AO
;
1647 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
1648 mpctx
->audio_out
->info
->short_name
,
1649 ao_data
.samplerate
, ao_data
.channels
,
1650 af_fmt2str_short(ao_data
.format
),
1651 af_fmt2bits(ao_data
.format
)/8 );
1652 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1653 mpctx
->audio_out
->info
->name
, mpctx
->audio_out
->info
->author
);
1654 if(strlen(mpctx
->audio_out
->info
->comment
) > 0)
1655 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", mpctx
->audio_out
->info
->comment
);
1656 // init audio filters:
1658 current_module
="af_init";
1659 if(!build_afilter_chain(mpctx
, mpctx
->sh_audio
, &ao_data
)) {
1660 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Couldn't find matching filter/ao format!\n");
1661 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1662 // uninit_player(mpctx, INITIALIZED_ACODEC|INITIALIZED_AO); // close codec & ao
1663 // sh_audio=mpctx->d_audio->sh=NULL; // -> nosound
1667 mpctx
->mixer
.audio_out
= mpctx
->audio_out
;
1668 mpctx
->mixer
.volstep
= volstep
;
1677 // Return pts value corresponding to the end point of audio written to the
1679 static double written_audio_pts(struct MPContext
*mpctx
)
1681 sh_audio_t
*sh_audio
= mpctx
->sh_audio
;
1682 demux_stream_t
*d_audio
= mpctx
->d_audio
;
1683 double buffered_output
;
1684 // first calculate the end pts of audio that has been output by decoder
1685 double a_pts
= sh_audio
->pts
;
1686 if (a_pts
!= MP_NOPTS_VALUE
)
1687 // Good, decoder supports new way of calculating audio pts.
1688 // sh_audio->pts is the timestamp of the latest input packet with
1689 // known pts that the decoder has decoded. sh_audio->pts_bytes is
1690 // the amount of bytes the decoder has written after that timestamp.
1691 a_pts
+= sh_audio
->pts_bytes
/ (double) sh_audio
->o_bps
;
1693 // Decoder doesn't support new way of calculating pts (or we're
1694 // being called before it has decoded anything with known timestamp).
1695 // Use the old method of audio pts calculation: take the timestamp
1696 // of last packet with known pts the decoder has read data from,
1697 // and add amount of bytes read after the beginning of that packet
1698 // divided by input bps. This will be inaccurate if the input/output
1699 // ratio is not constant for every audio packet or if it is constant
1700 // but not accurately known in sh_audio->i_bps.
1702 a_pts
= d_audio
->pts
;
1703 // ds_tell_pts returns bytes read after last timestamp from
1704 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
1705 // it has read but not decoded
1706 if (sh_audio
->i_bps
)
1707 a_pts
+= (ds_tell_pts(d_audio
) - sh_audio
->a_in_buffer_len
) /
1708 (double)sh_audio
->i_bps
;
1710 // Now a_pts hopefully holds the pts for end of audio from decoder.
1711 // Substract data in buffers between decoder and audio out.
1713 // Decoded but not filtered
1714 a_pts
-= sh_audio
->a_buffer_len
/ (double)sh_audio
->o_bps
;
1716 // Data buffered in audio filters, measured in bytes of "missing" output
1717 buffered_output
= af_calc_delay(sh_audio
->afilter
);
1719 // Data that was ready for ao but was buffered because ao didn't fully
1720 // accept everything to internal buffers yet
1721 buffered_output
+= sh_audio
->a_out_buffer_len
;
1723 // Filters divide audio length by playback_speed, so multiply by it
1724 // to get the length in original units without speedup or slowdown
1725 a_pts
-= buffered_output
* mpctx
->opts
.playback_speed
/ ao_data
.bps
;
1727 return a_pts
+ mpctx
->video_offset
;
1730 // Return pts value corresponding to currently playing audio.
1731 double playing_audio_pts(struct MPContext
*mpctx
)
1733 return written_audio_pts(mpctx
) - mpctx
->opts
.playback_speed
*
1734 mpctx
->audio_out
->get_delay();
1737 static int check_framedrop(struct MPContext
*mpctx
, double frame_time
) {
1738 struct MPOpts
*opts
= &mpctx
->opts
;
1739 // check for frame-drop:
1740 current_module
= "check_framedrop";
1741 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
1742 static int dropped_frames
;
1743 float delay
= opts
->playback_speed
*mpctx
->audio_out
->get_delay();
1744 float d
= delay
-mpctx
->delay
;
1746 // we should avoid dropping too many frames in sequence unless we
1747 // are too late. and we allow 100ms A-V delay here:
1748 if (d
< -dropped_frames
*frame_time
-0.100 && !mpctx
->paused
1749 && !mpctx
->update_video_immediately
) {
1752 return frame_dropping
;
1764 static float timing_sleep(struct MPContext
*mpctx
, float time_frame
)
1768 // -------- RTC -----------
1769 current_module
="sleep_rtc";
1770 while (time_frame
> 0.000) {
1771 unsigned long rtc_ts
;
1772 if (read(rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
1773 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC read error: %s\n", strerror(errno
));
1774 time_frame
-= get_relative_time(mpctx
);
1779 // assume kernel HZ=100 for softsleep, works with larger HZ but with
1780 // unnecessarily high CPU usage
1781 float margin
= softsleep
? 0.011 : 0;
1782 current_module
= "sleep_timer";
1783 while (time_frame
> margin
) {
1784 usec_sleep(1000000 * (time_frame
- margin
));
1785 time_frame
-= get_relative_time(mpctx
);
1788 current_module
= "sleep_soft";
1790 mp_tmsg(MSGT_AVSYNC
, MSGL_WARN
, "Warning! Softsleep underflow!\n");
1791 while (time_frame
> 0)
1792 time_frame
-= get_relative_time(mpctx
); // burn the CPU
1798 #ifdef CONFIG_DVDNAV
1802 /// store decoded video image
1803 static mp_image_t
* mp_dvdnav_copy_mpi(mp_image_t
*to_mpi
,
1804 mp_image_t
*from_mpi
) {
1807 /// Do not store B-frames
1808 if (from_mpi
->pict_type
== FF_B_TYPE
)
1812 to_mpi
->w
== from_mpi
->w
&&
1813 to_mpi
->h
== from_mpi
->h
&&
1814 to_mpi
->imgfmt
== from_mpi
->imgfmt
)
1818 free_mp_image(to_mpi
);
1819 if (from_mpi
->w
== 0 || from_mpi
->h
== 0)
1821 mpi
= alloc_mpi(from_mpi
->w
,from_mpi
->h
,from_mpi
->imgfmt
);
1824 copy_mpi(mpi
,from_mpi
);
1828 static void mp_dvdnav_reset_stream (MPContext
*ctx
) {
1829 struct MPOpts
*opts
= &ctx
->opts
;
1830 if (ctx
->sh_video
) {
1832 ctx
->d_video
->pts
= 0.0f
;
1833 ctx
->sh_video
->pts
= 0.0f
;
1834 ctx
->sh_video
->i_pts
= 0.0f
;
1835 ctx
->sh_video
->last_pts
= 0.0f
;
1836 ctx
->sh_video
->num_buffered_pts
= 0;
1837 ctx
->sh_video
->num_frames
= 0;
1838 ctx
->sh_video
->num_frames_decoded
= 0;
1839 ctx
->sh_video
->timer
= 0.0f
;
1840 ctx
->sh_video
->stream_delay
= 0.0f
;
1841 ctx
->sh_video
->timer
= 0;
1842 ctx
->demuxer
->stream_pts
= MP_NOPTS_VALUE
;
1845 if (ctx
->sh_audio
) {
1846 /// free audio packets and reset
1847 ds_free_packs(ctx
->d_audio
);
1848 audio_delay
-= ctx
->sh_audio
->stream_delay
;
1849 ctx
->delay
=- audio_delay
;
1850 ctx
->audio_out
->reset();
1851 resync_audio_stream(ctx
->sh_audio
);
1854 if (ctx
->d_sub
) opts
->sub_id
= -2;
1858 /// clear all EOF related flags
1859 ctx
->d_video
->eof
= ctx
->d_audio
->eof
= ctx
->stream
->eof
= 0;
1862 /// Restore last decoded DVDNAV (still frame)
1863 static mp_image_t
*mp_dvdnav_restore_smpi(struct MPContext
*mpctx
,
1865 unsigned char **start
,
1866 mp_image_t
*decoded_frame
)
1868 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
1869 return decoded_frame
;
1871 /// a change occured in dvdnav stream
1872 if (mp_dvdnav_cell_has_changed(mpctx
->stream
,0)) {
1873 mp_dvdnav_read_wait(mpctx
->stream
, 1, 1);
1874 mp_dvdnav_context_free(mpctx
);
1875 mp_dvdnav_reset_stream(mpctx
);
1876 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
1877 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
1883 /// Display still frame, if any
1884 if (mpctx
->nav_smpi
&& !mpctx
->nav_buffer
)
1885 decoded_frame
= mpctx
->nav_smpi
;
1887 /// increment video frame : continue playing after still frame
1888 len
= demuxer_get_time_length(mpctx
->demuxer
);
1889 if (mpctx
->sh_video
->pts
>= len
&&
1890 mpctx
->sh_video
->pts
> 0.0 && len
> 0.0) {
1891 mp_dvdnav_skip_still(mpctx
->stream
);
1892 mp_dvdnav_skip_wait(mpctx
->stream
);
1894 mpctx
->sh_video
->pts
+= 1 / mpctx
->sh_video
->fps
;
1896 if (mpctx
->nav_buffer
) {
1897 *start
= mpctx
->nav_start
;
1898 *in_size
= mpctx
->nav_in_size
;
1899 if (mpctx
->nav_start
)
1900 memcpy(*start
,mpctx
->nav_buffer
,mpctx
->nav_in_size
);
1904 return decoded_frame
;
1907 /// Save last decoded DVDNAV (still frame)
1908 static void mp_dvdnav_save_smpi(struct MPContext
*mpctx
, int in_size
,
1909 unsigned char *start
,
1910 mp_image_t
*decoded_frame
)
1912 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
1915 if (mpctx
->nav_buffer
)
1916 free(mpctx
->nav_buffer
);
1918 mpctx
->nav_buffer
= malloc(in_size
);
1919 mpctx
->nav_start
= start
;
1920 mpctx
->nav_in_size
= mpctx
->nav_buffer
? in_size
: -1;
1921 if (mpctx
->nav_buffer
)
1922 memcpy(mpctx
->nav_buffer
,start
,in_size
);
1924 if (decoded_frame
&& mpctx
->nav_smpi
!= decoded_frame
)
1925 mpctx
->nav_smpi
= mp_dvdnav_copy_mpi(mpctx
->nav_smpi
,decoded_frame
);
1927 #endif /* CONFIG_DVDNAV */
1929 /* Modify video timing to match the audio timeline. There are two main
1930 * reasons this is needed. First, video and audio can start from different
1931 * positions at beginning of file or after a seek (MPlayer starts both
1932 * immediately even if they have different pts). Second, the file can have
1933 * audio timestamps that are inconsistent with the duration of the audio
1934 * packets, for example two consecutive timestamp values differing by
1935 * one second but only a packet with enough samples for half a second
1936 * of playback between them.
1938 static void adjust_sync(struct MPContext
*mpctx
, double frame_time
)
1940 struct MPOpts
*opts
= &mpctx
->opts
;
1941 current_module
= "av_sync";
1943 if (!mpctx
->sh_audio
)
1946 double a_pts
= written_audio_pts(mpctx
) - mpctx
->delay
;
1947 double v_pts
= mpctx
->sh_video
->pts
;
1948 double av_delay
= a_pts
- v_pts
;
1949 // Try to sync vo_flip() so it will *finish* at given time
1950 av_delay
+= mpctx
->last_vo_flip_duration
;
1951 av_delay
-= audio_delay
; // This much pts difference is desired
1953 double change
= av_delay
* 0.1;
1954 double max_change
= default_max_pts_correction
>= 0 ?
1955 default_max_pts_correction
: frame_time
* 0.1;
1956 if (change
< -max_change
)
1957 change
= -max_change
;
1958 else if (change
> max_change
)
1959 change
= max_change
;
1960 mpctx
->delay
+= change
;
1961 mpctx
->total_avsync_change
+= change
;
1964 static int fill_audio_out_buffers(struct MPContext
*mpctx
)
1966 struct MPOpts
*opts
= &mpctx
->opts
;
1973 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
1975 current_module
="play_audio";
1979 // all the current uses of ao_data.pts seem to be in aos that handle
1980 // sync completely wrong; there should be no need to use ao_data.pts
1982 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
1983 bytes_to_write
= mpctx
->audio_out
->get_space();
1984 if (mpctx
->sh_video
|| bytes_to_write
>= ao_data
.outburst
)
1987 // handle audio-only case:
1988 // this is where mplayer sleeps during audio-only playback
1989 // to avoid 100% CPU use
1990 sleep_time
= (ao_data
.outburst
- bytes_to_write
) * 1000 / ao_data
.bps
;
1991 if (sleep_time
< 10) sleep_time
= 10; // limit to 100 wakeups per second
1992 usec_sleep(sleep_time
* 1000);
1995 while (bytes_to_write
) {
1996 playsize
= bytes_to_write
;
1997 if (playsize
> MAX_OUTBURST
)
1998 playsize
= MAX_OUTBURST
;
1999 bytes_to_write
-= playsize
;
2001 // Fill buffer if needed:
2002 current_module
="decode_audio";
2004 if (decode_audio(sh_audio
, playsize
) < 0) // EOF or error
2005 if (mpctx
->d_audio
->eof
) {
2007 if (sh_audio
->a_out_buffer_len
== 0)
2011 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2012 if (playsize
> sh_audio
->a_out_buffer_len
) {
2013 playsize
= sh_audio
->a_out_buffer_len
;
2015 playflags
|= AOPLAY_FINAL_CHUNK
;
2021 current_module
="play_audio";
2023 // Is this pts value actually useful for the aos that access it?
2024 // They're obviously badly broken in the way they handle av sync;
2025 // would not having access to this make them more broken?
2026 ao_data
.pts
= ((mpctx
->sh_video
?mpctx
->sh_video
->timer
:0)+mpctx
->delay
)*90000.0;
2027 playsize
= mpctx
->audio_out
->play(sh_audio
->a_out_buffer
, playsize
, playflags
);
2030 sh_audio
->a_out_buffer_len
-= playsize
;
2031 memmove(sh_audio
->a_out_buffer
, &sh_audio
->a_out_buffer
[playsize
],
2032 sh_audio
->a_out_buffer_len
);
2033 mpctx
->delay
+= opts
->playback_speed
*playsize
/(double)ao_data
.bps
;
2035 else if (audio_eof
&& mpctx
->audio_out
->get_delay() < .04) {
2036 // Sanity check to avoid hanging in case current ao doesn't output
2037 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
2038 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Audio output truncated at end.\n");
2039 sh_audio
->a_out_buffer_len
= 0;
2045 static int sleep_until_update(struct MPContext
*mpctx
, float *time_frame
,
2046 float *aq_sleep_time
)
2048 struct MPOpts
*opts
= &mpctx
->opts
;
2049 int frame_time_remaining
= 0;
2050 current_module
="calc_sleep_time";
2052 *time_frame
-= get_relative_time(mpctx
); // reset timer
2054 if (mpctx
->sh_audio
&& !mpctx
->d_audio
->eof
) {
2055 float delay
= mpctx
->audio_out
->get_delay();
2056 mp_dbg(MSGT_AVSYNC
, MSGL_DBG2
, "delay=%f\n", delay
);
2060 * Adjust this raw delay value by calculating the expected
2061 * delay for this frame and generating a new value which is
2062 * weighted between the two. The higher autosync is, the
2063 * closer to the delay value gets to that which "-nosound"
2064 * would have used, and the longer it will take for A/V
2065 * sync to settle at the right value (but it eventually will.)
2066 * This settling time is very short for values below 100.
2068 float predicted
= mpctx
->delay
/ opts
->playback_speed
+ *time_frame
;
2069 float difference
= delay
- predicted
;
2070 delay
= predicted
+ difference
/ (float)autosync
;
2073 *time_frame
= delay
- mpctx
->delay
/ opts
->playback_speed
;
2075 // delay = amount of audio buffered in soundcard/driver
2076 if (delay
> 0.25) delay
=0.25; else
2077 if (delay
< 0.10) delay
=0.10;
2078 if (*time_frame
> delay
*0.6) {
2079 // sleep time too big - may cause audio drops (buffer underrun)
2080 frame_time_remaining
= 1;
2081 *time_frame
= delay
*0.5;
2084 // If we're lagging more than 200 ms behind the right playback rate,
2085 // don't try to "catch up".
2086 // If benchmark is set always output frames as fast as possible
2087 // without sleeping.
2088 if (*time_frame
< -0.2 || benchmark
)
2092 *aq_sleep_time
+= *time_frame
;
2095 //============================== SLEEP: ===================================
2097 // flag 256 means: libvo driver does its timing (dvb card)
2098 if (*time_frame
> 0.001 && !(mpctx
->sh_video
->output_flags
&256))
2099 *time_frame
= timing_sleep(mpctx
, *time_frame
);
2100 return frame_time_remaining
;
2103 int reinit_video_chain(struct MPContext
*mpctx
)
2105 struct MPOpts
*opts
= &mpctx
->opts
;
2106 sh_video_t
* const sh_video
= mpctx
->sh_video
;
2108 //================== Init VIDEO (codec & libvo) ==========================
2109 if (!opts
->fixed_vo
|| !(mpctx
->initialized_flags
& INITIALIZED_VO
)) {
2110 current_module
="preinit_libvo";
2112 //shouldn't we set dvideo->id=-2 when we fail?
2113 //if((mpctx->video_out->preinit(vo_subdevice))!=0){
2114 if(!(mpctx
->video_out
=init_best_video_out(opts
, mpctx
->x11_state
, mpctx
->key_fifo
, mpctx
->input
))){
2115 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Error opening/initializing the selected video_out (-vo) device.\n");
2118 mpctx
->initialized_flags
|=INITIALIZED_VO
;
2121 if(stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_ASPECT_RATIO
, &ar
) != STREAM_UNSUPPORTED
)
2122 mpctx
->sh_video
->stream_aspect
= ar
;
2123 current_module
="init_video_filters";
2125 char* vf_arg
[] = { "_oldargs_", (char*)mpctx
->video_out
, NULL
};
2126 sh_video
->vfilter
= vf_open_filter(opts
, NULL
,"vo",vf_arg
);
2130 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
2131 vf_menu
= vf_open_plugin(opts
,libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
2133 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Can't open libmenu video filter with root menu %s.\n",menu_root
);
2138 sh_video
->vfilter
= vf_menu
;
2145 if (opts
->vf_settings
)
2146 for (i
= 0; opts
->vf_settings
[i
].name
; ++i
)
2147 if (strcmp(opts
->vf_settings
[i
].name
, "ass") == 0) {
2152 extern vf_info_t vf_info_ass
;
2153 const vf_info_t
* libass_vfs
[] = {&vf_info_ass
, NULL
};
2154 char* vf_arg
[] = {"auto", "1", NULL
};
2155 vf_instance_t
* vf_ass
= vf_open_plugin(opts
, libass_vfs
,sh_video
->vfilter
,"ass",vf_arg
);
2157 sh_video
->vfilter
= vf_ass
;
2159 mp_msg(MSGT_CPLAYER
,MSGL_ERR
, "ASS: cannot add video filter\n");
2164 sh_video
->vfilter
= append_filters(sh_video
->vfilter
, opts
->vf_settings
);
2168 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_INIT_EOSD
, ass_library
);
2171 current_module
="init_video_codec";
2173 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2174 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
2175 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2177 if(!sh_video
->initialized
){
2178 if(!opts
->fixed_vo
) uninit_player(mpctx
, INITIALIZED_VO
);
2182 mpctx
->initialized_flags
|=INITIALIZED_VCODEC
;
2184 if (sh_video
->codec
)
2185 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODEC=%s\n", sh_video
->codec
->name
);
2187 sh_video
->last_pts
= MP_NOPTS_VALUE
;
2188 sh_video
->num_buffered_pts
= 0;
2189 sh_video
->next_frame_time
= 0;
2192 // Auto quality option enabled
2193 output_quality
=get_video_quality_max(sh_video
);
2194 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
2195 else output_quality
=auto_quality
;
2196 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
2197 set_video_quality(sh_video
,output_quality
);
2200 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2202 current_module
="init_vo";
2207 mpctx
->sh_video
= mpctx
->d_video
->sh
= NULL
;
2211 static double update_video_nocorrect_pts(struct MPContext
*mpctx
,
2214 struct sh_video
*sh_video
= mpctx
->sh_video
;
2216 double frame_time
= 0;
2218 current_module
= "filter_video";
2219 // In nocorrect-pts mode there is no way to properly time these frames
2220 if (vf_output_queued_frame(sh_video
->vfilter
))
2222 unsigned char *packet
= NULL
;
2223 frame_time
= sh_video
->next_frame_time
;
2224 if (mpctx
->update_video_immediately
)
2226 int in_size
= video_read_frame(sh_video
, &sh_video
->next_frame_time
,
2227 &packet
, force_fps
);
2229 #ifdef CONFIG_DVDNAV
2230 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
2231 if (mp_dvdnav_is_eof(mpctx
->stream
))
2234 mpctx
->d_video
->eof
= 0;
2236 mpctx
->d_audio
->eof
= 0;
2237 mpctx
->stream
->eof
= 0;
2242 if (in_size
> max_framesize
)
2243 max_framesize
= in_size
;
2244 sh_video
->timer
+= frame_time
;
2245 if (mpctx
->sh_audio
)
2246 mpctx
->delay
-= frame_time
;
2247 // video_read_frame can change fps (e.g. for ASF video)
2248 vo_fps
= sh_video
->fps
;
2249 int framedrop_type
= check_framedrop(mpctx
, frame_time
);
2250 current_module
= "decode video";
2252 void *decoded_frame
;
2253 #ifdef CONFIG_DVDNAV
2254 decoded_frame
= mp_dvdnav_restore_smpi(mpctx
, &in_size
, &packet
, NULL
);
2255 if (in_size
>= 0 && !decoded_frame
)
2257 decoded_frame
= decode_video(sh_video
, packet
, in_size
, framedrop_type
,
2259 #ifdef CONFIG_DVDNAV
2260 // Save last still frame for future display
2261 mp_dvdnav_save_smpi(mpctx
, in_size
, packet
, decoded_frame
);
2263 if (decoded_frame
) {
2264 // These updates are done here for vf_expand OSD/subtitles
2265 update_subtitles(sh_video
, mpctx
->d_sub
, mpctx
->video_offset
, 0);
2266 update_teletext(sh_video
, mpctx
->demuxer
, 0);
2267 update_osd_msg(mpctx
);
2268 current_module
= "filter video";
2269 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2277 static double update_video(struct MPContext
*mpctx
, int *blit_frame
)
2279 struct sh_video
*sh_video
= mpctx
->sh_video
;
2281 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_SET_OSD_OBJ
,
2282 mpctx
->osd
); // hack for vf_expand
2283 if (!mpctx
->opts
.correct_pts
)
2284 return update_video_nocorrect_pts(mpctx
, blit_frame
);
2289 current_module
= "filter_video";
2290 // XXX Time used in this call is not counted in any performance
2291 // timer now, OSD time is not updated correctly for filter-added frames
2292 if (vf_output_queued_frame(sh_video
->vfilter
))
2294 unsigned char *packet
= NULL
;
2295 bool hit_eof
= false;
2296 int in_size
= ds_get_packet_pts(mpctx
->d_video
, &packet
, &pts
);
2297 if (pts
!= MP_NOPTS_VALUE
)
2298 pts
+= mpctx
->video_offset
;
2300 // try to extract last frames in case of decoder lag
2305 if (in_size
> max_framesize
)
2306 max_framesize
= in_size
;
2307 current_module
= "decode video";
2308 int framedrop_type
= check_framedrop(mpctx
, sh_video
->frametime
);
2309 void *decoded_frame
= decode_video(sh_video
, packet
, in_size
,
2310 framedrop_type
, pts
);
2311 if (decoded_frame
) {
2312 // These updates are done here for vf_expand OSD/subtitles
2313 update_subtitles(sh_video
, mpctx
->d_sub
, mpctx
->video_offset
, 0);
2314 update_teletext(sh_video
, mpctx
->demuxer
, 0);
2315 update_osd_msg(mpctx
);
2316 current_module
= "filter video";
2317 if (filter_video(sh_video
, decoded_frame
, sh_video
->pts
))
2323 sh_video
->vfilter
->control(sh_video
->vfilter
, VFCTRL_GET_PTS
, &pts
);
2324 if (pts
== MP_NOPTS_VALUE
) {
2325 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Video pts after filters MISSING\n");
2326 // Try to use decoder pts from before filters
2327 pts
= sh_video
->pts
;
2328 if (pts
== MP_NOPTS_VALUE
)
2329 pts
= sh_video
->last_pts
;
2331 sh_video
->pts
= pts
;
2332 if (sh_video
->last_pts
== MP_NOPTS_VALUE
)
2333 sh_video
->last_pts
= sh_video
->pts
;
2334 else if (sh_video
->last_pts
> sh_video
->pts
) {
2335 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Decreasing video pts: %f < %f\n",
2336 sh_video
->pts
, sh_video
->last_pts
);
2337 /* If the difference in pts is small treat it as jitter around the
2338 * right value (possibly caused by incorrect timestamp ordering) and
2339 * just show this frame immediately after the last one.
2340 * Treat bigger differences as timestamp resets and start counting
2341 * timing of later frames from the position of this one. */
2342 if (sh_video
->last_pts
- sh_video
->pts
> 0.5)
2343 sh_video
->last_pts
= sh_video
->pts
;
2345 sh_video
->pts
= sh_video
->last_pts
;
2347 double frame_time
= sh_video
->pts
- sh_video
->last_pts
;
2348 sh_video
->last_pts
= sh_video
->pts
;
2349 sh_video
->timer
+= frame_time
;
2350 if (mpctx
->sh_audio
)
2351 mpctx
->delay
-= frame_time
;
2356 void pause_player(struct MPContext
*mpctx
)
2361 mpctx
->step_frames
= 0;
2362 mpctx
->time_frame
-= get_relative_time(mpctx
);
2364 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2365 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2367 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2368 mpctx
->audio_out
->pause(); // pause audio, keep data if possible
2371 void unpause_player(struct MPContext
*mpctx
)
2377 if (mpctx
->audio_out
&& mpctx
->sh_audio
)
2378 mpctx
->audio_out
->resume(); // resume audio
2379 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
2380 && !mpctx
->step_frames
)
2381 vo_control(mpctx
->video_out
, VOCTRL_RESUME
, NULL
); // resume video
2382 (void)get_relative_time(mpctx
); // ignore time that passed during pause
2385 void add_step_frame(struct MPContext
*mpctx
)
2387 mpctx
->step_frames
++;
2388 if (mpctx
->video_out
&& mpctx
->sh_video
&& mpctx
->video_out
->config_ok
)
2389 vo_control(mpctx
->video_out
, VOCTRL_PAUSE
, NULL
);
2390 unpause_player(mpctx
);
2393 static void pause_loop(struct MPContext
*mpctx
)
2397 // Small hack to display the pause message on the OSD line.
2398 // The pause string is: "\n == PAUSE == \r" so we need to
2399 // take the first and the last char out
2400 if (term_osd
&& !mpctx
->sh_video
) {
2401 char msg
[128] = _("\n ===== PAUSE =====\r");
2402 int mlen
= strlen(msg
);
2404 set_osd_msg(OSD_MSG_PAUSE
, 1, 0, "%s", msg
+1);
2405 update_osd_msg(mpctx
);
2407 mp_tmsg(MSGT_CPLAYER
,MSGL_STATUS
,"\n ===== PAUSE =====\r");
2408 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_PAUSED\n");
2411 while ( (cmd
= mp_input_get_cmd(mpctx
->input
, 20, 1, 1)) == NULL
2412 || cmd
->id
== MP_CMD_SET_MOUSE_POS
|| cmd
->pausing
== 4) {
2414 cmd
= mp_input_get_cmd(mpctx
->input
, 0,1,0);
2415 run_command(mpctx
, cmd
);
2419 if (mpctx
->sh_video
&& mpctx
->video_out
)
2420 vo_check_events(mpctx
->video_out
);
2423 vf_menu_pause_update(vf_menu
);
2426 update_osd_msg(mpctx
);
2427 int hack
= vo_osd_changed(0);
2428 vo_osd_changed(hack
);
2435 // Find the right mute status and record position for new file position
2436 static void edl_seek_reset(MPContext
*mpctx
)
2438 mpctx
->edl_muted
= 0;
2439 next_edl_record
= edl_records
;
2441 while (next_edl_record
) {
2442 if (next_edl_record
->start_sec
>= mpctx
->sh_video
->pts
)
2445 if (next_edl_record
->action
== EDL_MUTE
)
2446 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2447 next_edl_record
= next_edl_record
->next
;
2449 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2450 mixer_mute(&mpctx
->mixer
);
2454 // Execute EDL command for the current position if one exists
2455 static void edl_update(MPContext
*mpctx
)
2457 if (!next_edl_record
)
2460 if (!mpctx
->sh_video
) {
2461 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Cannot use EDL without video, disabling.\n");
2462 free_edl(edl_records
);
2463 next_edl_record
= NULL
;
2468 if (mpctx
->sh_video
->pts
>= next_edl_record
->start_sec
) {
2469 if (next_edl_record
->action
== EDL_SKIP
) {
2470 mpctx
->osd_function
= OSD_FFW
;
2471 mpctx
->abs_seek_pos
= 0;
2472 mpctx
->rel_seek_secs
= next_edl_record
->length_sec
;
2473 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop "
2474 "[%f], length [%f]\n", next_edl_record
->start_sec
,
2475 next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2477 else if (next_edl_record
->action
== EDL_MUTE
) {
2478 mpctx
->edl_muted
= !mpctx
->edl_muted
;
2479 if ((mpctx
->user_muted
| mpctx
->edl_muted
) != mpctx
->mixer
.muted
)
2480 mixer_mute(&mpctx
->mixer
);
2481 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n",
2482 next_edl_record
->start_sec
);
2484 next_edl_record
= next_edl_record
->next
;
2488 static void reinit_decoders(struct MPContext
*mpctx
)
2490 reinit_video_chain(mpctx
);
2491 reinit_audio_chain(mpctx
);
2492 mp_property_do("sub", M_PROPERTY_SET
, &mpctx
->global_sub_pos
, mpctx
);
2495 static bool timeline_set_part(struct MPContext
*mpctx
, int i
)
2497 struct timeline_part
*p
= mpctx
->timeline
+ mpctx
->timeline_part
;
2498 struct timeline_part
*n
= mpctx
->timeline
+ i
;
2499 mpctx
->timeline_part
= i
;
2500 mpctx
->video_offset
= n
->start
- n
->source_start
;
2501 if (n
->source
== p
->source
)
2503 uninit_player(mpctx
, INITIALIZED_VCODEC
| (mpctx
->opts
.fixed_vo
&& mpctx
->opts
.video_id
!= -2 ? 0 : INITIALIZED_VO
) | INITIALIZED_AO
| INITIALIZED_ACODEC
);
2504 mpctx
->demuxer
= n
->source
->demuxer
;
2505 mpctx
->d_video
= mpctx
->demuxer
->video
;
2506 mpctx
->d_audio
= mpctx
->demuxer
->audio
;
2507 mpctx
->d_sub
= mpctx
->demuxer
->sub
;
2508 mpctx
->sh_video
= mpctx
->d_video
->sh
;
2509 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
2513 // Given pts, switch playback to the corresponding part.
2514 // Return offset within that part.
2515 static double timeline_set_from_time(struct MPContext
*mpctx
, double pts
,
2520 for (int i
= 0; i
< mpctx
->num_timeline_parts
; i
++) {
2521 struct timeline_part
*p
= mpctx
->timeline
+ i
;
2522 if (pts
< (p
+1)->start
) {
2523 *need_reset
= timeline_set_part(mpctx
, i
);
2524 return pts
- p
->start
+ p
->source_start
;
2531 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute
2532 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length
2533 // return -1 if seek failed (non-seekable stream?), 0 otherwise
2534 static int seek(MPContext
*mpctx
, double amount
, int style
)
2536 current_module
= "seek";
2537 if (mpctx
->stop_play
== AT_END_OF_FILE
)
2538 mpctx
->stop_play
= KEEP_PLAYING
;
2539 if (mpctx
->timeline
&& style
& SEEK_FACTOR
) {
2540 amount
*= mpctx
->timeline
[mpctx
->num_timeline_parts
].start
;
2541 style
&= ~SEEK_FACTOR
;
2543 if ((mpctx
->demuxer
->accurate_seek
|| mpctx
->timeline
) && mpctx
->sh_video
2544 && !(style
& (SEEK_ABSOLUTE
| SEEK_FACTOR
))) {
2545 style
|= SEEK_ABSOLUTE
;
2547 style
|= SEEK_FORWARD
;
2549 style
|= SEEK_BACKWARD
;
2550 amount
+= mpctx
->sh_video
->pts
;
2553 /* At least the liba52 decoder wants to read from the input stream
2554 * during initialization, so reinit must be done after the demux_seek()
2555 * call that clears possible stream EOF. */
2556 bool need_reset
= false;
2557 if (mpctx
->timeline
) {
2558 amount
= timeline_set_from_time(mpctx
, amount
, &need_reset
);
2560 mpctx
->stop_play
= AT_END_OF_FILE
;
2561 // Clear audio from current position
2562 if (mpctx
->sh_audio
) {
2563 mpctx
->audio_out
->reset();
2564 mpctx
->sh_audio
->a_buffer_len
= 0;
2565 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2570 int seekresult
= demux_seek(mpctx
->demuxer
, amount
, audio_delay
, style
);
2572 reinit_decoders(mpctx
);
2573 if (seekresult
== 0)
2576 if (mpctx
->sh_video
) {
2577 current_module
= "seek_video_reset";
2578 resync_video_stream(mpctx
->sh_video
);
2579 if (mpctx
->video_out
->config_ok
)
2580 vo_control(mpctx
->video_out
, VOCTRL_RESET
, NULL
);
2581 mpctx
->sh_video
->num_buffered_pts
= 0;
2582 mpctx
->sh_video
->last_pts
= MP_NOPTS_VALUE
;
2583 mpctx
->num_buffered_frames
= 0;
2585 mpctx
->time_frame
= 0;
2586 mpctx
->update_video_immediately
= true;
2587 // Not all demuxers set d_video->pts during seek, so this value
2588 // (which is used by at least vobsub and edl code below) may
2589 // be completely wrong (probably 0).
2590 mpctx
->sh_video
->pts
= mpctx
->d_video
->pts
+ mpctx
->video_offset
;
2591 update_subtitles(mpctx
->sh_video
, mpctx
->d_sub
, mpctx
->video_offset
, 1);
2592 update_teletext(mpctx
->sh_video
, mpctx
->demuxer
, 1);
2595 if (mpctx
->sh_audio
) {
2596 current_module
= "seek_audio_reset";
2597 mpctx
->audio_out
->reset(); // stop audio, throwing away buffered data
2598 mpctx
->sh_audio
->a_buffer_len
= 0;
2599 mpctx
->sh_audio
->a_out_buffer_len
= 0;
2602 if (vo_vobsub
&& mpctx
->sh_video
) {
2603 current_module
= "seek_vobsub_reset";
2604 vobsub_seek(vo_vobsub
, mpctx
->sh_video
->pts
);
2607 edl_seek_reset(mpctx
);
2609 mpctx
->total_avsync_change
= 0;
2610 audio_time_usage
= 0; video_time_usage
= 0; vout_time_usage
= 0;
2613 current_module
= NULL
;
2617 int get_current_chapter(struct MPContext
*mpctx
)
2619 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2620 return demuxer_get_current_chapter(mpctx
->demuxer
);
2623 double current_pts
= mpctx
->sh_video
->pts
;
2624 for (i
= 1; i
< mpctx
->num_chapters
; i
++)
2625 if (current_pts
< mpctx
->chapters
[i
].start
)
2630 // currently returns a string allocated with malloc, not talloc
2631 char *chapter_display_name(struct MPContext
*mpctx
, int chapter
)
2633 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2634 return demuxer_chapter_display_name(mpctx
->demuxer
, chapter
);
2635 return strdup(mpctx
->chapters
[chapter
].name
);
2638 int seek_chapter(struct MPContext
*mpctx
, int chapter
, double *seek_pts
,
2639 char **chapter_name
)
2641 if (!mpctx
->chapters
|| !mpctx
->sh_video
)
2642 return demuxer_seek_chapter(mpctx
->demuxer
, chapter
, seek_pts
,
2644 if (chapter
>= mpctx
->num_chapters
)
2648 *seek_pts
= mpctx
->chapters
[chapter
].start
;
2650 *chapter_name
= talloc_strdup(NULL
, mpctx
->chapters
[chapter
].name
);
2654 static int find_ordered_chapter_sources(struct MPContext
*mpctx
,
2655 struct content_source
*sources
,
2657 unsigned char uid_map
[][16])
2659 int num_filenames
= 0;
2660 char **filenames
= NULL
;
2661 if (num_sources
> 1) {
2662 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "This file references data from "
2663 "other sources.\n");
2664 if (mpctx
->stream
->type
!= STREAMTYPE_FILE
) {
2665 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Playback source is not a "
2666 "normal disk file. Will not search for related files.\n");
2668 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Will scan other files in the "
2669 "same directory to find referenced sources.\n");
2670 filenames
= find_files(mpctx
->demuxer
->filename
, ".mkv",
2675 int num_left
= num_sources
- 1;
2676 for (int i
= 0; i
< num_filenames
&& num_left
> 0; i
++) {
2677 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Checking file %s\n",
2678 filename_recode(filenames
[i
]));
2680 struct stream
*s
= open_stream(filenames
[i
], &mpctx
->opts
, &format
);
2683 struct demuxer
*d
= demux_open(&mpctx
->opts
, s
, DEMUXER_TYPE_MATROSKA
,
2684 mpctx
->opts
.audio_id
,
2685 mpctx
->opts
.video_id
,
2686 mpctx
->opts
.sub_id
, filenames
[i
]);
2691 if (d
->file_format
== DEMUXER_TYPE_MATROSKA
) {
2692 for (int i
= 1; i
< num_sources
; i
++) {
2693 if (sources
[i
].demuxer
)
2695 if (!memcmp(uid_map
[i
], d
->matroska_data
.segment_uid
, 16)) {
2696 mp_msg(MSGT_CPLAYER
, MSGL_INFO
,"Match for source %d: %s\n",
2697 i
, filename_recode(d
->filename
));
2698 sources
[i
].stream
= s
;
2699 sources
[i
].demuxer
= d
;
2711 talloc_free(filenames
);
2713 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Failed to find ordered chapter part!\n"
2714 "There will be parts MISSING from the video!\n");
2715 for (int i
= 1, j
= 1; i
< num_sources
; i
++)
2716 if (sources
[i
].demuxer
) {
2717 sources
[j
] = sources
[i
];
2718 memcpy(uid_map
[j
], uid_map
[i
], 16);
2722 return num_sources
- num_left
;
2725 static void build_ordered_chapter_timeline(struct MPContext
*mpctx
)
2727 if (!mpctx
->opts
.ordered_chapters
) {
2728 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, but "
2729 "you have disabled support for them. Ignoring.\n");
2733 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "File uses ordered chapters, will build "
2734 "edit timeline.\n");
2736 struct demuxer
*demuxer
= mpctx
->demuxer
;
2737 struct matroska_data
*m
= &demuxer
->matroska_data
;
2739 struct content_source
*sources
= talloc_array_ptrtype(NULL
, sources
,
2740 m
->num_ordered_chapters
);
2741 sources
[0].stream
= mpctx
->stream
;
2742 sources
[0].demuxer
= mpctx
->demuxer
;
2743 unsigned char uid_map
[m
->num_ordered_chapters
][16];
2744 int num_sources
= 1;
2745 memcpy(uid_map
[0], m
->segment_uid
, 16);
2747 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
2748 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
2749 if (!c
->has_segment_uid
)
2750 memcpy(c
->segment_uid
, m
->segment_uid
, 16);
2752 for (int j
= 0; j
< num_sources
; j
++)
2753 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
2755 memcpy(uid_map
[num_sources
], c
->segment_uid
, 16);
2756 sources
[num_sources
] = (struct content_source
){};
2762 num_sources
= find_ordered_chapter_sources(mpctx
, sources
, num_sources
,
2766 struct timeline_part
*timeline
= talloc_array_ptrtype(NULL
, timeline
,
2767 m
->num_ordered_chapters
+ 1);
2768 struct chapter
*chapters
= talloc_array_ptrtype(NULL
, chapters
,
2769 m
->num_ordered_chapters
);
2770 uint64_t starttime
= 0;
2771 uint64_t missing_time
= 0;
2773 int num_chapters
= 0;
2774 uint64_t prev_part_offset
;
2775 for (int i
= 0; i
< m
->num_ordered_chapters
; i
++) {
2776 struct matroska_chapter
*c
= m
->ordered_chapters
+ i
;
2779 for (j
= 0; j
< num_sources
; j
++) {
2780 if (!memcmp(c
->segment_uid
, uid_map
[j
], 16))
2783 missing_time
+= c
->end
- c
->start
;
2786 chapters
[num_chapters
].start
= starttime
/ 1000.;
2787 chapters
[num_chapters
].name
= talloc_strdup(chapters
, c
->name
);
2788 /* Only add a separate part if the time or file actually changes.
2789 * Matroska files have chapter divisions that are redundant from
2790 * timeline point of view because the same chapter structure is used
2791 * both to specify the timeline and for normal chapter information.
2792 * Removing a missing inserted external chapter can also cause this. */
2793 if (part_count
== 0 || c
->start
!= starttime
+ prev_part_offset
2794 || sources
+ j
!= timeline
[part_count
- 1].source
) {
2795 timeline
[part_count
].source
= sources
+ j
;
2796 timeline
[part_count
].start
= chapters
[num_chapters
].start
;
2797 timeline
[part_count
].source_start
= c
->start
/ 1000.;
2798 prev_part_offset
= c
->start
- starttime
;
2801 starttime
+= c
->end
- c
->start
;
2804 timeline
[part_count
].start
= starttime
/ 1000.;
2807 // None of the parts come from the file itself???
2808 talloc_free(sources
);
2809 talloc_free(timeline
);
2810 talloc_free(chapters
);
2814 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline contains %d parts from %d "
2815 "sources. Total length %.3f seconds.\n", part_count
, num_sources
,
2816 timeline
[part_count
].start
);
2818 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "There are %.3f seconds missing "
2819 "from the timeline!\n", missing_time
/ 1000.);
2820 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Source files:\n");
2821 for (int i
= 0; i
< num_sources
; i
++)
2822 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%d: %s\n", i
,
2823 filename_recode(sources
[i
].demuxer
->filename
));
2824 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Timeline parts: (number, start, "
2825 "source_start, source):\n");
2826 for (int i
= 0; i
< part_count
; i
++) {
2827 struct timeline_part
*p
= timeline
+ i
;
2828 mp_msg(MSGT_CPLAYER
, MSGL_V
, "%3d %9.3f %9.3f %3td\n", i
, p
->start
,
2829 p
->source_start
, p
->source
- sources
);
2831 mp_msg(MSGT_CPLAYER
, MSGL_V
, "END %9.3f\n", timeline
[part_count
].start
);
2832 mpctx
->sources
= sources
;
2833 mpctx
->num_sources
= num_sources
;
2834 mpctx
->timeline
= timeline
;
2835 mpctx
->num_timeline_parts
= part_count
;
2836 mpctx
->num_chapters
= num_chapters
;
2837 mpctx
->chapters
= chapters
;
2839 mpctx
->timeline_part
= 0;
2840 mpctx
->video_offset
= timeline
[0].source_start
;
2841 mpctx
->demuxer
= timeline
[0].source
->demuxer
;
2845 static int read_keys(void *ctx
, int fd
)
2848 return mplayer_get_key(ctx
, 0);
2852 #ifdef PTW32_STATIC_LIB
2853 static void detach_ptw32(void)
2855 pthread_win32_thread_detach_np();
2856 pthread_win32_process_detach_np();
2860 /* This preprocessor directive is a hack to generate a mplayer-nomain.o object
2861 * file for some tools to link against. */
2862 #ifndef DISABLE_MAIN
2863 int main(int argc
,char* argv
[]){
2870 /* Flag indicating whether MPlayer should exit without playing anything. */
2873 //float a_frame=0; // Audio
2877 struct MPContext
*mpctx
= &(struct MPContext
){
2878 .osd_function
= OSD_PLAY
,
2879 .begin_skip
= MP_NOPTS_VALUE
,
2880 .play_tree_step
= 1,
2881 .global_sub_pos
= -1,
2882 .set_of_sub_pos
= -1,
2883 .file_format
= DEMUXER_TYPE_UNKNOWN
,
2887 #ifdef PTW32_STATIC_LIB
2888 pthread_win32_process_attach_np();
2889 pthread_win32_thread_attach_np();
2890 atexit(detach_ptw32
);
2894 srand(GetTimerMS());
2899 mpctx
->x11_state
= vo_x11_init_state();
2901 struct MPOpts
*opts
= &mpctx
->opts
;
2902 set_default_mplayer_options(opts
);
2903 // Create the config context and register the options
2904 mpctx
->mconfig
= m_config_new(opts
, cfg_include
);
2905 m_config_register_options(mpctx
->mconfig
,mplayer_opts
);
2906 mp_input_register_options(mpctx
->mconfig
);
2908 // Preparse the command line
2909 m_config_preparse_command_line(mpctx
->mconfig
,argc
,argv
);
2911 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
2916 stream_tv_defaults
.immediate
= 1;
2919 parse_cfgfiles(mpctx
, mpctx
->mconfig
);
2921 mpctx
->playtree
= m_config_parse_mp_command_line(mpctx
->mconfig
, argc
, argv
);
2922 if(mpctx
->playtree
== NULL
)
2925 mpctx
->playtree
= play_tree_cleanup(mpctx
->playtree
);
2926 if(mpctx
->playtree
) {
2927 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
,mpctx
->mconfig
);
2928 if(mpctx
->playtree_iter
) {
2929 if(play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
2930 play_tree_iter_free(mpctx
->playtree_iter
);
2931 mpctx
->playtree_iter
= NULL
;
2933 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
,1);
2937 mpctx
->key_fifo
= mp_fifo_create(opts
);
2939 print_version("MPlayer");
2941 #if defined(__MINGW32__) || defined(__CYGWIN__)
2942 // stop Windows from showing all kinds of annoying error dialogs
2943 SetErrorMode(0x8003);
2944 // request 1ms timer resolution
2948 #ifdef CONFIG_PRIORITY
2952 if(opts
->video_driver_list
&& strcmp(opts
->video_driver_list
[0],"help")==0){
2957 if(opts
->audio_driver_list
&& strcmp(opts
->audio_driver_list
[0],"help")==0){
2962 /* Check codecs.conf. */
2963 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
2964 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
2965 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
2966 if(!parse_codec_cfg(NULL
)){
2967 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
2969 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"Using built-in default codecs.conf.\n");
2972 free( mem_ptr
); // release the buffer created by get_path()
2976 if(video_codec_list
){
2978 video_codec
=video_codec_list
[0];
2979 for(i
=0;video_codec_list
[i
];i
++)
2980 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
2983 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
2984 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available audio codecs:\n");
2985 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
2987 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2990 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
2991 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Available video codecs:\n");
2992 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
2994 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
2997 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
2999 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3002 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
3004 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3007 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
3013 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
3015 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
3019 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
3020 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
3021 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
3023 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3026 if(list_properties
) {
3027 property_print_help();
3032 exit_player(mpctx
, EXIT_NONE
);
3034 if(!mpctx
->filename
&& !player_idle_mode
){
3035 // no file/vcd/dvd -> show HELP:
3036 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
3037 exit_player_with_rc(mpctx
, EXIT_NONE
, 0);
3040 /* Display what configure line was used */
3041 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Configuration: " CONFIGURATION
"\n");
3043 // Many users forget to include command line in bugreports...
3044 if( mp_msg_test(MSGT_CPLAYER
,MSGL_V
) ){
3045 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "CommandLine:");
3046 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
3047 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
3050 //------ load global data first ------
3052 mpctx
->osd
= osd_create();
3055 #ifdef CONFIG_FREETYPE
3058 #ifdef CONFIG_FONTCONFIG
3059 if(font_fontconfig
<= 0)
3062 #ifdef CONFIG_BITMAP_FONT
3064 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
3065 if(!vo_font
) mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load bitmap font: %s\n",
3066 filename_recode(font_name
));
3069 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
3070 free(mem_ptr
); // release the buffer created by get_path()
3072 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
3075 mpctx
->osd
->sub_font
= read_font_desc(sub_font_name
, font_factor
, verbose
>1);
3077 mpctx
->osd
->sub_font
= vo_font
;
3079 #ifdef CONFIG_FONTCONFIG
3084 ass_library
= ass_init();
3090 // seteuid(0); /* Can't hurt to try to get root here */
3091 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
3092 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Failed to open %s: %s (it should be readable by the user.)\n",
3093 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
3095 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
3097 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
3098 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp
, strerror(errno
));
3099 mp_tmsg(MSGT_CPLAYER
, MSGL_HINT
, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp
);
3102 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
3103 /* variable only by the root */
3104 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno
));
3108 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Using Linux hardware RTC timing (%ldHz).\n", irqp
);
3112 #endif /* HAVE_RTC */
3113 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
3114 softsleep
?"software":timer_name
);
3117 load_termcap(NULL
); // load key-codes
3120 // ========== Init keyboard FIFO (connection to libvo) ============
3122 // Init input system
3123 current_module
= "init_input";
3124 mpctx
->input
= mp_input_init(&opts
->input
);
3125 mp_input_add_key_fd(mpctx
->input
, -1,0,mplayer_get_key
,NULL
, mpctx
->key_fifo
);
3127 mp_input_add_cmd_fd(mpctx
->input
, 0,USE_SELECT
,MP_INPUT_SLAVE_CMD_FUNC
,NULL
);
3128 else if(!noconsolecontrols
)
3129 mp_input_add_key_fd(mpctx
->input
, 0, 1, read_keys
, NULL
, mpctx
->key_fifo
);
3130 // Set the libstream interrupt callback
3131 stream_set_interrupt_callback(mp_input_check_interrupt
, mpctx
->input
);
3135 if(menu_cfg
&& menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3136 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3138 menu_cfg
= get_path("menu.conf");
3139 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
, menu_cfg
))
3140 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", menu_cfg
);
3142 if(menu_init(mpctx
, mpctx
->mconfig
, mpctx
->input
,
3143 MPLAYER_CONFDIR
"/menu.conf"))
3144 mp_tmsg(MSGT_CPLAYER
, MSGL_V
, "Menu initialized: %s\n", MPLAYER_CONFDIR
"/menu.conf");
3146 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Menu init failed.\n");
3154 current_module
= NULL
;
3158 signal(SIGCHLD
,child_sighandler
);
3161 #ifdef CONFIG_CRASH_DEBUG
3162 prog_path
= argv
[0];
3164 //========= Catch terminate signals: ================
3165 // terminate requests:
3166 signal(SIGTERM
,exit_sighandler
); // kill
3167 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
3169 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
3171 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
3172 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
3173 #ifdef CONFIG_SIGHANDLER
3175 signal(SIGBUS
,exit_sighandler
); // bus error
3176 signal(SIGSEGV
,exit_sighandler
); // segfault
3177 signal(SIGILL
,exit_sighandler
); // illegal instruction
3178 signal(SIGFPE
,exit_sighandler
); // floating point exc.
3179 signal(SIGABRT
,exit_sighandler
); // abort()
3180 #ifdef CONFIG_CRASH_DEBUG
3182 signal(SIGTRAP
,exit_sighandler
);
3186 // ******************* Now, let's see the per-file stuff ********************
3190 // init global sub numbers
3191 mpctx
->global_sub_size
= 0;
3192 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) mpctx
->global_sub_indices
[i
] = -1; }
3194 if (mpctx
->filename
) {
3195 load_per_protocol_config (mpctx
->mconfig
, mpctx
->filename
);
3196 load_per_extension_config (mpctx
->mconfig
, mpctx
->filename
);
3197 load_per_file_config (mpctx
->mconfig
, mpctx
->filename
);
3200 if (opts
->video_driver_list
)
3201 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_VO
, opts
->video_driver_list
[0]);
3202 if (opts
->audio_driver_list
)
3203 load_per_output_config (mpctx
->mconfig
, PROFILE_CFG_AO
, opts
->audio_driver_list
[0]);
3205 // We must enable getch2 here to be able to interrupt network connection
3207 if(!noconsolecontrols
&& !slave_mode
){
3208 if(mpctx
->initialized_flags
&INITIALIZED_GETCH2
)
3209 mp_tmsg(MSGT_CPLAYER
,MSGL_WARN
,"WARNING: getch2_init called twice!\n");
3211 getch2_enable(); // prepare stdin for hotkeys...
3212 mpctx
->initialized_flags
|=INITIALIZED_GETCH2
;
3213 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
3216 // =================== GUI idle loop (STOP state) ===========================
3217 while (player_idle_mode
&& !mpctx
->filename
) {
3218 play_tree_t
* entry
= NULL
;
3220 while (!(cmd
= mp_input_get_cmd(mpctx
->input
, 0,1,0))) { // wait for command
3221 if (mpctx
->video_out
)
3222 vo_check_events(mpctx
->video_out
);
3226 case MP_CMD_LOADFILE
:
3227 // prepare a tree entry with the new filename
3228 entry
= play_tree_new();
3229 play_tree_add_file(entry
, cmd
->args
[0].v
.s
);
3230 // The entry is added to the main playtree after the switch().
3232 case MP_CMD_LOADLIST
:
3233 entry
= parse_playlist_file(mpctx
->mconfig
, cmd
->args
[0].v
.s
);
3236 exit_player_with_rc(mpctx
, EXIT_QUIT
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
3238 case MP_CMD_GET_PROPERTY
:
3239 case MP_CMD_SET_PROPERTY
:
3240 case MP_CMD_STEP_PROPERTY
:
3241 run_command(mpctx
, cmd
);
3247 if (entry
) { // user entered a command that gave a valid entry
3248 if (mpctx
->playtree
) // the playtree is always a node with one child. let's clear it
3249 play_tree_free_list(mpctx
->playtree
->child
, 1);
3250 else mpctx
->playtree
=play_tree_new(); // .. or make a brand new playtree
3252 if (!mpctx
->playtree
) continue; // couldn't make playtree! wait for next command
3254 play_tree_set_child(mpctx
->playtree
, entry
);
3256 /* Make iterator start at the top the of tree. */
3257 mpctx
->playtree_iter
= play_tree_iter_new(mpctx
->playtree
, mpctx
->mconfig
);
3258 if (!mpctx
->playtree_iter
) continue;
3260 // find the first real item in the tree
3261 if (play_tree_iter_step(mpctx
->playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
3263 play_tree_iter_free(mpctx
->playtree_iter
);
3264 mpctx
->playtree_iter
= NULL
;
3265 continue; // wait for next command
3267 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, 1);
3270 //---------------------------------------------------------------------------
3273 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"\nPlaying %s.\n",
3274 filename_recode(mpctx
->filename
));
3277 if (edl_records
) free_edl(edl_records
);
3278 next_edl_record
= edl_records
= edl_parse_file();
3280 if (edl_output_filename
) {
3281 if (edl_fd
) fclose(edl_fd
);
3282 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
3284 mp_tmsg(MSGT_CPLAYER
, MSGL_ERR
, "Can't open EDL file [%s] for writing.\n",
3285 filename_recode(edl_output_filename
));
3289 //==================== Open VOB-Sub ============================
3291 current_module
="vobsub";
3293 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
3295 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Cannot load subtitles: %s\n",
3296 filename_recode(vobsub_name
));
3297 } else if (sub_auto
&& mpctx
->filename
){
3298 /* try to autodetect vobsub from movie filename ::atmos */
3299 char *buf
= strdup(mpctx
->filename
), *psub
;
3300 char *pdot
= strrchr(buf
, '.');
3301 char *pslash
= strrchr(buf
, '/');
3302 #if defined(__MINGW32__) || defined(__CYGWIN__)
3303 if (!pslash
) pslash
= strrchr(buf
, '\\');
3305 if (pdot
&& (!pslash
|| pdot
> pslash
))
3307 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
3308 /* try from ~/.mplayer/sub */
3309 if(!vo_vobsub
&& (psub
= get_path( "sub/" ))) {
3312 bname
= strrchr(buf
,'/');
3313 #if defined(__MINGW32__) || defined(__CYGWIN__)
3314 if(!bname
) bname
= strrchr(buf
,'\\');
3318 l
= strlen(psub
) + strlen(bname
) + 1;
3319 psub
= realloc(psub
,l
);
3321 vo_vobsub
=vobsub_open(psub
,spudec_ifo
,0,&vo_spudec
);
3327 mpctx
->initialized_flags
|=INITIALIZED_VOBSUB
;
3328 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
3329 mp_property_do("sub_forced_only", M_PROPERTY_SET
, &forced_subs_only
, mpctx
);
3331 // setup global sub numbering
3332 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] = mpctx
->global_sub_size
; // the global # of the first vobsub.
3333 mpctx
->global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
3336 //============ Open & Sync STREAM --- fork cache2 ====================
3339 mpctx
->demuxer
=NULL
;
3340 if (mpctx
->d_audio
) {
3341 //free_demuxer_stream(mpctx->d_audio);
3342 mpctx
->d_audio
=NULL
;
3344 if (mpctx
->d_video
) {
3345 //free_demuxer_stream(d_video);
3346 mpctx
->d_video
=NULL
;
3348 mpctx
->sh_audio
=NULL
;
3349 mpctx
->sh_video
=NULL
;
3351 current_module
="open_stream";
3352 mpctx
->stream
= open_stream(mpctx
->filename
, opts
, &mpctx
->file_format
);
3353 if(!mpctx
->stream
) { // error...
3354 mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
);
3355 goto goto_next_file
;
3357 mpctx
->initialized_flags
|=INITIALIZED_STREAM
;
3359 if(mpctx
->file_format
== DEMUXER_TYPE_PLAYLIST
) {
3360 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "\nThis looks like a playlist, but "
3361 "playlist support will not be used automatically.\n"
3362 "MPlayer's playlist code is unsafe and should only be used with "
3363 "trusted sources.\nPlayback will probably fail.\n\n");
3367 current_module
="handle_playlist";
3368 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",
3369 filename_recode(mpctx
->filename
));
3370 entry
= parse_playtree(mpctx
->stream
, mpctx
->mconfig
, 0);
3371 mpctx
->eof
=playtree_add_playlist(mpctx
, entry
);
3372 goto goto_next_file
;
3375 mpctx
->stream
->start_pos
+=seek_to_byte
;
3377 if(stream_dump_type
==5){
3378 unsigned char buf
[4096];
3381 current_module
="dumpstream";
3382 if(mpctx
->stream
->type
==STREAMTYPE_STREAM
&& mpctx
->stream
->fd
<0){
3383 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot dump this stream - no file descriptor available.\n");
3384 exit_player(mpctx
, EXIT_ERROR
);
3386 stream_reset(mpctx
->stream
);
3387 stream_seek(mpctx
->stream
,mpctx
->stream
->start_pos
);
3388 f
=fopen(stream_dump_name
,"wb");
3390 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3391 exit_player(mpctx
, EXIT_ERROR
);
3393 if (dvd_chapter
> 1) {
3394 int chapter
= dvd_chapter
- 1;
3395 stream_control(mpctx
->stream
, STREAM_CTRL_SEEK_TO_CHAPTER
, &chapter
);
3397 while(!mpctx
->stream
->eof
&& !async_quit_request
){
3398 len
=stream_read(mpctx
->stream
,buf
,4096);
3400 if(fwrite(buf
,len
,1,f
) != 1) {
3401 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",stream_dump_name
);
3402 exit_player(mpctx
, EXIT_ERROR
);
3405 if(dvd_last_chapter
> 0) {
3407 if (stream_control(mpctx
->stream
, STREAM_CTRL_GET_CURRENT_CHAPTER
,
3408 &chapter
) == STREAM_OK
&& chapter
+ 1 > dvd_last_chapter
)
3413 mp_tmsg(MSGT_MENCODER
,MSGL_FATAL
,"%s: Error writing file.\n",stream_dump_name
);
3414 exit_player(mpctx
, EXIT_ERROR
);
3416 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3417 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3420 #ifdef CONFIG_DVDREAD
3421 if(mpctx
->stream
->type
==STREAMTYPE_DVD
){
3422 current_module
="dvd lang->id";
3423 if(opts
->audio_id
==-1) opts
->audio_id
=dvd_aid_from_lang(mpctx
->stream
,audio_lang
);
3424 if(dvdsub_lang
&& opts
->sub_id
==-2) opts
->sub_id
=-1;
3425 if(dvdsub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=dvd_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3426 // setup global sub numbering
3427 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3428 mpctx
->global_sub_size
+= dvd_number_of_subs(mpctx
->stream
);
3429 current_module
=NULL
;
3433 #ifdef CONFIG_DVDNAV
3434 if(mpctx
->stream
->type
==STREAMTYPE_DVDNAV
){
3435 current_module
="dvdnav lang->id";
3436 if(opts
->audio_id
==-1) opts
->audio_id
=mp_dvdnav_aid_from_lang(mpctx
->stream
,audio_lang
);
3437 if(dvdsub_lang
&& opts
->sub_id
==-2) opts
->sub_id
=-1;
3438 if(dvdsub_lang
&& opts
->sub_id
==-1) opts
->sub_id
=mp_dvdnav_sid_from_lang(mpctx
->stream
,dvdsub_lang
);
3439 // setup global sub numbering
3440 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3441 mpctx
->global_sub_size
+= mp_dvdnav_number_of_subs(mpctx
->stream
);
3442 current_module
=NULL
;
3446 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3448 if(stream_cache_size
>0){
3449 current_module
="enable_cache";
3450 if(!stream_enable_cache(mpctx
->stream
,stream_cache_size
*1024,
3451 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
3452 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
3453 if((mpctx
->stop_play
= libmpdemux_was_interrupted(mpctx
, PT_NEXT_ENTRY
))) goto goto_next_file
;
3456 //============ Open DEMUXERS --- DETECT file type =======================
3457 current_module
="demux_open";
3459 mpctx
->demuxer
=demux_open(opts
, mpctx
->stream
,mpctx
->file_format
,opts
->audio_id
,opts
->video_id
,opts
->sub_id
,mpctx
->filename
);
3461 // HACK to get MOV Reference Files working
3463 if (mpctx
->demuxer
&& mpctx
->demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
3465 unsigned char* playlist_entry
;
3466 play_tree_t
*list
= NULL
, *entry
= NULL
;
3468 current_module
="handle_demux_playlist";
3469 while (ds_get_packet(mpctx
->demuxer
->video
,&playlist_entry
)>0)
3473 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",
3474 filename_recode(playlist_entry
));
3476 bname
=mp_basename(playlist_entry
);
3477 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
3480 if (!strcmp(playlist_entry
, mpctx
->filename
)) // ignoring self-reference
3483 entry
= play_tree_new();
3485 if (mpctx
->filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
3487 temp
=malloc((strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))+strlen(playlist_entry
)+1));
3490 strncpy(temp
, mpctx
->filename
, strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
)));
3491 temp
[strlen(mpctx
->filename
)-strlen(mp_basename(mpctx
->filename
))]='\0';
3492 strcat(temp
, playlist_entry
);
3493 if (!strcmp(temp
, mpctx
->filename
)) {
3497 play_tree_add_file(entry
,temp
);
3498 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
3503 play_tree_add_file(entry
,playlist_entry
);
3508 play_tree_append_entry(list
,entry
);
3510 free_demuxer(mpctx
->demuxer
);
3511 mpctx
->demuxer
= NULL
;
3515 entry
= play_tree_new();
3516 play_tree_set_child(entry
,list
);
3517 mpctx
->stop_play
= playtree_add_playlist(mpctx
, entry
);
3518 goto goto_next_file
;
3523 goto goto_next_file
;
3525 if (mpctx
->demuxer
->matroska_data
.ordered_chapters
)
3526 build_ordered_chapter_timeline(mpctx
);
3528 if (!mpctx
->sources
) {
3529 mpctx
->sources
= talloc_ptrtype(NULL
, mpctx
->sources
);
3530 *mpctx
->sources
= (struct content_source
){.stream
= mpctx
->stream
,
3531 .demuxer
= mpctx
->demuxer
};
3532 mpctx
->num_sources
= 1;
3537 if (seek_chapter(mpctx
, dvd_chapter
-1, &pts
, NULL
) >= 0 && pts
> -1.0)
3538 seek(mpctx
, pts
, SEEK_ABSOLUTE
);
3541 mpctx
->initialized_flags
|=INITIALIZED_DEMUXER
;
3543 if (mpctx
->stream
->type
!= STREAMTYPE_DVD
&& mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
) {
3546 // setup global sub numbering
3547 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] = mpctx
->global_sub_size
; // the global # of the first demux-specific sub.
3548 for (i
= 0; i
< MAX_S_STREAMS
; i
++)
3549 if (mpctx
->demuxer
->s_streams
[i
])
3550 maxid
= FFMAX(maxid
, mpctx
->demuxer
->s_streams
[i
]->sid
);
3551 mpctx
->global_sub_size
+= maxid
+ 1;
3553 // Make opts->sub_id always selectable if set.
3554 if (mpctx
->global_sub_size
<= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
)
3555 mpctx
->global_sub_size
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
+ 1;
3558 if (ass_enabled
&& ass_library
) {
3559 for (int j
= 0; j
< mpctx
->num_sources
; j
++) {
3560 struct demuxer
*d
= mpctx
->sources
[j
].demuxer
;
3561 for (int i
= 0; i
< d
->num_attachments
; i
++) {
3562 struct demux_attachment
*att
= d
->attachments
+ i
;
3563 if (extract_embedded_fonts
3564 && att
->name
&& att
->type
&& att
->data
&& att
->data_size
3565 && (strcmp(att
->type
, "application/x-truetype-font") == 0
3566 || strcmp(att
->type
, "application/x-font") == 0))
3567 ass_add_font(ass_library
, att
->name
, att
->data
, att
->data_size
);
3573 current_module
="demux_open2";
3575 //file_format=demuxer->file_format;
3577 mpctx
->d_audio
=mpctx
->demuxer
->audio
;
3578 mpctx
->d_video
=mpctx
->demuxer
->video
;
3579 mpctx
->d_sub
=mpctx
->demuxer
->sub
;
3581 // select audio stream
3582 select_audio(mpctx
->demuxer
, opts
->audio_id
, audio_lang
);
3585 if((stream_dump_type
)&&(stream_dump_type
<4)){
3587 demux_stream_t
*ds
=NULL
;
3588 current_module
="dump";
3589 // select stream to dump
3590 switch(stream_dump_type
){
3591 case 1: ds
=mpctx
->d_audio
;break;
3592 case 2: ds
=mpctx
->d_video
;break;
3593 case 3: ds
=mpctx
->d_sub
;break;
3596 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"dump: FATAL: Selected stream missing!\n");
3597 exit_player(mpctx
, EXIT_ERROR
);
3599 // disable other streams:
3600 if(mpctx
->d_audio
&& mpctx
->d_audio
!=ds
) {ds_free_packs(mpctx
->d_audio
); mpctx
->d_audio
->id
=-2; }
3601 if(mpctx
->d_video
&& mpctx
->d_video
!=ds
) {ds_free_packs(mpctx
->d_video
); mpctx
->d_video
->id
=-2; }
3602 if(mpctx
->d_sub
&& mpctx
->d_sub
!=ds
) {ds_free_packs(mpctx
->d_sub
); mpctx
->d_sub
->id
=-2; }
3604 f
=fopen(stream_dump_name
,"wb");
3606 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot open dump file.\n");
3607 exit_player(mpctx
, EXIT_ERROR
);
3610 unsigned char* start
;
3611 int in_size
=ds_get_packet(ds
,&start
);
3612 if( (mpctx
->demuxer
->file_format
==DEMUXER_TYPE_AVI
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_ASF
|| mpctx
->demuxer
->file_format
==DEMUXER_TYPE_MOV
)
3613 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
3614 if(in_size
>0) fwrite(start
,in_size
,1,f
);
3615 if(dvd_last_chapter
>0) {
3616 int cur_chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
3617 if(cur_chapter
!=-1 && cur_chapter
+1>dvd_last_chapter
)
3622 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Core dumped ;)\n");
3623 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
3626 mpctx
->sh_audio
=mpctx
->d_audio
->sh
;
3627 mpctx
->sh_video
=mpctx
->d_video
->sh
;
3629 if(mpctx
->sh_video
){
3631 current_module
="video_read_properties";
3632 if(!video_read_properties(mpctx
->sh_video
)) {
3633 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"Video: Cannot read properties.\n");
3634 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3636 mp_tmsg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n",
3637 mpctx
->demuxer
->file_format
,mpctx
->sh_video
->format
, mpctx
->sh_video
->disp_w
,mpctx
->sh_video
->disp_h
,
3638 mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
3641 /* need to set fps here for output encoders to pick it up in their init */
3643 mpctx
->sh_video
->fps
=force_fps
;
3644 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3646 vo_fps
= mpctx
->sh_video
->fps
;
3648 if(!mpctx
->sh_video
->fps
&& !force_fps
){
3649 mp_tmsg(MSGT_CPLAYER
,MSGL_ERR
,"FPS not specified in the header or invalid, use the -fps option.\n");
3650 mpctx
->sh_video
=mpctx
->d_video
->sh
=NULL
;
3656 if(!mpctx
->sh_video
&& !mpctx
->sh_audio
){
3657 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "No stream found.\n");
3659 if(mpctx
->stream
->type
== STREAMTYPE_DVB
)
3662 int v
= mpctx
->last_dvb_step
;
3664 dir
= DVB_CHANNEL_HIGHER
;
3666 dir
= DVB_CHANNEL_LOWER
;
3668 if(dvb_step_channel(mpctx
->stream
, dir
)) {
3669 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3670 mpctx
->dvbin_reopen
= 1;
3674 goto goto_next_file
; // exit_player(_("Fatal error"));
3677 /* display clip info */
3678 demux_info_print(mpctx
->demuxer
);
3680 //================== Read SUBTITLES (DVD & TEXT) ==========================
3681 if(vo_spudec
==NULL
&& mpctx
->sh_video
&&
3682 (mpctx
->stream
->type
==STREAMTYPE_DVD
|| mpctx
->stream
->type
== STREAMTYPE_DVDNAV
)){
3683 init_vo_spudec(mpctx
);
3686 if(mpctx
->sh_video
) {
3687 // after reading video params we should load subtitles because
3688 // we know fps so now we can adjust subtitle time to ~6 seconds AST
3690 current_module
="read_subtitles_file";
3692 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
3693 add_subtitles(mpctx
, sub_name
[i
], mpctx
->sh_video
->fps
, 0);
3695 if(sub_auto
) { // auto load sub file ...
3696 char *psub
= get_path( "sub/" );
3697 char **tmp
= sub_filenames((psub
? psub
: ""), mpctx
->filename
);
3699 free(psub
); // release the buffer created by get_path() above
3701 add_subtitles(mpctx
, tmp
[i
], mpctx
->sh_video
->fps
, 1);
3706 if (mpctx
->set_of_sub_size
> 0) {
3707 // setup global sub numbering
3708 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = mpctx
->global_sub_size
; // the global # of the first sub.
3709 mpctx
->global_sub_size
+= mpctx
->set_of_sub_size
;
3713 if (mpctx
->global_sub_size
) {
3714 // find the best sub to use
3715 int vobsub_index_id
= vobsub_get_index_by_id(vo_vobsub
, vobsub_id
);
3716 mpctx
->global_sub_pos
= -1; // no subs by default
3717 if (vobsub_index_id
>= 0) {
3718 // if user asks for a vobsub id, use that first.
3719 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_index_id
;
3720 } else if (opts
->sub_id
>= 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3721 // if user asks for a dvd sub id, use that next.
3722 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
;
3723 } else if (mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
3724 // if there are text subs to use, use those. (autosubs come last here)
3725 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
];
3726 } else if (opts
->sub_id
< 0 && mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
3727 // finally select subs by language and container hints
3728 if (opts
->sub_id
< 0 && dvdsub_lang
)
3729 opts
->sub_id
= demuxer_sub_track_by_lang(mpctx
->demuxer
, dvdsub_lang
);
3730 if (opts
->sub_id
< 0)
3731 opts
->sub_id
= demuxer_default_sub_track(mpctx
->demuxer
);
3732 if (opts
->sub_id
>= 0)
3733 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
] + opts
->sub_id
;
3735 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
3736 mpctx
->global_sub_pos
--;
3737 mp_property_do("sub",M_PROPERTY_STEP_UP
,NULL
, mpctx
);
3739 switch (stream_dump_type
) {
3740 case 3: list_sub_file(subdata
); break;
3741 case 4: dump_mpsub(subdata
, mpctx
->sh_video
->fps
); break;
3742 case 6: dump_srt(subdata
, mpctx
->sh_video
->fps
); break;
3743 case 7: dump_microdvd(subdata
, mpctx
->sh_video
->fps
); break;
3744 case 8: dump_jacosub(subdata
, mpctx
->sh_video
->fps
); break;
3745 case 9: dump_sami(subdata
, mpctx
->sh_video
->fps
); break;
3749 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_FILENAME=%s\n",
3750 filename_recode(mpctx
->filename
));
3751 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_DEMUXER=%s\n", mpctx
->demuxer
->desc
->name
);
3752 if (mpctx
->sh_video
) {
3753 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3754 if (mpctx
->sh_video
->format
>= 0x20202020)
3755 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx
->sh_video
->format
);
3757 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", mpctx
->sh_video
->format
);
3758 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", mpctx
->sh_video
->i_bps
*8);
3759 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", mpctx
->sh_video
->disp_w
);
3760 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", mpctx
->sh_video
->disp_h
);
3761 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", mpctx
->sh_video
->fps
);
3762 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", mpctx
->sh_video
->aspect
);
3764 if (mpctx
->sh_audio
) {
3765 /* Assume FOURCC if all bytes >= 0x20 (' ') */
3766 if (mpctx
->sh_audio
->format
>= 0x20202020)
3767 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx
->sh_audio
->format
);
3769 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", mpctx
->sh_audio
->format
);
3770 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", mpctx
->sh_audio
->i_bps
*8);
3771 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", mpctx
->sh_audio
->samplerate
);
3772 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", mpctx
->sh_audio
->channels
);
3774 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_LENGTH=%.2f\n", demuxer_get_time_length(mpctx
->demuxer
));
3775 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_SEEKABLE=%d\n",
3776 mpctx
->stream
->seek
&& (!mpctx
->demuxer
|| mpctx
->demuxer
->seekable
));
3777 if (mpctx
->demuxer
) {
3778 if (mpctx
->demuxer
->num_chapters
== 0)
3779 stream_control(mpctx
->demuxer
->stream
, STREAM_CTRL_GET_NUM_CHAPTERS
, &mpctx
->demuxer
->num_chapters
);
3780 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
,"ID_CHAPTERS=%d\n", mpctx
->demuxer
->num_chapters
);
3783 if(!mpctx
->sh_video
) goto main
; // audio-only
3785 if(!reinit_video_chain(mpctx
)) {
3786 if(!mpctx
->sh_video
){
3787 if(!mpctx
->sh_audio
) goto goto_next_file
;
3788 goto main
; // exit_player(_("Fatal error"));
3792 if(mpctx
->sh_video
->output_flags
& 0x08 && vo_spudec
)
3793 spudec_set_hw_spu(vo_spudec
,mpctx
->video_out
);
3795 #ifdef CONFIG_FREETYPE
3796 force_load_font
= 1;
3799 //================== MAIN: ==========================
3801 current_module
="main";
3804 char* msg
= property_expand_string(mpctx
, playing_msg
);
3805 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"%s",msg
);
3810 // Disable the term OSD in verbose mode
3811 if(verbose
) term_osd
= 0;
3814 //int frame_corr_num=0; //
3815 //float v_frame=0; // Video
3816 //float num_frames=0; // number of frames played
3818 int frame_time_remaining
=0; // flag
3820 mpctx
->num_buffered_frames
=0;
3822 // Make sure old OSD does not stay around,
3823 // e.g. with -fixed-vo and same-resolution files
3825 update_osd_msg(mpctx
);
3827 //================ SETUP AUDIO ==========================
3829 if(mpctx
->sh_audio
){
3830 reinit_audio_chain(mpctx
);
3831 if (mpctx
->sh_audio
&& mpctx
->sh_audio
->codec
)
3832 mp_msg(MSGT_IDENTIFY
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", mpctx
->sh_audio
->codec
->name
);
3835 current_module
="av_init";
3837 if(mpctx
->sh_video
){
3838 mpctx
->sh_video
->timer
=0;
3840 audio_delay
+= mpctx
->sh_video
->stream_delay
;
3842 if(mpctx
->sh_audio
){
3843 if (start_volume
>= 0)
3844 mixer_setvolume(&mpctx
->mixer
, start_volume
, start_volume
);
3846 audio_delay
-= mpctx
->sh_audio
->stream_delay
;
3847 mpctx
->delay
=-audio_delay
;
3850 if(!mpctx
->sh_audio
){
3851 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Audio: no sound\n");
3852 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",mpctx
->d_audio
->packs
);
3853 ds_free_packs(mpctx
->d_audio
); // free buffered chunks
3854 //mpctx->d_audio->id=-2; // do not read audio chunks
3855 //uninit_player(mpctx, INITIALIZED_AO); // close device
3857 if(!mpctx
->sh_video
){
3858 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Video: no video\n");
3859 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",mpctx
->d_video
->packs
);
3860 ds_free_packs(mpctx
->d_video
);
3861 mpctx
->d_video
->id
=-2;
3862 //if(!fixed_vo) uninit_player(mpctx, INITIALIZED_VO);
3865 if (!mpctx
->sh_video
&& !mpctx
->sh_audio
)
3866 goto goto_next_file
;
3868 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
3869 if(force_fps
&& mpctx
->sh_video
){
3870 vo_fps
= mpctx
->sh_video
->fps
=force_fps
;
3871 mpctx
->sh_video
->frametime
=1.0f
/mpctx
->sh_video
->fps
;
3872 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"FPS forced to be %5.3f (ftime: %5.3f).\n",mpctx
->sh_video
->fps
,mpctx
->sh_video
->frametime
);
3875 mp_input_set_section(mpctx
->input
, NULL
);
3876 //TODO: add desired (stream-based) sections here
3877 if (mpctx
->stream
->type
==STREAMTYPE_TV
) mp_input_set_section(mpctx
->input
, "tv");
3878 if (mpctx
->stream
->type
==STREAMTYPE_DVDNAV
) mp_input_set_section(mpctx
->input
, "dvdnav");
3880 //==================== START PLAYING =======================
3882 if(opts
->loop_times
>1) opts
->loop_times
--; else
3883 if(opts
->loop_times
==1) opts
->loop_times
= -1;
3885 mp_tmsg(MSGT_CPLAYER
,MSGL_INFO
,"Starting playback...\n");
3887 total_time_usage_start
=GetTimer();
3888 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3889 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
3890 play_n_frames
=play_n_frames_mf
;
3892 if(play_n_frames
==0){
3893 mpctx
->stop_play
=PT_NEXT_ENTRY
; goto goto_next_file
;
3897 seek(mpctx
, seek_to_sec
, SEEK_ABSOLUTE
);
3898 end_at
.pos
+= seek_to_sec
;
3901 if (end_at
.type
== END_AT_SIZE
) {
3902 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "Option -endpos in MPlayer does not yet support size units.\n");
3903 end_at
.type
= END_AT_NONE
;
3906 #ifdef CONFIG_DVDNAV
3907 mp_dvdnav_context_free(mpctx
);
3908 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
3909 mp_dvdnav_read_wait(mpctx
->stream
, 0, 1);
3910 mp_dvdnav_cell_has_changed(mpctx
->stream
,1);
3914 get_relative_time(mpctx
); // reset current delta
3915 mpctx
->time_frame
= 0;
3916 mpctx
->drop_message_shown
= 0;
3917 mpctx
->update_video_immediately
= true;
3918 mpctx
->total_avsync_change
= 0;
3919 // Make sure VO knows current pause state
3920 if (mpctx
->sh_video
)
3921 vo_control(mpctx
->video_out
, mpctx
->paused
? VOCTRL_PAUSE
: VOCTRL_RESUME
,
3924 while(!mpctx
->stop_play
){
3925 float aq_sleep_time
=0;
3927 if(dvd_last_chapter
>0) {
3928 int cur_chapter
= get_current_chapter(mpctx
);
3929 if(cur_chapter
!=-1 && cur_chapter
+1>dvd_last_chapter
)
3930 goto goto_next_file
;
3933 if(!mpctx
->sh_audio
&& mpctx
->d_audio
->sh
) {
3934 mpctx
->sh_audio
= mpctx
->d_audio
->sh
;
3935 mpctx
->sh_audio
->ds
= mpctx
->d_audio
;
3936 reinit_audio_chain(mpctx
);
3939 /*========================== PLAY AUDIO ============================*/
3941 if (mpctx
->sh_audio
&& !mpctx
->paused
)
3942 if (!fill_audio_out_buffers(mpctx
))
3943 // at eof, all audio at least written to ao
3944 if (!mpctx
->sh_video
)
3945 mpctx
->stop_play
= AT_END_OF_FILE
;
3948 if(!mpctx
->sh_video
) {
3949 // handle audio-only case:
3951 // sh_audio can be NULL due to video stream switching
3952 // TODO: handle this better
3953 if (mpctx
->sh_audio
)
3954 a_pos
= playing_audio_pts(mpctx
);
3956 print_status(mpctx
, a_pos
, false);
3958 if(end_at
.type
== END_AT_TIME
&& end_at
.pos
< a_pos
)
3959 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3960 update_osd_msg(mpctx
);
3964 /*========================== PLAY VIDEO ============================*/
3966 vo_pts
=mpctx
->sh_video
->timer
*90000.0;
3967 vo_fps
=mpctx
->sh_video
->fps
;
3969 if (!mpctx
->num_buffered_frames
) {
3970 double frame_time
= update_video(mpctx
, &blit_frame
);
3971 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
3972 if (mpctx
->sh_video
->vf_initialized
< 0) {
3973 mp_tmsg(MSGT_CPLAYER
,MSGL_FATAL
, "\nFATAL: Could not initialize video filters (-vf) or video output (-vo).\n");
3974 mpctx
->stop_play
= PT_NEXT_ENTRY
;
3975 goto goto_next_file
;
3978 struct vf_instance
*vf
= mpctx
->sh_video
->vfilter
;
3979 vf
->control(vf
, VFCTRL_DRAW_EOSD
, NULL
);
3980 vf
->control(vf
, VFCTRL_DRAW_OSD
, mpctx
->osd
);
3984 mpctx
->stop_play
= AT_END_OF_FILE
;
3986 // might return with !eof && !blit_frame if !correct_pts
3987 mpctx
->num_buffered_frames
+= blit_frame
;
3988 if (mpctx
->update_video_immediately
) {
3989 // Show this frame immediately, rest normally
3990 mpctx
->update_video_immediately
= false;
3992 mpctx
->time_frame
+= frame_time
/ opts
->playback_speed
;
3993 adjust_sync(mpctx
, frame_time
);
3997 if (mpctx
->timeline
) {
3998 struct timeline_part
*next
= mpctx
->timeline
+ mpctx
->timeline_part
+ 1;
3999 if (mpctx
->sh_video
->pts
>= next
->start
4000 || mpctx
->stop_play
== AT_END_OF_FILE
4001 && mpctx
->timeline_part
+ 1 < mpctx
->num_timeline_parts
) {
4002 seek(mpctx
, next
->start
, SEEK_ABSOLUTE
);
4007 // ==========================================================================
4009 // current_module="draw_osd";
4010 // if(vo_config_count) mpctx->video_out->draw_osd();
4012 current_module
="vo_check_events";
4013 vo_check_events(mpctx
->video_out
);
4016 if (stop_xscreensaver
) {
4017 current_module
= "stop_xscreensaver";
4018 xscreensaver_heartbeat(mpctx
->x11_state
);
4021 if (heartbeat_cmd
) {
4022 static unsigned last_heartbeat
;
4023 unsigned now
= GetTimerMS();
4024 if (now
- last_heartbeat
> 30000) {
4025 last_heartbeat
= now
;
4026 system(heartbeat_cmd
);
4030 frame_time_remaining
= sleep_until_update(mpctx
, &mpctx
->time_frame
, &aq_sleep_time
);
4032 //====================== FLIP PAGE (VIDEO BLT): =========================
4034 current_module
="flip_page";
4035 if (!frame_time_remaining
&& blit_frame
) {
4036 unsigned int t2
=GetTimer();
4038 vo_flip_page(mpctx
->video_out
);
4039 mpctx
->num_buffered_frames
--;
4041 mpctx
->last_vo_flip_duration
= (GetTimer() - t2
) * 0.000001;
4042 vout_time_usage
+= mpctx
->last_vo_flip_duration
;
4043 print_status(mpctx
, MP_NOPTS_VALUE
, true);
4046 print_status(mpctx
, MP_NOPTS_VALUE
, false);
4048 //============================ Auto QUALITY ============================
4050 /*Output quality adjustments:*/
4052 current_module
="autoq";
4053 // float total=0.000001f * (GetTimer()-aq_total_time);
4054 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4055 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
4058 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4059 if(output_quality
>1 && aq_sleep_time
<0)
4062 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
4064 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4065 set_video_quality(mpctx
->sh_video
,output_quality
);
4068 if (!frame_time_remaining
&& blit_frame
) {
4069 if (play_n_frames
>= 0) {
4071 if (play_n_frames
<= 0)
4072 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4074 if (mpctx
->step_frames
> 0) {
4075 mpctx
->step_frames
--;
4076 if (mpctx
->step_frames
== 0)
4077 pause_player(mpctx
);
4082 // FIXME: add size based support for -endpos
4083 if (end_at
.type
== END_AT_TIME
&&
4084 !frame_time_remaining
&& end_at
.pos
<= mpctx
->sh_video
->pts
)
4085 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4087 } // end if(mpctx->sh_video)
4089 #ifdef CONFIG_DVDNAV
4090 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
4092 mp_dvdnav_get_highlight (mpctx
->stream
, &hl
);
4093 osd_set_nav_box (hl
.sx
, hl
.sy
, hl
.ex
, hl
.ey
);
4094 vo_osd_changed (OSDTYPE_DVDNAV
);
4096 if (mp_dvdnav_stream_has_changed(mpctx
->stream
)) {
4098 if (stream_control (mpctx
->demuxer
->stream
,
4099 STREAM_CTRL_GET_ASPECT_RATIO
, &ar
)
4100 != STREAM_UNSUPPORTED
)
4101 mpctx
->sh_video
->stream_aspect
= ar
;
4106 //================= Keyboard events, SEEKing ====================
4108 current_module
="key_events";
4113 while ((cmd
= mp_input_get_cmd(mpctx
->input
, 0,0,0)) != NULL
) {
4114 run_command(mpctx
, cmd
);
4116 if (mpctx
->stop_play
)
4119 if (!mpctx
->paused
|| mpctx
->stop_play
|| mpctx
->rel_seek_secs
4120 || mpctx
->abs_seek_pos
)
4122 if (mpctx
->sh_video
) {
4123 update_osd_msg(mpctx
);
4124 int hack
= vo_osd_changed(0);
4125 vo_osd_changed(hack
);
4127 if (redraw_osd(mpctx
->sh_video
, mpctx
->osd
) < 0) {
4128 add_step_frame(mpctx
);
4139 if (step_sec
> 0 && !mpctx
->paused
) {
4140 mpctx
->osd_function
=OSD_FFW
;
4141 mpctx
->rel_seek_secs
+=step_sec
;
4147 if(mpctx
->stop_play
==AT_END_OF_FILE
&& opts
->loop_times
>=0) {
4148 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d\n", opts
->loop_times
);
4150 if(opts
->loop_times
>1) opts
->loop_times
--; else
4151 if(opts
->loop_times
==1) opts
->loop_times
=-1;
4152 play_n_frames
=play_n_frames_mf
;
4154 mpctx
->abs_seek_pos
=SEEK_ABSOLUTE
; mpctx
->rel_seek_secs
=seek_to_sec
;
4157 if(mpctx
->rel_seek_secs
|| mpctx
->abs_seek_pos
){
4158 seek(mpctx
, mpctx
->rel_seek_secs
, mpctx
->abs_seek_pos
);
4160 mpctx
->rel_seek_secs
=0;
4161 mpctx
->abs_seek_pos
=0;
4164 } // while(!mpctx->stop_play)
4166 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",mpctx
->stop_play
);
4169 if(mpctx
->dvbin_reopen
)
4171 mpctx
->stop_play
= 0;
4172 uninit_player(mpctx
, INITIALIZED_ALL
-(INITIALIZED_STREAM
|INITIALIZED_GETCH2
|(opts
->fixed_vo
?INITIALIZED_VO
:0)));
4173 cache_uninit(mpctx
->stream
);
4174 mpctx
->dvbin_reopen
= 0;
4175 goto goto_enable_cache
;
4180 goto_next_file
: // don't jump here after ao/vo/getch initialization!
4182 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
4185 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
4186 double total_time_usage
;
4187 total_time_usage_start
=GetTimer()-total_time_usage_start
;
4188 total_time_usage
= (float)total_time_usage_start
*0.000001;
4189 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4190 video_time_usage
,vout_time_usage
,audio_time_usage
,
4191 total_time_usage
-tot
,total_time_usage
);
4192 if(total_time_usage
>0.0)
4193 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4194 100.0*video_time_usage
/total_time_usage
,
4195 100.0*vout_time_usage
/total_time_usage
,
4196 100.0*audio_time_usage
/total_time_usage
,
4197 100.0*(total_time_usage
-tot
)/total_time_usage
,
4199 if(total_frame_cnt
&& frame_dropping
)
4200 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4201 total_frame_cnt
-drop_frame_cnt
,
4202 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
4204 100*drop_frame_cnt
/total_frame_cnt
,
4206 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
4209 // time to uninit all, except global stuff:
4210 uninit_player(mpctx
, INITIALIZED_ALL
-(opts
->fixed_vo
?INITIALIZED_VO
:0));
4212 if(mpctx
->set_of_sub_size
> 0) {
4213 current_module
="sub_free";
4214 for(i
= 0; i
< mpctx
->set_of_sub_size
; ++i
) {
4215 sub_free(mpctx
->set_of_subtitles
[i
]);
4217 if(mpctx
->set_of_ass_tracks
[i
])
4218 ass_free_track( mpctx
->set_of_ass_tracks
[i
] );
4221 mpctx
->set_of_sub_size
= 0;
4223 vo_sub_last
= vo_sub
=NULL
;
4228 ass_clear_fonts(ass_library
);
4231 if (!mpctx
->stop_play
) // In case some goto jumped here...
4232 mpctx
->stop_play
= PT_NEXT_ENTRY
;
4234 int playtree_direction
= 1;
4236 if(mpctx
->stop_play
== PT_NEXT_ENTRY
|| mpctx
->stop_play
== PT_PREV_ENTRY
) {
4237 if(play_tree_iter_step(mpctx
->playtree_iter
,mpctx
->play_tree_step
,0) != PLAY_TREE_ITER_ENTRY
) {
4238 play_tree_iter_free(mpctx
->playtree_iter
);
4239 mpctx
->playtree_iter
= NULL
;
4241 mpctx
->play_tree_step
= 1;
4242 } else if(mpctx
->stop_play
== PT_UP_NEXT
|| mpctx
->stop_play
== PT_UP_PREV
) {
4243 int direction
= mpctx
->stop_play
== PT_UP_NEXT
? 1 : -1;
4244 if(mpctx
->playtree_iter
) {
4245 if(play_tree_iter_up_step(mpctx
->playtree_iter
,direction
,0) != PLAY_TREE_ITER_ENTRY
) {
4246 play_tree_iter_free(mpctx
->playtree_iter
);
4247 mpctx
->playtree_iter
= NULL
;
4250 } else if (mpctx
->stop_play
== PT_STOP
) {
4251 play_tree_iter_free(mpctx
->playtree_iter
);
4252 mpctx
->playtree_iter
= NULL
;
4253 } else { // NEXT PREV SRC
4254 playtree_direction
= mpctx
->stop_play
== PT_PREV_SRC
? -1 : 1;
4257 while(mpctx
->playtree_iter
!= NULL
) {
4258 mpctx
->filename
= play_tree_iter_get_file(mpctx
->playtree_iter
, playtree_direction
);
4259 if(mpctx
->filename
== NULL
) {
4260 if(play_tree_iter_step(mpctx
->playtree_iter
, playtree_direction
, 0) != PLAY_TREE_ITER_ENTRY
) {
4261 play_tree_iter_free(mpctx
->playtree_iter
);
4262 mpctx
->playtree_iter
= NULL
;
4268 if(mpctx
->playtree_iter
!= NULL
|| player_idle_mode
){
4269 if(!mpctx
->playtree_iter
) mpctx
->filename
= NULL
;
4270 mpctx
->stop_play
= 0;
4271 goto play_next_file
;
4275 exit_player_with_rc(mpctx
, EXIT_EOF
, 0);
4279 #endif /* DISABLE_MAIN */