TSDuck Version 3.32-2780 (TSDuck - The MPEG Transport Stream Toolkit)
ts::PESPacket Class Reference

Representation of MPEG PES packets. More...

Inheritance diagram for ts::PESPacket:
Collaboration diagram for ts::PESPacket:

Public Types

typedef DemuxedData SuperClass
 Explicit identification of super class.
 

Public Member Functions

 PESPacket (const ByteBlock &content, PID source_pid=PID_NULL)
 Constructor from full binary content. More...
 
 PESPacket (const ByteBlockPtr &content_ptr, PID source_pid=PID_NULL)
 Constructor from full binary content. More...
 
 PESPacket (const PESPacket &other, ShareMode mode)
 Copy constructor. More...
 
 PESPacket (const void *content, size_t content_size, PID source_pid=PID_NULL)
 Constructor from full binary content. More...
 
 PESPacket (PESPacket &&other) noexcept
 Move constructor. More...
 
 PESPacket (PID source_pid=PID_NULL)
 Default constructor. More...
 
virtual void clear () override
 Clear data content.
 
virtual const uint8_t * content () const
 Access to the full binary content of the data. More...
 
DemuxedDatacopy (const DemuxedData &other)
 Duplication. More...
 
PESPacketcopy (const PESPacket &other)
 Duplication. More...
 
size_t findIntraImage () const
 Check if the PES packet contains an intra-coded image. More...
 
PacketCounter firstTSPacketIndex () const
 Index of first TS packet of the data in the demultiplexed stream. More...
 
CodecType getCodec () const
 Get the codec type, as specified by the user (optional). More...
 
uint64_t getPCR () const
 Get the optional PCR value which was associated to the PES packets. More...
 
uint8_t getStreamId () const
 Stream id of the PES packet. More...
 
uint8_t getStreamType () const
 Get the stream type, as specified in the PMT (optional). More...
 
bool hasLongHeader () const
 Check if the packet has a long header. More...
 
const uint8_t * header () const
 Access to the PES header of the packet. More...
 
size_t headerSize () const
 Size of the PES header of the packet. More...
 
bool isAC3 () const
 Check if the PES packet contains AC-3 or Enhanced-AC-3 audio. More...
 
bool isAVC () const
 Check if the PES packet contains AVC / H.264 video. More...
 
bool isHEVC () const
 Check if the PES packet contains HEVC / H.265 video. More...
 
bool isMPEG2Video () const
 Check if the PES packet contains MPEG-2 video. More...
 
bool isValid () const
 Check if the packet has valid content. More...
 
bool isVVC () const
 Check if the PES packet contains VVC / H.266 video. More...
 
PacketCounter lastTSPacketIndex () const
 Index of last TS packet of the data in the demultiplexed stream. More...
 
bool matchContent (const ByteBlock &pattern, const ByteBlock &mask=ByteBlock()) const
 Check if the start of the data matches a given pattern. More...
 
bool operator!= (const DemuxedData &other) const
 Unequality operator. More...
 
bool operator!= (const PESPacket &other) const
 Unequality operator. More...
 
PESPacketoperator= (const PESPacket &other)
 Assignment operator. More...
 
PESPacketoperator= (PESPacket &&other) noexcept
 Move assignment operator. More...
 
bool operator== (const DemuxedData &other) const
 Equality operator. More...
 
bool operator== (const PESPacket &other) const
 Equality operator. More...
 
const uint8_t * payload () const
 Access to the payload of the packet. More...
 
size_t payloadSize () const
 Size of the payload of the packet. More...
 
virtual void reload (const ByteBlock &content, PID source_pid=PID_NULL) override
 Reload from full binary content. More...
 
virtual void reload (const ByteBlockPtr &content_ptr, PID source_pid=PID_NULL) override
 Reload from full binary content. More...
 
virtual void reload (const void *content, size_t content_size, PID source_pid=PID_NULL) override
 Reload from full binary content. More...
 
void setCodec (CodecType codec)
 Set the codec type (informational only). More...
 
void setDefaultCodec (CodecType default_codec)
 Set a default codec type. More...
 
void setFirstTSPacketIndex (PacketCounter i)
 Set the first TS packet of the data in the demultiplexed stream. More...
 
