summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-01 15:17:09 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-01 15:17:09 +0200
commitd617d4550eeb3a174ff2eb8d0bca2844af2cd9e7 (patch)
tree7be5c174bf3dfae0165581613e2f1d048cff1217 /src
parente0cf82871fe24348101a0b565ea309e074e3663b (diff)
downloaddabmux-d617d4550eeb3a174ff2eb8d0bca2844af2cd9e7.tar.gz
dabmux-d617d4550eeb3a174ff2eb8d0bca2844af2cd9e7.tar.bz2
dabmux-d617d4550eeb3a174ff2eb8d0bca2844af2cd9e7.zip
Use new EDI input API with callback
Diffstat (limited to 'src')
-rw-r--r--src/input/Edi.cpp33
-rw-r--r--src/input/Edi.h2
2 files changed, 17 insertions, 18 deletions
diff --git a/src/input/Edi.cpp b/src/input/Edi.cpp
index 4a499e1..f4b5e25 100644
--- a/src/input/Edi.cpp
+++ b/src/input/Edi.cpp
@@ -47,7 +47,7 @@ constexpr size_t TCP_BLOCKSIZE = 2048;
Edi::Edi(const std::string& name, const dab_input_edi_config_t& config) :
RemoteControllable(name),
m_tcp_receive_server(TCP_BLOCKSIZE),
- m_sti_writer(),
+ m_sti_writer(bind(&Edi::m_new_sti_frame_callback, this, placeholders::_1)),
m_sti_decoder(m_sti_writer, VERBOSE),
m_max_frames_overrun(config.buffer_size),
m_num_frames_prebuffering(config.prebuffering),
@@ -306,8 +306,6 @@ size_t Edi::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utc
void Edi::m_run()
{
while (m_running) {
- bool work_done = false;
-
switch (m_input_used) {
case InputUsed::UDP:
{
@@ -318,7 +316,9 @@ void Edi::m_run()
}
if (not packet.buffer.empty()) {
m_sti_decoder.push_packet(packet.buffer);
- work_done = true;
+ }
+ else {
+ this_thread::sleep_for(chrono::milliseconds(12));
}
}
break;
@@ -327,27 +327,24 @@ void Edi::m_run()
auto packet = m_tcp_receive_server.receive();
if (not packet.empty()) {
m_sti_decoder.push_bytes(packet);
- work_done = true;
+ }
+ else {
+ this_thread::sleep_for(chrono::milliseconds(12));
}
}
break;
default:
throw logic_error("unimplemented input");
}
+ }
+}
- const auto sti = m_sti_writer.getFrame();
- if (not sti.frame.empty()) {
- // We should not wait here, because we want the complete input buffering
- // happening inside m_frames. Using the blocking function is only a protection
- // against runaway memory usage if something goes wrong in the consumer.
- m_frames.push_wait_if_full(move(sti), m_max_frames_overrun * 2);
- work_done = true;
- }
-
- if (not work_done) {
- // Avoid fast loop
- this_thread::sleep_for(chrono::milliseconds(12));
- }
+void Edi::m_new_sti_frame_callback(EdiDecoder::sti_frame_t&& sti) {
+ if (not sti.frame.empty()) {
+ // We should not wait here, because we want the complete input buffering
+ // happening inside m_frames. Using the blocking function is only a protection
+ // against runaway memory usage if something goes wrong in the consumer.
+ m_frames.push_wait_if_full(move(sti), m_max_frames_overrun * 2);
}
}
diff --git a/src/input/Edi.h b/src/input/Edi.h
index 6f8c013..ed4d7cf 100644
--- a/src/input/Edi.h
+++ b/src/input/Edi.h
@@ -82,6 +82,8 @@ class Edi : public InputBase, public RemoteControllable {
protected:
void m_run();
+ void m_new_sti_frame_callback(EdiDecoder::sti_frame_t&& frame);
+
std::mutex m_mutex;
enum class InputUsed { Invalid, UDP, TCP };