aboutsummaryrefslogtreecommitdiffstats
path: root/src/dabOutput
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-08-19 17:18:51 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-08-19 17:18:51 +0200
commit5ee85c4ac41337e383eb1a735bc05f1e5d46a98f (patch)
tree9a6b4e9ec0138e282a67ac5d537248af4b067ad5 /src/dabOutput
parent247b175a6bf8107f0c92e6ca32e11af4b1a47b8a (diff)
downloaddabmux-5ee85c4ac41337e383eb1a735bc05f1e5d46a98f.tar.gz
dabmux-5ee85c4ac41337e383eb1a735bc05f1e5d46a98f.tar.bz2
dabmux-5ee85c4ac41337e383eb1a735bc05f1e5d46a98f.zip
Use EDI output from odr-mmbtools-common
Diffstat (limited to 'src/dabOutput')
-rw-r--r--src/dabOutput/edi/AFPacket.cpp96
-rw-r--r--src/dabOutput/edi/AFPacket.h61
-rw-r--r--src/dabOutput/edi/Config.h84
-rw-r--r--src/dabOutput/edi/Interleaver.cpp122
-rw-r--r--src/dabOutput/edi/Interleaver.h75
-rw-r--r--src/dabOutput/edi/PFT.cpp327
-rw-r--r--src/dabOutput/edi/PFT.h78
-rw-r--r--src/dabOutput/edi/TagItems.cpp216
-rw-r--r--src/dabOutput/edi/TagItems.h149
-rw-r--r--src/dabOutput/edi/TagPacket.cpp79
-rw-r--r--src/dabOutput/edi/TagPacket.h56
-rw-r--r--src/dabOutput/edi/Transport.cpp189
-rw-r--r--src/dabOutput/edi/Transport.h71
13 files changed, 0 insertions, 1603 deletions
diff --git a/src/dabOutput/edi/AFPacket.cpp b/src/dabOutput/edi/AFPacket.cpp
deleted file mode 100644
index a58a980..0000000
--- a/src/dabOutput/edi/AFPacket.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- Copyright (C) 2014
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output.
- This implements an AF Packet as defined ETSI TS 102 821.
- Also see ETSI TS 102 693
-
- */
-/*
- 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 "config.h"
-#include "crc.h"
-#include "AFPacket.h"
-#include "TagItems.h"
-#include "TagPacket.h"
-#include <vector>
-#include <string>
-#include <iostream>
-#include <cstdio>
-#include <stdint.h>
-#include <arpa/inet.h>
-
-namespace edi {
-
-// Header PT field. AF packet contains TAG payload
-const uint8_t AFHEADER_PT_TAG = 'T';
-
-// AF Packet Major (3 bits) and Minor (4 bits) version
-const uint8_t AFHEADER_VERSION = 0x10; // MAJ=1, MIN=0
-
-AFPacket AFPacketiser::Assemble(TagPacket tag_packet)
-{
- std::vector<uint8_t> payload = tag_packet.Assemble();
-
- if (m_verbose)
- std::cerr << "Assemble AFPacket " << seq << std::endl;
-
- std::string pack_data("AF"); // SYNC
- std::vector<uint8_t> packet(pack_data.begin(), pack_data.end());
-
- uint32_t taglength = payload.size();
-
- if (m_verbose)
- std::cerr << " AFPacket payload size " << payload.size() << std::endl;
-
- // write length into packet
- packet.push_back((taglength >> 24) & 0xFF);
- packet.push_back((taglength >> 16) & 0xFF);
- packet.push_back((taglength >> 8) & 0xFF);
- packet.push_back(taglength & 0xFF);
-
- // fill rest of header
- packet.push_back(seq >> 8);
- packet.push_back(seq & 0xFF);
- seq++;
- packet.push_back((have_crc ? 0x80 : 0) | AFHEADER_VERSION); // ar_cf: CRC=1
- packet.push_back(AFHEADER_PT_TAG);
-
- // insert payload, must have a length multiple of 8 bytes
- packet.insert(packet.end(), payload.begin(), payload.end());
-
- // calculate CRC over AF Header and payload
- uint16_t crc = 0xffff;
- crc = crc16(crc, &(packet.front()), packet.size());
- crc ^= 0xffff;
-
- if (m_verbose)
- fprintf(stderr, " AFPacket crc %x\n", crc);
-
- packet.push_back((crc >> 8) & 0xFF);
- packet.push_back(crc & 0xFF);
-
- if (m_verbose)
- std::cerr << " AFPacket length " << packet.size() << std::endl;
-
- return packet;
-}
-
-}
diff --git a/src/dabOutput/edi/AFPacket.h b/src/dabOutput/edi/AFPacket.h
deleted file mode 100644
index b4ccef1..0000000
--- a/src/dabOutput/edi/AFPacket.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- Copyright (C) 2014
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output.
- This implements an AF Packet as defined ETSI TS 102 821.
- Also see ETSI TS 102 693
-
- */
-/*
- 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/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include <vector>
-#include <stdint.h>
-#include "TagItems.h"
-#include "TagPacket.h"
-
-namespace edi {
-
-typedef std::vector<uint8_t> AFPacket;
-
-// ETSI TS 102 821, 6.1 AF packet structure
-class AFPacketiser
-{
- public:
- AFPacketiser() :
- m_verbose(false) {};
- AFPacketiser(bool verbose) :
- m_verbose(verbose) {};
-
- AFPacket Assemble(TagPacket tag_packet);
-
- private:
- static const bool have_crc = true;
-
- uint16_t seq = 0; //counter that overflows at 0xFFFF
-
- bool m_verbose;
-};
-
-}
-
diff --git a/src/dabOutput/edi/Config.h b/src/dabOutput/edi/Config.h
deleted file mode 100644
index 0c7dce8..0000000
--- a/src/dabOutput/edi/Config.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- Copyright (C) 2019
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output,
- UDP and TCP transports and their configuration
-
- */
-/*
- 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/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include <vector>
-#include <string>
-#include <memory>
-#include <cstdint>
-
-namespace edi {
-
-/** Configuration for EDI output */
-
-struct destination_t {
- virtual ~destination_t() {};
-};
-
-// Can represent both unicast and multicast destinations
-struct udp_destination_t : public destination_t {
- std::string dest_addr;
- std::string source_addr;
- unsigned int source_port = 0;
- unsigned int ttl = 10;
-};
-
-// TCP server that can accept multiple connections
-struct tcp_server_t : public destination_t {
- unsigned int listen_port = 0;
- size_t max_frames_queued = 1024;
-};
-
-// TCP client that connects to one endpoint
-struct tcp_client_t : public destination_t {
- std::string dest_addr;
- unsigned int dest_port = 0;
- size_t max_frames_queued = 1024;
-};
-
-struct configuration_t {
- unsigned chunk_len = 207; // RSk, data length of each chunk
- unsigned fec = 0; // number of fragments that can be recovered
- bool dump = false; // dump a file with the EDI packets
- bool verbose = false;
- bool enable_pft = false; // Enable protection and fragmentation
- unsigned int tagpacket_alignment = 0;
- std::vector<std::shared_ptr<destination_t> > destinations;
- unsigned int dest_port = 0; // common destination port, because it's encoded in the transport layer
- unsigned int latency_frames = 0; // if nonzero, enable interleaver with a latency of latency_frames * 24ms
-
- bool enabled() const { return destinations.size() > 0; }
- bool interleaver_enabled() const { return latency_frames > 0; }
-
- void print() const;
-};
-
-}
-
-
diff --git a/src/dabOutput/edi/Interleaver.cpp b/src/dabOutput/edi/Interleaver.cpp
deleted file mode 100644
index f26a50e..0000000
--- a/src/dabOutput/edi/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/src/dabOutput/edi/Interleaver.h b/src/dabOutput/edi/Interleaver.h
deleted file mode 100644
index f1cff30..0000000
--- a/src/dabOutput/edi/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 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/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include <vector>
-#include <deque>
-#include <stdexcept>
-#include <stdint.h>
-#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/src/dabOutput/edi/PFT.cpp b/src/dabOutput/edi/PFT.cpp
deleted file mode 100644
index 63dfa34..0000000
--- a/src/dabOutput/edi/PFT.cpp
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- Copyright (C) 2019
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output,
- Protection, Fragmentation and Transport. (PFT)
-
- Are supported:
- Reed-Solomon and Fragmentation
-
- This implements part of PFT as defined ETSI TS 102 821.
-
- */
-/*
- 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 "config.h"
-#include <vector>
-#include <list>
-#include <cstdio>
-#include <cstring>
-#include <stdint.h>
-#include <arpa/inet.h>
-#include <stdexcept>
-#include <sstream>
-#include "PFT.h"
-#include "crc.h"
-#include "ReedSolomon.h"
-
-namespace edi {
-
-using namespace std;
-
-// An integer division that rounds up, i.e. ceil(a/b)
-#define CEIL_DIV(a, b) (a % b == 0 ? a / b : a / b + 1)
-
-PFT::PFT() { }
-
-PFT::PFT(const configuration_t &conf) :
- m_k(conf.chunk_len),
- m_m(conf.fec),
- m_dest_port(conf.dest_port),
- m_pseq(0),
- m_num_chunks(0),
- m_verbose(conf.verbose)
- {
- if (m_k > 207) {
- etiLog.level(warn) <<
- "EDI PFT: maximum chunk size is 207.";
- throw std::out_of_range("EDI PFT Chunk size too large.");
- }
-
- if (m_m > 5) {
- etiLog.level(warn) <<
- "EDI PFT: high number of recoverable fragments"
- " may lead to large overhead";
- // See TS 102 821, 7.2.1 Known values, list entry for 'm'
- }
- }
-
-RSBlock PFT::Protect(AFPacket af_packet)
-{
- RSBlock rs_block;
-
- // number of chunks is ceil(afpacketsize / m_k)
- // TS 102 821 7.2.2: c = ceil(l / k_max)
- m_num_chunks = CEIL_DIV(af_packet.size(), m_k);
-
- if (m_verbose) {
- fprintf(stderr, "Protect %zu chunks of size %zu\n",
- m_num_chunks, af_packet.size());
- }
-
- // calculate size of chunk:
- // TS 102 821 7.2.2: k = ceil(l / c)
- // chunk_len does not include the 48 bytes of protection.
- const size_t chunk_len = CEIL_DIV(af_packet.size(), m_num_chunks);
- if (chunk_len > 207) {
- std::stringstream ss;
- ss << "Chunk length " << chunk_len << " too large (>207)";
- throw std::runtime_error(ss.str());
- }
-
- // The last RS chunk is zero padded
- // TS 102 821 7.2.2: z = c*k - l
- const size_t zero_pad = m_num_chunks * chunk_len - af_packet.size();
-
- // Create the RS(k+p,k) encoder
- const int firstRoot = 1; // Discovered by analysing EDI dump
- const int gfPoly = 0x11d;
- const bool reverse = false;
- // The encoding has to be 255, 207 always, because the chunk has to
- // be padded at the end, and not at the beginning as libfec would
- // do
- ReedSolomon rs_encoder(255, 207, reverse, gfPoly, firstRoot);
-
- // add zero padding to last chunk
- for (size_t i = 0; i < zero_pad; i++) {
- af_packet.push_back(0);
- }
-
- if (m_verbose) {
- fprintf(stderr, " add %zu zero padding\n", zero_pad);
- }
-
- // Calculate RS for each chunk and assemble RS block
- for (size_t i = 0; i < af_packet.size(); i+= chunk_len) {
- vector<uint8_t> chunk(207);
- vector<uint8_t> protection(PARITYBYTES);
-
- // copy chunk_len bytes into new chunk
- memcpy(&chunk.front(), &af_packet[i], chunk_len);
-
- // calculate RS for chunk with padding
- rs_encoder.encode(&chunk.front(), &protection.front(), 207);
-
- // Drop the padding
- chunk.resize(chunk_len);
-
- // append new chunk and protection to the RS Packet
- rs_block.insert(rs_block.end(), chunk.begin(), chunk.end());
- rs_block.insert(rs_block.end(), protection.begin(), protection.end());
- }
-
- return rs_block;
-}
-
-vector< vector<uint8_t> > PFT::ProtectAndFragment(AFPacket af_packet)
-{
- const bool enable_RS = (m_m > 0);
-
- if (enable_RS) {
- RSBlock rs_block = Protect(af_packet);
-
-#if 0
- fprintf(stderr, " af_packet (%zu):", af_packet.size());
- for (size_t i = 0; i < af_packet.size(); i++) {
- fprintf(stderr, "%02x ", af_packet[i]);
- }
- fprintf(stderr, "\n");
-
- fprintf(stderr, " rs_block (%zu):", rs_block.size());
- for (size_t i = 0; i < rs_block.size(); i++) {
- fprintf(stderr, "%02x ", rs_block[i]);
- }
- fprintf(stderr, "\n");
-#endif
-
- // TS 102 821 7.2.2: s_max = MIN(floor(c*p/(m+1)), MTU - h))
- const size_t max_payload_size = ( m_num_chunks * PARITYBYTES ) / (m_m + 1);
-
- // Calculate fragment count and size
- // TS 102 821 7.2.2: ceil((l + c*p + z) / s_max)
- // l + c*p + z = length of RS block
- const size_t num_fragments = CEIL_DIV(rs_block.size(), max_payload_size);
-
- // TS 102 821 7.2.2: ceil((l + c*p + z) / f)
- const size_t fragment_size = CEIL_DIV(rs_block.size(), num_fragments);
-
- if (m_verbose)
- fprintf(stderr, " PnF fragment_size %zu, num frag %zu\n",
- fragment_size, num_fragments);
-
- vector< vector<uint8_t> > fragments(num_fragments);
-
- for (size_t i = 0; i < num_fragments; i++) {
- fragments[i].resize(fragment_size);
- for (size_t j = 0; j < fragment_size; j++) {
- const size_t ix = j*num_fragments + i;
- if (ix < rs_block.size()) {
- fragments[i][j] = rs_block[ix];
- }
- else {
- fragments[i][j] = 0;
- }
- }
- }
-
- return fragments;
- }
- else { // No RS, only fragmentation
- // TS 102 821 7.2.2: s_max = MTU - h
- // Ethernet MTU is 1500, but maybe you are routing over a network which
- // has some sort of packet encapsulation. Add some margin.
- const size_t max_payload_size = 1400;
-
- // Calculate fragment count and size
- // TS 102 821 7.2.2: ceil((l + c*p + z) / s_max)
- // l + c*p + z = length of AF packet
- const size_t num_fragments = CEIL_DIV(af_packet.size(), max_payload_size);
-
- // TS 102 821 7.2.2: ceil((l + c*p + z) / f)
- const size_t fragment_size = CEIL_DIV(af_packet.size(), num_fragments);
- vector< vector<uint8_t> > fragments(num_fragments);
-
- for (size_t i = 0; i < num_fragments; i++) {
- fragments[i].reserve(fragment_size);
-
- for (size_t j = 0; j < fragment_size; j++) {
- const size_t ix = i*fragment_size + j;
- if (ix < af_packet.size()) {
- fragments[i].push_back(af_packet.at(ix));
- }
- else {
- break;
- }
- }
- }
-
- return fragments;
- }
-}
-
-std::vector< PFTFragment > PFT::Assemble(AFPacket af_packet)
-{
- vector< vector<uint8_t> > fragments = ProtectAndFragment(af_packet);
- vector< vector<uint8_t> > pft_fragments; // These contain PF headers
-
- const bool enable_RS = (m_m > 0);
- const bool enable_transport = true;
-
- unsigned int findex = 0;
-
- unsigned fcount = fragments.size();
-
- // calculate size of chunk:
- // TS 102 821 7.2.2: k = ceil(l / c)
- // chunk_len does not include the 48 bytes of protection.
- const size_t chunk_len = enable_RS ?
- CEIL_DIV(af_packet.size(), m_num_chunks) : 0;
-
- // The last RS chunk is zero padded
- // TS 102 821 7.2.2: z = c*k - l
- const size_t zero_pad = enable_RS ?
- m_num_chunks * chunk_len - af_packet.size() : 0;
-
- for (const auto &fragment : fragments) {
- // Psync
- std::string psync("PF");
- std::vector<uint8_t> packet(psync.begin(), psync.end());
-
- // Pseq
- packet.push_back(m_pseq >> 8);
- packet.push_back(m_pseq & 0xFF);
-
- // Findex
- packet.push_back(findex >> 16);
- packet.push_back(findex >> 8);
- packet.push_back(findex & 0xFF);
- findex++;
-
- // Fcount
- packet.push_back(fcount >> 16);
- packet.push_back(fcount >> 8);
- packet.push_back(fcount & 0xFF);
-
- // RS (1 bit), transport (1 bit) and Plen (14 bits)
- unsigned int plen = fragment.size();
- if (enable_RS) {
- plen |= 0x8000; // Set FEC bit
- }
-
- if (enable_transport) {
- plen |= 0x4000; // Set ADDR bit
- }
-
- packet.push_back(plen >> 8);
- packet.push_back(plen & 0xFF);
-
- if (enable_RS) {
- packet.push_back(chunk_len); // RSk
- packet.push_back(zero_pad); // RSz
- }
-
- if (enable_transport) {
- // Source (16 bits)
- uint16_t addr_source = 0;
- packet.push_back(addr_source >> 8);
- packet.push_back(addr_source & 0xFF);
-
- // Dest (16 bits)
- packet.push_back(m_dest_port >> 8);
- packet.push_back(m_dest_port & 0xFF);
- }
-
- // calculate CRC over AF Header and payload
- uint16_t crc = 0xffff;
- crc = crc16(crc, &(packet.front()), packet.size());
- crc ^= 0xffff;
-
- packet.push_back((crc >> 8) & 0xFF);
- packet.push_back(crc & 0xFF);
-
- // insert payload, must have a length multiple of 8 bytes
- packet.insert(packet.end(), fragment.begin(), fragment.end());
-
- pft_fragments.push_back(packet);
-
-#if 0
- fprintf(stderr, "* PFT pseq %d, findex %d, fcount %d, plen %d\n",
- m_pseq, findex, fcount, plen & ~0xC000);
-#endif
- }
-
- m_pseq++;
-
- return pft_fragments;
-}
-
-}
-
diff --git a/src/dabOutput/edi/PFT.h b/src/dabOutput/edi/PFT.h
deleted file mode 100644
index 4076bf3..0000000
--- a/src/dabOutput/edi/PFT.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- Copyright (C) 2019
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output,
- Protection, Fragmentation and Transport. (PFT)
-
- Are supported:
- Reed-Solomon and Fragmentation
-
- This implements part of PFT as defined ETSI TS 102 821.
-
- */
-/*
- 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/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include <vector>
-#include <list>
-#include <stdexcept>
-#include <stdint.h>
-#include "AFPacket.h"
-#include "Log.h"
-#include "ReedSolomon.h"
-#include "dabOutput/edi/Config.h"
-
-namespace edi {
-
-typedef std::vector<uint8_t> RSBlock;
-typedef std::vector<uint8_t> PFTFragment;
-
-class PFT
-{
- public:
- static constexpr int PARITYBYTES = 48;
-
- PFT();
- PFT(const configuration_t& conf);
-
- // return a list of PFT fragments with the correct
- // PFT headers
- std::vector< PFTFragment > Assemble(AFPacket af_packet);
-
- // Apply Reed-Solomon FEC to the AF Packet
- RSBlock Protect(AFPacket af_packet);
-
- // Cut a RSBlock into several fragments that can be transmitted
- std::vector< std::vector<uint8_t> > ProtectAndFragment(AFPacket af_packet);
-
- private:
- unsigned int m_k = 207; // length of RS data word
- unsigned int m_m = 3; // number of fragments that can be recovered if lost
- unsigned int m_dest_port = 12000; // Destination port for transport header
- uint16_t m_pseq = 0;
- size_t m_num_chunks = 0;
- bool m_verbose = 0;
-};
-
-}
-
diff --git a/src/dabOutput/edi/TagItems.cpp b/src/dabOutput/edi/TagItems.cpp
deleted file mode 100644
index dfb4934..0000000
--- a/src/dabOutput/edi/TagItems.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- EDI output.
- This defines a few TAG items as defined ETSI TS 102 821 and
- ETSI TS 102 693
-
- Copyright (C) 2019
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- */
-/*
- 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 "config.h"
-#include "TagItems.h"
-#include <vector>
-#include <iostream>
-#include <string>
-#include <stdint.h>
-#include <stdexcept>
-
-namespace edi {
-
-std::vector<uint8_t> TagStarPTR::Assemble()
-{
- //std::cerr << "TagItem *ptr" << std::endl;
- std::string pack_data("*ptr");
- std::vector<uint8_t> packet(pack_data.begin(), pack_data.end());
-
- packet.push_back(0);
- packet.push_back(0);
- packet.push_back(0);
- packet.push_back(0x40);
-
- std::string protocol("DETI");
- packet.insert(packet.end(), protocol.begin(), protocol.end());
-
- // Major
- packet.push_back(0);
- packet.push_back(0);
-
- // Minor
- packet.push_back(0);
- packet.push_back(0);
- return packet;
-}
-
-std::vector<uint8_t> TagDETI::Assemble()
-{
- std::string pack_data("deti");
- std::vector<uint8_t> packet(pack_data.begin(), pack_data.end());
- packet.reserve(256);
-
- // Placeholder for length
- packet.push_back(0);
- packet.push_back(0);
- packet.push_back(0);
- packet.push_back(0);
-
- uint8_t fct = dlfc % 250;
- uint8_t fcth = dlfc / 250;
-
-
- uint16_t detiHeader = fct | (fcth << 8) | (rfudf << 13) | (ficf << 14) | (atstf << 15);
- packet.push_back(detiHeader >> 8);
- packet.push_back(detiHeader & 0xFF);
-
- uint32_t etiHeader = mnsc | (rfu << 16) | (rfa << 17) |
- (fp << 19) | (mid << 22) | (stat << 24);
- packet.push_back((etiHeader >> 24) & 0xFF);
- packet.push_back((etiHeader >> 16) & 0xFF);
- packet.push_back((etiHeader >> 8) & 0xFF);
- packet.push_back(etiHeader & 0xFF);
-
- if (atstf) {
- packet.push_back(utco);
-
- packet.push_back((seconds >> 24) & 0xFF);
- packet.push_back((seconds >> 16) & 0xFF);
- packet.push_back((seconds >> 8) & 0xFF);
- packet.push_back(seconds & 0xFF);
-
- packet.push_back((tsta >> 16) & 0xFF);
- packet.push_back((tsta >> 8) & 0xFF);
- packet.push_back(tsta & 0xFF);
- }
-
- if (ficf) {
- for (size_t i = 0; i < fic_length; i++) {
- packet.push_back(fic_data[i]);
- }
- }
-
- if (rfudf) {
- packet.push_back((rfud >> 16) & 0xFF);
- packet.push_back((rfud >> 8) & 0xFF);
- packet.push_back(rfud & 0xFF);
- }
-
- // calculate and update size
- // remove TAG name and TAG length fields and convert to bits
- uint32_t taglength = (packet.size() - 8) * 8;
-
- // write length into packet
- packet[4] = (taglength >> 24) & 0xFF;
- packet[5] = (taglength >> 16) & 0xFF;
- packet[6] = (taglength >> 8) & 0xFF;
- packet[7] = taglength & 0xFF;
-
- dlfc = (dlfc+1) % 5000;
-
- /*
- std::cerr << "TagItem deti, packet.size " << packet.size() << std::endl;
- std::cerr << " fic length " << fic_length << std::endl;
- std::cerr << " length " << taglength / 8 << std::endl;
- */
- return packet;
-}
-
-void TagDETI::set_edi_time(const std::time_t t, int tai_utc_offset)
-{
- utco = tai_utc_offset - 32;
-
- const std::time_t posix_timestamp_1_jan_2000 = 946684800;
-
- seconds = t - posix_timestamp_1_jan_2000 + utco;
-}
-
-std::vector<uint8_t> TagESTn::Assemble()
-{
- std::string pack_data("est");
- std::vector<uint8_t> packet(pack_data.begin(), pack_data.end());
- packet.reserve(mst_length*8 + 16);
-
- packet.push_back(id);
-
- // Placeholder for length
- packet.push_back(0);
- packet.push_back(0);
- packet.push_back(0);
- packet.push_back(0);
-
- if (tpl > 0x3F) {
- throw std::runtime_error("TagESTn: invalid TPL value");
- }
-
- if (sad > 0x3FF) {
- throw std::runtime_error("TagESTn: invalid SAD value");
- }
-
- if (scid > 0x3F) {
- throw std::runtime_error("TagESTn: invalid SCID value");
- }
-
- uint32_t sstc = (scid << 18) | (sad << 8) | (tpl << 2) | rfa;
- packet.push_back((sstc >> 16) & 0xFF);
- packet.push_back((sstc >> 8) & 0xFF);
- packet.push_back(sstc & 0xFF);
-
- for (size_t i = 0; i < mst_length * 8; i++) {
- packet.push_back(mst_data[i]);
- }
-
- // calculate and update size
- // remove TAG name and TAG length fields and convert to bits
- uint32_t taglength = (packet.size() - 8) * 8;
-
- // write length into packet
- packet[4] = (taglength >> 24) & 0xFF;
- packet[5] = (taglength >> 16) & 0xFF;
- packet[6] = (taglength >> 8) & 0xFF;
- packet[7] = taglength & 0xFF;
-
- /*
- std::cerr << "TagItem ESTn, length " << packet.size() << std::endl;
- std::cerr << " mst_length " << mst_length << std::endl;
- */
- return packet;
-}
-
-std::vector<uint8_t> TagStarDMY::Assemble()
-{
- std::string pack_data("*dmy");
- std::vector<uint8_t> packet(pack_data.begin(), pack_data.end());
-
- packet.resize(4 + 4 + length_);
-
- const uint32_t length_bits = length_ * 8;
-
- packet[4] = (length_bits >> 24) & 0xFF;
- packet[5] = (length_bits >> 16) & 0xFF;
- packet[6] = (length_bits >> 8) & 0xFF;
- packet[7] = length_bits & 0xFF;
-
- // The remaining bytes in the packet are "undefined data"
-
- return packet;
-}
-
-}
-
diff --git a/src/dabOutput/edi/TagItems.h b/src/dabOutput/edi/TagItems.h
deleted file mode 100644
index b29a142..0000000
--- a/src/dabOutput/edi/TagItems.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- EDI output.
- This defines a few TAG items as defined ETSI TS 102 821 and
- ETSI TS 102 693
-
- Copyright (C) 2019
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- */
-/*
- 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/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include "Eti.h"
-#include <vector>
-#include <chrono>
-#include <string>
-#include <stdint.h>
-
-namespace edi {
-
-class TagItem
-{
- public:
- virtual std::vector<uint8_t> Assemble() = 0;
-};
-
-// ETSI TS 102 693, 5.1.1 Protocol type and revision
-class TagStarPTR : public TagItem
-{
- public:
- std::vector<uint8_t> Assemble();
-};
-
-// ETSI TS 102 693, 5.1.3 DAB ETI(LI) Management (deti)
-class TagDETI : public TagItem
-{
- public:
- std::vector<uint8_t> Assemble();
-
- /***** DATA in intermediary format ****/
- // For the ETI Header: must be defined !
- uint8_t stat = 0;
- uint8_t mid = 0;
- uint8_t fp = 0;
- uint8_t rfa = 0;
- uint8_t rfu = 0; // MNSC is valid
- uint16_t mnsc = 0;
- uint16_t dlfc = 0; // modulo 5000 frame counter
-
- // ATST (optional)
- bool atstf = false; // presence of atst data
-
- /* UTCO: Offset (in seconds) between UTC and the Seconds value. The
- * value is expressed as an unsigned 8-bit quantity. As of February
- * 2009, the value shall be 2 and shall change as a result of each
- * modification of the number of leap seconds, as proscribed by
- * International Earth Rotation and Reference Systems Service (IERS).
- *
- * According to Annex F
- * EDI = TAI - 32s (constant)
- * EDI = UTC + UTCO
- * we derive
- * UTCO = TAI-UTC - 32
- * where the TAI-UTC offset is given by the USNO bulletin using
- * the ClockTAI module.
- */
- uint8_t utco = 0;
-
- /* Update the EDI time. t is in UTC */
- void set_edi_time(const std::time_t t, int tai_utc_offset);
-
- /* The number of SI seconds since 2000-01-01 T 00:00:00 UTC as an
- * unsigned 32-bit quantity. Contrary to POSIX, this value also
- * counts leap seconds.
- */
- uint32_t seconds = 0;
-
- /* TSTA: Shall be the 24 least significant bits of the Time Stamp
- * (TIST) field from the STI-D(LI) Frame. The full definition for the
- * STI TIST can be found in annex B of EN 300 797 [4]. The most
- * significant 8 bits of the TIST field of the incoming STI-D(LI)
- * frame, if required, may be carried in the RFAD field.
- */
- uint32_t tsta = 0xFFFFFF;
-
- // the FIC (optional)
- bool ficf = false;
- const unsigned char* fic_data;
- size_t fic_length;
-
- // rfu
- bool rfudf = false;
- uint32_t rfud = 0;
-
-
-};
-
-// ETSI TS 102 693, 5.1.5 ETI Sub-Channel Stream <n>
-class TagESTn : public TagItem
-{
- public:
- std::vector<uint8_t> Assemble();
-
- // SSTCn
- uint8_t scid;
- uint16_t sad;
- uint8_t tpl;
- uint8_t rfa;
-
- // Pointer to MSTn data
- uint8_t* mst_data;
- size_t mst_length; // STLn * 8 bytes
-
- uint8_t id;
-};
-
-// ETSI TS 102 821, 5.2.2.2 Dummy padding
-class TagStarDMY : public TagItem
-{
- public:
- /* length is the TAG value length in bytes */
- TagStarDMY(uint32_t length) : length_(length) {}
- std::vector<uint8_t> Assemble();
-
- private:
- uint32_t length_;
-};
-
-}
-
diff --git a/src/dabOutput/edi/TagPacket.cpp b/src/dabOutput/edi/TagPacket.cpp
deleted file mode 100644
index b16dc33..0000000
--- a/src/dabOutput/edi/TagPacket.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- Copyright (C) 2014
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output.
- This defines a TAG Packet.
- */
-/*
- 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 "config.h"
-#include "Eti.h"
-#include "TagPacket.h"
-#include "TagItems.h"
-#include <vector>
-#include <iostream>
-#include <string>
-#include <list>
-#include <stdint.h>
-#include <cassert>
-
-namespace edi {
-
-TagPacket::TagPacket(unsigned int alignment) : m_alignment(alignment)
-{ }
-
-std::vector<uint8_t> TagPacket::Assemble()
-{
- std::list<TagItem*>::iterator tag;
-
- std::vector<uint8_t> packet;
-
- //std::cerr << "Assemble TAGPacket" << std::endl;
-
- for (tag = tag_items.begin(); tag != tag_items.end(); ++tag) {
- std::vector<uint8_t> tag_data = (*tag)->Assemble();
- packet.insert(packet.end(), tag_data.begin(), tag_data.end());
-
- //std::cerr << " Add TAGItem of length " << tag_data.size() << std::endl;
- }
-
- if (m_alignment == 0) { /* no padding */ }
- else if (m_alignment == 8) {
- // Add padding inside TAG packet
- while (packet.size() % 8 > 0) {
- packet.push_back(0); // TS 102 821, 5.1, "padding shall be undefined"
- }
- }
- else if (m_alignment > 8) {
- TagStarDMY dmy(m_alignment - 8);
- auto dmy_data = dmy.Assemble();
- packet.insert(packet.end(), dmy_data.begin(), dmy_data.end());
- }
- else {
- std::cerr << "Invalid alignment requirement " << m_alignment <<
- " defined in TagPacket" << std::endl;
- }
-
- return packet;
-}
-
-}
-
diff --git a/src/dabOutput/edi/TagPacket.h b/src/dabOutput/edi/TagPacket.h
deleted file mode 100644
index a861cbb..0000000
--- a/src/dabOutput/edi/TagPacket.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- Copyright (C) 2014
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output.
- This defines a TAG Packet.
- */
-/*
- 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/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include "TagItems.h"
-#include <vector>
-#include <string>
-#include <list>
-#include <stdint.h>
-
-namespace edi {
-
-// A TagPacket is nothing else than a list of tag items, with an
-// Assemble function that puts the bytestream together and adds
-// padding such that the total length is a multiple of 8 Bytes.
-//
-// ETSI TS 102 821, 5.1 Tag Packet
-class TagPacket
-{
- public:
- TagPacket(unsigned int alignment);
- std::vector<uint8_t> Assemble();
-
- std::list<TagItem*> tag_items;
-
- private:
- unsigned int m_alignment;
-};
-
-}
-
diff --git a/src/dabOutput/edi/Transport.cpp b/src/dabOutput/edi/Transport.cpp
deleted file mode 100644
index 187aabe..0000000
--- a/src/dabOutput/edi/Transport.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- Copyright (C) 2019
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output,
- UDP and TCP transports and their configuration
-
- */
-/*
- 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 "Transport.h"
-#include <iterator>
-
-using namespace std;
-
-namespace edi {
-
-void configuration_t::print() const
-{
- etiLog.level(info) << "EDI";
- etiLog.level(info) << " verbose " << verbose;
- for (auto edi_dest : destinations) {
- if (auto udp_dest = dynamic_pointer_cast<edi::udp_destination_t>(edi_dest)) {
- etiLog.level(info) << " UDP to " << udp_dest->dest_addr << ":" << dest_port;
- if (not udp_dest->source_addr.empty()) {
- etiLog.level(info) << " source " << udp_dest->source_addr;
- etiLog.level(info) << " ttl " << udp_dest->ttl;
- }
- etiLog.level(info) << " source port " << udp_dest->source_port;
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_server_t>(edi_dest)) {
- etiLog.level(info) << " TCP listening on port " << tcp_dest->listen_port;
- etiLog.level(info) << " max frames queued " << tcp_dest->max_frames_queued;
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_client_t>(edi_dest)) {
- etiLog.level(info) << " TCP client connecting to " << tcp_dest->dest_addr << ":" << tcp_dest->dest_port;
- etiLog.level(info) << " max frames queued " << tcp_dest->max_frames_queued;
- }
- else {
- throw logic_error("EDI destination not implemented");
- }
- }
- if (interleaver_enabled()) {
- etiLog.level(info) << " interleave " << latency_frames * 24 << " ms";
- }
-}
-
-
-Sender::Sender(const configuration_t& conf) :
- m_conf(conf),
- edi_pft(m_conf)
-{
- if (m_conf.verbose) {
- etiLog.log(info, "Setup EDI");
- }
-
- for (const auto& edi_dest : m_conf.destinations) {
- if (const auto udp_dest = dynamic_pointer_cast<edi::udp_destination_t>(edi_dest)) {
- auto udp_socket = std::make_shared<Socket::UDPSocket>(udp_dest->source_port);
-
- if (not udp_dest->source_addr.empty()) {
- udp_socket->setMulticastSource(udp_dest->source_addr.c_str());
- udp_socket->setMulticastTTL(udp_dest->ttl);
- }
-
- udp_sockets.emplace(udp_dest.get(), udp_socket);
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_server_t>(edi_dest)) {
- auto dispatcher = make_shared<Socket::TCPDataDispatcher>(tcp_dest->max_frames_queued);
- dispatcher->start(tcp_dest->listen_port, "0.0.0.0");
- tcp_dispatchers.emplace(tcp_dest.get(), dispatcher);
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_client_t>(edi_dest)) {
- auto tcp_socket = make_shared<Socket::TCPSocket>();
- tcp_socket->connect(tcp_dest->dest_addr, tcp_dest->dest_port);
- tcp_senders.emplace(tcp_dest.get(), tcp_socket);
- }
- else {
- throw logic_error("EDI destination not implemented");
- }
- }
-
- if (m_conf.interleaver_enabled()) {
- edi_interleaver.SetLatency(m_conf.latency_frames);
- }
-
- if (m_conf.dump) {
- edi_debug_file.open("./edi.debug");
- }
-
- if (m_conf.verbose) {
- etiLog.log(info, "EDI set up");
- }
-}
-
-void Sender::write(const TagPacket& tagpacket)
-{
- // Assemble into one AF Packet
- edi::AFPacket af_packet = edi_afPacketiser.Assemble(tagpacket);
-
- if (m_conf.enable_pft) {
- // Apply PFT layer to AF Packet (Reed Solomon FEC and Fragmentation)
- vector<edi::PFTFragment> edi_fragments = edi_pft.Assemble(af_packet);
-
- if (m_conf.verbose) {
- fprintf(stderr, "EDI number of PFT fragment before interleaver %zu\n",
- edi_fragments.size());
- }
-
- if (m_conf.interleaver_enabled()) {
- edi_fragments = edi_interleaver.Interleave(edi_fragments);
- }
-
- // Send over ethernet
- for (const auto& edi_frag : edi_fragments) {
- 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, m_conf.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.data(), edi_frag.size());
- }
- else {
- throw logic_error("EDI destination not implemented");
- }
- }
-
- if (m_conf.dump) {
- ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
- copy(edi_frag.begin(), edi_frag.end(), debug_iterator);
- }
- }
-
- if (m_conf.verbose) {
- fprintf(stderr, "EDI number of PFT fragments %zu\n",
- edi_fragments.size());
- }
- }
- else {
- // Send over ethernet
- 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, m_conf.dest_port);
-
- udp_sockets.at(udp_dest.get())->send(af_packet, addr);
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_server_t>(dest)) {
- tcp_dispatchers.at(tcp_dest.get())->write(af_packet);
- }
- else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_client_t>(dest)) {
- tcp_senders.at(tcp_dest.get())->sendall(af_packet.data(), af_packet.size());
- }
- else {
- throw logic_error("EDI destination not implemented");
- }
- }
-
- if (m_conf.dump) {
- ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
- copy(af_packet.begin(), af_packet.end(), debug_iterator);
- }
- }
-}
-
-}
diff --git a/src/dabOutput/edi/Transport.h b/src/dabOutput/edi/Transport.h
deleted file mode 100644
index 9633275..0000000
--- a/src/dabOutput/edi/Transport.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- Copyright (C) 2019
- Matthias P. Braendli, matthias.braendli@mpb.li
-
- http://www.opendigitalradio.org
-
- EDI output,
- UDP and TCP transports and their configuration
-
- */
-/*
- 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/>.
- */
-
-#pragma once
-
-#include "config.h"
-#include "dabOutput/edi/Config.h"
-#include "AFPacket.h"
-#include "PFT.h"
-#include "Interleaver.h"
-#include "Socket.h"
-#include <vector>
-#include <unordered_map>
-#include <stdexcept>
-#include <fstream>
-#include <cstdint>
-
-namespace edi {
-
-/** Configuration for EDI output */
-
-class Sender {
- public:
- Sender(const configuration_t& conf);
-
- void write(const TagPacket& tagpacket);
-
- private:
- configuration_t m_conf;
- std::ofstream edi_debug_file;
-
- // The TagPacket will then be placed into an AFPacket
- edi::AFPacketiser edi_afPacketiser;
-
- // 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::TCPSocket>> tcp_senders;
-};
-
-}
-