6 // #include <sys/mman.h>
12 #define SIGHUP 1 /* hangup */
13 #define SIGQUIT 3 /* quit */
14 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
15 #define SIGBUS 10 /* bus error */
16 extern int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
);
34 #define HELP_MP_DEFINE_STATIC
40 #include "cfg-mplayer-def.h"
43 #include "subreader.h"
46 #include "libvo/video_out.h"
48 #include "libvo/font_load.h"
49 #include "libvo/sub.h"
52 #include "libvo/x11_common.h"
55 #include "libao2/audio_out.h"
56 #include "libao2/audio_plugin.h"
58 #include "codec-cfg.h"
61 #include "libmpdemux/dvdauth.h"
75 #include "osdep/getch2.h"
76 #include "osdep/timer.h"
78 #include "cpudetect.h"
81 #include "Gui/interface.h"
84 #include "input/input.h"
91 #define ABS(x) (((x)>=0)?(x):(-(x)))
92 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
95 #include <linux/rtc.h>
99 #include "libmpdemux/tv.h"
102 #ifdef HAS_DVBIN_SUPPORT
103 #include "libmpdemux/dvbin.h"
104 static int last_dvb_step
= 1;
108 #include "libmpdemux/matroska.h"
111 //**************************************************************************//
113 //**************************************************************************//
114 #include "playtree.h"
115 #include "playtreeparser.h"
118 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
119 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
122 play_tree_t
* playtree
;
123 play_tree_iter_t
* playtree_iter
= NULL
;
125 #define PT_NEXT_ENTRY 1
126 #define PT_PREV_ENTRY -1
127 #define PT_NEXT_SRC 2
128 #define PT_PREV_SRC -2
130 #define PT_UP_PREV -3
132 //**************************************************************************//
134 //**************************************************************************//
138 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
);
140 m_config_parse_config_file(m_config_t
* config
, char *conffile
);
142 //**************************************************************************//
144 //**************************************************************************//
146 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
148 static int cfg_include(m_option_t
*conf
, char *filename
){
149 return m_config_parse_config_file(mconfig
, filename
);
152 #include "get_path.c"
154 //**************************************************************************//
156 //**************************************************************************//
159 void xscreensaver_heartbeat(float time
);
162 //**************************************************************************//
163 //**************************************************************************//
164 // Input media streaming & demultiplexer:
165 //**************************************************************************//
167 static int max_framesize
=0;
169 #include "libmpdemux/stream.h"
170 #include "libmpdemux/demuxer.h"
171 #include "libmpdemux/stheader.h"
172 //#include "parse_es.h"
174 #include "libmpcodecs/dec_audio.h"
175 #include "libmpcodecs/dec_video.h"
176 #include "libmpcodecs/mp_image.h"
177 #include "libmpcodecs/vf.h"
179 extern void vf_list_plugins();
181 //**************************************************************************//
182 //**************************************************************************//
184 // Common FIFO functions, and keyboard/event FIFO code
187 //**************************************************************************//
189 vo_functions_t
*video_out
=NULL
;
190 ao_functions_t
*audio_out
=NULL
;
195 double video_time_usage
=0;
196 double vout_time_usage
=0;
197 static double audio_time_usage
=0;
198 static int total_time_usage_start
=0;
199 static int total_frame_cnt
=0;
200 static int drop_frame_cnt
=0; // total number of dropped frames
205 static int output_quality
=0;
207 float playback_speed
=1.0;
215 #define MAX_OSD_LEVEL 3
218 int osd_level_saved
=-1;
222 static char *seek_to_sec
=NULL
;
223 static off_t seek_to_byte
=0;
224 static off_t step_sec
=0;
225 static int loop_times
=-1;
226 static int loop_seek
=0;
229 int autosync
=0; // 30 might be a good default value.
231 // may be changed by GUI: (FIXME!)
232 float rel_seek_secs
=0;
236 char **audio_codec_list
=NULL
; // override audio codec
237 char **video_codec_list
=NULL
; // override video codec
238 char **audio_fm_list
=NULL
; // override audio codec family
239 char **video_fm_list
=NULL
; // override video codec family
246 char* audio_lang
=NULL
;
247 char* dvdsub_lang
=NULL
;
248 static char* spudec_ifo
=NULL
;
249 char* filename
=NULL
; //"MI2-Trailer.avi";
250 int forced_subs_only
=0;
253 int stream_cache_size
=-1;
254 #ifdef USE_STREAM_CACHE
255 extern int cache_fill_status
;
257 #define cache_fill_status 0
261 static char *stream_dump_name
="stream.dump";
262 int stream_dump_type
=0;
265 static float default_max_pts_correction
=-1;//0.01f;
266 static float max_pts_correction
=0;//default_max_pts_correction;
267 static float c_total
=0;
270 static int softsleep
=0;
273 static int force_srate
=0;
274 static int audio_output_format
=0;
275 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
276 static int play_n_frames
=-1;
277 static int play_n_frames_mf
=-1;
280 char** video_driver_list
=NULL
;
281 char** audio_driver_list
=NULL
;
283 extern char *vo_subdevice
;
284 extern char *ao_subdevice
;
286 // codec outfmt flags (defined in libmpcodecs/vd.c)
290 char *font_name
=NULL
;
291 float font_factor
=0.75;
292 char **sub_name
=NULL
;
296 char *vobsub_name
=NULL
;
297 /*DSP!!char *dsp=NULL;*/
299 int suboverlap_enabled
= 1;
301 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
302 int set_of_sub_size
= 0;
303 int set_of_sub_pos
= -1;
304 float sub_last_pts
= -303;
307 static stream_t
* stream
=NULL
;
308 static demuxer_t
*demuxer
=NULL
;
309 static sh_audio_t
*sh_audio
=NULL
;
310 static sh_video_t
*sh_video
=NULL
;
312 char* current_module
=NULL
; // for debugging
314 // also modified by Gui/mplayer/gtk/eq.c:
315 int vo_gamma_gamma
= 1000;
316 int vo_gamma_brightness
= 1000;
317 int vo_gamma_contrast
= 1000;
318 int vo_gamma_saturation
= 1000;
319 int vo_gamma_hue
= 1000;
324 #include "m_struct.h"
325 #include "libmenu/menu.h"
326 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
327 extern vf_info_t vf_info_menu
;
328 static vf_info_t
* libmenu_vfs
[] = {
332 static vf_instance_t
* vf_menu
= NULL
;
333 static int use_menu
= 0;
334 static char* menu_cfg
= NULL
;
335 static char* menu_root
= "main";
344 struct edl_record edl_records
[ MAX_EDL_ENTRIES
];
345 int num_edl_records
= 0;
347 edl_record_ptr next_edl_record
= NULL
;
348 static char* edl_filename
= NULL
;
349 static char* edl_output_filename
= NULL
;
350 short edl_decision
= 0;
353 static unsigned int inited_flags
=0;
357 #define INITED_GETCH2 8
358 #define INITED_SPUDEC 32
359 #define INITED_STREAM 64
360 #define INITED_INPUT 128
361 #define INITED_VOBSUB 256
362 #define INITED_DEMUXER 512
363 #define INITED_ACODEC 1024
364 #define INITED_VCODEC 2048
365 #define INITED_ALL 0xFFFF
367 static void uninit_player(unsigned int mask
){
368 mask
=inited_flags
&mask
;
370 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
372 if(mask
&INITED_ACODEC
){
373 inited_flags
&=~INITED_ACODEC
;
374 current_module
="uninit_acodec";
375 if(sh_audio
) uninit_audio(sh_audio
);
379 if(mask
&INITED_VCODEC
){
380 inited_flags
&=~INITED_VCODEC
;
381 current_module
="uninit_vcodec";
382 if(sh_video
) uninit_video(sh_video
);
389 if(mask
&INITED_DEMUXER
){
390 inited_flags
&=~INITED_DEMUXER
;
391 current_module
="free_demuxer";
393 stream
=demuxer
->stream
;
394 free_demuxer(demuxer
);
399 // kill the cache process:
400 if(mask
&INITED_STREAM
){
401 inited_flags
&=~INITED_STREAM
;
402 current_module
="uninit_stream";
403 if(stream
) free_stream(stream
);
408 inited_flags
&=~INITED_VO
;
409 current_module
="uninit_vo";
414 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
415 if(mask
&INITED_GETCH2
){
416 inited_flags
&=~INITED_GETCH2
;
417 current_module
="uninit_getch2";
418 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
423 if(mask
&INITED_VOBSUB
){
424 inited_flags
&=~INITED_VOBSUB
;
425 current_module
="uninit_vobsub";
426 if(vo_vobsub
) vobsub_close(vo_vobsub
);
430 if (mask
&INITED_SPUDEC
){
431 inited_flags
&=~INITED_SPUDEC
;
432 current_module
="uninit_spudec";
433 spudec_free(vo_spudec
);
438 inited_flags
&=~INITED_AO
;
439 current_module
="uninit_ao";
440 audio_out
->uninit(); audio_out
=NULL
;
445 inited_flags
&=~INITED_GUI
;
446 current_module
="uninit_gui";
451 if(mask
&INITED_INPUT
){
452 inited_flags
&=~INITED_INPUT
;
453 current_module
="uninit_input";
460 static void exit_player_with_rc(char* how
, int rc
){
462 uninit_player(INITED_ALL
);
467 vo_uninit(); // close the X11 connection (if any opened)
470 current_module
="exit_player";
472 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Exiting
,mp_gettext(how
));
473 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
478 void exit_player(char* how
){
479 exit_player_with_rc(how
, 1);
482 static void exit_sighandler(int x
){
483 static int sig_count
=0;
485 if(sig_count
==5 || (inited_flags
==0 && sig_count
>1)) exit(1);
489 kill(getpid(),SIGKILL
);
492 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
493 current_module
?current_module
:mp_gettext("unknown")
501 break; // killed from keyboard (^C) or killed [-9]
503 #ifdef RUNTIME_CPUDETECT
504 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
506 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
510 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
512 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
517 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
519 extern void mp_input_register_options(m_config_t
* cfg
);
522 #include "cfg-mplayer.h"
524 void parse_cfgfiles( m_config_t
* conf
)
528 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
530 if ((conffile
= get_path("")) == NULL
) {
531 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
536 mkdir(conffile
, 0777);
539 if ((conffile
= get_path("config")) == NULL
) {
540 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
542 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
543 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
544 write(conffile_fd
, default_config
, strlen(default_config
));
547 if (m_config_parse_config_file(conf
, conffile
) < 0)
554 void load_per_file_config (m_config_t
* conf
, const char *const file
)
557 char cfg
[strlen(file
)+10];
561 sprintf (cfg
, "%s.conf", file
);
563 if (!stat (cfg
, &st
))
565 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Loading config '%s'\n", cfg
);
566 m_config_parse_config_file (conf
, cfg
);
570 if ((name
= strrchr (cfg
, '/')) == NULL
)
575 if ((confpath
= get_path (name
)) != NULL
)
577 if (!stat (confpath
, &st
))
579 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Loading config '%s'\n", confpath
);
580 m_config_parse_config_file (conf
, confpath
);
587 // When libmpdemux perform a blocking operation (network connection or cache filling)
588 // if the operation fail we use this function to check if it was interrupted by the user.
589 // The function return a new value for eof.
590 static int libmpdemux_was_interrupted(int eof
) {
592 if((cmd
= mp_input_get_cmd(0,0)) != NULL
) {
595 exit_player_with_rc(MSGTR_Exit_quit
, 0);
596 case MP_CMD_PLAY_TREE_STEP
: {
597 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
599 case MP_CMD_PLAY_TREE_UP_STEP
: {
600 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
602 case MP_CMD_PLAY_ALT_SRC_STEP
: {
603 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
611 #define mp_basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
613 int playtree_add_playlist(play_tree_t
* entry
)
615 play_tree_add_bpf(entry
,filename
);
620 import_playtree_playlist_into_gui(entry
, mconfig
);
621 play_tree_free_list(entry
,1);
627 entry
= playtree_iter
->tree
;
628 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
629 return PT_NEXT_ENTRY
;
631 if(playtree_iter
->tree
== entry
) { // Loop with a single file
632 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
633 return PT_NEXT_ENTRY
;
636 play_tree_remove(entry
,1,1);
639 play_tree_insert_entry(playtree_iter
->tree
,entry
);
640 play_tree_set_params_from(entry
,playtree_iter
->tree
);
641 entry
= playtree_iter
->tree
;
642 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
643 return PT_NEXT_ENTRY
;
645 play_tree_remove(entry
,1,1);
650 static int play_tree_step
= 1;
654 sub_data
* subdata
= NULL
;
656 void add_subtitles(char *filename
, float fps
, int silent
)
660 if (filename
== NULL
) {
661 subd
= (sub_data
*)malloc(sizeof(sub_data
));
662 subd
->filename
= strdup("none");
663 subd
->subtitles
= NULL
;
664 subd
->sub_uses_time
= 1;
667 set_of_subtitles
[set_of_sub_size
] = subd
;
672 subd
= sub_read_file(filename
, fps
);
674 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
675 if (subd
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) return;
676 set_of_subtitles
[set_of_sub_size
] = subd
;
678 printf("SUB: added subtitle file (%d): %s\n", set_of_sub_size
, filename
);
681 void update_set_of_subtitles()
682 // subdata was changed, set_of_sub... have to be updated.
685 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
686 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
687 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
688 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
690 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
692 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
693 set_of_subtitles
[set_of_sub_pos
] = subdata
;
695 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
696 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
703 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
704 * make it all work is to use the builtin SDL-bootstrap code, which
705 * will be done automatically by replacing our main() if we include SDL.h.
707 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
712 int main(int argc
,char* argv
[]){
716 static demux_stream_t
*d_audio
=NULL
;
717 static demux_stream_t
*d_video
=NULL
;
718 static demux_stream_t
*d_dvdsub
=NULL
;
720 int file_format
=DEMUXER_TYPE_UNKNOWN
;
722 int delay_corrected
=1;
727 int osd_function
=OSD_PLAY
;
728 int osd_last_pts
=-303;
729 int osd_show_av_delay
= 0;
730 int osd_show_text
= 0;
731 int osd_show_sub_delay
= 0;
732 int osd_show_sub_pos
= 0;
733 int osd_show_sub_visibility
= 0;
734 int osd_show_sub_alignment
= 0;
735 int osd_show_vobsub_changed
= 0;
736 int osd_show_sub_changed
= 0;
737 int osd_show_percentage
= 0;
738 int osd_show_tv_channel
= 25;
742 //float a_frame=0; // Audio
747 int gui_no_filename
=0;
750 srand((int) time(NULL
));
753 mp_msg_set_level(MSGL_STATUS
);
755 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2003 MPlayer Team\n\n");
756 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
757 GetCpuCaps(&gCpuCaps
);
759 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
760 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
761 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
762 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
763 #ifdef RUNTIME_CPUDETECT
764 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
766 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
768 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
771 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
774 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
777 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
780 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
783 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
785 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n\n");
789 #if defined(WIN32) && defined(USE_WIN32DLL)
790 { /*make our codec dirs available for LoadLibraryA()*/
791 char tmppath
[MAX_PATH
*2 + 1];
792 char win32path
[MAX_PATH
];
793 char realpath
[MAX_PATH
];
794 int WINAPI
SetEnvironmentVariableA(char*,char*);
795 int WINAPI
GetModuleFileNameA(void*,char*,int);
797 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
798 strcpy(tmppath
,win32path
);
799 #ifdef USE_REALCODECS
800 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
801 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
802 #endif /*USE_REALCODECS*/
804 if(!strstr(WIN32_PATH
,":")){
805 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
806 strcpy(win32path
+ strlen(win32path
) - strlen("mplayer.exe"), WIN32_PATH
);
808 else strcpy(win32path
,WIN32_PATH
);
809 strcpy(tmppath
,win32path
);
810 #ifdef USE_REALCODECS
811 if(!strstr(REALCODEC_PATH
,":")){
812 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
813 strcpy(realpath
+ strlen(realpath
) - strlen("mplayer.exe"), REALCODEC_PATH
);
815 else strcpy(realpath
,REALCODEC_PATH
);
816 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
817 #endif /*USE_REALCODECS*/
818 #endif /*__CYGWIN__*/
819 SetEnvironmentVariableA("PATH", tmppath
);
821 #endif /*WIN32 && USE_WIN32DLL*/
824 tv_param_immediate
= 1;
828 if(!strcmp(argv
[0],"gmplayer") ||
829 (strrchr(argv
[0],'/') && !strcmp(strrchr(argv
[0],'/'),"/gmplayer") ) )
832 mconfig
= m_config_new();
833 m_config_register_options(mconfig
,mplayer_opts
);
834 // TODO : add something to let modules register their options
835 mp_input_register_options(mconfig
);
836 parse_cfgfiles(mconfig
);
839 if ( use_gui
) cfg_read();
842 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
846 playtree
= play_tree_cleanup(playtree
);
848 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
850 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
851 play_tree_iter_free(playtree_iter
);
852 playtree_iter
= NULL
;
854 filename
= play_tree_iter_get_file(playtree_iter
,1);
860 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
864 if(use_gui
&& !vo_init()){
865 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
868 if (use_gui
&& playtree_iter
){
869 char cwd
[PATH_MAX
+2];
870 // Remove Playtree and Playtree-Iter from memory as its not used by gui
871 play_tree_iter_free(playtree_iter
);
874 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
877 // Prefix relative paths with current working directory
878 play_tree_add_bpf(playtree
, cwd
);
880 // Import initital playtree into gui
881 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
885 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
890 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
896 if(!parse_codec_cfg(get_path("codecs.conf"))){
897 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
898 if(!parse_codec_cfg(NULL
)){
899 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
902 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_BuiltinCodecsConf
);
907 if(video_codec_list
){
909 video_codec
=video_codec_list
[0];
910 for(i
=0;video_codec_list
[i
];i
++)
911 printf("vc#%d: '%s'\n",i
,video_codec_list
[i
]);
914 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
915 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
920 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
921 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
926 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
931 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
937 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
948 float start
, stop
, duration
;
950 int next_edl_array_index
= 0;
952 next_edl_record
= edl_records
;
954 if( ( fd
= fopen( edl_filename
, "r" ) ) == NULL
) {
955 printf( "Error opening EDL file [%s]!\n", edl_filename
);
956 next_edl_record
->next
= NULL
;
958 while( fgets( line
, 99, fd
) != NULL
) {
960 if( ( sscanf( line
, "%f %f %d", &start
, &stop
, &action
) ) == 0 ) {
961 printf( "Invalid EDL line: [%s]\n", line
);
963 if( next_edl_array_index
> 0 ) {
964 edl_records
[ next_edl_array_index
-1 ].next
= &edl_records
[ next_edl_array_index
];
965 if( start
<= edl_records
[ next_edl_array_index
-1 ].stop_sec
) {
966 printf( "Invalid EDL line [%d]: [%s]\n", lineCount
, line
);
967 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
);
971 if( stop
<= start
) {
972 printf( "Invalid EDL line [%d]: [%s]\n", lineCount
, line
);
973 printf( "Stop time must follow start time. Discarding EDL entry.\n" );
976 edl_records
[ next_edl_array_index
].action
= action
;
977 if( action
== EDL_MUTE
) {
978 edl_records
[ next_edl_array_index
].length_sec
= 0;
979 edl_records
[ next_edl_array_index
].start_sec
= start
;
980 edl_records
[ next_edl_array_index
].stop_sec
= start
;
981 next_edl_array_index
++;
982 if( next_edl_array_index
>= MAX_EDL_ENTRIES
-1 ) {
985 edl_records
[ next_edl_array_index
-1 ].next
= &edl_records
[ next_edl_array_index
];
986 edl_records
[ next_edl_array_index
].action
= EDL_MUTE
;
987 edl_records
[ next_edl_array_index
].length_sec
= 0;
988 edl_records
[ next_edl_array_index
].start_sec
= stop
;
989 edl_records
[ next_edl_array_index
].stop_sec
= stop
;
991 edl_records
[ next_edl_array_index
].length_sec
= stop
- start
;
992 edl_records
[ next_edl_array_index
].start_sec
= start
;
993 edl_records
[ next_edl_array_index
].stop_sec
= stop
;
995 next_edl_array_index
++;
996 if( next_edl_array_index
>= MAX_EDL_ENTRIES
-1 ) {
1001 if( next_edl_array_index
> 0 ) {
1002 edl_records
[ next_edl_array_index
-1 ].next
= &edl_records
[ next_edl_array_index
];
1004 edl_records
[ next_edl_array_index
].start_sec
= -1;
1005 edl_records
[ next_edl_array_index
].next
= NULL
;
1006 num_edl_records
= ( next_edl_array_index
);
1010 next_edl_record
->next
= NULL
;
1012 if( edl_output_filename
) {
1013 if( edl_filename
) {
1014 printf( "Sorry; EDL mode and EDL output mode are mutually exclusive! Disabling all EDL functions.\n" );
1015 edl_output_filename
= NULL
;
1016 edl_filename
= NULL
;
1017 next_edl_record
->next
= NULL
;
1019 if( ( edl_fd
= fopen( edl_output_filename
, "w" ) ) == NULL
) {
1020 printf( "Error opening file [%s] for writing!\n", edl_output_filename
);
1021 edl_output_filename
= NULL
;
1022 next_edl_record
->next
= NULL
;
1028 printf( "EDL Records:\n" );
1029 if( next_edl_record
->next
!= NULL
) {
1030 while( next_edl_record
->next
!= NULL
) {
1031 printf( "EDL: start [%f], stop [%f], action [%d]\n", next_edl_record
->start_sec
, next_edl_record
->stop_sec
, next_edl_record
->action
);
1032 next_edl_record
= next_edl_record
->next
;
1034 next_edl_record
= edl_records
;
1043 // no file/vcd/dvd -> show HELP:
1044 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
1046 } else gui_no_filename
=1;
1049 // Many users forget to include command line in bugreports...
1051 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "CommandLine:");
1052 for(i
=1;i
<argc
;i
++)printf(" '%s'",argv
[i
]);
1056 mp_msg_set_level(verbose
+MSGL_STATUS
);
1058 //------ load global data first ------
1063 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
1064 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
1067 vo_font
=read_font_desc(get_path("font/font.desc"),font_factor
,verbose
>1);
1069 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
1071 #ifdef HAVE_FREETYPE
1081 // seteuid(0); /* Can't hurt to try to get root here */
1082 if ((rtc_fd
= open("/dev/rtc", O_RDONLY
)) < 0)
1083 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Failed to open /dev/rtc: %s (mplayer should be setuid root or /dev/rtc should be readable by the user.)\n", strerror(errno
));
1085 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
1087 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
1088 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n", irqp
, strerror(errno
));
1089 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n", irqp
);
1092 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
1093 /* variable only by the root */
1094 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC init error in ioctl (rtc_pie_on): %s\n", strerror(errno
));
1098 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_UsingRTCTiming
, irqp
);
1102 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1103 // and now ? -- Pontscho
1104 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
1108 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Using %s timing\n",softsleep
?"software":"usleep()");
1111 if ( !use_gui
) load_termcap(NULL
); // load key-codes
1114 // ========== Init keyboard FIFO (connection to libvo) ============
1116 // Init input system
1117 current_module
= "init_input";
1119 #ifndef HAVE_NO_POSIX_SELECT
1120 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
1122 if(keyb_fifo_get
> 0)
1123 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
1125 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
1129 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
1131 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
1134 #ifndef HAVE_NO_POSIX_SELECT
1135 mp_input_add_key_fd(0,1,NULL
,NULL
);
1137 mp_input_add_key_fd(0,0,NULL
,NULL
);
1140 inited_flags
|=INITED_INPUT
;
1141 current_module
= NULL
;
1145 if(menu_cfg
&& menu_init(menu_cfg
))
1146 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu inited: %s\n", menu_cfg
);
1148 menu_cfg
= get_path("menu.conf");
1149 if(menu_init(menu_cfg
))
1150 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu inited: %s\n", menu_cfg
);
1152 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
1153 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu inited: %s\n", MPLAYER_CONFDIR
"/menu.conf");
1155 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Menu init failed\n");
1165 //========= Catch terminate signals: ================
1166 // terminate requests:
1167 signal(SIGTERM
,exit_sighandler
); // kill
1168 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
1170 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
1172 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
1173 #ifdef ENABLE_SIGHANDLER
1175 signal(SIGBUS
,exit_sighandler
); // bus error
1176 signal(SIGSEGV
,exit_sighandler
); // segfault
1177 signal(SIGILL
,exit_sighandler
); // illegal instruction
1178 signal(SIGFPE
,exit_sighandler
); // floating point exc.
1179 signal(SIGABRT
,exit_sighandler
); // abort()
1185 inited_flags
|=INITED_GUI
;
1186 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
1190 // ******************* Now, let's see the per-file stuff ********************
1194 if (filename
) load_per_file_config (mconfig
, filename
);
1196 // We must enable getch2 here to be able to interrupt network connection
1198 if(!use_stdin
&& !slave_mode
){
1199 if(inited_flags
&INITED_GETCH2
)
1200 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"WARNING: getch2_init called twice!\n");
1202 getch2_enable(); // prepare stdin for hotkeys...
1203 inited_flags
|=INITED_GETCH2
;
1204 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
1207 // =================== GUI idle loop (STOP state) ===========================
1210 file_format
=DEMUXER_TYPE_UNKNOWN
;
1211 guiGetEvent( guiSetDefaults
,0 );
1212 while ( guiIntfStruct
.Playing
!= 1 )
1217 guiGetEvent( guiReDraw
,NULL
);
1218 if ( (cmd
= mp_input_get_cmd(0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
1220 guiGetEvent( guiSetParameters
,NULL
);
1221 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
1223 play_tree_t
* entry
= play_tree_new();
1224 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
1225 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
1226 else playtree
=play_tree_new();
1227 play_tree_set_child( playtree
,entry
);
1230 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
1233 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
1235 play_tree_iter_free(playtree_iter
);
1236 playtree_iter
= NULL
;
1238 filename
= play_tree_iter_get_file(playtree_iter
,1);
1244 //---------------------------------------------------------------------------
1246 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
1247 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
1249 //==================== Open VOB-Sub ============================
1251 current_module
="vobsub";
1253 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
1255 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
1256 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
1257 /* try to autodetect vobsub from movie filename ::atmos */
1258 char *buf
= malloc((strlen(filename
)-3) * sizeof(char));
1259 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
1260 strncpy(buf
, filename
, strlen(filename
)-4);
1261 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
1265 sub_auto
=0; // don't do autosub for textsubs if vobsub found
1266 inited_flags
|=INITED_VOBSUB
;
1267 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
1268 // check if vobsub requested only to display forced subtitles
1269 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
1272 //============ Open & Sync STREAM --- fork cache2 ====================
1277 //free_demuxer_stream(d_audio);
1281 //free_demuxer_stream(d_video);
1287 current_module
="open_stream";
1288 stream
=open_stream(filename
,0,&file_format
);
1289 if(!stream
) { // error...
1290 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
1291 goto goto_next_file
;
1293 inited_flags
|=INITED_STREAM
;
1296 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
1299 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
1302 current_module
="handle_playlist";
1303 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
1304 entry
= parse_playtree(stream
,0);
1305 eof
=playtree_add_playlist(entry
);
1306 goto goto_next_file
;
1308 stream
->start_pos
+=seek_to_byte
;
1311 current_module
="libcss";
1313 if (dvd_import_key(dvdimportkey
)) {
1314 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorDVDkey
);
1315 exit_player(MSGTR_Exit_error
);
1317 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CmdlineDVDkey
);
1319 if (dvd_auth_device
) {
1320 if (dvd_auth(dvd_auth_device
,filename
)) {
1321 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"Error in DVD auth...\n");
1322 exit_player(MSGTR_Exit_error
);
1324 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_DVDauthOk
);
1328 if(stream_dump_type
==5){
1329 unsigned char buf
[4096];
1332 current_module
="dumpstream";
1333 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
1334 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"Cannot dump this stream - no 'fd' available\n");
1335 exit_player(MSGTR_Exit_error
);
1337 stream_reset(stream
);
1338 stream_seek(stream
,stream
->start_pos
);
1339 f
=fopen(stream_dump_name
,"wb");
1341 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1342 exit_player(MSGTR_Exit_error
);
1344 while(!stream
->eof
){
1345 len
=stream_read(stream
,buf
,4096);
1347 if(fwrite(buf
,len
,1,f
) != 1) {
1348 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1349 exit_player(MSGTR_Exit_error
);
1354 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1355 exit_player(MSGTR_Exit_error
);
1357 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1358 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1362 if(stream
->type
==STREAMTYPE_DVD
){
1363 current_module
="dvd lang->id";
1364 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
1365 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
1366 current_module
=NULL
;
1371 if (stream
->type
==STREAMTYPE_DVDNAV
) stream_cache_size
=0; // must disable caching...
1374 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1375 if(stream_cache_size
>0){
1376 current_module
="enable_cache";
1377 if(!stream_enable_cache(stream
,stream_cache_size
*1024,stream_cache_size
*1024/5,stream_cache_size
*1024/20))
1378 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
1381 //============ Open DEMUXERS --- DETECT file type =======================
1382 #ifdef HAS_DVBIN_SUPPORT
1385 current_module
="demux_open";
1387 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
1389 // HACK to get MOV Reference Files working
1391 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
1393 unsigned char* playlist_entry
;
1394 play_tree_t
*list
= NULL
, *entry
= NULL
;
1396 current_module
="handle_demux_playlist";
1397 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
1401 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry\n",playlist_entry
);
1403 bname
=mp_basename(playlist_entry
);
1404 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
1407 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
1410 entry
= play_tree_new();
1412 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
1414 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1)*sizeof(char));
1417 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
1418 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
1419 strcat(temp
, playlist_entry
);
1420 play_tree_add_file(entry
,temp
);
1421 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s\n",temp
);
1426 play_tree_add_file(entry
,playlist_entry
);
1431 play_tree_append_entry(list
,entry
);
1433 free_demuxer(demuxer
);
1438 entry
= play_tree_new();
1439 play_tree_set_child(entry
,list
);
1440 eof
=playtree_add_playlist(entry
);
1441 goto goto_next_file
;
1450 current_module
="handle_playlist";
1451 switch(stream
->type
){
1452 case STREAMTYPE_VCD
:
1453 case STREAMTYPE_DVD
:
1454 case STREAMTYPE_DVDNAV
:
1455 case STREAMTYPE_CDDA
:
1456 case STREAMTYPE_VCDBINCUE
:
1457 // don't try to parse raw media as playlist, it's unlikely
1458 goto goto_next_file
;
1460 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"Falling back on trying to parse playlist %s...\n",filename
);
1461 stream_reset(stream
);
1462 stream_seek(stream
,stream
->start_pos
);
1463 entry
= parse_playtree(stream
,0);
1465 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
1467 eof
=playtree_add_playlist(entry
);
1469 goto goto_next_file
;
1471 inited_flags
|=INITED_DEMUXER
;
1473 current_module
="demux_open2";
1475 //file_format=demuxer->file_format;
1477 d_audio
=demuxer
->audio
;
1478 d_video
=demuxer
->video
;
1479 d_dvdsub
=demuxer
->sub
;
1482 if((stream_dump_type
)&&(stream_dump_type
<4)){
1484 demux_stream_t
*ds
=NULL
;
1485 current_module
="dump";
1486 // select stream to dump
1487 switch(stream_dump_type
){
1488 case 1: ds
=d_audio
;break;
1489 case 2: ds
=d_video
;break;
1490 case 3: ds
=d_dvdsub
;break;
1493 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
1494 exit_player(MSGTR_Exit_error
);
1496 // disable other streams:
1497 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
1498 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
1499 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
1501 f
=fopen(stream_dump_name
,"wb");
1503 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1504 exit_player(MSGTR_Exit_error
);
1507 unsigned char* start
;
1508 int in_size
=ds_get_packet(ds
,&start
);
1509 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
1510 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
1511 if(in_size
>0) fwrite(start
,in_size
,1,f
);
1514 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1515 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1518 sh_audio
=d_audio
->sh
;
1519 sh_video
=d_video
->sh
;
1523 current_module
="video_read_properties";
1524 if(!video_read_properties(sh_video
)) {
1525 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
1526 sh_video
=d_video
->sh
=NULL
;
1528 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1529 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
1530 sh_video
->fps
,sh_video
->frametime
1533 /* need to set fps here for output encoders to pick it up in their init */
1535 sh_video
->fps
=force_fps
;
1536 sh_video
->frametime
=1.0f
/sh_video
->fps
;
1538 vo_fps
= sh_video
->fps
;
1540 vo_mouse_timer_const
=(int)sh_video
->fps
;
1543 if(!sh_video
->fps
&& !force_fps
){
1544 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
1545 sh_video
=d_video
->sh
=NULL
;
1553 if(!sh_video
&& !sh_audio
){
1554 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
1555 #ifdef HAS_DVBIN_SUPPORT
1556 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
1558 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
1562 int v
= last_dvb_step
;
1564 dir
= DVB_CHANNEL_HIGHER
;
1566 dir
= DVB_CHANNEL_LOWER
;
1568 if(dvb_step_channel(priv
, dir
))
1570 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
1571 goto goto_open_demuxer
;
1576 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
1579 /* display clip info */
1580 demux_info_print(demuxer
);
1582 //================== Read SUBTITLES (DVD & TEXT) ==========================
1583 if(d_dvdsub
->id
>= 0 && vo_spudec
==NULL
&& sh_video
){
1586 unsigned int palette
[16], width
, height
;
1587 current_module
="spudec_init_vobsub";
1588 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1589 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1593 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
1594 current_module
="spudec_init_dvdnav";
1595 vo_spudec
=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t
*)(stream
->priv
)),
1596 sh_video
->disp_w
, sh_video
->disp_h
);
1601 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
1602 current_module
="spudec_init_dvdread";
1603 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
1604 sh_video
->disp_w
, sh_video
->disp_h
);
1608 #ifdef HAVE_MATROSKA
1609 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1610 (d_dvdsub
->sh
!= NULL
) && (((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
1611 current_module
= "spudec_init_matroska";
1612 vo_spudec
= spudec_new_scaled(((mkv_sh_sub_t
*)d_dvdsub
->sh
)->palette
,
1613 ((mkv_sh_sub_t
*)d_dvdsub
->sh
)->width
,
1614 ((mkv_sh_sub_t
*)d_dvdsub
->sh
)->height
);
1618 if (vo_spudec
==NULL
) {
1619 current_module
="spudec_init_normal";
1620 vo_spudec
=spudec_new_scaled(NULL
, sh_video
->disp_w
, sh_video
->disp_h
);
1621 spudec_set_font_factor(vo_spudec
,font_factor
);
1624 if (vo_spudec
!=NULL
)
1625 inited_flags
|=INITED_SPUDEC
;
1629 // Apply current settings for forced subs
1630 if (vo_spudec
!=NULL
)
1631 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
1635 // after reading video params we should load subtitles because
1636 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1638 current_module
="read_subtitles_file";
1640 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
1641 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
1643 if(sub_auto
) { // auto load sub file ...
1644 char **tmp
= sub_filenames(get_path("sub/"), filename
);
1647 add_subtitles (*tmp2
++, sh_video
->fps
, 0);
1649 if (set_of_sub_size
== 0)
1650 add_subtitles (get_path("default.sub"), sh_video
->fps
, 1);
1651 if (set_of_sub_size
> 0)
1652 add_subtitles (NULL
, sh_video
->fps
, 1);
1654 if (set_of_sub_size
> 0) {
1655 //osd_show_sub_changed = sh_video->fps;
1656 subdata
= set_of_subtitles
[set_of_sub_pos
=0];
1658 if(stream_dump_type
==3) list_sub_file(subdata
);
1659 if(stream_dump_type
==4) dump_mpsub(subdata
, sh_video
->fps
);
1660 if(stream_dump_type
==6) dump_srt(subdata
, sh_video
->fps
);
1661 if(stream_dump_type
==7) dump_microdvd(subdata
, sh_video
->fps
);
1662 if(stream_dump_type
==8) dump_jacosub(subdata
, sh_video
->fps
);
1663 if(stream_dump_type
==9) dump_sami(subdata
, sh_video
->fps
);
1668 //================== Init AUDIO (codec) ==========================
1670 // Go through the codec.conf and find the best codec...
1671 current_module
="init_audio_codec";
1672 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1673 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
1674 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
1676 inited_flags
|=INITED_ACODEC
;
1677 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1681 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
1683 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1684 if (sh_video
->format
>= 0x20202020)
1685 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", &sh_video
->format
);
1687 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
1688 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
1689 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
1690 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
1691 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
1692 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
1695 if (sh_audio
->codec
)
1696 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
1697 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1698 if (sh_audio
->format
>= 0x20202020)
1699 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio
->format
);
1701 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
1702 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
1703 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
1704 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
1706 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer
));
1709 if(!sh_video
) goto main
; // audio-only
1711 //================== Init VIDEO (codec & libvo) ==========================
1712 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
1713 current_module
="preinit_libvo";
1716 //if((video_out->preinit(vo_subdevice))!=0){
1717 if(!(video_out
=init_best_video_out(video_driver_list
))){
1718 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
1719 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
1721 sh_video
->video_out
=video_out
;
1722 inited_flags
|=INITED_VO
;
1725 current_module
="init_video_filters";
1727 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
1728 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
1732 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
1733 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
1735 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,"Can't open libmenu video filter with root menu %s\n",menu_root
);
1740 sh_video
->vfilter
=(void*)append_filters(vf_menu
);
1743 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
1745 current_module
="init_video_codec";
1747 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1748 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
1749 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1751 if(!sh_video
->inited
){
1752 if(!fixed_vo
) uninit_player(INITED_VO
);
1753 if(!sh_audio
) goto goto_next_file
;
1754 sh_video
= d_video
->sh
= NULL
;
1755 goto main
; // exit_player(MSGTR_Exit_error);
1758 inited_flags
|=INITED_VCODEC
;
1761 // Auto quality option enabled
1762 output_quality
=get_video_quality_max(sh_video
);
1763 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
1764 else output_quality
=auto_quality
;
1765 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d\n",output_quality
);
1766 set_video_quality(sh_video
,output_quality
);
1769 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1771 current_module
="init_vo";
1774 if (vo_gamma_gamma
!= 1000)
1775 set_video_colors (sh_video
, "gamma", vo_gamma_gamma
);
1776 if (vo_gamma_brightness
!= 1000)
1777 set_video_colors(sh_video
, "brightness", vo_gamma_brightness
);
1778 if (vo_gamma_contrast
!= 1000)
1779 set_video_colors(sh_video
, "contrast", vo_gamma_contrast
);
1780 if (vo_gamma_saturation
!= 1000)
1781 set_video_colors(sh_video
, "saturation", vo_gamma_saturation
);
1782 if (vo_gamma_hue
!= 1000)
1783 set_video_colors(sh_video
, "hue", vo_gamma_hue
);
1786 if(vo_flags
& 0x08 && vo_spudec
)
1787 spudec_set_hw_spu(vo_spudec
,video_out
);
1789 #ifdef HAVE_FREETYPE
1790 force_load_font
= 1;
1793 //================== MAIN: ==========================
1795 current_module
="main";
1797 // If there is no video OSD has to be disabled.
1798 // In case of playing a playtree we have to restore the
1799 // old OSD level after playing one or more audio-only files.
1800 if(!sh_video
&& osd_level
>= 0) { // save OSD level only once
1801 osd_level_saved
= osd_level
;
1803 } else if (osd_level_saved
> -1) { // if there is a saved OSD level, restore it
1804 osd_level
= osd_level_saved
;
1805 osd_level_saved
= -1;
1813 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
1814 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
1815 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
1816 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
1817 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
1822 //int frame_corr_num=0; //
1823 //float v_frame=0; // Video
1824 float time_frame
=0; // Timer
1825 //float num_frames=0; // number of frames played
1827 char osd_text_buffer
[64];
1828 char osd_show_text_buffer
[64];
1829 int drop_frame
=0; // current dropping status
1830 int dropped_frames
=0; // how many frames dropped since last non-dropped frame
1831 int too_slow_frame_cnt
=0;
1832 int too_fast_frame_cnt
=0;
1833 // for auto-quality:
1834 float AV_delay
=0; // average of A-V timestamp differences
1835 double vdecode_time
;
1836 unsigned int lastframeout_ts
=0;
1837 /*float time_frame_corr_avg=0;*/ /* unused */
1839 float next_frame_time
=0;
1840 int frame_time_remaining
=0; // flag
1843 osd_text_buffer
[0]=0;
1845 //================ SETUP AUDIO ==========================
1848 //const ao_info_t *info=audio_out->info;
1849 current_module
="af_preinit";
1850 ao_data
.samplerate
=force_srate
?force_srate
:sh_audio
->samplerate
*playback_speed
;
1851 ao_data
.channels
=audio_output_channels
?audio_output_channels
:sh_audio
->channels
;
1852 ao_data
.format
=audio_output_format
?audio_output_format
:sh_audio
->sample_format
;
1854 if(!preinit_audio_filters(sh_audio
,
1856 (int)(sh_audio
->samplerate
*playback_speed
),
1857 sh_audio
->channels
, sh_audio
->sample_format
, sh_audio
->samplesize
,
1859 &ao_data
.samplerate
, &ao_data
.channels
, &ao_data
.format
,
1860 audio_out_format_bits(ao_data
.format
)/8)){
1861 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,"Error at audio filter chain pre-init!\n");
1863 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AF_pre: %dHz %dch %s\n",
1864 ao_data
.samplerate
, ao_data
.channels
,
1865 audio_out_format_name(ao_data
.format
));
1868 current_module
="ao2_init";
1869 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
1870 (ao_plugin_cfg
.plugin_list
!=NULL
), // plugin flag
1871 force_srate
?force_srate
:ao_data
.samplerate
,
1872 audio_output_channels
?audio_output_channels
:ao_data
.channels
,
1873 audio_output_format
?audio_output_format
:ao_data
.format
,0))){
1875 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1876 uninit_player(INITED_ACODEC
); // close codec
1877 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
1880 inited_flags
|=INITED_AO
;
1881 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bps)\n",
1882 audio_out
->info
->short_name
,
1883 ao_data
.samplerate
, ao_data
.channels
,
1884 audio_out_format_name(ao_data
.format
),
1885 audio_out_format_bits(ao_data
.format
)/8 );
1886 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_AODescription_AOAuthor
,
1887 audio_out
->info
->name
, audio_out
->info
->author
);
1888 if(strlen(audio_out
->info
->comment
) > 0)
1889 mp_msg(MSGT_CPLAYER
,MSGL_V
,MSGTR_AOComment
, audio_out
->info
->comment
);
1890 // init audio filters:
1892 current_module
="af_init";
1893 if(!init_audio_filters(sh_audio
,
1894 (int)(sh_audio
->samplerate
*playback_speed
),
1895 sh_audio
->channels
, sh_audio
->sample_format
, sh_audio
->samplesize
,
1896 ao_data
.samplerate
, ao_data
.channels
, ao_data
.format
,
1897 audio_out_format_bits(ao_data
.format
)/8, /* ao_data.bps, */
1898 ao_data
.outburst
*4, ao_data
.buffersize
)){
1899 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,"Couldn't find matching filter / ao format!\n");
1900 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1901 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1902 // sh_audio=d_audio->sh=NULL; // -> nosound
1908 current_module
="av_init";
1910 if(sh_video
) sh_video
->timer
=0;
1911 if(sh_audio
) sh_audio
->delay
=-audio_delay
;
1914 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
1915 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused audio chunks\n",d_audio
->packs
);
1916 ds_free_packs(d_audio
); // free buffered chunks
1917 d_audio
->id
=-2; // do not read audio chunks
1918 //uninit_player(INITED_AO); // close device
1921 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
1922 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %d unused video chunks\n",d_video
->packs
);
1923 ds_free_packs(d_video
);
1925 //if(!fixed_vo) uninit_player(INITED_VO);
1928 if (!sh_video
&& !sh_audio
)
1929 goto goto_next_file
;
1931 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
1932 if(force_fps
&& sh_video
){
1933 vo_fps
= sh_video
->fps
=force_fps
;
1934 sh_video
->frametime
=1.0f
/sh_video
->fps
;
1935 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
1938 //==================== START PLAYING =======================
1940 if(loop_times
>1) loop_times
--; else
1941 if(loop_times
==1) loop_times
= -1;
1943 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
1948 if (stream
->type
==STREAMTYPE_DVDNAV
) {
1949 dvdnav_stream_fullstart((dvdnav_priv_t
*)stream
->priv
);
1953 total_time_usage_start
=GetTimer();
1954 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
1955 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
1956 play_n_frames
=play_n_frames_mf
;
1958 if(play_n_frames
==0){
1959 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
1963 float aq_sleep_time
=0;
1965 if(play_n_frames
>=0){
1967 if(play_n_frames
<0) eof
= PT_NEXT_ENTRY
;
1970 /*========================== PLAY AUDIO ============================*/
1977 current_module
="play_audio";
1979 ao_data
.pts
=((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
1980 playsize
=audio_out
->get_space();
1982 // handle audio-only case:
1983 if(!playsize
&& !sh_video
) { // buffer is full, do not block here!!!
1984 usec_sleep(10000); // Wait a tick before retry
1988 if(playsize
>MAX_OUTBURST
) playsize
=MAX_OUTBURST
; // we shouldn't exceed it!
1990 // Fill buffer if needed:
1991 current_module
="decode_audio"; // Enter AUDIO decoder module
1993 while(sh_audio
->a_out_buffer_len
<playsize
&& !d_audio
->eof
){
1994 int ret
=decode_audio(sh_audio
,&sh_audio
->a_out_buffer
[sh_audio
->a_out_buffer_len
],
1995 playsize
-sh_audio
->a_out_buffer_len
,sh_audio
->a_out_buffer_size
-sh_audio
->a_out_buffer_len
);
1996 if(ret
<=0) break; // EOF?
1997 sh_audio
->a_out_buffer_len
+=ret
;
2000 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2001 if(playsize
>sh_audio
->a_out_buffer_len
) playsize
=sh_audio
->a_out_buffer_len
;
2004 current_module
="play_audio";
2005 playsize
=audio_out
->play(sh_audio
->a_out_buffer
,playsize
,0);
2008 sh_audio
->a_out_buffer_len
-=playsize
;
2009 memmove(sh_audio
->a_out_buffer
,&sh_audio
->a_out_buffer
[playsize
],sh_audio
->a_out_buffer_len
);
2010 sh_audio
->delay
+=playback_speed
*playsize
/((float)((ao_data
.bps
&& sh_audio
->afilter
) ?
2011 ao_data
.bps
: sh_audio
->o_bps
));
2015 } // while(sh_audio)
2018 // handle audio-only case:
2021 // convert time to HH:MM:SS.F format
2023 long tenths
= 10 * sh_audio
->delay
-audio_out
->get_delay();
2024 int hh
= (tenths
/ 36000) % 100;
2025 int mm
= (tenths
/ 600) % 60;
2026 int ss
= (tenths
/ 10) % 60;
2027 int f1
= tenths
% 10;
2028 char hhmmssf
[16]; // only really need 11, but just in case...
2029 sprintf( hhmmssf
, "%2d:%2d:%2d.%1d", hh
, mm
, ss
, f1
);
2034 // uncomment the next three lines to show leading zero ten-hours
2035 // else if (' ' == hhmmssf[0]) {
2036 // hhmmssf[0] = '0';
2038 if ((0 == hh
) && (0 == mm
)) {
2042 else if ((' ' == hhmmssf
[3]) && (' ' != hhmmssf
[2])) {
2045 if ((' ' == hhmmssf
[6]) && (' ' != hhmmssf
[5])) {
2048 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A: %s %4.1f%% %d%% \r"
2050 ,(sh_audio
->delay
>0.5)?100.0*audio_time_usage
/(double)sh_audio
->delay
:0
2054 if(d_audio
->eof
) eof
= PT_NEXT_ENTRY
;
2058 /*========================== PLAY VIDEO ============================*/
2060 float frame_time
=next_frame_time
;
2062 vo_pts
=sh_video
->timer
*90000.0;
2063 vo_fps
=sh_video
->fps
;
2065 if(!frame_time_remaining
){
2066 //-------------------- Decode a frame: -----------------------
2067 vdecode_time
=video_time_usage
;
2069 { unsigned char* start
=NULL
;
2072 current_module
="video_read_frame";
2073 in_size
=video_read_frame(sh_video
,&next_frame_time
,&start
,force_fps
);
2074 if(in_size
<0){ eof
=1; break; }
2075 if(in_size
>max_framesize
) max_framesize
=in_size
; // stats
2076 sh_video
->timer
+=frame_time
;
2077 if(sh_audio
) sh_audio
->delay
-=frame_time
;
2078 time_frame
+=frame_time
; // for nosound
2079 // check for frame-drop:
2080 current_module
="check_framedrop";
2081 if(sh_audio
&& !d_audio
->eof
){
2082 float delay
=playback_speed
*audio_out
->get_delay();
2083 float d
=delay
-sh_audio
->delay
;
2084 // we should avoid dropping to many frames in sequence unless we
2085 // are too late. and we allow 100ms A-V delay here:
2086 if(d
<-dropped_frames
*frame_time
-0.100){
2087 drop_frame
=frame_dropping
;
2091 drop_frame
=dropped_frames
=0;
2096 current_module
="decode_video";
2097 // printf("Decode! %p %d \n",start,in_size);
2098 blit_frame
=decode_video(sh_video
,start
,in_size
,drop_frame
);
2101 vdecode_time
=video_time_usage
-vdecode_time
;
2102 //------------------------ frame decoded. --------------------
2104 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
2106 if(sh_video
->vf_inited
<0){
2107 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_NotInitializeVOPorVO
);
2108 eof
=1; goto goto_next_file
;
2113 // ==========================================================================
2115 // current_module="draw_osd";
2116 // if(vo_config_count) video_out->draw_osd();
2119 if(use_gui
) guiEventHandling();
2122 current_module
="calc_sleep_time";
2125 { // debug frame dropping code
2126 float delay
=audio_out
->get_delay();
2127 mp_msg(MSGT_AVSYNC
,MSGL_V
,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2128 sh_video
->timer
,sh_audio
->timer
-delay
,
2129 sh_video
->timer
-(sh_audio
->timer
-delay
),
2134 if(drop_frame
&& !frame_time_remaining
&& !autosync
){
2136 * Note: time_frame should not be forced to 0 in autosync mode.
2137 * It is used as a cumulative counter to predict and correct the
2138 * delay measurements from the audio driver. time_frame is already
2139 * < 0, so the "time to sleep" code does not actually sleep. Also,
2140 * blit_frame is already 0 because drop_frame was true when
2141 * decode_video was called (which causes it to set blit_frame to 0.)
2142 * When autosync==0, the default behavior is still completely unchanged.
2145 time_frame
=0; // don't sleep!
2146 blit_frame
=0; // don't display!
2150 // It's time to sleep...
2152 frame_time_remaining
=0;
2153 time_frame
-=GetRelativeTime(); // reset timer
2155 if(sh_audio
&& !d_audio
->eof
){
2156 float delay
=playback_speed
*audio_out
->get_delay();
2157 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"delay=%f\n",delay
);
2161 * Adjust this raw delay value by calculating the expected
2162 * delay for this frame and generating a new value which is
2163 * weighted between the two. The higher autosync is, the
2164 * closer to the delay value gets to that which "-nosound"
2165 * would have used, and the longer it will take for A/V
2166 * sync to settle at the right value (but it eventually will.)
2167 * This settling time is very short for values below 100.
2169 float predicted
= sh_audio
->delay
+time_frame
;
2170 float difference
= delay
- predicted
;
2171 delay
= predicted
+ difference
/ (float)autosync
;
2174 time_frame
=delay
-sh_audio
->delay
;
2176 // delay = amount of audio buffered in soundcard/driver
2177 if(delay
>0.25) delay
=0.25; else
2178 if(delay
<0.10) delay
=0.10;
2179 if(time_frame
>delay
*0.6){
2180 // sleep time too big - may cause audio drops (buffer underrun)
2181 frame_time_remaining
=1;
2182 time_frame
=delay
*0.5;
2188 if( (time_frame
<-3*frame_time
|| time_frame
>3*frame_time
) || benchmark
)
2193 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2195 aq_sleep_time
+=time_frame
;
2199 //============================== SLEEP: ===================================
2201 time_frame
/=playback_speed
;
2203 // flag 256 means: libvo driver does its timing (dvb card)
2204 if(time_frame
>0.001 && !(vo_flags
&256)){
2208 // -------- RTC -----------
2209 current_module
="sleep_rtc";
2210 while (time_frame
> 0.000) {
2211 unsigned long rtc_ts
;
2212 if (read (rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
2213 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "Linux RTC read error: %s\n", strerror(errno
));
2214 time_frame
-=GetRelativeTime();
2219 // -------- USLEEP + SOFTSLEEP -----------
2220 float min
=softsleep
?0.021:0.005;
2221 current_module
="sleep_usleep";
2222 while(time_frame
>min
){
2223 if(time_frame
<=0.020)
2224 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2226 usec_sleep(1000000*(time_frame
-0.020));
2227 time_frame
-=GetRelativeTime();
2230 current_module
="sleep_soft";
2231 if(time_frame
<0) mp_msg(MSGT_AVSYNC
, MSGL_WARN
, "Warning! Softsleep underflow!\n");
2232 while(time_frame
>0) time_frame
-=GetRelativeTime(); // burn the CPU
2238 //if(!frame_time_remaining){ // should we display the frame now?
2240 //====================== FLIP PAGE (VIDEO BLT): =========================
2242 current_module
="vo_check_events";
2243 if(vo_config_count
) video_out
->check_events();
2245 current_module
="flip_page";
2246 if (!frame_time_remaining
) {
2248 unsigned int t2
=GetTimer();
2251 #define FRAME_LAG_WARN 0.2
2252 j
= ((float)t2
- lastframeout_ts
) / 1000000;
2253 lastframeout_ts
= GetTimer();
2254 if (j
< frame_time
+ frame_time
* -FRAME_LAG_WARN
)
2255 too_fast_frame_cnt
++;
2256 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2257 else if (j
> frame_time
+ frame_time
* FRAME_LAG_WARN
)
2258 too_slow_frame_cnt
++;
2259 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2261 if(vo_config_count
) video_out
->flip_page();
2262 // usec_sleep(50000); // test only!
2265 vout_time_usage
+=tt
;
2268 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2269 otherwise A/V desync will occur. -- Alvieboy
2271 if (vo_config_count
)
2272 video_out
->control(VOCTRL_DUPLICATE_FRAME
, NULL
);
2275 //====================== A-V TIMESTAMP CORRECTION: =========================
2277 current_module
="av_sync";
2283 // unplayed bytes in our and soundcard/dma buffer:
2284 float delay
=playback_speed
*audio_out
->get_delay()+(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2288 * If autosync is enabled, the value for delay must be calculated
2289 * a bit differently. It is set only to the difference between
2290 * the audio and video timers. Any attempt to include the real
2291 * or corrected delay causes the pts_correction code below to
2292 * try to correct for the changes in delay which autosync is
2293 * trying to measure. This keeps the two from competing, but still
2294 * allows the code to correct for PTS drift *only*. (Using a delay
2295 * value here, even a "corrected" one, would be incompatible with
2298 delay
=sh_audio
->delay
;
2299 delay
+=(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2304 // PTS = sample_no / samplerate
2305 unsigned int samples
=
2306 // (sh_audio->audio.dwSampleSize)?
2307 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2308 ds_tell_block(d_audio
); // <- used for VBR audio
2309 samples
+=sh_audio
->audio
.dwStart
; // offset
2310 a_pts
=samples
*(float)sh_audio
->audio
.dwScale
/(float)sh_audio
->audio
.dwRate
;
2312 a_pts
-=(sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2316 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2318 if(!delay_corrected
) if(a_pts
) delay_corrected
=1;
2320 printf("\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2322 ds_tell_pts(d_audio
)/(float)sh_audio
->i_bps
,
2323 -sh_audio
->a_in_buffer_len
/(float)sh_audio
->i_bps
,
2324 a_pts
+(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
);
2326 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2328 v_pts
=sh_video
? sh_video
->pts
: d_video
->pts
;
2330 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
);
2332 if(delay_corrected
){
2333 static int drop_message
=0;
2335 AV_delay
=(a_pts
-delay
-audio_delay
)-v_pts
;
2336 if(AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
2338 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
2341 if(x
<-max_pts_correction
) x
=-max_pts_correction
; else
2342 if(x
> max_pts_correction
) x
= max_pts_correction
;
2343 if(default_max_pts_correction
>=0)
2344 max_pts_correction
=default_max_pts_correction
;
2346 max_pts_correction
=sh_video
->frametime
*0.10; // +-10% of time
2347 if(!frame_time_remaining
){ sh_audio
->delay
+=x
; c_total
+=x
;} // correction
2348 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",
2349 a_pts
-audio_delay
-delay
,v_pts
,AV_delay
,c_total
,
2350 (int)sh_video
->num_frames
,(int)sh_video
->num_frames_decoded
,
2351 (sh_video
->timer
>0.5)?(int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
):0,
2352 (sh_video
->timer
>0.5)?(int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
):0,
2353 (sh_video
->timer
>0.5)?(100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
):0
2365 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video
->pts
,
2366 (int)sh_video
->num_frames
,
2367 (sh_video
->timer
>0.5)?(int)(100.0*video_time_usage
/(double)sh_video
->timer
):0,
2368 (sh_video
->timer
>0.5)?(int)(100.0*vout_time_usage
/(double)sh_video
->timer
):0,
2369 (sh_video
->timer
>0.5)?(100.0*audio_time_usage
/(double)sh_video
->timer
):0
2379 //============================ Auto QUALITY ============================
2381 /*Output quality adjustments:*/
2383 current_module
="autoq";
2384 // float total=0.000001f * (GetTimer()-aq_total_time);
2385 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2386 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
2389 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2390 if(output_quality
>1 && aq_sleep_time
<0)
2393 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
2395 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2396 set_video_quality(sh_video
,output_quality
);
2399 } // end if(sh_video)
2401 //============================ Handle PAUSE ===============================
2403 current_module
="pause";
2407 if (!--osd_visible
){
2408 vo_osd_progbar_type
=-1; // disable
2409 vo_osd_changed(OSDTYPE_PROGBAR
);
2410 if (osd_function
!= OSD_PAUSE
)
2411 osd_function
= OSD_PLAY
;
2416 if(osd_function
==OSD_PAUSE
){
2419 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2423 if(use_gui
) guiGetEvent( guiCEvent
,(char *)guiSetPause
);
2425 if (video_out
&& sh_video
&& vo_config_count
)
2426 video_out
->control(VOCTRL_PAUSE
, NULL
);
2428 if (audio_out
&& sh_audio
)
2429 audio_out
->pause(); // pause audio, keep data if possible
2431 while( (cmd
= mp_input_get_cmd(20,1)) == NULL
) {
2432 if(sh_video
&& video_out
&& vo_config_count
) video_out
->check_events();
2436 guiGetEvent( guiReDraw
,NULL
);
2437 if(guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
)) break;
2442 vf_menu_pause_update(vf_menu
);
2447 osd_function
=OSD_PLAY
;
2448 if (audio_out
&& sh_audio
)
2449 audio_out
->resume(); // resume audio
2450 if (video_out
&& sh_video
&& vo_config_count
)
2451 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
2452 (void)GetRelativeTime(); // keep TF around FT in next cycle
2456 if ( guiIntfStruct
.Playing
== guiSetStop
) goto goto_next_file
;
2457 guiGetEvent( guiCEvent
,(char *)guiSetPlay
);
2464 osd_function
=OSD_FFW
;
2465 rel_seek_secs
+=step_sec
;
2469 if (stream
->type
==STREAMTYPE_DVDNAV
&& dvd_nav_still
)
2470 dvdnav_stream_sleeping((dvdnav_priv_t
*)stream
->priv
);
2473 //================= EDL =========================================
2476 if( next_edl_record
->next
) { // Are we (still?) doing EDL?
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
;
2499 //================= Keyboard events, SEEKing ====================
2501 current_module
="key_events";
2506 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0)) != NULL
) {
2508 case MP_CMD_SEEK
: {
2510 osd_show_percentage
= 25;
2511 v
= cmd
->args
[0].v
.i
;
2512 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2513 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
2516 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2519 else if(abs
) { /* Absolute seek by percentage */
2522 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2523 rel_seek_secs
= v
/100.0;
2527 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
2532 case MP_CMD_EDL_MARK
:
2534 float v
= sh_video
->pts
;
2535 fprintf( edl_fd
, "%f %f %d\n", v
-2, v
, 0 );
2539 case MP_CMD_AUDIO_DELAY
: {
2540 float v
= cmd
->args
[0].v
.f
;
2542 osd_show_av_delay
= 9;
2543 if(sh_audio
) sh_audio
->delay
+= v
;
2545 case MP_CMD_PAUSE
: {
2546 osd_function
=OSD_PAUSE
;
2549 case MP_CMD_QUIT
: {
2550 exit_player_with_rc(MSGTR_Exit_quit
, 0);
2552 case MP_CMD_GRAB_FRAMES
: {
2555 case MP_CMD_PLAY_TREE_STEP
: {
2556 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
2557 int force
= cmd
->args
[1].v
.i
;
2566 for (i
=0;i
<-1*n
;i
++)
2571 if(!force
&& playtree_iter
) {
2572 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2574 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2575 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2576 play_tree_iter_free(i
);
2578 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2584 case MP_CMD_PLAY_TREE_UP_STEP
: {
2585 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
2586 int force
= cmd
->args
[1].v
.i
;
2588 if(!force
&& playtree_iter
) {
2589 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2590 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2591 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2592 play_tree_iter_free(i
);
2594 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2597 case MP_CMD_PLAY_ALT_SRC_STEP
: {
2598 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
2599 int v
= cmd
->args
[0].v
.i
;
2600 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
2602 else if(v
< 0 && playtree_iter
->file
> 1)
2607 case MP_CMD_SUB_DELAY
: {
2610 int abs
= cmd
->args
[1].v
.i
;
2611 float v
= cmd
->args
[0].v
.f
;
2616 osd_show_sub_delay
= 9; // show the subdelay in OSD
2620 case MP_CMD_SUB_STEP
: {
2623 int movement
= cmd
->args
[0].v
.i
;
2624 step_sub(subdata
, sh_video
->pts
, movement
);
2625 osd_show_sub_delay
= 9; // show the subdelay in OSD
2632 int v
= cmd
->args
[0].v
.i
;
2634 osd_level
=(osd_level
+1)%(MAX_OSD_LEVEL
+1);
2636 osd_level
= v
> MAX_OSD_LEVEL
? MAX_OSD_LEVEL
: v
;
2640 case MP_CMD_OSD_SHOW_TEXT
: {
2642 if(osd_level
&& sh_video
){
2643 osd_show_text
=sh_video
->fps
; // 1 sec
2644 strncpy(osd_show_text_buffer
, cmd
->args
[0].v
.s
, 64);
2648 case MP_CMD_VOLUME
: {
2649 int v
= cmd
->args
[0].v
.i
;
2651 // start change for absolute volume value
2652 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2656 mixer_setvolume( (float)v
, (float)v
);
2665 if(osd_level
&& sh_video
){
2666 osd_visible
=sh_video
->fps
; // 1 sec
2667 vo_osd_progbar_type
=OSD_VOLUME
;
2668 vo_osd_progbar_value
=(mixer_getbothvolume()*256.0)/100.0;
2669 vo_osd_changed(OSDTYPE_PROGBAR
);
2676 case MP_CMD_LOADFILE
: {
2677 play_tree_t
* e
= play_tree_new();
2678 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
2680 // Go back to the start point
2681 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
2683 play_tree_free_list(playtree
->child
,1);
2684 play_tree_set_child(playtree
,e
);
2685 play_tree_iter_step(playtree_iter
,0,0);
2689 case MP_CMD_LOADLIST
: {
2690 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
2692 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
2694 // Go back to the start point
2695 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
2697 play_tree_free_list(playtree
->child
,1);
2698 play_tree_set_child(playtree
,e
);
2699 play_tree_iter_step(playtree_iter
,0,0);
2704 case MP_CMD_GAMMA
: {
2705 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2710 if (vo_gamma_gamma
== 1000)
2713 get_video_colors (sh_video
, "gamma", &vo_gamma_gamma
);
2719 vo_gamma_gamma
+= v
;
2721 if (vo_gamma_gamma
> 100)
2722 vo_gamma_gamma
= 100;
2723 else if (vo_gamma_gamma
< -100)
2724 vo_gamma_gamma
= -100;
2725 set_video_colors(sh_video
, "gamma", vo_gamma_gamma
);
2728 osd_visible
=sh_video
->fps
; // 1 sec
2729 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
2730 vo_osd_progbar_value
=(vo_gamma_gamma
<<7)/100 + 128;
2731 vo_osd_changed(OSDTYPE_PROGBAR
);
2735 case MP_CMD_BRIGHTNESS
: {
2736 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2741 if (vo_gamma_brightness
== 1000)
2743 vo_gamma_brightness
= 0;
2744 get_video_colors(sh_video
, "brightness", &vo_gamma_brightness
);
2748 vo_gamma_brightness
= v
;
2750 vo_gamma_brightness
+= v
;
2752 if (vo_gamma_brightness
> 100)
2753 vo_gamma_brightness
= 100;
2754 else if (vo_gamma_brightness
< -100)
2755 vo_gamma_brightness
= -100;
2756 if(set_video_colors(sh_video
, "brightness", vo_gamma_brightness
)){
2759 osd_visible
=sh_video
->fps
; // 1 sec
2760 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
2761 vo_osd_progbar_value
=(vo_gamma_brightness
<<7)/100 + 128;
2762 vo_osd_changed(OSDTYPE_PROGBAR
);
2767 case MP_CMD_CONTRAST
: {
2768 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2773 if (vo_gamma_contrast
== 1000)
2775 vo_gamma_contrast
= 0;
2776 get_video_colors(sh_video
, "contrast", &vo_gamma_contrast
);
2780 vo_gamma_contrast
= v
;
2782 vo_gamma_contrast
+= v
;
2784 if (vo_gamma_contrast
> 100)
2785 vo_gamma_contrast
= 100;
2786 else if (vo_gamma_contrast
< -100)
2787 vo_gamma_contrast
= -100;
2788 if(set_video_colors(sh_video
, "contrast", vo_gamma_contrast
)){
2791 osd_visible
=sh_video
->fps
; // 1 sec
2792 vo_osd_progbar_type
=OSD_CONTRAST
;
2793 vo_osd_progbar_value
=(vo_gamma_contrast
<<7)/100 + 128;
2794 vo_osd_changed(OSDTYPE_PROGBAR
);
2799 case MP_CMD_SATURATION
: {
2800 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2805 if (vo_gamma_saturation
== 1000)
2807 vo_gamma_saturation
= 0;
2808 get_video_colors(sh_video
, "saturation", &vo_gamma_saturation
);
2812 vo_gamma_saturation
= v
;
2814 vo_gamma_saturation
+= v
;
2816 if (vo_gamma_saturation
> 100)
2817 vo_gamma_saturation
= 100;
2818 else if (vo_gamma_saturation
< -100)
2819 vo_gamma_saturation
= -100;
2820 if(set_video_colors(sh_video
, "saturation", vo_gamma_saturation
)){
2823 osd_visible
=sh_video
->fps
; // 1 sec
2824 vo_osd_progbar_type
=OSD_SATURATION
;
2825 vo_osd_progbar_value
=(vo_gamma_saturation
<<7)/100 + 128;
2826 vo_osd_changed(OSDTYPE_PROGBAR
);
2832 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2837 if (vo_gamma_hue
== 1000)
2840 get_video_colors(sh_video
, "hue", &vo_gamma_hue
);
2848 if (vo_gamma_hue
> 100)
2850 else if (vo_gamma_hue
< -100)
2851 vo_gamma_hue
= -100;
2852 if(set_video_colors(sh_video
, "hue", vo_gamma_hue
)){
2855 osd_visible
=sh_video
->fps
; // 1 sec
2856 vo_osd_progbar_type
=OSD_HUE
;
2857 vo_osd_progbar_value
=(vo_gamma_hue
<<7)/100 + 128;
2858 vo_osd_changed(OSDTYPE_PROGBAR
);
2863 case MP_CMD_FRAMEDROPPING
: {
2864 int v
= cmd
->args
[0].v
.i
;
2866 frame_dropping
= (frame_dropping
+1)%3;
2868 frame_dropping
= v
> 2 ? 2 : v
;
2871 case MP_CMD_TV_SET_FREQ
: {
2872 if (file_format
== DEMUXER_TYPE_TV
)
2873 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
2875 case MP_CMD_TV_SET_NORM
: {
2876 if (file_format
== DEMUXER_TYPE_TV
)
2877 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
2879 case MP_CMD_TV_SET_BRIGHTNESS
: {
2880 if (file_format
== DEMUXER_TYPE_TV
)
2881 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_BRIGHTNESS
, cmd
->args
[0].v
.i
);
2883 case MP_CMD_TV_SET_HUE
: {
2884 if (file_format
== DEMUXER_TYPE_TV
)
2885 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_HUE
, cmd
->args
[0].v
.i
);
2887 case MP_CMD_TV_SET_SATURATION
: {
2888 if (file_format
== DEMUXER_TYPE_TV
)
2889 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_SATURATION
, cmd
->args
[0].v
.i
);
2891 case MP_CMD_TV_SET_CONTRAST
: {
2892 if (file_format
== DEMUXER_TYPE_TV
)
2893 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_CONTRAST
, cmd
->args
[0].v
.i
);
2895 case MP_CMD_TV_STEP_CHANNEL
: {
2896 if (file_format
== DEMUXER_TYPE_TV
) {
2897 int v
= cmd
->args
[0].v
.i
;
2899 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
2901 if (tv_channel_list
) {
2902 osd_show_tv_channel
= sh_video
->fps
;
2903 vo_osd_changed(OSDTYPE_SUBTITLE
);
2907 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
2909 if (tv_channel_list
) {
2910 osd_show_tv_channel
= sh_video
->fps
;
2911 vo_osd_changed(OSDTYPE_SUBTITLE
);
2917 #ifdef HAS_DVBIN_SUPPORT
2918 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
2920 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
2924 int v
= cmd
->args
[0].v
.i
;
2928 dir
= DVB_CHANNEL_HIGHER
;
2930 dir
= DVB_CHANNEL_LOWER
;
2933 if(dvb_step_channel(priv
, dir
))
2935 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
2936 printf("UNINIT COMPLETE\n");
2937 goto goto_open_demuxer
;
2943 case MP_CMD_TV_SET_CHANNEL
: {
2944 if (file_format
== DEMUXER_TYPE_TV
) {
2945 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
2947 if (tv_channel_list
) {
2948 osd_show_tv_channel
= sh_video
->fps
;
2949 vo_osd_changed(OSDTYPE_SUBTITLE
);
2954 #ifdef HAS_DVBIN_SUPPORT
2955 case MP_CMD_DVB_SET_CHANNEL
:
2957 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
2959 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
2962 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
2967 if(dvb_set_channel(priv
, cmd
->args
[0].v
.i
))
2969 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
2970 goto goto_open_demuxer
;
2976 case MP_CMD_TV_LAST_CHANNEL
: {
2977 if (file_format
== DEMUXER_TYPE_TV
) {
2978 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
2980 if (tv_channel_list
) {
2981 osd_show_tv_channel
= sh_video
->fps
;
2982 vo_osd_changed(OSDTYPE_SUBTITLE
);
2987 case MP_CMD_TV_STEP_NORM
: {
2988 if (file_format
== DEMUXER_TYPE_TV
)
2989 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
2991 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
2992 if (file_format
== DEMUXER_TYPE_TV
)
2993 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
2996 case MP_CMD_VO_FULLSCREEN
:
2999 if ( use_gui
) guiGetEvent( guiIEvent
,(char *)MP_CMD_GUI_FULLSCREEN
);
3002 if(video_out
&& vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
3004 case MP_CMD_PANSCAN
: {
3005 if ( !video_out
) break;
3006 if ( video_out
->control( VOCTRL_GET_PANSCAN
,NULL
) == VO_TRUE
)
3008 int abs
= cmd
->args
[1].v
.i
;
3009 float v
= cmd
->args
[0].v
.f
;
3012 else res
= vo_panscan
+v
;
3013 vo_panscan
= res
> 1 ? 1 : res
< 0 ? 0 : res
;
3014 video_out
->control( VOCTRL_SET_PANSCAN
,NULL
);
3016 if(osd_level
&& sh_video
){
3017 osd_visible
=sh_video
->fps
; // 1 sec
3018 vo_osd_progbar_type
=OSD_PANSCAN
;
3019 vo_osd_progbar_value
=vo_panscan
*256;
3020 vo_osd_changed(OSDTYPE_PROGBAR
);
3021 #ifdef HAVE_FREETYPE
3022 if (subtitle_autoscale
== 2 || subtitle_autoscale
== 3)
3023 // force scaling font to movie width or diagonal
3024 force_load_font
= 1;
3030 case MP_CMD_SUB_POS
:
3035 v
= cmd
->args
[0].v
.i
;
3038 if(sub_pos
>100) sub_pos
=100;
3039 if(sub_pos
<0) sub_pos
=0;
3040 vo_osd_changed(OSDTYPE_SUBTITLE
);
3041 osd_show_sub_pos
= 9;
3045 case MP_CMD_SUB_ALIGNMENT
:
3049 if (cmd
->nargs
>= 1)
3050 sub_alignment
= cmd
->args
[0].v
.i
;
3052 sub_alignment
= (sub_alignment
+1) % 3;
3053 osd_show_sub_alignment
= 9;
3054 vo_osd_changed(OSDTYPE_SUBTITLE
);
3058 case MP_CMD_SUB_VISIBILITY
:
3062 sub_visibility
=1-sub_visibility
;
3063 osd_show_sub_visibility
= 9; // show state of subtitle visibility in OSD
3064 vo_osd_changed(OSDTYPE_SUBTITLE
);
3068 case MP_CMD_GET_SUB_VISIBILITY
:
3072 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_SUB_VISIBILITY=%ld\n", sub_visibility
);
3076 case MP_CMD_VOBSUB_LANG
:
3079 int new_id
= vobsub_id
+ 1;
3082 if ((unsigned int) new_id
>= vobsub_get_indexes_count(vo_vobsub
))
3084 if(new_id
!= vobsub_id
)
3085 osd_show_vobsub_changed
= 9;
3089 else if (set_of_sub_size
> 0){ //change subtitle file
3090 set_of_sub_pos
= (set_of_sub_pos
+ 1) % set_of_sub_size
;
3091 subdata
= set_of_subtitles
[set_of_sub_pos
];
3092 osd_show_sub_changed
= sh_video
->fps
;
3094 vo_osd_changed(OSDTYPE_SUBTITLE
);
3098 case MP_CMD_SUB_FORCED_ONLY
:
3100 forced_subs_only
= forced_subs_only
? 0 : ~0; // toggle state
3101 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3104 case MP_CMD_SCREENSHOT
:
3105 if(vo_config_count
) video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
3107 case MP_CMD_VF_CHANGE_RECTANGLE
:
3108 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
3111 case MP_CMD_GET_TIME_LENGTH
: {
3112 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_LENGTH=%ld\n", demuxer_get_time_length(demuxer
));
3115 case MP_CMD_GET_VO_FULLSCREEN
: {
3116 if(video_out
&& vo_config_count
)
3117 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_VO_FULLSCREEN=%ld\n", vo_fs
);
3120 case MP_CMD_GET_PERCENT_POS
: {
3121 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ANS_PERCENT_POSITION=%ld\n", demuxer_get_percent_pos(demuxer
));
3125 case MP_CMD_DVDNAV_EVENT
: {
3126 dvdnav_priv_t
* dvdnav_priv
= (dvdnav_priv_t
*)(stream
->priv
);
3127 dvdnav_event_t
* dvdnav_event
= (dvdnav_event_t
*)(cmd
->args
[0].v
.v
);
3129 /* ignore these events if we're not in dvd_nav mode */
3130 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3132 if (!dvdnav_event
) {
3133 printf("DVDNAV Event NULL?!\n");
3137 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3139 switch (dvdnav_event
->event
) {
3140 case DVDNAV_BLOCK_OK
: {
3141 /* be silent about this one */
3144 case DVDNAV_HIGHLIGHT
: {
3145 dvdnav_highlight_event_t
*hevent
= (dvdnav_highlight_event_t
*)(dvdnav_event
->details
);
3147 printf("DVDNAV Event: Highlight event broken\n");
3151 if (hevent
->display
&& hevent
->buttonN
>0)
3153 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3154 sprintf( dvd_nav_text
, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3156 hevent
->sx
,hevent
->sy
,
3157 hevent
->ex
,hevent
->ey
,
3158 hevent
->pts
, d_video
->pts
);
3159 printf("DVDNAV Event: %s\n",dvd_nav_text
);
3160 //osd_show_dvd_nav_delay = 60;
3162 osd_show_dvd_nav_highlight
=1;
3163 osd_show_dvd_nav_sx
=hevent
->sx
;
3164 osd_show_dvd_nav_ex
=hevent
->ex
;
3165 osd_show_dvd_nav_sy
=hevent
->sy
;
3166 osd_show_dvd_nav_ey
=hevent
->ey
;
3169 osd_show_dvd_nav_highlight
=0;
3170 printf("DVDNAV Event: Highlight Hide\n");
3174 case DVDNAV_STILL_FRAME
: {
3175 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*)(dvdnav_event
->details
);
3177 printf( "######################################## DVDNAV Event: Still Frame: %d sec(s)\n", still_event
->length
);
3178 while (dvdnav_stream_sleeping(dvdnav_priv
)) {
3179 usec_sleep(1000); /* 1ms */
3181 dvdnav_stream_sleep(dvdnav_priv
,still_event
->length
);
3185 printf( "DVDNAV Event: Nav Stop\n" );
3189 printf("DVDNAV Event: Nav NOP\n");
3192 case DVDNAV_SPU_STREAM_CHANGE
: {
3193 #if DVDNAVVERSION > 012
3194 dvdnav_spu_stream_change_event_t
*stream_change
= (dvdnav_spu_stream_change_event_t
*)(dvdnav_event
->details
);
3196 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d/%d/%d logical: %d\n",
3197 stream_change
->physical_wide
,
3198 stream_change
->physical_letterbox
,
3199 stream_change
->physical_pan_scan
,
3200 stream_change
->logical
);
3202 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical_wide
) {
3203 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3204 d_dvdsub
->id
,stream_change
->physical_wide
);
3205 // FIXME: need a better way to change SPU id
3206 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical_wide
;
3207 if (vo_spudec
) spudec_reset(vo_spudec
);
3210 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3212 printf("DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n",
3213 stream_change
->physical
,
3214 stream_change
->logical
);
3216 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical
) {
3217 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3218 d_dvdsub
->id
,stream_change
->physical
);
3219 // FIXME: need a better way to change SPU id
3220 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical
;
3221 if (vo_spudec
) spudec_reset(vo_spudec
);
3226 case DVDNAV_AUDIO_STREAM_CHANGE
: {
3228 #if DVDNAVVERSION > 012
3229 dvdnav_audio_stream_change_event_t
*stream_change
= (dvdnav_audio_stream_change_event_t
*)(dvdnav_event
->details
);
3231 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3234 printf("DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n",
3235 stream_change
->physical
,
3236 stream_change
->logical
);
3238 aid_temp
=stream_change
->physical
;
3239 if (aid_temp
>=0) aid_temp
+=128; // FIXME: is this sane?
3240 if (d_audio
&& audio_id
!=aid_temp
) {
3241 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_audio->id change: was %d is now %d\n",
3242 d_audio
->id
,aid_temp
);
3243 // FIXME: need a bettery way to change audio stream id
3244 d_audio
->id
=dvdsub_id
=aid_temp
;
3245 if(sh_audio
) resync_audio_stream(sh_audio
);
3250 case DVDNAV_VTS_CHANGE
: {
3251 printf("DVDNAV Event: Nav VTS Change\n");
3254 case DVDNAV_CELL_CHANGE
: {
3255 dvdnav_cell_change_event_t
*cell_change
= (dvdnav_cell_change_event_t
*)(dvdnav_event
->details
);
3256 cell_playback_t
* cell_playback
= cell_change
->new_cell
;
3258 printf("DVDNAV Event: Nav Cell Change\n");
3259 osd_show_dvd_nav_highlight
=0; /* screen changed, disable menu */
3261 printf("new still time: %d\n",cell_playback->still_time);
3262 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3263 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3264 cell_playback->playback_time.hour,
3265 cell_playback->playback_time.minute,
3266 cell_playback->playback_time.second,
3267 cell_playback->playback_time.frame_u);
3270 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3274 case DVDNAV_NAV_PACKET
: {
3275 // printf("DVDNAV Event: Nav Packet\n");
3278 case DVDNAV_SPU_CLUT_CHANGE
: {
3279 uint32_t * new_clut
= (uint32_t *)(dvdnav_event
->details
);
3281 printf("DVDNAV Event: Nav SPU CLUT Change\n");
3282 // send new palette to SPU decoder
3283 if (vo_spudec
) spudec_update_palette(vo_spudec
,new_clut
);
3287 case DVDNAV_SEEK_DONE
: {
3288 printf("DVDNAV Event: Nav Seek Done\n");
3293 // free the dvdnav event
3294 free(dvdnav_event
->details
);
3296 cmd
->args
[0].v
.v
=NULL
;
3298 case MP_CMD_DVDNAV
: {
3299 dvdnav_priv_t
* dvdnav_priv
=(dvdnav_priv_t
*)stream
->priv
;
3301 /* ignore these events if we're not in dvd_nav mode */
3302 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3304 switch (cmd
->args
[0].v
.i
) {
3305 case MP_CMD_DVDNAV_UP
:
3306 dvdnav_upper_button_select(dvdnav_priv
->dvdnav
);
3308 case MP_CMD_DVDNAV_DOWN
:
3309 dvdnav_lower_button_select(dvdnav_priv
->dvdnav
);
3311 case MP_CMD_DVDNAV_LEFT
:
3312 dvdnav_left_button_select(dvdnav_priv
->dvdnav
);
3314 case MP_CMD_DVDNAV_RIGHT
:
3315 dvdnav_right_button_select(dvdnav_priv
->dvdnav
);
3317 case MP_CMD_DVDNAV_MENU
:
3318 printf("Menu call\n");
3319 dvdnav_menu_call(dvdnav_priv
->dvdnav
,DVD_MENU_Root
);
3321 case MP_CMD_DVDNAV_SELECT
:
3322 dvdnav_button_activate(dvdnav_priv
->dvdnav
);
3325 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Weird DVD Nav cmd %d\n",cmd
->args
[0].v
.i
);
3333 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3336 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
3346 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
3347 rel_seek_secs
+= 3600*a
+60*b
+d
;
3348 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
3349 rel_seek_secs
+= 60*a
+d
;
3350 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
3357 if(eof
==1 && loop_times
>=0) {
3359 play_tree_iter_step(playtree_iter
,0,0);
3361 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
3363 if(loop_times
>1) loop_times
--; else
3364 if(loop_times
==1) loop_times
=-1;
3365 play_n_frames
=play_n_frames_mf
;
3367 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
3371 if(rel_seek_secs
|| abs_seek_pos
){
3372 current_module
="seek";
3373 if(demux_seek(demuxer
,rel_seek_secs
,abs_seek_pos
)){
3375 /* FIXME there should be real seeking for vobsub */
3376 if(sh_video
) sh_video
->pts
=d_video
->pts
;
3378 vobsub_reset(vo_vobsub
);
3380 if(sh_video
&& d_video
->packs
== 0)
3381 ds_fill_buffer(d_video
);
3383 if(d_audio
->packs
== 0)
3384 ds_fill_buffer(d_audio
);
3386 float a_pts
=d_audio
->pts
;
3387 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
3388 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
);
3390 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
);
3392 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A: --- V:%6.1f \r",d_video
->pts
);
3398 current_module
="seek_video_reset";
3399 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
3403 current_module
="seek_audio_reset";
3404 audio_out
->reset(); // stop audio, throwing away buffered data
3408 if(osd_level
&& !loop_seek
){
3410 if( !edl_decision
) {
3412 if( 1 ) { // Let the compiler optimize this out
3414 int len
=((demuxer
->movi_end
-demuxer
->movi_start
)>>8);
3415 if (len
>0 && sh_video
){
3416 osd_visible
=sh_video
->fps
; // 1 sec
3417 vo_osd_progbar_type
=0;
3418 vo_osd_progbar_value
=(demuxer
->filepos
-demuxer
->movi_start
)/len
;
3419 vo_osd_changed(OSDTYPE_PROGBAR
);
3426 max_pts_correction
=0.1;
3427 osd_visible
=sh_video
->fps
; // to rewert to PLAY pointer after 1 sec
3428 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3430 too_slow_frame_cnt
=0;
3431 too_fast_frame_cnt
=0;
3433 if(vo_spudec
) spudec_reset(vo_spudec
);
3439 if( !edl_decision
) {
3440 for( x
= 0; x
< num_edl_records
; x
++ ) { // FIXME: do binary search
3441 // Find first EDL entry where start follows current time
3442 if( edl_records
[ x
].start_sec
>= sh_video
->pts
&& edl_records
[ x
].action
!= EDL_MUTE
) {
3443 next_edl_record
= &edl_records
[ x
];
3454 frame_time_remaining
=0;
3455 current_module
=NULL
;
3462 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
3463 // get pos from frame number / total frames
3464 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
3466 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
3467 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
3468 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
3470 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
3471 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
3472 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
3473 guiGetEvent( guiReDraw
,NULL
);
3474 guiGetEvent( guiSetVolume
,NULL
);
3475 if(guiIntfStruct
.Playing
==0) break; // STOP
3476 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
3477 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3479 if ( stream
->type
== STREAMTYPE_DVD
)
3481 dvd_priv_t
* dvdp
= stream
->priv
;
3482 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3489 //================= Update OSD ====================
3491 if(osd_level
>=1 && sh_video
){
3492 int pts
=sh_video
->pts
;
3493 char osd_text_tmp
[64];
3494 if(pts
==osd_last_pts
-1) ++pts
; else osd_last_pts
=pts
;
3495 vo_osd_text
=osd_text_buffer
;
3497 if (osd_show_dvd_nav_delay
) {
3498 snprintf(osd_text_tmp
, 63, "DVDNAV: %s", dvd_nav_text
);
3499 osd_show_dvd_nav_delay
--;
3503 if (osd_show_tv_channel
&& tv_channel_list
) {
3504 snprintf(osd_text_tmp
, 63, "Channel: %s", tv_channel_current
->name
);
3505 osd_show_tv_channel
--;
3508 if (osd_show_text
) {
3509 snprintf(osd_text_tmp
, 63, "%s", osd_show_text_buffer
);
3512 if (osd_show_sub_visibility
) {
3513 snprintf(osd_text_tmp
, 63, "Subtitles: %sabled", sub_visibility
?"en":"dis");
3514 osd_show_sub_visibility
--;
3516 if (osd_show_vobsub_changed
) {
3517 const char *language
= "none";
3518 if (vo_vobsub
&& vobsub_id
>= 0)
3519 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
3520 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", vobsub_id
, language
? language
: "unknown");
3521 osd_show_vobsub_changed
--;
3524 if (osd_show_sub_changed
) {
3526 tmp
= subdata
->filename
;
3527 if ((tmp2
= strrchr(tmp
, '/'))) {
3530 snprintf(osd_text_tmp
, 63, "Sub: (%d) %s%s",
3532 strlen(tmp
) < 20 ? "" : "...",
3533 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
3534 osd_show_sub_changed
--;
3537 if (osd_show_sub_delay
) {
3538 snprintf(osd_text_tmp
, 63, "Sub delay: %d ms", ROUND(sub_delay
*1000));
3539 osd_show_sub_delay
--;
3541 if (osd_show_sub_pos
) {
3542 snprintf(osd_text_tmp
, 63, "Sub position: %d/100", sub_pos
);
3545 if (osd_show_sub_alignment
) {
3546 snprintf(osd_text_tmp
, 63, "Sub alignment: %s",
3547 (sub_alignment
== 2 ? "bottom" :
3548 (sub_alignment
== 1 ? "center" : "top")));
3549 osd_show_sub_alignment
--;
3551 if (osd_show_av_delay
) {
3552 snprintf(osd_text_tmp
, 63, "A-V delay: %d ms", ROUND(audio_delay
*1000));
3553 osd_show_av_delay
--;
3554 } else if(osd_level
>=2) {
3555 int len
= demuxer_get_time_length(demuxer
);
3556 int percentage
= -1;
3557 char percentage_text
[10];
3558 if (osd_show_percentage
) {
3559 percentage
= demuxer_get_percent_pos(demuxer
);
3560 osd_show_percentage
--;
3562 if (percentage
>= 0)
3563 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
3565 percentage_text
[0] = 0;
3567 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
);
3569 snprintf(osd_text_tmp
, 63, "%c %02d:%02d:%02d%s",osd_function
,pts
/3600,(pts
/60)%60,pts
%60,percentage_text
);
3570 } else osd_text_tmp
[0]=0;
3572 if(strcmp(vo_osd_text
, osd_text_tmp
)) {
3573 strncpy(vo_osd_text
, osd_text_tmp
, 63);
3574 vo_osd_changed(OSDTYPE_OSD
);
3579 vo_osd_changed(OSDTYPE_OSD
);
3582 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3583 // vo_osd_text=osd_text_buffer;
3588 if(subdata
&& sh_video
->pts
>0){
3589 float pts
=sh_video
->pts
;
3590 if(sub_fps
==0) sub_fps
=sh_video
->fps
;
3591 current_module
="find_sub";
3592 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0 ) {
3593 find_sub(subdata
, (pts
+sub_delay
) *
3594 (subdata
->sub_uses_time
? 100. : sub_fps
));
3595 // FIXME! frame counter...
3598 current_module
=NULL
;
3603 if (stop_xscreensaver
&& sh_video
) {
3604 current_module
="stop_xscreensaver";
3605 xscreensaver_heartbeat(sh_video
->pts
);
3606 current_module
=NULL
;
3611 if(vo_config_count
&& vo_spudec
) {
3612 unsigned char* packet
=NULL
;
3614 current_module
="spudec";
3615 spudec_heartbeat(vo_spudec
,90000*sh_video
->timer
);
3616 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3621 if(sh_video
->pts
+sub_delay
>=0) {
3622 // The + next_frame_time is there because we'll display the sub at the next frame
3623 len
= vobsub_get_packet(vo_vobsub
,sh_video
->pts
+sub_delay
+next_frame_time
,(void**)&packet
,×tamp
);
3625 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
3626 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
);
3631 len
= ds_get_packet_sub(d_dvdsub
,(unsigned char**)&packet
);
3633 float x
= d_dvdsub
->pts
- sh_video
->pts
;
3634 if (x
< -10 || x
> 10) // prevent missing subs on pts reset
3635 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
+ sub_delay
- sh_video
->pts
);
3636 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
3637 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
);
3640 if(len
<=0 || !packet
) break;
3641 if(timestamp
< 0) timestamp
= 0;
3642 spudec_assemble(vo_spudec
,packet
,len
,timestamp
);
3645 /* detect wether the sub has changed or not */
3646 if(spudec_changed(vo_spudec
))
3647 vo_osd_changed(OSDTYPE_SPU
);
3648 current_module
=NULL
;
3653 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
3657 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3659 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3662 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3663 double total_time_usage
;
3664 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3665 total_time_usage
= (float)total_time_usage_start
*0.000001;
3666 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3667 video_time_usage
,vout_time_usage
,audio_time_usage
,
3668 total_time_usage
-tot
,total_time_usage
);
3669 if(total_time_usage
>0.0)
3670 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3671 100.0*video_time_usage
/total_time_usage
,
3672 100.0*vout_time_usage
/total_time_usage
,
3673 100.0*audio_time_usage
/total_time_usage
,
3674 100.0*(total_time_usage
-tot
)/total_time_usage
,
3676 if(total_frame_cnt
&& frame_dropping
)
3677 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3678 total_frame_cnt
-drop_frame_cnt
,
3679 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3681 100*drop_frame_cnt
/total_frame_cnt
,
3683 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
3687 // time to uninit all, except global stuff:
3688 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
3691 if ( set_of_sub_size
> 0 )
3693 current_module
="sub_free";
3694 for (i
= 0; i
< set_of_sub_size
; ++i
)
3695 sub_free( set_of_subtitles
[i
] );
3696 set_of_sub_size
= 0;
3702 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
3703 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
3704 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
3707 play_tree_iter_free(playtree_iter
);
3708 playtree_iter
= NULL
;
3711 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
3712 eof
= eof
== PT_UP_NEXT
? 1 : -1;
3713 if ( playtree_iter
) {
3714 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
3717 play_tree_iter_free(playtree_iter
);
3718 playtree_iter
= NULL
;
3721 } else { // NEXT PREV SRC
3722 eof
= eof
== PT_PREV_SRC
? -1 : 1;
3725 if(eof
== 0) eof
= 1;
3727 while(playtree_iter
!= NULL
) {
3728 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
3729 if(filename
== NULL
) {
3730 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
3731 play_tree_iter_free(playtree_iter
);
3732 playtree_iter
= NULL
;
3739 if( use_gui
&& !playtree_iter
)
3742 if ( !guiIntfStruct
.DiskChanged
)
3748 if(use_gui
|| playtree_iter
!= NULL
){
3751 goto play_next_file
;
3754 #ifdef HAVE_FREETYPE
3755 current_module
="uninit_font";
3756 if (vo_font
) free_font_desc(vo_font
);
3761 exit_player_with_rc(MSGTR_Exit_eof
, 0);