X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fvideo_encoder.h;h=1c2a9491148c50d1deeed8dacbe84b50b43fe627;hb=8acd52c4ad9cd890bc689601775255e55912783f;hp=76dd92fa12cb12ef7dc2d439f9f335d75dcaf6b4;hpb=eeda8995329601f9f4e35047358400833eeae68e;p=nageru diff --git a/nageru/video_encoder.h b/nageru/video_encoder.h index 76dd92f..1c2a949 100644 --- a/nageru/video_encoder.h +++ b/nageru/video_encoder.h @@ -14,16 +14,21 @@ #include #include #include +#include extern "C" { #include #include } +#include + #include "shared/mux.h" #include "shared/ref_counted_gl_sync.h" +#include "srt_metrics.h" class AudioEncoder; +class AV1Encoder; class DiskSpaceEstimator; class HTTPD; class Mux; @@ -51,7 +56,7 @@ public: // // The semantics of y_tex and cbcr_tex depend on is_zerocopy(): // - // - If false, the are input parameters, ie., the caller + // - If false, they are input parameters, ie., the caller // allocates textures. (The contents are not read before // end_frame() is called.) // - If true, they are output parameters, ie., VideoEncoder @@ -74,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); - 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 quicksync_encoder; // Under _and_ . movit::ResourcePool *resource_pool; @@ -90,15 +100,27 @@ private: bool seen_sync_markers = false; - std::unique_ptr stream_mux; // To HTTP. + std::unique_ptr http_mux; // To the HTTP server. + std::unique_ptr srt_mux; // To the SRT endpoint (if any). std::unique_ptr stream_audio_encoder; std::unique_ptr x264_encoder; // nullptr if not using x264. + std::unique_ptr x264_disk_encoder; // nullptr if not using x264, or if not having separate disk encodes. +#ifdef HAVE_AV1 + std::unique_ptr av1_encoder; // nullptr if not using SVT-AV1. +#endif + + SRTSOCKET srt_sock = -1; - std::string stream_mux_header; - MuxMetrics stream_mux_metrics; + std::string http_mux_header; + MuxMetrics http_mux_metrics; + MuxMetrics srt_mux_metrics; + SRTMetrics srt_metrics; + std::atomic metric_srt_num_connection_attempts{0}; + std::atomic want_srt_metric_update{true}; // Is nominally set every frame. Some racing is OK (this is mainly a rate-limiter). std::atomic quicksync_encoders_in_shutdown{0}; std::atomic overriding_bitrate{0}; + std::atomic should_quit{false}; // Encoders that are shutdown, but need to call release_gl_resources() // (or be deleted) from some thread with an OpenGL context.