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

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 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 const uint32_t kSenderSsrc = 0x10203; 173 const uint32_t kSenderSsrc = 0x10203;
173 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc); 174 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
174 rtcp::SenderReport sr; 175 rtcp::SenderReport sr;
175 sr.From(kSenderSsrc); 176 sr.From(kSenderSsrc);
176 rtc::Buffer packet = sr.Build(); 177 rtc::Buffer packet = sr.Build();
177 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); 178 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
178 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); 179 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC);
179 EXPECT_EQ(kRtcpSr, rtcp_packet_info_.rtcpPacketTypeFlags); 180 EXPECT_EQ(kRtcpSr, rtcp_packet_info_.rtcpPacketTypeFlags);
180 } 181 }
181 182
183 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) {
184 Random r(0x0123456789abcdef);
185 const uint32_t kSenderSsrc = r.Rand(0x00000001u, 0xfffffffeu);
186 const uint32_t kRemoteSsrc = r.Rand(0x00000001u, 0xfffffffeu);
187 const int64_t kRttMs = r.Rand(1, 18 * 3600 * 1000);
188 const uint32_t kDelayNtp = r.Rand<uint32_t>();
189 const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp);
190
191 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
192 std::set<uint32_t> ssrcs;
193 ssrcs.insert(kRemoteSsrc);
194 rtcp_receiver_->SetSsrcs(kRemoteSsrc, ssrcs);
195
196 int64_t rtt_ms = 0;
197 EXPECT_EQ(
198 -1, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
199
200 uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_));
201 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
202
203 rtcp::SenderReport sr;
204 sr.From(kSenderSsrc);
205 rtcp::ReportBlock block;
206 block.To(kRemoteSsrc);
207 block.WithLastSr(sent_ntp);
208 block.WithDelayLastSr(kDelayNtp);
209 sr.WithReportBlock(block);
210
211 rtc::Buffer packet = sr.Build();
212 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
213
214 EXPECT_EQ(
215 0, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr));
216 EXPECT_NEAR(kRttMs, rtt_ms, 1);
217 }
218
182 TEST_F(RtcpReceiverTest, InjectRrPacket) { 219 TEST_F(RtcpReceiverTest, InjectRrPacket) {
183 const uint32_t kSenderSsrc = 0x10203; 220 const uint32_t kSenderSsrc = 0x10203;
184 rtcp::ReceiverReport rr; 221 rtcp::ReceiverReport rr;
185 rr.From(kSenderSsrc); 222 rr.From(kSenderSsrc);
186 rtc::Buffer packet = rr.Build(); 223 rtc::Buffer packet = rr.Build();
187 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); 224 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
188 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); 225 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC);
189 EXPECT_EQ(kRtcpRr, rtcp_packet_info_.rtcpPacketTypeFlags); 226 EXPECT_EQ(kRtcpRr, rtcp_packet_info_.rtcpPacketTypeFlags);
190 ASSERT_EQ(0u, rtcp_packet_info_.report_blocks.size()); 227 ASSERT_EQ(0u, rtcp_packet_info_.report_blocks.size());
191 } 228 }
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 ssrcs.insert(kSourceSsrc); 698 ssrcs.insert(kSourceSsrc);
662 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); 699 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
663 700
664 rtcp::Dlrr dlrr; 701 rtcp::Dlrr dlrr;
665 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); 702 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890);
666 rtcp::ExtendedReports xr; 703 rtcp::ExtendedReports xr;
667 xr.From(0x2345); 704 xr.From(0x2345);
668 xr.WithDlrr(dlrr); 705 xr.WithDlrr(dlrr);
669 rtc::Buffer packet = xr.Build(); 706 rtc::Buffer packet = xr.Build();
670 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); 707 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
671 // The parser should note the DLRR report block item, but not flag the packet 708 // The parser should note the DLRR report block item.
672 // since the RTT is not estimated.
673 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item); 709 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item);
674 } 710 }
675 711
676 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) { 712 TEST_F(RtcpReceiverTest, InjectExtendedReportsDlrrPacketWithMultipleSubBlocks) {
677 const uint32_t kSourceSsrc = 0x123456; 713 const uint32_t kSourceSsrc = 0x123456;
678 std::set<uint32_t> ssrcs; 714 std::set<uint32_t> ssrcs;
679 ssrcs.insert(kSourceSsrc); 715 ssrcs.insert(kSourceSsrc);
680 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); 716 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
681 717
682 rtcp::Dlrr dlrr; 718 rtcp::Dlrr dlrr;
683 dlrr.WithDlrrItem(kSourceSsrc + 1, 0x12345, 0x67890); 719 dlrr.WithDlrrItem(kSourceSsrc + 1, 0x12345, 0x67890);
684 dlrr.WithDlrrItem(kSourceSsrc + 2, 0x12345, 0x67890); 720 dlrr.WithDlrrItem(kSourceSsrc + 2, 0x12345, 0x67890);
685 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); 721 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890);
686 rtcp::ExtendedReports xr; 722 rtcp::ExtendedReports xr;
687 xr.From(0x2345); 723 xr.From(0x2345);
688 xr.WithDlrr(dlrr); 724 xr.WithDlrr(dlrr);
689 rtc::Buffer packet = xr.Build(); 725 rtc::Buffer packet = xr.Build();
690 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); 726 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
691 // The parser should note the DLRR report block item, but not flag the packet 727 // The parser should note the DLRR report block item.
692 // since the RTT is not estimated.
693 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item); 728 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item);
694 } 729 }
695 730
696 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithMultipleReportBlocks) { 731 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithMultipleReportBlocks) {
697 const uint32_t kSourceSsrc = 0x123456; 732 const uint32_t kSourceSsrc = 0x123456;
698 std::set<uint32_t> ssrcs; 733 std::set<uint32_t> ssrcs;
699 ssrcs.insert(kSourceSsrc); 734 ssrcs.insert(kSourceSsrc);
700 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); 735 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
701 736
702 rtcp::Rrtr rrtr; 737 rtcp::Rrtr rrtr;
703 rtcp::Dlrr dlrr; 738 rtcp::Dlrr dlrr;
704 dlrr.WithDlrrItem(kSourceSsrc, 0x12345, 0x67890); 739 dlrr.WithDlrrItem(kSourceSsrc, 0, 0x67890);
705 rtcp::VoipMetric metric; 740 rtcp::VoipMetric metric;
706 metric.To(kSourceSsrc); 741 metric.To(kSourceSsrc);
707 rtcp::ExtendedReports xr; 742 rtcp::ExtendedReports xr;
708 xr.From(0x2345); 743 xr.From(0x2345);
709 xr.WithRrtr(rrtr); 744 xr.WithRrtr(rrtr);
710 xr.WithDlrr(dlrr); 745 xr.WithDlrr(dlrr);
711 xr.WithVoipMetric(metric); 746 xr.WithVoipMetric(metric);
712 rtc::Buffer packet = xr.Build(); 747 rtc::Buffer packet = xr.Build();
713 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); 748 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
749 // The parser should not flag the packet since the RTT is not estimated.
714 EXPECT_EQ(static_cast<unsigned int>(kRtcpXrReceiverReferenceTime + 750 EXPECT_EQ(static_cast<unsigned int>(kRtcpXrReceiverReferenceTime +
715 kRtcpXrVoipMetric), 751 kRtcpXrVoipMetric),
716 rtcp_packet_info_.rtcpPacketTypeFlags); 752 rtcp_packet_info_.rtcpPacketTypeFlags);
717 // The parser should note the DLRR report block item, but not flag the packet 753 // The parser should note the DLRR report block item.
718 // since the RTT is not estimated.
719 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item); 754 EXPECT_TRUE(rtcp_packet_info_.xr_dlrr_item);
720 } 755 }
721 756
722 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithUnknownReportBlock) { 757 TEST_F(RtcpReceiverTest, InjectExtendedReportsPacketWithUnknownReportBlock) {
723 const uint32_t kSourceSsrc = 0x123456; 758 const uint32_t kSourceSsrc = 0x123456;
724 std::set<uint32_t> ssrcs; 759 std::set<uint32_t> ssrcs;
725 ssrcs.insert(kSourceSsrc); 760 ssrcs.insert(kSourceSsrc);
726 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); 761 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
727 std::vector<uint32_t> remote_ssrcs; 762 std::vector<uint32_t> remote_ssrcs;
728 remote_ssrcs.push_back(kSourceSsrc); 763 remote_ssrcs.push_back(kSourceSsrc);
(...skipping 19 matching lines...) Expand all
748 kRtcpXrVoipMetric), 783 kRtcpXrVoipMetric),
749 rtcp_packet_info_.rtcpPacketTypeFlags); 784 rtcp_packet_info_.rtcpPacketTypeFlags);
750 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item); 785 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item);
751 } 786 }
752 787
753 TEST_F(RtcpReceiverTest, TestXrRrRttInitiallyFalse) { 788 TEST_F(RtcpReceiverTest, TestXrRrRttInitiallyFalse) {
754 int64_t rtt_ms; 789 int64_t rtt_ms;
755 EXPECT_FALSE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); 790 EXPECT_FALSE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms));
756 } 791 }
757 792
793 TEST_F(RtcpReceiverTest, RttCalculatedAfterXrDlrr) {
794 Random rand(0x0123456789abcdef);
795 const uint32_t kSourceSsrc = rand.Rand(0x00000001u, 0xfffffffeu);
796 const uint32_t kRttMs = rand.Rand(1, 18 * 3600 * 1000);
797 const uint32_t kDelayNtp = rand.Rand<uint32_t>();
798 const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp);
799 std::set<uint32_t> ssrcs;
800 ssrcs.insert(kSourceSsrc);
801 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs);
802 NtpTime now(system_clock_);
803 uint32_t sent_ntp = CompactNtp(now);
804 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs);
805
806 rtcp::Dlrr dlrr;
807 dlrr.WithDlrrItem(kSourceSsrc, sent_ntp, kDelayNtp);
808 rtcp::ExtendedReports xr;
809 xr.From(0x2345);
810 xr.WithDlrr(dlrr);
811 rtc::Buffer packet = xr.Build();
812 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
813
814 int64_t rtt_ms = 0;
815 EXPECT_TRUE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms));
816 EXPECT_NEAR(kRttMs, rtt_ms, 1);
817 }
818
758 TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) { 819 TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) {
759 RtcpReceiveTimeInfo info; 820 RtcpReceiveTimeInfo info;
760 EXPECT_FALSE(rtcp_receiver_->LastReceivedXrReferenceTimeInfo(&info)); 821 EXPECT_FALSE(rtcp_receiver_->LastReceivedXrReferenceTimeInfo(&info));
761 } 822 }
762 823
763 TEST_F(RtcpReceiverTest, GetLastReceivedExtendedReportsReferenceTimeInfo) { 824 TEST_F(RtcpReceiverTest, GetLastReceivedExtendedReportsReferenceTimeInfo) {
764 const uint32_t kSenderSsrc = 0x123456; 825 const uint32_t kSenderSsrc = 0x123456;
765 const NtpTime kNtp(0x10203, 0x40506); 826 const NtpTime kNtp(0x10203, 0x40506);
766 const uint32_t kNtpMid = 827 const uint32_t kNtpMid = CompactNtp(kNtp);
767 RTCPUtility::MidNtp(kNtp.seconds(), kNtp.fractions());
768 828
769 rtcp::Rrtr rrtr; 829 rtcp::Rrtr rrtr;
770 rrtr.WithNtp(kNtp); 830 rrtr.WithNtp(kNtp);
771 rtcp::ExtendedReports xr; 831 rtcp::ExtendedReports xr;
772 xr.From(kSenderSsrc); 832 xr.From(kSenderSsrc);
773 xr.WithRrtr(rrtr); 833 xr.WithRrtr(rrtr);
774 rtc::Buffer packet = xr.Build(); 834 rtc::Buffer packet = xr.Build();
775 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); 835 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
776 EXPECT_EQ(kRtcpXrReceiverReferenceTime, 836 EXPECT_EQ(kRtcpXrReceiverReferenceTime,
777 rtcp_packet_info_.rtcpPacketTypeFlags); 837 rtcp_packet_info_.rtcpPacketTypeFlags);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 1151
1092 // Transport feedback should be ignored, but next packet should work. 1152 // Transport feedback should be ignored, but next packet should work.
1093 EXPECT_EQ(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback); 1153 EXPECT_EQ(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback);
1094 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpRemb); 1154 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpRemb);
1095 EXPECT_EQ(kBitrateBps, rtcp_packet_info_.receiverEstimatedMaxBitrate); 1155 EXPECT_EQ(kBitrateBps, rtcp_packet_info_.receiverEstimatedMaxBitrate);
1096 } 1156 }
1097 1157
1098 } // Anonymous namespace 1158 } // Anonymous namespace
1099 1159
1100 } // namespace webrtc 1160 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc ('k') | webrtc/modules/rtp_rtcp/source/rtcp_sender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698