TSDuck v3.45-4776
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TimeSourceTraits< T > Class Template Reference

Traits class for TimeSource values. More...

#include <tsTS.h>

Public Types

using Duration = cn::duration< std::intmax_t, std::ratio< 1, TICKS > >
 Definition of the time source as a std::chrono::duration type.
 

Static Public Member Functions

static uint64_t Add (uint64_t t, int64_t offset)
 Add a signed offset to a time stamp.
 
static int64_t Diff (uint64_t t1, uint64_t t2)
 Compute the difference between two time stamp values (t1 - t2).
 
static uint64_t Next (uint64_t last, PacketCounter distance, const BitRate &bitrate)
 Compute the time stamp of a packet, based on the equivalent time stamp of a previous packet.
 
static bool Sequenced (uint64_t t1, uint64_t t2)
 Check if two time stamps are in sequence.
 
static UString ToString (uint64_t t, bool hexa=true, bool decimal=true, bool ms=true)
 Convert a time stamp value to a string.
 
static bool Wrap (uint64_t t1, uint64_t t2)
 Check if time stamps t1 and t2 follow each othen, in any order, after wrap up.
 
static bool WrapUp (uint64_t t1, uint64_t t2)
 Check if time stamps t2 follows time t1 after wrap up.
 

Static Public Attributes

static constexpr size_t BIT_SIZE = TimeSourceSuperTraits<T>::BIT_SIZE
 Size in bits of the time source.
 
static constexpr size_t HEX_DIGITS = (BIT_SIZE + 3) / 4
 Number of required hexadecimal digits to represent the time source.
 
static constexpr uint64_t INVALID = 0xFFFFFFFFFFFFFFFF
 An invalid PTS and DTS value, can be used as a marker.
 
static constexpr uint64_t MAX = SCALE - 1
 The maximum possible value for the time source.
 
static constexpr uint64_t SCALE = TimeSourceSuperTraits<T>::SCALE
 Scale factor for the modular time source.
 
static constexpr uint64_t TICKS = TimeSourceSuperTraits<T>::TICKS
 Clock frequency in Hz for the time source.
 
static constexpr TimeSource TYPE = T
 Redefine the time source type as a local declaration.
 
static constexpr uint64_t WRAPUP_THRESHOLD = (4 * SCALE) / 5
 Minimum distance between two time stamp values to consider them as wrapping up after the maximum value.
 

Detailed Description

template<TimeSource T>
class ts::TimeSourceTraits< T >

Traits class for TimeSource values.

The traits class is generic, based on a specialization of TimeSourceSuperTraits.

Member Function Documentation

◆ WrapUp()

template<TimeSource T>
static bool ts::TimeSourceTraits< T >::WrapUp ( uint64_t  t1,
uint64_t  t2 
)
inlinestatic

Check if time stamps t2 follows time t1 after wrap up.

Parameters
[in]t1First time value.
[in]t2Second time value.
Returns
True if t2 is probably following t1 after wrapping up. The exact criteria is that t2 wraps up after t1 and their distance is within 20% of a full time source range.

◆ Wrap()

template<TimeSource T>
static bool ts::TimeSourceTraits< T >::Wrap ( uint64_t  t1,
uint64_t  t2 
)
inlinestatic

Check if time stamps t1 and t2 follow each othen, in any order, after wrap up.

Parameters
[in]t1First time value.
[in]t2Second time value.
Returns
True if t1 and t2 follow each othen, in any order, after wrap up.

◆ Sequenced()

template<TimeSource T>
static bool ts::TimeSourceTraits< T >::Sequenced ( uint64_t  t1,
uint64_t  t2 
)
inlinestatic

Check if two time stamps are in sequence.

Sample application: In MPEG video, B-frames are transported out-of-sequence. Their PTS is typically lower than the previous D-frame or I-frame in the transport. A "sequenced" PTS is one that is higher than the previous sequenced PTS (with possible wrap up).

Parameters
[in]t1First time value.
[in]t2Second time value.
Returns
True if t1 and t2 follow each othen, possibly after wrapping up at 2**33.

◆ Next()

template<ts::TimeSource T>
uint64_t ts::TimeSourceTraits< T >::Next ( uint64_t  last,
PacketCounter  distance,
const BitRate bitrate 
)
static

Compute the time stamp of a packet, based on the equivalent time stamp of a previous packet.

Parameters
[in]lastTime stamp in a previous packet.
[in]distanceNumber of TS packets since the packet with last.
[in]bitrateConstant bitrate of the stream in bits per second.
Returns
The time stamp of the packet which is at the specified distance from the packet with last or INVALID if a parameter is incorrect.

◆ Add()

template<ts::TimeSource T>
uint64_t ts::TimeSourceTraits< T >::Add ( uint64_t  t,
int64_t  offset 
)
static

Add a signed offset to a time stamp.

Parameters
[in]tInitial time value.
[in]offsetSigned offset.
Returns
The adjusted time value or INVALID if a parameter is incorrect.

◆ Diff()

template<ts::TimeSource T>
int64_t ts::TimeSourceTraits< T >::Diff ( uint64_t  t1,
uint64_t  t2 
)
static

Compute the difference between two time stamp values (t1 - t2).

Parameters
[in]t1First time value.
[in]t2Second time value.
Returns
The difference between the two values or INVALID if a parameter is incorrect.

◆ ToString()

template<ts::TimeSource T>
ts::UString ts::TimeSourceTraits< T >::ToString ( uint64_t  t,
bool  hexa = true,
bool  decimal = true,
bool  ms = true 
)
static

Convert a time stamp value to a string.

Parameters
[in]tThe time value.
[in]hexaIf true (the defaul), include hexadecimal value.
[in]decimalIf true (the defaul), include decimal value.
[in]msIf true (the defaul), include the equivalent duration in milliseconds.
Returns
The formatted string.

Member Data Documentation

◆ WRAPUP_THRESHOLD

template<TimeSource T>
constexpr uint64_t ts::TimeSourceTraits< T >::WRAPUP_THRESHOLD = (4 * SCALE) / 5
staticconstexpr

Minimum distance between two time stamp values to consider them as wrapping up after the maximum value.

Because time sources are modular values, they wrap up after MAX. It is common to consider, for instance, that value 4 "follows" MAX-4, even though 4 < MAX-4. The exact criteria is that two time stamp values are considered as following each other if their distance is within 20% of a full time source range.


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