]> git.sesse.net Git - nageru/commitdiff
Move transitioning to the next clip away from the done callback.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 7 Oct 2018 15:57:18 +0000 (17:57 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 7 Oct 2018 15:57:18 +0000 (17:57 +0200)
This is a natural step on the way to fade support.

clip_list.h
mainwindow.cpp
mainwindow.h
player.cpp
player.h

index 31ddb6cb297965512c5c7a65d26bfc52b485ca9b..eb1340f2514702046632c7c5317b46e415b14710 100644 (file)
@@ -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; }
 
index b6ac8bf1c45fba2ee652178178ebe8a93e4b526b..6779cac991944f0b392694c2f779b6084587899e 100644 (file)
@@ -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();
        }
 }
 
index 35898a78b8deec1f1273b6d5dc0ba8f7fa20f55b..a396a92f272941a9a5921671162237d9b04a68db 100644 (file)
@@ -7,6 +7,7 @@
 #include <QLabel>
 #include <QMainWindow>
 
+#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();
index 3a958917fff5639942bba4c8e713c562044bd2d5..079f5cf3116d3f603e181d05bdfc3bdc8c930d51 100644 (file)
@@ -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<mutex> lock(queue_state_mu);
                        playing = false;
index 294ffbaa3b9d765baade1f20966c32cf42d4800d..63d4871c8c653ebdbe02bb1ef10259d93ea46b01 100644 (file)
--- a/player.h
+++ b/player.h
@@ -28,6 +28,11 @@ public:
        using done_callback_func = std::function<void()>;
        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<Clip()>;
+       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<void(double played_this_clip, double total_length)>;
@@ -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;