}
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);
}
}
/*
- 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.
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;
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;
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));
}
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);
+}
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;
*/
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;