diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-04-21 23:57:25 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-04-21 23:57:25 +0200 |
| commit | f644c272a6a6384f6bfc6ca16ada6208057402a8 (patch) | |
| tree | 6b3341998b91b6c5dcd904b0bf37f60d8051453f /src/lib | |
| parent | fa5f3a8bf77209da27acc33cf144e2e4500a2600 (diff) | |
| parent | 4873cbc567d2c97c6587ab624e4c53abcd23cf23 (diff) | |
Add option to set project properties from a DCP loaded as content (#1688).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/copy_dcp_details_to_film.cc | 73 | ||||
| -rw-r--r-- | src/lib/copy_dcp_details_to_film.h | 26 | ||||
| -rw-r--r-- | src/lib/dcp_content.cc | 53 | ||||
| -rw-r--r-- | src/lib/dcp_content.h | 23 | ||||
| -rw-r--r-- | src/lib/dcp_content_type.cc | 24 | ||||
| -rw-r--r-- | src/lib/dcp_content_type.h | 1 | ||||
| -rw-r--r-- | src/lib/dcp_examiner.cc | 12 | ||||
| -rw-r--r-- | src/lib/dcp_examiner.h | 18 | ||||
| -rw-r--r-- | src/lib/film.cc | 9 | ||||
| -rw-r--r-- | src/lib/film.h | 1 | ||||
| -rw-r--r-- | src/lib/util.h | 11 | ||||
| -rw-r--r-- | src/lib/wscript | 1 |
12 files changed, 237 insertions, 15 deletions
diff --git a/src/lib/copy_dcp_details_to_film.cc b/src/lib/copy_dcp_details_to_film.cc new file mode 100644 index 000000000..a009735fb --- /dev/null +++ b/src/lib/copy_dcp_details_to_film.cc @@ -0,0 +1,73 @@ +/* + Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "copy_dcp_details_to_film.h" +#include "dcp_content.h" +#include "film.h" +#include "types.h" +#include "video_content.h" +#include "audio_content.h" +#include "ratio.h" +#include "dcp_content_type.h" +#include <boost/shared_ptr.hpp> +#include <map> + +using std::map; +using std::string; +using boost::shared_ptr; + +void +copy_dcp_details_to_film (shared_ptr<const DCPContent> dcp, shared_ptr<Film> film) +{ + string name = dcp->name (); + name = name.substr (0, name.find("_")); + film->set_name (name); + film->set_use_isdcf_name (true); + if (dcp->content_kind()) { + film->set_dcp_content_type (DCPContentType::from_libdcp_kind(dcp->content_kind().get())); + } + film->set_encrypted (dcp->encrypted()); + film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT); + film->set_interop (dcp->standard() == dcp::INTEROP); + film->set_three_d (dcp->three_d()); + + if (dcp->video) { + film->set_container (Ratio::nearest_from_ratio(dcp->video->size().ratio())); + film->set_resolution (dcp->resolution()); + DCPOMATIC_ASSERT (dcp->video_frame_rate()); + film->set_video_frame_rate (*dcp->video_frame_rate()); + } + + if (dcp->audio) { + film->set_audio_channels (dcp->audio->stream()->channels()); + } + + map<dcp::Marker, dcpomatic::ContentTime> dcp_markers; + map<dcp::Marker, dcpomatic::DCPTime> film_markers; + film->clear_markers (); + for (map<dcp::Marker, dcpomatic::ContentTime>::const_iterator i = dcp_markers.begin(); i != dcp_markers.end(); ++i) { + film->set_marker (i->first, dcpomatic::DCPTime(i->second.get())); + } + + film->set_ratings (dcp->ratings()); + film->set_content_version (dcp->content_version()); +} + + diff --git a/src/lib/copy_dcp_details_to_film.h b/src/lib/copy_dcp_details_to_film.h new file mode 100644 index 000000000..38eb7fcc9 --- /dev/null +++ b/src/lib/copy_dcp_details_to_film.h @@ -0,0 +1,26 @@ +/* + Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include <boost/shared_ptr.hpp> + +class DCPContent; +class Film; + +extern void copy_dcp_details_to_film (boost::shared_ptr<const DCPContent> dcp, boost::shared_ptr<Film> film); diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 52ac6132c..4280ad13a 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -49,6 +49,7 @@ using std::distance; using std::pair; using std::vector; using std::list; +using std::map; using boost::shared_ptr; using boost::scoped_ptr; using boost::optional; @@ -146,6 +147,16 @@ DCPContent::DCPContent (cxml::ConstNodePtr node, int version) BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("ReelLength")) { _reel_lengths.push_back (raw_convert<int64_t> (i->content ())); } + + BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("Marker")) { + _markers[dcp::marker_from_string(i->string_attribute("type"))] = ContentTime(raw_convert<int64_t>(i->content())); + } + + BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("Rating")) { + _ratings.push_back (dcp::Rating(i)); + } + + _content_version = node->optional_string_child("ContentVersion").get_value_or(""); } void @@ -240,6 +251,12 @@ DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) _content_kind = examiner->content_kind (); _cpl = examiner->cpl (); _reel_lengths = examiner->reel_lengths (); + map<dcp::Marker, dcp::Time> markers = examiner->markers(); + for (map<dcp::Marker, dcp::Time>::const_iterator i = markers.begin(); i != markers.end(); ++i) { + _markers[i->first] = ContentTime(i->second.as_editable_units(DCPTime::HZ)); + } + _ratings = examiner->ratings (); + _content_version = examiner->content_version (); } if (old_texts == texts) { @@ -339,6 +356,19 @@ DCPContent::as_xml (xmlpp::Node* node, bool with_paths) const BOOST_FOREACH (int64_t i, _reel_lengths) { node->add_child("ReelLength")->add_child_text (raw_convert<string> (i)); } + + for (map<dcp::Marker, ContentTime>::const_iterator i = _markers.begin(); i != _markers.end(); ++i) { + xmlpp::Element* marker = node->add_child("Marker"); + marker->set_attribute("type", dcp::marker_to_string(i->first)); + marker->add_child_text(raw_convert<string>(i->second.get())); + } + + BOOST_FOREACH (dcp::Rating i, _ratings) { + xmlpp::Element* rating = node->add_child("Rating"); + i.as_xml (rating); + } + + node->add_child("ContentVersion")->add_child_text (_content_version); } DCPTime @@ -591,13 +621,8 @@ DCPContent::can_reference_video (shared_ptr<const Film> film, string& why_not) c return false; } - Resolution video_res = RESOLUTION_2K; - if (video->size().width > 2048 || video->size().height > 1080) { - video_res = RESOLUTION_4K; - } - - if (film->resolution() != video_res) { - if (video_res == RESOLUTION_4K) { + if (film->resolution() != resolution()) { + if (resolution() == RESOLUTION_4K) { /// TRANSLATORS: this string will follow "Cannot reference this DCP: " why_not = _("it is 4K and the film is 2K."); } else { @@ -723,3 +748,15 @@ DCPContent::kdm_timing_window_valid () const dcp::LocalTime now; return _kdm->not_valid_before() < now && now < _kdm->not_valid_after(); } + + +Resolution +DCPContent::resolution () const +{ + if (video->size().width > 2048 || video->size().height > 1080) { + return RESOLUTION_4K; + } + + return RESOLUTION_2K; +} + diff --git a/src/lib/dcp_content.h b/src/lib/dcp_content.h index 65bed29bc..6d707670f 100644 --- a/src/lib/dcp_content.h +++ b/src/lib/dcp_content.h @@ -144,8 +144,28 @@ public: return _content_kind; } + dcp::Standard standard () const { + boost::mutex::scoped_lock lm (_mutex); + DCPOMATIC_ASSERT (_standard); + return _standard.get (); + } + + std::map<dcp::Marker, dcpomatic::ContentTime> markers () const { + return _markers; + } + bool kdm_timing_window_valid () const; + Resolution resolution () const; + + std::vector<dcp::Rating> ratings () const { + return _ratings; + } + + std::string content_version () const { + return _content_version; + } + private: friend class reels_test5; @@ -192,6 +212,9 @@ private: boost::optional<std::string> _cpl; /** List of the lengths of the reels in this DCP */ std::list<int64_t> _reel_lengths; + std::map<dcp::Marker, dcpomatic::ContentTime> _markers; + std::vector<dcp::Rating> _ratings; + std::string _content_version; }; #endif diff --git a/src/lib/dcp_content_type.cc b/src/lib/dcp_content_type.cc index 613ed15a5..4fedd366c 100644 --- a/src/lib/dcp_content_type.cc +++ b/src/lib/dcp_content_type.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -24,7 +24,7 @@ #include "dcp_content_type.h" #include "dcpomatic_assert.h" -#include <cassert> +#include <boost/foreach.hpp> #include "i18n.h" @@ -60,9 +60,9 @@ DCPContentType::setup_dcp_content_types () DCPContentType const * DCPContentType::from_isdcf_name (string n) { - for (vector<DCPContentType const *>::const_iterator i = _dcp_content_types.begin(); i != _dcp_content_types.end(); ++i) { - if ((*i)->isdcf_name() == n) { - return *i; + BOOST_FOREACH (DCPContentType const * i, _dcp_content_types) { + if (i->isdcf_name() == n) { + return i; } } @@ -70,6 +70,20 @@ DCPContentType::from_isdcf_name (string n) } DCPContentType const * +DCPContentType::from_libdcp_kind (dcp::ContentKind kind) +{ + BOOST_FOREACH (DCPContentType const * i, _dcp_content_types) { + if (i->libdcp_kind() == kind) { + return i; + } + } + + DCPOMATIC_ASSERT (false); + return 0; +} + + +DCPContentType const * DCPContentType::from_index (int n) { DCPOMATIC_ASSERT (n >= 0 && n < int (_dcp_content_types.size ())); diff --git a/src/lib/dcp_content_type.h b/src/lib/dcp_content_type.h index 2685e6edf..eea698217 100644 --- a/src/lib/dcp_content_type.h +++ b/src/lib/dcp_content_type.h @@ -51,6 +51,7 @@ public: } static DCPContentType const * from_isdcf_name (std::string); + static DCPContentType const * from_libdcp_kind (dcp::ContentKind); static DCPContentType const * from_index (int); static int as_index (DCPContentType const *); static std::vector<DCPContentType const *> all (); diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc index 9bf401125..d04dacdd6 100644 --- a/src/lib/dcp_examiner.cc +++ b/src/lib/dcp_examiner.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -23,6 +23,7 @@ #include "exceptions.h" #include "image.h" #include "config.h" +#include "util.h" #include <dcp/dcp.h> #include <dcp/decrypted_kdm.h> #include <dcp/cpl.h> @@ -40,6 +41,7 @@ #include <dcp/subtitle_asset.h> #include <dcp/reel_subtitle_asset.h> #include <dcp/reel_closed_caption_asset.h> +#include <dcp/reel_markers_asset.h> #include <dcp/sound_asset.h> #include <boost/foreach.hpp> #include <iostream> @@ -49,6 +51,7 @@ using std::list; using std::cout; using std::runtime_error; +using std::map; using boost::shared_ptr; using boost::dynamic_pointer_cast; @@ -183,6 +186,11 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant) _text_count[TEXT_CLOSED_CAPTION]++; } + if (i->main_markers ()) { + map<dcp::Marker, dcp::Time> rm = i->main_markers()->get(); + _markers.insert (rm.begin(), rm.end()); + } + if (i->main_picture()) { _reel_lengths.push_back (i->main_picture()->actual_duration()); } else if (i->main_sound()) { @@ -229,6 +237,8 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant) _standard = cpl->standard().get(); _three_d = !cpl->reels().empty() && cpl->reels().front()->main_picture() && dynamic_pointer_cast<dcp::StereoPictureAsset> (cpl->reels().front()->main_picture()->asset()); + _ratings = list_to_vector (cpl->ratings()); + _content_version = cpl->content_version_label_text (); _cpl = cpl->id (); } diff --git a/src/lib/dcp_examiner.h b/src/lib/dcp_examiner.h index e52234e36..21aa8d3ab 100644 --- a/src/lib/dcp_examiner.h +++ b/src/lib/dcp_examiner.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -25,6 +25,7 @@ #include "video_examiner.h" #include "audio_examiner.h" #include "dcp.h" +#include <dcp/dcp_time.h> class DCPContent; @@ -118,6 +119,18 @@ public: return _reel_lengths; } + std::map<dcp::Marker, dcp::Time> markers () const { + return _markers; + } + + std::vector<dcp::Rating> ratings () const { + return _ratings; + } + + std::string content_version () const { + return _content_version; + } + private: boost::optional<double> _video_frame_rate; boost::optional<dcp::Size> _video_size; @@ -140,4 +153,7 @@ private: dcp::ContentKind _content_kind; std::string _cpl; std::list<int64_t> _reel_lengths; + std::map<dcp::Marker, dcp::Time> _markers; + std::vector<dcp::Rating> _ratings; + std::string _content_version; }; diff --git a/src/lib/film.cc b/src/lib/film.cc index ed2c5a372..a89d58a1f 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1778,6 +1778,15 @@ Film::unset_marker (dcp::Marker type) _markers.erase (type); } + +void +Film::clear_markers () +{ + ChangeSignaller<Film> ch (this, MARKERS); + _markers.clear (); +} + + void Film::set_ratings (vector<dcp::Rating> r) { diff --git a/src/lib/film.h b/src/lib/film.h index c4cd8bef1..86e9be6d9 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -381,6 +381,7 @@ public: void set_reencode_j2k (bool); void set_marker (dcp::Marker type, dcpomatic::DCPTime time); void unset_marker (dcp::Marker type); + void clear_markers (); void set_ratings (std::vector<dcp::Rating> r); void set_content_version (std::string v); diff --git a/src/lib/util.h b/src/lib/util.h index 12c79ea5a..f8e9409f1 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -128,6 +128,17 @@ vector_to_list (std::vector<T> v) return l; } +template <class T> +std::vector<T> +list_to_vector (std::list<T> v) +{ + std::vector<T> l; + BOOST_FOREACH (T& i, v) { + l.push_back (i); + } + return l; +} + extern double db_to_linear (double db); extern double linear_to_db (double linear); diff --git a/src/lib/wscript b/src/lib/wscript index 67bcf8d8b..17f96d61e 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -52,6 +52,7 @@ sources = """ config.cc content.cc content_factory.cc + copy_dcp_details_to_film.cc create_cli.cc cross_common.cc crypto.cc |