void setLastTSPacketIndex (PacketCounter i)
 Set the last TS packet of the data in the demultiplexed stream. More...
 
void setPCR (uint64_t pcr)
 Set the PCR value for this PES packet. More...
 
void setSourcePID (PID pid)
 Set the source PID. More...
 
void setStreamId (uint8_t sid)
 Set the stream id of the PES packet. More...
 
void setStreamType (uint8_t type)
 Set the stream type, as specified in the PMT. More...
 
virtual size_t size () const override
 Size of the binary content of the data. More...
 
PID sourcePID () const
 Get the source PID. More...
 
size_t spuriousDataSize () const
 Number of spurious data bytes after the packet. More...
 

Static Public Member Functions

static size_t FindIntraImage (const uint8_t *data, size_t size, uint8_t stream_type=ST_NULL, CodecType default_format=CodecType::UNDEFINED)
 Check if a truncated PES packet may contain the start of an intra-coded image. More...
 
static bool HasCommonVideoHeader (const uint8_t *data, size_t size)
 Check if a truncated PES packet starts with 00 00 00 [00...] 01, common header for AVC, HEVC and VVC. More...
 
static bool IsAC3 (const uint8_t *data, size_t size, uint8_t stream_type=ST_NULL)
 Check if a truncated PES packet may contain AC-3 or Enhanced-AC-3 audio. More...
 
static bool IsAVC (const uint8_t *data, size_t size, uint8_t stream_type=ST_NULL)
 Check if a truncated PES packet may contain AVC / H.264 video. More...
 
static bool IsHEVC (const uint8_t *data, size_t size, uint8_t stream_type=ST_NULL)
 Check if a truncated PES packet may contain HEVC / H.265 video. More...
 
static bool IsMPEG2Video (const uint8_t *data, size_t size, uint8_t stream_type=ST_NULL)
 Check if a truncated PES packet may contain MPEG-2 or MPEG-1 video. More...
 
static bool IsVVC (const uint8_t *data, size_t size, uint8_t stream_type=ST_NULL)
 Check if a truncated PES packet may contain VVC / H.266 video. More...
 

Protected Member Functions

void rwAppend (const void *data, size_t dsize)
 Append raw data to the full binary content of the data for subclasses. More...
 
uint8_t * rwContent ()
 Read/write access to the full binary content of the data for subclasses. More...
 
void rwResize (size_t s)
 Resize the full binary content of the data for subclasses. More...
 

Detailed Description

Representation of MPEG PES packets.

Constructor & Destructor Documentation

◆ PESPacket() [1/6]

ts::PESPacket::PESPacket ( PID  source_pid = PID_NULL)

Default constructor.

The PESPacket is initially marked invalid.

Parameters
[in]source_pidPID from which the packet was read.

◆ PESPacket() [2/6]

ts::PESPacket::PESPacket ( const PESPacket other,
ShareMode  mode 
)

Copy constructor.

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

◆ PESPacket() [3/6]

ts::PESPacket::PESPacket ( PESPacket &&  other)
noexcept

Move constructor.

Parameters
[in,out]otherAnother instance to move.

◆ PESPacket() [4/6]

ts::PESPacket::PESPacket ( const void *  content,
size_t  content_size,
PID  source_pid = PID_NULL 
)

Constructor from full binary content.

The content is copied into the packet if valid.

Parameters
[in]contentAddress of the binary packet data.
[in]content_sizeSize in bytes of the packet.
[in]source_pidPID from which the packet was read.

◆ PESPacket() [5/6]

ts::PESPacket::PESPacket ( const ByteBlock content,
PID  source_pid = PID_NULL 
)

Constructor from full binary content.

The content is copied into the packet if valid.

Parameters
[in]contentBinary packet data.
[in]source_pidPID from which the packet was read.

◆ PESPacket() [6/6]

ts::PESPacket::PESPacket ( const ByteBlockPtr content_ptr,
PID  source_pid = PID_NULL 
)

Constructor from full binary content.

The content is copied into the packet if valid.

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

Member Function Documentation

◆ reload() [1/3]

