X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;h=29952d0f2e8f57fe6e10a7920af1fbce42940338;hp=486c1dd6a5ab91929bff0567338dd35a13162309;hb=d5e6fa029f1fb7b7dccd32dd2906a0858a876cae;hpb=3ff1586aad2fa5ba7e5fd95e178614aae12496e6 diff --git a/src/lib/film.cc b/src/lib/film.cc index 486c1dd6a..29952d0f2 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -29,7 +29,6 @@ #include "audio_content.h" #include "audio_processor.h" #include "change_signaller.h" -#include "check_content_change_job.h" #include "cinema.h" #include "compose.hpp" #include "config.h" @@ -59,6 +58,7 @@ #include "upload_job.h" #include "util.h" #include "video_content.h" +#include "version.h" #include #include #include @@ -73,12 +73,12 @@ #include #include #include -#include -#include #include #include #include +#include #include +#include #include "i18n.h" @@ -154,9 +154,9 @@ int const Film::current_state_version = 38; Film::Film (optional dir) : _playlist (new Playlist) - , _use_isdcf_name (true) + , _use_isdcf_name (Config::instance()->use_isdcf_name_by_default()) , _dcp_content_type (Config::instance()->default_dcp_content_type ()) - , _container (Config::instance()->default_container ()) + , _container(Ratio::from_id("185")) , _resolution (Resolution::TWO_K) , _encrypted (false) , _context_id (dcp::make_uuid ()) @@ -174,8 +174,10 @@ Film::Film (optional dir) , _user_explicit_container (false) , _user_explicit_resolution (false) , _name_language (dcp::LanguageTag("en-US")) + , _release_territory(Config::instance()->default_territory()) , _version_number (1) , _status (dcp::Status::FINAL) + , _audio_language(Config::instance()->default_audio_language()) , _state_version (current_state_version) , _dirty (false) , _tolerant (false) @@ -376,77 +378,6 @@ Film::subtitle_analysis_path (shared_ptr content) const } -/** Add suitable Jobs to the JobManager to create a DCP for this Film. - * @param gui true if this is being called from a GUI tool. - * @param check true to check the content in the project for changes before making the DCP. - */ -void -Film::make_dcp (bool gui, bool check) -{ - if (dcp_name().find ("/") != string::npos) { - throw BadSettingError (_("name"), _("Cannot contain slashes")); - } - - if (container() == nullptr) { - throw MissingSettingError (_("container")); - } - - if (content().empty()) { - throw runtime_error (_("You must add some content to the DCP before creating it")); - } - - if (length() == DCPTime()) { - throw runtime_error (_("The DCP is empty, perhaps because all the content has zero length.")); - } - - if (dcp_content_type() == nullptr) { - throw MissingSettingError (_("content type")); - } - - if (name().empty()) { - set_name ("DCP"); - } - - for (auto i: content ()) { - if (!i->paths_valid()) { - throw runtime_error (_("some of your content is missing")); - } - auto dcp = dynamic_pointer_cast(i); - if (dcp && dcp->needs_kdm()) { - throw runtime_error (_("Some of your content needs a KDM")); - } - if (dcp && dcp->needs_assets()) { - throw runtime_error (_("Some of your content needs an OV")); - } - } - - set_isdcf_date_today (); - - for (auto i: environment_info ()) { - LOG_GENERAL_NC (i); - } - - for (auto i: content ()) { - LOG_GENERAL ("Content: %1", i->technical_summary()); - } - LOG_GENERAL ("DCP video rate %1 fps", video_frame_rate()); - if (Config::instance()->only_servers_encode ()) { - LOG_GENERAL_NC ("0 threads: ONLY SERVERS SET TO ENCODE"); - } else { - LOG_GENERAL ("%1 threads", Config::instance()->master_encoding_threads()); - } - LOG_GENERAL ("J2K bandwidth %1", j2k_bandwidth()); - - auto tj = make_shared(shared_from_this()); - tj->set_encoder (make_shared(shared_from_this(), tj)); - if (check) { - auto cc = make_shared(shared_from_this(), tj, gui); - JobManager::instance()->add (cc); - } else { - JobManager::instance()->add (tj); - } -} - /** Start a job to send our DCP to the configured TMS */ void Film::send_dcp_to_tms () @@ -461,6 +392,9 @@ Film::metadata (bool with_content_paths) const auto root = doc->create_root_node ("Metadata"); root->add_child("Version")->add_child_text (raw_convert (current_state_version)); + auto last_write = root->add_child("LastWrittenBy"); + last_write->add_child_text (dcpomatic_version); + last_write->set_attribute("git", dcpomatic_git_commit); root->add_child("Name")->add_child_text (_name); root->add_child("UseISDCFName")->add_child_text (_use_isdcf_name ? "1" : "0"); @@ -475,6 +409,7 @@ Film::metadata (bool with_content_paths) const root->add_child("Resolution")->add_child_text (resolution_to_string (_resolution)); root->add_child("J2KBandwidth")->add_child_text (raw_convert (_j2k_bandwidth)); root->add_child("VideoFrameRate")->add_child_text (raw_convert (_video_frame_rate)); + root->add_child("AudioFrameRate")->add_child_text(raw_convert(_audio_frame_rate)); root->add_child("ISDCFDate")->add_child_text (boost::gregorian::to_iso_string (_isdcf_date)); root->add_child("AudioChannels")->add_child_text (raw_convert (_audio_channels)); root->add_child("ThreeD")->add_child_text (_three_d ? "1" : "0"); @@ -548,12 +483,12 @@ Film::write_metadata (boost::filesystem::path path) const /** Write state to our `metadata' file */ void -Film::write_metadata () const +Film::write_metadata () { DCPOMATIC_ASSERT (directory()); boost::filesystem::create_directories (directory().get()); metadata()->write_to_file_formatted(file(metadata_file).string()); - _dirty = false; + set_dirty (false); } /** Write a template from this film */ @@ -601,6 +536,8 @@ Film::read_metadata (optional path) } } + _last_written_by = f.optional_string_child("LastWrittenBy"); + _name = f.string_child ("Name"); if (_state_version >= 9) { _use_isdcf_name = f.bool_child ("UseISDCFName"); @@ -628,6 +565,7 @@ Film::read_metadata (optional path) _resolution = string_to_resolution (f.string_child ("Resolution")); _j2k_bandwidth = f.number_child ("J2KBandwidth"); _video_frame_rate = f.number_child ("VideoFrameRate"); + _audio_frame_rate = f.optional_number_child("AudioFrameRate").get_value_or(48000); _encrypted = f.bool_child ("Encrypted"); _audio_channels = f.number_child ("AudioChannels"); /* We used to allow odd numbers (and zero) channels, but it's just not worth @@ -725,6 +663,43 @@ Film::read_metadata (optional path) _audio_language = dcp::LanguageTag(*audio_language); } + /* Read the old ISDCFMetadata tag from 2.14.x metadata */ + auto isdcf = f.optional_node_child("ISDCFMetadata"); + if (isdcf) { + if (auto territory = isdcf->optional_string_child("Territory")) { + try { + _release_territory = dcp::LanguageTag::RegionSubtag(*territory); + } catch (...) { + /* Invalid region subtag; just ignore it */ + } + } + if (auto audio_language = isdcf->optional_string_child("AudioLanguage")) { + try { + _audio_language = dcp::LanguageTag(*audio_language); + } catch (...) { + /* Invalid language tag; just ignore it */ + } + } + if (auto content_version = isdcf->optional_string_child("ContentVersion")) { + _content_versions.push_back (*content_version); + } + if (auto rating = isdcf->optional_string_child("Rating")) { + _ratings.push_back (dcp::Rating("", *rating)); + } + if (auto mastered_luminance = isdcf->optional_number_child("MasteredLuminance")) { + if (*mastered_luminance > 0) { + _luminance = dcp::Luminance(*mastered_luminance, dcp::Luminance::Unit::FOOT_LAMBERT); + } + } + _studio = isdcf->optional_string_child("Studio"); + _facility = isdcf->optional_string_child("Facility"); + _temp_version = isdcf->optional_bool_child("TempVersion").get_value_or("false"); + _pre_release = isdcf->optional_bool_child("PreRelease").get_value_or("false"); + _red_band = isdcf->optional_bool_child("RedBand").get_value_or("false"); + _two_d_version_of_three_d = isdcf->optional_bool_child("TwoDVersionOfThreeD").get_value_or("false"); + _chain = isdcf->optional_string_child("Chain"); + } + list notes; _playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"), _state_version, notes); @@ -733,7 +708,7 @@ Film::read_metadata (optional path) set_backtrace_file (file ("backtrace.txt")); } - _dirty = false; + set_dirty (false); return notes; } @@ -830,7 +805,7 @@ Film::subtitle_languages () const string Film::isdcf_name (bool if_created_now) const { - string d; + string isdcf_name; auto raw_name = name (); @@ -869,14 +844,12 @@ Film::isdcf_name (bool if_created_now) const } } - if (fixed_name.length() > 14) { - fixed_name = fixed_name.substr (0, 14); - } + fixed_name = fixed_name.substr(0, 14); - d += fixed_name; + isdcf_name += fixed_name; if (dcp_content_type()) { - d += "_" + dcp_content_type()->isdcf_name(); + isdcf_name += "_" + dcp_content_type()->isdcf_name(); string version = "1"; if (_interop) { if (!_content_versions.empty()) { @@ -888,46 +861,46 @@ Film::isdcf_name (bool if_created_now) const } else { version = dcp::raw_convert(_version_number); } - d += "-" + version; + isdcf_name += "-" + version; } if (_temp_version) { - d += "-Temp"; + isdcf_name += "-Temp"; } if (_pre_release) { - d += "-Pre"; + isdcf_name += "-Pre"; } if (_red_band) { - d += "-RedBand"; + isdcf_name += "-RedBand"; } if (_chain && !_chain->empty()) { - d += "-" + *_chain; + isdcf_name += "-" + *_chain; } if (three_d ()) { - d += "-3D"; + isdcf_name += "-3D"; } if (_two_d_version_of_three_d) { - d += "-2D"; + isdcf_name += "-2D"; } if (_luminance) { auto fl = _luminance->value_in_foot_lamberts(); char buffer[64]; snprintf (buffer, sizeof(buffer), "%.1f", fl); - d += String::compose("-%1fl", buffer); + isdcf_name += String::compose("-%1fl", buffer); } if (video_frame_rate() != 24) { - d += "-" + raw_convert(video_frame_rate()); + isdcf_name += "-" + raw_convert(video_frame_rate()); } if (container()) { - d += "_" + container()->isdcf_name(); + isdcf_name += "_" + container()->isdcf_name(); } /* XXX: this uses the first bit of content only */ @@ -940,14 +913,25 @@ Film::isdcf_name (bool if_created_now) const auto first_ratio = lrintf((*first_video)->video->scaled_size(frame_size()).ratio() * 100); auto container_ratio = lrintf(container()->ratio() * 100); if (first_ratio != container_ratio) { - d += "-" + dcp::raw_convert(first_ratio); + isdcf_name += "-" + dcp::raw_convert(first_ratio); } } } - auto audio_language = (_audio_language && _audio_language->language()) ? _audio_language->language()->subtag() : "XX"; + auto entry_for_language = [](dcp::LanguageTag const& tag) { + /* Look up what we should be using for this tag in the DCNC name */ + for (auto const& dcnc: dcp::dcnc_tags()) { + if (tag.to_string() == dcnc.first) { + return dcnc.second; + } + } + /* Fallback to the language subtag, if there is one */ + return tag.language() ? tag.language()->subtag() : "XX"; + }; - d += "_" + to_upper (audio_language); + auto audio_language = _audio_language ? entry_for_language(*_audio_language) : "XX"; + + isdcf_name += "_" + to_upper (audio_language); /* I'm not clear on the precise details of the convention for CCAP labelling; for now I'm just appending -CCAP if we have any closed captions. @@ -967,29 +951,30 @@ Film::isdcf_name (bool if_created_now) const auto sub_langs = subtitle_languages(); if (sub_langs.first && sub_langs.first->language()) { - auto lang = sub_langs.first->language()->subtag(); + auto lang = entry_for_language(*sub_langs.first); if (burnt_in) { transform (lang.begin(), lang.end(), lang.begin(), ::tolower); } else { lang = to_upper (lang); } - d += "-" + lang; + isdcf_name += "-" + lang; if (ccap) { - d += "-CCAP"; + isdcf_name += "-CCAP"; } } else { /* No subtitles */ - d += "-XX"; + isdcf_name += "-XX"; } if (_release_territory) { auto territory = _release_territory->subtag(); - d += "_" + to_upper (territory); - if (_ratings.empty ()) { - d += "-NR"; - } else { - d += "-" + _ratings[0].label; + isdcf_name += "_" + to_upper (territory); + if (!_ratings.empty()) { + auto label = _ratings[0].label; + boost::erase_all(label, "+"); + boost::erase_all(label, "-"); + isdcf_name += "-" + label; } } @@ -999,42 +984,42 @@ Film::isdcf_name (bool if_created_now) const auto ch = audio_channel_types (mapped, audio_channels()); if (!ch.first && !ch.second) { - d += "_MOS"; + isdcf_name += "_MOS"; } else if (ch.first) { - d += String::compose("_%1%2", ch.first, ch.second); + isdcf_name += String::compose("_%1%2", ch.first, ch.second); } if (audio_channels() > static_cast(dcp::Channel::HI) && find(mapped.begin(), mapped.end(), static_cast(dcp::Channel::HI)) != mapped.end()) { - d += "-HI"; + isdcf_name += "-HI"; } if (audio_channels() > static_cast(dcp::Channel::VI) && find(mapped.begin(), mapped.end(), static_cast(dcp::Channel::VI)) != mapped.end()) { - d += "-VI"; + isdcf_name += "-VI"; } - d += "_" + resolution_to_string (_resolution); + isdcf_name += "_" + resolution_to_string (_resolution); if (_studio && _studio->length() >= 2) { - d += "_" + to_upper (_studio->substr(0, 4)); + isdcf_name += "_" + to_upper (_studio->substr(0, 4)); } if (if_created_now) { - d += "_" + boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ()); + isdcf_name += "_" + boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ()); } else { - d += "_" + boost::gregorian::to_iso_string (_isdcf_date); + isdcf_name += "_" + boost::gregorian::to_iso_string (_isdcf_date); } if (_facility && _facility->length() >= 3) { - d += "_" + to_upper(_facility->substr(0, 3)); + isdcf_name += "_" + to_upper(_facility->substr(0, 3)); } if (_interop) { - d += "_IOP"; + isdcf_name += "_IOP"; } else { - d += "_SMPTE"; + isdcf_name += "_SMPTE"; } if (three_d ()) { - d += "-3D"; + isdcf_name += "-3D"; } auto vf = false; @@ -1056,12 +1041,12 @@ Film::isdcf_name (bool if_created_now) const } if (vf) { - d += "_VF"; + isdcf_name += "_VF"; } else { - d += "_OV"; + isdcf_name += "_OV"; } - return d; + return isdcf_name; } /** @return name to give the DCP */ @@ -1080,7 +1065,7 @@ void Film::set_directory (boost::filesystem::path d) { _directory = d; - _dirty = true; + set_dirty (true); } void @@ -1223,7 +1208,7 @@ void Film::signal_change (ChangeType type, Property p) { if (type == ChangeType::DONE) { - _dirty = true; + set_dirty (true); if (p == Property::CONTENT) { if (!_user_explicit_video_frame_rate) { @@ -1250,6 +1235,7 @@ Film::set_isdcf_date_today () _isdcf_date = boost::gregorian::day_clock::local_day (); } + boost::filesystem::path Film::j2c_path (int reel, Frame frame, Eyes eyes, bool tmp) const { @@ -1502,7 +1488,7 @@ Film::playlist_content_change (ChangeType type, weak_ptr c, int p, bool ContentChange (type, c, p, frequent); } - _dirty = true; + set_dirty (true); } void @@ -1521,7 +1507,7 @@ Film::playlist_change (ChangeType type) check_settings_consistency (); } - _dirty = true; + set_dirty (true); } /** Check for (and if necessary fix) impossible settings combinations, like @@ -1583,14 +1569,6 @@ Film::playlist_order_changed () signal_change (ChangeType::DONE, Property::CONTENT_ORDER); } -int -Film::audio_frame_rate () const -{ - /* It seems that nobody makes 96kHz DCPs at the moment, so let's avoid them. - See #1436. - */ - return 48000; -} void Film::set_sequence (bool s) @@ -1742,9 +1720,9 @@ Film::should_be_enough_disk_space (double& required, double& available, bool& ca boost::filesystem::path test = internal_video_asset_dir() / "test"; boost::filesystem::path test2 = internal_video_asset_dir() / "test2"; can_hard_link = true; - auto f = fopen_boost (test, "w"); + dcp::File f(test, "w"); if (f) { - fclose (f); + f.close(); boost::system::error_code ec; boost::filesystem::create_hard_link (test, test2, ec); if (ec) { @@ -1778,7 +1756,7 @@ Film::audio_output_names () const vector n; for (int i = 0; i < audio_channels(); ++i) { - if (i != 8 && i != 9 && i != 15) { + if (Config::instance()->use_all_audio_channels() || (i != 8 && i != 9 && i != 15)) { n.push_back (NamedChannel(short_audio_channel_name(i), i)); } } @@ -1882,7 +1860,7 @@ void Film::use_template (string name) { _template_film.reset (new Film (optional())); - _template_film->read_metadata (Config::instance()->template_path (name)); + _template_film->read_metadata (Config::instance()->template_read_path(name)); _use_isdcf_name = _template_film->_use_isdcf_name; _dcp_content_type = _template_film->_dcp_content_type; _container = _template_film->_container; @@ -2095,34 +2073,15 @@ Film::info_file_handle (DCPTimePeriod period, bool read) const return std::make_shared(_info_file_mutex, info_file(period), read); } -InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read) +InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path path, bool read) : _lock (mutex) - , _file (file) + , _file (path, read ? "rb" : (boost::filesystem::exists(path) ? "r+b" : "wb")) { - if (read) { - _handle = fopen_boost (file, "rb"); - if (!_handle) { - throw OpenFileError (file, errno, OpenFileError::READ); - } - } else { - auto const exists = boost::filesystem::exists (file); - if (exists) { - _handle = fopen_boost (file, "r+b"); - } else { - _handle = fopen_boost (file, "wb"); - } - - if (!_handle) { - throw OpenFileError (file, errno, exists ? OpenFileError::READ_WRITE : OpenFileError::WRITE); - } + if (!_file) { + throw OpenFileError (path, errno, read ? OpenFileError::READ : (boost::filesystem::exists(path) ? OpenFileError::READ_WRITE : OpenFileError::WRITE)); } } -InfoFileHandle::~InfoFileHandle () -{ - fclose (_handle); -} - /** Add FFOC and LFOC markers to a list if they are not already there */ void @@ -2178,6 +2137,14 @@ Film::set_audio_language (optional language) } +void +Film::set_audio_frame_rate (int rate) +{ + FilmChangeSignaller ch (this, Property::AUDIO_FRAME_RATE); + _audio_frame_rate = rate; +} + + bool Film::has_sign_language_video_channel () const { @@ -2192,3 +2159,52 @@ Film::set_sign_language_video_language (optional lang) _sign_language_video_language = lang; } + +void +Film::set_dirty (bool dirty) +{ + auto const changed = dirty != _dirty; + _dirty = dirty; + if (changed) { + emit (boost::bind(boost::ref(DirtyChange), _dirty)); + } +} + + +/** @return true if the metadata was (probably) last written by a version earlier + * than the given one; false if it definitely was not. + */ +bool +Film::last_written_by_earlier_than(int major, int minor, int micro) const +{ + if (!_last_written_by) { + return true; + } + + vector parts; + boost::split(parts, *_last_written_by, boost::is_any_of(".")); + + if (parts.size() != 3) { + /* Not sure what's going on, so let's say it was written by an old version */ + return true; + } + + if (boost::ends_with(parts[2], "pre")) { + parts[2] = parts[2].substr(0, parts[2].length() - 3); + } + + int our_major = dcp::raw_convert(parts[0]); + int our_minor = dcp::raw_convert(parts[1]); + int our_micro = dcp::raw_convert(parts[2]); + + if (our_major != major) { + return our_major < major; + } + + if (our_minor != minor) { + return our_minor < minor; + } + + return our_micro < micro; +} +