]> git.sesse.net Git - nageru/blob - video_encoder.h
Move X264Encoder out of QuickSyncEncoder. This completes independent restart of the...
[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 "audio_encoder.h"
14 #include "mux.h"
15 #include "ref_counted_frame.h"
16 #include "ref_counted_gl_sync.h"
17
18 class HTTPD;
19 class QSurface;
20 class QuickSyncEncoder;
21 class X264Encoder;
22
23 class VideoEncoder : public KeyFrameSignalReceiver {
24 public:
25         VideoEncoder(QSurface *surface, const std::string &va_display, int width, int height, HTTPD *httpd);
26         ~VideoEncoder();
27
28         void add_audio(int64_t pts, std::vector<float> audio);
29         bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex);
30         RefCountedGLsync end_frame(int64_t pts, int64_t duration, const std::vector<RefCountedFrame> &input_frames);
31
32         // Does a cut of the disk stream immediately ("frame" is used for the filename only).
33         void do_cut(int frame);
34
35         virtual void signal_keyframe() override {
36                 stream_mux_writing_keyframes = true;
37         }
38
39 private:
40         void open_output_stream();
41         void close_output_stream();
42         static int write_packet_thunk(void *opaque, uint8_t *buf, int buf_size);
43         int write_packet(uint8_t *buf, int buf_size);
44
45         std::unique_ptr<QuickSyncEncoder> quicksync_encoder;
46         QSurface *surface;
47         std::string va_display;
48         int width, height;
49         HTTPD *httpd;
50
51         std::unique_ptr<Mux> stream_mux;  // To HTTP.
52         std::unique_ptr<AudioEncoder> stream_audio_encoder;
53         std::unique_ptr<X264Encoder> x264_encoder;  // nullptr if not using x264.
54
55         // While Mux object is constructing, <stream_mux_writing_header> is true,
56         // and the header is being collected into stream_mux_header.
57         bool stream_mux_writing_header;
58         std::string stream_mux_header;
59
60         bool stream_mux_writing_keyframes = false;
61 };
62
63 #endif