From bf82967d4c04946ae6e0490ea28e160a856fc81b Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 29 Oct 2018 15:35:13 +0100 Subject: Rework inputstat to use absolute timestamps internally --- src/ManagementServer.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/ManagementServer.h') diff --git a/src/ManagementServer.h b/src/ManagementServer.h index 17b8bda..18af48c 100644 --- a/src/ManagementServer.h +++ b/src/ManagementServer.h @@ -107,28 +107,34 @@ class InputStat std::string m_name; /************ STATISTICS ***********/ - // Calculate minimum and maximum buffer fill from - // a FIFO of values from the last few seconds - std::deque m_buffer_fill_stats; - std::chrono::time_point m_time_last_buffer_notify; + // Keep track of buffer fill with timestamps, so that we + // can calculate the correct state from it. + struct fill_stat_t { + std::chrono::time_point timestamp; + long bufsize; + }; + std::deque m_buffer_fill_stats; // counter of number of overruns and underruns since startup - uint32_t m_num_underruns; - uint32_t m_num_overruns; + uint32_t m_num_underruns = 0; + uint32_t m_num_overruns = 0; // Peak audio levels (linear 16-bit PCM) for the two channels. // Keep a FIFO of values from the last minutes, apply // a short window to also see short-term fluctuations. - std::deque m_peaks_left; - std::deque m_peaks_right; - std::chrono::time_point m_time_last_peak_notify; + struct peak_stat_t { + std::chrono::time_point timestamp; + int peak_left; + int peak_right; + }; + std::deque m_peak_stats; size_t m_short_window_length = 0; /************* STATE ***************/ /* Variables used for determining the input state */ - int m_glitch_counter; // saturating counter - int m_silence_counter; // saturating counter + int m_glitch_counter = 0; // saturating counter + int m_silence_counter = 0; // saturating counter std::chrono::time_point m_time_last_event; // The mutex that has to be held during all notify and readout -- cgit v1.2.3