libflute
AlcPacket.h
Go to the documentation of this file.
1 // libflute - FLUTE/ALC library
2 //
3 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 #pragma once
19 #include <stddef.h>
20 #include <stdint.h>
21 #include <vector>
22 #include "flute_types.h"
23 #include "EncodingSymbol.h"
24 
25 namespace LibFlute {
29  class AlcPacket {
30  public:
37  AlcPacket(char* data, size_t len);
38 
49  AlcPacket(uint16_t tsi, uint16_t toi, FecOti fec_oti, const std::vector<EncodingSymbol>& symbols, size_t max_size, uint32_t fdt_instance_id);
50 
54  ~AlcPacket();
55 
59  uint64_t tsi() const { return _tsi; };
60 
64  uint64_t toi() const { return _toi; };
65 
69  const FecOti& fec_oti() const { return _fec_oti; };
70 
74  size_t header_length() const { return _lct_header.lct_header_len * 4; };
75 
79  uint32_t fdt_instance_id() const { return _fdt_instance_id; };
80 
84  FecScheme fec_scheme() const { return _fec_oti.encoding_id; };
85 
89  ContentEncoding content_encoding() const { return _content_encoding; };
90 
94  char* data() const { return _buffer; };
95 
99  size_t size() const { return _len; };
100 
101  private:
102  uint64_t _tsi = 0;
103  uint64_t _toi = 0;
104 
105  uint32_t _fdt_instance_id = 0;
106 
107  uint32_t _source_block_number = 0;
108  uint32_t _encoding_symbol_id = 0;
109 
110  ContentEncoding _content_encoding = ContentEncoding::NONE;
111  FecOti _fec_oti = {};
112 
113  char* _buffer = nullptr;
114  size_t _len;
115 
116  // RFC5651 5.1 - LCT Header Format
117  struct __attribute__((packed)) lct_header_t {
118 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
119  uint8_t res1:1;
120  uint8_t source_packet_indicator:1;
121  uint8_t congestion_control_flag:2;
122  uint8_t version:4;
123 
124  uint8_t close_object_flag:1;
125  uint8_t close_session_flag:1;
126  uint8_t res:2;
127  uint8_t half_word_flag:1;
128  uint8_t toi_flag:2;
129  uint8_t tsi_flag:1;
130 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
131  uint8_t version:4;
132  uint8_t congestion_control_flag:2;
133  uint8_t source_packet_indicator:1;
134  uint8_t res1:1;
135 
136  uint8_t tsi_flag:1;
137  uint8_t toi_flag:2;
138  uint8_t half_word_flag:1;
139  uint8_t res2:2;
140  uint8_t close_session_flag:1;
141  uint8_t close_object_flag:1;
142 #else
143 #error "Endianness can not be determined"
144 #endif
145  uint8_t lct_header_len;
146  uint8_t codepoint;
147  } _lct_header;
148  static_assert(sizeof(_lct_header) == 4);
149 
150  enum HeaderExtension {
151  EXT_NOP = 0,
152  EXT_AUTH = 1,
153  EXT_TIME = 2,
154  EXT_FTI = 64,
155  EXT_FDT = 192,
156  EXT_CENC = 193
157  };
158 
159  };
160 };
161 
A class for parsing and creating ALC packets.
Definition: AlcPacket.h:29
uint64_t tsi() const
Get the TSI.
Definition: AlcPacket.h:59
AlcPacket(uint16_t tsi, uint16_t toi, FecOti fec_oti, const std::vector< EncodingSymbol > &symbols, size_t max_size, uint32_t fdt_instance_id)
Create an ALC packet from encoding symbols.
char * data() const
Get a pointer to the payload data of the constructed packet.
Definition: AlcPacket.h:94
size_t header_length() const
Get the LCT header length.
Definition: AlcPacket.h:74
uint32_t fdt_instance_id() const
Get the FDT instance ID.
Definition: AlcPacket.h:79
ContentEncoding content_encoding() const
Get the content encoding.
Definition: AlcPacket.h:89
~AlcPacket()
Default destructor.
Definition: AlcPacket.cpp:233
const FecOti & fec_oti() const
Get the FEC OTI values.
Definition: AlcPacket.h:69
FecScheme fec_scheme() const
Get the FEC scheme.
Definition: AlcPacket.h:84
size_t size() const
Get the payload size.
Definition: AlcPacket.h:99
uint64_t toi() const
Get the TOI.
Definition: AlcPacket.h:64
AlcPacket(char *data, size_t len)
Create an ALC packet from payload data.
Definition: AlcPacket.cpp:24
FecScheme
Error correction schemes.
Definition: flute_types.h:46
ContentEncoding
Content Encodings.
Definition: flute_types.h:36
OTI values struct.
Definition: flute_types.h:53
FecScheme encoding_id
Definition: flute_types.h:54