aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2021-02-15 10:45:46 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2021-02-15 10:45:46 +0100
commit02650f3f087ae3cc9fd6ae0aaf011aea2bf177df (patch)
tree67524c29877a5ccd46e47d916b0c2ae355b61a9a
parent6bfd16f561c292fec0b42316f3c22d901ef038ed (diff)
downloadODR-EDI2EDI-02650f3f087ae3cc9fd6ae0aaf011aea2bf177df.tar.gz
ODR-EDI2EDI-02650f3f087ae3cc9fd6ae0aaf011aea2bf177df.tar.bz2
ODR-EDI2EDI-02650f3f087ae3cc9fd6ae0aaf011aea2bf177df.zip
Common fc2902b: Replace EDI interleaver by improved EDI spreading
-rw-r--r--Makefile.am2
-rw-r--r--lib/edioutput/EDIConfig.h5
-rw-r--r--lib/edioutput/Interleaver.cpp122
-rw-r--r--lib/edioutput/Interleaver.h75
-rw-r--r--lib/edioutput/Transport.cpp83
-rw-r--r--lib/edioutput/Transport.h8
-rw-r--r--src/main.cpp15
7 files changed, 53 insertions, 257 deletions
diff --git a/Makefile.am b/Makefile.am
index 78e3690..219522e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,8 +31,6 @@ odr_edi2edi_SOURCES = src/main.cpp \
lib/edioutput/AFPacket.cpp \
lib/edioutput/AFPacket.h \
lib/edioutput/EDIConfig.h \
- lib/edioutput/Interleaver.cpp \
- lib/edioutput/Interleaver.h \
lib/edioutput/PFT.cpp \
lib/edioutput/PFT.h \
lib/edioutput/TagItems.cpp \
diff --git a/lib/edioutput/EDIConfig.h b/lib/edioutput/EDIConfig.h
index 647d77e..be6c9c4 100644
--- a/lib/edioutput/EDIConfig.h
+++ b/lib/edioutput/EDIConfig.h
@@ -71,10 +71,11 @@ struct configuration_t {
bool enable_pft = false; // Enable protection and fragmentation
unsigned int tagpacket_alignment = 0;
std::vector<std::shared_ptr<destination_t> > destinations;
- unsigned int latency_frames = 0; // if nonzero, enable interleaver with a latency of latency_frames * 24ms
+ double fragment_spreading_factor = 0.95;
+ // Spread transmission of fragments in time. 1.0 = 100% means spreading over the whole duration of a frame (24ms)
+ // Above 100% means that the fragments are spread over several 24ms periods, interleaving the AF packets.
bool enabled() const { return destinations.size() > 0; }
- bool interleaver_enabled() const { return latency_frames > 0; }
void print() const;
};
diff --git a/lib/edioutput/Interleaver.cpp b/lib/edioutput/Interleaver.cpp
deleted file mode 100644
index f26a50e..0000000
--- a/lib/edioutput/Interleaver.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- Copyright (C) 2017
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output,
- Interleaving of PFT fragments to increase robustness against
- burst packet loss.
-
- This is possible because EDI has to assume that fragments may reach
- the receiver out of order.
-
- */
-/*
- This file is part of ODR-DabMux.
-
- ODR-DabMux is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- ODR-DabMux is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "Interleaver.h"
-#include <cassert>
-
-namespace edi {
-
-void Interleaver::SetLatency(size_t latency_frames)
-{
- m_latency = latency_frames;
-}
-
-Interleaver::fragment_vec Interleaver::Interleave(fragment_vec &fragments)
-{
- m_fragment_count = fragments.size();
-
- // Create vectors containing Fcount*latency fragments in total
- // and store them into the deque
- if (m_buffer.empty()) {
- m_buffer.emplace_back();
- }
-
- auto& last_buffer = m_buffer.back();
-
- for (auto& fragment : fragments) {
- const bool last_buffer_is_complete =
- (last_buffer.size() >= m_fragment_count * m_latency);
-
- if (last_buffer_is_complete) {
- m_buffer.emplace_back();
- last_buffer = m_buffer.back();
- }
-
- last_buffer.push_back(std::move(fragment));
- }
-
- fragments.clear();
-
- while ( not m_buffer.empty() and
- (m_buffer.front().size() >= m_fragment_count * m_latency)) {
-
- auto& first_buffer = m_buffer.front();
-
- assert(first_buffer.size() == m_fragment_count * m_latency);
-
- /* Assume we have 5 fragments per AF frame, and latency of 3.
- * This will give the following strides:
- * 0 1 2
- * +-------+-------+---+
- * | 0 1 | 2 3 | 4 |
- * | | +---+ |
- * | 5 6 | 7 | 8 9 |
- * | +---+ | |
- * |10 |11 12 |13 14 |
- * +---+-------+-------+
- *
- * ix will be 0, 5, 10, 1, 6 in the first loop
- */
-
- for (size_t i = 0; i < m_fragment_count; i++) {
- const size_t ix = m_interleave_offset + m_fragment_count * m_stride;
- m_interleaved_fragments.push_back(first_buffer.at(ix));
-
- m_stride += 1;
- if (m_stride >= m_latency) {
- m_interleave_offset++;
- m_stride = 0;
- }
- }
-
- if (m_interleave_offset >= m_fragment_count) {
- m_interleave_offset = 0;
- m_stride = 0;
- m_buffer.pop_front();
- }
- }
-
- std::vector<PFTFragment> interleaved_frags;
-
- const size_t n = std::min(m_fragment_count, m_interleaved_fragments.size());
- std::move(m_interleaved_fragments.begin(),
- m_interleaved_fragments.begin() + n,
- std::back_inserter(interleaved_frags));
- m_interleaved_fragments.erase(
- m_interleaved_fragments.begin(),
- m_interleaved_fragments.begin() + n);
-
- return interleaved_frags;
-}
-
-}
-
-
diff --git a/lib/edioutput/Interleaver.h b/lib/edioutput/Interleaver.h
deleted file mode 100644
index 3029d5d..0000000
--- a/lib/edioutput/Interleaver.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- Copyright (C) 2017
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output,
- Interleaving of PFT fragments to increase robustness against
- burst packet loss.
-
- This is possible because EDI has to assume that fragments may reach
- the receiver out of order.
-
- */
-/*
- This file is part of the ODR-mmbTools.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include <vector>
-#include <deque>
-#include <stdexcept>
-#include <cstdint>
-#include "Log.h"
-#include "PFT.h"
-
-namespace edi {
-
-class Interleaver {
- public:
- using fragment_vec = std::vector<PFTFragment>;
-
- /* Configure the interleaver to use latency_frames number of AF
- * packets for interleaving. Total delay through the interleaver
- * will be latency_frames * 24ms
- */
- void SetLatency(size_t latency_frames);
-
- /* Move the fragments for an AF Packet into the interleaver and
- * return interleaved fragments to be transmitted.
- */
- fragment_vec Interleave(fragment_vec &fragments);
-
- private:
- size_t m_latency = 0;
- size_t m_fragment_count = 0;
- size_t m_interleave_offset = 0;
- size_t m_stride = 0;
-
- /* Buffer that accumulates enough fragments to interleave */
- std::deque<fragment_vec> m_buffer;
-
- /* Buffer that contains fragments that have been interleaved,
- * to avoid that the interleaver output is too bursty
- */
- std::deque<PFTFragment> m_interleaved_fragments;
-};
-
-}
-
diff --git a/lib/edioutput/Transport.cpp b/lib/edioutput/Transport.cpp
index f8e5dc7..fd7e2b7 100644
--- a/lib/edioutput/Transport.cpp
+++ b/lib/edioutput/Transport.cpp
@@ -57,9 +57,6 @@ void configuration_t::print() const
throw logic_error("EDI destination not implemented");
}
}
- if (interleaver_enabled()) {
- etiLog.level(info) << " interleave " << latency_frames * 24 << " ms";
- }
}
@@ -96,10 +93,6 @@ Sender::Sender(const configuration_t& conf) :
}
}
- if (m_conf.interleaver_enabled()) {
- edi_interleaver.SetLatency(m_conf.latency_frames);
- }
-
if (m_conf.dump) {
edi_debug_file.open("./edi.debug");
}
@@ -119,57 +112,63 @@ void Sender::write(const TagPacket& tagpacket)
vector<edi::PFTFragment> edi_fragments = edi_pft.Assemble(af_packet);
if (m_conf.verbose) {
- fprintf(stderr, "EDI Output: Number of PFT fragment before interleaver %zu\n",
- edi_fragments.size());
- }
-
- if (m_conf.interleaver_enabled()) {
- edi_fragments = edi_interleaver.Interleave(edi_fragments);
- }
-
- if (m_conf.verbose) {
fprintf(stderr, "EDI Output: Number of PFT fragments %zu\n",
edi_fragments.size());
}
/* Spread out the transmission of all fragments over 25% of the 24ms AF packet duration
- * to reduce the risk of losing a burst of fragments because of congestion.
- *
- * 25% was chosen so that other outputs still have time to do their thing. */
- auto inter_fragment_wait_time = std::chrono::microseconds(0);
+ * to reduce the risk of losing a burst of fragments because of congestion. */
+ using namespace std::chrono;
+ auto inter_fragment_wait_time = microseconds(0);
if (edi_fragments.size() > 1) {
- inter_fragment_wait_time = std::chrono::microseconds(llrint(0.25 * 24000.0 / edi_fragments.size()));
+ inter_fragment_wait_time = microseconds(
+ llrint(m_conf.fragment_spreading_factor * 24000.0 / edi_fragments.size())
+ );
}
- // Send over ethernet
+ /* Separate insertion into map and transmission so as to make spreading possible */
+ const auto now = steady_clock::now();
+ auto tp = now;
for (auto& edi_frag : edi_fragments) {
- if (m_conf.dump) {
- ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
- copy(edi_frag.begin(), edi_frag.end(), debug_iterator);
- }
+ m_pending_frames[tp] = move(edi_frag);
+ tp += inter_fragment_wait_time;
+ }
- for (auto& dest : m_conf.destinations) {
- if (const auto& udp_dest = dynamic_pointer_cast<edi::udp_destination_t>(dest)) {
- Socket::InetAddress addr;
- addr.resolveUdpDestination(udp_dest->dest_addr, udp_dest->dest_port);
+ // Send over ethernet
+ for (auto it = m_pending_frames.begin(); it != m_pending_frames.end(); ) {
+ const auto& edi_frag = it->second;
- udp_sockets.at(udp_dest.get())->send(edi_frag, addr);
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_server_t>(dest)) {
- tcp_dispatchers.at(tcp_dest.get())->write(edi_frag);
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_client_t>(dest)) {
- tcp_senders.at(tcp_dest.get())->sendall(edi_frag);
+ if (it->first <= now) {
+ if (m_conf.dump) {
+ ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
+ copy(edi_frag.begin(), edi_frag.end(), debug_iterator);
}
- else {
- throw logic_error("EDI destination not implemented");
+
+ for (auto& dest : m_conf.destinations) {
+ if (const auto& udp_dest = dynamic_pointer_cast<edi::udp_destination_t>(dest)) {
+ Socket::InetAddress addr;
+ addr.resolveUdpDestination(udp_dest->dest_addr, udp_dest->dest_port);
+
+ udp_sockets.at(udp_dest.get())->send(edi_frag, addr);
+ }
+ else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_server_t>(dest)) {
+ tcp_dispatchers.at(tcp_dest.get())->write(edi_frag);
+ }
+ else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_client_t>(dest)) {
+ tcp_senders.at(tcp_dest.get())->sendall(edi_frag);
+ }
+ else {
+ throw logic_error("EDI destination not implemented");
+ }
}
+ it = m_pending_frames.erase(it);
+ }
+ else {
+ ++it;
}
-
- std::this_thread::sleep_for(inter_fragment_wait_time);
}
}
- else {
+ else /* PFT disabled */ {
// Send over ethernet
if (m_conf.dump) {
ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
diff --git a/lib/edioutput/Transport.h b/lib/edioutput/Transport.h
index 56ded3b..9ee4e27 100644
--- a/lib/edioutput/Transport.h
+++ b/lib/edioutput/Transport.h
@@ -31,9 +31,10 @@
#include "EDIConfig.h"
#include "AFPacket.h"
#include "PFT.h"
-#include "Interleaver.h"
#include "Socket.h"
#include <vector>
+#include <chrono>
+#include <map>
#include <unordered_map>
#include <stdexcept>
#include <fstream>
@@ -61,12 +62,11 @@ class Sender {
// The AF Packet will be protected with reed-solomon and split in fragments
edi::PFT edi_pft;
- // To mitigate for burst packet loss, PFT fragments can be sent out-of-order
- edi::Interleaver edi_interleaver;
-
std::unordered_map<udp_destination_t*, std::shared_ptr<Socket::UDPSocket>> udp_sockets;
std::unordered_map<tcp_server_t*, std::shared_ptr<Socket::TCPDataDispatcher>> tcp_dispatchers;
std::unordered_map<tcp_client_t*, std::shared_ptr<Socket::TCPSendClient>> tcp_senders;
+
+ std::map<std::chrono::steady_clock::time_point, edi::PFTFragment> m_pending_frames;
};
}
diff --git a/src/main.cpp b/src/main.cpp
index 698f8e3..43d8cab 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -69,7 +69,7 @@ static void usage()
cerr << " -x Drop frames where for which the wait time would be negative, i.e. frames that arrived too late.\n";
cerr << " -P Disable PFT and send AFPackets.\n";
cerr << " -f <fec> Set the FEC.\n";
- cerr << " -i <interleave> Enable the interleaver with this latency.\n";
+ cerr << " -i <interleave> Configure the interleaver with given interleave percentage: 0% send all fragments at once, 100% spread over 24ms, >100% spread and interleave. Default 95%\n";
cerr << " -D Dump the EDI to edi.debug file.\n";
cerr << " -v Enables verbose mode.\n";
cerr << " -a <alignement> Set the alignment of the TAG Packet (default 8).\n";
@@ -171,18 +171,13 @@ class Main : public EdiDecoder::ETIDataCollector {
break;
case 'i':
{
- double interleave_ms = std::stod(optarg);
- if (interleave_ms != 0.0) {
- if (interleave_ms < 0) {
+ int interleave_percent = std::stoi(optarg);
+ if (interleave_percent != 0) {
+ if (interleave_percent < 0) {
throw std::runtime_error("EDI output: negative interleave value is invalid.");
}
- auto latency_rounded = lround(interleave_ms / 24.0);
- if (latency_rounded * 24 > 30000) {
- throw std::runtime_error("EDI output: interleaving set for more than 30 seconds!");
- }
-
- edi_conf.latency_frames = latency_rounded;
+ edi_conf.fragment_spreading_factor = (double)interleave_percent / 100.0;
}
}
break;