virtual void ts::PESPacket::reload ( const void *  content,
size_t  content_size,
PID  source_pid = PID_NULL 
)
overridevirtual

Reload from full binary content.

Parameters
[in]contentAddress of the binary packet data.
[in]content_sizeSize in bytes of the packet.
[in]source_pidPID from which the data were read.

Reimplemented from ts::DemuxedData.

◆ reload() [2/3]

virtual void ts::PESPacket::reload ( const ByteBlock content,
PID  source_pid = PID_NULL 
)
overridevirtual

Reload from full binary content.

Parameters
[in]contentBinary packet data.
[in]source_pidPID from which the data were read.

Reimplemented from ts::DemuxedData.

◆ reload() [3/3]

virtual void ts::PESPacket::reload ( const ByteBlockPtr content_ptr,
PID  source_pid = PID_NULL 
)
overridevirtual

Reload from full binary content.

Parameters
[in]content_ptrSafe pointer to the binary packet data. The content is referenced, and thus shared. Do not modify the referenced ByteBlock from outside the DemuxedData.
[in]source_pidPID from which the data were read.

Reimplemented from ts::DemuxedData.

◆ size()

virtual size_t ts::PESPacket::size ( ) const
overridevirtual

Size of the binary content of the data.

Returns
Size of the binary content of the data.

Reimplemented from ts::DemuxedData.

◆ operator=() [1/2]

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

Assignment operator.

The packets are referenced, and thus shared between the two packet objects.

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

◆ operator=() [2/2]

PESPacket& ts::PESPacket::operator= ( PESPacket &&  other)
noexcept

Move assignment operator.

Parameters
[in,out]otherOther packet to assign to this object.
Returns
A reference to this object.

◆ copy() [1/2]

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

Duplication.

Similar to assignment but the packets are duplicated.

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

◆ isValid()

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

Check if the packet has valid content.

Returns
True if the packet has valid content.

◆ operator==() [1/2]

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

Equality operator.

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

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

◆ operator!=() [1/2]

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

Unequality operator.

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

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

◆ getPCR()

uint64_t ts::PESPacket::getPCR ( ) const
inline

Get the optional PCR value which was associated to the PES packets.

It was typically extracted from the first TS packet of the PES packet.

Returns
The 42-bit PCR or INVALID_PCR if there is none.

◆ setPCR()

void ts::PESPacket::setPCR ( uint64_t  pcr)

Set the PCR value for this PES packet.

Parameters
[in]pcrThe new 42-bit PCR value. Specify INVALID_PCR to clear the PCR.

◆ getStreamType()

uint8_t ts::PESPacket::getStreamType ( ) const
inline

Get the stream type, as specified in the PMT (optional).

Returns
The stream type.

◆ setStreamType()

void ts::PESPacket::setStreamType ( uint8_t  type)
inline

Set the stream type, as specified in the PMT.

Parameters
[in]typeThe stream type.

◆ getCodec()

CodecType ts::PESPacket::getCodec ( ) const
inline

Get the codec type, as specified by the user (optional).

Returns
The codec type.

◆ setCodec()

void ts::PESPacket::setCodec ( CodecType  codec)
inline

Set the codec type (informational only).

Parameters
[in]codecThe codec type.

◆ setDefaultCodec()

void ts::PESPacket::setDefaultCodec ( CodecType  default_codec)

Set a default codec type.

If the codec is not already known and if the data in the PES packet looks compatible with codec, then this codec type is set.

Parameters
[in]default_codecThe default codec type.

◆ getStreamId()

uint8_t ts::PESPacket::getStreamId ( ) const

Stream id of the PES packet.

Returns
The stream id of the PES packet.

◆ setStreamId()

void ts::PESPacket::setStreamId ( uint8_t  sid)

Set the stream id of the PES packet.

Parameters
[in]sidThe stream id of the PES packet.

◆ hasLongHeader()

bool ts::PESPacket::hasLongHeader ( ) const

Check if the packet has a long header.

Returns
True if the packet has a long header.

◆ header()

const uint8_t* ts::PESPacket::header ( ) const
inline

Access to the PES header of the packet.

Returns
Address of the PES header of the packet.

◆ headerSize()

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

