新增rtp时间戳大幅跳跃处理逻辑

This commit is contained in:
ziyue 2021-07-12 21:39:47 +08:00
parent 298f6e3864
commit 1cf79e886b

View File

@ -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) {
auto diff = rtp_stamp_ms - _rtp_stamp_ms;
if (diff < 10 * 1000) {
//时间戳正常增长
_last_ret = _ntp_stamp_ms + (rtp_stamp_ms - _rtp_stamp_ms);
_last_ret = _ntp_stamp_ms + diff;
return _last_ret;
}
if (_rtp_stamp_ms - rtp_stamp_ms < 10 * 1000) {
//小于10秒的时间戳回退说明收到rtp乱序了
return _ntp_stamp_ms - (_rtp_stamp_ms - rtp_stamp_ms);
//时间戳大幅跳跃
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;
}
auto diff = _rtp_stamp_ms - rtp_stamp_ms;
if (diff < 10 * 1000) {
//小于10秒的时间戳回退说明收到rtp乱序了
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;