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

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

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