TSDuck Version 3.16-1064 (TSDuck - The MPEG Transport Stream Toolkit)
ts::Section Class Reference

Representation of MPEG PSI/SI sections. More...

Public Member Functions

 Section ()
 Default constructor. More...
 
 Section (const Section &other, CopyShare mode)
 Copy constructor. More...
 
 Section (const void *content, size_t content_size, PID source_pid=PID_NULL, CRC32::Validation crc_op=CRC32::IGNORE)
 Constructor from full binary content. More...
 
 Section (const ByteBlock &content, PID source_pid=PID_NULL, CRC32::Validation crc_op=CRC32::IGNORE)
 Constructor from full binary content. More...
 
 Section (const ByteBlockPtr &content_ptr, PID source_pid=PID_NULL, CRC32::Validation crc_op=CRC32::IGNORE)
 Constructor from full binary content. More...
 
 Section (TID tid, bool is_private_section, const void *payload, size_t payload_size, PID source_pid=PID_NULL)
 Constructor from a short section payload. More...
 
 Section (TID tid, bool is_private_section, uint16_t tid_ext, uint8_t version, bool is_current, uint8_t section_number, uint8_t last_section_number, const void *payload, size_t payload_size, PID source_pid=PID_NULL)
 Constructor from a long section payload. More...
 
void clear ()
 Clear section content. More...
 
const uint8_t * content () const
 Access to the full binary content of the section. More...
 
Sectioncopy (const Section &other)
 Duplication. More...
 
std::ostream & dump (std::ostream &strm, int indent=0, CASFamily cas=CAS_OTHER, bool no_header=false) const
 Hexa dump the section on an output stream without interpretation of the payload. More...
 
ETID etid () const
 Get the table id and id extension (long section only). More...
 
PacketCounter getFirstTSPacketIndex () const
 Index of first TS packet of the section in the demultiplexed stream. More...
 
PacketCounter getLastTSPacketIndex () const
 Index of last TS packet of the section in the demultiplexed stream. More...
 
bool hasDiversifiedPayload () const
 Check if the section has a "diversified" payload. More...
 
size_t headerSize () const
 Size of the section header. More...
 
bool isCurrent () const
 Check if the section is "current", not "next" (long section only). More...
 
bool isLongSection () const
 Check if the section is a long one. More...
 
bool isNext () const
 Check if the section is "next", not "current" (long section only). More...
 
