]> git.sesse.net Git - nageru/blobdiff - nageru/video_encoder.h
Fix a Clang 19 warning.
[nageru] / nageru / video_encoder.h
index 7a5fef1ac4dfd9cadc07bc6492b1281213a327f4..6301f50d3d7274283b22dc942882a9ee58ba697b 100644 (file)
@@ -6,6 +6,7 @@
 #define _VIDEO_ENCODER_H
 
 #include <epoxy/gl.h>
+#include <epoxy/gl_generated.h>
 #include <movit/image_format.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -20,8 +21,11 @@ extern "C" {
 #include <libavformat/avio.h>
 }
 
+#include <srt/srt.h>
+
 #include "shared/mux.h"
 #include "shared/ref_counted_gl_sync.h"
+#include "srt_metrics.h"
 
 class AudioEncoder;
 class AV1Encoder;
@@ -75,11 +79,16 @@ public:
        void change_x264_bitrate(unsigned rate_kbit);
 
 private:
-       void open_output_stream();
+       void open_output_streams();
        static int write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
        int write_packet2(uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time);
 
-       const AVOutputFormat *oformat;
+       static int write_srt_packet_thunk(void *opaque, uint8_t *buf, int buf_size);
+       int write_srt_packet(uint8_t *buf, int buf_size);
+       int open_srt_socket();  // Returns -1 on error.
+       int connect_to_srt();  // Returns -1 on error.
+
+       const AVOutputFormat *oformat, *srt_oformat;
        mutable std::mutex qs_mu, qs_audio_mu;
        std::unique_ptr<QuickSyncEncoder> quicksync_encoder;  // Under <qs_mu> _and_ <qs_audio_mu>.
        movit::ResourcePool *resource_pool;
@@ -91,7 +100,8 @@ private:
 
        bool seen_sync_markers = false;
 
-       std::unique_ptr<Mux> stream_mux;  // To HTTP.
+       std::unique_ptr<Mux> http_mux;  // To the HTTP server.
+       std::unique_ptr<Mux> srt_mux;  // To the SRT endpoint (if any).
        std::unique_ptr<AudioEncoder> stream_audio_encoder;
        std::unique_ptr<X264Encoder> x264_encoder;  // nullptr if not using x264.
        std::unique_ptr<X264Encoder> x264_disk_encoder;  // nullptr if not using x264, or if not having separate disk encodes.
@@ -99,11 +109,18 @@ private:
        std::unique_ptr<AV1Encoder> av1_encoder;  // nullptr if not using SVT-AV1.
 #endif
 
-       std::string stream_mux_header;
-       MuxMetrics stream_mux_metrics;
+       SRTSOCKET srt_sock = -1;
+
+       std::string http_mux_header;
+       MuxMetrics http_mux_metrics;
+       MuxMetrics srt_mux_metrics;
+       SRTMetrics srt_metrics;
+       std::atomic<int64_t> metric_srt_num_connection_attempts{0};
+       std::atomic<bool> want_srt_metric_update{true};  // Is nominally set every frame. Some racing is OK (this is mainly a rate-limiter).
 
        std::atomic<int> quicksync_encoders_in_shutdown{0};
        std::atomic<int> overriding_bitrate{0};
+       std::atomic<bool> should_quit{false};
 
        // Encoders that are shutdown, but need to call release_gl_resources()
        // (or be deleted) from some thread with an OpenGL context.