From 86a866d5f3f5bf2fec67d1c813524479c6727eab Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 19 Nov 2019 17:07:35 +0100 Subject: [PATCH] Clean up access to stuff from Film. --- src/lib/film.cc | 7 +++++++ src/lib/film.h | 7 +++++++ src/lib/playlist.cc | 11 +++++++++- src/lib/playlist.h | 2 ++ src/wx/film_viewer.cc | 16 +++++++++++++-- src/wx/film_viewer.h | 1 + src/wx/gl_video_view.cc | 40 ++++--------------------------------- src/wx/gl_video_view.h | 5 ----- src/wx/simple_video_view.cc | 4 ++-- src/wx/video_view.cc | 2 +- src/wx/video_view.h | 22 ++++++++++++++------ 11 files changed, 64 insertions(+), 53 deletions(-) diff --git a/src/lib/film.cc b/src/lib/film.cc index 2a50e8c81..aa71834a1 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -169,6 +169,7 @@ Film::Film (optional dir) _playlist_change_connection = _playlist->Change.connect (bind (&Film::playlist_change, this, _1)); _playlist_order_changed_connection = _playlist->OrderChanged.connect (bind (&Film::playlist_order_changed, this)); _playlist_content_change_connection = _playlist->ContentChange.connect (bind (&Film::playlist_content_change, this, _1, _2, _3, _4)); + _playlist_length_change_connection = _playlist->LengthChange.connect (bind(&Film::playlist_length_change, this)); if (dir) { /* Make state.directory a complete path without ..s (where possible) @@ -1292,6 +1293,12 @@ Film::playlist_content_change (ChangeType type, weak_ptr c, int p, bool } } +void +Film::playlist_length_change () +{ + LengthChange (); +} + void Film::playlist_change (ChangeType type) { diff --git a/src/lib/film.h b/src/lib/film.h index 68f8b5334..c72251880 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -390,6 +390,11 @@ public: /** Emitted when some property of our content has changed */ mutable boost::signals2::signal, int, bool)> ContentChange; + /** Emitted when the film's length might have changed; this is not like a normal + property as its value is derived from the playlist, so it has its own signal. + */ + mutable boost::signals2::signal LengthChange; + /** Emitted when we have something important to tell the user */ boost::signals2::signal Message; @@ -409,6 +414,7 @@ private: void playlist_change (ChangeType); void playlist_order_changed (); void playlist_content_change (ChangeType type, boost::weak_ptr, int, bool frequent); + void playlist_length_change (); void maybe_add_content (boost::weak_ptr, boost::weak_ptr, bool disable_audio_analysis); void audio_analysis_finished (); void check_settings_consistency (); @@ -486,6 +492,7 @@ private: 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; std::list _job_connections; std::list _audio_analysis_connections; diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 9e96c693a..73a3214d3 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -113,6 +113,9 @@ Playlist::content_change (weak_ptr weak_film, ChangeType type, weak_ if (changed) { OrderChanged (); } + + /* The length might have changed, and that's good enough for this signal */ + LengthChange (); } } @@ -281,6 +284,8 @@ Playlist::add (shared_ptr film, shared_ptr c) } Change (CHANGE_TYPE_DONE); + + LengthChange (); } void @@ -312,6 +317,8 @@ Playlist::remove (shared_ptr c) } /* This won't change order, so it does not need a sort */ + + LengthChange (); } void @@ -334,9 +341,11 @@ Playlist::remove (ContentList c) } } + Change (CHANGE_TYPE_DONE); + /* This won't change order, so it does not need a sort */ - Change (CHANGE_TYPE_DONE); + LengthChange (); } class FrameRateCandidate diff --git a/src/lib/playlist.h b/src/lib/playlist.h index d7db75d0f..b6e23b4a5 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -78,6 +78,8 @@ public: /** Emitted when content has been added to or removed from the playlist; implies OrderChanged */ mutable boost::signals2::signal Change; mutable boost::signals2::signal OrderChanged; + /** Emitted when the length might have changed; may sometimes be emitted when it has not */ + mutable boost::signals2::signal LengthChange; mutable boost::signals2::signal, int, bool)> ContentChange; diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index f3250dbfa..31093cb0a 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -157,7 +157,6 @@ FilmViewer::set_film (shared_ptr film) _film = film; - _video_view->set_film (_film); _video_view->clear (); _closed_captions_dialog->clear (); @@ -184,6 +183,7 @@ FilmViewer::set_film (shared_ptr film) _player->set_play_referenced (); _film->Change.connect (boost::bind (&FilmViewer::film_change, this, _1, _2)); + _film->LengthChange.connect (boost::bind(&FilmViewer::film_length_change, this)); _player->Change.connect (boost::bind (&FilmViewer::player_change, this, _1, _2, _3)); /* Keep about 1 second's worth of history samples */ @@ -384,11 +384,23 @@ FilmViewer::player_change (ChangeType type, int property, bool frequent) void FilmViewer::film_change (ChangeType type, Film::Property p) { - if (type == CHANGE_TYPE_DONE && p == Film::AUDIO_CHANNELS) { + if (type != CHANGE_TYPE_DONE) { + return; + } + + if (p == Film::AUDIO_CHANNELS) { recreate_butler (); + } else if (p == Film::VIDEO_FRAME_RATE) { + _video_view->set_video_frame_rate (_film->video_frame_rate()); } } +void +FilmViewer::film_length_change () +{ + _video_view->set_length (_film->length()); +} + /** Re-get the current frame slowly by seeking */ void FilmViewer::slow_refresh () diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index eaf46f1e6..e42c37a8d 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -165,6 +165,7 @@ private: void film_change (ChangeType, Film::Property); void recreate_butler (); void config_changed (Config::Property); + void film_length_change (); dcpomatic::DCPTime time () const; boost::optional audio_time () const; diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index c3a611283..3cf58757d 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -55,7 +55,6 @@ GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent) : VideoView (viewer) , _vsync_enabled (false) , _thread (0) - , _one_shot (false) { _canvas = new wxGLCanvas (parent, wxID_ANY, 0, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE); _canvas->Bind (wxEVT_PAINT, boost::bind(&GLVideoView::paint, this)); @@ -278,20 +277,6 @@ GLVideoView::stop () _thread = 0; } -bool -GLVideoView::one_shot () const -{ - boost::mutex::scoped_lock lm (_one_shot_mutex); - return _one_shot; -} - -void -GLVideoView::set_one_shot (bool s) -{ - boost::mutex::scoped_lock lm (_one_shot_mutex); - _one_shot = s; -} - void GLVideoView::thread () try @@ -303,20 +288,12 @@ try _canvas->SetCurrent (*_context); } - while (true) { - if (!film() && !one_shot()) { - /* XXX: this should be an indefinite wait until - one of our conditions becomes true. - */ - dcpomatic_sleep_milliseconds (40); - continue; - } - - set_one_shot (false); + std::cout << "Here we go " << video_frame_rate() << " " << to_string(length()) << "\n"; + while (true) { dcpomatic::DCPTime const next = position() + one_video_frame(); - if (next >= film()->length()) { + if (next >= length()) { _viewer->stop (); _viewer->emit_finished (); continue; @@ -359,15 +336,6 @@ GLVideoView::context () const bool GLVideoView::display_next_frame (bool non_blocking) { - bool const g = get_next_frame (non_blocking); - set_one_shot (true); - return g; + return get_next_frame (non_blocking); } -dcpomatic::DCPTime -GLVideoView::one_video_frame () const -{ - return dcpomatic::DCPTime::from_frames (1, film()->video_frame_rate()); -} - - diff --git a/src/wx/gl_video_view.h b/src/wx/gl_video_view.h index cf42432a9..73db3535d 100644 --- a/src/wx/gl_video_view.h +++ b/src/wx/gl_video_view.h @@ -53,9 +53,6 @@ private: void draw (); void thread (); wxGLContext* context () const; - bool one_shot () const; - void set_one_shot (bool s); - dcpomatic::DCPTime one_video_frame () const; wxGLCanvas* _canvas; @@ -66,6 +63,4 @@ private: boost::optional _size; bool _vsync_enabled; boost::thread* _thread; - mutable boost::mutex _one_shot_mutex; - bool _one_shot; }; diff --git a/src/wx/simple_video_view.cc b/src/wx/simple_video_view.cc index a00524f7d..dcf30cd1a 100644 --- a/src/wx/simple_video_view.cc +++ b/src/wx/simple_video_view.cc @@ -145,14 +145,14 @@ SimpleVideoView::update () void SimpleVideoView::timer () { - if (!film() || !_viewer->playing()) { + if (!_viewer->playing()) { return; } display_next_frame (false); DCPTime const next = _viewer->position() + _viewer->one_video_frame(); - if (next >= film()->length()) { + if (next >= length()) { _viewer->stop (); _viewer->Finished (); return; diff --git a/src/wx/video_view.cc b/src/wx/video_view.cc index e1a8b7306..6478ff2a6 100644 --- a/src/wx/video_view.cc +++ b/src/wx/video_view.cc @@ -67,7 +67,7 @@ VideoView::get_next_frame (bool non_blocking) dcpomatic::DCPTime VideoView::one_video_frame () const { - return dcpomatic::DCPTime::from_frames (1, film()->video_frame_rate()); + return dcpomatic::DCPTime::from_frames (1, video_frame_rate()); } /* XXX_b: comment */ diff --git a/src/wx/video_view.h b/src/wx/video_view.h index d9ef2a65f..06067130c 100644 --- a/src/wx/video_view.h +++ b/src/wx/video_view.h @@ -39,6 +39,7 @@ public: #ifdef DCPOMATIC_VARIANT_SWAROOP , _in_watermark (false) #endif + , _video_frame_rate (0) {} virtual ~VideoView () {} @@ -66,9 +67,14 @@ public: return _player_video.second; } - void set_film (boost::shared_ptr film) { + void set_video_frame_rate (int r) { boost::mutex::scoped_lock lm (_mutex); - _film = film; + _video_frame_rate = r; + } + + void set_length (dcpomatic::DCPTime len) { + boost::mutex::scoped_lock lm (_mutex); + _length = len; } protected: @@ -78,10 +84,13 @@ protected: bool get_next_frame (bool non_blocking); int time_until_next_frame () const; dcpomatic::DCPTime one_video_frame () const; - - boost::shared_ptr film () const { + int video_frame_rate () const { + boost::mutex::scoped_lock lm (_mutex); + return _video_frame_rate; + } + dcpomatic::DCPTime length () const { boost::mutex::scoped_lock lm (_mutex); - return _film; + return _length; } FilmViewer* _viewer; @@ -97,7 +106,8 @@ protected: #endif private: - boost::shared_ptr _film; + int _video_frame_rate; + dcpomatic::DCPTime _length; }; #endif -- 2.30.2