From 1cf79e886b466160b118926ba1a1b6905c2904b8 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Mon, 12 Jul 2021 21:39:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ertp=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E5=A4=A7=E5=B9=85=E8=B7=B3=E8=B7=83=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Stamp.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Common/Stamp.cpp b/src/Common/Stamp.cpp index 015168f1..f9df913e 100644 --- a/src/Common/Stamp.cpp +++ b/src/Common/Stamp.cpp @@ -224,21 +224,33 @@ 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 rtp_stamp_ms = uint64_t(rtp_stamp) * 1000 / sample_rate; if (!_rtp_stamp_ms && !_ntp_stamp_ms) { + //尚未收到sender report rtcp包 return rtp_stamp_ms; } + uint64_t max_rtp_ms = uint64_t(UINT32_MAX) * 1000 / sample_rate; if (rtp_stamp_ms > _rtp_stamp_ms) { - //时间戳正常增长 - _last_ret = _ntp_stamp_ms + (rtp_stamp_ms - _rtp_stamp_ms); + auto diff = rtp_stamp_ms - _rtp_stamp_ms; + if (diff < 10 * 1000) { + //时间戳正常增长 + _last_ret = _ntp_stamp_ms + diff; + return _last_ret; + } + //时间戳大幅跳跃 + if (_rtp_stamp_ms < 60 * 1000 && rtp_stamp_ms > max_rtp_ms - 60 * 1000) { + //应该是rtp时间戳溢出+乱序 + return _ntp_stamp_ms + diff - max_rtp_ms; + } + //不明原因的时间戳大幅跳跃,直接返回上次值 return _last_ret; } - if (_rtp_stamp_ms - rtp_stamp_ms < 10 * 1000) { + auto diff = _rtp_stamp_ms - rtp_stamp_ms; + if (diff < 10 * 1000) { //小于10秒的时间戳回退,说明收到rtp乱序了 - return _ntp_stamp_ms - (_rtp_stamp_ms - rtp_stamp_ms); + return _ntp_stamp_ms - diff; } - uint64_t max_rtp_ms = uint64_t(UINT32_MAX) * 1000 / sample_rate; if (rtp_stamp_ms < 60 * 1000 && _rtp_stamp_ms > max_rtp_ms - 60 * 1000) { //确定是时间戳溢出 - return _ntp_stamp_ms + rtp_stamp_ms + (max_rtp_ms - _rtp_stamp_ms); + return _ntp_stamp_ms + (max_rtp_ms - diff); } //不明原因的时间戳回退,直接返回上次值 return _last_ret;