From 5afbd563b1aa1fa79cc8d225297ae9e7f48fbaff Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 27 Oct 2025 22:44:58 +0100 Subject: wip: Use new signal handling for Playlist. --- src/lib/film.cc | 48 ++++++++++++++++++++++++++++++++---------------- src/lib/film.h | 17 +++++++++++++---- src/lib/player.cc | 2 +- src/lib/playlist.h | 9 ++++----- 4 files changed, 50 insertions(+), 26 deletions(-) (limited to 'src/lib') diff --git a/src/lib/film.cc b/src/lib/film.cc index c6a6f3cce..6ae33f9f2 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -212,10 +212,10 @@ Film::Film(optional dir) _video_bit_rate[encoding] = Config::instance()->default_video_bit_rate(encoding); } - _playlist_change_connection = _playlist->Change.connect(bind(&Film::playlist_change, this, _1)); - _playlist_order_changed_connection = _playlist->OrderChange.connect(bind(&Film::playlist_order_changed, this)); - _playlist_content_change_connection = _playlist->ContentChange.connect(bind(&Film::playlist_content_change, this, _1, _2, _3)); - _playlist_length_change_connection = _playlist->LengthChange.connect(bind(&Film::playlist_length_change, this)); + _playlist_change_connection = _playlist->Change.connect_same_thread(bind(&Film::playlist_change, this, _1)); + _playlist_order_changed_connection = _playlist->OrderChange.connect_same_thread(bind(&Film::playlist_order_changed, this)); + _playlist_content_change_connection = _playlist->ContentChange.connect_same_thread(bind(&Film::playlist_content_change, this, _1, _2, _3)); + _playlist_length_change_connection = _playlist->LengthChange.connect_same_thread(bind(&Film::playlist_length_change, this)); if (dir) { _directory = dcp::filesystem::weakly_canonical(*dir); @@ -430,7 +430,7 @@ Film::metadata(bool with_content_paths) const cxml::add_text_child(root, "CustomReelBoundary", fmt::to_string(boundary.get())); } cxml::add_text_child(root, "ReencodeJ2K", _reencode_j2k ? "1" : "0"); - cxml::add_text_child(root, "UserExplicitVideoFrameRate", _user_explicit_video_frame_rate ? "1" : "0"); + cxml::add_text_child(root, "UserExplicitVideoFrameRate", user_explicit_video_frame_rate() ? "1" : "0"); for (auto const& marker: _markers) { auto m = cxml::add_child(root, "Marker"); m->set_attribute("type", dcp::marker_to_string(marker.first)); @@ -1220,14 +1220,21 @@ Film::set_video_bit_rate(VideoEncoding encoding, int64_t bit_rate) void Film::set_video_frame_rate(int f, bool user_explicit) { - if (_video_frame_rate == f) { - return; + { + boost::mutex::scoped_lock lm(_mutex); + if (_video_frame_rate == f) { + return; + } } FilmChangeSignaller ch(this, FilmProperty::VIDEO_FRAME_RATE); - _video_frame_rate = f; - if (user_explicit) { - _user_explicit_video_frame_rate = true; + + { + boost::mutex::scoped_lock lm(_mutex); + _video_frame_rate = f; + if (user_explicit) { + _user_explicit_video_frame_rate = true; + } } } @@ -1314,12 +1321,16 @@ Film::set_reencode_j2k(bool r) _reencode_j2k = r; } + +/** Can be called from any thread */ void Film::signal_change(ChangeType type, int p) { signal_change(type, static_cast(p)); } + +/** Can be called from any thread */ void Film::signal_change(ChangeType type, FilmProperty p) { @@ -1327,7 +1338,7 @@ Film::signal_change(ChangeType type, FilmProperty p) set_dirty(true); if (p == FilmProperty::CONTENT) { - if (!_user_explicit_video_frame_rate) { + if (!user_explicit_video_frame_rate()) { set_video_frame_rate(best_video_frame_rate()); } } @@ -1784,7 +1795,7 @@ Film::check_settings_consistency() void Film::playlist_order_changed() { - /* XXX: missing PENDING */ + signal_change(ChangeType::PENDING, FilmProperty::CONTENT_ORDER); signal_change(ChangeType::DONE, FilmProperty::CONTENT_ORDER); } @@ -2374,12 +2385,17 @@ Film::set_sign_language_video_language(optional lang) void -Film::set_dirty(bool dirty) +Film::set_dirty(bool dirty_) { - auto const changed = dirty != _dirty; - _dirty = dirty; + bool changed = false; + { + boost::mutex::scoped_lock lm(_mutex); + changed = dirty_ != _dirty; + _dirty = dirty_; + } + if (changed) { - emit(boost::bind(boost::ref(DirtyChange), _dirty)); + emit(boost::bind(boost::ref(DirtyChange), dirty())); } } diff --git a/src/lib/film.h b/src/lib/film.h index 8574c700f..d6c6e945b 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -39,6 +39,7 @@ #include "ratio.h" #include "remembered_asset.h" #include "resolution.h" +#include "signal.h" #include "signaller.h" #include "territory_type.h" #include "transcode_job.h" @@ -133,6 +134,7 @@ public: /** @return true if our state has changed since we last saved it */ bool dirty() const { + boost::mutex::scoped_lock lm(_mutex); return _dirty; } @@ -486,10 +488,17 @@ private: void check_reel_boundaries_for_atmos(); std::vector reels_for_type(ReelType type) const; + bool user_explicit_video_frame_rate() const { + boost::mutex::scoped_lock lm(_mutex); + return _user_explicit_video_frame_rate; + } + /** Log to write to */ std::shared_ptr _log; std::shared_ptr _playlist; + mutable boost::mutex _mutex; + /** Complete path to directory containing the film metadata; * must not be relative. */ @@ -570,10 +579,10 @@ private: std::map _ui_state; - boost::signals2::scoped_connection _playlist_change_connection; - boost::signals2::scoped_connection _playlist_order_changed_connection; - boost::signals2::scoped_connection _playlist_content_change_connection; - boost::signals2::scoped_connection _playlist_length_change_connection; + ScopedConnection _playlist_change_connection; + ScopedConnection _playlist_order_changed_connection; + ScopedConnection _playlist_content_change_connection; + ScopedConnection _playlist_length_change_connection; std::list _job_connections; std::list _audio_analysis_connections; diff --git a/src/lib/player.cc b/src/lib/player.cc index 878a802f6..58e49c921 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -143,7 +143,7 @@ Player::connect() /* The butler must hear about this first, so since we are proxying this through to the butler we must be first. */ - _playlist_change_connection = playlist()->Change.connect(bind(&Player::playlist_change, this, _1), boost::signals2::at_front); + _playlist_change_connection = playlist()->Change.connect_same_thread(bind(&Player::playlist_change, this, _1), boost::signals2::at_front); _playlist_content_change_connection = playlist()->ContentChange.connect(bind(&Player::playlist_content_change, this, _1, _2, _3)); } diff --git a/src/lib/playlist.h b/src/lib/playlist.h index ca4a80bbf..d3fff1fdb 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -30,7 +30,6 @@ #include "signal.h" #include "types.h" #include -#include #include #include @@ -83,12 +82,12 @@ public: void repeat(std::shared_ptr film, ContentList, int); /** Emitted when content has been added to or removed from the playlist; implies OrderChange */ - mutable boost::signals2::signal Change; - mutable boost::signals2::signal OrderChange; + mutable Signal Change; + mutable Signal OrderChange; /** Emitted when the length might have changed; may sometimes be emitted when it has not */ - mutable boost::signals2::signal LengthChange; + mutable Signal LengthChange; - mutable boost::signals2::signal ContentChange; + mutable Signal ContentChange; private: void content_change(std::weak_ptr, ChangeType, int, bool); -- cgit v1.2.3