完善rtt相关代码

This commit is contained in:
xiongziliang 2021-07-06 23:09:56 +08:00
parent 4c296488f1
commit 986e9511a2
3 changed files with 17 additions and 1 deletions

View File

@ -103,7 +103,7 @@ void RtcpContext::onRtcp(RtcpHeader *rtcp) {
//转换为毫秒
auto ms_inc = ntpmsw_inc * 1000 + (ntplsw_inc / ((double) (((uint64_t) 1) << 32) * 1.0e-3));
auto rtt = (int) ((ms_inc - delay_ms) / 2);
auto rtt = (int) (ms_inc - delay_ms);
_rtt[item->ssrc] = rtt;
//InfoL << "ssrc:" << item->ssrc << ",rtt:" << rtt;
}
@ -113,6 +113,14 @@ void RtcpContext::onRtcp(RtcpHeader *rtcp) {
}
}
uint32_t RtcpContext::getRtt(uint32_t ssrc) const {
auto it = _rtt.find(ssrc);
if (it == _rtt.end()) {
return 0;
}
return it->second;
}
size_t RtcpContext::getExpectedPackets() const {
if (!_is_receiver) {
throw std::runtime_error("rtp发送者无法统计应收包数");

View File

@ -71,6 +71,13 @@ public:
*/
void clear();
/**
* rtt
* @param ssrc rtp ssrc
* @return rtt,
*/
uint32_t getRtt(uint32_t ssrc) const;
private:
/**
*

View File

@ -640,6 +640,7 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
auto it = _ssrc_to_track.find(item->ssrc);
if (it != _ssrc_to_track.end()) {
auto &track = it->second;
track->rtcp_context_send->onRtcp(rtcp);
auto sr = track->rtcp_context_send->createRtcpSR(track->answer_ssrc_rtp);
sendRtcpPacket(sr->data(), sr->size(), true);
} else {