Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc

Issue 2393723004: replace NtpTime->Clock with Clock->NtpTime dependency (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) { 264 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) {
265 Random r(0x0123456789abcdef); 265 Random r(0x0123456789abcdef);
266 const int64_t kRttMs = r.Rand(1, 9 * 3600 * 1000); 266 const int64_t kRttMs = r.Rand(1, 9 * 3600 * 1000);
267 const uint32_t kDelayNtp = r.Rand(0, 0x7fffffff); 267 const uint32_t kDelayNtp = r.Rand(0, 0x7fffffff);
268 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); 268 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
269 269
270 int64_t rtt_ms = 0; 270 int64_t rtt_ms = 0;
271 EXPECT_EQ( 271 EXPECT_EQ(
272 -1, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); 272 -1, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
273 273
274 uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_)); 274 uint32_t sent_ntp = CompactNtp(system_clock_.CurrentNtpTime());
275 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); 275 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
276 276
277 rtcp::SenderReport sr; 277 rtcp::SenderReport sr;
278 sr.SetSenderSsrc(kSenderSsrc); 278 sr.SetSenderSsrc(kSenderSsrc);
279 rtcp::ReportBlock block; 279 rtcp::ReportBlock block;
280 block.SetMediaSsrc(kReceiverMainSsrc); 280 block.SetMediaSsrc(kReceiverMainSsrc);
281 block.SetLastSr(sent_ntp); 281 block.SetLastSr(sent_ntp);
282 block.SetDelayLastSr(kDelayNtp); 282 block.SetDelayLastSr(kDelayNtp);
283 sr.AddReportBlock(block); 283 sr.AddReportBlock(block);
284 284
285 EXPECT_CALL(rtp_rtcp_impl_, OnReceivedRtcpReportBlocks(_)); 285 EXPECT_CALL(rtp_rtcp_impl_, OnReceivedRtcpReportBlocks(_));
286 EXPECT_CALL(bandwidth_observer_, OnReceivedRtcpReceiverReport(_, _, _)); 286 EXPECT_CALL(bandwidth_observer_, OnReceivedRtcpReceiverReport(_, _, _));
287 InjectRtcpPacket(sr); 287 InjectRtcpPacket(sr);
288 288
289 EXPECT_EQ( 289 EXPECT_EQ(
290 0, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); 290 0, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
291 EXPECT_NEAR(kRttMs, rtt_ms, 1); 291 EXPECT_NEAR(kRttMs, rtt_ms, 1);
292 } 292 }
293 293
294 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesNegativeRTTAsOne) { 294 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesNegativeRTTAsOne) {
295 Random r(0x0123456789abcdef); 295 Random r(0x0123456789abcdef);
296 const int64_t kRttMs = r.Rand(-3600 * 1000, -1); 296 const int64_t kRttMs = r.Rand(-3600 * 1000, -1);
297 const uint32_t kDelayNtp = r.Rand(0, 0x7fffffff); 297 const uint32_t kDelayNtp = r.Rand(0, 0x7fffffff);
298 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); 298 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
299 299
300 int64_t rtt_ms = 0; 300 int64_t rtt_ms = 0;
301 EXPECT_EQ( 301 EXPECT_EQ(
302 -1, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); 302 -1, rtcp_receiver_.RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
303 303
304 uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_)); 304 uint32_t sent_ntp = CompactNtp(system_clock_.CurrentNtpTime());
305 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); 305 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
306 306
307 rtcp::SenderReport sr; 307 rtcp::SenderReport sr;
308 sr.SetSenderSsrc(kSenderSsrc); 308 sr.SetSenderSsrc(kSenderSsrc);
309 rtcp::ReportBlock block; 309 rtcp::ReportBlock block;
310 block.SetMediaSsrc(kReceiverMainSsrc); 310 block.SetMediaSsrc(kReceiverMainSsrc);
311 block.SetLastSr(sent_ntp); 311 block.SetLastSr(sent_ntp);
312 block.SetDelayLastSr(kDelayNtp); 312 block.SetDelayLastSr(kDelayNtp);
313 sr.AddReportBlock(block); 313 sr.AddReportBlock(block);
314 314
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 rtcp_receiver_.SetRtcpXrRrtrStatus(true); 767 rtcp_receiver_.SetRtcpXrRrtrStatus(true);
768 int64_t rtt_ms = 0; 768 int64_t rtt_ms = 0;
769 EXPECT_FALSE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)); 769 EXPECT_FALSE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms));
770 770
771 rtcp::ExtendedReports xr; 771 rtcp::ExtendedReports xr;
772 xr.SetSenderSsrc(kSenderSsrc); 772 xr.SetSenderSsrc(kSenderSsrc);
773 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, kLastRR, kDelay)); 773 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, kLastRR, kDelay));
774 774
775 InjectRtcpPacket(xr); 775 InjectRtcpPacket(xr);
776 776
777 uint32_t compact_ntp_now = CompactNtp(NtpTime(system_clock_)); 777 uint32_t compact_ntp_now = CompactNtp(system_clock_.CurrentNtpTime());
778 EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)); 778 EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms));
779 uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR; 779 uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR;
780 EXPECT_NEAR(CompactNtpRttToMs(rtt_ntp), rtt_ms, 1); 780 EXPECT_NEAR(CompactNtpRttToMs(rtt_ntp), rtt_ms, 1);
781 } 781 }
782 782
783 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) { 783 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) {
784 const uint32_t kLastRR = 0x12345; 784 const uint32_t kLastRR = 0x12345;
785 const uint32_t kDelay = 0x56789; 785 const uint32_t kDelay = 0x56789;
786 rtcp_receiver_.SetRtcpXrRrtrStatus(true); 786 rtcp_receiver_.SetRtcpXrRrtrStatus(true);
787 787
788 rtcp::ExtendedReports xr; 788 rtcp::ExtendedReports xr;
789 xr.SetSenderSsrc(kSenderSsrc); 789 xr.SetSenderSsrc(kSenderSsrc);
790 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, kLastRR, kDelay)); 790 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, kLastRR, kDelay));
791 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc + 1, 0x12345, 0x67890)); 791 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc + 1, 0x12345, 0x67890));
792 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc + 2, 0x12345, 0x67890)); 792 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc + 2, 0x12345, 0x67890));
793 793
794 InjectRtcpPacket(xr); 794 InjectRtcpPacket(xr);
795 795
796 uint32_t compact_ntp_now = CompactNtp(NtpTime(system_clock_)); 796 uint32_t compact_ntp_now = CompactNtp(system_clock_.CurrentNtpTime());
797 int64_t rtt_ms = 0; 797 int64_t rtt_ms = 0;
798 EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)); 798 EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms));
799 uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR; 799 uint32_t rtt_ntp = compact_ntp_now - kDelay - kLastRR;
800 EXPECT_NEAR(CompactNtpRttToMs(rtt_ntp), rtt_ms, 1); 800 EXPECT_NEAR(CompactNtpRttToMs(rtt_ntp), rtt_ms, 1);
801 } 801 }
802 802
803 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithMultipleReportBlocks) { 803 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithMultipleReportBlocks) {
804 rtcp_receiver_.SetRtcpXrRrtrStatus(true); 804 rtcp_receiver_.SetRtcpXrRrtrStatus(true);
805 805
806 rtcp::Rrtr rrtr; 806 rtcp::Rrtr rrtr;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 int64_t rtt_ms; 852 int64_t rtt_ms;
853 EXPECT_FALSE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)); 853 EXPECT_FALSE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms));
854 } 854 }
855 855
856 TEST_F(RtcpReceiverTest, RttCalculatedAfterExtendedReportsDlrr) { 856 TEST_F(RtcpReceiverTest, RttCalculatedAfterExtendedReportsDlrr) {
857 Random rand(0x0123456789abcdef); 857 Random rand(0x0123456789abcdef);
858 const int64_t kRttMs = rand.Rand(1, 9 * 3600 * 1000); 858 const int64_t kRttMs = rand.Rand(1, 9 * 3600 * 1000);
859 const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff); 859 const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff);
860 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); 860 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
861 rtcp_receiver_.SetRtcpXrRrtrStatus(true); 861 rtcp_receiver_.SetRtcpXrRrtrStatus(true);
862 NtpTime now(system_clock_); 862 NtpTime now = system_clock_.CurrentNtpTime();
863 uint32_t sent_ntp = CompactNtp(now); 863 uint32_t sent_ntp = CompactNtp(now);
864 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); 864 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
865 865
866 rtcp::ExtendedReports xr; 866 rtcp::ExtendedReports xr;
867 xr.SetSenderSsrc(kSenderSsrc); 867 xr.SetSenderSsrc(kSenderSsrc);
868 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, sent_ntp, kDelayNtp)); 868 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, sent_ntp, kDelayNtp));
869 869
870 InjectRtcpPacket(xr); 870 InjectRtcpPacket(xr);
871 871
872 int64_t rtt_ms = 0; 872 int64_t rtt_ms = 0;
873 EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)); 873 EXPECT_TRUE(rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms));
874 EXPECT_NEAR(kRttMs, rtt_ms, 1); 874 EXPECT_NEAR(kRttMs, rtt_ms, 1);
875 } 875 }
876 876
877 TEST_F(RtcpReceiverTest, XrDlrrCalculatesNegativeRttAsOne) { 877 TEST_F(RtcpReceiverTest, XrDlrrCalculatesNegativeRttAsOne) {
878 Random rand(0x0123456789abcdef); 878 Random rand(0x0123456789abcdef);
879 const int64_t kRttMs = rand.Rand(-3600 * 1000, -1); 879 const int64_t kRttMs = rand.Rand(-3600 * 1000, -1);
880 const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff); 880 const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff);
881 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); 881 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp);
882 NtpTime now(system_clock_); 882 NtpTime now = system_clock_.CurrentNtpTime();
883 uint32_t sent_ntp = CompactNtp(now); 883 uint32_t sent_ntp = CompactNtp(now);
884 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); 884 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
885 rtcp_receiver_.SetRtcpXrRrtrStatus(true); 885 rtcp_receiver_.SetRtcpXrRrtrStatus(true);
886 886
887 rtcp::ExtendedReports xr; 887 rtcp::ExtendedReports xr;
888 xr.SetSenderSsrc(kSenderSsrc); 888 xr.SetSenderSsrc(kSenderSsrc);
889 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, sent_ntp, kDelayNtp)); 889 xr.AddDlrrItem(ReceiveTimeInfo(kReceiverMainSsrc, sent_ntp, kDelayNtp));
890 890
891 InjectRtcpPacket(xr); 891 InjectRtcpPacket(xr);
892 892
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 1308
1309 rtcp::ExtendedReports xr; 1309 rtcp::ExtendedReports xr;
1310 xr.SetTargetBitrate(bitrate); 1310 xr.SetTargetBitrate(bitrate);
1311 1311
1312 EXPECT_CALL(bitrate_allocation_observer_, 1312 EXPECT_CALL(bitrate_allocation_observer_,
1313 OnBitrateAllocationUpdated(expected_allocation)); 1313 OnBitrateAllocationUpdated(expected_allocation));
1314 InjectRtcpPacket(xr); 1314 InjectRtcpPacket(xr);
1315 } 1315 }
1316 1316
1317 } // namespace webrtc 1317 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc ('k') | webrtc/modules/rtp_rtcp/source/rtcp_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698