From: Steinar H. Gunderson Date: Fri, 28 Dec 2018 16:06:15 +0000 (+0100) Subject: Call the done callback only when the entire playlist is done. Simplifies a fair amoun... X-Git-Tag: 1.8.1~14 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=e64a84bb856263242278afa9770ae5d05e21b055 Call the done callback only when the entire playlist is done. Simplifies a fair amount of stuff. --- diff --git a/futatabi/clip_list.cpp b/futatabi/clip_list.cpp index c586b1a..0bb73ae 100644 --- a/futatabi/clip_list.cpp +++ b/futatabi/clip_list.cpp @@ -433,25 +433,6 @@ void ClipList::change_num_cameras(size_t num_cameras) emit any_content_changed(); } -void PlayList::set_currently_playing(int index, double progress) -{ - int old_index = currently_playing_index; - int column = int(Column::PLAYING); - if (index != old_index) { - currently_playing_index = index; - play_progress = progress; - if (old_index != -1) { - emit dataChanged(this->index(old_index, column), this->index(old_index, column)); - } - if (index != -1) { - emit dataChanged(this->index(index, column), this->index(index, column)); - } - } else if (index != -1 && fabs(progress - play_progress) > 1e-3) { - play_progress = progress; - emit dataChanged(this->index(index, column), this->index(index, column)); - } -} - void PlayList::set_progress(const map &progress) { const int column = int(Column::PLAYING); diff --git a/futatabi/clip_list.h b/futatabi/clip_list.h index af3d1f5..99fdf53 100644 --- a/futatabi/clip_list.h +++ b/futatabi/clip_list.h @@ -137,10 +137,6 @@ public: ClipProxy mutable_back() { return mutable_clip(size() - 1); } const Clip *back() const { return clip(size() - 1); } - // TODO: Move these out of PlayList. - void set_currently_playing(int index, double progress); // -1 = none. - int get_currently_playing() const { return currently_playing_index; } - void set_progress(const std::map &progress); ClipListProto serialize() const; @@ -157,7 +153,6 @@ signals: private: std::vector clips; - int currently_playing_index = -1; double play_progress = 0.0; std::map current_progress; size_t num_cameras = 2; diff --git a/futatabi/export.cpp b/futatabi/export.cpp index 1aea044..5481007 100644 --- a/futatabi/export.cpp +++ b/futatabi/export.cpp @@ -232,13 +232,10 @@ void export_interpolated_clip(const string &filename, const vector &clips) promise done_promise; future done = done_promise.get_future(); std::atomic current_value{ 0.0 }; - size_t clip_idx = 0; Player player(/*destination=*/nullptr, Player::FILE_STREAM_OUTPUT, closer.release()); - player.set_done_callback([&done_promise, &clip_idx, &clips] { - if (clip_idx >= clips.size()) { - done_promise.set_value(); - } + player.set_done_callback([&done_promise] { + done_promise.set_value(); }); player.set_progress_callback([¤t_value, &clips, total_length](const std::map &player_progress, double time_remaining) { current_value = 1.0 - time_remaining / total_length; diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index 22b8d9c..3d3d8c1 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -186,7 +186,7 @@ MainWindow::MainWindow() live_player.reset(new Player(ui->live_display, Player::HTTPD_STREAM_OUTPUT)); live_player->set_done_callback([this] { post_to_main_thread([this] { - live_player_clip_done(); + live_player_done(); }); }); live_player->set_progress_callback([this](const map &progress, double time_remaining) { @@ -493,7 +493,6 @@ void MainWindow::play_clicked() } live_player->play(clips); playlist_clips->set_progress({ { start_row, 0.0f } }); - playlist_clips->set_currently_playing(start_row, 0.0f); playlist_selection_changed(); ui->stop_btn->setEnabled(true); @@ -504,23 +503,14 @@ void MainWindow::stop_clicked() Clip fake_clip; fake_clip.pts_in = 0; fake_clip.pts_out = 0; - size_t last_row = playlist_clips->size() - 1; - playlist_clips->set_currently_playing(last_row, 0.0f); live_player->play(fake_clip); } -void MainWindow::live_player_clip_done() +void MainWindow::live_player_done() { - int row = playlist_clips->get_currently_playing(); - if (row == -1 || row == int(playlist_clips->size()) - 1) { - set_output_status("paused"); - playlist_clips->set_progress({}); - playlist_clips->set_currently_playing(-1, 0.0f); - ui->stop_btn->setEnabled(false); - } else { - playlist_clips->set_progress({ { row + 1, 0.0f } }); - playlist_clips->set_currently_playing(row + 1, 0.0f); - } + set_output_status("paused"); + playlist_clips->set_progress({}); + ui->stop_btn->setEnabled(false); } static string format_duration(double t) diff --git a/futatabi/mainwindow.h b/futatabi/mainwindow.h index e2934ff..f93da89 100644 --- a/futatabi/mainwindow.h +++ b/futatabi/mainwindow.h @@ -102,7 +102,7 @@ private: void preview_angle_clicked(unsigned stream_idx); void play_clicked(); void stop_clicked(); - void live_player_clip_done(); + void live_player_done(); void live_player_clip_progress(const std::map &progress, double time_remaining); void set_output_status(const std::string &status); void playlist_duplicate(); diff --git a/futatabi/player.cpp b/futatabi/player.cpp index 3545eb1..0d9e092 100644 --- a/futatabi/player.cpp +++ b/futatabi/player.cpp @@ -50,6 +50,9 @@ void Player::thread_func(AVFormatContext *file_avctx) while (!should_quit) { play_playlist_once(); + if (done_callback != nullptr) { + done_callback(); + } } } @@ -322,9 +325,6 @@ void Player::play_playlist_once() if (should_quit) { return; } - if (done_callback != nullptr) { - done_callback(); - } // Start the next clip from the point where the fade went out. if (next_clip != nullptr) { @@ -332,10 +332,6 @@ void Player::play_playlist_once() in_pts_origin = next_clip->pts_in + lrint(next_clip_fade_time * TIMEBASE * clip.speed); } } - - if (done_callback != nullptr) { - done_callback(); - } } void Player::display_single_frame(int primary_stream_idx, const FrameOnDisk &primary_frame, int secondary_stream_idx, const FrameOnDisk &secondary_frame, double fade_alpha, steady_clock::time_point frame_start, bool snapped)