TSDuck Version 3.20-1548 (TSDuck - The MPEG Transport Stream Toolkit)
ts::TSPacket Struct Reference

Basic definition of an MPEG-2 transport packet. More...

Classes

class  AdaptationFieldError
 Internal error: access a non-existent adaptation field. More...
 

Public Types

enum  {
  DUMP_RAW = 0x00010000,
  DUMP_TS_HEADER = 0x00020000,
  DUMP_PES_HEADER = 0x00040000,
  DUMP_PAYLOAD = 0x00080000
}
 Options for packet display. More...
 

Public Member Functions

 TSPacket ()=default
 Default constructor.
 
 TSPacket (const TSPacket &p)=default
 Copy constructor. More...
 
void clearDiscontinuityIndicator ()
 Clear discontinuity_indicator - 1 bit.
 
void clearESPI ()
 Clear elementary_stream_priority_indicator (ESPI) - 1 bit.
 
void clearPriority ()
 Clear transport_priority - 1 bit.
 
void clearPUSI ()
 Clear payload_unit_start_indicator (PUSI) - 1 bit.
 
void clearRandomAccessIndicator ()
 Clear random_access_indicator - 1 bit.
 
void clearTEI ()
 Clear transport_error_indicator (TEI) - 1 bit.
 
void copyFrom (const void *source)
 Init packet from a memory area. More...
 
void copyTo (void *dest) const
 Copy packet content to a memory area. More...
 
std::ostream & display (std::ostream &strm, uint32_t flags=0, size_t indent=0, size_t size=PKT_SIZE) const
 This method displays the content of a transport packet. More...
 
size_t getAFSize () const
 Compute adaptation_field (AF) size. More...
 
size_t getAFStuffingSize () const
 Compute the size of the stuffing part in the adaptation_field. More...
 
uint8_t getCC () const
 Extract continuity_counter (CC) - 4 bits. More...
 
bool getDiscontinuityIndicator () const
 Check if packet has a discontinuity_indicator set - 1 bit. More...
 
uint64_t getDTS () const
 Get the DTS - 33 bits. More...
 
bool getESPI () const
 Check if packet has a elementary_stream_priority_indicator (ESPI) set - 1 bit. More...
 
size_t getHeaderSize () const
 Compute the size of the TS header. More...
 
uint64_t getOPCR () const
 Get the OPCR - 42 bits. More...
 
uint8_t * getPayload ()
 Get payload start address. More...
 
const uint8_t * getPayload () const
 Get payload start address. More...
 
size_t getPayloadSize () const
 Compute payload size. More...
 
uint64_t getPCR () const
 Get the PCR - 42 bits. More...
 
size_t getPESHeaderSize () const
 Get the size of the PES header in the packet, if one is present. More...
 
bool getPESHeaderStuffingArea (const uint8_t *&addr, size_t &pes_size, size_t &ts_size) const
 Get the address and size of the stuffing area of the PES header in the TS packet. More...
 
bool getPESHeaderStuffingArea (uint8_t *&addr, size_t &pes_size, size_t &ts_size)
 Get the address and size of the stuffing area of the PES header in the TS packet. More...
 
PID getPID () const
 Extract PID - 13 bits. More...
 
bool getPriority () const
 Extract transport_priority - 1 bit. More...
 
uint8_t * getPrivateData ()
 Get address of private data in adaptation field. More...
 
const uint8_t * getPrivateData () const
 Get address of private data in adaptation field. More...
 
void getPrivateData (ByteBlock &data) const
 Get private data from adaptation field. More...
 
size_t getPrivateDataSize () const
 Get size in bytes of private data from adaptation field. More...
 
uint64_t getPTS () const
 Get the PTS - 33 bits. More...
 
bool getPUSI () const
 Extract payload_unit_start_indicator (PUSI) - 1 bit. More...
 
bool getRandomAccessIndicator () const
 Check if packet has a random_access_indicator set - 1 bit. More...
 
uint8_t getScrambling () const
 Extract transport_scrambling_control - 2 bits. More...
 
int8_t getSpliceCountdown () const
 Get the splicing point countdown - 8 bits (signed). More...
 
bool getTEI () const
 Extract transport_error_indicator (TEI) - 1 bit. More...
 
