X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Flib%2Fbutler.cc;h=56f8919f5516487742c44b308bf345ceb350d687;hb=a5ea5c0d2637dd41e3d356cb62cac75b8cadf8ce;hp=2b6010aaa6df777498f90a7c969e667670eea623;hpb=63d301ca5f4518c2d559066cc7909e7acb62cd7f;p=dcpomatic.git diff --git a/src/lib/butler.cc b/src/lib/butler.cc index 2b6010aaa..56f8919f5 100644 --- a/src/lib/butler.cc +++ b/src/lib/butler.cc @@ -29,6 +29,7 @@ using std::cout; using std::pair; using std::make_pair; +using std::string; using boost::weak_ptr; using boost::shared_ptr; using boost::bind; @@ -37,11 +38,11 @@ using boost::optional; /** Minimum video readahead in frames */ #define MINIMUM_VIDEO_READAHEAD 10 /** Maximum video readahead in frames; should never be reached unless there are bugs in Player */ -#define MAXIMUM_VIDEO_READAHEAD 240 +#define MAXIMUM_VIDEO_READAHEAD 24 /** Minimum audio readahead in frames */ -#define MINIMUM_AUDIO_READAHEAD (48000*5) +#define MINIMUM_AUDIO_READAHEAD (48000 * MINIMUM_VIDEO_READAHEAD / 24) /** Minimum audio readahead in frames; should never be reached unless there are bugs in Player */ -#define MAXIMUM_AUDIO_READAHEAD (48000*60) +#define MAXIMUM_AUDIO_READAHEAD (48000 * MAXIMUM_VIDEO_READAHEAD / 24) #define LOG_WARNING(...) _log->log (String::compose(__VA_ARGS__), LogEntry::TYPE_WARNING); @@ -59,7 +60,6 @@ Butler::Butler (shared_ptr player, shared_ptr log, AudioMapping aud { _player_video_connection = _player->Video.connect (bind (&Butler::video, this, _1, _2)); _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 @@ -102,12 +102,18 @@ Butler::should_run () const LOG_WARNING ("Butler audio buffers reached %1 frames", _audio.size()); } - return (_video.size() < MINIMUM_VIDEO_READAHEAD || (!_disable_audio && _audio.size() < MINIMUM_AUDIO_READAHEAD)) - && (_video.size() < MAXIMUM_VIDEO_READAHEAD) - && (_audio.size() < MAXIMUM_AUDIO_READAHEAD) - && !_stop_thread - && !_finished - && !_died; + if (_stop_thread || _finished || _died) { + /* Definitely do not run */ + return false; + } + + if (_video.size() < MINIMUM_VIDEO_READAHEAD || (!_disable_audio && _audio.size() < MINIMUM_AUDIO_READAHEAD)) { + /* Definitely do run: we need data */ + return true; + } + + /* Run if we aren't full of video or audio */ + return (_video.size() < MAXIMUM_VIDEO_READAHEAD) && (_audio.size() < MAXIMUM_AUDIO_READAHEAD); } void @@ -231,14 +237,6 @@ Butler::audio (shared_ptr audio) _audio.put (remap (audio, _audio_channels, _audio_mapping)); } -void -Butler::player_changed () -{ - _video.clear (); - _audio.clear (); - _summon.notify_all (); -} - /** Try to get `frames' frames of audio and copy it into `out'. Silence * will be filled if no audio is available. * @return true if there was a buffer underrun, otherwise false. @@ -257,3 +255,10 @@ Butler::disable_audio () boost::mutex::scoped_lock lm (_mutex); _disable_audio = true; } + +pair +Butler::memory_used () const +{ + /* XXX: should also look at _audio.memory_used() */ + return _video.memory_used(); +}