]> git.sesse.net Git - nageru/commitdiff
Make it possible to play an entire playlist of clips.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 13 Jun 2018 21:37:32 +0000 (23:37 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 13 Jun 2018 21:37:32 +0000 (23:37 +0200)
clip_list.h
mainwindow.cpp
mainwindow.h
player.cpp
player.h

index 851f86a1296d818005984dae117cf9ad7d13dbc2..9ca6e63799896f32cc5312a3e72a0c48704abf38 100644 (file)
@@ -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);
 
index 74b67e4396f221ee552a1822f8e3a334792ea102..84231b743a0734cf91c143a9f99a16c11b45f157 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "clip_list.h"
 #include "player.h"
+#include "post_to_main_thread.h"
 #include "ui_mainwindow.h"
 
 #include <string>
@@ -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);
+       }
+}
index e9b8dc14ee1942f88387f57bf858e586bca3f519..c037c77833b0a67fdd021d20d8da8b326bd6c9c9 100644 (file)
@@ -27,6 +27,7 @@ private:
        void queue_clicked();
        void preview_clicked();
        void play_clicked();
+       void live_player_clip_done();
 };
 
 extern MainWindow *global_mainwindow;
index 6e45f39cd3fc5cc2aaa6ac5b4770ef09b5ac5085..b9ac64cbb8798abcd1b8927a9ec069e8cc10115d 100644 (file)
@@ -67,11 +67,14 @@ void Player::thread_func()
                        if (eof) break;
                }
 
-               // TODO: callback so that the next playlist item can be cued.
                {
                        unique_lock<mutex> lock(cue_state_mu);
                        cue_state = PAUSED;
                }
+
+               if (done_callback != nullptr) {
+                       done_callback();
+               }
        }
 }
 
index debf9194474baacacefdc448b14e5bbce6caecfa..06e70b4570b83909b6fb3d66f71c9ae2787d20ed 100644 (file)
--- a/player.h
+++ b/player.h
@@ -4,6 +4,7 @@
 #include "clip_list.h"
 
 #include <condition_variable>
+#include <functional>
 #include <mutex>
 
 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()>;
+       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.