vdr-plugin-softhddevice-drm-gles 1.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
cPes Class Referenceabstract

PES packet parser class. More...

#include <pes.h>

Public Member Functions

 cPes (const uint8_t *, int)
 Construct a PES packet parser. More...
 
bool IsValid ()
 Check if the PES packet is valid. More...
 
bool HasPts ()
 Check if the PES packet contains a Presentation Time Stamp (PTS) More...
 
int64_t GetPts ()
 Get the Presentation Time Stamp (PTS) from the PES header. More...
 
const uint8_t * GetPayload ()
 Get a pointer to the PES payload data. More...
 
int GetPayloadSize ()
 Get the size of the PES payload. More...
 
int GetPacketLength ()
 Get the total length of the PES packet. More...
 
uint8_t GetStreamId ()
 

Protected Member Functions

virtual bool IsStreamIdValid ()=0
 
void Init ()
 Initialize and validate the PES packet. More...
 
bool IsHeaderValid ()
 Check if the PES header is valid. More...
 

Protected Attributes

bool m_valid = false
 flag indicating if the PES packet is valid More...
 
const uint8_t * m_data
 pointer to the raw PES packet data More...
 
int m_size
 size of the PES packet More...
 

Static Protected Attributes

static constexpr uint32_t PES_PACKET_START_CODE_PREFIX = 0x00'0001
 
static constexpr uint32_t PES_PACKET_START_CODE_PREFIX_LEN = 3
 

Detailed Description

PES packet parser class.

This class parses PES (Packetized Elementary Stream) packets to extract header information, PTS, and payload data.

Definition at line 38 of file pes.h.

Constructor & Destructor Documentation

◆ cPes()

cPes::cPes ( const uint8_t *  data,
int  size 
)

Construct a PES packet parser.

Initializes the parser with a pointer to PES packet data and its size. The actual validation is performed by calling Init() in derived classes.

Parameters
dataPointer to the raw PES packet data
sizeSize of the PES packet in bytes

Definition at line 215 of file pes.cpp.

Member Function Documentation

◆ GetPacketLength()

int cPes::GetPacketLength ( )

Get the total length of the PES packet.

Returns the complete size of the PES packet including both header and payload. The length is read from the PES packet header (bytes 4-5).

For packets with a specified length field (common for audio):

  • Returns the actual PES packet length from the header
  • Calculated as 6 + length_field (per H.222.0 standard)
  • The length_field specifies bytes after the 6-byte header prefix (3 bytes start code + 1 byte stream ID + 2 bytes length field)

For unbounded packets (length field = 0, common for video streams):

  • Returns the input buffer size (m_size)
Returns
Total size in bytes: actual packet length if specified, otherwise input buffer size

Definition at line 346 of file pes.cpp.

References m_data, and m_size.

Referenced by cSoftHdDevice::HandleStillPicture(), and TEST_CASE().

◆ GetPayload()

const uint8_t * cPes::GetPayload ( )

Get a pointer to the PES payload data.

Returns a pointer to the start of the payload data, skipping the PES header. For H.264/HEVC streams with a leading zero byte, the leading zero is also skipped.

Returns
Pointer to the payload data

Definition at line 311 of file pes.cpp.

References m_data.

Referenced by cSoftHdDevice::PlayAudio(), cSoftHdDevice::PlayVideoInternal(), and TEST_CASE().

◆ GetPayloadSize()

int cPes::GetPayloadSize ( )

Get the size of the PES payload.

Calculates the size of the payload by subtracting the header size (and optional leading zero for H.264/HEVC) from the total packet size.

Returns
Size of the payload in bytes

Definition at line 324 of file pes.cpp.

References m_data, and m_size.

Referenced by cSoftHdDevice::PlayAudio(), cSoftHdDevice::PlayVideoInternal(), and TEST_CASE().

◆ GetPts()

int64_t cPes::GetPts ( )

Get the Presentation Time Stamp (PTS) from the PES header.

Extracts the PTS value from the PES packet header if present. The PTS indicates when the decoded content should be presented.

Returns
The PTS value in 90 kHz units, or AV_NOPTS_VALUE if no PTS is present

Definition at line 295 of file pes.cpp.

References AV_NOPTS_VALUE, HasPts(), and m_data.

