-
Notifications
You must be signed in to change notification settings - Fork 7
/
mplayer.c
executable file
·3696 lines (3197 loc) · 106 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
/// \file
/// \ingroup Properties Command2Property OSDMsgStack
#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 */
#define SIGPIPE 13 /* broken pipe */
#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 "m_property.h"
#include "cfg-mplayer-def.h"
#include "subreader.h"
#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 "codec-cfg.h"
#include "edl.h"
#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 player_idle_mode=0;
int quiet=0;
int enable_mouse_movements=0;
#ifdef WIN32
char * proc_priority=NULL;
#endif
#define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
#ifdef HAVE_RTC
#ifdef __linux__
#include <linux/rtc.h>
#else
#include <rtc.h>
#define RTC_IRQP_SET RTCIO_IRQP_SET
#define RTC_PIE_ON RTCIO_PIE_ON
#endif /* __linux__ */
#endif /* HAVE_RTC */
#ifdef USE_TV
#include "stream/tv.h"
#endif
#ifdef USE_RADIO
#include "stream/stream_radio.h"
#endif
#ifdef HAS_DVBIN_SUPPORT
#include "stream/dvbin.h"
#include "stream/cache2.h"
#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
//**************************************************************************//
// Config
//**************************************************************************//
#include "parser-cfg.h"
#include "parser-mpcmd.h"
m_config_t* mconfig;
//**************************************************************************//
// 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.h"
//**************************************************************************//
// XScreensaver
//**************************************************************************//
#ifdef HAVE_X11
void xscreensaver_heartbeat(void);
#endif
//**************************************************************************//
//**************************************************************************//
// Input media streaming & demultiplexer:
//**************************************************************************//
static int max_framesize=0;
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
//#include "parse_es.h"
#include "libmpdemux/matroska.h"
#ifdef USE_DVDREAD
#include "stream/stream_dvd.h"
#endif
#ifdef USE_DVDNAV
#include "stream/stream_dvdnav.h"
#endif
#include "libmpcodecs/dec_audio.h"
#include "libmpcodecs/dec_video.h"
#include "libmpcodecs/mp_image.h"
#include "libmpcodecs/vf.h"
#include "libmpcodecs/vd.h"
#include "mixer.h"
#include "mp_core.h"
//**************************************************************************//
//**************************************************************************//
// Common FIFO functions, and keyboard/event FIFO code
#include "mp_fifo.h"
int noconsolecontrols=0;
//**************************************************************************//
// Not all functions in mplayer.c take the context as an argument yet
static MPContext mpctx_s = {
.osd_function = OSD_PLAY,
.begin_skip = MP_NOPTS_VALUE,
.play_tree_step = 1,
.global_sub_pos = -1,
.set_of_sub_pos = -1,
.file_format = DEMUXER_TYPE_UNKNOWN,
.loop_times = -1,
#ifdef HAS_DVBIN_SUPPORT
.last_dvb_step = 1,
#endif
};
static MPContext *mpctx = &mpctx_s;
int fixed_vo=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
static int list_properties = 0;
int osd_level=1;
// if nonzero, hide current OSD contents when GetTimerMS() reaches this
unsigned int osd_visible;
int osd_duration = 1000;
int term_osd = 1;
static char* term_osd_esc = "\x1b[A\r\x1b[K";
static char* playing_msg = NULL;
// seek:
static double seek_to_sec;
static off_t seek_to_byte=0;
static off_t step_sec=0;
static int loop_seek=0;
static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 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
// demuxer:
extern char *demuxer_name; // override demuxer
extern char *audio_demuxer_name; // override audio demuxer
extern char *sub_demuxer_name; // override sub demuxer
// streaming:
int audio_id=-1;
int video_id=-1;
int dvdsub_id=-2;
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;
int file_filter=1;
// 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_seek_min_percent=50.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 ignore_start=0;
static int softsleep=0;
float force_fps=0;
static int force_srate=0;
static int audio_output_format=-1; // AF_FORMAT_UNKNOWN
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;
// sub:
char *font_name=NULL;
char *sub_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_ASS
#include "libass/ass.h"
#include "libass/ass_mp.h"
#endif
extern int mp_msg_levels[MSGT_MAX];
extern int mp_msg_level_all;
char* current_module=NULL; // for debugging
// ---
#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 = 1;
static char* rtc_device;
#endif
edl_record_ptr edl_records = NULL; ///< EDL entries memory area
edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
short edl_decision = 0; ///< 1 when an EDL operation has been made.
FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode.
int use_filedir_conf;
static unsigned int inited_flags=0;
#include "mpcommon.h"
#include "command.h"
#include "metadata.h"
#define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
void *mpctx_get_video_out(MPContext *mpctx)
{
return mpctx->video_out;
}
void *mpctx_get_audio_out(MPContext *mpctx)
{
return mpctx->audio_out;
}
void *mpctx_get_playtree_iter(MPContext *mpctx)
{
return mpctx->playtree_iter;
}
void *mpctx_get_mixer(MPContext *mpctx)
{
return &mpctx->mixer;
}
int mpctx_get_global_sub_size(MPContext *mpctx)
{
return mpctx->global_sub_size;
}
static int is_valid_metadata_type (metadata_t type) {
switch (type)
{
/* check for valid video stream */
case META_VIDEO_CODEC:
case META_VIDEO_BITRATE:
case META_VIDEO_RESOLUTION:
{
if (!mpctx->sh_video)
return 0;
break;
}
/* check for valid audio stream */
case META_AUDIO_CODEC:
case META_AUDIO_BITRATE:
case META_AUDIO_SAMPLES:
{
if (!mpctx->sh_audio)
return 0;
break;
}
/* check for valid demuxer */
case META_INFO_TITLE:
case META_INFO_ARTIST:
case META_INFO_ALBUM:
case META_INFO_YEAR:
case META_INFO_COMMENT:
case META_INFO_TRACK:
case META_INFO_GENRE:
{
if (!mpctx->demuxer)
return 0;
break;
}
default:
break;
}
return 1;
}
static char *get_demuxer_info (char *tag) {
char **info = mpctx->demuxer->info;
int n;
if (!info || !tag)
return NULL;
for (n = 0; info[2*n] != NULL ; n++)
if (!strcmp (info[2*n], tag))
break;
return info[2*n+1] ? strdup (info[2*n+1]) : NULL;
}
char *get_metadata (metadata_t type) {
char *meta = NULL;
sh_audio_t * const sh_audio = mpctx->sh_audio;
sh_video_t * const sh_video = mpctx->sh_video;
if (!is_valid_metadata_type (type))
return NULL;
switch (type)
{
case META_NAME:
{
return strdup (mp_basename2 (filename));
}
case META_VIDEO_CODEC:
{
if (sh_video->format == 0x10000001)
meta = strdup ("mpeg1");
else if (sh_video->format == 0x10000002)
meta = strdup ("mpeg2");
else if (sh_video->format == 0x10000004)
meta = strdup ("mpeg4");
else if (sh_video->format == 0x10000005)
meta = strdup ("h264");
else if (sh_video->format >= 0x20202020)
{
meta = malloc (8);
sprintf (meta, "%.4s", (char *) &sh_video->format);
}
else
{
meta = malloc (8);
sprintf (meta, "0x%08X", sh_video->format);
}
return meta;
}
case META_VIDEO_BITRATE:
{
meta = malloc (16);
sprintf (meta, "%d kbps", (int) (sh_video->i_bps * 8 / 1024));
return meta;
}
case META_VIDEO_RESOLUTION:
{
meta = malloc (16);
sprintf (meta, "%d x %d", sh_video->disp_w, sh_video->disp_h);
return meta;
}
case META_AUDIO_CODEC:
{
if (sh_audio->codec && sh_audio->codec->name)
meta = strdup (sh_audio->codec->name);
return meta;
}
case META_AUDIO_BITRATE:
{
meta = malloc (16);
sprintf (meta, "%d kbps", (int) (sh_audio->i_bps * 8/1000));
return meta;
}
case META_AUDIO_SAMPLES:
{
meta = malloc (16);
sprintf (meta, "%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels);
return meta;
}
/* check for valid demuxer */
case META_INFO_TITLE:
return get_demuxer_info ("Title");
case META_INFO_ARTIST:
return get_demuxer_info ("Artist");
case META_INFO_ALBUM:
return get_demuxer_info ("Album");
case META_INFO_YEAR:
return get_demuxer_info ("Year");
case META_INFO_COMMENT:
return get_demuxer_info ("Comment");
case META_INFO_TRACK:
return get_demuxer_info ("Track");
case META_INFO_GENRE:
return get_demuxer_info ("Genre");
default:
break;
}
return meta;
}
/// step size of mixer changes
int volstep = 3;
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(mpctx->sh_audio) uninit_audio(mpctx->sh_audio);
#ifdef HAVE_NEW_GUI
if (use_gui) guiGetEvent(guiSetAfilter, (char *)NULL);
#endif
mpctx->sh_audio=NULL;
mpctx->mixer.afilter = NULL;
}
if(mask&INITED_VCODEC){
inited_flags&=~INITED_VCODEC;
current_module="uninit_vcodec";
if(mpctx->sh_video) uninit_video(mpctx->sh_video);
mpctx->sh_video=NULL;
#ifdef HAVE_MENU
vf_menu=NULL;
#endif
}
if(mask&INITED_DEMUXER){
inited_flags&=~INITED_DEMUXER;
current_module="free_demuxer";
if(mpctx->demuxer){
mpctx->stream=mpctx->demuxer->stream;
free_demuxer(mpctx->demuxer);
}
mpctx->demuxer=NULL;
}
// kill the cache process:
if(mask&INITED_STREAM){
inited_flags&=~INITED_STREAM;
current_module="uninit_stream";
if(mpctx->stream) free_stream(mpctx->stream);
mpctx->stream=NULL;
}
if(mask&INITED_VO){
inited_flags&=~INITED_VO;
current_module="uninit_vo";
mpctx->video_out->uninit();
mpctx->video_out=NULL;
}
// Must be after libvo uninit, as few vo drivers (svgalib) have 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";
if (mpctx->edl_muted) mixer_mute(&mpctx->mixer);
mpctx->audio_out->uninit(mpctx->eof?0:1); mpctx->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;
}
void exit_player_with_rc(const char* how, int rc){
if (mpctx->user_muted && !mpctx->edl_muted) mixer_mute(&mpctx->mixer);
uninit_player(INITED_ALL);
#ifdef HAVE_X11
#ifdef HAVE_NEW_GUI
if ( !use_gui )
#endif
vo_uninit(); // Close the X11 connection (if any is open).
#endif
#ifdef HAVE_FREETYPE
current_module="uninit_font";
if (vo_font) free_font_desc(vo_font);
vo_font = NULL;
done_freetype();
#endif
free_osd_list();
#ifdef USE_ASS
ass_library_done(ass_library);
#endif
current_module="exit_player";
// free mplayer config
if(mconfig)
m_config_free(mconfig);
if(mpctx->playtree)
play_tree_free(mpctx->playtree, 1);
if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,how);
mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);
exit(rc);
}
void exit_player(const 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:"unknown"
);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x);
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 mp_input_register_options(m_config_t* cfg);
#include "cfg-mplayer.h"
static 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 (use_filedir_conf && !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 performs a blocking operation (network connection or
* cache filling) if the operation fails we use this function to check
* if it was interrupted by the user.
* The function returns 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;
mpctx->play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i;
} 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_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 = mpctx->playtree_iter->tree;
if(play_tree_iter_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
return PT_NEXT_ENTRY;
}
if(mpctx->playtree_iter->tree == entry ) { // Loop with a single file
if(play_tree_iter_up_step(mpctx->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(mpctx->playtree_iter->tree,entry);
play_tree_set_params_from(entry,mpctx->playtree_iter->tree);
entry = mpctx->playtree_iter->tree;
if(play_tree_iter_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
return PT_NEXT_ENTRY;
}
play_tree_remove(entry,1,1);
}
return PT_NEXT_SRC;
}
void add_subtitles(char *filename, float fps, int silent)
{
sub_data *subd;
#ifdef USE_ASS
ass_track_t *asst = 0;
#endif
if (filename == NULL || mpctx->set_of_sub_size >= MAX_SUBTITLE_FILES) {
return;
}
subd = sub_read_file(filename, fps);
#ifdef USE_ASS
if (ass_enabled)
#ifdef USE_ICONV
asst = ass_read_file(ass_library, filename, sub_cp);
#else
asst = ass_read_file(ass_library, filename, 0);
#endif
if (ass_enabled && subd && !asst)
asst = ass_read_subdata(ass_library, subd, fps);
if (!asst && !subd && !silent)
#else
if(!subd && !silent)
#endif
mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub,
filename_recode(filename));
#ifdef USE_ASS
if (!asst && !subd) return;
mpctx->set_of_ass_tracks[mpctx->set_of_sub_size] = asst;
#else
if (!subd) return;
#endif
mpctx->set_of_subtitles[mpctx->set_of_sub_size] = subd;
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", mpctx->set_of_sub_size);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n",
filename_recode(filename));
++mpctx->set_of_sub_size;
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, mpctx->set_of_sub_size,
filename_recode(filename));
}
// FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
void update_set_of_subtitles(void)
// subdata was changed, set_of_sub... have to be updated.
{
sub_data ** const set_of_subtitles = mpctx->set_of_subtitles;
int i;
if (mpctx->set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted
for (i = mpctx->set_of_sub_pos + 1; i < mpctx->set_of_sub_size; ++i)
set_of_subtitles[i-1] = set_of_subtitles[i];
set_of_subtitles[mpctx->set_of_sub_size-1] = NULL;
--mpctx->set_of_sub_size;
if (mpctx->set_of_sub_size > 0) subdata = set_of_subtitles[mpctx->set_of_sub_pos=0];
}
else if (mpctx->set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed
set_of_subtitles[mpctx->set_of_sub_pos] = subdata;
}
else if (mpctx->set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added
set_of_subtitles[mpctx->set_of_sub_pos=mpctx->set_of_sub_size] = subdata;
++mpctx->set_of_sub_size;
}
}
void init_vo_spudec(void) {
if (vo_spudec)
spudec_free(vo_spudec);
inited_flags &= ~INITED_SPUDEC;
vo_spudec = NULL;
if (spudec_ifo) {
unsigned int palette[16], width, height;
current_module="spudec_init_vobsub";
if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
vo_spudec=spudec_new_scaled(palette, width, height);
}