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 extern int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
);
39 #define HELP_MP_DEFINE_STATIC
45 #include "cfg-mplayer-def.h"
48 #include "subreader.h"
51 #include "libvo/video_out.h"
53 #include "libvo/font_load.h"
54 #include "libvo/sub.h"
57 #include "libvo/x11_common.h"
60 #include "libao2/audio_out.h"
61 #include "libao2/audio_plugin.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"
92 #define ABS(x) (((x)>=0)?(x):(-(x)))
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
96 #include <linux/rtc.h>
100 #include "libmpdemux/tv.h"
103 #ifdef HAS_DVBIN_SUPPORT
104 #include "libmpdemux/dvbin.h"
105 static int last_dvb_step
= 1;
109 #include "libmpdemux/matroska.h"
112 //**************************************************************************//
114 //**************************************************************************//
115 #include "playtree.h"
116 #include "playtreeparser.h"
119 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
120 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
123 play_tree_t
* playtree
;
124 play_tree_iter_t
* playtree_iter
= NULL
;
126 #define PT_NEXT_ENTRY 1
127 #define PT_PREV_ENTRY -1
128 #define PT_NEXT_SRC 2
129 #define PT_PREV_SRC -2
131 #define PT_UP_PREV -3
133 //**************************************************************************//
135 //**************************************************************************//
139 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
);
141 m_config_parse_config_file(m_config_t
* config
, char *conffile
);
143 //**************************************************************************//
145 //**************************************************************************//
147 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
149 static int cfg_include(m_option_t
*conf
, char *filename
){
150 return m_config_parse_config_file(mconfig
, filename
);
153 #include "get_path.c"
155 //**************************************************************************//
157 //**************************************************************************//
160 void xscreensaver_heartbeat(void);
163 //**************************************************************************//
164 //**************************************************************************//
165 // Input media streaming & demultiplexer:
166 //**************************************************************************//
168 static int max_framesize
=0;
170 #include "libmpdemux/stream.h"
171 #include "libmpdemux/demuxer.h"
172 #include "libmpdemux/stheader.h"
173 //#include "parse_es.h"
175 #include "libmpcodecs/dec_audio.h"
176 #include "libmpcodecs/dec_video.h"
177 #include "libmpcodecs/mp_image.h"
178 #include "libmpcodecs/vf.h"
180 extern void vf_list_plugins();
182 //**************************************************************************//
183 //**************************************************************************//
185 // Common FIFO functions, and keyboard/event FIFO code
188 //**************************************************************************//
190 vo_functions_t
*video_out
=NULL
;
191 ao_functions_t
*audio_out
=NULL
;
197 double video_time_usage
=0;
198 double vout_time_usage
=0;
199 static double audio_time_usage
=0;
200 static int total_time_usage_start
=0;
201 static int total_frame_cnt
=0;
202 static int drop_frame_cnt
=0; // total number of dropped frames
207 static int output_quality
=0;
209 float playback_speed
=1.0;
217 #define MAX_OSD_LEVEL 3
220 int osd_level_saved
=-1;
224 static char *seek_to_sec
=NULL
;
225 static off_t seek_to_byte
=0;
226 static off_t step_sec
=0;
227 static int loop_times
=-1;
228 static int loop_seek
=0;
231 int autosync
=0; // 30 might be a good default value.
233 // may be changed by GUI: (FIXME!)
234 float rel_seek_secs
=0;
238 char **audio_codec_list
=NULL
; // override audio codec
239 char **video_codec_list
=NULL
; // override video codec
240 char **audio_fm_list
=NULL
; // override audio codec family
241 char **video_fm_list
=NULL
; // override video codec family
248 char* audio_lang
=NULL
;
249 char* dvdsub_lang
=NULL
;
250 static char* spudec_ifo
=NULL
;
251 char* filename
=NULL
; //"MI2-Trailer.avi";
252 int forced_subs_only
=0;
255 int stream_cache_size
=-1;
256 #ifdef USE_STREAM_CACHE
257 extern int cache_fill_status
;
259 #define cache_fill_status 0
263 static char *stream_dump_name
="stream.dump";
264 int stream_dump_type
=0;
267 static float default_max_pts_correction
=-1;//0.01f;
268 static float max_pts_correction
=0;//default_max_pts_correction;
269 static float c_total
=0;
272 static int softsleep
=0;
275 static int force_srate
=0;
276 static int audio_output_format
=0;
277 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
278 static int play_n_frames
=-1;
279 static int play_n_frames_mf
=-1;
282 char** video_driver_list
=NULL
;
283 char** audio_driver_list
=NULL
;
285 extern char *vo_subdevice
;
286 extern char *ao_subdevice
;
288 // codec outfmt flags (defined in libmpcodecs/vd.c)
292 char *font_name
=NULL
;
293 #ifdef HAVE_FONTCONFIG
294 extern int font_fontconfig
;
296 float font_factor
=0.75;
297 char **sub_name
=NULL
;
301 char *vobsub_name
=NULL
;
302 /*DSP!!char *dsp=NULL;*/
304 int suboverlap_enabled
= 1;
306 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
307 int set_of_sub_size
= 0;
308 int set_of_sub_pos
= -1;
309 float sub_last_pts
= -303;
312 static stream_t
* stream
=NULL
;
313 static demuxer_t
*demuxer
=NULL
;
314 static sh_audio_t
*sh_audio
=NULL
;
315 static sh_video_t
*sh_video
=NULL
;
317 char* current_module
=NULL
; // for debugging
319 // also modified by Gui/mplayer/gtk/eq.c:
320 int vo_gamma_gamma
= 1000;
321 int vo_gamma_brightness
= 1000;
322 int vo_gamma_contrast
= 1000;
323 int vo_gamma_saturation
= 1000;
324 int vo_gamma_hue
= 1000;
329 #include "m_struct.h"
330 #include "libmenu/menu.h"
331 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
332 extern vf_info_t vf_info_menu
;
333 static vf_info_t
* libmenu_vfs
[] = {
337 static vf_instance_t
* vf_menu
= NULL
;
338 static int use_menu
= 0;
339 static char* menu_cfg
= NULL
;
340 static char* menu_root
= "main";
349 struct edl_record edl_records
[ MAX_EDL_ENTRIES
];
350 int num_edl_records
= 0;
352 edl_record_ptr next_edl_record
= NULL
;
353 static char* edl_filename
= NULL
;
354 static char* edl_output_filename
= NULL
;
355 short edl_decision
= 0;
358 static unsigned int inited_flags
=0;
362 #define INITED_GETCH2 8
363 #define INITED_SPUDEC 32
364 #define INITED_STREAM 64
365 #define INITED_INPUT 128
366 #define INITED_VOBSUB 256
367 #define INITED_DEMUXER 512
368 #define INITED_ACODEC 1024
369 #define INITED_VCODEC 2048
370 #define INITED_ALL 0xFFFF
372 static void uninit_player(unsigned int mask
){
373 mask
=inited_flags
&mask
;
375 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
377 if(mask
&INITED_ACODEC
){
378 inited_flags
&=~INITED_ACODEC
;
379 current_module
="uninit_acodec";
380 if(sh_audio
) uninit_audio(sh_audio
);
384 if(mask
&INITED_VCODEC
){
385 inited_flags
&=~INITED_VCODEC
;
386 current_module
="uninit_vcodec";
387 if(sh_video
) uninit_video(sh_video
);
394 if(mask
&INITED_DEMUXER
){
395 inited_flags
&=~INITED_DEMUXER
;
396 current_module
="free_demuxer";
398 stream
=demuxer
->stream
;
399 free_demuxer(demuxer
);
404 // kill the cache process:
405 if(mask
&INITED_STREAM
){
406 inited_flags
&=~INITED_STREAM
;
407 current_module
="uninit_stream";
408 if(stream
) free_stream(stream
);
413 inited_flags
&=~INITED_VO
;
414 current_module
="uninit_vo";
419 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
420 if(mask
&INITED_GETCH2
){
421 inited_flags
&=~INITED_GETCH2
;
422 current_module
="uninit_getch2";
423 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
428 if(mask
&INITED_VOBSUB
){
429 inited_flags
&=~INITED_VOBSUB
;
430 current_module
="uninit_vobsub";
431 if(vo_vobsub
) vobsub_close(vo_vobsub
);
435 if (mask
&INITED_SPUDEC
){
436 inited_flags
&=~INITED_SPUDEC
;
437 current_module
="uninit_spudec";
438 spudec_free(vo_spudec
);
443 inited_flags
&=~INITED_AO
;
444 current_module
="uninit_ao";
445 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
450 inited_flags
&=~INITED_GUI
;
451 current_module
="uninit_gui";
456 if(mask
&INITED_INPUT
){
457 inited_flags
&=~INITED_INPUT
;
458 current_module
="uninit_input";
465 static void exit_player_with_rc(char* how
, int rc
){
467 uninit_player(INITED_ALL
);
472 vo_uninit(); // close the X11 connection (if any opened)
475 current_module
="exit_player";
477 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Exiting
,mp_gettext(how
));
478 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
483 void exit_player(char* how
){
484 exit_player_with_rc(how
, 1);
487 static void exit_sighandler(int x
){
488 static int sig_count
=0;
490 if(sig_count
==5 || (inited_flags
==0 && sig_count
>1)) exit(1);
494 kill(getpid(),SIGKILL
);
497 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
498 current_module
?current_module
:mp_gettext("unknown")
506 break; // killed from keyboard (^C) or killed [-9]
508 #ifdef RUNTIME_CPUDETECT
509 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
511 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
515 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
517 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
522 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
524 extern void mp_input_register_options(m_config_t
* cfg
);
527 #include "cfg-mplayer.h"
529 void parse_cfgfiles( m_config_t
* conf
)
533 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
535 if ((conffile
= get_path("")) == NULL
) {
536 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
541 mkdir(conffile
, 0777);
544 if ((conffile
= get_path("config")) == NULL
) {
545 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
547 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
548 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
549 write(conffile_fd
, default_config
, strlen(default_config
));
552 if (m_config_parse_config_file(conf
, conffile
) < 0)
559 void load_per_file_config (m_config_t
* conf
, const char *const file
)
562 char cfg
[strlen(file
)+10];
566 sprintf (cfg
, "%s.conf", file
);
568 if (!stat (cfg
, &st
))
570 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Loading config '%s'\n", cfg
);
571 m_config_parse_config_file (conf
, cfg
);
575 if ((name
= strrchr (cfg
, '/')) == NULL
)
580 if ((confpath
= get_path (name
)) != NULL
)
582 if (!stat (confpath
, &st
))
584 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Loading config '%s'\n", confpath
);
585 m_config_parse_config_file (conf
, confpath
);
592 // When libmpdemux perform a blocking operation (network connection or cache filling)
593 // if the operation fail we use this function to check if it was interrupted by the user.
594 // The function return a new value for eof.
595 static int libmpdemux_was_interrupted(int eof
) {
597 if((cmd
= mp_input_get_cmd(0,0)) != NULL
) {
600 exit_player_with_rc(MSGTR_Exit_quit
, 0);
601 case MP_CMD_PLAY_TREE_STEP
: {
602 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
604 case MP_CMD_PLAY_TREE_UP_STEP
: {
605 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
607 case MP_CMD_PLAY_ALT_SRC_STEP
: {
608 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
616 #define mp_basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
618 int playtree_add_playlist(play_tree_t
* entry
)
620 play_tree_add_bpf(entry
,filename
);
625 import_playtree_playlist_into_gui(entry
, mconfig
);
626 play_tree_free_list(entry
,1);
632 entry
= playtree_iter
->tree
;
633 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
634 return PT_NEXT_ENTRY
;
636 if(playtree_iter
->tree
== entry
) { // Loop with a single file
637 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
638 return PT_NEXT_ENTRY
;
641 play_tree_remove(entry
,1,1);
644 play_tree_insert_entry(playtree_iter
->tree
,entry
);
645 play_tree_set_params_from(entry
,playtree_iter
->tree
);
646 entry
= playtree_iter
->tree
;
647 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
648 return PT_NEXT_ENTRY
;
650 play_tree_remove(entry
,1,1);
655 static int play_tree_step
= 1;
659 sub_data
* subdata
= NULL
;
661 void add_subtitles(char *filename
, float fps
, int silent
)
665 if (filename
== NULL
) {
666 subd
= (sub_data
*)malloc(sizeof(sub_data
));
667 subd
->filename
= strdup("none");
668 subd
->subtitles
= NULL
;
669 subd
->sub_uses_time
= 1;
672 set_of_subtitles
[set_of_sub_size
] = subd
;
677 subd
= sub_read_file(filename
, fps
);
679 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
680 if (subd
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) return;
681 set_of_subtitles
[set_of_sub_size
] = subd
;
683 printf("SUB: added subtitle file (%d): %s\n", set_of_sub_size
, filename
);
686 void update_set_of_subtitles()
687 // subdata was changed, set_of_sub... have to be updated.
690 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
691 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
692 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
693 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
695 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
697 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
698 set_of_subtitles
[set_of_sub_pos
] = subdata
;
700 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
701 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
708 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
709 * make it all work is to use the builtin SDL-bootstrap code, which
710 * will be done automatically by replacing our main() if we include SDL.h.
712 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
717 int main(int argc
,char* argv
[]){
721 static demux_stream_t
*d_audio
=NULL
;
722 static demux_stream_t
*d_video
=NULL
;
723 static demux_stream_t
*d_dvdsub
=NULL
;
725 int file_format
=DEMUXER_TYPE_UNKNOWN
;
727 int delay_corrected
=1;
731 int osd_function
=OSD_PLAY
;
732 int osd_last_pts
=-303;
733 int osd_show_av_delay
= 0;
734 int osd_show_text
= 0;
735 int osd_show_sub_delay
= 0;
736 int osd_show_sub_pos
= 0;
737 int osd_show_sub_visibility
= 0;
738 int osd_show_sub_alignment
= 0;
739 int osd_show_vobsub_changed
= 0;
740 int osd_show_sub_changed
= 0;
741 int osd_show_percentage
= 0;
742 int osd_show_tv_channel
= 25;
743 int osd_show_ontop
= 0;
744 int osd_show_framedropping
= 0;
748 //float a_frame=0; // Audio
753 int gui_no_filename
=0;
756 srand((int) time(NULL
));
759 mp_msg_set_level(MSGL_STATUS
);
761 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2004 MPlayer Team\n\n");
762 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
763 GetCpuCaps(&gCpuCaps
);
765 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
766 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
767 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
768 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
769 #ifdef RUNTIME_CPUDETECT
770 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
772 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
774 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
777 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
780 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
783 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
786 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
789 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
791 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n\n");
795 #if defined(WIN32) && defined(USE_WIN32DLL)
796 { /*make our codec dirs available for LoadLibraryA()*/
797 char tmppath
[MAX_PATH
*2 + 1];
798 char win32path
[MAX_PATH
];
799 char realpath
[MAX_PATH
];
801 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
802 strcpy(tmppath
,win32path
);
803 #ifdef USE_REALCODECS
804 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
805 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
806 #endif /*USE_REALCODECS*/
808 if(!strstr(WIN32_PATH
,":")){
809 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
810 strcpy(win32path
+ strlen(win32path
) - strlen("mplayer.exe"), WIN32_PATH
);
812 else strcpy(win32path
,WIN32_PATH
);
813 strcpy(tmppath
,win32path
);
814 #ifdef USE_REALCODECS
815 if(!strstr(REALCODEC_PATH
,":")){
816 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
817 strcpy(realpath
+ strlen(realpath
) - strlen("mplayer.exe"), REALCODEC_PATH
);
819 else strcpy(realpath
,REALCODEC_PATH
);
820 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
821 #endif /*USE_REALCODECS*/
822 #endif /*__CYGWIN__*/
823 SetEnvironmentVariableA("PATH", tmppath
);
825 #endif /*WIN32 && USE_WIN32DLL*/
828 tv_param_immediate
= 1;
832 if(!strcmp(argv
[0],"gmplayer") ||
833 (strrchr(argv
[0],'/') && !strcmp(strrchr(argv
[0],'/'),"/gmplayer") ) )
836 mconfig
= m_config_new();
837 m_config_register_options(mconfig
,mplayer_opts
);
838 // TODO : add something to let modules register their options
839 mp_input_register_options(mconfig
);
840 parse_cfgfiles(mconfig
);
843 if ( use_gui
) cfg_read();
846 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
850 playtree
= play_tree_cleanup(playtree
);
852 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
854 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
855 play_tree_iter_free(playtree_iter
);
856 playtree_iter
= NULL
;
858 filename
= play_tree_iter_get_file(playtree_iter
,1);
864 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
868 if(use_gui
&& !vo_init()){
869 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
872 if (use_gui
&& playtree_iter
){
873 char cwd
[PATH_MAX
+2];
874 // Remove Playtree and Playtree-Iter from memory as its not used by gui
875 play_tree_iter_free(playtree_iter
);
878 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
881 // Prefix relative paths with current working directory
882 play_tree_add_bpf(playtree
, cwd
);
884 // Import initital playtree into gui
885 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
889 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
894 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
900 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
901 if(!parse_codec_cfg(get_path("codecs.conf"))){
902 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
903 if(!parse_codec_cfg(NULL
)){
904 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
907 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_BuiltinCodecsConf
);
913 if(video_codec_list
){
915 video_codec
=video_codec_list
[0];
916 for(i
=0;video_codec_list
[i
];i
++)
917 printf("vc#%d: '%s'\n",i
,video_codec_list
[i
]);
920 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
921 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
926 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
927 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
932 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
937 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
943 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
954 float start
, stop
, duration
;
956 int next_edl_array_index
= 0;
958 next_edl_record
= edl_records
;
960 if( ( fd
= fopen( edl_filename
, "r" ) ) == NULL
) {
961 printf( "Error opening EDL file [%s]!\n", edl_filename
);
962 next_edl_record
->next
= NULL
;
964 while( fgets( line
, 99, fd
) != NULL
) {
966 if( ( sscanf( line
, "%f %f %d", &start
, &stop
, &action
) ) == 0 ) {
967 printf( "Invalid EDL line: [%s]\n", line
);
969 if( next_edl_array_index
> 0 ) {
970 edl_records
[ next_edl_array_index
-1 ].next
= &edl_records
[ next_edl_array_index
];
971 if( start
<= edl_records
[ next_edl_array_index
-1 ].stop_sec
) {
972 printf( "Invalid EDL line [%d]: [%s]\n", lineCount
, line
);
973 printf( "Last stop position was [%f]; next start is [%f]. Entries must be in chronological order and cannot overlap. Discarding EDL entry.\n", edl_records
[ next_edl_array_index
-1 ].stop_sec
, start
);
977 if( stop
<= start
) {
978 printf( "Invalid EDL line [%d]: [%s]\n", lineCount
, line
);
979 printf( "Stop time must follow start time. Discarding EDL entry.\n" );
982 edl_records
[ next_edl_array_index
].action
= action
;
983 if( action
== EDL_MUTE
) {
984 edl_records
[ next_edl_array_index
].length_sec
= 0;
985 edl_records
[ next_edl_array_index
].start_sec
= start
;
986 edl_records
[ next_edl_array_index
].stop_sec
= start
;
987 next_edl_array_index
++;
988 if( next_edl_array_index
>= MAX_EDL_ENTRIES
-1 ) {
991 edl_records
[ next_edl_array_index
-1 ].next
= &edl_records
[ next_edl_array_index
];
992 edl_records
[ next_edl_array_index
].action
= EDL_MUTE
;
993 edl_records
[ next_edl_array_index
].length_sec
= 0;
994 edl_records
[ next_edl_array_index
].start_sec
= stop
;
995 edl_records
[ next_edl_array_index
].stop_sec
= stop
;
997 edl_records
[ next_edl_array_index
].length_sec
= stop
- start
;
998 edl_records
[ next_edl_array_index
].start_sec
= start
;
999 edl_records
[ next_edl_array_index
].stop_sec
= stop
;
1001 next_edl_array_index
++;
1002 if( next_edl_array_index
>= MAX_EDL_ENTRIES
-1 ) {
1007 if( next_edl_array_index
> 0 ) {
1008 edl_records
[ next_edl_array_index
-1 ].next
= &edl_records
[ next_edl_array_index
];
1010 edl_records
[ next_edl_array_index
].start_sec
= -1;
1011 edl_records
[ next_edl_array_index
].next
= NULL
;
1012 num_edl_records
= ( next_edl_array_index
);
1016 next_edl_record
->next
= NULL
;
1018 if( edl_output_filename
) {
1019 if( edl_filename
) {
1020 printf( "Sorry; EDL mode and EDL output mode are mutually exclusive! Disabling all EDL functions.\n" );
1021 edl_output_filename
= NULL
;
1022 edl_filename
= NULL
;
1023 next_edl_record
->next
= NULL
;
1025 if( ( edl_fd
= fopen( edl_output_filename
, "w" ) ) == NULL
) {
1026 printf( "Error opening file [%s] for writing!\n", edl_output_filename
);
1027 edl_output_filename
= NULL
;
1028 next_edl_record
->next
= NULL
;
1034 printf( "EDL Records:\n" );
1035 if( next_edl_record
->next
!= NULL
) {
1036 while( next_edl_record
->next
!= NULL
) {
1037 printf( "EDL: start [%f], stop [%f], action [%d]\n", next_edl_record
->start_sec
, next_edl_record
->stop_sec
, next_edl_record
->action
);
1038 next_edl_record
= next_edl_record
->next
;
1040 next_edl_record
= edl_records
;
1049 // no file/vcd/dvd -> show HELP:
1050 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
1052 } else gui_no_filename
=1;
1055 // Many users forget to include command line in bugreports...
1057 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "CommandLine:");
1058 for(i
=1;i
<argc
;i
++)printf(" '%s'",argv
[i
]);
1062 mp_msg_set_level(verbose
+MSGL_STATUS
);
1064 //------ load global data first ------
1068 #ifdef HAVE_FREETYPE
1071 #ifdef HAVE_FONTCONFIG
1072 if(!font_fontconfig
)
1076 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
1077 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
1080 vo_font
=read_font_desc(get_path("font/font.desc"),font_factor
,verbose
>1);
1082 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
1084 #ifdef HAVE_FONTCONFIG
1093 // seteuid(0); /* Can't hurt to try to get root here */
1094 if ((rtc_fd
= open("/dev/rtc", O_RDONLY
)) < 0)
1095 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Failed to open /dev/rtc: %s (/dev/rtc should be readable by the user.)\n", strerror(errno
));
1097 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
1099 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
1100 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp
, strerror(errno
));
1101 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp
);
1104 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
1105 /* variable only by the root */
1106 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno
));
1110 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_UsingRTCTiming
, irqp
);
1114 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1115 // and now ? -- Pontscho
1116 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
1120 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Using %s timing\n",softsleep
?"software":"usleep()");
1123 if ( !use_gui
) load_termcap(NULL
); // load key-codes
1126 // ========== Init keyboard FIFO (connection to libvo) ============
1128 // Init input system
1129 current_module
= "init_input";
1131 #ifndef HAVE_NO_POSIX_SELECT
1132 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
1134 if(keyb_fifo_get
> 0)
1135 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
1137 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
1141 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
1143 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
1146 #ifndef HAVE_NO_POSIX_SELECT
1147 mp_input_add_key_fd(0,1,NULL
,NULL
);
1149 mp_input_add_key_fd(0,0,NULL
,NULL
);
1152 inited_flags
|=INITED_INPUT
;
1153 current_module
= NULL
;
1157 if(menu_cfg
&& menu_init(menu_cfg
))
1158 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu inited: %s\n", menu_cfg
);
1160 menu_cfg
= get_path("menu.conf");
1161 if(menu_init(menu_cfg
))
1162 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu inited: %s\n", menu_cfg
);
1164 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
1165 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu inited: %s\n", MPLAYER_CONFDIR
"/menu.conf");
1167 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu init failed\n");
1177 //========= Catch terminate signals: ================
1178 // terminate requests:
1179 signal(SIGTERM
,exit_sighandler
); // kill
1180 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
1182 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
1184 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
1185 #ifdef ENABLE_SIGHANDLER
1187 signal(SIGBUS
,exit_sighandler
); // bus error
1188 signal(SIGSEGV
,exit_sighandler
); // segfault
1189 signal(SIGILL
,exit_sighandler
); // illegal instruction
1190 signal(SIGFPE
,exit_sighandler
); // floating point exc.
1191 signal(SIGABRT
,exit_sighandler
); // abort()
1197 inited_flags
|=INITED_GUI
;
1198 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
1202 // ******************* Now, let's see the per-file stuff ********************
1206 if (filename
) load_per_file_config (mconfig
, filename
);
1208 // We must enable getch2 here to be able to interrupt network connection
1210 if(!use_stdin
&& !slave_mode
){
1211 if(inited_flags
&INITED_GETCH2
)
1212 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"WARNING: getch2_init called twice!\n");
1214 getch2_enable(); // prepare stdin for hotkeys...
1215 inited_flags
|=INITED_GETCH2
;
1216 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
1219 // =================== GUI idle loop (STOP state) ===========================
1222 file_format
=DEMUXER_TYPE_UNKNOWN
;
1223 guiGetEvent( guiSetDefaults
,0 );
1224 while ( guiIntfStruct
.Playing
!= 1 )
1229 guiGetEvent( guiReDraw
,NULL
);
1230 if ( (cmd
= mp_input_get_cmd(0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
1232 guiGetEvent( guiSetParameters
,NULL
);
1233 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
1235 play_tree_t
* entry
= play_tree_new();
1236 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
1237 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
1238 else playtree
=play_tree_new();
1239 play_tree_set_child( playtree
,entry
);
1242 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
1245 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
1247 play_tree_iter_free(playtree_iter
);
1248 playtree_iter
= NULL
;
1250 filename
= play_tree_iter_get_file(playtree_iter
,1);
1256 //---------------------------------------------------------------------------
1258 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
1259 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
1261 //==================== Open VOB-Sub ============================
1263 current_module
="vobsub";
1265 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
1267 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
1268 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
1269 /* try to autodetect vobsub from movie filename ::atmos */
1270 char *buf
= malloc((strlen(filename
)-3) * sizeof(char));
1271 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
1272 strncpy(buf
, filename
, strlen(filename
)-4);
1273 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
1277 sub_auto
=0; // don't do autosub for textsubs if vobsub found
1278 inited_flags
|=INITED_VOBSUB
;
1279 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
1280 // check if vobsub requested only to display forced subtitles
1281 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
1284 //============ Open & Sync STREAM --- fork cache2 ====================
1289 //free_demuxer_stream(d_audio);
1293 //free_demuxer_stream(d_video);
1299 current_module
="open_stream";
1300 stream
=open_stream(filename
,0,&file_format
);
1301 if(!stream
) { // error...
1302 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
1303 goto goto_next_file
;
1305 inited_flags
|=INITED_STREAM
;
1308 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
1311 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
1314 current_module
="handle_playlist";
1315 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
1316 entry
= parse_playtree(stream
,0);
1317 eof
=playtree_add_playlist(entry
);
1318 goto goto_next_file
;
1320 stream
->start_pos
+=seek_to_byte
;
1322 if(stream_dump_type
==5){
1323 unsigned char buf
[4096];
1326 current_module
="dumpstream";
1327 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
1328 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot dump this stream - no 'fd' available\n");
1329 exit_player(MSGTR_Exit_error
);
1331 stream_reset(stream
);
1332 stream_seek(stream
,stream
->start_pos
);
1333 f
=fopen(stream_dump_name
,"wb");
1335 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1336 exit_player(MSGTR_Exit_error
);
1338 while(!stream
->eof
){
1339 len
=stream_read(stream
,buf
,4096);
1341 if(fwrite(buf
,len
,1,f
) != 1) {
1342 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1343 exit_player(MSGTR_Exit_error
);
1348 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1349 exit_player(MSGTR_Exit_error
);
1351 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1352 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1356 if(stream
->type
==STREAMTYPE_DVD
){
1357 current_module
="dvd lang->id";
1358 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
1359 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
1360 current_module
=NULL
;
1365 if (stream
->type
==STREAMTYPE_DVDNAV
) stream_cache_size
=0; // must disable caching...
1368 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1369 #ifdef HAS_DVBIN_SUPPORT
1372 if(stream_cache_size
>0){
1373 current_module
="enable_cache";
1374 if(!stream_enable_cache(stream
,stream_cache_size
*1024,stream_cache_size
*1024/5,stream_cache_size
*1024/20))
1375 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
1378 //============ Open DEMUXERS --- DETECT file type =======================
1379 current_module
="demux_open";
1381 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
1383 // HACK to get MOV Reference Files working
1385 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
1387 unsigned char* playlist_entry
;
1388 play_tree_t
*list
= NULL
, *entry
= NULL
;
1390 current_module
="handle_demux_playlist";
1391 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
1395 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry\n",playlist_entry
);
1397 bname
=mp_basename(playlist_entry
);
1398 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
1401 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
1404 entry
= play_tree_new();
1406 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
1408 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1)*sizeof(char));
1411 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
1412 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
1413 strcat(temp
, playlist_entry
);
1414 play_tree_add_file(entry
,temp
);
1415 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s\n",temp
);
1420 play_tree_add_file(entry
,playlist_entry
);
1425 play_tree_append_entry(list
,entry
);
1427 free_demuxer(demuxer
);
1432 entry
= play_tree_new();
1433 play_tree_set_child(entry
,list
);
1434 eof
=playtree_add_playlist(entry
);
1435 goto goto_next_file
;
1444 current_module
="handle_playlist";
1445 switch(stream
->type
){
1446 case STREAMTYPE_VCD
:
1447 case STREAMTYPE_DVD
:
1448 case STREAMTYPE_DVDNAV
:
1449 case STREAMTYPE_CDDA
:
1450 case STREAMTYPE_VCDBINCUE
:
1451 // don't try to parse raw media as playlist, it's unlikely
1452 goto goto_next_file
;
1454 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Falling back on trying to parse playlist %s...\n",filename
);
1455 stream_reset(stream
);
1456 stream_seek(stream
,stream
->start_pos
);
1457 entry
= parse_playtree(stream
,0);
1459 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
1461 eof
=playtree_add_playlist(entry
);
1463 goto goto_next_file
;
1465 inited_flags
|=INITED_DEMUXER
;
1467 current_module
="demux_open2";
1469 //file_format=demuxer->file_format;
1471 d_audio
=demuxer
->audio
;
1472 d_video
=demuxer
->video
;
1473 d_dvdsub
=demuxer
->sub
;
1476 if((stream_dump_type
)&&(stream_dump_type
<4)){
1478 demux_stream_t
*ds
=NULL
;
1479 current_module
="dump";
1480 // select stream to dump
1481 switch(stream_dump_type
){
1482 case 1: ds
=d_audio
;break;
1483 case 2: ds
=d_video
;break;
1484 case 3: ds
=d_dvdsub
;break;
1487 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
1488 exit_player(MSGTR_Exit_error
);
1490 // disable other streams:
1491 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
1492 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
1493 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
1495 f
=fopen(stream_dump_name
,"wb");
1497 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1498 exit_player(MSGTR_Exit_error
);
1501 unsigned char* start
;
1502 int in_size
=ds_get_packet(ds
,&start
);
1503 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
1504 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
1505 if(in_size
>0) fwrite(start
,in_size
,1,f
);
1508 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1509 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1512 sh_audio
=d_audio
->sh
;
1513 sh_video
=d_video
->sh
;
1517 current_module
="video_read_properties";
1518 if(!video_read_properties(sh_video
)) {
1519 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
1520 sh_video
=d_video
->sh
=NULL
;
1522 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1523 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
1524 sh_video
->fps
,sh_video
->frametime
1527 /* need to set fps here for output encoders to pick it up in their init */
1529 sh_video
->fps
=force_fps
;
1530 sh_video
->frametime
=1.0f
/sh_video
->fps
;
1532 vo_fps
= sh_video
->fps
;
1534 vo_mouse_timer_const
=(int)sh_video
->fps
;
1537 if(!sh_video
->fps
&& !force_fps
){
1538 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
1539 sh_video
=d_video
->sh
=NULL
;
1547 if(!sh_video
&& !sh_audio
){
1548 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
1549 #ifdef HAS_DVBIN_SUPPORT
1550 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
1552 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
1556 int v
= last_dvb_step
;
1558 dir
= DVB_CHANNEL_HIGHER
;
1560 dir
= DVB_CHANNEL_LOWER
;
1562 if(dvb_step_channel(priv
, dir
))
1564 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
1565 cache_uninit(stream
);
1566 goto goto_enable_cache
;
1571 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
1574 /* display clip info */
1575 demux_info_print(demuxer
);
1577 //================== Read SUBTITLES (DVD & TEXT) ==========================
1578 if(d_dvdsub
->id
>= 0 && vo_spudec
==NULL
&& sh_video
){
1581 unsigned int palette
[16], width
, height
;
1582 current_module
="spudec_init_vobsub";
1583 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1584 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1588 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
1589 current_module
="spudec_init_dvdnav";
1590 vo_spudec
=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t
*)(stream
->priv
)),
1591 sh_video
->disp_w
, sh_video
->disp_h
);
1596 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
1597 current_module
="spudec_init_dvdread";
1598 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
1599 sh_video
->disp_w
, sh_video
->disp_h
);
1603 #ifdef HAVE_MATROSKA
1604 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1605 (d_dvdsub
->sh
!= NULL
) && (((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
1606 current_module
= "spudec_init_matroska";
1607 vo_spudec
= spudec_new_scaled(((mkv_sh_sub_t
*)d_dvdsub
->sh
)->palette
,
1608 ((mkv_sh_sub_t
*)d_dvdsub
->sh
)->width
,
1609 ((mkv_sh_sub_t
*)d_dvdsub
->sh
)->height
);
1613 if (vo_spudec
==NULL
) {
1614 current_module
="spudec_init_normal";
1615 vo_spudec
=spudec_new_scaled(NULL
, sh_video
->disp_w
, sh_video
->disp_h
);
1616 spudec_set_font_factor(vo_spudec
,font_factor
);
1619 if (vo_spudec
!=NULL
)
1620 inited_flags
|=INITED_SPUDEC
;
1624 // Apply current settings for forced subs
1625 if (vo_spudec
!=NULL
)
1626 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
1630 // after reading video params we should load subtitles because
1631 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1633 current_module
="read_subtitles_file";
1635 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
1636 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
1638 if(sub_auto
) { // auto load sub file ...
1639 char *psub
= get_path( "sub/" );
1640 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
1643 add_subtitles (*tmp2
++, sh_video
->fps
, 0);
1645 if (set_of_sub_size
== 0)
1646 add_subtitles (get_path("default.sub"), sh_video
->fps
, 1);
1647 if (set_of_sub_size
> 0)
1648 add_subtitles (NULL
, sh_video
->fps
, 1);
1650 if (set_of_sub_size
> 0) {
1651 //osd_show_sub_changed = sh_video->fps;
1652 subdata
= set_of_subtitles
[set_of_sub_pos
=0];
1654 if(stream_dump_type
==3) list_sub_file(subdata
);
1655 if(stream_dump_type
==4) dump_mpsub(subdata
, sh_video
->fps
);
1656 if(stream_dump_type
==6) dump_srt(subdata
, sh_video
->fps
);
1657 if(stream_dump_type
==7) dump_microdvd(subdata
, sh_video
->fps
);
1658 if(stream_dump_type
==8) dump_jacosub(subdata
, sh_video
->fps
);
1659 if(stream_dump_type
==9) dump_sami(subdata
, sh_video
->fps
);
1664 //================== Init AUDIO (codec) ==========================
1666 // Go through the codec.conf and find the best codec...
1667 current_module
="init_audio_codec";
1668 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1669 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
1670 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
1672 inited_flags
|=INITED_ACODEC
;
1673 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1677 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
1679 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1680 if (sh_video
->format
>= 0x20202020)
1681 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", &sh_video
->format
);
1683 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
1684 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
1685 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
1686 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
1687 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
1688 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
1691 if (sh_audio
->codec
)
1692 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
1693 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1694 if (sh_audio
->format
>= 0x20202020)
1695 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio
->format
);
1697 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
1698 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
1699 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
1700 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
1702 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer
));
1705 if(!sh_video
) goto main
; // audio-only
1707 //================== Init VIDEO (codec & libvo) ==========================
1708 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
1709 current_module
="preinit_libvo";
1712 //if((video_out->preinit(vo_subdevice))!=0){
1713 if(!(video_out
=init_best_video_out(video_driver_list
))){
1714 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
1715 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
1717 sh_video
->video_out
=video_out
;
1718 inited_flags
|=INITED_VO
;
1721 current_module
="init_video_filters";
1723 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
1724 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
1728 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
1729 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
1731 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,"Can't open libmenu video filter with root menu %s\n",menu_root
);
1736 sh_video
->vfilter
=(void*)append_filters(vf_menu
);
1739 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
1741 current_module
="init_video_codec";
1743 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1744 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
1745 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1747 if(!sh_video
->inited
){
1748 if(!fixed_vo
) uninit_player(INITED_VO
);
1749 if(!sh_audio
) goto goto_next_file
;
1750 sh_video
= d_video
->sh
= NULL
;
1751 goto main
; // exit_player(MSGTR_Exit_error);
1754 inited_flags
|=INITED_VCODEC
;
1757 // Auto quality option enabled
1758 output_quality
=get_video_quality_max(sh_video
);
1759 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
1760 else output_quality
=auto_quality
;
1761 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d\n",output_quality
);
1762 set_video_quality(sh_video
,output_quality
);
1765 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1767 current_module
="init_vo";
1770 if (vo_gamma_gamma
!= 1000)
1771 set_video_colors (sh_video
, "gamma", vo_gamma_gamma
);
1772 if (vo_gamma_brightness
!= 1000)
1773 set_video_colors(sh_video
, "brightness", vo_gamma_brightness
);
1774 if (vo_gamma_contrast
!= 1000)
1775 set_video_colors(sh_video
, "contrast", vo_gamma_contrast
);
1776 if (vo_gamma_saturation
!= 1000)
1777 set_video_colors(sh_video
, "saturation", vo_gamma_saturation
);
1778 if (vo_gamma_hue
!= 1000)
1779 set_video_colors(sh_video
, "hue", vo_gamma_hue
);
1782 if(vo_flags
& 0x08 && vo_spudec
)
1783 spudec_set_hw_spu(vo_spudec
,video_out
);
1785 #ifdef HAVE_FREETYPE
1786 force_load_font
= 1;
1789 //================== MAIN: ==========================
1791 current_module
="main";
1793 // If there is no video OSD has to be disabled.
1794 // In case of playing a playtree we have to restore the
1795 // old OSD level after playing one or more audio-only files.
1796 if(!sh_video
&& osd_level
>= 0) { // save OSD level only once
1797 osd_level_saved
= osd_level
;
1799 } else if (osd_level_saved
> -1) { // if there is a saved OSD level, restore it
1800 osd_level
= osd_level_saved
;
1801 osd_level_saved
= -1;
1809 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
1810 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
1811 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
1812 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
1813 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
1818 //int frame_corr_num=0; //
1819 //float v_frame=0; // Video
1820 float time_frame
=0; // Timer
1821 //float num_frames=0; // number of frames played
1823 char osd_text_buffer
[64];
1824 char osd_show_text_buffer
[64];
1825 int drop_frame
=0; // current dropping status
1826 int dropped_frames
=0; // how many frames dropped since last non-dropped frame
1827 int too_slow_frame_cnt
=0;
1828 int too_fast_frame_cnt
=0;
1829 // for auto-quality:
1830 float AV_delay
=0; // average of A-V timestamp differences
1831 double vdecode_time
;
1832 unsigned int lastframeout_ts
=0;
1833 /*float time_frame_corr_avg=0;*/ /* unused */
1835 float next_frame_time
=0;
1836 int frame_time_remaining
=0; // flag
1839 osd_text_buffer
[0]=0;
1841 //================ SETUP AUDIO ==========================
1844 //const ao_info_t *info=audio_out->info;
1845 current_module
="af_preinit";
1846 ao_data
.samplerate
=force_srate
?force_srate
:sh_audio
->samplerate
*playback_speed
;
1847 ao_data
.channels
=audio_output_channels
?audio_output_channels
:sh_audio
->channels
;
1848 ao_data
.format
=audio_output_format
?audio_output_format
:sh_audio
->sample_format
;
1850 if(!preinit_audio_filters(sh_audio
,
1852 (int)(sh_audio
->samplerate
*playback_speed
),
1853 sh_audio
->channels
, sh_audio
->sample_format
, sh_audio
->samplesize
,
1855 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
,
1856 audio_out_format_bits(ao_data
.format
)/8)){
1857 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,"Error at audio filter chain pre-init!\n");
1859 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AF_pre: %dHz %dch %s\n",
1860 ao_data
.samplerate
, ao_data
.channels
,
1861 audio_out_format_name(ao_data
.format
));
1864 current_module
="ao2_init";
1865 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
1866 (ao_plugin_cfg
.plugin_list
!=NULL
), // plugin flag
1867 force_srate
?force_srate
:ao_data
.samplerate
,
1868 audio_output_channels
?audio_output_channels
:ao_data
.channels
,
1869 audio_output_format
?audio_output_format
:ao_data
.format
,0))){
1871 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1872 uninit_player(INITED_ACODEC
); // close codec
1873 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
1876 inited_flags
|=INITED_AO
;
1877 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bps)\n",
1878 audio_out
->info
->short_name
,
1879 ao_data
.samplerate
, ao_data
.channels
,
1880 audio_out_format_name(ao_data
.format
),
1881 audio_out_format_bits(ao_data
.format
)/8 );
1882 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_AODescription_AOAuthor
,
1883 audio_out
->info
->name
, audio_out
->info
->author
);
1884 if(strlen(audio_out
->info
->comment
) > 0)
1885 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_AOComment
, audio_out
->info
->comment
);
1886 // init audio filters:
1888 current_module
="af_init";
1889 if(!init_audio_filters(sh_audio
,
1890 (int)(sh_audio
->samplerate
*playback_speed
),
1891 sh_audio
->channels
, sh_audio
->sample_format
, sh_audio
->samplesize
,
1892 ao_data
.samplerate
, ao_data
.channels
, ao_data
.format
,
1893 audio_out_format_bits(ao_data
.format
)/8, /* ao_data.bps, */
1894 ao_data
.outburst
*4, ao_data
.buffersize
)){
1895 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,"Couldn't find matching filter / ao format!\n");
1896 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1897 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1898 // sh_audio=d_audio->sh=NULL; // -> nosound
1904 current_module
="av_init";
1906 if(sh_video
) sh_video
->timer
=0;
1907 if(sh_audio
) sh_audio
->delay
=-audio_delay
;
1910 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
1911 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks\n",d_audio
->packs
);
1912 ds_free_packs(d_audio
); // free buffered chunks
1913 d_audio
->id
=-2; // do not read audio chunks
1914 //uninit_player(INITED_AO); // close device
1917 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
1918 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks\n",d_video
->packs
);
1919 ds_free_packs(d_video
);
1921 //if(!fixed_vo) uninit_player(INITED_VO);
1924 if (!sh_video
&& !sh_audio
)
1925 goto goto_next_file
;
1927 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
1928 if(force_fps
&& sh_video
){
1929 vo_fps
= sh_video
->fps
=force_fps
;
1930 sh_video
->frametime
=1.0f
/sh_video
->fps
;
1931 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
1934 //==================== START PLAYING =======================
1936 if(loop_times
>1) loop_times
--; else
1937 if(loop_times
==1) loop_times
= -1;
1939 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
1944 if (stream
->type
==STREAMTYPE_DVDNAV
) {
1945 dvdnav_stream_fullstart((dvdnav_priv_t
*)stream
->priv
);
1949 total_time_usage_start
=GetTimer();
1950 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
1951 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
1952 play_n_frames
=play_n_frames_mf
;
1954 if(play_n_frames
==0){
1955 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
1959 float aq_sleep_time
=0;
1961 if(play_n_frames
>=0){
1963 if(play_n_frames
<0) eof
= PT_NEXT_ENTRY
;
1966 /*========================== PLAY AUDIO ============================*/
1973 current_module
="play_audio";
1975 ao_data
.pts
=((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
1976 playsize
=audio_out
->get_space();
1978 // handle audio-only case:
1979 if(!playsize
&& !sh_video
) { // buffer is full, do not block here!!!
1980 usec_sleep(10000); // Wait a tick before retry
1984 if(playsize
>MAX_OUTBURST
) playsize
=MAX_OUTBURST
; // we shouldn't exceed it!
1986 // Fill buffer if needed:
1987 current_module
="decode_audio"; // Enter AUDIO decoder module
1989 while(sh_audio
->a_out_buffer_len
<playsize
&& !d_audio
->eof
){
1990 int ret
=decode_audio(sh_audio
,&sh_audio
->a_out_buffer
[sh_audio
->a_out_buffer_len
],
1991 playsize
-sh_audio
->a_out_buffer_len
,sh_audio
->a_out_buffer_size
-sh_audio
->a_out_buffer_len
);
1992 if(ret
<=0) break; // EOF?
1993 sh_audio
->a_out_buffer_len
+=ret
;
1996 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
1997 if(playsize
>sh_audio
->a_out_buffer_len
) playsize
=sh_audio
->a_out_buffer_len
;
2000 current_module
="play_audio";
2001 playsize
=audio_out
->play(sh_audio
->a_out_buffer
,playsize
,0);
2004 sh_audio
->a_out_buffer_len
-=playsize
;
2005 memmove(sh_audio
->a_out_buffer
,&sh_audio
->a_out_buffer
[playsize
],sh_audio
->a_out_buffer_len
);
2006 sh_audio
->delay
+=playback_speed
*playsize
/((float)((ao_data
.bps
&& sh_audio
->afilter
) ?
2007 ao_data
.bps
: sh_audio
->o_bps
));
2011 } // while(sh_audio)
2014 // handle audio-only case:
2017 // convert time to HH:MM:SS.F format
2019 long tenths
= 10 * sh_audio
->delay
-audio_out
->get_delay();
2020 int hh
= (tenths
/ 36000) % 100;
2021 int mm
= (tenths
/ 600) % 60;
2022 int ss
= (tenths
/ 10) % 60;
2023 int f1
= tenths
% 10;
2024 char hhmmssf
[16]; // only really need 11, but just in case...
2025 sprintf( hhmmssf
, "%2d:%2d:%2d.%1d", hh
, mm
, ss
, f1
);
2030 // uncomment the next three lines to show leading zero ten-hours
2031 // else if (' ' == hhmmssf[0]) {
2032 // hhmmssf[0] = '0';
2034 if ((0 == hh
) && (0 == mm
)) {
2038 else if ((' ' == hhmmssf
[3]) && (' ' != hhmmssf
[2])) {
2041 if ((' ' == hhmmssf
[6]) && (' ' != hhmmssf
[5])) {
2044 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A: %s %4.1f%% %d%% \r"
2046 ,(sh_audio
->delay
>0.5)?100.0*audio_time_usage
/(double)sh_audio
->delay
:0
2050 if(d_audio
->eof
) eof
= PT_NEXT_ENTRY
;
2054 /*========================== PLAY VIDEO ============================*/
2056 float frame_time
=next_frame_time
;
2058 vo_pts
=sh_video
->timer
*90000.0;
2059 vo_fps
=sh_video
->fps
;
2061 if(!frame_time_remaining
){
2062 //-------------------- Decode a frame: -----------------------
2063 vdecode_time
=video_time_usage
;
2065 { unsigned char* start
=NULL
;
2068 current_module
="video_read_frame";
2069 in_size
=video_read_frame(sh_video
,&next_frame_time
,&start
,force_fps
);
2070 if(in_size
<0){ eof
=1; break; }
2071 if(in_size
>max_framesize
) max_framesize
=in_size
; // stats
2072 sh_video
->timer
+=frame_time
;
2073 if(sh_audio
) sh_audio
->delay
-=frame_time
;
2074 time_frame
+=frame_time
; // for nosound
2075 // check for frame-drop:
2076 current_module
="check_framedrop";
2077 if(sh_audio
&& !d_audio
->eof
){
2078 float delay
=playback_speed
*audio_out
->get_delay();
2079 float d
=delay
-sh_audio
->delay
;
2080 // we should avoid dropping to many frames in sequence unless we
2081 // are too late. and we allow 100ms A-V delay here:
2082 if(d
<-dropped_frames
*frame_time
-0.100){
2083 drop_frame
=frame_dropping
;
2087 drop_frame
=dropped_frames
=0;
2092 current_module
="decode_video";
2093 // printf("Decode! %p %d \n",start,in_size);
2094 blit_frame
=decode_video(sh_video
,start
,in_size
,drop_frame
);
2097 vdecode_time
=video_time_usage
-vdecode_time
;
2098 //------------------------ frame decoded. --------------------
2100 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
2102 if(sh_video
->vf_inited
<0){
2103 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_NotInitializeVOPorVO
);
2104 eof
=1; goto goto_next_file
;
2109 // ==========================================================================
2111 // current_module="draw_osd";
2112 // if(vo_config_count) video_out->draw_osd();
2115 if(use_gui
) guiEventHandling();
2118 current_module
="calc_sleep_time";
2121 { // debug frame dropping code
2122 float delay
=audio_out
->get_delay();
2123 mp_msg(MSGT_AVSYNC
,MSGL_V
,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2124 sh_video
->timer
,sh_audio
->timer
-delay
,
2125 sh_video
->timer
-(sh_audio
->timer
-delay
),
2130 if(drop_frame
&& !frame_time_remaining
&& !autosync
){
2132 * Note: time_frame should not be forced to 0 in autosync mode.
2133 * It is used as a cumulative counter to predict and correct the
2134 * delay measurements from the audio driver. time_frame is already
2135 * < 0, so the "time to sleep" code does not actually sleep. Also,
2136 * blit_frame is already 0 because drop_frame was true when
2137 * decode_video was called (which causes it to set blit_frame to 0.)
2138 * When autosync==0, the default behavior is still completely unchanged.
2141 time_frame
=0; // don't sleep!
2142 blit_frame
=0; // don't display!
2146 // It's time to sleep...
2148 frame_time_remaining
=0;
2149 time_frame
-=GetRelativeTime(); // reset timer
2151 if(sh_audio
&& !d_audio
->eof
){
2152 float delay
=playback_speed
*audio_out
->get_delay();
2153 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"delay=%f\n",delay
);
2157 * Adjust this raw delay value by calculating the expected
2158 * delay for this frame and generating a new value which is
2159 * weighted between the two. The higher autosync is, the
2160 * closer to the delay value gets to that which "-nosound"
2161 * would have used, and the longer it will take for A/V
2162 * sync to settle at the right value (but it eventually will.)
2163 * This settling time is very short for values below 100.
2165 float predicted
= sh_audio
->delay
+time_frame
;
2166 float difference
= delay
- predicted
;
2167 delay
= predicted
+ difference
/ (float)autosync
;
2170 time_frame
=delay
-sh_audio
->delay
;
2172 // delay = amount of audio buffered in soundcard/driver
2173 if(delay
>0.25) delay
=0.25; else
2174 if(delay
<0.10) delay
=0.10;
2175 if(time_frame
>delay
*0.6){
2176 // sleep time too big - may cause audio drops (buffer underrun)
2177 frame_time_remaining
=1;
2178 time_frame
=delay
*0.5;
2184 if( (time_frame
<-3*frame_time
|| time_frame
>3*frame_time
) || benchmark
)
2189 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2191 aq_sleep_time
+=time_frame
;
2195 //============================== SLEEP: ===================================
2197 time_frame
/=playback_speed
;
2199 // flag 256 means: libvo driver does its timing (dvb card)
2200 if(time_frame
>0.001 && !(vo_flags
&256)){
2204 // -------- RTC -----------
2205 current_module
="sleep_rtc";
2206 while (time_frame
> 0.000) {
2207 unsigned long rtc_ts
;
2208 if (read (rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
2209 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC read error: %s\n", strerror(errno
));
2210 time_frame
-=GetRelativeTime();
2215 // -------- USLEEP + SOFTSLEEP -----------
2216 float min
=softsleep
?0.021:0.005;
2217 current_module
="sleep_usleep";
2218 while(time_frame
>min
){
2219 if(time_frame
<=0.020)
2220 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2222 usec_sleep(1000000*(time_frame
-0.020));
2223 time_frame
-=GetRelativeTime();
2226 current_module
="sleep_soft";
2227 if(time_frame
<0) mp_msg(MSGT_AVSYNC
, MSGL_WARN
, "Warning! Softsleep underflow!\n");
2228 while(time_frame
>0) time_frame
-=GetRelativeTime(); // burn the CPU
2234 //if(!frame_time_remaining){ // should we display the frame now?
2236 //====================== FLIP PAGE (VIDEO BLT): =========================
2238 current_module
="vo_check_events";
2239 if(vo_config_count
) video_out
->check_events();
2241 current_module
="flip_page";
2242 if (!frame_time_remaining
) {
2244 unsigned int t2
=GetTimer();
2247 #define FRAME_LAG_WARN 0.2
2248 j
= ((float)t2
- lastframeout_ts
) / 1000000;
2249 lastframeout_ts
= GetTimer();
2250 if (j
< frame_time
+ frame_time
* -FRAME_LAG_WARN
)
2251 too_fast_frame_cnt
++;
2252 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2253 else if (j
> frame_time
+ frame_time
* FRAME_LAG_WARN
)
2254 too_slow_frame_cnt
++;
2255 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2257 if(vo_config_count
) video_out
->flip_page();
2258 // usec_sleep(50000); // test only!
2261 vout_time_usage
+=tt
;
2264 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2265 otherwise A/V desync will occur. -- Alvieboy
2267 if (vo_config_count
)
2268 video_out
->control(VOCTRL_DUPLICATE_FRAME
, NULL
);
2271 //====================== A-V TIMESTAMP CORRECTION: =========================
2273 current_module
="av_sync";
2279 // unplayed bytes in our and soundcard/dma buffer:
2280 float delay
=playback_speed
*audio_out
->get_delay()+(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2284 * If autosync is enabled, the value for delay must be calculated
2285 * a bit differently. It is set only to the difference between
2286 * the audio and video timers. Any attempt to include the real
2287 * or corrected delay causes the pts_correction code below to
2288 * try to correct for the changes in delay which autosync is
2289 * trying to measure. This keeps the two from competing, but still
2290 * allows the code to correct for PTS drift *only*. (Using a delay
2291 * value here, even a "corrected" one, would be incompatible with
2294 delay
=sh_audio
->delay
;
2295 delay
+=(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2300 // PTS = sample_no / samplerate
2301 unsigned int samples
=
2302 // (sh_audio->audio.dwSampleSize)?
2303 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2304 ds_tell_block(d_audio
); // <- used for VBR audio
2305 samples
+=sh_audio
->audio
.dwStart
; // offset
2306 a_pts
=samples
*(float)sh_audio
->audio
.dwScale
/(float)sh_audio
->audio
.dwRate
;
2308 a_pts
-=(sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2312 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2314 if(!delay_corrected
) if(a_pts
) delay_corrected
=1;
2316 printf("\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2318 ds_tell_pts(d_audio
)/(float)sh_audio
->i_bps
,
2319 -sh_audio
->a_in_buffer_len
/(float)sh_audio
->i_bps
,
2320 a_pts
+(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
);
2322 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2324 v_pts
=sh_video
? sh_video
->pts
: d_video
->pts
;
2326 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
);
2328 if(delay_corrected
){
2329 static int drop_message
=0;
2331 AV_delay
=(a_pts
-delay
-audio_delay
)-v_pts
;
2332 if(AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
2334 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
2337 if(x
<-max_pts_correction
) x
=-max_pts_correction
; else
2338 if(x
> max_pts_correction
) x
= max_pts_correction
;
2339 if(default_max_pts_correction
>=0)
2340 max_pts_correction
=default_max_pts_correction
;
2342 max_pts_correction
=sh_video
->frametime
*0.10; // +-10% of time
2343 if(!frame_time_remaining
){ sh_audio
->delay
+=x
; c_total
+=x
;} // correction
2344 if(!quiet
) mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",
2345 a_pts
-audio_delay
-delay
,v_pts
,AV_delay
,c_total
,
2346 (int)sh_video
->num_frames
,(int)sh_video
->num_frames_decoded
,
2347 (sh_video
->timer
>0.5)?(int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
):0,
2348 (sh_video
->timer
>0.5)?(int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
):0,
2349 (sh_video
->timer
>0.5)?(100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
):0
2361 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video
->pts
,
2362 (int)sh_video
->num_frames
,
2363 (sh_video
->timer
>0.5)?(int)(100.0*video_time_usage
/(double)sh_video
->timer
):0,
2364 (sh_video
->timer
>0.5)?(int)(100.0*vout_time_usage
/(double)sh_video
->timer
):0,
2365 (sh_video
->timer
>0.5)?(100.0*audio_time_usage
/(double)sh_video
->timer
):0
2375 //============================ Auto QUALITY ============================
2377 /*Output quality adjustments:*/
2379 current_module
="autoq";
2380 // float total=0.000001f * (GetTimer()-aq_total_time);
2381 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2382 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
2385 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2386 if(output_quality
>1 && aq_sleep_time
<0)
2389 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
2391 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2392 set_video_quality(sh_video
,output_quality
);
2395 } // end if(sh_video)
2397 //============================ Handle PAUSE ===============================
2399 current_module
="pause";
2403 if (!--osd_visible
){
2404 vo_osd_progbar_type
=-1; // disable
2405 vo_osd_changed(OSDTYPE_PROGBAR
);
2406 if (osd_function
!= OSD_PAUSE
)
2407 osd_function
= OSD_PLAY
;
2412 if(osd_function
==OSD_PAUSE
){
2415 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2419 if(use_gui
) guiGetEvent( guiCEvent
,(char *)guiSetPause
);
2421 if (video_out
&& sh_video
&& vo_config_count
)
2422 video_out
->control(VOCTRL_PAUSE
, NULL
);
2424 if (audio_out
&& sh_audio
)
2425 audio_out
->pause(); // pause audio, keep data if possible
2427 while( (cmd
= mp_input_get_cmd(20,1)) == NULL
) {
2428 if(sh_video
&& video_out
&& vo_config_count
) video_out
->check_events();
2432 guiGetEvent( guiReDraw
,NULL
);
2433 if(guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
)) break;
2438 vf_menu_pause_update(vf_menu
);
2443 osd_function
=OSD_PLAY
;
2444 if (audio_out
&& sh_audio
)
2445 audio_out
->resume(); // resume audio
2446 if (video_out
&& sh_video
&& vo_config_count
)
2447 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
2448 (void)GetRelativeTime(); // keep TF around FT in next cycle
2452 if ( guiIntfStruct
.Playing
== guiSetStop
) goto goto_next_file
;
2453 guiGetEvent( guiCEvent
,(char *)guiSetPlay
);
2460 osd_function
=OSD_FFW
;
2461 rel_seek_secs
+=step_sec
;
2465 if (stream
->type
==STREAMTYPE_DVDNAV
&& dvd_nav_still
)
2466 dvdnav_stream_sleeping((dvdnav_priv_t
*)stream
->priv
);
2469 //================= EDL =========================================
2472 if( next_edl_record
->next
) { // Are we (still?) doing EDL?
2474 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, "Cannot use edit list without video. EDL disabled.\n" );
2475 next_edl_record
->next
= NULL
;
2477 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
2478 if( next_edl_record
->action
== EDL_SKIP
) {
2479 osd_function
= OSD_FFW
;
2481 rel_seek_secs
= next_edl_record
->length_sec
;
2483 printf( "\nEDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record
->start_sec
, next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2486 next_edl_record
= next_edl_record
->next
;
2487 } else if( next_edl_record
->action
== EDL_MUTE
) {
2490 printf( "\nEDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
2493 next_edl_record
= next_edl_record
->next
;
2500 //================= Keyboard events, SEEKing ====================
2502 current_module
="key_events";
2507 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0)) != NULL
) {
2509 case MP_CMD_SEEK
: {
2511 osd_show_percentage
= 25;
2512 v
= cmd
->args
[0].v
.i
;
2513 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2514 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
2517 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2520 else if(abs
) { /* Absolute seek by percentage */
2523 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2524 rel_seek_secs
= v
/100.0;
2528 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
2533 case MP_CMD_EDL_MARK
:
2535 float v
= sh_video
->pts
;
2536 fprintf( edl_fd
, "%f %f %d\n", v
-2, v
, 0 );
2540 case MP_CMD_AUDIO_DELAY
: {
2541 float v
= cmd
->args
[0].v
.f
;
2543 osd_show_av_delay
= 9;
2544 if(sh_audio
) sh_audio
->delay
+= v
;
2546 case MP_CMD_PAUSE
: {
2547 osd_function
=OSD_PAUSE
;
2550 case MP_CMD_QUIT
: {
2551 exit_player_with_rc(MSGTR_Exit_quit
, 0);
2553 case MP_CMD_GRAB_FRAMES
: {
2556 case MP_CMD_PLAY_TREE_STEP
: {
2557 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
2558 int force
= cmd
->args
[1].v
.i
;
2567 for (i
=0;i
<-1*n
;i
++)
2572 if(!force
&& playtree_iter
) {
2573 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2575 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2576 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2577 play_tree_iter_free(i
);
2579 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2585 case MP_CMD_PLAY_TREE_UP_STEP
: {
2586 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
2587 int force
= cmd
->args
[1].v
.i
;
2589 if(!force
&& playtree_iter
) {
2590 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2591 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2592 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2593 play_tree_iter_free(i
);
2595 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2598 case MP_CMD_PLAY_ALT_SRC_STEP
: {
2599 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
2600 int v
= cmd
->args
[0].v
.i
;
2601 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
2603 else if(v
< 0 && playtree_iter
->file
> 1)
2608 case MP_CMD_SUB_DELAY
: {
2611 int abs
= cmd
->args
[1].v
.i
;
2612 float v
= cmd
->args
[0].v
.f
;
2617 osd_show_sub_delay
= 9; // show the subdelay in OSD
2621 case MP_CMD_SUB_STEP
: {
2624 int movement
= cmd
->args
[0].v
.i
;
2625 step_sub(subdata
, sh_video
->pts
, movement
);
2626 osd_show_sub_delay
= 9; // show the subdelay in OSD
2633 int v
= cmd
->args
[0].v
.i
;
2635 osd_level
=(osd_level
+1)%(MAX_OSD_LEVEL
+1);
2637 osd_level
= v
> MAX_OSD_LEVEL
? MAX_OSD_LEVEL
: v
;
2641 case MP_CMD_OSD_SHOW_TEXT
: {
2643 if(osd_level
&& sh_video
){
2644 osd_show_text
=sh_video
->fps
; // 1 sec
2645 strncpy(osd_show_text_buffer
, cmd
->args
[0].v
.s
, 64);
2649 case MP_CMD_VOLUME
: {
2650 int v
= cmd
->args
[0].v
.i
;
2652 // start change for absolute volume value
2653 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2657 mixer_setvolume( (float)v
, (float)v
);
2666 if(osd_level
&& sh_video
){
2667 osd_visible
=sh_video
->fps
; // 1 sec
2668 vo_osd_progbar_type
=OSD_VOLUME
;
2669 vo_osd_progbar_value
=(mixer_getbothvolume()*256.0)/100.0;
2670 vo_osd_changed(OSDTYPE_PROGBAR
);
2677 case MP_CMD_LOADFILE
: {
2678 play_tree_t
* e
= play_tree_new();
2679 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
2681 // Go back to the start point
2682 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
2684 play_tree_free_list(playtree
->child
,1);
2685 play_tree_set_child(playtree
,e
);
2686 play_tree_iter_step(playtree_iter
,0,0);
2690 case MP_CMD_LOADLIST
: {
2691 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
2693 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
2695 // Go back to the start point
2696 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
2698 play_tree_free_list(playtree
->child
,1);
2699 play_tree_set_child(playtree
,e
);
2700 play_tree_iter_step(playtree_iter
,0,0);
2705 case MP_CMD_GAMMA
: {
2706 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2711 if (vo_gamma_gamma
== 1000)
2714 get_video_colors (sh_video
, "gamma", &vo_gamma_gamma
);
2720 vo_gamma_gamma
+= v
;
2722 if (vo_gamma_gamma
> 100)
2723 vo_gamma_gamma
= 100;
2724 else if (vo_gamma_gamma
< -100)
2725 vo_gamma_gamma
= -100;
2726 set_video_colors(sh_video
, "gamma", vo_gamma_gamma
);
2729 osd_visible
=sh_video
->fps
; // 1 sec
2730 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
2731 vo_osd_progbar_value
=(vo_gamma_gamma
<<7)/100 + 128;
2732 vo_osd_changed(OSDTYPE_PROGBAR
);
2736 case MP_CMD_BRIGHTNESS
: {
2737 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2742 if (vo_gamma_brightness
== 1000)
2744 vo_gamma_brightness
= 0;
2745 get_video_colors(sh_video
, "brightness", &vo_gamma_brightness
);
2749 vo_gamma_brightness
= v
;
2751 vo_gamma_brightness
+= v
;
2753 if (vo_gamma_brightness
> 100)
2754 vo_gamma_brightness
= 100;
2755 else if (vo_gamma_brightness
< -100)
2756 vo_gamma_brightness
= -100;
2757 if(set_video_colors(sh_video
, "brightness", vo_gamma_brightness
)){
2760 osd_visible
=sh_video
->fps
; // 1 sec
2761 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
2762 vo_osd_progbar_value
=(vo_gamma_brightness
<<7)/100 + 128;
2763 vo_osd_changed(OSDTYPE_PROGBAR
);
2768 case MP_CMD_CONTRAST
: {
2769 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2774 if (vo_gamma_contrast
== 1000)
2776 vo_gamma_contrast
= 0;
2777 get_video_colors(sh_video
, "contrast", &vo_gamma_contrast
);
2781 vo_gamma_contrast
= v
;
2783 vo_gamma_contrast
+= v
;
2785 if (vo_gamma_contrast
> 100)
2786 vo_gamma_contrast
= 100;
2787 else if (vo_gamma_contrast
< -100)
2788 vo_gamma_contrast
= -100;
2789 if(set_video_colors(sh_video
, "contrast", vo_gamma_contrast
)){
2792 osd_visible
=sh_video
->fps
; // 1 sec
2793 vo_osd_progbar_type
=OSD_CONTRAST
;
2794 vo_osd_progbar_value
=(vo_gamma_contrast
<<7)/100 + 128;
2795 vo_osd_changed(OSDTYPE_PROGBAR
);
2800 case MP_CMD_SATURATION
: {
2801 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2806 if (vo_gamma_saturation
== 1000)
2808 vo_gamma_saturation
= 0;
2809 get_video_colors(sh_video
, "saturation", &vo_gamma_saturation
);
2813 vo_gamma_saturation
= v
;
2815 vo_gamma_saturation
+= v
;
2817 if (vo_gamma_saturation
> 100)
2818 vo_gamma_saturation
= 100;
2819 else if (vo_gamma_saturation
< -100)
2820 vo_gamma_saturation
= -100;
2821 if(set_video_colors(sh_video
, "saturation", vo_gamma_saturation
)){
2824 osd_visible
=sh_video
->fps
; // 1 sec
2825 vo_osd_progbar_type
=OSD_SATURATION
;
2826 vo_osd_progbar_value
=(vo_gamma_saturation
<<7)/100 + 128;
2827 vo_osd_changed(OSDTYPE_PROGBAR
);
2833 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2838 if (vo_gamma_hue
== 1000)
2841 get_video_colors(sh_video
, "hue", &vo_gamma_hue
);
2849 if (vo_gamma_hue
> 100)
2851 else if (vo_gamma_hue
< -100)
2852 vo_gamma_hue
= -100;
2853 if(set_video_colors(sh_video
, "hue", vo_gamma_hue
)){
2856 osd_visible
=sh_video
->fps
; // 1 sec
2857 vo_osd_progbar_type
=OSD_HUE
;
2858 vo_osd_progbar_value
=(vo_gamma_hue
<<7)/100 + 128;
2859 vo_osd_changed(OSDTYPE_PROGBAR
);
2864 case MP_CMD_FRAMEDROPPING
: {
2865 int v
= cmd
->args
[0].v
.i
;
2867 frame_dropping
= (frame_dropping
+1)%3;
2869 osd_show_framedropping
=10;
2870 vo_osd_changed(OSDTYPE_SUBTITLE
);
2874 frame_dropping
= v
> 2 ? 2 : v
;
2877 case MP_CMD_TV_SET_FREQ
: {
2878 if (file_format
== DEMUXER_TYPE_TV
)
2879 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
2881 case MP_CMD_TV_SET_NORM
: {
2882 if (file_format
== DEMUXER_TYPE_TV
)
2883 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
2885 case MP_CMD_TV_SET_BRIGHTNESS
: {
2886 if (file_format
== DEMUXER_TYPE_TV
)
2887 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_BRIGHTNESS
, cmd
->args
[0].v
.i
);
2889 case MP_CMD_TV_SET_HUE
: {
2890 if (file_format
== DEMUXER_TYPE_TV
)
2891 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_HUE
, cmd
->args
[0].v
.i
);
2893 case MP_CMD_TV_SET_SATURATION
: {
2894 if (file_format
== DEMUXER_TYPE_TV
)
2895 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_SATURATION
, cmd
->args
[0].v
.i
);
2897 case MP_CMD_TV_SET_CONTRAST
: {
2898 if (file_format
== DEMUXER_TYPE_TV
)
2899 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_CONTRAST
, cmd
->args
[0].v
.i
);
2901 case MP_CMD_TV_STEP_CHANNEL
: {
2902 if (file_format
== DEMUXER_TYPE_TV
) {
2903 int v
= cmd
->args
[0].v
.i
;
2905 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
2907 if (tv_channel_list
) {
2908 osd_show_tv_channel
= sh_video
->fps
;
2909 vo_osd_changed(OSDTYPE_SUBTITLE
);
2913 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
2915 if (tv_channel_list
) {
2916 osd_show_tv_channel
= sh_video
->fps
;
2917 vo_osd_changed(OSDTYPE_SUBTITLE
);
2923 #ifdef HAS_DVBIN_SUPPORT
2924 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
2926 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
2930 int v
= cmd
->args
[0].v
.i
;
2934 dir
= DVB_CHANNEL_HIGHER
;
2936 dir
= DVB_CHANNEL_LOWER
;
2939 if(dvb_step_channel(priv
, dir
))
2941 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
2942 cache_uninit(stream
);
2943 goto goto_enable_cache
;
2949 case MP_CMD_TV_SET_CHANNEL
: {
2950 if (file_format
== DEMUXER_TYPE_TV
) {
2951 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
2953 if (tv_channel_list
) {
2954 osd_show_tv_channel
= sh_video
->fps
;
2955 vo_osd_changed(OSDTYPE_SUBTITLE
);
2960 #ifdef HAS_DVBIN_SUPPORT
2961 case MP_CMD_DVB_SET_CHANNEL
:
2963 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
2965 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
2968 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
2973 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
2975 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
2976 cache_uninit(stream
);
2977 goto goto_enable_cache
;
2983 case MP_CMD_TV_LAST_CHANNEL
: {
2984 if (file_format
== DEMUXER_TYPE_TV
) {
2985 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
2987 if (tv_channel_list
) {
2988 osd_show_tv_channel
= sh_video
->fps
;
2989 vo_osd_changed(OSDTYPE_SUBTITLE
);
2994 case MP_CMD_TV_STEP_NORM
: {
2995 if (file_format
== DEMUXER_TYPE_TV
)
2996 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
2998 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
2999 if (file_format
== DEMUXER_TYPE_TV
)
3000 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
3003 case MP_CMD_VO_FULLSCREEN
:
3006 if ( use_gui
) guiGetEvent( guiIEvent
,(char *)MP_CMD_GUI_FULLSCREEN
);
3009 if(video_out
&& vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
3011 case MP_CMD_VO_ONTOP
:
3013 if(video_out
&& vo_config_count
) {
3014 video_out
->control(VOCTRL_ONTOP
, 0);
3017 vo_osd_changed(OSDTYPE_SUBTITLE
);
3022 case MP_CMD_PANSCAN
: {
3023 if ( !video_out
) break;
3024 if ( video_out
->control( VOCTRL_GET_PANSCAN
,NULL
) == VO_TRUE
)
3026 int abs
= cmd
->args
[1].v
.i
;
3027 float v
= cmd
->args
[0].v
.f
;
3030 else res
= vo_panscan
+v
;
3031 vo_panscan
= res
> 1 ? 1 : res
< 0 ? 0 : res
;
3032 video_out
->control( VOCTRL_SET_PANSCAN
,NULL
);
3034 if(osd_level
&& sh_video
){
3035 osd_visible
=sh_video
->fps
; // 1 sec
3036 vo_osd_progbar_type
=OSD_PANSCAN
;
3037 vo_osd_progbar_value
=vo_panscan
*256;
3038 vo_osd_changed(OSDTYPE_PROGBAR
);
3039 #ifdef HAVE_FREETYPE
3040 if (subtitle_autoscale
== 2 || subtitle_autoscale
== 3)
3041 // force scaling font to movie width or diagonal
3042 force_load_font
= 1;
3048 case MP_CMD_SUB_POS
:
3053 v
= cmd
->args
[0].v
.i
;
3056 if(sub_pos
>100) sub_pos
=100;
3057 if(sub_pos
<0) sub_pos
=0;
3058 vo_osd_changed(OSDTYPE_SUBTITLE
);
3059 osd_show_sub_pos
= 9;
3063 case MP_CMD_SUB_ALIGNMENT
:
3067 if (cmd
->nargs
>= 1)
3068 sub_alignment
= cmd
->args
[0].v
.i
;
3070 sub_alignment
= (sub_alignment
+1) % 3;
3071 osd_show_sub_alignment
= 9;
3072 vo_osd_changed(OSDTYPE_SUBTITLE
);
3076 case MP_CMD_SUB_VISIBILITY
:
3080 sub_visibility
=1-sub_visibility
;
3081 osd_show_sub_visibility
= 9; // show state of subtitle visibility in OSD
3082 vo_osd_changed(OSDTYPE_SUBTITLE
);
3086 case MP_CMD_GET_SUB_VISIBILITY
:
3090 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_SUB_VISIBILITY=%ld\n", sub_visibility
);
3094 case MP_CMD_VOBSUB_LANG
:
3097 int new_id
= vobsub_id
+ 1;
3100 if ((unsigned int) new_id
>= vobsub_get_indexes_count(vo_vobsub
))
3102 if(new_id
!= vobsub_id
)
3103 osd_show_vobsub_changed
= 9;
3107 else if (set_of_sub_size
> 0){ //change subtitle file
3108 set_of_sub_pos
= (set_of_sub_pos
+ 1) % set_of_sub_size
;
3109 subdata
= set_of_subtitles
[set_of_sub_pos
];
3110 osd_show_sub_changed
= sh_video
->fps
;
3112 vo_osd_changed(OSDTYPE_SUBTITLE
);
3116 case MP_CMD_SUB_FORCED_ONLY
:
3118 forced_subs_only
= forced_subs_only
? 0 : ~0; // toggle state
3119 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3122 case MP_CMD_SCREENSHOT
:
3123 if(vo_config_count
) video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
3125 case MP_CMD_VF_CHANGE_RECTANGLE
:
3126 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
3129 case MP_CMD_GET_TIME_LENGTH
: {
3130 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer
));
3133 case MP_CMD_GET_VO_FULLSCREEN
: {
3134 if(video_out
&& vo_config_count
)
3135 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_VO_FULLSCREEN=%ld\n", vo_fs
);
3138 case MP_CMD_GET_PERCENT_POS
: {
3139 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer
));
3143 case MP_CMD_DVDNAV_EVENT
: {
3144 dvdnav_priv_t
* dvdnav_priv
= (dvdnav_priv_t
*)(stream
->priv
);
3145 dvdnav_event_t
* dvdnav_event
= (dvdnav_event_t
*)(cmd
->args
[0].v
.v
);
3147 /* ignore these events if we're not in dvd_nav mode */
3148 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3150 if (!dvdnav_event
) {
3151 printf("DVDNAV Event NULL?!\n");
3155 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3157 switch (dvdnav_event
->event
) {
3158 case DVDNAV_BLOCK_OK
: {
3159 /* be silent about this one */
3162 case DVDNAV_HIGHLIGHT
: {
3163 dvdnav_highlight_event_t
*hevent
= (dvdnav_highlight_event_t
*)(dvdnav_event
->details
);
3165 printf("DVDNAV Event: Highlight event broken\n");
3169 if (hevent
->display
&& hevent
->buttonN
>0)
3171 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3172 sprintf( dvd_nav_text
, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3174 hevent
->sx
,hevent
->sy
,
3175 hevent
->ex
,hevent
->ey
,
3176 hevent
->pts
, d_video
->pts
);
3177 printf("DVDNAV Event: %s\n",dvd_nav_text
);
3178 //osd_show_dvd_nav_delay = 60;
3180 osd_show_dvd_nav_highlight
=1;
3181 osd_show_dvd_nav_sx
=hevent
->sx
;
3182 osd_show_dvd_nav_ex
=hevent
->ex
;
3183 osd_show_dvd_nav_sy
=hevent
->sy
;
3184 osd_show_dvd_nav_ey
=hevent
->ey
;
3187 osd_show_dvd_nav_highlight
=0;
3188 printf("DVDNAV Event: Highlight Hide\n");
3192 case DVDNAV_STILL_FRAME
: {
3193 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*)(dvdnav_event
->details
);
3195 printf( "######################################## DVDNAV Event: Still Frame: %d sec(s)\n", still_event
->length
);
3196 while (dvdnav_stream_sleeping(dvdnav_priv
)) {
3197 usec_sleep(1000); /* 1ms */
3199 dvdnav_stream_sleep(dvdnav_priv
,still_event
->length
);
3203 printf( "DVDNAV Event: Nav Stop\n" );
3207 printf("DVDNAV Event: Nav NOP\n");
3210 case DVDNAV_SPU_STREAM_CHANGE
: {
3211 #if DVDNAVVERSION > 012
3212 dvdnav_spu_stream_change_event_t
*stream_change
= (dvdnav_spu_stream_change_event_t
*)(dvdnav_event
->details
);
3214 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d/%d/%d logical: %d\n",
3215 stream_change
->physical_wide
,
3216 stream_change
->physical_letterbox
,
3217 stream_change
->physical_pan_scan
,
3218 stream_change
->logical
);
3220 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical_wide
) {
3221 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3222 d_dvdsub
->id
,stream_change
->physical_wide
);
3223 // FIXME: need a better way to change SPU id
3224 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical_wide
;
3225 if (vo_spudec
) spudec_reset(vo_spudec
);
3228 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3230 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n",
3231 stream_change
->physical
,
3232 stream_change
->logical
);
3234 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical
) {
3235 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3236 d_dvdsub
->id
,stream_change
->physical
);
3237 // FIXME: need a better way to change SPU id
3238 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical
;
3239 if (vo_spudec
) spudec_reset(vo_spudec
);
3244 case DVDNAV_AUDIO_STREAM_CHANGE
: {
3246 #if DVDNAVVERSION > 012
3247 dvdnav_audio_stream_change_event_t
*stream_change
= (dvdnav_audio_stream_change_event_t
*)(dvdnav_event
->details
);
3249 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3252 printf("DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n",
3253 stream_change
->physical
,
3254 stream_change
->logical
);
3256 aid_temp
=stream_change
->physical
;
3257 if (aid_temp
>=0) aid_temp
+=128; // FIXME: is this sane?
3258 if (d_audio
&& audio_id
!=aid_temp
) {
3259 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_audio->id change: was %d is now %d\n",
3260 d_audio
->id
,aid_temp
);
3261 // FIXME: need a bettery way to change audio stream id
3262 d_audio
->id
=dvdsub_id
=aid_temp
;
3263 if(sh_audio
) resync_audio_stream(sh_audio
);
3268 case DVDNAV_VTS_CHANGE
: {
3269 printf("DVDNAV Event: Nav VTS Change\n");
3272 case DVDNAV_CELL_CHANGE
: {
3273 dvdnav_cell_change_event_t
*cell_change
= (dvdnav_cell_change_event_t
*)(dvdnav_event
->details
);
3274 cell_playback_t
* cell_playback
= cell_change
->new_cell
;
3276 printf("DVDNAV Event: Nav Cell Change\n");
3277 osd_show_dvd_nav_highlight
=0; /* screen changed, disable menu */
3279 printf("new still time: %d\n",cell_playback->still_time);
3280 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3281 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3282 cell_playback->playback_time.hour,
3283 cell_playback->playback_time.minute,
3284 cell_playback->playback_time.second,
3285 cell_playback->playback_time.frame_u);
3288 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3292 case DVDNAV_NAV_PACKET
: {
3293 // printf("DVDNAV Event: Nav Packet\n");
3296 case DVDNAV_SPU_CLUT_CHANGE
: {
3297 uint32_t * new_clut
= (uint32_t *)(dvdnav_event
->details
);
3299 printf("DVDNAV Event: Nav SPU CLUT Change\n");
3300 // send new palette to SPU decoder
3301 if (vo_spudec
) spudec_update_palette(vo_spudec
,new_clut
);
3305 case DVDNAV_SEEK_DONE
: {
3306 printf("DVDNAV Event: Nav Seek Done\n");
3311 // free the dvdnav event
3312 free(dvdnav_event
->details
);
3314 cmd
->args
[0].v
.v
=NULL
;
3316 case MP_CMD_DVDNAV
: {
3317 dvdnav_priv_t
* dvdnav_priv
=(dvdnav_priv_t
*)stream
->priv
;
3319 /* ignore these events if we're not in dvd_nav mode */
3320 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3322 switch (cmd
->args
[0].v
.i
) {
3323 case MP_CMD_DVDNAV_UP
:
3324 dvdnav_upper_button_select(dvdnav_priv
->dvdnav
);
3326 case MP_CMD_DVDNAV_DOWN
:
3327 dvdnav_lower_button_select(dvdnav_priv
->dvdnav
);
3329 case MP_CMD_DVDNAV_LEFT
:
3330 dvdnav_left_button_select(dvdnav_priv
->dvdnav
);
3332 case MP_CMD_DVDNAV_RIGHT
:
3333 dvdnav_right_button_select(dvdnav_priv
->dvdnav
);
3335 case MP_CMD_DVDNAV_MENU
:
3336 printf("Menu call\n");
3337 dvdnav_menu_call(dvdnav_priv
->dvdnav
,DVD_MENU_Root
);
3339 case MP_CMD_DVDNAV_SELECT
:
3340 dvdnav_button_activate(dvdnav_priv
->dvdnav
);
3343 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Weird DVD Nav cmd %d\n",cmd
->args
[0].v
.i
);
3351 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3354 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
3364 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
3365 rel_seek_secs
+= 3600*a
+60*b
+d
;
3366 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
3367 rel_seek_secs
+= 60*a
+d
;
3368 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
3375 if(eof
==1 && loop_times
>=0) {
3377 play_tree_iter_step(playtree_iter
,0,0);
3379 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
3381 if(loop_times
>1) loop_times
--; else
3382 if(loop_times
==1) loop_times
=-1;
3383 play_n_frames
=play_n_frames_mf
;
3385 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
3389 if(rel_seek_secs
|| abs_seek_pos
){
3390 current_module
="seek";
3391 if(demux_seek(demuxer
,rel_seek_secs
,abs_seek_pos
)){
3393 /* FIXME there should be real seeking for vobsub */
3394 if(sh_video
) sh_video
->pts
=d_video
->pts
;
3396 //vobsub_reset(vo_vobsub);
3397 vobsub_seek(vo_vobsub
,sh_video
->pts
);
3399 if(sh_video
&& d_video
->packs
== 0)
3400 ds_fill_buffer(d_video
);
3402 if(d_audio
->packs
== 0)
3403 ds_fill_buffer(d_audio
);
3405 float a_pts
=d_audio
->pts
;
3406 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
3407 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
);
3409 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
);
3411 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A: --- V:%6.1f \r",d_video
->pts
);
3417 current_module
="seek_video_reset";
3418 resync_video_stream(sh_video
);
3419 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
3423 current_module
="seek_audio_reset";
3424 audio_out
->reset(); // stop audio, throwing away buffered data
3428 if(osd_level
&& !loop_seek
){
3430 if( !edl_decision
) {
3432 if( 1 ) { // Let the compiler optimize this out
3434 int len
=((demuxer
->movi_end
-demuxer
->movi_start
)>>8);
3435 if (len
>0 && sh_video
){
3436 osd_visible
=sh_video
->fps
; // 1 sec
3437 vo_osd_progbar_type
=0;
3438 vo_osd_progbar_value
=(demuxer
->filepos
-demuxer
->movi_start
)/len
;
3439 vo_osd_changed(OSDTYPE_PROGBAR
);
3446 max_pts_correction
=0.1;
3447 osd_visible
=sh_video
->fps
; // to rewert to PLAY pointer after 1 sec
3448 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3450 too_slow_frame_cnt
=0;
3451 too_fast_frame_cnt
=0;
3453 if(vo_spudec
) spudec_reset(vo_spudec
);
3459 if( !edl_decision
) {
3460 for( x
= 0; x
< num_edl_records
; x
++ ) { // FIXME: do binary search
3461 // Find first EDL entry where start follows current time
3462 if( edl_records
[ x
].start_sec
>= sh_video
->pts
&& edl_records
[ x
].action
!= EDL_MUTE
) {
3463 next_edl_record
= &edl_records
[ x
];
3474 frame_time_remaining
=0;
3475 current_module
=NULL
;
3482 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
3483 // get pos from frame number / total frames
3484 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
3486 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
3487 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
3488 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
3490 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
3491 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
3492 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
3493 guiGetEvent( guiReDraw
,NULL
);
3494 guiGetEvent( guiSetVolume
,NULL
);
3495 if(guiIntfStruct
.Playing
==0) break; // STOP
3496 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
3497 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3499 if ( stream
->type
== STREAMTYPE_DVD
)
3501 dvd_priv_t
* dvdp
= stream
->priv
;
3502 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3509 //================= Update OSD ====================
3511 if(osd_level
>=1 && sh_video
){
3512 int pts
=sh_video
->pts
;
3513 char osd_text_tmp
[64];
3514 if(pts
==osd_last_pts
-1) ++pts
; else osd_last_pts
=pts
;
3515 vo_osd_text
=osd_text_buffer
;
3517 if (osd_show_dvd_nav_delay
) {
3518 snprintf(osd_text_tmp
, 63, "DVDNAV: %s", dvd_nav_text
);
3519 osd_show_dvd_nav_delay
--;
3523 if (osd_show_tv_channel
&& tv_channel_list
) {
3524 snprintf(osd_text_tmp
, 63, "Channel: %s", tv_channel_current
->name
);
3525 osd_show_tv_channel
--;
3528 if (osd_show_text
) {
3529 snprintf(osd_text_tmp
, 63, "%s", osd_show_text_buffer
);
3532 if (osd_show_sub_visibility
) {
3533 snprintf(osd_text_tmp
, 63, "Subtitles: %sabled", sub_visibility
?"en":"dis");
3534 osd_show_sub_visibility
--;
3536 if (osd_show_vobsub_changed
) {
3537 const char *language
= "none";
3538 if (vo_vobsub
&& vobsub_id
>= 0)
3539 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
3540 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", vobsub_id
, language
? language
: "unknown");
3541 osd_show_vobsub_changed
--;
3544 if (osd_show_sub_changed
) {
3546 tmp
= subdata
->filename
;
3547 if ((tmp2
= strrchr(tmp
, '/'))) {
3550 snprintf(osd_text_tmp
, 63, "Sub: (%d) %s%s",
3552 strlen(tmp
) < 20 ? "" : "...",
3553 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
3554 osd_show_sub_changed
--;
3557 if (osd_show_sub_delay
) {
3558 snprintf(osd_text_tmp
, 63, "Sub delay: %d ms", ROUND(sub_delay
*1000));
3559 osd_show_sub_delay
--;
3561 if (osd_show_sub_pos
) {
3562 snprintf(osd_text_tmp
, 63, "Sub position: %d/100", sub_pos
);
3565 if (osd_show_sub_alignment
) {
3566 snprintf(osd_text_tmp
, 63, "Sub alignment: %s",
3567 (sub_alignment
== 2 ? "bottom" :
3568 (sub_alignment
== 1 ? "center" : "top")));
3569 osd_show_sub_alignment
--;
3571 if (osd_show_av_delay
) {
3572 snprintf(osd_text_tmp
, 63, "A-V delay: %d ms", ROUND(audio_delay
*1000));
3573 osd_show_av_delay
--;
3574 } else if (osd_show_ontop
) {
3575 snprintf(osd_text_tmp
, 63, "Stay on top: %sabled", vo_ontop
?"en":"dis");
3577 } else if (osd_show_framedropping
) {
3578 snprintf(osd_text_tmp
, 63, "Framedropping: %s",
3579 (frame_dropping
== 1 ? "on" :
3580 (frame_dropping
== 2 ? "hard" : "off")));
3581 osd_show_framedropping
--;
3582 } else if(osd_level
>=2) {
3583 int len
= demuxer_get_time_length(demuxer
);
3584 int percentage
= -1;
3585 char percentage_text
[10];
3586 if (osd_show_percentage
) {
3587 percentage
= demuxer_get_percent_pos(demuxer
);
3588 osd_show_percentage
--;
3590 if (percentage
>= 0)
3591 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
3593 percentage_text
[0] = 0;
3595 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
);
3597 snprintf(osd_text_tmp
, 63, "%c %02d:%02d:%02d%s",osd_function
,pts
/3600,(pts
/60)%60,pts
%60,percentage_text
);
3598 } else osd_text_tmp
[0]=0;
3600 if(strcmp(vo_osd_text
, osd_text_tmp
)) {
3601 strncpy(vo_osd_text
, osd_text_tmp
, 63);
3602 vo_osd_changed(OSDTYPE_OSD
);
3607 vo_osd_changed(OSDTYPE_OSD
);
3610 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3611 // vo_osd_text=osd_text_buffer;
3616 if(subdata
&& sh_video
->pts
>0){
3617 float pts
=sh_video
->pts
;
3618 if(sub_fps
==0) sub_fps
=sh_video
->fps
;
3619 current_module
="find_sub";
3620 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0 ) {
3621 find_sub(subdata
, (pts
+sub_delay
) *
3622 (subdata
->sub_uses_time
? 100. : sub_fps
));
3623 // FIXME! frame counter...
3626 current_module
=NULL
;
3631 if (stop_xscreensaver
&& sh_video
) {
3632 current_module
="stop_xscreensaver";
3633 xscreensaver_heartbeat();
3634 current_module
=NULL
;
3639 if(vo_config_count
&& vo_spudec
) {
3640 unsigned char* packet
=NULL
;
3642 current_module
="spudec";
3643 spudec_heartbeat(vo_spudec
,90000*sh_video
->timer
);
3644 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3649 if(sh_video
->pts
+sub_delay
>=0) {
3650 // The + next_frame_time is there because we'll display the sub at the next frame
3651 len
= vobsub_get_packet(vo_vobsub
,sh_video
->pts
+sub_delay
+next_frame_time
,(void**)&packet
,×tamp
);
3653 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
3654 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
);
3659 len
= ds_get_packet_sub(d_dvdsub
,(unsigned char**)&packet
);
3661 float x
= d_dvdsub
->pts
- sh_video
->pts
;
3662 if (x
< -10 || x
> 10) // prevent missing subs on pts reset
3663 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
+ sub_delay
- sh_video
->pts
);
3664 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
3665 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
);
3668 if(len
<=0 || !packet
) break;
3669 if(timestamp
< 0) timestamp
= 0;
3670 else spudec_assemble(vo_spudec
,packet
,len
,timestamp
);
3673 /* detect wether the sub has changed or not */
3674 if(spudec_changed(vo_spudec
))
3675 vo_osd_changed(OSDTYPE_SPU
);
3676 current_module
=NULL
;
3681 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
3685 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3687 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3690 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3691 double total_time_usage
;
3692 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3693 total_time_usage
= (float)total_time_usage_start
*0.000001;
3694 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3695 video_time_usage
,vout_time_usage
,audio_time_usage
,
3696 total_time_usage
-tot
,total_time_usage
);
3697 if(total_time_usage
>0.0)
3698 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3699 100.0*video_time_usage
/total_time_usage
,
3700 100.0*vout_time_usage
/total_time_usage
,
3701 100.0*audio_time_usage
/total_time_usage
,
3702 100.0*(total_time_usage
-tot
)/total_time_usage
,
3704 if(total_frame_cnt
&& frame_dropping
)
3705 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3706 total_frame_cnt
-drop_frame_cnt
,
3707 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3709 100*drop_frame_cnt
/total_frame_cnt
,
3711 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
3715 // time to uninit all, except global stuff:
3716 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
3719 if ( set_of_sub_size
> 0 )
3721 current_module
="sub_free";
3722 for (i
= 0; i
< set_of_sub_size
; ++i
)
3723 sub_free( set_of_subtitles
[i
] );
3724 set_of_sub_size
= 0;
3730 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
3731 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
3732 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
3735 play_tree_iter_free(playtree_iter
);
3736 playtree_iter
= NULL
;
3739 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
3740 eof
= eof
== PT_UP_NEXT
? 1 : -1;
3741 if ( playtree_iter
) {
3742 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
3745 play_tree_iter_free(playtree_iter
);
3746 playtree_iter
= NULL
;
3749 } else { // NEXT PREV SRC
3750 eof
= eof
== PT_PREV_SRC
? -1 : 1;
3753 if(eof
== 0) eof
= 1;
3755 while(playtree_iter
!= NULL
) {
3756 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
3757 if(filename
== NULL
) {
3758 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
3759 play_tree_iter_free(playtree_iter
);
3760 playtree_iter
= NULL
;
3767 if( use_gui
&& !playtree_iter
)
3770 if ( !guiIntfStruct
.DiskChanged
)
3776 if(use_gui
|| playtree_iter
!= NULL
){
3779 goto play_next_file
;
3782 #ifdef HAVE_FREETYPE
3783 current_module
="uninit_font";
3784 if (vo_font
) free_font_desc(vo_font
);
3789 exit_player_with_rc(MSGTR_Exit_eof
, 0);