Size of the PES header of the packet.

Returns
Size of the PES header of the packet.

◆ payload()

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

Access to the payload of the packet.

Returns
Address of the payload of the packet.

◆ payloadSize()

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

Size of the payload of the packet.

Returns
Size of the payload of the packet.

◆ spuriousDataSize()

size_t ts::PESPacket::spuriousDataSize ( ) const
inline

Number of spurious data bytes after the packet.

Returns
Size of the spurious data bytes after the packet.

◆ isMPEG2Video()

bool ts::PESPacket::isMPEG2Video ( ) const

Check if the PES packet contains MPEG-2 video.

Also applies to MPEG-1 video.

Returns
True if the PES packet contains MPEG-2 video.

◆ isAVC()

bool ts::PESPacket::isAVC ( ) const

Check if the PES packet contains AVC / H.264 video.

Returns
True if the PES packet contains AVC / H.264 video.

◆ isHEVC()

bool ts::PESPacket::isHEVC ( ) const

Check if the PES packet contains HEVC / H.265 video.

Returns
True if the PES packet contains HEVC / H.265 video.

◆ isVVC()

bool ts::PESPacket::isVVC ( ) const

Check if the PES packet contains VVC / H.266 video.

Returns
True if the PES packet contains VVC / H.266 video.

◆ isAC3()

bool ts::PESPacket::isAC3 ( ) const

Check if the PES packet contains AC-3 or Enhanced-AC-3 audio.

Warning: As specified in ETSI TS 102 366, an AC-3 audio frame always starts with 0x0B77. This is what we check here. However, it is still possible that other encodings may start from time to time with 0x0B77. Thus, it is safe to say that a PID in which all PES packets start with 0x0B77 (ie isAC3() returns true) contains AC-3. However, if only a few PES packets start with 0x0B77, it is safe to say that it should be something else.

Returns
True if the PES packet contains AC-3 or Enhanced-AC-3 audio.

◆ findIntraImage()

size_t ts::PESPacket::findIntraImage ( ) const

Check if the PES packet contains an intra-coded image.

The stream type and/or codec type must have been set.

Returns
If the PES packet contains the start of an intra-coded image, return the offset inside the PES packet where the intra-image starts. This value is informational only, the exact semantics depends on the video codec. Return NPOS if no intra-image was found.

◆ IsMPEG2Video()

static bool ts::PESPacket::IsMPEG2Video ( const uint8_t *  data,
size_t  size,
uint8_t  stream_type = ST_NULL 
)
static

Check if a truncated PES packet may contain MPEG-2 or MPEG-1 video.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
[in]stream_typeOptional stream type, as found in the PMT. Used as a hint.
Returns
True if the PES data may contain MPEG-2 or MPEG-1 video.

◆ IsAVC()

static bool ts::PESPacket::IsAVC ( const uint8_t *  data,
size_t  size,
uint8_t  stream_type = ST_NULL 
)
inlinestatic

Check if a truncated PES packet may contain AVC / H.264 video.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
[in]stream_typeOptional stream type, as found in the PMT. Used as a hint.
Returns
True if the PES data may contain AVC / H.264 video.

◆ IsHEVC()

static bool ts::PESPacket::IsHEVC ( const uint8_t *  data,
size_t  size,
uint8_t  stream_type = ST_NULL 
)
inlinestatic

Check if a truncated PES packet may contain HEVC / H.265 video.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
[in]stream_typeOptional stream type, as found in the PMT. Used as a hint.
Returns
True if the PES data may contain HEVC / H.265 video.

◆ IsVVC()

static bool ts::PESPacket::IsVVC ( const uint8_t *  data,
size_t  size,
uint8_t  stream_type = ST_NULL 
)
inlinestatic

Check if a truncated PES packet may contain VVC / H.266 video.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
[in]stream_typeOptional stream type, as found in the PMT. Used as a hint.
Returns
True if the PES data may contain VVC / H.266 video.

◆ IsAC3()

static bool ts::PESPacket::IsAC3 ( const uint8_t *  data,
size_t  size,
uint8_t  stream_type = ST_NULL 
)
static

