]> git.sesse.net Git - nageru/blob - player.h
Actually send the MJPEG frames on to the HTTP stream.
[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 extern "C" {
11 #include <libavformat/avio.h>
12 }
13
14 class JPEGFrameView;
15 class Mux;
16
17 class Player {
18 public:
19         Player(JPEGFrameView *destination);
20
21         void play_clip(const Clip &clip, unsigned stream_idx);
22         void override_angle(unsigned stream_idx);  // For the current clip only.
23
24         // Not thread-safe to set concurrently with playing.
25         // Will be called back from the player thread.
26         using done_callback_func = std::function<void()>;
27         void set_done_callback(done_callback_func cb) { done_callback = cb; }
28
29 private:
30         void thread_func();
31         void open_output_stream();
32         static int write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
33         int write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
34
35         JPEGFrameView *destination;
36         done_callback_func done_callback;
37
38         std::mutex mu;
39         Clip current_clip;  // Under mu. Can have pts_in = -1 for no clip.
40         unsigned current_stream_idx;  // Under mu.
41
42         std::mutex queue_state_mu;
43         std::condition_variable new_clip_changed;
44         bool new_clip_ready = false;  // Under queue_state_mu.
45         bool playing = false;  // Under queue_state_mu.
46         int override_stream_idx = -1;  // Under queue_state_mu.
47
48         // For streaming.
49         std::unique_ptr<Mux> stream_mux;  // To HTTP.
50         std::string stream_mux_header;
51         bool seen_sync_markers = false;
52 };
53
54 #endif  // !defined(_PLAYER_H)