mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
Improve timestamp corrector
This commit is contained in:
parent
351e8fbd43
commit
e4025a6811
@ -27,6 +27,12 @@ DeltaStamp::DeltaStamp() {
|
|||||||
_max_delta = 300;
|
_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) {
|
int64_t DeltaStamp::relativeStamp(int64_t stamp, bool enable_rollback) {
|
||||||
_relative_stamp += deltaStamp(stamp, enable_rollback);
|
_relative_stamp += deltaStamp(stamp, enable_rollback);
|
||||||
return _relative_stamp;
|
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
|
// 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) {
|
if (ret > _max_delta) {
|
||||||
needSync();
|
needSync();
|
||||||
return 1;
|
return _last_delta;
|
||||||
}
|
}
|
||||||
|
_last_delta = ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +74,7 @@ int64_t DeltaStamp::deltaStamp(int64_t stamp, bool enable_rollback) {
|
|||||||
// 不允许回退或者回退太多了, 强制时间戳加1 [AUTO-TRANSLATED:152f5ffa]
|
// 不允许回退或者回退太多了, 强制时间戳加1 [AUTO-TRANSLATED:152f5ffa]
|
||||||
// Not allowed to retreat or retreat too much, force the timestamp to add 1
|
// Not allowed to retreat or retreat too much, force the timestamp to add 1
|
||||||
needSync();
|
needSync();
|
||||||
return 1;
|
return _last_delta;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -93,6 +100,14 @@ void Stamp::enableRollback(bool flag) {
|
|||||||
_enable_rollback = 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]
|
// 限制dts回退 [AUTO-TRANSLATED:6bc53b31]
|
||||||
// Limit dts retreat
|
// Limit dts retreat
|
||||||
void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out, bool modifyStamp) {
|
void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out, bool modifyStamp) {
|
||||||
|
@ -42,11 +42,15 @@ public:
|
|||||||
// Set the maximum allowed rollback or jump amplitude
|
// Set the maximum allowed rollback or jump amplitude
|
||||||
void setMaxDelta(size_t max_delta);
|
void setMaxDelta(size_t max_delta);
|
||||||
|
|
||||||
|
// 重置
|
||||||
|
void reset();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void needSync() {}
|
virtual void needSync() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int _max_delta;
|
int _max_delta;
|
||||||
|
int _last_delta = 1;
|
||||||
int64_t _last_stamp = 0;
|
int64_t _last_stamp = 0;
|
||||||
int64_t _relative_stamp = 0;
|
int64_t _relative_stamp = 0;
|
||||||
};
|
};
|
||||||
@ -123,6 +127,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void enableRollback(bool flag);
|
void enableRollback(bool flag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置
|
||||||
|
*/
|
||||||
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 主要实现音视频时间戳同步功能 [AUTO-TRANSLATED:45863fce]
|
// 主要实现音视频时间戳同步功能 [AUTO-TRANSLATED:45863fce]
|
||||||
// Mainly implements audio and video timestamp synchronization function
|
// Mainly implements audio and video timestamp synchronization function
|
||||||
|
Loading…
Reference in New Issue
Block a user