From 2b58a4433f16c510d56b1d16d2e3bb882b184861 Mon Sep 17 00:00:00 2001 From: "minyue@webrtc.org" Date: Thu, 11 Sep 2014 07:51:53 +0000 Subject: [PATCH] Calculating round-trip-time in send-only channel in VoE. TESTS=built chromium and tested with 1:1 hangout call BUG= R=stefan@webrtc.org, xians@webrtc.org Review URL: https://webrtc-codereview.appspot.com/23489004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7147 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/voice_engine/channel.cc | 85 +++++++++++++++++++--------------- webrtc/voice_engine/channel.h | 1 + 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 41728c74a..6d6b099cd 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -3481,43 +3481,7 @@ Channel::GetRTPStatistics(CallStatistics& stats) stats.jitterSamples); // --- RTT - - uint16_t RTT(0); - RTCPMethod method = _rtpRtcpModule->RTCP(); - if (method == kRtcpOff) - { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, - VoEId(_instanceId, _channelId), - "GetRTPStatistics() RTCP is disabled => valid RTT " - "measurements cannot be retrieved"); - } else - { - // The remote SSRC will be zero if no RTP packet has been received. - uint32_t remoteSSRC = rtp_receiver_->SSRC(); - if (remoteSSRC > 0) - { - uint16_t avgRTT(0); - uint16_t maxRTT(0); - uint16_t minRTT(0); - - if (_rtpRtcpModule->RTT(remoteSSRC, &RTT, &avgRTT, &minRTT, &maxRTT) - != 0) - { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, - VoEId(_instanceId, _channelId), - "GetRTPStatistics() failed to retrieve RTT from " - "the RTP/RTCP module"); - } - } else - { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, - VoEId(_instanceId, _channelId), - "GetRTPStatistics() failed to measure RTT since no " - "RTP packets have been received yet"); - } - } - - stats.rttMs = static_cast (RTT); + stats.rttMs = GetRTT(); WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), @@ -4566,5 +4530,52 @@ int32_t Channel::GetPlayoutFrequency() { return playout_frequency; } +int Channel::GetRTT() const { + RTCPMethod method = _rtpRtcpModule->RTCP(); + if (method == kRtcpOff) { + WEBRTC_TRACE(kTraceWarning, kTraceVoice, + VoEId(_instanceId, _channelId), + "GetRTPStatistics() RTCP is disabled => valid RTT " + "measurements cannot be retrieved"); + return 0; + } + std::vector report_blocks; + _rtpRtcpModule->RemoteRTCPStat(&report_blocks); + if (report_blocks.empty()) { + WEBRTC_TRACE(kTraceWarning, kTraceVoice, + VoEId(_instanceId, _channelId), + "GetRTPStatistics() failed to measure RTT since no " + "RTCP packets have been received yet"); + return 0; + } + + uint32_t remoteSSRC = rtp_receiver_->SSRC(); + std::vector::const_iterator it = report_blocks.begin(); + for (; it != report_blocks.end(); ++it) { + if (it->remoteSSRC == remoteSSRC) + break; + } + if (it == report_blocks.end()) { + // We have not received packets with SSRC matching the report blocks. + // To calculate RTT we try with the SSRC of the first report block. + // This is very important for send-only channels where we don't know + // the SSRC of the other end. + remoteSSRC = report_blocks[0].remoteSSRC; + } + uint16_t rtt = 0; + uint16_t avg_rtt = 0; + uint16_t max_rtt= 0; + uint16_t min_rtt = 0; + if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) + != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVoice, + VoEId(_instanceId, _channelId), + "GetRTPStatistics() failed to retrieve RTT from " + "the RTP/RTCP module"); + return 0; + } + return static_cast(rtt); +} + } // namespace voe } // namespace webrtc diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h index 94fa04fb5..d030daf38 100644 --- a/webrtc/voice_engine/channel.h +++ b/webrtc/voice_engine/channel.h @@ -508,6 +508,7 @@ private: unsigned char id); int32_t GetPlayoutFrequency(); + int GetRTT() const; CriticalSectionWrapper& _fileCritSect; CriticalSectionWrapper& _callbackCritSect;