X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;h=54267bc5686038d1006fd1c75ba62de41e641e3f;hb=8a8c977c12fc65f1f50ea05099387e0fc8840e7d;hp=0b717738d09bfacd7198b870003869123dd7edb7;hpb=fb2f4b49cf0d003491ec21460051c01187c211fe;p=dcpomatic.git diff --git a/src/lib/film.cc b/src/lib/film.cc index 0b717738d..54267bc56 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -18,88 +18,92 @@ */ + /** @file src/film.cc * @brief A representation of some audio, video and subtitle content, and details of * how they should be presented in a DCP. */ + #include "atmos_content.h" +#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 "cross.h" +#include "dcp_content.h" +#include "dcp_content_type.h" +#include "dcp_encoder.h" +#include "dcpomatic_log.h" +#include "digester.h" +#include "environment_info.h" +#include "examine_content_job.h" +#include "exceptions.h" +#include "ffmpeg_content.h" +#include "ffmpeg_subtitle_stream.h" +#include "file_log.h" #include "film.h" +#include "font.h" #include "job.h" -#include "util.h" #include "job_manager.h" -#include "dcp_encoder.h" -#include "transcode_job.h" -#include "upload_job.h" +#include "kdm_with_metadata.h" #include "null_log.h" -#include "file_log.h" -#include "dcpomatic_log.h" -#include "exceptions.h" -#include "examine_content_job.h" -#include "config.h" #include "playlist.h" -#include "dcp_content_type.h" #include "ratio.h" -#include "cross.h" -#include "environment_info.h" -#include "audio_processor.h" -#include "digester.h" -#include "compose.hpp" #include "screen.h" -#include "audio_content.h" -#include "video_content.h" #include "text_content.h" -#include "ffmpeg_content.h" -#include "dcp_content.h" -#include "kdm_with_metadata.h" -#include "cinema.h" -#include "change_signaller.h" -#include "check_content_change_job.h" -#include "ffmpeg_subtitle_stream.h" -#include "font.h" +#include "transcode_job.h" +#include "upload_job.h" +#include "util.h" +#include "video_content.h" +#include "version.h" #include -#include #include -#include -#include +#include #include +#include #include -#include #include +#include +#include #include -#include #include +#include #include #include -#include -#include #include #include #include +#include #include +#include #include "i18n.h" -using std::string; -using std::pair; -using std::vector; -using std::setfill; -using std::min; -using std::max; -using std::make_pair; -using std::cout; -using std::list; -using std::set; -using std::runtime_error; -using std::copy; + using std::back_inserter; -using std::map; +using std::copy; +using std::cout; +using std::dynamic_pointer_cast; using std::exception; using std::find; +using std::list; +using std::make_pair; +using std::make_shared; +using std::map; +using std::max; +using std::min; +using std::pair; +using std::runtime_error; +using std::set; +using std::setfill; using std::shared_ptr; +using std::string; +using std::vector; using std::weak_ptr; -using std::make_shared; -using std::dynamic_pointer_cast; using boost::optional; using boost::is_any_of; #if BOOST_VERSION >= 106100 @@ -108,7 +112,9 @@ using namespace boost::placeholders; using dcp::raw_convert; using namespace dcpomatic; -string const Film::metadata_file = "metadata.xml"; + +static constexpr char metadata_file[] = "metadata.xml"; + /* 5 -> 6 * AudioMapping XML changed. @@ -141,6 +147,7 @@ string const Film::metadata_file = "metadata.xml"; */ int const Film::current_state_version = 38; + /** Construct a Film object in a given directory. * * @param dir Film directory. @@ -148,7 +155,7 @@ 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 ()) , _resolution (Resolution::TWO_K) @@ -176,6 +183,20 @@ Film::Film (optional dir) { set_isdcf_date_today (); + auto metadata = Config::instance()->default_metadata(); + if (metadata.find("chain") != metadata.end()) { + _chain = metadata["chain"]; + } + if (metadata.find("distributor") != metadata.end()) { + _distributor = metadata["distributor"]; + } + if (metadata.find("facility") != metadata.end()) { + _facility = metadata["facility"]; + } + if (metadata.find("studio") != metadata.end()) { + _studio = metadata["studio"]; + } + _playlist_change_connection = _playlist->Change.connect (bind (&Film::playlist_change, this, _1)); _playlist_order_changed_connection = _playlist->OrderChange.connect (bind (&Film::playlist_order_changed, this)); _playlist_content_change_connection = _playlist->ContentChange.connect (bind (&Film::playlist_content_change, this, _1, _2, _3, _4)); @@ -253,6 +274,10 @@ Film::video_identifier () const s += "_3D"; } + if (_reencode_j2k) { + s += "_R"; + } + return s; } @@ -352,77 +377,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 () @@ -437,6 +391,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"); @@ -451,6 +408,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"); @@ -481,6 +439,9 @@ Film::metadata (bool with_content_paths) const if (_release_territory) { root->add_child("ReleaseTerritory")->add_child_text(_release_territory->subtag()); } + if (_sign_language_video_language) { + root->add_child("SignLanguageVideoLanguage")->add_child_text(_sign_language_video_language->to_string()); + } root->add_child("VersionNumber")->add_child_text(raw_convert(_version_number)); root->add_child("Status")->add_child_text(dcp::status_to_string(_status)); if (_chain) { @@ -505,6 +466,9 @@ Film::metadata (bool with_content_paths) const } root->add_child("UserExplicitContainer")->add_child_text(_user_explicit_container ? "1" : "0"); root->add_child("UserExplicitResolution")->add_child_text(_user_explicit_resolution ? "1" : "0"); + if (_audio_language) { + root->add_child("AudioLanguage")->add_child_text(_audio_language->to_string()); + } _playlist->as_xml (root->add_child ("Playlist"), with_content_paths); return doc; @@ -518,12 +482,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 */ @@ -598,6 +562,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 @@ -659,6 +624,11 @@ Film::read_metadata (optional path) _release_territory = dcp::LanguageTag::RegionSubtag (*release_territory); } + auto sign_language_video_language = f.optional_string_child("SignLanguageVideoLanguage"); + if (sign_language_video_language) { + _sign_language_video_language = dcp::LanguageTag(*sign_language_video_language); + } + _version_number = f.optional_number_child("VersionNumber").get_value_or(0); auto status = f.optional_string_child("Status"); @@ -685,6 +655,48 @@ Film::read_metadata (optional path) _user_explicit_container = f.optional_bool_child("UserExplicitContainer").get_value_or(true); _user_explicit_resolution = f.optional_bool_child("UserExplicitResolution").get_value_or(true); + auto audio_language = f.optional_string_child("AudioLanguage"); + if (audio_language) { + _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); @@ -693,7 +705,7 @@ Film::read_metadata (optional path) set_backtrace_file (file ("backtrace.txt")); } - _dirty = false; + set_dirty (false); return notes; } @@ -760,23 +772,6 @@ Film::mapped_audio_channels () const } -vector -Film::audio_languages () const -{ - vector result; - for (auto i: content()) { - if (i->audio && !i->audio->mapping().mapped_output_channels().empty() && i->audio->language()) { - result.push_back (i->audio->language().get()); - } - } - - std::sort (result.begin(), result.end()); - auto last = std::unique (result.begin(), result.end()); - result.erase (last, result.end()); - return result; -} - - pair, vector> Film::subtitle_languages () const { @@ -911,23 +906,29 @@ Film::isdcf_name (bool if_created_now) const /* 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) { - Ratio const* content_ratio = nullptr; - for (auto i: content ()) { - if (i->video) { - /* Here's the first piece of video content */ - content_ratio = Ratio::nearest_from_ratio(i->video->scaled_size(frame_size()).ratio()); - break; + 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_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); } } + } - if (content_ratio && content_ratio != container()) { - /* This needs to be the numeric version of the ratio, and ::id() is close enough */ - d += "-" + content_ratio->id(); + 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"; + }; - auto audio_langs = audio_languages(); - auto audio_language = (audio_langs.empty() || !audio_langs.front().language()) ? "XX" : audio_langs.front().language()->subtag(); + auto audio_language = _audio_language ? entry_for_language(*_audio_language) : "XX"; d += "_" + to_upper (audio_language); @@ -949,7 +950,7 @@ 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 { @@ -1062,7 +1063,7 @@ void Film::set_directory (boost::filesystem::path d) { _directory = d; - _dirty = true; + set_dirty (true); } void @@ -1205,7 +1206,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) { @@ -1232,6 +1233,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 { @@ -1484,7 +1486,7 @@ Film::playlist_content_change (ChangeType type, weak_ptr c, int p, bool ContentChange (type, c, p, frequent); } - _dirty = true; + set_dirty (true); } void @@ -1503,7 +1505,7 @@ Film::playlist_change (ChangeType type) check_settings_consistency (); } - _dirty = true; + set_dirty (true); } /** Check for (and if necessary fix) impossible settings combinations, like @@ -1565,14 +1567,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) @@ -1724,9 +1718,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) { @@ -1864,7 +1858,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; @@ -2077,34 +2071,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 @@ -2151,3 +2126,45 @@ Film::set_two_d_version_of_three_d (bool t) _two_d_version_of_three_d = t; } + +void +Film::set_audio_language (optional language) +{ + FilmChangeSignaller ch (this, Property::AUDIO_LANGUAGE); + _audio_language = 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 +{ + return _audio_channels >= static_cast(dcp::Channel::SIGN_LANGUAGE); +} + + +void +Film::set_sign_language_video_language (optional lang) +{ + FilmChangeSignaller ch (this, Property::SIGN_LANGUAGE_VIDEO_LANGUAGE); + _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)); + } +} +