TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches

#include <tsPESDemux.h>

Inheritance diagram for ts::PESDemux:
Collaboration diagram for ts::PESDemux:

Public Types

using SuperClass = TimeTrackerDemux

Public Member Functions

 PESDemux (DuckContext &duck, PESHandlerInterface *handler=nullptr, const PIDSet &pids=AllPIDs())
virtual ~PESDemux () override
virtual void addPID (PID pid)
virtual void addPIDs (const PIDSet &pids)
bool allAC3 (PID pid) const
int demuxId () const
DuckContext & duck ()
virtual void feedPacket (const TSPacket &pkt) override
void flushUnboundedPES ()
void flushUnboundedPES (PID pid)
void getAC3Attributes (PID pid, AC3Attributes &attr) const
void getAudioAttributes (PID pid, MPEG2AudioAttributes &attr) const
void getAVCAttributes (PID pid, AVCAttributes &attr) const
CodecType getDefaultCodec (PID pid) const
void getHEVCAttributes (PID pid, HEVCAttributes &attr) const
size_t getMaxUnboundedSize () const
void getVideoAttributes (PID pid, MPEG2VideoAttributes &attr) const
virtual bool isFilteredPID (PID pid) const
virtual size_t pidCount () const
cn::milliseconds pidDuration (PID pid) const
PacketCounter processedPackets () const
virtual void removePID (PID pid)
Report & report ()
virtual void reset ()
virtual void resetPID (PID pid)
void setDefaultCodec (CodecType codec)
void setDefaultCodec (PID pid, CodecType codec)
void setDemuxId (int id)
void setMaxUnboundedSize (size_t size)
void setPESHandler (PESHandlerInterface *h)
virtual void setPIDFilter (const PIDSet &pid_filter)
PacketCounter totalPackets () const

Static Public Attributes

static constexpr size_t DEFAULT_MAX_UNBOUNDED_PES_SIZE = 512 * 1024

Protected Member Functions

bool afterCallingHandler (bool execute_delayed_operations=true)
void beforeCallingHandler (PID pid=PID_NULL)
virtual void handlePESPacket (const PESPacket &packet)
virtual void immediateReset () override
virtual void immediateResetPID (PID pid) override

Detailed Description

This class extracts PES packets from TS packets.

Member Typedef Documentation

◆ SuperClass

Explicit reference to superclass.

Constructor & Destructor Documentation

◆ PESDemux()

ts::PESDemux::PESDemux ( DuckContext & duck,
PESHandlerInterface * handler = nullptr,
const PIDSet & pids = AllPIDs() )
explicit

Constructor.

Parameters
[in,out]duckTSDuck execution context. The reference is kept inside the demux.
[in]handlerThe object to invoke when PES packets are analyzed.
[in]pidsThe set of PID's to demux.

◆ ~PESDemux()

virtual ts::PESDemux::~PESDemux ( )
overridevirtual

Destructor.

Member Function Documentation

◆ feedPacket()

virtual void ts::PESDemux::feedPacket ( const TSPacket & pkt)
overridevirtual

The following method feeds the demux with a TS packet.

Parameters
[in]pktA TS packet.

Reimplemented from ts::TimeTrackerDemux.

◆ flushUnboundedPES() [1/2]

void ts::PESDemux::flushUnboundedPES ( PID pid)

Flush any unterminated unbounded PES packet on the specified PID. Unbounded PES packets have no predetermined size. They implicitely end when the next PES packet starts on the same PID. However, at end of stream, there is no next PES packet and the previous buffered data are not considered as a full unbounded packet. These data are lost. This method shall be called at end of stream when the caller is certain that the buffered data from the PID form a complete PES packet. This PES packet is then processed.

Parameters
[in]pidPID containing an unbounded PES packet to complete.

◆ flushUnboundedPES() [2/2]

void ts::PESDemux::flushUnboundedPES ( )

Flush any unterminated unbounded PES packet on all PID's.

See also
flushUnboundedPES(PID)

◆ setPESHandler()

void ts::PESDemux::setPESHandler ( PESHandlerInterface * h)
inline

Replace the PES packet handler.

Parameters
[in]hThe object to invoke when PES packets are analyzed.

◆ setMaxUnboundedSize()

void ts::PESDemux::setMaxUnboundedSize ( size_t size)
inline

Set the maximum size for unbounded PES packets. Unbounded PES packets have no predetermined size. They implicitely end when the next PES packet starts on the same PID. The demux accumulates the PES content for them on each PID as long as no new PES packet starts. To avoid saturating the memory of the demux, we limit the size of unbounded PES packets. If an unbounded PES packet exceeds the specified maximum size, the binary content which was accumulated so far for that PES packet is passed to the handler's handleInvalidPESPacket() and the PES packet is dropped. Accumulating PES data on that PID will restart at the beginning of the next PES packet.

Parameters
[in]sizeThe maximum size for unbounded PES packets to use.

◆ getMaxUnboundedSize()

size_t ts::PESDemux::getMaxUnboundedSize ( ) const
inline

