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