-
Notifications
You must be signed in to change notification settings - Fork 21
/
mplayer.c
5398 lines (4807 loc) · 175 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 <mbstring.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/time.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/matroska.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 "osdep/getch2.h"
#include "osdep/timer.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
#include "mplayer_lang.h"
#include "winstuff.h"
#ifdef CONFIG_ICONV
#include <iconv.h>
#endif
#define STRING_MAX 2048
int is_auto_stream_cache=0;
int not_save_status = 0;
extern int sub_source_by_pos(MPContext * mpctx, int sub_pos);
extern char *demux_mkv_sub_lang(int);
extern void StartGuiThread(void);
extern HANDLE hAccelTable;
extern int gui_thread;
extern int channel_state;
extern int bSeeking;
extern int end_pos;
extern int no_dvdnav;
#ifdef CONFIG_ICONV
extern char *url_cp;
extern char *sub_cps;
char *new_dvd_device = NULL;
char *new_bluray_device = NULL;
char *new_audio_stream = NULL;
char *sub_font_names = NULL;
int cp_index_min;
#endif
int percent;
float percent_value=500.0;
static const int FAKE_VIDEO_W=320;
static const int FAKE_VIDEO_H=180;
int fake_sub=0;
int fake_video;
int fake_size;
char *fake_buffer = NULL;
char *save_filename = NULL;
char *last_filename = NULL;
int save_volume,save_sec,save_audio_id,save_set_of_sub_pos,save_sub_pos;
int reload = 0;
int auto_play = 0;
int need_update_playtree = 0;
int loop_break = 0;
extern int high_accuracy_timer;
extern int autoplay_fuzziness;
extern int sys_Language;
extern int always_quit;
extern int loop_all;
extern int vo_dirver;
extern int d3d_autolevel;
extern int generate_preview;
static char *help_texts = NULL;
static double demuxer_get_current_time_ex(demuxer_t *demuxer);
play_tree_t* playtree;
int codec_swap_uv = 0;
#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
extern int force_dshow_demux;
extern int open_with_dshow_demux;
#endif
extern int enable_file_mapping;
extern int osd_percent;
extern int osd_systime;
extern int is_vista;
extern int using_aero;
extern int always_thread;
extern int using_theme;
extern int have_audio;
extern int always_use_ass;
int save_dvdsub_id=-1;
int save_vobsub_id=-1;
int stream_cache_auto=0;
static int is_saved=0;
static float save_ass_scale = 1.0;
static float save_text_scale = 1.0;
int is_asf_format=0;
int is_mpegts_format=0;
float stream_offset_ex=0;
int save_auto_threads = 0;
static double stream_len_ex=0;
static int stream_need_adjust=0;
static int is_vob_format=0;
static int mpegts_not_mpeg=0;
static int save_frame_dropping=0;
static float save_subdelay=0;
static double save_endpos=0;
extern int adjust_ts_offset;
extern int seek_realtime;
extern int auto_threads;
static int seek_to_time = 0;
char status_text_timer[64];
char status_text_timer2[64];
char status_text_saved[64] = {0};
char percentage_text[10];
char systime_text[28];
char systime_text_only[28];
int show_status2 = 0;
static double last_pts = -303;
static double last_pec_pts = -303;
extern int show_status;
static HANDLE hgetnextThread = NULL;
extern char *video_exts[];
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
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;
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 = 1;
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
static int format_use_cache();
extern int get_extension_cache_size(const char *filename, const char *ext);
extern int set_map_buffer_size(stream_t *s, double bps, int use_cache);
extern void load_config_ex(void);
extern int set_playlist_mpctx(MPContext *mpctx_in);
extern int playtree_update(MPContext * mpctx);
extern void getFindname(const char *name, char *ret);
static 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 (!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 && !fake_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);
have_audio = 1;
} else
have_audio = 0;
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);
}
}
static void initHelp(void)
{
if(sys_Language == 1)
help_texts = gb_help_text;
else if(sys_Language == 3)
help_texts = gbk_help_text;
else if(sys_Language == 4)
help_texts = big5_help_text;
else
help_texts = help_text;
}
char *get_help_text(void)
{
return help_texts;
}
int get_sub_size(void)
{
return mpctx->global_sub_size;
}
void set_sh_vfilter(vf_instance_t *vf)
{
mpctx->sh_video->vfilter = vf;
}
void show_benchmark()
{
if(benchmark){
double tot=video_time_usage+vout_time_usage+audio_time_usage;
double total_time_usage;
total_time_usage_start=GetTimer()-total_time_usage_start;
total_time_usage = (float)total_time_usage_start*0.000001;
mp_msg(MSGT_CPLAYER,benchmark==1?MSGL_INFO:MSGL_FATAL,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n",
video_time_usage,vout_time_usage,audio_time_usage,
total_time_usage-tot,total_time_usage);
if(total_time_usage>0.0)
mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n",
100.0 * video_time_usage / total_time_usage,
100.0 * vout_time_usage / total_time_usage,
100.0 * audio_time_usage / total_time_usage,
100.0 * (total_time_usage - tot) / total_time_usage,
100.0);
if(total_frame_cnt && frame_dropping)
mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n",
total_frame_cnt-drop_frame_cnt,
(total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0,
drop_frame_cnt,
100*drop_frame_cnt/total_frame_cnt,
total_frame_cnt,
(total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0);
}
}
void update_sub_list(int i)
{
int id, sub_type, x, j, namelen;
char s[64];
char *shortname;
demux_stream_t *const d_sub = mpctx->d_sub;
if (!mpctx->global_sub_size) return;
if (i < 0) i = 0;
while (i < mpctx->global_sub_size) {
sub_type = sub_source_by_pos(mpctx, i);
id = i;
for(x = 0; x < sub_type; x++)
id -= mpctx->sub_counts[x];
snprintf(s, 63, "%s", MSGTR_Unknown);
if (sub_type == SUB_SOURCE_VOBSUB) {
id = vobsub_get_id_by_index(vo_vobsub, id);
char *lang = vobsub_get_id(vo_vobsub, id);
snprintf(s, 63, "VobSub(%d) %s", id, lang ? lang : MSGTR_Unknown);
} else if (sub_type == SUB_SOURCE_SUBS) {
char *sub_name = NULL;
#ifdef CONFIG_ASS
if (ass_enabled && mpctx->set_of_ass_tracks[id])
sub_name = mpctx->set_of_ass_tracks[id]->name;
else
#endif
if(mpctx->set_of_subtitles[id])
sub_name = mpctx->set_of_subtitles[id]->filename;
if(sub_name) {
shortname = _mbsrchr(sub_name, '\\');
if(shortname) sub_name = shortname + 1;
namelen = _mbslen(sub_name);
shortname = sub_name;
if(namelen > 32) {
for(x = 0; x < (namelen-32); x++)
shortname = _mbsinc(shortname);
}
snprintf(s, 63, "%s%s", namelen <= 32 ? "" : "...", shortname);
}
} else if (sub_type == SUB_SOURCE_DEMUX) {
char lang[40] = MSGTR_Unknown;
demuxer_sub_lang(mpctx->demuxer, id, lang, sizeof(lang));
snprintf(s, 63, "(%d) %s", id, lang);
} else {
snprintf(s, 63, MSGTR_Disabled);
}
guiCommand(CMD_ADD_SUBMENU, (int)s);
i++;
}
}
void update_subtitle_menu()
{
guiCommand(CMD_DEL_SUBMENU, 0);
update_sub_list(0);
guiCommand(CMD_UPDATE_SUBMENU, mpctx->global_sub_pos);
}
void mp_parse_commandline(char *cmdline)
{
if (cmdline) {
int i = 0;
char *v[50];
char *p;
while (i < 49) {
v[++i] = cmdline;
p = strchr(cmdline, ' ');
if (!p) break;
*p = 0;
cmdline = p + 1;
}
m_config_parse_mp_command_line(mconfig, ++i, v);
}
}
void mp_get_filename(play_tree_t *entry)
{
if (entry) {
if (mpctx->playtree) // the playtree is always a node with one child. let's clear it
play_tree_free_list(mpctx->playtree->child, 1);
else mpctx->playtree=play_tree_new(); // .. or make a brand new playtree
if (!mpctx->playtree) return; // couldn't make playtree!
play_tree_set_child(mpctx->playtree, entry);
/* Make iterator start at the top the of tree. */
mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree, mconfig);
if (!mpctx->playtree_iter) return;
// find the first real item in the tree
if (play_tree_iter_step(mpctx->playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {
// no items!
play_tree_iter_free(mpctx->playtree_iter);
mpctx->playtree_iter = NULL;
} else
filename = play_tree_iter_get_file(mpctx->playtree_iter, 1);
}
}
void seek2time(int time)
{
seek_to_time = time;
}
void save_status(void)
{
if (mpctx->demuxer)
save_sec = (fake_video?mpctx->d_audio->pts:demuxer_get_current_time_ex(mpctx->demuxer));
save_audio_id = audio_id;
save_vobsub_id = vobsub_id;
save_dvdsub_id = dvdsub_id;
save_set_of_sub_pos = mpctx->set_of_sub_pos;
save_sub_pos = sub_pos;
save_ass_scale = ass_font_scale;
save_text_scale = text_font_scale_factor;
strncpy(last_filename , filename , MAX_PATH);
is_saved = !not_save_status;
not_save_status = 0;
}
static void save_volume_status(void)
{
char s[10];
char *tmp = get_path("kk.ini");
sprintf(s, "%d", save_volume);
WritePrivateProfileString("Status", "Volume", s, tmp);
free(tmp);
}
static char* string_recode(const char* str)
{
#ifdef CONFIG_ICONV
iconv_t icdsc = (iconv_t)(-1);
static char recoded_str[STRING_MAX];
char* precoded;
size_t str_len, max_path;
if (icdsc == (iconv_t)(-1)) {
if(sys_Language == 4)
icdsc = iconv_open("BIG-5", "UTF-8");
else
icdsc = iconv_open("GBK", "UTF-8");
if (icdsc == (iconv_t)(-1))
return str;
}
str_len = strlen(str);
max_path = STRING_MAX - 4;
precoded = recoded_str;
if (iconv(icdsc, &str, &str_len, &precoded, &max_path) == (size_t)(-1))
return str;
*precoded = '\0';
return recoded_str;
#else
return str;
#endif
}
char* string_encode(const char* str)
{
#ifdef CONFIG_ICONV
iconv_t icdsc = (iconv_t)(-1);
static char recoded_str[STRING_MAX];
char* precoded;
size_t str_len, max_path;
if (icdsc == (iconv_t)(-1)) {
if(sys_Language == 4)
icdsc = iconv_open("UTF-8", "BIG-5");
else
icdsc = iconv_open("UTF-8", "GBK");
if (icdsc == (iconv_t)(-1))
return str;
}
str_len = strlen(str);
max_path = STRING_MAX - 4;
precoded = recoded_str;
if (iconv(icdsc, &str, &str_len, &precoded, &max_path) == (size_t)(-1))
return str;
*precoded = '\0';
return recoded_str;
#else
return str;
#endif
}
void fake_subtitle()
{
FILE *fd = NULL;
int n;
char **info, *subfile, *artist = NULL, *title = NULL, *album = NULL, *track = NULL;
subfile = get_path("AudioTags.srt");
if ( ( fd = fopen(subfile,"w") ) == NULL )
return 0;
info = mpctx->demuxer->info;
if (info) {
for (n = 0; info[2 * n] != NULL; n++) {
if(strcasecmp(info[2 * n], "author") == 0 || strcasecmp(info[2 * n], "artist") == 0) {
artist = strdup(string_recode(info[2 * n + 1]));
} else if(strcasecmp(info[2 * n], "title") == 0) {
title = strdup(string_recode(info[2 * n + 1]));
} else if(strcasecmp(info[2 * n], "album") == 0) {
album = strdup(string_recode(info[2 * n + 1]));
} else if(strcasecmp(info[2 * n], "track") == 0) {
track = strdup(string_recode(info[2 * n + 1]));
}
}
}
fprintf(fd ,"1\n00:00:01,000 --> 00:30:00,000\n");
if(!title && !artist && !album && !track) {
title = _mbsrchr(filename, '\\');
if(!title)
fprintf(fd, "%s", filename);
else
fprintf(fd ,"%s", title+1);
} else {
if(title) {
fprintf(fd ,"%s\n", title);
free(title);
}
if(artist) {
fprintf(fd ,"%s\n", artist);
free(artist);
}
if(album) {
fprintf(fd ,"%s", album);
free(album);
}
if(track) {
fprintf(fd ," #%s", track);
free(track);
}
}
fprintf(fd ,"\n");
fclose(fd);
fake_sub = 1;
add_subtitles(subfile, mpctx->sh_video->fps, 0);
fake_sub = 0;
remove(subfile);
free(subfile);
}
static double demuxer_get_current_time_ex(demuxer_t *demuxer)
{
double get_time_ans, offset, pts;
get_time_ans = pts = demuxer_get_current_time(demuxer);
if(stream_need_adjust) {
if(is_mpegts_format && !mpegts_not_mpeg) {
sh_video_t *sh_video = demuxer->video->sh;
sh_audio_t *sh_audio = demuxer->audio->sh;
if (sh_video && sh_video->i_bps && sh_audio && sh_audio->i_bps)
get_time_ans = (demuxer->filepos - demuxer->movi_start)
/ (sh_video->i_bps + sh_audio->i_bps);
else if (sh_video && sh_video->i_bps)
get_time_ans = (demuxer->filepos - demuxer->movi_start) / sh_video->i_bps;
else if (sh_audio && sh_audio->i_bps)
get_time_ans = (demuxer->filepos - demuxer->movi_start) / sh_audio->i_bps;
else
get_time_ans = 0;
offset = get_time_ans-pts;