bool isPrivateSection () const
 Check if the section is a private one (ie. More...
 
bool isShortSection () const
 Check if the section is a short one. More...
 
bool isValid () const
 Check if the section has valid content. More...
 
uint8_t lastSectionNumber () const
 Get the number of the last section in the table (long section only). More...
 
bool operator!= (const Section &other) const
 Unequality operator. More...
 
Sectionoperator= (const Section &other)
 Assignment operator. More...
 
bool operator== (const Section &other) const
 Equality operator. More...
 
PacketCounter packetCount () const
 Minimum number of TS packets required to transport the section. More...
 
const uint8_t * payload () const
 Access to the payload of the section. More...
 
size_t payloadSize () const
 Get the size of the payload of the section. More...
 
std::istream & read (std::istream &strm, CRC32::Validation crc_op=CRC32::IGNORE, Report &report=(*ts::CerrReport::Instance()))
 Read a section from standard streams (binary mode). More...
 
void recomputeCRC ()
 This method recomputes and replaces the CRC32 of the section.
 
void reload (const void *content, size_t content_size, PID source_pid=PID_NULL, CRC32::Validation crc_op=CRC32::IGNORE)
 Reload from full binary content. More...
 
void reload (const ByteBlock &content, PID source_pid=PID_NULL, CRC32::Validation crc_op=CRC32::IGNORE)
 Reload from full binary content. More...
 
void reload (const ByteBlockPtr &content_ptr, PID source_pid=PID_NULL, CRC32::Validation crc_op=CRC32::IGNORE)
 Reload from full binary content. More...
 
void reload (TID tid, bool is_private_section, const void *payload, size_t payload_size, PID source_pid=PID_NULL)
 Reload from a short section payload. More...
 
void reload (TID tid, bool is_private_section, uint16_t tid_ext, uint8_t version, bool is_current, uint8_t section_number, uint8_t last_section_number, const void *payload, size_t payload_size, PID source_pid=PID_NULL)
 Reload from a long section payload. More...
 
uint8_t sectionNumber () const
 Get the section number in the table (long section only). More...
 
void setFirstTSPacketIndex (PacketCounter i)
 Set the first TS packet of the section in the demultiplexed stream. More...
 
void setIsCurrent (bool is_current, bool recompute_crc=true)
 Set the section current/next flag (long section only). More...
 
void setLastSectionNumber (uint8_t num, bool recompute_crc=true)
 Set the number of the last section in the table (long section only). More...
 
void setLastTSPacketIndex (PacketCounter i)
 Set the last TS packet of the section in the demultiplexed stream. More...
 
void setSectionNumber (uint8_t num, bool recompute_crc=true)
 Set the section number (long section only). More...
 
void setSourcePID (PID pid)
 Set the source PID. More...
 
void setTableIdExtension (uint16_t tid_ext, bool recompute_crc=true)
 Set the table id extension (long section only). More...
 
void setUInt16 (size_t offset, uint16_t value, bool recompute_crc=true)
 Set a 16-bit integer in the payload of the section. More...
 
void setUInt8 (size_t offset, uint8_t value, bool recompute_crc=true)
 Set one byte in the payload of the section. More...
 
void setVersion (uint8_t version, bool recompute_crc=true)
 Set the section version number (long section only). More...
 
size_t size () const
 Size of the binary content of the section. More...
 
PID sourcePID () const
 Get the source PID. More...
 
TID tableId () const
 Get the table id. More...
 
uint16_t tableIdExtension () const
 Get the table id extension (long section only). More...
 
uint8_t version () const
 Get the section version number (long section only). More...
 
std::ostream & write (std::ostream &strm, Report &report=(*ts::CerrReport::Instance())) const
 Write a section to standard streams (binary mode). More...
 

Static Public Member Functions

template<class CONTAINER >
static PacketCounter PacketCount (const CONTAINER &container, bool pack=true)
 Static method to compute the minimum number of TS packets required to transport a set of sections. More...
 
static size_t SectionSize (const void *content, size_t content_size)
 Static method to compute a section size. More...
 
static size_t SectionSize (const ByteBlock &content)
 Static method to compute a section size. More...
 

Detailed Description

Representation of MPEG PSI/SI sections.

What to do with the CRC32 when building a section depends on the parameter named crc_op:

  • IGNORE: Neither check nor compute.
  • CHECK: Validate the CRC from the section data. Mark the section as invalid if CRC is incorrect.
  • COMPUTE: Compute the CRC and store it in the section.

Typically, if the ByteBlock comes from the wire, use CHECK. If the ByteBlock is built by the application, use COMPUTE,

Constructor & Destructor Documentation

◆ Section() [1/7]

ts::Section::Section ( )

Default constructor.

Section is initially marked invalid.

◆ Section() [2/7]

ts::Section::Section ( const Section other,
CopyShare  mode 
)

Copy constructor.

Parameters
[in]otherAnother instance to copy.
[in]modeThe section's data are either shared (ts::SHARE) between the two instances or duplicated (ts::COPY).

◆ Section() [3/7]

ts::Section::Section ( const void *  content,
size_t  content_size,
PID  source_pid = PID_NULL,
CRC32::Validation  crc_op = CRC32::IGNORE 
)

Constructor from full binary content.

The content is copied into the section if valid.

Parameters
[in]contentAddress of the binary section data.
[in]content_sizeSize in bytes of the section.
[in]source_pidPID from which the section was read.
[in]crc_opHow to process the CRC32.

◆ Section() [4/7]

ts::Section::Section ( const ByteBlock content,
PID  source_pid = PID_NULL,
CRC32::Validation  crc_op = CRC32::IGNORE 
)

Constructor from full binary content.

The content is copied into the section if valid.

Parameters
[in]contentBinary section data.
[in]source_pidPID from which the section was read.
[in]crc_opHow to process the CRC32.

◆ Section() [5/7]

ts::Section::Section ( const ByteBlockPtr content_ptr,
PID  source_pid = PID_NULL,
CRC32::Validation  crc_op = CRC32::IGNORE 
)

Constructor from full binary content.

The content is copied into the section if valid.

Parameters
[in]content_ptrSafe pointer to the binary section data. The content is referenced, and thus shared. Do not modify the referenced ByteBlock from outside the Section.
[in]source_pidPID from which the section was read.
[in]crc_opHow to process the CRC32.

◆ Section() [6/7]

ts::Section::Section ( TID  tid,
bool  is_private_section,
const void *  payload,
size_t  payload_size,
PID  source_pid = PID_NULL 
)

Constructor from a short section payload.

Parameters
[in]tidTable id.
[in]is_private_sectionIf true, this is a private section (ie. not MPEG-defined).
[in]payloadAddress of the payload data.
[in]payload_sizeSize in bytes of the payload data.
[in]source_pidPID from which the section was read.

◆ Section() [7/7]

ts::Section::Section ( TID  tid,
bool  is_private_section,
uint16_t  tid_ext,
uint8_t  version,
bool  is_current,
uint8_t  section_number,
uint8_t  last_section_number,
const void *  payload,
size_t  payload_size,
PID  source_pid = PID_NULL 
)

Constructor from a long section payload.

The provided payload does not contain the CRC32. The CRC32 is automatically computed.

Parameters
[in]tidTable id.
[in]is_private_sectionIf true, this is a private section (ie. not MPEG-defined).
[in]tid_extTable id extension.
[in]versionSection version number.
[in]is_currentIf true, this is a "current" section, not a "next" section.
[in]section_numberSection number.
[in]last_section_numberNumber of last section in the table.
[in]payloadAddress of the payload data.
[in]payload_sizeSize in bytes of the payload data.
[in]source_pidPID from which the section was read.

Member Function Documentation

◆ reload() [1/5]

void ts::Section::reload ( const void *  content,
size_t  content_size,
PID  source_pid = PID_NULL,
CRC32::Validation  crc_op = CRC32::IGNORE 
)
inline

Reload from full binary content.

The content is copied into the section if valid.

Parameters
[in]contentAddress of the binary section data.
[in]content_sizeSize in bytes of the section.
[in]source_pidPID from which the section was read.
[in]crc_opHow to process the CRC32.

◆ reload() [2/5]

void ts::Section::reload ( const ByteBlock content,
PID  source_pid = PID_NULL,
CRC32::Validation  crc_op = CRC32::IGNORE 
)
inline

Reload from full binary content.

Parameters
[in]contentBinary section data.
[in]source_pidPID from which the section was read.
[in]crc_opHow to process the CRC32.

◆ reload() [3/5]

void ts::Section::reload ( const ByteBlockPtr content_ptr,
PID  source_pid = PID_NULL,
CRC32::Validation  crc_op = CRC32::IGNORE 
)
inline

Reload from full binary content.

Parameters
[in]content_ptrSafe pointer to the binary section data. The content is referenced, and thus shared. Do not modify the referenced ByteBlock from outside the Section.
[in]source_pidPID from which the section was read.
[in]crc_opHow to process the CRC32.

◆ reload() [4/5]

void ts::Section::reload ( TID  tid,
bool  is_private_section,
const void *  payload,
size_t  payload_size,
PID  source_pid = PID_NULL 
)

Reload from a short section payload.

Parameters
[in]tidTable id.
[in]is_private_sectionIf true, this is a private section (ie. not MPEG-defined).
[in]payloadAddress of the payload data.
[in]payload_sizeSize in bytes of the payload data.
[in]source_pidPID from which the section was read.

◆ reload() [5/5]

void ts::Section::reload ( TID  tid,
bool  is_private_section,
uint16_t  tid_ext,
uint8_t  version,
bool  is_current,
uint8_t  section_number,
uint8_t  last_section_number,
const void *  payload,
size_t  payload_size,
PID  source_pid = PID_NULL 
)

Reload from a long section payload.

The provided payload does not contain the CRC32. The CRC32 is automatically computed.

Parameters
[in]tidTable id.
[in]is_private_sectionIf true, this is a private section (ie. not MPEG-defined).
[in]tid_extTable id extension.
[in]versionSection version number.
[in]is_currentIf true, this is a "current" section, not a "next" section.
[in]section_numberSection number.
[in]last_section_numberNumber of last section in the table.
[in]payloadAddress of the payload data.
[in]payload_sizeSize in bytes of the payload data.
[in]source_pidPID from which the section was read.

◆ clear()

void ts::Section::clear ( )
inline

Clear section content.

Becomes invalid section.

◆ operator=()

Section& ts::Section::operator= ( const Section other)

Assignment operator.

The sections contents are referenced, and thus shared between the two section objects.

Parameters
[in]otherOther section to assign to this object.
Returns
A reference to this object.

◆ copy()

Section& ts::Section::copy ( const Section other)

Duplication.

Similar to assignment but the sections are duplicated.

Parameters
[in]otherOther section to duplicate into this object.
Returns
A reference to this object.

◆ isValid()

bool ts::Section::isValid ( ) const
inline

Check if the section has valid content.

Returns
True if the section has valid content.

◆ operator==()

bool ts::Section::operator== ( const Section other) const

Equality operator.

The source PID's are ignored, only the section contents are compared. Invalid sections are never identical.

Parameters
[in]otherOther section to compare.
Returns
True if the two sections are identical. False otherwise.

◆ operator!=()

bool ts::Section::operator!= ( const Section other) const
inline

Unequality operator.

The source PID's are ignored, only the section contents are compared. Invalid sections are never identical.

Parameters
[in]otherOther section to compare.
Returns
True if the two sections are different. False otherwise.

◆ tableId()

TID ts::Section::tableId ( ) const
inline

Get the table id.

Returns
The table id.

◆ isLongSection()

bool ts::Section::isLongSection ( ) const
inline

Check if the section is a long one.

Returns
True if the section is a long one.

◆ isShortSection()

bool ts::Section::isShortSection ( ) const
inline

Check if the section is a short one.

Returns
True if the section is a short one.

◆ isPrivateSection()

bool ts::Section::isPrivateSection ( ) const
inline

Check if the section is a private one (ie.

not MPEG-defined).

Returns
True if the section is a private one (ie. not MPEG-defined).

◆ tableIdExtension()

uint16_t ts::Section::tableIdExtension ( ) const
inline

Get the table id extension (long section only).

Returns
The table id extension.

◆ version()

uint8_t ts::Section::version ( ) const
inline

Get the section version number (long section only).

Returns
The section version number.

◆ isCurrent()

bool ts::Section::isCurrent ( ) const
inline

Check if the section is "current", not "next" (long section only).

Returns
True if the section is "current", false if it is "next".

◆ isNext()

bool ts::Section::isNext ( ) const
inline

Check if the section is "next", not "current" (long section only).

Returns
True if the section is "next", false if it is "current".

◆ sectionNumber()

uint8_t ts::Section::sectionNumber ( ) const
inline

Get the section number in the table (long section only).

Returns
The section number in the table.

◆ lastSectionNumber()

uint8_t ts::Section::lastSectionNumber ( ) const
inline

Get the number of the last section in the table (long section only).

Returns
The number of the last section in the table.

◆ etid()

ETID ts::Section::etid ( ) const
inline

Get the table id and id extension (long section only).

Returns
The table id and id extension as an ETID.

◆ sourcePID()

PID ts::Section::sourcePID ( ) const
inline

Get the source PID.

Returns
The source PID.

◆ content()

const uint8_t* ts::Section::content ( ) const
inline

Access to the full binary content of the section.

Do not modify content.

Returns
Address of the full binary content of the section. May be invalidated after modification in section.

◆ size()

size_t ts::Section::size ( ) const
inline

Size of the binary content of the section.

Returns
Size of the binary content of the section.

◆ headerSize()

size_t ts::Section::headerSize ( ) const
inline

Size of the section header.

Returns
Size of the section header.

◆ payload()

const uint8_t* ts::Section::payload ( ) const
inline

Access to the payload of the section.

For short sections, the payload starts after the private_section_length field. For long sections, the payload starts after the last_section_number field and ends before the CRC32 field. Do not modify payload content. May be invalidated after modification in section.

Returns
Address of the payload of the section.

◆ payloadSize()

size_t ts::Section::payloadSize ( ) const
inline

Get the size of the payload of the section.

For long sections, the payload ends before the CRC32 field.

Returns
Size in bytes of the payload of the section.

◆ packetCount()

PacketCounter ts::Section::packetCount ( ) const
inline

Minimum number of TS packets required to transport the section.

Returns
The minimum number of TS packets required to transport the section.

◆ setTableIdExtension()

void ts::Section::setTableIdExtension ( uint16_t  tid_ext,
bool  recompute_crc = true 
)

Set the table id extension (long section only).

Parameters
[in]tid_extThe table id extension.
[in]recompute_crcIf true, immediately recompute the CRC32 of the section.

◆ setVersion()

void ts::Section::setVersion ( uint8_t  version,
bool  recompute_crc = true 
)

Set the section version number (long section only).

Parameters
[in]versionThe section version number.
[in]recompute_crcIf true, immediately recompute the CRC32 of the section.

◆ setIsCurrent()

void ts::Section::setIsCurrent ( bool  is_current,
bool  recompute_crc = true 
)

Set the section current/next flag (long section only).

Parameters
[in]is_currentTrue if the table is "current", false if it is "next".
[in]recompute_crcIf true, immediately recompute the CRC32 of the section.

◆ setSectionNumber()

void ts::Section::setSectionNumber ( uint8_t  num,
bool  recompute_crc = true 
)

Set the section number (long section only).

Parameters
[in]numThe section number.
[in]recompute_crcIf true, immediately recompute the CRC32 of the section.

◆ setLastSectionNumber()

void ts::Section::setLastSectionNumber ( uint8_t  num,
bool  recompute_crc = true 
)

Set the number of the last section in the table (long section only).

Parameters
[in]numThe number of the last section in the table.
[in]recompute_crcIf true, immediately recompute the CRC32 of the section.

◆ setUInt8()

void ts::Section::setUInt8 ( size_t  offset,
uint8_t  value,
bool  recompute_crc = true 
)

Set one byte in the payload of the section.

Parameters
[in]offsetByte offset in the payload.
[in]valueThe value to set in the payload.
[in]recompute_crcIf true, immediately recompute the CRC32 of the section.

◆ setUInt16()

void ts::Section::setUInt16 ( size_t  offset,
uint16_t  value,
bool  recompute_crc = true 
)

Set a 16-bit integer in the payload of the section.

Parameters
[in]offsetByte offset in the payload.
[in]valueThe value to set in the payload.
[in]recompute_crcIf true, immediately recompute the CRC32 of the section.

◆ setSourcePID()

void ts::Section::setSourcePID ( PID  pid)
inline

Set the source PID.

Parameters
[in]pidThe source PID.

◆ getFirstTSPacketIndex()

PacketCounter ts::Section::getFirstTSPacketIndex ( ) const
inline

Index of first TS packet of the section in the demultiplexed stream.

Usually valid only if the section was extracted by a demux.

Returns
The first TS packet of the section in the demultiplexed stream.

◆ getLastTSPacketIndex()

PacketCounter ts::Section::getLastTSPacketIndex ( ) const
inline

Index of last TS packet of the section in the demultiplexed stream.

Usually valid only if the section was extracted by a demux.

Returns
The last TS packet of the section in the demultiplexed stream.

◆ setFirstTSPacketIndex()

void ts::Section::setFirstTSPacketIndex ( PacketCounter  i)
inline

Set the first TS packet of the section in the demultiplexed stream.

Parameters
[in]iThe first TS packet of the section in the demultiplexed stream.

◆ setLastTSPacketIndex()

void ts::Section::setLastTSPacketIndex ( PacketCounter  i)
inline

Set the last TS packet of the section in the demultiplexed stream.

Parameters
[in]iThe last TS packet of the section in the demultiplexed stream.

◆ hasDiversifiedPayload()

bool ts::Section::hasDiversifiedPayload ( ) const

Check if the section has a "diversified" payload.

A payload is "diversified" if its size is 2 bytes or more and if it contains at least 2 different byte values (not all 0x00 or not all 0xFF for instance).

Returns
True if the payload is diversified.

◆ read()

std::istream& ts::Section::read ( std::istream &  strm,
CRC32::Validation  crc_op = CRC32::IGNORE,
Report report = (*ts::CerrReport::Instance()) 
)

Read a section from standard streams (binary mode).

Parameters
[in,out]strmA standard stream in input mode. If a section is invalid (eof before end of section, wrong crc), the failbit of the stream is set.
[in]crc_opHow to process the CRC32 of the input packet.
[in,out]reportWhere to report errors.
Returns
A reference to the strm object.

◆ write()

std::ostream& ts::Section::write ( std::ostream &  strm,
Report report = (*ts::CerrReport::Instance()) 
) const

Write a section to standard streams (binary mode).

Parameters
[in,out]strmA standard stream in output mode.
[in,out]reportWhere to report errors.
Returns
A reference to the strm object.

◆ dump()

std::ostream& ts::Section::dump ( std::ostream &  strm,
int  indent = 0,
CASFamily  cas = CAS_OTHER,
bool  no_header = false 
) const

Hexa dump the section on an output stream without interpretation of the payload.

Parameters
[in,out]strmA standard stream in output mode (text mode).
[in]indentIndicates the base indentation of lines.
[in]casCAS family, for CAS-specific information.
[in]no_headerIf true, do not display the section header.
Returns
A reference to the strm object.

◆ SectionSize() [1/2]

static size_t ts::Section::SectionSize ( const void *  content,
size_t  content_size 
)
static

Static method to compute a section size.

Parameters
[in]contentAddress of the binary section data.
[in]content_sizeSize in bytes of the buffer containing the section and possibly trailing additional data.
Returns
The total size in bytes of the section starting at content or zero on error.

◆ SectionSize() [2/2]

static size_t ts::Section::SectionSize ( const ByteBlock content)
inlinestatic

Static method to compute a section size.

Parameters
[in]contentBuffer containing the section and possibly trailing additional data.
Returns
The total size in bytes of the section starting in content or zero on error.

◆ PacketCount()

template<class CONTAINER >
static PacketCounter ts::Section::PacketCount ( const CONTAINER &  container,
bool  pack = true 
)
static

Static method to compute the minimum number of TS packets required to transport a set of sections.

Template Parameters
CONTAINERA container class of SectionPtr as defined by the C++ Standard Template Library (STL).
Parameters
[in]containerA container class of SectionPtr.
[in]packIf true, assume that sections are packed in TS packets. When false, assume that each section starts at the beginning of a TS packet and stuffing in applied at the end of each section.
Returns
The minimum number of TS packets required to transport the sections in container.

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