MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
time.cpp File Reference
Include dependency graph for time.cpp:

Go to the source code of this file.

Functions

MXL_EXPORT uint64_t mxlGetCurrentIndex (mxlRational const *editRate)
MXL_EXPORT uint64_t mxlGetNsUntilIndex (uint64_t index, mxlRational const *editRate)
MXL_EXPORT uint64_t mxlGetTime ()
MXL_EXPORT uint64_t mxlIndexToTimestamp (mxlRational const *editRate, uint64_t index)
MXL_EXPORT void mxlSleepForNs (uint64_t ns)
MXL_EXPORT void mxlSleepUntil (uint64_t timestamp)
MXL_EXPORT uint64_t mxlTimestampToIndex (mxlRational const *editRate, uint64_t timestamp)

Function Documentation

◆ mxlGetCurrentIndex()

MXL_EXPORT uint64_t mxlGetCurrentIndex ( mxlRational const * editRate)

Get the current ringbuffer index based on the current system TAI time Index 0 is defined to be index at the beginning of the epoch as defined by SMPTE ST 2059

Parameters
[in]editRateThe edit rate of the Flow
Returns
The index or MXL_UNDEFINED_INDEX if editRate is null or invalid

Definition at line 18 of file time.cpp.

19{
20 if ((editRate == nullptr) || (editRate->denominator == 0) || (editRate->numerator == 0))
21 {
23 }
24
25 auto const now = mxlGetTime();
26 return now ? mxlTimestampToIndex(editRate, now) : MXL_UNDEFINED_INDEX;
27}
#define MXL_UNDEFINED_INDEX
Definition rational.h:17
auto const now
MXL_EXPORT uint64_t mxlTimestampToIndex(mxlRational const *editRate, uint64_t timestamp)
Definition time.cpp:31
MXL_EXPORT uint64_t mxlGetTime()
Definition time.cpp:11

◆ mxlGetNsUntilIndex()

MXL_EXPORT uint64_t mxlGetNsUntilIndex ( uint64_t index,
mxlRational const * editRate )

Utility method to help compute how many nanoseconds we need to wait until the beginning of the specified index

Parameters
[in]indexThe index to wait for
[in]editRateThe edit rate of the Flow
Returns
How many nanoseconds to wait or MXL_UNDEFINED_INDEX if editRate is null or invalid

Definition at line 50 of file time.cpp.

51{
52 // Validate the edit rate
53 if ((editRate == nullptr) || (editRate->denominator == 0) || (editRate->numerator == 0))
54 {
56 }
57
58 auto const targetNs = mxlIndexToTimestamp(editRate, index);
59 auto const nowNs = mxlGetTime();
60 return ((nowNs != 0ULL) && (targetNs >= nowNs)) ? targetNs - nowNs : 0ULL;
61}
uint64_t index
MXL_EXPORT uint64_t mxlIndexToTimestamp(mxlRational const *editRate, uint64_t index)
Definition time.cpp:38

◆ mxlGetTime()

MXL_EXPORT uint64_t mxlGetTime ( void )

Get the current time using the most appropriate clock for the platform.

Returns
The current time in nanoseconds since the epoch.

Definition at line 11 of file time.cpp.

12{
14}
auto const currentTime
Definition test_time.cpp:58

◆ mxlIndexToTimestamp()

MXL_EXPORT uint64_t mxlIndexToTimestamp ( mxlRational const * editRate,
uint64_t index )

Get the current timestamp based on the user provided index. Index 0 is defined to be index at the beginning of the epoch as defined by SMPTE ST 2059

Parameters
[in]editRateThe edit rate of the Flow
[in]indexThe index in the ringbuffer
Returns
The time stamp in nanoseconds since the epoch or MXL_UNDEFINED_INDEX if editRate is null or invalid

Definition at line 38 of file time.cpp.

39{
40 if (editRate != nullptr)
41 {
42 auto const res = mxl::lib::indexToTimestamp(*editRate, index);
43 return (res || (index == 0)) ? res.value : MXL_UNDEFINED_INDEX;
44 }
46}
constexpr Timepoint indexToTimestamp(mxlRational const &editRate, std::uint64_t index) noexcept

◆ mxlSleepForNs()

MXL_EXPORT void mxlSleepForNs ( uint64_t ns)

Sleep for a specific amount of time.

Parameters
[in]nsHow long to sleep for, in nanoseconds.

Definition at line 65 of file time.cpp.

66{
68}
Duration sleep(Duration duration, Clock clock=Clock::Realtime) noexcept
Definition Thread.cpp:33

◆ mxlSleepUntil()

MXL_EXPORT void mxlSleepUntil ( uint64_t timestamp)

Sleep until the specified timestamp is reached.

Parameters
[in]timestampThe time stamp in nanoseconds since the epoch.

Definition at line 72 of file time.cpp.

73{
75}
int sleepUntil(Timepoint timepoint, Clock clock=Clock::Realtime) noexcept
Definition Thread.cpp:56
auto const timestamp
Definition test_time.cpp:61

◆ mxlTimestampToIndex()

MXL_EXPORT uint64_t mxlTimestampToIndex ( mxlRational const * editRate,
uint64_t timestamp )

Get the current index based on the user provided timespec Index 0 is defined to be index at the beginning of the epoch as defined by SMPTE ST 2059

Parameters
[in]editRateThe edit rate of the Flow
[in]timestampThe time stamp in nanoseconds since the epoch.
Returns
The index or MXL_UNDEFINED_INDEX if editRate is null or invalid

Definition at line 31 of file time.cpp.

32{
33 return (editRate != nullptr) ? mxl::lib::timestampToIndex(*editRate, mxl::lib::Timepoint(timestamp)) : MXL_UNDEFINED_INDEX;
34}
constexpr std::uint64_t timestampToIndex(mxlRational const &editRate, Timepoint timestamp) noexcept