mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 14:45:55 +08:00
优化ntp时间戳获取性能
This commit is contained in:
parent
1cf79e886b
commit
77283f3973
@ -222,9 +222,14 @@ void NtpStamp::setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t nt
|
||||
}
|
||||
|
||||
uint64_t NtpStamp::getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate) {
|
||||
if (rtp_stamp == _last_rtp_stamp) {
|
||||
return _last_ret;
|
||||
}
|
||||
uint64_t rtp_stamp_ms = uint64_t(rtp_stamp) * 1000 / sample_rate;
|
||||
if (!_rtp_stamp_ms && !_ntp_stamp_ms) {
|
||||
//尚未收到sender report rtcp包
|
||||
_last_ret = rtp_stamp_ms;
|
||||
_last_rtp_stamp = rtp_stamp;
|
||||
return rtp_stamp_ms;
|
||||
}
|
||||
uint64_t max_rtp_ms = uint64_t(UINT32_MAX) * 1000 / sample_rate;
|
||||
@ -233,6 +238,7 @@ uint64_t NtpStamp::getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate) {
|
||||
if (diff < 10 * 1000) {
|
||||
//时间戳正常增长
|
||||
_last_ret = _ntp_stamp_ms + diff;
|
||||
_last_rtp_stamp = rtp_stamp;
|
||||
return _last_ret;
|
||||
}
|
||||
//时间戳大幅跳跃
|
||||
|
@ -123,6 +123,7 @@ public:
|
||||
uint64_t getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate);
|
||||
|
||||
private:
|
||||
uint32_t _last_rtp_stamp = 0;
|
||||
uint64_t _rtp_stamp_ms = 0;
|
||||
uint64_t _ntp_stamp_ms = 0;
|
||||
uint64_t _last_ret = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user