]> git.sesse.net Git - nageru/commitdiff
Do some hotfixes to reduce mutex contention (but this needs a rework).
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 28 Jun 2017 22:57:01 +0000 (00:57 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 28 Jun 2017 22:57:01 +0000 (00:57 +0200)
quicksync_encoder_impl.h
video_encoder.cpp

index 917420ca41af16a81ffdd3668bd6ea38f3fb78cc..85ac3ab980d525369e7f9c788d31dd0b8208ce78 100644 (file)
@@ -135,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;
index a622ba2af6640425d72dc5a72de44b4cc8f218e3..ec864d490dcdedfb67d3077ecc354d2856969d3a 100644 (file)
@@ -136,14 +136,17 @@ void VideoEncoder::change_x264_bitrate(unsigned rate_kbit)
 
 void VideoEncoder::add_audio(int64_t pts, std::vector<float> audio)
 {
-       lock_guard<mutex> lock(qs_mu);
-       quicksync_encoder->add_audio(pts, audio);
+       {
+               lock_guard<mutex> lock(qs_mu);
+               quicksync_encoder->add_audio(pts, audio);
+       }
        stream_audio_encoder->encode_audio(audio, pts + quicksync_encoder->global_delay());
 }
 
 bool VideoEncoder::is_zerocopy() const
 {
-       lock_guard<mutex> lock(qs_mu);
+       // Explicitly do _not_ take qs_mu; this is called from the mixer,
+       // and qs_mu might be contended. is_zerocopy() is thread safe.
        return quicksync_encoder->is_zerocopy();
 }