Clean up access to stuff from Film.
authorCarl Hetherington <cth@carlh.net>
Tue, 19 Nov 2019 16:07:35 +0000 (17:07 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 8 Jan 2020 20:56:47 +0000 (21:56 +0100)
src/lib/film.cc
src/lib/film.h
src/lib/playlist.cc
src/lib/playlist.h
src/wx/film_viewer.cc
src/wx/film_viewer.h
src/wx/gl_video_view.cc
src/wx/gl_video_view.h
src/wx/simple_video_view.cc
src/wx/video_view.cc
src/wx/video_view.h

index 2a50e8c81dd732d360cf2f93147c253d355b7942..aa71834a1f281ebdeaf322cde741951e2b81429d 100644 (file)
@@ -169,6 +169,7 @@ Film::Film (optional<boost::filesystem::path> 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<Content> c, int p, bool
        }
 }
 
+void
+Film::playlist_length_change ()
+{
+       LengthChange ();
+}
+
 void
 Film::playlist_change (ChangeType type)
 {
index 68f8b5334a4f1ec9c6eaff5288d56aecae415d54..c722518805855732bda05fcc06c94427997a6cdb 100644 (file)
@@ -390,6 +390,11 @@ public:
        /** Emitted when some property of our content has changed */
        mutable boost::signals2::signal<void (ChangeType, boost::weak_ptr<Content>, 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<void ()> LengthChange;
+
        /** Emitted when we have something important to tell the user */
        boost::signals2::signal<void (std::string)> Message;
 
@@ -409,6 +414,7 @@ private:
        void playlist_change (ChangeType);
        void playlist_order_changed ();
        void playlist_content_change (ChangeType type, boost::weak_ptr<Content>, int, bool frequent);
+       void playlist_length_change ();
        void maybe_add_content (boost::weak_ptr<Job>, boost::weak_ptr<Content>, 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<boost::signals2::connection> _job_connections;
        std::list<boost::signals2::connection> _audio_analysis_connections;
 
index 9e96c693a529679b197ae66e0ba6c67d8a2fc248..73a3214d30314818016590e0b9aac4dca298fd81 100644 (file)
@@ -113,6 +113,9 @@ Playlist::content_change (weak_ptr<const Film> 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<const Film> film, shared_ptr<Content> c)
        }
 
        Change (CHANGE_TYPE_DONE);
+
+       LengthChange ();
 }
 
 void
@@ -312,6 +317,8 @@ Playlist::remove (shared_ptr<Content> 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
index d7db75d0fb9ed44feccfb7a70a0561780eea5eb6..b6e23b4a5a5d3281c359fd1d3def4765f17264aa 100644 (file)
@@ -78,6 +78,8 @@ public:
        /** Emitted when content has been added to or removed from the playlist; implies OrderChanged */
        mutable boost::signals2::signal<void (ChangeType)> Change;
        mutable boost::signals2::signal<void ()> OrderChanged;
+       /** Emitted when the length might have changed; may sometimes be emitted when it has not */
+       mutable boost::signals2::signal<void ()> LengthChange;
 
        mutable boost::signals2::signal<void (ChangeType, boost::weak_ptr<Content>, int, bool)> ContentChange;
 
index f3250dbfa8f62c5901f036e995204922a5cb1ed2..31093cb0a8581de14087867cbc22608c64d1dc40 100644 (file)
@@ -157,7 +157,6 @@ FilmViewer::set_film (shared_ptr<Film> 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> 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 ()
index eaf46f1e6bbc8474bbc69020e12a0f31e950b828..e42c37a8d4ffab33c7f06aacf165bea4aa44351d 100644 (file)
@@ -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<dcpomatic::DCPTime> audio_time () const;
index c3a6112831750641cedc226733010ba83b70fb94..3cf58757d08bc441c662fb283db28516d9806ae2 100644 (file)
@@ -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());
-}
-
-
index cf42432a94102a4d35db6d1629a5e9ce37279552..73db3535d2775c7fdc84b46482e7a1143948a4fd 100644 (file)
@@ -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<dcp::Size> _size;
        bool _vsync_enabled;
        boost::thread* _thread;
-       mutable boost::mutex _one_shot_mutex;
-       bool _one_shot;
 };
index a00524f7d06617ed85694e3f22f4841479df43b8..dcf30cd1a7bdadc0ad2e19805acb2f51d8d6255e 100644 (file)
@@ -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;
index e1a8b7306681b12972b63abb5c5780f92ef0cf2b..6478ff2a654ada0b0d58ef0ca32c1d1cd3f9fed6 100644 (file)
@@ -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 */
index d9ef2a65f4859afd8a8bea01dd8ef9abd0c8642b..06067130c5a330d64a103b4bd47f0ac75eac514f 100644 (file)
@@ -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<const Film> 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<const Film> 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<const Film> _film;
+       int _video_frame_rate;
+       dcpomatic::DCPTime _length;
 };
 
 #endif