Add Piece:fonts().
[dcpomatic.git] / src / lib / piece.cc
index 2cdc20a5032395a259891a32f20aa733c89166bd..ca92f1db5e036eb7815f61657044d51ede938fab 100644 (file)
@@ -33,6 +33,7 @@
 using std::dynamic_pointer_cast;
 using std::make_shared;
 using std::shared_ptr;
+using std::vector;
 using boost::optional;
 using namespace dcpomatic;
 
@@ -54,7 +55,7 @@ Piece::Piece (shared_ptr<Content> c, shared_ptr<Decoder> d, FrameRateChange f)
 void
 Piece::update_pull_to (DCPTime& pull_to) const
 {
-       if (done) {
+       if (_done) {
                return;
        }
 
@@ -193,20 +194,11 @@ 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 ()
 {
        LOG_DEBUG_PLAYER ("Calling pass() on %1", _content->path(0));
-       done = decoder->pass();
+       _done = decoder->pass();
 }
 
 
@@ -218,13 +210,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)
 {
@@ -235,14 +220,45 @@ Piece::seek (shared_ptr<const Film> film, DCPTime time, bool accurate)
                   been trimmed to a point between keyframes, or something).
                   */
                decoder->seek (dcp_to_content_time(position(), film), true);
-               done = false;
+               _done = false;
        } else if (position() <= time && time < end(film)) {
                /* During; seek to position */
                decoder->seek (dcp_to_content_time(time, film), accurate);
-               done = false;
+               _done = false;
        } else {
                /* After; this piece is done */
-               done = true;
+               _done = true;
        }
 }
 
+
+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 {};
+}
+
+vector<dcpomatic::FontData>
+Piece::fonts () const
+{
+       return decoder->fonts();
+}
+