From 65f773f8aad39558b69e8cc73ab4e9bef419496d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 25 Apr 2021 17:45:38 +0200 Subject: Add Piece::decoder_before(). --- src/lib/piece.cc | 41 +++++++++++++++++++++++++---------------- src/lib/piece.h | 3 +-- src/lib/player.cc | 20 ++++---------------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/lib/piece.cc b/src/lib/piece.cc index 2cdc20a50..54d37f453 100644 --- a/src/lib/piece.cc +++ b/src/lib/piece.cc @@ -193,15 +193,6 @@ Piece::decoder_for (shared_ptr content) const } -DCPTime -Piece::decoder_position () const -{ - auto t = content_time_to_dcp(_content, std::max(decoder->position(), _content->trim_start())); - DCPOMATIC_ASSERT (t); - return *t; -} - - void Piece::pass () { @@ -218,13 +209,6 @@ Piece::reference_dcp_audio () const } -bool -Piece::has_text () const -{ - return !decoder->text.empty(); -} - - void Piece::seek (shared_ptr film, DCPTime time, bool accurate) { @@ -246,3 +230,28 @@ Piece::seek (shared_ptr film, DCPTime time, bool accurate) } } + +optional +Piece::decoder_before(shared_ptr film, optional time) +{ + if (done) { + return {}; + } + + auto t = content_time_to_dcp(_content, std::max(decoder->position(), _content->trim_start())); + DCPOMATIC_ASSERT (t); + + if (*t > end(film)) { + done = true; + } else { + /* Given two choices at the same time, pick the one with texts so we see it before + the video. + */ + if (!time || t < *time || (t == *time && !decoder->text.empty())) { + return t; + } + } + + return {}; +} + diff --git a/src/lib/piece.h b/src/lib/piece.h index 56b16fb28..c567a2f7c 100644 --- a/src/lib/piece.h +++ b/src/lib/piece.h @@ -70,9 +70,8 @@ public: std::shared_ptr decoder_for (std::shared_ptr content) const; - dcpomatic::DCPTime decoder_position () const; - bool has_text () const; void seek (std::shared_ptr film, dcpomatic::DCPTime time, bool accurate); + boost::optional decoder_before(std::shared_ptr film, boost::optional time); std::shared_ptr decoder; boost::optional ignore_video; diff --git a/src/lib/player.cc b/src/lib/player.cc index 5951e179d..91d429708 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -598,22 +598,10 @@ Player::pass () optional earliest_time; for (auto i: _pieces) { - if (i->done) { - continue; - } - - auto const t = i->decoder_position (); - if (t > i->end(_film)) { - i->done = true; - } else { - - /* Given two choices at the same time, pick the one with texts so we see it before - the video. - */ - if (!earliest_time || t < *earliest_time || (t == *earliest_time && i->has_text())) { - earliest_time = t; - earliest_content = i; - } + auto time = i->decoder_before(_film, earliest_time); + if (time) { + earliest_time = *time; + earliest_content = i; } } -- cgit v1.2.3