mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
新增rtp时间戳大幅跳跃处理逻辑
This commit is contained in:
parent
298f6e3864
commit
1cf79e886b
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user