Commit 77283f39 by ziyue

优化ntp时间戳获取性能

parent 1cf79e88
...@@ -222,9 +222,14 @@ void NtpStamp::setNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate, uint64_t nt ...@@ -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) { 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; uint64_t rtp_stamp_ms = uint64_t(rtp_stamp) * 1000 / sample_rate;
if (!_rtp_stamp_ms && !_ntp_stamp_ms) { if (!_rtp_stamp_ms && !_ntp_stamp_ms) {
//尚未收到sender report rtcp包 //尚未收到sender report rtcp包
_last_ret = rtp_stamp_ms;
_last_rtp_stamp = rtp_stamp;
return rtp_stamp_ms; return rtp_stamp_ms;
} }
uint64_t max_rtp_ms = uint64_t(UINT32_MAX) * 1000 / sample_rate; 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) { ...@@ -233,6 +238,7 @@ uint64_t NtpStamp::getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate) {
if (diff < 10 * 1000) { if (diff < 10 * 1000) {
//时间戳正常增长 //时间戳正常增长
_last_ret = _ntp_stamp_ms + diff; _last_ret = _ntp_stamp_ms + diff;
_last_rtp_stamp = rtp_stamp;
return _last_ret; return _last_ret;
} }
//时间戳大幅跳跃 //时间戳大幅跳跃
......
...@@ -123,6 +123,7 @@ public: ...@@ -123,6 +123,7 @@ public:
uint64_t getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate); uint64_t getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate);
private: private:
uint32_t _last_rtp_stamp = 0;
uint64_t _rtp_stamp_ms = 0; uint64_t _rtp_stamp_ms = 0;
uint64_t _ntp_stamp_ms = 0; uint64_t _ntp_stamp_ms = 0;
uint64_t _last_ret = 0; uint64_t _last_ret = 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论