bool hasAF () const
 Check if packet has an adaptation_field (AF) More...
 
bool hasDTS () const
 Check if the TS packet contains a Decoding Time Stamp (DTS). More...
 
bool hasOPCR () const
 Check if packet has an Original Program Clock Reference (OPCR) More...
 
bool hasPayload () const
 Check if packet has a payload. More...
 
bool hasPCR () const
 Check if packet has a Program Clock Reference (PCR) More...
 
bool hasPrivateData () const
 Check if packet has private data in adaptation field. More...
 
bool hasPTS () const
 Check if the TS packet contains a Presentation Time Stamp (PTS). More...
 
bool hasSpliceCountdown () const
 Check if packet has splicing point countdown. More...
 
bool hasValidSync () const
 Check if the sync byte is valid. More...
 
void init (PID pid=PID_NULL, uint8_t cc=0, uint8_t data=0xFF)
 Initialize a TS packet. More...
 
bool isClear () const
 Check if the packet is clear (ie not scrambled). More...
 
bool isDuplicate (const TSPacket &other) const
 Check if this packet is a duplicate as another one. More...
 
bool isScrambled () const
 Check if the packet is scrambled. More...
 
bool operator!= (const TSPacket &p) const
 Unequality operator. More...
 
TSPacketoperator= (const TSPacket &p) noexcept
 Assigment operator. More...
 
bool operator== (const TSPacket &p) const
 Equality operator. More...
 
std::istream & read (std::istream &strm, bool check_sync=true, Report &report=(*ts::CerrReport::Instance()))
 Read a packet from standard streams (binary mode). More...
 
void removeOPCR ()
 Remove the Original Program Clock Reference (OPCR) from the packet, if there is one. More...
 
void removePCR ()
 Remove the Program Clock Reference (PCR) from the packet, if there is one. More...
 
void removePrivateData ()
 Remove the private data from the adaptation field, if there is one. More...
 
void removeSpliceCountdown ()
 Remove the splicing point countdown from the packet, if there is one. More...
 
bool reserveStuffing (size_t size, bool shift_payload=false, bool enforce_af=false)
 Reserve some given space in the stuffing part of the adaptation field. More...
 
bool samePayload (const TSPacket &other) const
 Check if this packet has the same payload as another one. More...
 
void setCC (uint8_t cc)
 Set continuity_counter (CC) - 4 bits. More...
 
bool setDiscontinuityIndicator (bool shift_payload=false)
 Set discontinuity_indicator - 1 bit. More...
 
void setDTS (const uint64_t &dts)
 Replace the DTS value - 33 bits. More...
 
bool setESPI (bool shift_payload=false)
 Set elementary_stream_priority_indicator (ESPI) - 1 bit. More...
 
bool setOPCR (const uint64_t &opcr, bool shift_payload=false)
 Create or replace the OPCR value - 42 bits. More...
 
bool setPayloadSize (size_t size, bool shift_payload=false, uint8_t pad=0xFF)
 Set the payload size. More...
 
bool setPCR (const uint64_t &pcr, bool shift_payload=false)
 Create or replace the PCR value - 42 bits. More...
 
void setPID (PID pid)
 Set PID - 13 bits. More...
 
void setPriority ()
 Set transport_priority - 1 bit.
 
void setPriority (bool on)
 Set transport_priority - 1 bit. More...
 
bool setPrivateData (const ByteBlock &data, bool shift_payload=false)
 Set private data in adaptation field. More...
 
bool setPrivateData (const void *data, size_t size, bool shift_payload=false)
 Set private data in adaptation field. More...
 
void setPTS (const uint64_t &pts)
 Replace the PTS value - 33 bits. More...
 
void setPUSI ()
 Set payload_unit_start_indicator (PUSI) - 1 bit.
 
void setPUSI (bool on)
 Set payload_unit_start_indicator (PUSI) - 1 bit. More...
 
bool setRandomAccessIndicator (bool shift_payload=false)
 Set random_access_indicator - 1 bit. More...
 
void setScrambling (uint8_t sc)
 Set transport_scrambling_control - 2 bits. More...
 
bool setSpliceCountdown (int8_t count, bool shift_payload=false)
 Create or replace the splicing point countdown - 8 bits. More...
 
void setTEI ()
 Set transport_error_indicator (TEI) - 1 bit.
 
