Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
headers.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_fec/headers.h
10
//! @brief FECFRAME headers.
11
12
#ifndef ROC_FEC_HEADERS_H_
13
#define ROC_FEC_HEADERS_H_
14
15
#include "
roc_core/attributes.h
"
16
#include "
roc_core/endian.h
"
17
#include "
roc_core/panic.h
"
18
#include "
roc_core/stddefs.h
"
19
#include "
roc_packet/fec.h
"
20
21
namespace
roc
{
22
namespace
fec
{
23
24
//! FEC Payload ID type.
25
enum
PayloadID_Type
{
26
Source
,
//!< Source packet header of footer.
27
Repair
//!< Source packet header of footer.
28
};
29
30
//! FEC Payload ID position.
31
enum
PayloadID_Pos
{
32
Header
,
//!< PayloadID comes before payload.
33
Footer
//!< PayloadID comes after payload.
34
};
35
36
//! LDPC-Staircase Source FEC Payload ID.
37
//!
38
//! RFC 6816 5.1.2: "Explicit Source FEC Payload ID"
39
//!
40
//! @code
41
//! 0 1 2 3
42
//! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
43
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44
//! | Source Block Number (SBN) | Encoding Symbol ID (ESI) |
45
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46
//! | Source Block Length (k) |
47
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48
//! @endcode
49
ROC_ATTR_PACKED_BEGIN
class
LDPC_Source_PayloadID
{
50
private
:
51
//! Source block number.
52
uint16_t sbn_;
53
54
//! Encoding symbol ID.
55
uint16_t esi_;
56
57
//! Source block length.
58
uint16_t k_;
59
60
public
:
61
//! Get FEC scheme to which these packets belong to.
62
static
packet::FecScheme
fec_scheme
() {
63
return
packet::FEC_LDPC_Staircase
;
64
}
65
66
//! Clear header.
67
void
clear
() {
68
memset(
this
, 0,
sizeof
(*
this
));
69
}
70
71
//! Get source block number.
72
uint16_t
sbn
()
const
{
73
return
core::ntoh16u
(sbn_);
74
}
75
76
//! Set source block number.
77
void
set_sbn
(uint16_t val) {
78
sbn_ =
core::hton16u
(val);
79
}
80
81
//! Get encoding symbol ID.
82
uint16_t
esi
()
const
{
83
return
core::ntoh16u
(esi_);
84
}
85
86
//! Set encoding symbol ID.
87
void
set_esi
(uint16_t val) {
88
esi_ =
core::hton16u
(val);
89
}
90
91
//! Get source block length.
92
uint16_t
k
()
const
{
93
return
core::ntoh16u
(k_);
94
}
95
96
//! Set source block length.
97
void
set_k
(uint16_t val) {
98
k_ =
core::hton16u
(val);
99
}
100
101
//! Get number encoding symbols.
102
uint16_t
n
()
const
{
103
return
0;
104
}
105
106
//! Set number encoding symbols.
107
void
set_n
(uint16_t) {
108
}
109
}
ROC_ATTR_PACKED_END
;
110
111
//! LDPC-Staircase Repair FEC Payload ID.
112
//!
113
//! RFC 6816 5.1.3: "Repair FEC Payload ID"
114
//!
115
//! @code
116
//! 0 1 2 3
117
//! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
118
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119
//! | Source Block Number (SBN) | Encoding Symbol ID (ESI) |
120
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121
//! | Source Block Length (k) | Number Encoding Symbols (n) |
122
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123
//! @endcode
124
ROC_ATTR_PACKED_BEGIN
class
LDPC_Repair_PayloadID
{
125
private
:
126
//! Source block number.
127
uint16_t sbn_;
128
129
//! Encoding symbol ID.
130
uint16_t esi_;
131
132
//! Source block length.
133
uint16_t k_;
134
135
//! Number encoding symbols.
136
uint16_t n_;
137
138
public
:
139
//! Get FEC scheme to which these packets belong to.
140
static
packet::FecScheme
fec_scheme
() {
141
return
packet::FEC_LDPC_Staircase
;
142
}
143
144
//! Clear header.
145
void
clear
() {
146
memset(
this
, 0,
sizeof
(*
this
));
147
}
148
149
//! Get source block number.
150
uint16_t
sbn
()
const
{
151
return
core::ntoh16u
(sbn_);
152
}
153
154
//! Set source block number.
155
void
set_sbn
(uint16_t val) {
156
sbn_ =
core::hton16u
(val);
157
}
158
159
//! Get encoding symbol ID.
160
uint16_t
esi
()
const
{
161
return
core::ntoh16u
(esi_);
162
}
163
164
//! Set encoding symbol ID.
165
void
set_esi
(uint16_t val) {
166
esi_ =
core::hton16u
(val);
167
}
168
169
//! Get source block length.
170
uint16_t
k
()
const
{
171
return
core::ntoh16u
(k_);
172
}
173
174
//! Set source block length.
175
void
set_k
(uint16_t val) {
176
k_ =
core::hton16u
(val);
177
}
178
179
//! Get number encoding symbols.
180
uint16_t
n
()
const
{
181
return
core::ntoh16u
(n_);
182
}
183
184
//! Set number encoding symbols.
185
void
set_n
(uint16_t val) {
186
n_ =
core::hton16u
(val);
187
}
188
}
ROC_ATTR_PACKED_END
;
189
190
//! Reed-Solomon Source or Repair Payload ID (for m=8).
191
//!
192
//! RFC 5510 5.1: "FEC Payload ID"
193
//!
194
//! @code
195
//! 0 1 2 3
196
//! 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
197
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
198
//! | Source Block Number (24 bits) | Enc. Symb. ID |
199
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
200
//! | Source Block Length (k) |
201
//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202
//! @endcode
203
ROC_ATTR_PACKED_BEGIN
class
RS8M_PayloadID
{
204
private
:
205
//! Source block number.
206
uint8_t sbn_[3];
207
208
//! Encoding symbol ID.
209
uint8_t esi_;
210
211
//! Source block length.
212
uint16_t k_;
213
214
public
:
215
//! Get FEC scheme to which these packets belong to.
216
static
packet::FecScheme
fec_scheme
() {
217
return
packet::FEC_ReedSolomon_M8
;
218
}
219
220
//! Clear header.
221
void
clear
() {
222
memset(
this
, 0,
sizeof
(*
this
));
223
}
224
225
//! Get source block number.
226
uint32_t
sbn
()
const
{
227
return
(uint32_t(sbn_[0]) << 16) | (uint32_t(sbn_[1]) << 8) | uint32_t(sbn_[2]);
228
}
229
230
//! Set source block number.
231
void
set_sbn
(uint32_t val) {
232
roc_panic_if
((val >> 24) != 0);
233
sbn_[0] = uint8_t((val >> 16) & 0xff);
234
sbn_[1] = uint8_t((val >> 8) & 0xff);
235
sbn_[2] = uint8_t(val & 0xff);
236
}
237
238
//! Get encoding symbol ID.
239
uint8_t
esi
()
const
{
240
return
esi_;
241
}
242
243
//! Set encoding symbol ID.
244
void
set_esi
(uint16_t val) {
245
roc_panic_if
((val >> 8) != 0);
246
esi_ = (uint8_t)val;
247
}
248
249
//! Get source block length.
250
uint16_t
k
()
const
{
251
return
core::ntoh16u
(k_);
252
}
253
254
//! Set source block length.
255
void
set_k
(uint16_t val) {
256
k_ =
core::hton16u
(val);
257
}
258
259
//! Get number encoding symbols.
260
uint16_t
n
()
const
{
261
return
255;
262
}
263
264
//! Set number encoding symbols.
265
void
set_n
(uint16_t) {
266
}
267
}
ROC_ATTR_PACKED_END
;
268
269
}
// namespace fec
270
}
// namespace roc
271
272
#endif
// ROC_FEC_HEADERS_H_
attributes.h
Compiler attributes.
ROC_ATTR_PACKED_BEGIN
#define ROC_ATTR_PACKED_BEGIN
Pack structure fields. Place these before class or struct keyword.
Definition
attributes.h:55
ROC_ATTR_PACKED_END
#define ROC_ATTR_PACKED_END
Pack structure fields. Place these between '}' and ';'.
Definition
attributes.h:58
roc::fec::LDPC_Repair_PayloadID
LDPC-Staircase Repair FEC Payload ID.
Definition
headers.h:124
roc::fec::LDPC_Repair_PayloadID::k
uint16_t k() const
Get source block length.
Definition
headers.h:170
roc::fec::LDPC_Repair_PayloadID::set_k
void set_k(uint16_t val)
Set source block length.
Definition
headers.h:175
roc::fec::LDPC_Repair_PayloadID::esi
uint16_t esi() const
Get encoding symbol ID.
Definition
headers.h:160
roc::fec::LDPC_Repair_PayloadID::clear
void clear()
Clear header.
Definition
headers.h:145
roc::fec::LDPC_Repair_PayloadID::set_esi
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition
headers.h:165
roc::fec::LDPC_Repair_PayloadID::set_n
void set_n(uint16_t val)
Set number encoding symbols.
Definition
headers.h:185
roc::fec::LDPC_Repair_PayloadID::fec_scheme
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition
headers.h:140
roc::fec::LDPC_Repair_PayloadID::n
uint16_t n() const
Get number encoding symbols.
Definition
headers.h:180
roc::fec::LDPC_Repair_PayloadID::sbn
uint16_t sbn() const
Get source block number.
Definition
headers.h:150
roc::fec::LDPC_Repair_PayloadID::set_sbn
void set_sbn(uint16_t val)
Set source block number.
Definition
headers.h:155
roc::fec::LDPC_Source_PayloadID
LDPC-Staircase Source FEC Payload ID.
Definition
headers.h:49
roc::fec::LDPC_Source_PayloadID::esi
uint16_t esi() const
Get encoding symbol ID.
Definition
headers.h:82
roc::fec::LDPC_Source_PayloadID::clear
void clear()
Clear header.
Definition
headers.h:67
roc::fec::LDPC_Source_PayloadID::k
uint16_t k() const
Get source block length.
Definition
headers.h:92
roc::fec::LDPC_Source_PayloadID::set_k
void set_k(uint16_t val)
Set source block length.
Definition
headers.h:97
roc::fec::LDPC_Source_PayloadID::sbn
uint16_t sbn() const
Get source block number.
Definition
headers.h:72
roc::fec::LDPC_Source_PayloadID::n
uint16_t n() const
Get number encoding symbols.
Definition
headers.h:102
roc::fec::LDPC_Source_PayloadID::set_sbn
void set_sbn(uint16_t val)
Set source block number.
Definition
headers.h:77
roc::fec::LDPC_Source_PayloadID::fec_scheme
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition
headers.h:62
roc::fec::LDPC_Source_PayloadID::set_n
void set_n(uint16_t)
Set number encoding symbols.
Definition
headers.h:107
roc::fec::LDPC_Source_PayloadID::set_esi
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition
headers.h:87
roc::fec::RS8M_PayloadID
Reed-Solomon Source or Repair Payload ID (for m=8).
Definition
headers.h:203
roc::fec::RS8M_PayloadID::fec_scheme
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition
headers.h:216
roc::fec::RS8M_PayloadID::sbn
uint32_t sbn() const
Get source block number.
Definition
headers.h:226
roc::fec::RS8M_PayloadID::set_esi
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition
headers.h:244
roc::fec::RS8M_PayloadID::n
uint16_t n() const
Get number encoding symbols.
Definition
headers.h:260
roc::fec::RS8M_PayloadID::set_k
void set_k(uint16_t val)
Set source block length.
Definition
headers.h:255
roc::fec::RS8M_PayloadID::clear
void clear()
Clear header.
Definition
headers.h:221
roc::fec::RS8M_PayloadID::set_n
void set_n(uint16_t)
Set number encoding symbols.
Definition
headers.h:265
roc::fec::RS8M_PayloadID::esi
uint8_t esi() const
Get encoding symbol ID.
Definition
headers.h:239
roc::fec::RS8M_PayloadID::set_sbn
void set_sbn(uint32_t val)
Set source block number.
Definition
headers.h:231
roc::fec::RS8M_PayloadID::k
uint16_t k() const
Get source block length.
Definition
headers.h:250
endian.h
Endian conversion functions.
fec.h
FEC packet.
roc::core::hton16u
uint16_t hton16u(uint16_t v)
Host to network byte order (unsigned 16-bit).
Definition
endian.h:54
roc::core::ntoh16u
uint16_t ntoh16u(uint16_t v)
Network to host byte order (unsigned 16-bit).
Definition
endian.h:24
roc::fec
FEC support.
roc::fec::PayloadID_Pos
PayloadID_Pos
FEC Payload ID position.
Definition
headers.h:31
roc::fec::Header
@ Header
PayloadID comes before payload.
Definition
headers.h:32
roc::fec::Footer
@ Footer
PayloadID comes after payload.
Definition
headers.h:33
roc::fec::PayloadID_Type
PayloadID_Type
FEC Payload ID type.
Definition
headers.h:25
roc::fec::Source
@ Source
Source packet header of footer.
Definition
headers.h:26
roc::fec::Repair
@ Repair
Source packet header of footer.
Definition
headers.h:27
roc::packet::FecScheme
FecScheme
FECFRAME scheme.
Definition
fec.h:23
roc::packet::FEC_ReedSolomon_M8
@ FEC_ReedSolomon_M8
Reed-Solomon (m=8).
Definition
fec.h:28
roc::packet::FEC_LDPC_Staircase
@ FEC_LDPC_Staircase
LDPC-Staircase.
Definition
fec.h:31
roc
Root namespace.
panic.h
Panic.
roc_panic_if
#define roc_panic_if(x)
Panic if condition is true.
Definition
panic.h:26
stddefs.h
Commonly used types and functions.
roc_fec
headers.h
Generated by
1.17.0