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

TS processing speed metrics evaluation. More...

#include <tsTSSpeedMetrics.h>

Public Member Functions

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

Static Public Attributes

static constexpr size_t INTERVAL_COUNT = 20
 Default number of intervals in the sliding window of bitrate computation.
 
static constexpr cn::nanoseconds MIN_NANOSEC_PER_INTERVAL = cn::milliseconds(100)
 Default minimum number of nanoseconds per interval.
 
static constexpr PacketCounter MIN_PACKET_PER_INTERVAL = 100
 Default minimum packets to accumulate per interval.
 

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,
cn::nanoseconds  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()

cn::nanoseconds 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

constexpr PacketCounter ts::TSSpeedMetrics::MIN_PACKET_PER_INTERVAL = 100
staticconstexpr

Default minimum packets to accumulate per interval.

See the description of the class.

◆ MIN_NANOSEC_PER_INTERVAL

constexpr cn::nanoseconds ts::TSSpeedMetrics::MIN_NANOSEC_PER_INTERVAL = cn::milliseconds(100)
staticconstexpr

Default minimum number of nanoseconds per interval.

See the description of the class.

◆ INTERVAL_COUNT

constexpr size_t ts::TSSpeedMetrics::INTERVAL_COUNT = 20
staticconstexpr

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: