#pragma once #include #include // Десять секундных интервалов. Время передаёт аудиопоток из монотонных часов. 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; } };