]> git.sesse.net Git - nageru/commitdiff
Set one fence less in the case of non-zerocopy H.264 encoding.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 12 Apr 2016 17:21:30 +0000 (19:21 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 12 Apr 2016 17:21:30 +0000 (19:21 +0200)
h264encode.cpp
h264encode.h
mixer.cpp

index f4f643284d1ce95e5cb40e3a63dbd03979ad5b42..c923f475a94e7720316aa29d4aef3ee60549fead 100644 (file)
@@ -196,7 +196,7 @@ public:
        ~H264EncoderImpl();
        void add_audio(int64_t pts, vector<float> audio);
        bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex);
-       void end_frame(RefCountedGLsync fence, int64_t pts, const vector<RefCountedFrame> &input_frames);
+       RefCountedGLsync end_frame(int64_t pts, const vector<RefCountedFrame> &input_frames);
        void shutdown();
 
 private:
@@ -1879,7 +1879,7 @@ void H264EncoderImpl::add_audio(int64_t pts, vector<float> audio)
        frame_queue_nonempty.notify_all();
 }
 
-void H264EncoderImpl::end_frame(RefCountedGLsync fence, int64_t pts, const vector<RefCountedFrame> &input_frames)
+RefCountedGLsync H264EncoderImpl::end_frame(int64_t pts, const vector<RefCountedFrame> &input_frames)
 {
        assert(!is_shutdown);
 
@@ -1909,16 +1909,18 @@ void H264EncoderImpl::end_frame(RefCountedGLsync fence, int64_t pts, const vecto
 
                glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT | GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
                check_error();
-               fence = RefCountedGLsync(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
-               check_error();
        }
 
+       RefCountedGLsync fence = RefCountedGLsync(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
+       check_error();
+
        {
                unique_lock<mutex> lock(frame_queue_mutex);
                pending_video_frames[current_storage_frame] = PendingFrame{ fence, input_frames, pts };
                ++current_storage_frame;
        }
        frame_queue_nonempty.notify_all();
+       return fence;
 }
 
 void H264EncoderImpl::shutdown()
@@ -2147,9 +2149,9 @@ bool H264Encoder::begin_frame(GLuint *y_tex, GLuint *cbcr_tex)
        return impl->begin_frame(y_tex, cbcr_tex);
 }
 
-void H264Encoder::end_frame(RefCountedGLsync fence, int64_t pts, const vector<RefCountedFrame> &input_frames)
+RefCountedGLsync H264Encoder::end_frame(int64_t pts, const vector<RefCountedFrame> &input_frames)
 {
-       impl->end_frame(fence, pts, input_frames);
+       return impl->end_frame(pts, input_frames);
 }
 
 void H264Encoder::shutdown()
index 0d70524e76d5a73d01977e1852a434a59280e947..43a56c609c147448d834751b5e81a89bcf9c1cdc 100644 (file)
@@ -50,7 +50,7 @@ public:
 
        void add_audio(int64_t pts, std::vector<float> audio);
        bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex);
-       void end_frame(RefCountedGLsync fence, int64_t pts, const std::vector<RefCountedFrame> &input_frames);
+       RefCountedGLsync end_frame(int64_t pts, const std::vector<RefCountedFrame> &input_frames);
        void shutdown();  // Blocking.
 
 private:
index 4e3d486efdb9d816146506b5af7fee48bf954735..08d2d0140b6afffa501df67936ef6aa30ea7a72c 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -795,11 +795,8 @@ void Mixer::render_one_frame()
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
-       RefCountedGLsync fence(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
-       check_error();
-
        const int64_t av_delay = TIMEBASE / 10;  // Corresponds to the fixed delay in resampling_queue.h. TODO: Make less hard-coded.
-       h264_encoder->end_frame(fence, pts_int + av_delay, theme_main_chain.input_frames);
+       RefCountedGLsync fence = h264_encoder->end_frame(pts_int + av_delay, theme_main_chain.input_frames);
 
        // The live frame just shows the RGBA texture we just rendered.
        // It owns rgba_tex now.