TSDuck v3.40-4033
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::CyclingPacketizer Class Reference

Cyclic packetization of MPEG sections into Transport Stream packets. More...

#include <tsCyclingPacketizer.h>

Inheritance diagram for ts::CyclingPacketizer:
Collaboration diagram for ts::CyclingPacketizer:

Public Types

enum class  StuffingPolicy {
  NEVER ,
  AT_END ,
  ALWAYS
}
 Specify where stuffing applies. More...
 

Public Member Functions

 CyclingPacketizer (const DuckContext &duck, PID pid=PID_NULL, StuffingPolicy policy=StuffingPolicy::AT_END, const BitRate &bitrate=0)
 Default constructor.
 
virtual ~CyclingPacketizer () override
 Destructor.
 
void addSection (const SectionPtr &section, cn::milliseconds repetition_rate=cn::milliseconds::zero())
 Add one section into the packetizer.
 
void addSections (const SectionPtrVector &sections, cn::milliseconds repetition_rate=cn::milliseconds::zero())
 Add some sections into the packetizer.
 
void addTable (const BinaryTable &table, cn::milliseconds repetition_rate=cn::milliseconds::zero())
 Add all sections of a binary table into the packetizer.
 
void addTable (DuckContext &duck, const AbstractTable &table, cn::milliseconds repetition_rate=cn::milliseconds::zero())
 Add all sections of a typed table into the packetizer.
 
void allowHeaderSplit (bool allow)
 Allow or disallow splitting section headers across TS packets.
 
bool atCycleBoundary () const
 Check if the last generated packet was the last packet in the cycle.
 
bool atSectionBoundary () const
 Check if the packet stream is exactly at a section boundary.
 
BitRate bitRate () const
 Get the bitrate of the generated PID.
 
virtual std::ostream & display (std::ostream &strm) const override
 Display the internal state of the packetizer, mainly for debug.
 
const DuckContextduck () const
 Get a reference to the TSDuck execution context.
 
virtual bool getNextPacket (TSPacket &packet) override
 Build the next MPEG packet for the list of items (sections or PES) to pacjetize.
 
PID getPID () const
 Get the default PID for subsequent MPEG packets.
 
bool headerSplitAllowed () const
 Check if splitting section headers across TS packets is allowed.
 
uint8_t nextContinuityCounter () const
 Get the continuity counter value for next MPEG packet.
 
PacketCounter packetCount () const
 Get the number of generated TS packets so far.
 
void removeAll ()
 Remove all sections in the packetizer.
 
void removeSections (TID tid)
 Remove all sections with the specified table id.
 
void removeSections (TID tid, uint16_t tid_ext)
 Remove all sections with the specified table id and table id extension.
 
void removeSections (TID tid, uint16_t tid_ext, uint8_t sec_number)
 Remove all sections with the specified table id, table id extension and section number.
 
Reportreport () const
 Get a reference to the debugging report.
 
virtual void reset () override
 Reset the packetizer.
 
SectionCounter sectionCount () const
 Get the number of completely packetized sections so far.
 
SectionProviderInterfacesectionProvider () const
 Get the object which provides MPEG sections when the packetizer needs a new section.
 
void setBitRate (const BitRate &bitrate)
 Set the bitrate of the generated PID.
 
void setNextContinuityCounter (uint8_t cc)
 Set the continuity counter value for next MPEG packet.
 
void setPID (PID pid)
 Set the default PID for subsequent MPEG packets.
 
void setStuffingPolicy (StuffingPolicy sp)
 Set the TS packet stuffing policy at end of packet.
 
SectionCounter storedSectionCount () const
 Get the number of stored sections to packetize.
 
StuffingPolicy stuffingPolicy () const
 Get the TS packet stuffing policy at end of packet.
 

Protected Member Functions

void configurePacket (TSPacket &pkt, bool nullify)
 Configure a TS packet with continuity and PID.
 

Detailed Description

Cyclic packetization of MPEG sections into Transport Stream packets.

A CyclingPacketizer contains various sections to be packetized on one PID.

All packets are generated on demand. The generated packets have the right PID and continuity counters and can be directly injected in a transport stream.

The "cycle" of the packetizer is defined as the smallest set of TS packets containing all sections, with respect to the broadcasting constraints (stuffing, specific repetition rates, etc).

It is possible to set different repetition rates for sections. In that case, the target "bitrate" of the PID must be specified. The sections are inserted on a best effort basis to respect the minimum repetition rates.

When the packetizer bitrate is specified as zero (the default), the target bitrate of the PID is unspecified. The repetition rates of sections are ignored.

Note that when sections have different repetition rates, some sections may be repeated into one cycle of the Packetizer.

Section stuffing may occur at the end of a section. If the section ends in the middle of an MPEG packet, the beginning of the next section can start immediately or can be delayed to the beginning of the next packet. In the later case, the rest of the current packet is filled with stuffing bytes (0xFF).

