]> git.sesse.net Git - nageru/blob - video_stream.h
Move stream generation into a new class VideoStream, which will also soon deal with...
[nageru] / video_stream.h
1 #ifndef _VIDEO_STREAM_H
2 #define _VIDEO_STREAM_H 1
3
4 #include <stdint.h>
5 #include <epoxy/gl.h>
6
7 extern "C" {
8 #include <libavformat/avio.h>
9 }
10
11 #include <condition_variable>
12 #include <deque>
13 #include <mutex>
14 #include <string>
15 #include <thread>
16
17 class Mux;
18
19 class VideoStream {
20 public:
21         void start();
22         void stop();
23
24         void schedule_original_frame(int64_t output_pts, unsigned stream_idx, int64_t input_pts);
25         void schedule_interpolated_frame(int64_t output_pts, unsigned stream_idx, int64_t input_first_pts, int64_t input_second_pts, float alpha);
26
27 private:
28         void encode_thread_func();
29         std::thread encode_thread;
30
31         static int write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
32         int write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
33
34         struct QueuedFrame {
35                 int64_t output_pts;
36                 enum Type { ORIGINAL, INTERPOLATED } type;
37                 unsigned stream_idx;
38                 int64_t input_first_pts;  // The only pts for original frames.  
39
40                 // For interpolated frames only.
41                 int64_t input_second_pts;
42                 float alpha;
43                 GLuint flow_tex;
44                 GLuint fence;  // Set when the flow is done computing.
45         };
46         std::deque<QueuedFrame> frame_queue;  // Under <queue_lock>.
47         std::mutex queue_lock;
48         std::condition_variable queue_nonempty;
49
50         std::unique_ptr<Mux> stream_mux;  // To HTTP.
51         std::string stream_mux_header;
52         bool seen_sync_markers = false;
53 };
54
55 #endif  // !defined(_VIDEO_STREAM_H)