diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-02-16 10:40:12 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-02-16 10:40:12 +0100 |
| commit | bb949ec65adf95f4a2c7dd5ee7e97b9daaaf3d3f (patch) | |
| tree | 09153b297f7cebd3f13ab58188982366185298f6 /src/lib | |
| parent | 39d51cddeeea82e602ab1925430b0dfb5752ac79 (diff) | |
C++11 tidying.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/audio_ring_buffers.cc | 19 | ||||
| -rw-r--r-- | src/lib/audio_ring_buffers.h | 13 | ||||
| -rw-r--r-- | src/lib/decoder.cc | 16 | ||||
| -rw-r--r-- | src/lib/decoder.h | 29 | ||||
| -rw-r--r-- | src/lib/digester.cc | 12 | ||||
| -rw-r--r-- | src/lib/digester.h | 10 | ||||
| -rw-r--r-- | src/lib/frame_interval_checker.h | 11 | ||||
| -rw-r--r-- | src/lib/job_manager.cc | 80 | ||||
| -rw-r--r-- | src/lib/job_manager.h | 20 | ||||
| -rw-r--r-- | src/lib/playlist.cc | 44 | ||||
| -rw-r--r-- | src/lib/playlist.h | 17 | ||||
| -rw-r--r-- | src/lib/ratio.cc | 44 | ||||
| -rw-r--r-- | src/lib/ratio.h | 13 |
13 files changed, 226 insertions, 102 deletions
diff --git a/src/lib/audio_ring_buffers.cc b/src/lib/audio_ring_buffers.cc index 289045ff5..1a216ab33 100644 --- a/src/lib/audio_ring_buffers.cc +++ b/src/lib/audio_ring_buffers.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,11 +18,13 @@ */ + #include "audio_ring_buffers.h" #include "dcpomatic_assert.h" #include "exceptions.h" #include <iostream> + using std::min; using std::cout; using std::make_pair; @@ -32,12 +34,13 @@ using std::shared_ptr; using boost::optional; using namespace dcpomatic; + AudioRingBuffers::AudioRingBuffers () - : _used_in_head (0) { } + /** @param frame_rate Frame rate in use; this is only used to check timing consistency of the incoming data */ void AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time, int frame_rate) @@ -56,6 +59,7 @@ AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time, int fr _buffers.push_back(make_pair(data, time)); } + /** @return time of the returned data; if it's not set this indicates an underrun */ optional<DCPTime> AudioRingBuffers::get (float* out, int channels, int frames) @@ -75,7 +79,7 @@ AudioRingBuffers::get (float* out, int channels, int frames) return time; } - pair<shared_ptr<const AudioBuffers>, DCPTime> front = _buffers.front (); + auto front = _buffers.front (); if (!time) { time = front.second + DCPTime::from_frames(_used_in_head, 48000); } @@ -103,16 +107,18 @@ AudioRingBuffers::get (float* out, int channels, int frames) return time; } + optional<DCPTime> AudioRingBuffers::peek () const { boost::mutex::scoped_lock lm (_mutex); if (_buffers.empty()) { - return optional<DCPTime>(); + return {}; } return _buffers.front().second; } + void AudioRingBuffers::clear () { @@ -121,13 +127,14 @@ AudioRingBuffers::clear () _used_in_head = 0; } + Frame AudioRingBuffers::size () const { boost::mutex::scoped_lock lm (_mutex); Frame s = 0; - for (list<pair<shared_ptr<const AudioBuffers>, DCPTime> >::const_iterator i = _buffers.begin(); i != _buffers.end(); ++i) { - s += i->first->frames(); + for (auto const& i: _buffers) { + s += i.first->frames(); } return s - _used_in_head; } diff --git a/src/lib/audio_ring_buffers.h b/src/lib/audio_ring_buffers.h index 2cfc0a30b..be8a616e2 100644 --- a/src/lib/audio_ring_buffers.h +++ b/src/lib/audio_ring_buffers.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,20 +18,26 @@ */ + #ifndef DCPOMATIC_AUDIO_RING_BUFFERS_H #define DCPOMATIC_AUDIO_RING_BUFFERS_H + #include "audio_buffers.h" #include "types.h" #include "dcpomatic_time.h" #include <boost/thread.hpp> #include <list> -class AudioRingBuffers : public boost::noncopyable + +class AudioRingBuffers { public: AudioRingBuffers (); + AudioRingBuffers (AudioBuffers const&) = delete; + AudioRingBuffers& operator= (AudioBuffers const&) = delete; + void put (std::shared_ptr<const AudioBuffers> data, dcpomatic::DCPTime time, int frame_rate); boost::optional<dcpomatic::DCPTime> get (float* out, int channels, int frames); boost::optional<dcpomatic::DCPTime> peek () const; @@ -42,7 +48,8 @@ public: private: mutable boost::mutex _mutex; std::list<std::pair<std::shared_ptr<const AudioBuffers>, dcpomatic::DCPTime> > _buffers; - int _used_in_head; + int _used_in_head = 0; }; + #endif diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index bf0bd1a26..5d1915128 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "decoder.h" #include "video_decoder.h" #include "audio_decoder.h" @@ -25,24 +26,27 @@ #include <boost/optional.hpp> #include <iostream> + using std::cout; using boost::optional; using std::shared_ptr; using std::weak_ptr; using namespace dcpomatic; + Decoder::Decoder (weak_ptr<const Film> film) : WeakConstFilm (film) { } + /** @return Earliest time of content that the next pass() will emit */ ContentTime Decoder::position () const { optional<ContentTime> pos; - shared_ptr<const Film> f = film(); + auto f = film(); if (video && !video->ignore() && (!pos || video->position(f).get_value_or(ContentTime()) < *pos)) { pos = video->position(f); @@ -70,6 +74,7 @@ Decoder::position () const return pos.get_value_or(ContentTime()); } + void Decoder::seek (ContentTime, bool) { @@ -84,12 +89,13 @@ Decoder::seek (ContentTime, bool) } } + shared_ptr<TextDecoder> Decoder::only_text () const { DCPOMATIC_ASSERT (text.size() < 2); - if (text.empty ()) { - return shared_ptr<TextDecoder> (); + if (text.empty()) { + return {}; } - return text.front (); + return text.front(); } diff --git a/src/lib/decoder.h b/src/lib/decoder.h index da5be4af6..a672e8a10 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,39 +18,47 @@ */ + /** @file src/decoder.h * @brief Decoder class. */ + #ifndef DCPOMATIC_DECODER_H #define DCPOMATIC_DECODER_H -#include "types.h" + +#include "dcpomatic_time.h" #include "film.h" #include "font_data.h" -#include "dcpomatic_time.h" +#include "types.h" #include "weak_film.h" #include <boost/utility.hpp> -class Decoded; -class VideoDecoder; -class AudioDecoder; -class TextDecoder; + class AtmosDecoder; +class AudioDecoder; +class Decoded; class DecoderPart; +class TextDecoder; +class VideoDecoder; + /** @class Decoder. * @brief Parent class for decoders of content. */ -class Decoder : public boost::noncopyable, public WeakConstFilm +class Decoder : public WeakConstFilm { public: Decoder (std::weak_ptr<const Film> film); virtual ~Decoder () {} + Decoder (Decoder const&) = delete; + Decoder& operator= (Decoder const&) = delete; + std::shared_ptr<VideoDecoder> video; std::shared_ptr<AudioDecoder> audio; - std::list<std::shared_ptr<TextDecoder> > text; + std::list<std::shared_ptr<TextDecoder>> text; std::shared_ptr<AtmosDecoder> atmos; std::shared_ptr<TextDecoder> only_text () const; @@ -64,8 +72,9 @@ public: virtual dcpomatic::ContentTime position () const; virtual std::vector<dcpomatic::FontData> fonts () const { - return std::vector<dcpomatic::FontData>(); + return {}; } }; + #endif diff --git a/src/lib/digester.cc b/src/lib/digester.cc index 452452ba4..8542c75a1 100644 --- a/src/lib/digester.cc +++ b/src/lib/digester.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,39 +18,46 @@ */ + #include "digester.h" #include "dcpomatic_assert.h" #include <nettle/md5.h> #include <iomanip> #include <cstdio> + using std::string; using std::hex; using std::setfill; using std::setw; + Digester::Digester () { md5_init (&_context); } + Digester::~Digester () { get (); } + void Digester::add (void const * data, size_t size) { - md5_update (&_context, size, reinterpret_cast<uint8_t const *> (data)); + md5_update (&_context, size, reinterpret_cast<uint8_t const *>(data)); } + void Digester::add (string const & s) { add (s.c_str(), s.length()); } + string Digester::get () const { @@ -69,6 +76,7 @@ Digester::get () const return _digest.get (); } + void Digester::get (uint8_t* buffer) const { diff --git a/src/lib/digester.h b/src/lib/digester.h index 6cdaf2331..e4daabd68 100644 --- a/src/lib/digester.h +++ b/src/lib/digester.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,17 +18,21 @@ */ + #include <nettle/md5.h> -#include <boost/noncopyable.hpp> #include <boost/optional.hpp> #include <string> -class Digester : public boost::noncopyable + +class Digester { public: Digester (); ~Digester (); + Digester (Digester const&) = delete; + Digester& operator= (Digester const&) = delete; + void add (void const * data, size_t size); template <class T> diff --git a/src/lib/frame_interval_checker.h b/src/lib/frame_interval_checker.h index a8db31a49..e8f537c1a 100644 --- a/src/lib/frame_interval_checker.h +++ b/src/lib/frame_interval_checker.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,14 +18,19 @@ */ + #include "dcpomatic_time.h" #include <boost/optional.hpp> -#include <boost/noncopyable.hpp> #include <vector> -class FrameIntervalChecker : public boost::noncopyable + +class FrameIntervalChecker { public: + FrameIntervalChecker () {} + FrameIntervalChecker (FrameIntervalChecker const &) = delete; + FrameIntervalChecker& operator= (FrameIntervalChecker const &) = delete; + void feed (dcpomatic::ContentTime time, double frame_rate); enum Guess diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc index 1724879d0..2839bce30 100644 --- a/src/lib/job_manager.cc +++ b/src/lib/job_manager.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,38 +18,41 @@ */ + /** @file src/job_manager.cc * @brief A simple scheduler for jobs. */ -#include "job_manager.h" -#include "job.h" -#include "cross.h" + #include "analyse_audio_job.h" #include "analyse_subtitles_job.h" +#include "cross.h" #include "film.h" +#include "job.h" +#include "job_manager.h" #include <boost/thread.hpp> -#include <iostream> -using std::string; + +using std::dynamic_pointer_cast; using std::list; -using std::cout; +using std::make_shared; using std::shared_ptr; +using std::string; using std::weak_ptr; +using boost::bind; using boost::function; -using std::dynamic_pointer_cast; using boost::optional; -using boost::bind; -JobManager* JobManager::_instance = 0; + +JobManager* JobManager::_instance = nullptr; + JobManager::JobManager () - : _terminate (false) - , _paused (false) { } + void JobManager::start () { @@ -59,6 +62,7 @@ JobManager::start () #endif } + JobManager::~JobManager () { boost::this_thread::disable_interruption dis; @@ -78,6 +82,7 @@ JobManager::~JobManager () } catch (...) {} } + shared_ptr<Job> JobManager::add (shared_ptr<Job> j) { @@ -87,39 +92,42 @@ JobManager::add (shared_ptr<Job> j) _empty_condition.notify_all (); } - emit (boost::bind (boost::ref (JobAdded), weak_ptr<Job> (j))); + emit (boost::bind(boost::ref(JobAdded), weak_ptr<Job>(j))); return j; } + shared_ptr<Job> JobManager::add_after (shared_ptr<Job> after, shared_ptr<Job> j) { { boost::mutex::scoped_lock lm (_mutex); - list<shared_ptr<Job> >::iterator i = find (_jobs.begin(), _jobs.end(), after); + auto i = find (_jobs.begin(), _jobs.end(), after); DCPOMATIC_ASSERT (i != _jobs.end()); _jobs.insert (i, j); _empty_condition.notify_all (); } - emit (boost::bind (boost::ref (JobAdded), weak_ptr<Job> (j))); + emit (boost::bind(boost::ref(JobAdded), weak_ptr<Job>(j))); return j; } -list<shared_ptr<Job> > + +list<shared_ptr<Job>> JobManager::get () const { boost::mutex::scoped_lock lm (_mutex); return _jobs; } + bool JobManager::work_to_do () const { boost::mutex::scoped_lock lm (_mutex); - list<shared_ptr<Job> >::const_iterator i = _jobs.begin(); + auto i = _jobs.begin(); while (i != _jobs.end() && (*i)->finished()) { ++i; } @@ -127,12 +135,13 @@ JobManager::work_to_do () const return i != _jobs.end (); } + bool JobManager::errors () const { boost::mutex::scoped_lock lm (_mutex); for (auto i: _jobs) { - if (i->finished_in_error ()) { + if (i->finished_in_error()) { return true; } } @@ -140,6 +149,7 @@ JobManager::errors () const return false; } + void JobManager::scheduler () { @@ -183,22 +193,24 @@ JobManager::scheduler () } } + void JobManager::job_finished () { { boost::mutex::scoped_lock lm (_mutex); - emit (boost::bind (boost::ref (ActiveJobsChanged), _last_active_job, optional<string>())); + emit (boost::bind(boost::ref (ActiveJobsChanged), _last_active_job, optional<string>())); _last_active_job = optional<string>(); } _empty_condition.notify_all (); } + JobManager * JobManager::instance () { - if (_instance == 0) { + if (!_instance) { _instance = new JobManager (); _instance->start (); } @@ -206,13 +218,15 @@ JobManager::instance () return _instance; } + void JobManager::drop () { delete _instance; - _instance = 0; + _instance = nullptr; } + void JobManager::analyse_audio ( shared_ptr<const Film> film, @@ -226,7 +240,7 @@ JobManager::analyse_audio ( boost::mutex::scoped_lock lm (_mutex); for (auto i: _jobs) { - shared_ptr<AnalyseAudioJob> a = dynamic_pointer_cast<AnalyseAudioJob> (i); + auto a = dynamic_pointer_cast<AnalyseAudioJob> (i); if (a && a->path() == film->audio_analysis_path(playlist) && !i->finished_cancelled()) { i->when_finished (connection, ready); return; @@ -239,7 +253,7 @@ JobManager::analyse_audio ( { boost::mutex::scoped_lock lm (_mutex); - job.reset (new AnalyseAudioJob (film, playlist, from_zero)); + job = make_shared<AnalyseAudioJob> (film, playlist, from_zero); connection = job->Finished.connect (ready); _jobs.push_back (job); _empty_condition.notify_all (); @@ -261,7 +275,7 @@ JobManager::analyse_subtitles ( boost::mutex::scoped_lock lm (_mutex); for (auto i: _jobs) { - shared_ptr<AnalyseSubtitlesJob> a = dynamic_pointer_cast<AnalyseSubtitlesJob> (i); + auto a = dynamic_pointer_cast<AnalyseSubtitlesJob> (i); if (a && a->path() == film->subtitle_analysis_path(content)) { i->when_finished (connection, ready); return; @@ -274,13 +288,13 @@ JobManager::analyse_subtitles ( { boost::mutex::scoped_lock lm (_mutex); - job.reset (new AnalyseSubtitlesJob(film, content)); + job = make_shared<AnalyseSubtitlesJob>(film, content); connection = job->Finished.connect (ready); _jobs.push_back (job); _empty_condition.notify_all (); } - emit (boost::bind (boost::ref (JobAdded), weak_ptr<Job> (job))); + emit (boost::bind(boost::ref(JobAdded), weak_ptr<Job>(job))); } @@ -291,8 +305,8 @@ JobManager::increase_priority (shared_ptr<Job> job) { boost::mutex::scoped_lock lm (_mutex); - list<shared_ptr<Job> >::iterator last = _jobs.end (); - for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) { + auto last = _jobs.end (); + for (auto i = _jobs.begin(); i != _jobs.end(); ++i) { if (*i == job && last != _jobs.end()) { swap (*i, *last); changed = true; @@ -307,6 +321,7 @@ JobManager::increase_priority (shared_ptr<Job> job) } } + void JobManager::priority_changed () { @@ -330,9 +345,10 @@ JobManager::priority_changed () } } - emit (boost::bind (boost::ref (JobsReordered))); + emit (boost::bind(boost::ref(JobsReordered))); } + void JobManager::decrease_priority (shared_ptr<Job> job) { @@ -340,8 +356,8 @@ JobManager::decrease_priority (shared_ptr<Job> job) { boost::mutex::scoped_lock lm (_mutex); - for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) { - list<shared_ptr<Job> >::iterator next = i; + for (auto i = _jobs.begin(); i != _jobs.end(); ++i) { + auto next = i; ++next; if (*i == job && next != _jobs.end()) { swap (*i, *next); @@ -356,6 +372,7 @@ JobManager::decrease_priority (shared_ptr<Job> job) } } + void JobManager::pause () { @@ -374,6 +391,7 @@ JobManager::pause () _paused = true; } + void JobManager::resume () { diff --git a/src/lib/job_manager.h b/src/lib/job_manager.h index 461688845..4fe1e45d6 100644 --- a/src/lib/job_manager.h +++ b/src/lib/job_manager.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,10 +18,12 @@ */ + /** @file src/job_manager.h * @brief A simple scheduler for jobs. */ + #include "signaller.h" #include <boost/thread/mutex.hpp> #include <boost/thread.hpp> @@ -29,23 +31,29 @@ #include <boost/thread/condition.hpp> #include <list> + class Job; class Film; class Playlist; class Content; struct threed_test7; + extern bool wait_for_jobs (); + /** @class JobManager * @brief A simple scheduler for jobs. */ -class JobManager : public Signaller, public boost::noncopyable +class JobManager : public Signaller { public: + JobManager (JobManager const&) = delete; + JobManager& operator= (JobManager const&) = delete; + std::shared_ptr<Job> add (std::shared_ptr<Job>); std::shared_ptr<Job> add_after (std::shared_ptr<Job> after, std::shared_ptr<Job> j); - std::list<std::shared_ptr<Job> > get () const; + std::list<std::shared_ptr<Job>> get () const; bool work_to_do () const; bool errors () const; void increase_priority (std::shared_ptr<Job>); @@ -94,10 +102,10 @@ private: mutable boost::mutex _mutex; boost::condition _empty_condition; /** List of jobs in the order that they will be executed */ - std::list<std::shared_ptr<Job> > _jobs; + std::list<std::shared_ptr<Job>> _jobs; std::list<boost::signals2::connection> _connections; - bool _terminate; - bool _paused; + bool _terminate = false; + bool _paused = false; std::shared_ptr<Job> _paused_job; boost::optional<std::string> _last_active_job; diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 20534e467..e8714e9d6 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "playlist.h" #include "video_content.h" #include "text_content.h" @@ -39,6 +40,7 @@ #include "i18n.h" + using std::list; using std::cout; using std::vector; @@ -55,13 +57,13 @@ using namespace dcpomatic; using namespace boost::placeholders; #endif + Playlist::Playlist () - : _sequence (true) - , _sequencing (false) { } + Playlist::~Playlist () { boost::mutex::scoped_lock lm (_mutex); @@ -69,6 +71,7 @@ Playlist::~Playlist () disconnect (); } + void Playlist::content_change (weak_ptr<const Film> weak_film, ChangeType type, weak_ptr<Content> content, int property, bool frequent) { @@ -117,6 +120,7 @@ Playlist::content_change (weak_ptr<const Film> weak_film, ChangeType type, weak_ ContentChange (type, content, property, frequent); } + void Playlist::maybe_sequence (shared_ptr<const Film> film) { @@ -126,7 +130,7 @@ Playlist::maybe_sequence (shared_ptr<const Film> film) _sequencing = true; - ContentList cont = content (); + auto cont = content (); /* Keep track of the content that we've set the position of so that we don't do it twice. @@ -171,6 +175,7 @@ Playlist::maybe_sequence (shared_ptr<const Film> film) _sequencing = false; } + string Playlist::video_identifier () const { @@ -193,6 +198,7 @@ Playlist::video_identifier () const return digester.get (); } + /** @param film Film that this Playlist is for. * @param node <Playlist> node. * @param version Metadata version number. @@ -227,7 +233,7 @@ Playlist::set_from_xml (shared_ptr<const Film> film, cxml::ConstNodePtr node, in } /* ...or have a start trim which is an integer number of frames */ - ContentTime const old_trim = content->trim_start(); + auto const old_trim = content->trim_start(); content->set_trim_start(old_trim); if (old_trim != content->trim_start()) { string note = _("Your project contains video content whose trim was not aligned to a frame boundary."); @@ -255,6 +261,7 @@ Playlist::set_from_xml (shared_ptr<const Film> film, cxml::ConstNodePtr node, in reconnect (film); } + /** @param node <Playlist> node. * @param with_content_paths true to include <Path> nodes in <Content> nodes, false to omit them. */ @@ -266,6 +273,7 @@ Playlist::as_xml (xmlpp::Node* node, bool with_content_paths) } } + void Playlist::add (shared_ptr<const Film> film, shared_ptr<Content> c) { @@ -283,6 +291,7 @@ Playlist::add (shared_ptr<const Film> film, shared_ptr<Content> c) LengthChange (); } + void Playlist::remove (shared_ptr<Content> c) { @@ -316,6 +325,7 @@ Playlist::remove (shared_ptr<Content> c) LengthChange (); } + void Playlist::remove (ContentList c) { @@ -325,7 +335,7 @@ Playlist::remove (ContentList c) boost::mutex::scoped_lock lm (_mutex); for (auto i: c) { - ContentList::iterator j = _content.begin (); + auto j = _content.begin (); while (j != _content.end() && *j != i) { ++j; } @@ -343,6 +353,7 @@ Playlist::remove (ContentList c) LengthChange (); } + class FrameRateCandidate { public: @@ -355,6 +366,7 @@ public: int dcp; }; + /** @return the best frame rate from Config::_allowed_dcp_frame_rates for the content in this list */ int Playlist::best_video_frame_rate () const @@ -412,6 +424,7 @@ Playlist::best_video_frame_rate () const return best->dcp; } + /** @return length of the playlist from time 0 to the last thing on the playlist */ DCPTime Playlist::length (shared_ptr<const Film> film) const @@ -424,6 +437,7 @@ Playlist::length (shared_ptr<const Film> film) const return len; } + /** @return position of the first thing on the playlist, if it's not empty */ optional<DCPTime> Playlist::start () const @@ -441,6 +455,7 @@ Playlist::start () const return start; } + /** Must be called with a lock held on _mutex */ void Playlist::disconnect () @@ -452,6 +467,7 @@ Playlist::disconnect () _content_connections.clear (); } + /** Must be called with a lock held on _mutex */ void Playlist::reconnect (shared_ptr<const Film> film) @@ -463,6 +479,7 @@ Playlist::reconnect (shared_ptr<const Film> film) } } + DCPTime Playlist::video_end (shared_ptr<const Film> film) const { @@ -476,6 +493,7 @@ Playlist::video_end (shared_ptr<const Film> film) const return end; } + DCPTime Playlist::text_end (shared_ptr<const Film> film) const { @@ -489,10 +507,11 @@ Playlist::text_end (shared_ptr<const Film> film) const return end; } + FrameRateChange Playlist::active_frame_rate_change (DCPTime t, int dcp_video_frame_rate) const { - ContentList cont = content (); + auto cont = content (); for (ContentList::const_reverse_iterator i = cont.rbegin(); i != cont.rend(); ++i) { if (!(*i)->video) { continue; @@ -515,12 +534,14 @@ Playlist::active_frame_rate_change (DCPTime t, int dcp_video_frame_rate) const return FrameRateChange (dcp_video_frame_rate, dcp_video_frame_rate); } + void Playlist::set_sequence (bool s) { _sequence = s; } + bool ContentSorter::operator() (shared_ptr<Content> a, shared_ptr<Content> b) { @@ -539,6 +560,7 @@ ContentSorter::operator() (shared_ptr<Content> a, shared_ptr<Content> b) return a->digest() < b->digest(); } + /** @return content in ascending order of position */ ContentList Playlist::content () const @@ -547,10 +569,11 @@ Playlist::content () const return _content; } + void Playlist::repeat (shared_ptr<const Film> film, ContentList c, int n) { - pair<DCPTime, DCPTime> range (DCPTime::max (), DCPTime ()); + pair<DCPTime, DCPTime> range (DCPTime::max(), DCPTime()); for (auto i: c) { range.first = min (range.first, i->position ()); range.second = max (range.second, i->position ()); @@ -580,6 +603,7 @@ Playlist::repeat (shared_ptr<const Film> film, ContentList c, int n) Change (ChangeType::DONE); } + void Playlist::move_earlier (shared_ptr<const Film> film, shared_ptr<Content> c) { @@ -603,6 +627,7 @@ Playlist::move_earlier (shared_ptr<const Film> film, shared_ptr<Content> c) c->set_position (film, p); } + void Playlist::move_later (shared_ptr<const Film> film, shared_ptr<Content> c) { @@ -627,6 +652,7 @@ Playlist::move_later (shared_ptr<const Film> film, shared_ptr<Content> c) c->set_position (film, c->position() + next_c->length_after_trim(film)); } + int64_t Playlist::required_disk_space (shared_ptr<const Film> film, int j2k_bandwidth, int audio_channels, int audio_frame_rate) const { @@ -649,6 +675,7 @@ Playlist::required_disk_space (shared_ptr<const Film> film, int j2k_bandwidth, i return video + audio + 65536; } + string Playlist::content_summary (shared_ptr<const Film> film, DCPTimePeriod period) const { @@ -674,6 +701,7 @@ Playlist::content_summary (shared_ptr<const Film> film, DCPTimePeriod period) co return best_summary; } + pair<double, double> Playlist::speed_up_range (int dcp_video_frame_rate) const { diff --git a/src/lib/playlist.h b/src/lib/playlist.h index 91f39bf6b..0dd2370a8 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #ifndef DCPOMATIC_PLAYLIST_H #define DCPOMATIC_PLAYLIST_H + #include "change_signaller.h" #include "frame_rate_change.h" #include "util.h" @@ -29,23 +31,29 @@ #include <boost/thread.hpp> #include <list> + class Film; + struct ContentSorter { bool operator() (std::shared_ptr<Content> a, std::shared_ptr<Content> b); }; + /** @class Playlist * @brief A set of Content objects with knowledge of how they should be arranged into * a DCP. */ -class Playlist : public boost::noncopyable +class Playlist { public: Playlist (); ~Playlist (); + Playlist (Playlist const&) = delete; + Playlist& operator= (Playlist const&) = delete; + void as_xml (xmlpp::Node *, bool with_content_paths); void set_from_xml (std::shared_ptr<const Film> film, cxml::ConstNodePtr node, int version, std::list<std::string>& notes); @@ -91,9 +99,10 @@ private: mutable boost::mutex _mutex; /** List of content. Kept sorted in position order. */ ContentList _content; - bool _sequence; - bool _sequencing; + bool _sequence = true; + bool _sequencing = false; std::list<boost::signals2::connection> _content_connections; }; + #endif diff --git a/src/lib/ratio.cc b/src/lib/ratio.cc index 93ad5755d..5ba79c28b 100644 --- a/src/lib/ratio.cc +++ b/src/lib/ratio.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "ratio.h" #include "util.h" #include "config.h" @@ -26,27 +27,31 @@ #include "i18n.h" + using std::string; using std::vector; using boost::optional; + vector<Ratio const *> Ratio::_ratios; + void Ratio::setup_ratios () { - _ratios.push_back (new Ratio (float(1290) / 1080, "119", _("1.19"), optional<string>(), "119")); - _ratios.push_back (new Ratio (float(1440) / 1080, "133", _("1.33 (4:3)"), optional<string>(), "133")); - _ratios.push_back (new Ratio (float(1485) / 1080, "138", _("1.38 (Academy)"), optional<string>(), "137")); - _ratios.push_back (new Ratio (float(1544) / 1080, "143", _("1.43 (IMAX)"), optional<string>(), "143")); - _ratios.push_back (new Ratio (float(1800) / 1080, "166", _("1.66"), optional<string>(), "166")); - _ratios.push_back (new Ratio (float(1920) / 1080, "178", _("1.78 (16:9 or HD)"), optional<string>(), "178")); - _ratios.push_back (new Ratio (float(1998) / 1080, "185", _("1.85 (Flat)"), string(_("DCI Flat")), "F")); - _ratios.push_back (new Ratio (float(2048) / 872, "235", _("2.35 (35mm Scope)"), optional<string>(), "S")); - _ratios.push_back (new Ratio (float(2048) / 858, "239", _("2.39 (Scope)"), string(_("DCI Scope")), "S")); - _ratios.push_back (new Ratio (float(2048) / 1080, "190", _("1.90 (Full frame)"), string(_("Full frame")), "C")); + _ratios.push_back (new Ratio(float(1290) / 1080, "119", _("1.19"), optional<string>(), "119")); + _ratios.push_back (new Ratio(float(1440) / 1080, "133", _("1.33 (4:3)"), optional<string>(), "133")); + _ratios.push_back (new Ratio(float(1485) / 1080, "138", _("1.38 (Academy)"), optional<string>(), "137")); + _ratios.push_back (new Ratio(float(1544) / 1080, "143", _("1.43 (IMAX)"), optional<string>(), "143")); + _ratios.push_back (new Ratio(float(1800) / 1080, "166", _("1.66"), optional<string>(), "166")); + _ratios.push_back (new Ratio(float(1920) / 1080, "178", _("1.78 (16:9 or HD)"), optional<string>(), "178")); + _ratios.push_back (new Ratio(float(1998) / 1080, "185", _("1.85 (Flat)"), string(_("DCI Flat")), "F")); + _ratios.push_back (new Ratio(float(2048) / 872, "235", _("2.35 (35mm Scope)"), optional<string>(), "S")); + _ratios.push_back (new Ratio(float(2048) / 858, "239", _("2.39 (Scope)"), string(_("DCI Scope")), "S")); + _ratios.push_back (new Ratio(float(2048) / 1080, "190", _("1.90 (Full frame)"), string(_("Full frame")), "C")); } + Ratio const * Ratio::from_id (string i) { @@ -55,7 +60,7 @@ Ratio::from_id (string i) i = "138"; } - vector<Ratio const *>::iterator j = _ratios.begin (); + auto j = _ratios.begin (); while (j != _ratios.end() && (*j)->id() != i) { ++j; } @@ -67,30 +72,32 @@ Ratio::from_id (string i) return *j; } + /** @return Ratio corresponding to a given fractional ratio (+/- 0.01), or 0 */ Ratio const * Ratio::from_ratio (float r) { - vector<Ratio const *>::iterator j = _ratios.begin (); - while (j != _ratios.end() && fabs ((*j)->ratio() - r) > 0.01) { + auto j = _ratios.begin (); + while (j != _ratios.end() && fabs((*j)->ratio() - r) > 0.01) { ++j; } if (j == _ratios.end ()) { - return 0; + return nullptr; } return *j; } + Ratio const * Ratio::nearest_from_ratio (float r) { - Ratio const * nearest = 0; + Ratio const * nearest = nullptr; float distance = FLT_MAX; - for (vector<Ratio const *>::iterator i = _ratios.begin (); i != _ratios.end(); ++i) { - float const d = fabs ((*i)->ratio() - r); + for (auto i = _ratios.begin(); i != _ratios.end(); ++i) { + float const d = fabs((*i)->ratio() - r); if (d < distance) { distance = d; nearest = *i; @@ -113,6 +120,7 @@ Ratio::containers () return r; } + string Ratio::container_nickname () const { diff --git a/src/lib/ratio.h b/src/lib/ratio.h index 40f596ab8..016a22edc 100644 --- a/src/lib/ratio.h +++ b/src/lib/ratio.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,17 +18,20 @@ */ + #ifndef DCPOMATIC_RATIO_H #define DCPOMATIC_RATIO_H + #include <dcp/util.h> #include <boost/utility.hpp> #include <vector> + /** @class Ratio * @brief Description of an image ratio. */ -class Ratio : public boost::noncopyable +class Ratio { public: Ratio (float ratio, std::string id, std::string in, boost::optional<std::string> cn, std::string d) @@ -39,6 +42,9 @@ public: , _isdcf_name (d) {} + Ratio (Ratio const&) = delete; + Ratio& operator= (Ratio const&) = delete; + std::string id () const { return _id; } @@ -50,7 +56,7 @@ public: std::string container_nickname () const; bool used_for_container () const { - return static_cast<bool> (_container_nickname); + return static_cast<bool>(_container_nickname); } std::string isdcf_name () const { @@ -85,4 +91,5 @@ private: static std::vector<Ratio const *> _ratios; }; + #endif |
