1 changed files with 7 additions and 5 deletions
@ -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; |
||||
} |
||||
}; |
||||
|
||||
Loading…
Reference in new issue