From: Steinar H. Gunderson Date: Sun, 22 Nov 2015 22:39:36 +0000 (+0100) Subject: Fix a race on the r128 object. X-Git-Tag: 1.0.0~87 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=b22d8d6b38d060ccc5dfa591712211caf9ca3968 Fix a race on the r128 object. --- diff --git a/mixer.cpp b/mixer.cpp index 57cd5bd..04a3553 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -493,6 +493,7 @@ void Mixer::thread_func() } if (audio_level_callback != nullptr) { + unique_lock lock(r128_mutex); double loudness_s = r128.loudness_S(); double loudness_i = r128.integrated(); double loudness_range_low = r128.range_min(); @@ -743,7 +744,10 @@ void Mixer::process_audio_one_frame(int64_t frame_pts_int, int num_samples) vector left, right; deinterleave_samples(samples_out, &left, &right); float *ptrs[] = { left.data(), right.data() }; - r128.process(left.size(), ptrs); + { + unique_lock lock(r128_mutex); + r128.process(left.size(), ptrs); + } // Send the samples to the sound card. if (alsa) { diff --git a/mixer.h b/mixer.h index b9acfc4..07a31e9 100644 --- a/mixer.h +++ b/mixer.h @@ -268,7 +268,8 @@ private: std::atomic should_quit{false}; audio_level_callback_t audio_level_callback = nullptr; - Ebu_r128_proc r128; + std::mutex r128_mutex; + Ebu_r128_proc r128; // Under r128_mutex. Resampler peak_resampler; std::atomic peak{0.0f};