-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmplayer.c
4158 lines (3690 loc) · 121 KB
/
mplayer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#ifdef WIN32
#define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
#include <windows.h>
#endif
#include <string.h>
#include <unistd.h>
// #include <sys/mman.h>
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/ioctl.h>
#include <sys/wait.h>
#else
#define SIGHUP 1 /* hangup */
#define SIGQUIT 3 /* quit */
#define SIGKILL 9 /* kill (cannot be caught or ignored) */
#define SIGBUS 10 /* bus error */
extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);
#endif
#include <sys/time.h>
#include <sys/stat.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <limits.h>
#include <errno.h>
#include "version.h"
#include "mp_msg.h"
#define HELP_MP_DEFINE_STATIC
#include "help_mp.h"
#include "m_option.h"
#include "m_config.h"
#include "cfg-mplayer-def.h"
#ifdef USE_SUB
#include "subreader.h"
#endif
#include "libvo/video_out.h"
#include "libvo/font_load.h"
#include "libvo/sub.h"
#ifdef HAVE_X11
#include "libvo/x11_common.h"
#endif
#include "libao2/audio_out.h"
#include "libao2/audio_plugin.h"
#include "codec-cfg.h"
#ifdef USE_DVDNAV
#include <dvdnav.h>
#endif
#ifdef USE_EDL
#include "edl.h"
#endif
#include "spudec.h"
#include "vobsub.h"
#include "osdep/getch2.h"
#include "osdep/timer.h"
#include "cpudetect.h"
#ifdef HAVE_NEW_GUI
#include "Gui/interface.h"
#endif
#include "input/input.h"
int slave_mode=0;
int verbose=0;
int identify=0;
int quiet=0;
#define ABS(x) (((x)>=0)?(x):(-(x)))
#define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
#ifdef HAVE_RTC
#include <linux/rtc.h>
#endif
#ifdef USE_TV
#include "libmpdemux/tv.h"
#endif
#ifdef HAS_DVBIN_SUPPORT
#include "libmpdemux/dvbin.h"
static int last_dvb_step = 1;
#endif
//**************************************************************************//
// Playtree
//**************************************************************************//
#include "playtree.h"
#include "playtreeparser.h"
#ifdef HAVE_NEW_GUI
extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);
extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);
#endif
play_tree_t* playtree;
play_tree_iter_t* playtree_iter = NULL;
#define PT_NEXT_ENTRY 1
#define PT_PREV_ENTRY -1
#define PT_NEXT_SRC 2
#define PT_PREV_SRC -2
#define PT_UP_NEXT 3
#define PT_UP_PREV -3
//**************************************************************************//
// Config
//**************************************************************************//
m_config_t* mconfig;
extern play_tree_t*
m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);
extern int
m_config_parse_config_file(m_config_t* config, char *conffile);
//**************************************************************************//
// Config file
//**************************************************************************//
static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
static int cfg_include(m_option_t *conf, char *filename){
return m_config_parse_config_file(mconfig, filename);
}
#include "get_path.c"
//**************************************************************************//
// XScreensaver
//**************************************************************************//
#ifdef HAVE_X11
void xscreensaver_heartbeat(void);
#endif
//**************************************************************************//
//**************************************************************************//
// Input media streaming & demultiplexer:
//**************************************************************************//
static int max_framesize=0;
#include "libmpdemux/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
//#include "parse_es.h"
#ifdef HAVE_MATROSKA
#include "libmpdemux/matroska.h"
#endif
#include "libmpcodecs/dec_audio.h"
#include "libmpcodecs/dec_video.h"
#include "libmpcodecs/mp_image.h"
#include "libmpcodecs/vf.h"
extern void vf_list_plugins();
//**************************************************************************//
//**************************************************************************//
// Common FIFO functions, and keyboard/event FIFO code
#include "fifo.c"
int noconsolecontrols=0;
//**************************************************************************//
vo_functions_t *video_out=NULL;
ao_functions_t *audio_out=NULL;
int fixed_vo=0;
int eof=0;
// benchmark:
double video_time_usage=0;
double vout_time_usage=0;
static double audio_time_usage=0;
static int total_time_usage_start=0;
static int total_frame_cnt=0;
static int drop_frame_cnt=0; // total number of dropped frames
int benchmark=0;
// options:
int auto_quality=0;
static int output_quality=0;
float playback_speed=1.0;
int use_gui=0;
#ifdef HAVE_NEW_GUI
int enqueue=0;
#endif
#define MAX_OSD_LEVEL 3
int osd_level=1;
int osd_level_saved=-1;
int osd_visible=100;
// seek:
static char *seek_to_sec=NULL;
static off_t seek_to_byte=0;
static off_t step_sec=0;
static int loop_times=-1;
static int loop_seek=0;
// A/V sync:
int autosync=0; // 30 might be a good default value.
// may be changed by GUI: (FIXME!)
float rel_seek_secs=0;
int abs_seek_pos=0;
// codecs:
char **audio_codec_list=NULL; // override audio codec
char **video_codec_list=NULL; // override video codec
char **audio_fm_list=NULL; // override audio codec family
char **video_fm_list=NULL; // override video codec family
// streaming:
int audio_id=-1;
int video_id=-1;
int dvdsub_id=-1;
int vobsub_id=-1;
char* audio_lang=NULL;
char* dvdsub_lang=NULL;
static char* spudec_ifo=NULL;
char* filename=NULL; //"MI2-Trailer.avi";
int forced_subs_only=0;
// cache2:
int stream_cache_size=-1;
#ifdef USE_STREAM_CACHE
extern int cache_fill_status;
float stream_cache_min_percent=20.0;
float stream_cache_prefill_percent=5.0;
#else
#define cache_fill_status 0
#endif
// dump:
static char *stream_dump_name="stream.dump";
int stream_dump_type=0;
// A-V sync:
static float default_max_pts_correction=-1;//0.01f;
static float max_pts_correction=0;//default_max_pts_correction;
static float c_total=0;
float audio_delay=0;
static int softsleep=0;
float force_fps=0;
static int force_srate=0;
static int audio_output_format=0;
int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode
static int play_n_frames=-1;
static int play_n_frames_mf=-1;
// screen info:
char** video_driver_list=NULL;
char** audio_driver_list=NULL;
extern char *vo_subdevice;
extern char *ao_subdevice;
// codec outfmt flags (defined in libmpcodecs/vd.c)
extern int vo_flags;
// sub:
char *font_name=NULL;
#ifdef HAVE_FONTCONFIG
extern int font_fontconfig;
#endif
float font_factor=0.75;
char **sub_name=NULL;
float sub_delay=0;
float sub_fps=0;
int sub_auto = 1;
char *vobsub_name=NULL;
/*DSP!!char *dsp=NULL;*/
int subcc_enabled=0;
int suboverlap_enabled = 1;
#ifdef USE_SUB
sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
int set_of_sub_size = 0;
int set_of_sub_pos = -1;
float sub_last_pts = -303;
#endif
int global_sub_size = 0; // this encompasses all subtitle sources
int global_sub_pos = -1; // this encompasses all subtitle sources
#define SUB_SOURCE_SUBS 0
#define SUB_SOURCE_VOBSUB 1
#define SUB_SOURCE_DEMUX 2
#define SUB_SOURCES 3
int global_sub_indices[SUB_SOURCES];
int global_sub_quiet_osd_hack = 0;
static stream_t* stream=NULL;
static demuxer_t *demuxer=NULL;
static sh_audio_t *sh_audio=NULL;
static sh_video_t *sh_video=NULL;
char* current_module=NULL; // for debugging
extern int vo_gamma_gamma;
extern int vo_gamma_brightness;
extern int vo_gamma_contrast;
extern int vo_gamma_saturation;
extern int vo_gamma_hue;
// ---
#ifdef HAVE_MENU
#include "m_struct.h"
#include "libmenu/menu.h"
extern void vf_menu_pause_update(struct vf_instance_s* vf);
extern vf_info_t vf_info_menu;
static vf_info_t* libmenu_vfs[] = {
&vf_info_menu,
NULL
};
static vf_instance_t* vf_menu = NULL;
static int use_menu = 0;
static char* menu_cfg = NULL;
static char* menu_root = "main";
#endif
#ifdef HAVE_RTC
static int nortc;
static char* rtc_device;
#endif
#ifdef USE_EDL
edl_record_ptr edl_records = NULL; ///< EDL entries memory area
edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
int edl_memory_slots = 0; ///< number of EDL entries (1 for skip + 2 for each mute)
int edl_operations = 0; ///< number of EDL operations, skip + mute
short user_muted = 0; ///< Stores whether User wanted muted mode.
short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
short edl_decision = 0; ///< 1 when an EDL operation has been made
FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode
#endif
static unsigned int inited_flags=0;
#define INITED_VO 1
#define INITED_AO 2
#define INITED_GUI 4
#define INITED_GETCH2 8
#define INITED_SPUDEC 32
#define INITED_STREAM 64
#define INITED_INPUT 128
#define INITED_VOBSUB 256
#define INITED_DEMUXER 512
#define INITED_ACODEC 1024
#define INITED_VCODEC 2048
#define INITED_ALL 0xFFFF
static void uninit_player(unsigned int mask){
mask=inited_flags&mask;
mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);
if(mask&INITED_ACODEC){
inited_flags&=~INITED_ACODEC;
current_module="uninit_acodec";
if(sh_audio) uninit_audio(sh_audio);
sh_audio=NULL;
}
if(mask&INITED_VCODEC){
inited_flags&=~INITED_VCODEC;
current_module="uninit_vcodec";
if(sh_video) uninit_video(sh_video);
sh_video=NULL;
#ifdef HAVE_MENU
vf_menu=NULL;
#endif
}
if(mask&INITED_DEMUXER){
inited_flags&=~INITED_DEMUXER;
current_module="free_demuxer";
if(demuxer){
stream=demuxer->stream;
free_demuxer(demuxer);
}
demuxer=NULL;
}
// kill the cache process:
if(mask&INITED_STREAM){
inited_flags&=~INITED_STREAM;
current_module="uninit_stream";
if(stream) free_stream(stream);
stream=NULL;
}
if(mask&INITED_VO){
inited_flags&=~INITED_VO;
current_module="uninit_vo";
video_out->uninit();
video_out=NULL;
}
// must be after libvo uninit, as few vo drivers (svgalib) has tty code
if(mask&INITED_GETCH2){
inited_flags&=~INITED_GETCH2;
current_module="uninit_getch2";
mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");
// restore terminal:
getch2_disable();
}
if(mask&INITED_VOBSUB){
inited_flags&=~INITED_VOBSUB;
current_module="uninit_vobsub";
if(vo_vobsub) vobsub_close(vo_vobsub);
vo_vobsub=NULL;
}
if (mask&INITED_SPUDEC){
inited_flags&=~INITED_SPUDEC;
current_module="uninit_spudec";
spudec_free(vo_spudec);
vo_spudec=NULL;
}
if(mask&INITED_AO){
inited_flags&=~INITED_AO;
current_module="uninit_ao";
audio_out->uninit(eof?0:1); audio_out=NULL;
}
#ifdef HAVE_NEW_GUI
if(mask&INITED_GUI){
inited_flags&=~INITED_GUI;
current_module="uninit_gui";
guiDone();
}
#endif
if(mask&INITED_INPUT){
inited_flags&=~INITED_INPUT;
current_module="uninit_input";
mp_input_uninit();
}
current_module=NULL;
}
static void exit_player_with_rc(char* how, int rc){
uninit_player(INITED_ALL);
#ifdef HAVE_X11
#ifdef HAVE_NEW_GUI
if ( !use_gui )
#endif
vo_uninit(); // close the X11 connection (if any opened)
#endif
#ifdef HAVE_FREETYPE
current_module="uninit_font";
if (vo_font) free_font_desc(vo_font);
vo_font = NULL;
done_freetype();
#endif
current_module="exit_player";
// free mplayer config
free(mconfig);
#ifdef USE_EDL
if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
#endif
if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));
mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
exit(rc);
}
void exit_player(char* how){
exit_player_with_rc(how, 1);
}
#ifndef __MINGW32__
static void child_sighandler(int x){
pid_t pid;
while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
}
#endif
#ifdef CRASH_DEBUG
static char *prog_path;
static int crash_debug = 0;
#endif
static void exit_sighandler(int x){
static int sig_count=0;
#ifdef CRASH_DEBUG
if (!crash_debug || x != SIGTRAP)
#endif
++sig_count;
if(inited_flags==0 && sig_count>1) exit(1);
if(sig_count==5)
{
/* We're crashing bad and can't uninit cleanly :(
* by popular request, we make one last (dirty)
* effort to restore the user's
* terminal. */
getch2_disable();
exit(1);
}
if(sig_count==6) exit(1);
if(sig_count>6){
// can't stop :(
#ifndef __MINGW32__
kill(getpid(),SIGKILL);
#endif
}
mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,
current_module?current_module:mp_gettext("unknown")
);
if(sig_count<=1)
switch(x){
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGKILL:
break; // killed from keyboard (^C) or killed [-9]
case SIGILL:
#ifdef RUNTIME_CPUDETECT
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);
#else
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);
#endif
case SIGFPE:
case SIGSEGV:
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);
default:
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);
#ifdef CRASH_DEBUG
if (crash_debug) {
int gdb_pid;
char spid[20];
snprintf(spid, 19, "%i", getpid());
spid[19] = 0;
mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n");
gdb_pid = fork();
mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n");
if (gdb_pid == 0) { // We are the child
if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1)
mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n");
} else if (gdb_pid < 0)
mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n");
else {
waitpid(gdb_pid, NULL, 0);
}
if (x == SIGTRAP) return;
}
#endif
}
exit_player(NULL);
}
//extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
extern void mp_input_register_options(m_config_t* cfg);
#include "mixer.h"
mixer_t mixer;
/// step size of mixer changes
int volstep = 3;
#include "cfg-mplayer.h"
void parse_cfgfiles( m_config_t* conf )
{
char *conffile;
int conffile_fd;
if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)
exit_player(NULL);
if ((conffile = get_path("")) == NULL) {
mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);
} else {
#ifdef __MINGW32__
mkdir(conffile);
#else
mkdir(conffile, 0777);
#endif
free(conffile);
if ((conffile = get_path("config")) == NULL) {
mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);
} else {
if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);
write(conffile_fd, default_config, strlen(default_config));
close(conffile_fd);
}
if (m_config_parse_config_file(conf, conffile) < 0)
exit_player(NULL);
free(conffile);
}
}
}
void load_per_file_config (m_config_t* conf, const char *const file)
{
char *confpath;
char cfg[strlen(file)+10];
struct stat st;
char *name;
sprintf (cfg, "%s.conf", file);
if (!stat (cfg, &st))
{
mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
m_config_parse_config_file (conf, cfg);
return;
}
if ((name = strrchr (cfg, '/')) == NULL)
name = cfg;
else
name++;
if ((confpath = get_path (name)) != NULL)
{
if (!stat (confpath, &st))
{
mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
m_config_parse_config_file (conf, confpath);
}
free (confpath);
}
}
// When libmpdemux perform a blocking operation (network connection or cache filling)
// if the operation fail we use this function to check if it was interrupted by the user.
// The function return a new value for eof.
static int libmpdemux_was_interrupted(int eof) {
mp_cmd_t* cmd;
if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {
switch(cmd->id) {
case MP_CMD_QUIT:
exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);
case MP_CMD_PLAY_TREE_STEP: {
eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
} break;
case MP_CMD_PLAY_TREE_UP_STEP: {
eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
} break;
case MP_CMD_PLAY_ALT_SRC_STEP: {
eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC;
} break;
}
mp_cmd_free(cmd);
}
return eof;
}
#define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
#define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
int playtree_add_playlist(play_tree_t* entry)
{
play_tree_add_bpf(entry,filename);
#ifdef HAVE_NEW_GUI
if (use_gui) {
if (entry) {
import_playtree_playlist_into_gui(entry, mconfig);
play_tree_free_list(entry,1);
}
} else
#endif
{
if(!entry) {
entry = playtree_iter->tree;
if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
return PT_NEXT_ENTRY;
}
if(playtree_iter->tree == entry ) { // Loop with a single file
if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
return PT_NEXT_ENTRY;
}
}
play_tree_remove(entry,1,1);
return PT_NEXT_SRC;
}
play_tree_insert_entry(playtree_iter->tree,entry);
play_tree_set_params_from(entry,playtree_iter->tree);
entry = playtree_iter->tree;
if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
return PT_NEXT_ENTRY;
}
play_tree_remove(entry,1,1);
}
return PT_NEXT_SRC;
}
static int play_tree_step = 1;
int sub_source()
{
int source = -1;
int top = -1;
int i;
for (i = 0; i < SUB_SOURCES; i++) {
int j = global_sub_indices[i];
if ((j >= 0) && (j > top) && (global_sub_pos >= j)) {
source = i;
top = j;
}
}
return source;
}
#ifdef USE_SUB
sub_data* subdata = NULL;
void add_subtitles(char *filename, float fps, int silent)
{
sub_data *subd;
if (filename == NULL) {
return;
}
subd = sub_read_file(filename, fps);
if(!subd && !silent)
mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return;
set_of_subtitles[set_of_sub_size] = subd;
if (identify)
{
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
}
++set_of_sub_size;
mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
}
// FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
void update_set_of_subtitles()
// subdata was changed, set_of_sub... have to be updated.
{
int i;
if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i)
set_of_subtitles[i-1] = set_of_subtitles[i];
set_of_subtitles[set_of_sub_size-1] = NULL;
--set_of_sub_size;
if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0];
}
else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
set_of_subtitles[set_of_sub_pos] = subdata;
}
else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata;
++set_of_sub_size;
}
}
#endif
/*
* In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to
* make it all work is to use the builtin SDL-bootstrap code, which
* will be done automatically by replacing our main() if we include SDL.h.
*/
#if defined(SYS_DARWIN) && defined(HAVE_SDL)
#include <SDL.h>
#endif
/**
* \brief append a formatted string
* \param buf buffer to print into
* \param pos position of terminating 0 in buf
* \param len maximum number of characters in buf, not including terminating 0
* \param format printf format string
*/
static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
{
va_list va;
va_start(va, format);
*pos += vsnprintf(&buf[*pos], len - *pos, format, va);
va_end(va);
if (*pos >= len ) {
buf[len] = 0;
*pos = len;
}
}
/**
* \brief print the status line
* \param a_pos audio position
* \param a_v A-V desynchronization
* \param corr amount out A-V synchronization
*/
static void print_status(float a_pos, float a_v, float corr)
{
int width;
char *line;
unsigned pos = 0;
get_screen_size();
if (screen_width > 0)
width = screen_width;
else
width = 80;
#ifdef WIN32
// windows command line is broken (MinGW's rxvt works though, but we
// should not depend on that).
width--;
#endif
line = malloc(width + 1); // one additional for terminating null
// Audio time
if (sh_audio) {
saddf(line, &pos, width, "A:%6.1f ", a_pos);
if (!sh_video) {
// convert time to HH:MM:SS.F format
long tenths = 10 * a_pos;
int f1 = tenths % 10;
int ss = (tenths / 10) % 60;
int mm = (tenths / 600) % 60;
int hh = (tenths / 36000) % 100;
saddf(line, &pos, width, "(");
if (hh > 0)
saddf(line, &pos, width, "%2d:", hh);
if (hh > 0 || mm > 0)
saddf(line, &pos, width, "%02d:", mm);
saddf(line, &pos, width, "%02d.", ss);
saddf(line, &pos, width, "%1d", f1);
saddf(line, &pos, width, ") ");
}
}
// Video time
if (sh_video)
saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
// A-V sync
if (sh_audio && sh_video)
saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
// Video stats
if (sh_video)
saddf(line, &pos, width, "%3d/%3d ",
(int)sh_video->num_frames,
(int)sh_video->num_frames_decoded);
// CPU usage
if (sh_video) {
if (sh_video->timer > 0.5)
saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
(int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
(int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
(100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
else
saddf(line, &pos, width, "??%% ??%% ??,?%% ");
} else if (sh_audio) {
if (sh_audio->delay > 0.5)
saddf(line, &pos, width, "%4.1f%% ",
100.0*audio_time_usage/(double)sh_audio->delay);
else
saddf(line, &pos, width, "??,?%% ");
}
// VO stats
if (sh_video)
saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
#ifdef USE_STREAM_CACHE
// cache stats
if (stream_cache_size > 0)
saddf(line, &pos, width, "%d%% ", cache_fill_status);
#endif
// other
if (playback_speed != 1)
saddf(line, &pos, width, "%4.2fx ", playback_speed);
// end
memset(&line[pos], ' ', width - pos);
line[width] = 0;
mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
free(line);
}
/**
* \brief build a chain of audio filters that converts the input format
* to the ao's format, taking into account the current playback_speed.
* \param sh_audio describes the requested input format of the chain.
* \param ao_data describes the requested output format of the chain.
*/
static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data)
{
int new_srate;
int result;
if (!sh_audio)
{
mixer.afilter = NULL;
return 0;
}
new_srate = sh_audio->samplerate * playback_speed;
if (new_srate != ao_data->samplerate) {
// limits are taken from libaf/af_resample.c
if (new_srate < 8000)
new_srate = 8000;
if (new_srate > 192000)
new_srate = 192000;
playback_speed = (float)new_srate / (float)sh_audio->samplerate;
}
result = init_audio_filters(sh_audio, new_srate,
sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize,
ao_data->samplerate, ao_data->channels, ao_data->format,
audio_out_format_bits(ao_data->format) / 8, /* ao_data.bps, */
ao_data->outburst * 4, ao_data->buffersize);
mixer.afilter = sh_audio->afilter;
return result;
}
int main(int argc,char* argv[]){
char * mem_ptr;
static demux_stream_t *d_audio=NULL;
static demux_stream_t *d_video=NULL;
static demux_stream_t *d_dvdsub=NULL;
int file_format=DEMUXER_TYPE_UNKNOWN;
int delay_corrected=1;
// movie info:
int osd_function=OSD_PLAY;
int osd_last_pts=-303;
int osd_show_av_delay = 0;
int osd_show_text = 0;
int osd_show_speed = 0;
int osd_show_sub_delay = 0;
int osd_show_sub_pos = 0;
int osd_show_sub_visibility = 0;
int osd_show_sub_alignment = 0;
int osd_show_vobsub_changed = 0;
int osd_show_sub_changed = 0;
int osd_show_percentage = 0;
int osd_show_tv_channel = 25;
int osd_show_ontop = 0;
int osd_show_rootwin = 0;
int osd_show_framedropping = 0;
int rtc_fd=-1;
//float a_frame=0; // Audio
int i;
char *tmp;
int gui_no_filename=0;
srand((int) time(NULL));
mp_msg_init();
mp_msg_set_level(MSGL_STATUS);
mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2004 MPlayer Team\n");
/* Test for cpu capabilities (and corresponding OS support) for optimizing */
GetCpuCaps(&gCpuCaps);