Referenced by cSoftHdDevice::PlayAudio(), cSoftHdDevice::PlayVideoInternal(), and TEST_CASE().

◆ GetStreamId()

uint8_t cPes::GetStreamId ( )
inline

Definition at line 48 of file pes.h.

References m_data.

Referenced by Init(), cPesAudio::IsAudioStreamId(), cPesAudio::IsPrivateStreamId(), and cPesVideo::IsStreamIdValid().

◆ HasPts()

bool cPes::HasPts ( void  )

Check if the PES packet contains a Presentation Time Stamp (PTS)

Examines the PES header flags to determine if a PTS is present in the packet. The PTS presence is indicated by specific bits in the PES header flags field.

Returns
true if the PES packet contains a PTS, false otherwise

Definition at line 282 of file pes.cpp.

References m_data.

Referenced by GetPts(), and cSoftHdDevice::PlayVideoInternal().

◆ Init()

void cPes::Init ( void  )
protected

Initialize and validate the PES packet.

Performs validation checks on the PES packet structure:

  • Validates the PES header (start code prefix)
  • Checks if the stream ID matches the expected type (audio/video)
  • Ensures the packet has sufficient size for the header
  • Verifies the payload offset is within bounds

Sets m_valid to true if all checks pass. Called by derived class constructors.

Definition at line 231 of file pes.cpp.

References GetStreamId(), IsHeaderValid(), IsStreamIdValid(), LOGDEBUG, LOGWARNING, m_data, m_size, and m_valid.

Referenced by cPesAudio::cPesAudio(), and cPesVideo::cPesVideo().

◆ IsHeaderValid()

bool cPes::IsHeaderValid ( )
protected

Check if the PES header is valid.

Validates that the PES packet has a valid header by checking:

  • The packet is long enough to contain a header
  • The start code prefix (0x000001) is present
Returns
true if the header is valid, false otherwise

Definition at line 269 of file pes.cpp.

References m_data, m_size, PES_PACKET_START_CODE_PREFIX, and ReadBytes().

Referenced by Init().

◆ IsStreamIdValid()

virtual bool cPes::IsStreamIdValid ( )
protectedpure virtual

Implemented in cPesVideo, and cPesAudio.

Referenced by Init().

◆ IsValid()

bool cPes::IsValid ( )

Check if the PES packet is valid.

Validates that the PES packet is well-formed and matches the expected stream type by checking:

  • The PES header is valid
  • The stream ID matches the expected stream type (video or audio)

The stream ID is masked with 0xF0 to check the stream type category (e.g., 0xE0 for video, 0xC0 for audio) while ignoring the low nibble which indicates the specific stream number.

Video streams have stream IDs in the range 0xE0-0xEF according to H.222.0 03/2017 Table 2-22, audio streams have IDs in the range 0xC0-0xCF.

Returns
true if the packet is valid and matches the expected stream type, false otherwise

Definition at line 256 of file pes.cpp.

References m_valid.

Referenced by cSoftHdDevice::HandleStillPicture(), cSoftHdDevice::PlayAudio(), cSoftHdDevice::PlayVideoInternal(), and TEST_CASE().

Member Data Documentation

◆ m_data

const uint8_t* cPes::m_data
protected

pointer to the raw PES packet data

Definition at line 56 of file pes.h.

Referenced by GetPacketLength(), GetPayload(), GetPayloadSize(), GetPts(), GetStreamId(), HasPts(), Init(), and IsHeaderValid().

◆ m_size

int cPes::m_size
protected

size of the PES packet

Definition at line 57 of file pes.h.

Referenced by GetPacketLength(), GetPayloadSize(), Init(), and IsHeaderValid().

◆ m_valid

bool cPes::m_valid = false
protected

flag indicating if the PES packet is valid

Definition at line 55 of file pes.h.

Referenced by Init(), and IsValid().

◆ PES_PACKET_START_CODE_PREFIX

constexpr uint32_t cPes::PES_PACKET_START_CODE_PREFIX = 0x00'0001
staticconstexprprotected

Definition at line 61 of file pes.h.

Referenced by IsHeaderValid().

◆ PES_PACKET_START_CODE_PREFIX_LEN

constexpr uint32_t cPes::PES_PACKET_START_CODE_PREFIX_LEN = 3
staticconstexprprotected

Definition at line 62 of file pes.h.


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