]> git.sesse.net Git - nageru/commitdiff
Fix a race on the r128 object.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 22 Nov 2015 22:39:36 +0000 (23:39 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 22 Nov 2015 22:39:36 +0000 (23:39 +0100)
mixer.cpp
mixer.h

index 57cd5bdaf2d30daeabc370bffdffaa7703239ef7..04a35530cc7af36d7681d1aca2ebef695be960e0 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -493,6 +493,7 @@ void Mixer::thread_func()
                }
 
                if (audio_level_callback != nullptr) {
+                       unique_lock<mutex> 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<float> left, right;
        deinterleave_samples(samples_out, &left, &right);
        float *ptrs[] = { left.data(), right.data() };
-       r128.process(left.size(), ptrs);
+       {
+               unique_lock<mutex> 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 b9acfc4c607e2a9b880ef8dea5bc7867da9fa286..07a31e959fe5a21e2b268ed7f4aad11e0ac2e90a 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -268,7 +268,8 @@ private:
        std::atomic<bool> 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<float> peak{0.0f};