修复ntp时间戳计算精度导致的bug:#1086

This commit is contained in:
夏楚 2021-09-04 09:28:41 +08:00 committed by GitHub
parent c2bf2928d0
commit ad1ae2ac66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -244,7 +244,7 @@ uint64_t NtpStamp::getNtpStamp_l(uint32_t rtp_stamp, uint32_t sample_rate) {
//rtp时间戳正增长 //rtp时间戳正增长
if (rtp_stamp >= _last_rtp_stamp) { if (rtp_stamp >= _last_rtp_stamp) {
auto diff = (rtp_stamp - _last_rtp_stamp) / (sample_rate / 1000.0f); auto diff = static_cast<int>((rtp_stamp - _last_rtp_stamp) / (sample_rate / 1000.0f));
if (diff < MAX_DELTA_STAMP) { if (diff < MAX_DELTA_STAMP) {
//时间戳正常增长 //时间戳正常增长
update(rtp_stamp, _last_ntp_stamp_ms + diff); update(rtp_stamp, _last_ntp_stamp_ms + diff);
@ -264,7 +264,7 @@ uint64_t NtpStamp::getNtpStamp_l(uint32_t rtp_stamp, uint32_t sample_rate) {
} }
//rtp时间戳负增长 //rtp时间戳负增长
auto diff = (_last_rtp_stamp - rtp_stamp) / (sample_rate / 1000.0f); auto diff = static_cast<int>((_last_rtp_stamp - rtp_stamp) / (sample_rate / 1000.0f));
if (diff < MAX_DELTA_STAMP) { if (diff < MAX_DELTA_STAMP) {
//正常范围的时间戳回退说明收到rtp乱序了 //正常范围的时间戳回退说明收到rtp乱序了
return _last_ntp_stamp_ms - diff; return _last_ntp_stamp_ms - diff;
@ -283,4 +283,4 @@ uint64_t NtpStamp::getNtpStamp_l(uint32_t rtp_stamp, uint32_t sample_rate) {
return _last_ntp_stamp_ms; return _last_ntp_stamp_ms;
} }
}//namespace mediakit }//namespace mediakit