]> git.sesse.net Git - nageru/blob - player.h
Make it possible to play an entire playlist of clips.
[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
18         // Not thread-safe to set concurrently with playing.
19         // Will be called back from the player thread.
20         using done_callback_func = std::function<void()>;
21         void set_done_callback(done_callback_func cb) { done_callback = cb; }
22
23 private:
24         void thread_func();
25
26         JPEGFrameView *destination;
27         done_callback_func done_callback;
28
29         std::mutex mu;
30         Clip current_clip;  // Under mu.
31         unsigned current_stream_idx;  // Under mu.
32
33         enum { PAUSED, PLAYING } cue_state = PAUSED;  // Under cue_state_mu.
34         std::mutex cue_state_mu;
35         std::condition_variable cue_is_playing;
36 };
37
38 #endif  // !defined(_PLAYER_H)