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 Source FEC Payload ID.
37//!
38//! @code
39//! 0 1 2 3
40//! 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
41//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42//! | Source Block Number (SBN) | Encoding Symbol ID (ESI) |
43//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44//! | Source Block Length (k) |
45//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46//! @endcode
48private:
49 //! Source block number.
50 uint16_t sbn_;
51
52 //! Encoding symbol ID.
53 uint16_t esi_;
54
55 //! Source block length.
56 uint16_t k_;
57
58public:
59 //! Get FEC scheme to which these packets belong to.
62 }
63
64 //! Clear header.
65 void clear() {
66 memset(this, 0, sizeof(*this));
67 }
68
69 //! Get source block number.
70 uint16_t sbn() const {
71 return core::ntoh16u(sbn_);
72 }
73
74 //! Set source block number.
75 void set_sbn(uint16_t val) {
76 sbn_ = core::hton16u(val);
77 }
78
79 //! Get encoding symbol ID.
80 uint16_t esi() const {
81 return core::ntoh16u(esi_);
82 }
83
84 //! Set encoding symbol ID.
85 void set_esi(uint16_t val) {
86 esi_ = core::hton16u(val);
87 }
88
89 //! Get source block length.
90 uint16_t k() const {
91 return core::ntoh16u(k_);
92 }
93
94 //! Set source block length.
95 void set_k(uint16_t val) {
96 k_ = core::hton16u(val);
97 }
98
99 //! Get number encoding symbols.
100 uint16_t n() const {
101 return 0;
102 }
103
104 //! Set number encoding symbols.
105 void set_n(uint16_t) {
106 }
108
109//! LDPC Repair FEC Payload ID.
110//!
111//! @code
112//! 0 1 2 3
113//! 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
114//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115//! | Source Block Number (SBN) | Encoding Symbol ID (ESI) |
116//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117//! | Source Block Length (k) | Number Encoding Symbols (n) |
118//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119//! @endcode
121private:
122 //! Source block number.
123 uint16_t sbn_;
124
125 //! Encoding symbol ID.
126 uint16_t esi_;
127
128 //! Source block length.
129 uint16_t k_;
130
131 //! Number encoding symbols.
132 uint16_t n_;
133
134public:
135 //! Get FEC scheme to which these packets belong to.
138 }
139
140 //! Clear header.
141 void clear() {
142 memset(this, 0, sizeof(*this));
143 }
144
145 //! Get source block number.
146 uint16_t sbn() const {
147 return core::ntoh16u(sbn_);
148 }
149
150 //! Set source block number.
151 void set_sbn(uint16_t val) {
152 sbn_ = core::hton16u(val);
153 }
154
155 //! Get encoding symbol ID.
156 uint16_t esi() const {
157 return core::ntoh16u(esi_);
158 }
159
160 //! Set encoding symbol ID.
161 void set_esi(uint16_t val) {
162 esi_ = core::hton16u(val);
163 }
164
165 //! Get source block length.
166 uint16_t k() const {
167 return core::ntoh16u(k_);
168 }
169
170 //! Set source block length.
171 void set_k(uint16_t val) {
172 k_ = core::hton16u(val);
173 }
174
175 //! Get number encoding symbols.
176 uint16_t n() const {
177 return core::ntoh16u(n_);
178 }
179
180 //! Set number encoding symbols.
181 void set_n(uint16_t val) {
182 n_ = core::hton16u(val);
183 }
185
186//! Reed-Solomon Source or Repair Payload ID (for m=8).
187//!
188//! @code
189//! 0 1 2 3
190//! 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
191//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
192//! | Source Block Number (24 bits) | Enc. Symb. ID |
193//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
194//! | Source Block Length (k) |
195//! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
196//! @endcode
198private:
199 //! Source block number.
200 uint8_t sbn_[3];
201
202 //! Encoding symbol ID.
203 uint8_t esi_;
204
205 //! Source block length.
206 uint16_t k_;
207
208public:
209 //! Get FEC scheme to which these packets belong to.
212 }
213
214 //! Clear header.
215 void clear() {
216 memset(this, 0, sizeof(*this));
217 }
218
219 //! Get source block number.
220 uint32_t sbn() const {
221 return (uint32_t(sbn_[0]) << 16) | (uint32_t(sbn_[1]) << 8) | uint32_t(sbn_[2]);
222 }
223
224 //! Set source block number.
225 void set_sbn(uint32_t val) {
226 roc_panic_if((val >> 24) != 0);
227 sbn_[0] = uint8_t((val >> 16) & 0xff);
228 sbn_[1] = uint8_t((val >> 8) & 0xff);
229 sbn_[2] = uint8_t(val & 0xff);
230 }
231
232 //! Get encoding symbol ID.
233 uint8_t esi() const {
234 return esi_;
235 }
236
237 //! Set encoding symbol ID.
238 void set_esi(uint16_t val) {
239 roc_panic_if((val >> 8) != 0);
240 esi_ = (uint8_t)val;
241 }
242
243 //! Get source block length.
244 uint16_t k() const {
245 return core::ntoh16u(k_);
246 }
247
248 //! Set source block length.
249 void set_k(uint16_t val) {
250 k_ = core::hton16u(val);
251 }
252
253 //! Get number encoding symbols.
254 uint16_t n() const {
255 return 255;
256 }
257
258 //! Set number encoding symbols.
259 void set_n(uint16_t) {
260 }
262
263} // namespace fec
264} // namespace roc
265
266#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:47
#define ROC_ATTR_PACKED_END
Pack structure fields. Place these between '}' and ';'.
Definition: attributes.h:50
LDPC Repair FEC Payload ID.
Definition: headers.h:120
uint16_t k() const
Get source block length.
Definition: headers.h:166
void set_k(uint16_t val)
Set source block length.
Definition: headers.h:171
uint16_t esi() const
Get encoding symbol ID.
Definition: headers.h:156
void clear()
Clear header.
Definition: headers.h:141
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition: headers.h:161
void set_n(uint16_t val)
Set number encoding symbols.
Definition: headers.h:181
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition: headers.h:136
uint16_t n() const
Get number encoding symbols.
Definition: headers.h:176
uint16_t sbn() const
Get source block number.
Definition: headers.h:146
void set_sbn(uint16_t val)
Set source block number.
Definition: headers.h:151
LDPC Source FEC Payload ID.
Definition: headers.h:47
uint16_t esi() const
Get encoding symbol ID.
Definition: headers.h:80
void clear()
Clear header.
Definition: headers.h:65
uint16_t k() const
Get source block length.
Definition: headers.h:90
void set_k(uint16_t val)
Set source block length.
Definition: headers.h:95
uint16_t sbn() const
Get source block number.
Definition: headers.h:70
uint16_t n() const
Get number encoding symbols.
Definition: headers.h:100
void set_sbn(uint16_t val)
Set source block number.
Definition: headers.h:75
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition: headers.h:60
void set_n(uint16_t)
Set number encoding symbols.
Definition: headers.h:105
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition: headers.h:85
Reed-Solomon Source or Repair Payload ID (for m=8).
Definition: headers.h:197
static packet::FecScheme fec_scheme()
Get FEC scheme to which these packets belong to.
Definition: headers.h:210
uint32_t sbn() const
Get source block number.
Definition: headers.h:220
void set_esi(uint16_t val)
Set encoding symbol ID.
Definition: headers.h:238
uint16_t n() const
Get number encoding symbols.
Definition: headers.h:254
void set_k(uint16_t val)
Set source block length.
Definition: headers.h:249
void clear()
Clear header.
Definition: headers.h:215
void set_n(uint16_t)
Set number encoding symbols.
Definition: headers.h:259
uint8_t esi() const
Get encoding symbol ID.
Definition: headers.h:233
void set_sbn(uint32_t val)
Set source block number.
Definition: headers.h:225
uint16_t k() const
Get source block length.
Definition: headers.h:244
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.