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

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

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

234 {
235  if (_buffer) free(_buffer);
236 }

Member Function Documentation

◆ content_encoding()

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

Get the content encoding.

Definition at line 89 of file AlcPacket.h.

89 { return _content_encoding; };

◆ data()

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

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

Definition at line 94 of file AlcPacket.h.

94 { return _buffer; };

◆ fdt_instance_id()

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

Get the FDT instance ID.

Definition at line 79 of file AlcPacket.h.

79 { return _fdt_instance_id; };

◆ fec_oti()

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

Get the FEC OTI values.

Definition at line 69 of file AlcPacket.h.

69 { return _fec_oti; };

◆ fec_scheme()

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

Get the FEC scheme.

Definition at line 84 of file AlcPacket.h.

84 { return _fec_oti.encoding_id; };

◆ header_length()

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

Get the LCT header length.

Definition at line 74 of file AlcPacket.h.

74 { return _lct_header.lct_header_len * 4; };

◆ size()

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

Get the payload size.

Definition at line 99 of file AlcPacket.h.

99 { return _len; };

◆ toi()

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

Get the TOI.

Definition at line 64 of file AlcPacket.h.

64 { return _toi; };

◆ tsi()

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

Get the TSI.

Definition at line 59 of file AlcPacket.h.

59 { return _tsi; };

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