Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc |
| index e0c70c2b5cd08a1f5c61581cede0c8df7cbef4f4..07a3deb58bab76148d64522d8dbea9c801089348 100644 |
| --- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc |
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc |
| @@ -36,7 +36,8 @@ |
| #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" |
| #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" |
| #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
| -#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
| +#include "webrtc/modules/rtp_rtcp/source/time_util.h" |
| +#include "webrtc/system_wrappers/include/ntp_time.h" |
| namespace webrtc { |
| @@ -180,6 +181,42 @@ TEST_F(RtcpReceiverTest, InjectSrPacketFromExpectedPeer) { |
| EXPECT_EQ(kRtcpSr, rtcp_packet_info_.rtcpPacketTypeFlags); |
| } |
| +TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) { |
| + Random r(0x0123456789abcdef); |
| + const uint32_t kSenderSsrc = r.Rand(0x00000001u, 0xfffffffeu); |
| + const uint32_t kRemoteSsrc = r.Rand(0x00000001u, 0xfffffffeu); |
| + const int64_t kRttMs = r.Rand(1, 18 * 3600 * 1000); |
| + const uint32_t kDelayNtp = r.Rand<uint32_t>(); |
| + const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp); |
| + |
| + rtcp_receiver_->SetRemoteSSRC(kSenderSsrc); |
| + std::set<uint32_t> ssrcs; |
| + ssrcs.insert(kRemoteSsrc); |
| + rtcp_receiver_->SetSsrcs(kRemoteSsrc, ssrcs); |
| + |
| + int64_t rtt_ms = 0; |
| + EXPECT_EQ( |
| + -1, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); |
| + |
| + uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_)); |
| + system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); |
| + |
| + rtcp::SenderReport sr; |
| + sr.From(kSenderSsrc); |
| + rtcp::ReportBlock block; |
| + block.To(kRemoteSsrc); |
| + block.WithLastSr(sent_ntp); |
| + block.WithDelayLastSr(kDelayNtp); |
| + sr.WithReportBlock(block); |
| + |
| + rtc::scoped_ptr<rtcp::RawPacket> packet = sr.Build(); |
| + EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); |
| + |
| + EXPECT_EQ( |
| + 0, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); |
| + EXPECT_NEAR(kRttMs, rtt_ms, 1); |
|
stefan-webrtc
2016/02/03 10:03:11
What's the reason we can't get an exact rtt here?
danilchap
2016/02/03 13:27:11
Rounding.
if rtt would be stored and returned in 1
stefan-webrtc
2016/02/22 16:14:35
Acknowledged.
|
| +} |
| + |
| TEST_F(RtcpReceiverTest, InjectRrPacket) { |
| const uint32_t kSenderSsrc = 0x10203; |
| rtcp::ReceiverReport rr; |
| @@ -663,7 +700,7 @@ TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithSubBlock) { |
| rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); |
| rtcp::Dlrr dlrr; |
| - dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); |
| + dlrr.WithDlrrItem(kSourceSsrc, 0, 0x67890); |
|
stefan-webrtc
2016/02/03 10:03:11
Could you explain these changes to me?
danilchap
2016/02/03 13:27:11
changed field is sent time.
Before this cl it wasn
|
| rtcp::ExtendedReports xr; |
| xr.From(0x2345); |
| xr.WithDlrr(dlrr); |
| @@ -681,9 +718,9 @@ TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) { |
| rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); |
| rtcp::Dlrr dlrr; |
| - dlrr.WithDlrrItem(kSourceSsrc + 1, 0x12345, 0x67890); |
| - dlrr.WithDlrrItem(kSourceSsrc + 2, 0x12345, 0x67890); |
| - dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); |
| + dlrr.WithDlrrItem(kSourceSsrc + 1, 0, 0x67890); |
| + dlrr.WithDlrrItem(kSourceSsrc + 2, 0, 0x67890); |
| + dlrr.WithDlrrItem(kSourceSsrc, 0, 0x67890); |
| rtcp::ExtendedReports xr; |
| xr.From(0x2345); |
| xr.WithDlrr(dlrr); |
| @@ -702,7 +739,7 @@ TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithMultipleReportBlocks) { |
| rtcp::Rrtr rrtr; |
| rtcp::Dlrr dlrr; |
| - dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); |
| + dlrr.WithDlrrItem(kSourceSsrc, 0, 0x67890); |
|
danilchap
2016/02/03 13:27:11
This test does check rtt wasn't estimated. So need
|
| rtcp::VoipMetric metric; |
| metric.To(kSourceSsrc); |
| rtcp::ExtendedReports xr; |
| @@ -756,6 +793,32 @@ TEST_F(RtcpReceiverTest, TestXrRrRttInitiallyFalse) { |
| EXPECT_FALSE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); |
| } |
| +TEST_F(RtcpReceiverTest, RttCalculatedAfterXrDlrr) { |
| + Random rand(0x0123456789abcdef); |
| + const uint32_t kSourceSsrc = rand.Rand(0x00000001u, 0xfffffffeu); |
| + const uint32_t kRttMs = rand.Rand(1, 18 * 3600 * 1000); |
| + const uint32_t kDelayNtp = rand.Rand<uint32_t>(); |
| + const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp); |
| + std::set<uint32_t> ssrcs; |
| + ssrcs.insert(kSourceSsrc); |
| + rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); |
| + NtpTime now(system_clock_); |
| + uint32_t sent_ntp = CompactNtp(now); |
| + system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); |
| + |
| + rtcp::Dlrr dlrr; |
| + dlrr.WithDlrrItem(kSourceSsrc, sent_ntp, kDelayNtp); |
| + rtcp::ExtendedReports xr; |
| + xr.From(0x2345); |
| + xr.WithDlrr(dlrr); |
| + rtc::scoped_ptr<rtcp::RawPacket> packet = xr.Build(); |
| + EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); |
| + |
| + int64_t rtt_ms = 0; |
| + EXPECT_TRUE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); |
| + EXPECT_NEAR(kRttMs, rtt_ms, 1); |
| +} |
|
stefan-webrtc
2016/02/03 10:03:11
Maybe we can reuse a few lines from the other test
danilchap
2016/02/03 13:27:11
Do not want to think about test improvements in th
|
| + |
| TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) { |
| RtcpReceiveTimeInfo info; |
| EXPECT_FALSE(rtcp_receiver_->LastReceivedXrReferenceTimeInfo(&info)); |
| @@ -764,8 +827,7 @@ TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) { |
| TEST_F(RtcpReceiverTest, GetLastReceivedExtendedReportsReferenceTimeInfo) { |
| const uint32_t kSenderSsrc = 0x123456; |
| const NtpTime kNtp(0x10203, 0x40506); |
| - const uint32_t kNtpMid = |
| - RTCPUtility::MidNtp(kNtp.seconds(), kNtp.fractions()); |
| + const uint32_t kNtpMid = CompactNtp(kNtp); |
| rtcp::Rrtr rrtr; |
| rrtr.WithNtp(kNtp); |