11#ifndef GAMP_AV_PTS_HPP_
12#define GAMP_AV_PTS_HPP_
71 : m_speed(std::move(speed)), m_scr(
scr), m_pts(pts)
97 float getSpeed() const noexcept {
return m_speed(); }
104 void set(uint64_t
scr, uint32_t pts)
noexcept {
109 void setPTS(uint32_t pts)
noexcept { m_pts = pts; }
111 void setSCR(uint64_t currentMillis)
noexcept { m_scr = currentMillis; }
120 m_pts = other.last();
132 const float dpts =
static_cast<float>( currentMillis - m_scr ) * m_speed() + 0.5f;
133 return m_pts +
static_cast<uint32_t
>( dpts );
139 std::string
getTimeStr(uint64_t currentMillis,
bool addFractions) {
145 return m_pts - rhs.last();
150 return get(currentMillis) - rhs.get(currentMillis);
153 std::string
toString() noexcept {
return std::to_string(m_pts); }
155 std::string
toString(uint64_t currentMillis)
noexcept {
return "last "+std::to_string(m_pts)+
" ms, current "+std::to_string(
get(currentMillis))+
" ms"; }
163 std::string
toTimeStr(uint64_t millis,
bool addFractions)
const noexcept {
164 using namespace std::chrono;
165 milliseconds ms(millis);
166 seconds sec = duration_cast<seconds>(ms);
167 ms -= duration_cast<milliseconds>(sec);
168 minutes m = duration_cast<minutes>(sec);
169 sec -= duration_cast<seconds>(m);
170 hours h = duration_cast<hours>(m);
171 m -= duration_cast<minutes>(h);
174 if( 0 < h.count() ) {
180 if( 0 < h.count() ) {
194 using namespace std::chrono;
195 milliseconds ms(millis);
196 seconds sec = duration_cast<seconds>(ms);
197 ms -= duration_cast<milliseconds>(sec);
198 minutes m = duration_cast<minutes>(sec);
199 sec -= duration_cast<seconds>(m);
200 hours h = duration_cast<hours>(m);
201 m -= duration_cast<minutes>(h);
209 static uint32_t
toMillis(
const std::string& datestr)
noexcept;
std::string toString() noexcept
std::string toTimeStr(uint64_t millis)
Returns a full time string representation 'HH:mm:ss.SSS'.
uint32_t getCurrent() const noexcept
Returns get(long) passing Clock#currentMillis().
jau::function< float()> FloatValue
An external float value getter.
void set(const PTS &other) noexcept
Updates the PTS value with values from other PTS instance.
constexpr_atomic uint64_t scr() const noexcept
Returns the System Clock Reference (SCR) in milliseconds of last PTS update via set(long,...
std::string getTimeStr(uint64_t currentMillis, bool addFractions)
Returns get(long) as time string representation via toTimeStr(long, boolean).
PTS(FloatValue speed, uint64_t scr, uint32_t pts) noexcept
Create new instance.
void set(uint64_t scr, uint32_t pts) noexcept
Updates the PTS value with given System Clock Reference (SCR) in milliseconds.
std::string toString(uint64_t currentMillis) noexcept
constexpr_atomic uint32_t diff(uint64_t currentMillis, const PTS &rhs) const noexcept
Returns get(long) - rhs.
constexpr_atomic bool isEOS() const noexcept
Returns true if getLast() equals to TimeFrameI#END_OF_STREAM_PTS, indicating end of stream (EOS).
static uint32_t toMillis(const std::string &datestr) noexcept
Returns milliseconds from given string representation in '[H[H]:]m[m]:s[s][.S*]'.
std::string toTimeStr(uint64_t millis, bool addFractions) const noexcept
Returns a time string representation '[HH:]mm:ss[.SSS]', dropping unused hour quantities and fraction...
void setSCR(uint64_t currentMillis) noexcept
Sets the System Clock Reference (SCR) in milliseconds of last PTS update, see set(long,...
void setPTS(uint32_t pts) noexcept
Sets the PTS value, see set(long, int).
constexpr_atomic bool isValid() const noexcept
Returns true if getLast() is unequal to TimeFrameI#INVALID_PTS.
std::string getLastTimeStr(bool addFractions) const noexcept
Returns getLast() as time string representation via toTimeStr(long, boolean).
std::string getSCRTimeStr(bool addFractions) const noexcept
Returns scr() as time string representation via toTimeStr(long, boolean).
PTS(FloatValue speed) noexcept
Create new instance, initializing pts with TimeFrameI#INVALID_PTS and system-clock timestamp with zer...
float getSpeed() const noexcept
Returns the external playback speed.
constexpr_atomic uint32_t get(uint64_t currentMillis) const noexcept
Returns the last() updated PTS, interpolated by scr() System Clock Reference (SCR) delta to given cur...
constexpr_atomic uint32_t last() const noexcept
Returns the last updated PTS value via set(long, int) w/o System Clock Reference (SCR) interpolation.
constexpr_atomic uint32_t diffLast(const PTS &rhs) const noexcept
Returns getLast() - rhs.
static constexpr uint32_t END_OF_STREAM_PTS
Constant marking the end of the stream PTS, i.e.
static constexpr uint32_t INVALID_PTS
Constant marking an invalid (or undefined) PTS, i.e.
Class template jau::function is a general-purpose static-polymorphic function wrapper.
ordered_atomic< uint64_t, std::memory_order_relaxed > relaxed_atomic_uint64
Relaxed non-SC atomic integral scalar uint64_t.
ordered_atomic< uint32_t, std::memory_order_relaxed > relaxed_atomic_uint32
Relaxed non-SC atomic integral scalar uint32_t.
#define constexpr_atomic
Used when designed to declare a function constexpr, but prohibited by its specific implementation.
constexpr std::string format_string_n(const std::size_t maxStrLen, const std::string_view &format, const Args &...args)
Returns a (potentially truncated) string according to snprintf() formatting rules and variable number...
uint64_t getCurrentMilliseconds() noexcept
Returns current monotonic time in milliseconds.