diff options
Diffstat (limited to 'src/dabOutput/edi/PFT.cpp')
-rw-r--r-- | src/dabOutput/edi/PFT.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
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; +} + |