From d7d46887a6b270122dc2113404a5667f7d184f75 Mon Sep 17 00:00:00 2001 From: "mflodman@webrtc.org" Date: Tue, 14 Feb 2012 12:49:59 +0000 Subject: [PATCH] Update receive only channels with RTT. vie_autotest_loopback.cc will not be part of the commit, it's only to show the test. TEST=temporary with attached loopback test. Review URL: https://webrtc-codereview.appspot.com/390007 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1678 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/modules/rtp_rtcp/source/rtcp_receiver.cc | 20 ++++++++- src/modules/rtp_rtcp/source/rtcp_receiver.h | 9 ++++ src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc | 43 ++++++++++++++++++-- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/modules/rtp_rtcp/source/rtcp_receiver.cc b/src/modules/rtp_rtcp/source/rtcp_receiver.cc index f7d08f0d42..f4eca71613 100644 --- a/src/modules/rtp_rtcp/source/rtcp_receiver.cc +++ b/src/modules/rtp_rtcp/source/rtcp_receiver.cc @@ -46,7 +46,8 @@ RTCPReceiver::RTCPReceiver(const WebRtc_Word32 id, _lastReceivedSRNTPsecs(0), _lastReceivedSRNTPfrac(0), _receivedInfoMap(), - _packetTimeOutMS(0) + _packetTimeOutMS(0), + _rtt(0) { memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id, "%s created", __FUNCTION__); @@ -191,6 +192,23 @@ WebRtc_Word32 RTCPReceiver::RTT(const WebRtc_UWord32 remoteSSRC, return 0; } +WebRtc_UWord16 RTCPReceiver::RTT() const { + CriticalSectionScoped lock(_criticalSectionRTCPReceiver); + if (!_receivedReportBlockMap.empty()) { + return 0; + } + return _rtt; +} + +int RTCPReceiver::SetRTT(WebRtc_UWord16 rtt) { + CriticalSectionScoped lock(_criticalSectionRTCPReceiver); + if (!_receivedReportBlockMap.empty()) { + return -1; + } + _rtt = rtt; + return 0; +} + void RTCPReceiver::UpdateLipSync(const WebRtc_Word32 audioVideoOffset) const { diff --git a/src/modules/rtp_rtcp/source/rtcp_receiver.h b/src/modules/rtp_rtcp/source/rtcp_receiver.h index 580b1c1a87..eb1b658dac 100644 --- a/src/modules/rtp_rtcp/source/rtcp_receiver.h +++ b/src/modules/rtp_rtcp/source/rtcp_receiver.h @@ -69,6 +69,10 @@ public: WebRtc_UWord16* minRTT, WebRtc_UWord16* maxRTT) const; + WebRtc_UWord16 RTT() const; + + int SetRTT(WebRtc_UWord16 rtt); + WebRtc_Word32 ResetRTT(const WebRtc_UWord32 remoteSSRC); void UpdateLipSync(const WebRtc_Word32 audioVideoOffset) const; @@ -219,6 +223,11 @@ protected: _receivedCnameMap; WebRtc_UWord32 _packetTimeOutMS; + + // Externally set RTT. This value can only be used if there are no valid + // RTT estimates. + WebRtc_UWord16 _rtt; + }; } // namespace webrtc #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_ diff --git a/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index efbf4b6832..5857a0fa86 100644 --- a/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/src/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -34,6 +34,8 @@ const float FracMS = 4.294967296E6f; namespace webrtc { +const WebRtc_UWord16 kDefaultRtt = 200; + RtpRtcp* RtpRtcp::CreateRtpRtcp(const WebRtc_Word32 id, const bool audio) { return CreateRtpRtcp(id, audio, ModuleRTPUtility::GetSystemClock()); @@ -378,14 +380,33 @@ WebRtc_Word32 ModuleRtpRtcpImpl::Process() { const bool defaultInstance(_childModules.empty() ? false : true); if (!defaultInstance && _rtcpSender.TimeToSendRTCPReport()) { - WebRtc_UWord16 RTT = 0; - _rtcpReceiver.RTT(_rtpReceiver.SSRC(), &RTT, NULL, NULL, NULL); + WebRtc_UWord16 max_rtt = 0; + if (_rtcpSender.Sending()) { + std::vector receive_blocks; + _rtcpReceiver.StatisticsReceived(&receive_blocks); + for (std::vector::iterator it = receive_blocks.begin(); + it != receive_blocks.end(); ++it) { + WebRtc_UWord16 rtt = 0; + _rtcpReceiver.RTT(it->remoteSSRC, &max_rtt, NULL, NULL, NULL); + max_rtt = (rtt > max_rtt) ? rtt : max_rtt; + } + } else { + // We're only receiving, i.e. this module doesn't have its own RTT + // estimate. Use the RTT set by a sending channel using the same default + // module. + max_rtt = _rtcpReceiver.RTT(); + } + if (max_rtt == 0) { + // No valid estimate available, i.e. no sending channel using the same + // default module or no RTCP received yet. + max_rtt = kDefaultRtt; + } if (REMB() && _rtcpSender.ValidBitrateEstimate()) { unsigned int target_bitrate = - _rtcpSender.CalculateNewTargetBitrate(RTT); + _rtcpSender.CalculateNewTargetBitrate(max_rtt); _rtcpSender.UpdateRemoteBitrateEstimate(target_bitrate); } else if (TMMBR()) { - _rtcpSender.CalculateNewTargetBitrate(RTT); + _rtcpSender.CalculateNewTargetBitrate(max_rtt); } _rtcpSender.SendRTCP(kRtcpReport); } @@ -2758,6 +2779,20 @@ void ModuleRtpRtcpImpl::ProcessDefaultModuleBandwidth() { // No sending modules and no bitrate estimate. return; } + + // Update RTT to all receive only child modules, they won't have their own RTT + // estimate. Assume the receive only channels are on similar links as the + // sending channel and have approximately the same RTT. + { + CriticalSectionScoped lock(_criticalSectionModulePtrs); + for (std::list::iterator it = _childModules.begin(); + it != _childModules.end(); ++it) { + if (!(*it)->Sending()) { + (*it)->_rtcpReceiver.SetRTT(maxRoundTripTime); + } + } + } + _bandwidthManagement.SetSendBitrate(minBitrateBps, 0, 0); // Update default module bitrate. Don't care about min max.