diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-04-23 21:22:19 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-04-23 21:22:19 +0100 |
| commit | d8dd8b76a5b0f59e11392ab261f2410102bfe934 (patch) | |
| tree | caa66d72ba1860c5ab574b788962f8db37a81b21 /src | |
| parent | 8cf721f7d88fb110e8f56b7dcd9cc4a6586d5a54 (diff) | |
Cope better with the butler thread throwing an exception; give up
on doing anything else with it.
Fix thread running waiting for audio when it is disabled.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/butler.cc | 22 | ||||
| -rw-r--r-- | src/lib/butler.h | 1 |
2 files changed, 17 insertions, 6 deletions
diff --git a/src/lib/butler.cc b/src/lib/butler.cc index b84dbc024..b9aa0a5db 100644 --- a/src/lib/butler.cc +++ b/src/lib/butler.cc @@ -41,6 +41,7 @@ Butler::Butler (weak_ptr<const Film> film, shared_ptr<Player> player, AudioMappi , _player (player) , _pending_seek_accurate (false) , _finished (false) + , _died (false) , _audio_mapping (audio_mapping) , _audio_channels (audio_channels) , _stop_thread (false) @@ -67,7 +68,7 @@ Butler::~Butler () bool Butler::should_run () const { - return (_video.size() < VIDEO_READAHEAD || _audio.size() < AUDIO_READAHEAD) && !_stop_thread && !_finished; + return (_video.size() < VIDEO_READAHEAD || (!_disable_audio && _audio.size() < AUDIO_READAHEAD)) && !_stop_thread && !_finished && !_died; } void @@ -94,20 +95,25 @@ try */ while (should_run() && !_pending_seek_position) { lm.unlock (); - if (_player->pass ()) { + bool const r = _player->pass (); + lm.lock (); + if (r) { _finished = true; _arrived.notify_all (); break; } - lm.lock (); _arrived.notify_all (); } } } catch (boost::thread_interrupted) { /* The butler thread is being terminated */ + boost::mutex::scoped_lock lm (_mutex); + _finished = true; + _arrived.notify_all (); } catch (...) { store_current (); - _finished = true; + boost::mutex::scoped_lock lm (_mutex); + _died = true; _arrived.notify_all (); } @@ -117,11 +123,11 @@ Butler::get_video () boost::mutex::scoped_lock lm (_mutex); /* Wait for data if we have none */ - while (_video.empty() && !_finished) { + while (_video.empty() && !_finished && !_died) { _arrived.wait (lm); } - if (_video.empty() && _finished) { + if (_video.empty()) { return make_pair (shared_ptr<PlayerVideo>(), DCPTime()); } @@ -134,6 +140,10 @@ void Butler::seek (DCPTime position, bool accurate) { boost::mutex::scoped_lock lm (_mutex); + if (_died) { + return; + } + _video.clear (); _audio.clear (); _finished = false; diff --git a/src/lib/butler.h b/src/lib/butler.h index 948a78ea5..2cb49c1a6 100644 --- a/src/lib/butler.h +++ b/src/lib/butler.h @@ -65,6 +65,7 @@ private: bool _pending_seek_accurate; bool _finished; + bool _died; AudioMapping _audio_mapping; int _audio_channels; |
