1 changed files with 6 additions and 5 deletions
@ -1,20 +1,21 @@ |
|||||||
#pragma once |
#pragma once |
||||||
#include <cstdint> |
#include <cstdint> |
||||||
|
|
||||||
// Бюджет 30 fps с запасом четверти кадра на дрожание PTS, без накопления после паузы.
|
// Бюджет 30 fps с запасом одного кадра; интервал >=25мс запрещает burst после паузы.
|
||||||
class CallVideoCadence { |
class CallVideoCadence { |
||||||
int64_t lastPts = -1, credit = 1250000; |
int64_t lastPts = -1, lastAccepted = -1, credit = 1250000; |
||||||
public: |
public: |
||||||
bool accept(int64_t pts) { |
bool accept(int64_t pts) { |
||||||
if (lastPts >= 0) { |
if (lastPts >= 0) { |
||||||
if (pts <= lastPts) return false; |
if (pts <= lastPts) return false; |
||||||
const int64_t elapsed = pts - lastPts; |
const int64_t elapsed = pts - lastPts; |
||||||
credit = elapsed >= 41667 ? 1250000 : credit + elapsed * 30; |
credit = elapsed >= 66667 ? 2000000 : credit + elapsed * 30; |
||||||
if (credit > 1250000) credit = 1250000; |
if (credit > 2000000) credit = 2000000; |
||||||
} |
} |
||||||
lastPts = pts; |
lastPts = pts; |
||||||
if (credit < 1000000) return false; |
if (credit < 1000000 || (lastAccepted >= 0 && pts - lastAccepted < 25000)) return false; |
||||||
credit -= 1000000; |
credit -= 1000000; |
||||||
|
lastAccepted = pts; |
||||||
return true; |
return true; |
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|||||||
Loading…
Reference in new issue