From: Steinar H. Gunderson Date: Wed, 13 Jun 2018 21:37:32 +0000 (+0200) Subject: Make it possible to play an entire playlist of clips. X-Git-Tag: 1.8.0~76^2~279 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=9c8b3d2c80d20a391ada89a2a54910ec35c036d2;p=nageru Make it possible to play an entire playlist of clips. --- diff --git a/clip_list.h b/clip_list.h index 851f86a..9ca6e63 100644 --- a/clip_list.h +++ b/clip_list.h @@ -80,6 +80,7 @@ public: const Clip *back() const { return clip(size() - 1); } void set_currently_playing(int index); // -1 = none. Only makes sense for the playlist. + int get_currently_playing() const { return currently_playing_index; } void emit_data_changed(size_t row); diff --git a/mainwindow.cpp b/mainwindow.cpp index 74b67e4..84231b7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,6 +2,7 @@ #include "clip_list.h" #include "player.h" +#include "post_to_main_thread.h" #include "ui_mainwindow.h" #include @@ -63,6 +64,11 @@ MainWindow::MainWindow() preview_player = new Player(ui->preview_display); live_player = new Player(ui->live_display); + live_player->set_done_callback([this]{ + post_to_main_thread([this]{ + live_player_clip_done(); + }); + }); } void MainWindow::queue_clicked() @@ -110,7 +116,20 @@ void MainWindow::play_clicked() row = selected->selectedRows(0)[0].row(); } - const Clip &clip = *cliplist_clips->clip(row); + const Clip &clip = *playlist_clips->clip(row); live_player->play_clip(clip, clip.stream_idx); playlist_clips->set_currently_playing(row); } + +void MainWindow::live_player_clip_done() +{ + 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); + } else { + playlist_clips->set_currently_playing(-1); + } +} diff --git a/mainwindow.h b/mainwindow.h index e9b8dc1..c037c77 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ private: void queue_clicked(); void preview_clicked(); void play_clicked(); + void live_player_clip_done(); }; extern MainWindow *global_mainwindow; diff --git a/player.cpp b/player.cpp index 6e45f39..b9ac64c 100644 --- a/player.cpp +++ b/player.cpp @@ -67,11 +67,14 @@ void Player::thread_func() if (eof) break; } - // TODO: callback so that the next playlist item can be cued. { unique_lock lock(cue_state_mu); cue_state = PAUSED; } + + if (done_callback != nullptr) { + done_callback(); + } } } diff --git a/player.h b/player.h index debf919..06e70b4 100644 --- a/player.h +++ b/player.h @@ -4,6 +4,7 @@ #include "clip_list.h" #include +#include #include class JPEGFrameView; @@ -14,10 +15,16 @@ public: void play_clip(const Clip &clip, unsigned stream_idx); + // Not thread-safe to set concurrently with playing. + // Will be called back from the player thread. + using done_callback_func = std::function; + void set_done_callback(done_callback_func cb) { done_callback = cb; } + private: void thread_func(); JPEGFrameView *destination; + done_callback_func done_callback; std::mutex mu; Clip current_clip; // Under mu.