6 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
12 // #include <sys/mman.h>
13 #include <sys/types.h>
15 #include <sys/ioctl.h>
18 #define SIGHUP 1 /* hangup */
19 #define SIGQUIT 3 /* quit */
20 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
21 #define SIGBUS 10 /* bus error */
22 #define SIGPIPE 13 /* broken pipe */
23 extern int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
);
40 #define HELP_MP_DEFINE_STATIC
46 #include "cfg-mplayer-def.h"
49 #include "subreader.h"
52 #include "libvo/video_out.h"
54 #include "libvo/font_load.h"
55 #include "libvo/sub.h"
58 #include "libvo/x11_common.h"
61 #include "libao2/audio_out.h"
63 #include "codec-cfg.h"
76 #include "osdep/getch2.h"
77 #include "osdep/timer.h"
79 #include "cpudetect.h"
82 #include "Gui/interface.h"
85 #include "input/input.h"
93 char * proc_priority
=NULL
;
96 #define ABS(x) (((x)>=0)?(x):(-(x)))
97 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
101 #include <linux/rtc.h>
104 #define RTC_IRQP_SET RTCIO_IRQP_SET
105 #define RTC_PIE_ON RTCIO_PIE_ON
110 #include "libmpdemux/tv.h"
113 #ifdef HAS_DVBIN_SUPPORT
114 #include "libmpdemux/dvbin.h"
115 static int last_dvb_step
= 1;
118 //**************************************************************************//
120 //**************************************************************************//
121 #include "playtree.h"
122 #include "playtreeparser.h"
125 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
126 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
129 play_tree_t
* playtree
;
130 play_tree_iter_t
* playtree_iter
= NULL
;
132 #define PT_NEXT_ENTRY 1
133 #define PT_PREV_ENTRY -1
134 #define PT_NEXT_SRC 2
135 #define PT_PREV_SRC -2
137 #define PT_UP_PREV -3
139 //**************************************************************************//
141 //**************************************************************************//
145 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
);
147 m_config_parse_config_file(m_config_t
* config
, char *conffile
);
149 //**************************************************************************//
151 //**************************************************************************//
153 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
155 static int cfg_include(m_option_t
*conf
, char *filename
){
156 return m_config_parse_config_file(mconfig
, filename
);
159 #include "get_path.c"
161 //**************************************************************************//
163 //**************************************************************************//
166 void xscreensaver_heartbeat(void);
169 //**************************************************************************//
170 //**************************************************************************//
171 // Input media streaming & demultiplexer:
172 //**************************************************************************//
174 static int max_framesize
=0;
176 #include "libmpdemux/stream.h"
177 #include "libmpdemux/demuxer.h"
178 #include "libmpdemux/stheader.h"
179 //#include "parse_es.h"
181 #include "libmpdemux/matroska.h"
184 #include "libmpcodecs/dec_audio.h"
185 #include "libmpcodecs/dec_video.h"
186 #include "libmpcodecs/mp_image.h"
187 #include "libmpcodecs/vf.h"
189 extern void vf_list_plugins();
191 //**************************************************************************//
192 //**************************************************************************//
194 // Common FIFO functions, and keyboard/event FIFO code
196 int noconsolecontrols
=0;
197 //**************************************************************************//
199 vo_functions_t
*video_out
=NULL
;
200 ao_functions_t
*audio_out
=NULL
;
206 double video_time_usage
=0;
207 double vout_time_usage
=0;
208 static double audio_time_usage
=0;
209 static int total_time_usage_start
=0;
210 static int total_frame_cnt
=0;
211 static int drop_frame_cnt
=0; // total number of dropped frames
216 static int output_quality
=0;
218 float playback_speed
=1.0;
226 #define MAX_OSD_LEVEL 3
229 int osd_level_saved
=-1;
233 static char *seek_to_sec
=NULL
;
234 static off_t seek_to_byte
=0;
235 static off_t step_sec
=0;
236 static int loop_times
=-1;
237 static int loop_seek
=0;
240 int autosync
=0; // 30 might be a good default value.
242 // may be changed by GUI: (FIXME!)
243 float rel_seek_secs
=0;
247 char **audio_codec_list
=NULL
; // override audio codec
248 char **video_codec_list
=NULL
; // override video codec
249 char **audio_fm_list
=NULL
; // override audio codec family
250 char **video_fm_list
=NULL
; // override video codec family
253 extern char *demuxer_name
; // override demuxer
254 extern char *audio_demuxer_name
; // override audio demuxer
255 extern char *sub_demuxer_name
; // override sub demuxer
262 char* audio_lang
=NULL
;
263 char* dvdsub_lang
=NULL
;
264 static char* spudec_ifo
=NULL
;
265 char* filename
=NULL
; //"MI2-Trailer.avi";
266 int forced_subs_only
=0;
269 int stream_cache_size
=-1;
270 #ifdef USE_STREAM_CACHE
271 extern int cache_fill_status
;
273 float stream_cache_min_percent
=20.0;
274 float stream_cache_seek_min_percent
=50.0;
276 #define cache_fill_status 0
280 static char *stream_dump_name
="stream.dump";
281 int stream_dump_type
=0;
284 static float default_max_pts_correction
=-1;//0.01f;
285 static float max_pts_correction
=0;//default_max_pts_correction;
286 static float c_total
=0;
289 static int softsleep
=0;
292 static int force_srate
=0;
293 static int audio_output_format
=0;
294 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
295 static int play_n_frames
=-1;
296 static int play_n_frames_mf
=-1;
299 char** video_driver_list
=NULL
;
300 char** audio_driver_list
=NULL
;
302 extern char *vo_subdevice
;
303 extern char *ao_subdevice
;
305 // codec outfmt flags (defined in libmpcodecs/vd.c)
309 char *font_name
=NULL
;
310 #ifdef HAVE_FONTCONFIG
311 extern int font_fontconfig
;
313 float font_factor
=0.75;
314 char **sub_name
=NULL
;
318 char *vobsub_name
=NULL
;
319 /*DSP!!char *dsp=NULL;*/
321 int suboverlap_enabled
= 1;
323 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
324 int set_of_sub_size
= 0;
325 int set_of_sub_pos
= -1;
326 float sub_last_pts
= -303;
328 int global_sub_size
= 0; // this encompasses all subtitle sources
329 int global_sub_pos
= -1; // this encompasses all subtitle sources
330 #define SUB_SOURCE_SUBS 0
331 #define SUB_SOURCE_VOBSUB 1
332 #define SUB_SOURCE_DEMUX 2
333 #define SUB_SOURCES 3
334 int global_sub_indices
[SUB_SOURCES
];
335 int global_sub_quiet_osd_hack
= 0;
337 static stream_t
* stream
=NULL
;
338 static demuxer_t
*demuxer
=NULL
;
339 static sh_audio_t
*sh_audio
=NULL
;
340 static sh_video_t
*sh_video
=NULL
;
342 char* current_module
=NULL
; // for debugging
344 extern int vo_gamma_gamma
;
345 extern int vo_gamma_brightness
;
346 extern int vo_gamma_contrast
;
347 extern int vo_gamma_saturation
;
348 extern int vo_gamma_hue
;
353 #include "m_struct.h"
354 #include "libmenu/menu.h"
355 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
356 extern vf_info_t vf_info_menu
;
357 static vf_info_t
* libmenu_vfs
[] = {
361 static vf_instance_t
* vf_menu
= NULL
;
362 static int use_menu
= 0;
363 static char* menu_cfg
= NULL
;
364 static char* menu_root
= "main";
370 static char* rtc_device
;
374 edl_record_ptr edl_records
= NULL
; ///< EDL entries memory area
375 edl_record_ptr next_edl_record
= NULL
; ///< only for traversing edl_records
376 short user_muted
= 0; ///< Stores whether User wanted muted mode.
377 short edl_muted
= 0; ///< Stores whether EDL is currently in muted mode.
378 short edl_decision
= 0; ///< 1 when an EDL operation has been made
379 FILE* edl_fd
= NULL
; ///< fd to write to when in -edlout mode
382 static unsigned int inited_flags
=0;
386 #define INITED_GETCH2 8
387 #define INITED_SPUDEC 32
388 #define INITED_STREAM 64
389 #define INITED_INPUT 128
390 #define INITED_VOBSUB 256
391 #define INITED_DEMUXER 512
392 #define INITED_ACODEC 1024
393 #define INITED_VCODEC 2048
394 #define INITED_ALL 0xFFFF
396 static void uninit_player(unsigned int mask
){
397 mask
=inited_flags
&mask
;
399 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
401 if(mask
&INITED_ACODEC
){
402 inited_flags
&=~INITED_ACODEC
;
403 current_module
="uninit_acodec";
404 if(sh_audio
) uninit_audio(sh_audio
);
406 guiGetEvent(guiSetAfilter
, (char *)NULL
);
411 if(mask
&INITED_VCODEC
){
412 inited_flags
&=~INITED_VCODEC
;
413 current_module
="uninit_vcodec";
414 if(sh_video
) uninit_video(sh_video
);
421 if(mask
&INITED_DEMUXER
){
422 inited_flags
&=~INITED_DEMUXER
;
423 current_module
="free_demuxer";
425 stream
=demuxer
->stream
;
426 free_demuxer(demuxer
);
431 // kill the cache process:
432 if(mask
&INITED_STREAM
){
433 inited_flags
&=~INITED_STREAM
;
434 current_module
="uninit_stream";
435 if(stream
) free_stream(stream
);
440 inited_flags
&=~INITED_VO
;
441 current_module
="uninit_vo";
446 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
447 if(mask
&INITED_GETCH2
){
448 inited_flags
&=~INITED_GETCH2
;
449 current_module
="uninit_getch2";
450 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
455 if(mask
&INITED_VOBSUB
){
456 inited_flags
&=~INITED_VOBSUB
;
457 current_module
="uninit_vobsub";
458 if(vo_vobsub
) vobsub_close(vo_vobsub
);
462 if (mask
&INITED_SPUDEC
){
463 inited_flags
&=~INITED_SPUDEC
;
464 current_module
="uninit_spudec";
465 spudec_free(vo_spudec
);
470 inited_flags
&=~INITED_AO
;
471 current_module
="uninit_ao";
472 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
477 inited_flags
&=~INITED_GUI
;
478 current_module
="uninit_gui";
483 if(mask
&INITED_INPUT
){
484 inited_flags
&=~INITED_INPUT
;
485 current_module
="uninit_input";
492 static void exit_player_with_rc(char* how
, int rc
){
494 uninit_player(INITED_ALL
);
499 vo_uninit(); // close the X11 connection (if any opened)
503 current_module
="uninit_font";
504 if (vo_font
) free_font_desc(vo_font
);
510 current_module
="exit_player";
512 // free mplayer config
514 m_config_free(mconfig
);
517 play_tree_free(playtree
, 1);
521 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
523 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,mp_gettext(how
));
524 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
529 void exit_player(char* how
){
530 exit_player_with_rc(how
, 1);
534 static void child_sighandler(int x
){
536 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
541 static char *prog_path
;
542 static int crash_debug
= 0;
545 static void exit_sighandler(int x
){
546 static int sig_count
=0;
548 if (!crash_debug
|| x
!= SIGTRAP
)
551 if(inited_flags
==0 && sig_count
>1) exit(1);
554 /* We're crashing bad and can't uninit cleanly :(
555 * by popular request, we make one last (dirty)
556 * effort to restore the user's
561 if(sig_count
==6) exit(1);
565 kill(getpid(),SIGKILL
);
568 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
569 current_module
?current_module
:mp_gettext("unknown")
577 break; // killed from keyboard (^C) or killed [-9]
579 #ifdef RUNTIME_CPUDETECT
580 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
582 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
586 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
588 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
593 snprintf(spid
, 19, "%i", getpid());
595 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forking...\n");
597 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Forked...\n");
598 if (gdb_pid
== 0) { // We are the child
599 if (execlp("gdb", "gdb", prog_path
, spid
, NULL
) == -1)
600 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't start gdb\n");
601 } else if (gdb_pid
< 0)
602 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Couldn't fork\n");
604 waitpid(gdb_pid
, NULL
, 0);
606 if (x
== SIGTRAP
) return;
613 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
615 extern void mp_input_register_options(m_config_t
* cfg
);
619 /// step size of mixer changes
622 #include "cfg-mplayer.h"
624 void parse_cfgfiles( m_config_t
* conf
)
628 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
630 if ((conffile
= get_path("")) == NULL
) {
631 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
636 mkdir(conffile
, 0777);
639 if ((conffile
= get_path("config")) == NULL
) {
640 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
642 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
643 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
644 write(conffile_fd
, default_config
, strlen(default_config
));
647 if (m_config_parse_config_file(conf
, conffile
) < 0)
654 void load_per_file_config (m_config_t
* conf
, const char *const file
)
657 char cfg
[strlen(file
)+10];
661 sprintf (cfg
, "%s.conf", file
);
663 if (!stat (cfg
, &st
))
665 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
666 m_config_parse_config_file (conf
, cfg
);
670 if ((name
= strrchr (cfg
, '/')) == NULL
)
675 if ((confpath
= get_path (name
)) != NULL
)
677 if (!stat (confpath
, &st
))
679 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
680 m_config_parse_config_file (conf
, confpath
);
687 // When libmpdemux perform a blocking operation (network connection or cache filling)
688 // if the operation fail we use this function to check if it was interrupted by the user.
689 // The function return a new value for eof.
690 static int libmpdemux_was_interrupted(int eof
) {
692 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
695 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
696 case MP_CMD_PLAY_TREE_STEP
: {
697 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
699 case MP_CMD_PLAY_TREE_UP_STEP
: {
700 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
702 case MP_CMD_PLAY_ALT_SRC_STEP
: {
703 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
711 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
712 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
714 int playtree_add_playlist(play_tree_t
* entry
)
716 play_tree_add_bpf(entry
,filename
);
721 import_playtree_playlist_into_gui(entry
, mconfig
);
722 play_tree_free_list(entry
,1);
728 entry
= playtree_iter
->tree
;
729 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
730 return PT_NEXT_ENTRY
;
732 if(playtree_iter
->tree
== entry
) { // Loop with a single file
733 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
734 return PT_NEXT_ENTRY
;
737 play_tree_remove(entry
,1,1);
740 play_tree_insert_entry(playtree_iter
->tree
,entry
);
741 play_tree_set_params_from(entry
,playtree_iter
->tree
);
742 entry
= playtree_iter
->tree
;
743 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
744 return PT_NEXT_ENTRY
;
746 play_tree_remove(entry
,1,1);
751 static int play_tree_step
= 1;
758 for (i
= 0; i
< SUB_SOURCES
; i
++) {
759 int j
= global_sub_indices
[i
];
760 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
770 sub_data
* subdata
= NULL
;
771 static subtitle
* vo_sub_last
= NULL
;
773 void add_subtitles(char *filename
, float fps
, int silent
)
777 if (filename
== NULL
) {
781 subd
= sub_read_file(filename
, fps
);
783 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
784 if (subd
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) return;
785 set_of_subtitles
[set_of_sub_size
] = subd
;
788 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ID_FILE_SUB_ID=%d\n", set_of_sub_size
);
789 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ID_FILE_SUB_FILENAME=%s\n", filename
);
792 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AddedSubtitleFile
, set_of_sub_size
, filename
);
795 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
796 void update_set_of_subtitles()
797 // subdata was changed, set_of_sub... have to be updated.
800 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
801 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
802 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
803 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
805 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
807 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
808 set_of_subtitles
[set_of_sub_pos
] = subdata
;
810 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
811 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
818 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
819 * make it all work is to use the builtin SDL-bootstrap code, which
820 * will be done automatically by replacing our main() if we include SDL.h.
822 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
827 * \brief append a formatted string
828 * \param buf buffer to print into
829 * \param pos position of terminating 0 in buf
830 * \param len maximum number of characters in buf, not including terminating 0
831 * \param format printf format string
833 static void saddf(char *buf
, unsigned *pos
, int len
, const char *format
, ...)
836 va_start(va
, format
);
837 *pos
+= vsnprintf(&buf
[*pos
], len
- *pos
, format
, va
);
846 * \brief print the status line
847 * \param a_pos audio position
848 * \param a_v A-V desynchronization
849 * \param corr amount out A-V synchronization
851 static void print_status(float a_pos
, float a_v
, float corr
)
857 if (screen_width
> 0)
858 width
= screen_width
;
862 // windows command line is broken (MinGW's rxvt works though, but we
863 // should not depend on that).
866 line
= malloc(width
+ 1); // one additional for terminating null
870 saddf(line
, &pos
, width
, "A:%6.1f ", a_pos
);
872 // convert time to HH:MM:SS.F format
873 long tenths
= 10 * a_pos
;
874 int f1
= tenths
% 10;
875 int ss
= (tenths
/ 10) % 60;
876 int mm
= (tenths
/ 600) % 60;
877 int hh
= (tenths
/ 36000) % 100;
878 saddf(line
, &pos
, width
, "(");
880 saddf(line
, &pos
, width
, "%2d:", hh
);
881 if (hh
> 0 || mm
> 0)
882 saddf(line
, &pos
, width
, "%02d:", mm
);
883 saddf(line
, &pos
, width
, "%02d.", ss
);
884 saddf(line
, &pos
, width
, "%1d", f1
);
885 saddf(line
, &pos
, width
, ") ");
891 saddf(line
, &pos
, width
, "V:%6.1f ", sh_video
->pts
);
894 if (sh_audio
&& sh_video
)
895 saddf(line
, &pos
, width
, "A-V:%7.3f ct:%7.3f ", a_v
, corr
);
899 saddf(line
, &pos
, width
, "%3d/%3d ",
900 (int)sh_video
->num_frames
,
901 (int)sh_video
->num_frames_decoded
);
905 if (sh_video
->timer
> 0.5)
906 saddf(line
, &pos
, width
, "%2d%% %2d%% %4.1f%% ",
907 (int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
),
908 (int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
),
909 (100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
));
911 saddf(line
, &pos
, width
, "??%% ??%% ??,?%% ");
912 } else if (sh_audio
) {
913 if (sh_audio
->delay
> 0.5)
914 saddf(line
, &pos
, width
, "%4.1f%% ",
915 100.0*audio_time_usage
/(double)sh_audio
->delay
);
917 saddf(line
, &pos
, width
, "??,?%% ");
922 saddf(line
, &pos
, width
, "%d %d ", drop_frame_cnt
, output_quality
);
924 #ifdef USE_STREAM_CACHE
926 if (stream_cache_size
> 0)
927 saddf(line
, &pos
, width
, "%d%% ", cache_fill_status
);
931 if (playback_speed
!= 1)
932 saddf(line
, &pos
, width
, "%4.2fx ", playback_speed
);
935 memset(&line
[pos
], ' ', width
- pos
);
937 mp_msg(MSGT_AVSYNC
, MSGL_STATUS
, "%s\r", line
);
942 * \brief build a chain of audio filters that converts the input format
943 * to the ao's format, taking into account the current playback_speed.
944 * \param sh_audio describes the requested input format of the chain.
945 * \param ao_data describes the requested output format of the chain.
947 static int build_afilter_chain(sh_audio_t
*sh_audio
, ao_data_t
*ao_data
)
954 guiGetEvent(guiSetAfilter
, (char *)NULL
);
956 mixer
.afilter
= NULL
;
959 new_srate
= sh_audio
->samplerate
* playback_speed
;
960 if (new_srate
!= ao_data
->samplerate
) {
961 // limits are taken from libaf/af_resample.c
962 if (new_srate
< 8000)
964 if (new_srate
> 192000)
966 playback_speed
= (float)new_srate
/ (float)sh_audio
->samplerate
;
968 result
= init_audio_filters(sh_audio
, new_srate
,
969 sh_audio
->channels
, sh_audio
->sample_format
,
970 &ao_data
->samplerate
, &ao_data
->channels
, &ao_data
->format
,
971 ao_data
->outburst
* 4, ao_data
->buffersize
);
972 mixer
.afilter
= sh_audio
->afilter
;
974 guiGetEvent(guiSetAfilter
, (char *)sh_audio
->afilter
);
981 * \brief Log the currently displayed subtitle to a file
983 * Logs the current or last displayed subtitle together with filename
984 * and time information to ~/.mplayer/subtitle_log
986 * Intended purpose is to allow convenient marking of bogus subtitles
987 * which need to be fixed while watching the movie.
990 static void log_sub(){
995 if (subdata
== NULL
|| vo_sub_last
== NULL
) return;
996 fname
= get_path("subtitle_log");
997 f
= fopen(fname
, "a");
999 fprintf(f
, "----------------------------------------------------------\n");
1000 if (subdata
->sub_uses_time
) {
1001 fprintf(f
, "N: %s S: %02d:%02d:%02d.%02d E: %02d:%02d:%02d.%02d\n", filename
,
1002 vo_sub_last
->start
/360000, (vo_sub_last
->start
/6000)%60,
1003 (vo_sub_last
->start
/100)%60, vo_sub_last
->start
%100,
1004 vo_sub_last
->end
/360000, (vo_sub_last
->end
/6000)%60,
1005 (vo_sub_last
->end
/100)%60, vo_sub_last
->end
%100);
1007 fprintf(f
, "N: %s S: %d E: %d\n", filename
, vo_sub_last
->start
, vo_sub_last
->end
);
1009 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
1010 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
1016 int main(int argc
,char* argv
[]){
1021 static demux_stream_t
*d_audio
=NULL
;
1022 static demux_stream_t
*d_video
=NULL
;
1023 static demux_stream_t
*d_dvdsub
=NULL
;
1025 int file_format
=DEMUXER_TYPE_UNKNOWN
;
1027 int delay_corrected
=1;
1031 int osd_function
=OSD_PLAY
;
1032 int osd_last_pts
=-303;
1033 int osd_show_av_delay
= 0;
1034 int osd_show_text
= 0;
1035 int osd_show_speed
= 0;
1036 int osd_show_sub_delay
= 0;
1037 int osd_show_sub_pos
= 0;
1038 int osd_show_sub_visibility
= 0;
1039 int osd_show_sub_alignment
= 0;
1040 int osd_show_vobsub_changed
= 0;
1041 int osd_show_sub_changed
= 0;
1042 int osd_show_percentage
= 0;
1043 int osd_show_tv_channel
= 25;
1044 int osd_show_ontop
= 0;
1045 int osd_show_rootwin
= 0;
1046 int osd_show_framedropping
= 0;
1047 int osd_show_status
= 0;
1051 //float a_frame=0; // Audio
1056 int gui_no_filename
=0;
1059 srand((int) time(NULL
));
1064 mp_msg_set_level(MSGL_STATUS
);
1066 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2005 MPlayer Team\n");
1067 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
1068 GetCpuCaps(&gCpuCaps
);
1069 #if defined(ARCH_X86) || defined(ARCH_X86_64)
1070 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
1071 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
1072 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
1073 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
1074 #ifdef RUNTIME_CPUDETECT
1075 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
1077 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
1079 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
1082 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
1085 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
1088 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
1091 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
1094 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
1096 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n\n");
1100 #if defined(WIN32) && defined(USE_WIN32DLL)
1101 { /*make our codec dirs available for LoadLibraryA()*/
1102 char tmppath
[MAX_PATH
*2 + 1];
1103 char win32path
[MAX_PATH
];
1104 char realpath
[MAX_PATH
];
1106 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
1107 strcpy(tmppath
,win32path
);
1108 #ifdef USE_REALCODECS
1109 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
1110 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
1111 #endif /*USE_REALCODECS*/
1113 if(!strstr(WIN32_PATH
,":")){
1114 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
1115 strcpy(win32path
+ strlen(win32path
) - strlen("mplayer.exe"), WIN32_PATH
);
1117 else strcpy(win32path
,WIN32_PATH
);
1118 strcpy(tmppath
,win32path
);
1119 #ifdef USE_REALCODECS
1120 if(!strstr(REALCODEC_PATH
,":")){
1121 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
1122 strcpy(realpath
+ strlen(realpath
) - strlen("mplayer.exe"), REALCODEC_PATH
);
1124 else strcpy(realpath
,REALCODEC_PATH
);
1125 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
1126 #endif /*USE_REALCODECS*/
1127 #endif /*__CYGWIN__*/
1128 SetEnvironmentVariableA("PATH", tmppath
);
1130 #endif /*WIN32 && USE_WIN32DLL*/
1133 tv_param_immediate
= 1;
1137 if(!strcmp(argv
[0],"gmplayer") ||
1138 (strrchr(argv
[0],'/') && !strcmp(strrchr(argv
[0],'/'),"/gmplayer") ) )
1141 mconfig
= m_config_new();
1142 m_config_register_options(mconfig
,mplayer_opts
);
1143 // TODO : add something to let modules register their options
1144 mp_input_register_options(mconfig
);
1145 parse_cfgfiles(mconfig
);
1148 if ( use_gui
) cfg_read();
1151 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
1152 if(playtree
== NULL
)
1155 playtree
= play_tree_cleanup(playtree
);
1157 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
1159 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
1160 play_tree_iter_free(playtree_iter
);
1161 playtree_iter
= NULL
;
1163 filename
= play_tree_iter_get_file(playtree_iter
,1);
1170 for(i
=0; priority_presets_defs
[i
].name
; i
++){
1171 if(strcasecmp(priority_presets_defs
[i
].name
, proc_priority
) == 0)
1174 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,"Setting process priority: %s\n",
1175 priority_presets_defs
[i
].name
);
1176 SetPriorityClass(GetCurrentProcess(), priority_presets_defs
[i
].prio
);
1179 #ifndef HAVE_NEW_GUI
1181 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
1185 if(use_gui
&& !vo_init()){
1186 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
1189 if (use_gui
&& playtree_iter
){
1190 char cwd
[PATH_MAX
+2];
1191 // Remove Playtree and Playtree-Iter from memory as its not used by gui
1192 play_tree_iter_free(playtree_iter
);
1195 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
1198 // Prefix relative paths with current working directory
1199 play_tree_add_bpf(playtree
, cwd
);
1201 // Import initital playtree into gui
1202 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
1206 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
1208 exit_player_with_rc(NULL
, 0);
1211 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
1213 exit_player_with_rc(NULL
, 0);
1217 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
1218 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
1219 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
1220 if(!parse_codec_cfg(NULL
)){
1221 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
1222 exit_player_with_rc(NULL
, 0);
1224 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_BuiltinCodecsConf
);
1227 free( mem_ptr
); // release the buffer created by get_path()
1231 if(video_codec_list
){
1233 video_codec
=video_codec_list
[0];
1234 for(i
=0;video_codec_list
[i
];i
++)
1235 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
1238 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
1239 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
1241 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ID_AUDIO_CODECS\n");
1243 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
1244 exit_player_with_rc(NULL
, 0);
1246 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
1247 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
1249 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ID_VIDEO_CODECS\n");
1251 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
1252 exit_player_with_rc(NULL
, 0);
1254 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
1256 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
1257 exit_player_with_rc(NULL
, 0);
1259 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
1261 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
1262 exit_player_with_rc(NULL
, 0);
1264 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
1267 exit_player_with_rc(NULL
, 0);
1270 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
1272 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
1273 exit_player_with_rc(NULL
, 0);
1276 if((demuxer_name
&& strcmp(demuxer_name
,"help")==0) ||
1277 (audio_demuxer_name
&& strcmp(audio_demuxer_name
,"help")==0) ||
1278 (sub_demuxer_name
&& strcmp(sub_demuxer_name
,"help")==0)){
1280 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
1281 exit_player_with_rc(NULL
, 0);
1285 if (edl_check_mode() == EDL_ERROR
&& edl_filename
)
1287 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantUseBothModes
);
1289 } else if (edl_filename
)
1291 if (edl_records
) free_edl(edl_records
);
1292 next_edl_record
= edl_records
= edl_parse_file();
1293 } else if (edl_output_filename
)
1295 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
1297 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
1298 edl_output_filename
);
1306 // no file/vcd/dvd -> show HELP:
1307 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
1308 exit_player_with_rc(NULL
, 0);
1309 } else gui_no_filename
=1;
1312 // Many users forget to include command line in bugreports...
1314 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
1315 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_CPLAYER
, MSGL_INFO
," '%s'",argv
[i
]);
1316 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "\n");
1319 mp_msg_set_level(verbose
+MSGL_STATUS
);
1321 //------ load global data first ------
1325 #ifdef HAVE_FREETYPE
1328 #ifdef HAVE_FONTCONFIG
1329 if(!font_fontconfig
)
1333 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
1334 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
1337 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
1338 free(mem_ptr
); // release the buffer created by get_path()
1340 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
1342 #ifdef HAVE_FONTCONFIG
1351 // seteuid(0); /* Can't hurt to try to get root here */
1352 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
1353 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
1354 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
1356 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
1358 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
1359 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
1360 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
1363 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
1364 /* variable only by the root */
1365 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
1369 mp_msg(MSGT_CPLAYER
, MSGL_V
, MSGTR_UsingRTCTiming
, irqp
);
1373 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1374 // and now ? -- Pontscho
1375 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
1379 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Using %s timing\n",
1380 softsleep
?"software":timer_name
);
1383 if ( !use_gui
) load_termcap(NULL
); // load key-codes
1386 // ========== Init keyboard FIFO (connection to libvo) ============
1388 // Init input system
1389 current_module
= "init_input";
1392 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
1394 if(keyb_fifo_get
> 0)
1395 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
1397 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
1401 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
1403 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
1405 else if(!noconsolecontrols
)
1406 #ifndef HAVE_NO_POSIX_SELECT
1407 mp_input_add_key_fd(0,1,NULL
,NULL
);
1409 mp_input_add_key_fd(0,0,NULL
,NULL
);
1412 inited_flags
|=INITED_INPUT
;
1413 current_module
= NULL
;
1417 if(menu_cfg
&& menu_init(menu_cfg
))
1418 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
1420 menu_cfg
= get_path("menu.conf");
1421 if(menu_init(menu_cfg
))
1422 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
1424 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
1425 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
1427 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
1437 signal(SIGCHLD
,child_sighandler
);
1441 prog_path
= argv
[0];
1443 //========= Catch terminate signals: ================
1444 // terminate requests:
1445 signal(SIGTERM
,exit_sighandler
); // kill
1446 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
1448 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
1450 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
1451 signal(SIGPIPE
,exit_sighandler
); // Some window managers cause this
1452 #ifdef ENABLE_SIGHANDLER
1454 signal(SIGBUS
,exit_sighandler
); // bus error
1455 signal(SIGSEGV
,exit_sighandler
); // segfault
1456 signal(SIGILL
,exit_sighandler
); // illegal instruction
1457 signal(SIGFPE
,exit_sighandler
); // floating point exc.
1458 signal(SIGABRT
,exit_sighandler
); // abort()
1461 signal(SIGTRAP
,exit_sighandler
);
1468 inited_flags
|=INITED_GUI
;
1469 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
1473 // ******************* Now, let's see the per-file stuff ********************
1477 // init global sub numbers
1478 global_sub_size
= 0;
1479 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
1480 global_sub_quiet_osd_hack
= 1;
1482 if (filename
) load_per_file_config (mconfig
, filename
);
1484 // We must enable getch2 here to be able to interrupt network connection
1486 if(!noconsolecontrols
&& !slave_mode
){
1487 if(inited_flags
&INITED_GETCH2
)
1488 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
1490 getch2_enable(); // prepare stdin for hotkeys...
1491 inited_flags
|=INITED_GETCH2
;
1492 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
1495 // =================== GUI idle loop (STOP state) ===========================
1498 file_format
=DEMUXER_TYPE_UNKNOWN
;
1499 guiGetEvent( guiSetDefaults
,0 );
1500 while ( guiIntfStruct
.Playing
!= 1 )
1505 guiGetEvent( guiReDraw
,NULL
);
1506 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
1508 guiGetEvent( guiSetParameters
,NULL
);
1509 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
1511 play_tree_t
* entry
= play_tree_new();
1512 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
1513 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
1514 else playtree
=play_tree_new();
1515 play_tree_set_child( playtree
,entry
);
1518 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
1521 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
1523 play_tree_iter_free(playtree_iter
);
1524 playtree_iter
= NULL
;
1526 filename
= play_tree_iter_get_file(playtree_iter
,1);
1532 //---------------------------------------------------------------------------
1534 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
1536 //==================== Open VOB-Sub ============================
1538 current_module
="vobsub";
1540 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
1542 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
1543 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
1544 /* try to autodetect vobsub from movie filename ::atmos */
1545 char *buf
= malloc((strlen(filename
)-3) * sizeof(char));
1546 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
1547 strncpy(buf
, filename
, strlen(filename
)-4);
1548 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
1552 inited_flags
|=INITED_VOBSUB
;
1553 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
1554 // check if vobsub requested only to display forced subtitles
1555 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
1557 // setup global sub numbering
1558 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
1559 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
1562 //============ Open & Sync STREAM --- fork cache2 ====================
1567 //free_demuxer_stream(d_audio);
1571 //free_demuxer_stream(d_video);
1577 current_module
="open_stream";
1578 stream
=open_stream(filename
,0,&file_format
);
1579 if(!stream
) { // error...
1580 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
1581 goto goto_next_file
;
1583 inited_flags
|=INITED_STREAM
;
1586 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
1589 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
1592 current_module
="handle_playlist";
1593 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
1594 entry
= parse_playtree(stream
,0);
1595 eof
=playtree_add_playlist(entry
);
1596 goto goto_next_file
;
1598 stream
->start_pos
+=seek_to_byte
;
1600 if(stream_dump_type
==5){
1601 unsigned char buf
[4096];
1604 current_module
="dumpstream";
1605 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
1606 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
1607 exit_player(MSGTR_Exit_error
);
1609 stream_reset(stream
);
1610 stream_seek(stream
,stream
->start_pos
);
1611 f
=fopen(stream_dump_name
,"wb");
1613 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1614 exit_player(MSGTR_Exit_error
);
1616 while(!stream
->eof
){
1617 len
=stream_read(stream
,buf
,4096);
1619 if(fwrite(buf
,len
,1,f
) != 1) {
1620 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1621 exit_player(MSGTR_Exit_error
);
1626 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1627 exit_player(MSGTR_Exit_error
);
1629 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1630 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1634 if(stream
->type
==STREAMTYPE_DVD
){
1635 current_module
="dvd lang->id";
1636 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
1637 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
1638 // setup global sub numbering
1639 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
1640 global_sub_size
+= dvd_number_of_subs(stream
);
1641 current_module
=NULL
;
1646 if (stream
->type
==STREAMTYPE_DVDNAV
) stream_cache_size
=0; // must disable caching...
1649 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1650 #ifdef HAS_DVBIN_SUPPORT
1653 if(stream_cache_size
>0){
1654 current_module
="enable_cache";
1655 if(!stream_enable_cache(stream
,stream_cache_size
*1024,
1656 stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),
1657 stream_cache_size
*1024*(stream_cache_seek_min_percent
/ 100.0)))
1658 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
1661 //============ Open DEMUXERS --- DETECT file type =======================
1662 current_module
="demux_open";
1664 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
1666 // HACK to get MOV Reference Files working
1668 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
1670 unsigned char* playlist_entry
;
1671 play_tree_t
*list
= NULL
, *entry
= NULL
;
1673 current_module
="handle_demux_playlist";
1674 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
1678 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",playlist_entry
);
1680 bname
=mp_basename(playlist_entry
);
1681 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
1684 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
1687 entry
= play_tree_new();
1689 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
1691 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1)*sizeof(char));
1694 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
1695 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
1696 strcat(temp
, playlist_entry
);
1697 play_tree_add_file(entry
,temp
);
1698 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
1703 play_tree_add_file(entry
,playlist_entry
);
1708 play_tree_append_entry(list
,entry
);
1710 free_demuxer(demuxer
);
1715 entry
= play_tree_new();
1716 play_tree_set_child(entry
,list
);
1717 eof
=playtree_add_playlist(entry
);
1718 goto goto_next_file
;
1727 current_module
="handle_playlist";
1728 switch(stream
->type
){
1729 case STREAMTYPE_VCD
:
1730 case STREAMTYPE_DVD
:
1731 case STREAMTYPE_DVDNAV
:
1732 case STREAMTYPE_CDDA
:
1733 case STREAMTYPE_VCDBINCUE
:
1734 // don't try to parse raw media as playlist, it's unlikely
1735 goto goto_next_file
;
1737 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
1738 stream_reset(stream
);
1739 stream_seek(stream
,stream
->start_pos
);
1740 entry
= parse_playtree(stream
,0);
1742 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
1744 eof
=playtree_add_playlist(entry
);
1746 goto goto_next_file
;
1748 inited_flags
|=INITED_DEMUXER
;
1750 #ifdef HAVE_MATROSKA
1751 if (demuxer
->type
==DEMUXER_TYPE_MATROSKA
) {
1752 // setup global sub numbering
1753 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
1754 global_sub_size
+= demux_mkv_num_subs(demuxer
);
1757 #ifdef HAVE_OGGVORBIS
1758 if (demuxer
->type
==DEMUXER_TYPE_OGG
) {
1759 // setup global sub numbering
1760 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
1761 global_sub_size
+= demux_ogg_num_subs(demuxer
);
1765 current_module
="demux_open2";
1767 //file_format=demuxer->file_format;
1769 d_audio
=demuxer
->audio
;
1770 d_video
=demuxer
->video
;
1771 d_dvdsub
=demuxer
->sub
;
1774 if((stream_dump_type
)&&(stream_dump_type
<4)){
1776 demux_stream_t
*ds
=NULL
;
1777 current_module
="dump";
1778 // select stream to dump
1779 switch(stream_dump_type
){
1780 case 1: ds
=d_audio
;break;
1781 case 2: ds
=d_video
;break;
1782 case 3: ds
=d_dvdsub
;break;
1785 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
1786 exit_player(MSGTR_Exit_error
);
1788 // disable other streams:
1789 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
1790 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
1791 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
1793 f
=fopen(stream_dump_name
,"wb");
1795 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1796 exit_player(MSGTR_Exit_error
);
1799 unsigned char* start
;
1800 int in_size
=ds_get_packet(ds
,&start
);
1801 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
1802 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
1803 if(in_size
>0) fwrite(start
,in_size
,1,f
);
1806 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1807 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1810 sh_audio
=d_audio
->sh
;
1811 sh_video
=d_video
->sh
;
1815 current_module
="video_read_properties";
1816 if(!video_read_properties(sh_video
)) {
1817 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
1818 sh_video
=d_video
->sh
=NULL
;
1820 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1821 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
1822 sh_video
->fps
,sh_video
->frametime
1825 /* need to set fps here for output encoders to pick it up in their init */
1827 sh_video
->fps
=force_fps
;
1828 sh_video
->frametime
=1.0f
/sh_video
->fps
;
1830 vo_fps
= sh_video
->fps
;
1832 vo_mouse_timer_const
=(int)sh_video
->fps
;
1835 if(!sh_video
->fps
&& !force_fps
){
1836 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
1837 sh_video
=d_video
->sh
=NULL
;
1845 if(!sh_video
&& !sh_audio
){
1846 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
1847 #ifdef HAS_DVBIN_SUPPORT
1848 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
1850 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
1854 int v
= last_dvb_step
;
1856 dir
= DVB_CHANNEL_HIGHER
;
1858 dir
= DVB_CHANNEL_LOWER
;
1860 if(dvb_step_channel(priv
, dir
))
1862 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
1863 cache_uninit(stream
);
1864 goto goto_enable_cache
;
1869 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
1872 /* display clip info */
1873 demux_info_print(demuxer
);
1875 //================== Read SUBTITLES (DVD & TEXT) ==========================
1876 if(vo_spudec
==NULL
&& sh_video
&&
1877 (stream
->type
==STREAMTYPE_DVD
|| demuxer
->type
==DEMUXER_TYPE_MATROSKA
||
1878 d_dvdsub
->id
>= 0)){
1881 unsigned int palette
[16], width
, height
;
1882 current_module
="spudec_init_vobsub";
1883 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1884 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1888 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
1889 current_module
="spudec_init_dvdnav";
1890 vo_spudec
=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t
*)(stream
->priv
)),
1891 sh_video
->disp_w
, sh_video
->disp_h
);
1896 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
1897 current_module
="spudec_init_dvdread";
1898 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
1899 sh_video
->disp_w
, sh_video
->disp_h
);
1903 #ifdef HAVE_MATROSKA
1904 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1905 (d_dvdsub
->sh
!= NULL
) && (((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
1906 mkv_sh_sub_t
*mkv_sh_sub
= (mkv_sh_sub_t
*)d_dvdsub
->sh
;
1907 current_module
= "spudec_init_matroska";
1909 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1910 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1911 mkv_sh_sub
->height
);
1912 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1916 if (vo_spudec
==NULL
) {
1917 current_module
="spudec_init_normal";
1918 vo_spudec
=spudec_new_scaled(NULL
, sh_video
->disp_w
, sh_video
->disp_h
);
1919 spudec_set_font_factor(vo_spudec
,font_factor
);
1922 if (vo_spudec
!=NULL
)
1923 inited_flags
|=INITED_SPUDEC
;
1927 // Apply current settings for forced subs
1928 if (vo_spudec
!=NULL
)
1929 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
1933 // after reading video params we should load subtitles because
1934 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1936 current_module
="read_subtitles_file";
1938 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
1939 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
1941 if(sub_auto
) { // auto load sub file ...
1942 char *psub
= get_path( "sub/" );
1943 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
1945 free(psub
); // release the buffer created by get_path() above
1947 add_subtitles (tmp
[i
], sh_video
->fps
, 0);
1951 if (set_of_sub_size
== 0)
1953 add_subtitles (mem_ptr
=get_path("default.sub"), sh_video
->fps
, 1);
1954 free(mem_ptr
); // release the buffer created by get_path()
1957 if (set_of_sub_size
> 0) {
1958 // setup global sub numbering
1959 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
1960 global_sub_size
+= set_of_sub_size
;
1965 if (global_sub_size
) {
1966 // find the best sub to use
1967 if (vobsub_id
>= 0) {
1968 // if user asks for a vobsub id, use that first.
1969 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
1970 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
1971 // if user asks for a dvd sub id, use that next.
1972 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
1973 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
1974 // if there are text subs to use, use those. (autosubs come last here)
1975 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
1977 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1978 // if nothing else works, get subs from the demuxer.
1979 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1982 // nothing worth doing automatically.
1983 global_sub_pos
= -1;
1985 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1987 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1990 //================== Init AUDIO (codec) ==========================
1992 // Go through the codec.conf and find the best codec...
1993 current_module
="init_audio_codec";
1994 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1995 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
1996 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
1998 inited_flags
|=INITED_ACODEC
;
1999 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2003 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
2005 /* Assume FOURCC if all bytes >= 0x20 (' ') */
2006 if (sh_video
->format
>= 0x20202020)
2007 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", &sh_video
->format
);
2009 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
2010 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
2011 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
2012 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
2013 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
2014 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
2017 if (sh_audio
->codec
)
2018 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
2019 /* Assume FOURCC if all bytes >= 0x20 (' ') */
2020 if (sh_audio
->format
>= 0x20202020)
2021 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio
->format
);
2023 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
2024 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
2025 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
2026 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
2028 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer
));
2031 if(!sh_video
) goto main
; // audio-only
2033 //================== Init VIDEO (codec & libvo) ==========================
2034 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
2035 current_module
="preinit_libvo";
2038 //if((video_out->preinit(vo_subdevice))!=0){
2039 if(!(video_out
=init_best_video_out(video_driver_list
))){
2040 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
2041 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
2043 sh_video
->video_out
=video_out
;
2044 inited_flags
|=INITED_VO
;
2047 current_module
="init_video_filters";
2049 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
2050 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
2054 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
2055 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
2057 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
2062 sh_video
->vfilter
=(void*)append_filters(vf_menu
);
2065 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
2067 current_module
="init_video_codec";
2069 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2070 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
2071 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
2073 if(!sh_video
->inited
){
2074 if(!fixed_vo
) uninit_player(INITED_VO
);
2075 if(!sh_audio
) goto goto_next_file
;
2076 sh_video
= d_video
->sh
= NULL
;
2077 goto main
; // exit_player(MSGTR_Exit_error);
2080 inited_flags
|=INITED_VCODEC
;
2083 // Auto quality option enabled
2084 output_quality
=get_video_quality_max(sh_video
);
2085 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
2086 else output_quality
=auto_quality
;
2087 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
2088 set_video_quality(sh_video
,output_quality
);
2091 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
2093 current_module
="init_vo";
2095 if(vo_flags
& 0x08 && vo_spudec
)
2096 spudec_set_hw_spu(vo_spudec
,video_out
);
2098 #ifdef HAVE_FREETYPE
2099 force_load_font
= 1;
2102 //================== MAIN: ==========================
2104 current_module
="main";
2106 // If there is no video OSD has to be disabled.
2107 // In case of playing a playtree we have to restore the
2108 // old OSD level after playing one or more audio-only files.
2109 if(!sh_video
&& osd_level
>= 0) { // save OSD level only once
2110 osd_level_saved
= osd_level
;
2112 } else if (osd_level_saved
> -1) { // if there is a saved OSD level, restore it
2113 osd_level
= osd_level_saved
;
2114 osd_level_saved
= -1;
2122 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
2123 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
2124 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
2125 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
2126 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
2131 //int frame_corr_num=0; //
2132 //float v_frame=0; // Video
2133 float time_frame
=0; // Timer
2134 //float num_frames=0; // number of frames played
2136 char osd_text_buffer
[64];
2137 char osd_show_text_buffer
[64];
2138 int drop_frame
=0; // current dropping status
2139 int dropped_frames
=0; // how many frames dropped since last non-dropped frame
2140 int too_slow_frame_cnt
=0;
2141 int too_fast_frame_cnt
=0;
2142 // for auto-quality:
2143 float AV_delay
=0; // average of A-V timestamp differences
2144 double vdecode_time
;
2145 unsigned int lastframeout_ts
=0;
2146 /*float time_frame_corr_avg=0;*/ /* unused */
2148 float next_frame_time
=0;
2149 int frame_time_remaining
=0; // flag
2152 osd_text_buffer
[0]=0;
2154 //================ SETUP AUDIO ==========================
2157 //const ao_info_t *info=audio_out->info;
2158 current_module
="af_preinit";
2159 ao_data
.samplerate
=force_srate
;
2161 ao_data
.format
=audio_output_format
;
2163 // first init to detect best values
2164 if(!preinit_audio_filters(sh_audio
,
2166 (int)(sh_audio
->samplerate
*playback_speed
),
2167 sh_audio
->channels
, sh_audio
->sample_format
,
2169 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
)){
2170 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
2173 current_module
="ao2_init";
2174 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
2178 ao_data
.format
,0))){
2180 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
2181 uninit_player(INITED_ACODEC
); // close codec
2182 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
2185 inited_flags
|=INITED_AO
;
2186 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bps)\n",
2187 audio_out
->info
->short_name
,
2188 ao_data
.samplerate
, ao_data
.channels
,
2189 af_fmt2str_short(ao_data
.format
),
2190 af_fmt2bits(ao_data
.format
)/8 );
2191 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
2192 audio_out
->info
->name
, audio_out
->info
->author
);
2193 if(strlen(audio_out
->info
->comment
) > 0)
2194 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
2195 // init audio filters:
2197 current_module
="af_init";
2198 if(!build_afilter_chain(sh_audio
, &ao_data
)) {
2199 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
2200 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2201 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2202 // sh_audio=d_audio->sh=NULL; // -> nosound
2206 mixer
.audio_out
= audio_out
;
2207 mixer
.volstep
= volstep
;
2210 current_module
="av_init";
2212 if(sh_video
) sh_video
->timer
=0;
2213 if(sh_audio
) sh_audio
->delay
=-audio_delay
;
2216 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
2217 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks.\n",d_audio
->packs
);
2218 ds_free_packs(d_audio
); // free buffered chunks
2219 d_audio
->id
=-2; // do not read audio chunks
2220 //uninit_player(INITED_AO); // close device
2223 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
2224 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks.\n",d_video
->packs
);
2225 ds_free_packs(d_video
);
2227 //if(!fixed_vo) uninit_player(INITED_VO);
2230 if (!sh_video
&& !sh_audio
)
2231 goto goto_next_file
;
2233 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
2234 if(force_fps
&& sh_video
){
2235 vo_fps
= sh_video
->fps
=force_fps
;
2236 sh_video
->frametime
=1.0f
/sh_video
->fps
;
2237 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
2240 //==================== START PLAYING =======================
2242 if(loop_times
>1) loop_times
--; else
2243 if(loop_times
==1) loop_times
= -1;
2245 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
2248 if (stream
->type
==STREAMTYPE_DVDNAV
) {
2249 dvdnav_stream_fullstart((dvdnav_priv_t
*)stream
->priv
);
2253 total_time_usage_start
=GetTimer();
2254 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
2255 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
2256 play_n_frames
=play_n_frames_mf
;
2258 if(play_n_frames
==0){
2259 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
2263 float aq_sleep_time
=0;
2265 /*========================== PLAY AUDIO ============================*/
2272 current_module
="play_audio";
2274 ao_data
.pts
=((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
2275 playsize
=audio_out
->get_space();
2277 // handle audio-only case:
2278 if(playsize
< ao_data
.outburst
&&
2279 !sh_video
) { // buffer is full, do not block here!!!
2280 usec_sleep(10000); // Wait a tick before retry
2284 if(playsize
>MAX_OUTBURST
) playsize
=MAX_OUTBURST
; // we shouldn't exceed it!
2286 // Fill buffer if needed:
2287 current_module
="decode_audio"; // Enter AUDIO decoder module
2289 while(sh_audio
->a_out_buffer_len
<playsize
&& !d_audio
->eof
){
2290 int ret
=decode_audio(sh_audio
,&sh_audio
->a_out_buffer
[sh_audio
->a_out_buffer_len
],
2291 playsize
-sh_audio
->a_out_buffer_len
,sh_audio
->a_out_buffer_size
-sh_audio
->a_out_buffer_len
);
2292 if(ret
<=0) break; // EOF?
2293 sh_audio
->a_out_buffer_len
+=ret
;
2296 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2297 if(playsize
>sh_audio
->a_out_buffer_len
) playsize
=sh_audio
->a_out_buffer_len
;
2300 current_module
="play_audio";
2301 playsize
=audio_out
->play(sh_audio
->a_out_buffer
,playsize
,0);
2304 sh_audio
->a_out_buffer_len
-=playsize
;
2305 memmove(sh_audio
->a_out_buffer
,&sh_audio
->a_out_buffer
[playsize
],sh_audio
->a_out_buffer_len
);
2306 sh_audio
->delay
+=playback_speed
*playsize
/((float)((ao_data
.bps
&& sh_audio
->afilter
) ?
2307 ao_data
.bps
: sh_audio
->o_bps
));
2311 } // while(sh_audio)
2314 // handle audio-only case:
2316 float a_pos
= sh_audio
->delay
- audio_out
->get_delay() * playback_speed
;
2317 print_status(a_pos
, 0, 0);
2319 if(d_audio
->eof
) eof
= PT_NEXT_ENTRY
;
2323 /*========================== PLAY VIDEO ============================*/
2325 float frame_time
=next_frame_time
;
2327 vo_pts
=sh_video
->timer
*90000.0;
2328 vo_fps
=sh_video
->fps
;
2330 if(!frame_time_remaining
){
2331 //-------------------- Decode a frame: -----------------------
2332 vdecode_time
=video_time_usage
;
2334 { unsigned char* start
=NULL
;
2337 current_module
="video_read_frame";
2338 in_size
=video_read_frame(sh_video
,&next_frame_time
,&start
,force_fps
);
2339 if(in_size
<0){ eof
=1; break; }
2340 if(in_size
>max_framesize
) max_framesize
=in_size
; // stats
2341 sh_video
->timer
+=frame_time
;
2342 if(sh_audio
) sh_audio
->delay
-=frame_time
;
2343 time_frame
+=frame_time
; // for nosound
2344 // video_read_frame can change fps (e.g. for asf video)
2345 vo_fps
= sh_video
->fps
;
2347 vo_mouse_timer_const
= (int)sh_video
->fps
;
2349 // check for frame-drop:
2350 current_module
="check_framedrop";
2351 if(sh_audio
&& !d_audio
->eof
){
2352 float delay
=playback_speed
*audio_out
->get_delay();
2353 float d
=delay
-sh_audio
->delay
;
2354 // we should avoid dropping to many frames in sequence unless we
2355 // are too late. and we allow 100ms A-V delay here:
2356 if(d
<-dropped_frames
*frame_time
-0.100 && osd_function
!= OSD_PAUSE
){
2357 drop_frame
=frame_dropping
;
2361 drop_frame
=dropped_frames
=0;
2366 current_module
="decode_video";
2367 // printf("Decode! %p %d \n",start,in_size);
2368 blit_frame
=decode_video(sh_video
,start
,in_size
,drop_frame
);
2371 vdecode_time
=video_time_usage
-vdecode_time
;
2372 //------------------------ frame decoded. --------------------
2374 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
2376 if(sh_video
->vf_inited
<0){
2377 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_NotInitializeVOPorVO
);
2378 eof
=1; goto goto_next_file
;
2383 // ==========================================================================
2385 // current_module="draw_osd";
2386 // if(vo_config_count) video_out->draw_osd();
2389 if(use_gui
) guiEventHandling();
2392 current_module
="calc_sleep_time";
2395 { // debug frame dropping code
2396 float delay
=audio_out
->get_delay();
2397 mp_msg(MSGT_AVSYNC
,MSGL_V
,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2398 sh_video
->timer
,sh_audio
->timer
-delay
,
2399 sh_video
->timer
-(sh_audio
->timer
-delay
),
2404 if(drop_frame
&& !frame_time_remaining
&& !autosync
){
2406 * Note: time_frame should not be forced to 0 in autosync mode.
2407 * It is used as a cumulative counter to predict and correct the
2408 * delay measurements from the audio driver. time_frame is already
2409 * < 0, so the "time to sleep" code does not actually sleep. Also,
2410 * blit_frame is already 0 because drop_frame was true when
2411 * decode_video was called (which causes it to set blit_frame to 0.)
2412 * When autosync==0, the default behavior is still completely unchanged.
2415 time_frame
=0; // don't sleep!
2416 blit_frame
=0; // don't display!
2420 // It's time to sleep...
2422 frame_time_remaining
=0;
2423 time_frame
-=GetRelativeTime(); // reset timer
2425 if(sh_audio
&& !d_audio
->eof
){
2426 float delay
=playback_speed
*audio_out
->get_delay();
2427 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"delay=%f\n",delay
);
2431 * Adjust this raw delay value by calculating the expected
2432 * delay for this frame and generating a new value which is
2433 * weighted between the two. The higher autosync is, the
2434 * closer to the delay value gets to that which "-nosound"
2435 * would have used, and the longer it will take for A/V
2436 * sync to settle at the right value (but it eventually will.)
2437 * This settling time is very short for values below 100.
2439 float predicted
= sh_audio
->delay
+time_frame
;
2440 float difference
= delay
- predicted
;
2441 delay
= predicted
+ difference
/ (float)autosync
;
2444 time_frame
=delay
-sh_audio
->delay
;
2446 // delay = amount of audio buffered in soundcard/driver
2447 if(delay
>0.25) delay
=0.25; else
2448 if(delay
<0.10) delay
=0.10;
2449 if(time_frame
>delay
*0.6){
2450 // sleep time too big - may cause audio drops (buffer underrun)
2451 frame_time_remaining
=1;
2452 time_frame
=delay
*0.5;
2458 if( (time_frame
<-3*frame_time
|| time_frame
>3*frame_time
) || benchmark
)
2463 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2465 aq_sleep_time
+=time_frame
;
2469 //============================== SLEEP: ===================================
2471 time_frame
/=playback_speed
;
2473 // flag 256 means: libvo driver does its timing (dvb card)
2474 if(time_frame
>0.001 && !(vo_flags
&256)){
2478 // -------- RTC -----------
2479 current_module
="sleep_rtc";
2480 while (time_frame
> 0.000) {
2481 unsigned long rtc_ts
;
2482 if (read (rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
2483 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
2484 time_frame
-=GetRelativeTime();
2490 current_module
="sleep_darwin";
2491 while(time_frame
>0.005) {
2492 usec_sleep(1000000*time_frame
);
2493 time_frame
-=GetRelativeTime();
2498 // -------- TIMER + SOFTSLEEP -----------
2499 float min
=softsleep
?0.021:0.005;
2500 current_module
="sleep_timer";
2501 while(time_frame
>min
){
2502 if(time_frame
<=0.020)
2503 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2505 usec_sleep(1000000*(time_frame
-0.020));
2506 time_frame
-=GetRelativeTime();
2509 current_module
="sleep_soft";
2510 if(time_frame
<0) mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
2511 while(time_frame
>0) time_frame
-=GetRelativeTime(); // burn the CPU
2517 //if(!frame_time_remaining){ // should we display the frame now?
2519 //====================== FLIP PAGE (VIDEO BLT): =========================
2521 current_module
="vo_check_events";
2522 if(vo_config_count
) video_out
->check_events();
2524 current_module
="flip_page";
2525 if (!frame_time_remaining
) {
2527 unsigned int t2
=GetTimer();
2530 #define FRAME_LAG_WARN 0.2
2531 j
= ((float)t2
- lastframeout_ts
) / 1000000;
2532 lastframeout_ts
= GetTimer();
2533 if (j
< frame_time
+ frame_time
* -FRAME_LAG_WARN
)
2534 too_fast_frame_cnt
++;
2535 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2536 else if (j
> frame_time
+ frame_time
* FRAME_LAG_WARN
)
2537 too_slow_frame_cnt
++;
2538 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2540 if(vo_config_count
) video_out
->flip_page();
2541 if (play_n_frames
>= 0) {
2543 if (play_n_frames
< 0) eof
= PT_NEXT_ENTRY
;
2546 // usec_sleep(50000); // test only!
2549 vout_time_usage
+=tt
;
2552 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2553 otherwise A/V desync will occur. -- Alvieboy
2555 if (vo_config_count
)
2556 video_out
->control(VOCTRL_DUPLICATE_FRAME
, NULL
);
2559 //====================== A-V TIMESTAMP CORRECTION: =========================
2561 current_module
="av_sync";
2567 // unplayed bytes in our and soundcard/dma buffer:
2568 float delay
=playback_speed
*audio_out
->get_delay()+(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2572 * If autosync is enabled, the value for delay must be calculated
2573 * a bit differently. It is set only to the difference between
2574 * the audio and video timers. Any attempt to include the real
2575 * or corrected delay causes the pts_correction code below to
2576 * try to correct for the changes in delay which autosync is
2577 * trying to measure. This keeps the two from competing, but still
2578 * allows the code to correct for PTS drift *only*. (Using a delay
2579 * value here, even a "corrected" one, would be incompatible with
2582 delay
=sh_audio
->delay
;
2583 delay
+=(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2588 // PTS = sample_no / samplerate
2589 unsigned int samples
=
2590 // (sh_audio->audio.dwSampleSize)?
2591 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2592 ds_tell_block(d_audio
); // <- used for VBR audio
2593 samples
+=sh_audio
->audio
.dwStart
; // offset
2594 a_pts
=samples
*(float)sh_audio
->audio
.dwScale
/(float)sh_audio
->audio
.dwRate
;
2596 a_pts
-=(sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2600 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2602 if(!delay_corrected
) if(a_pts
) delay_corrected
=1;
2604 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2606 ds_tell_pts(d_audio
)/(float)sh_audio
->i_bps
,
2607 -sh_audio
->a_in_buffer_len
/(float)sh_audio
->i_bps
,
2608 a_pts
+(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
);
2610 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2612 v_pts
=sh_video
? sh_video
->pts
: d_video
->pts
;
2614 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"### A:%8.3f (%8.3f) V:%8.3f A-V:%7.4f \n",a_pts
,a_pts
-audio_delay
-delay
,v_pts
,(a_pts
-delay
-audio_delay
)-v_pts
);
2616 if(delay_corrected
){
2617 static int drop_message
=0;
2619 AV_delay
=(a_pts
-delay
-audio_delay
)-v_pts
;
2620 if(AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
2622 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
2625 if(x
<-max_pts_correction
) x
=-max_pts_correction
; else
2626 if(x
> max_pts_correction
) x
= max_pts_correction
;
2627 if(default_max_pts_correction
>=0)
2628 max_pts_correction
=default_max_pts_correction
;
2630 max_pts_correction
=sh_video
->frametime
*0.10; // +-10% of time
2631 if(!frame_time_remaining
){ sh_audio
->delay
+=x
; c_total
+=x
;} // correction
2633 print_status(a_pts
- audio_delay
- delay
, AV_delay
, c_total
);
2640 print_status(0, 0, 0);
2644 //============================ Auto QUALITY ============================
2646 /*Output quality adjustments:*/
2648 current_module
="autoq";
2649 // float total=0.000001f * (GetTimer()-aq_total_time);
2650 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2651 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
2654 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2655 if(output_quality
>1 && aq_sleep_time
<0)
2658 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
2660 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2661 set_video_quality(sh_video
,output_quality
);
2664 } // end if(sh_video)
2666 //============================ Handle PAUSE ===============================
2668 current_module
="pause";
2672 if (!--osd_visible
){
2673 vo_osd_progbar_type
=-1; // disable
2674 vo_osd_changed(OSDTYPE_PROGBAR
);
2675 if (osd_function
!= OSD_PAUSE
)
2676 osd_function
= OSD_PLAY
;
2681 if(osd_function
==OSD_PAUSE
){
2684 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2686 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ID_PAUSED\n");
2690 if(use_gui
) guiGetEvent( guiCEvent
,(char *)guiSetPause
);
2692 if (video_out
&& sh_video
&& vo_config_count
)
2693 video_out
->control(VOCTRL_PAUSE
, NULL
);
2695 if (audio_out
&& sh_audio
)
2696 audio_out
->pause(); // pause audio, keep data if possible
2698 while( (cmd
= mp_input_get_cmd(20,1,1)) == NULL
) {
2699 if(sh_video
&& video_out
&& vo_config_count
) video_out
->check_events();
2703 guiGetEvent( guiReDraw
,NULL
);
2704 if(guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
)) break;
2709 vf_menu_pause_update(vf_menu
);
2713 if (cmd
&& cmd
->id
== MP_CMD_PAUSE
) {
2714 cmd
= mp_input_get_cmd(0,1,0);
2717 osd_function
=OSD_PLAY
;
2718 if (audio_out
&& sh_audio
)
2719 audio_out
->resume(); // resume audio
2720 if (video_out
&& sh_video
&& vo_config_count
)
2721 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
2722 (void)GetRelativeTime(); // keep TF around FT in next cycle
2726 if ( guiIntfStruct
.Playing
== guiSetStop
) goto goto_next_file
;
2727 guiGetEvent( guiCEvent
,(char *)guiSetPlay
);
2734 osd_function
=OSD_FFW
;
2735 rel_seek_secs
+=step_sec
;
2739 if (stream
->type
==STREAMTYPE_DVDNAV
&& dvd_nav_still
)
2740 dvdnav_stream_sleeping((dvdnav_priv_t
*)stream
->priv
);
2743 //================= EDL =========================================
2746 if( next_edl_record
) { // Are we (still?) doing EDL?
2748 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
2749 free_edl(edl_records
);
2750 next_edl_record
= NULL
;
2753 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
2754 if( next_edl_record
->action
== EDL_SKIP
) {
2755 osd_function
= OSD_FFW
;
2757 rel_seek_secs
= next_edl_record
->length_sec
;
2758 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record
->start_sec
, next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2760 } else if( next_edl_record
->action
== EDL_MUTE
) {
2761 edl_muted
= !edl_muted
;
2762 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
2763 mp_msg(MSGT_CPLAYER
, MSGL_DBG4
, "EDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
2765 next_edl_record
=next_edl_record
->next
;
2771 //================= Keyboard events, SEEKing ====================
2773 current_module
="key_events";
2778 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
2780 case MP_CMD_SEEK
: {
2783 osd_show_percentage
= 25;
2784 v
= cmd
->args
[0].v
.f
;
2785 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2786 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
2789 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2792 else if(abs
) { /* Absolute seek by percentage */
2795 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2796 rel_seek_secs
= v
/100.0;
2800 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
2805 case MP_CMD_EDL_MARK
:
2807 float v
= sh_video
->pts
;
2808 fprintf( edl_fd
, "%f %f %d\n", v
-2, v
, 0 );
2812 case MP_CMD_SWITCH_RATIO
: {
2813 if (cmd
->nargs
== 0)
2814 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
2816 movie_aspect
= cmd
->args
[0].v
.f
;
2817 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
2819 case MP_CMD_AUDIO_DELAY
: {
2820 float v
= cmd
->args
[0].v
.f
;
2822 osd_show_av_delay
= 9;
2823 if(sh_audio
) sh_audio
->delay
+= v
;
2825 case MP_CMD_SPEED_INCR
: {
2826 float v
= cmd
->args
[0].v
.f
;
2827 playback_speed
+= v
;
2829 osd_show_speed
= sh_video
->fps
;
2830 build_afilter_chain(sh_audio
, &ao_data
);
2832 case MP_CMD_SPEED_MULT
: {
2833 float v
= cmd
->args
[0].v
.f
;
2834 playback_speed
*= v
;
2836 osd_show_speed
= sh_video
->fps
;
2837 build_afilter_chain(sh_audio
, &ao_data
);
2839 case MP_CMD_SPEED_SET
: {
2840 float v
= cmd
->args
[0].v
.f
;
2843 osd_show_speed
= sh_video
->fps
;
2844 build_afilter_chain(sh_audio
, &ao_data
);
2846 case MP_CMD_FRAME_STEP
:
2847 case MP_CMD_PAUSE
: {
2851 case MP_CMD_QUIT
: {
2852 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
2854 case MP_CMD_GRAB_FRAMES
: {
2857 case MP_CMD_PLAY_TREE_STEP
: {
2858 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
2859 int force
= cmd
->args
[1].v
.i
;
2868 for (i
=0;i
<-1*n
;i
++)
2873 if(!force
&& playtree_iter
) {
2874 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2876 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2877 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2878 play_tree_iter_free(i
);
2880 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2886 case MP_CMD_PLAY_TREE_UP_STEP
: {
2887 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
2888 int force
= cmd
->args
[1].v
.i
;
2890 if(!force
&& playtree_iter
) {
2891 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2892 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2893 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2894 play_tree_iter_free(i
);
2896 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2899 case MP_CMD_PLAY_ALT_SRC_STEP
: {
2900 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
2901 int v
= cmd
->args
[0].v
.i
;
2902 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
2904 else if(v
< 0 && playtree_iter
->file
> 1)
2909 case MP_CMD_SUB_DELAY
: {
2912 int abs
= cmd
->args
[1].v
.i
;
2913 float v
= cmd
->args
[0].v
.f
;
2918 osd_show_sub_delay
= 9; // show the subdelay in OSD
2922 case MP_CMD_SUB_STEP
: {
2925 int movement
= cmd
->args
[0].v
.i
;
2926 step_sub(subdata
, sh_video
->pts
, movement
);
2927 osd_show_sub_delay
= 9; // show the subdelay in OSD
2931 case MP_CMD_SUB_LOG
: {
2939 int v
= cmd
->args
[0].v
.i
;
2941 osd_level
=(osd_level
+1)%(MAX_OSD_LEVEL
+1);
2943 osd_level
= v
> MAX_OSD_LEVEL
? MAX_OSD_LEVEL
: v
;
2944 /* Show OSD state when disabled, but not when an explicit
2945 argument is given to the osd command, i.e. in slave mode. */
2946 if (v
== -1 && osd_level
<= 1)
2947 osd_show_status
= 9;
2951 case MP_CMD_OSD_SHOW_TEXT
: {
2953 if(osd_level
&& sh_video
){
2954 osd_show_text
=sh_video
->fps
; // 1 sec
2955 strncpy(osd_show_text_buffer
, cmd
->args
[0].v
.s
, 64);
2959 case MP_CMD_VOLUME
: {
2960 int v
= cmd
->args
[0].v
.i
;
2962 // start change for absolute volume value
2963 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2966 if (edl_muted
) break;
2971 mixer_setvolume(&mixer
, (float)v
, (float)v
);
2974 mixer_incvolume(&mixer
);
2976 mixer_decvolume(&mixer
);
2980 if(osd_level
&& sh_video
){
2982 osd_visible
=sh_video
->fps
; // 1 sec
2983 vo_osd_progbar_type
=OSD_VOLUME
;
2984 mixer_getbothvolume(&mixer
, &vol
);
2985 vo_osd_progbar_value
=(vol
*256.0)/100.0;
2986 vo_osd_changed(OSDTYPE_PROGBAR
);
2992 user_muted
= !user_muted
;
2993 if ((edl_muted
| user_muted
) != mixer
.muted
)
2997 case MP_CMD_LOADFILE
: {
2998 play_tree_t
* e
= play_tree_new();
2999 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
3001 // Go back to the start point
3002 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
3004 play_tree_free_list(playtree
->child
,1);
3005 play_tree_set_child(playtree
,e
);
3006 play_tree_iter_step(playtree_iter
,0,0);
3010 case MP_CMD_LOADLIST
: {
3011 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
3013 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
3015 // Go back to the start point
3016 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
3018 play_tree_free_list(playtree
->child
,1);
3019 play_tree_set_child(playtree
,e
);
3020 play_tree_iter_step(playtree_iter
,0,0);
3025 case MP_CMD_GAMMA
: {
3026 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
3031 if (vo_gamma_gamma
== 1000)
3034 get_video_colors (sh_video
, "gamma", &vo_gamma_gamma
);
3040 vo_gamma_gamma
+= v
;
3042 if (vo_gamma_gamma
> 100)
3043 vo_gamma_gamma
= 100;
3044 else if (vo_gamma_gamma
< -100)
3045 vo_gamma_gamma
= -100;
3046 set_video_colors(sh_video
, "gamma", vo_gamma_gamma
);
3049 osd_visible
=sh_video
->fps
; // 1 sec
3050 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
3051 vo_osd_progbar_value
=(vo_gamma_gamma
<<7)/100 + 128;
3052 vo_osd_changed(OSDTYPE_PROGBAR
);
3056 case MP_CMD_BRIGHTNESS
: {
3057 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
3062 if (vo_gamma_brightness
== 1000)
3064 vo_gamma_brightness
= 0;
3065 get_video_colors(sh_video
, "brightness", &vo_gamma_brightness
);
3069 vo_gamma_brightness
= v
;
3071 vo_gamma_brightness
+= v
;
3073 if (vo_gamma_brightness
> 100)
3074 vo_gamma_brightness
= 100;
3075 else if (vo_gamma_brightness
< -100)
3076 vo_gamma_brightness
= -100;
3077 if(set_video_colors(sh_video
, "brightness", vo_gamma_brightness
)){
3080 osd_visible
=sh_video
->fps
; // 1 sec
3081 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
3082 vo_osd_progbar_value
=(vo_gamma_brightness
<<7)/100 + 128;
3083 vo_osd_changed(OSDTYPE_PROGBAR
);
3088 case MP_CMD_CONTRAST
: {
3089 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
3094 if (vo_gamma_contrast
== 1000)
3096 vo_gamma_contrast
= 0;
3097 get_video_colors(sh_video
, "contrast", &vo_gamma_contrast
);
3101 vo_gamma_contrast
= v
;
3103 vo_gamma_contrast
+= v
;
3105 if (vo_gamma_contrast
> 100)
3106 vo_gamma_contrast
= 100;
3107 else if (vo_gamma_contrast
< -100)
3108 vo_gamma_contrast
= -100;
3109 if(set_video_colors(sh_video
, "contrast", vo_gamma_contrast
)){
3112 osd_visible
=sh_video
->fps
; // 1 sec
3113 vo_osd_progbar_type
=OSD_CONTRAST
;
3114 vo_osd_progbar_value
=(vo_gamma_contrast
<<7)/100 + 128;
3115 vo_osd_changed(OSDTYPE_PROGBAR
);
3120 case MP_CMD_SATURATION
: {
3121 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
3126 if (vo_gamma_saturation
== 1000)
3128 vo_gamma_saturation
= 0;
3129 get_video_colors(sh_video
, "saturation", &vo_gamma_saturation
);
3133 vo_gamma_saturation
= v
;
3135 vo_gamma_saturation
+= v
;
3137 if (vo_gamma_saturation
> 100)
3138 vo_gamma_saturation
= 100;
3139 else if (vo_gamma_saturation
< -100)
3140 vo_gamma_saturation
= -100;
3141 if(set_video_colors(sh_video
, "saturation", vo_gamma_saturation
)){
3144 osd_visible
=sh_video
->fps
; // 1 sec
3145 vo_osd_progbar_type
=OSD_SATURATION
;
3146 vo_osd_progbar_value
=(vo_gamma_saturation
<<7)/100 + 128;
3147 vo_osd_changed(OSDTYPE_PROGBAR
);
3153 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
3158 if (vo_gamma_hue
== 1000)
3161 get_video_colors(sh_video
, "hue", &vo_gamma_hue
);
3169 if (vo_gamma_hue
> 100)
3171 else if (vo_gamma_hue
< -100)
3172 vo_gamma_hue
= -100;
3173 if(set_video_colors(sh_video
, "hue", vo_gamma_hue
)){
3176 osd_visible
=sh_video
->fps
; // 1 sec
3177 vo_osd_progbar_type
=OSD_HUE
;
3178 vo_osd_progbar_value
=(vo_gamma_hue
<<7)/100 + 128;
3179 vo_osd_changed(OSDTYPE_PROGBAR
);
3184 case MP_CMD_FRAMEDROPPING
: {
3185 int v
= cmd
->args
[0].v
.i
;
3187 frame_dropping
= (frame_dropping
+1)%3;
3189 osd_show_framedropping
=10;
3190 vo_osd_changed(OSDTYPE_SUBTITLE
);
3194 frame_dropping
= v
> 2 ? 2 : v
;
3197 case MP_CMD_TV_SET_FREQ
: {
3198 if (file_format
== DEMUXER_TYPE_TV
)
3199 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
3201 case MP_CMD_TV_SET_NORM
: {
3202 if (file_format
== DEMUXER_TYPE_TV
)
3203 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
3205 case MP_CMD_TV_SET_BRIGHTNESS
: {
3206 if (file_format
== DEMUXER_TYPE_TV
)
3207 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_BRIGHTNESS
, cmd
->args
[0].v
.i
);
3209 case MP_CMD_TV_SET_HUE
: {
3210 if (file_format
== DEMUXER_TYPE_TV
)
3211 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_HUE
, cmd
->args
[0].v
.i
);
3213 case MP_CMD_TV_SET_SATURATION
: {
3214 if (file_format
== DEMUXER_TYPE_TV
)
3215 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_SATURATION
, cmd
->args
[0].v
.i
);
3217 case MP_CMD_TV_SET_CONTRAST
: {
3218 if (file_format
== DEMUXER_TYPE_TV
)
3219 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_CONTRAST
, cmd
->args
[0].v
.i
);
3221 case MP_CMD_TV_STEP_CHANNEL
: {
3222 if (file_format
== DEMUXER_TYPE_TV
) {
3223 int v
= cmd
->args
[0].v
.i
;
3225 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
3227 if (tv_channel_list
) {
3228 osd_show_tv_channel
= sh_video
->fps
;
3229 vo_osd_changed(OSDTYPE_SUBTITLE
);
3233 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
3235 if (tv_channel_list
) {
3236 osd_show_tv_channel
= sh_video
->fps
;
3237 vo_osd_changed(OSDTYPE_SUBTITLE
);
3243 #ifdef HAS_DVBIN_SUPPORT
3244 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
3246 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
3250 int v
= cmd
->args
[0].v
.i
;
3254 dir
= DVB_CHANNEL_HIGHER
;
3256 dir
= DVB_CHANNEL_LOWER
;
3259 if(dvb_step_channel(priv
, dir
))
3261 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
3262 cache_uninit(stream
);
3263 goto goto_enable_cache
;
3269 case MP_CMD_TV_SET_CHANNEL
: {
3270 if (file_format
== DEMUXER_TYPE_TV
) {
3271 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
3273 if (tv_channel_list
) {
3274 osd_show_tv_channel
= sh_video
->fps
;
3275 vo_osd_changed(OSDTYPE_SUBTITLE
);
3280 #ifdef HAS_DVBIN_SUPPORT
3281 case MP_CMD_DVB_SET_CHANNEL
:
3283 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
3285 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
3288 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
3293 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
3295 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
3296 cache_uninit(stream
);
3297 goto goto_enable_cache
;
3303 case MP_CMD_TV_LAST_CHANNEL
: {
3304 if (file_format
== DEMUXER_TYPE_TV
) {
3305 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
3307 if (tv_channel_list
) {
3308 osd_show_tv_channel
= sh_video
->fps
;
3309 vo_osd_changed(OSDTYPE_SUBTITLE
);
3314 case MP_CMD_TV_STEP_NORM
: {
3315 if (file_format
== DEMUXER_TYPE_TV
)
3316 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
3318 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
3319 if (file_format
== DEMUXER_TYPE_TV
)
3320 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
3323 case MP_CMD_SWITCH_VSYNC
: {
3324 vo_vsync
= ( cmd
->nargs
> 0 )? cmd
->args
[0].v
.i
: !vo_vsync
;
3326 case MP_CMD_VO_FULLSCREEN
:
3329 if ( use_gui
) guiGetEvent( guiIEvent
,(char *)MP_CMD_GUI_FULLSCREEN
);
3332 if(video_out
&& vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
3334 case MP_CMD_VO_ONTOP
:
3336 if(video_out
&& vo_config_count
) {
3337 video_out
->control(VOCTRL_ONTOP
, 0);
3340 vo_osd_changed(OSDTYPE_SUBTITLE
);
3345 case MP_CMD_VO_ROOTWIN
:
3347 if(video_out
&& vo_config_count
) {
3348 video_out
->control(VOCTRL_ROOTWIN
, 0);
3350 osd_show_rootwin
=10;
3351 vo_osd_changed(OSDTYPE_SUBTITLE
);
3356 case MP_CMD_PANSCAN
: {
3357 if ( !video_out
) break;
3358 if ( video_out
->control( VOCTRL_GET_PANSCAN
,NULL
) == VO_TRUE
)
3360 int abs
= cmd
->args
[1].v
.i
;
3361 float v
= cmd
->args
[0].v
.f
;
3364 else res
= vo_panscan
+v
;
3365 vo_panscan
= res
> 1 ? 1 : res
< 0 ? 0 : res
;
3366 video_out
->control( VOCTRL_SET_PANSCAN
,NULL
);
3368 if(osd_level
&& sh_video
){
3369 osd_visible
=sh_video
->fps
; // 1 sec
3370 vo_osd_progbar_type
=OSD_PANSCAN
;
3371 vo_osd_progbar_value
=vo_panscan
*256;
3372 vo_osd_changed(OSDTYPE_PROGBAR
);
3377 case MP_CMD_SUB_POS
:
3382 v
= cmd
->args
[0].v
.i
;
3385 if(sub_pos
>100) sub_pos
=100;
3386 if(sub_pos
<0) sub_pos
=0;
3387 vo_osd_changed(OSDTYPE_SUBTITLE
);
3388 osd_show_sub_pos
= 9;
3392 case MP_CMD_SUB_ALIGNMENT
:
3396 if (cmd
->nargs
>= 1)
3397 sub_alignment
= cmd
->args
[0].v
.i
;
3399 sub_alignment
= (sub_alignment
+1) % 3;
3400 osd_show_sub_alignment
= 9;
3401 vo_osd_changed(OSDTYPE_SUBTITLE
);
3405 case MP_CMD_SUB_VISIBILITY
:
3409 sub_visibility
=1-sub_visibility
;
3410 osd_show_sub_visibility
= 9; // show state of subtitle visibility in OSD
3411 vo_osd_changed(OSDTYPE_SUBTITLE
);
3415 case MP_CMD_SUB_LOAD
:
3419 int n
= set_of_sub_size
;
3420 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
3421 if (n
!= set_of_sub_size
) {
3422 if (global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
3423 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
;
3429 case MP_CMD_SUB_REMOVE
:
3433 int v
= cmd
->args
[0].v
.i
;
3436 for (v
= 0; v
< set_of_sub_size
; ++v
) {
3437 subd
= set_of_subtitles
[v
];
3438 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
3440 set_of_subtitles
[v
] = NULL
;
3442 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
3443 global_sub_size
-= set_of_sub_size
;
3444 set_of_sub_size
= 0;
3445 if (set_of_sub_pos
>= 0) {
3446 global_sub_pos
= -2;
3447 vo_sub_last
= vo_sub
= NULL
;
3448 vo_osd_changed(OSDTYPE_SUBTITLE
);
3449 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
3450 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3453 else if (v
< set_of_sub_size
) {
3454 subd
= set_of_subtitles
[v
];
3455 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
, MSGTR_RemovedSubtitleFile
, v
+ 1, subd
->filename
);
3457 if (set_of_sub_pos
== v
) {
3458 global_sub_pos
= -2;
3459 vo_sub_last
= vo_sub
= NULL
;
3460 vo_osd_changed(OSDTYPE_SUBTITLE
);
3461 vo_update_osd(sh_video
->disp_w
, sh_video
->disp_h
);
3462 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
3464 else if (set_of_sub_pos
> v
) {
3468 while (++v
< set_of_sub_size
)
3469 set_of_subtitles
[v
- 1] = set_of_subtitles
[v
];
3472 if (set_of_sub_size
<= 0)
3473 global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
3474 set_of_subtitles
[set_of_sub_size
] = NULL
;
3479 case MP_CMD_GET_SUB_VISIBILITY
:
3483 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_SUB_VISIBILITY=%ld\n", sub_visibility
);
3487 case MP_CMD_SUB_SELECT
:
3488 if (global_sub_size
) {
3490 int v
= cmd
->args
[0].v
.i
;
3496 if (global_sub_pos
>= global_sub_size
)
3497 global_sub_pos
= -1;
3498 if (global_sub_pos
>= 0)
3499 source
= sub_source();
3501 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3502 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
3503 global_sub_indices
[SUB_SOURCE_SUBS
], global_sub_indices
[SUB_SOURCE_DEMUX
],
3504 global_sub_pos
, source
);
3507 set_of_sub_pos
= -1;
3509 vo_sub_last
= vo_sub
= NULL
;
3513 if (d_dvdsub
) d_dvdsub
->id
= -1;
3516 // if sub_changed is till on but subdata's been reset, bad things happen.
3517 osd_show_vobsub_changed
= 0;
3518 osd_show_sub_changed
= 0;
3520 if (source
== SUB_SOURCE_VOBSUB
) {
3521 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
3522 if (!global_sub_quiet_osd_hack
) osd_show_vobsub_changed
= sh_video
->fps
;
3524 } else if (source
== SUB_SOURCE_SUBS
) {
3525 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
3526 subdata
= set_of_subtitles
[set_of_sub_pos
];
3527 if (!global_sub_quiet_osd_hack
) osd_show_sub_changed
= sh_video
->fps
;
3528 vo_osd_changed(OSDTYPE_SUBTITLE
);
3530 // FIXME: is this the correct place for these?
3531 if(stream_dump_type
==3) list_sub_file(subdata
);
3532 if(stream_dump_type
==4) dump_mpsub(subdata
, sh_video
->fps
);
3533 if(stream_dump_type
==6) dump_srt(subdata
, sh_video
->fps
);
3534 if(stream_dump_type
==7) dump_microdvd(subdata
, sh_video
->fps
);
3535 if(stream_dump_type
==8) dump_jacosub(subdata
, sh_video
->fps
);
3536 if(stream_dump_type
==9) dump_sami(subdata
, sh_video
->fps
);
3538 } else if (source
== SUB_SOURCE_DEMUX
) {
3539 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
3542 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
3543 d_dvdsub
->id
= dvdsub_id
;
3544 spudec_reset(vo_spudec
);
3547 #ifdef HAVE_OGGVORBIS
3548 if (demuxer
->type
== DEMUXER_TYPE_OGG
)
3549 d_dvdsub
->id
= demux_ogg_sub_id(demuxer
, dvdsub_id
);
3551 #ifdef HAVE_MATROSKA
3552 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
3553 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
3554 if (d_dvdsub
->id
>= 0 && ((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v') {
3555 mkv_sh_sub_t
*mkv_sh_sub
= (mkv_sh_sub_t
*)d_dvdsub
->sh
;
3556 if (vo_spudec
!= NULL
)
3557 spudec_free(vo_spudec
);
3559 spudec_new_scaled_vobsub(mkv_sh_sub
->has_palette
? mkv_sh_sub
->palette
: NULL
, mkv_sh_sub
->colors
,
3560 mkv_sh_sub
->custom_colors
,
3562 mkv_sh_sub
->height
);
3563 if (!forced_subs_only
)
3564 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
3566 spudec_set_forced_subs_only(vo_spudec
, forced_subs_only
);
3567 inited_flags
|= INITED_SPUDEC
;
3573 if (!global_sub_quiet_osd_hack
) osd_show_vobsub_changed
= sh_video
->fps
;
3575 if (!global_sub_quiet_osd_hack
) osd_show_vobsub_changed
= sh_video
->fps
;
3577 vo_osd_changed(OSDTYPE_SUBTITLE
);
3580 // it's annoying and dumb to show osd saying "off" at every subless file...
3581 global_sub_quiet_osd_hack
= 0;
3584 case MP_CMD_SUB_FORCED_ONLY
:
3586 forced_subs_only
= forced_subs_only
? 0 : ~0; // toggle state
3587 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3590 case MP_CMD_SCREENSHOT
:
3591 if(vo_config_count
) video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
3593 case MP_CMD_VF_CHANGE_RECTANGLE
:
3594 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
3597 case MP_CMD_GET_TIME_LENGTH
: {
3598 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer
));
3601 case MP_CMD_GET_VO_FULLSCREEN
: {
3602 if(video_out
&& vo_config_count
)
3603 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_VO_FULLSCREEN=%ld\n", vo_fs
);
3606 case MP_CMD_GET_PERCENT_POS
: {
3607 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer
));
3609 case MP_CMD_GET_TIME_POS
: {
3612 pos
= sh_video
->pts
;
3614 if (sh_audio
&& audio_out
)
3615 pos
= sh_audio
->delay
- audio_out
->get_delay() * playback_speed
;
3616 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
3618 case MP_CMD_SWITCH_AUDIO
: {
3619 int v
= demuxer_switch_audio(demuxer
, cmd
->args
[0].v
.i
);
3621 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", v
);
3626 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
3633 case MP_CMD_DVDNAV_EVENT
: {
3634 dvdnav_priv_t
* dvdnav_priv
= (dvdnav_priv_t
*)(stream
->priv
);
3635 dvdnav_event_t
* dvdnav_event
= (dvdnav_event_t
*)(cmd
->args
[0].v
.v
);
3637 /* ignore these events if we're not in dvd_nav mode */
3638 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3640 if (!dvdnav_event
) {
3641 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNullEvent
);
3645 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3647 switch (dvdnav_event
->event
) {
3648 case DVDNAV_BLOCK_OK
: {
3649 /* be silent about this one */
3652 case DVDNAV_HIGHLIGHT
: {
3653 dvdnav_highlight_event_t
*hevent
= (dvdnav_highlight_event_t
*)(dvdnav_event
->details
);
3655 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavHighlightEventBroken
);
3659 if (hevent
->display
&& hevent
->buttonN
>0)
3661 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3662 sprintf( dvd_nav_text
, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3664 hevent
->sx
,hevent
->sy
,
3665 hevent
->ex
,hevent
->ey
,
3666 hevent
->pts
, d_video
->pts
);
3667 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavEvent
,dvd_nav_text
);
3668 //osd_show_dvd_nav_delay = 60;
3670 osd_show_dvd_nav_highlight
=1;
3671 osd_show_dvd_nav_sx
=hevent
->sx
;
3672 osd_show_dvd_nav_ex
=hevent
->ex
;
3673 osd_show_dvd_nav_sy
=hevent
->sy
;
3674 osd_show_dvd_nav_ey
=hevent
->ey
;
3677 osd_show_dvd_nav_highlight
=0;
3678 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavHighlightHide
);
3682 case DVDNAV_STILL_FRAME
: {
3683 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*)(dvdnav_event
->details
);
3685 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavStillFrame
, still_event
->length
);
3686 while (dvdnav_stream_sleeping(dvdnav_priv
)) {
3687 usec_sleep(1000); /* 1ms */
3689 dvdnav_stream_sleep(dvdnav_priv
,still_event
->length
);
3693 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavStop
);
3697 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavNOP
);
3700 case DVDNAV_SPU_STREAM_CHANGE
: {
3701 #if DVDNAVVERSION > 012
3702 dvdnav_spu_stream_change_event_t
*stream_change
= (dvdnav_spu_stream_change_event_t
*)(dvdnav_event
->details
);
3704 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuStreamChangeVerbose
,
3705 stream_change
->physical_wide
,
3706 stream_change
->physical_letterbox
,
3707 stream_change
->physical_pan_scan
,
3708 stream_change
->logical
);
3710 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical_wide
) {
3711 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3712 d_dvdsub
->id
,stream_change
->physical_wide
);
3713 // FIXME: need a better way to change SPU id
3714 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical_wide
;
3715 if (vo_spudec
) spudec_reset(vo_spudec
);
3718 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3720 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuStreamChange
,
3721 stream_change
->physical
,
3722 stream_change
->logical
);
3724 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical
) {
3725 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3726 d_dvdsub
->id
,stream_change
->physical
);
3727 // FIXME: need a better way to change SPU id
3728 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical
;
3729 if (vo_spudec
) spudec_reset(vo_spudec
);
3734 case DVDNAV_AUDIO_STREAM_CHANGE
: {
3736 #if DVDNAVVERSION > 012
3737 dvdnav_audio_stream_change_event_t
*stream_change
= (dvdnav_audio_stream_change_event_t
*)(dvdnav_event
->details
);
3739 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3742 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavAudioStreamChange
,
3743 stream_change
->physical
,
3744 stream_change
->logical
);
3746 aid_temp
=stream_change
->physical
;
3747 if (aid_temp
>=0) aid_temp
+=128; // FIXME: is this sane?
3748 if (d_audio
&& audio_id
!=aid_temp
) {
3749 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_audio->id change: was %d is now %d\n",
3750 d_audio
->id
,aid_temp
);
3751 // FIXME: need a bettery way to change audio stream id
3752 d_audio
->id
=dvdsub_id
=aid_temp
;
3753 if(sh_audio
) resync_audio_stream(sh_audio
);
3758 case DVDNAV_VTS_CHANGE
: {
3759 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavVTSChange
);
3762 case DVDNAV_CELL_CHANGE
: {
3763 dvdnav_cell_change_event_t
*cell_change
= (dvdnav_cell_change_event_t
*)(dvdnav_event
->details
);
3764 cell_playback_t
* cell_playback
= cell_change
->new_cell
;
3766 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavCellChange
);
3767 osd_show_dvd_nav_highlight
=0; /* screen changed, disable menu */
3769 printf("new still time: %d\n",cell_playback->still_time);
3770 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3771 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3772 cell_playback->playback_time.hour,
3773 cell_playback->playback_time.minute,
3774 cell_playback->playback_time.second,
3775 cell_playback->playback_time.frame_u);
3778 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3782 case DVDNAV_NAV_PACKET
: {
3783 // printf("DVDNAV Event: Nav Packet\n");
3786 case DVDNAV_SPU_CLUT_CHANGE
: {
3787 uint32_t * new_clut
= (uint32_t *)(dvdnav_event
->details
);
3789 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuClutChange
);
3790 // send new palette to SPU decoder
3791 if (vo_spudec
) spudec_update_palette(vo_spudec
,new_clut
);
3795 case DVDNAV_SEEK_DONE
: {
3796 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSeekDone
);
3801 // free the dvdnav event
3802 free(dvdnav_event
->details
);
3804 cmd
->args
[0].v
.v
=NULL
;
3806 case MP_CMD_DVDNAV
: {
3807 dvdnav_priv_t
* dvdnav_priv
=(dvdnav_priv_t
*)stream
->priv
;
3809 /* ignore these events if we're not in dvd_nav mode */
3810 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3812 switch (cmd
->args
[0].v
.i
) {
3813 case MP_CMD_DVDNAV_UP
:
3814 dvdnav_upper_button_select(dvdnav_priv
->dvdnav
);
3816 case MP_CMD_DVDNAV_DOWN
:
3817 dvdnav_lower_button_select(dvdnav_priv
->dvdnav
);
3819 case MP_CMD_DVDNAV_LEFT
:
3820 dvdnav_left_button_select(dvdnav_priv
->dvdnav
);
3822 case MP_CMD_DVDNAV_RIGHT
:
3823 dvdnav_right_button_select(dvdnav_priv
->dvdnav
);
3825 case MP_CMD_DVDNAV_MENU
:
3826 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_MenuCall
);
3827 dvdnav_menu_call(dvdnav_priv
->dvdnav
,DVD_MENU_Root
);
3829 case MP_CMD_DVDNAV_SELECT
:
3830 dvdnav_button_activate(dvdnav_priv
->dvdnav
);
3833 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Weird DVD Nav cmd %d\n",cmd
->args
[0].v
.i
);
3841 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3844 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
3848 osd_function
= OSD_PAUSE
;
3856 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
3857 rel_seek_secs
+= 3600*a
+60*b
+d
;
3858 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
3859 rel_seek_secs
+= 60*a
+d
;
3860 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
3867 if(eof
==1 && loop_times
>=0) {
3869 play_tree_iter_step(playtree_iter
,0,0);
3871 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
3873 if(loop_times
>1) loop_times
--; else
3874 if(loop_times
==1) loop_times
=-1;
3875 play_n_frames
=play_n_frames_mf
;
3877 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
3881 if(rel_seek_secs
|| abs_seek_pos
){
3882 current_module
="seek";
3883 if(demux_seek(demuxer
,rel_seek_secs
,abs_seek_pos
)){
3885 /* FIXME there should be real seeking for vobsub */
3886 if(sh_video
) sh_video
->pts
=d_video
->pts
;
3888 //vobsub_reset(vo_vobsub);
3889 vobsub_seek(vo_vobsub
,sh_video
->pts
);
3891 if(sh_video
&& d_video
->packs
== 0)
3892 ds_fill_buffer(d_video
);
3894 if(d_audio
->packs
== 0)
3895 ds_fill_buffer(d_audio
);
3897 float a_pts
=d_audio
->pts
;
3898 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
3899 mp_msg(MSGT_AVSYNC
,MSGL_V
,"SEEK: A: %5.3f V: %5.3f A-V: %5.3f \n",a_pts
,d_video
->pts
,a_pts
-d_video
->pts
);
3901 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A:%6.1f V:%6.1f A-V:%7.3f ct: ? \r",d_audio
->pts
,d_video
->pts
,0.0f
);
3903 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A: --- V:%6.1f \r",d_video
->pts
);
3909 current_module
="seek_video_reset";
3910 resync_video_stream(sh_video
);
3911 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
3915 current_module
="seek_audio_reset";
3916 audio_out
->reset(); // stop audio, throwing away buffered data
3920 if(osd_level
&& !loop_seek
){
3922 if( !edl_decision
) {
3924 if( 1 ) { // Let the compiler optimize this out
3927 osd_visible
=sh_video
->fps
; // 1 sec
3928 vo_osd_progbar_type
=0;
3929 vo_osd_progbar_value
=demuxer_get_percent_pos(demuxer
) * 256 / 100;
3930 vo_osd_changed(OSDTYPE_PROGBAR
);
3937 max_pts_correction
=0.1;
3938 osd_visible
=sh_video
->fps
; // to rewert to PLAY pointer after 1 sec
3939 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3941 too_slow_frame_cnt
=0;
3942 too_fast_frame_cnt
=0;
3944 if(vo_spudec
) spudec_reset(vo_spudec
);
3949 * We saw a seek, have to rewind the EDL operations stack
3950 * and find the next EDL action to take care of.
3954 next_edl_record
= edl_records
;
3956 while (next_edl_record
)
3958 /* Trying to remember if we need to mute/unmute first;
3959 * prior EDL implementation lacks this.
3962 if (next_edl_record
->start_sec
>= sh_video
->pts
)
3965 if (next_edl_record
->action
== EDL_MUTE
) edl_muted
= !edl_muted
;
3966 next_edl_record
= next_edl_record
->next
;
3969 if ((user_muted
| edl_muted
) != mixer
.muted
) mixer_mute(&mixer
);
3973 frame_time_remaining
=0;
3974 current_module
=NULL
;
3981 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
3982 // get pos from frame number / total frames
3983 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
3985 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
3986 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
3987 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
3989 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
3990 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
3991 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
3992 guiGetEvent( guiReDraw
,NULL
);
3993 guiGetEvent( guiSetVolume
,NULL
);
3994 if(guiIntfStruct
.Playing
==0) break; // STOP
3995 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
3996 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3998 if ( stream
->type
== STREAMTYPE_DVD
)
4000 dvd_priv_t
* dvdp
= stream
->priv
;
4001 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
4008 //================= Update OSD ====================
4010 if(osd_level
>=1 && sh_video
){
4011 int pts
=sh_video
->pts
;
4012 char osd_text_tmp
[64];
4013 if(pts
==osd_last_pts
-1) ++pts
; else osd_last_pts
=pts
;
4014 vo_osd_text
=osd_text_buffer
;
4016 if (osd_show_dvd_nav_delay
) {
4017 snprintf(osd_text_tmp
, 63, "DVDNAV: %s", dvd_nav_text
);
4018 osd_show_dvd_nav_delay
--;
4022 if (osd_show_tv_channel
&& tv_channel_list
) {
4023 snprintf(osd_text_tmp
, 63, "Channel: %s", tv_channel_current
->name
);
4024 osd_show_tv_channel
--;
4027 if (osd_show_text
) {
4028 snprintf(osd_text_tmp
, 63, "%s", osd_show_text_buffer
);
4031 if (osd_show_sub_visibility
) {
4032 snprintf(osd_text_tmp
, 63, "Subtitles: %sabled", sub_visibility
?"en":"dis");
4033 osd_show_sub_visibility
--;
4035 if (osd_show_vobsub_changed
) {
4036 snprintf(osd_text_tmp
, 63, "Subtitles: off");
4037 if (vo_vobsub
&& vobsub_id
>= 0) {
4038 const char *language
= "none";
4039 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
4040 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", vobsub_id
, language
? language
: "unknown");
4042 #ifdef HAVE_OGGVORBIS
4043 if (d_dvdsub
&& demuxer
->type
== DEMUXER_TYPE_OGG
) {
4044 if (dvdsub_id
>= 0) {
4045 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
4046 if (!lang
) lang
= "unknown";
4047 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", dvdsub_id
, lang
);
4052 if (vo_spudec
&& (demuxer
->type
!= DEMUXER_TYPE_MATROSKA
)) {
4053 if (dvdsub_id
>= 0) {
4054 char lang
[5] = "none";
4056 code
= dvd_lang_from_sid(stream
, dvdsub_id
);
4058 lang
[0] = code
>> 8;
4062 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", dvdsub_id
, lang
);
4066 #ifdef HAVE_MATROSKA
4067 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
4068 char lang
[10] = "unknown";
4069 if (dvdsub_id
>= 0) {
4070 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
4072 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", dvdsub_id
, lang
);
4076 osd_show_vobsub_changed
--;
4079 if (osd_show_sub_changed
) {
4081 tmp
= subdata
->filename
;
4082 if ((tmp2
= strrchr(tmp
, '/'))) {
4085 snprintf(osd_text_tmp
, 63, "Sub: (%d) %s%s",
4087 strlen(tmp
) < 20 ? "" : "...",
4088 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
4089 osd_show_sub_changed
--;
4092 if (osd_show_sub_delay
) {
4093 snprintf(osd_text_tmp
, 63, "Sub delay: %d ms", ROUND(sub_delay
*1000));
4094 osd_show_sub_delay
--;
4096 if (osd_show_sub_pos
) {
4097 snprintf(osd_text_tmp
, 63, "Sub position: %d/100", sub_pos
);
4100 if (osd_show_sub_alignment
) {
4101 snprintf(osd_text_tmp
, 63, "Sub alignment: %s",
4102 (sub_alignment
== 2 ? "bottom" :
4103 (sub_alignment
== 1 ? "center" : "top")));
4104 osd_show_sub_alignment
--;
4106 if (osd_show_av_delay
) {
4107 snprintf(osd_text_tmp
, 63, "A-V delay: %d ms", ROUND(audio_delay
*1000));
4108 osd_show_av_delay
--;
4109 } else if (osd_show_speed
) {
4110 snprintf(osd_text_tmp
, 63, "Speed: x %6.2f", playback_speed
);
4112 } else if (osd_show_ontop
) {
4113 snprintf(osd_text_tmp
, 63, "Stay on top: %sabled", vo_ontop
?"en":"dis");
4115 } else if (osd_show_rootwin
) {
4116 snprintf(osd_text_tmp
, 63, "Rootwin: %sabled", vo_rootwin
?"en":"dis");
4118 } else if (osd_show_framedropping
) {
4119 snprintf(osd_text_tmp
, 63, "Framedropping: %s",
4120 (frame_dropping
== 1 ? "on" :
4121 (frame_dropping
== 2 ? "hard" : "off")));
4122 osd_show_framedropping
--;
4123 } else if(osd_level
>=2) {
4124 int len
= demuxer_get_time_length(demuxer
);
4125 int percentage
= -1;
4126 char percentage_text
[10];
4127 if (osd_show_percentage
) {
4128 percentage
= demuxer_get_percent_pos(demuxer
);
4129 osd_show_percentage
--;
4131 if (percentage
>= 0)
4132 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
4134 percentage_text
[0] = 0;
4136 snprintf(osd_text_tmp
, 63, "%c %02d:%02d:%02d / %02d:%02d:%02d%s",osd_function
,pts
/3600,(pts
/60)%60,pts
%60,len
/3600,(len
/60)%60,len
%60,percentage_text
);
4138 snprintf(osd_text_tmp
, 63, "%c %02d:%02d:%02d%s",osd_function
,pts
/3600,(pts
/60)%60,pts
%60,percentage_text
);
4139 } else osd_text_tmp
[0]=0;
4141 if(strcmp(vo_osd_text
, osd_text_tmp
)) {
4142 strncpy(vo_osd_text
, osd_text_tmp
, 63);
4143 vo_osd_changed(OSDTYPE_OSD
);
4148 vo_osd_changed(OSDTYPE_OSD
);
4151 if (osd_level
<= 1 && osd_show_status
> 0 && sh_video
) {
4152 vo_osd_text
= osd_text_buffer
;
4153 snprintf(vo_osd_text
, 63, "OSD: %sabled", osd_level
? "en" : "dis");
4154 vo_osd_changed(OSDTYPE_OSD
);
4157 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
4158 // vo_osd_text=osd_text_buffer;
4163 if(subdata
&& sh_video
&& sh_video
->pts
>0){
4164 float pts
=sh_video
->pts
;
4165 if(sub_fps
==0) sub_fps
=sh_video
->fps
;
4166 current_module
="find_sub";
4167 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0 ) {
4168 find_sub(subdata
, (pts
+sub_delay
) *
4169 (subdata
->sub_uses_time
? 100. : sub_fps
));
4170 if (vo_sub
) vo_sub_last
= vo_sub
;
4171 // FIXME! frame counter...
4174 current_module
=NULL
;
4179 if (stop_xscreensaver
&& sh_video
) {
4180 current_module
="stop_xscreensaver";
4181 xscreensaver_heartbeat();
4182 current_module
=NULL
;
4187 if(vo_config_count
&& vo_spudec
) {
4188 unsigned char* packet
=NULL
;
4190 current_module
="spudec";
4191 spudec_heartbeat(vo_spudec
,90000*sh_video
->timer
);
4192 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
4197 if(sh_video
->pts
+sub_delay
>=0) {
4198 // The + next_frame_time is there because we'll display the sub at the next frame
4199 len
= vobsub_get_packet(vo_vobsub
,sh_video
->pts
+sub_delay
+next_frame_time
,(void**)&packet
,×tamp
);
4201 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
4202 mp_dbg(MSGT_CPLAYER
,MSGL_V
,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len
,sh_video
->pts
,sh_video
->timer
,timestamp
/ 90000.0,timestamp
);
4207 len
= ds_get_packet_sub(d_dvdsub
,(unsigned char**)&packet
);
4209 float x
= d_dvdsub
->pts
- sh_video
->pts
;
4210 if (x
< -10 || x
> 10) // prevent missing subs on pts reset
4211 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
+ sub_delay
- sh_video
->pts
);
4212 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
4213 mp_dbg(MSGT_CPLAYER
,MSGL_V
,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f ts=%d \n",len
,sh_video
->pts
,d_dvdsub
->pts
,timestamp
);
4216 if(len
<=0 || !packet
) break;
4217 if(timestamp
< 0) timestamp
= 0;
4218 else spudec_assemble(vo_spudec
,packet
,len
,timestamp
);
4221 /* detect wether the sub has changed or not */
4222 if(spudec_changed(vo_spudec
))
4223 vo_osd_changed(OSDTYPE_SPU
);
4224 current_module
=NULL
;
4229 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
4233 goto_next_file
: // don't jump here after ao/vo/getch initialization!
4235 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
4238 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
4239 double total_time_usage
;
4240 total_time_usage_start
=GetTimer()-total_time_usage_start
;
4241 total_time_usage
= (float)total_time_usage_start
*0.000001;
4242 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
4243 video_time_usage
,vout_time_usage
,audio_time_usage
,
4244 total_time_usage
-tot
,total_time_usage
);
4245 if(total_time_usage
>0.0)
4246 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
4247 100.0*video_time_usage
/total_time_usage
,
4248 100.0*vout_time_usage
/total_time_usage
,
4249 100.0*audio_time_usage
/total_time_usage
,
4250 100.0*(total_time_usage
-tot
)/total_time_usage
,
4252 if(total_frame_cnt
&& frame_dropping
)
4253 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
4254 total_frame_cnt
-drop_frame_cnt
,
4255 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
4257 100*drop_frame_cnt
/total_frame_cnt
,
4259 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
4263 // time to uninit all, except global stuff:
4264 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
4267 if ( set_of_sub_size
> 0 )
4269 current_module
="sub_free";
4270 for (i
= 0; i
< set_of_sub_size
; ++i
)
4271 sub_free( set_of_subtitles
[i
] );
4272 set_of_sub_size
= 0;
4273 vo_sub_last
= vo_sub
=NULL
;
4278 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
4279 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
4280 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
4283 play_tree_iter_free(playtree_iter
);
4284 playtree_iter
= NULL
;
4287 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
4288 eof
= eof
== PT_UP_NEXT
? 1 : -1;
4289 if ( playtree_iter
) {
4290 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
4293 play_tree_iter_free(playtree_iter
);
4294 playtree_iter
= NULL
;
4297 } else { // NEXT PREV SRC
4298 eof
= eof
== PT_PREV_SRC
? -1 : 1;
4301 if(eof
== 0) eof
= 1;
4303 while(playtree_iter
!= NULL
) {
4304 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
4305 if(filename
== NULL
) {
4306 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
4307 play_tree_iter_free(playtree_iter
);
4308 playtree_iter
= NULL
;
4315 if( use_gui
&& !playtree_iter
)
4318 if ( !guiIntfStruct
.DiskChanged
)
4324 if(use_gui
|| playtree_iter
!= NULL
){
4327 goto play_next_file
;
4331 exit_player_with_rc(MSGTR_Exit_eof
, 0);