void setTEI (bool on)
 Set transport_error_indicator (TEI) - 1 bit. More...
 
bool startPES () const
 Check if the packet contains the start of a clear PES header. More...
 
std::ostream & write (std::ostream &strm, Report &report=(*ts::CerrReport::Instance())) const
 Write a packet to standard streams (binary mode). More...
 

Static Public Member Functions

static void Copy (TSPacket *dest, const TSPacket *source, size_t count=1)
 Copy contiguous TS packets. More...
 
static void Copy (TSPacket *dest, const uint8_t *source, size_t count=1)
 Copy contiguous TS packets from raw memory. More...
 
static void Copy (uint8_t *dest, const TSPacket *source, size_t count=1)
 Copy contiguous TS packets into raw memory. More...
 
static void SanityCheck ()
 Sanity check routine. More...
 

Public Attributes

uint8_t b [PKT_SIZE]
 The public content is the 188-byte array representing the TS packet.
 

Detailed Description

Basic definition of an MPEG-2 transport packet.

Physically, an object of this class is exactly implemented as a 188-byte TS packets. It is safe to consider that arrays or vectors of this class have the physical layout of a transport stream.

For performance reason, there is no constructor. Uninitialized packets have undefined binary content.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Options for packet display.

Enumerator
DUMP_RAW 

Complete packet in hexadecimal (default)

DUMP_TS_HEADER 

Decode/format TS header.

DUMP_PES_HEADER 

Decode/format PES header.

DUMP_PAYLOAD 

Payload in hexadecimal.

Constructor & Destructor Documentation

◆ TSPacket()

ts::TSPacket::TSPacket ( const TSPacket p)
default

Copy constructor.

Parameters
[in]pOther packet to copy.

Member Function Documentation

◆ operator=()

TSPacket& ts::TSPacket::operator= ( const TSPacket p)
noexcept

Assigment operator.

Parameters
[in]pOther packet to copy.
Returns
A reference to this object.

◆ operator==()

bool ts::TSPacket::operator== ( const TSPacket p) const
inline

Equality operator.

Parameters
[in]pOther packet to compare.
Returns
True is this object is equal to p.

◆ operator!=()

bool ts::TSPacket::operator!= ( const TSPacket p) const
inline

Unequality operator.

Parameters
[in]pOther packet to compare.
Returns
True is this object is different from p.

◆ init()

void ts::TSPacket::init ( PID  pid = PID_NULL,
uint8_t  cc = 0,
uint8_t  data = 0xFF 
)

Initialize a TS packet.

This method should be used when initializing with NullPacket or EmptyPacket is not appropriate. The packet payload is 184 bytes long and filled with the data byte.

Parameters
[in]pidPID value.
[in]ccContinuity counter.
[in]dataByte value to fill the payload with.

◆ hasValidSync()

bool ts::TSPacket::hasValidSync ( ) const
inline

Check if the sync byte is valid.

Returns
True if the sync byte of the packet is valid.

◆ getPID()

PID ts::TSPacket::getPID ( ) const
inline

Extract PID - 13 bits.

Returns
The PID value.

◆ setPID()

void ts::TSPacket::setPID ( PID  pid)
inline

Set PID - 13 bits.

Parameters
[in]pidThe new PID.

◆ getPUSI()

bool ts::TSPacket::getPUSI ( ) const
inline

Extract payload_unit_start_indicator (PUSI) - 1 bit.

Returns
The PUSI value.

◆ setPUSI()

void ts::TSPacket::setPUSI ( bool  on)
inline

Set payload_unit_start_indicator (PUSI) - 1 bit.

Parameters
[in]onThe value to set.

◆ getTEI()

bool ts::TSPacket::getTEI ( ) const
inline

Extract transport_error_indicator (TEI) - 1 bit.

Returns
The TEI value.

◆ setTEI()

void ts::TSPacket::setTEI ( bool  on)
inline

Set transport_error_indicator (TEI) - 1 bit.

Parameters
[in]onThe value to set.

◆ getPriority()

bool ts::TSPacket::getPriority ( ) const
inline

Extract transport_priority - 1 bit.

Returns
The transport_priority value.

◆ setPriority()

void ts::TSPacket::setPriority ( bool  on)
inline

Set transport_priority - 1 bit.

