Remove write-only variable
[mplayer.git] / mplayer.c
blob8daf53db1b0c885e78ebb28002ddc0e78c3c3cfe
2 /// \file
3 /// \ingroup Properties Command2Property OSDMsgStack
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "config.h"
9 #ifdef WIN32
10 #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
11 #include <windows.h>
12 #endif
13 #include <string.h>
14 #include <unistd.h>
16 // #include <sys/mman.h>
17 #include <sys/types.h>
18 #ifndef __MINGW32__
19 #include <sys/ioctl.h>
20 #include <sys/wait.h>
21 #else
22 #define SIGHUP 1 /* hangup */
23 #define SIGQUIT 3 /* quit */
24 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
25 #define SIGBUS 10 /* bus error */
26 #define SIGPIPE 13 /* broken pipe */
27 extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
28 #endif
30 #include <sys/time.h>
31 #include <sys/stat.h>
33 #include <signal.h>
34 #include <time.h>
35 #include <fcntl.h>
36 #include <limits.h>
38 #include <errno.h>
40 #include "version.h"
42 #include "mp_msg.h"
44 #define HELP_MP_DEFINE_STATIC
45 #include "help_mp.h"
47 #include "m_option.h"
48 #include "m_config.h"
49 #include "m_property.h"
51 #include "cfg-mplayer-def.h"
53 #ifdef USE_SUB
54 #include "subreader.h"
55 #endif
57 #include "libvo/video_out.h"
59 #include "libvo/font_load.h"
60 #include "libvo/sub.h"
62 #ifdef HAVE_X11
63 #include "libvo/x11_common.h"
64 #endif
66 #include "libao2/audio_out.h"
68 #include "codec-cfg.h"
70 #include "edl.h"
72 #include "spudec.h"
73 #include "vobsub.h"
75 #include "osdep/getch2.h"
76 #include "osdep/timer.h"
78 #include "cpudetect.h"
80 #ifdef HAVE_NEW_GUI
81 #include "Gui/interface.h"
82 #endif
84 #include "input/input.h"
86 int slave_mode=0;
87 int player_idle_mode=0;
88 int quiet=0;
89 int enable_mouse_movements=0;
91 #ifdef WIN32
92 char * proc_priority=NULL;
93 #endif
95 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
97 #ifdef HAVE_RTC
98 #ifdef __linux__
99 #include <linux/rtc.h>
100 #else
101 #include <rtc.h>
102 #define RTC_IRQP_SET RTCIO_IRQP_SET
103 #define RTC_PIE_ON RTCIO_PIE_ON
104 #endif /* __linux__ */
105 #endif /* HAVE_RTC */
107 #ifdef USE_TV
108 #include "stream/tv.h"
109 #endif
110 #ifdef USE_RADIO
111 #include "stream/stream_radio.h"
112 #endif
114 #ifdef HAS_DVBIN_SUPPORT
115 #include "stream/dvbin.h"
116 static int last_dvb_step = 1;
117 static int dvbin_reopen = 0;
118 #include "stream/cache2.h"
119 #endif
121 //**************************************************************************//
122 // Playtree
123 //**************************************************************************//
124 #include "playtree.h"
125 #include "playtreeparser.h"
127 #ifdef HAVE_NEW_GUI
128 extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
129 extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
130 #endif
132 play_tree_t* playtree;
133 play_tree_iter_t* playtree_iter = NULL;
134 static int play_tree_step = 1;
136 #define PT_NEXT_ENTRY 1
137 #define PT_PREV_ENTRY -1
138 #define PT_NEXT_SRC 2
139 #define PT_PREV_SRC -2
140 #define PT_UP_NEXT 3
141 #define PT_UP_PREV -3
143 //**************************************************************************//
144 // Config
145 //**************************************************************************//
146 #include "parser-cfg.h"
147 #include "parser-mpcmd.h"
149 m_config_t* mconfig;
151 //**************************************************************************//
152 // Config file
153 //**************************************************************************//
155 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
157 static int cfg_include(m_option_t *conf, char *filename){
158 return m_config_parse_config_file(mconfig, filename);
161 #include "get_path.c"
163 //**************************************************************************//
164 // XScreensaver
165 //**************************************************************************//
167 #ifdef HAVE_X11
168 void xscreensaver_heartbeat(void);
169 #endif
171 //**************************************************************************//
172 //**************************************************************************//
173 // Input media streaming & demultiplexer:
174 //**************************************************************************//
176 static int max_framesize=0;
178 #include "stream/stream.h"
179 #include "libmpdemux/demuxer.h"
180 #include "libmpdemux/stheader.h"
181 //#include "parse_es.h"
182 #include "libmpdemux/matroska.h"
184 #ifdef USE_DVDREAD
185 #include "stream/stream_dvd.h"
186 #endif
188 #include "libmpcodecs/dec_audio.h"
189 #include "libmpcodecs/dec_video.h"
190 #include "libmpcodecs/mp_image.h"
191 #include "libmpcodecs/vf.h"
192 #include "libmpcodecs/vd.h"
194 //**************************************************************************//
196 static void reinit_audio_chain(void);
198 //**************************************************************************//
199 //**************************************************************************//
201 // Common FIFO functions, and keyboard/event FIFO code
202 #include "fifo.c"
203 int noconsolecontrols=0;
204 //**************************************************************************//
206 vo_functions_t *video_out=NULL;
207 ao_functions_t *audio_out=NULL;
209 int fixed_vo=0;
210 int eof=0;
212 // benchmark:
213 double video_time_usage=0;
214 double vout_time_usage=0;
215 static double audio_time_usage=0;
216 static int total_time_usage_start=0;
217 static int total_frame_cnt=0;
218 static int drop_frame_cnt=0; // total number of dropped frames
219 int benchmark=0;
221 // options:
222 int auto_quality=0;
223 static int output_quality=0;
225 float playback_speed=1.0;
227 int use_gui=0;
229 #ifdef HAVE_NEW_GUI
230 int enqueue=0;
231 #endif
233 static int list_properties = 0;
235 #define MAX_OSD_LEVEL 3
236 #define MAX_TERM_OSD_LEVEL 1
238 int osd_level=1;
239 int osd_level_saved=-1;
240 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
241 unsigned int osd_visible;
242 static int osd_function=OSD_PLAY;
243 static int osd_show_percentage = 0;
244 static int osd_duration = 1000;
246 static int term_osd = 1;
247 static char* term_osd_esc = "\x1b[A\r\x1b[K";
248 static char* playing_msg = NULL;
249 // seek:
250 static char *seek_to_sec=NULL;
251 static off_t seek_to_byte=0;
252 static off_t step_sec=0;
253 static int loop_times=-1;
254 static int loop_seek=0;
256 static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 };
258 // A/V sync:
259 int autosync=0; // 30 might be a good default value.
261 // may be changed by GUI: (FIXME!)
262 float rel_seek_secs=0;
263 int abs_seek_pos=0;
265 // codecs:
266 char **audio_codec_list=NULL; // override audio codec
267 char **video_codec_list=NULL; // override video codec
268 char **audio_fm_list=NULL; // override audio codec family
269 char **video_fm_list=NULL; // override video codec family
271 // demuxer:
272 extern char *demuxer_name; // override demuxer
273 extern char *audio_demuxer_name; // override audio demuxer
274 extern char *sub_demuxer_name; // override sub demuxer
276 // streaming:
277 int audio_id=-1;
278 int video_id=-1;
279 int dvdsub_id=-2;
280 int vobsub_id=-1;
281 char* audio_lang=NULL;
282 char* dvdsub_lang=NULL;
283 static char* spudec_ifo=NULL;
284 char* filename=NULL; //"MI2-Trailer.avi";
285 int forced_subs_only=0;
286 int file_filter=1;
288 // cache2:
289 int stream_cache_size=-1;
290 #ifdef USE_STREAM_CACHE
291 extern int cache_fill_status;
293 float stream_cache_min_percent=20.0;
294 float stream_cache_seek_min_percent=50.0;
295 #else
296 #define cache_fill_status 0
297 #endif
299 // dump:
300 static char *stream_dump_name="stream.dump";
301 int stream_dump_type=0;
303 // A-V sync:
304 static float default_max_pts_correction=-1;//0.01f;
305 static float max_pts_correction=0;//default_max_pts_correction;
306 static float c_total=0;
307 float audio_delay=0;
308 static int ignore_start=0;
310 static int softsleep=0;
312 float force_fps=0;
313 static int force_srate=0;
314 static int audio_output_format=-1; // AF_FORMAT_UNKNOWN
315 int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
316 static int play_n_frames=-1;
317 static int play_n_frames_mf=-1;
319 // screen info:
320 char** video_driver_list=NULL;
321 char** audio_driver_list=NULL;
323 extern char *vo_subdevice;
324 extern char *ao_subdevice;
326 // codec outfmt flags (defined in libmpcodecs/vd.c)
327 extern int vo_flags;
329 // sub:
330 char *font_name=NULL;
331 #ifdef HAVE_FONTCONFIG
332 extern int font_fontconfig;
333 #endif
334 float font_factor=0.75;
335 char **sub_name=NULL;
336 float sub_delay=0;
337 float sub_fps=0;
338 int sub_auto = 1;
339 char *vobsub_name=NULL;
340 /*DSP!!char *dsp=NULL;*/
341 int subcc_enabled=0;
342 int suboverlap_enabled = 1;
343 #ifdef USE_SUB
344 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
345 int set_of_sub_size = 0;
346 int set_of_sub_pos = -1;
347 float sub_last_pts = -303;
348 #endif
349 int global_sub_size = 0; // this encompasses all subtitle sources
350 int global_sub_pos = -1; // this encompasses all subtitle sources
351 #define SUB_SOURCE_SUBS 0
352 #define SUB_SOURCE_VOBSUB 1
353 #define SUB_SOURCE_DEMUX 2
354 #define SUB_SOURCES 3
355 int global_sub_indices[SUB_SOURCES];
357 #ifdef USE_ASS
358 #include "libass/ass.h"
359 #include "libass/ass_mp.h"
361 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
362 // or NULL if format unsupported
363 ass_track_t* set_of_ass_tracks[MAX_SUBTITLE_FILES];
364 ass_track_t* ass_track = 0; // current track to render
365 #endif
367 extern int mp_msg_levels[MSGT_MAX];
368 extern int mp_msg_level_all;
370 static stream_t* stream=NULL;
371 static demuxer_t *demuxer=NULL;
372 static sh_audio_t *sh_audio=NULL;
373 static sh_video_t *sh_video=NULL;
374 static demux_stream_t *d_audio=NULL;
375 static demux_stream_t *d_video=NULL;
376 static demux_stream_t *d_dvdsub=NULL;
378 char* current_module=NULL; // for debugging
380 extern int vo_gamma_gamma;
381 extern int vo_gamma_brightness;
382 extern int vo_gamma_contrast;
383 extern int vo_gamma_saturation;
384 extern int vo_gamma_hue;
386 // ---
388 #ifdef HAVE_MENU
389 #include "m_struct.h"
390 #include "libmenu/menu.h"
391 extern void vf_menu_pause_update(struct vf_instance_s* vf);
392 extern vf_info_t vf_info_menu;
393 static vf_info_t* libmenu_vfs[] = {
394 &vf_info_menu,
395 NULL
397 static vf_instance_t* vf_menu = NULL;
398 static int use_menu = 0;
399 static char* menu_cfg = NULL;
400 static char* menu_root = "main";
401 #endif
404 #ifdef HAVE_RTC
405 static int nortc = 1;
406 static char* rtc_device;
407 #endif
409 edl_record_ptr edl_records = NULL; ///< EDL entries memory area
410 edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
411 short user_muted = 0; ///< Stores whether user wanted muted mode.
412 short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
413 short edl_decision = 0; ///< 1 when an EDL operation has been made.
414 FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode.
415 float begin_skip = MP_NOPTS_VALUE; ///< start time of the current skip while on edlout mode
416 int use_filedir_conf;
418 static unsigned int inited_flags=0;
419 #define INITED_VO 1
420 #define INITED_AO 2
421 #define INITED_GUI 4
422 #define INITED_GETCH2 8
423 #define INITED_SPUDEC 32
424 #define INITED_STREAM 64
425 #define INITED_INPUT 128
426 #define INITED_VOBSUB 256
427 #define INITED_DEMUXER 512
428 #define INITED_ACODEC 1024
429 #define INITED_VCODEC 2048
430 #define INITED_ALL 0xFFFF
432 #include "metadata.h"
434 #define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
436 static int is_valid_metadata_type (metadata_t type) {
437 switch (type)
439 /* check for valid video stream */
440 case META_VIDEO_CODEC:
441 case META_VIDEO_BITRATE:
442 case META_VIDEO_RESOLUTION:
444 if (!sh_video)
445 return 0;
446 break;
449 /* check for valid audio stream */
450 case META_AUDIO_CODEC:
451 case META_AUDIO_BITRATE:
452 case META_AUDIO_SAMPLES:
454 if (!sh_audio)
455 return 0;
456 break;
459 /* check for valid demuxer */
460 case META_INFO_TITLE:
461 case META_INFO_ARTIST:
462 case META_INFO_ALBUM:
463 case META_INFO_YEAR:
464 case META_INFO_COMMENT:
465 case META_INFO_TRACK:
466 case META_INFO_GENRE:
468 if (!demuxer)
469 return 0;
470 break;
473 default:
474 break;
477 return 1;
480 static char *get_demuxer_info (char *tag) {
481 char **info = demuxer->info;
482 int n;
484 if (!info || !tag)
485 return NULL;
487 for (n = 0; info[2*n] != NULL ; n++)
488 if (!strcmp (info[2*n], tag))
489 break;
491 return info[2*n+1] ? strdup (info[2*n+1]) : NULL;
494 char *get_metadata (metadata_t type) {
495 char *meta = NULL;
497 if (!is_valid_metadata_type (type))
498 return NULL;
500 switch (type)
502 case META_NAME:
504 return strdup (mp_basename2 (filename));
507 case META_VIDEO_CODEC:
509 if (sh_video->format == 0x10000001)
510 meta = strdup ("mpeg1");
511 else if (sh_video->format == 0x10000002)
512 meta = strdup ("mpeg2");
513 else if (sh_video->format == 0x10000004)
514 meta = strdup ("mpeg4");
515 else if (sh_video->format == 0x10000005)
516 meta = strdup ("h264");
517 else if (sh_video->format >= 0x20202020)
519 meta = (char *) malloc (8);
520 sprintf (meta, "%.4s", (char *) &sh_video->format);
522 else
524 meta = (char *) malloc (8);
525 sprintf (meta, "0x%08X", sh_video->format);
527 return meta;
530 case META_VIDEO_BITRATE:
532 meta = (char *) malloc (16);
533 sprintf (meta, "%d kbps", (int) (sh_video->i_bps * 8 / 1024));
534 return meta;
537 case META_VIDEO_RESOLUTION:
539 meta = (char *) malloc (16);
540 sprintf (meta, "%d x %d", sh_video->disp_w, sh_video->disp_h);
541 return meta;
544 case META_AUDIO_CODEC:
546 if (sh_audio->codec && sh_audio->codec->name)
547 meta = strdup (sh_audio->codec->name);
548 return meta;
551 case META_AUDIO_BITRATE:
553 meta = (char *) malloc (16);
554 sprintf (meta, "%d kbps", (int) (sh_audio->i_bps * 8/1000));
555 return meta;
558 case META_AUDIO_SAMPLES:
560 meta = (char *) malloc (16);
561 sprintf (meta, "%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels);
562 return meta;
565 /* check for valid demuxer */
566 case META_INFO_TITLE:
567 return get_demuxer_info ("Title");
569 case META_INFO_ARTIST:
570 return get_demuxer_info ("Artist");
572 case META_INFO_ALBUM:
573 return get_demuxer_info ("Album");
575 case META_INFO_YEAR:
576 return get_demuxer_info ("Year");
578 case META_INFO_COMMENT:
579 return get_demuxer_info ("Comment");
581 case META_INFO_TRACK:
582 return get_demuxer_info ("Track");
584 case META_INFO_GENRE:
585 return get_demuxer_info ("Genre");
587 default:
588 break;
591 return meta;
594 static void uninit_player(unsigned int mask){
595 mask=inited_flags&mask;
597 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
599 if(mask&INITED_ACODEC){
600 inited_flags&=~INITED_ACODEC;
601 current_module="uninit_acodec";
602 if(sh_audio) uninit_audio(sh_audio);
603 #ifdef HAVE_NEW_GUI
604 guiGetEvent(guiSetAfilter, (char *)NULL);
605 #endif
606 sh_audio=NULL;
609 if(mask&INITED_VCODEC){
610 inited_flags&=~INITED_VCODEC;
611 current_module="uninit_vcodec";
612 if(sh_video) uninit_video(sh_video);
613 sh_video=NULL;
614 #ifdef HAVE_MENU
615 vf_menu=NULL;
616 #endif
619 if(mask&INITED_DEMUXER){
620 inited_flags&=~INITED_DEMUXER;
621 current_module="free_demuxer";
622 if(demuxer){
623 stream=demuxer->stream;
624 free_demuxer(demuxer);
626 demuxer=NULL;
629 // kill the cache process:
630 if(mask&INITED_STREAM){
631 inited_flags&=~INITED_STREAM;
632 current_module="uninit_stream";
633 if(stream) free_stream(stream);
634 stream=NULL;
637 if(mask&INITED_VO){
638 inited_flags&=~INITED_VO;
639 current_module="uninit_vo";
640 video_out->uninit();
641 video_out=NULL;
644 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
645 if(mask&INITED_GETCH2){
646 inited_flags&=~INITED_GETCH2;
647 current_module="uninit_getch2";
648 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
649 // restore terminal:
650 getch2_disable();
653 if(mask&INITED_VOBSUB){
654 inited_flags&=~INITED_VOBSUB;
655 current_module="uninit_vobsub";
656 if(vo_vobsub) vobsub_close(vo_vobsub);
657 vo_vobsub=NULL;
660 if (mask&INITED_SPUDEC){
661 inited_flags&=~INITED_SPUDEC;
662 current_module="uninit_spudec";
663 spudec_free(vo_spudec);
664 vo_spudec=NULL;
667 if(mask&INITED_AO){
668 inited_flags&=~INITED_AO;
669 current_module="uninit_ao";
670 audio_out->uninit(eof?0:1); audio_out=NULL;
673 #ifdef HAVE_NEW_GUI
674 if(mask&INITED_GUI){
675 inited_flags&=~INITED_GUI;
676 current_module="uninit_gui";
677 guiDone();
679 #endif
681 if(mask&INITED_INPUT){
682 inited_flags&=~INITED_INPUT;
683 current_module="uninit_input";
684 mp_input_uninit();
687 current_module=NULL;
690 static void exit_player_with_rc(const char* how, int rc){
692 uninit_player(INITED_ALL);
693 #ifdef HAVE_X11
694 #ifdef HAVE_NEW_GUI
695 if ( !use_gui )
696 #endif
697 vo_uninit(); // Close the X11 connection (if any is open).
698 #endif
700 #ifdef HAVE_FREETYPE
701 current_module="uninit_font";
702 if (vo_font) free_font_desc(vo_font);
703 vo_font = NULL;
704 done_freetype();
705 #endif
706 free_osd_list();
708 #ifdef USE_ASS
709 ass_library_done(ass_library);
710 #endif
712 current_module="exit_player";
714 // free mplayer config
715 if(mconfig)
716 m_config_free(mconfig);
718 if(playtree)
719 play_tree_free(playtree, 1);
722 if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
723 if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,how);
724 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
726 exit(rc);
729 void exit_player(const char* how){
730 exit_player_with_rc(how, 1);
733 #ifndef __MINGW32__
734 static void child_sighandler(int x){
735 pid_t pid;
736 while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
738 #endif
740 #ifdef CRASH_DEBUG
741 static char *prog_path;
742 static int crash_debug = 0;
743 #endif
745 static void exit_sighandler(int x){
746 static int sig_count=0;
747 #ifdef CRASH_DEBUG
748 if (!crash_debug || x != SIGTRAP)
749 #endif
750 ++sig_count;
751 if(inited_flags==0 && sig_count>1) exit(1);
752 if(sig_count==5)
754 /* We're crashing bad and can't uninit cleanly :(
755 * by popular request, we make one last (dirty)
756 * effort to restore the user's
757 * terminal. */
758 getch2_disable();
759 exit(1);
761 if(sig_count==6) exit(1);
762 if(sig_count>6){
763 // can't stop :(
764 #ifndef __MINGW32__
765 kill(getpid(),SIGKILL);
766 #endif
768 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
769 current_module?current_module:"unknown"
771 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x);
772 if(sig_count<=1)
773 switch(x){
774 case SIGINT:
775 case SIGQUIT:
776 case SIGTERM:
777 case SIGKILL:
778 break; // killed from keyboard (^C) or killed [-9]
779 case SIGILL:
780 #ifdef RUNTIME_CPUDETECT
781 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
782 #else
783 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
784 #endif
785 case SIGFPE:
786 case SIGSEGV:
787 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
788 default:
789 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
790 #ifdef CRASH_DEBUG
791 if (crash_debug) {
792 int gdb_pid;
793 char spid[20];
794 snprintf(spid, 19, "%i", getpid());
795 spid[19] = 0;
796 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
797 gdb_pid = fork();
798 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
799 if (gdb_pid == 0) { // We are the child
800 if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
801 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
802 } else if (gdb_pid < 0)
803 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
804 else {
805 waitpid(gdb_pid, NULL, 0);
807 if (x == SIGTRAP) return;
809 #endif
811 exit_player(NULL);
814 extern void mp_input_register_options(m_config_t* cfg);
816 #include "mixer.h"
817 mixer_t mixer;
818 /// step size of mixer changes
819 int volstep = 3;
821 #include "cfg-mplayer.h"
823 static void parse_cfgfiles( m_config_t* conf )
825 char *conffile;
826 int conffile_fd;
827 if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
828 exit_player(NULL);
829 if ((conffile = get_path("")) == NULL) {
830 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
831 } else {
832 #ifdef __MINGW32__
833 mkdir(conffile);
834 #else
835 mkdir(conffile, 0777);
836 #endif
837 free(conffile);
838 if ((conffile = get_path("config")) == NULL) {
839 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
840 } else {
841 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
842 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
843 write(conffile_fd, default_config, strlen(default_config));
844 close(conffile_fd);
846 if (m_config_parse_config_file(conf, conffile) < 0)
847 exit_player(NULL);
848 free(conffile);
853 void load_per_file_config (m_config_t* conf, const char *const file)
855 char *confpath;
856 char cfg[strlen(file)+10];
857 struct stat st;
858 char *name;
860 sprintf (cfg, "%s.conf", file);
862 if (use_filedir_conf && !stat (cfg, &st))
864 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
865 m_config_parse_config_file (conf, cfg);
866 return;
869 if ((name = strrchr (cfg, '/')) == NULL)
870 name = cfg;
871 else
872 name++;
874 if ((confpath = get_path (name)) != NULL)
876 if (!stat (confpath, &st))
878 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
879 m_config_parse_config_file (conf, confpath);
882 free (confpath);
886 /* When libmpdemux performs a blocking operation (network connection or
887 * cache filling) if the operation fails we use this function to check
888 * if it was interrupted by the user.
889 * The function returns a new value for eof. */
890 static int libmpdemux_was_interrupted(int eof) {
891 mp_cmd_t* cmd;
892 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
893 switch(cmd->id) {
894 case MP_CMD_QUIT:
895 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
896 case MP_CMD_PLAY_TREE_STEP: {
897 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
898 play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i;
899 } break;
900 case MP_CMD_PLAY_TREE_UP_STEP: {
901 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
902 } break;
903 case MP_CMD_PLAY_ALT_SRC_STEP: {
904 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
905 } break;
907 mp_cmd_free(cmd);
909 return eof;
912 #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
914 int playtree_add_playlist(play_tree_t* entry)
916 play_tree_add_bpf(entry,filename);
918 #ifdef HAVE_NEW_GUI
919 if (use_gui) {
920 if (entry) {
921 import_playtree_playlist_into_gui(entry, mconfig);
922 play_tree_free_list(entry,1);
924 } else
925 #endif
927 if(!entry) {
928 entry = playtree_iter->tree;
929 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
930 return PT_NEXT_ENTRY;
932 if(playtree_iter->tree == entry ) { // Loop with a single file
933 if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
934 return PT_NEXT_ENTRY;
937 play_tree_remove(entry,1,1);
938 return PT_NEXT_SRC;
940 play_tree_insert_entry(playtree_iter->tree,entry);
941 play_tree_set_params_from(entry,playtree_iter->tree);
942 entry = playtree_iter->tree;
943 if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
944 return PT_NEXT_ENTRY;
946 play_tree_remove(entry,1,1);
948 return PT_NEXT_SRC;
951 int sub_source(void)
953 int source = -1;
954 int top = -1;
955 int i;
956 for (i = 0; i < SUB_SOURCES; i++) {
957 int j = global_sub_indices[i];
958 if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
959 source = i;
960 top = j;
963 return source;
966 #ifdef USE_SUB
968 sub_data* subdata = NULL;
969 static subtitle* vo_sub_last = NULL;
971 void add_subtitles(char *filename, float fps, int silent)
973 sub_data *subd;
974 #ifdef USE_ASS
975 ass_track_t *asst = 0;
976 #endif
978 if (filename == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) {
979 return;
982 subd = sub_read_file(filename, fps);
983 #ifdef USE_ASS
984 if (ass_enabled)
985 #ifdef USE_ICONV
986 asst = ass_read_file(ass_library, filename, sub_cp);
987 #else
988 asst = ass_read_file(ass_library, filename, 0);
989 #endif
990 if (ass_enabled && subd && !asst)
991 asst = ass_read_subdata(ass_library, subd, fps);
993 if (!asst && !subd && !silent)
994 #else
995 if(!subd && !silent)
996 #endif
997 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
999 #ifdef USE_ASS
1000 if (!asst && !subd) return;
1001 set_of_ass_tracks[set_of_sub_size] = asst;
1002 #else
1003 if (!subd) return;
1004 #endif
1005 set_of_subtitles[set_of_sub_size] = subd;
1006 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
1007 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
1008 ++set_of_sub_size;
1009 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
1012 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
1013 void update_set_of_subtitles(void)
1014 // subdata was changed, set_of_sub... have to be updated.
1016 int i;
1017 if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
1018 for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
1019 set_of_subtitles[i-1] = set_of_subtitles[i];
1020 set_of_subtitles[set_of_sub_size-1] = NULL;
1021 --set_of_sub_size;
1022 if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
1024 else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
1025 set_of_subtitles[set_of_sub_pos] = subdata;
1027 else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
1028 set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
1029 ++set_of_sub_size;
1032 #endif /* USE_SUB */
1035 * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
1036 * make it all work is to use the builtin SDL-bootstrap code, which
1037 * will be done automatically by replacing our main() if we include SDL.h.
1039 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
1040 #include <SDL.h>
1041 #endif
1044 * \brief append a formatted string
1045 * \param buf buffer to print into
1046 * \param pos position of terminating 0 in buf
1047 * \param len maximum number of characters in buf, not including terminating 0
1048 * \param format printf format string
1050 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
1052 va_list va;
1053 va_start(va, format);
1054 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
1055 va_end(va);
1056 if (*pos >= len ) {
1057 buf[len] = 0;
1058 *pos = len;
1063 * \brief append time in the hh:mm:ss.f format
1064 * \param buf buffer to print into
1065 * \param pos position of terminating 0 in buf
1066 * \param len maximum number of characters in buf, not including terminating 0
1067 * \param time time value to convert/append
1069 static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) {
1070 long tenths = 10 * time;
1071 int f1 = tenths % 10;
1072 int ss = (tenths / 10) % 60;
1073 int mm = (tenths / 600) % 60;
1074 int hh = tenths / 36000;
1075 if (time <= 0) {
1076 saddf(buf, pos, len, "unknown");
1077 return;
1079 if (hh > 0)
1080 saddf(buf, pos, len, "%2d:", hh);
1081 if (hh > 0 || mm > 0)
1082 saddf(buf, pos, len, "%02d:", mm);
1083 saddf(buf, pos, len, "%02d.%1d", ss, f1);
1087 * \brief print the status line
1088 * \param a_pos audio position
1089 * \param a_v A-V desynchronization
1090 * \param corr amount out A-V synchronization
1092 static void print_status(float a_pos, float a_v, float corr)
1094 int width;
1095 char *line;
1096 unsigned pos = 0;
1097 get_screen_size();
1098 if (screen_width > 0)
1099 width = screen_width;
1100 else
1101 width = 80;
1102 #ifdef WIN32
1103 /* Windows command line is broken (MinGW's rxvt works, but we
1104 * should not depend on that). */
1105 width--;
1106 #endif
1107 line = malloc(width + 1); // one additional char for the terminating null
1109 // Audio time
1110 if (sh_audio) {
1111 saddf(line, &pos, width, "A:%6.1f ", a_pos);
1112 if (!sh_video) {
1113 float len = demuxer_get_time_length(demuxer);
1114 saddf(line, &pos, width, "(");
1115 sadd_hhmmssf(line, &pos, width, a_pos);
1116 saddf(line, &pos, width, ") of %.1f (", len);
1117 sadd_hhmmssf(line, &pos, width, len);
1118 saddf(line, &pos, width, ") ");
1122 // Video time
1123 if (sh_video)
1124 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
1126 // A-V sync
1127 if (sh_audio && sh_video)
1128 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
1130 // Video stats
1131 if (sh_video)
1132 saddf(line, &pos, width, "%3d/%3d ",
1133 (int)sh_video->num_frames,
1134 (int)sh_video->num_frames_decoded);
1136 // CPU usage
1137 if (sh_video) {
1138 if (sh_video->timer > 0.5)
1139 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
1140 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
1141 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
1142 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
1143 else
1144 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
1145 } else if (sh_audio) {
1146 if (sh_audio->delay > 0.5)
1147 saddf(line, &pos, width, "%4.1f%% ",
1148 100.0*audio_time_usage/(double)sh_audio->delay);
1149 else
1150 saddf(line, &pos, width, "??,?%% ");
1153 // VO stats
1154 if (sh_video)
1155 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
1157 #ifdef USE_STREAM_CACHE
1158 // cache stats
1159 if (stream_cache_size > 0)
1160 saddf(line, &pos, width, "%d%% ", cache_fill_status);
1161 #endif
1163 // other
1164 if (playback_speed != 1)
1165 saddf(line, &pos, width, "%4.2fx ", playback_speed);
1167 // end
1168 if (erase_to_end_of_line) {
1169 line[pos] = 0;
1170 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s%s\r", line, erase_to_end_of_line);
1171 } else {
1172 memset(&line[pos], ' ', width - pos);
1173 line[width] = 0;
1174 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
1176 free(line);
1180 * \brief build a chain of audio filters that converts the input format
1181 * to the ao's format, taking into account the current playback_speed.
1182 * \param sh_audio describes the requested input format of the chain.
1183 * \param ao_data describes the requested output format of the chain.
1185 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
1187 int new_srate;
1188 int result;
1189 if (!sh_audio)
1191 #ifdef HAVE_NEW_GUI
1192 guiGetEvent(guiSetAfilter, (char *)NULL);
1193 #endif
1194 mixer.afilter = NULL;
1195 return 0;
1197 new_srate = sh_audio->samplerate * playback_speed;
1198 if (new_srate != ao_data->samplerate) {
1199 // limits are taken from libaf/af_resample.c
1200 if (new_srate < 8000)
1201 new_srate = 8000;
1202 if (new_srate > 192000)
1203 new_srate = 192000;
1204 playback_speed = (float)new_srate / (float)sh_audio->samplerate;
1206 result = init_audio_filters(sh_audio, new_srate,
1207 sh_audio->channels, sh_audio->sample_format,
1208 &ao_data->samplerate, &ao_data->channels, &ao_data->format,
1209 ao_data->outburst * 4, ao_data->buffersize);
1210 mixer.afilter = sh_audio->afilter;
1211 #ifdef HAVE_NEW_GUI
1212 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter);
1213 #endif
1214 return result;
1217 #ifdef USE_SUB
1219 * \brief Log the currently displayed subtitle to a file
1221 * Logs the current or last displayed subtitle together with filename
1222 * and time information to ~/.mplayer/subtitle_log
1224 * Intended purpose is to allow convenient marking of bogus subtitles
1225 * which need to be fixed while watching the movie.
1228 static void log_sub(void){
1229 char *fname;
1230 FILE *f;
1231 int i;
1233 if (subdata == NULL || vo_sub_last == NULL) return;
1234 fname = get_path("subtitle_log");
1235 f = fopen(fname, "a");
1236 if (!f) return;
1237 fprintf(f, "----------------------------------------------------------\n");
1238 if (subdata->sub_uses_time) {
1239 fprintf(f, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename,
1240 vo_sub_last->start/360000, (vo_sub_last->start/6000)%60,
1241 (vo_sub_last->start/100)%60, vo_sub_last->start%100,
1242 vo_sub_last->end/360000, (vo_sub_last->end/6000)%60,
1243 (vo_sub_last->end/100)%60, vo_sub_last->end%100);
1244 } else {
1245 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start, vo_sub_last->end);
1247 for (i = 0; i < vo_sub_last->lines; i++) {
1248 fprintf(f, "%s\n", vo_sub_last->text[i]);
1250 fclose(f);
1252 #endif /* USE_SUB */
1254 /// \defgroup OSDMsgStack OSD message stack
1256 ///@{
1258 #define OSD_MSG_TV_CHANNEL 0
1259 #define OSD_MSG_TEXT 1
1260 #define OSD_MSG_SUB_DELAY 2
1261 #define OSD_MSG_SPEED 3
1262 #define OSD_MSG_OSD_STATUS 4
1263 #define OSD_MSG_BAR 5
1264 #define OSD_MSG_PAUSE 6
1265 #define OSD_MSG_RADIO_CHANNEL 7
1266 /// Base id for messages generated from the commmand to property bridge.
1267 #define OSD_MSG_PROPERTY 0x100
1270 typedef struct mp_osd_msg mp_osd_msg_t;
1271 struct mp_osd_msg {
1272 /// Previous message on the stack.
1273 mp_osd_msg_t* prev;
1274 /// Message text.
1275 char msg[64];
1276 int id,level,started;
1277 /// Display duration in ms.
1278 unsigned time;
1281 /// OSD message stack.
1282 static mp_osd_msg_t* osd_msg_stack = NULL;
1285 * \brief Add a message on the OSD message stack
1287 * If a message with the same id is already present in the stack
1288 * it is pulled on top of the stack, otherwise a new message is created.
1292 static void set_osd_msg(int id, int level, int time, const char* fmt, ...) {
1293 mp_osd_msg_t *msg,*last=NULL;
1294 va_list va;
1295 int r;
1297 // look if the id is already in the stack
1298 for(msg = osd_msg_stack ; msg && msg->id != id ;
1299 last = msg, msg = msg->prev);
1300 // not found: alloc it
1301 if(!msg) {
1302 msg = calloc(1,sizeof(mp_osd_msg_t));
1303 msg->prev = osd_msg_stack;
1304 osd_msg_stack = msg;
1305 } else if(last) { // found, but it's not on top of the stack
1306 last->prev = msg->prev;
1307 msg->prev = osd_msg_stack;
1308 osd_msg_stack = msg;
1310 // write the msg
1311 va_start(va,fmt);
1312 r = vsnprintf(msg->msg, 64, fmt, va);
1313 va_end(va);
1314 if(r >= 64) msg->msg[63] = 0;
1315 // set id and time
1316 msg->id = id;
1317 msg->level = level;
1318 msg->time = time;
1323 * \brief Remove a message from the OSD stack
1325 * This function can be used to get rid of a message right away.
1329 static void rm_osd_msg(int id) {
1330 mp_osd_msg_t *msg,*last=NULL;
1332 // Search for the msg
1333 for(msg = osd_msg_stack ; msg && msg->id != id ;
1334 last = msg, msg = msg->prev);
1335 if(!msg) return;
1337 // Detach it from the stack and free it
1338 if(last)
1339 last->prev = msg->prev;
1340 else
1341 osd_msg_stack = msg->prev;
1342 free(msg);
1346 * \brief Remove all messages from the OSD stack
1350 static void clear_osd_msgs(void) {
1351 mp_osd_msg_t* msg = osd_msg_stack, *prev = NULL;
1352 while(msg) {
1353 prev = msg->prev;
1354 free(msg);
1355 msg = prev;
1357 osd_msg_stack = NULL;
1361 * \brief Get the current message from the OSD stack.
1363 * This function decrements the message timer and destroys the old ones.
1364 * The message that should be displayed is returned (if any).
1368 static mp_osd_msg_t* get_osd_msg(void) {
1369 mp_osd_msg_t *msg,*prev,*last = NULL;
1370 static unsigned last_update = 0;
1371 unsigned now = GetTimerMS();
1372 unsigned diff;
1373 char hidden_dec_done = 0;
1375 if(!last_update) last_update = now;
1376 diff = now >= last_update ? now - last_update : 0;
1378 last_update = now;
1380 // Look for the first message in the stack with high enough level.
1381 for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) {
1382 prev = msg->prev;
1383 if(msg->level > osd_level && hidden_dec_done) continue;
1384 // The message has a high enough level or it is the first hidden one
1385 // in both cases we decrement the timer or kill it.
1386 if(!msg->started || msg->time > diff) {
1387 if(msg->started) msg->time -= diff;
1388 else msg->started = 1;
1389 // display it
1390 if(msg->level <= osd_level) return msg;
1391 hidden_dec_done = 1;
1392 continue;
1394 // kill the message
1395 free(msg);
1396 if(last) {
1397 last->prev = prev;
1398 msg = last;
1399 } else {
1400 osd_msg_stack = prev;
1401 msg = NULL;
1404 // Nothing found
1405 return NULL;
1408 // Make a define to test if we are using the term OSD without having
1409 // to #ifdef USE_OSD all the time.
1410 #ifdef USE_OSD
1411 #define use_term_osd (term_osd && !sh_video)
1412 #else
1413 #define use_term_osd (term_osd)
1414 #endif
1417 * \brief Display the OSD bar.
1419 * Display the OSD bar or fall back on a simple message.
1423 void set_osd_bar(int type,const char* name,double min,double max,double val) {
1425 if(osd_level < 1) return;
1427 #ifdef USE_OSD
1428 if(sh_video) {
1429 osd_visible = (GetTimerMS() + 1000) | 1;
1430 vo_osd_progbar_type = type;
1431 vo_osd_progbar_value = 256*(val-min)/(max-min);
1432 vo_osd_changed(OSDTYPE_PROGBAR);
1433 return;
1435 #endif
1437 set_osd_msg(OSD_MSG_BAR,1,osd_duration,"%s: %d %%",
1438 name,ROUND(100*(val-min)/(max-min)));
1443 * \brief Update the OSD message line.
1445 * This function displays the current message on the vo OSD or on the term.
1446 * If the stack is empty and the OSD level is high enough the timer
1447 * is displayed (only on the vo OSD).
1451 static void update_osd_msg(void) {
1452 mp_osd_msg_t *msg;
1453 static char osd_text[64] = "";
1454 static char osd_text_timer[64];
1456 #ifdef USE_OSD
1457 // we need some mem for vo_osd_text
1458 vo_osd_text = (unsigned char*)osd_text;
1459 #endif
1461 // Look if we have a msg
1462 if((msg = get_osd_msg())) {
1463 if(strcmp(osd_text,msg->msg)) {
1464 strncpy((char*)osd_text, msg->msg, 63);
1465 #ifdef USE_OSD
1466 if(sh_video) vo_osd_changed(OSDTYPE_OSD); else
1467 #endif
1468 if(term_osd) mp_msg(MSGT_CPLAYER,MSGL_STATUS,"%s%s\n",term_osd_esc,msg->msg);
1470 return;
1473 #ifdef USE_OSD
1474 if(sh_video) {
1475 // fallback on the timer
1476 if(osd_level>=2) {
1477 int len = demuxer_get_time_length(demuxer);
1478 int percentage = -1;
1479 char percentage_text[10];
1480 int pts = demuxer_get_current_time(demuxer);
1482 if (osd_show_percentage)
1483 percentage = demuxer_get_percent_pos(demuxer);
1485 if (percentage >= 0)
1486 snprintf(percentage_text, 9, " (%d%%)", percentage);
1487 else
1488 percentage_text[0] = 0;
1490 if (osd_level == 3)
1491 snprintf(osd_text_timer, 63,
1492 "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
1493 osd_function,pts/3600,(pts/60)%60,pts%60,
1494 len/3600,(len/60)%60,len%60,percentage_text);
1495 else
1496 snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s",
1497 osd_function,pts/3600,(pts/60)%60,
1498 pts%60,percentage_text);
1499 } else
1500 osd_text_timer[0]=0;
1502 // always decrement the percentage timer
1503 if(osd_show_percentage)
1504 osd_show_percentage--;
1506 if(strcmp(osd_text,osd_text_timer)) {
1507 strncpy(osd_text, osd_text_timer, 63);
1508 vo_osd_changed(OSDTYPE_OSD);
1510 return;
1512 #endif
1514 // Clear the term osd line
1515 if(term_osd && osd_text[0]) {
1516 osd_text[0] = 0;
1517 printf("%s\n",term_osd_esc);
1521 ///@}
1522 // OSDMsgStack
1524 /// \defgroup Properties
1525 ///@{
1527 /// \defgroup GeneralProperties General properties
1528 /// \ingroup Properties
1529 ///@{
1531 /// OSD level (RW)
1532 static int mp_property_osdlevel(m_option_t* prop,int action,void* arg) {
1533 return m_property_choice(prop,action,arg,&osd_level);
1536 /// Playback speed (RW)
1537 static int mp_property_playback_speed(m_option_t* prop,int action,void* arg) {
1538 switch(action) {
1539 case M_PROPERTY_SET:
1540 if(!arg) return 0;
1541 M_PROPERTY_CLAMP(prop,*(float*)arg);
1542 playback_speed = *(float*)arg;
1543 build_afilter_chain(sh_audio, &ao_data);
1544 return 1;
1545 case M_PROPERTY_STEP_UP:
1546 case M_PROPERTY_STEP_DOWN:
1547 playback_speed += (arg ? *(float*)arg : 0.1) *
1548 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1549 M_PROPERTY_CLAMP(prop,playback_speed);
1550 build_afilter_chain(sh_audio, &ao_data);
1551 return 1;
1553 return m_property_float_range(prop,action,arg,&playback_speed);
1556 /// filename with path (RO)
1557 static int mp_property_path(m_option_t* prop,int action,void* arg) {
1558 return m_property_string_ro(prop,action,arg,filename);
1561 /// filename without path (RO)
1562 static int mp_property_filename(m_option_t* prop,int action,void* arg) {
1563 char* f;
1564 if(!filename) return M_PROPERTY_UNAVAILABLE;
1565 if(((f = strrchr(filename,'/')) || (f = strrchr(filename,'\\'))) && f[1])
1566 f++;
1567 else
1568 f = filename;
1569 return m_property_string_ro(prop,action,arg,f);
1572 /// Demuxer name (RO)
1573 static int mp_property_demuxer(m_option_t* prop,int action,void* arg) {
1574 if(!demuxer) return M_PROPERTY_UNAVAILABLE;
1575 return m_property_string_ro(prop,action,arg,(char*)demuxer->desc->name);
1578 /// Position in the stream (RW)
1579 static int mp_property_stream_pos(m_option_t* prop,int action,void* arg) {
1580 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1581 if (!arg) return M_PROPERTY_ERROR;
1582 switch (action) {
1583 case M_PROPERTY_GET:
1584 *(off_t*)arg = stream_tell(demuxer->stream);
1585 return M_PROPERTY_OK;
1586 case M_PROPERTY_SET:
1587 M_PROPERTY_CLAMP(prop,*(off_t*)arg);
1588 stream_seek(demuxer->stream, *(off_t*)arg);
1589 return M_PROPERTY_OK;
1591 return M_PROPERTY_NOT_IMPLEMENTED;
1594 /// Stream start offset (RO)
1595 static int mp_property_stream_start(m_option_t* prop,int action,void* arg) {
1596 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1597 switch (action) {
1598 case M_PROPERTY_GET:
1599 *(off_t*)arg = demuxer->stream->start_pos;
1600 return M_PROPERTY_OK;
1602 return M_PROPERTY_NOT_IMPLEMENTED;
1605 /// Stream end offset (RO)
1606 static int mp_property_stream_end(m_option_t* prop,int action,void* arg) {
1607 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1608 switch (action) {
1609 case M_PROPERTY_GET:
1610 *(off_t*)arg = demuxer->stream->end_pos;
1611 return M_PROPERTY_OK;
1613 return M_PROPERTY_NOT_IMPLEMENTED;
1616 /// Stream length (RO)
1617 static int mp_property_stream_length(m_option_t* prop,int action,void* arg) {
1618 if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE;
1619 switch (action) {
1620 case M_PROPERTY_GET:
1621 *(off_t*)arg = demuxer->stream->end_pos - demuxer->stream->start_pos;
1622 return M_PROPERTY_OK;
1624 return M_PROPERTY_NOT_IMPLEMENTED;
1627 /// Media length in seconds (RO)
1628 static int mp_property_length(m_option_t* prop,int action,void* arg) {
1629 double len;
1631 if(!demuxer ||
1632 !(int)(len = demuxer_get_time_length(demuxer)))
1633 return M_PROPERTY_UNAVAILABLE;
1635 switch(action) {
1636 case M_PROPERTY_PRINT:
1637 if(!arg) return 0;
1638 else {
1639 int h, m, s = len;
1640 h = s/3600;
1641 s -= h*3600;
1642 m = s/60;
1643 s -= m*60;
1644 *(char**)arg = malloc(20);
1645 if(h > 0) sprintf(*(char**)arg,"%d:%02d:%02d",h,m,s);
1646 else if(m > 0) sprintf(*(char**)arg,"%d:%02d",m,s);
1647 else sprintf(*(char**)arg,"%d",s);
1648 return 1;
1650 break;
1652 return m_property_double_ro(prop,action,arg,len);
1655 ///@}
1657 /// \defgroup AudioProperties Audio properties
1658 /// \ingroup Properties
1659 ///@{
1661 /// Volume (RW)
1662 static int mp_property_volume(m_option_t* prop,int action,void* arg) {
1664 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1666 switch(action) {
1667 case M_PROPERTY_GET:
1668 if(!arg) return 0;
1669 mixer_getbothvolume(&mixer,arg);
1670 return 1;
1671 case M_PROPERTY_PRINT:{
1672 float vol;
1673 if(!arg) return 0;
1674 mixer_getbothvolume(&mixer,&vol);
1675 return m_property_float_range(prop,action,arg,&vol);
1677 case M_PROPERTY_STEP_UP:
1678 case M_PROPERTY_STEP_DOWN:
1679 case M_PROPERTY_SET:
1680 break;
1681 default:
1682 return M_PROPERTY_NOT_IMPLEMENTED;
1685 if (edl_muted) return M_PROPERTY_DISABLED;
1686 user_muted = 0;
1688 switch(action) {
1689 case M_PROPERTY_SET:
1690 if(!arg) return 0;
1691 M_PROPERTY_CLAMP(prop,*(float*)arg);
1692 mixer_setvolume(&mixer,*(float*)arg,*(float*)arg);
1693 return 1;
1694 case M_PROPERTY_STEP_UP:
1695 if(arg && *(float*)arg <= 0)
1696 mixer_decvolume(&mixer);
1697 else
1698 mixer_incvolume(&mixer);
1699 return 1;
1700 case M_PROPERTY_STEP_DOWN:
1701 if(arg && *(float*)arg <= 0)
1702 mixer_incvolume(&mixer);
1703 else
1704 mixer_decvolume(&mixer);
1705 return 1;
1707 return M_PROPERTY_NOT_IMPLEMENTED;
1710 /// Mute (RW)
1711 static int mp_property_mute(m_option_t* prop,int action,void* arg) {
1713 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1715 switch(action) {
1716 case M_PROPERTY_SET:
1717 if(edl_muted) return M_PROPERTY_DISABLED;
1718 if(!arg) return 0;
1719 if((!!*(int*)arg) != mixer.muted)
1720 mixer_mute(&mixer);
1721 user_muted = mixer.muted;
1722 return 1;
1723 case M_PROPERTY_STEP_UP:
1724 case M_PROPERTY_STEP_DOWN:
1725 if(edl_muted) return M_PROPERTY_DISABLED;
1726 mixer_mute(&mixer);
1727 user_muted = mixer.muted;
1728 return 1;
1729 case M_PROPERTY_PRINT:
1730 if(!arg) return 0;
1731 if(edl_muted) {
1732 *(char**)arg = strdup(MSGTR_EnabledEdl);
1733 return 1;
1735 default:
1736 return m_property_flag(prop,action,arg,&mixer.muted);
1741 /// Audio delay (RW)
1742 static int mp_property_audio_delay(m_option_t* prop,int action,void* arg) {
1743 if(!(sh_audio && sh_video)) return M_PROPERTY_UNAVAILABLE;
1744 switch(action) {
1745 case M_PROPERTY_SET:
1746 case M_PROPERTY_STEP_UP:
1747 case M_PROPERTY_STEP_DOWN:
1748 if(!arg) return 0;
1749 else {
1750 float delay = audio_delay;
1751 m_property_delay(prop,action,arg,&audio_delay);
1752 if(sh_audio) sh_audio->delay -= audio_delay-delay;
1754 return 1;
1755 default:
1756 return m_property_delay(prop,action,arg,&audio_delay);
1760 /// Audio codec tag (RO)
1761 static int mp_property_audio_format(m_option_t* prop,int action,void* arg) {
1762 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1763 return m_property_int_ro(prop,action,arg,sh_audio->format);
1766 /// Audio bitrate (RO)
1767 static int mp_property_audio_bitrate(m_option_t* prop,int action,void* arg) {
1768 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1769 return m_property_int_ro(prop,action,arg,sh_audio->i_bps);
1772 /// Samplerate (RO)
1773 static int mp_property_samplerate(m_option_t* prop,int action,void* arg) {
1774 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1775 return m_property_int_ro(prop,action,arg,sh_audio->samplerate);
1778 /// Number of channels (RO)
1779 static int mp_property_channels(m_option_t* prop,int action,void* arg) {
1780 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1781 switch(action) {
1782 case M_PROPERTY_PRINT:
1783 if(!arg) return 0;
1784 switch(sh_audio->channels) {
1785 case 1: *(char**)arg = strdup("mono"); break;
1786 case 2: *(char**)arg = strdup("stereo"); break;
1787 default:
1788 *(char**)arg = malloc(32);
1789 sprintf(*(char**)arg,"%d channels",sh_audio->channels);
1791 return 1;
1793 return m_property_int_ro(prop,action,arg,sh_audio->channels);
1796 /// Selected audio id (RW)
1797 static int mp_property_audio(m_option_t* prop,int action,void* arg) {
1798 int current_id = -1;
1800 if(!sh_audio) return M_PROPERTY_UNAVAILABLE;
1802 switch(action) {
1803 case M_PROPERTY_GET:
1804 if(!arg) return 0;
1805 *(int*)arg = audio_id;
1806 return 1;
1807 case M_PROPERTY_PRINT:
1808 if(!arg) return 0;
1810 if (audio_id < 0)
1811 *(char**)arg = strdup(MSGTR_Disabled);
1812 else {
1813 char lang[40] = MSGTR_Unknown;
1814 if (demuxer->type == DEMUXER_TYPE_MATROSKA)
1815 demux_mkv_get_audio_lang(demuxer, audio_id, lang, 9);
1816 #ifdef USE_DVDREAD
1817 else {
1818 int code = dvd_lang_from_aid(stream, audio_id);
1819 if (code) {
1820 lang[0] = code >> 8;
1821 lang[1] = code;
1822 lang[2] = 0;
1825 #endif
1826 *(char**)arg = malloc(64);
1827 snprintf(*(char**)arg, 64, "(%d) %s", audio_id, lang);
1829 return 1;
1831 case M_PROPERTY_STEP_UP:
1832 current_id = demuxer->audio->id;
1833 audio_id = demuxer_switch_audio(demuxer, -1);
1834 if(audio_id > -1 && demuxer->audio->id != current_id) {
1835 sh_audio_t *sh2;
1836 uninit_player(INITED_AO | INITED_ACODEC);
1837 sh2 = demuxer->a_streams[demuxer->audio->id];
1838 if(sh2) {
1839 sh2->ds = demuxer->audio;
1840 sh_audio = sh2;
1841 reinit_audio_chain();
1844 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
1846 break;
1847 default:
1848 return M_PROPERTY_NOT_IMPLEMENTED;
1851 return 1;
1854 ///@}
1856 /// \defgroup VideoProperties Video properties
1857 /// \ingroup Properties
1858 ///@{
1860 /// Fullscreen state (RW)
1861 static int mp_property_fullscreen(m_option_t* prop,int action,void* arg) {
1863 if(!video_out) return M_PROPERTY_UNAVAILABLE;
1865 switch(action) {
1866 case M_PROPERTY_SET:
1867 if(!arg) return 0;
1868 M_PROPERTY_CLAMP(prop,*(int*)arg);
1869 if(vo_fs == !!*(int*)arg) return 1;
1870 case M_PROPERTY_STEP_UP:
1871 case M_PROPERTY_STEP_DOWN:
1872 #ifdef HAVE_NEW_GUI
1873 if(use_gui) guiGetEvent(guiIEvent,(char*)MP_CMD_GUI_FULLSCREEN);
1874 else
1875 #endif
1876 if(vo_config_count) video_out->control(VOCTRL_FULLSCREEN, 0);
1877 return 1;
1878 default:
1879 return m_property_flag(prop,action,arg,&vo_fs);
1883 /// Panscan (RW)
1884 static int mp_property_panscan(m_option_t* prop,int action,void* arg) {
1886 if(!video_out || video_out->control(VOCTRL_GET_PANSCAN,NULL ) != VO_TRUE)
1887 return M_PROPERTY_UNAVAILABLE;
1889 switch(action) {
1890 case M_PROPERTY_SET:
1891 if(!arg) return 0;
1892 M_PROPERTY_CLAMP(prop,*(float*)arg);
1893 vo_panscan = *(float*)arg;
1894 video_out->control(VOCTRL_SET_PANSCAN,NULL);
1895 return 1;
1896 case M_PROPERTY_STEP_UP:
1897 case M_PROPERTY_STEP_DOWN:
1898 vo_panscan += (arg ? *(float*)arg : 0.1) *
1899 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1900 if(vo_panscan > 1) vo_panscan = 1;
1901 else if(vo_panscan < 0) vo_panscan = 0;
1902 video_out->control(VOCTRL_SET_PANSCAN,NULL);
1903 return 1;
1904 default:
1905 return m_property_float_range(prop,action,arg,&vo_panscan);
1909 /// Helper to set vo flags.
1910 /** \ingroup PropertyImplHelper
1912 static int mp_property_vo_flag(m_option_t* prop,int action,void* arg,
1913 int vo_ctrl,int* vo_var) {
1915 if(!video_out) return M_PROPERTY_UNAVAILABLE;
1917 switch(action) {
1918 case M_PROPERTY_SET:
1919 if(!arg) return 0;
1920 M_PROPERTY_CLAMP(prop,*(int*)arg);
1921 if(*vo_var == !!*(int*)arg) return 1;
1922 case M_PROPERTY_STEP_UP:
1923 case M_PROPERTY_STEP_DOWN:
1924 if(vo_config_count) video_out->control(vo_ctrl, 0);
1925 return 1;
1926 default:
1927 return m_property_flag(prop,action,arg,vo_var);
1931 /// Window always on top (RW)
1932 static int mp_property_ontop(m_option_t* prop,int action,void* arg) {
1933 return mp_property_vo_flag(prop,action,arg,VOCTRL_ONTOP,&vo_ontop);
1936 /// Display in the root window (RW)
1937 static int mp_property_rootwin(m_option_t* prop,int action,void* arg) {
1938 return mp_property_vo_flag(prop,action,arg,VOCTRL_ROOTWIN,&vo_rootwin);
1941 /// Show window borders (RW)
1942 static int mp_property_border(m_option_t* prop,int action,void* arg) {
1943 return mp_property_vo_flag(prop,action,arg,VOCTRL_BORDER,&vo_border);
1946 /// Framedropping state (RW)
1947 static int mp_property_framedropping(m_option_t* prop,int action,void* arg) {
1949 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1951 switch(action) {
1952 case M_PROPERTY_PRINT:
1953 if(!arg) return 0;
1954 *(char**)arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1955 (frame_dropping == 2 ? MSGTR_HardFrameDrop : MSGTR_Disabled));
1956 return 1;
1957 default:
1958 return m_property_choice(prop,action,arg,&frame_dropping);
1962 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1963 static int mp_property_gamma(m_option_t* prop,int action,void* arg) {
1964 int* gamma = prop->priv, r;
1966 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1968 if(gamma[0] == 1000) {
1969 gamma[0] = 0;
1970 get_video_colors (sh_video, prop->name, gamma);
1973 switch(action) {
1974 case M_PROPERTY_SET:
1975 if(!arg) return 0;
1976 M_PROPERTY_CLAMP(prop,*(int*)arg);
1977 *gamma = *(int*)arg;
1978 r = set_video_colors(sh_video, prop->name, *gamma);
1979 if(r <= 0) break;
1980 return r;
1981 case M_PROPERTY_GET:
1982 if(!arg) return 0;
1983 r = get_video_colors (sh_video, prop->name, arg);
1984 if(r <= 0) break;
1985 return r;
1986 case M_PROPERTY_STEP_UP:
1987 case M_PROPERTY_STEP_DOWN:
1988 *gamma += (arg ? *(int*)arg : 1) *
1989 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1990 M_PROPERTY_CLAMP(prop,*gamma);
1991 r = set_video_colors(sh_video, prop->name, *gamma);
1992 if(r <= 0) break;
1993 return r;
1994 default:
1995 return M_PROPERTY_NOT_IMPLEMENTED;
1998 #ifdef USE_TV
1999 if(demuxer->type == DEMUXER_TYPE_TV) {
2000 int l = strlen(prop->name);
2001 char tv_prop[3+l+1];
2002 sprintf(tv_prop,"tv_%s",prop->name);
2003 return mp_property_do(tv_prop,action,arg);
2005 #endif
2007 return M_PROPERTY_UNAVAILABLE;
2010 /// VSync (RW)
2011 static int mp_property_vsync(m_option_t* prop,int action,void* arg) {
2012 return m_property_flag(prop,action,arg,&vo_vsync);
2015 /// Video codec tag (RO)
2016 static int mp_property_video_format(m_option_t* prop,int action,void* arg) {
2017 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2018 return m_property_int_ro(prop,action,arg,sh_video->format);
2021 /// Video bitrate (RO)
2022 static int mp_property_video_bitrate(m_option_t* prop,int action,void* arg) {
2023 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2024 return m_property_int_ro(prop,action,arg,sh_video->i_bps);
2027 /// Video display width (RO)
2028 static int mp_property_width(m_option_t* prop,int action,void* arg) {
2029 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2030 return m_property_int_ro(prop,action,arg,sh_video->disp_w);
2033 /// Video display height (RO)
2034 static int mp_property_height(m_option_t* prop,int action,void* arg) {
2035 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2036 return m_property_int_ro(prop,action,arg,sh_video->disp_h);
2039 /// Video fps (RO)
2040 static int mp_property_fps(m_option_t* prop,int action,void* arg) {
2041 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2042 return m_property_float_ro(prop,action,arg,sh_video->fps);
2045 /// Video aspect (RO)
2046 static int mp_property_aspect(m_option_t* prop,int action,void* arg) {
2047 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2048 return m_property_float_ro(prop,action,arg,sh_video->aspect);
2051 ///@}
2053 /// \defgroup SubProprties Subtitles properties
2054 /// \ingroup Properties
2055 ///@{
2057 /// Text subtitle position (RW)
2058 static int mp_property_sub_pos(m_option_t* prop,int action,void* arg) {
2059 #ifdef USE_SUB
2060 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2062 switch(action) {
2063 case M_PROPERTY_SET:
2064 if(!arg) return 0;
2065 case M_PROPERTY_STEP_UP:
2066 case M_PROPERTY_STEP_DOWN:
2067 vo_osd_changed(OSDTYPE_SUBTITLE);
2068 default:
2069 return m_property_int_range(prop,action,arg,&sub_pos);
2071 #else
2072 return M_PROPERTY_UNAVAILABLE;
2073 #endif
2076 /// Selected subtitles (RW)
2077 static int mp_property_sub(m_option_t* prop,int action,void* arg) {
2078 int source = -1, reset_spu = 0;
2079 char* sub_name;
2081 if(global_sub_size <= 0) return M_PROPERTY_UNAVAILABLE;
2083 switch(action) {
2084 case M_PROPERTY_GET:
2085 if(!arg) return 0;
2086 *(int*)arg = global_sub_pos;
2087 return 1;
2088 case M_PROPERTY_PRINT:
2089 if(!arg) return 0;
2090 *(char**)arg = malloc(64);
2091 (*(char**)arg)[63] = 0;
2092 sub_name = 0;
2093 #ifdef USE_SUB
2094 if(subdata)
2095 sub_name = subdata->filename;
2096 #endif
2097 #ifdef USE_ASS
2098 if (ass_track && ass_track->name)
2099 sub_name = ass_track->name;
2100 #endif
2101 #if defined(USE_SUB) || defined(USE_ASS)
2102 if(sub_name) {
2103 char *tmp,*tmp2;
2104 tmp = sub_name;
2105 if ((tmp2 = strrchr(tmp, '/')))
2106 tmp = tmp2+1;
2108 snprintf(*(char**)arg, 63, "(%d) %s%s",
2109 set_of_sub_pos + 1,
2110 strlen(tmp) < 20 ? "" : "...",
2111 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
2112 return 1;
2114 #endif
2115 if (demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
2116 char lang[40] = MSGTR_Unknown;
2117 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
2118 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, lang);
2119 return 1;
2121 #ifdef HAVE_OGGVORBIS
2122 if (demuxer->type == DEMUXER_TYPE_OGG && d_dvdsub && dvdsub_id >= 0) {
2123 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
2124 if (!lang) lang = MSGTR_Unknown;
2125 snprintf(*(char**)arg, 63, "(%d) %s",
2126 dvdsub_id, lang);
2127 return 1;
2129 #endif
2130 if (vo_vobsub && vobsub_id >= 0) {
2131 const char *language = MSGTR_Unknown;
2132 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
2133 snprintf(*(char**)arg, 63, "(%d) %s",
2134 vobsub_id, language ? language : MSGTR_Unknown);
2135 return 1;
2137 #ifdef USE_DVDREAD
2138 if (vo_spudec && dvdsub_id >= 0) {
2139 char lang[3];
2140 int code = dvd_lang_from_sid(stream, dvdsub_id);
2141 lang[0] = code >> 8;
2142 lang[1] = code;
2143 lang[2] = 0;
2144 snprintf(*(char**)arg, 63, "(%d) %s",
2145 dvdsub_id, lang);
2146 return 1;
2148 #endif
2149 snprintf(*(char**)arg, 63, MSGTR_Disabled);
2150 return 1;
2152 case M_PROPERTY_SET:
2153 if(!arg) return 0;
2154 if(*(int*)arg < -1) *(int*)arg = -1;
2155 else if(*(int*)arg >= global_sub_size) *(int*)arg = global_sub_size-1;
2156 global_sub_pos = *(int*)arg;
2157 break;
2158 case M_PROPERTY_STEP_UP:
2159 global_sub_pos += 2;
2160 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
2161 break;
2162 case M_PROPERTY_STEP_DOWN:
2163 global_sub_pos += global_sub_size+1;
2164 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
2165 break;
2166 default:
2167 return M_PROPERTY_NOT_IMPLEMENTED;
2170 if (global_sub_pos >= 0)
2171 source = sub_source();
2173 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
2174 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
2175 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
2176 global_sub_indices[SUB_SOURCE_SUBS],
2177 global_sub_indices[SUB_SOURCE_DEMUX],
2178 global_sub_pos, source);
2180 #ifdef USE_SUB
2181 set_of_sub_pos = -1;
2182 subdata = NULL;
2183 vo_sub_last = vo_sub = NULL;
2184 #endif
2185 vobsub_id = -1;
2186 dvdsub_id = -1;
2187 if (d_dvdsub) {
2188 if(d_dvdsub->id > -2) reset_spu = 1;
2189 d_dvdsub->id = -2;
2191 #ifdef USE_ASS
2192 ass_track = 0;
2193 #endif
2195 if (source == SUB_SOURCE_VOBSUB) {
2196 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
2197 #ifdef USE_SUB
2198 } else if (source == SUB_SOURCE_SUBS) {
2199 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
2200 #ifdef USE_ASS
2201 if (ass_enabled && set_of_ass_tracks[set_of_sub_pos])
2202 ass_track = set_of_ass_tracks[set_of_sub_pos];
2203 else
2204 #endif
2206 subdata = set_of_subtitles[set_of_sub_pos];
2207 vo_osd_changed(OSDTYPE_SUBTITLE);
2209 #endif
2210 } else if (source == SUB_SOURCE_DEMUX) {
2211 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
2212 if (d_dvdsub) {
2213 #ifdef USE_DVDREAD
2214 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
2215 d_dvdsub->id = dvdsub_id;
2216 spudec_reset(vo_spudec);
2218 #endif
2219 #ifdef HAVE_OGGVORBIS
2220 if (demuxer->type == DEMUXER_TYPE_OGG)
2221 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
2222 #endif
2223 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
2224 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
2225 #ifdef USE_ASS
2226 if (ass_enabled && (d_dvdsub->id >= 0) &&
2227 (((sh_sub_t *)d_dvdsub->sh)->type == 'a')) {
2228 ass_track = ((sh_sub_t *)d_dvdsub->sh)->ass_track;
2230 #endif
2231 if (d_dvdsub->id >= 0 &&
2232 ((sh_sub_t *)d_dvdsub->sh)->type == 'v') {
2233 sh_sub_t *mkv_sh_sub = (sh_sub_t *)d_dvdsub->sh;
2234 if (vo_spudec != NULL)
2235 spudec_free(vo_spudec);
2236 vo_spudec =
2237 spudec_new_scaled_vobsub(mkv_sh_sub->has_palette ?
2238 mkv_sh_sub->palette :
2239 NULL, mkv_sh_sub->colors,
2240 mkv_sh_sub->custom_colors,
2241 mkv_sh_sub->width,
2242 mkv_sh_sub->height);
2243 if (!forced_subs_only)
2244 forced_subs_only = mkv_sh_sub->forced_subs_only;
2245 if (vo_spudec) {
2246 spudec_set_forced_subs_only(vo_spudec,
2247 forced_subs_only);
2248 inited_flags |= INITED_SPUDEC;
2253 } else { // off
2254 #ifdef USE_SUB
2255 vo_osd_changed(OSDTYPE_SUBTITLE);
2256 #endif
2257 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2259 #ifdef USE_DVDREAD
2260 if (vo_spudec && stream->type == STREAMTYPE_DVD && dvdsub_id < 0 && reset_spu) {
2261 dvdsub_id = -2;
2262 d_dvdsub->id = dvdsub_id;
2263 spudec_reset(vo_spudec);
2265 #endif
2267 return 1;
2270 /// Subtitle delay (RW)
2271 static int mp_property_sub_delay(m_option_t* prop,int action,void* arg) {
2272 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2273 return m_property_delay(prop,action,arg,&sub_delay);
2276 /// Alignment of text subtitles (RW)
2277 static int mp_property_sub_alignment(m_option_t* prop,int action,void* arg) {
2278 #ifdef USE_SUB
2279 char* name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
2281 if(!sh_video || global_sub_pos < 0 || sub_source() != SUB_SOURCE_SUBS)
2282 return M_PROPERTY_UNAVAILABLE;
2284 switch(action) {
2285 case M_PROPERTY_PRINT:
2286 if(!arg) return 0;
2287 M_PROPERTY_CLAMP(prop,sub_alignment);
2288 *(char**)arg = strdup(name[sub_alignment]);
2289 return 1;
2290 case M_PROPERTY_SET:
2291 if(!arg) return 0;
2292 case M_PROPERTY_STEP_UP:
2293 case M_PROPERTY_STEP_DOWN:
2294 vo_osd_changed(OSDTYPE_SUBTITLE);
2295 default:
2296 return m_property_choice(prop,action,arg,&sub_alignment);
2298 #else
2299 return M_PROPERTY_UNAVAILABLE;
2300 #endif
2303 /// Subtitle visibility (RW)
2304 static int mp_property_sub_visibility(m_option_t* prop,int action,void* arg) {
2305 #ifdef USE_SUB
2306 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
2308 switch(action) {
2309 case M_PROPERTY_SET:
2310 if(!arg) return 0;
2311 case M_PROPERTY_STEP_UP:
2312 case M_PROPERTY_STEP_DOWN:
2313 vo_osd_changed(OSDTYPE_SUBTITLE);
2314 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
2315 default:
2316 return m_property_flag(prop,action,arg,&sub_visibility);
2318 #else
2319 return M_PROPERTY_UNAVAILABLE;
2320 #endif
2323 /// Show only forced subtitles (RW)
2324 static int mp_property_sub_forced_only(m_option_t* prop,int action,void* arg) {
2325 if(!vo_spudec) return M_PROPERTY_UNAVAILABLE;
2327 switch(action) {
2328 case M_PROPERTY_SET:
2329 if(!arg) return 0;
2330 case M_PROPERTY_STEP_UP:
2331 case M_PROPERTY_STEP_DOWN:
2332 m_property_flag(prop,action,arg,&forced_subs_only);
2333 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
2334 return 1;
2335 default:
2336 return m_property_flag(prop,action,arg,&forced_subs_only);
2341 ///@}
2343 /// \defgroup TVProperties TV properties
2344 /// \ingroup Properties
2345 ///@{
2347 #ifdef USE_TV
2349 /// TV color settings (RW)
2350 static int mp_property_tv_color(m_option_t* prop,int action,void* arg) {
2351 int r,val;
2352 tvi_handle_t* tvh = demuxer->priv;
2353 if(demuxer->type != DEMUXER_TYPE_TV || !tvh) return M_PROPERTY_UNAVAILABLE;
2355 switch(action) {
2356 case M_PROPERTY_SET:
2357 if(!arg) return 0;
2358 M_PROPERTY_CLAMP(prop,*(int*)arg);
2359 return tv_set_color_options(tvh,(int)prop->priv,*(int*)arg);
2360 case M_PROPERTY_GET:
2361 return tv_get_color_options(tvh,(int)prop->priv,arg);
2362 case M_PROPERTY_STEP_UP:
2363 case M_PROPERTY_STEP_DOWN:
2364 if((r = tv_get_color_options(tvh,(int)prop->priv,&val)) >= 0) {
2365 if(!r) return 0;
2366 val += (arg ? *(int*)arg : 1) *
2367 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2368 M_PROPERTY_CLAMP(prop,val);
2369 return tv_set_color_options(tvh,(int)prop->priv,val);
2371 return 0;
2373 return M_PROPERTY_NOT_IMPLEMENTED;
2376 #endif
2378 ///@}
2380 /// All properties available in MPlayer.
2381 /** \ingroup Properties
2383 static m_option_t mp_properties[] = {
2384 // General
2385 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2386 M_OPT_RANGE, 0, 3, NULL },
2387 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2388 M_OPT_RANGE, 0.01, 100.0, NULL },
2389 { "filename", mp_property_filename, CONF_TYPE_STRING,
2390 0, 0, 0, NULL },
2391 { "path", mp_property_path, CONF_TYPE_STRING,
2392 0, 0, 0, NULL },
2393 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2394 0, 0, 0, NULL },
2395 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2396 M_OPT_MIN, 0, 0, NULL },
2397 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2398 M_OPT_MIN, 0, 0, NULL },
2399 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2400 M_OPT_MIN, 0, 0, NULL },
2401 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2402 M_OPT_MIN, 0, 0, NULL },
2403 { "length", mp_property_length, CONF_TYPE_DOUBLE,
2404 0, 0, 0, NULL },
2406 // Audio
2407 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2408 M_OPT_RANGE, 0, 100, NULL },
2409 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2410 M_OPT_RANGE, 0, 1, NULL },
2411 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2412 M_OPT_RANGE, -100, 100, NULL },
2413 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2414 0, 0, 0, NULL },
2415 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2416 0, 0, 0, NULL },
2417 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2418 0, 0, 0, NULL },
2419 { "channels", mp_property_channels, CONF_TYPE_INT,
2420 0, 0, 0, NULL },
2421 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2422 -1, -1, 0, NULL },
2424 // Video
2425 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2426 M_OPT_RANGE, 0, 1, NULL },
2427 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2428 M_OPT_RANGE, 0, 1, NULL },
2429 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2430 M_OPT_RANGE, 0, 1, NULL },
2431 { "border", mp_property_border, CONF_TYPE_FLAG,
2432 M_OPT_RANGE, 0, 1, NULL },
2433 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2434 M_OPT_RANGE, 0, 2, NULL },
2435 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2436 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2437 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2438 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2439 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2440 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2441 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2442 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2443 { "hue", mp_property_gamma, CONF_TYPE_INT,
2444 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2445 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2446 M_OPT_RANGE, 0, 1, NULL },
2447 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2448 M_OPT_RANGE, 0, 1, NULL },
2449 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2450 0, 0, 0, NULL },
2451 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2452 0, 0, 0, NULL },
2453 { "width", mp_property_width, CONF_TYPE_INT,
2454 0, 0, 0, NULL },
2455 { "height", mp_property_height, CONF_TYPE_INT,
2456 0, 0, 0, NULL },
2457 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2458 0, 0, 0, NULL },
2459 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2460 0, 0, 0, NULL },
2462 // Subs
2463 { "sub", mp_property_sub, CONF_TYPE_INT,
2464 M_OPT_MIN, -1, 0, NULL },
2465 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2466 0, 0, 0, NULL },
2467 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2468 M_OPT_RANGE, 0, 100, NULL },
2469 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2470 M_OPT_RANGE, 0, 2, NULL },
2471 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2472 M_OPT_RANGE, 0, 1, NULL },
2473 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2474 M_OPT_RANGE, 0, 1, NULL },
2476 #ifdef USE_TV
2477 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2478 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_BRIGHTNESS },
2479 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2480 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_CONTRAST },
2481 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2482 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_SATURATION },
2483 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2484 M_OPT_RANGE, -100, 100, (void*)TV_COLOR_HUE },
2485 #endif
2487 { NULL, NULL, NULL, 0, 0, 0, NULL }
2490 m_option_t* mp_property_find(const char* name) {
2491 return m_option_list_find(mp_properties,name);
2494 int mp_property_do(const char* name,int action, void* val) {
2495 m_option_t* p = mp_property_find(name);
2496 if(!p) return M_PROPERTY_UNAVAILABLE;
2497 return m_property_do(p,action,val);
2500 ///@}
2501 // Properties group
2505 * \defgroup Command2Property Command to property bridge
2507 * It is used to handle most commands that just set a property
2508 * and optionally display something on the OSD.
2509 * Two kinds of commands are handled: adjust or toggle.
2511 * Adjust commands take 1 or 2 parameters: <value> <abs>
2512 * If <abs> is non-zero the property is set to the given value
2513 * otherwise it is adjusted.
2515 * Toggle commands take 0 or 1 parameters. With no parameter
2516 * or a value less than the property minimum it just steps the
2517 * property to its next value. Otherwise it sets it to the given
2518 * value.
2523 /// List of the commands that can be handled by setting a property.
2524 static struct {
2525 /// property name
2526 const char* name;
2527 /// cmd id
2528 int cmd;
2529 /// set/adjust or toggle command
2530 int toggle;
2531 /// progressbar type
2532 int osd_progbar;
2533 /// osd msg id if it must be shared
2534 int osd_id;
2535 /// osd msg template
2536 const char* osd_msg;
2537 } set_prop_cmd[] = {
2538 // audio
2539 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2540 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2541 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2542 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2543 // video
2544 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2545 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2546 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2547 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2548 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2549 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2550 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2551 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2552 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2553 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2554 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2555 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2556 // subs
2557 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2558 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2559 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2560 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2561 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2562 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2563 #ifdef USE_TV
2564 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2565 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2566 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2567 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2568 #endif
2569 { NULL, 0, 0, 0, -1, NULL }
2572 /// Handle commands that set a property.
2573 static int set_property_command(mp_cmd_t* cmd) {
2574 int i,r;
2575 m_option_t* prop;
2577 // look for the command
2578 for(i = 0 ; set_prop_cmd[i].name ; i++)
2579 if(set_prop_cmd[i].cmd == cmd->id) break;
2580 if(!set_prop_cmd[i].name) return 0;
2582 // get the property
2583 prop = mp_property_find(set_prop_cmd[i].name);
2584 if(!prop) return 0;
2586 // toggle command
2587 if(set_prop_cmd[i].toggle) {
2588 // set to value
2589 if(cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2590 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v.i);
2591 else
2592 r = m_property_do(prop,M_PROPERTY_STEP_UP,NULL);
2593 } else if(cmd->args[1].v.i) //set
2594 r = m_property_do(prop,M_PROPERTY_SET,&cmd->args[0].v);
2595 else // adjust
2596 r = m_property_do(prop,M_PROPERTY_STEP_UP,&cmd->args[0].v);
2598 if(r <= 0) return 1;
2600 if(set_prop_cmd[i].osd_progbar) {
2601 if(prop->type == CONF_TYPE_INT) {
2602 if(m_property_do(prop,M_PROPERTY_GET,&r) > 0)
2603 set_osd_bar(set_prop_cmd[i].osd_progbar,
2604 set_prop_cmd[i].osd_msg,
2605 prop->min,prop->max,r);
2606 } else if(prop->type == CONF_TYPE_FLOAT) {
2607 float f;
2608 if(m_property_do(prop,M_PROPERTY_GET,&f) > 0)
2609 set_osd_bar(set_prop_cmd[i].osd_progbar,set_prop_cmd[i].osd_msg,
2610 prop->min,prop->max,f);
2611 } else
2612 mp_msg(MSGT_CPLAYER,MSGL_ERR, "Property use an unsupported type.\n");
2613 return 1;
2616 if(set_prop_cmd[i].osd_msg) {
2617 char* val = m_property_print(prop);
2618 if(val) {
2619 set_osd_msg(set_prop_cmd[i].osd_id >= 0 ? set_prop_cmd[i].osd_id :
2620 OSD_MSG_PROPERTY+i,1,osd_duration,
2621 set_prop_cmd[i].osd_msg,val);
2622 free(val);
2625 return 1;
2628 static void reinit_audio_chain(void) {
2629 if(sh_audio){
2630 current_module="init_audio_codec";
2631 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2632 if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
2633 sh_audio=d_audio->sh=NULL; // failed to init :(
2634 d_audio->id = -2;
2635 return;
2636 } else
2637 inited_flags|=INITED_ACODEC;
2638 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
2641 //const ao_info_t *info=audio_out->info;
2642 current_module="af_preinit";
2643 ao_data.samplerate=force_srate;
2644 ao_data.channels=0;
2645 ao_data.format=audio_output_format;
2646 #if 1
2647 // first init to detect best values
2648 if(!preinit_audio_filters(sh_audio,
2649 // input:
2650 (int)(sh_audio->samplerate*playback_speed),
2651 sh_audio->channels, sh_audio->sample_format,
2652 // output:
2653 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){
2654 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError);
2655 exit_player(MSGTR_Exit_error);
2657 #endif
2658 current_module="ao2_init";
2659 if(!(audio_out=init_best_audio_out(audio_driver_list,
2660 0, // plugin flag
2661 ao_data.samplerate,
2662 ao_data.channels,
2663 ao_data.format,0))){
2664 // FAILED:
2665 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO);
2666 uninit_player(INITED_ACODEC); // close codec
2667 sh_audio=d_audio->sh=NULL; // -> nosound
2668 d_audio->id = -2;
2669 return;
2670 } else {
2671 // SUCCESS:
2672 inited_flags|=INITED_AO;
2673 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n",
2674 audio_out->info->short_name,
2675 ao_data.samplerate, ao_data.channels,
2676 af_fmt2str_short(ao_data.format),
2677 af_fmt2bits(ao_data.format)/8 );
2678 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n",
2679 audio_out->info->name, audio_out->info->author);
2680 if(strlen(audio_out->info->comment) > 0)
2681 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", audio_out->info->comment);
2682 // init audio filters:
2683 #if 1
2684 current_module="af_init";
2685 if(!build_afilter_chain(sh_audio, &ao_data)) {
2686 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
2687 // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n");
2688 // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao
2689 // sh_audio=d_audio->sh=NULL; // -> nosound
2691 #endif
2693 mixer.audio_out = audio_out;
2694 mixer.volstep = volstep;
2699 ///@}
2700 // Command2Property
2703 // Return pts value corresponding to the end point of audio written to the
2704 // ao so far.
2705 static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio)
2707 // first calculate the end pts of audio that has been output by decoder
2708 double a_pts = sh_audio->pts;
2709 if (a_pts != MP_NOPTS_VALUE)
2710 // Good, decoder supports new way of calculating audio pts.
2711 // sh_audio->pts is the timestamp of the latest input packet with
2712 // known pts that the decoder has decoded. sh_audio->pts_bytes is
2713 // the amount of bytes the decoder has written after that timestamp.
2714 a_pts += sh_audio->pts_bytes / (double) sh_audio->o_bps;
2715 else {
2716 // Decoder doesn't support new way of calculating pts (or we're
2717 // being called before it has decoded anything with known timestamp).
2718 // Use the old method of audio pts calculation: take the timestamp
2719 // of last packet with known pts the decoder has read data from,
2720 // and add amount of bytes read after the beginning of that packet
2721 // divided by input bps. This will be inaccurate if the input/output
2722 // ratio is not constant for every audio packet or if it is constant
2723 // but not accurately known in sh_audio->i_bps.
2725 a_pts = d_audio->pts;
2726 // ds_tell_pts returns bytes read after last timestamp from
2727 // demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
2728 // it has read but not decoded
2729 if (sh_audio->i_bps)
2730 a_pts += (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len) /
2731 (double)sh_audio->i_bps;
2733 // Now a_pts hopefully holds the pts for end of audio from decoder.
2734 // Substract data in buffers between decoder and audio out.
2736 // Decoded but not filtered
2737 a_pts -= sh_audio->a_buffer_len / (double)sh_audio->o_bps;
2739 // Data that was ready for ao but was buffered because ao didn't fully
2740 // accept everything to internal buffers yet
2741 a_pts -= sh_audio->a_out_buffer_len * playback_speed / (double)ao_data.bps;
2743 return a_pts;
2746 // Return pts value corresponding to currently playing audio.
2747 static double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio,
2748 ao_functions_t *audio_out)
2750 return written_audio_pts(sh_audio, d_audio) - playback_speed *
2751 audio_out->get_delay();
2755 static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video)
2757 unsigned char *start;
2758 int in_size;
2759 int hit_eof=0;
2760 double pts;
2762 while (1) {
2763 current_module = "decode video";
2764 // XXX Time used in this call is not counted in any performance
2765 // timer now, OSD is not updated correctly for filter-added frames
2766 if (vf_output_queued_frame(sh_video->vfilter))
2767 break;
2768 current_module = "video_read_frame";
2769 in_size = ds_get_packet_pts(d_video, &start, &pts);
2770 if (in_size < 0) {
2771 // try to extract last frames in case of decoder lag
2772 in_size = 0;
2773 pts = 1e300;
2774 hit_eof = 1;
2776 if (in_size > max_framesize)
2777 max_framesize = in_size;
2778 if (pts == MP_NOPTS_VALUE)
2779 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts value from demuxer MISSING\n");
2780 current_module = "decode video";
2781 void *decoded_frame = decode_video(sh_video, start, in_size, 0, pts);
2782 if (decoded_frame) {
2783 update_osd_msg();
2784 if (filter_video(sh_video, decoded_frame, sh_video->pts))
2785 break;
2787 if (hit_eof)
2788 return 0;
2790 return 1;
2793 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy) {
2794 //remove the borders, if any, and rescale to the range [0,1],[0,1]
2795 if(vo_fs) { //we are in full-screen mode
2796 if(vo_screenwidth > vo_dwidth) //there are borders along the x axis
2797 ix -= (vo_screenwidth - vo_dwidth) / 2;
2798 if(vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
2799 iy -= (vo_screenheight - vo_dheight) / 2;
2801 if(ix < 0 || ix > vo_dwidth) {*dx = *dy = -1.0; return; } //we are on one of the borders
2802 if(iy < 0 || iy > vo_dheight) {*dx = *dy = -1.0; return; } //we are on one of the borders
2805 *dx = (double) ix / (double) vo_dwidth;
2806 *dy = (double) iy / (double) vo_dheight;
2808 mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
2809 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth, vo_dheight, vo_fs);
2812 #ifdef HAVE_RTC
2813 int rtc_fd = -1;
2814 #endif
2816 static float timing_sleep(float time_frame)
2818 #ifdef HAVE_RTC
2819 if (rtc_fd >= 0){
2820 // -------- RTC -----------
2821 current_module="sleep_rtc";
2822 while (time_frame > 0.000) {
2823 unsigned long rtc_ts;
2824 if (read(rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
2825 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
2826 time_frame -= GetRelativeTime();
2828 } else
2829 #endif
2830 #ifdef SYS_DARWIN
2832 current_module = "sleep_darwin";
2833 while (time_frame > 0.005) {
2834 usec_sleep(1000000*time_frame);
2835 time_frame -= GetRelativeTime();
2838 #else
2840 // assume kernel HZ=100 for softsleep, works with larger HZ but with
2841 // unnecessarily high CPU usage
2842 float margin = softsleep ? 0.011 : 0;
2843 current_module = "sleep_timer";
2844 while (time_frame > margin) {
2845 usec_sleep(1000000 * (time_frame - margin));
2846 time_frame -= GetRelativeTime();
2848 if (softsleep){
2849 current_module = "sleep_soft";
2850 if (time_frame < 0)
2851 mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
2852 while (time_frame > 0)
2853 time_frame-=GetRelativeTime(); // burn the CPU
2856 #endif /* SYS_DARWIN */
2857 return time_frame;
2860 static void adjust_sync_and_print_status(int between_frames, float timing_error)
2862 current_module="av_sync";
2864 if(sh_audio){
2865 double a_pts, v_pts;
2867 if (autosync)
2869 * If autosync is enabled, the value for delay must be calculated
2870 * a bit differently. It is set only to the difference between
2871 * the audio and video timers. Any attempt to include the real
2872 * or corrected delay causes the pts_correction code below to
2873 * try to correct for the changes in delay which autosync is
2874 * trying to measure. This keeps the two from competing, but still
2875 * allows the code to correct for PTS drift *only*. (Using a delay
2876 * value here, even a "corrected" one, would be incompatible with
2877 * autosync mode.)
2879 a_pts = written_audio_pts(sh_audio, d_audio) - sh_audio->delay;
2880 else
2881 a_pts = playing_audio_pts(sh_audio, d_audio, audio_out);
2883 v_pts = sh_video->pts;
2886 static int drop_message=0;
2887 double AV_delay = a_pts - audio_delay - v_pts;
2888 double x;
2889 if (AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){
2890 ++drop_message;
2891 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow);
2893 if (autosync)
2894 x = AV_delay*0.1f;
2895 else
2896 /* Do not correct target time for the next frame if this frame
2897 * was late not because of wrong target time but because the
2898 * target time could not be met */
2899 x = (AV_delay + timing_error * playback_speed) * 0.1f;
2900 if (x < -max_pts_correction)
2901 x = -max_pts_correction;
2902 else if (x> max_pts_correction)
2903 x = max_pts_correction;
2904 if (default_max_pts_correction >= 0)
2905 max_pts_correction = default_max_pts_correction;
2906 else
2907 max_pts_correction = sh_video->frametime*0.10; // +-10% of time
2908 if (!between_frames) {
2909 sh_audio->delay+=x;
2910 c_total+=x;
2912 if(!quiet)
2913 print_status(a_pts - audio_delay, AV_delay, c_total);
2916 } else {
2917 // No audio:
2919 if (!quiet)
2920 print_status(0, 0, 0);
2924 int fill_audio_out_buffers(void)
2926 unsigned int t;
2927 double tt;
2928 int playsize;
2929 int playflags=0;
2930 int audio_eof=0;
2931 int bytes_to_write;
2933 current_module="play_audio";
2935 while (1) {
2936 // all the current uses of ao_data.pts seem to be in aos that handle
2937 // sync completely wrong; there should be no need to use ao_data.pts
2938 // in get_space()
2939 ao_data.pts = ((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2940 bytes_to_write = audio_out->get_space();
2941 if (sh_video || bytes_to_write >= ao_data.outburst)
2942 break;
2944 // handle audio-only case:
2945 // this is where mplayer sleeps during audio-only playback
2946 // to avoid 100% CPU use
2947 usec_sleep(10000); // Wait a tick before retry
2950 while (bytes_to_write) {
2951 playsize = bytes_to_write;
2952 if (playsize > MAX_OUTBURST)
2953 playsize = MAX_OUTBURST;
2954 bytes_to_write -= playsize;
2956 // Fill buffer if needed:
2957 current_module="decode_audio";
2958 t = GetTimer();
2959 while (sh_audio->a_out_buffer_len < playsize) {
2960 int buflen = sh_audio->a_out_buffer_len;
2961 int ret = decode_audio(sh_audio, &sh_audio->a_out_buffer[buflen],
2962 playsize - buflen, // min bytes
2963 sh_audio->a_out_buffer_size - buflen // max
2965 if (ret <= 0) { // EOF?
2966 if (d_audio->eof) {
2967 audio_eof = 1;
2968 if (sh_audio->a_out_buffer_len == 0)
2969 return 0;
2971 break;
2973 sh_audio->a_out_buffer_len += ret;
2975 t = GetTimer() - t;
2976 tt = t*0.000001f; audio_time_usage+=tt;
2977 if (playsize > sh_audio->a_out_buffer_len) {
2978 playsize = sh_audio->a_out_buffer_len;
2979 if (audio_eof)
2980 playflags |= AOPLAY_FINAL_CHUNK;
2982 if (!playsize)
2983 break;
2985 // play audio:
2986 current_module="play_audio";
2988 // Is this pts value actually useful for the aos that access it?
2989 // They're obviously badly broken in the way they handle av sync;
2990 // would not having access to this make them more broken?
2991 ao_data.pts = ((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0;
2992 playsize = audio_out->play(sh_audio->a_out_buffer, playsize, playflags);
2994 if (playsize > 0) {
2995 sh_audio->a_out_buffer_len -= playsize;
2996 memmove(sh_audio->a_out_buffer, &sh_audio->a_out_buffer[playsize],
2997 sh_audio->a_out_buffer_len);
2998 sh_audio->delay += playback_speed*playsize/(double)ao_data.bps;
3000 else if (audio_eof && audio_out->get_delay() < .04) {
3001 // Sanity check to avoid hanging in case current ao doesn't output
3002 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
3003 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n");
3004 sh_audio->a_out_buffer_len = 0;
3007 return 1;
3010 int sleep_until_update(float *time_frame, float *aq_sleep_time)
3012 current_module="calc_sleep_time";
3014 int frame_time_remaining = 0;
3015 *time_frame -= GetRelativeTime(); // reset timer
3017 if (sh_audio && !d_audio->eof) {
3018 float delay = audio_out->get_delay();
3019 mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "delay=%f\n", delay);
3021 if (autosync) {
3023 * Adjust this raw delay value by calculating the expected
3024 * delay for this frame and generating a new value which is
3025 * weighted between the two. The higher autosync is, the
3026 * closer to the delay value gets to that which "-nosound"
3027 * would have used, and the longer it will take for A/V
3028 * sync to settle at the right value (but it eventually will.)
3029 * This settling time is very short for values below 100.
3031 float predicted = sh_audio->delay / playback_speed + *time_frame;
3032 float difference = delay - predicted;
3033 delay = predicted + difference / (float)autosync;
3036 *time_frame = delay - sh_audio->delay / playback_speed;
3038 // delay = amount of audio buffered in soundcard/driver
3039 if (delay > 0.25) delay=0.25; else
3040 if (delay < 0.10) delay=0.10;
3041 if (*time_frame > delay*0.6) {
3042 // sleep time too big - may cause audio drops (buffer underrun)
3043 frame_time_remaining = 1;
3044 *time_frame = delay*0.5;
3046 } else {
3047 // If we're lagging more than 200 ms behind the right playback rate,
3048 // don't try to "catch up".
3049 // If benchmark is set always output frames as fast as possible
3050 // without sleeping.
3051 if (*time_frame < -0.2 || benchmark)
3052 *time_frame = 0;
3055 *aq_sleep_time += *time_frame;
3058 //============================== SLEEP: ===================================
3060 // flag 256 means: libvo driver does its timing (dvb card)
3061 if (*time_frame > 0.001 && !(vo_flags&256))
3062 *time_frame = timing_sleep(*time_frame);
3063 return frame_time_remaining;
3067 int main(int argc,char* argv[]){
3070 char * mem_ptr;
3072 int file_format=DEMUXER_TYPE_UNKNOWN;
3074 // movie info:
3076 /* Flag indicating whether MPlayer should exit without playing anything. */
3077 int opt_exit = 0;
3079 //float a_frame=0; // Audio
3081 int i;
3082 char *tmp;
3084 int gui_no_filename=0;
3086 struct {double pts; vo_functions_t *vo;} vf_vo_data;
3088 srand((int) time(NULL));
3090 InitTimer();
3092 mp_msg_init();
3094 mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2006 MPlayer Team\n");
3095 /* Test for CPU capabilities (and corresponding OS support) for optimizing */
3096 GetCpuCaps(&gCpuCaps);
3097 #ifdef ARCH_X86
3098 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
3099 gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
3100 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
3101 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
3102 #ifdef RUNTIME_CPUDETECT
3103 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
3104 #else
3105 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
3106 #ifdef HAVE_MMX
3107 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
3108 #endif
3109 #ifdef HAVE_MMX2
3110 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
3111 #endif
3112 #ifdef HAVE_3DNOW
3113 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
3114 #endif
3115 #ifdef HAVE_3DNOWEX
3116 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
3117 #endif
3118 #ifdef HAVE_SSE
3119 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
3120 #endif
3121 #ifdef HAVE_SSE2
3122 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
3123 #endif
3124 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
3125 #endif /* RUNTIME_CPUDETECT */
3126 #endif /* ARCH_X86 */
3128 #if defined(WIN32) && defined(USE_WIN32DLL)
3129 set_path_env();
3130 #endif /*WIN32 && USE_WIN32DLL*/
3132 #ifdef USE_TV
3133 tv_param_immediate = 1;
3134 #endif
3136 if (argc > 1 && argv[1] &&
3137 (!strcmp(argv[1], "-gui") || !strcmp(argv[1], "-nogui"))) {
3138 use_gui = !strcmp(argv[1], "-gui");
3139 } else
3140 if ( argv[0] )
3142 char *base = strrchr(argv[0], '/');
3143 if (!base)
3144 base = strrchr(argv[0], '\\');
3145 if (!base)
3146 base = argv[0];
3147 if(strstr(base, "gmplayer"))
3148 use_gui=1;
3151 mconfig = m_config_new();
3152 m_config_register_options(mconfig,mplayer_opts);
3153 // TODO : add something to let modules register their options
3154 mp_input_register_options(mconfig);
3155 parse_cfgfiles(mconfig);
3157 #ifdef HAVE_NEW_GUI
3158 if ( use_gui ) cfg_read();
3159 #endif
3161 playtree = m_config_parse_mp_command_line(mconfig, argc, argv);
3162 if(playtree == NULL)
3163 opt_exit = 1;
3164 else {
3165 playtree = play_tree_cleanup(playtree);
3166 if(playtree) {
3167 playtree_iter = play_tree_iter_new(playtree,mconfig);
3168 if(playtree_iter) {
3169 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
3170 play_tree_iter_free(playtree_iter);
3171 playtree_iter = NULL;
3173 filename = play_tree_iter_get_file(playtree_iter,1);
3178 #if defined(WIN32) && defined(HAVE_NEW_GUI)
3179 void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
3180 if(runningmplayer && filename && use_gui){
3181 COPYDATASTRUCT csData;
3182 char file[MAX_PATH];
3183 char *filepart = filename;
3184 if(GetFullPathName(filename, MAX_PATH, file, &filepart)){
3185 csData.dwData = 0;
3186 csData.cbData = strlen(file)*2;
3187 csData.lpData = file;
3188 SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData);
3191 #endif
3193 #ifdef WIN32
3194 if(proc_priority){
3195 int i;
3196 for(i=0; priority_presets_defs[i].name; i++){
3197 if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
3198 break;
3200 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",
3201 priority_presets_defs[i].name);
3202 SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
3204 #endif
3205 #ifndef HAVE_NEW_GUI
3206 if(use_gui){
3207 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);
3208 use_gui=0;
3210 #else
3211 #ifndef WIN32
3212 if(use_gui && !vo_init()){
3213 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
3214 use_gui=0;
3216 #endif
3217 if (use_gui && playtree_iter){
3218 char cwd[PATH_MAX+2];
3219 // Free Playtree and Playtree-Iter as it's not used by the GUI.
3220 play_tree_iter_free(playtree_iter);
3221 playtree_iter=NULL;
3223 if (getcwd(cwd, PATH_MAX) != (char *)NULL)
3225 strcat(cwd, "/");
3226 // Prefix relative paths with current working directory
3227 play_tree_add_bpf(playtree, cwd);
3229 // Import initital playtree into GUI.
3230 import_initial_playtree_into_gui(playtree, mconfig, enqueue);
3232 #endif /* HAVE_NEW_GUI */
3234 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){
3235 list_video_out();
3236 opt_exit = 1;
3239 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){
3240 list_audio_out();
3241 opt_exit = 1;
3244 /* Check codecs.conf. */
3245 if(!codecs_file || !parse_codec_cfg(codecs_file)){
3246 if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
3247 if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
3248 if(!parse_codec_cfg(NULL)){
3249 mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);
3250 exit_player_with_rc(NULL, 0);
3252 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
3255 free( mem_ptr ); // release the buffer created by get_path()
3258 #if 0
3259 if(video_codec_list){
3260 int i;
3261 video_codec=video_codec_list[0];
3262 for(i=0;video_codec_list[i];i++)
3263 mp_msg(MSGT_FIXME,MSGL_FIXME,"vc#%d: '%s'\n",i,video_codec_list[i]);
3265 #endif
3266 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
3267 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
3268 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODECS\n");
3269 list_codecs(1);
3270 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3271 opt_exit = 1;
3273 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){
3274 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs);
3275 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODECS\n");
3276 list_codecs(0);
3277 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3278 opt_exit = 1;
3280 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){
3281 vfm_help();
3282 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3283 opt_exit = 1;
3285 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
3286 afm_help();
3287 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3288 opt_exit = 1;
3290 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){
3291 af_help();
3292 printf("\n");
3293 opt_exit = 1;
3295 #ifdef HAVE_X11
3296 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){
3297 fstype_help();
3298 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");
3299 opt_exit = 1;
3301 #endif
3302 if((demuxer_name && strcmp(demuxer_name,"help")==0) ||
3303 (audio_demuxer_name && strcmp(audio_demuxer_name,"help")==0) ||
3304 (sub_demuxer_name && strcmp(sub_demuxer_name,"help")==0)){
3305 demuxer_help();
3306 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
3307 opt_exit = 1;
3309 if(list_properties) {
3310 m_properties_print_help_list(mp_properties);
3311 opt_exit = 1;
3314 if(opt_exit)
3315 exit_player(NULL);
3317 if (player_idle_mode && use_gui) {
3318 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NoIdleAndGui);
3319 exit_player_with_rc(NULL, 1);
3322 if(!filename && !player_idle_mode){
3323 if(!use_gui){
3324 // no file/vcd/dvd -> show HELP:
3325 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);
3326 exit_player_with_rc(NULL, 0);
3327 } else gui_no_filename=1;
3330 // Many users forget to include command line in bugreports...
3331 if( mp_msg_test(MSGT_CPLAYER,MSGL_V) ){
3332 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);
3333 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);
3334 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
3337 //------ load global data first ------
3339 // check font
3340 #ifdef USE_OSD
3341 #ifdef HAVE_FREETYPE
3342 init_freetype();
3343 #endif
3344 #ifdef HAVE_FONTCONFIG
3345 if(!font_fontconfig)
3347 #endif
3348 #ifdef HAVE_BITMAP_FONT
3349 if(font_name){
3350 vo_font=read_font_desc(font_name,font_factor,verbose>1);
3351 if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
3352 } else {
3353 // try default:
3354 vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
3355 free(mem_ptr); // release the buffer created by get_path()
3356 if(!vo_font)
3357 vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
3359 #endif
3360 #ifdef HAVE_FONTCONFIG
3362 #endif
3363 #endif /* USE_OSD */
3364 vo_init_osd();
3366 #ifdef USE_ASS
3367 ass_library = ass_init();
3368 #endif
3370 #ifdef HAVE_RTC
3371 if(!nortc)
3373 // seteuid(0); /* Can't hurt to try to get root here */
3374 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0)
3375 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable,
3376 rtc_device ? rtc_device : "/dev/rtc", strerror(errno));
3377 else {
3378 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */
3380 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) {
3381 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno));
3382 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp);
3383 close (rtc_fd);
3384 rtc_fd = -1;
3385 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
3386 /* variable only by the root */
3387 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno));
3388 close (rtc_fd);
3389 rtc_fd = -1;
3390 } else
3391 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp);
3394 #ifdef HAVE_NEW_GUI
3395 // breaks DGA and SVGAlib and VESA drivers: --A'rpi
3396 // and now ? -- Pontscho
3397 if(use_gui) setuid( getuid() ); // strongly test, please check this.
3398 #endif
3399 if(rtc_fd<0)
3400 #endif /* HAVE_RTC */
3401 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",
3402 softsleep?"software":timer_name);
3404 #ifdef USE_TERMCAP
3405 if ( !use_gui ) load_termcap(NULL); // load key-codes
3406 #endif
3408 // ========== Init keyboard FIFO (connection to libvo) ============
3410 // Init input system
3411 current_module = "init_input";
3412 mp_input_init(use_gui);
3413 #if 0
3414 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
3416 if(keyb_fifo_get > 0)
3417 mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);
3418 #else
3419 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);
3420 #endif
3421 if(slave_mode)
3422 #ifndef __MINGW32__
3423 mp_input_add_cmd_fd(0,1,NULL,NULL);
3424 #else
3425 mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);
3426 #endif
3427 else if(!noconsolecontrols)
3428 #ifndef HAVE_NO_POSIX_SELECT
3429 mp_input_add_key_fd(0,1,NULL,NULL);
3430 #else
3431 mp_input_add_key_fd(0,0,NULL,NULL);
3432 #endif
3434 inited_flags|=INITED_INPUT;
3435 current_module = NULL;
3437 #ifdef HAVE_MENU
3438 if(use_menu) {
3439 if(menu_cfg && menu_init(menu_cfg))
3440 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
3441 else {
3442 menu_cfg = get_path("menu.conf");
3443 if(menu_init(menu_cfg))
3444 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);
3445 else {
3446 if(menu_init(MPLAYER_CONFDIR "/menu.conf"))
3447 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");
3448 else {
3449 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);
3450 use_menu = 0;
3455 #endif
3457 /// Catch signals
3458 #ifndef __MINGW32__
3459 signal(SIGCHLD,child_sighandler);
3460 #endif
3462 #ifdef CRASH_DEBUG
3463 prog_path = argv[0];
3464 #endif
3465 //========= Catch terminate signals: ================
3466 // terminate requests:
3467 signal(SIGTERM,exit_sighandler); // kill
3468 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
3470 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
3472 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
3473 signal(SIGPIPE,exit_sighandler); // Some window managers cause this
3474 #ifdef ENABLE_SIGHANDLER
3475 // fatal errors:
3476 signal(SIGBUS,exit_sighandler); // bus error
3477 signal(SIGSEGV,exit_sighandler); // segfault
3478 signal(SIGILL,exit_sighandler); // illegal instruction
3479 signal(SIGFPE,exit_sighandler); // floating point exc.
3480 signal(SIGABRT,exit_sighandler); // abort()
3481 #ifdef CRASH_DEBUG
3482 if (crash_debug)
3483 signal(SIGTRAP,exit_sighandler);
3484 #endif
3485 #endif
3487 #ifdef HAVE_NEW_GUI
3488 if(use_gui){
3489 guiInit();
3490 inited_flags|=INITED_GUI;
3491 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) );
3493 #endif
3495 // ******************* Now, let's see the per-file stuff ********************
3497 play_next_file:
3499 // init global sub numbers
3500 global_sub_size = 0;
3501 { int i; for (i = 0; i < SUB_SOURCES; i++) global_sub_indices[i] = -1; }
3503 if (filename) load_per_file_config (mconfig, filename);
3505 // We must enable getch2 here to be able to interrupt network connection
3506 // or cache filling
3507 if(!noconsolecontrols && !slave_mode){
3508 if(inited_flags&INITED_GETCH2)
3509 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice);
3510 else
3511 getch2_enable(); // prepare stdin for hotkeys...
3512 inited_flags|=INITED_GETCH2;
3513 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n");
3516 // =================== GUI idle loop (STOP state) ===========================
3517 #ifdef HAVE_NEW_GUI
3518 if ( use_gui ) {
3519 file_format=DEMUXER_TYPE_UNKNOWN;
3520 guiGetEvent( guiSetDefaults,0 );
3521 while ( guiIntfStruct.Playing != 1 )
3523 mp_cmd_t* cmd;
3524 usec_sleep(20000);
3525 guiEventHandling();
3526 guiGetEvent( guiReDraw,NULL );
3527 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
3529 guiGetEvent( guiSetParameters,NULL );
3530 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM )
3532 play_tree_t * entry = play_tree_new();
3533 play_tree_add_file( entry,guiIntfStruct.Filename );
3534 if ( playtree ) play_tree_free_list( playtree->child,1 );
3535 else playtree=play_tree_new();
3536 play_tree_set_child( playtree,entry );
3537 if(playtree)
3539 playtree_iter = play_tree_iter_new(playtree,mconfig);
3540 if(playtree_iter)
3542 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY)
3544 play_tree_iter_free(playtree_iter);
3545 playtree_iter = NULL;
3547 filename = play_tree_iter_get_file(playtree_iter,1);
3552 #endif /* HAVE_NEW_GUI */
3554 while (player_idle_mode && !filename) {
3555 play_tree_t * entry = NULL;
3556 mp_cmd_t * cmd;
3557 while (!(cmd = mp_input_get_cmd(0,1,0))) { // wait for command
3558 if (video_out && vo_config_count) video_out->check_events();
3559 usec_sleep(20000);
3561 switch (cmd->id) {
3562 case MP_CMD_LOADFILE:
3563 // prepare a tree entry with the new filename
3564 entry = play_tree_new();
3565 play_tree_add_file(entry, cmd->args[0].v.s);
3566 // The entry is added to the main playtree after the switch().
3567 break;
3568 case MP_CMD_LOADLIST:
3569 entry = parse_playlist_file(cmd->args[0].v.s);
3570 break;
3571 case MP_CMD_QUIT:
3572 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
3573 break;
3576 mp_cmd_free(cmd);
3578 if (entry) { // user entered a command that gave a valid entry
3579 if (playtree) // the playtree is always a node with one child. let's clear it
3580 play_tree_free_list(playtree->child, 1);
3581 else playtree=play_tree_new(); // .. or make a brand new playtree
3583 if (!playtree) continue; // couldn't make playtree! wait for next command
3585 play_tree_set_child(playtree, entry);
3587 /* Make iterator start at the top the of tree. */
3588 playtree_iter = play_tree_iter_new(playtree, mconfig);
3589 if (!playtree_iter) continue;
3591 // find the first real item in the tree
3592 if (play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
3593 // no items!
3594 play_tree_iter_free(playtree_iter);
3595 playtree_iter = NULL;
3596 continue; // wait for next command
3598 filename = play_tree_iter_get_file(playtree_iter, 1);
3601 //---------------------------------------------------------------------------
3603 if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
3605 if (edl_filename) {
3606 if (edl_records) free_edl(edl_records);
3607 next_edl_record = edl_records = edl_parse_file();
3609 if (edl_output_filename) {
3610 if (edl_fd) fclose(edl_fd);
3611 if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
3613 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
3614 edl_output_filename);
3618 //==================== Open VOB-Sub ============================
3620 current_module="vobsub";
3621 if (vobsub_name){
3622 vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
3623 if(vo_vobsub==NULL)
3624 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
3625 }else if(sub_auto && filename && (strlen(filename)>=5)){
3626 /* try to autodetect vobsub from movie filename ::atmos */
3627 char *buf = malloc((strlen(filename)-3)),*psub;
3628 memset(buf,0,strlen(filename)-3); // make sure string is terminated
3629 strncpy(buf, filename, strlen(filename)-4);
3630 vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
3631 /* try from ~/.mplayer/sub */
3632 if(!vo_vobsub && (psub = get_path( "sub/" ))) {
3633 char *bname;
3634 int l;
3635 bname = strrchr(buf,'/');
3636 #ifdef WIN32
3637 if(!bname) bname = strrchr(buf,'\\');
3638 #endif
3639 if(bname) bname++;
3640 else bname = buf;
3641 l = strlen(psub) + strlen(bname) + 1;
3642 psub = realloc(psub,l);
3643 strcat(psub,bname);
3644 vo_vobsub=vobsub_open(psub,spudec_ifo,0,&vo_spudec);
3645 free(psub);
3647 free(buf);
3649 if(vo_vobsub){
3650 inited_flags|=INITED_VOBSUB;
3651 vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
3652 // check if vobsub requested only to display forced subtitles
3653 forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);
3655 // setup global sub numbering
3656 global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
3657 global_sub_size += vobsub_get_indexes_count(vo_vobsub);
3660 //============ Open & Sync STREAM --- fork cache2 ====================
3662 stream=NULL;
3663 demuxer=NULL;
3664 if (d_audio) {
3665 //free_demuxer_stream(d_audio);
3666 d_audio=NULL;
3668 if (d_video) {
3669 //free_demuxer_stream(d_video);
3670 d_video=NULL;
3672 sh_audio=NULL;
3673 sh_video=NULL;
3675 current_module="open_stream";
3676 stream=open_stream(filename,0,&file_format);
3677 if(!stream) { // error...
3678 eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
3679 goto goto_next_file;
3681 inited_flags|=INITED_STREAM;
3683 #ifdef HAVE_NEW_GUI
3684 if ( use_gui ) guiGetEvent( guiSetStream,(char *)stream );
3685 #endif
3687 if(file_format == DEMUXER_TYPE_PLAYLIST) {
3688 play_tree_t* entry;
3689 // Handle playlist
3690 current_module="handle_playlist";
3691 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
3692 entry = parse_playtree(stream,0);
3693 eof=playtree_add_playlist(entry);
3694 goto goto_next_file;
3696 stream->start_pos+=seek_to_byte;
3698 if(stream_dump_type==5){
3699 unsigned char buf[4096];
3700 int len;
3701 FILE *f;
3702 current_module="dumpstream";
3703 if(stream->type==STREAMTYPE_STREAM && stream->fd<0){
3704 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
3705 exit_player(MSGTR_Exit_error);
3707 stream_reset(stream);
3708 stream_seek(stream,stream->start_pos);
3709 f=fopen(stream_dump_name,"wb");
3710 if(!f){
3711 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
3712 exit_player(MSGTR_Exit_error);
3714 while(!stream->eof){
3715 len=stream_read(stream,buf,4096);
3716 if(len>0) {
3717 if(fwrite(buf,len,1,f) != 1) {
3718 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
3719 exit_player(MSGTR_Exit_error);
3723 if(fclose(f)) {
3724 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
3725 exit_player(MSGTR_Exit_error);
3727 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
3728 exit_player_with_rc(MSGTR_Exit_eof, 0);
3731 #ifdef USE_DVDREAD
3732 if(stream->type==STREAMTYPE_DVD){
3733 current_module="dvd lang->id";
3734 if(audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
3735 if(dvdsub_lang && dvdsub_id==-2) dvdsub_id=-1;
3736 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
3737 // setup global sub numbering
3738 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
3739 global_sub_size += dvd_number_of_subs(stream);
3740 current_module=NULL;
3742 #endif
3744 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
3745 goto_enable_cache:
3746 if(stream_cache_size>0){
3747 current_module="enable_cache";
3748 if(!stream_enable_cache(stream,stream_cache_size*1024,
3749 stream_cache_size*1024*(stream_cache_min_percent / 100.0),
3750 stream_cache_size*1024*(stream_cache_seek_min_percent / 100.0)))
3751 if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file;
3754 //============ Open DEMUXERS --- DETECT file type =======================
3755 current_module="demux_open";
3757 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
3759 // HACK to get MOV Reference Files working
3761 if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
3763 unsigned char* playlist_entry;
3764 play_tree_t *list = NULL, *entry = NULL;
3766 current_module="handle_demux_playlist";
3767 while (ds_get_packet(demuxer->video,&playlist_entry)>0)
3769 char *temp, *bname;
3771 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
3773 bname=mp_basename(playlist_entry);
3774 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
3775 continue;
3777 if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
3778 continue;
3780 entry = play_tree_new();
3782 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
3784 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1));
3785 if (temp)
3787 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
3788 temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
3789 strcat(temp, playlist_entry);
3790 play_tree_add_file(entry,temp);
3791 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
3792 free(temp);
3795 else
3796 play_tree_add_file(entry,playlist_entry);
3798 if(!list)
3799 list = entry;
3800 else
3801 play_tree_append_entry(list,entry);
3803 free_demuxer(demuxer);
3804 demuxer = NULL;
3806 if (list)
3808 entry = play_tree_new();
3809 play_tree_set_child(entry,list);
3810 eof=playtree_add_playlist(entry);
3811 goto goto_next_file;
3815 if(!demuxer)
3817 #if 0
3818 play_tree_t* entry;
3819 // Handle playlist
3820 current_module="handle_playlist";
3821 switch(stream->type){
3822 case STREAMTYPE_VCD:
3823 case STREAMTYPE_DVD:
3824 case STREAMTYPE_CDDA:
3825 case STREAMTYPE_VCDBINCUE:
3826 // don't try to parse raw media as playlist, it's unlikely
3827 goto goto_next_file;
3829 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FallingBackOnPlaylist,filename);
3830 stream_reset(stream);
3831 stream_seek(stream,stream->start_pos);
3832 entry = parse_playtree(stream,0);
3833 if(!entry)
3834 mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
3835 else
3836 eof=playtree_add_playlist(entry);
3837 #endif
3838 goto goto_next_file;
3840 inited_flags|=INITED_DEMUXER;
3842 if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
3843 // setup global sub numbering
3844 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
3845 global_sub_size += demux_mkv_num_subs(demuxer);
3847 #ifdef HAVE_OGGVORBIS
3848 if (demuxer->type==DEMUXER_TYPE_OGG) {
3849 // setup global sub numbering
3850 global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
3851 global_sub_size += demux_ogg_num_subs(demuxer);
3853 #endif
3855 current_module="demux_open2";
3857 //file_format=demuxer->file_format;
3859 d_audio=demuxer->audio;
3860 d_video=demuxer->video;
3861 d_dvdsub=demuxer->sub;
3863 // DUMP STREAMS:
3864 if((stream_dump_type)&&(stream_dump_type<4)){
3865 FILE *f;
3866 demux_stream_t *ds=NULL;
3867 current_module="dump";
3868 // select stream to dump
3869 switch(stream_dump_type){
3870 case 1: ds=d_audio;break;
3871 case 2: ds=d_video;break;
3872 case 3: ds=d_dvdsub;break;
3874 if(!ds){
3875 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
3876 exit_player(MSGTR_Exit_error);
3878 // disable other streams:
3879 if(d_audio && d_audio!=ds) {ds_free_packs(d_audio); d_audio->id=-2; }
3880 if(d_video && d_video!=ds) {ds_free_packs(d_video); d_video->id=-2; }
3881 if(d_dvdsub && d_dvdsub!=ds) {ds_free_packs(d_dvdsub); d_dvdsub->id=-2; }
3882 // let's dump it!
3883 f=fopen(stream_dump_name,"wb");
3884 if(!f){
3885 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
3886 exit_player(MSGTR_Exit_error);
3888 while(!ds->eof){
3889 unsigned char* start;
3890 int in_size=ds_get_packet(ds,&start);
3891 if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
3892 && stream_dump_type==2) fwrite(&in_size,1,4,f);
3893 if(in_size>0) fwrite(start,in_size,1,f);
3895 fclose(f);
3896 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
3897 exit_player_with_rc(MSGTR_Exit_eof, 0);
3900 sh_audio=d_audio->sh;
3901 sh_video=d_video->sh;
3903 if(sh_video){
3905 current_module="video_read_properties";
3906 if(!video_read_properties(sh_video)) {
3907 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties);
3908 sh_video=d_video->sh=NULL;
3909 } else {
3910 mp_msg(MSGT_CPLAYER,MSGL_V,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n",
3911 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
3912 sh_video->fps,sh_video->frametime
3915 /* need to set fps here for output encoders to pick it up in their init */
3916 if(force_fps){
3917 sh_video->fps=force_fps;
3918 sh_video->frametime=1.0f/sh_video->fps;
3920 vo_fps = sh_video->fps;
3922 if(!sh_video->fps && !force_fps){
3923 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified);
3924 sh_video=d_video->sh=NULL;
3930 fflush(stdout);
3932 if(!sh_video && !sh_audio){
3933 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound);
3934 #ifdef HAS_DVBIN_SUPPORT
3935 if((stream->type == STREAMTYPE_DVB) && stream->priv)
3937 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
3938 if(priv->is_on)
3940 int dir;
3941 int v = last_dvb_step;
3942 if(v > 0)
3943 dir = DVB_CHANNEL_HIGHER;
3944 else
3945 dir = DVB_CHANNEL_LOWER;
3947 if(dvb_step_channel(priv, dir))
3948 eof = dvbin_reopen = 1;
3951 #endif
3952 goto goto_next_file; // exit_player(MSGTR_Exit_error);
3955 /* display clip info */
3956 demux_info_print(demuxer);
3958 //================== Read SUBTITLES (DVD & TEXT) ==========================
3959 if(vo_spudec==NULL && sh_video &&
3960 (stream->type==STREAMTYPE_DVD || demuxer->type==DEMUXER_TYPE_MATROSKA ||
3961 d_dvdsub->id >= 0)){
3963 if (spudec_ifo) {
3964 unsigned int palette[16], width, height;
3965 current_module="spudec_init_vobsub";
3966 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
3967 vo_spudec=spudec_new_scaled(palette, width, height);
3970 #ifdef USE_DVDREAD
3971 if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) {
3972 current_module="spudec_init_dvdread";
3973 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
3974 sh_video->disp_w, sh_video->disp_h);
3976 #endif
3978 if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) &&
3979 (d_dvdsub->sh != NULL) && (((sh_sub_t *)d_dvdsub->sh)->type == 'v')) {
3980 sh_sub_t *mkv_sh_sub = (sh_sub_t *)d_dvdsub->sh;
3981 current_module = "spudec_init_matroska";
3982 vo_spudec =
3983 spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors,
3984 mkv_sh_sub->custom_colors, mkv_sh_sub->width,
3985 mkv_sh_sub->height);
3986 forced_subs_only = mkv_sh_sub->forced_subs_only;
3989 if (vo_spudec==NULL) {
3990 current_module="spudec_init_normal";
3991 vo_spudec=spudec_new_scaled(NULL, sh_video->disp_w, sh_video->disp_h);
3992 spudec_set_font_factor(vo_spudec,font_factor);
3995 if (vo_spudec!=NULL)
3996 inited_flags|=INITED_SPUDEC;
4000 // Apply current settings for forced subs
4001 if (vo_spudec!=NULL)
4002 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
4004 #ifdef USE_SUB
4005 if(sh_video) {
4006 // after reading video params we should load subtitles because
4007 // we know fps so now we can adjust subtitle time to ~6 seconds AST
4008 // check .sub
4009 current_module="read_subtitles_file";
4010 if(sub_name){
4011 for (i = 0; sub_name[i] != NULL; ++i)
4012 add_subtitles (sub_name[i], sh_video->fps, 0);
4014 if(sub_auto) { // auto load sub file ...
4015 char *psub = get_path( "sub/" );
4016 char **tmp = sub_filenames((psub ? psub : ""), filename);
4017 int i = 0;
4018 free(psub); // release the buffer created by get_path() above
4019 while (tmp[i]) {
4020 add_subtitles (tmp[i], sh_video->fps, 0);
4021 free(tmp[i++]);
4023 free(tmp);
4025 if (set_of_sub_size > 0) {
4026 // setup global sub numbering
4027 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size; // the global # of the first sub.
4028 global_sub_size += set_of_sub_size;
4031 #endif /* USE_SUB */
4033 if (global_sub_size) {
4034 // find the best sub to use
4035 if (vobsub_id >= 0) {
4036 // if user asks for a vobsub id, use that first.
4037 global_sub_pos = global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_id;
4038 } else if (dvdsub_id >= 0 && global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4039 // if user asks for a dvd sub id, use that next.
4040 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX] + dvdsub_id;
4041 } else if (global_sub_indices[SUB_SOURCE_SUBS] >= 0) {
4042 // if there are text subs to use, use those. (autosubs come last here)
4043 global_sub_pos = global_sub_indices[SUB_SOURCE_SUBS];
4045 } else if (global_sub_indices[SUB_SOURCE_DEMUX] >= 0) {
4046 // if nothing else works, get subs from the demuxer.
4047 global_sub_pos = global_sub_indices[SUB_SOURCE_DEMUX];
4049 } else {
4050 // nothing worth doing automatically.
4051 global_sub_pos = -1;
4053 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
4054 global_sub_pos--;
4055 mp_property_do("sub",M_PROPERTY_STEP_UP,NULL);
4056 if(subdata)
4057 switch (stream_dump_type) {
4058 case 3: list_sub_file(subdata); break;
4059 case 4: dump_mpsub(subdata, sh_video->fps); break;
4060 case 6: dump_srt(subdata, sh_video->fps); break;
4061 case 7: dump_microdvd(subdata, sh_video->fps); break;
4062 case 8: dump_jacosub(subdata, sh_video->fps); break;
4063 case 9: dump_sami(subdata, sh_video->fps); break;
4067 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n", filename);
4068 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_DEMUXER=%s\n", demuxer->desc->name);
4069 if (sh_video) {
4070 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4071 if (sh_video->format >= 0x20202020)
4072 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", (char *)&sh_video->format);
4073 else
4074 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", sh_video->format);
4075 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", sh_video->i_bps*8);
4076 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
4077 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
4078 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", sh_video->fps);
4079 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", sh_video->aspect);
4081 if (sh_audio) {
4082 /* Assume FOURCC if all bytes >= 0x20 (' ') */
4083 if (sh_audio->format >= 0x20202020)
4084 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&sh_audio->format);
4085 else
4086 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", sh_audio->format);
4087 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", sh_audio->i_bps*8);
4088 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
4089 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
4091 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
4093 if(!sh_video) goto main; // audio-only
4095 //================== Init VIDEO (codec & libvo) ==========================
4096 if(!fixed_vo || !(inited_flags&INITED_VO)){
4097 current_module="preinit_libvo";
4099 vo_config_count=0;
4100 //if((video_out->preinit(vo_subdevice))!=0){
4101 if(!(video_out=init_best_video_out(video_driver_list))){
4102 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
4103 goto goto_next_file; // exit_player(MSGTR_Exit_error);
4105 sh_video->video_out=video_out;
4106 inited_flags|=INITED_VO;
4109 vf_vo_data.vo = video_out;
4110 current_module="init_video_filters";
4112 char* vf_arg[] = { "_oldargs_", (char*)&vf_vo_data , NULL };
4113 sh_video->vfilter=(void*)vf_open_filter(NULL,"vo",vf_arg);
4115 #ifdef HAVE_MENU
4116 if(use_menu) {
4117 char* vf_arg[] = { "_oldargs_", menu_root, NULL };
4118 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg);
4119 if(!vf_menu) {
4120 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root);
4121 use_menu = 0;
4124 if(vf_menu)
4125 sh_video->vfilter=(void*)vf_menu;
4126 #endif
4127 #ifdef USE_ASS
4128 if(ass_enabled) {
4129 int i;
4130 int insert = 1;
4131 if (vf_settings)
4132 for (i = 0; vf_settings[i].name; ++i)
4133 if (strcmp(vf_settings[i].name, "ass") == 0) {
4134 insert = 0;
4135 break;
4137 if (insert) {
4138 extern vf_info_t vf_info_ass;
4139 vf_info_t* libass_vfs[] = {&vf_info_ass, NULL};
4140 char* vf_arg[] = {"auto", "1", NULL};
4141 vf_instance_t* vf_ass = vf_open_plugin(libass_vfs,sh_video->vfilter,"ass",vf_arg);
4142 if (vf_ass)
4143 sh_video->vfilter=(void*)vf_ass;
4144 else
4145 mp_msg(MSGT_CPLAYER,MSGL_ERR, "ASS: cannot add video filter\n");
4148 #endif
4149 sh_video->vfilter=(void*)append_filters(sh_video->vfilter);
4151 #ifdef USE_ASS
4152 if (ass_enabled)
4153 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_INIT_EOSD, ass_library);
4154 #endif
4156 current_module="init_video_codec";
4158 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
4159 init_best_video_codec(sh_video,video_codec_list,video_fm_list);
4160 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
4162 if(!sh_video->inited){
4163 if(!fixed_vo) uninit_player(INITED_VO);
4164 if(!sh_audio) goto goto_next_file;
4165 sh_video = d_video->sh = NULL;
4166 goto main; // exit_player(MSGTR_Exit_error);
4169 inited_flags|=INITED_VCODEC;
4171 if (sh_video->codec)
4172 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", sh_video->codec->name);
4174 if(auto_quality>0){
4175 // Auto quality option enabled
4176 output_quality=get_video_quality_max(sh_video);
4177 if(auto_quality>output_quality) auto_quality=output_quality;
4178 else output_quality=auto_quality;
4179 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality);
4180 set_video_quality(sh_video,output_quality);
4183 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============
4185 current_module="init_vo";
4187 if(vo_flags & 0x08 && vo_spudec)
4188 spudec_set_hw_spu(vo_spudec,video_out);
4190 #ifdef HAVE_FREETYPE
4191 force_load_font = 1;
4192 #endif
4194 //================== MAIN: ==========================
4195 main:
4196 current_module="main";
4198 if(playing_msg) {
4199 char* msg = m_properties_expand_string(mp_properties,playing_msg);
4200 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",msg);
4201 free(msg);
4205 // Disable the term OSD in verbose mode
4206 if(verbose) term_osd = 0;
4207 fflush(stdout);
4210 //int frame_corr_num=0; //
4211 //float v_frame=0; // Video
4212 float time_frame=0; // Timer
4213 //float num_frames=0; // number of frames played
4214 double last_pts = MP_NOPTS_VALUE;
4215 int grab_frames=0;
4216 int drop_frame=0; // current dropping status
4217 int dropped_frames=0; // how many frames dropped since last non-dropped frame
4219 float next_frame_time=0;
4220 int frame_time_remaining=0; // flag
4221 int blit_frame=0;
4222 int was_paused=0;
4224 // Make sure old OSD does not stay around,
4225 // e.g. with -fixed-vo and same-resolution files
4226 clear_osd_msgs();
4227 update_osd_msg();
4229 //================ SETUP AUDIO ==========================
4231 if(sh_audio){
4232 reinit_audio_chain();
4233 if (sh_audio && sh_audio->codec)
4234 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", sh_audio->codec->name);
4237 current_module="av_init";
4239 if(sh_video){
4240 sh_video->timer=0;
4241 if (! ignore_start)
4242 audio_delay += sh_video->stream_delay;
4244 if(sh_audio){
4245 if (! ignore_start)
4246 audio_delay -= sh_audio->stream_delay;
4247 sh_audio->delay=-audio_delay;
4250 if(!sh_audio){
4251 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound);
4252 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",d_audio->packs);
4253 ds_free_packs(d_audio); // free buffered chunks
4254 //d_audio->id=-2; // do not read audio chunks
4255 //uninit_player(INITED_AO); // close device
4257 if(!sh_video){
4258 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo);
4259 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",d_video->packs);
4260 ds_free_packs(d_video);
4261 d_video->id=-2;
4262 //if(!fixed_vo) uninit_player(INITED_VO);
4265 if (!sh_video && !sh_audio)
4266 goto goto_next_file;
4268 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
4269 if(force_fps && sh_video){
4270 vo_fps = sh_video->fps=force_fps;
4271 sh_video->frametime=1.0f/sh_video->fps;
4272 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,sh_video->fps,sh_video->frametime);
4275 #ifdef HAVE_NEW_GUI
4276 if ( use_gui ) {
4277 if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
4278 if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 );
4279 guiGetEvent( guiSetFileFormat,(char *)demuxer->file_format );
4280 if ( guiGetEvent( guiSetValues,(char *)sh_video ) ) goto goto_next_file;
4281 guiGetEvent( guiSetDemuxer,(char *)demuxer );
4283 #endif
4285 //==================== START PLAYING =======================
4287 if(loop_times>1) loop_times--; else
4288 if(loop_times==1) loop_times = -1;
4290 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying);fflush(stdout);
4292 total_time_usage_start=GetTimer();
4293 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
4294 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark
4295 play_n_frames=play_n_frames_mf;
4297 if(play_n_frames==0){
4298 eof=PT_NEXT_ENTRY; goto goto_next_file;
4301 while(!eof){
4302 float aq_sleep_time=0;
4303 if(!sh_audio && d_audio->sh) {
4304 sh_audio = d_audio->sh;
4305 sh_audio->ds = d_audio;
4306 reinit_audio_chain();
4309 /*========================== PLAY AUDIO ============================*/
4311 if (sh_audio)
4312 if (!fill_audio_out_buffers())
4313 // at eof, all audio at least written to ao
4314 if (!sh_video)
4315 eof = PT_NEXT_ENTRY;
4318 if(!sh_video) {
4319 // handle audio-only case:
4320 double a_pos=0;
4321 if(!quiet || end_at.type == END_AT_TIME )
4322 a_pos = playing_audio_pts(sh_audio, d_audio, audio_out);
4324 if(!quiet)
4325 print_status(a_pos, 0, 0);
4327 if(end_at.type == END_AT_TIME && end_at.pos < a_pos)
4328 eof = PT_NEXT_ENTRY;
4329 update_osd_msg();
4331 } else {
4333 /*========================== PLAY VIDEO ============================*/
4335 float frame_time=next_frame_time;
4337 vo_pts=sh_video->timer*90000.0;
4338 vo_fps=sh_video->fps;
4340 if(!frame_time_remaining){
4341 //-------------------- Decode a frame: -----------------------
4342 blit_frame = 0; // Don't blit if we hit EOF
4343 if (!correct_pts) while(1)
4344 { unsigned char* start=NULL;
4345 int in_size;
4346 // get it!
4347 current_module="video_read_frame";
4348 in_size=video_read_frame(sh_video,&next_frame_time,&start,force_fps);
4349 if(in_size<0){ eof=1; break; }
4350 if(in_size>max_framesize) max_framesize=in_size; // stats
4351 sh_video->timer+=frame_time;
4352 if(sh_audio) sh_audio->delay-=frame_time;
4353 time_frame += frame_time / playback_speed; // for nosound
4354 // video_read_frame can change fps (e.g. for ASF video)
4355 vo_fps = sh_video->fps;
4356 // check for frame-drop:
4357 current_module="check_framedrop";
4358 if(sh_audio && !d_audio->eof){
4359 float delay=playback_speed*audio_out->get_delay();
4360 float d=delay-sh_audio->delay;
4361 // we should avoid dropping too many frames in sequence unless we
4362 // are too late. and we allow 100ms A-V delay here:
4363 if(d<-dropped_frames*frame_time-0.100 && osd_function != OSD_PAUSE){
4364 drop_frame=frame_dropping;
4365 ++drop_frame_cnt;
4366 ++dropped_frames;
4367 } else {
4368 drop_frame=dropped_frames=0;
4370 ++total_frame_cnt;
4372 // decode:
4373 current_module="decode_video";
4374 // printf("Decode! %p %d \n",start,in_size);
4375 update_osd_msg();
4376 void *decoded_frame = decode_video(sh_video,start,in_size,drop_frame, sh_video->pts);
4377 blit_frame = (decoded_frame && filter_video(sh_video, decoded_frame,
4378 sh_video->pts));
4379 break;
4381 else while (1) {
4382 if (!generate_video_frame(sh_video, d_video)) {
4383 eof = 1;
4384 break;
4386 sh_video->pts = vf_vo_data.pts;
4387 if (sh_video->pts == MP_NOPTS_VALUE) {
4388 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts after filters MISSING\n");
4389 sh_video->pts = last_pts;
4391 if (last_pts == MP_NOPTS_VALUE)
4392 last_pts = sh_video->pts;
4393 else if (last_pts >= sh_video->pts) {
4394 last_pts = sh_video->pts;
4395 mp_msg(MSGT_CPLAYER, MSGL_WARN, "pts value <= previous");
4397 frame_time = sh_video->pts - last_pts;
4398 last_pts = sh_video->pts;
4399 sh_video->timer += frame_time;
4400 time_frame += frame_time / playback_speed; // for nosound
4401 if(sh_audio)
4402 sh_audio->delay -= frame_time;
4403 blit_frame = 1;
4404 break;
4407 //------------------------ frame decoded. --------------------
4409 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
4411 if(sh_video->vf_inited<0){
4412 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NotInitializeVOPorVO);
4413 eof=1; goto goto_next_file;
4418 // ==========================================================================
4420 // current_module="draw_osd";
4421 // if(vo_config_count) video_out->draw_osd();
4423 #ifdef HAVE_NEW_GUI
4424 if(use_gui) guiEventHandling();
4425 #endif
4427 current_module="vo_check_events";
4428 if (vo_config_count) video_out->check_events();
4430 #ifdef HAVE_X11
4431 if (stop_xscreensaver) {
4432 current_module = "stop_xscreensaver";
4433 xscreensaver_heartbeat();
4435 #endif
4437 frame_time_remaining = sleep_until_update(&time_frame, &aq_sleep_time);
4439 //====================== FLIP PAGE (VIDEO BLT): =========================
4441 current_module="flip_page";
4442 if (!frame_time_remaining && blit_frame) {
4443 unsigned int t2=GetTimer();
4445 if(vo_config_count) video_out->flip_page();
4447 vout_time_usage += (GetTimer() - t2) * 0.000001;
4449 //====================== A-V TIMESTAMP CORRECTION: =========================
4451 adjust_sync_and_print_status(frame_time_remaining, time_frame);
4453 //============================ Auto QUALITY ============================
4455 /*Output quality adjustments:*/
4456 if(auto_quality>0){
4457 current_module="autoq";
4458 // float total=0.000001f * (GetTimer()-aq_total_time);
4459 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total)
4460 if(output_quality<auto_quality && aq_sleep_time>0)
4461 ++output_quality;
4462 else
4463 // if(output_quality>0 && aq_sleep_time<-0.05f*total)
4464 if(output_quality>1 && aq_sleep_time<0)
4465 --output_quality;
4466 else
4467 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms
4468 output_quality=0;
4469 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality);
4470 set_video_quality(sh_video,output_quality);
4473 if (play_n_frames >= 0 && !frame_time_remaining && blit_frame) {
4474 --play_n_frames;
4475 if (play_n_frames <= 0) eof = PT_NEXT_ENTRY;
4479 // FIXME: add size based support for -endpos
4480 if (end_at.type == END_AT_TIME &&
4481 !frame_time_remaining && end_at.pos <= sh_video->pts)
4482 eof = PT_NEXT_ENTRY;
4484 } // end if(sh_video)
4486 //============================ Handle PAUSE ===============================
4488 current_module="pause";
4490 #ifdef USE_OSD
4491 if(osd_visible){
4492 // 36000000 means max timed visibility is 1 hour into the future, if
4493 // the difference is greater assume it's wrapped around from below 0
4494 if (osd_visible - GetTimerMS() > 36000000) {
4495 osd_visible = 0;
4496 vo_osd_progbar_type=-1; // disable
4497 vo_osd_changed(OSDTYPE_PROGBAR);
4498 if (osd_function != OSD_PAUSE)
4499 osd_function = OSD_PLAY;
4502 #endif
4504 if(osd_function==OSD_PAUSE){
4505 mp_cmd_t* cmd;
4506 if(!quiet) {
4507 // Small hack to display the pause message on the OSD line.
4508 // The pause string is: "\n == PAUSE == \r" so we need to
4509 // take the first and the last char out
4510 if(use_term_osd) {
4511 char msg[128] = MSGTR_Paused;
4512 int mlen = strlen(msg);
4513 msg[mlen-1] = '\0';
4514 set_osd_msg(OSD_MSG_PAUSE,1,0,"%s",msg+1);
4515 update_osd_msg();
4516 } else
4517 mp_msg(MSGT_CPLAYER,MSGL_STATUS,MSGTR_Paused);
4518 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_PAUSED\n");
4519 fflush(stdout);
4521 #ifdef HAVE_NEW_GUI
4522 if(use_gui) guiGetEvent( guiCEvent,(char *)guiSetPause );
4523 #endif
4524 if (video_out && sh_video && vo_config_count)
4525 video_out->control(VOCTRL_PAUSE, NULL);
4527 if (audio_out && sh_audio)
4528 audio_out->pause(); // pause audio, keep data if possible
4530 while( (cmd = mp_input_get_cmd(20,1,1)) == NULL) {
4531 if(sh_video && video_out && vo_config_count) video_out->check_events();
4532 #ifdef HAVE_NEW_GUI
4533 if(use_gui){
4534 guiEventHandling();
4535 guiGetEvent( guiReDraw,NULL );
4536 if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
4538 #endif
4539 #ifdef HAVE_MENU
4540 if(vf_menu)
4541 vf_menu_pause_update(vf_menu);
4542 #endif
4543 usec_sleep(20000);
4545 if (cmd && cmd->id == MP_CMD_PAUSE) {
4546 cmd = mp_input_get_cmd(0,1,0);
4547 mp_cmd_free(cmd);
4549 osd_function=OSD_PLAY;
4550 if (audio_out && sh_audio)
4551 audio_out->resume(); // resume audio
4552 if (video_out && sh_video && vo_config_count)
4553 video_out->control(VOCTRL_RESUME, NULL); // resume video
4554 (void)GetRelativeTime(); // keep TF around FT in next cycle
4555 #ifdef HAVE_NEW_GUI
4556 if (use_gui)
4558 if ( guiIntfStruct.Playing == guiSetStop ) goto goto_next_file;
4559 guiGetEvent( guiCEvent,(char *)guiSetPlay );
4561 #endif
4562 was_paused = 1;
4565 // handle -sstep
4566 if(step_sec>0) {
4567 osd_function=OSD_FFW;
4568 rel_seek_secs+=step_sec;
4571 //================= EDL =========================================
4573 if( next_edl_record ) { // Are we (still?) doing EDL?
4574 if ( !sh_video ) {
4575 mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
4576 free_edl(edl_records);
4577 next_edl_record = NULL;
4578 edl_records = NULL;
4579 } else {
4580 if( sh_video->pts >= next_edl_record->start_sec ) {
4581 if( next_edl_record->action == EDL_SKIP ) {
4582 osd_function = OSD_FFW;
4583 abs_seek_pos = 0;
4584 rel_seek_secs = next_edl_record->length_sec;
4585 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: start [%f], stop [%f], length [%f]\n", next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec );
4586 edl_decision = 1;
4587 } else if( next_edl_record->action == EDL_MUTE ) {
4588 edl_muted = !edl_muted;
4589 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
4590 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
4592 next_edl_record=next_edl_record->next;
4597 //================= Keyboard events, SEEKing ====================
4599 current_module="key_events";
4602 mp_cmd_t* cmd;
4603 int brk_cmd = 0;
4604 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
4605 if(!set_property_command(cmd))
4606 switch(cmd->id) {
4607 case MP_CMD_SEEK : {
4608 float v;
4609 int abs;
4610 if(sh_video)
4611 osd_show_percentage = sh_video->fps;
4612 v = cmd->args[0].v.f;
4613 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
4614 if(abs==2) { /* Absolute seek to a specific timestamp in seconds */
4615 abs_seek_pos = 1;
4616 if(sh_video)
4617 osd_function= (v > sh_video->pts) ? OSD_FFW : OSD_REW;
4618 rel_seek_secs = v;
4620 else if(abs) { /* Absolute seek by percentage */
4621 abs_seek_pos = 3;
4622 if(sh_video)
4623 osd_function= OSD_FFW; // Direction isn't set correctly
4624 rel_seek_secs = v/100.0;
4626 else {
4627 rel_seek_secs+= v;
4628 osd_function= (v > 0) ? OSD_FFW : OSD_REW;
4630 brk_cmd = 1;
4631 } break;
4632 case MP_CMD_SET_PROPERTY: {
4633 m_option_t* prop = mp_property_find(cmd->args[0].v.s);
4634 if(!prop) mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unkown property: '%s'\n",cmd->args[0].v.s);
4635 else if(m_property_parse(prop,cmd->args[1].v.s) <= 0)
4636 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to set property '%s' to '%s'.\n",
4637 cmd->args[0].v.s,cmd->args[1].v.s);
4639 } break;
4640 case MP_CMD_GET_PROPERTY: {
4641 m_option_t* prop;
4642 void* val;
4643 prop = mp_property_find(cmd->args[0].v.s);
4644 if(!prop) {
4645 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Unkown property: '%s'\n",cmd->args[0].v.s);
4646 break;
4648 /* Use m_option_print directly to get easily parseable values. */
4649 val = calloc(1,prop->type->size);
4650 if(m_property_do(prop,M_PROPERTY_GET,val) <= 0) {
4651 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to get value of property '%s'.\n",
4652 cmd->args[0].v.s);
4653 break;
4655 tmp = m_option_print(prop,val);
4656 if(!tmp || tmp == (char*)-1) {
4657 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Failed to print value of property '%s'.\n",
4658 cmd->args[0].v.s);
4659 break;
4661 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_%s=%s\n",cmd->args[0].v.s,tmp);
4662 free(tmp);
4663 } break;
4664 case MP_CMD_EDL_MARK:
4665 if( edl_fd ) {
4666 float v = sh_video ? sh_video->pts :
4667 playing_audio_pts(sh_audio, d_audio, audio_out);
4669 if(begin_skip == MP_NOPTS_VALUE)
4671 begin_skip = v;
4672 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
4673 }else{
4674 if(begin_skip > v)
4676 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
4677 }else{
4678 fprintf(edl_fd, "%f %f %d\n", begin_skip, v, 0);
4679 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
4681 begin_skip = MP_NOPTS_VALUE;
4684 break;
4685 case MP_CMD_SWITCH_RATIO : {
4686 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
4687 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
4688 else
4689 movie_aspect = cmd->args[0].v.f;
4690 mpcodecs_config_vo (sh_video, sh_video->disp_w, sh_video->disp_h, 0);
4691 } break;
4692 case MP_CMD_SPEED_INCR : {
4693 float v = cmd->args[0].v.f;
4694 playback_speed += v;
4695 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4696 build_afilter_chain(sh_audio, &ao_data);
4697 } break;
4698 case MP_CMD_SPEED_MULT : {
4699 float v = cmd->args[0].v.f;
4700 playback_speed *= v;
4701 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4702 build_afilter_chain(sh_audio, &ao_data);
4703 } break;
4704 case MP_CMD_SPEED_SET : {
4705 float v = cmd->args[0].v.f;
4706 playback_speed = v;
4707 set_osd_msg(OSD_MSG_SPEED,1,osd_duration,MSGTR_OSDSpeed, playback_speed);
4708 build_afilter_chain(sh_audio, &ao_data);
4709 } break;
4710 case MP_CMD_FRAME_STEP :
4711 case MP_CMD_PAUSE : {
4712 cmd->pausing = 1;
4713 brk_cmd = 1;
4714 } break;
4715 case MP_CMD_FILE_FILTER : {
4716 file_filter = cmd->args[0].v.i;
4717 break;
4719 case MP_CMD_QUIT : {
4720 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
4722 case MP_CMD_GRAB_FRAMES : {
4723 grab_frames=2;
4724 } break;
4725 case MP_CMD_PLAY_TREE_STEP : {
4726 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
4727 int force = cmd->args[1].v.i;
4729 #ifdef HAVE_NEW_GUI
4730 if (use_gui) {
4731 int i=0;
4732 if (n>0)
4733 for (i=0;i<n;i++)
4734 mplNext();
4735 else
4736 for (i=0;i<-1*n;i++)
4737 mplPrev();
4738 } else
4739 #endif
4741 if(!force && playtree_iter) {
4742 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
4744 if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
4745 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
4746 play_tree_iter_free(i);
4747 } else
4748 eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
4749 if(eof)
4750 play_tree_step = n;
4751 brk_cmd = 1;
4753 } break;
4754 case MP_CMD_PLAY_TREE_UP_STEP : {
4755 int n = cmd->args[0].v.i > 0 ? 1 : -1;
4756 int force = cmd->args[1].v.i;
4758 if(!force && playtree_iter) {
4759 play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
4760 if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
4761 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
4762 play_tree_iter_free(i);
4763 } else
4764 eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
4765 brk_cmd = 1;
4766 } break;
4767 case MP_CMD_PLAY_ALT_SRC_STEP : {
4768 if(playtree_iter && playtree_iter->num_files > 1) {
4769 int v = cmd->args[0].v.i;
4770 if(v > 0 && playtree_iter->file < playtree_iter->num_files)
4771 eof = PT_NEXT_SRC;
4772 else if(v < 0 && playtree_iter->file > 1)
4773 eof = PT_PREV_SRC;
4775 brk_cmd = 1;
4776 } break;
4777 case MP_CMD_SUB_STEP : {
4778 #ifdef USE_SUB
4779 if (sh_video) {
4780 int movement = cmd->args[0].v.i;
4781 step_sub(subdata, sh_video->pts, movement);
4782 #ifdef USE_ASS
4783 if (ass_track)
4784 sub_delay += ass_step_sub(ass_track, (sh_video->pts + sub_delay) * 1000 + .5, movement) / 1000.;
4785 #endif
4786 set_osd_msg(OSD_MSG_SUB_DELAY,1,osd_duration,
4787 MSGTR_OSDSubDelay, ROUND(sub_delay*1000));
4789 #endif
4790 } break;
4791 case MP_CMD_SUB_LOG : {
4792 #ifdef USE_SUB
4793 log_sub();
4794 #endif
4795 } break;
4796 case MP_CMD_OSD : {
4797 int v = cmd->args[0].v.i;
4798 int max = use_term_osd ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
4799 if(osd_level > max) osd_level = max;
4800 if(v < 0)
4801 osd_level=(osd_level+1)%(max+1);
4802 else
4803 osd_level= v > max ? max : v;
4804 /* Show OSD state when disabled, but not when an explicit
4805 argument is given to the OSD command, i.e. in slave mode. */
4806 if (v == -1 && osd_level <= 1)
4807 set_osd_msg(OSD_MSG_OSD_STATUS,0,osd_duration,
4808 MSGTR_OSDosd, osd_level ? MSGTR_OSDenabled : MSGTR_OSDdisabled);
4809 else
4810 rm_osd_msg(OSD_MSG_OSD_STATUS);
4811 } break;
4812 case MP_CMD_OSD_SHOW_TEXT : {
4813 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
4814 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
4815 "%-.63s",cmd->args[0].v.s);
4816 } break;
4817 case MP_CMD_OSD_SHOW_PROPERTY_TEXT : {
4818 char* txt = m_properties_expand_string(mp_properties,cmd->args[0].v.s);
4819 /* if no argument supplied take default osd_duration, else <arg> ms. */
4820 if(txt) {
4821 set_osd_msg(OSD_MSG_TEXT,cmd->args[2].v.i,
4822 (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i),
4823 "%-.63s",txt);
4824 free(txt);
4826 } break;
4827 case MP_CMD_LOADFILE : {
4828 play_tree_t* e = play_tree_new();
4829 play_tree_add_file(e,cmd->args[0].v.s);
4831 if (cmd->args[1].v.i) // append
4832 play_tree_append_entry(playtree, e);
4833 else {
4834 // Go back to the starting point.
4835 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
4836 /* NOP */;
4837 play_tree_free_list(playtree->child,1);
4838 play_tree_set_child(playtree,e);
4839 play_tree_iter_step(playtree_iter,0,0);
4840 eof = PT_NEXT_SRC;
4842 brk_cmd = 1;
4843 } break;
4844 case MP_CMD_LOADLIST : {
4845 play_tree_t* e = parse_playlist_file(cmd->args[0].v.s);
4846 if(!e)
4847 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_PlaylistLoadUnable,cmd->args[0].v.s);
4848 else {
4849 if (cmd->args[1].v.i) // append
4850 play_tree_append_entry(playtree, e);
4851 else {
4852 // Go back to the starting point.
4853 while(play_tree_iter_up_step(playtree_iter,0,1) != PLAY_TREE_ITER_END)
4854 /* NOP */;
4855 play_tree_free_list(playtree->child,1);
4856 play_tree_set_child(playtree,e);
4857 play_tree_iter_step(playtree_iter,0,0);
4858 eof = PT_NEXT_SRC;
4861 brk_cmd = 1;
4862 } break;
4863 #ifdef USE_RADIO
4864 case MP_CMD_RADIO_STEP_CHANNEL : {
4865 if (demuxer->stream->type==STREAMTYPE_RADIO) {
4866 int v = cmd->args[0].v.i;
4867 if(v > 0)
4868 radio_step_channel(demuxer->stream, RADIO_CHANNEL_HIGHER);
4869 else
4870 radio_step_channel(demuxer->stream, RADIO_CHANNEL_LOWER);
4871 if (radio_get_channel_name(demuxer->stream)) {
4872 set_osd_msg(OSD_MSG_RADIO_CHANNEL,1,osd_duration,
4873 MSGTR_OSDChannel, radio_get_channel_name(demuxer->stream));
4876 } break;
4877 case MP_CMD_RADIO_SET_CHANNEL : {
4878 if (demuxer->stream->type== STREAMTYPE_RADIO) {
4879 radio_set_channel(demuxer->stream, cmd->args[0].v.s);
4880 if (radio_get_channel_name(demuxer->stream)) {
4881 set_osd_msg(OSD_MSG_RADIO_CHANNEL,1,osd_duration,
4882 MSGTR_OSDChannel, radio_get_channel_name(demuxer->stream));
4885 } break;
4886 case MP_CMD_RADIO_SET_FREQ : {
4887 if (demuxer->stream->type== STREAMTYPE_RADIO)
4888 radio_set_freq(demuxer->stream, cmd->args[0].v.f);
4889 } break;
4890 #endif
4891 #ifdef USE_TV
4892 case MP_CMD_TV_SET_FREQ : {
4893 if (file_format == DEMUXER_TYPE_TV)
4894 tv_set_freq((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.f * 16.0);
4895 } break;
4896 case MP_CMD_TV_SET_NORM : {
4897 if (file_format == DEMUXER_TYPE_TV)
4898 tv_set_norm((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
4899 } break;
4900 case MP_CMD_TV_STEP_CHANNEL : {
4901 if (file_format == DEMUXER_TYPE_TV) {
4902 int v = cmd->args[0].v.i;
4903 if(v > 0){
4904 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_HIGHER);
4905 } else {
4906 tv_step_channel((tvi_handle_t*)(demuxer->priv), TV_CHANNEL_LOWER);
4908 if (tv_channel_list) {
4909 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
4910 MSGTR_OSDChannel, tv_channel_current->name);
4911 //vo_osd_changed(OSDTYPE_SUBTITLE);
4915 #ifdef HAS_DVBIN_SUPPORT
4916 if((stream->type == STREAMTYPE_DVB) && stream->priv)
4918 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
4919 if(priv->is_on)
4921 int dir;
4922 int v = cmd->args[0].v.i;
4924 last_dvb_step = v;
4925 if(v > 0)
4926 dir = DVB_CHANNEL_HIGHER;
4927 else
4928 dir = DVB_CHANNEL_LOWER;
4931 if(dvb_step_channel(priv, dir))
4932 eof = dvbin_reopen = 1;
4935 #endif /* HAS_DVBIN_SUPPORT */
4936 break;
4937 case MP_CMD_TV_SET_CHANNEL : {
4938 if (file_format == DEMUXER_TYPE_TV) {
4939 tv_set_channel((tvi_handle_t*)(demuxer->priv), cmd->args[0].v.s);
4940 if (tv_channel_list) {
4941 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
4942 MSGTR_OSDChannel, tv_channel_current->name);
4943 //vo_osd_changed(OSDTYPE_SUBTITLE);
4946 } break;
4947 #ifdef HAS_DVBIN_SUPPORT
4948 case MP_CMD_DVB_SET_CHANNEL:
4950 if((stream->type == STREAMTYPE_DVB) && stream->priv)
4952 dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
4953 if(priv->is_on)
4955 if(priv->list->current <= cmd->args[0].v.i)
4956 last_dvb_step = 1;
4957 else
4958 last_dvb_step = -1;
4960 if(dvb_set_channel(priv, cmd->args[1].v.i, cmd->args[0].v.i))
4961 eof = dvbin_reopen = 1;
4965 break;
4966 #endif /* HAS_DVBIN_SUPPORT */
4967 case MP_CMD_TV_LAST_CHANNEL : {
4968 if (file_format == DEMUXER_TYPE_TV) {
4969 tv_last_channel((tvi_handle_t*)(demuxer->priv));
4970 if (tv_channel_list) {
4971 set_osd_msg(OSD_MSG_TV_CHANNEL,1,osd_duration,
4972 MSGTR_OSDChannel, tv_channel_current->name);
4973 //vo_osd_changed(OSDTYPE_SUBTITLE);
4976 } break;
4977 case MP_CMD_TV_STEP_NORM : {
4978 if (file_format == DEMUXER_TYPE_TV)
4979 tv_step_norm((tvi_handle_t*)(demuxer->priv));
4980 } break;
4981 case MP_CMD_TV_STEP_CHANNEL_LIST : {
4982 if (file_format == DEMUXER_TYPE_TV)
4983 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
4984 } break;
4985 #endif /* USE_TV */
4986 case MP_CMD_SUB_LOAD:
4988 #ifdef USE_SUB
4989 if (sh_video) {
4990 int n = set_of_sub_size;
4991 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
4992 if (n != set_of_sub_size) {
4993 if (global_sub_indices[SUB_SOURCE_SUBS] < 0)
4994 global_sub_indices[SUB_SOURCE_SUBS] = global_sub_size;
4995 ++global_sub_size;
4998 #endif
4999 } break;
5000 case MP_CMD_SUB_REMOVE:
5002 #ifdef USE_SUB
5003 if (sh_video) {
5004 int v = cmd->args[0].v.i;
5005 sub_data *subd;
5006 if (v < 0) {
5007 for (v = 0; v < set_of_sub_size; ++v) {
5008 subd = set_of_subtitles[v];
5009 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
5010 sub_free(subd);
5011 set_of_subtitles[v] = NULL;
5013 global_sub_indices[SUB_SOURCE_SUBS] = -1;
5014 global_sub_size -= set_of_sub_size;
5015 set_of_sub_size = 0;
5016 if (set_of_sub_pos >= 0) {
5017 global_sub_pos = -2;
5018 vo_sub_last = vo_sub = NULL;
5019 vo_osd_changed(OSDTYPE_SUBTITLE);
5020 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
5021 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5024 else if (v < set_of_sub_size) {
5025 subd = set_of_subtitles[v];
5026 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
5027 sub_free(subd);
5028 if (set_of_sub_pos == v) {
5029 global_sub_pos = -2;
5030 vo_sub_last = vo_sub = NULL;
5031 vo_osd_changed(OSDTYPE_SUBTITLE);
5032 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
5033 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
5035 else if (set_of_sub_pos > v) {
5036 --set_of_sub_pos;
5037 --global_sub_pos;
5039 while (++v < set_of_sub_size)
5040 set_of_subtitles[v - 1] = set_of_subtitles[v];
5041 --set_of_sub_size;
5042 --global_sub_size;
5043 if (set_of_sub_size <= 0)
5044 global_sub_indices[SUB_SOURCE_SUBS] = -1;
5045 set_of_subtitles[set_of_sub_size] = NULL;
5048 #endif /* USE_SUB */
5049 } break;
5050 case MP_CMD_GET_SUB_VISIBILITY:
5052 #ifdef USE_SUB
5053 if (sh_video) {
5054 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
5056 #endif
5057 } break;
5058 case MP_CMD_SCREENSHOT :
5059 if(vo_config_count){
5060 mp_msg(MSGT_CPLAYER,MSGL_INFO,"sending VFCTRL_SCREENSHOT!\n");
5061 if(CONTROL_OK!=((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SCREENSHOT, &cmd->args[0].v.i))
5062 video_out->control(VOCTRL_SCREENSHOT, NULL);
5064 break;
5065 case MP_CMD_VF_CHANGE_RECTANGLE:
5066 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
5067 break;
5069 case MP_CMD_GET_TIME_LENGTH : {
5070 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_LENGTH=%.2lf\n", demuxer_get_time_length(demuxer));
5071 } break;
5073 case MP_CMD_GET_FILENAME : {
5074 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_FILENAME='%s'\n", get_metadata (META_NAME));
5075 } break;
5077 case MP_CMD_GET_VIDEO_CODEC : {
5078 char *inf = get_metadata (META_VIDEO_CODEC);
5079 if (!inf) inf = strdup ("");
5080 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
5081 free (inf);
5082 } break;
5084 case MP_CMD_GET_VIDEO_BITRATE : {
5085 char *inf = get_metadata (META_VIDEO_BITRATE);
5086 if (!inf) inf = strdup ("");
5087 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
5088 free (inf);
5089 } break;
5091 case MP_CMD_GET_VIDEO_RESOLUTION : {
5092 char *inf = get_metadata (META_VIDEO_RESOLUTION);
5093 if (!inf) inf = strdup ("");
5094 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
5095 free (inf);
5096 } break;
5098 case MP_CMD_GET_AUDIO_CODEC : {
5099 char *inf = get_metadata (META_AUDIO_CODEC);
5100 if (!inf) inf = strdup ("");
5101 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
5102 free (inf);
5103 } break;
5105 case MP_CMD_GET_AUDIO_BITRATE : {
5106 char *inf = get_metadata (META_AUDIO_BITRATE);
5107 if (!inf) inf = strdup ("");
5108 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
5109 free (inf);
5110 } break;
5112 case MP_CMD_GET_AUDIO_SAMPLES : {
5113 char *inf = get_metadata (META_AUDIO_SAMPLES);
5114 if (!inf) inf = strdup ("");
5115 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
5116 free (inf);
5117 } break;
5119 case MP_CMD_GET_META_TITLE : {
5120 char *inf = get_metadata (META_INFO_TITLE);
5121 if (!inf) inf = strdup ("");
5122 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
5123 free (inf);
5124 } break;
5126 case MP_CMD_GET_META_ARTIST : {
5127 char *inf = get_metadata (META_INFO_ARTIST);
5128 if (!inf) inf = strdup ("");
5129 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
5130 free (inf);
5131 } break;
5133 case MP_CMD_GET_META_ALBUM : {
5134 char *inf = get_metadata (META_INFO_ALBUM);
5135 if (!inf) inf = strdup ("");
5136 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
5137 free (inf);
5138 } break;
5140 case MP_CMD_GET_META_YEAR : {
5141 char *inf = get_metadata (META_INFO_YEAR);
5142 if (!inf) inf = strdup ("");
5143 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
5144 free (inf);
5145 } break;
5147 case MP_CMD_GET_META_COMMENT : {
5148 char *inf = get_metadata (META_INFO_COMMENT);
5149 if (!inf) inf = strdup ("");
5150 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
5151 free (inf);
5152 } break;
5154 case MP_CMD_GET_META_TRACK : {
5155 char *inf = get_metadata (META_INFO_TRACK);
5156 if (!inf) inf = strdup ("");
5157 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
5158 free (inf);
5159 } break;
5161 case MP_CMD_GET_META_GENRE : {
5162 char *inf = get_metadata (META_INFO_GENRE);
5163 if (!inf) inf = strdup ("");
5164 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
5165 free (inf);
5166 } break;
5168 case MP_CMD_GET_VO_FULLSCREEN : {
5169 if(video_out && vo_config_count)
5170 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
5171 } break;
5173 case MP_CMD_GET_PERCENT_POS : {
5174 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_PERCENT_POSITION=%d\n", demuxer_get_percent_pos(demuxer));
5175 } break;
5176 case MP_CMD_GET_TIME_POS : {
5177 float pos = 0;
5178 if (sh_video)
5179 pos = sh_video->pts;
5180 else
5181 if (sh_audio && audio_out)
5182 pos = playing_audio_pts(sh_audio, d_audio, audio_out);
5183 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
5184 } break;
5185 case MP_CMD_RUN : {
5186 #ifndef __MINGW32__
5187 if(!fork()) {
5188 execl("/bin/sh","sh","-c",cmd->args[0].v.s,NULL);
5189 exit(0);
5191 #endif
5192 } break;
5193 case MP_CMD_KEYDOWN_EVENTS : {
5194 mplayer_put_key(cmd->args[0].v.i);
5195 } break;
5196 case MP_CMD_SEEK_CHAPTER : {
5197 int seek = cmd->args[0].v.i;
5198 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
5199 int chap;
5200 float next_pts = 0;
5201 int num_chapters;
5202 char *chapter_name;
5204 rel_seek_secs = 0;
5205 abs_seek_pos = 0;
5206 chap = demuxer_seek_chapter(demuxer, seek, abs, &next_pts, &num_chapters, &chapter_name);
5207 if(chap != -1) {
5208 if(next_pts > -1.0) {
5209 abs_seek_pos = 1;
5210 rel_seek_secs = next_pts;
5212 if(chapter_name) {
5213 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter,
5214 chap+1, chapter_name);
5215 free(chapter_name);
5217 } else {
5218 if (seek > 0)
5219 rel_seek_secs = 1000000000.;
5220 else
5221 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter, 0, MSGTR_Unknown);
5223 break;
5224 } break;
5225 case MP_CMD_SET_MOUSE_POS: {
5226 int button = -1, pointer_x, pointer_y;
5227 double dx, dy;
5228 pointer_x = cmd->args[0].v.i;
5229 pointer_y = cmd->args[1].v.i;
5230 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
5231 #ifdef USE_DVDNAV
5232 if(stream->type == STREAMTYPE_DVDNAV && dx > 0.0 && dy > 0.0) {
5233 pointer_x = (int) (dx * (double) sh_video->disp_w);
5234 pointer_y = (int) (dy * (double) sh_video->disp_h);
5235 mp_dvdnav_update_mouse_pos(stream, pointer_x, pointer_y, &button);
5236 if(button>0) set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button);
5238 #endif
5239 break;
5241 #ifdef USE_DVDNAV
5242 case MP_CMD_DVDNAV: {
5243 int button = -1;
5244 if(stream->type != STREAMTYPE_DVDNAV) break;
5246 if(mp_dvdnav_handle_input(stream, cmd->args[0].v.i, &button)) {
5247 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT|(fixed_vo ? INITED_VO : 0)));
5248 goto goto_enable_cache;
5249 } else if(button>0) set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button);
5250 break;
5252 #endif
5253 default : {
5254 #ifdef HAVE_NEW_GUI
5255 if ( ( use_gui )&&( cmd->id > MP_CMD_GUI_EVENTS ) ) guiGetEvent( guiIEvent,(char *)cmd->id );
5256 else
5257 #endif
5258 mp_msg(MSGT_CPLAYER, MSGL_V, "Received unknown cmd %s\n",cmd->name);
5261 switch (cmd->pausing) {
5262 case 1: // "pausing"
5263 osd_function = OSD_PAUSE;
5264 break;
5265 case 3: // "pausing_toggle"
5266 was_paused = !was_paused;
5267 // fall through
5268 case 2: // "pausing_keep"
5269 if (was_paused) osd_function = OSD_PAUSE;
5271 mp_cmd_free(cmd);
5274 was_paused = 0;
5276 if (seek_to_sec) {
5277 int a,b; float d;
5279 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3)
5280 rel_seek_secs += 3600*a +60*b +d ;
5281 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2)
5282 rel_seek_secs += 60*a +d;
5283 else if (sscanf(seek_to_sec, "%f", &d)==1)
5284 rel_seek_secs += d;
5286 seek_to_sec = NULL;
5289 if (end_at.type != END_AT_NONE) {
5290 if(end_at.type == END_AT_SIZE) {
5291 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_MPEndposNoSizeBased);
5292 end_at.type = END_AT_NONE;
5293 } else {
5294 end_at.pos += rel_seek_secs;
5298 /* Looping. */
5299 if(eof==1 && loop_times>=0) {
5300 int l = loop_times;
5301 play_tree_iter_step(playtree_iter,0,0);
5302 loop_times = l;
5303 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", loop_times,eof);
5305 if(loop_times>1) loop_times--; else
5306 if(loop_times==1) loop_times=-1;
5307 play_n_frames=play_n_frames_mf;
5308 eof=0;
5309 abs_seek_pos=3; rel_seek_secs=0; // seek to start of movie (0%)
5310 loop_seek = 1;
5313 if(rel_seek_secs || abs_seek_pos){
5314 current_module="seek";
5315 if(demux_seek(demuxer,rel_seek_secs,audio_delay,abs_seek_pos)){
5316 // success:
5317 /* FIXME there should be real seeking for vobsub */
5318 if(sh_video) sh_video->pts=d_video->pts;
5319 if (vo_vobsub)
5320 //vobsub_reset(vo_vobsub);
5321 vobsub_seek(vo_vobsub,sh_video->pts);
5322 fflush(stdout);
5324 if(sh_video){
5325 current_module="seek_video_reset";
5326 resync_video_stream(sh_video);
5327 if(vo_config_count) video_out->control(VOCTRL_RESET,NULL);
5328 sh_video->num_buffered_pts = 0;
5329 last_pts = MP_NOPTS_VALUE;
5332 if(sh_audio){
5333 current_module="seek_audio_reset";
5334 audio_out->reset(); // stop audio, throwing away buffered data
5335 sh_audio->a_buffer_len = 0;
5336 sh_audio->a_out_buffer_len = 0;
5338 // Set OSD:
5339 if(!loop_seek){
5340 if( !edl_decision )
5341 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(demuxer));
5344 if(sh_video) {
5345 c_total=0;
5346 max_pts_correction=0.1;
5347 osd_visible=(GetTimerMS() + 1000) | 1; // to revert to PLAY pointer after 1 sec
5348 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
5349 drop_frame_cnt=0;
5351 if(vo_spudec) spudec_reset(vo_spudec);
5355 * We saw a seek, have to rewind the EDL operations stack
5356 * and find the next EDL action to take care of.
5359 edl_muted = 0;
5360 next_edl_record = edl_records;
5362 while (next_edl_record)
5364 /* Trying to remember if we need to mute/unmute first;
5365 * prior EDL implementation lacks this.
5368 if (next_edl_record->start_sec >= sh_video->pts)
5369 break;
5371 if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted;
5372 next_edl_record = next_edl_record->next;
5375 if ((user_muted | edl_muted) != mixer.muted) mixer_mute(&mixer);
5377 rel_seek_secs=0;
5378 abs_seek_pos=0;
5379 frame_time_remaining=0;
5380 current_module=NULL;
5381 loop_seek=0;
5384 #ifdef HAVE_NEW_GUI
5385 if(use_gui){
5386 guiEventHandling();
5387 if(demuxer->file_format==DEMUXER_TYPE_AVI && sh_video && sh_video->video.dwLength>2){
5388 // get pos from frame number / total frames
5389 guiIntfStruct.Position=(float)d_video->pack_no*100.0f/sh_video->video.dwLength;
5390 } else {
5391 off_t len = ( demuxer->movi_end - demuxer->movi_start );
5392 off_t pos = ( demuxer->file_format == DEMUXER_TYPE_AUDIO?stream->pos:demuxer->filepos );
5393 guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len );
5395 if ( sh_video ) guiIntfStruct.TimeSec=sh_video->pts;
5396 else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay;
5397 guiIntfStruct.LengthInSec=demuxer_get_time_length(demuxer);
5398 guiGetEvent( guiReDraw,NULL );
5399 guiGetEvent( guiSetVolume,NULL );
5400 if(guiIntfStruct.Playing==0) break; // STOP
5401 if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
5402 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file;
5403 #ifdef USE_DVDREAD
5404 if ( stream->type == STREAMTYPE_DVD )
5406 dvd_priv_t * dvdp = stream->priv;
5407 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1;
5409 #endif
5411 #endif /* HAVE_NEW_GUI */
5414 //================= Update OSD ====================
5416 #ifdef USE_SUB
5417 // find sub
5418 if(subdata && sh_video && sh_video->pts>0){
5419 float pts=sh_video->pts;
5420 if(sub_fps==0) sub_fps=sh_video->fps;
5421 current_module="find_sub";
5422 if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
5423 find_sub(subdata, (pts+sub_delay) *
5424 (subdata->sub_uses_time ? 100. : sub_fps));
5425 if (vo_sub) vo_sub_last = vo_sub;
5426 // FIXME! frame counter...
5427 sub_last_pts = pts;
5429 current_module=NULL;
5431 #endif
5433 // DVD sub:
5434 if(vo_config_count && vo_spudec) {
5435 unsigned char* packet=NULL;
5436 int len,timestamp;
5437 current_module="spudec";
5438 spudec_heartbeat(vo_spudec,90000*sh_video->timer);
5439 /* Get a sub packet from the DVD or a vobsub and make a timestamp
5440 relative to sh_video->timer */
5441 while(1) {
5442 // Vobsub
5443 len = 0;
5444 if(vo_vobsub) {
5445 if(sh_video->pts+sub_delay>=0) {
5446 // The + next_frame_time is there because we'll display the sub at the next frame
5447 len = vobsub_get_packet(vo_vobsub,sh_video->pts+sub_delay+next_frame_time,(void**)&packet,&timestamp);
5448 if(len > 0) {
5449 timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
5450 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);
5453 } else {
5454 // DVD sub
5455 len = ds_get_packet_sub(d_dvdsub,(unsigned char**)&packet);
5456 if(len > 0) {
5457 float x = d_dvdsub->pts - sh_video->pts;
5458 if (x < -10 || x > 10) // prevent missing subs on pts reset
5459 timestamp = 90000*(sh_video->timer + d_dvdsub->pts + sub_delay - sh_video->pts);
5460 else timestamp = 90000*(sh_video->timer + sub_delay);
5461 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);
5464 if(len<=0 || !packet) break;
5465 if(timestamp < 0) timestamp = 0;
5466 else spudec_assemble(vo_spudec,packet,len,timestamp);
5469 /* detect wether the sub has changed or not */
5470 if(spudec_changed(vo_spudec))
5471 vo_osd_changed(OSDTYPE_SPU);
5472 current_module=NULL;
5475 } // while(!eof)
5477 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",eof);
5479 #ifdef HAS_DVBIN_SUPPORT
5480 if(dvbin_reopen)
5482 eof = 0;
5483 uninit_player(INITED_ALL-(INITED_STREAM|INITED_INPUT));
5484 cache_uninit(stream);
5485 dvbin_reopen = 0;
5486 goto goto_enable_cache;
5488 #endif
5491 goto_next_file: // don't jump here after ao/vo/getch initialization!
5493 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
5495 if(benchmark){
5496 double tot=video_time_usage+vout_time_usage+audio_time_usage;
5497 double total_time_usage;
5498 total_time_usage_start=GetTimer()-total_time_usage_start;
5499 total_time_usage = (float)total_time_usage_start*0.000001;
5500 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
5501 video_time_usage,vout_time_usage,audio_time_usage,
5502 total_time_usage-tot,total_time_usage);
5503 if(total_time_usage>0.0)
5504 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
5505 100.0*video_time_usage/total_time_usage,
5506 100.0*vout_time_usage/total_time_usage,
5507 100.0*audio_time_usage/total_time_usage,
5508 100.0*(total_time_usage-tot)/total_time_usage,
5509 100.0);
5510 if(total_frame_cnt && frame_dropping)
5511 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
5512 total_frame_cnt-drop_frame_cnt,
5513 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
5514 drop_frame_cnt,
5515 100*drop_frame_cnt/total_frame_cnt,
5516 total_frame_cnt,
5517 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
5521 // time to uninit all, except global stuff:
5522 uninit_player(INITED_ALL-(INITED_GUI+INITED_INPUT+(fixed_vo?INITED_VO:0)));
5524 #ifdef USE_SUB
5525 if ( set_of_sub_size > 0 )
5527 current_module="sub_free";
5528 for (i = 0; i < set_of_sub_size; ++i) {
5529 sub_free( set_of_subtitles[i] );
5530 #ifdef USE_ASS
5531 if ( set_of_ass_tracks[i] )
5532 ass_free_track( set_of_ass_tracks[i] );
5533 #endif
5535 set_of_sub_size = 0;
5537 vo_sub_last = vo_sub=NULL;
5538 subdata=NULL;
5539 #ifdef USE_ASS
5540 ass_track = NULL;
5541 #endif
5542 #endif
5544 if(eof == PT_NEXT_ENTRY || eof == PT_PREV_ENTRY) {
5545 eof = eof == PT_NEXT_ENTRY ? 1 : -1;
5546 if(play_tree_iter_step(playtree_iter,play_tree_step,0) == PLAY_TREE_ITER_ENTRY) {
5547 eof = 1;
5548 } else {
5549 play_tree_iter_free(playtree_iter);
5550 playtree_iter = NULL;
5552 play_tree_step = 1;
5553 } else if (eof == PT_UP_NEXT || eof == PT_UP_PREV) {
5554 eof = eof == PT_UP_NEXT ? 1 : -1;
5555 if ( playtree_iter ) {
5556 if(play_tree_iter_up_step(playtree_iter,eof,0) == PLAY_TREE_ITER_ENTRY) {
5557 eof = 1;
5558 } else {
5559 play_tree_iter_free(playtree_iter);
5560 playtree_iter = NULL;
5563 } else { // NEXT PREV SRC
5564 eof = eof == PT_PREV_SRC ? -1 : 1;
5567 if(eof == 0) eof = 1;
5569 while(playtree_iter != NULL) {
5570 filename = play_tree_iter_get_file(playtree_iter,eof);
5571 if(filename == NULL) {
5572 if( play_tree_iter_step(playtree_iter,eof,0) != PLAY_TREE_ITER_ENTRY) {
5573 play_tree_iter_free(playtree_iter);
5574 playtree_iter = NULL;
5576 } else
5577 break;
5580 #ifdef HAVE_NEW_GUI
5581 if( use_gui && !playtree_iter )
5583 #ifdef USE_DVDREAD
5584 if ( !guiIntfStruct.DiskChanged )
5585 #endif
5586 mplEnd();
5588 #endif
5590 if(use_gui || playtree_iter != NULL || player_idle_mode){
5591 if (!playtree_iter) filename = NULL;
5592 eof = 0;
5593 goto play_next_file;
5597 exit_player_with_rc(MSGTR_Exit_eof, 0);
5599 return 1;