Cache film length for Player::pass.
authorCarl Hetherington <cth@carlh.net>
Tue, 23 Jul 2019 21:55:15 +0000 (22:55 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 25 Jan 2020 00:47:00 +0000 (01:47 +0100)
src/lib/player.cc
src/lib/player.h

index 79db7cc2c76d1695ac3201a09a1a470ecc360b30..657c1a8b4ed9e2d168a2ffdbc156b46704824545 100644 (file)
@@ -243,6 +243,9 @@ Player::setup_pieces_unlocked ()
        _last_video_time = DCPTime ();
        _last_video_eyes = EYES_BOTH;
        _last_audio_time = DCPTime ();
        _last_video_time = DCPTime ();
        _last_video_eyes = EYES_BOTH;
        _last_audio_time = DCPTime ();
+
+       /* Cached value to save recalculating it on every ::pass */
+       _film_length = _film->length ();
 }
 
 void
 }
 
 void
@@ -564,13 +567,14 @@ bool
 Player::pass ()
 {
        boost::mutex::scoped_lock lm (_mutex);
 Player::pass ()
 {
        boost::mutex::scoped_lock lm (_mutex);
+       DCPOMATIC_ASSERT (_film_length);
 
        if (_suspended) {
                /* We can't pass in this state */
                return false;
        }
 
 
        if (_suspended) {
                /* We can't pass in this state */
                return false;
        }
 
-       if (_playlist->length(_film) == DCPTime()) {
+       if (*_film_length == DCPTime()) {
                /* Special case of an empty Film; just give one black frame */
                emit_video (black_player_video_frame(EYES_BOTH), DCPTime());
                return true;
                /* Special case of an empty Film; just give one black frame */
                emit_video (black_player_video_frame(EYES_BOTH), DCPTime());
                return true;
@@ -677,7 +681,7 @@ Player::pass ()
        /* Work out the time before which the audio is definitely all here.  This is the earliest last_push_end of one
           of our streams, or the position of the _silent.
        */
        /* Work out the time before which the audio is definitely all here.  This is the earliest last_push_end of one
           of our streams, or the position of the _silent.
        */
-       DCPTime pull_to = _film->length ();
+       DCPTime pull_to = *_film_length;
        for (map<AudioStreamPtr, StreamState>::const_iterator i = _stream_states.begin(); i != _stream_states.end(); ++i) {
                if (!i->second.piece->done && i->second.last_push_end < pull_to) {
                        pull_to = i->second.last_push_end;
        for (map<AudioStreamPtr, StreamState>::const_iterator i = _stream_states.begin(); i != _stream_states.end(); ++i) {
                if (!i->second.piece->done && i->second.last_push_end < pull_to) {
                        pull_to = i->second.last_push_end;
index e99c345bb211ea99d683fcb5b3d32513305ad4c9..2fd7c8668a914125dc6308968393d3bf1d79c806 100644 (file)
@@ -206,6 +206,9 @@ private:
        ActiveText _active_texts[TEXT_COUNT];
        boost::shared_ptr<AudioProcessor> _audio_processor;
 
        ActiveText _active_texts[TEXT_COUNT];
        boost::shared_ptr<AudioProcessor> _audio_processor;
 
+       /* Cached stuff */
+       boost::optional<dcpomatic::DCPTime> _film_length;
+
        boost::signals2::scoped_connection _film_changed_connection;
        boost::signals2::scoped_connection _playlist_change_connection;
        boost::signals2::scoped_connection _playlist_content_change_connection;
        boost::signals2::scoped_connection _film_changed_connection;
        boost::signals2::scoped_connection _playlist_change_connection;
        boost::signals2::scoped_connection _playlist_content_change_connection;