libflute
Public Member Functions | List of all members
LibFlute::AlcPacket Class Reference

A class for parsing and creating ALC packets. More...

#include <AlcPacket.h>

Public Member Functions

 AlcPacket (char *data, size_t len)
 Create an ALC packet from payload data. More...
 
 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. More...
 
 ~AlcPacket ()
 Default destructor. More...
 
uint64_t tsi () const
 Get the TSI. More...
 
uint64_t toi () const
 Get the TOI. More...
 
const FecOtifec_oti () const
 Get the FEC OTI values. More...
 
size_t header_length () const
 Get the LCT header length. More...
 
uint32_t fdt_instance_id () const
 Get the FDT instance ID. More...
 
FecScheme fec_scheme () const
 Get the FEC scheme. More...
 
ContentEncoding content_encoding () const
 Get the content encoding. More...
 
char * data () const
 Get a pointer to the payload data of the constructed packet. More...
 
size_t size () const
 Get the payload size. More...
 

Detailed Description

A class for parsing and creating ALC packets.

Definition at line 27 of file AlcPacket.h.

Constructor & Destructor Documentation

◆ AlcPacket() [1/2]

LibFlute::AlcPacket::AlcPacket ( char *  data,
size_t  len 
)

Create an ALC packet from payload data.

Parameters
dataReceived data to be parsed
lenLength of the buffer

Definition at line 22 of file AlcPacket.cpp.

23 {
24  if (len < 4) {
25  throw std::runtime_error("Packet too short");
26  }
27 
28  std::memcpy(&_lct_header, data, 4);
29  if (_lct_header.version != 1) {
30  throw std::runtime_error("Unsupported LCT version");
31  }
32 
33  char* hdr_ptr = data + 4;
34  if (_lct_header.congestion_control_flag != 0) {
35  throw std::runtime_error("Unsupported CCI field length");
36  }
37  // [TODO] read CCI
38  hdr_ptr += 4;
39 
40  if (_lct_header.half_word_flag == 0 && _lct_header.tsi_flag == 0) {
41  throw std::runtime_error("TSI field not present");
42  }
43  auto tsi_shift = 0;
44  if(_lct_header.half_word_flag == 1) {
45  _tsi = ntohs(*(uint16_t*)hdr_ptr);
46  tsi_shift = 16;
47  hdr_ptr += 2;
48  }
49  if(_lct_header.tsi_flag == 1) {
50  _tsi |= ntohl(*(uint32_t*)hdr_ptr) << tsi_shift;
51  hdr_ptr += 4;
52  }
53 
54  if ( _lct_header.close_session_flag == 0 && _lct_header.half_word_flag == 0 && _lct_header.toi_flag == 0) {
55  throw std::runtime_error("TOI field not present");
56  }
57  auto toi_shift = 0;
58  if(_lct_header.half_word_flag == 1) {
59  _toi = ntohs(*(uint16_t*)hdr_ptr);
60  toi_shift = 16;
61  hdr_ptr += 2;
62  }
63  switch(_lct_header.toi_flag) {
64  case 0: break;
65  case 1:
66  _toi |= ntohl(*(uint32_t*)hdr_ptr) << toi_shift;
67  hdr_ptr += 4;
68  break;
69  case 2:
70  if (toi_shift > 0) {
71  throw std::runtime_error("TOI fields over 64 bits in length are not supported");
72  } else {
73  _toi = ntohl(*(uint32_t*)hdr_ptr);
74  hdr_ptr += 4;
75  _toi |= (uint64_t)(ntohl(*(uint32_t*)hdr_ptr)) << 32;
76  hdr_ptr += 4;
77  }
78  break;
79  default:
80  throw std::runtime_error("TOI fields over 64 bits in length are not supported");
81  }
82 
83  if (_lct_header.codepoint == 0) {
85  } else {
86  throw std::runtime_error("Only Compact No-Code FEC is supported");
87  }
88 
89  auto expected_header_len = 2 +
90  _lct_header.congestion_control_flag +
91  _lct_header.half_word_flag +
92  _lct_header.tsi_flag +
93  _lct_header.toi_flag;
94 
95  size_t ext_header_len = (_lct_header.lct_header_len - expected_header_len) * 4;
96  while (ext_header_len > 0) {
97  auto ext_ptr = hdr_ptr;
98  uint8_t het = *ext_ptr;
99  ext_ptr += 1; // Skip HET
100  uint8_t hel = 0;
101  size_t ext_len = 4;
102  if (het <= 127) {
103  hel = *ext_ptr;
104  ext_len = hel * 4;
105  ext_ptr += 1; // Skip HEL
106  }
107 
108  if (ext_len > ext_header_len) {
109  throw std::runtime_error("Header extension length exceeds remaining header length");
110  }
111 
112  switch ((AlcPacket::HeaderExtension)het) {
113  case EXT_NOP:
114  case EXT_AUTH:
115  case EXT_TIME: {
116  break; // ignored
117  }
118  case EXT_FTI: {
119  if (_fec_oti.encoding_id == FecScheme::CompactNoCode) {
120  if (hel != 4) {
121  throw std::runtime_error("Invalid length for EXT_FTI header extension");
122  }
123  _fec_oti.transfer_length = (uint64_t)(ntohs(*(uint16_t*)ext_ptr)) << 32;
124  ext_ptr += 2;
125  _fec_oti.transfer_length |= (uint64_t)(ntohl(*(uint32_t*)ext_ptr));
126  ext_ptr += 4;
127  ext_ptr += 2; // reserved
128  _fec_oti.encoding_symbol_length = ntohs(*(uint16_t*)ext_ptr);
129  ext_ptr += 2;
130  _fec_oti.max_source_block_length = ntohl(*(uint32_t*)ext_ptr);
131  }
132  break;
133  }
134  case EXT_FDT: {
135  uint8_t flute_version = (*ext_ptr & 0xF0) >> 4;
136  if (flute_version > 2) {
137  throw std::runtime_error("Unsupported FLUTE version");
138  }
139  _fdt_instance_id = (*ext_ptr & 0x0F) << 16;
140  ext_ptr++;
141  _fdt_instance_id |= ntohs(*(uint16_t*)ext_ptr);
142  break;
143  }
144  case EXT_CENC: {
145  uint8_t encoding = *ext_ptr;
146  switch (encoding) {
147  case 0: _content_encoding = ContentEncoding::NONE; break;
148  case 1: _content_encoding = ContentEncoding::ZLIB; break;
149  case 2: _content_encoding = ContentEncoding::DEFLATE; break;
150  case 3: _content_encoding = ContentEncoding::GZIP; break;
151  }
152  break;
153  }
154  }
155 
156  ext_header_len -= ext_len;
157  hdr_ptr += ext_len;
158  }
159 }
char * data() const
Get a pointer to the payload data of the constructed packet.
Definition: AlcPacket.h:92
uint64_t transfer_length
Definition: flute_types.h:54
FecScheme encoding_id
Definition: flute_types.h:52
uint32_t max_source_block_length
Definition: flute_types.h:56
uint32_t encoding_symbol_length
Definition: flute_types.h:55

