Supporters update.
[dcpomatic.git] / src / lib / player.cc
index c03cb97a59f50ad8549f8142279e48a236a801dc..75f6b7919fd6c02fe0143e9d152917fc7f17ee41 100644 (file)
@@ -251,7 +251,7 @@ have_video (shared_ptr<const Content> content)
 bool
 have_audio (shared_ptr<const Content> content)
 {
-       return static_cast<bool>(content->audio) && content->can_be_played();
+       return content->has_mapped_audio() && content->can_be_played();
 }
 
 
@@ -369,7 +369,7 @@ Player::setup_pieces ()
 
        _stream_states.clear ();
        for (auto i: _pieces) {
-               if (i->content->audio) {
+               if (i->content->has_mapped_audio()) {
                        for (auto j: i->content->audio->streams()) {
                                _stream_states[j] = StreamState(i);
                        }
@@ -688,6 +688,39 @@ Player::set_play_referenced ()
 }
 
 
+pair<shared_ptr<Piece>, optional<DCPTime>>
+Player::earliest_piece_and_time() const
+{
+       auto film = _film.lock();
+       DCPOMATIC_ASSERT(film);
+
+       shared_ptr<Piece> earliest_content;
+       optional<DCPTime> earliest_time;
+
+       for (auto const& piece: _pieces) {
+               if (piece->done) {
+                       continue;
+               }
+
+               auto const t = content_time_to_dcp(piece, max(piece->decoder->position(), piece->content->trim_start()));
+               if (t > piece->content->end(film)) {
+                       piece->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 && !piece->decoder->text.empty())) {
+                               earliest_time = t;
+                               earliest_content = piece;
+                       }
+               }
+       }
+
+       return { earliest_content, earliest_time };
+}
+
+
 bool
 Player::pass ()
 {
@@ -711,26 +744,7 @@ Player::pass ()
 
        shared_ptr<Piece> earliest_content;
        optional<DCPTime> earliest_time;
-
-       for (auto i: _pieces) {
-               if (i->done) {
-                       continue;
-               }
-
-               auto const t = content_time_to_dcp (i, max(i->decoder->position(), i->content->trim_start()));
-               if (t > i->content->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->decoder->text.empty())) {
-                               earliest_time = t;
-                               earliest_content = i;
-                       }
-               }
-       }
+       std::tie(earliest_content, earliest_time) = earliest_piece_and_time();
 
        bool done = false;
 
@@ -1644,3 +1658,30 @@ Player::set_disable_audio_processor()
        _disable_audio_processor = true;
 }
 
+
+Frame
+Player::frames_done() const
+{
+       auto film = _film.lock();
+       DCPOMATIC_ASSERT(film);
+
+       shared_ptr<Piece> earliest_content;
+       optional<DCPTime> earliest_time;
+       std::tie(earliest_content, earliest_time) = earliest_piece_and_time();
+
+       return earliest_time.get_value_or({}).frames_round(film->video_frame_rate());
+}
+
+
+float
+Player::progress() const
+{
+       auto film = _film.lock();
+       DCPOMATIC_ASSERT(film);
+
+       shared_ptr<Piece> earliest_content;
+       optional<DCPTime> earliest_time;
+       std::tie(earliest_content, earliest_time) = earliest_piece_and_time();
+
+       return static_cast<float>(earliest_time.get_value_or({}).get()) / film->length().get();
+}