Improve timestamp corrector

This commit is contained in:
xia-chu 2024-10-13 00:23:34 +08:00
parent 351e8fbd43
commit e4025a6811
2 changed files with 26 additions and 2 deletions

View File

@ -27,6 +27,12 @@ DeltaStamp::DeltaStamp() {
_max_delta = 300;
}
void DeltaStamp::reset() {
_last_stamp = 0;
_relative_stamp = 0;
_last_delta = 1;
}
int64_t DeltaStamp::relativeStamp(int64_t stamp, bool enable_rollback) {
_relative_stamp += deltaStamp(stamp, enable_rollback);
return _relative_stamp;
@ -55,8 +61,9 @@ int64_t DeltaStamp::deltaStamp(int64_t stamp, bool enable_rollback) {
// In the live broadcast case, the timestamp increment must not be greater than MAX_DELTA_STAMP, otherwise the relative timestamp is forced to add 1
if (ret > _max_delta) {
needSync();
return 1;
return _last_delta;
}
_last_delta = ret;
return ret;
}
@ -67,7 +74,7 @@ int64_t DeltaStamp::deltaStamp(int64_t stamp, bool enable_rollback) {
// 不允许回退或者回退太多了, 强制时间戳加1 [AUTO-TRANSLATED:152f5ffa]
// Not allowed to retreat or retreat too much, force the timestamp to add 1
needSync();
return 1;
return _last_delta;
}
return ret;
}
@ -93,6 +100,14 @@ void Stamp::enableRollback(bool flag) {
_enable_rollback = flag;
}
void Stamp::reset() {
DeltaStamp::reset();
_relative_stamp = 0;
_last_dts_in = 0;
_last_dts_out = 0;
_last_pts_out = 0;
}
// 限制dts回退 [AUTO-TRANSLATED:6bc53b31]
// Limit dts retreat
void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out, bool modifyStamp) {

View File

@ -42,11 +42,15 @@ public:
// Set the maximum allowed rollback or jump amplitude
void setMaxDelta(size_t max_delta);
// 重置
void reset();
protected:
virtual void needSync() {}
protected:
int _max_delta;
int _last_delta = 1;
int64_t _last_stamp = 0;
int64_t _relative_stamp = 0;
};
@ -123,6 +127,11 @@ public:
*/
void enableRollback(bool flag);
/**
*
*/
void reset();
private:
// 主要实现音视频时间戳同步功能 [AUTO-TRANSLATED:45863fce]
// Mainly implements audio and video timestamp synchronization function