mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-31 08:39:34 +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 NtpStamp::getNtpStamp(uint32_t rtp_stamp, uint32_t sample_rate) {
|
||||||
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包
|
||||||
return rtp_stamp_ms;
|
return rtp_stamp_ms;
|
||||||
}
|
}
|
||||||
|
uint64_t max_rtp_ms = uint64_t(UINT32_MAX) * 1000 / sample_rate;
|
||||||
if (rtp_stamp_ms > _rtp_stamp_ms) {
|
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;
|
return _last_ret;
|
||||||
}
|
}
|
||||||
if (_rtp_stamp_ms - rtp_stamp_ms < 10 * 1000) {
|
//时间戳大幅跳跃
|
||||||
//小于10秒的时间戳回退,说明收到rtp乱序了
|
if (_rtp_stamp_ms < 60 * 1000 && rtp_stamp_ms > max_rtp_ms - 60 * 1000) {
|
||||||
return _ntp_stamp_ms - (_rtp_stamp_ms - rtp_stamp_ms);
|
//应该是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) {
|
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;
|
return _last_ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user