Add only-servers-encode option for debugging / optimisation / testing of servers.
[dcpomatic.git] / src / lib / config.h
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/config.h
21  *  @brief Class holding configuration.
22  */
23
24 #ifndef DCPOMATIC_CONFIG_H
25 #define DCPOMATIC_CONFIG_H
26
27 #include "isdcf_metadata.h"
28 #include "video_content.h"
29 #include <dcp/metadata.h>
30 #include <dcp/certificate.h>
31 #include <dcp/certificate_chain.h>
32 #include <boost/shared_ptr.hpp>
33 #include <boost/signals2.hpp>
34 #include <boost/filesystem.hpp>
35 #include <vector>
36
37 class ServerDescription;
38 class Scaler;
39 class Filter;
40 class CinemaSoundProcessor;
41 class DCPContentType;
42 class Ratio;
43 class Cinema;
44
45 /** @class Config
46  *  @brief A singleton class holding configuration.
47  */
48 class Config : public boost::noncopyable
49 {
50 public:
51         /** @return number of threads to use for J2K encoding on the local machine */
52         int num_local_encoding_threads () const {
53                 return _num_local_encoding_threads;
54         }
55
56         boost::filesystem::path default_directory () const {
57                 return _default_directory;
58         }
59
60         boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
61
62         enum Property {
63                 USE_ANY_SERVERS,
64                 SERVERS,
65                 OTHER
66         };
67
68         /** @return base port number to use for J2K encoding servers */
69         int server_port_base () const {
70                 return _server_port_base;
71         }
72
73         void set_use_any_servers (bool u) {
74                 _use_any_servers = u;
75                 changed (USE_ANY_SERVERS);
76         }
77
78         bool use_any_servers () const {
79                 return _use_any_servers;
80         }
81
82         /** @param s New list of servers */
83         void set_servers (std::vector<std::string> s) {
84                 _servers = s;
85                 changed (SERVERS);
86         }
87
88         /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
89         std::vector<std::string> servers () const {
90                 return _servers;
91         }
92
93         bool only_servers_encode () const {
94                 return _only_servers_encode;
95         }
96
97         Protocol tms_protocol () const {
98                 return _tms_protocol;
99         }
100
101         /** @return The IP address of a TMS that we can copy DCPs to */
102         std::string tms_ip () const {
103                 return _tms_ip;
104         }
105
106         /** @return The path on a TMS that we should changed DCPs to */
107         std::string tms_path () const {
108                 return _tms_path;
109         }
110
111         /** @return User name to log into the TMS with */
112         std::string tms_user () const {
113                 return _tms_user;
114         }
115
116         /** @return Password to log into the TMS with */
117         std::string tms_password () const {
118                 return _tms_password;
119         }
120
121         /** @return The cinema sound processor that we are using */
122         CinemaSoundProcessor const * cinema_sound_processor () const {
123                 return _cinema_sound_processor;
124         }
125
126         std::list<boost::shared_ptr<Cinema> > cinemas () const {
127                 return _cinemas;
128         }
129
130         std::list<int> allowed_dcp_frame_rates () const {
131                 return _allowed_dcp_frame_rates;
132         }
133
134         bool allow_any_dcp_frame_rate () const {
135                 return _allow_any_dcp_frame_rate;
136         }
137
138         ISDCFMetadata default_isdcf_metadata () const {
139                 return _default_isdcf_metadata;
140         }
141
142         boost::optional<std::string> language () const {
143                 return _language;
144         }
145
146         int default_still_length () const {
147                 return _default_still_length;
148         }
149
150         Ratio const * default_container () const {
151                 return _default_container;
152         }
153
154         DCPContentType const * default_dcp_content_type () const {
155                 return _default_dcp_content_type;
156         }
157
158         std::string dcp_issuer () const {
159                 return _dcp_issuer;
160         }
161
162         std::string dcp_creator () const {
163                 return _dcp_creator;
164         }
165
166         int default_j2k_bandwidth () const {
167                 return _default_j2k_bandwidth;
168         }
169
170         int default_audio_delay () const {
171                 return _default_audio_delay;
172         }
173
174         std::string mail_server () const {
175                 return _mail_server;
176         }
177
178         int mail_port () const {
179                 return _mail_port;
180         }
181
182         std::string mail_user () const {
183                 return _mail_user;
184         }
185
186         std::string mail_password () const {
187                 return _mail_password;
188         }
189
190         std::string kdm_subject () const {
191                 return _kdm_subject;
192         }
193
194         std::string kdm_from () const {
195                 return _kdm_from;
196         }
197
198         std::string kdm_cc () const {
199                 return _kdm_cc;
200         }
201
202         std::string kdm_bcc () const {
203                 return _kdm_bcc;
204         }
205
206         std::string kdm_email () const {
207                 return _kdm_email;
208         }
209
210         boost::shared_ptr<const dcp::CertificateChain> signer_chain () const {
211                 return _signer_chain;
212         }
213
214         boost::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
215                 return _decryption_chain;
216         }
217
218         bool check_for_updates () const {
219                 return _check_for_updates;
220         }
221
222         bool check_for_test_updates () const {
223                 return _check_for_test_updates;
224         }
225
226         int maximum_j2k_bandwidth () const {
227                 return _maximum_j2k_bandwidth;
228         }
229
230         int log_types () const {
231                 return _log_types;
232         }
233
234 #ifdef DCPOMATIC_WINDOWS
235         bool win32_console () const {
236                 return _win32_console;
237         }
238 #endif
239
240         std::vector<boost::filesystem::path> history () const {
241                 return _history;
242         }
243
244         /** @param n New number of local encoding threads */
245         void set_num_local_encoding_threads (int n) {
246                 maybe_set (_num_local_encoding_threads, n);
247         }
248
249         void set_default_directory (boost::filesystem::path d) {
250                 maybe_set (_default_directory, d);
251         }
252
253         /** @param p New server port */
254         void set_server_port_base (int p) {
255                 maybe_set (_server_port_base, p);
256         }
257
258         void set_only_servers_encode (bool o) {
259                 maybe_set (_only_servers_encode, o);
260         }
261
262         void set_tms_protocol (Protocol p) {
263                 maybe_set (_tms_protocol, p);
264         }
265
266         /** @param i IP address of a TMS that we can copy DCPs to */
267         void set_tms_ip (std::string i) {
268                 maybe_set (_tms_ip, i);
269         }
270
271         /** @param p Path on a TMS that we should changed DCPs to */
272         void set_tms_path (std::string p) {
273                 maybe_set (_tms_path, p);
274         }
275
276         /** @param u User name to log into the TMS with */
277         void set_tms_user (std::string u) {
278                 maybe_set (_tms_user, u);
279         }
280
281         /** @param p Password to log into the TMS with */
282         void set_tms_password (std::string p) {
283                 maybe_set (_tms_password, p);
284         }
285
286         void add_cinema (boost::shared_ptr<Cinema> c) {
287                 _cinemas.push_back (c);
288                 changed ();
289         }
290
291         void remove_cinema (boost::shared_ptr<Cinema> c) {
292                 _cinemas.remove (c);
293                 changed ();
294         }
295
296         void set_allowed_dcp_frame_rates (std::list<int> const & r) {
297                 maybe_set (_allowed_dcp_frame_rates, r);
298         }
299
300         void set_allow_any_dcp_frame_rate (bool a) {
301                 maybe_set (_allow_any_dcp_frame_rate, a);
302         }
303
304         void set_default_isdcf_metadata (ISDCFMetadata d) {
305                 maybe_set (_default_isdcf_metadata, d);
306         }
307
308         void set_language (std::string l) {
309                 if (_language && _language.get() == l) {
310                         return;
311                 }
312                 _language = l;
313                 changed ();
314         }
315
316         void unset_language () {
317                 if (!_language) {
318                         return;
319                 }
320
321                 _language = boost::none;
322                 changed ();
323         }
324
325         void set_default_still_length (int s) {
326                 maybe_set (_default_still_length, s);
327         }
328
329         void set_default_container (Ratio const * c) {
330                 maybe_set (_default_container, c);
331         }
332
333         void set_default_dcp_content_type (DCPContentType const * t) {
334                 maybe_set (_default_dcp_content_type, t);
335         }
336
337         void set_dcp_issuer (std::string i) {
338                 maybe_set (_dcp_issuer, i);
339         }
340
341         void set_dcp_creator (std::string c) {
342                 maybe_set (_dcp_creator, c);
343         }
344
345         void set_default_j2k_bandwidth (int b) {
346                 maybe_set (_default_j2k_bandwidth, b);
347         }
348
349         void set_default_audio_delay (int d) {
350                 maybe_set (_default_audio_delay, d);
351         }
352
353         void set_mail_server (std::string s) {
354                 maybe_set (_mail_server, s);
355         }
356
357         void set_mail_port (int p) {
358                 maybe_set (_mail_port, p);
359         }
360
361         void set_mail_user (std::string u) {
362                 maybe_set (_mail_user, u);
363         }
364
365         void set_mail_password (std::string p) {
366                 maybe_set (_mail_password, p);
367         }
368
369         void set_kdm_subject (std::string s) {
370                 maybe_set (_kdm_subject, s);
371         }
372
373         void set_kdm_from (std::string f) {
374                 maybe_set (_kdm_from, f);
375         }
376
377         void set_kdm_cc (std::string f) {
378                 maybe_set (_kdm_cc, f);
379         }
380
381         void set_kdm_bcc (std::string f) {
382                 maybe_set (_kdm_bcc, f);
383         }
384
385         void set_kdm_email (std::string e) {
386                 maybe_set (_kdm_email, e);
387         }
388
389         void reset_kdm_email ();
390
391         void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
392                 maybe_set (_signer_chain, s);
393         }
394
395         void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
396                 maybe_set (_decryption_chain, c);
397         }
398
399         void set_check_for_updates (bool c) {
400                 maybe_set (_check_for_updates, c);
401         }
402
403         void set_check_for_test_updates (bool c) {
404                 maybe_set (_check_for_test_updates, c);
405         }
406
407         void set_maximum_j2k_bandwidth (int b) {
408                 maybe_set (_maximum_j2k_bandwidth, b);
409         }
410
411         void set_log_types (int t) {
412                 maybe_set (_log_types, t);
413         }
414
415 #ifdef DCPOMATIC_WINDOWS
416         void set_win32_console (bool c) {
417                 maybe_set (_win32_console, c);
418         }
419 #endif
420
421         void clear_history () {
422                 _history.clear ();
423                 changed ();
424         }
425
426         void add_to_history (boost::filesystem::path p);
427
428         void changed (Property p = OTHER);
429         boost::signals2::signal<void (Property)> Changed;
430
431         void write () const;
432
433         static Config* instance ();
434         static void drop ();
435         static void restore_defaults ();
436         static bool have_existing ();
437
438 private:
439         Config ();
440         static boost::filesystem::path file ();
441         void read ();
442         void set_defaults ();
443         void set_kdm_email_to_default ();
444
445         template <class T>
446         void maybe_set (T& member, T new_value) {
447                 if (member == new_value) {
448                         return;
449                 }
450                 member = new_value;
451                 changed ();
452         }
453
454         /** number of threads to use for J2K encoding on the local machine */
455         int _num_local_encoding_threads;
456         /** default directory to put new films in */
457         boost::filesystem::path _default_directory;
458         /** base port number to use for J2K encoding servers;
459          *  this port and the one above it will be used.
460          */
461         int _server_port_base;
462         /** true to broadcast on the `any' address to look for servers */
463         bool _use_any_servers;
464         /** J2K encoding servers that should definitely be used */
465         std::vector<std::string> _servers;
466         bool _only_servers_encode;
467         Protocol _tms_protocol;
468         /** The IP address of a TMS that we can copy DCPs to */
469         std::string _tms_ip;
470         /** The path on a TMS that we should write DCPs to */
471         std::string _tms_path;
472         /** User name to log into the TMS with */
473         std::string _tms_user;
474         /** Password to log into the TMS with */
475         std::string _tms_password;
476         /** Our cinema sound processor */
477         CinemaSoundProcessor const * _cinema_sound_processor;
478         std::list<int> _allowed_dcp_frame_rates;
479         /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
480         bool _allow_any_dcp_frame_rate;
481         /** Default ISDCF metadata for newly-created Films */
482         ISDCFMetadata _default_isdcf_metadata;
483         boost::optional<std::string> _language;
484         /** Default length of still image content (seconds) */
485         int _default_still_length;
486         Ratio const * _default_container;
487         DCPContentType const * _default_dcp_content_type;
488         std::string _dcp_issuer;
489         std::string _dcp_creator;
490         int _default_j2k_bandwidth;
491         int _default_audio_delay;
492         std::list<boost::shared_ptr<Cinema> > _cinemas;
493         std::string _mail_server;
494         int _mail_port;
495         std::string _mail_user;
496         std::string _mail_password;
497         std::string _kdm_subject;
498         std::string _kdm_from;
499         std::string _kdm_cc;
500         std::string _kdm_bcc;
501         std::string _kdm_email;
502         boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
503         /** Chain used to decrypt KDMs; the leaf of this chain is the target
504          *  certificate for making KDMs given to DCP-o-matic.
505          */
506         boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
507         /** true to check for updates on startup */
508         bool _check_for_updates;
509         bool _check_for_test_updates;
510         /** maximum allowed J2K bandwidth in bits per second */
511         int _maximum_j2k_bandwidth;
512         int _log_types;
513 #ifdef DCPOMATIC_WINDOWS
514         bool _win32_console;
515 #endif
516         std::vector<boost::filesystem::path> _history;
517
518         /** Singleton instance, or 0 */
519         static Config* _instance;
520 };
521
522 #endif