Parameters
[in]onThe value to set.

◆ getScrambling()

uint8_t ts::TSPacket::getScrambling ( ) const
inline

Extract transport_scrambling_control - 2 bits.

Returns
The transport_scrambling_control value.

◆ isClear()

bool ts::TSPacket::isClear ( ) const
inline

Check if the packet is clear (ie not scrambled).

Returns
True if the packet is clear.

◆ isScrambled()

bool ts::TSPacket::isScrambled ( ) const
inline

Check if the packet is scrambled.

Returns
True if the packet is scrambled.

◆ setScrambling()

void ts::TSPacket::setScrambling ( uint8_t  sc)
inline

Set transport_scrambling_control - 2 bits.

Parameters
[in]scNew transport_scrambling_control value.

◆ getCC()

uint8_t ts::TSPacket::getCC ( ) const
inline

Extract continuity_counter (CC) - 4 bits.

Returns
The CC value.

◆ setCC()

void ts::TSPacket::setCC ( uint8_t  cc)
inline

Set continuity_counter (CC) - 4 bits.

Parameters
[in]ccNew continuity_counter value.

◆ hasAF()

bool ts::TSPacket::hasAF ( ) const
inline

Check if packet has an adaptation_field (AF)

Returns
True if the packet has an adaptation_field.

◆ getAFSize()

size_t ts::TSPacket::getAFSize ( ) const
inline

Compute adaptation_field (AF) size.

Returns
Total size in bytes of the adaptation_field, including the length field.

◆ getAFStuffingSize()

size_t ts::TSPacket::getAFStuffingSize ( ) const

Compute the size of the stuffing part in the adaptation_field.

Returns
Size in bytes of the stuffing part in the adaptation_field.

◆ getHeaderSize()

size_t ts::TSPacket::getHeaderSize ( ) const
inline

Compute the size of the TS header.

Returns
Size in bytes of the TS header. This is also the index of the TS payload.

◆ hasPayload()

bool ts::TSPacket::hasPayload ( ) const
inline

Check if packet has a payload.

Returns
True if the packet has a payload.

◆ getPayload() [1/2]

const uint8_t* ts::TSPacket::getPayload ( ) const
inline

Get payload start address.

Returns
The payload start address.

◆ getPayload() [2/2]

uint8_t* ts::TSPacket::getPayload ( )
inline

Get payload start address.

Returns
The payload start address.

◆ getPayloadSize()

size_t ts::TSPacket::getPayloadSize ( ) const
inline

Compute payload size.

Returns
The payload size in bytes.

◆ setPayloadSize()

bool ts::TSPacket::setPayloadSize ( size_t  size,
bool  shift_payload = false,
uint8_t  pad = 0xFF 
)

Set the payload size.

If the payload shall be shrunk, the adaptation field is enlarged with stuffing. If the payload shall be enlarged, reduce the amount of stuffing in the adaptation field. This method should be used only when creating a packet from scratch, before filling the payload.

Parameters
[in]sizeThe requested payload size.
[in]shift_payloadIf true, the payload is shifted so that the start of its content remains the same. When the payload is shrunk, its end is truncated. When the paylaod is enlarged, it is padded with pad values. When shift_payload is false, the data in the memory area of the payload is not modified. In that case, the memory is silently overwritten, losing the payload content.
[in]padByte value to use when padding the adaptation field or payload.
Returns
True on success, false when the requested size is too large.

◆ getDiscontinuityIndicator()

bool ts::TSPacket::getDiscontinuityIndicator ( ) const
inline

Check if packet has a discontinuity_indicator set - 1 bit.

Returns
True if packet has a discontinuity_indicator set.

◆ setDiscontinuityIndicator()

bool ts::TSPacket::setDiscontinuityIndicator ( bool  shift_payload = false)
inline

Set discontinuity_indicator - 1 bit.

Parameters
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be created.
Returns
True if the flag was correctly set. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ getRandomAccessIndicator()

bool ts::TSPacket::getRandomAccessIndicator ( ) const
inline

Check if packet has a random_access_indicator set - 1 bit.

Returns
True if packet has a random_access_indicator set.

◆ setRandomAccessIndicator()

bool ts::TSPacket::setRandomAccessIndicator ( bool  shift_payload = false)
inline

