From 5eb4be2bd63d1590eac0e018f23bf00856b90194 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 29 Jun 2017 00:57:01 +0200 Subject: [PATCH] Do some hotfixes to reduce mutex contention (but this needs a rework). --- quicksync_encoder_impl.h | 2 +- video_encoder.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/quicksync_encoder_impl.h b/quicksync_encoder_impl.h index 917420c..85ac3ab 100644 --- a/quicksync_encoder_impl.h +++ b/quicksync_encoder_impl.h @@ -135,7 +135,7 @@ private: bool is_shutdown = false; bool has_released_gl_resources = false; - bool use_zerocopy; + std::atomic use_zerocopy; int drm_fd = -1; std::thread encode_thread, storage_thread; diff --git a/video_encoder.cpp b/video_encoder.cpp index a622ba2..ec864d4 100644 --- a/video_encoder.cpp +++ b/video_encoder.cpp @@ -136,14 +136,17 @@ void VideoEncoder::change_x264_bitrate(unsigned rate_kbit) void VideoEncoder::add_audio(int64_t pts, std::vector audio) { - lock_guard lock(qs_mu); - quicksync_encoder->add_audio(pts, audio); + { + lock_guard 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 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(); } -- 2.39.2