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

Side by Side Diff: webrtc/modules/pacing/paced_sender_unittest.cc

Issue 1958053002: Revert "Reland of Remove SendPacer from ViEEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 7 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
« no previous file with comments | « webrtc/modules/pacing/paced_sender.cc ('k') | webrtc/modules/pacing/packet_router.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 kTargetBitrate = 800;
26 static const float kPaceMultiplier = 1.5f;
26 27
27 class MockPacedSenderCallback : public PacedSender::PacketSender { 28 class MockPacedSenderCallback : public PacedSender::Callback {
28 public: 29 public:
29 MOCK_METHOD4(TimeToSendPacket, 30 MOCK_METHOD4(TimeToSendPacket,
30 bool(uint32_t ssrc, 31 bool(uint32_t ssrc,
31 uint16_t sequence_number, 32 uint16_t sequence_number,
32 int64_t capture_time_ms, 33 int64_t capture_time_ms,
33 bool retransmission)); 34 bool retransmission));
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::Callback {
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) {
46 return true; 47 return true;
47 } 48 }
48 49
49 size_t TimeToSendPadding(size_t bytes) { 50 size_t TimeToSendPadding(size_t bytes) {
50 const size_t kPaddingPacketSize = 224; 51 const size_t kPaddingPacketSize = 224;
51 size_t num_packets = (bytes + kPaddingPacketSize - 1) / kPaddingPacketSize; 52 size_t num_packets = (bytes + kPaddingPacketSize - 1) / kPaddingPacketSize;
52 padding_sent_ += kPaddingPacketSize * num_packets; 53 padding_sent_ += kPaddingPacketSize * num_packets;
53 return kPaddingPacketSize * num_packets; 54 return kPaddingPacketSize * num_packets;
54 } 55 }
55 56
56 size_t padding_sent() { return padding_sent_; } 57 size_t padding_sent() { return padding_sent_; }
57 58
58 private: 59 private:
59 size_t padding_sent_; 60 size_t padding_sent_;
60 }; 61 };
61 62
62 class PacedSenderProbing : public PacedSender::PacketSender { 63 class PacedSenderProbing : public PacedSender::Callback {
63 public: 64 public:
64 PacedSenderProbing(const std::list<int>& expected_deltas, Clock* clock) 65 PacedSenderProbing(const std::list<int>& expected_deltas, Clock* clock)
65 : prev_packet_time_ms_(-1), 66 : prev_packet_time_ms_(-1),
66 expected_deltas_(expected_deltas), 67 expected_deltas_(expected_deltas),
67 packets_sent_(0), 68 packets_sent_(0),
68 clock_(clock) {} 69 clock_(clock) {}
69 70
70 bool TimeToSendPacket(uint32_t ssrc, 71 bool TimeToSendPacket(uint32_t ssrc,
71 uint16_t sequence_number, 72 uint16_t sequence_number,
72 int64_t capture_time_ms, 73 int64_t capture_time_ms,
(...skipping 27 matching lines...) Expand all
100 std::list<int> expected_deltas_; 101 std::list<int> expected_deltas_;
101 int packets_sent_; 102 int packets_sent_;
102 Clock* clock_; 103 Clock* clock_;
103 }; 104 };
104 105
105 class PacedSenderTest : public ::testing::Test { 106 class PacedSenderTest : public ::testing::Test {
106 protected: 107 protected:
107 PacedSenderTest() : clock_(123456) { 108 PacedSenderTest() : clock_(123456) {
108 srand(0); 109 srand(0);
109 // Need to initialize PacedSender after we initialize clock. 110 // Need to initialize PacedSender after we initialize clock.
110 send_bucket_.reset(new PacedSender(&clock_, &callback_, kTargetBitrateBps)); 111 send_bucket_.reset(new PacedSender(&clock_,
112 &callback_,
113 kTargetBitrate,
114 kPaceMultiplier * kTargetBitrate,
115 0));
111 // Default to bitrate probing disabled for testing purposes. Probing tests 116 // Default to bitrate probing disabled for testing purposes. Probing tests
112 // have to enable probing, either by creating a new PacedSender instance or 117 // have to enable probing, either by creating a new PacedSender instance or
113 // by calling SetProbingEnabled(true). 118 // by calling SetProbingEnabled(true).
114 send_bucket_->SetProbingEnabled(false); 119 send_bucket_->SetProbingEnabled(false);
115 } 120 }
116 121
117 void SendAndExpectPacket(PacedSender::Priority priority, 122 void SendAndExpectPacket(PacedSender::Priority priority,
118 uint32_t ssrc, 123 uint32_t ssrc,
119 uint16_t sequence_number, 124 uint16_t sequence_number,
120 int64_t capture_time_ms, 125 int64_t capture_time_ms,
121 size_t size, 126 size_t size,
122 bool retransmission) { 127 bool retransmission) {
123 send_bucket_->InsertPacket(priority, ssrc, sequence_number, capture_time_ms, 128 send_bucket_->InsertPacket(priority, ssrc, sequence_number, capture_time_ms,
124 size, retransmission); 129 size, retransmission);
125 EXPECT_CALL(callback_, 130 EXPECT_CALL(callback_,
126 TimeToSendPacket(ssrc, sequence_number, capture_time_ms, false)) 131 TimeToSendPacket(ssrc, sequence_number, capture_time_ms, false))
127 .Times(1) 132 .Times(1)
128 .WillRepeatedly(Return(true)); 133 .WillRepeatedly(Return(true));
129 } 134 }
130 135
131 SimulatedClock clock_; 136 SimulatedClock clock_;
132 MockPacedSenderCallback callback_; 137 MockPacedSenderCallback callback_;
133 std::unique_ptr<PacedSender> send_bucket_; 138 std::unique_ptr<PacedSender> send_bucket_;
134 }; 139 };
135 140
136 TEST_F(PacedSenderTest, QueuePacket) { 141 TEST_F(PacedSenderTest, QueuePacket) {
137 uint32_t ssrc = 12345; 142 uint32_t ssrc = 12345;
138 uint16_t sequence_number = 1234; 143 uint16_t sequence_number = 1234;
139 // Due to the multiplicative factor we can send 5 packets during a send 144 // Due to the multiplicative factor we can send 3 packets not 2 packets.
140 // interval. (network capacity * multiplier / (8 bits per byte * 145 SendAndExpectPacket(PacedSender::kNormalPriority,
141 // (packet size * #send intervals per second) 146 ssrc,
142 const size_t packets_to_send = 147 sequence_number++,
143 kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); 148 clock_.TimeInMilliseconds(),
144 for (size_t i = 0; i < packets_to_send; ++i) { 149 250,
145 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 150 false);
146 clock_.TimeInMilliseconds(), 250, false); 151 SendAndExpectPacket(PacedSender::kNormalPriority,
147 } 152 ssrc,
148 153 sequence_number++,
154 clock_.TimeInMilliseconds(),
155 250,
156 false);
157 SendAndExpectPacket(PacedSender::kNormalPriority,
158 ssrc,
159 sequence_number++,
160 clock_.TimeInMilliseconds(),
161 250,
162 false);
149 int64_t queued_packet_timestamp = clock_.TimeInMilliseconds(); 163 int64_t queued_packet_timestamp = clock_.TimeInMilliseconds();
150 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 164 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
151 sequence_number, queued_packet_timestamp, 250, 165 sequence_number, queued_packet_timestamp, 250,
152 false); 166 false);
153 EXPECT_EQ(packets_to_send + 1, send_bucket_->QueueSizePackets());
154 send_bucket_->Process(); 167 send_bucket_->Process();
155 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 168 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
156 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); 169 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0);
157 clock_.AdvanceTimeMilliseconds(4); 170 clock_.AdvanceTimeMilliseconds(4);
158 EXPECT_EQ(1, send_bucket_->TimeUntilNextProcess()); 171 EXPECT_EQ(1, send_bucket_->TimeUntilNextProcess());
159 clock_.AdvanceTimeMilliseconds(1); 172 clock_.AdvanceTimeMilliseconds(1);
160 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 173 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
161 EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); 174 EXPECT_CALL(
162 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, 175 callback_,
163 queued_packet_timestamp, false)) 176 TimeToSendPacket(ssrc, sequence_number++, queued_packet_timestamp, false))
164 .Times(1) 177 .Times(1)
165 .WillRepeatedly(Return(true)); 178 .WillRepeatedly(Return(true));
166 send_bucket_->Process(); 179 send_bucket_->Process();
167 sequence_number++; 180 sequence_number++;
168 EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); 181 SendAndExpectPacket(PacedSender::kNormalPriority,
169 182 ssrc,
170 // We can send packets_to_send -1 packets of size 250 during the current 183 sequence_number++,
171 // interval since one packet has already been sent. 184 clock_.TimeInMilliseconds(),
172 for (size_t i = 0; i < packets_to_send - 1; ++i) { 185 250,
173 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 186 false);
174 clock_.TimeInMilliseconds(), 250, false); 187 SendAndExpectPacket(PacedSender::kNormalPriority,
175 } 188 ssrc,
189 sequence_number++,
190 clock_.TimeInMilliseconds(),
191 250,
192 false);
176 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 193 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
177 sequence_number++, clock_.TimeInMilliseconds(), 194 sequence_number++, clock_.TimeInMilliseconds(),
178 250, false); 195 250, false);
179 EXPECT_EQ(packets_to_send, send_bucket_->QueueSizePackets());
180 send_bucket_->Process(); 196 send_bucket_->Process();
181 EXPECT_EQ(1u, send_bucket_->QueueSizePackets());
182 } 197 }
183 198
184 TEST_F(PacedSenderTest, PaceQueuedPackets) { 199 TEST_F(PacedSenderTest, PaceQueuedPackets) {
185 uint32_t ssrc = 12345; 200 uint32_t ssrc = 12345;
186 uint16_t sequence_number = 1234; 201 uint16_t sequence_number = 1234;
187 202
188 // Due to the multiplicative factor we can send 5 packets during a send 203 // Due to the multiplicative factor we can send 3 packets not 2 packets.
189 // interval. (network capacity * multiplier / (8 bits per byte * 204 for (int i = 0; i < 3; ++i) {
190 // (packet size * #send intervals per second) 205 SendAndExpectPacket(PacedSender::kNormalPriority,
191 const size_t packets_to_send_per_interval = 206 ssrc,
192 kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); 207 sequence_number++,
193 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 208 clock_.TimeInMilliseconds(),
194 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 209 250,
195 clock_.TimeInMilliseconds(), 250, false); 210 false);
196 } 211 }
197 212 for (int j = 0; j < 30; ++j) {
198 for (size_t j = 0; j < packets_to_send_per_interval * 10; ++j) {
199 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 213 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
200 sequence_number++, clock_.TimeInMilliseconds(), 214 sequence_number++, clock_.TimeInMilliseconds(),
201 250, false); 215 250, false);
202 } 216 }
203 EXPECT_EQ(packets_to_send_per_interval + packets_to_send_per_interval * 10,
204 send_bucket_->QueueSizePackets());
205 send_bucket_->Process(); 217 send_bucket_->Process();
206 EXPECT_EQ(packets_to_send_per_interval * 10,
207 send_bucket_->QueueSizePackets());
208 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); 218 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0);
209 for (int k = 0; k < 10; ++k) { 219 for (int k = 0; k < 10; ++k) {
210 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 220 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
211 clock_.AdvanceTimeMilliseconds(5); 221 clock_.AdvanceTimeMilliseconds(5);
212 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, _, false)) 222 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, _, false))
213 .Times(packets_to_send_per_interval) 223 .Times(3)
214 .WillRepeatedly(Return(true)); 224 .WillRepeatedly(Return(true));
215 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 225 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
216 send_bucket_->Process(); 226 send_bucket_->Process();
217 } 227 }
218 EXPECT_EQ(0u, send_bucket_->QueueSizePackets());
219 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 228 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
220 clock_.AdvanceTimeMilliseconds(5); 229 clock_.AdvanceTimeMilliseconds(5);
221 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 230 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
222 EXPECT_EQ(0u, send_bucket_->QueueSizePackets());
223 send_bucket_->Process(); 231 send_bucket_->Process();
224 232 SendAndExpectPacket(PacedSender::kNormalPriority,
225 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 233 ssrc,
226 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 234 sequence_number++,
227 clock_.TimeInMilliseconds(), 250, false); 235 clock_.TimeInMilliseconds(),
228 } 236 250,
237 false);
238 SendAndExpectPacket(PacedSender::kNormalPriority,
239 ssrc,
240 sequence_number++,
241 clock_.TimeInMilliseconds(),
242 250,
243 false);
244 SendAndExpectPacket(PacedSender::kNormalPriority,
245 ssrc,
246 sequence_number++,
247 clock_.TimeInMilliseconds(),
248 250,
249 false);
229 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 250 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
230 sequence_number, clock_.TimeInMilliseconds(), 250, 251 sequence_number, clock_.TimeInMilliseconds(), 250,
231 false); 252 false);
232 send_bucket_->Process(); 253 send_bucket_->Process();
233 EXPECT_EQ(1u, send_bucket_->QueueSizePackets());
234 } 254 }
235 255
236 TEST_F(PacedSenderTest, PaceQueuedPacketsWithDuplicates) { 256 TEST_F(PacedSenderTest, PaceQueuedPacketsWithDuplicates) {
237 uint32_t ssrc = 12345; 257 uint32_t ssrc = 12345;
238 uint16_t sequence_number = 1234; 258 uint16_t sequence_number = 1234;
239 uint16_t queued_sequence_number; 259 uint16_t queued_sequence_number;
240 260
241 // Due to the multiplicative factor we can send 5 packets during a send 261 // Due to the multiplicative factor we can send 3 packets not 2 packets.
242 // interval. (network capacity * multiplier / (8 bits per byte * 262 for (int i = 0; i < 3; ++i) {
243 // (packet size * #send intervals per second) 263 SendAndExpectPacket(PacedSender::kNormalPriority,
244 const size_t packets_to_send_per_interval = 264 ssrc,
245 kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); 265 sequence_number++,
246 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 266 clock_.TimeInMilliseconds(),
247 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 267 250,
248 clock_.TimeInMilliseconds(), 250, false); 268 false);
249 } 269 }
250 queued_sequence_number = sequence_number; 270 queued_sequence_number = sequence_number;
251 271
252 for (size_t j = 0; j < packets_to_send_per_interval * 10; ++j) { 272 for (int j = 0; j < 30; ++j) {
253 // Send in duplicate packets. 273 // Send in duplicate packets.
254 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 274 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
255 sequence_number, clock_.TimeInMilliseconds(), 275 sequence_number, clock_.TimeInMilliseconds(),
256 250, false); 276 250, false);
257 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 277 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
258 sequence_number++, clock_.TimeInMilliseconds(), 278 sequence_number++, clock_.TimeInMilliseconds(),
259 250, false); 279 250, false);
260 } 280 }
261 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); 281 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0);
262 send_bucket_->Process(); 282 send_bucket_->Process();
263 for (int k = 0; k < 10; ++k) { 283 for (int k = 0; k < 10; ++k) {
264 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 284 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
265 clock_.AdvanceTimeMilliseconds(5); 285 clock_.AdvanceTimeMilliseconds(5);
266 286
267 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 287 for (int i = 0; i < 3; ++i) {
268 EXPECT_CALL(callback_, 288 EXPECT_CALL(callback_,
269 TimeToSendPacket(ssrc, queued_sequence_number++, _, false)) 289 TimeToSendPacket(ssrc, queued_sequence_number++, _, false))
270 .Times(1) 290 .Times(1)
271 .WillRepeatedly(Return(true)); 291 .WillRepeatedly(Return(true));
272 } 292 }
273 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 293 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
274 send_bucket_->Process(); 294 send_bucket_->Process();
275 } 295 }
276 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 296 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
277 clock_.AdvanceTimeMilliseconds(5); 297 clock_.AdvanceTimeMilliseconds(5);
278 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 298 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
279 send_bucket_->Process(); 299 send_bucket_->Process();
280 300 SendAndExpectPacket(PacedSender::kNormalPriority,
281 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 301 ssrc,
282 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 302 sequence_number++,
283 clock_.TimeInMilliseconds(), 250, false); 303 clock_.TimeInMilliseconds(),
284 } 304 250,
305 false);
306 SendAndExpectPacket(PacedSender::kNormalPriority,
307 ssrc,
308 sequence_number++,
309 clock_.TimeInMilliseconds(),
310 250,
311 false);
312 SendAndExpectPacket(PacedSender::kNormalPriority,
313 ssrc,
314 sequence_number++,
315 clock_.TimeInMilliseconds(),
316 250,
317 false);
285 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 318 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
286 sequence_number++, clock_.TimeInMilliseconds(), 319 sequence_number++, clock_.TimeInMilliseconds(),
287 250, false); 320 250, false);
288 send_bucket_->Process(); 321 send_bucket_->Process();
289 EXPECT_EQ(1u, send_bucket_->QueueSizePackets());
290 } 322 }
291 323
292 TEST_F(PacedSenderTest, CanQueuePacketsWithSameSequenceNumberOnDifferentSsrcs) { 324 TEST_F(PacedSenderTest, CanQueuePacketsWithSameSequenceNumberOnDifferentSsrcs) {
293 uint32_t ssrc = 12345; 325 uint32_t ssrc = 12345;
294 uint16_t sequence_number = 1234; 326 uint16_t sequence_number = 1234;
295 327
296 SendAndExpectPacket(PacedSender::kNormalPriority, 328 SendAndExpectPacket(PacedSender::kNormalPriority,
297 ssrc, 329 ssrc,
298 sequence_number, 330 sequence_number,
299 clock_.TimeInMilliseconds(), 331 clock_.TimeInMilliseconds(),
300 250, 332 250,
301 false); 333 false);
302 334
303 // Expect packet on second ssrc to be queued and sent as well. 335 // Expect packet on second ssrc to be queued and sent as well.
304 SendAndExpectPacket(PacedSender::kNormalPriority, 336 SendAndExpectPacket(PacedSender::kNormalPriority,
305 ssrc + 1, 337 ssrc + 1,
306 sequence_number, 338 sequence_number,
307 clock_.TimeInMilliseconds(), 339 clock_.TimeInMilliseconds(),
308 250, 340 250,
309 false); 341 false);
310 342
311 clock_.AdvanceTimeMilliseconds(1000); 343 clock_.AdvanceTimeMilliseconds(1000);
312 send_bucket_->Process(); 344 send_bucket_->Process();
313 } 345 }
314 346
315 TEST_F(PacedSenderTest, Padding) { 347 TEST_F(PacedSenderTest, Padding) {
316 uint32_t ssrc = 12345; 348 uint32_t ssrc = 12345;
317 uint16_t sequence_number = 1234; 349 uint16_t sequence_number = 1234;
318 350
319 send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); 351 send_bucket_->UpdateBitrate(
320 send_bucket_->SetAllocatedSendBitrate(kTargetBitrateBps, kTargetBitrateBps); 352 kTargetBitrate, kPaceMultiplier * kTargetBitrate, kTargetBitrate);
321 353 // Due to the multiplicative factor we can send 3 packets not 2 packets.
322 // Due to the multiplicative factor we can send 5 packets during a send 354 SendAndExpectPacket(PacedSender::kNormalPriority,
323 // interval. (network capacity * multiplier / (8 bits per byte * 355 ssrc,
324 // (packet size * #send intervals per second) 356 sequence_number++,
325 const size_t packets_to_send_per_interval = 357 clock_.TimeInMilliseconds(),
326 kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); 358 250,
327 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 359 false);
328 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 360 SendAndExpectPacket(PacedSender::kNormalPriority,
329 clock_.TimeInMilliseconds(), 250, false); 361 ssrc,
330 } 362 sequence_number++,
363 clock_.TimeInMilliseconds(),
364 250,
365 false);
366 SendAndExpectPacket(PacedSender::kNormalPriority,
367 ssrc,
368 sequence_number++,
369 clock_.TimeInMilliseconds(),
370 250,
371 false);
331 // No padding is expected since we have sent too much already. 372 // No padding is expected since we have sent too much already.
332 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); 373 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0);
333 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 374 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
334 clock_.AdvanceTimeMilliseconds(5); 375 clock_.AdvanceTimeMilliseconds(5);
335 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 376 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
336 send_bucket_->Process(); 377 send_bucket_->Process();
337 EXPECT_EQ(0u, send_bucket_->QueueSizePackets());
338
339 // 5 milliseconds later should not send padding since we filled the buffers
340 // initially.
341 EXPECT_CALL(callback_, TimeToSendPadding(250)).Times(0);
342 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
343 clock_.AdvanceTimeMilliseconds(5);
344 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
345 send_bucket_->Process();
346 378
347 // 5 milliseconds later we have enough budget to send some padding. 379 // 5 milliseconds later we have enough budget to send some padding.
348 EXPECT_CALL(callback_, TimeToSendPadding(250)).Times(1). 380 EXPECT_CALL(callback_, TimeToSendPadding(250)).Times(1).
349 WillOnce(Return(250)); 381 WillOnce(Return(250));
350 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 382 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
351 clock_.AdvanceTimeMilliseconds(5); 383 clock_.AdvanceTimeMilliseconds(5);
352 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 384 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
353 send_bucket_->Process(); 385 send_bucket_->Process();
354 } 386 }
355 387
356 TEST_F(PacedSenderTest, VerifyPaddingUpToBitrate) { 388 TEST_F(PacedSenderTest, VerifyPaddingUpToBitrate) {
357 uint32_t ssrc = 12345; 389 uint32_t ssrc = 12345;
358 uint16_t sequence_number = 1234; 390 uint16_t sequence_number = 1234;
359 int64_t capture_time_ms = 56789; 391 int64_t capture_time_ms = 56789;
360 const int kTimeStep = 5; 392 const int kTimeStep = 5;
361 const int64_t kBitrateWindow = 100; 393 const int64_t kBitrateWindow = 100;
362 send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); 394 send_bucket_->UpdateBitrate(
363 send_bucket_->SetAllocatedSendBitrate(kTargetBitrateBps, kTargetBitrateBps); 395 kTargetBitrate, kPaceMultiplier * kTargetBitrate, kTargetBitrate);
364
365 int64_t start_time = clock_.TimeInMilliseconds(); 396 int64_t start_time = clock_.TimeInMilliseconds();
366 while (clock_.TimeInMilliseconds() - start_time < kBitrateWindow) { 397 while (clock_.TimeInMilliseconds() - start_time < kBitrateWindow) {
367 SendAndExpectPacket(PacedSender::kNormalPriority, 398 SendAndExpectPacket(PacedSender::kNormalPriority,
368 ssrc, 399 ssrc,
369 sequence_number++, 400 sequence_number++,
370 capture_time_ms, 401 capture_time_ms,
371 250, 402 250,
372 false); 403 false);
373 clock_.AdvanceTimeMilliseconds(kTimeStep); 404 clock_.AdvanceTimeMilliseconds(kTimeStep);
374 EXPECT_CALL(callback_, TimeToSendPadding(250)).Times(1). 405 EXPECT_CALL(callback_, TimeToSendPadding(250)).Times(1).
375 WillOnce(Return(250)); 406 WillOnce(Return(250));
376 send_bucket_->Process(); 407 send_bucket_->Process();
377 } 408 }
378 } 409 }
379 410
380 TEST_F(PacedSenderTest, VerifyAverageBitrateVaryingMediaPayload) { 411 TEST_F(PacedSenderTest, VerifyAverageBitrateVaryingMediaPayload) {
381 uint32_t ssrc = 12345; 412 uint32_t ssrc = 12345;
382 uint16_t sequence_number = 1234; 413 uint16_t sequence_number = 1234;
383 int64_t capture_time_ms = 56789; 414 int64_t capture_time_ms = 56789;
384 const int kTimeStep = 5; 415 const int kTimeStep = 5;
385 const int64_t kBitrateWindow = 10000; 416 const int64_t kBitrateWindow = 10000;
386 PacedSenderPadding callback; 417 PacedSenderPadding callback;
387 send_bucket_.reset(new PacedSender(&clock_, &callback, kTargetBitrateBps)); 418 send_bucket_.reset(new PacedSender(
419 &clock_, &callback, kTargetBitrate, kPaceMultiplier * kTargetBitrate, 0));
388 send_bucket_->SetProbingEnabled(false); 420 send_bucket_->SetProbingEnabled(false);
389 send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); 421 send_bucket_->UpdateBitrate(
390 send_bucket_->SetAllocatedSendBitrate(kTargetBitrateBps, kTargetBitrateBps); 422 kTargetBitrate, kPaceMultiplier * kTargetBitrate, kTargetBitrate);
391
392 int64_t start_time = clock_.TimeInMilliseconds(); 423 int64_t start_time = clock_.TimeInMilliseconds();
393 size_t media_bytes = 0; 424 size_t media_bytes = 0;
394 while (clock_.TimeInMilliseconds() - start_time < kBitrateWindow) { 425 while (clock_.TimeInMilliseconds() - start_time < kBitrateWindow) {
395 int rand_value = rand(); // NOLINT (rand_r instead of rand) 426 int rand_value = rand(); // NOLINT (rand_r instead of rand)
396 size_t media_payload = rand_value % 100 + 200; // [200, 300] bytes. 427 size_t media_payload = rand_value % 100 + 200; // [200, 300] bytes.
397 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 428 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
398 sequence_number++, capture_time_ms, 429 sequence_number++, capture_time_ms,
399 media_payload, false); 430 media_payload, false);
400 media_bytes += media_payload; 431 media_bytes += media_payload;
401 clock_.AdvanceTimeMilliseconds(kTimeStep); 432 clock_.AdvanceTimeMilliseconds(kTimeStep);
402 send_bucket_->Process(); 433 send_bucket_->Process();
403 } 434 }
404 EXPECT_NEAR(kTargetBitrateBps / 1000, 435 EXPECT_NEAR(kTargetBitrate,
405 static_cast<int>(8 * (media_bytes + callback.padding_sent()) / 436 static_cast<int>(8 * (media_bytes + callback.padding_sent()) /
406 kBitrateWindow), 437 kBitrateWindow), 1);
407 1);
408 } 438 }
409 439
410 TEST_F(PacedSenderTest, Priority) { 440 TEST_F(PacedSenderTest, Priority) {
411 uint32_t ssrc_low_priority = 12345; 441 uint32_t ssrc_low_priority = 12345;
412 uint32_t ssrc = 12346; 442 uint32_t ssrc = 12346;
413 uint16_t sequence_number = 1234; 443 uint16_t sequence_number = 1234;
414 int64_t capture_time_ms = 56789; 444 int64_t capture_time_ms = 56789;
415 int64_t capture_time_ms_low_priority = 1234567; 445 int64_t capture_time_ms_low_priority = 1234567;
416 446
417 // Due to the multiplicative factor we can send 5 packets during a send 447 // Due to the multiplicative factor we can send 3 packets not 2 packets.
418 // interval. (network capacity * multiplier / (8 bits per byte * 448 SendAndExpectPacket(PacedSender::kLowPriority,
419 // (packet size * #send intervals per second) 449 ssrc,
420 const size_t packets_to_send_per_interval = 450 sequence_number++,
421 kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); 451 capture_time_ms,
422 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 452 250,
423 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 453 false);
424 clock_.TimeInMilliseconds(), 250, false); 454 SendAndExpectPacket(PacedSender::kNormalPriority,
425 } 455 ssrc,
456 sequence_number++,
457 capture_time_ms,
458 250,
459 false);
460 SendAndExpectPacket(PacedSender::kNormalPriority,
461 ssrc,
462 sequence_number++,
463 capture_time_ms,
464 250,
465 false);
426 send_bucket_->Process(); 466 send_bucket_->Process();
427 EXPECT_EQ(0u, send_bucket_->QueueSizePackets());
428 467
429 // Expect normal and low priority to be queued and high to pass through. 468 // Expect normal and low priority to be queued and high to pass through.
430 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc_low_priority, 469 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc_low_priority,
431 sequence_number++, capture_time_ms_low_priority, 470 sequence_number++, capture_time_ms_low_priority,
432 250, false); 471 250, false);
433 472 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
434 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 473 sequence_number++, capture_time_ms, 250, false);
435 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 474 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
436 sequence_number++, capture_time_ms, 250, false); 475 sequence_number++, capture_time_ms, 250, false);
437 } 476 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
477 sequence_number++, capture_time_ms, 250, false);
438 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, 478 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc,
439 sequence_number++, capture_time_ms, 250, false); 479 sequence_number++, capture_time_ms, 250, false);
440 480
441 // Expect all high and normal priority to be sent out first. 481 // Expect all high and normal priority to be sent out first.
442 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); 482 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0);
443 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, capture_time_ms, false)) 483 EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, capture_time_ms, false))
444 .Times(packets_to_send_per_interval + 1) 484 .Times(4)
445 .WillRepeatedly(Return(true)); 485 .WillRepeatedly(Return(true));
446 486
447 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 487 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
448 clock_.AdvanceTimeMilliseconds(5); 488 clock_.AdvanceTimeMilliseconds(5);
449 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 489 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
450 send_bucket_->Process(); 490 send_bucket_->Process();
451 EXPECT_EQ(1u, send_bucket_->QueueSizePackets());
452 491
453 EXPECT_CALL(callback_, 492 EXPECT_CALL(callback_,
454 TimeToSendPacket( 493 TimeToSendPacket(
455 ssrc_low_priority, _, capture_time_ms_low_priority, false)) 494 ssrc_low_priority, _, capture_time_ms_low_priority, false))
456 .Times(1) 495 .Times(1)
457 .WillRepeatedly(Return(true)); 496 .WillRepeatedly(Return(true));
458 497
459 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 498 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
460 clock_.AdvanceTimeMilliseconds(5); 499 clock_.AdvanceTimeMilliseconds(5);
461 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); 500 EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess());
462 send_bucket_->Process(); 501 send_bucket_->Process();
463 } 502 }
464 503
465 TEST_F(PacedSenderTest, HighPrioDoesntAffectBudget) { 504 TEST_F(PacedSenderTest, HighPrioDoesntAffectBudget) {
466 uint32_t ssrc = 12346; 505 uint32_t ssrc = 12346;
467 uint16_t sequence_number = 1234; 506 uint16_t sequence_number = 1234;
468 int64_t capture_time_ms = 56789; 507 int64_t capture_time_ms = 56789;
469 508
470 // As high prio packets doesn't affect the budget, we should be able to send 509 // As high prio packets doesn't affect the budget, we should be able to send
471 // a high number of them at once. 510 // a high number of them at once.
472 for (int i = 0; i < 25; ++i) { 511 for (int i = 0; i < 25; ++i) {
473 SendAndExpectPacket(PacedSender::kHighPriority, ssrc, sequence_number++, 512 SendAndExpectPacket(PacedSender::kHighPriority, ssrc, sequence_number++,
474 capture_time_ms, 250, false); 513 capture_time_ms, 250, false);
475 } 514 }
476 send_bucket_->Process(); 515 send_bucket_->Process();
477 // Low prio packets does affect the budget. 516 // Low prio packets does affect the budget, so we should only be able to send
478 // Due to the multiplicative factor we can send 5 packets during a send 517 // 3 at once, the 4th should be queued.
479 // interval. (network capacity * multiplier / (8 bits per byte * 518 for (int i = 0; i < 3; ++i) {
480 // (packet size * #send intervals per second)
481 const size_t packets_to_send_per_interval =
482 kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200);
483 for (size_t i = 0; i < packets_to_send_per_interval; ++i) {
484 SendAndExpectPacket(PacedSender::kLowPriority, ssrc, sequence_number++, 519 SendAndExpectPacket(PacedSender::kLowPriority, ssrc, sequence_number++,
485 clock_.TimeInMilliseconds(), 250, false); 520 capture_time_ms, 250, false);
486 } 521 }
487 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc, sequence_number, 522 send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc, sequence_number,
488 capture_time_ms, 250, false); 523 capture_time_ms, 250, false);
489 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 524 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
490 clock_.AdvanceTimeMilliseconds(5); 525 clock_.AdvanceTimeMilliseconds(5);
491 send_bucket_->Process(); 526 send_bucket_->Process();
492 EXPECT_EQ(1u, send_bucket_->QueueSizePackets());
493 EXPECT_CALL(callback_, 527 EXPECT_CALL(callback_,
494 TimeToSendPacket(ssrc, sequence_number++, capture_time_ms, false)) 528 TimeToSendPacket(ssrc, sequence_number++, capture_time_ms, false))
495 .Times(1) 529 .Times(1);
496 .WillRepeatedly(Return(true));
497 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); 530 EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess());
498 clock_.AdvanceTimeMilliseconds(5); 531 clock_.AdvanceTimeMilliseconds(5);
499 send_bucket_->Process(); 532 send_bucket_->Process();
500 EXPECT_EQ(0u, send_bucket_->QueueSizePackets());
501 } 533 }
502 534
503 TEST_F(PacedSenderTest, Pause) { 535 TEST_F(PacedSenderTest, Pause) {
504 uint32_t ssrc_low_priority = 12345; 536 uint32_t ssrc_low_priority = 12345;
505 uint32_t ssrc = 12346; 537 uint32_t ssrc = 12346;
506 uint16_t sequence_number = 1234; 538 uint16_t sequence_number = 1234;
507 int64_t capture_time_ms = clock_.TimeInMilliseconds(); 539 int64_t capture_time_ms = clock_.TimeInMilliseconds();
508 540
509 EXPECT_EQ(0, send_bucket_->QueueInMs()); 541 EXPECT_EQ(0, send_bucket_->QueueInMs());
510 542
511 // Due to the multiplicative factor we can send 5 packets during a send 543 // Due to the multiplicative factor we can send 3 packets not 2 packets.
512 // interval. (network capacity * multiplier / (8 bits per byte * 544 SendAndExpectPacket(PacedSender::kLowPriority,
513 // (packet size * #send intervals per second) 545 ssrc,
514 const size_t packets_to_send_per_interval = 546 sequence_number++,
515 kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); 547 capture_time_ms,
516 for (size_t i = 0; i < packets_to_send_per_interval; ++i) { 548 250,
517 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 549 false);
518 clock_.TimeInMilliseconds(), 250, false); 550 SendAndExpectPacket(PacedSender::kNormalPriority,
519 } 551 ssrc,
520 552 sequence_number++,
553 capture_time_ms,
554 250,
555 false);
556 SendAndExpectPacket(PacedSender::kNormalPriority,
557 ssrc,
558 sequence_number++,
559 capture_time_ms,
560 250,
561 false);
521 send_bucket_->Process(); 562 send_bucket_->Process();
522 563
523 send_bucket_->Pause(); 564 send_bucket_->Pause();
524 565
525 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 566 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
526 sequence_number++, capture_time_ms, 250, false); 567 sequence_number++, capture_time_ms, 250, false);
527 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 568 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
528 sequence_number++, capture_time_ms, 250, false); 569 sequence_number++, capture_time_ms, 250, false);
529 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, 570 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc,
530 sequence_number++, capture_time_ms, 250, false); 571 sequence_number++, capture_time_ms, 250, false);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 clock_.AdvanceTimeMilliseconds(10000); 661 clock_.AdvanceTimeMilliseconds(10000);
621 send_bucket_->Process(); 662 send_bucket_->Process();
622 EXPECT_EQ(0, send_bucket_->QueueInMs()); 663 EXPECT_EQ(0, send_bucket_->QueueInMs());
623 } 664 }
624 665
625 TEST_F(PacedSenderTest, ExpectedQueueTimeMs) { 666 TEST_F(PacedSenderTest, ExpectedQueueTimeMs) {
626 uint32_t ssrc = 12346; 667 uint32_t ssrc = 12346;
627 uint16_t sequence_number = 1234; 668 uint16_t sequence_number = 1234;
628 const size_t kNumPackets = 60; 669 const size_t kNumPackets = 60;
629 const size_t kPacketSize = 1200; 670 const size_t kPacketSize = 1200;
630 const int32_t kMaxBitrate = PacedSender::kDefaultPaceMultiplier * 30000; 671 const int32_t kMaxBitrate = kPaceMultiplier * 30;
631 EXPECT_EQ(0, send_bucket_->ExpectedQueueTimeMs()); 672 EXPECT_EQ(0, send_bucket_->ExpectedQueueTimeMs());
632 673
633 send_bucket_->SetEstimatedBitrate(30000); 674 send_bucket_->UpdateBitrate(30, kMaxBitrate, 0);
634 for (size_t i = 0; i < kNumPackets; ++i) { 675 for (size_t i = 0; i < kNumPackets; ++i) {
635 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 676 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++,
636 clock_.TimeInMilliseconds(), kPacketSize, false); 677 clock_.TimeInMilliseconds(), kPacketSize, false);
637 } 678 }
638 679
639 // Queue in ms = 1000 * (bytes in queue) *8 / (bits per second) 680 // Queue in ms = 1000 * (bytes in queue) / (kbit per second * 1000 / 8)
640 int64_t queue_in_ms = 681 int64_t queue_in_ms =
641 static_cast<int64_t>(1000 * kNumPackets * kPacketSize * 8 / kMaxBitrate); 682 static_cast<int64_t>(kNumPackets * kPacketSize * 8 / kMaxBitrate);
642 EXPECT_EQ(queue_in_ms, send_bucket_->ExpectedQueueTimeMs()); 683 EXPECT_EQ(queue_in_ms, send_bucket_->ExpectedQueueTimeMs());
643 684
644 int64_t time_start = clock_.TimeInMilliseconds(); 685 int64_t time_start = clock_.TimeInMilliseconds();
645 while (send_bucket_->QueueSizePackets() > 0) { 686 while (send_bucket_->QueueSizePackets() > 0) {
646 int time_until_process = send_bucket_->TimeUntilNextProcess(); 687 int time_until_process = send_bucket_->TimeUntilNextProcess();
647 if (time_until_process <= 0) { 688 if (time_until_process <= 0) {
648 send_bucket_->Process(); 689 send_bucket_->Process();
649 } else { 690 } else {
650 clock_.AdvanceTimeMilliseconds(time_until_process); 691 clock_.AdvanceTimeMilliseconds(time_until_process);
651 } 692 }
652 } 693 }
653 int64_t duration = clock_.TimeInMilliseconds() - time_start; 694 int64_t duration = clock_.TimeInMilliseconds() - time_start;
654 695
655 EXPECT_EQ(0, send_bucket_->ExpectedQueueTimeMs()); 696 EXPECT_EQ(0, send_bucket_->ExpectedQueueTimeMs());
656 697
657 // Allow for aliasing, duration should be within one pack of max time limit. 698 // Allow for aliasing, duration should be within one pack of max time limit.
658 EXPECT_NEAR(duration, PacedSender::kMaxQueueLengthMs, 699 EXPECT_NEAR(duration, PacedSender::kMaxQueueLengthMs,
659 static_cast<int64_t>(1000 * kPacketSize * 8 / kMaxBitrate)); 700 static_cast<int64_t>(kPacketSize * 8 / kMaxBitrate));
660 } 701 }
661 702
662 TEST_F(PacedSenderTest, QueueTimeGrowsOverTime) { 703 TEST_F(PacedSenderTest, QueueTimeGrowsOverTime) {
663 uint32_t ssrc = 12346; 704 uint32_t ssrc = 12346;
664 uint16_t sequence_number = 1234; 705 uint16_t sequence_number = 1234;
665 EXPECT_EQ(0, send_bucket_->QueueInMs()); 706 EXPECT_EQ(0, send_bucket_->QueueInMs());
666 707
667 send_bucket_->SetEstimatedBitrate(30000); 708 send_bucket_->UpdateBitrate(30, kPaceMultiplier * 30, 0);
668 SendAndExpectPacket(PacedSender::kNormalPriority, 709 SendAndExpectPacket(PacedSender::kNormalPriority,
669 ssrc, 710 ssrc,
670 sequence_number, 711 sequence_number,
671 clock_.TimeInMilliseconds(), 712 clock_.TimeInMilliseconds(),
672 1200, 713 1200,
673 false); 714 false);
674 715
675 clock_.AdvanceTimeMilliseconds(500); 716 clock_.AdvanceTimeMilliseconds(500);
676 EXPECT_EQ(500, send_bucket_->QueueInMs()); 717 EXPECT_EQ(500, send_bucket_->QueueInMs());
677 send_bucket_->Process(); 718 send_bucket_->Process();
678 EXPECT_EQ(0, send_bucket_->QueueInMs()); 719 EXPECT_EQ(0, send_bucket_->QueueInMs());
679 } 720 }
680 721
681 TEST_F(PacedSenderTest, ProbingWithInitialFrame) { 722 TEST_F(PacedSenderTest, ProbingWithInitialFrame) {
682 const int kNumPackets = 11; 723 const int kNumPackets = 11;
683 const int kNumDeltas = kNumPackets - 1; 724 const int kNumDeltas = kNumPackets - 1;
684 const size_t kPacketSize = 1200; 725 const size_t kPacketSize = 1200;
685 const int kInitialBitrateBps = 300000; 726 const int kInitialBitrateKbps = 300;
686 uint32_t ssrc = 12346; 727 uint32_t ssrc = 12346;
687 uint16_t sequence_number = 1234; 728 uint16_t sequence_number = 1234;
688
689 const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5}; 729 const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5};
690 std::list<int> expected_deltas_list(expected_deltas, 730 std::list<int> expected_deltas_list(expected_deltas,
691 expected_deltas + kNumDeltas); 731 expected_deltas + kNumDeltas);
692 PacedSenderProbing callback(expected_deltas_list, &clock_); 732 PacedSenderProbing callback(expected_deltas_list, &clock_);
693 send_bucket_.reset(new PacedSender(&clock_, &callback, kInitialBitrateBps)); 733 send_bucket_.reset(
734 new PacedSender(&clock_,
735 &callback,
736 kInitialBitrateKbps,
737 kPaceMultiplier * kInitialBitrateKbps,
738 0));
694 739
695 for (int i = 0; i < kNumPackets; ++i) { 740 for (int i = 0; i < kNumPackets; ++i) {
696 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 741 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
697 sequence_number++, clock_.TimeInMilliseconds(), 742 sequence_number++, clock_.TimeInMilliseconds(),
698 kPacketSize, false); 743 kPacketSize, false);
699 } 744 }
700
701 while (callback.packets_sent() < kNumPackets) { 745 while (callback.packets_sent() < kNumPackets) {
702 int time_until_process = send_bucket_->TimeUntilNextProcess(); 746 int time_until_process = send_bucket_->TimeUntilNextProcess();
703 if (time_until_process <= 0) { 747 if (time_until_process <= 0) {
704 send_bucket_->Process(); 748 send_bucket_->Process();
705 } else { 749 } else {
706 clock_.AdvanceTimeMilliseconds(time_until_process); 750 clock_.AdvanceTimeMilliseconds(time_until_process);
707 } 751 }
708 } 752 }
709 } 753 }
710 754
711 TEST_F(PacedSenderTest, ProbingWithTooSmallInitialFrame) { 755 TEST_F(PacedSenderTest, ProbingWithTooSmallInitialFrame) {
712 const int kNumPackets = 11; 756 const int kNumPackets = 11;
713 const int kNumDeltas = kNumPackets - 1; 757 const int kNumDeltas = kNumPackets - 1;
714 const size_t kPacketSize = 1200; 758 const size_t kPacketSize = 1200;
715 const int kInitialBitrateBps = 300000; 759 const int kInitialBitrateKbps = 300;
716 uint32_t ssrc = 12346; 760 uint32_t ssrc = 12346;
717 uint16_t sequence_number = 1234; 761 uint16_t sequence_number = 1234;
718 const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5}; 762 const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5};
719 std::list<int> expected_deltas_list(expected_deltas, 763 std::list<int> expected_deltas_list(expected_deltas,
720 expected_deltas + kNumDeltas); 764 expected_deltas + kNumDeltas);
721 PacedSenderProbing callback(expected_deltas_list, &clock_); 765 PacedSenderProbing callback(expected_deltas_list, &clock_);
722 send_bucket_.reset(new PacedSender(&clock_, &callback, kInitialBitrateBps)); 766 send_bucket_.reset(new PacedSender(&clock_, &callback, kInitialBitrateKbps,
767 kPaceMultiplier * kInitialBitrateKbps, 0));
723 768
724 for (int i = 0; i < kNumPackets - 5; ++i) { 769 for (int i = 0; i < kNumPackets - 5; ++i) {
725 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 770 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
726 sequence_number++, clock_.TimeInMilliseconds(), 771 sequence_number++, clock_.TimeInMilliseconds(),
727 kPacketSize, false); 772 kPacketSize, false);
728 } 773 }
729 while (callback.packets_sent() < kNumPackets) { 774 while (callback.packets_sent() < kNumPackets) {
730 int time_until_process = send_bucket_->TimeUntilNextProcess(); 775 int time_until_process = send_bucket_->TimeUntilNextProcess();
731 if (time_until_process <= 0) { 776 if (time_until_process <= 0) {
732 send_bucket_->Process(); 777 send_bucket_->Process();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 } 832 }
788 } 833 }
789 } 834 }
790 } 835 }
791 836
792 TEST_F(PacedSenderTest, PaddingOveruse) { 837 TEST_F(PacedSenderTest, PaddingOveruse) {
793 uint32_t ssrc = 12346; 838 uint32_t ssrc = 12346;
794 uint16_t sequence_number = 1234; 839 uint16_t sequence_number = 1234;
795 const size_t kPacketSize = 1200; 840 const size_t kPacketSize = 1200;
796 841
797 send_bucket_->SetEstimatedBitrate(60000); 842 // Min bitrate 0 => no padding, padding budget will stay at 0.
798 send_bucket_->SetAllocatedSendBitrate(60000, 0); 843 send_bucket_->UpdateBitrate(60, 90, 0);
799
800 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 844 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++,
801 clock_.TimeInMilliseconds(), kPacketSize, false); 845 clock_.TimeInMilliseconds(), kPacketSize, false);
802 send_bucket_->Process(); 846 send_bucket_->Process();
803 847
804 // Add 30kbit padding. When increasing budget, media budget will increase from 848 // Add 30kbit padding. When increasing budget, media budget will increase from
805 // negative (overuse) while padding budget will increase from 0. 849 // negative (overuse) while padding budget will increase form 0.
806 clock_.AdvanceTimeMilliseconds(5); 850 clock_.AdvanceTimeMilliseconds(5);
807 send_bucket_->SetAllocatedSendBitrate(60000, 30000); 851 send_bucket_->UpdateBitrate(60, 90, 30);
808 852
809 SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, 853 send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc,
810 clock_.TimeInMilliseconds(), kPacketSize, false); 854 sequence_number++, clock_.TimeInMilliseconds(),
811 EXPECT_LT(5u, send_bucket_->ExpectedQueueTimeMs()); 855 kPacketSize, false);
856
812 // Don't send padding if queue is non-empty, even if padding budget > 0. 857 // Don't send padding if queue is non-empty, even if padding budget > 0.
813 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); 858 EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0);
814 send_bucket_->Process(); 859 send_bucket_->Process();
815 } 860 }
816 861
817 TEST_F(PacedSenderTest, AverageQueueTime) { 862 TEST_F(PacedSenderTest, AverageQueueTime) {
818 uint32_t ssrc = 12346; 863 uint32_t ssrc = 12346;
819 uint16_t sequence_number = 1234; 864 uint16_t sequence_number = 1234;
820 const size_t kPacketSize = 1200; 865 const size_t kPacketSize = 1200;
821 const int kBitrateBps = 10 * kPacketSize * 8; // 10 packets per second. 866 const int kBitrateBps = 10 * kPacketSize * 8; // 10 packets per second.
867 const int kBitrateKbps = (kBitrateBps + 500) / 1000;
822 868
823 send_bucket_->SetEstimatedBitrate(kBitrateBps); 869 send_bucket_->UpdateBitrate(kBitrateKbps, kBitrateKbps, kBitrateKbps);
824 870
825 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs()); 871 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs());
826 872
827 int64_t first_capture_time = clock_.TimeInMilliseconds(); 873 int64_t first_capture_time = clock_.TimeInMilliseconds();
828 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 874 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
829 sequence_number, first_capture_time, kPacketSize, 875 sequence_number, first_capture_time, kPacketSize,
830 false); 876 false);
831 clock_.AdvanceTimeMilliseconds(10); 877 clock_.AdvanceTimeMilliseconds(10);
832 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 878 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
833 sequence_number + 1, clock_.TimeInMilliseconds(), 879 sequence_number + 1, clock_.TimeInMilliseconds(),
(...skipping 20 matching lines...) Expand all
854 for (int i = 0; i < 3; ++i) { 900 for (int i = 0; i < 3; ++i) {
855 clock_.AdvanceTimeMilliseconds(30); // Max delta. 901 clock_.AdvanceTimeMilliseconds(30); // Max delta.
856 send_bucket_->Process(); 902 send_bucket_->Process();
857 } 903 }
858 904
859 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs()); 905 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs());
860 } 906 }
861 907
862 } // namespace test 908 } // namespace test
863 } // namespace webrtc 909 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/paced_sender.cc ('k') | webrtc/modules/pacing/packet_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698