OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/test/simple_test_tick_clock.h" | 5 #include "base/test/simple_test_tick_clock.h" |
6 #include "media/cast/cast_defines.h" | 6 #include "media/cast/cast_defines.h" |
| 7 #include "media/cast/cast_environment.h" |
7 #include "media/cast/pacing/paced_sender.h" | 8 #include "media/cast/pacing/paced_sender.h" |
8 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h" | 9 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h" |
9 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h" | 10 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h" |
10 #include "media/cast/rtcp/rtcp.h" | 11 #include "media/cast/rtcp/rtcp.h" |
11 #include "media/cast/rtcp/test_rtcp_packet_builder.h" | 12 #include "media/cast/rtcp/test_rtcp_packet_builder.h" |
| 13 #include "media/cast/test/fake_task_runner.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
13 | 15 |
14 namespace media { | 16 namespace media { |
15 namespace cast { | 17 namespace cast { |
16 | 18 |
17 using testing::_; | 19 using testing::_; |
18 | 20 |
19 static const uint32 kSenderSsrc = 0x10203; | 21 static const uint32 kSenderSsrc = 0x10203; |
20 static const uint32 kReceiverSsrc = 0x40506; | 22 static const uint32 kReceiverSsrc = 0x40506; |
21 static const uint32 kUnknownSsrc = 0xDEAD; | 23 static const uint32 kUnknownSsrc = 0xDEAD; |
22 static const std::string kCName("test@10.1.1.1"); | 24 static const std::string kCName("test@10.1.1.1"); |
23 static const uint32 kRtcpIntervalMs = 500; | 25 static const uint32 kRtcpIntervalMs = 500; |
24 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); | 26 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); |
25 static const int64 kAddedDelay = 123; | 27 static const int64 kAddedDelay = 123; |
26 static const int64 kAddedShortDelay= 100; | 28 static const int64 kAddedShortDelay= 100; |
27 | 29 |
28 class LocalRtcpTransport : public PacedPacketSender { | 30 class LocalRtcpTransport : public PacedPacketSender { |
29 public: | 31 public: |
30 explicit LocalRtcpTransport(base::SimpleTestTickClock* testing_clock) | 32 LocalRtcpTransport(scoped_refptr<CastEnvironment> cast_environment, |
| 33 base::SimpleTestTickClock* testing_clock) |
31 : short_delay_(false), | 34 : short_delay_(false), |
32 testing_clock_(testing_clock) {} | 35 testing_clock_(testing_clock) {} |
33 | 36 |
34 void SetRtcpReceiver(Rtcp* rtcp) { rtcp_ = rtcp; } | 37 void SetRtcpReceiver(Rtcp* rtcp) { rtcp_ = rtcp; } |
35 | 38 |
36 void SetShortDelay() { short_delay_ = true; } | 39 void SetShortDelay() { short_delay_ = true; } |
37 | 40 |
38 virtual bool SendRtcpPacket(const std::vector<uint8>& packet) OVERRIDE { | 41 virtual bool SendRtcpPacket(const std::vector<uint8>& packet) OVERRIDE { |
39 if (short_delay_) { | 42 if (short_delay_) { |
40 testing_clock_->Advance( | 43 testing_clock_->Advance( |
(...skipping 10 matching lines...) Expand all Loading... |
51 } | 54 } |
52 | 55 |
53 virtual bool ResendPackets(const PacketList& packets) OVERRIDE { | 56 virtual bool ResendPackets(const PacketList& packets) OVERRIDE { |
54 return false; | 57 return false; |
55 } | 58 } |
56 | 59 |
57 private: | 60 private: |
58 bool short_delay_; | 61 bool short_delay_; |
59 Rtcp* rtcp_; | 62 Rtcp* rtcp_; |
60 base::SimpleTestTickClock* testing_clock_; | 63 base::SimpleTestTickClock* testing_clock_; |
| 64 scoped_refptr<CastEnvironment> cast_environment_; |
61 }; | 65 }; |
62 | 66 |
63 class RtcpPeer : public Rtcp { | 67 class RtcpPeer : public Rtcp { |
64 public: | 68 public: |
65 RtcpPeer(base::TickClock* clock, | 69 RtcpPeer(scoped_refptr<CastEnvironment> cast_environment, |
66 RtcpSenderFeedback* sender_feedback, | 70 RtcpSenderFeedback* sender_feedback, |
67 PacedPacketSender* const paced_packet_sender, | 71 PacedPacketSender* const paced_packet_sender, |
68 RtpSenderStatistics* rtp_sender_statistics, | 72 RtpSenderStatistics* rtp_sender_statistics, |
69 RtpReceiverStatistics* rtp_receiver_statistics, | 73 RtpReceiverStatistics* rtp_receiver_statistics, |
70 RtcpMode rtcp_mode, | 74 RtcpMode rtcp_mode, |
71 const base::TimeDelta& rtcp_interval, | 75 const base::TimeDelta& rtcp_interval, |
72 bool sending_media, | 76 bool sending_media, |
73 uint32 local_ssrc, | 77 uint32 local_ssrc, |
74 const std::string& c_name) | 78 const std::string& c_name) |
75 : Rtcp(clock, | 79 : Rtcp(cast_environment, |
76 sender_feedback, | 80 sender_feedback, |
77 paced_packet_sender, | 81 paced_packet_sender, |
78 rtp_sender_statistics, | 82 rtp_sender_statistics, |
79 rtp_receiver_statistics, | 83 rtp_receiver_statistics, |
80 rtcp_mode, | 84 rtcp_mode, |
81 rtcp_interval, | 85 rtcp_interval, |
82 sending_media, | 86 sending_media, |
83 local_ssrc, | 87 local_ssrc, |
84 c_name) { | 88 c_name) { |
85 } | 89 } |
86 | 90 |
87 using Rtcp::CheckForWrapAround; | 91 using Rtcp::CheckForWrapAround; |
88 using Rtcp::OnReceivedLipSyncInfo; | 92 using Rtcp::OnReceivedLipSyncInfo; |
89 }; | 93 }; |
90 | 94 |
91 class RtcpTest : public ::testing::Test { | 95 class RtcpTest : public ::testing::Test { |
92 protected: | 96 protected: |
93 RtcpTest() | 97 RtcpTest() |
94 : transport_(&testing_clock_) { | 98 : task_runner_(new test::FakeTaskRunner(&testing_clock_)), |
| 99 cast_environment_(new CastEnvironment(&testing_clock_, task_runner_, |
| 100 task_runner_, task_runner_, task_runner_, task_runner_, |
| 101 false, false, false)), |
| 102 transport_(cast_environment_, &testing_clock_) { |
95 testing_clock_.Advance( | 103 testing_clock_.Advance( |
96 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 104 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
97 } | 105 } |
98 | 106 |
99 virtual ~RtcpTest() {} | 107 virtual ~RtcpTest() {} |
100 | 108 |
101 virtual void SetUp() { | 109 virtual void SetUp() { |
102 EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(0); | 110 EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(0); |
103 } | 111 } |
104 | 112 |
105 base::SimpleTestTickClock testing_clock_; | 113 base::SimpleTestTickClock testing_clock_; |
| 114 scoped_refptr<test::FakeTaskRunner> task_runner_; |
| 115 scoped_refptr<CastEnvironment> cast_environment_; |
106 LocalRtcpTransport transport_; | 116 LocalRtcpTransport transport_; |
107 MockRtcpSenderFeedback mock_sender_feedback_; | 117 MockRtcpSenderFeedback mock_sender_feedback_; |
108 }; | 118 }; |
109 | 119 |
110 TEST_F(RtcpTest, TimeToSend) { | 120 TEST_F(RtcpTest, TimeToSend) { |
111 base::TimeTicks start_time; | 121 base::TimeTicks start_time; |
112 start_time += base::TimeDelta::FromMilliseconds(kStartMillisecond); | 122 start_time += base::TimeDelta::FromMilliseconds(kStartMillisecond); |
113 Rtcp rtcp(&testing_clock_, | 123 Rtcp rtcp(cast_environment_, |
114 &mock_sender_feedback_, | 124 &mock_sender_feedback_, |
115 &transport_, | 125 &transport_, |
116 NULL, | 126 NULL, |
117 NULL, | 127 NULL, |
118 kRtcpCompound, | 128 kRtcpCompound, |
119 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 129 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
120 true, // Media sender. | 130 true, // Media sender. |
121 kSenderSsrc, | 131 kSenderSsrc, |
122 kCName); | 132 kCName); |
123 transport_.SetRtcpReceiver(&rtcp); | 133 transport_.SetRtcpReceiver(&rtcp); |
124 EXPECT_LE(start_time, rtcp.TimeToSendNextRtcpReport()); | 134 EXPECT_LE(start_time, rtcp.TimeToSendNextRtcpReport()); |
125 EXPECT_GE(start_time + base::TimeDelta::FromMilliseconds( | 135 EXPECT_GE(start_time + base::TimeDelta::FromMilliseconds( |
126 kRtcpIntervalMs * 3 / 2), | 136 kRtcpIntervalMs * 3 / 2), |
127 rtcp.TimeToSendNextRtcpReport()); | 137 rtcp.TimeToSendNextRtcpReport()); |
128 base::TimeDelta delta = rtcp.TimeToSendNextRtcpReport() - start_time; | 138 base::TimeDelta delta = rtcp.TimeToSendNextRtcpReport() - start_time; |
129 testing_clock_.Advance(delta); | 139 testing_clock_.Advance(delta); |
130 EXPECT_EQ(testing_clock_.NowTicks(), rtcp.TimeToSendNextRtcpReport()); | 140 EXPECT_EQ(testing_clock_.NowTicks(), rtcp.TimeToSendNextRtcpReport()); |
131 } | 141 } |
132 | 142 |
133 TEST_F(RtcpTest, BasicSenderReport) { | 143 TEST_F(RtcpTest, BasicSenderReport) { |
134 Rtcp rtcp(&testing_clock_, | 144 Rtcp rtcp(cast_environment_, |
135 &mock_sender_feedback_, | 145 &mock_sender_feedback_, |
136 &transport_, | 146 &transport_, |
137 NULL, | 147 NULL, |
138 NULL, | 148 NULL, |
139 kRtcpCompound, | 149 kRtcpCompound, |
140 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 150 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
141 true, // Media sender. | 151 true, // Media sender. |
142 kSenderSsrc, | 152 kSenderSsrc, |
143 kCName); | 153 kCName); |
144 transport_.SetRtcpReceiver(&rtcp); | 154 transport_.SetRtcpReceiver(&rtcp); |
145 rtcp.SendRtcpReport(kUnknownSsrc); | 155 rtcp.SendRtcpReport(kUnknownSsrc); |
146 } | 156 } |
147 | 157 |
148 TEST_F(RtcpTest, BasicReceiverReport) { | 158 TEST_F(RtcpTest, BasicReceiverReport) { |
149 Rtcp rtcp(&testing_clock_, | 159 Rtcp rtcp(cast_environment_, |
150 &mock_sender_feedback_, | 160 &mock_sender_feedback_, |
151 &transport_, | 161 &transport_, |
152 NULL, | 162 NULL, |
153 NULL, | 163 NULL, |
154 kRtcpCompound, | 164 kRtcpCompound, |
155 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 165 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
156 false, // Media receiver. | 166 false, // Media receiver. |
157 kSenderSsrc, | 167 kSenderSsrc, |
158 kCName); | 168 kCName); |
159 transport_.SetRtcpReceiver(&rtcp); | 169 transport_.SetRtcpReceiver(&rtcp); |
160 rtcp.SetRemoteSSRC(kSenderSsrc); | 170 rtcp.SetRemoteSSRC(kSenderSsrc); |
161 rtcp.SendRtcpReport(kSenderSsrc); | 171 rtcp.SendRtcpReport(kSenderSsrc); |
162 } | 172 } |
163 | 173 |
164 TEST_F(RtcpTest, BasicCast) { | 174 TEST_F(RtcpTest, BasicCast) { |
165 EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(1); | 175 EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(1); |
166 | 176 |
167 // Media receiver. | 177 // Media receiver. |
168 Rtcp rtcp(&testing_clock_, | 178 Rtcp rtcp(cast_environment_, |
169 &mock_sender_feedback_, | 179 &mock_sender_feedback_, |
170 &transport_, | 180 &transport_, |
171 NULL, | 181 NULL, |
172 NULL, | 182 NULL, |
173 kRtcpReducedSize, | 183 kRtcpReducedSize, |
174 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 184 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
175 false, | 185 false, |
176 kSenderSsrc, | 186 kSenderSsrc, |
177 kCName); | 187 kCName); |
178 transport_.SetRtcpReceiver(&rtcp); | 188 transport_.SetRtcpReceiver(&rtcp); |
179 rtcp.SetRemoteSSRC(kSenderSsrc); | 189 rtcp.SetRemoteSSRC(kSenderSsrc); |
180 RtcpCastMessage cast_message(kSenderSsrc); | 190 RtcpCastMessage cast_message(kSenderSsrc); |
181 cast_message.ack_frame_id_ = kAckFrameId; | 191 cast_message.ack_frame_id_ = kAckFrameId; |
182 PacketIdSet missing_packets; | 192 PacketIdSet missing_packets; |
183 cast_message.missing_frames_and_packets_[ | 193 cast_message.missing_frames_and_packets_[ |
184 kLostFrameId] = missing_packets; | 194 kLostFrameId] = missing_packets; |
185 | 195 |
186 missing_packets.insert(kLostPacketId1); | 196 missing_packets.insert(kLostPacketId1); |
187 missing_packets.insert(kLostPacketId2); | 197 missing_packets.insert(kLostPacketId2); |
188 missing_packets.insert(kLostPacketId3); | 198 missing_packets.insert(kLostPacketId3); |
189 cast_message.missing_frames_and_packets_[ | 199 cast_message.missing_frames_and_packets_[ |
190 kFrameIdWithLostPackets] = missing_packets; | 200 kFrameIdWithLostPackets] = missing_packets; |
191 rtcp.SendRtcpCast(cast_message); | 201 rtcp.SendRtcpCast(cast_message); |
192 } | 202 } |
193 | 203 |
194 TEST_F(RtcpTest, Rtt) { | 204 TEST_F(RtcpTest, Rtt) { |
195 // Media receiver. | 205 // Media receiver. |
196 LocalRtcpTransport receiver_transport(&testing_clock_); | 206 LocalRtcpTransport receiver_transport(cast_environment_, &testing_clock_); |
197 Rtcp rtcp_receiver(&testing_clock_, | 207 Rtcp rtcp_receiver(cast_environment_, |
198 &mock_sender_feedback_, | 208 &mock_sender_feedback_, |
199 &receiver_transport, | 209 &receiver_transport, |
200 NULL, | 210 NULL, |
201 NULL, | 211 NULL, |
202 kRtcpReducedSize, | 212 kRtcpReducedSize, |
203 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 213 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
204 false, | 214 false, |
205 kReceiverSsrc, | 215 kReceiverSsrc, |
206 kCName); | 216 kCName); |
207 | 217 |
208 // Media sender. | 218 // Media sender. |
209 LocalRtcpTransport sender_transport(&testing_clock_); | 219 LocalRtcpTransport sender_transport(cast_environment_, &testing_clock_); |
210 Rtcp rtcp_sender(&testing_clock_, | 220 Rtcp rtcp_sender(cast_environment_, |
211 &mock_sender_feedback_, | 221 &mock_sender_feedback_, |
212 &sender_transport, | 222 &sender_transport, |
213 NULL, | 223 NULL, |
214 NULL, | 224 NULL, |
215 kRtcpReducedSize, | 225 kRtcpReducedSize, |
216 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 226 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
217 true, | 227 true, |
218 kSenderSsrc, | 228 kSenderSsrc, |
219 kCName); | 229 kCName); |
220 | 230 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2); | 305 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2); |
296 EXPECT_EQ(input_time, out_2); // Verify inverse. | 306 EXPECT_EQ(input_time, out_2); // Verify inverse. |
297 | 307 |
298 // Verify delta. | 308 // Verify delta. |
299 EXPECT_EQ((out_2 - out_1), time_delta); | 309 EXPECT_EQ((out_2 - out_1), time_delta); |
300 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), GG_UINT32_C(1)); | 310 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), GG_UINT32_C(1)); |
301 EXPECT_NEAR((ntp_fractions_2 - ntp_fractions_1), 0xffffffff / 10, 1); | 311 EXPECT_NEAR((ntp_fractions_2 - ntp_fractions_1), 0xffffffff / 10, 1); |
302 } | 312 } |
303 | 313 |
304 TEST_F(RtcpTest, WrapAround) { | 314 TEST_F(RtcpTest, WrapAround) { |
305 RtcpPeer rtcp_peer(&testing_clock_, | 315 RtcpPeer rtcp_peer(cast_environment_, |
306 &mock_sender_feedback_, | 316 &mock_sender_feedback_, |
307 NULL, | 317 NULL, |
308 NULL, | 318 NULL, |
309 NULL, | 319 NULL, |
310 kRtcpReducedSize, | 320 kRtcpReducedSize, |
311 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 321 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
312 false, | 322 false, |
313 kReceiverSsrc, | 323 kReceiverSsrc, |
314 kCName); | 324 kCName); |
315 uint32 new_timestamp = 0; | 325 uint32 new_timestamp = 0; |
316 uint32 old_timestamp = 0; | 326 uint32 old_timestamp = 0; |
317 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); | 327 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); |
318 new_timestamp = 1234567890; | 328 new_timestamp = 1234567890; |
319 old_timestamp = 1234567000; | 329 old_timestamp = 1234567000; |
320 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); | 330 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); |
321 new_timestamp = 1234567000; | 331 new_timestamp = 1234567000; |
322 old_timestamp = 1234567890; | 332 old_timestamp = 1234567890; |
323 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); | 333 EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); |
324 new_timestamp = 123; | 334 new_timestamp = 123; |
325 old_timestamp = 4234567890u; | 335 old_timestamp = 4234567890u; |
326 EXPECT_EQ(1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); | 336 EXPECT_EQ(1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); |
327 new_timestamp = 4234567890u; | 337 new_timestamp = 4234567890u; |
328 old_timestamp = 123; | 338 old_timestamp = 123; |
329 EXPECT_EQ(-1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); | 339 EXPECT_EQ(-1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp)); |
330 } | 340 } |
331 | 341 |
332 TEST_F(RtcpTest, RtpTimestampInSenderTime) { | 342 TEST_F(RtcpTest, RtpTimestampInSenderTime) { |
333 RtcpPeer rtcp_peer(&testing_clock_, | 343 RtcpPeer rtcp_peer(cast_environment_, |
334 &mock_sender_feedback_, | 344 &mock_sender_feedback_, |
335 NULL, | 345 NULL, |
336 NULL, | 346 NULL, |
337 NULL, | 347 NULL, |
338 kRtcpReducedSize, | 348 kRtcpReducedSize, |
339 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), | 349 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), |
340 false, | 350 false, |
341 kReceiverSsrc, | 351 kReceiverSsrc, |
342 kCName); | 352 kCName); |
343 int frequency = 32000; | 353 int frequency = 32000; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); | 397 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); |
388 rtp_timestamp = 64000; | 398 rtp_timestamp = 64000; |
389 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, | 399 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, |
390 &rtp_timestamp_in_ticks)); | 400 &rtp_timestamp_in_ticks)); |
391 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000), | 401 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000), |
392 rtp_timestamp_in_ticks); | 402 rtp_timestamp_in_ticks); |
393 } | 403 } |
394 | 404 |
395 } // namespace cast | 405 } // namespace cast |
396 } // namespace media | 406 } // namespace media |
OLD | NEW |