优化ntp时间戳获取性能

This commit is contained in:
ziyue 2021-07-13 10:10:23 +08:00
parent 1cf79e886b
commit 77283f3973
2 changed files with 7 additions and 0 deletions

View File

@ -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;
}
//时间戳大幅跳跃

View File

@ -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;