diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-05-16 14:59:50 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-05-16 14:59:50 +0200 |
| commit | eb6f689b8e9d982d73612af2ba5ddc7ab021aec8 (patch) | |
| tree | ac58fbabe3e13fa656d19543320b4a42206073dd /src/lib/player.cc | |
| parent | 8aa25e2ec75dada5f07a3860d668241821056f61 (diff) | |
| parent | 7a9cadc6fe86c74035dd971685b1acdc8f32d3fc (diff) | |
Merge branch 'main' into v2.17.x
Diffstat (limited to 'src/lib/player.cc')
| -rw-r--r-- | src/lib/player.cc | 81 |
1 files changed, 61 insertions, 20 deletions
diff --git a/src/lib/player.cc b/src/lib/player.cc index 913d7392f..9ba2f1cb0 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -685,6 +685,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 () { @@ -708,26 +741,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; @@ -1612,3 +1626,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(); +} |
