]> git.sesse.net Git - nageru/blob - player.h
Make it possible to switch camera angles for previews with the 1–4 keys.
[nageru] / player.h
1 #ifndef _PLAYER_H
2 #define _PLAYER_H 1
3
4 #include "clip_list.h"
5
6 #include <condition_variable>
7 #include <functional>
8 #include <mutex>
9
10 class JPEGFrameView;
11
12 class Player {
13 public:
14         Player(JPEGFrameView *destination);
15
16         void play_clip(const Clip &clip, unsigned stream_idx);
17         void override_angle(unsigned stream_idx);  // For the current clip only.
18
19         // Not thread-safe to set concurrently with playing.
20         // Will be called back from the player thread.
21         using done_callback_func = std::function<void()>;
22         void set_done_callback(done_callback_func cb) { done_callback = cb; }
23
24 private:
25         void thread_func();
26
27         JPEGFrameView *destination;
28         done_callback_func done_callback;
29
30         std::mutex mu;
31         Clip current_clip;  // Under mu. Can have pts_in = -1 for no clip.
32         unsigned current_stream_idx;  // Under mu.
33
34         std::mutex queue_state_mu;
35         std::condition_variable new_clip_changed;
36         bool new_clip_ready = false;  // Under queue_state_mu.
37         bool playing = false;  // Under queue_state_mu.
38         int override_stream_idx = -1;  // Under queue_state_mu.
39 };
40
41 #endif  // !defined(_PLAYER_H)