-
Notifications
You must be signed in to change notification settings - Fork 6
/
mplayer.c
4228 lines (3749 loc) · 142 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
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#if defined(__MINGW32__) || defined(__CYGWIN__)
#define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/
#include <windows.h>
#endif
#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
#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 */
/*
* 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(__APPLE__) && defined(CONFIG_SDL)
#ifdef CONFIG_SDL_SDL_H
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
#endif
#include "gui/interface.h"
#include "input/input.h"
#include "libao2/audio_out.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libmenu/menu.h"
#include "libmpcodecs/dec_audio.h"
#include "libmpcodecs/dec_video.h"
#include "libmpcodecs/mp_image.h"
#include "libmpcodecs/vd.h"
#include "libmpcodecs/vf.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "sub/font_load.h"
#include "sub/sub.h"
#include "libvo/video_out.h"
#include "stream/cache2.h"
#include "stream/stream.h"
#include "stream/stream_bd.h"
#include "stream/stream_dvdnav.h"
#include "stream/stream_radio.h"
#include "stream/tv.h"
#include "access_mpcontext.h"
#include "sub/ass_mp.h"
#include "cfg-mplayer-def.h"
#include "codec-cfg.h"
#include "command.h"
#include "edl.h"
#include "help_mp.h"
#include "m_config.h"
#include "m_option.h"
#include "m_property.h"
#include "m_struct.h"
#include "metadata.h"
#include "mixer.h"
#include "mp_core.h"
#include "mp_fifo.h"
#include "mp_msg.h"
#include "mp_strings.h"
#include "mpcommon.h"
#include "mplayer.h"
#include "osdep/getch2.h"
#include "osdep/timer.h"
#include "parser-cfg.h"
#include "parser-mpcmd.h"
#include "path.h"
#include "playtree.h"
#include "playtreeparser.h"
#include "sub/spudec.h"
#include "sub/subreader.h"
#include "sub/vobsub.h"
#include "sub/eosd.h"
#include "udp_sync.h"
#ifdef CONFIG_X11
#include "libvo/x11_common.h"
#endif
#ifdef CONFIG_DVBIN
#include "stream/dvbin.h"
#endif
#ifdef CONFIG_DVDREAD
#include "stream/stream_dvd.h"
#endif
#if defined(CONFIG_FONTCONFIG) && defined(_WIN32)
#include <fontconfig/fontconfig.h>
extern int FcDebugVal;
#endif
int slave_mode;
int player_idle_mode;
int quiet;
int enable_mouse_movements;
float start_volume = -1;
double start_pts = MP_NOPTS_VALUE;
char *heartbeat_cmd;
float heartbeat_interval = 30.0;
static int max_framesize;
int noconsolecontrols;
//**************************************************************************//
// 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 CONFIG_DVBIN
.last_dvb_step = 1,
#endif
};
static MPContext *mpctx = &mpctx_s;
int fixed_vo;
// benchmark:
double video_time_usage;
double vout_time_usage;
static double audio_time_usage;
static int total_time_usage_start;
static int total_frame_cnt;
static int drop_frame_cnt; // total number of dropped frames
int benchmark;
// options:
#define DEFAULT_STARTUP_DECODE_RETRY 8
int auto_quality;
static int output_quality;
float playback_speed = 1.0;
int use_gui;
#ifdef CONFIG_GUI
int enqueue;
#endif
#ifdef _WIN32
#include <io.h>
static void term_osd_eraseline(void)
{
DWORD wr;
COORD pos;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO cinfo;
GetConsoleScreenBufferInfo(hOut, &cinfo);
pos.X = 0;
pos.Y = cinfo.dwCursorPosition.Y - 1;
FillConsoleOutputCharacter(hOut, ' ', cinfo.dwSize.X, pos, &wr);
FillConsoleOutputAttribute(hOut, cinfo.wAttributes, cinfo.dwSize.X, pos, &wr);
SetConsoleCursorPosition(hOut, pos);
}
#else
#define term_osd_eraseline() printf("%s", term_osd_esc)
#endif
static int list_properties;
int osd_level = 1;
// if nonzero, hide current OSD contents when GetTimerMS() reaches this
unsigned int osd_visible;
int osd_duration = 1000;
int osd_fractions; // determines how fractions of seconds are displayed
// on OSD
int term_osd = 1;
static char *term_osd_esc = "\x1b[A\r\x1b[K";
static char *playing_msg;
// seek:
static double seek_to_sec = MP_NOPTS_VALUE;
static off_t seek_to_byte;
static off_t step_sec;
static int loop_seek;
static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 };
// A/V sync:
int autosync; // 30 might be a good default value.
// may be changed by GUI: (FIXME!)
float rel_seek_secs;
int abs_seek_pos;
// codecs:
char **audio_codec_list; // override audio codec
char **video_codec_list; // override video codec
char **audio_fm_list; // override audio codec family
char **video_fm_list; // override video codec family
// streaming:
int audio_id = -1;
int video_id = -1;
int dvdsub_id = -1;
// this dvdsub_id was selected via slang
// use this to allow dvdnav to follow -slang across stream resets,
// in particular the subtitle ID for a language changes
int dvdsub_lang_id;
int vobsub_id = -1;
char *audio_lang;
char *dvdsub_lang;
char *filename;
int file_filter = 1;
// cache2:
int stream_cache_size = -1;
#ifdef CONFIG_STREAM_CACHE
float stream_cache_min_percent = 20.0;
float stream_cache_seek_min_percent = 50.0;
#endif
// dump:
char *stream_dump_name = "stream.dump";
int stream_dump_type;
uint64_t stream_dump_count;
unsigned stream_dump_start_time;
unsigned stream_dump_last_print_time;
int capture_dump;
// A-V sync:
static float default_max_pts_correction = -1;
static float max_pts_correction; //default_max_pts_correction;
static float c_total;
float audio_delay;
static int ignore_start;
static int softsleep;
double force_fps;
static int force_srate;
static int audio_output_format = AF_FORMAT_UNKNOWN;
int frame_dropping; // 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;
char **audio_driver_list;
// sub:
char *font_name;
char *sub_font_name;
float font_factor = 0.75;
char **sub_name;
char **sub_paths;
float sub_delay;
float sub_fps;
int sub_auto = 1;
char *vobsub_name;
int subcc_enabled;
int suboverlap_enabled = 1;
char *current_module; // for debugging
#ifdef CONFIG_MENU
static const vf_info_t *const libmenu_vfs[] = {
&vf_info_menu,
NULL
};
static vf_instance_t *vf_menu;
int use_menu;
static char *menu_cfg;
static char *menu_root = "main";
#endif
#ifdef HAVE_RTC
static int nortc = 1;
static char *rtc_device;
#endif
edl_record_ptr edl_records; ///< EDL entries memory area
edl_record_ptr next_edl_record; ///< only for traversing edl_records
short edl_decision; ///< 1 when an EDL operation has been made.
short edl_needs_reset; ///< 1 if we need to reset EDL next pointer
short edl_backward; ///< 1 if we need to skip to the beginning of the next EDL record
FILE *edl_fd; ///< fd to write to when in -edlout mode.
// Number of seconds to add to the seek when jumping out
// of EDL scene in backward direction. This is needed to
// have some time after the seek to decide what to do next
// (next seek, pause,...), otherwise after the seek it will
// enter the same scene again and skip forward immediately
float edl_backward_delay = 2;
int edl_start_pts; ///< Automatically add/sub this from EDL start/stop pos
int use_filedir_conf;
int use_filename_title;
static unsigned int initialized_flags;
int volstep = 3; ///< step size of mixer changes
#ifdef CONFIG_CRASH_DEBUG
static char *prog_path;
static int crash_debug;
#endif
int allow_playlist_parsing;
/* This header requires all the global variable declarations. */
#include "cfg-mplayer.h"
const void *mpctx_get_video_out(MPContext *mpctx)
{
return mpctx->video_out;
}
const void *mpctx_get_audio_out(MPContext *mpctx)
{
return mpctx->audio_out;
}
void *mpctx_get_demuxer(MPContext *mpctx)
{
return mpctx->demuxer;
}
void *mpctx_get_playtree_iter(MPContext *mpctx)
{
return mpctx->playtree_iter;
}
void *mpctx_get_mixer(MPContext *mpctx)
{
return &mpctx->mixer;
}
void mpctx_get_global_sub_info(MPContext *mpctx, int *size, int *pos)
{
mp_property_do("sub", M_PROPERTY_GET, pos, mpctx);
if (size) *size = mpctx->global_sub_size;
}
int mpctx_get_osd_function(MPContext *mpctx)
{
return mpctx->osd_function;
}
void *mpctx_get_stream(MPContext *mpctx)
{
return mpctx->stream;
}
void *mpctx_get_afilter(MPContext *mpctx)
{
return mpctx->sh_audio ? mpctx->sh_audio->afilter : NULL;
}
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 (!av_strcasecmp(info[2 * n], tag))
break;
return info[2 * n + 1] ? strdup(info[2 * n + 1]) : NULL;
}
char *get_metadata(metadata_t type)
{
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_basename(filename));
case META_VIDEO_CODEC:
if (sh_video->format == 0x10000001)
return strdup("mpeg1");
else if (sh_video->format == 0x10000002)
return strdup("mpeg2");
else if (sh_video->format == 0x10000004)
return strdup("mpeg4");
else if (sh_video->format == 0x10000005)
return strdup("h264");
else if (sh_video->format >= 0x20202020)
return mp_asprintf("%.4s", (char *)&sh_video->format);
return mp_asprintf("0x%08X", sh_video->format);
case META_VIDEO_BITRATE:
return mp_asprintf("%d kbps", (int)(sh_video->i_bps * 8 / 1024));
case META_VIDEO_RESOLUTION:
return mp_asprintf("%d x %d", sh_video->disp_w, sh_video->disp_h);
case META_AUDIO_CODEC:
if (sh_audio->codec && sh_audio->codec->name_idx)
return strdup(codec_idx2str(sh_audio->codec->name_idx));
break;
case META_AUDIO_BITRATE:
return mp_asprintf("%d kbps", (int)(sh_audio->i_bps * 8 / 1000));
case META_AUDIO_SAMPLES:
return mp_asprintf("%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels);
/* 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 NULL;
}
static void print_file_properties(const MPContext *mpctx, const char *filename)
{
double video_start_pts = MP_NOPTS_VALUE;
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILENAME=%s\n",
filename_recode(filename));
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXER=%s\n", mpctx->demuxer ? mpctx->demuxer->desc->name : "none");
if (mpctx->sh_video) {
/* Assume FOURCC if all bytes >= 0x20 (' ') */
if (mpctx->sh_video->format >= 0x20202020)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx->sh_video->format);
else
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_FORMAT=0x%08X\n", mpctx->sh_video->format);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_BITRATE=%d\n", mpctx->sh_video->i_bps * 8);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_WIDTH=%d\n", mpctx->sh_video->disp_w);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_HEIGHT=%d\n", mpctx->sh_video->disp_h);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_FPS=%5.3f\n", mpctx->sh_video->fps);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n", mpctx->sh_video->aspect);
video_start_pts = ds_get_next_pts(mpctx->d_video);
}
if (mpctx->sh_audio) {
/* Assume FOURCC if all bytes >= 0x20 (' ') */
if (mpctx->sh_audio->format >= 0x20202020)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx->sh_audio->format);
else
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_FORMAT=%d\n", mpctx->sh_audio->format);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_BITRATE=%d\n", mpctx->sh_audio->i_bps * 8);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_RATE=%d\n", mpctx->sh_audio->samplerate);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_NCH=%d\n", mpctx->sh_audio->channels);
start_pts = ds_get_next_pts(mpctx->d_audio);
}
if (video_start_pts != MP_NOPTS_VALUE) {
if (start_pts == MP_NOPTS_VALUE || !mpctx->sh_audio ||
(mpctx->sh_video && video_start_pts < start_pts))
start_pts = video_start_pts;
}
if (start_pts != MP_NOPTS_VALUE)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_START_TIME=%.2f\n", start_pts);
else
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_START_TIME=unknown\n");
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_LENGTH=%.2f\n", mpctx->demuxer ? demuxer_get_time_length(mpctx->demuxer) : 0);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SEEKABLE=%d\n",
mpctx->stream->seek && (!mpctx->demuxer || mpctx->demuxer->seekable));
if (mpctx->demuxer) {
if (mpctx->demuxer->num_chapters == 0)
stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTERS=%d\n", mpctx->demuxer->num_chapters);
}
}
#ifdef CONFIG_DVDNAV
static void mp_dvdnav_context_free(MPContext *ctx)
{
if (ctx->nav_smpi)
free_mp_image(ctx->nav_smpi);
ctx->nav_smpi = NULL;
free(ctx->nav_buffer);
ctx->nav_buffer = NULL;
ctx->nav_start = NULL;
ctx->nav_in_size = 0;
}
#endif
void uninit_player(unsigned int mask)
{
mask &= initialized_flags;
mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n*** uninit(0x%X)\n", mask);
if (mask & INITIALIZED_ACODEC) {
initialized_flags &= ~INITIALIZED_ACODEC;
current_module = "uninit_acodec";
if (mpctx->sh_audio)
uninit_audio(mpctx->sh_audio);
mpctx->sh_audio = NULL;
mpctx->mixer.afilter = NULL;
}
// VCODEC is also used for video filters
if (mask & INITIALIZED_VCODEC) {
initialized_flags &= ~INITIALIZED_VCODEC;
current_module = "uninit_vcodec";
if (mpctx->sh_video)
uninit_video(mpctx->sh_video);
mpctx->sh_video = NULL;
#ifdef CONFIG_MENU
vf_menu = NULL;
#endif
}
if (mask & INITIALIZED_DEMUXER) {
initialized_flags &= ~INITIALIZED_DEMUXER;
current_module = "free_demuxer";
if (mpctx->demuxer)
free_demuxer(mpctx->demuxer);
mpctx->demuxer = NULL;
}
// kill the cache process:
if (mask & INITIALIZED_STREAM) {
initialized_flags &= ~INITIALIZED_STREAM;
current_module = "uninit_stream";
if (mpctx->stream)
free_stream(mpctx->stream);
mpctx->stream = NULL;
}
if (mask & INITIALIZED_VO) {
initialized_flags &= ~INITIALIZED_VO;
current_module = "uninit_vo";
mpctx->video_out->uninit();
mpctx->video_out = NULL;
#ifdef CONFIG_DVDNAV
mp_dvdnav_context_free(mpctx);
#endif
if (vo_spudec) {
current_module = "uninit_spudec";
spudec_free(vo_spudec);
vo_spudec = NULL;
}
}
// Must be after libvo uninit, as few vo drivers (svgalib) have tty code.
if (mask & INITIALIZED_GETCH2) {
initialized_flags &= ~INITIALIZED_GETCH2;
current_module = "uninit_getch2";
mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n[[[uninit getch2]]]\n");
// restore terminal:
getch2_disable();
}
if (mask & INITIALIZED_SUBS) {
initialized_flags &= ~INITIALIZED_SUBS;
if (mpctx->set_of_sub_size > 0) {
int i;
current_module = "sub_free";
for (i = 0; i < mpctx->set_of_sub_size; ++i) {
sub_free(mpctx->set_of_subtitles[i]);
#ifdef CONFIG_ASS
if (mpctx->set_of_ass_tracks[i])
ass_free_track(mpctx->set_of_ass_tracks[i]);
#endif
}
mpctx->set_of_sub_size = 0;
}
vo_sub_last = vo_sub = NULL;
subdata = NULL;
#ifdef CONFIG_ASS
ass_track = NULL;
if (ass_library)
ass_clear_fonts(ass_library);
#endif
}
if (mask & INITIALIZED_VOBSUB) {
initialized_flags &= ~INITIALIZED_VOBSUB;
current_module = "uninit_vobsub";
if (vo_vobsub)
vobsub_close(vo_vobsub);
vo_vobsub = NULL;
}
if (mask & INITIALIZED_AO) {
initialized_flags &= ~INITIALIZED_AO;
current_module = "uninit_ao";
if (mpctx->edl_muted)
mixer_mute(&mpctx->mixer);
if (mpctx->audio_out)
mpctx->audio_out->uninit(mpctx->eof ? 0 : 1);
mpctx->audio_out = NULL;
}
#ifdef CONFIG_GUI
if (mask & INITIALIZED_GUI) {
initialized_flags &= ~INITIALIZED_GUI;
current_module = "uninit_gui";
guiDone();
}
#endif
if (mask & INITIALIZED_INPUT) {
initialized_flags &= ~INITIALIZED_INPUT;
current_module = "uninit_input";
mp_input_uninit();
#ifdef CONFIG_MENU
if (use_menu)
menu_uninit();
#endif
}
current_module = NULL;
}
void exit_player_with_rc(enum exit_reason how, int rc)
{
#ifdef CONFIG_NETWORKING
if (udp_master)
send_udp(udp_ip, udp_port, "bye");
#endif /* CONFIG_NETWORKING */
#ifndef _WIN32
if (mpctx->user_muted && !mpctx->edl_muted)
mixer_mute(&mpctx->mixer);
#endif
uninit_player(INITIALIZED_ALL);
#if defined(__MINGW32__) || defined(__CYGWIN__)
timeEndPeriod(1);
#endif
#ifdef CONFIG_X11
#ifdef CONFIG_GUI
if (!use_gui)
#endif
vo_uninit(); // Close the X11 connection (if any is open).
#endif
common_uninit();
current_module = "exit_player";
if (mpctx->playtree_iter)
play_tree_iter_free(mpctx->playtree_iter);
mpctx->playtree_iter = NULL;
if (mpctx->playtree)
play_tree_free(mpctx->playtree, 1);
mpctx->playtree = NULL;
free(edl_records); // free mem allocated for EDL
edl_records = NULL;
switch (how) {
case EXIT_QUIT:
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_ExitingHow, MSGTR_Exit_quit);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=QUIT\n");
break;
case EXIT_EOF:
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_ExitingHow, MSGTR_Exit_eof);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=EOF\n");
break;
case EXIT_ERROR:
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_ExitingHow, MSGTR_Exit_error);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=ERROR\n");
break;
default:
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=NONE\n");
}
mp_msg(MSGT_CPLAYER, MSGL_DBG2, "max framesize was %d bytes\n", max_framesize);
// must be last since e.g. mp_msg uses option values
// that will be freed by this.
if (mconfig)
m_config_free(mconfig);
mconfig = NULL;
mp_msg_uninit();
exit(rc);
}
void exit_player(enum exit_reason how)
{
exit_player_with_rc(how, 1);
}
#ifndef __MINGW32__
static void child_sighandler(int x)
{
pid_t pid;
do {
pid = waitpid(-1, NULL, WNOHANG);
} while (pid > 0);
// Without this, we will be called only once at
// least on Linux 3.16.
signal(SIGCHLD, child_sighandler);
}
#endif
static void exit_sighandler(int x)
{
static int sig_count;
#ifdef CONFIG_CRASH_DEBUG
if (!crash_debug || x != SIGTRAP)
#endif
++sig_count;
if (initialized_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 : MSGTR_Unknown
);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x);
if (sig_count <= 1)
switch (x) {
case SIGINT:
case SIGPIPE:
case SIGQUIT:
case SIGTERM:
case SIGKILL:
async_quit_request = 1;
return; // killed from keyboard (^C) or killed [-9]
case SIGILL:
#if CONFIG_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 CONFIG_CRASH_DEBUG
if (crash_debug) {
int gdb_pid;
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_Forking);
gdb_pid = fork();
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_Forked);
if (gdb_pid == 0) { // We are the child
char spid[20];
snprintf(spid, sizeof(spid), "%i", getppid());
getch2_disable(); // allow terminal to work properly with gdb
if (execlp("gdb", "gdb", prog_path, spid, "-ex", "bt", NULL) == -1)
mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CouldntStartGdb);
} else if (gdb_pid < 0)
mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CouldntFork);
else {
waitpid(gdb_pid, NULL, 0);
}
if (x == SIGTRAP)
return;
}
#endif
}
getch2_disable();
exit(1);
}
static void parse_cfgfiles(m_config_t *conf)
{
char *conffile;
int conffile_fd;
if (!disable_system_conf &&
m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf", 1) < 0)
exit_player(EXIT_NONE);
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 (!disable_user_conf &&
m_config_parse_config_file(conf, conffile, 1) < 0)
exit_player(EXIT_NONE);
free(conffile);
}
}
}
#define PROFILE_CFG_PROTOCOL "protocol."
static void load_per_protocol_config(m_config_t *conf, const char *const file)
{
char *str;
char *protocol;
m_profile_t *p;
/* does filename actually uses a protocol ? */
str = strstr(file, "://");
if (!str)
return;
protocol = av_asprintf("%s%s", PROFILE_CFG_PROTOCOL, file);
*strstr(protocol, "://") = 0;
p = m_config_get_profile(conf, protocol);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingProtocolProfile, protocol);
m_config_set_profile(conf, p);
}
av_freep(&protocol);
}
#define PROFILE_CFG_EXTENSION "extension."
static void load_per_extension_config(m_config_t *conf, const char *const file)
{
char *str;
char extension[sizeof(PROFILE_CFG_EXTENSION) + 7];
m_profile_t *p;
/* does filename actually have an extension ? */
str = strrchr(filename, '.');
if (!str)
return;
snprintf(extension, sizeof(extension), "%s%s", PROFILE_CFG_EXTENSION, ++str);
p = m_config_get_profile(conf, extension);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingExtensionProfile, extension);
m_config_set_profile(conf, p);
}
}
#define PROFILE_CFG_VO "vo."
#define PROFILE_CFG_AO "ao."
static void load_per_output_config(m_config_t *conf, char *cfg, char *out)
{
m_profile_t *p;
char *profile = av_asprintf("%s%s", cfg, out);
p = m_config_get_profile(conf, profile);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingExtensionProfile, profile);
m_config_set_profile(conf, p);
}
av_freep(&profile);
}
/**
* @brief Tries to load a config file.
* @return 0 if file was not found, 1 otherwise
*/
static int try_load_config(m_config_t *conf, const char *file)
{
struct stat st;
if (stat(file, &st))
return 0;
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingConfig, file);
m_config_parse_config_file(conf, file, 0);
return 1;
}
static void load_per_file_config(m_config_t *conf, const char *const file)
{
char *confpath;
char cfg[PATH_MAX];
const char *name;
if (strlen(file) > PATH_MAX - 14) {
mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_FilenameTooLong);
return;
}
sprintf(cfg, "%s.conf", file);
name = mp_basename(cfg);
if (use_filedir_conf) {
char dircfg[PATH_MAX];