X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;h=44c49220b94f6836935d132341dc7ff7d23aabe8;hb=ea554f39cec595666a3d4552235ccca4e60305a5;hp=46074e2ada19632b09e84c30dd2fe822d5f48930;hpb=6a9cdf1f5ab9f7f7ecea865b2930bb4c385609c4;p=dcpomatic.git diff --git a/src/lib/film.cc b/src/lib/film.cc index 46074e2ad..44c49220b 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -155,7 +155,6 @@ Film::Film (optional dir) , _encrypted (false) , _context_id (dcp::make_uuid ()) , _j2k_bandwidth (Config::instance()->default_j2k_bandwidth ()) - , _isdcf_metadata (Config::instance()->default_isdcf_metadata ()) , _video_frame_rate (24) , _audio_channels (Config::instance()->default_dcp_audio_channels ()) , _three_d (false) @@ -169,10 +168,8 @@ Film::Film (optional dir) , _user_explicit_container (false) , _user_explicit_resolution (false) , _name_language (dcp::LanguageTag("en-US")) - , _audio_language (dcp::LanguageTag("en-US")) , _version_number (1) , _status (dcp::Status::FINAL) - , _luminance (dcp::Luminance(4.5, dcp::Luminance::Unit::FOOT_LAMBERT)) , _state_version (current_state_version) , _dirty (false) , _tolerant (false) @@ -287,13 +284,13 @@ Film::audio_analysis_path (shared_ptr playlist) const auto p = dir ("analysis"); Digester digester; - for (auto i: playlist->content ()) { + for (auto i: playlist->content()) { if (!i->audio) { continue; } - digester.add (i->digest ()); - digester.add (i->audio->mapping().digest ()); + digester.add (i->digest()); + digester.add (i->audio->mapping().digest()); if (playlist->content().size() != 1) { /* Analyses should be considered equal regardless of gain if they were made from just one piece of content. This @@ -301,7 +298,14 @@ Film::audio_analysis_path (shared_ptr playlist) const analysis at the plotting stage rather than having to recompute it. */ - digester.add (i->audio->gain ()); + digester.add (i->audio->gain()); + + /* Likewise we only care about position if we're looking at a + * whole-project view. + */ + digester.add (i->position().get()); + digester.add (i->trim_start().get()); + digester.add (i->trim_end().get()); } } @@ -446,7 +450,6 @@ 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)); - _isdcf_metadata.as_xml (root->add_child ("ISDCFMetadata")); root->add_child("VideoFrameRate")->add_child_text (raw_convert (_video_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)); @@ -475,7 +478,6 @@ Film::metadata (bool with_content_paths) const root->add_child("ContentVersion")->add_child_text(i); } root->add_child("NameLanguage")->add_child_text(_name_language.to_string()); - root->add_child("AudioLanguage")->add_child_text(_audio_language.to_string()); if (_release_territory) { root->add_child("ReleaseTerritory")->add_child_text(_release_territory->subtag()); } @@ -490,14 +492,21 @@ Film::metadata (bool with_content_paths) const if (_facility) { root->add_child("Facility")->add_child_text(*_facility); } + if (_studio) { + root->add_child("Studio")->add_child_text(*_studio); + } + root->add_child("TempVersion")->add_child_text(_temp_version ? "1" : "0"); + root->add_child("PreRelease")->add_child_text(_pre_release ? "1" : "0"); + root->add_child("RedBand")->add_child_text(_red_band ? "1" : "0"); + root->add_child("TwoDVersionOfThreeD")->add_child_text(_two_d_version_of_three_d ? "1" : "0"); if (_luminance) { root->add_child("LuminanceValue")->add_child_text(raw_convert(_luminance->value())); root->add_child("LuminanceUnit")->add_child_text(dcp::Luminance::unit_to_string(_luminance->unit())); } root->add_child("UserExplicitContainer")->add_child_text(_user_explicit_container ? "1" : "0"); root->add_child("UserExplicitResolution")->add_child_text(_user_explicit_resolution ? "1" : "0"); - for (auto i: _subtitle_languages) { - root->add_child("SubtitleLanguage")->add_child_text(i.to_string()); + if (_audio_language) { + root->add_child("AudioLanguage")->add_child_text(_audio_language->to_string()); } _playlist->as_xml (root->add_child ("Playlist"), with_content_paths); @@ -568,11 +577,9 @@ Film::read_metadata (optional path) _name = f.string_child ("Name"); if (_state_version >= 9) { _use_isdcf_name = f.bool_child ("UseISDCFName"); - _isdcf_metadata = ISDCFMetadata (f.node_child ("ISDCFMetadata")); _isdcf_date = boost::gregorian::from_undelimited_string (f.string_child ("ISDCFDate")); } else { _use_isdcf_name = f.bool_child ("UseDCIName"); - _isdcf_metadata = ISDCFMetadata (f.node_child ("DCIMetadata")); _isdcf_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate")); } @@ -650,10 +657,6 @@ Film::read_metadata (optional path) if (name_language) { _name_language = dcp::LanguageTag (*name_language); } - auto audio_language = f.optional_string_child("AudioLanguage"); - if (audio_language) { - _audio_language = dcp::LanguageTag (*audio_language); - } auto release_territory = f.optional_string_child("ReleaseTerritory"); if (release_territory) { _release_territory = dcp::LanguageTag::RegionSubtag (*release_territory); @@ -669,6 +672,11 @@ Film::read_metadata (optional path) _chain = f.optional_string_child("Chain"); _distributor = f.optional_string_child("Distributor"); _facility = f.optional_string_child("Facility"); + _studio = f.optional_string_child("Studio"); + _temp_version = f.optional_bool_child("TempVersion").get_value_or(false); + _pre_release = f.optional_bool_child("PreRelease").get_value_or(false); + _red_band = f.optional_bool_child("RedBand").get_value_or(false); + _two_d_version_of_three_d = f.optional_bool_child("TwoDVersionOfThreeD").get_value_or(false); auto value = f.optional_number_child("LuminanceValue"); auto unit = f.optional_string_child("LuminanceUnit"); @@ -680,8 +688,9 @@ 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); - for (auto i: f.node_children("SubtitleLanguage")) { - _subtitle_languages.push_back (dcp::LanguageTag(i->content())); + auto audio_language = f.optional_string_child("AudioLanguage"); + if (audio_language) { + _audio_language = dcp::LanguageTag(*audio_language); } list notes; @@ -692,41 +701,6 @@ Film::read_metadata (optional path) set_backtrace_file (file ("backtrace.txt")); } - /* Around 2.15.108 we removed subtitle language state from the text content and the ISDCF - * metadata and put it into the Film instead. If we've loaded an old Film let's try and fish - * out the settings from where they were so that they don't get lost. - */ - - optional found_language; - - for (auto i: f.node_child("Playlist")->node_children("Content")) { - auto text = i->optional_node_child("Text"); - if (text && text->optional_string_child("Language") && !found_language) { - try { - found_language = dcp::LanguageTag(text->string_child("Language")); - } catch (...) {} - } - } - - if (_state_version >= 9) { - auto isdcf_language = f.node_child("ISDCFMetadata")->optional_string_child("SubtitleLanguage"); - if (isdcf_language && !found_language) { - try { - found_language = dcp::LanguageTag(*isdcf_language); - } catch (...) { - try { - found_language = dcp::LanguageTag(boost::algorithm::to_lower_copy(*isdcf_language)); - } catch (...) { - - } - } - } - } - - if (found_language) { - _subtitle_languages.push_back (*found_language); - } - _dirty = false; return notes; } @@ -793,6 +767,33 @@ Film::mapped_audio_channels () const return mapped; } + +pair, vector> +Film::subtitle_languages () const +{ + pair, vector> result; + for (auto i: content()) { + for (auto j: i->text) { + if (j->use() && j->type() == TextType::OPEN_SUBTITLE && j->language()) { + if (j->language_is_additional()) { + result.second.push_back (j->language().get()); + } else { + result.first = j->language().get(); + } + } + } + if (i->video && i->video->burnt_subtitle_language()) { + result.first = i->video->burnt_subtitle_language(); + } + } + + std::sort (result.second.begin(), result.second.end()); + auto last = std::unique (result.second.begin(), result.second.end()); + result.second.erase (last, result.second.end()); + return result; +} + + /** @return a ISDCF-compliant name for a DCP of this film */ string Film::isdcf_name (bool if_created_now) const @@ -844,37 +845,49 @@ Film::isdcf_name (bool if_created_now) const if (dcp_content_type()) { d += "_" + dcp_content_type()->isdcf_name(); - d += "-" + raw_convert(isdcf_metadata().content_version); + string version = "1"; + if (_interop) { + if (!_content_versions.empty()) { + auto cv = _content_versions[0]; + if (!cv.empty() && std::all_of(cv.begin(), cv.end(), isdigit)) { + version = cv; + } + } + } else { + version = dcp::raw_convert(_version_number); + } + d += "-" + version; } - auto const dm = isdcf_metadata (); - - if (dm.temp_version) { + if (_temp_version) { d += "-Temp"; } - if (dm.pre_release) { + if (_pre_release) { d += "-Pre"; } - if (dm.red_band) { + if (_red_band) { d += "-RedBand"; } - if (!dm.chain.empty ()) { - d += "-" + dm.chain; + if (_chain && !_chain->empty()) { + d += "-" + *_chain; } if (three_d ()) { d += "-3D"; } - if (dm.two_d_version_of_three_d) { + if (_two_d_version_of_three_d) { d += "-2D"; } - if (!dm.mastered_luminance.empty ()) { - d += "-" + dm.mastered_luminance; + if (_luminance) { + auto fl = _luminance->value_in_foot_lamberts(); + char buffer[64]; + snprintf (buffer, sizeof(buffer), "%.1f", fl); + d += String::compose("-%1fl", buffer); } if (video_frame_rate() != 24) { @@ -889,24 +902,20 @@ 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 const audio_language = dm.audio_language.empty() ? "XX" : dm.audio_language; + auto audio_language = (_audio_language && _audio_language->language()) ? _audio_language->language()->subtag() : "XX"; - d += "_" + audio_language; + d += "_" + 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. @@ -924,12 +933,13 @@ Film::isdcf_name (bool if_created_now) const } } - if (!_subtitle_languages.empty()) { - auto lang = _subtitle_languages.front().language().get_value_or("en").subtag(); + auto sub_langs = subtitle_languages(); + if (sub_langs.first && sub_langs.first->language()) { + auto lang = sub_langs.first->language()->subtag(); if (burnt_in) { transform (lang.begin(), lang.end(), lang.begin(), ::tolower); } else { - transform (lang.begin(), lang.end(), lang.begin(), ::toupper); + lang = to_upper (lang); } d += "-" + lang; @@ -941,12 +951,13 @@ Film::isdcf_name (bool if_created_now) const d += "-XX"; } - if (!dm.territory.empty ()) { - d += "_" + dm.territory; - if (dm.rating.empty ()) { + if (_release_territory) { + auto territory = _release_territory->subtag(); + d += "_" + to_upper (territory); + if (_ratings.empty ()) { d += "-NR"; } else { - d += "-" + dm.rating; + d += "-" + _ratings[0].label; } } @@ -970,8 +981,8 @@ Film::isdcf_name (bool if_created_now) const d += "_" + resolution_to_string (_resolution); - if (!dm.studio.empty ()) { - d += "_" + dm.studio; + if (_studio && _studio->length() >= 2) { + d += "_" + to_upper (_studio->substr(0, 4)); } if (if_created_now) { @@ -980,8 +991,8 @@ Film::isdcf_name (bool if_created_now) const d += "_" + boost::gregorian::to_iso_string (_isdcf_date); } - if (!dm.facility.empty ()) { - d += "_" + dm.facility; + if (_facility && _facility->length() >= 3) { + d += "_" + to_upper(_facility->substr(0, 3)); } if (_interop) { @@ -1101,13 +1112,6 @@ Film::set_j2k_bandwidth (int b) _j2k_bandwidth = b; } -void -Film::set_isdcf_metadata (ISDCFMetadata m) -{ - FilmChangeSignaller ch (this, Property::ISDCF_METADATA); - _isdcf_metadata = m; -} - /** @param f New frame rate. * @param user_explicit true if this comes from a direct user instruction, false if it is from * DCP-o-matic being helpful. @@ -1135,9 +1139,8 @@ Film::set_three_d (bool t) FilmChangeSignaller ch (this, Property::THREE_D); _three_d = t; - if (_three_d && _isdcf_metadata.two_d_version_of_three_d) { - FilmChangeSignaller ch (this, Property::ISDCF_METADATA); - _isdcf_metadata.two_d_version_of_three_d = false; + if (_three_d && _two_d_version_of_three_d) { + set_two_d_version_of_three_d (false); } } @@ -1657,7 +1660,7 @@ Film::make_kdm ( map, dcp::Key> keys; for (auto i: cpl->reel_file_assets()) { - if (!i->key_id()) { + if (!i->encrypted()) { continue; } @@ -1862,7 +1865,6 @@ Film::use_template (string name) _audio_processor = _template_film->_audio_processor; _reel_type = _template_film->_reel_type; _reel_length = _template_film->_reel_length; - _isdcf_metadata = _template_film->_isdcf_metadata; } pair @@ -1981,14 +1983,6 @@ Film::set_name_language (dcp::LanguageTag lang) } -void -Film::set_audio_language (dcp::LanguageTag lang) -{ - FilmChangeSignaller ch (this, Property::AUDIO_LANGUAGE); - _audio_language = lang; -} - - void Film::set_release_territory (optional region) { @@ -2038,33 +2032,18 @@ Film::set_luminance (optional l) void -Film::set_subtitle_language (dcp::LanguageTag language) -{ - set_subtitle_languages ({language}); -} - - -void -Film::unset_subtitle_language () -{ - FilmChangeSignaller ch (this, Property::SUBTITLE_LANGUAGES); - _subtitle_languages.clear(); -} - - -void -Film::set_subtitle_languages (vector languages) +Film::set_facility (optional f) { - FilmChangeSignaller ch (this, Property::SUBTITLE_LANGUAGES); - _subtitle_languages = languages; + FilmChangeSignaller ch (this, Property::FACILITY); + _facility = f; } void -Film::set_facility (optional f) +Film::set_studio (optional s) { - FilmChangeSignaller ch (this, Property::FACILITY); - _facility = f; + FilmChangeSignaller ch (this, Property::STUDIO); + _studio = s; } @@ -2125,3 +2104,44 @@ Film::add_ffoc_lfoc (Markers& markers) const markers[dcp::Marker::LFOC] = length() - DCPTime::from_frames(1, video_frame_rate()); } } + + +void +Film::set_temp_version (bool t) +{ + FilmChangeSignaller ch (this, Property::TEMP_VERSION); + _temp_version = t; +} + + +void +Film::set_pre_release (bool p) +{ + FilmChangeSignaller ch (this, Property::PRE_RELEASE); + _pre_release = p; +} + + +void +Film::set_red_band (bool r) +{ + FilmChangeSignaller ch (this, Property::RED_BAND); + _red_band = r; +} + + +void +Film::set_two_d_version_of_three_d (bool t) +{ + FilmChangeSignaller ch (this, Property::TWO_D_VERSION_OF_THREE_D); + _two_d_version_of_three_d = t; +} + + +void +Film::set_audio_language (optional language) +{ + FilmChangeSignaller ch (this, Property::AUDIO_LANGUAGE); + _audio_language = language; +} +