From 6bc39058abf24f21cac008b024327a88370915bd Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 13 Jul 2021 17:30:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=A4=A7=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E8=B7=B3=E5=8F=98=E5=AE=B9=E5=BF=8D=E5=BA=A6=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E7=BD=91=E7=BB=9C=E6=8A=96=E5=8A=A8=E6=97=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E9=9F=B3=E8=A7=86=E9=A2=91=E4=B8=8D=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Stamp.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Common/Stamp.cpp b/src/Common/Stamp.cpp index c915a519..8d177db2 100644 --- a/src/Common/Stamp.cpp +++ b/src/Common/Stamp.cpp @@ -10,7 +10,9 @@ #include "Stamp.h" -#define MAX_DELTA_STAMP 1000 +//时间戳最大允许跳变30秒,主要是防止网络抖动导致的跳变 +#define MAX_DELTA_STAMP (30 * 1000) +#define STAMP_LOOP_DELTA (60 * 1000) #define MAX_CTS 500 #define ABS(x) ((x) > 0 ? (x) : (-x)) @@ -235,14 +237,14 @@ uint64_t NtpStamp::getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate) { uint64_t max_rtp_ms = uint64_t(UINT32_MAX) * 1000 / sample_rate; if (rtp_stamp_ms > _rtp_stamp_ms) { auto diff = rtp_stamp_ms - _rtp_stamp_ms; - if (diff < 10 * 1000) { + if (diff < MAX_DELTA_STAMP) { //时间戳正常增长 _last_ret = _ntp_stamp_ms + diff; _last_rtp_stamp = rtp_stamp; return _last_ret; } //时间戳大幅跳跃 - if (_rtp_stamp_ms < 60 * 1000 && rtp_stamp_ms > max_rtp_ms - 60 * 1000) { + if (_rtp_stamp_ms < STAMP_LOOP_DELTA && rtp_stamp_ms > max_rtp_ms - STAMP_LOOP_DELTA) { //应该是rtp时间戳溢出+乱序 return _ntp_stamp_ms + diff - max_rtp_ms; } @@ -250,11 +252,11 @@ uint64_t NtpStamp::getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate) { return _last_ret; } auto diff = _rtp_stamp_ms - rtp_stamp_ms; - if (diff < 10 * 1000) { - //小于10秒的时间戳回退,说明收到rtp乱序了 + if (diff < MAX_DELTA_STAMP) { + //正常范围的时间戳回退,说明收到rtp乱序了 return _ntp_stamp_ms - diff; } - if (rtp_stamp_ms < 60 * 1000 && _rtp_stamp_ms > max_rtp_ms - 60 * 1000) { + if (rtp_stamp_ms < STAMP_LOOP_DELTA && _rtp_stamp_ms > max_rtp_ms - STAMP_LOOP_DELTA) { //确定是时间戳溢出 return _ntp_stamp_ms + (max_rtp_ms - diff); }