summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-04-25 17:45:38 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-07 09:29:59 +0200
commit65f773f8aad39558b69e8cc73ab4e9bef419496d (patch)
treefffc3bdb2c3fba6de05934e97b2cb1525f7a0290
parentca3343840b28c258c91635cedc133ee064d9d03d (diff)
Add Piece::decoder_before().
-rw-r--r--src/lib/piece.cc41
-rw-r--r--src/lib/piece.h3
-rw-r--r--src/lib/player.cc20
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> 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<const Film> film, DCPTime time, bool accurate)
{
@@ -246,3 +230,28 @@ Piece::seek (shared_ptr<const Film> film, DCPTime time, bool accurate)
}
}
+
+optional<dcpomatic::DCPTime>
+Piece::decoder_before(shared_ptr<const Film> film, optional<dcpomatic::DCPTime> 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> decoder_for (std::shared_ptr<Content> content) const;
- dcpomatic::DCPTime decoder_position () const;
- bool has_text () const;
void seek (std::shared_ptr<const Film> film, dcpomatic::DCPTime time, bool accurate);
+ boost::optional<dcpomatic::DCPTime> decoder_before(std::shared_ptr<const Film> film, boost::optional<dcpomatic::DCPTime> time);
std::shared_ptr<Decoder> decoder;
boost::optional<dcpomatic::DCPTimePeriod> 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<DCPTime> 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;
}
}