Get DCP transcode progress from the player (#2804).
authorCarl Hetherington <cth@carlh.net>
Sun, 12 May 2024 13:22:28 +0000 (15:22 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 15 May 2024 21:49:51 +0000 (23:49 +0200)
src/lib/dcp_encoder.cc
src/lib/player.cc
src/lib/player.h

index 9a840c8ab916b6a594f4e6881f223ad20346f4f5..c7ee180e11f0da9bec17c26b76c1cac7f7656c95 100644 (file)
@@ -159,5 +159,5 @@ DCPEncoder::current_rate () const
 Frame
 DCPEncoder::frames_done () const
 {
-       return _j2k_encoder.video_frames_enqueued();
+       return _player.frames_done();
 }
index c03cb97a59f50ad8549f8142279e48a236a801dc..2e96e4bee72b8cb45731dc43b2363e40d0f660cc 100644 (file)
@@ -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,16 @@ 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());
+}
index 94e41bbcace5aceab2ea56c05ef88c7f83166e9f..43c46945cb4f7fd8057a502ce5b11bc58483de84 100644 (file)
@@ -90,6 +90,7 @@ public:
 
        bool pass ();
        void seek (dcpomatic::DCPTime time, bool accurate);
+       Frame frames_done() const;
 
        std::vector<std::shared_ptr<dcpomatic::Font>> get_subtitle_fonts ();
 
@@ -155,6 +156,7 @@ private:
        dcpomatic::ContentTime dcp_to_content_time (std::shared_ptr<const Piece> piece, dcpomatic::DCPTime t) const;
        dcpomatic::DCPTime content_time_to_dcp (std::shared_ptr<const Piece> piece, dcpomatic::ContentTime t) const;
        std::shared_ptr<PlayerVideo> black_player_video_frame (Eyes eyes) const;
+       std::pair<std::shared_ptr<Piece>, boost::optional<dcpomatic::DCPTime>> earliest_piece_and_time() const;
 
        void video (std::weak_ptr<Piece>, ContentVideo);
        void audio (std::weak_ptr<Piece>, AudioStreamPtr, ContentAudio);