TSDuck v3.38-3696
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::PESPacket Class Reference

Representation of MPEG PES packets. More...

#include <tsPESPacket.h>

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

Public Types

using SuperClass = DemuxedData
 Explicit identification of super class.
 

Public Member Functions

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

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.
 
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.
 
static size_t HeaderSize (const uint8_t *data, size_t size)
 Get the header size of the start of a PES packet.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Protected Member Functions

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

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

◆ clear()

virtual void ts::PESPacket::clear ( )
overridevirtual

Clear data content.

Reimplemented from ts::DemuxedData.

◆ 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 logical binary content of the data.

For subclasses of DemuxedData, this is the logical size of the data structure inside the DemuxedData blob.

Returns
Size of the logical 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.

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

◆ HeaderSize()

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

Get the header size of the start of a PES packet.

Parameters
[in]dataAddress of data to check, typically the start of a PES packet.
[in]sizeData size in bytes.
Returns
The PES header size in bytes, if one is found, or 0 on error.

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

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

◆ rawDataSize()

size_t ts::DemuxedData::rawDataSize ( ) const
inherited

Size of the complete binary raw data containing the logical structure.

Returns
Size of the complete binary raw data.

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