From 03be4eea8fe0f2a72ee848595fdd37036574cbcb Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 15 Dec 2018 00:17:52 +0100 Subject: [PATCH] Factor out estimated time left calculation into its own function. --- futatabi/mainwindow.cpp | 22 ++++------------------ futatabi/player.cpp | 24 ++++++++++++++++++++++++ futatabi/player.h | 2 ++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index 9684933..7455cac 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -418,25 +418,11 @@ void MainWindow::live_player_clip_progress(const map &progress) { playlist_clips->set_progress(progress); - // Look at the last clip and then start counting from there. - assert(!progress.empty()); - auto last_it = progress.end(); - --last_it; - double remaining = 0.0; - double last_fade_time_seconds = 0.0; - for (size_t row = last_it->first; row < playlist_clips->size(); ++row) { - const Clip clip = *playlist_clips->clip(row); - double clip_length = double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed. - if (row == last_it->first) { - // A clip we're playing: Subtract the part we've already played. - remaining = clip_length * (1.0 - last_it->second); - } else { - // A clip we haven't played yet: Subtract the part that's overlapping - // with a previous clip (due to fade). - remaining += max(clip_length - last_fade_time_seconds, 0.0); - } - last_fade_time_seconds = min(clip_length, clip.fade_time_seconds); + vector clips; + for (size_t row = 0; row < playlist_clips->size(); ++row) { + clips.push_back(*playlist_clips->clip(row)); } + double remaining = compute_time_left(clips, progress); set_output_status(format_duration(remaining) + " left"); } diff --git a/futatabi/player.cpp b/futatabi/player.cpp index 2fb3939..e5562f7 100644 --- a/futatabi/player.cpp +++ b/futatabi/player.cpp @@ -472,3 +472,27 @@ void Player::release_queue_spot() --num_queued_frames; new_clip_changed.notify_all(); } + +double compute_time_left(const vector &clips, const map &progress) +{ + // Look at the last clip and then start counting from there. + assert(!progress.empty()); + auto last_it = progress.end(); + --last_it; + double remaining = 0.0; + double last_fade_time_seconds = 0.0; + for (size_t row = last_it->first; row < clips.size(); ++row) { + const Clip &clip = clips[row]; + double clip_length = double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed. + if (row == last_it->first) { + // A clip we're playing: Subtract the part we've already played. + remaining = clip_length * (1.0 - last_it->second); + } else { + // A clip we haven't played yet: Subtract the part that's overlapping + // with a previous clip (due to fade). + remaining += max(clip_length - last_fade_time_seconds, 0.0); + } + last_fade_time_seconds = min(clip_length, clip.fade_time_seconds); + } + return remaining; +} diff --git a/futatabi/player.h b/futatabi/player.h index 03da29e..22de0b3 100644 --- a/futatabi/player.h +++ b/futatabi/player.h @@ -20,6 +20,8 @@ class VideoStream; class QSurface; class QSurfaceFormat; +double compute_time_left(const std::vector &clips, const std::map &progress); + class Player : public QueueInterface { public: enum StreamOutput { -- 2.39.2