Skip to content

Commit

Permalink
[core] Renamed TSBPD class functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Oct 14, 2024
1 parent 2c199e9 commit e2f133b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions srtcore/buffer_rcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,12 +1096,12 @@ void CRcvBuffer::applyGroupDrift(const steady_clock::time_point& timebase,

CRcvBuffer::time_point CRcvBuffer::getTsbPdTimeBase(uint32_t usPktTimestamp) const
{
return m_tsbpd.getTsbPdTimeBase(usPktTimestamp);
return m_tsbpd.getBaseTime(usPktTimestamp);
}

void CRcvBuffer::updateTsbPdTimeBase(uint32_t usPktTimestamp)
{
m_tsbpd.updateTsbPdTimeBase(usPktTimestamp);
m_tsbpd.updateBaseTime(usPktTimestamp);
}

string CRcvBuffer::strFullnessState(int iFirstUnackSeqNo, const time_point& tsNow) const
Expand All @@ -1125,7 +1125,7 @@ string CRcvBuffer::strFullnessState(int iFirstUnackSeqNo, const time_point& tsNo
{
ss << ", timespan ";
const uint32_t usPktTimestamp = packetAt(iLastPos).getMsgTimeStamp();
ss << count_milliseconds(m_tsbpd.getPktTsbPdTime(usPktTimestamp) - nextValidPkt.tsbpd_time);
ss << count_milliseconds(m_tsbpd.getPktTime(usPktTimestamp) - nextValidPkt.tsbpd_time);
ss << " ms";
}
}
Expand All @@ -1142,7 +1142,7 @@ string CRcvBuffer::strFullnessState(int iFirstUnackSeqNo, const time_point& tsNo

CRcvBuffer::time_point CRcvBuffer::getPktTsbPdTime(uint32_t usPktTimestamp) const
{
return m_tsbpd.getPktTsbPdTime(usPktTimestamp);
return m_tsbpd.getPktTime(usPktTimestamp);
}

/* Return moving average of acked data pkts, bytes, and timespan (ms) of the receive buffer */
Expand Down
24 changes: 12 additions & 12 deletions srtcore/tsbpd_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool CTsbpdTime::addDriftSample(uint32_t usPktTimestamp, const time_point& tsPkt
// is to estimate RTT change and assume that the change of the one way network delay is
// approximated by the half of the RTT change.
const duration tdRTTDelta = usRTTSample >= 0 ? microseconds_from((usRTTSample - m_iFirstRTT) / 2) : duration(0);
const time_point tsPktBaseTime = getPktTsbPdBaseTimeNoLock(usPktTimestamp);
const time_point tsPktBaseTime = getPktBaseTimeNoLock(usPktTimestamp);
const steady_clock::duration tdDrift = tsPktArrival - tsPktBaseTime - tdRTTDelta;

const bool updated = m_DriftTracer.update(count_microseconds(tdDrift));
Expand Down Expand Up @@ -210,42 +210,42 @@ void CTsbpdTime::applyGroupDrift(const steady_clock::time_point& timebase,
m_DriftTracer.forceDrift(count_microseconds(udrift));
}

CTsbpdTime::time_point CTsbpdTime::getTsbPdTimeBaseNoLock(uint32_t timestamp_us) const
CTsbpdTime::time_point CTsbpdTime::getBaseTimeNoLock(uint32_t timestamp_us) const
{
// A data packet within [TSBPD_WRAP_PERIOD; 2 * TSBPD_WRAP_PERIOD] would end TSBPD wrap-aware state.
// Some incoming control packets may not update the TSBPD base (calling updateTsbPdTimeBase(..)),
// Some incoming control packets may not update the TSBPD base (calling updateBaseTime(..)),
// but may come before a data packet with a timestamp in this range. Therefore the whole range should be tracked.
const int64_t carryover_us =
(m_bTsbPdWrapCheck && timestamp_us <= 2 * TSBPD_WRAP_PERIOD) ? int64_t(CPacket::MAX_TIMESTAMP) + 1 : 0;

return (m_tsTsbPdTimeBase + microseconds_from(carryover_us));
}

CTsbpdTime::time_point CTsbpdTime::getTsbPdTimeBase(uint32_t timestamp_us) const
CTsbpdTime::time_point CTsbpdTime::getBaseTime(uint32_t timestamp_us) const
{
SharedLock lck(m_mtxRW);
return getTsbPdTimeBaseNoLock(timestamp_us);
return getBaseTimeNoLock(timestamp_us);
}

CTsbpdTime::time_point CTsbpdTime::getPktTsbPdTime(uint32_t usPktTimestamp) const
CTsbpdTime::time_point CTsbpdTime::getPktTime(uint32_t usPktTimestamp) const
{
SharedLock lck(m_mtxRW);
time_point value = getPktTsbPdBaseTimeNoLock(usPktTimestamp) + m_tdTsbPdDelay + microseconds_from(m_DriftTracer.drift());
time_point value = getPktBaseTimeNoLock(usPktTimestamp) + m_tdTsbPdDelay + microseconds_from(m_DriftTracer.drift());

return value;
}

CTsbpdTime::time_point CTsbpdTime::getPktTsbPdBaseTimeNoLock(uint32_t usPktTimestamp) const
CTsbpdTime::time_point CTsbpdTime::getPktBaseTimeNoLock(uint32_t usPktTimestamp) const
{
return getTsbPdTimeBaseNoLock(usPktTimestamp) + microseconds_from(usPktTimestamp);
return getBaseTimeNoLock(usPktTimestamp) + microseconds_from(usPktTimestamp);
}

CTsbpdTime::time_point CTsbpdTime::getPktTsbPdBaseTime(uint32_t usPktTimestamp) const
CTsbpdTime::time_point CTsbpdTime::getPktBaseTime(uint32_t usPktTimestamp) const
{
return getTsbPdTimeBase(usPktTimestamp) + microseconds_from(usPktTimestamp);
return getBaseTime(usPktTimestamp) + microseconds_from(usPktTimestamp);
}

void CTsbpdTime::updateTsbPdTimeBase(uint32_t usPktTimestamp)
void CTsbpdTime::updateBaseTime(uint32_t usPktTimestamp)
{
ExclusiveLock lck(m_mtxRW);
if (m_bTsbPdWrapCheck)
Expand Down
20 changes: 10 additions & 10 deletions srtcore/tsbpd_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,31 @@ class CTsbpdTime
/// When packet timestamp approaches CPacket::MAX_TIMESTAMP, the TSBPD base time should be
/// shifted accordingly to correctly handle new packets with timestamps starting from zero.
/// @param usPktTimestamp timestamp field value of a data packet.
void updateTsbPdTimeBase(uint32_t usPktTimestamp);
void updateBaseTime(uint32_t usPktTimestamp);

/// @brief Get TSBPD base time adjusted for carryover, which occurs when
/// a packet's timestamp exceeds the UINT32_MAX and continues from zero.
/// @param [in] usPktTimestamp 32-bit value of packet timestamp field (microseconds).
///
/// @return TSBPD base time for a provided packet timestamp.
time_point getTsbPdTimeBase(uint32_t usPktTimestamp) const;
time_point getBaseTime(uint32_t usPktTimestamp) const;

/// @brief Get packet TSBPD time without buffering delay and clock drift, which is
/// the target time for delivering the packet to an upstream application.
/// Essentially: getTsbPdTimeBase(usPktTimestamp) + usPktTimestamp
/// Essentially: getBaseTime(usPktTimestamp) + usPktTimestamp
/// @param [in] usPktTimestamp 32-bit value of packet timestamp field (microseconds).
///
/// @return Packet TSBPD base time without buffering delay.
time_point getPktTsbPdBaseTime(uint32_t usPktTimestamp) const;
time_point getPktBaseTime(uint32_t usPktTimestamp) const;

/// @brief Get packet TSBPD time with buffering delay and clock drift, which is
/// the target time for delivering the packet to an upstream application
/// (including drift and carryover effects, if any).
/// Essentially: getPktTsbPdBaseTime(usPktTimestamp) + m_tdTsbPdDelay + drift()
/// Essentially: getPktBaseTime(usPktTimestamp) + m_tdTsbPdDelay + drift()
/// @param [in] usPktTimestamp 32-bit value of packet timestamp field (microseconds).
///
/// @return Packet TSBPD time with buffering delay.
time_point getPktTsbPdTime(uint32_t usPktTimestamp) const;
time_point getPktTime(uint32_t usPktTimestamp) const;

/// @brief Get current drift value.
/// @return current drift value.
Expand All @@ -123,16 +123,16 @@ class CTsbpdTime
/// @param [in] usPktTimestamp 32-bit value of packet timestamp field (microseconds).
///
/// @return TSBPD base time for a provided packet timestamp.
time_point getTsbPdTimeBaseNoLock(uint32_t usPktTimestamp) const;
time_point getBaseTimeNoLock(uint32_t usPktTimestamp) const;

/// @brief Get packet TSBPD time without buffering delay and clock drift, which is
/// the target time for delivering the packet to an upstream application.
/// Essentially: getTsbPdTimeBase(usPktTimestamp) + usPktTimestamp
/// Essentially: getBaseTime(usPktTimestamp) + usPktTimestamp
/// Does not lock the internal state.
/// @param [in] usPktTimestamp 32-bit value of packet timestamp field (microseconds).
///
/// @return Packet TSBPD base time without buffering delay.
time_point getPktTsbPdBaseTimeNoLock(uint32_t usPktTimestamp) const;
time_point getPktBaseTimeNoLock(uint32_t usPktTimestamp) const;


int m_iFirstRTT; // First measured RTT sample.
Expand All @@ -143,7 +143,7 @@ class CTsbpdTime
/// @note m_tsTsbPdTimeBase is changed in the following cases:
/// 1. Initialized upon SRT_CMD_HSREQ packet as the difference with the current time:
/// = (NOW - PACKET_TIMESTAMP), at the time of HSREQ reception.
/// 2. Shifted forward on timestamp overflow (@see CTsbpdTime::updateTsbPdTimeBase), when overflow
/// 2. Shifted forward on timestamp overflow (@see CTsbpdTime::updateBaseTime), when overflow
/// of the timestamp field value of a data packet is detected.
/// += CPacket::MAX_TIMESTAMP + 1
/// 3. Clock drift (@see CTsbpdTime::addDriftSample, executed exclusively
Expand Down

0 comments on commit e2f133b

Please sign in to comment.