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

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

Issue 1491843004: [rtp_rtcp] RTT intermidiate calculation use ntp time instead of milliseconds. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase & reduced RtpRtcpImplUnittest to more reasanable expectations Created 4 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 18 matching lines...) Expand all
29 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" 29 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
30 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h" 30 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h"
31 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h" 31 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h"
32 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" 32 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
33 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h" 33 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h"
34 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h" 34 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
35 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 35 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
36 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" 36 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h"
37 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" 37 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h"
38 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" 38 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
39 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 39 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
40 #include "webrtc/system_wrappers/include/ntp_time.h"
40 41
41 namespace webrtc { 42 namespace webrtc {
42 43
43 namespace { // Anonymous namespace; hide utility functions and classes. 44 namespace { // Anonymous namespace; hide utility functions and classes.
44 45
45 // This test transport verifies that no functions get called. 46 // This test transport verifies that no functions get called.
46 class TestTransport : public Transport, 47 class TestTransport : public Transport,
47 public NullRtpData { 48 public NullRtpData {
48 public: 49 public:
49 explicit TestTransport() : rtcp_receiver_(nullptr) {} 50 explicit TestTransport() : rtcp_receiver_(nullptr) {}
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 const uint32_t kSenderSsrc = 0x10203; 174 const uint32_t kSenderSsrc = 0x10203;
174 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc); 175 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
175 rtcp::SenderReport sr; 176 rtcp::SenderReport sr;
176 sr.From(kSenderSsrc); 177 sr.From(kSenderSsrc);
177 rtc::scoped_ptr<rtcp::RawPacket> packet(sr.Build()); 178 rtc::scoped_ptr<rtcp::RawPacket> packet(sr.Build());
178 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); 179 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
179 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); 180 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC);
180 EXPECT_EQ(kRtcpSr, rtcp_packet_info_.rtcpPacketTypeFlags); 181 EXPECT_EQ(kRtcpSr, rtcp_packet_info_.rtcpPacketTypeFlags);
181 } 182 }
182 183
184 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) {
185 Random r(0x0123456789abcdef);
186 const uint32_t kSenderSsrc = r.Rand(0x00000001u, 0xfffffffeu);
187 const uint32_t kRemoteSsrc = r.Rand(0x00000001u, 0xfffffffeu);
188 const int64_t kRttMs = r.Rand(1, 18 * 3600 * 1000);
189 const uint32_t kDelayNtp = r.Rand<uint32_t>();
190 const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp);
191
192 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
193 std::set<uint32_t> ssrcs;
194 ssrcs.insert(kRemoteSsrc);
195 rtcp_receiver_->SetSsrcs(kRemoteSsrc, ssrcs);
196
197 int64_t rtt_ms = 0;
198 EXPECT_EQ(
199 -1, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
200
201 uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_));
202 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
203
204 rtcp::SenderReport sr;
205 sr.From(kSenderSsrc);
206 rtcp::ReportBlock block;
207 block.To(kRemoteSsrc);
208 block.WithLastSr(sent_ntp);
209 block.WithDelayLastSr(kDelayNtp);
210 sr.WithReportBlock(block);
211
212 rtc::scoped_ptr<rtcp::RawPacket> packet = sr.Build();
213 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
214
215 EXPECT_EQ(
216 0, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
217 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.
218 }
219
183 TEST_F(RtcpReceiverTest, InjectRrPacket) { 220 TEST_F(RtcpReceiverTest, InjectRrPacket) {
184 const uint32_t kSenderSsrc = 0x10203; 221 const uint32_t kSenderSsrc = 0x10203;
185 rtcp::ReceiverReport rr; 222 rtcp::ReceiverReport rr;
186 rr.From(kSenderSsrc); 223 rr.From(kSenderSsrc);
187 rtc::scoped_ptr<rtcp::RawPacket> packet(rr.Build()); 224 rtc::scoped_ptr<rtcp::RawPacket> packet(rr.Build());
188 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); 225 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
189 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); 226 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC);
190 EXPECT_EQ(kRtcpRr, rtcp_packet_info_.rtcpPacketTypeFlags); 227 EXPECT_EQ(kRtcpRr, rtcp_packet_info_.rtcpPacketTypeFlags);
191 ASSERT_EQ(0u, rtcp_packet_info_.report_blocks.size()); 228 ASSERT_EQ(0u, rtcp_packet_info_.report_blocks.size());
192 } 229 }
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item); 693 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item);
657 } 694 }
658 695
659 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithSubBlock) { 696 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithSubBlock) {
660 const uint32_t kSourceSsrc = 0x123456; 697 const uint32_t kSourceSsrc = 0x123456;
661 std::set<uint32_t> ssrcs; 698 std::set<uint32_t> ssrcs;
662 ssrcs.insert(kSourceSsrc); 699 ssrcs.insert(kSourceSsrc);
663 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); 700 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
664 701
665 rtcp::Dlrr dlrr; 702 rtcp::Dlrr dlrr;
666 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); 703 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
667 rtcp::ExtendedReports xr; 704 rtcp::ExtendedReports xr;
668 xr.From(0x2345); 705 xr.From(0x2345);
669 xr.WithDlrr(dlrr); 706 xr.WithDlrr(dlrr);
670 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build()); 707 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build());
671 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); 708 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
672 // The parser should note the DLRR report block item, but not flag the packet 709 // The parser should note the DLRR report block item, but not flag the packet
673 // since the RTT is not estimated. 710 // since the RTT is not estimated.
674 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item); 711 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item);
675 } 712 }
676 713
677 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) { 714 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) {
678 const uint32_t kSourceSsrc = 0x123456; 715 const uint32_t kSourceSsrc = 0x123456;
679 std::set<uint32_t> ssrcs; 716 std::set<uint32_t> ssrcs;
680 ssrcs.insert(kSourceSsrc); 717 ssrcs.insert(kSourceSsrc);
681 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); 718 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
682 719
683 rtcp::Dlrr dlrr; 720 rtcp::Dlrr dlrr;
684 dlrr.WithDlrrItem(kSourceSsrc + 1, 0x12345, 0x67890); 721 dlrr.WithDlrrItem(kSourceSsrc + 1, 0, 0x67890);
685 dlrr.WithDlrrItem(kSourceSsrc + 2, 0x12345, 0x67890); 722 dlrr.WithDlrrItem(kSourceSsrc + 2, 0, 0x67890);
686 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); 723 dlrr.WithDlrrItem(kSourceSsrc, 0, 0x67890);
687 rtcp::ExtendedReports xr; 724 rtcp::ExtendedReports xr;
688 xr.From(0x2345); 725 xr.From(0x2345);
689 xr.WithDlrr(dlrr); 726 xr.WithDlrr(dlrr);
690 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build()); 727 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build());
691 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); 728 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
692 // The parser should note the DLRR report block item, but not flag the packet 729 // The parser should note the DLRR report block item, but not flag the packet
693 // since the RTT is not estimated. 730 // since the RTT is not estimated.
694 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item); 731 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item);
695 } 732 }
696 733
697 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithMultipleReportBlocks) { 734 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithMultipleReportBlocks) {
698 const uint32_t kSourceSsrc = 0x123456; 735 const uint32_t kSourceSsrc = 0x123456;
699 std::set<uint32_t> ssrcs; 736 std::set<uint32_t> ssrcs;
700 ssrcs.insert(kSourceSsrc); 737 ssrcs.insert(kSourceSsrc);
701 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); 738 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
702 739
703 rtcp::Rrtr rrtr; 740 rtcp::Rrtr rrtr;
704 rtcp::Dlrr dlrr; 741 rtcp::Dlrr dlrr;
705 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); 742 dlrr.WithDlrrItem(kSourceSsrc, 0, 0x67890);
danilchap 2016/02/03 13:27:11 This test does check rtt wasn't estimated. So need
706 rtcp::VoipMetric metric; 743 rtcp::VoipMetric metric;
707 metric.To(kSourceSsrc); 744 metric.To(kSourceSsrc);
708 rtcp::ExtendedReports xr; 745 rtcp::ExtendedReports xr;
709 xr.From(0x2345); 746 xr.From(0x2345);
710 xr.WithRrtr(rrtr); 747 xr.WithRrtr(rrtr);
711 xr.WithDlrr(dlrr); 748 xr.WithDlrr(dlrr);
712 xr.WithVoipMetric(metric); 749 xr.WithVoipMetric(metric);
713 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build()); 750 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build());
714 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); 751 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
715 EXPECT_EQ(static_cast<unsigned int>(kRtcpXrReceiverReferenceTime + 752 EXPECT_EQ(static_cast<unsigned int>(kRtcpXrReceiverReferenceTime +
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 kRtcpXrVoipMetric), 786 kRtcpXrVoipMetric),
750 rtcp_packet_info_.rtcpPacketTypeFlags); 787 rtcp_packet_info_.rtcpPacketTypeFlags);
751 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item); 788 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item);
752 } 789 }
753 790
754 TEST_F(RtcpReceiverTest, TestXrRrRttInitiallyFalse) { 791 TEST_F(RtcpReceiverTest, TestXrRrRttInitiallyFalse) {
755 int64_t rtt_ms; 792 int64_t rtt_ms;
756 EXPECT_FALSE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); 793 EXPECT_FALSE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms));
757 } 794 }
758 795
796 TEST_F(RtcpReceiverTest, RttCalculatedAfterXrDlrr) {
797 Random rand(0x0123456789abcdef);
798 const uint32_t kSourceSsrc = rand.Rand(0x00000001u, 0xfffffffeu);
799 const uint32_t kRttMs = rand.Rand(1, 18 * 3600 * 1000);
800 const uint32_t kDelayNtp = rand.Rand<uint32_t>();
801 const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp);
802 std::set<uint32_t> ssrcs;
803 ssrcs.insert(kSourceSsrc);
804 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
805 NtpTime now(system_clock_);
806 uint32_t sent_ntp = CompactNtp(now);
807 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
808
809 rtcp::Dlrr dlrr;
810 dlrr.WithDlrrItem(kSourceSsrc, sent_ntp, kDelayNtp);
811 rtcp::ExtendedReports xr;
812 xr.From(0x2345);
813 xr.WithDlrr(dlrr);
814 rtc::scoped_ptr<rtcp::RawPacket> packet = xr.Build();
815 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
816
817 int64_t rtt_ms = 0;
818 EXPECT_TRUE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms));
819 EXPECT_NEAR(kRttMs, rtt_ms, 1);
820 }
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
821
759 TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) { 822 TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) {
760 RtcpReceiveTimeInfo info; 823 RtcpReceiveTimeInfo info;
761 EXPECT_FALSE(rtcp_receiver_->LastReceivedXrReferenceTimeInfo(&info)); 824 EXPECT_FALSE(rtcp_receiver_->LastReceivedXrReferenceTimeInfo(&info));
762 } 825 }
763 826
764 TEST_F(RtcpReceiverTest, GetLastReceivedExtendedReportsReferenceTimeInfo) { 827 TEST_F(RtcpReceiverTest, GetLastReceivedExtendedReportsReferenceTimeInfo) {
765 const uint32_t kSenderSsrc = 0x123456; 828 const uint32_t kSenderSsrc = 0x123456;
766 const NtpTime kNtp(0x10203, 0x40506); 829 const NtpTime kNtp(0x10203, 0x40506);
767 const uint32_t kNtpMid = 830 const uint32_t kNtpMid = CompactNtp(kNtp);
768 RTCPUtility::MidNtp(kNtp.seconds(), kNtp.fractions());
769 831
770 rtcp::Rrtr rrtr; 832 rtcp::Rrtr rrtr;
771 rrtr.WithNtp(kNtp); 833 rrtr.WithNtp(kNtp);
772 rtcp::ExtendedReports xr; 834 rtcp::ExtendedReports xr;
773 xr.From(kSenderSsrc); 835 xr.From(kSenderSsrc);
774 xr.WithRrtr(rrtr); 836 xr.WithRrtr(rrtr);
775 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build()); 837 rtc::scoped_ptr<rtcp::RawPacket> packet(xr.Build());
776 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length())); 838 EXPECT_EQ(0, InjectRtcpPacket(packet->Buffer(), packet->Length()));
777 EXPECT_EQ(kRtcpXrReceiverReferenceTime, 839 EXPECT_EQ(kRtcpXrReceiverReferenceTime,
778 rtcp_packet_info_.rtcpPacketTypeFlags); 840 rtcp_packet_info_.rtcpPacketTypeFlags);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 1161
1100 // Transport feedback should be ignored, but next packet should work. 1162 // Transport feedback should be ignored, but next packet should work.
1101 EXPECT_EQ(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback); 1163 EXPECT_EQ(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback);
1102 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpRemb); 1164 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpRemb);
1103 EXPECT_EQ(kBitrateBps, rtcp_packet_info_.receiverEstimatedMaxBitrate); 1165 EXPECT_EQ(kBitrateBps, rtcp_packet_info_.receiverEstimatedMaxBitrate);
1104 } 1166 }
1105 1167
1106 } // Anonymous namespace 1168 } // Anonymous namespace
1107 1169
1108 } // namespace webrtc 1170 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698