aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/edi/STIWriter.cpp2
-rw-r--r--src/ManagementServer.cpp42
-rw-r--r--src/ManagementServer.h3
-rw-r--r--src/input/Zmq.cpp22
-rw-r--r--src/input/Zmq.h3
5 files changed, 43 insertions, 29 deletions
diff --git a/lib/edi/STIWriter.cpp b/lib/edi/STIWriter.cpp
index b0e2bc2..389a838 100644
--- a/lib/edi/STIWriter.cpp
+++ b/lib/edi/STIWriter.cpp
@@ -127,6 +127,8 @@ void STIWriter::assemble()
stiFrame.timestamp.seconds = m_seconds;
stiFrame.timestamp.utco = m_utco;
stiFrame.timestamp.tsta = m_management_data.tsta;
+ stiFrame.audio_levels = m_audio_levels;
+ stiFrame.version_data = m_version_data;
m_frame_callback(move(stiFrame));
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());
+}
+
diff --git a/src/ManagementServer.h b/src/ManagementServer.h
index 5b52957..e88d233 100644
--- a/src/ManagementServer.h
+++ b/src/ManagementServer.h
@@ -107,6 +107,9 @@ class InputStat
private:
std::string m_name;
+ // Remove all expired fill and peak stats
+ void prune_statistics(const std::chrono::time_point<std::chrono::steady_clock>& timestamp);
+
/************ STATISTICS ***********/
// Keep track of buffer fill with timestamps, so that we
// can calculate the correct state from it.
diff --git a/src/input/Zmq.cpp b/src/input/Zmq.cpp
index 0a9d59d..603f514 100644
--- a/src/input/Zmq.cpp
+++ b/src/input/Zmq.cpp
@@ -268,7 +268,6 @@ size_t ZmqBase::readFrame(uint8_t* buffer, size_t size)
size_t over_max = m_frame_buffer.size() - m_config.prebuffering;
while (over_max--) {
- delete[] m_frame_buffer.front();
m_frame_buffer.pop_front();
}
}
@@ -288,7 +287,6 @@ size_t ZmqBase::readFrame(uint8_t* buffer, size_t size)
* frames even though we could drop less.
* */
for (int frame_del_count = 0; frame_del_count < 5; frame_del_count++) {
- delete[] m_frame_buffer.front();
m_frame_buffer.pop_front();
}
}
@@ -323,9 +321,11 @@ size_t ZmqBase::readFrame(uint8_t* buffer, size_t size)
}
else {
/* Normal situation, give a frame from the frame_buffer */
- uint8_t* newframe = m_frame_buffer.front();
- memcpy(buffer, newframe, size);
- delete[] newframe;
+ auto& newframe = m_frame_buffer.front();
+ if (newframe.size() != size) {
+ throw logic_error("Inconsistent ZMQ sizes");
+ }
+ memcpy(buffer, newframe.data(), newframe.size());
m_frame_buffer.pop_front();
return size;
}
@@ -388,9 +388,9 @@ int ZmqMPEG::readFromSocket(size_t framesize)
}
else if (m_enable_input) {
// copy the input frame blockwise into the frame_buffer
- auto framedata = new uint8_t[framesize];
- memcpy(framedata, data, framesize);
- m_frame_buffer.push_back(framedata);
+ vector<uint8_t> framedata(framesize);
+ copy(data, data + framesize, framedata.begin());
+ m_frame_buffer.push_back(move(framedata));
}
else {
return 0;
@@ -466,9 +466,9 @@ int ZmqAAC::readFromSocket(size_t framesize)
for (uint8_t* framestart = data;
framestart < &data[5*framesize];
framestart += framesize) {
- auto audioframe = new uint8_t[framesize];
- memcpy(audioframe, framestart, framesize);
- m_frame_buffer.push_back(audioframe);
+ vector<uint8_t> audioframe(framesize);
+ copy(framestart, framestart + framesize, audioframe.begin());
+ m_frame_buffer.push_back(move(audioframe));
}
}
else {
diff --git a/src/input/Zmq.h b/src/input/Zmq.h
index 2e37b5f..f4992f1 100644
--- a/src/input/Zmq.h
+++ b/src/input/Zmq.h
@@ -45,6 +45,7 @@
#include <list>
#include <string>
+#include <vector>
#include <cstdint>
#include "zmq.hpp"
#include "input/inputs.h"
@@ -212,7 +213,7 @@ class ZmqBase : public InputBase, public RemoteControllable {
bool m_enable_input;
/* stores elements of type char[<superframesize>] */
- std::list<uint8_t*> m_frame_buffer;
+ std::list<std::vector<uint8_t> > m_frame_buffer;
dab_input_zmq_config_t m_config;