2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 /** @file src/config.h
21 * @brief Class holding configuration.
24 #ifndef DCPOMATIC_CONFIG_H
25 #define DCPOMATIC_CONFIG_H
27 #include "isdcf_metadata.h"
29 #include <dcp/certificate_chain.h>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/signals2.hpp>
32 #include <boost/filesystem.hpp>
35 class CinemaSoundProcessor;
41 * @brief A singleton class holding configuration.
43 class Config : public boost::noncopyable
46 /** @return number of threads to use for J2K encoding on the local machine */
47 int num_local_encoding_threads () const {
48 return _num_local_encoding_threads;
51 boost::filesystem::path default_directory () const {
52 return _default_directory;
55 boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
63 /** @return base port number to use for J2K encoding servers */
64 int server_port_base () const {
65 return _server_port_base;
68 void set_use_any_servers (bool u) {
70 changed (USE_ANY_SERVERS);
73 bool use_any_servers () const {
74 return _use_any_servers;
77 /** @param s New list of servers */
78 void set_servers (std::vector<std::string> s) {
83 /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
84 std::vector<std::string> servers () const {
88 bool only_servers_encode () const {
89 return _only_servers_encode;
92 Protocol tms_protocol () const {
96 /** @return The IP address of a TMS that we can copy DCPs to */
97 std::string tms_ip () const {
101 /** @return The path on a TMS that we should changed DCPs to */
102 std::string tms_path () const {
106 /** @return User name to log into the TMS with */
107 std::string tms_user () const {
111 /** @return Password to log into the TMS with */
112 std::string tms_password () const {
113 return _tms_password;
116 /** @return The cinema sound processor that we are using */
117 CinemaSoundProcessor const * cinema_sound_processor () const {
118 return _cinema_sound_processor;
121 std::list<boost::shared_ptr<Cinema> > cinemas () const {
125 std::list<int> allowed_dcp_frame_rates () const {
126 return _allowed_dcp_frame_rates;
129 bool allow_any_dcp_frame_rate () const {
130 return _allow_any_dcp_frame_rate;
133 ISDCFMetadata default_isdcf_metadata () const {
134 return _default_isdcf_metadata;
137 boost::optional<std::string> language () const {
141 int default_still_length () const {
142 return _default_still_length;
145 Ratio const * default_container () const {
146 return _default_container;
149 DCPContentType const * default_dcp_content_type () const {
150 return _default_dcp_content_type;
153 std::string dcp_issuer () const {
157 std::string dcp_creator () const {
161 int default_j2k_bandwidth () const {
162 return _default_j2k_bandwidth;
165 int default_audio_delay () const {
166 return _default_audio_delay;
169 bool default_interop () const {
170 return _default_interop;
173 std::string mail_server () const {
177 int mail_port () const {
181 std::string mail_user () const {
185 std::string mail_password () const {
186 return _mail_password;
189 std::string kdm_subject () const {
193 std::string kdm_from () const {
197 std::string kdm_cc () const {
201 std::string kdm_bcc () const {
205 std::string kdm_email () const {
209 boost::shared_ptr<const dcp::CertificateChain> signer_chain () const {
210 return _signer_chain;
213 boost::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
214 return _decryption_chain;
217 bool check_for_updates () const {
218 return _check_for_updates;
221 bool check_for_test_updates () const {
222 return _check_for_test_updates;
225 int maximum_j2k_bandwidth () const {
226 return _maximum_j2k_bandwidth;
229 int log_types () const {
233 bool automatic_audio_analysis () const {
234 return _automatic_audio_analysis;
237 #ifdef DCPOMATIC_WINDOWS
238 bool win32_console () const {
239 return _win32_console;
243 std::vector<boost::filesystem::path> history () const {
247 /** @param n New number of local encoding threads */
248 void set_num_local_encoding_threads (int n) {
249 maybe_set (_num_local_encoding_threads, n);
252 void set_default_directory (boost::filesystem::path d) {
253 maybe_set (_default_directory, d);
256 /** @param p New server port */
257 void set_server_port_base (int p) {
258 maybe_set (_server_port_base, p);
261 void set_only_servers_encode (bool o) {
262 maybe_set (_only_servers_encode, o);
265 void set_tms_protocol (Protocol p) {
266 maybe_set (_tms_protocol, p);
269 /** @param i IP address of a TMS that we can copy DCPs to */
270 void set_tms_ip (std::string i) {
271 maybe_set (_tms_ip, i);
274 /** @param p Path on a TMS that we should changed DCPs to */
275 void set_tms_path (std::string p) {
276 maybe_set (_tms_path, p);
279 /** @param u User name to log into the TMS with */
280 void set_tms_user (std::string u) {
281 maybe_set (_tms_user, u);
284 /** @param p Password to log into the TMS with */
285 void set_tms_password (std::string p) {
286 maybe_set (_tms_password, p);
289 void add_cinema (boost::shared_ptr<Cinema> c) {
290 _cinemas.push_back (c);
294 void remove_cinema (boost::shared_ptr<Cinema> c) {
299 void set_allowed_dcp_frame_rates (std::list<int> const & r) {
300 maybe_set (_allowed_dcp_frame_rates, r);
303 void set_allow_any_dcp_frame_rate (bool a) {
304 maybe_set (_allow_any_dcp_frame_rate, a);
307 void set_default_isdcf_metadata (ISDCFMetadata d) {
308 maybe_set (_default_isdcf_metadata, d);
311 void set_language (std::string l) {
312 if (_language && _language.get() == l) {
319 void unset_language () {
324 _language = boost::none;
328 void set_default_still_length (int s) {
329 maybe_set (_default_still_length, s);
332 void set_default_container (Ratio const * c) {
333 maybe_set (_default_container, c);
336 void set_default_dcp_content_type (DCPContentType const * t) {
337 maybe_set (_default_dcp_content_type, t);
340 void set_dcp_issuer (std::string i) {
341 maybe_set (_dcp_issuer, i);
344 void set_dcp_creator (std::string c) {
345 maybe_set (_dcp_creator, c);
348 void set_default_j2k_bandwidth (int b) {
349 maybe_set (_default_j2k_bandwidth, b);
352 void set_default_audio_delay (int d) {
353 maybe_set (_default_audio_delay, d);
356 void set_default_interop (bool i) {
357 maybe_set (_default_interop, i);
360 void set_mail_server (std::string s) {
361 maybe_set (_mail_server, s);
364 void set_mail_port (int p) {
365 maybe_set (_mail_port, p);
368 void set_mail_user (std::string u) {
369 maybe_set (_mail_user, u);
372 void set_mail_password (std::string p) {
373 maybe_set (_mail_password, p);
376 void set_kdm_subject (std::string s) {
377 maybe_set (_kdm_subject, s);
380 void set_kdm_from (std::string f) {
381 maybe_set (_kdm_from, f);
384 void set_kdm_cc (std::string f) {
385 maybe_set (_kdm_cc, f);
388 void set_kdm_bcc (std::string f) {
389 maybe_set (_kdm_bcc, f);
392 void set_kdm_email (std::string e) {
393 maybe_set (_kdm_email, e);
396 void reset_kdm_email ();
398 void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
399 maybe_set (_signer_chain, s);
402 void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
403 maybe_set (_decryption_chain, c);
406 void set_check_for_updates (bool c) {
407 maybe_set (_check_for_updates, c);
409 set_check_for_test_updates (false);
413 void set_check_for_test_updates (bool c) {
414 maybe_set (_check_for_test_updates, c);
417 void set_maximum_j2k_bandwidth (int b) {
418 maybe_set (_maximum_j2k_bandwidth, b);
421 void set_log_types (int t) {
422 maybe_set (_log_types, t);
425 void set_automatic_audio_analysis (bool a) {
426 maybe_set (_automatic_audio_analysis, a);
429 #ifdef DCPOMATIC_WINDOWS
430 void set_win32_console (bool c) {
431 maybe_set (_win32_console, c);
435 void clear_history () {
440 void add_to_history (boost::filesystem::path p);
442 void changed (Property p = OTHER);
443 boost::signals2::signal<void (Property)> Changed;
447 static Config* instance ();
449 static void restore_defaults ();
450 static bool have_existing ();
454 static boost::filesystem::path file (bool create_directories = true);
456 void set_defaults ();
457 void set_kdm_email_to_default ();
458 boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
461 void maybe_set (T& member, T new_value) {
462 if (member == new_value) {
469 /** number of threads to use for J2K encoding on the local machine */
470 int _num_local_encoding_threads;
471 /** default directory to put new films in */
472 boost::filesystem::path _default_directory;
473 /** base port number to use for J2K encoding servers;
474 * this port and the two above it will be used.
476 int _server_port_base;
477 /** true to broadcast on the `any' address to look for servers */
478 bool _use_any_servers;
479 /** J2K encoding servers that should definitely be used */
480 std::vector<std::string> _servers;
481 bool _only_servers_encode;
482 Protocol _tms_protocol;
483 /** The IP address of a TMS that we can copy DCPs to */
485 /** The path on a TMS that we should write DCPs to */
486 std::string _tms_path;
487 /** User name to log into the TMS with */
488 std::string _tms_user;
489 /** Password to log into the TMS with */
490 std::string _tms_password;
491 /** Our cinema sound processor */
492 CinemaSoundProcessor const * _cinema_sound_processor;
493 std::list<int> _allowed_dcp_frame_rates;
494 /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
495 bool _allow_any_dcp_frame_rate;
496 /** Default ISDCF metadata for newly-created Films */
497 ISDCFMetadata _default_isdcf_metadata;
498 boost::optional<std::string> _language;
499 /** Default length of still image content (seconds) */
500 int _default_still_length;
501 Ratio const * _default_container;
502 DCPContentType const * _default_dcp_content_type;
503 std::string _dcp_issuer;
504 std::string _dcp_creator;
505 int _default_j2k_bandwidth;
506 int _default_audio_delay;
507 bool _default_interop;
508 std::list<boost::shared_ptr<Cinema> > _cinemas;
509 std::string _mail_server;
511 std::string _mail_user;
512 std::string _mail_password;
513 std::string _kdm_subject;
514 std::string _kdm_from;
516 std::string _kdm_bcc;
517 std::string _kdm_email;
518 boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
519 /** Chain used to decrypt KDMs; the leaf of this chain is the target
520 * certificate for making KDMs given to DCP-o-matic.
522 boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
523 /** true to check for updates on startup */
524 bool _check_for_updates;
525 bool _check_for_test_updates;
526 /** maximum allowed J2K bandwidth in bits per second */
527 int _maximum_j2k_bandwidth;
529 bool _automatic_audio_analysis;
530 #ifdef DCPOMATIC_WINDOWS
533 std::vector<boost::filesystem::path> _history;
535 /** Singleton instance, or 0 */
536 static Config* _instance;