TSDuck v3.40-4120
MPEG Transport Stream Toolkit
|
Representation of MPEG PES packets. More...
#include <tsPESPacket.h>
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. | |
const UString & | attribute () const |
Get the generic user-defined "attribute" string of the object. | |
virtual void | clear () override |
Clear data content. | |
virtual const uint8_t * | content () const |
Access to the full binary content of the data. | |
DemuxedData & | copy (const DemuxedData &other) |
Duplication. | |
PESPacket & | copy (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. | |
PESPacket & | operator= (const PESPacket &other) |
Assignment operator. | |
PESPacket & | operator= (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 | setAttribute (const UString &attr) |
Set a generic user-defined string as "attribute" of the object. | |
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. | |
Representation of MPEG PES packets.
Default constructor.
The PESPacket is initially marked invalid.
[in] | source_pid | PID from which the packet was read. |
Copy constructor.
[in] | other | Another instance to copy. |
[in] | mode | The packet's data are either shared (ShareMode::SHARE) between the two instances or duplicated (ShareMode::COPY). |
|
noexcept |
Move constructor.
[in,out] | other | Another instance to move. |
Constructor from full binary content.
The content is copied into the packet if valid.
[in] | content | Address of the binary packet data. |
[in] | content_size | Size in bytes of the packet. |
[in] | source_pid | PID from which the packet was read. |
Constructor from full binary content.
The content is copied into the packet if valid.
[in] | content | Binary packet data. |
[in] | source_pid | PID from which the packet was read. |
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.
|
overridevirtual |
Clear data content.
Reimplemented from ts::DemuxedData.
|
overridevirtual |
Reload from full binary content.
[in] | content | Address of the binary packet data. |
[in] | content_size | Size in bytes of the packet. |
[in] | source_pid | PID from which the data were read. |
Reimplemented from ts::DemuxedData.
|
overridevirtual |
Reload from full binary content.
[in] | content | Binary packet data. |
[in] | source_pid | PID from which the data were read. |
Reimplemented from ts::DemuxedData.
|
overridevirtual |
Reload from full binary content.
[in] | content_ptr | Safe 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_pid | PID from which the data were read. |
Reimplemented from ts::DemuxedData.
|
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.
Reimplemented from ts::DemuxedData.
Assignment operator.
The packets are referenced, and thus shared between the two packet objects.
[in] | other | Other packet to assign to this object. |
Move assignment operator.
[in,out] | other | Other packet to assign to this object. |
Duplication.
Similar to assignment but the packets are duplicated.
[in] | other | Other packet to duplicate into this object. |
|
inline |
Check if the packet has valid content.
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.
[in] | other | Other packet to compare. |
|
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.
void ts::PESPacket::setPCR | ( | uint64_t | pcr | ) |
Set the PCR value for this PES packet.
[in] | pcr | The new 42-bit PCR value. Specify INVALID_PCR to clear the PCR. |
|
inline |
Get the stream type, as specified in the PMT (optional).
|
inline |
Set the stream type, as specified in the PMT.
[in] | type | The stream type. |
|
inline |
Get the codec type, as specified by the user (optional).
|
inline |
Set the codec type (informational only).
[in] | codec | The codec type. |
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.
[in] | default_codec | The default codec type. |
uint8_t ts::PESPacket::getStreamId | ( | ) | const |
Stream id of the PES packet.
void ts::PESPacket::setStreamId | ( | uint8_t | sid | ) |
Set the stream id of the PES packet.
[in] | sid | The stream id of the PES packet. |
bool ts::PESPacket::hasLongHeader | ( | ) | const |
Check if the packet has a long header.
|
inline |
Access to the PES header of the packet.
|
inline |
Size of the PES header of the packet.
|
inline |
Access to the payload of the packet.
|
inline |
Size of the payload of the packet.
|
inline |
Number of spurious data bytes after the packet.
bool ts::PESPacket::isMPEG2Video | ( | ) | const |
Check if the PES packet contains MPEG-2 video.
Also applies to MPEG-1 video.
bool ts::PESPacket::isAVC | ( | ) | const |
Check if the PES packet contains AVC / H.264 video.
bool ts::PESPacket::isHEVC | ( | ) | const |
Check if the PES packet contains HEVC / H.265 video.
bool ts::PESPacket::isVVC | ( | ) | const |
Check if the PES packet contains VVC / H.266 video.
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.
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.
|
static |
Get the header size of the start of a PES packet.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
|
static |
Check if a truncated PES packet may contain MPEG-2 or MPEG-1 video.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
[in] | stream_type | Optional stream type, as found in the PMT. Used as a hint. |
|
inlinestatic |
Check if a truncated PES packet may contain AVC / H.264 video.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
[in] | stream_type | Optional stream type, as found in the PMT. Used as a hint. |
|
inlinestatic |
Check if a truncated PES packet may contain HEVC / H.265 video.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
[in] | stream_type | Optional stream type, as found in the PMT. Used as a hint. |
|
inlinestatic |
Check if a truncated PES packet may contain VVC / H.266 video.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
[in] | stream_type | Optional stream type, as found in the PMT. Used as a hint. |
|
static |
Check if a truncated PES packet may contain AC-3 or Enhanced-AC-3 audio.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
[in] | stream_type | Optional stream type, as found in the PMT. Used as a hint. |
|
static |
Check if a truncated PES packet starts with 00 00 00 [00...] 01, common header for AVC, HEVC and VVC.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
|
static |
Check if a truncated PES packet may contain the start of an intra-coded image.
[in] | data | Address of data to check, typically the start of a PES packet. |
[in] | size | Data size in bytes. |
[in] | stream_type | Optional stream type, as found in the PMT. Used as a hint. |
[in] | default_format | Default encoding format if it cannot be determined from stream_type. If stream_type and default_format are both unspecified, intra-image cannot be detected. |
|
inherited |
Duplication.
Similar to assignment but the data are duplicated.
[in] | other | Other data to duplicate into this object. |
|
inherited |
Equality operator.
The source PID's are ignored, only the data contents are compared.
[in] | other | Other packet to compare. |
|
inlineinherited |
Get the source PID.
|
inlineinherited |
Set the source PID.
[in] | pid | The source PID. |
|
inlineinherited |
Index of first TS packet of the data in the demultiplexed stream.
Usually valid only if the data were extracted by a demux.
|
inlineinherited |
Index of last TS packet of the data in the demultiplexed stream.
Usually valid only if the data were extracted by a demux.
|
inlineinherited |
Set the first TS packet of the data in the demultiplexed stream.
[in] | i | The first TS packet of the data in the demultiplexed stream. |
|
inlineinherited |
Set the last TS packet of the data in the demultiplexed stream.
[in] | i | The last TS packet of the data in the demultiplexed stream. |
|
inlineinherited |
Set a generic user-defined string as "attribute" of the object.
The semantics of this attribute string is not defined. It is used by the application. The attribute string can be found in the <metadata>
structure of the XML representation of a table.
[in] | attr | Generic string to set as attribute. |
|
inlineinherited |
Get the generic user-defined "attribute" string of the object.
|
virtualinherited |
Access to the full binary content of the data.
Do not modify content.
|
inherited |
Size of the complete binary raw data containing the logical structure.
|
inherited |
Check if the start of the data matches a given pattern.
[in] | pattern | A byte block to compare with the start of the data. |
[in] | mask | Optional mask to select meaningful bits in pattern. |
|
inlineprotectedinherited |
Read/write access to the full binary content of the data for subclasses.
|
protectedinherited |
Resize the full binary content of the data for subclasses.
[in] | s | New size in bytes of the full binary content of the data. |
|
protectedinherited |
Append raw data to the full binary content of the data for subclasses.
[in] | data | Address of the new area to append. |
[in] | dsize | Size of the area to append. |