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 |
11 #include <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/modules/pacing/paced_sender.h" | 16 #include "webrtc/modules/pacing/paced_sender.h" |
17 #include "webrtc/system_wrappers/include/clock.h" | 17 #include "webrtc/system_wrappers/include/clock.h" |
18 | 18 |
19 using testing::_; | 19 using testing::_; |
20 using testing::Return; | 20 using testing::Return; |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace test { | 23 namespace test { |
24 | 24 |
25 static const int kTargetBitrateBps = 800000; | 25 static const int kTargetBitrateBps = 800000; |
26 | 26 |
27 class MockPacedSenderCallback : public PacedSender::PacketSender { | 27 class MockPacedSenderCallback : public PacedSender::PacketSender { |
28 public: | 28 public: |
29 MOCK_METHOD4(TimeToSendPacket, | 29 MOCK_METHOD5(TimeToSendPacket, |
30 bool(uint32_t ssrc, | 30 bool(uint32_t ssrc, |
31 uint16_t sequence_number, | 31 uint16_t sequence_number, |
32 int64_t capture_time_ms, | 32 int64_t capture_time_ms, |
33 bool retransmission)); | 33 bool retransmission, |
| 34 int probe_cluster_id)); |
34 MOCK_METHOD1(TimeToSendPadding, | 35 MOCK_METHOD1(TimeToSendPadding, |
35 size_t(size_t bytes)); | 36 size_t(size_t bytes)); |
36 }; | 37 }; |
37 | 38 |
38 class PacedSenderPadding : public PacedSender::PacketSender { | 39 class PacedSenderPadding : public PacedSender::PacketSender { |
39 public: | 40 public: |
40 PacedSenderPadding() : padding_sent_(0) {} | 41 PacedSenderPadding() : padding_sent_(0) {} |
41 | 42 |
42 bool TimeToSendPacket(uint32_t ssrc, | 43 bool TimeToSendPacket(uint32_t ssrc, |
43 uint16_t sequence_number, | 44 uint16_t sequence_number, |
44 int64_t capture_time_ms, | 45 int64_t capture_time_ms, |
45 bool retransmission) { | 46 bool retransmission, |
| 47 int probe_cluster_id) override { |
46 return true; | 48 return true; |
47 } | 49 } |
48 | 50 |
49 size_t TimeToSendPadding(size_t bytes) { | 51 size_t TimeToSendPadding(size_t bytes) override { |
50 const size_t kPaddingPacketSize = 224; | 52 const size_t kPaddingPacketSize = 224; |
51 size_t num_packets = (bytes + kPaddingPacketSize - 1) / kPaddingPacketSize; | 53 size_t num_packets = (bytes + kPaddingPacketSize - 1) / kPaddingPacketSize; |
52 padding_sent_ += kPaddingPacketSize * num_packets; | 54 padding_sent_ += kPaddingPacketSize * num_packets; |
53 return kPaddingPacketSize * num_packets; | 55 return kPaddingPacketSize * num_packets; |
54 } | 56 } |
55 | 57 |
56 size_t padding_sent() { return padding_sent_; } | 58 size_t padding_sent() { return padding_sent_; } |
57 | 59 |
58 private: | 60 private: |
59 size_t padding_sent_; | 61 size_t padding_sent_; |
60 }; | 62 }; |
61 | 63 |
62 class PacedSenderProbing : public PacedSender::PacketSender { | 64 class PacedSenderProbing : public PacedSender::PacketSender { |
63 public: | 65 public: |
64 PacedSenderProbing(const std::list<int>& expected_deltas, Clock* clock) | 66 PacedSenderProbing(const std::list<int>& expected_deltas, Clock* clock) |
65 : prev_packet_time_ms_(-1), | 67 : prev_packet_time_ms_(-1), |
66 expected_deltas_(expected_deltas), | 68 expected_deltas_(expected_deltas), |
67 packets_sent_(0), | 69 packets_sent_(0), |
68 clock_(clock) {} | 70 clock_(clock) {} |
69 | 71 |
70 bool TimeToSendPacket(uint32_t ssrc, | 72 bool TimeToSendPacket(uint32_t ssrc, |
71 uint16_t sequence_number, | 73 uint16_t sequence_number, |
72 int64_t capture_time_ms, | 74 int64_t capture_time_ms, |
73 bool retransmission) { | 75 bool retransmission, |
| 76 int probe_cluster_id) override { |
74 ExpectAndCountPacket(); | 77 ExpectAndCountPacket(); |
75 return true; | 78 return true; |
76 } | 79 } |
77 | 80 |
78 size_t TimeToSendPadding(size_t bytes) { | 81 size_t TimeToSendPadding(size_t bytes) override { |
79 ExpectAndCountPacket(); | 82 ExpectAndCountPacket(); |
80 return bytes; | 83 return bytes; |
81 } | 84 } |
82 | 85 |
83 void ExpectAndCountPacket() { | 86 void ExpectAndCountPacket() { |
84 ++packets_sent_; | 87 ++packets_sent_; |
85 EXPECT_FALSE(expected_deltas_.empty()); | 88 EXPECT_FALSE(expected_deltas_.empty()); |
86 if (expected_deltas_.empty()) | 89 if (expected_deltas_.empty()) |
87 return; | 90 return; |
88 int64_t now_ms = clock_->TimeInMilliseconds(); | 91 int64_t now_ms = clock_->TimeInMilliseconds(); |
(...skipping 29 matching lines...) Expand all Loading... |
118 } | 121 } |
119 | 122 |
120 void SendAndExpectPacket(PacedSender::Priority priority, | 123 void SendAndExpectPacket(PacedSender::Priority priority, |
121 uint32_t ssrc, | 124 uint32_t ssrc, |
122 uint16_t sequence_number, | 125 uint16_t sequence_number, |
123 int64_t capture_time_ms, | 126 int64_t capture_time_ms, |
124 size_t size, | 127 size_t size, |
125 bool retransmission) { | 128 bool retransmission) { |
126 send_bucket_->InsertPacket(priority, ssrc, sequence_number, capture_time_ms, | 129 send_bucket_->InsertPacket(priority, ssrc, sequence_number, capture_time_ms, |
127 size, retransmission); | 130 size, retransmission); |
128 EXPECT_CALL(callback_, | 131 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, |
129 TimeToSendPacket(ssrc, sequence_number, capture_time_ms, false)) | 132 capture_time_ms, false, _)) |
130 .Times(1) | 133 .Times(1) |
131 .WillRepeatedly(Return(true)); | 134 .WillRepeatedly(Return(true)); |
132 } | 135 } |
133 | 136 |
134 SimulatedClock clock_; | 137 SimulatedClock clock_; |
135 MockPacedSenderCallback callback_; | 138 MockPacedSenderCallback callback_; |
136 std::unique_ptr<PacedSender> send_bucket_; | 139 std::unique_ptr<PacedSender> send_bucket_; |
137 }; | 140 }; |
138 | 141 |
139 TEST_F(PacedSenderTest, QueuePacket) { | 142 TEST_F(PacedSenderTest, QueuePacket) { |
(...skipping 15 matching lines...) Expand all Loading... |
155 false); | 158 false); |
156 EXPECT_EQ(packets_to_send + 1, send_bucket_->QueueSizePackets()); | 159 EXPECT_EQ(packets_to_send + 1, send_bucket_->QueueSizePackets()); |
157 send_bucket_->Process(); | 160 send_bucket_->Process(); |
158 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 161 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
159 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); | 162 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
160 clock_.AdvanceTimeMilliseconds(4); | 163 clock_.AdvanceTimeMilliseconds(4); |
161 EXPECT_EQ(1, send_bucket_->TimeUntilNextProcess()); | 164 EXPECT_EQ(1, send_bucket_->TimeUntilNextProcess()); |
162 clock_.AdvanceTimeMilliseconds(1); | 165 clock_.AdvanceTimeMilliseconds(1); |
163 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 166 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
164 EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); | 167 EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
165 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, | 168 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number++, |
166 queued_packet_timestamp, false)) | 169 queued_packet_timestamp, false, _)) |
167 .Times(1) | 170 .Times(1) |
168 .WillRepeatedly(Return(true)); | 171 .WillRepeatedly(Return(true)); |
169 send_bucket_->Process(); | 172 send_bucket_->Process(); |
170 sequence_number++; | 173 sequence_number++; |
171 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); | 174 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
172 | 175 |
173 // We can send packets_to_send -1 packets of size 250 during the current | 176 // We can send packets_to_send -1 packets of size 250 during the current |
174 // interval since one packet has already been sent. | 177 // interval since one packet has already been sent. |
175 for (size_t i = 0; i < packets_to_send - 1; ++i) { | 178 for (size_t i = 0; i < packets_to_send - 1; ++i) { |
176 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, | 179 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
(...skipping 28 matching lines...) Expand all Loading... |
205 } | 208 } |
206 EXPECT_EQ(packets_to_send_per_interval + packets_to_send_per_interval * 10, | 209 EXPECT_EQ(packets_to_send_per_interval + packets_to_send_per_interval * 10, |
207 send_bucket_->QueueSizePackets()); | 210 send_bucket_->QueueSizePackets()); |
208 send_bucket_->Process(); | 211 send_bucket_->Process(); |
209 EXPECT_EQ(packets_to_send_per_interval * 10, | 212 EXPECT_EQ(packets_to_send_per_interval * 10, |
210 send_bucket_->QueueSizePackets()); | 213 send_bucket_->QueueSizePackets()); |
211 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); | 214 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
212 for (int k = 0; k < 10; ++k) { | 215 for (int k = 0; k < 10; ++k) { |
213 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 216 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
214 clock_.AdvanceTimeMilliseconds(5); | 217 clock_.AdvanceTimeMilliseconds(5); |
215 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, _, false)) | 218 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, _, false, _)) |
216 .Times(packets_to_send_per_interval) | 219 .Times(packets_to_send_per_interval) |
217 .WillRepeatedly(Return(true)); | 220 .WillRepeatedly(Return(true)); |
218 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 221 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
219 send_bucket_->Process(); | 222 send_bucket_->Process(); |
220 } | 223 } |
221 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); | 224 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
222 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 225 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
223 clock_.AdvanceTimeMilliseconds(5); | 226 clock_.AdvanceTimeMilliseconds(5); |
224 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 227 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
225 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); | 228 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 250, false); | 265 250, false); |
263 } | 266 } |
264 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); | 267 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
265 send_bucket_->Process(); | 268 send_bucket_->Process(); |
266 for (int k = 0; k < 10; ++k) { | 269 for (int k = 0; k < 10; ++k) { |
267 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 270 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
268 clock_.AdvanceTimeMilliseconds(5); | 271 clock_.AdvanceTimeMilliseconds(5); |
269 | 272 |
270 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { | 273 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
271 EXPECT_CALL(callback_, | 274 EXPECT_CALL(callback_, |
272 TimeToSendPacket(ssrc, queued_sequence_number++, _, false)) | 275 TimeToSendPacket(ssrc, queued_sequence_number++, _, false, _)) |
273 .Times(1) | 276 .Times(1) |
274 .WillRepeatedly(Return(true)); | 277 .WillRepeatedly(Return(true)); |
275 } | 278 } |
276 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 279 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
277 send_bucket_->Process(); | 280 send_bucket_->Process(); |
278 } | 281 } |
279 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 282 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
280 clock_.AdvanceTimeMilliseconds(5); | 283 clock_.AdvanceTimeMilliseconds(5); |
281 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 284 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
282 send_bucket_->Process(); | 285 send_bucket_->Process(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 437 |
435 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { | 438 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
436 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, | 439 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
437 sequence_number++, capture_time_ms, 250, false); | 440 sequence_number++, capture_time_ms, 250, false); |
438 } | 441 } |
439 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, | 442 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, |
440 sequence_number++, capture_time_ms, 250, false); | 443 sequence_number++, capture_time_ms, 250, false); |
441 | 444 |
442 // Expect all high and normal priority to be sent out first. | 445 // Expect all high and normal priority to be sent out first. |
443 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); | 446 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
444 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, capture_time_ms, false)) | 447 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, capture_time_ms, false, _)) |
445 .Times(packets_to_send_per_interval + 1) | 448 .Times(packets_to_send_per_interval + 1) |
446 .WillRepeatedly(Return(true)); | 449 .WillRepeatedly(Return(true)); |
447 | 450 |
448 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 451 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
449 clock_.AdvanceTimeMilliseconds(5); | 452 clock_.AdvanceTimeMilliseconds(5); |
450 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 453 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
451 send_bucket_->Process(); | 454 send_bucket_->Process(); |
452 EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); | 455 EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
453 | 456 |
454 EXPECT_CALL(callback_, | 457 EXPECT_CALL(callback_, |
455 TimeToSendPacket( | 458 TimeToSendPacket(ssrc_low_priority, _, |
456 ssrc_low_priority, _, capture_time_ms_low_priority, false)) | 459 capture_time_ms_low_priority, false, _)) |
457 .Times(1) | 460 .Times(1) |
458 .WillRepeatedly(Return(true)); | 461 .WillRepeatedly(Return(true)); |
459 | 462 |
460 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 463 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
461 clock_.AdvanceTimeMilliseconds(5); | 464 clock_.AdvanceTimeMilliseconds(5); |
462 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 465 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
463 send_bucket_->Process(); | 466 send_bucket_->Process(); |
464 } | 467 } |
465 | 468 |
466 TEST_F(PacedSenderTest, HighPrioDoesntAffectBudget) { | 469 TEST_F(PacedSenderTest, HighPrioDoesntAffectBudget) { |
(...skipping 17 matching lines...) Expand all Loading... |
484 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { | 487 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
485 SendAndExpectPacket(PacedSender::kLowPriority, ssrc, sequence_number++, | 488 SendAndExpectPacket(PacedSender::kLowPriority, ssrc, sequence_number++, |
486 clock_.TimeInMilliseconds(), 250, false); | 489 clock_.TimeInMilliseconds(), 250, false); |
487 } | 490 } |
488 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc, sequence_number, | 491 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc, sequence_number, |
489 capture_time_ms, 250, false); | 492 capture_time_ms, 250, false); |
490 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 493 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
491 clock_.AdvanceTimeMilliseconds(5); | 494 clock_.AdvanceTimeMilliseconds(5); |
492 send_bucket_->Process(); | 495 send_bucket_->Process(); |
493 EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); | 496 EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
494 EXPECT_CALL(callback_, | 497 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number++, |
495 TimeToSendPacket(ssrc, sequence_number++, capture_time_ms, false)) | 498 capture_time_ms, false, _)) |
496 .Times(1) | 499 .Times(1) |
497 .WillRepeatedly(Return(true)); | 500 .WillRepeatedly(Return(true)); |
498 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 501 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
499 clock_.AdvanceTimeMilliseconds(5); | 502 clock_.AdvanceTimeMilliseconds(5); |
500 send_bucket_->Process(); | 503 send_bucket_->Process(); |
501 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); | 504 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
502 } | 505 } |
503 | 506 |
504 TEST_F(PacedSenderTest, Pause) { | 507 TEST_F(PacedSenderTest, Pause) { |
505 uint32_t ssrc_low_priority = 12345; | 508 uint32_t ssrc_low_priority = 12345; |
(...skipping 30 matching lines...) Expand all Loading... |
536 // Expect everything to be queued. | 539 // Expect everything to be queued. |
537 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc_low_priority, | 540 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc_low_priority, |
538 sequence_number++, second_capture_time_ms, 250, | 541 sequence_number++, second_capture_time_ms, 250, |
539 false); | 542 false); |
540 | 543 |
541 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms, | 544 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms, |
542 send_bucket_->QueueInMs()); | 545 send_bucket_->QueueInMs()); |
543 | 546 |
544 // Expect no packet to come out while paused. | 547 // Expect no packet to come out while paused. |
545 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); | 548 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
546 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _)).Times(0); | 549 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _, _)).Times(0); |
547 | 550 |
548 for (int i = 0; i < 10; ++i) { | 551 for (int i = 0; i < 10; ++i) { |
549 clock_.AdvanceTimeMilliseconds(5); | 552 clock_.AdvanceTimeMilliseconds(5); |
550 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 553 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
551 send_bucket_->Process(); | 554 send_bucket_->Process(); |
552 } | 555 } |
553 // Expect high prio packets to come out first followed by all packets in the | 556 // Expect high prio packets to come out first followed by all packets in the |
554 // way they were added. | 557 // way they were added. |
555 EXPECT_CALL(callback_, TimeToSendPacket(_, _, capture_time_ms, false)) | 558 EXPECT_CALL(callback_, TimeToSendPacket(_, _, capture_time_ms, false, _)) |
556 .Times(3) | 559 .Times(3) |
557 .WillRepeatedly(Return(true)); | 560 .WillRepeatedly(Return(true)); |
558 EXPECT_CALL(callback_, TimeToSendPacket(_, _, second_capture_time_ms, false)) | 561 EXPECT_CALL(callback_, |
| 562 TimeToSendPacket(_, _, second_capture_time_ms, false, _)) |
559 .Times(1) | 563 .Times(1) |
560 .WillRepeatedly(Return(true)); | 564 .WillRepeatedly(Return(true)); |
561 send_bucket_->Resume(); | 565 send_bucket_->Resume(); |
562 | 566 |
563 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); | 567 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
564 clock_.AdvanceTimeMilliseconds(5); | 568 clock_.AdvanceTimeMilliseconds(5); |
565 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); | 569 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
566 send_bucket_->Process(); | 570 send_bucket_->Process(); |
567 | 571 |
568 EXPECT_EQ(0, send_bucket_->QueueInMs()); | 572 EXPECT_EQ(0, send_bucket_->QueueInMs()); |
569 } | 573 } |
570 | 574 |
571 TEST_F(PacedSenderTest, ResendPacket) { | 575 TEST_F(PacedSenderTest, ResendPacket) { |
572 uint32_t ssrc = 12346; | 576 uint32_t ssrc = 12346; |
573 uint16_t sequence_number = 1234; | 577 uint16_t sequence_number = 1234; |
574 int64_t capture_time_ms = clock_.TimeInMilliseconds(); | 578 int64_t capture_time_ms = clock_.TimeInMilliseconds(); |
575 EXPECT_EQ(0, send_bucket_->QueueInMs()); | 579 EXPECT_EQ(0, send_bucket_->QueueInMs()); |
576 | 580 |
577 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, | 581 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
578 sequence_number, capture_time_ms, 250, false); | 582 sequence_number, capture_time_ms, 250, false); |
579 clock_.AdvanceTimeMilliseconds(1); | 583 clock_.AdvanceTimeMilliseconds(1); |
580 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, | 584 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
581 sequence_number + 1, capture_time_ms + 1, 250, | 585 sequence_number + 1, capture_time_ms + 1, 250, |
582 false); | 586 false); |
583 clock_.AdvanceTimeMilliseconds(9999); | 587 clock_.AdvanceTimeMilliseconds(9999); |
584 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms, | 588 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms, |
585 send_bucket_->QueueInMs()); | 589 send_bucket_->QueueInMs()); |
586 // Fails to send first packet so only one call. | 590 // Fails to send first packet so only one call. |
587 EXPECT_CALL(callback_, | 591 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, |
588 TimeToSendPacket(ssrc, sequence_number, capture_time_ms, false)) | 592 capture_time_ms, false, _)) |
589 .Times(1) | 593 .Times(1) |
590 .WillOnce(Return(false)); | 594 .WillOnce(Return(false)); |
591 clock_.AdvanceTimeMilliseconds(10000); | 595 clock_.AdvanceTimeMilliseconds(10000); |
592 send_bucket_->Process(); | 596 send_bucket_->Process(); |
593 | 597 |
594 // Queue remains unchanged. | 598 // Queue remains unchanged. |
595 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms, | 599 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms, |
596 send_bucket_->QueueInMs()); | 600 send_bucket_->QueueInMs()); |
597 | 601 |
598 // Fails to send second packet. | 602 // Fails to send second packet. |
599 EXPECT_CALL(callback_, | 603 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, |
600 TimeToSendPacket(ssrc, sequence_number, capture_time_ms, false)) | 604 capture_time_ms, false, _)) |
601 .Times(1) | 605 .Times(1) |
602 .WillOnce(Return(true)); | 606 .WillOnce(Return(true)); |
603 EXPECT_CALL( | 607 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number + 1, |
604 callback_, | 608 capture_time_ms + 1, false, _)) |
605 TimeToSendPacket(ssrc, sequence_number + 1, capture_time_ms + 1, false)) | |
606 .Times(1) | 609 .Times(1) |
607 .WillOnce(Return(false)); | 610 .WillOnce(Return(false)); |
608 clock_.AdvanceTimeMilliseconds(10000); | 611 clock_.AdvanceTimeMilliseconds(10000); |
609 send_bucket_->Process(); | 612 send_bucket_->Process(); |
610 | 613 |
611 // Queue is reduced by 1 packet. | 614 // Queue is reduced by 1 packet. |
612 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms - 1, | 615 EXPECT_EQ(clock_.TimeInMilliseconds() - capture_time_ms - 1, |
613 send_bucket_->QueueInMs()); | 616 send_bucket_->QueueInMs()); |
614 | 617 |
615 // Send second packet and queue becomes empty. | 618 // Send second packet and queue becomes empty. |
616 EXPECT_CALL( | 619 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number + 1, |
617 callback_, | 620 capture_time_ms + 1, false, _)) |
618 TimeToSendPacket(ssrc, sequence_number + 1, capture_time_ms + 1, false)) | |
619 .Times(1) | 621 .Times(1) |
620 .WillOnce(Return(true)); | 622 .WillOnce(Return(true)); |
621 clock_.AdvanceTimeMilliseconds(10000); | 623 clock_.AdvanceTimeMilliseconds(10000); |
622 send_bucket_->Process(); | 624 send_bucket_->Process(); |
623 EXPECT_EQ(0, send_bucket_->QueueInMs()); | 625 EXPECT_EQ(0, send_bucket_->QueueInMs()); |
624 } | 626 } |
625 | 627 |
626 TEST_F(PacedSenderTest, ExpectedQueueTimeMs) { | 628 TEST_F(PacedSenderTest, ExpectedQueueTimeMs) { |
627 uint32_t ssrc = 12346; | 629 uint32_t ssrc = 12346; |
628 uint16_t sequence_number = 1234; | 630 uint16_t sequence_number = 1234; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, sequence_number, | 763 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, sequence_number, |
762 clock_.TimeInMilliseconds(), kPacketSize, true); | 764 clock_.TimeInMilliseconds(), kPacketSize, true); |
763 | 765 |
764 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, | 766 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, |
765 sequence_number + 1, clock_.TimeInMilliseconds(), | 767 sequence_number + 1, clock_.TimeInMilliseconds(), |
766 kPacketSize, true); | 768 kPacketSize, true); |
767 | 769 |
768 // Packets from earlier frames should be sent first. | 770 // Packets from earlier frames should be sent first. |
769 { | 771 { |
770 ::testing::InSequence sequence; | 772 ::testing::InSequence sequence; |
771 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, | 773 EXPECT_CALL(callback_, |
772 clock_.TimeInMilliseconds(), true)) | 774 TimeToSendPacket(ssrc, sequence_number, |
| 775 clock_.TimeInMilliseconds(), true, _)) |
773 .WillOnce(Return(true)); | 776 .WillOnce(Return(true)); |
774 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number + 1, | 777 EXPECT_CALL(callback_, |
775 clock_.TimeInMilliseconds(), true)) | 778 TimeToSendPacket(ssrc, sequence_number + 1, |
| 779 clock_.TimeInMilliseconds(), true, _)) |
776 .WillOnce(Return(true)); | 780 .WillOnce(Return(true)); |
777 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number + 3, | 781 EXPECT_CALL(callback_, |
778 clock_.TimeInMilliseconds() + 33, | 782 TimeToSendPacket(ssrc, sequence_number + 3, |
779 true)).WillOnce(Return(true)); | 783 clock_.TimeInMilliseconds() + 33, true, _)) |
780 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number + 2, | 784 .WillOnce(Return(true)); |
781 clock_.TimeInMilliseconds() + 33, | 785 EXPECT_CALL(callback_, |
782 true)).WillOnce(Return(true)); | 786 TimeToSendPacket(ssrc, sequence_number + 2, |
| 787 clock_.TimeInMilliseconds() + 33, true, _)) |
| 788 .WillOnce(Return(true)); |
783 | 789 |
784 while (send_bucket_->QueueSizePackets() > 0) { | 790 while (send_bucket_->QueueSizePackets() > 0) { |
785 int time_until_process = send_bucket_->TimeUntilNextProcess(); | 791 int time_until_process = send_bucket_->TimeUntilNextProcess(); |
786 if (time_until_process <= 0) { | 792 if (time_until_process <= 0) { |
787 send_bucket_->Process(); | 793 send_bucket_->Process(); |
788 } else { | 794 } else { |
789 clock_.AdvanceTimeMilliseconds(time_until_process); | 795 clock_.AdvanceTimeMilliseconds(time_until_process); |
790 } | 796 } |
791 } | 797 } |
792 } | 798 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, | 842 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
837 sequence_number + 1, clock_.TimeInMilliseconds(), | 843 sequence_number + 1, clock_.TimeInMilliseconds(), |
838 kPacketSize, false); | 844 kPacketSize, false); |
839 clock_.AdvanceTimeMilliseconds(10); | 845 clock_.AdvanceTimeMilliseconds(10); |
840 | 846 |
841 EXPECT_EQ((20 + 10) / 2, send_bucket_->AverageQueueTimeMs()); | 847 EXPECT_EQ((20 + 10) / 2, send_bucket_->AverageQueueTimeMs()); |
842 | 848 |
843 // Only first packet (queued for 20ms) should be removed, leave the second | 849 // Only first packet (queued for 20ms) should be removed, leave the second |
844 // packet (queued for 10ms) alone in the queue. | 850 // packet (queued for 10ms) alone in the queue. |
845 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, | 851 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, |
846 first_capture_time, false)) | 852 first_capture_time, false, _)) |
847 .Times(1) | 853 .Times(1) |
848 .WillRepeatedly(Return(true)); | 854 .WillRepeatedly(Return(true)); |
849 send_bucket_->Process(); | 855 send_bucket_->Process(); |
850 | 856 |
851 EXPECT_EQ(10, send_bucket_->AverageQueueTimeMs()); | 857 EXPECT_EQ(10, send_bucket_->AverageQueueTimeMs()); |
852 | 858 |
853 clock_.AdvanceTimeMilliseconds(10); | 859 clock_.AdvanceTimeMilliseconds(10); |
854 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number + 1, | 860 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number + 1, |
855 first_capture_time + 10, false)) | 861 first_capture_time + 10, false, _)) |
856 .Times(1) | 862 .Times(1) |
857 .WillRepeatedly(Return(true)); | 863 .WillRepeatedly(Return(true)); |
858 for (int i = 0; i < 3; ++i) { | 864 for (int i = 0; i < 3; ++i) { |
859 clock_.AdvanceTimeMilliseconds(30); // Max delta. | 865 clock_.AdvanceTimeMilliseconds(30); // Max delta. |
860 send_bucket_->Process(); | 866 send_bucket_->Process(); |
861 } | 867 } |
862 | 868 |
863 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs()); | 869 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs()); |
864 } | 870 } |
865 | 871 |
| 872 TEST_F(PacedSenderTest, ProbeClusterId) { |
| 873 uint32_t ssrc = 12346; |
| 874 uint16_t sequence_number = 1234; |
| 875 const size_t kPacketSize = 1200; |
| 876 |
| 877 send_bucket_->SetProbingEnabled(true); |
| 878 for (int i = 0; i < 11; ++i) { |
| 879 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
| 880 sequence_number + i, clock_.TimeInMilliseconds(), |
| 881 kPacketSize, false); |
| 882 } |
| 883 |
| 884 // First probing cluster. |
| 885 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _, 0)) |
| 886 .Times(6) |
| 887 .WillRepeatedly(Return(true)); |
| 888 for (int i = 0; i < 6; ++i) |
| 889 send_bucket_->Process(); |
| 890 |
| 891 // Second probing cluster. |
| 892 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _, 1)) |
| 893 .Times(5) |
| 894 .WillRepeatedly(Return(true)); |
| 895 for (int i = 0; i < 5; ++i) |
| 896 send_bucket_->Process(); |
| 897 |
| 898 // No more probing packets. |
| 899 EXPECT_CALL(callback_, TimeToSendPadding(_)) |
| 900 .Times(1); |
| 901 send_bucket_->Process(); |
| 902 } |
| 903 |
866 } // namespace test | 904 } // namespace test |
867 } // namespace webrtc | 905 } // namespace webrtc |
OLD | NEW |