1 /*
2  *  Copyright (C) 2005-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "pictures/PictureScalingAlgorithm.h"
12 #include "settings/lib/ISettingCallback.h"
13 #include "settings/lib/ISettingsHandler.h"
14 #include "utils/SortUtils.h"
15 
16 #include <set>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 #define CACHE_BUFFER_MODE_INTERNET 0
22 #define CACHE_BUFFER_MODE_ALL 1
23 #define CACHE_BUFFER_MODE_TRUE_INTERNET 2
24 #define CACHE_BUFFER_MODE_NONE 3
25 #define CACHE_BUFFER_MODE_NETWORK 4
26 
27 class CAppParamParser;
28 class CProfileManager;
29 class CSettingsManager;
30 class CVariant;
31 struct IntegerSettingOption;
32 
33 class TiXmlElement;
34 namespace ADDON
35 {
36   class IAddon;
37 }
38 
39 class DatabaseSettings
40 {
41 public:
DatabaseSettings()42   DatabaseSettings() { Reset(); }
Reset()43   void Reset()
44   {
45     type.clear();
46     host.clear();
47     port.clear();
48     user.clear();
49     pass.clear();
50     name.clear();
51     key.clear();
52     cert.clear();
53     ca.clear();
54     capath.clear();
55     ciphers.clear();
56     compression = false;
57   };
58   std::string type;
59   std::string host;
60   std::string port;
61   std::string user;
62   std::string pass;
63   std::string name;
64   std::string key;
65   std::string cert;
66   std::string ca;
67   std::string capath;
68   std::string ciphers;
69   bool compression;
70 };
71 
72 struct TVShowRegexp
73 {
74   bool byDate;
75   std::string regexp;
76   int defaultSeason;
77   TVShowRegexp(bool d, const std::string& r, int s = 1):
regexpTVShowRegexp78     regexp(r)
79   {
80     byDate = d;
81     defaultSeason = s;
82   }
83 };
84 
85 struct RefreshOverride
86 {
87   float fpsmin;
88   float fpsmax;
89 
90   float refreshmin;
91   float refreshmax;
92 
93   bool  fallback;
94 };
95 
96 
97 struct RefreshVideoLatency
98 {
99   float refreshmin;
100   float refreshmax;
101 
102   float delay;
103 };
104 
105 typedef std::vector<TVShowRegexp> SETTINGS_TVSHOWLIST;
106 
107 class CAdvancedSettings : public ISettingCallback, public ISettingsHandler
108 {
109   public:
110     CAdvancedSettings();
111 
112     void OnSettingsLoaded() override;
113     void OnSettingsUnloaded() override;
114 
115     void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override;
116 
117     void Initialize(const CAppParamParser &params, CSettingsManager& settingsMgr);
118     void Uninitialize(CSettingsManager& settingsMgr);
Initialized()119     bool Initialized() const { return m_initialized; };
120     void AddSettingsFile(const std::string &filename);
121     bool Load(const CProfileManager &profileManager);
122 
123     static void GetCustomTVRegexps(TiXmlElement *pRootElement, SETTINGS_TVSHOWLIST& settings);
124     static void GetCustomRegexps(TiXmlElement *pRootElement, std::vector<std::string> &settings);
125     static void GetCustomExtensions(TiXmlElement *pRootElement, std::string& extensions);
126 
127     std::string m_audioDefaultPlayer;
128     float m_audioPlayCountMinimumPercent;
129     bool m_VideoPlayerIgnoreDTSinWAV;
130     float m_limiterHold;
131     float m_limiterRelease;
132 
133     bool  m_omlSync = true;
134 
135     float m_videoSubsDelayRange;
136     float m_videoAudioDelayRange;
137     bool m_videoUseTimeSeeking;
138     int m_videoTimeSeekForward;
139     int m_videoTimeSeekBackward;
140     int m_videoTimeSeekForwardBig;
141     int m_videoTimeSeekBackwardBig;
142     int m_videoPercentSeekForward;
143     int m_videoPercentSeekBackward;
144     int m_videoPercentSeekForwardBig;
145     int m_videoPercentSeekBackwardBig;
146     std::vector<int> m_seekSteps;
147     std::string m_videoPPFFmpegPostProc;
148     bool m_videoVDPAUtelecine;
149     bool m_videoVDPAUdeintSkipChromaHD;
150     bool m_musicUseTimeSeeking;
151     int m_musicTimeSeekForward;
152     int m_musicTimeSeekBackward;
153     int m_musicTimeSeekForwardBig;
154     int m_musicTimeSeekBackwardBig;
155     int m_musicPercentSeekForward;
156     int m_musicPercentSeekBackward;
157     int m_musicPercentSeekForwardBig;
158     int m_musicPercentSeekBackwardBig;
159     int m_videoIgnoreSecondsAtStart;
160     float m_videoIgnorePercentAtEnd;
161     float m_audioApplyDrc;
162 
163     int   m_videoVDPAUScaling;
164     float m_videoNonLinStretchRatio;
165     bool  m_videoEnableHighQualityHwScalers;
166     float m_videoAutoScaleMaxFps;
167     std::vector<RefreshOverride> m_videoAdjustRefreshOverrides;
168     std::vector<RefreshVideoLatency> m_videoRefreshLatency;
169     float m_videoDefaultLatency;
170     int  m_videoCaptureUseOcclusionQuery;
171     bool m_DXVACheckCompatibility;
172     bool m_DXVACheckCompatibilityPresent;
173     int  m_videoFpsDetect;
174     float m_maxTempo;
175     bool m_videoPreferStereoStream = false;
176 
177     std::string m_videoDefaultPlayer;
178     float m_videoPlayCountMinimumPercent;
179 
180     float m_slideshowBlackBarCompensation;
181     float m_slideshowZoomAmount;
182     float m_slideshowPanAmount;
183 
184     int m_songInfoDuration;
185     int m_logLevel;
186     int m_logLevelHint;
187     std::string m_cddbAddress;
188     bool m_addSourceOnTop; //!< True to put 'add source' buttons on top
189 
190     //airtunes + airplay
191     int m_airTunesPort;
192     int m_airPlayPort;
193 
194     bool m_handleMounting;
195 
196     bool m_fullScreenOnMovieStart;
197     std::string m_cachePath;
198     std::string m_videoCleanDateTimeRegExp;
199     std::vector<std::string> m_videoCleanStringRegExps;
200     std::vector<std::string> m_videoExcludeFromListingRegExps;
201     std::vector<std::string> m_allExcludeFromScanRegExps;
202     std::vector<std::string> m_moviesExcludeFromScanRegExps;
203     std::vector<std::string> m_tvshowExcludeFromScanRegExps;
204     std::vector<std::string> m_audioExcludeFromListingRegExps;
205     std::vector<std::string> m_audioExcludeFromScanRegExps;
206     std::vector<std::string> m_pictureExcludeFromListingRegExps;
207     std::vector<std::string> m_videoStackRegExps;
208     std::vector<std::string> m_folderStackRegExps;
209     std::vector<std::string> m_trailerMatchRegExps;
210     SETTINGS_TVSHOWLIST m_tvshowEnumRegExps;
211     std::string m_tvshowMultiPartEnumRegExp;
212     typedef std::vector< std::pair<std::string, std::string> > StringMapping;
213     StringMapping m_pathSubstitutions;
214     int m_remoteDelay; ///< \brief number of remote messages to ignore before repeating
215     bool m_bScanIRServer;
216 
217     bool m_playlistAsFolders;
218     bool m_detectAsUdf;
219 
220     unsigned int m_fanartRes; ///< \brief the maximal resolution to cache fanart at (assumes 16x9)
221     unsigned int m_imageRes;  ///< \brief the maximal resolution to cache images at (assumes 16x9)
222     CPictureScalingAlgorithm::Algorithm m_imageScalingAlgorithm;
223 
224     int m_sambaclienttimeout;
225     std::string m_sambadoscodepage;
226     bool m_sambastatfiles;
227 
228     bool m_bHTTPDirectoryStatFilesize;
229 
230     bool m_bFTPThumbs;
231     bool m_bShoutcastArt;
232 
233     std::string m_musicThumbs;
234     std::vector<std::string> m_musicArtistExtraArt;
235     std::vector<std::string> m_musicAlbumExtraArt;
236 
237     int m_iMusicLibraryRecentlyAddedItems;
238     int m_iMusicLibraryDateAdded;
239     bool m_bMusicLibraryAllItemsOnBottom;
240     bool m_bMusicLibraryCleanOnUpdate;
241     bool m_bMusicLibraryArtistSortOnUpdate;
242     bool m_bMusicLibraryUseISODates;
243     std::string m_strMusicLibraryAlbumFormat;
244     bool m_prioritiseAPEv2tags;
245     std::string m_musicItemSeparator;
246     std::vector<std::string> m_musicArtistSeparators;
247     std::string m_videoItemSeparator;
248     std::vector<std::string> m_musicTagsFromFileFilters;
249 
250     bool m_bVideoLibraryAllItemsOnBottom;
251     int m_iVideoLibraryRecentlyAddedItems;
252     bool m_bVideoLibraryCleanOnUpdate;
253     bool m_bVideoLibraryUseFastHash;
254     bool m_bVideoLibraryImportWatchedState;
255     bool m_bVideoLibraryImportResumePoint;
256     std::vector<std::string> m_videoEpisodeExtraArt;
257     std::vector<std::string> m_videoTvShowExtraArt;
258     std::vector<std::string> m_videoTvSeasonExtraArt;
259     std::vector<std::string> m_videoMovieExtraArt;
260     std::vector<std::string> m_videoMovieSetExtraArt;
261     std::vector<std::string> m_videoMusicVideoExtraArt;
262 
263     bool m_bVideoScannerIgnoreErrors;
264     int m_iVideoLibraryDateAdded;
265 
266     std::set<std::string> m_vecTokens;
267 
268     int m_iEpgUpdateCheckInterval;  // seconds
269     int m_iEpgCleanupInterval;      // seconds
270     int m_iEpgActiveTagCheckInterval; // seconds
271     int m_iEpgRetryInterruptedUpdateInterval; // seconds
272     int m_iEpgUpdateEmptyTagsInterval; // seconds
273     bool m_bEpgDisplayUpdatePopup;
274     bool m_bEpgDisplayIncrementalUpdatePopup;
275 
276     // EDL Commercial Break
277     bool m_bEdlMergeShortCommBreaks;
278     int m_iEdlMaxCommBreakLength;   // seconds
279     int m_iEdlMinCommBreakLength;   // seconds
280     int m_iEdlMaxCommBreakGap;      // seconds
281     int m_iEdlMaxStartGap;          // seconds
282     int m_iEdlCommBreakAutowait;    // seconds
283     int m_iEdlCommBreakAutowind;    // seconds
284 
285     int m_curlconnecttimeout;
286     int m_curllowspeedtime;
287     int m_curlretries;
288     int m_curlKeepAliveInterval;    // seconds
289     bool m_curlDisableIPV6;
290     bool m_curlDisableHTTP2;
291 
292     std::string m_caTrustFile;
293 
294     bool m_fullScreen;
295     bool m_startFullScreen;
296     bool m_showExitButton; /* Ideal for appliances to hide a 'useless' button */
297     bool m_canWindowed;
298     bool m_splashImage;
299     bool m_alwaysOnTop;  /* makes xbmc to run always on top .. osx/win32 only .. */
300     int m_playlistRetries;
301     int m_playlistTimeout;
302     bool m_GLRectangleHack;
303     int m_iSkipLoopFilter;
304 
305     bool m_bVirtualShares;
306     bool m_bTry10bitOutput;
307 
308     std::string m_cpuTempCmd;
309     std::string m_gpuTempCmd;
310 
311     /* PVR/TV related advanced settings */
312     int m_iPVRTimeCorrection;     /*!< @brief correct all times (epg tags, timer tags, recording tags) by this amount of minutes. defaults to 0. */
313     int m_iPVRInfoToggleInterval; /*!< @brief if there are more than 1 pvr gui info item available (e.g. multiple recordings active at the same time), use this toggle delay in milliseconds. defaults to 3000. */
314     bool m_bPVRChannelIconsAutoScan; /*!< @brief automatically scan user defined folder for channel icons when loading internal channel groups */
315     bool m_bPVRAutoScanIconsUserSet; /*!< @brief mark channel icons populated by auto scan as "user set" */
316     int m_iPVRNumericChannelSwitchTimeout; /*!< @brief time in msecs after that a channel switch occurs after entering a channel number, if confirmchannelswitch is disabled */
317     int m_iPVRTimeshiftThreshold; /*!< @brief time diff between current playing time and timeshift buffer end, in seconds, before a playing stream is displayed as timeshifting. */
318     bool m_bPVRTimeshiftSimpleOSD; /*!< @brief use simple timeshift OSD (with progress only for the playing event instead of progress for the whole ts buffer). */
319     SortDescription m_PVRDefaultSortOrder; /*!< @brief SortDecription used to store default recording sort type and sort order */
320 
321     DatabaseSettings m_databaseMusic; // advanced music database setup
322     DatabaseSettings m_databaseVideo; // advanced video database setup
323     DatabaseSettings m_databaseTV;    // advanced tv database setup
324     DatabaseSettings m_databaseEpg;   /*!< advanced EPG database setup */
325 
326     bool m_useLocaleCollation;
327 
328     bool m_guiVisualizeDirtyRegions;
329     int  m_guiAlgorithmDirtyRegions;
330     bool m_guiSmartRedraw;
331     unsigned int m_addonPackageFolderSize;
332 
333     unsigned int m_cacheMemSize;
334     unsigned int m_cacheBufferMode;
335     unsigned int m_cacheChunkSize;
336     float m_cacheReadFactor;
337 
338     bool m_jsonOutputCompact;
339     unsigned int m_jsonTcpPort;
340 
341     bool m_enableMultimediaKeys;
342     std::vector<std::string> m_settingsFiles;
343     void ParseSettingsFile(const std::string &file);
344 
345     float GetLatencyTweak(float refreshrate);
346     bool m_initialized;
347 
348     void SetDebugMode(bool debug);
349 
350     //! \brief Toggles dirty-region visualization
ToggleDirtyRegionVisualization()351     void ToggleDirtyRegionVisualization() { m_guiVisualizeDirtyRegions = !m_guiVisualizeDirtyRegions; };
352 
353     // runtime settings which cannot be set from advancedsettings.xml
354     std::string m_videoExtensions;
355     std::string m_discStubExtensions;
356     std::string m_subtitlesExtensions;
357     std::string m_musicExtensions;
358     std::string m_pictureExtensions;
359 
360     std::string m_stereoscopicregex_3d;
361     std::string m_stereoscopicregex_sbs;
362     std::string m_stereoscopicregex_tab;
363 
364     /*!< @brief position behavior of ass subtitles when setting "subtitle position on screen" set to "fixed"
365     True to show at the fixed position set in video calibration
366     False to show at the bottom of video (default) */
367     bool m_videoAssFixedWorks;
368 
369     bool m_openGlDebugging;
370 
371     std::string m_userAgent;
372     uint32_t m_nfsTimeout;
373     int m_nfsRetries;
374 
375   private:
376     void Initialize();
377     void Clear();
378     void SetExtraArtwork(const TiXmlElement* arttypes, std::vector<std::string>& artworkMap);
379     void MigrateOldArtSettings();
380 };
381