From ee9af6533da1f8c31ae83fdaf2c73599c6b27262 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 15 Oct 2026 02:05:08 +0200 Subject: [PATCH] Avoid accumulated rounding in call frame pacing --- tools/chatgui/src/call_video_cadence.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/chatgui/src/call_video_cadence.h b/tools/chatgui/src/call_video_cadence.h index 00e8aaa1..bd68cd7e 100644 --- a/tools/chatgui/src/call_video_cadence.h +++ b/tools/chatgui/src/call_video_cadence.h @@ -1,15 +1,17 @@ #pragma once -#include #include // Сетка 30 fps с допуском половины периода: дрожание PTS не превращает 30 fps в 15. class CallVideoCadence { - int64_t next = -1; + int64_t origin = -1, lastSlot = -1; public: bool accept(int64_t pts) { - constexpr int64_t period = 1000000 / 30; - if (next >= 0 && pts < next - period / 2) return false; - next = next < 0 ? pts + period : std::max(next + period, pts + period / 2); + if (origin < 0) origin = pts; + if (pts < origin) return false; + const int64_t elapsed = pts - origin; + const int64_t slot = (elapsed / 1000000) * 30 + ((elapsed % 1000000) * 30 + 500000) / 1000000; + if (slot <= lastSlot) return false; + lastSlot = slot; return true; } };