OLD | NEW |
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 rtc::Buffer packet = sr.Build(); | 177 rtc::Buffer packet = sr.Build(); |
178 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); | 178 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); |
179 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); | 179 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); |
180 EXPECT_EQ(kRtcpSr, rtcp_packet_info_.rtcpPacketTypeFlags); | 180 EXPECT_EQ(kRtcpSr, rtcp_packet_info_.rtcpPacketTypeFlags); |
181 } | 181 } |
182 | 182 |
183 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) { | 183 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesRTT) { |
184 Random r(0x0123456789abcdef); | 184 Random r(0x0123456789abcdef); |
185 const uint32_t kSenderSsrc = r.Rand(0x00000001u, 0xfffffffeu); | 185 const uint32_t kSenderSsrc = r.Rand(0x00000001u, 0xfffffffeu); |
186 const uint32_t kRemoteSsrc = r.Rand(0x00000001u, 0xfffffffeu); | 186 const uint32_t kRemoteSsrc = r.Rand(0x00000001u, 0xfffffffeu); |
187 const int64_t kRttMs = r.Rand(1, 18 * 3600 * 1000); | 187 const int64_t kRttMs = r.Rand(1, 9 * 3600 * 1000); |
188 const uint32_t kDelayNtp = r.Rand<uint32_t>(); | 188 const uint32_t kDelayNtp = r.Rand(0, 0x7fffffff); |
189 const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp); | 189 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); |
190 | 190 |
191 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc); | 191 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc); |
192 std::set<uint32_t> ssrcs; | 192 std::set<uint32_t> ssrcs; |
193 ssrcs.insert(kRemoteSsrc); | 193 ssrcs.insert(kRemoteSsrc); |
194 rtcp_receiver_->SetSsrcs(kRemoteSsrc, ssrcs); | 194 rtcp_receiver_->SetSsrcs(kRemoteSsrc, ssrcs); |
195 | 195 |
196 int64_t rtt_ms = 0; | 196 int64_t rtt_ms = 0; |
197 EXPECT_EQ( | 197 EXPECT_EQ( |
198 -1, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); | 198 -1, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); |
199 | 199 |
200 uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_)); | 200 uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_)); |
201 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); | 201 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); |
202 | 202 |
203 rtcp::SenderReport sr; | 203 rtcp::SenderReport sr; |
204 sr.From(kSenderSsrc); | 204 sr.From(kSenderSsrc); |
205 rtcp::ReportBlock block; | 205 rtcp::ReportBlock block; |
206 block.To(kRemoteSsrc); | 206 block.To(kRemoteSsrc); |
207 block.WithLastSr(sent_ntp); | 207 block.WithLastSr(sent_ntp); |
208 block.WithDelayLastSr(kDelayNtp); | 208 block.WithDelayLastSr(kDelayNtp); |
209 sr.WithReportBlock(block); | 209 sr.WithReportBlock(block); |
210 | 210 |
211 rtc::Buffer packet = sr.Build(); | 211 rtc::Buffer packet = sr.Build(); |
212 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); | 212 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); |
213 | 213 |
214 EXPECT_EQ( | 214 EXPECT_EQ( |
215 0, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); | 215 0, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); |
216 EXPECT_NEAR(kRttMs, rtt_ms, 1); | 216 EXPECT_NEAR(kRttMs, rtt_ms, 1); |
217 } | 217 } |
218 | 218 |
| 219 TEST_F(RtcpReceiverTest, InjectSrPacketCalculatesNegativeRTTAsOne) { |
| 220 Random r(0x0123456789abcdef); |
| 221 const uint32_t kSenderSsrc = r.Rand(0x00000001u, 0xfffffffeu); |
| 222 const uint32_t kRemoteSsrc = r.Rand(0x00000001u, 0xfffffffeu); |
| 223 const int64_t kRttMs = r.Rand(-3600 * 1000, -1); |
| 224 const uint32_t kDelayNtp = r.Rand(0, 0x7fffffff); |
| 225 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); |
| 226 |
| 227 rtcp_receiver_->SetRemoteSSRC(kSenderSsrc); |
| 228 std::set<uint32_t> ssrcs; |
| 229 ssrcs.insert(kRemoteSsrc); |
| 230 rtcp_receiver_->SetSsrcs(kRemoteSsrc, ssrcs); |
| 231 |
| 232 int64_t rtt_ms = 0; |
| 233 EXPECT_EQ( |
| 234 -1, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); |
| 235 |
| 236 uint32_t sent_ntp = CompactNtp(NtpTime(system_clock_)); |
| 237 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); |
| 238 |
| 239 rtcp::SenderReport sr; |
| 240 sr.From(kSenderSsrc); |
| 241 rtcp::ReportBlock block; |
| 242 block.To(kRemoteSsrc); |
| 243 block.WithLastSr(sent_ntp); |
| 244 block.WithDelayLastSr(kDelayNtp); |
| 245 sr.WithReportBlock(block); |
| 246 |
| 247 rtc::Buffer packet = sr.Build(); |
| 248 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); |
| 249 |
| 250 EXPECT_EQ( |
| 251 0, rtcp_receiver_->RTT(kSenderSsrc, &rtt_ms, nullptr, nullptr, nullptr)); |
| 252 EXPECT_EQ(1, rtt_ms); |
| 253 } |
| 254 |
219 TEST_F(RtcpReceiverTest, InjectRrPacket) { | 255 TEST_F(RtcpReceiverTest, InjectRrPacket) { |
220 const uint32_t kSenderSsrc = 0x10203; | 256 const uint32_t kSenderSsrc = 0x10203; |
221 rtcp::ReceiverReport rr; | 257 rtcp::ReceiverReport rr; |
222 rr.From(kSenderSsrc); | 258 rr.From(kSenderSsrc); |
223 rtc::Buffer packet = rr.Build(); | 259 rtc::Buffer packet = rr.Build(); |
224 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); | 260 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); |
225 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); | 261 EXPECT_EQ(kSenderSsrc, rtcp_packet_info_.remoteSSRC); |
226 EXPECT_EQ(kRtcpRr, rtcp_packet_info_.rtcpPacketTypeFlags); | 262 EXPECT_EQ(kRtcpRr, rtcp_packet_info_.rtcpPacketTypeFlags); |
227 ASSERT_EQ(0u, rtcp_packet_info_.report_blocks.size()); | 263 ASSERT_EQ(0u, rtcp_packet_info_.report_blocks.size()); |
228 } | 264 } |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 kRtcpXrVoipMetric), | 819 kRtcpXrVoipMetric), |
784 rtcp_packet_info_.rtcpPacketTypeFlags); | 820 rtcp_packet_info_.rtcpPacketTypeFlags); |
785 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item); | 821 EXPECT_FALSE(rtcp_packet_info_.xr_dlrr_item); |
786 } | 822 } |
787 | 823 |
788 TEST_F(RtcpReceiverTest, TestXrRrRttInitiallyFalse) { | 824 TEST_F(RtcpReceiverTest, TestXrRrRttInitiallyFalse) { |
789 int64_t rtt_ms; | 825 int64_t rtt_ms; |
790 EXPECT_FALSE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); | 826 EXPECT_FALSE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); |
791 } | 827 } |
792 | 828 |
793 TEST_F(RtcpReceiverTest, RttCalculatedAfterXrDlrr) { | 829 TEST_F(RtcpReceiverTest, XrDlrrCalculatesRtt) { |
794 Random rand(0x0123456789abcdef); | 830 Random rand(0x0123456789abcdef); |
795 const uint32_t kSourceSsrc = rand.Rand(0x00000001u, 0xfffffffeu); | 831 const uint32_t kSourceSsrc = rand.Rand(0x00000001u, 0xfffffffeu); |
796 const uint32_t kRttMs = rand.Rand(1, 18 * 3600 * 1000); | 832 const int64_t kRttMs = rand.Rand(1, 9 * 3600 * 1000); |
797 const uint32_t kDelayNtp = rand.Rand<uint32_t>(); | 833 const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff); |
798 const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp); | 834 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); |
| 835 rtcp_receiver_->SetRtcpXrRrtrStatus(true); |
799 std::set<uint32_t> ssrcs; | 836 std::set<uint32_t> ssrcs; |
800 ssrcs.insert(kSourceSsrc); | 837 ssrcs.insert(kSourceSsrc); |
801 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); | 838 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); |
802 NtpTime now(system_clock_); | 839 NtpTime now(system_clock_); |
803 uint32_t sent_ntp = CompactNtp(now); | 840 uint32_t sent_ntp = CompactNtp(now); |
804 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); | 841 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); |
805 | 842 |
806 rtcp::Dlrr dlrr; | 843 rtcp::Dlrr dlrr; |
807 dlrr.WithDlrrItem(kSourceSsrc, sent_ntp, kDelayNtp); | 844 dlrr.WithDlrrItem(kSourceSsrc, sent_ntp, kDelayNtp); |
808 rtcp::ExtendedReports xr; | 845 rtcp::ExtendedReports xr; |
809 xr.From(0x2345); | 846 xr.From(0x2345); |
810 xr.WithDlrr(dlrr); | 847 xr.WithDlrr(dlrr); |
811 rtc::Buffer packet = xr.Build(); | 848 rtc::Buffer packet = xr.Build(); |
812 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); | 849 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); |
813 | 850 |
814 int64_t rtt_ms = 0; | 851 int64_t rtt_ms = 0; |
815 EXPECT_TRUE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); | 852 EXPECT_TRUE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); |
816 EXPECT_NEAR(kRttMs, rtt_ms, 1); | 853 EXPECT_NEAR(kRttMs, rtt_ms, 1); |
817 } | 854 } |
818 | 855 |
| 856 TEST_F(RtcpReceiverTest, XrDlrrCalculatesNegativeRttAsOne) { |
| 857 Random rand(0x0123456789abcdef); |
| 858 const uint32_t kSourceSsrc = rand.Rand(0x00000001u, 0xfffffffeu); |
| 859 const int64_t kRttMs = rand.Rand(-3600 * 1000, -1); |
| 860 const uint32_t kDelayNtp = rand.Rand(0, 0x7fffffff); |
| 861 const int64_t kDelayMs = CompactNtpRttToMs(kDelayNtp); |
| 862 rtcp_receiver_->SetRtcpXrRrtrStatus(true); |
| 863 std::set<uint32_t> ssrcs; |
| 864 ssrcs.insert(kSourceSsrc); |
| 865 rtcp_receiver_->SetSsrcs(kSourceSsrc, ssrcs); |
| 866 NtpTime now(system_clock_); |
| 867 uint32_t sent_ntp = CompactNtp(now); |
| 868 system_clock_.AdvanceTimeMilliseconds(kRttMs + kDelayMs); |
| 869 |
| 870 rtcp::Dlrr dlrr; |
| 871 dlrr.WithDlrrItem(kSourceSsrc, sent_ntp, kDelayNtp); |
| 872 rtcp::ExtendedReports xr; |
| 873 xr.From(0x2345); |
| 874 xr.WithDlrr(dlrr); |
| 875 rtc::Buffer packet = xr.Build(); |
| 876 EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size())); |
| 877 |
| 878 int64_t rtt_ms = 0; |
| 879 EXPECT_TRUE(rtcp_receiver_->GetAndResetXrRrRtt(&rtt_ms)); |
| 880 EXPECT_EQ(1, rtt_ms); |
| 881 } |
| 882 |
819 TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) { | 883 TEST_F(RtcpReceiverTest, LastReceivedXrReferenceTimeInfoInitiallyFalse) { |
820 RtcpReceiveTimeInfo info; | 884 RtcpReceiveTimeInfo info; |
821 EXPECT_FALSE(rtcp_receiver_->LastReceivedXrReferenceTimeInfo(&info)); | 885 EXPECT_FALSE(rtcp_receiver_->LastReceivedXrReferenceTimeInfo(&info)); |
822 } | 886 } |
823 | 887 |
824 TEST_F(RtcpReceiverTest, GetLastReceivedExtendedReportsReferenceTimeInfo) { | 888 TEST_F(RtcpReceiverTest, GetLastReceivedExtendedReportsReferenceTimeInfo) { |
825 const uint32_t kSenderSsrc = 0x123456; | 889 const uint32_t kSenderSsrc = 0x123456; |
826 const NtpTime kNtp(0x10203, 0x40506); | 890 const NtpTime kNtp(0x10203, 0x40506); |
827 const uint32_t kNtpMid = CompactNtp(kNtp); | 891 const uint32_t kNtpMid = CompactNtp(kNtp); |
828 | 892 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 | 1215 |
1152 // Transport feedback should be ignored, but next packet should work. | 1216 // Transport feedback should be ignored, but next packet should work. |
1153 EXPECT_EQ(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback); | 1217 EXPECT_EQ(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpTransportFeedback); |
1154 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpRemb); | 1218 EXPECT_NE(0u, rtcp_packet_info_.rtcpPacketTypeFlags & kRtcpRemb); |
1155 EXPECT_EQ(kBitrateBps, rtcp_packet_info_.receiverEstimatedMaxBitrate); | 1219 EXPECT_EQ(kBitrateBps, rtcp_packet_info_.receiverEstimatedMaxBitrate); |
1156 } | 1220 } |
1157 | 1221 |
1158 } // Anonymous namespace | 1222 } // Anonymous namespace |
1159 | 1223 |
1160 } // namespace webrtc | 1224 } // namespace webrtc |
OLD | NEW |