Set random_access_indicator - 1 bit.

Parameters
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be created.
Returns
True if the flag was correctly set. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ getESPI()

bool ts::TSPacket::getESPI ( ) const
inline

Check if packet has a elementary_stream_priority_indicator (ESPI) set - 1 bit.

Returns
True if packet has an ESPI set.

◆ setESPI()

bool ts::TSPacket::setESPI ( bool  shift_payload = false)
inline

Set elementary_stream_priority_indicator (ESPI) - 1 bit.

Parameters
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be created.
Returns
True if the flag was correctly set. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ hasPCR()

bool ts::TSPacket::hasPCR ( ) const
inline

Check if packet has a Program Clock Reference (PCR)

Returns
True if packet has a PCR.

◆ getPCR()

uint64_t ts::TSPacket::getPCR ( ) const

Get the PCR - 42 bits.

Returns
The PCR or INVALID_PCR if not found.

◆ setPCR()

bool ts::TSPacket::setPCR ( const uint64_t &  pcr,
bool  shift_payload = false 
)

Create or replace the PCR value - 42 bits.

Parameters
[in]pcrThe new PCR value.
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be enlarged.
Returns
True if the PCR was correctly created. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ removePCR()

void ts::TSPacket::removePCR ( )
inline

Remove the Program Clock Reference (PCR) from the packet, if there is one.

The adaptation field size is unchanged, its stuffing part is enlarged.

◆ hasOPCR()

bool ts::TSPacket::hasOPCR ( ) const
inline

Check if packet has an Original Program Clock Reference (OPCR)

Returns
True if packet has an OPCR.

◆ getOPCR()

uint64_t ts::TSPacket::getOPCR ( ) const

Get the OPCR - 42 bits.

Returns
The OPCR or INVALID_PCR if not found.

◆ setOPCR()

bool ts::TSPacket::setOPCR ( const uint64_t &  opcr,
bool  shift_payload = false 
)

Create or replace the OPCR value - 42 bits.

Parameters
[in]opcrThe new OPCR value.
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be enlarged.
Returns
True if the OPCR was correctly created. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ removeOPCR()

void ts::TSPacket::removeOPCR ( )
inline

Remove the Original Program Clock Reference (OPCR) from the packet, if there is one.

The adaptation field size is unchanged, its stuffing part is enlarged.

◆ hasSpliceCountdown()

bool ts::TSPacket::hasSpliceCountdown ( ) const
inline

Check if packet has splicing point countdown.

Returns
True if packet has a splicing point countdown.

◆ getSpliceCountdown()

int8_t ts::TSPacket::getSpliceCountdown ( ) const

Get the splicing point countdown - 8 bits (signed).

Returns
The splicing point countdown or 0 if not found.

◆ setSpliceCountdown()

bool ts::TSPacket::setSpliceCountdown ( int8_t  count,
bool  shift_payload = false 
)

Create or replace the splicing point countdown - 8 bits.

Parameters
[in]countThe new splicing point countdown value.
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be enlarged.
Returns
True if the splicing point countdown was correctly created. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ removeSpliceCountdown()

void ts::TSPacket::removeSpliceCountdown ( )
inline

Remove the splicing point countdown from the packet, if there is one.

The adaptation field size is unchanged, its stuffing part is enlarged.

◆ hasPrivateData()

bool ts::TSPacket::hasPrivateData ( ) const
inline

Check if packet has private data in adaptation field.

Returns
True if packet has private data in adaptation field.

◆ getPrivateDataSize()

size_t ts::TSPacket::getPrivateDataSize ( ) const

Get size in bytes of private data from adaptation field.

Returns
Size in bytes of private data (not including its length field).

◆ getPrivateData() [1/3]

const uint8_t* ts::TSPacket::getPrivateData ( ) const

Get address of private data in adaptation field.

Returns
Address of private data in adaptation field or a null pointer if there is no private data.

◆ getPrivateData() [2/3]

uint8_t* ts::TSPacket::getPrivateData ( )

Get address of private data in adaptation field.

Returns
Address of private data in adaptation field or a null pointer if there is no private data.

◆ getPrivateData() [3/3]

void ts::TSPacket::getPrivateData ( ByteBlock data) const

Get private data from adaptation field.

Parameters
[out]dataPrivate data from adaptation field.

