diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index 7ff1412bb..acc2c266e 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -1135,10 +1135,13 @@ int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list, id_, "SendNACK(size:%u)", size); - uint16_t avg_rtt = 0; - rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &avg_rtt, NULL, NULL); + // Use RTT from RtcpRttStats class if provided. + uint16_t rtt = rtt_ms(); + if (rtt == 0) { + rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); + } - int64_t wait_time = 5 + ((avg_rtt * 3) >> 1); // 5 + RTT * 1.5. + int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5. if (wait_time == 5) { wait_time = 100; // During startup we don't have an RTT. } @@ -1597,9 +1600,12 @@ void ModuleRtpRtcpImpl::OnReceivedNACK( nack_sequence_numbers.size() == 0) { return; } - uint16_t avg_rtt = 0; - rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &avg_rtt, NULL, NULL); - rtp_sender_.OnReceivedNACK(nack_sequence_numbers, avg_rtt); + // Use RTT from RtcpRttStats class if provided. + uint16_t rtt = rtt_ms(); + if (rtt == 0) { + rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); + } + rtp_sender_.OnReceivedNACK(nack_sequence_numbers, rtt); } int32_t ModuleRtpRtcpImpl::LastReceivedNTP( diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h index b7a1fb129..7e0425f3b 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h @@ -405,6 +405,7 @@ class ModuleRtpRtcpImpl : public RtpRtcp { Clock* clock_; private: + FRIEND_TEST_ALL_PREFIXES(RtpRtcpImplTest, Rtt); FRIEND_TEST_ALL_PREFIXES(RtpRtcpImplTest, RttForReceiverOnly); int64_t RtcpReportInterval(); void SetRtcpReceiverSsrcs(uint32_t main_ssrc); diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc index 6248f4970..50f7f2e1c 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc @@ -122,6 +122,13 @@ TEST_F(RtpRtcpImplTest, Rtt) { // No RTT from other ssrc. EXPECT_EQ(-1, rtp_rtcp_impl_->RTT(kSsrc + 1, &rtt, &avg_rtt, &min_rtt, &max_rtt)); + + // Verify RTT from rtt_stats config. + EXPECT_EQ(0U, rtt_stats_.LastProcessedRtt()); + EXPECT_EQ(0U, rtp_rtcp_impl_->rtt_ms()); + rtp_rtcp_impl_->Process(); + EXPECT_EQ(100U, rtt_stats_.LastProcessedRtt()); + EXPECT_EQ(100U, rtp_rtcp_impl_->rtt_ms()); } TEST_F(RtpRtcpImplTest, SetRtcpXrRrtrStatus) { @@ -147,7 +154,6 @@ TEST_F(RtpRtcpImplTest, RttForReceiverOnly) { // Verify RTT. EXPECT_EQ(0U, rtt_stats_.LastProcessedRtt()); EXPECT_EQ(0U, rtp_rtcp_impl_->rtt_ms()); - rtp_rtcp_impl_->Process(); EXPECT_EQ(100U, rtt_stats_.LastProcessedRtt()); EXPECT_EQ(100U, rtp_rtcp_impl_->rtt_ms());