A bitrate is specified in bits/second. Zero means undefined. A repetition rate is specified in milliseconds. Zero means undefined.

Member Enumeration Documentation

◆ StuffingPolicy

Specify where stuffing applies.

Enumerator
NEVER 

No stuffing, always pack sections.

AT_END 

Stuffing at end of cycle, pack sections inside cycle.

ALWAYS 

Always stuffing, never pack sections.

Constructor & Destructor Documentation

◆ CyclingPacketizer()

ts::CyclingPacketizer::CyclingPacketizer ( const DuckContext duck,
PID  pid = PID_NULL,
StuffingPolicy  policy = StuffingPolicy::AT_END,
const BitRate bitrate = 0 
)

Default constructor.

Parameters
[in]duckTSDuck execution context. The reference is kept inside the packetizer.
[in]pidPID for generated TS packets.
[in]policyTS packet stuffing policy at end of packet.
[in]bitrateOutput bitrate, zero if undefined. Useful only when using specific repetition rates for sections

Member Function Documentation

◆ setStuffingPolicy()

void ts::CyclingPacketizer::setStuffingPolicy ( StuffingPolicy  sp)
inline

Set the TS packet stuffing policy at end of packet.

Parameters
[in]spTS packet stuffing policy at end of packet.

◆ stuffingPolicy()

StuffingPolicy ts::CyclingPacketizer::stuffingPolicy ( ) const
inline

Get the TS packet stuffing policy at end of packet.

Returns
TS packet stuffing policy at end of packet.

◆ setBitRate()

void ts::CyclingPacketizer::setBitRate ( const BitRate bitrate)

Set the bitrate of the generated PID.

Useful only when using specific repetition rates for sections

Parameters
[in]bitrateOutput bitrate, zero if undefined.

◆ bitRate()

BitRate ts::CyclingPacketizer::bitRate ( ) const
inline

Get the bitrate of the generated PID.

Returns
Output bitrate, zero if undefined.

◆ addSection()

void ts::CyclingPacketizer::addSection ( const SectionPtr section,
cn::milliseconds  repetition_rate = cn::milliseconds::zero() 
)

Add one section into the packetizer.

The contents of the sections are shared.

Parameters
[in]sectionA smart pointer to the section to packetize.
[in]repetition_rateRepetition rate of the section in milliseconds. If zero, simply packetize sections one after the other.

◆ addSections()

void ts::CyclingPacketizer::addSections ( const SectionPtrVector sections,
cn::milliseconds  repetition_rate = cn::milliseconds::zero() 
)

Add some sections into the packetizer.

The contents of the sections are shared.

Parameters
[in]sectionsA vector of smart pointer to the sections to packetize.
[in]repetition_rateRepetition rate of the sections in milliseconds. If zero, simply packetize sections one after the other.

◆ addTable() [1/2]

void ts::CyclingPacketizer::addTable ( const BinaryTable table,
cn::milliseconds  repetition_rate = cn::milliseconds::zero() 
)

Add all sections of a binary table into the packetizer.

The contents of the sections are shared. If the table is not complete (there are missing sections), the sections which are present are individually added.

Parameters
[in]tableA binary table to packetize.
[in]repetition_rateRepetition rate of the sections in milliseconds. If zero, simply packetize sections one after the other.

◆ addTable() [2/2]

void ts::CyclingPacketizer::addTable ( DuckContext duck,
const AbstractTable table,
cn::milliseconds  repetition_rate = cn::milliseconds::zero() 
)

Add all sections of a typed table into the packetizer.

Parameters
[in,out]duckTSDuck execution context.
[in]tableA table to packetize.
[in]repetition_rateRepetition rate of the sections in milliseconds. If zero, simply packetize sections one after the other.

◆ removeSections() [1/3]

void ts::CyclingPacketizer::removeSections ( TID  tid)

Remove all sections with the specified table id.

If one such section is currently being packetized, the rest of the section will be packetized.

Parameters
[in]tidThe table id of the sections to remove.

◆ removeSections() [2/3]

void ts::CyclingPacketizer::removeSections ( TID  tid,
uint16_t  tid_ext 
)

Remove all sections with the specified table id and table id extension.

If one such section is currently being packetized, the rest of the section will be packetized.

Parameters
[in]tidThe table id of the sections to remove.
[in]tid_extThe table id extension of the sections to remove.

◆ removeSections() [3/3]

void ts::CyclingPacketizer::removeSections ( TID  tid,
uint16_t  tid_ext,
uint8_t  sec_number 
)

Remove all sections with the specified table id, table id extension and section number.

If one such section is currently being packetized, the rest of the section will be packetized.

Parameters
[in]tidThe table id of the sections to remove.
[in]tid_extThe table id extension of the sections to remove.
[in]sec_numberThe section number of the sections to remove.

