6 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
12 // #include <sys/mman.h>
13 #include <sys/types.h>
15 #include <sys/ioctl.h>
18 #define SIGHUP 1 /* hangup */
19 #define SIGQUIT 3 /* quit */
20 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
21 #define SIGBUS 10 /* bus error */
22 extern int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
);
39 #define HELP_MP_DEFINE_STATIC
45 #include "cfg-mplayer-def.h"
48 #include "subreader.h"
51 #include "libvo/video_out.h"
53 #include "libvo/font_load.h"
54 #include "libvo/sub.h"
57 #include "libvo/x11_common.h"
60 #include "libao2/audio_out.h"
61 #include "libao2/audio_plugin.h"
63 #include "codec-cfg.h"
76 #include "osdep/getch2.h"
77 #include "osdep/timer.h"
79 #include "cpudetect.h"
82 #include "Gui/interface.h"
85 #include "input/input.h"
92 #define ABS(x) (((x)>=0)?(x):(-(x)))
93 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
96 #include <linux/rtc.h>
100 #include "libmpdemux/tv.h"
103 #ifdef HAS_DVBIN_SUPPORT
104 #include "libmpdemux/dvbin.h"
105 static int last_dvb_step
= 1;
108 //**************************************************************************//
110 //**************************************************************************//
111 #include "playtree.h"
112 #include "playtreeparser.h"
115 extern int import_playtree_playlist_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
);
116 extern int import_initial_playtree_into_gui(play_tree_t
* my_playtree
, m_config_t
* config
, int enqueue
);
119 play_tree_t
* playtree
;
120 play_tree_iter_t
* playtree_iter
= NULL
;
122 #define PT_NEXT_ENTRY 1
123 #define PT_PREV_ENTRY -1
124 #define PT_NEXT_SRC 2
125 #define PT_PREV_SRC -2
127 #define PT_UP_PREV -3
129 //**************************************************************************//
131 //**************************************************************************//
135 m_config_parse_mp_command_line(m_config_t
*config
, int argc
, char **argv
);
137 m_config_parse_config_file(m_config_t
* config
, char *conffile
);
139 //**************************************************************************//
141 //**************************************************************************//
143 static int cfg_inc_verbose(m_option_t
*conf
){ ++verbose
; return 0;}
145 static int cfg_include(m_option_t
*conf
, char *filename
){
146 return m_config_parse_config_file(mconfig
, filename
);
149 #include "get_path.c"
151 //**************************************************************************//
153 //**************************************************************************//
156 void xscreensaver_heartbeat(void);
159 //**************************************************************************//
160 //**************************************************************************//
161 // Input media streaming & demultiplexer:
162 //**************************************************************************//
164 static int max_framesize
=0;
166 #include "libmpdemux/stream.h"
167 #include "libmpdemux/demuxer.h"
168 #include "libmpdemux/stheader.h"
169 //#include "parse_es.h"
171 #include "libmpdemux/matroska.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
186 int noconsolecontrols
=0;
187 //**************************************************************************//
189 vo_functions_t
*video_out
=NULL
;
190 ao_functions_t
*audio_out
=NULL
;
196 double video_time_usage
=0;
197 double vout_time_usage
=0;
198 static double audio_time_usage
=0;
199 static int total_time_usage_start
=0;
200 static int total_frame_cnt
=0;
201 static int drop_frame_cnt
=0; // total number of dropped frames
206 static int output_quality
=0;
208 float playback_speed
=1.0;
216 #define MAX_OSD_LEVEL 3
219 int osd_level_saved
=-1;
223 static char *seek_to_sec
=NULL
;
224 static off_t seek_to_byte
=0;
225 static off_t step_sec
=0;
226 static int loop_times
=-1;
227 static int loop_seek
=0;
230 int autosync
=0; // 30 might be a good default value.
232 // may be changed by GUI: (FIXME!)
233 float rel_seek_secs
=0;
237 char **audio_codec_list
=NULL
; // override audio codec
238 char **video_codec_list
=NULL
; // override video codec
239 char **audio_fm_list
=NULL
; // override audio codec family
240 char **video_fm_list
=NULL
; // override video codec family
247 char* audio_lang
=NULL
;
248 char* dvdsub_lang
=NULL
;
249 static char* spudec_ifo
=NULL
;
250 char* filename
=NULL
; //"MI2-Trailer.avi";
251 int forced_subs_only
=0;
254 int stream_cache_size
=-1;
255 #ifdef USE_STREAM_CACHE
256 extern int cache_fill_status
;
258 float stream_cache_min_percent
=20.0;
259 float stream_cache_prefill_percent
=5.0;
261 #define cache_fill_status 0
265 static char *stream_dump_name
="stream.dump";
266 int stream_dump_type
=0;
269 static float default_max_pts_correction
=-1;//0.01f;
270 static float max_pts_correction
=0;//default_max_pts_correction;
271 static float c_total
=0;
274 static int softsleep
=0;
277 static int force_srate
=0;
278 static int audio_output_format
=0;
279 int frame_dropping
=0; // option 0=no drop 1= drop vo 2= drop decode
280 static int play_n_frames
=-1;
281 static int play_n_frames_mf
=-1;
284 char** video_driver_list
=NULL
;
285 char** audio_driver_list
=NULL
;
287 extern char *vo_subdevice
;
288 extern char *ao_subdevice
;
290 // codec outfmt flags (defined in libmpcodecs/vd.c)
294 char *font_name
=NULL
;
295 #ifdef HAVE_FONTCONFIG
296 extern int font_fontconfig
;
298 float font_factor
=0.75;
299 char **sub_name
=NULL
;
303 char *vobsub_name
=NULL
;
304 /*DSP!!char *dsp=NULL;*/
306 int suboverlap_enabled
= 1;
308 sub_data
* set_of_subtitles
[MAX_SUBTITLE_FILES
];
309 int set_of_sub_size
= 0;
310 int set_of_sub_pos
= -1;
311 float sub_last_pts
= -303;
313 int global_sub_size
= 0; // this encompasses all subtitle sources
314 int global_sub_pos
= -1; // this encompasses all subtitle sources
315 #define SUB_SOURCE_SUBS 0
316 #define SUB_SOURCE_VOBSUB 1
317 #define SUB_SOURCE_DEMUX 2
318 #define SUB_SOURCES 3
319 int global_sub_indices
[SUB_SOURCES
];
320 int global_sub_quiet_osd_hack
= 0;
322 static stream_t
* stream
=NULL
;
323 static demuxer_t
*demuxer
=NULL
;
324 static sh_audio_t
*sh_audio
=NULL
;
325 static sh_video_t
*sh_video
=NULL
;
327 char* current_module
=NULL
; // for debugging
329 extern int vo_gamma_gamma
;
330 extern int vo_gamma_brightness
;
331 extern int vo_gamma_contrast
;
332 extern int vo_gamma_saturation
;
333 extern int vo_gamma_hue
;
338 #include "m_struct.h"
339 #include "libmenu/menu.h"
340 extern void vf_menu_pause_update(struct vf_instance_s
* vf
);
341 extern vf_info_t vf_info_menu
;
342 static vf_info_t
* libmenu_vfs
[] = {
346 static vf_instance_t
* vf_menu
= NULL
;
347 static int use_menu
= 0;
348 static char* menu_cfg
= NULL
;
349 static char* menu_root
= "main";
355 static char* rtc_device
;
359 edl_record_ptr edl_records
= NULL
; /// EDL entries memory area
360 edl_record_ptr next_edl_record
= NULL
; /// only for traversing edl_records
361 int edl_memory_slots
= 0; /// number of EDL entries (1 for skip + 2 for each mute)
362 int edl_operations
= 0; /// number of EDL operations, skip + mute
363 short edl_decision
= 0; /// 1 when an EDL operation has been made
364 FILE* edl_fd
= NULL
; /// fd to write to when in -edlout mode
365 int edl_mute_count
= 0; /// even number when mute and unmute has been matched
368 static unsigned int inited_flags
=0;
372 #define INITED_GETCH2 8
373 #define INITED_SPUDEC 32
374 #define INITED_STREAM 64
375 #define INITED_INPUT 128
376 #define INITED_VOBSUB 256
377 #define INITED_DEMUXER 512
378 #define INITED_ACODEC 1024
379 #define INITED_VCODEC 2048
380 #define INITED_ALL 0xFFFF
382 static void uninit_player(unsigned int mask
){
383 mask
=inited_flags
&mask
;
385 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n*** uninit(0x%X)\n",mask
);
387 if(mask
&INITED_ACODEC
){
388 inited_flags
&=~INITED_ACODEC
;
389 current_module
="uninit_acodec";
390 if(sh_audio
) uninit_audio(sh_audio
);
394 if(mask
&INITED_VCODEC
){
395 inited_flags
&=~INITED_VCODEC
;
396 current_module
="uninit_vcodec";
397 if(sh_video
) uninit_video(sh_video
);
404 if(mask
&INITED_DEMUXER
){
405 inited_flags
&=~INITED_DEMUXER
;
406 current_module
="free_demuxer";
408 stream
=demuxer
->stream
;
409 free_demuxer(demuxer
);
414 // kill the cache process:
415 if(mask
&INITED_STREAM
){
416 inited_flags
&=~INITED_STREAM
;
417 current_module
="uninit_stream";
418 if(stream
) free_stream(stream
);
423 inited_flags
&=~INITED_VO
;
424 current_module
="uninit_vo";
429 // must be after libvo uninit, as few vo drivers (svgalib) has tty code
430 if(mask
&INITED_GETCH2
){
431 inited_flags
&=~INITED_GETCH2
;
432 current_module
="uninit_getch2";
433 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[uninit getch2]]]\n");
438 if(mask
&INITED_VOBSUB
){
439 inited_flags
&=~INITED_VOBSUB
;
440 current_module
="uninit_vobsub";
441 if(vo_vobsub
) vobsub_close(vo_vobsub
);
445 if (mask
&INITED_SPUDEC
){
446 inited_flags
&=~INITED_SPUDEC
;
447 current_module
="uninit_spudec";
448 spudec_free(vo_spudec
);
453 inited_flags
&=~INITED_AO
;
454 current_module
="uninit_ao";
455 audio_out
->uninit(eof
?0:1); audio_out
=NULL
;
460 inited_flags
&=~INITED_GUI
;
461 current_module
="uninit_gui";
466 if(mask
&INITED_INPUT
){
467 inited_flags
&=~INITED_INPUT
;
468 current_module
="uninit_input";
475 static void exit_player_with_rc(char* how
, int rc
){
477 uninit_player(INITED_ALL
);
482 vo_uninit(); // close the X11 connection (if any opened)
485 current_module
="exit_player";
488 if(edl_records
!= NULL
) free(edl_records
); // free mem allocated for EDL
490 if(how
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_ExitingHow
,mp_gettext(how
));
491 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"max framesize was %d bytes\n",max_framesize
);
496 void exit_player(char* how
){
497 exit_player_with_rc(how
, 1);
501 static void child_sighandler(int x
){
503 while((pid
=waitpid(-1,NULL
,WNOHANG
)) > 0);
507 static void exit_sighandler(int x
){
508 static int sig_count
=0;
510 if(inited_flags
==0 && sig_count
>1) exit(1);
513 /* We're crashing bad and can't uninit cleanly :(
514 * by popular request, we make one last (dirty)
515 * effort to restore the user's
520 if(sig_count
==6) exit(1);
524 kill(getpid(),SIGKILL
);
527 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,"\n" MSGTR_IntBySignal
,x
,
528 current_module
?current_module
:mp_gettext("unknown")
536 break; // killed from keyboard (^C) or killed [-9]
538 #ifdef RUNTIME_CPUDETECT
539 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL_RTCpuSel
);
541 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGILL
);
545 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGSEGV_SIGFPE
);
547 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_Exit_SIGCRASH
);
552 //extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
554 extern void mp_input_register_options(m_config_t
* cfg
);
558 /// step size of mixer changes
561 #include "cfg-mplayer.h"
563 void parse_cfgfiles( m_config_t
* conf
)
567 if (m_config_parse_config_file(conf
, MPLAYER_CONFDIR
"/mplayer.conf") < 0)
569 if ((conffile
= get_path("")) == NULL
) {
570 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoHomeDir
);
575 mkdir(conffile
, 0777);
578 if ((conffile
= get_path("config")) == NULL
) {
579 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_GetpathProblem
);
581 if ((conffile_fd
= open(conffile
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666)) != -1) {
582 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CreatingCfgFile
, conffile
);
583 write(conffile_fd
, default_config
, strlen(default_config
));
586 if (m_config_parse_config_file(conf
, conffile
) < 0)
593 void load_per_file_config (m_config_t
* conf
, const char *const file
)
596 char cfg
[strlen(file
)+10];
600 sprintf (cfg
, "%s.conf", file
);
602 if (!stat (cfg
, &st
))
604 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, cfg
);
605 m_config_parse_config_file (conf
, cfg
);
609 if ((name
= strrchr (cfg
, '/')) == NULL
)
614 if ((confpath
= get_path (name
)) != NULL
)
616 if (!stat (confpath
, &st
))
618 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_LoadingConfig
, confpath
);
619 m_config_parse_config_file (conf
, confpath
);
626 // When libmpdemux perform a blocking operation (network connection or cache filling)
627 // if the operation fail we use this function to check if it was interrupted by the user.
628 // The function return a new value for eof.
629 static int libmpdemux_was_interrupted(int eof
) {
631 if((cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
634 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
635 case MP_CMD_PLAY_TREE_STEP
: {
636 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
638 case MP_CMD_PLAY_TREE_UP_STEP
: {
639 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
641 case MP_CMD_PLAY_ALT_SRC_STEP
: {
642 eof
= (cmd
->args
[0].v
.i
> 0) ? PT_NEXT_SRC
: PT_PREV_SRC
;
650 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
651 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
653 int playtree_add_playlist(play_tree_t
* entry
)
655 play_tree_add_bpf(entry
,filename
);
660 import_playtree_playlist_into_gui(entry
, mconfig
);
661 play_tree_free_list(entry
,1);
667 entry
= playtree_iter
->tree
;
668 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
669 return PT_NEXT_ENTRY
;
671 if(playtree_iter
->tree
== entry
) { // Loop with a single file
672 if(play_tree_iter_up_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
673 return PT_NEXT_ENTRY
;
676 play_tree_remove(entry
,1,1);
679 play_tree_insert_entry(playtree_iter
->tree
,entry
);
680 play_tree_set_params_from(entry
,playtree_iter
->tree
);
681 entry
= playtree_iter
->tree
;
682 if(play_tree_iter_step(playtree_iter
,1,0) != PLAY_TREE_ITER_ENTRY
) {
683 return PT_NEXT_ENTRY
;
685 play_tree_remove(entry
,1,1);
690 static int play_tree_step
= 1;
697 for (i
= 0; i
< SUB_SOURCES
; i
++) {
698 int j
= global_sub_indices
[i
];
699 if ((j
>= 0) && (j
> top
) && (global_sub_pos
>= j
)) {
709 sub_data
* subdata
= NULL
;
711 void add_subtitles(char *filename
, float fps
, int silent
)
715 if (filename
== NULL
) {
719 subd
= sub_read_file(filename
, fps
);
721 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_CantLoadSub
, filename
);
722 if (subd
== NULL
|| set_of_sub_size
>= MAX_SUBTITLE_FILES
) return;
723 set_of_subtitles
[set_of_sub_size
] = subd
;
725 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_AddedSubtitleFile
, set_of_sub_size
, filename
);
728 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
729 void update_set_of_subtitles()
730 // subdata was changed, set_of_sub... have to be updated.
733 if (set_of_sub_size
> 0 && subdata
== NULL
) { // *subdata was deleted
734 for (i
= set_of_sub_pos
+ 1; i
< set_of_sub_size
; ++i
)
735 set_of_subtitles
[i
-1] = set_of_subtitles
[i
];
736 set_of_subtitles
[set_of_sub_size
-1] = NULL
;
738 if (set_of_sub_size
> 0) subdata
= set_of_subtitles
[set_of_sub_pos
=0];
740 else if (set_of_sub_size
> 0 && subdata
!= NULL
) { // *subdata was changed
741 set_of_subtitles
[set_of_sub_pos
] = subdata
;
743 else if (set_of_sub_size
<= 0 && subdata
!= NULL
) { // *subdata was added
744 set_of_subtitles
[set_of_sub_pos
=set_of_sub_size
] = subdata
;
751 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
752 * make it all work is to use the builtin SDL-bootstrap code, which
753 * will be done automatically by replacing our main() if we include SDL.h.
755 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
760 int main(int argc
,char* argv
[]){
765 static demux_stream_t
*d_audio
=NULL
;
766 static demux_stream_t
*d_video
=NULL
;
767 static demux_stream_t
*d_dvdsub
=NULL
;
769 int file_format
=DEMUXER_TYPE_UNKNOWN
;
771 int delay_corrected
=1;
775 int osd_function
=OSD_PLAY
;
776 int osd_last_pts
=-303;
777 int osd_show_av_delay
= 0;
778 int osd_show_text
= 0;
779 int osd_show_sub_delay
= 0;
780 int osd_show_sub_pos
= 0;
781 int osd_show_sub_visibility
= 0;
782 int osd_show_sub_alignment
= 0;
783 int osd_show_vobsub_changed
= 0;
784 int osd_show_sub_changed
= 0;
785 int osd_show_percentage
= 0;
786 int osd_show_tv_channel
= 25;
787 int osd_show_ontop
= 0;
788 int osd_show_rootwin
= 0;
789 int osd_show_framedropping
= 0;
793 //float a_frame=0; // Audio
798 int gui_no_filename
=0;
801 srand((int) time(NULL
));
804 mp_msg_set_level(MSGL_STATUS
);
806 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, "MPlayer " VERSION
" (C) 2000-2004 MPlayer Team\n\n");
807 /* Test for cpu capabilities (and corresponding OS support) for optimizing */
808 GetCpuCaps(&gCpuCaps
);
810 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
811 gCpuCaps
.hasMMX
,gCpuCaps
.hasMMX2
,
812 gCpuCaps
.has3DNow
, gCpuCaps
.has3DNowExt
,
813 gCpuCaps
.hasSSE
, gCpuCaps
.hasSSE2
);
814 #ifdef RUNTIME_CPUDETECT
815 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithRuntimeDetection
);
817 mp_msg(MSGT_CPLAYER
,MSGL_INFO
, MSGTR_CompiledWithCPUExtensions
);
819 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX");
822 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," MMX2");
825 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNow");
828 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," 3DNowEx");
831 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE");
834 mp_msg(MSGT_CPLAYER
,MSGL_INFO
," SSE2");
836 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n\n");
840 #if defined(WIN32) && defined(USE_WIN32DLL)
841 { /*make our codec dirs available for LoadLibraryA()*/
842 char tmppath
[MAX_PATH
*2 + 1];
843 char win32path
[MAX_PATH
];
844 char realpath
[MAX_PATH
];
846 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
847 strcpy(tmppath
,win32path
);
848 #ifdef USE_REALCODECS
849 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
850 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
851 #endif /*USE_REALCODECS*/
853 if(!strstr(WIN32_PATH
,":")){
854 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
855 strcpy(win32path
+ strlen(win32path
) - strlen("mplayer.exe"), WIN32_PATH
);
857 else strcpy(win32path
,WIN32_PATH
);
858 strcpy(tmppath
,win32path
);
859 #ifdef USE_REALCODECS
860 if(!strstr(REALCODEC_PATH
,":")){
861 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
862 strcpy(realpath
+ strlen(realpath
) - strlen("mplayer.exe"), REALCODEC_PATH
);
864 else strcpy(realpath
,REALCODEC_PATH
);
865 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
866 #endif /*USE_REALCODECS*/
867 #endif /*__CYGWIN__*/
868 SetEnvironmentVariableA("PATH", tmppath
);
870 #endif /*WIN32 && USE_WIN32DLL*/
873 tv_param_immediate
= 1;
877 if(!strcmp(argv
[0],"gmplayer") ||
878 (strrchr(argv
[0],'/') && !strcmp(strrchr(argv
[0],'/'),"/gmplayer") ) )
881 mconfig
= m_config_new();
882 m_config_register_options(mconfig
,mplayer_opts
);
883 // TODO : add something to let modules register their options
884 mp_input_register_options(mconfig
);
885 parse_cfgfiles(mconfig
);
888 if ( use_gui
) cfg_read();
891 playtree
= m_config_parse_mp_command_line(mconfig
, argc
, argv
);
895 playtree
= play_tree_cleanup(playtree
);
897 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
899 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
) {
900 play_tree_iter_free(playtree_iter
);
901 playtree_iter
= NULL
;
903 filename
= play_tree_iter_get_file(playtree_iter
,1);
909 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_NoGui
);
913 if(use_gui
&& !vo_init()){
914 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_GuiNeedsX
);
917 if (use_gui
&& playtree_iter
){
918 char cwd
[PATH_MAX
+2];
919 // Remove Playtree and Playtree-Iter from memory as its not used by gui
920 play_tree_iter_free(playtree_iter
);
923 if (getcwd(cwd
, PATH_MAX
) != (char *)NULL
)
926 // Prefix relative paths with current working directory
927 play_tree_add_bpf(playtree
, cwd
);
929 // Import initital playtree into gui
930 import_initial_playtree_into_gui(playtree
, mconfig
, enqueue
);
934 if(video_driver_list
&& strcmp(video_driver_list
[0],"help")==0){
936 exit_player_with_rc(NULL
, 0);
939 if(audio_driver_list
&& strcmp(audio_driver_list
[0],"help")==0){
941 exit_player_with_rc(NULL
, 0);
945 if(!codecs_file
|| !parse_codec_cfg(codecs_file
)){
946 if(!parse_codec_cfg(mem_ptr
=get_path("codecs.conf"))){
947 if(!parse_codec_cfg(MPLAYER_CONFDIR
"/codecs.conf")){
948 if(!parse_codec_cfg(NULL
)){
949 mp_msg(MSGT_CPLAYER
,MSGL_HINT
,MSGTR_CopyCodecsConf
);
950 exit_player_with_rc(NULL
, 0);
952 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_BuiltinCodecsConf
);
955 free( mem_ptr
); // release the buffer created by get_path()
959 if(video_codec_list
){
961 video_codec
=video_codec_list
[0];
962 for(i
=0;video_codec_list
[i
];i
++)
963 mp_msg(MSGT_FIXME
,MSGL_FIXME
,"vc#%d: '%s'\n",i
,video_codec_list
[i
]);
966 if(audio_codec_list
&& strcmp(audio_codec_list
[0],"help")==0){
967 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableAudioCodecs
);
969 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
970 exit_player_with_rc(NULL
, 0);
972 if(video_codec_list
&& strcmp(video_codec_list
[0],"help")==0){
973 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_AvailableVideoCodecs
);
975 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
976 exit_player_with_rc(NULL
, 0);
978 if(video_fm_list
&& strcmp(video_fm_list
[0],"help")==0){
980 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
981 exit_player_with_rc(NULL
, 0);
983 if(audio_fm_list
&& strcmp(audio_fm_list
[0],"help")==0){
985 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
986 exit_player_with_rc(NULL
, 0);
988 if(af_cfg
.list
&& strcmp(af_cfg
.list
[0],"help")==0){
991 exit_player_with_rc(NULL
, 0);
994 if(vo_fstype_list
&& strcmp(vo_fstype_list
[0],"help")==0){
996 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
997 exit_player_with_rc(NULL
, 0);
1002 if (edl_check_mode() == EDL_ERROR
&& edl_filename
)
1004 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantUseBothModes
);
1006 } else if (edl_filename
)
1008 edl_memory_slots
= edl_count_entries();
1009 if (edl_memory_slots
> 0)
1011 edl_records
= calloc(edl_memory_slots
, sizeof(struct edl_record
));
1012 if (edl_records
== NULL
)
1014 mp_msg(MSGT_CPLAYER
, MSGL_FATAL
, MSGTR_EdlOutOfMem
);
1018 if ((edl_operations
= edl_parse_file(edl_records
)) > 0)
1020 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdlRecordsNo
,
1025 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdlQueueEmpty
);
1030 next_edl_record
= edl_records
;
1032 } else if (edl_output_filename
)
1034 if ((edl_fd
= fopen(edl_output_filename
, "w")) == NULL
)
1036 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlCantOpenForWrite
,
1037 edl_output_filename
);
1045 // no file/vcd/dvd -> show HELP:
1046 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, help_text
);
1047 exit_player_with_rc(NULL
, 0);
1048 } else gui_no_filename
=1;
1051 // Many users forget to include command line in bugreports...
1053 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_CommandLine
);
1054 for(i
=1;i
<argc
;i
++)mp_msg(MSGT_FIXME
, MSGL_FIXME
," '%s'",argv
[i
]);
1055 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n");
1058 mp_msg_set_level(verbose
+MSGL_STATUS
);
1060 //------ load global data first ------
1064 #ifdef HAVE_FREETYPE
1067 #ifdef HAVE_FONTCONFIG
1068 if(!font_fontconfig
)
1072 vo_font
=read_font_desc(font_name
,font_factor
,verbose
>1);
1073 if(!vo_font
) mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadFont
,font_name
);
1076 vo_font
=read_font_desc( mem_ptr
=get_path("font/font.desc"),font_factor
,verbose
>1);
1077 free(mem_ptr
); // release the buffer created by get_path()
1079 vo_font
=read_font_desc(MPLAYER_DATADIR
"/font/font.desc",font_factor
,verbose
>1);
1081 #ifdef HAVE_FONTCONFIG
1090 // seteuid(0); /* Can't hurt to try to get root here */
1091 if ((rtc_fd
= open(rtc_device
? rtc_device
: "/dev/rtc", O_RDONLY
)) < 0)
1092 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_RTCDeviceNotOpenable
,
1093 rtc_device
? rtc_device
: "/dev/rtc", strerror(errno
));
1095 unsigned long irqp
= 1024; /* 512 seemed OK. 128 is jerky. */
1097 if (ioctl(rtc_fd
, RTC_IRQP_SET
, irqp
) < 0) {
1098 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_LinuxRTCInitErrorIrqpSet
, irqp
, strerror(errno
));
1099 mp_msg(MSGT_CPLAYER
, MSGL_HINT
, MSGTR_IncreaseRTCMaxUserFreq
, irqp
);
1102 } else if (ioctl(rtc_fd
, RTC_PIE_ON
, 0) < 0) {
1103 /* variable only by the root */
1104 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCInitErrorPieOn
, strerror(errno
));
1108 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_UsingRTCTiming
, irqp
);
1112 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
1113 // and now ? -- Pontscho
1114 if(use_gui
) setuid( getuid() ); // strongly test, please check this.
1118 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "Using %s timing\n",
1119 softsleep
?"software":timer_name
);
1122 if ( !use_gui
) load_termcap(NULL
); // load key-codes
1125 // ========== Init keyboard FIFO (connection to libvo) ============
1127 // Init input system
1128 current_module
= "init_input";
1130 #ifndef HAVE_NO_POSIX_SELECT
1131 make_pipe(&keyb_fifo_get
,&keyb_fifo_put
);
1133 if(keyb_fifo_get
> 0)
1134 mp_input_add_key_fd(keyb_fifo_get
,1,NULL
,NULL
);
1136 mp_input_add_key_fd(-1,0,mplayer_get_key
,NULL
);
1140 mp_input_add_cmd_fd(0,1,NULL
,NULL
);
1142 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func
,NULL
);
1144 else if(!noconsolecontrols
)
1145 #ifndef HAVE_NO_POSIX_SELECT
1146 mp_input_add_key_fd(0,1,NULL
,NULL
);
1148 mp_input_add_key_fd(0,0,NULL
,NULL
);
1151 inited_flags
|=INITED_INPUT
;
1152 current_module
= NULL
;
1156 if(menu_cfg
&& menu_init(menu_cfg
))
1157 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
1159 menu_cfg
= get_path("menu.conf");
1160 if(menu_init(menu_cfg
))
1161 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, menu_cfg
);
1163 if(menu_init(MPLAYER_CONFDIR
"/menu.conf"))
1164 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitialized
, MPLAYER_CONFDIR
"/menu.conf");
1166 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MenuInitFailed
);
1176 signal(SIGCHLD
,child_sighandler
);
1179 //========= Catch terminate signals: ================
1180 // terminate requests:
1181 signal(SIGTERM
,exit_sighandler
); // kill
1182 signal(SIGHUP
,exit_sighandler
); // kill -HUP / xterm closed
1184 signal(SIGINT
,exit_sighandler
); // Interrupt from keyboard
1186 signal(SIGQUIT
,exit_sighandler
); // Quit from keyboard
1187 #ifdef ENABLE_SIGHANDLER
1189 signal(SIGBUS
,exit_sighandler
); // bus error
1190 signal(SIGSEGV
,exit_sighandler
); // segfault
1191 signal(SIGILL
,exit_sighandler
); // illegal instruction
1192 signal(SIGFPE
,exit_sighandler
); // floating point exc.
1193 signal(SIGABRT
,exit_sighandler
); // abort()
1199 inited_flags
|=INITED_GUI
;
1200 guiGetEvent( guiCEvent
,(char *)((gui_no_filename
) ? 0 : 1) );
1204 // ******************* Now, let's see the per-file stuff ********************
1208 // init global sub numbers
1209 global_sub_size
= 0;
1210 { int i
; for (i
= 0; i
< SUB_SOURCES
; i
++) global_sub_indices
[i
] = -1; }
1211 global_sub_quiet_osd_hack
= 1;
1213 if (filename
) load_per_file_config (mconfig
, filename
);
1215 // We must enable getch2 here to be able to interrupt network connection
1217 if(!noconsolecontrols
&& !slave_mode
){
1218 if(inited_flags
&INITED_GETCH2
)
1219 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_Getch2InitializedTwice
);
1221 getch2_enable(); // prepare stdin for hotkeys...
1222 inited_flags
|=INITED_GETCH2
;
1223 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"\n[[[init getch2]]]\n");
1226 // =================== GUI idle loop (STOP state) ===========================
1229 file_format
=DEMUXER_TYPE_UNKNOWN
;
1230 guiGetEvent( guiSetDefaults
,0 );
1231 while ( guiIntfStruct
.Playing
!= 1 )
1236 guiGetEvent( guiReDraw
,NULL
);
1237 if ( (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
1239 guiGetEvent( guiSetParameters
,NULL
);
1240 if ( guiIntfStruct
.StreamType
== STREAMTYPE_STREAM
)
1242 play_tree_t
* entry
= play_tree_new();
1243 play_tree_add_file( entry
,guiIntfStruct
.Filename
);
1244 if ( playtree
) play_tree_free_list( playtree
->child
,1 );
1245 else playtree
=play_tree_new();
1246 play_tree_set_child( playtree
,entry
);
1249 playtree_iter
= play_tree_iter_new(playtree
,mconfig
);
1252 if(play_tree_iter_step(playtree_iter
,0,0) != PLAY_TREE_ITER_ENTRY
)
1254 play_tree_iter_free(playtree_iter
);
1255 playtree_iter
= NULL
;
1257 filename
= play_tree_iter_get_file(playtree_iter
,1);
1263 //---------------------------------------------------------------------------
1265 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
1266 if(filename
) mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Playing
, filename
);
1268 //==================== Open VOB-Sub ============================
1270 current_module
="vobsub";
1272 vo_vobsub
=vobsub_open(vobsub_name
,spudec_ifo
,1,&vo_spudec
);
1274 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantLoadSub
,vobsub_name
);
1275 }else if(sub_auto
&& filename
&& (strlen(filename
)>=5)){
1276 /* try to autodetect vobsub from movie filename ::atmos */
1277 char *buf
= malloc((strlen(filename
)-3) * sizeof(char));
1278 memset(buf
,0,strlen(filename
)-3); // make sure string is terminated
1279 strncpy(buf
, filename
, strlen(filename
)-4);
1280 vo_vobsub
=vobsub_open(buf
,spudec_ifo
,0,&vo_spudec
);
1284 inited_flags
|=INITED_VOBSUB
;
1285 vobsub_set_from_lang(vo_vobsub
, dvdsub_lang
);
1286 // check if vobsub requested only to display forced subtitles
1287 forced_subs_only
=vobsub_get_forced_subs_flag(vo_vobsub
);
1289 // setup global sub numbering
1290 global_sub_indices
[SUB_SOURCE_VOBSUB
] = global_sub_size
; // the global # of the first vobsub.
1291 global_sub_size
+= vobsub_get_indexes_count(vo_vobsub
);
1294 //============ Open & Sync STREAM --- fork cache2 ====================
1299 //free_demuxer_stream(d_audio);
1303 //free_demuxer_stream(d_video);
1309 current_module
="open_stream";
1310 stream
=open_stream(filename
,0,&file_format
);
1311 if(!stream
) { // error...
1312 eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
);
1313 goto goto_next_file
;
1315 inited_flags
|=INITED_STREAM
;
1318 if ( use_gui
) guiGetEvent( guiSetStream
,(char *)stream
);
1321 if(file_format
== DEMUXER_TYPE_PLAYLIST
) {
1324 current_module
="handle_playlist";
1325 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Parsing playlist %s...\n",filename
);
1326 entry
= parse_playtree(stream
,0);
1327 eof
=playtree_add_playlist(entry
);
1328 goto goto_next_file
;
1330 stream
->start_pos
+=seek_to_byte
;
1332 if(stream_dump_type
==5){
1333 unsigned char buf
[4096];
1336 current_module
="dumpstream";
1337 if(stream
->type
==STREAMTYPE_STREAM
&& stream
->fd
<0){
1338 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpstreamFdUnavailable
);
1339 exit_player(MSGTR_Exit_error
);
1341 stream_reset(stream
);
1342 stream_seek(stream
,stream
->start_pos
);
1343 f
=fopen(stream_dump_name
,"wb");
1345 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1346 exit_player(MSGTR_Exit_error
);
1348 while(!stream
->eof
){
1349 len
=stream_read(stream
,buf
,4096);
1351 if(fwrite(buf
,len
,1,f
) != 1) {
1352 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1353 exit_player(MSGTR_Exit_error
);
1358 mp_msg(MSGT_MENCODER
,MSGL_FATAL
,MSGTR_ErrorWritingFile
,stream_dump_name
);
1359 exit_player(MSGTR_Exit_error
);
1361 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1362 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1366 if(stream
->type
==STREAMTYPE_DVD
){
1367 current_module
="dvd lang->id";
1368 if(audio_id
==-1) audio_id
=dvd_aid_from_lang(stream
,audio_lang
);
1369 if(dvdsub_lang
&& dvdsub_id
==-1) dvdsub_id
=dvd_sid_from_lang(stream
,dvdsub_lang
);
1370 // setup global sub numbering
1371 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
1372 global_sub_size
+= dvd_number_of_subs(stream
);
1373 current_module
=NULL
;
1378 if (stream
->type
==STREAMTYPE_DVDNAV
) stream_cache_size
=0; // must disable caching...
1381 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
1382 #ifdef HAS_DVBIN_SUPPORT
1385 if(stream_cache_size
>0){
1386 current_module
="enable_cache";
1387 if(!stream_enable_cache(stream
,stream_cache_size
*1024,stream_cache_size
*1024*(stream_cache_min_percent
/ 100.0),stream_cache_size
*1024*(stream_cache_prefill_percent
/ 100.0)))
1388 if((eof
= libmpdemux_was_interrupted(PT_NEXT_ENTRY
))) goto goto_next_file
;
1391 //============ Open DEMUXERS --- DETECT file type =======================
1392 current_module
="demux_open";
1394 demuxer
=demux_open(stream
,file_format
,audio_id
,video_id
,dvdsub_id
,filename
);
1396 // HACK to get MOV Reference Files working
1398 if (demuxer
&& demuxer
->type
==DEMUXER_TYPE_PLAYLIST
)
1400 unsigned char* playlist_entry
;
1401 play_tree_t
*list
= NULL
, *entry
= NULL
;
1403 current_module
="handle_demux_playlist";
1404 while (ds_get_packet(demuxer
->video
,&playlist_entry
)>0)
1408 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Adding file %s to element entry.\n",playlist_entry
);
1410 bname
=mp_basename(playlist_entry
);
1411 if ((strlen(bname
)>10) && !strncmp(bname
,"qt",2) && !strncmp(bname
+3,"gateQT",6))
1414 if (!strncmp(bname
,mp_basename(filename
),strlen(bname
))) // ignoring self-reference
1417 entry
= play_tree_new();
1419 if (filename
&& !strcmp(mp_basename(playlist_entry
),playlist_entry
)) // add reference path of current file
1421 temp
=malloc((strlen(filename
)-strlen(mp_basename(filename
))+strlen(playlist_entry
)+1)*sizeof(char));
1424 strncpy(temp
, filename
, strlen(filename
)-strlen(mp_basename(filename
)));
1425 temp
[strlen(filename
)-strlen(mp_basename(filename
))]='\0';
1426 strcat(temp
, playlist_entry
);
1427 play_tree_add_file(entry
,temp
);
1428 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Resolving reference to %s.\n",temp
);
1433 play_tree_add_file(entry
,playlist_entry
);
1438 play_tree_append_entry(list
,entry
);
1440 free_demuxer(demuxer
);
1445 entry
= play_tree_new();
1446 play_tree_set_child(entry
,list
);
1447 eof
=playtree_add_playlist(entry
);
1448 goto goto_next_file
;
1457 current_module
="handle_playlist";
1458 switch(stream
->type
){
1459 case STREAMTYPE_VCD
:
1460 case STREAMTYPE_DVD
:
1461 case STREAMTYPE_DVDNAV
:
1462 case STREAMTYPE_CDDA
:
1463 case STREAMTYPE_VCDBINCUE
:
1464 // don't try to parse raw media as playlist, it's unlikely
1465 goto goto_next_file
;
1467 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FallingBackOnPlaylist
,filename
);
1468 stream_reset(stream
);
1469 stream_seek(stream
,stream
->start_pos
);
1470 entry
= parse_playtree(stream
,0);
1472 mp_msg(MSGT_DEMUXER
,MSGL_ERR
,MSGTR_FormatNotRecognized
);
1474 eof
=playtree_add_playlist(entry
);
1476 goto goto_next_file
;
1478 inited_flags
|=INITED_DEMUXER
;
1480 #ifdef HAVE_MATROSKA
1481 if (demuxer
->type
==DEMUXER_TYPE_MATROSKA
) {
1482 // setup global sub numbering
1483 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
1484 global_sub_size
+= demux_mkv_num_subs(demuxer
);
1487 #ifdef HAVE_OGGVORBIS
1488 if (demuxer
->type
==DEMUXER_TYPE_OGG
) {
1489 // setup global sub numbering
1490 global_sub_indices
[SUB_SOURCE_DEMUX
] = global_sub_size
; // the global # of the first demux-specific sub.
1491 global_sub_size
+= demux_ogg_num_subs(demuxer
);
1495 current_module
="demux_open2";
1497 //file_format=demuxer->file_format;
1499 d_audio
=demuxer
->audio
;
1500 d_video
=demuxer
->video
;
1501 d_dvdsub
=demuxer
->sub
;
1504 if((stream_dump_type
)&&(stream_dump_type
<4)){
1506 demux_stream_t
*ds
=NULL
;
1507 current_module
="dump";
1508 // select stream to dump
1509 switch(stream_dump_type
){
1510 case 1: ds
=d_audio
;break;
1511 case 2: ds
=d_video
;break;
1512 case 3: ds
=d_dvdsub
;break;
1515 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_DumpSelectedStreamMissing
);
1516 exit_player(MSGTR_Exit_error
);
1518 // disable other streams:
1519 if(d_audio
&& d_audio
!=ds
) {ds_free_packs(d_audio
); d_audio
->id
=-2; }
1520 if(d_video
&& d_video
!=ds
) {ds_free_packs(d_video
); d_video
->id
=-2; }
1521 if(d_dvdsub
&& d_dvdsub
!=ds
) {ds_free_packs(d_dvdsub
); d_dvdsub
->id
=-2; }
1523 f
=fopen(stream_dump_name
,"wb");
1525 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_CantOpenDumpfile
);
1526 exit_player(MSGTR_Exit_error
);
1529 unsigned char* start
;
1530 int in_size
=ds_get_packet(ds
,&start
);
1531 if( (demuxer
->file_format
==DEMUXER_TYPE_AVI
|| demuxer
->file_format
==DEMUXER_TYPE_ASF
|| demuxer
->file_format
==DEMUXER_TYPE_MOV
)
1532 && stream_dump_type
==2) fwrite(&in_size
,1,4,f
);
1533 if(in_size
>0) fwrite(start
,in_size
,1,f
);
1536 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_CoreDumped
);
1537 exit_player_with_rc(MSGTR_Exit_eof
, 0);
1540 sh_audio
=d_audio
->sh
;
1541 sh_video
=d_video
->sh
;
1545 current_module
="video_read_properties";
1546 if(!video_read_properties(sh_video
)) {
1547 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotReadVideoProperties
);
1548 sh_video
=d_video
->sh
=NULL
;
1550 mp_msg(MSGT_CPLAYER
,MSGL_V
,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
1551 demuxer
->file_format
,sh_video
->format
, sh_video
->disp_w
,sh_video
->disp_h
,
1552 sh_video
->fps
,sh_video
->frametime
1555 /* need to set fps here for output encoders to pick it up in their init */
1557 sh_video
->fps
=force_fps
;
1558 sh_video
->frametime
=1.0f
/sh_video
->fps
;
1560 vo_fps
= sh_video
->fps
;
1562 vo_mouse_timer_const
=(int)sh_video
->fps
;
1565 if(!sh_video
->fps
&& !force_fps
){
1566 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_FPSnotspecified
);
1567 sh_video
=d_video
->sh
=NULL
;
1575 if(!sh_video
&& !sh_audio
){
1576 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
, MSGTR_NoStreamFound
);
1577 #ifdef HAS_DVBIN_SUPPORT
1578 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
1580 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
1584 int v
= last_dvb_step
;
1586 dir
= DVB_CHANNEL_HIGHER
;
1588 dir
= DVB_CHANNEL_LOWER
;
1590 if(dvb_step_channel(priv
, dir
))
1592 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
1593 cache_uninit(stream
);
1594 goto goto_enable_cache
;
1599 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
1602 /* display clip info */
1603 demux_info_print(demuxer
);
1605 //================== Read SUBTITLES (DVD & TEXT) ==========================
1606 if(vo_spudec
==NULL
&& sh_video
&& (stream
->type
==STREAMTYPE_DVD
|| demuxer
->type
==DEMUXER_TYPE_MATROSKA
)){
1609 unsigned int palette
[16], width
, height
;
1610 current_module
="spudec_init_vobsub";
1611 if (vobsub_parse_ifo(NULL
,spudec_ifo
, palette
, &width
, &height
, 1, -1, NULL
) >= 0)
1612 vo_spudec
=spudec_new_scaled(palette
, width
, height
);
1616 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVDNAV
) {
1617 current_module
="spudec_init_dvdnav";
1618 vo_spudec
=spudec_new_scaled(dvdnav_stream_get_palette((dvdnav_priv_t
*)(stream
->priv
)),
1619 sh_video
->disp_w
, sh_video
->disp_h
);
1624 if (vo_spudec
==NULL
&& stream
->type
==STREAMTYPE_DVD
) {
1625 current_module
="spudec_init_dvdread";
1626 vo_spudec
=spudec_new_scaled(((dvd_priv_t
*)(stream
->priv
))->cur_pgc
->palette
,
1627 sh_video
->disp_w
, sh_video
->disp_h
);
1631 #ifdef HAVE_MATROSKA
1632 if ((vo_spudec
== NULL
) && (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) &&
1633 (d_dvdsub
->sh
!= NULL
) && (((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v')) {
1634 mkv_sh_sub_t
*mkv_sh_sub
= (mkv_sh_sub_t
*)d_dvdsub
->sh
;
1635 current_module
= "spudec_init_matroska";
1637 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
1638 mkv_sh_sub
->custom_colors
, mkv_sh_sub
->width
,
1639 mkv_sh_sub
->height
);
1640 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
1644 if (vo_spudec
==NULL
) {
1645 current_module
="spudec_init_normal";
1646 vo_spudec
=spudec_new_scaled(NULL
, sh_video
->disp_w
, sh_video
->disp_h
);
1647 spudec_set_font_factor(vo_spudec
,font_factor
);
1650 if (vo_spudec
!=NULL
)
1651 inited_flags
|=INITED_SPUDEC
;
1655 // Apply current settings for forced subs
1656 if (vo_spudec
!=NULL
)
1657 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
1661 // after reading video params we should load subtitles because
1662 // we know fps so now we can adjust subtitles time to ~6 seconds AST
1664 current_module
="read_subtitles_file";
1666 for (i
= 0; sub_name
[i
] != NULL
; ++i
)
1667 add_subtitles (sub_name
[i
], sh_video
->fps
, 0);
1669 if(sub_auto
) { // auto load sub file ...
1670 char *psub
= get_path( "sub/" );
1671 char **tmp
= sub_filenames((psub
? psub
: ""), filename
);
1673 free(psub
); // release the buffer created by get_path() above
1675 add_subtitles (*tmp2
++, sh_video
->fps
, 0);
1677 if (set_of_sub_size
== 0)
1679 add_subtitles (mem_ptr
=get_path("default.sub"), sh_video
->fps
, 1);
1680 free(mem_ptr
); // release the buffer created by get_path()
1682 if (set_of_sub_size
> 0)
1683 add_subtitles (NULL
, sh_video
->fps
, 1);
1685 if (set_of_sub_size
> 0) {
1686 // setup global sub numbering
1687 global_sub_indices
[SUB_SOURCE_SUBS
] = global_sub_size
; // the global # of the first sub.
1688 global_sub_size
+= set_of_sub_size
;
1693 if (global_sub_size
) {
1694 // find the best sub to use
1695 if (vobsub_id
>= 0) {
1696 // if user asks for a vobsub id, use that first.
1697 global_sub_pos
= global_sub_indices
[SUB_SOURCE_VOBSUB
] + vobsub_id
;
1698 } else if (dvdsub_id
>= 0 && global_sub_indices
[SUB_SOURCE_DEMUX
] >= 0) {
1699 // if user asks for a dvd sub id, use that next.
1700 global_sub_pos
= global_sub_indices
[SUB_SOURCE_DEMUX
] + dvdsub_id
;
1701 } else if (global_sub_indices
[SUB_SOURCE_SUBS
] >= 0) {
1702 // if there are text subs to use, use those. (autosubs come last here)
1703 global_sub_pos
= global_sub_indices
[SUB_SOURCE_SUBS
];
1705 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
1706 // if nothing else works, get subs from the demuxer.
1707 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
1710 // nothing worth doing automatically.
1711 global_sub_pos
= -1;
1713 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
1715 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
1718 //================== Init AUDIO (codec) ==========================
1720 // Go through the codec.conf and find the best codec...
1721 current_module
="init_audio_codec";
1722 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1723 if(!init_best_audio_codec(sh_audio
,audio_codec_list
,audio_fm_list
)){
1724 sh_audio
=d_audio
->sh
=NULL
; // failed to init :(
1726 inited_flags
|=INITED_ACODEC
;
1727 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1731 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_FILENAME=%s\n", filename
);
1733 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1734 if (sh_video
->format
>= 0x20202020)
1735 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=%.4s\n", &sh_video
->format
);
1737 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FORMAT=0x%08X\n", sh_video
->format
);
1738 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_BITRATE=%d\n", sh_video
->i_bps
*8);
1739 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_WIDTH=%d\n", sh_video
->disp_w
);
1740 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_HEIGHT=%d\n", sh_video
->disp_h
);
1741 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_FPS=%5.3f\n", sh_video
->fps
);
1742 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_VIDEO_ASPECT=%1.4f\n", sh_video
->aspect
);
1745 if (sh_audio
->codec
)
1746 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_CODEC=%s\n", sh_audio
->codec
->name
);
1747 /* Assume FOURCC if all bytes >= 0x20 (' ') */
1748 if (sh_audio
->format
>= 0x20202020)
1749 mp_msg(MSGT_GLOBAL
,MSGL_INFO
, "ID_AUDIO_FORMAT=%.4s\n", &sh_audio
->format
);
1751 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_FORMAT=%d\n", sh_audio
->format
);
1752 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_BITRATE=%d\n", sh_audio
->i_bps
*8);
1753 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_RATE=%d\n", sh_audio
->samplerate
);
1754 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_AUDIO_NCH=%d\n", sh_audio
->channels
);
1756 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,"ID_LENGTH=%ld\n", demuxer_get_time_length(demuxer
));
1759 if(!sh_video
) goto main
; // audio-only
1761 //================== Init VIDEO (codec & libvo) ==========================
1762 if(!fixed_vo
|| !(inited_flags
&INITED_VO
)){
1763 current_module
="preinit_libvo";
1766 //if((video_out->preinit(vo_subdevice))!=0){
1767 if(!(video_out
=init_best_video_out(video_driver_list
))){
1768 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_ErrorInitializingVODevice
);
1769 goto goto_next_file
; // exit_player(MSGTR_Exit_error);
1771 sh_video
->video_out
=video_out
;
1772 inited_flags
|=INITED_VO
;
1775 current_module
="init_video_filters";
1777 char* vf_arg
[] = { "_oldargs_", (char*)video_out
, NULL
};
1778 sh_video
->vfilter
=(void*)vf_open_filter(NULL
,"vo",vf_arg
);
1782 char* vf_arg
[] = { "_oldargs_", menu_root
, NULL
};
1783 vf_menu
= vf_open_plugin(libmenu_vfs
,sh_video
->vfilter
,"menu",vf_arg
);
1785 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CantOpenLibmenuFilterWithThisRootMenu
,menu_root
);
1790 sh_video
->vfilter
=(void*)append_filters(vf_menu
);
1793 sh_video
->vfilter
=(void*)append_filters(sh_video
->vfilter
);
1795 current_module
="init_video_codec";
1797 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1798 init_best_video_codec(sh_video
,video_codec_list
,video_fm_list
);
1799 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"==========================================================================\n");
1801 if(!sh_video
->inited
){
1802 if(!fixed_vo
) uninit_player(INITED_VO
);
1803 if(!sh_audio
) goto goto_next_file
;
1804 sh_video
= d_video
->sh
= NULL
;
1805 goto main
; // exit_player(MSGTR_Exit_error);
1808 inited_flags
|=INITED_VCODEC
;
1811 // Auto quality option enabled
1812 output_quality
=get_video_quality_max(sh_video
);
1813 if(auto_quality
>output_quality
) auto_quality
=output_quality
;
1814 else output_quality
=auto_quality
;
1815 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AutoQ: setting quality to %d.\n",output_quality
);
1816 set_video_quality(sh_video
,output_quality
);
1819 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
1821 current_module
="init_vo";
1823 if(vo_flags
& 0x08 && vo_spudec
)
1824 spudec_set_hw_spu(vo_spudec
,video_out
);
1826 #ifdef HAVE_FREETYPE
1827 force_load_font
= 1;
1830 //================== MAIN: ==========================
1832 current_module
="main";
1834 // If there is no video OSD has to be disabled.
1835 // In case of playing a playtree we have to restore the
1836 // old OSD level after playing one or more audio-only files.
1837 if(!sh_video
&& osd_level
>= 0) { // save OSD level only once
1838 osd_level_saved
= osd_level
;
1840 } else if (osd_level_saved
> -1) { // if there is a saved OSD level, restore it
1841 osd_level
= osd_level_saved
;
1842 osd_level_saved
= -1;
1850 if ( sh_audio
) guiIntfStruct
.AudioType
=sh_audio
->channels
; else guiIntfStruct
.AudioType
=0;
1851 if ( !sh_video
&& sh_audio
) guiGetEvent( guiSetAudioOnly
,(char *)1 ); else guiGetEvent( guiSetAudioOnly
,(char *)0 );
1852 guiGetEvent( guiSetFileFormat
,(char *)demuxer
->file_format
);
1853 if ( guiGetEvent( guiSetValues
,(char *)sh_video
) ) goto goto_next_file
;
1854 guiGetEvent( guiSetDemuxer
,(char *)demuxer
);
1859 //int frame_corr_num=0; //
1860 //float v_frame=0; // Video
1861 float time_frame
=0; // Timer
1862 //float num_frames=0; // number of frames played
1864 char osd_text_buffer
[64];
1865 char osd_show_text_buffer
[64];
1866 int drop_frame
=0; // current dropping status
1867 int dropped_frames
=0; // how many frames dropped since last non-dropped frame
1868 int too_slow_frame_cnt
=0;
1869 int too_fast_frame_cnt
=0;
1870 // for auto-quality:
1871 float AV_delay
=0; // average of A-V timestamp differences
1872 double vdecode_time
;
1873 unsigned int lastframeout_ts
=0;
1874 /*float time_frame_corr_avg=0;*/ /* unused */
1876 float next_frame_time
=0;
1877 int frame_time_remaining
=0; // flag
1880 osd_text_buffer
[0]=0;
1882 //================ SETUP AUDIO ==========================
1885 //const ao_info_t *info=audio_out->info;
1886 current_module
="af_preinit";
1887 ao_data
.samplerate
=force_srate
?force_srate
:sh_audio
->samplerate
*playback_speed
;
1888 ao_data
.channels
=audio_output_channels
?audio_output_channels
:sh_audio
->channels
;
1889 ao_data
.format
=audio_output_format
?audio_output_format
:sh_audio
->sample_format
;
1891 if(!preinit_audio_filters(sh_audio
,
1893 (int)(sh_audio
->samplerate
*playback_speed
),
1894 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)){
1898 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_AudioFilterChainPreinitError
);
1900 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AF_pre: %dHz %dch %s\n",
1901 ao_data
.samplerate
, ao_data
.channels
,
1902 audio_out_format_name(ao_data
.format
));
1905 current_module
="ao2_init";
1906 if(!(audio_out
=init_best_audio_out(audio_driver_list
,
1907 (ao_plugin_cfg
.plugin_list
!=NULL
), // plugin flag
1908 force_srate
?force_srate
:ao_data
.samplerate
,
1909 audio_output_channels
?audio_output_channels
:ao_data
.channels
,
1910 audio_output_format
?audio_output_format
:ao_data
.format
,0))){
1912 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_CannotInitAO
);
1913 uninit_player(INITED_ACODEC
); // close codec
1914 sh_audio
=d_audio
->sh
=NULL
; // -> nosound
1917 inited_flags
|=INITED_AO
;
1918 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"AO: [%s] %dHz %dch %s (%d bps)\n",
1919 audio_out
->info
->short_name
,
1920 ao_data
.samplerate
, ao_data
.channels
,
1921 audio_out_format_name(ao_data
.format
),
1922 audio_out_format_bits(ao_data
.format
)/8 );
1923 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Description: %s\nAO: Author: %s\n",
1924 audio_out
->info
->name
, audio_out
->info
->author
);
1925 if(strlen(audio_out
->info
->comment
) > 0)
1926 mp_msg(MSGT_CPLAYER
,MSGL_V
,"AO: Comment: %s\n", audio_out
->info
->comment
);
1927 // init audio filters:
1929 current_module
="af_init";
1930 if(!init_audio_filters(sh_audio
,
1931 (int)(sh_audio
->samplerate
*playback_speed
),
1932 sh_audio
->channels
, sh_audio
->sample_format
, sh_audio
->samplesize
,
1933 ao_data
.samplerate
, ao_data
.channels
, ao_data
.format
,
1934 audio_out_format_bits(ao_data
.format
)/8, /* ao_data.bps, */
1935 ao_data
.outburst
*4, ao_data
.buffersize
)){
1936 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_NoMatchingFilter
);
1937 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
1938 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
1939 // sh_audio=d_audio->sh=NULL; // -> nosound
1943 mixer
.audio_out
= audio_out
;
1944 mixer
.afilter
= sh_audio
? sh_audio
->afilter
: NULL
;
1945 mixer
.volstep
= volstep
;
1948 current_module
="av_init";
1950 if(sh_video
) sh_video
->timer
=0;
1951 if(sh_audio
) sh_audio
->delay
=-audio_delay
;
1954 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_NoSound
);
1955 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %s unused audio chunks.\n",d_audio
->packs
);
1956 ds_free_packs(d_audio
); // free buffered chunks
1957 d_audio
->id
=-2; // do not read audio chunks
1958 //uninit_player(INITED_AO); // close device
1961 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_Video_NoVideo
);
1962 mp_msg(MSGT_CPLAYER
,MSGL_V
,"Freeing %s unused video chunks.\n",d_video
->packs
);
1963 ds_free_packs(d_video
);
1965 //if(!fixed_vo) uninit_player(INITED_VO);
1968 if (!sh_video
&& !sh_audio
)
1969 goto goto_next_file
;
1971 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
1972 if(force_fps
&& sh_video
){
1973 vo_fps
= sh_video
->fps
=force_fps
;
1974 sh_video
->frametime
=1.0f
/sh_video
->fps
;
1975 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_FPSforced
,sh_video
->fps
,sh_video
->frametime
);
1978 //==================== START PLAYING =======================
1980 if(loop_times
>1) loop_times
--; else
1981 if(loop_times
==1) loop_times
= -1;
1983 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_StartPlaying
);fflush(stdout
);
1988 if (stream
->type
==STREAMTYPE_DVDNAV
) {
1989 dvdnav_stream_fullstart((dvdnav_priv_t
*)stream
->priv
);
1993 total_time_usage_start
=GetTimer();
1994 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
1995 total_frame_cnt
=0; drop_frame_cnt
=0; // fix for multifile fps benchmark
1996 play_n_frames
=play_n_frames_mf
;
1998 if(play_n_frames
==0){
1999 eof
=PT_NEXT_ENTRY
; goto goto_next_file
;
2003 float aq_sleep_time
=0;
2005 if(play_n_frames
>=0){
2007 if(play_n_frames
<0) eof
= PT_NEXT_ENTRY
;
2010 /*========================== PLAY AUDIO ============================*/
2017 current_module
="play_audio";
2019 ao_data
.pts
=((sh_video
?sh_video
->timer
:0)+sh_audio
->delay
)*90000.0;
2020 playsize
=audio_out
->get_space();
2022 // handle audio-only case:
2023 if(!playsize
&& !sh_video
) { // buffer is full, do not block here!!!
2024 usec_sleep(10000); // Wait a tick before retry
2028 if(playsize
>MAX_OUTBURST
) playsize
=MAX_OUTBURST
; // we shouldn't exceed it!
2030 // Fill buffer if needed:
2031 current_module
="decode_audio"; // Enter AUDIO decoder module
2033 while(sh_audio
->a_out_buffer_len
<playsize
&& !d_audio
->eof
){
2034 int ret
=decode_audio(sh_audio
,&sh_audio
->a_out_buffer
[sh_audio
->a_out_buffer_len
],
2035 playsize
-sh_audio
->a_out_buffer_len
,sh_audio
->a_out_buffer_size
-sh_audio
->a_out_buffer_len
);
2036 if(ret
<=0) break; // EOF?
2037 sh_audio
->a_out_buffer_len
+=ret
;
2040 tt
= t
*0.000001f
; audio_time_usage
+=tt
;
2041 if(playsize
>sh_audio
->a_out_buffer_len
) playsize
=sh_audio
->a_out_buffer_len
;
2044 current_module
="play_audio";
2045 playsize
=audio_out
->play(sh_audio
->a_out_buffer
,playsize
,0);
2048 sh_audio
->a_out_buffer_len
-=playsize
;
2049 memmove(sh_audio
->a_out_buffer
,&sh_audio
->a_out_buffer
[playsize
],sh_audio
->a_out_buffer_len
);
2050 sh_audio
->delay
+=playback_speed
*playsize
/((float)((ao_data
.bps
&& sh_audio
->afilter
) ?
2051 ao_data
.bps
: sh_audio
->o_bps
));
2055 } // while(sh_audio)
2058 // handle audio-only case:
2061 // convert time to HH:MM:SS.F format
2063 long tenths
= 10 * (sh_audio
->delay
-audio_out
->get_delay()*playback_speed
);
2064 int hh
= (tenths
/ 36000) % 100;
2065 int mm
= (tenths
/ 600) % 60;
2066 int ss
= (tenths
/ 10) % 60;
2067 int f1
= tenths
% 10;
2068 char hhmmssf
[16]; // only really need 11, but just in case...
2069 sprintf( hhmmssf
, "%2d:%2d:%2d.%1d", hh
, mm
, ss
, f1
);
2074 // uncomment the next three lines to show leading zero ten-hours
2075 // else if (' ' == hhmmssf[0]) {
2076 // hhmmssf[0] = '0';
2078 if ((0 == hh
) && (0 == mm
)) {
2082 else if ((' ' == hhmmssf
[3]) && (' ' != hhmmssf
[2])) {
2085 if ((' ' == hhmmssf
[6]) && (' ' != hhmmssf
[5])) {
2088 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A: %s %4.1f%% %d%% \r"
2090 ,(sh_audio
->delay
>0.5)?100.0*audio_time_usage
/(double)sh_audio
->delay
:0
2094 if(d_audio
->eof
) eof
= PT_NEXT_ENTRY
;
2098 /*========================== PLAY VIDEO ============================*/
2100 float frame_time
=next_frame_time
;
2102 vo_pts
=sh_video
->timer
*90000.0;
2103 vo_fps
=sh_video
->fps
;
2105 if(!frame_time_remaining
){
2106 //-------------------- Decode a frame: -----------------------
2107 vdecode_time
=video_time_usage
;
2109 { unsigned char* start
=NULL
;
2112 current_module
="video_read_frame";
2113 in_size
=video_read_frame(sh_video
,&next_frame_time
,&start
,force_fps
);
2114 if(in_size
<0){ eof
=1; break; }
2115 if(in_size
>max_framesize
) max_framesize
=in_size
; // stats
2116 sh_video
->timer
+=frame_time
;
2117 if(sh_audio
) sh_audio
->delay
-=frame_time
;
2118 time_frame
+=frame_time
; // for nosound
2119 // check for frame-drop:
2120 current_module
="check_framedrop";
2121 if(sh_audio
&& !d_audio
->eof
){
2122 float delay
=playback_speed
*audio_out
->get_delay();
2123 float d
=delay
-sh_audio
->delay
;
2124 // we should avoid dropping to many frames in sequence unless we
2125 // are too late. and we allow 100ms A-V delay here:
2126 if(d
<-dropped_frames
*frame_time
-0.100 && osd_function
!= OSD_PAUSE
){
2127 drop_frame
=frame_dropping
;
2131 drop_frame
=dropped_frames
=0;
2136 current_module
="decode_video";
2137 // printf("Decode! %p %d \n",start,in_size);
2138 blit_frame
=decode_video(sh_video
,start
,in_size
,drop_frame
);
2141 vdecode_time
=video_time_usage
-vdecode_time
;
2142 //------------------------ frame decoded. --------------------
2144 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"*** ftime=%5.3f ***\n",frame_time
);
2146 if(sh_video
->vf_inited
<0){
2147 mp_msg(MSGT_CPLAYER
,MSGL_FATAL
,MSGTR_NotInitializeVOPorVO
);
2148 eof
=1; goto goto_next_file
;
2153 // ==========================================================================
2155 // current_module="draw_osd";
2156 // if(vo_config_count) video_out->draw_osd();
2159 if(use_gui
) guiEventHandling();
2162 current_module
="calc_sleep_time";
2165 { // debug frame dropping code
2166 float delay
=audio_out
->get_delay();
2167 mp_msg(MSGT_AVSYNC
,MSGL_V
,"\r[V] %5.3f [A] %5.3f => {%5.3f} (%5.3f) [%d] \n",
2168 sh_video
->timer
,sh_audio
->timer
-delay
,
2169 sh_video
->timer
-(sh_audio
->timer
-delay
),
2174 if(drop_frame
&& !frame_time_remaining
&& !autosync
){
2176 * Note: time_frame should not be forced to 0 in autosync mode.
2177 * It is used as a cumulative counter to predict and correct the
2178 * delay measurements from the audio driver. time_frame is already
2179 * < 0, so the "time to sleep" code does not actually sleep. Also,
2180 * blit_frame is already 0 because drop_frame was true when
2181 * decode_video was called (which causes it to set blit_frame to 0.)
2182 * When autosync==0, the default behavior is still completely unchanged.
2185 time_frame
=0; // don't sleep!
2186 blit_frame
=0; // don't display!
2190 // It's time to sleep...
2192 frame_time_remaining
=0;
2193 time_frame
-=GetRelativeTime(); // reset timer
2195 if(sh_audio
&& !d_audio
->eof
){
2196 float delay
=playback_speed
*audio_out
->get_delay();
2197 mp_dbg(MSGT_AVSYNC
,MSGL_DBG2
,"delay=%f\n",delay
);
2201 * Adjust this raw delay value by calculating the expected
2202 * delay for this frame and generating a new value which is
2203 * weighted between the two. The higher autosync is, the
2204 * closer to the delay value gets to that which "-nosound"
2205 * would have used, and the longer it will take for A/V
2206 * sync to settle at the right value (but it eventually will.)
2207 * This settling time is very short for values below 100.
2209 float predicted
= sh_audio
->delay
+time_frame
;
2210 float difference
= delay
- predicted
;
2211 delay
= predicted
+ difference
/ (float)autosync
;
2214 time_frame
=delay
-sh_audio
->delay
;
2216 // delay = amount of audio buffered in soundcard/driver
2217 if(delay
>0.25) delay
=0.25; else
2218 if(delay
<0.10) delay
=0.10;
2219 if(time_frame
>delay
*0.6){
2220 // sleep time too big - may cause audio drops (buffer underrun)
2221 frame_time_remaining
=1;
2222 time_frame
=delay
*0.5;
2228 if( (time_frame
<-3*frame_time
|| time_frame
>3*frame_time
) || benchmark
)
2233 // if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,sh_audio->timer,sh_video->timer);
2235 aq_sleep_time
+=time_frame
;
2239 //============================== SLEEP: ===================================
2241 time_frame
/=playback_speed
;
2243 // flag 256 means: libvo driver does its timing (dvb card)
2244 if(time_frame
>0.001 && !(vo_flags
&256)){
2248 // -------- RTC -----------
2249 current_module
="sleep_rtc";
2250 while (time_frame
> 0.000) {
2251 unsigned long rtc_ts
;
2252 if (read (rtc_fd
, &rtc_ts
, sizeof(rtc_ts
)) <= 0)
2253 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, MSGTR_LinuxRTCReadError
, strerror(errno
));
2254 time_frame
-=GetRelativeTime();
2259 // -------- TIMER + SOFTSLEEP -----------
2260 float min
=softsleep
?0.021:0.005;
2261 current_module
="sleep_timer";
2262 while(time_frame
>min
){
2263 if(time_frame
<=0.020)
2264 usec_sleep(0); // sleeps 1 clock tick (10ms)!
2266 usec_sleep(1000000*(time_frame
-0.020));
2267 time_frame
-=GetRelativeTime();
2270 current_module
="sleep_soft";
2271 if(time_frame
<0) mp_msg(MSGT_AVSYNC
, MSGL_WARN
, MSGTR_SoftsleepUnderflow
);
2272 while(time_frame
>0) time_frame
-=GetRelativeTime(); // burn the CPU
2278 //if(!frame_time_remaining){ // should we display the frame now?
2280 //====================== FLIP PAGE (VIDEO BLT): =========================
2282 current_module
="vo_check_events";
2283 if(vo_config_count
) video_out
->check_events();
2285 current_module
="flip_page";
2286 if (!frame_time_remaining
) {
2288 unsigned int t2
=GetTimer();
2291 #define FRAME_LAG_WARN 0.2
2292 j
= ((float)t2
- lastframeout_ts
) / 1000000;
2293 lastframeout_ts
= GetTimer();
2294 if (j
< frame_time
+ frame_time
* -FRAME_LAG_WARN
)
2295 too_fast_frame_cnt
++;
2296 /* printf ("PANIC: too fast frame (%.3f)!\n", j); */
2297 else if (j
> frame_time
+ frame_time
* FRAME_LAG_WARN
)
2298 too_slow_frame_cnt
++;
2299 /* printf ("PANIC: too slow frame (%.3f)!\n", j); */
2301 if(vo_config_count
) video_out
->flip_page();
2302 // usec_sleep(50000); // test only!
2305 vout_time_usage
+=tt
;
2308 Well, no blitting is needed, but some devices (such as yuv4mpeg) must output frame
2309 otherwise A/V desync will occur. -- Alvieboy
2311 if (vo_config_count
)
2312 video_out
->control(VOCTRL_DUPLICATE_FRAME
, NULL
);
2315 //====================== A-V TIMESTAMP CORRECTION: =========================
2317 current_module
="av_sync";
2323 // unplayed bytes in our and soundcard/dma buffer:
2324 float delay
=playback_speed
*audio_out
->get_delay()+(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2328 * If autosync is enabled, the value for delay must be calculated
2329 * a bit differently. It is set only to the difference between
2330 * the audio and video timers. Any attempt to include the real
2331 * or corrected delay causes the pts_correction code below to
2332 * try to correct for the changes in delay which autosync is
2333 * trying to measure. This keeps the two from competing, but still
2334 * allows the code to correct for PTS drift *only*. (Using a delay
2335 * value here, even a "corrected" one, would be incompatible with
2338 delay
=sh_audio
->delay
;
2339 delay
+=(float)sh_audio
->a_buffer_len
/(float)sh_audio
->o_bps
;
2344 // PTS = sample_no / samplerate
2345 unsigned int samples
=
2346 // (sh_audio->audio.dwSampleSize)?
2347 // ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
2348 ds_tell_block(d_audio
); // <- used for VBR audio
2349 samples
+=sh_audio
->audio
.dwStart
; // offset
2350 a_pts
=samples
*(float)sh_audio
->audio
.dwScale
/(float)sh_audio
->audio
.dwRate
;
2352 a_pts
-=(sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2356 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
2358 if(!delay_corrected
) if(a_pts
) delay_corrected
=1;
2360 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
2362 ds_tell_pts(d_audio
)/(float)sh_audio
->i_bps
,
2363 -sh_audio
->a_in_buffer_len
/(float)sh_audio
->i_bps
,
2364 a_pts
+(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
);
2366 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
2368 v_pts
=sh_video
? sh_video
->pts
: d_video
->pts
;
2370 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
);
2372 if(delay_corrected
){
2373 static int drop_message
=0;
2375 AV_delay
=(a_pts
-delay
-audio_delay
)-v_pts
;
2376 if(AV_delay
>0.5 && drop_frame_cnt
>50 && drop_message
==0){
2378 mp_msg(MSGT_AVSYNC
,MSGL_WARN
,MSGTR_SystemTooSlow
);
2381 if(x
<-max_pts_correction
) x
=-max_pts_correction
; else
2382 if(x
> max_pts_correction
) x
= max_pts_correction
;
2383 if(default_max_pts_correction
>=0)
2384 max_pts_correction
=default_max_pts_correction
;
2386 max_pts_correction
=sh_video
->frametime
*0.10; // +-10% of time
2387 if(!frame_time_remaining
){ sh_audio
->delay
+=x
; c_total
+=x
;} // correction
2388 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",
2389 a_pts
-audio_delay
-delay
,v_pts
,AV_delay
,c_total
,
2390 (int)sh_video
->num_frames
,(int)sh_video
->num_frames_decoded
,
2391 (sh_video
->timer
>0.5)?(int)(100.0*video_time_usage
*playback_speed
/(double)sh_video
->timer
):0,
2392 (sh_video
->timer
>0.5)?(int)(100.0*vout_time_usage
*playback_speed
/(double)sh_video
->timer
):0,
2393 (sh_video
->timer
>0.5)?(100.0*audio_time_usage
*playback_speed
/(double)sh_video
->timer
):0
2405 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video
->pts
,
2406 (int)sh_video
->num_frames
,
2407 (sh_video
->timer
>0.5)?(int)(100.0*video_time_usage
/(double)sh_video
->timer
):0,
2408 (sh_video
->timer
>0.5)?(int)(100.0*vout_time_usage
/(double)sh_video
->timer
):0,
2409 (sh_video
->timer
>0.5)?(100.0*audio_time_usage
/(double)sh_video
->timer
):0
2419 //============================ Auto QUALITY ============================
2421 /*Output quality adjustments:*/
2423 current_module
="autoq";
2424 // float total=0.000001f * (GetTimer()-aq_total_time);
2425 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
2426 if(output_quality
<auto_quality
&& aq_sleep_time
>0)
2429 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
2430 if(output_quality
>1 && aq_sleep_time
<0)
2433 if(output_quality
>0 && aq_sleep_time
<-0.050f
) // 50ms
2435 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
2436 set_video_quality(sh_video
,output_quality
);
2439 } // end if(sh_video)
2441 //============================ Handle PAUSE ===============================
2443 current_module
="pause";
2447 if (!--osd_visible
){
2448 vo_osd_progbar_type
=-1; // disable
2449 vo_osd_changed(OSDTYPE_PROGBAR
);
2450 if (osd_function
!= OSD_PAUSE
)
2451 osd_function
= OSD_PLAY
;
2456 if(osd_function
==OSD_PAUSE
){
2459 mp_msg(MSGT_CPLAYER
,MSGL_STATUS
,MSGTR_Paused
);
2463 if(use_gui
) guiGetEvent( guiCEvent
,(char *)guiSetPause
);
2465 if (video_out
&& sh_video
&& vo_config_count
)
2466 video_out
->control(VOCTRL_PAUSE
, NULL
);
2468 if (audio_out
&& sh_audio
)
2469 audio_out
->pause(); // pause audio, keep data if possible
2471 while( (cmd
= mp_input_get_cmd(20,1,1)) == NULL
) {
2472 if(sh_video
&& video_out
&& vo_config_count
) video_out
->check_events();
2476 guiGetEvent( guiReDraw
,NULL
);
2477 if(guiIntfStruct
.Playing
!=2 || (rel_seek_secs
|| abs_seek_pos
)) break;
2482 vf_menu_pause_update(vf_menu
);
2486 if (cmd
->id
== MP_CMD_PAUSE
) {
2487 cmd
= mp_input_get_cmd(0,1,0);
2490 osd_function
=OSD_PLAY
;
2491 if (audio_out
&& sh_audio
)
2492 audio_out
->resume(); // resume audio
2493 if (video_out
&& sh_video
&& vo_config_count
)
2494 video_out
->control(VOCTRL_RESUME
, NULL
); // resume video
2495 (void)GetRelativeTime(); // keep TF around FT in next cycle
2499 if ( guiIntfStruct
.Playing
== guiSetStop
) goto goto_next_file
;
2500 guiGetEvent( guiCEvent
,(char *)guiSetPlay
);
2507 osd_function
=OSD_FFW
;
2508 rel_seek_secs
+=step_sec
;
2512 if (stream
->type
==STREAMTYPE_DVDNAV
&& dvd_nav_still
)
2513 dvdnav_stream_sleeping((dvdnav_priv_t
*)stream
->priv
);
2516 //================= EDL =========================================
2519 if( next_edl_record
) { // Are we (still?) doing EDL?
2521 mp_msg( MSGT_CPLAYER
, MSGL_ERR
, MSGTR_EdlNOsh_video
);
2522 next_edl_record
->next
= NULL
;
2524 if( sh_video
->pts
>= next_edl_record
->start_sec
) {
2525 if( next_edl_record
->action
== EDL_SKIP
) {
2526 osd_function
= OSD_FFW
;
2528 rel_seek_secs
= next_edl_record
->length_sec
;
2530 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_EDLSKIPStartStopLength
, next_edl_record
->start_sec
, next_edl_record
->stop_sec
, next_edl_record
->length_sec
);
2533 } else if( next_edl_record
->action
== EDL_MUTE
) {
2535 edl_mute_count
++; // new EDL seek behavior needs this
2537 mp_msg(MSGT_FIXME
, MSGL_FIXME
, "\nEDL_MUTE: [%f]\n", next_edl_record
->start_sec
);
2541 next_edl_record
=next_edl_record
->next
;
2547 //================= Keyboard events, SEEKing ====================
2549 current_module
="key_events";
2554 while( !brk_cmd
&& (cmd
= mp_input_get_cmd(0,0,0)) != NULL
) {
2556 case MP_CMD_SEEK
: {
2558 osd_show_percentage
= 25;
2559 v
= cmd
->args
[0].v
.i
;
2560 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2561 if(abs
==2) { /* Absolute seek to a specific timestamp in seconds */
2564 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2567 else if(abs
) { /* Absolute seek by percentage */
2570 osd_function
= (v
> sh_video
->timer
) ? OSD_FFW
: OSD_REW
;
2571 rel_seek_secs
= v
/100.0;
2575 osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
2580 case MP_CMD_EDL_MARK
:
2582 float v
= sh_video
->pts
;
2583 fprintf( edl_fd
, "%f %f %d\n", v
-2, v
, 0 );
2587 case MP_CMD_SWITCH_RATIO
: {
2588 if (cmd
->nargs
== 0)
2589 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
2591 movie_aspect
= cmd
->args
[0].v
.f
;
2592 mpcodecs_config_vo (sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
2594 case MP_CMD_AUDIO_DELAY
: {
2595 float v
= cmd
->args
[0].v
.f
;
2597 osd_show_av_delay
= 9;
2598 if(sh_audio
) sh_audio
->delay
+= v
;
2600 case MP_CMD_PAUSE
: {
2601 osd_function
=OSD_PAUSE
;
2604 case MP_CMD_QUIT
: {
2605 exit_player_with_rc(MSGTR_Exit_quit
, (cmd
->nargs
> 0)? cmd
->args
[0].v
.i
: 0);
2607 case MP_CMD_GRAB_FRAMES
: {
2610 case MP_CMD_PLAY_TREE_STEP
: {
2611 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
2612 int force
= cmd
->args
[1].v
.i
;
2621 for (i
=0;i
<-1*n
;i
++)
2626 if(!force
&& playtree_iter
) {
2627 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2629 if(play_tree_iter_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2630 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2631 play_tree_iter_free(i
);
2633 eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2639 case MP_CMD_PLAY_TREE_UP_STEP
: {
2640 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
2641 int force
= cmd
->args
[1].v
.i
;
2643 if(!force
&& playtree_iter
) {
2644 play_tree_iter_t
* i
= play_tree_iter_new_copy(playtree_iter
);
2645 if(play_tree_iter_up_step(i
,n
,0) == PLAY_TREE_ITER_ENTRY
)
2646 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2647 play_tree_iter_free(i
);
2649 eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2652 case MP_CMD_PLAY_ALT_SRC_STEP
: {
2653 if(playtree_iter
&& playtree_iter
->num_files
> 1) {
2654 int v
= cmd
->args
[0].v
.i
;
2655 if(v
> 0 && playtree_iter
->file
< playtree_iter
->num_files
)
2657 else if(v
< 0 && playtree_iter
->file
> 1)
2662 case MP_CMD_SUB_DELAY
: {
2665 int abs
= cmd
->args
[1].v
.i
;
2666 float v
= cmd
->args
[0].v
.f
;
2671 osd_show_sub_delay
= 9; // show the subdelay in OSD
2675 case MP_CMD_SUB_STEP
: {
2678 int movement
= cmd
->args
[0].v
.i
;
2679 step_sub(subdata
, sh_video
->pts
, movement
);
2680 osd_show_sub_delay
= 9; // show the subdelay in OSD
2687 int v
= cmd
->args
[0].v
.i
;
2689 osd_level
=(osd_level
+1)%(MAX_OSD_LEVEL
+1);
2691 osd_level
= v
> MAX_OSD_LEVEL
? MAX_OSD_LEVEL
: v
;
2695 case MP_CMD_OSD_SHOW_TEXT
: {
2697 if(osd_level
&& sh_video
){
2698 osd_show_text
=sh_video
->fps
; // 1 sec
2699 strncpy(osd_show_text_buffer
, cmd
->args
[0].v
.s
, 64);
2703 case MP_CMD_VOLUME
: {
2704 int v
= cmd
->args
[0].v
.i
;
2706 // start change for absolute volume value
2707 int abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2711 mixer_setvolume(&mixer
, (float)v
, (float)v
);
2714 mixer_incvolume(&mixer
);
2716 mixer_decvolume(&mixer
);
2720 if(osd_level
&& sh_video
){
2722 osd_visible
=sh_video
->fps
; // 1 sec
2723 vo_osd_progbar_type
=OSD_VOLUME
;
2724 mixer_getbothvolume(&mixer
, &vol
);
2725 vo_osd_progbar_value
=(vol
*256.0)/100.0;
2726 vo_osd_changed(OSDTYPE_PROGBAR
);
2733 case MP_CMD_LOADFILE
: {
2734 play_tree_t
* e
= play_tree_new();
2735 play_tree_add_file(e
,cmd
->args
[0].v
.s
);
2737 // Go back to the start point
2738 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
2740 play_tree_free_list(playtree
->child
,1);
2741 play_tree_set_child(playtree
,e
);
2742 play_tree_iter_step(playtree_iter
,0,0);
2746 case MP_CMD_LOADLIST
: {
2747 play_tree_t
* e
= parse_playlist_file(cmd
->args
[0].v
.s
);
2749 mp_msg(MSGT_CPLAYER
,MSGL_ERR
,MSGTR_PlaylistLoadUnable
,cmd
->args
[0].v
.s
);
2751 // Go back to the start point
2752 while(play_tree_iter_up_step(playtree_iter
,0,1) != PLAY_TREE_ITER_END
)
2754 play_tree_free_list(playtree
->child
,1);
2755 play_tree_set_child(playtree
,e
);
2756 play_tree_iter_step(playtree_iter
,0,0);
2761 case MP_CMD_GAMMA
: {
2762 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2767 if (vo_gamma_gamma
== 1000)
2770 get_video_colors (sh_video
, "gamma", &vo_gamma_gamma
);
2776 vo_gamma_gamma
+= v
;
2778 if (vo_gamma_gamma
> 100)
2779 vo_gamma_gamma
= 100;
2780 else if (vo_gamma_gamma
< -100)
2781 vo_gamma_gamma
= -100;
2782 set_video_colors(sh_video
, "gamma", vo_gamma_gamma
);
2785 osd_visible
=sh_video
->fps
; // 1 sec
2786 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
2787 vo_osd_progbar_value
=(vo_gamma_gamma
<<7)/100 + 128;
2788 vo_osd_changed(OSDTYPE_PROGBAR
);
2792 case MP_CMD_BRIGHTNESS
: {
2793 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2798 if (vo_gamma_brightness
== 1000)
2800 vo_gamma_brightness
= 0;
2801 get_video_colors(sh_video
, "brightness", &vo_gamma_brightness
);
2805 vo_gamma_brightness
= v
;
2807 vo_gamma_brightness
+= v
;
2809 if (vo_gamma_brightness
> 100)
2810 vo_gamma_brightness
= 100;
2811 else if (vo_gamma_brightness
< -100)
2812 vo_gamma_brightness
= -100;
2813 if(set_video_colors(sh_video
, "brightness", vo_gamma_brightness
)){
2816 osd_visible
=sh_video
->fps
; // 1 sec
2817 vo_osd_progbar_type
=OSD_BRIGHTNESS
;
2818 vo_osd_progbar_value
=(vo_gamma_brightness
<<7)/100 + 128;
2819 vo_osd_changed(OSDTYPE_PROGBAR
);
2824 case MP_CMD_CONTRAST
: {
2825 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2830 if (vo_gamma_contrast
== 1000)
2832 vo_gamma_contrast
= 0;
2833 get_video_colors(sh_video
, "contrast", &vo_gamma_contrast
);
2837 vo_gamma_contrast
= v
;
2839 vo_gamma_contrast
+= v
;
2841 if (vo_gamma_contrast
> 100)
2842 vo_gamma_contrast
= 100;
2843 else if (vo_gamma_contrast
< -100)
2844 vo_gamma_contrast
= -100;
2845 if(set_video_colors(sh_video
, "contrast", vo_gamma_contrast
)){
2848 osd_visible
=sh_video
->fps
; // 1 sec
2849 vo_osd_progbar_type
=OSD_CONTRAST
;
2850 vo_osd_progbar_value
=(vo_gamma_contrast
<<7)/100 + 128;
2851 vo_osd_changed(OSDTYPE_PROGBAR
);
2856 case MP_CMD_SATURATION
: {
2857 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2862 if (vo_gamma_saturation
== 1000)
2864 vo_gamma_saturation
= 0;
2865 get_video_colors(sh_video
, "saturation", &vo_gamma_saturation
);
2869 vo_gamma_saturation
= v
;
2871 vo_gamma_saturation
+= v
;
2873 if (vo_gamma_saturation
> 100)
2874 vo_gamma_saturation
= 100;
2875 else if (vo_gamma_saturation
< -100)
2876 vo_gamma_saturation
= -100;
2877 if(set_video_colors(sh_video
, "saturation", vo_gamma_saturation
)){
2880 osd_visible
=sh_video
->fps
; // 1 sec
2881 vo_osd_progbar_type
=OSD_SATURATION
;
2882 vo_osd_progbar_value
=(vo_gamma_saturation
<<7)/100 + 128;
2883 vo_osd_changed(OSDTYPE_PROGBAR
);
2889 int v
= cmd
->args
[0].v
.i
, abs
= cmd
->args
[1].v
.i
;
2894 if (vo_gamma_hue
== 1000)
2897 get_video_colors(sh_video
, "hue", &vo_gamma_hue
);
2905 if (vo_gamma_hue
> 100)
2907 else if (vo_gamma_hue
< -100)
2908 vo_gamma_hue
= -100;
2909 if(set_video_colors(sh_video
, "hue", vo_gamma_hue
)){
2912 osd_visible
=sh_video
->fps
; // 1 sec
2913 vo_osd_progbar_type
=OSD_HUE
;
2914 vo_osd_progbar_value
=(vo_gamma_hue
<<7)/100 + 128;
2915 vo_osd_changed(OSDTYPE_PROGBAR
);
2920 case MP_CMD_FRAMEDROPPING
: {
2921 int v
= cmd
->args
[0].v
.i
;
2923 frame_dropping
= (frame_dropping
+1)%3;
2925 osd_show_framedropping
=10;
2926 vo_osd_changed(OSDTYPE_SUBTITLE
);
2930 frame_dropping
= v
> 2 ? 2 : v
;
2933 case MP_CMD_TV_SET_FREQ
: {
2934 if (file_format
== DEMUXER_TYPE_TV
)
2935 tv_set_freq((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.f
* 16.0);
2937 case MP_CMD_TV_SET_NORM
: {
2938 if (file_format
== DEMUXER_TYPE_TV
)
2939 tv_set_norm((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
2941 case MP_CMD_TV_SET_BRIGHTNESS
: {
2942 if (file_format
== DEMUXER_TYPE_TV
)
2943 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_BRIGHTNESS
, cmd
->args
[0].v
.i
);
2945 case MP_CMD_TV_SET_HUE
: {
2946 if (file_format
== DEMUXER_TYPE_TV
)
2947 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_HUE
, cmd
->args
[0].v
.i
);
2949 case MP_CMD_TV_SET_SATURATION
: {
2950 if (file_format
== DEMUXER_TYPE_TV
)
2951 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_SATURATION
, cmd
->args
[0].v
.i
);
2953 case MP_CMD_TV_SET_CONTRAST
: {
2954 if (file_format
== DEMUXER_TYPE_TV
)
2955 tv_set_color_options((tvi_handle_t
*)(demuxer
->priv
), TV_COLOR_CONTRAST
, cmd
->args
[0].v
.i
);
2957 case MP_CMD_TV_STEP_CHANNEL
: {
2958 if (file_format
== DEMUXER_TYPE_TV
) {
2959 int v
= cmd
->args
[0].v
.i
;
2961 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_HIGHER
);
2963 if (tv_channel_list
) {
2964 osd_show_tv_channel
= sh_video
->fps
;
2965 vo_osd_changed(OSDTYPE_SUBTITLE
);
2969 tv_step_channel((tvi_handle_t
*)(demuxer
->priv
), TV_CHANNEL_LOWER
);
2971 if (tv_channel_list
) {
2972 osd_show_tv_channel
= sh_video
->fps
;
2973 vo_osd_changed(OSDTYPE_SUBTITLE
);
2979 #ifdef HAS_DVBIN_SUPPORT
2980 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
2982 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
2986 int v
= cmd
->args
[0].v
.i
;
2990 dir
= DVB_CHANNEL_HIGHER
;
2992 dir
= DVB_CHANNEL_LOWER
;
2995 if(dvb_step_channel(priv
, dir
))
2997 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
2998 cache_uninit(stream
);
2999 goto goto_enable_cache
;
3005 case MP_CMD_TV_SET_CHANNEL
: {
3006 if (file_format
== DEMUXER_TYPE_TV
) {
3007 tv_set_channel((tvi_handle_t
*)(demuxer
->priv
), cmd
->args
[0].v
.s
);
3009 if (tv_channel_list
) {
3010 osd_show_tv_channel
= sh_video
->fps
;
3011 vo_osd_changed(OSDTYPE_SUBTITLE
);
3016 #ifdef HAS_DVBIN_SUPPORT
3017 case MP_CMD_DVB_SET_CHANNEL
:
3019 if((stream
->type
== STREAMTYPE_DVB
) && stream
->priv
)
3021 dvb_priv_t
*priv
= (dvb_priv_t
*) stream
->priv
;
3024 if(priv
->list
->current
<= cmd
->args
[0].v
.i
)
3029 if(dvb_set_channel(priv
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
3031 uninit_player(INITED_ALL
-(INITED_STREAM
|INITED_INPUT
));
3032 cache_uninit(stream
);
3033 goto goto_enable_cache
;
3039 case MP_CMD_TV_LAST_CHANNEL
: {
3040 if (file_format
== DEMUXER_TYPE_TV
) {
3041 tv_last_channel((tvi_handle_t
*)(demuxer
->priv
));
3043 if (tv_channel_list
) {
3044 osd_show_tv_channel
= sh_video
->fps
;
3045 vo_osd_changed(OSDTYPE_SUBTITLE
);
3050 case MP_CMD_TV_STEP_NORM
: {
3051 if (file_format
== DEMUXER_TYPE_TV
)
3052 tv_step_norm((tvi_handle_t
*)(demuxer
->priv
));
3054 case MP_CMD_TV_STEP_CHANNEL_LIST
: {
3055 if (file_format
== DEMUXER_TYPE_TV
)
3056 tv_step_chanlist((tvi_handle_t
*)(demuxer
->priv
));
3059 case MP_CMD_SWITCH_VSYNC
: {
3060 vo_vsync
= ( cmd
->nargs
> 0 )? cmd
->args
[0].v
.i
: !vo_vsync
;
3062 case MP_CMD_VO_FULLSCREEN
:
3065 if ( use_gui
) guiGetEvent( guiIEvent
,(char *)MP_CMD_GUI_FULLSCREEN
);
3068 if(video_out
&& vo_config_count
) video_out
->control(VOCTRL_FULLSCREEN
, 0);
3070 case MP_CMD_VO_ONTOP
:
3072 if(video_out
&& vo_config_count
) {
3073 video_out
->control(VOCTRL_ONTOP
, 0);
3076 vo_osd_changed(OSDTYPE_SUBTITLE
);
3081 case MP_CMD_VO_ROOTWIN
:
3083 if(video_out
&& vo_config_count
) {
3084 video_out
->control(VOCTRL_ROOTWIN
, 0);
3086 osd_show_rootwin
=10;
3087 vo_osd_changed(OSDTYPE_SUBTITLE
);
3092 case MP_CMD_PANSCAN
: {
3093 if ( !video_out
) break;
3094 if ( video_out
->control( VOCTRL_GET_PANSCAN
,NULL
) == VO_TRUE
)
3096 int abs
= cmd
->args
[1].v
.i
;
3097 float v
= cmd
->args
[0].v
.f
;
3100 else res
= vo_panscan
+v
;
3101 vo_panscan
= res
> 1 ? 1 : res
< 0 ? 0 : res
;
3102 video_out
->control( VOCTRL_SET_PANSCAN
,NULL
);
3104 if(osd_level
&& sh_video
){
3105 osd_visible
=sh_video
->fps
; // 1 sec
3106 vo_osd_progbar_type
=OSD_PANSCAN
;
3107 vo_osd_progbar_value
=vo_panscan
*256;
3108 vo_osd_changed(OSDTYPE_PROGBAR
);
3109 #ifdef HAVE_FREETYPE
3110 if (subtitle_autoscale
== 2 || subtitle_autoscale
== 3)
3111 // force scaling font to movie width or diagonal
3112 force_load_font
= 1;
3118 case MP_CMD_SUB_POS
:
3123 v
= cmd
->args
[0].v
.i
;
3126 if(sub_pos
>100) sub_pos
=100;
3127 if(sub_pos
<0) sub_pos
=0;
3128 vo_osd_changed(OSDTYPE_SUBTITLE
);
3129 osd_show_sub_pos
= 9;
3133 case MP_CMD_SUB_ALIGNMENT
:
3137 if (cmd
->nargs
>= 1)
3138 sub_alignment
= cmd
->args
[0].v
.i
;
3140 sub_alignment
= (sub_alignment
+1) % 3;
3141 osd_show_sub_alignment
= 9;
3142 vo_osd_changed(OSDTYPE_SUBTITLE
);
3146 case MP_CMD_SUB_VISIBILITY
:
3150 sub_visibility
=1-sub_visibility
;
3151 osd_show_sub_visibility
= 9; // show state of subtitle visibility in OSD
3152 vo_osd_changed(OSDTYPE_SUBTITLE
);
3156 case MP_CMD_GET_SUB_VISIBILITY
:
3160 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,MSGTR_AnsSubVisibility
, sub_visibility
);
3164 case MP_CMD_SUB_SELECT
:
3165 if (global_sub_size
) {
3169 if (global_sub_pos
>= global_sub_size
)
3170 global_sub_pos
= -1;
3171 if (global_sub_pos
>= 0)
3172 source
= sub_source();
3174 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
3175 global_sub_size
, global_sub_indices
[SUB_SOURCE_VOBSUB
],
3176 global_sub_indices
[SUB_SOURCE_SUBS
], global_sub_indices
[SUB_SOURCE_DEMUX
],
3177 global_sub_pos
, source
);
3180 set_of_sub_pos
= -1;
3186 if (d_dvdsub
) d_dvdsub
->id
= -1;
3189 // if sub_changed is till on but subdata's been reset, bad things happen.
3190 osd_show_vobsub_changed
= 0;
3191 osd_show_sub_changed
= 0;
3193 if (source
== SUB_SOURCE_VOBSUB
) {
3194 vobsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_VOBSUB
];
3195 if (!global_sub_quiet_osd_hack
) osd_show_vobsub_changed
= sh_video
->fps
;
3197 } else if (source
== SUB_SOURCE_SUBS
) {
3198 set_of_sub_pos
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_SUBS
];
3199 subdata
= set_of_subtitles
[set_of_sub_pos
];
3200 if (!global_sub_quiet_osd_hack
) osd_show_sub_changed
= sh_video
->fps
;
3201 vo_osd_changed(OSDTYPE_SUBTITLE
);
3203 // FIXME: is this the correct place for these?
3204 if(stream_dump_type
==3) list_sub_file(subdata
);
3205 if(stream_dump_type
==4) dump_mpsub(subdata
, sh_video
->fps
);
3206 if(stream_dump_type
==6) dump_srt(subdata
, sh_video
->fps
);
3207 if(stream_dump_type
==7) dump_microdvd(subdata
, sh_video
->fps
);
3208 if(stream_dump_type
==8) dump_jacosub(subdata
, sh_video
->fps
);
3209 if(stream_dump_type
==9) dump_sami(subdata
, sh_video
->fps
);
3211 } else if (source
== SUB_SOURCE_DEMUX
) {
3212 dvdsub_id
= global_sub_pos
- global_sub_indices
[SUB_SOURCE_DEMUX
];
3215 if (vo_spudec
&& stream
->type
== STREAMTYPE_DVD
) {
3216 d_dvdsub
->id
= dvdsub_id
;
3217 spudec_reset(vo_spudec
);
3220 #ifdef HAVE_OGGVORBIS
3221 if (demuxer
->type
== DEMUXER_TYPE_OGG
)
3222 d_dvdsub
->id
= demux_ogg_sub_id(demuxer
, dvdsub_id
);
3224 #ifdef HAVE_MATROSKA
3225 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
3226 d_dvdsub
->id
= demux_mkv_change_subs(demuxer
, dvdsub_id
);
3227 if (d_dvdsub
->id
>= 0 && ((mkv_sh_sub_t
*)d_dvdsub
->sh
)->type
== 'v') {
3228 mkv_sh_sub_t
*mkv_sh_sub
= (mkv_sh_sub_t
*)d_dvdsub
->sh
;
3229 if (vo_spudec
!= NULL
)
3230 spudec_free(vo_spudec
);
3232 spudec_new_scaled_vobsub(mkv_sh_sub
->palette
, mkv_sh_sub
->colors
,
3233 mkv_sh_sub
->custom_colors
,
3235 mkv_sh_sub
->height
);
3236 if (!forced_subs_only
)
3237 forced_subs_only
= mkv_sh_sub
->forced_subs_only
;
3239 spudec_set_forced_subs_only(vo_spudec
, forced_subs_only
);
3240 inited_flags
|= INITED_SPUDEC
;
3246 if (!global_sub_quiet_osd_hack
) osd_show_vobsub_changed
= sh_video
->fps
;
3248 if (!global_sub_quiet_osd_hack
) osd_show_vobsub_changed
= sh_video
->fps
;
3250 vo_osd_changed(OSDTYPE_SUBTITLE
);
3253 // it's annoying and dumb to show osd saying "off" at every subless file...
3254 global_sub_quiet_osd_hack
= 0;
3257 case MP_CMD_SUB_FORCED_ONLY
:
3259 forced_subs_only
= forced_subs_only
? 0 : ~0; // toggle state
3260 spudec_set_forced_subs_only(vo_spudec
,forced_subs_only
);
3263 case MP_CMD_SCREENSHOT
:
3264 if(vo_config_count
) video_out
->control(VOCTRL_SCREENSHOT
, NULL
);
3266 case MP_CMD_VF_CHANGE_RECTANGLE
:
3267 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
3270 case MP_CMD_GET_TIME_LENGTH
: {
3271 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,MSGTR_AnsLength
, demuxer_get_time_length(demuxer
));
3274 case MP_CMD_GET_VO_FULLSCREEN
: {
3275 if(video_out
&& vo_config_count
)
3276 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,MSGTR_AnsVoFullscreen
, vo_fs
);
3279 case MP_CMD_GET_PERCENT_POS
: {
3280 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,MSGTR_AnsPercentPos
, demuxer_get_percent_pos(demuxer
));
3283 case MP_CMD_CRUN
: {
3286 execl("/bin/sh","sh","-c",cmd
->args
[0].v
.s
,NULL
);
3294 case MP_CMD_DVDNAV_EVENT
: {
3295 dvdnav_priv_t
* dvdnav_priv
= (dvdnav_priv_t
*)(stream
->priv
);
3296 dvdnav_event_t
* dvdnav_event
= (dvdnav_event_t
*)(cmd
->args
[0].v
.v
);
3298 /* ignore these events if we're not in dvd_nav mode */
3299 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3301 if (!dvdnav_event
) {
3302 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNullEvent
);
3306 //printf("mplayer: got event: %d\n",dvdnav_event->event);
3308 switch (dvdnav_event
->event
) {
3309 case DVDNAV_BLOCK_OK
: {
3310 /* be silent about this one */
3313 case DVDNAV_HIGHLIGHT
: {
3314 dvdnav_highlight_event_t
*hevent
= (dvdnav_highlight_event_t
*)(dvdnav_event
->details
);
3316 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavHighlightEventBroken
);
3320 if (hevent
->display
&& hevent
->buttonN
>0)
3322 //dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
3323 sprintf( dvd_nav_text
, "Highlight button %d (%u,%u)-(%u,%u) PTS %d (now is %5.2f)",
3325 hevent
->sx
,hevent
->sy
,
3326 hevent
->ex
,hevent
->ey
,
3327 hevent
->pts
, d_video
->pts
);
3328 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavEvent
,dvd_nav_text
);
3329 //osd_show_dvd_nav_delay = 60;
3331 osd_show_dvd_nav_highlight
=1;
3332 osd_show_dvd_nav_sx
=hevent
->sx
;
3333 osd_show_dvd_nav_ex
=hevent
->ex
;
3334 osd_show_dvd_nav_sy
=hevent
->sy
;
3335 osd_show_dvd_nav_ey
=hevent
->ey
;
3338 osd_show_dvd_nav_highlight
=0;
3339 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavHighlightHide
);
3343 case DVDNAV_STILL_FRAME
: {
3344 dvdnav_still_event_t
*still_event
= (dvdnav_still_event_t
*)(dvdnav_event
->details
);
3346 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavStillFrame
, still_event
->length
);
3347 while (dvdnav_stream_sleeping(dvdnav_priv
)) {
3348 usec_sleep(1000); /* 1ms */
3350 dvdnav_stream_sleep(dvdnav_priv
,still_event
->length
);
3354 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavStop
);
3358 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavNOP
);
3361 case DVDNAV_SPU_STREAM_CHANGE
: {
3362 #if DVDNAVVERSION > 012
3363 dvdnav_spu_stream_change_event_t
*stream_change
= (dvdnav_spu_stream_change_event_t
*)(dvdnav_event
->details
);
3365 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuStreamChangeVerbose
,
3366 stream_change
->physical_wide
,
3367 stream_change
->physical_letterbox
,
3368 stream_change
->physical_pan_scan
,
3369 stream_change
->logical
);
3371 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical_wide
) {
3372 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3373 d_dvdsub
->id
,stream_change
->physical_wide
);
3374 // FIXME: need a better way to change SPU id
3375 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical_wide
;
3376 if (vo_spudec
) spudec_reset(vo_spudec
);
3379 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3381 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuStreamChange
,
3382 stream_change
->physical
,
3383 stream_change
->logical
);
3385 if (vo_spudec
&& dvdsub_id
!=stream_change
->physical
) {
3386 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_dvdsub->id change: was %d is now %d\n",
3387 d_dvdsub
->id
,stream_change
->physical
);
3388 // FIXME: need a better way to change SPU id
3389 d_dvdsub
->id
=dvdsub_id
=stream_change
->physical
;
3390 if (vo_spudec
) spudec_reset(vo_spudec
);
3395 case DVDNAV_AUDIO_STREAM_CHANGE
: {
3397 #if DVDNAVVERSION > 012
3398 dvdnav_audio_stream_change_event_t
*stream_change
= (dvdnav_audio_stream_change_event_t
*)(dvdnav_event
->details
);
3400 dvdnav_stream_change_event_t
*stream_change
= (dvdnav_stream_change_event_t
*)(dvdnav_event
->details
);
3403 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavAudioStreamChange
,
3404 stream_change
->physical
,
3405 stream_change
->logical
);
3407 aid_temp
=stream_change
->physical
;
3408 if (aid_temp
>=0) aid_temp
+=128; // FIXME: is this sane?
3409 if (d_audio
&& audio_id
!=aid_temp
) {
3410 mp_msg(MSGT_INPUT
,MSGL_DBG2
,"d_audio->id change: was %d is now %d\n",
3411 d_audio
->id
,aid_temp
);
3412 // FIXME: need a bettery way to change audio stream id
3413 d_audio
->id
=dvdsub_id
=aid_temp
;
3414 if(sh_audio
) resync_audio_stream(sh_audio
);
3419 case DVDNAV_VTS_CHANGE
: {
3420 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavVTSChange
);
3423 case DVDNAV_CELL_CHANGE
: {
3424 dvdnav_cell_change_event_t
*cell_change
= (dvdnav_cell_change_event_t
*)(dvdnav_event
->details
);
3425 cell_playback_t
* cell_playback
= cell_change
->new_cell
;
3427 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavCellChange
);
3428 osd_show_dvd_nav_highlight
=0; /* screen changed, disable menu */
3430 printf("new still time: %d\n",cell_playback->still_time);
3431 printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
3432 printf("new playback_time: %02d:%02d:%02d.%02d\n",
3433 cell_playback->playback_time.hour,
3434 cell_playback->playback_time.minute,
3435 cell_playback->playback_time.second,
3436 cell_playback->playback_time.frame_u);
3439 //rel_seek_secs=1; // not really: we can't seek, but it'll reset the muxer
3443 case DVDNAV_NAV_PACKET
: {
3444 // printf("DVDNAV Event: Nav Packet\n");
3447 case DVDNAV_SPU_CLUT_CHANGE
: {
3448 uint32_t * new_clut
= (uint32_t *)(dvdnav_event
->details
);
3450 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSpuClutChange
);
3451 // send new palette to SPU decoder
3452 if (vo_spudec
) spudec_update_palette(vo_spudec
,new_clut
);
3456 case DVDNAV_SEEK_DONE
: {
3457 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_DvdnavNavSeekDone
);
3462 // free the dvdnav event
3463 free(dvdnav_event
->details
);
3465 cmd
->args
[0].v
.v
=NULL
;
3467 case MP_CMD_DVDNAV
: {
3468 dvdnav_priv_t
* dvdnav_priv
=(dvdnav_priv_t
*)stream
->priv
;
3470 /* ignore these events if we're not in dvd_nav mode */
3471 if (stream
->type
!= STREAMTYPE_DVDNAV
) break;
3473 switch (cmd
->args
[0].v
.i
) {
3474 case MP_CMD_DVDNAV_UP
:
3475 dvdnav_upper_button_select(dvdnav_priv
->dvdnav
);
3477 case MP_CMD_DVDNAV_DOWN
:
3478 dvdnav_lower_button_select(dvdnav_priv
->dvdnav
);
3480 case MP_CMD_DVDNAV_LEFT
:
3481 dvdnav_left_button_select(dvdnav_priv
->dvdnav
);
3483 case MP_CMD_DVDNAV_RIGHT
:
3484 dvdnav_right_button_select(dvdnav_priv
->dvdnav
);
3486 case MP_CMD_DVDNAV_MENU
:
3487 mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_MenuCall
);
3488 dvdnav_menu_call(dvdnav_priv
->dvdnav
,DVD_MENU_Root
);
3490 case MP_CMD_DVDNAV_SELECT
:
3491 dvdnav_button_activate(dvdnav_priv
->dvdnav
);
3494 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Weird DVD Nav cmd %d\n",cmd
->args
[0].v
.i
);
3502 if ( ( use_gui
)&&( cmd
->id
> MP_CMD_GUI_EVENTS
) ) guiGetEvent( guiIEvent
,(char *)cmd
->id
);
3505 mp_msg(MSGT_CPLAYER
, MSGL_V
, "Received unknown cmd %s\n",cmd
->name
);
3515 if (sscanf(seek_to_sec
, "%d:%d:%f", &a
,&b
,&d
)==3)
3516 rel_seek_secs
+= 3600*a
+60*b
+d
;
3517 else if (sscanf(seek_to_sec
, "%d:%f", &a
, &d
)==2)
3518 rel_seek_secs
+= 60*a
+d
;
3519 else if (sscanf(seek_to_sec
, "%f", &d
)==1)
3526 if(eof
==1 && loop_times
>=0) {
3528 play_tree_iter_step(playtree_iter
,0,0);
3530 mp_msg(MSGT_CPLAYER
,MSGL_V
,"loop_times = %d, eof = %d\n", loop_times
,eof
);
3532 if(loop_times
>1) loop_times
--; else
3533 if(loop_times
==1) loop_times
=-1;
3534 play_n_frames
=play_n_frames_mf
;
3536 abs_seek_pos
=3; rel_seek_secs
=0; // seek to start of movie (0%)
3540 if(rel_seek_secs
|| abs_seek_pos
){
3541 current_module
="seek";
3542 if(demux_seek(demuxer
,rel_seek_secs
,abs_seek_pos
)){
3544 /* FIXME there should be real seeking for vobsub */
3545 if(sh_video
) sh_video
->pts
=d_video
->pts
;
3547 //vobsub_reset(vo_vobsub);
3548 vobsub_seek(vo_vobsub
,sh_video
->pts
);
3550 if(sh_video
&& d_video
->packs
== 0)
3551 ds_fill_buffer(d_video
);
3553 if(d_audio
->packs
== 0)
3554 ds_fill_buffer(d_audio
);
3556 float a_pts
=d_audio
->pts
;
3557 a_pts
+=(ds_tell_pts(d_audio
)-sh_audio
->a_in_buffer_len
)/(float)sh_audio
->i_bps
;
3558 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
);
3560 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
);
3562 mp_msg(MSGT_AVSYNC
,MSGL_STATUS
,"A: --- V:%6.1f \r",d_video
->pts
);
3568 current_module
="seek_video_reset";
3569 resync_video_stream(sh_video
);
3570 if(vo_config_count
) video_out
->control(VOCTRL_RESET
,NULL
);
3574 current_module
="seek_audio_reset";
3575 audio_out
->reset(); // stop audio, throwing away buffered data
3579 if(osd_level
&& !loop_seek
){
3581 if( !edl_decision
) {
3583 if( 1 ) { // Let the compiler optimize this out
3585 int len
=((demuxer
->movi_end
-demuxer
->movi_start
)>>8);
3586 if (len
>0 && sh_video
){
3587 osd_visible
=sh_video
->fps
; // 1 sec
3588 vo_osd_progbar_type
=0;
3589 vo_osd_progbar_value
=(demuxer
->filepos
-demuxer
->movi_start
)/len
;
3590 vo_osd_changed(OSDTYPE_PROGBAR
);
3597 max_pts_correction
=0.1;
3598 osd_visible
=sh_video
->fps
; // to rewert to PLAY pointer after 1 sec
3599 audio_time_usage
=0; video_time_usage
=0; vout_time_usage
=0;
3601 too_slow_frame_cnt
=0;
3602 too_fast_frame_cnt
=0;
3604 if(vo_spudec
) spudec_reset(vo_spudec
);
3609 * We saw a seek, have to rewind the EDL operations stack
3610 * and find the next EDL action to take care of.
3613 next_edl_record
= edl_records
;
3615 while (next_edl_record
)
3617 /* Trying to remember if we need to mute/unmute first;
3618 * prior EDL implementation lacks this.
3621 if (next_edl_record
->start_sec
>= sh_video
->pts
)
3623 if (edl_mute_count
> 0)
3625 if ((edl_mute_count
% 2) == 0 &&
3626 next_edl_record
->mute_state
== EDL_MUTE_END
)
3631 if ((edl_mute_count
% 2) != 0 &&
3632 next_edl_record
->mute_state
== EDL_MUTE_START
)
3637 } else if (next_edl_record
->mute_state
== EDL_MUTE_END
)
3645 next_edl_record
= next_edl_record
->next
;
3647 if (!next_edl_record
&& (edl_mute_count
% 2) != 0
3648 && edl_mute_count
> 0)
3657 frame_time_remaining
=0;
3658 current_module
=NULL
;
3665 if(demuxer
->file_format
==DEMUXER_TYPE_AVI
&& sh_video
&& sh_video
->video
.dwLength
>2){
3666 // get pos from frame number / total frames
3667 guiIntfStruct
.Position
=(float)d_video
->pack_no
*100.0f
/sh_video
->video
.dwLength
;
3669 off_t len
= ( demuxer
->movi_end
- demuxer
->movi_start
);
3670 off_t pos
= ( demuxer
->file_format
== DEMUXER_TYPE_AUDIO
?stream
->pos
:demuxer
->filepos
);
3671 guiIntfStruct
.Position
=(len
<= 0? 0.0f
: ( pos
- demuxer
->movi_start
) * 100.0f
/ len
);
3673 if ( sh_video
) guiIntfStruct
.TimeSec
=sh_video
->pts
;
3674 else if ( sh_audio
) guiIntfStruct
.TimeSec
=sh_audio
->delay
;
3675 guiIntfStruct
.LengthInSec
=demuxer_get_time_length(demuxer
);
3676 guiGetEvent( guiReDraw
,NULL
);
3677 guiGetEvent( guiSetVolume
,NULL
);
3678 if(guiIntfStruct
.Playing
==0) break; // STOP
3679 if(guiIntfStruct
.Playing
==2) osd_function
=OSD_PAUSE
;
3680 if ( guiIntfStruct
.DiskChanged
|| guiIntfStruct
.NewPlay
) goto goto_next_file
;
3682 if ( stream
->type
== STREAMTYPE_DVD
)
3684 dvd_priv_t
* dvdp
= stream
->priv
;
3685 guiIntfStruct
.DVD
.current_chapter
=dvd_chapter_from_cell(dvdp
,guiIntfStruct
.DVD
.current_title
-1, dvdp
->cur_cell
)+1;
3692 //================= Update OSD ====================
3694 if(osd_level
>=1 && sh_video
){
3695 int pts
=sh_video
->pts
;
3696 char osd_text_tmp
[64];
3697 if(pts
==osd_last_pts
-1) ++pts
; else osd_last_pts
=pts
;
3698 vo_osd_text
=osd_text_buffer
;
3700 if (osd_show_dvd_nav_delay
) {
3701 snprintf(osd_text_tmp
, 63, "DVDNAV: %s", dvd_nav_text
);
3702 osd_show_dvd_nav_delay
--;
3706 if (osd_show_tv_channel
&& tv_channel_list
) {
3707 snprintf(osd_text_tmp
, 63, "Channel: %s", tv_channel_current
->name
);
3708 osd_show_tv_channel
--;
3711 if (osd_show_text
) {
3712 snprintf(osd_text_tmp
, 63, "%s", osd_show_text_buffer
);
3715 if (osd_show_sub_visibility
) {
3716 snprintf(osd_text_tmp
, 63, "Subtitles: %sabled", sub_visibility
?"en":"dis");
3717 osd_show_sub_visibility
--;
3719 if (osd_show_vobsub_changed
) {
3720 if (vo_vobsub
&& vobsub_id
>= 0) {
3721 const char *language
= "none";
3722 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
3723 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", vobsub_id
, language
? language
: "unknown");
3725 #ifdef HAVE_OGGVORBIS
3726 if (d_dvdsub
&& demuxer
->type
== DEMUXER_TYPE_OGG
) {
3728 snprintf(osd_text_tmp
, 63, "Subtitles: (off)");
3730 char *lang
= demux_ogg_sub_lang(demuxer
, dvdsub_id
);
3731 if (!lang
) lang
= "unknown";
3732 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", dvdsub_id
, lang
);
3737 if (vo_spudec
&& (demuxer
->type
!= DEMUXER_TYPE_MATROSKA
)) {
3738 char lang
[5] = "none";
3740 if (dvdsub_id
>= 0) code
= dvd_lang_from_sid(stream
, dvdsub_id
);
3742 lang
[0] = code
>> 8;
3746 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", dvdsub_id
, lang
);
3749 #ifdef HAVE_MATROSKA
3750 if (demuxer
->type
== DEMUXER_TYPE_MATROSKA
) {
3751 char lang
[10] = "unknown";
3752 if (dvdsub_id
>= 0) {
3753 demux_mkv_get_sub_lang(demuxer
, dvdsub_id
, lang
, 9);
3756 strcpy(lang
, "off");
3757 snprintf(osd_text_tmp
, 63, "Subtitles: (%d) %s", dvdsub_id
, lang
);
3760 osd_show_vobsub_changed
--;
3763 if (osd_show_sub_changed
) {
3765 tmp
= subdata
->filename
;
3766 if ((tmp2
= strrchr(tmp
, '/'))) {
3769 snprintf(osd_text_tmp
, 63, "Sub: (%d) %s%s",
3771 strlen(tmp
) < 20 ? "" : "...",
3772 strlen(tmp
) < 20 ? tmp
: tmp
+strlen(tmp
)-19);
3773 osd_show_sub_changed
--;
3776 if (osd_show_sub_delay
) {
3777 snprintf(osd_text_tmp
, 63, "Sub delay: %d ms", ROUND(sub_delay
*1000));
3778 osd_show_sub_delay
--;
3780 if (osd_show_sub_pos
) {
3781 snprintf(osd_text_tmp
, 63, "Sub position: %d/100", sub_pos
);
3784 if (osd_show_sub_alignment
) {
3785 snprintf(osd_text_tmp
, 63, "Sub alignment: %s",
3786 (sub_alignment
== 2 ? "bottom" :
3787 (sub_alignment
== 1 ? "center" : "top")));
3788 osd_show_sub_alignment
--;
3790 if (osd_show_av_delay
) {
3791 snprintf(osd_text_tmp
, 63, "A-V delay: %d ms", ROUND(audio_delay
*1000));
3792 osd_show_av_delay
--;
3793 } else if (osd_show_ontop
) {
3794 snprintf(osd_text_tmp
, 63, "Stay on top: %sabled", vo_ontop
?"en":"dis");
3796 } else if (osd_show_rootwin
) {
3797 snprintf(osd_text_tmp
, 63, "Rootwin: %sabled", vo_rootwin
?"en":"dis");
3799 } else if (osd_show_framedropping
) {
3800 snprintf(osd_text_tmp
, 63, "Framedropping: %s",
3801 (frame_dropping
== 1 ? "on" :
3802 (frame_dropping
== 2 ? "hard" : "off")));
3803 osd_show_framedropping
--;
3804 } else if(osd_level
>=2) {
3805 int len
= demuxer_get_time_length(demuxer
);
3806 int percentage
= -1;
3807 char percentage_text
[10];
3808 if (osd_show_percentage
) {
3809 percentage
= demuxer_get_percent_pos(demuxer
);
3810 osd_show_percentage
--;
3812 if (percentage
>= 0)
3813 snprintf(percentage_text
, 9, " (%d%%)", percentage
);
3815 percentage_text
[0] = 0;
3817 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
);
3819 snprintf(osd_text_tmp
, 63, "%c %02d:%02d:%02d%s",osd_function
,pts
/3600,(pts
/60)%60,pts
%60,percentage_text
);
3820 } else osd_text_tmp
[0]=0;
3822 if(strcmp(vo_osd_text
, osd_text_tmp
)) {
3823 strncpy(vo_osd_text
, osd_text_tmp
, 63);
3824 vo_osd_changed(OSDTYPE_OSD
);
3829 vo_osd_changed(OSDTYPE_OSD
);
3832 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
3833 // vo_osd_text=osd_text_buffer;
3838 if(subdata
&& sh_video
->pts
>0){
3839 float pts
=sh_video
->pts
;
3840 if(sub_fps
==0) sub_fps
=sh_video
->fps
;
3841 current_module
="find_sub";
3842 if (pts
> sub_last_pts
|| pts
< sub_last_pts
-1.0 ) {
3843 find_sub(subdata
, (pts
+sub_delay
) *
3844 (subdata
->sub_uses_time
? 100. : sub_fps
));
3845 // FIXME! frame counter...
3848 current_module
=NULL
;
3853 if (stop_xscreensaver
&& sh_video
) {
3854 current_module
="stop_xscreensaver";
3855 xscreensaver_heartbeat();
3856 current_module
=NULL
;
3861 if(vo_config_count
&& vo_spudec
) {
3862 unsigned char* packet
=NULL
;
3864 current_module
="spudec";
3865 spudec_heartbeat(vo_spudec
,90000*sh_video
->timer
);
3866 // Get a sub packet from the dvd or a vobsub and make a timestamp relative to sh_video->timer
3871 if(sh_video
->pts
+sub_delay
>=0) {
3872 // The + next_frame_time is there because we'll display the sub at the next frame
3873 len
= vobsub_get_packet(vo_vobsub
,sh_video
->pts
+sub_delay
+next_frame_time
,(void**)&packet
,×tamp
);
3875 timestamp
-= (sh_video
->pts
+ sub_delay
- sh_video
->timer
)*90000;
3876 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
);
3881 len
= ds_get_packet_sub(d_dvdsub
,(unsigned char**)&packet
);
3883 float x
= d_dvdsub
->pts
- sh_video
->pts
;
3884 if (x
< -10 || x
> 10) // prevent missing subs on pts reset
3885 timestamp
= 90000*(sh_video
->timer
+ d_dvdsub
->pts
+ sub_delay
- sh_video
->pts
);
3886 else timestamp
= 90000*(sh_video
->timer
+ sub_delay
);
3887 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
);
3890 if(len
<=0 || !packet
) break;
3891 if(timestamp
< 0) timestamp
= 0;
3892 else spudec_assemble(vo_spudec
,packet
,len
,timestamp
);
3895 /* detect wether the sub has changed or not */
3896 if(spudec_changed(vo_spudec
))
3897 vo_osd_changed(OSDTYPE_SPU
);
3898 current_module
=NULL
;
3903 mp_msg(MSGT_GLOBAL
,MSGL_V
,"EOF code: %d \n",eof
);
3907 goto_next_file
: // don't jump here after ao/vo/getch initialization!
3909 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\n");
3912 double tot
=video_time_usage
+vout_time_usage
+audio_time_usage
;
3913 double total_time_usage
;
3914 total_time_usage_start
=GetTimer()-total_time_usage_start
;
3915 total_time_usage
= (float)total_time_usage_start
*0.000001;
3916 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
3917 video_time_usage
,vout_time_usage
,audio_time_usage
,
3918 total_time_usage
-tot
,total_time_usage
);
3919 if(total_time_usage
>0.0)
3920 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
3921 100.0*video_time_usage
/total_time_usage
,
3922 100.0*vout_time_usage
/total_time_usage
,
3923 100.0*audio_time_usage
/total_time_usage
,
3924 100.0*(total_time_usage
-tot
)/total_time_usage
,
3926 if(total_frame_cnt
&& frame_dropping
)
3927 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
3928 total_frame_cnt
-drop_frame_cnt
,
3929 (total_time_usage
>0.5)?((total_frame_cnt
-drop_frame_cnt
)/total_time_usage
):0,
3931 100*drop_frame_cnt
/total_frame_cnt
,
3933 (total_time_usage
>0.5)?(total_frame_cnt
/total_time_usage
):0);
3937 // time to uninit all, except global stuff:
3938 uninit_player(INITED_ALL
-(INITED_GUI
+INITED_INPUT
+(fixed_vo
?INITED_VO
:0)));
3941 if ( set_of_sub_size
> 0 )
3943 current_module
="sub_free";
3944 for (i
= 0; i
< set_of_sub_size
; ++i
)
3945 sub_free( set_of_subtitles
[i
] );
3946 set_of_sub_size
= 0;
3952 if(eof
== PT_NEXT_ENTRY
|| eof
== PT_PREV_ENTRY
) {
3953 eof
= eof
== PT_NEXT_ENTRY
? 1 : -1;
3954 if(play_tree_iter_step(playtree_iter
,play_tree_step
,0) == PLAY_TREE_ITER_ENTRY
) {
3957 play_tree_iter_free(playtree_iter
);
3958 playtree_iter
= NULL
;
3961 } else if (eof
== PT_UP_NEXT
|| eof
== PT_UP_PREV
) {
3962 eof
= eof
== PT_UP_NEXT
? 1 : -1;
3963 if ( playtree_iter
) {
3964 if(play_tree_iter_up_step(playtree_iter
,eof
,0) == PLAY_TREE_ITER_ENTRY
) {
3967 play_tree_iter_free(playtree_iter
);
3968 playtree_iter
= NULL
;
3971 } else { // NEXT PREV SRC
3972 eof
= eof
== PT_PREV_SRC
? -1 : 1;
3975 if(eof
== 0) eof
= 1;
3977 while(playtree_iter
!= NULL
) {
3978 filename
= play_tree_iter_get_file(playtree_iter
,eof
);
3979 if(filename
== NULL
) {
3980 if( play_tree_iter_step(playtree_iter
,eof
,0) != PLAY_TREE_ITER_ENTRY
) {
3981 play_tree_iter_free(playtree_iter
);
3982 playtree_iter
= NULL
;
3989 if( use_gui
&& !playtree_iter
)
3992 if ( !guiIntfStruct
.DiskChanged
)
3998 if(use_gui
|| playtree_iter
!= NULL
){
4001 goto play_next_file
;
4004 #ifdef HAVE_FREETYPE
4005 current_module
="uninit_font";
4006 if (vo_font
) free_font_desc(vo_font
);
4011 exit_player_with_rc(MSGTR_Exit_eof
, 0);