2 changed files with 24 additions and 8 deletions
@ -1,17 +1,20 @@
|
||||
#pragma once |
||||
#include <cstdint> |
||||
|
||||
// Сетка 30 fps с допуском четверти периода: дрожание PTS не превращает 30 fps в 15.
|
||||
// Бюджет 30 fps с запасом четверти кадра на дрожание PTS, без накопления после паузы.
|
||||
class CallVideoCadence { |
||||
int64_t origin = -1, lastSlot = -1; |
||||
int64_t lastPts = -1, credit = 1250000; |
||||
public: |
||||
bool accept(int64_t pts) { |
||||
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 + 250000) / 1000000; |
||||
if (slot <= lastSlot) return false; |
||||
lastSlot = slot; |
||||
if (lastPts >= 0) { |
||||
if (pts <= lastPts) return false; |
||||
const int64_t elapsed = pts - lastPts; |
||||
credit = elapsed >= 41667 ? 1250000 : credit + elapsed * 30; |
||||
if (credit > 1250000) credit = 1250000; |
||||
} |
||||
lastPts = pts; |
||||
if (credit < 1000000) return false; |
||||
credit -= 1000000; |
||||
return true; |
||||
} |
||||
}; |
||||
|
||||
Loading…
Reference in new issue