12 #ifndef ROC_FEC_COMPOSER_H_
13 #define ROC_FEC_COMPOSER_H_
25 template <
class PayloadID, PayloadID_Type Type, PayloadID_Pos Pos>
33 : inner_composer_(inner_composer) {
39 if ((
unsigned long)buffer.
data() % payload_alignment != 0) {
40 roc_panic(
"fec composer: unexpected non-aligned buffer");
44 header_size +=
sizeof(PayloadID);
47 if (inner_composer_ == NULL) {
53 "fec composer: not enough space for alignment: padding=%lu cap=%lu",
54 (
unsigned long)padding, (
unsigned long)buffer.
capacity());
58 buffer.
reslice(padding, padding);
61 return inner_composer_->
align(buffer, header_size, payload_alignment);
71 if (payload_id.
capacity() <
sizeof(PayloadID)) {
73 "fec composer: not enough space for fec header: size=%lu cap=%lu",
74 (
unsigned long)
sizeof(PayloadID),
75 (
unsigned long)payload_id.
capacity());
78 payload_id.
reslice(0,
sizeof(PayloadID));
84 if (inner_composer_) {
85 if (!inner_composer_->
prepare(packet, payload, payload_size)) {
89 payload.
reslice(0, payload_size);
95 if (payload_id.
capacity() <
sizeof(PayloadID)) {
97 "fec composer: not enough space for fec header: size=%lu cap=%lu",
98 (
unsigned long)
sizeof(PayloadID),
99 (
unsigned long)payload_id.
capacity());
102 payload_id.
reslice(0,
sizeof(PayloadID));
124 if (inner_composer_) {
125 return inner_composer_->
pad(packet, padding_size);
135 roc_panic(
"fec composer: unexpected non-fec packet");
139 roc_panic(
"fec composer: unexpected payload id size");
159 if (inner_composer_) {
160 return inner_composer_->
compose(packet);
static size_t pad_as(size_t size, size_t alignment)
Return padding needed for given alignment.
Base class for non-copyable objects.
Slice subslice(size_t from, size_t to) const
Construct a slice pointing to a part of this slice.
size_t capacity() const
Get maximum possible number of elements in slice.
T * data() const
Get slice data.
void reslice(size_t from, size_t to)
Change slice beginning and ending inside the buffer.
size_t size() const
Get number of elements in slice.
FECFRAME packet composer.
virtual bool pad(packet::Packet &packet, size_t padding_size)
Pad packet.
virtual bool compose(packet::Packet &packet)
Compose packet to buffer.
Composer(packet::IComposer *inner_composer)
Initialization.
virtual bool prepare(packet::Packet &packet, core::Slice< uint8_t > &buffer, size_t payload_size)
Prepare buffer for composing a packet.
virtual bool align(core::Slice< uint8_t > &buffer, size_t header_size, size_t payload_alignment)
Adjust buffer to align payload.
Packet composer interface.
virtual bool align(core::Slice< uint8_t > &buffer, size_t header_size, size_t payload_alignment)=0
Adjust buffer to align payload.
virtual bool pad(Packet &packet, size_t padding_size)=0
Pad packet.
virtual bool prepare(Packet &packet, core::Slice< uint8_t > &buffer, size_t payload_size)=0
Prepare buffer for composing a packet.
virtual bool compose(Packet &packet)=0
Compose packet to buffer.
const FEC * fec() const
FEC packet.
@ FlagRepair
Packet contains repair FEC symbols.
@ FlagFEC
Packet contains FEC header.
void add_flags(unsigned flags)
Add flags.
Packet composer interface.
#define roc_log(level,...)
Print message to log.
@ Header
PayloadID comes before payload.
@ Footer
PayloadID comes after payload.
@ Repair
Source packet header of footer.
@ LogDebug
Regular debug message.
#define roc_panic_if(x)
Panic if condition is true.
#define roc_panic(...)
Print error message and terminate program gracefully.
core::Slice< uint8_t > payload
FECFRAME payload.
size_t encoding_symbol_id
The index number of packet in a block ("esi").
size_t source_block_length
Number of source packets in block to which this packet belongs ("sblen").
FecScheme fec_scheme
The FEC scheme to which the packet belongs to.
size_t block_length
Number of source + repair packets in block to which this packet belongs ("blen").
blknum_t source_block_number
Number of a source block in a packet stream ("sbn").
core::Slice< uint8_t > payload_id
FECFRAME header or footer.