From b9583e6a9c726eeee96eb574a81b77f521f9c004 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 7 Oct 2018 17:57:18 +0200 Subject: [PATCH] Move transitioning to the next clip away from the done callback. This is a natural step on the way to fade support. --- clip_list.h | 1 + mainwindow.cpp | 21 +++++++++++++++------ mainwindow.h | 2 ++ player.cpp | 13 +++++++++++++ player.h | 6 ++++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/clip_list.h b/clip_list.h index 31ddb6c..eb1340f 100644 --- a/clip_list.h +++ b/clip_list.h @@ -126,6 +126,7 @@ 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; } diff --git a/mainwindow.cpp b/mainwindow.cpp index b6ac8bf..6779cac 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -126,6 +126,7 @@ MainWindow::MainWindow() live_player_clip_done(); }); }); + live_player->set_next_clip_callback(bind(&MainWindow::live_player_get_next_clip, this)); live_player->set_progress_callback([this](double played_this_clip, double total_length) { post_to_main_thread([this, played_this_clip, total_length] { live_player_clip_progress(played_this_clip, total_length); @@ -325,15 +326,23 @@ void MainWindow::play_clicked() void MainWindow::live_player_clip_done() { + int row = playlist_clips->get_currently_playing(); + if (row == -1 || row == int(playlist_clips->size()) - 1) { + ui->live_label->setText("Current output (paused)"); + playlist_clips->set_currently_playing(-1, 0.0f); + } else { + playlist_clips->set_currently_playing(row + 1, 0.0f); + } +} + +Clip MainWindow::live_player_get_next_clip() +{ + // FIXME: threading int row = playlist_clips->get_currently_playing(); if (row != -1 && row < int(playlist_clips->size()) - 1) { - ++row; - const Clip &clip = *playlist_clips->clip(row); - live_player->play_clip(clip, clip.stream_idx); - playlist_clips->set_currently_playing(row, 0.0f); + return *playlist_clips->clip(row + 1); } else { - playlist_clips->set_currently_playing(-1, 0.0f); - ui->live_label->setText("Current output (paused)"); + return Clip(); } } diff --git a/mainwindow.h b/mainwindow.h index 35898a7..a396a92 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -7,6 +7,7 @@ #include #include +#include "clip_list.h" #include "db.h" #include "state.pb.h" @@ -68,6 +69,7 @@ private: void preview_angle_clicked(unsigned stream_idx); void play_clicked(); void live_player_clip_done(); + Clip live_player_get_next_clip(); void live_player_clip_progress(double played_this_clip, double total_length); void playlist_duplicate(); void playlist_remove(); diff --git a/player.cpp b/player.cpp index 3a95891..079f5cf 100644 --- a/player.cpp +++ b/player.cpp @@ -69,6 +69,7 @@ void Player::thread_func(bool also_output_to_stream) clip = current_clip; stream_idx = current_stream_idx; } +got_clip: steady_clock::time_point origin = steady_clock::now(); int64_t in_pts_origin = clip.pts_in; int64_t out_pts_origin = pts; @@ -176,6 +177,18 @@ void Player::thread_func(bool also_output_to_stream) } } + if (next_clip_callback != nullptr) { + Clip next_clip = next_clip_callback(); + if (next_clip.pts_in != -1) { + clip = next_clip; + stream_idx = next_clip.stream_idx; // Override is used for previews only, and next_clip is used for live ony. + if (done_callback != nullptr) { + done_callback(); + } + goto got_clip; + } + } + { unique_lock lock(queue_state_mu); playing = false; diff --git a/player.h b/player.h index 294ffba..63d4871 100644 --- a/player.h +++ b/player.h @@ -28,6 +28,11 @@ public: using done_callback_func = std::function; void set_done_callback(done_callback_func cb) { done_callback = cb; } + // Not thread-safe to set concurrently with playing. + // Will be called back from the player thread. + using next_clip_callback_func = std::function; + void set_next_clip_callback(next_clip_callback_func cb) { next_clip_callback = cb; } + // Not thread-safe to set concurrently with playing. // Will be called back from the player thread. using progress_callback_func = std::function; @@ -45,6 +50,7 @@ private: JPEGFrameView *destination; done_callback_func done_callback; + next_clip_callback_func next_clip_callback; progress_callback_func progress_callback; std::mutex mu; -- 2.39.2