◆ AlcPacket() [2/2]

LibFlute::AlcPacket::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.

Parameters
tsiTransport Stream Identifier
toiTransport Object Identifier
fec_otiOTI values
symbolsVector of encoding symbols
max_sizeMaximum payload size
fdt_instance_idFDT instance ID (only relevant for FDT with TOI=0)

◆ ~AlcPacket()

LibFlute::AlcPacket::~AlcPacket ( )

Default destructor.

Definition at line 224 of file AlcPacket.cpp.

225 {
226  if (_buffer) free(_buffer);
227 }

Member Function Documentation

◆ content_encoding()

ContentEncoding LibFlute::AlcPacket::content_encoding ( ) const
inline

Get the content encoding.

Definition at line 87 of file AlcPacket.h.

87 { return _content_encoding; };

◆ data()

char* LibFlute::AlcPacket::data ( ) const
inline

Get a pointer to the payload data of the constructed packet.

Definition at line 92 of file AlcPacket.h.

92 { return _buffer; };

◆ fdt_instance_id()

uint32_t LibFlute::AlcPacket::fdt_instance_id ( ) const
inline

Get the FDT instance ID.

Definition at line 77 of file AlcPacket.h.

77 { return _fdt_instance_id; };

◆ fec_oti()

const FecOti& LibFlute::AlcPacket::fec_oti ( ) const
inline

Get the FEC OTI values.

Definition at line 67 of file AlcPacket.h.

67 { return _fec_oti; };

◆ fec_scheme()

FecScheme LibFlute::AlcPacket::fec_scheme ( ) const
inline

Get the FEC scheme.

Definition at line 82 of file AlcPacket.h.

82 { return _fec_oti.encoding_id; };

◆ header_length()

size_t LibFlute::AlcPacket::header_length ( ) const
inline

Get the LCT header length.

Definition at line 72 of file AlcPacket.h.

72 { return _lct_header.lct_header_len * 4; };

◆ size()

size_t LibFlute::AlcPacket::size ( ) const
inline

Get the payload size.

Definition at line 97 of file AlcPacket.h.

97 { return _len; };

◆ toi()

uint64_t LibFlute::AlcPacket::toi ( ) const
inline

Get the TOI.

Definition at line 62 of file AlcPacket.h.

62 { return _toi; };

◆ tsi()

uint64_t LibFlute::AlcPacket::tsi ( ) const
inline

Get the TSI.

Definition at line 57 of file AlcPacket.h.

57 { return _tsi; };

The documentation for this class was generated from the following files: