summaryrefslogtreecommitdiff
path: root/src/lib/butler.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-07-26 15:47:52 +0100
committerCarl Hetherington <cth@carlh.net>2017-07-26 15:47:52 +0100
commit3e230d3785f19bc707fd7ea2b1f55321b93f536f (patch)
tree2773a105d2cf218d9c038418e388ff50f9b46236 /src/lib/butler.cc
parentb395478cbb0706de2b6afa9a34fb33e49c61ee67 (diff)
Multi-threaded decode of DCP when previewing.
Diffstat (limited to 'src/lib/butler.cc')
-rw-r--r--src/lib/butler.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/butler.cc b/src/lib/butler.cc
index 771c4e633..053d7c3bc 100644
--- a/src/lib/butler.cc
+++ b/src/lib/butler.cc
@@ -48,6 +48,7 @@ using boost::optional;
Butler::Butler (weak_ptr<const Film> film, shared_ptr<Player> player, AudioMapping audio_mapping, int audio_channels)
: _film (film)
, _player (player)
+ , _prepare_work (new boost::asio::io_service::work (_prepare_service))
, _pending_seek_accurate (false)
, _finished (false)
, _died (false)
@@ -60,6 +61,13 @@ Butler::Butler (weak_ptr<const Film> film, shared_ptr<Player> player, AudioMappi
_player_audio_connection = _player->Audio.connect (bind (&Butler::audio, this, _1));
_player_changed_connection = _player->Changed.connect (bind (&Butler::player_changed, this));
_thread = new boost::thread (bind (&Butler::thread, this));
+
+ /* Create some threads to do work on the PlayerVideos we are creating; at present this is used to
+ multi-thread JPEG2000 decoding.
+ */
+ for (int i = 0; i < boost::thread::hardware_concurrency(); ++i) {
+ _prepare_pool.create_thread (bind (&boost::asio::io_service::run, &_prepare_service));
+ }
}
Butler::~Butler ()
@@ -69,6 +77,10 @@ Butler::~Butler ()
_stop_thread = true;
}
+ _prepare_work.reset ();
+ _prepare_pool.join_all ();
+ _prepare_service.stop ();
+
_thread->interrupt ();
try {
_thread->join ();
@@ -181,6 +193,16 @@ Butler::seek (DCPTime position, bool accurate)
}
void
+Butler::prepare (weak_ptr<PlayerVideo> weak_video) const
+{
+ shared_ptr<PlayerVideo> video = weak_video.lock ();
+ /* If the weak_ptr cannot be locked the video obviously no longer requires any work */
+ if (video) {
+ video->prepare ();
+ }
+}
+
+void
Butler::video (shared_ptr<PlayerVideo> video, DCPTime time)
{
{
@@ -191,6 +213,7 @@ Butler::video (shared_ptr<PlayerVideo> video, DCPTime time)
}
}
+ _prepare_service.post (bind (&Butler::prepare, this, weak_ptr<PlayerVideo>(video)));
_video.put (video, time);
}