TSDuck Version 3.16-1064 (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

void clearPriority ()
 Clear transport_priority - 1 bit.
 
void clearPUSI ()
 Clear payload_unit_start_indicator (PUSI) - 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...
 
void createPCR (const uint64_t &pcr)
 Create or replace the PCR value - 42 bits. 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...
 
const uint8_t * getPayload () const
 Get payload start address. More...
 
uint8_t * getPayload ()
 Get payload start address. More...
 
size_t getPayloadSize () const
 Compute payload size. More...
 
uint64_t getPCR () const
 Get the PCR - 42 bits. More...
 
PID getPID () const
 Extract PID - 13 bits. More...
 
bool getPriority () const
 Extract transport_priority - 1 bit. 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 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 isScrambled () const
 Check if the packet is scrambled. More...
 
bool operator!= (const TSPacket &p) const
 Unequality operator. More...
 
TSPacketoperator= (const TSPacket &p)
 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 setCC (uint8_t cc)
 Set continuity_counter (CC) - 4 bits. More...
 
void setDTS (const uint64_t &dts)
 Replace the DTS value - 33 bits. More...
 
void setOPCR (const uint64_t &opcr)
 Replace the OPCR value - 42 bits. More...
 
bool setPayloadSize (size_t size)
 Set the payload size. More...
 
void setPCR (const uint64_t &pcr)
 Replace the PCR value - 42 bits. More...
 
void setPID (PID pid)
 Set PID - 13 bits. More...
 
void setPriority ()
 Set transport_priority - 1 bit.
 
void setPTS (const uint64_t &pts)
 Replace the PTS value - 33 bits. More...
 
void setPUSI ()
 Set payload_unit_start_indicator (PUSI) - 1 bit.
 
void setScrambling (uint8_t sc)
 Set transport_scrambling_control - 2 bits. More...
 
void setTEI ()
 Set transport_error_indicator (TEI) - 1 bit.
 
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.

Member Function Documentation

◆ operator=()

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

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.

◆ getTEI()

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

Extract transport_error_indicator (TEI) - 1 bit.

Returns
The TEI value.

◆ getPriority()

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

Extract transport_priority - 1 bit.

Returns
The transport_priority value.

◆ 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
Size in bytes of the adaptation_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)

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.
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.

◆ 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.

◆ 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.

◆ hasPCR()

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

Check if packet has a Program Clock Reference (PCR)

Returns
True if packet has a PCR.

◆ hasOPCR()

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

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

Returns
True if packet has an OPCR.

◆ hasSpliceCountdown()

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

Check if packet has splicing point countdown.

Returns
True if packet has a splicing point countdown.

◆ getPCR()

uint64_t ts::TSPacket::getPCR ( ) const

Get the PCR - 42 bits.

Returns
The PCR or 0 if not found.

◆ getOPCR()

uint64_t ts::TSPacket::getOPCR ( ) const

Get the OPCR - 42 bits.

Returns
The OPCR or 0 if not found.

◆ 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.

◆ setPCR()

void ts::TSPacket::setPCR ( const uint64_t &  pcr)

Replace the PCR value - 42 bits.

Parameters
[in]pcrThe new PCR value.
Exceptions
AdaptationFieldErrorif no PCR is present.

◆ createPCR()

void ts::TSPacket::createPCR ( const uint64_t &  pcr)

Create or replace the PCR value - 42 bits.

If there is no PCR, the adaptation field is created or enlarged. In this case, the start of the packet payload is overwritten. This method should be used only when creating a packet from scratch, before filling the payload.

Parameters
[in]pcrThe new PCR value.

◆ setOPCR()

void ts::TSPacket::setOPCR ( const uint64_t &  opcr)

Replace the OPCR value - 42 bits.

Parameters
[in]opcrThe new OPCR value.
Exceptions
AdaptationFieldErrorif no OPCR is present.

◆ 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.

◆ 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 0 if not found.

◆ getDTS()

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

Get the DTS - 33 bits.

Returns
The DTS or 0 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.

◆ 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)
inline

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
inline

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 
)
inlinestatic

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 
)
inlinestatic

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 
)
inlinestatic

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: