TSDuck v3.46-4964
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TSPacket Class Referencefinal

#include <tsTSPacket.h>

Public Types

enum  {
  DUMP_RAW = 0x00010000 ,
  DUMP_TS_HEADER = 0x00020000 ,
  DUMP_PES_HEADER = 0x00040000 ,
  DUMP_PAYLOAD = 0x00080000 ,
  DUMP_AF = 0x00100000
}

Public Member Functions

void clearDiscontinuityIndicator ()
void clearESPI ()
void clearPriority ()
void clearPUSI ()
void clearRandomAccessIndicator ()
void clearTEI ()
void copyFrom (const void *source)
void copyTo (void *dest) const
std::ostream & display (std::ostream &strm, uint32_t flags=0, size_t indent=0, size_t size=PKT_SIZE) const
size_t getAFSize () const
size_t getAFStuffingSize () const
uint8_t getCC () const
bool getDiscontinuityIndicator () const
uint64_t getDTS () const
bool getESPI () const
size_t getHeaderSize () const
uint64_t getOPCR () const
uint8_t * getPayload ()
const uint8_t * getPayload () const
size_t getPayloadSize () const
uint64_t getPCR () const
size_t getPESHeaderSize () const
bool getPESHeaderStuffingArea (const uint8_t *&addr, size_t &pes_size, size_t &ts_size) const
bool getPESHeaderStuffingArea (uint8_t *&addr, size_t &pes_size, size_t &ts_size)
PID getPID () const
bool getPriority () const
uint8_t * getPrivateData ()
const uint8_t * getPrivateData () const
void getPrivateData (ByteBlock &data) const
size_t getPrivateDataSize () const
uint64_t getPTS () const
bool getPUSI () const
bool getRandomAccessIndicator () const
uint8_t getScrambling () const
int8_t getSpliceCountdown () const
bool getTEI () const
bool hasAF () const
bool hasDTS () const
bool hasOPCR () const
bool hasPayload () const
bool hasPCR () const
bool hasPrivateData () const
bool hasPTS () const
bool hasSpliceCountdown () const
bool hasValidSync () const
void init (PID pid=PID_NULL, uint8_t cc=0, uint8_t data=0xFF)
bool isClear () const
bool isDuplicate (const TSPacket &other) const
bool isScrambled () const
bool operator== (const TSPacket &p) const
std::istream & read (std::istream &strm, bool check_sync=true, Report &report=(ts::CerrReport::Instance()))
void removeOPCR ()
void removePCR ()
void removePrivateData ()
void removeSpliceCountdown ()
bool reserveStuffing (size_t size, bool shift_payload=false, bool enforce_af=false)
bool samePayload (const TSPacket &other) const
void setCC (uint8_t cc)
bool setDiscontinuityIndicator (bool shift_payload=false)
void setDTS (const uint64_t &dts)
bool setESPI (bool shift_payload=false)
bool setOPCR (const uint64_t &opcr, bool shift_payload=false)
bool setPayloadSize (size_t size, bool shift_payload=false, uint8_t pad=0xFF)
bool setPCR (const uint64_t &pcr, bool shift_payload=false)
void setPID (PID pid)
void setPriority ()
void setPriority (bool on)
bool setPrivateData (const ByteBlock &data, bool shift_payload=false)
bool setPrivateData (const void *data, size_t size, bool shift_payload=false)
void setPTS (const uint64_t &pts)
void setPUSI ()
void setPUSI (bool on)
bool setRandomAccessIndicator (bool shift_payload=false)
void setScrambling (uint8_t sc)
bool setSpliceCountdown (int8_t count, bool shift_payload=false)
void setTEI ()
void setTEI (bool on)
bool startPES () const
std::ostream & write (std::ostream &strm, Report &report=(ts::CerrReport::Instance())) const

Static Public Member Functions

static void Copy (TSPacket *dest, const TSPacket *source, size_t count=1)
static void Copy (TSPacket *dest, const uint8_t *source, size_t count=1, size_t packet_size=PKT_SIZE)
static void Copy (uint8_t *dest, const TSPacket *source, size_t count=1, size_t packet_size=PKT_SIZE)
static uint64_t GetPCR (const uint8_t *b)
static bool Locate (const uint8_t *buffer, size_t buffer_size, size_t &start_index, size_t &packet_count, size_t &packet_size)
static void PutPCR (uint8_t *b, const uint64_t &pcr)
static void SanityCheck ()

Public Attributes

uint8_t b [PKT_SIZE]

Static Public Attributes

static constexpr size_t PCR_BYTES = 6

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.

