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 21 of file AlcPacket.cpp.

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

218 {
219  if (_buffer) free(_buffer);
220 }

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: