Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
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
21namespace roc {
22namespace fec {
23
24//! FEC Payload ID type.
26 Source, //!< Source packet header of footer.
27 Repair //!< Source packet header of footer.
28};
29
30//! FEC Payload ID position.
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
50private:
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
60public:
61 //! Get FEC scheme to which these packets belong to.
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 }
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
125private:
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
138public:
139 //! Get FEC scheme to which these packets belong to.
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 }
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
204private:
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
214public:
215 //! Get FEC scheme to which these packets belong to.
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 }
268
269} // namespace fec
270} // namespace roc
271
272#endif // ROC_FEC_HEADERS_H_
Compiler attributes.
#define ROC_ATTR_PACKED_BEGIN
Pack structure fields. Place these before class or struct keyword.
Definition attributes.h:55
#define ROC_ATTR_PACKED_END
Pack structure fields. Place these between '}' and ';'.
Definition attributes.h:58
LDPC-Staircase Repair FEC Payload ID.
Definition headers.h:124
uint16_t k() const
Get source block length.
Definition headers.h:170
void set_k(uint16_t val)
Set source block length.
Definition headers.h:175
uint16_t esi() const
Get encoding symbol ID.
Definition headers.h:160
void clear()
Clear header.
Definition headers.h:145
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition headers.h:165
void set_n(uint16_t val)
Set number encoding symbols.
Definition headers.h:185
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition headers.h:140
uint16_t n() const
Get number encoding symbols.
Definition headers.h:180
uint16_t sbn() const
Get source block number.
Definition headers.h:150
void set_sbn(uint16_t val)
Set source block number.
Definition headers.h:155
LDPC-Staircase Source FEC Payload ID.
Definition headers.h:49
uint16_t esi() const
Get encoding symbol ID.
Definition headers.h:82
void clear()
Clear header.
Definition headers.h:67
uint16_t k() const
Get source block length.
Definition headers.h:92
void set_k(uint16_t val)
Set source block length.
Definition headers.h:97
uint16_t sbn() const
Get source block number.
Definition headers.h:72
uint16_t n() const
Get number encoding symbols.
Definition headers.h:102
void set_sbn(uint16_t val)
Set source block number.
Definition headers.h:77
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition headers.h:62
void set_n(uint16_t)
Set number encoding symbols.
Definition headers.h:107
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition headers.h:87
Reed-Solomon Source or Repair Payload ID (for m=8).
Definition headers.h:203
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition headers.h:216
uint32_t sbn() const
Get source block number.
Definition headers.h:226
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition headers.h:244
uint16_t n() const
Get number encoding symbols.
Definition headers.h:260
void set_k(uint16_t val)
Set source block length.
Definition headers.h:255
void clear()
Clear header.
Definition headers.h:221
void set_n(uint16_t)
Set number encoding symbols.
Definition headers.h:265
uint8_t esi() const
Get encoding symbol ID.
Definition headers.h:239
void set_sbn(uint32_t val)
Set source block number.
Definition headers.h:231
uint16_t k() const
Get source block length.
Definition headers.h:250
Endian conversion functions.
FEC packet.
uint16_t hton16u(uint16_t v)
Host to network byte order (unsigned 16-bit).
Definition endian.h:54
uint16_t ntoh16u(uint16_t v)
Network to host byte order (unsigned 16-bit).
Definition endian.h:24
PayloadID_Pos
FEC Payload ID position.
Definition headers.h:31
@ Header
PayloadID comes before payload.
Definition headers.h:32
@ Footer
PayloadID comes after payload.
Definition headers.h:33
PayloadID_Type
FEC Payload ID type.
Definition headers.h:25
@ Source
Source packet header of footer.
Definition headers.h:26
@ Repair
Source packet header of footer.
Definition headers.h:27
FecScheme
FECFRAME scheme.
Definition fec.h:23
@ FEC_ReedSolomon_M8
Reed-Solomon (m=8).
Definition fec.h:28
@ FEC_LDPC_Staircase
LDPC-Staircase.
Definition fec.h:31
Root namespace.
Panic.
#define roc_panic_if(x)
Panic if condition is true.
Definition panic.h:26
Commonly used types and functions.