From 2b37c51ea17b77b88e2f7fda443109acc260aa8f Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 28 Dec 2018 12:09:17 +0100 Subject: [PATCH] Move progress row information into Player; will be easier to track when we start modifying the lists. --- futatabi/export.cpp | 6 +++++- futatabi/mainwindow.cpp | 26 ++++++++------------------ futatabi/mainwindow.h | 1 - futatabi/player.cpp | 16 ++++++++-------- futatabi/player.h | 14 +++++++++++--- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/futatabi/export.cpp b/futatabi/export.cpp index dce83c3..2b9f531 100644 --- a/futatabi/export.cpp +++ b/futatabi/export.cpp @@ -224,6 +224,10 @@ void export_interpolated_clip(const string &filename, const vector &clips) progress.setValue(0); double total_length = compute_time_left(clips, { { 0, 0.0 } }); + vector clips_with_row; + for (const Clip &clip : clips) { + clips_with_row.emplace_back(Player::ClipWithRow{ clip, 0 }); + } promise done_promise; future done = done_promise.get_future(); @@ -239,7 +243,7 @@ void export_interpolated_clip(const string &filename, const vector &clips) player.set_progress_callback([¤t_value, &clips, total_length](const std::map &player_progress) { current_value = 1.0 - compute_time_left(clips, player_progress) / total_length; }); - player.play(clips); + player.play(clips_with_row); while (done.wait_for(std::chrono::milliseconds(100)) != future_status::ready && !progress.wasCanceled()) { progress.setValue(lrint(100000.0 * current_value)); } diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index 6553c8c..5cbfb13 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -336,7 +336,7 @@ void MainWindow::preview_clicked() if (selected->hasSelection()) { QModelIndex index = selected->currentIndex(); const Clip &clip = *playlist_clips->clip(index.row()); - preview_player->play({ clip }); + preview_player->play(clip); return; } } @@ -346,7 +346,7 @@ void MainWindow::preview_clicked() QItemSelectionModel *selected = ui->clip_list->selectionModel(); if (!selected->hasSelection()) { - preview_player->play({ *cliplist_clips->back() }); + preview_player->play(*cliplist_clips->back()); return; } @@ -357,7 +357,7 @@ void MainWindow::preview_clicked() } else { clip.stream_idx = ui->preview_display->get_stream_idx(); } - preview_player->play({ clip }); + preview_player->play(clip); } void MainWindow::preview_angle_clicked(unsigned stream_idx) @@ -487,12 +487,9 @@ void MainWindow::play_clicked() start_row = selected->selectedRows(0)[0].row(); } - live_player_index_to_row.clear(); - - vector clips; + vector clips; for (unsigned row = start_row; row < playlist_clips->size(); ++row) { - live_player_index_to_row.emplace(clips.size(), row); - clips.push_back(*playlist_clips->clip(row)); + clips.emplace_back(Player::ClipWithRow{ *playlist_clips->clip(row), row }); } live_player->play(clips); playlist_clips->set_progress({ { start_row, 0.0f } }); @@ -509,8 +506,7 @@ void MainWindow::stop_clicked() fake_clip.pts_out = 0; size_t last_row = playlist_clips->size() - 1; playlist_clips->set_currently_playing(last_row, 0.0f); - live_player_index_to_row.clear(); - live_player->play({ fake_clip }); + live_player->play(fake_clip); } void MainWindow::live_player_clip_done() @@ -564,13 +560,7 @@ static string format_duration(double t) void MainWindow::live_player_clip_progress(const map &progress) { - map converted_progress; - for (const auto &it : progress) { - if (live_player_index_to_row.count(it.first)) { - converted_progress.emplace(live_player_index_to_row[it.first], it.second); - } - } - playlist_clips->set_progress(converted_progress); + playlist_clips->set_progress(progress); vector clips; for (size_t row = 0; row < playlist_clips->size(); ++row) { @@ -841,7 +831,7 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind Clip fake_clip; fake_clip.pts_in = pts; fake_clip.pts_out = pts + 1; - preview_player->play({ fake_clip }); + preview_player->play(fake_clip); } void MainWindow::playlist_selection_changed() diff --git a/futatabi/mainwindow.h b/futatabi/mainwindow.h index afc16ff..33a510e 100644 --- a/futatabi/mainwindow.h +++ b/futatabi/mainwindow.h @@ -43,7 +43,6 @@ private: QLabel *disk_free_label; std::unique_ptr preview_player, live_player; - std::map live_player_index_to_row; DB db; unsigned num_cameras; diff --git a/futatabi/player.cpp b/futatabi/player.cpp index f342ac5..a82b16e 100644 --- a/futatabi/player.cpp +++ b/futatabi/player.cpp @@ -64,7 +64,7 @@ double calc_progress(const Clip &clip, int64_t pts) void Player::play_playlist_once() { - vector clip_list; + vector clip_list; bool clip_ready; steady_clock::time_point before_sleep = steady_clock::now(); @@ -99,10 +99,10 @@ void Player::play_playlist_once() } steady_clock::time_point origin = steady_clock::now(); // TODO: Add a 100 ms buffer for ramp-up? - int64_t in_pts_origin = clip_list[0].pts_in; + int64_t in_pts_origin = clip_list[0].clip.pts_in; for (size_t clip_idx = 0; clip_idx < clip_list.size(); ++clip_idx) { - const Clip &clip = clip_list[clip_idx]; - const Clip *next_clip = (clip_idx + 1 < clip_list.size()) ? &clip_list[clip_idx + 1] : nullptr; + const Clip &clip = clip_list[clip_idx].clip; + const Clip *next_clip = (clip_idx + 1 < clip_list.size()) ? &clip_list[clip_idx + 1].clip : nullptr; int64_t out_pts_origin = pts; double next_clip_fade_time = -1.0; @@ -179,9 +179,9 @@ void Player::play_playlist_once() if (progress_callback != nullptr) { // NOTE: None of this will take into account any snapping done below. - map progress{ { clip_idx, calc_progress(clip, in_pts_for_progress) } }; + map progress{ { clip_list[clip_idx].row, calc_progress(clip, in_pts_for_progress) } }; if (next_clip != nullptr && time_left_this_clip <= next_clip_fade_time) { - progress[clip_idx + 1] = calc_progress(*next_clip, in_pts_secondary_for_progress); + progress[clip_list[clip_idx + 1].row] = calc_progress(*next_clip, in_pts_secondary_for_progress); } progress_callback(progress); } @@ -419,7 +419,7 @@ Player::~Player() player_thread.join(); } -void Player::play(const vector &clips) +void Player::play(const vector &clips) { lock_guard lock(queue_state_mu); new_clip_ready = true; @@ -437,7 +437,7 @@ void Player::override_angle(unsigned stream_idx) lock_guard lock(queue_state_mu); if (new_clip_ready) { assert(queued_clip_list.size() == 1); - queued_clip_list[0].stream_idx = stream_idx; + queued_clip_list[0].clip.stream_idx = stream_idx; return; } diff --git a/futatabi/player.h b/futatabi/player.h index 549b1f3..a581a54 100644 --- a/futatabi/player.h +++ b/futatabi/player.h @@ -32,7 +32,15 @@ public: Player(JPEGFrameView *destination, StreamOutput stream_output, AVFormatContext *file_avctx = nullptr); ~Player(); - void play(const std::vector &clips); + struct ClipWithRow { + Clip clip; + unsigned row; // Used for progress callback only. + }; + void play(const Clip &clip) + { + play({ ClipWithRow{ clip, 0 } }); + } + void play(const std::vector &clips); void override_angle(unsigned stream_idx); // Assumes one-clip playlist only. // Not thread-safe to set concurrently with playing. @@ -42,7 +50,7 @@ public: // Not thread-safe to set concurrently with playing. // Will be called back from the player thread. - // The keys in the given map are indexes in the vector given to play(). + // The keys in the given map are row members in the vector given to play(). using progress_callback_func = std::function &progress)>; void set_progress_callback(progress_callback_func cb) { progress_callback = cb; } @@ -71,7 +79,7 @@ private: std::mutex queue_state_mu; std::condition_variable new_clip_changed; - std::vector queued_clip_list; // Under queue_state_mu. + std::vector queued_clip_list; // Under queue_state_mu. bool new_clip_ready = false; // Under queue_state_mu. bool playing = false; // Under queue_state_mu. int override_stream_idx = -1; // Under queue_state_mu. -- 2.39.2