]> git.sesse.net Git - nageru/blob - video_encoder.h
Move the entire stream mux logic from QuickSyncEncoder into VideoEncoder.
[nageru] / video_encoder.h
1 // A class to orchestrate the concept of video encoding. Will keep track of
2 // the muxes to stream and disk, the QuickSyncEncoder, and also the X264Encoder
3 // (for the stream) if there is one.
4
5 #ifndef _VIDEO_ENCODER_H
6 #define _VIDEO_ENCODER_H
7
8 #include <stdint.h>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "mux.h"
14 #include "ref_counted_frame.h"
15 #include "ref_counted_gl_sync.h"
16
17 class HTTPD;
18 class QSurface;
19 class QuickSyncEncoder;
20
21 class VideoEncoder : public KeyFrameSignalReceiver {
22 public:
23         VideoEncoder(QSurface *surface, const std::string &va_display, int width, int height, HTTPD *httpd);
24         ~VideoEncoder();
25
26         void add_audio(int64_t pts, std::vector<float> audio);
27         bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex);
28         RefCountedGLsync end_frame(int64_t pts, int64_t duration, const std::vector<RefCountedFrame> &input_frames);
29
30         // Does a cut of the disk stream immediately ("frame" is used for the filename only).
31         void do_cut(int frame);
32
33         virtual void signal_keyframe() override {
34                 stream_mux_writing_keyframes = true;
35         }
36
37 private:
38         void open_output_stream();
39         void close_output_stream();
40         static int write_packet_thunk(void *opaque, uint8_t *buf, int buf_size);
41         int write_packet(uint8_t *buf, int buf_size);
42
43         std::unique_ptr<QuickSyncEncoder> quicksync_encoder;
44         QSurface *surface;
45         std::string va_display;
46         int width, height;
47         HTTPD *httpd;
48
49         std::unique_ptr<Mux> stream_mux;  // To HTTP.
50
51         // While Mux object is constructing, <stream_mux_writing_header> is true,
52         // and the header is being collected into stream_mux_header.
53         bool stream_mux_writing_header;
54         std::string stream_mux_header;
55
56         bool stream_mux_writing_keyframes = false;
57 };
58
59 #endif