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.
5 #ifndef _VIDEO_ENCODER_H
6 #define _VIDEO_ENCODER_H
13 #include "audio_encoder.h"
15 #include "ref_counted_frame.h"
16 #include "ref_counted_gl_sync.h"
20 class QuickSyncEncoder;
22 class VideoEncoder : public KeyFrameSignalReceiver {
24 VideoEncoder(QSurface *surface, const std::string &va_display, int width, int height, HTTPD *httpd);
27 void add_audio(int64_t pts, std::vector<float> audio);
28 bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex);
29 RefCountedGLsync end_frame(int64_t pts, int64_t duration, const std::vector<RefCountedFrame> &input_frames);
31 // Does a cut of the disk stream immediately ("frame" is used for the filename only).
32 void do_cut(int frame);
34 virtual void signal_keyframe() override {
35 stream_mux_writing_keyframes = true;
39 void open_output_stream();
40 void close_output_stream();
41 static int write_packet_thunk(void *opaque, uint8_t *buf, int buf_size);
42 int write_packet(uint8_t *buf, int buf_size);
44 std::unique_ptr<QuickSyncEncoder> quicksync_encoder;
46 std::string va_display;
50 std::unique_ptr<Mux> stream_mux; // To HTTP.
51 std::unique_ptr<AudioEncoder> stream_audio_encoder;
53 // While Mux object is constructing, <stream_mux_writing_header> is true,
54 // and the header is being collected into stream_mux_header.
55 bool stream_mux_writing_header;
56 std::string stream_mux_header;
58 bool stream_mux_writing_keyframes = false;