TSDuck Version 3.32-2769 (TSDuck - The MPEG Transport Stream Toolkit)
ts::TSSpeedMetrics Class Reference

TS processing speed metrics evaluation. More...

Public Member Functions

 TSSpeedMetrics (PacketCounter packets=MIN_PACKET_PER_INTERVAL, NanoSecond nanosecs=MIN_NANOSEC_PER_INTERVAL, size_t intervals=INTERVAL_COUNT)
 Constructor. More...
 
BitRate bitrate () const
 Get the evaluated processing bitrate in bits/second based on 188-byte packets. More...
 
bool processedPacket (PacketCounter count=1)
 Report the processing of some TS packets by the application. More...
 
NanoSecond sessionNanoSeconds () const
 Get the duration of the session, since start(), in nanoseconds. More...
 
void start ()
 Start a new processing time session.
 

Static Public Attributes

static const size_t INTERVAL_COUNT = 20
 Default number of intervals in the sliding window of bitrate computation. More...
 
static const NanoSecond MIN_NANOSEC_PER_INTERVAL = 100 * NanoSecPerMilliSec
 Default minimum number of nanoseconds per interval. More...
 
static const PacketCounter MIN_PACKET_PER_INTERVAL = 100
 Default minimum packets to accumulate per interval. More...
 

Detailed Description

TS processing speed metrics evaluation.

An instance of this class evaluates the reading or processing speed of a TS. This is different from the TS bitrate, as evaluated by the class PCRAnalyzer, when the TS is not a live one but a file for instance.

This class is useful to perform actions at regular intervals, based on wall clock time, not TS clock. Instead of checking the system time at every packet, which is far from efficient, an application can predict an average number of packets to process before performing the repetitive action.

Warning: The processing speed of the TS is typically not stable. Buffer sizes impact the latency for instance. As well as any external factor in the operating system. So, predictions on packet distance are only hints at best. This class shall be considered as an optimization on the number of times the system time is probed, not a precise prediction.

Principle of operation:

  • We work on a monotonic clock and we count packets.
  • We compute an "current" processing bitrate, not an average bitrate from the beginning.
  • The bitrate is computed over the last period of at least 2 seconds and at least 2000 packets (default values).
  • This "current period" is in fact made of a sliding windows of 20 elementary interval. Each interval must extend over at least 100 packets and 100 milliseconds.

Constructor & Destructor Documentation

◆ TSSpeedMetrics()

ts::TSSpeedMetrics::TSSpeedMetrics ( PacketCounter  packets = MIN_PACKET_PER_INTERVAL,
NanoSecond  nanosecs = MIN_NANOSEC_PER_INTERVAL,
size_t  intervals = INTERVAL_COUNT 
)

Constructor.

Parameters
[in]packetsMinimum packets to accumulate per interval.
[in]nanosecsMinimum number of nanoseconds per interval.
[in]intervalsMax number of sliding time intervals.

Member Function Documentation

◆ processedPacket()

bool ts::TSSpeedMetrics::processedPacket ( PacketCounter  count = 1)

Report the processing of some TS packets by the application.

Parameters
[in]countNumber of processed packets, one by default.
Returns
True if we just fetched the value of the clock.

◆ bitrate()

BitRate ts::TSSpeedMetrics::bitrate ( ) const

Get the evaluated processing bitrate in bits/second based on 188-byte packets.

Returns
The evaluated TS bitrate in bits/second or zero if not available.

◆ sessionNanoSeconds()

NanoSecond ts::TSSpeedMetrics::sessionNanoSeconds ( ) const
inline

Get the duration of the session, since start(), in nanoseconds.

The value is the most precise when processedPacket() just returned true.

Returns
The duration of the session, since start(), in nanoseconds.

Member Data Documentation

◆ MIN_PACKET_PER_INTERVAL

const PacketCounter ts::TSSpeedMetrics::MIN_PACKET_PER_INTERVAL = 100
static

Default minimum packets to accumulate per interval.

See the description of the class.

◆ MIN_NANOSEC_PER_INTERVAL

const NanoSecond ts::TSSpeedMetrics::MIN_NANOSEC_PER_INTERVAL = 100 * NanoSecPerMilliSec
static

Default minimum number of nanoseconds per interval.

See the description of the class.

◆ INTERVAL_COUNT

const size_t ts::TSSpeedMetrics::INTERVAL_COUNT = 20
static

Default number of intervals in the sliding window of bitrate computation.

See the description of the class.


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