You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
1.0 KiB
24 lines
1.0 KiB
#pragma once |
|
#include <algorithm> |
|
#include <cstdint> |
|
|
|
// Десять секундных интервалов. Время передаёт аудиопоток из монотонных часов. |
|
struct call_jitter_window { |
|
struct bucket { int64_t second = -1; int low = 0, high = 0; } buckets[10]; |
|
int low = 0, high = 0, reserve = 60; |
|
int max_reserve = 1000; |
|
bool observe(int64_t now_ms, int depth) { |
|
int64_t second = now_ms / 1000; |
|
auto& b = buckets[second % 10]; |
|
bool changed_second = b.second != second; |
|
if (changed_second) { b.second = second; b.low = b.high = depth; } |
|
else { b.low = std::min(b.low, depth); b.high = std::max(b.high, depth); } |
|
low = high = depth; |
|
for (const auto& item : buckets) { |
|
if (item.second < 0 || item.second > second || second - item.second >= 10) continue; |
|
low = std::min(low, item.low); high = std::max(high, item.high); |
|
} |
|
reserve = std::max(60, std::min(max_reserve, high - low)); |
|
return changed_second; |
|
} |
|
};
|
|
|