]> git.sesse.net Git - nageru/blobdiff - nageru/quicksync_encoder_impl.h
Fix a Clang 19 warning.
[nageru] / nageru / quicksync_encoder_impl.h
index 0800c5956b758466234560fba3b24ec79fd37585..6d8463db76aef4e3a897a35e9aff49e9c8891e7d 100644 (file)
@@ -1,28 +1,39 @@
 #ifndef _QUICKSYNC_ENCODER_IMPL_H
 #define _QUICKSYNC_ENCODER_IMPL_H 1
 
+#include <stddef.h>
+#include <stdint.h>
 #include <epoxy/egl.h>
+#include <epoxy/gl.h>
 #include <movit/image_format.h>
 #include <va/va.h>
+#include <va/va_enc_h264.h>
 
+#include <atomic>
 #include <condition_variable>
+#include <deque>
 #include <map>
 #include <memory>
 #include <mutex>
 #include <queue>
 #include <string>
-#include <stack>
 #include <thread>
 #include <unordered_map>
+#include <vector>
 
 #include "audio_encoder.h"
 #include "defs.h"
 #include "shared/timebase.h"
 #include "print_latency.h"
+#include "ref_counted_frame.h"
 #include "shared/ref_counted_gl_sync.h"
-#include "va_display_with_cleanup.h"
+#include "shared/va_display.h"
 #include "v4l_output.h"
 
+extern "C" {
+#include <libavformat/avformat.h>
+}
+
 #define SURFACE_NUM 16 /* 16 surfaces for source YUV */
 #define MAX_NUM_REF1 16 // Seemingly a hardware-fixed value, not related to SURFACE_NUM
 #define MAX_NUM_REF2 32 // Seemingly a hardware-fixed value, not related to SURFACE_NUM
@@ -39,11 +50,11 @@ class ResourcePool;
 }
 class DiskSpaceEstimator;
 class QSurface;
-class X264Encoder;
+class VideoCodecInterface;
 
 class QuickSyncEncoderImpl {
 public:
-       QuickSyncEncoderImpl(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const std::string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder, DiskSpaceEstimator *disk_space_estimator);
+       QuickSyncEncoderImpl(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const std::string &va_display, int width, int height, const AVOutputFormat *oformat, VideoCodecInterface *http_encoder, VideoCodecInterface *disk_encoder, DiskSpaceEstimator *disk_space_estimator);
        ~QuickSyncEncoderImpl();
        void add_audio(int64_t pts, std::vector<float> audio);
        bool is_zerocopy() const;
@@ -52,14 +63,18 @@ public:
        void shutdown();
        void close_file();
        void release_gl_resources();
-       void set_stream_mux(Mux *mux)
+       void set_http_mux(Mux *mux)
+       {
+               http_mux = mux;
+       }
+       void set_srt_mux(Mux *mux)
        {
-               stream_mux = mux;
+               srt_mux = mux;
        }
 
        // So we never get negative dts.
        int64_t global_delay() const {
-               return int64_t(ip_period - 1) * (TIMEBASE / MAX_FPS);
+               return int64_t(ip_period - 1) * (TIMEBASE / TYPICAL_FPS);
        }
 
 private:
@@ -111,7 +126,6 @@ private:
        void open_output_file(const std::string &filename);
        void encode_thread_func();
        void encode_remaining_frames_as_p(int encoding_frame_num, int gop_start_display_frame_num, int64_t last_dts);
-       void add_packet_for_uncompressed_frame(int64_t pts, int64_t duration, const uint8_t *data);
        void pass_frame(PendingFrame frame, int display_frame_num, int64_t pts, int64_t duration);
        void encode_frame(PendingFrame frame, int encoding_frame_num, int display_frame_num, int gop_start_display_frame_num,
                          int frame_type, int64_t pts, int64_t dts, int64_t duration, movit::YCbCrLumaCoefficients ycbcr_coefficients);
@@ -171,10 +185,12 @@ private:
        std::mutex file_audio_encoder_mutex;
        std::unique_ptr<AudioEncoder> file_audio_encoder;
 
-       X264Encoder *x264_encoder;  // nullptr if not using x264.
+       VideoCodecInterface *http_encoder;  // nullptr if not using x264/SVT-AV1.
+       VideoCodecInterface *disk_encoder;
        std::unique_ptr<V4LOutput> v4l_output;  // nullptr if not using V4L2 output.
 
-       Mux* stream_mux = nullptr;  // To HTTP.
+       Mux* http_mux = nullptr;  // To the HTTP server.
+       Mux* srt_mux = nullptr;  // To the remote SRT endpoint, if any.
        std::unique_ptr<Mux> file_mux;  // To local disk.
 
        // Encoder parameters
@@ -209,7 +225,7 @@ private:
        static constexpr int initial_qp = 15;
        static constexpr int minimal_qp = 0;
        static constexpr int intra_period = 30;
-       static constexpr int intra_idr_period = MAX_FPS;  // About a second; more at lower frame rates. Not ideal.
+       static constexpr int intra_idr_period = TYPICAL_FPS;  // About a second; more at lower frame rates. Not ideal.
 
        // Quality settings that are meant to be static, but might be overridden
        // by the profile.