◆ setPrivateData() [1/2]

bool ts::TSPacket::setPrivateData ( const void *  data,
size_t  size,
bool  shift_payload = false 
)

Set private data in adaptation field.

Parameters
[in]dataAddress of private data to set in the packet.
[in]sizeSize in bytes of private data to set in the packet.
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be created or enlarged.
Returns
True if the flag was correctly set. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ setPrivateData() [2/2]

bool ts::TSPacket::setPrivateData ( const ByteBlock data,
bool  shift_payload = false 
)

Set private data in adaptation field.

Parameters
[in]dataPrivate data to set in the packet.
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be created or enlarged.
Returns
True if the flag was correctly set. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ removePrivateData()

void ts::TSPacket::removePrivateData ( )

Remove the private data from the adaptation field, if there is one.

The adaptation field size is unchanged, its stuffing part is enlarged.

◆ reserveStuffing()

bool ts::TSPacket::reserveStuffing ( size_t  size,
bool  shift_payload = false,
bool  enforce_af = false 
)

Reserve some given space in the stuffing part of the adaptation field.

Parameters
[in]sizeThe expected stuffing size in bytes, in the adaptation field. If the AF stuffing is already that size or larger, do nothing. Otherwise, attempt to increase the AF size by shifting and truncating the payload.
[in]shift_payloadIf true, the payload can be shifted and truncated when the adaptation field needs to be enlarged.
[in]enforce_afWhen true, try to create the AF anyway, even if size is zero, making sure that the flags field of the AF is present.
Returns
True if the expected stuffing size is available. False when the adaptation needed to be enlarged but could not because shift_payload was false.

◆ startPES()

bool ts::TSPacket::startPES ( ) const

Check if the packet contains the start of a clear PES header.

Returns
True if the packet contains the start of a clear PES header.

◆ getPESHeaderSize()

size_t ts::TSPacket::getPESHeaderSize ( ) const

Get the size of the PES header in the packet, if one is present.

Returns
The size of the PES header in bytes or zero if there is no PES header. It is not guaranteed that the complete PES header fits inside the TS packet.

◆ getPESHeaderStuffingArea() [1/2]

bool ts::TSPacket::getPESHeaderStuffingArea ( const uint8_t *&  addr,
size_t &  pes_size,
size_t &  ts_size 
) const

Get the address and size of the stuffing area of the PES header in the TS packet.

Parameters
[out]addrAddress of the PES header stuffing area. This address points inside the TS packet payload.
[out]pes_sizeSize in bytes of the PES header stuffing area. This is the complete size, some of which can be outside the TS packet.
[out]ts_sizeSize in bytes of the PES header stuffing area which is in the TS packet. This size can be lower than the returned pes_size if the stuffing area continues in another TS packet.
Returns
True when the PES header stuffing area was found. False otherwise.

◆ getPESHeaderStuffingArea() [2/2]

bool ts::TSPacket::getPESHeaderStuffingArea ( uint8_t *&  addr,
size_t &  pes_size,
size_t &  ts_size 
)

Get the address and size of the stuffing area of the PES header in the TS packet.

Parameters
[out]addrAddress of the PES header stuffing area. This address points inside the TS packet payload.
[out]pes_sizeSize in bytes of the PES header stuffing area. This is the complete size, some of which can be outside the TS packet.
[out]ts_sizeSize in bytes of the PES header stuffing area which is in the TS packet. This size can be lower than the returned pes_size if the stuffing area continues in another TS packet.
Returns
True when the PES header stuffing area was found. False otherwise.

◆ hasPTS()

bool ts::TSPacket::hasPTS ( ) const
inline

Check if the TS packet contains a Presentation Time Stamp (PTS).

Technically, the PTS and DTS are part of the PES packet, not the TS packet. If the TS packet is the first TS packet of a PES packet, it is possible that the PTS and/or DTS are present in the PES packet but outside the first TS packet. This is possible but rare. So, we provide here a fast way of getting PTS and/or DTS from the TS packet if available.

Returns
True if the packet contains a PTS.

◆ hasDTS()

bool ts::TSPacket::hasDTS ( ) const
inline

Check if the TS packet contains a Decoding Time Stamp (DTS).

Returns
True if the packet contains a DTS.
See also
hasPTS()

