]> git.sesse.net Git - nageru/blobdiff - quicksync_encoder_impl.h
Fix some compiler warnings.
[nageru] / quicksync_encoder_impl.h
index b55edbbc58c6586ff8645fe3b0fbdd08844212f4..bc84e0adc7280beadb9e11ad1ee278eec59ac1ec 100644 (file)
@@ -2,6 +2,7 @@
 #define _QUICKSYNC_ENCODER_IMPL_H 1
 
 #include <epoxy/egl.h>
+#include <movit/image_format.h>
 #include <va/va.h>
 
 #include <condition_variable>
@@ -35,9 +36,11 @@ 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();
        void add_audio(int64_t pts, std::vector<float> audio);
-       bool begin_frame(int64_t pts, int64_t duration, const std::vector<RefCountedFrame> &input_frames, GLuint *y_tex, GLuint *cbcr_tex);
+       bool is_zerocopy() const;
+       bool begin_frame(int64_t pts, int64_t duration, movit::YCbCrLumaCoefficients ycbcr_coefficients, const std::vector<RefCountedFrame> &input_frames, GLuint *y_tex, GLuint *cbcr_tex);
        RefCountedGLsync end_frame();
        void shutdown();
+       void close_file();
        void release_gl_resources();
        void set_stream_mux(Mux *mux)
        {
@@ -55,6 +58,7 @@ private:
                int frame_type;
                std::vector<float> audio;
                int64_t pts, dts, duration;
+               movit::YCbCrLumaCoefficients ycbcr_coefficients;
                ReceivedTimestamps received_ts;
                std::vector<size_t> ref_display_frame_numbers;
        };
@@ -62,15 +66,16 @@ private:
                RefCountedGLsync fence;
                std::vector<RefCountedFrame> input_frames;
                int64_t pts, duration;
+               movit::YCbCrLumaCoefficients ycbcr_coefficients;
        };
        struct GLSurface {
+               // Only if x264_video_to_disk == false.
                VASurfaceID src_surface, ref_surface;
                VABufferID coded_buf;
-
                VAImage surface_image;
-               GLuint y_tex, cbcr_tex;
 
-               // Only if use_zerocopy == true.
+               // Only if use_zerocopy == true (which implies x264_video_to_disk == false).
+               GLuint y_tex, cbcr_tex;
                EGLImage y_egl_image, cbcr_egl_image;
 
                // Only if use_zerocopy == false.
@@ -99,21 +104,21 @@ private:
        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);
+                         int frame_type, int64_t pts, int64_t dts, int64_t duration, movit::YCbCrLumaCoefficients ycbcr_coefficients);
        void storage_task_thread();
        void storage_task_enqueue(storage_task task);
        void save_codeddata(GLSurface *surf, storage_task task);
-       int render_packedsequence();
+       int render_packedsequence(movit::YCbCrLumaCoefficients ycbcr_coefficients);
        int render_packedpicture();
        void render_packedslice();
        int render_sequence();
        int render_picture(GLSurface *surf, int frame_type, int display_frame_num, int gop_start_display_frame_num);
-       void sps_rbsp(bitstream *bs);
+       void sps_rbsp(movit::YCbCrLumaCoefficients ycbcr_coefficients, bitstream *bs);
        void pps_rbsp(bitstream *bs);
        int build_packed_pic_buffer(unsigned char **header_buffer);
        int render_slice(int encoding_frame_num, int display_frame_num, int gop_start_display_frame_num, int frame_type);
        void slice_header(bitstream *bs);
-       int build_packed_seq_buffer(unsigned char **header_buffer);
+       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();
@@ -130,7 +135,7 @@ private:
 
        bool is_shutdown = false;
        bool has_released_gl_resources = false;
-       bool use_zerocopy;
+       std::atomic<bool> use_zerocopy;
        int drm_fd = -1;
 
        std::thread encode_thread, storage_thread;
@@ -157,6 +162,7 @@ private:
        std::map<int, PendingFrame> reorder_buffer;
        int quicksync_encoding_frame_num = 0;
 
+       std::mutex file_audio_encoder_mutex;
        std::unique_ptr<AudioEncoder> file_audio_encoder;
 
        X264Encoder *x264_encoder;  // nullptr if not using x264.