X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fconfig.cc;h=79a7b01f1dd68f4aebf39cb07e5797533926abfa;hb=5d398836a9b6acc2bbb536dabbd7bbc42a098659;hp=7d8e823351656fdff8c019f31ce963d7510315b1;hpb=71b531d0e2ee661b008e343850daf91ff4708a20;p=dcpomatic.git diff --git a/src/lib/config.cc b/src/lib/config.cc index 7d8e82335..79a7b01f1 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -22,13 +22,17 @@ #include #include #include +#include +#include #include "config.h" #include "server.h" #include "scaler.h" #include "filter.h" -#include "format.h" +#include "ratio.h" #include "dcp_content_type.h" #include "sound_processor.h" +#include "colour_conversion.h" +#include "cinema.h" #include "i18n.h" @@ -36,19 +40,27 @@ using std::vector; using std::ifstream; using std::string; using std::ofstream; +using std::list; +using std::max; using boost::shared_ptr; +using boost::lexical_cast; +using boost::optional; Config* Config::_instance = 0; /** Construct default configuration */ Config::Config () - : _num_local_encoding_threads (2) + : _num_local_encoding_threads (max (2U, boost::thread::hardware_concurrency())) , _server_port (6192) - , _reference_scaler (Scaler::from_id (N_("bicubic"))) - , _tms_path (N_(".")) + , _tms_path (".") , _sound_processor (SoundProcessor::from_id (N_("dolby_cp750"))) - , _default_format (0) - , _default_dcp_content_type (0) + , _default_still_length (10) + , _default_container (Ratio::from_id ("185")) + , _default_dcp_content_type (DCPContentType::from_dci_name ("TST")) + , _default_j2k_bandwidth (200000000) + , _kdm_email ( + "Dear Projectionist\n\nPlease find attached KDMs for $CPL_NAME.\n\nBest regards,\nDCP-o-matic" + ) { _allowed_dcp_frame_rates.push_back (24); _allowed_dcp_frame_rates.push_back (25); @@ -56,9 +68,92 @@ Config::Config () _allowed_dcp_frame_rates.push_back (48); _allowed_dcp_frame_rates.push_back (50); _allowed_dcp_frame_rates.push_back (60); + + _colour_conversions.push_back (PresetColourConversion (_("sRGB"), 2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6)); + _colour_conversions.push_back (PresetColourConversion (_("sRGB non-linearised"), 2.4, false, libdcp::colour_matrix::srgb_to_xyz, 2.6)); +} + +void +Config::read () +{ + if (!boost::filesystem::exists (file (false))) { + read_old_metadata (); + return; + } + + cxml::Document f ("Config"); + f.read_file (file (false)); + optional c; + + _num_local_encoding_threads = f.number_child ("NumLocalEncodingThreads"); + _default_directory = f.string_child ("DefaultDirectory"); + _server_port = f.number_child ("ServerPort"); - ifstream f (file().c_str ()); + list > servers = f.node_children ("Server"); + for (list >::iterator i = servers.begin(); i != servers.end(); ++i) { + _servers.push_back (ServerDescription (*i)); + } + + _tms_ip = f.string_child ("TMSIP"); + _tms_path = f.string_child ("TMSPath"); + _tms_user = f.string_child ("TMSUser"); + _tms_password = f.string_child ("TMSPassword"); + + c = f.optional_string_child ("SoundProcessor"); + if (c) { + _sound_processor = SoundProcessor::from_id (c.get ()); + } + + _language = f.optional_string_child ("Language"); + + c = f.optional_string_child ("DefaultContainer"); + if (c) { + _default_container = Ratio::from_id (c.get ()); + } + + c = f.optional_string_child ("DefaultDCPContentType"); + if (c) { + _default_dcp_content_type = DCPContentType::from_dci_name (c.get ()); + } + + _dcp_metadata.issuer = f.optional_string_child ("DCPMetadataIssuer").get_value_or (""); + _dcp_metadata.creator = f.optional_string_child ("DCPMetadataCreator").get_value_or (""); + + _default_dci_metadata = DCIMetadata (f.node_child ("DCIMetadata")); + _default_still_length = f.optional_number_child("DefaultStillLength").get_value_or (10); + _default_j2k_bandwidth = f.optional_number_child("DefaultJ2KBandwidth").get_value_or (200000000); + + list > cc = f.node_children ("ColourConversion"); + + if (!cc.empty ()) { + _colour_conversions.clear (); + } + + for (list >::iterator i = cc.begin(); i != cc.end(); ++i) { + _colour_conversions.push_back (PresetColourConversion (*i)); + } + + list > cin = f.node_children ("Cinema"); + for (list >::iterator i = cin.begin(); i != cin.end(); ++i) { + /* Slightly grotty two-part construction of Cinema here so that we can use + shared_from_this. + */ + shared_ptr cinema (new Cinema (*i)); + cinema->read_screens (*i); + _cinemas.push_back (cinema); + } + + _mail_server = f.string_child ("MailServer"); + _kdm_from = f.string_child ("KDMFrom"); + _kdm_email = f.string_child ("KDMEmail"); +} + +void +Config::read_old_metadata () +{ + ifstream f (file(true).string().c_str ()); string line; + while (getline (f, line)) { if (line.empty ()) { continue; @@ -82,12 +177,11 @@ Config::Config () _default_directory = v; } else if (k == N_("server_port")) { _server_port = atoi (v.c_str ()); - } else if (k == N_("reference_scaler")) { - _reference_scaler = Scaler::from_id (v); - } else if (k == N_("reference_filter")) { - _reference_filters.push_back (Filter::from_id (v)); } else if (k == N_("server")) { - _servers.push_back (ServerDescription::create_from_metadata (v)); + optional server = ServerDescription::create_from_metadata (v); + if (server) { + _servers.push_back (server.get ()); + } } else if (k == N_("tms_ip")) { _tms_ip = v; } else if (k == N_("tms_path")) { @@ -100,8 +194,8 @@ Config::Config () _sound_processor = SoundProcessor::from_id (v); } else if (k == "language") { _language = v; - } else if (k == "default_format") { - _default_format = Format::from_metadata (v); + } else if (k == "default_container") { + _default_container = Ratio::from_id (v); } else if (k == "default_dcp_content_type") { _default_dcp_content_type = DCPContentType::from_dci_name (v); } else if (k == "dcp_metadata_issuer") { @@ -112,20 +206,36 @@ Config::Config () _dcp_metadata.issue_date = v; } - _default_dci_metadata.read (k, v); + _default_dci_metadata.read_old_metadata (k, v); } } /** @return Filename to write configuration to */ -string -Config::file () const +boost::filesystem::path +Config::file (bool old) const { boost::filesystem::path p; p /= g_get_user_config_dir (); boost::system::error_code ec; boost::filesystem::create_directory (p, ec); - p /= N_(".dvdomatic"); - return p.string (); + if (old) { + p /= ".dvdomatic"; + } else { + p /= "dcpomatic"; + p /= "config.xml"; + } + return p; +} + +boost::filesystem::path +Config::signer_chain_directory () const +{ + boost::filesystem::path p; + p /= g_get_user_config_dir (); + p /= "dcpomatic"; + p /= "crypt"; + boost::filesystem::create_directories (p); + return p; } /** @return Singleton instance */ @@ -134,6 +244,13 @@ Config::instance () { if (_instance == 0) { _instance = new Config; + try { + _instance->read (); + } catch (...) { + /* configuration load failed; never mind, just + stick with the default. + */ + } } return _instance; @@ -143,48 +260,58 @@ Config::instance () void Config::write () const { - ofstream f (file().c_str ()); - f << "num_local_encoding_threads " << _num_local_encoding_threads << "\n" - << "default_directory " << _default_directory << "\n" - << "server_port " << _server_port << "\n"; - - if (_reference_scaler) { - f << "reference_scaler " << _reference_scaler->id () << "\n"; - } + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("Config"); - for (vector::const_iterator i = _reference_filters.begin(); i != _reference_filters.end(); ++i) { - f << "reference_filter " << (*i)->id () << "\n"; - } + root->add_child("NumLocalEncodingThreads")->add_child_text (lexical_cast (_num_local_encoding_threads)); + root->add_child("DefaultDirectory")->add_child_text (_default_directory.string ()); + root->add_child("ServerPort")->add_child_text (lexical_cast (_server_port)); - for (vector::const_iterator i = _servers.begin(); i != _servers.end(); ++i) { - f << "server " << (*i)->as_metadata () << "\n"; + for (vector::const_iterator i = _servers.begin(); i != _servers.end(); ++i) { + i->as_xml (root->add_child ("Server")); } - f << "tms_ip " << _tms_ip << "\n"; - f << "tms_path " << _tms_path << "\n"; - f << "tms_user " << _tms_user << "\n"; - f << "tms_password " << _tms_password << "\n"; + root->add_child("TMSIP")->add_child_text (_tms_ip); + root->add_child("TMSPath")->add_child_text (_tms_path); + root->add_child("TMSUser")->add_child_text (_tms_user); + root->add_child("TMSPassword")->add_child_text (_tms_password); if (_sound_processor) { - f << "sound_processor " << _sound_processor->id () << "\n"; + root->add_child("SoundProcessor")->add_child_text (_sound_processor->id ()); } if (_language) { - f << "language " << _language.get() << "\n"; + root->add_child("Language")->add_child_text (_language.get()); } - if (_default_format) { - f << "default_format " << _default_format->as_metadata() << "\n"; + if (_default_container) { + root->add_child("DefaultContainer")->add_child_text (_default_container->id ()); } if (_default_dcp_content_type) { - f << "default_dcp_content_type " << _default_dcp_content_type->dci_name() << "\n"; + root->add_child("DefaultDCPContentType")->add_child_text (_default_dcp_content_type->dci_name ()); + } + root->add_child("DCPMetadataIssuer")->add_child_text (_dcp_metadata.issuer); + root->add_child("DCPMetadataCreator")->add_child_text (_dcp_metadata.creator); + + _default_dci_metadata.as_xml (root->add_child ("DCIMetadata")); + + root->add_child("DefaultStillLength")->add_child_text (lexical_cast (_default_still_length)); + root->add_child("DefaultJ2KBandwidth")->add_child_text (lexical_cast (_default_j2k_bandwidth)); + + for (vector::const_iterator i = _colour_conversions.begin(); i != _colour_conversions.end(); ++i) { + i->as_xml (root->add_child ("ColourConversion")); } - f << "dcp_metadata_issuer " << _dcp_metadata.issuer << "\n"; - f << "dcp_metadata_creator " << _dcp_metadata.creator << "\n"; - f << "dcp_metadata_issue_date " << _dcp_metadata.issue_date << "\n"; - _default_dci_metadata.write (f); + for (list >::const_iterator i = _cinemas.begin(); i != _cinemas.end(); ++i) { + (*i)->as_xml (root->add_child ("Cinema")); + } + + root->add_child("MailServer")->add_child_text (_mail_server); + root->add_child("KDMFrom")->add_child_text (_kdm_from); + root->add_child("KDMEmail")->add_child_text (_kdm_email); + + doc.write_to_file_formatted (file(false).string ()); } -string -Config::default_directory_or (string a) const +boost::filesystem::path +Config::default_directory_or (boost::filesystem::path a) const { if (_default_directory.empty() || !boost::filesystem::exists (_default_directory)) { return a;