Skip to content

Commit a246ee3

Browse files
committed
Add a way to read jitter in SteamNetConnectionRealTimeStatus_t
1 parent 725e273 commit a246ee3

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

include/steam/steamnetworkingtypes.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,17 @@ struct SteamNetConnectionRealTimeStatus_t
802802
/// Nagle delay is ignored for the purposes of this calculation.
803803
SteamNetworkingMicroseconds m_usecQueueTime;
804804

805+
/// Highest packet jitter experienced, since the last time this information
806+
/// was returned. (The high water mark is cleared each time you fetch the info.)
807+
///
808+
/// - The units are microseconds, although the measurement precision is usually
809+
/// not nearly this precise.
810+
/// - A negative value means "no data available".
811+
/// - Not all connections are able to measure jitter.
812+
int32 m_usecMaxJitter;
813+
805814
// Internal stuff, room to change API easily
806-
uint32 reserved[16];
815+
uint32 reserved[15];
807816
};
808817

809818
/// Quick status of a particular lane

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_connections.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,10 @@ EResult CSteamNetworkConnectionBase::APIGetRealTimeStatus( SteamNetConnectionRea
19531953
pStatus->m_flOutBytesPerSec = m_statsEndToEnd.m_sent.m_bytes.m_flRate;
19541954
pStatus->m_flInPacketsPerSec = m_statsEndToEnd.m_recv.m_packets.m_flRate;
19551955
pStatus->m_flInBytesPerSec = m_statsEndToEnd.m_recv.m_bytes.m_flRate;
1956+
1957+
// Max jitter, and clear it
1958+
pStatus->m_usecMaxJitter = m_statsEndToEnd.m_usecAPIRealtimeStatusMaxJitter;
1959+
m_statsEndToEnd.m_usecAPIRealtimeStatusMaxJitter = -1;
19561960
}
19571961
SNP_PopulateRealTimeStatus( pStatus, nLanes, pLanes, usecNow );
19581962

src/steamnetworkingsockets/steamnetworking_statsutils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,10 @@ struct LinkStatsTrackerEndToEnd : public LinkStatsTrackerBase
10771077
/// Time when the current interval started
10781078
SteamNetworkingMicroseconds m_usecSpeedIntervalStart;
10791079

1080+
/// Jitter value that is returned in GetConnectionRealTimeStatus and then
1081+
/// cleared.
1082+
int m_usecAPIRealtimeStatusMaxJitter;
1083+
10801084
///// TX Speed, should match CMsgSteamDatagramLinkLifetimeStats
10811085
//int m_nTXSpeed;
10821086
//int m_nTXSpeedMax;
@@ -1169,6 +1173,22 @@ struct LinkStatsTrackerEndToEnd : public LinkStatsTrackerBase
11691173
}
11701174
}
11711175

1176+
inline void InternalProcessJitterSample( int usecJitter )
1177+
{
1178+
LinkStatsTrackerBase::InternalProcessJitterSample( usecJitter );
1179+
1180+
// Update user high water mark.
1181+
//
1182+
// Use absolute value here...I think?
1183+
// If one packet is delayed and then the next packet arrives on time, the second
1184+
// jitter value will be negative, and both packets will be counted as bad, even
1185+
// though only the second one was. (Arriving early usually isn't a problem, it's
1186+
// arriving late that's bad). However, for the use cases for this is currently
1187+
// intended, it's OK. With any reasonable packet rate, we assume the app
1188+
// won't be checking this value fast enough for it to matter.
1189+
m_usecAPIRealtimeStatusMaxJitter = std::max( m_usecAPIRealtimeStatusMaxJitter, abs( usecJitter ) );
1190+
}
1191+
11721192
private:
11731193

11741194
void UpdateSpeedInterval( SteamNetworkingMicroseconds usecNow );

src/steamnetworkingsockets/steamnetworkingsockets_stats.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ void LinkStatsTrackerEndToEnd::InitInternal( SteamNetworkingMicroseconds usecNow
768768

769769
m_usecWhenStartedConnectedState = 0;
770770
m_usecWhenEndedConnectedState = 0;
771+
m_usecAPIRealtimeStatusMaxJitter = -1;
771772

772773
//m_TXSpeedSample.Clear();
773774
//m_nTXSpeed = 0;

0 commit comments

Comments
 (0)