DUMP_AF 

Decode/format adaptation field.

Member Function Documentation

◆ operator==()

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

Equality operator.

Parameters
[in]pOther packet to compare.
Returns
True if this object is equal to 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.

◆ clearPUSI()

void ts::TSPacket::clearPUSI ( )
inline

Clear payload_unit_start_indicator (PUSI) - 1 bit

◆ setPUSI() [1/2]

void ts::TSPacket::setPUSI ( )
inline

Set payload_unit_start_indicator (PUSI) - 1 bit

◆ setPUSI() [2/2]

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.

◆ clearTEI()

void ts::TSPacket::clearTEI ( )
inline

Clear transport_error_indicator (TEI) - 1 bit

◆ setTEI() [1/2]

void ts::TSPacket::setTEI ( )
inline

Set transport_error_indicator (TEI) - 1 bit

◆ setTEI() [2/2]

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.

◆ clearPriority()

void ts::TSPacket::clearPriority ( )
inline

Clear transport_priority - 1 bit

◆ setPriority() [1/2]

void ts::TSPacket::setPriority ( )
inline

Set transport_priority - 1 bit

◆ setPriority() [2/2]

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.

◆ clearDiscontinuityIndicator()

void ts::TSPacket::clearDiscontinuityIndicator ( )
inline

Clear discontinuity_indicator - 1 bit

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

◆ clearRandomAccessIndicator()

void ts::TSPacket::clearRandomAccessIndicator ( )
inline

Clear random_access_indicator - 1 bit

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

◆ clearESPI()

void ts::TSPacket::clearESPI ( )
inline

Clear elementary_stream_priority_indicator (ESPI) - 1 bit

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

◆ GetPCR()

uint64_t ts::TSPacket::GetPCR ( const uint8_t * b)
static

This static method extracts a PCR from a stream.

Parameters
[in]bAddress of a 6-byte memory area containing a PCR binary value.
Returns
A 42-bit PCR value.

◆ PutPCR()

void ts::TSPacket::PutPCR ( uint8_t * b,
const uint64_t & pcr )
static

This routine inserts a PCR in a stream.

Parameters
[out]bAddress of a 6-byte memory area to write the PCR binary value.
[in]pcrA 42-bit PCR value.

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

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]

void ts::TSPacket::Copy ( TSPacket * dest,
const uint8_t * source,
size_t count = 1,
size_t packet_size = PKT_SIZE )
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.
[in]packet_sizeIndividual packet size in the source memory area.

◆ Copy() [3/3]

void ts::TSPacket::Copy ( uint8_t * dest,
const TSPacket * source,
size_t count = 1,
size_t packet_size = PKT_SIZE )
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.
[in]packet_sizeIndividual packet size in the destination memory area.

◆ Locate()

bool ts::TSPacket::Locate ( const uint8_t * buffer,
size_t buffer_size,
size_t & start_index,
size_t & packet_count,
size_t & packet_size )
static

Locate contiguous TS packets into a buffer.

This static method is typically used to locate useful packets in a UDP datagram. Basically, we expect the message to contain only TS packets. However, we also face the following situations:

  • Presence of a header preceeding the first TS packet (typically when the TS packets are encapsulated in RTP).
  • Presence of a truncated packet at the end of message.

To face the first situation, we look backward from the end of the message, looking for a 0x47 sync byte every 188 or 204 bytes, going backward.

If no TS packet is found using the first method, we restart from the beginning of the message, looking for a 0x47 sync byte every 188 or 204 bytes, going forward. If we find this pattern, followed by less than 188 or 204 bytes, then we have found a sequence of TS packets.

Parameters
[in]bufferAddress of a message buffer containing TS packets.
[in]buffer_sizeSize in bytes of the buffer.
[out]start_indexStart index in bytes of the first TS packet in the buffer.
[out]packet_countNumber of TS packets in the buffer.
[in,out]packet_sizeOn input, indicate the previous packet size from the same source. If different from PKT_SIZE (188) and PKT_RS_SIZE (204), assume an unknown packet size. On output, if packets were found, it is set to the packet size.
Returns
True if at least one packet was found, false if there is no packet in the buffer.

◆ SanityCheck()

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.

Member Data Documentation

◆ b

uint8_t ts::TSPacket::b[PKT_SIZE]

The public content is the 188-byte array representing the TS packet.

◆ PCR_BYTES

size_t ts::TSPacket::PCR_BYTES = 6
staticconstexpr

Size in bytes of a Program Clock Reference (PCR) as stored in a TS packet.


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