From af0edaf7dcd36c367cb585c98e8413c5347a7386 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 23 Jul 2019 22:55:15 +0100 Subject: [PATCH] Cache film length for Player::pass. --- src/lib/player.cc | 8 ++++++-- src/lib/player.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/player.cc b/src/lib/player.cc index 79db7cc2c..657c1a8b4 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -243,6 +243,9 @@ Player::setup_pieces_unlocked () _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 @@ -564,13 +567,14 @@ bool Player::pass () { boost::mutex::scoped_lock lm (_mutex); + DCPOMATIC_ASSERT (_film_length); 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; @@ -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. */ - DCPTime pull_to = _film->length (); + DCPTime pull_to = *_film_length; for (map::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; diff --git a/src/lib/player.h b/src/lib/player.h index e99c345bb..2fd7c8668 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -206,6 +206,9 @@ private: ActiveText _active_texts[TEXT_COUNT]; boost::shared_ptr _audio_processor; + /* Cached stuff */ + boost::optional _film_length; + boost::signals2::scoped_connection _film_changed_connection; boost::signals2::scoped_connection _playlist_change_connection; boost::signals2::scoped_connection _playlist_content_change_connection; -- 2.30.2