diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/butler.cc | 28 | ||||
| -rw-r--r-- | src/lib/butler.h | 5 | ||||
| -rw-r--r-- | src/lib/change_signaller.cc | 24 | ||||
| -rw-r--r-- | src/lib/change_signaller.h | 7 | ||||
| -rw-r--r-- | src/lib/content.cc | 2 | ||||
| -rw-r--r-- | src/lib/film.cc | 4 | ||||
| -rw-r--r-- | src/lib/player.cc | 6 | ||||
| -rw-r--r-- | src/lib/player_video.cc | 18 | ||||
| -rw-r--r-- | src/lib/player_video.h | 2 | ||||
| -rw-r--r-- | src/lib/playlist.cc | 4 | ||||
| -rw-r--r-- | src/lib/signal_manager.h | 3 | ||||
| -rw-r--r-- | src/lib/timer.cc | 50 | ||||
| -rw-r--r-- | src/lib/timer.h | 16 | ||||
| -rw-r--r-- | src/lib/wscript | 1 |
14 files changed, 136 insertions, 34 deletions
diff --git a/src/lib/butler.cc b/src/lib/butler.cc index dd9874587..5fd695a94 100644 --- a/src/lib/butler.cc +++ b/src/lib/butler.cc @@ -88,6 +88,7 @@ Butler::Butler ( , _alignment (alignment) , _fast (fast) , _prepare_only_proxy (prepare_only_proxy) + , _lookahead(false) { _player_video_connection = _player.Video.connect(bind(&Butler::video, this, _1, _2)); _player_audio_connection = _player.Audio.connect(bind(&Butler::audio, this, _1, _2, _3)); @@ -107,7 +108,7 @@ Butler::Butler ( LOG_TIMING("start-prepare-threads %1", boost::thread::hardware_concurrency() * 2); - for (size_t i = 0; i < boost::thread::hardware_concurrency() * 2; ++i) { + for (size_t i = 0; i < boost::thread::hardware_concurrency() / 2; ++i) { _prepare_pool.create_thread (bind (&boost::asio::io_service::run, &_prepare_service)); } } @@ -200,6 +201,7 @@ try /* Do any seek that has been requested */ if (_pending_seek_position) { _finished = false; + std::cout << "-------------------------------- seek " << to_string(*_pending_seek_position) << " " << _pending_seek_accurate << "\n"; _player.seek(*_pending_seek_position, _pending_seek_accurate); _pending_seek_position = optional<DCPTime> (); } @@ -322,11 +324,12 @@ void Butler::prepare (weak_ptr<PlayerVideo> weak_video) try { - auto video = weak_video.lock (); /* If the weak_ptr cannot be locked the video obviously no longer requires any work */ - if (video) { + if (auto video = weak_video.lock()) { LOG_TIMING("start-prepare in %1", thread_id()); + std::cout << "SPREP.\n"; video->prepare (_pixel_format, _video_range, _alignment, _fast, _prepare_only_proxy); + std::cout << "FPREP.\n"; LOG_TIMING("finish-prepare in %1", thread_id()); } } @@ -355,7 +358,10 @@ Butler::video (shared_ptr<PlayerVideo> video, DCPTime time) return; } - _prepare_service.post (bind(&Butler::prepare, this, weak_ptr<PlayerVideo>(video))); + std::cout << "POST " << to_string(time) << " to prep service.\n"; + // if (_lookahead) { + _prepare_service.post(bind(&Butler::prepare, this, weak_ptr<PlayerVideo>(video))); + // } _video.put (video, time); } @@ -481,3 +487,17 @@ Butler::Error::summary () const return ""; } + +void +Butler::enable_lookahead() +{ + _lookahead = true; +} + + +void +Butler::disable_lookahead() +{ + _lookahead = false; +} + diff --git a/src/lib/butler.h b/src/lib/butler.h index 6bb0467af..bc6d7485a 100644 --- a/src/lib/butler.h +++ b/src/lib/butler.h @@ -95,6 +95,9 @@ public: std::pair<size_t, std::string> memory_used () const; + void enable_lookahead(); + void disable_lookahead(); + private: void thread (); void video (std::shared_ptr<PlayerVideo> video, dcpomatic::DCPTime time); @@ -152,6 +155,8 @@ private: */ boost::optional<dcpomatic::DCPTime> _awaiting; + boost::atomic<bool> _lookahead; + boost::signals2::scoped_connection _player_video_connection; boost::signals2::scoped_connection _player_audio_connection; boost::signals2::scoped_connection _player_text_connection; diff --git a/src/lib/change_signaller.cc b/src/lib/change_signaller.cc deleted file mode 100644 index a1f093d14..000000000 --- a/src/lib/change_signaller.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> - - This file is part of DCP-o-matic. - - DCP-o-matic is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - DCP-o-matic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. - -*/ - - -#include "change_signaller.h" - - diff --git a/src/lib/change_signaller.h b/src/lib/change_signaller.h index 0b2c1539d..f66e83ff6 100644 --- a/src/lib/change_signaller.h +++ b/src/lib/change_signaller.h @@ -23,9 +23,12 @@ #define DCPOMATIC_CHANGE_SIGNALLER_H +#include "timer.h" #include <boost/thread.hpp> #include <vector> +#include <iostream> + enum class ChangeType { @@ -73,6 +76,7 @@ public: boost::mutex::scoped_lock lm(_mutex); _pending.push_back(signal); } else { + GlobalTimer::instance()->mark("signalled"); signal.thing->signal_change(signal.type, signal.property); } } @@ -128,6 +132,9 @@ public: ~ChangeSignaller () { + if (static_cast<int>(_property) == 401) { + GlobalTimer::instance()->mark("signal_change 401"); + } ChangeSignalDespatcher<T, P>::instance()->signal_change({_thing, _property, _done ? ChangeType::DONE : ChangeType::CANCELLED}); } diff --git a/src/lib/content.cc b/src/lib/content.cc index 5e6dd7e31..91574a669 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -204,10 +204,12 @@ Content::examine(shared_ptr<const Film>, shared_ptr<Job> job, bool) void Content::signal_change (ChangeType c, int p) { + std::cout << "Content::signal_change " << p << " " << static_cast<int>(c) << "\n"; try { if (c == ChangeType::PENDING || c == ChangeType::CANCELLED) { Change (c, shared_from_this(), p, _change_signals_frequent); } else { + PeriodTimer timer("emit"); emit (boost::bind (boost::ref(Change), c, shared_from_this(), p, _change_signals_frequent)); } } catch (std::bad_weak_ptr &) { diff --git a/src/lib/film.cc b/src/lib/film.cc index 9c0637dbb..0db103969 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1578,12 +1578,12 @@ Film::playlist_content_change (ChangeType type, weak_ptr<Content> c, int p, bool } if (type == ChangeType::DONE) { - emit (boost::bind (boost::ref (ContentChange), type, c, p, frequent)); + // emit (boost::bind (boost::ref (ContentChange), type, c, p, frequent)); if (!frequent) { check_settings_consistency (); } } else { - ContentChange (type, c, p, frequent); + // ContentChange (type, c, p, frequent); } set_dirty (true); diff --git a/src/lib/player.cc b/src/lib/player.cc index 7048435b5..a4912ce61 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -255,6 +255,8 @@ have_audio (shared_ptr<const Content> content) void Player::setup_pieces () { + std::cout << "setup pieces.\n"; + boost::mutex::scoped_lock lm (_mutex); auto old_pieces = _pieces; @@ -416,6 +418,10 @@ Player::setup_pieces () void Player::playlist_content_change (ChangeType type, int property, bool frequent) { + if (frequent) { + return; + } + auto film = _film.lock(); if (!film) { return; diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index b2da6c33b..b3fc57c74 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -115,13 +115,27 @@ PlayerVideo::set_text (PositionImage image) } +bool +PlayerVideo::have_image() const +{ + boost::mutex::scoped_lock lm (_mutex); + return have_image_unlocked(); +} + + +bool +PlayerVideo::have_image_unlocked() const +{ + return _image && _crop == _image_crop && _inter_size == _image_inter_size && _out_size == _image_out_size && _fade == _image_fade; +} + + shared_ptr<Image> PlayerVideo::image (function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, bool fast) const { /* XXX: this assumes that image() and prepare() are only ever called with the same parameters (except crop, inter size, out size, fade) */ - boost::mutex::scoped_lock lm (_mutex); - if (!_image || _crop != _image_crop || _inter_size != _image_inter_size || _out_size != _image_out_size || _fade != _image_fade) { + if (!have_image_unlocked()) { make_image (pixel_format, video_range, fast); } return _image; diff --git a/src/lib/player_video.h b/src/lib/player_video.h index e2968749c..e27975932 100644 --- a/src/lib/player_video.h +++ b/src/lib/player_video.h @@ -75,6 +75,7 @@ public: return _text; } + bool have_image() const; void prepare (std::function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, Image::Alignment alignment, bool fast, bool proxy_only); std::shared_ptr<Image> image (std::function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, bool fast) const; std::shared_ptr<const Image> raw_image () const; @@ -128,6 +129,7 @@ public: private: void make_image (std::function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, bool fast) const; + bool have_image_unlocked() const; std::shared_ptr<const ImageProxy> _in; Crop _crop; diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index a0d7d6531..f50285681 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -96,6 +96,7 @@ Playlist::content_change (weak_ptr<const Film> weak_film, ChangeType type, weak_ DCPOMATIC_ASSERT (film); if (type == ChangeType::DONE) { + PeriodTimer timer("content_change#1 in Playlist"); if ( property == ContentProperty::TRIM_START || property == ContentProperty::TRIM_END || @@ -116,6 +117,7 @@ Playlist::content_change (weak_ptr<const Film> weak_film, ChangeType type, weak_ property == ContentProperty::TRIM_START || property == ContentProperty::TRIM_END) { + bool changed = false; { @@ -134,6 +136,8 @@ Playlist::content_change (weak_ptr<const Film> weak_film, ChangeType type, weak_ } } + + PeriodTimer timer("content_change#2 in Playlist"); ContentChange (type, content, property, frequent); } diff --git a/src/lib/signal_manager.h b/src/lib/signal_manager.h index 99e3b5c52..853c473c7 100644 --- a/src/lib/signal_manager.h +++ b/src/lib/signal_manager.h @@ -27,6 +27,8 @@ #include <boost/asio.hpp> #include <boost/thread.hpp> +#include <iostream> + class Signaller; @@ -85,6 +87,7 @@ private: store_current (); } } else { + std::cout << "[[waiting]]\n"; /* non-UI thread; post to the service and wake up the UI */ _service.post (f); wake_ui (); diff --git a/src/lib/timer.cc b/src/lib/timer.cc index caef89e0e..46766d70f 100644 --- a/src/lib/timer.cc +++ b/src/lib/timer.cc @@ -27,6 +27,7 @@ #include "compose.hpp" #include "timer.h" #include "util.h" +#include <fmt/format.h> #include <sys/time.h> #include <iostream> @@ -41,6 +42,9 @@ using std::string; using boost::optional; +GlobalTimer* GlobalTimer::_instance = nullptr; + + /** @param n Name to use when giving output */ PeriodTimer::PeriodTimer (string n) : _name (n) @@ -54,7 +58,7 @@ PeriodTimer::~PeriodTimer () { struct timeval stop; gettimeofday (&stop, 0); - cout << N_("T: ") << _name << N_(": ") << (seconds (stop) - seconds (_start)) << N_("\n"); + cout << fmt::format("T: {}: {:.3f}\n", _name, seconds(stop) - seconds(_start)); } @@ -143,3 +147,47 @@ StateTimer::~StateTimer () cout << N_("\t") << i.second << "\n"; } } + + +GlobalTimer* +GlobalTimer::instance() +{ + if (!_instance) { + _instance = new GlobalTimer(); + } + + return _instance; +} + + +void +GlobalTimer::reset() +{ + struct timeval now; + gettimeofday(&now, 0); + _reset = _last = seconds(now); + // std::cout << "|----------------------\\\n"; +} + + +void +GlobalTimer::mark(string const& tag) +{ + // std::cout << "|" << tag << " "; + + struct timeval now; + gettimeofday(&now, 0); + auto const now_seconds = seconds(now); + + if (_last > 0) { + // std::cout << fmt::format("{:.2} ", now_seconds - _last); + } + + if (_reset > 0) { + // std::cout << fmt::format("{:.2} ", now_seconds - _reset); + } + + _last = now_seconds; + // std::cout << "\n"; +} + diff --git a/src/lib/timer.h b/src/lib/timer.h index be3706607..e60b1a8ba 100644 --- a/src/lib/timer.h +++ b/src/lib/timer.h @@ -105,4 +105,20 @@ private: }; +class GlobalTimer +{ +public: + void mark(std::string const& tag); + void reset(); + + static GlobalTimer* instance(); + +private: + static GlobalTimer* _instance; + + double _reset = 0; + double _last = 0; +}; + + #endif diff --git a/src/lib/wscript b/src/lib/wscript index 8a4b17dbc..0f5a23521 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -51,7 +51,6 @@ sources = """ check_content_job.cc cinema_list.cc cinema_sound_processor.cc - change_signaller.cc collator.cc colour_conversion.cc config.cc |
