From 986e9511a2ea3a6aa2cac5fd661c529108eba4a0 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 6 Jul 2021 23:09:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84rtt=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtcp/RtcpContext.cpp | 10 +++++++++- src/Rtcp/RtcpContext.h | 7 +++++++ webrtc/WebRtcTransport.cpp | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Rtcp/RtcpContext.cpp b/src/Rtcp/RtcpContext.cpp index 5ea20ebc..aad7c3c7 100644 --- a/src/Rtcp/RtcpContext.cpp +++ b/src/Rtcp/RtcpContext.cpp @@ -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发送者无法统计应收包数"); diff --git a/src/Rtcp/RtcpContext.h b/src/Rtcp/RtcpContext.h index 3caa95c2..a5a88fe6 100644 --- a/src/Rtcp/RtcpContext.h +++ b/src/Rtcp/RtcpContext.h @@ -71,6 +71,13 @@ public: */ void clear(); + /** + * 获取rtt + * @param ssrc rtp ssrc + * @return rtt,单位毫秒 + */ + uint32_t getRtt(uint32_t ssrc) const; + private: /** * 上次结果与本次结果间应收包数 diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index ec7cc0e8..1a0616b1 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -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 {