]> git.sesse.net Git - nageru/blobdiff - mixer.h
Do some ALSA tweaks that will hopefully get rid of the underrun loops.
[nageru] / mixer.h
diff --git a/mixer.h b/mixer.h
index 01712b8f136a0b116cc27c3d603b2c3b2613e348..8f74cc53206300ff6ee3f036dbd99859489351f4 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -22,6 +22,7 @@
 #include <vector>
 
 #include "bmusb/bmusb.h"
+#include "alsa_output.h"
 #include "ebu_r128_proc.h"
 #include "h264encode.h"
 #include "httpd.h"
@@ -137,6 +138,16 @@ public:
                locut_cutoff_hz = cutoff_hz;
        }
 
+       float get_limiter_threshold_dbfs()
+       {
+               return limiter_threshold_dbfs;
+       }
+
+       float get_compressor_threshold_dbfs()
+       {
+               return compressor_threshold_dbfs;
+       }
+
        void set_limiter_threshold_dbfs(float threshold_dbfs)
        {
                limiter_threshold_dbfs = threshold_dbfs;
@@ -165,7 +176,8 @@ private:
                FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format);
        void place_rectangle(movit::Effect *resample_effect, movit::Effect *padding_effect, float x0, float y0, float x1, float y1);
        void thread_func();
-       void process_audio_one_frame();
+       void audio_thread_func();
+       void process_audio_one_frame(int64_t frame_pts_int);
        void subsample_chroma(GLuint src_tex, GLuint dst_dst);
        void release_display_frame(DisplayFrame *frame);
        double pts() { return double(pts_int) / TIMEBASE; }
@@ -229,7 +241,8 @@ private:
        OutputChannel output_channel[NUM_OUTPUTS];
 
        std::thread mixer_thread;
-       bool should_quit = false;
+       std::thread audio_thread;
+       std::atomic<bool> should_quit{false};
 
        audio_level_callback_t audio_level_callback = nullptr;
        Ebu_r128_proc r128;
@@ -247,11 +260,17 @@ private:
        static constexpr float ref_level_dbfs = -14.0f;
 
        StereoCompressor limiter;
-       std::atomic<float> limiter_threshold_dbfs{ref_level_dbfs + 0.0f};   // 0 dB.
+       std::atomic<float> limiter_threshold_dbfs{ref_level_dbfs + 4.0f};   // 4 dB.
        std::atomic<bool> limiter_enabled{true};
        StereoCompressor compressor;
        std::atomic<float> compressor_threshold_dbfs{ref_level_dbfs - 12.0f};  // -12 dB.
        std::atomic<bool> compressor_enabled{true};
+
+       std::unique_ptr<ALSAOutput> alsa;
+
+       std::mutex audio_mutex;
+       std::condition_variable audio_pts_queue_changed;
+       std::queue<int64_t> audio_pts_queue;
 };
 
 extern Mixer *global_mixer;