Get the maximum size for unbounded PES packets.

Returns
The maximum size for unbounded PES packets.
See also
setMaxUnboundedSize()

◆ setDefaultCodec() [1/2]

void ts::PESDemux::setDefaultCodec ( CodecType codec)
inline

Set the default audio or video codec for all analyzed PES PID's. The analysis of the content of a PES packet sometimes depends on the PES data format. The PES demux uses several ways to determine the data format inside a PES packet. First, when the packet is identified in a PMT, the stream type may uniquely identify the format. Second, the content itself can be identified as a specific format. Finally, in the absence of other indications, the specified codec is used.

Parameters
[in]codecThe default codec to use.

◆ setDefaultCodec() [2/2]

void ts::PESDemux::setDefaultCodec ( PID pid,
CodecType codec )

Set the default audio or video codec for one specific PES PID's. This is the same as setDefaultCodec(CodecType) for one specific PID. The codec of a PID is automatically determined from the characteristics of this PID in the PMT, if the PMT packets are passed to this demux.

Parameters
[in]pidThe PID to identify.
[in]codecThe default codec to use.
See also
setDefaultCodec(CodecType)

◆ getDefaultCodec()

CodecType ts::PESDemux::getDefaultCodec ( PID pid) const

Get the default codec type on a given PID.

Parameters
[in]pidThe PID to check.
Returns
The default codec to use on pid.
See also
setDefaultCodec()

◆ getAudioAttributes()

void ts::PESDemux::getAudioAttributes ( PID pid,
MPEG2AudioAttributes & attr ) const

Get the current audio attributes on the specified PID.

Parameters
[in]pidThe PID to check.
[out]attrThe returned attributes. Invoke its isValid() method to verify its validity.

◆ getVideoAttributes()

void ts::PESDemux::getVideoAttributes ( PID pid,
MPEG2VideoAttributes & attr ) const

Get the current MPEG-2 video attributes on the specified PID.

Parameters
[in]pidThe PID to check.
[out]attrThe returned attributes. Invoke its isValid() method to verify its validity.

◆ getAVCAttributes()

void ts::PESDemux::getAVCAttributes ( PID pid,
AVCAttributes & attr ) const

Get the current AVC video attributes on the specified PID.

Parameters
[in]pidThe PID to check.
[out]attrThe returned attributes. Invoke its isValid() method to verify its validity.

◆ getHEVCAttributes()

void ts::PESDemux::getHEVCAttributes ( PID pid,
HEVCAttributes & attr ) const

Get the current HEVC video attributes on the specified PID.

Parameters
[in]pidThe PID to check.
[out]attrThe returned attributes. Invoke its isValid() method to verify its validity.

◆ getAC3Attributes()

void ts::PESDemux::getAC3Attributes ( PID pid,
AC3Attributes & attr ) const

Get the current AC-3 audio attributes on the specified PID.

Parameters
[in]pidThe PID to check.
[out]attrThe returned attributes. Invoke its isValid() method to verify its validity.

◆ allAC3()

bool ts::PESDemux::allAC3 ( PID pid) const

Check if all PES packets on the specified PID contain AC-3 audio.

Parameters
[in]pidThe PID to check.
Returns
True if all PES packets on the specified PID contain AC-3 audio. Due to the way AC-3 is detected, it is possible that some PES packets are erroneously detected as AC-3. Thus, getAC3Attributes() returns a valid value since some AC-3 was detected. But, on homogeneous streams, it is safe to assume that the PID really contains AC-3 only if all PES packets contain AC-3.

◆ handlePESPacket()

virtual void ts::PESDemux::handlePESPacket ( const PESPacket & packet)
protectedvirtual

This hook is invoked when a complete PES packet is available. Can be overloaded by subclasses to add intermediate processing.

Parameters
[in]packetThe PES packet.

Reimplemented in ts::TeletextDemux.

◆ immediateReset()

virtual void ts::PESDemux::immediateReset ( )
overrideprotectedvirtual

Reset the demux immediately.

Reimplemented from ts::TimeTrackerDemux.

Reimplemented in ts::TeletextDemux.

◆ immediateResetPID()

virtual void ts::PESDemux::immediateResetPID ( PID pid)
overrideprotectedvirtual

Reset the demuxing context for one single PID immediately.

Parameters
[in]pidThe PID to reset.

Reimplemented from ts::TimeTrackerDemux.

Reimplemented in ts::TeletextDemux.

◆ pidDuration()

cn::milliseconds ts::TimeTrackerDemux::pidDuration ( PID pid) const
inherited

Get the number of milliseconds measured on a PID.

Parameters
[in]pidThe PID to check.
Returns
The number of milliseconds of the content of the specified pid, since the beginning of the stream, based on the PTS of this PID. If no PTS were found on this PID, use PCR's from another PID. Return zero is no timing information was found.

◆ report()

Report & ts::AbstractDemux::report ( )
inlineinherited

Get the associated Report.

Returns
A reference to the associated Report.

◆ duck()

