X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=quicksync_encoder_impl.h;h=7645b99b6b34edf5e8afd83b91a6a9e7f981ba10;hb=330ca2f0052b06d91004c6ceb73cd57ab95e7fe1;hp=0dcb9cb0e0a3a374af7ca2a7eb5ecd90b26a0b41;hpb=48bb6f0c57bbc1b75349e995f8bb684f179719ed;p=nageru diff --git a/quicksync_encoder_impl.h b/quicksync_encoder_impl.h index 0dcb9cb..7645b99 100644 --- a/quicksync_encoder_impl.h +++ b/quicksync_encoder_impl.h @@ -19,6 +19,7 @@ #include "defs.h" #include "timebase.h" #include "print_latency.h" +#include "ref_counted_gl_sync.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 @@ -31,6 +32,23 @@ struct __bitstream { }; typedef struct __bitstream bitstream; +namespace movit { +class ResourcePool; +} +class DiskSpaceEstimator; +class QSurface; +class X264Encoder; + +struct VADisplayWithCleanup { + ~VADisplayWithCleanup(); + + VADisplay va_dpy; + Display *x11_display = nullptr; + bool can_use_zerocopy = true; + int drm_fd = -1; +}; +std::unique_ptr va_open_display(const std::string &va_display); // Can return nullptr on failure. + 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); @@ -121,10 +139,7 @@ private: int build_packed_seq_buffer(movit::YCbCrLumaCoefficients ycbcr_coefficients, unsigned char **header_buffer); int build_packed_slice_buffer(unsigned char **header_buffer); int init_va(const std::string &va_display); - int deinit_va(); void enable_zerocopy_if_possible(); - VADisplay va_open_display(const std::string &va_display); - void va_close_display(VADisplay va_dpy); int setup_encode(); void release_encode(); void update_ReferenceFrames(int current_display_frame, int frame_type); @@ -135,8 +150,7 @@ private: bool is_shutdown = false; bool has_released_gl_resources = false; - std::atomic use_zerocopy; - int drm_fd = -1; + std::atomic use_zerocopy{false}; std::thread encode_thread, storage_thread; @@ -170,10 +184,8 @@ private: Mux* stream_mux = nullptr; // To HTTP. std::unique_ptr file_mux; // To local disk. - Display *x11_display = nullptr; - // Encoder parameters - VADisplay va_dpy; + std::unique_ptr va_dpy; VAProfile h264_profile = (VAProfile)~0; VAConfigAttrib config_attrib[VAConfigAttribTypeMax]; int config_attrib_num = 0, enc_packed_header_idx;