diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-07-19 21:09:12 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-07-27 13:15:34 +0100 |
| commit | ea49dd17eea804a2569531ea4cb8e1bd216717f7 (patch) | |
| tree | 70d0cde8353bc5643e954e28ec997a707f6b6977 /src | |
| parent | 2ae3d1c397dd3ca75c707e46592198b3a83f4444 (diff) | |
Do parallel digest calculation when there are multiple reels (#855).
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/reel_writer.cc | 8 | ||||
| -rw-r--r-- | src/lib/reel_writer.h | 4 | ||||
| -rw-r--r-- | src/lib/writer.cc | 46 | ||||
| -rw-r--r-- | src/lib/writer.h | 4 |
4 files changed, 52 insertions, 10 deletions
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index e6533d2cc..d576eb2a0 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -417,16 +417,14 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr } void -ReelWriter::calculate_digests (shared_ptr<Job> job) +ReelWriter::calculate_digests (boost::function<void (float)> set_progress) { - job->sub (_("Computing image digest")); if (_picture_asset) { - _picture_asset->hash (boost::bind (&Job::set_progress, job.get(), _1, false)); + _picture_asset->hash (set_progress); } if (_sound_asset) { - job->sub (_("Computing audio digest")); - _sound_asset->hash (boost::bind (&Job::set_progress, job.get(), _1, false)); + _sound_asset->hash (set_progress); } } diff --git a/src/lib/reel_writer.h b/src/lib/reel_writer.h index 6e27171ec..9dc740171 100644 --- a/src/lib/reel_writer.h +++ b/src/lib/reel_writer.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -57,7 +57,7 @@ public: void finish (); boost::shared_ptr<dcp::Reel> create_reel (std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<Font> > const & fonts); - void calculate_digests (boost::shared_ptr<Job> job); + void calculate_digests (boost::function<void (float)> set_progress); Frame start () const; diff --git a/src/lib/writer.cc b/src/lib/writer.cc index efd43a25b..1874e68f4 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -58,6 +58,9 @@ using std::pair; using std::string; using std::list; using std::cout; +using std::map; +using std::min; +using std::max; using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; @@ -456,12 +459,34 @@ Writer::finish () dcp.add (cpl); + /* Calculate digests for each reel in parallel */ + + shared_ptr<Job> job = _job.lock (); + job->sub (_("Computing digests")); + + boost::asio::io_service service; + boost::thread_group pool; + + shared_ptr<boost::asio::io_service::work> work (new boost::asio::io_service::work (service)); + + int const threads = max (1, Config::instance()->num_local_encoding_threads ()); + + for (int i = 0; i < threads; ++i) { + pool.create_thread (boost::bind (&boost::asio::io_service::run, &service)); + } + BOOST_FOREACH (ReelWriter& i, _reels) { + boost::function<void (float)> set_progress = boost::bind (&Writer::set_digest_progress, this, job.get(), _1); + service.post (boost::bind (&ReelWriter::calculate_digests, &i, set_progress)); + } - shared_ptr<Job> job = _job.lock (); - DCPOMATIC_ASSERT (job); - i.calculate_digests (job); + work.reset (); + pool.join_all (); + service.stop (); + /* Add reels to CPL */ + + BOOST_FOREACH (ReelWriter& i, _reels) { cpl->add (i.create_reel (_reel_assets, _fonts)); } @@ -597,3 +622,18 @@ Writer::video_reel (int frame) const DCPOMATIC_ASSERT (i < _reels.size ()); return i; } + +void +Writer::set_digest_progress (Job* job, float progress) +{ + /* I believe this is thread-safe */ + _digest_progresses[boost::this_thread::get_id()] = progress; + + boost::mutex::scoped_lock lm (_digest_progresses_mutex); + float min_progress = 0; + for (map<boost::thread::id, float>::const_iterator i = _digest_progresses.begin(); i != _digest_progresses.end(); ++i) { + min_progress = min (min_progress, i->second); + } + + job->set_progress (min_progress); +} diff --git a/src/lib/writer.h b/src/lib/writer.h index 170307d8d..c1d7e4f8b 100644 --- a/src/lib/writer.h +++ b/src/lib/writer.h @@ -113,6 +113,7 @@ private: void terminate_thread (bool); bool have_sequenced_image_at_queue_head (); size_t video_reel (int frame) const; + void set_digest_progress (Job* job, float progress); /** our Film */ boost::shared_ptr<const Film> _film; @@ -150,6 +151,9 @@ private: */ int _pushed_to_disk; + boost::mutex _digest_progresses_mutex; + std::map<boost::thread::id, float> _digest_progresses; + std::list<ReferencedReelAsset> _reel_assets; std::list<boost::shared_ptr<Font> > _fonts; |
