This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
/
PmsConfiguration.java
2087 lines (1797 loc) · 67.7 KB
/
PmsConfiguration.java
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
/*
* PS3 Media Server, for streaming any medias to your PS3.
* Copyright (C) 2008 A.Brochard
*
* This program 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; version 2
* of the License only.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.pms.configuration;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import net.pms.io.SystemUtils;
import net.pms.Messages;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.ConversionException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.event.ConfigurationListener;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.jna.Platform;
/**
* Container for all configurable PMS settings. Settings are typically defined by three things:
* a unique key for use in the configuration file "PMS.conf", a getter (and setter) method and
* a default value. When a key cannot be found in the current configuration, the getter will
* return a default value. Setters only store a value, they do not permanently save it to
* file.
*/
public class PmsConfiguration {
private static final Logger logger = LoggerFactory.getLogger(PmsConfiguration.class);
private static final int DEFAULT_PROXY_SERVER_PORT = -1;
private static final int DEFAULT_SERVER_PORT = 5001;
// MEncoder has a hardwired maximum of 8 threads for -lavcopts and -lavdopts:
// https://code.google.com/p/ps3mediaserver/issues/detail?id=517
private static final int MENCODER_MAX_THREADS = 8;
private static final String KEY_ALTERNATE_SUBS_FOLDER = "alternate_subs_folder";
private static final String KEY_ALTERNATE_THUMB_FOLDER = "alternate_thumb_folder";
private static final String KEY_APERTURE_ENABLED = "aperture";
private static final String KEY_AUDIO_BITRATE = "audiobitrate";
private static final String KEY_AUDIO_CHANNEL_COUNT = "audiochannels";
private static final String KEY_AUDIO_RESAMPLE = "audio_resample";
private static final String KEY_AUDIO_THUMBNAILS_METHOD = "audio_thumbnails_method";
private static final String KEY_AUTO_UPDATE = "auto_update";
private static final String KEY_AVISYNTH_CONVERT_FPS = "avisynth_convertfps";
private static final String KEY_AVISYNTH_SCRIPT = "avisynth_script";
private static final String KEY_BUFFER_TYPE = "buffertype";
private static final String KEY_CHAPTER_INTERVAL = "chapter_interval";
private static final String KEY_CHAPTER_SUPPORT = "chapter_support";
private static final String KEY_CHARSET_ENCODING = "charsetencoding";
private static final String KEY_CODEC_SPEC_SCRIPT = "codec_spec_script";
private static final String KEY_DISABLE_FAKESIZE = "disable_fakesize";
private static final String KEY_DVDISO_THUMBNAILS = "dvd_isos_thumbnails";
private static final String KEY_EMBED_DTS_IN_PCM = "embed_dts_in_pcm";
private static final String KEY_ENGINES = "engines";
private static final String KEY_FFMPEG_ALTERNATIVE_PATH = "alternativeffmpegpath";
private static final String KEY_FFMPEG_SETTINGS = "ffmpeg";
private static final String KEY_FIX_25FPS_AV_MISMATCH = "fix_25fps_av_mismatch";
private static final String KEY_FORCETRANSCODE = "forcetranscode";
private static final String KEY_HIDE_EMPTY_FOLDERS = "hide_empty_folders";
private static final String KEY_HIDE_ENGINENAMES = "hide_enginenames";
private static final String KEY_HIDE_EXTENSIONS = "hide_extensions";
private static final String KEY_HIDE_MEDIA_LIBRARY_FOLDER = "hide_media_library_folder";
private static final String KEY_HIDE_TRANSCODE_FOLDER = "hide_transcode_folder";
private static final String KEY_HIDE_VIDEO_SETTINGS = "hidevideosettings";
private static final String KEY_HTTP_ENGINE_V2 = "http_engine_v2";
private static final String KEY_IMAGE_THUMBNAILS_ENABLED = "image_thumbnails";
private static final String KEY_IP_FILTER = "ip_filter";
private static final String KEY_IPHOTO_ENABLED = "iphoto";
private static final String KEY_ITUNES_ENABLED = "itunes";
private static final String KEY_LANGUAGE = "language";
private static final String KEY_MAX_AUDIO_BUFFER = "maxaudiobuffer";
private static final String KEY_MAX_BITRATE = "maximumbitrate";
private static final String KEY_MAX_MEMORY_BUFFER_SIZE = "maxvideobuffer";
private static final String KEY_MENCODER_AC3_FIXED = "mencoder_ac3_fixed";
private static final String KEY_MENCODER_ASS_DEFAULTSTYLE = "mencoder_ass_defaultstyle";
private static final String KEY_MENCODER_ASS_MARGIN = "mencoder_ass_margin";
private static final String KEY_MENCODER_ASS = "mencoder_ass";
private static final String KEY_MENCODER_ASS_OUTLINE = "mencoder_ass_outline";
private static final String KEY_MENCODER_ASS_SCALE = "mencoder_ass_scale";
private static final String KEY_MENCODER_ASS_SHADOW = "mencoder_ass_shadow";
private static final String KEY_MENCODER_AUDIO_LANGS = "mencoder_audiolangs";
private static final String KEY_MENCODER_AUDIO_SUB_LANGS = "mencoder_audiosublangs";
private static final String KEY_MENCODER_CUSTOM_OPTIONS = "mencoder_decode"; // TODO (breaking change): should be renamed to e.g. mencoder_custom_options
private static final String KEY_MENCODER_DISABLE_SUBS = "mencoder_disablesubs";
private static final String KEY_MENCODER_FONT_CONFIG = "mencoder_fontconfig";
private static final String KEY_MENCODER_FONT = "mencoder_font";
private static final String KEY_MENCODER_FORCED_SUB_LANG = "forced_sub_lang";
private static final String KEY_MENCODER_FORCED_SUB_TAGS = "forced_sub_tags";
private static final String KEY_MENCODER_FORCE_FPS = "mencoder_forcefps";
private static final String KEY_MENCODER_INTELLIGENT_SYNC = "mencoder_intelligent_sync";
private static final String KEY_MENCODER_MAIN_SETTINGS = "mencoder_encode";
private static final String KEY_MENCODER_MAX_THREADS = "mencoder_max_threads";
private static final String KEY_MENCODER_MT = "mencoder_mt";
private static final String KEY_MENCODER_MUX_COMPATIBLE = "mencoder_mux_compatible";
private static final String KEY_MENCODER_NOASS_BLUR = "mencoder_noass_blur";
private static final String KEY_MENCODER_NOASS_OUTLINE = "mencoder_noass_outline";
private static final String KEY_MENCODER_NOASS_SCALE = "mencoder_noass_scale";
private static final String KEY_MENCODER_NOASS_SUBPOS = "mencoder_noass_subpos";
private static final String KEY_MENCODER_NO_OUT_OF_SYNC = "mencoder_nooutofsync";
private static final String KEY_MENCODER_OVERSCAN_COMPENSATION_HEIGHT = "mencoder_overscan_compensation_height";
private static final String KEY_MENCODER_OVERSCAN_COMPENSATION_WIDTH = "mencoder_overscan_compensation_width";
private static final String KEY_MENCODER_REMUX_AC3 = "mencoder_remux_ac3";
private static final String KEY_MENCODER_REMUX_MPEG2 = "mencoder_remux_mpeg2";
private static final String KEY_MENCODER_SCALER = "mencoder_scaler";
private static final String KEY_MENCODER_SCALEX = "mencoder_scalex";
private static final String KEY_MENCODER_SCALEY = "mencoder_scaley";
private static final String KEY_MENCODER_SUB_CP = "mencoder_subcp";
private static final String KEY_MENCODER_SUB_FRIBIDI = "mencoder_subfribidi";
private static final String KEY_MENCODER_SUB_LANGS = "mencoder_sublangs";
private static final String KEY_MENCODER_USE_PCM = "mencoder_usepcm";
private static final String KEY_MENCODER_VOBSUB_SUBTITLE_QUALITY = "mencoder_vobsub_subtitle_quality";
private static final String KEY_MENCODER_YADIF = "mencoder_yadif";
private static final String KEY_MINIMIZED = "minimized";
private static final String KEY_MIN_MEMORY_BUFFER_SIZE = "minvideobuffer";
private static final String KEY_MIN_STREAM_BUFFER = "minwebbuffer";
private static final String KEY_MUX_ALLAUDIOTRACKS = "tsmuxer_mux_all_audiotracks";
private static final String KEY_NETWORK_INTERFACE = "network_interface";
private static final String KEY_NOTRANSCODE = "notranscode";
private static final String KEY_NUMBER_OF_CPU_CORES = "nbcores";
private static final String KEY_OPEN_ARCHIVES = "enable_archive_browsing";
private static final String KEY_OVERSCAN = "mencoder_overscan";
private static final String KEY_PLUGIN_DIRECTORY = "plugins";
private static final String KEY_PREVENTS_SLEEP = "prevents_sleep_mode";
private static final String KEY_PROFILE_NAME = "name";
private static final String KEY_PROXY_SERVER_PORT = "proxy";
private static final String KEY_SERVER_HOSTNAME = "hostname";
private static final String KEY_SERVER_PORT = "port";
private static final String KEY_SHARES = "shares";
private static final String KEY_SKIP_LOOP_FILTER_ENABLED = "skiploopfilter";
private static final String KEY_SKIP_NETWORK_INTERFACES = "skip_network_interfaces";
private static final String KEY_SORT_METHOD = "key_sort_method";
private static final String KEY_SUBS_COLOR = "subs_color";
private static final String KEY_TEMP_FOLDER_PATH = "temp";
private static final String KEY_THUMBNAIL_GENERATION_ENABLED = "thumbnails"; // TODO (breaking change): should be renamed to e.g. generate_thumbnails
private static final String KEY_THUMBNAIL_SEEK_POS = "thumbnail_seek_pos";
private static final String KEY_TRANSCODE_BLOCKS_MULTIPLE_CONNECTIONS = "transcode_block_multiple_connections";
private static final String KEY_TRANSCODE_KEEP_FIRST_CONNECTION = "transcode_keep_first_connection";
private static final String KEY_TSMUXER_FORCEFPS = "tsmuxer_forcefps";
private static final String KEY_TSMUXER_PREREMIX_AC3 = "tsmuxer_preremix_ac3";
private static final String KEY_TURBO_MODE_ENABLED = "turbomode";
private static final String KEY_UPNP_PORT = "upnp_port";
private static final String KEY_USE_CACHE = "usecache";
private static final String KEY_USE_MPLAYER_FOR_THUMBS = "use_mplayer_for_video_thumbs";
private static final String KEY_USE_SUBTITLES = "autoloadsrt";
private static final String KEY_UUID = "uuid";
private static final String KEY_VIDEOTRANSCODE_START_DELAY = "key_videotranscode_start_delay";
private static final String KEY_VIRTUAL_FOLDERS = "vfolders";
// the name of the subdirectory under which PMS config files are stored for this build (default: PMS).
// see Build for more details
private static final String PROFILE_DIRECTORY_NAME = Build.getProfileDirectoryName();
// the default profile name displayed on the renderer
private static String HOSTNAME;
private static String DEFAULT_AVI_SYNTH_SCRIPT;
private static final String BUFFER_TYPE_FILE = "file";
private static final int MAX_MAX_MEMORY_BUFFER_SIZE = 400;
private static final char LIST_SEPARATOR = ',';
private static final String KEY_FOLDERS = "folders";
private final PropertiesConfiguration configuration;
private final TempFolder tempFolder;
private final ProgramPathDisabler programPaths;
private final IpFilter filter = new IpFilter();
/**
* The set of the keys defining when the HTTP server has to restarted due to a configuration change
*/
public static final Set<String> NEED_RELOAD_FLAGS = new HashSet<String>(
Arrays.asList(
KEY_ALTERNATE_THUMB_FOLDER,
KEY_NETWORK_INTERFACE,
KEY_IP_FILTER,
KEY_SORT_METHOD,
KEY_HIDE_EMPTY_FOLDERS,
KEY_HIDE_TRANSCODE_FOLDER,
KEY_HIDE_MEDIA_LIBRARY_FOLDER,
KEY_OPEN_ARCHIVES,
KEY_USE_CACHE,
KEY_HIDE_ENGINENAMES,
KEY_ITUNES_ENABLED,
KEY_IPHOTO_ENABLED,
KEY_APERTURE_ENABLED,
KEY_ENGINES,
KEY_FOLDERS,
KEY_HIDE_VIDEO_SETTINGS,
KEY_AUDIO_THUMBNAILS_METHOD,
KEY_NOTRANSCODE,
KEY_FORCETRANSCODE,
KEY_SERVER_PORT,
KEY_SERVER_HOSTNAME,
KEY_CHAPTER_SUPPORT,
KEY_HIDE_EXTENSIONS
)
);
/*
The following code enables a single setting - PMS_PROFILE - to be used to
initialize PROFILE_PATH i.e. the path to the current session's profile (AKA PMS.conf).
It also initializes PROFILE_DIRECTORY - i.e. the directory the profile is located in -
which is needed for configuration-by-convention detection of WEB.conf (anything else?).
While this convention - and therefore PROFILE_DIRECTORY - will remain,
adding more configurables - e.g. web_conf = ... - is on the TODO list.
PMS_PROFILE is read (in this order) from the property pms.profile.path or the
environment variable PMS_PROFILE. If PMS is launched with the command-line option
"profiles" (e.g. from a shortcut), it displays a file chooser dialog that
allows the pms.profile.path property to be set. This makes it easy to run PMS
under multiple profiles without fiddling with environment variables, properties or
command-line arguments.
1) if PMS_PROFILE is not set, PMS.conf is located in:
Windows: %ALLUSERSPROFILE%\$build
Mac OS X: $HOME/Library/Application Support/$build
Everything else: $HOME/.config/$build
- where $build is a subdirectory that ensures incompatible PMS builds don't target/clobber
the same configuration files. The default value for $build is "PMS". Other builds might use e.g.
"PMS Rendr Edition" or "pms-mlx".
2) if a relative or absolute *directory path* is supplied (the directory must exist),
it is used as the profile directory and the profile is located there under the default profile name (PMS.conf):
PMS_PROFILE = /absolute/path/to/dir
PMS_PROFILE = relative/path/to/dir # relative to the working directory
Amongst other things, this can be used to restore the legacy behaviour of locating PMS.conf in the current
working directory e.g.:
PMS_PROFILE=. ./PMS.sh
3) if a relative or absolute *file path* is supplied (the file doesn't have to exist),
it is taken to be the profile, and its parent dir is taken to be the profile (i.e. config file) dir:
PMS_PROFILE = PMS.conf # profile dir = .
PMS_PROFILE = folder/dev.conf # profile dir = folder
PMS_PROFILE = /path/to/some.file # profile dir = /path/to/
*/
private static final String DEFAULT_PROFILE_FILENAME = "PMS.conf";
private static final String ENV_PROFILE_PATH = "PMS_PROFILE";
private static final String PROFILE_DIRECTORY; // path to directory containing PMS config files
private static final String PROFILE_PATH; // abs path to profile file e.g. /path/to/PMS.conf
private static final String PROPERTY_PROFILE_PATH = "pms.profile.path";
static {
// first try the system property, typically set via the profile chooser
String profile = System.getProperty(PROPERTY_PROFILE_PATH);
// failing that, try the environment variable
if (profile == null) {
profile = System.getenv(ENV_PROFILE_PATH);
}
if (profile != null) {
File f = new File(profile);
// if it exists, we know whether it's a file or directory
// otherwise, it must be a file since we don't autovivify directories
if (f.exists() && f.isDirectory()) {
PROFILE_DIRECTORY = FilenameUtils.normalize(f.getAbsolutePath());
PROFILE_PATH = FilenameUtils.normalize(new File(f, DEFAULT_PROFILE_FILENAME).getAbsolutePath());
} else { // doesn't exist or is a file (i.e. not a directory)
PROFILE_PATH = FilenameUtils.normalize(f.getAbsolutePath());
PROFILE_DIRECTORY = FilenameUtils.normalize(f.getParentFile().getAbsolutePath());
}
} else {
String profileDir = null;
if (Platform.isWindows()) {
String programData = System.getenv("ALLUSERSPROFILE");
if (programData != null) {
profileDir = String.format("%s\\%s", programData, PROFILE_DIRECTORY_NAME);
} else {
profileDir = ""; // i.e. current (working) directory
}
} else if (Platform.isMac()) {
profileDir = String.format(
"%s/%s/%s",
System.getProperty("user.home"),
"/Library/Application Support",
PROFILE_DIRECTORY_NAME
);
} else {
String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
if (xdgConfigHome == null) {
profileDir = String.format("%s/.config/%s", System.getProperty("user.home"), PROFILE_DIRECTORY_NAME);
} else {
profileDir = String.format("%s/%s", xdgConfigHome, PROFILE_DIRECTORY_NAME);
}
}
File f = new File(profileDir);
if ((f.exists() || f.mkdir()) && f.isDirectory()) {
PROFILE_DIRECTORY = FilenameUtils.normalize(f.getAbsolutePath());
} else {
PROFILE_DIRECTORY = FilenameUtils.normalize(new File("").getAbsolutePath());
}
PROFILE_PATH = FilenameUtils.normalize(new File(PROFILE_DIRECTORY, DEFAULT_PROFILE_FILENAME).getAbsolutePath());
}
}
public PmsConfiguration() throws ConfigurationException, IOException {
configuration = new PropertiesConfiguration();
configuration.setListDelimiter((char) 0);
configuration.setFileName(PROFILE_PATH);
File pmsConfFile = new File(PROFILE_PATH);
if (pmsConfFile.exists() && pmsConfFile.isFile()) {
configuration.load(PROFILE_PATH);
}
tempFolder = new TempFolder(getString(KEY_TEMP_FOLDER_PATH, null));
programPaths = createProgramPathsChain(configuration);
Locale.setDefault(new Locale(getLanguage()));
// set DEFAULT_AVI_SYNTH_SCRIPT properly according to language
DEFAULT_AVI_SYNTH_SCRIPT =
Messages.getString("MEncoderAviSynth.4")
+ Messages.getString("MEncoderAviSynth.5")
+ Messages.getString("MEncoderAviSynth.6")
+ Messages.getString("MEncoderAviSynth.7")
+ Messages.getString("MEncoderAviSynth.8")
+ Messages.getString("MEncoderAviSynth.9")
+ Messages.getString("MEncoderAviSynth.10")
+ Messages.getString("MEncoderAviSynth.11")
+ Messages.getString("MEncoderAviSynth.12");
}
/**
* Check if we have disabled something first, then check the config file,
* then the Windows registry, then check for a platform-specific
* default.
*/
private static ProgramPathDisabler createProgramPathsChain(Configuration configuration) {
return new ProgramPathDisabler(
new ConfigurationProgramPaths(configuration,
new WindowsRegistryProgramPaths(
new PlatformSpecificDefaultPathsFactory().get())));
}
public File getTempFolder() throws IOException {
return tempFolder.getTempFolder();
}
public String getVlcPath() {
return programPaths.getVlcPath();
}
public void disableVlc() {
programPaths.disableVlc();
}
public String getEac3toPath() {
return programPaths.getEac3toPath();
}
public String getMencoderPath() {
return programPaths.getMencoderPath();
}
public int getMencoderMaxThreads() {
return Math.min(getInt(KEY_MENCODER_MAX_THREADS, getNumberOfCpuCores()), MENCODER_MAX_THREADS);
}
public String getDCRawPath() {
return programPaths.getDCRaw();
}
public void disableMEncoder() {
programPaths.disableMencoder();
}
public String getFfmpegPath() {
return programPaths.getFfmpegPath();
}
public void disableFfmpeg() {
programPaths.disableFfmpeg();
}
public String getMplayerPath() {
return programPaths.getMplayerPath();
}
public void disableMplayer() {
programPaths.disableMplayer();
}
public String getTsmuxerPath() {
return programPaths.getTsmuxerPath();
}
public String getFlacPath() {
return programPaths.getFlacPath();
}
/**
* If the framerate is not recognized correctly and the video runs too fast or too
* slow, tsMuxeR can be forced to parse the fps from FFmpeg. Default value is true.
* @return True if tsMuxeR should parse fps from FFmpeg.
*/
public boolean isTsmuxerForceFps() {
return configuration.getBoolean(KEY_TSMUXER_FORCEFPS, true);
}
/**
* Force tsMuxeR to mux all audio tracks.
* TODO: Remove this redundant code.
* @return True
*/
public boolean isTsmuxerPreremuxAc3() {
return true;
}
/**
* The AC3 audio bitrate determines the quality of digital audio sound. An AV-receiver
* or amplifier has to be capable of playing this quality. Default value is 640.
* @return The AC3 audio bitrate.
*/
public int getAudioBitrate() {
return getInt(KEY_AUDIO_BITRATE, 640);
}
/**
* Force tsMuxeR to mux all audio tracks.
* TODO: Remove this redundant code; getter always returns true.
*/
public void setTsmuxerPreremuxAc3(boolean value) {
configuration.setProperty(KEY_TSMUXER_PREREMIX_AC3, value);
}
/**
* If the framerate is not recognized correctly and the video runs too fast or too
* slow, tsMuxeR can be forced to parse the fps from FFmpeg.
* @param value Set to true if tsMuxeR should parse fps from FFmpeg.
*/
public void setTsmuxerForceFps(boolean value) {
configuration.setProperty(KEY_TSMUXER_FORCEFPS, value);
}
/**
* The server port where PMS listens for TCP/IP traffic. Default value is 5001.
* @return The port number.
*/
public int getServerPort() {
return getInt(KEY_SERVER_PORT, DEFAULT_SERVER_PORT);
}
/**
* Set the server port where PMS must listen for TCP/IP traffic.
* @param value The TCP/IP port number.
*/
public void setServerPort(int value) {
configuration.setProperty(KEY_SERVER_PORT, value);
}
/**
* The hostname of the server.
* @return The hostname if it is defined, otherwise <code>null</code>.
*/
public String getServerHostname() {
String value = getString(KEY_SERVER_HOSTNAME, "");
if (StringUtils.isNotBlank(value)) {
return value;
} else {
return null;
}
}
/**
* Set the hostname of the server.
* @param value The hostname.
*/
public void setHostname(String value) {
configuration.setProperty(KEY_SERVER_HOSTNAME, value);
}
/**
* The TCP/IP port number for a proxy server. Default value is -1.
* TODO: Is this still used?
* @return The proxy port number.
*/
public int getProxyServerPort() {
return getInt(KEY_PROXY_SERVER_PORT, DEFAULT_PROXY_SERVER_PORT);
}
/**
* Get the code of the preferred language for the PMS user interface. Default
* is based on the locale.
* @return The ISO 639 language code.
*/
public String getLanguage() {
String def = Locale.getDefault().getLanguage();
if (def == null) {
def = "en";
}
String value = getString(KEY_LANGUAGE, def);
return StringUtils.isNotBlank(value) ? value.trim() : def;
}
/**
* Return the <code>int</code> value for a given configuration key. First, the key
* is looked up in the current configuration settings. If it exists and contains a
* valid value, that value is returned. If the key contains an invalid value or
* cannot be found, the specified default value is returned.
* @param key The key to look up.
* @param def The default value to return when no valid key value can be found.
* @return The value configured for the key.
*/
private int getInt(String key, int def) {
try {
return configuration.getInt(key, def);
} catch (ConversionException e) {
return def;
}
}
/**
* Return the <code>boolean</code> value for a given configuration key. First, the
* key is looked up in the current configuration settings. If it exists and contains
* a valid value, that value is returned. If the key contains an invalid value or
* cannot be found, the specified default value is returned.
* @param key The key to look up.
* @param def The default value to return when no valid key value can be found.
* @return The value configured for the key.
*/
private boolean getBoolean(String key, boolean def) {
try {
return configuration.getBoolean(key, def);
} catch (ConversionException e) {
return def;
}
}
/**
* Return the <code>String</code> value for a given configuration key. First, the
* key is looked up in the current configuration settings. If it exists and contains
* a valid value, that value is returned. If the key contains an invalid value or
* cannot be found, the specified default value is returned.
* @param key The key to look up.
* @param def The default value to return when no valid key value can be found.
* @return The value configured for the key.
*/
private String getString(String key, String def) {
String value = configuration.getString(key, def);
if (value != null) {
value = value.trim();
}
return value;
}
/**
* Return a <code>List</code> of <code>String</code> values for a given configuration
* key. First, the key is looked up in the current configuration settings. If it
* exists and contains a valid value, that value is returned. If the key contains an
* invalid value or cannot be found, a list with the specified default values is
* returned.
* @param key The key to look up.
* @param def The default values to return when no valid key value can be found.
* These values should be entered as a comma separated string, whitespace
* will be trimmed. For example: <code>"gnu, gnat ,moo "</code> will be
* returned as <code>{ "gnu", "gnat", "moo" }</code>.
* @return The list of value strings configured for the key.
*/
private List<String> getStringList(String key, String def) {
String value = getString(key, def);
if (value != null) {
String[] arr = value.split(",");
List<String> result = new ArrayList<String>(arr.length);
for (String str : arr) {
if (str.trim().length() > 0) {
result.add(str.trim());
}
}
return result;
} else {
return Collections.emptyList();
}
}
/**
* Returns the preferred minimum size for the transcoding memory buffer in megabytes.
* Default value is 12.
* @return The minimum memory buffer size.
*/
public int getMinMemoryBufferSize() {
return getInt(KEY_MIN_MEMORY_BUFFER_SIZE, 12);
}
/**
* Returns the preferred maximum size for the transcoding memory buffer in megabytes.
* The value returned has a top limit of 600. Default value is 400.
* @return The maximum memory buffer size.
*/
public int getMaxMemoryBufferSize() {
return Math.max(0, Math.min(MAX_MAX_MEMORY_BUFFER_SIZE, getInt(KEY_MAX_MEMORY_BUFFER_SIZE, 400)));
}
/**
* Returns the top limit that can be set for the maximum memory buffer size.
* @return The top limit.
*/
public String getMaxMemoryBufferSizeStr() {
return String.valueOf(MAX_MAX_MEMORY_BUFFER_SIZE);
}
/**
* Set the preferred maximum for the transcoding memory buffer in megabytes. The top
* limit for the value is 600.
* @param value The maximum buffer size.
*/
public void setMaxMemoryBufferSize(int value) {
configuration.setProperty(KEY_MAX_MEMORY_BUFFER_SIZE, Math.max(0, Math.min(MAX_MAX_MEMORY_BUFFER_SIZE, value)));
}
/**
* Returns the font scale used for ASS subtitling. Default value is 1.0.
* @return The ASS font scale.
*/
public String getMencoderAssScale() {
return getString(KEY_MENCODER_ASS_SCALE, "1.0");
}
/**
* Some versions of mencoder produce garbled audio because the "ac3" codec is used
* instead of the "ac3_fixed" codec. Returns true if "ac3_fixed" should be used.
* Default is false.
* See https://code.google.com/p/ps3mediaserver/issues/detail?id=1092#c1
* @return True if "ac3_fixed" should be used.
*/
public boolean isMencoderAc3Fixed() {
return configuration.getBoolean(KEY_MENCODER_AC3_FIXED, false);
}
/**
* Returns the margin used for ASS subtitling. Default value is 10.
* @return The ASS margin.
*/
public String getMencoderAssMargin() {
return getString(KEY_MENCODER_ASS_MARGIN, "10");
}
/**
* Returns the outline parameter used for ASS subtitling. Default value is 1.
* @return The ASS outline parameter.
*/
public String getMencoderAssOutline() {
return getString(KEY_MENCODER_ASS_OUTLINE, "1");
}
/**
* Returns the shadow parameter used for ASS subtitling. Default value is 1.
* @return The ASS shadow parameter.
*/
public String getMencoderAssShadow() {
return getString(KEY_MENCODER_ASS_SHADOW, "1");
}
/**
* Returns the subfont text scale parameter used for subtitling without ASS.
* Default value is 3.
* @return The subfont text scale parameter.
*/
public String getMencoderNoAssScale() {
return getString(KEY_MENCODER_NOASS_SCALE, "3");
}
/**
* Returns the subpos parameter used for subtitling without ASS.
* Default value is 2.
* @return The subpos parameter.
*/
public String getMencoderNoAssSubPos() {
return getString(KEY_MENCODER_NOASS_SUBPOS, "2");
}
/**
* Returns the subfont blur parameter used for subtitling without ASS.
* Default value is 1.
* @return The subfont blur parameter.
*/
public String getMencoderNoAssBlur() {
return getString(KEY_MENCODER_NOASS_BLUR, "1");
}
/**
* Returns the subfont outline parameter used for subtitling without ASS.
* Default value is 1.
* @return The subfont outline parameter.
*/
public String getMencoderNoAssOutline() {
return getString(KEY_MENCODER_NOASS_OUTLINE, "1");
}
/**
* Set the subfont outline parameter used for subtitling without ASS.
* @param value The subfont outline parameter value to set.
*/
public void setMencoderNoAssOutline(String value) {
configuration.setProperty(KEY_MENCODER_NOASS_OUTLINE, value);
}
/**
* Some versions of mencoder produce garbled audio because the "ac3" codec is used
* instead of the "ac3_fixed" codec.
* See https://code.google.com/p/ps3mediaserver/issues/detail?id=1092#c1
* @param value Set to true if "ac3_fixed" should be used.
*/
public void setMencoderAc3Fixed(boolean value) {
configuration.setProperty(KEY_MENCODER_AC3_FIXED, value);
}
/**
* Set the margin used for ASS subtitling.
* @param value The ASS margin value to set.
*/
public void setMencoderAssMargin(String value) {
configuration.setProperty(KEY_MENCODER_ASS_MARGIN, value);
}
/**
* Set the outline parameter used for ASS subtitling.
* @param value The ASS outline parameter value to set.
*/
public void setMencoderAssOutline(String value) {
configuration.setProperty(KEY_MENCODER_ASS_OUTLINE, value);
}
/**
* Set the shadow parameter used for ASS subtitling.
* @param value The ASS shadow parameter value to set.
*/
public void setMencoderAssShadow(String value) {
configuration.setProperty(KEY_MENCODER_ASS_SHADOW, value);
}
/**
* Set the font scale used for ASS subtitling.
* @param value The ASS font scale value to set.
*/
public void setMencoderAssScale(String value) {
configuration.setProperty(KEY_MENCODER_ASS_SCALE, value);
}
/**
* Set the subfont text scale parameter used for subtitling without ASS.
* @param value The subfont text scale parameter value to set.
*/
public void setMencoderNoAssScale(String value) {
configuration.setProperty(KEY_MENCODER_NOASS_SCALE, value);
}
/**
* Set the subfont blur parameter used for subtitling without ASS.
* @param value The subfont blur parameter value to set.
*/
public void setMencoderNoAssBlur(String value) {
configuration.setProperty(KEY_MENCODER_NOASS_BLUR, value);
}
/**
* Set the subpos parameter used for subtitling without ASS.
* @param value The subpos parameter value to set.
*/
public void setMencoderNoAssSubPos(String value) {
configuration.setProperty(KEY_MENCODER_NOASS_SUBPOS, value);
}
/**
* Set the maximum number of concurrent mencoder threads.
* XXX Currently unused.
* @param value The maximum number of concurrent threads.
*/
public void setMencoderMaxThreads(int value) {
configuration.setProperty(KEY_MENCODER_MAX_THREADS, value);
}
/**
* Set the preferred language for the PMS user interface.
* @param value The ISO 639 language code.
*/
public void setLanguage(String value) {
configuration.setProperty(KEY_LANGUAGE, value);
Locale.setDefault(new Locale(getLanguage()));
}
/**
* Returns the number of seconds from the start of a video file (the seek
* position) where the thumbnail image for the movie should be extracted
* from. Default is 1 second.
* @return The seek position in seconds.
*/
public int getThumbnailSeekPos() {
return getInt(KEY_THUMBNAIL_SEEK_POS, 1);
}
/**
* Sets the number of seconds from the start of a video file (the seek
* position) where the thumbnail image for the movie should be extracted
* from.
* @param value The seek position in seconds.
*/
public void setThumbnailSeekPos(int value) {
configuration.setProperty(KEY_THUMBNAIL_SEEK_POS, value);
}
/**
* Older versions of mencoder do not support ASS/SSA subtitles on all
* platforms. Returns true if mencoder supports them. Default is true
* on Windows and OS X, false otherwise.
* See https://code.google.com/p/ps3mediaserver/issues/detail?id=1097
* @return True if mencoder supports ASS/SSA subtitles.
*/
public boolean isMencoderAss() {
return getBoolean(KEY_MENCODER_ASS, Platform.isWindows() || Platform.isMac());
}
/**
* Returns whether or not subtitles should be disabled when using MEncoder
* as transcoding engine. Default is false, meaning subtitles should not
* be disabled.
* @return True if subtitles should be disabled, false otherwise.
*/
public boolean isMencoderDisableSubs() {
return getBoolean(KEY_MENCODER_DISABLE_SUBS, false);
}
/**
* Returns whether or not the Pulse Code Modulation audio format should be
* forced when using MEncoder as transcoding engine. The default is false.
* @return True if PCM should be forced, false otherwise.
*/
public boolean isMencoderUsePcm() {
return getBoolean(KEY_MENCODER_USE_PCM, false);
}
/**
* Returns the name of a TrueType font to use for MEncoder subtitles.
* Default is <code>""</code>.
* @return The font name.
*/
public String getMencoderFont() {
return getString(KEY_MENCODER_FONT, "");
}
/**
* Returns the audio language priority for MEncoder as a comma separated
* string. For example: <code>"eng,fre,jpn,ger,und"</code>, where "und"
* stands for "undefined".
* @return The audio language priority string.
*/
public String getMencoderAudioLanguages() {
return getString(KEY_MENCODER_AUDIO_LANGS, getDefaultLanguages());
}
/**
* Returns a string of comma separated audio or subtitle languages,
* ordered by priority.
* @return The string of languages.
*/
private String getDefaultLanguages() {
if ("fr".equals(getLanguage())) {
return "fre,jpn,ger,eng,und";
} else {
return "eng,fre,jpn,ger,und";
}
}
/**
* Returns the subtitle language priority for MEncoder as a comma
* separated string. For example: <code>"eng,fre,jpn,ger,und"</code>,
* where "und" stands for "undefined".
* @return The subtitle language priority string.
*/
public String getMencoderSubLanguages() {
return getString(KEY_MENCODER_SUB_LANGS, getDefaultLanguages());
}
/**
* Returns the ISO 639 language code for the subtitle language that should
* be forced upon MEncoder.
* @return The subtitle language code.
*/
public String getMencoderForcedSubLanguage() {
return getString(KEY_MENCODER_FORCED_SUB_LANG, getLanguage());
}
/**
* Returns the tag string that identifies the subtitle language that
* should be forced upon MEncoder.
* @return The tag string.
*/
public String getMencoderForcedSubTags() {
return getString(KEY_MENCODER_FORCED_SUB_TAGS, "forced");
}
/**
* Returns a string of audio language and subtitle language pairs
* ordered by priority for MEncoder to try to match. Audio language
* and subtitle language should be comma separated as a pair,
* individual pairs should be semicolon separated. "*" can be used to
* match any language. Subtitle language can be defined as "off". For
* example: <code>"en,off;jpn,eng;*,eng;*;*"</code>.
* Default value is <code>""</code>.
* @return The audio and subtitle languages priority string.
*/
public String getMencoderAudioSubLanguages() {
return getString(KEY_MENCODER_AUDIO_SUB_LANGS, "");
}
/**
* Returns whether or not MEncoder should use FriBiDi mode, which
* is needed to display subtitles in languages that read from right to
* left, like Arabic, Farsi, Hebrew, Urdu, etc. Default value is false.
* @return True if FriBiDi mode should be used, false otherwise.
*/
public boolean isMencoderSubFribidi() {
return getBoolean(KEY_MENCODER_SUB_FRIBIDI, false);
}
/**
* Returns the character encoding (or code page) that MEncoder should use
* for displaying subtitles. Default is "cp1252".
* @return The character encoding.
*/
public String getMencoderSubCp() {
return getString(KEY_MENCODER_SUB_CP, "cp1252");
}
/**
* Returns whether or not MEncoder should use fontconfig for displaying
* subtitles. Default is false.
* @return True if fontconfig should be used, false otherwise.
*/
public boolean isMencoderFontConfig() {
return getBoolean(KEY_MENCODER_FONT_CONFIG, false);
}
/**
* Set to true if MEncoder should be forced to use the framerate that is
* parsed by FFmpeg.
* @param value Set to true if the framerate should be forced, false
* otherwise.
*/
public void setMencoderForceFps(boolean value) {
configuration.setProperty(KEY_MENCODER_FORCE_FPS, value);
}
/**
* Returns true if MEncoder should be forced to use the framerate that is
* parsed by FFmpeg.
* @return True if the framerate should be forced, false otherwise.
*/
public boolean isMencoderForceFps() {
return getBoolean(KEY_MENCODER_FORCE_FPS, false);
}
/**
* Sets the audio language priority for MEncoder as a comma separated
* string. For example: <code>"eng,fre,jpn,ger,und"</code>, where "und"
* stands for "undefined".
* @param value The audio language priority string.
*/
public void setMencoderAudioLanguages(String value) {
configuration.setProperty(KEY_MENCODER_AUDIO_LANGS, value);