◆ removeAll()

void ts::CyclingPacketizer::removeAll ( )

Remove all sections in the packetizer.

If a section is currently being packetized, the rest of the section will be packetized.

◆ storedSectionCount()

SectionCounter ts::CyclingPacketizer::storedSectionCount ( ) const
inline

Get the number of stored sections to packetize.

Returns
The number of stored sections to packetize.

◆ atCycleBoundary()

bool ts::CyclingPacketizer::atCycleBoundary ( ) const

Check if the last generated packet was the last packet in the cycle.

Note that if the stuffing policy is NEVER, this is not reliable since it is unlikely that a packet actually terminates a cycle.

Returns
True when the last generated packet was the last packet in the cycle.

◆ reset()

virtual void ts::CyclingPacketizer::reset ( )
overridevirtual

Reset the packetizer.

All unfinished items (sections or PES packets) are dropped.

Reimplemented from ts::Packetizer.

◆ display()

virtual std::ostream & ts::CyclingPacketizer::display ( std::ostream &  strm) const
overridevirtual

Display the internal state of the packetizer, mainly for debug.

Parameters
[in,out]strmOutput text stream.
Returns
A reference to strm.

Reimplemented from ts::Packetizer.

◆ sectionProvider()

SectionProviderInterface * ts::Packetizer::sectionProvider ( ) const
inlineinherited

Get the object which provides MPEG sections when the packetizer needs a new section.

Returns
The object which will be called each time a section is required.

◆ atSectionBoundary()

bool ts::Packetizer::atSectionBoundary ( ) const
inlineinherited

Check if the packet stream is exactly at a section boundary.

Returns
True if the last returned packet contained the end of a section and no unfinished section.

◆ sectionCount()

SectionCounter ts::Packetizer::sectionCount ( ) const
inlineinherited

Get the number of completely packetized sections so far.

Returns
The number of completely packetized sections so far.

◆ allowHeaderSplit()

void ts::Packetizer::allowHeaderSplit ( bool  allow)
inlineinherited

Allow or disallow splitting section headers across TS packets.

By default, a Packetizer never splits a section header between two TS packets. This is not required by the MPEG standard but some STB are known to have problems with that.

Parameters
[in]allowIf true, splitting section headers across TS packets is allowed.

◆ headerSplitAllowed()

bool ts::Packetizer::headerSplitAllowed ( ) const
inlineinherited

Check if splitting section headers across TS packets is allowed.

Returns
True if splitting section headers across TS packets is allowed.

◆ getNextPacket()

virtual bool ts::Packetizer::getNextPacket ( TSPacket packet)
overridevirtualinherited

Build the next MPEG packet for the list of items (sections or PES) to pacjetize.

If there is nothing to packetize, generate a null packet on PID_NULL.

Parameters
[out]packetThe next TS packet.
Returns
True if a real packet is returned, false if a null packet was returned.

Implements ts::AbstractPacketizer.

◆ setPID()

void ts::AbstractPacketizer::setPID ( PID  pid)
inlineinherited

Set the default PID for subsequent MPEG packets.

Parameters
[in]pidPID for generated TS packets.

◆ getPID()

PID ts::AbstractPacketizer::getPID ( ) const
inlineinherited

Get the default PID for subsequent MPEG packets.

Returns
PID for generated TS packets.

◆ setNextContinuityCounter()

void ts::AbstractPacketizer::setNextContinuityCounter ( uint8_t  cc)
inlineinherited

Set the continuity counter value for next MPEG packet.

This counter is automatically incremented at each packet. It is usually never a good idea to change this, except maybe before generating the first packet if the continuity must be preserved with the previous content of the PID.

Parameters
[in]ccNext continuity counter.

◆ nextContinuityCounter()

uint8_t ts::AbstractPacketizer::nextContinuityCounter ( ) const
inlineinherited

Get the continuity counter value for next MPEG packet.

Returns
Next continuity counter.

◆ packetCount()

PacketCounter ts::AbstractPacketizer::packetCount ( ) const
inlineinherited

Get the number of generated TS packets so far.

Returns
The number of generated TS packets so far.

◆ report()

Report & ts::AbstractPacketizer::report ( ) const
inlineinherited

Get a reference to the debugging report.

Returns
A reference to the debugging report.

◆ duck()

const DuckContext & ts::AbstractPacketizer::duck ( ) const
inlineinherited

Get a reference to the TSDuck execution context.

Returns
A reference to the TSDuck execution context.

◆ configurePacket()

void ts::AbstractPacketizer::configurePacket ( TSPacket pkt,
bool  nullify 
)
protectedinherited

Configure a TS packet with continuity and PID.

Also increment the number of generated packet. So this method must be called exactly once per packet.

Parameters
[in,out]pktTS packet to configure
[in]nullifyReturn a null packet instead (no data to return for now).

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