X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;h=ace371ba7923de6988ba89e9f5fcb891e4503660;hp=e49b7f78e7ed026cf14beb3bd8d96b0f311cb121;hb=dacf46c8aa5b399a7d51c9d0808869af9b73791c;hpb=04f8ba59d17e726570b4c1f361f10c7548fbe5c2 diff --git a/src/lib/film.cc b/src/lib/film.cc index e49b7f78e..ace371ba7 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -29,10 +29,10 @@ #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" +#include "constants.h" #include "cross.h" #include "dcp_content.h" #include "dcp_content_type.h" @@ -57,7 +57,6 @@ #include "text_content.h" #include "transcode_job.h" #include "upload_job.h" -#include "util.h" #include "video_content.h" #include "version.h" #include @@ -157,7 +156,7 @@ Film::Film (optional dir) : _playlist (new Playlist) , _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 ()) @@ -167,6 +166,7 @@ Film::Film (optional dir) , _three_d (false) , _sequence (true) , _interop (Config::instance()->default_interop ()) + , _limit_to_smpte_bv20(false) , _audio_processor (0) , _reel_type (ReelType::SINGLE) , _reel_length (2000000000) @@ -175,8 +175,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) @@ -268,6 +270,11 @@ Film::video_identifier () const s += "_I"; } else { s += "_S"; + if (_limit_to_smpte_bv20) { + s += "_L20"; + } else { + s += "_L21"; + } } if (_three_d) { @@ -352,6 +359,7 @@ Film::subtitle_analysis_path (shared_ptr content) const Digester digester; digester.add (content->digest()); + digester.add(_interop ? "1" : "0"); if (!content->text.empty()) { auto tc = content->text.front(); @@ -414,6 +422,7 @@ Film::metadata (bool with_content_paths) const root->add_child("ThreeD")->add_child_text (_three_d ? "1" : "0"); root->add_child("Sequence")->add_child_text (_sequence ? "1" : "0"); root->add_child("Interop")->add_child_text (_interop ? "1" : "0"); + root->add_child("LimitToSMPTEBv20")->add_child_text(_limit_to_smpte_bv20 ? "1" : "0"); root->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0"); root->add_child("Key")->add_child_text (_key.hex ()); root->add_child("ContextID")->add_child_text (_context_id); @@ -535,6 +544,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"); @@ -582,6 +593,7 @@ Film::read_metadata (optional path) _three_d = f.bool_child ("ThreeD"); _interop = f.bool_child ("Interop"); + _limit_to_smpte_bv20 = f.optional_bool_child("LimitToSMPTEBv20").get_value_or(false); _key = dcp::Key (f.string_child ("Key")); _context_id = f.optional_string_child("ContextID").get_value_or (dcp::make_uuid ()); @@ -629,7 +641,7 @@ Film::read_metadata (optional path) _sign_language_video_language = dcp::LanguageTag(*sign_language_video_language); } - _version_number = f.optional_number_child("VersionNumber").get_value_or(0); + _version_number = f.optional_number_child("VersionNumber").get_value_or(1); auto status = f.optional_string_child("Status"); if (status) { @@ -802,10 +814,15 @@ Film::subtitle_languages () const string Film::isdcf_name (bool if_created_now) const { - string d; + string isdcf_name; auto raw_name = name (); + auto to_upper = [](string s) { + transform(s.begin(), s.end(), s.begin(), ::toupper); + return s; + }; + /* Split the raw name up into words */ vector words; split (words, raw_name, is_any_of (" _-")); @@ -841,14 +858,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()) { @@ -860,59 +875,60 @@ 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(); } + auto content_list = content(); + /* XXX: this uses the first bit of content only */ /* Interior aspect ratio. The standard says we don't do this for trailers, for some strange reason */ if (dcp_content_type() && dcp_content_type()->libdcp_kind() != dcp::ContentKind::TRAILER) { - auto cl = content(); - auto first_video = std::find_if(cl.begin(), cl.end(), [](shared_ptr c) { return static_cast(c->video); }); - if (first_video != cl.end()) { + auto first_video = std::find_if(content_list.begin(), content_list.end(), [](shared_ptr c) { return static_cast(c->video); }); + if (first_video != content_list.end()) { 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); } } } @@ -930,7 +946,7 @@ Film::isdcf_name (bool if_created_now) const auto audio_language = _audio_language ? entry_for_language(*_audio_language) : "XX"; - d += "_" + to_upper (audio_language); + 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. @@ -938,7 +954,7 @@ Film::isdcf_name (bool if_created_now) const auto burnt_in = true; auto ccap = false; - for (auto i: content()) { + for (auto i: content_list) { for (auto j: i->text) { if (j->type() == TextType::OPEN_SUBTITLE && j->use() && !j->burn()) { burnt_in = false; @@ -957,22 +973,23 @@ Film::isdcf_name (bool if_created_now) const 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; } } @@ -982,46 +999,50 @@ 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); + if (find_if(content_list.begin(), content_list.end(), [](shared_ptr c) { return static_cast(c->atmos); }) != content_list.end()) { + isdcf_name += "-IAB"; + } + + 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; - for (auto i: content()) { + for (auto i: content_list) { auto dc = dynamic_pointer_cast(i); if (!dc) { continue; @@ -1039,12 +1060,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 */ @@ -1166,6 +1187,15 @@ Film::set_interop (bool i) _interop = i; } + +void +Film::set_limit_to_smpte_bv20(bool limit) +{ + FilmChangeSignaller ch(this, Property::LIMIT_TO_SMPTE_BV20); + _limit_to_smpte_bv20 = limit; +} + + void Film::set_audio_processor (AudioProcessor const * processor) { @@ -1622,37 +1652,18 @@ Film::active_area () const } -/** @param recipient KDM recipient certificate. - * @param trusted_devices Certificate thumbprints of other trusted devices (can be empty). - * @param cpl_file CPL filename. +/* @param cpl_file CPL filename. * @param from KDM from time expressed as a local time with an offset from UTC. * @param until KDM to time expressed as a local time with an offset from UTC. - * @param formulation KDM formulation to use. - * @param disable_forensic_marking_picture true to disable forensic marking of picture. - * @param disable_forensic_marking_audio if not set, don't disable forensic marking of audio. If set to 0, - * disable all forensic marking; if set above 0, disable forensic marking above that channel. */ -dcp::EncryptedKDM -Film::make_kdm ( - dcp::Certificate recipient, - vector trusted_devices, - boost::filesystem::path cpl_file, - dcp::LocalTime from, - dcp::LocalTime until, - dcp::Formulation formulation, - bool disable_forensic_marking_picture, - optional disable_forensic_marking_audio - ) const +dcp::DecryptedKDM +Film::make_kdm(boost::filesystem::path cpl_file, dcp::LocalTime from, dcp::LocalTime until) const { if (!_encrypted) { throw runtime_error (_("Cannot make a KDM as this project is not encrypted.")); } auto cpl = make_shared(cpl_file); - auto signer = Config::instance()->signer_chain(); - if (!signer->valid ()) { - throw InvalidSignerError (); - } /* Find keys that have been added to imported, encrypted DCP content */ list imported_keys; @@ -1691,7 +1702,7 @@ Film::make_kdm ( return dcp::DecryptedKDM ( cpl->id(), keys, from, until, cpl->content_title_text(), cpl->content_title_text(), dcp::LocalTime().as_string() - ).encrypt (signer, recipient, trusted_devices, formulation, disable_forensic_marking_picture, disable_forensic_marking_audio); + ); } @@ -1718,9 +1729,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) { @@ -1754,7 +1765,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)); } } @@ -2071,34 +2082,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 @@ -2187,3 +2179,41 @@ Film::set_dirty (bool 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; +} +