Control the insertion points of TS packets in a stream based on various criteria.
More...
#include <tsPacketInsertionController.h>
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.
◆ PacketInsertionController()
Constructor.
- Parameters
-
[in] | report | Where to report verbose and debug messages. |
◆ 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] | rate | New 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] | rate | New 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] | packets | Number 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] | packets | Number 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_packets | Number 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] | packets | New 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] | percent | New 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] | name | The 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] | name | The new name to use. |
◆ DEFAULT_WAIT_ALERT
constexpr size_t ts::PacketInsertionController::DEFAULT_WAIT_ALERT = 16 |
|
staticconstexpr |
◆ DEFAULT_BITRATE_RESET_PERCENT
constexpr size_t ts::PacketInsertionController::DEFAULT_BITRATE_RESET_PERCENT = 10 |
|
staticconstexpr |
The documentation for this class was generated from the following file: