Avoid accumulated rounding in call frame pacing

This commit is contained in:
evgeny committed 2026-10-15 02:05:08 +02:00
1 parent dceb868111
commit 7b7e33cf72
1 file changed
+7 -5
+7 -5
View File
@@ -1,15 +1,17 @@
#pragma once
#include <algorithm>
#include <cstdint>
// Сетка 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;
}
};