summaryrefslogtreecommitdiffstats
path: root/src/ManagementServer.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-02-25 16:26:04 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-02-25 16:26:04 +0100
commit691617b1b651abe3c0413ab4e9349e56c8cf54e5 (patch)
tree125b3cd307fb8a665e9c96431767cd732e195f4c /src/ManagementServer.cpp
parent9e1a5e0d5a6421628863c049619e12800670e79a (diff)
downloaddabmux-691617b1b651abe3c0413ab4e9349e56c8cf54e5.tar.gz
dabmux-691617b1b651abe3c0413ab4e9349e56c8cf54e5.tar.bz2
dabmux-691617b1b651abe3c0413ab4e9349e56c8cf54e5.zip
Fix issue that input stays in Unstable when it is prebuffering
Diffstat (limited to 'src/ManagementServer.cpp')
-rw-r--r--src/ManagementServer.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/ManagementServer.cpp b/src/ManagementServer.cpp
index 783a40b..16b7fbd 100644
--- a/src/ManagementServer.cpp
+++ b/src/ManagementServer.cpp
@@ -379,14 +379,7 @@ void InputStat::notifyBuffer(long bufsize)
const auto time_now = steady_clock::now();
m_buffer_fill_stats.push_front({time_now, bufsize});
- // Keep only stats whose timestamp are more recent than
- // BUFFER_STATS_KEEP_DURATION ago
- m_buffer_fill_stats.erase(remove_if(
- m_buffer_fill_stats.begin(), m_buffer_fill_stats.end(),
- [&](const fill_stat_t& fs) {
- return fs.timestamp + BUFFER_STATS_KEEP_DURATION < time_now;
- }),
- m_buffer_fill_stats.end());
+ prune_statistics(time_now);
}
void InputStat::notifyPeakLevels(int peak_left, int peak_right)
@@ -395,17 +388,9 @@ void InputStat::notifyPeakLevels(int peak_left, int peak_right)
using namespace std::chrono;
const auto time_now = steady_clock::now();
-
m_peak_stats.push_front({time_now, peak_left, peak_right});
- // Keep only stats whose timestamp are more recent than
- // BUFFER_STATS_KEEP_DURATION ago
- m_peak_stats.erase(remove_if(
- m_peak_stats.begin(), m_peak_stats.end(),
- [&](const peak_stat_t& ps) {
- return ps.timestamp + PEAK_STATS_KEEP_DURATION < time_now;
- }),
- m_peak_stats.end());
+ prune_statistics(time_now);
if (m_peak_stats.size() >= 2) {
// Calculate the peak over the short window
@@ -602,6 +587,8 @@ std::string InputStat::encodeValuesJSON()
input_state_t InputStat::determineState()
{
const auto now = std::chrono::steady_clock::now();
+ prune_statistics(now);
+
input_state_t state;
/* if the last event was more that INPUT_COUNTER_RESET_TIME
@@ -642,3 +629,24 @@ input_state_t InputStat::determineState()
return state;
}
+void InputStat::prune_statistics(const std::chrono::time_point<std::chrono::steady_clock>& time_now)
+{
+ // Keep only stats whose timestamp are more recent than
+ // BUFFER_STATS_KEEP_DURATION ago
+ m_buffer_fill_stats.erase(remove_if(
+ m_buffer_fill_stats.begin(), m_buffer_fill_stats.end(),
+ [&](const fill_stat_t& fs) {
+ return fs.timestamp + BUFFER_STATS_KEEP_DURATION < time_now;
+ }),
+ m_buffer_fill_stats.end());
+
+ // Keep only stats whose timestamp are more recent than
+ // BUFFER_STATS_KEEP_DURATION ago
+ m_peak_stats.erase(remove_if(
+ m_peak_stats.begin(), m_peak_stats.end(),
+ [&](const peak_stat_t& ps) {
+ return ps.timestamp + PEAK_STATS_KEEP_DURATION < time_now;
+ }),
+ m_peak_stats.end());
+}
+