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

Control the insertion points of TS packets in a stream based on various criteria. More...

#include <tsPacketInsertionController.h>

Public Member Functions

 PacketInsertionController (Report &report=(ts::NullReport::Instance()))
 Constructor.
 
BitRate currentMainBitRate () const
 Get current bitrate of the main transport stream.
 
BitRate currentSubBitRate () const
 Get current bitrate of the sub-stream.
 
void declareMainPackets (size_t packets)
 Count packets in the main transport stream.
 
void declareSubPackets (size_t packets)
 Count packets in the sub-stream.
 
bool mustInsert (size_t waiting_packets=1)
 Check if a packet from the sub-stream shall be inserted at the current position in the main transport stream.
 
void reset ()
 Reset the state of the controller.
 
void setBitRateVariationResetThreshold (size_t percent)
 Set a reset threshold for bitrate variation.
 
void setMainBitRate (const BitRate &rate)
 Declare a new value for the bitrate of the main transport stream.
 
void setMainStreamName (const UString &name)
 Set a name for the main stream (only for debug messages).
 
void setSubBitRate (const BitRate &rate)
 Declare a new value for the bitrate of the sub-stream.
 
void setSubStreamName (const UString &name)
 Set a name for the sub-stream (only for debug messages).
 
void setWaitPacketsAlertThreshold (size_t packets)
 Set an alert threshold to waiting packets.
 

Static Public Attributes

static constexpr size_t DEFAULT_BITRATE_RESET_PERCENT = 10
 Default reset threshold for bitrate variation (percentage).
 
static constexpr size_t DEFAULT_WAIT_ALERT = 16
 Default alert threshold for packets waiting from the sub-stream.
 

Detailed Description

Control the insertion points of TS packets in a stream based on various criteria.

The scenarion is the following:

  • The main transport stream has some known bitrate.
  • A sub-stream shall be inserted in the main stream (one PID, a merged TS, whatever).
  • The sub-stream has a known target bitrate inside the main stream.
  • We count packets in the main TS.
  • We want to know when we should insert packets from the sub-stream inside the main stream.

Constructor & Destructor Documentation

◆ PacketInsertionController()

ts::PacketInsertionController::PacketInsertionController ( Report report = (ts::NullReport::Instance()))

Constructor.

Parameters
[in]reportWhere to report verbose and debug messages.

Member Function Documentation

◆ reset()

void ts::PacketInsertionController::reset ( )

Reset the state of the controller.

The packet counters are reset. The last bitrates and stream names are retained.

◆ setMainBitRate()

void ts::PacketInsertionController::setMainBitRate ( const BitRate rate)

Declare a new value for the bitrate of the main transport stream.

Parameters
[in]rateNew bitrate value. Zero means unknown bitrate.

◆ setSubBitRate()

void ts::PacketInsertionController::setSubBitRate ( const BitRate rate)

Declare a new value for the bitrate of the sub-stream.

Parameters
[in]rateNew bitrate value. Zero means unknown bitrate.

◆ currentMainBitRate()

BitRate ts::PacketInsertionController::currentMainBitRate ( ) const
inline

Get current bitrate of the main transport stream.

Returns
Current bitrate of the main transport stream.

◆ currentSubBitRate()

BitRate ts::PacketInsertionController::currentSubBitRate ( ) const
inline

Get current bitrate of the sub-stream.

Returns
Current bitrate of the sub-stream.

◆ declareMainPackets()

void ts::PacketInsertionController::declareMainPackets ( size_t  packets)
inline

Count packets in the main transport stream.

This method must be called each time packets pass through the main transport stream. This includes packets which are replaced with content from the sub-stream.

Parameters
[in]packetsNumber of passed packets in the main transport stream.

◆ declareSubPackets()

void ts::PacketInsertionController::declareSubPackets ( size_t  packets)
inline

Count packets in the sub-stream.

This method must be called each time packets from the main transport stream are replaced with content from the sub-stream.

Parameters
[in]packetsNumber of packets which are replaced with content from the sub-stream.

◆ mustInsert()

bool ts::PacketInsertionController::mustInsert ( size_t  waiting_packets = 1)

Check if a packet from the sub-stream shall be inserted at the current position in the main transport stream.

Parameters
[in]waiting_packetsNumber of packets waiting to be inserted. This value is used only when greater than 1. In that case, it indicates that a real-time source is providing packets in bursts. If the bursts are too important, then packet insertion is temporarily accelerated to avoid overflow.
Returns
True if it is appropriate to insert a packet from the sub-stream here, false otherwise. Always return true if any bitrate, main stream or sub-stream, is ignored (zero).
See also
setWaitPacketsAlertThreshold()

◆ setWaitPacketsAlertThreshold()

void ts::PacketInsertionController::setWaitPacketsAlertThreshold ( size_t  packets)
inline

Set an alert threshold to waiting packets.

When the number of current packets waiting to be inserted from the sub-stream becomes higher than the specified alert threshold, the insertion rate is temporarily accelerated to avoid overflow. When the sub-stream is correctly regulated on average but regularly bursts, the waiting packets threshold should be at least the burst size to keep a smooth insertion.

This parameter is used to make sure that 1) bursts do not affect the insertion rythm and 2) overflows are smoothly absorbed.

The initial default threshold is DEFAULT_WAIT_ALERT packets.

Parameters
[in]packetsNew alert threshold, in number of packets. When set to zero, no acceleration is performed.
See also
mustInsert()

◆ setBitRateVariationResetThreshold()

void ts::PacketInsertionController::setBitRateVariationResetThreshold ( size_t  percent)

Set a reset threshold for bitrate variation.

The bitrate, main stream or sub-stream, may vary. The actual bitrate which is used in computations is the average of all previously specified bitrate values. But if a bitrate suddenly varies from this average value by more than a given percentage, the average is reset to the new value. When the bitrate is reset that way, the insertion computation restarts.

The initial default threshold is DEFAULT_BITRATE_RESET_PERCENT.

Parameters
[in]percentNew percentage threshold (0 to 100).

◆ setMainStreamName()

void ts::PacketInsertionController::setMainStreamName ( const UString name)
inline

Set a name for the main stream (only for debug messages).

Parameters
[in]nameThe new name to use.

◆ setSubStreamName()

void ts::PacketInsertionController::setSubStreamName ( const UString name)
inline

Set a name for the sub-stream (only for debug messages).

Parameters
[in]nameThe new name to use.

Member Data Documentation

◆ DEFAULT_WAIT_ALERT

constexpr size_t ts::PacketInsertionController::DEFAULT_WAIT_ALERT = 16
staticconstexpr

Default alert threshold for packets waiting from the sub-stream.

See also
setWaitPacketsAlertThreshold()

◆ DEFAULT_BITRATE_RESET_PERCENT

constexpr size_t ts::PacketInsertionController::DEFAULT_BITRATE_RESET_PERCENT = 10
staticconstexpr

Default reset threshold for bitrate variation (percentage).

See also
setBitRateVariationResetThreshold()

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