Check if a truncated PES packet may contain AC-3 or Enhanced-AC-3 audio.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
[in]stream_typeOptional stream type, as found in the PMT. Used as a hint.
Returns
True if the PES data may contain AC-3 or Enhanced-AC-3 audio.

◆ HasCommonVideoHeader()

static bool ts::PESPacket::HasCommonVideoHeader ( const uint8_t *  data,
size_t  size 
)
static

Check if a truncated PES packet starts with 00 00 00 [00...] 01, common header for AVC, HEVC and VVC.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
Returns
True if the PES data starts with a common header.

◆ FindIntraImage()

static size_t ts::PESPacket::FindIntraImage ( const uint8_t *  data,
size_t  size,
uint8_t  stream_type = ST_NULL,
CodecType  default_format = CodecType::UNDEFINED 
)
static

Check if a truncated PES packet may contain the start of an intra-coded image.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
[in]stream_typeOptional stream type, as found in the PMT. Used as a hint.
[in]default_formatDefault encoding format if it cannot be determined from stream_type. If stream_type and default_format are both unspecified, intra-image cannot be detected.
Returns
If the PES data may contain the start of an intra-coded image, return the offset inside data where the intra-image starts. This value is informational only, the exact semantics depends on the video codec. Return NPOS if no intra-image was found. If the data is not sufficient to determine the presence of an intra-image, return NPOS, even though a larger piece of information may contain one.

◆ copy() [2/2]

DemuxedData& ts::DemuxedData::copy ( const DemuxedData other)
inherited

Duplication.

Similar to assignment but the data are duplicated.

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

◆ operator==() [2/2]

bool ts::DemuxedData::operator== ( const DemuxedData other) const
inherited

Equality operator.

The source PID's are ignored, only the data contents are compared.

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

◆ operator!=() [2/2]

bool ts::DemuxedData::operator!= ( const DemuxedData other) const
inlineinherited

Unequality operator.

The source PID's are ignored, only the packet contents are compared.

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

◆ sourcePID()

PID ts::DemuxedData::sourcePID ( ) const
inlineinherited

Get the source PID.

Returns
The source PID.

◆ setSourcePID()

void ts::DemuxedData::setSourcePID ( PID  pid)
inlineinherited

Set the source PID.

Parameters
[in]pidThe source PID.

◆ firstTSPacketIndex()

PacketCounter ts::DemuxedData::firstTSPacketIndex ( ) const
inlineinherited

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

Usually valid only if the data were extracted by a demux.

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

◆ lastTSPacketIndex()

PacketCounter ts::DemuxedData::lastTSPacketIndex ( ) const
inlineinherited

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

Usually valid only if the data were extracted by a demux.

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

◆ setFirstTSPacketIndex()

void ts::DemuxedData::setFirstTSPacketIndex ( PacketCounter  i)
inlineinherited

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

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

◆ setLastTSPacketIndex()

void ts::DemuxedData::setLastTSPacketIndex ( PacketCounter  i)
inlineinherited

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

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

◆ content()

virtual const uint8_t* ts::DemuxedData::content ( ) const
virtualinherited

Access to the full binary content of the data.

Do not modify content.

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

◆ matchContent()

bool ts::DemuxedData::matchContent ( const ByteBlock pattern,
const ByteBlock mask = ByteBlock() 
) const
inherited

Check if the start of the data matches a given pattern.

Parameters
[in]patternA byte block to compare with the start of the data.
[in]maskOptional mask to select meaningful bits in pattern.
Returns
Size of the binary content of the data.

◆ rwContent()

uint8_t* ts::DemuxedData::rwContent ( )
inlineprotectedinherited

Read/write access to the full binary content of the data for subclasses.

Returns
Address of the full binary content of the data.

◆ rwResize()

void ts::DemuxedData::rwResize ( size_t  s)
protectedinherited

Resize the full binary content of the data for subclasses.

Parameters
[in]sNew size in bytes of the full binary content of the data.

◆ rwAppend()

void ts::DemuxedData::rwAppend ( const void *  data,
size_t  dsize 
)
protectedinherited

Append raw data to the full binary content of the data for subclasses.

Parameters
[in]dataAddress of the new area to append.
[in]dsizeSize of the area to append.

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