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 // Licensed under the License terms and conditions for use, reproduction, and
6 // distribution of 5G-MAG software (the “License”). You may not use this file
7 // except in compliance with the License. You may obtain a copy of the License at
8 // https://www.5g-mag.com/reference-tools. Unless required by applicable law or
9 // agreed to in writing, software distributed under the License is distributed on
10 // an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 // or implied.
12 //
13 // See the License for the specific language governing permissions and limitations
14 // under the License.
15 //
16 #pragma once
17 #include <stddef.h>
18 #include <stdint.h>
19 #include <vector>
20 #include "flute_types.h"
21 #include "EncodingSymbol.h"
22 
23 namespace LibFlute {
27  class AlcPacket {
28  public:
35  AlcPacket(char* data, size_t len);
36 
47  AlcPacket(uint16_t tsi, uint16_t toi, FecOti fec_oti, const std::vector<EncodingSymbol>& symbols, size_t max_size, uint32_t fdt_instance_id);
48 
52  ~AlcPacket();
53 
57  uint64_t tsi() const { return _tsi; };
58 
62  uint64_t toi() const { return _toi; };
63 
67  const FecOti& fec_oti() const { return _fec_oti; };
68 
72  size_t header_length() const { return _lct_header.lct_header_len * 4; };
73 
77  uint32_t fdt_instance_id() const { return _fdt_instance_id; };
78 
82  FecScheme fec_scheme() const { return _fec_oti.encoding_id; };
83 
87  ContentEncoding content_encoding() const { return _content_encoding; };
88 
92  char* data() const { return _buffer; };
93 
97  size_t size() const { return _len; };
98 
99  private:
100  uint64_t _tsi = 0;
101  uint64_t _toi = 0;
102 
103  uint32_t _fdt_instance_id = 0;
104 
105  uint32_t _source_block_number = 0;
106  uint32_t _encoding_symbol_id = 0;
107 
108  ContentEncoding _content_encoding = ContentEncoding::NONE;
109  FecOti _fec_oti = {};
110 
111  char* _buffer = nullptr;
112  size_t _len;
113 
114  // RFC5651 5.1 - LCT Header Format
115  struct __attribute__((packed)) lct_header_t {
116 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
117  uint8_t res1:1;
118  uint8_t source_packet_indicator:1;
119  uint8_t congestion_control_flag:2;
120  uint8_t version:4;
121 
122  uint8_t close_object_flag:1;
123  uint8_t close_session_flag:1;
124  uint8_t res:2;
125  uint8_t half_word_flag:1;
126  uint8_t toi_flag:2;
127  uint8_t tsi_flag:1;
128 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
129  uint8_t version:4;
130  uint8_t congestion_control_flag:2;
131  uint8_t source_packet_indicator:1;
132  uint8_t res1:1;
133 
134  uint8_t tsi_flag:1;
135  uint8_t toi_flag:2;
136  uint8_t half_word_flag:1;
137  uint8_t res2:2;
138  uint8_t close_session_flag:1;
139  uint8_t close_object_flag:1;
140 #else
141 #error "Endianness can not be determined"
142 #endif
143  uint8_t lct_header_len;
144  uint8_t codepoint;
145  } _lct_header;
146  static_assert(sizeof(_lct_header) == 4);
147 
148  enum HeaderExtension {
149  EXT_NOP = 0,
150  EXT_AUTH = 1,
151  EXT_TIME = 2,
152  EXT_FTI = 64,
153  EXT_FDT = 192,
154  EXT_CENC = 193
155  };
156 
157  };
158 };
159 
A class for parsing and creating ALC packets.
Definition: AlcPacket.h:27
uint64_t tsi() const
Get the TSI.
Definition: AlcPacket.h:57
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:92
size_t header_length() const
Get the LCT header length.
Definition: AlcPacket.h:72
uint32_t fdt_instance_id() const
Get the FDT instance ID.
Definition: AlcPacket.h:77
ContentEncoding content_encoding() const
Get the content encoding.
Definition: AlcPacket.h:87
~AlcPacket()
Default destructor.
Definition: AlcPacket.cpp:217
const FecOti & fec_oti() const
Get the FEC OTI values.
Definition: AlcPacket.h:67
FecScheme fec_scheme() const
Get the FEC scheme.
Definition: AlcPacket.h:82
size_t size() const
Get the payload size.
Definition: AlcPacket.h:97
uint64_t toi() const
Get the TOI.
Definition: AlcPacket.h:62
AlcPacket(char *data, size_t len)
Create an ALC packet from payload data.
Definition: AlcPacket.cpp:21
FecScheme
Error correction schemes.
Definition: flute_types.h:44
ContentEncoding
Content Encodings.
Definition: flute_types.h:34
OTI values struct.
Definition: flute_types.h:51
FecScheme encoding_id
Definition: flute_types.h:52