◆ getPTS()

uint64_t ts::TSPacket::getPTS ( ) const
inline

Get the PTS - 33 bits.

Returns
The PTS or INVALID_PTS if not found.

◆ getDTS()

uint64_t ts::TSPacket::getDTS ( ) const
inline

Get the DTS - 33 bits.

Returns
The DTS or INVALID_DTS if not found.

◆ setPTS()

void ts::TSPacket::setPTS ( const uint64_t &  pts)
inline

Replace the PTS value - 33 bits.

Parameters
[in]ptsThe new PTS value.

◆ setDTS()

void ts::TSPacket::setDTS ( const uint64_t &  dts)
inline

Replace the DTS value - 33 bits.

Parameters
[in]dtsThe new DTS value.

◆ samePayload()

bool ts::TSPacket::samePayload ( const TSPacket other) const

Check if this packet has the same payload as another one.

Parameters
[in]otherThe other packet to compare.
Returns
True if the two packets have a payload and these payloads are identical.

◆ isDuplicate()

bool ts::TSPacket::isDuplicate ( const TSPacket other) const

Check if this packet is a duplicate as another one.

A valid "true" pair of duplicate packets is made of two consecutive packets with same continuity counter and same payload. It must also have the same adaptation field, with the exception of the PCR which can (should?) be different.

Parameters
[in]otherThe other packet to compare.
Returns
True if the two packets have same PID, same CC and same payload.

◆ read()

std::istream& ts::TSPacket::read ( std::istream &  strm,
bool  check_sync = true,
Report report = (*ts::CerrReport::Instance()) 
)

Read a packet from standard streams (binary mode).

Parameters
[in,out]strmA standard stream in input mode.
[in]check_syncIf true, the sync byte of the input packet is checked. If it is not valid, set the failbit of the stream.
[in,out]reportWhere to report errors.
Returns
A reference to the strm object.

◆ write()

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

Write a packet 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.

◆ display()

std::ostream& ts::TSPacket::display ( std::ostream &  strm,
uint32_t  flags = 0,
size_t  indent = 0,
size_t  size = PKT_SIZE 
) const

This method displays the content of a transport packet.

Parameters
[in,out]strmA standard stream in output mode (text mode).
[in]flagsIndicate which part must be dumped. If DUMP_RAW or DUMP_PAYLOAD is specified, flags from ts::UString::HexaFlags may also be used.
[in]indentIndicates the base indentation of lines.
[in]sizeMaximum size to display in the packet.
Returns
A reference to the strm object.

◆ copyFrom()

void ts::TSPacket::copyFrom ( const void *  source)

Init packet from a memory area.

Parameters
[in]sourceAddress of the memory area to read. Must contain at least PKT_SIZE bytes.

◆ copyTo()

void ts::TSPacket::copyTo ( void *  dest) const

Copy packet content to a memory area.

Parameters
[out]destAddress of the memory area to write. Must contain at least PKT_SIZE bytes.

◆ Copy() [1/3]

static void ts::TSPacket::Copy ( TSPacket dest,
const TSPacket source,
size_t  count = 1 
)
static

Copy contiguous TS packets.

Parameters
[out]destAddress of the first contiguous TS packet to write.
[in]sourceAddress of the first contiguous TS packet to read.
[in]countNumber of TS packets to copy.

◆ Copy() [2/3]

static void ts::TSPacket::Copy ( TSPacket dest,
const uint8_t *  source,
size_t  count = 1 
)
static

Copy contiguous TS packets from raw memory.

Parameters
[out]destAddress of the first contiguous TS packet to write.
[in]sourceAddress of the memory area to read.
[in]countNumber of TS packets to copy.

◆ Copy() [3/3]

static void ts::TSPacket::Copy ( uint8_t *  dest,
const TSPacket source,
size_t  count = 1 
)
static

Copy contiguous TS packets into raw memory.

Parameters
[out]destAddress of the memory area to write.
[in]sourceAddress of the first contiguous TS packet to read.
[in]countNumber of TS packets to copy.

◆ SanityCheck()

static void ts::TSPacket::SanityCheck ( )
static

Sanity check routine.

Ensure that the TSPacket structure can be used in contiguous memory array and array of packets. Can be used once at startup time in paranoid applications. Abort application on error.


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