DuckContext & ts::AbstractDemux::duck ( )
inlineinherited

Get the associated TSDuck execution context.

Returns
A reference to the associated DuckContext.

◆ setPIDFilter()

virtual void ts::AbstractDemux::setPIDFilter ( const PIDSet & pid_filter)
virtualinherited

Replace the list of PID's to filter. The method resetPID() is invoked on each removed PID.

Parameters
[in]pid_filterThe list of PID's to filter.

◆ addPID()

virtual void ts::AbstractDemux::addPID ( PID pid)
inlinevirtualinherited

Add one PID to filter.

Parameters
[in]pidThe new PID to filter.

Reimplemented in ts::MPEDemux.

◆ addPIDs()

virtual void ts::AbstractDemux::addPIDs ( const PIDSet & pids)
inlinevirtualinherited

Add several PID's to filter.

Parameters
[in]pidsThe list of new PID's to filter.

Reimplemented in ts::MPEDemux.

◆ removePID()

virtual void ts::AbstractDemux::removePID ( PID pid)
virtualinherited

Remove one PID to filter. The method resetPID() is invoked on pid.

Parameters
[in]pidThe PID to no longer filter.

Reimplemented in ts::MPEDemux.

◆ pidCount()

virtual size_t ts::AbstractDemux::pidCount ( ) const
inlinevirtualinherited

Get the current number of PID's being filtered.

Returns
The current number of PID's being filtered.

◆ totalPackets()

PacketCounter ts::AbstractDemux::totalPackets ( ) const
inlineinherited

Get the current total number of TS packets which were processed by the demux.

Returns
The current number of TS packets which were processed by the demux.

◆ processedPackets()

PacketCounter ts::AbstractDemux::processedPackets ( ) const
inlineinherited

Get the number of processed TS packets in filtered PIDs.

Returns
The number of processed TS packets.

◆ isFilteredPID()

virtual bool ts::AbstractDemux::isFilteredPID ( PID pid) const
inlinevirtualinherited

Check if a PID is filtered.

Parameters
[in]pidThe PID to test.
Returns
Tue if pid is filtered.

◆ reset()

virtual void ts::AbstractDemux::reset ( )
virtualinherited

Reset the demux.

Useful when the transport stream changes. The PID filter and the handlers are not modified.

If invoked in an application-handler, the operation is delayed until the handler terminates. For subclass implementers, see beforeCallingHandler() and override immediateReset() instead of reset().

Reimplemented in ts::StandaloneTableDemux.

◆ resetPID()

virtual void ts::AbstractDemux::resetPID ( PID pid)
virtualinherited

Reset the demuxing context for one single PID. Forget all previous partially demuxed data on this PID.

If invoked in an application-handler, the operation is delayed until the handler terminates. For subclass implementers, see beforeCallingHandler() and override immediateResetPID() instead of resetPID().

Parameters
[in]pidThe PID to reset.

Reimplemented in ts::StandaloneTableDemux.

◆ setDemuxId()

void ts::AbstractDemux::setDemuxId ( int id)
inlineinherited

Set some arbitrary "demux id" value. This value is chosen and set by the application. It can be retrieved later if a table or section handler is used by several demux. The demux id is not interpreted by the demux, it is only stored for the application. The initial value of a demux id is zero.

Parameters
[in]idApplication-defined demux id to assign.

◆ demuxId()

int ts::AbstractDemux::demuxId ( ) const
inlineinherited

Get the "demux id" value, as previously stored by the application.

Returns
The application-defined demux id.

◆ beforeCallingHandler()

void ts::AbstractDemux::beforeCallingHandler ( PID pid = PID_NULL)
protectedinherited

Helper for subclass, before invoking an application-defined handler.

The idea is to protect the integrity of the demux during the execution of an application-defined handler. The handler is invoked in the middle of an operation but the handler may call reset() or resetPID(). Executing the reset in the middle of an operation may be problematic. By using beforeCallingHandler() and afterCallingHandler(), all reset operations in between are delayed after the execution of the handler.

Example:

try {
_handler->handleEvent(*this, pid, ...);
}
catch (...) {
throw;
}
bool afterCallingHandler(bool execute_delayed_operations=true)
void beforeCallingHandler(PID pid=PID_NULL)
Parameters
[in]pidThe PID for which the handler will be called. All reset operations on this PID will be delayed until afterCallingHandler().

◆ afterCallingHandler()

bool ts::AbstractDemux::afterCallingHandler ( bool execute_delayed_operations = true)
protectedinherited

Helper for subclass, after invoking an application-defined handler.

Parameters
[in]execute_delayed_operationsWhen true (the default), execute all pending reset operations.
Returns
True if a delayed reset was executed.
See also
beforeCallingHandler()

Member Data Documentation

◆ DEFAULT_MAX_UNBOUNDED_PES_SIZE

size_t ts::PESDemux::DEFAULT_MAX_UNBOUNDED_PES_SIZE = 512 * 1024
staticconstexpr

Default maximum size for unbounded PES packets.

See also
setMaxUnboundedSize()

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