summaryrefslogtreecommitdiffstats
path: root/src/dabOutput/edi/PFT.h
blob: 54c229f30bc3ef81f717c1b49873185517d305f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
   Copyright (C) 2013,2014 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 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/>.
   */

#ifndef _PFT_H_
#define _PFT_H_

#include "config.h"
#include <vector>
#include <list>
#include <stdexcept>
#include <stdint.h>
#include "AFPacket.h"
#include "Log.h"
#include "ReedSolomon.h"

typedef std::vector<uint8_t> RSPacket;
typedef std::vector<uint8_t> PFTFragment;

class PFT
{
    public:
        static const int ParityBytes = 48;

        PFT(unsigned int RSDataWordLength, unsigned int NumRecoverableFragments) :
            m_k(RSDataWordLength),
            m_m(NumRecoverableFragments),
            m_pseq(0),
            m_encoder(m_k + ParityBytes, m_k)
        {
            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'
            }
        }

        // 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
        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

        uint16_t m_pseq;

        size_t m_num_chunks;

        ReedSolomon m_encoder;

};

#endif