mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] introduce fraction lost into congestion control module
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
int64_t ConvertToNtpTime(int64_t time_us) {
|
||||
int64_t SystemClock::ConvertToNtpTime(int64_t time_us) {
|
||||
constexpr int64_t kMicrosecondsPerSecond = 1000000;
|
||||
constexpr uint64_t kNtpFractionalUnit = 0x100000000; // 2^32
|
||||
uint32_t seconds = static_cast<uint32_t>(time_us / kMicrosecondsPerSecond);
|
||||
@@ -120,3 +120,21 @@ int64_t SystemClock::CurrentUtcTimeMs() {
|
||||
int64_t SystemClock::CurrentUtcTime() {
|
||||
return CurrentUtcTimeNs() / 1000000000LL;
|
||||
}
|
||||
|
||||
int64_t SystemClock::NtpToUtc(int64_t ntp_time) {
|
||||
constexpr int64_t kNtpEpochOffset =
|
||||
2208988800LL; // NTP epoch starts at 1900-01-01, Unix epoch starts at
|
||||
// 1970-01-01
|
||||
constexpr int64_t kMicrosecondsPerSecond = 1000000;
|
||||
constexpr uint64_t kNtpFractionalUnit = 0x100000000; // 2^32
|
||||
|
||||
uint32_t seconds = static_cast<uint32_t>(ntp_time / kNtpFractionalUnit);
|
||||
uint32_t fractions = static_cast<uint32_t>(ntp_time % kNtpFractionalUnit);
|
||||
|
||||
int64_t unix_seconds = static_cast<int64_t>(seconds) - kNtpEpochOffset;
|
||||
int64_t microseconds =
|
||||
(static_cast<int64_t>(fractions) * kMicrosecondsPerSecond) /
|
||||
kNtpFractionalUnit;
|
||||
|
||||
return unix_seconds * kMicrosecondsPerSecond + microseconds;
|
||||
}
|
||||
@@ -29,6 +29,10 @@ class SystemClock {
|
||||
int64_t CurrentUtcTimeMs();
|
||||
int64_t CurrentUtcTimeUs();
|
||||
int64_t CurrentUtcTimeNs();
|
||||
|
||||
int64_t ConvertToNtpTime(int64_t time_us);
|
||||
|
||||
int64_t NtpToUtc(int64_t ntp_time);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user