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