diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-02-17 02:17:12 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-02-17 02:17:12 +0100 |
| commit | 3c7e18dca8f7f5c331cc0d23f44abd01341b6ec9 (patch) | |
| tree | e2eba0a08363966c6f234f53d4c5c2ea4b80ba33 /src/lib/content.cc | |
| parent | 410624e0548f65b795b192367f9272eb6f5d7bdb (diff) | |
White space: content.{cc,h}
Diffstat (limited to 'src/lib/content.cc')
| -rw-r--r-- | src/lib/content.cc | 204 |
1 files changed, 99 insertions, 105 deletions
diff --git a/src/lib/content.cc b/src/lib/content.cc index 5e6dd7e31..c5f82a375 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -64,22 +64,16 @@ int const ContentProperty::TRIM_END = 404; int const ContentProperty::VIDEO_FRAME_RATE = 405; -Content::Content () +Content::Content(DCPTime p) + : _position(p) { } -Content::Content (DCPTime p) - : _position (p) +Content::Content(boost::filesystem::path p) { - -} - - -Content::Content (boost::filesystem::path p) -{ - add_path (p); + add_path(p); } @@ -93,50 +87,50 @@ Content::Content(cxml::ConstNodePtr node, boost::optional<boost::filesystem::pat } auto const mod = i->optional_number_attribute<time_t>("mtime"); if (mod) { - _last_write_times.push_back (*mod); + _last_write_times.push_back(*mod); } else { boost::system::error_code ec; auto last_write = dcp::filesystem::last_write_time(i->content(), ec); - _last_write_times.push_back (ec ? 0 : last_write); + _last_write_times.push_back(ec ? 0 : last_write); } } - _digest = node->optional_string_child ("Digest").get_value_or ("X"); - _position = DCPTime (node->number_child<DCPTime::Type> ("Position")); - _trim_start = ContentTime (node->number_child<ContentTime::Type> ("TrimStart")); - _trim_end = ContentTime (node->number_child<ContentTime::Type> ("TrimEnd")); - _video_frame_rate = node->optional_number_child<double> ("VideoFrameRate"); + _digest = node->optional_string_child("Digest").get_value_or("X"); + _position = DCPTime(node->number_child<DCPTime::Type>("Position")); + _trim_start = ContentTime(node->number_child<ContentTime::Type>("TrimStart")); + _trim_end = ContentTime(node->number_child<ContentTime::Type>("TrimEnd")); + _video_frame_rate = node->optional_number_child<double>("VideoFrameRate"); } -Content::Content (vector<shared_ptr<Content>> 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()) +Content::Content(vector<shared_ptr<Content>> 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()) { for (size_t i = 0; i < c.size(); ++i) { - if (i > 0 && c[i]->trim_start() > ContentTime ()) { - throw JoinError (_("Only the first piece of content to be joined can have a start trim.")); + if (i > 0 && c[i]->trim_start() > ContentTime()) { + throw JoinError(_("Only the first piece of content to be joined can have a start trim.")); } - if (i < (c.size() - 1) && c[i]->trim_end () > ContentTime ()) { - throw JoinError (_("Only the last piece of content to be joined can have an end trim.")); + if (i < (c.size() - 1) && c[i]->trim_end() > ContentTime()) { + throw JoinError(_("Only the last piece of content to be joined can have an end trim.")); } if ( (_video_frame_rate && !c[i]->_video_frame_rate) || (!_video_frame_rate && c[i]->_video_frame_rate) ) { - throw JoinError (_("Content to be joined must have the same video frame rate")); + throw JoinError(_("Content to be joined must have the same video frame rate")); } - if (_video_frame_rate && fabs (_video_frame_rate.get() - c[i]->_video_frame_rate.get()) > VIDEO_FRAME_RATE_EPSILON) { - throw JoinError (_("Content to be joined must have the same video frame rate")); + if (_video_frame_rate && fabs(_video_frame_rate.get() - c[i]->_video_frame_rate.get()) > VIDEO_FRAME_RATE_EPSILON) { + throw JoinError(_("Content to be joined must have the same video frame rate")); } for (size_t j = 0; j < c[i]->number_of_paths(); ++j) { - _paths.push_back (c[i]->path(j)); - _last_write_times.push_back (c[i]->_last_write_times[j]); + _paths.push_back(c[i]->path(j)); + _last_write_times.push_back(c[i]->_last_write_times[j]); } } } @@ -145,7 +139,7 @@ Content::Content (vector<shared_ptr<Content>> c) void Content::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour path_behaviour, optional<boost::filesystem::path> film_directory) const { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); if (with_paths) { for (size_t i = 0; i < _paths.size(); ++i) { @@ -156,7 +150,7 @@ Content::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour path_beh } auto p = cxml::add_child(element, "Path"); p->add_child_text(path.string()); - p->set_attribute ("mtime", fmt::to_string(_last_write_times[i])); + p->set_attribute("mtime", fmt::to_string(_last_write_times[i])); } } cxml::add_text_child(element, "Digest", _digest); @@ -170,13 +164,13 @@ Content::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour path_beh string -Content::calculate_digest () const +Content::calculate_digest() const { /* Some content files are very big, so we use a poor man's digest here: a digest of the first and last 1e6 bytes with the size of the first file tacked on the end as a string. */ - return simple_digest (paths()); + return simple_digest(paths()); } @@ -184,31 +178,31 @@ void Content::examine(shared_ptr<const Film>, shared_ptr<Job> job, bool) { if (job) { - job->sub (_("Computing digest")); + job->sub(_("Computing digest")); } - auto const d = calculate_digest (); + auto const d = calculate_digest(); - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); _digest = d; - _last_write_times.clear (); + _last_write_times.clear(); for (auto i: _paths) { boost::system::error_code ec; auto last_write = dcp::filesystem::last_write_time(i, ec); - _last_write_times.push_back (ec ? 0 : last_write); + _last_write_times.push_back(ec ? 0 : last_write); } } void -Content::signal_change (ChangeType c, int p) +Content::signal_change(ChangeType c, int p) { try { if (c == ChangeType::PENDING || c == ChangeType::CANCELLED) { - Change (c, shared_from_this(), p, _change_signals_frequent); + Change(c, shared_from_this(), p, _change_signals_frequent); } else { - emit (boost::bind (boost::ref(Change), c, shared_from_this(), p, _change_signals_frequent)); + emit(boost::bind(boost::ref(Change), c, shared_from_this(), p, _change_signals_frequent)); } } catch (std::bad_weak_ptr &) { /* This must be during construction; never mind */ @@ -217,12 +211,12 @@ Content::signal_change (ChangeType c, int p) void -Content::set_position (shared_ptr<const Film> film, DCPTime p, bool force_emit) +Content::set_position(shared_ptr<const Film> film, DCPTime p, bool force_emit) { /* video and audio content can modify its position */ if (video) { - video->modify_position (film, p); + video->modify_position(film, p); } /* Only allow the audio to modify if we have no video; @@ -232,15 +226,15 @@ Content::set_position (shared_ptr<const Film> film, DCPTime p, bool force_emit) cope. */ if (!video && audio) { - audio->modify_position (film, p); + audio->modify_position(film, p); } - ContentChangeSignaller cc (this, ContentProperty::POSITION); + ContentChangeSignaller cc(this, ContentProperty::POSITION); { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); if (p == _position && !force_emit) { - cc.abort (); + cc.abort(); return; } @@ -252,12 +246,12 @@ Content::set_position (shared_ptr<const Film> film, DCPTime p, bool force_emit) void Content::set_trim_start(shared_ptr<const Film> film, ContentTime t) { - DCPOMATIC_ASSERT (t.get() >= 0); + DCPOMATIC_ASSERT(t.get() >= 0); /* video and audio content can modify its start trim */ if (video) { - video->modify_trim_start (t); + video->modify_trim_start(t); } /* See note in ::set_position */ @@ -265,10 +259,10 @@ Content::set_trim_start(shared_ptr<const Film> film, ContentTime t) audio->modify_trim_start(film, t); } - ContentChangeSignaller cc (this, ContentProperty::TRIM_START); + ContentChangeSignaller cc(this, ContentProperty::TRIM_START); { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); if (_trim_start == t) { cc.abort(); } else { @@ -279,14 +273,14 @@ Content::set_trim_start(shared_ptr<const Film> film, ContentTime t) void -Content::set_trim_end (ContentTime t) +Content::set_trim_end(ContentTime t) { - DCPOMATIC_ASSERT (t.get() >= 0); + DCPOMATIC_ASSERT(t.get() >= 0); - ContentChangeSignaller cc (this, ContentProperty::TRIM_END); + ContentChangeSignaller cc(this, ContentProperty::TRIM_END); { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); _trim_end = t; } } @@ -297,7 +291,7 @@ Content::clone() const { /* This is a bit naughty, but I can't think of a compelling reason not to do it ... */ xmlpp::Document doc; - auto node = doc.create_root_node ("Content"); + auto node = doc.create_root_node("Content"); as_xml(node, true, PathBehaviour::KEEP_ABSOLUTE, {}); /* notes is unused here (we assume) */ @@ -307,9 +301,9 @@ Content::clone() const string -Content::technical_summary () const +Content::technical_summary() const { - auto s = String::compose ("%1 %2 %3", path_summary(), digest(), position().seconds()); + auto s = String::compose("%1 %2 %3", path_summary(), digest(), position().seconds()); if (_video_frame_rate) { s += String::compose(" %1", *_video_frame_rate); } @@ -318,7 +312,7 @@ Content::technical_summary () const DCPTime -Content::length_after_trim (shared_ptr<const Film> film) const +Content::length_after_trim(shared_ptr<const Film> film) const { auto length = max(DCPTime(), full_length(film) - DCPTime(trim_start() + trim_end(), film->active_frame_rate_change(position()))); if (video) { @@ -332,10 +326,10 @@ Content::length_after_trim (shared_ptr<const Film> film) const * the appearance of its video. */ string -Content::identifier () const +Content::identifier() const { char buffer[256]; - snprintf ( + snprintf( buffer, sizeof(buffer), "%s_%" PRId64 "_%" PRId64 "_%" PRId64, Content::digest().c_str(), position().get(), trim_start().get(), trim_end().get() ); @@ -344,7 +338,7 @@ Content::identifier () const bool -Content::paths_valid () const +Content::paths_valid() const { for (auto i: _paths) { if (!dcp::filesystem::exists(i)) { @@ -357,32 +351,32 @@ Content::paths_valid () const void -Content::set_paths (vector<boost::filesystem::path> paths) +Content::set_paths(vector<boost::filesystem::path> paths) { - ContentChangeSignaller cc (this, ContentProperty::PATH); + ContentChangeSignaller cc(this, ContentProperty::PATH); { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); _paths.clear(); for (auto path: paths) { _paths.push_back(boost::filesystem::canonical(path)); } - _last_write_times.clear (); + _last_write_times.clear(); for (auto i: _paths) { boost::system::error_code ec; auto last_write = dcp::filesystem::last_write_time(i, ec); - _last_write_times.push_back (ec ? 0 : last_write); + _last_write_times.push_back(ec ? 0 : last_write); } } } string -Content::path_summary () const +Content::path_summary() const { /* XXX: should handle multiple paths more gracefully */ - DCPOMATIC_ASSERT (number_of_paths ()); + DCPOMATIC_ASSERT(number_of_paths()); auto s = path(0).filename().string(); if (number_of_paths() > 1) { @@ -395,23 +389,23 @@ Content::path_summary () const /** @return a list of properties that might be interesting to the user */ list<UserProperty> -Content::user_properties (shared_ptr<const Film> film) const +Content::user_properties(shared_ptr<const Film> film) const { list<UserProperty> p; - add_properties (film, p); + add_properties(film, p); return p; } /** @return DCP times of points within this content where a reel split could occur */ list<DCPTime> -Content::reel_split_points (shared_ptr<const Film>) const +Content::reel_split_points(shared_ptr<const Film>) const { list<DCPTime> t; /* This is only called for video content and such content has its position forced to start on a frame boundary. */ - t.push_back (position()); + t.push_back(position()); return t; } @@ -419,10 +413,10 @@ Content::reel_split_points (shared_ptr<const Film>) const void Content::set_video_frame_rate(shared_ptr<const Film> film, double r) { - ContentChangeSignaller cc (this, ContentProperty::VIDEO_FRAME_RATE); + ContentChangeSignaller cc(this, ContentProperty::VIDEO_FRAME_RATE); { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); if (_video_frame_rate && fabs(r - *_video_frame_rate) < VIDEO_FRAME_RATE_EPSILON) { cc.abort(); } @@ -437,24 +431,24 @@ Content::set_video_frame_rate(shared_ptr<const Film> film, double r) void -Content::unset_video_frame_rate () +Content::unset_video_frame_rate() { - ContentChangeSignaller cc (this, ContentProperty::VIDEO_FRAME_RATE); + ContentChangeSignaller cc(this, ContentProperty::VIDEO_FRAME_RATE); { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); _video_frame_rate = optional<double>(); } } double -Content::active_video_frame_rate (shared_ptr<const Film> film) const +Content::active_video_frame_rate(shared_ptr<const Film> film) const { { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); if (_video_frame_rate) { - return _video_frame_rate.get (); + return _video_frame_rate.get(); } } @@ -467,7 +461,7 @@ Content::active_video_frame_rate (shared_ptr<const Film> film) const void -Content::add_properties (shared_ptr<const Film>, list<UserProperty>& p) const +Content::add_properties(shared_ptr<const Film>, list<UserProperty>& p) const { auto paths_to_show = std::min(number_of_paths(), size_t{8}); string paths = ""; @@ -480,7 +474,7 @@ Content::add_properties (shared_ptr<const Film>, list<UserProperty>& p) const if (paths_to_show < number_of_paths()) { paths += String::compose("... and %1 more", number_of_paths() - paths_to_show); } - p.push_back ( + p.push_back( UserProperty( UserProperty::GENERAL, paths_to_show > 1 ? _("Filenames") : _("Filename"), @@ -490,20 +484,20 @@ Content::add_properties (shared_ptr<const Film>, list<UserProperty>& p) const if (_video_frame_rate) { if (video) { - p.push_back ( - UserProperty ( + p.push_back( + UserProperty( UserProperty::VIDEO, _("Frame rate"), - locale_convert<string> (_video_frame_rate.get(), 5), + locale_convert<string>(_video_frame_rate.get(), 5), _("frames per second") ) ); } else { - p.push_back ( - UserProperty ( + p.push_back( + UserProperty( UserProperty::GENERAL, _("Prepared for video frame rate"), - locale_convert<string> (_video_frame_rate.get(), 5), + locale_convert<string>(_video_frame_rate.get(), 5), _("frames per second") ) ); @@ -514,19 +508,19 @@ Content::add_properties (shared_ptr<const Film>, list<UserProperty>& p) const /** Take settings from the given content if it is of the correct type */ void -Content::take_settings_from (shared_ptr<const Content> c) +Content::take_settings_from(shared_ptr<const Content> c) { if (video && c->video) { - video->take_settings_from (c->video); + video->take_settings_from(c->video); } if (audio && c->audio) { - audio->take_settings_from (c->audio); + audio->take_settings_from(c->audio); } - auto i = text.begin (); - auto j = c->text.begin (); + auto i = text.begin(); + auto j = c->text.begin(); while (i != text.end() && j != c->text.end()) { - (*i)->take_settings_from (*j); + (*i)->take_settings_from(*j); ++i; ++j; } @@ -534,18 +528,18 @@ Content::take_settings_from (shared_ptr<const Content> c) shared_ptr<TextContent> -Content::only_text () const +Content::only_text() const { - DCPOMATIC_ASSERT (text.size() < 2); + DCPOMATIC_ASSERT(text.size() < 2); if (text.empty()) { return {}; } - return text.front (); + return text.front(); } shared_ptr<TextContent> -Content::text_of_original_type (TextType type) const +Content::text_of_original_type(TextType type) const { for (auto i: text) { if (i->original_type() == type) { @@ -558,18 +552,18 @@ Content::text_of_original_type (TextType type) const void -Content::add_path (boost::filesystem::path p) +Content::add_path(boost::filesystem::path p) { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm(_mutex); _paths.push_back(boost::filesystem::canonical(p)); boost::system::error_code ec; auto last_write = dcp::filesystem::last_write_time(p, ec); - _last_write_times.push_back (ec ? 0 : last_write); + _last_write_times.push_back(ec ? 0 : last_write); } bool -Content::changed () const +Content::changed() const { bool write_time_changed = false; for (auto i = 0U; i < _paths.size(); ++i) { |
