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

Side by Side Diff: webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.cc

Issue 2378103005: Reland: Fix race / crash in OnNetworkRouteChanged(). (Closed)
Patch Set: . Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 #include "webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h " 10 #include "webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h "
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 packet.arrival_time_ms = prev_arrival_time_us_ / 1000; 143 packet.arrival_time_ms = prev_arrival_time_us_ / 1000;
144 ++i; 144 ++i;
145 } 145 }
146 it = std::min_element(streams_.begin(), streams_.end(), RtpStream::Compare); 146 it = std::min_element(streams_.begin(), streams_.end(), RtpStream::Compare);
147 return std::max((*it)->next_rtp_time(), time_now_us); 147 return std::max((*it)->next_rtp_time(), time_now_us);
148 } 148 }
149 } // namespace test 149 } // namespace test
150 150
151 DelayBasedBweTest::DelayBasedBweTest() 151 DelayBasedBweTest::DelayBasedBweTest()
152 : clock_(100000000), 152 : clock_(100000000),
153 bitrate_observer_(new test::TestBitrateObserver), 153 bitrate_estimator_(&clock_),
154 bitrate_estimator_(new DelayBasedBwe(bitrate_observer_.get(), &clock_)),
155 stream_generator_(new test::StreamGenerator(1e6, // Capacity. 154 stream_generator_(new test::StreamGenerator(1e6, // Capacity.
156 clock_.TimeInMicroseconds())), 155 clock_.TimeInMicroseconds())),
157 arrival_time_offset_ms_(0) {} 156 arrival_time_offset_ms_(0) {}
158 157
159 DelayBasedBweTest::~DelayBasedBweTest() {} 158 DelayBasedBweTest::~DelayBasedBweTest() {}
160 159
161 void DelayBasedBweTest::AddDefaultStream() { 160 void DelayBasedBweTest::AddDefaultStream() {
162 stream_generator_->AddStream(new test::RtpStream(30, 3e5)); 161 stream_generator_->AddStream(new test::RtpStream(30, 3e5));
163 } 162 }
164 163
(...skipping 10 matching lines...) Expand all
175 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms, 174 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms,
176 int64_t send_time_ms, 175 int64_t send_time_ms,
177 uint16_t sequence_number, 176 uint16_t sequence_number,
178 size_t payload_size, 177 size_t payload_size,
179 int probe_cluster_id) { 178 int probe_cluster_id) {
180 RTC_CHECK_GE(arrival_time_ms + arrival_time_offset_ms_, 0); 179 RTC_CHECK_GE(arrival_time_ms + arrival_time_offset_ms_, 0);
181 PacketInfo packet(arrival_time_ms + arrival_time_offset_ms_, send_time_ms, 180 PacketInfo packet(arrival_time_ms + arrival_time_offset_ms_, send_time_ms,
182 sequence_number, payload_size, probe_cluster_id); 181 sequence_number, payload_size, probe_cluster_id);
183 std::vector<PacketInfo> packets; 182 std::vector<PacketInfo> packets;
184 packets.push_back(packet); 183 packets.push_back(packet);
185 bitrate_estimator_->IncomingPacketFeedbackVector(packets); 184 DelayBasedBwe::Result result =
185 bitrate_estimator_.IncomingPacketFeedbackVector(packets);
186 const uint32_t kDummySsrc = 0;
187 if (result.updated) {
188 bitrate_observer_.OnReceiveBitrateChanged({kDummySsrc},
189 result.target_bitrate_bps);
190 }
186 } 191 }
187 192
188 // Generates a frame of packets belonging to a stream at a given bitrate and 193 // Generates a frame of packets belonging to a stream at a given bitrate and
189 // with a given ssrc. The stream is pushed through a very simple simulated 194 // with a given ssrc. The stream is pushed through a very simple simulated
190 // network, and is then given to the receive-side bandwidth estimator. 195 // network, and is then given to the receive-side bandwidth estimator.
191 // Returns true if an over-use was seen, false otherwise. 196 // Returns true if an over-use was seen, false otherwise.
192 // The StreamGenerator::updated() should be used to check for any changes in 197 // The StreamGenerator::updated() should be used to check for any changes in
193 // target bitrate after the call to this function. 198 // target bitrate after the call to this function.
194 bool DelayBasedBweTest::GenerateAndProcessFrame(uint32_t ssrc, 199 bool DelayBasedBweTest::GenerateAndProcessFrame(uint32_t ssrc,
195 uint32_t bitrate_bps) { 200 uint32_t bitrate_bps) {
196 stream_generator_->SetBitrateBps(bitrate_bps); 201 stream_generator_->SetBitrateBps(bitrate_bps);
197 std::vector<PacketInfo> packets; 202 std::vector<PacketInfo> packets;
198 int64_t next_time_us = 203 int64_t next_time_us =
199 stream_generator_->GenerateFrame(&packets, clock_.TimeInMicroseconds()); 204 stream_generator_->GenerateFrame(&packets, clock_.TimeInMicroseconds());
200 if (packets.empty()) 205 if (packets.empty())
201 return false; 206 return false;
202 207
203 bool overuse = false; 208 bool overuse = false;
204 bitrate_observer_->Reset(); 209 bitrate_observer_.Reset();
205 clock_.AdvanceTimeMicroseconds(1000 * packets.back().arrival_time_ms - 210 clock_.AdvanceTimeMicroseconds(1000 * packets.back().arrival_time_ms -
206 clock_.TimeInMicroseconds()); 211 clock_.TimeInMicroseconds());
207 for (auto& packet : packets) { 212 for (auto& packet : packets) {
208 RTC_CHECK_GE(packet.arrival_time_ms + arrival_time_offset_ms_, 0); 213 RTC_CHECK_GE(packet.arrival_time_ms + arrival_time_offset_ms_, 0);
209 packet.arrival_time_ms += arrival_time_offset_ms_; 214 packet.arrival_time_ms += arrival_time_offset_ms_;
210 } 215 }
211 bitrate_estimator_->IncomingPacketFeedbackVector(packets); 216 DelayBasedBwe::Result result =
212 217 bitrate_estimator_.IncomingPacketFeedbackVector(packets);
213 if (bitrate_observer_->updated()) { 218 const uint32_t kDummySsrc = 0;
214 if (bitrate_observer_->latest_bitrate() < bitrate_bps) 219 if (result.updated) {
220 bitrate_observer_.OnReceiveBitrateChanged({kDummySsrc},
221 result.target_bitrate_bps);
222 if (result.target_bitrate_bps < bitrate_bps)
215 overuse = true; 223 overuse = true;
216 } 224 }
217 225
218 clock_.AdvanceTimeMicroseconds(next_time_us - clock_.TimeInMicroseconds()); 226 clock_.AdvanceTimeMicroseconds(next_time_us - clock_.TimeInMicroseconds());
219 return overuse; 227 return overuse;
220 } 228 }
221 229
222 // Run the bandwidth estimator with a stream of |number_of_frames| frames, or 230 // Run the bandwidth estimator with a stream of |number_of_frames| frames, or
223 // until it reaches |target_bitrate|. 231 // until it reaches |target_bitrate|.
224 // Can for instance be used to run the estimator for some time to get it 232 // Can for instance be used to run the estimator for some time to get it
225 // into a steady state. 233 // into a steady state.
226 uint32_t DelayBasedBweTest::SteadyStateRun(uint32_t ssrc, 234 uint32_t DelayBasedBweTest::SteadyStateRun(uint32_t ssrc,
227 int max_number_of_frames, 235 int max_number_of_frames,
228 uint32_t start_bitrate, 236 uint32_t start_bitrate,
229 uint32_t min_bitrate, 237 uint32_t min_bitrate,
230 uint32_t max_bitrate, 238 uint32_t max_bitrate,
231 uint32_t target_bitrate) { 239 uint32_t target_bitrate) {
232 uint32_t bitrate_bps = start_bitrate; 240 uint32_t bitrate_bps = start_bitrate;
233 bool bitrate_update_seen = false; 241 bool bitrate_update_seen = false;
234 // Produce |number_of_frames| frames and give them to the estimator. 242 // Produce |number_of_frames| frames and give them to the estimator.
235 for (int i = 0; i < max_number_of_frames; ++i) { 243 for (int i = 0; i < max_number_of_frames; ++i) {
236 bool overuse = GenerateAndProcessFrame(ssrc, bitrate_bps); 244 bool overuse = GenerateAndProcessFrame(ssrc, bitrate_bps);
237 if (overuse) { 245 if (overuse) {
238 EXPECT_LT(bitrate_observer_->latest_bitrate(), max_bitrate); 246 EXPECT_LT(bitrate_observer_.latest_bitrate(), max_bitrate);
239 EXPECT_GT(bitrate_observer_->latest_bitrate(), min_bitrate); 247 EXPECT_GT(bitrate_observer_.latest_bitrate(), min_bitrate);
240 bitrate_bps = bitrate_observer_->latest_bitrate(); 248 bitrate_bps = bitrate_observer_.latest_bitrate();
241 bitrate_update_seen = true; 249 bitrate_update_seen = true;
242 } else if (bitrate_observer_->updated()) { 250 } else if (bitrate_observer_.updated()) {
243 bitrate_bps = bitrate_observer_->latest_bitrate(); 251 bitrate_bps = bitrate_observer_.latest_bitrate();
244 bitrate_observer_->Reset(); 252 bitrate_observer_.Reset();
245 } 253 }
246 if (bitrate_update_seen && bitrate_bps > target_bitrate) { 254 if (bitrate_update_seen && bitrate_bps > target_bitrate) {
247 break; 255 break;
248 } 256 }
249 } 257 }
250 EXPECT_TRUE(bitrate_update_seen); 258 EXPECT_TRUE(bitrate_update_seen);
251 return bitrate_bps; 259 return bitrate_bps;
252 } 260 }
253 261
254 void DelayBasedBweTest::InitialBehaviorTestHelper( 262 void DelayBasedBweTest::InitialBehaviorTestHelper(
255 uint32_t expected_converge_bitrate) { 263 uint32_t expected_converge_bitrate) {
256 const int kFramerate = 50; // 50 fps to avoid rounding errors. 264 const int kFramerate = 50; // 50 fps to avoid rounding errors.
257 const int kFrameIntervalMs = 1000 / kFramerate; 265 const int kFrameIntervalMs = 1000 / kFramerate;
258 uint32_t bitrate_bps = 0; 266 uint32_t bitrate_bps = 0;
259 int64_t send_time_ms = 0; 267 int64_t send_time_ms = 0;
260 uint16_t sequence_number = 0; 268 uint16_t sequence_number = 0;
261 std::vector<uint32_t> ssrcs; 269 std::vector<uint32_t> ssrcs;
262 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 270 EXPECT_FALSE(bitrate_estimator_.LatestEstimate(&ssrcs, &bitrate_bps));
263 EXPECT_EQ(0u, ssrcs.size()); 271 EXPECT_EQ(0u, ssrcs.size());
264 clock_.AdvanceTimeMilliseconds(1000); 272 clock_.AdvanceTimeMilliseconds(1000);
265 bitrate_estimator_->Process(); 273 EXPECT_FALSE(bitrate_estimator_.LatestEstimate(&ssrcs, &bitrate_bps));
266 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 274 EXPECT_FALSE(bitrate_observer_.updated());
267 EXPECT_FALSE(bitrate_observer_->updated()); 275 bitrate_observer_.Reset();
268 bitrate_observer_->Reset();
269 clock_.AdvanceTimeMilliseconds(1000); 276 clock_.AdvanceTimeMilliseconds(1000);
270 // Inserting packets for 5 seconds to get a valid estimate. 277 // Inserting packets for 5 seconds to get a valid estimate.
271 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) { 278 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) {
272 // NOTE!!! If the following line is moved under the if case then this test 279 // NOTE!!! If the following line is moved under the if case then this test
273 // wont work on windows realease bots. 280 // wont work on windows realease bots.
274 int cluster_id = i < kInitialProbingPackets ? 0 : PacketInfo::kNotAProbe; 281 int cluster_id = i < kInitialProbingPackets ? 0 : PacketInfo::kNotAProbe;
275 282
276 if (i == kNumInitialPackets) { 283 if (i == kNumInitialPackets) {
277 bitrate_estimator_->Process(); 284 EXPECT_FALSE(bitrate_estimator_.LatestEstimate(&ssrcs, &bitrate_bps));
278 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
279 EXPECT_EQ(0u, ssrcs.size()); 285 EXPECT_EQ(0u, ssrcs.size());
280 EXPECT_FALSE(bitrate_observer_->updated()); 286 EXPECT_FALSE(bitrate_observer_.updated());
281 bitrate_observer_->Reset(); 287 bitrate_observer_.Reset();
282 } 288 }
283 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, 289 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms,
284 sequence_number++, kMtu, cluster_id); 290 sequence_number++, kMtu, cluster_id);
285 clock_.AdvanceTimeMilliseconds(1000 / kFramerate); 291 clock_.AdvanceTimeMilliseconds(1000 / kFramerate);
286 send_time_ms += kFrameIntervalMs; 292 send_time_ms += kFrameIntervalMs;
287 } 293 }
288 bitrate_estimator_->Process(); 294 EXPECT_TRUE(bitrate_estimator_.LatestEstimate(&ssrcs, &bitrate_bps));
289 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
290 ASSERT_EQ(1u, ssrcs.size()); 295 ASSERT_EQ(1u, ssrcs.size());
291 EXPECT_EQ(kDefaultSsrc, ssrcs.front()); 296 EXPECT_EQ(kDefaultSsrc, ssrcs.front());
292 EXPECT_NEAR(expected_converge_bitrate, bitrate_bps, kAcceptedBitrateErrorBps); 297 EXPECT_NEAR(expected_converge_bitrate, bitrate_bps, kAcceptedBitrateErrorBps);
293 EXPECT_TRUE(bitrate_observer_->updated()); 298 EXPECT_TRUE(bitrate_observer_.updated());
294 bitrate_observer_->Reset(); 299 bitrate_observer_.Reset();
295 EXPECT_EQ(bitrate_observer_->latest_bitrate(), bitrate_bps); 300 EXPECT_EQ(bitrate_observer_.latest_bitrate(), bitrate_bps);
296 } 301 }
297 302
298 void DelayBasedBweTest::RateIncreaseReorderingTestHelper( 303 void DelayBasedBweTest::RateIncreaseReorderingTestHelper(
299 uint32_t expected_bitrate_bps) { 304 uint32_t expected_bitrate_bps) {
300 const int kFramerate = 50; // 50 fps to avoid rounding errors. 305 const int kFramerate = 50; // 50 fps to avoid rounding errors.
301 const int kFrameIntervalMs = 1000 / kFramerate; 306 const int kFrameIntervalMs = 1000 / kFramerate;
302 int64_t send_time_ms = 0; 307 int64_t send_time_ms = 0;
303 uint16_t sequence_number = 0; 308 uint16_t sequence_number = 0;
304 // Inserting packets for five seconds to get a valid estimate. 309 // Inserting packets for five seconds to get a valid estimate.
305 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) { 310 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) {
306 // NOTE!!! If the following line is moved under the if case then this test 311 // NOTE!!! If the following line is moved under the if case then this test
307 // wont work on windows realease bots. 312 // wont work on windows realease bots.
308 int cluster_id = i < kInitialProbingPackets ? 0 : PacketInfo::kNotAProbe; 313 int cluster_id = i < kInitialProbingPackets ? 0 : PacketInfo::kNotAProbe;
309 314
310 // TODO(sprang): Remove this hack once the single stream estimator is gone, 315 // TODO(sprang): Remove this hack once the single stream estimator is gone,
311 // as it doesn't do anything in Process(). 316 // as it doesn't do anything in Process().
312 if (i == kNumInitialPackets) { 317 if (i == kNumInitialPackets) {
313 // Process after we have enough frames to get a valid input rate estimate. 318 // Process after we have enough frames to get a valid input rate estimate.
314 bitrate_estimator_->Process(); 319
315 EXPECT_FALSE(bitrate_observer_->updated()); // No valid estimate. 320 EXPECT_FALSE(bitrate_observer_.updated()); // No valid estimate.
316 } 321 }
317 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, 322 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms,
318 sequence_number++, kMtu, cluster_id); 323 sequence_number++, kMtu, cluster_id);
319 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 324 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
320 send_time_ms += kFrameIntervalMs; 325 send_time_ms += kFrameIntervalMs;
321 } 326 }
322 bitrate_estimator_->Process(); 327 EXPECT_TRUE(bitrate_observer_.updated());
323 EXPECT_TRUE(bitrate_observer_->updated()); 328 EXPECT_NEAR(expected_bitrate_bps, bitrate_observer_.latest_bitrate(),
324 EXPECT_NEAR(expected_bitrate_bps, bitrate_observer_->latest_bitrate(),
325 kAcceptedBitrateErrorBps); 329 kAcceptedBitrateErrorBps);
326 for (int i = 0; i < 10; ++i) { 330 for (int i = 0; i < 10; ++i) {
327 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); 331 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs);
328 send_time_ms += 2 * kFrameIntervalMs; 332 send_time_ms += 2 * kFrameIntervalMs;
329 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, 333 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms,
330 sequence_number + 2, 1000); 334 sequence_number + 2, 1000);
331 IncomingFeedback(clock_.TimeInMilliseconds(), 335 IncomingFeedback(clock_.TimeInMilliseconds(),
332 send_time_ms - kFrameIntervalMs, sequence_number + 1, 336 send_time_ms - kFrameIntervalMs, sequence_number + 1,
333 1000); 337 1000);
334 sequence_number += 2; 338 sequence_number += 2;
335 } 339 }
336 bitrate_estimator_->Process(); 340 EXPECT_TRUE(bitrate_observer_.updated());
337 EXPECT_TRUE(bitrate_observer_->updated()); 341 EXPECT_NEAR(expected_bitrate_bps, bitrate_observer_.latest_bitrate(),
338 EXPECT_NEAR(expected_bitrate_bps, bitrate_observer_->latest_bitrate(),
339 kAcceptedBitrateErrorBps); 342 kAcceptedBitrateErrorBps);
340 } 343 }
341 344
342 // Make sure we initially increase the bitrate as expected. 345 // Make sure we initially increase the bitrate as expected.
343 void DelayBasedBweTest::RateIncreaseRtpTimestampsTestHelper( 346 void DelayBasedBweTest::RateIncreaseRtpTimestampsTestHelper(
344 int expected_iterations) { 347 int expected_iterations) {
345 // This threshold corresponds approximately to increasing linearly with 348 // This threshold corresponds approximately to increasing linearly with
346 // bitrate(i) = 1.04 * bitrate(i-1) + 1000 349 // bitrate(i) = 1.04 * bitrate(i-1) + 1000
347 // until bitrate(i) > 500000, with bitrate(1) ~= 30000. 350 // until bitrate(i) > 500000, with bitrate(1) ~= 30000.
348 uint32_t bitrate_bps = 30000; 351 uint32_t bitrate_bps = 30000;
349 int iterations = 0; 352 int iterations = 0;
350 AddDefaultStream(); 353 AddDefaultStream();
351 // Feed the estimator with a stream of packets and verify that it reaches 354 // Feed the estimator with a stream of packets and verify that it reaches
352 // 500 kbps at the expected time. 355 // 500 kbps at the expected time.
353 while (bitrate_bps < 5e5) { 356 while (bitrate_bps < 5e5) {
354 bool overuse = GenerateAndProcessFrame(kDefaultSsrc, bitrate_bps); 357 bool overuse = GenerateAndProcessFrame(kDefaultSsrc, bitrate_bps);
355 if (overuse) { 358 if (overuse) {
356 EXPECT_GT(bitrate_observer_->latest_bitrate(), bitrate_bps); 359 EXPECT_GT(bitrate_observer_.latest_bitrate(), bitrate_bps);
357 bitrate_bps = bitrate_observer_->latest_bitrate(); 360 bitrate_bps = bitrate_observer_.latest_bitrate();
358 bitrate_observer_->Reset(); 361 bitrate_observer_.Reset();
359 } else if (bitrate_observer_->updated()) { 362 } else if (bitrate_observer_.updated()) {
360 bitrate_bps = bitrate_observer_->latest_bitrate(); 363 bitrate_bps = bitrate_observer_.latest_bitrate();
361 bitrate_observer_->Reset(); 364 bitrate_observer_.Reset();
362 } 365 }
363 ++iterations; 366 ++iterations;
364 ASSERT_LE(iterations, expected_iterations); 367 // ASSERT_LE(iterations, expected_iterations);
365 } 368 }
366 ASSERT_EQ(expected_iterations, iterations); 369 ASSERT_EQ(expected_iterations, iterations);
367 } 370 }
368 371
369 void DelayBasedBweTest::CapacityDropTestHelper( 372 void DelayBasedBweTest::CapacityDropTestHelper(
370 int number_of_streams, 373 int number_of_streams,
371 bool wrap_time_stamp, 374 bool wrap_time_stamp,
372 uint32_t expected_bitrate_drop_delta, 375 uint32_t expected_bitrate_drop_delta,
373 int64_t receiver_clock_offset_change_ms) { 376 int64_t receiver_clock_offset_change_ms) {
374 const int kFramerate = 30; 377 const int kFramerate = 30;
(...skipping 23 matching lines...) Expand all
398 } 401 }
399 ASSERT_EQ(bitrate_sum, kStartBitrate); 402 ASSERT_EQ(bitrate_sum, kStartBitrate);
400 } 403 }
401 404
402 // Run in steady state to make the estimator converge. 405 // Run in steady state to make the estimator converge.
403 stream_generator_->set_capacity_bps(kInitialCapacityBps); 406 stream_generator_->set_capacity_bps(kInitialCapacityBps);
404 uint32_t bitrate_bps = SteadyStateRun( 407 uint32_t bitrate_bps = SteadyStateRun(
405 kDefaultSsrc, steady_state_time * kFramerate, kStartBitrate, 408 kDefaultSsrc, steady_state_time * kFramerate, kStartBitrate,
406 kMinExpectedBitrate, kMaxExpectedBitrate, kInitialCapacityBps); 409 kMinExpectedBitrate, kMaxExpectedBitrate, kInitialCapacityBps);
407 EXPECT_NEAR(kInitialCapacityBps, bitrate_bps, 130000u); 410 EXPECT_NEAR(kInitialCapacityBps, bitrate_bps, 130000u);
408 bitrate_observer_->Reset(); 411 bitrate_observer_.Reset();
409 412
410 // Add an offset to make sure the BWE can handle it. 413 // Add an offset to make sure the BWE can handle it.
411 arrival_time_offset_ms_ += receiver_clock_offset_change_ms; 414 arrival_time_offset_ms_ += receiver_clock_offset_change_ms;
412 415
413 // Reduce the capacity and verify the decrease time. 416 // Reduce the capacity and verify the decrease time.
414 stream_generator_->set_capacity_bps(kReducedCapacityBps); 417 stream_generator_->set_capacity_bps(kReducedCapacityBps);
415 int64_t overuse_start_time = clock_.TimeInMilliseconds(); 418 int64_t overuse_start_time = clock_.TimeInMilliseconds();
416 int64_t bitrate_drop_time = -1; 419 int64_t bitrate_drop_time = -1;
417 for (int i = 0; i < 100 * number_of_streams; ++i) { 420 for (int i = 0; i < 100 * number_of_streams; ++i) {
418 GenerateAndProcessFrame(kDefaultSsrc, bitrate_bps); 421 GenerateAndProcessFrame(kDefaultSsrc, bitrate_bps);
419 if (bitrate_drop_time == -1 && 422 if (bitrate_drop_time == -1 &&
420 bitrate_observer_->latest_bitrate() <= kReducedCapacityBps) { 423 bitrate_observer_.latest_bitrate() <= kReducedCapacityBps) {
421 bitrate_drop_time = clock_.TimeInMilliseconds(); 424 bitrate_drop_time = clock_.TimeInMilliseconds();
422 } 425 }
423 if (bitrate_observer_->updated()) 426 if (bitrate_observer_.updated())
424 bitrate_bps = bitrate_observer_->latest_bitrate(); 427 bitrate_bps = bitrate_observer_.latest_bitrate();
425 } 428 }
426 429
427 EXPECT_NEAR(expected_bitrate_drop_delta, 430 EXPECT_NEAR(expected_bitrate_drop_delta,
428 bitrate_drop_time - overuse_start_time, 33); 431 bitrate_drop_time - overuse_start_time, 33);
429 } 432 }
430 433
431 void DelayBasedBweTest::TestTimestampGroupingTestHelper() { 434 void DelayBasedBweTest::TestTimestampGroupingTestHelper() {
432 const int kFramerate = 50; // 50 fps to avoid rounding errors. 435 const int kFramerate = 50; // 50 fps to avoid rounding errors.
433 const int kFrameIntervalMs = 1000 / kFramerate; 436 const int kFrameIntervalMs = 1000 / kFramerate;
434 int64_t send_time_ms = 0; 437 int64_t send_time_ms = 0;
435 uint16_t sequence_number = 0; 438 uint16_t sequence_number = 0;
436 // Initial set of frames to increase the bitrate. 6 seconds to have enough 439 // Initial set of frames to increase the bitrate. 6 seconds to have enough
437 // time for the first estimate to be generated and for Process() to be called. 440 // time for the first estimate to be generated and for Process() to be called.
438 for (int i = 0; i <= 6 * kFramerate; ++i) { 441 for (int i = 0; i <= 6 * kFramerate; ++i) {
439 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, 442 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms,
440 sequence_number++, 1000); 443 sequence_number++, 1000);
441 444
442 bitrate_estimator_->Process();
443 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 445 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
444 send_time_ms += kFrameIntervalMs; 446 send_time_ms += kFrameIntervalMs;
445 } 447 }
446 EXPECT_TRUE(bitrate_observer_->updated()); 448 EXPECT_TRUE(bitrate_observer_.updated());
447 EXPECT_GE(bitrate_observer_->latest_bitrate(), 400000u); 449 EXPECT_GE(bitrate_observer_.latest_bitrate(), 400000u);
448 450
449 // Insert batches of frames which were sent very close in time. Also simulate 451 // Insert batches of frames which were sent very close in time. Also simulate
450 // capacity over-use to see that we back off correctly. 452 // capacity over-use to see that we back off correctly.
451 const int kTimestampGroupLength = 15; 453 const int kTimestampGroupLength = 15;
452 for (int i = 0; i < 100; ++i) { 454 for (int i = 0; i < 100; ++i) {
453 for (int j = 0; j < kTimestampGroupLength; ++j) { 455 for (int j = 0; j < kTimestampGroupLength; ++j) {
454 // Insert |kTimestampGroupLength| frames with just 1 timestamp ticks in 456 // Insert |kTimestampGroupLength| frames with just 1 timestamp ticks in
455 // between. Should be treated as part of the same group by the estimator. 457 // between. Should be treated as part of the same group by the estimator.
456 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, 458 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms,
457 sequence_number++, 100); 459 sequence_number++, 100);
458 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs / kTimestampGroupLength); 460 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs / kTimestampGroupLength);
459 send_time_ms += 1; 461 send_time_ms += 1;
460 } 462 }
461 // Increase time until next batch to simulate over-use. 463 // Increase time until next batch to simulate over-use.
462 clock_.AdvanceTimeMilliseconds(10); 464 clock_.AdvanceTimeMilliseconds(10);
463 send_time_ms += kFrameIntervalMs - kTimestampGroupLength; 465 send_time_ms += kFrameIntervalMs - kTimestampGroupLength;
464 bitrate_estimator_->Process();
465 } 466 }
466 EXPECT_TRUE(bitrate_observer_->updated()); 467 EXPECT_TRUE(bitrate_observer_.updated());
467 // Should have reduced the estimate. 468 // Should have reduced the estimate.
468 EXPECT_LT(bitrate_observer_->latest_bitrate(), 400000u); 469 EXPECT_LT(bitrate_observer_.latest_bitrate(), 400000u);
469 } 470 }
470 471
471 void DelayBasedBweTest::TestWrappingHelper(int silence_time_s) { 472 void DelayBasedBweTest::TestWrappingHelper(int silence_time_s) {
472 const int kFramerate = 100; 473 const int kFramerate = 100;
473 const int kFrameIntervalMs = 1000 / kFramerate; 474 const int kFrameIntervalMs = 1000 / kFramerate;
474 int64_t send_time_ms = 0; 475 int64_t send_time_ms = 0;
475 uint16_t sequence_number = 0; 476 uint16_t sequence_number = 0;
476 477
477 for (size_t i = 0; i < 3000; ++i) { 478 for (size_t i = 0; i < 3000; ++i) {
478 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, 479 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms,
479 sequence_number++, 1000); 480 sequence_number++, 1000);
480 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 481 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
481 send_time_ms += kFrameIntervalMs; 482 send_time_ms += kFrameIntervalMs;
482 bitrate_estimator_->Process();
483 } 483 }
484 uint32_t bitrate_before = 0; 484 uint32_t bitrate_before = 0;
485 std::vector<uint32_t> ssrcs; 485 std::vector<uint32_t> ssrcs;
486 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_before); 486 bitrate_estimator_.LatestEstimate(&ssrcs, &bitrate_before);
487 487
488 clock_.AdvanceTimeMilliseconds(silence_time_s * 1000); 488 clock_.AdvanceTimeMilliseconds(silence_time_s * 1000);
489 send_time_ms += silence_time_s * 1000; 489 send_time_ms += silence_time_s * 1000;
490 bitrate_estimator_->Process();
491 490
492 for (size_t i = 0; i < 21; ++i) { 491 for (size_t i = 0; i < 21; ++i) {
493 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, 492 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms,
494 sequence_number++, 1000); 493 sequence_number++, 1000);
495 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); 494 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs);
496 send_time_ms += kFrameIntervalMs; 495 send_time_ms += kFrameIntervalMs;
497 bitrate_estimator_->Process();
498 } 496 }
499 uint32_t bitrate_after = 0; 497 uint32_t bitrate_after = 0;
500 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after); 498 bitrate_estimator_.LatestEstimate(&ssrcs, &bitrate_after);
501 EXPECT_LT(bitrate_after, bitrate_before); 499 EXPECT_LT(bitrate_after, bitrate_before);
502 } 500 }
503 } // namespace webrtc 501 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698