]> git.sesse.net Git - nageru/blob - player.h
Move stream generation into a new class VideoStream, which will also soon deal with...
[nageru] / player.h
1 #ifndef _PLAYER_H
2 #define _PLAYER_H 1
3
4 #include "clip_list.h"
5 #include "video_stream.h"
6
7 #include <condition_variable>
8 #include <functional>
9 #include <mutex>
10
11 class JPEGFrameView;
12
13 class Player {
14 public:
15         Player(JPEGFrameView *destination);
16
17         void play_clip(const Clip &clip, unsigned stream_idx);
18         void override_angle(unsigned stream_idx);  // For the current clip only.
19
20         // Not thread-safe to set concurrently with playing.
21         // Will be called back from the player thread.
22         using done_callback_func = std::function<void()>;
23         void set_done_callback(done_callback_func cb) { done_callback = cb; }
24
25 private:
26         void thread_func();
27         void open_output_stream();
28         static int write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
29         int write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
30
31         JPEGFrameView *destination;
32         done_callback_func done_callback;
33
34         std::mutex mu;
35         Clip current_clip;  // Under mu. Can have pts_in = -1 for no clip.
36         unsigned current_stream_idx;  // Under mu.
37
38         std::mutex queue_state_mu;
39         std::condition_variable new_clip_changed;
40         bool new_clip_ready = false;  // Under queue_state_mu.
41         bool playing = false;  // Under queue_state_mu.
42         int override_stream_idx = -1;  // Under queue_state_mu.
43
44         VideoStream video_stream;
45 };
46
47 #endif  // !defined(_PLAYER_H)