]> git.sesse.net Git - nageru/blobdiff - player.h
Make it possible to switch camera angles for previews with the 1–4 keys.
[nageru] / player.h
index 960bc22fcd713f2f7a58d4a9e168f78958206c0e..e251c6e86d8f20446e8692361bad34c2123d15bd 100644 (file)
--- a/player.h
+++ b/player.h
@@ -3,7 +3,39 @@
 
 #include "clip_list.h"
 
-void start_player_thread();
-void play_clip(const Clip &clip, unsigned stream_idx);
+#include <condition_variable>
+#include <functional>
+#include <mutex>
+
+class JPEGFrameView;
+
+class Player {
+public:
+       Player(JPEGFrameView *destination);
+
+       void play_clip(const Clip &clip, unsigned stream_idx);
+       void override_angle(unsigned stream_idx);  // For the current clip only.
+
+       // 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. Can have pts_in = -1 for no clip.
+       unsigned current_stream_idx;  // Under mu.
+
+       std::mutex queue_state_mu;
+       std::condition_variable new_clip_changed;
+       bool new_clip_ready = false;  // Under queue_state_mu.
+       bool playing = false;  // Under queue_state_mu.
+       int override_stream_idx = -1;  // Under queue_state_mu.
+};
 
 #endif  // !defined(_PLAYER_H)