Browse Source

Avoid accumulated rounding in call frame pacing

master
evgeny 5 days ago
parent
commit
ee9af6533d
  1. 12
      tools/chatgui/src/call_video_cadence.h

12
tools/chatgui/src/call_video_cadence.h

@ -1,15 +1,17 @@
#pragma once #pragma once
#include <algorithm>
#include <cstdint> #include <cstdint>
// Сетка 30 fps с допуском половины периода: дрожание PTS не превращает 30 fps в 15. // Сетка 30 fps с допуском половины периода: дрожание PTS не превращает 30 fps в 15.
class CallVideoCadence { class CallVideoCadence {
int64_t next = -1; int64_t origin = -1, lastSlot = -1;
public: public:
bool accept(int64_t pts) { bool accept(int64_t pts) {
constexpr int64_t period = 1000000 / 30; if (origin < 0) origin = pts;
if (next >= 0 && pts < next - period / 2) return false; if (pts < origin) return false;
next = next < 0 ? pts + period : std::max(next + period, pts + period / 2); 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; return true;
} }
}; };

Loading…
Cancel
Save