Add a way to read jitter in SteamNetConnectionRealTimeStatus_t

This commit is contained in:
Fletcher Dunn
2025-07-24 09:38:11 -07:00
parent 6dc062bea6
commit c1d3608c89
4 changed files with 35 additions and 1 deletions
+10 -1
View File
@@ -801,8 +801,17 @@ struct SteamNetConnectionRealTimeStatus_t
/// Nagle delay is ignored for the purposes of this calculation.
SteamNetworkingMicroseconds m_usecQueueTime;
/// Highest packet jitter experienced, since the last time this information
/// was returned. (The high water mark is cleared each time you fetch the info.)
///
/// - The units are microseconds, although the measurement precision is usually
/// not nearly this precise.
/// - A negative value means "no data available".
/// - Not all connections are able to measure jitter.
int32 m_usecMaxJitter;
// Internal stuff, room to change API easily
uint32 reserved[16];
uint32 reserved[15];
};
/// Quick status of a particular lane
@@ -1953,6 +1953,10 @@ EResult CSteamNetworkConnectionBase::APIGetRealTimeStatus( SteamNetConnectionRea
pStatus->m_flOutBytesPerSec = m_statsEndToEnd.m_sent.m_bytes.m_flRate;
pStatus->m_flInPacketsPerSec = m_statsEndToEnd.m_recv.m_packets.m_flRate;
pStatus->m_flInBytesPerSec = m_statsEndToEnd.m_recv.m_bytes.m_flRate;
// Max jitter, and clear it
pStatus->m_usecMaxJitter = m_statsEndToEnd.m_usecAPIRealtimeStatusMaxJitter;
m_statsEndToEnd.m_usecAPIRealtimeStatusMaxJitter = -1;
}
SNP_PopulateRealTimeStatus( pStatus, nLanes, pLanes, usecNow );
@@ -1077,6 +1077,10 @@ struct LinkStatsTrackerEndToEnd : public LinkStatsTrackerBase
/// Time when the current interval started
SteamNetworkingMicroseconds m_usecSpeedIntervalStart;
/// Jitter value that is returned in GetConnectionRealTimeStatus and then
/// cleared.
int m_usecAPIRealtimeStatusMaxJitter;
///// TX Speed, should match CMsgSteamDatagramLinkLifetimeStats
//int m_nTXSpeed;
//int m_nTXSpeedMax;
@@ -1169,6 +1173,22 @@ protected:
}
}
inline void InternalProcessJitterSample( int usecJitter )
{
LinkStatsTrackerBase::InternalProcessJitterSample( usecJitter );
// Update user high water mark.
//
// Use absolute value here...I think?
// If one packet is delayed and then the next packet arrives on time, the second
// jitter value will be negative, and both packets will be counted as bad, even
// though only the second one was. (Arriving early usually isn't a problem, it's
// arriving late that's bad). However, for the use cases for this is currently
// intended, it's OK. With any reasonable packet rate, we assume the app
// won't be checking this value fast enough for it to matter.
m_usecAPIRealtimeStatusMaxJitter = std::max( m_usecAPIRealtimeStatusMaxJitter, abs( usecJitter ) );
}
private:
void UpdateSpeedInterval( SteamNetworkingMicroseconds usecNow );
@@ -768,6 +768,7 @@ void LinkStatsTrackerEndToEnd::InitInternal( SteamNetworkingMicroseconds usecNow
m_usecWhenStartedConnectedState = 0;
m_usecWhenEndedConnectedState = 0;
m_usecAPIRealtimeStatusMaxJitter = -1;
//m_TXSpeedSample.Clear();
//m_nTXSpeed = 0;