X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fcontent.cc;h=49ab944be54c79c3d478469ad09762a9555768fe;hp=0171563ae5d041d1fb9ee97812bd17e8b2c2bf6f;hb=33e13c4053138930f4b2f59349e441c76111059d;hpb=e0255a64d22440d718e5512f34a4f21f0d37a21b diff --git a/src/lib/content.cc b/src/lib/content.cc index 0171563ae..49ab944be 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -18,10 +18,12 @@ */ + /** @file src/lib/content.cc * @brief Content class. */ + #include "content.h" #include "change_signaller.h" #include "util.h" @@ -42,18 +44,21 @@ #include "i18n.h" -using std::string; -using std::list; + using std::cout; -using std::vector; +using std::list; +using std::make_shared; using std::max; using std::pair; using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; -using dcp::raw_convert; using dcp::locale_convert; +using dcp::raw_convert; using namespace dcpomatic; + int const ContentProperty::PATH = 400; int const ContentProperty::POSITION = 401; int const ContentProperty::LENGTH = 402; @@ -61,33 +66,29 @@ int const ContentProperty::TRIM_START = 403; int const ContentProperty::TRIM_END = 404; int const ContentProperty::VIDEO_FRAME_RATE = 405; + Content::Content () - : _position (0) - , _trim_start (0) - , _trim_end (0) - , _change_signals_frequent (false) + : _change_signals_frequent (false) { } + Content::Content (DCPTime p) : _position (p) - , _trim_start (0) - , _trim_end (0) , _change_signals_frequent (false) { } + Content::Content (boost::filesystem::path p) - : _position (0) - , _trim_start (0) - , _trim_end (0) - , _change_signals_frequent (false) + : _change_signals_frequent (false) { add_path (p); } + Content::Content (cxml::ConstNodePtr node) : _change_signals_frequent (false) { @@ -96,10 +97,10 @@ Content::Content (cxml::ConstNodePtr node) auto const mod = i->optional_number_attribute("mtime"); if (mod) { _last_write_times.push_back (*mod); - } else if (boost::filesystem::exists(i->content())) { - _last_write_times.push_back (boost::filesystem::last_write_time(i->content())); } else { - _last_write_times.push_back (0); + boost::system::error_code ec; + auto last_write = boost::filesystem::last_write_time(i->content(), ec); + _last_write_times.push_back (ec ? 0 : last_write); } } _digest = node->optional_string_child ("Digest").get_value_or ("X"); @@ -109,10 +110,11 @@ Content::Content (cxml::ConstNodePtr node) _video_frame_rate = node->optional_number_child ("VideoFrameRate"); } -Content::Content (vector > c) - : _position (c.front()->position ()) - , _trim_start (c.front()->trim_start ()) - , _trim_end (c.back()->trim_end ()) + +Content::Content (vector> c) + : _position (c.front()->position()) + , _trim_start (c.front()->trim_start()) + , _trim_end (c.back()->trim_end()) , _video_frame_rate (c.front()->video_frame_rate()) , _change_signals_frequent (false) { @@ -143,6 +145,7 @@ Content::Content (vector > c) } } + void Content::as_xml (xmlpp::Node* node, bool with_paths) const { @@ -150,20 +153,21 @@ Content::as_xml (xmlpp::Node* node, bool with_paths) const if (with_paths) { for (size_t i = 0; i < _paths.size(); ++i) { - xmlpp::Element* p = node->add_child("Path"); + auto p = node->add_child("Path"); p->add_child_text (_paths[i].string()); p->set_attribute ("mtime", raw_convert(_last_write_times[i])); } } - node->add_child("Digest")->add_child_text (_digest); - node->add_child("Position")->add_child_text (raw_convert (_position.get ())); - node->add_child("TrimStart")->add_child_text (raw_convert (_trim_start.get ())); - node->add_child("TrimEnd")->add_child_text (raw_convert (_trim_end.get ())); + node->add_child("Digest")->add_child_text(_digest); + node->add_child("Position")->add_child_text(raw_convert(_position.get())); + node->add_child("TrimStart")->add_child_text(raw_convert(_trim_start.get())); + node->add_child("TrimEnd")->add_child_text(raw_convert(_trim_end.get())); if (_video_frame_rate) { - node->add_child("VideoFrameRate")->add_child_text (raw_convert (_video_frame_rate.get())); + node->add_child("VideoFrameRate")->add_child_text(raw_convert(_video_frame_rate.get())); } } + string Content::calculate_digest () const { @@ -178,6 +182,7 @@ Content::calculate_digest () const return digest_head_tail(p, 1000000) + raw_convert(boost::filesystem::file_size(p.front())); } + void Content::examine (shared_ptr, shared_ptr job) { @@ -192,10 +197,13 @@ Content::examine (shared_ptr, shared_ptr job) _last_write_times.clear (); for (auto i: _paths) { - _last_write_times.push_back (boost::filesystem::last_write_time(i)); + boost::system::error_code ec; + auto last_write = boost::filesystem::last_write_time(i, ec); + _last_write_times.push_back (ec ? 0 : last_write); } } + void Content::signal_change (ChangeType c, int p) { @@ -210,6 +218,7 @@ Content::signal_change (ChangeType c, int p) } } + void Content::set_position (shared_ptr film, DCPTime p, bool force_emit) { @@ -242,6 +251,7 @@ Content::set_position (shared_ptr film, DCPTime p, bool force_emit) } } + void Content::set_trim_start (ContentTime t) { @@ -264,6 +274,7 @@ Content::set_trim_start (ContentTime t) } } + void Content::set_trim_end (ContentTime t) { @@ -286,9 +297,10 @@ Content::clone () const /* notes is unused here (we assume) */ list notes; - return content_factory (cxml::NodePtr(new cxml::Node(node)), Film::current_state_version, notes); + return content_factory (make_shared(node), Film::current_state_version, notes); } + string Content::technical_summary () const { @@ -299,6 +311,7 @@ Content::technical_summary () const return s; } + DCPTime Content::length_after_trim (shared_ptr film) const { @@ -309,6 +322,7 @@ Content::length_after_trim (shared_ptr film) const return length; } + /** @return string which changes when something about this content changes which affects * the appearance of its video. */ @@ -323,6 +337,7 @@ Content::identifier () const return buffer; } + bool Content::paths_valid () const { @@ -335,6 +350,7 @@ Content::paths_valid () const return true; } + void Content::set_paths (vector paths) { @@ -345,11 +361,14 @@ Content::set_paths (vector paths) _paths = paths; _last_write_times.clear (); for (auto i: _paths) { - _last_write_times.push_back (boost::filesystem::last_write_time(i)); + boost::system::error_code ec; + auto last_write = boost::filesystem::last_write_time(i, ec); + _last_write_times.push_back (ec ? 0 : last_write); } } } + string Content::path_summary () const { @@ -365,6 +384,7 @@ Content::path_summary () const return s; } + /** @return a list of properties that might be interesting to the user */ list Content::user_properties (shared_ptr film) const @@ -374,6 +394,7 @@ Content::user_properties (shared_ptr film) const return p; } + /** @return DCP times of points within this content where a reel split could occur */ list Content::reel_split_points (shared_ptr) const @@ -386,6 +407,7 @@ Content::reel_split_points (shared_ptr) const return t; } + void Content::set_video_frame_rate (double r) { @@ -405,6 +427,7 @@ Content::set_video_frame_rate (double r) } } + void Content::unset_video_frame_rate () { @@ -416,6 +439,7 @@ Content::unset_video_frame_rate () } } + double Content::active_video_frame_rate (shared_ptr film) const { @@ -433,6 +457,7 @@ Content::active_video_frame_rate (shared_ptr film) const return film->active_frame_rate_change(position()).source; } + void Content::add_properties (shared_ptr, list& p) const { @@ -461,6 +486,7 @@ Content::add_properties (shared_ptr, list& p) const } } + /** Take settings from the given content if it is of the correct type */ void Content::take_settings_from (shared_ptr c) @@ -481,16 +507,18 @@ Content::take_settings_from (shared_ptr c) } } + shared_ptr Content::only_text () const { DCPOMATIC_ASSERT (text.size() < 2); - if (text.empty ()) { - return shared_ptr (); + if (text.empty()) { + return {}; } return text.front (); } + shared_ptr Content::text_of_original_type (TextType type) const { @@ -500,13 +528,16 @@ Content::text_of_original_type (TextType type) const } } - return shared_ptr (); + return {}; } + void Content::add_path (boost::filesystem::path p) { boost::mutex::scoped_lock lm (_mutex); _paths.push_back (p); - _last_write_times.push_back (boost::filesystem::last_write_time(p)); + boost::system::error_code ec; + auto last_write = boost::filesystem::last_write_time(p, ec); + _last_write_times.push_back (ec ? 0 : last_write); }