summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-05-17 17:48:22 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-05-20 21:39:37 +0200
commit8a4f546b85d0887d1d5af0a428753c7d31304b72 (patch)
tree220fddd2933e3b0ab93944552d44fe904a34e2ec /src
parent598bee55402280ff4ca6dedcbd212017a57e482e (diff)
downloaddabmux-8a4f546b85d0887d1d5af0a428753c7d31304b72.tar.gz
dabmux-8a4f546b85d0887d1d5af0a428753c7d31304b72.tar.bz2
dabmux-8a4f546b85d0887d1d5af0a428753c7d31304b72.zip
add non-working PFT layer
Diffstat (limited to 'src')
-rw-r--r--src/DabMux.cpp13
-rw-r--r--src/Makefile.am1
-rw-r--r--src/dabOutput/edi/PFT.cpp91
-rw-r--r--src/dabOutput/edi/PFT.h77
4 files changed, 179 insertions, 3 deletions
diff --git a/src/DabMux.cpp b/src/DabMux.cpp
index 3859734..6003c48 100644
--- a/src/DabMux.cpp
+++ b/src/DabMux.cpp
@@ -116,6 +116,7 @@ typedef DWORD32 uint32_t;
#include "dabOutput/edi/TagItems.h"
#include "dabOutput/edi/TagPacket.h"
#include "dabOutput/edi/AFPacket.h"
+#include "dabOutput/edi/PFT.h"
#include "crc.h"
#include "UdpSocket.h"
#include "InetAddress.h"
@@ -673,7 +674,10 @@ int main(int argc, char *argv[])
TagPacket edi_tagpacket;
// The TagPacket will then be placed into an AFPacket
- AFPacketiser edi_afPacket(EDI_AFPACKET_PROTOCOLTYPE_TAGITEMS);
+ AFPacketiser edi_afPacketiser(EDI_AFPACKET_PROTOCOLTYPE_TAGITEMS);
+
+ // The AF Packet will be protected with reed-solomon and split in fragments
+ PFT edi_pft(128, 3);
edi_tagDETI.atstf = 0; // TODO add ATST support
@@ -1954,11 +1958,14 @@ int main(int argc, char *argv[])
edi_tagpacket.tag_items.push_back(&(*tag));
}
- vector<uint8_t> edi_afpacketData = edi_afPacket.Assemble(edi_tagpacket);
+ AFPacket edi_afpacket = edi_afPacketiser.Assemble(edi_tagpacket);
+
+ vector< vector<uint8_t> > edi_fragments = edi_pft.ProtectAndFragment(edi_afpacket);
#if EDI_DEBUG
std::ostream_iterator<uint8_t> debug_iterator(edi_debug_file);
- std::copy(edi_afpacketData.begin(), edi_afpacketData.end(), debug_iterator);
+ std::copy(edi_afpacket.begin(), edi_afpacket.end(), debug_iterator);
+ fprintf(stderr, "EDI number of fragments %zu\n", edi_fragments.size());
#endif
#if _DEBUG
diff --git a/src/Makefile.am b/src/Makefile.am
index 709abe4..b65b9d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -73,6 +73,7 @@ odr_dabmux_SOURCES =DabMux.cpp DabMux.h \
dabOutput/edi/AFPacket.cpp dabOutput/edi/AFPacket.h \
dabOutput/edi/TagItems.cpp dabOutput/edi/TagItems.h \
dabOutput/edi/TagPacket.cpp dabOutput/edi/TagPacket.h \
+ dabOutput/edi/PFT.cpp dabOutput/edi/PFT.h \
bridge.h bridge.c \
utils.cpp utils.h \
MuxElements.cpp MuxElements.h \
diff --git a/src/dabOutput/edi/PFT.cpp b/src/dabOutput/edi/PFT.cpp
new file mode 100644
index 0000000..e14a008
--- /dev/null
+++ b/src/dabOutput/edi/PFT.cpp
@@ -0,0 +1,91 @@
+/*
+ Copyright (C) 2013 Matthias P. Braendli
+ http://mpb.li
+
+ 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 CRC-DabMux.
+
+ CRC-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.
+
+ CRC-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 CRC-DabMux. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <vector>
+#include <list>
+#include <stdint.h>
+#include "PFT.h"
+#include "ReedSolomon.h"
+
+using namespace std;
+
+typedef vector<uint8_t> Chunk;
+
+
+RSPacket PFT::Protect(AFPacket af_packet)
+{
+ RSPacket rs_packet;
+
+ m_num_chunks = af_packet.size() / 207 + 1;
+ const size_t zero_pad = m_num_chunks * m_k - af_packet.size();
+
+ // add zero padding to last chunk
+ for (size_t i = 0; i < zero_pad; i++) {
+ af_packet.push_back(0);
+ }
+
+ for (size_t i = 1; i < af_packet.size(); i+= m_k) {
+ // add new chunk to the list
+ Chunk c(m_k + ParityBytes);
+
+ for (size_t j = 0; j < m_k; j++) {
+ c[j] = af_packet[i+j];
+ }
+
+ // calculate RS for chunk
+ m_encoder.encode(&c.front(), c.size());
+
+ rs_packet.insert(rs_packet.end(), c.begin(), c.end());
+ }
+
+ return rs_packet;
+}
+
+vector< vector<uint8_t> > PFT::ProtectAndFragment(AFPacket af_packet)
+{
+ RSPacket rs_packet = Protect(af_packet);
+
+ const size_t max_payload_size = ( m_num_chunks * ParityBytes ) / (m_m + 1);
+
+ const size_t fragment_size = m_num_chunks * (m_k + ParityBytes) / max_payload_size;
+ const size_t num_fragments = m_num_chunks * (m_k + ParityBytes) / fragment_size;
+
+ vector< vector<uint8_t> > fragments(num_fragments);
+
+ for (size_t i = 0; i < num_fragments; i++) {
+ for (size_t j = 0; j < fragment_size; j++) {
+ fragments[i][j] = rs_packet[j*num_fragments + i]; //TODO that's wrong. fix it.
+ }
+ }
+
+ return fragments;
+}
+
diff --git a/src/dabOutput/edi/PFT.h b/src/dabOutput/edi/PFT.h
new file mode 100644
index 0000000..713170f
--- /dev/null
+++ b/src/dabOutput/edi/PFT.h
@@ -0,0 +1,77 @@
+/*
+ Copyright (C) 2013 Matthias P. Braendli
+ http://mpb.li
+
+ 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 CRC-DabMux.
+
+ CRC-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.
+
+ CRC-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 CRC-DabMux. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _PFT_H_
+#define _PFT_H_
+
+#include "config.h"
+#include <vector>
+#include <list>
+#include <stdint.h>
+#include "AFPacket.h"
+#include "Log.h"
+#include "ReedSolomon.h"
+
+typedef std::vector<uint8_t> RSPacket;
+
+class PFT
+{
+ public:
+ static const int ParityBytes = 255 - 207;
+
+ PFT(unsigned int RSDataWordLength, unsigned int NumRecoverableFragments) :
+ m_k(RSDataWordLength), m_m(NumRecoverableFragments), m_encoder(255, 207)
+ {
+ 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'
+ }
+ }
+
+ // Apply Reed-Solomon FEC to the AF Packet
+ RSPacket Protect(AFPacket af_packet);
+
+ // Cut a RSPacket into several fragments that can be transmitted
+ std::vector< std::vector<uint8_t> > ProtectAndFragment(AFPacket af_packet);
+
+ private:
+ unsigned int m_k; // length of RS data word
+ unsigned int m_m; // number of fragments that can be recovered if lost
+
+ size_t m_num_chunks;
+
+ ReedSolomon m_encoder;
+
+};
+
+#endif
+